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