]> code.citadel.org Git - citadel.git/blobdiff - citadel/citserver.c
* Cleaned up some things that generated compiler warnings
[citadel.git] / citadel / citserver.c
index 8fd945e5f3c3bdf6508671fd8e6780381c800de6..eda6a754efb9fd26597d5cbb0959fcf9e6dc8780 100644 (file)
@@ -63,6 +63,7 @@
 #endif
 
 struct CitContext *ContextList = NULL;
+struct CitContext* next_session = NULL;
 char *unique_session_numbers;
 int ScheduledShutdown = 0;
 int do_defrag = 0;
@@ -90,10 +91,10 @@ void master_startup(void) {
        check_ref_counts();
 
        lprintf(CTDL_INFO, "Creating base rooms (if necessary)\n");
-       create_room(BASEROOM,           0, "", 0, 1, 0);
-       create_room(AIDEROOM,           3, "", 0, 1, 0);
-       create_room(SYSCONFIGROOM,      3, "", 0, 1, 0);
-       create_room(config.c_twitroom,  0, "", 0, 1, 0);
+       create_room(BASEROOM,           0, "", 0, 1, 0, VIEW_BBS);
+       create_room(AIDEROOM,           3, "", 0, 1, 0, VIEW_BBS);
+       create_room(SYSCONFIGROOM,      3, "", 0, 1, 0, VIEW_BBS);
+       create_room(config.c_twitroom,  0, "", 0, 1, 0, VIEW_BBS);
 
        /* The "Local System Configuration" room doesn't need to be visible */
         if (lgetroom(&qrbuf, SYSCONFIGROOM) == 0) {
@@ -204,6 +205,9 @@ void RemoveContext (struct CitContext *con)
        else {
                for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
                        if (ptr->next == con) {
+                               /* See fair scheduling in sysdep.c */
+                               if (next_session == ptr->next)
+                                       next_session = ptr->next->next;
                                ToFree = ptr->next;
                                ptr->next = ptr->next->next;
                                --num_sessions;
@@ -232,7 +236,7 @@ void RemoveContext (struct CitContext *con)
        logout(con);
 
        unlink(con->temp);
-       lprintf(CTDL_NOTICE, "Session %d: ended.\n", con->cs_pid);
+       lprintf(CTDL_NOTICE, "[%3d] Session ended.\n", con->cs_pid);
 
        /* Deallocate any user-data attached to this session */
        deallocate_user_data(con);
@@ -357,7 +361,7 @@ void cmd_info(void) {
 
 
 /*
- * returns an asterisk if there are any express messages waiting,
+ * returns an asterisk if there are any instant messages waiting,
  * space otherwise.
  */
 char CtdlCheckExpress(void) {
@@ -372,16 +376,16 @@ char CtdlCheckExpress(void) {
 void cmd_time(void)
 {
    time_t tv;
-   struct tm *tmp;
+   struct tm tmp;
    
    tv = time(NULL);
-   tmp = localtime(&tv);
+   localtime_r(&tv, &tmp);
    
    /* timezone and daylight global variables are not portable. */
 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
-   cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, tmp->tm_gmtoff, tmp->tm_isdst);
+   cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst);
 #else
-   cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, timezone, tmp->tm_isdst);
+   cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst);
 #endif
 }
 
@@ -589,6 +593,8 @@ void cmd_emsg(char *mname)
        char *dirs[2];
        int a;
 
+       unbuffer_output();
+
        if (CtdlAccessCheck(ac_aide)) return;
 
        extract(buf,mname,0);
@@ -663,6 +669,11 @@ int CtdlAccessCheck(int required_level) {
                return(-1);
        }
 
+       if ((required_level >= ac_logged_in) && (CC->logged_in == 0)) {
+               cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
+               return(-1);
+       }
+
        if (CC->user.axlevel >= 6) return(0);
        if (required_level >= ac_aide) {
                cprintf("%d This command requires Aide access.\n",
@@ -677,12 +688,6 @@ int CtdlAccessCheck(int required_level) {
                return(-1);
        }
 
-       if (CC->logged_in) return(0);
-       if (required_level >= ac_logged_in) {
-               cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
-               return(-1);
-       }
-
        /* shhh ... succeed quietly */
        return(0);
 }
@@ -860,7 +865,7 @@ void generate_nonce(struct CitContext *con) {
  */
 void begin_session(struct CitContext *con)
 {
-       int len;        /* should be socklen_t but doesn't work on Macintosh */
+       int len;
        struct sockaddr_in sin;
 
        /* 
@@ -889,7 +894,7 @@ void begin_session(struct CitContext *con)
        len = sizeof sin;
        if (!CC->is_local_socket) {
                if (!getpeername(con->client_socket,
-                  (struct sockaddr *) &sin, &len))
+                  (struct sockaddr *) &sin, &len))     /* should be socklen_t but doesn't work on Macintosh */
                        locate_host(con->cs_host, sizeof con->cs_host,
                                con->cs_addr, sizeof con->cs_addr,
                                &sin.sin_addr);
@@ -921,7 +926,7 @@ void citproto_begin_session() {
                        config.c_nodename, config.c_maxsessions);
        }
        else {
-               cprintf("%d %s Citadel/UX server ready.\n",
+               cprintf("%d %s Citadel server ready.\n",
                        CIT_OK, config.c_nodename);
        }
 }
@@ -938,12 +943,14 @@ void do_command_loop(void) {
        time(&CC->lastcmd);
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
        if (client_gets(cmdbuf) < 1) {
-               lprintf(CTDL_ERR, "Client socket is broken.  Ending session.\n");
+               lprintf(CTDL_ERR, "Client socket is broken; ending session\n");
                CC->kill_me = 1;
                return;
        }
        lprintf(CTDL_INFO, "Citadel: %s\n", cmdbuf);
 
+       buffer_output();
+
        /*
         * Let other clients see the last command we executed, and
         * update the idle time, but not NOOP, QNOP, PEXP, or GEXP.
@@ -966,7 +973,7 @@ void do_command_loop(void) {
        }
                   
        if (!strncasecmp(cmdbuf,"NOOP",4)) {
-               cprintf("%d%cok\n",CIT_OK,CtdlCheckExpress());
+               cprintf("%d%cok\n", CIT_OK, CtdlCheckExpress() );
        }
        
        else if (!strncasecmp(cmdbuf,"QNOP",4)) {
@@ -974,7 +981,7 @@ void do_command_loop(void) {
        }
 
        else if (!strncasecmp(cmdbuf,"QUIT",4)) {
-               cprintf("%d Goodbye.\n",CIT_OK);
+               cprintf("%d Goodbye.\n", CIT_OK);
                CC->kill_me = 1;
        }
 
@@ -984,7 +991,7 @@ void do_command_loop(void) {
 
        else if (!strncasecmp(cmdbuf,"LOUT",4)) {
                if (CC->logged_in) logout(CC);
-               cprintf("%d logged out.\n",CIT_OK);
+               cprintf("%d logged out.\n", CIT_OK);
        }
 
        else if (!strncasecmp(cmdbuf,"USER",4)) {
@@ -1308,9 +1315,20 @@ void do_command_loop(void) {
        }
 
        else if (!DLoader_Exec_Cmd(cmdbuf)) {
-               cprintf("%d Unrecognized or unsupported command.\n", ERROR + CMD_NOT_SUPPORTED);
+               cprintf("%d Unrecognized or unsupported command.\n",
+                       ERROR + CMD_NOT_SUPPORTED);
               }
 
-       /* Run any after-each-command outines registered by modules */
+       unbuffer_output();
+
+       /* Run any after-each-command routines registered by modules */
        PerformSessionHooks(EVT_CMD);
 }
+
+
+/*
+ * This loop performs all asynchronous functions.
+ */
+void do_async_loop(void) {
+       PerformSessionHooks(EVT_ASYNC);
+}