annotate jabberbot/capat.py @ 4701:d8049de69c4f

release edit lock if someone saves an unchanged page
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 18 Apr 2009 21:08:35 +0200
parents 911cb338943e
children 500f68d3e2fd
rev   line source
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
2
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
3 """
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
4 MoinMoin - Entity Capabilities (XEP-0115) implementation
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
5
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2968
diff changeset
6 Enables Jabber/XMPP clients to save bandwidth by caching
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2968
diff changeset
7 information about extensions supported by various client
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
8 implementations.
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
9
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
10 @copyright: 2007 by Robert Lehmann <lehmannro@gmail.com>
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2968
diff changeset
11 2008 by Bolesław Kulbabiński <bolekk@gmail.com>
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
12 @license: GNU GPL, see COPYING for details.
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
13 """
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
14
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
15 import base64
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
16 import itertools
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
17 from MoinMoin.support.python_compatibility import hash_new
2968
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
18 from pyxmpp.presence import Presence
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
19
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
20 HASHALIASES = { # IANA Hash Function Textual Names Registry
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
21 # to `hashlib.new` mapping
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
22 'sha-1': 'sha1',
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
23 'sha-224': 'sha224',
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
24 'sha-256': 'sha256',
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
25 'sha-384': 'sha384',
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
26 'sha-512': 'sha512',
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
27 'md5': 'md5',
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
28 'md2': 'md2',
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
29 }
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
30
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
31
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
32 def generate_ver(identities, features, algo='sha-1'):
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
33 """Generate the 'ver' attribute according to XEP-0115.
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
34
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
35 See http://www.xmpp.org/extensions/xep-0115.html#ver
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2968
diff changeset
36
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
37 @param identities: a number of (category, type) identity pairs
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
38 @param algo: optional algo attribute with IANA aliasing
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
39
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
40 @type identities: iterable of 2-tuples of strings
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
41 @type features: iterable of strings
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
42 @type algo: string (IANA Hash Function Textual Name)
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
43 """
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
44
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
45 # only IANA aliases are supported
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
46 if algo not in HASHALIASES:
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
47 raise ValueError("undefined hash algorithm")
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
48 algo = hash_new(HASHALIASES[algo])
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
49
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
50 ident = list(identities)
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
51 # default sorting already considers both, category and type
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
52 ident.sort()
4393
911cb338943e Python 2.3 compatibility fixes (thanks to Greg Ward)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3019
diff changeset
53 ident = ['%s/%s' % (idcat, idtype) for idcat, idtype in ident]
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2968
diff changeset
54
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
55 feat = list(features)
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
56 # strings (byte arrays) are ordered by i;octet by default
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
57 feat.sort()
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
58
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2968
diff changeset
59 s = '<'.join(itertools.chain(ident, feat, ('', )))
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
60 # the trailing empty string adds a trailing '<' to the result
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
61 algo.update(s)
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
62 s = base64.b64encode(algo.digest())
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
63
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
64 return s
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
65
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
66 def hash_iq(stanza, algo='sha-1'):
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
67 """Search an <Iq/> entity for features/identities and generate a
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
68 'ver' attribute hash.
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
69
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
70 @type stanza: pyxmpp.iq.Iq
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
71 """
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
72 stanza = iter(stanza.get_query())
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
73 stanza.next() # drop first item: whole query
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2968
diff changeset
74
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
75 feat = []
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
76 ident = []
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2968
diff changeset
77
2958
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
78 # traverse all child nodes
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
79 for item in stanza:
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
80 if item.name == 'identity':
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
81 ident.append((item.prop('category'), item.prop('type')))
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
82 elif item.name == 'feature':
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
83 feat.append(item.prop('var'))
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
84
6eebb112108b GHOP: 1st part of XEP-115 (Entity Capabilities) implementation by starGaming
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
85 return generate_ver(ident, feat, algo)
2968
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
86
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
87 # <identity /> and <feature /> attributes
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
88 IDENT = (('category', 'client'),
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
89 ('type', 'bot'))
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
90 FEAT = ('http://jabber.org/protocol/disco#info',
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
91 'jabber:x:data') # data forms
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
92 NODE = "http://moinmo.in/#1.7"
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
93
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
94 def create_presence(jid):
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
95 """ Creates a presence stanza (as described in XEP-0115)
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
96
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
97 @param jid: bot's jabber ID
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
98 """
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
99 pres = Presence(from_jid=jid)
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
100
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
101 c = pres.add_new_content('http://jabber.org/protocol/caps', 'c')
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
102 c.setProp('node', NODE)
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
103
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
104 ver = generate_ver(IDENT, FEAT)
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
105 c.setProp('ver', ver)
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
106
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
107 return pres
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
108
3019
d860ab45d438 GHOP: part 3/3 of XEP-115 implementation by bolekk.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2968
diff changeset
109 def create_response(disco_query):
2968
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
110 """ Creates an <Iq /> tag as a response to a service discovery query
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
111
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
112 @param disco_query: received query
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
113 """
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
114 response = disco_query.make_result_response()
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
115 query = response.new_query(ns_uri='http://jabber.org/protocol/disco#info')
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
116
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
117 ident = query.newChild(None, 'identity', None)
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
118 for item in IDENT:
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
119 ident.setProp(item[0], item[1])
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
120
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
121 for item in FEAT:
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
122 query.newChild(None, 'feature', None).setProp('var', item)
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
123
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
124 return response
2a5fa7d79d86 GHOP: 2/3 of XEP-0115 implementation by bolekk
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2958
diff changeset
125