Changeset 2286 for trunk/gsdl/src
- Timestamp:
- 2001-04-05T17:08:52+12:00 (23 years ago)
- Location:
- trunk/gsdl/src/w32server
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/w32server/cgiwrapper.cpp
r2280 r2286 172 172 return 0; 173 173 } 174 175 176 177 #ifndef MAX_FILENAME_SIZE178 #define MAX_FILENAME_SIZE 2048179 #endif180 181 174 182 175 receptionist recpt; … … 580 573 581 574 582 static void rememberpref (char *tailstr) { 583 584 // gsdl_enterlib = tailstr; 585 } 586 587 588 static void send_file_from_disk(char *filename, 575 static void rememberpref (const text_t &tailstr) { 576 gsdl_enterlib = tailstr; 577 } 578 579 580 static void send_file_from_disk(text_t filename, 589 581 RequestInfoT *RInfo, 590 RequestFieldsT *RFields) 591 { 592 int len, nr; char *tail, *kind; 593 FILE *thefile; 594 595 // select appropriate mime type from file name 596 len = strlen(filename); 597 while (len > 0 && filename[len-1] != '.') len--; 598 kind = "unknown"; 599 if (len > 0) { 600 tail = &filename[len]; 601 if (stricmp("gif",tail) == 0) kind = "image/gif"; 602 else if (stricmp("jpg",tail) == 0 || 603 stricmp("jpeg",tail) == 0) kind = "image/jpeg"; 604 else if (stricmp("htm",tail) == 0 || 605 stricmp("html",tail) == 0) kind = "text/html"; 606 } 607 608 // set up file name 609 text_t filenamet = filename_cat (current_gsdlhome, filename); 610 filename = filenamet.getcstr(); 582 RequestFieldsT *RFields) { 583 584 // select appropriate mime type from file extension 585 text_t ext; 586 text_t::const_iterator end = filename.end(); 587 text_t::const_iterator it = filename.begin(); 588 text_t::const_iterator lastdot = end; 589 while ((it = findchar(it, end, '.')) != end) { 590 lastdot = it; 591 it++; 592 } 593 if (lastdot < end) ext = substr(lastdot+1, end); 594 595 text_t mime = "unknown"; 596 int len = ext.size(); 597 if (len == 3) { 598 if ((ext[0] == 'g' || ext[0] == 'G') && 599 (ext[1] == 'i' || ext[1] == 'I') && 600 (ext[2] == 'f' || ext[2] == 'F')) { 601 mime = "image/gif"; 602 } else if ((ext[0] == 'j' || ext[0] == 'J') && 603 (ext[1] == 'p' || ext[1] == 'P') && 604 (ext[2] == 'g' || ext[2] == 'G')) { 605 mime = "image/jpeg"; 606 } else if ((ext[0] == 'h' || ext[0] == 'H') && 607 (ext[1] == 't' || ext[1] == 'T') && 608 (ext[2] == 'm' || ext[2] == 'M')) { 609 mime = "text/html"; 610 } 611 } else if (len == 4) { 612 if ((ext[0] == 'j' || ext[0] == 'J') && 613 (ext[1] == 'p' || ext[1] == 'P') && 614 (ext[2] == 'e' || ext[2] == 'E') && 615 (ext[3] == 'g' || ext[3] == 'G')) { 616 mime = "image/jpeg"; 617 } else if ((ext[0] == 'h' || ext[0] == 'H') && 618 (ext[1] == 't' || ext[1] == 'T') && 619 (ext[2] == 'm' || ext[2] == 'M') && 620 (ext[3] == 'l' || ext[3] == 'L')) { 621 mime = "text/html"; 622 } 623 } 611 624 612 // try to open it 613 thefile = fopen(filename, "rb"); 625 // try to open the file 626 filename = filename_cat (current_gsdlhome, filename); 627 char *filenamec = filename.getcstr(); 628 FILE *thefile = fopen(filenamec, "rb"); 629 delete filenamec; 614 630 if (thefile == NULL) { 615 631 log_message("file not found\n"); … … 618 634 return; 619 635 } 620 636 637 int nr; 621 638 char buffer[2048]; 622 639 // send back required information 623 if (send_header(kind, RInfo) >= 0) { 640 char *mimec = mime.getcstr(); 641 if (send_header(mimec, RInfo) >= 0) { 624 642 if (strcmpi(RFields->MethodStr, "HEAD") != 0) { 625 643 for (;;) { … … 632 650 } 633 651 } 652 delete mimec; 634 653 fclose(thefile); 635 654 } 636 655 637 static void handle_library_request(c har *TailStr, RequestInfoT *RInfo,656 static void handle_library_request(const text_t &argstr, RequestInfoT *RInfo, 638 657 RequestFieldsT *RequestFields) { 639 // check for a "?" at the start of the tail string 640 if (*TailStr == '?') TailStr++; 641 642 outconvertclass text_t2ascii; 643 658 644 659 // parse the cgi arguments and produce the resulting page if there 645 // ha sbeen no errors so far660 // have been no errors so far 646 661 cgiargsclass args; 647 662 text_tmap empty; // don't use this (it's for fastcgi on unix) 648 if (!recpt.parse_cgi_args ( TailStr, args, cerr, empty)) {663 if (!recpt.parse_cgi_args (argstr, args, cerr, empty)) { 649 664 page_errorparseargs(gsdl_gsdlhome); 650 665 return; … … 700 715 } 701 716 702 static void handle_server_request( char *initialTailStr,717 static void handle_server_request(text_t &tailstr, 703 718 RequestInfoT *RequestInfo, 704 719 RequestFieldsT *RequestFields) { 705 char tmpstr[MAX_URL_SIZE+1024];706 char tailstr[MAX_URL_SIZE+16];707 720 721 text_t argstr; 722 708 723 // do any url adjustments necessary 709 if (strcmp(initialTailStr, "/") == 0) { 710 strcpy (tailstr, "/cgi-bin/gw"); 711 } else strcpy (tailstr, initialTailStr); 724 if (tailstr.empty() || tailstr == "/") { 725 tailstr = "/cgi-bin/gw"; 726 } 727 728 text_t::const_iterator begin = tailstr.begin(); 729 text_t::const_iterator end = tailstr.end(); 712 730 713 731 // test to see if this is a library request or a local 714 732 // file request 715 if ((strncmp(tailstr, "/cgi-bin/gw", 11) == 0) && 716 ((tailstr[11] == '\0') || (tailstr[11] == '?'))) { 733 if ((tailstr == "/cgi-bin/gw") || 734 ((tailstr.size() > 11) && 735 (substr(begin, begin+11) == "/cgi-bin/gw"))) { 736 717 737 // library request 718 738 739 // argstr is the bit after the '?' 740 if (tailstr != "/cgi-bin/gw") { 741 argstr = substr(begin+12, end); 742 } 743 719 744 // log the difference in access times 720 745 DWORD thislibaccesstime = GetTickCount(); 721 if (gsdl_keep_log||gsdl_show_console) { 722 sprintf(tmpstr, "DELTA LIB ACCESS TIME: %i\n", (int)(thislibaccesstime - lastlibaccesstime)); 723 log_message (tmpstr); 746 if (gsdl_keep_log || gsdl_show_console) { 747 char logstr[256]; 748 sprintf(logstr, "DELTA LIB ACCESS TIME: %i\n", (int)(thislibaccesstime - lastlibaccesstime)); 749 log_message (logstr); 724 750 } 725 751 lastlibaccesstime = thislibaccesstime; 726 752 727 753 // log this request 728 if (gsdl_keep_log||gsdl_show_console) { 729 sprintf (tmpstr, "LOCAL LIB: %s\n", tailstr); 730 log_message (tmpstr); 731 } 732 733 handle_library_request (&tailstr[11], RequestInfo, RequestFields); 754 if (gsdl_keep_log || gsdl_show_console) { 755 text_t logstr = "LOCAL LIB: " + tailstr + "\n"; 756 char *logstrc = logstr.getcstr(); 757 log_message (logstrc); 758 delete logstrc; 759 } 760 761 handle_library_request (argstr, RequestInfo, RequestFields); 734 762 735 763 // remember the preferences 736 rememberpref (tailstr);764 // rememberpref (tailstr); 737 765 738 766 // log memory information 739 if (gsdl_keep_log ||gsdl_show_console) {767 if (gsdl_keep_log || gsdl_show_console) { 740 768 MEMORYSTATUS memstatus; 741 769 memstatus.dwLength = sizeof(MEMORYSTATUS); 742 770 GlobalMemoryStatus(&memstatus); 743 sprintf (tmpstr, "BDELTA AVAIL VIRTUAL: %i K\n", 771 char logstr[256]; 772 sprintf (logstr, "BDELTA AVAIL VIRTUAL: %i K\n", 744 773 (int)((baseavailvirtual - memstatus.dwAvailVirtual)/1024)); 745 log_message ( tmpstr);774 log_message (logstr); 746 775 } 747 776 748 777 } else { 749 778 // local file 750 if (gsdl_keep_log||gsdl_show_console) { 751 sprintf (tmpstr, "LOCAL FILE: %s\n", tailstr); 752 log_message (tmpstr); 779 if (gsdl_keep_log || gsdl_show_console) { 780 text_t logstr = "LOCAL FILE: " + tailstr + "\n"; 781 char *logstrc = logstr.getcstr(); 782 log_message (logstrc); 783 delete logstrc; 753 784 } 754 785 send_file_from_disk (tailstr, RequestInfo, RequestFields); 755 786 } 756 }757 758 static void fix_prefix(char *dest, char *pref, char *suff)759 {760 strcpy(dest,pref);761 if (*suff != '/') strcat(dest,"/");762 if (strlen(dest) + strlen(suff) + 1 > MAX_URL_SIZE)763 strcpy(dest,"http://gsdl/name-too-long");764 else765 strcat(dest,suff);766 787 } 767 788 … … 769 790 RequestFieldsT *RequestFields) 770 791 { 771 char *protocol, *machine, *rest; int port;772 // char URICopyA[MAX_URL_SIZE], URICopyB[MAX_URL_SIZE];792 text_t protocol, machine, rest; 793 int port; 773 794 774 795 if (RequestFields->ContentLength > 0) { 775 796 // POST data 776 797 URIStr.push_back('?'); 777 URIStr += (char*)RequestFields->Content; 778 779 // int len = strlen (URIStr); 780 // fail relatively gracefully (and mysteriously) if POST 781 // arguments are too long 782 // if (len + RequestFields->ContentLength + 1 <= MAX_URL_SIZE) { 783 // URIStr[len] = '?'; len ++; 784 // for (int i = 0; i < RequestFields->ContentLength; i++) { 785 // URIStr[len] = RequestFields->Content[i]; 786 // len ++; 787 // } 788 // URIStr[len] = '\0'; 789 // } else { 790 // MessageBox (NULL, "POST data too long", "Greenstone Digital Library Software", MB_OK); 791 // } 792 } 793 794 char *URICopyA = URIStr.getcstr(); 795 char URICopyB[MAX_URL_SIZE]; 796 char *URICopytmp = URIStr.getcstr(); 797 798 // strcpy(URICopyA,URIStr); 799 800 if (parse_url(URICopyA,&protocol,&machine,&port,&rest)!=http_ok) { 801 /* Alter local file request to address 'gsdl' */ 802 // fix_prefix(URICopyB, "http://gsdl", URIStr); 803 fix_prefix(URICopyB, "http://gsdl", URICopytmp); 804 URIStr = URICopyB; 805 strcpy(URICopyA, URICopyB); 806 parse_url(URICopyA,&protocol,&machine,&port,&rest); 807 } 808 809 if (strncmp(machine, "gsdl", 5) == 0) { 798 for (int i = 0; i < RequestFields->ContentLength; i++) { 799 URIStr.push_back(RequestFields->Content[i]); 800 } 801 } 802 803 if (parse_url(URIStr, protocol, machine, &port, rest)!=http_ok) { 804 // Alter local file request to address 'gsdl' 805 if (*(URIStr.begin()) != '/') URIStr = "http://gsdl/" + URIStr; 806 else URIStr = "http://gsdl" + URIStr; 807 parse_url(URIStr, protocol, machine, &port, rest); 808 } 809 810 if (machine == "gsdl") { 810 811 // a local file request 811 812 handle_server_request(rest, RequestInfo, RequestFields); -
trunk/gsdl/src/w32server/d_winsock.cpp
r611 r2286 1 /********************************************************************** 2 * 3 * d_winsock.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 1 28 #include <windows.h> 2 29 #include "d_winsock.h" -
trunk/gsdl/src/w32server/d_winsock.h
r611 r2286 1 /********************************************************************** 2 * 3 * d_winsock.h 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 1 28 #ifndef D_WINSOCK_H 2 29 #define D_WINSOCK_H 3 30 4 5 31 /* get most definitions from the real winsock */ 6 32 #include <winsock.h> 7 8 33 9 34 #define D_NOERROR 0 … … 12 37 #define D_ERR_FREELIBFAILED 3 13 38 14 15 16 39 // d_LoadWinsock must be called before an normal winsock 17 40 // functions 18 19 41 20 42 // expects path to be NULL, a empty string, or a path which ends in a slash … … 26 48 // D_ERR_FREELIBFAILED on failure 27 49 int d_UnloadWinsock (); 28 29 50 30 51 // dynamically loaded versions of the winsock functions … … 97 118 long lEvent); 98 119 99 100 101 102 103 120 #endif -
trunk/gsdl/src/w32server/fnord.cpp
r1292 r2286 1 /* 2 Copyright (C) 1996 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 18 The author can be contacted via Email at [email protected] 19 */ 1 /********************************************************************** 2 * 3 * fnord.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 20 28 #include "text_t.h" 21 29 #include <windows.h> -
trunk/gsdl/src/w32server/httpreq.cpp
r2280 r2286 1 /* 2 Copyright (C) 1996 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 18 The author can be contacted via Email at [email protected] 19 */ 1 /********************************************************************** 2 * 3 * httpreq.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 20 28 #include "text_t.h" 21 29 #include <windows.h> … … 303 311 if (RequestFields.AcceptStr[0] == '\0') { 304 312 strncpy(RequestFields.AcceptStr, FieldValStr, ReqAcceptStrLen - 1); 305 // if (Len >= ReqAcceptStrLen)306 // if (log_debug) log_message("Accept field truncated");307 313 } 308 314 else { … … 317 323 else if (strcmp("DATE:", FieldNameStr) == 0) { 318 324 strncpy(RequestFields.DateStr, FieldValStr, ReqDateStrLen - 1); 319 // if (Len >= ReqDateStrLen) LogError("Date field truncated");320 325 } 321 326 else if (strcmp("USER-AGENT:", FieldNameStr) == 0) { 322 327 strncpy(RequestFields.UserAgentStr, FieldValStr, ReqUserAgentStrLen - 1); 323 // if (Len >= ReqUserAgentStrLen) {324 // LogError("User Agent field truncated, value follows");325 // LogError(RequestFields.UserAgentStr);326 // }327 328 } 328 329 else if (strcmp("CONNECTION:", FieldNameStr) == 0) { 329 330 strncpy(RequestFields.ConnectionStr, FieldValStr, ReqConnectionStrLen - 1); 330 // if (Len >= ReqConnectionStrLen) LogError("Connection field truncated");331 331 } 332 332 //--Sometimes-- 333 333 else if (strcmp("ACCEPT-LANGUAGE:", FieldNameStr) == 0) { 334 334 strncpy(RequestFields.AcceptLangStr, FieldValStr, ReqAcceptLangStrLen - 1); 335 // if (Len >= ReqAcceptLangStrLen) LogError("Accept-Language field truncated");336 335 } 337 336 else if (strcmp("REFERER:", FieldNameStr) == 0) { 338 337 strncpy(RequestFields.RefererStr, FieldValStr, ReqRefererStrLen - 1); 339 // if (Len >= ReqRefererStrLen) LogError("Referer field truncated");340 338 } 341 339 else if (strcmp("IF-MODIFIED-SINCE:", FieldNameStr) == 0) { 342 340 strncpy(RequestFields.IfModSinceStr, FieldValStr, ReqIfModSinceStrLen - 1); 343 // if (Len >= ReqIfModSinceStrLen) LogError("If Modified Since field truncated");344 341 } 345 342 //--Uncommon-- 346 343 else if (strcmp("FROM:", FieldNameStr) == 0) { 347 344 strncpy(RequestFields.FromStr, FieldValStr, ReqFromStrLen - 1); 348 // if (Len >= ReqFromStrLen) LogError("From field truncated");349 345 } 350 346 else if (strcmp("MIME-VERSION:", FieldNameStr) == 0) { 351 347 strncpy(RequestFields.MIMEVerStr, FieldValStr, ReqMIMEVerStrLen - 1); 352 // if (Len >= ReqMIMEVerStrLen) LogError("MIME Version field truncated");353 348 } 354 349 else if (strcmp("PRAGMA:", FieldNameStr) == 0) { 355 350 strncpy(RequestFields.PragmaStr, FieldValStr, ReqPragmaStrLen - 1); 356 // if (Len >= ReqPragmaStrLen) LogError("Pragma field truncated");357 351 } 358 352 //--Special case-- 359 353 else if (strcmp("AUTHORIZATION:", FieldNameStr) == 0) { 360 354 strncpy(RequestFields.AuthorizationStr, FieldValStr, ReqAuthorizationStrLen - 1); 361 // if (Len >= ReqAuthorizationStrLen) LogError("Authorization field truncated");362 355 } 363 356 else if (strcmp("CONTENT-LENGTH:", FieldNameStr) == 0) { 364 357 strncpy(RequestFields.ContentLengthStr, FieldValStr, ReqContentLengthStrLen - 1); 365 // if (Len >= ReqContentLengthStrLen) LogError("Content Length field truncated");366 358 } 367 359 else if (strcmp("CONTENT-TYPE:", FieldNameStr) == 0) { 368 360 strncpy(RequestFields.ContentTypeStr, FieldValStr, ReqContentTypeStrLen - 1); 369 // if (Len >= ReqContentTypeStrLen) LogError("Content Type field truncated");370 361 } 371 362 else if (strcmp("CONTENT-ENCODING:", FieldNameStr) == 0) { 372 363 strncpy(RequestFields.ContentEncodingStr, FieldValStr, ReqContentEncodingStrLen - 1); 373 // if (Len >= ReqContentEncodingStrLen) LogError("Content Encoding field truncated");374 364 } 375 365 else { … … 390 380 } 391 381 392 393 382 if (RequestFields.ContentLengthStr[0] != 0) { //Do we have attached data? 394 383 unsigned int NumRecv; … … 396 385 RequestFields.ContentLength = atol(RequestFields.ContentLengthStr); 397 386 if (RequestFields.ContentLength > 0) { 398 // ThreadDebugMessage(RequestInfo.ThreadNum, "Getting content");399 387 400 388 //Allocate memory -
trunk/gsdl/src/w32server/httpreq.h
r2280 r2286 1 /********************************************************************** 2 * 3 * httpreq.h 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 1 28 #ifndef HTTPREQ_H 2 29 #define HTTPREQ_H … … 6 33 7 34 /* 8 Copyright (C) 1996 9 10 This program is free software; you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 2 of the License, or 13 (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 24 The author can be contacted via Email at [email protected] 25 */ 26 27 /* 28 Module Name: HTTP Reqeust 35 Module Name: HTTP Request 29 36 Purpose: Parses HTTP requests and then calls the appropriate function 30 37 to respond to the request … … 37 44 //Used for sending information to the request thread 38 45 struct RequestThreadMessageT { 39 40 41 42 46 SOCKADDR_IN ClientSockAddr; 47 SOCKET ClientSocket; 48 int AddrLen; 49 }; 43 50 44 51 //Length constants for RequestFieldsT 45 52 #define ReqMethodStrLen 24 46 //#define ReqURIStrLen 25547 53 #define ReqVersionStrLen 24 48 54 #define ReqDateStrLen 48 … … 64 70 #define ReqPathTranslatedStrLen 512 65 71 #define ReqScriptNameStrLen 512 66 // ---67 // 443668 72 69 73 #define MAX_OTHER_HEADERS 100 … … 77 81 //Simple request line info v0.9 78 82 char MethodStr[ReqMethodStrLen]; 79 // char URIStr[ReqURIStrLen];80 83 text_t URIStr; 81 84 //added v1.0 -
trunk/gsdl/src/w32server/httpsend.cpp
r2280 r2286 1 /* 2 Copyright (C) 1996 1 /********************************************************************** 2 * 3 * httpsend.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 *********************************************************************/ 3 27 4 This program is free software; you can redistribute it and/or modify5 it under the terms of the GNU General Public License as published by6 the Free Software Foundation; either version 2 of the License, or7 (at your option) any later version.8 9 This program is distributed in the hope that it will be useful,10 but WITHOUT ANY WARRANTY; without even the implied warranty of11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 GNU General Public License for more details.13 14 You should have received a copy of the GNU General Public License15 along with this program; if not, write to the Free Software16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.17 18 The author can be contacted via Email at [email protected]19 */20 28 #include <windows.h> 21 29 #include <stdlib.h> … … 45 53 /******************************************************************************/ 46 54 47 void SendHTTPError(int ErrorNum, char *ErrorTitleStr, char *ErrorDescStr, RequestInfoT &RequestInfo, RequestFieldsT &RequestFields)48 {49 50 55 void SendHTTPError(int ErrorNum, char *ErrorTitleStr, char *ErrorDescStr, 56 RequestInfoT &RequestInfo, RequestFieldsT &RequestFields) { 57 char Header[512]; 58 char Body[512]; 51 59 52 char ErrorNumStr[17]; 60 char ErrorNumStr[17]; 61 62 DWORD BodyLength; 63 char BodyLengthStr[17]; 53 64 54 DWORD BodyLength; 55 char BodyLengthStr[17]; 65 int HeaderLength; 66 67 itoa(ErrorNum, ErrorNumStr, 10); 68 69 // Didn't find it, build the message manually 70 Body[0] = 0; 71 strcat(Body, "<HTML><HEAD><TITLE>Server Error</TITLE></HEAD><BODY>\n"); 72 strcat(Body, "<H1>Error "); 73 strcat(Body, ErrorNumStr); 74 strcat(Body, ": "); 75 strcat(Body, ErrorTitleStr); 76 strcat(Body, "</H1>\n"); 77 strcat(Body, ErrorDescStr); 78 strcat(Body, "\n</BODY></HTML>"); 79 BodyLength = (DWORD) strlen(Body); 56 80 57 int HeaderLength; 58 59 itoa(ErrorNum, ErrorNumStr, 10); 60 61 //Didn't find it, build the message manualry 62 Body[0] = 0; 63 strcat(Body, "<HTML><HEAD><TITLE>Server Error</TITLE></HEAD><BODY>\n"); 64 strcat(Body, "<H1>Error "); 65 strcat(Body, ErrorNumStr); 66 strcat(Body, ": "); 67 strcat(Body, ErrorTitleStr); 68 strcat(Body, "</H1>\n"); 69 strcat(Body, ErrorDescStr); 70 strcat(Body, "\n</BODY></HTML>"); 71 BodyLength = (DWORD) strlen(Body); 72 73 //Build Header 74 Header[0] = 0; 75 //Status Line 76 strcat(Header, "HTTP/1.0 "); 77 strcat(Header, ErrorNumStr); 78 strcat(Header, " "); 79 strcat(Header, ErrorDescStr); 80 strcat(Header, "\r\n"); 81 //Server 82 strcat(Header, "Server: GSDL\r\n"); 83 //Content Type (assume HTML) 84 strcat(Header, "Content-Type: text/html\r\n"); 85 //Content Length 86 itoa(BodyLength, BodyLengthStr, 10); 87 strcat(Header, "Content-Length: "); 88 strcat(Header, BodyLengthStr); 89 strcat(Header, "\r\n"); 90 //Single CRLF to end header 91 strcat(Header, "\r\n"); 92 93 HeaderLength = strlen(Header); 94 81 //Build Header 82 Header[0] = 0; 83 //Status Line 84 strcat(Header, "HTTP/1.0 "); 85 strcat(Header, ErrorNumStr); 86 strcat(Header, " "); 87 strcat(Header, ErrorDescStr); 88 strcat(Header, "\r\n"); 89 //Server 90 strcat(Header, "Server: GSDL\r\n"); 91 //Content Type (assume HTML) 92 strcat(Header, "Content-Type: text/html\r\n"); 93 //Content Length 94 itoa(BodyLength, BodyLengthStr, 10); 95 strcat(Header, "Content-Length: "); 96 strcat(Header, BodyLengthStr); 97 strcat(Header, "\r\n"); 98 //Single CRLF to end header 99 strcat(Header, "\r\n"); 100 101 HeaderLength = strlen(Header); 102 95 103 //Send header 96 104 SendData(RequestInfo.ClientSocket, (BYTE *) Header, strlen(Header), RequestInfo.ThreadNum); -
trunk/gsdl/src/w32server/httpsend.h
r611 r2286 1 /* 2 Copyright (C) 1996 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 18 The author can be contacted via Email at [email protected] 19 */ 1 /********************************************************************** 2 * 3 * httpsend.h 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 *********************************************************************/ 20 27 21 28 /* … … 36 43 Parameters: 37 44 ErrorNum - HTTP error number to send 38 45 ErrorTitleStr - Title of the error 39 46 ErrorDescStr - String describing the error 40 47 RequestInfo - HTTP request information (see httpreq.h) 41 48 RequestFields - Parsed HTTP header info (see httpreq.h) 42 49 */ 43 void SendHTTPError(int ErrorNum, char *ErrorTitleStr, char *ErrorDescStr, RequestInfoT &RequestInfo, RequestFieldsT &RequestFields); 50 void SendHTTPError(int ErrorNum, char *ErrorTitleStr, char *ErrorDescStr, 51 RequestInfoT &RequestInfo, RequestFieldsT &RequestFields); -
trunk/gsdl/src/w32server/httpsrv.cpp
r1203 r2286 1 /* 2 Copyright (C) 1996 1 /********************************************************************** 2 * 3 * httpsrc.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 *********************************************************************/ 3 27 4 This program is free software; you can redistribute it and/or modify5 it under the terms of the GNU General Public License as published by6 the Free Software Foundation; either version 2 of the License, or7 (at your option) any later version.8 9 This program is distributed in the hope that it will be useful,10 but WITHOUT ANY WARRANTY; without even the implied warranty of11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 GNU General Public License for more details.13 14 You should have received a copy of the GNU General Public License15 along with this program; if not, write to the Free Software16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.17 18 The author can be contacted via Email at [email protected]19 */20 28 #include "text_t.h" 21 29 #include <windows.h> … … 47 55 // returns 0 on success, and a WSA error otherwise 48 56 int StartHTTPServer(HWND PassedMsgWindow) { 49 57 50 58 MsgWindow = PassedMsgWindow; 51 59 //Create the server socket … … 62 70 /******************************************************************************/ 63 71 void ProcessHTTPServerMsg(WPARAM Socket, LPARAM MsgInfo) { 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 72 log_message("accept message arrived\n"); 73 if (Socket != ServerSocket) { 74 if (gsdl_keep_log || gsdl_show_console) log_message("Incorrect socket sent in message"); 75 } 76 switch (WSAGETSELECTEVENT(MsgInfo)) { 77 case FD_ACCEPT: 78 switch (WSAGETSELECTERROR(MsgInfo)) { 79 case WSAENETDOWN: 80 LogCriticalError("1","Network Down"); 81 break; 82 default: //No Error 83 HTTPServerAnswer(); 84 } 85 break; 86 } 79 87 } 80 88 81 89 /******************************************************************************/ 82 90 void HTTPServerAnswer() { 83 84 85 86 91 SOCKADDR_IN ClientSockAddr; 92 SOCKET ClientSocket; 93 int AddrLen = sizeof(SOCKADDR_IN); 94 RequestThreadMessageT Parameters; 87 95 while (AnswerListeningSocket(ServerSocket, ClientSocket, ClientSockAddr, AddrLen) == 0) { 88 96 log_message("Answering socket\n"); 89 97 //Call the thread procedure to handle the connection 90 98 Parameters.ClientSockAddr = ClientSockAddr; 91 92 99 Parameters.ClientSocket = ClientSocket; 100 Parameters.AddrLen = AddrLen; 93 101 RequestThread(&Parameters); 94 102 } 95 103 } 96 -
trunk/gsdl/src/w32server/httpsrv.h
r611 r2286 1 /* 2 Copyright (C) 1996 1 /********************************************************************** 2 * 3 * httpsrv.h 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 *********************************************************************/ 3 27 4 This program is free software; you can redistribute it and/or modify5 it under the terms of the GNU General Public License as published by6 the Free Software Foundation; either version 2 of the License, or7 (at your option) any later version.8 9 This program is distributed in the hope that it will be useful,10 but WITHOUT ANY WARRANTY; without even the implied warranty of11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 GNU General Public License for more details.13 14 You should have received a copy of the GNU General Public License15 along with this program; if not, write to the Free Software16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.17 18 The author can be contacted via Email at [email protected]19 */20 28 #define HTTP_SERVER_MSG WM_USER + 23 21 29 22 30 /* 23 31 Function Name: Start HTTP Server 24 Purpose: Starts the HTTP server. Inits Winsock, MIME, loads registry stuff, 25 etc. 32 33 Purpose: Starts the HTTP server. Inits Winsock, MIME, loads registry 34 stuff, etc. 35 26 36 Parameters: 27 37 PassedMsgWindow - The handle of the window that handles messages. Needed 28 29 to send a shutdown message on error. 30 */ 38 to setup WSASelect notification of socket events and 39 to send a shutdown message on error. */ 40 31 41 // returns 0 on success, and a WSA error otherwise 32 42 int StartHTTPServer(HWND PassedMsgWindow); -
trunk/gsdl/src/w32server/locate.cpp
r1203 r2286 1 /********************************************************************** 2 * 3 * locate.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 1 28 #include "text_t.h" 2 29 #include <windows.h> … … 14 41 15 42 static int location_found=0; 16 char data_location[MAX_ URL_SIZE];43 char data_location[MAX_FILENAME_SIZE]; 17 44 18 45 void set_location(char *possible) … … 24 51 strcat(data_location,"\\"); 25 52 location_found = 1; 26 53 } 27 54 } 28 55 … … 31 58 char *send; 32 59 if (location_found != 0) return; 33 if (GetModuleFileName(NULL,data_location,MAX_ URL_SIZE) <= 0)60 if (GetModuleFileName(NULL,data_location,MAX_FILENAME_SIZE) <= 0) 34 61 send = data_location; 35 62 else { … … 188 215 fprintf(log_file,"%s",msg); 189 216 fflush(log_file); 190 217 } 191 218 if (gsdl_show_console) { 192 219 char buffer[1024]; HDC dc; … … 195 222 display_text(dc,buffer); 196 223 ReleaseDC(GSDL_Window,dc); 197 224 } 198 225 } 199 226 … … 201 228 { 202 229 if (log_file != NULL) { 203 204 205 206 207 208 209 } 210 230 int len = 0; 231 while (len < n) { 232 fputc (msg[len], log_file); 233 len++; 234 } 235 fflush(log_file); 236 } 237 211 238 // these messages are not send to the console 212 239 if (gsdl_show_console) { … … 215 242 display_text(dc,"message only written to log file\n"); 216 243 ReleaseDC(GSDL_Window,dc); 217 244 } 218 245 } 219 246 220 247 void LogCriticalError(char *cderr, char *Msg) 221 248 { 222 223 224 225 226 227 228 229 230 231 249 char MsgBoxStr[200]; 250 251 strcpy(MsgBoxStr, "Critical Error Number "); 252 strcat(MsgBoxStr, cderr); 253 strcat(MsgBoxStr, "\n"); 254 strcat(MsgBoxStr, Msg); 255 strcat(MsgBoxStr, "\nGreenstone Digital Library software\nshutting down"); 256 MessageBox(GSDL_Window, MsgBoxStr, "Greenstone Digital Library Software", 257 MB_OK | MB_ICONERROR); 258 PostMessage(GSDL_Window, WM_DESTROY, 0, 0); 232 259 } 233 260 … … 236 263 DWORD DiffTickCounts (DWORD first, DWORD second) 237 264 { 238 239 240 } 265 if (second >= first) return (second-first); 266 return (MAXDWORD-first+1+second); 267 } -
trunk/gsdl/src/w32server/locate.h
r2038 r2286 1 //#define MAX_URL_SIZE 256 2 // now kind of long to allow for post data 3 #define MAX_URL_SIZE 8192 1 /********************************************************************** 2 * 3 * locate.h 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 #ifndef MAX_FILENAME_SIZE 29 #define MAX_FILENAME_SIZE 2048 30 #endif 4 31 5 32 extern HWND GSDL_Window; … … 9 36 void refresh_console(HDC dc); 10 37 11 12 extern char data_location[MAX_URL_SIZE]; 38 extern char data_location[MAX_FILENAME_SIZE]; 13 39 14 40 extern void set_location(char *possible); -
trunk/gsdl/src/w32server/netio.cpp
r1203 r2286 1 /* 2 Copyright (C) 1996 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 18 The author can be contacted via Email at [email protected] 19 */ 1 /********************************************************************** 2 * 3 * netio.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 *********************************************************************/ 20 27 21 28 #include <windows.h> … … 41 48 int dns_msg_error = 0; 42 49 43 44 50 DWORD LocalIPNumber; 45 51 char LocalName[MAXHOSTNAME]; 46 52 47 48 53 //Private Function Declarations 49 54 DWORD GetHostID(); 50 51 55 52 56 // returns 0 on success, 53 57 // WSASYSNOTREADY, WSAVERNOTSUPPORTED, or WSAEINVAL on failure 54 58 int InitNetIO() { 55 WSADATA Data; 56 57 // Load Winsock 58 int err = d_WSAStartup(MAKEWORD(1, 1), &Data); 59 60 // get local IP number 61 if (err == 0) LocalIPNumber = GetHostID(); 62 else LocalIPNumber = INADDR_ANY; 63 64 // set the Local Name to "" for now 65 LocalName[0] = 0; 59 WSADATA Data; 60 61 // Load Winsock 62 int err = d_WSAStartup(MAKEWORD(1, 1), &Data); 63 64 // get local IP number 65 if (err == 0) LocalIPNumber = GetHostID(); 66 else LocalIPNumber = INADDR_ANY; 67 68 // set the Local Name to "" for now 69 LocalName[0] = 0; 70 71 return err; 72 } 73 74 75 void CleanUpNetIO() { 76 //Experimental, heard this will better clean up, especialy if a call is 77 //blocking.... 78 d_WSAUnhookBlockingHook(); 79 80 //Clean up Winsock 81 d_WSACleanup() == SOCKET_ERROR; 82 } 83 84 85 void ResetNetIO() { 86 //Figure out the local name on first querry, set to "" until then... 87 LocalName[0] = 0; 88 } 89 90 91 DWORD GetLocalIP() { 92 return LocalIPNumber; 93 } 94 95 long __stdcall DNSWindowProc(HWND hWnd,UINT wMsg, WPARAM wParam, LPARAM lParam) { 96 if (wMsg == HTTP_DNS_MSG) { 97 dns_msg_received = 1; 98 dns_msg_error = WSAGETASYNCERROR(lParam); 99 return 0; 100 } 101 102 return DefWindowProc(hWnd, wMsg, wParam, lParam); 103 } 104 105 char *GetLocalName(HINSTANCE hInstance) { 106 // static in case it is written to after the function has finished 107 // (I did not error checking on WSACancelAsyncRequest) 108 static char buf[MAXGETHOSTSTRUCT]; 66 109 67 return err; 68 } 69 70 71 void CleanUpNetIO() { 72 //Experimental, heard this will better clean up, especialy if a call is 73 //blocking.... 74 d_WSAUnhookBlockingHook(); 75 76 //Clean up Winsock 77 d_WSACleanup() == SOCKET_ERROR; 78 } 79 80 81 void ResetNetIO() { 82 //Figure out the local name on first querry, set to "" until then... 83 LocalName[0] = 0; 84 } 85 86 87 DWORD GetLocalIP() { 88 return LocalIPNumber; 89 } 90 91 92 93 94 95 long __stdcall DNSWindowProc(HWND hWnd,UINT wMsg, WPARAM wParam, LPARAM lParam) { 96 if (wMsg == HTTP_DNS_MSG) { 97 dns_msg_received = 1; 98 dns_msg_error = WSAGETASYNCERROR(lParam); 99 return 0; 110 if (LocalName[0] == 0) { 111 hostent *DNSResult = NULL; 112 in_addr LocalInAddr; 113 114 // if we failed to get the local IP number 115 // use the loop-back device 116 if (LocalIPNumber == INADDR_ANY) { 117 strcpy(LocalName, "127.0.0.1"); // loop-back device 118 return LocalName; 119 } 120 121 //Convert the number to an in_addr struct 122 LocalInAddr.s_addr = LocalIPNumber; 123 124 // if we fail to find the domain name we will 125 // still want the IP address 126 strcpy(LocalName, d_inet_ntoa(LocalInAddr)); 127 128 // make sure they actually passed in an instance handle 129 if (hInstance == NULL) return LocalName; 130 131 // do a async domain name lookup so that we 132 // can control the timeout 133 134 // create a window class and window to handle the async messages 135 WNDCLASS wc; HWND hwndDNS; 136 137 wc.style = 0; 138 wc.lpfnWndProc = DNSWindowProc; 139 wc.cbClsExtra = 0; 140 wc.cbWndExtra = 0; 141 wc.hInstance = hInstance; 142 wc.hIcon = NULL; 143 wc.hCursor = NULL; 144 wc.hbrBackground = NULL; 145 wc.lpszMenuName = NULL; 146 wc.lpszClassName = "GSDL DNS Window"; 147 if (!RegisterClass(&wc)) return LocalName; 148 149 hwndDNS = CreateWindow("GSDL DNS Window", "", 150 WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, 151 NULL, NULL, hInstance, NULL); 152 if (!hwndDNS) return LocalName; 153 154 // process all messages currently on the queue 155 MSG Message; 156 while (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) { 157 TranslateMessage(&Message); /* translate keyboard messages */ 158 DispatchMessage(&Message); /* return control to Windows NT */ 159 } 160 161 //Do a async DNS lookup on the IP number 162 dns_msg_received = 0; 163 dns_msg_error = 0; 164 HANDLE asyncGetHostReq = d_WSAAsyncGetHostByAddr( 165 hwndDNS, HTTP_DNS_MSG, (char *)&(LocalInAddr), 166 4, PF_INET, buf, MAXGETHOSTSTRUCT); 167 168 if (asyncGetHostReq != NULL) { 169 // wait 5 seconds for the request to complete 170 int now = GetTickCount(); 171 while ((DiffTickCounts(now, GetTickCount()) < 5000) && !dns_msg_received) { 172 if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) { 173 TranslateMessage(&Message); /* translate keyboard messages */ 174 DispatchMessage(&Message); /* return control to Windows NT */ 175 } else { 176 Sleep(1); 100 177 } 101 102 return DefWindowProc(hWnd, wMsg, wParam, lParam); 103 } 104 105 char *GetLocalName(HINSTANCE hInstance) { 106 // static in case it is written to after the function has finished 107 // (I did not error checking on WSACancelAsyncRequest) 108 static char buf[MAXGETHOSTSTRUCT]; 109 110 111 if (LocalName[0] == 0) { 112 hostent *DNSResult = NULL; 113 in_addr LocalInAddr; 114 115 // if we failed to get the local IP number 116 // use the loop-back device 117 if (LocalIPNumber == INADDR_ANY) { 118 strcpy(LocalName, "127.0.0.1"); // loop-back device 119 return LocalName; 120 } 121 122 //Convert the number to an in_addr struct 123 LocalInAddr.s_addr = LocalIPNumber; 124 125 // if we fail to find the domain name we will 126 // still want the IP address 127 strcpy(LocalName, d_inet_ntoa(LocalInAddr)); 128 129 130 // make sure they actually passed in an instance handle 131 if (hInstance == NULL) return LocalName; 132 133 // do a async domain name lookup so that we 134 // can control the timeout 135 136 // create a window class and window to handle the async messages 137 WNDCLASS wc; HWND hwndDNS; 138 139 wc.style = 0; 140 wc.lpfnWndProc = DNSWindowProc; 141 wc.cbClsExtra = 0; 142 wc.cbWndExtra = 0; 143 wc.hInstance = hInstance; 144 wc.hIcon = NULL; 145 wc.hCursor = NULL; 146 wc.hbrBackground = NULL; 147 wc.lpszMenuName = NULL; 148 wc.lpszClassName = "GSDL DNS Window"; 149 if (!RegisterClass(&wc)) return LocalName; 150 151 hwndDNS = CreateWindow("GSDL DNS Window", "", 152 WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, 153 NULL, NULL, hInstance, NULL); 154 if (!hwndDNS) return LocalName; 155 156 // process all messages currently on the queue 157 MSG Message; 158 while (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) { 159 TranslateMessage(&Message); /* translate keyboard messages */ 160 DispatchMessage(&Message); /* return control to Windows NT */ 161 } 162 163 //Do a async DNS lookup on the IP number 164 dns_msg_received = 0; 165 dns_msg_error = 0; 166 HANDLE asyncGetHostReq = d_WSAAsyncGetHostByAddr( 167 hwndDNS, HTTP_DNS_MSG, (char *)&(LocalInAddr), 168 4, PF_INET, buf, MAXGETHOSTSTRUCT); 169 170 if (asyncGetHostReq != NULL) { 171 // wait 5 seconds for the request to complete 172 int now = GetTickCount(); 173 while ((DiffTickCounts(now, GetTickCount()) < 5000) && !dns_msg_received) { 174 if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) { 175 TranslateMessage(&Message); /* translate keyboard messages */ 176 DispatchMessage(&Message); /* return control to Windows NT */ 177 } else { 178 Sleep(1); 179 } 180 } 181 if (!dns_msg_received) 182 d_WSACancelAsyncRequest(asyncGetHostReq); 183 } 184 185 DestroyWindow(hwndDNS); 186 187 if (dns_msg_received && (dns_msg_error == 0)) { 188 //Worked, use the primary name 189 strcpy(LocalName, ((hostent *)(buf))->h_name); 190 //Convert it to lower case for cosmedic reasons 191 CharLower(LocalName); 192 } 193 } 194 return LocalName; 178 } 179 if (!dns_msg_received) 180 d_WSACancelAsyncRequest(asyncGetHostReq); 181 } 182 183 DestroyWindow(hwndDNS); 184 185 if (dns_msg_received && (dns_msg_error == 0)) { 186 //Worked, use the primary name 187 strcpy(LocalName, ((hostent *)(buf))->h_name); 188 //Convert it to lower case for cosmedic reasons 189 CharLower(LocalName); 190 } 191 } 192 return LocalName; 195 193 } 196 194 … … 203 201 204 202 #define MAXBINDCOUNT 4096 205 int CreateListeningSocket(int &PortNum, HWND MsgWindow, WORD SocketMsg, SOCKET &ServerSocket) { 206 int err = 0; 207 SOCKADDR_IN ServerSockAddr; 208 int bind_port, bind_count; 209 210 //Create the Server Socket 211 ServerSocket = d_socket(AF_INET, SOCK_STREAM, 0); 212 if (ServerSocket == INVALID_SOCKET) return d_WSAGetLastError(); 213 214 bind_port = PortNum; 215 for (bind_count=0; bind_count < MAXBINDCOUNT; bind_count++) { 216 // Set up the Server Socket Address 217 memset(&ServerSockAddr, 0, sizeof(ServerSockAddr)); //Needed? 218 ServerSockAddr.sin_port = d_htons( (WORD) bind_port); 219 ServerSockAddr.sin_family = AF_INET; 220 ServerSockAddr.sin_addr.s_addr = d_htonl(INADDR_ANY); 221 222 // Try to bind the socket with the address 223 if (d_bind(ServerSocket, (LPSOCKADDR) &ServerSockAddr, 224 sizeof(ServerSockAddr)) != SOCKET_ERROR) { 225 PortNum = bind_port; 226 break; 227 } 228 229 // make sure it failed to bind because it was 230 // already bound 231 err = d_WSAGetLastError (); 232 if (err != WSAEADDRINUSE) return err; 233 234 // Or choose another port number to try 235 if (bind_port == 80) bind_port = IPPORT_RESERVED+1; 236 else if (bind_count == 0) bind_port = 80; 237 else bind_port++; 203 int CreateListeningSocket(int &PortNum, HWND MsgWindow, 204 WORD SocketMsg, SOCKET &ServerSocket) { 205 int err = 0; 206 SOCKADDR_IN ServerSockAddr; 207 int bind_port, bind_count; 208 209 //Create the Server Socket 210 ServerSocket = d_socket(AF_INET, SOCK_STREAM, 0); 211 if (ServerSocket == INVALID_SOCKET) return d_WSAGetLastError(); 212 213 bind_port = PortNum; 214 for (bind_count=0; bind_count < MAXBINDCOUNT; bind_count++) { 215 // Set up the Server Socket Address 216 memset(&ServerSockAddr, 0, sizeof(ServerSockAddr)); //Needed? 217 ServerSockAddr.sin_port = d_htons( (WORD) bind_port); 218 ServerSockAddr.sin_family = AF_INET; 219 ServerSockAddr.sin_addr.s_addr = d_htonl(INADDR_ANY); 220 221 // Try to bind the socket with the address 222 if (d_bind(ServerSocket, (LPSOCKADDR) &ServerSockAddr, 223 sizeof(ServerSockAddr)) != SOCKET_ERROR) { 224 PortNum = bind_port; 225 break; 226 } 227 228 // make sure it failed to bind because it was 229 // already bound 230 err = d_WSAGetLastError (); 231 if (err != WSAEADDRINUSE) return err; 232 233 // Or choose another port number to try 234 if (bind_port == 80) bind_port = IPPORT_RESERVED+1; 235 else if (bind_count == 0) bind_port = 80; 236 else bind_port++; 237 } 238 239 // return an error in we couldn't find a valid port 240 if (bind_count == MAXBINDCOUNT) return WSAEADDRINUSE; 241 242 // Start listening for connections 243 if (d_listen(ServerSocket, SOMAXCONN) == SOCKET_ERROR) 244 return d_WSAGetLastError (); 245 246 // Set up event for new connections 247 if (d_WSAAsyncSelect(ServerSocket, MsgWindow, SocketMsg, FD_ACCEPT) == SOCKET_ERROR) 248 return d_WSAGetLastError (); 249 250 return 0; 251 } 252 253 254 int AnswerListeningSocket(SOCKET ServerSocket, SOCKET &ClientSocket, 255 SOCKADDR_IN &ClientSockAddr, int AddrLen) { 256 if (d_WSAIsBlocking()) { 257 log_message("rejected connect due blocking\n"); 258 return -1; 259 } 260 261 ClientSocket = d_accept(ServerSocket, (LPSOCKADDR) &ClientSockAddr, &AddrLen); 262 if (ClientSocket == INVALID_SOCKET) { 263 log_message("accept failed - connection lost\n"); 264 return -1; 265 } 266 267 log_message("accept success - connection made\n"); 268 return 0; 269 } 270 271 void DestroyListeningSocket(SOCKET &ServerSocket, HWND MsgWindow) { 272 //Remove any message notification 273 d_WSAAsyncSelect(ServerSocket, MsgWindow, 0, 0); 274 275 //Close the socket 276 CloseSocket(ServerSocket); 277 } 278 279 void CloseSocket(SOCKET &TargetSocket) { 280 if (TargetSocket != INVALID_SOCKET) { 281 //Since we're closing the socket, there's not much I can do about errors 282 //now so I'm not gonna bother checking... 283 284 //Shutdown both ends, assume we have all data... 285 d_shutdown(TargetSocket, 2); 286 287 d_closesocket(TargetSocket); 288 289 //Make sure we can't use the old handle again... 290 TargetSocket = INVALID_SOCKET; 291 } 292 } 293 294 int GetData(SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, 295 int ThreadNum) { 296 297 int NumRecv; 298 int Error; 299 struct timeval Timeout; 300 fd_set SocketSet; 301 302 //Set up a socket set structure with just ClientSocket for select(..) 303 FD_ZERO(&SocketSet); 304 FD_SET(ClientSocket, &SocketSet); 305 306 //set timeout 307 Timeout.tv_sec = NETIO_CONN_TIMEOUT; 308 Timeout.tv_usec = 0; 309 310 do { 311 NumRecv = d_recv(ClientSocket, (char *) IOBuffer, IOBufferSize, 0); 312 if (NumRecv == 0) { 313 //Lost connect 314 return -1; 315 316 } else if (NumRecv == SOCKET_ERROR) { 317 Error = d_WSAGetLastError(); 318 if (Error == WSAEWOULDBLOCK) { 319 NumRecv = 0; 320 //Wait for socket to be readable 321 if (d_select(0, &SocketSet, NULL, NULL, &Timeout) != 1) { 322 //Timeout 323 return -1; 238 324 } 239 240 // return an error in we couldn't find a valid port 241 if (bind_count == MAXBINDCOUNT) return WSAEADDRINUSE; 242 243 // Start listening for connections 244 if (d_listen(ServerSocket, SOMAXCONN) == SOCKET_ERROR) 245 return d_WSAGetLastError (); 246 247 // Set up event for new connections 248 if (d_WSAAsyncSelect(ServerSocket, MsgWindow, SocketMsg, FD_ACCEPT) == SOCKET_ERROR) 249 return d_WSAGetLastError (); 250 251 return 0; 252 } 253 254 255 int AnswerListeningSocket(SOCKET ServerSocket, SOCKET &ClientSocket, SOCKADDR_IN &ClientSockAddr, int AddrLen) { 256 if (d_WSAIsBlocking()) { 257 log_message("rejected connect due blocking\n"); 258 return -1; 325 326 } else { 327 //Assume connection terminated 328 return -1; 329 } 330 } 331 } while(NumRecv == 0); 332 return NumRecv; 333 } 334 335 int GetLine(char *OutStr, SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, 336 int &BufferIndex, int &DataInBuffer, int ThreadNum) { 337 338 int i; 339 char CurChar; 340 341 i = 0; 342 do { 343 if (BufferIndex == DataInBuffer) { //Need more data 344 DataInBuffer = GetData(ClientSocket, IOBuffer, IOBufferSize, ThreadNum); 345 if (DataInBuffer == -1) { 346 //Lost connect 347 return -1; 348 } 349 BufferIndex = 0; 350 } 351 CurChar = IOBuffer[BufferIndex]; 352 BufferIndex++; 353 if ((CurChar != 10) && (CurChar != 13)) { 354 OutStr[i] = CurChar; 355 i++; 356 } 357 } while ((CurChar != 10) && (i < NETIO_MAX_LINE)); 358 if (i == NETIO_MAX_LINE) { 359 return -1; 360 } 361 362 OutStr[i] = 0; 363 return 0; 364 } 365 366 int SendData(SOCKET ClientSocket, BYTE *SendBuffer, int NumToSend, 367 int ThreadNum) { 368 369 int NumSent = 0; 370 int Error; 371 struct timeval Timeout; 372 fd_set SocketSet; 373 374 char NumSentStr[50]; 375 itoa(NumToSend, NumSentStr, 10); 376 377 //Set up a socket set structure with just ClientSocket for select(..) 378 FD_ZERO(&SocketSet); 379 FD_SET(ClientSocket, &SocketSet); 380 //set timeout 381 Timeout.tv_sec = NETIO_CONN_TIMEOUT; 382 Timeout.tv_usec = 0; 383 384 while (NumToSend > 0) { 385 NumSent = d_send(ClientSocket, (char *) SendBuffer + NumSent, NumToSend, 0); 386 if (NumSent == 0) { 387 //Lost connect 388 return -1; 389 } 390 else if (NumSent == SOCKET_ERROR) { 391 Error = d_WSAGetLastError(); 392 if (Error == WSAEWOULDBLOCK) { 393 NumSent = 0; 394 if (d_select(0, NULL, &SocketSet, NULL, &Timeout) != 1) { 395 //Timeout 396 return -1; 259 397 } 260 261 ClientSocket = d_accept(ServerSocket, (LPSOCKADDR) &ClientSockAddr, &AddrLen); 262 if (ClientSocket == INVALID_SOCKET) { 263 log_message("accept failed - connection lost\n"); 264 return -1; 265 } 266 267 log_message("accept success - connection made\n"); 268 return 0; 269 } 270 271 272 void DestroyListeningSocket(SOCKET &ServerSocket, HWND MsgWindow) { 273 //Remove any message notification 274 d_WSAAsyncSelect(ServerSocket, MsgWindow, 0, 0); 275 276 //Close the socket 277 CloseSocket(ServerSocket); 278 } 279 280 281 void CloseSocket(SOCKET &TargetSocket) { 282 if (TargetSocket != INVALID_SOCKET) { 283 //Since we're closing the socket, there's not much I can do about errors 284 //now so I'm not gonna bother checking... 285 286 //Shutdown both ends, assume we have all data... 287 d_shutdown(TargetSocket, 2); 288 289 d_closesocket(TargetSocket); 290 291 //Make sure we can't use the old handle again... 292 TargetSocket = INVALID_SOCKET; 293 } 294 } 295 296 297 int GetData(SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, 298 int ThreadNum) { 299 300 int NumRecv; 301 int Error; 302 struct timeval Timeout; 303 fd_set SocketSet; 304 305 //Set up a socket set structure with just ClientSocket for select(..) 306 FD_ZERO(&SocketSet); 307 FD_SET(ClientSocket, &SocketSet); 308 309 //set timeout 310 Timeout.tv_sec = NETIO_CONN_TIMEOUT; 311 Timeout.tv_usec = 0; 312 313 do { 314 NumRecv = d_recv(ClientSocket, (char *) IOBuffer, IOBufferSize, 0); 315 if (NumRecv == 0) { 316 //Lost connect 317 return -1; 318 319 } else if (NumRecv == SOCKET_ERROR) { 320 Error = d_WSAGetLastError(); 321 if (Error == WSAEWOULDBLOCK) { 322 NumRecv = 0; 323 //Wait for socket to be readable 324 if (d_select(0, &SocketSet, NULL, NULL, &Timeout) != 1) { 325 //Timeout 326 return -1; 327 } 328 329 } else { 330 //Assume connection terminated 331 return -1; 332 } 333 } 334 } while(NumRecv == 0); 335 return NumRecv; 336 } 337 338 339 int GetLine(char *OutStr, SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, 340 int &BufferIndex, int &DataInBuffer, int ThreadNum) { 341 342 int i; 343 char CurChar; 344 345 i = 0; 346 do { 347 if (BufferIndex == DataInBuffer) { //Need more data 348 DataInBuffer = GetData(ClientSocket, IOBuffer, IOBufferSize, ThreadNum); 349 if (DataInBuffer == -1) { 350 //Lost connect 351 return -1; 352 } 353 BufferIndex = 0; 354 } 355 CurChar = IOBuffer[BufferIndex]; 356 BufferIndex++; 357 if ((CurChar != 10) && (CurChar != 13)) { 358 OutStr[i] = CurChar; 359 i++; 360 } 361 } while ((CurChar != 10) && (i < NETIO_MAX_LINE)); 362 if (i == NETIO_MAX_LINE) { 363 return -1; 364 } 365 366 OutStr[i] = 0; 367 return 0; 368 } 369 370 371 int SendData(SOCKET ClientSocket, BYTE *SendBuffer, int NumToSend, 372 int ThreadNum) { 373 374 int NumSent = 0; 375 int Error; 376 struct timeval Timeout; 377 fd_set SocketSet; 378 379 char NumSentStr[50]; 380 itoa(NumToSend, NumSentStr, 10); 381 382 //Set up a socket set structure with just ClientSocket for select(..) 383 FD_ZERO(&SocketSet); 384 FD_SET(ClientSocket, &SocketSet); 385 //set timeout 386 Timeout.tv_sec = NETIO_CONN_TIMEOUT; 387 Timeout.tv_usec = 0; 388 389 while (NumToSend > 0) { 390 NumSent = d_send(ClientSocket, (char *) SendBuffer + NumSent, NumToSend, 0); 391 if (NumSent == 0) { 392 //Lost connect 393 return -1; 394 } 395 else if (NumSent == SOCKET_ERROR) { 396 Error = d_WSAGetLastError(); 397 if (Error == WSAEWOULDBLOCK) { 398 NumSent = 0; 399 if (d_select(0, NULL, &SocketSet, NULL, &Timeout) != 1) { 400 //Timeout 401 return -1; 402 } 403 } 404 else { 405 //Lost Connection 406 return -1; 407 } 408 } 409 NumToSend -= NumSent; 410 } 411 return 0; 412 } 413 398 } 399 else { 400 //Lost Connection 401 return -1; 402 } 403 } 404 NumToSend -= NumSent; 405 } 406 return 0; 407 } 414 408 415 409 … … 433 427 */ 434 428 DWORD GetHostID () { 435 char szLclHost [MAXHOSTNAME]; 436 LPHOSTENT lpstHostent; 437 SOCKADDR_IN stLclAddr; 438 SOCKADDR_IN stRmtAddr; 439 int nAddrSize = sizeof(SOCKADDR); 440 SOCKET hSock; 441 int nRet; 442 443 /* Init local address (to zero) */ 444 stLclAddr.sin_addr.s_addr = INADDR_ANY; 445 446 /* Get the local hostname */ 447 nRet = d_gethostname(szLclHost, MAXHOSTNAME); 448 if (nRet != SOCKET_ERROR) { 449 /* Resolve hostname for local address */ 450 lpstHostent = d_gethostbyname((LPSTR)szLclHost); 451 if (lpstHostent) 452 stLclAddr.sin_addr.s_addr = *((u_long FAR*) (lpstHostent->h_addr)); 453 } 454 455 /* If still not resolved, then try second strategy */ 456 if (stLclAddr.sin_addr.s_addr == INADDR_ANY) { 457 /* Get a UDP socket */ 458 hSock = d_socket(AF_INET, SOCK_DGRAM, 0); 459 if (hSock != INVALID_SOCKET) { 460 /* Connect to arbitrary port and address (NOT loopback) */ 461 stRmtAddr.sin_family = AF_INET; 462 stRmtAddr.sin_port = d_htons(IPPORT_ECHO); 463 stRmtAddr.sin_addr.s_addr = d_inet_addr("128.127.50.1"); 464 nRet = d_connect(hSock, 465 (LPSOCKADDR)&stRmtAddr, 466 sizeof(SOCKADDR)); 467 if (nRet != SOCKET_ERROR) { 468 /* Get local address */ 469 d_getsockname(hSock, 470 (LPSOCKADDR)&stLclAddr, 471 (int FAR*)&nAddrSize); 472 } 473 d_closesocket(hSock); /* we're done with the socket */ 474 } 475 } 476 return (stLclAddr.sin_addr.s_addr); 477 } 478 429 char szLclHost [MAXHOSTNAME]; 430 LPHOSTENT lpstHostent; 431 SOCKADDR_IN stLclAddr; 432 SOCKADDR_IN stRmtAddr; 433 int nAddrSize = sizeof(SOCKADDR); 434 SOCKET hSock; 435 int nRet; 436 437 /* Init local address (to zero) */ 438 stLclAddr.sin_addr.s_addr = INADDR_ANY; 439 440 /* Get the local hostname */ 441 nRet = d_gethostname(szLclHost, MAXHOSTNAME); 442 if (nRet != SOCKET_ERROR) { 443 /* Resolve hostname for local address */ 444 lpstHostent = d_gethostbyname((LPSTR)szLclHost); 445 if (lpstHostent) 446 stLclAddr.sin_addr.s_addr = *((u_long FAR*) (lpstHostent->h_addr)); 447 } 448 449 /* If still not resolved, then try second strategy */ 450 if (stLclAddr.sin_addr.s_addr == INADDR_ANY) { 451 /* Get a UDP socket */ 452 hSock = d_socket(AF_INET, SOCK_DGRAM, 0); 453 if (hSock != INVALID_SOCKET) { 454 /* Connect to arbitrary port and address (NOT loopback) */ 455 stRmtAddr.sin_family = AF_INET; 456 stRmtAddr.sin_port = d_htons(IPPORT_ECHO); 457 stRmtAddr.sin_addr.s_addr = d_inet_addr("128.127.50.1"); 458 nRet = d_connect(hSock, 459 (LPSOCKADDR)&stRmtAddr, 460 sizeof(SOCKADDR)); 461 if (nRet != SOCKET_ERROR) { 462 /* Get local address */ 463 d_getsockname(hSock, 464 (LPSOCKADDR)&stLclAddr, 465 (int FAR*)&nAddrSize); 466 } 467 d_closesocket(hSock); /* we're done with the socket */ 468 } 469 } 470 return (stLclAddr.sin_addr.s_addr); 471 } -
trunk/gsdl/src/w32server/netio.h
r1203 r2286 1 /* 2 Copyright (C) 1996 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 18 The author can be contacted via Email at [email protected] 19 */ 1 /********************************************************************** 2 * 3 * netio.h 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 *********************************************************************/ 20 27 21 28 /* … … 51 58 Function Name: Init Net IO 52 59 Purpose: Initializes the module so calls can be made querying network 53 60 information for the local macnine. 54 61 Notes: MUST be called before GetLocalIP and GetLocalName 55 62 */ … … 91 98 // WSAENOBUFS, WSAEPROTONOSUPPORT, WSAEPROTOTYPE, WSAESOCKTNOSUPPORT, 92 99 // WSAEADDRINUSE, WSAEINVAL, WSAEISCONN, WSAENOTSOCK, WSAEOPNOTSUPP 93 int CreateListeningSocket(int &PortNum, HWND MsgWindow, WORD SocketMsg, SOCKET &ServerSocket); 100 int CreateListeningSocket(int &PortNum, HWND MsgWindow, 101 WORD SocketMsg, SOCKET &ServerSocket); 94 102 95 int AnswerListeningSocket(SOCKET ServerSocket, SOCKET &ClientSocket, SOCKADDR_IN &ClientSockAddr, int AddrLen); 103 int AnswerListeningSocket(SOCKET ServerSocket, SOCKET &ClientSocket, 104 SOCKADDR_IN &ClientSockAddr, int AddrLen); 96 105 97 106 void DestroyListeningSocket(SOCKET &ServerSocket, HWND MsgWindow); … … 132 141 Returns: -1 on disconnect or error (abort connection), 0 on success 133 142 */ 134 int GetLine(char *OutStr, SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, int &BufferIndex, int &DataInBuffer, int ThreadNum); 143 int GetLine(char *OutStr, SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, 144 int &BufferIndex, int &DataInBuffer, int ThreadNum); 135 145 136 146 /* … … 149 159 errors I was getting when getting a "rude" disconnect 150 160 */ 151 int SendData(SOCKET ClientSocket, BYTE *SendBuffer, int NumToSend, int ThreadNum); 161 int SendData(SOCKET ClientSocket, BYTE *SendBuffer, 162 int NumToSend, int ThreadNum); -
trunk/gsdl/src/w32server/parse.cpp
r611 r2286 1 /* 2 Copyright (C) 1996 1 /********************************************************************** 2 * 3 * parse.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 *********************************************************************/ 3 27 4 This program is free software; you can redistribute it and/or modify5 it under the terms of the GNU General Public License as published by6 the Free Software Foundation; either version 2 of the License, or7 (at your option) any later version.8 9 This program is distributed in the hope that it will be useful,10 but WITHOUT ANY WARRANTY; without even the implied warranty of11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 GNU General Public License for more details.13 14 You should have received a copy of the GNU General Public License15 along with this program; if not, write to the Free Software16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.17 18 The author can be contacted via Email at [email protected]19 */20 28 #include <windows.h> 21 29 #include <stdlib.h> -
trunk/gsdl/src/w32server/parse.h
r611 r2286 1 /* 2 Copyright (C) 1996 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 18 The author can be contacted via Email at [email protected] 19 */ 1 /********************************************************************** 2 * 3 * parse.h 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 *********************************************************************/ 20 27 21 28 /* … … 102 109 occur. 103 110 */ 104 void GetWord(char *DestStr, const char *SourceStr, const int Start, int &End); 111 void GetWord(char *DestStr, const char *SourceStr, 112 const int Start, int &End); 105 113 106 114 /* -
trunk/gsdl/src/w32server/settings.cpp
r1800 r2286 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 1 28 #include "text_t.h" 2 29 -
trunk/gsdl/src/w32server/settings.h
r1270 r2286 1 /********************************************************************** 2 * 3 * settings.h 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 1 28 #ifndef SETTINGS_H 2 29 #define SETTINGS_H 3 4 #ifndef MAX_FILENAME_SIZE5 #define MAX_FILENAME_SIZE 10246 #endif7 30 8 31 #define GS_NETSCAPE 0 … … 13 36 #include "cfgread.h" 14 37 #include "receptionist.h" 38 #include "locate.h" 15 39 16 40 // library settings -
trunk/gsdl/src/w32server/startbrowser.cpp
r611 r2286 1 /********************************************************************** 2 * 3 * startbrowser.cpp 4 * Copyright (C) 1999 The New Zealand Digital Library Project 5 * 6 * A component of the Greenstone digital library software 7 * from the New Zealand Digital Library Project at the 8 * University of Waikato, New Zealand. 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * 24 *********************************************************************/ 25 1 26 #include "startbrowser.h" 2 27 #include <windows.h> … … 21 46 static HSZ hszActivateTopic = NULL; 22 47 23 24 48 // budget callback 25 49 HDDEDATA CALLBACK DdeCallback(UINT uType, /* transaction type */ 26 27 28 29 30 31 32 50 UINT uFmt, /* clipboard data format */ 51 HCONV hconv, /* handle of conversation */ 52 HSZ hsz1, /* handle of string */ 53 HSZ hsz2, /* handle of string */ 54 HDDEDATA hdata, /* handle of global memory object */ 55 DWORD dwData1, /* transaction-specific data */ 56 DWORD dwData2) /* transaction-specific data */ 33 57 { 34 return (HDDEDATA) NULL; 35 } 36 58 return (HDDEDATA) NULL; 59 } 37 60 38 61 // returns 0 on failure 39 62 static int talkdde (HSZ hszServName, HSZ hszSysTopic, char *requeststr) { 40 HSZ hszRequest; 41 HCONV hConv; 42 HDDEDATA result; 43 44 // try to connect to the newly started browser 45 hConv = DdeConnect (idInst, hszServName, hszSysTopic, (PCONVCONTEXT) NULL); 46 if (hConv == NULL) return 0; 47 48 hszRequest = DdeCreateStringHandle (idInst, requeststr, CP_WINANSI); 49 50 //HDDEDATA hRetVal = DdeClientTransaction(NULL, 0ul, m_hConv, 51 // hszItem, CF_TEXT, 52 // XTYP_REQUEST, 53 // DDETIMEOUT, NULL); 54 result = DdeClientTransaction ( 55 NULL, // pointer to data to pass to server 56 0, // length of data 57 hConv, // handle to conversation 58 hszRequest, // handle to item name string 59 CF_TEXT, // clipboard data format 60 XTYP_REQUEST, // transaction type 61 SB_DDETIMEOUT, // time-out duration 62 NULL // pointer to transaction result 63 ); 64 65 if (result != NULL) DdeFreeDataHandle (result); 66 DdeDisconnect(hConv); 67 DdeFreeStringHandle (idInst, hszRequest); 68 69 return 1; 70 } 71 63 HSZ hszRequest; 64 HCONV hConv; 65 HDDEDATA result; 66 67 // try to connect to the newly started browser 68 hConv = DdeConnect (idInst, hszServName, hszSysTopic, (PCONVCONTEXT) NULL); 69 if (hConv == NULL) return 0; 70 71 hszRequest = DdeCreateStringHandle (idInst, requeststr, CP_WINANSI); 72 result = DdeClientTransaction ( 73 NULL, // pointer to data to pass to server 74 0, // length of data 75 hConv, // handle to conversation 76 hszRequest, // handle to item name string 77 CF_TEXT, // clipboard data format 78 XTYP_REQUEST, // transaction type 79 SB_DDETIMEOUT, // time-out duration 80 NULL // pointer to transaction result 81 ); 82 83 if (result != NULL) DdeFreeDataHandle (result); 84 DdeDisconnect(hConv); 85 DdeFreeStringHandle (idInst, hszRequest); 86 87 return 1; 88 } 72 89 73 90 // returns 0 on failure 74 91 static int openurl(HSZ hszServName, HSZ hszActivateTopic, HSZ hszOpenURLTopic, char *url) { 75 76 77 78 79 80 81 82 83 84 85 92 char requeststr[65600]; 93 94 // bring the browser to the front, don't worry if this fails 95 talkdde (hszServName, hszActivateTopic, "0xFFFFFFFF,0x0"); 96 97 // tell the browser to open a url 98 strcpy (requeststr, "\""); 99 strcat (requeststr, url); 100 strcat (requeststr, "\",,0xFFFFFFFF,0x0,,,"); 101 102 return talkdde (hszServName, hszOpenURLTopic, requeststr); 86 103 } 87 104 88 105 // returns 0 on failure 89 106 static int tryconnect(HSZ hszServName, HSZ hszSysTopic) { 90 91 92 93 94 107 // try to connect to a running browser 108 HCONV hConv = DdeConnect (idInst, hszServName, hszSysTopic, (PCONVCONTEXT) NULL); 109 if (hConv == NULL) return 0; 110 DdeDisconnect(hConv); 111 return 1; 95 112 } 96 113 97 114 static void freestrings () { 98 // free up any currently allocated strings 99 if (hszNetscapeName != NULL) DdeFreeStringHandle (idInst, hszNetscapeName); 100 hszNetscapeName = NULL; 101 if (hszIExploreName != NULL) DdeFreeStringHandle (idInst, hszIExploreName); 102 hszIExploreName = NULL; 103 if (hszOpenURLTopic != NULL) DdeFreeStringHandle (idInst, hszOpenURLTopic); 104 hszOpenURLTopic = NULL; 105 if (hszActivateTopic != NULL) DdeFreeStringHandle (idInst, hszActivateTopic); 106 hszActivateTopic = NULL; 107 } 108 109 115 // free up any currently allocated strings 116 if (hszNetscapeName != NULL) DdeFreeStringHandle (idInst, hszNetscapeName); 117 hszNetscapeName = NULL; 118 if (hszIExploreName != NULL) DdeFreeStringHandle (idInst, hszIExploreName); 119 hszIExploreName = NULL; 120 if (hszOpenURLTopic != NULL) DdeFreeStringHandle (idInst, hszOpenURLTopic); 121 hszOpenURLTopic = NULL; 122 if (hszActivateTopic != NULL) DdeFreeStringHandle (idInst, hszActivateTopic); 123 hszActivateTopic = NULL; 124 } 110 125 111 126 static void getbrowserinfo() { 112 freestrings(); 113 114 hszNetscapeName = DdeCreateStringHandle(idInst,"NETSCAPE",CP_WINANSI); 115 hszIExploreName = DdeCreateStringHandle(idInst,"IExplore",CP_WINANSI); 116 117 hszOpenURLTopic = DdeCreateStringHandle(idInst,"WWW_OpenURL",CP_WINANSI); 118 hszActivateTopic = DdeCreateStringHandle(idInst,"WWW_Activate",CP_WINANSI); 119 } 120 121 127 freestrings(); 128 129 hszNetscapeName = DdeCreateStringHandle(idInst,"NETSCAPE",CP_WINANSI); 130 hszIExploreName = DdeCreateStringHandle(idInst,"IExplore",CP_WINANSI); 131 132 hszOpenURLTopic = DdeCreateStringHandle(idInst,"WWW_OpenURL",CP_WINANSI); 133 hszActivateTopic = DdeCreateStringHandle(idInst,"WWW_Activate",CP_WINANSI); 134 } 122 135 123 136 // returns SB_NOERROR on success, 124 137 // SB_ALREADYINIT or SB_DDE_FAILINIT on failure 125 138 int initstartbrowser () { 126 if (inited) return SB_ALREADYINIT; 127 128 // from nstest if(DdeInitialize(&CDDEObject::m_dwidInst, NstestDdeCallBack, APPCLASS_STANDARD, 0ul)) 129 if (DdeInitialize (&idInst, (PFNCALLBACK) DdeCallback, 130 APPCLASS_STANDARD, 0) 131 // CBF_FAIL_EXECUTES | CBF_SKIP_ALLNOTIFICATIONS, 0) 132 != DMLERR_NO_ERROR) { 133 freestrings(); 134 inited = 0; 135 return SB_DDE_FAILINIT; 136 } 137 138 getbrowserinfo(); 139 140 inited = 1; 141 return SB_NOERROR; 139 if (inited) return SB_ALREADYINIT; 140 141 // from nstest if(DdeInitialize(&CDDEObject::m_dwidInst, NstestDdeCallBack, APPCLASS_STANDARD, 0ul)) 142 if (DdeInitialize (&idInst, (PFNCALLBACK) DdeCallback, 143 APPCLASS_STANDARD, 0) 144 != DMLERR_NO_ERROR) { 145 freestrings(); 146 inited = 0; 147 return SB_DDE_FAILINIT; 148 } 149 150 getbrowserinfo(); 151 152 inited = 1; 153 return SB_NOERROR; 142 154 } 143 155 … … 146 158 // SB_DDE_FAILDEINIT of failure 147 159 int deinitstartbrowser () { 148 149 150 151 152 153 154 155 156 157 158 160 // make sure this has been inited 161 // not being inited here, however, is not 162 // important 163 if (!inited) return SB_NOERROR; 164 inited = 0; 165 166 freestrings(); 167 168 if (DdeUninitialize(idInst)) return SB_NOERROR; 169 170 return SB_DDE_FAILDEINIT; 159 171 } 160 172 … … 166 178 // SB_FAILCONNECTBROWSER on failure 167 179 int startbrowser (char *url, char *browser_exe, char *startdir) { 168 char newcommand[SB_COMLEN]; 169 int usingnetscape = 0; 170 int usingiexplore = 0; 171 172 if (!inited) return SB_NOTINITED; // has to be inited first 173 174 // find out which browser we are dealing with 175 strcpy (newcommand, browser_exe); 176 _strlwr (newcommand); 177 if (strstr (newcommand, "netscape.exe") != NULL) { 178 // netscape 179 usingnetscape = 1; 180 } else if (strstr (newcommand, "iexplore.exe") != NULL) { 181 // internet explorer 182 usingiexplore = 1; 183 } 184 185 // only try to communicate with a running browser if a startdir 186 // is not specified 187 if (startdir == NULL) { 188 if (usingnetscape && hszNetscapeName != NULL && 189 openurl(hszNetscapeName, hszActivateTopic, hszOpenURLTopic, url)) { 190 return SB_NOERROR; 191 } 192 if (usingiexplore && hszIExploreName != NULL && 193 openurl(hszIExploreName, hszActivateTopic, hszOpenURLTopic, url)) { 194 return SB_NOERROR; 195 } 196 } 197 198 strcpy (newcommand, browser_exe); 199 200 // don't put the url on the command line for internet explorer 201 if (usingiexplore) { 202 strcat (newcommand, " -nohome"); 203 204 } else { 205 // will have to put the url on the command line 206 strcat (newcommand, " \""); 207 strcat (newcommand, url); 208 strcat (newcommand, "\""); 209 } 210 211 // change the working directory (if needed) 212 char cwd[1024]; 213 cwd[0] = '\0'; 214 if (startdir != NULL) { 215 _getcwd(cwd, 1024); 216 _chdir(startdir); 217 } 218 219 // attempt to start the browser 220 int res = WinExec(newcommand, SW_SHOW); 221 222 // change the working directory back (if needed) 223 if (startdir != NULL) _chdir(cwd); 224 225 if (res == ERROR_BAD_FORMAT) return SB_FAIL_BADFORMAT; 226 if ((res == ERROR_FILE_NOT_FOUND) || (res == ERROR_PATH_NOT_FOUND)) 227 return SB_FAIL_NOTFOUND; 228 if (res <= 31) return SB_FAIL_NORESOURCES; 229 230 numbrowserstarted++; 231 232 // if we aren't using iexplore then the url was 233 // put on the command line and there is nothing left to do 234 if (!usingiexplore) return SB_NOERROR; 235 236 // connect to the browser and get it to open a page, 237 // time out after 1 minute 238 DWORD lastcheck = GetTickCount (); 239 while (DiffTickCounts (lastcheck, GetTickCount()) <= 60000) { 240 if (usingnetscape && hszNetscapeName != NULL && 241 openurl(hszNetscapeName, hszActivateTopic, hszOpenURLTopic, url)) { 242 return SB_NOERROR; 243 } 244 if (usingiexplore && hszIExploreName != NULL && 245 openurl(hszIExploreName, hszActivateTopic, hszOpenURLTopic, url)) { 246 return SB_NOERROR; 247 } 248 } 249 250 // timed out trying to connect to the browser 251 return SB_FAILCONNECTBROWSER; 252 } 253 254 180 char newcommand[SB_COMLEN]; 181 int usingnetscape = 0; 182 int usingiexplore = 0; 183 184 if (!inited) return SB_NOTINITED; // has to be inited first 185 186 // find out which browser we are dealing with 187 strcpy (newcommand, browser_exe); 188 _strlwr (newcommand); 189 if (strstr (newcommand, "netscape.exe") != NULL) { 190 // netscape 191 usingnetscape = 1; 192 } else if (strstr (newcommand, "iexplore.exe") != NULL) { 193 // internet explorer 194 usingiexplore = 1; 195 } 196 197 // only try to communicate with a running browser if a startdir 198 // is not specified 199 if (startdir == NULL) { 200 if (usingnetscape && hszNetscapeName != NULL && 201 openurl(hszNetscapeName, hszActivateTopic, hszOpenURLTopic, url)) { 202 return SB_NOERROR; 203 } 204 if (usingiexplore && hszIExploreName != NULL && 205 openurl(hszIExploreName, hszActivateTopic, hszOpenURLTopic, url)) { 206 return SB_NOERROR; 207 } 208 } 209 210 strcpy (newcommand, browser_exe); 211 212 // don't put the url on the command line for internet explorer 213 if (usingiexplore) { 214 strcat (newcommand, " -nohome"); 215 216 } else { 217 // will have to put the url on the command line 218 strcat (newcommand, " \""); 219 strcat (newcommand, url); 220 strcat (newcommand, "\""); 221 } 222 223 // change the working directory (if needed) 224 char cwd[1024]; 225 cwd[0] = '\0'; 226 if (startdir != NULL) { 227 _getcwd(cwd, 1024); 228 _chdir(startdir); 229 } 230 231 // attempt to start the browser 232 int res = WinExec(newcommand, SW_SHOW); 233 234 // change the working directory back (if needed) 235 if (startdir != NULL) _chdir(cwd); 236 237 if (res == ERROR_BAD_FORMAT) return SB_FAIL_BADFORMAT; 238 if ((res == ERROR_FILE_NOT_FOUND) || (res == ERROR_PATH_NOT_FOUND)) 239 return SB_FAIL_NOTFOUND; 240 if (res <= 31) return SB_FAIL_NORESOURCES; 241 242 numbrowserstarted++; 243 244 // if we aren't using iexplore then the url was 245 // put on the command line and there is nothing left to do 246 if (!usingiexplore) return SB_NOERROR; 247 248 // connect to the browser and get it to open a page, 249 // time out after 1 minute 250 DWORD lastcheck = GetTickCount (); 251 while (DiffTickCounts (lastcheck, GetTickCount()) <= 60000) { 252 if (usingnetscape && hszNetscapeName != NULL && 253 openurl(hszNetscapeName, hszActivateTopic, hszOpenURLTopic, url)) { 254 return SB_NOERROR; 255 } 256 if (usingiexplore && hszIExploreName != NULL && 257 openurl(hszIExploreName, hszActivateTopic, hszOpenURLTopic, url)) { 258 return SB_NOERROR; 259 } 260 } 261 262 // timed out trying to connect to the browser 263 return SB_FAILCONNECTBROWSER; 264 } 255 265 256 266 // returns SB_NOERROR on success, 257 267 // SB_NOTINITED, SB_FAILCONNECTBROWSER on failure 258 268 int browserrunning (char *browser_exe) { 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 } 269 char newcommand[SB_COMLEN]; 270 if (!inited) return SB_NOTINITED; // has to be inited first 271 272 strcpy (newcommand, browser_exe); 273 _strlwr (newcommand); 274 275 if ((strstr (newcommand, "netscape.exe") != NULL) && (hszNetscapeName != NULL) && 276 tryconnect(hszNetscapeName, hszOpenURLTopic)) { 277 // succeeded connecting to netscape 278 return SB_NOERROR; 279 280 } else if ((strstr (newcommand, "iexplore.exe") != NULL) && (hszIExploreName != NULL) && 281 tryconnect(hszIExploreName, hszOpenURLTopic)) { 282 // succeeded connecting to internet explorer 283 return SB_NOERROR; 284 } 285 286 return SB_FAILCONNECTBROWSER; 287 } -
trunk/gsdl/src/w32server/startbrowser.h
r611 r2286 1 /********************************************************************** 2 * 3 * startbrowser.h 4 * Copyright (C) 1999 The New Zealand Digital Library Project 5 * 6 * A component of the Greenstone digital library software 7 * from the New Zealand Digital Library Project at the 8 * University of Waikato, New Zealand. 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * 24 *********************************************************************/ 25 1 26 #define SB_NOERROR 0 2 27 #define SB_ALREADYINIT 1 -
trunk/gsdl/src/w32server/wincgiutils.cpp
r611 r2286 1 /********************************************************************** 2 * 3 * wincgiutils.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 1 28 #include <windows.h> 2 29 #include <string.h> 3 30 #include "netio.h" 4 31 #include "httpreq.h" 5 // #include "locate.h"6 32 #include "wincgiutils.h" 7 33 8 9 #define url_limit 25610 #define file_limit 102400 /*should be large enough for a header line*/11 34 #define default_http_port 80 12 35 36 // Attempt to break a url into segments. If the parsing fails, 'name' is 37 // left pointing to the unparsed portion. 38 int parse_url(const text_t &url, text_t &protocol, text_t &machine, 39 int *port, text_t &name) { 13 40 14 int parse_url(char *url, 15 char **protocol, char **machine, int *port, char **name) 16 /* Attempt to break a url into segments. If the parsing 17 fails, 'name' is left pointing to the unparsed portion. 18 This routine may extend the url string by one character */ 19 { 20 char next, thiss; 21 *protocol = *machine = ""; 41 protocol.clear(); 42 machine.clear(); 22 43 *port = default_http_port; 44 name.clear(); 23 45 24 *name = url; /* In case there is no protocol */25 while (*url != ':' && *url != 0) url++;26 if (*url == 0) return http_error_url_invalid;27 url++;28 if ( *url != '/') return http_error_url_invalid;29 *url++ = 0;30 i f (*url != '/') return http_error_url_invalid;31 url++;32 33 *protocol = *name;34 *machine = url;35 while (*url != ':' && *url != '/' && *url != 0) url++;36 if (*url == ':') { 37 *url = 0;38 url++; *port = 0;39 while (*url >= '0' && *url <= '9')40 *port = *port * 10 + (*url++ - '0');46 text_t::const_iterator begin = url.begin(); 47 text_t::const_iterator end = url.end(); 48 text_t::const_iterator it = findchar(begin, end, ':'); 49 if (it == end) {name = url; return http_error_url_invalid;} 50 if (substr(it+1, it+3) != "//") {name = url; return http_error_url_invalid;} 51 protocol = substr(begin, it); 52 it += 3; 53 while (it < end) { 54 if (*it == ':') { 55 it++; 56 text_t portstr; 57 while (it != end && (*it >= '0' && *it <= '9')) { 58 portstr.push_back(*it); 59 it++; 60 } 61 *port = portstr.getint(); 62 if (it == end) break; 41 63 } 42 if (*url == '/') { 43 *url++ = 0; 44 next = '/'; 45 *name = url; 46 while (*url != 0) { 47 thiss = *url; *url++ = next; next = thiss; } 48 *url++ = next; 49 *url = 0; 64 65 if (*it == '/') { 66 while (it != end) { 67 name.push_back(*it); 68 it++; 69 } 70 break; 50 71 } 51 else if (*url == 0) { 52 url++; 53 *name = url; 54 *url++ = '/'; 55 *url = 0; 56 } 57 else { 58 *name = url; 59 return http_error_url_invalid; 72 73 machine.push_back(*it); 74 it ++; 60 75 } 61 76 return http_ok; 62 77 } 63 64 65 66 78 67 79 int Send_String(char *str, RequestInfoT *RInfo) … … 80 92 { 81 93 char Header[1536]; int len, lenc; 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 94 //Build Header 95 Header[0] = 0; 96 //Status Line 97 if (content[0] != '@') /*No redirection needed*/ 98 strcat(Header, "HTTP/1.0 200 OK\r\n"); 99 else /*Redirection*/ 100 strcat(Header, "HTTP/1.0 302 Relocation\r\n"); 101 //Server 102 strcat(Header, "Server: GSDL\r\n"); 103 //Content Type 104 strcat(Header, "Content-type: "); 105 if (content[0] != '@') /*No redirection needed*/ 106 strcat(Header, content); 107 else { /*Redirection entry*/ 108 strcat(Header, "text/html \r\n"); 109 strcat(Header, "Location: "); 110 len = strlen(Header); 111 lenc = strlen(content) - 1; 112 strncpy(&Header[len], &content[1], lenc); 113 Header[len+lenc] = 0; 114 } 115 strcat(Header, " \r\n"); 116 //Single CRLF to end header 117 strcat(Header, "\r\n"); 118 119 return Send_String(Header, RequestInfo); 108 120 } 109 121 … … 112 124 char Header[512], Body[512], ErrorNumStr[17], BodyLengthStr[17]; 113 125 DWORD BodyLength; int HeaderLength; 114 126 115 127 itoa(error_num, ErrorNumStr, 10); 116 128 117 129 //Build Data (so we can determine length for the header) 118 130 Body[0] = 0; … … 149 161 //Send the file if we have one (and if it's not a HEAD request) 150 162 SendData(RequestInfo->ClientSocket, (BYTE *) Header, strlen(Header), RequestInfo->ThreadNum); 151 // if ((FileFound == FALSE) && (strcmpi(RequestFields.MethodStr, "HEAD") != 0)) {152 163 // if ((FileFound == FALSE) && (strcmpi(RequestFields.MethodStr, "HEAD") != 0)) { 164 //Send generated data 153 165 SendData(RequestInfo->ClientSocket, (BYTE *) Body, BodyLength, RequestInfo->ThreadNum); 154 155 166 } 156 -
trunk/gsdl/src/w32server/wincgiutils.h
r611 r2286 1 /********************************************************************** 2 * 3 * wincgiutils.h 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 1 28 #define http_ok 0 2 29 #define http_error_url_invalid 11 3 30 4 5 int parse_url(char *url, 6 char **protocol, char **machine, int *port, char **name); 7 31 int parse_url(const text_t &url, text_t &protocol, text_t &machine, 32 int *port, text_t &name); 8 33 9 34 struct param_vals {char *name, *value; int vsize; char *dfault; };
Note:
See TracChangeset
for help on using the changeset viewer.