/**
 * 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 */
/**
 * Add an item to the menu. It will be inserted into the 
 * proper popup menu basing on its type.
 *
 * @param cmds new abstract commands
 * @param numOfCmds number of new abstract commands
 * @return status of this call
 */
MidpError CommandManager::setCommands(MidpCommand* cmds, int numOfCmds) {
    MidpError err = KNI_OK;
    int i = count()-1;

    // Remove any popup menu
    for (; i >= 0; i--) {
	    removeItemAt(0);
    }

    // Clear existing popup menu content
    actionMenu->clear();
    goMenu->clear();
    helpMenu->clear();

    // reset state of menu bar when item is active
    actItem = -1;

    // Insert each command to each popup menu basing on its type
    for (i = 0; i < numOfCmds; i++) {
        QString text;
        pcsl_string* short_label = &cmds[i].shortLabel_str;
        GET_PCSL_STRING_DATA_AND_LENGTH(short_label) {
            if(PCSL_STRING_PARAMETER_ERROR(short_label)) {
                REPORT_ERROR(LC_HIGHUI, "out-of-memory error"
                             " in CommandManager::setCommands");
            } else {
                text.setUnicodeCodes(short_label_data,
                                     short_label_len);
            }
        } RELEASE_PCSL_STRING_DATA_AND_LENGTH

        if (cmds[i].type == COMMAND_TYPE_HELP) {
            helpMenu->insertItemTrunc(text, cmds[i].id);

        } else if (cmds[i].type == COMMAND_TYPE_BACK
            || cmds[i].type == COMMAND_TYPE_OK
            || cmds[i].type == COMMAND_TYPE_CANCEL
            || cmds[i].type == COMMAND_TYPE_STOP) {
            goMenu->insertItemTrunc(text, cmds[i].id);
        } else {
            actionMenu->insertItemTrunc(text, cmds[i].id);
        }
    }

    // Only add non-empty popup menus
    if (goMenu->count() > 0) {
	    insertItem(GO_MENUITEM_TEXT, goMenu, -1, 0);
    }
    if (actionMenu->count() > 0) {
	    insertItem(ACTION_MENUITEM_TEXT, actionMenu, -1, 0);
    }
    if (helpMenu->count() > 0) {
        insertItem(HELP_MENUITEM_TEXT, helpMenu, -1, 0);
    }
    return err;
}
/**
 * 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;
}
/**
 * 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 */
Esempio n. 5
0
/**
 * This helper function deletes the specified directory and all
 * its contents.
 *
 * @param pDirName the directory to delete
 */
void do_cleanup(const pcsl_string* pDirName)
{
    pcsl_string name1 = PCSL_STRING_NULL;
    pcsl_string * pSubDir = &name1;
    pcsl_string name2 = PCSL_STRING_NULL;
    pcsl_string * pDirEntry = &name2;
    pcsl_string * tmp;
    javacall_handle listHandle;
    int nestLevel = 0;
    int pathLen;
    javacall_utf16 * fileName = NULL;
    int fileNameLen = 0;
    pcsl_string_status status;
    javacall_result res;
    int finish = 0;
    jchar sep = javacall_get_file_separator();

    // initialize current directory
    if (PCSL_STRING_OK != pcsl_string_dup(pDirName, pSubDir)) {
        return;
    }

    for ( ; ; ) {
        // open upper-level directory for listing
        GET_PCSL_STRING_DATA_AND_LENGTH(pSubDir)
        if (PCSL_STRING_PARAMETER_ERROR(pSubDir)) {
            listHandle = NULL;
        } else {
            listHandle = javacall_dir_open(pSubDir_data, pSubDir_len);
        }
        RELEASE_PCSL_STRING_DATA_AND_LENGTH
        if (NULL == listHandle) {
            pcsl_string_free(pSubDir);
            return;
        }

        // get the first entry in the current directory
        fileName = javacall_dir_get_next(listHandle, &fileNameLen);

        while (NULL != fileName) {
            // compose full path for the directory entry
            if (PCSL_STRING_OK != pcsl_string_dup(pSubDir, pDirEntry)) {
                javacall_dir_close(listHandle);
                pcsl_string_free(pSubDir);
                return;
            }
            pcsl_string_predict_size(pDirEntry, pcsl_string_length(pDirEntry) + 1 + fileNameLen);
            if (PCSL_STRING_OK != pcsl_string_append_char(pDirEntry, sep)
             || PCSL_STRING_OK != pcsl_string_append_buf(pDirEntry, fileName, fileNameLen)) {
                javacall_dir_close(listHandle);
                pcsl_string_free(pSubDir);
                pcsl_string_free(pDirEntry);
                return;
            }

            // check if directory entry is a subdirectory
            GET_PCSL_STRING_DATA_AND_LENGTH(pDirEntry)
            if (PCSL_STRING_PARAMETER_ERROR(pDirEntry)) {
                finish = 1;
            } else {
                res = javacall_fileconnection_dir_exists(pDirEntry_data, pDirEntry_len);
            }
            RELEASE_PCSL_STRING_DATA_AND_LENGTH
            if (finish) {
                javacall_dir_close(listHandle);
                pcsl_string_free(pSubDir);
                pcsl_string_free(pDirEntry);
                return;
            }
            if (JAVACALL_OK == res) {
                // found subdirectory, open it for listing
                javacall_dir_close(listHandle);
                pcsl_string_free(pSubDir);
                tmp = pDirEntry;
                pDirEntry = pSubDir;
                pSubDir = tmp;
                GET_PCSL_STRING_DATA_AND_LENGTH(pSubDir)
                if (PCSL_STRING_PARAMETER_ERROR(pSubDir)) {
                    listHandle = NULL;
                } else {
                    listHandle = javacall_dir_open(pSubDir_data, pSubDir_len);
                }
                RELEASE_PCSL_STRING_DATA_AND_LENGTH
                if (NULL == listHandle) {
                    pcsl_string_free(pSubDir);
                    return;
                }
                nestLevel++;
            } else {
                // found regular file, simply remove it
                GET_PCSL_STRING_DATA_AND_LENGTH(pDirEntry)
                if (PCSL_STRING_PARAMETER_ERROR(pDirEntry)) {
                    res = JAVACALL_FAIL;
                } else {
                    // ensure that the file is not read-only
                    javacall_fileconnection_set_writable(pDirEntry_data, pDirEntry_len, JAVACALL_TRUE);
                    res = javacall_file_delete(pDirEntry_data, pDirEntry_len);
                }
                RELEASE_PCSL_STRING_DATA_AND_LENGTH
                pcsl_string_free(pDirEntry);
                if (JAVACALL_OK != res) {
                    javacall_dir_close(listHandle);
                    pcsl_string_free(pSubDir);
                    return;
                }
            }
            // iterate through the current directory
            fileName = javacall_dir_get_next(listHandle, &fileNameLen);
        }