]> code.citadel.org Git - citadel.git/blobdiff - citadel/textclient/citadel.c
Condense the default wholist when there are multiple sessions from the same user
[citadel.git] / citadel / textclient / citadel.c
index 8d730855eda712dea9079c2ef6a00c8d07f6acfb..19f46ca57ddab3becfa4e010942ea5c0ab61bb57 100644 (file)
@@ -127,21 +127,6 @@ CtdlIPC *ipc_for_signal_handlers;  /* KLUDGE cover your eyes */
 int enable_syslog = 0;
 
 
-/*
- * CtdlLogPrintf()  ...   Write logging information; 
- *                  simple here to have the same 
- *                  symbols in the client.
- */
-
-void CtdlLogPrintf(enum LogLevel loglevel, const char *format, ...) {   
-       va_list arg_ptr;
-
-       va_start(arg_ptr, format);
-       vfprintf(stderr, format, arg_ptr);   
-       va_end(arg_ptr);   
-       fflush(stderr);
-}   
-
 /*
  * here is our 'clean up gracefully and exit' routine
  */
@@ -471,6 +456,7 @@ void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
        switch(room->RRdefaultview) {
                case VIEW_BBS:
                case VIEW_MAILBOX:
+               case VIEW_BLOG:
                                        entmsg_ok = 1;
                                        break;
                default:
@@ -531,6 +517,14 @@ void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
                }
        }
        free(room);
+
+       if (screenwidth>5) snprintf(&status_line[1], screenwidth-1, "%s  |  %s  |  %s  |  %s  |  %d new mail  |",
+               (secure ? "Encrypted" : "Unencrypted"),
+               ipc->ServInfo.humannode,
+               ipc->ServInfo.site_location,
+               room_name,
+               newmailcount
+       );
 }
 
 /* Goto next room having unread messages.
@@ -595,7 +589,6 @@ void forget_all_rooms_on(CtdlIPC *ipc, int ffloor)
        int r;                          /* IPC response code */
 
        scr_printf("Forgetting all rooms on %s...\n", &floorlist[ffloor][0]);
-       scr_flush();
        remove_march("_FLOOR_", ffloor);
        r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, ffloor, &flist, buf);
        if (r / 100 != 1) {
@@ -973,8 +966,6 @@ void read_config(CtdlIPC *ipc)
        scr_printf("\n");
 
        /* show preferences */
-       scr_printf("Your screen width: ");                                     color(BRIGHT_CYAN); scr_printf("%d",   /*user->USscreenwidth*/ screenwidth);          color(DIM_WHITE); 
-       scr_printf(", height: ");                                              color(BRIGHT_CYAN); scr_printf("%d\n", /*user->USscreenheight*/ screenheight);        color(DIM_WHITE);  
        scr_printf("Are you an experienced Citadel user: ");                   color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_EXPERT) ? "Yes" : "No");     color(DIM_WHITE);
        scr_printf("Print last old message on New message request: ");         color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_LASTOLD)? "Yes" : "No");     color(DIM_WHITE);
        scr_printf("Prompt after each message: ");                             color(BRIGHT_CYAN); scr_printf("%s\n", (!(user->flags & US_NOPROMPT))? "Yes" : "No"); color(DIM_WHITE);
@@ -1184,7 +1175,20 @@ void get_serv_info(CtdlIPC *ipc, char *supplied_hostname)
 
 
 /*
- * Record compare function for SortOnlineUsers()
+ * Session username compare function for SortOnlineUsers()
+ */
+int rwho_username_cmp(const void *rec1, const void *rec2) {
+       char *u1, *u2;
+
+       u1 = strchr(rec1, '|');
+       u2 = strchr(rec2, '|');
+
+       return strcasecmp( (u1?++u1:"") , (u2?++u2:"") );
+}
+
+
+/*
+ * Idle time compare function for SortOnlineUsers()
  */
 int idlecmp(const void *rec1, const void *rec2) {
        time_t i1, i2;
@@ -1202,8 +1206,11 @@ int idlecmp(const void *rec1, const void *rec2) {
  * Sort the list of online users by idle time.
  * This function frees the supplied buffer, and returns a new one
  * to the caller.  The caller is responsible for freeing the returned buffer.
+ *
+ * If 'condense' is nonzero, multiple sessions for the same user will be
+ * combined into one for brevity.
  */
-char *SortOnlineUsers(char *listing) {
+char *SortOnlineUsers(char *listing, int condense) {
        int rows;
        char *sortbuf;
        char *retbuf;
@@ -1226,17 +1233,37 @@ char *SortOnlineUsers(char *listing) {
                memcpy(&sortbuf[i*SIZ], buf, (size_t)SIZ);
        }
 
-       /* Do the sort */
+       /* Sort by idle time */
        qsort(sortbuf, rows, SIZ, idlecmp);
 
+       /* Combine multiple sessions for the same user */
+       if (condense) {
+               qsort(sortbuf, rows, SIZ, rwho_username_cmp);
+               if (rows > 1) for (i=1; i<rows; ++i) if (i>0) {
+                       char u1[USERNAME_SIZE];
+                       char u2[USERNAME_SIZE];
+                       extract_token(u1, &sortbuf[(i-1)*SIZ], 1, '|', sizeof u1);
+                       extract_token(u2, &sortbuf[i*SIZ], 1, '|', sizeof u2);
+                       if (!strcasecmp(u1, u2)) {
+                               memcpy(&sortbuf[i*SIZ], &sortbuf[(i+1)*SIZ], (rows-i-1)*SIZ);
+                               --rows;
+                               --i;
+                       }
+               }
+
+               qsort(sortbuf, rows, SIZ, idlecmp);     /* idle sort again */
+       }
+
        /* Copy back to a \n delimited list */
        strcpy(retbuf, "");
        for (i=0; i<rows; ++i) {
-               strcat(retbuf, &sortbuf[i*SIZ]);
-               if (i<(rows-1)) strcat(retbuf, "\n");
+               if (!IsEmptyStr(&sortbuf[i*SIZ])) {
+                       strcat(retbuf, &sortbuf[i*SIZ]);
+                       if (i<(rows-1)) strcat(retbuf, "\n");
+               }
        }
-    free(listing);
-    free(sortbuf);
+       free(listing);
+       free(sortbuf);
        return(retbuf);
 }
 
@@ -1274,7 +1301,7 @@ void who_is_online(CtdlIPC *ipc, int longlist)
                scr_printf("\n");
        }
        r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
-       listing = SortOnlineUsers(listing);
+       listing = SortOnlineUsers(listing, (!longlist));
        if (r / 100 == 1) {
                while (!IsEmptyStr(listing)) {
                        int isidle = 0;
@@ -1401,7 +1428,6 @@ int shift(int argc, char **argv, int start, int count) {
 
 static void statusHook(char *s) {
        scr_printf(s);
-       scr_flush();
 }
 
 /*
@@ -1552,6 +1578,8 @@ int main(int argc, char **argv)
                logoff(NULL, 3);
        }
 
+       CtdlIPC_SetNetworkStatusCallback(ipc, scr_wait_indicator);
+
        if (!(ipc->isLocal)) {
                scr_printf("Connected to %s [%s].\n", ipc->ip_hostname, ipc->ip_address);
        }
@@ -1600,7 +1628,6 @@ int main(int argc, char **argv)
        get_serv_info(ipc, telnet_client_host);
        scr_printf("%-24s\n%s\n%s\n", ipc->ServInfo.software, ipc->ServInfo.humannode,
                   ipc->ServInfo.site_location);
-       scr_flush();
 
        screenwidth = 80;       /* default screen dimensions */
        screenheight = 24;
@@ -1669,7 +1696,7 @@ int main(int argc, char **argv)
        if (!IsEmptyStr(rc_password)) {
                strcpy(password, rc_password);
        } else {
-               newprompt("\rPlease enter your password: ", password, -19);
+               newprompt("\rPlease enter your password: ", password, -(SIZ-1));
        }
 
        if (*nonce) {
@@ -1782,17 +1809,11 @@ NEWUSR: if (IsEmptyStr(rc_password)) {
        screenwidth = 80;
        screenheight = 24;
        r = CtdlIPCGetConfig(ipc, &myself, aaa);
-       if (r == 2) {
-               screenwidth = myself->USscreenwidth;
-               screenheight = myself->USscreenheight;
-       }
        if (getenv("TERM") != NULL)
                if (!strcmp(getenv("TERM"), "xterm")) {
                        have_xterm = 1;
                }
-#ifdef TIOCGWINSZ
        check_screen_dims();
-#endif
 
        set_floor_mode(ipc);