/*------------------------------------------------------------------------*/ BOOL HistoryFile::setDefaultFilename(void) { const ScilabPreferences* prefs = getScilabPreferences(); if (prefs != NULL && prefs->historyFile != NULL) { const char* prefHistoryFile = prefs->historyFile; this->setFilename(expandPathVariable((char*)prefHistoryFile)); return TRUE; } else { std::string filename(DEFAULT_HISTORY_FILE); char *SCIHOME = getSCIHOME(); if (SCIHOME) { std::string scihome(SCIHOME); std::string sep(DIR_SEPARATOR); this->setFilename(scihome + sep + filename); return TRUE; } else { this->setFilename(filename); return FALSE; } } }
/* ==================================================================== */ int getProxyValues(char **proxyHost, long *proxyPort, char **proxyUserPwd) { FILE * pFile; long lSize; char * buffer; size_t result; char *configPtr; char *osName; char *host, *user, *password, *userpwd; long port; int useproxy; char *tp, *field, *value, *eqptr; int eqpos, tplen; //construct ATOMS config file path configPtr = (char *)MALLOC(PATH_MAX * sizeof(char)); strcpy(configPtr, getSCIHOME()); osName = (char *)MALLOC(50 * sizeof(char)); strcpy(osName, getOSFullName()); if (strcmp(osName, "Windows") == 0) { char *osVer = (char *)MALLOC(50 * sizeof(char)); strcpy(osVer, getOSRelease()); if (strstr(osVer, "x64") != NULL) { strcat(configPtr, "/.atoms/x64/config"); } else { strcat(configPtr, "/.atoms/config"); } } else { strcat(configPtr, "/.atoms/config"); } wcfopen (pFile, configPtr , "rb" ); if (pFile == NULL) { // Scierror(999,"Could not open scicurl_config file\n"); return 0; } fseek (pFile , 0 , SEEK_END); lSize = ftell(pFile); rewind (pFile); // allocate memory to contain the whole file buffer = (char*)MALLOC((lSize + 1) * sizeof(char)); if (buffer == NULL) { return 0; } buffer[lSize] = '\0'; // copy the file into the buffer result = fread (buffer, 1, lSize, pFile); if (result != lSize) { Scierror(999, _("Failed to read the scicurl_config file '%s'.\n"), configPtr); return 0; } host = user = password = userpwd = NULL; useproxy = 0; tp = field = value = eqptr = NULL; eqpos = tplen = 0; // parse each line to extract variables tp = strtok(buffer, "\n"); while (tp != NULL) { eqptr = strrchr(tp, '='); tplen = (int)strlen(tp); if (eqptr == NULL) { Scierror(999, _("Improper syntax of scicurl_config file ('%s'), '=' not found %d:%s\n"), configPtr, tplen, tp); return 0; } eqpos = (int)(eqptr - tp); if (tplen <= eqpos + 1) { Scierror(999, _("Improper syntax of scicurl_config file ('%s'), after an '='\n"), configPtr); return 0; } if (tp[eqpos - 1] != ' ' || tp[eqpos + 1] != ' ') { Scierror(999, _("Improper syntax of scicurl_config file ('%s'), space before and after '=' expected\n"), configPtr); return 0; } //get field and value from each line field = (char *)MALLOC(sizeof(char) * (eqpos)); value = (char *)MALLOC(sizeof(char) * (strlen(tp) - eqpos - 1)); memcpy(field, tp, eqpos - 1); field[eqpos - 1] = '\0'; memcpy(value, tp + eqpos + 2, strlen(tp) - eqpos - 2); value[strlen(tp) - eqpos - 2] = '\0'; //check and read proxy variables if (strcmp(field, "useProxy") == 0) { if (strcmp(value, "False") == 0) { return 0; } if (strcmp(value, "True") == 0) { useproxy = 1; } } else if (strcmp(field, "proxyHost") == 0) { host = (char *)MALLOC((strlen(value) + 1) * sizeof(char)); strcpy(host, value); } else if (strcmp(field, "proxyPort") == 0) { port = strtol(value, NULL, 10); } else if (strcmp(field, "proxyUser") == 0) { user = (char *)MALLOC((strlen(value) + 1) * sizeof(char)); strcpy(user, value); } else if (strcmp(field, "proxyPassword") == 0) { password = (char *)MALLOC((strlen(value) + 1) * sizeof(char)); strcpy(password, value); } free(field); free(value); tp = strtok(NULL, "\n"); } // if proxy is set, update the parameters if (useproxy == 1) { // proxyUserPwd = "user:password" int userlen, passlen; userlen = passlen = 0; if (user != NULL) { userlen = (int)strlen(user); } if (password != NULL) { passlen = (int)strlen(user); } if (userlen + passlen != 0) { userpwd = (char *)MALLOC((userlen + passlen + 2) * sizeof(char)); strcpy(userpwd, user); strcat(userpwd, ":"); if (password != NULL) { strcat(userpwd, password); } } *proxyHost = host; *proxyPort = port; *proxyUserPwd = userpwd; } fclose(pFile); free(buffer); return useproxy; }