Mercurial > libervia-backend
annotate libervia/backend/core/patches.py @ 4108:238e305f2306
plugin JID Search: JID search plugin, first draft
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 06 Jul 2023 11:34:51 +0200 |
parents | 4b842c1fb686 |
children | a1e7e82a8921 |
rev | line source |
---|---|
2809
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
1 import copy |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
2 from twisted.words.protocols.jabber import xmlstream, sasl, client as tclient, jid |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 from wokkel import client |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
4 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
5 from libervia.backend.core.log import getLogger |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
7 log = getLogger(__name__) |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
9 """This module applies monkey patches to Twisted and Wokkel |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
10 First part handle certificate validation during XMPP connectionand are temporary |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
11 (until merged upstream). |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
12 Second part add a trigger point to send and onElement method of XmlStream |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
13 """ |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
14 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
15 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
16 ## certificate validation patches |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 class XMPPClient(client.XMPPClient): |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
21 def __init__(self, jid, password, host=None, port=5222, |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
22 tls_required=True, configurationForTLS=None): |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 self.jid = jid |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 self.domain = jid.host.encode('idna') |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 self.host = host |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 self.port = port |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
28 factory = HybridClientFactory( |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
29 jid, password, tls_required=tls_required, |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
30 configurationForTLS=configurationForTLS) |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 client.StreamManager.__init__(self, factory) |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
35 def HybridClientFactory(jid, password, tls_required=True, configurationForTLS=None): |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
36 a = HybridAuthenticator(jid, password, tls_required, configurationForTLS) |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 return xmlstream.XmlStreamFactory(a) |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 class HybridAuthenticator(client.HybridAuthenticator): |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
42 res_binding = True |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
44 def __init__(self, jid, password, tls_required=True, configurationForTLS=None): |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 xmlstream.ConnectAuthenticator.__init__(self, jid.host) |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 self.jid = jid |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 self.password = password |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
48 self.tls_required = tls_required |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
49 self.configurationForTLS = configurationForTLS |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 def associateWithStream(self, xs): |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 xmlstream.ConnectAuthenticator.associateWithStream(self, xs) |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
54 tlsInit = xmlstream.TLSInitiatingInitializer( |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
55 xs, required=self.tls_required, configurationForTLS=self.configurationForTLS) |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 xs.initializers = [client.client.CheckVersionInitializer(xs), |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 tlsInit, |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
58 CheckAuthInitializer(xs, self.res_binding)] |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
59 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
60 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
61 # XmlStream triggers |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
62 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
63 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
64 class XmlStream(xmlstream.XmlStream): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
65 """XmlStream which allows to add hooks""" |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
66 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
67 def __init__(self, authenticator): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
68 xmlstream.XmlStream.__init__(self, authenticator) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
69 # hooks at this level should not modify content |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
70 # so it's not needed to handle priority as with triggers |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
71 self._onElementHooks = [] |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
72 self._sendHooks = [] |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
73 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3044
diff
changeset
|
74 def add_hook(self, hook_type, callback): |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
75 """Add a send or receive hook""" |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
76 conflict_msg = f"Hook conflict: can't add {hook_type} hook {callback}" |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
77 if hook_type == C.STREAM_HOOK_RECEIVE: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
78 if callback not in self._onElementHooks: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
79 self._onElementHooks.append(callback) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
80 else: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
81 log.warning(conflict_msg) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
82 elif hook_type == C.STREAM_HOOK_SEND: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
83 if callback not in self._sendHooks: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
84 self._sendHooks.append(callback) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
85 else: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
86 log.warning(conflict_msg) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
87 else: |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
88 raise ValueError(f"Invalid hook type: {hook_type}") |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
89 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
90 def onElement(self, element): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
91 for hook in self._onElementHooks: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
92 hook(element) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
93 xmlstream.XmlStream.onElement(self, element) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
94 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
95 def send(self, obj): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
96 for hook in self._sendHooks: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
97 hook(obj) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
98 xmlstream.XmlStream.send(self, obj) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
99 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
100 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
101 # Binding activation (needed for stream management, XEP-0198) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
102 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
103 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
104 class CheckAuthInitializer(client.CheckAuthInitializer): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
105 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
106 def __init__(self, xs, res_binding): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
107 super(CheckAuthInitializer, self).__init__(xs) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
108 self.res_binding = res_binding |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
109 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
110 def initialize(self): |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
111 # XXX: modification of client.CheckAuthInitializer which has optional |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
112 # resource binding, and which doesn't do deprecated |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
113 # SessionInitializer |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
114 if (sasl.NS_XMPP_SASL, 'mechanisms') in self.xmlstream.features: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
115 inits = [(sasl.SASLInitiatingInitializer, True)] |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
116 if self.res_binding: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
117 inits.append((tclient.BindInitializer, True)), |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
118 |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
119 for initClass, required in inits: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
120 init = initClass(self.xmlstream) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
121 init.required = required |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
122 self.xmlstream.initializers.append(init) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
123 elif (tclient.NS_IQ_AUTH_FEATURE, 'auth') in self.xmlstream.features: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
124 self.xmlstream.initializers.append( |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
125 tclient.IQAuthInitializer(self.xmlstream)) |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
126 else: |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
127 raise Exception("No available authentication method found") |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
2809
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
130 # jid fix |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
131 |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
132 def internJID(jidstring): |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
133 """ |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
134 Return interned JID. |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
135 |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
136 @rtype: L{JID} |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
137 """ |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
138 # XXX: this interJID return a copy of the cached jid |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
139 # this avoid modification of cached jid as JID is mutable |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
140 # TODO: propose this upstream |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
141 |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
142 if jidstring in jid.__internJIDs: |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
143 return copy.copy(jid.__internJIDs[jidstring]) |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
144 else: |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
145 j = jid.JID(jidstring) |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
146 jid.__internJIDs[jidstring] = j |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
147 return copy.copy(j) |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
148 |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
149 |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 def apply(): |
3044
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
151 # certificate validation |
691283719bb2
core (patches): updated TLS patches:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
152 client.XMPPClient = XMPPClient |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
153 # XmlStream triggers |
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
154 xmlstream.XmlStreamFactory.protocol = XmlStream |
2809
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
155 # jid fix |
00d905e1b0ef
core (patches): partially fixed jid caching:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
156 jid.internJID = internJID |