Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

How-To parse URI.
[The GNU oSIP stack]

To demonstrate how to use the libosip2 parser, the simplest way is to start playing with URI. (Uniform Resource Identifier)

For each parser (headers, SIP message or URI), you'll always find something close to this minimal subset of methods:

	// allocation/release of memory.
	xxxx_init(osip_xxx_t **el);
	xxxx_free(osip_xxx_t *el);

	xxxx_parse(osip_xxx_t *el, char *source);
	xxxx_to_str(osip_xxx_t *el, char **dest);

For the URI parser, the API is documented in osip_uri.h

Here is the sequence needed to parse a given buffer containing a sip URI:

        osip_uri_t *uri;
	int i;

	if (i!=0) { fprintf(stderr, "cannot allocate\n"); return -1; }
	i=osip_uri_parse(uri, buffer);
	if (i!=0) { fprintf(stderr, "cannot parse uri\n"); }

Here is the sequence needed to convert the URI into a printable string. Note that in this sequence, dest is allocated dynamically and must be released at the end of the call sequence to avoid memory leaks.

	char *dest;
	i = osip_uri_to_str(uri, &dest);
	if (i!=0) { fprintf(stderr, "cannot get printable URI\n"); return -1; }
	fprintf(stdout, "URI: %s\n", dest);

Generated on Tue Feb 22 00:59:48 2005 for libosip by  doxygen 1.4.1