]> code.citadel.org Git - citadel.git/blobdiff - webcit/static.c
Added the ability to specify a file defining *simple* redirect patterns.
[citadel.git] / webcit / static.c
index 0b4f449c440f4495ec23546c457b2ff27512d814..1113fd1d578cd6eb54e0b606e017ae4549a2f739 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: webcit.c 7459 2009-05-17 08:34:33Z dothebart $
- *
  * This is the main transaction loop of the web service.  It maintains a
  * persistent session to the Citadel server, handling HTTP WebCit requests as
  * they arrive and presenting a user interface.
@@ -13,6 +11,8 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <stddef.h>
+
 
 #include "webcit.h"
 #include "webserver.h"
 HashList *StaticFilemappings[4] = {NULL, NULL, NULL, NULL};
 /*
                {
-                       lprintf(9, "Suspicious request. Ignoring.");
+                       syslog(9, "Suspicious request. Ignoring.");
                        hprintf("HTTP/1.1 404 Security check failed\r\n");
                        hprintf("Content-Type: text/plain\r\n\r\n");
-                       wprintf("You have sent a malformed or invalid request.\r\n");
+                       wc_printf("You have sent a malformed or invalid request.\r\n");
                        end_burst();
                }
 */
@@ -43,23 +43,24 @@ void output_static(const char *what)
 
        fd = open(what, O_RDONLY);
        if (fd <= 0) {
-               lprintf(9, "output_static('%s') [%s]  -- NOT FOUND --\n", what, ChrPtr(WC->Hdr->this_page));
+               syslog(9, "output_static('%s') [%s]  -- NOT FOUND --\n", what, ChrPtr(WC->Hdr->this_page));
                hprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
                hprintf("Content-Type: text/plain\r\n");
                begin_burst();
-               wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
+               wc_printf("Cannot open %s: %s\r\n", what, strerror(errno));
                end_burst();
        } else {
                len = strlen (what);
                content_type = GuessMimeByFilename(what, len);
 
                if (fstat(fd, &statbuf) == -1) {
-                       lprintf(9, "output_static('%s')  -- FSTAT FAILED --\n", what);
+                       syslog(9, "output_static('%s')  -- FSTAT FAILED --\n", what);
                        hprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
                        hprintf("Content-Type: text/plain\r\n");
                        begin_burst();
-                       wprintf("Cannot fstat %s: %s\n", what, strerror(errno));
+                       wc_printf("Cannot fstat %s: %s\n", what, strerror(errno));
                        end_burst();
+                       if (fd > 0) close(fd);
                        return;
                }
 
@@ -69,7 +70,7 @@ void output_static(const char *what)
                if (StrBufReadBLOB(WC->WBuf, &fd, 1, bytes, &Err) < 0)
                {
                        if (fd > 0) close(fd);
-                       lprintf(9, "output_static('%s')  -- FREAD FAILED (%s) --\n", what, strerror(errno));
+                       syslog(9, "output_static('%s')  -- FREAD FAILED (%s) --\n", what, strerror(errno));
                                hprintf("HTTP/1.1 500 internal server error \r\n");
                                hprintf("Content-Type: text/plain\r\n");
                                end_burst();
@@ -78,9 +79,6 @@ void output_static(const char *what)
 
 
                close(fd);
-#ifndef TECH_PREVIEW
-               lprintf(9, "output_static('%s')  %s\n", what, content_type);
-#endif
                http_transmit_thing(content_type, 2);
        }
        if (yesbstr("force_close_session")) {
@@ -200,7 +198,7 @@ int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir)
                        StrBufAppendBufPlain(OneWebName, filedir_entry->d_name, d_namelen, 0);
 
                        Put(DirList, SKEY(OneWebName), FileName, HFreeStrBuf);
-                       /* lprintf(9, "[%s | %s]\n", ChrPtr(OneWebName), ChrPtr(FileName)); */
+                       /* syslog(9, "[%s | %s]\n", ChrPtr(OneWebName), ChrPtr(FileName)); */
                        break;
                default:
                        break;
@@ -223,6 +221,8 @@ void output_flat_static(void)
        void *vFile;
        StrBuf *File;
 
+       if (WCC->Hdr->HR.Handler == NULL)
+               return;
        if (GetHash(StaticFilemappings[0], SKEY(WCC->Hdr->HR.Handler->Name), &vFile) &&
            (vFile != NULL))
        {
@@ -231,8 +231,6 @@ void output_flat_static(void)
        }
 }
 
-extern void do_404(void);
-
 void output_static_safe(HashList *DirList)
 {
        wcsession *WCC = WC;
@@ -246,7 +244,7 @@ void output_static_safe(HashList *DirList)
                output_static(ChrPtr(vFile));
        }
        else {
-               lprintf(1, "output_static_safe() file %s not found. \n", 
+               syslog(1, "output_static_safe() file %s not found. \n", 
                        ChrPtr(WCC->Hdr->HR.ReqLine));
 ///TODO: detect image & output blank image
                do_404();
@@ -269,6 +267,35 @@ void output_static_3(void)
        output_static_safe(StaticFilemappings[3]);
 }
 
+
+/*
+ * robots.txt
+ */
+void robots_txt(void) {
+       output_headers(0, 0, 0, 0, 0, 0);
+
+       hprintf("Content-type: text/plain\r\n"
+               "Server: %s\r\n"
+               "Connection: close\r\n",
+               PACKAGE_STRING);
+       begin_burst();
+
+       wc_printf("User-agent: *\r\n"
+               "Disallow: /printmsg\r\n"
+               "Disallow: /msgheaders\r\n"
+               "Disallow: /groupdav\r\n"
+               "Disallow: /do_template\r\n"
+               "Disallow: /static\r\n"
+               "Sitemap: %s/sitemap.xml\r\n"
+               "\r\n"
+               ,
+               ChrPtr(site_prefix)
+       );
+
+       wDumpContent(0);
+}
+
+
 void 
 ServerStartModule_STATIC
 (void)
@@ -298,10 +325,10 @@ InitModule_STATIC
        LoadStaticDir(static_dirs[2], StaticFilemappings[2], "");
        LoadStaticDir(static_dirs[3], StaticFilemappings[3], "");
 
-       WebcitAddUrlHandler(HKEY("robots.txt"), output_flat_static, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
-       WebcitAddUrlHandler(HKEY("favicon.ico"), output_flat_static, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
-       WebcitAddUrlHandler(HKEY("static"), output_static_0, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
-       WebcitAddUrlHandler(HKEY("static.local"), output_static_1, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
-       WebcitAddUrlHandler(HKEY("tinymce"), output_static_2, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
-       WebcitAddUrlHandler(HKEY("tiny_mce"), output_static_2, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
+       WebcitAddUrlHandler(HKEY("robots.txt"), "", 0, robots_txt, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
+       WebcitAddUrlHandler(HKEY("favicon.ico"), "", 0, output_flat_static, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
+       WebcitAddUrlHandler(HKEY("static"), "", 0, output_static_0, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
+       WebcitAddUrlHandler(HKEY("static.local"), "", 0, output_static_1, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
+       WebcitAddUrlHandler(HKEY("tinymce"), "", 0, output_static_2, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
+       WebcitAddUrlHandler(HKEY("tiny_mce"), "", 0, output_static_2, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
 }