/** * Utility for serialized handler appending. */ static void appendSerializedCH(const JSR211_CH* ch, jchar* buf) { jsize n; n = pcsl_string_utf16_length(&(ch->id)); if (n > 0) { pcsl_string_convert_to_utf16(&(ch->id), buf, n+1, &n); buf += n; } *buf++ = '\n'; n = pcsl_string_utf16_length(&(ch->class_name)); if (n > 0) { pcsl_string_convert_to_utf16(&(ch->class_name), buf, n+1, &n); buf += n; } *buf++ = '\n'; *buf++ = (jchar)(ch->suite_id >> 16); *buf++ = (jchar)ch->suite_id; *buf = (jchar)ch->flag; }
/** * Starts a new transaction of the given type. * * @param transactionType type of the new transaction * @param suiteId ID of the suite, may be UNUSED_SUITE_ID * @param pFilename name of the midlet suite's file, may be NULL * * @return ALL_OK if no errors, * IO_ERROR if I/O error */ MIDPError begin_transaction(MIDPTransactionType transactionType, SuiteIdType suiteId, const pcsl_string *pFilename) { pcsl_string_status rc; pcsl_string transDataFile; char *pszError = NULL; MIDPError status = ALL_OK; char pBuffer[MAX_FILENAME_LENGTH + sizeof(int) /* file name length */ + sizeof(suiteId) + sizeof(transactionType)]; char *p = pBuffer; int len = sizeof(suiteId) + sizeof(transactionType); *(MIDPTransactionType*)p = transactionType; p += sizeof(MIDPTransactionType); *(SuiteIdType*)p = suiteId; p += sizeof(SuiteIdType); if (pFilename != NULL) { int strLen; rc = pcsl_string_convert_to_utf16(pFilename, (jchar*)(p + sizeof(int)), MAX_FILENAME_LENGTH / sizeof(jchar), &strLen); if (rc != PCSL_STRING_OK) { return OUT_OF_MEMORY; } *(int*)p = strLen; len += strLen; } /* get a full path to the transaction data file */ rc = pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID), &TRANSACTION_DATA_FILENAME, &transDataFile); if (rc != PCSL_STRING_OK) { return OUT_OF_MEMORY; } status = write_file(&pszError, &transDataFile, pBuffer, len); storageFreeError(pszError); pcsl_string_free(&transDataFile); g_transactionStarted = 1; return status; }
/** * Fills output result structure with string array. * @param strArray string array. * @param length array length. * @param result output result structure. * @return operation status. */ jsr211_result jsr211_fillStringArray(const pcsl_string* strArr, int length, /*OUT*/ JSR211_RESULT_STRARRAY* result) { jsize cap, len, siz; // buffer capacity, used length, requested size jchar* buf; if (strArr == NULL || length <= 0) { result->len = 0; result->buf = NULL; } else { _INIT_BUFFER_(buf, cap) for (*buf = (jchar)length, len = 1; length--; len += siz, strArr++) { siz = pcsl_string_utf16_length(strArr); _ASSURE_BUFFER_(buf, cap, len + siz + 2) buf[len++] = siz; pcsl_string_convert_to_utf16(strArr, buf + len, siz+1, &siz); } result->len = len; result->buf = buf; } return JSR211_OK; }
/** * Writes the file with information about the installed suites. * * Note that if the value of the global variable g_numberOfSuites * is zero, the file will be truncated. * * @param ppszError pointer to character string pointer to accept an error * * @return status code: ALL_OK if no errors, * OUT_OF_MEMORY if malloc failed * IO_ERROR if an IO_ERROR */ MIDPError write_suites_data(char** ppszError) { MIDPError status = ALL_OK; long bufferLen, pos; char* buffer = NULL; pcsl_string_status rc; pcsl_string suitesDataFile; MidletSuiteData* pData; *ppszError = NULL; /* get a full path to the _suites.dat */ rc = pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID), &SUITE_DATA_FILENAME, &suitesDataFile); if (rc != PCSL_STRING_OK) { return OUT_OF_MEMORY; } if (!g_numberOfSuites) { /* truncate the file with the list of the installed suites */ status = write_file(ppszError, &suitesDataFile, buffer, 0); pcsl_string_free(&suitesDataFile); return status; } /* allocate a buffer where the information about all suites will be saved */ bufferLen = g_numberOfSuites * (sizeof(MidletSuiteData) + MAX_VAR_SUITE_DATA_LEN); /* space to store the number of suites */ bufferLen += sizeof(int); buffer = (char*)pcsl_mem_malloc(bufferLen); if (buffer == NULL) { pcsl_string_free(&suitesDataFile); return OUT_OF_MEMORY; } /* assemble the information about all suites into the allocated buffer */ pos = 0; pData = g_pSuitesData; *(int*)&buffer[pos] = g_numberOfSuites; ADJUST_POS_IN_BUF(pos, bufferLen, sizeof(int)); while (pData != NULL) { memcpy((char*)&buffer[pos], (char*)pData, MIDLET_SUITE_DATA_SIZE); ADJUST_POS_IN_BUF(pos, bufferLen, MIDLET_SUITE_DATA_SIZE); /* setup pJarHash */ if (pData->jarHashLen > 0) { memcpy((char*)&buffer[pos], pData->varSuiteData.pJarHash, pData->jarHashLen); ADJUST_POS_IN_BUF(pos, bufferLen, pData->jarHashLen); } /* setup string fields */ { int i, convertedLen; jint strLen; pcsl_string* pStrings[] = { &pData->varSuiteData.midletClassName, &pData->varSuiteData.displayName, &pData->varSuiteData.iconName, &pData->varSuiteData.suiteVendor, &pData->varSuiteData.suiteName, &pData->varSuiteData.pathToJar, &pData->varSuiteData.pathToSettings }; status = ALL_OK; for (i = 0; i < (int) (sizeof(pStrings) / sizeof(pStrings[0])); i++) { strLen = pcsl_string_utf16_length(pStrings[i]); /* * We have to guarantee 4 - bytes alignment to use this: * *(jint*)&buffer[pos] = strLen; * on RISC CPUs. */ pos = SUITESTORE_ALIGN_4(pos); *(jint*)&buffer[pos] = strLen; ADJUST_POS_IN_BUF(pos, bufferLen, sizeof(jint)); /* assert(bufferLen > 0); */ if (strLen > 0) { rc = pcsl_string_convert_to_utf16(pStrings[i], (jchar*)&buffer[pos], bufferLen / sizeof(jchar), &convertedLen); if (rc != PCSL_STRING_OK) { status = OUT_OF_MEMORY; break; } ADJUST_POS_IN_BUF(pos, bufferLen, convertedLen * sizeof(jchar)); } } } if (status != ALL_OK) { break; } pData = pData->nextEntry; } if (status == ALL_OK) { /* write the buffer into the file */ status = write_file(ppszError, &suitesDataFile, buffer, pos); } /* cleanup */ pcsl_mem_free(buffer); pcsl_string_free(&suitesDataFile); return status; }