📄 inet_msg_unpack.c
字号:
* FUNCTION
* inet_msg_unpack_integer
* DESCRIPTION
* This function create an new string.
* PARAMETERS
* mem_func [IN] Memory function
* text [IN] String of field value
* RETURNS
* memory pointer
*****************************************************************************/
kal_uint32 inet_msg_unpack_integer(inet_mem_func_struct *mem_func, kal_char *text)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
return (kal_uint32) atoi(text);
} /* end of inet_msg_unpack_integer */
/*****************************************************************************
* FUNCTION
* inet_msg_unpack_string
* DESCRIPTION
* This function create an new string.
* PARAMETERS
* mem_func [IN] Memory function
* text [IN] String of field value
* RETURNS
* memory pointer
*****************************************************************************/
kal_uint32 inet_msg_unpack_string(inet_mem_func_struct *mem_func, kal_char *text)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
return (kal_uint32) inet_msg_strdup(mem_func, text);
} /* end of inet_msg_unpack_string */
/*****************************************************************************
* FUNCTION
* inet_msg_unpack_content_range
* DESCRIPTION
* This function is used to unpack content_range.
* PARAMETERS
* mem_func [IN] Memory function
* text [IN] String of field value
* RETURNS
* memory pointer
*****************************************************************************/
kal_uint32 inet_msg_unpack_content_range(inet_mem_func_struct *mem_func, kal_char *text)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_char *s, *s2;
inet_content_range_struct *content_range =
(inet_content_range_struct*) inet_malloc(mem_func, sizeof(inet_content_range_struct));
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!content_range)
{
goto exit_err;
}
if ((s = strchr(text, ' ')) == NULL)
{
goto exit_err;
}
*s++ = '\0';
/* retrieve bytes-uint */
if ((content_range->unit_name = inet_msg_strdup(mem_func, text)) == NULL)
{
goto exit_err;
}
inet_msg_skipcfws(&s);
if ((text = strchr(s, '/')) == NULL)
{
goto exit_err;
}
*text++ = '\0';
if ((s2 = strchr(s, '-')) != NULL)
{
*s2++ = '\0';
content_range->first_pos = atoi(s);
content_range->last_pos = atoi(s2);
}
else
{
content_range->first_pos = -1;
content_range->last_pos = -1;
}
inet_msg_skipcfws(&text);
if (*text != '\0' && *text != '*')
{
content_range->instance_length = atoi(text);
}
else
{
content_range->instance_length = -1;
}
return (kal_uint32) content_range;
exit_err:
if (content_range)
{
inet_content_range_struct_free_fn(mem_func, content_range);
}
return 0;
} /* end of inet_msg_unpack_content_range */
/*****************************************************************************
* FUNCTION
* inet_msg_unpack_cookie
* DESCRIPTION
*
* PARAMETERS
* mem_func [?]
* text [?]
* version [IN]
* RETURNS
*
*****************************************************************************/
kal_uint32 inet_msg_unpack_cookie(inet_mem_func_struct *mem_func, kal_char *text, kal_int8 version)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_char *s, *param, *next_token = NULL;
inet_cookie_list_struct *cookie_list_head =
(inet_cookie_list_struct*) inet_malloc(mem_func, sizeof(inet_cookie_list_struct));
inet_cookie_list_struct *cookie_list = cookie_list_head;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!cookie_list)
{
return (kal_uint32) cookie_list;
}
while (text)
{
/* Version 0:Set-Cookie header always has one cookie.
Version 1:Set-Cookies2 may have several cookies, seperated by ',' */
if (next_token == NULL && version == 1)
{
next_token = inet_msg_get_next_token(text);
}
if (NULL != (param = strchr(text, ';')))
{
*param++ = '\0';
}
else if (*text == '\0')
{
return (kal_uint32) cookie_list_head;
}
inet_msg_mime_skipws(&text);
if (!text || *text == '\0')
{
break;
}
/* some parameters don't have value, eg, "lr" */
if (NULL != (s = strchr(text, '=')))
{
*s++ = '\0';
}
if (cookie_list->object == NULL)
{
cookie_list->object = (inet_cookie_struct*) inet_malloc(mem_func, sizeof(inet_cookie_struct));
cookie_list->object->version = version;
if (cookie_list->object == NULL)
{
return (kal_uint32) cookie_list_head;
}
}
if (inet_msg_compare_cstring(text, "Comment") == 0)
{
if (s)
{
if (cookie_list->object->comment)
{
inet_mfree(mem_func, cookie_list->object->comment);
}
cookie_list->object->comment = inet_msg_strdup(mem_func, s);
}
}
else if (inet_msg_compare_cstring(text, "CommentURL") == 0)
{
if (s)
{
inet_msg_mime_quote(s);
if (cookie_list->object->comment_url)
{
inet_mfree(mem_func, cookie_list->object->comment_url);
}
cookie_list->object->comment_url = inet_msg_strdup(mem_func, s);
}
}
else if (inet_msg_compare_cstring(text, "Max-Age") == 0)
{
if (s)
{
cookie_list->object->max_age = atoi(s);
if (cookie_list->object->max_age == 0)
{
cookie_list->object->max_age = -1;
}
}
}
else if (inet_msg_compare_cstring(text, "expires") == 0)
{
if (s)
{
applib_dt_rfc1123_rfc850_asctime_dateString2Time(s, &cookie_list->object->expiry_time);
}
}
else if (inet_msg_compare_cstring(text, "Path") == 0)
{
if (s)
{
if (cookie_list->object->path)
{
inet_mfree(mem_func, cookie_list->object->path);
}
cookie_list->object->path = inet_msg_strdup(mem_func, s);
}
}
else if (inet_msg_compare_cstring(text, "Port") == 0)
{
kal_char *str, *comma;
inet_msg_mime_quote(s);
str = s;
while ((comma = strchr(str, ',')) != NULL)
{
*comma = '\0';
inet_msg_add_int_object_to_list(mem_func, &cookie_list->object->portlist, atoi(str));
str = comma + 1;
}
inet_msg_add_int_object_to_list(mem_func, &cookie_list->object->portlist, atoi(str));
}
else if (inet_msg_compare_cstring(text, "Secure") == 0)
{
cookie_list->object->secure = KAL_TRUE;
}
else if (inet_msg_compare_cstring(text, "Discard") == 0)
{
cookie_list->object->discard = KAL_TRUE;
}
else if (inet_msg_compare_cstring(text, "Version") == 0)
{
if (s)
{
cookie_list->object->version = atoi(s);
}
}
else if (inet_msg_compare_cstring(text, "Domain") == 0)
{
if (s)
{
if (cookie_list->object->domain)
{
inet_mfree(mem_func, cookie_list->object->domain);
}
cookie_list->object->domain = inet_msg_strdup(mem_func, s);
}
}
else
{
/* cookie name and value */
cookie_list->object->version = version;
cookie_list->object->name = inet_msg_strdup(mem_func, text);
if (s)
{
cookie_list->object->value = inet_msg_strdup(mem_func, s);
}
}
text = param;
if (next_token && text == NULL && version == 1)
{
text = next_token;
next_token = NULL;
/* Create one cookie object */
cookie_list->next = (inet_cookie_list_struct*) inet_malloc(mem_func, sizeof(inet_cookie_list_struct));
if (cookie_list->next == NULL)
{
return (kal_uint32) cookie_list_head;
}
cookie_list->next->object = (inet_cookie_struct*) inet_malloc(mem_func, sizeof(inet_cookie_struct));
if (cookie_list->next->object == NULL)
{
return (kal_uint32) cookie_list_head;
}
if (cookie_list->object->path == NULL)
{
ASSERT((cookie_list->object->path = inet_msg_strdup(mem_func, "/")) != NULL);
}
cookie_list = cookie_list->next;
}
} /* while */
return (kal_uint32) cookie_list_head;
}
/*****************************************************************************
* FUNCTION
* inet_msg_unpack_if_range
* DESCRIPTION
* This function is used to unpack If-Range.
* PARAMETERS
* mem_func [IN] Memory function
* text [IN] String of field value
* RETURNS
* memory pointer
*****************************************************************************/
kal_uint32 inet_msg_unpack_if_range(inet_mem_func_struct *mem_func, kal_char *text)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
inet_int_str_struct *if_range = NULL;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (text == NULL)
{
return 0;
}
if_range = (inet_int_str_struct*) inet_malloc(mem_func, sizeof(inet_int_str_struct));
if (if_range == NULL)
{
goto exit_err;
}
if (applib_dt_rfc1123_rfc850_asctime_dateString2Time(text, (kal_uint32*) & if_range->int_value) == KAL_FALSE)
{
if_range->str_value = inet_msg_strdup(mem_func, text);
if (if_range->str_value == NULL)
{
goto exit_err;
}
}
return (kal_uint32) if_range;
exit_err:
if (if_range)
{
inet_int_str_struct_free_fn(mem_func, if_range);
}
return 0;
} /* end of inet_msg_unpack_if_range */
/*****************************************************************************
* FUNCTION
* inet_msg_unpack_set_cookie_v1
* DESCRIPTION
* This function is used to unpack version 0 cookies.
* PARAMETERS
* mem_func [IN] Memory function
* text [IN] String of field value
* RETURNS
* memory pointer
*****************************************************************************/
kal_uint32 inet_msg_unpack_set_cookie_v1(inet_mem_func_struct *mem_func, kal_char *text)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
return inet_msg_unpack_cookie(mem_func, text, 0);
}
/*****************************************************************************
* FUNCTION
* inet_msg_unpack_set_cookie_v2
* DESCRIPTION
* This function is used to unpack version 1 cookies. (RFC2965)
* PARAMETERS
* mem_func [IN] Memory function
* text [IN] String of field value
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -