int verbosity = 9; /* Logging level */
int msock; /* master listening socket */
+int is_https = 0; /* Nonzero if I am an HTTPS service */
extern void *context_loop(int);
extern void *housekeeping_loop(void);
extern pthread_mutex_t SessionListMutex;
char *server_cookie = NULL;
-char *defaulthost = DEFAULT_HOST;
-char *defaultport = DEFAULT_PORT;
-
-pthread_mutex_t AcceptQueue;
+char *ctdlhost = DEFAULT_HOST;
+char *ctdlport = DEFAULT_PORT;
/*
* This is a generic function to set up a master socket for listening on
char tracefile[PATH_MAX];
/* Parse command line */
+#ifdef HAVE_OPENSSL
+ while ((a = getopt(argc, argv, "hp:t:cs")) != EOF)
+#else
while ((a = getopt(argc, argv, "hp:t:c")) != EOF)
+#endif
switch (a) {
case 'p':
port = atoi(optarg);
}
}
break;
+ case 's':
+ is_https = 1;
+ break;
default:
fprintf(stderr, "usage: webserver [-p localport] "
"[-t tracefile] [-c] "
+#ifdef HAVE_OPENSSL
+ "[-s] "
+#endif
"[remotehost [remoteport]]\n");
return 1;
}
if (optind < argc) {
- defaulthost = argv[optind];
+ ctdlhost = argv[optind];
if (++optind < argc)
- defaultport = argv[optind];
+ ctdlport = argv[optind];
}
/* Tell 'em who's in da house */
lprintf(1, SERVER "\n"
-"Copyright (C) 1996-2002 by the Citadel/UX development team.\n"
+"Copyright (C) 1996-2004 by the Citadel/UX development team.\n"
"This software is distributed under the terms of the GNU General Public\n"
"License. If you paid for this software, someone is ripping you off.\n\n");
signal(SIGPIPE, SIG_IGN);
pthread_mutex_init(&SessionListMutex, NULL);
- pthread_mutex_init(&AcceptQueue, NULL);
/*
* Start up the housekeeping thread
(void *(*)(void *)) housekeeping_loop, NULL);
+ /*
+ * If this is an HTTPS server, fire up SSL
+ */
+#ifdef HAVE_OPENSSL
+ if (is_https) {
+ init_ssl();
+ }
+#endif
+
/* Start a few initial worker threads */
- for (i=0; i<(INITIAL_WORKER_THREADS); ++i) {
+ for (i=0; i<(MIN_WORKER_THREADS); ++i) {
spawn_another_worker_thread();
}
- /* now the original thread can go away. */
- pthread_exit(NULL);
+ /* now the original thread becomes another worker */
+ worker_entry();
return 0;
}
*/
void worker_entry(void) {
int ssock;
- struct sockaddr_in fsin;
- int alen;
int i = 0;
int time_to_die = 0;
- time_t start_time, stop_time;
+ int fail_this_transaction = 0;
do {
/* Only one thread can accept at a time */
- start_time = time(NULL);
- pthread_mutex_lock(&AcceptQueue);
- ssock = accept(msock, (struct sockaddr *) &fsin, &alen);
- pthread_mutex_unlock(&AcceptQueue);
- stop_time = time(NULL);
-
- /* Augment the thread pool if we're not blocking at all */
- if ( (stop_time - start_time) == 0L) {
- spawn_another_worker_thread();
- }
-
+ fail_this_transaction = 0;
+ ssock = accept(msock, NULL, 0);
if (ssock < 0) {
lprintf(2, "accept() failed: %s\n", strerror(errno));
} else {
setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR,
&i, sizeof(i));
+ /* If we are an HTTPS server, go crypto now. */
+#ifdef HAVE_OPENSSL
+ if (is_https) {
+ if (starttls() != 0) {
+ fail_this_transaction = 1;
+ }
+ }
+#endif
+
/* Perform an HTTP transaction... */
- context_loop(ssock);
+ if (fail_this_transaction == 0) {
+ context_loop(ssock);
+ }
/* ...and close the socket. */
lingering_close(ssock);
struct tm *tim;
gettimeofday(&tv, NULL);
- tim = localtime(&(tv.tv_sec));
+ tim = localtime((time_t *)&(tv.tv_sec));
if (WC && WC->wc_session) {
fprintf(stderr,
tim->tm_year + 1900, tim->tm_mon + 1,
tim->tm_mday, tim->tm_hour, tim->tm_min,
tim->tm_sec, (long)tv.tv_usec / 1000,
- pthread_self(), WC->wc_session, buf);
+ (long)pthread_self(),
+ WC->wc_session, buf);
} else {
fprintf(stderr,
"%04d/%02d/%02d %2d:%02d:%02d.%03ld [%ld] %s",
tim->tm_year + 1900, tim->tm_mon + 1,
tim->tm_mday, tim->tm_hour, tim->tm_min,
tim->tm_sec, (long)tv.tv_usec / 1000,
- pthread_self(), buf);
+ (long)pthread_self(),
+ buf);
}
fflush(stderr);
}