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 20c2392d2b5f933c43ac60d530e6f95d44c08509
Author: Thomas Wolf <thomas.w...@paranor.ch>
AuthorDate: Tue Jul 28 16:59:25 2020 +0300

    [SSHD-1042] Added more callbacks to SftpEventListener
---
 .../sftp/server/AbstractSftpSubsystemHelper.java   | 22 +++++++++++++++-
 .../apache/sshd/sftp/server/SftpEventListener.java | 29 ++++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git 
a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java
 
b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java
index c1df158..4a8a7d9 100644
--- 
a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java
+++ 
b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java
@@ -310,6 +310,17 @@ public abstract class AbstractSftpSubsystemHelper
             log.debug("process({})[length={}, type={}, id={}] processing",
                     getServerSession(), length, 
SftpConstants.getCommandMessageName(type), id);
         }
+        try {
+            SftpEventListener listener = getSftpEventListenerProxy();
+            ServerSession session = getServerSession();
+            listener.received(session, type, id);
+        } catch (IOException | RuntimeException e) {
+            if (type == SftpConstants.SSH_FXP_INIT) {
+                throw e;
+            }
+            sendStatus(prepareReply(buffer), id, e, type);
+            return;
+        }
         doProcess(buffer, length, type, id);
     }
 
@@ -1650,7 +1661,16 @@ public abstract class AbstractSftpSubsystemHelper
     }
 
     protected void doExtended(Buffer buffer, int id) throws IOException {
-        executeExtendedCommand(buffer, id, buffer.getString());
+        String extension = buffer.getString();
+        try {
+            SftpEventListener listener = getSftpEventListenerProxy();
+            ServerSession session = getServerSession();
+            listener.receivedExtension(session, extension, id);
+        } catch (IOException | RuntimeException e) {
+            sendStatus(prepareReply(buffer), id, e, 
SftpConstants.SSH_FXP_EXTENDED, extension);
+            return;
+        }
+        executeExtendedCommand(buffer, id, extension);
     }
 
     /**
diff --git 
a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpEventListener.java 
b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpEventListener.java
index 9ba8131..5367ebf 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpEventListener.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpEventListener.java
@@ -27,6 +27,7 @@ import java.util.Map;
 
 import org.apache.sshd.common.util.SshdEventListener;
 import org.apache.sshd.server.session.ServerSession;
+import org.apache.sshd.sftp.common.SftpConstants;
 
 /**
  * Can be used register for SFTP events. <B>Note:</B> it does not expose the 
entire set of available SFTP commands and
@@ -35,6 +36,34 @@ import org.apache.sshd.server.session.ServerSession;
  * @author <a href="mailto:d...@mina.apache.org";>Apache MINA SSHD Project</a>
  */
 public interface SftpEventListener extends SshdEventListener {
+
+    /**
+     * Called when a SFTP request has been received before it is processed.
+     *
+     * @param  session     The {@link ServerSession} through which the request 
was received
+     * @param  type        The request type; one of the {@code SSH_FXP_*} 
constants from {@link SftpConstants}
+     * @param  id          The id received with the request
+     * @throws IOException If the request shall generate an error response. 
Throwing an exception for
+     *                     {@code type = }{@link SftpConstants#SSH_FXP_INIT} 
closes the session.
+     */
+    default void received(ServerSession session, int type, int id) throws 
IOException {
+        // empty
+    }
+
+    /**
+     * Called when a SFTP extension request {@link 
SftpConstants#SSH_FXP_EXTENDED} has been received before it is
+     * processed.
+     *
+     * @param  session     The {@link ServerSession} through which the request 
was received
+     * @param  extension   The extension request received; one of the {@code 
SSH_EXT_*} constants from
+     *                     {@link SftpConstants}
+     * @param  id          The id received with the request
+     * @throws IOException If the request shall generate an error response.
+     */
+    default void receivedExtension(ServerSession session, String extension, 
int id) throws IOException {
+        // empty
+    }
+
     /**
      * Called when the SFTP protocol has been initialized
      *

Reply via email to