⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jam_policy.c

📁 java 1.1 gemini 08_16
💻 C
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************
*  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) 2001
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 *   jam_policy.c
 *
 * Project:
 * --------
 *   Maui_Software
 *
 * Description:
 * ------------
 *   This file includes utilities to retrieve and modify permission setting in 
 *   _policy.txt
 *
 * 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!!
 *============================================================================
  ****************************************************************************/

/*************************************************************************
 * Include Header Files
 *************************************************************************/
#include "jal.h"
#include "jam_policy.h"
#include "jam_msg_util.h"
#include "j2me_custom.h"
#include "jvm_internal.h"
#include "stdio.h"

#ifdef OGDR_SECURITY_SETTING
/*************************************************************************
 * Global Declaration
 *************************************************************************/
extern j2me_custom_file_info_struct *j2me_custom_file_info_ptr;

/*****************************************************************************
 * FUNCTION
 *  py_trim_str
 * DESCRIPTION
 *  Remove the space charactors in head and tail of a string.
 * PARAMETERS
 *  string        [IN/OUT]        The string to be fixed.
 * RETURNS
 *  void
 *****************************************************************************/
static void py_trim_str(kal_char* string)
{
    kal_char* org_string = string;
    kal_int32 str_len = strlen(string) - 1;
    while(*string == ' ')
    {
        string ++;
    }

    while(org_string[str_len] == ' ')
    {
        str_len --;
    }
    org_string[str_len + 1] = 0;
    strcpy(org_string, string);
}

/*****************************************************************************
 * FUNCTION
 *  str_indexOf
 * DESCRIPTION
 *  Find a pattern of a string
 * PARAMETERS
 *  str         [IN]        The string to be searched.
 *  pattern     [IN]        The pattern to be matched.
 *  fromIndex	[IN]		The start index of a string to be searched.
 * RETURNS
 *  kal_int32		The found index of a pattern in a string.
 *****************************************************************************/
static kal_int32 str_indexOf(kal_char* str, kal_char* pattern, kal_int32 fromIndex) {
    kal_char *v1 = str;
    kal_char *v2 = pattern;
    kal_int32 str_len = strlen(str);
    kal_int32 pattern_len = strlen(pattern);
    kal_char first;
    kal_int32 i, j, k;
    kal_int32 end;
    kal_int32 max = str_len - pattern_len;
    
    if (fromIndex >= str_len) {
        if (str_len == 0 && fromIndex == 0 && pattern_len == 0) {
            /* There is an empty string at index 0 in an empty string. */
            return 0;
        }
        /* Note: fromIndex might be near -1>>>1 */
        return -1;
    }
    if (fromIndex < 0) {
        fromIndex = 0;
    }
    if (pattern_len == 0) {
        return fromIndex;
    }
    
    first  = v2[0];
    i = fromIndex;
    
    while (KAL_TRUE) {
startSearchForFirstChar:
        /* Look for first character. */
        while (i <= max && v1[i] != first) {
            i++;
        }
        if (i > max) {
            return -1;
        }
        
        /* Found first character, now look at the rest of v2 */
        j = i + 1;
        end = j + pattern_len - 1;
        k = 1;
        while (j < end) {
            if (v1[j++] != v2[k++]) {
                i++;
                /* Look for str's first char again. */
                goto startSearchForFirstChar;
            }
        }
        return i;  /* Found whole string. */
    }
}

/*****************************************************************************
 * FUNCTION
 *  get_attribute_number
 * DESCRIPTION
 *  Parse how many key / value pairs in the input policy data.
 * PARAMETERS
 *  policy_data [IN]        The input policy data.
 * RETURNS
 *  kal_int32		attribute number
 *****************************************************************************/
static kal_int32 get_attribute_number(kal_char* policy_data)
{
    kal_int32 str_index = 0;
    kal_int32 attribute_number = 0;
    while(policy_data[str_index] != 0)
    {
        if(policy_data[str_index] == ':')
        {
            attribute_number ++;
        }
        str_index ++;
    }
    return attribute_number;
}

/*****************************************************************************
 * FUNCTION
 *  parse_key_pair
 * DESCRIPTION
 *  Parse key / value pairs in the input policy data and save them to 
 *  key pair structure
 * PARAMETERS
 *  kp          [IN]        The key / value pair structure
 *  policy_data [IN]        Policy raw data in _policy.txt.
 * RETURNS
 *  kal_int32		        Determine success or fail
 *****************************************************************************/
static kal_int32 parse_key_pair(key_value_pair_struct* kp, kal_char* policy_data)
{
    kal_bool get_key = KAL_TRUE;
    kal_int32 last_index = 0;
    kal_int32 str_index = 0;
    kal_int32 kp_index = 0;
    while(policy_data[str_index] != 0)
    {
        if(get_key)
        {
            if(policy_data[str_index] == ':')
            {
                kp[kp_index].key = (kal_char*)jvm_malloc(str_index - last_index + 1);
                memcpy(kp[kp_index].key, &(policy_data[last_index]), str_index - last_index);
                kp[kp_index].key[str_index - last_index] = 0;
                py_trim_str(kp[kp_index].key);
                last_index = str_index + 1;
                get_key = KAL_FALSE;
            }
        }
        else
        {
            if(policy_data[str_index] == '\r' || policy_data[str_index] == '\n')
            {
                if(policy_data[str_index + 1] == ' ')
                {
                    str_index += 2;
                    continue;
                }
                if(policy_data[str_index + 1] == '\n' && policy_data[str_index + 2] == ' ')
                {
                    str_index += 3;
                    continue;
                }
                
                kp[kp_index].value = (kal_char*)jvm_malloc(str_index - last_index + 1);
                memcpy(kp[kp_index].value, &(policy_data[last_index]), str_index - last_index);
                kp[kp_index].value[str_index - last_index] = 0;
                py_trim_str(kp[kp_index].value);
                last_index = str_index + 1;
                while(policy_data[last_index] == '\r' || policy_data[last_index] == '\n')
                {
                    last_index ++;
                }
                
                kp_index ++;
                get_key = KAL_TRUE;
            }
        }
        str_index ++;
    }
    if(get_key == KAL_FALSE)
    {
        kp[kp_index].value = (kal_char*)jvm_malloc(str_index - last_index);
        memcpy(kp[kp_index].value, &(policy_data[last_index]), str_index - last_index);
        kp_index ++;
    }
    kp[kp_index].key = NULL;
    kp[kp_index].value = NULL;
    return J2ME_NO_ERROR;
}

/*****************************************************************************
 * FUNCTION
 *  get_a2p
 * DESCRIPTION
 *  Get the mapping of Alias name in Java policy to MMI setting group
 * PARAMETERS
 *  kp          [IN]        The key / value pair structure
 * RETURNS
 *  alias_to_perm_struct    Alias to permission group mapping
 *****************************************************************************/
static alias_to_perm_struct* get_a2p(key_value_pair_struct* kp)
{
    alias_to_perm_struct* return_a2p;
    kal_int32 total_alias = 0;
    kal_int32 kp_index = 0;
    kal_int32 str_index = 0;
    kal_int32 start_index = 0;
    kal_int32 a2p_index;
    while(kp[kp_index].key != NULL)
    {
        if(strcmp(kp[kp_index].key, "alias") == 0)
        {
            total_alias ++;
        }
        kp_index ++;
    }
    return_a2p = (alias_to_perm_struct*)jvm_malloc(sizeof(alias_to_perm_struct) * (total_alias + 1));
    kp_index = 0;
    a2p_index = 0;
    
    while(kp[kp_index].key != NULL)
    {
        start_index = 0;
        str_index = 0;
        if(strcmp(kp[kp_index].key, "alias") == 0)
        {
            while(kp[kp_index].value[str_index] == ' ')
            {
                str_index ++;
            }
            start_index = str_index;
            while(kp[kp_index].value[str_index] != ' ' && kp[kp_index].value[str_index] != '\r' &&
                  kp[kp_index].value[str_index] != '\n')
            {
                str_index ++;
            }
            
            return_a2p[a2p_index].key = jvm_malloc(str_index - start_index + 1);
            memcpy(return_a2p[a2p_index].key, &(kp[kp_index].value[start_index]), str_index - start_index);
            return_a2p[a2p_index].key[str_index - start_index] = 0;
            return_a2p[a2p_index].perm = PERMISSION_UNKNOWN;
            
            if(str_indexOf(kp[kp_index].value, "javax.microedition.io.Connector.http", str_index) != -1)
            {
                return_a2p[a2p_index].perm = PERMISSION_NETWORK;
            }
            else if(str_indexOf(kp[kp_index].value, "javax.microedition.io.PushRegistry", str_index) != -1)
            {
                return_a2p[a2p_index].perm = PERMISSION_PUSH;
            }
            else if(str_indexOf(kp[kp_index].value, "javax.microedition.io.Connector.sms", str_index) != -1)
            {
                return_a2p[a2p_index].perm = PERMISSION_MESSAGE;
            }
            else if(str_indexOf(kp[kp_index].value, "javax.microedition.media.control.RecordControl", str_index) != -1)
            {
                return_a2p[a2p_index].perm = PERMISSION_MULTIMEDIA;
            }
            else if(str_indexOf(kp[kp_index].value, "javax.microedition.io.Connector.file.read", str_index) != -1)
            {
                return_a2p[a2p_index].perm = PERMISSION_DATA_READ;
            }
            else if(str_indexOf(kp[kp_index].value, "javax.microedition.io.Connector.file.write", str_index) != -1)
            {
                return_a2p[a2p_index].perm = PERMISSION_DATA_WRITE;
            }
            else if(str_indexOf(kp[kp_index].value, "javax.microedition.io.Connector.comm", str_index) != -1)
            {
                return_a2p[a2p_index].perm = PERMISSION_LOCAL_CON;
            }
            
            a2p_index ++;
        }
        kp_index ++;
    }
    return_a2p[a2p_index].key = NULL;
    return_a2p[a2p_index].perm = PERMISSION_UNKNOWN;
    

⌨️ 快捷键说明

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