use of dev.hawala.xns.level4.filing.FilingCommon.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());
}
}
use of dev.hawala.xns.level4.filing.FilingCommon.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();
}
}
use of dev.hawala.xns.level4.filing.FilingCommon.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;
}
use of dev.hawala.xns.level4.filing.FilingCommon.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();
}
}
use of dev.hawala.xns.level4.filing.FilingCommon.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();
}
Aggregations