Class BodyParser
This class extracts both binary and text contents blocks from a SIP message. The ProcessMultiPartContents() method may be used to handle MSRP multipart/mixed message bodies.
Inherited Members
Namespace: SipLib.Body
Assembly: SipLib.dll
Syntax
public class BodyParser
Remarks
The reason that this class must be used when there is the possiblity that a SIP message might contain binary data is that almost all SIP related functions treat the entire message as UTF8 encoded strings. If arbitrary binary data is encoded to a UTF8 string then converted back to a raw binary array then encoding errors will occur.
Methods
| Edit this page View SourceContentsAreBinary(string, string?)
Determines if the contents of a SIP message body are binary or text. The known binary types are defined in the KnownBinaryTypes array. This array contains only a small subset of the IANA registered MIME types defined at: https://www.iana.org/assignments/media-types/media-types.xhtml
Declaration
public static bool ContentsAreBinary(string ContentType, string? ContentTransferEncoding)
Parameters
Type | Name | Description |
---|---|---|
string | ContentType | Value of the Content-Type header |
string | ContentTransferEncoding | Value of the Content-Transfer-Encoding header. May be null if not present. |
Returns
Type | Description |
---|---|
bool | Returns true if the Content-Type is a known binary type or false if it is not. |
ParseSipBody(byte[], string)
Parses a SIP message body. This method should be used when the SIP message body could contain data that must be treated as purely binary data as opposed to character data.
Declaration
public static List<MessageContentsContainer> ParseSipBody(byte[] MsgBytes, string ContentType)
Parameters
Type | Name | Description |
---|---|---|
byte[] | MsgBytes | Contains the entire SIP message -- headers and the body |
string | ContentType | Value of the Content-Type header of the SIP message |
Returns
Type | Description |
---|---|
List<MessageContentsContainer> | Returns a list of MessageContentsContainer objects. The list will be empty if the SIP message does not contain a body or if an error occurred. |
Exceptions
Type | Condition |
---|---|
NullReferenceException | |
IndexOutOfRangeException | |
Exception |
ProcessMultiPartContents(byte[], string)
Processes a SIP message with multiple body parts (i.e., Content-Type = multipart/mixed). Some body parts may be binary and some may be text. This method will also work with multipart/mixed MSRP messages.
Declaration
public static List<MessageContentsContainer> ProcessMultiPartContents(byte[] MsgBytes, string ContentType)
Parameters
Type | Name | Description |
---|---|---|
byte[] | MsgBytes | Bytes of the entire message including headers and request line) and the body. Alternatively, pass all of the bytes of only the body of the message. |
string | ContentType | Value of the Content-Type header of the overall message. For example: "multipart/mixed; boundary=boundary1". The boundary parameter value may be quoted or not. |
Returns
Type | Description |
---|---|
List<MessageContentsContainer> | Returns a list of MessageContentsContainer objects. The return value will not be null, but it may be empty is an error occurred. |