#include "http_vhost.h"
#include "http_request.h"
#include "util_date.h"
+#include "apr_strings.h"
/* Some WWW schemes and their default ports; this is basically /etc/services */
/* This will become global when the protocol abstraction comes */
static int proxy_handler(request_rec *r)
{
char *url, *scheme, *p;
+ const char *p2;
void *sconf = r->server->module_config;
proxy_server_conf *conf = (proxy_server_conf *)
ap_get_module_config(sconf, &proxy_module);
if (!direct_connect)
for (i = 0; i < proxies->nelts; i++) {
- p = strchr(ents[i].scheme, ':'); /* is it a partial URL? */
+ p2 = ap_strchr_c(ents[i].scheme, ':'); /* is it a partial URL? */
if (strcmp(ents[i].scheme, "*") == 0 ||
- (p == NULL && strcasecmp(scheme, ents[i].scheme) == 0) ||
- (p != NULL &&
+ (p2 == NULL && strcasecmp(scheme, ents[i].scheme) == 0) ||
+ (p2 != NULL &&
strncasecmp(url, ents[i].scheme, strlen(ents[i].scheme)) == 0)) {
/* CONNECT is a special method that bypasses the normal
* proxy code.
}
static const char *
- add_proxy(cmd_parms *cmd, void *dummy, char *f, char *r)
+ add_proxy(cmd_parms *cmd, void *dummy, const char *f1, const char *r1)
{
server_rec *s = cmd->server;
proxy_server_conf *conf =
(proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
struct proxy_remote *new;
char *p, *q;
+ char *r, *f;
int port;
+ r = apr_pstrdup(cmd->pool, r1);
+ f = apr_pstrdup(cmd->pool, f1);
p = strchr(r, ':');
if (p == NULL || p[1] != '/' || p[2] != '/' || p[3] == '\0')
return "ProxyRemote: Bad syntax for a remote proxy server";
}
static const char *
- set_cache_exclude(cmd_parms *cmd, void *dummy, char *arg)
+ set_cache_exclude(cmd_parms *cmd, void *dummy, const char *arg)
{
server_rec *s = cmd->server;
proxy_server_conf *psf = (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
new = apr_push_array(psf->nocaches);
new->name = arg;
/* Don't do name lookups on things that aren't dotted */
- if (strchr(arg, '.') != NULL && ap_proxy_host2addr(new->name, &hp) == NULL)
- /*@@@FIXME: This copies only the first of (possibly many) IP addrs */
+ if (ap_strchr_c(arg, '.') != NULL &&
+ ap_proxy_host2addr(new->name, &hp) == NULL)
+ /*@@@FIXME: This copies only the first of (possibly many) IP addrs */
memcpy(&new->addr, hp.h_addr, sizeof(struct in_addr));
else
new->addr.s_addr = 0;
}
static const char *
- add_pass(cmd_parms *cmd, void *dummy, char *f, char *r)
+ add_pass(cmd_parms *cmd, void *dummy, const char *f, const char *r)
{
server_rec *s = cmd->server;
proxy_server_conf *conf =
}
static const char *
- add_pass_reverse(cmd_parms *cmd, void *dummy, char *f, char *r)
+ add_pass_reverse(cmd_parms *cmd, void *dummy, const char *f, const char *r)
{
server_rec *s = cmd->server;
proxy_server_conf *conf;
return NULL;
}
-static const char *set_proxy_exclude(cmd_parms *parms, void *dummy, char *arg)
+static const char *set_proxy_exclude(cmd_parms *parms, void *dummy, const char *arg)
{
server_rec *s = parms->server;
proxy_server_conf *conf =
new = apr_push_array(conf->noproxies);
new->name = arg;
/* Don't do name lookups on things that aren't dotted */
- if (strchr(arg, '.') != NULL && ap_proxy_host2addr(new->name, &hp) == NULL)
+ if (ap_strchr_c(arg, '.') != NULL && ap_proxy_host2addr(new->name, &hp) == NULL)
/*@@@FIXME: This copies only the first of (possibly many) IP addrs */
memcpy(&new->addr, hp.h_addr, sizeof(struct in_addr));
else
* Set the ports CONNECT can use
*/
static const char *
- set_allowed_ports(cmd_parms *parms, void *dummy, char *arg)
+ set_allowed_ports(cmd_parms *parms, void *dummy, const char *arg)
{
server_rec *s = parms->server;
proxy_server_conf *conf =
* which should never be accessed via the configured ProxyRemote servers
*/
static const char *
- set_proxy_dirconn(cmd_parms *parms, void *dummy, char *arg)
+ set_proxy_dirconn(cmd_parms *parms, void *dummy, const char *arg)
{
server_rec *s = parms->server;
proxy_server_conf *conf =
if (!found) {
New = apr_push_array(conf->dirconn);
- New->name = arg;
+ New->name = apr_pstrdup(parms->pool, arg);
New->hostentry = NULL;
if (ap_proxy_is_ipaddr(New, parms->pool)) {
}
static const char *
- set_proxy_domain(cmd_parms *parms, void *dummy, char *arg)
+ set_proxy_domain(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
static const char *
- set_recv_buffer_size(cmd_parms *parms, void *dummy, char *arg)
+ set_recv_buffer_size(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
}
static const char*
- set_via_opt(cmd_parms *parms, void *dummy, char *arg)
+ set_via_opt(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf = ap_get_module_config(parms->server->module_config, &proxy_module);
}
static const char*
- set_cache_completion(cmd_parms *parms, void *dummy, char *arg)
+ set_cache_completion(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf = ap_get_module_config(parms->server->module_config, &proxy_module);
int s = atoi(arg);
static const command_rec proxy_cmds[] =
{
- {"ProxyRequests", set_proxy_req, NULL, RSRC_CONF, FLAG,
- "on if the true proxy requests should be accepted"},
- {"ProxyRemote", add_proxy, NULL, RSRC_CONF, TAKE2,
- "a scheme, partial URL or '*' and a proxy server"},
- {"ProxyPass", add_pass, NULL, RSRC_CONF, TAKE2,
- "a virtual path and a URL"},
- {"ProxyPassReverse", add_pass_reverse, NULL, RSRC_CONF, TAKE2,
- "a virtual path and a URL for reverse proxy behaviour"},
- {"ProxyBlock", set_proxy_exclude, NULL, RSRC_CONF, ITERATE,
- "A list of names, hosts or domains to which the proxy will not connect"},
- {"ProxyReceiveBufferSize", set_recv_buffer_size, NULL, RSRC_CONF, TAKE1,
- "Receive buffer size for outgoing HTTP and FTP connections in bytes"},
- {"NoProxy", set_proxy_dirconn, NULL, RSRC_CONF, ITERATE,
- "A list of domains, hosts, or subnets to which the proxy will connect directly"},
- {"ProxyDomain", set_proxy_domain, NULL, RSRC_CONF, TAKE1,
- "The default intranet domain name (in absence of a domain in the URL)"},
- {"AllowCONNECT", set_allowed_ports, NULL, RSRC_CONF, ITERATE,
- "A list of ports which CONNECT may connect to"},
- {"ProxyVia", set_via_opt, NULL, RSRC_CONF, TAKE1,
- "Configure Via: proxy header header to one of: on | off | block | full"},
- {"ProxyNoCache", set_cache_exclude, NULL, RSRC_CONF, ITERATE,
- "A list of names, hosts or domains for which caching is *not* provided"},
- {"ProxyForceCacheCompletion", set_cache_completion, NULL, RSRC_CONF, TAKE1,
- "Force a http cache completion after this percentage is loaded"},
+ AP_INIT_FLAG("ProxyRequests", set_proxy_req, NULL, RSRC_CONF,
+ "on if the true proxy requests should be accepted"),
+ AP_INIT_TAKE2("ProxyRemote", add_proxy, NULL, RSRC_CONF,
+ "a scheme, partial URL or '*' and a proxy server"),
+ AP_INIT_TAKE2("ProxyPass", add_pass, NULL, RSRC_CONF,
+ "a virtual path and a URL"),
+ AP_INIT_TAKE2("ProxyPassReverse", add_pass_reverse, NULL, RSRC_CONF,
+ "a virtual path and a URL for reverse proxy behaviour"),
+ AP_INIT_ITERATE("ProxyBlock", set_proxy_exclude, NULL, RSRC_CONF,
+ "A list of names, hosts or domains to which the proxy will not connect"),
+ AP_INIT_TAKE1("ProxyReceiveBufferSize", set_recv_buffer_size, NULL, RSRC_CONF,
+ "Receive buffer size for outgoing HTTP and FTP connections in bytes"),
+ AP_INIT_ITERATE("NoProxy", set_proxy_dirconn, NULL, RSRC_CONF,
+ "A list of domains, hosts, or subnets to which the proxy will connect directly"),
+ AP_INIT_TAKE1("ProxyDomain", set_proxy_domain, NULL, RSRC_CONF,
+ "The default intranet domain name (in absence of a domain in the URL)"),
+ AP_INIT_ITERATE("AllowCONNECT", set_allowed_ports, NULL, RSRC_CONF,
+ "A list of ports which CONNECT may connect to"),
+ AP_INIT_TAKE1("ProxyVia", set_via_opt, NULL, RSRC_CONF,
+ "Configure Via: proxy header header to one of: on | off | block | full"),
+ AP_INIT_ITERATE("ProxyNoCache", set_cache_exclude, NULL, RSRC_CONF,
+ "A list of names, hosts or domains for which caching is *not* provided"),
+ AP_INIT_TAKE1("ProxyForceCacheCompletion", set_cache_completion, NULL, RSRC_CONF,
+ "Force a http cache completion after this percentage is loaded"),
{NULL}
};
/* FTP routines for Apache proxy */
+#include "apr_strings.h"
#include "mod_proxy.h"
#include "http_main.h"
#include "http_log.h"
register int n, o, w;
conn_rec *con = r->connection;
char *dir, *path, *reldir, *site;
- BUFF *cachefp = NULL;
+ apr_file_t *cachefp = NULL;
if(c) ap_cache_el_data(c, &cachefp);
o = 0;
total_bytes_sent += n;
- if (cachefp && ap_bwrite(cachefp, buf, n, &cntr) != n) {
+ cntr = n;
+ if (cachefp && apr_write(cachefp, buf, &cntr) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"proxy: error writing to cache");
ap_proxy_cache_error(&c);
int port, i, j, len, rc, nocache = 0;
apr_socket_t *csd;
struct in_addr destaddr;
- BUFF *f, *cachefp = NULL;
+ BUFF *f;
+ apr_file_t *cachefp = NULL;
BUFF *data = NULL;
apr_pool_t *p = r->pool;
int one = 1;
/* check if ProxyBlock directive on this host */
destaddr.s_addr = apr_inet_addr(host);
for (i = 0; i < conf->noproxies->nelts; i++) {
- if ((npent[i].name != NULL && strstr(host, npent[i].name) != NULL)
+ if ((npent[i].name != NULL && ap_strstr_c(host, npent[i].name) != NULL)
|| destaddr.s_addr == npent[i].addr.s_addr || npent[i].name[0] == '*')
return ap_proxyerror(r, HTTP_FORBIDDEN,
"Connect to remote machine blocked");
/* check if NoCache directive on this host */
for (i = 0; i < conf->nocaches->nelts; i++) {
- if ((ncent[i].name != NULL && strstr(host, ncent[i].name) != NULL)
+ if ((ncent[i].name != NULL && ap_strstr_c(host, ncent[i].name) != NULL)
|| destaddr.s_addr == ncent[i].addr.s_addr || ncent[i].name[0] == '*')
nocache = 1;
}
/* write status line */
if (!r->assbackwards)
ap_rvputs(r, "HTTP/1.0 ", r->status_line, CRLF, NULL);
- if (cachefp && ap_bvputs(cachefp, "HTTP/1.0 ", r->status_line, CRLF, NULL) == -1) {
+ if (cachefp && apr_puts(apr_pstrcat(r->pool, "HTTP/1.0 ", r->status_line, CRLF, NULL), cachefp) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"proxy: error writing CRLF to cache");
ap_proxy_cache_error(&c);
ap_cache_el_header_walk(c, ap_proxy_send_hdr_line, r, NULL);
if (!r->assbackwards)
ap_rputs(CRLF, r);
- if (cachefp && ap_bputs(CRLF, cachefp) == -1) {
+ if (cachefp && apr_puts(CRLF, cachefp) == -1) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"proxy: error writing CRLF to cache");
ap_proxy_cache_error(&c);
/* HTTP routines for Apache proxy */
+#include "apr_strings.h"
#include "mod_proxy.h"
#include "http_log.h"
#include "http_main.h"
{
const char *strp;
char *strp2;
- const char *desthost;
+ char *desthost;
apr_socket_t *sock;
int i, len, backasswards, content_length=-1;
apr_array_header_t *reqhdrs_arr;
apr_table_entry_t *reqhdrs;
struct sockaddr_in server;
struct in_addr destaddr;
- BUFF *f, *cachefp=NULL;
+ BUFF *f;
+ apr_file_t *cachefp=NULL;
char buffer[HUGE_STRING_LEN];
char portstr[32];
apr_pool_t *p = r->pool;
return HTTP_BAD_REQUEST;
urlptr += 3;
destport = DEFAULT_HTTP_PORT;
- strp = strchr(urlptr, '/');
+ strp = ap_strchr_c(urlptr, '/');
if (strp == NULL) {
desthost = apr_pstrdup(p, urlptr);
urlptr = "/";
desthost = q;
}
- strp2 = strchr(desthost, ':');
+ strp2 = ap_strchr(desthost, ':');
if (strp2 != NULL) {
*(strp2++) = '\0';
if (apr_isdigit(*strp2)) {
/* check if ProxyBlock directive on this host */
destaddr.s_addr = apr_inet_addr(desthost);
for (i = 0; i < conf->noproxies->nelts; i++) {
- if ((npent[i].name != NULL && strstr(desthost, npent[i].name) != NULL)
+ if ((npent[i].name != NULL && ap_strstr_c(desthost, npent[i].name) != NULL)
|| destaddr.s_addr == npent[i].addr.s_addr || npent[i].name[0] == '*')
return ap_proxyerror(r, HTTP_FORBIDDEN,
"Connect to remote machine blocked");
content_length = atoi(clen ? clen : "-1");
for (i = 0; i < conf->nocaches->nelts; i++) {
- if ((ncent[i].name != NULL && strstr(desthost, ncent[i].name) != NULL)
+ if ((ncent[i].name != NULL && ap_strstr_c(desthost, ncent[i].name) != NULL)
|| destaddr.s_addr == ncent[i].addr.s_addr || ncent[i].name[0] == '*')
nocache = 1;
}
/* write status line */
if (!r->assbackwards)
ap_rvputs(r, "HTTP/1.0 ", r->status_line, CRLF, NULL);
- if (cachefp && ap_bvputs(cachefp, "HTTP/1.0 ", r->status_line, CRLF, NULL) == -1) {
+ if (cachefp && apr_puts(apr_pstrcat(r->pool, "HTTP/1.0 ", r->status_line, CRLF, NULL), cachefp) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"proxy: error writing status line to cache");
ap_proxy_cache_error(&c);
/* Is it an HTTP/0.9 respose? If so, send the extra data */
if (backasswards) {
ap_bwrite(r->connection->client, buffer, len, &cntr);
- if (cachefp && ap_bwrite(cachefp, buffer, len, &cntr) != len) {
+ cntr = len;
+ if (cachefp && apr_write(cachefp, buffer, &cntr) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"proxy: error writing extra data to cache %ld",
(long)cachefp);
*/
/* Utility routines for Apache proxy */
+#include "apr_strings.h"
#include "mod_proxy.h"
#include "http_main.h"
#include "apr_md5.h"
{
int i, j, ch;
char *y;
- const char *allowed; /* characters which should not be encoded */
- const char *reserved; /* characters which much not be en/de-coded */
+ char *allowed; /* characters which should not be encoded */
+ char *reserved; /* characters which much not be en/de-coded */
/* N.B. in addition to :@&=, this allows ';' in an http path
* and '?' in an ftp path -- this may be revised
* formatted, then it exits very quickly.
*/
const char *
- ap_proxy_date_canon(apr_pool_t *p, const char *x)
+ ap_proxy_date_canon(apr_pool_t *p, const char *x1)
{
+ char *x = apr_pstrdup(p, x1);
int wk, mday, year, hour, min, sec, mon;
char *q, month[4], zone[4], week[4];
register int n, o;
conn_rec *con = r->connection;
int alternate_timeouts = 1; /* 1 if we alternate between soft & hard timeouts */
- BUFF *cachefp = NULL;
+ apr_file_t *cachefp = NULL;
int written = 0, wrote_to_cache;
total_bytes_rcvd = 0;
/* Write to cache first. */
/*@@@ XXX FIXME: Assuming that writing the cache file won't time out?!!? */
- if (cachefp && ap_bwrite(cachefp, &buf[0], cntr, &wrote_to_cache) != APR_SUCCESS) {
+ wrote_to_cache = cntr;
+ if (cachefp && apr_write(cachefp, &buf[0], &wrote_to_cache) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"proxy: error writing to cache");
ap_proxy_cache_error(&c);
len = strlen(val);
while (list != NULL) {
- p = strchr(list, ',');
+ p = ap_strchr_c(list, ',');
if (p != NULL) {
i = p - list;
do
static int proxy_match_word(struct dirconn_entry *This, request_rec *r)
{
const char *host = proxy_get_host_of_request(r);
- return host != NULL && strstr(host, This->name) != NULL;
+ return host != NULL && ap_strstr_c(host, This->name) != NULL;
}
int ap_proxy_doconnect(apr_socket_t *sock, char *host, apr_uint32_t port, request_rec *r)
unsigned ap_proxy_bputs2(const char *data, BUFF *client, ap_cache_el *cache)
{
unsigned len = ap_bputs(data, client);
- BUFF *cachefp = NULL;
+ apr_file_t *cachefp = NULL;
if (ap_cache_el_data(cache, &cachefp) == APR_SUCCESS)
- ap_bputs(data, cachefp);
+ apr_puts(data, cachefp);
return len;
}
int ap_proxy_cache_send(request_rec *r, ap_cache_el *c)
{
- BUFF *cachefp = NULL, *fp = r->connection->client;
+ apr_file_t *cachefp = NULL;
+ BUFF *fp = r->connection->client;
char buffer[500];
ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, NULL,
if(ap_cache_el_data(c, &cachefp) != APR_SUCCESS)
return HTTP_INTERNAL_SERVER_ERROR;
/* send the response */
- if(ap_bgets(buffer, sizeof(buffer), cachefp))
+ if(apr_fgets(buffer, sizeof(buffer), cachefp))
ap_bvputs(fp, buffer, NULL);
/* send headers */
ap_cache_el_header_walk(c, ap_proxy_send_hdr_line, r, NULL);
ap_bputs(CRLF, fp);
/* send data */
- if(!r->header_only && !ap_proxy_send_fb(0, cachefp, r, NULL))
+ /* XXX I changed the ap_proxy_send_fb call to use fp instead of cachefp.
+ * this compiles cleanly, but it is probably the completely wrong
+ * solution. We need to go through the proxy code, and remove all
+ * of the BUFF's. rbb
+ */
+ if(!r->header_only && !ap_proxy_send_fb(0, fp, r, NULL))
return HTTP_INTERNAL_SERVER_ERROR;
return OK;
}