PageRenderTime 37ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/httpd-2.4.2/modules/proxy/ajp.h

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