Mercurial > libervia-backend
annotate sat.tac @ 67:0e50dd3a234a
message sending bug fixes + sortilege update
- sortilege now use default profile. /!\ sortilege is really buggy currently, need some attention
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 04 Feb 2010 01:06:36 +1100 |
parents | 8147b4f40809 |
children | 9b842086d915 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT: a jabber client | |
57 | 6 Copyright (C) 2009, 2010 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 | |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
22 CONST = { |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
23 'client_name' : u'SàT (Salut à toi)', |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
58
diff
changeset
|
24 'client_version' : u'0.0.2D', #Please add 'D' at the end for dev versions |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
25 'local_dir' : '~/.sat' |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
26 } |
0 | 27 |
2
c49345fd7737
refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
28 from twisted.application import internet, service |
12
ef8060d365cb
whitespace ping to avoid disconnection (was disconnected after 6 min of inactivity with openfire)
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
29 from twisted.internet import glib2reactor, protocol, task |
0 | 30 glib2reactor.install() |
31 | |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
32 from twisted.words.protocols.jabber import jid, xmlstream |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
33 from twisted.words.protocols.jabber import error as jab_error |
0 | 34 from twisted.words.xish import domish |
35 | |
36 from twisted.internet import reactor | |
37 import pdb | |
38 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
39 from wokkel import client, disco, xmppim, generic, compat |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
40 |
0 | 41 from sat_bridge.DBus import DBusBridge |
42 import logging | |
43 from logging import debug, info, error | |
44 | |
45 import signal, sys | |
46 import os.path | |
47 | |
48 from tools.memory import Memory | |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
49 from tools.xml_tools import XMLTools |
0 | 50 from glob import glob |
51 | |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
52 try: |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
53 from twisted.words.protocols.xmlstream import XMPPHandler |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
54 except ImportError: |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
55 from wokkel.subprotocols import XMPPHandler |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
56 |
0 | 57 |
58 ### logging configuration FIXME: put this elsewhere ### | |
59 logging.basicConfig(level=logging.DEBUG, | |
60 format='%(message)s') | |
61 ### | |
62 | |
63 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
64 sat_id = 0 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
65 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
66 def sat_next_id(): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
67 global sat_id |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
68 sat_id+=1 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
69 return "sat_id_"+str(sat_id) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
70 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
71 class SatXMPPClient(client.XMPPClient): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
72 |
64 | 73 def __init__(self, host_app, profile, user_jid, password, host=None, port=5222): |
50 | 74 client.XMPPClient.__init__(self, user_jid, password, host, port) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
75 self.factory.clientConnectionLost = self.connectionLost |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
76 self.__connected=False |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
77 self.profile = profile |
64 | 78 self.host_app = host_app |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
79 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
80 def _authd(self, xmlstream): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
81 print "SatXMPPClient" |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
82 client.XMPPClient._authd(self, xmlstream) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
83 self.__connected=True |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
84 print "********** [%s] CONNECTED **********" % self.profile |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
85 self.streamInitialized() |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
86 self.host_app.bridge.connected(self.profile) #we send the signal to the clients |
13
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 streamInitialized(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
89 """Called after _authd""" |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
90 debug ("XML stream is initialized") |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
91 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
|
92 self.keep_alife.start(180) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
93 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
94 self.disco = SatDiscoProtocol(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
95 self.disco.setHandlerParent(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
96 self.discoHandler = disco.DiscoHandler() |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
97 self.discoHandler.setHandlerParent(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
98 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
99 self.roster.requestRoster() |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
100 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
101 self.presence.available() |
64 | 102 |
103 self.disco.requestInfo(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDisco) #FIXME: use these informations | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
104 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
105 def isConnected(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
106 return self.__connected |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
107 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
108 def connectionLost(self, connector, unused_reason): |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
109 self.__connected=False |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
110 print "********** [%s] DISCONNECTED **********" % self.profile |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
111 try: |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
112 self.keep_alife.stop() |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
113 except AttributeError: |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
114 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
|
115 self.host_app.bridge.disconnected(self.profile) #we send the signal to the clients |
0 | 116 |
117 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
118 class SatMessageProtocol(xmppim.MessageProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
119 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
120 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
121 xmppim.MessageProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
122 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
123 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
124 def onMessage(self, message): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
125 debug (u"got_message from: %s", message["from"]) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
126 for e in message.elements(): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
127 if e.name == "body": |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
128 type = message['type'] if message.hasAttribute('type') else 'chat' #FIXME: check specs |
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
129 self.host.bridge.newMessage(message["from"], e.children[0], type, profile=self.parent.profile) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
130 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
|
131 break |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
132 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
133 class SatRosterProtocol(xmppim.RosterClientProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
134 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
135 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
136 xmppim.RosterClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
137 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
138 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
139 def rosterCb(self, roster): |
50 | 140 for raw_jid, item in roster.iteritems(): |
141 self.onRosterSet(item) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
142 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
143 def requestRoster(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
144 """ ask the server for Roster list """ |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
145 debug("requestRoster") |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
146 self.getRoster().addCallback(self.rosterCb) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
147 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
148 def removeItem(self, to): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
149 """Remove a contact from roster list""" |
50 | 150 xmppim.RosterClientProtocol.removeItem(self, to) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
151 #TODO: check IQ result |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
152 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
153 def addItem(self, to): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
154 """Add a contact to roster list""" |
50 | 155 xmppim.RosterClientProtocol.addItem(self, to) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
156 #TODO: check IQ result |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
157 |
50 | 158 def onRosterSet(self, item): |
159 """Called when a new/update roster item is received""" | |
160 #TODO: send a signal to frontends | |
161 item_attr = {'to': str(item.subscriptionTo), | |
162 'from': str(item.subscriptionFrom), | |
163 'ask': str(item.ask) | |
164 } | |
165 if item.name: | |
166 item_attr['name'] = item.name | |
167 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
|
168 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
|
169 self.host.bridge.newContact(item.jid.full(), item_attr, item.groups, self.parent.profile) |
50 | 170 |
171 def onRosterRemove(self, entity): | |
172 """Called when a roster removal event is received""" | |
173 #TODO: send a signal to frontends | |
174 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
|
175 self.host.memory.delContact(entity, self.parent.profile) |
50 | 176 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
177 class SatPresenceProtocol(xmppim.PresenceClientProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
178 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
179 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
180 xmppim.PresenceClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
181 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
182 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
183 def availableReceived(self, entity, show=None, statuses=None, priority=0): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
184 info ("presence update for [%s]", entity) |
50 | 185 |
186 if statuses.has_key(None): #we only want string keys | |
187 statuses["default"] = statuses[None] | |
188 del statuses[None] | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
189 |
50 | 190 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
|
191 int(priority), statuses, self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
192 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
193 #now it's time to notify frontends |
50 | 194 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
|
195 int(priority), statuses, self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
196 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
197 def unavailableReceived(self, entity, statuses=None): |
50 | 198 if statuses and statuses.has_key(None): #we only want string keys |
199 statuses["default"] = statuses[None] | |
200 del statuses[None] | |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
201 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
|
202 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
203 #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
|
204 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
|
205 |
50 | 206 |
207 def available(self, entity=None, show=None, statuses=None, priority=0): | |
208 if statuses and statuses.has_key('default'): | |
209 statuses[None] = statuses['default'] | |
210 del statuses['default'] | |
211 xmppim.PresenceClientProtocol.available(self, entity, show, statuses, priority) | |
212 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
213 def subscribedReceived(self, entity): |
50 | 214 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
|
215 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
|
216 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
|
217 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
218 def unsubscribedReceived(self, entity): |
50 | 219 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
|
220 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
|
221 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
|
222 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
223 def subscribeReceived(self, entity): |
50 | 224 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
|
225 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
|
226 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
|
227 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
228 def unsubscribeReceived(self, entity): |
50 | 229 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
|
230 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
|
231 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
|
232 |
14 | 233 class SatDiscoProtocol(disco.DiscoClientProtocol): |
234 def __init__(self, host): | |
235 disco.DiscoClientProtocol.__init__(self) | |
236 | |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
237 class SatFallbackHandler(generic.FallbackHandler): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
238 def __init__(self, host): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
239 generic.FallbackHandler.__init__(self) |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
240 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
241 def iqFallback(self, iq): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
242 #pdb.set_trace() |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
243 print "iqFallback: xml = [%s], handled=%s" % (iq.toXml(), "True" if iq.handled else "False") |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
244 generic.FallbackHandler.iqFallback(self, iq) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
245 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
246 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
247 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
248 def __init__(self, host, jabber_host, user_login, user_pass, answer_id): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
249 xmlstream.ConnectAuthenticator.__init__(self, jabber_host) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
250 self.host = host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
251 self.jabber_host = jabber_host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
252 self.user_login = user_login |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
253 self.user_pass = user_pass |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
254 self.answer_id = answer_id |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
255 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
|
256 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
257 def connectionMade(self): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
258 print "connectionMade" |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
259 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
260 self.xmlstream.namespace = "jabber:client" |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
261 self.xmlstream.sendHeader() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
262 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
263 iq = compat.IQ(self.xmlstream, 'set') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
264 iq["to"] = self.jabber_host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
265 query = iq.addElement(('jabber:iq:register', 'query')) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
266 _user = query.addElement('username') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
267 _user.addContent(self.user_login) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
268 _pass = query.addElement('password') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
269 _pass.addContent(self.user_pass) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
270 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
|
271 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
272 def registrationAnswer(self, answer): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
273 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
|
274 answer_type = "SUCCESS" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
275 answer_data={"message":"Registration successfull"} |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
276 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
|
277 self.xmlstream.sendFooter() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
278 |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
279 def registrationFailure(self, failure): |
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
280 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
|
281 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
|
282 answer_data = {} |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
283 if failure.value.condition == 'conflict': |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
284 answer_data['reason'] = 'conflict' |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
285 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
|
286 else: |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
287 answer_data['reason'] = 'unknown' |
50 | 288 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
|
289 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
|
290 self.xmlstream.sendFooter() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
291 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
292 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
293 class SAT(service.Service): |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
294 |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
295 def get_next_id(self): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
296 return sat_next_id() |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
297 |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
298 def get_const(self, name): |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
299 """Return a constant""" |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
300 if not CONST.has_key(name): |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
301 error('Trying to access an undefined constant') |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
302 raise Exception |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
303 return CONST[name] |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
304 |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
305 def set_const(self, name, value): |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
306 """Save a constant""" |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
307 if CONST.has_key(name): |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
308 error('Trying to redefine a constant') |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
309 raise Exception |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
310 CONST[name] = value |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
311 |
0 | 312 def __init__(self): |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
313 #TODO: standardize callback system |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
314 |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
315 local_dir = os.path.expanduser(self.get_const('local_dir')) |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
316 if not os.path.exists(local_dir): |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
317 os.makedirs(local_dir) |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
318 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
319 self.__waiting_conf = {} #callback called when a confirmation is received |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
320 self.__progress_cb_map = {} #callback called when a progress is requested (key = progress id) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
321 self.__general_cb_map = {} #callback called for general reasons (key = name) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
322 self.__private_data = {} #used for internal callbacks (key = id) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
323 self.profiles = {} |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
324 self.plugins = {} |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
325 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
326 self.memory=Memory(self) |
0 | 327 self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future |
328 | |
329 self.bridge=DBusBridge() | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
330 self.bridge.register("getProfileName", self.memory.getProfileName) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
58
diff
changeset
|
331 self.bridge.register("getProfilesList", self.memory.getProfilesList) |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
58
diff
changeset
|
332 self.bridge.register("createProfile", self.memory.createProfile) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
333 self.bridge.register("registerNewAccount", self.registerNewAccount) |
0 | 334 self.bridge.register("connect", self.connect) |
1 | 335 self.bridge.register("disconnect", self.disconnect) |
0 | 336 self.bridge.register("getContacts", self.memory.getContacts) |
337 self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus) | |
50 | 338 self.bridge.register("getWaitingSub", self.memory.getWaitingSub) |
0 | 339 self.bridge.register("sendMessage", self.sendMessage) |
340 self.bridge.register("setParam", self.setParam) | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
341 self.bridge.register("getParamA", self.memory.getParamA) |
0 | 342 self.bridge.register("getParams", self.memory.getParams) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
343 self.bridge.register("getParamsForCategory", self.memory.getParamsForCategory) |
0 | 344 self.bridge.register("getParamsCategories", self.memory.getParamsCategories) |
345 self.bridge.register("getHistory", self.memory.getHistory) | |
346 self.bridge.register("setPresence", self.setPresence) | |
50 | 347 self.bridge.register("subscription", self.subscription) |
0 | 348 self.bridge.register("addContact", self.addContact) |
349 self.bridge.register("delContact", self.delContact) | |
350 self.bridge.register("isConnected", self.isConnected) | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
351 self.bridge.register("launchAction", self.launchAction) |
0 | 352 self.bridge.register("confirmationAnswer", self.confirmationAnswer) |
353 self.bridge.register("getProgress", self.getProgress) | |
354 | |
64 | 355 self._import_plugins() |
0 | 356 |
357 | |
358 def _import_plugins(self): | |
359 """Import all plugins found in plugins directory""" | |
360 #TODO: manage dependencies | |
361 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename,glob ("plugins/plugin*.py"))] | |
64 | 362 |
0 | 363 for plug in plug_lst: |
364 plug_path = 'plugins.'+plug | |
365 __import__(plug_path) | |
366 mod = sys.modules[plug_path] | |
367 plug_info = mod.PLUGIN_INFO | |
368 info ("importing plugin: %s", plug_info['name']) | |
369 self.plugins[plug_info['import_name']] = getattr(mod, plug_info['main'])(self) | |
64 | 370 if plug_info.has_key('handler') and plug_info['handler'] == 'yes': |
371 self.plugins[plug_info['import_name']].is_handler = True | |
372 else: | |
373 self.plugins[plug_info['import_name']].is_handler = False | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
374 #TODO: test xmppclient presence and register handler parent |
0 | 375 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
376 def connect(self, profile_key = '@DEFAULT@'): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
377 """Connect to jabber server""" |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
378 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
379 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
380 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
381 if not profile_key: |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
382 error ('Trying to connect a non-exsitant profile') |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
383 return |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
384 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
385 if (self.isConnected()): |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
386 info("already connected !") |
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
387 return |
2
c49345fd7737
refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
388 print "connecting..." |
64 | 389 current = self.profiles[profile] = SatXMPPClient(self, profile, |
390 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile_key), profile), | |
391 self.memory.getParamA("Password", "Connection", profile_key = profile_key), | |
392 self.memory.getParamA("Server", "Connection", profile_key = profile_key), 5222) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
393 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
394 current.messageProt = SatMessageProtocol(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
395 current.messageProt.setHandlerParent(current) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
396 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
397 current.roster = SatRosterProtocol(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
398 current.roster.setHandlerParent(current) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
399 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
400 current.presence = SatPresenceProtocol(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
401 current.presence.setHandlerParent(current) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
402 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
403 current.fallBack = SatFallbackHandler(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
404 current.fallBack.setHandlerParent(current) |
14 | 405 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
406 current.versionHandler = generic.VersionHandler(self.get_const('client_name'), |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
407 self.get_const('client_version')) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
408 current.versionHandler.setHandlerParent(current) |
14 | 409 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
410 debug ("setting plugins parents") |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
411 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
412 for plugin in self.plugins.iteritems(): |
64 | 413 if plugin[1].is_handler: |
414 plugin[1].getHandler().setHandlerParent(current) | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
415 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
416 current.startService() |
2
c49345fd7737
refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
417 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
418 def disconnect(self, profile_key='@DEFAULT@'): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
419 """disconnect from jabber server""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
420 if (not self.isConnected(profile_key)): |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
421 info("not connected !") |
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
422 return |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
423 profile = self.memory.getProfileName(profile_key) |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
424 info("Disconnecting...") |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
425 self.profiles[profile].stopService() |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
426 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
427 def startService(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
428 info("Salut à toi ô mon frère !") |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
429 self.connect() |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
430 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
431 def stopService(self): |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
432 self.memory.save() |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
433 info("Salut aussi à Rantanplan") |
0 | 434 |
435 def run(self): | |
436 debug("running app") | |
437 reactor.run() | |
438 | |
439 def stop(self): | |
440 debug("stopping app") | |
441 reactor.stop() | |
442 | |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
443 ## Misc methods ## |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
444 |
64 | 445 def getJidNStream(self, profile_key): |
446 """Convenient method to get jid and stream from profile key | |
447 @return: tuple (jid, xmlstream) from profile, can be None""" | |
448 profile = self.memory.getProfileName(profile_key) | |
449 if not profile or not self.profiles[profile].isConnected(): | |
450 return (None, None) | |
451 return (self.profiles[profile].jid, self.profiles[profile].xmlstream) | |
452 | |
453 def getClient(self, profile_key): | |
454 """Convenient method to get client from profile key | |
455 @return: client or None if it doesn't exist""" | |
456 profile = self.memory.getProfileName(profile_key) | |
457 if not profile: | |
458 return None | |
459 return self.profiles[profile] | |
460 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
461 def registerNewAccount(self, login, password, server, port = 5222, id = None): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
462 """Connect to a server and create a new account using in-band registration""" |
0 | 463 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
464 next_id = id or sat_next_id() #the id is used to send server's answer |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
465 serverRegistrer = xmlstream.XmlStreamFactory(RegisteringAuthenticator(self, server, login, password, next_id)) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
466 connector = reactor.connectTCP(server, port, serverRegistrer) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
467 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
468 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
469 return next_id |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
470 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
471 def registerNewAccountCB(self, id, data): |
64 | 472 #FIXME: gof: profile not managed here ! |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
473 user = jid.parse(self.memory.getParamA("JabberID", "Connection"))[0] |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
474 password = self.memory.getParamA("Password", "Connection") |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
475 server = self.memory.getParamA("Server", "Connection") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
476 |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
477 if not user or not password or not server: |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
478 info ('No user or server given') |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
479 #TODO: a proper error message must be sent to frontend |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
480 self.actionResult(id, "ERROR", {'message':"No user, password or server given, can't register new account."}) |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
481 return |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
482 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
483 confirm_id = sat_next_id() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
484 self.__private_data[confirm_id]=id |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
485 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
486 self.askConfirmation(confirm_id, "YES/NO", |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
487 {"message":"Are you sure to register new account [%s] to server %s ?" % (user, server)}, |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
488 self.regisConfirmCB) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
489 print ("===============+++++++++++ REGISTER NEW ACCOUNT++++++++++++++============") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
490 print "id=",id |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
491 print "data=",data |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
492 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
493 def regisConfirmCB(self, id, accepted, data): |
64 | 494 #FIXME: gof: profile not managed here ! |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
495 print "register Confirmation CB ! (%s)" % str(accepted) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
496 action_id = self.__private_data[id] |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
497 del self.__private_data[id] |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
498 user = jid.parse(self.memory.getParamA("JabberID", "Connection"))[0] |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
499 password = self.memory.getParamA("Password", "Connection") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
500 server = self.memory.getParamA("Server", "Connection") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
501 if accepted: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
502 self.registerNewAccount(user, password, server, id=action_id) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
503 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
504 self.actionResult(action_id, "SUPPRESS", {}) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
505 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
506 def submitForm(self, action, target, fields, profile_key='@DEFAULT@'): |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
507 """submit a form |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
508 @param target: target jid where we are submitting |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
509 @param fields: list of tuples (name, value) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
510 @return: tuple: (id, deferred) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
511 """ |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
512 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
513 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
514 assert(profile) |
36 | 515 to_jid = jid.JID(target) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
516 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
517 iq = compat.IQ(self.profiles[profile].xmlstream, 'set') |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
518 iq["to"] = target |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
519 iq["from"] = self.profiles[profile].jid.full() |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
520 query = iq.addElement(('jabber:iq:register', 'query')) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
521 if action=='SUBMIT': |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
522 form = XMLTools.tupleList2dataForm(fields) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
523 query.addChild(form.toElement()) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
524 elif action=='CANCEL': |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
525 query.addElement('remove') |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
526 else: |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
527 error ("FIXME FIXME FIXME: Unmanaged action (%s) in submitForm" % action) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
528 raise NotImplementedError |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
529 |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
530 deferred = iq.send(target) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
531 return (iq['id'], deferred) |
36 | 532 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
533 ## Client management ## |
0 | 534 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
535 def setParam(self, name, value, category, profile_key='@DEFAULT@'): |
0 | 536 """set wanted paramater and notice observers""" |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
537 info ("setting param: %s=%s in category %s", name, value, category) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
538 self.memory.setParam(name, value, category, profile_key) |
0 | 539 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
540 def isConnected(self, profile_key='@DEFAULT@'): |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
541 """Return connection status of profile |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
542 @param profile_key: key_word or profile name to determine profile name |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
543 @return True if connected |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
544 """ |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
545 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
546 if not profile: |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
547 error ('asking connection status for a non-existant profile') |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
548 raise Exception #TODO: raise a proper exception |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
549 if not self.profiles.has_key(profile): |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
550 return False |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
551 return self.profiles[profile].isConnected() |
0 | 552 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
553 def launchAction(self, type, data): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
554 """Launch a specific action asked by client |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
555 @param type: action type (button) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
556 @param data: needed data to launch the action |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
557 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
558 @return: action id for result, or empty string in case or error |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
559 """ |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
560 if type=="button": |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
561 try: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
562 cb_name = self.memory.getParamA(data["name"], data["category"], "callback") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
563 except KeyError: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
564 error ("Incomplete data") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
565 return "" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
566 id = sat_next_id() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
567 self.callGeneralCB(cb_name, id, data) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
568 return id |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
569 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
570 error ("Unknown action type") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
571 return "" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
572 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
573 |
0 | 574 ## jabber methods ## |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
575 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
576 def sendMessage(self,to,msg,type='chat', profile_key='@DEFAULT@'): |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
577 print "sendtype=", type #gof |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
578 #FIXME: check validity of recipient |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
579 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
580 assert(profile) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
581 current_jid = self.profiles[profile].jid |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
582 debug("Sending jabber message to %s...", to) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
583 message = domish.Element(('jabber:client','message')) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
584 message["to"] = jid.JID(to).full() |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
585 message["from"] = current_jid.full() |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
586 message["type"] = type |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
587 message.addElement("body", "jabber:client", msg) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
588 self.profiles[profile].xmlstream.send(message) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
589 self.memory.addToHistory(current_jid, current_jid, jid.JID(to), message["type"], unicode(msg)) |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
590 self.bridge.newMessage(message['from'], unicode(msg), to=message['to'], type=type, profile=profile) #We send back the message, so all clients are aware of it |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
591 |
0 | 592 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
593 def setPresence(self, to="", show="", priority = 0, statuses={}, profile_key='@DEFAULT@'): |
0 | 594 """Send our presence information""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
595 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
596 assert(profile) |
50 | 597 to_jid = jid.JID(to) if to else None |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
598 self.profiles[profile].presence.available(to_jid, show, statuses, priority) |
50 | 599 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
600 def subscription(self, type, raw_jid, profile_key='@DEFAULT@'): |
50 | 601 """Called to manage subscription""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
602 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
603 assert(profile) |
50 | 604 to_jid = jid.JID(raw_jid) |
605 debug ('subsciption request [%s] for %s', type, to_jid.full()) | |
606 if type=="subscribe": | |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
607 self.profiles[profile].presence.subscribe(to_jid) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
608 elif type=="subscribed": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
609 self.profiles[profile].subscribed(to_jid) |
50 | 610 contact = self.memory.getContact(to_jid) |
611 if not contact or not bool(contact['to']): #we automatically subscribe to 'to' presence | |
612 debug('sending automatic "to" subscription request') | |
613 self.subscription('subscribe', to_jid.userhost()) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
614 elif type=="unsubscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
615 self.profiles[profile].presence.unsubscribe(to_jid) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
616 elif type=="unsubscribed": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
617 self.profiles[profile].presence.unsubscribed(to_jid) |
0 | 618 |
619 | |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
620 def addContact(self, to, profile_key='@DEFAULT@'): |
0 | 621 """Add a contact in roster list""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
622 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
623 assert(profile) |
0 | 624 to_jid=jid.JID(to) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
625 self.profiles[profile].roster.addItem(to_jid) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
626 self.profiles[profile].presence.subscribe(to_jid) |
0 | 627 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
628 def delContact(self, to, profile_key='@DEFAULT@'): |
0 | 629 """Remove contact from roster list""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
630 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
631 assert(profile) |
0 | 632 to_jid=jid.JID(to) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
633 self.profiles[profile].roster.removeItem(to_jid) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
634 self.profiles[profile].presence.unsubscribe(to_jid) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
635 self.host.bridge.contactDeleted(to, profile) |
0 | 636 |
637 | |
638 ## callbacks ## | |
639 | |
640 def serverDisco(self, disco): | |
641 """xep-0030 Discovery Protocol.""" | |
14 | 642 for feature in disco.features: |
643 debug ("Feature found: %s",feature) | |
644 self.server_features.append(feature) | |
645 for cat, type in disco.identities: | |
646 debug ("Identity found: [%s/%s] %s" % (cat, type, disco.identities[(cat,type)])) | |
0 | 647 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
648 |
0 | 649 ## Generic HMI ## |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
650 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
651 def actionResult(self, id, type, data): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
652 """Send the result of an action |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
653 @param id: same id used with action |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
654 @param type: result type ("PARAM", "SUCCESS", "ERROR", "FORM") |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
655 @param data: dictionary |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
656 """ |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
657 self.bridge.actionResult(type, id, data) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
658 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
659 def actionResultExt(self, id, type, data): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
660 """Send the result of an action, extended version |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
661 @param id: same id used with action |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
662 @param type: result type /!\ only "DICT_DICT" for this method |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
663 @param data: dictionary of dictionaries |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
664 """ |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
665 if type != "DICT_DICT": |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
666 error("type for actionResultExt must be DICT_DICT, fixing it") |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
667 type = "DICT_DICT" |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
668 self.bridge.actionResultExt(type, id, data) |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
669 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
670 |
0 | 671 |
672 def askConfirmation(self, id, type, data, cb): | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
673 """Add a confirmation callback |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
674 @param id: id used to get answer |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
675 @param type: confirmation type ("YES/NO", "FILE_TRANSFERT") |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
676 @param data: data (depend of confirmation type) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
677 @param cb: callback called with the answer |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
678 """ |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
679 if self.__waiting_conf.has_key(id): |
0 | 680 error ("Attempt to register two callbacks for the same confirmation") |
681 else: | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
682 self.__waiting_conf[id] = cb |
0 | 683 self.bridge.askConfirmation(type, id, data) |
684 | |
685 | |
686 def confirmationAnswer(self, id, accepted, data): | |
687 """Called by frontends to answer confirmation requests""" | |
688 debug ("Received confirmation answer for id [%s]: %s", id, "accepted" if accepted else "refused") | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
689 if not self.__waiting_conf.has_key(id): |
0 | 690 error ("Received an unknown confirmation") |
691 else: | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
692 cb = self.__waiting_conf[id] |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
693 del self.__waiting_conf[id] |
0 | 694 cb(id, accepted, data) |
695 | |
696 def registerProgressCB(self, id, CB): | |
697 """Register a callback called when progress is requested for id""" | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
698 self.__progress_cb_map[id] = CB |
0 | 699 |
700 def removeProgressCB(self, id): | |
701 """Remove a progress callback""" | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
702 if not self.__progress_cb_map.has_key(id): |
0 | 703 error ("Trying to remove an unknow progress callback") |
704 else: | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
705 del self.__progress_cb_map[id] |
0 | 706 |
707 def getProgress(self, id): | |
708 """Return a dict with progress information | |
709 data['position'] : current possition | |
710 data['size'] : end_position | |
711 """ | |
712 data = {} | |
713 try: | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
714 self.__progress_cb_map[id](data) |
0 | 715 except KeyError: |
716 pass | |
717 #debug("Requested progress for unknown id") | |
718 return data | |
719 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
720 def registerGeneralCB(self, name, CB): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
721 """Register a callback called for general reason""" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
722 self.__general_cb_map[name] = CB |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
723 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
724 def removeGeneralCB(self, name): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
725 """Remove a general callback""" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
726 if not self.__general_cb_map.has_key(name): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
727 error ("Trying to remove an unknow general callback") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
728 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
729 del self.__general_cb_map[name] |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
730 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
731 def callGeneralCB(self, name, *args, **kwargs): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
732 """Call general function back""" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
733 try: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
734 return self.__general_cb_map[name](*args, **kwargs) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
735 except KeyError: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
736 error("Trying to call unknown function") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
737 return None |
0 | 738 |
2
c49345fd7737
refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
739 application = service.Application('SàT') |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
740 service = SAT() |
2
c49345fd7737
refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
741 service.setServiceParent(application) |