ajp.h revision 742318b93e89c311f66b55f426c4d9cf2c14628b
181e56d8b348d301d615ccf5465ae600fee2867berikabele/* Licensed to the Apache Software Foundation (ASF) under one or more
181e56d8b348d301d615ccf5465ae600fee2867berikabele * contributor license agreements. See the NOTICE file distributed with
181e56d8b348d301d615ccf5465ae600fee2867berikabele * this work for additional information regarding copyright ownership.
2470bf1424599e7876e1f5b6db234a6a66282ef8slive * The ASF licenses this file to You under the Apache License, Version 2.0
2470bf1424599e7876e1f5b6db234a6a66282ef8slive * (the "License"); you may not use this file except in compliance with
2470bf1424599e7876e1f5b6db234a6a66282ef8slive * the License. You may obtain a copy of the License at
5a58787efeb02a1c3f06569d019ad81fd2efa06end *
5a58787efeb02a1c3f06569d019ad81fd2efa06end * http://www.apache.org/licenses/LICENSE-2.0
5a58787efeb02a1c3f06569d019ad81fd2efa06end *
5a58787efeb02a1c3f06569d019ad81fd2efa06end * Unless required by applicable law or agreed to in writing, software
5a58787efeb02a1c3f06569d019ad81fd2efa06end * distributed under the License is distributed on an "AS IS" BASIS,
5a58787efeb02a1c3f06569d019ad81fd2efa06end * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5a58787efeb02a1c3f06569d019ad81fd2efa06end * See the License for the specific language governing permissions and
5a58787efeb02a1c3f06569d019ad81fd2efa06end * limitations under the License.
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz */
5a58787efeb02a1c3f06569d019ad81fd2efa06end
5a58787efeb02a1c3f06569d019ad81fd2efa06end/**
5a58787efeb02a1c3f06569d019ad81fd2efa06end * @file ajp.h
4b5981e276e93df97c34e4da05ca5cf8bbd937dand * @brief Apache Jserv Protocol
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd *
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * @defgroup AJP_defines AJP definitions
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * @ingroup MOD_PROXY
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * @{
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd */
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd#ifndef AJP_H
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd#define AJP_H
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen
7f2bf625b283a5892b4f85e186edb086080dcf96erikabele#include "apr_version.h"
7f2bf625b283a5892b4f85e186edb086080dcf96erikabele#include "apr.h"
7f2bf625b283a5892b4f85e186edb086080dcf96erikabele
7f2bf625b283a5892b4f85e186edb086080dcf96erikabele#include "apr_hooks.h"
7f2bf625b283a5892b4f85e186edb086080dcf96erikabele#include "apr_lib.h"
5a58787efeb02a1c3f06569d019ad81fd2efa06end#include "apr_strings.h"
5a58787efeb02a1c3f06569d019ad81fd2efa06end#include "apr_buckets.h"
5a58787efeb02a1c3f06569d019ad81fd2efa06end#include "apr_md5.h"
5a58787efeb02a1c3f06569d019ad81fd2efa06end#include "apr_network_io.h"
5a58787efeb02a1c3f06569d019ad81fd2efa06end#include "apr_poll.h"
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm#include "apr_pools.h"
d3abd6e75e12da87b0ab3aecc6017dfc7267b2cerbowen#include "apr_strings.h"
5a58787efeb02a1c3f06569d019ad81fd2efa06end#include "apr_uri.h"
5a58787efeb02a1c3f06569d019ad81fd2efa06end#include "apr_date.h"
5a58787efeb02a1c3f06569d019ad81fd2efa06end#include "apr_fnmatch.h"
9afc027f0d7f85979066cd278a271a4930b5ad11slive#define APR_WANT_STRFUNC
9afc027f0d7f85979066cd278a271a4930b5ad11slive#include "apr_want.h"
9bcfc3697a91b5215893a7d0206865b13fc72148nd
9afc027f0d7f85979066cd278a271a4930b5ad11slive#if APR_HAVE_NETINET_IN_H
b3dd544b1f17efe6d927c15408d911f64d83bd48kess#include <netinet/in.h>
9bcfc3697a91b5215893a7d0206865b13fc72148nd#endif
9afc027f0d7f85979066cd278a271a4930b5ad11slive#if APR_HAVE_ARPA_INET_H
9afc027f0d7f85979066cd278a271a4930b5ad11slive#include <arpa/inet.h>
9afc027f0d7f85979066cd278a271a4930b5ad11slive#endif
d3abd6e75e12da87b0ab3aecc6017dfc7267b2cerbowen
7eb26bcd90adad324330ce83e1b90ebe54a28948nd#define AJP13_DEF_HOST "127.0.0.1"
d3abd6e75e12da87b0ab3aecc6017dfc7267b2cerbowen#ifdef NETWARE
7eb26bcd90adad324330ce83e1b90ebe54a28948nd#define AJP13_DEF_PORT 9009 /* default to 9009 since 8009 is used by OS */
d3abd6e75e12da87b0ab3aecc6017dfc7267b2cerbowen#else
9afc027f0d7f85979066cd278a271a4930b5ad11slive#define AJP13_DEF_PORT 8009
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#endif
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen/* The following environment variables match mod_ssl! */
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define AJP13_HTTPS_INDICATOR "HTTPS"
9afc027f0d7f85979066cd278a271a4930b5ad11slive#define AJP13_SSL_CLIENT_CERT_INDICATOR "SSL_CLIENT_CERT"
2470bf1424599e7876e1f5b6db234a6a66282ef8slive#define AJP13_SSL_CIPHER_INDICATOR "SSL_CIPHER"
9bcfc3697a91b5215893a7d0206865b13fc72148nd#define AJP13_SSL_SESSION_INDICATOR "SSL_SESSION_ID"
dc1eee5ace4a2dec38d0b37d6daf9efb7e3c81b7kess#define AJP13_SSL_KEY_SIZE_INDICATOR "SSL_CIPHER_USEKEYSIZE"
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm
9bcfc3697a91b5215893a7d0206865b13fc72148nd#ifdef AJP_USE_HTTPD_WRAP
9bcfc3697a91b5215893a7d0206865b13fc72148nd#include "httpd_wrap.h"
9bcfc3697a91b5215893a7d0206865b13fc72148nd#else
2470bf1424599e7876e1f5b6db234a6a66282ef8slive#include "httpd.h"
9bcfc3697a91b5215893a7d0206865b13fc72148nd#include "http_config.h"
9afc027f0d7f85979066cd278a271a4930b5ad11slive#include "http_request.h"
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#include "http_core.h"
9afc027f0d7f85979066cd278a271a4930b5ad11slive#include "http_protocol.h"
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#include "http_main.h"
9afc027f0d7f85979066cd278a271a4930b5ad11slive#include "http_log.h"
5a58787efeb02a1c3f06569d019ad81fd2efa06end#endif
5a58787efeb02a1c3f06569d019ad81fd2efa06end
5a58787efeb02a1c3f06569d019ad81fd2efa06end#include "mod_proxy.h"
2470bf1424599e7876e1f5b6db234a6a66282ef8slive#include "util_ebcdic.h"
2470bf1424599e7876e1f5b6db234a6a66282ef8slive
9afc027f0d7f85979066cd278a271a4930b5ad11slive/** AJP Specific error codes
2470bf1424599e7876e1f5b6db234a6a66282ef8slive */
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen/** Buffer overflow exception */
9afc027f0d7f85979066cd278a271a4930b5ad11slive#define AJP_EOVERFLOW (APR_OS_START_USERERR + 1)
9afc027f0d7f85979066cd278a271a4930b5ad11slive/** Destination Buffer is to small */
9afc027f0d7f85979066cd278a271a4930b5ad11slive#define AJP_ETOSMALL (APR_OS_START_USERERR + 2)
9afc027f0d7f85979066cd278a271a4930b5ad11slive/** Invalid input parameters */
9afc027f0d7f85979066cd278a271a4930b5ad11slive#define AJP_EINVAL (APR_OS_START_USERERR + 3)
5a58787efeb02a1c3f06569d019ad81fd2efa06end/** Bad message signature */
5a58787efeb02a1c3f06569d019ad81fd2efa06end#define AJP_EBAD_SIGNATURE (APR_OS_START_USERERR + 4)
5a58787efeb02a1c3f06569d019ad81fd2efa06end/** Incoming message too bg */
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define AJP_ETOBIG (APR_OS_START_USERERR + 5)
2470bf1424599e7876e1f5b6db234a6a66282ef8slive/** Missing message header */
9afc027f0d7f85979066cd278a271a4930b5ad11slive#define AJP_ENO_HEADER (APR_OS_START_USERERR + 6)
2470bf1424599e7876e1f5b6db234a6a66282ef8slive/** Bad message header */
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define AJP_EBAD_HEADER (APR_OS_START_USERERR + 7)
9afc027f0d7f85979066cd278a271a4930b5ad11slive/** Bad message */
9afc027f0d7f85979066cd278a271a4930b5ad11slive#define AJP_EBAD_MESSAGE (APR_OS_START_USERERR + 8)
9afc027f0d7f85979066cd278a271a4930b5ad11slive/** Cant log via AJP14 */
9afc027f0d7f85979066cd278a271a4930b5ad11slive#define AJP_ELOGFAIL (APR_OS_START_USERERR + 9)
9afc027f0d7f85979066cd278a271a4930b5ad11slive/** Bad request method */
9afc027f0d7f85979066cd278a271a4930b5ad11slive#define AJP_EBAD_METHOD (APR_OS_START_USERERR + 10)
9afc027f0d7f85979066cd278a271a4930b5ad11slive
2470bf1424599e7876e1f5b6db234a6a66282ef8slive
2470bf1424599e7876e1f5b6db234a6a66282ef8slive/** A structure that represents ajp message */
2470bf1424599e7876e1f5b6db234a6a66282ef8slivetypedef struct ajp_msg ajp_msg_t;
2470bf1424599e7876e1f5b6db234a6a66282ef8slive
2470bf1424599e7876e1f5b6db234a6a66282ef8slive/** A structure that represents ajp message */
181e56d8b348d301d615ccf5465ae600fee2867berikabelestruct ajp_msg
181e56d8b348d301d615ccf5465ae600fee2867berikabele{
2470bf1424599e7876e1f5b6db234a6a66282ef8slive /** The buffer holding a AJP message */
2470bf1424599e7876e1f5b6db234a6a66282ef8slive apr_byte_t *buf;
2470bf1424599e7876e1f5b6db234a6a66282ef8slive /** The length of AJP message header (defaults to AJP_HEADER_LEN) */
1494875b08f5d3f65e9b7e844bc830a1d21101d1kess apr_size_t header_len;
1494875b08f5d3f65e9b7e844bc830a1d21101d1kess /** The length of AJP message */
2470bf1424599e7876e1f5b6db234a6a66282ef8slive apr_size_t len;
1494875b08f5d3f65e9b7e844bc830a1d21101d1kess /** The current read position */
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen apr_size_t pos;
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen /** Flag indicating the origing of the message */
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen int server_side;
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen /** The size of the buffer */
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen apr_size_t max_size;
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen};
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen/**
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * Signature for the messages sent from Apache to tomcat
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen */
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define AJP13_WS_HEADER 0x1234
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define AJP_HEADER_LEN 4
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define AJP_HEADER_SZ_LEN 2
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define AJP_HEADER_SZ 6
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define AJP_MSG_BUFFER_SZ 8192
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define AJP_MAX_BUFFER_SZ 65536
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define AJP13_MAX_SEND_BODY_SZ (AJP_MAX_BUFFER_SZ - AJP_HEADER_SZ)
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define AJP_PING_PONG_SZ 128
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen/** Send a request from web server to container*/
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define CMD_AJP13_FORWARD_REQUEST (unsigned char)2
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen/** Write a body chunk from the servlet container to the web server */
0091285a38c741ee51224a98002108e842495df5rbowen#define CMD_AJP13_SEND_BODY_CHUNK (unsigned char)3
0091285a38c741ee51224a98002108e842495df5rbowen/** Send response headers from the servlet container to the web server. */
0091285a38c741ee51224a98002108e842495df5rbowen#define CMD_AJP13_SEND_HEADERS (unsigned char)4
0091285a38c741ee51224a98002108e842495df5rbowen/** Marks the end of response. */
0091285a38c741ee51224a98002108e842495df5rbowen#define CMD_AJP13_END_RESPONSE (unsigned char)5
0091285a38c741ee51224a98002108e842495df5rbowen/** Get further data from the web server if it hasn't all been transferred yet. */
0091285a38c741ee51224a98002108e842495df5rbowen#define CMD_AJP13_GET_BODY_CHUNK (unsigned char)6
0091285a38c741ee51224a98002108e842495df5rbowen/** The web server asks the container to shut itself down. */
0091285a38c741ee51224a98002108e842495df5rbowen#define CMD_AJP13_SHUTDOWN (unsigned char)7
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen/** Webserver ask container to take control (logon phase) */
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#define CMD_AJP13_PING (unsigned char)8
9bcfc3697a91b5215893a7d0206865b13fc72148nd/** Container response to cping request */
9bcfc3697a91b5215893a7d0206865b13fc72148nd#define CMD_AJP13_CPONG (unsigned char)9
9bcfc3697a91b5215893a7d0206865b13fc72148nd/** Webserver check if container is alive, since container should respond by cpong */
9bcfc3697a91b5215893a7d0206865b13fc72148nd#define CMD_AJP13_CPING (unsigned char)10
9bcfc3697a91b5215893a7d0206865b13fc72148nd
0091285a38c741ee51224a98002108e842495df5rbowen/** @} */
5a58787efeb02a1c3f06569d019ad81fd2efa06end
5a58787efeb02a1c3f06569d019ad81fd2efa06end/**
5a58787efeb02a1c3f06569d019ad81fd2efa06end * @defgroup AJP_api AJP API functions
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * @ingroup MOD_PROXY
2470bf1424599e7876e1f5b6db234a6a66282ef8slive * @{
9afc027f0d7f85979066cd278a271a4930b5ad11slive */
2470bf1424599e7876e1f5b6db234a6a66282ef8slive/**
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * Check a new AJP Message by looking at signature and return its size
9afc027f0d7f85979066cd278a271a4930b5ad11slive *
9afc027f0d7f85979066cd278a271a4930b5ad11slive * @param msg AJP Message to check
9afc027f0d7f85979066cd278a271a4930b5ad11slive * @param len Pointer to returned len
9afc027f0d7f85979066cd278a271a4930b5ad11slive * @return APR_SUCCESS or error
9afc027f0d7f85979066cd278a271a4930b5ad11slive */
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowenapr_status_t ajp_msg_check_header(ajp_msg_t *msg, apr_size_t *len);
181e56d8b348d301d615ccf5465ae600fee2867berikabele
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen/**
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * Reset an AJP Message
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen *
0091285a38c741ee51224a98002108e842495df5rbowen * @param msg AJP Message to reset
0091285a38c741ee51224a98002108e842495df5rbowen * @return APR_SUCCESS or error
0091285a38c741ee51224a98002108e842495df5rbowen */
0091285a38c741ee51224a98002108e842495df5rbowenapr_status_t ajp_msg_reset(ajp_msg_t *msg);
5a58787efeb02a1c3f06569d019ad81fd2efa06end
5a58787efeb02a1c3f06569d019ad81fd2efa06end/**
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm * Reuse an AJP Message
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm *
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm * @param msg AJP Message to reuse
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm * @return APR_SUCCESS or error
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm */
144c96f1a9d2f0c8bfccafea655dae120f7470d2colmapr_status_t ajp_msg_reuse(ajp_msg_t *msg);
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm/**
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm * Mark the end of an AJP Message
5b111d121ddb14d690dde7c180402d0b9a030b7and *
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm * @param msg AJP Message to end
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm * @return APR_SUCCESS or error
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm */
5b111d121ddb14d690dde7c180402d0b9a030b7andapr_status_t ajp_msg_end(ajp_msg_t *msg);
5b111d121ddb14d690dde7c180402d0b9a030b7and
5b111d121ddb14d690dde7c180402d0b9a030b7and/**
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm * Add an unsigned 32bits value to AJP Message
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm *
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm * @param msg AJP Message to get value from
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm * @param value value to add to AJP Message
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm * @return APR_SUCCESS or error
144c96f1a9d2f0c8bfccafea655dae120f7470d2colm */
e45879d70a535d2700c2b4720d99830ae0da1d6acolmapr_status_t ajp_msg_append_uint32(ajp_msg_t *msg, apr_uint32_t value);
e45879d70a535d2700c2b4720d99830ae0da1d6acolm
e45879d70a535d2700c2b4720d99830ae0da1d6acolm/**
e45879d70a535d2700c2b4720d99830ae0da1d6acolm * Add an unsigned 16bits value to AJP Message
e45879d70a535d2700c2b4720d99830ae0da1d6acolm *
e45879d70a535d2700c2b4720d99830ae0da1d6acolm * @param msg AJP Message to get value from
e45879d70a535d2700c2b4720d99830ae0da1d6acolm * @param value value to add to AJP Message
e45879d70a535d2700c2b4720d99830ae0da1d6acolm * @return APR_SUCCESS or error
e45879d70a535d2700c2b4720d99830ae0da1d6acolm */
e45879d70a535d2700c2b4720d99830ae0da1d6acolmapr_status_t ajp_msg_append_uint16(ajp_msg_t *msg, apr_uint16_t value);
e45879d70a535d2700c2b4720d99830ae0da1d6acolm
e45879d70a535d2700c2b4720d99830ae0da1d6acolm/**
e45879d70a535d2700c2b4720d99830ae0da1d6acolm * Add an unsigned 8bits value to AJP Message
e45879d70a535d2700c2b4720d99830ae0da1d6acolm *
e45879d70a535d2700c2b4720d99830ae0da1d6acolm * @param msg AJP Message to get value from
e45879d70a535d2700c2b4720d99830ae0da1d6acolm * @param value value to add to AJP Message
e45879d70a535d2700c2b4720d99830ae0da1d6acolm * @return APR_SUCCESS or error
e45879d70a535d2700c2b4720d99830ae0da1d6acolm */
5a58787efeb02a1c3f06569d019ad81fd2efa06endapr_status_t ajp_msg_append_uint8(ajp_msg_t *msg, apr_byte_t value);
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd/**
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * Add a String in AJP message, and transform the String in ASCII
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * if convert is set and we're on an EBCDIC machine
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd *
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * @param msg AJP Message to get value from
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd * @param value Pointer to String
4b22542f6f38567cae7873b176188a6622f67eb0fielding * @param convert When set told to convert String to ASCII
5a58787efeb02a1c3f06569d019ad81fd2efa06end * @return APR_SUCCESS or error
20f6157c1ed768396995a96830bd8e76a3b654c1nd */
apr_status_t ajp_msg_append_string_ex(ajp_msg_t *msg, const char *value,
int convert);
/**
* Add a String in AJP message, and transform
* the String in ASCII if we're on an EBCDIC machine
*/
#define ajp_msg_append_string(m, v) ajp_msg_append_string_ex(m, v, 1)
/**
* Add a String in AJP message.
*/
#define ajp_msg_append_string_ascii(m, v) ajp_msg_append_string_ex(m, v, 0)
/**
* Add a Byte array to AJP Message
*
* @param msg AJP Message to get value from
* @param value Pointer to Byte array
* @param valuelen Byte array len
* @return APR_SUCCESS or error
*/
apr_status_t ajp_msg_append_bytes(ajp_msg_t *msg, const apr_byte_t *value,
apr_size_t valuelen);
/**
* 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 APR_SUCCESS or error
*/
apr_status_t ajp_msg_get_uint32(ajp_msg_t *msg, apr_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 APR_SUCCESS or error
*/
apr_status_t ajp_msg_get_uint16(ajp_msg_t *msg, apr_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 APR_SUCCESS or error
*/
apr_status_t ajp_msg_peek_uint16(ajp_msg_t *msg, apr_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 APR_SUCCESS or error
*/
apr_status_t ajp_msg_get_uint8(ajp_msg_t *msg, apr_byte_t *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 APR_SUCCESS or error
*/
apr_status_t ajp_msg_peek_uint8(ajp_msg_t *msg, apr_byte_t *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 APR_SUCCESS or error
*/
apr_status_t ajp_msg_get_string(ajp_msg_t *msg, const char **rvalue);
/**
* Get a Byte array from AJP Message
*
* @param msg AJP Message to get value from
* @param rvalue Pointer where value will be returned
* @param rvalue_len Pointer where Byte array len will be returned
* @return APR_SUCCESS or error
*/
apr_status_t ajp_msg_get_bytes(ajp_msg_t *msg, apr_byte_t **rvalue,
apr_size_t *rvalue_len);
/**
* 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 APR_SUCCESS or error
*/
apr_status_t ajp_msg_create(apr_pool_t *pool, apr_size_t size, ajp_msg_t **rmsg);
/**
* Recopy an AJP Message to another
*
* @param smsg source AJP message
* @param dmsg destination AJP message
* @return APR_SUCCESS or error
*/
apr_status_t ajp_msg_copy(ajp_msg_t *smsg, ajp_msg_t *dmsg);
/**
* Serialize in an AJP Message a PING command
*
* +-----------------------+
* | PING CMD (1 byte) |
* +-----------------------+
*
* @param msg AJP message to put serialized message
* @return APR_SUCCESS or error
*/
apr_status_t ajp_msg_serialize_ping(ajp_msg_t *msg);
/**
* Serialize in an AJP Message a CPING command
*
* +-----------------------+
* | CPING CMD (1 byte) |
* +-----------------------+
*
* @param msg AJP message to put serialized message
* @return APR_SUCCESS or error
*/
apr_status_t ajp_msg_serialize_cping(ajp_msg_t *msg);
/**
* Dump up to the first 1024 bytes on an AJP Message
*
* @param pool pool to allocate from
* @param msg AJP Message to dump
* @param err error string to display
* @param count the number of bytes to dump
* @param buf buffer pointer for dump message
* @return APR_SUCCESS or error
*/
apr_status_t ajp_msg_dump(apr_pool_t *pool, ajp_msg_t *msg, char *err,
apr_size_t count, char **buf);
/**
* Log an AJP message
*
* @param request The current request
* @param msg AJP Message to dump
* @param err error string to display
* @return APR_SUCCESS or error
*/
apr_status_t ajp_msg_log(request_rec *r, ajp_msg_t *msg, char *err);
/**
* Send an AJP message to backend
*
* @param sock backend socket
* @param msg AJP message to put serialized message
* @return APR_SUCCESS or error
*/
apr_status_t ajp_ilink_send(apr_socket_t *sock, ajp_msg_t *msg);
/**
* Receive an AJP message from backend
*
* @param sock backend socket
* @param msg AJP message to put serialized message
* @return APR_SUCCESS or error
*/
apr_status_t ajp_ilink_receive(apr_socket_t *sock, ajp_msg_t *msg);
/**
* Build the ajp header message and send it
* @param sock backend socket
* @param r current request
* @param buffsize max size of the AJP packet.
* @param uri requested uri
* @return APR_SUCCESS or error
*/
apr_status_t ajp_send_header(apr_socket_t *sock, request_rec *r,
apr_size_t buffsize,
apr_uri_t *uri);
/**
* Read the ajp message and return the type of the message.
* @param sock backend socket
* @param r current request
* @param buffsize size of the buffer.
* @param msg returned AJP message
* @return APR_SUCCESS or error
*/
apr_status_t ajp_read_header(apr_socket_t *sock,
request_rec *r,
apr_size_t buffsize,
ajp_msg_t **msg);
/**
* Allocate a msg to send data
* @param pool pool to allocate from
* @param ptr data buffer
* @param len the length of allocated data buffer
* @param msg returned AJP message
* @return APR_SUCCESS or error
*/
apr_status_t ajp_alloc_data_msg(apr_pool_t *pool, char **ptr,
apr_size_t *len, ajp_msg_t **msg);
/**
* Send the data message
* @param sock backend socket
* @param msg AJP message to send
* @param len AJP message length
* @return APR_SUCCESS or error
*/
apr_status_t ajp_send_data_msg(apr_socket_t *sock,
ajp_msg_t *msg, apr_size_t len);
/**
* Parse the message type
* @param r current request
* @param msg AJP message
* @return AJP message type.
*/
int ajp_parse_type(request_rec *r, ajp_msg_t *msg);
/**
* Parse the header message from container
* @param r current request
* @param conf proxy config
* @param msg AJP message
* @return APR_SUCCESS or error
*/
apr_status_t ajp_parse_header(request_rec *r, proxy_dir_conf *conf,
ajp_msg_t *msg);
/**
* Parse the message body and return data address and length
* @param r current request
* @param msg AJP message
* @param len returned AJP message length
* @param ptr returned data
* @return APR_SUCCESS or error
*/
apr_status_t ajp_parse_data(request_rec *r, ajp_msg_t *msg,
apr_uint16_t *len, char **ptr);
/**
* Check the reuse flag in CMD_AJP13_END_RESPONSE
* @param r current request
* @param msg AJP message
* @param reuse returned reuse flag
* @return APR_SUCCESS or error
*/
apr_status_t ajp_parse_reuse(request_rec *r, ajp_msg_t *msg,
apr_byte_t *reuse);
/**
* Handle the CPING/CPONG messages
* @param sock backend socket
* @param r current request
* @param timeout time window for receiving cpong reply
* @return APR_SUCCESS or error
*/
apr_status_t ajp_handle_cping_cpong(apr_socket_t *sock,
request_rec *r,
apr_interval_time_t timeout);
/**
* Convert numeric message type into string
* @param type AJP message type
* @return AJP message type as a string
*/
const char *ajp_type_str(int type);
/** @} */
#endif /* AJP_H */