ajp_header.c revision 3e13c3c3e6517a04c8c20ffb8e62aadb3b13f8df
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/* Licensed to the Apache Software Foundation (ASF) under one or more
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * contributor license agreements. See the NOTICE file distributed with
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * this work for additional information regarding copyright ownership.
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * The ASF licenses this file to You under the Apache License, Version 2.0
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * (the "License"); you may not use this file except in compliance with
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * the License. You may obtain a copy of the License at
a78048ccbdb6256da15e6b0e7e95355e480c2301nd *
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * http://www.apache.org/licenses/LICENSE-2.0
a78048ccbdb6256da15e6b0e7e95355e480c2301nd *
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * Unless required by applicable law or agreed to in writing, software
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * distributed under the License is distributed on an "AS IS" BASIS,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
2e545ce2450a9953665f701bb05350f0d3f26275nd * limitations under the License.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen */
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include "ajp_header.h"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include "ajp.h"
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen
3f08db06526d6901aa08c110b5bc7dde6bc39905ndAPLOG_USE_MODULE(proxy_ajp);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic const char *response_trans_headers[] = {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Content-Type",
3f08db06526d6901aa08c110b5bc7dde6bc39905nd "Content-Language",
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Content-Length",
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Date",
befb6758d5618c60f29b19f9a7eb75ab993511dcjim "Last-Modified",
aee1f193a276866212922ae5072e3014db28582frpluem "Location",
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung "Set-Cookie",
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Set-Cookie2",
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem "Servlet-Engine",
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem "Status",
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "WWW-Authenticate"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd};
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic const char *long_res_header_for_sc(int sc)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const char *rc = NULL;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd sc = sc & 0X00FF;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if(sc <= SC_RES_HEADERS_NUM && sc > 0) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd rc = response_trans_headers[sc - 1];
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return rc;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd}
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh#define UNKNOWN_METHOD (-1)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic int sc_for_req_header(const char *header_name)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{
a78048ccbdb6256da15e6b0e7e95355e480c2301nd char header[16];
a78048ccbdb6256da15e6b0e7e95355e480c2301nd apr_size_t len = strlen(header_name);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const char *p = header_name;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd int i = 0;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd /* ACCEPT-LANGUAGE is the longest header
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * that is of interest.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (len < 4 || len > 15)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return UNKNOWN_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd while (*p)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd header[i++] = apr_toupper(*p++);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd header[i] = '\0';
a78048ccbdb6256da15e6b0e7e95355e480c2301nd p = &header[1];
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd switch (header[0]) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd case 'A':
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (memcmp(p, "CCEPT", 5) == 0) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (!header[6])
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_ACCEPT;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else if (header[6] == '-') {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd p += 6;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (strcmp(p, "CHARSET") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_ACCEPT_CHARSET;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else if (strcmp(p, "ENCODING") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_ACCEPT_ENCODING;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else if (strcmp(p, "LANGUAGE") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_ACCEPT_LANGUAGE;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return UNKNOWN_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return UNKNOWN_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else if (strcmp(p, "UTHORIZATION") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_AUTHORIZATION;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return UNKNOWN_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd break;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd case 'C':
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if(strcmp(p, "OOKIE2") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_COOKIE2;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else if (strcmp(p, "OOKIE") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_COOKIE;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else if(strcmp(p, "ONNECTION") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_CONNECTION;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else if(strcmp(p, "ONTENT-TYPE") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_CONTENT_TYPE;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else if(strcmp(p, "ONTENT-LENGTH") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_CONTENT_LENGTH;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return UNKNOWN_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd break;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd case 'H':
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if(strcmp(p, "OST") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_HOST;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return UNKNOWN_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd break;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd case 'P':
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if(strcmp(p, "RAGMA") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_PRAGMA;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return UNKNOWN_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd break;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd case 'R':
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if(strcmp(p, "EFERER") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_REFERER;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return UNKNOWN_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd break;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd case 'U':
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if(strcmp(p, "SER-AGENT") == 0)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_USER_AGENT;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return UNKNOWN_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd break;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd default:
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return UNKNOWN_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd /* NOTREACHED */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd}
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/* Apache method number to SC methods transform table */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic const unsigned char sc_for_req_method_table[] = {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_GET,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_PUT,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_POST,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_DELETE,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd 0, /* M_DELETE */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_OPTIONS,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_TRACE,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd 0, /* M_PATCH */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_PROPFIND,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_PROPPATCH,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_MKCOL,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_COPY,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_MOVE,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_LOCK,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_UNLOCK,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_VERSION_CONTROL,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_CHECKOUT,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_UNCHECKOUT,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_CHECKIN,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_UPDATE,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_LABEL,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_REPORT,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_MKWORKSPACE,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_MKACTIVITY,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_BASELINE_CONTROL,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd SC_M_MERGE,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd 0 /* M_INVALID */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd};
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic int sc_for_req_method_by_id(request_rec *r)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{
a78048ccbdb6256da15e6b0e7e95355e480c2301nd int method_id = r->method_number;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (method_id < 0 || method_id > M_INVALID) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return UNKNOWN_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else if (r->header_only) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return SC_M_HEAD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return sc_for_req_method_table[method_id] ?
a78048ccbdb6256da15e6b0e7e95355e480c2301nd sc_for_req_method_table[method_id] : UNKNOWN_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd}
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/*
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Message structure
a78048ccbdb6256da15e6b0e7e95355e480c2301nd *
a78048ccbdb6256da15e6b0e7e95355e480c2301nd *
a78048ccbdb6256da15e6b0e7e95355e480c2301ndAJPV13_REQUEST/AJPV14_REQUEST=
a78048ccbdb6256da15e6b0e7e95355e480c2301nd request_prefix (1) (byte)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd method (byte)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd protocol (string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd req_uri (string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd remote_addr (string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd remote_host (string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd server_name (string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd server_port (short)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd is_ssl (boolean)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd num_headers (short)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd num_headers*(req_header_name header_value)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ?context (byte)(string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ?servlet_path (byte)(string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ?remote_user (byte)(string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ?auth_type (byte)(string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ?query_string (byte)(string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ?jvm_route (byte)(string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ?ssl_cert (byte)(string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ?ssl_cipher (byte)(string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ?ssl_session (byte)(string)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ?ssl_key_size (byte)(int) via JkOptions +ForwardKeySize
a78048ccbdb6256da15e6b0e7e95355e480c2301nd request_terminator (byte)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ?body content_length*(var binary)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic apr_status_t ajp_marshal_into_msgb(ajp_msg_t *msg,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd request_rec *r,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd apr_uri_t *uri)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{
a78048ccbdb6256da15e6b0e7e95355e480c2301nd int method;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd apr_uint32_t i, num_headers = 0;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd apr_byte_t is_ssl;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd char *remote_host;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const char *session_route, *envvar;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const apr_array_header_t *arr = apr_table_elts(r->subprocess_env);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const apr_table_entry_t *elts = (const apr_table_entry_t *)arr->elts;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_log_error(APLOG_MARK, APLOG_TRACE8, 0, r->server,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Into ajp_marshal_into_msgb");
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if ((method = sc_for_req_method_by_id(r)) == UNKNOWN_METHOD) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "ajp_marshal_into_msgb - No such method %s",
a78048ccbdb6256da15e6b0e7e95355e480c2301nd r->method);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return AJP_EBAD_METHOD;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd is_ssl = (apr_byte_t) ap_proxy_conn_is_https(r->connection);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (r->headers_in && apr_table_elts(r->headers_in)) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const apr_array_header_t *t = apr_table_elts(r->headers_in);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd num_headers = t->nelts;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd remote_host = (char *)ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_HOST, NULL);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_reset(msg);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (ajp_msg_append_uint8(msg, CMD_AJP13_FORWARD_REQUEST) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_uint8(msg, (apr_byte_t) method) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_string(msg, r->protocol) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_string(msg, uri->path) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_string(msg, r->connection->remote_ip) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_string(msg, remote_host) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_string(msg, ap_get_server_name(r)) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_uint16(msg, (apr_uint16_t)r->connection->local_addr->port) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_uint8(msg, is_ssl) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_uint16(msg, (apr_uint16_t) num_headers)) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "ajp_marshal_into_msgb: "
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Error appending the message begining");
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return APR_EGENERAL;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd for (i = 0 ; i < num_headers ; i++) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd int sc;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const apr_array_header_t *t = apr_table_elts(r->headers_in);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const apr_table_entry_t *elts = (apr_table_entry_t *)t->elts;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if ((sc = sc_for_req_header(elts[i].key)) != UNKNOWN_METHOD) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (ajp_msg_append_uint16(msg, (apr_uint16_t)sc)) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "ajp_marshal_into_msgb: "
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Error appending the header name");
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return AJP_EOVERFLOW;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (ajp_msg_append_string(msg, elts[i].key)) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "ajp_marshal_into_msgb: "
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Error appending the header name");
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return AJP_EOVERFLOW;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (ajp_msg_append_string(msg, elts[i].val)) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "ajp_marshal_into_msgb: "
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Error appending the header value");
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return AJP_EOVERFLOW;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_log_error(APLOG_MARK, APLOG_TRACE5, 0, r->server,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "ajp_marshal_into_msgb: Header[%d] [%s] = [%s]",
a78048ccbdb6256da15e6b0e7e95355e480c2301nd i, elts[i].key, elts[i].val);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/* XXXX need to figure out how to do this
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (s->secret) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (ajp_msg_append_uint8(msg, SC_A_SECRET) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_string(msg, s->secret)) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Error ajp_marshal_into_msgb - "
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Error appending secret");
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return APR_EGENERAL;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (r->user) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (ajp_msg_append_uint8(msg, SC_A_REMOTE_USER) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_string(msg, r->user)) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "ajp_marshal_into_msgb: "
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Error appending the remote user");
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return AJP_EOVERFLOW;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (r->ap_auth_type) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (ajp_msg_append_uint8(msg, SC_A_AUTH_TYPE) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_string(msg, r->ap_auth_type)) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "ajp_marshal_into_msgb: "
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Error appending the auth type");
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return AJP_EOVERFLOW;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd /* XXXX ebcdic (args converted?) */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (uri->query) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (ajp_msg_append_uint8(msg, SC_A_QUERY_STRING) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_string(msg, uri->query)) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "ajp_marshal_into_msgb: "
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Error appending the query string");
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return AJP_EOVERFLOW;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen if ((session_route = apr_table_get(r->notes, "session-route"))) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (ajp_msg_append_uint8(msg, SC_A_JVM_ROUTE) ||
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ajp_msg_append_string(msg, session_route)) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "ajp_marshal_into_msgb: "
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Error appending the jvm route");
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return AJP_EOVERFLOW;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
befb6758d5618c60f29b19f9a7eb75ab993511dcjim/* XXX: Is the subprocess_env a right place?
aee1f193a276866212922ae5072e3014db28582frpluem * <Location /examples>
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * ProxyPass ajp://remote:8009/servlets-examples
727872d18412fc021f03969b8641810d8896820bhumbedooh * SetEnv SSL_SESSION_ID CUSTOM_SSL_SESSION_ID
0d0ba3a410038e179b695446bb149cce6264e0abnd * </Location>
727872d18412fc021f03969b8641810d8896820bhumbedooh */
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh /*
0d0ba3a410038e179b695446bb149cce6264e0abnd * Only lookup SSL variables if we are currently running HTTPS.
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh * Furthermore ensure that only variables get set in the AJP message
727872d18412fc021f03969b8641810d8896820bhumbedooh * that are not NULL and not empty.
0d0ba3a410038e179b695446bb149cce6264e0abnd */
0d0ba3a410038e179b695446bb149cce6264e0abnd if (is_ssl) {
0d0ba3a410038e179b695446bb149cce6264e0abnd if ((envvar = ap_proxy_ssl_val(r->pool, r->server, r->connection, r,
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh AJP13_SSL_CLIENT_CERT_INDICATOR))
0d0ba3a410038e179b695446bb149cce6264e0abnd && envvar[0]) {
0d0ba3a410038e179b695446bb149cce6264e0abnd if (ajp_msg_append_uint8(msg, SC_A_SSL_CERT)
0d0ba3a410038e179b695446bb149cce6264e0abnd || ajp_msg_append_string(msg, envvar)) {
727872d18412fc021f03969b8641810d8896820bhumbedooh ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
0d0ba3a410038e179b695446bb149cce6264e0abnd "ajp_marshal_into_msgb: "
0d0ba3a410038e179b695446bb149cce6264e0abnd "Error appending the SSL certificates");
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh return AJP_EOVERFLOW;
205f749042ed530040a4f0080dbcb47ceae8a374rjung }
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen }
0d0ba3a410038e179b695446bb149cce6264e0abnd
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd if ((envvar = ap_proxy_ssl_val(r->pool, r->server, r->connection, r,
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd AJP13_SSL_CIPHER_INDICATOR))
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd && envvar[0]) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (ajp_msg_append_uint8(msg, SC_A_SSL_CIPHER)
|| ajp_msg_append_string(msg, envvar)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_marshal_into_msgb: "
"Error appending the SSL ciphers");
return AJP_EOVERFLOW;
}
}
if ((envvar = ap_proxy_ssl_val(r->pool, r->server, r->connection, r,
AJP13_SSL_SESSION_INDICATOR))
&& envvar[0]) {
if (ajp_msg_append_uint8(msg, SC_A_SSL_SESSION)
|| ajp_msg_append_string(msg, envvar)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_marshal_into_msgb: "
"Error appending the SSL session");
return AJP_EOVERFLOW;
}
}
/* ssl_key_size is required by Servlet 2.3 API */
if ((envvar = ap_proxy_ssl_val(r->pool, r->server, r->connection, r,
AJP13_SSL_KEY_SIZE_INDICATOR))
&& envvar[0]) {
if (ajp_msg_append_uint8(msg, SC_A_SSL_KEY_SIZE)
|| ajp_msg_append_uint16(msg, (unsigned short) atoi(envvar))) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"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;
char *val = apr_itoa(r->pool, r->connection->remote_addr->port);
if (ajp_msg_append_uint8(msg, SC_A_REQ_ATTRIBUTE) ||
ajp_msg_append_string(msg, key) ||
ajp_msg_append_string(msg, val)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_marshal_into_msgb: "
"Error appending attribute %s=%s",
key, val);
return AJP_EOVERFLOW;
}
}
/* Use the environment vars prefixed with AJP_
* and pass it to the header striping that prefix.
*/
for (i = 0; i < (apr_uint32_t)arr->nelts; i++) {
if (!strncmp(elts[i].key, "AJP_", 4)) {
if (ajp_msg_append_uint8(msg, SC_A_REQ_ATTRIBUTE) ||
ajp_msg_append_string(msg, elts[i].key + 4) ||
ajp_msg_append_string(msg, elts[i].val)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_marshal_into_msgb: "
"Error appending attribute %s=%s",
elts[i].key, elts[i].val);
return AJP_EOVERFLOW;
}
}
}
if (ajp_msg_append_uint8(msg, SC_A_ARE_DONE)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_marshal_into_msgb: "
"Error appending the message end");
return AJP_EOVERFLOW;
}
ap_log_error(APLOG_MARK, APLOG_TRACE8, 0, r->server,
"ajp_marshal_into_msgb: Done");
return APR_SUCCESS;
}
/*
AJPV13_RESPONSE/AJPV14_RESPONSE:=
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)
*/
static int addit_dammit(void *v, const char *key, const char *val)
{
apr_table_addn(v, key, val);
return 1;
}
static apr_status_t ajp_unmarshal_response(ajp_msg_t *msg,
request_rec *r,
proxy_dir_conf *dconf)
{
apr_uint16_t status;
apr_status_t rc;
const char *ptr;
apr_uint16_t num_headers;
int i;
rc = ajp_msg_get_uint16(msg, &status);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_unmarshal_response: Null status");
return rc;
}
r->status = status;
rc = ajp_msg_get_string(msg, &ptr);
if (rc == APR_SUCCESS) {
#if APR_CHARSET_EBCDIC /* copy only if we have to */
ptr = apr_pstrdup(r->pool, ptr);
ap_xlate_proto_from_ascii(ptr, strlen(ptr));
#endif
r->status_line = apr_psprintf(r->pool, "%d %s", status, ptr);
} else {
r->status_line = NULL;
}
ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server,
"ajp_unmarshal_response: status = %d", status);
rc = ajp_msg_get_uint16(msg, &num_headers);
if (rc == APR_SUCCESS) {
apr_table_t *save_table;
/* First, tuck away all already existing cookies */
/*
* Could optimize here, but just in case we want to
* also save other headers, keep this logic.
*/
save_table = apr_table_make(r->pool, num_headers + 2);
apr_table_do(addit_dammit, save_table, r->headers_out,
"Set-Cookie", NULL);
r->headers_out = save_table;
} else {
r->headers_out = NULL;
num_headers = 0;
}
ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server,
"ajp_unmarshal_response: Number of headers is = %d",
num_headers);
for(i = 0 ; i < (int) num_headers ; i++) {
apr_uint16_t name;
const char *stringname;
const char *value;
rc = ajp_msg_peek_uint16(msg, &name);
if (rc != APR_SUCCESS) {
return rc;
}
if ((name & 0XFF00) == 0XA000) {
ajp_msg_get_uint16(msg, &name);
stringname = long_res_header_for_sc(name);
if (stringname == NULL) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_unmarshal_response: "
"No such sc (%08x)",
name);
return AJP_EBAD_HEADER;
}
} else {
name = 0;
rc = ajp_msg_get_string(msg, &stringname);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_unmarshal_response: "
"Null header name");
return rc;
}
ap_xlate_proto_from_ascii(stringname, strlen(stringname));
}
rc = ajp_msg_get_string(msg, &value);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_unmarshal_response: "
"Null header value");
return rc;
}
/* Set-Cookie need additional processing */
if (!strcasecmp(stringname, "Set-Cookie")) {
value = ap_proxy_cookie_reverse_map(r, dconf, value);
}
/* Location, Content-Location, URI and Destination need additional
* processing */
else if (!strcasecmp(stringname, "Location")
|| !strcasecmp(stringname, "Content-Location")
|| !strcasecmp(stringname, "URI")
|| !strcasecmp(stringname, "Destination"))
{
value = ap_proxy_location_reverse_map(r, dconf, value);
}
ap_xlate_proto_from_ascii(value, strlen(value));
ap_log_error(APLOG_MARK, APLOG_TRACE5, 0, r->server,
"ajp_unmarshal_response: Header[%d] [%s] = [%s]",
i, stringname, value);
apr_table_add(r->headers_out, stringname, value);
/* Content-type needs an additional handling */
if (strcasecmp(stringname, "Content-Type") == 0) {
/* add corresponding filter */
ap_set_content_type(r, apr_pstrdup(r->pool, value));
ap_log_error(APLOG_MARK, APLOG_TRACE5, 0, r->server,
"ajp_unmarshal_response: ap_set_content_type to '%s'", value);
}
}
return APR_SUCCESS;
}
/*
* Build the ajp header message and send it
*/
apr_status_t ajp_send_header(apr_socket_t *sock,
request_rec *r,
apr_size_t buffsize,
apr_uri_t *uri)
{
ajp_msg_t *msg;
apr_status_t rc;
rc = ajp_msg_create(r->pool, buffsize, &msg);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_send_header: ajp_msg_create failed");
return rc;
}
rc = ajp_marshal_into_msgb(msg, r, uri);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_send_header: ajp_marshal_into_msgb failed");
return rc;
}
rc = ajp_ilink_send(sock, msg);
ajp_msg_log(r, msg, "ajp_send_header: ajp_ilink_send packet dump");
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_send_header: ajp_ilink_send failed");
return rc;
}
return APR_SUCCESS;
}
/*
* Read the ajp message and return the type of the message.
*/
apr_status_t ajp_read_header(apr_socket_t *sock,
request_rec *r,
apr_size_t buffsize,
ajp_msg_t **msg)
{
apr_byte_t result;
apr_status_t rc;
if (*msg) {
rc = ajp_msg_reuse(*msg);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_read_header: ajp_msg_reuse failed");
return rc;
}
}
else {
rc = ajp_msg_create(r->pool, buffsize, msg);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_read_header: ajp_msg_create failed");
return rc;
}
}
ajp_msg_reset(*msg);
rc = ajp_ilink_receive(sock, *msg);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_read_header: ajp_ilink_receive failed");
return rc;
}
ajp_msg_log(r, *msg, "ajp_read_header: ajp_ilink_receive packet dump");
rc = ajp_msg_peek_uint8(*msg, &result);
ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, r->server,
"ajp_read_header: ajp_ilink_received %s (0x%02x)",
ajp_type_str(result), result);
return APR_SUCCESS;
}
/* parse the msg to read the type */
int ajp_parse_type(request_rec *r, ajp_msg_t *msg)
{
apr_byte_t result;
ajp_msg_peek_uint8(msg, &result);
ap_log_error(APLOG_MARK, APLOG_TRACE6, 0, r->server,
"ajp_parse_type: got %s (0x%02x)",
ajp_type_str(result), result);
return (int) result;
}
/* parse the header */
apr_status_t ajp_parse_header(request_rec *r, proxy_dir_conf *conf,
ajp_msg_t *msg)
{
apr_byte_t result;
apr_status_t rc;
rc = ajp_msg_get_uint8(msg, &result);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_parse_headers: ajp_msg_get_byte failed");
return rc;
}
if (result != CMD_AJP13_SEND_HEADERS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_parse_headers: wrong type %s (0x%02x) expecting %s (0x%02x)",
ajp_type_str(result), result,
ajp_type_str(CMD_AJP13_SEND_HEADERS), CMD_AJP13_SEND_HEADERS);
return AJP_EBAD_HEADER;
}
return ajp_unmarshal_response(msg, r, conf);
}
/* parse the body and return data address and length */
apr_status_t ajp_parse_data(request_rec *r, ajp_msg_t *msg,
apr_uint16_t *len, char **ptr)
{
apr_byte_t result;
apr_status_t rc;
apr_uint16_t expected_len;
rc = ajp_msg_get_uint8(msg, &result);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_parse_data: ajp_msg_get_byte failed");
return rc;
}
if (result != CMD_AJP13_SEND_BODY_CHUNK) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_parse_data: wrong type %s (0x%02x) expecting %s (0x%02x)",
ajp_type_str(result), result,
ajp_type_str(CMD_AJP13_SEND_BODY_CHUNK), CMD_AJP13_SEND_BODY_CHUNK);
return AJP_EBAD_HEADER;
}
rc = ajp_msg_get_uint16(msg, len);
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.
*/
expected_len = msg->len - (AJP_HEADER_LEN + AJP_HEADER_SZ_LEN + 1 + 1);
if (*len != expected_len) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_parse_data: Wrong chunk length. Length of chunk is %i,"
" expected length is %i.", *len, expected_len);
return AJP_EBAD_HEADER;
}
*ptr = (char *)&(msg->buf[msg->pos]);
return APR_SUCCESS;
}
/* Check the reuse flag in CMD_AJP13_END_RESPONSE */
apr_status_t ajp_parse_reuse(request_rec *r, ajp_msg_t *msg,
apr_byte_t *reuse)
{
apr_byte_t result;
apr_status_t rc;
rc = ajp_msg_get_uint8(msg, &result);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_parse_reuse: ajp_msg_get_byte failed");
return rc;
}
if (result != CMD_AJP13_END_RESPONSE) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"ajp_parse_reuse: wrong type %s (0x%02x) expecting %s (0x%02x)",
ajp_type_str(result), result,
ajp_type_str(CMD_AJP13_END_RESPONSE), CMD_AJP13_END_RESPONSE);
return AJP_EBAD_HEADER;
}
return ajp_msg_get_uint8(msg, reuse);
}
/*
* Allocate a msg to send data
*/
apr_status_t ajp_alloc_data_msg(apr_pool_t *pool, char **ptr, apr_size_t *len,
ajp_msg_t **msg)
{
apr_status_t rc;
if ((rc = ajp_msg_create(pool, *len, msg)) != APR_SUCCESS)
return rc;
ajp_msg_reset(*msg);
*ptr = (char *)&((*msg)->buf[6]);
*len = *len - 6;
return APR_SUCCESS;
}
/*
* Send the data message
*/
apr_status_t ajp_send_data_msg(apr_socket_t *sock,
ajp_msg_t *msg, apr_size_t len)
{
msg->buf[4] = (apr_byte_t)((len >> 8) & 0xFF);
msg->buf[5] = (apr_byte_t)(len & 0xFF);
msg->len += len + 2; /* + 1 XXXX where is '\0' */
return ajp_ilink_send(sock, msg);
}