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

View File

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

View File

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

View File

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

View File

@@ -43,7 +43,7 @@ class RDPController(object):
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)
class Factory(protocol.Factory):
class ClientFactory(protocol.Factory):
'''
Factory of Client RDP protocol
'''
@@ -52,9 +52,11 @@ class Factory(protocol.Factory):
Function call from twisted and build rdp protocol stack
@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
'''
@@ -92,16 +94,13 @@ class RDPClientObserver(object):
'''
class use to inform all rdp event handle by RDPY
'''
def __init__(self):
self._controller = RDPController(LayerMode.CLIENT)
def __init__(self, controller):
"""
@param controller: RDP controller use to interact with protocol
"""
self._controller = controller
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):
'''
notify bitmap update

View File

@@ -529,9 +529,11 @@ class Factory(protocol.Factory):
Function call by twisted on connection
@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
"""
@@ -542,8 +544,8 @@ class RFBClientObserver(object):
"""
RFB client protocol observer
"""
def __init__(self):
self._controller = RFBController(LayerMode.CLIENT)
def __init__(self, controller):
self._controller = controller
self._controller.addClientObserver(self)
def getController(self):