def sendPong(self): self.m_pingReceived = True wrap = protocol_pb2.WrapperMessage() wrap.type = protocol_pb2.WrapperMessage.TYPE_PONG message = wrap.SerializeToString() self.send(message) self.sendMemoryUsage()
def WRAP(MESSAGE, TYPE): wrap = protocol_pb2.WrapperMessage() wrap.type = TYPE wrap.payload = MESSAGE return wrap.SerializeToString()
def handleDataRead(self, data): self.m_data += data while len(self.m_data) != 0: expected_size = 0 if (len(self.m_data) >= 4): expected_size = struct.unpack('!I', self.m_data[0:4])[0] if (len(self.m_data) - 4 < expected_size): return else: return wrapper = protocol_pb2.WrapperMessage() if (wrapper.ParseFromString(self.m_data[4:]) == False): self.m_data = self.m_data[expected_size + 4:] return self.m_data = self.m_data[4 + expected_size:] if wrapper.type == protocol_pb2.WrapperMessage.TYPE_LOGIN: self.handleLoginPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_LOGOUT: self.handleLogoutPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_PING: self.sendPong() elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_CONV_MESSAGE: self.handleConvMessagePayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_JOIN_ROOM: self.handleJoinRoomPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_LEAVE_ROOM: self.handleLeaveRoomPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_VCARD: self.handleVCardPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDY_CHANGED: self.handleBuddyChangedPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDY_REMOVED: self.handleBuddyRemovedPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_STATUS_CHANGED: self.handleStatusChangedPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDY_TYPING: self.handleChatStatePayload( wrapper.payload, protocol_pb2.WrapperMessage.TYPE_BUDDY_TYPING) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDY_TYPED: self.handleChatStatePayload( wrapper.payload, protocol_pb2.WrapperMessage.TYPE_BUDDY_TYPED) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDY_STOPPED_TYPING: self.handleChatStatePayload( wrapper.payload, protocol_pb2.WrapperMessage.TYPE_BUDDY_STOPPED_TYPING) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_ATTENTION: self.handleAttentionPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_FT_START: self.handleFTStartPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_FT_FINISH: self.handleFTFinishPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_FT_PAUSE: self.handleFTPausePayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_FT_CONTINUE: self.handleFTContinuePayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_EXIT: self.handleExitRequest() elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_RAW_XML: self.handleRawXmlRequest(wrapper.payload)
def handleDataRead(self, data): self.m_data += data while len(self.m_data) != 0: expected_size = 0 if (len(self.m_data) >= 4): expected_size = struct.unpack('!I', self.m_data[0:4])[0] if (len(self.m_data) - 4 < expected_size): self.logger.debug("Data packet incomplete") return else: self.logger.debug("Data packet incomplete") return packet = self.m_data[4:4 + expected_size] wrapper = protocol_pb2.WrapperMessage() try: parseFromString = wrapper.ParseFromString(packet) except: self.m_data = self.m_data[expected_size + 4:] self.logger.error( "Parse from String exception. Skipping packet.") return if parseFromString == False: self.m_data = self.m_data[expected_size + 4:] self.logger.error("Parse from String failed. Skipping packet.") return self.m_data = self.m_data[4 + expected_size:] if wrapper.type == protocol_pb2.WrapperMessage.TYPE_LOGIN: self.handleLoginPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_LOGOUT: self.handleLogoutPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_PING: self.sendPong() elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_CONV_MESSAGE: self.handleConvMessagePayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_JOIN_ROOM: self.handleJoinRoomPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_LEAVE_ROOM: self.handleLeaveRoomPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_VCARD: self.handleVCardPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDY_CHANGED: self.handleBuddyChangedPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDY_REMOVED: self.handleBuddyRemovedPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_STATUS_CHANGED: self.handleStatusChangedPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDY_TYPING: self.handleChatStatePayload( wrapper.payload, protocol_pb2.WrapperMessage.TYPE_BUDDY_TYPING) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDY_TYPED: self.handleChatStatePayload( wrapper.payload, protocol_pb2.WrapperMessage.TYPE_BUDDY_TYPED) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDY_STOPPED_TYPING: self.handleChatStatePayload( wrapper.payload, protocol_pb2.WrapperMessage.TYPE_BUDDY_STOPPED_TYPING) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_ATTENTION: self.handleAttentionPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_FT_START: self.handleFTStartPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_FT_FINISH: self.handleFTFinishPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_FT_PAUSE: self.handleFTPausePayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_FT_CONTINUE: self.handleFTContinuePayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_EXIT: self.handleExitRequest() elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_CONV_MESSAGE_ACK: self.handleConvMessageAckPayload(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_RAW_XML: self.handleRawXmlRequest(wrapper.payload) elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDIES: self.handleBuddiesPayload(wrapper.payload)