📄 inet_msg_unpack.c
字号:
{
goto no_mem;
}
}
}
return (kal_uint32) ct;
no_mem:
inet_content_type_struct_free_fn(mem_func, ct);
return 0;
}
/*****************************************************************************
* FUNCTION
* inet_msg_unpack_content_type_list
* DESCRIPTION
* This function unpacks the content-type list. It can be used in Accept
* GRAMMER
* type/subtype
* PARAMETERS
* mem_func [IN] Memory function
* text [IN] String of field value
* RETURNS
* inet_content_type_struct pointer
*****************************************************************************/
kal_uint32 inet_msg_unpack_content_type_list(inet_mem_func_struct *mem_func, kal_char *text)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/* with initialized value */
kal_char *next_token = NULL;
inet_content_type_list_struct *content_type_list, *content_type_head;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!text)
{
return (kal_uint32) text;
}
content_type_head = (inet_content_type_list_struct*) inet_malloc(mem_func, sizeof(inet_content_type_list_struct));
if (!content_type_head)
{
return (kal_uint32) content_type_head;
}
content_type_list = content_type_head;
do
{
if (next_token)
{
text = next_token;
next_token = NULL; /* reset */
if (!content_type_list->next)
{
content_type_list->next =
(inet_content_type_list_struct*) inet_malloc(mem_func, sizeof(inet_content_type_list_struct));
if (!content_type_list->next)
{
goto exit_err;
}
}
content_type_list = content_type_list->next;
}
/* Find next content-type token */
next_token = inet_msg_get_next_token(text);
inet_msg_skipcfws(&text);
content_type_list->object = (inet_content_type_struct*) inet_msg_unpack_content_type(mem_func, text);
if (content_type_list->object == NULL)
{
goto exit_err;
}
} while (next_token);
return (kal_uint32) content_type_head;
exit_err:
if (content_type_head)
{
inet_content_type_list_struct_free_fn(mem_func, content_type_head);
}
return 0;
}
/*****************************************************************************
* FUNCTION
* inet_msg_unpack_via_list
* DESCRIPTION
* This function unpacks the Via.
*
* Via = ( "Via" / "v" ) HCOLON via-parm *(COMMA via-parm)
* via-parm = sent-protocol LWS sent-by *( SEMI via-params )
* via-params = via-ttl / via-maddr
* / via-received / via-branch
* / via-extension
* via-ttl = "ttl" EQUAL ttl
* via-maddr = "maddr" EQUAL host
* via-received = "received" EQUAL (IPv4address / IPv6address)
* via-branch = "branch" EQUAL token
* via-extension = generic-param
* sent-protocol = protocol-name SLASH protocol-version
* SLASH transport
* sent-by = host [ COLON port ]
* ttl = 1*3DIGIT ; 0 to 255
* host = hostname / IPv4address / IPv6reference
*
* Eg "SIP/2.0/UDP 172.21.120.118:2412;branch=z9hG4bK30155.5037.0\r\n"
* PARAMETERS
* mem_func [IN] Memory function
* text [IN] String of field value
* RETURNS
* inet_via_list_struct*
*****************************************************************************/
kal_uint32 inet_msg_unpack_via_list(inet_mem_func_struct *mem_func, kal_char *text)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_char *s, *pp, *sentby, *comment, *param, *port, *next_token = NULL;
inet_via_list_struct *via_list, *via_list_head;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!text)
{
return (kal_uint32) text;
}
via_list_head = (inet_via_list_struct*) inet_malloc(mem_func, sizeof(inet_via_list_struct));
if (!via_list_head)
{
return (kal_uint32) via_list_head;
}
via_list_head->object = (inet_via_struct*) inet_malloc(mem_func, sizeof(inet_via_struct));
if (!(via_list_head->object))
{
return (kal_uint32) via_list_head;
}
via_list = via_list_head;
do
{
comment = NULL;
if (next_token)
{
text = next_token;
next_token = NULL; /* reset */
s = next_token;
pp = next_token;
sentby = next_token;
param = next_token;
port = next_token;
if (via_list->next == NULL)
{
via_list->next = (inet_via_list_struct*) inet_malloc(mem_func, sizeof(inet_via_list_struct));
if (via_list->next == NULL)
{
return (kal_uint32) via_list_head;
}
}
via_list = via_list->next;
if (!(via_list->object))
{
via_list->object = (inet_via_struct*) inet_malloc(mem_func, sizeof(inet_via_struct));
if (!(via_list->object))
{
return (kal_uint32) via_list_head;
}
}
}
if (NULL != (next_token = strchr(text, ',')))
{
*next_token++ = '\0';
}
if (NULL == (sentby = strchr(text, ' ')) && NULL == (sentby = strchr(text, '\t')))
{
return (kal_uint32) via_list_head;
}
*sentby++ = '\0';
/* decode sent-protocol, eg "SIP/2.0/UDP" */
if ((s = strchr(text, '/')) == NULL)
{
via_list->object->version = inet_msg_strdup(mem_func, text);
}
else
{
if (strchr(s + 1, '/') == NULL)
{
/* This via belongs to HTTP format, Protoclo name/Protocol Version, eg: HTTP/1.1 */
*s++ = '\0';
via_list->object->proto_name = inet_msg_strdup(mem_func, text);
via_list->object->version = inet_msg_strdup(mem_func, s);
}
else
{
if (NULL == (s = kal_strtok_r(text, "/", &pp)))
{
return (kal_uint32) via_list_head;
}
via_list->object->proto_name = inet_msg_strdup(mem_func, s);
if (NULL == (s = kal_strtok_r(NULL, "/", &pp)))
{
return (kal_uint32) via_list_head;
}
via_list->object->version = inet_msg_strdup(mem_func, s);
if (NULL == (s = kal_strtok_r(NULL, " \t", &pp)))
{
return (kal_uint32) via_list_head;
}
via_list->object->transport = inet_msg_strdup(mem_func, s);
}
}
inet_msg_mime_skipws(&sentby);
if (!sentby || *sentby == '\0')
{
return (kal_uint32) via_list_head;
}
if (NULL != (param = strchr(sentby, ';')))
{
*param++ = '\0';
}
else if (NULL != (comment = strchr(sentby, ' ')))
{
*comment++ = '\0';
}
/* decode sent-by, eg "172.21.120.118:2412" */
if (NULL != (port = strchr(sentby, ':')))
{
*port++ = '\0';
}
via_list->object->host = inet_msg_strdup(mem_func, sentby);
if (port)
{
via_list->object->port = atoi(port);
}
if (param)
{
via_list->object->param_list = (inet_param_list_struct*) inet_msg_unpack_param(mem_func, param);
}
if (comment)
{
/* This is for HTTP protocol */
inet_msg_mime_skipws(&comment);
via_list->object->comment = inet_msg_strdup(mem_func, comment);
}
} while (next_token);
return (kal_uint32) via_list_head;
}
/*****************************************************************************
* FUNCTION
* inet_msg_unpack_cseq
* DESCRIPTION
* This function unpacks the CSeq.
*
* CSeq = "CSeq" HCOLON 1*DIGIT LWS Method
* Eg: "3574 REGISTER"
* PARAMETERS
* mem_func [IN] Memory function
* text [IN] String of field value
* RETURNS
* inet_cseq_struct pointer
*****************************************************************************/
kal_uint32 inet_msg_unpack_cseq(inet_mem_func_struct *mem_func, kal_char *text)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_char *s;
inet_cseq_struct *cseq = NULL;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* Shall skip the LWS in between sequence & method */
if (NULL == (s = strpbrk(text, " \t")))
{
return (kal_uint32) cseq;
}
*s++ = '\0';
inet_msg_mime_skipws(&s);
if (!s || *s == '\0')
{
return (kal_uint32) cseq;
}
if (NULL != (cseq = (inet_cseq_struct*) inet_malloc(mem_func, sizeof(inet_cseq_struct))))
{
cseq->seq = atoi(text);
cseq->method = inet_msg_unpack_method(s);
}
return (kal_uint32) cseq;
} /* end of sip_msg_unpack_cseq */
/*****************************************************************************
* FUNCTION
* inet_msg_unpack_param
* DESCRIPTION
* This function unpacks the param list.
* PARAMETERS
* mem_func [IN] Memory function
* text [IN] String of field value
* RETURNS
* recognized method : method type
* unrecognized method : SIP_UNRECOGNIZED_METHOD
*****************************************************************************/
kal_uint32 inet_msg_unpack_param(inet_mem_func_struct *mem_func, kal_char *text)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_char *s, *param;
inet_param_list_struct *list = (inet_param_list_struct*) inet_malloc(mem_func, sizeof(inet_param_list_struct));
inet_param_list_struct *list_orgin = list;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!list)
{
return (kal_uint32) list;
}
while (text)
{
if (NULL != (param = strchr(text, ';')))
{
*param++ = '\0';
}
inet_msg_skipcfws2(&text);
if (!text || *text == '\0')
{
break;
}
/* some parameters don't have value, eg, "lr" */
if (NULL != (s = strchr(text, '=')))
{
*s++ = '\0';
}
if (list && list->object)
{
list->next = (inet_param_list_struct*) inet_malloc(mem_func, sizeof(inet_param_list_struct));
list = list->next;
if (!list)
{
return (kal_uint32) list_orgin;
}
}
if (list->object == NULL)
{
list->object = (inet_param_struct*) inet_malloc(mem_func, sizeof(inet_param_struct));
if (list->object == NULL)
{
return (kal_uint32) list_orgin;
}
}
list->object->name = inet_msg_strdup(mem_func, text);
if (s)
{
/* inet_msg_mime_quote(s); */
list->object->value = inet_msg_strdup(mem_func, s);
}
text = param;
} /* while */
return (kal_uint32) list_orgin;
}
/*****************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -