Parsing the contents of a SIP message

I am implementing the SIP protocol and I am stuck parsing a SIP message. I am using the oSIP library. My code looks like this:

#include <stdio.h>
#include <stdlib.h>
#include <osip2/osip.h>
#include <osipparser2/osip_parser.h>
#include <string.h>

void main()
{
  int i,error;
  osip_message_t *message;
  char text[]="INVITE sip:jarsku@feanor.pc.lut.fi SIP/2.0\nCall-ID: 123456789@aradan\nVia: SIP/2.0/UDP 157.24.25.137:5060\nFrom: Arto <sip:athamala@feanor.pc.lut.fi>\nTo: Jari <sip:jarsku@feanor.pc.lut.fi>\nCSeq: 1 INVITE\nContent-Type: application/sdp\n\nv=0\na=3333aaa333";
  char *p=(char *)&text;

  i = strlen(text);
  error = osip_init(&message);
  error = osip_message_init(&message);
  error = osip_message_parse(message, p, i);
}

      

When I run this code, the message structure is filled with data from the text. Accordingly, the call_id, content_lenght, content_type, cseq, from, req_uri, sip_method, sip_version,

to and vias fields are filled in correctly, but the field message contains the value 0x0, message_length

equal to 0, and message_property equal to 2. The error codes are equal to 0 for all three commands. Why isn't the message body parsed? I'm confused by this: The RFC states that each line must end with a CLRF sequence, but I just use \n

and it seems to work. Further, I dislike this statement:

error = osip_init(&message);
error = osip_message_init(&message);

      

This is strange to me. The oSIP documentation states that the sequence is:

osip_message_t *sip;
osip_message_init(&sip);
osip_message_parse(sip, buffer, length_of_buffer);
osip_message_free(sip);

      

should be enough (in my code I am using init and message_init), but this is throwing me a Segmentation error.

And why is it possible that the field is content_length

autocompleted but the message is not parsed?

One final question: why is this topic so badly covered on the Internet? No manual, oSIP documentation is poor.

thank

+3


source to share


3 answers


I think you are probably reading the documentation incorrectly. The osip_init () function wants osip_t ** osip to not be a message. Re: http://www.gnu.org/software/osip/doc/html/group_howto0_initialize.html



+2


source


For future searches with a similar problem:

I got the same error as Matka in his comment.



return value -5 from osip_message_parse

This was due to the wrong sip message that I was passing to the program while debugging.

+1


source


I know this is an old question, but I just came across it.

osip_init is not required to use only the parser, but you must initialize the parser with parser_init (); instead of this.

0


source







All Articles