-- File: [Igor]<Emerson>STP>Friends>UnsafeSTP.mesa  Edited by:
-- Smokey,	 6-Jul-81 17:58:25
-- Karlton,	 9-Dec-81 18:11:47
-- Bruce,	10-Nov-81 16:15:44
-- Mark,	21-May-81 15:45:50
-- JGS,		14-Aug-81 16:50:01
-- Davirro,	27-Aug-82 15:40:22
-- Loretta,	14-Sep-82 15:10:46
-- Schmidt February 6, 1983 9:03 pm

DIRECTORY
  Ascii USING [NUL],
  Stream USING [
    Handle, InputOptions, SetSSTProcedure,
    SendAttentionProcedure, WaitAttentionProcedure],
  System USING [gmtEpoch],
  Time USING [Packed];
    
  UnsafeSTP: DEFINITIONS =
    BEGIN
    
-- Types and data

  Handle: TYPE = LONG POINTER TO Object;
  Object: TYPE;
  
  Access: TYPE = {read, write};
  Completion: TYPE = {ok, error};
  Continue: TYPE = {yes, no};
  Confirmation: TYPE = {do, skip, abort};
  ValidProperties: TYPE = {
    userName, userPassword, connectName, connectPassword, directory, nameBody,
    version, createDate, readDate, writeDate, byteSize, type, size, author,
    eolConversion, account, userAccount, device, serverName};
  DesiredProperties: TYPE = PACKED ARRAY ValidProperties OF BOOLEAN ← ALL[FALSE];
  CompletionProcType: TYPE = PROCEDURE [what: Completion, fileOrError: LONG STRING];
  ConfirmProcType: TYPE = PROCEDURE [file: LONG STRING]
    RETURNS [answer: Confirmation, localStream: Stream.Handle];
  NoteFileProcType: TYPE = PROCEDURE [file: LONG STRING] RETURNS [continue: Continue];
  FileInfo: TYPE = LONG POINTER TO FileInfoObject;
  FileInfoObject: TYPE = RECORD [
    directory, body, version: LONG STRING ← NIL,
    author: LONG STRING ← NIL,
    create, read, write: LONG STRING ← NIL,
    size: LONG CARDINAL ← 0,
    type: Type ← unknown];
  Type: TYPE = MACHINE DEPENDENT {unknown(0), text, binary};
  
  defaultOptions: Stream.InputOptions = [
    terminateOnEndPhysicalRecord: FALSE,
    signalLongBlock: FALSE,
    signalShortBlock: FALSE,
    signalSSTChange: TRUE,
    signalEndOfStream: TRUE];
    
-- Procedures

  Close: PROCEDURE [stp: Handle];
  Connect: PROCEDURE [stp: Handle, name, password: LONG STRING];
  Create: PROCEDURE RETURNS [stp: Handle];
  CreateRemoteStream: PROCEDURE [
    stp: Handle,
    file: LONG STRING,
    access: Access,
    fileType: Type ← unknown,
    options: Stream.InputOptions ← defaultOptions,
    creation: Time.Packed ← System.gmtEpoch]
    RETURNS[stream: Stream.Handle];
  Delete: PROCEDURE [
    stp: Handle,
    name: LONG STRING,
    confirm: ConfirmProcType ← NIL,
    complete: CompletionProcType ← NIL];
  Destroy: PROCEDURE [stp: Handle] RETURNS [Handle];
  Enumerate: PROCEDURE [stp: Handle, name: LONG STRING, proc: NoteFileProcType];
  IsOpen: PROCEDURE [stp: Handle] RETURNS [yes: BOOLEAN];
  GetFileInfo: PROCEDURE [stp: Handle] RETURNS [FileInfo];
  GetProperty: PROCEDURE [stp: Handle, prop: ValidProperties] RETURNS [LONG STRING];
  GetDesiredProperties: PROCEDURE [stp: Handle] RETURNS [props: DesiredProperties];
  Login: PROCEDURE [stp: Handle, name, password: LONG STRING];
  NextFileName: PROCEDURE [remoteStream: Stream.Handle] RETURNS [file: LONG STRING];
  Open: PROCEDURE [stp: Handle, host: LONG STRING] RETURNS [herald: LONG STRING];
  Rename: PROCEDURE [stp: Handle, old, new: LONG STRING];
  Retrieve: PROCEDURE [
    stp: Handle,
    file: LONG STRING,
    confirm: ConfirmProcType ← NIL,
    complete: CompletionProcType ← NIL];
  SetHost: PROCEDURE [stp: Handle, host: LONG STRING];
  SetDirectory: PROCEDURE [stp: Handle, directory: LONG STRING];
  SetDesiredProperties: PROCEDURE [stp: Handle, props: DesiredProperties];
  Store: PROCEDURE [
    stp: Handle,
    file: LONG STRING,
    stream: Stream.Handle,
    noteFile: NoteFileProcType ← NIL,
    fileType: Type ←  unknown,
    creation: Time.Packed ← System.gmtEpoch];
    
-- Nop Procedures

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

  Error: SIGNAL [
    stp: Handle, code: ErrorCode, error: LONG 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