Renderers cleanup part 1
[citadel.git] / webcit / static.c
index 9a91e267649c7a21a9b7358b608495a3781dbe06..34a656ee2b6058ed3203c4fc5d70cf9ad816dd98 100644 (file)
@@ -56,10 +56,10 @@ unsigned char OnePixelGif[37] = {
 };
 
 
-HashList *StaticFilemappings[4] = {NULL, NULL, NULL, NULL};
+HashList *StaticFilemappings[5] = {NULL, NULL, NULL, NULL, NULL};
 /*
   {
-  syslog(9, "Suspicious request. Ignoring.");
+  syslog(LOG_DEBUG, "Suspicious request. Ignoring.");
   hprintf("HTTP/1.1 404 Security check failed\r\n");
   hprintf("Content-Type: text/plain\r\n\r\n");
   wc_printf("You have sent a malformed or invalid request.\r\n");
@@ -94,7 +94,7 @@ void output_static(const char *what)
        content_type = GuessMimeByFilename(what, len);
        fd = open(what, O_RDONLY);
        if (fd <= 0) {
-               syslog(9, "output_static('%s') [%s]  -- NOT FOUND --\n", what, ChrPtr(WC->Hdr->this_page));
+               syslog(LOG_INFO, "output_static('%s') [%s]  -- NOT FOUND --\n", what, ChrPtr(WC->Hdr->this_page));
                if (strstr(content_type, "image/") != NULL)
                {
                        output_error_pic("the file you requsted is gone.", strerror(errno));
@@ -109,7 +109,7 @@ void output_static(const char *what)
                }
        } else {
                if (fstat(fd, &statbuf) == -1) {
-                       syslog(9, "output_static('%s')  -- FSTAT FAILED --\n", what);
+                       syslog(LOG_INFO, "output_static('%s')  -- FSTAT FAILED --\n", what);
                        if (strstr(content_type, "image/") != NULL)
                        {
                                output_error_pic("Stat failed!", strerror(errno));
@@ -131,7 +131,7 @@ void output_static(const char *what)
                if (StrBufReadBLOB(WC->WBuf, &fd, 1, bytes, &Err) < 0)
                {
                        if (fd > 0) close(fd);
-                       syslog(9, "output_static('%s')  -- FREAD FAILED (%s) --\n", what, strerror(errno));
+                       syslog(LOG_INFO, "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();
@@ -163,13 +163,20 @@ int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir)
         int d_namelen;
        int istoplevel;
                
+       if (IsEmptyStr(DirName))
+       {
+               return 0;
+       }
+
        filedir = opendir (DirName);
-       if (filedir == NULL) {
+       if (filedir == NULL)
+       {
                return 0;
        }
 
        d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1);
-       if (d == NULL) {
+       if (d == NULL)
+       {
                closedir(filedir);
                return 0;
        }
@@ -183,7 +190,7 @@ int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir)
               (filedir_entry != NULL))
        {
 #ifdef _DIRENT_HAVE_D_NAMLEN
-               d_namelen = filedir_entry->d_namelen;
+               d_namelen = filedir_entry->d_namlen;
 
 #else
                d_namelen = strlen(filedir_entry->d_name);
@@ -260,7 +267,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);
-                       /* syslog(9, "[%s | %s]\n", ChrPtr(OneWebName), ChrPtr(FileName)); */
+                       /* syslog(LOG_DEBUG, "[%s | %s]\n", ChrPtr(OneWebName), ChrPtr(FileName)); */
                        break;
                default:
                        break;
@@ -307,7 +314,7 @@ void output_static_safe(HashList *DirList)
                output_static(ChrPtr(File));
        }
        else {
-               syslog(1, "output_static_safe() file %s not found. \n", 
+               syslog(LOG_INFO, "output_static_safe() file %s not found. \n", 
                        ChrPtr(WCC->Hdr->HR.ReqLine));
                MimeType =  GuessMimeByFilename(SKEY(WCC->Hdr->HR.ReqLine));
                if (strstr(MimeType, "image/") != NULL)
@@ -334,7 +341,7 @@ void output_static_2(void)
 }
 void output_static_3(void)
 {
-       output_static_safe(StaticFilemappings[3]);
+       output_static_safe(StaticFilemappings[4]);
 }
 
 
@@ -379,6 +386,7 @@ ServerStartModule_STATIC
        StaticFilemappings[1] = NewHash(1, NULL);
        StaticFilemappings[2] = NewHash(1, NULL);
        StaticFilemappings[3] = NewHash(1, NULL);
+       StaticFilemappings[4] = NewHash(1, NULL);
 }
 void 
 ServerShutdownModule_STATIC
@@ -388,6 +396,7 @@ ServerShutdownModule_STATIC
        DeleteHash(&StaticFilemappings[1]);
        DeleteHash(&StaticFilemappings[2]);
        DeleteHash(&StaticFilemappings[3]);
+       DeleteHash(&StaticFilemappings[4]);
 }
 
 
@@ -399,6 +408,7 @@ InitModule_STATIC
        LoadStaticDir(static_dirs[1], StaticFilemappings[1], "");
        LoadStaticDir(static_dirs[2], StaticFilemappings[2], "");
        LoadStaticDir(static_dirs[3], StaticFilemappings[3], "");
+       LoadStaticDir(static_dirs[4], StaticFilemappings[4], "");
 
        WebcitAddUrlHandler(HKEY("robots.txt"), "", 0, robots_txt, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
        WebcitAddUrlHandler(HKEY("favicon.ico"), "", 0, output_flat_static, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
@@ -406,4 +416,5 @@ InitModule_STATIC
        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);
+       WebcitAddUrlHandler(HKEY("epiceditor"), "", 0, output_static_3, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY);
 }