]> code.citadel.org Git - citadel.git/blobdiff - webcit/webserver.c
* iteratorstruct private again
[citadel.git] / webcit / webserver.c
index 5c107f3821094480ffe957903b40804e030eacf7..b89035870b009d1373fce419961e8ed6c0d5d120 100644 (file)
@@ -5,7 +5,7 @@
  * waiting on the specified port for incoming HTTP connections.  When a
  * connection is established, it calls context_loop() from context_loop.c.
  *
- * Copyright (c) 1996-2008 by the citadel.org developers.
+ * Copyright (c) 1996-2009 by the citadel.org developers.
  * This program is released under the terms of the GNU General Public License v3.
  *
  */
@@ -210,7 +210,7 @@ int client_read_to(int *sock, StrBuf *Target, StrBuf *Buf, int bytes, int timeou
                       (retval >= 0))
                        retval = client_read_sslbuffer(Buf, timeout);
                if (retval >= 0) {
-                       StrBufAppendBuf(Target, Buf, 0); /// todo: Buf > bytes?
+                       StrBufAppendBuf(Target, Buf, 0); /* todo: Buf > bytes? */
 #ifdef HTTP_TRACING
                        write(2, "\033[32m", 5);
                        write(2, buf, bytes);
@@ -225,7 +225,7 @@ int client_read_to(int *sock, StrBuf *Target, StrBuf *Buf, int bytes, int timeou
        }
 #endif
 
-       if (StrLength(Buf) > 0) {//// todo: what if Buf > bytes?
+       if (StrLength(Buf) > 0) {/*/// todo: what if Buf > bytes?*/
                StrBufAppendBuf(Target, Buf, 0);
        }
        retval = StrBufReadBLOB(Target, 
@@ -253,8 +253,9 @@ int client_read_to(int *sock, StrBuf *Target, StrBuf *Buf, int bytes, int timeou
  */
 void begin_burst(void)
 {
-       if (WC->WBuf == NULL)
+       if (WC->WBuf == NULL) {
                WC->WBuf = NewStrBufPlain(NULL, 32768);
+       }
 }
 
 
@@ -263,20 +264,20 @@ void begin_burst(void)
  */
 long end_burst(void)
 {
-       struct wcsession *WCC = WC;
+       wcsession *WCC = WC;
         const char *ptr, *eptr;
         long count;
        ssize_t res;
         fd_set wset;
         int fdflags;
 
-#ifdef HAVE_ZLIB
+       //#ifdef HAVE_ZLIB
        /* Perform gzip compression, if enabled and supported by client */
        if (!DisableGzip && (WCC->gzip_ok) && CompressBuffer(WCC->WBuf))
        {
                hprintf("Content-encoding: gzip\r\n");
        }
-#endif /* HAVE_ZLIB */
+       //#endif        /* HAVE_ZLIB */
 
        hprintf("Content-length: %d\r\n\r\n", StrLength(WCC->WBuf));
 
@@ -374,48 +375,6 @@ int client_read(int *sock, StrBuf *Target, StrBuf *buf, int bytes)
 }
 
 
-/*
- * Get a LF-terminated line of text from the client.
- * (This is implemented in terms of client_read() and could be
- * justifiably moved out of sysdep.c)
- *
- * sock                socket fd to get client line from
- * buf         buffer to write read data to
- * bufsiz      how many bytes to read
- *
- * returns the number of bytes read
- */
-/////int client_getln(int *sock, char *buf, int bufsiz)
-/////{
-/////  int i, retval;
-/////
-/////  /* Read one character at a time.*/
-/////  for (i = 0; *sock > 0; i++) {
-/////          retval = client_read(sock, &buf[i], 1);
-/////          if (retval < 0)
-/////                  return retval;
-/////          if (retval != 1 || buf[i] == '\n' || i == (bufsiz-1))
-/////                  break;
-/////          if ( (!isspace(buf[i])) && (!isprint(buf[i])) ) {
-/////                  /* Non printable character recieved from client */
-/////                  return(-1);
-/////          }
-/////  }
-/////
-/////  /* If we got a long line, discard characters until the newline. */
-/////  if (i == (bufsiz-1))
-/////          while (buf[i] != '\n' && retval == 1)
-/////                  retval = client_read(sock, &buf[i], 1);
-/////
-/////  /*
-/////   * Strip any trailing non-printable characters.
-/////   */
-/////  buf[i] = 0;
-/////  while ((i > 0) && (!isprint(buf[i - 1]))) {
-/////          buf[--i] = 0;
-/////  }
-/////  return (retval);
-/////}
 
 /*
  * Shut us down the regular way.
@@ -498,7 +457,6 @@ int ClientGetLine(int *sock, StrBuf *Target, StrBuf *CLineBuf)
  */
 pid_t current_child;
 void graceful_shutdown(int signum) {
-//     kill(current_child, signum);
        char wd[SIZ];
        FILE *FD;
        int fd;
@@ -559,16 +517,12 @@ void start_daemon(char *pid_file)
                        exit(errno);
                }
        
-               else if (current_child == 0) {  // child process
-//                     signal(SIGTERM, graceful_shutdown);
+               else if (current_child == 0) {  /* child process */
                        signal(SIGHUP, graceful_shutdown);
 
                        return; /* continue starting webcit. */
                }
-       
-               else { // watcher process
-//                     signal(SIGTERM, SIG_IGN);
-//                     signal(SIGHUP, SIG_IGN);
+               else { /* watcher process */
                        if (pid_file) {
                                fp = fopen(pid_file, "w");
                                if (fp != NULL) {
@@ -651,11 +605,13 @@ void spawn_another_worker_thread()
        pthread_attr_destroy(&attr);
 }
 
-//#define DBG_PRINNT_HOOKS_AT_START
+/* #define DBG_PRINNT_HOOKS_AT_START */
 #ifdef DBG_PRINNT_HOOKS_AT_START
 const char foobuf[32];
 const char *nix(void *vptr) {snprintf(foobuf, 32, "%0x", (long) vptr); return foobuf;}
 #endif 
+extern int dbg_analyze_msg;
+extern int dbg_bactrace_template_errors;
 void InitTemplateCache(void);
 extern int LoadTemplates;
 extern void LoadZoneFiles(void);
@@ -685,6 +641,8 @@ int main(int argc, char **argv)
 #endif /* ENABLE_NLS */
        char uds_listen_path[PATH_MAX]; /* listen on a unix domain socket? */
 
+       WildFireInitBacktrace(argv[0], 2);
+
        HandlerHash = NewHash(1, NULL);
        PreferenceHooks = NewHash(1, NULL);
        WirelessTemplateCache = NewHash(1, NULL);
@@ -758,6 +716,8 @@ int main(int argc, char **argv)
                        break;
                case 'T':
                        LoadTemplates = atoi(optarg);
+                       dbg_analyze_msg = (LoadTemplates && (1<<1)) != 0;
+                       dbg_bactrace_template_errors = (LoadTemplates && (1<<2)) != 0;
                        break;
                case 'Z':
                        DisableGzip = 1;
@@ -810,13 +770,12 @@ int main(int argc, char **argv)
                start_daemon(pidfile);
        }
        else {
-///            signal(SIGTERM, graceful_shutdown);
                signal(SIGHUP, graceful_shutdown);
        }
 
        /* Tell 'em who's in da house */
        lprintf(1, PACKAGE_STRING "\n");
-       lprintf(1, "Copyright (C) 1996-2008 by the Citadel development team.\n"
+       lprintf(1, "Copyright (C) 1996-2009 by the Citadel development team.\n"
                "This software is distributed under the terms of the "
                "GNU General Public License.\n\n"
        );
@@ -1030,19 +989,19 @@ void worker_entry(void)
                        if (msock > 0)  ret = select(msock+1, &tempset, NULL, NULL,  &tv);
                        end_critical_section(S_SELECT);
                        if ((ret < 0) && (errno != EINTR) && (errno != EAGAIN))
-                       {// EINTR and EAGAIN are thrown but not of interest.
+                       {/* EINTR and EAGAIN are thrown but not of interest. */
                                lprintf(2, "accept() failed:%d %s\n",
                                        errno, strerror(errno));
                        }
                        else if ((ret > 0) && (msock > 0) && FD_ISSET(msock, &tempset))
-                       {// Successfully selected, and still not shutting down? Accept!
+                       {/* Successfully selected, and still not shutting down? Accept! */
                                ssock = accept(msock, NULL, 0);
                        }
                        
                } while ((msock > 0) && (ssock < 0)  && (time_to_die == 0));
 
                if ((msock == -1)||(time_to_die))
-               {// ok, we're going down.
+               {/* ok, we're going down. */
                        int shutdown = 0;
 
                        /* the first to come here will have to do the cleanup.
@@ -1056,11 +1015,11 @@ void worker_entry(void)
                        }
                        end_critical_section(S_SHUTDOWN);
                        if (shutdown == 1)
-                       {// we're the one to cleanup the mess.
+                       {/* we're the one to cleanup the mess. */
                                lprintf(2, "I'm master shutdown: tagging sessions to be killed.\n");
                                shutdown_sessions();
                                lprintf(2, "master shutdown: waiting for others\n");
-                               sleeeeeeeeeep(1); // wait so some others might finish...
+                               sleeeeeeeeeep(1); /* wait so some others might finish... */
                                lprintf(2, "master shutdown: cleaning up sessions\n");
                                do_housekeeping();
                                lprintf(2, "master shutdown: cleaning up libical\n");
@@ -1078,7 +1037,7 @@ void worker_entry(void)
                        if (ssock > 0) close (ssock);
                        lprintf(2, "inbetween.");
                        pthread_exit(NULL);
-               } else { // Got it? do some real work!
+               } else { /* Got it? do some real work! */
                        /* Set the SO_REUSEADDR socket option */
                        i = 1;
                        setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR,