diff -u ffproxy-1.4.1/cache.c ffproxy-1.4.1+accel/cache.c --- ffproxy-1.4.1/cache.c 2003-07-20 13:25:05.000000000 +0200 +++ ffproxy-1.4.1+accel/cache.c 2003-08-02 10:09:36.000000000 +0200 @@ -28,8 +28,10 @@ #include #ifdef LINUX #define __USE_GNU 1 -#endif +#include +#else #include +#endif #include #include diff -u ffproxy-1.4.1/cfg.h ffproxy-1.4.1+accel/cfg.h --- ffproxy-1.4.1/cfg.h 2003-07-20 11:51:54.000000000 +0200 +++ ffproxy-1.4.1+accel/cfg.h 2003-08-02 10:09:36.000000000 +0200 @@ -24,4 +24,8 @@ unsigned long cache_max_file_size; int use_ipv6; int aux_proxy_ipv6; + + int use_accel; + char accelhost[256]; + unsigned int accelport; }; Common subdirectories: ffproxy-1.4.1/db and ffproxy-1.4.1+accel/db diff -u ffproxy-1.4.1/db.c ffproxy-1.4.1+accel/db.c --- ffproxy-1.4.1/db.c 2003-08-01 22:41:50.000000000 +0200 +++ ffproxy-1.4.1+accel/db.c 2003-08-02 10:09:36.000000000 +0200 @@ -319,6 +319,13 @@ else config.use_ipv6 = 0; continue; + } else if (strcmp("accel_host", obuf) == 0) { + (void) strncpy(config.accelhost, abuf, sizeof(config.accelhost) - 1); + config.use_accel = 1; + continue; + } else if (strcmp("accel_port", obuf) == 0) { + config.accelport = atoi(abuf); + continue; } else if (*obuf != '#') { warn("unknown option in config file %s: %s", config.file, obuf); continue; diff -u ffproxy-1.4.1/filter.c ffproxy-1.4.1+accel/filter.c --- ffproxy-1.4.1/filter.c 2003-07-20 13:25:05.000000000 +0200 +++ ffproxy-1.4.1+accel/filter.c 2003-08-02 10:09:36.000000000 +0200 @@ -41,6 +41,9 @@ { size_t i; int j; + char buf[4096]; + int have_host_header = 0; + static const char host_header[] = "Host: "; i = 0; while (f_host[i] != NULL) @@ -100,6 +103,18 @@ debug("filter_request() => added loop header[%d] (%s)", i, r->header[i]); + // is there Host: header left? + j = 0; + while (r->header[j] != NULL && j < sizeof(r->header) - 2 && !have_host_header) { + if (strncasecmp(r->header[j], host_header, strlen(host_header)) == 0) { + have_host_header++; + debug("filter_request() => found host header (%d)", have_host_header); + } + +// len = snprintf(buf, sizeof(buf), "Host: %s:%d\r\n", r->host, r->port); + j++; + } + i++; j = 0; while (f_hdr_add[j] != NULL && i < sizeof(r->header) - 1) { Common subdirectories: ffproxy-1.4.1/html and ffproxy-1.4.1+accel/html diff -u ffproxy-1.4.1/http.c ffproxy-1.4.1+accel/http.c --- ffproxy-1.4.1/http.c 2003-07-20 13:25:05.000000000 +0200 +++ ffproxy-1.4.1+accel/http.c 2003-08-02 10:09:36.000000000 +0200 @@ -26,6 +26,7 @@ #include "req.h" #include "print.h" #include "http.h" +#include "cfg.h" static const char http_get[] = "GET "; static const char http_post[] = "POST "; @@ -38,6 +39,8 @@ { size_t i, k; char *p; + extern struct cfg config; + char accelport[10]; if (strncmp(http_get, s, strlen(http_get)) == 0) { r->type = GET; @@ -58,26 +61,49 @@ debug("http_url() => got url part (%s)", s); - if (strncmp(s, http, strlen(http)) != 0) { - r->type = UNKNOWN; - return -1; - } + if (config.use_accel) { + debug("http_url() => using as accelerator proxy"); + i = 0; +debug("http: %s (%d)", http, strlen(http)); +debug("config.accelhost: %s (%d)", config.accelhost, strlen(config.accelhost)); + // add http:// + for (k=0; k<=strlen(http)-1; k++) { + r->url[i++] = http[k]; + } + // add hostname (or IP) + for (k=0; k<=strlen(config.accelhost)-1; k++) { + r->url[i++] = config.accelhost[k]; + } + // add port number + r->url[i++] = ':'; + snprintf(accelport, sizeof(accelport), "%d", config.accelport); + for (k=0; k<=strlen(accelport)-1; k++) { + r->url[i++] = accelport[k]; + } + r->url[i] = '\0'; + debug("http_url() => accelerator mode created url (%s)", r->url); + } else { + if (strncmp(s, http, strlen(http)) != 0) { + r->type = UNKNOWN; + return -1; + } - i = 0; - while (i < strlen(http)) { - r->url[i] = http[i]; - i++, s++; - } + i = 0; + while (i < strlen(http)) { + r->url[i] = http[i]; + i++, s++; + } - while (i < sizeof(r->url) - 1 && *s != '_' - && (isalnum(*s) || *s == '-' || *s == '.' || *s == ':')) - r->url[i++] = tolower(*(s++)); - r->url[i] = '\0'; - if (*s != '/' && *s != ' ') { - r->type = UNKNOWN; - return -1; + while (i < sizeof(r->url) - 1 && *s != '_' + && (isalnum(*s) || *s == '-' || *s == '.' || *s == ':')) + r->url[i++] = tolower(*(s++)); + r->url[i] = '\0'; + if (*s != '/' && *s != ' ') { + r->type = UNKNOWN; + return -1; + } } - + k = 0; while (i < sizeof(r->url) - 1 && k < sizeof(r->urlpath) - 1 && *s != ' ' && *s != '\0' && isprint(*s)) { r->urlpath[k++] = *s; diff -u ffproxy-1.4.1/main.c ffproxy-1.4.1+accel/main.c --- ffproxy-1.4.1/main.c 2003-08-01 22:22:01.000000000 +0200 +++ ffproxy-1.4.1+accel/main.c 2003-08-02 10:10:37.000000000 +0200 @@ -39,7 +39,7 @@ static void usage(void); static void drop_privileges(void); -static const char version[] = "1.4.1"; +static const char version[] = "1.4.1+accel"; static const char rcsid[] = "$Id: main.c,v 1.41 2003/08/01 20:11:05 niklas Exp niklas $"; char loop_header[100]; @@ -73,8 +73,10 @@ config.cache_max_file_size = 1024 * 2; config.use_ipv6 = 1; config.aux_proxy_ipv6 = 1; + config.use_accel = 0; + config.accelport = 80; - while ((c = getopt(argc, argv, "vdc:p:x:X:l:u:g:r:D:f:s4h")) != -1) { + while ((c = getopt(argc, argv, "vdc:p:x:X:l:u:g:r:D:f:s4ha:A:")) != -1) { switch (c) { case 'v': (void) printf("ffproxy version %s, %s\n", @@ -124,6 +126,14 @@ case '4': config.use_ipv6 = 0; break; + case 'a': + (void) strncpy(config.accelhost, optarg, sizeof(config.accelhost) - 1); + config.accelhost[sizeof(config.accelhost) - 1] = '\0'; + config.use_accel = 1; + break; + case 'A': + config.accelport = atoi(optarg); + break; case 'h': default: usage(); @@ -173,6 +183,7 @@ (void) fprintf(stderr, "usage: ffproxy [-vds4h] [-c host|ip] [-p port] [-x host|ip] [-X port] [-l max]\n" " [-u uid -g gid] [-r dir] [-D dir] [-f file]\n" + " [-a host|ip] [-A port]\n" "\n" " -v print version number\n" " -d become daemon\n" @@ -189,7 +200,9 @@ " -g gid change gid\n" " -r dir chroot to dir\n" " -D dir databases are in dir (default is %s)\n" - " -f file use config file (default is %s)\n", + " -f file use config file (default is %s)\n" + " -a host|ip auxiliary forward server to use\n" + " -A port auxiliary forward server port\n" DATADIR, CFGFILE); exit(1); } diff -u ffproxy-1.4.1/request.c ffproxy-1.4.1+accel/request.c --- ffproxy-1.4.1/request.c 2003-08-01 22:11:13.000000000 +0200 +++ ffproxy-1.4.1+accel/request.c 2003-08-02 10:11:44.000000000 +0200 @@ -308,8 +308,7 @@ if (r->port == 80) len = snprintf(buf, sizeof(buf), - "%s %s HTTP/%d.%d\r\n" - "Host: %s\r\n", + "%s %s HTTP/%d.%d\r\n", ((r->type == GET) ? "GET" : ((r->type) == HEAD) ? "HEAD" : "POST"), (*config.proxyhost && config.proxyport) != '\0' ? r->url : r->urlpath, diff -u ffproxy-1.4.1/sample.config ffproxy-1.4.1+accel/sample.config --- ffproxy-1.4.1/sample.config 2003-08-01 22:40:50.000000000 +0200 +++ ffproxy-1.4.1+accel/sample.config 2003-08-02 10:09:36.000000000 +0200 @@ -66,4 +66,10 @@ #db_files_path ./ db_files_path /var/ffproxy +# if you want to use ffproxy as http accelerator (that is, connecting +# to just one http server and beeing used as front-end to that, e.g. +# in DMZ) uncomments options below (port is optional) +#accel_host 10.254.1.2 +#accel_port 80 + # end of file