home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES2.ZIP / UUCICO / dcpstats.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-09  |  7.8 KB  |  232 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    File transfer information for UUPC/extended                     */
  3. /*                                                                    */
  4. /*    Copyright (c) 1991, Andrew H. Derbyshire                        */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  9. /*       Wonderworks.                                                 */
  10. /*                                                                    */
  11. /*       All rights reserved except those explicitly granted by       */
  12. /*       the UUPC/extended license agreement.                         */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*
  16.  *       $Id: dcpstats.c 1.7 1993/10/09 22:21:55 rhg Exp $
  17.  *
  18.  *       $Log: dcpstats.c $
  19.  * Revision 1.7  1993/10/09  22:21:55  rhg
  20.  * ANSIfy source
  21.  *
  22.  * Revision 1.6  1993/09/20  04:41:54  ahd
  23.  * OS/2 2.x support
  24.  *
  25.  * Revision 1.5  1993/04/11  00:34:11  ahd
  26.  * Global edits for year, TEXT, etc.
  27.  *
  28.  * Revision 1.4  1993/03/06  23:04:54  ahd
  29.  * Lock host status file before updating
  30.  *
  31.  * Revision 1.3  1992/12/30  13:17:12  ahd
  32.  * Windows/NT changes
  33.  *
  34.  */
  35.  
  36. /*--------------------------------------------------------------------*/
  37. /*                       standard include files                       */
  38. /*--------------------------------------------------------------------*/
  39.  
  40. #include <stdio.h>
  41. #include <string.h>
  42. #include <time.h>
  43. #include <stdlib.h>
  44.  
  45. /*--------------------------------------------------------------------*/
  46. /*                    UUPC/extended include files                     */
  47. /*--------------------------------------------------------------------*/
  48.  
  49. #include "lib.h"
  50. #include "dcp.h"
  51. #include "dcpstats.h"
  52. #include "stater.h"
  53. #include "hlib.h"
  54. #include "hostable.h"
  55. #include "hostatus.h"
  56. #include "security.h"
  57. #include "timestmp.h"
  58. #include "ssleep.h"
  59. #include "lock.h"
  60.  
  61. /*--------------------------------------------------------------------*/
  62. /*                          Global variables                          */
  63. /*--------------------------------------------------------------------*/
  64.  
  65. currentfile();
  66.  
  67. /*--------------------------------------------------------------------*/
  68. /*    d c s t a t s                                                   */
  69. /*                                                                    */
  70. /*    Report transmission information for a connection                */
  71. /*--------------------------------------------------------------------*/
  72.  
  73. void dcstats(void)
  74. {
  75.    if (hostp == BADHOST)
  76.    {
  77.       printmsg(0,"dcstats: host structure pointer is NULL");
  78.       panic();
  79.    }
  80.  
  81.    if (!equal(rmtname , hostp->hostname))
  82.       return;
  83.  
  84.    if (remote_stats.lconnect > 0)
  85.    {
  86.       time_t connected;
  87.       unsigned long bytes;
  88.       unsigned long bps;
  89.  
  90.       HostStatus();
  91.  
  92.       connected = time(NULL) - remote_stats.lconnect;
  93.       remote_stats.connect += connected;
  94.       bytes = remote_stats.bsent + remote_stats.breceived;
  95.  
  96.       if ( connected > 0 )
  97.          bps = bytes / (long unsigned) connected;
  98.       else
  99.          bps = 0;
  100.  
  101.       printmsg(0,"%ld files sent, %ld files received, "
  102.                  "%ld bytes sent, %ld bytes received",
  103.             remote_stats.fsent, remote_stats.freceived ,
  104.             remote_stats.bsent, remote_stats.breceived);
  105.       printmsg(0, "%ld packets transferred, %ld errors, "
  106.                   "connection time %ld:%02ld, %ld bytes/second",
  107.             (long) remote_stats.packets,
  108.             (long) remote_stats.errors,
  109.             (long) connected / 60L, (long) connected % 60L, bps);
  110.  
  111.    } /*if */
  112.    else
  113.       printmsg(0,"Unable to print information for host %s (%s)",
  114.             rmtname,
  115.             hostp->hostname);
  116.  
  117.    if (remote_stats.lconnect > hostp->hstats->lconnect)
  118.       hostp->hstats->lconnect = remote_stats.lconnect;
  119.  
  120.    if (remote_stats.ltime > hostp->hstats->ltime)
  121.       hostp->hstats->lconnect = remote_stats.lconnect;
  122.  
  123.    hostp->hstats->connect   += remote_stats.connect;
  124.    hostp->hstats->calls     += remote_stats.calls;
  125.    hostp->hstats->fsent     += remote_stats.fsent;
  126.    hostp->hstats->freceived += remote_stats.freceived;
  127.    hostp->hstats->bsent     += remote_stats.bsent;
  128.    hostp->hstats->breceived += remote_stats.breceived;
  129.    hostp->hstats->errors    += remote_stats.errors;
  130.    hostp->hstats->packets   += remote_stats.packets;
  131.  
  132. } /* dcstats */
  133.  
  134. /*--------------------------------------------------------------------*/
  135. /*    d c u p d a t e                                                 */
  136. /*                                                                    */
  137. /*    Update the status of all known hosts                            */
  138. /*--------------------------------------------------------------------*/
  139.  
  140. void dcupdate( void )
  141. {
  142.    boolean firsthost = TRUE;
  143.    struct HostTable *host;
  144.    FILE *stream;
  145.    char fname[FILENAME_MAX];
  146.    long size;
  147.    unsigned short len1 = (unsigned short) strlen(compilep);
  148.    unsigned short len2 = (unsigned short) strlen(compilev);
  149.    boolean gotlock;
  150.    short retries = 30;
  151.    LOCKSTACK savelock;
  152.  
  153.    mkfilename( fname, E_confdir, DCSTATUS );
  154.  
  155. /*--------------------------------------------------------------------*/
  156. /*            Save lock status, then lock host status file            */
  157. /*--------------------------------------------------------------------*/
  158.  
  159.    PushLock( &savelock );
  160.  
  161.    do {
  162.       gotlock = LockSystem( "*status", B_UUSTAT );
  163.       if ( ! gotlock )
  164.          ssleep(2);
  165.    } while ( ! gotlock && retries-- );
  166.  
  167.    if ( ! gotlock )
  168.    {
  169.       printmsg(0,"Cannot obtain lock for %s", fname );
  170.       PopLock( &savelock );
  171.       return;
  172.    }
  173.  
  174. /*--------------------------------------------------------------------*/
  175. /*                  Old previous status as required                   */
  176. /*--------------------------------------------------------------------*/
  177.  
  178.    HostStatus();              /* Get new data, if needed          */
  179.  
  180.    filebkup( fname );      /* Rename the file if desired       */
  181.  
  182.    if ((stream  = FOPEN(fname, "w", BINARY_MODE)) == NULL)
  183.    {
  184.       printerr( fname );
  185.       return;
  186.    }
  187.  
  188.    fwrite( &len1, sizeof len1, 1, stream );
  189.    fwrite( &len2, sizeof len2, 1, stream );
  190.    fwrite( compilep , 1, len1, stream);
  191.    fwrite( compilev , 1, len2, stream);
  192.    fwrite( &start_stats , sizeof start_stats , 1,  stream);
  193.  
  194.    while  ((host = nexthost( firsthost )) != BADHOST)
  195.    {
  196.       len1 = (unsigned short) strlen( host->hostname );
  197.       len2 = (unsigned short) sizeof *(host->hstats);
  198.  
  199.       firsthost = FALSE;
  200.  
  201.       fwrite( &len1, sizeof len1, 1, stream );
  202.       fwrite( &len2, sizeof len2, 1, stream );
  203.       fwrite( host->hostname , sizeof hostp->hostname[0], len1, stream);
  204.       host->hstats->save_hstatus = (unsigned short) ((host->hstatus == called)
  205.                                                      ? succeeded
  206.                                                      : host->hstatus);
  207.       fwrite( host->hstats , len2, 1,  stream);
  208.    }
  209.  
  210. /*--------------------------------------------------------------------*/
  211. /*         Make we sure got end of file and not an I/O error          */
  212. /*--------------------------------------------------------------------*/
  213.  
  214.    if (ferror( stream ))
  215.    {
  216.       printerr( fname );
  217.       clearerr( stream );
  218.    }
  219.  
  220.    fclose( stream );
  221.  
  222.    hstatus_age = stater( fname , &size );
  223.  
  224. /*--------------------------------------------------------------------*/
  225. /*                      Restore locks and return                      */
  226. /*--------------------------------------------------------------------*/
  227.  
  228.    UnlockSystem( );
  229.    PopLock( &savelock );
  230.  
  231. } /* dcupdate */
  232.