SDP Module

1.12.1

Module Meta Information

The sdp module provides a simple "C" parser interface for SDP [RFC2327], Session Description Protocol.

Contact:
Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>
Status:
Core library
License:
LGPL
Contributor(s):

SDP Parser

SDP parser parses an SDP message and converts it to internally used SDP datatypes.

Typically, the SDP parser is used as follows:

 sdp_parser parser = sdp_parse(home, message, len, 0);

 if (!sdp_session(parser)) {
   show(sdp_parsing_error(parser));
 } else {
   sdp_session_t *sdp = sdp_session(parser);
Act upon session description, then free the parser:
 }
 sdp_parser_free(parser);

There are various flags indicating what kind of SDP variants parser accepts. The sanity check run after parsing can be disabled by including flag sdp_f_insane. The parser can be used to parse syntactically vague configuration files when using flag sdp_f_config. The parser will then accept * for media, protocol and port, for instance.

Todo:
strict (parser accepts some non-conforming SDP even with strict)

SDP Printer

SDP printer converts internally used SDP datatypes to the standard SDP format.

Typically, the SDP printer is used as follows:

 char buffer[512];
 sdp_printer printer = sdp_print(home, session, buffer, sizeof(buffer), 0);

 if (sdp_message(printer)) {
   char const *msg = sdp_message(printer);
   int  msgsize = sdp_message_size(printer);

At this point, application can use the SDP message contents, e.g., it can send them to network, and then free the message:

 }
 else {
   show_critical_error(sdp_printing_error(printer));
 }
 sdp_printer_free(printer);

Example

Examples on using SDP parser can be found from sdp_test.c and nua.c. Here is an simple example, which decodes an SDP text in original, increments the version number in the origin line, and encodes the SDP description again to buf.

int increment_sdp_version(char buf[], int bsize, 
                          char const *original, int osize)
{
  su_home_t home[1] = { SU_HOME_INIT(home) };
  sdp_parser_t *parser = sdp_parse(home, original, osize, 0);
  sdp_printer_t *printer;
  int retval = 0;

  if (sdp_session(parser)) {
    sdp_session_t *sdp = sdp_session(parser);
    
    sdp->sdp_origin->o_version++;

    printer = sdp_print(home, sdp, buf, bsize, 0);

    if (sdp_message(printer)) {
      retval = sdp_message_size(printer);
    }
    else {
      fprintf(stderr, "increment_sdp_version: %s\n", 
              sdp_printing_error(printer));
    }

    sdp_printer_free(printer);
  }
  else {
    fprintf(stderr, "increment_sdp_version: %s\n", 
            sdp_parsing_error(p));
  }

  sdp_parser_free(parser);
      
  su_home_deinit(home);

  return retval;
}

Sofia-SIP 1.12.1 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.