/** * 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 */ MIDPError midp_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; }
/** * Lists all installed MIDlet suites. This is an example of how to use * the public MIDP API. * * @param argc The total number of arguments * @param argv An array of 'C' strings containing the arguments * * @return <tt>0</tt> for success, otherwise <tt>-1</tt> * * IMPL_NOTE: determine if it is desirable for user targeted output * messages to be sent via the log/trace service, or if * they should remain as printf calls */ int listMidlets(int argc, char* argv[]) { int status = -1; int i; long size; char* midpHome = NULL; (void)argv; /* Avoid compiler warnings */ if (argc > 1) { REPORT_ERROR(LC_AMS, "Too many arguments given"); fprintf(stderr, "Too many arguments given\n"); return -1; } /* get midp home directory, set it */ midpHome = midpFixMidpHome(argv[0]); if (midpHome == NULL) { return -1; } /* set up midpHome before calling initialize */ midpSetHomeDir(midpHome); if (midpInitialize() != 0) { REPORT_ERROR(LC_AMS, "Not enough memory"); fprintf(stderr, "Not enough memory\n"); return -1; } do { SuiteIdType* pSuites = NULL; int numberOfSuites = 0; MIDPError err; err = midp_get_suite_ids(&pSuites, &numberOfSuites); if (err != ALL_OK) { REPORT_ERROR1(LC_AMS, "Error in midp_get_suite_ids(), code %d", err); fprintf(stderr, "Error in midp_get_suite_ids(), code %d.\n", err); break; } if (numberOfSuites == 0) { REPORT_ERROR(LC_AMS, "No MIDlet Suites installed on phone"); printf("** No MIDlet Suites installed on phone\n"); status = 0; break; } for (i = 0; i < numberOfSuites; i++) { MidpInstallInfo info; MidpProperties properties; info = midp_get_suite_install_info(pSuites[i]); if (BAD_ID_INFO_STATUS(info)) { REPORT_ERROR(LC_AMS, "Suite list is corrupt"); fprintf(stderr, "Suite list is corrupt\n"); break; } if (OUT_OF_MEM_INFO_STATUS(info)) { REPORT_ERROR(LC_AMS, "Out Of Memory for Info"); fprintf(stderr, "Out Of Memory for Info\n"); break; } if (SUITE_CORRUPTED_ERR_STATUS(info)) { /* * Installinfo is not initialsed in case of an error * so no need to free it */ REPORT_ERROR1(LC_AMS, "Error : Suite %d is corrupted", (i+1)); fprintf(stderr, "Error : Suite %d is corrupted\n", (i+1)); continue; } if (READ_ERROR_INFO_STATUS(info)) { REPORT_ERROR(LC_AMS, "Corrupt install info"); fprintf(stderr, "Corrupt install info\n"); break; } properties = midp_get_suite_properties(pSuites[i]); if (OUT_OF_MEM_PROPERTY_STATUS(properties)) { midp_free_install_info(&info); midp_free_properties(&properties); REPORT_ERROR(LC_AMS, "Out Of Memory for properties"); fprintf(stderr, "Out Of Memory for properties\n"); break; } if (CORRUPTED_PROPERTY_STATUS(properties)) { midp_free_install_info(&info); midp_free_properties(&properties); REPORT_ERROR1(LC_AMS, "Error : Suite %d is corrupted", (i+1)); fprintf(stderr, "Error : Suite %d is corrupted\n", (i+1)); continue; } if (READ_ERROR_PROPERTY_STATUS(properties)) { midp_free_install_info(&info); midp_free_properties(&properties); REPORT_ERROR(LC_AMS, "Corrupt properties"); fprintf(stderr, "Corrupt properties\n"); break; } printf("[%d]\n", (i + 1)); printProperty(" Name: ", &SUITE_NAME_PROP, properties); printProperty(" Vendor: ", &SUITE_VENDOR_PROP, properties); printProperty(" Version: ", &SUITE_VERSION_PROP, properties); printProperty(" Description: ", &SUITE_DESC_PROP, properties); if (info.authPathLen > 0) { int j; puts(" Authorized by: "); for (j = 0; j < info.authPathLen; j++) { print_field(" ", &info.authPath_as[j]); } } print_field(" SecurityDomain: ", &info.domain_s); printf(" Verified: %s\n", (info.pVerifyHash != NULL ? "true" : "false")); printf(" Suite ID: %ld\n", (long)pSuites[i]); print_field(" JAD URL: ", &info.jadUrl_s); print_field(" JAR URL: ", &info.jarUrl_s); size = midp_get_suite_storage_size(pSuites[i]); if (size < 0) { fprintf(stderr, "Ran out of memory getting the size\n"); } else { printf(" Size: %ldK\n", (size + 1023) / 1024); } midp_free_install_info(&info); midp_free_properties(&properties); } midp_free_suite_ids(pSuites, numberOfSuites); status = 0; } while (0); midpFinalize(); return status; }
int find_midlet_class(SuiteIdType id, int midletNumber, pcsl_string* res) { MidpProperties properties; pcsl_string keySuffix = PCSL_STRING_NULL; pcsl_string key = PCSL_STRING_NULL; const pcsl_string* property = &PCSL_STRING_NULL; pcsl_string temp = PCSL_STRING_NULL; pcsl_string_status stat; int begin; int result = 0; *res = PCSL_STRING_NULL; properties = midp_get_suite_properties(id); if (OUT_OF_MEM_PROPERTY_STATUS(properties)) { return OUT_OF_MEM_LEN; } do { if (CORRUPTED_PROPERTY_STATUS(properties)) { midp_free_properties(&properties); REPORT_ERROR(LC_AMS, "Error : Suite is corrupted"); fprintf(stderr, "Error : Suite is corrupted\n"); result = NULL_LEN; break; } if (READ_ERROR_PROPERTY_STATUS(properties)) { midp_free_properties(&properties); REPORT_ERROR(LC_AMS, "Corrupt properties"); fprintf(stderr, "Corrupt properties\n"); result = NULL_LEN; break; } stat = pcsl_string_convert_from_jint(midletNumber, &keySuffix); if (PCSL_STRING_OK != stat) { if(PCSL_STRING_ENOMEM == stat) { result = OUT_OF_MEM_LEN; } else { result = NULL_LEN; } break; } stat = pcsl_string_cat(&KEY_PREFIX, &keySuffix, &key); pcsl_string_free(&keySuffix); if (PCSL_STRING_OK != stat) { result = OUT_OF_MEM_LEN; break; } property = midp_find_property(&properties, &key); if (pcsl_string_length(property) <= 0) { /* property not found */ result = NULL_LEN; break; } /* The class is the last item in the set. */ begin = pcsl_string_last_index_of(property, (jchar)','); if (begin < 0 || begin >= pcsl_string_length(property)) { result = NULL_LEN; break; } begin++; stat = pcsl_string_substring(property, begin, pcsl_string_length(property), &temp); if (PCSL_STRING_OK != stat) { result = OUT_OF_MEM_LEN; break; } if (pcsl_string_length(&temp) <= 0) { pcsl_string_free(&temp); result = NULL_LEN; break; } stat = pcsl_string_trim(&temp, res); pcsl_string_free(&temp); if (PCSL_STRING_OK != stat) { result = OUT_OF_MEM_LEN; break; } } while (0); midp_free_properties(&properties); return result; }
/** * Removes a software package given its suite ID * <p> * If the component is in use it must continue to be available * to the other components that are using it. The resources it * consumes must not be released until it is not in use. * * @param suiteId ID of the suite * * @return ALL_OK if no errors, * NOT_FOUND if the suite does not exist, * SUITE_LOCKED if the suite is locked, * BAD_PARAMS this suite cannot be removed */ MIDPError midp_remove_suite(SuiteIdType suiteId) { pcsl_string filename; char* pszError; pcsl_string suiteRoot; MIDPError status; int operationStarted = 0; void* fileIteratorHandle = NULL; MidpProperties properties; pcsl_string* pproperty; MidletSuiteData* pData = NULL; pcsl_string filenameBase; lockStorageList *node = NULL; /* get the filename base from the suite id */ status = build_suite_filename(suiteId, &PCSL_STRING_EMPTY, &filenameBase); if (status != ALL_OK) { return status; } node = find_storage_lock(suiteId); if (node != NULL) { if (node->update != KNI_TRUE) { return SUITE_LOCKED; } } /* * 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(REMOVE_LEVEL) != 0) { return OUT_OF_MEMORY; } do { int rc; /* return code for rmsdb_... and storage_... */ /* load _suites.dat */ status = read_suites_data(&pszError); storageFreeError(pszError); if (status != ALL_OK) { break; } /* check that the suite exists and it is not a preloaded one */ pData = get_suite_data(suiteId); if (pData == NULL) { status = NOT_FOUND; break; } /* notify the listeners that we starting to remove the suite */ operationStarted = 1; suite_listeners_notify(SUITESTORE_LISTENER_TYPE_REMOVE, SUITESTORE_OPERATION_START, ALL_OK, pData); if (pData->type == COMPONENT_PREINSTALLED_SUITE) { status = BAD_PARAMS; break; } status = begin_transaction(TRANSACTION_REMOVE_SUITE, suiteId, NULL); if (status != ALL_OK) { return status; } /* * Remove the files * Call the native RMS method to remove the RMS data. * This function call is needed for portability */ rc = rmsdb_remove_record_stores_for_suite(&filenameBase, suiteId); if (rc == KNI_FALSE) { status = SUITE_LOCKED; break; } pushdeletesuite(suiteId); /* * If there is a delete notify property, add the value to the delete * notify URL list. */ properties = midp_get_suite_properties(suiteId); if (properties.numberOfProperties > 0) { pproperty = midp_find_property(&properties, &DELETE_NOTIFY_PROP); if (pcsl_string_length(pproperty) > 0) { midpAddDeleteNotification(suiteId, pproperty); } pproperty = midp_find_property(&properties, &INSTALL_NOTIFY_PROP); if (pcsl_string_length(pproperty) > 0) { /* * Remove any pending install notifications since they are only * retried when the suite is run. */ midpRemoveInstallNotification(suiteId); } midp_free_properties(&properties); } if ((status = get_suite_storage_root(suiteId, &suiteRoot)) != ALL_OK) { break; } fileIteratorHandle = storage_open_file_iterator(&suiteRoot); if (!fileIteratorHandle) { status = IO_ERROR; break; } #if ENABLE_ICON_CACHE midp_remove_suite_icons(suiteId); #endif for (;;) { rc = storage_get_next_file_in_iterator(&suiteRoot, fileIteratorHandle, &filename); if (0 != rc) { break; } storage_delete_file(&pszError, &filename); pcsl_string_free(&filename); if (pszError != NULL) { storageFreeError(pszError); break; } } } while (0); pcsl_string_free(&suiteRoot); storageCloseFileIterator(fileIteratorHandle); (void)finish_transaction(); /* * Notify the listeners the we've finished removing the suite. * It should be done before remove_from_suite_list_and_save() * call because it frees pData structure. */ if (operationStarted) { suite_listeners_notify(SUITESTORE_LISTENER_TYPE_REMOVE, SUITESTORE_OPERATION_END, status, pData); } if (status == ALL_OK) { (void)remove_from_suite_list_and_save(suiteId); } remove_storage_lock(suiteId); return status; }