Mercurial > libervia-backend
annotate sat.tac @ 58:d660d1e5cee4 0.0.2 SàT v0.0.2
updates for 0.0.2 release
- CHANGELOG is updated
- version changed in SàT
- launching script launch SàT as a daemon
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 10 Jan 2010 18:34:31 +1100 |
parents | a5b5fb5fc9fd |
children | 9764e027ecc0 |
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)', |
58 | 24 'client_version' : u'0.0.2', #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 |
52 | 73 def __init__(self, bridge, 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 |
52 | 77 self.bridge = bridge |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
78 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
79 def _authd(self, xmlstream): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
80 print "SatXMPPClient" |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
81 client.XMPPClient._authd(self, xmlstream) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
82 self.__connected=True |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
83 print "********** CONNECTED **********" |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
84 self.streamInitialized() |
52 | 85 self.bridge.connected() #we send the signal to the clients |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
86 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
87 def streamInitialized(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
88 """Called after _authd""" |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
89 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
|
90 self.keep_alife.start(180) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
91 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
92 def isConnected(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
93 return self.__connected |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
94 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
95 def connectionLost(self, connector, unused_reason): |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
96 self.__connected=False |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
97 print "********** DISCONNECTED **********" |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
98 try: |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
99 self.keep_alife.stop() |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
100 except AttributeError: |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
101 debug("No keep_alife") |
52 | 102 self.bridge.disconnected() #we send the signal to the clients |
0 | 103 |
104 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
105 class SatMessageProtocol(xmppim.MessageProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
106 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
107 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
108 xmppim.MessageProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
109 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
110 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
111 def onMessage(self, message): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
112 debug (u"got_message from: %s", message["from"]) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
113 for e in message.elements(): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
114 if e.name == "body": |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
115 self.host.bridge.newMessage(message["from"], e.children[0]) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
116 self.host.memory.addToHistory(self.host.me, jid.JID(message["from"]), self.host.me, "chat", e.children[0]) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
117 break |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
118 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
119 class SatRosterProtocol(xmppim.RosterClientProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
120 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
121 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
122 xmppim.RosterClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
123 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
124 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
125 def rosterCb(self, roster): |
50 | 126 for raw_jid, item in roster.iteritems(): |
127 self.onRosterSet(item) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
128 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
129 def requestRoster(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
130 """ ask the server for Roster list """ |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
131 debug("requestRoster") |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
132 self.getRoster().addCallback(self.rosterCb) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
133 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
134 def removeItem(self, to): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
135 """Remove a contact from roster list""" |
50 | 136 xmppim.RosterClientProtocol.removeItem(self, to) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
137 #TODO: check IQ result |
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 addItem(self, to): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
140 """Add a contact to roster list""" |
50 | 141 xmppim.RosterClientProtocol.addItem(self, to) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
142 #TODO: check IQ result |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
143 |
50 | 144 def onRosterSet(self, item): |
145 """Called when a new/update roster item is received""" | |
146 #TODO: send a signal to frontends | |
147 item_attr = {'to': str(item.subscriptionTo), | |
148 'from': str(item.subscriptionFrom), | |
149 'ask': str(item.ask) | |
150 } | |
151 if item.name: | |
152 item_attr['name'] = item.name | |
153 info ("new contact in roster list: %s", item.jid.full()) | |
154 self.host.memory.addContact(item.jid, item_attr, item.groups) | |
155 self.host.bridge.newContact(item.jid.full(), item_attr, item.groups) | |
156 | |
157 def onRosterRemove(self, entity): | |
158 """Called when a roster removal event is received""" | |
159 #TODO: send a signal to frontends | |
160 print "removing %s from roster list" % entity.full() | |
161 self.host.memory.delContact(entity) | |
162 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
163 class SatPresenceProtocol(xmppim.PresenceClientProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
164 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
165 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
166 xmppim.PresenceClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
167 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
168 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
169 def availableReceived(self, entity, show=None, statuses=None, priority=0): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
170 info ("presence update for [%s]", entity) |
50 | 171 |
172 if statuses.has_key(None): #we only want string keys | |
173 statuses["default"] = statuses[None] | |
174 del statuses[None] | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
175 |
50 | 176 self.host.memory.addPresenceStatus(entity, show or "", |
177 int(priority), statuses) | |
13
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 #now it's time to notify frontends |
50 | 180 self.host.bridge.presenceUpdate(entity.full(), show or "", |
181 int(priority), statuses) | |
13
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 unavailableReceived(self, entity, statuses=None): |
50 | 184 if statuses and statuses.has_key(None): #we only want string keys |
185 statuses["default"] = statuses[None] | |
186 del statuses[None] | |
187 self.host.memory.addPresenceStatus(entity, "unavailable", 0, statuses) | |
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 #now it's time to notify frontends |
50 | 190 self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
191 |
50 | 192 |
193 def available(self, entity=None, show=None, statuses=None, priority=0): | |
194 if statuses and statuses.has_key('default'): | |
195 statuses[None] = statuses['default'] | |
196 del statuses['default'] | |
197 xmppim.PresenceClientProtocol.available(self, entity, show, statuses, priority) | |
198 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
199 def subscribedReceived(self, entity): |
50 | 200 debug ("subscription approved for [%s]" % entity.userhost()) |
201 self.host.memory.delWaitingSub(entity.userhost()) | |
202 self.host.bridge.subscribe('subscribed', entity.userhost()) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
203 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
204 def unsubscribedReceived(self, entity): |
50 | 205 debug ("unsubscription confirmed for [%s]" % entity.userhost()) |
206 self.host.memory.delWaitingSub(entity.userhost()) | |
207 self.host.bridge.subscribe('unsubscribed', entity.userhost()) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
208 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
209 def subscribeReceived(self, entity): |
50 | 210 debug ("subscription request for [%s]" % entity.userhost()) |
211 self.host.memory.addWaitingSub('subscribe', entity.userhost()) | |
212 self.host.bridge.subscribe('subscribe', entity.userhost()) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
213 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
214 def unsubscribeReceived(self, entity): |
50 | 215 debug ("unsubscription asked for [%s]" % entity.userhost()) |
216 self.host.memory.addWaitingSub('unsubscribe', entity.userhost()) | |
217 self.host.bridge.subscribe('unsubscribe', entity.userhost()) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
218 |
14 | 219 class SatDiscoProtocol(disco.DiscoClientProtocol): |
220 def __init__(self, host): | |
221 disco.DiscoClientProtocol.__init__(self) | |
222 | |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
223 class SatFallbackHandler(generic.FallbackHandler): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
224 def __init__(self, host): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
225 generic.FallbackHandler.__init__(self) |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
226 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
227 def iqFallback(self, iq): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
228 #pdb.set_trace() |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
229 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
|
230 generic.FallbackHandler.iqFallback(self, iq) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
231 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
232 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
233 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
234 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
|
235 xmlstream.ConnectAuthenticator.__init__(self, jabber_host) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
236 self.host = host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
237 self.jabber_host = jabber_host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
238 self.user_login = user_login |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
239 self.user_pass = user_pass |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
240 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
|
241 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
|
242 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
243 def connectionMade(self): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
244 print "connectionMade" |
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 self.xmlstream.namespace = "jabber:client" |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
247 self.xmlstream.sendHeader() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
248 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
249 iq = compat.IQ(self.xmlstream, 'set') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
250 iq["to"] = self.jabber_host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
251 query = iq.addElement(('jabber:iq:register', 'query')) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
252 _user = query.addElement('username') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
253 _user.addContent(self.user_login) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
254 _pass = query.addElement('password') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
255 _pass.addContent(self.user_pass) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
256 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
|
257 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
258 def registrationAnswer(self, answer): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
259 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
|
260 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
|
261 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
|
262 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
|
263 self.xmlstream.sendFooter() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
264 |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
265 def registrationFailure(self, failure): |
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
266 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
|
267 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
|
268 answer_data = {} |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
269 if failure.value.condition == 'conflict': |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
270 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
|
271 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
|
272 else: |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
273 answer_data['reason'] = 'unknown' |
50 | 274 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
|
275 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
|
276 self.xmlstream.sendFooter() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
277 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
278 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
279 class SAT(service.Service): |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
280 |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
281 def get_next_id(self): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
282 return sat_next_id() |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
283 |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
284 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
|
285 """Return a constant""" |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
286 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
|
287 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
|
288 raise Exception |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
289 return CONST[name] |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
290 |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
291 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
|
292 """Save a constant""" |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
293 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
|
294 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
|
295 raise Exception |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
296 CONST[name] = value |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
297 |
0 | 298 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
|
299 #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
|
300 |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
301 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
|
302 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
|
303 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
|
304 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
305 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
|
306 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
|
307 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
|
308 self.__private_data = {} #used for internal callbacks (key = id) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
309 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
|
310 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
311 self.memory=Memory(self) |
0 | 312 self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future |
313 | |
314 self.bridge=DBusBridge() | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
315 self.bridge.register("registerNewAccount", self.registerNewAccount) |
0 | 316 self.bridge.register("connect", self.connect) |
1 | 317 self.bridge.register("disconnect", self.disconnect) |
0 | 318 self.bridge.register("getContacts", self.memory.getContacts) |
319 self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus) | |
50 | 320 self.bridge.register("getWaitingSub", self.memory.getWaitingSub) |
0 | 321 self.bridge.register("sendMessage", self.sendMessage) |
322 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
|
323 self.bridge.register("getParamA", self.memory.getParamA) |
0 | 324 self.bridge.register("getParams", self.memory.getParams) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
325 self.bridge.register("getParamsForCategory", self.memory.getParamsForCategory) |
0 | 326 self.bridge.register("getParamsCategories", self.memory.getParamsCategories) |
327 self.bridge.register("getHistory", self.memory.getHistory) | |
328 self.bridge.register("setPresence", self.setPresence) | |
50 | 329 self.bridge.register("subscription", self.subscription) |
0 | 330 self.bridge.register("addContact", self.addContact) |
331 self.bridge.register("delContact", self.delContact) | |
332 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
|
333 self.bridge.register("launchAction", self.launchAction) |
0 | 334 self.bridge.register("confirmationAnswer", self.confirmationAnswer) |
335 self.bridge.register("getProgress", self.getProgress) | |
336 | |
337 self._import_plugins() | |
338 | |
339 | |
340 def _import_plugins(self): | |
341 """Import all plugins found in plugins directory""" | |
342 #TODO: manage dependencies | |
343 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename,glob ("plugins/plugin*.py"))] | |
344 | |
345 for plug in plug_lst: | |
346 plug_path = 'plugins.'+plug | |
347 __import__(plug_path) | |
348 mod = sys.modules[plug_path] | |
349 plug_info = mod.PLUGIN_INFO | |
350 info ("importing plugin: %s", plug_info['name']) | |
351 self.plugins[plug_info['import_name']] = getattr(mod, plug_info['main'])(self) | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
352 #TODO: test xmppclient presence and register handler parent |
0 | 353 |
354 def connect(self): | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
355 """Connect to jabber server""" |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
356 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
357 if (self.isConnected()): |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
358 info("already connected !") |
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
359 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
|
360 print "connecting..." |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
361 self.me = jid.JID(self.memory.getParamA("JabberID", "Connection")) |
52 | 362 self.xmppclient = SatXMPPClient(self.bridge, self.me, 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
|
363 self.memory.getParamA("Server", "Connection"), 5222) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
364 self.xmppclient.streamInitialized = self.streamInitialized |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
365 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
366 self.messageProt = SatMessageProtocol(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
367 self.messageProt.setHandlerParent(self.xmppclient) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
368 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
369 self.roster = SatRosterProtocol(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
370 self.roster.setHandlerParent(self.xmppclient) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
371 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
372 self.presence = SatPresenceProtocol(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
373 self.presence.setHandlerParent(self.xmppclient) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
374 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
375 self.fallBack = SatFallbackHandler(self) |
14 | 376 self.fallBack.setHandlerParent(self.xmppclient) |
377 | |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
378 self.versionHandler = generic.VersionHandler(self.get_const('client_name'), |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
379 self.get_const('client_version')) |
14 | 380 self.versionHandler.setHandlerParent(self.xmppclient) |
381 | |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
382 debug ("setting plugins parents") |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
383 for plugin in self.plugins.iteritems(): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
384 if isinstance(plugin[1], XMPPHandler): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
385 plugin[1].setHandlerParent(self.xmppclient) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
386 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
387 self.xmppclient.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
|
388 |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
389 def disconnect(self): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
390 """disconnect from jabber server""" |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
391 if (not self.isConnected()): |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
392 info("not connected !") |
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
393 return |
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
394 info("Disconnecting...") |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
395 self.xmppclient.stopService() |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
396 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
397 def startService(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
398 info("Salut à toi ô mon frère !") |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
399 self.connect() |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
400 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
401 def stopService(self): |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
402 self.memory.save() |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
403 info("Salut aussi à Rantanplan") |
0 | 404 |
405 def run(self): | |
406 debug("running app") | |
407 reactor.run() | |
408 | |
409 def stop(self): | |
410 debug("stopping app") | |
411 reactor.stop() | |
412 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
413 def streamInitialized(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
414 """Called when xmlstream is OK""" |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
415 SatXMPPClient.streamInitialized(self.xmppclient) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
416 debug ("XML stream is initialized") |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
417 self.xmlstream = self.xmppclient.xmlstream |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
418 self.me = self.xmppclient.jid #in case of the ressource has changed |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
419 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
420 self.disco = SatDiscoProtocol(self) |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
421 self.disco.setHandlerParent(self.xmppclient) |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
422 self.discoHandler = disco.DiscoHandler() |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
423 self.discoHandler.setHandlerParent(self.xmppclient) |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
424 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
425 self.roster.requestRoster() |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
426 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
427 self.presence.available() |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
428 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
429 self.disco.requestInfo(jid.JID(self.memory.getParamA("Server", "Connection"))).addCallback(self.serverDisco) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
430 |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
431 ## Misc methods ## |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
432 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
433 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
|
434 """Connect to a server and create a new account using in-band registration""" |
0 | 435 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
436 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
|
437 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
|
438 connector = reactor.connectTCP(server, port, serverRegistrer) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
439 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
440 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
441 return next_id |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
442 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
443 def registerNewAccountCB(self, 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
|
444 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
|
445 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
|
446 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
|
447 |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
448 if not user or not password or not server: |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
449 info ('No user or server given') |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
450 #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
|
451 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
|
452 return |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
453 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
454 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
|
455 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
|
456 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
457 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
|
458 {"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
|
459 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
|
460 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
|
461 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
|
462 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
|
463 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
464 def regisConfirmCB(self, id, accepted, data): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
465 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
|
466 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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
474 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
|
475 |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
476 def submitForm(self, action, target, fields): |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
477 """submit a form |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
478 @param target: target jid where we are submitting |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
479 @param fields: list of tuples (name, value) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
480 @return: tuple: (id, deferred) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
481 """ |
36 | 482 to_jid = jid.JID(target) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
483 |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
484 iq = compat.IQ(self.xmlstream, 'set') |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
485 iq["to"] = target |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
486 iq["from"] = self.me.full() |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
487 query = iq.addElement(('jabber:iq:register', 'query')) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
488 if action=='SUBMIT': |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
489 form = XMLTools.tupleList2dataForm(fields) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
490 query.addChild(form.toElement()) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
491 elif action=='CANCEL': |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
492 query.addElement('remove') |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
493 else: |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
494 error ("FIXME FIXME FIXME: Unmanaged action (%s) in submitForm" % action) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
495 raise NotImplementedError |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
496 |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
497 deferred = iq.send(target) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
498 return (iq['id'], deferred) |
36 | 499 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
500 ## Client management ## |
0 | 501 |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
502 def setParam(self, name, value, category): |
0 | 503 """set wanted paramater and notice observers""" |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
504 info ("setting param: %s=%s in category %s", name, value, category) |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
505 self.memory.setParam(name, value, category) |
0 | 506 |
507 def failed(self,xmlstream): | |
508 debug("failed: %s", xmlstream.getErrorMessage()) | |
509 debug("failed: %s", dir(xmlstream)) | |
510 | |
511 def isConnected(self): | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
512 try: |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
513 if self.xmppclient.isConnected(): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
514 return True |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
515 except AttributeError: |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
516 #xmppclient not available |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
517 pass |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
518 return False |
0 | 519 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
520 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
|
521 """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
|
522 @param type: action type (button) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
523 @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
|
524 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
525 @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
|
526 """ |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
527 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
|
528 try: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
529 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
|
530 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
|
531 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
|
532 return "" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
533 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
|
534 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
|
535 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
|
536 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
537 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
|
538 return "" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
539 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
540 |
0 | 541 ## jabber methods ## |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
542 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
543 def sendMessage(self,to,msg,type='chat'): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
544 #FIXME: check validity of recipient |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
545 debug("Sending jabber message to %s...", to) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
546 message = domish.Element(('jabber:client','message')) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
547 message["to"] = jid.JID(to).full() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
548 message["from"] = self.me.full() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
549 message["type"] = type |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
550 message.addElement("body", "jabber:client", msg) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
551 self.xmlstream.send(message) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
552 self.memory.addToHistory(self.me, self.me, jid.JID(to), message["type"], unicode(msg)) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
553 self.bridge.newMessage(message['from'], unicode(msg), to=message['to']) #We send back the message, so all clients are aware of it |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
554 |
0 | 555 |
50 | 556 def setPresence(self, to="", show="", priority = 0, statuses={}): |
0 | 557 """Send our presence information""" |
50 | 558 to_jid = jid.JID(to) if to else None |
559 self.presence.available(to_jid, show, statuses, priority) | |
560 | |
561 def subscription(self, type, raw_jid): | |
562 """Called to manage subscription""" | |
563 to_jid = jid.JID(raw_jid) | |
564 debug ('subsciption request [%s] for %s', type, to_jid.full()) | |
565 if type=="subscribe": | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
566 self.presence.subscribe(to_jid) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
567 elif type=="subscribed": |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
568 self.presence.subscribed(to_jid) |
50 | 569 contact = self.memory.getContact(to_jid) |
570 if not contact or not bool(contact['to']): #we automatically subscribe to 'to' presence | |
571 debug('sending automatic "to" subscription request') | |
572 self.subscription('subscribe', to_jid.userhost()) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
573 elif type=="unsubscribe": |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
574 self.presence.unsubscribe(to_jid) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
575 elif type=="unsubscribed": |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
576 self.presence.unsubscribed(to_jid) |
0 | 577 |
578 | |
579 def addContact(self, to): | |
580 """Add a contact in roster list""" | |
581 to_jid=jid.JID(to) | |
50 | 582 self.roster.addItem(to_jid) |
583 self.presence.subscribe(to_jid) | |
0 | 584 |
585 def delContact(self, to): | |
586 """Remove contact from roster list""" | |
587 to_jid=jid.JID(to) | |
50 | 588 self.roster.removeItem(to_jid) |
589 self.presence.unsubscribe(to_jid) | |
0 | 590 self.bridge.contactDeleted(to) |
591 | |
592 | |
593 ## callbacks ## | |
594 | |
595 def serverDisco(self, disco): | |
596 """xep-0030 Discovery Protocol.""" | |
14 | 597 for feature in disco.features: |
598 debug ("Feature found: %s",feature) | |
599 self.server_features.append(feature) | |
600 for cat, type in disco.identities: | |
601 debug ("Identity found: [%s/%s] %s" % (cat, type, disco.identities[(cat,type)])) | |
0 | 602 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
603 |
0 | 604 ## 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
|
605 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
606 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
|
607 """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
|
608 @param id: same id used with action |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
609 @param type: result type ("PARAM", "SUCCESS", "ERROR", "FORM") |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
610 @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
|
611 """ |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
612 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
|
613 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
614 def actionResultExt(self, id, type, data): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
615 """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
|
616 @param id: same id used with action |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
617 @param type: result type /!\ only "DICT_DICT" for this method |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
618 @param data: dictionary of dictionaries |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
619 """ |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
620 if type != "DICT_DICT": |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
621 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
|
622 type = "DICT_DICT" |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
623 self.bridge.actionResultExt(type, id, data) |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
624 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
625 |
0 | 626 |
627 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
|
628 """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
|
629 @param id: id used to get answer |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
630 @param type: confirmation type ("YES/NO", "FILE_TRANSFERT") |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
631 @param data: data (depend of confirmation type) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
632 @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
|
633 """ |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
634 if self.__waiting_conf.has_key(id): |
0 | 635 error ("Attempt to register two callbacks for the same confirmation") |
636 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
|
637 self.__waiting_conf[id] = cb |
0 | 638 self.bridge.askConfirmation(type, id, data) |
639 | |
640 | |
641 def confirmationAnswer(self, id, accepted, data): | |
642 """Called by frontends to answer confirmation requests""" | |
643 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
|
644 if not self.__waiting_conf.has_key(id): |
0 | 645 error ("Received an unknown confirmation") |
646 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
|
647 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
|
648 del self.__waiting_conf[id] |
0 | 649 cb(id, accepted, data) |
650 | |
651 def registerProgressCB(self, id, CB): | |
652 """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
|
653 self.__progress_cb_map[id] = CB |
0 | 654 |
655 def removeProgressCB(self, id): | |
656 """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
|
657 if not self.__progress_cb_map.has_key(id): |
0 | 658 error ("Trying to remove an unknow progress callback") |
659 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
|
660 del self.__progress_cb_map[id] |
0 | 661 |
662 def getProgress(self, id): | |
663 """Return a dict with progress information | |
664 data['position'] : current possition | |
665 data['size'] : end_position | |
666 """ | |
667 data = {} | |
668 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
|
669 self.__progress_cb_map[id](data) |
0 | 670 except KeyError: |
671 pass | |
672 #debug("Requested progress for unknown id") | |
673 return data | |
674 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
675 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
|
676 """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
|
677 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
|
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 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
|
680 """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
|
681 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
|
682 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
|
683 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
684 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
|
685 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
686 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
|
687 """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
|
688 try: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
689 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
|
690 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
|
691 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
|
692 return None |
0 | 693 |
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
|
694 application = service.Application('SàT') |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
695 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
|
696 service.setServiceParent(application) |