⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ht2-parser.dox

📁 最新osip源代码
💻 DOX
字号:
/** * @ingroup libosip2 The GNU oSIP stack * @defgroup howto2_parser How-To parse SIP message.For the SIP parser, the API is documented in osip_message.hHere is the sequence needed to parse a given buffer containinga sip request or response. Because the SIP message can containsbinary data in its body part, the length of the buffer must begiven to the API.<PRE>        osip_message_t *sip;	int i;	i=osip_message_init(&sip);	if (i!=0) { fprintf(stderr, "cannot allocate\n"); return -1; }	i=osip_message_parse(sip, buffer, length_of_buffer);	if (i!=0) { fprintf(stderr, "cannot parse sip message\n"); }	osip_message_free(sip);</PRE>Here is the sequence needed to convert the message into a printablestring. Note that in this sequence, dest is allocated dynamicallyand must be released at the end of the call sequence to avoidmemory leaks.When converting SIP message, the final length of the allocated bufferwill be returned in the third argument. You then have the knowledge ofthe length of the data received.<PRE>	char *dest=NULL;	int length=0;	i = osip_message_to_str(sip, &dest, &length);	if (i!=0) { fprintf(stderr, "cannot get printable message\n"); return -1; }	fprintf(stdout, "message:\n%s\n", dest);	osip_free(dest);</PRE>When using libosip2 and its transaction management features, you'll generallyonly need to create a suitable events. Thus, you'll probably use this API (onlyfor SIP message that you receive!):<PRE>	osip_event_t *evt;	int length = size_of_buffer;	evt = osip_parse(buffer, i);</PRE><B>It is important to understand that the libosip2 parser will not checkcompletely if the message is compliant and well formed. The applicationlayer is still responsible for this.</B> The following string showsa request-URI containing a strange port number! <pre>INVITE sip:jack@atosc.org:abcd SIP/2.0</pre>The libosip2 parser will not detect this as an error and it willbe up to you to verify at evry action that things are as you areexpecting them to be!*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -