Esempio n. 1
0
int
rmsdb_record_store_open(char** ppszError, SuiteIdType suiteId,
                        const pcsl_string * name_str, int extension) {
    StorageIdType storageId;
    MIDPError status;
    pcsl_string filename_str;
    int handle;
    lockFileList* searchedNodePtr = NULL;
    int addflag = 0;

    *ppszError = NULL;

    if ((extension == DB_EXTENSION_INDEX) && (lockFileListPtr != NULL)) {
        /* linked list is already initialised for a db file */
        searchedNodePtr = findLockById(suiteId, name_str);
        if (searchedNodePtr != NULL) {
            /* File is already opened by another isolate, return an error */
            *ppszError = (char *)FILE_LOCK_ERROR;
            return -2;
        } else { /* remember to add a node */
            addflag = 1;
        }
    }

    /*
     * 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 0;
    }

    if (MIDP_ERROR_NONE != rmsdb_get_unique_id_path(suiteId, storageId,
            name_str, extension, &filename_str)) {
        return -1;
    }
    handle = midp_file_cache_open(ppszError, storageId,
                                  &filename_str, OPEN_READ_WRITE);

    pcsl_string_free(&filename_str);
    if (*ppszError != NULL) {
        return -1;
    }

    /*
     * Add the node only if it's a db file AND lockFileListPtr is NULL or
     * addflag is 1
     */
    if ((extension == DB_EXTENSION_INDEX)&&
        ( (lockFileListPtr == NULL) || (addflag == 1)) ) {
            if (recordStoreCreateLock(suiteId, name_str, handle) != 0) {
                return -1;
            }
    }

    return handle;
}
Esempio n. 2
0
int
rmsdb_record_store_open(char** ppszError, pcsl_string* filenameBase,
                        const pcsl_string * name_str, int extension) {
    pcsl_string filename_str;
    int handle;
#if ENABLE_RECORDSTORE_FILE_LOCK
    lockFileList* searchedNodePtr = NULL;
#endif

    *ppszError = NULL;

#if ENABLE_RECORDSTORE_FILE_LOCK
    if (extension == DB_EXTENSION_INDEX) {
        searchedNodePtr = rmsdb_find_file_lock_by_id(filenameBase, name_str);
        if (searchedNodePtr != NULL) {
            /* File is already opened by another isolate, return an error */
            *ppszError = (char *)FILE_LOCK_ERROR;
            return -2;
        }
    }
#endif

    /*
     * IMPL_NOTE: for security reasons the record store is always
     * located in the internal storage.
     */
    if (MIDP_ERROR_NONE != rmsdb_get_unique_id_path(filenameBase, 
                INTERNAL_STORAGE_ID, name_str, extension, &filename_str)) {
        return -1;
    }
    handle = midp_file_cache_open(ppszError, INTERNAL_STORAGE_ID,
                                  &filename_str, OPEN_READ_WRITE);

    pcsl_string_free(&filename_str);
    if (*ppszError != NULL) {
        return -1;
    }

#if ENABLE_RECORDSTORE_FILE_LOCK
    if (extension == DB_EXTENSION_INDEX) {
        if (rmsdb_create_file_lock(filenameBase, name_str, handle) != 0) {
            return -1;
        }
    }
#endif    

    return handle;
}