Exemplo n.º 1
0
/**
 * Gets the classpath for the specified MIDlet suite id.
 *
 * Note that memory for the in/out parameter classPath is
 * allocated by the callee. The caller is responsible for
 * freeing it using pcsl_mem_free().
 *
 * @param suiteId   The suite id used to identify the MIDlet suite
 * @param storageId storage ID, INTERNAL_STORAGE_ID for the internal storage
 * @param classPath The in/out parameter that contains returned class path
 * @param extension Extension of the file (
 *
 * @return one of the error codes:
 * <pre>
 *     ALL_OK, OUT_OF_MEMORY
 * </pre>
 */
static MIDPError
get_class_path_impl(SuiteIdType suiteId,
                    jint storageId,
                    pcsl_string * classPath,
                    const pcsl_string * extension) {
    const pcsl_string* root = storage_get_root(storageId);
    pcsl_string path = PCSL_STRING_NULL;
    jint suiteIdLen = GET_SUITE_ID_LEN(suiteId);

    *classPath = PCSL_STRING_NULL;

    /* performance hint: predict buffer capacity */
    pcsl_string_predict_size(&path, pcsl_string_length(root)
                                    + suiteIdLen
                                    + pcsl_string_length(extension));
    if (PCSL_STRING_OK != pcsl_string_append(&path, root) ||
            PCSL_STRING_OK != pcsl_string_append(&path,
                midp_suiteid2pcsl_string(suiteId)) ||
            PCSL_STRING_OK != pcsl_string_append(&path, extension)) {
        pcsl_string_free(&path);
        return OUT_OF_MEMORY;
    }

    *classPath = path;

    return ALL_OK;
}
Exemplo n.º 2
0
void
printPcslStringWithMessageImpl(char* message, const pcsl_string* pstr) {
    char* tag;

    if ((pcsl_string_length(pstr) <= 0) && (!message)) {
        REPORT_INFO(LC_MIDPSTRING,
		    "printPcslStringWithMessage() No input");
        return;
    }

    if (message) {
        tag = message;
    } else {
        tag = "message = NULL:";
    }

    if (pcsl_string_length(pstr) > 0) {
        const char* msg = pcsl_string_get_utf8_data(pstr);
        if (msg) {
            REPORT_INFO2(LC_MIDPSTRING, "%s: %s", tag, msg);
            pcsl_string_release_utf8_data(msg, pstr);
        } else {
           REPORT_INFO1(LC_MIDPSTRING,
	        "%s: printPcslStringWithMessage can't convert pcsl_string to char*", tag);
        }
    } else {
        REPORT_INFO2(LC_MIDPSTRING, "%s: pcsl_string is %s", tag,
            0 == pcsl_string_length(pstr) ? "empty" : "null" );
    }
}
Exemplo n.º 3
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 the classpath for the specified MIDlet suite id.
 *
 * Note that memory for the in/out parameter classPath is
 * allocated by the callee. The caller is responsible for
 * freeing it using pcsl_mem_free().
 *
 * @param suiteId   The suite id used to identify the MIDlet suite
 * @param storageId storage ID, INTERNAL_STORAGE_ID for the internal storage
 * @param classPath The in/out parameter that contains returned class path
 * @param extension Extension of the file (
 *
 * @return one of the error codes:
 * <pre>
 *     ALL_OK, OUT_OF_MEMORY
 * </pre>
 */
static MIDPError
get_class_path_impl(ComponentType type,
                    SuiteIdType suiteId,
                    ComponentIdType componentId,
                    jint storageId,
                    pcsl_string * pClassPath,
                    const pcsl_string * pExtension) {
    const pcsl_string* root = storage_get_root(storageId);
    pcsl_string path = PCSL_STRING_NULL;
    jint suiteIdLen = GET_SUITE_ID_LEN(suiteId);
    jint componentIdLen = 0;

#if ENABLE_DYNAMIC_COMPONENTS
    if (type == COMPONENT_DYNAMIC) {
        componentIdLen = GET_COMPONENT_ID_LEN(componentId);
    }
#else
    (void)type;
    (void)componentId;
#endif

    *pClassPath = PCSL_STRING_NULL;

    /* performance hint: predict buffer capacity */
    pcsl_string_predict_size(&path, pcsl_string_length(root)
                                    + suiteIdLen + componentIdLen +
                                    + pcsl_string_length(pExtension));
    if (PCSL_STRING_OK != pcsl_string_append(&path, root) ||
            PCSL_STRING_OK != pcsl_string_append(&path,
                midp_suiteid2pcsl_string(suiteId))) {
        pcsl_string_free(&path);
        return OUT_OF_MEMORY;
    }

#if ENABLE_DYNAMIC_COMPONENTS
    if (type == COMPONENT_DYNAMIC) {
        if (PCSL_STRING_OK != pcsl_string_append(&path,
                midp_componentid2pcsl_string(componentId))) {
            pcsl_string_free(&path);
            return OUT_OF_MEMORY;
        }
    }
#endif

    if (PCSL_STRING_OK != pcsl_string_append(&path, pExtension)) {
        pcsl_string_free(&path);
        return OUT_OF_MEMORY;
    }

    *pClassPath = path;

    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;
}
QString pcsl_string2QString(const pcsl_string &pstring)
{
  /*
  * Example From the QT toolkit doc for QString.isNull()
  * QString a;          // a.unicode() == 0,  a.length() == 0
  * QString b = "";     // b.unicode() == "", b.length() == 0
  * a.isNull();         // TRUE, because a.unicode() == 0
  * a.isEmpty();        // TRUE, because a.length() == 0
  * b.isNull();         // FALSE, because b.unicode() != 0
  * b.isEmpty();        // TRUE, because b.length() == 0
  */
  QString qstring;
  if (pcsl_string_is_null(&pstring))
  {
    // we want isNull to be true
    qstring = QString::null;
  }
  else if (pcsl_string_length(&pstring) == 0)
  {
    // we want isEmpty to be true
    qstring = "";
  }
  else
  {
    const pcsl_string* const mmstring = &pstring;
    GET_PCSL_STRING_DATA_AND_LENGTH(mmstring)
    qstring.setUtf16((const ushort *)mmstring_data, mmstring_len);
    RELEASE_PCSL_STRING_DATA_AND_LENGTH
  }
  return qstring;
}
/**
 * Gets the storage root for a MIDlet suite by ID.
 * Free the data of the string returned with pcsl_string_free().
 *
 * @param suiteId suite ID
 * @param sRoot receives storage root (gets set to NULL in the case of an error)
 *
 * @return status: ALL_OK if success,
 * OUT_OF_MEMORY if out-of-memory
 */
MIDPError
get_suite_storage_root(SuiteIdType suiteId, pcsl_string* sRoot) {
    StorageIdType storageId;
    const pcsl_string* root;
    MIDPError status;

    *sRoot = PCSL_STRING_EMPTY;

    /* get an id of the storage where the suite is located */
    status = midp_suite_get_suite_storage(suiteId, &storageId);
    if (status != ALL_OK) {
        return status;
    }

    root = storage_get_root(storageId);

    pcsl_string_predict_size(sRoot,
        pcsl_string_length(root) + GET_SUITE_ID_LEN(suiteId));

    if (PCSL_STRING_OK == pcsl_string_append(sRoot, root) &&
            PCSL_STRING_OK == pcsl_string_append(sRoot,
                midp_suiteid2pcsl_string(suiteId))) {
        return ALL_OK;
    }

    pcsl_string_free(sRoot);
    *sRoot = PCSL_STRING_NULL;

    return OUT_OF_MEMORY;
}
Exemplo n.º 8
0
/**
 * Construct a bar that shows indicators.
 */
IndicatorBar::IndicatorBar(QWidget* parent) : QWidget(parent) {

    // Set fixed size
    setFixedSize(FULLWIDTH, 18);

    QString qiconPath;
    const pcsl_string * iconPath = storage_get_config_root(INTERNAL_STORAGE_ID);
    jint iconPath_len = pcsl_string_length(iconPath);
    const jchar * iconPath_data = pcsl_string_get_utf16_data(iconPath);

    if (NULL != iconPath_data) {
        qiconPath.setUnicodeCodes((const ushort *)iconPath_data, iconPath_len);
    } // else {
    // The qiconPath string will remain null.
    // If this happens, most likely, it may show as not found resources
    // }

    // Bar image is set as background , maintained by QWidget
    setBackgroundPixmap(QPixmap(qiconPath+"indicator_bar.png"));

    homeIcon    = new QPixmap(qiconPath+"indicator_home.png");
    trustedIcon = new QPixmap(qiconPath+"indicator_trusted.png");
    networkIcon = new QPixmap(qiconPath+"indicator_network.png");

    // Initialize paint flags for icons to false
    homeOn = KNI_FALSE;
    networkOn = KNI_FALSE;
    trustedOn = KNI_FALSE;

    // Remember this instance as the singleton
    singleton = this;

    pcsl_string_release_utf16_data(iconPath_data, iconPath);
}
Exemplo n.º 9
0
void
printPcslStringImpl(const pcsl_string* pstr) {
    if (pcsl_string_length(pstr) <= 0) {
       REPORT_INFO(LC_MIDPSTRING,
		    "printPcslString: Bad Length.");
        return;
    }
    if (pcsl_string_length(pstr) > 0) {
        const char* msg = pcsl_string_get_utf8_data(pstr);
        if (msg) {
	        REPORT_INFO1(LC_MIDPSTRING, "%s", msg);
            pcsl_string_release_utf8_data(msg, pstr);
        } else {
             REPORT_INFO(LC_MIDPSTRING,
	        "printPcslString: can't convert from pcsl_string to char");

        }
    }
}
Exemplo n.º 10
0
/**
 * Opens a file and fills the content of the file in the result_buf. <BR>
 * This function made memory allocation inside.
 *
 * @param filename   Path to the file.
 * @param result_buf Pointer to the buffer that will be filled by content of the file.
 * @return buffer file size in bytes
 */
long readJadFile(const pcsl_string * filename, char** result_buf) {
    int fd = 0;
    char* err = NULL;
    long bufsize = -1;
    int numread = 0;
    char* res = *result_buf;

    if (pcsl_string_length(filename) <= 0) {
        REPORT_INFO(LC_AMS, "readJadFile():No file name.");
        return BAD_PARAMS;
    }

    fd = storage_open(&err, filename, OPEN_READ);
    if(err != NULL) {
        REPORT_INFO1(LC_AMS, "readJadFile():Can't open jad file '%s'",err);
        storageFreeError(err);
        return NO_JAD_FILE;
    }

    bufsize = storageSizeOf(&err, fd);
    if((bufsize <= 0) || (err != NULL)) {
        REPORT_INFO1(LC_AMS,  "readJadFile():Problem getting file size: %s",
		     err );
        storageFreeError(err);
        return IO_ERROR;
    }

    res = (char*)midpMalloc(bufsize+1);
    if (res == NULL || (err != NULL)) {
        REPORT_INFO1(LC_AMS, "readJadFile():Can't allocate memory. %s", err);
        storageFreeError(err);
        return OUT_OF_MEMORY;
    }

    memset(res,0,(bufsize+1));

    REPORT_INFO2(LC_AMS, "fd = %d, bufsize = %ld\n", fd, bufsize);

    numread = storageRead(&err, fd, res, bufsize);
    if((numread <= 0) || (numread != bufsize) || (err)) {
        REPORT_INFO3(LC_AMS, "size = %ld, numread = %d, err = %s.",
               bufsize, numread, err);
        storageClose(&err, fd);
        return IO_ERROR;
    }

    REPORT_INFO2(LC_AMS, "size = %ld, numread = %d", bufsize, numread);

    storageClose(&err, fd);
    if(err != NULL) {
        REPORT_INFO1(LC_AMS, "Can't close jad file %s\n", err);
    }
    *result_buf = res;
    return bufsize;
} /* end of readJadFile */
Exemplo n.º 11
0
static char*
storage_get_last_file_error(char* pszFunction, const pcsl_string* filename_str) {
    char* temp;
    int charsLeft;
    int i;
    int j;
    int lim;

    temp = strerror(errno);
    if (temp == NULL) {
        return "Unspecified Error";
    }

    strcpy(errorBuffer, pszFunction);
    strcat(errorBuffer, ": ");
    charsLeft = MAX_ERROR_LEN - strlen(errorBuffer);

    strncat(errorBuffer, temp, charsLeft);
    charsLeft = MAX_ERROR_LEN - strlen(errorBuffer);

    strncat(errorBuffer, ", ", charsLeft);
    charsLeft = MAX_ERROR_LEN - strlen(errorBuffer);

    if (NULL_LEN == pcsl_string_length(filename_str)) {
        strncat(errorBuffer, "NULL", charsLeft);
    } else {
        const jchar* filename_data = pcsl_string_get_utf16_data(filename_str);
        int filename_len = pcsl_string_length(filename_str);
        lim = charsLeft < filename_len ? charsLeft : filename_len;
        for (i = strlen(errorBuffer), j = 0; j < lim; i++, j++) {
            errorBuffer[i] = (char)filename_data[j];
        }

        errorBuffer[i] = 0;
        pcsl_string_release_utf16_data(filename_data,filename_str);
    }

    return errorBuffer;
}
Exemplo n.º 12
0
/*
 * Prefixing the system directory for storage, APP_DIR, with midp_home.
 *
 * @param midp_home file system path to where MIDP is installed
 *
 * @return 0 for success, non-zero for out of memory
 */
int
storageInitialize(char *midp_home) {
    jchar fsep = storageGetFileSeparator();

    if (storageInitDone) {
        /* Already initialized */
        return 0;
    }

    if (PCSL_STRING_OK != pcsl_string_initialize()) {
        REPORT_ERROR(LC_CORE, "Error: cannot initialize string library.\n");
        return -1;
    }

    if(pcsl_file_init() < 0)  {
        REPORT_ERROR(LC_CORE, "Error: out of memory.\n");
        return -1;
    }

    /* set up a path to the internal storage */
    if (PCSL_STRING_OK != pcsl_string_from_chars(midp_home, &sRoot[0])) {
        REPORT_ERROR(LC_CORE, "Error: out of memory.\n");
        storageFinalize();
        return -1;
    }

    /* performance hint: predict buffer capacity */
    pcsl_string_predict_size(&sRoot[0], pcsl_string_length(&sRoot[0]) + 2
                                    + PCSL_STRING_LITERAL_LENGTH(APP_DIR));
    if (PCSL_STRING_OK != pcsl_string_append_char(&sRoot[0], fsep)
     || PCSL_STRING_OK != pcsl_string_append(&sRoot[0], &APP_DIR)
     || PCSL_STRING_OK != pcsl_string_append_char(&sRoot[0], fsep)) {
        REPORT_ERROR(LC_CORE, "Error: out of memory.\n");
        storageFinalize();
        return -1;
    }

    if (0 != initializeConfigRoot(midp_home)) {
        storageFinalize();
        return -1;
    }

    storageInitDone = 1;
    return 0;
}
Exemplo n.º 13
0
/**
 * Write pcsl_string to storage.
 * First write a jint with length, then the text in utf-16 encoding.
 *
 * @param ppszError  in the case of error, receives address of a string
 *                   describing the problem
 * @param handle     handle of the file to write to
 * @param str        string to be written
 */
void
storage_write_utf16_string(char** ppszError, int handle, const pcsl_string* str) {
  jint length;
  if(pcsl_string_is_null(str)) {
    length = -1;
  } else {
    length = pcsl_string_length(str);
  }
  storageWrite(ppszError, handle, (char*)&length, sizeof (length));

  /* are there data to write? */
  if (NULL == *ppszError && length > 0) {
    const jchar* data = pcsl_string_get_utf16_data(str);
    if(NULL == data) {
      *ppszError = (char *)OUT_OF_MEM_ERROR;
    } else {
      storageWrite(ppszError, handle, (char*)data, length * sizeof (jchar));
      pcsl_string_release_utf16_data(data, str);
    }
  }
}
Exemplo n.º 14
0
static int
initializeConfigRoot(char* midp_home) {
    jchar fileSep = storageGetFileSeparator();

    if (PCSL_STRING_OK != pcsl_string_from_chars(midp_home, &configRoot[0])) {
        return -1;
    }

    /* performance hint: predict buffer capacity */
    pcsl_string_predict_size(&configRoot[0],
                            pcsl_string_length(&configRoot[0])
                            + 2 + PCSL_STRING_LITERAL_LENGTH(CONFIG_SUBDIR));

    if (PCSL_STRING_OK != pcsl_string_append_char(&configRoot[0], fileSep)
     || PCSL_STRING_OK != pcsl_string_append(&configRoot[0], &CONFIG_SUBDIR)
     || PCSL_STRING_OK != pcsl_string_append_char(&configRoot[0], fileSep)) {
        pcsl_string_free(&configRoot[0]);
        return -1;
    }

    return 0;
}
Exemplo n.º 15
0
/**
 * Verifies access of caller for current content handler.
 * Reads access restrictions from a current record and
 * compares it with a passed caller_id.
 *
 * @param caller_id caller
 * @param current_position current position of the file
 * @param current_size [out] size of current record
 * @return 1 if access is permitted
 */
static int check_access(const pcsl_string* caller_id, long current_position, 
                                                            int* current_size) {
  int    access_len, access_ok;

  if ((*current_size = position_field(JSR211_CHR_ACCESSES)) <= 0) {
    return -1;
  }
  if (caller_id != NULL && pcsl_string_length(caller_id) > 0) {
    storageRelativePosition(&io_error_message, table_file, sizeof(int));
    storageRead(&io_error_message, table_file, (char*)&access_len, sizeof(int));
    if (!access_len) {
      access_ok = 1;
    }
    else {
      storageRelativePosition(&io_error_message, table_file, -2 * (long)sizeof(int));
      access_ok = compare_array(caller_id, JSR211_TRUE, find_first);
    }
  }
  else {
    access_ok = 1;
  }
  storagePosition(&io_error_message, table_file, current_position);
  return access_ok;
}
Exemplo n.º 16
0
extern "C" void
pcsl_string2QString(const pcsl_string &pstring, QString &qstring) {
    /*
     * Example From the QT toolkit doc for QString.isNull()
     * QString a;          // a.unicode() == 0,  a.length() == 0
     * QString b = "";     // b.unicode() == "", b.length() == 0
     * a.isNull();         // TRUE, because a.unicode() == 0
     * a.isEmpty();        // TRUE, because a.length() == 0
     * b.isNull();         // FALSE, because b.unicode() != 0
     * b.isEmpty();        // TRUE, because b.length() == 0
     */
    if (pcsl_string_is_null(&pstring)) {
        // we want isNull to be true
	qstring = (const char *)NULL;
    } else if (pcsl_string_length(&pstring) == 0) {
        // we want isEmpty to be true
        qstring = "";
    } else {
        const pcsl_string* const mmstring = &pstring;
        GET_PCSL_STRING_DATA_AND_LENGTH(mmstring)
        qstring.setUnicodeCodes((const ushort *)mmstring_data, mmstring_len);
        RELEASE_PCSL_STRING_DATA_AND_LENGTH
    }
}
Exemplo n.º 17
0
/**
 * Returns an array of the names of record stores owned by the
 * MIDlet suite.
 *
 * @param suiteId
 * @param ppNames pointer to pointer that will be filled in with names
 *
 * @return number of record store names or OUT_OF_MEM_LEN
 */
int
rmsdb_get_record_store_list(SuiteIdType suiteId, pcsl_string* *const ppNames) {
    int numberOfStores;
    pcsl_string root;
    pcsl_string* pStores;
    pcsl_string filename;
    pcsl_string ascii_name = PCSL_STRING_NULL_INITIALIZER;
    int i;
    void* handle = NULL;
    MIDPError status;
    int f_errc;
    pcsl_string_status s_errc;
    StorageIdType storageId;
    /* IMPL_NOTE: how can we get it statically? */
    const int dbext_len = pcsl_string_length(&DB_EXTENSION);

    *ppNames = NULL;

    /*
     * IMPL Note: here is assumed that the record store is located in the same
     * storage as the midlet suite. This may not be true.
     */
    status = midp_suite_get_suite_storage(suiteId, &storageId);
    if (status != ALL_OK) {
        return OUT_OF_MEM_LEN;
    }

    status = midp_suite_get_rms_filename(suiteId, storageId, -1,
                                         &PCSL_STRING_EMPTY, &root);
    if (status != ALL_OK) {
        return OUT_OF_MEM_LEN;
    }

    if (pcsl_string_is_null(&root)) {
        return 0;
    }

    numberOfStores = rmsdb_get_number_of_record_stores_int(&root);
    if (numberOfStores <= 0) {
        pcsl_string_free(&root);
        return numberOfStores;
    }
    pStores = alloc_pcsl_string_list(numberOfStores);
    if (pStores == NULL) {
        pcsl_string_free(&root);
        return OUT_OF_MEM_LEN;
    }

    handle = storage_open_file_iterator(&root);
    if (!handle) {
        pcsl_string_free(&root);
        return OUT_OF_MEM_LEN;
    }

    /* the main loop */
    for(i=0,f_errc=0,s_errc=0;;) {
        f_errc = storage_get_next_file_in_iterator(&root, handle, &filename);
        if (0 != f_errc) {
            f_errc = 0;
            break;
        }
        if (pcsl_string_ends_with(&filename, &DB_EXTENSION)) {
            s_errc =
              pcsl_string_substring(&filename,
                                    pcsl_string_length(&root),
                                    pcsl_string_length(&filename)
                                        - dbext_len,
                                    &ascii_name);
            pcsl_string_free(&filename);

            if (PCSL_STRING_OK != s_errc ) {
                break;
            }

            s_errc = escaped_ascii_to_unicode(&ascii_name, &pStores[i]);
            pcsl_string_free(&ascii_name);
            if (PCSL_STRING_OK != s_errc ) {
                break;
            }
            i++;
        }

        pcsl_string_free(&filename);
        /* IMPL_NOTE: do we need this one? isn't it useless? */
        if (i == numberOfStores) {
            break;
        }
    }

    pcsl_string_free(&root);
    storageCloseFileIterator(handle);

    if (f_errc || s_errc) {
        /* The loop stopped because we ran out of memory. */
        free_pcsl_string_list(pStores, i);
        return OUT_OF_MEM_LEN;
    }
    *ppNames = pStores;
    return numberOfStores;
}
Exemplo n.º 18
0
/**
 * Removes a software package given its suite ID
 * <p>
 * If the component is in use it must continue to be available
 * to the other components that are using it.  The resources it
 * consumes must not be released until it is not in use.
 *
 * @param suiteId ID of the suite
 *
 * @return ALL_OK if no errors,
 *         NOT_FOUND if the suite does not exist,
 *         SUITE_LOCKED if the suite is locked,
 *         BAD_PARAMS this suite cannot be removed
 */
MIDPError
midp_remove_suite(SuiteIdType suiteId) {
    pcsl_string filename;
    char* pszError;
    pcsl_string suiteRoot;
    MIDPError status;
    int operationStarted = 0;
    void* fileIteratorHandle = NULL;
    MidpProperties properties;
    pcsl_string* pproperty;
    MidletSuiteData* pData = NULL;
    pcsl_string filenameBase;

    lockStorageList *node = NULL;

    /* get the filename base from the suite id */
    status = build_suite_filename(suiteId, &PCSL_STRING_EMPTY, 
                                          &filenameBase);
    if (status != ALL_OK) {
        return status;
    }
    node = find_storage_lock(suiteId);
    if (node != NULL) {
        if (node->update != KNI_TRUE) {
            return SUITE_LOCKED;
        }
    }

    /*
     * This is a public API which can be called without the VM running
     * so we need automatically init anything needed, to make the
     * caller's code less complex.
     *
     * Initialization is performed in steps so that we do use any
     * extra resources such as the VM for the operation being performed.
     */
    if (midpInit(REMOVE_LEVEL) != 0) {
        return OUT_OF_MEMORY;
    }

    do {
        int rc; /* return code for rmsdb_... and storage_... */

        /* load _suites.dat */
        status = read_suites_data(&pszError);
        storageFreeError(pszError);
        if (status != ALL_OK) {
            break;
        }

        /* check that the suite exists and it is not a preloaded one */
        pData = get_suite_data(suiteId);

        if (pData == NULL) {
            status = NOT_FOUND;
            break;
        }

        /* notify the listeners that we starting to remove the suite */
        operationStarted = 1;
        suite_listeners_notify(SUITESTORE_LISTENER_TYPE_REMOVE,
            SUITESTORE_OPERATION_START, ALL_OK, pData);

        if (pData->type == COMPONENT_PREINSTALLED_SUITE) {
            status = BAD_PARAMS;
            break;
        }

        status = begin_transaction(TRANSACTION_REMOVE_SUITE, suiteId, NULL);
        if (status != ALL_OK) {
            return status;
        }

        /*
         * Remove the files
         * Call the native RMS method to remove the RMS data.
         * This function call is needed for portability
         */
        rc = rmsdb_remove_record_stores_for_suite(&filenameBase, suiteId);
        if (rc == KNI_FALSE) {
            status = SUITE_LOCKED;
            break;
        }

        pushdeletesuite(suiteId);

        /*
         * If there is a delete notify property, add the value to the delete
         * notify URL list.
         */
        properties = midp_get_suite_properties(suiteId);
        if (properties.numberOfProperties > 0) {
            pproperty = midp_find_property(&properties, &DELETE_NOTIFY_PROP);
            if (pcsl_string_length(pproperty) > 0) {
                midpAddDeleteNotification(suiteId, pproperty);
            }

            pproperty = midp_find_property(&properties, &INSTALL_NOTIFY_PROP);
            if (pcsl_string_length(pproperty) > 0) {
                /*
                 * Remove any pending install notifications since they are only
                 * retried when the suite is run.
                 */
                midpRemoveInstallNotification(suiteId);
            }

            midp_free_properties(&properties);
        }

        if ((status = get_suite_storage_root(suiteId, &suiteRoot)) != ALL_OK) {
            break;
        }

        fileIteratorHandle = storage_open_file_iterator(&suiteRoot);
        if (!fileIteratorHandle) {
            status = IO_ERROR;
            break;
        }

#if ENABLE_ICON_CACHE
        midp_remove_suite_icons(suiteId);
#endif        

        for (;;) {
            rc = storage_get_next_file_in_iterator(&suiteRoot,
                fileIteratorHandle, &filename);
            if (0 != rc) {
                break;
            }
            storage_delete_file(&pszError, &filename);
            pcsl_string_free(&filename);
            if (pszError != NULL) {
                storageFreeError(pszError);
                break;
            }
        }

    } while (0);

    pcsl_string_free(&suiteRoot);
    storageCloseFileIterator(fileIteratorHandle);

    (void)finish_transaction();

    /*
     * Notify the listeners the we've finished removing the suite.
     * It should be done before remove_from_suite_list_and_save()
     * call because it frees pData structure.
     */
    if (operationStarted) {
        suite_listeners_notify(SUITESTORE_LISTENER_TYPE_REMOVE,
            SUITESTORE_OPERATION_END, status, pData);
    }

    if (status == ALL_OK) {
        (void)remove_from_suite_list_and_save(suiteId);
    }

    remove_storage_lock(suiteId);

    return status;
}
Exemplo n.º 19
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 */
Exemplo n.º 20
0
void MidpMountedRoots::update(bool notify)
{
    DEBUG_PRINT("update");

#ifdef UNIX
    QValueList<QString> disks;
    QValueList<QString> paths;
    bool rebuild = false;
    int  count   = 0;

    // Read system mounts
    struct mntent *me;
    FILE *mntfp = setmntent("/etc/mtab", "r");
    if (mntfp)
    {
        while ((me = getmntent( mntfp )) != 0)
        {
            QString disk = me->mnt_fsname;
            if (isValidDisk(disk))
            {
                count++;

                disks.append(disk);

                QString path = QString(me->mnt_dir) + '/';
                paths.append(path);

                if (!isCachedDisk(disk))
                {
                    rebuild = true;
                }
            }
        }
        endmntent(mntfp);
    }

    // Add special roots for PIM, FC and Private
    const pcsl_string* storage = storage_get_root(INTERNAL_STORAGE_ID);
    if (pcsl_string_length(storage) >= 0)
    {
        const char* cstorage = (const char*)pcsl_string_get_utf8_data(storage);
        QString qstorage = cstorage;
        pcsl_string_release_utf8_data((const jbyte*)cstorage, storage);

        QString fc = qstorage + "storage/";
        QFile ffc(fc);
        // determine whether the path exists
        // Note: the path is created by the build system.
        if (ffc.exists())
        {
            count++;
            const QString name = "storage";

            disks.append(name);
            paths.append(fc);

            if (!isCachedDisk(name))
            {
                rebuild = true;
            }
        }

        QString pim = qstorage + "pimdb/";
        QFile fpim(pim);
        // determine whether the path exists
        // Note: the path is created by the build system.
        if (fpim.exists())
        {
            count++;
            const QString name = "pimdb";

            disks.append(name);
            paths.append(pim);

            if (!isCachedDisk(name))
            {
                rebuild = true;
            }
        }

        QString prv = qstorage + "private/";
        QFile fprv(prv);
        // determine whether the path exists
        // Note: the path is created by the build system.
        if (fprv.exists())
        {
            count++;
            const QString name = "private";

            disks.append(name);
            paths.append(prv);

            if (!isCachedDisk(name))
            {
                rebuild = true;
            }
        }
    }

    if (rebuild || count != (int)mRoots.count())
    {
        mRoots.clear();
        QStringList::ConstIterator it  = disks.begin();
        QStringList::ConstIterator pit = paths.begin();
        for (; it != disks.end(); ++it, ++pit)
        {
            QString disk = *it;
            QString path = *pit;
            QString root, local;
            if (getDiskInfo(disk, root, local))
            {
                MidpFileRoot* fs = new MidpFileRoot(disk, path, root, local);
                mRoots.append(fs);
            }
        }
        // Call the handler if required
        if (notify) {
            disksChanged();
        }
    }
#endif
}
Exemplo n.º 21
0
/**
 * Fills <code>JSR211_content_handler</code> structure with data from 
 * <code>ContentHandlerImpl</code> object.
 * <BR>Fields <code>ID, storageId</code> and <code>classname</code>
 * are mandatory. They must have not 0 length.
 *
 * @param o <code>ContentHandlerImpl</code> object
 * @param handler pointer on <code>JSR211_content_handler</code> structure
 * to be filled up
 * @return KNI_OK - if successfully get all fields, 
 * KNI_ERR or KNI_ENOMEM - otherwise
 */
static int fillHandlerData(jobject o, JSR211_content_handler* handler) {
    int ret;    // returned result code
    KNI_StartHandles(1);
    KNI_DeclareHandle(fldObj);   // field object

    do {
        // ID
        KNI_GetObjectField(o, chImplId, fldObj);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(fldObj, &(handler->id))) {
            ret = KNI_ENOMEM;
            break;
        }
        // check mandatory field
        if (pcsl_string_length(&(handler->id)) <= 0) {
            ret = KNI_ERR;
            break;
        }

        // suiteId
        handler->suite_id = KNI_GetIntField(o, chImplSuiteId);

        // classname
        KNI_GetObjectField(o, chImplClassname, fldObj);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(fldObj, &(handler->class_name))) {
            ret = KNI_ENOMEM;
            break;
        }

        // flag
        handler->flag = KNI_GetIntField(o, chImplregMethod);

        // types
        KNI_GetObjectField(o, chImplTypes, fldObj);
        handler->type_num = getStringArray(fldObj, &(handler->types));
        if (handler->type_num < 0) {
            ret = KNI_ENOMEM;
            break;
        }

        // suffixes        
        KNI_GetObjectField(o, chImplSuffixes, fldObj);
        handler->suff_num = getStringArray(fldObj, &(handler->suffixes));
        if (handler->suff_num < 0) {
            ret = KNI_ENOMEM;
            break;
        }

        // actions
        KNI_GetObjectField(o, chImplActions, fldObj);
        handler->act_num = getStringArray(fldObj, &(handler->actions));
        if (handler->act_num < 0) {
            ret = KNI_ENOMEM;
            break;
        }

        // action names
        if (handler->act_num > 0) {
            KNI_GetObjectField(o, chImplActionnames, fldObj);
            ret = fillActionMap(fldObj, handler);
            if (KNI_OK != ret) {
                break;
            }
        }

        // accesses
        KNI_GetObjectField(o, chImplAccesses, fldObj);
        handler->access_num = getStringArray(fldObj, &(handler->accesses));
        if (handler->access_num < 0) {
            ret = KNI_ENOMEM;
            break;
        }

        ret = KNI_OK;
    } while (0);

    KNI_EndHandles();
    return ret;
}
Exemplo n.º 22
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);
        }
Exemplo n.º 23
0
/**
 * Returns an array of the names of record stores owned by the
 * MIDlet suite.
 *
 * @param filenameBase filenameBase of the suite
 * @param ppNames pointer to pointer that will be filled in with names
 *
 * @return number of record store names or OUT_OF_MEM_LEN
 */
int
rmsdb_get_record_store_list(pcsl_string* filenameBase, pcsl_string* *const ppNames) {
    int numberOfStores;
    pcsl_string root;
    pcsl_string* pStores;
    pcsl_string filename;
    pcsl_string ascii_name = PCSL_STRING_NULL_INITIALIZER;
    int i;
    void* handle = NULL;
    MIDPError status;
    int f_errc;
    pcsl_string_status s_errc;
    /* IMPL_NOTE: how can we get it statically? */
    const int dbext_len = pcsl_string_length(&DB_EXTENSION);

    *ppNames = NULL;

    /*
     * IMPL_NOTE: for security reasons the record store is always
     * located in the internal storage.
     */
    status = buildSuiteFilename(filenameBase, &PCSL_STRING_EMPTY, -1, 
                                 &root);

    if (status != MIDP_ERROR_NONE) {
        return status;
    }

    if (pcsl_string_is_null(&root)) {
        return 0;
    }

    numberOfStores = rmsdb_get_number_of_record_stores_int(&root);
    if (numberOfStores <= 0) {
        pcsl_string_free(&root);
        return numberOfStores;
    }
    pStores = alloc_pcsl_string_list(numberOfStores);
    if (pStores == NULL) {
        pcsl_string_free(&root);
        return OUT_OF_MEM_LEN;
    }

    handle = storage_open_file_iterator(&root);
    if (!handle) {
        pcsl_string_free(&root);
        return OUT_OF_MEM_LEN;
    }

    /* the main loop */
    for (i=0,f_errc=0,s_errc=0;;) {
        f_errc = storage_get_next_file_in_iterator(&root, handle, &filename);
        if (0 != f_errc) {
            f_errc = 0;
            break;
        }
        if (pcsl_string_ends_with(&filename, &DB_EXTENSION)) {
            s_errc =
              pcsl_string_substring(&filename,
                                    pcsl_string_length(&root),
                                    pcsl_string_length(&filename)
                                        - dbext_len,
                                    &ascii_name);
            pcsl_string_free(&filename);

            if (PCSL_STRING_OK != s_errc ) {
                break;
            }

            s_errc = pcsl_esc_extract_attached(0, &ascii_name, &pStores[i]);
            pcsl_string_free(&ascii_name);
            if (PCSL_STRING_OK != s_errc ) {
                break;
            }
            i++;
        }

        pcsl_string_free(&filename);
        /* IMPL_NOTE: do we need this one? isn't it useless? */
        if (i == numberOfStores) {
            break;
        }
    }

    pcsl_string_free(&root);
    storageCloseFileIterator(handle);

    if (f_errc || s_errc) {
        /* The loop stopped because we ran out of memory. */
        free_pcsl_string_list(pStores, i);
        return OUT_OF_MEM_LEN;
    }
    *ppNames = pStores;
    return numberOfStores;
}
Exemplo n.º 24
0
int
find_midlet_class(SuiteIdType id, int midletNumber, pcsl_string* res) {
    MidpProperties properties;
    pcsl_string keySuffix = PCSL_STRING_NULL;
    pcsl_string key = PCSL_STRING_NULL;
    const pcsl_string* property = &PCSL_STRING_NULL;
    pcsl_string temp = PCSL_STRING_NULL;
    pcsl_string_status stat;
    int begin;
    int result = 0;
    *res = PCSL_STRING_NULL;

    properties = midp_get_suite_properties(id);
    if (OUT_OF_MEM_PROPERTY_STATUS(properties)) {
        return OUT_OF_MEM_LEN;
    }

    do {
        if (CORRUPTED_PROPERTY_STATUS(properties)) {
            midp_free_properties(&properties);
            REPORT_ERROR(LC_AMS, "Error : Suite is corrupted");
            fprintf(stderr, "Error : Suite is corrupted\n");
            result = NULL_LEN;
            break;
        }

        if (READ_ERROR_PROPERTY_STATUS(properties)) {
            midp_free_properties(&properties);
            REPORT_ERROR(LC_AMS, "Corrupt properties");
            fprintf(stderr, "Corrupt properties\n");
            result = NULL_LEN;
            break;
        }

        stat = pcsl_string_convert_from_jint(midletNumber, &keySuffix);
        if (PCSL_STRING_OK != stat) {
            if(PCSL_STRING_ENOMEM == stat) {
                result = OUT_OF_MEM_LEN;
            } else {
                result = NULL_LEN;
            }
            break;
        }

        stat = pcsl_string_cat(&KEY_PREFIX, &keySuffix, &key);
        pcsl_string_free(&keySuffix);
        if (PCSL_STRING_OK != stat) {
            result = OUT_OF_MEM_LEN;
            break;
        }

        property = midp_find_property(&properties, &key);
        if (pcsl_string_length(property) <= 0) {
            /* property not found */
            result = NULL_LEN;
            break;
        }

        /* The class is the last item in the set. */
        begin = pcsl_string_last_index_of(property, (jchar)',');
        if (begin < 0 || begin >= pcsl_string_length(property)) {
            result = NULL_LEN;
            break;
        }

        begin++;
        stat = pcsl_string_substring(property, begin, pcsl_string_length(property), &temp);
        if (PCSL_STRING_OK != stat) {
            result = OUT_OF_MEM_LEN;
            break;
        }
        if (pcsl_string_length(&temp) <= 0) {
            pcsl_string_free(&temp);
            result = NULL_LEN;
            break;
        }
        stat = pcsl_string_trim(&temp, res);
        pcsl_string_free(&temp);
        if (PCSL_STRING_OK != stat) {
            result = OUT_OF_MEM_LEN;
            break;
        }
    } while (0);

    midp_free_properties(&properties);
    return result;
}
Exemplo n.º 25
0
/**
 * Moves a software package with given suite ID to the specified storage.
 *
 * @param suiteId suite ID for the installed package
 * @param storageId new storage ID
 *
 * @return SUITE_LOCKED if the
 * suite is locked, NOT_FOUND if the suite cannot be found or
 * invalid storage ID specified, BAD_PARAMS if attempt is made
 * to move suite to the external storage, GENERAL_ERROR if
 * VERIFY_ONCE is not enabled and if MONET is enabled
 */
MIDPError
midp_change_suite_storage(SuiteIdType suiteId, StorageIdType newStorageId) {

#ifndef VERIFY_ONCE
    (void)suiteId;
    (void)newStorageId;
    return GENERAL_ERROR;
#else

   /*
    * if VERIFY_ONCE is enabled then MONET is disabled
    * so we don't have to check ENABLE_MONET.
    */

    {
        pcsl_string suiteRoot;
        MidletSuiteData* pData = NULL;
        int status;
        void* fileIteratorHandle = NULL;
        lockStorageList *node = NULL;

        if ((UNUSED_STORAGE_ID == newStorageId) ||
            (newStorageId >= MAX_STORAGE_NUM)) {
            return BAD_PARAMS;
        }

        /*
         * IMPL_NOTE: for security reasons we allow to move suite
         * only to the internal storage.
         */
        if (newStorageId != INTERNAL_STORAGE_ID) {
            return BAD_PARAMS;
        }

        node = find_storage_lock(suiteId);
        if (node != NULL) {
            if (node->update != KNI_TRUE) {
                return SUITE_LOCKED;
            }
        }

        /*
         * This is a public API which can be called without the VM running
         * so we need automatically init anything needed, to make the
         * caller's code less complex.
         *
         * Initialization is performed in steps so that we do use any
         * extra resources such as the VM for the operation being performed.
         */
        if (midpInit(REMOVE_LEVEL) != 0) {
            remove_storage_lock(suiteId);
            return OUT_OF_MEMORY;
        }

        /* check that the suite exists and it is not a preloaded one */
        pData = get_suite_data(suiteId);

        if (pData == NULL) {
            remove_storage_lock(suiteId);
            return NOT_FOUND;
        }

        if (pData->storageId == newStorageId) {
            remove_storage_lock(suiteId);
            return BAD_PARAMS;
        }

        if (pData->type == COMPONENT_PREINSTALLED_SUITE) {
            remove_storage_lock(suiteId);
            return BAD_PARAMS;
        }

        do {
            jsize oldRootLength;
            jsize newRootLength;
            const pcsl_string* newRoot;
            const pcsl_string* oldRoot;
            char* pszError = NULL;
            pcsl_string filePath;
            pcsl_string newFilePath;


            status = begin_transaction(TRANSACTION_CHANGE_STORAGE, suiteId, NULL);
            if (status != ALL_OK) {
                break;
            }

            if ((status = get_suite_storage_root(suiteId, &suiteRoot)) != ALL_OK) {
                break;
            }

            fileIteratorHandle = storage_open_file_iterator(&suiteRoot);
            if (!fileIteratorHandle) {
                status = IO_ERROR;
                break;
            }

            newRoot = storage_get_root(newStorageId);
            oldRoot = storage_get_root(pData->storageId);
            newRootLength = pcsl_string_length(newRoot);
            oldRootLength = pcsl_string_length(oldRoot);

            status = ALL_OK;

            if ((status = midp_suite_get_class_path(suiteId,
                pData->storageId, KNI_FALSE, &filePath)) != ALL_OK) {
                break;
            }

            if ((status = midp_suite_get_class_path(suiteId,
                newStorageId, KNI_FALSE, &newFilePath)) != ALL_OK) {
                break;
            }

            storage_rename_file(&pszError, &filePath, &newFilePath);
            if (pszError != NULL) {
                status = IO_ERROR;
                storageFreeError(pszError);
                pcsl_string_free(&filePath);
                pcsl_string_free(&newFilePath);
                break;
            }

            pcsl_string_free(&filePath);
            pcsl_string_free(&newFilePath);

#if ENABLE_IMAGE_CACHE
            moveImageCache(suiteId, pData->storageId, newStorageId);
#endif

            pData->storageId = newStorageId;

            status = write_suites_data(&pszError);
            storageFreeError(pszError);

        } while (0);

        pcsl_string_free(&suiteRoot);
        storageCloseFileIterator(fileIteratorHandle);

        if (status != ALL_OK) {
            (void)rollback_transaction();
        } else {
            (void)finish_transaction();
        }

        remove_storage_lock(suiteId);

        return status;
    }

#endif /* VERIFY_ONCE */
}
Exemplo n.º 26
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;
}
Exemplo n.º 27
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 */