;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 124.4
;;; Reason:
;;;  Do not force user to login to use TCP versions of band transfer,
;;;  finger, host time.
;;; Written 25-May-88 17:09:20 by pld (Peter L. DeWolf) at site Gigamos Cambridge
;;; while running on Azathoth from band 2
;;; with Experimental System 124.3, Experimental Local-File 74.0, Experimental File-Server 23.0, Experimental Unix-Interface 12.0, Experimental ZMail 72.0, Experimental Tape 23.0, Experimental Lambda-Diag 16.0, microcode 1756, SDU Boot Tape 3.14, SDU ROM 8.



; From modified file DJ: L.NETWORK; TRANSPARENT.LISP#6 at 25-May-88 17:09:30
#10R NETWORK#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "NETWORK")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; TRANSPARENT  "

(export '(define-network-function))

))

; From modified file DJ: L.NETWORK.IP-TCP.SERVER; DISK.LISP#21 at 25-May-88 17:12:29
#10R TCP-APPLICATION#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "TCP-APPLICATION")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; IP-TCP; SERVER; DISK  "

(define-network-function (net:get-remote-disk-unit :internet) (host unit usage &optional initp writep)
  (declare (ignore initp))
  (declare (ignore writep))
  (let ((machine (send host :name))
	(stream)
	(normalp))
    (unwind-protect
	(let ((u (make-instance 'serial-stream-disk-unit
				:stream (setq stream (open-easy-tcp-stream
						           machine
							   (sym-value 'ipport-lmidisk)
							   nil
							   :keyword "Remote DISK access"
							   :input-buffers 8
							   :output-buffers 8))
				:unit-number unit
				:machine-name machine)))
	  (send u :notify (format nil "Disk being hacked remotely by ~A@~A -- ~A"
				  si:user-id (send si:local-host :name)
				  usage))
	  (prog1 u
		 (setq normalp t)))
      (or normalp (not stream) (close stream :abort t)))))

))

; From modified file DJ: L.NETWORK.IP-TCP.SERVER; FINGER.LISP#21 at 25-May-88 17:17:27
#10R TCP-APPLICATION#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "TCP-APPLICATION")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; IP-TCP; SERVER; FINGER  "

(defun finger-internet-host (host user &optional (ostream *standard-output*) style)
  (with-open-stream (stream (open-easy-tcp-stream (send (si:parse-host host) :name)
						  (sym-value 'ipport-finger)
						  nil
						  :keyword "FINGER User"
						  :input-buffers 1
						  :output-buffers 1))
    (let ((ascii-output (ftp:make-ascii-translating-output-stream stream nil))
	  (ascii-input (ftp:make-ascii-translating-input-stream stream nil)))
      (when (and user (> (string-length user) 0))
	(princ user ascii-output))
      (terpri ascii-output)
      (send stream :force-output)
      (format ostream "~2&")
      (when (eq style :brackets)
	(format ostream "[~A]~%" (send (si:parse-host host) :name)))
      (global:stream-copy-until-eof ascii-input ostream))))

))

; From modified file DJ: L.NETWORK.IP-TCP.SERVER; TIME.LISP#16 at 25-May-88 17:33:08
#10R TCP-APPLICATION#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "TCP-APPLICATION")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; IP-TCP; SERVER; TIME  "


(defun time-user-function (host-name)
  (check-type host-name string)
  (with-open-stream (stream (open-easy-tcp-stream host-name
						  (sym-value 'ipport-timeserver)
						  nil
						  :input-buffers 1
						  :output-buffers 0
						  :keyword "TIME User"))
    (receive-32b-hbf stream)))

))

; From modified file DJ: L.NETWORK.IP-TCP.SERVER; TIME.LISP#16 at 25-May-88 17:33:09
#10R TCP-APPLICATION#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "TCP-APPLICATION")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; IP-TCP; SERVER; TIME  "


(defun time-user-function-udp (host-name)
  (check-type host-name string)
  (with-open-stream (stream (open-easy-udp-stream host-name
						  (sym-value 'ipport-timeserver)
						  nil
						  :keyword "TIME User"))
    (let ((pkt (make-string 4)))
      (send stream :write-packet pkt 0 4)
      (dotimes (j 10.)
	(if (send stream :listen) (return nil))
	(global:process-sleep 60. "UDP Time Reply"))
      (and (send stream :listen)
	   (send stream :read-packet pkt)
	   (with-input-from-string (s pkt)
	     (receive-32b-hbf s))))))

))

; From modified file DJ: L.NETWORK.IP-TCP.SERVER; TIME.LISP#16 at 25-May-88 17:33:11
#10R TCP-APPLICATION#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "TCP-APPLICATION")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; IP-TCP; SERVER; TIME  "


(define-network-function (net:get-host-time :internet) (host)
  (when (wait-for-tcp-enabled (* 60. 30.))
    (time-user-function (send host :name))))

))
