// FtpServerInit.bcpl - Alto/Nova Subsystem version
// Copyright Xerox Corporation 1979, 1980, 1981, 1982
// Last modified October 6, 1982  11:07 PM by Boggs

get "FtpProt.decl"
get "AltoDefs.d"
get "Streams.d"

external
[
// outgoing procedures
InitFtpServer

// incoming procedures
FtpServer; FtpServFinishProc
FtpSStore; FtpSStoreFile; FtpSStoreCleanup
FtpSRetrieve; FtpSRetrieveFile; FtpSRetrieveCleanup
FtpSDelete; FtpSDeleteFile; FtpSRename
FtpSDirectory; FtpSVersion
LsPuts; DlsPuts; DblsPuts
Allocate; Free; Enqueue; Zero
InitializeContext; CreateDisplayStream

// outgoing statics
serverDsp; serverUFP; serverCtx; serverSoc

// incoming statics
debugFlag; tfsFlag; lBSPSoc
stackSize; ctxQ; fontHeight
sysFont; sysZone; lvUserFinishProc
]

static [ serverDsp; serverUFP; serverCtx; serverSoc ]

manifest serverDspLen = 1500

//-----------------------------------------------------------------------------------------
let InitFtpServer() be
//-----------------------------------------------------------------------------------------
[
let len = serverDspLen; let bitMap = Allocate(sysZone, serverDspLen, lv len)
if bitMap eq 0 then bitMap = Allocate(sysZone, len)
let ds = CreateDisplayStream((serverDsp>>DS.fdcb>>DCB.height*2)/fontHeight,
 bitMap, len, sysFont)
let dcb = @displayListHead; while dcb ne 0 do
   [
   if dcb>>DCB.next eq serverDsp>>DS.fdcb then
      [
      ds>>DS.ldcb>>DCB.next = serverDsp>>DS.ldcb>>DCB.next
      dcb>>DCB.next = ds>>DS.fdcb
      Free(sysZone, serverDsp); serverDsp = ds
      break
      ]
   dcb = dcb>>DCB.next
   ]

serverSoc = Allocate(sysZone, lBSPSoc)
serverCtx = Allocate(sysZone, stackSize); Zero(serverCtx, stackSize)
serverCtx = InitializeContext(serverCtx, stackSize, FtpServer, lenExtraCtx)
serverCtx>>FtpCtx.bspSoc = serverSoc
serverCtx>>FtpCtx.lst = lv LsPuts - offset ST.puts/16
serverCtx>>FtpCtx.dls = lv DlsPuts - offset ST.puts/16
serverCtx>>FtpCtx.dbls = lv DblsPuts - offset ST.puts/16
serverCtx>>FtpCtx.dspStream = serverDsp
let bufferLength = tfsFlag? 1024, 6*256
serverCtx>>FtpCtx.buffer = Allocate(sysZone, bufferLength)
serverCtx>>FtpCtx.bufferLength = bufferLength
serverCtx>>FtpCtx.debugFlag = debugFlag
serverCtx>>FtpCtx.Version = FtpSVersion
serverCtx>>FtpCtx.Store = FtpSStore
serverCtx>>FtpCtx.StoreFile = FtpSStoreFile
serverCtx>>FtpCtx.StoreCleanup = FtpSStoreCleanup
serverCtx>>FtpCtx.Retrieve = FtpSRetrieve
serverCtx>>FtpCtx.RetrieveFile = FtpSRetrieveFile
serverCtx>>FtpCtx.RetrieveCleanup = FtpSRetrieveCleanup
serverCtx>>FtpCtx.Delete = FtpSDelete
serverCtx>>FtpCtx.DeleteFile = FtpSDeleteFile
serverCtx>>FtpCtx.Directory = FtpSDirectory
serverCtx>>FtpCtx.Rename = FtpSRename
Enqueue(ctxQ, serverCtx)

serverUFP = @lvUserFinishProc
@lvUserFinishProc = FtpServFinishProc
]