HUGE PATCH. This moves all of mime_parser.c and all
[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
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
23
24 #include <libcitadel.h>
25 #include "citadel.h"
26 #include <unistd.h>
27 #include "citadel_ipc.h"
28 #include "citadel_dirs.h"
29
30 void logoff(int code)
31 {
32         exit(code);
33 }
34
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;
42
43         r = CtdlIPCUserListing(ipc, "", &listing, buf);
44         if (r / 100 != 1) {
45                 printf("%s\n", buf);
46                 return;
47         }
48         printf("       User Name           Num  L  LastCall  Calls Posts\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("%5ld %5ld\n",
64                         extract_long(buf,4),extract_long(buf,5));
65         }
66         printf("\n");
67 }
68
69
70 int main(int argc, char **argv)
71 {
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;
79
80         CtdlInitBase64Table();
81         calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
82
83         ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
84         CtdlIPC_chat_recv(ipc, buf);
85         if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
86                 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
87                 logoff(atoi(buf));
88         }
89
90         userlist(ipc);
91
92         CtdlIPCQuit(ipc);
93         exit(0);
94 }
95
96
97 #ifndef HAVE_STRERROR
98 /*
99  * replacement strerror() for systems that don't have it
100  */
101 char *strerror(int e)
102 {
103         static char buf[32];
104
105         snprintf(buf, sizeof buf, "errno = %d",e);
106         return(buf);
107 }
108 #endif