inet_msg_pack.c

来自「最新MTK手机软件源码」· C语言 代码 · 共 1,737 行 · 第 1/5 页

C
1,737
字号
/*****************************************************************************
*  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_pack.c
 *
 * Project:
 * --------
 *   MAUI
 *
 * Description:
 * ------------
 *   This file contains INET message pack function.
 *
 * 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!
 *
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/
#ifndef _INET_MSG_PACK_C
#define _INET_MSG_PACK_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_mem.h"
#include "inet_msg_util.h"
#include "inet_msg_api.h"
#include "inet_msg_res.h"
#include "inet_msg_pack.h"
#include "inet_msg_app.h"

#include "app_datetime.h"

extern const kal_char *const inet_uri_table[INET_URI_SCHEME_NUM];

#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* 0 */ 


/*****************************************************************************
 * FUNCTION
 *  inet_msg_pack_authorization
 * DESCRIPTION
 *  This function packs the inet_uri_struct header value.
 * PARAMETERS
 *  app_type        [IN]            application type
 *  arg             [IN]            pointer of header value
 *  buf             [IN]            buffer to store packed header value
 *  buf_len         [IN]            available data size of buffer
 *  r_size          [IN/OUT]        real data size to pack
 * RETURNS
 *  INET result code
 *****************************************************************************/
/* sip:172.21.120.203:5070 */
inet_result_enum inet_msg_pack_authorization(
                    kal_uint8 app_type,
                    void *arg,
                    kal_char *buf,
                    kal_int32 buf_len,
                    kal_int32 *r_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    inet_authorization_struct *authorization = (inet_authorization_struct*) arg;
    kal_int32 l = 0, m = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    *r_size = 0;

    CHECK_INET_PARAM(arg, INET_RESULT_ERROR)
        if ((authorization->auth_type == INET_AUTH_DIGEST && (authorization->digest_uri == NULL ||
                                                              authorization->realm == NULL ||
                                                              authorization->username == NULL)))
    {
        return INET_RESULT_INVALID_PARAM;
    }
    if (authorization->auth_type == INET_AUTH_BASIC)
    {
        if (authorization->response == NULL)
        {
            return INET_RESULT_INVALID_PARAM;
        }
        l = _snprintf(buf, buf_len, "Basic %s", authorization->response);
    CHECK_INET_PACK_ENBUF(l)}
    else if (authorization->auth_type == INET_AUTH_DIGEST)
    {
        if (authorization->nonce)   /* kevin */
        {
            m = _snprintf(
                    buf,
                    buf_len,
                    "Digest username=\"%s\",realm=\"%s\",nonce=\"%s\",uri=\"%s\"",
                    authorization->username,
                    authorization->realm,
                    authorization->nonce,
                    authorization->digest_uri);
        }
        else
        {
            m = _snprintf(
                    buf,
                    buf_len,
                    "Digest username=\"%s\",realm=\"%s\",nonce=\"\",uri=\"%s\"",
                    authorization->username,
                    authorization->realm,
                    authorization->digest_uri);
        }

        CHECK_INET_PACK_ENBUF(m) l += m;
        if (authorization->qop == INET_AUTH_QOP_AUTH)
        {
            m = _snprintf(buf + l, buf_len - l, "%s", ",qop=auth");
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
        else if (authorization->qop == INET_AUTH_QOP_AUTH)
        {
            m = _snprintf(buf + l, buf_len - l, "%s", ",qop=auth_int");
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
        if (authorization->algo == INET_AUTH_ALGO_MD5)
        {
            m = _snprintf(buf + l, buf_len - l, "%s", ",algorithm=MD5");
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
        else if (authorization->algo == INET_AUTH_ALGO_MD5_SESS)
        {
            m = _snprintf(buf + l, buf_len - l, "%s", ",algorithm=MD5-sess");
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
        if (authorization->nc)
        {
            m = _snprintf(buf + l, buf_len - l, ",nc=%s", authorization->nc);
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
        if (authorization->cnonce)
        {
            m = _snprintf(buf + l, buf_len - l, ", cnonce=%s", authorization->cnonce);
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
        if (authorization->response)
        {
            m = _snprintf(buf + l, buf_len - l, ", response=\"%s\"", authorization->response);
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
        else
        {
            m = _snprintf(buf + l, buf_len - l, ", response=\"\"");
        }
        if (authorization->opaque)
        {
            m = _snprintf(buf + l, buf_len - l, ", opaque=\"%s\"", authorization->opaque);
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
    }
    else
    {
        return INET_RESULT_ERROR;
    }

    *r_size = l;
    return INET_RESULT_OK;
}   /* end of inet_msg_pack_authorization */


/*****************************************************************************
 * FUNCTION
 *  inet_msg_pack_authenticate
 * DESCRIPTION
 *  This function packs the inet_uri_struct header value.
 * PARAMETERS
 *  app_type        [IN]            application type
 *  arg             [IN]            pointer of header value
 *  buf             [IN]            buffer to store packed header value
 *  buf_len         [IN]            available data size of buffer
 *  r_size          [IN/OUT]        real data size to pack
 * RETURNS
 *  INET result code
 *****************************************************************************/
/* sip:172.21.120.203:5070 */
inet_result_enum inet_msg_pack_authenticate(

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?