/**
 * Structure for SIP Message (REQUEST and RESPONSE).
 * @struct osip_message
 */
  struct osip_message
  {
    char *sip_version;                /**< SIP version (SIP request only) */
    osip_uri_t *req_uri;              /**< Request-Uri (SIP request only) */
    char *sip_method;                 /**< METHOD (SIP request only) */

int status_code;                  /**< Status Code (SIP answer only) */
    char *reason_phrase;              /**< Reason Phrase (SIP answer only) */

#ifndef MINISIZE
    osip_list_t accepts;             /**< Accept headers */
    osip_list_t accept_encodings;    /**< Accept-Encoding headers */
    osip_list_t accept_languages;    /**< Accept-Language headers */
    osip_list_t alert_infos;         /**< Alert-Info headers */
    osip_list_t allows;              /**< Allows headers */
    osip_list_t authentication_infos;/**< authentication_info headers */
#endif
    osip_list_t authorizations;      /**< Authorizations headers */
    osip_call_id_t *call_id;          /**< Call-ID header */
#ifndef MINISIZE
    osip_list_t call_infos;          /**< Call-Infos header */
#endif
    osip_list_t contacts;            /**< Contacts headers */
#ifndef MINISIZE
    osip_list_t content_encodings;   /**< Content-Encodings headers */
#endif
    osip_content_length_t *content_length;   /**< Content-Length header */
    osip_content_type_t *content_type;       /**< Content-Type header */
    osip_cseq_t *cseq;                /**< CSeq header */
#ifndef MINISIZE
    osip_list_t error_infos;         /**< Error-Info headers */
#endif
    osip_from_t *from;                /**< From header */
    osip_mime_version_t *mime_version;/**< Mime-Version header */
    osip_list_t proxy_authenticates; /**< Proxy-Authenticate headers */
#ifndef MINISIZE
    osip_list_t proxy_authentication_infos; /**< P-Authentication-Info headers */
#endif
    osip_list_t proxy_authorizations;/**< Proxy-authorization headers */
    osip_list_t record_routes;       /**< Record-Route headers */
    osip_list_t routes;              /**< Route headers */
    osip_to_t *to;                    /**< To header */
    osip_list_t vias;                /**< Vias headers */
    osip_list_t www_authenticates;   /**< WWW-Authenticate headers */

osip_list_t headers;             /**< Other headers */

osip_list_t bodies;              /**< List of attachements */

/*
       1: structure and buffer "message" are identical.
       2: buffer "message" is not up to date with the structure info (call osip_message_to_str to update it).
     */
    int message_property;             /**@internal */
    char *message;                    /**@internal */
    size_t message_length;            /**@internal */

void *application_data;           /**can be used by upper layer*/
  };

  

  typedef struct osip_list osip_list_t;

 struct osip_list

 {

    int nb_elt;

    __node_t *node;

  }

  typedef struct __node  __node_t;

  struct __node

  {

    void *next;      /*next __node_t containing element */

    void *element;  /*element in current node*/

  }

  int

  osip_message_parse (osip_message_t * sip, const char *buf, size_t length)

  {

    return _osip_message_parse(sip, buf, length, 0);

  }

  static int

  _osip_message_parse (osip_message_t *sip, const char *buf, size_t length,

              int sipfrag)

  {

    int i;

    const char *next_header_index;

    char *tmp;

    char *beg;

    

    tmp = osip_malloc (length + 2);

    if (tmp == NULL)

    {
      OSIP_TRACE (osip_trace

              (__FILE__, __LINE__, OSIP_ERROR, NULL,

              "Could not allocate memory. \n"));

      return -1;

    }

    beg = tmp;

    memcpy (tmp, buf, length);

    tmp[length] = '\0';

    osip_util_replace_all_lws (tmp);

    //parse request or status line

    i = __osip_message_startline_parse (sip, tmp, &next_header_inde);

    if (i == -1 && !sipfrag)

    {

      osip_fee(beg);

      return -1;

    }    

    tmp = (char*) next_header_index;

    //parse headers

    i = msg_headers_parse (sip, tmp, &next_header_index);

    if (i == -1)

    {

      OSIP_TRACE (osip_trace

              (__FILE__, __LINE__, OSIP_ERROR, NULL,

              "error in msg_header_parse()\n"));

      osip_free (beg);

      return -1;

    }

    tmp = (char *) next_header_index;

    if (tmp[0] == '\0' || tmp[1] == '\0' || tmp[2] == '\0'}

    {

      if (sip->content_length == NULL)

        osip_message_set_content_length (sip, "0");

      osip_free (beg);

      return 0;

    }

    i = msg_osip_body_parse (sip, tmp, &next_header_index, length - (tmp - beg));

    osip_free (beg);

    if (i == -1)

    {

      OSIP_TRACE (osip_trace

            (__FILE__, __LINE__, OSIP_ERROR, NULL,

            "error in msg_osip_body_parse()\n"));

      return -1;

    }

    /* this is mandatory in the osip stack */

    if (sip->content_length == NULL)

      osip_message_set_content_length (sip, "0");

    return 0;

}

  

osip结构体的更多相关文章

  1. Go结构体实现类似成员函数机制

    Go语言结构体成员能否是函数,从而实现类似类的成员函数的机制呢?答案是肯定的. package main import "fmt" type stru struct { testf ...

  2. C#基础回顾(二)—页面值传递、重载与重写、类与结构体、装箱与拆箱

    一.前言 -孤独的路上有梦想作伴,乘风破浪- 二.页面值传递 (1)C#各页面之间可以进行数据的交换和传递,页面之间可根据获取的数据,进行各自的操作(跳转.计算等操作).为了实现多种方式的数据传递,C ...

  3. go语言结构体

    定义: 是一种聚合的数据类型,是由零个或多个任意类型的值聚合成的实体. 成员: 每个值称为结构体的成员. 示例: 用结构体的经典案例处理公司的员工信息,每个员工信息包含一个唯一的员工编号.员工的名字. ...

  4. C语言中的结构体

    用户自己建立自己的结构体类型 1.  定义和使用结构体变量 (1).结构体的定义 C语言允许用户自己建立由不同类型数据组成的组合型的数据结构,它称为结构体. (2).声明一个结构体类型的一般形式为: ...

  5. C++_系列自学课程_第_12_课_结构体

    #include <iostream> #include <string> using namespace std; struct CDAccount { double bal ...

  6. java socket传送一个结构体给用C++编写的服务器解析的问题

    另一端是Java写客户端程序,两者之间需要通信.c++/c接收和发送的都是结构体,而Java是直接发送的字节流或者byte 数组.解决方法:c++/c socket 在发送结构体的时候其实发送的也是字 ...

  7. swift学习笔记3——类、结构体、枚举

    之前学习swift时的个人笔记,根据github:the-swift-programming-language-in-chinese学习.总结,将重要的内容提取,加以理解后整理为学习笔记,方便以后查询 ...

  8. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. C语言结构体对齐

    1.结构体变量中的元素如何访问? (1)数组中元素的访问方式:表面上有2种方式(数组下标方式和指针方式):实质上都是指针方式访问.(2)结构体变量中的元素访问方式:只有一种,用.或者->的方式来 ...

随机推荐

  1. neon指令,注意事项

    1. vbic_s8 (int8x8_t a, int8x8_t b) 是  ~(ai & bi),一开始理解成  (~ai )& bi 导致出错 2.uint8x8_t vqshrn ...

  2. 转json using指令

    using Newtonsoft.Json;using Newtonsoft.Json.Converters; string result = JsonConvert.SerializeObject( ...

  3. iOS下载使用系统字体

    iOS下载使用系统字体 通用开发中一般使用系统默认的字体: 另外系统也提供了一些其他字体我们可以选择下载使用 1:在mac上打开 字体册 app 即可查找系统支持的字体,适用于ios上开发使用 从ma ...

  4. 谷歌 火狐 CSS兼容

    @media screen and (-webkit-min-device-pixel-ratio:0){}谷歌@-moz-document url-prefix(){}火狐

  5. swig之于c++

    [namespace] namespace nsTest1 { int nsAdd(int a, int b) { return a + b; } } namespace nsTest2 { int ...

  6. 不再折腾-----hadoop-1.2.1完全分布式安装

    准备工作 三台虚拟机,强烈推荐vmware + centos6.5 三台虚拟机均设有hadoop用户 IP地址设置 IP地址 hostname 192.168.11.100 master 192.16 ...

  7. 如何做出header,footer固定定位后让main主体部分可以滑动,在微信浏览器中滑动到最后不出现黑边的情况

    <!doctype html>   <html>   <head>   <meta charset="utf-8">   </ ...

  8. [转] 深入探讨C++中的引用

    引用是C++引入的新语言特性,是C++常用的一个重要内容之一,正确.灵活地使用引用,可以使程序简洁.高效.我在工作中发现,许多人使用它仅仅是想当然,在某些微妙的场合,很容易出错,究其原由,大多因为没有 ...

  9. iOS开发网络篇—HTTP协议

    iOS开发网络篇—HTTP协议 说明:apache tomcat服务器必须占用8080端口 一.URL 1.基本介绍 URL的全称是Uniform Resource Locator(统一资源定位符) ...

  10. Masonry使用注意篇

    简要 自动布局最重要的是约束:UI元素间关系的数学表达式.约束包括尺寸.由优先级和阈值管理的相对位置.它们是添加剂,可能导致约束冲突 .约束不足造成布局无法确定 .这两种情况都会产生异常. 使用前:A ...