manifestparser.c

来自「This is a resource based on j2me embedde」· C语言 代码 · 共 653 行 · 第 1/2 页

C
653
字号
            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 */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 *//** * Reads a line from a manifest file. Compacts continuation lines.<BR> * (Allocates memory for this line.) * * @param mfbuf  pointer to the manifest jchar_buffer; this pointer will move to *               the next line * @param result pointer to pcsl_string where the new line from manifest *               will be stored * @return error code */static MIDPError readMfLine(jchar** mfbuf, pcsl_string * result) {    jchar* lineStart = NULL;    int is_broken_line = 0;    jchar* p = NULL;    int count = 0;    int i = 0;    *result = PCSL_STRING_NULL;    /* will use p to avoid all the *(*mfbuf) stuff and make it more readable */    p = (*mfbuf);    if (!(*p)) {        /* end of jchar_buffer */        return END_OF_MF;    }    /* skip commented out and blank lines */    while (COMMENTED_OUT(p) || NEW_LINE(p)) {        while (!NEW_LINE(p)) {            p++; /* skip commented out line */        }        while (NEW_LINE(p)) {            p++; /* skip new line */        }        /* now pointing to the next line */        if (MF_SPACE(p)) { /* if starting with space */            while (!NEW_LINE(p)) {                p++; /* skip the line */            }        } /* end of if */    } /* end of while */    lineStart = p;    for (;*p ;) {        count++;        p++;        if (NEW_LINE(p) && !MF_BROKEN_LINE(p)) {            *p = 0x00; /* cut the line */            if (*(p+1)) { /* if not end of the buffer */                p++; /* point to the next line beginning */                break;            }        } else if (MF_BROKEN_LINE(p)) {            while (!MF_SPACE(p)) { /* look for the space */                count++;                p++;            }            /* once space found, point to the next character and go ahead */            count++;            p++;            is_broken_line = 1;            continue;        } /* end of else */    } /* end of for */    /* move mfbuf to point to the next line */    (*mfbuf) = p;    pcsl_string_predict_size(result, count);    if (is_broken_line) {        i = 0;        while (*(lineStart+i)) {            /* here once we have a new line it will be followed by space */            if (NEW_LINE_1(lineStart+i)) {                i+=3;                count-=3;            } else if (NEW_LINE(lineStart+i)) {                i+=2;                count-=2;            }            if (PCSL_STRING_OK !=                pcsl_string_append_char(result, lineStart[i])) {                pcsl_string_free(result);                return OUT_OF_MEMORY;            }            i++;        }    } else {        if (PCSL_STRING_OK !=            pcsl_string_convert_from_utf16(lineStart, count, result)) {            return OUT_OF_MEMORY;        }    }    return ALL_OK;} /* end of readMfLine *//** * Counts a lines in manifest file. Skips commented out and blank lines. * * @param buf * @return */static int count_mf_lines(jchar* buf) {    int numberOfLines = 0;    if ((!buf) || (!*buf)) {        return -1;    }    while (*buf) {        /* skip commented out lines and lines that start with space */        if ((COMMENTED_OUT(buf)) || (MF_SPACE(buf))) {            /* run to the end of line */            while (!NEW_LINE(buf)) {                buf++;            }            /* skip all the new line characters an the end of line */            while (NEW_LINE(buf)) {                buf++;            }        } else {            numberOfLines++;            while (!NEW_LINE(buf)) {                buf++;            }            while (NEW_LINE(buf)) {                buf++;            }        }    } /* end of while */    return numberOfLines;} /* end of count_mf_lines *//** * 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 *//** * 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 */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?