// IfsFtpProt.decl -- Declarations for the Ifs implementation of Ftp
// Copyright Xerox Corporation 1979, 1980, 1981, 1982
// Last modified May 14, 1982  1:10 PM by Boggs

get "IfsRs.decl"

// Note that this is substantially different from the standard package.
// Rename this file to FtpProt.decl then compile the Ftp package for Ifs.

//---------------------------------------------------------------------------
manifest		// package wide declarations
//---------------------------------------------------------------------------
[
socketFTP = 3		// well known Pup socket

FTPVersion = 1		// FTP protocol version
MTP = true		// 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 <Number>
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(localPList,remotePList) = true|false
RetrieveFile word	// RetrieveFile(localPList) = true|false
RetrieveCleanup word	// RetrieveCleanup(localPList,ok)
Delete word		// Delete(localPList,remotePList) = true|false
DeleteFile word		// DeleteFile(localPList) = true|false
Directory word		// Directory(localPList,remotePList) = true|false
Rename word		// Rename(oldPList,newPList) = 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(pList) = pList|false
RetrieveMailMessage word // RetrieveMailMessage(localPList,remotePList) = t|f
RetrieveMailCleanup word // RetrieveMailCleanup(remotePList,ok)
]

//---------------------------------------------------------------------------
compiletest MTP		// Ftp Server Interface
   ifso  [ structure FTPSI [ @FTPSFI; @FTPSMI ] ]
   ifnot [ structure FTPSI [ @FTPSFI ] ]
//---------------------------------------------------------------------------
manifest lenFTPSI = size FTPSI/16

//---------------------------------------------------------------------------
structure FTPI:		// Ftp Interface
//---------------------------------------------------------------------------
[
dspStream word		// -> display stream
bspStream word		// -> bsp Stream
lst word		// -> log stream
dls word		// -> debugging stream
dbls word		// -> bsp and debugging stream
getCmdString word	// -> last string read by GetCommand
flags word =
   [
   debugFlag bit	// true enables lots of extra printout
   serverFlag bit	// true if this is a server
   newDirectory bit	// server implements markNewDirectory
   newStore bit		// server implements markNewStore
   blank bit 12
   ]
@FTPSI			// server interface
]
manifest lenFTPI = size FTPI/16

//---------------------------------------------------------------------------
structure FtpCtx:	// Ftp Context
//---------------------------------------------------------------------------
[
@RSCtx
ftpi word = @FTPI
   [
   diskStream word	// -> disk stream
   fd word		// -> IFS file descriptor
   ] =
   [
   msg word		// -> Msg descriptor
   index word		// mailbox index
   ]
]
manifest lenExtraFtpCtx = size FtpCtx/16-3

manifest
[
// File Server error codes
ecBinaryNotText = 601	// 102 file type is Binary not Text
ecMayBeText = 602	// Warning: $S may be type Text
ecCRLFConversion = 603	// 102 CRLF conversion not supported
ecByteSize = 604	// 102 requested byte size not equal to file byte size
ecTypeRequired = 605	// 102 TYPE property required
ecByteRequired = 606	// 102 BYTE-SIZE property required
ecNotRetrieved = 607	// 110 $S not retrieved: $P
ecNotImplemented = 608	// 1 Unimplemented command
ecNotStored = 609	// 107 not stored: $P
ecNetToDisk = 610	// 110 BSPReadBlock failed
ecDiskToNet = 611	// 110 BSPWriteBlock failed
ecFileDamaged = 612	// Caution: file $S is damaged
]