This is an automated email from the ASF dual-hosted git repository. lgoldstein pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mina-sshd.git
commit e18854aff026a33d2c0d93dc0a3f4b83ca979bf1 Author: Lyor Goldstein <[email protected]> AuthorDate: Wed Jun 26 17:58:14 2019 +0300 [SSHD-927] Updated SFTP readme with an abridged version of how to contribute a new SFTP extension to the code --- docs/sftp.md | 13 +++++++++++++ .../common/subsystem/sftp/extensions/ParserUtils.java | 18 ++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/sftp.md b/docs/sftp.md index a6f0373..49dee63 100644 --- a/docs/sftp.md +++ b/docs/sftp.md @@ -445,6 +445,19 @@ One can skip all the conditional code if a specific known extension is required: ``` +### Contributing support for a new extension + +* Add the code to handle the new extension in `AbstractSftpSubsystemHelper#executeExtendedCommand` + +* Declare the extension name in `DEFAULT_SUPPORTED_CLIENT_EXTENSIONS` (same class) + +* In the `org.apache.sshd.client.subsystem.sftp.extensions.helpers` package implement an extension of `AbstractSftpClientExtension` +for sending and receiving the newly added extension. + +* Add a relevant parser for reported extension data initial report (if necessary) in `ParserUtils#BUILT_IN_PARSERS` + +See how other extensions are implemented and follow their example + ### Internal exceptions and error message handling If an exception is thrown during processing of an SFTP command, then the exception is translated into a `SSH_FXP_STATUS` message diff --git a/sshd-sftp/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/ParserUtils.java b/sshd-sftp/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/ParserUtils.java index 958c84f..9c4231a 100644 --- a/sshd-sftp/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/ParserUtils.java +++ b/sshd-sftp/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/ParserUtils.java @@ -25,11 +25,15 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.NavigableMap; import java.util.Objects; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; +import java.util.function.Function; +import java.util.stream.Collectors; +import org.apache.sshd.common.NamedResource; import org.apache.sshd.common.subsystem.sftp.extensions.Supported2Parser.Supported2; import org.apache.sshd.common.subsystem.sftp.extensions.SupportedParser.Supported; import org.apache.sshd.common.subsystem.sftp.extensions.openssh.FstatVfsExtensionParser; @@ -61,14 +65,12 @@ public final class ParserUtils { FsyncExtensionParser.INSTANCE )); - private static final Map<String, ExtensionParser<?>> PARSERS_MAP; - - static { - PARSERS_MAP = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - for (ExtensionParser<?> p : BUILT_IN_PARSERS) { - PARSERS_MAP.put(p.getName(), p); - } - } + private static final NavigableMap<String, ExtensionParser<?>> PARSERS_MAP = + Collections.unmodifiableNavigableMap( + BUILT_IN_PARSERS.stream() + .collect(Collectors.toMap( + NamedResource::getName, Function.identity(), + GenericUtils.throwingMerger(), () -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER)))); private ParserUtils() { throw new UnsupportedOperationException("No instance");
