📄 inet_msg_api.c
字号:
if (pack_mode & INET_MSG_PACK_REQ_STATUS_LINE)
{
ret = inet_msg_pack_req_status_line_required_size(app_type, inet_msg, &req_resp_line_size);
if (ret != INET_RESULT_OK)
{
return ret;
}
}
if (pack_mode & INET_MSG_PACK_HEADER)
{
ret = inet_msg_pack_header_list_required_size(app_type, &inet_msg->mem_func, inet_msg->header_list, &hdr_size);
if (ret != INET_RESULT_OK)
{
return ret;
}
}
if (pack_mode & INET_MSG_PACK_BODY)
{
ret = inet_msg_pack_body_required_size(app_type, inet_msg, &bdy_size);
if (ret != INET_RESULT_OK)
{
return ret;
}
}
*size = req_resp_line_size + hdr_size + bdy_size + 1; /* '\0' */
return ret;
}
/*****************************************************************************
* FUNCTION
* inet_msg_pack
* DESCRIPTION
* This function packs the INET message from inet instance to the given buffer or filepath.
* PARAMETERS
* inet_msg [IN] A inet initialized message being packed.
* app_type [IN] Inet application type, ex:SIP, HTTP and EMAIL
* pack_mode [IN] pack mode
* buffer [IN] buffer stores data being packed
* buffer_size [IN] buffer size
* filepath [IN] file stores data being packed. Both buffer and filepath can't be TRUE.
* RETURNS
* inet_result_enum reult
*****************************************************************************/
inet_result_enum inet_msg_pack(
inet_message_struct *inet_msg,
kal_uint8 app_type,
kal_uint16 pack_mode,
kal_char *buffer,
kal_int32 buffer_size,
kal_wchar *filepath)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
inet_result_enum ret = INET_RESULT_ERROR;
kal_char *buf = buffer;
kal_int32 buf_len = buffer_size;
kal_int32 size = 0, l;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (pack_mode & INET_MSG_PACK_REQ_STATUS_LINE)
{
l = 0;
ret = inet_msg_pack_req_status_line(app_type, inet_msg, buf, buf_len, &l);
if (ret != INET_RESULT_OK)
{
return ret;
}
if (size + 2 >= buf_len) /* We have to append \r\n to buf */
{
return INET_RESULT_NO_MEMORY;
}
size += l;
*(buf + size) = '\r';
*(buf + size + 1) = '\n';
size += 2;
}
if (pack_mode & INET_MSG_PACK_HEADER)
{
l = 0;
ret = inet_msg_pack_header(app_type, pack_mode, inet_msg->header_list, buf + size, buf_len - size, filepath, &l);
if (ret != INET_RESULT_OK)
{
return ret;
}
size += l;
}
if (pack_mode & INET_MSG_PACK_BODY)
{
l = 0;
ret = inet_msg_pack_body(inet_msg, app_type, pack_mode, buf + size, buf_len - size, filepath, &l);
if (ret != INET_RESULT_OK)
{
return ret;
}
size += l;
}
if ((buf_len - size) < 1) /* kevin */
{
return INET_RESULT_NO_MEMORY;
}
*(buf + size) = '\0';
return ret;
}
/*****************************************************************************
* FUNCTION
* inet_msg_is_request
* DESCRIPTION
* This function indicates whether the inet message is a request or a response.
* PARAMETERS
* inet_msg [?]
* app_type [IN] Inet application type, ex:SIP, HTTP and EMAIL
* inet(?) [IN] A inet unpacked message.
* RETURNS
* kal_bool reult
*****************************************************************************/
kal_bool inet_msg_is_request(inet_message_struct *inet_msg, kal_uint8 app_type)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (inet_msg_get_header_field_num(inet_msg, INET_MSG_PROCESS_HEADER, 0, INET_HDR_METHOD, NULL) > 0)
{
return KAL_TRUE;
}
else
{
return KAL_FALSE;
}
}
/*****************************************************************************
* FUNCTION
* inet_msg_get_header_field_num
* DESCRIPTION
* This function returns the number of specific INET header field. In most cases,
* there are no duplicate headers. However, some headers may be more than one, ex: via.
* PARAMETERS
* inet_msg [?]
* process_part [IN] Header or body
* body_num [IN] Body index
* header_id [IN] Header field identifier
* header_name [IN] Unsupported header field name
* inet(?) [IN] A inet unpacked message.
* RETURNS
* kal_int32 number of duplicate headers
*****************************************************************************/
kal_int32 inet_msg_get_header_field_num(
inet_message_struct *inet_msg,
kal_uint8 process_part,
kal_int32 body_num,
inet_header_field_enum header_id,
kal_char *header_name)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
inet_header_list_struct *hdr_list = NULL;
kal_int32 count = 0;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!inet_msg)
{
return 0;
}
if (process_part == INET_MSG_PROCESS_HEADER)
{
hdr_list = inet_msg->header_list;
}
else
{
inet_body_list_struct *body_list = inet_msg->body_list;
{
body_num++;
while (body_list)
{
body_num--;
if (body_num == 0)
{
if (!body_list || !body_list->object || body_list->object->header_list)
{
return 0;
}
else
{
hdr_list = body_list->object->header_list;
}
}
body_list = body_list->next;
}
}
}
while (hdr_list)
{
if (hdr_list->object && hdr_list->object->header_id == header_id)
{
if (hdr_list->object->header_name)
{
if (header_name)
{
if (!inet_msg_compare_cstring(hdr_list->object->header_name, header_name))
{
count++;
break;
}
}
}
else
{
count++;
break;
}
}
hdr_list = hdr_list->next;
}
if (count > 0 && hdr_list)
{
inet_header_struct *hdr = hdr_list->object->next_dup_hdr;
while (hdr)
{
count++;
hdr = hdr->next_dup_hdr;
}
}
return count;
}
/* */
/*****************************************************************************
* FUNCTION
* inet_msg_get_header_field
* DESCRIPTION
* This function is used to retrieve one header from a inet instance.
* If INET_MSG_HEADER_STRUCTURE is present in header_value_form,
* this function just save the header value pointer to header_value pointer.
* It INET_MSG_HEADER_STRING is present in header_value_form,
* this function will allocate string buffer to store this header value in inet instance.
* PARAMETERS
* app_type [IN] Inet application type, ex:SIP, HTTP and EMAIL
* inet_msg [?]
* process_part [IN] Header or body
* index_of_dup_headers [IN] index in duplicate headers
* body_num [IN] Body index
* header_id [IN] Header field identifier
* header_name [IN] Unsupported header field name
* header_value_form [IN] format of header value , STRUCT or STRING
* header_value [IN/OUT] header value or pointer
* inet(?) [IN] A inet unpacked message.
* RETURNS
* inet_result_enum reult
*****************************************************************************/
inet_result_enum inet_msg_get_header_field(
kal_uint8 app_type,
inet_message_struct *inet_msg,
kal_uint8 process_part,
kal_int32 index_of_dup_headers,
kal_int32 body_num,
inet_header_field_enum header_id,
kal_char *header_name,
kal_uint8 header_value_form,
kal_uint32 *header_value)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (inet_msg)
{
inet_header_list_struct *hdr_list = NULL;
inet_header_struct *dup_hdr_list = NULL;
if (index_of_dup_headers < 0)
{
return INET_RESULT_HEADER_NOT_FOUND;
}
if (process_part == INET_MSG_PROCESS_HEADER)
{
hdr_list = inet_msg->header_list;
}
else
{
inet_body_list_struct *body_list = inet_msg->body_list;
{
body_num++;
while (body_list)
{
body_num--;
if (body_num == 0)
{
if (body_list == NULL || body_list->object == NULL || body_list->object->header_list == NULL)
{
return INET_RESULT_HEADER_LIST_NOT_FOUND;
}
else
{
hdr_list = body_list->object->header_list;
break;
}
}
body_list = body_list->next;
}
}
}
while (hdr_list)
{
if (hdr_list->object)
{
if (hdr_list->object->header_id == header_id)
{
if (!hdr_list->object->header_name)
{
break;
}
else if (!inet_msg_compare_cstring(hdr_list->object->header_name, header_name))
{
break;
}
}
}
hdr_list = hdr_list->next;
}
if (!hdr_list)
{
return INET_RESULT_HEADER_NOT_FOUND;
}
/* search duplicate header list */
dup_hdr_list = hdr_list->object;
index_of_dup_headers--;
while (index_of_dup_headers >= 0 && dup_hdr_list)
{
index_of_dup_headers--;
dup_hdr_list = dup_hdr_list->next_dup_hdr;
}
if (!dup_hdr_list)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -