fix all the <time.h> vs. <sys/time.h> issues, hopefully
[citadel.git] / citadel / readlog.c
1 /* 
2  * $Id$
3  *
4  * A simple program to parse citadel.log
5  */
6
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <fcntl.h>
10 #include <stdio.h>
11
12 #if TIME_WITH_SYS_TIME
13 # include <sys/time.h>
14 # include <time.h>
15 #else
16 # if HAVE_SYS_TIME_H
17 #  include <sys/time.h>
18 # else
19 #  include <time.h>
20 # endif
21 #endif
22
23 #include <string.h>
24 #include <errno.h>
25 #include "citadel.h"
26
27 void get_config (void);
28 struct config config;
29
30 int 
31 main (int argc, char **argv)
32 {
33   time_t LogTime;
34   unsigned int LogType;
35   char LogName[SIZ];
36
37   char buf[SIZ];
38   char aaa[100];
39   struct tm *tm;
40   char *tstring;
41   FILE *logfp;
42
43   get_config ();
44
45   logfp = fopen ("citadel.log", "r");
46   if (logfp == NULL)
47     {
48       perror ("Could not open citadel.log");
49       exit (errno);
50     }
51   else
52     {
53       while (fgets (buf, sizeof buf, logfp) != NULL)
54         {
55           buf[strlen (buf) - 1] = 0;
56           strcat(buf, " ");
57
58           LogTime = atol (strtok(buf, "|"));
59           LogType = atol (strtok(NULL, "|"));
60           strcpy(LogName, strtok(NULL, "|"));
61
62           if (LogType != 0)
63             {
64               strcpy (aaa, "");
65               if (LogType & CL_CONNECT)
66                 strcpy (aaa, "Connect");
67               if (LogType & CL_LOGIN)
68                 strcpy (aaa, "Login");
69               if (LogType & CL_NEWUSER)
70                 strcpy (aaa, "New User");
71               if (LogType & CL_BADPW)
72                 strcpy (aaa, "Bad PW Attempt");
73               if (LogType & CL_TERMINATE)
74                 strcpy (aaa, "Terminate");
75               if (LogType & CL_DROPCARR)
76                 strcpy (aaa, "Dropped Carrier");
77               if (LogType & CL_SLEEPING)
78                 strcpy (aaa, "Sleeping");
79               if (LogType & CL_PWCHANGE)
80                 strcpy (aaa, "Changed Passwd");
81               tm = (struct tm *) localtime (&LogTime);
82               tstring = (char *) asctime (tm);
83               printf ("%30s %20s %s", LogName, aaa, tstring);
84             }
85         }
86     }
87   fclose(logfp);
88   exit (0);
89 }