source: trunk/gsdl/src/w32server/httpsend.cpp@ 2280

Last change on this file since 2280 was 2280, checked in by sjboddie, 23 years ago

In the process of making some changes to the old fnord webserver code.
Note that this version is BROKEN, I just committed it so I could continue
the work I've been doing on my home PC at work.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1/*
2Copyright (C) 1996
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18The 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 "netio.h"
27#include "httpreq.h"
28#include "httpsend.h"
29
30//Private Function Declarations
31/*
32Function Name: Check IMS Date
33Purpose: Checks the string date of an "If Modified Since" header against
34 a file date stamp.
35Parameters:
36 FileTime - Time stamp on file
37 IMSStr - "If Modified Since" date string
38Returns: TRUE if the file has been modified since the given date or
39 the data can not be resolved (the string to date function will log
40 any errors)
41*/
42BOOL CheckIMSDate(SYSTEMTIME &FileTime, char *IMSStr);
43
44//Public Functions
45/******************************************************************************/
46
47void SendHTTPError(int ErrorNum, char *ErrorTitleStr, char *ErrorDescStr, RequestInfoT &RequestInfo, RequestFieldsT &RequestFields)
48{
49 char Header[512];
50 char Body[512];
51
52 char ErrorNumStr[17];
53
54 DWORD BodyLength;
55 char BodyLengthStr[17];
56
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
95 //Send header
96 SendData(RequestInfo.ClientSocket, (BYTE *) Header, strlen(Header), RequestInfo.ThreadNum);
97 //Send generated data
98 SendData(RequestInfo.ClientSocket, (BYTE *) Body, BodyLength, RequestInfo.ThreadNum);
99}
Note: See TracBrowser for help on using the repository browser.