ajp_header.c revision 5cd4f796d242bd32ff29a924cf0a608eea1e464f
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * applicable.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Licensed under the Apache License, Version 2.0 (the "License");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * you may not use this file except in compliance with the License.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * You may obtain a copy of the License at
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Unless required by applicable law or agreed to in writing, software
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * distributed under the License is distributed on an "AS IS" BASIS,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * See the License for the specific language governing permissions and
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * limitations under the License.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *response_trans_headers[] = {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Content-Type",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Content-Language",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Content-Length",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Last-Modified",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Location",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Set-Cookie",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Set-Cookie2",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Servlet-Engine",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "WWW-Authenticate"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *p = header_name;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* ACCEPT-LANGUAGE is the longest headeer
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * that is of interest.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb while (*p)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb switch (header[0]) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* NOTREACHED */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Apache method number to SC methods transform table */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const unsigned char sc_for_req_method_table[] = {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb 0, /* M_DELETE */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb 0, /* M_PATCH */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb 0 /* M_INVALID */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Message structure
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb request_prefix (1) (byte)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb method (byte)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb protocol (string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb req_uri (string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb remote_addr (string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb remote_host (string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb server_name (string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb server_port (short)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb is_ssl (boolean)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb num_headers (short)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb num_headers*(req_header_name header_value)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ?context (byte)(string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ?servlet_path (byte)(string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ?remote_user (byte)(string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ?auth_type (byte)(string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ?query_string (byte)(string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ?jvm_route (byte)(string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ?ssl_cert (byte)(string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ?ssl_cipher (byte)(string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ?ssl_session (byte)(string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ?ssl_key_size (byte)(int) via JkOptions +ForwardKeySize
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb request_terminator (byte)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ?body content_length*(var binary)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic apr_status_t ajp_marshal_into_msgb(ajp_msg_t *msg,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const apr_array_header_t *arr = apr_table_elts(r->subprocess_env);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const apr_table_entry_t *elts = (const apr_table_entry_t *)arr->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Into ajp_marshal_into_msgb");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((method = sc_for_req_method_by_id(r->method_number)) == UNKNOWN_METHOD) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb - No such method %s",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb is_ssl = (apr_byte_t) ap_proxy_conn_is_https(r->connection);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const apr_array_header_t *t = apr_table_elts(r->headers_in);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb remote_host = (char *)ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_HOST, NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ajp_msg_append_uint8(msg, CMD_AJP13_FORWARD_REQUEST) ||
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ajp_msg_append_uint16(msg, (apr_uint16_t)r->connection->local_addr->port) ||
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ajp_msg_append_uint16(msg, (apr_uint16_t) num_headers)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the message begining");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0 ; i < num_headers ; i++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const apr_array_header_t *t = apr_table_elts(r->headers_in);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const apr_table_entry_t *elts = (apr_table_entry_t *)t->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((sc = sc_for_req_header(elts[i].key)) != UNKNOWN_METHOD) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the header name");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the header name");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the header value");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: Header[%d] [%s] = [%s]",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* XXXX need to figure out how to do this
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (s->secret) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ajp_msg_append_uint8(msg, SC_A_SECRET) ||
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ajp_msg_append_string(msg, s->secret)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error ajp_marshal_into_msgb - "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending secret");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return APR_EGENERAL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the remote user");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the auth type");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* XXXX ebcdic (args converted?) */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the query string");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((session_route = apr_table_get(r->notes, "session-route"))) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the jvm route");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* XXX: Is the subprocess_env a right place?
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * <Location /examples>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ProxyPass ajp://remote:8009/servlets-examples
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * SetEnv SSL_SESSION_ID CUSTOM_SSL_SESSION_ID
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * </Location>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((envvar = ap_proxy_ssl_val(r->pool, r->server, r->connection, r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the SSL certificates");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((envvar = ap_proxy_ssl_val(r->pool, r->server, r->connection, r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the SSL ciphers");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((envvar = ap_proxy_ssl_val(r->pool, r->server, r->connection, r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the SSL session");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ssl_key_size is required by Servlet 2.3 API
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * added support only in ajp14 mode
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * JFC removed: ae->proto == AJP14_PROTO
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* XXXX ignored for the moment
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (s->ssl_key_size != -1) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ajp_msg_append_uint8(msg, SC_A_SSL_KEY_SIZE) ||
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ajp_msg_append_uint16(msg, (unsigned short) s->ssl_key_size)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error ajp_marshal_into_msgb - "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the SSL key size");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return APR_EGENERAL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Use the environment vars prefixed with AJP_
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * and pass it to the header striping that prefix.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending attribute %s=%s",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Error appending the message end");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_marshal_into_msgb: Done");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb response_prefix (2)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb status (short)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb status_msg (short)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb num_headers (short)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb num_headers*(res_header_name header_value)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *body_chunk
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb terminator boolean <! -- recycle connection or not -->
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbreq_header_name :=
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sc_req_header_name | (string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbres_header_name :=
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sc_res_header_name | (string)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbheader_value :=
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbbody_chunk :=
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb length (short)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb body length*(var binary)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic apr_status_t ajp_unmarshal_response(ajp_msg_t *msg,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *ptr;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_unmarshal_response: Null status");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->status_line = apr_psprintf(r->pool, "%d %s", status, ptr);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_xlate_proto_from_ascii(r->status_line, strlen(r->status_line));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_unmarshal_response: Number of headers is = %d",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for(i = 0 ; i < (int) num_headers ; i++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *stringname;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *value;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_unmarshal_response: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "No such sc (%08x)",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_unmarshal_response: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Null header name");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_xlate_proto_from_ascii(stringname, strlen(stringname));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_unmarshal_response: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Null header value");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Set-Cookie need additional processing */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Location, Content-Location, URI and Destination need additional
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * processing */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_unmarshal_response: Header[%d] [%s] = [%s]",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Content-type needs an additional handling */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* add corresponding filter */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_unmarshal_response: ap_set_content_type done");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Build the ajp header message and send it
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_send_header: ajp_msg_create failed");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_send_header: ajp_marshal_into_msgb failed");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_send_header: ajp_ilink_send failed");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Read the ajp message and return the type of the message.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_read_header: ajp_msg_create failed");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_read_header: ajp_ilink_receive failed");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* parse the msg to read the type */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return (int) result;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* parse the header */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbapr_status_t ajp_parse_header(request_rec *r, proxy_dir_conf *conf,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_parse_headers: ajp_msg_get_byte failed");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_parse_headers: wrong type %02x expecting 0x04", result);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* parse the body and return data address and length */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbapr_status_t ajp_parse_data(request_rec *r, ajp_msg_t *msg,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_parse_data: ajp_msg_get_byte failed");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "ajp_parse_data: wrong type %02x expecting 0x03", result);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Allocate a msg to send data
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbapr_status_t ajp_alloc_data_msg(apr_pool_t *pool, char **ptr, apr_size_t *len,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Send the data message