suitestore_common.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,047 行 · 第 1/3 页
C
1,047 行
* 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_bin_app_path(SuiteIdType suiteId, StorageIdType storageId, pcsl_string *classPath) { return get_class_path_impl(COMPONENT_REGULAR_SUITE, suiteId, UNUSED_COMPONENT_ID, storageId, classPath, &APP_IMAGE_EXTENSION);}#endif/** * Gets location of the cached resource with specified name * for the suite with the specified suiteId. * * Note that when porting memory for the in/out parameter * filename MUST be allocated using pcsl_mem_malloc(). * The caller is responsible for freeing the memory associated * with filename parameter. * * @param suiteId The application suite ID * @param storageId storage ID, INTERNAL_STORAGE_ID for the internal storage * @param pResourceName Name of the cached resource * @param pFileName The in/out parameter that contains returned filename * @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_cached_resource_filename(SuiteIdType suiteId, StorageIdType storageId, const pcsl_string * pResourceName, pcsl_string * pFileName) { const pcsl_string* root = storage_get_root(storageId); pcsl_string returnPath = PCSL_STRING_NULL; pcsl_string resourceFileName = PCSL_STRING_NULL; jint suiteIdLen = GET_SUITE_ID_LEN(suiteId); jsize resourceNameLen = pcsl_string_length(pResourceName); *pFileName = PCSL_STRING_NULL; if (resourceNameLen > 0) { /* performance hint: predict buffer capacity */ int fileNameLen = PCSL_STRING_ESCAPED_BUFFER_SIZE( resourceNameLen + pcsl_string_length(&TMP_EXT)); pcsl_string_predict_size(&resourceFileName, fileNameLen); if ( /* Convert any slashes */ pcsl_esc_attach_string(pResourceName, &resourceFileName) != PCSL_STRING_OK || /* Add the extension */ pcsl_string_append(&resourceFileName, &TMP_EXT) != PCSL_STRING_OK) { pcsl_string_free(&resourceFileName); return OUT_OF_MEMORY; } } /* performance hint: predict buffer capacity */ pcsl_string_predict_size(&returnPath, pcsl_string_length(root) + suiteIdLen + pcsl_string_length(&resourceFileName)); if (PCSL_STRING_OK != pcsl_string_append(&returnPath, root) || PCSL_STRING_OK != pcsl_string_append(&returnPath, midp_suiteid2pcsl_string(suiteId)) || PCSL_STRING_OK != pcsl_string_append(&returnPath, &resourceFileName)) { pcsl_string_free(&resourceFileName); pcsl_string_free(&returnPath); return OUT_OF_MEMORY; } pcsl_string_free(&resourceFileName); *pFileName = returnPath; return ALL_OK;}/** * Retrieves an ID of the requested type for the given suite. * * @param suiteId The application suite ID * @param resultType 0 to return suite storage ID, 1 - suite folder ID * @param pResult [out] receives the requested ID * * @return error code (ALL_OK if successful) */static MIDPErrorget_suite_int_impl(SuiteIdType suiteId, int resultType, void* pResult) { MIDPError status; MidletSuiteData* pData; char* pszError; if (pResult == NULL) { return BAD_PARAMS; } if (suiteId == INTERNAL_SUITE_ID) { /* handle a special case: predefined suite ID is given */ if (resultType) { *(FolderIdType*)pResult = 0; } else { *(StorageIdType*)pResult = INTERNAL_STORAGE_ID; } return ALL_OK; } /* load _suites.dat */ status = read_suites_data(&pszError); storageFreeError(pszError); if (status == ALL_OK) { pData = get_suite_data(suiteId); if (pData) { if (resultType) { *(FolderIdType*)pResult = pData->folderId; } else { *(StorageIdType*)pResult = pData->storageId; } } else { if (resultType) { *(FolderIdType*)pResult = -1; } else { *(StorageIdType*)pResult = UNUSED_STORAGE_ID; } status = NOT_FOUND; } } return status;}/** * Retrieves an ID of the storage where the midlet suite with the given suite ID * is stored. * * @param suiteId The application suite ID * @param pStorageId [out] receives an ID of the storage where * the suite is stored * * @return error code (ALL_OK if successful) */MIDPErrormidp_suite_get_suite_storage(SuiteIdType suiteId, StorageIdType* pStorageId) { return get_suite_int_impl(suiteId, 0, (void*)pStorageId);}/** * Retrieves an ID of the folder where the midlet suite with the given suite ID * is stored. * * @param suiteId The application suite ID * @param pFolderId [out] receives an ID of the folder where the suite is stored * * @return error code (ALL_OK if successful) */MIDPErrormidp_suite_get_suite_folder(SuiteIdType suiteId, FolderIdType* pFolderId) { return get_suite_int_impl(suiteId, 1, (void*)pFolderId);}/** * 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 vendor and name, or UNUSED_SUITE_ID * 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 */MIDPErrormidp_get_suite_id(const pcsl_string* vendor, const pcsl_string* name, SuiteIdType* pSuiteId) { return get_suite_or_component_id(COMPONENT_REGULAR_SUITE, vendor, name, (jint*)pSuiteId);}#if ENABLE_DYNAMIC_COMPONENTS/** * If the dynamic component exists, this function returns an unique identifier * of the component. Note that the component may be corrupted even if it exists. * If the component doesn't exist, a new component ID is created. * * @param vendor name of the vendor that created the component, as * given in a JAD file * @param name name of the component, as given in a JAD file * @param pComponentId [out] receives the platform-specific component ID of * the component given by vendor and name, or UNUSED_COMPONENT_ID * if component does not exist, or out of memory error occured, * or component is corrupted. * * @return ALL_OK if suite found, * NOT_FOUND if component does not exist (so a new ID was created), * other error code in case of error */MIDPErrormidp_get_component_id(const pcsl_string* vendor, const pcsl_string* name, ComponentIdType* pComponentId) { return get_suite_or_component_id(COMPONENT_DYNAMIC, vendor, name, (jint*)pComponentId);}#endif /* ENABLE_DYNAMIC_COMPONENTS *//** * Find and return the property the matches the given key. * The returned value need not be freed because it resides * in an internal data structure. * * @param pProperties property list * @param key key of property to find * * @return a pointer to the property value, * or to PCSL_STRING_NULL if not found. */pcsl_string*midp_find_property(MidpProperties* pProperties, const pcsl_string* key) { int i; /* Properties are stored as key, value pairs. */ for (i = 0; i < pProperties->numberOfProperties; i++) { if (pcsl_string_equals(&pProperties->pStringArr[i * 2], key)) { return &pProperties->pStringArr[(i * 2) + 1]; } } return (pcsl_string*)&PCSL_STRING_NULL;}/** * Free a list of properties. Does nothing if passed NULL. * * @param pProperties property list */voidmidp_free_properties(MidpProperties* pProperties) { /* Properties are stored as key, value pairs. */ if (!pProperties || pProperties->numberOfProperties <= 0) { return; } free_pcsl_string_list(pProperties->pStringArr, pProperties->numberOfProperties * 2); pProperties->pStringArr = NULL;}/** * Gets the properties of a MIDlet suite to persistent storage. * <pre> * The format of the properties file will be: * <number of strings as int (2 strings per property)> * {repeated for each property} * <length of a property key as int> * <property key as jchars> * <length of property value as int> * <property value as jchars> * </pre> * * * Note that memory for the strings inside the returned MidpProperties * structure is allocated by the callee, and the caller is * responsible for freeing it using midp_free_properties(). * * @param suiteId ID of the suite * * @return properties in a pair pattern of key and value, * use the status macros to check the result. A SUITE_CORRUPTED_ERROR * is returned as a status of MidpProperties when suite is corrupted */MidpPropertiesmidp_get_suite_properties(SuiteIdType suiteId) { pcsl_string filename; MidpProperties result = { 0, ALL_OK, NULL }; int len; char* pszError; MIDPError status; /* * This is a public API which can be called without the VM running * so we need automatically init anything needed, to make the * caller's code less complex. * * Initialization is performed in steps so that we do use any * extra resources such as the VM for the operation being performed. */ if (midpInit(LIST_LEVEL) != 0) { result.numberOfProperties = 0; result.status = OUT_OF_MEMORY; return result; } /* if (check_for_corrupted_suite(suiteId) == SUITE_CORRUPTED_ERROR) { result.numberOfProperties = 0; result.status = SUITE_CORRUPTED_ERROR; return result; } */ if (get_property_file(suiteId, KNI_TRUE, &filename) != ALL_OK) { result.numberOfProperties = 0; result.status = NOT_FOUND; return result; } status = get_string_list(&pszError, &filename, &result.pStringArr, &len); pcsl_string_free(&filename); if (status != ALL_OK) { result.numberOfProperties = 0; result.status = status; storageFreeError(pszError); return result; } if (len < 0) { /* error */ result.numberOfProperties = 0; result.status = GENERAL_ERROR; } else { /* each property is 2 strings (key and value) */ result.numberOfProperties = len / 2; } return result;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?