crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs | LICENSE

commit 02d94599519b5c28a3fedc2bbb7a81b28eb6fccf
parent 53ad389dd9d0f5689cd8a2f3b5155eae6515905c
Author: finwo <finwo@pm.me>
Date:   Sat,  3 Jan 2026 19:35:12 +0100

2.08

Diffstat:
MChangeLog | 4++++
MMakefile | 2+-
Mxr/backend/backend | 1+
Mxr/backenddef/backenddef | 5++++-
Mxr/backenddef/backenddef1.cc | 2+-
Dxr/backenddef/backenddef2.cc | 4----
Mxr/config/config | 2+-
Mxr/config/parsecmdline.cc | 10++++++++--
Mxr/config/setbackend.cc | 19+++++++++++--------
Mxr/etc/usage.txt | 3+++
10 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,7 @@ +2.08 [KK 2008-08-31] +I'd forgotten to include the 'P' into the set of allowed flags +(--prefix-timestamp would work, -P not). Fixed. + 2.07 [KK 2008-08-28] Stupid bug in 2.06, sorry that 2.06 got out.. Fixed. diff --git a/Makefile b/Makefile @@ -1,7 +1,7 @@ # Top-level Makefile for XR # ------------------------- -VER = 2.07 +VER = 2.08 BINDIR = /usr/sbin TAR = /tmp/crossroads-$(VER).tar.gz AUTHOR = Karel Kubat <karel@kubat.nl> diff --git a/xr/backend/backend b/xr/backend/backend @@ -27,6 +27,7 @@ public: string server() const { return (bdef.server()); } int port() const { return (bdef.port()); } unsigned maxconn() const { return (bdef.maxconn()); } + string hostmatch() const { return (bdef.hostmatch()); } unsigned connections() const { return (nconn); } double bytesserved() const { return (bytes_served); } unsigned clientsserved() const { return (totconn); } diff --git a/xr/backenddef/backenddef b/xr/backenddef/backenddef @@ -8,7 +8,7 @@ using namespace std; class BackendDef { public: - BackendDef(); + BackendDef(): srv(""), prt(-1), max(0), host_match("") {} BackendDef (string s, string p, string m = ""); void server(string s) { srv = s; } @@ -16,11 +16,14 @@ public: void port (int p) { prt = p; } int port() const { return (prt); } unsigned maxconn() const { return (max); } + void hostmatch(string s) { host_match = s; } + string hostmatch() const { return (host_match); } private: string srv; int prt; unsigned max; + string host_match; }; #endif diff --git a/xr/backenddef/backenddef1.cc b/xr/backenddef/backenddef1.cc @@ -1,7 +1,7 @@ #include "backenddef" BackendDef::BackendDef (string server, string port, string maxclients) : - srv(server), prt(0), max(0) { + srv(server), prt(-1), max(0), host_match("") { if (sscanf (port.c_str(), "%d", &prt) < 1) throw static_cast<Error>("Bad backend port specifier: '") + port + diff --git a/xr/backenddef/backenddef2.cc b/xr/backenddef/backenddef2.cc @@ -1,4 +0,0 @@ -#include "backenddef" - -BackendDef::BackendDef () : srv(""), prt(-1) { -} diff --git a/xr/config/config b/xr/config/config @@ -64,7 +64,7 @@ public: } private: - void setbackend (string s); + void setbackend (string s, string hostmatch); void setserver (string s); void setdispatchmode (string s); int setinteger (string s) const; diff --git a/xr/config/parsecmdline.cc b/xr/config/parsecmdline.cc @@ -16,7 +16,7 @@ void Config::parsecmdline (int ac, char **av) { throw static_cast<Error>("Bad command line '") + cmdline + "'\n" + USAGE; -# define OPTSTRING "?a:A:B:b:c:Dd:fhH:m:np:Ss:t:T:vVw:xX" +# define OPTSTRING "?a:A:B:b:c:Dd:fhH:m:M:nPp:Ss:t:T:vVw:xX" # ifdef HAVE_GETOPT_LONG static struct option longopts[] = { { "allow-from", required_argument, 0, 'a' }, @@ -31,6 +31,7 @@ void Config::parsecmdline (int ac, char **av) { { "help", no_argument, 0, 'h' }, { "add-server-header", required_argument, 0, 'H' }, { "max-connections", required_argument, 0, 'm' }, + { "host-match", required_argument, 0, 'M' }, { "tryout", no_argument, 0, 'n' }, { "prefix-timestamp", no_argument, 0, 'P' }, { "pidfile", required_argument, 0, 'p' }, @@ -50,6 +51,7 @@ void Config::parsecmdline (int ac, char **av) { int opt; bool backend_set = false; bool tryout = false; + string current_hostmatch = ""; # ifdef HAVE_GETOPT_LONG while ( (opt = getopt_long (ac, av, OPTSTRING, longopts, 0)) > 0) @@ -65,7 +67,7 @@ void Config::parsecmdline (int ac, char **av) { adddeny (optarg); break; case 'b': - setbackend (optarg); + setbackend (optarg, current_hostmatch); backend_set = true; break; case 'B': @@ -88,11 +90,15 @@ void Config::parsecmdline (int ac, char **av) { foreground_mode = true; break; case 'h': + case '?': throw static_cast<Error>(USAGE); break; case 'H': addserverheader (optarg); break; + case 'M': + current_hostmatch = optarg; + break; case 'm': max_conn = (unsigned)setinteger (optarg); break; diff --git a/xr/config/setbackend.cc b/xr/config/setbackend.cc @@ -1,8 +1,9 @@ #include "config" -void Config::setbackend (string str) { +void Config::setbackend (string str, string host) { vector<string> parts; int pos; + while ( (pos = str.find_first_of(":")) > 0) { if (pos > 0) parts.push_back (str.substr(0, pos)); @@ -13,11 +14,13 @@ void Config::setbackend (string str) { if (parts.size() < 2 || parts.size() > 3) throw static_cast<Error>("Bad back end specifier in '-b") + str + "', expected: SERVER:PORT or SERVER:PORT:MAXCONNECTIONS"; - if (parts.size() == 2) { - BackendDef bd (parts[0], parts[1]); - blist.push_back (bd); - } else { - BackendDef bd (parts[0], parts[1], parts[2]); - blist.push_back (bd); - } + + BackendDef *bdp; + if (parts.size() == 2) + bdp = new BackendDef(parts[0], parts[1]); + else + bdp = new BackendDef(parts[0], parts[1], parts[2]); + bdp->hostmatch(host); + blist.push_back (*bdp); + delete bdp; } diff --git a/xr/etc/usage.txt b/xr/etc/usage.txt @@ -54,6 +54,9 @@ may not exist on your platform): -m MAX, --max-connections MAX Sets the maximum number of connections to the balancer. Default is 0, no maximum. + -M HOST, --host-match HOST + Subsequently stated backends only apply when clients request a + matching host. Only available when the server is in http mode. -n, --tryout Validates all flags and stops; does not start the balancer. -P, --prefix-timestamp