-- file: STP.mesa  Edited by:
  -- Smokey on: Oct 3, 1980 8:17 AM
  -- Karlton on: Sep 29, 1980 2:48 PM
  
  DIRECTORY
    Ascii USING [NUL],
    Compatibility USING [SHandle],
    Stream USING [
      Handle, InputOptions, SetSSTProcedure, SendAttentionProcedure, WaitAttentionProcedure],
    System USING [gmtEpoch],
    Time USING [Packed];
    
  STP: DEFINITIONS =
    BEGIN
    
-- Types and data

  Handle: TYPE = POINTER TO Object;
  Object: TYPE;
  
  Access: TYPE = {read, write};
  Completion: TYPE = {ok, error};
  Continue: TYPE = {yes, no};
  Confirmation: TYPE = {do, skip, abort};
  CompletionProcType: TYPE = PROCEDURE [what: Completion, fileOrError: STRING];
  ConfirmProcType: TYPE = PROCEDURE [file: STRING]
    RETURNS [answer: Confirmation, localStream: Stream.Handle];
  NoteFileProcType: TYPE = PROCEDURE [file: STRING] RETURNS [continue: Continue];
  FileInfo: TYPE = POINTER TO FileInfoObject;
  FileInfoObject: TYPE = RECORD [
    directory, body, version: STRING ← NIL,
    author: STRING ← NIL,
    create, read, write: STRING ← NIL,
    size: LONG CARDINAL ← 0,
    type: FileType ← unknown];
  FileType: TYPE = {binary, text, unknown};
  
  defaultOptions: Stream.InputOptions = [
    terminateOnEndPhysicalRecord: FALSE,
    signalLongBlock: FALSE,
    signalShortBlock: FALSE,
    signalSSTChange: TRUE,
    signalEndOfStream: TRUE];
    
-- Procedures

  Close: PROCEDURE [stp: Handle];
  Connect: PROCEDURE [stp: Handle, name, password: STRING];
  Create: PROCEDURE RETURNS [stp: Handle];
  CreateRemoteStream: PROCEDURE [
    stp: Handle,
    file: STRING,
    access: Access,
    fileType: FileType ← unknown,
    options: Stream.InputOptions ← defaultOptions,
    creation: Time.Packed ← System.gmtEpoch]
    RETURNS[stream: Stream.Handle];
  Delete: PROCEDURE [
    stp: Handle,
    name: STRING,
    confirm: ConfirmProcType ← NIL,
    complete: CompletionProcType ← NIL];
  Destroy: PROCEDURE [stp: Handle] RETURNS [Handle];
  Enumerate: PROCEDURE [stp: Handle, name: STRING, proc: NoteFileProcType];
  GetFileInfo: PROCEDURE [stp: Handle] RETURNS [FileInfo];
  Login: PROCEDURE [stp: Handle, name, password: STRING];
  NextFileName: PROCEDURE [remoteStream: Stream.Handle] RETURNS [file: STRING];
  Open: PROCEDURE [stp: Handle, host: STRING] RETURNS [herald: STRING];
  Rename: PROCEDURE [stp: Handle, old, new: STRING];
  Retrieve: PROCEDURE [
    stp: Handle,
    file: STRING,
    confirm: ConfirmProcType ← NIL,
    complete: CompletionProcType ← NIL];
  SetHost: PROCEDURE [stp: Handle, host: STRING];
  SetDirectory: PROCEDURE [stp: Handle, directory: STRING];
  Store: PROCEDURE [
    stp: Handle,
    file: STRING,
    stream: Stream.Handle ← NIL,
    noteFile: NoteFileProcType ← NIL,
    fileType: FileType ←  unknown,
    creation: Time.Packed ← System.gmtEpoch];
    
-- For Alto/Pilot Compatibility purposes

  CreateFileStream: PROCEDURE [
    file: STRING,
    access: Access ← read,
    stream: Compatibility.SHandle ← NIL,
    fileType: FileType ← unknown,
    options: Stream.InputOptions ← defaultOptions]
    RETURNS[Stream.Handle];
  GetFileTimes: PROCEDURE [stream: Stream.Handle]
    RETURNS[create, write, read: Time.Packed];
    
-- Nop Procedures

  SetSSTNop: Stream.SetSSTProcedure;
  SendAttentionNop: Stream.SendAttentionProcedure;
  WaitAttentionNop: Stream.WaitAttentionProcedure;
  
-- Signals and Errors

  Error: SIGNAL [
    code: ErrorCode, error: STRING, reply: CHARACTER ← Ascii.NUL];
    -- reply is the code passed from server (see STPReplyCode.mesa)
  ErrorCode: TYPE = {
    -- connection errors
    noSuchHost, noRouteToNetwork, noNameLookupResponse, alreadyAConnection,
    noConnection, connectionClosed, connectionRejected,
    connectionTimedOut,
    -- credentials errors
    accessDenied, illegalUserName, illegalUserPassword, illegalUserAccount,
    illegalConnectName, illegalConnectPassword, credentailsMissing,  
    -- protocol errors
    protocolError, 
    -- file errors
    illegalFileName, noSuchFile, requestRefused,
    -- remote stream errors
    accessError, 
    -- catch all
    undefinedError};
    
  ConnectionErrors: TYPE = ErrorCode[noSuchHost..connectionTimedOut];
  CredentialsErrors: TYPE = ErrorCode[accessDenied..credentailsMissing];
  FileErrors: TYPE = ErrorCode[illegalFileName..requestRefused];
  
  END. -- end of STP