Example #1
0
    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
Example #2
0
 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)
Example #3
0
    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)
Example #4
0
 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)
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
 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)
Example #8
0
    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)
Example #9
0
 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)
Example #10
0
    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)
Example #11
0
    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)
Example #12
0
 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
Example #13
0
    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)
Example #14
0
    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)
Example #15
0
    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)
Example #16
0
    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)
Example #17
0
    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)
Example #18
0
    def sendSubscribe(self, to):
        presenceNode = ProtocolTreeNode('presence', {
            'type': 'subscribe',
            'to': to
        })

        self.out.write(presenceNode)
Example #19
0
 def sendPong(self, idx):
     iqNode = ProtocolTreeNode('iq', {
         'type': 'result',
         'to': self.domain,
         'id': idx
     })
     self.out.write(iqNode)
Example #20
0
 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
Example #21
0
    def sendSubscribe(self, to):
        presenceNode = ProtocolTreeNode("presence", {
            "type": "subscribe",
            "to": to
        })

        self.out.write(presenceNode)
Example #22
0
 def sendAuth(self):
     node = ProtocolTreeNode(
         "auth", {
             "xmlns": "urn:ietf:params:xml:ns:xmpp-sasl",
             "mechanism": "DIGEST-MD5-1"
         })
     self.out.write(node)
Example #23
0
    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
Example #24
0
 def sendPong(self, idx):
     iqNode = ProtocolTreeNode("iq", {
         "type": "result",
         "to": self.domain,
         "id": idx
     })
     self.out.write(iqNode)
Example #25
0
    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)
Example #26
0
    def getSubjectMessage(self, to, msg_id, child):
        messageNode = ProtocolTreeNode("message", {
            "to": to,
            "type": "subject",
            "id": msg_id
        }, [child])

        return messageNode
Example #27
0
    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)
Example #28
0
    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)
Example #29
0
    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 = []
Example #30
0
 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 = []