suitestore_common.c

来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,047 行 · 第 1/3 页

C
1,047
字号
/* * * * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). *  * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA *  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. *//** * @file * * @ingroup AMS * * This is reference implementation of the common MIDlet suite storage * functions. */#include <string.h>#include <kni.h>#include <pcsl_memory.h>#include <pcsl_esc.h>#include <pcsl_string.h>#include <midpInit.h>#include <suitestore_common.h>#include <suitestore_intern.h>#include <suitestore_locks.h>#if ENABLE_MONET/** * Filename to save the application image file of suite. */PCSL_DEFINE_ASCII_STRING_LITERAL_START(APP_IMAGE_EXTENSION)#ifdef PRODUCT    {'.', 'b', 'u', 'n', '\0'}#elif defined(AZZERT)    {'_', 'g', '.', 'b', 'u', 'n', '\0'}#else    {'_', 'r', '.', 'b', 'u', 'n', '\0'}#endifPCSL_DEFINE_ASCII_STRING_LITERAL_END(APP_IMAGE_EXTENSION);#endif/* Description of these internal functions can be found bellow in the code. */static MIDPError suite_in_list(ComponentType type, SuiteIdType suiteId,                               ComponentIdType componentId);static MIDPError get_string_list(char** ppszError, const pcsl_string* pFilename,                                 pcsl_string** paList, int* pStringNum);static MIDPError get_class_path_impl(ComponentType type,                                     SuiteIdType suiteId,                                     ComponentIdType componentId,                                     jint storageId,                                     pcsl_string* classPath,                                     const pcsl_string* extension);static MIDPError get_suite_or_component_id(ComponentType type,                                           const pcsl_string* vendor,                                           const pcsl_string* name,                                           jint* pId);/** * Initializes the subsystem. */MIDPErrormidp_suite_storage_init() {    return suite_storage_init_impl();}/** * Resets any persistent resources allocated by MIDlet suite storage functions. */voidmidp_suite_storage_cleanup() {    suite_storage_cleanup_impl();}#define SUITESTORE_COUNTOF(x) (sizeof(x) / sizeof(x[0]))/** * Converts the given suite ID to pcsl_string. * NOTE: this function returns a pointer to the static buffer! * * @param value suite id to convert * * @return pcsl_string representation of the given suite ID */const pcsl_string* midp_suiteid2pcsl_string(SuiteIdType value) {    int i;    jchar digits[] = {        '0', '1', '2', '3', '4', '5', '6', '7',        '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'    };    unsigned long unsignedValue = (unsigned long) value;    static jchar resChars[GET_SUITE_ID_LEN(value) + 1]; /* +1 for last zero */    static pcsl_string resString = {        resChars, SUITESTORE_COUNTOF(resChars), 0    };    for (i = (int)SUITESTORE_COUNTOF(resChars) - 2; i >= 0; i--) {        resChars[i] = digits[unsignedValue & 15];        unsignedValue >>= 4;    }    resChars[SUITESTORE_COUNTOF(resChars) - 1] = (jchar)0;    return &resString;}#if ENABLE_DYNAMIC_COMPONENTS/** * Converts the given component ID to pcsl_string. * NOTE: this function returns a pointer to the static buffer! * * The current implementation uses the internal knowledge that * ComponentIdType and SuiteIdType are compatible integer types. * * @param value component id to convert * @return pcsl_string representation of the given component id */const pcsl_string* midp_componentid2pcsl_string(ComponentIdType value) {    return midp_suiteid2pcsl_string((SuiteIdType)value);}#endif /* ENABLE_DYNAMIC_COMPONENTS *//** * Converts the given suite ID to array of chars. * NOTE: this function returns a pointer to the static buffer! * * @param value suite id to convert * * @return char[] representation of the given suite ID * or NULL in case of error. */const char* midp_suiteid2chars(SuiteIdType value) {    jsize resLen;    static jbyte resChars[GET_SUITE_ID_LEN(value) + 1]; /* +1 for last zero */    const pcsl_string* pResString = midp_suiteid2pcsl_string(value);    pcsl_string_status rc;    rc = pcsl_string_convert_to_utf8(pResString, resChars,        (jsize)SUITESTORE_COUNTOF(resChars), &resLen);    return (rc == PCSL_STRING_OK) ? (char*)&resChars : NULL;}#undef SUITESTORE_COUNTOF/** * Tells if a suite exists. * * @param suiteId ID of a suite * * @return ALL_OK if a suite exists, *         NOT_FOUND if not, *         OUT_OF_MEMORY if out of memory or IO error, *         IO_ERROR if IO error, *         SUITE_CORRUPTED_ERROR is suite is found in the list, *         but it's corrupted */MIDPErrormidp_suite_exists(SuiteIdType suiteId) {    MIDPError status;    if (UNUSED_SUITE_ID == suiteId) {        return NOT_FOUND;    }    if (suiteId == g_lastSuiteExistsID) {        /* suite exists - we have already checked */        return ALL_OK;    }    g_lastSuiteExistsID = UNUSED_SUITE_ID;    /* The internal romized suite will not be found in appdb. */    if (suiteId == INTERNAL_SUITE_ID) {        g_lastSuiteExistsID = suiteId;        return ALL_OK;    }    status = suite_in_list(COMPONENT_REGULAR_SUITE, suiteId,                           UNUSED_COMPONENT_ID);    if (status == ALL_OK) {        g_lastSuiteExistsID = suiteId;    }    return status;}/** * Gets location of the class path for the suite with the specified suiteId. * * Note that memory for the in/out parameter classPath is * allocated by the callee. The caller is responsible for * freeing it using pcsl_mem_free(). * * @param suiteId The application suite ID * @param storageId storage ID, INTERNAL_STORAGE_ID for the internal storage * @param checkSuiteExists true if suite should be checked for existence or not * @param classPath The in/out parameter that contains returned class path * @return error code that should be one of the following: * <pre> *     ALL_OK, OUT_OF_MEMORY, NOT_FOUND, *     SUITE_CORRUPTED_ERROR, BAD_PARAMS * </pre> */MIDPErrormidp_suite_get_class_path(SuiteIdType suiteId,                          StorageIdType storageId,                          jboolean checkSuiteExists,                          pcsl_string *classPath) {    MIDPError status = ALL_OK;    int suiteExistsOrNotChecked;    if (checkSuiteExists) {        status = midp_suite_exists(suiteId);        suiteExistsOrNotChecked = (status == ALL_OK ||                                   status == SUITE_CORRUPTED_ERROR);    } else {        /*         * Don't need to check is the suite exist,         * just construct the classpath for the given suite ID.         */        suiteExistsOrNotChecked = 1;    }    if (suiteExistsOrNotChecked) {        status = get_class_path_impl(COMPONENT_REGULAR_SUITE, suiteId,                                     UNUSED_COMPONENT_ID, storageId, classPath,                                     &JAR_EXTENSION);    } else {        *classPath = PCSL_STRING_NULL;    }    return status;}#if ENABLE_DYNAMIC_COMPONENTS/** * Tells if a component exists. * * @param componentId ID of a component * * @return ALL_OK if a component exists, *         NOT_FOUND if not, *         OUT_OF_MEMORY if out of memory or IO error, *         IO_ERROR if IO error, *         SUITE_CORRUPTED_ERROR if component is found in the list, *         but it's corrupted */MIDPErrormidp_component_exists(ComponentIdType componentId) {    MIDPError status;    if (UNUSED_COMPONENT_ID == componentId) {        return NOT_FOUND;    }    if (componentId == g_lastComponentExistsID) {        /* suite exists - we have already checked */        return ALL_OK;    }    g_lastComponentExistsID = UNUSED_COMPONENT_ID;    status = suite_in_list(COMPONENT_DYNAMIC, UNUSED_SUITE_ID, componentId);    if (status == ALL_OK) {        g_lastComponentExistsID = componentId;    }    return status;}/** * Gets location of the class path for the component * with the specified componentId. * * Note that memory for the in/out parameter classPath is * allocated by the callee. The caller is responsible for * freeing it using pcsl_mem_free(). * * @param componentId The ID of the component * @param suiteId The application suite ID * @param storageId storage ID, INTERNAL_STORAGE_ID for the internal storage * @param checkComponentExists true if the component should be checked for                               existence or not * @param pClassPath The in/out parameter that contains returned class path * @return error code that should be one of the following: * <pre> *     ALL_OK, OUT_OF_MEMORY, NOT_FOUND, *     SUITE_CORRUPTED_ERROR, BAD_PARAMS * </pre> */MIDPErrormidp_suite_get_component_class_path(ComponentIdType componentId,                                    SuiteIdType suiteId,                                    StorageIdType storageId,                                    jboolean checkComponentExists,                                    pcsl_string *pClassPath) {    MIDPError status = ALL_OK;    int componentExistsOrNotChecked;    if (checkComponentExists) {        status = midp_component_exists(componentId);        componentExistsOrNotChecked = (status == ALL_OK ||                                       status == SUITE_CORRUPTED_ERROR);    } else {        /*         * Don't need to check is the component exist,         * just construct the classpath for the given component ID.         */        componentExistsOrNotChecked = 1;    }    if (componentExistsOrNotChecked) {        status = get_class_path_impl(COMPONENT_DYNAMIC, suiteId, componentId,                                     storageId, pClassPath, &JAR_EXTENSION);    } else {        *pClassPath = PCSL_STRING_NULL;    }    return status;}#endif /* ENABLE_DYNAMIC_COMPONENTS */#if ENABLE_MONET/** * Only for MONET--Gets the class path to binary application image * for the suite with the specified MIDlet suite id. * * It is different from "usual" class path in that class path points to a * jar file, while this binary application image path points to a MONET bundle. *

⌨️ 快捷键说明

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