From: Art Cancro Date: Wed, 8 Sep 2010 16:49:46 +0000 (-0400) Subject: New global variable 'site_prefix' which replaces the often-repeated code which constr... X-Git-Tag: v8.01~736 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=74ed588f96bdfc2292b03f9b20e569ba8cd971bb New global variable 'site_prefix' which replaces the often-repeated code which constructs a host header when we need to express something as an absolute URL. In the not too distant future I will add code to allow the server to override the detected value with a configured value. --- diff --git a/webcit/auth.c b/webcit/auth.c index a03be8811..0dc3b7255 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -286,7 +286,6 @@ void openid_manual_create(void) */ void do_openid_login(void) { - wcsession *WCC = WC; char buf[4096]; if (havebstr("language")) { @@ -300,10 +299,10 @@ void do_openid_login(void) } if (havebstr("login_action")) { snprintf(buf, sizeof buf, - "OIDS %s|%s://%s/finalize_openid_login|%s://%s", + "OIDS %s|%s/finalize_openid_login|%s", bstr("openid_url"), - (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->HR.http_host), - (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->HR.http_host) + ChrPtr(site_prefix), + ChrPtr(site_prefix) ); serv_puts(buf); diff --git a/webcit/context_loop.c b/webcit/context_loop.c index ca72387d7..a358545e9 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -671,10 +671,18 @@ void Header_HandleUserAgent(StrBuf *Line, ParsedHttpHdrs *hdr) void Header_HandleHost(StrBuf *Line, ParsedHttpHdrs *hdr) { - if ((follow_xff) && (hdr->HR.http_host != NULL)) + if ((follow_xff) && (hdr->HR.http_host != NULL)) { return; - else + } + else { hdr->HR.http_host = Line; + if (site_prefix == NULL) { + site_prefix = NewStrBuf(); + StrBufAppendPrintf(site_prefix, "%s://", (is_https ? "https" : "http") ); + StrBufAppendBuf(site_prefix, Line, 0); + lprintf(CTDL_DEBUG, "\033[33m [%s] \033[0m\n", ChrPtr(site_prefix)); + } + } } void Header_HandleXFFHost(StrBuf *Line, ParsedHttpHdrs *hdr) diff --git a/webcit/groupdav_main.c b/webcit/groupdav_main.c index f72d09a22..3fc38fb30 100644 --- a/webcit/groupdav_main.c +++ b/webcit/groupdav_main.c @@ -190,39 +190,20 @@ void groupdav_main(void) * Output our host prefix for globally absolute URL's. */ void groupdav_identify_host(void) { - wcsession *WCC = WC; - - if (StrLength(WCC->Hdr->HR.http_host)!=0) { - wc_printf("%s://%s", - (is_https ? "https" : "http"), - ChrPtr(WCC->Hdr->HR.http_host)); - } + wc_printf("%s", ChrPtr(site_prefix)); } void tmplput_GROUPDAV_HOSTNAME(StrBuf *Target, WCTemplputParams *TP) { - wcsession *WCC = WC; - - if (StrLength(WCC->Hdr->HR.http_host)!=0) { - StrBufAppendPrintf(Target, - "%s://%s", - (is_https ? "https" : "http"), - ChrPtr(WCC->Hdr->HR.http_host)); - } + StrBufAppendPrintf(Target, "%s", ChrPtr(site_prefix)); } /* * Output our host prefix for globally absolute URL's. */ void groupdav_identify_hosthdr(void) { - wcsession *WCC = WC; - - if (StrLength(WCC->Hdr->HR.http_host)!=0) { - hprintf("%s://%s", - (is_https ? "https" : "http"), - ChrPtr(WCC->Hdr->HR.http_host)); - } + hprintf("%s", ChrPtr(site_prefix)); } diff --git a/webcit/listsub.c b/webcit/listsub.c index 60b5a49a6..c59cae348 100644 --- a/webcit/listsub.c +++ b/webcit/listsub.c @@ -55,12 +55,11 @@ void do_listsub(void) * Subscribe command */ if (!strcasecmp(cmd, "subscribe")) { - serv_printf("SUBS subscribe|%s|%s|%s|%s://%s/listsub", + serv_printf("SUBS subscribe|%s|%s|%s|%s/listsub", room, email, subtype, - (is_https ? "https" : "http"), - ChrPtr(WC->Hdr->HR.http_host) + ChrPtr(site_prefix) ); serv_getln(buf, sizeof buf); if (buf[0] == '2') { @@ -97,11 +96,10 @@ void do_listsub(void) * Unsubscribe command */ else if (!strcasecmp(cmd, "unsubscribe")) { - serv_printf("SUBS unsubscribe|%s|%s|%s://%s/listsub", - room, - email, - (is_https ? "https" : "http"), - ChrPtr(WC->Hdr->HR.http_host) + serv_printf("SUBS unsubscribe|%s|%s|%s/listsub", + room, + email, + ChrPtr(site_prefix) ); serv_getln(buf, sizeof buf); if (buf[0] == '2') { diff --git a/webcit/openid.c b/webcit/openid.c index e58382d42..8842e8810 100644 --- a/webcit/openid.c +++ b/webcit/openid.c @@ -66,15 +66,14 @@ void openid_attach(void) { char buf[4096]; if (havebstr("attach_button")) { - wcsession *WCC = WC; lprintf(CTDL_DEBUG, "Attempting to attach %s\n", bstr("openid_url")); snprintf(buf, sizeof buf, - "OIDS %s|%s://%s/finalize_openid_login|%s://%s", - bstr("openid_url"), - (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->HR.http_host), - (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->HR.http_host) + "OIDS %s|%s/finalize_openid_login|%s", + bstr("openid_url"), + ChrPtr(site_prefix), + ChrPtr(site_prefix) ); serv_puts(buf); diff --git a/webcit/webcit.h b/webcit/webcit.h index e6086b1b9..24eca9ad3 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -612,6 +612,7 @@ extern char wizard_filename[]; extern int follow_xff; extern int num_threads_existing; extern int num_threads_executing; +extern StrBuf *site_prefix; void InitialiseSemaphores(void); void begin_critical_section(int which_one); diff --git a/webcit/webserver.c b/webcit/webserver.c index b5ed93295..87b83afad 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -25,6 +25,7 @@ int is_https = 0; /* Nonzero if I am an HTTPS service */ int follow_xff = 0; /* Follow X-Forwarded-For: header */ int home_specified = 0; /* did the user specify a homedir? */ int DisableGzip = 0; +StrBuf *site_prefix = NULL; extern pthread_mutex_t SessionListMutex; extern pthread_key_t MyConKey;