Search in sources :

Example 1 with ConnectionErrorRecord

use of dev.hawala.xns.level4.mailing.MailingCommon.ConnectionErrorRecord in project dodo by devhawala.

the class MailingOldImpl method transport_post.

/*
	 *  post
	 *   = procedure 1
	 */
private static void transport_post(PostParams params, PostResults results) {
    // log ingoing data
    if (logParamsAndResults) {
        StringBuilder sb = new StringBuilder();
        params.append(sb, "  ", "params");
        log("##\n## procedure MailingImpl.transport_post() -- params\n%s\n##\n", sb.toString());
    }
    // check the credentials:
    // - this procedure is called for the generic mail server ("Mail Service:CHServers:CHServers")
    // - not for this specific mail service (which the 1st mail service name in the clearinghouse database)
    // - so use the generic name
    // - and: only the machine id for *this* mail service works...
    Credentials credentials = params.authPair.credentials;
    Verifier verifier = params.authPair.verifier;
    StrongVerifier decodedVerifier = StrongVerifier.make();
    int[] decodedConversationKey = new int[4];
    ThreePartName senderName = // throws an exception on invalid credentials
    mailService.checkCredentials(mailService.getChsDatabase().getGenericMailServiceName(), mailService.getMachineId(), credentials, verifier, decodedConversationKey, decodedVerifier);
    // check the recipients
    NameList allRecipients = NameList.make();
    ChsDatabase chs = mailService.getChsDatabase();
    for (int i = 0; i < params.recipients.size(); i++) {
        Name rcpt = params.recipients.get(i);
        String rcptFqn = chs.resolveName(rcpt);
        List<Name> dlMemberNames;
        if (rcptFqn != null && mailService.hasMailbox(rcptFqn)) {
            Name rcptName = Name.make();
            rcptName.from(rcptFqn);
            allRecipients.addDistinct(rcptName);
        } else if (params.allowDLRecipients.get() && rcptFqn != null && (dlMemberNames = getUserGroupMembersLcFqns(rcptFqn)) != null) {
            for (Name dlMember : dlMemberNames) {
                allRecipients.addDistinct(dlMember);
            }
        } else {
            UndeliveredName undelivered = UndeliveredName.make();
            undelivered.reason.set(UndeliveredNameType.noSuchRecipient);
            undelivered.name.from(rcpt);
            results.invalidNames.add(undelivered);
        }
    }
    // if invalid recipients are not allowed and we have some or if all recipients are invalid: throw error...
    if ((results.invalidNames.size() > 0 && !params.postIfInvalidNames.get()) || results.invalidNames.size() == params.recipients.size()) {
        InvalidRecipientsErrorRecord err = new InvalidRecipientsErrorRecord();
        for (int i = 0; i < results.invalidNames.size(); i++) {
            err.nameList.add(results.invalidNames.get(i));
        }
        err.raise();
    }
    // so create the mail
    try {
        ByteContentSource source = new ByteContentSource(params.content);
        if (allRecipients.size() > 0) {
            int[] mailId = mailService.postMail(senderName, allRecipients, params.contentsType.get(), source);
            for (int i = 0; i < mailId.length; i++) {
                results.msgID.get(i).set(mailId[i]);
            }
        } else {
            // abort bulk-data transfer
            source.read(null);
        }
    } catch (EndOfMessageException e) {
        new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
    }
    // log outgoing data
    if (logParamsAndResults) {
        StringBuilder sb = new StringBuilder();
        results.append(sb, "  ", "results");
        log("##\n## procedure MailingImpl.transport_post() -- results\n%s\n##\n", sb.toString());
    }
}
Also used : NameList(dev.hawala.xns.level4.mailing.MailingCommon.NameList) InvalidRecipientsErrorRecord(dev.hawala.xns.level4.mailing.MailTransport4.InvalidRecipientsErrorRecord) StrongVerifier(dev.hawala.xns.level4.common.AuthChsCommon.StrongVerifier) Verifier(dev.hawala.xns.level4.common.AuthChsCommon.Verifier) ConnectionErrorRecord(dev.hawala.xns.level4.mailing.MailingCommon.ConnectionErrorRecord) Name(dev.hawala.xns.level4.common.AuthChsCommon.Name) UndeliveredName(dev.hawala.xns.level4.mailing.MailingCommon.UndeliveredName) ThreePartName(dev.hawala.xns.level4.common.AuthChsCommon.ThreePartName) StrongVerifier(dev.hawala.xns.level4.common.AuthChsCommon.StrongVerifier) ThreePartName(dev.hawala.xns.level4.common.AuthChsCommon.ThreePartName) UndeliveredName(dev.hawala.xns.level4.mailing.MailingCommon.UndeliveredName) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) ChsDatabase(dev.hawala.xns.level4.common.ChsDatabase) ByteContentSource(dev.hawala.xns.level4.filing.ByteContentSource) Credentials(dev.hawala.xns.level4.common.AuthChsCommon.Credentials)

Example 2 with ConnectionErrorRecord

use of dev.hawala.xns.level4.mailing.MailingCommon.ConnectionErrorRecord in project dodo by devhawala.

the class FilingImpl method changeAttributes.

/*
	 * ChangeAttributes: PROCEDURE [ file: Handle, attributes: AttributeSequence,
	 *                               session: Session ]
	 *   REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
	 *             AuthenticationError, HandleError, InsertionError,
	 *             SessionError, SpaceError, UndefinedError ]
	 *   = 9;
	 */
private static void changeAttributes(ChangeAttributesParams params, RECORD results) {
    logParams("changeAttributes", params);
    // check session
    Session session = resolveSession(params.session);
    Volume vol = session.getService().getVolume();
    // check specified file handle
    Handle fileHandle = Handle.get(params.handle);
    if (fileHandle == null || fileHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    if (fileHandle.isVolumeRoot()) {
        // the file system root cannot be modified
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    FileEntry fe = fileHandle.getFe();
    if (fe == null) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    // change attributes
    List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(params.attributes);
    try (Volume.Session modSession = vol.startModificationSession()) {
        modSession.updateFileAttributes(fe, attrSetters, session.getUsername());
    } catch (InterruptedException e) {
        new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
    } catch (EndOfMessageException e) {
        new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
    } catch (CourierException ce) {
        // this is a RuntimeException, why is it catch-ed by Exception ???????
        throw ce;
    } catch (Exception e1) {
        new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
    }
}
Also used : AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) SpaceErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord) dev.hawala.xns.level4.filing.fs.iValueSetter(dev.hawala.xns.level4.filing.fs.iValueSetter) ConnectionErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord) NoMoreWriteSpaceException(dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) IOException(java.io.IOException) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) UndefinedErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) Volume(dev.hawala.xns.level4.filing.fs.Volume) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry)

Example 3 with ConnectionErrorRecord

use of dev.hawala.xns.level4.mailing.MailingCommon.ConnectionErrorRecord in project dodo by devhawala.

the class FilingImpl method createFile.

private static FileEntry createFile(Volume.Session modificationSession, Session session, long directoryFileID, AttributeSequence pAttributes, iContentSource source, ExceptionHandler exceptionHandler) {
    // get the volume
    Volume vol = session.getService().getVolume();
    // extract the minimal attributes => required: name ; optional: isDirectory(false), version(1/next), type(unknown)
    String name = null;
    boolean isDirectory = false;
    Integer version = null;
    Long type = null;
    for (int i = 0; i < pAttributes.value.size(); i++) {
        Attribute attr = pAttributes.value.get(i);
        switch((int) (attr.type.get() & 0xFFFF)) {
            case FilingCommon.atName:
                name = attr.getAsString();
                break;
            case FilingCommon.atIsDirectory:
                isDirectory = attr.getAsBoolean();
                break;
            case FilingCommon.atVersion:
                version = attr.getAsCardinal();
                break;
            case FilingCommon.atType:
                type = attr.getAsLongCardinal();
                break;
        }
    }
    if (name == null) {
        new AttributeValueErrorRecord(ArgumentProblem.missing, FilingCommon.atName).raise();
    }
    // create the new file
    List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(pAttributes);
    System.out.printf("volStartModificationsession()\n");
    try {
        System.out.printf("createFile( dirId = %d , isdirectory = %s , name = '%s' )\n", directoryFileID, "" + isDirectory, name);
        Volume.Session modSession = (modificationSession == null) ? vol.startModificationSession() : modificationSession;
        final FileEntry fe;
        try {
            fe = modSession.createFile(directoryFileID, isDirectory, name, version, type, session.getUsername(), attrSetters, source);
        } finally {
            if (modificationSession == null) {
                modSession.close();
            }
        }
        System.out.printf("-> done createFile(): fileID = %d\n", (fe != null) ? fe.getFileID() : -2);
        return fe;
    } catch (InterruptedException e) {
        System.out.printf("!!! InterruptedException !!!\n");
        new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
    } catch (EndOfMessageException e) {
        System.out.printf("!!! EndOfMessageException !!!\n");
        new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
    } catch (CourierException ce) {
        // this is a RuntimeException, why is it catch-ed by Exception ???????
        System.out.printf("!!! CourierException !!!\n");
        throw ce;
    } catch (Exception e) {
        System.out.printf("!!! Exception: %s -- %s !!!\n", e.getClass().getName(), e.getMessage());
        if (exceptionHandler != null) {
            exceptionHandler.accept(e);
        } else {
            new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
        }
    }
    // keep the compiler happy
    return null;
}
Also used : AttributeValueErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord) Attribute(dev.hawala.xns.level4.filing.FilingCommon.Attribute) UninterpretedAttribute(dev.hawala.xns.level4.filing.fs.UninterpretedAttribute) SpaceErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord) dev.hawala.xns.level4.filing.fs.iValueSetter(dev.hawala.xns.level4.filing.fs.iValueSetter) ConnectionErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord) NoMoreWriteSpaceException(dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) IOException(java.io.IOException) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) UndefinedErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) Volume(dev.hawala.xns.level4.filing.fs.Volume) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry)

Example 4 with ConnectionErrorRecord

use of dev.hawala.xns.level4.mailing.MailingCommon.ConnectionErrorRecord in project dodo by devhawala.

the class FilingImpl method deserialize.

/*
	 * Deserialize: PROCEDURE [ directory: Handle, attributes: AttributeSequence,
	 *                          controls: ControlSequence, serializedFile: BulkData.Source,
	 *                          session: Session ]
	 *   RETURNS [ file: Handle ]
	 *   REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
	 *             AuthenticationError, ConnectionError, ControlTypeError,
	 *             ControlValueError, HandleError, InsertionError,
	 *             SessionError, SpaceError, TransferError, UndefinedError ]
	 *   = 16;
	 */
private static void deserialize(DeserializeParams params, FileHandleRecord results) {
    logParams("deserialize", params);
    // check session
    Session session = resolveSession(params.session);
    // check directory
    Handle dirHandle = Handle.get(params.directory);
    if (dirHandle == null || dirHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    if (dirHandle.isVolumeRoot()) {
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    // prevent session timeout when processing large trees
    session.holdClosing();
    // do the transfer and deserialization
    try (Volume.Session modSession = session.getService().getVolume().startModificationSession()) {
        SerializedFile deserializedFile = new SerializedFile(ws -> new DeserializeTreeWireStream(ws, dirHandle.getFe().getFileID(), session, results, modSession), false);
        params.serializedFile.receive(deserializedFile);
    } catch (EndOfMessageException e) {
        new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
    } catch (Exception e) {
        System.out.printf("!!! Exception: %s -- %s !!!\n", e.getClass().getName(), e.getMessage());
        new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
    } finally {
        // restart timeout checks on the session
        session.continueUse();
    }
}
Also used : AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) Volume(dev.hawala.xns.level4.filing.fs.Volume) SerializedFile(dev.hawala.xns.level4.filing.FilingCommon.SerializedFile) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) SpaceErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord) ConnectionErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord) NoMoreWriteSpaceException(dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) IOException(java.io.IOException) CourierException(dev.hawala.xns.level3.courier.exception.CourierException)

Example 5 with ConnectionErrorRecord

use of dev.hawala.xns.level4.mailing.MailingCommon.ConnectionErrorRecord in project dodo by devhawala.

the class FilingImpl method store.

/*
	 * Store: PROCEDURE [ directory: Handle, attributes: AttributeSequence,
	 *                    controls: ControlSequence, content: BulkData.Source,
	 *                    session: Session ]
	 *   RETURNS [ file: Handle ]
	 *   REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
	 *             AuthenticationError, ConnectionError, ControlTypeError,
	 *             ControlValueError, HandleError, InsertionError,	SessionError,
	 *             SpaceError, TransferError, UndefinedError ]
	 *   = 12;
	 */
private static void store(StoreParams params, FileHandleRecord results) {
    logParams("store", params);
    // check session
    Session session = resolveSession(params.session);
    // check specified directory file handle
    Handle dirHandle = Handle.get(params.directory);
    if (dirHandle.isVolumeRoot()) {
        // the file system root cannot be modified
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    if (dirHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.directoryRequired).raise();
    }
    // TODO: check (access-)controls on directory
    final FileEntry fe;
    try {
        ByteContentSource source = new ByteContentSource(params.content);
        fe = createFile(null, session, dirHandle.getFe().getFileID(), params.attributes, source, null);
    } catch (EndOfMessageException e) {
        new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
        return;
    }
    // prepare results
    Handle fileHandle = new Handle(session, fe);
    fileHandle.setIdTo(results.file);
    logResult("store", results);
    // prolongate the sessions life if this took longer
    session.continueUse();
}
Also used : AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry) ConnectionErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord)

Aggregations

EndOfMessageException (dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException)5 ConnectionErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord)4 CourierException (dev.hawala.xns.level3.courier.exception.CourierException)3 NoMoreWriteSpaceException (dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException)3 AccessErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord)3 HandleErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord)3 SpaceErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord)3 FileEntry (dev.hawala.xns.level4.filing.fs.FileEntry)3 Volume (dev.hawala.xns.level4.filing.fs.Volume)3 IOException (java.io.IOException)3 UndefinedErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord)2 dev.hawala.xns.level4.filing.fs.iValueSetter (dev.hawala.xns.level4.filing.fs.iValueSetter)2 Credentials (dev.hawala.xns.level4.common.AuthChsCommon.Credentials)1 Name (dev.hawala.xns.level4.common.AuthChsCommon.Name)1 StrongVerifier (dev.hawala.xns.level4.common.AuthChsCommon.StrongVerifier)1 ThreePartName (dev.hawala.xns.level4.common.AuthChsCommon.ThreePartName)1 Verifier (dev.hawala.xns.level4.common.AuthChsCommon.Verifier)1 ChsDatabase (dev.hawala.xns.level4.common.ChsDatabase)1 ByteContentSource (dev.hawala.xns.level4.filing.ByteContentSource)1 Attribute (dev.hawala.xns.level4.filing.FilingCommon.Attribute)1