source: trunk/gsdl/src/w32server/settings.cpp@ 11718

Last change on this file since 11718 was 11319, checked in by kjdon, 18 years ago

added in localhost to address resolution methods

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