Ignore:
Timestamp:
2001-04-05T17:08:52+12:00 (23 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.

File:
1 edited

Legend:

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

    r611 r2286  
     1/**********************************************************************
     2 *
     3 * wincgiutils.cpp
     4 * Copyright (C) 1996
     5 *
     6 * A component of the fnord webserver written by [email protected].
     7 *
     8 * Altered for use with the Greenstone digital library software by the
     9 * New Zealand Digital Library Project at the University of Waikato,
     10 * New Zealand.
     11 *
     12 * This program is free software; you can redistribute it and/or modify
     13 * it under the terms of the GNU General Public License as published by
     14 * the Free Software Foundation; either version 2 of the License, or
     15 * (at your option) any later version.
     16 *
     17 * This program is distributed in the hope that it will be useful,
     18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     20 * GNU General Public License for more details.
     21 *
     22 * You should have received a copy of the GNU General Public License
     23 * along with this program; if not, write to the Free Software
     24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     25 *
     26 *********************************************************************/
     27
    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 
Note: See TracChangeset for help on using the changeset viewer.