suitestore_common.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,047 行 · 第 1/3 页
C
1,047 行
/** * Retrieves the specified property value of the suite. * * IMPL_NOTE: this functions is introduced instead of 3 functions above. * * @param suiteId [in] unique ID of the MIDlet suite * @param pKey [in] property name * @param pValue [out] buffer to conatain returned property value * * @return ALL_OK if no errors, * BAD_PARAMS if some parameter is invalid, * NOT_FOUND if suite was not found, * SUITE_CORRUPTED_ERROR if the suite is corrupted */MIDPErrormidp_get_suite_property(SuiteIdType suiteId, const pcsl_string* pKey, pcsl_string* pValue) { MidpProperties prop; pcsl_string* pPropFound; if (pKey == NULL || pValue == NULL) { return BAD_PARAMS; } (void)suiteId; (void)pKey; *pValue = PCSL_STRING_NULL; /* IMPL_NOTE: the following implementation should be optimized! */ prop = midp_get_suite_properties(suiteId); if (prop.status != ALL_OK) { return prop.status; } pPropFound = midp_find_property(&prop, pKey);// TODO !!!// midp_free_properties(&prop); if (pPropFound == NULL) { return NOT_FOUND; } *pValue = *pPropFound; return ALL_OK; }/* ------------------------------------------------------------ *//* Implementation *//* ------------------------------------------------------------ *//** * 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 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 MIDPErrorget_suite_or_component_id(ComponentType type, 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; *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#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 comonent 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;}/** * Tells if a given suite is in a list of the installed suites. * * @param suiteId unique ID of the midlet suite * * @return ALL_OK if the suite is in the list of the installed suites, * NOT_FOUND if not, * IO_ERROR if an i/o error occured when reading the information * about the installed suites, * OUT_OF_MEMORY if out of memory or IO error, * SUITE_CORRUPTED_ERROR is suite is found in the list, but it's * corrupted. */static MIDPErrorsuite_in_list(ComponentType type, SuiteIdType suiteId, ComponentIdType componentId) { MIDPError status; char* pszError; MidletSuiteData* pData;#if !ENABLE_DYNAMIC_COMPONENTS /** to supress compilation warnings */ (void)type; (void)componentId;#endif /* load _suites.dat */ status = read_suites_data(&pszError); storageFreeError(pszError); if (status != ALL_OK) { return status; }#if ENABLE_DYNAMIC_COMPONENTS if (type == COMPONENT_DYNAMIC) { pData = get_component_data(componentId); if (pData == NULL) { status = NOT_FOUND; } } else {#endif /* ENABLE_DYNAMIC_COMPONENTS */ pData = get_suite_data(suiteId); if (pData != NULL) { /* * Make sure that suite is not corrupted. Return * SUITE_CORRUPTED_ERROR if the suite is corrupted. * Remove the suite before returning the status. */ status = check_for_corrupted_suite(suiteId); } else { status = NOT_FOUND; }#if ENABLE_DYNAMIC_COMPONENTS }#endif return status;}/** * Gets the classpath for the specified MIDlet suite id. * * 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 suite id used to identify the MIDlet suite * @param storageId storage ID, INTERNAL_STORAGE_ID for the internal storage * @param classPath The in/out parameter that contains returned class path * @param extension Extension of the file ( * * @return one of the error codes: * <pre> * ALL_OK, OUT_OF_MEMORY * </pre> */static MIDPErrorget_class_path_impl(ComponentType type, SuiteIdType suiteId, ComponentIdType componentId, jint storageId, pcsl_string * pClassPath, const pcsl_string * pExtension) { const pcsl_string* root = storage_get_root(storageId); pcsl_string path = PCSL_STRING_NULL; jint suiteIdLen = GET_SUITE_ID_LEN(suiteId); jint componentIdLen = 0;#if ENABLE_DYNAMIC_COMPONENTS if (type == COMPONENT_DYNAMIC) { componentIdLen = GET_COMPONENT_ID_LEN(componentId); }#else (void)type; (void)componentId;#endif *pClassPath = PCSL_STRING_NULL; /* performance hint: predict buffer capacity */ pcsl_string_predict_size(&path, pcsl_string_length(root) + suiteIdLen + componentIdLen + + pcsl_string_length(pExtension)); if (PCSL_STRING_OK != pcsl_string_append(&path, root) || PCSL_STRING_OK != pcsl_string_append(&path, midp_suiteid2pcsl_string(suiteId))) { pcsl_string_free(&path); return OUT_OF_MEMORY; }#if ENABLE_DYNAMIC_COMPONENTS if (type == COMPONENT_DYNAMIC) { if (PCSL_STRING_OK != pcsl_string_append(&path, midp_componentid2pcsl_string(componentId))) { pcsl_string_free(&path); return OUT_OF_MEMORY; } }#endif if (PCSL_STRING_OK != pcsl_string_append(&path, pExtension)) { pcsl_string_free(&path); return OUT_OF_MEMORY; } *pClassPath = path; return ALL_OK;}/** * Retrieves the list of strings in a file. * The file has the number of strings at the front, each string * is a length and the jchars. * * @param ppszError pointer to character string pointer to accept an error * @param pFilename name of the file of strings * @param paList pointer to an array of pcsl_strings, free with * free_pcsl_string_list * @param pStringNum number of strings if successful (can be 0) * * @return error code (ALL_OK if successful) */static MIDPErrorget_string_list(char** ppszError, const pcsl_string* pFilename, pcsl_string** paList, int* pStringNum) { char* pszTemp; int i = 0; int handle; int numberOfStrings = 0; pcsl_string* pStrings = NULL; MIDPError status = ALL_OK; *ppszError = NULL; *paList = NULL; *pStringNum = 0; handle = storage_open(ppszError, pFilename, OPEN_READ); if (*ppszError != NULL) { return IO_ERROR; } do { storageRead(ppszError, handle, (char*)&numberOfStrings, sizeof (numberOfStrings)); if (*ppszError != NULL) { status = IO_ERROR; break; } if (numberOfStrings == 0) { break; } pStrings = alloc_pcsl_string_list(numberOfStrings); if (pStrings == NULL) { status = OUT_OF_MEMORY; break; } for (i = 0; i < numberOfStrings; i++) { pStrings[i] = PCSL_STRING_NULL; } for (i = 0; i < numberOfStrings; i++) { storage_read_utf16_string(ppszError, handle, &pStrings[i]); if (*ppszError != NULL) { status = IO_ERROR; break; } } if (i != numberOfStrings) { status = SUITE_CORRUPTED_ERROR; break; } } while (0); storageClose(&pszTemp, handle); storageFreeError(pszTemp); if (status == ALL_OK) { *paList = pStrings; *pStringNum = numberOfStrings; } else if (pStrings != NULL) { free_pcsl_string_list(pStrings, i); } return status;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?