⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 midpstartup.c

📁 用于移动设备上的java虚拟机源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    pathLen += strlen(getStorageRoot());    pathLen += strlen(suiteStorageName);    pathLen += strlen(AppJarFile);    pathLen += 1; /* Add one for trailing NULL */    path = (char*)midpMalloc(pathLen);    if (NULL == path) {        return NULL;    }    /* see MidletSuiteImpl.java for the correct separator */    sprintf(path, "%s%s%s", getStorageRoot(), suiteStorageName,            AppJarFile);    return path;}/*========================================================================= * FUNCTION:      getStorageNameFromNumber * OVERVIEW:      Convert a number to a MIDlet Suite storage name. The *                returned pointer must be de-allocated by the caller. * INTERFACE: *   parameters:  numberString:  A 'C' string containing the number *                                to convert. *   returns:     'C' string:    A 'C' string with the MIDlet Suite *                                storage name. *=======================================================================*/static char*getStorageNameFromNumber(char* numberString) {    int numberOfSuite;    char filename[MAX_FILENAME_LENGTH + 1];    char* pszError;    int handle;    char* previousName;    char* name;    int i;    /* the format of the string is "number:" */    if (sscanf(numberString, "%d", &numberOfSuite) != 1) {            fprintf(stderr,                    "Error getting storage name: invalid number format\n");        exit(-1);        return NULL;    }    /* the storage root will have any needed file separators */    strcpy(filename, getStorageRoot());    /* "suites.utf" is from com.sun.midp.midletsuite.Installer */    strcat(filename, SuitesFile);    handle = storageOpen(&pszError, filename, OPEN_READ);    if (pszError != NULL) {        fprintf(stderr, "Error getting storage name: %s\n", pszError);        storageFreeError(pszError);        exit(-1);        return NULL;    }    previousName = NULL;    for (i = 0; i < numberOfSuite; i++) {        name = readSuiteStorageName(&pszError, handle);        if (pszError != NULL) {            fprintf(stderr, "Error getting storage name: %s\n", pszError);            storageFreeError(pszError);            exit(-1);            return NULL;        }        if (name == NULL) {            fprintf(stderr, "Could not find suite number %d.\n",                    numberOfSuite);            exit(-1);            return NULL;        }        if (previousName != NULL) {            midpFree(previousName);        }        previousName = name;    }    storageClose(&pszError, handle);    return previousName;}/*========================================================================= * FUNCTION:      readSuiteStorageName * OVERVIEW:      Read a single storage name from a file containing a *                list of UTF-8 encoded storage names. * INTERFACE: *   parameters:  ppszError:   (out) 'C' string error message, if an error *                              occured while reading. *                handle:      The handle of the file to read *   returns:     'C' string:  The storage name, or, NULL if an error *                              occured while reading. If an error *                              occored, '*ppszError' will be non-NULL. *=======================================================================*/static char*readSuiteStorageName(char** ppszError, int handle) {    unsigned char msb;    unsigned int length;    unsigned char lsb;    char* name;    /* string format is: msb of length, lsb of length, length of bytes */    if (storageRead(ppszError, handle, (char*)&msb, 1) != 1) {        return NULL;    }    length = msb * 256;    if (storageRead(ppszError, handle, (char*)&lsb, 1) != 1) {        return NULL;    }    length += lsb;    name = (char*)midpMalloc(length + 1);    if (name == NULL) {        return NULL;    }    /*     * storage names only contain ASCII characters so no conversion is     * required     */    if (storageRead(ppszError, handle, name, length) != length) {        midpFree(name);        return NULL;    }    name[length] = 0;    return name;}/*========================================================================= * FUNCTION:      checkRestrictedPackageNameWithLen * OVERVIEW:      Checks in the requested package name is one of the MIDP *                protected namespace. This is used by the CLDC class loader *                to disallow application from creating Java class in the *                protected namespace as described in the CLDC specification. * INTERFACE: *   parameters:  packagename: The requested package name without the  *                             trailing '/' (may not be null terminated) *                len:         Length of the package name. *   returns:     boolean:     true if packagename is one of the protected *                             package namespace in MIDP. False otherwise *=======================================================================*/jboolean checkRestrictedPackageNameWithLen(const char *packagename, int len){  /*   * quick smoked test for protected package name. This reduces the number   * of strncmp() against the protected list.   * - if package name len is < 4   * - if package name does not start with "java"   * - if package name does not start with "com/sun"   */  if ((len < 4) ||      ((strncmp(packagename, "java", 4) != 0) &&       ((len >= 7) && (strncmp(packagename, "com/sun", 7) != 0)))) {    return KNI_FALSE;  }  /*   * Restrict classes and subpackage in the "java" and "javax" namespaces   * - classes will have "java" or "javax" as the package name   * - subpackage will have "java/" or "javax/" prefix   */  if (((len >= 4) && (strncmp(packagename, "java", 4) == 0) &&       ((len == 4) || (packagename[4] == '/'))) ||      ((len >= 5) && (strncmp(packagename, "javax", 5) == 0) &&       ((len == 5) || (packagename[5] == '/')))) {    return KNI_TRUE;  }   /*   * Restrict classes and subpackage in the "com/sun/cldc/i18n",   * "com/sun/cldc/io", & "com/sun/cldc/util" package namespaces   *   * Note: classes or other subpackage in "com/sun/cldc" is allowed.    * The code is more complicated due to this reason, instead of just   * protecting the entire com/sun/cldc namespace.   */  else if ((len >= 12) && (strncmp(packagename, "com/sun/cldc", 12) == 0)) {    if ((len != 12) &&        (((len >= 17) && (strncmp(packagename+12, "/i18n", 5) == 0) &&          ((len == 17) || (packagename[17] == '/'))) ||         ((len >= 15) && (strncmp(packagename+12, "/io", 3) == 0) &&          ((len == 15) || (packagename[15] == '/'))) ||         ((len >= 17) && (strncmp(packagename+12, "/util", 5) == 0) &&          ((len == 17) || (packagename[17] == '/'))))) {      return KNI_TRUE;    }  }   /*   * Restrict classes and subpackage in the    * "com/sun/midp/dev",   * "com/sun/midp/io",    * "com/sun/midp/lcdui",    * "com/sun/midp/main",    * "com/sun/midp/midlet",    * "com/sun/midp/midletsuite",    * "com/sun/midp/perfmon",    * "com/sun/midp/publickeystore",    * "com/sun/midp/rm",    * "com/sun/midp/security",    * & "com/sun/midp/ssl" package namespaces   *   * Note: classes or other subpackage in "com/sun/midp" is allowed.    * The code is more complicated due to this reason, instead of just   * protecting the entire com/sun/midp namespace.   */  else if ((len >= 12) && (strncmp(packagename, "com/sun/midp", 12) == 0)) {    if ((len !=12) &&        (((len >= 16) && (strncmp(packagename+12, "/dev", 4) == 0) &&          ((len == 16) || (packagename[16] == '/'))) ||         ((len >= 15) && (strncmp(packagename+12, "/io", 3) == 0) &&          ((len == 15) || (packagename[15] == '/'))) ||         ((len >= 18) && (strncmp(packagename+12, "/lcdui", 6) == 0) &&          ((len == 18) || (packagename[18] == '/'))) ||         ((len >= 17) && (strncmp(packagename+12, "/main", 6) == 0) &&          ((len == 17) || (packagename[17] == '/'))) ||         ((len >= 19) && (strncmp(packagename+12, "/midlet", 7) == 0) &&          ((len == 19) || (packagename[19] == '/'))) ||         ((len >= 24) && (strncmp(packagename+12, "/midletsuite", 12) == 0) &&          ((len == 24) || (packagename[24] == '/'))) ||         ((len >= 20) && (strncmp(packagename+12, "/perfmon", 8) == 0) &&          ((len == 20) || (packagename[20] == '/'))) ||         ((len >= 27) && (strncmp(packagename+12, "/publickeystore", 15) == 0) &&          ((len == 27) || (packagename[27] == '/'))) ||         ((len >= 16) && (strncmp(packagename+12, "/rms", 4) == 0) &&          ((len == 16) || (packagename[16] == '/'))) ||         ((len >= 21) && (strncmp(packagename+12, "/security", 9) == 0) &&          ((len == 21) || (packagename[21] == '/'))) ||         ((len >= 16) && (strncmp(packagename+12, "/ssl", 4) == 0) &&          ((len == 16) || (packagename[16] == '/'))))) {	return KNI_TRUE;    }  }   /*   * Restrict classes and subpackage in the "com/sun/mmedia" namespace   * - classes will have "com/sun/mmedia" as the package name   * - subpackage will have "com/sun/mmedia/" prefix   */  else if ((len >= 14) &&            (strncmp(packagename, "com/sun/mmedia", 14) == 0) &&           ((len == 14) || (packagename[14] == '/'))) {    return KNI_TRUE;  }  /* does not match any of the protected namespace */  return KNI_FALSE;}/*========================================================================= * FUNCTION:      checkRestrictedPackageName * OVERVIEW:      Checks in the requested package name is one of the MIDP *                protected namespace. This is used by the CLDC class loader *                to disallow application from creating Java class in the *                protected namespace as described in the CLDC specification. * INTERFACE: *   parameters:  packagename: The requested package name without the  *                             trailing '/' *                             (null terminated) *   returns:     boolean:     true is packagename is one of the protected *                             package namespace in MIDP. False otherwise *=======================================================================*/jboolean checkRestrictedPackageName(const char *packagename) {  return checkRestrictedPackageNameWithLen(packagename, strlen(packagename));}

⌨️ 快捷键说明

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