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: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 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_init(&sip);
osip_message_parse(sip, buffer, length_of_buffer);
osip_message_free(sip);
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