// FtpProt.decl - Declarations for the BCPL implementation of Ftp
// Copyright Xerox Corporation 1979, 1980, 1981, 1982
// Last modified May 13, 1982  1:08 PM by Boggs

//-----------------------------------------------------------------------------------------
manifest		// package wide declarations
//-----------------------------------------------------------------------------------------
[
socketFTP = 3		// rendezvous socket
socketMail = 7		// rendezvous socket

FTPVersion = 1		// FTP protocol version
MTP = false		// controls compilation of MTP code.

QuoteChar = $'		// string quote character

// data types
Unspecified = 0
Text = 1
Binary = 2

// end of line conventions
CR = 1
CRLF = 2
Transparent = 3
]

//-----------------------------------------------------------------------------------------
manifest
//-----------------------------------------------------------------------------------------
[
// FTP & MTP mark bytes
markRetrieve = 1
markStore = 2			//'old' store protocol
markYes = 3
markNo = 4
markHereIsFile = 5
markEndOfCommand = 6
markComment = 7
markVersion = 10b
markNewStore = 11b		//'new' store protocol
markDirectory = 12b		//'old' directory protocol
markHereIsPList = 13b
markNewDirectory = 14b		//'new' directory protocol
// 15b is available
markDelete = 16b
markRename = 17b
markStoreMail = 20b
markRetrieveMail = 21b
markFlushMailBox = 22b
markMailboxException = 23b
numMarks = MTP? 23b, 17b
]

//-----------------------------------------------------------------------------------------
structure Mark [ subCode byte; mark byte ]
//-----------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------
structure MT:	// Mark Table
//-----------------------------------------------------------------------------------------
[
string word	// -> string
code byte	// mark byte value
qBits byte =	// qualifying bits
   [
   blank bit 5
   ptx bit	// print text after this mark
   nf bit	// dont fetch bytes past this mark
   sc bit	// subcode byte follows this mark
   ]
] ↑1,numMarks
manifest lenMT = size MT/16

manifest
[
// MT qualifying bits
ptx = 1b15 rshift (offset MT.ptx↑1 rem 16)
nf = 1b15 rshift (offset MT.nf↑1 rem 16)
sc = 1b15 rshift (offset MT.sc↑1 rem 16)
]

//-----------------------------------------------------------------------------------------
structure Time [ h word; l word ]
//-----------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------
structure DPRP:
//-----------------------------------------------------------------------------------------
[
blank bit 2
SFIL bit	// Server-Filename
DEVI bit	// Device
DIRE bit	// Directory
NAMB bit	// Name-Body
VERS bit	// Version
TYPE bit	// Type
BYTE bit	// Byte-size
EOLC bit	// End-of-line-convention
SIZE bit	// Size
AUTH bit	// Author
CDAT bit	// Creation-date
RDAT bit	// Read-date
WDAT bit	// Write-date
CSUM bit	// Checksum
]

//-----------------------------------------------------------------------------------------
structure FPL:  // File Property List
//-----------------------------------------------------------------------------------------
[
UNAM word	// User-Name <String>
UPSW word	// User-Password <String>
CNAM word	// Connect-name <String>
CPSW word	// Connect-password <String>
SFIL word	// Server-Filename <String>
DEVI word	// Device <String>
DIRE word	// Directory <String>
NAMB word	// Name-Body <String>
VERS word	// Version <String>
TYPE word	// Type <Text|Binary|Unspecifed>
BYTE word	// Byte-size <Number>
EOLC word	// End-of-line-convention <CR|CRLF|Transparent>
SIZE word 2	// Size <Number>
AUTH word	// Author <String>
CDAT @Time	// Creation-date <Alto format date>
RDAT @Time	// Read-date <Alto format date>
WDAT @Time	// Write-date <Alto format date>
CSUM word	// Checksum <PupCheckSum+1>
DPRP @DPRP	// Desired-Property <property name>
]

//-----------------------------------------------------------------------------------------
structure MPL:	// Mail Property List
//-----------------------------------------------------------------------------------------
[
MLBX word	// Mailbox <string>
LGTH word 2	// Length <Number>
RCVD @Time	// Date-Received <Alto format date>
SNDR word	// Sender <string>
]

//-----------------------------------------------------------------------------------------
compiletest MTP
   ifso  [ structure PL [ @FPL; @MPL ] ]
   ifnot [ structure PL [ @FPL ] ]
//-----------------------------------------------------------------------------------------
manifest lenPL = size PL/16

//-----------------------------------------------------------------------------------------
structure Prop:		// an object
//-----------------------------------------------------------------------------------------
[
Scan word		// call 0
Gen word		// call 1
Free word		// call 2
Init word		// call 3
pOffset word		// word offset into pList
pErrSubCode word	// markNo subcode
pDPRP word		// DPRP bit vector
pExtra word		// object private interpretation
]
manifest lenProp = size Prop/16

//-----------------------------------------------------------------------------------------
structure FTPSFI:	// Ftp Server File Interface
//-----------------------------------------------------------------------------------------
[
Version word		// Version(bspStream,nil)
Store word		// Store(pList) = true|false
StoreFile word		// StoreFile(pList) = true|false
StoreCleanup word	// StoreCleanup(pList,ok)
Retrieve word		// Retrieve(localPL,remotePL) = true|false
RetrieveFile word	// RetrieveFile(localPL) = true|false
RetrieveCleanup word	// RetrieveCleanup(localPL,ok)
Delete word		// Delete(localPL,remotePL) = true|false
DeleteFile word		// DeleteFile(localPL) = true|false
Directory word		// Directory(localPL,remotePL) = true|false
Rename word		// Rename(oldPL,newPL) = true|false
]

//-----------------------------------------------------------------------------------------
structure FTPSMI:	// Ftp Server Mail Interface
//-----------------------------------------------------------------------------------------
[
StoreMail word		// StoreMail(pList) = true|false
StoreMailMessage word	// StoreMailMessage() = true|false
StoreMailCleanup word	// StoreMailCleanup(ok)
RetrieveMail word	// RetrieveMail(pl) = pl|false
RetrieveMailMessage word // RetrieveMailMessage(localPL,remotePL) = t|f
RetrieveMailCleanup word // RetrieveMailCleanup(remotePL,ok)
]

//-----------------------------------------------------------------------------------------
compiletest MTP		// Ftp Server Interface
   ifso  [ structure FTPSI [ @FTPSFI; @FTPSMI ] ]
   ifnot [ structure FTPSI [ @FTPSFI ] ]
//-----------------------------------------------------------------------------------------
manifest lenFTPSI = size FTPSI/16

//-----------------------------------------------------------------------------------------
structure FTPI:		// Ftp Interface
//-----------------------------------------------------------------------------------------
[
bspSoc word		// -> bsp Socket
dspStream word		// -> display stream
diskStream word		// -> disk stream
bspStream word		// -> bsp stream
lst word		// -> log stream
dls word		// -> debugging log stream
dbls word		// -> debug/bsp split stream
buffer word		// -> block I/O buffer
bufferLength word	// in words
getCmdString word	// -> last string read by GetCommand
debugFlag word		// true enables lots of extra printout
flags word =
   [
   connFlag bit		// true if connection is open
   serverFlag bit	// true if this is a server
   newStore bit		// (user only) true if server accepts [markNewStore]
   newDirectory bit	// (user only) true if server accepts [markNewDirectory]
   ]
]
manifest lenFTPI = size FTPI/16

//-----------------------------------------------------------------------------------------
structure FtpCtx:
//-----------------------------------------------------------------------------------------
[
blank word 3		// standard ctx stuff
@FTPI			// user/server independent stuff
@FTPSI			// server interface
]
manifest lenExtraCtx = size FtpCtx/16 - 3