]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
+ guess mimetype by template extension
[citadel.git] / webcit / webcit.c
index 5985982bd8a52cec9ac446a51a87f51e0c81db4e..3904d043199465dc1ed46c2fee4b220423972526 100644 (file)
@@ -175,11 +175,8 @@ void output_headers(       int do_httpheaders,     /* 1 = output HTTP headers
                }
 
                if ( (WC->logged_in) && (!unset_cookies) ) {
-                       wprintf("<div id=\"iconbar\">");
-                       do_selected_iconbar();
-                       /** check for instant messages (these display in a new window) */
+                 //DoTemplate(HKEY("iconbar"), NULL, &NoCtx);
                        page_popup();
-                       wprintf("</div>");
                }
 
                if (do_room_banner == 1) {
@@ -194,6 +191,13 @@ void output_headers(       int do_httpheaders,     /* 1 = output HTTP headers
        }
 }
 
+void output_custom_content_header(const char *ctype) {
+  hprintf("HTTP/1.1 200 OK\r\n");
+  hprintf("Content-type: %s; charset=utf-8\r\n",ctype);
+  hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(serv_info.serv_software));
+  hprintf("Connection: close\r\n");
+}
+
 
 /*
  * Generic function to do an HTTP redirect.  Easy and fun.
@@ -364,11 +368,12 @@ void blank_page(void) {
  * A template has been requested
  */
 void url_do_template(void) {
+       const StrBuf *MimeType;
        const StrBuf *Tmpl = sbstr("template");
        begin_burst();
-       output_headers(1, 0, 0, 0, 1, 0);
-       DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
-       end_burst();
+       output_headers(0, 0, 0, 0, 1, 0);
+       MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
+       http_transmit_thing(ChrPtr(MimeType), 0);
 }
 
 
@@ -544,7 +549,7 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
        StrBuf *UrlLine = NULL;
        StrBuf *content = NULL;
        const char *content_end = NULL;
-       char browser_host[256];
+       StrBuf *browser_host = NULL;
        char user_agent[256];
        int body_start = 0;
        int is_static = 0;
@@ -572,7 +577,6 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
        safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
        c_httpauth_user = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_USER));
        c_httpauth_pass = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_PASS));
-       strcpy(browser_host, "");
 
        WCC= WC;
        if (WCC->WBuf == NULL)
@@ -587,6 +591,7 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
        WCC->upload = NULL;
        WCC->is_mobile = 0;
        WCC->trailing_javascript = NewStrBuf();
+       WCC->nWildfireHeaders = 0;
 
        /** Figure out the action */
        index[0] = action;
@@ -651,27 +656,22 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
        if ((follow_xff) &&
            GetHash(HTTPHeaders, HKEY("X-FORWARDED-HOST"), &vLine) &&
            (vLine != NULL)) {
-               safestrncpy(WCC->http_host, 
-                           ChrPtr((StrBuf*)vLine), 
-                           sizeof WCC->http_host);
+               WCC->http_host = (StrBuf*)vLine;
        }
-       if (IsEmptyStr(WCC->http_host) && 
+       if ((StrLength(WCC->http_host) == 0) && 
            GetHash(HTTPHeaders, HKEY("HOST"), &vLine) &&
            (vLine!=NULL)) {
-               safestrncpy(WCC->http_host, 
-                           ChrPtr((StrBuf*)vLine), 
-                           sizeof WCC->http_host);
-               
+               WCC->http_host = (StrBuf*)vLine;
        }
+
        if (GetHash(HTTPHeaders, HKEY("X-FORWARDED-FOR"), &vLine) &&
            (vLine!=NULL)) {
-               safestrncpy(browser_host, 
-                           ChrPtr((StrBuf*) vLine), 
-                           sizeof browser_host);
-               while (num_tokens(browser_host, ',') > 1) {
-                       remove_token(browser_host, 0, ',');
+               browser_host = (StrBuf*) vLine;
+
+               while (StrBufNum_tokens(browser_host, ',') > 1) {
+                       StrBufRemove_token(browser_host, 0, ',');
                }
-               striplt(browser_host);
+               StrBufTrim(browser_host);
        }
 
        if (ContentLength > 0) {
@@ -701,9 +701,9 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
        }
 
        /* make a note of where we are in case the user wants to save it */
-       safestrncpy(WCC->this_page, ChrPtr(ReqLine), sizeof(WCC->this_page));
-       remove_token(WCC->this_page, 2, ' ');
-       remove_token(WCC->this_page, 0, ' ');
+       WCC->this_page = NewStrBufDup(ReqLine);
+       StrBufRemove_token(WCC->this_page, 2, ' ');
+       StrBufRemove_token(WCC->this_page, 0, ' ');
 
        /* If there are variables in the URL, we must grab them now */
        UrlLine = NewStrBufDup(ReqLine);
@@ -801,15 +801,28 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
                }
                else {
                        WCC->connected = 1;
-                       serv_getln(buf, sizeof buf);    /** get the server welcome message */
+                       serv_getln(buf, sizeof buf);    /* get the server greeting */
 
-                       /**
+                       /* Are there too many users already logged in? */
+                       if (!strncmp(buf, "571", 3)) {
+                               wprintf(_("This server is already serving its maximum number of users and cannot accept any additional logins at this time.  Please try again later or contact your system administrator."));
+                               end_burst();
+                               end_webcit_session();
+                               goto SKIP_ALL_THIS_CRAP;
+                       }
+
+                       /*
                         * From what host is our user connecting?  Go with
                         * the host at the other end of the HTTP socket,
                         * unless we are following X-Forwarded-For: headers
                         * and such a header has already turned up something.
                         */
-                       if ( (!follow_xff) || (strlen(browser_host) == 0) ) {
+                       if ( (!follow_xff) || (StrLength(browser_host) == 0) ) {
+                               if (browser_host == NULL) {
+                                       browser_host = NewStrBuf();
+                                       Put(HTTPHeaders, HKEY("FreeMeWithTheOtherHeaders"), 
+                                           browser_host, HFreeStrBuf);
+                               }
                                locate_host(browser_host, WCC->http_sock);
                        }
 
@@ -1015,6 +1028,7 @@ SKIP_ALL_THIS_CRAP:
        FreeStrBuf(&c_roomname);
        FreeStrBuf(&c_httpauth_user);
        FreeStrBuf(&c_httpauth_pass);
+       FreeStrBuf(&WCC->this_page);
        fflush(stdout);
        if (content != NULL) {
                FreeStrBuf(&content);
@@ -1026,6 +1040,7 @@ SKIP_ALL_THIS_CRAP:
                WCC->upload_length = 0;
        }
        FreeStrBuf(&WCC->trailing_javascript);
+       WCC->http_host = NULL;
 }