proxy_ajp.c revision 13852d30fd6e3ffee07702f9222a0dd5aeec75eb
/* 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.
*/
/* AJP routines for Apache proxy */
#include "mod_proxy.h"
#include "ajp.h"
/*
* Canonicalise http-like URLs.
* scheme is the scheme for the URL
* url is the URL starting with the first '/'
* def_port is the default port for this scheme.
*/
{
const char *err;
const char *scheme;
"proxy: AJP: canonicalising URL %s", url);
/* ap_port_of_scheme() */
url += 4;
scheme = "ajp";
}
/* XXX This is probably faulty */
url += 5;
scheme = "ajps";
}
else {
return DECLINED;
}
"proxy: AJP: canonicalising URL %s", url);
/* do syntatic check.
* We break the URL into host, port, path, search
*/
if (err) {
"error parsing URL %s: %s",
return HTTP_BAD_REQUEST;
}
/* N.B. if this isn't a true proxy request, then the URL _path_
* has already been decoded. True proxy requests have r->uri
* == r->unparsed_uri, and no others have that property.
*/
if (r->uri == r->unparsed_uri) {
*(search++) = '\0';
}
else
/* process path */
return HTTP_BAD_REQUEST;
else
sport[0] = '\0';
}
return OK;
}
/*
* process the request and write the respnse.
*/
char *url, char *server_portstr)
{
int result;
apr_bucket *e;
char *buff;
const char *tenc;
int havebody=1;
int isok=1;
/*
* Send the AJP request to the remote server
*/
/* send request headers */
if (status != APR_SUCCESS) {
"proxy: AJP: request failed to %pI (%s)",
return HTTP_SERVICE_UNAVAILABLE;
}
/* allocate an AJP message to store the data of the buckets */
if (status != APR_SUCCESS) {
"proxy: ajp_alloc_data_msg failed");
return status;
}
/* read the first bloc of data */
/* The AJP protocol does not want body data yet */
"proxy: request is chunked");
} else {
if (status != APR_SUCCESS) {
"proxy: ap_get_brigade failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
/* have something */
"proxy: APR_BUCKET_IS_EOS");
}
/* Try to send something */
"proxy: data to read (max %" APR_SIZE_T_FMT
if (status != APR_SUCCESS) {
"proxy: apr_brigade_flatten");
return HTTP_INTERNAL_SERVER_ERROR;
}
if (bufsiz > 0) {
if (status != APR_SUCCESS) {
"proxy: send failed to %pI (%s)",
return HTTP_SERVICE_UNAVAILABLE;
}
}
}
/* read the response */
if (status != APR_SUCCESS) {
"proxy: read response failed from %pI (%s)",
return HTTP_SERVICE_UNAVAILABLE;
}
/* parse the reponse */
while (isok) {
switch (result) {
case CMD_AJP13_GET_BODY_CHUNK:
if (havebody) {
/* That is the end */
bufsiz = 0;
havebody = 0;
"proxy: APR_BUCKET_IS_EOS");
} else {
if (status != APR_SUCCESS) {
"ap_get_brigade failed");
break;
}
if (status != APR_SUCCESS) {
"apr_brigade_flatten failed");
break;
}
}
if (status != APR_SUCCESS) {
"ajp_send_data_msg failed");
break;
}
} else {
/* something is wrong TC asks for more body but we are
* already at the end of the body data
*/
"ap_proxy_ajp_request error read after end");
isok = 0;
}
break;
case CMD_AJP13_SEND_HEADERS:
/* AJP13_SEND_HEADERS: process them */
if (status != APR_SUCCESS) {
isok=0;
}
break;
/* AJP13_SEND_BODY_CHUNK: piece of data */
r->connection->bucket_alloc);
if (status != APR_SUCCESS)
isok = 0;
break;
case CMD_AJP13_END_RESPONSE:
"proxy: error processing body");
isok=0;
}
break;
default:
isok=0;
break;
}
if (!isok)
break;
if (result == CMD_AJP13_END_RESPONSE)
break;
/* read the response */
if (status != APR_SUCCESS) {
isok=0;
"ajp_read_header failed");
break;
}
}
if (bb_len != -1)
if (!isok)
if (status != APR_SUCCESS) {
"proxy: send body failed to %pI (%s)",
return HTTP_SERVICE_UNAVAILABLE;
}
/* Nice we have answer to send to the client */
"proxy: got response from %pI (%s)",
return OK;
}
"proxy: got bad response (%d) from %pI (%s)",
return HTTP_SERVICE_UNAVAILABLE;
}
/*
* This handles http:// URLs, and other URLs using a remote proxy over http
* If proxyhost is NULL, then contact the server directly, otherwise
* go via the proxy.
* Note that if a proxy is used, then URLs other than http: can be accessed,
* also, if we have trouble which is clearly specific to the proxy, then
* we return DECLINED so that we can try another proxy. (Or the direct
* route.)
*/
{
int status;
char server_portstr[32];
const char *scheme = "AJP";
/* Note: Memory pool allocation.
* A downstream keepalive connection is always connected to the existence
* (or not) of an upstream keepalive connection. If this is not done then
* load balancing against multiple backend servers breaks (one backend
* server ends up taking 100% of the load), and the risk is run of
* downstream keepalive connections being kept open unnecessarily. This
* keeps webservers busy and ties up resources.
*
* As a result, we allocate all sockets out of the upstream connection
* pool, and when we want to reuse a socket, we check first whether the
* connection ID of the current upstream connection is the same as that
* of the connection when the socket was opened.
*/
#if 0
conn_rec *c = r->connection;
#endif
"proxy: AJP: declining URL %s", url);
return DECLINED;
}
"proxy: AJP: serving URL %s", url);
/* only use stored info for top-level pages. Sub requests don't share
* in keepalives
*/
#if 0
if (!r->main) {
}
#endif
/* create space for state information */
if (!backend) {
if (backend) {
}
return status;
}
#if 0
if (!r->main) {
}
#endif
}
backend->close_on_recycle = 0;
/* Step One: Determine Who To Connect To */
sizeof(server_portstr));
goto cleanup;
/* Step Two: Make the Connection */
goto cleanup;
}
#if 0
/* XXX: we don't need to create the bound client connection */
/* Step Three: Create conn_rec */
if (!backend->connection) {
goto cleanup;
}
#endif
/* Step Four: Process the Request */
goto cleanup;
#if 0
/* Clear the module config */
#endif
/* Do not close the socket */
return status;
}
static void ap_proxy_http_register_hook(apr_pool_t *p)
{
}
NULL, /* create per-directory config structure */
NULL, /* merge per-directory config structures */
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
NULL, /* command apr_table_t */
ap_proxy_http_register_hook/* register hooks */
};