📄 inet_msg_api.c
字号:
* PARAMETERS
* mem_func [IN] memory allocation and release functions
* header_id [IN] Header field identifier
* src_header [IN] Source header field
* dst_header [IN/OUT] Created header field
* RETURNS
* inet_result_enum reult
*****************************************************************************/
inet_result_enum inet_msg_cp_header_field_alone(
inet_mem_func_struct *mem_func,
inet_header_field_enum header_id,
void *src_header,
void **dst_header)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!mem_func || header_id > INET_HDR_NUM)
{
return INET_RESULT_INVALID_PARAM;
}
*dst_header = inet_msg_header_val_struct_copy_fn(header_id) (mem_func, src_header);
if (!*dst_header)
{
return INET_RESULT_NO_MEMORY;
}
else
{
return INET_RESULT_OK;
}
}
/*****************************************************************************
* FUNCTION
* inet_msg_get_body_data
* DESCRIPTION
* This function gets the body data from the inet instance.
* PARAMETERS
* inet_msg [IN] The target inet message.
* body_num [IN] Body index
* buffer [IN/OUT] pointer points to body data
* buffer_size [IN/OUT] body data size
* filepath [IN/OUT] A path of file stores body data.
* RETURNS
* inet_result_enum reult
*****************************************************************************/
inet_result_enum inet_msg_get_body_data(
inet_message_struct *inet_msg,
kal_int32 body_num,
kal_char **buffer,
kal_int32 *buffer_size,
kal_wchar **filepath)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
inet_body_list_struct *body_list = inet_msg->body_list;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
body_num++;
while (body_list)
{
body_num--;
if (body_num == 0)
{
break;
}
body_list = body_list->next;
}
if (!body_list || body_num > 0)
{
return INET_RESULT_BODY_LIST_NOT_FOUND;
}
if (!body_list->object)
{
return INET_RESULT_BODY_NOT_FOUND;
}
if (body_list->object->body_buf)
{
ASSERT(buffer);
*buffer = body_list->object->body_buf;
if (buffer_size)
{
*buffer_size = body_list->object->body_len;
}
}
else if (body_list->object->body_file)
{
ASSERT(filepath);
*filepath = body_list->object->body_file;
}
else
{
if (buffer)
{
*buffer = NULL;
}
if (buffer_size)
{
*buffer_size = 0;
}
if (filepath)
{
*filepath = NULL;
}
return INET_RESULT_BODY_NOT_FOUND;
}
return INET_RESULT_OK;
}
/*****************************************************************************
* FUNCTION
* inet_msg_add_body_data
* DESCRIPTION
* This function specified the body data into the inet instance.
* PARAMETERS
* inet_msg [IN] The target inet message.
* body_num [IN] Body index
* buffer [IN/OUT] pointer points to body data
* buffer_size [IN/OUT] body data size
* filepath [IN/OUT] A path of file stores body data.
* NOTES
* If there is data in target body part in inet_msg, the function will overwrite it with new setting.
* RETURNS
* inet_result_enum reult
*****************************************************************************/
inet_result_enum inet_msg_add_body_data(
inet_message_struct *inet_msg,
kal_int32 body_num,
kal_char *buffer,
kal_int32 buffer_size,
kal_wchar *filepath)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (inet_msg)
{
inet_body_list_struct *body_list = inet_msg->body_list;
body_num++;
while (body_list)
{
body_num--;
if (body_num >= 0)
{
if (body_num > 0 && !body_list->next &&
NULL == (body_list->next =
(inet_body_list_struct*) inet_malloc(&inet_msg->mem_func, sizeof(inet_body_list_struct))))
{
return INET_RESULT_NO_MEMORY;
}
else if (!body_list->object &&
NULL == (body_list->object =
(inet_body_struct*) inet_malloc(&inet_msg->mem_func, sizeof(inet_body_struct))))
{
return INET_RESULT_NO_MEMORY;
}
}
if (body_num == 0)
{
break;
}
body_list = body_list->next;
}
if (!body_list)
{
return INET_RESULT_BODY_LIST_NOT_FOUND;
}
if (body_list->object->body_buf)
{
inet_mfree(&inet_msg->mem_func, body_list->object->body_buf);
body_list->object->body_buf = NULL;
}
if (body_list->object->body_file)
{
/* To-Do: Delete body data file. */
inet_mfree(&inet_msg->mem_func, body_list->object->body_file);
body_list->object->body_file = NULL;
}
if (buffer && buffer_size > 0)
{
body_list->object->body_buf = buffer;
if (*(buffer + buffer_size - 1) == '\0')
{
body_list->object->body_len = buffer_size - 1;
}
else
{
body_list->object->body_len = buffer_size;
}
return INET_RESULT_OK;
}
else if (filepath)
{
kal_int32 size = app_ucs2_strlen((kal_int8*) filepath);
if (NULL == (body_list->object->body_file = (kal_wchar*) inet_malloc(&inet_msg->mem_func, size + 1)))
{
return INET_RESULT_NO_MEMORY;
}
app_ucs2_strcpy((kal_int8*) body_list->object->body_file, (kal_int8*) filepath);
return INET_RESULT_OK;
}
return INET_RESULT_OK;
}
else
{
return INET_RESULT_NO_INET_MSG;
}
}
/*****************************************************************************
* FUNCTION
* inet_msg_rm_body_file
* DESCRIPTION
* This function removed specified the body file from the inet instance.
* PARAMETERS
* inet_msg [IN] The target inet message.
* body_num [IN] Body index
* NOTES
* This function only clears body data. Body headers must be cleared by inet_free_header_list()*
* RETURNS
* inet_result_enum reult
*****************************************************************************/
inet_result_enum inet_msg_rm_body_file(inet_message_struct *inet_msg, kal_int32 body_num)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int32 bdy_num = body_num;
inet_body_list_struct *body_list;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!inet_msg)
{
return INET_RESULT_INVALID_PARAM;
}
body_list = inet_msg->body_list;
bdy_num++;
while (body_list)
{
bdy_num--;
if (bdy_num == 0)
{
break;
}
body_list = body_list->next;
}
if (!body_list || bdy_num > 0)
{
return INET_RESULT_BODY_LIST_NOT_FOUND;
}
if (!body_list->object)
{
return INET_RESULT_BODY_NOT_FOUND;
}
if (body_list->object->body_buf)
{
inet_mfree(&inet_msg->mem_func, body_list->object->body_buf);
body_list->object->body_buf = NULL;
}
if (body_list->object->body_file)
{
/* To-Do: Delete file */
inet_mfree(&inet_msg->mem_func, body_list->object->body_file);
body_list->object->body_file = NULL;
}
body_list->object->body_len = 0;
return INET_RESULT_OK;
}
/*****************************************************************************
* FUNCTION
* inet_msg_cp_body_part
* DESCRIPTION
* This function copies the specified INET header from the inet_src to inet_dst.
* Note that if the content of body being copied is provided by file, the function will not create another file.
* It just copies content filepath to dstinet message. If the content of body being copied is provided by memory,
* it will copy data from the memory to new buffer and insert the buffer to dst ine message.
* PARAMETERS
* app_type [IN] application type
* inet_src_msg [IN] The source inet message.
* inet_dst_msg [IN] The target inet message.
* src_body_num [IN] source body index
* dst_body_num [IN] destination body index
* RETURNS
* inet_result_enum reult
*****************************************************************************/
inet_result_enum inet_msg_cp_body_part(
kal_uint8 app_type,
inet_message_struct *inet_src_msg,
inet_message_struct *inet_dst_msg,
kal_int32 src_body_num,
kal_int32 dst_body_num)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_char *buf = NULL;
kal_int32 buf_size = 0;
kal_int32 bdy_num = src_body_num;
inet_result_enum ret;
inet_body_list_struct *src_body_list = NULL;
inet_body_list_struct *dst_body_list = NULL;
inet_header_list_struct *hdr_list = NULL;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!inet_src_msg || src_body_num < 0 || dst_body_num < 0)
{
return INET_RESULT_INVALID_PARAM;
}
src_body_list = inet_src_msg->body_list;
bdy_num++;
while (src_body_list)
{
bdy_num--;
if (bdy_num == 0)
{
break;
}
src_body_list = src_body_list->next;
}
if (!src_body_list || bdy_num > 0)
{
return INET_RESULT_BODY_LIST_NOT_FOUND;
}
if (!src_body_list->object)
{
return INET_RESULT_BODY_NOT_FOUND;
}
ret = INET_RESULT_OK;
if (src_body_list->object->body_buf && src_body_list->object->body_len > 0)
{
buf = inet_dst_msg->mem_func.all
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -