📄 inet_msg_util.c
字号:
inet_param_list_struct **list,
kal_char *name,
kal_char *value)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
inet_param_list_struct *new_obj;
inet_param_list_struct *t_list;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (list == NULL || name == NULL)
{
return KAL_FALSE;
}
t_list = *list;
new_obj = (inet_param_list_struct*) INET_MEM_ALLOC(sizeof(inet_param_list_struct));
if (new_obj == NULL)
{
return KAL_FALSE;
}
new_obj->object = (inet_param_struct*) INET_MEM_ALLOC(sizeof(inet_param_struct));
if (new_obj->object == NULL)
{
goto exit_err;
}
new_obj->object->name = inet_msg_strdup(mem_func, name);
if (new_obj->object->name == NULL)
{
goto exit_err;
}
if (value)
{
new_obj->object->value = inet_msg_strdup(mem_func, value);
if (new_obj->object->value == NULL)
{
goto exit_err;
}
}
if (t_list == NULL)
{
*list = new_obj;
return KAL_TRUE;
}
while (t_list->next)
{
t_list = t_list->next;
}
t_list->next = new_obj;
return KAL_TRUE;
exit_err:
inet_param_list_struct_free_fn(mem_func, new_obj);
return KAL_FALSE;
}
/*****************************************************************************
* FUNCTION
* inet_msg_rm_param_object_from_list
* DESCRIPTION
*
* PARAMETERS
* mem_func [?]
* list [IN]
* name [?]
* value [?]
* RETURNS
*
*****************************************************************************/
kal_bool inet_msg_rm_param_object_from_list(
inet_mem_func_struct *mem_func,
inet_param_list_struct **list,
kal_char *name,
kal_char *value /* could be null */ )
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
inet_param_list_struct *t_list;
inet_param_list_struct *p_list = NULL; /* previous */
inet_param_list_struct *n_list; /* next */
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (list == NULL || name == NULL)
{
return KAL_FALSE;
}
t_list = *list;
while (t_list)
{
if (t_list->object &&
!strcmp(t_list->object->name, name) &&
(!value || (t_list->object->value && !strcmp(t_list->object->value, value))))
{
n_list = t_list->next;
if (p_list)
{
p_list->next = n_list;
}
else
{
*list = n_list;
}
inet_param_struct_free_fn(mem_func, t_list->object);
inet_mfree(mem_func, t_list);
return KAL_TRUE;
}
p_list = t_list;
t_list = t_list->next;
}
return KAL_FALSE;
}
/*****************************************************************************
* FUNCTION
* inet_msg_get_param_object_num
* DESCRIPTION
*
* PARAMETERS
* list [?]
* RETURNS
*
*****************************************************************************/
kal_int32 inet_msg_get_param_object_num(inet_param_list_struct *list)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int32 num = 0; /* reset */
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
while (list && list->object)
{
num++;
list = list->next;
}
return num;
}
/*****************************************************************************
* FUNCTION
* inet_msg_add_int_object_to_list
* DESCRIPTION
*
* PARAMETERS
* mem_func [?]
* list [IN]
* int_val [IN]
* RETURNS
*
*****************************************************************************/
kal_bool inet_msg_add_int_object_to_list(
inet_mem_func_struct *mem_func,
inet_int_list_struct **list,
kal_int32 int_val)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
inet_int_list_struct *ptr;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (list == NULL)
{
return KAL_FALSE;
}
ptr = *list;
if (ptr == NULL)
{
ptr = (inet_int_list_struct*) INET_MEM_ALLOC(sizeof(inet_int_list_struct));
if (ptr == NULL)
{
return KAL_FALSE;
}
*list = ptr;
}
else
{
while (ptr->next)
{
ptr = ptr->next;
}
ptr->next = (inet_int_list_struct*) INET_MEM_ALLOC(sizeof(inet_int_list_struct));
if (ptr->next == NULL)
{
return KAL_FALSE;
}
ptr = ptr->next;
}
ptr->value = int_val;
return KAL_TRUE;
}
/*****************************************************************************
* FUNCTION
* inet_msg_add_str_object_to_list
* DESCRIPTION
*
* PARAMETERS
* mem_func [?]
* list [IN]
* str_val [?]
* RETURNS
*
*****************************************************************************/
kal_bool inet_msg_add_str_object_to_list(
inet_mem_func_struct *mem_func,
inet_str_list_struct **list,
kal_char *str_val)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
inet_str_list_struct *new_obj;
inet_str_list_struct *t_list;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (list == NULL || str_val == NULL)
{
return KAL_FALSE;
}
t_list = *list;
new_obj = (inet_str_list_struct*) INET_MEM_ALLOC(sizeof(inet_str_list_struct));
if (new_obj == NULL)
{
return KAL_FALSE;
}
new_obj->value = inet_msg_strdup(mem_func, str_val);
if (new_obj->value == NULL)
{
return KAL_FALSE;
}
if (t_list == NULL)
{
*list = new_obj;
return KAL_TRUE;
}
while (t_list->next)
{
t_list = t_list->next;
}
t_list->next = new_obj;
return KAL_TRUE;
}
/*****************************************************************************
* FUNCTION
* inet_msg_add_int_str_object_to_list
* DESCRIPTION
*
* PARAMETERS
* mem_func [?]
* list [?]
* int_val [IN]
* str_val [?]
* RETURNS
*
*****************************************************************************/
kal_bool inet_msg_add_int_str_object_to_list(
inet_mem_func_struct *mem_func,
inet_int_str_list_struct *list,
kal_int32 int_val,
kal_char *str_val)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
inet_int_str_list_struct *t_list = list;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (t_list == NULL)
{
return KAL_FALSE;
}
while (t_list)
{
if (NULL != t_list->object)
{
if (NULL == t_list->next)
{
t_list->next = (inet_int_str_list_struct*) INET_MEM_ALLOC(sizeof(inet_int_str_list_struct));
if (t_list->next == NULL)
{
return KAL_FALSE;
}
}
t_list = t_list->next;
}
else
{
t_list->object = (inet_int_str_struct*) INET_MEM_ALLOC(sizeof(inet_int_str_struct));
if (t_list->object == NULL)
{
return KAL_FALSE;
}
t_list->object->int_value = int_val;
if (str_val)
{
t_list->object->str_value = inet_msg_strdup(mem_func, str_val);
if (NULL == t_list->object->str_value)
{
inet_mfree(mem_func, t_list->object);
return KAL_FALSE;
}
}
return KAL_TRUE;
}
}
return KAL_FALSE;
}
/*****************************************************************************
* FUNCTION
* inet_msg_add_cookie_to_list
* DESCRIPTION
*
* PARAMETERS
* mem_func [?]
* list [IN]
* cookie [?]
* RETURNS
*
*****************************************************************************/
kal_bool inet_msg_add_cookie_to_list(
inet_mem_func_struct *mem_func,
inet_cookie_list_struct **list,
inet_cookie_struct *cookie)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
inet_cookie_list_struct *list_ptr;
inet_cookie_struct *cookie_ptr;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (list == NULL || cookie == NULL)
{
return KAL_FALSE;
}
list_ptr = (inet_cookie_list_struct*) INET_MEM_ALLOC(sizeof(inet_cookie_list_struct));
cookie_ptr = (inet_cookie_struct*) inet_cookie_struct_copy_fn(mem_func, cookie);
if (list_ptr == NULL || cookie_ptr == NULL)
{
if (list_ptr != NULL)
{
INET_MEM_FREE(list_ptr);
}
else if (cookie_ptr != NULL)
{
inet_cookie_struct_free_fn(mem_func, cookie_ptr);
}
return KAL_FALSE;
}
list_ptr->object = cookie_ptr;
if (*list == NULL)
{
*list = list_ptr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -