[2286] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * settings.cpp
|
---|
| 4 | * Copyright (C) 1996
|
---|
| 5 | *
|
---|
| 6 | * A component of the fnord webserver written by [email protected].
|
---|
| 7 | *
|
---|
| 8 | * Altered for use with the Greenstone digital library software by the
|
---|
| 9 | * New Zealand Digital Library Project at the University of Waikato,
|
---|
| 10 | * New Zealand.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or modify
|
---|
| 13 | * it under the terms of the GNU General Public License as published by
|
---|
| 14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | * (at your option) any later version.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful,
|
---|
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | * GNU General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, write to the Free Software
|
---|
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | *
|
---|
| 26 | *********************************************************************/
|
---|
| 27 |
|
---|
[1203] | 28 | #include "text_t.h"
|
---|
[4642] | 29 | #include "fileutil.h"
|
---|
[1203] | 30 |
|
---|
[611] | 31 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 32 | # include <ospace\std\fstream>
|
---|
| 33 | #elif defined(GSDL_USE_IOS_H)
|
---|
| 34 | # include <fstream.h>
|
---|
| 35 | #else
|
---|
| 36 | # include <fstream>
|
---|
| 37 | #endif
|
---|
| 38 |
|
---|
| 39 | #include <windows.h>
|
---|
| 40 | #include "httpsrv.h"
|
---|
| 41 | #include "settings.h"
|
---|
| 42 | #include "locate.h"
|
---|
| 43 | #include "resource.h"
|
---|
[902] | 44 | #include "cgiwrapper.h"
|
---|
[611] | 45 |
|
---|
| 46 | // library settings
|
---|
[902] | 47 | text_t gsdl_enterlib;
|
---|
| 48 | text_t gsdl_gsdlhome;
|
---|
[16310] | 49 | text_t gsdl_collecthome;
|
---|
[15625] | 50 | text_t gsdl_dbhome;
|
---|
[902] | 51 | text_t gsdl_collections;
|
---|
| 52 | colinfo_tmap gsdl_collectinfo;
|
---|
[611] | 53 |
|
---|
[902] | 54 | char gsdl_staticpages[MAX_FILENAME_SIZE];
|
---|
[611] | 55 |
|
---|
| 56 | // debug settings
|
---|
[902] | 57 | char gsdl_log_name[MAX_FILENAME_SIZE] = "c:\\gsdl.log";
|
---|
| 58 | int gsdl_keep_log = 0;
|
---|
| 59 | int gsdl_show_console = 0;
|
---|
[611] | 60 |
|
---|
| 61 | // general settings
|
---|
[902] | 62 | int gsdl_port_num = 80;
|
---|
[19210] | 63 | int gsdl_external_access = 0;
|
---|
[902] | 64 | int gsdl_auto_enter = 0;
|
---|
[10224] | 65 | int gsdl_browser = GS_DEFAULT;
|
---|
[902] | 66 | char gsdl_browser_exe[MAX_FILENAME_SIZE] = "";
|
---|
[4292] | 67 | text_t gsdl_url;
|
---|
[4642] | 68 | text_t gsdl_conffile;
|
---|
[4339] | 69 | int gsdl_start_browser = 1;
|
---|
[19015] | 70 | int gsdl_address_resolution_method = 2; // use localhost since users may switch between computers
|
---|
[20949] | 71 | text_t gsdl_host_IP;
|
---|
[19015] | 72 | // The resolution method was previously on 1: Get an IP, but don't resolve to a name
|
---|
[611] | 73 |
|
---|
| 74 | // private data
|
---|
| 75 |
|
---|
| 76 | // pathnames of the latest installed versions of netscape and
|
---|
| 77 | // internet explorer
|
---|
| 78 | static char netscape_exe[MAX_FILENAME_SIZE]="";
|
---|
| 79 | static char iexplore_exe[MAX_FILENAME_SIZE]="";
|
---|
| 80 |
|
---|
| 81 | // pathname of the default browser
|
---|
| 82 | static char default_browser_exe[MAX_FILENAME_SIZE]="";
|
---|
| 83 |
|
---|
| 84 | // whether netscape is needed (used in the settings dialog box)
|
---|
[902] | 85 | static int gsdl_netscapeneeded = 0;
|
---|
[611] | 86 |
|
---|
| 87 | static void remove_end_slashes(char *str) {
|
---|
[902] | 88 | int len = strlen (str);
|
---|
| 89 | while ((len > 0) && ((str[len-1] == '\\') || (str[len-1] == '/'))) {
|
---|
[9598] | 90 | --len;
|
---|
[902] | 91 | }
|
---|
| 92 | str[len] = '\0';
|
---|
[611] | 93 | }
|
---|
| 94 |
|
---|
[902] | 95 | static void remove_end_slashes (text_t &str) {
|
---|
| 96 | char *cstr = str.getcstr();
|
---|
| 97 | remove_end_slashes (cstr);
|
---|
| 98 | str = cstr;
|
---|
[9636] | 99 | delete []cstr;
|
---|
[902] | 100 | }
|
---|
[611] | 101 |
|
---|
| 102 | // returns 1 if successful, 0 otherwise
|
---|
| 103 | // checks for a file's existence
|
---|
| 104 | static int check_program_exe (char *path) {
|
---|
[902] | 105 | UINT curerrormode;
|
---|
| 106 | OFSTRUCT reOpenBuff;
|
---|
| 107 | int retvalue = 0;
|
---|
| 108 |
|
---|
| 109 | reOpenBuff.cBytes = sizeof (OFSTRUCT);
|
---|
| 110 |
|
---|
| 111 | curerrormode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
---|
| 112 | if (OpenFile(path, &reOpenBuff, OF_EXIST) != HFILE_ERROR) retvalue = 1;
|
---|
| 113 | SetErrorMode(curerrormode);
|
---|
| 114 |
|
---|
| 115 | return retvalue;
|
---|
[611] | 116 | }
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 | // returns 1 if successful, 0 otherwise
|
---|
| 120 | static int get_default_browser_path (char *providedhtmltype, char *path, int maxsize) {
|
---|
[902] | 121 | HKEY hk1, hk2;
|
---|
| 122 | char htmltype[256];
|
---|
| 123 | long size;
|
---|
| 124 | int retval = 0;
|
---|
| 125 |
|
---|
| 126 | htmltype[0] = '\0';
|
---|
| 127 | path[0] = '\0';
|
---|
| 128 |
|
---|
| 129 | // try and get information about the default browser from the
|
---|
| 130 | // registry
|
---|
| 131 |
|
---|
| 132 | if (providedhtmltype != NULL) strcpy (htmltype, providedhtmltype);
|
---|
| 133 |
|
---|
| 134 | else if (RegOpenKey(HKEY_CLASSES_ROOT, ".htm", &hk1) == ERROR_SUCCESS) {
|
---|
| 135 | size = 256;
|
---|
| 136 | RegQueryValue(hk1, NULL, htmltype, &size);
|
---|
| 137 | RegCloseKey(hk1);
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | if (RegOpenKey(HKEY_CLASSES_ROOT, htmltype, &hk1) == ERROR_SUCCESS) {
|
---|
| 141 | if (RegOpenKey(hk1, "shell\\open", &hk2) == ERROR_SUCCESS) {
|
---|
| 142 | // look for the command to start the browser
|
---|
| 143 | size = maxsize;
|
---|
| 144 | if (RegQueryValue(hk2,"command",path,&size) == ERROR_SUCCESS) {
|
---|
[611] | 145 | // strip all excess stuff off the command
|
---|
[902] | 146 | char endchar = ' ';
|
---|
| 147 | int i = 0, len = 0;
|
---|
| 148 | int state = 0; // 0=strip initial white-space and quotes, 1=grab path
|
---|
| 149 | while (path[i] != '\0') {
|
---|
| 150 | if (state == 0) {
|
---|
| 151 | if (path[i] == ' ') {
|
---|
| 152 | // do nothing
|
---|
| 153 | } else if (path[i] == '"') {
|
---|
| 154 | endchar = '"';
|
---|
| 155 | state = 1;
|
---|
| 156 | } else {
|
---|
| 157 | state = 1;
|
---|
| 158 | path[len] = path[i];
|
---|
[9598] | 159 | ++len;
|
---|
[902] | 160 | }
|
---|
| 161 | } else {
|
---|
| 162 | if (path[i] == endchar) break;
|
---|
| 163 | path[len] = path[i];
|
---|
[9598] | 164 | ++len;
|
---|
[902] | 165 | }
|
---|
[9598] | 166 | ++i;
|
---|
[611] | 167 | }
|
---|
[902] | 168 | path[len] = '\0';
|
---|
| 169 |
|
---|
| 170 | // check the resulting pathname
|
---|
| 171 | if (check_program_exe (path)) {
|
---|
| 172 | retval = 1; // succeeded
|
---|
| 173 | } else {
|
---|
| 174 | path[0] = '\0'; // failed (must have been deleted or something...)
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 | RegCloseKey(hk2);
|
---|
| 178 | }
|
---|
| 179 | RegCloseKey(hk1);
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | return retval;
|
---|
[611] | 183 | }
|
---|
| 184 |
|
---|
| 185 |
|
---|
| 186 | // returns 1 if successful, 0 otherwise
|
---|
| 187 | // note that appname should include .exe (e.g. netscape.exe)
|
---|
| 188 | static int registry_get_app_paths (char *appname, char *path, int maxsize) {
|
---|
[902] | 189 | HKEY hk1;
|
---|
| 190 | long size;
|
---|
| 191 | int retval = 0;
|
---|
| 192 |
|
---|
| 193 | path[0] = '\0';
|
---|
| 194 |
|
---|
| 195 | if (RegOpenKey(HKEY_LOCAL_MACHINE,
|
---|
| 196 | "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths",
|
---|
| 197 | &hk1) == ERROR_SUCCESS) {
|
---|
| 198 | size = maxsize;
|
---|
| 199 | if (RegQueryValue (hk1, appname, path, &size) == ERROR_SUCCESS &&
|
---|
| 200 | check_program_exe (path));
|
---|
| 201 | retval = 1;
|
---|
| 202 |
|
---|
| 203 | RegCloseKey(hk1);
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | return retval;
|
---|
[611] | 207 | }
|
---|
| 208 |
|
---|
| 209 | static void check_installed_browsers (int netscapeneeded) {
|
---|
[902] | 210 | netscape_exe[0] = '\0';
|
---|
| 211 | iexplore_exe[0] = '\0';
|
---|
| 212 | default_browser_exe[0] = '\0';
|
---|
| 213 |
|
---|
| 214 | // update the default browser information (if netscape isn't needed)
|
---|
| 215 | if (!netscapeneeded) {
|
---|
| 216 | get_default_browser_path (NULL, default_browser_exe, MAX_FILENAME_SIZE);
|
---|
| 217 | _strlwr (default_browser_exe);
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | // look for netscape
|
---|
| 221 |
|
---|
| 222 | // first look for netscape in the registry
|
---|
| 223 | if (!registry_get_app_paths("netscape.exe", netscape_exe, MAX_FILENAME_SIZE)) {
|
---|
| 224 | // next look for "NetscapeMarkup"
|
---|
| 225 | if (get_default_browser_path ("NetscapeMarkup", netscape_exe, MAX_FILENAME_SIZE)) {
|
---|
| 226 | _strlwr (netscape_exe);
|
---|
| 227 | if (!strstr (netscape_exe, "netscape.exe")) {
|
---|
[611] | 228 | netscape_exe[0] = '\0';
|
---|
[902] | 229 |
|
---|
| 230 | // next look for \netscape\netscape.exe
|
---|
| 231 |
|
---|
| 232 | // get drive letter of the windows directory
|
---|
| 233 | GetWindowsDirectory(netscape_exe, MAX_FILENAME_SIZE);
|
---|
| 234 | netscape_exe[1] = '\0';
|
---|
| 235 | strcat (netscape_exe, ":\\netscape\\netscape.exe");
|
---|
| 236 |
|
---|
| 237 | if (!check_program_exe (netscape_exe)) {
|
---|
| 238 | // lastly look for \netscape\program\netscape.exe
|
---|
| 239 | netscape_exe[1] = '\0';
|
---|
| 240 | strcat (netscape_exe, ":\\netscape\\program\\netscape.exe");
|
---|
| 241 |
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 | _strlwr (netscape_exe);
|
---|
| 247 | if ((strlen (netscape_exe) > 0) && !check_program_exe (netscape_exe)) {
|
---|
| 248 | netscape_exe[0] = '\0'; // couldn't find netscape
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | // look for internet explorer (if netscape isn't needed)
|
---|
| 252 |
|
---|
| 253 | // first look for iexplore in the registry
|
---|
| 254 | if (!netscapeneeded && !registry_get_app_paths("iexplore.exe",
|
---|
| 255 | iexplore_exe, MAX_FILENAME_SIZE)) {
|
---|
| 256 | // next look for "htmlfile"
|
---|
| 257 | if (get_default_browser_path ("htmlfile", iexplore_exe, MAX_FILENAME_SIZE)) {
|
---|
| 258 | _strlwr (iexplore_exe);
|
---|
| 259 | if (!strstr (iexplore_exe, "iexplore.exe")) {
|
---|
[611] | 260 | iexplore_exe[0] = '\0';
|
---|
[902] | 261 |
|
---|
| 262 | // next look for \iexplore\iexplore.exe
|
---|
| 263 |
|
---|
| 264 | // get drive letter of the windows directory
|
---|
| 265 | GetWindowsDirectory(iexplore_exe, MAX_FILENAME_SIZE);
|
---|
| 266 | iexplore_exe[1] = '\0';
|
---|
| 267 | strcat (iexplore_exe, ":\\iexplore\\iexplore.exe");
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
| 271 | _strlwr (iexplore_exe);
|
---|
| 272 | if ((strlen (iexplore_exe) > 0) && !check_program_exe (iexplore_exe)) {
|
---|
| 273 | iexplore_exe[0] = '\0'; // couldn't find internet explorer
|
---|
| 274 | }
|
---|
[611] | 275 | }
|
---|
| 276 |
|
---|
[4292] | 277 | void write_settings (const text_t url) {
|
---|
[902] | 278 |
|
---|
[4642] | 279 | if (gsdl_conffile.empty()) {
|
---|
| 280 | find_location();
|
---|
[18651] | 281 | gsdl_conffile = filename_cat(data_location, "llssite.cfg");
|
---|
[4642] | 282 | }
|
---|
| 283 |
|
---|
| 284 | char *conffile_c = gsdl_conffile.getcstr();
|
---|
| 285 | ofstream fout (conffile_c);
|
---|
[9636] | 286 | delete []conffile_c;
|
---|
[902] | 287 | if (fout) {
|
---|
| 288 |
|
---|
| 289 | outconvertclass text_t2ascii;
|
---|
[611] | 290 |
|
---|
[902] | 291 | // top (gsdl) level stuff
|
---|
| 292 | fout << "[gsdl]\n";
|
---|
[4292] | 293 |
|
---|
| 294 | if (!url.empty()) {
|
---|
[18651] | 295 | // url entry should only be written to llssite.cfg when the
|
---|
[4292] | 296 | // server is actually running, not when it's stopped (since we
|
---|
| 297 | // can't be sure what the url is at that stage). That is,
|
---|
| 298 | // write_settings() is called with the url argument set when the
|
---|
| 299 | // server first starts up, it's then called without url set as
|
---|
| 300 | // the server shuts down.
|
---|
| 301 | write_ini_line(fout, "url", url);
|
---|
| 302 | }
|
---|
| 303 |
|
---|
[902] | 304 | write_ini_line(fout, "enterlib", gsdl_enterlib);
|
---|
| 305 | write_ini_line(fout, "gsdlhome", gsdl_gsdlhome);
|
---|
[16310] | 306 | write_ini_line(fout, "collecthome", gsdl_collecthome);
|
---|
[15625] | 307 | write_ini_line(fout, "gdbmhome", gsdl_dbhome);
|
---|
[902] | 308 |
|
---|
| 309 | write_ini_line(fout, "logfilename", gsdl_log_name);
|
---|
| 310 | write_ini_line(fout, "keeplog", text_t(gsdl_keep_log));
|
---|
| 311 | write_ini_line(fout, "consolelog", text_t(gsdl_show_console));
|
---|
| 312 |
|
---|
| 313 | write_ini_line(fout, "portnumber", text_t(gsdl_port_num));
|
---|
[19210] | 314 | write_ini_line(fout, "externalaccess", text_t(gsdl_external_access));
|
---|
[902] | 315 | write_ini_line(fout, "autoenter", text_t(gsdl_auto_enter));
|
---|
| 316 | write_ini_line(fout, "browser", text_t(gsdl_browser));
|
---|
| 317 | write_ini_line(fout, "browserexe", gsdl_browser_exe);
|
---|
| 318 | write_ini_line(fout, "collections", gsdl_collections);
|
---|
[4339] | 319 | write_ini_line(fout, "start_browser", text_t(gsdl_start_browser));
|
---|
[10231] | 320 | write_ini_line(fout, "address_resolution_method", text_t(gsdl_address_resolution_method));
|
---|
[20949] | 321 | write_ini_line(fout, "hostIP", gsdl_host_IP);
|
---|
[10231] | 322 |
|
---|
[902] | 323 | // collection levels
|
---|
| 324 | colinfo_tmap::iterator here = gsdl_collectinfo.begin();
|
---|
| 325 | colinfo_tmap::iterator end = gsdl_collectinfo.end();
|
---|
| 326 | while (here != end) {
|
---|
| 327 | fout << text_t2ascii << "[" << (*here).first << "]\n";
|
---|
| 328 | if (!(*here).second.gsdl_gsdlhome.empty())
|
---|
| 329 | write_ini_line(fout, "gsdlhome", (*here).second.gsdl_gsdlhome);
|
---|
[16310] | 330 | if (!(*here).second.gsdl_collecthome.empty())
|
---|
| 331 | write_ini_line(fout, "collecthome", (*here).second.gsdl_collecthome);
|
---|
[15625] | 332 | if (!(*here).second.gsdl_dbhome.empty())
|
---|
| 333 | write_ini_line(fout, "gdbmhome", (*here).second.gsdl_dbhome);
|
---|
[902] | 334 |
|
---|
[9598] | 335 | ++here;
|
---|
[902] | 336 | }
|
---|
| 337 | fout.close();
|
---|
| 338 | }
|
---|
[611] | 339 | }
|
---|
| 340 |
|
---|
| 341 |
|
---|
| 342 | // browser_compare assumes that check_exe is in lowercase
|
---|
| 343 | static int browser_compare (char *browser_exe_path, char *check_exe) {
|
---|
[902] | 344 | char tmp_exe[MAX_FILENAME_SIZE];
|
---|
| 345 | strcpy (tmp_exe, browser_exe_path);
|
---|
| 346 | _strlwr (tmp_exe);
|
---|
| 347 | return (strstr (tmp_exe, check_exe) != NULL);
|
---|
[611] | 348 | }
|
---|
| 349 |
|
---|
| 350 | // This function assumes that check_installed_browsers
|
---|
| 351 | // has been recently called
|
---|
| 352 | // It also assumes that browser_exe is large
|
---|
| 353 | // enough to receive any path names to any browser
|
---|
| 354 | static void check_browser_settings (int &browser, char *browser_exe,
|
---|
[902] | 355 | int netscapeneeded) {
|
---|
| 356 | // sort out which browser to use
|
---|
| 357 | if ((browser == GS_NETSCAPE) && (netscape_exe[0] == '\0'))
|
---|
| 358 | browser = GS_IEXPLORE;
|
---|
| 359 | if ((browser == GS_IEXPLORE) && (netscapeneeded || (iexplore_exe[0] == '\0'))) {
|
---|
| 360 | if (netscape_exe[0] != '\0') browser = GS_NETSCAPE;
|
---|
| 361 | else browser = GS_OTHER;
|
---|
| 362 | }
|
---|
| 363 | if ((browser == GS_OTHER) && netscapeneeded &&
|
---|
| 364 | !browser_compare (browser_exe, "netscape.exe") && (netscape_exe[0] != '\0')) {
|
---|
| 365 | // this other browser isn't netscape and netscape is available
|
---|
| 366 | browser = GS_NETSCAPE;
|
---|
| 367 | }
|
---|
| 368 |
|
---|
| 369 |
|
---|
| 370 | // get the browser's executable
|
---|
[9526] | 371 | if (browser == GS_DEFAULT) {
|
---|
| 372 | strcpy (browser_exe, default_browser_exe);
|
---|
| 373 | } else if (browser == GS_NETSCAPE) {
|
---|
[902] | 374 | strcpy (browser_exe, netscape_exe);
|
---|
| 375 | } else if (browser == GS_IEXPLORE) {
|
---|
| 376 | strcpy (browser_exe, iexplore_exe);
|
---|
| 377 | } else {
|
---|
| 378 | browser = GS_OTHER;
|
---|
| 379 |
|
---|
| 380 | // if the browser should be netscape then check to
|
---|
| 381 | // make sure it is
|
---|
| 382 | if (netscapeneeded && !browser_compare (browser_exe, "netscape.exe")) {
|
---|
| 383 | // not netscape, set to no browser
|
---|
| 384 | browser_exe[0] = '\0';
|
---|
| 385 | }
|
---|
| 386 | }
|
---|
[611] | 387 | }
|
---|
| 388 |
|
---|
| 389 |
|
---|
| 390 | static void revert_defaults (int netscapeneeded) {
|
---|
[902] | 391 | find_location();
|
---|
| 392 |
|
---|
| 393 | // library settings
|
---|
[2343] | 394 | gsdl_enterlib = "/gsdl";
|
---|
[902] | 395 | gsdl_gsdlhome = data_location;
|
---|
[16310] | 396 | gsdl_collecthome = filename_cat(data_location,"collect");
|
---|
[15625] | 397 | gsdl_dbhome = data_location;
|
---|
[902] | 398 |
|
---|
| 399 | // debug settings
|
---|
| 400 | gsdl_keep_log = 0;
|
---|
[18018] | 401 | char *cstr_value = filename_cat(data_location,"gsdl.log").getcstr();
|
---|
| 402 | strcpy (gsdl_log_name, cstr_value); //strcpy (gsdl_log_name, "c:\\gsdl.log");
|
---|
| 403 | delete []cstr_value;
|
---|
[902] | 404 | gsdl_show_console = 0;
|
---|
| 405 |
|
---|
| 406 | // general settings
|
---|
| 407 | gsdl_port_num = 80;
|
---|
[19210] | 408 | gsdl_external_access = 0;
|
---|
[902] | 409 | gsdl_auto_enter = 0;
|
---|
[4339] | 410 | gsdl_start_browser = 1;
|
---|
| 411 |
|
---|
[902] | 412 | check_installed_browsers (netscapeneeded);
|
---|
[10224] | 413 | gsdl_browser = GS_DEFAULT;
|
---|
[902] | 414 | strcpy (gsdl_browser_exe, default_browser_exe);
|
---|
| 415 | check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
|
---|
[611] | 416 | }
|
---|
| 417 |
|
---|
| 418 | void read_settings (int netscapeneeded) {
|
---|
[902] | 419 |
|
---|
[4642] | 420 | if (gsdl_conffile.empty()) {
|
---|
| 421 | find_location();
|
---|
[18651] | 422 | gsdl_conffile = filename_cat(data_location, "llssite.cfg");
|
---|
[4642] | 423 | }
|
---|
[902] | 424 |
|
---|
| 425 | // set up defaults
|
---|
| 426 | revert_defaults (netscapeneeded);
|
---|
| 427 |
|
---|
| 428 | text_t key, value, section;
|
---|
| 429 | char *cstr_value;
|
---|
[4642] | 430 | char *conffile_c = gsdl_conffile.getcstr();
|
---|
[1203] | 431 | #if defined (GSDL_USE_IOS_H)
|
---|
[4642] | 432 | ifstream conf (conffile_c, ios::nocreate);
|
---|
[1203] | 433 | #else
|
---|
[4642] | 434 | ifstream conf (conffile_c);
|
---|
[1203] | 435 | #endif
|
---|
[9636] | 436 | delete []conffile_c;
|
---|
[902] | 437 | if (conf) {
|
---|
| 438 | while (read_ini_line(conf, key, value) >= 0) {
|
---|
[1739] | 439 | if (key.empty()) continue;
|
---|
[22770] | 440 | if (value.empty() && starts_with(key, "[") && ends_with(key, "]")) {
|
---|
[902] | 441 | // should be a section title
|
---|
| 442 | section = key;
|
---|
| 443 | // remove square brackets
|
---|
| 444 | section.erase (section.begin());
|
---|
| 445 | section.erase (section.end()-1);
|
---|
[611] | 446 |
|
---|
[902] | 447 | } else {
|
---|
[611] | 448 |
|
---|
[902] | 449 | cstr_value = value.getcstr ();
|
---|
| 450 |
|
---|
| 451 | if (section == "gsdl") {
|
---|
[611] | 452 |
|
---|
[902] | 453 | if (key == "enterlib") {
|
---|
| 454 | gsdl_enterlib = value;
|
---|
| 455 |
|
---|
| 456 | // 'logfilename' should occur in the configuration file
|
---|
| 457 | // before 'keeplog'
|
---|
| 458 | } else if (key == "logfilename") {
|
---|
| 459 | strcpy (gsdl_log_name, cstr_value);
|
---|
| 460 |
|
---|
| 461 | } else if (key == "keeplog") {
|
---|
| 462 | gsdl_keep_log = value.getint();
|
---|
| 463 | if (gsdl_keep_log) open_log_file();
|
---|
| 464 |
|
---|
| 465 | } else if (key == "consolelog") {
|
---|
| 466 | if (value.getint()) activate_console();
|
---|
| 467 | else deactivate_console();
|
---|
| 468 |
|
---|
| 469 | } else if (key == "portnumber") {
|
---|
| 470 | gsdl_port_num = value.getint();
|
---|
[19210] | 471 |
|
---|
| 472 | } else if (key == "externalaccess") {
|
---|
| 473 | gsdl_external_access = value.getint();
|
---|
[902] | 474 |
|
---|
| 475 | } else if (key == "autoenter") {
|
---|
| 476 | gsdl_auto_enter = value.getint();
|
---|
[4339] | 477 |
|
---|
| 478 | } else if (key == "start_browser") {
|
---|
| 479 | gsdl_start_browser = value.getint();
|
---|
[902] | 480 |
|
---|
| 481 | } else if (key == "browser") {
|
---|
| 482 | gsdl_browser = value.getint();
|
---|
| 483 |
|
---|
| 484 | } else if (key == "browserexe") {
|
---|
| 485 | strcpy (gsdl_browser_exe, cstr_value);
|
---|
[611] | 486 |
|
---|
[10231] | 487 | } else if (key == "address_resolution_method") {
|
---|
| 488 | gsdl_address_resolution_method = value.getint();
|
---|
| 489 |
|
---|
[902] | 490 | } else if (key == "collections") {
|
---|
| 491 | gsdl_collections = value;
|
---|
[16310] | 492 | }
|
---|
[15625] | 493 | // gsdlhome must occur in file before dbhome
|
---|
[16310] | 494 | else if (key == "gsdlhome") {
|
---|
[902] | 495 | gsdl_gsdlhome = value;
|
---|
[16310] | 496 | gsdl_collecthome = filename_cat(value,"collect");
|
---|
| 497 | gsdl_dbhome = value;
|
---|
| 498 | }
|
---|
| 499 | else if (key == "collecthome") {
|
---|
| 500 | gsdl_collecthome = value;
|
---|
| 501 | }
|
---|
| 502 | else if (key == "gdbmhome") {
|
---|
[15625] | 503 | gsdl_dbhome = value;
|
---|
[902] | 504 | }
|
---|
| 505 | } else {
|
---|
| 506 |
|
---|
[15625] | 507 | // gsdlhome must occur in file before dbhome
|
---|
[902] | 508 | if (key == "gsdlhome") {
|
---|
| 509 | gsdl_collectinfo[section].gsdl_gsdlhome = value;
|
---|
[17987] | 510 | gsdl_collectinfo[section].gsdl_collecthome = filename_cat(value,"collect");
|
---|
[15625] | 511 | gsdl_collectinfo[section].gsdl_dbhome = value;
|
---|
[16310] | 512 | }
|
---|
| 513 | else if (key == "collecthome") {
|
---|
| 514 | gsdl_collectinfo[section].gsdl_collecthome = value;
|
---|
| 515 | }
|
---|
| 516 | else if (key == "gdbmhome") {
|
---|
[15625] | 517 | gsdl_collectinfo[section].gsdl_dbhome = value;
|
---|
[902] | 518 | }
|
---|
[611] | 519 | }
|
---|
[9636] | 520 | delete []cstr_value;
|
---|
[902] | 521 | }
|
---|
| 522 | }
|
---|
| 523 | conf.close();
|
---|
| 524 | }
|
---|
| 525 |
|
---|
| 526 | // check the homes to make sure they don't contain
|
---|
| 527 | // extra slashes at the end
|
---|
| 528 | remove_end_slashes (gsdl_gsdlhome);
|
---|
[16310] | 529 | remove_end_slashes (gsdl_collecthome);
|
---|
[15625] | 530 | remove_end_slashes (gsdl_dbhome);
|
---|
[902] | 531 | colinfo_tmap::iterator here = gsdl_collectinfo.begin();
|
---|
| 532 | colinfo_tmap::iterator end = gsdl_collectinfo.end();
|
---|
| 533 | while (here != end) {
|
---|
| 534 | remove_end_slashes ((*here).second.gsdl_gsdlhome);
|
---|
[16310] | 535 | remove_end_slashes ((*here).second.gsdl_collecthome);
|
---|
[15625] | 536 | remove_end_slashes ((*here).second.gsdl_dbhome);
|
---|
[9598] | 537 | ++here;
|
---|
[902] | 538 | }
|
---|
[611] | 539 |
|
---|
[902] | 540 | // check the browser settings
|
---|
| 541 | check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
|
---|
[611] | 542 | }
|
---|
| 543 |
|
---|
[902] | 544 | void gsdl_check_browser_settings (int netscapeneeded) {
|
---|
| 545 | check_installed_browsers (netscapeneeded);
|
---|
| 546 | check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
|
---|
[611] | 547 | }
|
---|
| 548 |
|
---|
| 549 |
|
---|
| 550 | static void dialog_update_enables (HWND hwndDlg) {
|
---|
[902] | 551 | int res;
|
---|
| 552 |
|
---|
| 553 | // if they want to use another browser, they should be able
|
---|
| 554 | // edit its filename
|
---|
| 555 | res = SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER, BM_GETCHECK,0,0);
|
---|
| 556 | SendDlgItemMessage(hwndDlg, ID_OTHER_NAME, WM_ENABLE, (res == 1), 0);
|
---|
[611] | 557 | }
|
---|
| 558 |
|
---|
| 559 |
|
---|
| 560 | static int read_dialog_browser_field (HWND hwndDlg) {
|
---|
[9526] | 561 | if (SendDlgItemMessage(hwndDlg, ID_RADIO_DEFAULT,
|
---|
| 562 | BM_GETCHECK, 0, 0) == 1) return GS_DEFAULT;
|
---|
[902] | 563 | if (SendDlgItemMessage(hwndDlg, ID_RADIO_NETSCAPE,
|
---|
| 564 | BM_GETCHECK, 0, 0) == 1) return GS_NETSCAPE;
|
---|
| 565 | if (SendDlgItemMessage(hwndDlg, ID_RADIO_IE,
|
---|
| 566 | BM_GETCHECK, 0, 0) == 1) return GS_IEXPLORE;
|
---|
| 567 | if (SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER,
|
---|
| 568 | BM_GETCHECK, 0, 0) == 1) return GS_OTHER;
|
---|
| 569 | return GS_NETSCAPE;
|
---|
[611] | 570 | }
|
---|
| 571 |
|
---|
| 572 |
|
---|
| 573 | static void set_dialog_browser_field (HWND hwndDlg, int browser, char *othername) {
|
---|
[9526] | 574 | // if we are trying to set the browser to default, netscape or
|
---|
[902] | 575 | // internet explorer and we can't find them, set the browser
|
---|
| 576 | // to 'other'
|
---|
[9526] | 577 | if ((browser == GS_DEFAULT) && (default_browser_exe[0] == '\0'))
|
---|
| 578 | browser = GS_NETSCAPE;
|
---|
[902] | 579 | if ((browser == GS_NETSCAPE) && (netscape_exe[0] == '\0'))
|
---|
| 580 | browser = GS_IEXPLORE;
|
---|
| 581 | if ((browser == GS_IEXPLORE) && (iexplore_exe[0] == '\0')) {
|
---|
| 582 | if (netscape_exe[0] != '\0') browser = GS_NETSCAPE;
|
---|
| 583 | else browser = GS_OTHER;
|
---|
| 584 | }
|
---|
| 585 |
|
---|
| 586 | // update the radio buttons
|
---|
[9526] | 587 | SendDlgItemMessage(hwndDlg, ID_RADIO_DEFAULT, BM_SETCHECK,
|
---|
| 588 | (browser == GS_DEFAULT) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
[902] | 589 | SendDlgItemMessage(hwndDlg, ID_RADIO_NETSCAPE, BM_SETCHECK,
|
---|
| 590 | (browser == GS_NETSCAPE) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
| 591 | SendDlgItemMessage(hwndDlg, ID_RADIO_IE, BM_SETCHECK,
|
---|
| 592 | (browser == GS_IEXPLORE) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
| 593 | SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER, BM_SETCHECK,
|
---|
| 594 | (browser == GS_OTHER) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
| 595 |
|
---|
| 596 | // update the other name field
|
---|
[9526] | 597 | if (browser == GS_DEFAULT) {
|
---|
| 598 | SetDlgItemText(hwndDlg, ID_OTHER_NAME, default_browser_exe);
|
---|
| 599 | } else if (browser == GS_NETSCAPE) {
|
---|
[902] | 600 | SetDlgItemText(hwndDlg, ID_OTHER_NAME, netscape_exe);
|
---|
| 601 | } else if (browser == GS_IEXPLORE) {
|
---|
| 602 | SetDlgItemText(hwndDlg, ID_OTHER_NAME, iexplore_exe);
|
---|
| 603 | } else if (othername != NULL) {
|
---|
| 604 | SetDlgItemText(hwndDlg, ID_OTHER_NAME, othername);
|
---|
| 605 | }
|
---|
[611] | 606 | }
|
---|
| 607 |
|
---|
| 608 |
|
---|
| 609 | static void read_browser_exe_field (HWND hwndDlg, char *filename, int maxsize) {
|
---|
[902] | 610 | filename[0] = '\0';
|
---|
| 611 | GetDlgItemText(hwndDlg, ID_OTHER_NAME, filename, maxsize);
|
---|
[611] | 612 | }
|
---|
| 613 |
|
---|
[11096] | 614 | static int read_address_resolution_field (HWND hwndDlg) {
|
---|
| 615 | if (SendDlgItemMessage(hwndDlg, ID_ARM_NAME,
|
---|
| 616 | BM_GETCHECK, 0, 0) == 1) return ARM_NAME;
|
---|
| 617 | if (SendDlgItemMessage(hwndDlg, ID_ARM_IP,
|
---|
| 618 | BM_GETCHECK, 0, 0) == 1) return ARM_IP;
|
---|
[11319] | 619 | if (SendDlgItemMessage(hwndDlg, ID_ARM_LOCALHOST,
|
---|
| 620 | BM_GETCHECK, 0, 0) == 1) return ARM_LOCALHOST;
|
---|
[11096] | 621 | if (SendDlgItemMessage(hwndDlg, ID_ARM_127_0_0_1,
|
---|
| 622 | BM_GETCHECK, 0, 0) == 1) return ARM_127_0_0_1;
|
---|
| 623 | return ARM_NAME;
|
---|
| 624 | }
|
---|
[611] | 625 |
|
---|
[11096] | 626 | static void set_address_resolution_field (HWND hwndDlg,
|
---|
| 627 | int address_res_method) {
|
---|
| 628 | // update the radio buttons
|
---|
| 629 | SendDlgItemMessage(hwndDlg, ID_ARM_NAME, BM_SETCHECK,
|
---|
| 630 | (address_res_method == ARM_NAME) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
| 631 | SendDlgItemMessage(hwndDlg, ID_ARM_IP, BM_SETCHECK,
|
---|
| 632 | (address_res_method == ARM_IP) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
[11319] | 633 | SendDlgItemMessage(hwndDlg, ID_ARM_LOCALHOST, BM_SETCHECK,
|
---|
| 634 | (address_res_method == ARM_LOCALHOST) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
[11096] | 635 | SendDlgItemMessage(hwndDlg, ID_ARM_127_0_0_1, BM_SETCHECK,
|
---|
| 636 | (address_res_method == ARM_127_0_0_1) ? BST_CHECKED : BST_UNCHECKED, 0);
|
---|
| 637 |
|
---|
| 638 | }
|
---|
| 639 |
|
---|
[611] | 640 | static void read_dialog_fields (HWND hwndDlg) {
|
---|
[902] | 641 | int res; BOOL bres;
|
---|
| 642 |
|
---|
| 643 | // port number
|
---|
| 644 | gsdl_port_num = GetDlgItemInt(hwndDlg, SERVER_PORT_EDIT_BOX, &bres, 0);
|
---|
| 645 | if (!bres) gsdl_port_num = 80;
|
---|
[19210] | 646 |
|
---|
| 647 | // whether to allow external access or not
|
---|
| 648 | res = SendDlgItemMessage(hwndDlg, ID_EXTERNAL_ACCESS, BM_GETCHECK, 0, 0);
|
---|
| 649 | gsdl_external_access = (res == 1);
|
---|
| 650 |
|
---|
[902] | 651 | // whether to enter the library automatically on startup
|
---|
| 652 | res = SendDlgItemMessage(hwndDlg, ID_AUTO_ENTER_LIBRARY, BM_GETCHECK, 0, 0);
|
---|
| 653 | gsdl_auto_enter = (res == 1);
|
---|
[19210] | 654 |
|
---|
[902] | 655 | // which browser to use
|
---|
| 656 | gsdl_browser = read_dialog_browser_field (hwndDlg);
|
---|
| 657 |
|
---|
| 658 | // find out where the browser exe lives
|
---|
| 659 | read_browser_exe_field (hwndDlg, gsdl_browser_exe, MAX_FILENAME_SIZE);
|
---|
[11096] | 660 |
|
---|
| 661 | // which address resolution method
|
---|
| 662 | gsdl_address_resolution_method = read_address_resolution_field(hwndDlg);
|
---|
[611] | 663 | }
|
---|
| 664 |
|
---|
| 665 |
|
---|
| 666 |
|
---|
| 667 |
|
---|
| 668 | static BOOL CALLBACK dialog_proc(HWND hwndDlg, UINT uMsg,
|
---|
[902] | 669 | WPARAM wParam,LPARAM lParam) {
|
---|
| 670 | int wNotifyCode = HIWORD(wParam);
|
---|
| 671 | int wID = LOWORD(wParam);
|
---|
| 672 | char *filefilter = "Program Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0\0";
|
---|
| 673 | OPENFILENAME fname;
|
---|
| 674 | char filename[MAX_FILENAME_SIZE];
|
---|
| 675 |
|
---|
| 676 | switch (uMsg) {
|
---|
| 677 | case WM_INITDIALOG:
|
---|
| 678 | // set current values
|
---|
| 679 | SetDlgItemInt(hwndDlg, SERVER_PORT_EDIT_BOX, gsdl_port_num, FALSE);
|
---|
[19210] | 680 | SendDlgItemMessage(hwndDlg, ID_EXTERNAL_ACCESS, BM_SETCHECK,
|
---|
| 681 | gsdl_external_access ? 1 : 0, 0);
|
---|
[902] | 682 | SendDlgItemMessage(hwndDlg, ID_AUTO_ENTER_LIBRARY, BM_SETCHECK,
|
---|
| 683 | gsdl_auto_enter ? 1 : 0, 0);
|
---|
| 684 | set_dialog_browser_field (hwndDlg, gsdl_browser, gsdl_browser_exe);
|
---|
[11096] | 685 | set_address_resolution_field(hwndDlg, gsdl_address_resolution_method);
|
---|
[902] | 686 | dialog_update_enables(hwndDlg);
|
---|
| 687 |
|
---|
[9526] | 688 | // make sure that the default browser, netscape and internet explorer
|
---|
[902] | 689 | // radio buttons are only enabled if they could be found
|
---|
[9526] | 690 | if (default_browser_exe[0] == '\0')
|
---|
| 691 | EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_DEFAULT), FALSE);
|
---|
[902] | 692 | if (netscape_exe[0] == '\0')
|
---|
| 693 | EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_NETSCAPE), FALSE);
|
---|
| 694 | if (iexplore_exe[0] == '\0')
|
---|
| 695 | EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_IE), FALSE);
|
---|
| 696 |
|
---|
| 697 | return 1;
|
---|
| 698 |
|
---|
| 699 | case WM_COMMAND:
|
---|
| 700 | if (wNotifyCode == BN_CLICKED) {
|
---|
| 701 | switch (wID) {
|
---|
| 702 | case ID_CANCEL_BUTTON:
|
---|
| 703 | EndDialog(hwndDlg, 0);
|
---|
| 704 | return 1;
|
---|
| 705 |
|
---|
| 706 | case ID_OK_BUTTON:
|
---|
| 707 | // check to make sure we can find the browser
|
---|
| 708 | filename[0] = '\0';
|
---|
| 709 | read_browser_exe_field (hwndDlg, filename, MAX_FILENAME_SIZE);
|
---|
| 710 | if (check_program_exe (filename)) {
|
---|
| 711 | // the file exists
|
---|
| 712 | // if netscape is needed, make sure the browser is netscape
|
---|
| 713 | _strlwr(filename);
|
---|
| 714 | if (!gsdl_netscapeneeded || strstr (filename, "netscape.exe") != NULL) {
|
---|
| 715 | // everything is ok
|
---|
| 716 | read_dialog_fields(hwndDlg);
|
---|
| 717 | EndDialog(hwndDlg, 1);
|
---|
| 718 |
|
---|
| 719 | } else {
|
---|
| 720 | // message: must use netscape with this version
|
---|
| 721 | MessageBox(hwndDlg,
|
---|
| 722 | "You are using this software on a machine which\n"
|
---|
| 723 | "currently does not have a working TCP/IP network layer.\n"
|
---|
| 724 | "To allow the Greenstone Digital Library software to use\n"
|
---|
| 725 | "its own TCP/IP network layer you must use a Netscape\n"
|
---|
[2345] | 726 | "web browser.",
|
---|
[902] | 727 | "Greenstone Digital Library Software",
|
---|
| 728 | MB_OK|MB_APPLMODAL);
|
---|
| 729 | }
|
---|
| 730 | } else {
|
---|
| 731 | // message: the file did not exist
|
---|
| 732 | MessageBox(hwndDlg,
|
---|
[2345] | 733 | "Could not find the selected browser. You must have a\n"
|
---|
| 734 | "web browser installed to use the Greenstone Digital\n"
|
---|
| 735 | "Library software.",
|
---|
[902] | 736 | "Greenstone Digital Library Software",
|
---|
| 737 | MB_OK|MB_APPLMODAL);
|
---|
[611] | 738 | }
|
---|
[902] | 739 | return 1;
|
---|
[9526] | 740 |
|
---|
| 741 | case ID_RADIO_DEFAULT:
|
---|
| 742 | set_dialog_browser_field (hwndDlg, GS_DEFAULT, NULL);
|
---|
| 743 | dialog_update_enables(hwndDlg);
|
---|
| 744 | return 1;
|
---|
[902] | 745 |
|
---|
| 746 | case ID_RADIO_NETSCAPE:
|
---|
| 747 | set_dialog_browser_field (hwndDlg, GS_NETSCAPE, NULL);
|
---|
| 748 | dialog_update_enables(hwndDlg);
|
---|
| 749 | return 1;
|
---|
| 750 |
|
---|
| 751 | case ID_RADIO_IE:
|
---|
| 752 | set_dialog_browser_field (hwndDlg, GS_IEXPLORE, NULL);
|
---|
| 753 | dialog_update_enables(hwndDlg);
|
---|
| 754 | return 1;
|
---|
| 755 |
|
---|
| 756 | case ID_RADIO_OTHER:
|
---|
| 757 | set_dialog_browser_field (hwndDlg, GS_OTHER, NULL);
|
---|
| 758 | dialog_update_enables(hwndDlg);
|
---|
| 759 | return 1;
|
---|
| 760 |
|
---|
| 761 | case ID_BROWSE_BUTTON:
|
---|
| 762 | filename[0] = '\0';
|
---|
| 763 | memset(&fname, 0, sizeof(OPENFILENAME));
|
---|
| 764 | fname.lStructSize = sizeof(OPENFILENAME);
|
---|
| 765 | fname.hwndOwner = hwndDlg;
|
---|
| 766 | fname.hInstance = NULL;
|
---|
| 767 | fname.lpstrFilter = filefilter;
|
---|
| 768 | fname.lpstrCustomFilter = NULL;
|
---|
| 769 | fname.nMaxCustFilter = 0;
|
---|
| 770 | fname.nFilterIndex = 1;
|
---|
| 771 | fname.lpstrFile = filename;
|
---|
| 772 | fname.nMaxFile = MAX_FILENAME_SIZE-1;
|
---|
| 773 | fname.lpstrFileTitle = NULL;
|
---|
| 774 | fname.nMaxFileTitle = 0;
|
---|
| 775 | fname.lpstrInitialDir = NULL;
|
---|
| 776 | fname.lpstrTitle = "Choose Web Browser";
|
---|
| 777 | fname.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
|
---|
| 778 |
|
---|
| 779 | if(GetOpenFileName(&fname)) {
|
---|
| 780 | set_dialog_browser_field (hwndDlg, GS_OTHER, filename);
|
---|
| 781 | dialog_update_enables(hwndDlg);
|
---|
| 782 | }
|
---|
| 783 | return 1;
|
---|
[11096] | 784 |
|
---|
| 785 | case ID_ARM_NAME:
|
---|
| 786 | set_address_resolution_field (hwndDlg, ARM_NAME);
|
---|
| 787 | dialog_update_enables(hwndDlg);
|
---|
| 788 | return 1;
|
---|
| 789 | case ID_ARM_IP:
|
---|
| 790 | set_address_resolution_field (hwndDlg, ARM_IP);
|
---|
| 791 | dialog_update_enables(hwndDlg);
|
---|
| 792 | return 1;
|
---|
[11319] | 793 | case ID_ARM_LOCALHOST:
|
---|
| 794 | set_address_resolution_field (hwndDlg, ARM_LOCALHOST);
|
---|
| 795 | dialog_update_enables(hwndDlg);
|
---|
| 796 | return 1;
|
---|
[11096] | 797 | case ID_ARM_127_0_0_1:
|
---|
| 798 | set_address_resolution_field (hwndDlg, ARM_127_0_0_1);
|
---|
| 799 | dialog_update_enables(hwndDlg);
|
---|
| 800 | return 1;
|
---|
| 801 |
|
---|
[902] | 802 | }
|
---|
| 803 | }
|
---|
| 804 | return 0;
|
---|
| 805 |
|
---|
| 806 | case WM_CLOSE:
|
---|
| 807 | case WM_DESTROY:
|
---|
| 808 | EndDialog(hwndDlg, 0);
|
---|
| 809 | return 1;
|
---|
| 810 | }
|
---|
| 811 |
|
---|
| 812 | return 0;
|
---|
[611] | 813 | }
|
---|
| 814 |
|
---|
| 815 | static void dialog_debug_update_enables (HWND hwndDlg) {
|
---|
[902] | 816 | int res;
|
---|
| 817 |
|
---|
| 818 | // if they want a log of program use allow them to
|
---|
| 819 | // edit its filename
|
---|
| 820 | res = SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_GETCHECK,0,0);
|
---|
| 821 | SendDlgItemMessage(hwndDlg, LOG_NAME_BOX, WM_ENABLE, (res == 1), 0);
|
---|
[611] | 822 | }
|
---|
| 823 |
|
---|
| 824 |
|
---|
| 825 | static void read_dialog_debug_fields (HWND hwndDlg) {
|
---|
[902] | 826 | int res;
|
---|
| 827 |
|
---|
| 828 | // whether to log program use
|
---|
| 829 | res = SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_GETCHECK,0,0);
|
---|
| 830 | gsdl_keep_log = (res == 1);
|
---|
| 831 |
|
---|
| 832 | // log filename
|
---|
| 833 | res = SendDlgItemMessage(hwndDlg, LOG_NAME_BOX, EM_GETMODIFY,0,0);
|
---|
| 834 | if (res != 0) {
|
---|
| 835 | res = GetDlgItemText(hwndDlg, LOG_NAME_BOX, gsdl_log_name, MAX_FILENAME_SIZE);
|
---|
| 836 | }
|
---|
| 837 |
|
---|
| 838 | // whether to display log information on console
|
---|
| 839 | res = SendDlgItemMessage(hwndDlg, CONSOLE_CHECK, BM_GETCHECK,0,0);
|
---|
| 840 | gsdl_show_console = (res == 1);
|
---|
[611] | 841 | }
|
---|
| 842 |
|
---|
| 843 |
|
---|
| 844 | static BOOL CALLBACK dialog_debug_proc(HWND hwndDlg, UINT uMsg,
|
---|
[902] | 845 | WPARAM wParam,LPARAM lParam) {
|
---|
| 846 | int wNotifyCode = HIWORD(wParam);
|
---|
| 847 | int wID = LOWORD(wParam);
|
---|
| 848 |
|
---|
| 849 | switch (uMsg) {
|
---|
| 850 | case WM_INITDIALOG:
|
---|
| 851 | // set current values
|
---|
| 852 | SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_SETCHECK,
|
---|
| 853 | gsdl_keep_log ? 1 : 0, 0);
|
---|
| 854 | SetDlgItemText(hwndDlg, LOG_NAME_BOX, gsdl_log_name);
|
---|
| 855 | SendDlgItemMessage(hwndDlg, CONSOLE_CHECK, BM_SETCHECK,
|
---|
| 856 | gsdl_show_console ? 1 : 0, 0);
|
---|
| 857 | dialog_debug_update_enables(hwndDlg);
|
---|
| 858 | return 1;
|
---|
| 859 |
|
---|
| 860 | case WM_COMMAND:
|
---|
| 861 | if (wNotifyCode == BN_CLICKED) {
|
---|
| 862 | switch (wID) {
|
---|
| 863 | case ID_CANCEL_BUTTON:
|
---|
| 864 | EndDialog(hwndDlg, 0);
|
---|
| 865 | return 1;
|
---|
| 866 |
|
---|
| 867 | case ID_OK_BUTTON:
|
---|
| 868 | read_dialog_debug_fields(hwndDlg);
|
---|
| 869 | EndDialog(hwndDlg, 1);
|
---|
| 870 | return 1;
|
---|
| 871 |
|
---|
| 872 | case LOG_CHECK:
|
---|
| 873 | dialog_debug_update_enables(hwndDlg);
|
---|
| 874 | return 1;
|
---|
| 875 | }
|
---|
| 876 | }
|
---|
| 877 | return 0;
|
---|
| 878 |
|
---|
| 879 | case WM_CLOSE:
|
---|
| 880 | case WM_DESTROY:
|
---|
| 881 | EndDialog(hwndDlg, 0);
|
---|
| 882 | return 1;
|
---|
| 883 | }
|
---|
| 884 |
|
---|
| 885 | return 0;
|
---|
[611] | 886 | }
|
---|
| 887 |
|
---|
| 888 |
|
---|
| 889 | void Settings_Dialog(HWND window, int netscapeneeded)
|
---|
| 890 | {
|
---|
[902] | 891 | int old_gsdl_show_console = gsdl_show_console;
|
---|
| 892 | int old_gsdl_port_num = gsdl_port_num;
|
---|
[19210] | 893 | int old_gsdl_external_access = gsdl_external_access;
|
---|
[902] | 894 |
|
---|
| 895 | int res = 0;
|
---|
| 896 |
|
---|
| 897 | gsdl_netscapeneeded = netscapeneeded;
|
---|
| 898 |
|
---|
| 899 | if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) &&
|
---|
| 900 | (GetAsyncKeyState(VkKeyScan('d')) & 0x8000)) {
|
---|
| 901 | // control-D was pressed, display debug settings
|
---|
| 902 | // dialog box
|
---|
| 903 | res = DialogBox (NULL, MAKEINTRESOURCE(COMMS_DIALOG_DEBUG),
|
---|
| 904 | window, (DLGPROC)dialog_debug_proc);
|
---|
| 905 |
|
---|
| 906 | if (res == 1) {
|
---|
| 907 | // only update if exited via the OK button
|
---|
| 908 | if (gsdl_keep_log) open_log_file();
|
---|
| 909 | else close_log_file();
|
---|
| 910 |
|
---|
| 911 | // turn the console on/off if we need to
|
---|
| 912 | if (gsdl_show_console != old_gsdl_show_console) {
|
---|
| 913 | if (gsdl_show_console) activate_console ();
|
---|
| 914 | else deactivate_console ();
|
---|
| 915 | }
|
---|
| 916 | }
|
---|
| 917 |
|
---|
| 918 | } else {
|
---|
| 919 | // display normal settings dialog box
|
---|
| 920 |
|
---|
| 921 | // make sure everything is up-to-date
|
---|
| 922 | gsdl_check_browser_settings (netscapeneeded);
|
---|
| 923 |
|
---|
| 924 | res = DialogBox (NULL, MAKEINTRESOURCE(COMMS_DIALOG2),
|
---|
| 925 | window, (DLGPROC)dialog_proc);
|
---|
[611] | 926 |
|
---|
[902] | 927 | if (res == 1) {
|
---|
| 928 | // only update if exited via the OK button
|
---|
[19210] | 929 | if ((gsdl_port_num != old_gsdl_port_num)
|
---|
| 930 | || (gsdl_external_access != old_gsdl_external_access)) {
|
---|
[902] | 931 | EndHTTPServer();
|
---|
| 932 | StartHTTPServer(window);
|
---|
| 933 | }
|
---|
| 934 | }
|
---|
| 935 | }
|
---|
| 936 |
|
---|
| 937 | // save the settings if we exited via the ok button
|
---|
| 938 | if (res == 1) {
|
---|
[4292] | 939 | write_settings(gsdl_url);
|
---|
[902] | 940 | // reset httpprefix in case port number was changed
|
---|
| 941 | // configure_httpprefix ();
|
---|
| 942 | }
|
---|
[611] | 943 | }
|
---|