ht1-uri.dox 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @ingroup libosip2 The GNU oSIP stack
  3. * @defgroup howto_uri How-To parse URI.
  4. * @section howto_uri1 URI Parser APIs
  5. To demonstrate how to use the libosip2 parser, the
  6. simplest way is to start playing with URI. (Uniform
  7. Resource Identifier)
  8. For each parser (headers, SIP message or URI), you'll
  9. always find something close to this minimal subset of
  10. methods:
  11. ~~~~~~~{.c}
  12. // allocation/release of memory.
  13. xxxx_init(osip_xxx_t **el);
  14. xxxx_free(osip_xxx_t *el);
  15. xxxx_parse(osip_xxx_t *el, char *source);
  16. xxxx_to_str(osip_xxx_t *el, char **dest);
  17. ~~~~~~~
  18. For the URI parser, the API is documented in osip_uri.h
  19. * @section howto_uri2 Basic URI operations
  20. + Here is the sequence needed to parse a given buffer containing a sip URI:
  21. ~~~~~~~{.c}
  22. osip_uri_t *uri;
  23. int i;
  24. i=osip_uri_init(&uri);
  25. if (i!=0) { fprintf(stderr, "cannot allocate\n"); return -1; }
  26. i=osip_uri_parse(uri, buffer);
  27. if (i!=0) { fprintf(stderr, "cannot parse uri\n"); }
  28. osip_uri_free(uri);
  29. ~~~~~~~
  30. + Here is the sequence needed to convert the URI into a printable
  31. string.
  32. **Note**: dest is allocated dynamically and must be released at the end
  33. of the call sequence to avoid memory leaks.
  34. ~~~~~~~{.c}
  35. char *dest;
  36. i = osip_uri_to_str(uri, &dest);
  37. if (i!=0) { fprintf(stderr, "cannot get printable URI\n"); return -1; }
  38. fprintf(stdout, "URI: %s\n", dest);
  39. osip_free(dest);
  40. ~~~~~~~
  41. */