Programming Interfaces Guide

Parsing the SDP Session Structure

int sdp_parse(const char *sdp_info, int len, int flags, sdp_session_t **session, uint_t *p_error);

The sdp_parse() function parses the SDP description in the sdp_info parameter and populates the sdp_session_t structure. The len parameter specifies the length of the character buffer sdp_info. The function allocates the memory required for the sdp_session_t structure. To free that memory, call the sdp_free_session() function.

The value of the flags parameter must be set to zero. When the flags parameter has a nonzero value, the sdp_parse() function fails with a return value of EINVAL and sets the value of *session to NULL.

The p_error parameter takes on the values of any fields that have parsing errors. This parameter cannot have a value of NULL. Possible values for the p_error parameter are in the following list:

SDP_VERSION_ERROR             0x00000001
SDP_ORIGIN_ERROR              0x00000002
SDP_NAME_ERROR                0x00000004
SDP_INFO_ERROR                0x00000008
SDP_URI_ERROR                 0x00000010
SDP_EMAIL_ERROR               0x00000020
SDP_PHONE_ERROR               0x00000040
SDP_CONNECTION_ERROR          0x00000080
SDP_BANDWIDTH_ERROR           0x00000100
SDP_TIME_ERROR                0x00000200
SDP_REPEAT_TIME_ERROR         0x00000400
SDP_ZONE_ERROR                0x00000800
SDP_KEY_ERROR                 0x00001000
SDP_ATTRIBUTE_ERROR           0x00002000
SDP_MEDIA_ERROR               0x00004000
SDP_FIELDS_ORDER_ERROR        0x00008000
SDP_MISSING_FIELDS            0x00010000

When the SDP structure violates RFC 4566 by having fields out of order, the sdp_parse() function sets the value of the p_error parameter to SDP_FIELDS_ORDER_ERROR. When the SDP structure violates RFC 4566 by lacking mandatory fields, the sdp_parse() function sets the value of the p_error parameter to SDP_MISSING_FIELDS.

The sdp_parse() function continues to parse after processing a field with a parsing error, but the field with the parsing error will not be present in the resulting sdp_session_t structure.

Return Values: The sdp_parse() function returns 0 when the function completes successfully. When the session arguments are invalid, the sdp_parse()function returns EINVAL. When memory allocation fails while the sdp_parse() function is parsing sdp_info, the function returns ENOMEM. The value of errno does not change in the event of an error.

Example 3–5 Example: Parsing an SDP Session Structure

In this example, the SDP session structure is as follows:

o=jdoe 23423423 234234234 IN IP4\r\n
s=SDP seminar\r\n
i=A seminar on the session description protocol\r\n
c=IN IP4\r\n
t=2873397496 2873404696\r\n

After calling the sdp_parse_t() function, the resulting sdp_session_t structure is as follows:

session {
        sdp_session_version = 1
        s_version = 0
        s_origin {
                o_username = "jdoe"
                o_id = 23423423ULL
                o_version = 234234234ULL
                o_nettype = "IN"
                o_addrtype = "IP4"
                o_address = ""
        s_name = "SDP seminar"
        s_info = "A seminar on the session description protocol"
        s_uri =  (nil)
        s_email {
                value = ""
                next = (nil)
        s_phone = (nil)
        s_conn {
                c_nettype = "IN"
                c_addrtype = "IP4"
                c_address = ""
                c_addrcount = 0
                c_ttl = 0
                c_next = (nil)
        s_bw = (nil)
        s_time {
                t_start = 2873397496ULL
                t_stop = 2873404696ULL
                t_repeat = (nil)
                t_next = (nil)
        s_zone = (nil)
        s_key = (nil)
        s_attr = (nil)
        s_media = (nil)