]> granicus.if.org Git - apache/blob - modules/proxy/ajp.h
Update copyright year to 2005 and standardize on current copyright owner line.
[apache] / modules / proxy / ajp.h
1 /* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
2  * applicable.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef AJP_H
18 #define AJP_H
19
20 #include "apr_version.h"
21 #include "apr.h"
22
23 #include "apr_hooks.h"
24 #include "apr_lib.h"
25 #include "apr_strings.h"
26 #include "apr_buckets.h"
27 #include "apr_md5.h"
28 #include "apr_network_io.h"
29 #include "apr_pools.h"
30 #include "apr_strings.h"
31 #include "apr_uri.h"
32 #include "apr_date.h"
33 #include "apr_fnmatch.h"
34 #define APR_WANT_STRFUNC
35 #include "apr_want.h"
36
37 #if APR_HAVE_NETINET_IN_H
38 #include <netinet/in.h>
39 #endif
40 #if APR_HAVE_ARPA_INET_H
41 #include <arpa/inet.h>
42 #endif
43
44 #define AJP13_DEF_HOST "127.0.0.1"
45 #ifdef NETWARE
46 #define AJP13_DEF_PORT 9009     /* default to 9009 since 8009 is used by OS */
47 #else
48 #define AJP13_DEF_PORT 8009
49 #endif
50
51 /* The following environment variables match mod_ssl! */
52 #define AJP13_HTTPS_INDICATOR           "HTTPS"
53 #define AJP13_SSL_CLIENT_CERT_INDICATOR "SSL_CLIENT_CERT"
54 #define AJP13_SSL_CIPHER_INDICATOR      "SSL_CIPHER"
55 #define AJP13_SSL_SESSION_INDICATOR     "SSL_SESSION_ID"
56 #define AJP13_SSL_KEY_SIZE_INDICATOR    "SSL_CIPHER_USEKEYSIZE"
57
58 #if APR_CHARSET_EBCDIC
59
60 #define USE_CHARSET_EBCDIC
61 #define ajp_xlate_to_ascii(b, l) ap_xlate_proto_to_ascii(b, l)
62 #define ajp_xlate_from_ascii(b, l) ap_xlate_proto_from_ascii(b, l)
63
64 #else                           /* APR_CHARSET_EBCDIC */
65
66 #define ajp_xlate_to_ascii(b, l) 
67 #define ajp_xlate_from_ascii(b, l) 
68
69 #endif
70
71 #ifdef AJP_USE_HTTPD_WRAP
72 #include "httpd_wrap.h"
73 #else
74 #include "httpd.h"
75 #include "http_config.h"
76 #include "http_request.h"
77 #include "http_core.h"
78 #include "http_protocol.h"
79 #include "http_main.h"
80 #include "http_log.h"
81 #endif
82
83 #include "mod_proxy.h"
84
85
86 /** AJP Specific error codes
87  */
88 /** Buffer overflow exception */
89 #define AJP_EOVERFLOW           (APR_OS_START_USERERR + 1) 
90 /** Destination Buffer is to small */
91 #define AJP_ETOSMALL            (APR_OS_START_USERERR + 2) 
92 /** Invalid input parameters */
93 #define AJP_EINVAL              (APR_OS_START_USERERR + 3) 
94 /** Bad message signature */
95 #define AJP_EBAD_SIGNATURE      (APR_OS_START_USERERR + 4) 
96 /** Incoming message too bg */
97 #define AJP_ETOBIG              (APR_OS_START_USERERR + 5) 
98 /** Missing message header */
99 #define AJP_ENO_HEADER          (APR_OS_START_USERERR + 6) 
100 /** Bad message header */
101 #define AJP_EBAD_HEADER         (APR_OS_START_USERERR + 7) 
102 /** Bad message */
103 #define AJP_EBAD_MESSAGE        (APR_OS_START_USERERR + 8) 
104 /** Cant log via AJP14 */
105 #define AJP_ELOGFAIL            (APR_OS_START_USERERR + 9) 
106
107 /** A structure that represents ajp message */ 
108 typedef struct ajp_msg ajp_msg_t;
109
110 /** A structure that represents ajp message */ 
111 struct ajp_msg
112 {
113     /** The buffer holding a AJP message */ 
114     apr_byte_t  *buf;
115     /** The length of AJP message header (defaults to AJP_HEADER_LEN) */ 
116     apr_size_t  header_len;
117     /** The length of AJP message */ 
118     apr_size_t  len;
119     /** The current read position */ 
120     apr_size_t  pos;
121     /** Flag indicating the origing of the message */ 
122     int         server_side;
123 };
124
125 /**
126  * @defgroup AJP_defines AJP definitions 
127  * @{
128  */
129 /**
130  * Signature for the messages sent from Apache to tomcat
131  */
132 #define AJP13_WS_HEADER             0x1234
133 #define AJP_HEADER_LEN              4
134 #define AJP_HEADER_SZ_LEN           2
135 #define AJP_MSG_BUFFER_SZ           (8*1024)
136 #define AJP13_MAX_SEND_BODY_SZ      (AJP_MSG_BUFFER_SZ - 6)
137
138 /** Send a request from web server to container*/
139 #define CMD_AJP13_FORWARD_REQUEST   (unsigned char)2
140 /** Write a body chunk from the servlet container to the web server */
141 #define CMD_AJP13_SEND_BODY_CHUNK   (unsigned char)3
142 /** Send response headers from the servlet container to the web server. */
143 #define CMD_AJP13_SEND_HEADERS      (unsigned char)4
144 /** Marks the end of response. */
145 #define CMD_AJP13_END_RESPONSE      (unsigned char)5
146 /** Get further data from the web server if it hasn't all been transferred yet. */
147 #define CMD_AJP13_GET_BODY_CHUNK    (unsigned char)6
148 /** The web server asks the container to shut itself down. */
149 #define CMD_AJP13_SHUTDOWN          (unsigned char)7
150 /** Webserver ask container to take control (logon phase) */
151 #define CMD_AJP13_PING              (unsigned char)8
152 /** Container response to cping request */
153 #define CMD_AJP13_CPONG             (unsigned char)9
154 /** Webserver check if container is alive, since container should respond by cpong */
155 #define CMD_AJP13_CPING             (unsigned char)10
156
157 /** @} */
158
159 /**
160  * @defgroup AJP_api AJP API functions
161  * @{
162  */
163 /**
164  * Check a new AJP Message by looking at signature and return its size
165  *
166  * @param msg       AJP Message to check
167  * @param len       Pointer to returned len
168  * @return          APR_SUCCESS or error
169  */
170 apr_status_t ajp_msg_check_header(ajp_msg_t *msg, apr_size_t *len);
171
172 /**
173  * Reset an AJP Message
174  *
175  * @param msg       AJP Message to reset
176  * @return          APR_SUCCESS or error
177  */
178 apr_status_t ajp_msg_reset(ajp_msg_t *msg);
179
180 /**
181  * Mark the end of an AJP Message
182  *
183  * @param msg       AJP Message to end
184  * @return          APR_SUCCESS or error
185  */
186 apr_status_t ajp_msg_end(ajp_msg_t *msg);
187
188 /**
189  * Add an unsigned 32bits value to AJP Message
190  *
191  * @param msg       AJP Message to get value from
192  * @param value     value to add to AJP Message
193  * @return          APR_SUCCESS or error
194  */
195 apr_status_t ajp_msg_append_uint32(ajp_msg_t *msg, apr_uint32_t value);
196
197 /**
198  * Add an unsigned 16bits value to AJP Message
199  *
200  * @param msg       AJP Message to get value from
201  * @param value     value to add to AJP Message
202  * @return          APR_SUCCESS or error
203  */
204 apr_status_t ajp_msg_append_uint16(ajp_msg_t *msg, apr_uint16_t value);
205
206 /**
207  * Add an unsigned 8bits value to AJP Message
208  *
209  * @param msg       AJP Message to get value from
210  * @param value     value to add to AJP Message
211  * @return          APR_SUCCESS or error
212  */
213 apr_status_t ajp_msg_append_uint8(ajp_msg_t *msg, apr_byte_t value);
214
215 /**
216  *  Add a String in AJP message, and transform the String in ASCII 
217  *  if convert is set and we're on an EBCDIC machine    
218  *
219  * @param msg       AJP Message to get value from
220  * @param value     Pointer to String
221  * @param convert   When set told to convert String to ASCII
222  * @return          APR_SUCCESS or error
223  */
224 apr_status_t ajp_msg_append_string_ex(ajp_msg_t *msg, const char *value,
225                                       int convert);
226 /**
227  *  Add a String in AJP message, and transform 
228  *  the String in ASCII if we're on an EBCDIC machine    
229  */
230 #define ajp_msg_append_string(m, v) ajp_msg_append_string_ex(m, v, 1)
231
232 /**
233  *  Add a String in AJP message. 
234  */
235 #define ajp_msg_append_string_ascii(m, v) ajp_msg_append_string_ex(m, v, 0)
236
237 /**
238  * Add a Byte array to AJP Message
239  *
240  * @param msg       AJP Message to get value from
241  * @param value     Pointer to Byte array
242  * @param valuelen  Byte array len
243  * @return          APR_SUCCESS or error
244  */
245 apr_status_t ajp_msg_append_bytes(ajp_msg_t *msg, const apr_byte_t *value,
246                                   apr_size_t valuelen);
247
248 /**
249  * Get a 32bits unsigned value from AJP Message
250  *
251  * @param msg       AJP Message to get value from
252  * @param rvalue    Pointer where value will be returned
253  * @return          APR_SUCCESS or error
254  */
255 apr_status_t ajp_msg_get_uint32(ajp_msg_t *msg, apr_uint32_t *rvalue);
256
257 /**
258  * Get a 16bits unsigned value from AJP Message
259  *
260  * @param msg       AJP Message to get value from
261  * @param rvalue    Pointer where value will be returned
262  * @return          APR_SUCCESS or error
263  */
264 apr_status_t ajp_msg_get_uint16(ajp_msg_t *msg, apr_uint16_t *rvalue);
265
266 /**
267  * Peek a 16bits unsigned value from AJP Message, position in message
268  * is not updated
269  *
270  * @param msg       AJP Message to get value from
271  * @param rvalue    Pointer where value will be returned
272  * @return          APR_SUCCESS or error
273  */
274 apr_status_t ajp_msg_peek_uint16(ajp_msg_t *msg, apr_uint16_t *rvalue);
275
276 /**
277  * Get a 8bits unsigned value from AJP Message
278  *
279  * @param msg       AJP Message to get value from
280  * @param rvalue    Pointer where value will be returned
281  * @return          APR_SUCCESS or error
282  */
283 apr_status_t ajp_msg_get_uint8(ajp_msg_t *msg, apr_byte_t *rvalue);
284
285 /**
286  * Peek a 8bits unsigned value from AJP Message, position in message
287  * is not updated
288  *
289  * @param msg       AJP Message to get value from
290  * @param rvalue    Pointer where value will be returned
291  * @return          APR_SUCCESS or error
292  */
293 apr_status_t ajp_msg_peek_uint8(ajp_msg_t *msg, apr_byte_t *rvalue);
294
295 /**
296  * Get a String value from AJP Message
297  *
298  * @param msg       AJP Message to get value from
299  * @param rvalue    Pointer where value will be returned
300  * @return          APR_SUCCESS or error
301  */
302 apr_status_t ajp_msg_get_string(ajp_msg_t *msg, const char **rvalue);
303
304
305 /**
306  * Get a Byte array from AJP Message
307  *
308  * @param msg       AJP Message to get value from
309  * @param rvalue    Pointer where value will be returned
310  * @param rvalueLen Pointer where Byte array len will be returned
311  * @return          APR_SUCCESS or error
312  */
313 apr_status_t ajp_msg_get_bytes(ajp_msg_t *msg, apr_byte_t **rvalue,
314                                apr_size_t *rvalue_len);
315
316 /**
317  * Create an AJP Message from pool
318  *
319  * @param pool      memory pool to allocate AJP message from
320  * @param rmsg      Pointer to newly created AJP message
321  * @return          APR_SUCCESS or error
322  */
323 apr_status_t ajp_msg_create(apr_pool_t *pool, ajp_msg_t **rmsg);
324
325 /**
326  * Recopy an AJP Message to another
327  *
328  * @param smsg      source AJP message
329  * @param dmsg      destination AJP message
330  * @return          APR_SUCCESS or error
331  */
332 apr_status_t ajp_msg_copy(ajp_msg_t *smsg, ajp_msg_t *dmsg);
333
334 /**
335  * Serialize in an AJP Message a PING command
336  *
337  * +-----------------------+
338  * | PING CMD (1 byte)     |
339  * +-----------------------+
340  *
341  * @param smsg      AJP message to put serialized message
342  * @return          APR_SUCCESS or error
343  */
344 apr_status_t ajp_msg_serialize_ping(ajp_msg_t *msg);
345
346 /** 
347  * Serialize in an AJP Message a CPING command
348  *
349  * +-----------------------+
350  * | CPING CMD (1 byte)    |
351  * +-----------------------+
352  *
353  * @param smsg      AJP message to put serialized message
354  * @return          APR_SUCCESS or error
355  */
356 apr_status_t ajp_msg_serialize_cping(ajp_msg_t *msg);
357
358 /**
359  * Dump up to the first 1024 bytes on an AJP Message
360  *
361  * @param pool      pool to allocate from
362  * @param msg       AJP Message to dump
363  * @param err       error string to display
364  * @return          dump message
365  */
366 char * ajp_msg_dump(apr_pool_t *pool, ajp_msg_t *msg, char *err);
367
368 /** 
369  * Send an AJP message to backend
370  *
371  * @param soct      backend socket
372  * @param smsg      AJP message to put serialized message
373  * @return          APR_SUCCESS or error
374  */
375 apr_status_t ajp_ilink_send(apr_socket_t *sock, ajp_msg_t *msg);
376
377 /** 
378  * Receive an AJP message from backend
379  *
380  * @param sock      backend socket
381  * @param smsg      AJP message to put serialized message
382  * @return          APR_SUCCESS or error
383  */
384 apr_status_t ajp_ilink_receive(apr_socket_t *sock, ajp_msg_t *msg);
385
386 /**
387  * Build the ajp header message and send it
388  * @param sock      backend socket
389  * @param r         current request
390  * @uri uri         requested uri
391  * @return          APR_SUCCESS or error
392  */
393 apr_status_t ajp_send_header(apr_socket_t *sock, request_rec *r,
394                              apr_uri_t *uri);
395
396 /**
397  * Read the ajp message and return the type of the message.
398  * @param sock      backend socket
399  * @param r         current request
400  * @param msg       returned AJP message
401  * @return          APR_SUCCESS or error
402  */
403 apr_status_t ajp_read_header(apr_socket_t *sock,
404                              request_rec  *r,
405                              ajp_msg_t **msg);
406
407 /**
408  * Allocate a msg to send data
409  * @param pool      pool to allocate from
410  * @param ptr       data buffer
411  * @param len       the length of allocated data buffer
412  * @param msg       returned AJP message
413  * @return          APR_SUCCESS or error
414  */
415 apr_status_t  ajp_alloc_data_msg(apr_pool_t *pool, char **ptr,
416                                  apr_size_t *len, ajp_msg_t **msg);
417
418 /**
419  * Send the data message
420  * @param sock      backend socket
421  * @param msg       AJP message to send
422  * @param len       AJP message length      
423  * @return          APR_SUCCESS or error
424  */
425 apr_status_t  ajp_send_data_msg(apr_socket_t *sock,
426                                 ajp_msg_t *msg, apr_size_t len);
427
428 /**
429  * Parse the message type 
430  * @param r         current request
431  * @param msg       AJP message
432  * @return          AJP message type.
433  */
434 int ajp_parse_type(request_rec  *r, ajp_msg_t *msg);
435
436 /**
437  * Parse the header message from container 
438  * @param r         current request
439  * @param msg       AJP message
440  * @return          APR_SUCCESS or error
441  */
442 apr_status_t ajp_parse_header(request_rec *r, proxy_server_conf *conf,
443                               ajp_msg_t *msg);
444
445 /** 
446  * Parse the message body and return data address and length 
447  * @param r         current request
448  * @param msg       AJP message
449  * @param len       returned AJP message length 
450  * @param ptr       returned data
451  * @return          APR_SUCCESS or error
452  */
453 apr_status_t  ajp_parse_data(request_rec  *r, ajp_msg_t *msg,
454                              apr_uint16_t *len, char **ptr);
455
456 /** @} */
457
458 #endif /* AJP_H */
459