* cleanup shutdown procedure; free all structures and their properties
[citadel.git] / webcit / webserver.c
index 56a34eb063d819be8435bedf38d7165f461987c8..36c64a5f4155863c1dc82c815361cb49216de463 100644 (file)
@@ -242,7 +242,8 @@ int client_read_to(int sock, char *buf, int bytes, int timeout)
  */
 void begin_burst(void)
 {
-       WC->WBuf = NewStrBufPlain(NULL, 32768);
+       if (WC->WBuf == NULL)
+               WC->WBuf = NewStrBufPlain(NULL, 32768);
 }
 
 
@@ -274,7 +275,8 @@ long end_burst(void)
 
 #ifdef HAVE_OPENSSL
        if (is_https) {
-               client_write_ssl(ptr, StrLength(WCC->HBuf));
+               client_write_ssl(WCC->HBuf);
+               client_write_ssl(WCC->WBuf);
                return (count);
        }
 #endif
@@ -288,7 +290,7 @@ long end_burst(void)
 #endif
        fdflags = fcntl(WC->http_sock, F_GETFL);
 
-        while (ptr < eptr) {
+       while (ptr < eptr) {
                 if ((fdflags & O_NONBLOCK) == O_NONBLOCK) {
                         FD_ZERO(&wset);
                         FD_SET(WCC->http_sock, &wset);
@@ -312,13 +314,6 @@ long end_burst(void)
        count = StrLength(WCC->WBuf);
        eptr = ptr + count;
 
-#ifdef HAVE_OPENSSL
-       if (is_https) {
-               client_write_ssl(ptr, StrLength(WCC->HBuf));
-               return (count);
-       }
-#endif
-
 #ifdef HTTP_TRACING
        
        write(2, "\033[34m", 5);
@@ -586,7 +581,9 @@ void spawn_another_worker_thread()
 const char foobuf[32];
 const char *nix(void *vptr) {snprintf(foobuf, 32, "%0x", (long) vptr); return foobuf;}
 #endif 
+void InitTemplateCache(void);
 
+extern void LoadZoneFiles(void);
 /*
  * \brief Here's where it all begins.
  * \param argc number of commandline args
@@ -615,7 +612,16 @@ int main(int argc, char **argv)
        char uds_listen_path[PATH_MAX]; /*< listen on a unix domain socket? */
 
        HandlerHash = NewHash(1, NULL);
-       initialise_modules();
+       PreferenceHooks = NewHash(1, NULL);
+       WirelessTemplateCache = NewHash(1, NULL);
+       WirelessLocalTemplateCache = NewHash(1, NULL);
+       LocalTemplateCache = NewHash(1, NULL);
+       TemplateCache = NewHash(1, NULL);
+       GlobalNS = NewHash(1, NULL);
+       Iterators = NewHash(1, NULL);
+       Contitionals = NewHash(1, NULL);
+       LoadZoneFiles();
+
 
 #ifdef DBG_PRINNT_HOOKS_AT_START
        dbg_PrintHash(HandlerHash, nix, NULL);
@@ -787,6 +793,9 @@ int main(int argc, char **argv)
                perror("chdir");
        }
        LoadIconDir(static_icon_dir);
+       InitTemplateCache();
+
+       initialise_modules();
        initialize_viewdefs();
        initialize_axdefs();
 
@@ -859,10 +868,32 @@ int main(int argc, char **argv)
        worker_entry();
        ShutDownLibCitadel ();
        DeleteHash(&HandlerHash);
+       DeleteHash(&PreferenceHooks);
        return 0;
 }
 
 
+void ShutDownWebcit(void)
+{
+       DeleteHash(&ZoneHash);
+       free_zone_directory ();
+       icaltimezone_release_zone_tab ();
+       icalmemory_free_ring ();
+       ShutDownLibCitadel ();
+       DeleteHash(&HandlerHash);
+       DeleteHash(&PreferenceHooks);
+       DeleteHash(&GlobalNS);
+       DeleteHash(&WirelessTemplateCache);
+       DeleteHash(&WirelessLocalTemplateCache);
+       DeleteHash(&TemplateCache);
+       DeleteHash(&LocalTemplateCache);
+       DeleteHash(&Iterators);
+       DeleteHash(&Contitionals);
+#ifdef ENABLE_NLS
+       ShutdownLocale();
+#endif
+}
+
 /*
  * Entry point for worker threads
  */
@@ -930,10 +961,9 @@ void worker_entry(void)
                                lprintf(2, "master shutdown: cleaning up sessions\n");
                                do_housekeeping();
                                lprintf(2, "master shutdown: cleaning up libical\n");
-                               free_zone_directory ();
-                               icaltimezone_release_zone_tab ();
-                               icalmemory_free_ring ();
-                               ShutDownLibCitadel ();
+
+                               ShutDownWebcit();
+
                                lprintf(2, "master shutdown exiting!.\n");                              
                                exit(0);
                        }