Parsing SIP message body

吃可爱长大的小学妹 提交于 2019-12-22 10:18:16

问题


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


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/14499944/parsing-sip-message-body

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!