2008/7/30 Stefano Sabatini <[EMAIL PROTECTED]>: > On 7/30/08, Stefano Sabatini <[EMAIL PROTECTED]> wrote: >> On Wed, Jul 30, 2008 at 10:31 AM, Stefano Sabatini >> <[EMAIL PROTECTED]> wrote: >>> Hi all, >>> can you say if there is a simple way to convert a sip_t object to a char* >>> and viceversa? >>> >>> For example I would like to print all the incoming SIP messages from >>> the the event callback function. > [...] > > >From a textual representation to a msg_t and to a sip_t: > msg_data = "..."; > msg_t* msg = msg_make (sip_default_mclass(), 0, msg_data, sizeof (msg_data)); > if (!msg) { > fprintf(stderr, "Impossible to parse message\n"); > exit(1); > } > sip_t* sip = sip_object(msg); > > Still I don't know if there exists a function which returns a textual > representation of a message, > there is a sip_header_as_string(home, sip) function but not one which > prints the whole message.
Try msg_as_string().. > Also how can I get the headers from a sip_t struct, and how can I > iterate thrugh them? sip_t has pointers to each header fields, e.g., sip_via is pointer to a list of Via header fields. You can iterate through Via header fields with a loop like this: sip_t *sip = sip_object(sip); sip_via_t *via; for (via = sip->sip_via; via; via = via->v_next) { ... } If you want to iterate through each header field in the message, you should start from msg_chain_head(msg) and then proceed in order, e.g., for (next = msg_chain_head(msg); *next; next = &(*next)->sh_next) { sip_header_t *sh = (*next); msg_hclass_t const *hc = sh->sh_class; if (sip_is_via(sh) { sip_via_t const*via = (sip_via_t *)sh; .... } ... } The list of all the message components ("chain") also includes some non-header elements, like request-line, status-line and message body. There is also some complications with so called "list" headers like Require, their values are combined with their first occurrence, so headers like Require: 100rel Supported: timer Require: xyzzy will have one sip_require_t structure with tokens "100rel" and "xyzzy", one sip_supported_t structure with "timer" and a dummy sip_require_t structure in the chain. -- Pekka.Pessi mail at nokia.com ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Sofia-sip-devel mailing list Sofia-sip-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel