a modern and powerful library for parsing & manipulating SIP messages
siplib a powerful SIP library for framing & parsing SIP messages with a fluent API and immutable objects. siplib is part of pkts.io and the Aboutsip family and is designed to be used as a standalone module, either for building your own SIP stack from scratch, or developing your own tools for parsing & manipulating SIP.
The following example shows how to parse a SIP message, create a copy of it and by registering functions, some headers are manipulated at the time the SIP message is built.
In this example we are creating a SIP message "manually" but of course, in a real-world application you typically would read bytes off of a network stream or perhaps read a set of SIP messages from a file in case you are building a tool of some sort. However, this is just an example so therefore we are doing it the hard way...
Every object in siplib has a frame-method, which will attempt to frame the raw content into that object. This is true for SIP messages, SIP headers, SIP URIs etc. All frame-methods are overloaded and accept Strings, Buffers and byte-arrays.
One very common SIP application is to act as a SIP Proxy, which accepts an incoming message, finds the next hop and forwards the message there. When doing so, the proxy application may add some new headers, drop others, add a new top-most Via-header and manipulate the previous top Via etc. Since everything in siplib is immutable, a copy must be created, which returns a builder that allows you to perform the necessasry operations on the message before finally contstructing it through the build method.
The two resulting SIP messages are shown below, where the first one is the original BYE and the second one is the "proxy BYE". Note how the request URI on line 1 has changed from host 'siplib.io' to 'sipstack.io' due to the lambda expression registered with the onRequestURI method. In fact, this is the preferred way to manipulate any SIP message and the philopshy behind that is further discussed in the docs section. You'll also notice that a similar function was registered for non-system headers through the onHeader method as well as for Via-headers through the onViaHeader
Head over to the Get Started guide, which will take you through how to setup your project for using siplib.io.