Changeset 902 for trunk/gsdl/src/w32server/cgiwrapper.cpp
- Timestamp:
- 2000-02-03T14:45:48+13:00 (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/w32server/cgiwrapper.cpp
r611 r902 9 9 #include "wincgiutils.h" 10 10 #include "settings.h" 11 #include "fileutil.h" 11 12 12 13 #include "gsdlconf.h" … … 31 32 #include "mggdbmsource.h" 32 33 33 34 34 // actions 35 #include "action.h" 36 #include "statusaction.h" 35 37 #include "pageaction.h" 36 38 #include "pingaction.h" 37 39 #include "queryaction.h" 38 40 #include "documentaction.h" 39 #include " statusaction.h"41 #include "authenaction.h" 40 42 #include "usersaction.h" 41 #include "authenaction.h" 42 #include "tipaction.h" 43 #include "extlinkaction.h" 44 //#include "buildaction.h" 45 46 // browsers 47 #include "browserclass.h" 48 #include "vlistbrowserclass.h" 49 #include "hlistbrowserclass.h" 50 #include "datelistbrowserclass.h" 51 #include "invbrowserclass.h" 52 #include "pagedbrowserclass.h" 53 #include "htmlbrowserclass.h" 43 54 44 55 // filters … … 115 126 116 127 int logstreambuf::sync () { 117 if (gs _keep_log || gs_show_console) {128 if (gsdl_keep_log || gsdl_show_console) { 118 129 log_message ("LOCAL LIB MESSAGE: "); 119 130 log_message_N (pbase(), out_waiting()); … … 143 154 DWORD lastlibaccesstime; 144 155 DWORD baseavailvirtual; 145 146 156 147 157 static void page_errorsitecfg (const text_t &gsdlhome, const text_t &collection) { … … 318 328 cerr = &logstream; 319 329 cout = &textstream; 320 330 321 331 // collection should be set to "" unless in 322 332 // collection specific mode 323 333 text_t collection = ""; 334 text_tset gsdlhomes; 335 text_tarray collections; 336 colinfo_tmap::const_iterator this_info = gsdl_collectinfo.begin(); 337 colinfo_tmap::const_iterator end_info = gsdl_collectinfo.end(); 324 338 325 339 // note the current time 326 340 lastlibaccesstime = GetTickCount(); 327 341 328 342 // before we do the init we should make sure 329 343 // that we can find the relevant directories 330 if (!checkdir (GSDL_GSDLHOME "\\")) return 0; 331 if (!checkdir (GSDL_GSDLHOME "\\macros\\")) return 0; 332 333 // add a collection server for each collection 334 text_tarray collections; 335 ifstream collist (GSDL_GSDLHOME "/etc/collections.txt"); 336 if (!collist) { 337 exit(1); 338 } 339 char col[100]; 340 while (!collist.eof()) { 341 collist.getline (col, 100); 342 if (col[0] != '\0') 343 collections.push_back (col); 344 } 345 collist.close(); 346 344 if (!checkdir (gsdl_gsdlhome + "\\")) return 0; 345 if (!checkdir (gsdl_gsdlhome + "\\macros\\")) return 0; 346 347 if (collection.empty()) { 348 349 // get all collections from each gsdlhome (this relies 350 // on there not being more than one collection with the same 351 // name) 352 read_dir (filename_cat (gsdl_gsdlhome, "collect"), collections); 353 gsdlhomes.insert (gsdl_gsdlhome); 354 while (this_info != end_info) { 355 if (gsdlhomes.find ((*this_info).second.gsdl_gsdlhome) == gsdlhomes.end()) { 356 read_dir (filename_cat ((*this_info).second.gsdl_gsdlhome, "collect"), collections); 357 gsdlhomes.insert ((*this_info).second.gsdl_gsdlhome); 358 } 359 this_info ++; 360 } 361 } else { 362 collections.push_back (collection); 363 } 364 347 365 text_tarray::const_iterator thiscol = collections.begin(); 348 366 text_tarray::const_iterator endcol = collections.end(); 349 367 350 368 while (thiscol != endcol) { 351 369 352 370 // this memory is created but never destroyed 353 371 // we're also not doing any error checking to make sure we didn't … … 396 414 397 415 mapinconvertclass *gbinconvert = new mapinconvertclass(); 398 gbinconvert->setmapfile ( GSDL_GSDLHOME, "gbku", 0x25a1);416 gbinconvert->setmapfile (gsdl_gsdlhome, "gbku", 0x25a1); 399 417 mapoutconvertclass *gboutconvert = new mapoutconvertclass(); 400 gboutconvert->setmapfile ( GSDL_GSDLHOME, "ugbk", 0xa1f5);418 gboutconvert->setmapfile (gsdl_gsdlhome, "ugbk", 0xa1f5); 401 419 recpt.add_converter ("g", gbinconvert, gboutconvert); 402 420 … … 407 425 408 426 pageaction *apageaction = new pageaction(); 409 apageaction->set_receptionist (&recpt);410 427 recpt.add_action (apageaction); 411 428 … … 421 438 usersaction *ausersaction = new usersaction(); 422 439 recpt.add_action (ausersaction); 440 441 extlinkaction *anextlinkaction = new extlinkaction(); 442 recpt.add_action (anextlinkaction); 443 444 // buildaction *abuildaction = new buildaction(); 445 // abuildaction->set_receptionist (&recpt); 446 // recpt.add_action (abuildaction); 423 447 424 448 authenaction *aauthenaction = new authenaction(); 425 449 aauthenaction->set_receptionist(&recpt); 426 450 recpt.add_action (aauthenaction); 427 428 tipaction *atipaction = new tipaction(); 429 recpt.add_action (atipaction); 451 452 453 // list of browsers 454 vlistbrowserclass *avlistbrowserclass = new vlistbrowserclass(); 455 recpt.add_browser (avlistbrowserclass); 456 recpt.setdefaultbrowser ("VList"); 457 458 hlistbrowserclass *ahlistbrowserclass = new hlistbrowserclass(); 459 recpt.add_browser (ahlistbrowserclass); 460 461 datelistbrowserclass *adatelistbrowserclass = new datelistbrowserclass(); 462 recpt.add_browser (adatelistbrowserclass); 463 464 invbrowserclass *ainvbrowserclass = new invbrowserclass(); 465 recpt.add_browser (ainvbrowserclass); 466 467 pagedbrowserclass *apagedbrowserclass = new pagedbrowserclass(); 468 recpt.add_browser (apagedbrowserclass); 469 470 htmlbrowserclass *ahtmlbrowserclass = new htmlbrowserclass(); 471 recpt.add_browser (ahtmlbrowserclass); 430 472 431 473 // set defaults 432 recpt.configure ("gsdlhome", GSDL_GSDLHOME);474 recpt.configure ("gsdlhome", gsdl_gsdlhome); 433 475 recpt.configure ("collection", collection); 434 476 435 477 int maxrequests = 1; 436 if (!site_cfg_read (recpt, GSDL_GSDLHOME, collection, maxrequests)) { 437 // couldn't find the site configuration file 438 page_errorsitecfg (GSDL_GSDLHOME, collection); 439 return 0; 440 } else if (!main_cfg_read (recpt, GSDL_GSDLHOME, collection)) { 441 // couldn't find the main configuration file 442 page_errormaincfg (GSDL_GSDLHOME, collection); 443 return 0; 478 text_tset seenhomes; 479 this_info = gsdl_collectinfo.begin(); 480 481 // configure any collections with gsdlhome (or gdbmhome) 482 // different from the default 483 while (this_info != end_info) { 484 if (((*this_info).second.gsdl_gsdlhome != gsdl_gsdlhome) || 485 ((*this_info).second.gsdl_gdbmhome != gsdl_gdbmhome) && 486 (seenhomes.find ((*this_info).second.gsdl_gsdlhome + 487 (*this_info).second.gsdl_gdbmhome) == seenhomes.end())) { 488 text_tarray tmpconf; 489 tmpconf.push_back ((*this_info).first); 490 tmpconf.push_back ((*this_info).second.gsdl_gsdlhome); 491 tmpconf.push_back ((*this_info).second.gsdl_gdbmhome); 492 recpt.configure ("collectinfo", tmpconf); 493 seenhomes.insert ((*this_info).second.gsdl_gsdlhome + 494 (*this_info).second.gsdl_gdbmhome); 495 } 496 this_info ++; 497 } 498 499 // read in config files of each gsdlhome (in no particular order) 500 // those read in last will override those read earlier 501 // collections being used together in this way should be 502 // careful not to have site.cfg or main.cfg files that might 503 // screw with each other. 504 text_tset::const_iterator thome = gsdlhomes.begin(); 505 text_tset::const_iterator ehome = gsdlhomes.end(); 506 while (thome != ehome) { 507 if (!site_cfg_read (recpt, *thome, collection, maxrequests)) { 508 // couldn't find the site configuration file 509 page_errorsitecfg (*thome, collection); 510 return 0; 511 } else if (!main_cfg_read (recpt, *thome, collection)) { 512 // couldn't find the main configuration file 513 page_errormaincfg (*thome, collection); 514 return 0; 515 } 516 thome ++; 444 517 } 445 518 … … 450 523 if (!recpt.init(cerr)) { 451 524 // an error occurred during the initialisation 452 page_errorinit( GSDL_GSDLHOME);525 page_errorinit(gsdl_gsdlhome); 453 526 return 0; 454 527 } … … 465 538 466 539 static void rememberpref (char *tailstr) { 467 strcpy(gs_enterlib, tailstr); 468 469 // add "a=p&p=home" 470 strcat(gs_enterlib, "&a=p&p=home"); 540 541 // gsdl_enterlib = tailstr; 471 542 } 472 543 … … 493 564 494 565 // set up file name 495 text_t filenamet = text_t( GSDL_GSDLHOME) + filename;566 text_t filenamet = text_t(gsdl_gsdlhome) + filename; 496 567 text_t::iterator here = filenamet.begin(); 497 568 text_t::iterator end = filenamet.end(); … … 538 609 // has been no errors so far 539 610 cgiargsclass args; 540 if (!recpt.parse_cgi_args (TailStr, args, cerr)) { 541 page_errorparseargs(GSDL_GSDLHOME); 611 text_tmap empty; // don't use this (it's for fastcgi on unix) 612 if (!recpt.parse_cgi_args (TailStr, args, cerr, empty)) { 613 page_errorparseargs(gsdl_gsdlhome); 542 614 return; 543 615 } … … 547 619 text_t response_data; 548 620 549 recpt.get_cgihead_info (args, response, response_data, cerr); 550 char *response_data_c = response_data.getcstr(); 621 recpt.get_cgihead_info (args, response, response_data, cerr, empty); 551 622 552 623 if (response == location) { 553 624 // location response 554 if (send_header(strcat("@", response_data_c), RInfo) < 0) return; 555 // textstream << text_t2ascii << "Location: " << response_data << "\n\n"; 625 response_data = "@" + recpt.expandmacros (response_data, args, cerr); 626 char *response_data_c = response_data.getcstr(); 627 send_header(response_data_c, RInfo); 628 delete response_data_c; 629 return; 556 630 } else if (response == content) { 557 631 // content response 558 if (send_header(response_data_c, RInfo) < 0) return; 632 char *response_data_c = response_data.getcstr(); 633 if (send_header(response_data_c, RInfo) < 0) { 634 delete response_data_c; 635 return; 636 } 637 delete response_data_c; 559 638 } else { 560 639 // unknown response … … 565 644 textstream.tsbreset(); 566 645 textstream.setrequestinfo (RInfo); 567 delete response_data_c;568 646 569 647 if (!recpt.produce_content (args, cout, cerr)) { 570 page_errorcgipage( GSDL_GSDLHOME);648 page_errorcgipage(gsdl_gsdlhome); 571 649 return; 572 650 } 573 recpt.log_cgi_args (args, cerr );651 recpt.log_cgi_args (args, cerr, empty); 574 652 575 653 cout << flush; … … 598 676 // log the difference in access times 599 677 DWORD thislibaccesstime = GetTickCount(); 600 if (gs _keep_log||gs_show_console) {678 if (gsdl_keep_log||gsdl_show_console) { 601 679 sprintf(tmpstr, "DELTA LIB ACCESS TIME: %i\n", (int)(thislibaccesstime - lastlibaccesstime)); 602 680 log_message (tmpstr); … … 605 683 606 684 // log this request 607 if (gs _keep_log||gs_show_console) {685 if (gsdl_keep_log||gsdl_show_console) { 608 686 sprintf (tmpstr, "LOCAL LIB: %s\n", tailstr); 609 687 log_message (tmpstr); … … 616 694 617 695 // log memory information 618 if (gs _keep_log||gs_show_console) {696 if (gsdl_keep_log||gsdl_show_console) { 619 697 MEMORYSTATUS memstatus; 620 698 memstatus.dwLength = sizeof(MEMORYSTATUS); … … 627 705 } else { 628 706 // local file 629 if (gs _keep_log||gs_show_console) {707 if (gsdl_keep_log||gsdl_show_console) { 630 708 sprintf (tmpstr, "LOCAL FILE: %s\n", tailstr); 631 709 log_message (tmpstr);
Note:
See TracChangeset
for help on using the changeset viewer.