gpt4 book ai didi

c - 解析 SIP 消息体

转载 作者:行者123 更新时间:2023-12-02 00:13:08 25 4
gpt4 key购买 nike

我正在实现 SIP 协议(protocol),但在解析 SIP 消息时卡住了。我正在使用 oSIP 库。我的代码是这样的:

#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);
}

当我运行这段代码时,消息结构中填充了来自文本的数据。 call_id, content_lenght, content_type, cseq, from, req_uri, sip_method, sip_version, to 和 vias 字段都正确填写,但字段 message 的值为 0x0,message_length为 0,message_property 为 2。三个命令的错误代码均为 0。为什么不解析邮件正文?我对这些事情感到困惑:在 RFC 中规定,每一行都应该以 CLRF 序列结束,但我只是使用 \n 并且它看起来像工作。接下来我不喜欢这个说法:

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

对我来说,这很奇怪吗?在 documentation of oSIP 中声明了以下序列:

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

应该足够了(在我的代码中,我使用了 init 和 message_init),但这会抛出一个段错误。

为什么可能会自动填充字段 content_length 但消息未被解析?

最后一个问题:为什么这个话题在 Internet 上被如此广泛地报道?没有手册,oSIP 文档很糟糕

谢谢

最佳答案

我认为您可能读错了文档。函数 osip_init() 需要一个 osip_t **osip 而不是消息。回复:http://www.gnu.org/software/osip/doc/html/group_howto0_initialize.html

关于c - 解析 SIP 消息体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14499944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com