home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------*/
- /* h o s t a t u s . c */
- /* */
- /* Load host status information for UUPC/extended */
- /* */
- /* Copyright (c) 1991, Andrew H. Derbyshire */
- /*--------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
-
- #include "lib.h"
- #include "hlib.h"
- #include "hostable.h"
- #include "hostatus.h"
- #include "security.h"
-
- /*--------------------------------------------------------------------*/
- /* Define current file name for panic() and printerr() */
- /*--------------------------------------------------------------------*/
-
- currentfile();
-
- /*--------------------------------------------------------------------*/
- /* Global variables */
- /*--------------------------------------------------------------------*/
-
- time_t start_stats = 0;
-
- void HostStatus( void )
- {
-
- char fname[FILENAME_MAX];
- char buf[BUFSIZ];
- struct HostTable *host;
- FILE *stream;
- size_t len1;
- size_t len2;
-
- mkfilename( fname, spooldir, DCSTATUS );
-
- if ((stream = FOPEN(fname , "r", BINARY)) == NULL)
- {
- printmsg(1,"HostStatus: Unable to open host status file");
- time(&start_stats);
- return;
- }
-
- /*--------------------------------------------------------------------*/
- /* Read the header information */
- /*--------------------------------------------------------------------*/
-
- fread( &len1, sizeof len1, 1, stream );
- fread( &len2, sizeof len2, 1, stream );
- fread( buf , 1, len1, stream);
- buf[len1++] = ' ';
- fread( buf + len1 , 1, len2, stream);
- buf[ len1 + len2 ] = '\0';
- fread( &start_stats , sizeof start_stats , 1, stream);
- printmsg(5,"HostStatus: %s generated by %s beginning %s", fname, buf ,
- ctime(&start_stats));
-
- /*--------------------------------------------------------------------*/
- /* Load each host */
- /*--------------------------------------------------------------------*/
-
- while (!feof( stream ) && !ferror(stream))
- {
- if (fread( &len1, sizeof len1, 1, stream ) < 1)
- break;
- fread( &len2, sizeof len2, 1, stream );
- fread( buf , sizeof host->hostname[0], len1, stream);
- buf[ len1 ] = '\0';
- printmsg(5,"HostStatus: Name length %d, status length %d, \
- host name \"%s\"",
- len1, len2, buf );
- host = checkreal( buf );
-
- if ( host == BADHOST )
- {
- printmsg(1,"HostStatus: Host \"%s\" not found, purging entry",
- buf );
- fread( buf , len2, 1, stream);
- }
- else if ( len2 <= (sizeof *(host->hstats)))
- {
- fread( host->hstats , len2, 1, stream);
- printmsg(5,"HostStatus: Loaded status for host %s",
- host->hostname);
- if (( host->hstats->save_hstatus >= nocall ) &&
- ( host->hstats->save_hstatus < last_status ))
- host->hstatus = host->hstats->save_hstatus;
- else
- printmsg(0,"HostStatus: Invalid status (%d) ignored for \"%s\"",
- host->hstats->save_hstatus,host->hostname ) ;
- }
- else {
- printmsg(5,"HostStatus: Bad record length %d (wanted %d), \
- purging status for host %s", len2, (int) (sizeof *(host->hstats)), buf);
- fread( buf , len2, 1, stream);
- } /* else */
- } /* while */
-
- if (ferror( stream ))
- {
- printerr( fname );
- clearerr( stream );
- }
-
- fclose( stream );
-
- } /* HostStatus */
-