def getMessageNode(self, fmsg, child): requestNode = None serverNode = ProtocolTreeNode("server", None) xNode = ProtocolTreeNode("x", {"xmlns": "jabber:x:event"}, [serverNode]) childCount = (0 if requestNode is None else 1) + 2 messageChildren = [None] * childCount i = 0 if requestNode is not None: messageChildren[i] = requestNode i += 1 #System.currentTimeMillis() / 1000L + "-"+1 messageChildren[i] = xNode i += 1 messageChildren[i] = child i += 1 key = eval(fmsg.key) messageNode = ProtocolTreeNode("message", { "to": key.remote_jid, "type": "chat", "id": key.id }, messageChildren) return messageNode
def sendPaused(self, jid): composing = ProtocolTreeNode( 'paused', {'xmlns': 'http://jabber.org/protocol/chatstates'}) message = ProtocolTreeNode('message', { 'to': jid, 'type': 'chat' }, [composing]) self.out.write(message)
def setGroupSubject(self, group, subject): node = ProtocolTreeNode('subject', {'xmlns': 'w:g', 'value': subject}) node_out = ProtocolTreeNode('iq', { 'id': str(int(time.time())) + '-0', 'type': 'set', 'to': group }, [node]) self.out.write(node_out)
def sendMessageReceived(self, fmsg): receivedNode = ProtocolTreeNode("received", {"xmlns": "urn:xmpp:receipts"}) messageNode = ProtocolTreeNode("message", { "to": fmsg.key.remote_jid, "type": "chat", "id": fmsg.key.id }, [receivedNode]) self.out.write(messageNode)
def sendGetGroups(self, group_type): node = ProtocolTreeNode('list', {'xmlns': 'w:g', 'type': group_type}) node_out = ProtocolTreeNode('iq', { 'id': str(int(time.time())) + '-0', 'type': 'get', 'to': 'g.us' }, [node]) self.out.write(node_out)
def getServerProperties(self): node = ProtocolTreeNode('list', {'xmlns': 'w:g', 'type': 'props'}) node_out = ProtocolTreeNode('iq', { 'id': str(int(time.time())) + '-0', 'type': 'get', 'to': 'g.us' }, [node]) self.out.write(node_out)
def sendPaused(self, jid): print "SEND PAUSED TO JID" composing = ProtocolTreeNode( "paused", {"xmlns": "http://jabber.org/protocol/chatstates"}) message = ProtocolTreeNode("message", { "to": jid, "type": "chat" }, [composing]) self.out.write(message)
def getParticipants(self, group): node = ProtocolTreeNode('list', {'xmlns': 'w:g'}) node_out = ProtocolTreeNode('iq', { 'id': str(int(time.time())) + '-0', 'type': 'get', 'to': group }, [node]) self.out.write(node_out)
def sendTyping(self, jid): print "SEND TYPING TO JID" composing = ProtocolTreeNode( "composing", {"xmlns": "http://jabber.org/protocol/chatstates"}) message = ProtocolTreeNode("message", { "to": jid, "type": "chat" }, [composing]) self.out.write(message)
def sendMessageReceived(self, fmsg): receivedNode = ProtocolTreeNode('received', {'xmlns': 'urn:xmpp:receipts'}) messageNode = ProtocolTreeNode('message', { 'to': fmsg.remote, 'type': 'chat', 'id': fmsg.id }, [receivedNode]) self.out.write(messageNode)
def leaveGroup(self, group): group_nodes = [ProtocolTreeNode('group', {'id': group})] node = ProtocolTreeNode('leave', {'xmlns': 'w:g'}, group_nodes) node_out = ProtocolTreeNode('iq', { 'id': str(int(time.time())) + '-0', 'type': 'set', 'to': 'g.us' }, [node]) self.out.write(node_out)
def getReceiptAck(self, to, msg_id, receiptType): ackNode = ProtocolTreeNode("ack", { "xmlns": "urn:xmpp:receipts", "type": receiptType }) messageNode = ProtocolTreeNode("message", { "to": to, "type": "chat", "id": msg_id }, [ackNode]) return messageNode
def sendPing(self): idx = self.makeId('ping_') self.stanzaReader.requests[idx] = \ self.stanzaReader.handlePingResponse pingNode = ProtocolTreeNode('ping', {'xmlns': 'w:p'}) iqNode = ProtocolTreeNode('iq', { 'id': idx, 'type': 'get', 'to': self.domain }, [pingNode]) self.out.write(iqNode)
def sendPing(self): idx = self.makeId("ping_") self.stanzaReader.requests[idx] = self.stanzaReader.handlePingResponse pingNode = ProtocolTreeNode("ping", {"xmlns": "w:p"}) iqNode = ProtocolTreeNode("iq", { "id": idx, "type": "get", "to": self.domain }, [pingNode]) self.out.write(iqNode)
def sendVerbParticipants(self, group, participants, verb): participant_nodes = map( lambda p: ProtocolTreeNode('participants', {'jid': p}), participants) node = ProtocolTreeNode(verb, {'xmlns': 'w:g'}, participant_nodes) node_out = ProtocolTreeNode('iq', { 'id': str(int(time.time())) + '-0', 'type': 'set', 'to': group }, [node]) self.out.write(node_out)
def sendIq(self): node = ProtocolTreeNode("iq", { "to": "g.us", "type": "get", "id": str(int(time.time())) + "-0" }, None, 'expired') self.out.write(node) node = ProtocolTreeNode( "iq", { "to": "s.whatsapp.net", "type": "set", "id": str(int(time.time())) + "-1" }, None, 'expired') self.out.write(node)
def sendIq(self): node = ProtocolTreeNode('iq', { 'to': 'g.us', 'type': 'get', 'id': str(int(time.time())) + '-0' }, None, 'expired') self.out.write(node) node = ProtocolTreeNode( 'iq', { 'to': 's.whatsapp.net', 'type': 'set', 'id': str(int(time.time())) + '-1' }, None, 'expired') self.out.write(node)
def sendSubscribe(self, to): presenceNode = ProtocolTreeNode('presence', { 'type': 'subscribe', 'to': to }) self.out.write(presenceNode)
def sendPong(self, idx): iqNode = ProtocolTreeNode('iq', { 'type': 'result', 'to': self.domain, 'id': idx }) self.out.write(iqNode)
def getReceiptAck( self, to, msg_id, receiptType, ): ackNode = ProtocolTreeNode('ack', { 'xmlns': 'urn:xmpp:receipts', 'type': receiptType }) messageNode = ProtocolTreeNode('message', { 'to': to, 'type': 'chat', 'id': msg_id }, [ackNode]) return messageNode
def sendSubscribe(self, to): presenceNode = ProtocolTreeNode("presence", { "type": "subscribe", "to": to }) self.out.write(presenceNode)
def sendAuth(self): node = ProtocolTreeNode( "auth", { "xmlns": "urn:ietf:params:xml:ns:xmpp-sasl", "mechanism": "DIGEST-MD5-1" }) self.out.write(node)
def sendMessageWithBody(self, fmsg): #bodyNode = ProtocolTreeNode("body",None,message.data); #self.out.write(self.getMessageNode(message,bodyNode)); bodyNode = ProtocolTreeNode("body", None, None, fmsg.content) self.out.write(self.getMessageNode(fmsg, bodyNode)) self.msg_id += 1
def sendPong(self, idx): iqNode = ProtocolTreeNode("iq", { "type": "result", "to": self.domain, "id": idx }) self.out.write(iqNode)
def sendClientConfig(self, sound, pushID, preview, platform): idx = self.makeId("config_") configNode = ProtocolTreeNode( "config", { "xmlns": "urn:xmpp:whatsapp:push", "sound": sound, "id": pushID, "preview": "1" if preview else "0", "platform": platform }) iqNode = ProtocolTreeNode("iq", { "id": idx, "type": "set", "to": self.domain }, [configNode]) self.out.write(iqNode)
def getSubjectMessage(self, to, msg_id, child): messageNode = ProtocolTreeNode("message", { "to": to, "type": "subject", "id": msg_id }, [child]) return messageNode
def getLastOnline(self, jid): if len(jid.split('-')) == 2: return self.sendSubscribe(jid) idx = self.makeId('last_') self.stanzaReader.requests[idx] = \ self.stanzaReader.handleLastOnline query = ProtocolTreeNode('query', {'xmlns': 'jabber:iq:last'}) iqNode = ProtocolTreeNode('iq', { 'id': idx, 'type': 'get', 'to': jid }, [query]) self.out.write(iqNode)
def getLastOnline(self, jid): if len(jid.split('-')) == 2: #SUPER CANCEL SUBSCRIBE TO GROUP return self.sendSubscribe(jid) print "presence request Initiated for %s" % (jid) idx = self.makeId("last_") self.stanzaReader.requests[idx] = self.stanzaReader.handleLastOnline query = ProtocolTreeNode("query", {"xmlns": "jabber:iq:last"}) iqNode = ProtocolTreeNode("iq", { "id": idx, "type": "get", "to": jid }, [query]) self.out.write(iqNode)
def sendResponse(self, challengeData): response = self.getResponse(challengeData) node = ProtocolTreeNode('response', {'xmlns': 'urn:ietf:params:xml:ns:xmpp-sasl' }, None, str(base64.b64encode(response))) self.out.write(node) self.inn.inn.buf = []
def sendResponse(self, challengeData): #self.out.out.write(0); #HACK #self.out.out.write(255); #HACK response = self.getResponse(challengeData) node = ProtocolTreeNode("response", {"xmlns": "urn:ietf:params:xml:ns:xmpp-sasl"}, None, str(base64.b64encode(response))) #print "THE NODE::"; #print node.toString(); #exit(); self.out.write(node) #clear buf self.inn.inn.buf = []