Changeset 2286

Show
Ignore:
Timestamp:
05.04.2001 17:08:52 (19 years ago)
Author:
sjboddie
Message:

Had a bit of a tidy up in the fnord webserver code. The main change of note
was the removal of our reliance on the MAX_URL_SIZE constant. URLs and post
data of any length should now work.

Location:
trunk/gsdl/src/w32server
Files:
22 modified

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/w32server/cgiwrapper.cpp

    r2280 r2286  
    172172  return 0; 
    173173} 
    174  
    175  
    176  
    177 #ifndef MAX_FILENAME_SIZE 
    178 #define MAX_FILENAME_SIZE 2048 
    179 #endif 
    180  
    181174 
    182175receptionist recpt; 
     
    580573 
    581574 
    582 static void rememberpref (char *tailstr) { 
    583  
    584   //  gsdl_enterlib = tailstr; 
    585 } 
    586  
    587  
    588 static void send_file_from_disk(char *filename, 
     575static void rememberpref (const text_t &tailstr) { 
     576  gsdl_enterlib = tailstr; 
     577} 
     578 
     579 
     580static void send_file_from_disk(text_t filename, 
    589581                                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  } 
    611624     
    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; 
    614630  if (thefile == NULL) { 
    615631    log_message("file not found\n"); 
     
    618634    return; 
    619635  } 
    620    
     636 
     637  int nr; 
    621638  char buffer[2048]; 
    622639  // send back required information 
    623   if (send_header(kind, RInfo) >= 0) { 
     640  char *mimec = mime.getcstr(); 
     641  if (send_header(mimec, RInfo) >= 0) { 
    624642    if (strcmpi(RFields->MethodStr, "HEAD") != 0) { 
    625643      for (;;) { 
     
    632650    } 
    633651  } 
     652  delete mimec; 
    634653  fclose(thefile); 
    635654} 
    636655 
    637 static void handle_library_request(char *TailStr, RequestInfoT *RInfo, 
     656static void handle_library_request(const text_t &argstr, RequestInfoT *RInfo, 
    638657                   RequestFieldsT *RequestFields) { 
    639   // check for a "?" at the start of the tail string 
    640   if (*TailStr == '?') TailStr++; 
    641  
    642   outconvertclass text_t2ascii; 
    643    
     658 
    644659  // parse the cgi arguments and produce the resulting page if there 
    645   // has been no errors so far 
     660  // have been no errors so far 
    646661  cgiargsclass args; 
    647662  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)) { 
    649664    page_errorparseargs(gsdl_gsdlhome); 
    650665    return; 
     
    700715} 
    701716 
    702 static void handle_server_request(char *initialTailStr,  
     717static void handle_server_request(text_t &tailstr, 
    703718                  RequestInfoT *RequestInfo, 
    704719                  RequestFieldsT *RequestFields) { 
    705   char tmpstr[MAX_URL_SIZE+1024]; 
    706   char tailstr[MAX_URL_SIZE+16]; 
    707    
     720   
     721  text_t argstr; 
     722 
    708723  // 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(); 
    712730   
    713731  // test to see if this is a library request or a local 
    714732  // 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 
    717737    // library request 
    718738     
     739    // argstr is the bit after the '?' 
     740    if (tailstr != "/cgi-bin/gw") { 
     741      argstr = substr(begin+12, end); 
     742    } 
     743 
    719744    // log the difference in access times 
    720745    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); 
    724750    } 
    725751    lastlibaccesstime = thislibaccesstime; 
    726752     
    727753    // 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); 
    734762     
    735763    // remember the preferences 
    736     rememberpref (tailstr); 
     764    // rememberpref (tailstr); 
    737765     
    738766    // log memory information 
    739     if (gsdl_keep_log||gsdl_show_console) { 
     767    if (gsdl_keep_log || gsdl_show_console) { 
    740768      MEMORYSTATUS memstatus; 
    741769      memstatus.dwLength = sizeof(MEMORYSTATUS); 
    742770      GlobalMemoryStatus(&memstatus); 
    743       sprintf (tmpstr, "BDELTA AVAIL VIRTUAL: %i K\n",  
     771      char logstr[256]; 
     772      sprintf (logstr, "BDELTA AVAIL VIRTUAL: %i K\n",  
    744773           (int)((baseavailvirtual - memstatus.dwAvailVirtual)/1024)); 
    745       log_message (tmpstr); 
     774      log_message (logstr); 
    746775    } 
    747776     
    748777  } else { 
    749778    // 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; 
    753784    } 
    754785    send_file_from_disk (tailstr, RequestInfo, RequestFields); 
    755786  } 
    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   else 
    765     strcat(dest,suff); 
    766787} 
    767788 
     
    769790          RequestFieldsT *RequestFields) 
    770791{ 
    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; 
    773794 
    774795  if (RequestFields->ContentLength > 0) { 
    775796    // POST data 
    776797    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") { 
    810811    // a local file request 
    811812    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 bmorin@wpi.edu. 
     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 
    128#include <windows.h> 
    229#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 bmorin@wpi.edu. 
     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 
    128#ifndef D_WINSOCK_H 
    229#define D_WINSOCK_H 
    330 
    4  
    531/* get most definitions from the real winsock */ 
    632#include <winsock.h> 
    7  
    833 
    934#define D_NOERROR           0 
     
    1237#define D_ERR_FREELIBFAILED 3 
    1338 
    14  
    15  
    1639// d_LoadWinsock must be called before an normal winsock 
    1740// functions 
    18  
    1941 
    2042// expects path to be NULL, a empty string, or a path which ends in a slash 
     
    2648// D_ERR_FREELIBFAILED on failure 
    2749int d_UnloadWinsock (); 
    28  
    2950 
    3051// dynamically loaded versions of the winsock functions 
     
    97118             long lEvent); 
    98119 
    99  
    100  
    101  
    102  
    103120#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 bmorin@wpi.edu 
    19 */ 
     1/********************************************************************** 
     2 * 
     3 * fnord.cpp 
     4 * Copyright (C) 1996 
     5 *  
     6 * A component of the fnord webserver written by bmorin@wpi.edu. 
     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 
    2028#include "text_t.h" 
    2129#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 bmorin@wpi.edu 
    19 */ 
     1/********************************************************************** 
     2 * 
     3 * httpreq.cpp 
     4 * Copyright (C) 1996 
     5 *  
     6 * A component of the fnord webserver written by bmorin@wpi.edu. 
     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 
    2028#include "text_t.h" 
    2129#include <windows.h> 
     
    303311      if (RequestFields.AcceptStr[0] == '\0') { 
    304312        strncpy(RequestFields.AcceptStr, FieldValStr, ReqAcceptStrLen - 1); 
    305     //          if (Len >= ReqAcceptStrLen) 
    306     //        if (log_debug) log_message("Accept field truncated"); 
    307313      } 
    308314      else { 
     
    317323    else if (strcmp("DATE:", FieldNameStr) == 0) { 
    318324      strncpy(RequestFields.DateStr, FieldValStr, ReqDateStrLen - 1); 
    319       //            if (Len >= ReqDateStrLen) LogError("Date field truncated"); 
    320325    } 
    321326    else if (strcmp("USER-AGENT:", FieldNameStr) == 0) { 
    322327      strncpy(RequestFields.UserAgentStr, FieldValStr, ReqUserAgentStrLen - 1); 
    323       //            if (Len >= ReqUserAgentStrLen) { 
    324       //            LogError("User Agent field truncated, value follows"); 
    325       //            LogError(RequestFields.UserAgentStr); 
    326       //            } 
    327328    } 
    328329    else if (strcmp("CONNECTION:", FieldNameStr) == 0) { 
    329330      strncpy(RequestFields.ConnectionStr, FieldValStr, ReqConnectionStrLen - 1); 
    330       //            if (Len >= ReqConnectionStrLen) LogError("Connection field truncated"); 
    331331    } 
    332332    //--Sometimes-- 
    333333    else if (strcmp("ACCEPT-LANGUAGE:", FieldNameStr) == 0) { 
    334334      strncpy(RequestFields.AcceptLangStr, FieldValStr, ReqAcceptLangStrLen - 1); 
    335       //            if (Len >= ReqAcceptLangStrLen) LogError("Accept-Language field truncated"); 
    336335    } 
    337336    else if (strcmp("REFERER:", FieldNameStr) == 0) { 
    338337      strncpy(RequestFields.RefererStr, FieldValStr, ReqRefererStrLen - 1); 
    339       //            if (Len >= ReqRefererStrLen) LogError("Referer field truncated"); 
    340338    } 
    341339    else if (strcmp("IF-MODIFIED-SINCE:", FieldNameStr) == 0) { 
    342340      strncpy(RequestFields.IfModSinceStr, FieldValStr, ReqIfModSinceStrLen - 1); 
    343       //            if (Len >= ReqIfModSinceStrLen) LogError("If Modified Since field truncated"); 
    344341    } 
    345342    //--Uncommon-- 
    346343    else if (strcmp("FROM:", FieldNameStr) == 0) { 
    347344      strncpy(RequestFields.FromStr, FieldValStr, ReqFromStrLen - 1); 
    348       //            if (Len >= ReqFromStrLen) LogError("From field truncated"); 
    349345    } 
    350346    else if (strcmp("MIME-VERSION:", FieldNameStr) == 0) { 
    351347      strncpy(RequestFields.MIMEVerStr, FieldValStr, ReqMIMEVerStrLen - 1); 
    352       //            if (Len >= ReqMIMEVerStrLen) LogError("MIME Version field truncated"); 
    353348    } 
    354349    else if (strcmp("PRAGMA:", FieldNameStr) == 0) { 
    355350      strncpy(RequestFields.PragmaStr, FieldValStr, ReqPragmaStrLen - 1); 
    356       //            if (Len >= ReqPragmaStrLen) LogError("Pragma field truncated"); 
    357351    } 
    358352    //--Special case-- 
    359353    else if (strcmp("AUTHORIZATION:", FieldNameStr) == 0) { 
    360354      strncpy(RequestFields.AuthorizationStr, FieldValStr, ReqAuthorizationStrLen - 1); 
    361       //            if (Len >= ReqAuthorizationStrLen) LogError("Authorization field truncated"); 
    362355    } 
    363356    else if (strcmp("CONTENT-LENGTH:", FieldNameStr) == 0) { 
    364357      strncpy(RequestFields.ContentLengthStr, FieldValStr, ReqContentLengthStrLen - 1); 
    365       //            if (Len >= ReqContentLengthStrLen) LogError("Content Length field truncated"); 
    366358    } 
    367359    else if (strcmp("CONTENT-TYPE:", FieldNameStr) == 0) { 
    368360      strncpy(RequestFields.ContentTypeStr, FieldValStr, ReqContentTypeStrLen - 1); 
    369       //            if (Len >= ReqContentTypeStrLen) LogError("Content Type field truncated"); 
    370361    } 
    371362    else if (strcmp("CONTENT-ENCODING:", FieldNameStr) == 0) { 
    372363      strncpy(RequestFields.ContentEncodingStr, FieldValStr, ReqContentEncodingStrLen - 1); 
    373       //            if (Len >= ReqContentEncodingStrLen) LogError("Content Encoding field truncated"); 
    374364    } 
    375365    else { 
     
    390380  } 
    391381   
    392    
    393382  if (RequestFields.ContentLengthStr[0] != 0) { //Do we have attached data? 
    394383    unsigned int NumRecv; 
     
    396385    RequestFields.ContentLength = atol(RequestFields.ContentLengthStr); 
    397386    if (RequestFields.ContentLength > 0) { 
    398       //            ThreadDebugMessage(RequestInfo.ThreadNum, "Getting content"); 
    399387       
    400388      //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 bmorin@wpi.edu. 
     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 
    128#ifndef HTTPREQ_H 
    229#define HTTPREQ_H 
     
    633 
    734/* 
    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 bmorin@wpi.edu 
    25 */ 
    26  
    27 /* 
    28 Module Name: HTTP Reqeust 
     35Module Name: HTTP Request 
    2936Purpose: Parses HTTP requests and then calls the appropriate function 
    3037    to respond to the request 
     
    3744//Used for sending information to the request thread 
    3845struct RequestThreadMessageT { 
    39     SOCKADDR_IN ClientSockAddr; 
    40     SOCKET ClientSocket; 
    41     int AddrLen; 
    42     }; 
     46  SOCKADDR_IN ClientSockAddr; 
     47  SOCKET ClientSocket; 
     48  int AddrLen; 
     49}; 
    4350 
    4451//Length constants for RequestFieldsT 
    4552#define ReqMethodStrLen           24 
    46 //#define ReqURIStrLen             255 
    4753#define ReqVersionStrLen          24 
    4854#define ReqDateStrLen             48 
     
    6470#define ReqPathTranslatedStrLen  512 
    6571#define ReqScriptNameStrLen      512 
    66 //                               --- 
    67 //                              4436 
    6872 
    6973#define MAX_OTHER_HEADERS 100 
     
    7781  //Simple request line info v0.9 
    7882  char MethodStr[ReqMethodStrLen]; 
    79   //    char URIStr[ReqURIStrLen]; 
    8083  text_t URIStr; 
    8184  //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 bmorin@wpi.edu. 
     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 *********************************************************************/ 
    327 
    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 bmorin@wpi.edu 
    19 */ 
    2028#include <windows.h> 
    2129#include <stdlib.h> 
     
    4553/******************************************************************************/ 
    4654 
    47 void SendHTTPError(int ErrorNum, char *ErrorTitleStr, char *ErrorDescStr, RequestInfoT &RequestInfo, RequestFieldsT &RequestFields) 
    48 { 
    49     char Header[512]; 
    50     char Body[512]; 
     55void SendHTTPError(int ErrorNum, char *ErrorTitleStr, char *ErrorDescStr,  
     56           RequestInfoT &RequestInfo, RequestFieldsT &RequestFields) { 
     57  char Header[512]; 
     58  char Body[512]; 
    5159 
    52     char ErrorNumStr[17]; 
     60  char ErrorNumStr[17]; 
     61   
     62  DWORD BodyLength; 
     63  char BodyLengthStr[17]; 
    5364 
    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); 
    5680 
    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   
    95103  //Send header 
    96104  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 bmorin@wpi.edu 
    19 */ 
     1/********************************************************************** 
     2 * 
     3 * httpsend.h 
     4 * Copyright (C) 1996 
     5 *  
     6 * A component of the fnord webserver written by bmorin@wpi.edu. 
     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 *********************************************************************/ 
    2027 
    2128/* 
     
    3643Parameters: 
    3744    ErrorNum - HTTP error number to send 
    38   ErrorTitleStr - Title of the error 
     45    ErrorTitleStr - Title of the error 
    3946    ErrorDescStr - String describing the error 
    4047    RequestInfo - HTTP request information (see httpreq.h) 
    4148    RequestFields - Parsed HTTP header info (see httpreq.h) 
    4249*/ 
    43 void SendHTTPError(int ErrorNum, char *ErrorTitleStr, char *ErrorDescStr, RequestInfoT &RequestInfo, RequestFieldsT &RequestFields); 
     50void 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 bmorin@wpi.edu. 
     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 *********************************************************************/ 
    327 
    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 bmorin@wpi.edu 
    19 */ 
    2028#include "text_t.h" 
    2129#include <windows.h> 
     
    4755// returns 0 on success, and a WSA error otherwise 
    4856int StartHTTPServer(HWND PassedMsgWindow) { 
    49  
     57   
    5058  MsgWindow = PassedMsgWindow; 
    5159  //Create the server socket 
     
    6270/******************************************************************************/ 
    6371void ProcessHTTPServerMsg(WPARAM Socket, LPARAM MsgInfo) { 
    64     log_message("accept message arrived\n"); 
    65     if (Socket != ServerSocket) { 
    66         if (gsdl_keep_log || gsdl_show_console) log_message("Incorrect socket sent in message"); 
    67         } 
    68     switch (WSAGETSELECTEVENT(MsgInfo)) { 
    69         case FD_ACCEPT: 
    70             switch (WSAGETSELECTERROR(MsgInfo)) { 
    71                 case WSAENETDOWN: 
    72                     LogCriticalError("1","Network Down"); 
    73                     break; 
    74                 default: //No Error 
    75                     HTTPServerAnswer(); 
    76                 } 
    77             break; 
    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  } 
    7987} 
    8088 
    8189/******************************************************************************/ 
    8290void HTTPServerAnswer() { 
    83     SOCKADDR_IN ClientSockAddr; 
    84     SOCKET ClientSocket; 
    85     int AddrLen = sizeof(SOCKADDR_IN); 
    86     RequestThreadMessageT Parameters; 
     91  SOCKADDR_IN ClientSockAddr; 
     92  SOCKET ClientSocket; 
     93  int AddrLen = sizeof(SOCKADDR_IN); 
     94  RequestThreadMessageT Parameters; 
    8795  while (AnswerListeningSocket(ServerSocket, ClientSocket, ClientSockAddr, AddrLen) == 0) { 
    8896    log_message("Answering socket\n"); 
    89       //Call the thread procedure to handle the connection 
     97    //Call the thread procedure to handle the connection 
    9098    Parameters.ClientSockAddr = ClientSockAddr; 
    91     Parameters.ClientSocket = ClientSocket; 
    92     Parameters.AddrLen = AddrLen; 
     99    Parameters.ClientSocket = ClientSocket; 
     100    Parameters.AddrLen = AddrLen; 
    93101    RequestThread(&Parameters); 
    94102  } 
    95103} 
    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 bmorin@wpi.edu. 
     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 *********************************************************************/ 
    327 
    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 bmorin@wpi.edu 
    19 */ 
    2028#define HTTP_SERVER_MSG WM_USER + 23 
    2129 
    2230/* 
    2331Function Name: Start HTTP Server 
    24 Purpose: Starts the HTTP server.  Inits Winsock, MIME, loads registry stuff, 
    25             etc. 
     32 
     33Purpose: Starts the HTTP server.  Inits Winsock, MIME, loads registry 
     34         stuff, etc. 
     35 
    2636Parameters: 
    2737    PassedMsgWindow - The handle of the window that handles messages.  Needed 
    28                             to setup WSASelect notification of socket events and 
    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 
    3141// returns 0 on success, and a WSA error otherwise 
    3242int 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 bmorin@wpi.edu. 
     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 
    128#include "text_t.h" 
    229#include <windows.h> 
     
    1441 
    1542static int location_found=0; 
    16 char data_location[MAX_URL_SIZE]; 
     43char data_location[MAX_FILENAME_SIZE]; 
    1744 
    1845void set_location(char *possible) 
     
    2451      strcat(data_location,"\\"); 
    2552    location_found = 1; 
    26     } 
     53  } 
    2754} 
    2855 
     
    3158  char *send; 
    3259  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) 
    3461    send = data_location; 
    3562  else { 
     
    188215    fprintf(log_file,"%s",msg); 
    189216    fflush(log_file); 
    190     } 
     217  } 
    191218  if (gsdl_show_console) { 
    192219    char buffer[1024];  HDC dc; 
     
    195222    display_text(dc,buffer); 
    196223    ReleaseDC(GSDL_Window,dc); 
    197     } 
     224  } 
    198225} 
    199226 
     
    201228{ 
    202229  if (log_file != NULL) { 
    203       int len = 0; 
    204       while (len < n) { 
    205           fputc (msg[len], log_file); 
    206           len++; 
    207       } 
    208       fflush(log_file); 
    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   
    211238  // these messages are not send to the console 
    212239  if (gsdl_show_console) { 
     
    215242    display_text(dc,"message only written to log file\n"); 
    216243    ReleaseDC(GSDL_Window,dc); 
    217     } 
     244  } 
    218245} 
    219246 
    220247void LogCriticalError(char *cderr, char *Msg) 
    221248{ 
    222     char MsgBoxStr[200]; 
    223  
    224     strcpy(MsgBoxStr, "Critical Error Number "); 
    225     strcat(MsgBoxStr, cderr); 
    226     strcat(MsgBoxStr, "\n"); 
    227     strcat(MsgBoxStr, Msg); 
    228     strcat(MsgBoxStr, "\nGreenstone Digital Library software\nshutting down"); 
    229     MessageBox(GSDL_Window, MsgBoxStr, "Greenstone Digital Library Software", 
    230         MB_OK | MB_ICONERROR); 
    231     PostMessage(GSDL_Window, WM_DESTROY, 0, 0); 
     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); 
    232259} 
    233260 
     
    236263DWORD DiffTickCounts (DWORD first, DWORD second)  
    237264{ 
    238     if (second >= first) return (second-first); 
    239     return (MAXDWORD-first+1+second); 
    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 bmorin@wpi.edu. 
     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 
    431 
    532extern HWND GSDL_Window; 
     
    936void refresh_console(HDC dc); 
    1037 
    11  
    12 extern char data_location[MAX_URL_SIZE]; 
     38extern char data_location[MAX_FILENAME_SIZE]; 
    1339 
    1440extern 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 bmorin@wpi.edu 
    19 */ 
     1/********************************************************************** 
     2 * 
     3 * netio.cpp 
     4 * Copyright (C) 1996 
     5 *  
     6 * A component of the fnord webserver written by bmorin@wpi.edu. 
     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 *********************************************************************/ 
    2027 
    2128#include <windows.h> 
     
    4148int dns_msg_error = 0; 
    4249 
    43  
    4450DWORD LocalIPNumber; 
    4551char LocalName[MAXHOSTNAME]; 
    4652 
    47  
    4853//Private Function Declarations 
    4954DWORD GetHostID(); 
    50  
    5155 
    5256// returns 0 on success, 
    5357// WSASYSNOTREADY, WSAVERNOTSUPPORTED, or WSAEINVAL on failure 
    5458int 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 
     75void 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 
     85void ResetNetIO() { 
     86  //Figure out the local name on first querry, set to "" until then... 
     87  LocalName[0] = 0; 
     88} 
     89 
     90 
     91DWORD GetLocalIP() { 
     92  return LocalIPNumber; 
     93} 
     94 
     95long __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 
     105char *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]; 
    66109     
    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); 
    100177    } 
    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; 
    195193} 
    196194 
     
    203201 
    204202#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++; 
     203int 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 
     254int 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 
     271void 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 
     279void 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 
     294int 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; 
    238324    } 
    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 
     335int 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 
     366int 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; 
    259397    } 
    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} 
    414408 
    415409 
     
    433427 */ 
    434428DWORD 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 bmorin@wpi.edu 
    19 */ 
     1/********************************************************************** 
     2 * 
     3 * netio.h 
     4 * Copyright (C) 1996 
     5 *  
     6 * A component of the fnord webserver written by bmorin@wpi.edu. 
     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 *********************************************************************/ 
    2027 
    2128/* 
     
    5158Function Name: Init Net IO 
    5259Purpose: Initializes the module so calls can be made querying network 
    53     information for the local macnine. 
     60         information for the local macnine. 
    5461Notes: MUST be called before GetLocalIP and GetLocalName 
    5562*/ 
     
    9198// WSAENOBUFS, WSAEPROTONOSUPPORT, WSAEPROTOTYPE, WSAESOCKTNOSUPPORT, 
    9299// WSAEADDRINUSE, WSAEINVAL, WSAEISCONN, WSAENOTSOCK, WSAEOPNOTSUPP 
    93 int CreateListeningSocket(int &PortNum, HWND MsgWindow, WORD SocketMsg, SOCKET &ServerSocket); 
     100int CreateListeningSocket(int &PortNum, HWND MsgWindow,  
     101              WORD SocketMsg, SOCKET &ServerSocket); 
    94102 
    95 int AnswerListeningSocket(SOCKET ServerSocket, SOCKET &ClientSocket, SOCKADDR_IN &ClientSockAddr, int AddrLen); 
     103int AnswerListeningSocket(SOCKET ServerSocket, SOCKET &ClientSocket,  
     104              SOCKADDR_IN &ClientSockAddr, int AddrLen); 
    96105 
    97106void DestroyListeningSocket(SOCKET &ServerSocket, HWND MsgWindow); 
     
    132141Returns: -1 on disconnect or error (abort connection), 0 on success 
    133142*/ 
    134 int GetLine(char *OutStr, SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, int &BufferIndex, int &DataInBuffer, int ThreadNum); 
     143int GetLine(char *OutStr, SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize,  
     144        int &BufferIndex, int &DataInBuffer, int ThreadNum); 
    135145 
    136146/* 
     
    149159errors I was getting when getting a "rude" disconnect 
    150160*/ 
    151 int SendData(SOCKET ClientSocket, BYTE *SendBuffer, int NumToSend, int ThreadNum); 
     161int 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 bmorin@wpi.edu. 
     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 *********************************************************************/ 
    327 
    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 bmorin@wpi.edu 
    19 */ 
    2028#include <windows.h> 
    2129#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 bmorin@wpi.edu 
    19 */ 
     1/********************************************************************** 
     2 * 
     3 * parse.h 
     4 * Copyright (C) 1996 
     5 *  
     6 * A component of the fnord webserver written by bmorin@wpi.edu. 
     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 *********************************************************************/ 
    2027 
    2128/* 
     
    102109         occur. 
    103110*/ 
    104 void GetWord(char *DestStr, const char *SourceStr, const int Start, int &End); 
     111void GetWord(char *DestStr, const char *SourceStr,  
     112         const int Start, int &End); 
    105113 
    106114/* 
  • 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 bmorin@wpi.edu. 
     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 
    128#include "text_t.h" 
    229 
  • 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 bmorin@wpi.edu. 
     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 
    128#ifndef SETTINGS_H 
    229#define SETTINGS_H 
    3  
    4 #ifndef MAX_FILENAME_SIZE 
    5 #define MAX_FILENAME_SIZE 1024 
    6 #endif 
    730 
    831#define GS_NETSCAPE 0 
     
    1336#include "cfgread.h" 
    1437#include "receptionist.h" 
     38#include "locate.h" 
    1539 
    1640// 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 
    126#include "startbrowser.h" 
    227#include <windows.h> 
     
    2146static HSZ hszActivateTopic = NULL; 
    2247 
    23  
    2448// budget callback 
    2549HDDEDATA CALLBACK DdeCallback(UINT uType,     /* transaction type                 */ 
    26                               UINT uFmt,      /* clipboard data format            */ 
    27                               HCONV hconv,    /* handle of conversation           */ 
    28                               HSZ hsz1,       /* handle of string                 */ 
    29                               HSZ hsz2,       /* handle of string                 */ 
    30                               HDDEDATA hdata, /* handle of global memory object   */ 
    31                               DWORD dwData1,  /* transaction-specific data        */ 
    32                               DWORD dwData2)  /* transaction-specific data        */  
     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        */  
    3357{ 
    34     return (HDDEDATA) NULL;  
    35 } 
    36  
     58  return (HDDEDATA) NULL;  
     59} 
    3760 
    3861// returns 0 on failure 
    3962static 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} 
    7289 
    7390// returns 0 on failure 
    7491static int openurl(HSZ hszServName, HSZ hszActivateTopic, HSZ hszOpenURLTopic, char *url) { 
    75     char requeststr[65600]; 
    76  
    77     // bring the browser to the front, don't worry if this fails 
    78     talkdde (hszServName, hszActivateTopic, "0xFFFFFFFF,0x0"); 
    79  
    80     // tell the browser to open a url 
    81     strcpy (requeststr, "\""); 
    82     strcat (requeststr, url); 
    83     strcat (requeststr, "\",,0xFFFFFFFF,0x0,,,"); 
    84  
    85     return talkdde (hszServName, hszOpenURLTopic, requeststr); 
     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); 
    86103} 
    87104 
    88105// returns 0 on failure 
    89106static int tryconnect(HSZ hszServName, HSZ hszSysTopic) { 
    90     // try to connect to a running browser 
    91     HCONV hConv = DdeConnect (idInst, hszServName, hszSysTopic, (PCONVCONTEXT) NULL); 
    92     if (hConv == NULL) return 0; 
    93     DdeDisconnect(hConv); 
    94     return 1; 
     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; 
    95112} 
    96113 
    97114static 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} 
    110125 
    111126static 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} 
    122135 
    123136// returns SB_NOERROR on success,  
    124137// SB_ALREADYINIT or SB_DDE_FAILINIT on failure 
    125138int 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; 
    142154} 
    143155 
     
    146158// SB_DDE_FAILDEINIT of failure 
    147159int deinitstartbrowser () { 
    148     // make sure this has been inited 
    149     // not being inited here, however, is not 
    150     // important 
    151     if (!inited) return SB_NOERROR; 
    152     inited = 0; 
    153  
    154     freestrings(); 
    155  
    156     if (DdeUninitialize(idInst)) return SB_NOERROR; 
    157  
    158     return SB_DDE_FAILDEINIT; 
     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; 
    159171} 
    160172 
     
    166178// SB_FAILCONNECTBROWSER on failure 
    167179int 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} 
    255265 
    256266// returns SB_NOERROR on success, 
    257267// SB_NOTINITED, SB_FAILCONNECTBROWSER on failure 
    258268int browserrunning (char *browser_exe) { 
    259     char newcommand[SB_COMLEN]; 
    260     if (!inited) return SB_NOTINITED; // has to be inited first 
    261  
    262     strcpy (newcommand, browser_exe); 
    263     _strlwr (newcommand); 
    264  
    265     if ((strstr (newcommand, "netscape.exe") != NULL) && (hszNetscapeName != NULL) &&  
    266             tryconnect(hszNetscapeName, hszOpenURLTopic)) { 
    267         // succeeded connecting to netscape 
    268         return SB_NOERROR; 
    269  
    270     } else if ((strstr (newcommand, "iexplore.exe") != NULL) && (hszIExploreName != NULL) &&  
    271             tryconnect(hszIExploreName, hszOpenURLTopic)) { 
    272         // succeeded connecting to internet explorer 
    273         return SB_NOERROR; 
    274     } 
    275  
    276     return SB_FAILCONNECTBROWSER; 
    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 
    126#define SB_NOERROR            0 
    227#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 bmorin@wpi.edu. 
     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 
    128#include <windows.h> 
    229#include <string.h> 
    330#include "netio.h" 
    431#include "httpreq.h" 
    5 // #include "locate.h" 
    632#include "wincgiutils.h" 
    733 
    8  
    9 #define url_limit 256 
    10 #define file_limit 102400   /*should be large enough for a header line*/ 
    1134#define default_http_port 80 
    1235 
     36// Attempt to break a url into segments. If the parsing fails, 'name' is 
     37// left pointing to the unparsed portion. 
     38int parse_url(const text_t &url, text_t &protocol, text_t &machine,  
     39          int *port, text_t &name) { 
    1340 
    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(); 
    2243  *port = default_http_port; 
     44  name.clear(); 
    2345   
    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   if (*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; 
    4163    } 
    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; 
    5071    } 
    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 ++; 
    6075  } 
    6176  return http_ok; 
    6277} 
    63  
    64  
    65  
    6678 
    6779int Send_String(char *str, RequestInfoT *RInfo) 
     
    8092{ 
    8193  char Header[1536];  int len, lenc; 
    82     //Build Header 
    83     Header[0] = 0; 
    84     //Status Line 
    85     if (content[0] != '@')          /*No redirection needed*/ 
    86       strcat(Header, "HTTP/1.0 200 OK\r\n"); 
    87     else                            /*Redirection*/ 
    88       strcat(Header, "HTTP/1.0 302 Relocation\r\n"); 
    89     //Server 
    90     strcat(Header, "Server: GSDL\r\n"); 
    91     //Content Type 
    92     strcat(Header, "Content-type: "); 
    93     if (content[0] != '@')          /*No redirection needed*/ 
    94       strcat(Header, content); 
    95     else {                          /*Redirection entry*/ 
    96       strcat(Header, "text/html \r\n"); 
    97       strcat(Header, "Location: "); 
    98       len = strlen(Header); 
    99       lenc = strlen(content) - 1; 
    100       strncpy(&Header[len], &content[1], lenc); 
    101       Header[len+lenc] = 0; 
    102       } 
    103     strcat(Header, " \r\n"); 
    104     //Single CRLF to end header 
    105     strcat(Header, "\r\n"); 
    106  
    107    return Send_String(Header, RequestInfo); 
     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); 
    108120} 
    109121 
     
    112124  char Header[512], Body[512], ErrorNumStr[17], BodyLengthStr[17]; 
    113125  DWORD BodyLength; int HeaderLength; 
    114  
     126   
    115127  itoa(error_num, ErrorNumStr, 10); 
    116  
     128   
    117129  //Build Data (so we can determine length for the header) 
    118130  Body[0] = 0; 
     
    149161   //Send the file if we have one (and if it's not a HEAD request) 
    150162  SendData(RequestInfo->ClientSocket, (BYTE *) Header, strlen(Header), RequestInfo->ThreadNum); 
    151 //   if ((FileFound == FALSE) && (strcmpi(RequestFields.MethodStr, "HEAD") != 0)) { 
    152     //Send generated data 
     163  //   if ((FileFound == FALSE) && (strcmpi(RequestFields.MethodStr, "HEAD") != 0)) { 
     164  //Send generated data 
    153165  SendData(RequestInfo->ClientSocket, (BYTE *) Body, BodyLength, RequestInfo->ThreadNum); 
    154  
    155166} 
    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 bmorin@wpi.edu. 
     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 
    128#define http_ok 0 
    229#define http_error_url_invalid 11 
    330 
    4  
    5 int parse_url(char *url, 
    6           char **protocol, char **machine, int *port, char **name); 
    7  
     31int parse_url(const text_t &url, text_t &protocol, text_t &machine,  
     32          int *port, text_t &name); 
    833 
    934struct param_vals {char *name, *value; int vsize; char *dfault; };