SIP API Developer's Guide

Message Formatting Layer

The message formatting layer represents the message in the form that the next component or layer requires.

If the incoming message arrives over TCP, the message formatting layer breaks the byte stream at message boundaries. The message formatting layer parses the message in order to represent the message as a SIP message.

When the application is sending a message, the message formatting layer copies all of the message's headers and contents into a contiguous buffer before delivering the message to the application's send function.

Receiving Messages

The application sends the incoming message to the stack along with the connection object. If the transport is TCP, the message formatting layer breaks the byte stream at message boundaries. The SIP message's Content-Length header determines the message boundaries. A Content-Length header must be present in every message delivered over TCP in order to comply with RFC 3261. If the stack receives a message over TCP that does not contain a Content-Length header, the stack's behavior is unspecified.

The message formatting layer holds excess data that is not part of the current message for use with the next packet. When the system closes or reuses a connection, the connection manager must notify the stack. After receiving the notification, the stack frees the data and resources that the stack allocated to that connection. The stack delivers the message to the application by calling the receive function. The application registers the receive function with the stack during stack initialization.

Sending Messages

An application sends a SIP message by using the sip_sendmsg() function with the connection object and any message specific flags. The message formatting layer adds a Content-Length header and a line that contains only a Carriage Return/Line Feed (CRLF) character to the message and delivers the packet to the next layer. The message formatting layer copies all of the SIP message's headers and contents into a contiguous buffer before delivering the message to the application's send function. The connection manager provides the send function.