suitestore_midletsuitestorage_kni.c

来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,872 行 · 第 1/4 页

C
1,872
字号
        exists = KNI_TRUE;    } else if (status == SUITE_CORRUPTED_ERROR) {        remove_from_suite_list_and_save(suiteId);        KNI_ThrowNew(midletsuiteCorrupted, NULL);    } else if (status == OUT_OF_MEMORY) {        KNI_ThrowNew(midpOutOfMemoryError, NULL);    }    KNI_ReturnBoolean(exists);}/** * Fill in the authPath String array in an installInfo java object. * * @param src MidpInstallInfo struct with the auth path array * @param dst java InstallInfo object to fill * @param dstClass InstallInfo class object */static void fillAuthPath(KNIDECLARGS MidpInstallInfo src, jobject dst, jclass dstClass) {    int i;    jfieldID authPathFieldId;    int error = 0;    KNI_StartHandles(2);    KNI_DeclareHandle(stringObj);    KNI_DeclareHandle(authPathObj);    do {        if (src.authPathLen <= 0) {            break;        }        SNI_NewArray(SNI_STRING_ARRAY, src.authPathLen, authPathObj);        if (KNI_IsNullHandle(authPathObj)) {            break;        }        for (i = 0; i < src.authPathLen; i++) {            const pcsl_string* const apath = &src.authPath_as[i];            GET_PCSL_STRING_DATA_AND_LENGTH(apath)            if (PCSL_STRING_PARAMETER_ERROR(apath)) {                error = 1;            } else {                KNI_NewString(apath_data, (jsize)apath_len, stringObj);            }            RELEASE_PCSL_STRING_DATA_AND_LENGTH            if (error) {                break;            }            KNI_SetObjectArrayElement(authPathObj, (jint)i, stringObj);        }        if (error) {            KNI_ThrowNew(midpOutOfMemoryError, NULL);        } else {            authPathFieldId = midp_get_field_id(KNIPASSARGS dstClass, "authPath",                                                "[Ljava/lang/String;");            KNI_SetObjectField(dst, authPathFieldId, authPathObj);        }    } while (0);    KNI_EndHandles();}/** * Native method String createSuiteID(String, String) of * com.sun.midp.midletsuite.MIDletSuiteStorage. * <p> * Returns a unique identifier of MIDlet suite. * Constructed from the combination * of the values of the <code>MIDlet-Name</code> and * <code>MIDlet-Vendor</code> attributes. * * @param vendor name of the vendor that created the application, as *          given in a JAD file * @param name name of the suite, as given in a JAD file * * @return the platform-specific storage name of the application *          given by vendorName and appName */KNIEXPORT KNI_RETURNTYPE_INTKNIDECL(com_sun_midp_midletsuite_MIDletSuiteStorage_createSuiteID) {    SuiteIdType suiteId = UNUSED_SUITE_ID;    MIDPError rc;    rc = midp_create_suite_id(&suiteId);    if (rc != ALL_OK) {        if (rc == OUT_OF_MEMORY) {            KNI_ThrowNew(midpOutOfMemoryError, NULL);        } else {            KNI_ThrowNew(midpIOException, NULL);        }    }    KNI_ReturnInt(suiteId);}/** * Native method int getStorageUsed(String) of * com.sun.midp.midletsuite.MIDletSuiteStorage. * <p> * Gets the amount of storage on the device that this suite is using. * This includes the JAD, JAR, management data, and RMS. * * @param suiteId  ID of the suite * * @return number of bytes of storage the suite is using */KNIEXPORT KNI_RETURNTYPE_INTKNIDECL(com_sun_midp_midletsuite_MIDletSuiteStorage_getStorageUsed) {    int used = 0;    /* assert(sizeof(SuiteIdType) == sizeof(jint)); */    SuiteIdType suiteId = KNI_GetParameterAsInt(1);    used = midp_get_suite_storage_size(suiteId);    if (used < 0) {        KNI_ThrowNew(midpOutOfMemoryError, NULL);    }    KNI_ReturnInt((jint)used);}/** * Native method void getSuiteList(int[]) for class * com.sun.midp.midletsuite.MIDletSuiteStorage. * <p> * Get the list installed of MIDlet suite IDs. * * @param suites empty array of integerss to fill with suite IDs */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(com_sun_midp_midletsuite_MIDletSuiteStorage_getSuiteList) {    int i;    int numberOfStrings;    int numberOfSuites = 0;    MIDPError status;    SuiteIdType* pSuites = NULL;    KNI_StartHandles(1);    KNI_DeclareHandle(suites);    KNI_GetParameterAsObject(1, suites);    numberOfStrings = (int)KNI_GetArrayLength(suites);    do {        if (numberOfStrings <= 0) {            break;        }        status = midp_get_suite_ids(&pSuites, &numberOfSuites);        if (status != ALL_OK) {            KNI_ThrowNew(midpOutOfMemoryError, NULL);            break;        }        if (numberOfSuites == 0) {            break;        }        if (numberOfStrings > numberOfSuites) {            numberOfStrings = numberOfSuites;        }        for (i = 0; i < numberOfStrings; i++) {            KNI_SetIntArrayElement(suites, (jint)i, pSuites[i]);        }    } while (0);    midp_free_suite_ids(pSuites, numberOfSuites);    KNI_EndHandles();    KNI_ReturnVoid();}/** * Native method int getNumberOfSuites() for class * com.sun.midp.midletsuite.MIDletSuiteStorage. * <p> * Get the number of installed of MIDlet suites. * * @return the number of installed suites or -1 in case of error */KNIEXPORT KNI_RETURNTYPE_INTKNIDECL(com_sun_midp_midletsuite_MIDletSuiteStorage_getNumberOfSuites) {    int numberOfSuites;    MIDPError status = midp_get_number_of_suites(&numberOfSuites);    if (status != ALL_OK) {        numberOfSuites = status;    }    KNI_ReturnInt(numberOfSuites);}#if VERIFY_ONCE/** * Read suite hash value and fill the verifyHash field of * the com.sun.midp.midletsuite.InstallInfo object with it * * @param suiteId  ID of the suite * @param installInfoObj object to fill * @return MIDP_ERROR_NONE if successful, *      OUT_OF_MEMORY if out of memory, *      IO_ERROR if an IO error occurred * * @throws OutOfMemoryError if not enough memory to read/fill information */static MIDPError fillVerifyHash(SuiteIdType suiteId, jobject installInfoObj) {    int len;    jbyte* data = NULL;    jfieldID fieldID;    MIDPError status;    KNI_StartHandles(2);    KNI_DeclareHandle(clazz);    KNI_DeclareHandle(field);    status = readVerifyHash(suiteId, &data, &len);    /**     * Don't throw IOException on IO_ERROR status since a suite could     * be successfully installed even with not passed classes verification.     * In this case verify hash value can be unavailable, and suite must     * be started each time with classes verification.     */    if (status == OUT_OF_MEMORY) {        KNI_ThrowNew(midpOutOfMemoryError, NULL);    } else if (status == ALL_OK) {        SNI_NewArray(SNI_BYTE_ARRAY, len, field);        if (KNI_IsNullHandle(field)) {            KNI_ThrowNew(midpOutOfMemoryError, NULL);        } else {            KNI_GetObjectClass(installInfoObj, clazz);            fieldID = midp_get_field_id(KNIPASSARGS clazz, "verifyHash", "[B");            KNI_SetObjectField(installInfoObj, fieldID, field);            KNI_SetRawArrayRegion(field, 0, len, data);        }        midpFree(data);    }    KNI_EndHandles();    return status;}#endif /* VERIFY_ONCE *//** * native void load() throws IOException; * * Populates this InstallInfo instance from persistent store. * * @throws IOException if the information cannot be read */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(com_sun_midp_midletsuite_InstallInfo_load) {    MidpInstallInfo installInfo;    char* pszError;    jfieldID idFid;    SuiteIdType suiteId;    KNI_StartHandles(3);    KNI_DeclareHandle(thisObj);    KNI_DeclareHandle(clazz);    KNI_DeclareHandle(temp);    KNI_GetThisPointer(thisObj);    KNI_GetObjectClass(thisObj, clazz);    idFid = midp_get_field_id(KNIPASSARGS clazz, "id", "I");    suiteId = KNI_GetIntField(thisObj, idFid);    installInfo = read_install_info(&pszError, suiteId);    if (pszError != NULL) {        KNI_ThrowNew(midpIOException, pszError);        storageFreeError(pszError);    } else if (OUT_OF_MEM_INFO_STATUS(installInfo)) {        KNI_ThrowNew(midpOutOfMemoryError, NULL);    } else {        KNI_RESTORE_PCSL_STRING_FIELD(thisObj, clazz, "jadUrl",                                 &installInfo.jadUrl_s, temp);        KNI_RESTORE_PCSL_STRING_FIELD(thisObj, clazz, "jarUrl",                                 &installInfo.jarUrl_s, temp);        KNI_RESTORE_PCSL_STRING_FIELD(thisObj, clazz, "domain",                                 &installInfo.domain_s, temp);        KNI_RESTORE_BOOLEAN_FIELD(thisObj, clazz, "trusted",                                  installInfo.trusted);        fillAuthPath(KNIPASSARGS installInfo, thisObj, clazz);#if VERIFY_ONCE        (void)fillVerifyHash(suiteId, thisObj);#endif /* VERIFY_ONCE */        midp_free_install_info(&installInfo);    }    KNI_EndHandles();    KNI_ReturnVoid();}/** * native void load(); * * Gets the suite settings suite from persistent store. */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(com_sun_midp_midletsuite_SuiteSettings_load) {    SuiteIdType suiteId = UNUSED_SUITE_ID;    char* pszError;    jboolean enabled;    jbyte* pPermissions;    int numberOfPermissions;    int permissionsFieldLen;    jbyte pushInterrupt;    jint pushOptions;    jfieldID permissionsFid;    jfieldID suiteIdFid;    KNI_StartHandles(3);    KNI_DeclareHandle(thisObj);    KNI_DeclareHandle(clazz);    KNI_DeclareHandle(permissionsField);    KNI_GetThisPointer(thisObj);    KNI_GetObjectClass(thisObj, clazz);    permissionsFid = midp_get_field_id(KNIPASSARGS clazz, "permissions", "[B");    suiteIdFid = midp_get_field_id(KNIPASSARGS clazz, "suiteId", "I");    KNI_GetObjectField(thisObj, permissionsFid, permissionsField);    permissionsFieldLen = (int)KNI_GetArrayLength(permissionsField);    suiteId = KNI_GetIntField(thisObj, suiteIdFid);    do {        MIDPError status;        status = read_settings(&pszError, suiteId, &enabled, &pushInterrupt,            &pushOptions, &pPermissions, &numberOfPermissions);        if (status != ALL_OK) {            if (pszError != NULL) {                KNI_ThrowNew(midpIOException, pszError);                storageFreeError(pszError);            } else {                KNI_ThrowNew(midpOutOfMemoryError, NULL);            }            break;        }        KNI_RESTORE_BOOLEAN_FIELD(thisObj, clazz, "enabled", enabled);        KNI_RESTORE_BYTE_FIELD(thisObj, clazz, "pushInterruptSetting",                               pushInterrupt);        KNI_RESTORE_INT_FIELD(thisObj, clazz, "pushOptions",                              pushOptions);        if (numberOfPermissions > 0 && permissionsFieldLen > 0) {            if (numberOfPermissions > permissionsFieldLen) {                numberOfPermissions = permissionsFieldLen;            }            KNI_SetRawArrayRegion(permissionsField, 0, numberOfPermissions,                                  (jbyte*)pPermissions);        }        midpFree(pPermissions);    } while (0);    KNI_EndHandles();    KNI_ReturnVoid();}/** * private native void save0( *     jint suiteId, *     byte pushInterruptSetting, *     int pushOptions, *     byte[] permissions) throws IOException; * * Saves the suite settings to persistent store. * * @param suiteId ID of the suite * @param pushInterruptSetting push interrupt setting * @param pushOptions push options * @param permissions current permissions * * @throws IOException if an I/O error occurs */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(com_sun_midp_midletsuite_SuiteSettings_save0) {    char* pszError;    jbyte* pPermissions = NULL;    int permissionsLen;    jbyte pushInterrupt;    jint pushOptions;    jboolean enabled;    SuiteIdType suiteId;    MIDPError status;    KNI_StartHandles(1);    KNI_DeclareHandle(permissionsObj);    suiteId = KNI_GetParameterAsInt(1);    pushInterrupt = KNI_GetParameterAsByte(2);    pushOptions = KNI_GetParameterAsInt(3);    KNI_GetParameterAsObject(4, permissionsObj);    permissionsLen = (int)KNI_GetArrayLength(permissionsObj);    do {        pPermissions = (jbyte*)midpMalloc(permissionsLen);        if (pPermissions == NULL) {            KNI_ThrowNew(midpOutOfMemoryError, NULL);            break;        }        KNI_GetRawArrayRegion(permissionsObj, 0, permissionsLen,                              (jbyte*)pPermissions);        status = read_enabled_state(&pszError, suiteId, &enabled);        if (status != ALL_OK) {            if (pszError != NULL) {                KNI_ThrowNew(midpIOException, pszError);                storageFreeError(pszError);            } else {                KNI_ThrowNew(midpOutOfMemoryError, NULL);            }            break;        }        status = write_settings(&pszError, suiteId, enabled, pushInterrupt,                                pushOptions, pPermissions, permissionsLen,                                NULL);        if (status != ALL_OK) {            if (pszError != NULL) {                KNI_ThrowNew(midpIOException, pszError);                storageFreeError(pszError);            } else {                KNI_ThrowNew(midpOutOfMemoryError, NULL);            }            break;        }    } while (0);    midpFree(pPermissions);    KNI_EndHandles();    KNI_ReturnVoid();}/** * native String[] load() throws IOException; * * Gets the suite properties from persistent store. Returns the * properties as an array of strings: key0, value0, key1, value1, etc. * * @return an array of property key-value pairs * * @throws IOException if an IO error occurs * * The format of the properties file is: * <pre> * <number of strings as int (2 strings per property)> *    {repeated for each property} *    <length of a property key as int> *    <property key as jchars> *    <length of property value as int> *    <property value as jchars>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?