Fix compiler warnings in the textclient by evaluating returnvalues and removing unuse...
[citadel.git] / citadel / textclient / citadel.c
index 105f2d9f695af083e698c6754b96e797948796f1..622bed1c874142ce43107281eaabcf955bbd38c2 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
  */
@@ -335,8 +320,6 @@ void remove_march(char *roomname, int floornum)
 char *pop_march(int desired_floor, struct march *_march)
 {
        static char TheRoom[ROOMNAMELEN];
-       int TheFloor = 0;
-       int TheOrder = 32767;
        int TheWeight = 0;
        int weight;
        struct march *mptr = NULL;
@@ -358,8 +341,6 @@ char *pop_march(int desired_floor, struct march *_march)
                if (weight > TheWeight) {
                        TheWeight = weight;
                        strcpy(TheRoom, mptr->march_name);
-                       TheFloor = mptr->march_floor;
-                       TheOrder = mptr->march_order;
                }
        }
        return (TheRoom);
@@ -471,6 +452,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:
@@ -528,6 +510,9 @@ void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
                color(DIM_WHITE);
                if (!IsEmptyStr(rc_gotmail_cmd)) {
                        rv = system(rc_gotmail_cmd);
+                       if (rv) 
+                               scr_printf("*** failed to check for mail calling %s Reason %d.\n",
+                                          rc_gotmail_cmd, rv);
                }
        }
        free(room);
@@ -551,14 +536,13 @@ void gotonext(CtdlIPC *ipc)
        char buf[SIZ];
        struct march *mptr, *mptr2;
        char next_room[ROOMNAMELEN];
-       int r;                          /* IPC response code */
 
        /* Check to see if the march-mode list is already allocated.
         * If it is, pop the first room off the list and go there.
         */
        if (marchptr == NULL) {
-               r = CtdlIPCKnownRooms(ipc, SubscribedRoomsWithNewMessages,
-                                       AllFloors, &marchptr, buf);
+               CtdlIPCKnownRooms(ipc, SubscribedRoomsWithNewMessages,
+                                 AllFloors, &marchptr, buf);
 
 /* add _BASEROOM_ to the end of the march list, so the user will end up
  * in the system base room (usually the Lobby>) at the end of the loop
@@ -603,7 +587,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) {
@@ -1015,10 +998,9 @@ void system_info(CtdlIPC *ipc)
        int mrtg_users, mrtg_active_users; 
        char mrtg_server_uptime[40];
        long mrtg_himessage;
-       int ret;                        /* IPC response code */
 
        /* get #users, #active & server uptime */
-       ret = CtdlIPCGenericCommand(ipc, "MRTG|users", NULL, 0, &resp, &bytes, buf);
+       CtdlIPCGenericCommand(ipc, "MRTG|users", NULL, 0, &resp, &bytes, buf);
        mrtg_users = extract_int(resp, 0);
        remove_token(resp, 0, '\n');
        mrtg_active_users = extract_int(resp, 0);
@@ -1028,7 +1010,7 @@ void system_info(CtdlIPC *ipc)
        resp = NULL;
 
        /* get high message# */
-       ret = CtdlIPCGenericCommand(ipc, "MRTG|messages", NULL, 0, &resp, &bytes, buf);
+       CtdlIPCGenericCommand(ipc, "MRTG|messages", NULL, 0, &resp, &bytes, buf);
        mrtg_himessage = extract_long(resp, 0);
        free(resp);
        resp = NULL;
@@ -1190,7 +1172,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;
@@ -1208,8 +1203,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;
@@ -1232,17 +1230,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);
 }
 
@@ -1280,7 +1298,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;
@@ -1407,7 +1425,6 @@ int shift(int argc, char **argv, int start, int count) {
 
 static void statusHook(char *s) {
        scr_printf(s);
-       scr_flush();
 }
 
 /*
@@ -1422,7 +1439,6 @@ int main(int argc, char **argv)
        char *telnet_client_host = NULL;
        char *sptr, *sptr2;     /* USed to extract the nonce */
        char hexstring[MD5_HEXSTRING_SIZE];
-       int stored_password = 0;
        char password[SIZ];
        struct ctdlipcmisc chek;
        struct ctdluser *myself = NULL;
@@ -1608,7 +1624,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;
@@ -1633,7 +1648,6 @@ int main(int argc, char **argv)
 
                        if (r / 100 == 2) {
                                load_user_info(aaa);
-                               stored_password = 1;
                                goto PWOK;
                        } else {
                                set_stored_password(hostbuf, portbuf, "", "");
@@ -1677,7 +1691,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) {
@@ -1762,6 +1776,10 @@ NEWUSR:  if (IsEmptyStr(rc_password)) {
                        color(DIM_WHITE);
                        if (!IsEmptyStr(rc_gotmail_cmd)) {
                                rv = system(rc_gotmail_cmd);
+                               if (rv)
+                                       scr_printf("*** failed to check for mail calling %s Reason %d.\n",
+                                                  rc_gotmail_cmd, rv);
+
                        }
                }
                if ((axlevel >= AxAideU) && (chek.needvalid > 0)) {