Switched back to the old style thread architecture in preparation for eventual migrat...
[citadel.git] / citadel / citserver.c
index e1843eb209c2396a3684203f93eabc6ffb994d21..cff393ba04e239f8f68b1543d65cc6c7e3e40c81 100644 (file)
@@ -82,6 +82,7 @@ char *unique_session_numbers;
 int ScheduledShutdown = 0;
 time_t server_startup_time;
 int panic_fd;
+int openid_level_supported = 0;
 
 /*
  * print the actual stack frame.
@@ -171,11 +172,6 @@ void master_startup(void) {
 
        syslog(LOG_INFO, "Opening databases\n");
        open_databases();
-
-       ctdl_thread_internal_init_tsd();
-       
-       CtdlThreadAllocTSD();
-       
        check_ref_counts();
 
        syslog(LOG_INFO, "Creating base rooms (if necessary)\n");
@@ -243,10 +239,6 @@ void master_cleanup(int exitcode) {
        syslog(LOG_INFO, "Closing databases\n");
        close_databases();
 
-#ifdef DEBUG_MEMORY_LEAKS
-       dump_heap();
-#endif
-
        /* If the operator requested a halt but not an exit, halt here. */
        if (shutdown_and_halt) {
                syslog(LOG_NOTICE, "citserver: Halting server without exiting.\n");
@@ -288,7 +280,7 @@ void cmd_info(char *cmdbuf) {
        cprintf("%s\n", config.c_moreprompt);
        cprintf("1\n"); /* 1 = yes, this system supports floors */
        cprintf("1\n"); /* 1 = we support the extended paging options */
-       cprintf("%s\n", CC->cs_nonce);
+       cprintf("\n");  /* nonce no longer supported */
        cprintf("1\n"); /* 1 = yes, this system supports the QNOP command */
 
 #ifdef HAVE_LDAP
@@ -306,17 +298,17 @@ void cmd_info(char *cmdbuf) {
 
        cprintf("%s\n", config.c_default_cal_zone);
 
-       /* Output load averages */
-       cprintf("%f\n", CtdlThreadLoadAvg);
-       cprintf("%f\n", CtdlThreadWorkerAvg);
-       cprintf("%d\n", CtdlThreadGetCount());
+       /* thread load averages -- temporarily disabled during refactoring of this code */
+       cprintf("0\n");         /* load average */
+       cprintf("0\n");         /* worker average */
+       cprintf("0\n");         /* thread count */
 
        cprintf("1\n");         /* yes, Sieve mail filtering is supported */
        cprintf("%d\n", config.c_enable_fulltext);
        cprintf("%s\n", svn_revision());
 
        if (config.c_auth_mode == AUTHMODE_NATIVE) {
-               cprintf("1\n"); /* OpenID is enabled when using native auth */
+               cprintf("%d\n", openid_level_supported); /* OpenID is enabled when using native auth */
        }
        else {
                cprintf("0\n"); /* OpenID is disabled when using non-native auth */
@@ -790,7 +782,7 @@ void cmd_ipgm(char *argbuf)
                sleep(5);
                cprintf("%d Authentication failed.\n", ERROR + PASSWORD_REQUIRED);
                syslog(LOG_ERR, "Warning: ipgm authentication failed.\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_AUTHFAILED;
        }
 }
 
@@ -824,7 +816,7 @@ void cmd_down(char *argbuf) {
        {
                cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN); 
        }
-       CC->kill_me = 1; /* Even the DOWN command has to follow correct proceedure when disconecting */
+       CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
        CtdlThreadStopAll();
 }
 
@@ -889,22 +881,6 @@ void cmd_asyn(char *argbuf)
 }
 
 
-/*
- * Generate a "nonce" for APOP-style authentication.
- *
- * RFC 1725 et al specify a PID to be placed in front of the nonce.
- * Quoth BTX: That would be stupid.
- */
-void generate_nonce(CitContext *con) {
-       struct timeval tv;
-
-       memset(con->cs_nonce, NONCE_SIZE, 0);
-       gettimeofday(&tv, NULL);
-       memset(con->cs_nonce, NONCE_SIZE, 0);
-       snprintf(con->cs_nonce, NONCE_SIZE, "<%d%ld@%s>",
-               rand(), (long)tv.tv_usec, config.c_fqdn);
-}
-
 
 /*
  * Back-end function for starting a session
@@ -921,6 +897,8 @@ void begin_session(CitContext *con)
        con->internal_pgm = 0;
        con->download_fp = NULL;
        con->upload_fp = NULL;
+       con->cached_msglist = NULL;
+       con->cached_num_msgs = 0;
        con->FirstExpressMessage = NULL;
        time(&con->lastcmd);
        time(&con->lastidle);
@@ -932,7 +910,6 @@ void begin_session(CitContext *con)
        *con->fake_hostname = '\0';
        *con->fake_roomname = '\0';
        *con->cs_clientinfo = '\0';
-       generate_nonce(con);
        safestrncpy(con->cs_host, config.c_fqdn, sizeof con->cs_host);
        safestrncpy(con->cs_addr, "", sizeof con->cs_addr);
        con->cs_UDSclientUID = -1;
@@ -1008,7 +985,7 @@ void citproto_begin_session() {
                        ERROR + MAX_SESSIONS_EXCEEDED,
                        config.c_nodename, config.c_maxsessions
                );
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_MAX_SESSIONS_EXCEEDED;
        }
        else {
                cprintf("%d %s Citadel server ready.\n", CIT_OK, config.c_nodename);
@@ -1032,7 +1009,7 @@ void cmd_qnop(char *argbuf)
 void cmd_quit(char *argbuf)
 {
        cprintf("%d Goodbye.\n", CIT_OK);
-       CC->kill_me = 1;
+       CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
 }
 
 
@@ -1049,16 +1026,12 @@ void cmd_lout(char *argbuf)
  */
 void do_command_loop(void) {
        char cmdbuf[SIZ];
-       const char *old_name = NULL;
-       
-       old_name = CtdlThreadName("do_command_loop");
        
        time(&CC->lastcmd);
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
        if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
-               syslog(LOG_ERR, "Client disconnected: ending session.\n");
-               CC->kill_me = 1;
-               CtdlThreadName(old_name);
+               syslog(LOG_ERR, "Citadel client disconnected: ending session.\n");
+               CC->kill_me = KILLME_CLIENT_DISCONNECTED;
                return;
        }
 
@@ -1087,8 +1060,6 @@ void do_command_loop(void) {
                time(&CC->lastidle);
        }
        
-       CtdlThreadName(cmdbuf);
-               
        if ((strncasecmp(cmdbuf, "ENT0", 4))
           && (strncasecmp(cmdbuf, "MESG", 4))
           && (strncasecmp(cmdbuf, "MSGS", 4)))
@@ -1104,7 +1075,6 @@ void do_command_loop(void) {
 
        /* Run any after-each-command routines registered by modules */
        PerformSessionHooks(EVT_CMD);
-       CtdlThreadName(old_name);
 }