From reSIProcate
Revision as of 11:03, 15 June 2005 by Jason (talk | contribs)
Jump to navigation Jump to search

Message Bodies

Bodies are carried in SIP messages and are accessed with getContents and setContents. The bodies are stored as pointers to the Contents base type. Typically, use dynamic_cast to the desired type to access the derived body type.

Type Mapping

The type of the body is determined when parsing an incoming message. The body's type is determined by the MIME type in the messages Content-Type header.

The MIME type maps to a unique derived concrete Content type that parses and provides access to the parts of the body. This mapping can be modified by altering the derived Contents types that are #included in your application. For example, the class SdpContents causes itself to be the contents handler fot the MIM type application/sdp. When included, SdpContents will be invoked as the parser and interface for SDP bodies.

A different class can be specified to parse SDP by defining it to return application/sdp from its getStaticType() and including this class instead of SdpContents. Including two content handling classes for the same MIME type will causes an immediate run-time error.


The SDP body of a parsed message can be accessed with:

SdpContents* sdp = dynamic_cast<SdpContents*>(msg->getContents);

SdpContents provides a rich interface to the components of the SDP body.


Similarly, an SdpContents can be constructed and populated at run time and then made to be the body of an outgoing message. The Content-Type of the containing message will be set appropriately and the message will be serialzed to the wire with the SDP body:

SdpContents sdp;
msg->setContents(&sdp); // copy the sdp into the message

Alternatively, the copy can be avoided:

SdpContents* sdp;
std::auto_ptr<Contents*> contents(sdp);
msg->setContents(contents) // transfer the sdp to the message

Content Headers

Content headers are set on the content instance. The headers are output as part of the container's headers when the contents is placed in the container. For example, a SipMessage containing a MIME content will output these headers as SipMessage headers. When parsed, the content specific header information is migrated into the contained contents. Contents containers include SipMessage and multipart derived Contents.

Content headers are accessed analogously to SIP message headers. Each header has an accessor token used to overload the header method. The following headers are used in Contents and in SipMessage.

RFC NamereSIP Access TokenreSIP Type

The following headers are MIME specific. These headers are accessible on Contents only. These headers appear in encoded bodies only when the content is MIME wrapped (for example, contained in a MultipartRelatedContents).

RFC NamereSIP Access TokenreSIP Type

Notably absent from the set of accessible headers is Content-Length. The length of the content is caclulated from the concrete contents and is not settable.

For each header type, there is a header access method, exists method, and a remove method.

Class Hierarchy

Class Hierarchy