source: gsdl/trunk/runtime-src/src/w32server/settings.cpp@ 19015

Last change on this file since 19015 was 19015, checked in by ak19, 15 years ago

From now on the server starts up with address resolution method set to localhost rather than getting the ip (without resolving to a name). This will be helpful for people who move their laptops about from their home to office and the IP changes.

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