perm filename UPDATE.OLD[HST,NET]1 blob sn#727520 filedate 1983-09-16 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00008 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	TITLE UPDATE  A B C D E P PDLEN BUFLEN DIN DOUT DVER ERR VERFIL VERPPN HSTFIL HSTPPN ERRFIL ERRPPN NICVER DSKVER PDL DIBUF DOBUF DVIBUF DVOBUF ERBUF BUF ERRORS NIORTS SRINIC HNSPRT ENDMK ENDEND MAIHDR HDRPTR
C00006 00003	 NETSTR NETST1 CPOPJ1 CPOPJ MESTYP MESTY1 MAILMS ERRERR
C00009 00004	 VERNIC VERNI1 VERNI2
C00011 00005	 VERIN VERIN1 VERIN2 VEROUT VEROU1 VEROU2
C00014 00006	 VERCOM VERCO1
C00015 00007	 NEWNIC NEWNI1 NEWNI2 NEWNI3
C00019 00008	 TOPLEV NONEW UPDATE
C00022 ENDMK
C⊗;
TITLE UPDATE ;⊗ A B C D E P PDLEN BUFLEN DIN DOUT DVER ERR VERFIL VERPPN HSTFIL HSTPPN ERRFIL ERRPPN NICVER DSKVER PDL DIBUF DOBUF DVIBUF DVOBUF ERBUF BUF ERRORS NIORTS SRINIC HNSPRT ENDMK ENDEND MAIHDR HDRPTR

;This is a program to automatically keep the binary host table up-to-date.

A←1
B←2
C←3
D←4
E←5
P←17
PDLEN←←20
BUFLEN←←40			;Length of various blocks

DIN←←3				;Disk input channel for HOSTS.TXT file
DOUT←←4				;Disk output channel for HOSTS.TXT file
DVER←←5				;Disk channel for HOSTS.VER file
ERR←←6				;Disk channel for error message file

VERFIL:	SIXBIT/HOSTS/		;LOOKUP/ENTER block for file with NIC version string
	SIXBIT/VER/
	0
	0
VERPPN:	SIXBIT/HSTNET/

HSTFIL:	SIXBIT/HOSTS/		;LOOKUP/ENTER block for NIC host table
	SIXBIT/TXT/
	0
	0
HSTPPN:	SIXBIT/HSTNET/

ERRFIL:	SIXBIT/$MAIL/		;ENTER block for error message mail file
	SIXBIT/TMP/
	0
	0
ERRPPN:	SIXBIT/HSTNET/

NICVER:	BLOCK BUFLEN		;Version string from NIC
DSKVER:	BLOCK BUFLEN		;Version string on disk

PDL:	BLOCK PDLEN
DIBUF:	BLOCK 3			;Buffer headers
DOBUF:	BLOCK 3
DVIBUF:	BLOCK 3
DVOBUF:	BLOCK 3
ERBUF:	BLOCK 3
ERRORS:	0			;-1 if we have errors
CRLF:	BYTE (7)15,12

NIORTS←←-1			;Use network I/O routines
.INSERT NETWRK.FAI[S,NET]	;Wonderful network I/O package

;Host number for SRI-NIC.  We could use HSTNAM, but then we'd lose if there was
;something wrong with the host table.
SRINIC←←<BYTE (4)0(8)=10,0,0,=73>

HNSPRT←←=101			;Host Name Server port number

ENDMK:	12			;Chars that mark end of NIC host table
	"E"
	"N"
	"D"
ENDEND←←.

DEFINE MESSAG(MESS) <
	JRST [  MOVEI A,[ASCIZ\MESS
\]
		JRST MESTYP]
>

;Header lines for error message file
MAIHD1:	ASCIZ\MAIL/SUBJECT BUG-HOST\
MAIHD2:	BYTE (7)15,12,14	;CRLF,FF
MAIHD3:	ASCIZ/Bug report from UPDATE of host tables

/

;Data block for SWAP UUO
MAIBLK:	SIXBIT/SYS/
	SIXBIT/MAIL/
	SIXBIT/DMP/
	0,,1			;RPG startup
	0
	0
;⊗ NETSTR NETST1 CPOPJ1 CPOPJ MESTYP MESTY1 MAILMS ERRERR

;Output a string to current network connection.  Call:
;	MOVEI A,[ASCIZ/string/]
;	PUSHJ P,NETSTR
;	<error return>
;	<normal return>
NETSTR:	HRLI A,440700		;Make byte ptr
NETST1:	ILDB 0,A		;Get char
	JUMPE 0,CPOPJ1		;All done
	PUSHJ P,NETOCH		;Send char
	 POPJ P,		;Error return
	JRST NETST1

CPOPJ1:	AOS (P)
CPOPJ:	POPJ P,

;Here on error messages.  Non-skip return usually causes error return
;from whatever procedure we were executing.
MESTYP:	OUTSTR (A)		;Type error message on terminal
	HRLI A,440700		;Make byte ptr
	SKIPGE ERRORS		;Have there been previous errors?
	JRST MESTY1		;Yes, add current text to output
	SETOM ERRORS		;No, this is the first time we're here
	PUSH P,A		;Save ptr while we output header
	INIT ERR,0		;Open error file
	 SIXBIT/DSK/
	 ERBUF,,0
	 JRST ERRERR
	MOVE 0,ERRPPN
	MOVEM 0,ERRFIL+3
	ENTER ERR,ERRFIL
	 JRST ERRERR
	MOVE A,[POINT 7,MAIHD1]
	PUSHJ P,MESTY1		;Output first part of header
	MOVE A,[POINT 7,MAIHD2]
	PUSHJ P,MESTY1		;Second part
	MOVE A,[POINT 7,MAIHD3]
	PUSHJ P,MESTY1		;Third part
	POP P,A			;Now output message
MESTY1:	ILDB 0,A
	JUMPE 0,CPOPJ
	SOSG ERBUF+2
	OUT ERR,
	CAIA
	JRST ERRERR
	IDPB 0,ERBUF+1
	JRST MESTY1

;Here to mail accumulated error text.
MAILMS:	RELEAS ERR,		;Write out error file
	MOVE 14,ERRFIL		;Set input filename for MAIL
	MOVE 13,ERRFIL+1
	MOVE 11,ERRPPN
	MOVEI 12,0		;No returned message
	MOVEI 0,MAIBLK
	SWAP 0,			;Swap to mail
	POPJ P,			;Here if we get back somehow

;Here for error within an error
ERRERR:	OUTSTR [ASCIZ/Error in writing error file!
/]
	HALT .
;⊗ VERNIC VERNI1 VERNI2

;Here to get version string from the NIC Host Name Server.  Call:
;	PUSHJ P,VERNIC
;	<error return>
;	<success, version string in NICVER>
VERNIC:	MOVE A,[SRINIC]		;Set host number
	MOVEM A,HOST
	MOVEI A,HNSPRT		;And port number
	MOVEM A,ICPSKT
	PUSHJ P,CONECT
	 MESSAG Can't connect to NIC for version request.
	 MESSAG Can't connect to NIC for version request.
	MOVEI A,[ASCIZ/VERSION
/]
	PUSHJ P,NETSTR		;Send a version request
	 MESSAG Error in sending version request.
	PUSHJ P,NETSND		;Force output out
	 MESSAG Error in sending version request.
	;Now read in characters until connection closes.
	MOVE C,[POINT 7,NICVER]	;Ptr to start depositing chars
VERNI1:	PUSHJ P,NETICW		;Get a char
	 JRST [	TRNN 0,20000	;IODEND bit set (connection closed)?
		MESSAG I/O error in version request reply.
		JRST VERNI2]
	IDPB 0,C		;Store char
	CAMN C,[POINT 7,NICVER+BUFLEN-1,34] ;Check for overflow
	MESSAG Buffer overflow in version request reply.
	JRST VERNI1		;Back for more

VERNI2:	MOVEI 0,0		;End with a null
	IDPB 0,C
	PUSHJ P,CLOSER		;Close net connection
	JRST CPOPJ1		;And take success return
;⊗ VERIN VERIN1 VERIN2 VEROUT VEROU1 VEROU2

;Here to get the version string of the current NIC host table on disk.  Call:
;	PUSHJ P,VERIN
;	<error return>
;	<success, version string in DSKVER>
VERIN:	SETZM DSKVER		;In case LOOKUP fails
	INIT DVER,0
	 SIXBIT/DSK/
	 DVOBUF,,DVIBUF
	 MESSAG INIT error for version file input.
	MOVE A,VERPPN
	MOVEM A,VERFIL+3
	LOOKUP DVER,VERFIL
	 JRST CPOPJ1		;If no version file, just return
	MOVE C,[POINT 7,DSKVER]	;Ptr to start depositing chars
VERIN1:	SOSG DVIBUF+2
	IN DVER,
	JRST VERIN2
	GETSTS DVER,A
	TRNN A,IODEND		;End of file?
	MESSAG Input error on version file.
	TDZA 0,0		;End with a null
VERIN2:	ILDB 0,DVIBUF+1
	IDPB 0,C
	JUMPE 0,CPOPJ1		;Null or EOF marks end
	CAMN C,[POINT 7,DSKVER+BUFLEN-1,34] ;Check for overflow
	MESSAG Buffer overflow in version file input.
	JRST VERIN1		;Back for more

;Here to output NIC version string to the file.  Call:
;	<call VERIN; leave DVER channel open>
;	 ...
;	PUSHJ P,VEROUT
;	<error return>
;	<success return>
VEROUT:	MOVE B,VERPPN
	MOVEM B,VERFIL+3
	ENTER DVER,VERFIL	;Open in Read-Alter mode
	 MESSAG ENTER error for version file output.
	USETO DVER,0		;Position at beginning
	MOVE C,[POINT 7,NICVER]
VEROU1:	ILDB 0,C
	JUMPE 0,VEROU2		;Check for end
	SOSG DVOBUF+2
	OUT DVER,
	CAIA
	MESSAG Output error on version file.
	IDPB 0,DVOBUF+1
	JRST VEROU1

VEROU2:	RELEAS DVER,		;Put file in place
	JRST CPOPJ1
;⊗ VERCOM VERCO1

;Here to compare version strings stored in NICVER and DSKVER.  Call:
;	PUSHJ P,VERCOM
;	<return here if the same>
;	<return here if different>
VERCOM:	MOVE C,[POINT 7,NICVER]	;Set byte pointers
	MOVE D,[POINT 7,DSKVER]
VERCO1:	ILDB A,C		;Get a byte from each string
	ILDB B,D
	JUMPE A,[JUMPN B,CPOPJ1	;Exit if at end of first string
		 POPJ P,]
	JUMPE B,CPOPJ1		;Or second
	CAIN A,(B)		;Compare
	JRST VERCO1		;Keep checking
	JRST CPOPJ1		;Different
;⊗ NEWNIC NEWNI1 NEWNI2 NEWNI3

;Here to read in a new table from the NIC Host Name Server.  Call:
;	PUSHJ P,NEWNIC
;	<error return>
;	<success>
NEWNIC:	MOVE A,[SRINIC]		;Set host number
	MOVEM A,HOST
	MOVEI A,HNSPRT		;And port number
	MOVEM A,ICPSKT
	PUSHJ P,CONECT
	 MESSAG Can't connect to NIC for host table request.
	 MESSAG Can't connect to NIC for host table request.
	MOVEI A,[ASCIZ/ALL
/]
	PUSHJ P,NETSTR		;Ask for the whole table
	 MESSAG Error in sending host table request.
	PUSHJ P,NETSND		;Force output out
	 MESSAG Error in sending host table request.

	INIT DOUT,0		;Get ready to write new file
	 SIXBIT/DSK/
	 DOBUF,,0
	 MESSAG INIT error for host table output.
	MOVE A,HSTPPN
	MOVEM A,HSTFIL+3
	ENTER DOUT,HSTFIL
	 MESSAG ENTER error for host table output.
	MOVEI A,346		;Lowcore pointer for optimal number of buffers
	PEEK A,
	HLRZ A,A
	OUTBUF DOUT,(A)
	MOVEI C,0		;Initialize byte count
	MOVEI E,ENDMK		;Initialize endmark tester

NEWNI1:	PUSHJ P,NETICW		;Get a character from the network
	 JRST [ TRNN 0,20000	;Test for connection close
		MESSAG I/O error in host table request reply.
		JRST NEWNI3]
	SOSG DOBUF+2		;Output the character
	OUT DOUT,
	CAIA
	MESSAG Output error in writing host table file.
	IDPB 0,DOBUF+1
	SKIPGE E		;Skip unless already seen endmark
	AOJA C,NEWNI1		;Go back for more
	CAMN 0,(E)		;Compare current char to next in endmark
	AOJA E,NEWNI2		;If same, set up for next char
	MOVEI E,ENDMK		;If different, start test at beginning
	AOJA C,NEWNI1		;Go back for more

NEWNI2:	CAIN E,ENDEND		;Matched entire endmark?
	SETOM E			;Yes, note this
	AOJA C,NEWNI1		;And go finish input

NEWNI3:	OUT DOUT,		;Do last output
	CAIA
	MESSAG Output error in writing host table file.
	SKIPL E			;Was endmark seen?
	MESSAG Endmark of NIC host table not received.
	RELEAS DOUT,		;Yes, put new file in place
	PUSHJ P,CLOSER		;Close net connection
	JRST CPOPJ1		;And take success return
;⊗ TOPLEV NONEW UPDATE

TOPLEV:	OUTSTR [ASCIZ/Getting latest version number from NIC name server.
/]
	PUSHJ P,VERNIC		;Get NIC directory version string
	 POPJ P,		;Error of some kind
	OUTSTR [ASCIZ/NIC's version string is /]
	OUTSTR NICVER
	OUTSTR CRLF
	PUSHJ P,VERIN		;Get version from disk file
	 POPJ P,		;Error
	OUTSTR [ASCIZ/Saved version string is /]
	OUTSTR DSKVER
	OUTSTR CRLF
	PUSHJ P,VERCOM		;Compare version strings
	 JRST NONEW		;No update needed
	OUTSTR [ASCIZ/Getting new host table from NIC name server.
/]
	PUSHJ P,NEWNIC		;Read in the new host table
	 POPJ P,		;Some error
	PUSHJ P,VEROUT		;Output version string to file
	 POPJ P,		;Some error
	OUTSTR [ASCIZ/New host table successfully installed.
/]
;temporary, until we're fully automated
	MOVEI A,[ASCIZ/New NIC host table installed; please run HOSTS3.
/]
	PUSHJ P,MESTYP
	PUSHJ P,MAILMS
;end temporary code
	EXIT

NONEW:	OUTSTR [ASCIZ/No update of NIC host table needed.
/]
	EXIT


UPDATE:	RESET			;Program starts here
	MOVE P,[IOWD PDLEN,PDL]
	PUSHJ P,TOPLEV		;Only returns if some kind of error
	RELEAS DVER,3		;Don't write any files!
	RELEAS DOUT,3
	MOVEI A,[ASCIZ/UPDATE aborted due to errors.
/]
	PUSHJ P,MESTYP
	PUSHJ P,MAILMS		;Mail errors to interested people
	EXIT

	END UPDATE