Update config.guess and config.sub. Fix chdir() and -h in webcit
[citadel.git] / webcit / sysdep.c
index 6c0efa49b918a1941eb5a3049fb88c7fa657386a..bba4147aa50da6d13059fcfcbd02ff4624f13163 100644 (file)
 #include <sys/socket.h>
 #include <syslog.h>
 #include <sys/syslog.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
+#include <time.h>
 #include <limits.h>
 #include <sys/resource.h>
 #include <netinet/in.h>
@@ -79,19 +68,76 @@ char ctdl_key_dir[PATH_MAX]=SSL_DIR;
 char file_crpt_file_key[PATH_MAX]="";
 char file_crpt_file_csr[PATH_MAX]="";
 char file_crpt_file_cer[PATH_MAX]="";
+char file_etc_mimelist[PATH_MAX]="";
 
-const char editor_absolut_dir[PATH_MAX]=EDITORDIR;     /* nailed to what configure gives us. */
+char etc_dir[PATH_MAX];
 char static_dir[PATH_MAX];             /* calculated on startup */
 char static_local_dir[PATH_MAX];               /* calculated on startup */
 char static_icon_dir[PATH_MAX];          /* where should we find our mime icons? */
 char  *static_dirs[]={                         /* needs same sort order as the web mapping */
-       (char*)static_dir,                      /* our templates on disk */
-       (char*)static_local_dir,                /* user provided templates disk */
-       (char*)editor_absolut_dir,              /* the editor on disk */
-       (char*)static_icon_dir                  /* our icons... */
+       "./static",
+       "./static.local",
+       "./tiny_mce",
+       "./static/webcit_icons"
 };
 
 int ExitPipe[2];
+HashList *GZMimeBlackList = NULL; /* mimetypes which shouldn't be gzip compressed */
+
+void LoadMimeBlacklist(void)
+{
+       StrBuf *MimeBlackLine;
+       IOBuffer IOB;
+       eReadState state;
+       
+       memset(&IOB, 0, sizeof(IOBuffer));
+       IOB.fd = open(file_etc_mimelist, O_RDONLY);
+
+       IOB.Buf = NewStrBuf();
+       MimeBlackLine = NewStrBuf();
+       GZMimeBlackList = NewHash(1, NULL);
+
+       do
+       {
+               state = StrBufChunkSipLine(MimeBlackLine, &IOB);
+
+               switch (state)
+               {
+               case eMustReadMore:
+                       if (StrBuf_read_one_chunk_callback(IOB.fd, 0, &IOB) <= 0)
+                               state = eReadFail;
+                       break;
+               case eReadSuccess:
+                       if ((StrLength(MimeBlackLine) > 1) && 
+                           (*ChrPtr(MimeBlackLine) != '#'))
+                       {
+                               Put(GZMimeBlackList, SKEY(MimeBlackLine),
+                                   (void*) 1, reference_free_handler);
+                       }
+                       FlushStrBuf(MimeBlackLine);
+                       break;
+               case eReadFail:
+                       break;
+               case eBufferNotEmpty:
+                       break;
+               }
+       }
+       while (state != eReadFail);
+
+       close(IOB.fd);
+       
+       FreeStrBuf(&IOB.Buf);
+       FreeStrBuf(&MimeBlackLine);
+}
+
+void CheckGZipCompressionAllowed(const char *MimeType, long MLen)
+{
+       void *v;
+       wcsession *WCC = WC;
+
+       if (WCC->Hdr->HR.gzip_ok)
+           WCC->Hdr->HR.gzip_ok = GetHash(GZMimeBlackList, MimeType, MLen, &v) == 0;
+}
 
 void InitialiseSemaphores(void)
 {
@@ -131,6 +177,8 @@ void end_critical_section(int which_one)
 
 void ShutDownWebcit(void)
 {
+
+       DeleteHash(&GZMimeBlackList);
        free_zone_directory ();
        icaltimezone_release_zone_tab ();
        icalmemory_free_ring ();
@@ -486,6 +534,15 @@ webcit_calc_dirs_n_files(int relh, const char *basedir, int home, char *webcitdi
                 "%s/citadel.cer",
                 ctdl_key_dir);
 
+
+       basedir=ETCDIR;
+       COMPUTE_DIRECTORY(etc_dir);
+       StripSlashes(etc_dir, 1);
+       snprintf(file_etc_mimelist,
+                sizeof file_etc_mimelist, 
+                "%s/nogz-mimetypes.txt",
+                etc_dir);
+
        /* we should go somewhere we can leave our coredump, if enabled... */
        syslog(LOG_INFO, "Changing directory to %s\n", socket_dir);
        if (chdir(webcitdir) != 0) {
@@ -496,6 +553,9 @@ webcit_calc_dirs_n_files(int relh, const char *basedir, int home, char *webcitdi
 void drop_root(uid_t UID)
 {
        struct passwd pw, *pwp = NULL;
+#ifdef HAVE_GETPWUID_R
+       char pwbuf[SIZ];
+#endif
 
        /*
         * Now that we've bound the sockets, change to the Citadel user id and its