From bfee0760c00d5b396d6902a7f1aeab2813701f74 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 22 Aug 2001 16:38:06 +0000 Subject: [PATCH] * Added the "-c" command line option to generate optional cookies indicating the host name of the server. This makes it easy to put a cluster of WebCit servers behind (for example) an Arrowpoint load balancer. --- webcit/ChangeLog | 6 ++++++ webcit/README.txt | 11 +++++++++-- webcit/webcit.c | 5 ++++- webcit/webcit.h | 1 + webcit/webserver.c | 19 ++++++++++++++++--- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 3a2c25b3d..cc171b84f 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,9 @@ $Log$ +Revision 301.6 2001/08/22 16:38:06 ajc +* Added the "-c" command line option to generate optional cookies indicating + the host name of the server. This makes it easy to put a cluster of WebCit + servers behind (for example) an Arrowpoint load balancer. + Revision 301.5 2001/08/21 04:02:56 ajc * Added some more meta-tags to (hopefully) prevent the "lame goto" caused by unwanted page caching @@ -619,3 +624,4 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix + diff --git a/webcit/README.txt b/webcit/README.txt index 658e019c2..4dd93b196 100644 --- a/webcit/README.txt +++ b/webcit/README.txt @@ -61,11 +61,11 @@ any reason. Open /etc/inittab and add an entry something like this: Several command-line options are also available. Here's the usage for the "webserver" program: - webserver [-p localport] [-t tracefile] [remotehost [remoteport]] + webserver [-p localport] [-t tracefile] [-c] [remotehost [remoteport]] *or* - webserver [-p localport] [-t tracefile] uds /your/citadel/directory + webserver [-p localport] [-t tracefile] [-c] uds /your/citadel/directory Explained: @@ -77,6 +77,13 @@ the "webserver" program: -> tracefile: where you want WebCit to log to. This can be a file, a virtual console, or /dev/null to suppress logging altogether. + -> The "-c" option causes WebCit to output an extra cookie containing the + identity of the WebCit server. The cookie will look like this: + Set-cookie: wcserver=your.host.name + This is useful if you have a cluster of WebCit servers sitting behind a + load balancer, and the load balancer has the ability to use cookies to + keep track of which server to send HTTP requests to. + -> remotehost: the name or IP address of the host on which your Citadel/UX server is running. The default is "localhost". (NOTE: if you run WebCit and the Citadel/UX server on different hosts, the real-time chat diff --git a/webcit/webcit.c b/webcit/webcit.c index e936f2b5f..243edf6c8 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -315,6 +315,9 @@ void output_headers(int controlcode) wprintf("Set-cookie: webcit=%s\n", unset); } else { wprintf("Set-cookie: webcit=%s\n", cookie); + if (server_cookie != NULL) { + wprintf("%s\n", server_cookie); + } } if (print_standard_html_head > 0) { @@ -324,7 +327,7 @@ void output_headers(int controlcode) wprintf("\n" "\n" "\n" - "\n"); + "\n"); if (refresh30) wprintf( "\n"); else wprintf( diff --git a/webcit/webcit.h b/webcit/webcit.h index faca0d6ad..5bdbd4158 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -156,6 +156,7 @@ struct serv_info serv_info; extern char floorlist[128][256]; extern char *axdefs[]; extern char *defaulthost, *defaultport; +extern char *server_cookie; extern struct wcsubst *global_subst; diff --git a/webcit/webserver.c b/webcit/webserver.c index d86bfcb86..2f05519fa 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -48,7 +48,7 @@ extern pthread_mutex_t SessionListMutex; extern pthread_key_t MyConKey; - +char *server_cookie = NULL; char *defaulthost = DEFAULT_HOST; @@ -228,7 +228,7 @@ int main(int argc, char **argv) char tracefile[PATH_MAX]; /* Parse command line */ - while ((a = getopt(argc, argv, "hp:t:")) != EOF) + while ((a = getopt(argc, argv, "hp:t:c")) != EOF) switch (a) { case 'p': port = atoi(optarg); @@ -239,9 +239,22 @@ int main(int argc, char **argv) freopen(tracefile, "w", stderr); freopen(tracefile, "r", stdin); break; + case 'c': + server_cookie = malloc(256); + if (server_cookie != NULL) { + strcpy(server_cookie, "Set-cookie: wcserver="); + if (gethostname( + &server_cookie[strlen(server_cookie)], + 200) != 0) { + fprintf(stderr, "gethostname: %s\n", + strerror(errno)); + free(server_cookie); + } + } + break; default: fprintf(stderr, "usage: webserver [-p localport] " - "[-t tracefile] " + "[-t tracefile] [-c] " "[remotehost [remoteport]]\n"); return 1; } -- 2.39.2