// FtpProt.decl - Declarations for the BCPL Alto/Nova implementation of Ftp
// Copyright Xerox Corporation 1979, 1980
// Last modified December 25, 1980  5:45 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
//---------------------------------------------------------------------------
[
// mark types common to FTP and MTP
markYes = 3
markNo = 4
markHereIsFile = 5
markEndOfCommand = 6
markComment = 7
markVersion = 10b
markHereIsPList = 13b

// FTP mark bytes
markRetrieve = 1
markStore = 2
markNewStore = 11b
markDirectory = 12b
// mark type 14b is reserved for YouAreUser
// mark type 15b is reserved for Abort
markDelete = 16b
markRename = 17b

// MTP mark bytes
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 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>
]

//---------------------------------------------------------------------------
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
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
buffer word		// -> block I/O buffer
bufferLength word	// in words
byteCnt word 2		// number of bytes transferred
bitsPerSec word 2	// speed of transfer
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
   ]
]
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