Code refactoring

This commit is contained in:
speyrefitte
2014-06-23 14:42:49 +02:00
parent 450be029cd
commit dc7d2d56c5
6 changed files with 46 additions and 35 deletions

View File

@@ -5,6 +5,7 @@ Remote Desktop Protocol in Twisted Python
## Requirements ## Requirements
* python2.7 * python2.7
* python-twisted * python-twisted
* python-openssl
## Requirements for examples ## Requirements for examples
* python-qt4 * python-qt4
@@ -15,5 +16,6 @@ Remote Desktop Protocol in Twisted Python
* Packet redirection * Packet redirection
* License * License
* Most common orders * Most common orders
* FastPath messages
this project is still in progress. this project is still in progress.

View File

@@ -61,8 +61,11 @@ class RFBClientQt(RFBClientObserver, QAdaptor):
QAdaptor for specific RFB protocol stack QAdaptor for specific RFB protocol stack
is to an RFB observer is to an RFB observer
''' '''
def __init__(self): def __init__(self, controller):
RFBClientObserver.__init__(self) """
@param controller: controller for obser
"""
RFBClientObserver.__init__(self, controller)
self._widget = QRemoteDesktop(self) self._widget = QRemoteDesktop(self)
def getWidget(self): def getWidget(self):
@@ -118,8 +121,11 @@ class RDPClientQt(RDPClientObserver, QAdaptor):
''' '''
Adaptor for RDP client Adaptor for RDP client
''' '''
def __init__(self): def __init__(self, controller):
RDPClientObserver.__init__(self) """
@param controller: RDP controller
"""
RDPClientObserver.__init__(self, controller)
self._widget = QRemoteDesktop(self) self._widget = QRemoteDesktop(self)
def getWidget(self): def getWidget(self):

View File

@@ -31,16 +31,17 @@ from PyQt4 import QtGui
from rdpy.display.qt import RDPClientQt from rdpy.display.qt import RDPClientQt
from rdpy.protocol.rdp import rdp from rdpy.protocol.rdp import rdp
class RDPClientQtFactory(rdp.Factory): class RDPClientQtFactory(rdp.ClientFactory):
''' """
Factory create a RDP GUI client Factory create a RDP GUI client
''' """
def buildObserver(self): def buildObserver(self, controller):
''' """
build RFB observer Build RFB observer
''' @param controller: build factory and needed by observer
"""
#create client observer #create client observer
client = RDPClientQt() client = RDPClientQt(controller)
#create qt widget #create qt widget
self._w = client.getWidget() self._w = client.getWidget()
self._w.resize(1024, 800) self._w.resize(1024, 800)
@@ -52,21 +53,21 @@ class RDPClientQtFactory(rdp.Factory):
pass pass
def clientConnectionLost(self, connector, reason): def clientConnectionLost(self, connector, reason):
''' """
connection lost event Connection lost event
@param connector: twisted connector use for rdp connection (use reconnect to restart connection) @param connector: twisted connector use for rdp connection (use reconnect to restart connection)
@param reason: str use to advertise reason of lost connection @param reason: str use to advertise reason of lost connection
''' """
QtGui.QMessageBox.warning(self._w, "Warning", "Lost connection : %s"%reason) QtGui.QMessageBox.warning(self._w, "Warning", "Lost connection : %s"%reason)
reactor.stop() reactor.stop()
app.exit() app.exit()
def clientConnectionFailed(self, connector, reason): def clientConnectionFailed(self, connector, reason):
''' """
connection failed event Connection failed event
@param connector: twisted connector use for rdp connection (use reconnect to restart connection) @param connector: twisted connector use for rdp connection (use reconnect to restart connection)
@param reason: str use to advertise reason of lost connection @param reason: str use to advertise reason of lost connection
''' """
QtGui.QMessageBox.warning(self._w, "Warning", "Connection failed : %s"%reason) QtGui.QMessageBox.warning(self._w, "Warning", "Connection failed : %s"%reason)
reactor.stop() reactor.stop()
app.exit() app.exit()

View File

@@ -35,12 +35,13 @@ class RFBClientQtFactory(rfb.Factory):
""" """
Factory create a VNC GUI client Factory create a VNC GUI client
""" """
def buildObserver(self): def buildObserver(self, controller):
""" """
Build RFB Client observer Build RFB Client observer
@param controller: build by factory
""" """
#create client observer #create client observer
client = RFBClientQt() client = RFBClientQt(controller)
#create qt widget #create qt widget
self._w = client.getWidget() self._w = client.getWidget()
self._w.resize(1024, 800) self._w.resize(1024, 800)

View File

@@ -43,7 +43,7 @@ class RDPController(object):
for rectangle in bitmapUpdateData.rectangles._array: for rectangle in bitmapUpdateData.rectangles._array:
observer.onBitmapUpdate(rectangle.destLeft.value, rectangle.destTop.value, rectangle.destRight.value, rectangle.destBottom.value, rectangle.width.value, rectangle.height.value, rectangle.bitsPerPixel.value, (rectangle.flags & pdu.BitmapFlag.BITMAP_COMPRESSION).value, rectangle.bitmapDataStream.value) observer.onBitmapUpdate(rectangle.destLeft.value, rectangle.destTop.value, rectangle.destRight.value, rectangle.destBottom.value, rectangle.width.value, rectangle.height.value, rectangle.bitsPerPixel.value, (rectangle.flags & pdu.BitmapFlag.BITMAP_COMPRESSION).value, rectangle.bitmapDataStream.value)
class Factory(protocol.Factory): class ClientFactory(protocol.Factory):
''' '''
Factory of Client RDP protocol Factory of Client RDP protocol
''' '''
@@ -52,9 +52,11 @@ class Factory(protocol.Factory):
Function call from twisted and build rdp protocol stack Function call from twisted and build rdp protocol stack
@param addr: destination address @param addr: destination address
''' '''
return tpkt.TPKT(tpdu.createClient(mcs.createClient(self.buildObserver().getController()))); controller = RDPController(LayerMode.CLIENT)
self.buildObserver(controller)
return tpkt.TPKT(tpdu.createClient(mcs.createClient(controller)));
def buildObserver(self): def buildObserver(self, controller):
''' '''
build observer use for connection build observer use for connection
''' '''
@@ -92,16 +94,13 @@ class RDPClientObserver(object):
''' '''
class use to inform all rdp event handle by RDPY class use to inform all rdp event handle by RDPY
''' '''
def __init__(self): def __init__(self, controller):
self._controller = RDPController(LayerMode.CLIENT) """
@param controller: RDP controller use to interact with protocol
"""
self._controller = controller
self._controller.addClientObserver(self) self._controller.addClientObserver(self)
def getController(self):
"""
@return: RDP controller use by observer
"""
return self._controller
def onBitmapUpdate(self, destLeft, destTop, destRight, destBottom, width, height, bitsPerPixel, isCompress, data): def onBitmapUpdate(self, destLeft, destTop, destRight, destBottom, width, height, bitsPerPixel, isCompress, data):
''' '''
notify bitmap update notify bitmap update

View File

@@ -529,9 +529,11 @@ class Factory(protocol.Factory):
Function call by twisted on connection Function call by twisted on connection
@param addr: address where client try to connect @param addr: address where client try to connect
""" """
return self.buildObserver().getController().getRFBLayer() controller = RFBController(LayerMode.CLIENT)
self.buildObserver(controller)
return controller.getRFBLayer()
def buildObserver(self): def buildObserver(self, controller):
""" """
Build an RFB observer object Build an RFB observer object
""" """
@@ -542,8 +544,8 @@ class RFBClientObserver(object):
""" """
RFB client protocol observer RFB client protocol observer
""" """
def __init__(self): def __init__(self, controller):
self._controller = RFBController(LayerMode.CLIENT) self._controller = controller
self._controller.addClientObserver(self) self._controller.addClientObserver(self)
def getController(self): def getController(self):