(FILECREATED "11-Mar-85 13:03:15" {ERIS}<LISPCORE>SOURCES>NSCHAT.;4 11633  

      changes to:  (VARS NSCHATCOMS)
		   (FNS NSCHAT.ATTENTIONFN NSCHAT.OPEN)

      previous date: "15-Jan-85 22:37:42" {ERIS}<LISPCORE>SOURCES>NSCHAT.;3)


(* Copyright (c) 1984, 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT NSCHATCOMS)

(RPAQQ NSCHATCOMS ((COURIERPROGRAMS GAP)
		   (FNS NSCHAT.ATTENTIONFN NSCHAT.ERRORHANDLER NSCHAT.HOST.FILTER NSCHAT.OPEN)
		   (ADDVARS (CHAT.PROTOCOLTYPES (NS . NSCHAT.HOST.FILTER)))
		   (INITVARS (NSCHAT.OPTIONS.MENU))
		   (GLOBALVARS NSCHAT.OPTIONS.MENU)))

(COURIERPROGRAM GAP (3 3)
    TYPES
      ((WaitTime CARDINAL)
       (CharLength (ENUMERATION (five 0)
				(six 1)
				(seven 2)
				(eight 3)))
       (Parity (ENUMERATION (none 0)
			    (odd 1)
			    (even 2)
			    (one 3)
			    (zero 4)))
       (StopBits (ENUMERATION (one 0)
			      (two 1)))
       (FlowControl (RECORD (type (ENUMERATION (none 0)
					       (xOnXOff 1)))
			    (xOn UNSPECIFIED)
			    (xOff UNSPECIFIED)))
       (SessionHandle (ARRAY 2 UNSPECIFIED))
       [SessionParameterObject (CHOICE (xerox800 0 NIL)
				       (xerox850 1 UNSPECIFIED)
				       (xerox860 2 UNSPECIFIED)
				       (system6 3 (RECORD (sendBlockSize CARDINAL)
							  (receiveBlockSize CARDINAL)))
				       (cmcll 4 (RECORD (sendBlockSize CARDINAL)
							(receiveBlockSize CARDINAL)))
				       (ibm2770 5 (RECORD (sendBlockSize CARDINAL)
							  (receiveBlockSize CARDINAL)))
				       (ibm2770Host 6 (RECORD (sendBlockSize CARDINAL)
							      (receiveBlockSize CARDINAL)))
				       (ibm6670 7 (RECORD (sendBlockSize CARDINAL)
							  (receiveBlockSize CARDINAL)))
				       (ibm6670Host 8 (RECORD (sendBlockSize CARDINAL)
							      (receiveBlockSize CARDINAL)))
				       (ibm3270 9 NIL)
				       (ibm3270Host 10 NIL)
				       (OldTtyHost 11 (RECORD (charLength CharLength)
							      (parity Parity)
							      (stopBits StopBits)
							      (frameTimeout CARDINAL)))
				       (OldTty 12 (RECORD (charLength CharLength)
							  (parity Parity)
							  (stopBits StopBits)
							  (frameTimeout CARDINAL)))
				       (other 13 NIL)
				       (unknown 14 NIL)
				       (ibm2780 15 (RECORD (sendBlockSize CARDINAL)
							   (receiveBlockSize CARDINAL)))
				       (ibm2780Host 16 (RECORD (sendBlockSize CARDINAL)
							       (receiveBlockSize CARDINAL)))
				       (ibm3780 17 (RECORD (sendBlockSize CARDINAL)
							   (receiveBlockSize CARDINAL)))
				       (ibm3780Host 18 (RECORD (sendBlockSize CARDINAL)
							       (receiveBlockSize CARDINAL)))
				       (siemens9750 19 NIL)
				       (siemens9750Host 20 NIL)
				       (ttyHost 21 (RECORD (charLength CharLength)
							   (parity Parity)
							   (stopBits StopBits)
							   (frameTimeout CARDINAL)
							   (flowControl FlowControl)))
				       (tty 22 (RECORD (charLength CharLength)
						       (parity Parity)
						       (stopBits StopBits)
						       (frameTimeout CARDINAL)
						       (flowControl FlowControl]
       [TransportObject (CHOICE [rs232c 0 (RECORD (CommParams CommParamObject)
						  (preemptOthers ReserveType)
						  (preemptMe ReserveType)
						  (phoneNumber STRING)
						  (line (CHOICE (alreadyReserved 0
										 (RECORD
										   (resource Resource)
										   ))
								(reserveNeeded 1 (RECORD
										 (lineNumber CARDINAL]
				(bsc 1 (RECORD (localTerminalID STRING)
					       (localSecurityID STRING)
					       (lineControl LineControl)
					       (authenticateProc UNSPECIFIED)))
				(teletype 2 NIL)
				(polledBSCController 3 (RECORD (hostControllerName STRING)
							       (controllerAddress ControllerAddress)
							       (portsOnController CARDINAL)))
				(sdlcController 4 (RECORD (hostControllerName STRING)
							  (controllerAddress ControllerAddress)
							  (portsOnController CARDINAL)))
				(polledBSCTerminal 5 (RECORD (hostControllerName STRING)
							     (terminalAddress TerminalAddress)))
				(sdlcTerminal 6 (RECORD (hostControllerName STRING)
							(terminalAddress TerminalAddress)))
				(service 7 (RECORD (id LONGCARDINAL)))
				(unused 8 NIL)
				(polledBSCPrinter 9 (RECORD (hostControllerName STRING)
							    (printerAddress TerminalAddress)))
				(sdlcPrinter 10 (RECORD (hostControllerName STRING)
							(printerAddress TerminalAddress]
       (Sequence.TransportObject (SEQUENCE TransportObject))
       (BidReply (ENUMERATION (wack 0)
			      (nack 1)
			      (default 2)))
       (ExtendedBoolean (ENUMERATION (true 0)
				     (false 1)
				     (default 2)))
       (DeviceType (ENUMERATION (undefined 0)
				(terminal 1)
				(printer 2)))
       [CommParamObject (RECORD (accessDetail (CHOICE (directConn 0
								  (RECORD (duplex
									    (ENUMERATION
									      (full 0)
									      (half 1)))
									  (lineType LineType)
									  (lineSpeed LineSpeed)))
						      (dialConn (RECORD (duplex (ENUMERATION
										  (full 0)
										  (half 1)))
									(lineType LineType)
									(lineSpeed LineSpeed)
									(dialMode
									  (ENUMERATION (manual 0)
										       (auto 1)))
									(dialerNumber CARDINAL)
									(retryCount CARDINAL]
       (LineType (ENUMERATION (bitSynchronous 0)
			      (byteSynchronous 1)
			      (asynchronous 2)
			      (autoRecognition 3)))
       (LineSpeed (ENUMERATION (bps50 0)
			       (bps75 1)
			       (bps110 2)
			       (bps135p5 3)
			       (bps150 4)
			       (bps300 5)
			       (bps600 6)
			       (bps1200 7)
			       (bps2400 8)
			       (bps3600 9)
			       (bps4800 10)
			       (bps7200 11)
			       (bps9600 12)
			       (bps19200 13)
			       (bps28800 14)
			       (bps38400 15)
			       (bps48000 16)
			       (bps56000 17)
			       (bps57600 18)))
       (LineControl (ENUMERATION (primary 0)
				 (secondary 1)))
       (ControllerAddress CARDINAL)
       (TerminalAddress CARDINAL)
       (credentials (AUTHENTICATION . CREDENTIALS))
       (verifier (AUTHENTICATION . VERIFIER)))
    PROCEDURES
      ((Reset 0)
       (Create 2 (SessionParameterObject Sequence.TransportObject WaitTime credentials verifier)
	       RETURNS
	       (SessionHandle)
	       REPORTS
	       (badAddressFormat controllerAlreadyExists controllerDoesNotExist 
				 dialingHardwareProblem illegalTransport inconsistentParams 
				 mediumConnectFailed noCommunicationHardware noDialingHardware 
				 terminalAddressInUse terminalAddressInvalid tooManyGateStreams 
				 transmissionMediumUnavailable serviceTooBusy userNotAuthenticated 
				 userNotAuthorized serviceNotFound)))
    ERRORS
      ((unimplemented 0)
       (noCommunicationHardware 1)
       (illegalTransport 2)
       (mediumConnectFailed 3)
       (badAddressFormat 4)
       (noDialingHardware 5)
       (dialingHardwareProblem 6)
       (transmissionMediumUnavailable 7)
       (inconsistentParams 8)
       (tooManyGateStreams 9)
       (bugInGAPCode 10)
       (gapNotExported 11)
       (gapCommunicationError 12)
       (controllerAlreadyExists 13)
       (controllerDoesNotExist 14)
       (terminalAddressInUse 15)
       (terminalAddressInvalid 16)))
(DEFINEQ

(NSCHAT.ATTENTIONFN
  [LAMBDA (STREAM ATTNBYTE)                                  (* bvm: "11-Mar-85 13:00")
    [SELECTQ ATTNBYTE
	     (208 -1)
	     [209 (NOTIFY.EVENT (STREAMPROP STREAM (QUOTE MediumUpEvent]
	     (COND
	       ((OR XIPTRACEFLG NSWIZARDFLG)
		 (printout PROMPTWINDOW T "Attention byte: " .I1.8 ATTNBYTE]
    T])

(NSCHAT.ERRORHANDLER
  (LAMBDA (STREAM ERRCODE)                                   (* ejs: "18-Dec-84 20:43")
    (SELECTQ ERRCODE
	     (EOM (SPP.CLEAREOM STREAM))
	     (ATTENTION (SPP.CLEARATTENTION STREAM)
			(NSCHAT.ATTENTIONFN STREAM (BIN STREAM)))
	     (END (ADD.CHAT.MESSAGE STREAM "[Connection closed by remote host]")
		  -1)
	     (COND
	       ((SPP.OPENP STREAM)                           (* non-fatal error?)
		 (ADD.CHAT.MESSAGE STREAM (CONCAT "[SPP error " ERRCODE "]"))
		 (BIN STREAM))
	       (T (\EOF.ACTION STREAM))))))

(NSCHAT.HOST.FILTER
  [LAMBDA (NAME)                                             (* lmm "15-Jan-85 22:19")

          (* * Return NSCHAT.OPEN if NAME is an NS host with a telnet server.)


    (AND \NSFLG (STRPOS ":" NAME)
	 (SETQ NAME (CH.LOOKUP.OBJECT NAME))
	 (LIST (MKATOM NAME)
	       (FUNCTION NSCHAT.OPEN])

(NSCHAT.OPEN
  [LAMBDA (HOST)                                             (* bvm: "11-Mar-85 12:58")

          (* * Return a pair of SPP streams for a chat connection, or NIL. Add CHAT specific operations to the STREAM via 
	  STREAMPROP.)


    (PROG ((MediumUpEvent (CREATE.EVENT))
	   PORT SERVICE OUTSTREAM STREAM HANDLE FAILURE)
          [COND
	    ([NOT (SETQ SERVICE (MENU (OR NSCHAT.OPTIONS.MENU (SETQ NSCHAT.OPTIONS.MENU
					    (create MENU
						    ITEMS ←(QUOTE (("Any" 0 "Unspecified service")
								    ("Remote System Administration"
								      1 
					    "Connect to the remote system administration service")
								    ("Remote System Executive" 2 
								  "Connect to a remote executive")
								    ("Interactive Terminal Service"
								      3 "TTY-based mail service")))
						    TITLE ← "Specific NS Service?"]
	      (RETURN))
	    ((NULL (SETQ PORT (LOOKUP.NS.SERVER HOST)))
	      (SETQ FAILURE "Name not found"))
	    ([NULL (SETQ STREAM (COURIER.OPEN PORT NIL NIL (QUOTE NSCHAT)
					      NIL
					      (QUOTE (EOM.ON.FORCEOUT T ERRORHANDLER 
								      NSCHAT.ERRORHANDLER ATTENTIONFN 
								      NSCHAT.ATTENTIONFN]
                                                             (* No response)
	      )
	    (T (STREAMPROP STREAM (QUOTE MediumUpEvent)
			   MediumUpEvent)
	       (STREAMPROP STREAM (QUOTE EOFPFN)
			   (FUNCTION NSCHAT.EOFPFN))
	       (COND
		 [(NLISTP (SETQ HANDLE (COURIER.CALL STREAM (QUOTE GAP)
						     (QUOTE Create)
						     [QUOTE (tty (seven even two 100
									(none 0 0]
						     (BQUOTE ((service (, SERVICE))
							      (teletype)))
						     15000
						     (CAR (CH.GETAUTHENTICATOR))
						     (CADR (CH.GETAUTHENTICATOR))
						     (QUOTE RETURNERRORS]
		 [(EQ (CAR HANDLE)
		      (QUOTE ERROR))
		   (SETQ FAILURE (SELECTQ (CADR HANDLE)
					  ((REJECT 20)       (* We ought to figure out exactly what error 20 is.
							     Incomplete program declaration)
					    "Service not supported")
					  (SUBSTRING (CDR HANDLE)
						     2 -2]
		 (T (STREAMPROP STREAM (QUOTE SETDISPLAYTYPE)
				(FUNCTION NILL))
		    (STREAMPROP STREAM (QUOTE LOGINFO)
				(FUNCTION NILL))
		    (STREAMPROP STREAM (QUOTE FLUSH&WAIT)
				(FUNCTION NILL))
		    (STREAMPROP STREAM (QUOTE SENDSCREENPARAMS)
				(FUNCTION NILL))
		    (SETQ OUTSTREAM (SPPOUTPUTSTREAM STREAM))
		    (AWAIT.EVENT MediumUpEvent 15000)
		    (SPP.SENDATTENTION OUTSTREAM 209)
		    (RETURN (CONS STREAM OUTSTREAM]
          (printout PROMPTWINDOW T "Could not chat to " HOST " because: " (OR FAILURE "No Response"])
)

(ADDTOVAR CHAT.PROTOCOLTYPES (NS . NSCHAT.HOST.FILTER))

(RPAQ? NSCHAT.OPTIONS.MENU )
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NSCHAT.OPTIONS.MENU)
)
(PUTPROPS NSCHAT COPYRIGHT ("Xerox Corporation" 1984 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (7173 11386 (NSCHAT.ATTENTIONFN 7183 . 7550) (NSCHAT.ERRORHANDLER 7552 . 8152) (
NSCHAT.HOST.FILTER 8154 . 8508) (NSCHAT.OPEN 8510 . 11384)))))
STOP