annotate sat.tac @ 20:fc8c202cda87

refactoring: using xml params part IV (default values) - File Transfert/IP is now set by default to the ip externally visible
author Goffi <goffi@goffi.org>
date Sun, 08 Nov 2009 00:11:00 +0100
parents 6928e3cb73a8
children bb72c29f3432
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 SAT: a jabber client
goffi@necton2
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
22 client_name = u'SàT (Salut à toi)'
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
23 client_version = '0.0.1D' #Please add 'D' at the end for dev versions
0
goffi@necton2
parents:
diff changeset
24
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
25 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
26 from twisted.internet import glib2reactor, protocol, task
0
goffi@necton2
parents:
diff changeset
27 glib2reactor.install()
goffi@necton2
parents:
diff changeset
28
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
29 from twisted.words.protocols.jabber import jid, xmlstream, error
0
goffi@necton2
parents:
diff changeset
30 from twisted.words.xish import domish
goffi@necton2
parents:
diff changeset
31
goffi@necton2
parents:
diff changeset
32 from twisted.internet import reactor
goffi@necton2
parents:
diff changeset
33 import pdb
goffi@necton2
parents:
diff changeset
34
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
35 from wokkel import client, disco, xmppim, generic, compat
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
36
0
goffi@necton2
parents:
diff changeset
37 from sat_bridge.DBus import DBusBridge
goffi@necton2
parents:
diff changeset
38 import logging
goffi@necton2
parents:
diff changeset
39 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
40
goffi@necton2
parents:
diff changeset
41 import signal, sys
goffi@necton2
parents:
diff changeset
42 import os.path
goffi@necton2
parents:
diff changeset
43
goffi@necton2
parents:
diff changeset
44 from tools.memory import Memory
goffi@necton2
parents:
diff changeset
45 from glob import glob
goffi@necton2
parents:
diff changeset
46
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
47 try:
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
48 from twisted.words.protocols.xmlstream import XMPPHandler
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
49 except ImportError:
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
50 from wokkel.subprotocols import XMPPHandler
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
51
0
goffi@necton2
parents:
diff changeset
52
goffi@necton2
parents:
diff changeset
53 ### logging configuration FIXME: put this elsewhere ###
goffi@necton2
parents:
diff changeset
54 logging.basicConfig(level=logging.DEBUG,
goffi@necton2
parents:
diff changeset
55 format='%(message)s')
goffi@necton2
parents:
diff changeset
56 ###
goffi@necton2
parents:
diff changeset
57
goffi@necton2
parents:
diff changeset
58
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
59 sat_id = 0
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
60
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
61 def sat_next_id():
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
62 global sat_id
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
63 sat_id+=1
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
64 return "sat_id_"+str(sat_id)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
65
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
66 class SatXMPPClient(client.XMPPClient):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
67
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
68 def __init__(self, jid, password, host=None, port=5222):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
69 client.XMPPClient.__init__(self, jid, password, host, port)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
70 self.factory.clientConnectionLost = self.connectionLost
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
71 self.__connected=False
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
72
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
73 def _authd(self, xmlstream):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
74 print "SatXMPPClient"
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
75 client.XMPPClient._authd(self, xmlstream)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
76 self.__connected=True
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
77 print "********** CONNECTED **********"
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
78 self.streamInitialized()
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 streamInitialized(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
81 """Called after _authd"""
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
82 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
83 self.keep_alife.start(180)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
84
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
85 def isConnected(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
86 return self.__connected
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
87
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
88 def connectionLost(self, connector, unused_reason):
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
89 self.__connected=False
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
90 print "********** DISCONNECTED **********"
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
91 try:
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
92 self.keep_alife.stop()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
93 except AttributeError:
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
94 debug("No keep_alife")
0
goffi@necton2
parents:
diff changeset
95
goffi@necton2
parents:
diff changeset
96
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
97 class SatMessageProtocol(xmppim.MessageProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
98
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
99 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
100 xmppim.MessageProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
101 self.host = host
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
102
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
103 def onMessage(self, message):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
104 debug (u"got_message from: %s", message["from"])
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
105 for e in message.elements():
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
106 if e.name == "body":
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
107 self.host.bridge.newMessage(message["from"], e.children[0])
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
108 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
109 break
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 class SatRosterProtocol(xmppim.RosterClientProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
112
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
113 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
114 xmppim.RosterClientProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
115 self.host = host
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
116
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
117 def rosterCb(self, roster):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
118 for jid, item in roster.iteritems():
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
119 info ("new contact in roster list: %s", jid)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
120 #FIXME: fill attributes
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
121 self.host.memory.addContact(jid, {}, item.groups)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
122 self.host.bridge.newContact(jid, {}, item.groups)
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 requestRoster(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
125 """ ask the server for Roster list """
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
126 debug("requestRoster")
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
127 self.getRoster().addCallback(self.rosterCb)
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 removeItem(self, to):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
130 """Remove a contact from roster list"""
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
131 to_jid=jid.JID(to)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
132 xmppim.RosterClientProtocol.removeItem(self, to_jid)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
133 #TODO: check IQ result
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 addItem(self, to):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
136 """Add a contact to roster list"""
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
137 to_jid=jid.JID(to)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
138 xmppim.RosterClientProtocol.addItem(self, to_jid)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
139 #TODO: check IQ result
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
140
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
141 class SatPresenceProtocol(xmppim.PresenceClientProtocol):
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 __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
144 xmppim.PresenceClientProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
145 self.host = host
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
146
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
147 def availableReceived(self, entity, show=None, statuses=None, priority=0):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
148 info ("presence update for [%s]", entity)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
149
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
150 ### we check if the status is not about subscription ###
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
151 #FIXME: type is not needed anymore
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
152 #TODO: management of differents statuses (differents languages)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
153 status = statuses.values()[0] if len(statuses) else ""
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
154 self.host.memory.addPresenceStatus(entity.full(), "", show or "",
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
155 status or "", int(priority))
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
156
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
157 #now it's time to notify frontends
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
158 self.host.bridge.presenceUpdate(entity.full(), "", show or "",
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
159 status or "", int(priority))
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
160
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
161 def unavailableReceived(self, entity, statuses=None):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
162 #TODO: management of differents statuses (differents languages)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
163 status = statuses.values()[0] if len(statuses) else ""
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
164 self.host.memory.addPresenceStatus(entity.full(), "unavailable", "",
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
165 status or "", 0)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
166
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
167 #now it's time to notify frontends
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
168 self.host.bridge.presenceUpdate(entity.full(), "unavailable", "",
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
169 status or "", 0)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
170
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
171
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
172 def subscribedReceived(self, entity):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
173 debug ("subscription approved for [%s]" % entity)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
174
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
175 def unsubscribedReceived(self, entity):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
176 debug ("unsubscription confirmed for [%s]" % entity)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
177
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
178 def subscribeReceived(self, entity):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
179 #FIXME: auto answer for subscribe request, must be checked !
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
180 debug ("subscription request for [%s]" % entity)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
181 self.subscribed(entity)
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 unsubscribeReceived(self, entity):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
184 debug ("unsubscription asked for [%s]" % entity)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
185
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
186 class SatDiscoProtocol(disco.DiscoClientProtocol):
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
187 def __init__(self, host):
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
188 disco.DiscoClientProtocol.__init__(self)
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
189
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
190 class SatFallbackHandler(generic.FallbackHandler):
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
191 def __init__(self, host):
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
192 generic.FallbackHandler.__init__(self)
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
193
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
194 def iqFallback(self, iq):
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
195 #pdb.set_trace()
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
196 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
197 generic.FallbackHandler.iqFallback(self, iq)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
198
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
199 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator):
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
200
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
201 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
202 xmlstream.ConnectAuthenticator.__init__(self, jabber_host)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
203 self.host = host
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
204 self.jabber_host = jabber_host
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
205 self.user_login = user_login
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
206 self.user_pass = user_pass
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
207 self.answer_id = answer_id
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
208
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
209 def connectionMade(self):
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
210 print "connectionMade"
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
211
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
212 self.xmlstream.namespace = "jabber:client"
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
213 self.xmlstream.sendHeader()
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
214
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
215 iq = compat.IQ(self.xmlstream, 'set')
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
216 iq["to"] = self.jabber_host
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
217 query = iq.addElement(('jabber:iq:register', 'query'))
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
218 _user = query.addElement('username')
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
219 _user.addContent(self.user_login)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
220 _pass = query.addElement('password')
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
221 _pass.addContent(self.user_pass)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
222 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
223
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
224 def registrationAnswer(self, answer):
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
225 debug ("registration answer: %s" % answer.toXml())
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
226 answer_type = "success"
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
227 answer_data={"human":"Registration successfull"}
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
228 self.host.bridge.sendAnswer(answer_type, self.answer_id, answer_data)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
229 self.xmlstream.sendFooter()
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
230
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
231 def registrationFailure(self, error):
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
232 info ("Registration failure: %s" %str(error))
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
233 answer_type = "error"
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
234 answer_data={"human":"Registration failed"}
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
235 if error.value.condition == 'conflict':
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
236 answer_data['reason'] = 'conflict'
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
237 else:
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
238 answer_data['reason'] = 'unknown'
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
239 self.host.bridge.sendAnswer(answer_type, self.answer_id, answer_data)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
240 self.xmlstream.sendFooter()
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
241
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
242
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
243 class SAT(service.Service):
0
goffi@necton2
parents:
diff changeset
244
goffi@necton2
parents:
diff changeset
245 def __init__(self):
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
246 #self.reactor=reactor
0
goffi@necton2
parents:
diff changeset
247 self.memory=Memory()
goffi@necton2
parents:
diff changeset
248 self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future
goffi@necton2
parents:
diff changeset
249
goffi@necton2
parents:
diff changeset
250 self._waiting_conf = {} #callback called when a confirmation is received
goffi@necton2
parents:
diff changeset
251 self._progress_cb_map = {} #callback called when a progress is requested (key = progress id)
goffi@necton2
parents:
diff changeset
252 self.plugins = {}
goffi@necton2
parents:
diff changeset
253
goffi@necton2
parents:
diff changeset
254 self.bridge=DBusBridge()
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
255 self.bridge.register("registerNewAccount", self.registerNewAccount)
0
goffi@necton2
parents:
diff changeset
256 self.bridge.register("connect", self.connect)
1
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
257 self.bridge.register("disconnect", self.disconnect)
0
goffi@necton2
parents:
diff changeset
258 self.bridge.register("getContacts", self.memory.getContacts)
goffi@necton2
parents:
diff changeset
259 self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus)
goffi@necton2
parents:
diff changeset
260 self.bridge.register("sendMessage", self.sendMessage)
goffi@necton2
parents:
diff changeset
261 self.bridge.register("setParam", self.setParam)
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
262 self.bridge.register("getParamV", self.memory.getParamV)
0
goffi@necton2
parents:
diff changeset
263 self.bridge.register("getParams", self.memory.getParams)
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
264 self.bridge.register("getParamsForCategory", self.memory.getParamsForCategory)
0
goffi@necton2
parents:
diff changeset
265 self.bridge.register("getParamsCategories", self.memory.getParamsCategories)
goffi@necton2
parents:
diff changeset
266 self.bridge.register("getHistory", self.memory.getHistory)
goffi@necton2
parents:
diff changeset
267 self.bridge.register("setPresence", self.setPresence)
goffi@necton2
parents:
diff changeset
268 self.bridge.register("addContact", self.addContact)
goffi@necton2
parents:
diff changeset
269 self.bridge.register("delContact", self.delContact)
goffi@necton2
parents:
diff changeset
270 self.bridge.register("isConnected", self.isConnected)
goffi@necton2
parents:
diff changeset
271 self.bridge.register("confirmationAnswer", self.confirmationAnswer)
goffi@necton2
parents:
diff changeset
272 self.bridge.register("getProgress", self.getProgress)
goffi@necton2
parents:
diff changeset
273
goffi@necton2
parents:
diff changeset
274 self._import_plugins()
goffi@necton2
parents:
diff changeset
275
goffi@necton2
parents:
diff changeset
276
goffi@necton2
parents:
diff changeset
277 def _import_plugins(self):
goffi@necton2
parents:
diff changeset
278 """Import all plugins found in plugins directory"""
goffi@necton2
parents:
diff changeset
279 #TODO: manage dependencies
goffi@necton2
parents:
diff changeset
280 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename,glob ("plugins/plugin*.py"))]
goffi@necton2
parents:
diff changeset
281
goffi@necton2
parents:
diff changeset
282 for plug in plug_lst:
goffi@necton2
parents:
diff changeset
283 plug_path = 'plugins.'+plug
goffi@necton2
parents:
diff changeset
284 __import__(plug_path)
goffi@necton2
parents:
diff changeset
285 mod = sys.modules[plug_path]
goffi@necton2
parents:
diff changeset
286 plug_info = mod.PLUGIN_INFO
goffi@necton2
parents:
diff changeset
287 info ("importing plugin: %s", plug_info['name'])
goffi@necton2
parents:
diff changeset
288 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
289 #TODO: test xmppclient presence and register handler parent
0
goffi@necton2
parents:
diff changeset
290
goffi@necton2
parents:
diff changeset
291 def connect(self):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
292 """Connect to jabber server"""
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
293
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
294 if (self.isConnected()):
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
295 info("already connected !")
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
296 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
297 print "connecting..."
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
298 self.me = jid.JID(self.memory.getParamV("JabberID", "Connection"))
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
299 self.xmppclient = SatXMPPClient(self.me, self.memory.getParamV("Password", "Connection"),
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
300 self.memory.getParamV("Server", "Connection"), 5222)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
301 self.xmppclient.streamInitialized = self.streamInitialized
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
302
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
303 self.messageProt = SatMessageProtocol(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
304 self.messageProt.setHandlerParent(self.xmppclient)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
305
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
306 self.roster = SatRosterProtocol(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
307 self.roster.setHandlerParent(self.xmppclient)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
308
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
309 self.presence = SatPresenceProtocol(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
310 self.presence.setHandlerParent(self.xmppclient)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
311
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
312 self.fallBack = SatFallbackHandler(self)
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
313 self.fallBack.setHandlerParent(self.xmppclient)
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
314
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
315 self.versionHandler = generic.VersionHandler(unicode(client_name), client_version)
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
316 self.versionHandler.setHandlerParent(self.xmppclient)
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
317
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
318 debug ("setting plugins parents")
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
319 for plugin in self.plugins.iteritems():
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
320 if isinstance(plugin[1], XMPPHandler):
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
321 plugin[1].setHandlerParent(self.xmppclient)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
322
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
323 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
324
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
325 def disconnect(self):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
326 """disconnect from jabber server"""
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
327 if (not self.isConnected()):
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
328 info("not connected !")
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
329 return
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
330 info("Disconnecting...")
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
331 self.xmppclient.stopService()
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
332
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
333 def startService(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
334 info("Salut à toi ô mon frère !")
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
335 self.connect()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
336
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
337 def stopService(self):
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
338 self.memory.save()
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
339 info("Salut aussi à Rantanplan")
0
goffi@necton2
parents:
diff changeset
340
goffi@necton2
parents:
diff changeset
341 def run(self):
goffi@necton2
parents:
diff changeset
342 debug("running app")
goffi@necton2
parents:
diff changeset
343 reactor.run()
goffi@necton2
parents:
diff changeset
344
goffi@necton2
parents:
diff changeset
345 def stop(self):
goffi@necton2
parents:
diff changeset
346 debug("stopping app")
goffi@necton2
parents:
diff changeset
347 reactor.stop()
goffi@necton2
parents:
diff changeset
348
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
349 def streamInitialized(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
350 """Called when xmlstream is OK"""
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
351 SatXMPPClient.streamInitialized(self.xmppclient)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
352 debug ("XML stream is initialized")
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
353 self.xmlstream = self.xmppclient.xmlstream
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
354 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
355
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
356 self.disco = SatDiscoProtocol(self)
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
357 self.disco.setHandlerParent(self.xmppclient)
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
358 self.discoHandler = disco.DiscoHandler()
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
359 self.discoHandler.setHandlerParent(self.xmppclient)
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
360
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
361 self.roster.requestRoster()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
362
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
363 self.presence.available()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
364
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
365 self.disco.requestInfo(jid.JID(self.memory.getParamV("Server", "Connection"))).addCallback(self.serverDisco)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
366
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
367 ## Misc methods ##
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
368
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
369 def registerNewAccount(self, login, password, server, port = 5222):
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
370 """Connect to a server and create a new account using in-band registration"""
0
goffi@necton2
parents:
diff changeset
371
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
372 next_id = sat_next_id() #the id is used to send server's answer
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
373 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
374 connector = reactor.connectTCP(server, port, serverRegistrer)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
375 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect()
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
376
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
377 return next_id
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
378
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
379 ## Client management ##
0
goffi@necton2
parents:
diff changeset
380
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
381 def setParam(self, name, value, category):
0
goffi@necton2
parents:
diff changeset
382 """set wanted paramater and notice observers"""
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
383 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
384 self.memory.setParam(name, value, category)
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
385 self.bridge.paramUpdate(name, value, category)
0
goffi@necton2
parents:
diff changeset
386
goffi@necton2
parents:
diff changeset
387 def failed(self,xmlstream):
goffi@necton2
parents:
diff changeset
388 debug("failed: %s", xmlstream.getErrorMessage())
goffi@necton2
parents:
diff changeset
389 debug("failed: %s", dir(xmlstream))
goffi@necton2
parents:
diff changeset
390
goffi@necton2
parents:
diff changeset
391 def isConnected(self):
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
392 try:
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
393 if self.xmppclient.isConnected():
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
394 return True
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
395 except AttributeError:
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
396 #xmppclient not available
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
397 pass
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
398 return False
0
goffi@necton2
parents:
diff changeset
399
goffi@necton2
parents:
diff changeset
400 ## jabber methods ##
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
401
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
402 def sendMessage(self,to,msg,type='chat'):
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
403 #FIXME: check validity of recipient
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
404 debug("Sending jabber message to %s...", to)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
405 message = domish.Element(('jabber:client','message'))
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
406 message["to"] = jid.JID(to).full()
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
407 message["from"] = self.me.full()
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
408 message["type"] = type
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
409 message.addElement("body", "jabber:client", msg)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
410 self.xmlstream.send(message)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
411 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
412 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
413
0
goffi@necton2
parents:
diff changeset
414
goffi@necton2
parents:
diff changeset
415 def setPresence(self, to="", type="", show="", status="", priority=0):
goffi@necton2
parents:
diff changeset
416 """Send our presence information"""
goffi@necton2
parents:
diff changeset
417 if not type in ["", "unavailable", "subscribed", "subscribe",
goffi@necton2
parents:
diff changeset
418 "unsubscribe", "unsubscribed", "prob", "error"]:
goffi@necton2
parents:
diff changeset
419 error("Type error !")
goffi@necton2
parents:
diff changeset
420 #TODO: throw an error
goffi@necton2
parents:
diff changeset
421 return
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
422 to_jid=jid.JID(to)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
423 #TODO: refactor subscription bridge API
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
424 if type=="":
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
425 self.presence.available(to_jid, show, status, priority)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
426 elif type=="subscribe":
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
427 self.presence.subscribe(to_jid)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
428 elif type=="subscribed":
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
429 self.presence.subscribed(to_jid)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
430 elif type=="unsubscribe":
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
431 self.presence.unsubscribe(to_jid)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
432 elif type=="unsubscribed":
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
433 self.presence.unsubscribed(to_jid)
0
goffi@necton2
parents:
diff changeset
434
goffi@necton2
parents:
diff changeset
435
goffi@necton2
parents:
diff changeset
436 def addContact(self, to):
goffi@necton2
parents:
diff changeset
437 """Add a contact in roster list"""
goffi@necton2
parents:
diff changeset
438 to_jid=jid.JID(to)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
439 self.roster.addItem(to_jid.userhost())
0
goffi@necton2
parents:
diff changeset
440 self.setPresence(to_jid.userhost(), "subscribe")
goffi@necton2
parents:
diff changeset
441
goffi@necton2
parents:
diff changeset
442 def delContact(self, to):
goffi@necton2
parents:
diff changeset
443 """Remove contact from roster list"""
goffi@necton2
parents:
diff changeset
444 to_jid=jid.JID(to)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
445 self.roster.removeItem(to_jid.userhost())
0
goffi@necton2
parents:
diff changeset
446 self.bridge.contactDeleted(to)
goffi@necton2
parents:
diff changeset
447
goffi@necton2
parents:
diff changeset
448
goffi@necton2
parents:
diff changeset
449 ## callbacks ##
goffi@necton2
parents:
diff changeset
450
goffi@necton2
parents:
diff changeset
451 def serverDisco(self, disco):
goffi@necton2
parents:
diff changeset
452 """xep-0030 Discovery Protocol."""
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
453 for feature in disco.features:
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
454 debug ("Feature found: %s",feature)
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
455 self.server_features.append(feature)
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
456 for cat, type in disco.identities:
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
457 debug ("Identity found: [%s/%s] %s" % (cat, type, disco.identities[(cat,type)]))
0
goffi@necton2
parents:
diff changeset
458
goffi@necton2
parents:
diff changeset
459 ## Generic HMI ##
goffi@necton2
parents:
diff changeset
460
goffi@necton2
parents:
diff changeset
461 def askConfirmation(self, id, type, data, cb):
goffi@necton2
parents:
diff changeset
462 """Add a confirmation callback"""
goffi@necton2
parents:
diff changeset
463 if self._waiting_conf.has_key(id):
goffi@necton2
parents:
diff changeset
464 error ("Attempt to register two callbacks for the same confirmation")
goffi@necton2
parents:
diff changeset
465 else:
goffi@necton2
parents:
diff changeset
466 self._waiting_conf[id] = cb
goffi@necton2
parents:
diff changeset
467 self.bridge.askConfirmation(type, id, data)
goffi@necton2
parents:
diff changeset
468
goffi@necton2
parents:
diff changeset
469
goffi@necton2
parents:
diff changeset
470 def confirmationAnswer(self, id, accepted, data):
goffi@necton2
parents:
diff changeset
471 """Called by frontends to answer confirmation requests"""
goffi@necton2
parents:
diff changeset
472 debug ("Received confirmation answer for id [%s]: %s", id, "accepted" if accepted else "refused")
goffi@necton2
parents:
diff changeset
473 if not self._waiting_conf.has_key(id):
goffi@necton2
parents:
diff changeset
474 error ("Received an unknown confirmation")
goffi@necton2
parents:
diff changeset
475 else:
goffi@necton2
parents:
diff changeset
476 cb = self._waiting_conf[id]
goffi@necton2
parents:
diff changeset
477 del self._waiting_conf[id]
goffi@necton2
parents:
diff changeset
478 cb(id, accepted, data)
goffi@necton2
parents:
diff changeset
479
goffi@necton2
parents:
diff changeset
480 def registerProgressCB(self, id, CB):
goffi@necton2
parents:
diff changeset
481 """Register a callback called when progress is requested for id"""
goffi@necton2
parents:
diff changeset
482 self._progress_cb_map[id] = CB
goffi@necton2
parents:
diff changeset
483
goffi@necton2
parents:
diff changeset
484 def removeProgressCB(self, id):
goffi@necton2
parents:
diff changeset
485 """Remove a progress callback"""
goffi@necton2
parents:
diff changeset
486 if not self._progress_cb_map.has_key(id):
goffi@necton2
parents:
diff changeset
487 error ("Trying to remove an unknow progress callback")
goffi@necton2
parents:
diff changeset
488 else:
goffi@necton2
parents:
diff changeset
489 del self._progress_cb_map[id]
goffi@necton2
parents:
diff changeset
490
goffi@necton2
parents:
diff changeset
491 def getProgress(self, id):
goffi@necton2
parents:
diff changeset
492 """Return a dict with progress information
goffi@necton2
parents:
diff changeset
493 data['position'] : current possition
goffi@necton2
parents:
diff changeset
494 data['size'] : end_position
goffi@necton2
parents:
diff changeset
495 """
goffi@necton2
parents:
diff changeset
496 data = {}
goffi@necton2
parents:
diff changeset
497 try:
goffi@necton2
parents:
diff changeset
498 self._progress_cb_map[id](data)
goffi@necton2
parents:
diff changeset
499 except KeyError:
goffi@necton2
parents:
diff changeset
500 pass
goffi@necton2
parents:
diff changeset
501 #debug("Requested progress for unknown id")
goffi@necton2
parents:
diff changeset
502 return data
goffi@necton2
parents:
diff changeset
503
goffi@necton2
parents:
diff changeset
504
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
505 application = service.Application('SàT')
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
506 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
507 service.setServiceParent(application)