Changeset 2286 for trunk/gsdl/src/w32server/wincgiutils.cpp
- Timestamp:
- 2001-04-05T17:08:52+12:00 (23 years ago)
- 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 1 28 #include <windows.h> 2 29 #include <string.h> 3 30 #include "netio.h" 4 31 #include "httpreq.h" 5 // #include "locate.h"6 32 #include "wincgiutils.h" 7 33 8 9 #define url_limit 25610 #define file_limit 102400 /*should be large enough for a header line*/11 34 #define default_http_port 80 12 35 36 // Attempt to break a url into segments. If the parsing fails, 'name' is 37 // left pointing to the unparsed portion. 38 int parse_url(const text_t &url, text_t &protocol, text_t &machine, 39 int *port, text_t &name) { 13 40 14 int parse_url(char *url, 15 char **protocol, char **machine, int *port, char **name) 16 /* Attempt to break a url into segments. If the parsing 17 fails, 'name' is left pointing to the unparsed portion. 18 This routine may extend the url string by one character */ 19 { 20 char next, thiss; 21 *protocol = *machine = ""; 41 protocol.clear(); 42 machine.clear(); 22 43 *port = default_http_port; 44 name.clear(); 23 45 24 *name = url; /* In case there is no protocol */25 while (*url != ':' && *url != 0) url++;26 if (*url == 0) return http_error_url_invalid;27 url++;28 if ( *url != '/') return http_error_url_invalid;29 *url++ = 0;30 i f (*url != '/') return http_error_url_invalid;31 url++;32 33 *protocol = *name;34 *machine = url;35 while (*url != ':' && *url != '/' && *url != 0) url++;36 if (*url == ':') { 37 *url = 0;38 url++; *port = 0;39 while (*url >= '0' && *url <= '9')40 *port = *port * 10 + (*url++ - '0');46 text_t::const_iterator begin = url.begin(); 47 text_t::const_iterator end = url.end(); 48 text_t::const_iterator it = findchar(begin, end, ':'); 49 if (it == end) {name = url; return http_error_url_invalid;} 50 if (substr(it+1, it+3) != "//") {name = url; return http_error_url_invalid;} 51 protocol = substr(begin, it); 52 it += 3; 53 while (it < end) { 54 if (*it == ':') { 55 it++; 56 text_t portstr; 57 while (it != end && (*it >= '0' && *it <= '9')) { 58 portstr.push_back(*it); 59 it++; 60 } 61 *port = portstr.getint(); 62 if (it == end) break; 41 63 } 42 if (*url == '/') { 43 *url++ = 0; 44 next = '/'; 45 *name = url; 46 while (*url != 0) { 47 thiss = *url; *url++ = next; next = thiss; } 48 *url++ = next; 49 *url = 0; 64 65 if (*it == '/') { 66 while (it != end) { 67 name.push_back(*it); 68 it++; 69 } 70 break; 50 71 } 51 else if (*url == 0) { 52 url++; 53 *name = url; 54 *url++ = '/'; 55 *url = 0; 56 } 57 else { 58 *name = url; 59 return http_error_url_invalid; 72 73 machine.push_back(*it); 74 it ++; 60 75 } 61 76 return http_ok; 62 77 } 63 64 65 66 78 67 79 int Send_String(char *str, RequestInfoT *RInfo) … … 80 92 { 81 93 char Header[1536]; int len, lenc; 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 94 //Build Header 95 Header[0] = 0; 96 //Status Line 97 if (content[0] != '@') /*No redirection needed*/ 98 strcat(Header, "HTTP/1.0 200 OK\r\n"); 99 else /*Redirection*/ 100 strcat(Header, "HTTP/1.0 302 Relocation\r\n"); 101 //Server 102 strcat(Header, "Server: GSDL\r\n"); 103 //Content Type 104 strcat(Header, "Content-type: "); 105 if (content[0] != '@') /*No redirection needed*/ 106 strcat(Header, content); 107 else { /*Redirection entry*/ 108 strcat(Header, "text/html \r\n"); 109 strcat(Header, "Location: "); 110 len = strlen(Header); 111 lenc = strlen(content) - 1; 112 strncpy(&Header[len], &content[1], lenc); 113 Header[len+lenc] = 0; 114 } 115 strcat(Header, " \r\n"); 116 //Single CRLF to end header 117 strcat(Header, "\r\n"); 118 119 return Send_String(Header, RequestInfo); 108 120 } 109 121 … … 112 124 char Header[512], Body[512], ErrorNumStr[17], BodyLengthStr[17]; 113 125 DWORD BodyLength; int HeaderLength; 114 126 115 127 itoa(error_num, ErrorNumStr, 10); 116 128 117 129 //Build Data (so we can determine length for the header) 118 130 Body[0] = 0; … … 149 161 //Send the file if we have one (and if it's not a HEAD request) 150 162 SendData(RequestInfo->ClientSocket, (BYTE *) Header, strlen(Header), RequestInfo->ThreadNum); 151 // if ((FileFound == FALSE) && (strcmpi(RequestFields.MethodStr, "HEAD") != 0)) {152 163 // if ((FileFound == FALSE) && (strcmpi(RequestFields.MethodStr, "HEAD") != 0)) { 164 //Send generated data 153 165 SendData(RequestInfo->ClientSocket, (BYTE *) Body, BodyLength, RequestInfo->ThreadNum); 154 155 166 } 156
Note:
See TracChangeset
for help on using the changeset viewer.