;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 123.81
;;; Reason:
;;;  Both FTP Server and User now call (tcpa:open-easy-tcp-connection) rather than doing
;;;  it through (open).  Not only is this quicker, but we don't end up hashing pathnames
;;;  that will never be reused.
;;; Written 28-Oct-87 16:57:54 by pld at site LMI Cambridge
;;; while running on Jack Flanders from band 2
;;; with Experimental System 123.80, 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 Boot Tape 3.12, SDU ROM 8.



; From modified file DJ: L.NETWORK.IP-TCP.USER; FTP.LISP#33 at 28-Oct-87 16:57:55
#10R FTP#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "FTP")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; IP-TCP; USER; FTP  "

(defun initconn (direction &optional buffers optimistic)
  (unless (numberp buffers)
    (setq buffers 16.))
  (when *data*
    (close *data*)
    (setq *data* nil))
  (let ((addr nil)
	(port nil)
	(result nil))
    (setq *data* (tcpa:open-easy-tcp-stream (send *control* :remote-address)
					    (sym-value 'tcpa:ipport-ftp-data)
					    (unless *sendport*
					      (send *control* :local-port))
					    :direction direction
					    :input-buffers buffers
					    :output-buffers buffers
					    :optimistic optimistic
					    :keyword "FTP Data Connection"
					    :connect nil))
    (when *sendport*
      (setq addr (send *data* :local-address))
      (setq port (send *data* :local-port))
      (setq result (command "PORT ~D,~D,~D,~D,~D,~D"
			    (ldb (byte 8 24) addr)
			    (ldb (byte 8 16) addr)
			    (ldb (byte 8 8) addr)
			    (ldb (byte 8 0) addr)
			    (ldb (byte 8 8) port)
			    (ldb (byte 8 0) port)))
	(if (= result (sym error))
	    (let ((*sendport* nil))
	      (initconn direction))
	  (not (= result (sym complete)))))))

))

; From modified file DJ: L.NETWORK.IP-TCP.SERVER; FTP.LISP#71 at 28-Oct-87 16:58:14
#10R FTP#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "FTP")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; IP-TCP; SERVER; FTP  "

(defun make-ftp-data-connection (state name size mode)
  mode
  (ftp-reply state 150
	     "Opening data connection ~A(~A,~D)~A"
	     (if name (format nil "for ~A " name) "")
	     (canonical-ip (ftpstate-data-his-address state))
	     (ftpstate-data-his-port state)
	     (if size (format nil " (~D bytes)" size) ""))
  (global:condition-case-if ftp-catch-errors (sig)
      (progn
	(setf (ftpstate-data-my-address state) (send (ftpstate-ctrl-stream state) :local-address))
	(setf (ftpstate-data-my-port state) (sym tcp-application:ipport-ftp-data))
	(setf (ftpstate-data-stream state) (tcpa:open-easy-tcp-stream (ftpstate-data-his-address state)
								      (ftpstate-data-his-port state)
								      (ftpstate-data-my-port state)
								      :keyword "FTP Data Connection"))
	t)
    (error
     (tv:notify nil "FTP SERVER DATA CONNECTION ERROR on ~S ~D:~% ~A"
		(canonical-ip (ftpstate-data-his-address state))
		(ftpstate-data-his-port state)
		(send sig :report-string))
     nil)))

))
