コード例 #1
0
    def dump_description(self, dest):
        def sent(res):
            self.log.debug('description sent')
            pass

        self.log.debug('send description')
        #         print(dest['id'])
        if self.description:
            self.log.debug('cached description')
            iq = IQ(self.xmlstream, 'result')
            iq.addRawXml(self.description)
            iq['id'] = dest['id']
        else:
            self.log.debug('generate description')
            iq = IQ(self.xmlstream, 'result')
            query = domish.Element(('urn:schemas-upnp-org:cloud-1-0', 'query'))
            query['type'] = 'described'
            query['name'] = self.device.uuid
            d = tostring(self.device.dump(), encoding='unicode')
            query.addRawXml(d)
            #         print(query.toXml())
            for service in self.device.services:
                s = tostring(service.dump(), encoding='unicode')
                #             print(s)
                query.addRawXml(s)

    #         print(query.toXml())
            self.description = query.toXml()
            iq.addChild(query)
            iq['id'] = dest['id']
#             self.description = iq
#         print(iq.toXml())
        iq.addCallback(sent)
        iq.send(to=dest['from'])
コード例 #2
0
    def on_presence(self, presence):
        print('received presence: %s' % presence.toXml().encode('utf-8'))
        user, host, res = parse(presence['from'])
        jid = '@'.join((user, host))
        if presence.hasAttribute('type'):
            if presence['type'] == 'subscribe':
                if jid in self.users:
                    print('received subscription')
                    if self.users[jid] is False:
                        iq = IQ(self.xmlstream, 'set')
                        query = domish.Element(('jabber:iq:roster', 'query'))
                        item = domish.Element((None, 'item'))
                        item['jid'] = jid
                        item['name'] = jid
                        item.addElement('group', content='controllers')
                        query.addChild(item)
                        iq.addChild(query)
                        iq.addCallback(self.subscribed, jid)
                        self.xmlstream.send(iq)
                        pres = domish.Element((None, 'presence'))
                        pres['type'] = 'subscribed'
                        pres['to'] = jid
                        self.xmlstream.send(pres)

                else:
                    presence = domish.Element((None, 'presence'))
                    presence['type'] = 'unsubscribed'
                    presence['to'] = presence['from']
                    self.xmlstream.send(presence)
コード例 #3
0
def test(q, bus, conn, stream):
    # This sidecar sends a stanza, and waits for a reply, before being
    # created.
    pattern = EventPattern('stream-iq', to='sidecar.example.com',
        query_ns='http://example.com/sidecar')
    call_async(q, conn.Sidecars1, 'EnsureSidecar', TEST_PLUGIN_IFACE + ".IQ")
    e = q.expect_many(pattern)[0]

    # The server said yes, so we should get a sidecar back!
    acknowledge_iq(stream, e.stanza)
    q.expect('dbus-return', method='EnsureSidecar')

    identities = ["test/app-list//Test"]
    features = ["com.example.test1", "com.example.test2"]
    ver = compute_caps_hash(identities, features, {})

    iq = IQ(stream, "get")
    query = iq.addElement((ns.DISCO_INFO, 'query'))
    query['node'] = ns.GABBLE_CAPS + '#' + ver
    stream.send(iq)
    e = q.expect('stream-iq', query_ns='http://jabber.org/protocol/disco#info')

    returned_features = [feature['var']
        for feature in xpath.queryForNodes('/iq/query/feature', e.stanza)]
    assertEquals(features, returned_features)

    returned_identities = [identity['category'] + "/" + identity['type']+"//" + identity['name']
        for identity in xpath.queryForNodes('/iq/query/identity', e.stanza)]
    assertEquals(identities, returned_identities)

    new_ver = compute_caps_hash(returned_identities, returned_features, {})
    assertEquals(new_ver, ver)
コード例 #4
0
ファイル: stats.py プロジェクト: mend0za/jabber.org.by
    def getStats(self, jid = "icq.netlab.cz"):
        iq = IQ(self.xmlstream, "get")
        iq['to'] = jid
        iq.addElement(("http://jabber.org/protocol/stats", "query"))

        iq.addCallback(self._statsReceived)
        iq.send()
コード例 #5
0
 def on_description(self, iq):
     #         print(
     #             'Received description from %s: %s'
     #             % (iq['from'], iq.toXml().encode('utf-8')))
     pause = IQ(self.xmlstream, 'set')
     pause['to'] = iq['from']
     #         enveloppe = domish.Element(
     #             ('http://schemas.xmlsoap.org/soap/envelope/', 'Envelope'))
     enveloppe = domish.Element(
         ('http://schemas.xmlsoap.org/soap/envelope/', 'Envelope'),
         localPrefixes={'s': 'http://schemas.xmlsoap.org/soap/envelope/'})
     enveloppe[
         's:encodingStyle'] = "http://schemas.xmlsoap.org/soap/encoding/"
     header = domish.Element((None, 's:Header'))
     #         header = domish.Element(('http://schemas.xmlsoap.org/soap/envelope/', 'Header'))
     header['mustUnderstand'] = "1"
     uc = domish.Element(('urn:schemas-upnp-org:cloud-1-0', 'uc'))
     uc['serviceId'] = 'urn:av-openhome-org:serviceId:Playlist'
     header.addChild(uc)
     enveloppe.addChild(header)
     body = domish.Element((None, 's:Body'))
     #         body = domish.Element(('http://schemas.xmlsoap.org/soap/envelope/', 'Body'))
     action = domish.Element(
         ('urn:av-openhome-org:service:Playlist:1', 'Read'),
         localPrefixes={'u': 'urn:av-openhome-org:service:Playlist:1'})
     #         action = domish.Element(
     #             ('urn:av-openhome-org:service:Playlist:1', 'Pause'))
     body.addChild(action)
     enveloppe.addChild(body)
     pause.addChild(enveloppe)
     pause.addCallback(self.paused)
     print('send pause')
     print(pause.toXml())
     pause.send()
コード例 #6
0
def sync_stream(q, xmpp_connection):
    """Used to ensure that Salut has processed all stanzas sent to it on this
       xmpp_connection."""

    iq = IQ(None, "get")
    iq.addElement(('http://jabber.org/protocol/disco#info', 'query'))
    xmpp_connection.send(iq)
    q.expect('stream-iq', query_ns='http://jabber.org/protocol/disco#info')
コード例 #7
0
 def respond_rpc(self, resp, to, queryID):
     #         print('send: %s' % resp)
     #         self.log.debug('respond rpc: %s' % resp[0][39:])
     res = IQ(self.xmlstream, 'result')
     res['id'] = queryID
     if resp:
         for item in resp:
             res.addRawXml(item[39:].decode('utf-8'))  # Skip the xml header
     res.send(to=to)
コード例 #8
0
def make_result_iq(iq):
    result = IQ(None, "result")
    result["id"] = iq["id"]
    query = iq.firstChildElement()

    if query:
        result.addElement((query.uri, query.name))

    return result
コード例 #9
0
def send_roster_push(stream, jid, groups):
    iq = IQ(stream, 'set')
    query = iq.addElement((ns.ROSTER, 'query'))
    item = query.addElement('item')
    item['jid'] = jid
    item['subscription'] = 'both'
    for group in groups:
        item.addElement('group', content=group)
    stream.send(iq)
コード例 #10
0
 def send_not_found(self, id):
     iq = IQ(self.stream, 'error')
     iq['to'] = self.initiator
     iq['from'] = self.target
     iq['id'] = id
     error = iq.addElement(('', 'error'))
     error['type'] = 'cancel'
     error['code'] = '404'
     self.stream.send(iq)
コード例 #11
0
 def _send_socks5_reply(self, id, stream_used):
     result = IQ(self.stream, 'result')
     result['id'] = id
     result['from'] = self.target
     result['to'] = self.initiator
     query = result.addElement((ns.BYTESTREAMS, 'query'))
     streamhost_used = query.addElement((None, 'streamhost-used'))
     streamhost_used['jid'] = stream_used
     result.send()
コード例 #12
0
 def _cb_bare_jid_disco_iq(self, iq):
     # Additionally, Prosody 0.6.1 doesn't like us discoing our own bare
     # JID, and responds with an error which doesn't have the 'from'
     # attribute. Wocky used to discard this, but now tolerates it.
     result = IQ(self, 'error')
     result['id'] = iq['id']
     error = result.addElement((None, 'error'))
     error['type'] = 'cancel'
     error.addElement((ns.STANZA, 'service-unavailable'))
     self.send(result)
コード例 #13
0
def sync_stream(q, stream):
    """Used to ensure that Gabble has processed all stanzas sent to it."""

    iq = IQ(stream, "get")
    id = iq['id']
    iq.addElement(('http://jabber.org/protocol/disco#info', 'query'))
    stream.send(iq)
    q.expect('stream-iq', query_ns='http://jabber.org/protocol/disco#info',
        predicate=(lambda event:
            event.stanza['id'] == id and event.iq_type == 'result'))
コード例 #14
0
 def respondToInitialIq(self, iq):
     result = IQ(self.xmlstream, "result")
     result["id"] = iq["id"]
     query = result.addElement('query')
     query["xmlns"] = "jabber:iq:auth"
     query.addElement('username', content='test')
     query.addElement('password')
     query.addElement('digest')
     query.addElement('resource')
     self.xmlstream.send(result)
コード例 #15
0
def repeat_previous_vcard(stream, iq, previous):
    result = IQ(stream, 'result')
    result['id'] = iq['id']
    to = iq.getAttribute('to')

    if to is not None:
        result["from"] = to

    result.addRawXml(previous.firstChildElement().toXml())
    stream.send(result)
コード例 #16
0
def make_result_iq(stream, iq, add_query_node=True):
    result = IQ(stream, "result")
    result["id"] = iq["id"]
    to = iq.getAttribute('to')
    if to is not None:
        result["from"] = to
    query = iq.firstChildElement()

    if query and add_query_node:
        result.addElement((query.uri, query.name))

    return result
コード例 #17
0
ファイル: stats.py プロジェクト: mend0za/jabber.org.by
    def _statsReceived(self, el):

        iq = IQ(self.xmlstream, "get")
        iq['to'] = el['from']
        q = iq.addElement(("http://jabber.org/protocol/stats", "query"))

        query = el.firstChildElement()
        for child in query.children:
            s = q.addElement('stat')
            s['name'] = child['name']

        iq.addCallback(self._statsDataReceived)
        iq.send()
コード例 #18
0
 def _send_socks5_init(self, port):
     iq = IQ(self.stream, 'set')
     iq['to'] = self.target
     iq['from'] = self.initiator
     query = iq.addElement((ns.BYTESTREAMS, 'query'))
     query['sid'] = self.stream_id
     query['mode'] = 'tcp'
     for jid, host in self.hosts:
         streamhost = query.addElement('streamhost')
         streamhost['jid'] = jid
         streamhost['host'] = host
         streamhost['port'] = str(port)
     self.stream.send(iq)
コード例 #19
0
    def delete_ps_node(self, node):
        def deleted(res):
            if res['type'] == 'error':
                self.log.error('node deletion failed: %s' % res.toXml())

        iq = IQ(self.xmlstream, 'set')
        ps = domish.Element(
            ('http://jabber.org/protocol/pubsub#owner', 'pubsub'))
        delete = domish.Element((None, 'delete'))
        delete['node'] = node
        ps.addChild(delete)
        iq.addChild(ps)
        iq.send(to='pubsub.' + self.jid.host)
コード例 #20
0
 def check_users(self):
     for user, value in self.users.items():
         if value['state'] is False:
             iq = IQ(self.xmlstream, 'set')
             query = domish.Element(('jabber:iq:roster', 'query'))
             item = domish.Element((None, 'item'))
             item['name'] = user
             item['jid'] = user
             item.addElement('group', content='hosts')
             query.addChild(item)
             iq.addChild(query)
             iq.addCallback(self.subscribe, user)
             print('send IQ: %s' % (iq.toXml().encode('utf-8')))
             iq.send()
コード例 #21
0
    def authenticated(self, xs):

        self.log.debug('Cloud Authenticated')
        presence = domish.Element((None, 'presence'))
        xs.send(presence)
        xs.addObserver('/presence', self.on_presence)
        xs.addObserver('/iq', self.on_iq)
        xs.addObserver('/message', self.on_event)
        disco = IQ(xs, 'get')
        disco.addElement(('http://jabber.org/protocol/disco#items', 'query'))
        disco.addCallback(self.cloud_discovered)
        disco.send()
#         self.reactor.callLater(120, xs.sendFooter)
        self.reactor.callLater(5, self.check_users)
コード例 #22
0
 def moderate(self, jn, jid_nick, ra, set_to, reason=None):
  if not reason:
   try: reason = self.bot.nick
   except: reason = 'freQ'
  packet = IQ(self.globalbot.wrapper.x, 'set')
  query = packet.addElement('query', 'http://jabber.org/protocol/muc#admin')
  i = query.addElement('item')
  i[jn] = jid_nick
  i[ra] = set_to
  i.addElement('reason').addContent(reason)
  d = Deferred()
  packet.addCallback(d.callback)
  #print packet.toXml()
  callFromThread(packet.send, self.jid)
  return d
コード例 #23
0
def send_error_reply(stream, iq, error_stanza=None):
    result = IQ(stream, "error")
    result["id"] = iq["id"]
    query = iq.firstChildElement()
    to = iq.getAttribute('to')
    if to is not None:
        result["from"] = to

    if query:
        result.addElement((query.uri, query.name))

    if error_stanza:
        result.addChild(error_stanza)

    stream.send(result)
コード例 #24
0
 def __call__(self, *args, **kwargs):
     d = defer.Deferred()
     self.ctx, = self.contexts
     self.get_out_object(self.ctx, args, kwargs)
     self.get_out_string(self.ctx)
     self.ctx.in_string = []
     action = IQ(self.url[0], 'set')
     for item in self.ctx.out_string:
         action.addRawXml(item)
     if action.callbacks:
         action.addCallback(self.on_response, d)
     else:
         print('wtf?')
     action.send(to=self.url[1])
     return d
コード例 #25
0
def test(q, bus, conn, stream):
    amy_handle = conn.get_contact_handle_sync('*****@*****.**')

    # Divergence from Gabble: hazetest responds to all roster gets with an
    # empty roster, so we need to push the roster.
    iq = IQ(stream, 'set')
    query = iq.addElement(('jabber:iq:roster', 'query'))
    item = query.addElement('item')
    item['jid'] = '*****@*****.**'
    item['subscription'] = 'both'

    stream.send(iq)

    presence = domish.Element((None, 'presence'))
    presence['from'] = '*****@*****.**'
    show = presence.addElement((None, 'show'))
    show.addContent('away')
    status = presence.addElement((None, 'status'))
    status.addContent('At the pub')
    stream.send(presence)

    event = q.expect('dbus-signal', signal='PresencesChanged')
    assert event.args[0] == { amy_handle: (3, 'away', 'At the pub') }

    presence = domish.Element((None, 'presence'))
    presence['from'] = '*****@*****.**'
    show = presence.addElement((None, 'show'))
    show.addContent('chat')
    status = presence.addElement((None, 'status'))
    status.addContent('I may have been drinking')
    stream.send(presence)

    event = q.expect('dbus-signal', signal='PresencesChanged')
    # FIXME: 'chat' gets lost somewhere between the XMPP stream and what Haze
    # produces.
    assert event.args[0] == { amy_handle: (2, 'available', 'I may have been drinking') }

    amy_handle, asv = conn.Contacts.GetContactByID('*****@*****.**',
            [cs.CONN_IFACE_SIMPLE_PRESENCE])
    assertEquals(event.args[0][amy_handle], asv.get(cs.ATTR_PRESENCE))

    bob_handle, asv = conn.Contacts.GetContactByID('*****@*****.**',
            [cs.CONN_IFACE_SIMPLE_PRESENCE])
    assertEquals((cs.PRESENCE_UNKNOWN, 'unknown', ''),
            asv.get(cs.ATTR_PRESENCE))

    conn.Disconnect()
    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
コード例 #26
0
    def create_ps_node(self, node):
        def registered(node, iq):
            if iq['type'] == 'result':
                node_name = '/'.join((self._jid, node[1]))
                if node_name in self.registrations:
                    return
                event = XmppEvent(node_name, self, 'pubsub.' + self.jid.host)
                node[2].subscribe(event, 100)
                self.reactor.callLater(95, self.renew_subscription,
                                       *(node_name, node))
                self.registrations.append(node_name)
                self.log.debug('node {node} registered', node=node_name)
            else:
                self.log.error('node creation {name} failed:{iq}',
                               name=node,
                               iq=iq.toXml())

        iq = IQ(self.xmlstream, 'set')
        ps = domish.Element(('http://jabber.org/protocol/pubsub', 'pubsub'))
        create = domish.Element((None, 'create'))
        create['node'] = '/'.join((self._jid, node[1], node[0].name))
        ps.addChild(create)
        configure = domish.Element((None, 'configure'))
        x = domish.Element(('jabber:x:data', 'x'))
        x['type'] = 'submit'
        field = domish.Element((None, 'field'))
        field['var'] = 'FORM_TYPE'
        field['type'] = 'hidden'
        field.addElement(
            'value', content='http://jabber.org/protocol/pubsub#node_config')
        x.addChild(field)
        access = domish.Element((None, 'field'))
        access['var'] = 'pubsub#access_model'
        access.addElement('value', content='roster')
        x.addChild(access)
        #         expire = domish.Element((None, 'field'))
        #         expire['var'] = 'pubsub#item_expire'
        #         expire.addElement('value', content='60')
        #         x.addChild(expire)
        last = domish.Element((None, 'field'))
        last['var'] = 'pubsub#send_last_published_item'
        last.addElement('value', content='on_sub_and_presence')
        x.addChild(last)
        configure.addChild(x)
        ps.addChild(configure)
        iq.addChild(ps)
        iq.addCallback(registered, node)
        iq.send(to='pubsub.' + self.jid.host)
コード例 #27
0
    def bindIq(self, iq):
        resource = xpath.queryForString('/iq/bind/resource', iq)
        if self.resource is not None:
            assertEquals(self.resource, resource)
        else:
            assert resource is not None

        result = IQ(self.xmlstream, "result")
        result["id"] = iq["id"]
        bind = result.addElement((ns.NS_XMPP_BIND, 'bind'))
        self.bare_jid = '%s@%s' % (self.username, self.xmlstream.domain)
        self.full_jid = '%s/%s' % (self.bare_jid, resource)
        jid = bind.addElement('jid', content=self.full_jid)
        self.xmlstream.send(result)

        self.xmlstream.dispatch(self.xmlstream, xmlstream.STREAM_AUTHD_EVENT)
コード例 #28
0
def answer_error_to_pubsub_request(stream, request):
    # look for node's name in the request
    items = xpath.queryForNodes('/iq/pubsub/items', request)[0]
    node = items['node']

    reply = IQ(stream, "error")
    reply['id'] = request['id']
    reply['from'] = request['to']
    pubsub = reply.addElement((ns.PUBSUB, 'pubsub'))
    items = pubsub.addElement((None, 'items'))
    items['node'] = node
    error = reply.addElement((None, 'error'))
    error['type'] = 'auth'
    error.addElement((ns.STANZA, 'not-authorized'))
    error.addElement(
        ("%s#errors" % ns.PUBSUB, 'presence-subscription-required'))
    stream.send(reply)
コード例 #29
0
    def open_bytestream(self, expected_before=[], expected_after=[]):
        # open IBB bytestream
        iq = IQ(self.stream, 'set')
        iq['to'] = self.target
        iq['from'] = self.initiator
        open = iq.addElement((ns.IBB, 'open'))
        open['sid'] = self.stream_id
        # set a ridiculously small block size to stress test IBB buffering
        open['block-size'] = '1'

        assert self.checked

        events_before = self.q.expect_many(*expected_before)
        self.stream.send(iq)
        events_after = self.q.expect_many(*expected_after)

        return events_before, events_after
コード例 #30
0
 def on_presence(self, presence):
     self.log.debug('received presence: %s' %
                    presence.toXml().encode('utf-8'))
     if presence.hasAttribute('from'):
         user, host, res = parse(presence['from'])
         if presence['from'] in self.active_controllers:
             if presence.hasAttribute('type'):
                 if presence['type'] == 'unavailable':
                     self.active_controllers.remove(presence['from'])
                     self.log.info('User {_from} disconnected',
                                   _from=presence['from'])
                     return
         elif 'ControlPoint' in res:
             if presence.hasAttribute('type'):
                 if presence['type'] == 'unavailable':
                     return
             self.log.info('control point %s added' % presence['from'])
             if len(self.active_controllers) == 0:
                 self.check_ps_nodes()
             self.active_controllers.append(presence['from'])
         del (res)
         jid = '@'.join((user, host))
         if presence.hasAttribute('type'):
             if presence['type'] == 'subscribe':
                 if jid in self.users:
                     self.log.info('received subscription from %s' % jid)
                     if self.users[jid] is False:
                         iq = IQ(self.xmlstream, 'set')
                         query = domish.Element(
                             ('jabber:iq:roster', 'query'))
                         item = domish.Element((None, 'item'))
                         item['jid'] = jid
                         item['name'] = jid
                         item.addElement('group', content='UPnPCloud')
                         query.addChild(item)
                         iq.addChild(query)
                         iq.addCallback(self.subscribed, jid)
                         iq.send()
                 else:
                     self.log.error('subscription for user %s failed: %s' %
                                    (jid, 'Not in user list'))
                     pres = domish.Element((None, 'presence'))
                     pres['type'] = 'unsubscribed'
                     pres['to'] = presence['from']
                     self.xmlstream.send(pres)