Parsing SIP message body

I'm implementing SIP protocol and I'm stuck while parsing SIP message. I'm using the oSIP library. My code is like that:

#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/2.0\nCall-ID: 123456789@aradan\nVia: SIP/2.0/UDP\nFrom: Arto <>\nTo: Jari <>\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 text. Respective the fields call_id, content_lenght, content_type, cseq, from, req_uri, sip_method, sip_version, to and vias are filled correctly, but in the field message is value 0x0, message_length is 0 and message_property is 2. Error codes are 0 for all three commands. Why is the message body not parsed ? I'm confused of this things: In RFC is stated, that every line should be ended with CLRF sequence, but I'm simply using \n and it seems like working. Next I dont like this statement:

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

For me, is this weird. In the documentation of oSIP is stated that sequence of:

osip_message_t *sip;
osip_message_parse(sip, buffer, length_of_buffer);

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

And why is possible, that the field content_length is autofilled but the message is not parsed ?

Last question : why is this topic so terribly covered on Internet ? No manuals, oSIP documentation is bad

Thank you


I think you might be reading the documentation wrong. The function osip_init() wants a osip_t **osip not a message. Re:

For future peeps with a similar problem:

I got the same error as Matka mentioned in his comment.

return value -5 from osip_message_parse

It was due to a malformed sip message that I was passing to the program while debugging.

I know this is an old question, but I've just stumbled on it.

osip_init is not needed to use just the parser, but you should init the parser with parser_init(); instead.

Need Your Help

htmlagilitypack scrape all rows

.net winforms html-parsing web-scraping html-agility-pack

I need to scrape all table rows with class containing "row", within an iframe contained in a web page.

SQL Server Data has script tags in a Memo Field with Intranet IP Address

sql-server coldfusion

We have a ColdFusion page where admins can insert/update some real estate records after logging in. We are noticing that in one table's Memo field called 'description', there are sometimes tags wh...