New global variable 'site_prefix' which replaces the often-repeated code which constr...
authorArt Cancro <ajc@citadel.org>
Wed, 8 Sep 2010 16:49:46 +0000 (12:49 -0400)
committerArt Cancro <ajc@citadel.org>
Wed, 8 Sep 2010 16:49:46 +0000 (12:49 -0400)
webcit/auth.c
webcit/context_loop.c
webcit/groupdav_main.c
webcit/listsub.c
webcit/openid.c
webcit/webcit.h
webcit/webserver.c

index a03be8811f8b1c86063a33ba9a923e9e7d5218e7..0dc3b725592c23620ee4869e83cee6e19a529228 100644 (file)
@@ -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);
index ca72387d7d791c6af8d03121cafd98674cb8c366..a358545e989c36ccbc46ce5be28f495cf4aa46a1 100644 (file)
@@ -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)
index f72d09a2231aa8647f11d99d38d4bf95d691f8b6..3fc38fb306d1b585f4ef26d8ba873eb97655ffd1 100644 (file)
@@ -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));
 }
 
 
index 60b5a49a6b272252c719565bec0222fc134c6834..c59cae348e29eec6582ae59a964b256ef76c3ec2 100644 (file)
@@ -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') {
index e58382d42d238c049e59c0599bb91cc38ef6d16d..8842e88102549f3f214d7d480a58a05a2417c917 100644 (file)
@@ -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);
index e6086b1b91e9665d497b12df76fc93e553740cb2..24eca9ad3454d56c7d334fe281e8876301554d30 100644 (file)
@@ -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);
index b5ed93295b8dfcabfe2a5f8afb452326da082f0d..87b83afad5b71d5a5e9987f265e28c6e47d3fb01 100644 (file)
@@ -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;