Loading...
Searching...
No Matches
Sofia SIP User Agent Library - "sdp" - SDP Module

# Module Meta Information

The sdp module provides a simple "C" parser interface for SDP [RFC 2327], Session Description Protocol. The parser also implements support for IPv6 addresses as per RFC 3266. The RFC 4566 should be supported, but we have not checked since draft-eitf-mmusic-sdp-new-17 or so.

Contact:\n Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>

Status:\n Sofia SIP Core library

License:\n LGPL

Contributor(s):

- Pekka Pessi Pekka.nosp@m..Pes.nosp@m.si@no.nosp@m.kia..nosp@m.com
- Jari Selin Jari..nosp@m.Seli.nosp@m.n@nok.nosp@m.ia.c.nosp@m.om

# SDP Parser

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

Typically, the SDP parser is used as follows:

sdp_parser_t *parser = sdp_parse(home, message, len, 0);
if (!sdp_session(parser)) {
show(sdp_parsing_error(parser));
} else {
sdp_session_t *sdp = sdp_session(parser);
sdp_session_t
struct sdp_session_s sdp_session_t
SDP session description.
Definition sdp.h:45
sdp_parser_t
struct sdp_parser_s sdp_parser_t
SDP parser handle.
Definition sdp.h:530
sdp_parsing_error
char const * sdp_parsing_error(sdp_parser_t *p)
Get a parsing error message.
Definition sdp_parse.c:229
sdp_parse
sdp_parser_t * sdp_parse(su_home_t *, char const msg[], issize_t msgsize, int flags)
Parse an SDP message.
Definition sdp_parse.c:145
sdp_session
sdp_session_t * sdp_session(sdp_parser_t *p)
Retrieve an SDP session structure.
Definition sdp_parse.c:213

Act upon session description, then free the parser:

}
sdp_parser_free(parser);
sdp_parser_free
void sdp_parser_free(sdp_parser_t *p)
Free an SDP parser.
Definition sdp_parse.c:241

There are various flags indicating what kind of SDP variants the sdp_parse() 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.

# SDP Printer

SDP printer converts internally used SDP structure sdp_session_t to the standard SDP format.

Typically, the SDP printer is used as follows:

char buffer[512];
sdp_printer_t *printer = sdp_print(home, session, buffer, sizeof(buffer), 0);
if (sdp_message(printer)) {
char const *msg = sdp_message(printer);
size_t msgsize = sdp_message_size(printer);
sdp_print
sdp_printer_t * sdp_print(su_home_t *, sdp_session_t const *, char msgbuf[], isize_t maxmsgsize, int flags)
Print a SDP description.
Definition sdp_print.c:129
sdp_printer_t
struct sdp_printer_s sdp_printer_t
SDP printer handle.
Definition sdp.h:547
sdp_message
char const * sdp_message(sdp_printer_t *p)
Get encoded SDP message.
Definition sdp_print.c:201
sdp_message_size
isize_t sdp_message_size(sdp_printer_t *p)
Get size of encoded SDP message.
Definition sdp_print.c:218

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);
sdp_printer_free
void sdp_printer_free(sdp_printer_t *p)
Free a SDP printer.
Definition sdp_print.c:233
sdp_printing_error
char const * sdp_printing_error(sdp_printer_t *p)
Get encoding error.
Definition sdp_print.c:180

# Example

Examples on using SDP parser can be found from test_sdp.c and soa.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.

size_t increment_sdp_version(char buf[], size_t bsize,
char const *original, size_t osize)
{
su_home_t home[1] = { SU_HOME_INIT(home) };
sdp_parser_t *parser = sdp_parse(home, original, osize, 0);
sdp_printer_t *printer;
size_t 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(parser));
}
sdp_parser_free(parser);
su_home_deinit(home);
return retval;
}
sdp_origin_s::o_version
uint64_t o_version
Version of session description.
Definition sdp.h:107
sdp_session_s::sdp_origin
sdp_origin_t * sdp_origin
Owner/creator and session ID.
Definition sdp.h:86
su_home_deinit
void su_home_deinit(su_home_t *h)
su_home_t
SU_HOME_T su_home_t

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