ajp_header.c revision 0ded315d2c676a80a8d7f838df73cc81df9e91c7
/*
* Copyright 1999-2004 The Apache Software Foundation
*
* Licensed 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 headeer
* 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;
return SC_ACCEPT_CHARSET;
return SC_ACCEPT_ENCODING;
return SC_ACCEPT_LANGUAGE;
else
return UNKNOWN_METHOD;
}
else
return UNKNOWN_METHOD;
}
return SC_AUTHORIZATION;
else
return UNKNOWN_METHOD;
break;
case 'C':
return SC_COOKIE;
return SC_CONNECTION;
return SC_CONTENT_TYPE;
return SC_CONTENT_LENGTH;
return SC_COOKIE2;
else
return UNKNOWN_METHOD;
break;
case 'H':
return SC_HOST;
else
return UNKNOWN_METHOD;
break;
case 'P':
return SC_PRAGMA;
else
return UNKNOWN_METHOD;
break;
case 'R':
return SC_REFERER;
else
return UNKNOWN_METHOD;
break;
case 'U':
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(int method_id)
{
return UNKNOWN_METHOD;
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;
char *uri;
const char *session_route;
"Into ajp_marshal_into_msgb");
"Error ajp_marshal_into_msgb - No such method %s",
r->method);
return APR_EGENERAL;
}
/* XXXX need something */
num_headers = t->nelts;
}
*query_str = 0;
}
}
"Error ajp_marshal_into_msgb - "
"Error appending the message begining");
return APR_EGENERAL;
}
for (i = 0 ; i < num_headers ; i++) {
int sc;
"Error ajp_marshal_into_msgb - "
"Error appending the header name");
return APR_EGENERAL;
}
}
else {
"Error ajp_marshal_into_msgb - "
"Error appending the header name");
return APR_EGENERAL;
}
}
"Error ajp_marshal_into_msgb - "
"Error appending the header value");
return APR_EGENERAL;
}
"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) {
"Error ajp_marshal_into_msgb - "
"Error appending the remote user");
return APR_EGENERAL;
}
}
if (r->ap_auth_type) {
"Error ajp_marshal_into_msgb - "
"Error appending the auth type");
return APR_EGENERAL;
}
}
/* XXXX ebcdic (args converted?) */
if (r->args) {
"Error ajp_marshal_into_msgb - "
"Error appending the query string");
return APR_EGENERAL;
}
}
"Error ajp_marshal_into_msgb - "
"Error appending the jvm route");
return APR_EGENERAL;
}
}
/* XXXX ignored for the moment
if (s->ssl_cert_len) {
if (ajp_msg_append_uint8(msg, SC_A_SSL_CERT) ||
ajp_msg_append_string(msg, s->ssl_cert)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"Error ajp_marshal_into_msgb - "
"Error appending the SSL certificates");
return APR_EGENERAL;
}
}
if (s->ssl_cipher) {
if (ajp_msg_append_uint8(msg, SC_A_SSL_CIPHER) ||
ajp_msg_append_string(msg, s->ssl_cipher)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"Error ajp_marshal_into_msgb - "
"Error appending the SSL ciphers");
return APR_EGENERAL;
}
}
if (s->ssl_session) {
if (ajp_msg_append_uint8(msg, SC_A_SSL_SESSION) ||
ajp_msg_append_string(msg, s->ssl_session)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"Error ajp_marshal_into_msgb - "
"Error appending the SSL session");
return APR_EGENERAL;
}
}
*/
/*
* ssl_key_size is required by Servlet 2.3 API
* added support only in ajp14 mode
* JFC removed: ae->proto == AJP14_PROTO
*/
/* XXXX ignored for the moment
if (s->ssl_key_size != -1) {
if (ajp_msg_append_uint8(msg, SC_A_SSL_KEY_SIZE) ||
ajp_msg_append_uint16(msg, (unsigned short) s->ssl_key_size)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"Error ajp_marshal_into_msgb - "
"Error appending the SSL key size");
return APR_EGENERAL;
}
}
*/
/* Use the environment vars prefixed with AJP_
* and pass it to the header striping that prefix.
*/
"Error ajp_marshal_into_msgb - "
"Error appending attribute %s=%s",
return APR_EGENERAL;
}
}
}
"Error ajp_marshal_into_msgb - "
"Error appending the message end");
return APR_EGENERAL;
}
"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)
*/
request_rec *r)
{
char *ptr;
int i;
if (rc != APR_SUCCESS) {
"Error ajp_unmarshal_response - Null status");
return APR_EGENERAL;
}
if (rc == APR_SUCCESS) {
#if defined(AS400) || defined(_OSD_POSIX)
#endif
} else {
r->status_line = NULL;
}
"ajp_unmarshal_response: status = %d", status);
if (rc == APR_SUCCESS) {
} else {
r->headers_out = NULL;
num_headers = 0;
}
"ajp_unmarshal_response: Number of headers is = %d",
for(i = 0 ; i < (int) num_headers ; i++) {
char *stringname;
char *value;
if (rc != APR_SUCCESS) {
return APR_EGENERAL;
}
if (stringname == NULL) {
"Error ajp_unmarshal_response - "
"No such sc (%08x)",
name);
return APR_EGENERAL;
}
} else {
name = 0;
if (rc != APR_SUCCESS) {
"Error ajp_unmarshal_response - "
"Null header name");
return APR_EGENERAL;
}
#if defined(AS400) || defined(_OSD_POSIX)
#endif
}
if (rc != APR_SUCCESS) {
"Error ajp_unmarshal_response - "
"Null header value");
return APR_EGENERAL;
}
#if defined(AS400) || defined(_OSD_POSIX)
#endif
"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 done");
}
}
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 (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 %02x", result);
return APR_SUCCESS;
}
/* parse the msg to read the type */
{
"ajp_parse_type: got %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 %02x expecting 0x04", result);
return APR_EGENERAL;
}
return ajp_unmarshal_response(msg, r);
}
/* 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 %02x expecting 0x03", result);
return APR_EGENERAL;
}
if (rc != APR_SUCCESS) {
return APR_EGENERAL;
}
return APR_SUCCESS;
}
/*
* Allocate a msg to send data
*/
{
if (rc != APR_SUCCESS) {
"ajp_alloc_data_msg: ajp_msg_create failed");
return rc;
}
ajp_msg_reset(*msg);
return APR_SUCCESS;
}
/*
* Send the data message
*/
{
"ajp_send_data_msg: sending %d", len);
if (rc != APR_SUCCESS) {
"ajp_send_data_msg: ajp_ilink_send failed");
return rc;
}
return APR_SUCCESS;
}