fix all the <time.h> vs. <sys/time.h> issues, hopefully
[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 "citadel.h"
25 #include <unistd.h>
26 #include "ipc.h"
27 #include "tools.h"
28
29 void logoff(int code)
30 {
31         exit(code);
32         }
33
34 void userlist(void) { 
35         char buf[SIZ];
36         char fl[SIZ];
37         struct tm *tmbuf;
38         time_t lc;
39
40         serv_puts("LIST");
41         serv_gets(buf);
42         if (buf[0]!='1') {
43                 printf("%s\n",&buf[4]);
44                 return;
45                 }
46         printf("       User Name           Num  L  LastCall  Calls Posts\n");
47         printf("------------------------- ----- - ---------- ----- -----\n");
48         while (serv_gets(buf), strcmp(buf,"000")) {
49                 extract(fl,buf,0);
50                 printf("%-25s ",fl);
51                 printf("%5ld %d ",extract_long(buf,2),
52                         extract_int(buf,1));
53                 lc = extract_long(buf,3);
54                 tmbuf = (struct tm *)localtime(&lc);
55                 printf("%02d/%02d/%04d ",
56                         (tmbuf->tm_mon+1),
57                         tmbuf->tm_mday,
58                         (tmbuf->tm_year + 1900));
59                 printf("%5ld %5ld\n",
60                         extract_long(buf,4),extract_long(buf,5));
61                 }
62         printf("\n");
63         }
64
65
66 int main(int argc, char **argv)
67 {
68         char buf[SIZ];
69         char hostbuf[SIZ], portbuf[SIZ];
70
71         attach_to_server(argc, argv, hostbuf, portbuf);
72         serv_gets(buf);
73         if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
74                 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
75                 logoff(atoi(buf));
76                 }
77
78         userlist();
79
80         serv_puts("QUIT");
81         serv_gets(buf);
82         exit(0);
83         }
84
85
86 #ifndef HAVE_STRERROR
87 /*
88  * replacement strerror() for systems that don't have it
89  */
90 char *strerror(int e)
91 {
92         static char buf[32];
93
94         sprintf(buf,"errno = %d",e);
95         return(buf);
96         }
97 #endif
98
99
100
101
102