;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 123.106
;;; Reason:
;;;  Specify :keyword argument for TCP/UDP :open in TIME and FINGER User functions.
;;; Written 9-Nov-87 14:20:18 by pld at site LMI Cambridge
;;; while running on Djinn from band 2
;;; with Experimental System 123.104, Experimental Local-File 73.0, Experimental FILE-Server 22.0, Experimental Unix-Interface 11.0, Experimental Tape 18.0, Experimental KERMIT 34.0, Experimental ZMail 71.0, Experimental Lambda-Diag 15.0, microcode 1754, SDU ROM 8.



; From modified file DJ: L.NETWORK.IP-TCP.SERVER; TIME.LISP#14 at 9-Nov-87 14:20:31
#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-file (stream (format nil "TCP-HOST:~A.TIMESERVER" host-name) :keyword "TIME User")
    (receive-32b-hbf stream)))

))

; From modified file DJ: L.NETWORK.IP-TCP.SERVER; TIME.LISP#14 at 9-Nov-87 14:20:34
#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-file (stream (format nil "UDP-HOST:~A.TIMESERVER" host-name) :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"))
      (when (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; FINGER.LISP#19 at 9-Nov-87 14:23:43
#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)
  (global:condition-case (obj)
      (with-open-file (stream (format nil "TCP-HOST:~A.FINGER" (send (si:parse-host host) :name))
			      :keyword "FINGER User")
	(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)))
    (tcp:tcp-error obj)))
))
