/** * Writes the contents of the given buffer into the given file. * * Note that if the length of the input buffer is zero or less, * the file will be truncated. * * @param ppszError pointer to character string pointer to accept an error * @param fileName file to write * @param inBuffer buffer with data that will be stored * @param inBufferLen length of the inBuffer * * @return status code (ALL_OK if there was no errors) */ MIDPError write_file(char** ppszError, const pcsl_string* fileName, char* inBuffer, long inBufferLen) { int handle, status = ALL_OK; char* pszTemp; *ppszError = NULL; /* open the file */ handle = storage_open(ppszError, fileName, OPEN_WRITE); if (*ppszError != NULL) { return IO_ERROR; } /* write the whole buffer */ if (inBufferLen > 0) { storageWrite(ppszError, handle, inBuffer, inBufferLen); } else { storageTruncate(ppszError, handle, 0); } if (*ppszError != NULL) { status = IO_ERROR; } /* close the file */ storageClose(&pszTemp, handle); storageFreeError(pszTemp); return status; }
/** * Initializes a property set with the contents of a property file. * * @param props The property set to initialize * @param name The name of the property file to load. It is relative * to the <tt>configRoot</tt> path. * @param configRoot The fully qualified pathname to the root * configuration directory. * * @return <tt>0</tt> for success, otherwise <tt>-1</tt> */ static int initProps(Property** props, const pcsl_string * name, const pcsl_string * configRoot) { pcsl_string pathname; int fd = -1 ; char * errStr; /* Property file can be relative or at midp_home variable */ pcsl_string_cat(configRoot, name, &pathname); fd = storage_open(&errStr, &pathname, OPEN_READ); pcsl_string_free(&pathname); if (errStr != NULL) { REPORT_WARN2(LC_CORE, "Warning: could not open config file(%s): %s\n", pathname, errStr); storageFreeError(errStr); return 0; } /* Read through the file one line at a time */ if (parseConfig(fd, props) != 0) { return -1; } /* Close the storage handle */ storageClose(&errStr, fd); return 0; }
static gboolean ril_radio_settings_get_config(struct ril_radio_settings *rsd) { gboolean needsconfig = FALSE; gboolean value = FALSE; /* Hmm... One file shared by all modems... Why?? */ GKeyFile *keyfile = storage_open(NULL, RIL_STORE); char **alreadyset = g_key_file_get_groups(keyfile, NULL); if (alreadyset[0]) value = g_key_file_get_boolean( keyfile, alreadyset[0], LTE_FLAG, NULL); else if (rsd->ratmode == PREF_NET_TYPE_GSM_WCDMA_AUTO) value = TRUE; if (!value && rsd->ratmode == PREF_NET_TYPE_LTE_GSM_WCDMA) { g_key_file_set_boolean(keyfile, LTE_FLAG, LTE_FLAG, TRUE); needsconfig = TRUE; } else if (value && rsd->ratmode == PREF_NET_TYPE_GSM_WCDMA_AUTO) { g_key_file_set_boolean(keyfile, LTE_FLAG, LTE_FLAG, FALSE); needsconfig = TRUE; } g_strfreev(alreadyset); storage_close(NULL, RIL_STORE, keyfile, TRUE); DBG("needsconfig %d, rat mode %d", needsconfig, rsd->ratmode); return needsconfig; }
/** * Opens file that keeps device and service classes. * @return handle for the file, <code>-1</code> if opening failed. */ static int openCodFile() { char *error; int handle = -1; pcsl_string name = PCSL_STRING_EMPTY; int i; if (PCSL_STRING_OK == pcsl_string_append(&name, storage_get_root(INTERNAL_STORAGE_ID))) { for (i = 0; i < BT_ADDRESS_SIZE * 2; i++) { char c = (emul_data.local_addr[i / 2] >> ((i % 2) * 4)) & 0xf; if (c <= 9) { c += '0'; } else { c += 'a'; } if (PCSL_STRING_OK != pcsl_string_append_char(&name, c)) { break; } } if (i == BT_ADDRESS_SIZE * 2) { handle = storage_open(&error, &name, OPEN_READ_WRITE); storageFreeError(error); } } pcsl_string_free(&name); return handle; }
/** * Writes the settings of a MIDlet suite to persistent storage. * <pre> * The format of the properties file will be: * * push interrupt setting as an jbyte * length of a permissions as an int * array of permissions jbytes * push options as jint * </pre> * * @param ppszError pointer to character string pointer to accept an error * @param suiteId ID of the suite * @param enabled enabled setting * @param pushInterrupt pointer to a push interruptSetting * @param pushOptions user options for push interrupts * @param pPermissions pointer a pointer to accept a permissions array * @param numberOfPermissions length of pPermissions * * @return error code (ALL_OK if successful) */ MIDPError write_settings(char** ppszError, SuiteIdType suiteId, jboolean enabled, jbyte pushInterrupt, jint pushOptions, jbyte* pPermissions, int numberOfPermissions) { pcsl_string filename; int handle; char* pszTemp; MIDPError status; *ppszError = NULL; status = build_suite_filename(suiteId, &SETTINGS_FILENAME, &filename); if (status != ALL_OK) { return status; } handle = storage_open(ppszError, &filename, OPEN_READ_WRITE_TRUNCATE); pcsl_string_free(&filename); if (*ppszError != NULL) { return IO_ERROR; } storageWrite(ppszError, handle, (char*)&enabled, sizeof (jboolean)); do { if (*ppszError != NULL) { break; } storageWrite(ppszError, handle, (char*)&pushInterrupt, sizeof (jbyte)); if (*ppszError != NULL) { break; } storageWrite(ppszError, handle, (char*)&numberOfPermissions, sizeof (int)); if (*ppszError != NULL) { break; } storageWrite(ppszError, handle, (char*)pPermissions, numberOfPermissions * sizeof (jbyte)); storageWrite(ppszError, handle, (char*)&pushOptions, sizeof (jint)); if (*ppszError != NULL) { break; } } while (0); if (*ppszError != NULL) { status = IO_ERROR; } storageClose(&pszTemp, handle); storageFreeError(pszTemp); return ALL_OK; }
/** * Reads the given file into the given buffer. * File contents is read as one piece. * * @param ppszError pointer to character string pointer to accept an error * @param pFileName file to read * @param outBuffer buffer where the file contents should be stored * @param outBufferLen length of the outBuffer * * @return status code (ALL_OK if there was no errors) */ MIDPError read_file(char** ppszError, const pcsl_string* pFileName, char** outBuffer, long* outBufferLen) { int handle, status = ALL_OK; long fileSize, len; char* pszTemp; char* buffer = NULL; *ppszError = NULL; *outBuffer = NULL; *outBufferLen = 0; /* open the file */ handle = storage_open(ppszError, pFileName, OPEN_READ); if (*ppszError != NULL) { if (!storage_file_exists(pFileName)) { return NOT_FOUND; } return IO_ERROR; } do { /* get the size of file */ fileSize = storageSizeOf(ppszError, handle); if (*ppszError != NULL) { status = IO_ERROR; break; } if (fileSize > 0) { /* allocate a buffer to store the file contents */ buffer = (char*)pcsl_mem_malloc(fileSize); if (buffer == NULL) { status = OUT_OF_MEMORY; break; } /* read the whole file */ len = storageRead(ppszError, handle, buffer, fileSize); if (*ppszError != NULL || len != fileSize) { pcsl_mem_free(buffer); status = IO_ERROR; } } } while (0); /* close the file */ storageClose(&pszTemp, handle); storageFreeError(pszTemp); if (status == ALL_OK) { *outBuffer = buffer; *outBufferLen = fileSize; } return (MIDPError)status; }
static gboolean ril_get_net_config(struct radio_data *rsd) { GKeyFile *keyfile; GError *err = NULL; char *path = RIL_CONFIG; char **alreadyset = NULL; gboolean needsconfig = FALSE; gboolean value = FALSE; rsd->ratmode = PREF_NET_TYPE_GSM_WCDMA_AUTO; /* * First we need to check should the LTE be on * or not */ keyfile = g_key_file_new(); g_key_file_set_list_separator(keyfile, ','); if (g_key_file_load_from_file(keyfile, path, 0, &err)) { if (g_key_file_has_group(keyfile, LTE_FLAG)) rsd->ratmode = PREF_NET_TYPE_LTE_GSM_WCDMA; } else { g_error_free(err); needsconfig = TRUE; } g_key_file_free(keyfile); /* Then we need to check if it already set */ keyfile = storage_open(NULL, RIL_STORE); alreadyset = g_key_file_get_groups(keyfile, NULL); if (alreadyset[0]) value = g_key_file_get_boolean( keyfile, alreadyset[0], LTE_FLAG, NULL); else if (rsd->ratmode == PREF_NET_TYPE_GSM_WCDMA_AUTO) value = TRUE; if (!value && rsd->ratmode == PREF_NET_TYPE_LTE_GSM_WCDMA) { g_key_file_set_boolean(keyfile, LTE_FLAG, LTE_FLAG, TRUE); needsconfig = TRUE; } else if (value && rsd->ratmode == PREF_NET_TYPE_GSM_WCDMA_AUTO) { g_key_file_set_boolean(keyfile, LTE_FLAG, LTE_FLAG, FALSE); needsconfig = TRUE; } g_strfreev(alreadyset); storage_close(NULL, RIL_STORE, keyfile, TRUE); return needsconfig; }
static void sms_load_settings(struct ofono_sms *sms, const char *imsi) { GError *error; sms->settings = storage_open(imsi, SETTINGS_STORE); if (sms->settings == NULL) return; sms->imsi = g_strdup(imsi); error = NULL; sms->ref = g_key_file_get_integer(sms->settings, SETTINGS_GROUP, "NextReference", &error); if (error || sms->ref > 65536) { g_error_free(error); sms->ref = 1; g_key_file_set_integer(sms->settings, SETTINGS_GROUP, "NextReference", sms->ref); } error = NULL; sms->use_delivery_reports = g_key_file_get_boolean(sms->settings, SETTINGS_GROUP, "UseDeliveryReports", &error); if (error) { g_error_free(error); g_key_file_set_boolean(sms->settings, SETTINGS_GROUP, "UseDeliveryReports", sms->use_delivery_reports); } error = NULL; sms->bearer = g_key_file_get_integer(sms->settings, SETTINGS_GROUP, "Bearer", &error); if (error || sms_bearer_to_string(sms->bearer) == NULL) { g_error_free(error); sms->bearer = 3; /* Default to CS then PS */ g_key_file_set_integer(sms->settings, SETTINGS_GROUP, "Bearer", sms->bearer); } error = NULL; sms->alphabet = g_key_file_get_integer(sms->settings, SETTINGS_GROUP, "Alphabet", &error); if (error || sms_alphabet_to_string(sms->alphabet) == NULL) { g_error_free(error); sms->alphabet = SMS_ALPHABET_DEFAULT; g_key_file_set_integer(sms->settings, SETTINGS_GROUP, "Alphabet", sms->alphabet); } }
/** * 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 */
/** * Reads named secure resource of the suite with specified suiteId * from secure persistent storage. * * Note that when porting memory for the in/out parameter * returnValue MUST be allocated using pcsl_mem_malloc(). * The caller is responsible for freeing it. * * @param suiteId The suite id used to identify the MIDlet suite * @param resourceName The name of secure resource to read from storage * @param returnValue The in/out parameter that will return the * value part of the requested secure resource * (NULL is a valid return value) * @param valueSize The length of the secure resource value * * @return one of the error codes: * <pre> * ALL_OK, OUT_OF_MEMORY, NOT_FOUND, * SUITE_CORRUPTED_ERROR, BAD_PARAMS * </pre> */ MIDPError midp_suite_read_secure_resource(SuiteIdType suiteId, const pcsl_string* resourceName, jbyte **returnValue, jint *valueSize) { pcsl_string filename = PCSL_STRING_NULL; char *pszError = NULL; MIDPError errorCode; int bytesRead; int handle; *returnValue = NULL; *valueSize = 0; errorCode = get_secure_resource_file(suiteId, resourceName, &filename); if (errorCode != ALL_OK) { pcsl_string_free(&filename); return errorCode; } handle = storage_open(&pszError, &filename, OPEN_READ); pcsl_string_free(&filename); if (pszError != NULL) { storageFreeError(pszError); return SUITE_CORRUPTED_ERROR; } do { bytesRead = storageRead(&pszError, handle, (char*)valueSize, sizeof (int)); if (bytesRead != sizeof (int) || *valueSize == 0) break; *returnValue = (jbyte*)pcsl_mem_malloc(*valueSize * sizeof (jbyte)); if (*returnValue == NULL) { errorCode = OUT_OF_MEMORY; break; } bytesRead = storageRead(&pszError, handle, (char*)(*returnValue), *valueSize * sizeof (jbyte)); if (pszError != NULL || bytesRead != *valueSize) { errorCode = SUITE_CORRUPTED_ERROR; pcsl_mem_free(*returnValue); *returnValue = NULL; break; } } while (0); storageClose(&pszError, handle); storageFreeError(pszError); return errorCode; }
static void push_save() { char *error; bt_push_t *push = g_registry; pcsl_string full_name = PCSL_STRING_NULL; int storage; pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID), &BT_PUSH_FILENAME, &full_name); storage = storage_open(&error, &full_name, OPEN_READ_WRITE_TRUNCATE); pcsl_string_free(&full_name); if (error != NULL) { REPORT_ERROR1(LC_PUSH, "Error opening `BtPush' file: %s", error); storageFreeError(error); return; } storageWrite(&error, storage, (char *)&g_count, sizeof(g_count)); while (push != NULL && error == NULL) { bt_push_t *next = push->next; storageWrite(&error, storage, (char *)&push->port, sizeof(bt_port_t)); if (error != NULL) { break; } storageWrite(&error, storage, (char *)&push->params, sizeof(bt_params_t)); if (error != NULL) { break; } storageWrite(&error, storage, (char *)&push->record.classes, sizeof(push->record.classes)); if (error != NULL) { break; } storageWrite(&error, storage, (char *)&push->record.size, sizeof(push->record.size)); if (error != NULL) { break; } storageWrite(&error, storage, (char *)push->record.data, push->record.size); storageWrite(&error, storage, (char *)&push->record.id, sizeof(push->record.id)); if (error != NULL) { break; } push = next; } if (error != NULL) { REPORT_ERROR1(LC_PUSH, "Error writing `BtPush' file: %s", error); storageFreeError(error); } storageClose(&error, storage); storageFreeError(error); }
/** * Writes the contents of the given buffer into the given file. * * Note that if the length of the input buffer is zero or less, * the file will be truncated. * * @param ppszError pointer to character string pointer to accept an error * @param pFileName file to write * @param inBuffer buffer with data that will be stored * @param inBufferLen length of the inBuffer * * @return status code (ALL_OK if there was no errors) */ MIDPError write_file(char** ppszError, const pcsl_string* pFileName, char* inBuffer, long inBufferLen) { int handle, status = ALL_OK; char* pszTemp; pcsl_string tmpFileName; pcsl_string_status rc; *ppszError = NULL; /* get the name of the temporary file */ rc = pcsl_string_cat(pFileName, &TMP_FILE_EXTENSION, &tmpFileName); if (rc != PCSL_STRING_OK) { return OUT_OF_MEMORY; } /* open the file */ handle = storage_open(ppszError, &tmpFileName, OPEN_READ_WRITE_TRUNCATE); if (*ppszError != NULL) { pcsl_string_free(&tmpFileName); return IO_ERROR; } /* write the whole buffer */ if (inBufferLen > 0) { storageWrite(ppszError, handle, inBuffer, inBufferLen); } if (*ppszError != NULL) { status = IO_ERROR; } /* close the file */ storageClose(&pszTemp, handle); storageFreeError(pszTemp); if (status == ALL_OK) { /* rename the temporary file */ storage_rename_file(ppszError, &tmpFileName, pFileName); if (*ppszError != NULL) { status = IO_ERROR; storage_delete_file(&pszTemp, &tmpFileName); storageFreeError(pszTemp); } } else { storage_delete_file(&pszTemp, &tmpFileName); storageFreeError(pszTemp); } pcsl_string_free(&tmpFileName); return (MIDPError)status; }
/** * Copies a file. * * @param srcName source file * @param destName destination file * * @return 0 for success */ static int copyFile(const pcsl_string * srcName, const pcsl_string * destName) { char* pszError = NULL; char* pszDummy = NULL; int src; int dest; char buffer[1024]; long bytesRead; src = storage_open(&pszError, srcName, OPEN_READ); if (pszError == NULL) { dest = storage_open(&pszError, destName, OPEN_READ_WRITE_TRUNCATE); if (pszError == NULL) { bytesRead = storageRead(&pszError, src, buffer, sizeof (buffer)); while (pszError == NULL && bytesRead > 0) { storageWrite(&pszError, dest, buffer, bytesRead); if (pszError == NULL) { bytesRead = storageRead(&pszError, src, buffer, sizeof (buffer)); } } storageClose(&pszDummy, dest); storageFreeError(pszDummy); pszDummy = NULL; } storageClose(&pszDummy, src); storageFreeError(pszDummy); } if (pszError != NULL) { REPORT_ERROR1(LC_AMS, "Error while copying file: %s", pszError); storageFreeError(pszError); return -1; } return 0; }
/** * Opens registry file * * @param write write access flag * @return operation result */ static jsr211_result open_table_file(int write) { pcsl_string fileName = PCSL_STRING_NULL_INITIALIZER; int io_mode = OPEN_READ | (write ? OPEN_WRITE : 0); if (PCSL_STRING_OK != pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID), &JSR211_TABLE_NAME, &fileName)) { return JSR211_FAILED; } table_file = storage_open(&io_error_message, &fileName, io_mode); pcsl_string_free(&fileName); return io_error_message? JSR211_FAILED: JSR211_OK; }
static ssize_t storage_read(const bt_addr_le_t *addr, uint16_t key, void *data, size_t length) { fs_file_t file; ssize_t ret; ret = storage_open(addr, key, STORAGE_READ, &file); if (ret) { return ret; } ret = fs_read(&file, data, length); fs_close(&file); return ret; }
/** * Writes named secure resource of the suite with specified suiteId * to secure persistent storage. * * @param suiteId The suite id used to identify the MIDlet suite * @param resourceName The name of secure resource to read from storage * @param value The value part of the secure resource to be stored * @param valueSize The length of the secure resource value * * @return one of the error codes: * <pre> * ALL_OK, OUT_OF_MEMORY, NOT_FOUND, * SUITE_CORRUPTED_ERROR, BAD_PARAMS * </pre> */ MIDPError midp_suite_write_secure_resource(SuiteIdType suiteId, const pcsl_string* resourceName, jbyte *value, jint valueSize) { pcsl_string filename = PCSL_STRING_NULL; char *pszError = NULL; MIDPError errorCode; int handle; errorCode = get_secure_resource_file(suiteId, resourceName, &filename); if (errorCode != ALL_OK) { pcsl_string_free(&filename); return errorCode; } handle = storage_open(&pszError, &filename, OPEN_READ_WRITE_TRUNCATE); pcsl_string_free(&filename); if (pszError != NULL) { storageFreeError(pszError); return SUITE_CORRUPTED_ERROR; } do { storageWrite(&pszError, handle, (char*)&valueSize, sizeof (int)); if (pszError != NULL) break; storageWrite(&pszError, handle, (char*)value, valueSize * sizeof (jbyte)); if (pszError != NULL) break; } while (0); if (pszError != NULL) { errorCode = SUITE_CORRUPTED_ERROR; storageFreeError(pszError); } storageClose(&pszError, handle); storageFreeError(pszError); return errorCode; }
void* midpOpenJar(int* pError, const pcsl_string * name) { MidpJarInfo* pJarInfo; char* pszError; *pError = 0; pJarInfo = (MidpJarInfo*)midpMalloc(sizeof (MidpJarInfo)); if (pJarInfo == NULL) { *pError = MIDP_JAR_OUT_OF_MEM_ERROR; return NULL; } memset(pJarInfo, 0, sizeof (MidpJarInfo)); pJarInfo->fileObj.state = (void*)storage_open(&pszError, name, OPEN_READ); if (pszError != NULL) { midpFree(pJarInfo); *pError = MIDP_JAR_IO_ERROR; return NULL; } pJarInfo->fileObj.size = sizeOfFile; pJarInfo->fileObj.read = readChars; pJarInfo->fileObj.seek = seekChars; pJarInfo->fileObj.readChar = readChar; pJarInfo->heapManObj.alloc = allocFunction; pJarInfo->heapManObj.free = freeFunction; pJarInfo->heapManObj.addrFromHandle = addrFromHandleFunction; pJarInfo->jarInfo = getJarInfo(&pJarInfo->fileObj); if (pJarInfo->jarInfo.status != 0) { midpFree(pJarInfo); *pError = MIDP_JAR_CORRUPT_ERROR; return NULL; } return pJarInfo; }
static gboolean ril_roaming_allowed() { GError *error; error = NULL; GKeyFile *settings; struct ofono_sim *sim; sim = get_sim(); const char *imsi = ofono_sim_get_imsi(sim); settings = storage_open(imsi, "gprs"); gboolean roaming_allowed = g_key_file_get_boolean(settings, "Settings", "RoamingAllowed", &error); if (error) g_error_free(error); storage_close(imsi, "gprs", settings, FALSE); return roaming_allowed; }
/** * Loads the properties of a MIDlet suite from persistent storage. * * @param suiteId ID of the suite * @param pJadProps [out] pointer to a structure containing an array of strings, * in a pair pattern of key and value; NULL may be passed if it is not required * to read JAD properties * @param pJarProps [out] pointer to a structure containing an array of strings, * in a pair pattern of key and value; NULL may be passed if it is not required * to read JAR properties * * @return error code (ALL_OK for success) */ MIDPError load_install_properties(SuiteIdType suiteId, MidpProperties* pJadProps, MidpProperties* pJarProps) { pcsl_string filename; char* pszError = NULL; int handle, i, n; int numberOfProps; MIDPError status; status = get_property_file(suiteId, KNI_TRUE, &filename); if (status != ALL_OK) { return status; } handle = storage_open(&pszError, &filename, OPEN_READ); pcsl_string_free(&filename); if (pszError != NULL) { storageFreeError(pszError); return IO_ERROR; } status = ALL_OK; /* Read JAD, then JAR properties. */ for (n = 0; n < 2; n++) { MidpProperties *pProps = n ? pJarProps : pJadProps; if (!pProps) { continue; } storageRead(&pszError, handle, (char*)&numberOfProps, sizeof (numberOfProps)); if (pszError != NULL) { break; } pProps->pStringArr = alloc_pcsl_string_list(numberOfProps << 1); for (i = 0; i < numberOfProps << 1; i++) { storage_read_utf16_string(&pszError, handle, &pProps->pStringArr[i]); if (pszError != NULL) { break; } } if (pszError != NULL) { break; } pProps->numberOfProperties = numberOfProps; } if (pszError != NULL) { status = IO_ERROR; storageFreeError(pszError); } storageClose(&pszError, handle); storageFreeError(pszError); if (status != ALL_OK) { if (pJadProps) { free_pcsl_string_list(pJadProps->pStringArr, pJadProps->numberOfProperties << 1); } if (pJarProps) { free_pcsl_string_list(pJarProps->pStringArr, pJarProps->numberOfProperties << 1); } } return status; }
javacall_result bt_push_startup() { int i; char *error; pcsl_string full_name = PCSL_STRING_NULL; int storage; REPORT_INFO(LC_PUSH, "Bluetooth PushRegistry is now starting."); javacall_bt_sddb_initialize(); pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID), &BT_PUSH_FILENAME, &full_name); if (!storage_file_exists(&full_name)) { pcsl_string_free(&full_name); return JAVACALL_OK; } storage = storage_open(&error, &full_name, OPEN_READ); pcsl_string_free(&full_name); if (error != NULL) { REPORT_ERROR1(LC_PUSH, "Failed to open `BtPush' file: %s", error); storageFreeError(error); return JAVACALL_FAIL; } storageRead(&error, storage, (char *)&g_count, sizeof(g_count)); for (i = 0; error == NULL && i < g_count; i++) { bt_push_t *push = (bt_push_t *)pcsl_mem_malloc(sizeof(bt_push_t)); if (push == NULL) { REPORT_ERROR(LC_PUSH, "Failed to allocate memory."); storageClose(&error, storage); storageFreeError(error); return JAVACALL_FAIL; } storageRead(&error, storage, (char *)&push->port, sizeof(push->port)); if (error != NULL) { pcsl_mem_free(push); break; } storageRead(&error, storage, (char *)&push->params, sizeof(push->params)); if (error != NULL) { pcsl_mem_free(push); break; } storageRead(&error, storage, (char *)&push->record.classes, sizeof(push->record.classes)); if (error != NULL) { pcsl_mem_free(push); break; } storageRead(&error, storage, (char *)&push->record.size, sizeof(push->record.size)); if (error != NULL) { pcsl_mem_free(push); break; } push->record.data = pcsl_mem_malloc(push->record.size); if (push->record.data == NULL) { pcsl_mem_free(push); REPORT_ERROR(LC_PUSH, "Failed to allocate memory."); storageClose(&error, storage); storageFreeError(error); return JAVACALL_FAIL; } storageRead(&error, storage, (char *)push->record.data, push->record.size); if (error != NULL) { pcsl_mem_free(push->record.data); pcsl_mem_free(push); break; } storageRead(&error, storage, (char *)&push->record.id, sizeof(push->record.id)); if (error != NULL) { pcsl_mem_free(push); break; } push->server = BT_INVALID_HANDLE; push->client = NULL; push->next = g_registry; g_registry = push; } if (error != NULL) { REPORT_ERROR1(LC_PUSH, "Error reading `BtPush' file: %s", error); storageFreeError(error); storageClose(&error, storage); storageFreeError(error); return JAVACALL_FAIL; } REPORT_INFO1(LC_PUSH, "%d record(s) read.", g_count); storageClose(&error, storage); storageFreeError(error); if (g_count > 0) { /* Attempt to enable Bluetooth radio, if it is not already on. */ javacall_bool enabled; javacall_bt_stack_initialize(); if (javacall_bt_stack_is_enabled(&enabled) == JAVACALL_OK && enabled == JAVACALL_FALSE) { javacall_bt_stack_enable(); } } return JAVACALL_OK; }
/** * Gets the settings of a MIDlet suite from persistent storage. * <pre> * The format of the properties file will be: * * push interrupt setting as an jbyte * length of a permissions as an int * array of permissions jbytes * push options as jint * </pre> * * @param ppszError pointer to character string pointer to accept an error * @param suiteId ID of the suite * @param pEnabled pointer to an enabled setting * @param pPushInterrupt pointer to a push interruptSetting * @param pPushOptions user options for push interrupts * @param ppPermissions pointer a pointer to accept a permissions array * @param pNumberOfPermissions pointer to an int * * @return error code (ALL_OK if successful) */ MIDPError read_settings(char** ppszError, SuiteIdType suiteId, jboolean* pEnabled, jbyte* pPushInterrupt, jint* pPushOptions, jbyte** ppPermissions, int* pNumberOfPermissions) { pcsl_string filename; int handle; int bytesRead; char* pszTemp; MIDPError status; *ppszError = NULL; *ppPermissions = NULL; *pNumberOfPermissions = 0; status = build_suite_filename(suiteId, &SETTINGS_FILENAME, &filename); if (status != ALL_OK) { return status; } handle = storage_open(ppszError, &filename, OPEN_READ); pcsl_string_free(&filename); if (*ppszError != NULL) { return IO_ERROR; } bytesRead = storageRead(ppszError, handle, (char*)pEnabled, sizeof (jboolean)); do { if (*ppszError != NULL) { status = IO_ERROR; break; } bytesRead = storageRead(ppszError, handle, (char*)pPushInterrupt, sizeof (jbyte)); if (*ppszError != NULL) { status = IO_ERROR; break; } bytesRead = storageRead(ppszError, handle, (char*)pNumberOfPermissions, sizeof (int)); if (bytesRead != sizeof (int) || *pNumberOfPermissions == 0) { status = IO_ERROR; break; } *ppPermissions = (jbyte*)pcsl_mem_malloc( *pNumberOfPermissions * sizeof (jbyte)); if (*ppPermissions == NULL) { status = OUT_OF_MEMORY; break; } bytesRead = storageRead(ppszError, handle, (char*)(*ppPermissions), *pNumberOfPermissions * sizeof (jbyte)); if (bytesRead != *pNumberOfPermissions) { *pNumberOfPermissions = 0; pcsl_mem_free(*ppPermissions); status = SUITE_CORRUPTED_ERROR; break; } /* Old versions of the file may not have options. */ status = ALL_OK; *pPushOptions = 0; bytesRead = storageRead(ppszError, handle, (char*)pPushOptions, sizeof (jint)); if (*ppszError != NULL) { storageFreeError(*ppszError); *ppszError = NULL; break; } } while (0); storageClose(&pszTemp, handle); storageFreeError(pszTemp); return status; }
/** * Retrieves the list of strings in a file. * The file has the number of strings at the front, each string * is a length and the jchars. * * @param ppszError pointer to character string pointer to accept an error * @param pFilename name of the file of strings * @param paList pointer to an array of pcsl_strings, free with * free_pcsl_string_list * @param pStringNum number of strings if successful (can be 0) * * @return error code (ALL_OK if successful) */ static MIDPError get_string_list(char** ppszError, const pcsl_string* pFilename, pcsl_string** paList, int* pStringNum) { char* pszTemp; int i = 0; int handle; int numberOfStrings = 0; pcsl_string* pStrings = NULL; MIDPError status = ALL_OK; *ppszError = NULL; *paList = NULL; *pStringNum = 0; handle = storage_open(ppszError, pFilename, OPEN_READ); if (*ppszError != NULL) { return IO_ERROR; } do { storageRead(ppszError, handle, (char*)&numberOfStrings, sizeof (numberOfStrings)); if (*ppszError != NULL) { status = IO_ERROR; break; } if (numberOfStrings == 0) { break; } pStrings = alloc_pcsl_string_list(numberOfStrings); if (pStrings == NULL) { status = OUT_OF_MEMORY; break; } for (i = 0; i < numberOfStrings; i++) { pStrings[i] = PCSL_STRING_NULL; } for (i = 0; i < numberOfStrings; i++) { storage_read_utf16_string(ppszError, handle, &pStrings[i]); if (*ppszError != NULL) { status = IO_ERROR; break; } } if (i != numberOfStrings) { status = SUITE_CORRUPTED_ERROR; break; } } while (0); storageClose(&pszTemp, handle); storageFreeError(pszTemp); if (status == ALL_OK) { *paList = pStrings; *pStringNum = numberOfStrings; } else if (pStrings != NULL) { free_pcsl_string_list(pStrings, i); } return status; }
static gboolean ril_get_net_config(struct radio_data *rsd) { GKeyFile *keyfile; GError *err = NULL; char *config_path = RIL_CONFIG_DIR; char **alreadyset = NULL; gboolean needsconfig = FALSE; gboolean value = FALSE; gboolean found = FALSE; rsd->ratmode = PREF_NET_TYPE_GSM_WCDMA_AUTO; GDir *config_dir; const gchar *config_file; gsize length; gchar **codes = NULL; int i; /* * First we need to check should the LTE be on * or not */ keyfile = g_key_file_new(); g_key_file_set_list_separator(keyfile, ','); config_dir = g_dir_open(config_path, 0, NULL); while ((config_file = g_dir_read_name(config_dir)) != NULL) { char *path = g_strconcat(RIL_CONFIG_DIR "/", config_file, NULL); DBG("Rilconfig handling %s", path); gboolean ok = g_key_file_load_from_file(keyfile, path, 0, &err); g_free(path); if (!ok) { g_error_free(err); DBG("Rilconfig file skipped"); continue; } if (g_key_file_has_group(keyfile, LTE_FLAG)) found = TRUE; else if (g_key_file_has_group(keyfile, MCC_LIST)) { codes = g_key_file_get_string_list(keyfile, MCC_LIST, MCC_KEY, &length, NULL); if (codes) { for (i = 0; codes[i]; i++) { if (g_str_equal(codes[i], ofono_sim_get_mcc(get_sim())) == TRUE) { found = TRUE; break; } } g_strfreev(codes); } } if (found) { rsd->ratmode = PREF_NET_TYPE_LTE_GSM_WCDMA; break; } } g_key_file_free(keyfile); g_dir_close(config_dir); /* Then we need to check if it already set */ keyfile = storage_open(NULL, RIL_STORE); alreadyset = g_key_file_get_groups(keyfile, NULL); if (alreadyset[0]) value = g_key_file_get_boolean( keyfile, alreadyset[0], LTE_FLAG, NULL); else if (rsd->ratmode == PREF_NET_TYPE_GSM_WCDMA_AUTO) value = TRUE; if (!value && rsd->ratmode == PREF_NET_TYPE_LTE_GSM_WCDMA) { g_key_file_set_boolean(keyfile, LTE_FLAG, LTE_FLAG, TRUE); needsconfig = TRUE; } else if (value && rsd->ratmode == PREF_NET_TYPE_GSM_WCDMA_AUTO) { g_key_file_set_boolean(keyfile, LTE_FLAG, LTE_FLAG, FALSE); needsconfig = TRUE; } g_strfreev(alreadyset); storage_close(NULL, RIL_STORE, keyfile, TRUE); return needsconfig; }
KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(com_sun_midp_chameleon_skins_resources_LoadedSkinData_beginReadingSkinFile) { const unsigned char* skin_description = lfj_get_skin_description(); if (skin_description != NULL) { gsSkinFileDataStart = gsSkinFileDataPos = (unsigned char*)skin_description; gsSkinFileDataEnd = gsSkinFileDataStart + lfj_get_skin_description_size(); } else { char* errorStr = NULL; int fileHandle = -1; int fileSize; int bytesRead; jfieldID fid; KNI_StartHandles(2); KNI_DeclareHandle(classHandle); KNI_GetClassPointer(classHandle); fid = KNI_GetStaticFieldID(classHandle, "STRING_ENCODING_USASCII", "B"); STRING_ENCODING_USASCII = (unsigned char) KNI_GetStaticByteField(classHandle, fid); fid = KNI_GetStaticFieldID(classHandle, "STRING_ENCODING_UTF8", "B"); STRING_ENCODING_UTF8 = (unsigned char) KNI_GetStaticByteField(classHandle, fid); GET_PARAMETER_AS_PCSL_STRING(1, fileName); do { /* * Open skin file */ fileHandle = storage_open(&errorStr, &fileName, OPEN_READ); if (errorStr != NULL) { KNI_ThrowNew(midpIOException, errorStr); storageFreeError(errorStr); break; } /* * Obtain file size */ fileSize = storageSizeOf(&errorStr, fileHandle); if (errorStr != NULL) { KNI_ThrowNew(midpIOException, errorStr); storageFreeError(errorStr); break; } /* * Read whole file into heap memory */ gsSkinFileDataStart = (unsigned char*)midpMalloc(fileSize); if (gsSkinFileDataStart == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); break; } bytesRead = storageRead(&errorStr, fileHandle, (char*)gsSkinFileDataStart, fileSize); if (errorStr != NULL) { KNI_ThrowNew(midpIOException, errorStr); storageFreeError(errorStr); midpFree(gsSkinFileDataStart); gsSkinFileDataStart = NULL; break; } if (bytesRead != fileSize) { KNI_ThrowNew(midpIOException, "Failed to read whole file"); midpFree(gsSkinFileDataStart); gsSkinFileDataStart = NULL; break; } gsSkinFileDataPos = gsSkinFileDataStart; gsSkinFileDataEnd = gsSkinFileDataStart + fileSize; } while (0); RELEASE_PCSL_STRING_PARAMETER; /* * Close skin file */ if (fileHandle != -1) { storageClose(&errorStr, fileHandle); } KNI_EndHandles(); } KNI_ReturnVoid(); }