* Fixed a multiselect bug in the mailbox view. Ctrl-click was selecting a message...
[citadel.git] / citadel / userlist.c
blob3f78cea6fb0e03b61aa2c852984de2864838a2d8
1 /*
2 * $Id$
4 * Command-line user list utility.
6 */
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <string.h>
13 #if TIME_WITH_SYS_TIME
14 # include <sys/time.h>
15 # include <time.h>
16 #else
17 # if HAVE_SYS_TIME_H
18 # include <sys/time.h>
19 # else
20 # include <time.h>
21 # endif
22 #endif
24 #include <libcitadel.h>
25 #include "citadel.h"
26 #include <unistd.h>
27 #include "citadel_ipc.h"
28 #include "citadel_dirs.h"
30 void logoff(int code)
32 exit(code);
35 void userlist(CtdlIPC *ipc) {
36 char buf[SIZ];
37 char fl[SIZ];
38 struct tm tmbuf;
39 time_t lc;
40 char *listing = NULL;
41 int r;
43 r = CtdlIPCUserListing(ipc, "", &listing, buf);
44 if (r / 100 != 1) {
45 printf("%s\n", buf);
46 return;
48 printf(" User Name Num L Last Visit Logins Messages\n");
49 printf("------------------------- ----- - ---------- ------ --------\n");
50 while (strlen(listing) > 0) {
51 extract_token(buf, listing, 0, '\n', sizeof buf);
52 remove_token(listing, 0, '\n');
53 extract_token(fl, buf, 0, '|', sizeof fl);
54 printf("%-25s ",fl);
55 printf("%5ld %d ", extract_long(buf,2),
56 extract_int(buf,1));
57 lc = extract_long(buf,3);
58 localtime_r(&lc, &tmbuf);
59 printf("%02d/%02d/%04d ",
60 (tmbuf.tm_mon+1),
61 tmbuf.tm_mday,
62 (tmbuf.tm_year + 1900));
63 printf("%6ld %8ld\n",
64 extract_long(buf,4),extract_long(buf,5));
66 printf("\n");
70 int main(int argc, char **argv)
72 char buf[SIZ];
73 char hostbuf[SIZ], portbuf[SIZ];
74 CtdlIPC *ipc = NULL;
75 int relh=0;
76 int home=0;
77 char relhome[PATH_MAX]="";
78 char ctdldir[PATH_MAX]=CTDLDIR;
80 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
82 ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
83 CtdlIPC_chat_recv(ipc, buf);
84 if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
85 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
86 logoff(atoi(buf));
89 userlist(ipc);
91 CtdlIPCQuit(ipc);
92 exit(0);
96 #ifndef HAVE_STRERROR
98 * replacement strerror() for systems that don't have it
100 char *strerror(int e)
102 static char buf[32];
104 snprintf(buf, sizeof buf, "errno = %d",e);
105 return(buf);
107 #endif
111 * Stub function
113 void stty_ctdl(int cmd) {