(FILECREATED "15-Sep-84 14:39:45" {ERIS}<LISPCORE>SOURCES>CLEARINGHOUSE.;12 49822  

      changes to:  (FNS \CANONICAL.NSHOSTNAME)

      previous date: "14-Sep-84 18:09:42" {ERIS}<LISPCORE>SOURCES>CLEARINGHOUSE.;11)


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

(PRETTYCOMPRINT CLEARINGHOUSECOMS)

(RPAQQ CLEARINGHOUSECOMS [(COMS (* Authentication Protocol)
				(COURIERPROGRAMS AUTHENTICATION)
				(DECLARE: DONTCOPY (CONSTANTS (\AUTHENTICATION.SIMPLE.CREDENTIALS
								0)
							      (\AUTHENTICATION.SOCKET 21))
					  (GLOBALVARS AUTHENTICATION.NET.HINT 
						      \AUTHENTICATION.SERVER.CACHE))
				(INITVARS (AUTHENTICATION.NET.HINT)
					  (\AUTHENTICATION.SERVER.CACHE))
				(ADDVARS (\SYSTEMCACHEVARS \AUTHENTICATION.SERVER.CACHE))
				(FNS HASH.PASSWORD NSLOGIN NS.AUTHENTICATE NS.MAKE.SIMPLE.CREDENTIALS 
				     \AUTHENTICATION.FIND.SERVER))
	(COMS (* Clearinghouse Protocol)
	      (COURIERPROGRAMS CLEARINGHOUSE)
	      (DECLARE: DONTCOPY (CONSTANTS (\CH.BROADCAST.SOCKET 20)
					    (\CH.NULL.PROPERTY -1))
			(RECORDS CHBROADCAST DOMAINCACHE)
			(TEMPLATES CH.PROPERTY)
			(GLOBALVARS LOCAL.CLEARINGHOUSE \CH.CACHE CH.DEFAULT.DOMAIN 
				    CH.DEFAULT.ORGANIZATION CH.NET.HINT \CH.MAINLOCK 
				    NS.SERVER.NAMES.TO.ADDRESSES CLEARINGHOUSE.STRUCTURE.WINDOW 
				    CH.PROPERTIES))
	      (INITVARS (CH.NET.HINT)
			(CH.DEFAULT.DOMAIN NIL)
			(CH.DEFAULT.ORGANIZATION NIL)
			(LOCAL.CLEARINGHOUSE NIL)
			(\CH.CACHE NIL)
			(CLEARINGHOUSE.STRUCTURE.WINDOW NIL)
			(NS.SERVER.NAMES.TO.ADDRESSES NIL)
			(\CH.MAINLOCK (CREATE.MONITORLOCK "Clearinghouse")))
	      (ADDVARS (\SYSTEMCACHEVARS LOCAL.CLEARINGHOUSE \CH.CACHE NS.SERVER.NAMES.TO.ADDRESSES)
		       (CH.PROPERTIES (ALL 0)
				      (MEMBERS 3)
				      (ADDRESS.LIST 4)
				      (AUTHENTICATION.LEVEL 8)
				      (MAILBOXES 31)
				      (FILE.SERVICE 10000)
				      (PRINT.SERVICE 10001)
				      (USER 10003)
				      (MAIL.SERVICE 10004)
				      (CLEARINGHOUSE.SERVICE 10021)
				      (USERGROUP 10022)
				      (USERDATA 20000)
				      (FILESERVER 10)
				      (PRINTSERVER 11)))
	      (COMS (* Clearinghouse names)
		    (DECLARE: DONTCOPY (RECORDS NSNAME)
			      (MACROS UCASE.STREQUAL))
		    (INITRECORDS NSNAME)
		    (SYSRECORDS NSNAME)
		    (P (DEFPRINT (QUOTE NSNAME)
				 (FUNCTION \NSNAME.DEFPRINT)))
		    (PROP COURIERDEF NSNAME NSNAME2)
		    (FNS \NSNAME.DEFPRINT NSNAME.TO.STRING COURIER.READ.NSNAME COURIER.WRITE.NSNAME 
			 COURIER.NSNAME.LENGTH))
	      (COMS (* Finding Clearinghouse)
		    (FNS GETCLEARINGHOUSE \CH.CHECK.CLEARINGHOUSE START.CLEARINGHOUSE 
			 SHOW.CLEARINGHOUSE CH.FINDSERVER \CH.FIND.ORG.SERVER \CH.LOCATE.SERVERS 
			 \CH.PRINT.BLURB \CH.UPDATE.CACHE EQUAL.CH.NAMES PARSE.NSNAME 
			 CH.NAME.TO.STRING CANONICAL.CH.NAME CH.PROPERTY CH.GETAUTHENTICATOR)
		    (FNS CH.SERVERS \CH.GUESS.NEW.PROPERTIES))
	      (COMS (* Clearinghouse calls)
		    (FNS CH.DOMAINS.SERVED CH.CREATE.OBJECT CH.DELETE.OBJECT CH.CANONICAL.NAME 
			 CH.CREATE.ALIAS CH.DELETE.ALIAS CH.LOOKUP.OBJECT CH.DELETE.PROPERTY 
			 LOOKUP.NS.SERVER \CANONICAL.NSHOSTNAME)
		    (FNS CH.LIST.ALIASES CH.LIST.ALIASES.OF CH.LIST.DOMAINS CH.LIST.ORGANIZATIONS 
			 CH.LIST.OBJECTS CH.LIST.PROPERTIES)
		    (FNS CH.ADD.GROUP.PROPERTY CH.ADD.MEMBER CH.RETRIEVE.MEMBERS CH.DELETE.MEMBER 
			 CH.ISMEMBER)
		    (FNS CH.RETRIEVE.ITEM CH.ADD.ITEM.PROPERTY CH.CHANGE.ITEM])



(* Authentication Protocol)


(COURIERPROGRAM AUTHENTICATION (14 2)
    TYPES
      [(CREDENTIALS.TYPE (ENUMERATION (SIMPLE 0)
				      (STRONG 1)))
       [CREDENTIALS (RECORD (TYPE CREDENTIALS.TYPE)
			    (VALUE (SEQUENCE UNSPECIFIED]
       (SIMPLE.CREDENTIALS (CLEARINGHOUSE . NAME))
       (VERIFIER (SEQUENCE UNSPECIFIED))
       (SIMPLE.VERIFIER HASHED.PASSWORD)
       (HASHED.PASSWORD CARDINAL)
       (PROBLEM (ENUMERATION (CredentialsInvalid 0)
			     (VerifierInvalid 1)
			     (InappropriateCredentials 5)))
       (CALL.PROBLEM (ENUMERATION (TooBusy 0)
				  (AccessRightsInsufficient 1)
				  (KeysUnavailable 2)
				  (SimpleKeyDoesNotExist 4)
				  (SimpleKeyAlreadyRegistered 6)
				  (DomainForNewKeyUnavailable 7)
				  (DomainForNewKeyUnknown 8)
				  (DatabaseFull 11)
				  (Other 12)))
       (WHICH (ENUMERATION (notApplicable 0)
			   (Initiator 1)
			   (Recipient 2)
			   (Client 3]
    PROCEDURES
      ((BROADCAST.FOR.SERVERS 0 NIL RETURNS ((CLEARINGHOUSE . NETWORK.ADDRESS.LIST)))
       (CHECK.SIMPLE.CREDENTIALS 2 (CREDENTIALS VERIFIER)
				 RETURNS
				 (BOOLEAN)
				 REPORTS
				 (AUTHENTICATION.ERROR CALL.ERROR))
       (CREATE.SIMPLE.KEY 6 (CREDENTIALS VERIFIER (CLEARINGHOUSE . NAME)
					 HASHED.PASSWORD)
			  RETURNS NIL REPORTS (AUTHENTICATION.ERROR CALL.ERROR))
       (CHANGE.SIMPLE.KEY 7 (CREDENTIALS VERIFIER HASHED.PASSWORD)
			  RETURNS NIL REPORTS (AUTHENTICATION.ERROR CALL.ERROR))
       (DELETE.SIMPLE.KEY 8 (CREDENTIALS VERIFIER (CLEARINGHOUSE . NAME))
			  RETURNS NIL REPORTS (AUTHENTICATION.ERROR CALL.ERROR)))
    ERRORS
      ((AUTHENTICATION.ERROR 2 (PROBLEM))
       (CALL.ERROR 1 (CALL.PROBLEM WHICH))))
(DECLARE: DONTCOPY 
(DECLARE: EVAL@COMPILE 

(RPAQQ \AUTHENTICATION.SIMPLE.CREDENTIALS 0)

(RPAQQ \AUTHENTICATION.SOCKET 21)

(CONSTANTS (\AUTHENTICATION.SIMPLE.CREDENTIALS 0)
	   (\AUTHENTICATION.SOCKET 21))
)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS AUTHENTICATION.NET.HINT \AUTHENTICATION.SERVER.CACHE)
)
)

(RPAQ? AUTHENTICATION.NET.HINT )

(RPAQ? \AUTHENTICATION.SERVER.CACHE )

(ADDTOVAR \SYSTEMCACHEVARS \AUTHENTICATION.SERVER.CACHE)
(DEFINEQ

(HASH.PASSWORD
  [LAMBDA (PASSWORD)                                         (* bvm: " 3-NOV-83 22:35")

          (* Compute remainder mod 65357 of PASSWORD considered as an arbitrary length integer whose 16 bit words, from most
	  to least significant, are the characters in PASSWORD. Uses Horner's rule and properties of modular arithmetic to 
	  do it efficiently.)


    (bind (HASH ← 0) for CHAR instring (MKSTRING PASSWORD)
       do (SETQ HASH (IMOD (IPLUS (ITIMES HASH (CONSTANT (IMOD (EXPT 2 16)
							       65357)))
				  (L-CASECODE (\DECRYPT.PWD.CHAR CHAR)))
			   65357))
       finally (RETURN HASH])

(NSLOGIN
  [LAMBDA (HOST MSG)                                         (* bvm: "23-Aug-84 15:10")
    (\INTERNAL/GETPASSWORD HOST T NIL MSG NIL (QUOTE NS])

(NS.AUTHENTICATE
  [LAMBDA (SIMPLE.CREDENTIALS)                               (* bvm: "15-Aug-84 16:00")

          (* * Checks SIMPLE.CREDENTIALS -- For convenience, if SIMPLE.CREDENTIALS is not a list, creates credentials from 
	  the login for NS::)


    [OR (LISTP SIMPLE.CREDENTIALS)
	(SETQ SIMPLE.CREDENTIALS (NS.MAKE.SIMPLE.CREDENTIALS (\INTERNAL/GETPASSWORD (QUOTE NS::)
										    
									       SIMPLE.CREDENTIALS]
    (PROG ((ADDR (\AUTHENTICATION.FIND.SERVER))
	   RESULT)
          (RETURN (COND
		    ((NULL ADDR)
		      (QUOTE AllDown))
		    (T (SETQ RESULT (COURIER.CALL ADDR (QUOTE AUTHENTICATION)
						  (QUOTE CHECK.SIMPLE.CREDENTIALS)
						  (CAR SIMPLE.CREDENTIALS)
						  (CDR SIMPLE.CREDENTIALS)
						  (QUOTE RETURNERRORS)))
		       (COND
			 ((LISTP RESULT)
			   (CADDR RESULT))
			 (RESULT)
			 (T (QUOTE CredentialsInvalid])

(NS.MAKE.SIMPLE.CREDENTIALS
  [LAMBDA (NAME/PASS)                                        (* bvm: "15-Aug-84 15:30")
    (CONS (COURIER.CREATE (AUTHENTICATION . CREDENTIALS)
			  TYPE ←(QUOTE SIMPLE)
			  VALUE ←(COURIER.WRITE.REP (PARSE.NSNAME (CAR NAME/PASS))
						    (QUOTE AUTHENTICATION)
						    (QUOTE SIMPLE.CREDENTIALS)))
	  (COURIER.WRITE.REP (HASH.PASSWORD (CDR NAME/PASS))
			     (QUOTE AUTHENTICATION)
			     (QUOTE SIMPLE.VERIFIER])

(\AUTHENTICATION.FIND.SERVER
  [LAMBDA NIL                                                (* bvm: " 1-Jul-84 15:26")
                                                             (* Expanding ring broadcast, as defined in Clearinghouse
							     Protocol spec.)
    (PROG (INFO)
          (RETURN (COND
		    [(AND \AUTHENTICATION.SERVER.CACHE
			  (find ADDR in \AUTHENTICATION.SERVER.CACHE
			     suchthat (SELECTQ [CAR (LISTP (COURIER.EXPEDITED.CALL ADDR 
									   \AUTHENTICATION.SOCKET
										   (QUOTE 
										   AUTHENTICATION)
										   (QUOTE 
									    BROADCAST.FOR.SERVERS)
										   (QUOTE 
										     RETURNERRORS]
					       ((NIL ERROR REJECT)
						 NIL)
					       T]
		    ((SETQ INFO (COURIER.BROADCAST.CALL \AUTHENTICATION.SOCKET (QUOTE AUTHENTICATION)
							(QUOTE BROADCAST.FOR.SERVERS)
							NIL NIL AUTHENTICATION.NET.HINT 
							"Authentication servers"))
		      (SETQ \AUTHENTICATION.SERVER.CACHE (APPEND INFO \AUTHENTICATION.SERVER.CACHE))
		      (CAR INFO])
)



(* Clearinghouse Protocol)


(COURIERPROGRAM CLEARINGHOUSE (2 2)
    TYPES
      [(ORGANIZATION STRING)
       (DOMAIN STRING)
       (OBJECT STRING)
       (ORGANIZATION.NAME ORGANIZATION)
       (DOMAIN.NAME NSNAME2)
       (OBJECT.NAME NSNAME)
       (NAME NSNAME)
       (ORGANIZATION.NAME.PATTERN ORGANIZATION)
       (DOMAIN.NAME.PATTERN NSNAME2)
       (OBJECT.NAME.PATTERN NSNAME)
       (PROPERTY LONGCARDINAL)
       (PROPERTIES (SEQUENCE PROPERTY))
       (ITEM (SEQUENCE UNSPECIFIED))
       (NETWORK.ADDRESS NSADDRESS)
       (NETWORK.ADDRESS.LIST (SEQUENCE NETWORK.ADDRESS))
       [AUTHENTICATOR (RECORD (CREDENTIALS (AUTHENTICATION . CREDENTIALS))
			      (VERIFIER (AUTHENTICATION . VERIFIER]
       [MAILBOX.VALUES (RECORD (TIME TIME)
			       (MAIL.SERVICE (SEQUENCE NAME]
       (USERDATA.VALUE (RECORD (LAST.NAME.INDEX CARDINAL)
			       (FILE.SERVICE NAME)))
       (WHICH.ARGUMENT (ENUMERATION (FIRST 1)
				    (SECOND 2)))
       (ARGUMENT.PROBLEM (ENUMERATION (IllegalProperty 10)
				      (IllegalOrganization 11)
				      (IllegalDomain 12)
				      (IllegalObject 13)
				      (NoSuchOrganization 14)
				      (NoSuchDomain 15)
				      (NoSuchObject 16)))
       (CALL.PROBLEM (ENUMERATION (AccessRightsInsufficient 1)
				  (TooBusy 2)
				  (ServerDown 3)
				  (USE.COURIER 4)
				  (Other 5)))
       (PROPERTY.PROBLEM (ENUMERATION (Missing 20)
				      (WrongType 21)))
       (UPDATE.PROBLEM (ENUMERATION (NoChange 30)
				    (OutOfDate 31)
				    (ObjectOverflow 32)
				    (DatabaseOverflow 33]
    PROCEDURES
      ((RETRIEVE.ADDRESSES 0 NIL RETURNS (NETWORK.ADDRESS.LIST)
			   REPORTS
			   (CALL.ERROR))
       (LIST.DOMAINS.SERVED 1 (BULK.DATA.SINK AUTHENTICATOR)
			    RETURNS NIL REPORTS (CALL.ERROR))
       (CREATE.OBJECT 2 (OBJECT.NAME AUTHENTICATOR)
		      RETURNS NIL REPORTS (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR 
							  UPDATE.ERROR WRONG.SERVER))
       (DELETE.OBJECT 3 (OBJECT.NAME AUTHENTICATOR)
		      RETURNS NIL REPORTS (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR 
							  UPDATE.ERROR WRONG.SERVER))
       (LOOKUP.OBJECT 4 (OBJECT.NAME.PATTERN AUTHENTICATOR)
		      RETURNS
		      (OBJECT.NAME)
		      REPORTS
		      (ARGUMENT.ERROR CALL.ERROR WRONG.SERVER))
       (LIST.ORGANIZATIONS 5 (ORGANIZATION.NAME.PATTERN BULK.DATA.SINK AUTHENTICATOR)
			   RETURNS NIL REPORTS (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR 
							       WRONG.SERVER))
       (LIST.DOMAINS 6 (DOMAIN.NAME.PATTERN BULK.DATA.SINK AUTHENTICATOR)
		     RETURNS NIL REPORTS (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR WRONG.SERVER)
		     )
       (LIST.OBJECTS 7 (OBJECT.NAME.PATTERN PROPERTY BULK.DATA.SINK AUTHENTICATOR)
		     RETURNS NIL REPORTS (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR WRONG.SERVER)
		     )
       (LIST.ALIASES 8 (OBJECT.NAME.PATTERN BULK.DATA.SINK AUTHENTICATOR)
		     RETURNS NIL REPORTS (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR WRONG.SERVER)
		     )
       (LIST.ALIASES.OF 9 (OBJECT.NAME.PATTERN BULK.DATA.SINK AUTHENTICATOR)
			RETURNS
			(OBJECT.NAME)
			REPORTS
			(ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR WRONG.SERVER))
       (CREATE.ALIAS 10 (OBJECT.NAME OBJECT.NAME AUTHENTICATOR)
		     RETURNS
		     (OBJECT.NAME)
		     REPORTS
		     (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR UPDATE.ERROR WRONG.SERVER))
       (DELETE.ALIAS 11 (OBJECT.NAME AUTHENTICATOR)
		     RETURNS
		     (OBJECT.NAME)
		     REPORTS
		     (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR UPDATE.ERROR WRONG.SERVER))
       (ADD.GROUP.PROPERTY 12 (OBJECT.NAME PROPERTY BULK.DATA.SOURCE AUTHENTICATOR)
			   RETURNS
			   (OBJECT.NAME)
			   REPORTS
			   (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR PROPERTY.ERROR 
					   UPDATE.ERROR WRONG.SERVER))
       (ADD.ITEM.PROPERTY 13 (OBJECT.NAME PROPERTY ITEM AUTHENTICATOR)
			  RETURNS
			  (OBJECT.NAME)
			  REPORTS
			  (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR PROPERTY.ERROR UPDATE.ERROR 
					  WRONG.SERVER))
       (DELETE.PROPERTY 14 (OBJECT.NAME PROPERTY AUTHENTICATOR)
			RETURNS
			(OBJECT.NAME)
			REPORTS
			(ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR PROPERTY.ERROR UPDATE.ERROR 
					WRONG.SERVER))
       (LIST.PROPERTIES 15 (OBJECT.NAME.PATTERN AUTHENTICATOR)
			RETURNS
			(OBJECT.NAME PROPERTIES)
			REPORTS
			(ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR WRONG.SERVER))
       (RETRIEVE.ITEM 16 (OBJECT.NAME.PATTERN PROPERTY AUTHENTICATOR)
		      RETURNS
		      (OBJECT.NAME ITEM)
		      REPORTS
		      (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR PROPERTY.ERROR WRONG.SERVER))
       (CHANGE.ITEM 17 (OBJECT.NAME PROPERTY ITEM AUTHENTICATOR)
		    RETURNS
		    (OBJECT.NAME)
		    REPORTS
		    (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR PROPERTY.ERROR UPDATE.ERROR 
				    WRONG.SERVER))
       (RETRIEVE.MEMBERS 18 (OBJECT.NAME.PATTERN PROPERTY BULK.DATA.SINK AUTHENTICATOR)
			 RETURNS
			 (OBJECT.NAME)
			 REPORTS
			 (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR PROPERTY.ERROR WRONG.SERVER))
       (ADD.MEMBER 19 (OBJECT.NAME PROPERTY NSNAME AUTHENTICATOR)
		   RETURNS
		   (OBJECT.NAME)
		   REPORTS
		   (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR PROPERTY.ERROR UPDATE.ERROR 
				   WRONG.SERVER))
       (ADD.SELF 20 (OBJECT.NAME PROPERTY AUTHENTICATOR)
		 RETURNS
		 (OBJECT.NAME)
		 REPORTS
		 (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR PROPERTY.ERROR UPDATE.ERROR 
				 WRONG.SERVER))
       (DELETE.MEMBER 21 (OBJECT.NAME PROPERTY NSNAME AUTHENTICATOR)
		      RETURNS
		      (OBJECT.NAME)
		      REPORTS
		      (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR PROPERTY.ERROR UPDATE.ERROR 
				      WRONG.SERVER))
       (DELETE.SELF 22 (OBJECT.NAME PROPERTY AUTHENTICATOR)
		    RETURNS
		    (OBJECT.NAME)
		    REPORTS
		    (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR PROPERTY.ERROR UPDATE.ERROR 
				    WRONG.SERVER))
       (IS.MEMBER 23 (OBJECT.NAME.PATTERN PROPERTY PROPERTY NSNAME AUTHENTICATOR)
		  RETURNS
		  (BOOLEAN OBJECT.NAME)
		  REPORTS
		  (ARGUMENT.ERROR AUTHENTICATION.ERROR CALL.ERROR PROPERTY.ERROR WRONG.SERVER)))
    ERRORS
      [(CALL.ERROR 1 (CALL.PROBLEM))
       (ARGUMENT.ERROR 2 (ARGUMENT.PROBLEM WHICH.ARGUMENT))
       (PROPERTY.ERROR 3 (PROPERTY.PROBLEM OBJECT.NAME))
       (UPDATE.ERROR 4 (UPDATE.PROBLEM BOOLEAN WHICH.ARGUMENT OBJECT.NAME))
       (WRONG.SERVER 5 (OBJECT.NAME))
       (AUTHENTICATION.ERROR 6 ((AUTHENTICATION . PROBLEM])
(DECLARE: DONTCOPY 
(DECLARE: EVAL@COMPILE 

(RPAQQ \CH.BROADCAST.SOCKET 20)

(RPAQQ \CH.NULL.PROPERTY -1)

(CONSTANTS (\CH.BROADCAST.SOCKET 20)
	   (\CH.NULL.PROPERTY -1))
)

[DECLARE: EVAL@COMPILE 

(ACCESSFNS CHBROADCAST ((CHBROADCASTBODY (fetch (PACKETEXCHANGEXIP PACKETEXCHANGEBODY) of DATUM)))
		       (BLOCKRECORD CHBROADCASTBODY ((LOW.VERSION WORD)
				     (HIGH.VERSION WORD)
				     (MSGTYPE WORD)
				     (ZERO2 WORD)
				     (PROGRAM# FIXP)
				     (VERSION# WORD)
				     (ZERO3 WORD))))

(RECORD DOMAINCACHE (DCDOMAIN DCKNOWNSERVERS DCHINTSERVERS DCCOMPLETE))
]

(SETTEMPLATE (QUOTE CH.PROPERTY)
	     (QUOTE (PROP)))

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS LOCAL.CLEARINGHOUSE \CH.CACHE CH.DEFAULT.DOMAIN CH.DEFAULT.ORGANIZATION CH.NET.HINT 
	    \CH.MAINLOCK NS.SERVER.NAMES.TO.ADDRESSES CLEARINGHOUSE.STRUCTURE.WINDOW CH.PROPERTIES)
)
)

(RPAQ? CH.NET.HINT )

(RPAQ? CH.DEFAULT.DOMAIN NIL)

(RPAQ? CH.DEFAULT.ORGANIZATION NIL)

(RPAQ? LOCAL.CLEARINGHOUSE NIL)

(RPAQ? \CH.CACHE NIL)

(RPAQ? CLEARINGHOUSE.STRUCTURE.WINDOW NIL)

(RPAQ? NS.SERVER.NAMES.TO.ADDRESSES NIL)

(RPAQ? \CH.MAINLOCK (CREATE.MONITORLOCK "Clearinghouse"))

(ADDTOVAR \SYSTEMCACHEVARS LOCAL.CLEARINGHOUSE \CH.CACHE NS.SERVER.NAMES.TO.ADDRESSES)

(ADDTOVAR CH.PROPERTIES (ALL 0)
			(MEMBERS 3)
			(ADDRESS.LIST 4)
			(AUTHENTICATION.LEVEL 8)
			(MAILBOXES 31)
			(FILE.SERVICE 10000)
			(PRINT.SERVICE 10001)
			(USER 10003)
			(MAIL.SERVICE 10004)
			(CLEARINGHOUSE.SERVICE 10021)
			(USERGROUP 10022)
			(USERDATA 20000)
			(FILESERVER 10)
			(PRINTSERVER 11))



(* Clearinghouse names)

(DECLARE: DONTCOPY 
[DECLARE: EVAL@COMPILE 

(DATATYPE NSNAME ((NSOBJECT POINTER)
		  (NSDOMAIN POINTER)
		  (NSORGANIZATION POINTER))                  (* Canonical three-part Clearinghouse name)
		 )
]
(/DECLAREDATATYPE (QUOTE NSNAME)
		  (QUOTE (POINTER POINTER POINTER)))

(DECLARE: EVAL@COMPILE 

(PUTPROPS UCASE.STREQUAL MACRO ((X Y)
				(EQ (ALPHORDER X Y UPPERCASEARRAY)
				    (QUOTE EQUAL))))
)
)
(/DECLAREDATATYPE (QUOTE NSNAME)
		  (QUOTE (POINTER POINTER POINTER)))
[ADDTOVAR SYSTEMRECLST

(DATATYPE NSNAME ((NSOBJECT POINTER)
		  (NSDOMAIN POINTER)
		  (NSORGANIZATION POINTER)))
]
(DEFPRINT (QUOTE NSNAME)
	  (FUNCTION \NSNAME.DEFPRINT))

(PUTPROPS NSNAME COURIERDEF (COURIER.READ.NSNAME COURIER.WRITE.NSNAME COURIER.NSNAME.LENGTH))

(PUTPROPS NSNAME2 COURIERDEF (COURIER.READ.NSNAME COURIER.WRITE.NSNAME))
(DEFINEQ

(\NSNAME.DEFPRINT
  [LAMBDA (NAME STREAM)                                      (* bvm: "28-Jun-84 16:36")
    (LIST (NSNAME.TO.STRING NAME])

(NSNAME.TO.STRING
  [LAMBDA (NSNAME FULLNAMEFLG)                               (* bvm: "14-Jun-84 12:45")
    (PROG ((OBJ (fetch NSOBJECT of NSNAME))
	   (DOM (fetch NSDOMAIN of NSNAME))
	   (ORG (fetch NSORGANIZATION of NSNAME))
	   (COLON ":"))
          (RETURN (COND
		    ((NOT OBJ)                               (* Two-part name)
		      (CONCAT DOM COLON ORG))
		    ((OR FULLNAMEFLG (NOT (UCASE.STREQUAL ORG CH.DEFAULT.ORGANIZATION)))
                                                             (* No defaults)
		      (CONCAT OBJ COLON DOM COLON ORG))
		    (T (CONCAT OBJ COLON (COND
				 ((UCASE.STREQUAL DOM CH.DEFAULT.DOMAIN)
				   "")
				 (T DOM])

(COURIER.READ.NSNAME
  [LAMBDA (STREAM PROGRAM TYPE)                              (* bvm: "27-Jun-84 15:41")

          (* * Read a Clearinghouse name: 3 strings, or 2 strings if reading a 2-part name)


    (create NSNAME
	    NSORGANIZATION ←(COURIER.READ.STRING STREAM)
	    NSDOMAIN ←(COURIER.READ.STRING STREAM)
	    NSOBJECT ←(AND (EQ TYPE (QUOTE NSNAME))
			   (COURIER.READ.STRING STREAM])

(COURIER.WRITE.NSNAME
  [LAMBDA (STREAM NAME PROGRAM TYPE)                         (* bvm: "27-Jun-84 15:43")
    [COURIER.WRITE.STRING STREAM (ffetch NSORGANIZATION of (\DTEST NAME (QUOTE NSNAME]
    (COURIER.WRITE.STRING STREAM (ffetch NSDOMAIN of NAME))
    (COND
      ((EQ TYPE (QUOTE NSNAME))                              (* full 3-part name)
	(COURIER.WRITE.STRING STREAM (ffetch NSOBJECT of NAME])

(COURIER.NSNAME.LENGTH
  [LAMBDA (NSNAME PROGRAM TYPE)                              (* bvm: " 3-Jul-84 17:35")
    (IPLUS [COND
	     ((EQ TYPE (QUOTE NSNAME2))
	       0)
	     (T (COURIER.REP.LENGTH (fetch NSOBJECT of NSNAME)
				    NIL
				    (QUOTE STRING]
	   (COURIER.REP.LENGTH (fetch NSDOMAIN of NSNAME)
			       NIL
			       (QUOTE STRING))
	   (COURIER.REP.LENGTH (fetch NSORGANIZATION of NSNAME)
			       NIL
			       (QUOTE STRING])
)



(* Finding Clearinghouse)

(DEFINEQ

(GETCLEARINGHOUSE
  [LAMBDA NIL                                                (* bvm: "22-Jul-84 21:55")
    (COND
      ((AND CH.DEFAULT.DOMAIN CH.DEFAULT.ORGANIZATION LOCAL.CLEARINGHOUSE))
      (T (WITH.MONITOR \CH.MAINLOCK (COND
			 ((COURIER.BROADCAST.CALL \CH.BROADCAST.SOCKET (QUOTE CLEARINGHOUSE)
						  (QUOTE RETRIEVE.ADDRESSES)
						  NIL
						  (FUNCTION \CH.CHECK.CLEARINGHOUSE)
						  CH.NET.HINT "Clearinghouse servers")
			   LOCAL.CLEARINGHOUSE)
			 (T (ERROR "Can't find a Clearinghouse" NIL T])

(\CH.CHECK.CLEARINGHOUSE
  [LAMBDA (ADDRESSES)                                        (* bvm: "15-Aug-84 12:49")
    (PROG ((ADDR (BESTNSADDRESS ADDRESSES T))
	   DOMAINS DEFAULT)
          (RETURN (COND
		    ([AND ADDR (SETQ DOMAINS (CH.DOMAINS.SERVED ADDR))
			  (find old DEFAULT in DOMAINS
			     suchthat (PROGN                 (* Skip over the stupid ...:...
							     domain)
					     (NOT (STREQUAL (fetch NSORGANIZATION of DEFAULT)
							    "..."]
		      (COND
			((OR (NULL CH.DEFAULT.DOMAIN)
			     (NULL CH.DEFAULT.ORGANIZATION))
                                                             (* Use the first domain that this server serves to set 
							     the default domain and organization.)
                                                             (* Skip over the stupid ...:...
							     domain)
			  (printout PROMPTWINDOW T "[Default Clearinghouse domain set to "
				    (SETQ CH.DEFAULT.DOMAIN (fetch NSDOMAIN of DEFAULT))
				    ":"
				    (SETQ CH.DEFAULT.ORGANIZATION (fetch NSORGANIZATION of DEFAULT))
				    "]")))
		      (\CH.UPDATE.CACHE (create NSNAME
						NSOBJECT ←(MKSTRING ADDR)
						NSDOMAIN ← "CHServers"
						NSORGANIZATION ← "CHServers")
					ADDR DOMAINS)
		      (SETQ LOCAL.CLEARINGHOUSE ADDR])

(START.CLEARINGHOUSE
  [LAMBDA (RESTARTFLG)                                       (* bvm: "27-Jun-84 10:57")
    (COND
      ((OR RESTARTFLG (NULL LOCAL.CLEARINGHOUSE))
	(SETQ \NS.ROUTING.TABLE.RADIUS 5)
	(SETQ NS.SERVER.NAMES.TO.ADDRESSES (SETQ \CH.CACHE (SETQ LOCAL.CLEARINGHOUSE NIL)))
	(GETCLEARINGHOUSE)))
    LOCAL.CLEARINGHOUSE])

(SHOW.CLEARINGHOUSE
  [LAMBDA (ENTIRE.CLEARINGHOUSE? DONT.GRAPH)                 (* bvm: "23-Jun-84 16:11")
    (PROG (SEXPR)
          [SETQ SEXPR (CONS "" (COND
			      [ENTIRE.CLEARINGHOUSE?         (* Find all domains in all organizations.)
						     (for ORG in (CH.LIST.ORGANIZATIONS "*")
							collect (CONS ORG (CH.LIST.DOMAINS
									(CONCAT "*:" ORG]
			      (T                             (* Use cached structure.)
				 (for ORG in \CH.CACHE collect (CONS (CAR ORG)
								     (for DOM in (CDR ORG)
									collect (fetch DCDOMAIN
										   of DOM]
          (COND
	    (DONT.GRAPH (RETURN SEXPR)))
          (FILESLOAD (SYSLOAD FROM VALUEOF LISPUSERSDIRECTORIES)
		     GRAPHER)
          (SETQ CLEARINGHOUSE.STRUCTURE.WINDOW (SHOWGRAPH (LAYOUTSEXPR SEXPR (QUOTE HORIZONTAL)
								       NIL
								       (QUOTE (HELVETICA 10 BOLD)))
							  (OR CLEARINGHOUSE.STRUCTURE.WINDOW 
							      "Clearinghouse structure")))
          [WINDOWPROP CLEARINGHOUSE.STRUCTURE.WINDOW (QUOTE CLOSEFN)
		      (FUNCTION (LAMBDA NIL
			  (SETQ CLEARINGHOUSE.STRUCTURE.WINDOW NIL]
          (RETURN CLEARINGHOUSE.STRUCTURE.WINDOW])

(CH.FINDSERVER
  [LAMBDA (DOMAINPATTERN NOERRORFLG DONTPROBEFLG)            (* bvm: "28-Jun-84 16:37")
                                                             (* Find a Clearinghouse which serves the specified 
							     domain and return its NS address.
							     If DONTPROBEFLG is T, just search the cache.)
    (OR (type? NSNAME DOMAINPATTERN)
	(SETQ DOMAINPATTERN (PARSE.NSNAME DOMAINPATTERN 2)))
    (PROG ((ORGANIZATION (fetch NSORGANIZATION of DOMAINPATTERN))
	   (DOMAIN (fetch NSDOMAIN of DOMAINPATTERN))
	   ORGANIZATION.INFO)
          (SETQ ORGANIZATION.INFO (\CH.FIND.ORG.SERVER ORGANIZATION NOERRORFLG DONTPROBEFLG))
          (RETURN (COND
		    [(for DOMAIN.INFO in ORGANIZATION.INFO when (UCASE.STREQUAL (fetch DCDOMAIN
										   of DOMAIN.INFO)
										DOMAIN)
			do (RETURN (CAR (CAR (fetch DCKNOWNSERVERS of DOMAIN.INFO]
		    (DONTPROBEFLG (AND (NOT NOERRORFLG)
				       (ERROR "Couldn't find Clearinghouse server for domain" 
					      DOMAINPATTERN T)))
		    (T 

          (* Ask a clearinghouse in ORGANIZATION to find servers for this domain. For simplicity, assume the first one will 
	  tell us. This should be "Local Clearinghouse" if it serves ORGANIZATION)


		       (\CH.LOCATE.SERVERS [CAR (CAR (fetch DCKNOWNSERVERS of (CAR ORGANIZATION.INFO]
					   (create NSNAME
						   NSOBJECT ← DOMAIN
						   NSDOMAIN ← ORGANIZATION
						   NSORGANIZATION ← "CHServers")
					   NOERRORFLG ORGANIZATION DOMAIN)
		       (CH.FINDSERVER DOMAINPATTERN NOERRORFLG T])

(\CH.FIND.ORG.SERVER
  [LAMBDA (ORGANIZATION NOERRORFLG DONTPROBEFLG)             (* bvm: " 4-Jul-84 16:15")
    (COND
      [(CDR (find ORGINFO in \CH.CACHE suchthat (UCASE.STREQUAL (CAR ORGINFO)
								ORGANIZATION]
      ((UCASE.STREQUAL ORGANIZATION "CHServers")             (* Everyone handles this org)
	(GETCLEARINGHOUSE)
	[SETQ \CH.CACHE (NCONC1 \CH.CACHE (SETQ ORGANIZATION
				  (CONS ORGANIZATION (CONS [create DOMAINCACHE
								   DCDOMAIN ← ORGANIZATION
								   DCKNOWNSERVERS ←(fetch 
										   DCKNOWNSERVERS
										      of
										       (CADR
											 (CAR 
											\CH.CACHE]
							   (for ORGINFO in \CH.CACHE
							      collect (create DOMAINCACHE
									      DCDOMAIN ←(CAR ORGINFO)
									      DCKNOWNSERVERS ←(CADR
										ORGINFO]
	(CDR ORGANIZATION))
      (DONTPROBEFLG (AND (NOT NOERRORFLG)
			 (ERROR "Couldn't find Clearinghouse server for organization" ORGANIZATION T))
		    )
      (T (\CH.LOCATE.SERVERS (GETCLEARINGHOUSE)
			     (create NSNAME
				     NSOBJECT ← ORGANIZATION
				     NSDOMAIN ← "CHServers"
				     NSORGANIZATION ← "CHServers")
			     NOERRORFLG ORGANIZATION)
	 (\CH.FIND.ORG.SERVER ORGANIZATION NOERRORFLG T])

(\CH.LOCATE.SERVERS
  [LAMBDA (CHSERVER SERVERGROUP NOERRORFLG ORGANIZATION DOMAIN)
                                                             (* bvm: "15-Aug-84 16:35")

          (* * Talks to clearinghouse CHSERVER asking it to enumerate the class of servers SERVERGROUP.
	  We then locate each server and update the cache)


    (PROG (STREAM CHLIST CHNAMES NOROUTE)
          (\CH.PRINT.BLURB "Finding Clearinghouse server for " DOMAIN ORGANIZATION)
          (OR [COND
		((SETQ STREAM (COURIER.OPEN CHSERVER NIL NOERRORFLG (QUOTE CLEARINGHOUSE)))
		  [RESETLST (RESETSAVE NIL (LIST (FUNCTION \SPP.RESETCLOSE)
						 STREAM))
			    (COND
			      ((AND (SETQ CHNAMES (CH.RETRIEVE.MEMBERS SERVERGROUP
								       (CH.PROPERTY (QUOTE MEMBERS))
								       STREAM))
				    (NEQ (CAR CHNAMES)
					 (QUOTE ERROR)))
				(SETQ CHLIST (SORT.NSADDRESSES.BY.DISTANCE
				    (for CH in CHNAMES bind INFO when (SETQ INFO
									(COURIER.CALL
									  STREAM
									  (QUOTE CLEARINGHOUSE)
									  (QUOTE RETRIEVE.ITEM)
									  CH
									  (CH.PROPERTY (QUOTE 
										     ADDRESS.LIST))
									  (CH.GETAUTHENTICATOR)
									  (QUOTE NOERROR)))
				       collect (LIST (CAR (COURIER.READ.REP (CADR INFO)
									    (QUOTE CLEARINGHOUSE)
									    (QUOTE 
									     NETWORK.ADDRESS.LIST)))
						     (CAR INFO]

          (* Now have a list of all servers for the desired domain in hop order. Find the first one that's up, and make sure
	  it serves the domain that the hint claimed. Could update cache with all domains it serves, but then we would be in
	  danger of picking a distant server we know about in preference to a close server we haven't discovered yet)


		  (for PAIR in CHLIST bind CHDOMAINS DOM
		     when [COND
			    ([NOT (\LOCATE.NSNET (fetch NSNET of (CAR PAIR]
                                                             (* Give up when we get to inaccessible hosts)
			      (SETQ NOROUTE T)
			      (RETURN))
			    ((SETQ CHDOMAINS (CH.DOMAINS.SERVED (CAR PAIR)))
			      (for old DOM in CHDOMAINS
				 thereis (AND (OR (NULL DOMAIN)
						  (UCASE.STREQUAL (fetch NSDOMAIN of DOM)
								  DOMAIN))
					      (UCASE.STREQUAL (fetch NSORGANIZATION of DOM)
							      ORGANIZATION]
		     do (\CH.UPDATE.CACHE (CADR PAIR)
					  (CAR PAIR)
					  (LIST DOM))
			(RETURN T]
	      (\CH.PRINT.BLURB (COND
				 ((EQ (CAR CHNAMES)
				      (QUOTE ERROR))
				   "Unknown domain: ")
				 (NOROUTE "No network route to Clearinghouse for ")
				 (T "Unable to contact Clearinghouse for "))
			       DOMAIN ORGANIZATION])

(\CH.PRINT.BLURB
  [LAMBDA (MSG DOMAIN ORGANIZATION)                          (* bvm: "29-Jul-84 22:40")
    (printout PROMPTWINDOW T "[" MSG)
    [COND
      (DOMAIN (printout PROMPTWINDOW DOMAIN (QUOTE :]
    (printout PROMPTWINDOW ORGANIZATION "]"])

(\CH.UPDATE.CACHE
  [LAMBDA (OBJECT ADDRESS DOMAINS.SERVED)                    (* bvm: "23-Jun-84 16:12")
    (PROG (NAME.AND.ADDRESS ORGANIZATION DOMAINSTRING ORGANIZATION.INFO)
          (printout PROMPTWINDOW .TAB0 0 "[Noting Clearinghouse " (fetch NSOBJECT of OBJECT)
		    "]")
          (SETQ NAME.AND.ADDRESS (LIST ADDRESS OBJECT))
          [for DOMAIN in DOMAINS.SERVED
	     do (SETQ ORGANIZATION (fetch NSORGANIZATION of DOMAIN))
		(SETQ DOMAINSTRING (fetch NSDOMAIN of DOMAIN))
		[COND
		  ([NOT (SETQ ORGANIZATION.INFO (find X in \CH.CACHE suchthat (UCASE.STREQUAL
										(CAR X)
										ORGANIZATION]
		    (SETQ \CH.CACHE (NCONC1 \CH.CACHE (SETQ ORGANIZATION.INFO (CONS ORGANIZATION]
		(for DOMAIN.INFO in (CDR ORGANIZATION.INFO) when (UCASE.STREQUAL (fetch DCDOMAIN
										    of DOMAIN.INFO)
										 DOMAINSTRING)
		   do (push (fetch DCKNOWNSERVERS of DOMAIN.INFO)
			    NAME.AND.ADDRESS)
		      (RETURN (SORT.NSADDRESSES.BY.DISTANCE (fetch DCKNOWNSERVERS of DOMAIN.INFO)))
		   finally (NCONC1 ORGANIZATION.INFO (create DOMAINCACHE
							     DCDOMAIN ← DOMAINSTRING
							     DCKNOWNSERVERS ←(LIST NAME.AND.ADDRESS]
          (COND
	    (CLEARINGHOUSE.STRUCTURE.WINDOW (SHOW.CLEARINGHOUSE])

(EQUAL.CH.NAMES
  [LAMBDA (NAME1 NAME2)                                      (* bvm: "14-Jun-84 12:25")
                                                             (* Check if two Clearinghouse names are the same.)
    (AND (UCASE.STREQUAL (fetch NSOBJECT of NAME1)
			 (fetch NSOBJECT of NAME2))
	 (UCASE.STREQUAL (fetch NSDOMAIN of NAME1)
			 (fetch NSDOMAIN of NAME2))
	 (UCASE.STREQUAL (fetch NSORGANIZATION of NAME1)
			 (fetch NSORGANIZATION of NAME2])

(PARSE.NSNAME
  [LAMBDA (NAME #PARTS DEFAULTDOMAIN)                        (* bvm: " 3-Jul-84 16:26")

          (* * Coerces NAME to a 3-part NS name. If #PARTS is 1 or 2 then interprets NAME as 1 or 2-part name, discarding 
	  the object and/or domain name if supplied. 3-part names are objects of type NSNAME -
	  2-part names are objects of type NSNAME with an OBJECT field of NIL -
	  A 1 part name is simply the organization string. -
	  DEFAULTDOMAIN is the default to supply for missing parts, which in turn default to CH.DEFAULT.DOMAIN and 
	  CH.DEFAULT.ORGANIZATION -
	  If NAME is already an NSNAME, returns it or a copy if #PARTS implies coercion.)


    (COND
      ((type? NSNAME NAME)
	(SELECTQ #PARTS
		 ((NIL 3)
		   NAME)
		 (2 (COND
		      ((fetch NSOBJECT of NAME)
			(create NSNAME using NAME NSOBJECT ← NIL))
		      (T NAME)))
		 (1 (fetch NSORGANIZATION of NAME))
		 (LISPERROR "ILLEGAL ARG" #PARTS)))
      [[OR (STRINGP NAME)
	   (AND (NULL NAME)
		(SETQ NAME "*"))
	   (AND (LITATOM NAME)
		(SETQ NAME (MKSTRING NAME]
	(PROG (FIRSTPART SECONDPART THIRDPART I J)
	      (GETCLEARINGHOUSE)
	      (COND
		[(SETQ I (STRPOS ":" NAME))
		  (SETQ FIRSTPART (SUBSTRING NAME 1 (SUB1 I)))
		  (SETQ SECONDPART (SUBSTRING NAME (ADD1 I)
					      (COND
						((SETQ J (STRPOS ":" NAME (ADD1 I)))
						  (SETQ THIRDPART (SUBSTRING NAME (ADD1 J)
									     NIL))
						  (SUB1 J]
		(T (SETQ FIRSTPART NAME)))
	      (RETURN (SELECTQ #PARTS
			       [(NIL 3)
				 (create NSNAME
					 NSOBJECT ← FIRSTPART
					 NSDOMAIN ←(COND
					   (SECONDPART)
					   (DEFAULTDOMAIN (fetch NSDOMAIN of DEFAULTDOMAIN))
					   (T CH.DEFAULT.DOMAIN))
					 NSORGANIZATION ←(COND
					   (THIRDPART)
					   (DEFAULTDOMAIN (fetch NSORGANIZATION of DEFAULTDOMAIN))
					   (T CH.DEFAULT.ORGANIZATION]
			       [2 (create NSNAME
					  NSDOMAIN ←(OR (AND THIRDPART SECONDPART)
							FIRSTPART)
					  NSORGANIZATION ←(COND
					    (THIRDPART)
					    (SECONDPART)
					    (DEFAULTDOMAIN (fetch NSORGANIZATION of DEFAULTDOMAIN))
					    (T CH.DEFAULT.ORGANIZATION]
			       (1 (OR THIRDPART SECONDPART FIRSTPART))
			       (LISPERROR "ILLEGAL ARG" #PARTS]
      (T (LISPERROR "ILLEGAL ARG" NAME])

(CH.NAME.TO.STRING
  [LAMBDA (NSNAME FULLNAMEFLG)                               (* bvm: "28-Jun-84 16:37")
                                                             (* Return a string for a Clearinghouse name.
							     Leaves off default components unless FULLNAMEFLG is 
							     set.)
    (NSNAME.TO.STRING (COND
			((type? NSNAME NSNAME)
			  NSNAME)
			(T (PARSE.NSNAME NSNAME)))
		      FULLNAMEFLG])

(CANONICAL.CH.NAME
  [LAMBDA (NAME)                                             (* bvm: "28-Jun-84 16:37")
    (MKATOM (NSNAME.TO.STRING (PARSE.NSNAME NAME])

(CH.PROPERTY
  [LAMBDA (PROP)                                             (* bvm: "15-Aug-84 15:44")
                                                             (* Return the official Clearinghouse property ID for the
							     specified property.)
    (COND
      ((LITATOM PROP)
	(for PAIR in CH.PROPERTIES when (EQ (CAR PAIR)
					    PROP)
	   do (RETURN (CADR PAIR)) finally (ERROR "Unknown Clearinghouse property" PROP)))
      (T PROP])

(CH.GETAUTHENTICATOR
  [LAMBDA (NONTRIVIAL)                                       (* bvm: " 3-Jul-84 21:51")
    (COND
      [NONTRIVIAL (PROG [(INFO (\INTERNAL/GETPASSWORD (QUOTE NS::]
		        (RETURN (COND
				  (INFO (SETQ INFO (NS.MAKE.SIMPLE.CREDENTIALS INFO))
					(COURIER.CREATE (CLEARINGHOUSE . AUTHENTICATOR)
							CREDENTIALS ←(CAR INFO)
							VERIFIER ←(CDR INFO)))
				  (T (ERROR!]
      (T (COURIER.CREATE (CLEARINGHOUSE . AUTHENTICATOR)
			 CREDENTIALS ←(COURIER.CREATE (AUTHENTICATION . CREDENTIALS)
						      TYPE ←(QUOTE SIMPLE)
						      VALUE ← NIL)
			 VERIFIER ←(QUOTE (0])
)
(DEFINEQ

(CH.SERVERS
  [LAMBDA NIL                                                (* bvm: " 3-Jul-84 14:10")
                                                             (* Return a list of the names of all Clearinghouse 
							     servers.)
    (COURIER.CALL (GETCLEARINGHOUSE)
		  (QUOTE CLEARINGHOUSE)
		  (QUOTE RETRIEVE.MEMBERS)
		  (create NSNAME
			  NSOBJECT ← "CHServers"
			  NSDOMAIN ← "CHServers"
			  NSORGANIZATION ← "CHServers")
		  (CH.PROPERTY (QUOTE MEMBERS))
		  (QUOTE (CLEARINGHOUSE . OBJECT.NAME))
		  (CH.GETAUTHENTICATOR])

(\CH.GUESS.NEW.PROPERTIES
  [LAMBDA (DOMAIN MINPROPERTYID MAXPROPERTYID)               (* bvm: " 4-Jul-84 14:25")

          (* This is a hack that finds all the objects in the given domain with any properties in the given range.
	  Useful for finding out what the Services people are up to.)


    (PROG ((PATTERN (PARSE.NSNAME DOMAIN 2))
	   OBJECTS)
          (SETQ PATTERN (create NSNAME using PATTERN NSOBJECT ← "*"))
          (SETQ MINPROPERTYID (OR MINPROPERTYID 1))
          (SETQ MAXPROPERTYID (OR MAXPROPERTYID 25))
          (RETURN (for ID from MINPROPERTYID to MAXPROPERTYID when (SETQ OBJECTS (CH.LIST.OBJECTS
								       PATTERN ID))
		     collect (CONS ID OBJECTS])
)



(* Clearinghouse calls)

(DEFINEQ

(CH.DOMAINS.SERVED
  [LAMBDA (CHADDRESS)                                        (* bvm: " 3-Jul-84 14:12")

          (* We wrap this in an NLSETQ because we might get an error underneath the Bulk Data transfer if we're not really 
	  talking to a Clearinghouse.)


    (CAR (NLSETQ (COURIER.CALL CHADDRESS (QUOTE CLEARINGHOUSE)
			       (QUOTE LIST.DOMAINS.SERVED)
			       (QUOTE (CLEARINGHOUSE . DOMAIN.NAME))
			       (CH.GETAUTHENTICATOR])

(CH.CREATE.OBJECT
  [LAMBDA (OBJECTNAME)                                       (* bvm: " 4-Jul-84 14:50")

          (* * Creates an object with given name, no properties)


    (OR (COURIER.EXPEDITED.CALL (CH.FINDSERVER (SETQ OBJECTNAME (PARSE.NSNAME OBJECTNAME)))
				\CH.BROADCAST.SOCKET
				(QUOTE CLEARINGHOUSE)
				(QUOTE CREATE.OBJECT)
				OBJECTNAME
				(CH.GETAUTHENTICATOR)
				(QUOTE RETURNERRORS))
	OBJECTNAME])

(CH.DELETE.OBJECT
  [LAMBDA (OBJECTNAME)                                       (* bvm: " 4-Jul-84 14:50")

          (* * Deletes specified object from Clearinghouse database)


    (OR (COURIER.EXPEDITED.CALL (CH.FINDSERVER (SETQ OBJECTNAME (PARSE.NSNAME OBJECTNAME)))
				\CH.BROADCAST.SOCKET
				(QUOTE CLEARINGHOUSE)
				(QUOTE DELETE.OBJECT)
				OBJECTNAME
				(CH.GETAUTHENTICATOR)
				(QUOTE RETURNERRORS))
	OBJECTNAME])

(CH.CANONICAL.NAME
  [LAMBDA (NAME)                                             (* bvm: " 4-Jul-84 14:46")

          (* * Canonicalizes name, unless it is a pattern. Result is a standard 3-part name. Name is not required to be a 
	  valid Clearinghouse name, but if it is, it is dereferenced to its distinguished name)


    (PROG ((PARSED (PARSE.NSNAME NAME)))
          (RETURN (OR (AND (NOT (STRPOS (QUOTE *)
					NAME))
			   (CH.LOOKUP.OBJECT PARSED))
		      PARSED])

(CH.CREATE.ALIAS
  [LAMBDA (ALIAS OBJECTNAME)                                 (* bvm: " 4-Jul-84 14:53")

          (* * Makes ALIAS be an alias of OBJECTNAME in the Clearinghouse database)


    (COURIER.EXPEDITED.CALL (CH.FINDSERVER (SETQ OBJECTNAME (PARSE.NSNAME OBJECTNAME)))
			    \CH.BROADCAST.SOCKET
			    (QUOTE CLEARINGHOUSE)
			    (QUOTE CREATE.ALIAS)
			    (PARSE.NSNAME ALIAS)
			    OBJECTNAME
			    (CH.GETAUTHENTICATOR)
			    (QUOTE RETURNERRORS])

(CH.DELETE.ALIAS
  [LAMBDA (ALIAS)                                            (* bvm: " 4-Jul-84 14:52")

          (* * Deletes specified alias from Clearinghouse database)


    (COURIER.EXPEDITED.CALL (CH.FINDSERVER (SETQ ALIAS (PARSE.NSNAME ALIAS)))
			    \CH.BROADCAST.SOCKET
			    (QUOTE CLEARINGHOUSE)
			    (QUOTE DELETE.ALIAS)
			    ALIAS
			    (CH.GETAUTHENTICATOR)
			    (QUOTE RETURNERRORS])

(CH.LOOKUP.OBJECT
  [LAMBDA (OBJECTPATTERN)                                    (* bvm: "28-Jun-84 16:37")

          (* * Returns the canonical name of the specified object. If object contains wildcards, result is the first match)


    (SETQ OBJECTPATTERN (PARSE.NSNAME OBJECTPATTERN))
    (PROG ((ADDRESS (CH.FINDSERVER OBJECTPATTERN T)))
          (RETURN (AND ADDRESS (COURIER.EXPEDITED.CALL ADDRESS \CH.BROADCAST.SOCKET (QUOTE 
										    CLEARINGHOUSE)
						       (QUOTE LOOKUP.OBJECT)
						       OBJECTPATTERN
						       (CH.GETAUTHENTICATOR)
						       (QUOTE NOERROR])

(CH.DELETE.PROPERTY
  [LAMBDA (OBJECTNAME PROPERTY)                              (* bvm: " 4-Jul-84 14:21")
    (COURIER.EXPEDITED.CALL (CH.FINDSERVER (SETQ OBJECTNAME (PARSE.NSNAME OBJECTNAME)))
			    \CH.BROADCAST.SOCKET
			    (QUOTE CLEARINGHOUSE)
			    (QUOTE DELETE.PROPERTY)
			    OBJECTNAME
			    (OR (FIXP PROPERTY)
				(CH.PROPERTY PROPERTY))
			    (CH.GETAUTHENTICATOR)
			    (QUOTE RETURNERRORS])

(LOOKUP.NS.SERVER
  [LAMBDA (NAME TYPE FULLFLG)                                (* bvm: "14-Sep-84 18:08")
                                                             (* Return the NS address of the specified server.
							     If a type is given, use the Clearinghouse if the address
							     isn't in the cache.)
    (SETQ NAME (PARSE.NSNAME NAME))
    (PROG (ADDRESSES NAME&VALUE ENTRY)
          (COND
	    ((find old ENTRY in NS.SERVER.NAMES.TO.ADDRESSES suchthat (EQUAL.CH.NAMES (CAR ENTRY)
										      NAME)))
	    [[SETQ NAME&VALUE (COND
		  (TYPE (CH.RETRIEVE.ITEM NAME TYPE (QUOTE NETWORK.ADDRESS)))
		  (T (CH.RETRIEVE.ITEM NAME (CH.PROPERTY (QUOTE ADDRESS.LIST))
				       (QUOTE NETWORK.ADDRESS.LIST]
	      (push NS.SERVER.NAMES.TO.ADDRESSES (SETQ ENTRY (CONS (CAR NAME&VALUE)
								   (SETQ ADDRESSES
								     (COND
								       (TYPE 
                                                             (* Old way)
									     (replace NSSOCKET
										of (CADR NAME&VALUE)
										with 0)
                                                             (* Stupidity. Old clearinghouses sometimes give a 
							     nonzero socket here. Why?)
									     (LIST (CADR NAME&VALUE)))
								       (T (CADR NAME&VALUE]
	    (T (RETURN)))
          (RETURN (COND
		    (FULLFLG ENTRY)
		    (T (CADR ENTRY])

(\CANONICAL.NSHOSTNAME
  [LAMBDA (HOST)                                             (* bvm: "15-Sep-84 14:36")
    (MKATOM (NSNAME.TO.STRING (CAR (OR (LOOKUP.NS.SERVER HOST NIL T)
				       (LOOKUP.NS.SERVER HOST (QUOTE FILESERVER)
							 T)))
			      T])
)
(DEFINEQ

(CH.LIST.ALIASES
  [LAMBDA (OBJECTNAMEPATTERN)                                (* bvm: " 3-Jul-84 21:58")
    (COURIER.CALL (CH.FINDSERVER (SETQ OBJECTNAMEPATTERN (PARSE.NSNAME OBJECTNAMEPATTERN)))
		  (QUOTE CLEARINGHOUSE)
		  (QUOTE LIST.ALIASES)
		  OBJECTNAMEPATTERN
		  (QUOTE (CLEARINGHOUSE . OBJECT))
		  (CH.GETAUTHENTICATOR])

(CH.LIST.ALIASES.OF
  [LAMBDA (OBJECTPATTERN)                                    (* bvm: " 3-Jul-84 21:54")
    (COURIER.CALL (CH.FINDSERVER (SETQ OBJECTPATTERN (PARSE.NSNAME OBJECTPATTERN)))
		  (QUOTE CLEARINGHOUSE)
		  (QUOTE LIST.ALIASES.OF)
		  OBJECTPATTERN
		  (QUOTE (CLEARINGHOUSE . OBJECT.NAME))
		  (CH.GETAUTHENTICATOR])

(CH.LIST.DOMAINS
  [LAMBDA (DOMAINPATTERN)                                    (* bvm: " 3-Jul-84 14:33")
    (SETQ DOMAINPATTERN (PARSE.NSNAME DOMAINPATTERN 2))
    (COURIER.CALL [CAR (CAR (fetch DCKNOWNSERVERS of (CAR (\CH.FIND.ORG.SERVER (FETCH NSORGANIZATION
										  OF DOMAINPATTERN)
									       T]
		  (QUOTE CLEARINGHOUSE)
		  (QUOTE LIST.DOMAINS)
		  DOMAINPATTERN
		  (QUOTE (CLEARINGHOUSE . DOMAIN))
		  (CH.GETAUTHENTICATOR)
		  (QUOTE NOERROR])

(CH.LIST.ORGANIZATIONS
  [LAMBDA (ORGANIZATIONPATTERN)                              (* bvm: " 3-Jul-84 14:14")
    (COURIER.CALL (GETCLEARINGHOUSE)
		  (QUOTE CLEARINGHOUSE)
		  (QUOTE LIST.ORGANIZATIONS)
		  (PARSE.NSNAME ORGANIZATIONPATTERN 1)
		  (QUOTE (CLEARINGHOUSE . ORGANIZATION))
		  (CH.GETAUTHENTICATOR])

(CH.LIST.OBJECTS
  [LAMBDA (OBJECTPATTERN PROPERTY)                           (* bvm: " 3-Jul-84 14:17")
    (COURIER.CALL (CH.FINDSERVER (SETQ OBJECTPATTERN (PARSE.NSNAME OBJECTPATTERN))
				 T)
		  (QUOTE CLEARINGHOUSE)
		  (QUOTE LIST.OBJECTS)
		  OBJECTPATTERN
		  (CH.PROPERTY (OR PROPERTY (QUOTE ALL)))
		  (QUOTE (CLEARINGHOUSE . OBJECT))
		  (CH.GETAUTHENTICATOR)
		  (QUOTE NOERROR])

(CH.LIST.PROPERTIES
  [LAMBDA (OBJECTNAMEPATTERN)                                (* bvm: " 4-Jul-84 14:23")
    (PROG [(RESULT (COURIER.EXPEDITED.CALL (CH.FINDSERVER (SETQ OBJECTNAMEPATTERN (PARSE.NSNAME
							      OBJECTNAMEPATTERN)))
					   \CH.BROADCAST.SOCKET
					   (QUOTE CLEARINGHOUSE)
					   (QUOTE LIST.PROPERTIES)
					   OBJECTNAMEPATTERN
					   (CH.GETAUTHENTICATOR]
          (RETURN (COND
		    (RESULT                                  (* Oddity: this is supposed to be a list of properties, 
							     but they all come back swapped!)
			    [FRPLACA (CDR RESULT)
				     (for X in (CADR RESULT) collect (\MAKENUMBER (LOGAND X 
										       MAX.SMALLP)
										  (LRSH X 16]
			    RESULT])
)
(DEFINEQ

(CH.ADD.GROUP.PROPERTY
  [LAMBDA (OBJECTNAME PROPERTY MEMBERS)                      (* bvm: " 4-Jul-84 14:56")
    (SETQ MEMBERS (for X in MEMBERS collect (CH.CANONICAL.NAME X)))
    (COURIER.CALL (CH.FINDSERVER (SETQ OBJECTNAME (PARSE.NSNAME OBJECTNAME)))
		  (QUOTE CLEARINGHOUSE)
		  (QUOTE ADD.GROUP.PROPERTY)
		  OBJECTNAME
		  (OR (FIXP PROPERTY)
		      (CH.PROPERTY PROPERTY))
		  [FUNCTION (LAMBDA (DATASTREAM)             (* Function to write the membership onto the bulk data 
							     stream)
		      (COURIER.WRITE.BULKDATA DATASTREAM MEMBERS NIL (QUOTE NSNAME]
		  (CH.GETAUTHENTICATOR)
		  (QUOTE RETURNERRORS])

(CH.ADD.MEMBER
  [LAMBDA (GROUPNAME PROPERTY NEWMEMBER)                     (* bvm: " 4-Jul-84 14:47")
    (SETQ NEWMEMBER (CH.CANONICAL.NAME NEWMEMBER))
    (COURIER.EXPEDITED.CALL (CH.FINDSERVER (SETQ GROUPNAME (PARSE.NSNAME GROUPNAME)))
			    \CH.BROADCAST.SOCKET
			    (QUOTE CLEARINGHOUSE)
			    (QUOTE ADD.MEMBER)
			    GROUPNAME
			    (OR (FIXP PROPERTY)
				(CH.PROPERTY PROPERTY))
			    NEWMEMBER
			    (CH.GETAUTHENTICATOR)
			    (QUOTE RETURNERRORS])

(CH.RETRIEVE.MEMBERS
  [LAMBDA (OBJECTPATTERN PROPERTY STREAM)                    (* bvm: "15-Aug-84 15:29")
    (SETQ OBJECTPATTERN (PARSE.NSNAME OBJECTPATTERN))
    (COURIER.CALL (OR STREAM (CH.FINDSERVER OBJECTPATTERN))
		  (QUOTE CLEARINGHOUSE)
		  (QUOTE RETRIEVE.MEMBERS)
		  OBJECTPATTERN
		  (OR (FIXP PROPERTY)
		      (CH.PROPERTY PROPERTY))
		  (QUOTE (CLEARINGHOUSE . OBJECT.NAME))
		  (CH.GETAUTHENTICATOR)
		  (QUOTE RETURNERRORS])

(CH.DELETE.MEMBER
  [LAMBDA (GROUPNAME PROPERTY OLDMEMBER)                     (* bvm: " 4-Jul-84 14:23")
    (COURIER.EXPEDITED.CALL (CH.FINDSERVER (SETQ GROUPNAME (PARSE.NSNAME GROUPNAME)))
			    \CH.BROADCAST.SOCKET
			    (QUOTE CLEARINGHOUSE)
			    (QUOTE DELETE.MEMBER)
			    GROUPNAME
			    (OR (FIXP PROPERTY)
				(CH.PROPERTY PROPERTY))
			    (PARSE.NSNAME OLDMEMBER)
			    (CH.GETAUTHENTICATOR])

(CH.ISMEMBER
  [LAMBDA (GROUPNAME PROPERTY SECONDARYPROPERTY NAME)        (* bvm: " 4-Jul-84 14:21")
    (CAR (COURIER.EXPEDITED.CALL (CH.FINDSERVER (SETQ GROUPNAME (PARSE.NSNAME GROUPNAME)))
				 \CH.BROADCAST.SOCKET
				 (QUOTE CLEARINGHOUSE)
				 (QUOTE IS.MEMBER)
				 GROUPNAME
				 (OR (FIXP PROPERTY)
				     (CH.PROPERTY PROPERTY))
				 (COND
				   ((NULL SECONDARYPROPERTY)
				     \CH.NULL.PROPERTY)
				   ((FIXP SECONDARYPROPERTY))
				   (T (CH.PROPERTY SECONDARYPROPERTY)))
				 (PARSE.NSNAME NAME)
				 (CH.GETAUTHENTICATOR)
				 (QUOTE RETURNERRORS])
)
(DEFINEQ

(CH.RETRIEVE.ITEM
  [LAMBDA (OBJECTPATTERN PROPERTY INTERPRETATION)            (* bvm: "28-Jun-84 16:37")

          (* * Retrieves item property PROPERTY of object OBJECTPATTERN, returning (CanonicalName Value); If INTERPRETATION 
	  is given, then Value is interpreted via it, otherwise Value is just a SEQUENCE of UNSPECIFIED)


    (SETQ OBJECTPATTERN (PARSE.NSNAME OBJECTPATTERN))
    (PROG ((ADDRESS (CH.FINDSERVER OBJECTPATTERN T))
	   NAME&VALUE)
          [COND
	    ((AND ADDRESS (SETQ NAME&VALUE (COURIER.EXPEDITED.CALL ADDRESS \CH.BROADCAST.SOCKET
								   (QUOTE CLEARINGHOUSE)
								   (QUOTE RETRIEVE.ITEM)
								   OBJECTPATTERN
								   (CH.PROPERTY PROPERTY)
								   (CH.GETAUTHENTICATOR)
								   (QUOTE NOERROR)))
		  INTERPRETATION)
	      (RPLACA (CDR NAME&VALUE)
		      (COURIER.READ.REP (CADR NAME&VALUE)
					(QUOTE CLEARINGHOUSE)
					INTERPRETATION]
          (RETURN NAME&VALUE])

(CH.ADD.ITEM.PROPERTY
  [LAMBDA (OBJECTNAME PROPERTY VALUE INTERPRETATION)         (* bvm: " 4-Jul-84 14:21")
    (COURIER.EXPEDITED.CALL (CH.FINDSERVER (SETQ OBJECTNAME (PARSE.NSNAME OBJECTNAME)))
			    \CH.BROADCAST.SOCKET
			    (QUOTE CLEARINGHOUSE)
			    (QUOTE ADD.ITEM.PROPERTY)
			    OBJECTNAME
			    (OR (FIXP PROPERTY)
				(CH.PROPERTY PROPERTY))
			    (COND
			      (INTERPRETATION (COURIER.WRITE.REP VALUE NIL INTERPRETATION))
			      (T VALUE))
			    (CH.GETAUTHENTICATOR)
			    (QUOTE RETURNERRORS])

(CH.CHANGE.ITEM
  [LAMBDA (OBJECTNAME PROPERTY NEWVALUE INTERPRETATION)      (* bvm: " 4-Jul-84 14:22")
    (COURIER.EXPEDITED.CALL (CH.FINDSERVER (SETQ OBJECTNAME (PARSE.NSNAME OBJECTNAME)))
			    \CH.BROADCAST.SOCKET
			    (QUOTE CLEARINGHOUSE)
			    (QUOTE CHANGE.ITEM)
			    OBJECTNAME
			    (OR (FIXP PROPERTY)
				(CH.PROPERTY PROPERTY))
			    (COND
			      (INTERPRETATION (COURIER.WRITE.REP NEWVALUE NIL INTERPRETATION))
			      (T NEWVALUE))
			    (CH.GETAUTHENTICATOR)
			    (QUOTE RETURNERRORS])
)
(PUTPROPS CLEARINGHOUSE COPYRIGHT ("Xerox Corporation" 1984))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (5576 8814 (HASH.PASSWORD 5586 . 6242) (NSLOGIN 6244 . 6406) (NS.AUTHENTICATE 6408 . 
7297) (NS.MAKE.SIMPLE.CREDENTIALS 7299 . 7765) (\AUTHENTICATION.FIND.SERVER 7767 . 8812)) (17801 20013
 (\NSNAME.DEFPRINT 17811 . 17963) (NSNAME.TO.STRING 17965 . 18669) (COURIER.READ.NSNAME 18671 . 19084)
 (COURIER.WRITE.NSNAME 19086 . 19527) (COURIER.NSNAME.LENGTH 19529 . 20011)) (20048 35296 (
GETCLEARINGHOUSE 20058 . 20584) (\CH.CHECK.CLEARINGHOUSE 20586 . 21933) (START.CLEARINGHOUSE 21935 . 
22283) (SHOW.CLEARINGHOUSE 22285 . 23498) (CH.FINDSERVER 23500 . 25119) (\CH.FIND.ORG.SERVER 25121 . 
26391) (\CH.LOCATE.SERVERS 26393 . 29120) (\CH.PRINT.BLURB 29122 . 29394) (\CH.UPDATE.CACHE 29396 . 
30738) (EQUAL.CH.NAMES 30740 . 31259) (PARSE.NSNAME 31261 . 33569) (CH.NAME.TO.STRING 33571 . 34017) (
CANONICAL.CH.NAME 34019 . 34192) (CH.PROPERTY 34194 . 34676) (CH.GETAUTHENTICATOR 34678 . 35294)) (
35297 36621 (CH.SERVERS 35307 . 35878) (\CH.GUESS.NEW.PROPERTIES 35880 . 36619)) (36654 42240 (
CH.DOMAINS.SERVED 36664 . 37131) (CH.CREATE.OBJECT 37133 . 37580) (CH.DELETE.OBJECT 37582 . 38033) (
CH.CANONICAL.NAME 38035 . 38533) (CH.CREATE.ALIAS 38535 . 39031) (CH.DELETE.ALIAS 39033 . 39466) (
CH.LOOKUP.OBJECT 39468 . 40080) (CH.DELETE.PROPERTY 40082 . 40520) (LOOKUP.NS.SERVER 40522 . 41942) (
\CANONICAL.NSHOSTNAME 41944 . 42238)) (42241 44978 (CH.LIST.ALIASES 42251 . 42604) (CH.LIST.ALIASES.OF
 42606 . 42958) (CH.LIST.DOMAINS 42960 . 43459) (CH.LIST.ORGANIZATIONS 43461 . 43796) (CH.LIST.OBJECTS
 43798 . 44214) (CH.LIST.PROPERTIES 44216 . 44976)) (44979 47682 (CH.ADD.GROUP.PROPERTY 44989 . 45666)
 (CH.ADD.MEMBER 45668 . 46165) (CH.RETRIEVE.MEMBERS 46167 . 46636) (CH.DELETE.MEMBER 46638 . 47077) (
CH.ISMEMBER 47079 . 47680)) (47683 49738 (CH.RETRIEVE.ITEM 47693 . 48646) (CH.ADD.ITEM.PROPERTY 48648
 . 49194) (CH.CHANGE.ITEM 49196 . 49736)))))
STOP