]> code.citadel.org Git - citadel.git/blobdiff - webcit/static.c
* shuffle auth arround...
[citadel.git] / webcit / static.c
index e12a10b298992fc83e60d14619b8627b5f4616c5..7e5580b273400c188ce13bbfedd959ee3f398041 100644 (file)
 
 
 HashList *StaticFilemappings[4] = {NULL, NULL, NULL, NULL};
-
-
 /*
-  for ( a = 0; a < 9; ++a)
-  {
-  extract_token(index[a], ChrPtr(ReqLine), a + 1, '/', sizes[a]);
-  if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
-  if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
-  if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
-  if ((index[a][0] == '.') && (index[a][1] == '.'))
-  nBackDots++;
-  if (index[a][0] == '\0')
-  nEmpty++;
-  }
-*/
-
-/* TODO: staticdata
-{
-
-
-       /** Figure out the action * /
-       index[0] = action;
-       sizes[0] = sizeof action;
-       for (a=1; a<9; a++)
-       {
-               index[a] = arg[a-1];
-               sizes[a] = sizeof arg[a-1];
-       }
-       nBackDots = 0;
-       nEmpty = 0;
-
-
-       /* Static content can be sent without connecting to Citadel. * /
-       is_static = 0;
-       for (a=0; a<ndirs && ! is_static; ++a) {
-               if (!strcasecmp(action, (char*)static_content_dirs[a])) { /* map web to disk location * /
-                       is_static = 1;
-                       n_static = a;
-               }
-       }
-       if (is_static) {
-               if (nBackDots < 2)
-               {
-                       snprintf(buf, sizeof buf, "%s/%s/%s/%s/%s/%s/%s/%s",
-                                static_dirs[n_static], 
-                                index[1], index[2], index[3], index[4], index[5], index[6], index[7]);
-                       for (a=0; a<8; ++a) {
-                               if (buf[strlen(buf)-1] == '/') {
-                                       buf[strlen(buf)-1] = 0;
-                               }
-                       }
-                       for (a = 0; a < strlen(buf); ++a) {
-                               if (isspace(buf[a])) {
-                                       buf[a] = 0;
-                               }
-                       }
-                       output_static(buf);
-               }
-               else 
                {
                        lprintf(9, "Suspicious request. Ignoring.");
                        hprintf("HTTP/1.1 404 Security check failed\r\n");
@@ -85,11 +27,7 @@ HashList *StaticFilemappings[4] = {NULL, NULL, NULL, NULL};
                        wprintf("You have sent a malformed or invalid request.\r\n");
                        end_burst();
                }
-               goto SKIP_ALL_THIS_CRAP;        /* Don't try to connect * /
-       }
-       }*/
-
-
+*/
 /*
  * dump out static pages from disk
  */
@@ -105,7 +43,7 @@ void output_static(const char *what)
 
        fd = open(what, O_RDONLY);
        if (fd <= 0) {
-               lprintf(9, "output_static('%s')  -- NOT FOUND --\n", what);
+               lprintf(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");
                wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
@@ -148,56 +86,31 @@ void output_static(const char *what)
        }
 }
 
-       /* TODO: integrate this into the static startup logic
-
-        * While we're at it, gracefully handle requests for the
-        * robots.txt and favicon.ico files.
-        * /
-       if ((StrLength(ReqLine) >= 11) &&
-           !strncasecmp(ChrPtr(ReqLine), "/robots.txt", 11)) {
-               StrBufPlain(ReqLine, 
-                           HKEY("/static/robots.txt"
-                                "?force_close_session=yes HTTP/1.1"));
-               Hdr.eReqType = eGET;
-       }
-       else if ((StrLength(ReqLine) >= 11) &&
-                !strncasecmp(ChrPtr(ReqLine), "/favicon.ico", 12)) {
-               StrBufPlain(ReqLine, HKEY("/static/favicon.ico"));
-               Hdr.eReqType = eGET;
-       }
-
-*/
-
-
-
 
 int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir)
 {
        char dirname[PATH_MAX];
        char reldir[PATH_MAX];
-       StrBuf *FileName;
-       StrBuf *Tag;
-       StrBuf *Dir;
-       StrBuf *WebDir;
-       StrBuf *OneWebName;
+       StrBuf *FileName = NULL;
+       StrBuf *Dir = NULL;
+       StrBuf *WebDir = NULL;
+       StrBuf *OneWebName = NULL;
        DIR *filedir = NULL;
        struct dirent d;
        struct dirent *filedir_entry;
        int d_namelen;
        int d_without_ext;
                
-       Dir = NewStrBufPlain(DirName, -1);
-       WebDir = NewStrBufPlain(RelDir, -1);
-       OneWebName = NewStrBuf();
        filedir = opendir (DirName);
        if (filedir == NULL) {
-               FreeStrBuf(&Dir);
                return 0;
        }
 
-       FileName = NewStrBuf();
-       Tag = NewStrBuf();
-       while ((readdir_r(filedir, &d, &filedir_entry) == 0) &&
+       Dir = NewStrBufPlain(DirName, -1);
+       WebDir = NewStrBufPlain(RelDir, -1);
+       OneWebName = NewStrBuf();
+
+               while ((readdir_r(filedir, &d, &filedir_entry) == 0) &&
               (filedir_entry != NULL))
        {
                char *PStart;
@@ -249,7 +162,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);
-                       printf("[%s | %s]  \n", ChrPtr(OneWebName), ChrPtr(FileName));
+/*                     printf("[%s | %s]  \n", ChrPtr(OneWebName), ChrPtr(FileName));*/
                        break;
                default:
                        break;
@@ -258,14 +171,29 @@ int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir)
 
        }
        closedir(filedir);
-       FreeStrBuf(&FileName);
-       FreeStrBuf(&Tag);
        FreeStrBuf(&Dir);
+       FreeStrBuf(&WebDir);
        FreeStrBuf(&OneWebName);
        return 1;
 }
 
 
+void output_flat_static(void)
+{
+       wcsession *WCC = WC;
+       void *vFile;
+       StrBuf *File;
+
+       if (GetHash(StaticFilemappings[0], SKEY(WCC->Hdr->Handler->Name), &vFile) &&
+           (vFile != NULL))
+       {
+               File = (StrBuf*) vFile;
+               output_static(ChrPtr(vFile));
+       }
+}
+
+
+
 void output_static_safe(HashList *DirList)
 {
        wcsession *WCC = WC;
@@ -328,11 +256,9 @@ InitModule_STATIC
        LoadStaticDir(static_dirs[2], StaticFilemappings[2], "");
        LoadStaticDir(static_dirs[3], StaticFilemappings[3], "");
 
-       WebcitAddUrlHandler(HKEY("robots.txt"), output_static_0, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
-       WebcitAddUrlHandler(HKEY("favicon.ico"), output_static_0, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
+       WebcitAddUrlHandler(HKEY("robots.txt"), output_flat_static, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
+       WebcitAddUrlHandler(HKEY("favicon.ico"), output_flat_static, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
        WebcitAddUrlHandler(HKEY("static"), output_static_0, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
        WebcitAddUrlHandler(HKEY("static.local"), output_static_1, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
        WebcitAddUrlHandler(HKEY("tinymce"), output_static_2, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
-
-
 }