home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / dial / d_clog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-06-04  |  2.9 KB  |  123 lines

  1. # include  "util.h"
  2. # include  "d_clogcodes.h"
  3. # include  "d_returns.h"
  4. # include  <stdio.h>
  5. # include  "d_proto.h"
  6. # include  "d_structs.h"
  7.  
  8. extern    time_t    time();
  9. extern    char    *ctime();
  10. extern    char    *d_calllog;
  11. extern    char    d_uname[];
  12. extern    int    d_errno;
  13.  
  14. static time_t d_cstime;                /*  time call started  */
  15.  
  16. static char  d_cnumber[30];           /*  the number called  */
  17. static char  d_linetype[30];          /*  the type of dialout line used */
  18.  
  19. /*
  20.  *     D_CSTART
  21.  *
  22.  *     routine called to note the beginning of a call.  the current time is
  23.  *     saved, and if the phone number and user name are given, they are
  24.  *     saved also.
  25.  *
  26.  *     number -- character string which is phone number called
  27.  */
  28.  
  29. d_cstart(number, linetype)
  30.   register char  *number;
  31.   register char  *linetype;
  32.     {
  33.  
  34. /*  get the time and save the number if given  */
  35.  
  36.     time(&d_cstime);
  37.  
  38.     if (number)
  39.       (void) strcpy(d_cnumber, number);
  40.  
  41.     if (linetype)
  42.       (void) strcpy(d_linetype, linetype);
  43.  
  44.     return(D_OK);
  45.     }
  46. /* */
  47.  
  48. /*
  49.  *     D_CLOG
  50.  *
  51.  *     routine which logs calls.  we have to be careful here that
  52.  *     sensitive numbers are protected, but still allow us to see all
  53.  *     long distance calls.  the strategy that's used is to write X's
  54.  *     over the last 4 digits of number which have more than 7 digits.
  55.  *
  56.  *     code -- a character that is written in the file to indicate the
  57.  *             status of call completion
  58.  *     
  59.  */
  60.  
  61. d_clog(code)
  62.   int  code;
  63.     {
  64.     FILE  *clogfptr;
  65.     long duration;
  66.     long  stoptime;
  67.     int  seconds;
  68.     register int  hours, minutes;
  69.  
  70. /* check start time--if zero, this is an extraneous call to d_clog */
  71.     if (d_cstime == 0L) return;
  72.  
  73.  
  74. /*  open the call log file  */
  75.  
  76.     if ((clogfptr = fopen(d_calllog, "a")) == NULL)
  77.       {
  78.       d_errno = D_CALLLOG;
  79.       d_log("d_clog", "can't open call log file"); 
  80.       return;
  81.       }
  82.   
  83. /*  get the stop time and calculate the duration of the session  */
  84.  
  85.     time(&stoptime);
  86.     duration = stoptime - d_cstime;
  87.     /*NOSTRICT*/
  88.     d_cstime = 0L;
  89.     /*NOSTRICT*/
  90.     hours = (int) (duration / 3600);
  91.     /*NOSTRICT*/
  92.     minutes = (int) ((duration - (hours * 3600)) / 60l);
  93.     /*NOSTRICT*/
  94.     seconds = (int) (duration - (hours * 3600) - (minutes * 60));
  95.  
  96.     fprintf(clogfptr, "%-8s  %c  ", d_uname, code);
  97.     fprintf(clogfptr, "%-16.16s  ", d_cnumber);
  98.  
  99. /*  now the time data.  considerable craziness to make a pretty duration  */
  100.  
  101.     fprintf(clogfptr, "%-19.19s  ", ctime(&stoptime));
  102.  
  103.     if (hours > 0)
  104.       fprintf(clogfptr, "%2d:", hours);
  105.     else
  106.       fprintf(clogfptr, "   ");
  107.  
  108.     if (minutes > 0)
  109.       fprintf(clogfptr, "%2d:", minutes);
  110.     else
  111.       if (hours > 0)
  112.         fprintf(clogfptr, "00:", minutes);
  113.       else
  114.         fprintf(clogfptr, " 0:", minutes);
  115.  
  116.     if (seconds > 9)
  117.       fprintf(clogfptr, "%2d   %s\n", seconds, d_linetype);
  118.     else
  119.       fprintf(clogfptr, "0%1d   %s\n", seconds, d_linetype);
  120.  
  121.     fclose(clogfptr);
  122.     }
  123.