/**
* Structure for SIP Message (REQUEST and RESPONSE).
* @struct osip_message
*/
struct osip_message
{
char *sip_version; /** osip_uri_t *req_uri; /** char *sip_method; /**
int status_code; /** char *reason_phrase; /**
#ifndef MINISIZE
osip_list_t accepts; /** osip_list_t accept_encodings; /** osip_list_t accept_languages; /** osip_list_t alert_infos; /** osip_list_t allows; /** osip_list_t authentication_infos;/**#endif
osip_list_t authorizations; /** osip_call_id_t *call_id; /**#ifndef MINISIZE
osip_list_t call_infos; /**#endif
osip_list_t contacts; /**#ifndef MINISIZE
osip_list_t content_encodings; /**#endif
osip_content_length_t *content_length; /** osip_content_type_t *content_type; /** osip_cseq_t *cseq; /**#ifndef MINISIZE
osip_list_t error_infos; /**#endif
osip_from_t *from; /** osip_mime_version_t *mime_version;/** osip_list_t proxy_authenticates; /**#ifndef MINISIZE
osip_list_t proxy_authentication_infos; /**#endif
osip_list_t proxy_authorizations;/** osip_list_t record_routes; /** osip_list_t routes; /** osip_to_t *to; /** osip_list_t vias; /** osip_list_t www_authenticates; /**
osip_list_t headers; /**
osip_list_t bodies; /**
/*
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结构体