def announce_socks5_proxy(q, stream, disco_stanza):
    reply = make_result_iq(stream, disco_stanza)
    query = xpath.queryForNodes('/iq/query', reply)[0]
    item = query.addElement((None, 'item'))
    item['jid'] = 'proxy.localhost'
    stream.send(reply)

    # wait for proxy disco#info query
    event = q.expect('stream-iq', to='proxy.localhost', query_ns=ns.DISCO_INFO,
        iq_type='get')

    reply = elem_iq(stream, 'result', from_='proxy.localhost', id=event.stanza['id'])(
        elem(ns.DISCO_INFO, 'query')(
            elem('identity', category='proxy', type='bytestreams', name='SOCKS5 Bytestreams')(),
            elem('feature', var=ns.BYTESTREAMS)()))
    stream.send(reply)

    # Gabble asks for SOCKS5 info
    event = q.expect('stream-iq', to='proxy.localhost', query_ns=ns.BYTESTREAMS,
        iq_type='get')

    port = listen_socks5(q)
    reply = elem_iq(stream, 'result', id=event.stanza['id'], from_='proxy.localhost')(
        elem(ns.BYTESTREAMS, 'query')(
            elem('streamhost', jid='proxy.localhost', host='127.0.0.1', port=str(port))()))
    stream.send(reply)
    def _send_status_list(self, iq_id=None):
        if iq_id is None:
            iq_id = str(int(time()))
            iq_type = "set"
        else:
            iq_type = "result"
        status, show, invisible = self.shared_status
        elems = []
        elems.append(elem('status')(unicode(status)))
        elems.append(elem('show')(unicode(show)))
        for show, statuses in self.shared_status_lists.items():
            lst = []
            for _status in statuses:
                lst.append(elem('status')(unicode(_status)))
            elems.append(elem('status-list', show=show)(*lst))
        elems.append(elem('invisible', value=invisible)())

        attribs = {'status-max' : self.max_status_message_length,
                   'status-list-max' : '3',
                   'status-list-contents-max' : self.max_statuses,
                   'status-min-ver' : self.min_version}

        iq = elem_iq(self, iq_type, id=iq_id)(
            elem(ns.GOOGLE_SHARED_STATUS, 'query', **attribs)(*elems))

        self.send(iq)
Example #3
0
    def _cb_presence_iq(self, stanza):
        nodes = xpath.queryForNodes("/presence/c", stanza)
        c = nodes[0]
        if 'share-v1' in c.getAttribute('ext'):
            assert FileTransferTest.caps_identities is not None and \
                FileTransferTest.caps_features is not None and \
                FileTransferTest.caps_dataforms is not None

            new_hash = compute_caps_hash(FileTransferTest.caps_identities,
                                         FileTransferTest.caps_features + \
                                             [ns.GOOGLE_FEAT_SHARE],
                                         FileTransferTest.caps_dataforms)
            # Replace ver hash from one with file-transfer ns to one without
            FileTransferTest.caps_ft = c.attributes['ver']
            c.attributes['ver'] = new_hash
        else:
            node = c.attributes['node']
            ver = c.attributes['ver']
            # ask for raw caps
            request = elem_iq(self.stream,
                              'get',
                              from_='[email protected]/resource')(elem(
                                  ns.DISCO_INFO,
                                  'query',
                                  node=(node + '#' + ver)))
            self.stream.send(request)
Example #4
0
def disco_caps(q, stream, presence):
    c_nodes = xpath.queryForNodes('/presence/c', presence.stanza)
    assert c_nodes is not None
    assertLength(1, c_nodes)
    hash = c_nodes[0].attributes['hash']
    ver = c_nodes[0].attributes['ver']
    node = c_nodes[0].attributes['node']
    assertEquals('sha-1', hash)

    # ask caps
    request = \
        elem_iq(stream, 'get', from_='[email protected]/resource')(
          elem(ns.DISCO_INFO, 'query', node=(node + '#' + ver))
        )
    stream.send(request)

    # receive caps
    event = q.expect('stream-iq', query_ns=ns.DISCO_INFO, iq_id=request['id'])

    # Check that Gabble's announcing the identity we think it should be.
    (identities, features, dataforms) = extract_disco_parts(event.stanza)

    # Check if the hash matches the announced capabilities
    assertEquals(compute_caps_hash(identities, features, dataforms), ver)

    return (event, features, dataforms)
Example #5
0
def send_unrecognised_get(q, stream):
    stream.send(
        elem_iq(stream, 'get')(
          elem('urn:unimaginative', 'dont-handle-me-bro')
        ))

    return q.expect('stream-iq', iq_type='error')
    def _send_status_list(self, iq_id=None):
        if iq_id is None:
            iq_id = str(int(time()))
            iq_type = "set"
        else:
            iq_type = "result"
        status, show, invisible = self.shared_status
        elems = []
        elems.append(elem('status')(status))
        elems.append(elem('show')(show))
        for show, statuses in self.shared_status_lists.items():
            lst = []
            for _status in statuses:
                lst.append(elem('status')(_status))
            elems.append(elem('status-list', show=show)(*lst))
        elems.append(elem('invisible', value=invisible)())

        attribs = {
            'status-max': self.max_status_message_length,
            'status-list-max': '3',
            'status-list-contents-max': self.max_statuses,
            'status-min-ver': self.min_version
        }

        iq = elem_iq(self, iq_type, id=iq_id)(elem(ns.GOOGLE_SHARED_STATUS,
                                                   'query', **attribs)(*elems))

        self.send(iq)
def disco_caps(q, stream, presence):
    c_nodes = xpath.queryForNodes('/presence/c', presence.stanza)
    assert c_nodes is not None
    assertLength(1, c_nodes)
    hash = c_nodes[0].attributes['hash']
    ver = c_nodes[0].attributes['ver']
    node = c_nodes[0].attributes['node']
    assertEquals('sha-1', hash)

    # ask caps
    request = \
        elem_iq(stream, 'get', from_='[email protected]/resource')(
          elem(ns.DISCO_INFO, 'query', node=(node + '#' + ver))
        )
    stream.send(request)

    # receive caps
    event = q.expect('stream-iq', query_ns=ns.DISCO_INFO, iq_id=request['id'])

    # Check that Gabble's announcing the identity we think it should be.
    (identities, features, dataforms) = extract_disco_parts(event.stanza)

    # Check if the hash matches the announced capabilities
    assertEquals(compute_caps_hash(identities, features, dataforms), ver)

    return (event, features, dataforms)
Example #8
0
def test(q, bus, conn, stream):
    jid = '*****@*****.**'

    iq = elem_iq(stream, 'get', from_=jid)(elem(ns.DISCO_INFO, 'query'))
    stream.send(iq)

    event = q.expect('stream-iq', iq_type='result', to='*****@*****.**')
    assertEquals(iq['id'], event.stanza['id'])
 def send_own_message(to, text):
     iq = elem_iq(stream, 'set', from_='chat.facebook.com')(
           elem(NS_FACEBOOK_MESSAGES, 'own-message', to=to, self='false')(
             elem('body')(text)
           )
         )
     stream.send(iq)
     q.expect('stream-iq', iq_type='result', iq_id=iq['id'])
 def send_privacy_list_push_iq(self, list_name):
     iq = elem_iq(self, 'set')(
         elem(ns.PRIVACY, 'query')(
             elem('list', name=list_name)
             )
         )
     self.send(iq)
     return iq["id"]
def test(q, bus, conn, stream):
    jid = '*****@*****.**'

    iq = elem_iq(stream, 'get', from_=jid)(elem(ns.DISCO_INFO, 'query'))
    stream.send(iq)

    event = q.expect('stream-iq', iq_type='result', to='*****@*****.**')
    assertEquals(iq['id'], event.stanza['id'])
    def _send(self, from_, to, data):
        id = random.randint(0, sys.maxint)

        iq = elem_iq(self.stream, 'set', from_=from_, to=to, id=str(id))(
            elem('data', xmlns=ns.IBB, sid=self.stream_id, seq=str(self.seq))(
                (unicode(base64.b64encode(data)))))

        self.stream.send(iq)
 def send_privacy_list(self, req_iq, list_items):
     req_list = xpath.queryForNodes('//list', req_iq)[0]
     iq = elem_iq(self, "result", id=req_iq["id"])(
         elem(ns.PRIVACY, 'query')(
             elem('list', name=req_list["name"])(*list_items)
             )
         )
     self.send(iq)
 def send_own_message(to, text):
     iq = elem_iq(stream, 'set',
                  from_='chat.facebook.com')(elem(NS_FACEBOOK_MESSAGES,
                                                  'own-message',
                                                  to=to,
                                                  self='false')(
                                                      elem('body')(text)))
     stream.send(iq)
     q.expect('stream-iq', iq_type='result', iq_id=iq['id'])
Example #15
0
    def _send(self, from_, to, data):
        id = random.randint(0, sys.maxsize)

        iq = elem_iq(self.stream, 'set', from_=from_, to=to,
                     id=str(id))(elem('data',
                                      xmlns=ns.IBB,
                                      sid=self.stream_id,
                                      seq=str(self.seq))(
                                          (base64.b64encode(data).decode())))

        self.stream.send(iq)
Example #16
0
def disco_bundle(q, bus, conn, stream, node, features):
    request = \
        elem_iq(stream, 'get', from_='[email protected]/resource')(
          elem(ns.DISCO_INFO, 'query', node=node)
        )
    stream.send(request)

    disco_response = q.expect('stream-iq', query_ns=ns.DISCO_INFO,
            iq_id=request['id'])
    nodes = xpath.queryForNodes('/iq/query/feature', disco_response.stanza)
    vars = [n["var"] for n in nodes]
    assertEquals(set(features), set(vars))
    def close(self):
        if self.initiated:
            from_ = self.initiator
            to = self.target
        else:
            from_ = self.target
            to = self.initiator

        iq = elem_iq(self.stream, 'set', from_=from_, to=to, id=str(id))(
            elem('close', xmlns=ns.IBB, sid=self.stream_id)())

        self.stream.send(iq)
Example #18
0
def announce_socks5_proxy(q, stream, disco_stanza):
    reply = make_result_iq(stream, disco_stanza)
    query = xpath.queryForNodes('/iq/query', reply)[0]
    item = query.addElement((None, 'item'))
    item['jid'] = 'proxy.localhost'
    stream.send(reply)

    # wait for proxy disco#info query
    event = q.expect('stream-iq',
                     to='proxy.localhost',
                     query_ns=ns.DISCO_INFO,
                     iq_type='get')

    reply = elem_iq(stream,
                    'result',
                    from_='proxy.localhost',
                    id=event.stanza['id'])(elem(ns.DISCO_INFO, 'query')(
                        elem('identity',
                             category='proxy',
                             type='bytestreams',
                             name='SOCKS5 Bytestreams')(),
                        elem('feature', var=ns.BYTESTREAMS)()))
    stream.send(reply)

    # Gabble asks for SOCKS5 info
    event = q.expect('stream-iq',
                     to='proxy.localhost',
                     query_ns=ns.BYTESTREAMS,
                     iq_type='get')

    port = listen_socks5(q)
    reply = elem_iq(stream,
                    'result',
                    id=event.stanza['id'],
                    from_='proxy.localhost')(elem(ns.BYTESTREAMS, 'query')(
                        elem('streamhost',
                             jid='proxy.localhost',
                             host='127.0.0.1',
                             port=str(port))()))
    stream.send(reply)
Example #19
0
def test(q, bus, conn, stream):
    e = q.expect('stream-iq', iq_type='get', query_ns=ns.ROSTER)
    e.stanza['type'] = 'result'
    e.query.addChild(
        elem('item', jid='*****@*****.**', subscription='both'))
    stream.send(e.stanza)

    # Romeo's on the roster.
    stream.send(
        elem_iq(stream, 'get', from_='*****@*****.**')(
          elem(ns.LAST, 'query')
        )
      )
    e = q.expect('stream-iq', iq_type='result',
        query_ns=ns.LAST, query_name='query')
    # No real assertions about the number of seconds; this is just a smoke
    # test.
    seconds = e.query['seconds']
    assert seconds >= 0

    # Juliet is not.
    stream.send(
        elem_iq(stream, 'get', from_='*****@*****.**')(
          elem(ns.LAST, 'query')
        )
      )
    e = q.expect('stream-iq', iq_type='error',
        query_ns=ns.LAST, query_name='query')
    # Yuck.
    assertEquals('forbidden', e.stanza.children[1].children[0].name)

    # If the server asks, Gabble had better not crash.
    stream.send(
        elem_iq(stream, 'get')(
          elem(ns.LAST, 'query')
        )
      )
    e = q.expect('stream-iq', iq_type='result',
        query_ns=ns.LAST, query_name='query')
Example #20
0
def test(q, bus, conn, stream):
    e = q.expect('stream-iq', iq_type='get', query_ns=ns.ROSTER)
    e.stanza['type'] = 'result'
    e.query.addChild(
        elem('item', jid='*****@*****.**', subscription='both'))
    stream.send(e.stanza)

    # Romeo's on the roster.
    stream.send(
        elem_iq(stream, 'get', from_='*****@*****.**')(
          elem(ns.LAST, 'query')
        )
      )
    e = q.expect('stream-iq', iq_type='result',
        query_ns=ns.LAST, query_name='query')
    # No real assertions about the number of seconds; this is just a smoke
    # test.
    seconds = int(e.query['seconds'])
    assert seconds >= 0

    # Juliet is not.
    stream.send(
        elem_iq(stream, 'get', from_='*****@*****.**')(
          elem(ns.LAST, 'query')
        )
      )
    e = q.expect('stream-iq', iq_type='error',
        query_ns=ns.LAST, query_name='query')
    # Yuck.
    assertEquals('forbidden', e.stanza.children[1].children[0].name)

    # If the server asks, Gabble had better not crash.
    stream.send(
        elem_iq(stream, 'get')(
          elem(ns.LAST, 'query')
        )
      )
    e = q.expect('stream-iq', iq_type='result',
        query_ns=ns.LAST, query_name='query')
def disco_bundle(q, bus, conn, stream, node, features):
    request = \
        elem_iq(stream, 'get', from_='[email protected]/resource')(
          elem(ns.DISCO_INFO, 'query', node=node)
        )
    stream.send(request)

    disco_response = q.expect('stream-iq',
                              query_ns=ns.DISCO_INFO,
                              iq_id=request['id'])
    nodes = xpath.queryForNodes('/iq/query/feature', disco_response.stanza)
    vars = [n["var"] for n in nodes]
    assertEquals(set(features), set(vars))
def send_socks5_reply(stream, iq, jid=None, host=None, port=None):
    if jid is None:
        jid = iq['to']
    if port is None:
        port = proxy_port[jid]
    if host is None:
        host = '127.0.0.1'

    reply = elem_iq(stream, 'result', id=iq['id'], from_=iq['to'])(
        elem(ns.BYTESTREAMS, 'query')(
            elem('streamhost', jid=jid, host=host, port=port)()))

    stream.send(reply)
Example #23
0
    def close(self):
        if self.initiated:
            from_ = self.initiator
            to = self.target
        else:
            from_ = self.target
            to = self.initiator

        iq = elem_iq(self.stream, 'set', from_=from_, to=to,
                     id=str(id))(elem('close',
                                      xmlns=ns.IBB,
                                      sid=self.stream_id)())

        self.stream.send(iq)
Example #24
0
def send_socks5_reply(stream, iq, jid=None, host=None, port=None):
    if jid is None:
        jid = iq['to']
    if port is None:
        port = proxy_port[jid]
    if host is None:
        host = '127.0.0.1'

    reply = elem_iq(stream, 'result', id=iq['id'],
                    from_=iq['to'])(elem(ns.BYTESTREAMS,
                                         'query')(elem('streamhost',
                                                       jid=jid,
                                                       host=host,
                                                       port=port)()))

    stream.send(reply)
Example #25
0
def announce_gadget(q, stream, disco_stanza):
    # announce Gadget service
    reply = make_result_iq(stream, disco_stanza)
    query = xpath.queryForNodes('/iq/query', reply)[0]
    item = query.addElement((None, 'item'))
    item['jid'] = 'gadget.localhost'
    stream.send(reply)

    # wait for Gadget disco#info query
    event = q.expect('stream-iq', to='gadget.localhost', query_ns=ns.DISCO_INFO)

    reply = elem_iq(stream, 'result', id=event.stanza['id'], from_='gadget.localhost')(
        elem(ns.DISCO_INFO, 'query')(
            elem('identity', category='collaboration', type='gadget', name='OLPC Gadget')(),
            elem('feature', var=ns.OLPC_BUDDY)(),
            elem('feature', var=ns.OLPC_ACTIVITY)()))

    stream.send(reply)
Example #26
0
def server_discovered(q, bus, conn, stream, server=None):
    iq_event, disco_event = q.expect_many(
        EventPattern('stream-iq',
                     to=None,
                     query_ns='vcard-temp',
                     query_name='vCard'),
        EventPattern('stream-iq', to='localhost', query_ns=ns.DISCO_ITEMS))

    acknowledge_iq(stream, iq_event.stanza)

    # no search server has been discovered yet. The CreateChannel operation
    # will be completed once the disco process is finished.
    call_create(q, conn, server=server)

    # reply to IQ query
    reply = make_result_iq(stream, disco_event.stanza)
    query = xpath.queryForNodes('/iq/query', reply)[0]
    item = query.addElement((None, 'item'))
    item['jid'] = JUD_SERVER
    stream.send(reply)

    # wait for the disco#info query
    event = q.expect('stream-iq', to=JUD_SERVER, query_ns=ns.DISCO_INFO)

    reply = elem_iq(stream, 'result', id=event.stanza['id'], from_=JUD_SERVER)(
        elem(ns.DISCO_INFO, 'query')(elem('identity',
                                          category='directory',
                                          type='user',
                                          name='vCard User Search')(),
                                     elem('feature', var=ns.SEARCH)()))

    stream.send(reply)

    # JUD_SERVER is used as default, and shows up as the Server property on the
    # resulting channel.
    ret, _ = answer_field_query(q, stream, JUD_SERVER)
    _, properties = ret.value
    assertEquals(JUD_SERVER, properties[cs.CONTACT_SEARCH_SERVER])

    # Now that the search server has been discovered, it is used right away.
    call_create(q, conn, server=server)
    ret, _ = answer_field_query(q, stream, JUD_SERVER)
    _, properties = ret.value
    assertEquals(JUD_SERVER, properties[cs.CONTACT_SEARCH_SERVER])
def server_discovered(q, bus, conn, stream, server=None):
    iq_event, disco_event = q.expect_many(
        EventPattern('stream-iq', to=None, query_ns='vcard-temp',
            query_name='vCard'),
        EventPattern('stream-iq', to='localhost', query_ns=ns.DISCO_ITEMS))

    acknowledge_iq(stream, iq_event.stanza)

    # no search server has been discovered yet. The CreateChannel operation
    # will be completed once the disco process is finished.
    call_create(q, conn, server=server)

    # reply to IQ query
    reply = make_result_iq(stream, disco_event.stanza)
    query = xpath.queryForNodes('/iq/query', reply)[0]
    item = query.addElement((None, 'item'))
    item['jid'] = JUD_SERVER
    stream.send(reply)

    # wait for the disco#info query
    event = q.expect('stream-iq', to=JUD_SERVER, query_ns=ns.DISCO_INFO)

    reply = elem_iq(stream, 'result', id=event.stanza['id'], from_=JUD_SERVER)(
        elem(ns.DISCO_INFO, 'query')(
            elem('identity', category='directory', type='user', name='vCard User Search')(),
            elem('feature', var=ns.SEARCH)()))

    stream.send(reply)

    # JUD_SERVER is used as default, and shows up as the Server property on the
    # resulting channel.
    ret, _ = answer_field_query(q, stream, JUD_SERVER)
    _, properties = ret.value
    assertEquals(JUD_SERVER, properties[cs.CONTACT_SEARCH_SERVER])

    # Now that the search server has been discovered, it is used right away.
    call_create(q, conn, server=server)
    ret, _ = answer_field_query(q, stream, JUD_SERVER)
    _, properties = ret.value
    assertEquals(JUD_SERVER, properties[cs.CONTACT_SEARCH_SERVER])
    def _cb_presence_iq(self, stanza):
        nodes = xpath.queryForNodes("/presence/c", stanza)
        c = nodes[0]
        if 'share-v1' in c.getAttribute('ext'):
            assert FileTransferTest.caps_identities is not None and \
                FileTransferTest.caps_features is not None

            new_hash = compute_caps_hash(FileTransferTest.caps_identities,
                                         FileTransferTest.caps_features + \
                                             [ns.GOOGLE_FEAT_SHARE],
                                         {})
            # Replace ver hash from one with file-transfer ns to one without
            FileTransferTest.caps_ft = c.attributes['ver']
            c.attributes['ver'] = new_hash
        else:
            node = c.attributes['node']
            ver = c.attributes['ver']
            # ask for raw caps
            request = elem_iq(self.stream, 'get',
                              from_='[email protected]/resource')(
                elem(ns.DISCO_INFO, 'query', node=(node + '#' + ver)))
            self.stream.send(request)
Example #29
0
def disco_caps(q, stream, presence):
    c_nodes = xpath.queryForNodes('/presence/c', presence.stanza)
    assert c_nodes is not None
    assertLength(1, c_nodes)
    hash = c_nodes[0].attributes['hash']
    ver = c_nodes[0].attributes['ver']
    node = c_nodes[0].attributes['node']
    assertEquals('sha-1', hash)

    # ask caps
    request = \
        elem_iq(stream, 'get', from_='[email protected]/resource')(
          elem(ns.DISCO_INFO, 'query', node=(node + '#' + ver))
        )
    stream.send(request)

    # receive caps
    event = q.expect('stream-iq', query_ns=ns.DISCO_INFO, iq_id=request['id'])

    # Check that Gabble's announcing the identity we think it should be.
    identity_nodes = xpath.queryForNodes('/iq/query/identity', event.stanza)
    assertLength(1, identity_nodes)
    identity_node = identity_nodes[0]

    assertEquals('client', identity_node['category'])
    assertEquals(config.CLIENT_TYPE, identity_node['type'])
    assertEquals(config.PACKAGE_STRING, identity_node['name'])
    assertDoesNotContain('xml:lang', identity_node.attributes)

    identity = 'client/%s//%s' % (config.CLIENT_TYPE, config.PACKAGE_STRING)

    features = []
    for feature in xpath.queryForNodes('/iq/query/feature', event.stanza):
        features.append(feature['var'])

    # Check if the hash matches the announced capabilities
    assertEquals(compute_caps_hash([identity], features, {}), ver)

    return (event, features)
Example #30
0
def test(q, bus, conn, stream):
    request = elem_iq(stream, 'get')(elem(ns.VERSION, 'query'))

    stream.send(request)
    reply = q.expect('stream-iq',
                     iq_id=request['id'],
                     query_ns=ns.VERSION,
                     query_name='query')

    # Both <name/> and <version/> are REQUIRED. What they actually contain is
    # someone else's problem™.
    names = xpath.queryForNodes('/query/name', reply.query)
    assertLength(1, names)

    versions = xpath.queryForNodes('/query/version', reply.query)
    assertLength(1, versions)

    # <os/> is OPTIONAL. “Revealing the application's underlying operating
    # system may open the user or system to attacks directed against that
    # operating system; therefore, an application MUST provide a way for a
    # human user or administrator to disable sharing of information about the
    # operating system.” The “way” that we provide is never to send it.
    oss = xpath.queryForNodes('/query/os', reply.query)
    assert oss is None
Example #31
0
def test(q, bus, conn, stream):
    request = elem_iq(stream, 'get')(
      elem(ns.VERSION, 'query')
    )

    stream.send(request)
    reply = q.expect('stream-iq', iq_id=request['id'],
        query_ns=ns.VERSION, query_name='query')

    # Both <name/> and <version/> are REQUIRED. What they actually contain is
    # someone else's problem™.
    names = xpath.queryForNodes('/query/name', reply.query)
    assertLength(1, names)

    versions = xpath.queryForNodes('/query/version', reply.query)
    assertLength(1, versions)

    # <os/> is OPTIONAL. “Revealing the application's underlying operating
    # system may open the user or system to attacks directed against that
    # operating system; therefore, an application MUST provide a way for a
    # human user or administrator to disable sharing of information about the
    # operating system.” The “way” that we provide is never to send it.
    oss = xpath.queryForNodes('/query/os', reply.query)
    assert oss is None
 def shared_status_iq_cb(self, req_iq):
     if req_iq.getAttribute("type") == 'get':
         self._send_status_list(req_iq['id'])
     if req_iq.getAttribute("type") == 'set':
         self._store_shared_statuses(req_iq)
         self.send(elem_iq(self, "result", id=req_iq['id'])())
def test(q, bus, conn, stream):
    peer = '[email protected]/gmail.7E1F07D0'
    self = 'test@localhost/test'
    jp = JingleProtocol031()
    jt = GMail(jp, conn, q, stream, 'test@localhost', peer)
    jt.prepare(send_roster=False)

    sid = 'c1025763497'
    si = elem_iq(stream, 'set', from_=peer, to=self)(
      elem(ns.JINGLE, 'jingle', action='session-initiate', sid=sid, initiator=peer)(
        elem('content', name='video')(
          elem(ns.JINGLE_RTP, 'description', media='video')(
            elem('payload-type', id='99', name='H264-SVC')(
              elem('parameter', name='width', value='320'),
              elem('parameter', name='height', value='200'),
              elem('parameter', name='framerate', value='30'),
            ),
            # ... other codecs elided ...
            elem('encryption'),
          ),
          elem(ns.GOOGLE_P2P, 'transport'),
        ),
        elem('content', name='audio')(
          elem(ns.JINGLE_RTP, 'description', media='audio')(
            elem('payload-type', id='103', name='ISAC', clockrate='16000')(
              elem('parameter', name='bitrate', value='32000'),
            ),
            # ... other codecs elided ...
            elem('encryption'),
          ),
          elem(ns.GOOGLE_P2P, 'transport'),
        )
      ),
      elem(ns.GOOGLE_SESSION, 'session', action='initiate', sid='c1025763497', initiator=peer)(
        elem(ns.GOOGLE_SESSION_VIDEO, 'description')(
          elem('payload-type', id='99', name='H264-SVC', width='320', height='200', framerate='30'),
          # ... other codecs elided ...
          elem(ns.JINGLE_RTP, 'encryption')(
            elem(ns.GOOGLE_SESSION_VIDEO, 'usage'),
          ),
          elem(ns.GOOGLE_SESSION_PHONE, 'payload-type', id='103', name='ISAC', bitrate='32000', clockrate='16000'),
          # ... other codecs elided ...
          elem(ns.JINGLE_RTP, 'encryption')(
            elem(ns.GOOGLE_SESSION_PHONE, 'usage'),
          ),
        ),
      ),
    )
    stream.send(si)

    nc, nsh = q.expect_many(
        EventPattern('dbus-signal', signal='NewChannels'),
        EventPattern('dbus-signal', signal='NewSessionHandler'),
        )

    path, properties = nc.args[0][0]

    # It's an audio+video call
    assert properties[cs.INITIAL_AUDIO]
    assert properties[cs.INITIAL_VIDEO]
    # Google can't add and remove streams on the fly. We special-case GMail.
    assert properties[cs.IMMUTABLE_STREAMS]

    chan = wrap_channel(bus.get_object(conn.bus_name, path), 'StreamedMedia')
    session_handler = make_channel_proxy(conn, nsh.args[0], 'Media.SessionHandler')
    session_handler.Ready()

    path, _, _, _ = q.expect('dbus-signal', signal='NewStreamHandler').args
    stream1 = make_channel_proxy(conn, path, 'Media.StreamHandler')
    path, _, _, _ = q.expect('dbus-signal', signal='NewStreamHandler').args
    stream2 = make_channel_proxy(conn, path, 'Media.StreamHandler')

    stream1.Ready([])
    stream2.Ready([])

    # Audio rtcp
    stream.send(
      elem_iq(stream, from_=peer, to=self, type='set')(
        elem(ns.JINGLE, 'jingle', action='transport-info', sid=sid)(
          elem('content', name='audio')(
            elem(ns.GOOGLE_P2P, 'transport')(
              elem('candidate', address='172.22.64.192', port='54335',
                   name='rtcp', username='******',
                   password='******', preference='1', protocol='udp',
                   generation='0', network='1', type='local')
            )
          )
        )
      )
    )
    q.expect('dbus-signal', signal='AddRemoteCandidate', path=stream1.object_path)

    # audio rtp
    stream.send(
      elem_iq(stream, from_=peer, to=self, type='set')(
        elem(ns.JINGLE, 'jingle', action='transport-info', sid=sid)(
          elem('content', name='audio')(
            elem(ns.GOOGLE_P2P, 'transport')(
              elem('candidate', address='172.22.64.192', port='54337',
                   name='rtp', username='******',
                   password='******', preference='1', protocol='udp',
                   generation='0', network='1', type='local')
            )
          )
        )
      )
    )
    q.expect('dbus-signal', signal='AddRemoteCandidate', path=stream1.object_path)

    # video rtcp: note the weird name='' field which Gabble has to work around
    stream.send(
      elem_iq(stream, from_=peer, to=self, type='set')(
        elem(ns.JINGLE, 'jingle', action='transport-info', sid=sid)(
          elem('content', name='video')(
            elem(ns.GOOGLE_P2P, 'transport')(
              elem('candidate', address='172.22.64.192', port='54339',
                   name='video_rtcp', username='******',
                   password='******', preference='1', protocol='udp',
                   generation='0', network='1', type='local')
            )
          )
        )
      )
    )
    q.expect('dbus-signal', signal='AddRemoteCandidate', path=stream2.object_path)

    # video rtp: ditto
    stream.send(
      elem_iq(stream, from_=peer, to=self, type='set')(
        elem(ns.JINGLE, 'jingle', action='transport-info', sid=sid)(
          elem('content', name='video')(
            elem(ns.GOOGLE_P2P, 'transport')(
              elem('candidate', address='172.22.64.192', port='54341',
                   name='video_rtp', username='******',
                   password='******', preference='1', protocol='udp',
                   generation='0', network='1', type='local')
            )
          )
        )
      )
    )
    q.expect('dbus-signal', signal='AddRemoteCandidate', path=stream2.object_path)

    # Test that we're sending with name='video_rtp' as well, but only for the video stream.
    stream1.NewNativeCandidate("fake", jt.get_remote_transports_dbus())
    e = q.expect('stream-iq', predicate=jp.action_predicate('transport-info'))
    candidate = xpath.queryForNodes(
        '/iq/jingle/content[@name="audio"]/transport/candidate',
        e.stanza)[0]
    assertEquals('rtp', candidate['name'])

    stream2.NewNativeCandidate("fake", jt.get_remote_transports_dbus())
    e = q.expect('stream-iq', predicate=jp.action_predicate('transport-info'))
    candidate = xpath.queryForNodes(
        '/iq/jingle/content[@name="video"]/transport/candidate',
        e.stanza)[0]
    assertEquals('video_rtp', candidate['name'])
def send_unrecognised_get(q, stream):
    stream.send(
        elem_iq(stream, 'get')(elem('urn:unimaginative',
                                    'dont-handle-me-bro')))

    return q.expect('stream-iq', iq_type='error')
 def send_privacy_list_push_iq(self, list_name):
     iq = elem_iq(self, 'set')(elem(ns.PRIVACY,
                                    'query')(elem('list', name=list_name)))
     self.send(iq)
     return iq["id"]
 def send_privacy_list(self, req_iq, list_items):
     req_list = xpath.queryForNodes('//list', req_iq)[0]
     iq = elem_iq(self, "result", id=req_iq["id"])(elem(
         ns.PRIVACY, 'query')(elem('list',
                                   name=req_list["name"])(*list_items)))
     self.send(iq)
 def shared_status_iq_cb(self, req_iq):
     if req_iq.getAttribute("type") == 'get':
         self._send_status_list(req_iq['id'])
     if req_iq.getAttribute("type") == 'set':
         self._store_shared_statuses(req_iq)
         self.send(elem_iq(self, "result", id=req_iq['id'])())
    def send_privacy_list_list(self, iq_id, lists=[]):
        list_elements = [elem('list', name=l) for l in lists]

        iq = elem_iq(self, "result", id=iq_id)(elem(ns.PRIVACY,
                                                    'query')(*list_elements))
        self.send(iq)
    def send_privacy_list_list(self, iq_id, lists=[]):
        list_elements = [elem('list', name=l) for l in lists]

        iq = elem_iq(self, "result", id=iq_id)(
            elem(ns.PRIVACY, 'query')(*list_elements))
        self.send(iq)
def push_jingle_info(q, stream, stun_server, stun_port):
    iq = elem_iq(stream, 'set')(elem(ns.GOOGLE_JINGLE_INFO, 'query'))
    add_jingle_info(iq, stun_server, stun_port)
    stream.send(iq)
    q.expect('stream-iq', iq_type='result', iq_id=iq['id'])
Example #41
0
def push_jingle_info(q, stream, stun_server, stun_port):
    iq = elem_iq(stream, 'set')(elem(ns.GOOGLE_JINGLE_INFO, 'query'))
    add_jingle_info(iq, stun_server, stun_port)
    stream.send(iq)
    q.expect('stream-iq', iq_type='result', iq_id=iq['id'])