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