annotate src/server/server.py @ 682:e6bb64bd6b4d

server side: implemented methods to get SàT and Libervia versions
author Goffi <goffi@goffi.org>
date Thu, 19 Mar 2015 20:41:14 +0100
parents a90cc8fc9605
children 9877607c719a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1 #!/usr/bin/python
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
2 # -*- coding: utf-8 -*-
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
4 # Libervia: a Salut à Toi frontend
340
ce5b33f499c5 dates update
Goffi <goffi@goffi.org>
parents: 339
diff changeset
5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org>
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
7 # This program is free software: you can redistribute it and/or modify
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
10 # (at your option) any later version.
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
12 # This program is distributed in the hope that it will be useful,
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
15 # GNU Affero General Public License for more details.
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
19
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
20 from twisted.application import service
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
21 from twisted.internet import reactor, defer
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
22 from twisted.web import server
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
23 from twisted.web.static import File
553
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
24 from twisted.web.resource import Resource, NoResource, EncodingResourceWrapper
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
25 from twisted.web.util import Redirect, redirectTo
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
26 from twisted.python.components import registerAdapter
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
27 from twisted.python.failure import Failure
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
28 from twisted.words.protocols.jabber.jid import JID
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
29
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
30 from txjsonrpc.web import jsonrpc
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
31 from txjsonrpc import jsonrpclib
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
32
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
33 from sat.core.log import getLogger
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
34 log = getLogger(__name__)
555
db1b330c1eb1 server_side: set the connection attempt timeout to the bridge timeout (2 minutes)
souliane <souliane@mailoo.org>
parents: 554
diff changeset
35 from sat_frontends.bridge.DBus import DBusBridgeFrontend, BridgeExceptionNoService, const_TIMEOUT as BRIDGE_TIMEOUT
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
36 from sat.core.i18n import _, D_
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
37 from sat.core import exceptions
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
38 from sat.tools.xml_tools import paramsXML2XMLUI
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
39 from sat.tools import utils
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
40
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
41 import re
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
42 import glob
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
43 import os.path
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
44 import sys
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
45 import tempfile
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
46 import shutil
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
47 import uuid
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
48 from zope.interface import Interface, Attribute, implements
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
49 from xml.dom import minidom
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
50 from httplib import HTTPS_PORT
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
51 import libervia
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
52
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
53 try:
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
54 import OpenSSL
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
55 from twisted.internet import ssl
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
56 ssl_available = True
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
57 except:
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
58 ssl_available = False
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
59
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
60 from libervia.server.constants import Const as C
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
61 from libervia.server.blog import MicroBlog
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
62
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
63
514
530c88c1deee server_side: plugin refactoring:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
64 # following value are set from twisted.plugins.libervia_server initialise (see the comment there)
530c88c1deee server_side: plugin refactoring:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
65 DATA_DIR_DEFAULT = OPT_PARAMETERS_BOTH = OPT_PARAMETERS_CFG = coerceDataDir = None
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
66 __version__ = C.APP_VERSION
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
67
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
68
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
69 class ISATSession(Interface):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
70 profile = Attribute("Sat profile")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
71 jid = Attribute("JID associated with the profile")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
72
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
73
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
74 class SATSession(object):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
75 implements(ISATSession)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
76
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
77 def __init__(self, session):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
78 self.profile = None
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
79 self.jid = None
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
80
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
81
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
82 class LiberviaSession(server.Session):
555
db1b330c1eb1 server_side: set the connection attempt timeout to the bridge timeout (2 minutes)
souliane <souliane@mailoo.org>
parents: 554
diff changeset
83 sessionTimeout = C.SESSION_TIMEOUT
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
84
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
85 def __init__(self, *args, **kwargs):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
86 self.__lock = False
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
87 server.Session.__init__(self, *args, **kwargs)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
88
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
89 def lock(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
90 """Prevent session from expiring"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
91 self.__lock = True
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
92 self._expireCall.reset(sys.maxint)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
93
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
94 def unlock(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
95 """Allow session to expire again, and touch it"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
96 self.__lock = False
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
97 self.touch()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
98
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
99 def touch(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
100 if not self.__lock:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
101 server.Session.touch(self)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
102
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
103
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
104 class ProtectedFile(File):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
105 """A File class which doens't show directory listing"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
106
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
107 def directoryListing(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
108 return NoResource()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
109
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
110
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
111 class SATActionIDHandler(object):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
112 """Manage SàT action action_id lifecycle"""
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
113 ID_LIFETIME = 30 # after this time (in seconds), action_id will be suppressed and action result will be ignored
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
114
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
115 def __init__(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
116 self.waiting_ids = {}
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
117
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
118 def waitForId(self, callback, action_id, profile, *args, **kwargs):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
119 """Wait for an action result
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
120
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
121 @param callback: method to call when action gave a result back
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
122 @param action_id: action_id to wait for
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
123 @param profile: %(doc_profile)s
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
124 @param *args: additional argument to pass to callback
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
125 @param **kwargs: idem
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
126 """
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
127 action_tuple = (action_id, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
128 self.waiting_ids[action_tuple] = (callback, args, kwargs)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
129 reactor.callLater(self.ID_LIFETIME, self.purgeID, action_tuple)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
130
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
131 def purgeID(self, action_tuple):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
132 """Called when an action_id has not be handled in time"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
133 if action_tuple in self.waiting_ids:
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
134 log.warning("action of action_id %s [%s] has not been managed, action_id is now ignored" % action_tuple)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
135 del self.waiting_ids[action_tuple]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
136
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
137 def actionResultCb(self, answer_type, action_id, data, profile):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
138 """Manage the actionResult signal"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
139 action_tuple = (action_id, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
140 if action_tuple in self.waiting_ids:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
141 callback, args, kwargs = self.waiting_ids[action_tuple]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
142 del self.waiting_ids[action_tuple]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
143 callback(answer_type, action_id, data, *args, **kwargs)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
144
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
145
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
146 class JSONRPCMethodManager(jsonrpc.JSONRPC):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
147
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
148 def __init__(self, sat_host):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
149 jsonrpc.JSONRPC.__init__(self)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
150 self.sat_host = sat_host
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
151
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
152 def asyncBridgeCall(self, method_name, *args, **kwargs):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
153 """Call an asynchrone bridge method and return a deferred
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
154 @param method_name: name of the method as a unicode
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
155 @return: a deferred which trigger the result
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
156
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
157 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
158 d = defer.Deferred()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
159
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
160 def _callback(*args):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
161 if not args:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
162 d.callback(None)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
163 else:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
164 if len(args) != 1:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
165 Exception("Multiple return arguments not supported")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
166 d.callback(args[0])
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
167
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
168 def _errback(result):
465
33ec27ef4b6a server side: adapt passing the async failure from server to browser side, according to the new class BridgeException
souliane <souliane@mailoo.org>
parents: 464
diff changeset
169 d.errback(Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, result.classname)))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
170
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
171 kwargs["callback"] = _callback
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
172 kwargs["errback"] = _errback
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
173 getattr(self.sat_host.bridge, method_name)(*args, **kwargs)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
174 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
175
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
176
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
177 class MethodHandler(JSONRPCMethodManager):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
178
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
179 def __init__(self, sat_host):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
180 JSONRPCMethodManager.__init__(self, sat_host)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
181 self.authorized_params = None
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
182
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
183 def render(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
184 self.session = request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
185 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
186 if not profile:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
187 #user is not identified, we return a jsonrpc fault
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
188 parsed = jsonrpclib.loads(request.content.read())
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
189 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia
482
437eefa53a01 misc: remove some pylint errors and warnings
souliane <souliane@mailoo.org>
parents: 481
diff changeset
190 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) # pylint: disable=E1103
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
191 return jsonrpc.JSONRPC.render(self, request)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
192
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
193 def jsonrpc_getVersion(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
194 """Return SàT version"""
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
195 try:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
196 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
197 except AttributeError:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
198 self._version_cache = self.sat_host.bridge.getVersion()
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
199 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
200
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
201 def jsonrpc_getLiberviaVersion(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
202 """Return Libervia version"""
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
203 return self.sat_host.full_version
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
204
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
205 def jsonrpc_disconnect(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
206 """Disconnect the profile"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
207 sat_session = ISATSession(self.session)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
208 profile = sat_session.profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
209 self.sat_host.bridge.disconnect(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
210
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
211 def jsonrpc_getContacts(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
212 """Return all passed args."""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
213 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
214 return self.sat_host.bridge.getContacts(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
215
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
216 def jsonrpc_addContact(self, entity, name, groups):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
217 """Subscribe to contact presence, and add it to the given groups"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
218 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
219 self.sat_host.bridge.addContact(entity, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
220 self.sat_host.bridge.updateContact(entity, name, groups, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
221
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
222 def jsonrpc_delContact(self, entity):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
223 """Remove contact from contacts list"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
224 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
225 self.sat_host.bridge.delContact(entity, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
226
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
227 def jsonrpc_updateContact(self, entity, name, groups):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
228 """Update contact's roster item"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
229 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
230 self.sat_host.bridge.updateContact(entity, name, groups, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
231
623
4f7550a083b4 server and browser sides: fixes bad call to "subscription" bridge method
souliane <souliane@mailoo.org>
parents: 613
diff changeset
232 def jsonrpc_subscription(self, sub_type, entity):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
233 """Confirm (or infirm) subscription,
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
234 and setup user roster in case of subscription"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
235 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
236 self.sat_host.bridge.subscription(sub_type, entity, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
237
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
238 def jsonrpc_getWaitingSub(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
239 """Return list of room already joined by user"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
240 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
241 return self.sat_host.bridge.getWaitingSub(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
242
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
243 def jsonrpc_getWaitingConf(self):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
244 """Return list of waiting confirmations"""
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
245 profile = ISATSession(self.session).profile
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
246 return self.sat_host.bridge.getWaitingConf(profile)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
247
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
248 def jsonrpc_setStatus(self, presence, status):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
249 """Change the presence and/or status
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
250 @param presence: value from ("", "chat", "away", "dnd", "xa")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
251 @param status: any string to describe your status
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
252 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
253 profile = ISATSession(self.session).profile
413
7a8991cda2fa browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents: 408
diff changeset
254 self.sat_host.bridge.setPresence('', presence, {'': status}, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
255
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
256 def jsonrpc_sendMessage(self, to_jid, msg, subject, type_, options={}):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
257 """send message"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
258 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
259 return self.asyncBridgeCall("sendMessage", to_jid, msg, subject, type_, options, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
260
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
261 def jsonrpc_sendMblog(self, type_, dest, text, extra={}):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
262 """ Send microblog message
653
e1d067378ad3 browser_side: fixes sending/updating blog message/comment
souliane <souliane@mailoo.org>
parents: 651
diff changeset
263 @param type_ (unicode): one of "PUBLIC", "GROUP"
e1d067378ad3 browser_side: fixes sending/updating blog message/comment
souliane <souliane@mailoo.org>
parents: 651
diff changeset
264 @param dest (tuple(unicode)): recipient groups (ignored for "PUBLIC")
e1d067378ad3 browser_side: fixes sending/updating blog message/comment
souliane <souliane@mailoo.org>
parents: 651
diff changeset
265 @param text (unicode): microblog's text
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
266 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
267 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
268 extra['allow_comments'] = 'True'
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
269
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
270 if not type_: # auto-detect
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
271 type_ = "PUBLIC" if dest == [] else "GROUP"
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
272
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
273 if type_ in ("PUBLIC", "GROUP") and text:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
274 if type_ == "PUBLIC":
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
275 #This text if for the public microblog
473
d1565906f228 server_side: fixed some forgotten print statement
Goffi <goffi@goffi.org>
parents: 472
diff changeset
276 log.debug("sending public blog")
653
e1d067378ad3 browser_side: fixes sending/updating blog message/comment
souliane <souliane@mailoo.org>
parents: 651
diff changeset
277 return self.sat_host.bridge.sendGroupBlog("PUBLIC", (), text, extra, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
278 else:
473
d1565906f228 server_side: fixed some forgotten print statement
Goffi <goffi@goffi.org>
parents: 472
diff changeset
279 log.debug("sending group blog")
380
5e0e2032928c browser_side: bug fixes microblogs:
souliane <souliane@mailoo.org>
parents: 374
diff changeset
280 dest = dest if isinstance(dest, list) else [dest]
5e0e2032928c browser_side: bug fixes microblogs:
souliane <souliane@mailoo.org>
parents: 374
diff changeset
281 return self.sat_host.bridge.sendGroupBlog("GROUP", dest, text, extra, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
282 else:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
283 raise Exception("Invalid data")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
284
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
285 def jsonrpc_deleteMblog(self, pub_data, comments):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
286 """Delete a microblog node
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
287 @param pub_data: a tuple (service, comment node identifier, item identifier)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
288 @param comments: comments node identifier (for main item) or False
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
289 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
290 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
291 return self.sat_host.bridge.deleteGroupBlog(pub_data, comments if comments else '', profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
292
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
293 def jsonrpc_updateMblog(self, pub_data, comments, message, extra={}):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
294 """Modify a microblog node
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
295 @param pub_data: a tuple (service, comment node identifier, item identifier)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
296 @param comments: comments node identifier (for main item) or False
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
297 @param message: new message
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
298 @param extra: dict which option name as key, which can be:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
299 - allow_comments: True to accept an other level of comments, False else (default: False)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
300 - rich: if present, contain rich text in currently selected syntax
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
301 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
302 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
303 if comments:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
304 extra['allow_comments'] = 'True'
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
305 return self.sat_host.bridge.updateGroupBlog(pub_data, comments if comments else '', message, extra, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
306
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
307 def jsonrpc_sendMblogComment(self, node, text, extra={}):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
308 """ Send microblog message
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
309 @param node: url of the comments node
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
310 @param text: comment
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
311 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
312 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
313 if node and text:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
314 return self.sat_host.bridge.sendGroupBlogComment(node, text, extra, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
315 else:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
316 raise Exception("Invalid data")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
317
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 566
diff changeset
318 def jsonrpc_getMblogs(self, publisher_jid, item_ids, max_items=C.RSM_MAX_ITEMS):
389
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
319 """Get specified microblogs posted by a contact
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
320 @param publisher_jid: jid of the publisher
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
321 @param item_ids: list of microblogs items IDs
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
322 @return list of microblog data (dict)"""
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
323 profile = ISATSession(self.session).profile
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 566
diff changeset
324 d = self.asyncBridgeCall("getGroupBlogs", publisher_jid, item_ids, {'max': unicode(max_items)}, False, profile)
389
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
325 return d
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
326
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 566
diff changeset
327 def jsonrpc_getMblogsWithComments(self, publisher_jid, item_ids, max_comments=C.RSM_MAX_COMMENTS):
389
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
328 """Get specified microblogs posted by a contact and their comments
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
329 @param publisher_jid: jid of the publisher
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
330 @param item_ids: list of microblogs items IDs
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
331 @return list of couple (microblog data, list of microblog data)"""
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
332 profile = ISATSession(self.session).profile
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 566
diff changeset
333 d = self.asyncBridgeCall("getGroupBlogsWithComments", publisher_jid, item_ids, {}, max_comments, profile)
389
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
334 return d
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
335
679
a90cc8fc9605 merged branch frontends_multi_profiles
Goffi <goffi@goffi.org>
parents: 586 669
diff changeset
336 def jsonrpc_getMassiveMblogs(self, publishers_type, publishers, rsm=None):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
337 """Get lasts microblogs posted by several contacts at once
651
2df91d0308ac browser_side, server_side: MicroblogPanel.onGroupDrop and bridge method getMassiveLastMBlogs now only accepts the publishers as a set of unicode (no more None value or single unicode).
souliane <souliane@mailoo.org>
parents: 623
diff changeset
338
2df91d0308ac browser_side, server_side: MicroblogPanel.onGroupDrop and bridge method getMassiveLastMBlogs now only accepts the publishers as a set of unicode (no more None value or single unicode).
souliane <souliane@mailoo.org>
parents: 623
diff changeset
339 @param publishers_type (unicode): one of "ALL", "GROUP", "JID"
2df91d0308ac browser_side, server_side: MicroblogPanel.onGroupDrop and bridge method getMassiveLastMBlogs now only accepts the publishers as a set of unicode (no more None value or single unicode).
souliane <souliane@mailoo.org>
parents: 623
diff changeset
340 @param publishers (tuple(unicode)): tuple of publishers (empty list for all, list of groups or list of jids)
679
a90cc8fc9605 merged branch frontends_multi_profiles
Goffi <goffi@goffi.org>
parents: 586 669
diff changeset
341 @param rsm (dict): TODO
651
2df91d0308ac browser_side, server_side: MicroblogPanel.onGroupDrop and bridge method getMassiveLastMBlogs now only accepts the publishers as a set of unicode (no more None value or single unicode).
souliane <souliane@mailoo.org>
parents: 623
diff changeset
342 @return: dict{unicode: list[dict])
2df91d0308ac browser_side, server_side: MicroblogPanel.onGroupDrop and bridge method getMassiveLastMBlogs now only accepts the publishers as a set of unicode (no more None value or single unicode).
souliane <souliane@mailoo.org>
parents: 623
diff changeset
343 key: publisher's jid
2df91d0308ac browser_side, server_side: MicroblogPanel.onGroupDrop and bridge method getMassiveLastMBlogs now only accepts the publishers as a set of unicode (no more None value or single unicode).
souliane <souliane@mailoo.org>
parents: 623
diff changeset
344 value: list of microblog data (dict)
2df91d0308ac browser_side, server_side: MicroblogPanel.onGroupDrop and bridge method getMassiveLastMBlogs now only accepts the publishers as a set of unicode (no more None value or single unicode).
souliane <souliane@mailoo.org>
parents: 623
diff changeset
345 """
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
346 profile = ISATSession(self.session).profile
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 566
diff changeset
347 if rsm is None:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 566
diff changeset
348 rsm = {'max': unicode(C.RSM_MAX_ITEMS)}
679
a90cc8fc9605 merged branch frontends_multi_profiles
Goffi <goffi@goffi.org>
parents: 586 669
diff changeset
349 d = self.asyncBridgeCall("getMassiveGroupBlogs", publishers_type, publishers, rsm, profile)
651
2df91d0308ac browser_side, server_side: MicroblogPanel.onGroupDrop and bridge method getMassiveLastMBlogs now only accepts the publishers as a set of unicode (no more None value or single unicode).
souliane <souliane@mailoo.org>
parents: 623
diff changeset
350 self.sat_host.bridge.massiveSubscribeGroupBlogs(publishers_type, publishers, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
351 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
352
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 566
diff changeset
353 def jsonrpc_getMblogComments(self, service, node, rsm=None):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
354 """Get all comments of given node
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
355 @param service: jid of the service hosting the node
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
356 @param node: comments node
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
357 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
358 profile = ISATSession(self.session).profile
586
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 566
diff changeset
359 if rsm is None:
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 566
diff changeset
360 rsm = {'max': unicode(C.RSM_MAX_COMMENTS)}
3eb3a2c0c011 browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 566
diff changeset
361 d = self.asyncBridgeCall("getGroupBlogComments", service, node, rsm, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
362 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
363
427
b5b440e6ea16 server + browser side, getPresenceStatuses has been renamed
Goffi <goffi@goffi.org>
parents: 421
diff changeset
364 def jsonrpc_getPresenceStatuses(self):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
365 """Get Presence information for connected contacts"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
366 profile = ISATSession(self.session).profile
427
b5b440e6ea16 server + browser side, getPresenceStatuses has been renamed
Goffi <goffi@goffi.org>
parents: 421
diff changeset
367 return self.sat_host.bridge.getPresenceStatuses(profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
368
566
8a607044ecfa server_side: adapt to the new signatures of bridge method getHistory
souliane <souliane@mailoo.org>
parents: 555
diff changeset
369 def jsonrpc_getHistory(self, from_jid, to_jid, size, between, search=''):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
370 """Return history for the from_jid/to_jid couple"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
371 sat_session = ISATSession(self.session)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
372 profile = sat_session.profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
373 sat_jid = sat_session.jid
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
374 if not sat_jid:
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
375 # we keep a session cache for jid to avoir jid spoofing
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
376 sat_jid = sat_session.jid = JID(self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
377 if JID(from_jid).userhost() != sat_jid.userhost() and JID(to_jid).userhost() != sat_jid.userhost():
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
378 log.error("Trying to get history from a different jid (given (browser): {}, real (backend): {}), maybe a hack attempt ?".format(from_jid, sat_jid))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
379 return {}
566
8a607044ecfa server_side: adapt to the new signatures of bridge method getHistory
souliane <souliane@mailoo.org>
parents: 555
diff changeset
380 d = self.asyncBridgeCall("getHistory", from_jid, to_jid, size, between, search, profile)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
381
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
382 def show(result_dbus):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
383 result = []
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
384 for line in result_dbus:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
385 #XXX: we have to do this stupid thing because Python D-Bus use its own types instead of standard types
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
386 # and txJsonRPC doesn't accept D-Bus types, resulting in a empty query
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
387 timestamp, from_jid, to_jid, message, mess_type, extra = line
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
388 result.append((float(timestamp), unicode(from_jid), unicode(to_jid), unicode(message), unicode(mess_type), dict(extra)))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
389 return result
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
390 d.addCallback(show)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
391 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
392
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
393 def jsonrpc_joinMUC(self, room_jid, nick):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
394 """Join a Multi-User Chat room
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
395 @room_jid: leave empty string to generate a unique name
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
396 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
397 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
398 d = self.asyncBridgeCall("joinMUC", room_jid, nick, {}, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
399 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
400
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
401 def jsonrpc_inviteMUC(self, contact_jid, room_jid):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
402 """Invite a user to a Multi-User Chat room"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
403 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
404 try:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
405 room_jid = JID(room_jid).userhost()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
406 except:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
407 log.warning('Invalid room jid')
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
408 return
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
409 room_id = room_jid.split("@")[0]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
410 service = room_jid.split("@")[1]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
411 self.sat_host.bridge.inviteMUC(contact_jid, service, room_id, {}, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
412
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
413 def jsonrpc_mucLeave(self, room_jid):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
414 """Quit a Multi-User Chat room"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
415 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
416 try:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
417 room_jid = JID(room_jid)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
418 except:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
419 log.warning('Invalid room jid')
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
420 return
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
421 self.sat_host.bridge.mucLeave(room_jid.userhost(), profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
422
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
423 def jsonrpc_getRoomsJoined(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
424 """Return list of room already joined by user"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
425 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
426 return self.sat_host.bridge.getRoomsJoined(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
427
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
428 def jsonrpc_getRoomsSubjects(self):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
429 """Return list of room subjects"""
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
430 profile = ISATSession(self.session).profile
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
431 return self.sat_host.bridge.getRoomsSubjects(profile)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
432
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
433 def jsonrpc_launchTarotGame(self, other_players, room_jid=""):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
434 """Create a room, invite the other players and start a Tarot game
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
435 @param room_jid: leave empty string to generate a unique room name
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
436 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
437 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
438 try:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
439 if room_jid != "":
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
440 room_jid = JID(room_jid).userhost()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
441 except:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
442 log.warning('Invalid room jid')
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
443 return
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
444 self.sat_host.bridge.tarotGameLaunch(other_players, room_jid, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
445
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
446 def jsonrpc_getTarotCardsPaths(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
447 """Give the path of all the tarot cards"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
448 _join = os.path.join
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
449 _media_dir = _join(self.sat_host.media_dir, '')
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
450 return map(lambda x: _join(C.MEDIA_DIR, x[len(_media_dir):]), glob.glob(_join(_media_dir, C.CARDS_DIR, '*_*.png')))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
451
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
452 def jsonrpc_tarotGameReady(self, player, referee):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
453 """Tell to the server that we are ready to start the game"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
454 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
455 self.sat_host.bridge.tarotGameReady(player, referee, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
456
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
457 def jsonrpc_tarotGamePlayCards(self, player_nick, referee, cards):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
458 """Tell to the server the cards we want to put on the table"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
459 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
460 self.sat_host.bridge.tarotGamePlayCards(player_nick, referee, cards, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
461
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
462 def jsonrpc_launchRadioCollective(self, invited, room_jid=""):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
463 """Create a room, invite people, and start a radio collective
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
464 @param room_jid: leave empty string to generate a unique room name
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
465 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
466 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
467 try:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
468 if room_jid != "":
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
469 room_jid = JID(room_jid).userhost()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
470 except:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
471 log.warning('Invalid room jid')
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
472 return
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
473 self.sat_host.bridge.radiocolLaunch(invited, room_jid, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
474
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
475 def jsonrpc_getEntitiesData(self, jids, keys):
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
476 """Get cached data for several entities at once
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
477
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
478 @param jids: list jids from who we wants data, or empty list for all jids in cache
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
479 @param keys: name of data we want (list)
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
480 @return: requested data"""
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
481 if not C.ALLOWED_ENTITY_DATA.issuperset(keys):
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
482 raise exceptions.PermissionError("Trying to access unallowed data (hack attempt ?)")
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
483 profile = ISATSession(self.session).profile
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
484 try:
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
485 return self.sat_host.bridge.getEntitiesData(jids, keys, profile)
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
486 except Exception as e:
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
487 raise Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, unicode(e)))
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
488
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
489 def jsonrpc_getEntityData(self, jid, keys):
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
490 """Get cached data for an entity
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
491
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
492 @param jid: jid of contact from who we want data
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
493 @param keys: name of data we want (list)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
494 @return: requested data"""
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
495 if not C.ALLOWED_ENTITY_DATA.issuperset(keys):
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
496 raise exceptions.PermissionError("Trying to access unallowed data (hack attempt ?)")
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
497 profile = ISATSession(self.session).profile
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
498 try:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
499 return self.sat_host.bridge.getEntityData(jid, keys, profile)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
500 except Exception as e:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
501 raise Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, unicode(e)))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
502
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
503 def jsonrpc_getCard(self, jid_):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
504 """Get VCard for entiry
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
505 @param jid_: jid of contact from who we want data
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
506 @return: id to retrieve the profile"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
507 profile = ISATSession(self.session).profile
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
508 return self.sat_host.bridge.getCard(jid_, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
509
391
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
510 def jsonrpc_getAccountDialogUI(self):
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
511 """Get the dialog for managing user account
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
512 @return: XML string of the XMLUI"""
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
513 profile = ISATSession(self.session).profile
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
514 return self.sat_host.bridge.getAccountDialogUI(profile)
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
515
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
516 def jsonrpc_getParamsUI(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
517 """Return the parameters XML for profile"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
518 profile = ISATSession(self.session).profile
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 427
diff changeset
519 d = self.asyncBridgeCall("getParams", C.SECURITY_LIMIT, C.APP_NAME, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
520
333
c01397d18026 server side: paramsXml2xmlUI is now parasXML2XMLUI + improved lisibility in getParamsUI
Goffi <goffi@goffi.org>
parents: 331
diff changeset
521 def setAuthorizedParams(params_xml):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
522 if self.authorized_params is None:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
523 self.authorized_params = {}
333
c01397d18026 server side: paramsXml2xmlUI is now parasXML2XMLUI + improved lisibility in getParamsUI
Goffi <goffi@goffi.org>
parents: 331
diff changeset
524 for cat in minidom.parseString(params_xml.encode('utf-8')).getElementsByTagName("category"):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
525 params = cat.getElementsByTagName("param")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
526 params_list = [param.getAttribute("name") for param in params]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
527 self.authorized_params[cat.getAttribute("name")] = params_list
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
528 if self.authorized_params:
333
c01397d18026 server side: paramsXml2xmlUI is now parasXML2XMLUI + improved lisibility in getParamsUI
Goffi <goffi@goffi.org>
parents: 331
diff changeset
529 return params_xml
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
530 else:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
531 return None
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
532
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
533 d.addCallback(setAuthorizedParams)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
534
333
c01397d18026 server side: paramsXml2xmlUI is now parasXML2XMLUI + improved lisibility in getParamsUI
Goffi <goffi@goffi.org>
parents: 331
diff changeset
535 d.addCallback(lambda params_xml: paramsXML2XMLUI(params_xml) if params_xml else "")
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
536
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
537 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
538
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
539 def jsonrpc_asyncGetParamA(self, param, category, attribute="value"):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
540 """Return the parameter value for profile"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
541 profile = ISATSession(self.session).profile
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 427
diff changeset
542 d = self.asyncBridgeCall("asyncGetParamA", param, category, attribute, C.SECURITY_LIMIT, profile_key=profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
543 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
544
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
545 def jsonrpc_setParam(self, name, value, category):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
546 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
547 if category in self.authorized_params and name in self.authorized_params[category]:
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 427
diff changeset
548 return self.sat_host.bridge.setParam(name, value, category, C.SECURITY_LIMIT, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
549 else:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
550 log.warning("Trying to set parameter '%s' in category '%s' without authorization!!!"
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
551 % (name, category))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
552
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
553 def jsonrpc_launchAction(self, callback_id, data):
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
554 #FIXME: any action can be launched, this can be a huge security issue if callback_id can be guessed
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
555 # a security system with authorised callback_id must be implemented, similar to the one for authorised params
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
556 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
557 d = self.asyncBridgeCall("launchAction", callback_id, data, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
558 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
559
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
560 def jsonrpc_chatStateComposing(self, to_jid_s):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
561 """Call the method to process a "composing" state.
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
562 @param to_jid_s: contact the user is composing to
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
563 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
564 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
565 self.sat_host.bridge.chatStateComposing(to_jid_s, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
566
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
567 def jsonrpc_getNewAccountDomain(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
568 """@return: the domain for new account creation"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
569 d = self.asyncBridgeCall("getNewAccountDomain")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
570 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
571
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
572 def jsonrpc_confirmationAnswer(self, confirmation_id, result, answer_data):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
573 """Send the user's answer to any previous 'askConfirmation' signal"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
574 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
575 self.sat_host.bridge.confirmationAnswer(confirmation_id, result, answer_data, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
576
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 427
diff changeset
577 def jsonrpc_syntaxConvert(self, text, syntax_from=C.SYNTAX_XHTML, syntax_to=C.SYNTAX_CURRENT):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
578 """ Convert a text between two syntaxes
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
579 @param text: text to convert
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
580 @param syntax_from: source syntax (e.g. "markdown")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
581 @param syntax_to: dest syntax (e.g.: "XHTML")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
582 @param safe: clean resulting XHTML to avoid malicious code if True (forced here)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
583 @return: converted text """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
584 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
585 return self.sat_host.bridge.syntaxConvert(text, syntax_from, syntax_to, True, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
586
520
d58d4dd0cefe browser and server sides: add bridge method getLastResource
souliane <souliane@mailoo.org>
parents: 514
diff changeset
587 def jsonrpc_getLastResource(self, jid_s):
521
69bffcf37ce3 browser_side: add minimal requirements for generic plugins handling
souliane <souliane@mailoo.org>
parents: 520
diff changeset
588 """Get the last active resource of that contact."""
520
d58d4dd0cefe browser and server sides: add bridge method getLastResource
souliane <souliane@mailoo.org>
parents: 514
diff changeset
589 profile = ISATSession(self.session).profile
d58d4dd0cefe browser and server sides: add bridge method getLastResource
souliane <souliane@mailoo.org>
parents: 514
diff changeset
590 return self.sat_host.bridge.getLastResource(jid_s, profile)
d58d4dd0cefe browser and server sides: add bridge method getLastResource
souliane <souliane@mailoo.org>
parents: 514
diff changeset
591
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
592 # FIXME: as this belong to a plugin, it should be managed dynamically
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
593 def jsonrpc_skipOTR(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
594 """Tell the backend to leave OTR handling to Libervia."""
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
595 profile = ISATSession(self.session).profile
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
596 return self.sat_host.bridge.skipOTR(profile)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
597
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
598
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
599 class WaitingRequests(dict):
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
600
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
601 def setRequest(self, request, profile):
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
602 """Add the given profile to the waiting list.
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
603
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
604 @param request (server.Request): the connection request
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
605 @param profile (str): %(doc_profile)s
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
606 """
555
db1b330c1eb1 server_side: set the connection attempt timeout to the bridge timeout (2 minutes)
souliane <souliane@mailoo.org>
parents: 554
diff changeset
607 dc = reactor.callLater(BRIDGE_TIMEOUT, self.purgeRequest, profile)
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
608 self[profile] = (request, dc)
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
609
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
610 def purgeRequest(self, profile):
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
611 """Remove the given profile from the waiting list.
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
612
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
613 @param profile (str): %(doc_profile)s
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
614 """
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
615 try:
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
616 dc = self[profile][1]
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
617 except KeyError:
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
618 return
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
619 if dc.active():
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
620 dc.cancel()
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
621 del self[profile]
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
622
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
623 def getRequest(self, profile):
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
624 """Get the waiting request for the given profile.
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
625
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
626 @param profile (str): %(doc_profile)s
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
627 @return: the waiting request or None
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
628 """
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
629 return self[profile][0] if profile in self else None
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
630
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
631
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
632 class Register(JSONRPCMethodManager):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
633 """This class manage the registration procedure with SàT
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
634 It provide an api for the browser, check password and setup the web server"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
635
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
636 def __init__(self, sat_host):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
637 JSONRPCMethodManager.__init__(self, sat_host)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
638 self.profiles_waiting = {}
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
639 self.request = None
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
640 self.waiting_profiles = WaitingRequests()
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
641
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
642 def render(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
643 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
644 Render method with some hacks:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
645 - if login is requested, try to login with form data
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
646 - except login, every method is jsonrpc
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
647 - user doesn't need to be authentified for explicitely listed methods, but must be for all others
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
648 """
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
649 if request.postpath == ['login']:
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
650 return self.loginOrRegister(request)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
651 _session = request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
652 parsed = jsonrpclib.loads(request.content.read())
482
437eefa53a01 misc: remove some pylint errors and warnings
souliane <souliane@mailoo.org>
parents: 481
diff changeset
653 method = parsed.get("method") # pylint: disable=E1103
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
654 if method not in ['isRegistered', 'registerParams', 'getMenus']:
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
655 #if we don't call these methods, we need to be identified
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
656 profile = ISATSession(_session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
657 if not profile:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
658 #user is not identified, we return a jsonrpc fault
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
659 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia
482
437eefa53a01 misc: remove some pylint errors and warnings
souliane <souliane@mailoo.org>
parents: 481
diff changeset
660 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) # pylint: disable=E1103
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
661 self.request = request
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
662 return jsonrpc.JSONRPC.render(self, request)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
663
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
664 def loginOrRegister(self, request):
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
665 """This method is called with the POST information from the registering form.
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
666
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
667 @param request: request of the register form
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
668 @return: a constant indicating the state:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
669 - C.BAD_REQUEST: something is wrong in the request (bad arguments)
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
670 - a return value from self._loginAccount or self._registerNewAccount
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
671 """
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
672 try:
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
673 submit_type = request.args['submit_type'][0]
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
674 except KeyError:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
675 return C.BAD_REQUEST
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
676
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
677 if submit_type == 'register':
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
678 return self._registerNewAccount(request)
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
679 elif submit_type == 'login':
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
680 return self._loginAccount(request)
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
681 return Exception('Unknown submit type')
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
682
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
683 def _loginAccount(self, request):
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
684 """Try to authenticate the user with the request information.
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
685 @param request: request of the register form
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
686 @return: a constant indicating the state:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
687 - C.BAD_REQUEST: something is wrong in the request (bad arguments)
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
688 - C.PROFILE_AUTH_ERROR: either the profile (login) or the profile password is wrong
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
689 - C.XMPP_AUTH_ERROR: the profile is authenticated but the XMPP password is wrong
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
690 - C.ALREADY_WAITING: a request has already been submitted for this profile
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
691 - server.NOT_DONE_YET: the profile is being processed, the return
464
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
692 value will be given by self._logged or auth_eb
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
693 """
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
694 try:
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
695 login_ = request.args['login'][0]
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
696 password_ = request.args['login_password'][0]
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
697 except KeyError:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
698 return C.BAD_REQUEST
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
699
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
700 if login_.startswith('@'):
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
701 raise Exception('No profile_key allowed')
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
702
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
703 profile_check = self.sat_host.bridge.getProfileName(login_)
471
de039f008333 server side: added config only option empty_password_allowed_warning_dangerous_list, which allow to connect with a profile with empty password. /!\ MUST not be used if Libervia is accessible from outside, this option is mainly useful for developpers.
Goffi <goffi@goffi.org>
parents: 470
diff changeset
704 if ((not profile_check or profile_check != login_) or
de039f008333 server side: added config only option empty_password_allowed_warning_dangerous_list, which allow to connect with a profile with empty password. /!\ MUST not be used if Libervia is accessible from outside, this option is mainly useful for developpers.
Goffi <goffi@goffi.org>
parents: 470
diff changeset
705 (not password_ and profile_check not in self.sat_host.empty_password_allowed_warning_dangerous_list)):
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
706 return C.PROFILE_AUTH_ERROR
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
707 # profiles with empty passwords are restricted to local frontends
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
708
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
709 if self.waiting_profiles.getRequest(login_):
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
710 return C.ALREADY_WAITING
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
711
464
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
712 def auth_eb(failure):
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
713 fault = failure.value.faultString
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
714 self.waiting_profiles.purgeRequest(login_)
464
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
715 if fault == 'PasswordError':
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
716 log.info("Profile %s doesn't exist or the submitted password is wrong" % login_)
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
717 request.write(C.PROFILE_AUTH_ERROR)
464
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
718 elif fault == 'SASLAuthError':
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
719 log.info("The XMPP password of profile %s is wrong" % login_)
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
720 request.write(C.XMPP_AUTH_ERROR)
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
721 elif fault == 'NoReply':
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
722 log.info(_("Did not receive a reply (the timeout expired or the connection is broken)"))
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
723 request.write(C.NO_REPLY)
464
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
724 else:
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
725 log.error('Unmanaged fault string %s in errback for the connection of profile %s' % (fault, login_))
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
726 request.write(C.UNKNOWN_ERROR % fault)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
727 request.finish()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
728
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
729 self.waiting_profiles.setRequest(request, login_)
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
730 d = self.asyncBridgeCall("asyncConnect", login_, password_)
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
731 d.addCallbacks(lambda connected: self._logged(login_, request) if connected else None, auth_eb)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
732
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
733 return server.NOT_DONE_YET
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
734
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
735
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
736 def _registerNewAccount(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
737 """Create a new account, or return error
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
738 @param request: request of the register form
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
739 @return: a constant indicating the state:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
740 - C.BAD_REQUEST: something is wrong in the request (bad arguments)
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
741 - C.REGISTRATION_SUCCEED: new account has been successfully registered
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
742 - C.ALREADY_EXISTS: the given profile already exists
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
743 - C.INTERNAL_ERROR or C.UNKNOWN_ERROR
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
744 - server.NOT_DONE_YET: the profile is being processed, the return
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
745 value will be given later (one of those previously described)
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
746 """
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
747 try:
487
e588335b6aa8 browser and server side: force lower case for the profile name at new account creation + fixes CSS for textarea
souliane <souliane@mailoo.org>
parents: 482
diff changeset
748 # XXX: for now libervia forces the creation to lower case
e588335b6aa8 browser and server side: force lower case for the profile name at new account creation + fixes CSS for textarea
souliane <souliane@mailoo.org>
parents: 482
diff changeset
749 profile = login = request.args['register_login'][0].lower()
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
750 password = request.args['register_password'][0]
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
751 email = request.args['email'][0]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
752 except KeyError:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
753 return C.BAD_REQUEST
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
754 if not re.match(r'^[a-z0-9_-]+$', login, re.IGNORECASE) or \
445
c0ff91cabea0 server_side, browser_side: new account password must contain at least 6 chars + cosmetic change for register warning message
souliane <souliane@mailoo.org>
parents: 444
diff changeset
755 not re.match(r'^.+@.+\..+', email, re.IGNORECASE) or \
c0ff91cabea0 server_side, browser_side: new account password must contain at least 6 chars + cosmetic change for register warning message
souliane <souliane@mailoo.org>
parents: 444
diff changeset
756 len(password) < C.PASSWORD_MIN_LENGTH:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
757 return C.BAD_REQUEST
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
758
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
759 def registered(result):
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
760 request.write(C.REGISTRATION_SUCCEED)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
761 request.finish()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
762
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
763 def registeringError(failure):
374
f22a4bf9a67e server_side: fix error management at account creation
souliane <souliane@mailoo.org>
parents: 351
diff changeset
764 reason = failure.value.faultString
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
765 if reason == "ConflictError":
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
766 request.write(C.ALREADY_EXISTS)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
767 elif reason == "InternalError":
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
768 request.write(C.INTERNAL_ERROR)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
769 else:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
770 log.error('Unknown registering error: %s' % (reason,))
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
771 request.write(C.UNKNOWN_ERROR % reason)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
772 request.finish()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
773
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
774 d = self.asyncBridgeCall("registerSatAccount", email, password, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
775 d.addCallback(registered)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
776 d.addErrback(registeringError)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
777 return server.NOT_DONE_YET
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
778
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
779 def _logged(self, profile, request):
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
780 """Set everything when a user just logged in
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
781
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
782 @param profile
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
783 @param request
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
784 @return: a constant indicating the state:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
785 - C.PROFILE_LOGGED
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
786 - C.SESSION_ACTIVE
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
787 """
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
788 self.waiting_profiles.purgeRequest(profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
789 _session = request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
790 sat_session = ISATSession(_session)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
791 if sat_session.profile:
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
792 log.error(('/!\\ Session has already a profile, this should NEVER happen!'))
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
793 request.write(C.SESSION_ACTIVE)
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
794 request.finish()
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
795 return
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
796 # we manage profile server side to avoid profile spoofing
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
797 sat_session.profile = profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
798 self.sat_host.prof_connected.add(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
799
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
800 def onExpire():
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
801 log.info("Session expired (profile=%s)" % (profile,))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
802 try:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
803 #We purge the queue
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
804 del self.sat_host.signal_handler.queue[profile]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
805 except KeyError:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
806 pass
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
807 #and now we disconnect the profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
808 self.sat_host.bridge.disconnect(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
809
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
810 _session.notifyOnExpire(onExpire)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
811
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
812 request.write(C.PROFILE_LOGGED)
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
813 request.finish()
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
814
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
815 def jsonrpc_isConnected(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
816 _session = self.request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
817 profile = ISATSession(_session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
818 return self.sat_host.bridge.isConnected(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
819
456
da2a7f2b34c9 browser and server sides: use asyncConnect instead of connect
souliane <souliane@mailoo.org>
parents: 451
diff changeset
820 def jsonrpc_asyncConnect(self):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
821 _session = self.request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
822 profile = ISATSession(_session).profile
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
823 if self.waiting_profiles.getRequest(profile):
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
824 raise jsonrpclib.Fault(1, C.ALREADY_WAITING) # FIXME: define some standard error codes for libervia
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
825 self.waiting_profiles.setRequest(self.request, profile)
456
da2a7f2b34c9 browser and server sides: use asyncConnect instead of connect
souliane <souliane@mailoo.org>
parents: 451
diff changeset
826 self.sat_host.bridge.asyncConnect(profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
827 return server.NOT_DONE_YET
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
828
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
829 def jsonrpc_isRegistered(self):
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
830 """
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
831 @return: a couple (registered, message) with:
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
832 - registered: True if the user is already registered, False otherwise
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
833 - message: a security warning message if registered is False *and* the connection is unsecure, None otherwise
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
834 """
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
835 _session = self.request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
836 profile = ISATSession(_session).profile
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
837 if bool(profile):
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
838 return (True, None)
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
839 return (False, self.__getSecurityWarning())
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
840
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
841 def jsonrpc_registerParams(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
842 """Register the frontend specific parameters"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
843 params = """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
844 <params>
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
845 <individual>
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
846 <category name="%(category_name)s" label="%(category_label)s">
462
07433bd892ee server and browser sides: fixes UI parameters initialisation with user values + small refactoring
souliane <souliane@mailoo.org>
parents: 456
diff changeset
847 <param name="%(enable_unibox)s" label="%(enable_unibox_label)s" value="false" type="bool" security="0"/>
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
848 </category>
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
849 </individual>
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
850 </params>
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
851 """ % {
462
07433bd892ee server and browser sides: fixes UI parameters initialisation with user values + small refactoring
souliane <souliane@mailoo.org>
parents: 456
diff changeset
852 'category_name': C.COMPOSITION_KEY,
07433bd892ee server and browser sides: fixes UI parameters initialisation with user values + small refactoring
souliane <souliane@mailoo.org>
parents: 456
diff changeset
853 'category_label': _(C.COMPOSITION_KEY),
07433bd892ee server and browser sides: fixes UI parameters initialisation with user values + small refactoring
souliane <souliane@mailoo.org>
parents: 456
diff changeset
854 'enable_unibox': C.ENABLE_UNIBOX_PARAM,
07433bd892ee server and browser sides: fixes UI parameters initialisation with user values + small refactoring
souliane <souliane@mailoo.org>
parents: 456
diff changeset
855 'enable_unibox_label': _(C.ENABLE_UNIBOX_PARAM),
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
856 }
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
857
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 427
diff changeset
858 self.sat_host.bridge.paramsRegisterApp(params, C.SECURITY_LIMIT, C.APP_NAME)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
859
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
860 def jsonrpc_getMenus(self):
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
861 """Return the parameters XML for profile"""
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
862 # XXX: we put this method in Register because we get menus before being logged
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 427
diff changeset
863 return self.sat_host.bridge.getMenus('', C.SECURITY_LIMIT)
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
864
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
865 def __getSecurityWarning(self):
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
866 """@return: a security warning message, or None if the connection is secure"""
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
867 if self.request.URLPath().scheme == 'https' or not self.sat_host.security_warning:
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
868 return None
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
869 text = D_("You are about to connect to an unsecured service.")
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
870 if self.sat_host.connection_type == 'both':
421
39b07289ff42 server_side: added parameter port_https_ext (external port for HTTPS, used for example for the redirection)
souliane <souliane@mailoo.org>
parents: 417
diff changeset
871 new_port = (':%s' % self.sat_host.port_https_ext) if self.sat_host.port_https_ext != HTTPS_PORT else ''
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
872 url = "https://%s" % self.request.URLPath().netloc.replace(':%s' % self.sat_host.port, new_port)
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
873 text += D_('<br />Secure version of this website: <a href="%(url)s">%(url)s</a>') % {'url': url}
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
874 return text
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
875
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
876
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
877 class SignalHandler(jsonrpc.JSONRPC):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
878
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
879 def __init__(self, sat_host):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
880 Resource.__init__(self)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
881 self.register = None
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
882 self.sat_host = sat_host
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
883 self.signalDeferred = {}
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
884 self.queue = {}
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
885
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
886 def plugRegister(self, register):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
887 self.register = register
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
888
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
889 def jsonrpc_getSignals(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
890 """Keep the connection alive until a signal is received, then send it
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
891 @return: (signal, *signal_args)"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
892 _session = self.request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
893 profile = ISATSession(_session).profile
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
894 if profile in self.queue: # if we have signals to send in queue
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
895 if self.queue[profile]:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
896 return self.queue[profile].pop(0)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
897 else:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
898 #the queue is empty, we delete the profile from queue
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
899 del self.queue[profile]
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
900 _session.lock() # we don't want the session to expire as long as this connection is active
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
901
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
902 def unlock(signal, profile):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
903 _session.unlock()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
904 try:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
905 source_defer = self.signalDeferred[profile]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
906 if source_defer.called and source_defer.result[0] == "disconnected":
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
907 log.info(u"[%s] disconnected" % (profile,))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
908 _session.expire()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
909 except IndexError:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
910 log.error("Deferred result should be a tuple with fonction name first")
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
911
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
912 self.signalDeferred[profile] = defer.Deferred()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
913 self.request.notifyFinish().addBoth(unlock, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
914 return self.signalDeferred[profile]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
915
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
916 def getGenericCb(self, function_name):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
917 """Return a generic function which send all params to signalDeferred.callback
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
918 function must have profile as last argument"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
919 def genericCb(*args):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
920 profile = args[-1]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
921 if not profile in self.sat_host.prof_connected:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
922 return
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
923 if profile in self.signalDeferred:
482
437eefa53a01 misc: remove some pylint errors and warnings
souliane <souliane@mailoo.org>
parents: 481
diff changeset
924 self.signalDeferred[profile].callback((function_name, args[:-1]))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
925 del self.signalDeferred[profile]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
926 else:
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
927 if profile not in self.queue:
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
928 self.queue[profile] = []
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
929 self.queue[profile].append((function_name, args[:-1]))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
930 return genericCb
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
931
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
932 def connected(self, profile):
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
933 assert(self.register) # register must be plugged
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
934 request = self.register.waiting_profiles.getRequest(profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
935 if request:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
936 self.register._logged(profile, request)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
937
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
938 def disconnected(self, profile):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
939 if not profile in self.sat_host.prof_connected:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
940 log.error("'disconnected' signal received for a not connected profile")
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
941 return
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
942 self.sat_host.prof_connected.remove(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
943 if profile in self.signalDeferred:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
944 self.signalDeferred[profile].callback(("disconnected",))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
945 del self.signalDeferred[profile]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
946 else:
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
947 if profile not in self.queue:
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
948 self.queue[profile] = []
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
949 self.queue[profile].append(("disconnected",))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
950
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
951 def render(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
952 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
953 Render method wich reject access if user is not identified
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
954 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
955 _session = request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
956 parsed = jsonrpclib.loads(request.content.read())
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
957 profile = ISATSession(_session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
958 if not profile:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
959 #user is not identified, we return a jsonrpc fault
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
960 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia
482
437eefa53a01 misc: remove some pylint errors and warnings
souliane <souliane@mailoo.org>
parents: 481
diff changeset
961 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) # pylint: disable=E1103
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
962 self.request = request
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
963 return jsonrpc.JSONRPC.render(self, request)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
964
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
965
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
966 class UploadManager(Resource):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
967 """This class manage the upload of a file
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
968 It redirect the stream to SàT core backend"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
969 isLeaf = True
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
970 NAME = 'path' # name use by the FileUpload
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
971
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
972 def __init__(self, sat_host):
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
973 self.sat_host = sat_host
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
974 self.upload_dir = tempfile.mkdtemp()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
975 self.sat_host.addCleanup(shutil.rmtree, self.upload_dir)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
976
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
977 def getTmpDir(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
978 return self.upload_dir
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
979
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
980 def _getFileName(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
981 """Generate unique filename for a file"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
982 raise NotImplementedError
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
983
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
984 def _fileWritten(self, request, filepath):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
985 """Called once the file is actually written on disk
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
986 @param request: HTTP request object
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
987 @param filepath: full filepath on the server
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
988 @return: a tuple with the name of the async bridge method
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
989 to be called followed by its arguments.
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
990 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
991 raise NotImplementedError
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
992
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
993 def render(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
994 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
995 Render method with some hacks:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
996 - if login is requested, try to login with form data
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
997 - except login, every method is jsonrpc
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
998 - user doesn't need to be authentified for isRegistered, but must be for all other methods
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
999 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1000 filename = self._getFileName(request)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1001 filepath = os.path.join(self.upload_dir, filename)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1002 #FIXME: the uploaded file is fully loaded in memory at form parsing time so far
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1003 # (see twisted.web.http.Request.requestReceived). A custom requestReceived should
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1004 # be written in the futur. In addition, it is not yet possible to get progression informations
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1005 # (see http://twistedmatrix.com/trac/ticket/288)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1006
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1007 with open(filepath, 'w') as f:
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1008 f.write(request.args[self.NAME][0])
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1009
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1010 def finish(d):
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1011 error = isinstance(d, Exception) or isinstance(d, Failure)
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1012 request.write(C.UPLOAD_KO if error else C.UPLOAD_OK)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1013 # TODO: would be great to re-use the original Exception class and message
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1014 # but it is lost in the middle of the backtrace and encapsulated within
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1015 # a DBusException instance --> extract the data from the backtrace?
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1016 request.finish()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1017
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1018 d = JSONRPCMethodManager(self.sat_host).asyncBridgeCall(*self._fileWritten(request, filepath))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1019 d.addCallbacks(lambda d: finish(d), lambda failure: finish(failure))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1020 return server.NOT_DONE_YET
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1021
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1022
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1023 class UploadManagerRadioCol(UploadManager):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1024 NAME = 'song'
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1025
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1026 def _getFileName(self, request):
394
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 391
diff changeset
1027 extension = os.path.splitext(request.args['filename'][0])[1]
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 391
diff changeset
1028 return "%s%s" % (str(uuid.uuid4()), extension) # XXX: chromium doesn't seem to play song without the .ogg extension, even with audio/ogg mime-type
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1029
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1030 def _fileWritten(self, request, filepath):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1031 """Called once the file is actually written on disk
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1032 @param request: HTTP request object
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1033 @param filepath: full filepath on the server
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1034 @return: a tuple with the name of the async bridge method
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1035 to be called followed by its arguments.
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1036 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1037 profile = ISATSession(request.getSession()).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1038 return ("radiocolSongAdded", request.args['referee'][0], filepath, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1039
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1040
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1041 class UploadManagerAvatar(UploadManager):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1042 NAME = 'avatar_path'
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1043
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1044 def _getFileName(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1045 return str(uuid.uuid4())
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1046
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1047 def _fileWritten(self, request, filepath):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1048 """Called once the file is actually written on disk
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1049 @param request: HTTP request object
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1050 @param filepath: full filepath on the server
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1051 @return: a tuple with the name of the async bridge method
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1052 to be called followed by its arguments.
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1053 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1054 profile = ISATSession(request.getSession()).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1055 return ("setAvatar", filepath, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1056
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1057
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1058
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1059
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1060 class Libervia(service.Service):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1061
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1062
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1063 def __init__(self, *args, **kwargs):
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1064 self.initialised = defer.Deferred()
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1065
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1066 # options managing
514
530c88c1deee server_side: plugin refactoring:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1067 for opt in OPT_PARAMETERS_BOTH + OPT_PARAMETERS_CFG:
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1068 opt_name = opt[0]
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1069 setattr(self, opt_name, kwargs.get(opt_name, opt[2]))
421
39b07289ff42 server_side: added parameter port_https_ext (external port for HTTPS, used for example for the redirection)
souliane <souliane@mailoo.org>
parents: 417
diff changeset
1070 if not self.port_https_ext:
39b07289ff42 server_side: added parameter port_https_ext (external port for HTTPS, used for example for the redirection)
souliane <souliane@mailoo.org>
parents: 417
diff changeset
1071 self.port_https_ext = self.port_https
514
530c88c1deee server_side: plugin refactoring:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1072 if self.data_dir == DATA_DIR_DEFAULT:
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
1073 coerceDataDir(self.data_dir) # this is not done when using the default value
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1074
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
1075 self.html_dir = os.path.join(self.data_dir, C.HTML_DIR)
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
1076 self.server_css_dir = os.path.join(self.data_dir, C.SERVER_CSS_DIR)
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1077
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1078 self._cleanup = []
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1079
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
1080 root = ProtectedFile(self.html_dir)
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1081
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1082 self.signal_handler = SignalHandler(self)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1083 _register = Register(self)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1084 _upload_radiocol = UploadManagerRadioCol(self)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1085 _upload_avatar = UploadManagerAvatar(self)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1086 self.signal_handler.plugRegister(_register)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1087 self.sessions = {} # key = session value = user
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1088 self.prof_connected = set() # Profiles connected
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1089 self.action_handler = SATActionIDHandler()
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1090
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1091 ## bridge ##
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1092 try:
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1093 self.bridge = DBusBridgeFrontend()
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1094 except BridgeExceptionNoService:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1095 print(u"Can't connect to SàT backend, are you sure it's launched ?")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1096 sys.exit(1)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1097
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1098 def backendReady(dummy):
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1099 self.bridge.register("connected", self.signal_handler.connected)
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1100 self.bridge.register("disconnected", self.signal_handler.disconnected)
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1101 self.bridge.register("actionResult", self.action_handler.actionResultCb)
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1102 #core
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1103 for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated', 'askConfirmation', 'newAlert', 'paramUpdate']:
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1104 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name))
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1105 #plugins
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1106 for signal_name in ['personalEvent', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat',
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1107 'tarotGameShowCards', 'tarotGameInvalidCards', 'tarotGameCardsPlayed', 'tarotGameYourTurn', 'tarotGameScore', 'tarotGamePlayers',
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1108 'radiocolStarted', 'radiocolPreload', 'radiocolPlay', 'radiocolNoUpload', 'radiocolUploadOk', 'radiocolSongRejected', 'radiocolPlayers',
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1109 'roomLeft', 'roomUserChangedNick', 'chatStateReceived']:
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1110 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name), "plugin")
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1111 self.media_dir = self.bridge.getConfig('', 'media_dir')
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1112 self.local_dir = self.bridge.getConfig('', 'local_dir')
553
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1113
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1114 def putChild(path, resource):
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1115 """Add a child to the root resource"""
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1116 root.putChild(path, EncodingResourceWrapper(resource, [server.GzipEncoderFactory()]))
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1117
613
deddd1cd8aa5 browser side: added a base_location property to get location of current Libervia instance
Goffi <goffi@goffi.org>
parents: 608
diff changeset
1118 putChild('', Redirect(C.LIBERVIA_MAIN_PAGE))
602
be3fd3874c3a add very basic test system accessible from <root_url>/test, to be improved:
souliane <souliane@mailoo.org>
parents: 589
diff changeset
1119 putChild('test', Redirect('libervia_test.html'))
553
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1120 putChild('json_signal_api', self.signal_handler)
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1121 putChild('json_api', MethodHandler(self))
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1122 putChild('register_api', _register)
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1123 putChild('upload_radiocol', _upload_radiocol)
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1124 putChild('upload_avatar', _upload_avatar)
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1125 putChild('blog', MicroBlog(self))
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1126 putChild('css', ProtectedFile(self.server_css_dir))
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1127 putChild(os.path.dirname(C.MEDIA_DIR), ProtectedFile(self.media_dir))
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1128 putChild(os.path.dirname(C.AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, C.AVATARS_DIR)))
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1129 putChild('radiocol', ProtectedFile(_upload_radiocol.getTmpDir(), defaultType="audio/ogg")) # We cheat for PoC because we know we are on the same host, so we use directly upload dir
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1130 wrapped = EncodingResourceWrapper(root, [server.GzipEncoderFactory()])
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1131 self.site = server.Site(wrapped)
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1132 self.site.sessionFactory = LiberviaSession
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1133
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1134 self.bridge.getReady(lambda: self.initialised.callback(None),
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1135 lambda failure: self.initialised.errback(Exception(failure)))
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1136 self.initialised.addCallback(backendReady)
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1137 self.initialised.addErrback(lambda failure: log.error("Init error: %s" % failure))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1138
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1139 @property
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1140 def version(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1141 """Return the short version of Libervia"""
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1142 return C.APP_VERSION
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1143
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1144 @property
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1145 def full_version(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1146 """Return the full version of Libervia (with extra data when in development mode)"""
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1147 version = self.version
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1148 if version[-1] == 'D':
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1149 # we are in debug version, we add extra data
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1150 try:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1151 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1152 except AttributeError:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1153 self._version_cache = u"{} ({})".format(version, utils.getRepositoryData(libervia))
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1154 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1155 else:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1156 return version
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1157
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1158 def addCleanup(self, callback, *args, **kwargs):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1159 """Add cleaning method to call when service is stopped
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1160 cleaning method will be called in reverse order of they insertion
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1161 @param callback: callable to call on service stop
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1162 @param *args: list of arguments of the callback
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1163 @param **kwargs: list of keyword arguments of the callback"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1164 self._cleanup.insert(0, (callback, args, kwargs))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1165
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1166 def startService(self):
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1167 """Connect the profile for Libervia and start the HTTP(S) server(s)"""
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1168 def eb(e):
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1169 log.error(_("Connection failed: %s") % e)
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1170 self.stop()
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1171
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1172 def initOk(dummy):
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1173 if not self.bridge.isConnected(C.SERVICE_PROFILE):
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1174 self.bridge.asyncConnect(C.SERVICE_PROFILE, self.passphrase,
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1175 callback=self._startService, errback=eb)
472
42c8e91af048 server side: fixed start sequence when SERVICE_PROFILE is already connected
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1176 else:
42c8e91af048 server side: fixed start sequence when SERVICE_PROFILE is already connected
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1177 self._startService()
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1178
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1179 self.initialised.addCallback(initOk)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1180
472
42c8e91af048 server side: fixed start sequence when SERVICE_PROFILE is already connected
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1181 def _startService(self, dummy=None):
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
1182 """Actually start the HTTP(S) server(s) after the profile for Libervia is connected.
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
1183 @raise IOError: the certificate file doesn't exist
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
1184 @raise OpenSSL.crypto.Error: the certificate file is invalid
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
1185 """
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1186 if self.connection_type in ('https', 'both'):
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1187 if not ssl_available:
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1188 raise(ImportError(_("Python module pyOpenSSL is not installed!")))
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1189 try:
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1190 with open(os.path.expanduser(self.ssl_certificate)) as keyAndCert:
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1191 try:
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1192 cert = ssl.PrivateCertificate.loadPEM(keyAndCert.read())
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1193 except OpenSSL.crypto.Error as e:
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1194 log.error(_("The file '%s' must contain both private and public parts of the certificate") % self.ssl_certificate)
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1195 raise e
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1196 except IOError as e:
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1197 log.error(_("The file '%s' doesn't exist") % self.ssl_certificate)
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1198 raise e
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1199 reactor.listenSSL(self.port_https, self.site, cert.options())
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1200 if self.connection_type in ('http', 'both'):
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1201 if self.connection_type == 'both' and self.redirect_to_https:
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1202 reactor.listenTCP(self.port, server.Site(RedirectToHTTPS(self.port, self.port_https_ext)))
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1203 else:
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1204 reactor.listenTCP(self.port, self.site)
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1205
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1206 def stopService(self):
473
d1565906f228 server_side: fixed some forgotten print statement
Goffi <goffi@goffi.org>
parents: 472
diff changeset
1207 log.info(_("launching cleaning methods"))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1208 for callback, args, kwargs in self._cleanup:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1209 callback(*args, **kwargs)
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1210 self.bridge.disconnect(C.SERVICE_PROFILE)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1211
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1212 def run(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1213 reactor.run()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1214
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1215 def stop(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1216 reactor.stop()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1217
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1218
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1219 class RedirectToHTTPS(Resource):
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1220
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1221 def __init__(self, old_port, new_port):
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1222 Resource.__init__(self)
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1223 self.isLeaf = True
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1224 self.old_port = old_port
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1225 self.new_port = new_port
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1226
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1227 def render(self, request):
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1228 netloc = request.URLPath().netloc.replace(':%s' % self.old_port, ':%s' % self.new_port)
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1229 url = "https://" + netloc + request.uri
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1230 return redirectTo(url, request)
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1231
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1232
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1233 registerAdapter(SATSession, server.Session, ISATSession)