示例#1
0
static MIDPError buildSuiteFilename(pcsl_string* filenameBase, 
                                    const pcsl_string* name, jint extension, 
                                    pcsl_string* pFileName) {

    pcsl_string returnPath = PCSL_STRING_NULL;
    pcsl_string rmsFileName = PCSL_STRING_NULL;

    jsize filenameBaseLen = pcsl_string_length(filenameBase);
    jsize nameLen = pcsl_string_length(name);

    *pFileName = PCSL_STRING_NULL;

    if (nameLen > 0) {
        const pcsl_string* ext;
        jsize extLen;
        int fileNameLen;

        if (MIDP_RMS_IDX_EXT == extension) {
            ext = &IDX_EXTENSION;
            extLen = pcsl_string_length(&IDX_EXTENSION);
        } else if (MIDP_RMS_DB_EXT == extension) {
            ext = &DB_EXTENSION;
            extLen = pcsl_string_length(&DB_EXTENSION);
        } else {
            return BAD_PARAMS;
        }

        /* performance hint: predict buffer capacity */
        fileNameLen = PCSL_STRING_ESCAPED_BUFFER_SIZE(nameLen + extLen);
        pcsl_string_predict_size(&rmsFileName, fileNameLen);

        if (pcsl_esc_attach_string(name, &rmsFileName) !=
                PCSL_STRING_OK ||
                    pcsl_string_append(&rmsFileName, ext) != PCSL_STRING_OK) {
            pcsl_string_free(&rmsFileName);
            return OUT_OF_MEMORY;
        }
    }

    /* performance hint: predict buffer capacity */
    pcsl_string_predict_size(&returnPath, filenameBaseLen + 
                             pcsl_string_length(&rmsFileName));

    if (PCSL_STRING_OK != pcsl_string_append(&returnPath, filenameBase) ||
            PCSL_STRING_OK != pcsl_string_append(&returnPath, &rmsFileName)) {
        pcsl_string_free(&rmsFileName);
        pcsl_string_free(&returnPath);
        return OUT_OF_MEMORY;
    }

    pcsl_string_free(&rmsFileName);
   *pFileName = returnPath;

    return ALL_OK;
}
/**
 * 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>
 */
MIDPError
midp_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;
}
示例#3
0
/**
 * Gets location of the resource with specified type and name
 * for the suite with the specified suiteId.
 *
 * Note that the implementation of this function MUST allocate the memory
 * for the in/out parameter filename 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 where the RMS will be located
 * NOTE: currently this parameter is ignored due to limitation of our
 * implementation: RMS is always located at the same storage as the suite.
 * @param extension rms extension that can be MIDP_RMS_DB_EXT or
 * MIDP_RMS_IDX_EXT
 * @param pResourceName RMS name
 * @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>
 */
MIDPError
midp_suite_get_rms_filename(SuiteIdType suiteId,
                            StorageIdType storageId,
                            jint extension,
                            const pcsl_string* pResourceName,
                            pcsl_string* pFileName) {
    const pcsl_string* root;
    pcsl_string returnPath = PCSL_STRING_NULL;
    pcsl_string rmsFileName = PCSL_STRING_NULL;
    jint suiteIdLen = GET_SUITE_ID_LEN(suiteId);
    jsize resourceNameLen = pcsl_string_length(pResourceName);

    /*
     * IMPL_NOTE: currently we have a limitation that the suite's RMS
     * must be located at the same storage as the midlet suite.
     * See rms.c, rmsdb_get_record_store_space_available() for more details.
     */
    root = storage_get_root(storageId);

    *pFileName = PCSL_STRING_NULL;

    if (resourceNameLen > 0) {
        const pcsl_string* ext;
        jsize extLen;
        int fileNameLen;

        if (MIDP_RMS_IDX_EXT == extension) {
            ext = &IDX_EXTENSION;
            extLen = pcsl_string_length(&IDX_EXTENSION);
        } else if (MIDP_RMS_DB_EXT == extension) {
            ext = &DB_EXTENSION;
            extLen = pcsl_string_length(&DB_EXTENSION);
        } else {
            return BAD_PARAMS;
        }

        /* performance hint: predict buffer capacity */
        fileNameLen = PCSL_STRING_ESCAPED_BUFFER_SIZE(resourceNameLen + extLen);
        pcsl_string_predict_size(&rmsFileName, fileNameLen);

        if (pcsl_string_append_escaped_ascii(&rmsFileName, pResourceName) !=
                PCSL_STRING_OK ||
                    pcsl_string_append(&rmsFileName, ext) != PCSL_STRING_OK) {
            pcsl_string_free(&rmsFileName);
            return OUT_OF_MEMORY;
        }
    }

    /* performance hint: predict buffer capacity */
    pcsl_string_predict_size(&returnPath, pcsl_string_length(root) +
        suiteIdLen + pcsl_string_length(&rmsFileName));

    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, &rmsFileName)) {
        pcsl_string_free(&rmsFileName);
        pcsl_string_free(&returnPath);
        return OUT_OF_MEMORY;
    }

    pcsl_string_free(&rmsFileName);

    *pFileName = returnPath;

    return ALL_OK;
}