suitestore_installer.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,096 行 · 第 1/3 页
C
1,096 行
/* * * * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. *//** * @file * * @ingroup AMS * * This is reference implementation of the Installer API of the MIDlet suite * storage subsystem. The functions implemented in this file need not to be * ported if using a native installer (what is probably the case if using NAMS). */#include <string.h>#include <kni.h>#include <pcsl_memory.h>#include <midpInit.h>#include <midpStorage.h>#include <imageCache.h>#include <suitestore_intern.h>#include <suitestore_listeners.h>#include <suitestore_installer.h>#include <suitestore_task_manager.h>#if ENABLE_ICON_CACHE#include <suitestore_icon_cache.h>/** * Loads a native image from cache or jar file into memory. * * @param suiteId The suite id * @param pImageName The image resource name * @param **ppImageData Pointer where a buffer will be allocated and data stored * @return -1 if failed, else length of buffer */static intgetImageForIconCache(SuiteIdType suiteId, const pcsl_string* pImageName, unsigned char **ppImageData);#endif/* Description of these internal functions can be found bellow in the code. */static MIDPError store_install_properties(SuiteIdType suiteId, const MidpProperties* pJadProps, const MidpProperties* pJarProps, jint* pOutDataSize);static MIDPError store_jar(char** ppszError, ComponentType type, SuiteIdType suiteId, ComponentIdType componentId, StorageIdType storageId, const pcsl_string* jarName, pcsl_string* pNewFileName);static MIDPError add_to_suite_list_and_save(MidletSuiteData* pMsd);static MIDPError write_install_info(char** ppszError, ComponentType type, SuiteIdType suiteId, ComponentIdType componentId, const MidpInstallInfo* pInstallInfo, jint* pOutDataSize);static MIDPError create_unique_id(ComponentType idType, void* pId);/* ------------------------------------------------------------ *//* Public API *//* ------------------------------------------------------------ *//** * Returns a unique identifier of MIDlet suite. * * @param pSuiteId [out] receives the platform-specific storage name of the * application given by vendorName and appName * * @return ALL_OK if success, else an error code */MIDPErrormidp_create_suite_id(SuiteIdType* pSuiteId) { return create_unique_id(COMPONENT_REGULAR_SUITE, pSuiteId);}#if ENABLE_DYNAMIC_COMPONENTS/** * Returns a unique identifier of a MIDlet suite's dynamic component. * * @param pComponentId [out] receives a platform-specific id of the component * * @return ALL_OK if success, else an error code */MIDPErrormidp_create_component_id(ComponentIdType* pComponentId) { return create_unique_id(COMPONENT_DYNAMIC, pComponentId);}#endif /* ENABLE_DYNAMIC_COMPONENTS *//** * Read a the install information of a suite from persistent storage. * The caller should have make sure the suite ID is valid. * The caller should call midp_free_install_info when done with the information. * jadProps and jarProps fields are NOT filled by this function. * <pre> * The fields are * jadUrl * jarUrl * ca * domain * trusted * * Unicode strings are written as an int length and a jchar array. * </pre> * @param ppszError pointer to character string pointer to accept an error * @param suiteId ID of a suite * * @return an InstallInfo struct, use the status macros to check for * error conditions in the struct */MidpInstallInforead_install_info(char** ppszError, SuiteIdType suiteId) { MidpInstallInfo installInfo; pcsl_string filename; char* pszTemp; int handle; int no_errors = 0; int i; int rc; *ppszError = NULL; memset((unsigned char*)&installInfo, 0, sizeof (MidpInstallInfo)); rc = build_suite_filename(suiteId, &INSTALL_INFO_FILENAME, &filename); if (rc < 0) { installInfo.status = rc; return installInfo; } handle = storage_open(ppszError, &filename, OPEN_READ); pcsl_string_free(&filename); if (*ppszError != NULL) { installInfo.status = IO_ERROR; return installInfo; } do { storage_read_utf16_string(ppszError, handle, &installInfo.jadUrl_s); storage_read_utf16_string(ppszError, handle, &installInfo.jarUrl_s); storage_read_utf16_string(ppszError, handle, &installInfo.domain_s); storageRead(ppszError, handle, (char*)(&installInfo.trusted), sizeof (installInfo.trusted)); if (*ppszError != NULL) { break; } installInfo.authPathLen = 0; installInfo.authPath_as = NULL; storageRead(ppszError, handle, (char*)(&installInfo.authPathLen), sizeof (installInfo.authPathLen)); if (*ppszError != NULL) { break; } if (installInfo.authPathLen <= 0) { no_errors = 1; break; } installInfo.authPath_as = alloc_pcsl_string_list(installInfo.authPathLen); if (NULL == installInfo.authPath_as) { installInfo.authPathLen = 0; break; } for (i = 0; i < installInfo.authPathLen; i++) { storage_read_utf16_string(ppszError, handle, &installInfo.authPath_as[i]); } if (i != installInfo.authPathLen) { installInfo.authPathLen = i; break; } no_errors = 1; } while (0); storageClose(&pszTemp, handle); storageFreeError(pszTemp); if (no_errors) { return installInfo; } midp_free_install_info(&installInfo); memset((unsigned char*)&installInfo, 0, sizeof (MidpInstallInfo)); if (*ppszError != NULL) { installInfo.status = IO_ERROR; } else { installInfo.status = OUT_OF_MEMORY; } return installInfo;}/** * Frees an InstallInfo struct. Does nothing if passed NULL. * * @param pInstallInfo installation information returned from read_install_info. */voidmidp_free_install_info(MidpInstallInfo* pInstallInfo) { if (pInstallInfo != NULL) { pcsl_string_free(&pInstallInfo->jadUrl_s); pcsl_string_free(&pInstallInfo->jarUrl_s); pcsl_string_free(&pInstallInfo->domain_s); if (pInstallInfo->authPathLen > 0) { free_pcsl_string_list(pInstallInfo->authPath_as, pInstallInfo->authPathLen); } pInstallInfo->authPath_as = NULL; pInstallInfo->authPathLen = 0; }}/** * Gets the install information of a MIDlet suite. * * Note that memory for the strings inside the returned MidpInstallInfo * structure is allocated by the callee, and the caller is * responsible for freeing it using midp_free_install_info(). * * @param suiteId ID of the suite * * @return Installation information, use status macros to check the result * A SUITE_CORRUPTED_ERROR is returned as a status in InstallInfo * when suite is corrupted */MidpInstallInfomidp_get_suite_install_info(SuiteIdType suiteId) { MidpInstallInfo installInfo; char* pszError; /* * 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(LIST_LEVEL) != 0) { installInfo.status = OUT_OF_MEMORY; return installInfo; } /* if (check_for_corrupted_suite(suiteId) == SUITE_CORRUPTED_ERROR) { installInfo.status = SUITE_CORRUPTED_ERROR; return installInfo; } */ installInfo = read_install_info(&pszError, suiteId); if (pszError != NULL) { storageFreeError(pszError); }#if VERIFY_ONCE /* Read verify hash info */ installInfo.status = readVerifyHash(suiteId, &installInfo.pVerifyHash, &installInfo.verifyHashLen);#endif /* VERIFY_ONCE */ return installInfo;}/** * Stores or updates a midlet suite. * * @param pInstallInfo structure containing the following information:<br> * <pre> * id - unique ID of the suite; * jadUrl - where the JAD came from, can be null; * jarUrl - where the JAR came from; * jarFilename - name of the downloaded MIDlet suite jar file; * suiteName - name of the suite; * suiteVendor - vendor of the suite; * authPath - authPath if signed, the authorization path starting * with the most trusted authority; * domain - security domain of the suite; * trusted - true if suite is trusted; * verifyHash - may contain hash value of the suite with * preverified classes or may be NULL; * jadProps - properties given in the JAD as an array of strings in * key/value pair order, can be null if jadUrl is null * jarProps - properties of the manifest as an array of strings * in key/value pair order * </pre> * * @param pSuiteSettings structure containing the following information:<br> * <pre> * permissions - permissions for the suite; * pushInterruptSetting - defines if this MIDlet suite interrupt * other suites; * pushOptions - user options for push interrupts; * suiteId - unique ID of the suite, must be equal to the one given * in installInfo; * boolean enabled - if true, MIDlet from this suite can be run; * </pre> * * @param pSuiteData structure containing the following information:<br> * <pre> * suiteId - unique ID of the suite, must be equal to the value given * in installInfo and suiteSettings parameters; * storageId - ID of the storage where the MIDlet should be installed; * numberOfMidlets - number of midlets in the suite; * displayName - the suite's name to display to the user; * midletToRunClassName - the midlet's class name if the suite contains * only one midlet, ignored otherwise; * iconName - name of the icon for this suite. * </pre> * * @return status ALL_OK for success else an error code */MIDPErrormidp_store_suite(const MidpInstallInfo* pInstallInfo, const MidpSuiteSettings* pSuiteSettings, const MidletSuiteData* pSuiteData) { MIDPError status; char* pszError; lockStorageList *node; SuiteIdType suiteId; jint tmpSize;#if ENABLE_ICON_CACHE unsigned char* pIconData = NULL; int iconBufLen = -1;#endif if (pInstallInfo == NULL || pSuiteSettings == NULL || pSuiteData == NULL) { return BAD_PARAMS; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?