indent -kr -i8 -l132 on everything in webcit-ng
[citadel.git] / webcit-ng / webserver.c
index 25b87ec106feb44974a2790390350107f7bd2399..aaa73ee0ea77edf66ba5cda7e8fa106cf1f694a3 100644 (file)
@@ -29,8 +29,8 @@ static void *original_brk = NULL;     // Remember the original program break so we c
  */
 void spawn_another_worker_thread(int *pointer_to_master_socket)
 {
-       pthread_t th;                                   // Thread descriptor
-       pthread_attr_t attr;                            // Thread attributes
+       pthread_t th;           // Thread descriptor
+       pthread_attr_t attr;    // Thread attributes
 
        /* set attributes for the new thread */
        pthread_attr_init(&attr);
@@ -38,10 +38,9 @@ void spawn_another_worker_thread(int *pointer_to_master_socket)
        pthread_attr_setstacksize(&attr, 1048576);      // Large stacks to prevent MIME parser crash on FreeBSD
 
        /* now create the thread */
-       if (pthread_create(&th, &attr, (void *(*)(void *)) worker_entry, (void *)pointer_to_master_socket) != 0) {
+       if (pthread_create(&th, &attr, (void *(*)(void *)) worker_entry, (void *) pointer_to_master_socket) != 0) {
                syslog(LOG_WARNING, "Can't create thread: %s", strerror(errno));
-       }
-       else {
+       } else {
                ++num_threads_existing;
                ++num_threads_executing;
        }
@@ -61,25 +60,27 @@ void worker_entry(int *pointer_to_master_socket)
        int fail_this_transaction = 0;
        struct client_handle ch;
 
-       while(1) {
+       while (1) {
                /* Each worker thread blocks on accept() while waiting for something to do. */
                memset(&ch, 0, sizeof ch);
-               ch.sock = -1; 
+               ch.sock = -1;
                errno = EAGAIN;
                do {
                        --num_threads_executing;
-                       syslog(LOG_DEBUG, "Additional memory allocated since startup: %d bytes", (int)(sbrk(0)-original_brk));
-                       syslog(LOG_DEBUG, "Thread 0x%x calling accept() on master socket %d", (unsigned int)pthread_self(), master_socket);
+                       syslog(LOG_DEBUG, "Additional memory allocated since startup: %d bytes", (int) (sbrk(0) - original_brk));
+                       syslog(LOG_DEBUG, "Thread 0x%x calling accept() on master socket %d", (unsigned int) pthread_self(),
+                              master_socket);
                        ch.sock = accept(master_socket, NULL, 0);
                        if (ch.sock < 0) {
                                syslog(LOG_DEBUG, "accept() : %s", strerror(errno));
                        }
                        ++num_threads_executing;
-                       syslog(LOG_DEBUG, "socket %d is awake , threads executing: %d , threads total: %d", ch.sock, num_threads_executing, num_threads_existing);
+                       syslog(LOG_DEBUG, "socket %d is awake , threads executing: %d , threads total: %d", ch.sock,
+                              num_threads_executing, num_threads_existing);
                } while ((master_socket > 0) && (ch.sock < 0));
 
                /* If all threads are executing, spawn more, up to the maximum */
-               if ( (num_threads_executing >= num_threads_existing) && (num_threads_existing <= MAX_WORKER_THREADS) ) {
+               if ((num_threads_executing >= num_threads_existing) && (num_threads_existing <= MAX_WORKER_THREADS)) {
                        spawn_another_worker_thread(pointer_to_master_socket);
                }
 
@@ -95,10 +96,8 @@ void worker_entry(int *pointer_to_master_socket)
                        if (ch.ssl_handle == NULL) {
                                fail_this_transaction = 1;
                        }
-               }
-               else 
-               {
-                       int fdflags; 
+               } else {
+                       int fdflags;
                        fdflags = fcntl(ch.sock, F_GETFL);
                        if (fdflags < 0) {
                                syslog(LOG_WARNING, "unable to get server socket flags! %s", strerror(errno));
@@ -128,33 +127,33 @@ void worker_entry(int *pointer_to_master_socket)
  */
 int webserver(char *webserver_interface, int webserver_port, int webserver_protocol)
 {
-       int master_socket = (-1) ;
+       int master_socket = (-1);
        original_brk = sbrk(0);
 
-       switch(webserver_protocol) {
-               case WEBSERVER_HTTP:
-                       syslog(LOG_DEBUG, "Starting HTTP server on %s:%d", webserver_interface, webserver_port);
-                       master_socket = webcit_tcp_server(webserver_interface, webserver_port, 10);
-                       break;
-               case WEBSERVER_HTTPS:
-                       syslog(LOG_DEBUG, "Starting HTTPS server on %s:%d", webserver_interface, webserver_port);
-                       master_socket = webcit_tcp_server(webserver_interface, webserver_port, 10);
-                       init_ssl();
-                       is_https = 1;
-                       break;
-               default:
-                       syslog(LOG_ERR, "unknown protocol");
-                       ;;
+       switch (webserver_protocol) {
+       case WEBSERVER_HTTP:
+               syslog(LOG_DEBUG, "Starting HTTP server on %s:%d", webserver_interface, webserver_port);
+               master_socket = webcit_tcp_server(webserver_interface, webserver_port, 10);
+               break;
+       case WEBSERVER_HTTPS:
+               syslog(LOG_DEBUG, "Starting HTTPS server on %s:%d", webserver_interface, webserver_port);
+               master_socket = webcit_tcp_server(webserver_interface, webserver_port, 10);
+               init_ssl();
+               is_https = 1;
+               break;
+       default:
+               syslog(LOG_ERR, "unknown protocol");
+               ;;
        }
 
        if (master_socket < 1) {
                syslog(LOG_ERR, "Unable to bind the web server listening socket");
-               return(1);
+               return (1);
        }
 
        syslog(LOG_INFO, "Listening on socket %d", master_socket);
        signal(SIGPIPE, SIG_IGN);
 
-       worker_entry(&master_socket);                   // this thread becomes a worker
-       return(0);
+       worker_entry(&master_socket);   // this thread becomes a worker
+       return (0);
 }