ajp_header.c revision dd2d34f14a343f4d6ffd8c620384309a733f7301
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ajp_header.h"
#include "ajp.h"
static const char *response_trans_headers[] = {
"Content-Type",
"Content-Language",
"Content-Length",
"Date",
"Last-Modified",
"Location",
"Set-Cookie",
"Set-Cookie2",
"Servlet-Engine",
"Status",
"WWW-Authenticate"
};
static const char *long_res_header_for_sc(int sc)
{
}
return rc;
}
#define UNKNOWN_METHOD (-1)
static int sc_for_req_header(const char *header_name)
{
char header[16];
const char *p = header_name;
int i = 0;
/* ACCEPT-LANGUAGE is the longest header
* that is of interest.
*/
return UNKNOWN_METHOD;
while (*p)
header[i++] = apr_toupper(*p++);
header[i] = '\0';
p = &header[1];
switch (header[0]) {
case 'A':
if (!header[6])
return SC_ACCEPT;
p += 6;
if (strcmp(p, "CHARSET") == 0)
return SC_ACCEPT_CHARSET;
else if (strcmp(p, "ENCODING") == 0)
return SC_ACCEPT_ENCODING;
else if (strcmp(p, "LANGUAGE") == 0)
return SC_ACCEPT_LANGUAGE;
else
return UNKNOWN_METHOD;
}
else
return UNKNOWN_METHOD;
}
else if (strcmp(p, "UTHORIZATION") == 0)
return SC_AUTHORIZATION;
else
return UNKNOWN_METHOD;
break;
case 'C':
if(strcmp(p, "OOKIE2") == 0)
return SC_COOKIE2;
else if (strcmp(p, "OOKIE") == 0)
return SC_COOKIE;
else if(strcmp(p, "ONNECTION") == 0)
return SC_CONNECTION;
else if(strcmp(p, "ONTENT-TYPE") == 0)
return SC_CONTENT_TYPE;
else if(strcmp(p, "ONTENT-LENGTH") == 0)
return SC_CONTENT_LENGTH;
else
return UNKNOWN_METHOD;
break;
case 'H':
if(strcmp(p, "OST") == 0)
return SC_HOST;
else
return UNKNOWN_METHOD;
break;
case 'P':
if(strcmp(p, "RAGMA") == 0)
return SC_PRAGMA;
else
return UNKNOWN_METHOD;
break;
case 'R':
if(strcmp(p, "EFERER") == 0)
return SC_REFERER;
else
return UNKNOWN_METHOD;
break;
case 'U':
if(strcmp(p, "SER-AGENT") == 0)
return SC_USER_AGENT;
else
return UNKNOWN_METHOD;
break;
default:
return UNKNOWN_METHOD;
}
/* NOTREACHED */
}
/* Apache method number to SC methods transform table */
static const unsigned char sc_for_req_method_table[] = {
0, /* M_DELETE */
0, /* M_PATCH */
0 /* M_INVALID */
};
static int sc_for_req_method_by_id(request_rec *r)
{
int method_id = r->method_number;
return UNKNOWN_METHOD;
}
else if (r->header_only) {
return SC_M_HEAD;
}
else {
return sc_for_req_method_table[method_id] ?
}
}
/*
* Message structure
*
*
request_prefix (1) (byte)
method (byte)
protocol (string)
req_uri (string)
remote_addr (string)
remote_host (string)
server_name (string)
server_port (short)
is_ssl (boolean)
num_headers (short)
num_headers*(req_header_name header_value)
?context (byte)(string)
?servlet_path (byte)(string)
?remote_user (byte)(string)
?auth_type (byte)(string)
?query_string (byte)(string)
?jvm_route (byte)(string)
?ssl_cert (byte)(string)
?ssl_cipher (byte)(string)
?ssl_session (byte)(string)
?ssl_key_size (byte)(int) via JkOptions +ForwardKeySize
request_terminator (byte)
?body content_length*(var binary)
*/
request_rec *r,
{
int method;
apr_uint32_t i, num_headers = 0;
char *remote_host;
const char *session_route, *envvar;
"Into ajp_marshal_into_msgb");
"ajp_marshal_into_msgb - No such method %s",
r->method);
return AJP_EBAD_METHOD;
}
num_headers = t->nelts;
}
"ajp_marshal_into_msgb: "
"Error appending the message begining");
return APR_EGENERAL;
}
for (i = 0 ; i < num_headers ; i++) {
int sc;
"ajp_marshal_into_msgb: "
"Error appending the header name");
return AJP_EOVERFLOW;
}
}
else {
"ajp_marshal_into_msgb: "
"Error appending the header name");
return AJP_EOVERFLOW;
}
}
"ajp_marshal_into_msgb: "
"Error appending the header value");
return AJP_EOVERFLOW;
}
"ajp_marshal_into_msgb: Header[%d] [%s] = [%s]",
}
/* XXXX need to figure out how to do this
if (s->secret) {
if (ajp_msg_append_uint8(msg, SC_A_SECRET) ||
ajp_msg_append_string(msg, s->secret)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"Error ajp_marshal_into_msgb - "
"Error appending secret");
return APR_EGENERAL;
}
}
*/
if (r->user) {
"ajp_marshal_into_msgb: "
"Error appending the remote user");
return AJP_EOVERFLOW;
}
}
if (r->ap_auth_type) {
"ajp_marshal_into_msgb: "
"Error appending the auth type");
return AJP_EOVERFLOW;
}
}
/* XXXX ebcdic (args converted?) */
"ajp_marshal_into_msgb: "
"Error appending the query string");
return AJP_EOVERFLOW;
}
}
"ajp_marshal_into_msgb: "
"Error appending the jvm route");
return AJP_EOVERFLOW;
}
}
/* XXX: Is the subprocess_env a right place?
* <Location /examples>
* ProxyPass ajp://remote:8009/servlets-examples
* SetEnv SSL_SESSION_ID CUSTOM_SSL_SESSION_ID
* </Location>
*/
/*
* Only lookup SSL variables if we are currently running HTTPS.
* Furthermore ensure that only variables get set in the AJP message
* that are not NULL and not empty.
*/
if (is_ssl) {
&& envvar[0]) {
"ajp_marshal_into_msgb: "
"Error appending the SSL certificates");
return AJP_EOVERFLOW;
}
}
&& envvar[0]) {
"ajp_marshal_into_msgb: "
"Error appending the SSL ciphers");
return AJP_EOVERFLOW;
}
}
&& envvar[0]) {
"ajp_marshal_into_msgb: "
"Error appending the SSL session");
return AJP_EOVERFLOW;
}
}
/* ssl_key_size is required by Servlet 2.3 API */
&& envvar[0]) {
"Error ajp_marshal_into_msgb - "
"Error appending the SSL key size");
return APR_EGENERAL;
}
}
}
/* Forward the remote port information, which was forgotten
* from the builtin data of the AJP 13 protocol.
* Since the servlet spec allows to retrieve it via getRemotePort(),
* we provide the port to the Tomcat connector as a request
* attribute. Modern Tomcat versions know how to retrieve
* the remote port from this attribute.
*/
{
const char *key = SC_A_REQ_REMOTE_PORT;
"ajp_marshal_into_msgb: "
"Error appending attribute %s=%s",
return AJP_EOVERFLOW;
}
}
/* Use the environment vars prefixed with AJP_
* and pass it to the header striping that prefix.
*/
"ajp_marshal_into_msgb: "
"Error appending attribute %s=%s",
return AJP_EOVERFLOW;
}
}
}
"ajp_marshal_into_msgb: "
"Error appending the message end");
return AJP_EOVERFLOW;
}
"ajp_marshal_into_msgb: Done");
return APR_SUCCESS;
}
/*
response_prefix (2)
status (short)
status_msg (short)
num_headers (short)
num_headers*(res_header_name header_value)
*body_chunk
terminator boolean <! -- recycle connection or not -->
req_header_name :=
sc_req_header_name | (string)
res_header_name :=
sc_res_header_name | (string)
header_value :=
(string)
body_chunk :=
length (short)
body length*(var binary)
*/
{
return 1;
}
request_rec *r,
{
const char *ptr;
int i;
if (rc != APR_SUCCESS) {
"ajp_unmarshal_response: Null status");
return rc;
}
if (rc == APR_SUCCESS) {
#if APR_CHARSET_EBCDIC /* copy only if we have to */
#endif
} else {
r->status_line = NULL;
}
"ajp_unmarshal_response: status = %d", status);
if (rc == APR_SUCCESS) {
/* First, tuck away all already existing cookies */
/*
* Could optimize here, but just in case we want to
* also save other headers, keep this logic.
*/
"Set-Cookie", NULL);
r->headers_out = save_table;
} else {
r->headers_out = NULL;
num_headers = 0;
}
"ajp_unmarshal_response: Number of headers is = %d",
for(i = 0 ; i < (int) num_headers ; i++) {
const char *stringname;
const char *value;
if (rc != APR_SUCCESS) {
return rc;
}
if (stringname == NULL) {
"ajp_unmarshal_response: "
"No such sc (%08x)",
name);
return AJP_EBAD_HEADER;
}
} else {
name = 0;
if (rc != APR_SUCCESS) {
"ajp_unmarshal_response: "
"Null header name");
return rc;
}
}
if (rc != APR_SUCCESS) {
"ajp_unmarshal_response: "
"Null header value");
return rc;
}
/* Set-Cookie need additional processing */
}
/* Location, Content-Location, URI and Destination need additional
* processing */
{
}
"ajp_unmarshal_response: Header[%d] [%s] = [%s]",
i, stringname, value);
/* Content-type needs an additional handling */
/* add corresponding filter */
"ajp_unmarshal_response: ap_set_content_type to '%s'", value);
}
}
return APR_SUCCESS;
}
/*
* Build the ajp header message and send it
*/
request_rec *r,
{
if (rc != APR_SUCCESS) {
"ajp_send_header: ajp_msg_create failed");
return rc;
}
if (rc != APR_SUCCESS) {
"ajp_send_header: ajp_marshal_into_msgb failed");
return rc;
}
if (rc != APR_SUCCESS) {
"ajp_send_header: ajp_ilink_send failed");
return rc;
}
return APR_SUCCESS;
}
/*
* Read the ajp message and return the type of the message.
*/
request_rec *r,
{
if (*msg) {
if (rc != APR_SUCCESS) {
"ajp_read_header: ajp_msg_reuse failed");
return rc;
}
}
else {
if (rc != APR_SUCCESS) {
"ajp_read_header: ajp_msg_create failed");
return rc;
}
}
ajp_msg_reset(*msg);
if (rc != APR_SUCCESS) {
"ajp_read_header: ajp_ilink_receive failed");
return rc;
}
"ajp_read_header: ajp_ilink_received 0x%02x", result);
return APR_SUCCESS;
}
/* parse the msg to read the type */
{
"ajp_parse_type: got 0x%02x", result);
return (int) result;
}
/* parse the header */
{
if (rc != APR_SUCCESS) {
"ajp_parse_headers: ajp_msg_get_byte failed");
return rc;
}
if (result != CMD_AJP13_SEND_HEADERS) {
"ajp_parse_headers: wrong type 0x%02x expecting 0x%02x",
return AJP_EBAD_HEADER;
}
}
/* parse the body and return data address and length */
{
if (rc != APR_SUCCESS) {
"ajp_parse_data: ajp_msg_get_byte failed");
return rc;
}
if (result != CMD_AJP13_SEND_BODY_CHUNK) {
"ajp_parse_data: wrong type 0x%02x expecting 0x%02x",
return AJP_EBAD_HEADER;
}
if (rc != APR_SUCCESS) {
return rc;
}
/*
* msg->len contains the complete length of the message including all
* headers. So the expected length for a CMD_AJP13_SEND_BODY_CHUNK is
* msg->len minus the sum of
* AJP_HEADER_LEN : The length of the header to every AJP message.
* AJP_HEADER_SZ_LEN : The header giving the size of the chunk.
* 1 : The CMD_AJP13_SEND_BODY_CHUNK indicator byte (0x03).
* 1 : The last byte of this message always seems to be
* 0x00 and is not part of the chunk.
*/
if (*len != expected_len) {
"ajp_parse_data: Wrong chunk length. Length of chunk is %i,"
return AJP_EBAD_HEADER;
}
return APR_SUCCESS;
}
/* Check the reuse flag in CMD_AJP13_END_RESPONSE */
{
if (rc != APR_SUCCESS) {
"ajp_parse_reuse: ajp_msg_get_byte failed");
return rc;
}
if (result != CMD_AJP13_END_RESPONSE) {
"ajp_parse_reuse: wrong type 0x%02x expecting 0x%02x",
return AJP_EBAD_HEADER;
}
}
/*
* Allocate a msg to send data
*/
{
return rc;
ajp_msg_reset(*msg);
return APR_SUCCESS;
}
/*
* Send the data message
*/
{
}