📄 inet_msg_api.c
字号:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* inet_msg_api.c
*
* Project:
* --------
* MAUI
*
* Description:
* ------------
* This file contains public functions in inet message library.
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
#ifndef _INET_MSG_API_C
#define _INET_MSG_API_C
#ifdef INET_MSG_LIB_SUPPORT
/*****************************************************************************
* Include
*****************************************************************************/
#include <stdio.h>
#include "kal_release.h"
#include "inet_msg_cfg.h"
#include "inet_msg_def.h"
#include "inet_msg_struct.h"
#include "inet_msg_pack.h"
#include "inet_msg_unpack.h"
#include "inet_msg_api.h"
#include "inet_msg_mem.h"
#include "inet_msg_util.h"
#include "app_str.h"
#include "app_base64.h"
#include "app_md5.h"
/* Include: PS header file */
/* ... Add More PS header */
/*****************************************************************************
* Define
*****************************************************************************/
/*****************************************************************************
* Typedef
*****************************************************************************/
/*****************************************************************************
* Local Variable
*****************************************************************************/
extern const kal_char *const inet_method_name_table[INET_METHOD_NUM];
static kal_uint32 cnonce_base = 172953915;
/*****************************************************************************
* External Function
*****************************************************************************/
extern inet_result_enum inet_auth_calc_ha1(
inet_mem_func_struct *mem_func,
inet_auth_algorithm_enum algo,
kal_char *username,
kal_char *realm,
kal_char *password,
kal_char *nonce,
kal_char *cnonce,
kal_char **sessionKey);
inet_result_enum inet_auth_calc_digest_response(
inet_mem_func_struct *mem_func,
const kal_uint8 *HA1,
const kal_char *nonce,
const kal_char *nonce_count,
const kal_char *cnonce,
const inet_auth_qop_enum qop,
const kal_char *method,
const kal_char *digest_uri,
const kal_uint8 *HEntity,
kal_char **digest_in_authorization,
kal_char **digest_in_authentication_info);
inet_result_enum inet_auth_calc_hentity(
module_type mod_id,
inet_mem_func_struct *mem_func,
kal_uint8 *body_data,
kal_uint32 body_data_size,
kal_wchar *body_data_filepath,
kal_uint8 *hentity_md5_array,
kal_char **sessionKey);
/*****************************************************************************
* Local Function
*****************************************************************************/
/*****************************************************************************
* FUNCTION
* inet_msg_initialize
* DESCRIPTION
* This function initializes the INET instance.
* PARAMETERS
* mem_func [IN] memory allocation and release functions. Pls use ADM instead of control buffer!!!
* inet_msg [?]
* inet(?) [IN] used as returns
* RETURNS
* inet_result_enum reult
*****************************************************************************/
inet_result_enum inet_msg_initialize(inet_mem_func_struct *mem_func, inet_message_struct *inet_msg)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (mem_func == NULL || mem_func->alloc_fn == NULL || mem_func->free_fn == NULL || inet_msg == NULL)
{
return INET_RESULT_INVALID_PARAM;
}
kal_mem_set(inet_msg, 0, sizeof(inet_message_struct)); /* kevin */
inet_msg->mem_func.mod_id = mem_func->mod_id;
inet_msg->mem_func.alloc_fn = mem_func->alloc_fn;
inet_msg->mem_func.free_fn = mem_func->free_fn;
inet_msg->header_list = (inet_header_list_struct*) inet_malloc(mem_func, (sizeof(inet_header_list_struct)));
if (inet_msg->header_list == NULL)
{
return INET_RESULT_NO_MEMORY;
}
inet_msg->body_list = (inet_body_list_struct*) inet_malloc(mem_func, (sizeof(inet_body_list_struct)));
if (inet_msg->body_list == NULL)
{
mem_func->free_fn(inet_msg->header_list);
inet_msg->header_list = NULL; /* kevin */
return INET_RESULT_NO_MEMORY;
}
return INET_RESULT_OK;
}
/* add by kevin for saving memory by body removal */
/*****************************************************************************
* FUNCTION
* inet_msg_deinitialize_body
* DESCRIPTION
*
* PARAMETERS
* inet_msg [?]
* RETURNS
*
*****************************************************************************/
inet_result_enum inet_msg_deinitialize_body(inet_message_struct *inet_msg)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!inet_msg)
{
return INET_RESULT_NO_INET_MSG;
}
if (inet_msg->body_list)
{
inet_free_body_list(&inet_msg->mem_func, inet_msg->body_list);
inet_msg->body_list = NULL;
}
return INET_RESULT_OK;
}
/*****************************************************************************
* FUNCTION
* inet_msg_deinitialize
* DESCRIPTION
* This function de-initializes the INET instance.
* PARAMETERS
* inet_msg [?]
* inet(?) [IN] the inet message being deinitialized
* RETURNS
* inet_result_enum reult
*****************************************************************************/
inet_result_enum inet_msg_deinitialize(inet_message_struct *inet_msg)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!inet_msg)
{
return INET_RESULT_NO_INET_MSG;
}
if (inet_msg->header_list)
{
inet_free_header_list(&inet_msg->mem_func, inet_msg->header_list);
}
inet_msg_deinitialize_body(inet_msg);
return INET_RESULT_OK;
}
/*****************************************************************************
* FUNCTION
* inet_msg_unpack
* DESCRIPTION
* This function unpacks the INET message including two processes -
* one is header unpack and another is body unpack.
* PARAMETERS
* inet_msg [IN] A inet initialized message.
* app_type [IN] Inet application type, ex:SIP, HTTP and EMAIL
* unpack_mode [IN] unpack mode
* buffer [IN] buffer stores data being unpacked
* buffer_size [IN] buffer size
* filepath [IN] file stores data being unpacked. Both buffer and filepath can't be TRUE.
* folder_store_bodies [IN] a folder stores each body parsed from inet message.
* NOTES
* The body headers of 0st body are stored to inet_msg->header_list,
* not to inet_msg->body_list->object->header_list.
* If body is multipart format, 0st body object will not store any headers and body data.
* RETURNS
* inet_result_enum reult
*****************************************************************************/
inet_result_enum inet_msg_unpack(
inet_message_struct *inet_msg,
kal_uint8 app_type,
kal_uint16 unpack_mode,
kal_char *buffer,
kal_int32 buffer_size,
kal_wchar *filepath,
kal_wchar *folder_store_bodies)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
inet_mem_struct mem;
inet_result_enum ret;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
mem.buffer = buffer;
mem.pos = buffer;
mem.size = buffer_size;
/* Parse Request-Response Line and Headers */
ret = inet_msg_unpack_header(app_type, unpack_mode, inet_msg, &mem, INET_MSG_PROCESS_HEADER, 0);
if (ret != INET_RESULT_OK)
{
return ret;
}
/* Parse Body part */
if (unpack_mode & INET_MSG_UNPACK_BODY)
{
ret = inet_msg_unpack_body(app_type, unpack_mode, inet_msg, &mem);
}
return ret;
}
/*****************************************************************************
* FUNCTION
* inet_msg_pack_required_size
* DESCRIPTION
* This function calculates the required memory size to pack inet message.
* PARAMETERS
* inet_msg [IN] A inet initialized message.
* app_type [IN] application type
* pack_mode [IN] pack mode
* size [IN/OUT] size of memory required
* RETURNS
* INET result code
*****************************************************************************/
inet_result_enum inet_msg_pack_required_size(
inet_message_struct *inet_msg,
kal_uint8 app_type,
kal_uint16 pack_mode,
kal_int32 *size)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
inet_result_enum ret = INET_RESULT_ERROR;
kal_int32 req_resp_line_size = 0, hdr_size = 0, bdy_size = 0;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -