1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * httpsend.cpp
|
---|
4 | * Copyright (C) 1996
|
---|
5 | *
|
---|
6 | * A component of the fnord webserver written by [email protected].
|
---|
7 | *
|
---|
8 | * Altered for use with the Greenstone digital library software by the
|
---|
9 | * New Zealand Digital Library Project at the University of Waikato,
|
---|
10 | * New Zealand.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or modify
|
---|
13 | * it under the terms of the GNU General Public License as published by
|
---|
14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
15 | * (at your option) any later version.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful,
|
---|
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | * GNU General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, write to the Free Software
|
---|
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
25 | *
|
---|
26 | *********************************************************************/
|
---|
27 |
|
---|
28 | #include "text_t.h"
|
---|
29 |
|
---|
30 | #include <windows.h>
|
---|
31 | #include <stdlib.h>
|
---|
32 | #include <stdio.h>
|
---|
33 | #include <string.h>
|
---|
34 | #include <memory.h>
|
---|
35 | #pragma hdrstop
|
---|
36 | #include "netio.h"
|
---|
37 | #include "httpreq.h"
|
---|
38 | #include "httpsend.h"
|
---|
39 |
|
---|
40 | //Private Function Declarations
|
---|
41 | /*
|
---|
42 | Function Name: Check IMS Date
|
---|
43 | Purpose: Checks the string date of an "If Modified Since" header against
|
---|
44 | a file date stamp.
|
---|
45 | Parameters:
|
---|
46 | FileTime - Time stamp on file
|
---|
47 | IMSStr - "If Modified Since" date string
|
---|
48 | Returns: TRUE if the file has been modified since the given date or
|
---|
49 | the data can not be resolved (the string to date function will log
|
---|
50 | any errors)
|
---|
51 | */
|
---|
52 | BOOL CheckIMSDate(SYSTEMTIME &FileTime, char *IMSStr);
|
---|
53 |
|
---|
54 | //Public Functions
|
---|
55 | /******************************************************************************/
|
---|
56 |
|
---|
57 | void SendHTTPError(int ErrorNum, char *ErrorTitleStr, char *ErrorDescStr,
|
---|
58 | RequestInfoT &RequestInfo, RequestFieldsT &RequestFields) {
|
---|
59 | char Header[512];
|
---|
60 | char Body[512];
|
---|
61 |
|
---|
62 | char ErrorNumStr[17];
|
---|
63 |
|
---|
64 | DWORD BodyLength;
|
---|
65 | char BodyLengthStr[17];
|
---|
66 |
|
---|
67 | int HeaderLength;
|
---|
68 |
|
---|
69 | itoa(ErrorNum, ErrorNumStr, 10);
|
---|
70 |
|
---|
71 | // Didn't find it, build the message manually
|
---|
72 | Body[0] = 0;
|
---|
73 | strcat(Body, "<HTML><HEAD><TITLE>Server Error</TITLE></HEAD><BODY>\n");
|
---|
74 | strcat(Body, "<H1>Error ");
|
---|
75 | strcat(Body, ErrorNumStr);
|
---|
76 | strcat(Body, ": ");
|
---|
77 | strcat(Body, ErrorTitleStr);
|
---|
78 | strcat(Body, "</H1>\n");
|
---|
79 | strcat(Body, ErrorDescStr);
|
---|
80 | strcat(Body, "\n</BODY></HTML>");
|
---|
81 | BodyLength = (DWORD) strlen(Body);
|
---|
82 |
|
---|
83 | //Build Header
|
---|
84 | Header[0] = 0;
|
---|
85 | //Status Line
|
---|
86 | strcat(Header, "HTTP/1.0 ");
|
---|
87 | strcat(Header, ErrorNumStr);
|
---|
88 | strcat(Header, " ");
|
---|
89 | strcat(Header, ErrorDescStr);
|
---|
90 | strcat(Header, "\r\n");
|
---|
91 | //Server
|
---|
92 | strcat(Header, "Server: GSDL\r\n");
|
---|
93 | //Content Type (assume HTML)
|
---|
94 | strcat(Header, "Content-Type: text/html\r\n");
|
---|
95 | //Content Length
|
---|
96 | itoa(BodyLength, BodyLengthStr, 10);
|
---|
97 | strcat(Header, "Content-Length: ");
|
---|
98 | strcat(Header, BodyLengthStr);
|
---|
99 | strcat(Header, "\r\n");
|
---|
100 | //Single CRLF to end header
|
---|
101 | strcat(Header, "\r\n");
|
---|
102 |
|
---|
103 | HeaderLength = strlen(Header);
|
---|
104 |
|
---|
105 | //Send header
|
---|
106 | SendData(RequestInfo.ClientSocket, (BYTE *) Header, strlen(Header), RequestInfo.ThreadNum);
|
---|
107 | //Send generated data
|
---|
108 | SendData(RequestInfo.ClientSocket, (BYTE *) Body, BodyLength, RequestInfo.ThreadNum);
|
---|
109 | }
|
---|