-
Notifications
You must be signed in to change notification settings - Fork 30
/
http.h
222 lines (186 loc) · 6.74 KB
/
http.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
This program and the accompanying materials are
made available under the terms of the Eclipse Public License v2.0 which accompanies
this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html
SPDX-License-Identifier: EPL-2.0
Copyright Contributors to the Zowe Project.
*/
#ifndef _COMMON_HTTP_H_
#define _COMMON_HTTP_H_
#define HTTP_STATUS_CONTINUE 100
#define HTTP_STATUS_SWITCHING_PROTOCOLS 101
#define HTTP_STATUS_PROCESSING 102 /* WebDAV is primary user */
#define HTTP_STATUS_OK 200
#define HTTP_STATUS_CREATED 201
#define HTTP_STATUS_ACCEPTED 202
#define HTTP_STATUS_NO_CONTENT 204
#define HTTP_STATUS_PARTIAL_CONTENT 206
#define HTTP_STATUS_MULITPLE_CHOICES 300
#define HTTP_STATUS_MOVED_PERMANENTLY 301
#define HTTP_STATUS_FOUND 302
#define HTTP_STATUS_SEE_OTHER 303
#define HTTP_STATUS_NOT_MODIFIED 304
#define HTTP_STATUS_USE_PROXY 305
#define HTTP_STATUS_BAD_REQUEST 400
#define HTTP_STATUS_UNAUTHORIZED 401
#define HTTP_STATUS_PAYMENT_REQUIRED 402
#define HTTP_STATUS_FORBIDDEN 403
#define HTTP_STATUS_NOT_FOUND 404
#define HTTP_STATUS_METHOD_NOT_FOUND 405
#define HTTP_STATUS_NOT_ACCEPTABLE 406
#define HTTP_STATUS_PROXY_AUTH_REQUIRED 407
#define HTTP_STATUS_REQUEST_TIMEOUT 408
#define HTTP_STATUS_RESOURCE_CONFLICT 409
#define HTTP_STATUS_GONE 410
#define HTTP_STATUS_LENGTH_REQUIRED 411
#define HTTP_STATUS_PRECONDITION_FAILED 412
#define HTTP_STATUS_ENTITY_TOO_LARGE 413
#define HTTP_STATUS_URI_TOO_LONG 414
#define HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE 415
#define HTTP_STATUS_RANGE_NOT_SATISFIABLE 416
#define HTTP_STATUS_EXPECTATION_FAILED 417
#define HTTP_STATUS_PRECONDITION_REQUIRED 428
#define HTTP_STATUS_TOO_MANY_REQUESTS 429
#define HTTP_STATUS_INTERNAL_SERVER_ERROR 500
#define HTTP_STATUS_NOT_IMPLEMENTED 501
#define HTTP_STATUS_BAD_GATEWAY 502
#define HTTP_STATUS_SERVICE_UNAVAILABLE 503
#define HTTP_STATUS_GATEWAY_TIMEOUT 504
#define HTTP_STATUS_VERSION_NOT_SUPPORTED 505
#define MAX_HTTP_METHOD_NAME 256
#define MAX_HTTP_VERSION 256
#define MAX_HTTP_URI 1024
#define MAX_HTTP_FIELD_NAME 1024
#define MAX_HTTP_FIELD_VALUE 16384 /* Apache is 8K, IIS is 16K (hearsay) */
#define MAX_HTTP_CHUNK 2147483647 /* Technically unbounded, but ... */
#define HTTP_REQUEST_MAX_LOCALES 10
#define HTTP_PROTOCOL_1_0 1
#define HTTP_PROTOCOL_1_1 2
#define HTTP_METHOD_GET 1
#define HTTP_METHOD_PUT 2
#define HTTP_METHOD_POST 3
#define HTTP_METHOD_DELETE 4
#define HTTP_METHOD_HEAD 5
#define ENCODING_SIMPLE 1
#define ENCODING_CHUNKED 2
#define ENCODING_GZIP 3
/** HttpHeader is the holder of header data parsed from a request.
It is held in the HttpRequest structure and has convenience functions for getting
specific values.
*/
typedef struct HttpHeader_tag{
char *name;
char *nativeName;
char *value;
char *nativeValue;
int intValue;
int64 int64Value;
struct HttpHeader_tag *next;
} HttpHeader;
typedef struct BufferedInputStream_tag{
Socket *socket;
char *buffer;
int bufferSize;
int fill;
int pos;
int eof;
} BufferedInputStream;
typedef struct HttpRequestParamSpec_tag{
char *name;
int flags;
int type;
int minWidth;
int maxWidth;
int lowBound;
int highBound;
int64 lowBound64;
int64 highBound64;
struct HttpRequestParamSpec_tag *next;
} HttpRequestParamSpec;
typedef struct HttpRequestParam_tag{
HttpRequestParamSpec *specification;
int intValue;
int64 int64Value;
char *stringValue;
struct HttpRequestParam_tag *next;
} HttpRequestParam;
typedef struct HttpRequest_tag{
ShortLivedHeap *slh;
Socket *socket;
BufferedInputStream *input;
int flags;
int characterEncoding;
int contentLength; /* -1 if unknown */
char *contentType;
char *contentBody;
int protocol; /* HTTP/1.1 */
int localeCount;
char *acceptLocales[HTTP_REQUEST_MAX_LOCALES];
char *acceptCharset; /* preferred charset */
/* Cookie[] cookies; */
HttpHeader *headerChain;
char *method;
char *uri; /* everything after the host:port in browser location */
char *file; /* rarely NULL */
StringList *parsedFile;
char *queryString; /* NULL if no "?" in URL */
int queryStringLen;
char *fragmentIdentifier; /* NULL if no '#' in URL */
/* Map parameters; /* set to Collections.EMPTY_MAP if no params. */
int authenticated;
int isWebSocket;
char *username;
char *password;
char *remoteUser; /* null if not authenticated */
char *requestedSessionId; /* session id from client */
HttpRequestParam *processedParamList;
struct HttpRequest_tag *next;
const void *authToken; /* a JWT or other */
int keepAlive;
} HttpRequest;
/*************** WebSocket Stuff ********************/
#define STATE_NO_INPUT 1
#define FINISHING_HEADER 2
#define READING_PAYLOAD 3
#define FIN 0x80
#define OPCODE_CONTINUATION 0x00
#define OPCODE_TEXT_FRAME 0x01
#define OPCODE_BINARY_FRAME 0x02
#define OPCODE_CONNECTION_CLOSE 0x08
#define OPCODE_PING 0x09
#define OPCODE_PONG 0x0A
#define OPCODE_UNKNOWN 0x9999
typedef struct WSFrame_tag{
int opcodeAndFlags;
char *data;
int dataLength;
struct WSFrame_tag *next;
} WSFrame;
typedef struct WSMessage_tag{
int opcodeAndFlags;
WSFrame *firstFrame;
int closeReasonCode;
char data; /* could be text or binary depending on opcode */
int dataLength;
struct WSMessage_tag *next;
} WSMessage;
char *copyString(ShortLivedHeap *slh, char *s, int len);
char *copyStringToNative(ShortLivedHeap *slh, char *s, int len);
char* destructivelyNativize(char *s);
int headerMatch(HttpHeader *header, char *s);
char *toASCIIUTF8(char *buffer, int len);
int writeFully(Socket *socket, char *buffer, int len);
static const char methodGET[] = { 0x47, 0x45, 0x54, 0x00 };
static const char methodPOST[] = { 0x50, 0x4f, 0x53, 0x54, 0x00 };
static const char methodPUT[] = { 0x50, 0x55, 0x54, 0x00 };
static const char methodDELETE[] = { 0x44, 0x45, 0x4c, 0x45, 0x54, 0x45, 0x00};
void requestStringHeader(HttpRequest *request, int inEbcdic, char *name, char *value);
void requestIntHeader(HttpRequest *request, int inEbcdic, char *name, int value);
#endif /* _COMMON_HTTP_H_ */
/*
This program and the accompanying materials are
made available under the terms of the Eclipse Public License v2.0 which accompanies
this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html
SPDX-License-Identifier: EPL-2.0
Copyright Contributors to the Zowe Project.
*/