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

📄 group__howto2__parser.html

📁 关于OSIP协议栈开发的一个很有用的东东~~~
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>libosip: How-To parse SIP message.</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.8 --><div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div><h1>How-To parse SIP message.<br><small>[<a class="el" href="group__libosip2.html">The GNU oSIP stack</a>]</small></h1><table border=0 cellpadding=0 cellspacing=0><tr><td></td></tr></table>For the SIP parser, the API is documented in <a class="el" href="osip__message_8h.html">osip_message.h</a><p>Here is the sequence needed to parse a given buffer containing a sip request or response. Because the SIP message can contains binary data in its body part, the length of the buffer must be given to the API.<p><pre>        osip_message_t *sip;	int i;</pre><p><pre>	i=osip_message_init(&amp;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><p>Here is the sequence needed to convert the message into a printable string. Note that in this sequence, dest is allocated dynamically and must be released at the end of the call sequence to avoid memory leaks.<p>When converting SIP message, the final length of the allocated buffer will be returned in the third argument. You then have the knowledge of the length of the data received.<p><pre>	char *dest=NULL;	int length=0;	i = osip_message_to_str(sip, &amp;dest, &amp;length);	if (i!=0) { fprintf(stderr, "cannot get printable message\n"); return -1; }	fprintf(stdout, "message:\n%s\n", dest);	osip_free(dest);</pre><p>When using libosip2 and its transaction management features, you'll generally only need to create a suitable events. Thus, you'll probably use this API (only for SIP message that you receive!):<p><pre>	osip_event_t *evt;	int length = size_of_buffer;	evt = osip_parse(buffer, i);</pre><p><b>It is important to understand that the libosip2 parser will not check completely if the message is compliant and well formed. The application layer is still responsible for this.</b> The following string shows a request-URI containing a strange port number!<p><pre>INVITE sip:<a href="mailto:jack@atosc.org">jack@atosc.org</a>:abcd SIP/2.0</pre><p>The libosip2 parser will not detect this as an error and it will be up to you to verify at evry action that things are as you are expecting them to be! <hr size="1"><address style="align: right;"><small>Generated on Tue Sep 7 15:08:00 2004 for libosip by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.8 </small></address></body></html>

⌨️ 快捷键说明

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