osip结构体
/**
* 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;
}