1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * httpreq.h
|
---|
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 | #ifndef HTTPREQ_H
|
---|
29 | #define HTTPREQ_H
|
---|
30 |
|
---|
31 | #include "locate.h"
|
---|
32 | #include "text_t.h"
|
---|
33 |
|
---|
34 | /*
|
---|
35 | Module Name: HTTP Request
|
---|
36 | Purpose: Parses HTTP requests and then calls the appropriate function
|
---|
37 | to respond to the request
|
---|
38 | Public Functions:
|
---|
39 | Request Thread
|
---|
40 | */
|
---|
41 |
|
---|
42 | // Public Data Structures
|
---|
43 |
|
---|
44 | //Used for sending information to the request thread
|
---|
45 | struct RequestThreadMessageT {
|
---|
46 | SOCKADDR_IN ClientSockAddr;
|
---|
47 | SOCKET ClientSocket;
|
---|
48 | int AddrLen;
|
---|
49 | };
|
---|
50 |
|
---|
51 | //Length constants for RequestFieldsT
|
---|
52 | #define ReqMethodStrLen 24
|
---|
53 | #define ReqVersionStrLen 24
|
---|
54 | #define ReqDateStrLen 48
|
---|
55 | #define ReqMIMEVerStrLen 24
|
---|
56 | #define ReqPragmaStrLen 128
|
---|
57 | #define ReqAuthorizationStrLen 512
|
---|
58 | #define ReqFromStrLen 128
|
---|
59 | #define ReqIfModSinceStrLen 48
|
---|
60 | #define ReqRefererStrLen 512
|
---|
61 | #define ReqUserAgentStrLen 256
|
---|
62 | #define ReqContentEncodingStrLen 128
|
---|
63 | #define ReqContentTypeStrLen 128
|
---|
64 | #define ReqContentLengthStrLen 48
|
---|
65 | #define ReqAcceptStrLen 256
|
---|
66 | #define ReqAcceptLangStrLen 48
|
---|
67 | #define ReqConnectionStrLen 24
|
---|
68 | #define ReqAuthorizedUserStrLen 48
|
---|
69 | #define ReqPathInfoStrLen 512
|
---|
70 | #define ReqPathTranslatedStrLen 512
|
---|
71 | #define ReqScriptNameStrLen 512
|
---|
72 |
|
---|
73 | #define MAX_OTHER_HEADERS 100
|
---|
74 |
|
---|
75 | struct RequestHeaderT {
|
---|
76 | char *Var;
|
---|
77 | char *Val;
|
---|
78 | };
|
---|
79 |
|
---|
80 | struct RequestFieldsT {
|
---|
81 | //Simple request line info v0.9
|
---|
82 | char MethodStr[ReqMethodStrLen];
|
---|
83 | text_t URIStr;
|
---|
84 | //added v1.0
|
---|
85 | char VersionStr[ReqVersionStrLen];
|
---|
86 | //General Header
|
---|
87 | char DateStr[ReqDateStrLen];
|
---|
88 | char MIMEVerStr[ReqMIMEVerStrLen];
|
---|
89 | char PragmaStr[ReqPragmaStrLen];
|
---|
90 | //Request Header
|
---|
91 | char AuthorizationStr[ReqAuthorizationStrLen];
|
---|
92 | char FromStr[ReqFromStrLen];
|
---|
93 | char IfModSinceStr[ReqIfModSinceStrLen];
|
---|
94 | char RefererStr[ReqRefererStrLen];
|
---|
95 | char UserAgentStr[ReqUserAgentStrLen];
|
---|
96 | //Entity Header (Only CGI stuff)
|
---|
97 | char ContentEncodingStr[ReqContentEncodingStrLen];
|
---|
98 | char ContentTypeStr[ReqContentTypeStrLen];
|
---|
99 | char ContentLengthStr[ReqContentLengthStrLen];
|
---|
100 | //v1.0 Optional (the more common ones)
|
---|
101 | char AcceptStr[ReqAcceptStrLen];
|
---|
102 | char AcceptLangStr[ReqAcceptLangStrLen];
|
---|
103 | //v1.1 Exentions
|
---|
104 | char ConnectionStr[ReqConnectionStrLen];
|
---|
105 | //Pointer to buffer containing the content
|
---|
106 | DWORD ContentLength;
|
---|
107 | BYTE *Content;
|
---|
108 |
|
---|
109 | //Authorized user, filled in if a user is authorized from Auth..Str above
|
---|
110 | char AuthorizedUserStr[ReqAuthorizedUserStrLen];
|
---|
111 |
|
---|
112 | //CGI style fields
|
---|
113 | char PathInfoStr[ReqPathInfoStrLen];
|
---|
114 | char PathTranslatedStr[ReqPathTranslatedStrLen];
|
---|
115 | char ScriptNameStr[ReqScriptNameStrLen];
|
---|
116 |
|
---|
117 | //Other Headers
|
---|
118 | int NumOtherHeaders;
|
---|
119 | RequestHeaderT OtherHeaders[MAX_OTHER_HEADERS];
|
---|
120 | };
|
---|
121 |
|
---|
122 | struct RequestInfoT {
|
---|
123 | int ThreadNum;
|
---|
124 |
|
---|
125 | //Buffer for IO operations (so we're not constantly reallocating buffers)
|
---|
126 | BYTE *IOBuffer;
|
---|
127 | int IOBufferSize;
|
---|
128 |
|
---|
129 | //Socket the request is on and its address
|
---|
130 | SOCKET ClientSocket;
|
---|
131 | SOCKADDR_IN ClientSockAddr;
|
---|
132 | int AddrLen;
|
---|
133 |
|
---|
134 | //Should we keep the connection alive?
|
---|
135 | BOOL KeepAlive;
|
---|
136 | };
|
---|
137 |
|
---|
138 |
|
---|
139 | // Public Functions
|
---|
140 |
|
---|
141 | /*
|
---|
142 | Function Name: RequestThread
|
---|
143 | Purpose: Was the HTTP request processing thread
|
---|
144 | Now just a standard procedure called to process a request
|
---|
145 | Parameters:
|
---|
146 | Pointer to packed parameter structure
|
---|
147 | */
|
---|
148 | void RequestThread(RequestThreadMessageT *Parameters);
|
---|
149 |
|
---|
150 | /*
|
---|
151 | Function Name: Process 1.0 Request
|
---|
152 | Purpose: Sends a HTTP 1.0 (plus some) reply to a HTTP 1.x request
|
---|
153 | Parameters:
|
---|
154 | ClientSocket - Socket the client is on
|
---|
155 | ClientSockAddr - Address of client
|
---|
156 | AddrLen - Length of client address
|
---|
157 | RequestInfo - Structure storing the parsed headers
|
---|
158 | KeepAlive - To be set to true if we are maintainig the connection
|
---|
159 | IOBuffer - Pointer to buffer allocated for IO operations
|
---|
160 | TheadNum - Number of calling thread for debugging
|
---|
161 | Notes: The function uses "Connection: Keep-Alive" as written in the HTTP/1.1
|
---|
162 | draft and implemented by Netscape and MSIE
|
---|
163 | */
|
---|
164 | void Process10Request(RequestInfoT &RequestInfo, RequestFieldsT &RequestFields);
|
---|
165 |
|
---|
166 | #endif
|
---|