// PupEFTPCommon.bcpl -- by J. Shoch
// Copyright Xerox Corporation 1979

// Last modified June 3, 1979  12:00 PM by Taft

get "PupEFTP.decl"

external
[
// outgoing procedures
InitEFTPPackage; OpenEFTPSoc; CloseEFTPSoc; GetEFTPAbort; SendEFTPAbort

// incoming procedures
OpenLevel1Socket; CloseLevel1Socket; GetPBI; ReleasePBI
SetPupDPort; AppendStringToPup; CompletePup
DefaultArgs; Zero

// outgoing statics
lEFTPSoc
]

static [ lEFTPSoc = lenEFTPSoc ]


//----------------------------------------------------------------------------
let InitEFTPPackage(packageZone) be [ ]
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
and OpenEFTPSoc(soc, lclport, frnport; numargs na) be
//----------------------------------------------------------------------------
[
DefaultArgs(lv na, -1, 0, 0)
Zero(soc, lenEFTPSoc)
soc>>EFTPSoc.TransferNotStarted = true
soc>>EFTPSoc.currentTimeout = startingTimeout
OpenLevel1Socket(soc, lclport, frnport)
]

//----------------------------------------------------------------------------
and CloseEFTPSoc(soc) be
//----------------------------------------------------------------------------
[
if soc>>EFTPSoc.AbortPBI ne 0 then ReleasePBI(soc>>EFTPSoc.AbortPBI)
CloseLevel1Socket(soc)
]

//----------------------------------------------------------------------------
and GetEFTPAbort(soc) = soc>>EFTPSoc.AbortPBI
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
and SendEFTPAbort(soc, abortCode, abortString, pbi; numargs na) be
//----------------------------------------------------------------------------
// construct the outgoing abort packet,
// will get sent to source of pbi if supplied,
// will get sent to your current foreign port otherwise
[
let abortPbi = GetPBI(soc)
if na gr 3 then
   [
   abortPbi>>PBI.pup.id↑2 = pbi>>PBI.pup.id↑2
   SetPupDPort(abortPbi, lv pbi>>PBI.pup.sPort)
   ]
abortPbi>>PBI.pup.id↑2 = soc>>EFTPSoc.SeqNum
abortPbi>>PBI.pup.words↑1 = abortCode
AppendStringToPup(abortPbi, 3, abortString)
CompletePup(abortPbi, typeEFTPAbort)
]