/**
 * 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;                        
}
static MidpProperties verifyMfMustProperties(MidpProperties mfsmp) {

    /* MUST fields in MANIFEST */
    /* pcsl_string MIDlet-<n> for each MIDlet */
    pcsl_string * midlet_1;
    pcsl_string * name;
    pcsl_string * version;
    pcsl_string * vendor;
    pcsl_string * profile;
    pcsl_string * configuration;

    name = midp_find_property(&mfsmp, &SUITE_NAME_PROP);
    if (pcsl_string_is_null(name)) {
        REPORT_WARN(LC_AMS, "Missing suite name");
        mfsmp.status = NO_SUITE_NAME_PROP;
        return mfsmp;
    }

    vendor = midp_find_property(&mfsmp, &SUITE_VENDOR_PROP);
    if (pcsl_string_is_null(vendor)) {
        REPORT_WARN(LC_AMS, "Missing suite vendor");
        mfsmp.status = NO_SUITE_VENDOR_PROP;
        return mfsmp;
    }

    version = midp_find_property(&mfsmp, &SUITE_VERSION_PROP);
    if (pcsl_string_is_null(version)) {
        REPORT_WARN(LC_AMS, "Missing suite version");
        mfsmp.status = NO_SUITE_VERSION_PROP;
        return mfsmp;
    }
    if (!midpCheckVersion(version)) {
        REPORT_WARN(LC_AMS, "Corrupted suite version");
        mfsmp.status = BAD_SUITE_VERSION_PROP;
        return mfsmp;
    }

    profile = midp_find_property(&mfsmp, &MICROEDITION_PROFILE_PROP);
    if (pcsl_string_is_null(profile)) {
        REPORT_WARN(LC_AMS, "Missing Midp-Profile");
        mfsmp.status = NO_MICROEDITION_PROFILE_PROP;
        return mfsmp;
    }

    configuration = midp_find_property(&mfsmp, &MICROEDITION_CONFIGURATION_PROP);
    if (pcsl_string_is_null(configuration)) {
        REPORT_WARN(LC_AMS, "Missing Midp-Configuration");
        mfsmp.status = NO_MICROEDITION_CONFIGURATION_PROP;
        return mfsmp;
    }

    midlet_1 = midp_find_property(&mfsmp, &MIDLET_ONE_PROP);
    if (pcsl_string_is_null(midlet_1)) {
        REPORT_WARN(LC_AMS, "Missing Midlet-1");
        mfsmp.status = NO_MIDLET_ONE_PROP;
        return mfsmp;
    }
    return mfsmp;
} /* verifyMfMustProperties */
static MidpProperties verifyJadMustProperties(MidpProperties jadsmp) {

    /* 5 MUST fields in JAD */
    pcsl_string * name = NULL;
    pcsl_string * version = NULL;
    pcsl_string * vendor = NULL;
    pcsl_string * jarUrl = NULL;
    pcsl_string * jarSizeString = NULL;

    int permittedJarSize = 0;
    jint jarSizeByJad = 0;

    jarUrl = midp_find_property(&jadsmp, &JAR_URL_PROP);
    if (pcsl_string_is_null(jarUrl)) {
        REPORT_INFO(LC_AMS,  "Missing Jar URL");
        jadsmp.status = NO_JAR_URL_PROP;
        return jadsmp;
    }

    jarSizeString = midp_find_property(&jadsmp, &JAR_SIZE_PROP);
    if (pcsl_string_is_null(jarSizeString)) {
        REPORT_INFO(LC_AMS,  "Missing Jar size");
        jadsmp.status = NO_JAR_SIZE_PROP;
        return jadsmp;
    }

    if (PCSL_STRING_OK !=
        pcsl_string_convert_to_jint(jarSizeString, &jarSizeByJad)) {
        /* NUMBER_ERROR */
        REPORT_INFO1(LC_AMS, "JAD size ERROR %d", jarSizeByJad);
        jadsmp.status = NUMBER_ERROR;
        return jadsmp;
    }

    /* verify that requested jar size is not to big  */
    permittedJarSize = midpGetMaxJarSizePermitted();
    if (jarSizeByJad > permittedJarSize) {
        REPORT_INFO2(LC_AMS, "Jar size requested by Jad is to big %d > %d",
		     jarSizeByJad, permittedJarSize);
        REPORT_INFO(LC_AMS,  "Out Of Storage");
        jadsmp.status = OUT_OF_STORAGE;
        return jadsmp;
    }

    name = midp_find_property(&jadsmp, &SUITE_NAME_PROP);
    if (pcsl_string_is_null(name)) {
        REPORT_INFO(LC_AMS, "Missing suite name");
        jadsmp.status = NO_SUITE_NAME_PROP;
        return jadsmp;
    }

    vendor = midp_find_property(&jadsmp, &SUITE_VENDOR_PROP);
    if (pcsl_string_is_null(vendor)) {
        REPORT_INFO(LC_AMS,  "Missing suite vendor");
        jadsmp.status =  NO_SUITE_VENDOR_PROP;
        return jadsmp;
    }

    version = midp_find_property(&jadsmp, &SUITE_VERSION_PROP);
    if (pcsl_string_is_null(version)) {
        REPORT_INFO(LC_AMS,  "Missing suite version");
        jadsmp.status = NO_SUITE_VERSION_PROP;
        return jadsmp;
    }
    if (!midpCheckVersion(version)) {
        REPORT_INFO(LC_AMS,  "Corrupted suite version");
        jadsmp.status = NO_SUITE_VERSION_PROP;
        return jadsmp;
    }
    return jadsmp;
} /* verifyJadMUSTProperties */
Beispiel #4
0
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;
}
Beispiel #5
0
/**
 * Compares JAD and Manifest file properties that MUST be the same.
 * The properties are:
 * <B>MIDlet-Name</B>
 * <B>MIDlet-Vendor</B>
 * <B>MIDlet-Version</B>
 *
 * @param jadsmp MidpProperties struct that contains parsed JAD properties.
 * @param mfsmp  MidpProperties struct that contains parsed Manifest properties.
 * @return On success: ALL_OK
 *         On mismatch:
 *             SUITE_NAME_PROP_NOT_MATCH
 *             SUITE_VENDOR_PROP_NOT_MATCH
 *             SUITE_VERSION_PROP_NOT_MATCH
 *         On missing property:
 *             NO_SUITE_NAME_PROP
 *             NO_SUITE_VENDOR_PROP
 *             NO_SUITE_VERSION_PROP
 */
int compareJADandManifestProperties(MidpProperties* jadsmp, MidpProperties* mfsmp) {
    /* three properties MUST be similar in jad and manifest */
    const pcsl_string* jad_name = &PCSL_STRING_NULL;
    const pcsl_string* jad_version = &PCSL_STRING_NULL;
    const pcsl_string* jad_vendor = &PCSL_STRING_NULL;

    const pcsl_string* mf_name = &PCSL_STRING_NULL;
    const pcsl_string* mf_version = &PCSL_STRING_NULL;
    const pcsl_string* mf_vendor = &PCSL_STRING_NULL;
    /* compare jad and manifest properties */
    jad_name = midp_find_property(jadsmp, &SUITE_NAME_PROP);
    if (pcsl_string_is_null(jad_name)) {
        REPORT_ERROR(LC_AMS, "Can't get SUITE_NAME_PROP from JAD. This should not happen at this stage!");
        return NO_SUITE_NAME_PROP;
    }
    mf_name = midp_find_property(mfsmp, &SUITE_NAME_PROP);
    if (pcsl_string_is_null(mf_name)) {
        REPORT_ERROR(LC_AMS, "Can't get SUITE_NAME_PROP from Manifest.  This should not happen at this stage!");
        return NO_SUITE_NAME_PROP;
        /* handle it some how */
    }
    if ( ! pcsl_string_equals(jad_name, mf_name)) {
        /* versions are not equal */
        REPORT_ERROR(LC_AMS, "Manifest and Jad names are not equal.");
        return SUITE_NAME_PROP_NOT_MATCH;
    }

    jad_vendor = midp_find_property(jadsmp, &SUITE_VENDOR_PROP);
    if (pcsl_string_is_null(jad_vendor)) {
        REPORT_ERROR(LC_AMS, "Can't get SUITE_VENDOR_PROP from JAD.  This should not happen at this stage!\n");
        return NO_SUITE_VENDOR_PROP;
    }
    mf_vendor = midp_find_property(mfsmp, &SUITE_VENDOR_PROP);
    if (pcsl_string_is_null(mf_vendor)) {
        REPORT_ERROR(LC_AMS, "Can't get SUITE_VENDOR_PROP from Manifest. This should not happen at this stage!");
        return NO_SUITE_VENDOR_PROP;
    }

    if ( ! pcsl_string_equals(jad_vendor, mf_vendor)) {
        /* versions are not equal */
        REPORT_ERROR(LC_AMS, "Manifest and Jad vendors are not equal.");
        return SUITE_VENDOR_PROP_NOT_MATCH;
    }

    jad_version = midp_find_property(jadsmp, &SUITE_VERSION_PROP);
    if (pcsl_string_is_null(jad_version)) {
        REPORT_ERROR(LC_AMS, "Can't get SUITE_VERSION_PROP from JAD. This should not happen at this stage!");
        return NO_SUITE_VERSION_PROP;
    }
    mf_version = midp_find_property(mfsmp, &SUITE_VERSION_PROP);
    if (pcsl_string_is_null(mf_version)) {
        REPORT_ERROR(LC_AMS, "Can't get SUITE_VERSION_PROP from Manifest. This should not happen at this stage!");
        return NO_SUITE_VERSION_PROP;
    }
    {
        if (0 != midpCompareVersion(jad_version, mf_version)) {
            /* versions are not equal */
            REPORT_ERROR(LC_AMS, "Manifest and Jad versions are not equal.");
            return SUITE_VERSION_PROP_NOT_MATCH;
        }
    }

    return ALL_OK;
} /* end of compareJADandManifestProperties */
Beispiel #6
0
/**
 * Prints a property value to <tt>stdout</tt>.
 *
 * @param pszLabel A 'C' string label to be printed before the
 *                 property value
 * @param key The property key of the value to print
 * @param props The properties to search for <tt>key</tt>
 */
static void
printProperty(char* pszLabel, const pcsl_string * key, MidpProperties props) {
    print_field(pszLabel, midp_find_property(&props, key));
}
/**
 * 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;
}