Esempio n. 1
0
int
midpJarEntryExists(void* handle, const pcsl_string * name) {
    MidpJarInfo* pJarInfo = (MidpJarInfo*)handle;
    JarEntryInfo entryInfo;
    unsigned char* pName;
    int nameLen;
    unsigned char* pCompBuffer;

    /* Jar entry names are UTF-8 */
    pName = (unsigned char *)pcsl_string_get_utf8_data(name);
    if (NULL == pName) {
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }

    nameLen = pcsl_string_utf8_length(name);
    pCompBuffer = midpMalloc(nameLen);
    if (NULL == pCompBuffer) {
        pcsl_string_release_utf8_data((jbyte*)pName, name);
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }
    
    entryInfo = findJarEntryInfo(&pJarInfo->fileObj, &pJarInfo->jarInfo,
                pName, nameLen, pCompBuffer);
    pcsl_string_release_utf8_data((jbyte*)pName, name);
    midpFree(pCompBuffer);
    if (JAR_ENTRY_NOT_FOUND == entryInfo.status) {
        return 0;
    }

    if (entryInfo.status != 0) {
        return MIDP_JAR_CORRUPT_ERROR;
    }

    return 1;
}
Esempio n. 2
0
/* Returns the entry size or less than zero if error.
 *  If the entry does not exist, size is 0 and *ppEntry is NULL
 */
long
midpGetJarEntry(void* handle, const pcsl_string * name,
                unsigned char** ppEntry) {
    MidpJarInfo* pJarInfo = (MidpJarInfo*)handle;
    JarEntryInfo entryInfo;
    char*  entryData = NULL;
    int status;
    unsigned char* pName;
    int nameLen;
    unsigned char* pCompBuffer;

    *ppEntry = NULL;

    /* Jar entry names are UTF-8 */
    pName = (unsigned char *)pcsl_string_get_utf8_data(name);
    if (pName == NULL) {
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }

    nameLen = pcsl_string_utf8_length(name);
    pCompBuffer = midpMalloc(nameLen);
    if (pCompBuffer == NULL) {
        pcsl_string_release_utf8_data((jbyte*)pName, name);
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }
    
    entryInfo = findJarEntryInfo(&pJarInfo->fileObj, &pJarInfo->jarInfo,
                pName, nameLen, pCompBuffer);
    pcsl_string_release_utf8_data((jbyte*)pName, name);
    midpFree(pCompBuffer);
    if (entryInfo.status == JAR_ENTRY_NOT_FOUND) {
        return 0;
    }
    
    if (entryInfo.status != 0) {
        return MIDP_JAR_CORRUPT_ERROR;
    }

    entryData = midpMalloc((size_t)entryInfo.decompLen);
    if (entryData == NULL) {
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }

    status = inflateJarEntry(&pJarInfo->fileObj, &pJarInfo->heapManObj,
                             &entryInfo, (unsigned char*)entryData, 0);
    if (status != 0) {
        midpFree(entryData);
        return MIDP_JAR_CORRUPT_ERROR;
    }

    *ppEntry = (unsigned char*)entryData;
    return entryInfo.decompLen;
}
/**
 * Parses a value of MIDP_CONTROL_ARGS property from the midlet suite's
 * JAD file. Syntax of this property is defined by the following grammar:
 * <pre>
 * JAD_CONTROL_PARAM = "MIDP_CONTROL_ARGS" EQUAL *( ";" param)
 * param = report_level_param / log_channels_param / permissions_param /
 * trace_param / assert_param
 * report_level_param = "report_level" EQUAL 1*DIGIT
 * log_channels_param = "log_channels" EQUAL 1*DIGIT *( "," 1*DIGIT)
 * permissions_param  = "allow_all_permissions"
 * trace_param  = "enable_trace" EQUAL bool_val
 * assert_param = "enable_trace" EQUAL bool_val
 * bool_val = 0 / 1
 * </pre>
 *
 * @param pJadProps properties of the midlet suite from its jad file
 * @param pJadArgs [out] buffer where to store pointers to the name and value of
 * each control argument
 * @param maxJadArgs maximal number of arguments that the output buffer can hold
 */
void parse_control_args_from_jad(const MidpProperties* pJadProps,
        MIDP_JAD_CONTROL_ARGS* pJadArgs, int maxJadArgs) {
    int i, currArgNum = 0;
    int numOfJadProps = pJadProps ? pJadProps->numberOfProperties : 0;
    /* MIDP_CONTROL_ARGS */
    PCSL_DEFINE_STATIC_ASCII_STRING_LITERAL_START(propertyName) {
        'M', 'I', 'D', 'P', '_', 'C', 'O', 'N', 'T', 'R', 'O', 'L', '_',
        'A', 'R', 'G', 'S', '\0'
    } PCSL_DEFINE_STATIC_ASCII_STRING_LITERAL_END(propertyName);
    static jbyte propValue[128]; /* buffer to hold MIDP_ARGS jad property */

    for (i = 0; i < (numOfJadProps << 1); i++, i++) {
        if (pcsl_string_equals(&pJadProps->pStringArr[i], &propertyName)) {
            const char *pCurr;
            int propLen = pcsl_string_utf8_length(&pJadProps->pStringArr[i+1]);
            int start_pos, pos = 0;

            if (pcsl_string_convert_to_utf8(&pJadProps->pStringArr[i+1],
                    propValue, sizeof(propValue), NULL) != PCSL_STRING_OK) {
                break;
            }

            /* Parse the value of MIDP_CONTROL_ARGS jad property. */
            pCurr = (const char*)propValue;

            while (pos < propLen && currArgNum < maxJadArgs) {
                /* skip spaces */
                if (*pCurr == ' ') {
                    pCurr++;
                    pos++;
                    continue;
                }

                pJadArgs[currArgNum].pArgName = pCurr;
                start_pos = pos;

                /* look for "=", ";" or end-of-line) */
                while (pos < propLen && *pCurr) {
                    if (*pCurr == '=') {
                        pos++;
                        pJadArgs[currArgNum].pArgValue = ++pCurr;
                        break;
                    } else if (*pCurr == ';') {
                        pJadArgs[currArgNum].pArgValue = NULL;
                        break;
                    }
                    pos++;
                    pCurr++;
                }

                pJadArgs[currArgNum].argNameLen = pos - start_pos - 1;

                /* look for the next delimeter (";" or end-of-line) */
                while (pos < propLen && *pCurr) {
                    pos++;
                    if (*pCurr++ == ';') {
                        break;
                    }
                }

                currArgNum++;
            } /* end while */

            break;
        } /* end if MIDP_ARGS property found in JAD */
    } /* end for each property */

    pJadArgs[currArgNum].pArgName = pJadArgs[currArgNum].pArgValue = NULL;
    pJadArgs[currArgNum].argNameLen = 0;
}