Removed some long-unused defs from citadel.h
[citadel.git] / citadel / utils / userlist.c
1 /*
2  * Command-line user list utility.
3  *
4  */
5
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <stdio.h>
9 #include <string.h>
10
11 #if TIME_WITH_SYS_TIME
12 # include <sys/time.h>
13 # include <time.h>
14 #else
15 # if HAVE_SYS_TIME_H
16 #  include <sys/time.h>
17 # else
18 #  include <time.h>
19 # endif
20 #endif
21
22 #include <libcitadel.h>
23 #include "citadel.h"
24 #include <unistd.h>
25 #include "citadel_ipc.h"
26 #include "citadel_dirs.h"
27
28 void logoff(int code)
29 {
30         exit(code);
31 }
32
33 void userlist(CtdlIPC *ipc) { 
34         char buf[SIZ];
35         char fl[SIZ];
36         struct tm tmbuf;
37         time_t lc;
38         char *listing = NULL;
39         int r;
40
41         r = CtdlIPCUserListing(ipc, "", &listing, buf);
42         if (r / 100 != 1) {
43                 printf("%s\n", buf);
44                 return;
45         }
46         printf("       User Name           Num  L Last Visit Logins Messages\n");
47         printf("------------------------- ----- - ---------- ------ --------\n");
48         while (strlen(listing) > 0) {
49                 extract_token(buf, listing, 0, '\n', sizeof buf);
50                 remove_token(listing, 0, '\n');
51                 extract_token(fl, buf, 0, '|', sizeof fl);
52                 printf("%-25s ",fl);
53                 printf("%5ld %d ", extract_long(buf,2),
54                         extract_int(buf,1));
55                 lc = extract_long(buf,3);
56                 localtime_r(&lc, &tmbuf);
57                 printf("%02d/%02d/%04d ",
58                         (tmbuf.tm_mon+1),
59                         tmbuf.tm_mday,
60                         (tmbuf.tm_year + 1900));
61                 printf("%6ld %8ld\n",
62                         extract_long(buf,4),extract_long(buf,5));
63         }
64         printf("\n");
65 }
66
67
68 int main(int argc, char **argv)
69 {
70         char buf[SIZ];
71         char hostbuf[SIZ], portbuf[SIZ];
72         CtdlIPC *ipc = NULL;
73         int relh=0;
74         int home=0;
75         char relhome[PATH_MAX]="";
76         char ctdldir[PATH_MAX]=CTDLDIR;
77
78         calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
79
80         ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
81         CtdlIPC_chat_recv(ipc, buf);
82         if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
83                 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
84                 logoff(atoi(buf));
85         }
86
87         userlist(ipc);
88
89         CtdlIPCQuit(ipc);
90         exit(0);
91 }
92
93
94 #ifndef HAVE_STRERROR
95 /*
96  * replacement strerror() for systems that don't have it
97  */
98 char *strerror(int e)
99 {
100         static char buf[32];
101
102         snprintf(buf, sizeof buf, "errno = %d",e);
103         return(buf);
104 }
105 #endif
106
107
108 /*
109  * Stub function
110  */
111 void stty_ctdl(int cmd) {
112 }
113