Mercurial > libervia-web
comparison src/server/server.py @ 589:a5019e62c3e9 frontends_multi_profiles
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
/!\ not finished, partially working and highly instable
- add collections module with an OrderedDict like class
- SatWebFrontend inherit from QuickApp
- general sat_frontends tools.jid module is used
- bridge/json methods have moved to json module
- UniBox is partially removed (should be totally removed before merge to trunk)
- Signals are now register with the generic registerSignal method (which is called mainly in QuickFrontend)
- the generic getOrCreateWidget method from QuickWidgetsManager is used instead of Libervia's specific methods
- all Widget are now based more or less directly on QuickWidget
- with the new QuickWidgetsManager.getWidgets method, it's no more necessary to check all widgets which are instance of a particular class
- ChatPanel and related moved to chat module
- MicroblogPanel and related moved to blog module
- global and overcomplicated send method has been disabled: each class should manage its own sending
- for consistency with other frontends, former ContactPanel has been renamed to ContactList and vice versa
- for the same reason, ChatPanel has been renamed to Chat
- for compatibility with QuickFrontend, a fake profile is used in several places, it is set to C.PROF_KEY_NONE (real profile is managed server side for obvious security reasons)
- changed default url for web panel to SàT website, and contact address to generic SàT contact address
- ContactList is based on QuickContactList, UI changes are done in update method
- bride call (now json module) have been greatly improved, in particular call can be done in the same way as for other frontends (bridge.method_name(arg1, arg2, ..., callback=cb, errback=eb). Blocking method must be called like async methods due to javascript architecture
- in bridge calls, a callback can now exists without errback
- hard reload on BridgeSignals remote error has been disabled, a better option should be implemented
- use of constants where that make sens, some style improvments
- avatars are temporarily disabled
- lot of code disabled, will be fixed or removed before merge
- various other changes, check diff for more details
server side: manage remote exception on getEntityData, removed getProfileJid call, added getWaitingConf, added getRoomsSubjects
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 24 Jan 2015 01:45:39 +0100 |
parents | 8a607044ecfa |
children | be3fd3874c3a 917e271975d9 |
comparison
equal
deleted
inserted
replaced
585:bade589dbd5a | 589:a5019e62c3e9 |
---|---|
182 parsed = jsonrpclib.loads(request.content.read()) | 182 parsed = jsonrpclib.loads(request.content.read()) |
183 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia | 183 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia |
184 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) # pylint: disable=E1103 | 184 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) # pylint: disable=E1103 |
185 return jsonrpc.JSONRPC.render(self, request) | 185 return jsonrpc.JSONRPC.render(self, request) |
186 | 186 |
187 def jsonrpc_getProfileJid(self): | |
188 """Return the jid of the profile""" | |
189 sat_session = ISATSession(self.session) | |
190 profile = sat_session.profile | |
191 sat_session.jid = JID(self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile)) | |
192 return sat_session.jid.full() | |
193 | |
194 def jsonrpc_disconnect(self): | 187 def jsonrpc_disconnect(self): |
195 """Disconnect the profile""" | 188 """Disconnect the profile""" |
196 sat_session = ISATSession(self.session) | 189 sat_session = ISATSession(self.session) |
197 profile = sat_session.profile | 190 profile = sat_session.profile |
198 self.sat_host.bridge.disconnect(profile) | 191 self.sat_host.bridge.disconnect(profile) |
228 | 221 |
229 def jsonrpc_getWaitingSub(self): | 222 def jsonrpc_getWaitingSub(self): |
230 """Return list of room already joined by user""" | 223 """Return list of room already joined by user""" |
231 profile = ISATSession(self.session).profile | 224 profile = ISATSession(self.session).profile |
232 return self.sat_host.bridge.getWaitingSub(profile) | 225 return self.sat_host.bridge.getWaitingSub(profile) |
226 | |
227 def jsonrpc_getWaitingConf(self): | |
228 """Return list of waiting confirmations""" | |
229 profile = ISATSession(self.session).profile | |
230 return self.sat_host.bridge.getWaitingConf(profile) | |
233 | 231 |
234 def jsonrpc_setStatus(self, presence, status): | 232 def jsonrpc_setStatus(self, presence, status): |
235 """Change the presence and/or status | 233 """Change the presence and/or status |
236 @param presence: value from ("", "chat", "away", "dnd", "xa") | 234 @param presence: value from ("", "chat", "away", "dnd", "xa") |
237 @param status: any string to describe your status | 235 @param status: any string to describe your status |
357 """Return history for the from_jid/to_jid couple""" | 355 """Return history for the from_jid/to_jid couple""" |
358 sat_session = ISATSession(self.session) | 356 sat_session = ISATSession(self.session) |
359 profile = sat_session.profile | 357 profile = sat_session.profile |
360 sat_jid = sat_session.jid | 358 sat_jid = sat_session.jid |
361 if not sat_jid: | 359 if not sat_jid: |
362 log.error("No jid saved for this profile") | 360 # we keep a session cache for jid to avoir jid spoofing |
363 return {} | 361 sat_jid = sat_session.jid = JID(self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile)) |
364 if JID(from_jid).userhost() != sat_jid.userhost() and JID(to_jid).userhost() != sat_jid.userhost(): | 362 if JID(from_jid).userhost() != sat_jid.userhost() and JID(to_jid).userhost() != sat_jid.userhost(): |
365 log.error("Trying to get history from a different jid, maybe a hack attempt ?") | 363 log.error("Trying to get history from a different jid (given (browser): {}, real (backend): {}), maybe a hack attempt ?".format(from_jid, sat_jid)) |
366 return {} | 364 return {} |
367 d = self.asyncBridgeCall("getHistory", from_jid, to_jid, size, between, search, profile) | 365 d = self.asyncBridgeCall("getHistory", from_jid, to_jid, size, between, search, profile) |
368 | 366 |
369 def show(result_dbus): | 367 def show(result_dbus): |
370 result = [] | 368 result = [] |
416 def jsonrpc_getRoomsJoined(self): | 414 def jsonrpc_getRoomsJoined(self): |
417 """Return list of room already joined by user""" | 415 """Return list of room already joined by user""" |
418 profile = ISATSession(self.session).profile | 416 profile = ISATSession(self.session).profile |
419 return self.sat_host.bridge.getRoomsJoined(profile) | 417 return self.sat_host.bridge.getRoomsJoined(profile) |
420 | 418 |
419 def jsonrpc_getRoomsSubjects(self): | |
420 """Return list of room subjects""" | |
421 profile = ISATSession(self.session).profile | |
422 return self.sat_host.bridge.getRoomsSubjects(profile) | |
423 | |
421 def jsonrpc_launchTarotGame(self, other_players, room_jid=""): | 424 def jsonrpc_launchTarotGame(self, other_players, room_jid=""): |
422 """Create a room, invite the other players and start a Tarot game | 425 """Create a room, invite the other players and start a Tarot game |
423 @param room_jid: leave empty string to generate a unique room name | 426 @param room_jid: leave empty string to generate a unique room name |
424 """ | 427 """ |
425 profile = ISATSession(self.session).profile | 428 profile = ISATSession(self.session).profile |
464 """Get cached data for an entit | 467 """Get cached data for an entit |
465 @param jid: jid of contact from who we want data | 468 @param jid: jid of contact from who we want data |
466 @param keys: name of data we want (list) | 469 @param keys: name of data we want (list) |
467 @return: requested data""" | 470 @return: requested data""" |
468 profile = ISATSession(self.session).profile | 471 profile = ISATSession(self.session).profile |
469 return self.sat_host.bridge.getEntityData(jid, keys, profile) | 472 try: |
473 return self.sat_host.bridge.getEntityData(jid, keys, profile) | |
474 except Exception as e: | |
475 raise Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, unicode(e))) | |
470 | 476 |
471 def jsonrpc_getCard(self, jid): | 477 def jsonrpc_getCard(self, jid): |
472 """Get VCard for entiry | 478 """Get VCard for entiry |
473 @param jid: jid of contact from who we want data | 479 @param jid: jid of contact from who we want data |
474 @return: id to retrieve the profile""" | 480 @return: id to retrieve the profile""" |
759 if sat_session.profile: | 765 if sat_session.profile: |
760 log.error(('/!\\ Session has already a profile, this should NEVER happen!')) | 766 log.error(('/!\\ Session has already a profile, this should NEVER happen!')) |
761 request.write(C.SESSION_ACTIVE) | 767 request.write(C.SESSION_ACTIVE) |
762 request.finish() | 768 request.finish() |
763 return | 769 return |
770 # we manage profile server side to avoid profile spoofing | |
764 sat_session.profile = profile | 771 sat_session.profile = profile |
765 self.sat_host.prof_connected.add(profile) | 772 self.sat_host.prof_connected.add(profile) |
766 | 773 |
767 def onExpire(): | 774 def onExpire(): |
768 log.info("Session expired (profile=%s)" % (profile,)) | 775 log.info("Session expired (profile=%s)" % (profile,)) |