示例#1
0
/**
 * If the suite exists, this function returns a unique identifier of
 * MIDlet suite. Note that suite may be corrupted even if it exists.
 * If the suite doesn't exist, a new suite ID is created.
 *
 * @param vendor name of the vendor that created the application, as
 *          given in a JAD file
 * @param name name of the suite, as given in a JAD file
 * @param pSuiteId [out] receives the platform-specific suite ID of the
 *          application given by vendorName and appName, or string with
 *          a null data if suite does not exist, or
 *          out of memory error occured, or suite is corrupted.
 *
 * @return  ALL_OK if suite found,
 *          NOT_FOUND if suite does not exist (so a new ID was created),
 *          other error code in case of error
 */
MIDPError
midp_get_suite_id(const pcsl_string* vendor, const pcsl_string* name,
                  SuiteIdType* pSuiteId) {
    MIDPError status;
    char *pszError;
    MidletSuiteData* pData;

    *pSuiteId = UNUSED_SUITE_ID;

    /* load _suites.dat */
    status = read_suites_data(&pszError);
    storageFreeError(pszError);
    if (status != ALL_OK) {
        return status;
    }

    pData = g_pSuitesData;

    /* try to find a suite */
    while (pData != NULL) {
        if (pcsl_string_equals(&pData->varSuiteData.suiteName, name) &&
                pcsl_string_equals(&pData->varSuiteData.suiteVendor, vendor)) {
            *pSuiteId = pData->suiteId;
            return ALL_OK; /* IMPL_NOTE: consider SUITE_CORRUPTED_ERROR */
        }

        pData = pData->nextEntry;
    }

    /* suite was not found - create a new suite ID */
    status = midp_create_suite_id(pSuiteId);

    return (status == ALL_OK) ? NOT_FOUND : status;
}
/**
 * Checks if a midlet suite or dynamic component with the given name
 * created by the given vendor exists.
 * If it does, this function returns a unique identifier of the suite
 * or component. Note that the suite or component may be corrupted even
 * if it exists. If it doesn't, a new suite ID or component ID is created.
 *
 * @param type type of the component
 * @param suiteId if type == COMPONENT_DYNAMIC, contains ID of the suite this
 *                components belongs to; unused otherwise
 * @param vendor name of the vendor that created the application or component,
 *        as given in a JAD file
 * @param name name of the suite or component, as given in a JAD file
 * @param pId [out] receives the platform-specific suite ID or component ID
 *        of the application given by vendor and name, or UNUSED_SUITE_ID /
 *        UNUSED_COMPONENT_ID if suite does not exist, or out of memory
 *        error occured, or the suite / component is corrupted.
 *
 * @return  ALL_OK if suite or component found,
 *          NOT_FOUND if suite or component does not exist (so a new ID
 *          was created), other error code in case of error
 */
static MIDPError
get_suite_or_component_id(ComponentType type, SuiteIdType suiteId,
                           const pcsl_string* vendor, const pcsl_string* name,
                           jint* pId) {
    MIDPError status;
    char *pszError;
    MidletSuiteData* pData;

#if ENABLE_DYNAMIC_COMPONENTS
    if (type != COMPONENT_DYNAMIC) {
        *pId = (jint)UNUSED_SUITE_ID;
    } else {
        *pId = (jint)UNUSED_COMPONENT_ID;
    }
#else
    (void)type;
    (void)suiteId;
    *pId = (jint)UNUSED_SUITE_ID;
#endif /* ENABLE_DYNAMIC_COMPONENTS */

    /* load _suites.dat */
    status = read_suites_data(&pszError);
    storageFreeError(pszError);
    if (status != ALL_OK) {
        return status;
    }

    pData = g_pSuitesData;

    /* try to find a suite */
    while (pData != NULL) {
        if (pcsl_string_equals(&pData->varSuiteData.suiteName, name) &&
                pcsl_string_equals(&pData->varSuiteData.suiteVendor, vendor)
#if ENABLE_DYNAMIC_COMPONENTS
                    && (type == pData->type) && (type != COMPONENT_DYNAMIC ||
                        (type == COMPONENT_DYNAMIC && suiteId == pData->suiteId))
#endif
        ) {
#if ENABLE_DYNAMIC_COMPONENTS
            if (type != COMPONENT_DYNAMIC) {
                *pId = (jint)pData->suiteId;
            } else {
                *pId = (jint)pData->componentId;
            }
#else
            *pId = (jint)pData->suiteId;
#endif /* ENABLE_DYNAMIC_COMPONENTS */
            return ALL_OK; /* IMPL_NOTE: consider SUITE_CORRUPTED_ERROR */
        }

        pData = pData->nextEntry;
    }

    /* suite or component was not found - create a new suite or component ID */
#if ENABLE_DYNAMIC_COMPONENTS
    if (type != COMPONENT_DYNAMIC) {
        status = midp_create_suite_id((SuiteIdType*)pId);
    } else {
        status = midp_create_component_id((ComponentIdType*)pId);
    }
#else
    status = midp_create_suite_id((SuiteIdType*)pId);
#endif /* ENABLE_DYNAMIC_COMPONENTS */

    return (status == ALL_OK) ? NOT_FOUND : status;
}