]> code.citadel.org Git - citadel.git/commitdiff
Changing stats.c to read the new log format. This version builds without
authorArt Cancro <ajc@citadel.org>
Sun, 12 Jul 1998 21:59:01 +0000 (21:59 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 12 Jul 1998 21:59:01 +0000 (21:59 +0000)
errors, but it still doesn't work properly.

citadel/stats.c

index bf60e8789da92b62604b318acf226b3850fe74cd..3a8b877faf5f2add9cdfddca83b6ae9cc6107217 100644 (file)
@@ -1,11 +1,12 @@
 /* Citadel/UX call log stats program
- * version 2.4
  */
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <time.h>
 #include <stdio.h>
+#include <errno.h>
+#include <string.h>
 #include "citadel.h"
 
 #define disply(x,y) printf("%20s            %4.1f    %4.1f    %4d\n",x,((float)y)/calls,((float)y)/days,y)
@@ -25,7 +26,7 @@ void get_config ();
 struct config config;
 
 
-void 
+void
 prompt ()
 {
   char buf[16];
@@ -40,7 +41,7 @@ prompt ()
     }
 }
 
-int 
+int
 halfhour (time)                        /* Returns half-hour time period of time */
      long time;
 {
@@ -57,7 +58,7 @@ halfhour (time)                       /* Returns half-hour time period of time */
 
 
 
-void 
+void
 progress (curr, max)
      long curr;
      long max;
@@ -93,14 +94,16 @@ progress (curr, max)
 
 
 
-void 
+void
 main (argc, argv)
      int argc;
      char *argv[];
 {
-  struct calllog calllog;
+  time_t LogTime;
+  unsigned int LogType;
+  char LogName[256];
   struct usersupp usersupp;
-  int file, pos, a, b, lowest;
+  int a, b, lowest;
   float p, q;
   long timeon[72];
   long timeup[72];
@@ -118,6 +121,8 @@ main (argc, argv)
   FILE *fp, *sortpipe;
   char thegraph[GRANULARITY][73];
   int pc_only = 0;
+  char buf[256];
+  FILE *logfp;
 
   for (a = 0; a < argc; ++a)
     {
@@ -140,9 +145,6 @@ main (argc, argv)
   if (!batch_mode)
     printf ("Scanning call log, please wait...\n\n\n\n");
 
-  file = open ("calllog.pos", O_RDONLY);
-  read (file, &pos, 2);
-  close (file);
   from = 0L;
   to = 0L;
   for (a = 0; a < 72; ++a)
@@ -160,198 +162,210 @@ main (argc, argv)
   terms = 0;
   drops = 0;
   sleeps = 0;
-  file = open ("calllog", O_RDONLY);
-  lseek (file, (long) (pos * sizeof (struct calllog)), 0);
-  if (!batch_mode)
-    printf ("Scanning call log, please wait...\n");
-  for (a = 0; a < CALLLOG; ++a)
+
+
+  logfp = fopen ("citadel.log", "r");
+  if (logfp == NULL)
+    {
+      perror ("Could not open citadel.log");
+      exit (errno);
+    }
+  else
     {
       if (!batch_mode)
-       progress ((long) a, (long) (CALLLOG - 1));
-      if ((a + pos) == CALLLOG)
-       lseek (file, 0L, 0);
-      read (file, &calllog, sizeof (struct calllog));
-      if (calllog.CLflags != 0)
        {
-         if ((calllog.CLtime < from) || (from == 0L))
-           from = calllog.CLtime;
-         if ((calllog.CLtime > to) || (to == 0L))
-           to = calllog.CLtime;
-         strcpy (aaa, "");
-         if (calllog.CLflags & CL_CONNECT)
-           {
-             ++calls;
-             ++sess;
-             if (sess == 1)
-               cftime = calllog.CLtime;
-             strcpy (dname, calllog.CLfullname);
-           }
-         if (calllog.CLflags & CL_LOGIN)
+         printf ("Scanning call log, please wait...\n");
+       }
+      while (fgets (buf, 256, logfp) != NULL)
+       {
+         buf[strlen (buf) - 1] = 0;
+
+         LogTime = atol (strtok (buf, "|"));
+         LogType = atol (strtok (NULL, "|"));
+         strcpy (LogName, strtok (NULL, "|"));
+
+         if (LogType != 0)
            {
-             ++logins;
-             b = 0;
-             for (callptr = callers; callptr != NULL; callptr = callptr->next)
+             if ((LogTime < from) || (from == 0L))
+               from = LogTime;
+             if ((LogTime > to) || (to == 0L))
+               to = LogTime;
+             strcpy (aaa, "");
+             if (LogType & CL_CONNECT)
+               {
+                 ++calls;
+                 ++sess;
+                 if (sess == 1)
+                   cftime = LogTime;
+                 strcpy (dname, LogName);
+               }
+             if (LogType & CL_LOGIN)
                {
-                 if (!strcmp (callptr->Cname, calllog.CLfullname))
+                 ++logins;
+                 b = 0;
+                 for (callptr = callers; callptr != NULL; callptr = callptr->next)
+                   {
+                     if (!strcmp (callptr->Cname, LogName))
+                       {
+                         ++b;
+                         ++callptr->Ctimescalled;
+                       }
+                   }
+                 if (b == 0)
                    {
-                     ++b;
-                     ++callptr->Ctimescalled;
+                     callptr = (struct caller *) malloc (sizeof (struct caller));
+                     callptr->next = callers;
+                     callers = callptr;
+                     strcpy (callers->Cname, LogName);
+                     callers->Ctimescalled = 1;
                    }
                }
-             if (b == 0)
+             if (LogType & CL_NEWUSER)
+               ++newusers;
+             if (LogType & CL_BADPW)
+               ++badpws;
+             if (LogType & CL_TERMINATE)
                {
-                 callptr = (struct caller *) malloc (sizeof (struct caller));
-                 callptr->next = callers;
-                 callers = callptr;
-                 strcpy (callers->Cname, calllog.CLfullname);
-                 callers->Ctimescalled = 1;
+                 ++terms;
+                 --sess;
+                 if (sess == 0)
+                   {
+                     cttime = LogTime;
+                     for (aa = cftime; aa <= cttime; aa = aa + 300L)
+                       timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
+                     cftime = 0L;
+                     cttime = 0L;
+                   }
                }
-           }
-         if (calllog.CLflags & CL_NEWUSER)
-           ++newusers;
-         if (calllog.CLflags & CL_BADPW)
-           ++badpws;
-         if (calllog.CLflags & CL_TERMINATE)
-           {
-             ++terms;
-             --sess;
-             if (sess == 0)
+             if (LogType & CL_DROPCARR)
                {
-                 cttime = calllog.CLtime;
-                 for (aa = cftime; aa <= cttime; aa = aa + 300L)
-                   timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
-                 cftime = 0L;
-                 cttime = 0L;
+                 ++drops;
+                 --sess;
+                 if (sess == 0)
+                   {
+                     cttime = LogTime;
+                     for (aa = cftime; aa <= cttime; aa = aa + 300L)
+                       timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
+                     cftime = 0L;
+                     cttime = 0L;
+                   }
                }
-           }
-         if (calllog.CLflags & CL_DROPCARR)
-           {
-             ++drops;
-             --sess;
-             if (sess == 0)
+             if (LogType & CL_SLEEPING)
                {
-                 cttime = calllog.CLtime;
-                 for (aa = cftime; aa <= cttime; aa = aa + 300L)
-                   timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
-                 cftime = 0L;
-                 cttime = 0L;
+                 ++sleeps;
+                 --sess;
+                 if (sess == 0)
+                   {
+                     cttime = LogTime;
+                     for (aa = cftime; aa <= cttime; aa = aa + 300L)
+                       timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
+                     cftime = 0L;
+                     cttime = 0L;
+                   }
                }
+
+             if (sess < 0)
+               sess = 0;
+
            }
-         if (calllog.CLflags & CL_SLEEPING)
+       }
+      fclose (logfp);
+      tottime = to - from;
+      days = (int) (tottime / 86400L);
+      hours = (int) ((tottime % 86400L) / 3600L);
+      minutes = (int) ((tottime % 3600L) / 60L);
+
+      printf ("                              Avg/Call Avg/Day  Total\n");
+      disply ("Calls:", calls);
+      disply ("Logins:", logins);
+      disply ("New users:", newusers);
+      disply ("Bad pw attempts:", badpws);
+      disply ("Proper logoffs:", terms);
+      disply ("Carrier drops:", drops);
+      disply ("Sleeping drops:", sleeps);
+
+      printf ("\n");
+      tm = (struct tm *) localtime (&from);
+      printf ("From:              %s", (char *) asctime (localtime (&from)));
+      printf ("To:                %s", (char *) asctime (localtime (&to)));
+      printf ("Total report time: ");
+      printf ("%d days, %d hours, %d minutes\n",
+             days, hours, minutes);
+
+      for (aa = from; aa <= to; aa = aa + 1200L)
+       timeup[halfhour (aa)] = timeup[halfhour (aa)] + 20L;
+      prompt ();
+
+      lowest = GRANULARITY - 1;
+      for (b = 0; b < 72; ++b)
+       {
+         for (a = 0; a <= GRANULARITY; ++a)
            {
-             ++sleeps;
-             --sess;
-             if (sess == 0)
+             p = ((float) timeon[b]) / ((float) timeup[b]) * GRANULARITY;
+             q = (float) a;
+             if (p >= q)
                {
-                 cttime = calllog.CLtime;
-                 for (aa = cftime; aa <= cttime; aa = aa + 300L)
-                   timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
-                 cftime = 0L;
-                 cttime = 0L;
+                 thegraph[(GRANULARITY - 1) - a][b] = '#';
+                 if (lowest > (GRANULARITY - 1) - a)
+                   lowest = (GRANULARITY - 1) - a;
                }
            }
+       }
+
+      printf ("\n\n\n\n\n\n");
+
+      b = ((GRANULARITY - lowest) / 18);
+      if (b < 1)
+       b = 1;
+      for (a = lowest; a < GRANULARITY; a = a + b)
+       printf ("%2d%% |%s\n",
+               100 - (a + 1),
+               thegraph[a]);
+      printf ("    +------------------------------------------------------------------------\n");
+      printf ("     0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20 21 22 23\n");
+      fflush (stdout);
+      prompt ();
+
+      printf ("\n\n\n\n");
 
-         if (sess < 0)
-           sess = 0;
 
+      printf ("Top 20 Callers (sorted by total number of logins)\n");
+      printf ("Calls Avg/Day Username\n");
+      printf ("----- ------- ------------------------------\n");
+      fflush (stdout);
+      sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
+      for (callptr = callers; callptr != NULL; callptr = callptr->next)
+       {
+         fprintf (sortpipe, "%5d %7.2f %-30s\n",
+                  callptr->Ctimescalled,
+                  (((float) callptr->Ctimescalled) / ((float) days)),
+                  callptr->Cname);
        }
-    }
-  close (file);
-  tottime = to - from;
-  days = (int) (tottime / 86400L);
-  hours = (int) ((tottime % 86400L) / 3600L);
-  minutes = (int) ((tottime % 3600L) / 60L);
-
-  printf ("                              Avg/Call Avg/Day  Total\n");
-  disply ("Calls:", calls);
-  disply ("Logins:", logins);
-  disply ("New users:", newusers);
-  disply ("Bad pw attempts:", badpws);
-  disply ("Proper logoffs:", terms);
-  disply ("Carrier drops:", drops);
-  disply ("Sleeping drops:", sleeps);
-
-  printf ("\n");
-  tm = (struct tm *) localtime (&from);
-  printf ("From:              %s", (char *) asctime (localtime (&from)));
-  printf ("To:                %s", (char *) asctime (localtime (&to)));
-  printf ("Total report time: ");
-  printf ("%d days, %d hours, %d minutes\n",
-         days, hours, minutes);
-
-  for (aa = from; aa <= to; aa = aa + 1200L)
-    timeup[halfhour (aa)] = timeup[halfhour (aa)] + 20L;
-  prompt ();
-
-  lowest = GRANULARITY - 1;
-  for (b = 0; b < 72; ++b)
-    {
-      for (a = 0; a <= GRANULARITY; ++a)
+      pclose (sortpipe);
+      while (callers != NULL)
        {
-         p = ((float) timeon[b]) / ((float) timeup[b]) * GRANULARITY;
-         q = (float) a;
-         if (p >= q)
-           {
-             thegraph[(GRANULARITY - 1) - a][b] = '#';
-             if (lowest > (GRANULARITY - 1) - a)
-               lowest = (GRANULARITY - 1) - a;
-           }
+         callptr = callers->next;
+         free (callers);
+         callers = callptr;
        }
-    }
+      prompt ();
 
-  printf ("\n\n\n\n\n\n");
-
-  b = ((GRANULARITY - lowest) / 18);
-  if (b < 1)
-    b = 1;
-  for (a = lowest; a < GRANULARITY; a = a + b)
-    printf ("%2d%% |%s\n",
-           100 - (a + 1),
-           thegraph[a]);
-  printf ("    +------------------------------------------------------------------------\n");
-  printf ("     0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20 21 22 23\n");
-  fflush (stdout);
-  prompt ();
-
-  printf ("\n\n\n\n");
-
-
-  printf ("Top 20 Callers (sorted by total number of logins)\n");
-  printf ("Calls Avg/Day Username\n");
-  printf ("----- ------- ------------------------------\n");
-  fflush (stdout);
-  sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
-  for (callptr = callers; callptr != NULL; callptr = callptr->next)
-    {
-      fprintf (sortpipe, "%5d %7.2f %-30s\n",
-              callptr->Ctimescalled,
-              (((float) callptr->Ctimescalled) / ((float) days)),
-              callptr->Cname);
-    }
-  pclose (sortpipe);
-  while (callers != NULL)
-    {
-      callptr = callers->next;
-      free (callers);
-      callers = callptr;
-    }
-  prompt ();
-
-PC_ONLY_HERE:
-  printf ("Top 20 Contributing Users (post to call ratio)\n");
-  printf ("P/C Ratio Username\n");
-  printf ("--------- ------------------------------\n");
-  fflush (stdout);
-  sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
-  fp = fopen ("usersupp", "r");
-  while ((fp != NULL)
+    PC_ONLY_HERE:
+      printf ("Top 20 Contributing Users (post to call ratio)\n");
+      printf ("P/C Ratio Username\n");
+      printf ("--------- ------------------------------\n");
+      fflush (stdout);
+      sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
+      fp = fopen ("usersupp", "r");
+      while ((fp != NULL)
        && (fread ((char *) &usersupp, sizeof (struct usersupp), 1, fp) > 0))
-    {
-      fprintf (sortpipe, "%9.2f %-30s\n",
-              ((float) usersupp.posted / (float) usersupp.timescalled),
-              usersupp.fullname);
+       {
+         fprintf (sortpipe, "%9.2f %-30s\n",
+                  ((float) usersupp.posted / (float) usersupp.timescalled),
+                  usersupp.fullname);
+       }
+      fclose (fp);
+      pclose (sortpipe);
+      exit (0);
     }
-  fclose (fp);
-  pclose (sortpipe);
-  exit (0);
 }