home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES3.ZIP / UUCP / uusub.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-12  |  10.8 KB  |  329 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    u u s u b . c                                                   */
  3. /*                                                                    */
  4. /*    Report summary of UUPC activity                                 */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Copyright (c) 1990-1993 by Kendra Electronic Wonderworks        */
  9. /*                                                                    */
  10. /*    All rights reserved except those explicitly granted by the      */
  11. /*    UUPC/extended license agreement.                                */
  12. /*--------------------------------------------------------------------*/
  13.  
  14. /*--------------------------------------------------------------------*/
  15. /*                          RCS Information                           */
  16. /*--------------------------------------------------------------------*/
  17.  
  18. /*
  19.  *    $Id: uusub.c 1.7 1993/10/12 01:34:47 ahd Exp $
  20.  *
  21.  *    $Log: uusub.c $
  22.  * Revision 1.7  1993/10/12  01:34:47  ahd
  23.  * Normalize comments to PL/I style
  24.  *
  25.  * Revision 1.6  1993/10/03  20:43:08  ahd
  26.  * Normalize comments to C++ double slash
  27.  *
  28.  * Revision 1.5  1993/07/06  11:02:06  ahd
  29.  * Load host status information after parsing args
  30.  *
  31.  * Revision 1.4  1993/05/09  12:44:25  ahd
  32.  * Reset collection time start before writing it out to disk
  33.  *
  34.  * Revision 1.3  1993/04/11  00:35:46  ahd
  35.  * Global edits for year, TEXT, etc.
  36.  *
  37.  * Revision 1.2  1992/11/19  03:03:24  ahd
  38.  * drop rcsid
  39.  *
  40.  */
  41.  
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include <time.h>
  47.  
  48. #include "lib.h"
  49. #include "hostable.h"
  50. #include "dater.h"
  51. #include "hostrset.h"
  52. #include "hostatus.h"
  53. #include "getopt.h"
  54. #include "security.h"
  55. #include "timestmp.h"
  56.  
  57. /*--------------------------------------------------------------------*/
  58. /*                            Local macros                            */
  59. /*--------------------------------------------------------------------*/
  60.  
  61. #define line( a, b, c, d, e, f, g, h, i, j ) \
  62.       printf("%-8.8s %-6.6s %-11.11s %-11.11s %5.5s %5.5s %5.5s %5.5s %5.5s %5.5s\n" ,\
  63.       a, b, c, d, e, f, g, h, i ,j )
  64.  
  65. /*--------------------------------------------------------------------*/
  66. /*                        Internal prototypes                         */
  67. /*--------------------------------------------------------------------*/
  68.  
  69. static void showstats( const char *name );
  70. static void showhost( struct HostTable *host);
  71. static char *when( time_t t );
  72. static char *status( hostatus current_status );
  73. static char *format( long l);
  74.  
  75. /*--------------------------------------------------------------------*/
  76. /*                          Global variables                          */
  77. /*--------------------------------------------------------------------*/
  78.  
  79. static char output[10 * 12];
  80. static size_t column ;
  81.  
  82. currentfile();
  83.  
  84. /*--------------------------------------------------------------------*/
  85. /*    u s a g e                                                       */
  86. /*                                                                    */
  87. /*    Report flags used by program                                    */
  88. /*--------------------------------------------------------------------*/
  89.  
  90. static         void    usage(void)
  91. {
  92.       fprintf(stderr, "Usage: uusub\t[-c] [-s <nodename>] [-x debug]\n");
  93. }
  94.  
  95. /*--------------------------------------------------------------------*/
  96. /*                            main program                            */
  97. /*--------------------------------------------------------------------*/
  98.  
  99. #ifdef __TURBOC__
  100. #pragma argsused
  101. #endif
  102.  
  103. void main( int argc , char **argv)
  104. {
  105.  
  106.    int         option;
  107.    boolean clear_stats = FALSE;
  108.    char *name = nil(char);
  109.  
  110. /*--------------------------------------------------------------------*/
  111. /*               Announce ourselves to a waiting world                */
  112. /*--------------------------------------------------------------------*/
  113.  
  114.    debuglevel = 0;
  115.  
  116. #if defined(__CORE__)
  117.    copywrong = strdup(copyright);
  118.    checkref(copywrong);
  119. #endif
  120.  
  121.    banner( argv );
  122.  
  123. /*--------------------------------------------------------------------*/
  124. /*                        Process option flags                        */
  125. /*--------------------------------------------------------------------*/
  126.  
  127.    while ((option = getopt(argc, argv, "cs:x:")) != EOF)  {
  128.       switch(option)  {
  129.          case 'c':               /* clear stats                       */
  130.             clear_stats = TRUE;
  131.             break;
  132.          case 's':               /* only named host                    */
  133.             name = optarg;
  134.             break;
  135.          case 'x':
  136.             debuglevel = atoi(optarg);
  137.             break;
  138.          default:
  139.             usage();
  140.             exit(1);
  141.             break;
  142.       }
  143.    }
  144.  
  145.    if (optind != argc)
  146.    {
  147.       puts("Extra parameter(s) at end.");
  148.       exit(4);
  149.    }
  150.  
  151. /*--------------------------------------------------------------------*/
  152. /*       Load system configuration and then the UUPC host stats       */
  153. /*--------------------------------------------------------------------*/
  154.  
  155.    if (!configure( B_UUSTAT ))
  156.       panic();
  157.  
  158.    HostStatus();
  159.  
  160. /*--------------------------------------------------------------------*/
  161. /*            Now display or clear the loaded information             */
  162. /*--------------------------------------------------------------------*/
  163.  
  164.    if ( (name != NULL) && (checkreal( name ) == BADHOST) )
  165.        printf("Unknown host \"%s\"\n", name );
  166.    else if (clear_stats)
  167.    {
  168.        if ( name == NULL )
  169.          time( &start_stats );
  170.        HostReset((const char *)name);
  171.    }
  172.    else
  173.        showstats((const char *)name);
  174.  
  175. } /* main */
  176.  
  177. /*--------------------------------------------------------------------*/
  178. /*    s h o w s t a t s                                               */
  179. /*                                                                    */
  180. /*    Display information on all hosts                                */
  181. /*--------------------------------------------------------------------*/
  182.  
  183. static void showstats( const char *name )
  184. {
  185.    struct HostTable *host;
  186.    boolean firsthost = TRUE;
  187.    static const char *dashes = "-----------";
  188.  
  189.    printf("Host information collected since %s\n",ctime( &start_stats ));
  190.  
  191.    line("Host","Host ",  "Date Last",  "Last Conn","Secs" , "Bytes", "Bytes",
  192.          "Files", "Files", "Total");
  193.    line("Name","Status ","Connected ","Attempt", "Conn",  "Sent",  "Recvd",
  194.         "Sent",  "Recvd", "Errs");
  195.    line(dashes,dashes,dashes,dashes,dashes,dashes,dashes,dashes,
  196.          dashes,dashes);
  197.  
  198.    if (name != NULL)
  199.       showhost ( checkreal(name) );
  200.    else
  201.       while  ((host = nexthost( firsthost )) != BADHOST)
  202.       {
  203.          firsthost = FALSE;
  204.          showhost ( host );
  205.       } /* while */
  206.  
  207. } /* showstats */
  208.  
  209. /*--------------------------------------------------------------------*/
  210. /*    s h o w h o s t                                                 */
  211. /*                                                                    */
  212. /*    Display information on a single host                            */
  213. /*--------------------------------------------------------------------*/
  214.  
  215. static void showhost( struct HostTable *host)
  216. {
  217.    column = 0;
  218.    checkref( host->hstats );
  219.    line( host->hostname,
  220.       status( host->hstatus ),
  221.       when( host->hstats->lconnect ),
  222.       when( host->hstats->ltime ),
  223.       format( host->hstats->connect ),
  224.       format( host->hstats->bsent ),
  225.       format( host->hstats->breceived ),
  226.       format( host->hstats->fsent ),
  227.       format( host->hstats->freceived ),
  228.       format( host->hstats->errors  ));
  229. } /* showhost */
  230.  
  231. /*--------------------------------------------------------------------*/
  232. /*                            Subroutines                             */
  233. /*--------------------------------------------------------------------*/
  234.  
  235. static char *when( time_t t )
  236. {
  237.    column += 13;
  238.    return dater( t, &output[column]);
  239. } /* when */
  240.  
  241. static char *format( long l)
  242. {
  243.    if (l == 0)
  244.       return "";
  245.  
  246.    column += 12;
  247.    if ( l <= 99999)
  248.       sprintf( &output[ column ], "%ld", l);
  249.    else if ( (l/1000) <= 9999)
  250.       sprintf( &output[ column ], "%ldK", l / 1000);
  251.    else
  252.       sprintf( &output[ column ], "%ldM", l / 1000000);
  253.    return &output[column];
  254.  
  255. } /* format */
  256.  
  257. static char *status( hostatus current_status )
  258. {
  259.    switch ( current_status )
  260.    {
  261.       default:
  262.        return "??????";
  263.  
  264.       case  phantom:          /* Entry not fully initialized           */
  265.             return "noinit";
  266.  
  267.       case  localhost:        /* This entry is for ourselves           */
  268.             return "local";
  269.  
  270.       case  gatewayed:        /* This entry is delivered to via        */
  271.                               /* an external program on local sys     */
  272.             return "gatway";
  273.  
  274.       case  nocall:           /* real host: never called              */
  275.          return "NEVER";
  276.  
  277.       case autodial:          /* Calling now                          */
  278.          return "DIALNG";
  279.  
  280.       case nodevice:          /* Device open failed                    */
  281.          return "NODEV";
  282.  
  283.       case startup_failed:
  284.          return "NSTART";
  285.  
  286.       case  inprogress:       /* Call now active                       */
  287.          return "INPROG";
  288.  
  289.       case invalid_device:    /* Bad systems file entry               */
  290.          return "INVDEV";
  291.  
  292.       case  callback_req:     /* System must call us back              */
  293.           return "CALLBK";
  294.  
  295.       case  dial_script_failed:
  296.                               /* Hardcoded auto-dial failed           */
  297.          return "NDIALS";
  298.  
  299.       case  dial_failed:      /* Hardcoded auto-dial failed           */
  300.          return "NODIAL";
  301.  
  302.       case  script_failed:    /* script in L.SYS failed               */
  303.          return "NSCRPT";
  304.  
  305.       case  max_retry:        /* Have given up calling this sys        */
  306.          return "MAXTRY";
  307.  
  308.       case  too_soon:         /* In retry mode: too soon to call      */
  309.          return "TOSOON";
  310.  
  311.       case  succeeded:        /* self-explanatory                     */
  312.       case  called:           /* self-explanatory                     */
  313.          return "SUCESS";
  314.  
  315.       case  wrong_host:       /* Call out failed: wrong system        */
  316.          return "WRGHST";
  317.  
  318.       case  unknown_host:     /* Call in cailed: unknown system        */
  319.          return "UNKNWN";
  320.  
  321.       case  wrong_time:       /* Unable to call because of time        */
  322.          return "WRGTIM";
  323.  
  324.       case  call_failed:      /* Connection dropped in mid-call        */
  325.          return "FAILED";
  326.    } /* switch */
  327.  
  328. } /* status */
  329.