Mercurial > libervia-backend
annotate src/core/xmpp.py @ 341:9eebdc655b8b
code: added asyncConnect
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 May 2011 16:49:47 +0200 |
parents | 953536246d9d |
children | ca3a041fed30 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT: a jabber client | |
228 | 6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) |
0 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
330
608a4a2ba94e
Core: created a new core module where xmpp classes are put
Goffi <goffi@goffi.org>
parents:
324
diff
changeset
|
22 from twisted.internet import task, defer |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
23 from twisted.words.protocols.jabber import jid, xmlstream |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
24 from wokkel import client, disco, xmppim, generic, compat |
0 | 25 from logging import debug, info, error |
26 | |
333
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
27 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
28 class SatXMPPClient(client.XMPPClient): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
29 |
64 | 30 def __init__(self, host_app, profile, user_jid, password, host=None, port=5222): |
50 | 31 client.XMPPClient.__init__(self, user_jid, password, host, port) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
32 self.factory.clientConnectionLost = self.connectionLost |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
33 self.__connected=False |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
34 self.profile = profile |
64 | 35 self.host_app = host_app |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
36 self.client_initialized = defer.Deferred() |
341 | 37 self.conn_deferred = defer.Deferred() |
38 | |
39 def getConnectionDeferred(self): | |
40 """Return a deferred which fire when the client is connected""" | |
41 return self.conn_deferred | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
42 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
43 def _authd(self, xmlstream): |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
44 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
45 return |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
46 client.XMPPClient._authd(self, xmlstream) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
47 self.__connected=True |
69 | 48 info (_("********** [%s] CONNECTED **********") % self.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
49 self.streamInitialized() |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
50 self.host_app.bridge.connected(self.profile) #we send the signal to the clients |
277 | 51 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
52 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
53 def streamInitialized(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
54 """Called after _authd""" |
69 | 55 debug (_("XML stream is initialized")) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
56 self.keep_alife = task.LoopingCall(self.xmlstream.send, " ") #Needed to avoid disconnection (specially with openfire) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
57 self.keep_alife.start(180) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
58 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
59 self.disco = SatDiscoProtocol(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
60 self.disco.setHandlerParent(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
61 self.discoHandler = disco.DiscoHandler() |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
62 self.discoHandler.setHandlerParent(self) |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
63 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
64 if not self.host_app.trigger.point("Disco Handled", self.profile): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
65 return |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
66 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
67 self.roster.requestRoster() |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
68 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
69 self.presence.available() |
64 | 70 |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
71 self.disco.requestInfo(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDisco, self.profile) #FIXME: use these informations |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
72 self.disco.requestItems(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDiscoItems, self.disco, self.profile, self.client_initialized) |
341 | 73 self.conn_deferred.callback(None) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
74 |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
75 def initializationFailed(self, reason): |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
76 print ("initializationFailed: %s" % reason) |
274
c1ad04586edf
Bridge: rename connection_error to connectionError for function name consistency
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
77 self.host_app.bridge.connectionError("AUTH_ERROR", self.profile) |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
78 try: |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
79 client.XMPPClient.initializationFailed(self, reason) |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
80 except: |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
81 #we already send an error signal, no need to raise an exception |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
82 pass |
341 | 83 self.conn_deferred.errback() |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
84 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
85 def isConnected(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
86 return self.__connected |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
87 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
88 def connectionLost(self, connector, unused_reason): |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
89 self.__connected=False |
69 | 90 info (_("********** [%s] DISCONNECTED **********") % self.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
91 try: |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
92 self.keep_alife.stop() |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
93 except AttributeError: |
69 | 94 debug (_("No keep_alife")) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
95 self.host_app.bridge.disconnected(self.profile) #we send the signal to the clients |
0 | 96 |
97 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
98 class SatMessageProtocol(xmppim.MessageProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
99 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
100 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
101 xmppim.MessageProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
102 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
103 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
104 def onMessage(self, message): |
69 | 105 debug (_(u"got message from: %s"), message["from"]) |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
252
diff
changeset
|
106 if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile): |
252
c09aa319712e
Core: Trigger implementation + version number update
Goffi <goffi@goffi.org>
parents:
245
diff
changeset
|
107 return |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
108 for e in message.elements(): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
109 if e.name == "body": |
264 | 110 mess_type = message['type'] if message.hasAttribute('type') else 'normal' |
276
a00e87d48213
bridge, bridge constructor: fixed mix stuff
Goffi <goffi@goffi.org>
parents:
274
diff
changeset
|
111 self.host.bridge.newMessage(message["from"], e.children[0], mess_type, message['to'], profile=self.parent.profile) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
112 self.host.memory.addToHistory(self.parent.jid, jid.JID(message["from"]), self.parent.jid, "chat", e.children[0]) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
113 break |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
114 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
115 class SatRosterProtocol(xmppim.RosterClientProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
116 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
117 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
118 xmppim.RosterClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
119 self.host = host |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
120 self._groups=set() |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
121 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
122 def rosterCb(self, roster): |
50 | 123 for raw_jid, item in roster.iteritems(): |
124 self.onRosterSet(item) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
125 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
126 def requestRoster(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
127 """ ask the server for Roster list """ |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
128 debug("requestRoster") |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
129 self.getRoster().addCallback(self.rosterCb) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
130 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
131 def removeItem(self, to): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
132 """Remove a contact from roster list""" |
50 | 133 xmppim.RosterClientProtocol.removeItem(self, to) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
134 #TODO: check IQ result |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
135 |
187
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
136 #XXX: disabled (cf http://wokkel.ik.nu/ticket/56)) |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
137 #def addItem(self, to): |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
138 #"""Add a contact to roster list""" |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
139 #xmppim.RosterClientProtocol.addItem(self, to) |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
140 #TODO: check IQ result""" |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
141 |
50 | 142 def onRosterSet(self, item): |
143 """Called when a new/update roster item is received""" | |
144 #TODO: send a signal to frontends | |
145 item_attr = {'to': str(item.subscriptionTo), | |
146 'from': str(item.subscriptionFrom), | |
147 'ask': str(item.ask) | |
148 } | |
149 if item.name: | |
150 item_attr['name'] = item.name | |
69 | 151 info (_("new contact in roster list: %s"), item.jid.full()) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
152 self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
153 self.host.bridge.newContact(item.jid.full(), item_attr, item.groups, self.parent.profile) |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
154 self._groups.update(item.groups) |
50 | 155 |
156 def onRosterRemove(self, entity): | |
157 """Called when a roster removal event is received""" | |
158 #TODO: send a signal to frontends | |
69 | 159 print _("removing %s from roster list") % entity.full() |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
160 self.host.memory.delContact(entity, self.parent.profile) |
50 | 161 |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
162 def getGroups(self): |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
163 """Return a set of groups""" |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
164 return self._groups |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
165 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
166 class SatPresenceProtocol(xmppim.PresenceClientProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
167 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
168 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
169 xmppim.PresenceClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
170 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
171 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
172 def availableReceived(self, entity, show=None, statuses=None, priority=0): |
72 | 173 debug (_("presence update for [%(entity)s] (available, show=%(show)s statuses=%(statuses)s priority=%(priority)d)") % {'entity':entity, 'show':show, 'statuses':statuses, 'priority':priority}) |
50 | 174 |
334
698cbc6ebec8
core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents:
333
diff
changeset
|
175 if not statuses: |
698cbc6ebec8
core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents:
333
diff
changeset
|
176 statuses = {} |
698cbc6ebec8
core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents:
333
diff
changeset
|
177 |
50 | 178 if statuses.has_key(None): #we only want string keys |
179 statuses["default"] = statuses[None] | |
180 del statuses[None] | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
181 |
50 | 182 self.host.memory.addPresenceStatus(entity, show or "", |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
183 int(priority), statuses, self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
184 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
185 #now it's time to notify frontends |
50 | 186 self.host.bridge.presenceUpdate(entity.full(), show or "", |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
187 int(priority), statuses, self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
188 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
189 def unavailableReceived(self, entity, statuses=None): |
72 | 190 debug (_("presence update for [%(entity)s] (unavailable, statuses=%(statuses)s)") % {'entity':entity, 'statuses':statuses}) |
334
698cbc6ebec8
core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents:
333
diff
changeset
|
191 |
333
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
192 if not statuses: |
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
193 statuses = {} |
334
698cbc6ebec8
core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents:
333
diff
changeset
|
194 |
333
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
195 if statuses.has_key(None): #we only want string keys |
50 | 196 statuses["default"] = statuses[None] |
197 del statuses[None] | |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
198 self.host.memory.addPresenceStatus(entity, "unavailable", 0, statuses, self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
199 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
200 #now it's time to notify frontends |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
201 self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses, self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
202 |
50 | 203 |
204 def available(self, entity=None, show=None, statuses=None, priority=0): | |
205 if statuses and statuses.has_key('default'): | |
206 statuses[None] = statuses['default'] | |
207 del statuses['default'] | |
208 xmppim.PresenceClientProtocol.available(self, entity, show, statuses, priority) | |
209 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
210 def subscribedReceived(self, entity): |
69 | 211 debug (_("subscription approved for [%s]") % entity.userhost()) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
212 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
213 self.host.bridge.subscribe('subscribed', entity.userhost(), self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
214 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
215 def unsubscribedReceived(self, entity): |
69 | 216 debug (_("unsubscription confirmed for [%s]") % entity.userhost()) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
217 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
218 self.host.bridge.subscribe('unsubscribed', entity.userhost(), self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
219 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
220 def subscribeReceived(self, entity): |
69 | 221 debug (_("subscription request for [%s]") % entity.userhost()) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
222 self.host.memory.addWaitingSub('subscribe', entity.userhost(), self.parent.profile) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
223 self.host.bridge.subscribe('subscribe', entity.userhost(), self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
224 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
225 def unsubscribeReceived(self, entity): |
69 | 226 debug (_("unsubscription asked for [%s]") % entity.userhost()) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
227 self.host.memory.addWaitingSub('unsubscribe', entity.userhost(), self.parent.profile) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
228 self.host.bridge.subscribe('unsubscribe', entity.userhost(), self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
229 |
14 | 230 class SatDiscoProtocol(disco.DiscoClientProtocol): |
231 def __init__(self, host): | |
232 disco.DiscoClientProtocol.__init__(self) | |
233 | |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
234 class SatFallbackHandler(generic.FallbackHandler): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
235 def __init__(self, host): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
236 generic.FallbackHandler.__init__(self) |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
237 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
238 def iqFallback(self, iq): |
292
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
239 if iq.handled == True: |
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
240 return |
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
241 debug (u"iqFallback: xml = [%s]" % (iq.toXml())) |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
242 generic.FallbackHandler.iqFallback(self, iq) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
243 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
244 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
245 |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
246 def __init__(self, host, jabber_host, user_login, user_pass, email, answer_id): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
247 xmlstream.ConnectAuthenticator.__init__(self, jabber_host) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
248 self.host = host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
249 self.jabber_host = jabber_host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
250 self.user_login = user_login |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
251 self.user_pass = user_pass |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
252 self.user_email = email |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
253 self.answer_id = answer_id |
69 | 254 print _("Registration asked for"),user_login, user_pass, jabber_host |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
255 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
256 def connectionMade(self): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
257 print "connectionMade" |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
258 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
259 self.xmlstream.namespace = "jabber:client" |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
260 self.xmlstream.sendHeader() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
261 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
262 iq = compat.IQ(self.xmlstream, 'set') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
263 iq["to"] = self.jabber_host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
264 query = iq.addElement(('jabber:iq:register', 'query')) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
265 _user = query.addElement('username') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
266 _user.addContent(self.user_login) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
267 _pass = query.addElement('password') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
268 _pass.addContent(self.user_pass) |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
269 if self.user_email: |
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
270 _email = query.addElement('email') |
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
271 _email.addContent(self.user_email) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
272 reg = iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
273 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
274 def registrationAnswer(self, answer): |
69 | 275 debug (_("registration answer: %s") % answer.toXml()) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
276 answer_type = "SUCCESS" |
69 | 277 answer_data={"message":_("Registration successfull")} |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
278 self.host.bridge.actionResult(answer_type, self.answer_id, answer_data) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
279 self.xmlstream.sendFooter() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
280 |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
281 def registrationFailure(self, failure): |
69 | 282 info (_("Registration failure: %s") % str(failure.value)) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
283 answer_type = "ERROR" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
284 answer_data = {} |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
285 if failure.value.condition == 'conflict': |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
286 answer_data['reason'] = 'conflict' |
69 | 287 answer_data={"message":_("Username already exists, please choose an other one")} |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
288 else: |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
289 answer_data['reason'] = 'unknown' |
69 | 290 answer_data={"message":_("Registration failed (%s)") % str(failure.value.condition)} |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
291 self.host.bridge.actionResult(answer_type, self.answer_id, answer_data) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
292 self.xmlstream.sendFooter() |
292
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
293 |
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
294 class SatVersionHandler(generic.VersionHandler): |
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
295 |
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
296 def getDiscoInfo(self, requestor, target, node): |
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
297 #XXX: We need to work around wokkel's behavious (namespace not added if there is a |
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
298 # node) as it cause issues with XEP-0115 & PEP (XEP-0163): there is a node when server |
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
299 # ask for disco info, and not when we generate the key, so the hash is used with different |
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
300 # disco features, and when the server (seen on ejabberd) generate its own hash for security check |
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
301 # it reject our features (resulting in e.g. no notification on PEP) |
f7bd973bba5a
core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents:
288
diff
changeset
|
302 return generic.VersionHandler.getDiscoInfo(self, requestor, target, None) |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
303 |