From d5472ec0bd8a9bb18b15a2398f429fe191070b3f Mon Sep 17 00:00:00 2001 From: Mukund Sivaraman Date: Sat, 8 Mar 2008 17:33:54 -0800 Subject: Renamed file to replace underscores in it with dashes --- src/Makefile.am | 2 +- src/conffile.c | 2 +- src/reqs.c | 2 +- src/reverse-proxy.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/reverse-proxy.h | 36 ++++++++++++ src/reverse_proxy.c | 154 ---------------------------------------------------- src/reverse_proxy.h | 36 ------------ 7 files changed, 193 insertions(+), 193 deletions(-) create mode 100644 src/reverse-proxy.c create mode 100644 src/reverse-proxy.h delete mode 100644 src/reverse_proxy.c delete mode 100644 src/reverse_proxy.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 3904cd3..55485d6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,7 +41,7 @@ tinyproxy_SOURCES = \ vector.c vector.h EXTRA_tinyproxy_SOURCES = filter.c filter.h \ - reverse_proxy.c reverse_proxy.h + reverse-proxy.c reverse-proxy.h tinyproxy_DEPENDENCIES = @ADDITIONAL_OBJECTS@ tinyproxy_LDADD = @ADDITIONAL_OBJECTS@ diff --git a/src/conffile.c b/src/conffile.c index 66e4600..18f19fe 100644 --- a/src/conffile.c +++ b/src/conffile.c @@ -30,7 +30,7 @@ #include "htmlerror.h" #include "log.h" #include "reqs.h" -#include "reverse_proxy.h" +#include "reverse-proxy.h" /* * The configuration directives are defined in the structure below. Each diff --git a/src/reqs.c b/src/reqs.c index ff65343..e1a3b99 100644 --- a/src/reqs.c +++ b/src/reqs.c @@ -39,7 +39,7 @@ #include "text.h" #include "utils.h" #include "vector.h" -#include "reverse_proxy.h" +#include "reverse-proxy.h" /* * Maximum length of a HTTP line diff --git a/src/reverse-proxy.c b/src/reverse-proxy.c new file mode 100644 index 0000000..a89db0d --- /dev/null +++ b/src/reverse-proxy.c @@ -0,0 +1,154 @@ +/* $Id: reverse-proxy.c,v 1.1 2005-08-16 04:03:19 rjkaes Exp $ + * + * Allow tinyproxy to be used as a reverse proxy. + * + * Copyright (C) 1999-2005 Robert James Kaes (rjkaes@users.sourceforge.net) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include "tinyproxy.h" +#include "reverse-proxy.h" + +#include "conns.h" +#include "heap.h" +#include "htmlerror.h" +#include "log.h" + +/* + * Add entry to the reversepath list + */ +void +reversepath_add(const char *path, const char *url) +{ + struct reversepath *reverse; + + if (url == NULL) { + log_message(LOG_WARNING, + "Illegal reverse proxy rule: missing url"); + return; + } + + if (!strstr(url, "://")) { + log_message(LOG_WARNING, + "Skipping reverse proxy rule: '%s' is not a valid url", + url); + return; + } + + if (path && *path != '/') { + log_message(LOG_WARNING, + "Skipping reverse proxy rule: path '%s' doesn't start with a /", + path); + return; + } + + if (!(reverse = safemalloc(sizeof(struct reversepath)))) { + log_message(LOG_ERR, + "Unable to allocate memory in reversepath_add()"); + return; + } + + if (!path) + reverse->path = safestrdup("/"); + else + reverse->path = safestrdup(path); + + reverse->url = safestrdup(url); + + reverse->next = config.reversepath_list; + config.reversepath_list = reverse; + + log_message(LOG_INFO, + "Added reverse proxy rule: %s -> %s", reverse->path, + reverse->url); +} + +/* + * Check if a request url is in the reversepath list + */ +struct reversepath * +reversepath_get(char *url) +{ + struct reversepath *reverse = config.reversepath_list; + + while (reverse) { + if (strstr(url, reverse->path) == url) + return reverse; + + reverse = reverse->next; + } + + return NULL; +} + +/* + * Rewrite the URL for reverse proxying. + */ +char * +reverse_rewrite_url(struct conn_s *connptr, hashmap_t hashofheaders, char *url) +{ + char *rewrite_url = NULL; + char *cookie = NULL; + char *cookieval; + struct reversepath *reverse; + + /* Reverse requests always start with a slash */ + if (*url == '/') { + /* First try locating the reverse mapping by request url */ + reverse = reversepath_get(url); + if (reverse) { + rewrite_url = safemalloc(strlen(url) + + strlen(reverse->url) + 1); + strcpy(rewrite_url, reverse->url); + strcat(rewrite_url, url + strlen(reverse->path)); + } else if (config.reversemagic + && hashmap_entry_by_key(hashofheaders, + "cookie", + (void **)&cookie) > 0) { + + /* No match - try the magical tracking cookie next */ + if ((cookieval = strstr(cookie, REVERSE_COOKIE "=")) + && (reverse = + reversepath_get(cookieval + + strlen(REVERSE_COOKIE) + 1))) { + + rewrite_url = safemalloc(strlen(url) + + strlen + (reverse->url) + 1); + strcpy(rewrite_url, reverse->url); + strcat(rewrite_url, url + 1); + + log_message(LOG_INFO, + "Magical tracking cookie says: %s", + reverse->path); + } + } + } + + /* Forward proxy support off and no reverse path match found */ + if (config.reverseonly && !rewrite_url) { + log_message(LOG_ERR, "Bad request"); + indicate_http_error(connptr, 400, "Bad Request", + "detail", + "Request has an invalid URL", "url", + url, NULL); + return NULL; + } + + log_message(LOG_CONN, "Rewriting URL: %s -> %s", url, rewrite_url); + + /* Store reverse path so that the magical tracking cookie can be set */ + if (config.reversemagic) + connptr->reversepath = safestrdup(reverse->path); + + return rewrite_url; +} diff --git a/src/reverse-proxy.h b/src/reverse-proxy.h new file mode 100644 index 0000000..05d7236 --- /dev/null +++ b/src/reverse-proxy.h @@ -0,0 +1,36 @@ +/* $Id: reverse-proxy.h,v 1.1 2005-08-16 04:03:19 rjkaes Exp $ + * + * See 'reverse-proxy.c' for a detailed description. + * + * Copyright (C) 2005 Robert James Kaes (rjkaes@users.sourceforge.net) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#ifndef TINYPROXY_REVERSE_PROXY_H +#define TINYPROXY_REVERSE_PROXY_H + +#include "conns.h" + +struct reversepath { + struct reversepath *next; + char *path; + char *url; +}; + +#define REVERSE_COOKIE "yummy_magical_cookie" + +extern void reversepath_add(const char *path, const char *url); +extern struct reversepath *reversepath_get(char *url); +extern char *reverse_rewrite_url(struct conn_s *connptr, + hashmap_t hashofheaders, char *url); + +#endif diff --git a/src/reverse_proxy.c b/src/reverse_proxy.c deleted file mode 100644 index 40f15f4..0000000 --- a/src/reverse_proxy.c +++ /dev/null @@ -1,154 +0,0 @@ -/* $Id: reverse_proxy.c,v 1.1 2005-08-16 04:03:19 rjkaes Exp $ - * - * Allow tinyproxy to be used as a reverse proxy. - * - * Copyright (C) 1999-2005 Robert James Kaes (rjkaes@users.sourceforge.net) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2, or (at your option) any - * later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - */ - -#include "tinyproxy.h" -#include "reverse_proxy.h" - -#include "conns.h" -#include "heap.h" -#include "htmlerror.h" -#include "log.h" - -/* - * Add entry to the reversepath list - */ -void -reversepath_add(const char *path, const char *url) -{ - struct reversepath *reverse; - - if (url == NULL) { - log_message(LOG_WARNING, - "Illegal reverse proxy rule: missing url"); - return; - } - - if (!strstr(url, "://")) { - log_message(LOG_WARNING, - "Skipping reverse proxy rule: '%s' is not a valid url", - url); - return; - } - - if (path && *path != '/') { - log_message(LOG_WARNING, - "Skipping reverse proxy rule: path '%s' doesn't start with a /", - path); - return; - } - - if (!(reverse = safemalloc(sizeof(struct reversepath)))) { - log_message(LOG_ERR, - "Unable to allocate memory in reversepath_add()"); - return; - } - - if (!path) - reverse->path = safestrdup("/"); - else - reverse->path = safestrdup(path); - - reverse->url = safestrdup(url); - - reverse->next = config.reversepath_list; - config.reversepath_list = reverse; - - log_message(LOG_INFO, - "Added reverse proxy rule: %s -> %s", reverse->path, - reverse->url); -} - -/* - * Check if a request url is in the reversepath list - */ -struct reversepath * -reversepath_get(char *url) -{ - struct reversepath *reverse = config.reversepath_list; - - while (reverse) { - if (strstr(url, reverse->path) == url) - return reverse; - - reverse = reverse->next; - } - - return NULL; -} - -/* - * Rewrite the URL for reverse proxying. - */ -char * -reverse_rewrite_url(struct conn_s *connptr, hashmap_t hashofheaders, char *url) -{ - char *rewrite_url = NULL; - char *cookie = NULL; - char *cookieval; - struct reversepath *reverse; - - /* Reverse requests always start with a slash */ - if (*url == '/') { - /* First try locating the reverse mapping by request url */ - reverse = reversepath_get(url); - if (reverse) { - rewrite_url = safemalloc(strlen(url) + - strlen(reverse->url) + 1); - strcpy(rewrite_url, reverse->url); - strcat(rewrite_url, url + strlen(reverse->path)); - } else if (config.reversemagic - && hashmap_entry_by_key(hashofheaders, - "cookie", - (void **)&cookie) > 0) { - - /* No match - try the magical tracking cookie next */ - if ((cookieval = strstr(cookie, REVERSE_COOKIE "=")) - && (reverse = - reversepath_get(cookieval + - strlen(REVERSE_COOKIE) + 1))) { - - rewrite_url = safemalloc(strlen(url) + - strlen - (reverse->url) + 1); - strcpy(rewrite_url, reverse->url); - strcat(rewrite_url, url + 1); - - log_message(LOG_INFO, - "Magical tracking cookie says: %s", - reverse->path); - } - } - } - - /* Forward proxy support off and no reverse path match found */ - if (config.reverseonly && !rewrite_url) { - log_message(LOG_ERR, "Bad request"); - indicate_http_error(connptr, 400, "Bad Request", - "detail", - "Request has an invalid URL", "url", - url, NULL); - return NULL; - } - - log_message(LOG_CONN, "Rewriting URL: %s -> %s", url, rewrite_url); - - /* Store reverse path so that the magical tracking cookie can be set */ - if (config.reversemagic) - connptr->reversepath = safestrdup(reverse->path); - - return rewrite_url; -} diff --git a/src/reverse_proxy.h b/src/reverse_proxy.h deleted file mode 100644 index f27a9de..0000000 --- a/src/reverse_proxy.h +++ /dev/null @@ -1,36 +0,0 @@ -/* $Id: reverse_proxy.h,v 1.1 2005-08-16 04:03:19 rjkaes Exp $ - * - * See 'reverse_proxy.c' for a detailed description. - * - * Copyright (C) 2005 Robert James Kaes (rjkaes@users.sourceforge.net) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2, or (at your option) any - * later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - */ - -#ifndef TINYPROXY_REVERSE_PROXY_H -#define TINYPROXY_REVERSE_PROXY_H - -#include "conns.h" - -struct reversepath { - struct reversepath *next; - char *path; - char *url; -}; - -#define REVERSE_COOKIE "yummy_magical_cookie" - -extern void reversepath_add(const char *path, const char *url); -extern struct reversepath *reversepath_get(char *url); -extern char *reverse_rewrite_url(struct conn_s *connptr, - hashmap_t hashofheaders, char *url); - -#endif -- cgit v1.2.3