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