| Trees | Indices | Help |
|
|---|
|
|
1 # -*- coding:utf-8 -*-
2 ## src/common/protocol/caps.py
3 ##
4 ## Copyright (C) 2009 Stephan Erb <steve-e AT h3c.de>
5 ##
6 ## This file is part of Gajim.
7 ##
8 ## Gajim is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published
10 ## by the Free Software Foundation; version 3 only.
11 ##
12 ## Gajim is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ## GNU General Public License for more details.
16 ##
17 ## You should have received a copy of the GNU General Public License
18 ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
19 ##
20
21 """
22 Module containing the network portion of XEP-115 (Entity Capabilities)
23 """
24
25 import logging
26 log = logging.getLogger('gajim.c.p.caps')
27
28 from common.xmpp import NS_CAPS
29 from common import gajim
30 from common import helpers
31
32
34
36 self._account = account
37 self._dispatch_event = dispatch_event
38 self._capscache = capscache
39 self._create_suitable_client_caps = client_caps_factory
40
42 """
43 XMMPPY callback method to handle retrieved caps info
44 """
45 try:
46 jid = helpers.get_full_jid_from_iq(presence)
47 except:
48 log.info("Ignoring invalid JID in caps presenceCB")
49 return
50
51 client_caps = self._extract_client_caps_from_presence(presence)
52 self._capscache.query_client_of_jid_if_unknown(self, jid, client_caps)
53 self._update_client_caps_of_contact(jid, client_caps)
54
55 self._dispatch_event('CAPS_RECEIVED', (jid,))
56
58 caps_tag = presence.getTag('c', namespace=NS_CAPS)
59 if caps_tag:
60 hash_method, node, caps_hash = caps_tag['hash'], caps_tag['node'], caps_tag['ver']
61 else:
62 hash_method = node = caps_hash = None
63 return self._create_suitable_client_caps(node, caps_hash, hash_method)
64
66 contact = self._get_contact_or_gc_contact_for_jid(jid)
67 if contact:
68 contact.client_caps = client_caps
69 else:
70 log.info("Received Caps from unknown contact %s" % jid)
71
73 contact = gajim.contacts.get_contact_from_full_jid(self._account, jid)
74 if contact is None:
75 room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
76 contact = gajim.contacts.get_gc_contact(self._account, room_jid, nick)
77 return contact
78
80 """
81 XMMPPY callback to update our caps cache with queried information after
82 we have retrieved an unknown caps hash and issued a disco
83 """
84 contact = self._get_contact_or_gc_contact_for_jid(jid)
85 if not contact:
86 log.info("Received Disco from unknown contact %s" % jid)
87 return
88
89 lookup = contact.client_caps.get_cache_lookup_strategy()
90 cache_item = lookup(self._capscache)
91
92 if cache_item.is_valid():
93 # we already know that the hash is fine and have already cached
94 # the identities and features
95 return
96 else:
97 validate = contact.client_caps.get_hash_validation_strategy()
98 hash_is_valid = validate(identities, features, dataforms)
99
100 if hash_is_valid:
101 cache_item.set_and_store(identities, features)
102 else:
103 node = caps_hash = hash_method = None
104 contact.client_caps = self._create_suitable_client_caps(node,
105 caps_hash, hash_method)
106 log.info("Computed and retrieved caps hash differ." +
107 "Ignoring caps of contact %s" % contact.get_full_jid())
108
109 self._dispatch_event('CAPS_RECEIVED', (jid,))
110
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Thu Aug 12 02:08:15 2010 | http://epydoc.sourceforge.net |