-
Notifications
You must be signed in to change notification settings - Fork 60
/
ngx_http_ajp.h
478 lines (421 loc) · 14 KB
/
ngx_http_ajp.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
#ifndef NGX_HTTP_AJP_H
#define NGX_HTTP_AJP_H
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include <nginx.h>
#include "ngx_http_ajp_module.h"
#define AJP13_DEF_HOST "127.0.0.1"
#ifdef NETWARE
#define AJP13_DEF_PORT 9009 /* default to 9009 since 8009 is used by OS */
#else
#define AJP13_DEF_PORT 8009
#endif
#define AJP13_HTTPS_INDICATOR "HTTPS"
#define AJP13_SSL_CLIENT_CERT_INDICATOR "SSL_CLIENT_CERT"
#define AJP13_SSL_CIPHER_INDICATOR "SSL_CIPHER"
#define AJP13_SSL_SESSION_INDICATOR "SSL_SESSION_ID"
#define AJP13_SSL_KEY_SIZE_INDICATOR "SSL_CIPHER_USEKEYSIZE"
#define AJP_NULL_STRING_LENGTH (uint16_t)(-1)
#define AJP_EOVERFLOW 1001
typedef struct ajp_msg {
ngx_buf_t *buf;
size_t len;
int server_side;
} ajp_msg_t;
/*
* Signature for the messages sent from Apache to tomcat
*/
#define AJP13_WS_HEADER 0x1234
#define AJP_HEADER_LEN 4
#define AJP_HEADER_SZ_LEN 2
#define AJP_HEADER_SZ 6
#define AJP_MSG_BUFFER_SZ 8192
#define AJP_MAX_BUFFER_SZ 65536
#define AJP13_MAX_SEND_BODY_SZ (AJP_MAX_BUFFER_SZ - AJP_HEADER_SZ)
#define AJP_PING_PONG_SZ 128
/* Send a request from web server to container */
#define CMD_AJP13_FORWARD_REQUEST (unsigned char)2
/* Write a body chunk from the servlet container to the web server */
#define CMD_AJP13_SEND_BODY_CHUNK (unsigned char)3
/* Send response headers from the servlet container to the web server. */
#define CMD_AJP13_SEND_HEADERS (unsigned char)4
/* Marks the end of response. */
#define CMD_AJP13_END_RESPONSE (unsigned char)5
/*
* Get further data from the web server if it hasn't all been
* transferred yet.
*/
#define CMD_AJP13_GET_BODY_CHUNK (unsigned char)6
/* The web server asks the container to shut itself down. */
#define CMD_AJP13_SHUTDOWN (unsigned char)7
/* Webserver ask container to take control (logon phase) */
#define CMD_AJP13_PING (unsigned char)8
/* Container response to cping request */
#define CMD_AJP13_CPONG (unsigned char)9
/*
* Webserver check if container is alive, since container should
* respond by cpong
*/
#define CMD_AJP13_CPING (unsigned char)10
/*
* Conditional request attributes
*/
#define SC_A_CONTEXT (unsigned char)1
#define SC_A_SERVLET_PATH (unsigned char)2
#define SC_A_REMOTE_USER (unsigned char)3
#define SC_A_AUTH_TYPE (unsigned char)4
#define SC_A_QUERY_STRING (unsigned char)5
#define SC_A_JVM_ROUTE (unsigned char)6
#define SC_A_SSL_CERT (unsigned char)7
#define SC_A_SSL_CIPHER (unsigned char)8
#define SC_A_SSL_SESSION (unsigned char)9
#define SC_A_REQ_ATTRIBUTE (unsigned char)10
#define SC_A_SSL_KEY_SIZE (unsigned char)11
#define SC_A_SECRET (unsigned char)12
#define SC_A_ARE_DONE (unsigned char)0xFF
/*
* AJP private request attributes
*
* The following request attribute is recognized by Tomcat
* to contain the forwarded remote port.
*/
#define SC_A_REQ_REMOTE_PORT ("AJP_REMOTE_PORT")
/*
* Request methods, coded as numbers instead of strings.
* The list of methods was taken from Section 5.1.1 of RFC 2616,
* RFC 2518, the ACL IETF draft, and the DeltaV IESG Proposed Standard.
* Method = "OPTIONS"
* | "GET"
* | "HEAD"
* | "POST"
* | "PUT"
* | "DELETE"
* | "TRACE"
* | "PROPFIND"
* | "PROPPATCH"
* | "MKCOL"
* | "COPY"
* | "MOVE"
* | "LOCK"
* | "UNLOCK"
* | "ACL"
* | "REPORT"
* | "VERSION-CONTROL"
* | "CHECKIN"
* | "CHECKOUT"
* | "UNCHECKOUT"
* | "SEARCH"
* | "MKWORKSPACE"
* | "UPDATE"
* | "LABEL"
* | "MERGE"
* | "BASELINE-CONTROL"
* | "MKACTIVITY"
*
*/
#define SC_M_OPTIONS (unsigned char)1
#define SC_M_GET (unsigned char)2
#define SC_M_HEAD (unsigned char)3
#define SC_M_POST (unsigned char)4
#define SC_M_PUT (unsigned char)5
#define SC_M_DELETE (unsigned char)6
#define SC_M_TRACE (unsigned char)7
#define SC_M_PROPFIND (unsigned char)8
#define SC_M_PROPPATCH (unsigned char)9
#define SC_M_MKCOL (unsigned char)10
#define SC_M_COPY (unsigned char)11
#define SC_M_MOVE (unsigned char)12
#define SC_M_LOCK (unsigned char)13
#define SC_M_UNLOCK (unsigned char)14
/* Not supported in Nginx */
#define SC_M_ACL (unsigned char)15
#define SC_M_REPORT (unsigned char)16
#define SC_M_VERSION_CONTROL (unsigned char)17
#define SC_M_CHECKIN (unsigned char)18
#define SC_M_CHECKOUT (unsigned char)19
#define SC_M_UNCHECKOUT (unsigned char)20
#define SC_M_SEARCH (unsigned char)21
#define SC_M_MKWORKSPACE (unsigned char)22
#define SC_M_UPDATE (unsigned char)23
#define SC_M_LABEL (unsigned char)24
#define SC_M_MERGE (unsigned char)25
#define SC_M_BASELINE_CONTROL (unsigned char)26
#define SC_M_MKACTIVITY (unsigned char)27
/*
* Frequent request headers, these headers are coded as numbers
* instead of strings.
*
* Accept
* Accept-Charset
* Accept-Encoding
* Accept-Language
* Authorization
* Connection
* Content-Type
* Content-Length
* Cookie
* Cookie2
* Host
* Pragma
* Referer
* User-Agent
*
*/
#define SC_REQ_ACCEPT (unsigned short)0xA001
#define SC_REQ_ACCEPT_CHARSET (unsigned short)0xA002
#define SC_REQ_ACCEPT_ENCODING (unsigned short)0xA003
#define SC_REQ_ACCEPT_LANGUAGE (unsigned short)0xA004
#define SC_REQ_AUTHORIZATION (unsigned short)0xA005
#define SC_REQ_CONNECTION (unsigned short)0xA006
#define SC_REQ_CONTENT_TYPE (unsigned short)0xA007
#define SC_REQ_CONTENT_LENGTH (unsigned short)0xA008
#define SC_REQ_COOKIE (unsigned short)0xA009
#define SC_REQ_COOKIE2 (unsigned short)0xA00A
#define SC_REQ_HOST (unsigned short)0xA00B
#define SC_REQ_PRAGMA (unsigned short)0xA00C
#define SC_REQ_REFERER (unsigned short)0xA00D
#define SC_REQ_USER_AGENT (unsigned short)0xA00E
/*
* Frequent response headers, these headers are coded as numbers
* instead of strings.
*
* Content-Type
* Content-Language
* Content-Length
* Date
* Last-Modified
* Location
* Set-Cookie
* Servlet-Engine
* Status
* WWW-Authenticate
*
*/
#define SC_RESP_CONTENT_TYPE (unsigned short)0xA001
#define SC_RESP_CONTENT_LANGUAGE (unsigned short)0xA002
#define SC_RESP_CONTENT_LENGTH (unsigned short)0xA003
#define SC_RESP_DATE (unsigned short)0xA004
#define SC_RESP_LAST_MODIFIED (unsigned short)0xA005
#define SC_RESP_LOCATION (unsigned short)0xA006
#define SC_RESP_SET_COOKIE (unsigned short)0xA007
#define SC_RESP_SET_COOKIE2 (unsigned short)0xA008
#define SC_RESP_SERVLET_ENGINE (unsigned short)0xA009
#define SC_RESP_STATUS (unsigned short)0xA00A
#define SC_RESP_WWW_AUTHENTICATE (unsigned short)0xA00B
#define SC_RES_HEADERS_NUM 11
#define DUMP_LENGTH 64
ngx_int_t ajp_msg_is_zero_length(u_char *head);
/*
* Begin to parse an AJP Message, move the buffer header to the type's
* position.
*
* @param msg AJP Message to parse
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_parse_begin(ajp_msg_t *msg);
/*
* Reset an AJP Message
*
* @param msg AJP Message to reset
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_reset(ajp_msg_t *msg);
/*
* Reuse an AJP Message
*
* @param msg AJP Message to reuse
* @return The cleared message
*/
ajp_msg_t * ajp_msg_reuse(ajp_msg_t *msg);
/*
* Mark the end of an AJP Message
*
* @param msg AJP Message to end
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_end(ajp_msg_t *msg);
/*
* Add an unsigned 32bits value to AJP Message
*
* @param msg AJP Message to get value from
* @param value value to add to AJP Message
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_append_uint32(ajp_msg_t *msg, uint32_t value);
/*
* Add an unsigned 16bits value to AJP Message
*
* @param msg AJP Message to get value from
* @param value value to add to AJP Message
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_append_uint16(ajp_msg_t *msg, uint16_t value);
/*
* Add an unsigned 8bits value to AJP Message
*
* @param msg AJP Message to get value from
* @param value value to add to AJP Message
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_append_uint8(ajp_msg_t *msg, u_char value);
/*
* Add a String in AJP message
*
* @param msg AJP Message to get value from
* @param value Pointer to String
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_append_string(ajp_msg_t *msg, ngx_str_t *value);
/*
* Get a 32bits unsigned value from AJP Message
*
* @param msg AJP Message to get value from
* @param rvalue Pointer where value will be returned
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_get_uint32(ajp_msg_t *msg, uint32_t *rvalue);
/*
* Get a 16bits unsigned value from AJP Message
*
* @param msg AJP Message to get value from
* @param rvalue Pointer where value will be returned
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_get_uint16(ajp_msg_t *msg, uint16_t *rvalue);
/*
* Peek a 16bits unsigned value from AJP Message, position in message
* is not updated
*
* @param msg AJP Message to get value from
* @param rvalue Pointer where value will be returned
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_peek_uint16(ajp_msg_t *msg, uint16_t *rvalue);
/*
* Get a 8bits unsigned value from AJP Message
*
* @param msg AJP Message to get value from
* @param rvalue Pointer where value will be returned
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_get_uint8(ajp_msg_t *msg, u_char *rvalue);
/*
* Peek a 8bits unsigned value from AJP Message, position in message
* is not updated
*
* @param msg AJP Message to get value from
* @param rvalue Pointer where value will be returned
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_peek_uint8(ajp_msg_t *msg, u_char *rvalue);
/*
* Get a String value from AJP Message
*
* @param msg AJP Message to get value from
* @param rvalue Pointer where value will be returned
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_get_string(ajp_msg_t *msg, ngx_str_t *rvalue);
/*
* Create an AJP Message from pool
*
* @param pool memory pool to allocate AJP message from
* @param size size of the buffer to create
* @param rmsg Pointer to newly created AJP message
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_create(ngx_pool_t *pool, size_t size, ajp_msg_t **rmsg);
/*
* Create an AJP Message's buffer from pool
*
* @param pool memory pool to allocate AJP message from
* @param size size of the buffer to create
* @param rmsg Pointer to newly created AJP message
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_create_buffer(ngx_pool_t *pool, size_t size, ajp_msg_t *msg);
/*
* Create an AJP Message from pool without buffer
*
* @param pool memory pool to allocate AJP message from
* @param rmsg Pointer to newly created AJP message
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_create_without_buffer(ngx_pool_t *pool, ajp_msg_t **rmsg);
/*
* Allocate a msg to send data
*
* @param pool pool to allocate from
* @param msg returned AJP message
* @return NGX_OK or error
*/
ngx_int_t ajp_alloc_data_msg(ngx_pool_t *pool, ajp_msg_t *msg);
/*
* Finalize a data message
*
* @param msg returned AJP message
* @param size size of the data to send
* @return NGX_OK or error
*/
ngx_int_t ajp_data_msg_end(ajp_msg_t *msg, size_t len);
/*
* Dump up to the first DUMP_LENGTH bytes on an AJP Message
*
* @param pool pool to allocate from
* @param msg AJP Message to dump
* @param err error string to display
* @return dump message
*/
u_char * ajp_msg_dump(ngx_pool_t *pool, ajp_msg_t *msg, char *err);
/*
* Initialize the headers of request and reponse
*/
void ajp_header_init(void);
/*
* Fill the request packet into AJP message
*
* @param msg AJP message
* @param r current request
* @param alcf AJP configration structure
* @return NGX_OK or error
*/
ngx_int_t ajp_marshal_into_msgb(ajp_msg_t *msg,
ngx_http_request_t *r, ngx_http_ajp_loc_conf_t *alcf);
/*
* Parse the binary AJP response packet
*
* @param msg AJP message
* @param r current request
* @param alcf AJP configration structure
* @return NGX_OK or error
*/
ngx_int_t ajp_unmarshal_response(ajp_msg_t *msg,
ngx_http_request_t *r, ngx_http_ajp_loc_conf_t *alcf);
/*
* Handle the CPING/CPONG messages
* TODO: health check
*/
/*
* Serialize in an AJP Message a PING command
*
* +-----------------------+
* | PING CMD (1 byte) |
* +-----------------------+
*
* @param smsg AJP message to put serialized message
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_serialize_ping(ajp_msg_t *msg);
/*
* Serialize in an AJP Message a CPING command
*
* +-----------------------+
* | CPING CMD (1 byte) |
* +-----------------------+
*
* @param smsg AJP message to put serialized message
* @return NGX_OK or error
*/
ngx_int_t ajp_msg_serialize_cping(ajp_msg_t *msg);
#endif /* NGX_HTTP_AJP_H */