Пример #1
0
/**
 * Check to see if all the chars in the value of a property are valid.
 *
 * @param value value to check
 *
 * @return false if a character is not valid for a value
 */
static MIDPError checkMfValueChars(const pcsl_string * mfvalue) {
    jchar current;
    int i = 0;
    MIDPError err = ALL_OK;

    GET_PCSL_STRING_DATA_AND_LENGTH(mfvalue)
    if (PCSL_STRING_PARAMETER_ERROR(mfvalue)) {
        err = OUT_OF_MEMORY;
    } else {
        while (i < mfvalue_len) {
            current = mfvalue_data[i];
            /* if current is a CTL character, return an error */
            if ((current <= 0x1F || current == 0x7F) && (current != HT)) {
                printPcslStringWithMessage("checkMfValueChars: BAD_MF_VALUE ",
                                           mfvalue);
                err = BAD_MF_VALUE;
                break;
            }
            i++;
        } /* end of while */
    }
    RELEASE_PCSL_STRING_DATA_AND_LENGTH

    return err;
} /* end of checkMfValueChars */
Пример #2
0
/**
 * Check to see if all the chars in the key of a property are valid.
 *
 * @param jadkey key to check
 * @return BAD_JAD_KEY if a character is not valid for a key
 */
static MIDPError checkJadKeyChars(const pcsl_string * jadkey) {
    jchar current;
    int i = 0;
    MIDPError err = ALL_OK;

    GET_PCSL_STRING_DATA_AND_LENGTH(jadkey)
    if (PCSL_STRING_PARAMETER_ERROR(jadkey)) {
        err = OUT_OF_MEMORY;
    } else {
        while (i < jadkey_len) {
            current = jadkey_data[i];
            if (current <= 0x1F
             || current == 0x7F
             || current == '('
             || current == ')'
             || current == '<'
             || current == '>'
             || current == '@'
             || current == ','
             || current == ';'
             || current == '\''
             || current == '"'
             || current == '/'
             || current == '['
             || current == ']'
             || current == '?'
             || current == '='
             || current == '{'
             || current == '}'
             || current == SP
             || current == HT) {
                printPcslStringWithMessage("checkJadKeyChars: BAD_JAD_KEY ",
                                           jadkey);
                err = BAD_JAD_KEY;
                break;
            }
            i++;
        } /* end of while */
    }
    RELEASE_PCSL_STRING_DATA_AND_LENGTH

    return err;
}
Пример #3
0
/**
 * Check to see if all the chars in the key of a property are valid.
 *
 * @param key key to check
 *
 * @return an error if a character is not valid for a key
 */
static MIDPError checkMfKeyChars(const pcsl_string * mfkey) {
    /* IMPL NOTE: why chars in manifest key are different from jad key? */
    jchar current;
    int i = 0;
    MIDPError err = ALL_OK;

    GET_PCSL_STRING_DATA_AND_LENGTH(mfkey)
    if (PCSL_STRING_PARAMETER_ERROR(mfkey)) {
        err = OUT_OF_MEMORY;
    } else {
        while (i < mfkey_len) {
            current = mfkey_data[i];
            i++;

            if (current >= 'A' && current <= 'Z') {
                continue;
            }

            if (current >= 'a' && current <= 'z') {
                continue;
            }

            if (current >= '0' && current <= '9') {
                continue;
            }

            if ((i - 1) > 0 && (current == '-' || current == '_')) {
                continue;
            }

            printPcslStringWithMessage("checkMfKeyChars: BAD_MF_KEY ", mfkey);
            err = BAD_MF_KEY;
            break;
        } /* end of while */
    }
    RELEASE_PCSL_STRING_DATA_AND_LENGTH

    return err;
} /* end of checkMfKeyChars */
Пример #4
0
static MidpProperties midpParseMf(jchar* jchar_buffer) {

    MidpProperties mfsmp = {0, ALL_OK, NULL};
    pcsl_string mfkey;
    pcsl_string mfkey_trimmed;
    pcsl_string mfvalue;
    pcsl_string mfvalue_trimmed;
    pcsl_string mfline;
    MIDPError err;
    pcsl_string_status rc;

    int countLines = 0;
    int index = 0;
    int count = 0;

    if (!jchar_buffer) {
        mfsmp.status = BAD_PARAMS;
        return mfsmp;
    }

    countLines = count_mf_lines(jchar_buffer);

    if (countLines <= 0) {
        REPORT_INFO(LC_AMS, "midpParseMf(): Empty manifest.");
        mfsmp.status = OUT_OF_MEMORY;
        return mfsmp;
    }

    mfsmp.pStringArr = alloc_pcsl_string_list(countLines * 2);
    if (mfsmp.pStringArr == NULL) {
        mfsmp.status = OUT_OF_MEMORY;
        return mfsmp;
    }

    mfsmp.numberOfProperties = countLines;

    for (count = 0; count < countLines * 2 ;
         /* count increased at the end of for */ ) {
        /* memory for the line is allocated here */
        /* line continuation striped out */
        err = readMfLine(&jchar_buffer, &mfline);
        if (OUT_OF_MEMORY == err) {
            midp_free_properties(&mfsmp);
            mfsmp.status = OUT_OF_MEMORY;
            return mfsmp;
        } else if (END_OF_MF == err) {
            /* we are done */
            mfsmp.status = ALL_OK;
            break;
        }

        index = pcsl_string_index_of(&mfline, ':');
        if (index <= 0) {
            mfsmp.status = BAD_MF_KEY;
            pcsl_string_free(&mfline);
            continue;
        }

        /* memory for mfkey is allocated here */
        if (PCSL_STRING_OK !=
            pcsl_string_substring(&mfline, 0, index, &mfkey)) {
            midp_free_properties(&mfsmp);
            mfsmp.status = OUT_OF_MEMORY;
            pcsl_string_free(&mfline);
            return mfsmp;
        }

        rc = pcsl_string_trim(&mfkey, &mfkey_trimmed);
        pcsl_string_free(&mfkey);
        if (PCSL_STRING_OK != rc) {
            mfsmp.status = OUT_OF_MEMORY;
            midp_free_properties(&mfsmp);
            pcsl_string_free(&mfline);
            return mfsmp;
        }

        if (pcsl_string_length(&mfkey_trimmed) < 1) {
            mfsmp.status = BAD_PARAMS;
            pcsl_string_free(&mfline);
            pcsl_string_free(&mfkey_trimmed);
            continue;
        }

        err = checkMfKeyChars(&mfkey_trimmed);
        if (OUT_OF_MEMORY == err) {
            mfsmp.status = OUT_OF_MEMORY;
            midp_free_properties(&mfsmp);
            pcsl_string_free(&mfline);
            pcsl_string_free(&mfkey_trimmed);
            return mfsmp;
        } else if (BAD_MF_KEY == err) {
            mfsmp.status = BAD_MF_KEY;
            pcsl_string_free(&mfline);
            pcsl_string_free(&mfkey_trimmed);
            continue;
        }

        rc = pcsl_string_substring(&mfline, index + 1,
                                   pcsl_string_length(&mfline), &mfvalue);
        /* free the mfline once we have got the key and value */
        pcsl_string_free(&mfline);
        if (PCSL_STRING_OK != rc) {
            mfsmp.status = OUT_OF_MEMORY;
            midp_free_properties(&mfsmp);
            pcsl_string_free(&mfkey_trimmed);
            return mfsmp;
        }

        /* memory for value is allocated here */
        rc = pcsl_string_trim(&mfvalue, &mfvalue_trimmed);
        pcsl_string_free(&mfvalue);
        if (PCSL_STRING_OK != rc) {
            mfsmp.status = OUT_OF_MEMORY;
            midp_free_properties(&mfsmp);
            pcsl_string_free(&mfkey_trimmed);
            return mfsmp;
        }
        if (pcsl_string_is_null(&mfvalue_trimmed)) {
            mfsmp.status = NULL_LEN;
            pcsl_string_free(&mfkey_trimmed);
            continue;
        }

        err = checkMfValueChars(&mfvalue_trimmed);
        if (OUT_OF_MEMORY == err) {
            mfsmp.status = OUT_OF_MEMORY;
            midp_free_properties(&mfsmp);
            pcsl_string_free(&mfkey_trimmed);
            pcsl_string_free(&mfvalue_trimmed);
            return mfsmp;
        } else if (BAD_MF_VALUE == err) {
            mfsmp.status = BAD_MF_VALUE;
            pcsl_string_free(&mfkey_trimmed);
            pcsl_string_free(&mfvalue_trimmed);
            continue;
        }

        printPcslStringWithMessage("midpParseMf()", &mfkey_trimmed);
        printPcslStringWithMessage(" = ", &mfvalue_trimmed);

        /* Store key:value pair. */
        mfsmp.pStringArr[count] = mfkey_trimmed;
        mfsmp.pStringArr[count+1] = mfvalue_trimmed;

        count += 2;
    } /* end of for */

    mfsmp = verifyMfMustProperties(mfsmp);
    REPORT_INFO3(LC_AMS,
		 "End of midpParseMf: Status=%d, count=%d, countLines=%d",
		 mfsmp.status, count, countLines);

    return mfsmp;
} /* end of midpParseMf */
Пример #5
0
MidpProperties mf_main(char* mfbuf, int mflength) {

    MidpProperties mfsmp      = {0, ALL_OK, NULL};
    jchar* save_jchar_buffer  = NULL;
    jchar* jchar_buffer       = NULL;
    int jbufsize              = -1;
#if REPORT_LEVEL <= LOG_INFORMATION
    int res                   = 0;
#endif
    if ((mflength <= 0) || (!mfbuf)) {
        mfsmp.status = OUT_OF_MEMORY;
        return mfsmp;
    }

    jbufsize = mflength * sizeof(jchar);

    jchar_buffer = (jchar*)midpMalloc(jbufsize+2);
    if (!jchar_buffer) {
        midpFree(mfbuf);
        mfsmp.status = OUT_OF_MEMORY;
        return mfsmp;
    }
    memset(jchar_buffer,0,(jbufsize + 2));

    convertChar2JChar(mfbuf,jchar_buffer,mflength);

    midpFree(mfbuf);

    save_jchar_buffer = jchar_buffer;

    REPORT_INFO(LC_AMS,
		"#########################  Start of manifest parsing");

    /* during execution of this, jchar_buffer pointer will be changed */
    mfsmp = midpParseMf(jchar_buffer);
    midpFree(save_jchar_buffer);
    switch (mfsmp.status) {

    case NO_SUITE_NAME_PROP:
        midp_free_properties(&mfsmp);
        return mfsmp;

    case NO_SUITE_VENDOR_PROP:
        midp_free_properties(&mfsmp);
        return mfsmp;

    case NO_SUITE_VERSION_PROP:
        midp_free_properties(&mfsmp);
        return mfsmp;

    case NO_MIDLET_ONE_PROP:
        midp_free_properties(&mfsmp);
        return mfsmp;

    case NO_MICROEDITION_PROFILE_PROP:
        midp_free_properties(&mfsmp);
        return mfsmp;

    case NO_MICROEDITION_CONFIGURATION_PROP:
        REPORT_INFO1(LC_AMS,
		     "Manifest MUST property missing %d", mfsmp.status);
        return mfsmp;

    case BAD_PARAMS:
    case BAD_MF_KEY:
    case BAD_MF_VALUE:
        REPORT_INFO1(LC_AMS,
		     "Some NOT MUST Manifest property is not valid %d",
		     mfsmp.status);
        break;

    case ALL_OK:
        REPORT_INFO1(LC_AMS, "Manifest ALL_OK %d", mfsmp.status);
        break;

    default:
        REPORT_INFO1(LC_AMS, "MF parse OUT_OF_MEMORY %d", mfsmp.status);
        /* for unknown result assuming OUT_OF_MEMORY */
        return mfsmp;

    } /* end of switch */

#if REPORT_LEVEL <= LOG_INFORMATION
    reportToLog(LOG_INFORMATION, LC_AMS, "%s %s %d",
		"###########################  End   of manifest parsing:  ",
		"mf_main() : number of Manifest properties = ",
		mfsmp.numberOfProperties);
    for (res = 0; res < mfsmp.numberOfProperties * 2; res += 2) {
        printPcslStringWithMessage(" ", &mfsmp.pStringArr[res]);
        printPcslStringWithMessage(" ", &mfsmp.pStringArr[res+1]);
    }
#endif

    return mfsmp;
} /* end of mf_main */
Пример #6
0
static MidpProperties midpParseJad(jchar* jchar_buffer) {
    MidpProperties jadsmp = {0, ALL_OK, NULL};
    pcsl_string jadkey;
    pcsl_string jadkey_trimmed;
    pcsl_string jadvalue;
    pcsl_string jadvalue_trimmed;
    pcsl_string jadline;
    MIDPError err;
    pcsl_string_status rc;

    int countLines = 0;
    jint index = 0;
    int count = 0;

    if (!jchar_buffer) {
        jadsmp.status = BAD_PARAMS;
        return jadsmp;
    }

    countLines = count_jad_lines(jchar_buffer);

    if (countLines <= 0) {
        REPORT_INFO(LC_AMS, "midpParseJad(): Empty jad file.");
        jadsmp.status = OUT_OF_MEMORY;
        return jadsmp;
    }

    jadsmp.pStringArr = alloc_pcsl_string_list(countLines * 2);
    if (jadsmp.pStringArr == NULL) {
        jadsmp.status = OUT_OF_MEMORY;
        return jadsmp;
    }

    jadsmp.numberOfProperties = countLines;

    for (count = 0; count < countLines * 2 ;
        /* count increased at the end of for */ ) {
        /* memory for the line is allocated here */
        err = readJadLine(&jchar_buffer, &jadline);
        if (OUT_OF_MEMORY == err) {
            midp_free_properties(&jadsmp);
            jadsmp.status = OUT_OF_MEMORY;
            return jadsmp;
        } else if (END_OF_JAD == err) {
            /* we are done */
            jadsmp.status = ALL_OK;
            break;
        }

        index = pcsl_string_index_of(&jadline, ':');
        if (index <= 0) {
            jadsmp.status = BAD_JAD_KEY;
            pcsl_string_free(&jadline);
            continue;
        }

        /* memory for key is allocated here */
        if (PCSL_STRING_OK !=
            pcsl_string_substring(&jadline, 0, index, &jadkey)) {
            midp_free_properties(&jadsmp);
            jadsmp.status = OUT_OF_MEMORY;
            pcsl_string_free(&jadline);
            return jadsmp;
        }

        rc = pcsl_string_trim(&jadkey, &jadkey_trimmed);
        pcsl_string_free(&jadkey);
        if (PCSL_STRING_OK != rc) {
            jadsmp.status = OUT_OF_MEMORY;
            midp_free_properties(&jadsmp);
            pcsl_string_free(&jadline);
            return jadsmp;
        }

        if (pcsl_string_length(&jadkey_trimmed) < 1) {
            jadsmp.status = BAD_PARAMS;
            pcsl_string_free(&jadline);
            pcsl_string_free(&jadkey_trimmed);
            continue;
        }

        err = checkJadKeyChars(&jadkey_trimmed);
        if (OUT_OF_MEMORY == err) {
            jadsmp.status = OUT_OF_MEMORY;
            midp_free_properties(&jadsmp);
            pcsl_string_free(&jadline);
            pcsl_string_free(&jadkey_trimmed);
            return jadsmp;
        } else if (BAD_JAD_KEY == err) {
            jadsmp.status = BAD_JAD_KEY;
            pcsl_string_free(&jadline);
            pcsl_string_free(&jadkey_trimmed);
            continue;
        }

        rc = pcsl_string_substring(&jadline, index + 1,
                                   pcsl_string_length(&jadline), &jadvalue);
        /* free the jadline once we have got the key and value */
        pcsl_string_free(&jadline);
        if (PCSL_STRING_OK != rc) {
            jadsmp.status = OUT_OF_MEMORY;
            midp_free_properties(&jadsmp);
            pcsl_string_free(&jadkey_trimmed);
            return jadsmp;
        }

        /* memory for value is allocated here */
        rc = pcsl_string_trim(&jadvalue, &jadvalue_trimmed);
        pcsl_string_free(&jadvalue);
        if (PCSL_STRING_OK != rc) {
            jadsmp.status = OUT_OF_MEMORY;
            midp_free_properties(&jadsmp);
            pcsl_string_free(&jadkey_trimmed);
            return jadsmp;
        }
        if (pcsl_string_is_null(&jadvalue_trimmed)) {
            jadsmp.status = NULL_LEN;
            pcsl_string_free(&jadkey_trimmed);
            continue;
        }

        err = checkJadValueChars(&jadvalue_trimmed);
        if (OUT_OF_MEMORY == err) {
            jadsmp.status = OUT_OF_MEMORY;
            midp_free_properties(&jadsmp);
            pcsl_string_free(&jadkey_trimmed);
            pcsl_string_free(&jadvalue_trimmed);
            return jadsmp;
        } else if (BAD_JAD_VALUE == err) {
            jadsmp.status = BAD_JAD_VALUE;
            pcsl_string_free(&jadkey_trimmed);
            pcsl_string_free(&jadvalue_trimmed);
            continue;
        }

        printPcslStringWithMessage("midpParseJad()", &jadkey_trimmed);
        printPcslStringWithMessage("midpParseJad()", &jadvalue_trimmed);

        /* Store key:value pair. */
        jadsmp.pStringArr[count] = jadkey_trimmed;
        jadsmp.pStringArr[count+1] = jadvalue_trimmed;

        count += 2;
    } /* end of for */

    jadsmp = verifyJadMustProperties(jadsmp);

    REPORT_INFO3(LC_AMS,
                 "End jad parsing. Status=%d, count=%d, countLines=%d.",
                 jadsmp.status, count, countLines);

    return jadsmp;
} /* end of midpParseJad */
Пример #7
0
MidpProperties jad_main(char* jadbuf, int jadsize) {

    MidpProperties jadsmp = {0,ALL_OK,NULL};
    jchar* jchar_buffer = NULL;
    jchar* save_jchar_buffer = NULL;
    int jbufsize = -1;
#if REPORT_LEVEL <= LOG_INFORMATION
    int res = 0;
#endif
    jbufsize = jadsize * sizeof(jchar);

    jchar_buffer = (jchar*)midpMalloc(jbufsize+2);
    if (!jchar_buffer) {
        midpFree(jadbuf);
        jadsmp.status = OUT_OF_MEMORY;
        return jadsmp;
    }
    memset(jchar_buffer,0,(jbufsize + 2));

    convertChar2JChar(jadbuf,jchar_buffer,jadsize);
    midpFree(jadbuf);
    save_jchar_buffer = jchar_buffer;



    REPORT_INFO(LC_AMS, "####################### Start JAD parsing");

    /* during execution of this function jadbuf pointer will be changed
       status will be set during midpParseJad() execution */
    jadsmp = midpParseJad(jchar_buffer);
    midpFree(save_jchar_buffer);
    switch (jadsmp.status) {
    case OUT_OF_STORAGE:
        REPORT_WARN1(LC_AMS, "OUT_OF_STORAGE by JAD %d", jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case NO_JAR_URL_PROP:
        REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case NO_SUITE_NAME_PROP:
        REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case NO_SUITE_VENDOR_PROP:
        REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case NO_SUITE_VERSION_PROP:
        REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case NO_JAR_SIZE_PROP:
        REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case NUMBER_ERROR:
        REPORT_INFO1(LC_AMS,
		     "Error during parsing JAR size written in JAD %d",
		     jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case BAD_PARAMS:
    case BAD_JAD_KEY:
    case BAD_JAD_VALUE:
        REPORT_INFO1(LC_AMS,
		     "Some NOT mandatory Jad properties is not valid %d",
		     jadsmp.status);
        break;

    case ALL_OK:
        REPORT_INFO1(LC_AMS, "Jad ALL_OK %d", jadsmp.status);
        break;

    default:
        /* for an unknown result assuming OUT_OF_MEMORY */
        REPORT_INFO1(LC_AMS, "JAD parse OUT_OF_MEMORY %d", jadsmp.status);
        return jadsmp;
    } /* end of switch */

#if REPORT_LEVEL <= LOG_INFORMATION
    reportToLog(LOG_INFORMATION, LC_AMS,
		"######################### End of JAD parsing\n"
		"jad_main() : number of JAD properties = %d",
		jadsmp.numberOfProperties);

    for (res = 0; res < jadsmp.numberOfProperties*2; res+=2 ) {
        printPcslStringWithMessage(" ", &jadsmp.pStringArr[res]);
        printPcslStringWithMessage(" ", &jadsmp.pStringArr[res+1]);
    }
#endif

    return jadsmp;
} /* end of jad_main */
Пример #8
0
/**
 * Version string may looks like Major:Minor:Micro
 *
 * @param ver    pcsl_string that contains a version
 * @param major  Major version
 * @param minor  Minor version
 * @param micro  Micro version
 * @return 1 == OK
 *         0 = BAD version
 */
int midpGetVersion(const pcsl_string * ver, int *major, int *minor, int *micro) {
    int ma = 0;
    int mi = 0;
    int mc = 0;
    int count = 0;
    int dot_count = 0;
    int segment_size = 0;
    const jchar* p = NULL;
    const jchar* ver_data;
    jsize ver_len = pcsl_string_utf16_length(ver);

    *major = -1;
    *minor = -1;
    *micro = -1;

    if ((ver_len <= 0) || (ver_len > 8)) {
        return 0;
    }
    printPcslStringWithMessage("ver", ver);

    ver_data = pcsl_string_get_utf16_data(ver);
    if (NULL == ver_data) {
        return 0;
    }

    /* most checking done here */
    for (count=0; count < ver_len; count++) {
        if ((ver_data[count] >= '0') && (ver_data[count] <= '9')) {
            segment_size++;
        } else if (ver_data[count] == '.') {
            if ((segment_size == 0) || (segment_size > 2)) {
                REPORT_ERROR1(LC_AMS, "segment size wrong %d",
                              segment_size);
                pcsl_string_release_utf16_data(ver_data, ver);
                return 0;
            }
            dot_count++;
            segment_size = 0;
        } else {
            pcsl_string_release_utf16_data(ver_data, ver);
            return 0;
        }
    } /* end of for */

    /* can't be more then 2 dots in version */
    if (dot_count > 2) {
        REPORT_ERROR1(LC_AMS, "too many dots (%d)", dot_count);
        pcsl_string_release_utf16_data(ver_data, ver);
        return 0;
    }

    /*
     * Get major version
     */
    for (p = ver_data, count = 0; (*p != '.') && (count < ver_len); ) {
        if (*p >= '0' && *p <= '9') {
            ma *= 10;
            ma += *p - '0';
        } else {
            pcsl_string_release_utf16_data(ver_data, ver);
            return 0;
        }
        count++;
        p++;
    } /* end of for */

    if(*p == '.') {
        p++;
        count++;
    }

    /*
     * Get minor version.
     */
    for ( ; (*p != '.') && (count < ver_len); ) {
        if (*p >= '0' && *p <= '9') {
            mi *= 10;
            mi += *p - '0';
        } else {
            pcsl_string_release_utf16_data(ver_data, ver);
            return 0;
        }
        count++;
        p++;
    }

    if(*p == '.') {
        p++;
        count++;
    }

    /*
     * Get micro version; if it exists..
     */
    for ( ; (*p != '.') && (count < ver_len); ) {
        if (*p >= '0' && *p <= '9') {
            mc *= 10;
            mc += *p - '0';
        } else {
            pcsl_string_release_utf16_data(ver_data, ver);
            return 0;
        }
        p++;
        count++;
    }
    *major = ma;
    *minor = mi;
    *micro = mc;
    pcsl_string_release_utf16_data(ver_data, ver);
    return 1;
}