5354722a7728c3604023e1fe9b67565e26ae0995
[citadel.git] / citadel / userlist.c
1 /*
2  * $Id$
3  *
4  * Command-line user list utility.
5  *
6  */
7
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <time.h>
13 #include "citadel.h"
14 #include <unistd.h>
15 #include "ipc.h"
16 #include "tools.h"
17
18 void logoff(int code)
19 {
20         exit(code);
21         }
22
23 void userlist(void) { 
24         char buf[SIZ];
25         char fl[SIZ];
26         struct tm *tmbuf;
27         time_t lc;
28
29         serv_puts("LIST");
30         serv_gets(buf);
31         if (buf[0]!='1') {
32                 printf("%s\n",&buf[4]);
33                 return;
34                 }
35         printf("       User Name           Num  L  LastCall  Calls Posts\n");
36         printf("------------------------- ----- - ---------- ----- -----\n");
37         while (serv_gets(buf), strcmp(buf,"000")) {
38                 extract(fl,buf,0);
39                 printf("%-25s ",fl);
40                 printf("%5ld %d ",extract_long(buf,2),
41                         extract_int(buf,1));
42                 lc = extract_long(buf,3);
43                 tmbuf = (struct tm *)localtime(&lc);
44                 printf("%02d/%02d/%04d ",
45                         (tmbuf->tm_mon+1),
46                         tmbuf->tm_mday,
47                         (tmbuf->tm_year + 1900));
48                 printf("%5ld %5ld\n",
49                         extract_long(buf,4),extract_long(buf,5));
50                 }
51         printf("\n");
52         }
53
54
55 int main(int argc, char **argv)
56 {
57         char buf[SIZ];
58         char hostbuf[SIZ], portbuf[SIZ];
59
60         attach_to_server(argc, argv, hostbuf, portbuf);
61         serv_gets(buf);
62         if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
63                 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
64                 logoff(atoi(buf));
65                 }
66
67         userlist();
68
69         serv_puts("QUIT");
70         serv_gets(buf);
71         exit(0);
72         }
73
74
75 #ifndef HAVE_STRERROR
76 /*
77  * replacement strerror() for systems that don't have it
78  */
79 char *strerror(int e)
80 {
81         static char buf[32];
82
83         sprintf(buf,"errno = %d",e);
84         return(buf);
85         }
86 #endif
87
88
89
90
91