/** * Checks the size of free space in storage. * @return size of free space */ javacall_int64 javacall_dir_get_free_space_for_java(void) { long result; int rootPathLen = JAVACALL_MAX_FILE_NAME_LENGTH; javacall_utf16 rootPath[JAVACALL_MAX_FILE_NAME_LENGTH]; javacall_int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes; char root[JAVACALL_MAX_FILE_NAME_LENGTH]; javacall_result res; int i; res = javacall_dir_get_root_path(rootPath, &rootPathLen); for (i=0; i<rootPathLen; i++) { root[i] = (char)rootPath[i]; } root[i] = '\0'; result = GetDiskFreeSpaceEx(root, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes); if (result) { if (i64FreeBytesToCaller > DEFAULT_MAX_JAVA_SPACE) { return DEFAULT_MAX_JAVA_SPACE; } return i64FreeBytesToCaller; } return 0; }
/** * Generates a correct application directory based on several rules. If * the <tt>MIDP_HOME</tt> environment variable is set, its value is used * unmodified. Otherwise, this function will search for the <tt>appdb</tt> * directory in the following order: * <ul> * <li>current directory (if the MIDP executable is in the <tt>PATH</tt> * environment variable and the current directory is the right place) * <li>the parent directory of the midp executable * <li>the grandparent directory of the midp executable * </ul> * <p> * If <tt>cmd</tt> does not contain a directory (i.e. just the text * <tt>midp</tt>), the search starts from the current directory. Otherwise, * the search starts from the directory specified in <tt>cmd</tt> (i.e. * start in the directory <tt>bin</tt> if <tt>cmd</tt> is <tt>bin/midp</tt>). * <p> * <b>NOTE:</b> This is only applicable for development platforms. * * @param cmd A 'C' string containing the command used to start MIDP. * @return A 'C' string the found MIDP home directory, otherwise * <tt>NULL</tt>, this will be a static buffer, so that it safe * to call this function before midpInitialize, don't free it */ char* getApplicationDir(char *cmd) { static javacall_utf16 path[MAX_PATH_LEN]; static char midpAppDir[MAX_PATH_LEN]; javacall_result ret; int len = MAX_PATH_LEN - 1; (void)cmd; ret = javacall_dir_get_root_path (path, &len); if ( ret != JAVACALL_OK ) { REPORT_ERROR(LC_AMS,"getApplicationDir() << Root path query failed."); return NULL; } ret = javautil_unicode_utf16_to_utf8(path, len, midpAppDir, MAX_PATH_LEN, (int*)&len); if ( ret != JAVACALL_OK ) { REPORT_ERROR(LC_AMS,"getApplicationDir() << Root path query failed."); return NULL; } midpAppDir[len] = 0; return midpAppDir; }
javacall_result javacall_security_keystore_start(javacall_handle* jc_h) { javacall_utf16 rootPath[JAVACALL_MAX_FILE_NAME_LENGTH]; unsigned short unicode_main_ks[] = {'\\','_','m','a','i','n','.','k','s'}; int unicode_main_ks_name_length = sizeof(unicode_main_ks)/sizeof(unsigned short); javacall_result result; javacall_handle handle; int rootPathLen = JAVACALL_MAX_FILE_NAME_LENGTH; int res; int i; memset(rootPath, 0, JAVACALL_MAX_FILE_NAME_LENGTH); result = javacall_dir_get_root_path(rootPath, &rootPathLen); if(result == JAVACALL_FAIL) { return JAVACALL_FAIL; } if(rootPathLen < (JAVACALL_MAX_FILE_NAME_LENGTH - unicode_main_ks_name_length)) { for(i = 0; i < unicode_main_ks_name_length; i++) { rootPath[rootPathLen+i] = unicode_main_ks[i]; } rootPathLen+=i; } else { printf("javacall_security.c : File name %d, is to long.\n", unicode_to_char(rootPath)); return JAVACALL_FAIL; } javacall_set_local_variables(); currentPosition = NULL; printf("Opening %s.\n", unicode_to_char(rootPath)); result = javacall_file_open(rootPath, rootPathLen, JAVACALL_FILE_O_RDONLY, &handle); if(result == JAVACALL_FAIL) { printf("Can't open %s.\n", unicode_to_char(rootPath)); return JAVACALL_FAIL; } main_ks_size = (int)javacall_file_sizeofopenfile(handle); if(-1 == main_ks_size) { javacall_file_close(handle); printf("Can't get javacall_file_sizeofopenfile() %s\n", unicode_to_char(rootPath)); return JAVACALL_FAIL; } _main_ks_content = (unsigned char *) malloc(main_ks_size); if(_main_ks_content == NULL) { javacall_file_close(handle); return JAVACALL_FAIL; } res = javacall_file_read(handle, _main_ks_content, main_ks_size); if(res <= 0 ) { printf("Can't read %s\n", unicode_to_char(rootPath)); free(_main_ks_content); javacall_file_close(handle); return JAVACALL_FAIL; } javacall_file_close(handle); currentPosition = _main_ks_content; if(*currentPosition != CURRENT_VERSION) { printf("Can't read this key storage. Current version isn't correct\n"); free(_main_ks_content); currentPosition = NULL; return JAVACALL_FAIL; } currentPosition++; *jc_h = (javacall_handle)(¤tPosition); return JAVACALL_OK; } /* end of javacall_security_keystore_start */