[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-157]
change SubsystemHandler/SFTPServerInterface API change the API of SubsystemHandler to accept a reference to the ServerInstance object during construction. this will break all code that currently creates subsystem handlers (like sftp servers) -- sorry! lots of little doc fixups (mostly indenting).
This commit is contained in:
parent
5d8d1938fa
commit
71a337ee08
|
@ -306,7 +306,7 @@ class ServerInterface (object):
|
|||
handler_class, larg, kwarg = channel.get_transport()._get_subsystem_handler(name)
|
||||
if handler_class is None:
|
||||
return False
|
||||
handler = handler_class(channel, name, *larg, **kwarg)
|
||||
handler = handler_class(channel, name, self, *larg, **kwarg)
|
||||
handler.start()
|
||||
return True
|
||||
|
||||
|
@ -353,7 +353,7 @@ class SubsystemHandler (threading.Thread):
|
|||
|
||||
@since: ivysaur
|
||||
"""
|
||||
def __init__(self, channel, name):
|
||||
def __init__(self, channel, name, server):
|
||||
"""
|
||||
Create a new handler for a channel. This is used by L{ServerInterface}
|
||||
to start up a new handler when a channel requests this subsystem. You
|
||||
|
@ -365,11 +365,24 @@ class SubsystemHandler (threading.Thread):
|
|||
@type channel: L{Channel}
|
||||
@param name: name of the requested subsystem.
|
||||
@type name: str
|
||||
@param server: the server object for the session that started this
|
||||
subsystem
|
||||
@rtype server: L{ServerInterface}
|
||||
"""
|
||||
threading.Thread.__init__(self, target=self._run)
|
||||
self.__channel = channel
|
||||
self.__transport = channel.get_transport()
|
||||
self.__name = name
|
||||
self.__server = server
|
||||
|
||||
def get_server(self):
|
||||
"""
|
||||
Return the L{ServerInterface} object associated with this channel and
|
||||
subsystem.
|
||||
|
||||
@rtype: L{ServerInterface}
|
||||
"""
|
||||
return self.__server
|
||||
|
||||
def _run(self):
|
||||
try:
|
||||
|
@ -398,10 +411,9 @@ class SubsystemHandler (threading.Thread):
|
|||
@note: It is the responsibility of this method to exit if the
|
||||
underlying L{Transport} is closed. This can be done by checking
|
||||
L{Transport.is_active <BaseTransport.is_active>} or noticing an EOF
|
||||
on the L{Channel}.
|
||||
If this method loops forever without checking for this case, your
|
||||
python interpreter may refuse to exit because this thread will still
|
||||
be running.
|
||||
on the L{Channel}. If this method loops forever without checking
|
||||
for this case, your python interpreter may refuse to exit because
|
||||
this thread will still be running.
|
||||
|
||||
@param name: name of the requested subsystem.
|
||||
@type name: str
|
||||
|
|
|
@ -37,26 +37,26 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
|
|||
Use L{Transport.set_subsystem_handler} to activate this class.
|
||||
"""
|
||||
|
||||
def __init__(self, channel, name, server=SFTPServerInterface, server_args=None):
|
||||
def __init__(self, channel, name, server, sftp_si=SFTPServerInterface, *largs, **kwargs):
|
||||
"""
|
||||
The constructor for SFTPServer is meant to be called from within the
|
||||
L{Transport} as a subsystem handler. The C{server} and C{server_args}
|
||||
parameters are passed from the original call to
|
||||
L{Transport} as a subsystem handler. C{server} and any additional
|
||||
parameters or keyword parameters are passed from the original call to
|
||||
L{Transport.set_subsystem_handler}.
|
||||
|
||||
@param channel: channel passed from the L{Transport}.
|
||||
@type channel: L{Channel}
|
||||
@param name: name of the requested subsystem.
|
||||
@type name: str
|
||||
@param server: a subclass of L{SFTPServerInterface} to use for handling
|
||||
@param server: the server object associated with this channel and
|
||||
subsystem
|
||||
@type server: L{ServerInterface}
|
||||
@param sftp_si: a subclass of L{SFTPServerInterface} to use for handling
|
||||
individual requests.
|
||||
@type server: class
|
||||
@param server_args: keyword parameters to pass to C{server} when it's
|
||||
constructed.
|
||||
@type server_args: dict
|
||||
@type sftp_si: class
|
||||
"""
|
||||
BaseSFTP.__init__(self)
|
||||
SubsystemHandler.__init__(self, channel, name)
|
||||
SubsystemHandler.__init__(self, channel, name, server)
|
||||
transport = channel.get_transport()
|
||||
self.logger = util.get_logger(transport.get_log_channel() + '.' +
|
||||
channel.get_name() + '.sftp')
|
||||
|
@ -65,9 +65,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
|
|||
# map of handle-string to SFTPHandle for files & folders:
|
||||
self.file_table = { }
|
||||
self.folder_table = { }
|
||||
if server_args is None:
|
||||
server_args = {}
|
||||
self.server = server(**server_args)
|
||||
self.server = sftp_si(server, *largs, **kwargs)
|
||||
|
||||
def start_subsystem(self, name, transport, channel):
|
||||
self.sock = channel
|
||||
|
|
|
@ -38,6 +38,17 @@ class SFTPServerInterface (object):
|
|||
return an appropriate error code.
|
||||
"""
|
||||
|
||||
def __init__ (self, server, *largs, **kwargs):
|
||||
"""
|
||||
Create a new SFTPServerInterface object. This method does nothing by
|
||||
default and is meant to be overridden by subclasses.
|
||||
|
||||
@param server: the server object associated with this channel and
|
||||
SFTP subsystem
|
||||
@type server: L{ServerInterface}
|
||||
"""
|
||||
super(SFTPServerInterface, self).__init__(*largs, **kwargs)
|
||||
|
||||
def session_started(self):
|
||||
"""
|
||||
The SFTP server session has just started. This method is meant to be
|
||||
|
|
|
@ -762,7 +762,7 @@ class BaseTransport (threading.Thread):
|
|||
|
||||
def set_subsystem_handler(self, name, handler, *larg, **kwarg):
|
||||
"""
|
||||
Set the handler class for a subsystem in server mode. If a reqeuest
|
||||
Set the handler class for a subsystem in server mode. If a request
|
||||
for this subsystem is made on an open ssh channel later, this handler
|
||||
will be constructed and called -- see L{SubsystemHandler} for more
|
||||
detailed documentation.
|
||||
|
|
Loading…
Reference in New Issue