4 * This contains a simple multithreaded TCP server manager. It sits around
5 * waiting on the specified port for incoming HTTP connections. When a
6 * connection is established, it calls context_loop() from context_loop.c.
8 * Copyright (c) 1996-2008 by the citadel.org developers.
9 * This program is released under the terms of the GNU General Public License v3.
14 #include "webserver.h"
19 #include "modules_init.h"
21 int vsnprintf(char *buf, size_t max, const char *fmt, va_list argp);
24 int verbosity = 9; /* Logging level */
25 int msock; /* master listening socket */
26 int is_https = 0; /* Nonzero if I am an HTTPS service */
27 int follow_xff = 0; /* Follow X-Forwarded-For: header */
28 int home_specified = 0; /* did the user specify a homedir? */
29 int time_to_die = 0; /* Nonzero if server is shutting down */
30 extern void *context_loop(int*);
31 extern void *housekeeping_loop(void);
32 extern pthread_mutex_t SessionListMutex;
33 extern pthread_key_t MyConKey;
36 char ctdl_key_dir[PATH_MAX]=SSL_DIR;
37 char file_crpt_file_key[PATH_MAX]="";
38 char file_crpt_file_csr[PATH_MAX]="";
39 char file_crpt_file_cer[PATH_MAX]="";
41 char socket_dir[PATH_MAX]; /* where to talk to our citadel server */
42 static const char editor_absolut_dir[PATH_MAX]=EDITORDIR; /* nailed to what configure gives us. */
43 static char static_dir[PATH_MAX]; /* calculated on startup */
44 static char static_local_dir[PATH_MAX]; /* calculated on startup */
45 static char static_icon_dir[PATH_MAX]; /* where should we find our mime icons? */
46 char *static_dirs[]={ /* needs same sort order as the web mapping */
47 (char*)static_dir, /* our templates on disk */
48 (char*)static_local_dir, /* user provided templates disk */
49 (char*)editor_absolut_dir, /* the editor on disk */
50 (char*)static_icon_dir /* our icons... */
54 * Subdirectories from which the client may request static content
56 * (If you add more, remember to increment 'ndirs' below)
58 char *static_content_dirs[] = {
59 "static", /* static templates */
60 "static.local", /* site local static templates */
61 "tiny_mce" /* rich text editor */
67 char *server_cookie = NULL; /* our Cookie connection to the client */
68 int http_port = PORT_NUM; /* Port to listen on */
69 char *ctdlhost = DEFAULT_HOST; /* our name */
70 char *ctdlport = DEFAULT_PORT; /* our Port */
71 int setup_wizard = 0; /* should we run the setup wizard? \todo */
72 char wizard_filename[PATH_MAX]; /* where's the setup wizard? */
73 int running_as_daemon = 0; /* should we deamonize on startup? */
77 * This is a generic function to set up a master socket for listening on
78 * a TCP port. The server shuts down if the bind fails.
80 * ip_addr IP address to bind
81 * port_number port number to bind
82 * queue_len number of incoming connections to allow in the queue
84 int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
86 struct sockaddr_in sin;
89 memset(&sin, 0, sizeof(sin));
90 sin.sin_family = AF_INET;
91 if (ip_addr == NULL) {
92 sin.sin_addr.s_addr = INADDR_ANY;
94 sin.sin_addr.s_addr = inet_addr(ip_addr);
97 if (sin.sin_addr.s_addr == INADDR_NONE) {
98 sin.sin_addr.s_addr = INADDR_ANY;
101 if (port_number == 0) {
102 lprintf(1, "Cannot start: no port number specified.\n");
105 sin.sin_port = htons((u_short) port_number);
107 s = socket(PF_INET, SOCK_STREAM, (getprotobyname("tcp")->p_proto));
109 lprintf(1, "Can't create a socket: %s\n", strerror(errno));
112 /* Set some socket options that make sense. */
114 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
116 fcntl(s, F_SETFL, O_NONBLOCK); /* maide: this statement is incorrect
117 there should be a preceding F_GETFL
118 and a bitwise OR with the previous
121 if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
122 lprintf(1, "Can't bind: %s\n", strerror(errno));
125 if (listen(s, queue_len) < 0) {
126 lprintf(1, "Can't listen: %s\n", strerror(errno));
135 * Create a Unix domain socket and listen on it
136 * sockpath - file name of the unix domain socket
137 * queue_len - Number of incoming connections to allow in the queue
139 int ig_uds_server(char *sockpath, int queue_len)
141 struct sockaddr_un addr;
144 int actual_queue_len;
146 actual_queue_len = queue_len;
147 if (actual_queue_len < 5) actual_queue_len = 5;
149 i = unlink(sockpath);
150 if (i != 0) if (errno != ENOENT) {
151 lprintf(1, "webcit: can't unlink %s: %s\n",
152 sockpath, strerror(errno));
156 memset(&addr, 0, sizeof(addr));
157 addr.sun_family = AF_UNIX;
158 safestrncpy(addr.sun_path, sockpath, sizeof addr.sun_path);
160 s = socket(AF_UNIX, SOCK_STREAM, 0);
162 lprintf(1, "webcit: Can't create a socket: %s\n",
167 if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
168 lprintf(1, "webcit: Can't bind: %s\n",
173 if (listen(s, actual_queue_len) < 0) {
174 lprintf(1, "webcit: Can't listen: %s\n",
179 chmod(sockpath, 0777);
187 * Read data from the client socket.
189 * sock socket fd to read from
190 * buf buffer to read into
191 * bytes number of bytes to read
192 * timeout Number of seconds to wait before timing out
194 * Possible return values:
195 * 1 Requested number of bytes has been read.
196 * 0 Request timed out.
197 * -1 Connection is broken, or other error.
199 int client_read_to(int *sock, char *buf, int bytes, int timeout)
209 return (client_read_ssl(buf, bytes, timeout));
214 while ((len < bytes) && (*sock > 0)) {
216 FD_SET(*sock, &rfds);
220 retval = select((*sock) + 1, &rfds, NULL, NULL, &tv);
221 if (FD_ISSET(*sock, &rfds) == 0) {
225 rlen = read(*sock, &buf[len], bytes - len);
228 lprintf(2, "client_read() failed: %s\n",
239 write(2, "\033[32m", 5);
240 write(2, buf, bytes);
241 write(2, "\033[30m", 5);
248 * Begin buffering HTTP output so we can transmit it all in one write operation later.
250 void begin_burst(void)
252 if (WC->WBuf == NULL)
253 WC->WBuf = NewStrBufPlain(NULL, 32768);
258 * Finish buffering HTTP output. [Compress using zlib and] output with a Content-Length: header.
262 struct wcsession *WCC = WC;
263 const char *ptr, *eptr;
270 /* Perform gzip compression, if enabled and supported by client */
271 if ((WCC->gzip_ok) && CompressBuffer(WCC->WBuf))
273 hprintf("Content-encoding: gzip\r\n");
275 #endif /* HAVE_ZLIB */
277 hprintf("Content-length: %d\r\n\r\n", StrLength(WCC->WBuf));
279 ptr = ChrPtr(WCC->HBuf);
280 count = StrLength(WCC->HBuf);
285 client_write_ssl(WCC->HBuf);
286 client_write_ssl(WCC->WBuf);
294 write(2, "\033[34m", 5);
295 write(2, ptr, StrLength(WCC->WBuf));
296 write(2, "\033[30m", 5);
298 fdflags = fcntl(WC->http_sock, F_GETFL);
301 if ((fdflags & O_NONBLOCK) == O_NONBLOCK) {
303 FD_SET(WCC->http_sock, &wset);
304 if (select(WCC->http_sock + 1, NULL, &wset, NULL, NULL) == -1) {
305 lprintf(2, "client_write: Socket select failed (%s)\n", strerror(errno));
310 if ((res = write(WCC->http_sock,
313 lprintf(2, "client_write: Socket write failed (%s)\n", strerror(errno));
321 ptr = ChrPtr(WCC->WBuf);
322 count = StrLength(WCC->WBuf);
327 write(2, "\033[34m", 5);
328 write(2, ptr, StrLength(WCC->WBuf));
329 write(2, "\033[30m", 5);
333 if ((fdflags & O_NONBLOCK) == O_NONBLOCK) {
335 FD_SET(WCC->http_sock, &wset);
336 if (select(WCC->http_sock + 1, NULL, &wset, NULL, NULL) == -1) {
337 lprintf(2, "client_write: Socket select failed (%s)\n", strerror(errno));
342 if ((res = write(WCC->http_sock,
345 lprintf(2, "client_write: Socket write failed (%s)\n", strerror(errno));
353 return StrLength(WCC->WBuf);
359 * Read data from the client socket with default timeout.
360 * (This is implemented in terms of client_read_to() and could be
361 * justifiably moved out of sysdep.c)
363 * sock the socket fd to read from
364 * buf the buffer to write to
365 * bytes Number of bytes to read
367 int client_read(int *sock, char *buf, int bytes)
369 return (client_read_to(sock, buf, bytes, SLEEPING));
374 * Get a LF-terminated line of text from the client.
375 * (This is implemented in terms of client_read() and could be
376 * justifiably moved out of sysdep.c)
378 * sock socket fd to get client line from
379 * buf buffer to write read data to
380 * bufsiz how many bytes to read
382 * returns the number of bytes read
384 int client_getln(int *sock, char *buf, int bufsiz)
389 /* Read one character at a time.*/
390 for (i = 0; *sock > 0; i++) {
391 retval = client_read(sock, &buf[i], 1);
394 if (retval != 1 || buf[i] == '\n' || i == (bufsiz-1))
396 if ( (!isspace(buf[i])) && (!isprint(buf[i])) ) {
397 /* Non printable character recieved from client */
402 /* If we got a long line, discard characters until the newline. */
404 while (buf[i] != '\n' && retval == 1)
405 retval = client_read(sock, &buf[i], 1);
408 * Strip any trailing non-printable characters.
411 while ((i > 0) && (!isprint(buf[i - 1]))) {
418 * Shut us down the regular way.
419 * signum is the signal we want to forward
422 void graceful_shutdown_watcher(int signum) {
423 lprintf (1, "bye; shutting down watcher.");
424 kill(current_child, signum);
425 if (signum != SIGHUP)
430 * Shut us down the regular way.
431 * signum is the signal we want to forward
434 void graceful_shutdown(int signum) {
435 // kill(current_child, signum);
440 lprintf (1, "bye going down gracefull.[%d][%s]\n", signum, wd);
452 * Start running as a daemon.
454 void start_daemon(char *pid_file)
463 /* Close stdin/stdout/stderr and replace them with /dev/null.
464 * We don't just call close() because we don't want these fd's
465 * to be reused for other files.
469 signal(SIGHUP, SIG_IGN);
470 signal(SIGINT, SIG_IGN);
471 signal(SIGQUIT, SIG_IGN);
480 freopen("/dev/null", "r", stdin);
481 freopen("/dev/null", "w", stdout);
482 freopen("/dev/null", "w", stderr);
483 signal(SIGTERM, graceful_shutdown_watcher);
484 signal(SIGHUP, graceful_shutdown_watcher);
487 current_child = fork();
490 if (current_child < 0) {
492 ShutDownLibCitadel ();
496 else if (current_child == 0) { // child process
497 // signal(SIGTERM, graceful_shutdown);
498 signal(SIGHUP, graceful_shutdown);
500 return; /* continue starting webcit. */
503 else { // watcher process
504 // signal(SIGTERM, SIG_IGN);
505 // signal(SIGHUP, SIG_IGN);
507 fp = fopen(pid_file, "w");
509 fprintf(fp, "%d\n", getpid());
513 waitpid(current_child, &status, 0);
518 /* Did the main process exit with an actual exit code? */
519 if (WIFEXITED(status)) {
521 /* Exit code 0 means the watcher should exit */
522 if (WEXITSTATUS(status) == 0) {
526 /* Exit code 101-109 means the watcher should exit */
527 else if ( (WEXITSTATUS(status) >= 101) && (WEXITSTATUS(status) <= 109) ) {
531 /* Any other exit code means we should restart. */
537 /* Any other type of termination (signals, etc.) should also restart. */
542 } while (do_restart);
547 ShutDownLibCitadel ();
548 exit(WEXITSTATUS(status));
552 * Spawn an additional worker thread into the pool.
554 void spawn_another_worker_thread()
556 pthread_t SessThread; /* Thread descriptor */
557 pthread_attr_t attr; /* Thread attributes */
560 lprintf(3, "Creating a new thread\n");
562 /* set attributes for the new thread */
563 pthread_attr_init(&attr);
564 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
567 * Our per-thread stacks need to be bigger than the default size, otherwise
568 * the MIME parser crashes on FreeBSD, and the IMAP service crashes on
571 if ((ret = pthread_attr_setstacksize(&attr, 1024 * 1024))) {
572 lprintf(1, "pthread_attr_setstacksize: %s\n",
574 pthread_attr_destroy(&attr);
577 /* now create the thread */
578 if (pthread_create(&SessThread, &attr,
579 (void *(*)(void *)) worker_entry, NULL)
581 lprintf(1, "Can't create thread: %s\n", strerror(errno));
584 /* free up the attributes */
585 pthread_attr_destroy(&attr);
588 //#define DBG_PRINNT_HOOKS_AT_START
589 #ifdef DBG_PRINNT_HOOKS_AT_START
590 const char foobuf[32];
591 const char *nix(void *vptr) {snprintf(foobuf, 32, "%0x", (long) vptr); return foobuf;}
593 void InitTemplateCache(void);
594 extern int LoadTemplates;
595 extern void LoadZoneFiles(void);
598 * Here's where it all begins.
600 int main(int argc, char **argv)
602 pthread_t SessThread; /* Thread descriptor */
603 pthread_attr_t attr; /* Thread attributes */
604 int a, i; /* General-purpose variables */
605 char tracefile[PATH_MAX];
606 char ip_addr[256]="0.0.0.0";
607 char dirbuffer[PATH_MAX]="";
610 int home_specified=0;
611 char relhome[PATH_MAX]="";
612 char webcitdir[PATH_MAX] = DATADIR;
613 char *pidfile = NULL;
619 #endif /* ENABLE_NLS */
620 char uds_listen_path[PATH_MAX]; /* listen on a unix domain socket? */
622 HandlerHash = NewHash(1, NULL);
623 PreferenceHooks = NewHash(1, NULL);
624 WirelessTemplateCache = NewHash(1, NULL);
625 WirelessLocalTemplateCache = NewHash(1, NULL);
626 LocalTemplateCache = NewHash(1, NULL);
627 TemplateCache = NewHash(1, NULL);
628 GlobalNS = NewHash(1, NULL);
629 Iterators = NewHash(1, NULL);
630 Contitionals = NewHash(1, NULL);
634 #ifdef DBG_PRINNT_HOOKS_AT_START
635 dbg_PrintHash(HandlerHash, nix, NULL);
638 /* Ensure that we are linked to the correct version of libcitadel */
639 if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
640 fprintf(stderr, " You are running libcitadel version %d.%02d\n",
641 (libcitadel_version_number() / 100), (libcitadel_version_number() % 100));
642 fprintf(stderr, "WebCit was compiled against version %d.%02d\n",
643 (LIBCITADEL_VERSION_NUMBER / 100), (LIBCITADEL_VERSION_NUMBER % 100));
647 strcpy(uds_listen_path, "");
649 /* Parse command line */
651 while ((a = getopt(argc, argv, "h:i:p:t:T:x:dD:cfs")) != EOF)
653 while ((a = getopt(argc, argv, "h:i:p:t:T:x:dD:cf")) != EOF)
657 hdir = strdup(optarg);
659 if (!relh) safestrncpy(webcitdir, hdir,
662 safestrncpy(relhome, relhome,
664 /* free(hdir); TODO: SHOULD WE DO THIS? */
669 running_as_daemon = 1;
672 pidfile = strdup(optarg);
673 running_as_daemon = 1;
676 safestrncpy(ip_addr, optarg, sizeof ip_addr);
679 http_port = atoi(optarg);
680 if (http_port == 0) {
681 safestrncpy(uds_listen_path, optarg, sizeof uds_listen_path);
685 safestrncpy(tracefile, optarg, sizeof tracefile);
686 freopen(tracefile, "w", stdout);
687 freopen(tracefile, "w", stderr);
688 freopen(tracefile, "r", stdin);
691 LoadTemplates = atoi(optarg);
694 verbosity = atoi(optarg);
700 server_cookie = malloc(256);
701 if (server_cookie != NULL) {
702 safestrncpy(server_cookie,
703 "Set-cookie: wcserver=",
706 (&server_cookie[strlen(server_cookie)],
708 lprintf(2, "gethostname: %s\n",
718 fprintf(stderr, "usage: webcit "
719 "[-i ip_addr] [-p http_port] "
720 "[-t tracefile] [-c] [-f] "
721 "[-T Templatedebuglevel] "
726 "[remotehost [remoteport]]\n");
731 ctdlhost = argv[optind];
733 ctdlport = argv[optind];
736 /* daemonize, if we were asked to */
737 if (running_as_daemon) {
738 start_daemon(pidfile);
741 /// signal(SIGTERM, graceful_shutdown);
742 signal(SIGHUP, graceful_shutdown);
745 /* Tell 'em who's in da house */
746 lprintf(1, PACKAGE_STRING "\n");
747 lprintf(1, "Copyright (C) 1996-2008 by the Citadel development team.\n"
748 "This software is distributed under the terms of the "
749 "GNU General Public License.\n\n"
753 /* initialize the International Bright Young Thing */
755 initialize_locales();
757 locale = setlocale(LC_ALL, "");
759 mo = malloc(strlen(webcitdir) + 20);
760 lprintf(9, "Message catalog directory: %s\n", bindtextdomain("webcit", LOCALEDIR"/locale"));
762 lprintf(9, "Text domain: %s\n", textdomain("webcit"));
763 lprintf(9, "Text domain Charset: %s\n", bind_textdomain_codeset("webcit","UTF8"));
768 /* calculate all our path on a central place */
769 /* where to keep our config */
771 #define COMPUTE_DIRECTORY(SUBDIR) memcpy(dirbuffer,SUBDIR, sizeof dirbuffer);\
772 snprintf(SUBDIR,sizeof SUBDIR, "%s%s%s%s%s%s%s", \
773 (home&!relh)?webcitdir:basedir, \
774 ((basedir!=webcitdir)&(home&!relh))?basedir:"/", \
775 ((basedir!=webcitdir)&(home&!relh))?"/":"", \
777 (relhome[0]!='\0')?"/":"",\
779 (dirbuffer[0]!='\0')?"/":"");
781 COMPUTE_DIRECTORY(socket_dir);
782 basedir=WWWDIR "/static";
783 COMPUTE_DIRECTORY(static_dir);
784 basedir=WWWDIR "/static/icons";
785 COMPUTE_DIRECTORY(static_icon_dir);
786 basedir=WWWDIR "/static.local";
787 COMPUTE_DIRECTORY(static_local_dir);
789 snprintf(file_crpt_file_key,
790 sizeof file_crpt_file_key,
793 snprintf(file_crpt_file_csr,
794 sizeof file_crpt_file_csr,
797 snprintf(file_crpt_file_cer,
798 sizeof file_crpt_file_cer,
802 /* we should go somewhere we can leave our coredump, if enabled... */
803 lprintf(9, "Changing directory to %s\n", socket_dir);
804 if (chdir(webcitdir) != 0) {
807 LoadIconDir(static_icon_dir);
810 initialise_modules();
811 initialize_viewdefs();
814 /* Tell libical to return an error instead of aborting if it sees badly formed iCalendar data. */
815 icalerror_errors_are_fatal = 0;
818 * Set up a place to put thread-specific data.
819 * We only need a single pointer per thread - it points to the
820 * wcsession struct to which the thread is currently bound.
822 if (pthread_key_create(&MyConKey, NULL) != 0) {
823 lprintf(1, "Can't create TSD key: %s\n", strerror(errno));
825 InitialiseSemaphores ();
828 * Set up a place to put thread-specific SSL data.
829 * We don't stick this in the wcsession struct because SSL starts
830 * up before the session is bound, and it gets torn down between
834 if (pthread_key_create(&ThreadSSL, NULL) != 0) {
835 lprintf(1, "Can't create TSD key: %s\n", strerror(errno));
840 * Bind the server to our favorite port.
841 * There is no need to check for errors, because ig_tcp_server()
842 * exits if it doesn't succeed.
845 if (!IsEmptyStr(uds_listen_path)) {
846 lprintf(2, "Attempting to create listener socket at %s...\n", uds_listen_path);
847 msock = ig_uds_server(uds_listen_path, LISTEN_QUEUE_LENGTH);
850 lprintf(2, "Attempting to bind to port %d...\n", http_port);
851 msock = ig_tcp_server(ip_addr, http_port, LISTEN_QUEUE_LENGTH);
854 lprintf(2, "Listening on socket %d\n", msock);
855 signal(SIGPIPE, SIG_IGN);
857 pthread_mutex_init(&SessionListMutex, NULL);
860 * Start up the housekeeping thread
862 pthread_attr_init(&attr);
863 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
864 pthread_create(&SessThread, &attr,
865 (void *(*)(void *)) housekeeping_loop, NULL);
869 * If this is an HTTPS server, fire up SSL
877 /* Start a few initial worker threads */
878 for (i = 0; i < (MIN_WORKER_THREADS); ++i) {
879 spawn_another_worker_thread();
882 /* now the original thread becomes another worker */
884 ShutDownLibCitadel ();
885 DeleteHash(&HandlerHash);
886 DeleteHash(&PreferenceHooks);
891 void ShutDownWebcit(void)
893 DeleteHash(&ZoneHash);
894 free_zone_directory ();
895 icaltimezone_release_zone_tab ();
896 icalmemory_free_ring ();
897 ShutDownLibCitadel ();
898 DeleteHash(&HandlerHash);
899 DeleteHash(&PreferenceHooks);
900 DeleteHash(&GlobalNS);
901 DeleteHash(&WirelessTemplateCache);
902 DeleteHash(&WirelessLocalTemplateCache);
903 DeleteHash(&TemplateCache);
904 DeleteHash(&LocalTemplateCache);
905 DeleteHash(&Iterators);
906 DeleteHash(&Contitionals);
918 * Entry point for worker threads
920 void worker_entry(void)
924 int fail_this_transaction = 0;
927 fd_set readset, tempset;
932 FD_SET(msock, &readset);
935 /* Only one thread can accept at a time */
936 fail_this_transaction = 0;
940 ret = -1; /* just one at once should select... */
941 begin_critical_section(S_SELECT);
944 if (msock > 0) FD_SET(msock, &tempset);
947 if (msock > 0) ret = select(msock+1, &tempset, NULL, NULL, &tv);
948 end_critical_section(S_SELECT);
949 if ((ret < 0) && (errno != EINTR) && (errno != EAGAIN))
950 {// EINTR and EAGAIN are thrown but not of interest.
951 lprintf(2, "accept() failed:%d %s\n",
952 errno, strerror(errno));
954 else if ((ret > 0) && (msock > 0) && FD_ISSET(msock, &tempset))
955 {// Successfully selected, and still not shutting down? Accept!
956 ssock = accept(msock, NULL, 0);
959 } while ((msock > 0) && (ssock < 0) && (time_to_die == 0));
961 if ((msock == -1)||(time_to_die))
962 {// ok, we're going down.
965 /* the first to come here will have to do the cleanup.
966 * make shure its realy just one.
968 begin_critical_section(S_SHUTDOWN);
974 end_critical_section(S_SHUTDOWN);
976 {// we're the one to cleanup the mess.
977 lprintf(2, "I'm master shutdown: tagging sessions to be killed.\n");
979 lprintf(2, "master shutdown: waiting for others\n");
980 sleeeeeeeeeep(1); // wait so some others might finish...
981 lprintf(2, "master shutdown: cleaning up sessions\n");
983 lprintf(2, "master shutdown: cleaning up libical\n");
987 lprintf(2, "master shutdown exiting!.\n");
992 if (ssock < 0 ) continue;
995 if (ssock > 0) close (ssock);
996 lprintf(2, "inbetween.");
998 } else { // Got it? do some real work!
999 /* Set the SO_REUSEADDR socket option */
1001 setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR,
1004 /* If we are an HTTPS server, go crypto now. */
1007 if (starttls(ssock) != 0) {
1008 fail_this_transaction = 1;
1014 if (fail_this_transaction == 0) {
1016 /* Perform an HTTP transaction... */
1017 context_loop(&ssock);
1019 /* Shut down SSL/TLS if required... */
1026 /* ...and close the socket. */
1028 lingering_close(ssock);
1033 } while (!time_to_die);
1035 lprintf (1, "bye\n");
1040 * print log messages
1041 * logs to stderr if loglevel is lower than the verbosity set at startup
1043 * loglevel level of the message
1044 * format the printf like format string
1045 * ... the strings to put into format
1047 int lprintf(int loglevel, const char *format, ...)
1051 if (loglevel <= verbosity) {
1052 va_start(ap, format);
1053 vfprintf(stderr, format, ap);
1062 * print the actual stack frame.
1064 void wc_backtrace(void)
1066 #ifdef HAVE_BACKTRACE
1067 void *stack_frames[50];
1072 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
1073 strings = backtrace_symbols(stack_frames, size);
1074 for (i = 0; i < size; i++) {
1075 if (strings != NULL)
1076 lprintf(1, "%s\n", strings[i]);
1078 lprintf(1, "%p\n", stack_frames[i]);