On date Tuesday 2008-08-05 11:40:44 +0200, Stefano Sabatini phoned this:
> On Mon, Aug 4, 2008 at 8:07 PM, Pekka Pessi <[EMAIL PROTECTED]> wrote:
> > 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()..
> 
> Yes, I don't know how I missed it (mmh maybe because I was looking for
> something like sip_msg_as_string in sip...).

How can I get a msg_t from a sip_t?

I can convert a msg_t -> sip_t using sip_object, but how can I perform
the inverse conversion?

All I want to do is to simply print out the sip_t message received by
the event callback, so the solution looks either convert sip_t ->
msg_t and use msg_as_string() either to print sip_t using some to text
conversion function, which I can't find.
 
> >> 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) {
> >  ...
> > }

There is a supposed way to convert such header field structure to a
string?
Suppose that I want for example to convert sip->sip_from to a
corresponding string, which is the supposed way to do it (apart to
manually concat the various pieces found in that struct, which doesn't
look like the way to go)?

> > 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.
> 
> Thanks so much for the detailed answer!

Thanks again, regards.

-------------------------------------------------------------------------
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

Reply via email to