2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 /***************************************************************************
19 * Description: common stuff for bi-directional protocol ajp13/ajp14. *
20 * Author: Gal Shachor <shachor@il.ibm.com> *
21 * Author: Henri Gomez <hgomez@apache.org> *
22 * Version: $Revision: 1137200 $ *
23 ***************************************************************************/
25 #ifndef JK_AJP_COMMON_H
26 #define JK_AJP_COMMON_H
28 #include "jk_service.h"
29 #include "jk_msg_buff.h"
36 #endif /* __cplusplus */
38 #define JK_AJP_STATE_IDLE (0)
39 #define JK_AJP_STATE_OK (1)
40 #define JK_AJP_STATE_ERROR (2)
41 #define JK_AJP_STATE_PROBE (3)
42 #define JK_AJP_STATE_DEF (JK_AJP_STATE_IDLE)
43 #define JK_AJP_STATE_TEXT_IDLE ("OK/IDLE")
44 #define JK_AJP_STATE_TEXT_OK ("OK")
45 #define JK_AJP_STATE_TEXT_ERROR ("ERR")
46 #define JK_AJP_STATE_TEXT_PROBE ("ERR/PRB")
47 #define JK_AJP_STATE_TEXT_MAX (JK_AJP_STATE_PROBE)
48 #define JK_AJP_STATE_TEXT_DEF (JK_AJP_STATE_TEXT_IDLE)
50 /* We accept doing global maintenance if we are */
51 /* JK_AJP_MAINTAIN_TOLERANCE seconds early. */
52 #define JK_AJP_MAINTAIN_TOLERANCE (2)
55 * Conditional request attributes
58 #define SC_A_CONTEXT (unsigned char)1
59 #define SC_A_SERVLET_PATH (unsigned char)2
60 #define SC_A_REMOTE_USER (unsigned char)3
61 #define SC_A_AUTH_TYPE (unsigned char)4
62 #define SC_A_QUERY_STRING (unsigned char)5
63 #define SC_A_ROUTE (unsigned char)6
64 #define SC_A_SSL_CERT (unsigned char)7
65 #define SC_A_SSL_CIPHER (unsigned char)8
66 #define SC_A_SSL_SESSION (unsigned char)9
67 #define SC_A_REQ_ATTRIBUTE (unsigned char)10
68 #define SC_A_SSL_KEY_SIZE (unsigned char)11 /* only in if JkOptions +ForwardKeySize */
69 #define SC_A_SECRET (unsigned char)12
70 #define SC_A_STORED_METHOD (unsigned char)13
71 #define SC_A_ARE_DONE (unsigned char)0xFF
74 * AJP private request attributes
76 * The following request attribute is recognized by Tomcat
77 * to contain the forwarded remote port.
79 #define SC_A_REQ_REMOTE_PORT ("AJP_REMOTE_PORT")
82 * JK public request attributes
84 * Activation state of the worker in the load balancer.
85 * Can be any of the JK_LB_ACTIVATION_TEXT_* strings
86 * from jk_lb_worker.h.
88 #define SC_A_JK_LB_ACTIVATION ("JK_LB_ACTIVATION")
91 * Request methods, coded as numbers instead of strings.
92 * The list of methods was taken from Section 5.1.1 of RFC 2616,
93 * RFC 2518, the ACL IETF draft, and the DeltaV IESG Proposed Standard.
110 * | "VERSION-CONTROL"
119 * | "BASELINE-CONTROL"
123 #define SC_M_OPTIONS (unsigned char)1
124 #define SC_M_GET (unsigned char)2
125 #define SC_M_HEAD (unsigned char)3
126 #define SC_M_POST (unsigned char)4
127 #define SC_M_PUT (unsigned char)5
128 #define SC_M_DELETE (unsigned char)6
129 #define SC_M_TRACE (unsigned char)7
130 #define SC_M_PROPFIND (unsigned char)8
131 #define SC_M_PROPPATCH (unsigned char)9
132 #define SC_M_MKCOL (unsigned char)10
133 #define SC_M_COPY (unsigned char)11
134 #define SC_M_MOVE (unsigned char)12
135 #define SC_M_LOCK (unsigned char)13
136 #define SC_M_UNLOCK (unsigned char)14
137 #define SC_M_ACL (unsigned char)15
138 #define SC_M_REPORT (unsigned char)16
139 #define SC_M_VERSION_CONTROL (unsigned char)17
140 #define SC_M_CHECKIN (unsigned char)18
141 #define SC_M_CHECKOUT (unsigned char)19
142 #define SC_M_UNCHECKOUT (unsigned char)20
143 #define SC_M_SEARCH (unsigned char)21
144 #define SC_M_MKWORKSPACE (unsigned char)22
145 #define SC_M_UPDATE (unsigned char)23
146 #define SC_M_LABEL (unsigned char)24
147 #define SC_M_MERGE (unsigned char)25
148 #define SC_M_BASELINE_CONTROL (unsigned char)26
149 #define SC_M_MKACTIVITY (unsigned char)27
150 #define SC_M_JK_STORED (unsigned char)0xFF
153 * Frequent request headers, these headers are coded as numbers
154 * instead of strings.
173 #define SC_ACCEPT (unsigned short)0xA001
174 #define SC_ACCEPT_CHARSET (unsigned short)0xA002
175 #define SC_ACCEPT_ENCODING (unsigned short)0xA003
176 #define SC_ACCEPT_LANGUAGE (unsigned short)0xA004
177 #define SC_AUTHORIZATION (unsigned short)0xA005
178 #define SC_CONNECTION (unsigned short)0xA006
179 #define SC_CONTENT_TYPE (unsigned short)0xA007
180 #define SC_CONTENT_LENGTH (unsigned short)0xA008
181 #define SC_COOKIE (unsigned short)0xA009
182 #define SC_COOKIE2 (unsigned short)0xA00A
183 #define SC_HOST (unsigned short)0xA00B
184 #define SC_PRAGMA (unsigned short)0xA00C
185 #define SC_REFERER (unsigned short)0xA00D
186 #define SC_USER_AGENT (unsigned short)0xA00E
189 * Frequent response headers, these headers are coded as numbers
190 * instead of strings.
205 #define SC_RESP_CONTENT_TYPE (unsigned short)0xA001
206 #define SC_RESP_CONTENT_LANGUAGE (unsigned short)0xA002
207 #define SC_RESP_CONTENT_LENGTH (unsigned short)0xA003
208 #define SC_RESP_DATE (unsigned short)0xA004
209 #define SC_RESP_LAST_MODIFIED (unsigned short)0xA005
210 #define SC_RESP_LOCATION (unsigned short)0xA006
211 #define SC_RESP_SET_COOKIE (unsigned short)0xA007
212 #define SC_RESP_SET_COOKIE2 (unsigned short)0xA008
213 #define SC_RESP_SERVLET_ENGINE (unsigned short)0xA009
214 #define SC_RESP_STATUS (unsigned short)0xA00A
215 #define SC_RESP_WWW_AUTHENTICATE (unsigned short)0xA00B
216 #define SC_RES_HEADERS_NUM 11
219 * AJP13/AJP14 use same message structure
222 #define AJP_DEF_RETRY_ATTEMPTS (1)
224 #define AJP_HEADER_LEN (4)
225 #define AJP_HEADER_SZ_LEN (2)
226 #define CHUNK_BUFFER_PAD (12)
227 #define AJP_DEF_CACHE_TIMEOUT (0)
228 #define AJP_DEF_CONNECT_TIMEOUT (0) /* NO CONNECTION TIMEOUT => NO CPING/CPONG */
229 #define AJP_DEF_REPLY_TIMEOUT (0) /* NO REPLY TIMEOUT */
230 #define AJP_DEF_PREPOST_TIMEOUT (0) /* NO PREPOST TIMEOUT => NO CPING/CPONG */
231 #define AJP_DEF_RECOVERY_OPTS (0) /* NO RECOVERY / NO */
232 #define AJP_DEF_SOCKET_TIMEOUT (0) /* No timeout */
233 #define AJP_DEF_PING_TIMEOUT (10000) /* Default CPING/CPONG timeout (10 seconds) */
235 #define AJP_CPING_NONE (0) /* Do not send cping packets */
236 #define AJP_CPING_CONNECT (1) /* Send cping on fresh connection */
237 #define AJP_CPING_PREPOST (2) /* Send cping before sending request */
238 #define AJP_CPING_INTERVAL (4) /* Send cping on regular intervals */
241 #define RECOVER_ABORT_IF_TCGETREQUEST 0x0001 /* DON'T RECOVER IF TOMCAT FAILS AFTER RECEIVING REQUEST */
242 #define RECOVER_ABORT_IF_TCSENDHEADER 0x0002 /* DON'T RECOVER IF TOMCAT FAILS AFTER SENDING HEADERS */
243 #define RECOVER_ABORT_IF_CLIENTERROR 0x0004 /* CLOSE THE SOCKET IN CASE OF CLIENT ERROR */
244 #define RECOVER_ALWAYS_HTTP_HEAD 0x0008 /* RECOVER HTTP HEAD REQUESTS, EVEN IF ABORT OPTIONS ARE SET */
245 #define RECOVER_ALWAYS_HTTP_GET 0x0010 /* RECOVER HTTP GET REQUESTS, EVEN IF ABORT OPTIONS ARE SET */
247 #define JK_MAX_HTTP_STATUS_FAILS 32 /* Should be enough for most 400 and 500 statuses */
257 unsigned num_headers;
259 char **header_values;
261 typedef struct jk_res_data jk_res_data_t;
263 #include "jk_ajp14.h"
265 struct ajp_operation;
266 typedef struct ajp_operation ajp_operation_t;
269 typedef struct ajp_endpoint ajp_endpoint_t;
272 typedef struct ajp_worker ajp_worker_t;
277 /* Shared memory worker data */
278 jk_shm_ajp_worker_t *s;
280 char name[JK_SHM_STR_SIZ+1];
281 /* Sequence counter starting at 0 and increasing
282 * every time we change the config
284 volatile unsigned int sequence;
287 jk_pool_atom_t buf[TINY_POOL_SIZE];
291 struct sockaddr_in worker_inet_addr; /* Contains host and port */
292 unsigned connect_retry_attempts;
293 char host[JK_SHM_STR_SIZ+1];
295 int addr_sequence; /* Whether the address is resolved */
298 * Open connections cache...
300 * 1. Critical section object to protect the cache.
302 * 3. An array of "open" endpoints.
304 unsigned int ep_cache_sz;
305 unsigned int ep_mincache_sz;
306 unsigned int ep_maxcache_sz;
307 int cache_acquire_timeout;
308 ajp_endpoint_t **ep_cache;
310 int proto; /* PROTOCOL USED AJP13/AJP14 */
312 jk_login_service_t *login;
314 /* Weak secret similar with ajp12, used in ajp13 */
318 * Post physical connect handler.
319 * AJP14 will set here its login handler
321 int (*logon) (ajp_endpoint_t * ae, jk_logger_t *l);
324 * Handle Socket Timeouts
327 int socket_connect_timeout;
331 * Handle Cache Timeouts
336 * Handle Connection/Reply Timeouts
338 int connect_timeout; /* connect cping/cpong delay in ms (0 means disabled) */
339 int reply_timeout; /* reply timeout delay in ms (0 means disabled) */
340 int prepost_timeout; /* before sending a request cping/cpong timeout delay in ms (0 means disabled) */
341 int conn_ping_interval; /* interval for sending keepalive cping packets on
342 * unused connection */
343 int ping_timeout; /* generic cping/cpong timeout. Used for keepalive packets or
344 * as default for boolean valued connect and prepost timeouts.
346 unsigned int ping_mode; /* Ping mode flags (which types of cpings should be used) */
350 unsigned int recovery_opts;
353 * Public property to enable the number of retry attempts
358 unsigned int max_packet_size; /* Maximum AJP Packet size */
360 int retry_interval; /* Number of milliseconds to sleep before doing a retry */
363 * HTTP status that will cause failover (0 means disabled)
365 unsigned int http_status_fail_num;
366 int http_status_fail[JK_MAX_HTTP_STATUS_FAILS];
371 * endpoint, the remote connector which does the work
375 ajp_worker_t *worker;
378 jk_pool_atom_t buf[BIG_POOL_SIZE];
380 int proto; /* PROTOCOL USED AJP13/AJP14 */
385 /* Used with RECOVER_ABORT_IF_CLIENTERROR to hard abort
386 write of AJP response on client write errors */
389 jk_endpoint_t endpoint;
391 jk_uint64_t left_bytes_to_send;
393 /* time of the last request
394 handled by this endpoint */
397 /* Last operation performed via this endpoint */
399 int addr_sequence; /* Whether the address is resolved */
403 * little struct to avoid multiples ptr passing
404 * this struct is ready to hold upload file fd
405 * to add upload persistant storage
409 jk_msg_buf_t *request; /* original request storage */
410 jk_msg_buf_t *reply; /* reply storage (chuncked by ajp13 */
411 jk_msg_buf_t *post; /* small post data storage area */
412 int uploadfd; /* future persistant storage id */
413 int recoverable; /* if exchange could be conducted on another TC */
421 const char *jk_ajp_get_state(ajp_worker_t *aw, jk_logger_t *l);
423 int jk_ajp_get_state_code(const char *v);
425 int ajp_validate(jk_worker_t *pThis,
427 jk_worker_env_t *we, jk_logger_t *l, int proto);
429 int ajp_init(jk_worker_t *pThis,
431 jk_worker_env_t *we, jk_logger_t *l, int proto);
433 int JK_METHOD ajp_worker_factory(jk_worker_t **w,
434 const char *name, jk_logger_t *l);
436 int ajp_destroy(jk_worker_t **pThis, jk_logger_t *l, int proto);
438 int JK_METHOD ajp_done(jk_endpoint_t **e, jk_logger_t *l);
440 int ajp_get_endpoint(jk_worker_t *pThis,
441 jk_endpoint_t **pend, jk_logger_t *l, int proto);
443 int ajp_connect_to_endpoint(ajp_endpoint_t * ae, jk_logger_t *l);
445 void ajp_close_endpoint(ajp_endpoint_t * ae, jk_logger_t *l);
447 void jk_ajp_pull(ajp_worker_t * aw, int locked, jk_logger_t *l);
449 void jk_ajp_push(ajp_worker_t * aw, int locked, jk_logger_t *l);
451 int ajp_connection_tcp_send_message(ajp_endpoint_t * ae,
452 jk_msg_buf_t *msg, jk_logger_t *l);
454 int ajp_connection_tcp_get_message(ajp_endpoint_t * ae,
455 jk_msg_buf_t *msg, jk_logger_t *l);
457 int JK_METHOD ajp_maintain(jk_worker_t *pThis, time_t now, jk_logger_t *l);
459 int jk_ajp_get_cping_mode(const char *m, int def);
461 int ajp_has_endpoint(jk_worker_t *pThis, jk_logger_t *l);
465 #endif /* __cplusplus */
466 #endif /* JK_AJP_COMMON_H */