diff --git a/rdpy/protocol/common/layer.py b/rdpy/protocol/common/layer.py index a6a09ca..4085184 100644 --- a/rdpy/protocol/common/layer.py +++ b/rdpy/protocol/common/layer.py @@ -27,14 +27,14 @@ class Layer(object): if not self._presentation is None: self._presentation.connect() - def read(self, data): + def recv(self, data): ''' signal that data is available for this layer call by transport layer default is to pass data to presentation layer ''' if not self._presentation is None: - self._presentation.read(data) + self._presentation.recv(data) def write(self, data): ''' @@ -42,4 +42,5 @@ class Layer(object): write data for this layer default pass data to transport layer ''' - self.transport.write(data) \ No newline at end of file + if not self._transport is None: + self._transport.write(data) \ No newline at end of file diff --git a/rdpy/protocol/common/protocolbuffer.py b/rdpy/protocol/common/protocolbuffer.py index 6d27946..129ee4b 100644 --- a/rdpy/protocol/common/protocolbuffer.py +++ b/rdpy/protocol/common/protocolbuffer.py @@ -35,20 +35,21 @@ class ProtocolBuffer(protocol.Protocol): #rest is for next event of automata self._buffer = self._buffer[self._expectedLen:] #call recv function - self.recv(expectedData) + self.recvExpectedData(expectedData) def expect(self, expectedLen, callback = None): ''' - newt expected len + new expected len ''' self._expectedLen = expectedLen + #default callback is recvExpectedData if callback is None: - callback = self.__class__.recv + callback = self.__class__.recvExpectedData - self.recv = callback + self.recvExpectedData = callback - def recv(self, data): + def recvExpectedData(self, data): ''' call when expected data is receive ''' diff --git a/rdpy/protocol/rdp/tpkt.py b/rdpy/protocol/rdp/tpkt.py index 7d72fb9..a7992cb 100644 --- a/rdpy/protocol/rdp/tpkt.py +++ b/rdpy/protocol/rdp/tpkt.py @@ -1,15 +1,15 @@ ''' -Created on 5 sept. 2013 - @author: sylvain ''' - from rdpy.protocol.common.protocolbuffer import ProtocolBuffer from rdpy.protocol.common.layer import Layer from rdpy.protocol.common.stream import Stream + class TPKT(ProtocolBuffer, Layer): ''' - classdocs + TPKT layer in RDP protocol stack + this layer only handle size of packet + and determine if is a fast path packet ''' def __init__(self, presentation = None): ''' @@ -25,39 +25,62 @@ class TPKT(ProtocolBuffer, Layer): def connectionMade(self): ''' call when transport layer connection - is made + is made (inherit from ProtocolBuffer) ''' + #header is on two bytes self.expect(2, self.readHeader) + #no connection automata on this layer self.connect() def readHeader(self, data): + ''' + read header of TPKT packet + ''' #first read packet version self._lastPacketVersion = data.read_uint8() - + #classic packet if self._lastPacketVersion == 3: data.read_uint8() + #read end header self.expect(2, self.readExtendedHeader) else: + #is fast path packet self._lastShortLength = data.read_uint8() if self._lastShortLength & 0x80: + #size is 1 byte more self.expect(1, self.readExtendedFastPathHeader) return self.expect(self._lastShortLength - 2, self.readFastPath) def readExtendedHeader(self, data): + ''' + header may be on 4 bytes + ''' + #next state is read data self.expect(data.read_beuint16() - 4, self.readData) def readExtendedFastPathHeader(self, data): + ''' + fast ath header may be on 1 byte more + ''' self._lastShortLength &= ~0x80 self._lastShortLength = (self._lastShortLength << 8) + data.read_uint8() + #next state is fast patn data self.expect(self._lastShortLength - 3, self.readFastPath) def readFastPath(self, data): + ''' + fast path data + ''' pass def readData(self, data): - self._protocol.dataReceived(data) + ''' + read classic TPKT packet + ''' + #next state is pass to + self.recv(data) self.expect(2, self.readHeader) def write(self, data): diff --git a/rdpy/vncclient.py b/rdpy/vncclient.py index 4e8bc25..b1d9151 100644 --- a/rdpy/vncclient.py +++ b/rdpy/vncclient.py @@ -19,7 +19,7 @@ if __name__ == '__main__': protocol = rfb.Rfb(rfb.Rfb.CLIENT) w = widget.QRemoteDesktop(adaptor.RfbAdaptor(protocol)) w.resize(1000, 700) - w.setWindowTitle('QVNCViewer') + w.setWindowTitle('vncclient') w.show() from twisted.internet import reactor reactor.connectTCP("127.0.0.1", 5901, factory.RfbFactory(protocol))