-- FTPProtError.mesa, Edit: HGM October 13, 1980  7:49 PM  

-- Copyright  Xerox Corporation 1979, 1980

DIRECTORY
  FTPDefs,
  FTPPrivateDefs;

FTPProtError: PROGRAM IMPORTS FTPPrivateDefs EXPORTS FTPPrivateDefs SHARES FTPDefs
  =
  BEGIN OPEN FTPDefs, FTPPrivateDefs;



  SignalToCode: PUBLIC PROCEDURE [ftpError: FtpError] RETURNS [code: Byte] =
    BEGIN
    code ←
      SELECT ftpError FROM
	-- communication errors
	-- IN CommunicationError	=> codeUnidentifiedPermanentError,
	-- credential errors

	credentialsMissing => codeMissingUserName,
	noSuchPrimaryUser => codeIllegalUserName,
	noSuchSecondaryUser => codeIllegalConnectName,
	incorrectPrimaryPassword => codeBadUserPassword,
	incorrectSecondaryPassword => codeBadConnectPassword,
	requestedAccessDenied => codeRequestedAccessDenied,
	-- file errors

	illegalFilename => codeIllegalServerFilename,
	noSuchFile => codeFileNotFound,
	fileAlreadyExists => codeFileAlreadyExists,
	fileBusy => codeFileBusy,
	noRoomForFile => codeStorageExhausted,
	fileDataError => codeFileDataError,
	-- dump errors

	IN DumpError => codeFileDataError,
	-- mail errors

	noValidRecipients => codeNoValidMailbox,
	noSuchMailbox => codeIllegalMailbox,
	-- client errors
	-- IN ClientError		=> codeUnidentifiedPermanentError,
	-- protocol errors

	IN UndefinedFunctionError => codeCommandUndefined,
	IN ProtocolSequenceError => codeCommandIllegal,
	IN IllegalParameterListError => codeMalformedPropertyList,
	illegalFileType => codeIllegalType,
	-- IN ProtocolError		=> codeUnidentifiedPermanentError,
	-- internal errors
	-- IN InternalError		=> codeUnidentifiedPermanentError,
	-- unidentified errors

	unidentifiedTransientError => codeUnidentifiedTransientError,
	ENDCASE => codeUnidentifiedPermanentError;
    END;

  CodeToSignal: PUBLIC PROCEDURE [code: Byte] RETURNS [ftpError: FtpError] =
    BEGIN
    ftpError ←
      SELECT code FROM
	0 => unidentifiedError,
	codeCommandUndefined => functionNotImplemented,
	codeMissingUserName => credentialsMissing,
	codeCommandIllegal => illegalProtocolSequence,
	codeMalformedPropertyList => illegalProtocolParameterList,
	IN [codeIllegalServerFilename..codeIllegalVersion] => illegalFilename,
	codeIllegalType => illegalFileType,
	IN [codeIllegalByteSize..codeIllegalEndOfLineConvention] =>
	  illegalFileAttribute,
	codeIllegalUserName => noSuchPrimaryUser,
	codeBadUserPassword => incorrectPrimaryPassword,
	codeBadUserAccount => unidentifiedPermanentError,
	codeIllegalConnectName => noSuchSecondaryUser,
	codeBadConnectPassword => incorrectSecondaryPassword,
	IN [codeIllegalCreationDate..codeIllegalAuthor] => illegalFileAttribute,
	codeIllegalDevice => illegalFilename,
	codeNoValidMailbox => noValidRecipients,
	codeIllegalMailbox => noSuchMailbox,
	codeFileNotFound => noSuchFile,
	codeRequestedAccessDenied => requestedAccessDenied,
	codeTransferParametersInconsistent => illegalProtocolSequence,
	codeFileDataError => fileDataError,
	codeStorageExhausted => noRoomForFile,
	-- codeDontSendFile,
	-- codeStoreNotCompleted	=> unidentifiedError,

	codeUnidentifiedTransientError => unidentifiedTransientError,
	codeUnidentifiedPermanentError => unidentifiedPermanentError,
	codeFileBusy => fileBusy,
	codeFileAlreadyExists => fileAlreadyExists,
	ENDCASE => unrecognizedProtocolErrorCode;
    END;

  RecipientErrorToExceptionCode: PUBLIC PROCEDURE [recipientError: RecipientError]
    RETURNS [exceptionCode: Byte] =
    BEGIN
    exceptionCode ←
      SELECT recipientError FROM
	noSuchMailbox => excpCannotLocateMailbox,
	noForwardingProvided => excpNoForwardingProvided,
	unspecifiedTransientError => excpTransientError,
	unspecifiedPermanentError => excpPermanentError,
	ENDCASE => excpUnspecifiedFailure;
    END;

  ExceptionCodeToRecipientError: PUBLIC PROCEDURE [exceptionCode: Byte]
    RETURNS [recipientError: RecipientError] =
    BEGIN
    IF exceptionCode ~IN [excpMinimum..excpMaximum] THEN
      Abort[unrecognizedMailboxExceptionErrorCode];
    recipientError ←
      SELECT exceptionCode FROM
	-- excpUnspecifiedFailure	=> unspecifiedError,

	excpCannotLocateMailbox => noSuchMailbox,
	excpNoForwardingProvided => noForwardingProvided,
	excpTransientError => unspecifiedTransientError,
	excpPermanentError => unspecifiedPermanentError,
	ENDCASE => unspecifiedError;
    END;

  END..  -- FTPProtError