EXPORT(bool) aiInterfaceCallback_DataDirs_Roots_locatePath(int UNUSED_interfaceId, char* path, int path_sizeMax, const char* const relPath, bool writeable, bool create, bool dir) { bool exists = false; int locateFlags = 0; if (writeable) { locateFlags = locateFlags | FileSystem::WRITE; if (create) { locateFlags = locateFlags | FileSystem::CREATE_DIRS; } } std::string locatedPath = ""; const size_t tmpRelPath_size = strlen(relPath) + 1; char* tmpRelPath = new char[tmpRelPath_size]; STRCPYS(tmpRelPath, tmpRelPath_size, relPath); std::string tmpRelPathStr = tmpRelPath; if (dir) { locatedPath = filesystem.LocateDir(tmpRelPathStr, locateFlags); } else { locatedPath = filesystem.LocateFile(tmpRelPathStr, locateFlags); } exists = (locatedPath != relPath); STRCPYS(path, path_sizeMax, locatedPath.c_str()); delete [] tmpRelPath; return exists; }
PSDash::_void CLoginDlg::OnRegisterResult( _dword Callback, const RegisterResult & Result ) { BOOL bShowSelectUserName = FALSE, bCanceled = FALSE; if(Result.ErrorNum == 0) { MessageBox(GetFramework()->GetError(AP_E_Info_Succ), L"", MB_OK|MB_ICONEXCLAMATION); GetDlgItem(IDC_USERNAME).SetWindowText(m_RegInfo.UserName); GetDlgItem(IDC_PASSWORD).SetFocus(); } else { CString OutMsg; for(_dword a=0; a<Result.ErrorNum; a++) { CString tmp; tmp.Format(L"%d. %s\r\n", a+1, GetFramework()->GetError(Result.ErrorCode[a])); OutMsg +=tmp; if(Result.ErrorCode[a] == AP_E_Info_UserNameOccupied) { bShowSelectUserName = TRUE; } } if(!OutMsg.IsEmpty()) { MessageBox(OutMsg, L"Error", MB_OK | MB_ICONEXCLAMATION); } if(bShowSelectUserName) { CSelUserNameDlg dlg; dlg.m_Result = Result; int ret = dlg.DoModal(m_hWnd); if(ret == IDOK) { STRCPYS(m_RegInfo.UserName, (LPCTSTR)dlg.m_SeledUserName); } else if(ret == IDCANCEL) { bCanceled = TRUE; } } if(!bCanceled) this->SendMessage(WM_COMMAND, MAKEWPARAM(IDC_REGISTER, BN_CLICKED), (LPARAM)GetDlgItem(IDC_REGISTER).m_hWnd); } }
/** * Creates the Java library path. * -> where native shared libraries are searched * * It will consist of the following: * {spring-data-dir}/{AI_INTERFACES_DATA_DIR}/Java/{version}/ * {spring-data-dir}/{AI_INTERFACES_DATA_DIR}/Java/{version}/lib/ * {spring-data-dir}/{AI_INTERFACES_DATA_DIR}/Java/common/ * {spring-data-dir}/{AI_INTERFACES_DATA_DIR}/Java/common/lib/ */ static bool java_createNativeLibsPath(char* libraryPath, const size_t libraryPath_sizeMax) { // {spring-data-dir}/{AI_INTERFACES_DATA_DIR}/Java/{version}/ const char* const dd_r = callback->AIInterface_Info_getValueByKey(interfaceId, AI_INTERFACE_PROPERTY_DATA_DIR); if (dd_r == NULL) { simpleLog_logL(SIMPLELOG_LEVEL_ERROR, "Unable to find read-only data-dir."); return false; } else { STRCPYS(libraryPath, libraryPath_sizeMax, dd_r); } // {spring-data-dir}/{AI_INTERFACES_DATA_DIR}/Java/{version}/lib/ char* dd_lib_r = callback->DataDirs_allocatePath(interfaceId, NATIVE_LIBS_DIR, false, false, true, false); if (dd_lib_r == NULL) { simpleLog_logL(SIMPLELOG_LEVEL_NORMAL, "Unable to find read-only native libs data-dir (optional): %s", NATIVE_LIBS_DIR); } else { STRCATS(libraryPath, libraryPath_sizeMax, ENTRY_DELIM); STRCATS(libraryPath, libraryPath_sizeMax, dd_lib_r); FREE(dd_lib_r); } // {spring-data-dir}/{AI_INTERFACES_DATA_DIR}/Java/common/ const char* const dd_r_common = callback->AIInterface_Info_getValueByKey(interfaceId, AI_INTERFACE_PROPERTY_DATA_DIR_COMMON); if (dd_r_common == NULL || !util_fileExists(dd_r_common)) { simpleLog_logL(SIMPLELOG_LEVEL_NORMAL, "Unable to find common read-only data-dir (optional)."); } else { STRCATS(libraryPath, libraryPath_sizeMax, ENTRY_DELIM); STRCATS(libraryPath, libraryPath_sizeMax, dd_r_common); } // {spring-data-dir}/{AI_INTERFACES_DATA_DIR}/Java/common/lib/ if (dd_r_common != NULL) { char* dd_lib_r_common = callback->DataDirs_allocatePath(interfaceId, NATIVE_LIBS_DIR, false, false, true, true); if (dd_lib_r_common == NULL || !util_fileExists(dd_lib_r_common)) { simpleLog_logL(SIMPLELOG_LEVEL_NORMAL, "Unable to find common read-only native libs data-dir (optional)."); } else { STRCATS(libraryPath, libraryPath_sizeMax, ENTRY_DELIM); STRCATS(libraryPath, libraryPath_sizeMax, dd_lib_r_common); FREE(dd_lib_r_common); } } return true; }
EXPORT(bool) aiInterfaceCallback_DataDirs_Roots_getDir(int UNUSED_interfaceId, char* path, int path_sizeMax, int dirIndex) { const std::vector<std::string> dds = FileSystemHandler::GetInstance().GetDataDirectories(); size_t numDataDirs = dds.size(); if (dirIndex >= 0 && (size_t)dirIndex < numDataDirs) { STRCPYS(path, path_sizeMax, dds[dirIndex].c_str()); return true; } else { return false; } }
bool GetJREPathFromBase(char* path, size_t pathSize, const char* basePath, const char* arch) { char jrePath[MAXPATHLEN]; bool found = false; if (basePath != NULL) { // Is basePath a JRE path? STRCPYS(jrePath, MAXPATHLEN, basePath); if (CheckIfJREPath(jrePath, arch)) { STRCPYS(path, pathSize, basePath); found = true; } // Is basePath/jre a JRE path? STRCATS(jrePath, MAXPATHLEN, "/jre"); if (CheckIfJREPath(jrePath, arch)) { STRCPYS(path, pathSize, jrePath); found = true; } } return found; }
bool cRAI::LocateFile(IAICallback* cb, const string& relFileName, string& absFileName, bool forWriting) { int action = forWriting ? AIVAL_LOCATE_FILE_W : AIVAL_LOCATE_FILE_R; char absFN[2048]; STRCPYS(absFN, sizeof(absFN), relFileName.c_str()); const bool located = cb->GetValue(action, absFN); if (located) { absFileName = absFN; } else { absFileName = ""; } return located; }
bool cRAI::LocateFile(IAICallback* cb, const string& relFileName, string& absFileName, bool forWriting) { int action = AIVAL_LOCATE_FILE_R; if (forWriting) { action = AIVAL_LOCATE_FILE_W; } const size_t absFN_sizeMax = 512 + relFileName.size(); char absFN[absFN_sizeMax]; STRCPYS(absFN, absFN_sizeMax, relFileName.c_str()); const bool located = cb->GetValue(action, absFN); if (located) { absFileName = absFN; } else { absFileName = ""; } return located; }
std::string ExecuteProcess(const std::string& file, std::vector<std::string> args) { std::string execError = ""; // "The first argument, by convention, should point to // the filename associated with the file being executed." args.insert(args.begin(), Quote(file)); char** processArgs = new char*[args.size() + 1]; for (size_t a = 0; a < args.size(); ++a) { const std::string& arg = args.at(a); const size_t arg_size = arg.length() + 1; processArgs[a] = new char[arg_size]; STRCPYS(processArgs[a], arg_size, arg.c_str()); } // "The array of pointers must be terminated by a NULL pointer." processArgs[args.size()] = NULL; { // Execute #ifdef WIN32 #define EXECVP _execvp #else #define EXECVP execvp #endif const int ret = EXECVP(file.c_str(), processArgs); if (ret == -1) { execError = strerror(errno); } } for (size_t a = 0; a < args.size(); ++a) { delete[] processArgs[a]; } delete[] processArgs; return execError; }
static bool java_createJavaVMInitArgs(struct JavaVMInitArgs* vm_args, const struct Properties* jvmProps) { // ### evaluate JNI version to use ### //jint jniVersion = JNI_VERSION_1_1; //jint jniVersion = JNI_VERSION_1_2; jint jniVersion = JNI_VERSION_1_4; //jint jniVersion = JNI_VERSION_1_6; if (jvmProps != NULL) { const char* jniVersionFromCfg = java_getValueByKey(jvmProps, "jvm.jni.version"); if (jniVersionFromCfg != NULL) { unsigned long int jniVersion_tmp = strtoul(jniVersionFromCfg, NULL, 16); if (jniVersion_tmp != 0/* && jniVersion_tmp != ULONG_MAX*/) { jniVersion = (jint) jniVersion_tmp; } } } simpleLog_logL(SIMPLELOG_LEVEL_FINE, "JVM: JNI version: %#x", jniVersion); vm_args->version = jniVersion; // ### check if debug related JVM options should be used ### // if false, the JVM creation will fail if an // unknown or invalid option was specified bool useDebugOptions = true; const char* useDebugOptionsStr = "auto"; if (jvmProps != NULL) { const char* useDebugOptionsFromCfg = util_map_getValueByKey( jvmProps->size, jvmProps->keys, jvmProps->values, "jvm.useDebugOptions"); if (useDebugOptionsFromCfg != NULL) { useDebugOptionsStr = useDebugOptionsFromCfg; } } { if (strcmp(useDebugOptionsStr, "auto") == 0 || strcmp(useDebugOptionsStr, "Auto") == 0 || strcmp(useDebugOptionsStr, "AUTO") == 0 || strcmp(useDebugOptionsStr, "a") == 0 || strcmp(useDebugOptionsStr, "A") == 0) { // auto #if defined DEBUG useDebugOptions = true; #else // defined DEBUG useDebugOptions = false; #endif // defined DEBUG } else { // true or false useDebugOptions = util_strToBool(useDebugOptionsStr); } } // ### check if unrecognized JVM options should be ignored ### // if false, the JVM creation will fail if an // unknown or invalid option was specified bool ignoreUnrecognized = true; if (jvmProps != NULL) { const char* ignoreUnrecognizedFromCfg = java_getValueByKey(jvmProps, "jvm.arguments.ignoreUnrecognized"); if (ignoreUnrecognizedFromCfg != NULL && !util_strToBool(ignoreUnrecognizedFromCfg)) { ignoreUnrecognized = false; } } if (ignoreUnrecognized) { simpleLog_logL(SIMPLELOG_LEVEL_FINE, "JVM: ignoring unrecognized options"); vm_args->ignoreUnrecognized = JNI_TRUE; } else { simpleLog_logL(SIMPLELOG_LEVEL_FINE, "JVM: NOT ignoring unrecognized options"); vm_args->ignoreUnrecognized = JNI_FALSE; } // ### create the Java class-path option ### // autogenerate the class path static const size_t classPath_sizeMax = 8 * 1024; char* classPath = util_allocStr(classPath_sizeMax); // ..., autogenerate it ... if (!java_createClassPath(classPath, classPath_sizeMax)) { simpleLog_logL(SIMPLELOG_LEVEL_ERROR, "Failed creating Java class-path."); return false; } if (jvmProps != NULL) { // ..., and append the part from the jvm options properties file, // if it is specified there const char* clsPathFromCfg = java_getValueByKey(jvmProps, "jvm.option.java.class.path"); if (clsPathFromCfg != NULL) { STRCATS(classPath, classPath_sizeMax, ENTRY_DELIM); STRCATS(classPath, classPath_sizeMax, clsPathFromCfg); } } // create the java.class.path option static const size_t classPathOpt_sizeMax = 8 * 1024; char* classPathOpt = util_allocStr(classPathOpt_sizeMax); STRCPYS(classPathOpt, classPathOpt_sizeMax, "-Djava.class.path="); STRCATS(classPathOpt, classPathOpt_sizeMax, classPath); FREE(classPath); // ### create the Java library-path option ### // autogenerate the java library path static const size_t libraryPath_sizeMax = 4 * 1024; char* libraryPath = util_allocStr(libraryPath_sizeMax); // ..., autogenerate it ... if (!java_createNativeLibsPath(libraryPath, libraryPath_sizeMax)) { simpleLog_logL(SIMPLELOG_LEVEL_ERROR, "Failed creating Java library-path."); return false; } if (jvmProps != NULL) { // ..., and append the part from the jvm options properties file, // if it is specified there const char* libPathFromCfg = java_getValueByKey(jvmProps, "jvm.option.java.library.path"); if (libPathFromCfg != NULL) { STRCATS(libraryPath, libraryPath_sizeMax, ENTRY_DELIM); STRCATS(libraryPath, libraryPath_sizeMax, libPathFromCfg); } } // create the java.library.path option ... // autogenerate it, and append the part from the jvm options file, // if it is specified there static const size_t libraryPathOpt_sizeMax = 4 * 1024; char* libraryPathOpt = util_allocStr(libraryPathOpt_sizeMax); STRCPYS(libraryPathOpt, libraryPathOpt_sizeMax, "-Djava.library.path="); STRCATS(libraryPathOpt, libraryPathOpt_sizeMax, libraryPath); FREE(libraryPath); // ### create and set all JVM options ### static const size_t strOptions_sizeMax = 64; const char* strOptions[strOptions_sizeMax]; size_t op = 0; strOptions[op++] = classPathOpt; strOptions[op++] = libraryPathOpt; static const char* const JCPVAL = "-Djava.class.path="; const size_t JCPVAL_size = strlen(JCPVAL); static const char* const JLPVAL = "-Djava.library.path="; const size_t JLPVAL_size = strlen(JCPVAL); if (jvmProps != NULL) { // ### add string options from the JVM config file with property name "jvm.option.x" ### int i; for (i=0; i < jvmProps->size; ++i) { if (strcmp(jvmProps->keys[i], "jvm.option.x") == 0 || (useDebugOptions && (strcmp(jvmProps->keys[i], "jvm.option.debug.x") == 0))) { const char* const val = jvmProps->values[i]; const size_t val_size = strlen(val); // ignore "-Djava.class.path=..." // and "-Djava.library.path=..." options if (strncmp(val, JCPVAL, minSize(val_size, JCPVAL_size)) != 0 && strncmp(val, JLPVAL, minSize(val_size, JLPVAL_size)) != 0) { strOptions[op++] = val; } } } } else { // ### ... or set default ones, if the JVM config file was not found ### simpleLog_logL(SIMPLELOG_LEVEL_WARNING, "JVM: properties file ("JVM_PROPERTIES_FILE") not found; using default options."); strOptions[op++] = "-Xms4M"; strOptions[op++] = "-Xmx64M"; strOptions[op++] = "-Xss512K"; strOptions[op++] = "-Xoss400K"; #if defined DEBUG strOptions[op++] = "-Xcheck:jni"; strOptions[op++] = "-verbose:jni"; strOptions[op++] = "-XX:+UnlockDiagnosticVMOptions"; strOptions[op++] = "-XX:+LogVMOutput"; strOptions[op++] = "-Xdebug"; strOptions[op++] = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7777"; // disable JIT (required for debugging under the classical VM) strOptions[op++] = "-Djava.compiler=NONE"; // disable old JDB strOptions[op++] = "-Xnoagent"; #endif // defined DEBUG } const size_t options_size = op; vm_args->options = (struct JavaVMOption*) calloc(options_size, sizeof(struct JavaVMOption)); // fill strOptions into the JVM options simpleLog_logL(SIMPLELOG_LEVEL_FINE, "JVM: options:", options_size); char* dd_rw = callback->DataDirs_allocatePath(interfaceId, "", true, true, true, false); size_t i; jint nOptions = 0; for (i = 0; i < options_size; ++i) { char* tmpOptionString = util_allocStrReplaceStr(strOptions[i], "${home-dir}", dd_rw); // do not add empty options if (tmpOptionString != NULL) { if (strlen(tmpOptionString) > 0) { vm_args->options[nOptions].optionString = tmpOptionString; vm_args->options[nOptions].extraInfo = NULL; simpleLog_logL(SIMPLELOG_LEVEL_FINE, "JVM option %ul: %s", nOptions, tmpOptionString); nOptions++; } else { free(tmpOptionString); tmpOptionString = NULL; } } } vm_args->nOptions = nOptions; FREE(dd_rw); FREE(classPathOpt); FREE(libraryPathOpt); simpleLog_logL(SIMPLELOG_LEVEL_FINE, ""); return true; }