comparison src/server/server.py @ 1108:7ec1ba86d38d

server: replaced blocking calls to bridge by bridgeCall which is not blocking
author Goffi <goffi@goffi.org>
date Mon, 04 Jun 2018 11:52:19 +0200
parents 09feea19d7b9
children cdd389ef97bc
comparison
equal deleted inserted replaced
1107:2066d4fd9036 1108:7ec1ba86d38d
396 parsed = jsonrpclib.loads(request.content.read()) 396 parsed = jsonrpclib.loads(request.content.read())
397 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia 397 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia
398 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) # pylint: disable=E1103 398 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) # pylint: disable=E1103
399 return jsonrpc.JSONRPC.render(self, request) 399 return jsonrpc.JSONRPC.render(self, request)
400 400
401 @defer.inlineCallbacks
401 def jsonrpc_getVersion(self): 402 def jsonrpc_getVersion(self):
402 """Return SàT version""" 403 """Return SàT version"""
403 try: 404 try:
404 return self._version_cache 405 defer.returnValue(self._version_cache)
405 except AttributeError: 406 except AttributeError:
406 self._version_cache = self.sat_host.bridge.getVersion() 407 self._version_cache = yield self.sat_host.bridgeCall("getVersion")
407 return self._version_cache 408 defer.returnValue(self._version_cache)
408 409
409 def jsonrpc_getLiberviaVersion(self): 410 def jsonrpc_getLiberviaVersion(self):
410 """Return Libervia version""" 411 """Return Libervia version"""
411 return self.sat_host.full_version 412 return self.sat_host.full_version
412 413
413 def jsonrpc_disconnect(self): 414 def jsonrpc_disconnect(self):
414 """Disconnect the profile""" 415 """Disconnect the profile"""
415 sat_session = session_iface.ISATSession(self.session) 416 sat_session = session_iface.ISATSession(self.session)
416 profile = sat_session.profile 417 profile = sat_session.profile
417 self.sat_host.bridge.disconnect(profile) 418 self.sat_host.bridgeCall("disconnect", profile)
418 419
419 def jsonrpc_getContacts(self): 420 def jsonrpc_getContacts(self):
420 """Return all passed args.""" 421 """Return all passed args."""
421 profile = session_iface.ISATSession(self.session).profile 422 profile = session_iface.ISATSession(self.session).profile
422 return self.sat_host.bridge.getContacts(profile) 423 return self.sat_host.bridgeCall("getContacts", profile)
423 424
425 @defer.inlineCallbacks
424 def jsonrpc_addContact(self, entity, name, groups): 426 def jsonrpc_addContact(self, entity, name, groups):
425 """Subscribe to contact presence, and add it to the given groups""" 427 """Subscribe to contact presence, and add it to the given groups"""
426 profile = session_iface.ISATSession(self.session).profile 428 profile = session_iface.ISATSession(self.session).profile
427 self.sat_host.bridge.addContact(entity, profile) 429 yield self.sat_host.bridgeCall("addContact", entity, profile)
428 self.sat_host.bridge.updateContact(entity, name, groups, profile) 430 yield self.sat_host.bridgeCall("updateContact", entity, name, groups, profile)
429 431
430 def jsonrpc_delContact(self, entity): 432 def jsonrpc_delContact(self, entity):
431 """Remove contact from contacts list""" 433 """Remove contact from contacts list"""
432 profile = session_iface.ISATSession(self.session).profile 434 profile = session_iface.ISATSession(self.session).profile
433 self.sat_host.bridge.delContact(entity, profile) 435 return self.sat_host.bridgeCall("delContact", entity, profile)
434 436
435 def jsonrpc_updateContact(self, entity, name, groups): 437 def jsonrpc_updateContact(self, entity, name, groups):
436 """Update contact's roster item""" 438 """Update contact's roster item"""
437 profile = session_iface.ISATSession(self.session).profile 439 profile = session_iface.ISATSession(self.session).profile
438 self.sat_host.bridge.updateContact(entity, name, groups, profile) 440 return self.sat_host.bridgeCall("updateContact", entity, name, groups, profile)
439 441
440 def jsonrpc_subscription(self, sub_type, entity): 442 def jsonrpc_subscription(self, sub_type, entity):
441 """Confirm (or infirm) subscription, 443 """Confirm (or infirm) subscription,
442 and setup user roster in case of subscription""" 444 and setup user roster in case of subscription"""
443 profile = session_iface.ISATSession(self.session).profile 445 profile = session_iface.ISATSession(self.session).profile
444 self.sat_host.bridge.subscription(sub_type, entity, profile) 446 return self.sat_host.bridgeCall("subscription", sub_type, entity, profile)
445 447
446 def jsonrpc_getWaitingSub(self): 448 def jsonrpc_getWaitingSub(self):
447 """Return list of room already joined by user""" 449 """Return list of room already joined by user"""
448 profile = session_iface.ISATSession(self.session).profile 450 profile = session_iface.ISATSession(self.session).profile
449 return self.sat_host.bridge.getWaitingSub(profile) 451 return self.sat_host.bridgeCall("getWaitingSub", profile)
450 452
451 def jsonrpc_setStatus(self, presence, status): 453 def jsonrpc_setStatus(self, presence, status):
452 """Change the presence and/or status 454 """Change the presence and/or status
453 @param presence: value from ("", "chat", "away", "dnd", "xa") 455 @param presence: value from ("", "chat", "away", "dnd", "xa")
454 @param status: any string to describe your status 456 @param status: any string to describe your status
455 """ 457 """
456 profile = session_iface.ISATSession(self.session).profile 458 profile = session_iface.ISATSession(self.session).profile
457 self.sat_host.bridge.setPresence('', presence, {'': status}, profile) 459 return self.sat_host.bridgeCall("setPresence", '', presence, {'': status}, profile)
458 460
459 def jsonrpc_messageSend(self, to_jid, msg, subject, type_, extra={}): 461 def jsonrpc_messageSend(self, to_jid, msg, subject, type_, extra={}):
460 """send message""" 462 """send message"""
461 profile = session_iface.ISATSession(self.session).profile 463 profile = session_iface.ISATSession(self.session).profile
462 return self.asyncBridgeCall("messageSend", to_jid, msg, subject, type_, extra, profile) 464 return self.asyncBridgeCall("messageSend", to_jid, msg, subject, type_, extra, profile)
538 @param max_items (int): maximum number of item to get or C.NO_LIMIT to get everything 540 @param max_items (int): maximum number of item to get or C.NO_LIMIT to get everything
539 @param extra (dict): TODO 541 @param extra (dict): TODO
540 @return (str): RT Deferred session id 542 @return (str): RT Deferred session id
541 """ 543 """
542 profile = session_iface.ISATSession(self.session).profile 544 profile = session_iface.ISATSession(self.session).profile
543 return self.sat_host.bridge.mbGetFromMany(publishers_type, publishers, max_items, extra, profile) 545 return self.sat_host.bridgeCall("mbGetFromMany", publishers_type, publishers, max_items, extra, profile)
544 546
545 def jsonrpc_mbGetFromManyRTResult(self, rt_session): 547 def jsonrpc_mbGetFromManyRTResult(self, rt_session):
546 """Get results from RealTime mbGetFromMany session 548 """Get results from RealTime mbGetFromMany session
547 549
548 @param rt_session (str): RT Deferred session id 550 @param rt_session (str): RT Deferred session id
561 @param rsm_comments_dict (dict): RSM data for comments only 563 @param rsm_comments_dict (dict): RSM data for comments only
562 @param profile_key: profile key 564 @param profile_key: profile key
563 @return (str): RT Deferred session id 565 @return (str): RT Deferred session id
564 """ 566 """
565 profile = session_iface.ISATSession(self.session).profile 567 profile = session_iface.ISATSession(self.session).profile
566 return self.sat_host.bridge.mbGetFromManyWithComments(publishers_type, publishers, max_items, max_comments, rsm_dict, rsm_comments_dict, profile) 568 return self.sat_host.bridgeCall("mbGetFromManyWithComments", publishers_type, publishers, max_items, max_comments, rsm_dict, rsm_comments_dict, profile)
567 569
568 def jsonrpc_mbGetFromManyWithCommentsRTResult(self, rt_session): 570 def jsonrpc_mbGetFromManyWithCommentsRTResult(self, rt_session):
569 """Get results from RealTime mbGetFromManyWithComments session 571 """Get results from RealTime mbGetFromManyWithComments session
570 572
571 @param rt_session (str): RT Deferred session id 573 @param rt_session (str): RT Deferred session id
678 # return d 680 # return d
679 681
680 def jsonrpc_getPresenceStatuses(self): 682 def jsonrpc_getPresenceStatuses(self):
681 """Get Presence information for connected contacts""" 683 """Get Presence information for connected contacts"""
682 profile = session_iface.ISATSession(self.session).profile 684 profile = session_iface.ISATSession(self.session).profile
683 return self.sat_host.bridge.getPresenceStatuses(profile) 685 return self.sat_host.bridgeCall("getPresenceStatuses", profile)
684 686
685 def jsonrpc_historyGet(self, from_jid, to_jid, size, between, search=''): 687 def jsonrpc_historyGet(self, from_jid, to_jid, size, between, search=''):
686 """Return history for the from_jid/to_jid couple""" 688 """Return history for the from_jid/to_jid couple"""
687 sat_session = session_iface.ISATSession(self.session) 689 sat_session = session_iface.ISATSession(self.session)
688 profile = sat_session.profile 690 profile = sat_session.profile
689 sat_jid = sat_session.jid 691 sat_jid = sat_session.jid
690 if not sat_jid: 692 if not sat_jid:
691 # we keep a session cache for jid to avoir jid spoofing 693 raise exceptions.InternalError('session jid should be set')
692 sat_jid = sat_session.jid = jid.JID(self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile))
693 if jid.JID(from_jid).userhost() != sat_jid.userhost() and jid.JID(to_jid).userhost() != sat_jid.userhost(): 694 if jid.JID(from_jid).userhost() != sat_jid.userhost() and jid.JID(to_jid).userhost() != sat_jid.userhost():
694 log.error(u"Trying to get history from a different jid (given (browser): {}, real (backend): {}), maybe a hack attempt ?".format(from_jid, sat_jid)) 695 log.error(u"Trying to get history from a different jid (given (browser): {}, real (backend): {}), maybe a hack attempt ?".format(from_jid, sat_jid))
695 return {} 696 return {}
696 d = self.asyncBridgeCall("historyGet", from_jid, to_jid, size, between, search, profile) 697 d = self.asyncBridgeCall("historyGet", from_jid, to_jid, size, between, search, profile)
697 698
723 @param room_jid (unicode): room JID or empty string to generate a unique name 724 @param room_jid (unicode): room JID or empty string to generate a unique name
724 """ 725 """
725 profile = session_iface.ISATSession(self.session).profile 726 profile = session_iface.ISATSession(self.session).profile
726 room_id = room_jid.split("@")[0] 727 room_id = room_jid.split("@")[0]
727 service = room_jid.split("@")[1] 728 service = room_jid.split("@")[1]
728 self.sat_host.bridge.inviteMUC(contact_jid, service, room_id, {}, profile) 729 return self.sat_host.bridgeCall("inviteMUC", contact_jid, service, room_id, {}, profile)
729 730
730 def jsonrpc_mucLeave(self, room_jid): 731 def jsonrpc_mucLeave(self, room_jid):
731 """Quit a Multi-User Chat room""" 732 """Quit a Multi-User Chat room"""
732 profile = session_iface.ISATSession(self.session).profile 733 profile = session_iface.ISATSession(self.session).profile
733 try: 734 try:
734 room_jid = jid.JID(room_jid) 735 room_jid = jid.JID(room_jid)
735 except: 736 except:
736 log.warning('Invalid room jid') 737 log.warning('Invalid room jid')
737 return 738 return
738 self.sat_host.bridge.mucLeave(room_jid.userhost(), profile) 739 return self.sat_host.bridgeCall("mucLeave", room_jid.userhost(), profile)
739 740
740 def jsonrpc_mucGetRoomsJoined(self): 741 def jsonrpc_mucGetRoomsJoined(self):
741 """Return list of room already joined by user""" 742 """Return list of room already joined by user"""
742 profile = session_iface.ISATSession(self.session).profile 743 profile = session_iface.ISATSession(self.session).profile
743 return self.sat_host.bridge.mucGetRoomsJoined(profile) 744 return self.sat_host.bridgeCall("mucGetRoomsJoined", profile)
744 745
745 def jsonrpc_mucGetDefaultService(self): 746 def jsonrpc_mucGetDefaultService(self):
746 """@return: the default MUC""" 747 """@return: the default MUC"""
747 d = self.asyncBridgeCall("mucGetDefaultService") 748 d = self.asyncBridgeCall("mucGetDefaultService")
748 return d 749 return d
752 753
753 @param other_players (list[unicode]): JIDs of the players to play with 754 @param other_players (list[unicode]): JIDs of the players to play with
754 @param room_jid (unicode): room JID or empty string to generate a unique name 755 @param room_jid (unicode): room JID or empty string to generate a unique name
755 """ 756 """
756 profile = session_iface.ISATSession(self.session).profile 757 profile = session_iface.ISATSession(self.session).profile
757 self.sat_host.bridge.tarotGameLaunch(other_players, room_jid, profile) 758 return self.sat_host.bridgeCall("tarotGameLaunch", other_players, room_jid, profile)
758 759
759 def jsonrpc_getTarotCardsPaths(self): 760 def jsonrpc_getTarotCardsPaths(self):
760 """Give the path of all the tarot cards""" 761 """Give the path of all the tarot cards"""
761 _join = os.path.join 762 _join = os.path.join
762 _media_dir = _join(self.sat_host.media_dir, '') 763 _media_dir = _join(self.sat_host.media_dir, '')
763 return map(lambda x: _join(C.MEDIA_DIR, x[len(_media_dir):]), glob.glob(_join(_media_dir, C.CARDS_DIR, '*_*.png'))) 764 return map(lambda x: _join(C.MEDIA_DIR, x[len(_media_dir):]), glob.glob(_join(_media_dir, C.CARDS_DIR, '*_*.png')))
764 765
765 def jsonrpc_tarotGameReady(self, player, referee): 766 def jsonrpc_tarotGameReady(self, player, referee):
766 """Tell to the server that we are ready to start the game""" 767 """Tell to the server that we are ready to start the game"""
767 profile = session_iface.ISATSession(self.session).profile 768 profile = session_iface.ISATSession(self.session).profile
768 self.sat_host.bridge.tarotGameReady(player, referee, profile) 769 return self.sat_host.bridgeCall("tarotGameReady", player, referee, profile)
769 770
770 def jsonrpc_tarotGamePlayCards(self, player_nick, referee, cards): 771 def jsonrpc_tarotGamePlayCards(self, player_nick, referee, cards):
771 """Tell to the server the cards we want to put on the table""" 772 """Tell to the server the cards we want to put on the table"""
772 profile = session_iface.ISATSession(self.session).profile 773 profile = session_iface.ISATSession(self.session).profile
773 self.sat_host.bridge.tarotGamePlayCards(player_nick, referee, cards, profile) 774 return self.sat_host.bridgeCall("tarotGamePlayCards", player_nick, referee, cards, profile)
774 775
775 def jsonrpc_launchRadioCollective(self, invited, room_jid=""): 776 def jsonrpc_launchRadioCollective(self, invited, room_jid=""):
776 """Create a room, invite people, and start a radio collective. 777 """Create a room, invite people, and start a radio collective.
777 778
778 @param invited (list[unicode]): JIDs of the contacts to play with 779 @param invited (list[unicode]): JIDs of the contacts to play with
779 @param room_jid (unicode): room JID or empty string to generate a unique name 780 @param room_jid (unicode): room JID or empty string to generate a unique name
780 """ 781 """
781 profile = session_iface.ISATSession(self.session).profile 782 profile = session_iface.ISATSession(self.session).profile
782 self.sat_host.bridge.radiocolLaunch(invited, room_jid, profile) 783 return self.sat_host.bridgeCall("radiocolLaunch", invited, room_jid, profile)
783 784
784 def jsonrpc_getEntitiesData(self, jids, keys): 785 def jsonrpc_getEntitiesData(self, jids, keys):
785 """Get cached data for several entities at once 786 """Get cached data for several entities at once
786 787
787 @param jids: list jids from who we wants data, or empty list for all jids in cache 788 @param jids: list jids from who we wants data, or empty list for all jids in cache
789 @return: requested data""" 790 @return: requested data"""
790 if not C.ALLOWED_ENTITY_DATA.issuperset(keys): 791 if not C.ALLOWED_ENTITY_DATA.issuperset(keys):
791 raise exceptions.PermissionError("Trying to access unallowed data (hack attempt ?)") 792 raise exceptions.PermissionError("Trying to access unallowed data (hack attempt ?)")
792 profile = session_iface.ISATSession(self.session).profile 793 profile = session_iface.ISATSession(self.session).profile
793 try: 794 try:
794 return self.sat_host.bridge.getEntitiesData(jids, keys, profile) 795 return self.sat_host.bridgeCall("getEntitiesData", jids, keys, profile)
795 except Exception as e: 796 except Exception as e:
796 raise failure.Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, unicode(e))) 797 raise failure.Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, unicode(e)))
797 798
798 def jsonrpc_getEntityData(self, jid, keys): 799 def jsonrpc_getEntityData(self, jid, keys):
799 """Get cached data for an entity 800 """Get cached data for an entity
803 @return: requested data""" 804 @return: requested data"""
804 if not C.ALLOWED_ENTITY_DATA.issuperset(keys): 805 if not C.ALLOWED_ENTITY_DATA.issuperset(keys):
805 raise exceptions.PermissionError("Trying to access unallowed data (hack attempt ?)") 806 raise exceptions.PermissionError("Trying to access unallowed data (hack attempt ?)")
806 profile = session_iface.ISATSession(self.session).profile 807 profile = session_iface.ISATSession(self.session).profile
807 try: 808 try:
808 return self.sat_host.bridge.getEntityData(jid, keys, profile) 809 return self.sat_host.bridgeCall("getEntityData", jid, keys, profile)
809 except Exception as e: 810 except Exception as e:
810 raise failure.Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, unicode(e))) 811 raise failure.Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, unicode(e)))
811 812
812 def jsonrpc_getCard(self, jid_): 813 def jsonrpc_getCard(self, jid_):
813 """Get VCard for entiry 814 """Get VCard for entiry
814 @param jid_: jid of contact from who we want data 815 @param jid_: jid of contact from who we want data
815 @return: id to retrieve the profile""" 816 @return: id to retrieve the profile"""
816 profile = session_iface.ISATSession(self.session).profile 817 profile = session_iface.ISATSession(self.session).profile
817 return self.sat_host.bridge.getCard(jid_, profile) 818 return self.sat_host.bridgeCall("getCard", jid_, profile)
818 819
819 @defer.inlineCallbacks 820 @defer.inlineCallbacks
820 def jsonrpc_avatarGet(self, entity, cache_only, hash_only): 821 def jsonrpc_avatarGet(self, entity, cache_only, hash_only):
821 session_data = session_iface.ISATSession(self.session) 822 session_data = session_iface.ISATSession(self.session)
822 profile = session_data.profile 823 profile = session_data.profile
831 832
832 def jsonrpc_getAccountDialogUI(self): 833 def jsonrpc_getAccountDialogUI(self):
833 """Get the dialog for managing user account 834 """Get the dialog for managing user account
834 @return: XML string of the XMLUI""" 835 @return: XML string of the XMLUI"""
835 profile = session_iface.ISATSession(self.session).profile 836 profile = session_iface.ISATSession(self.session).profile
836 return self.sat_host.bridge.getAccountDialogUI(profile) 837 return self.sat_host.bridgeCall("getAccountDialogUI", profile)
837 838
838 def jsonrpc_getParamsUI(self): 839 def jsonrpc_getParamsUI(self):
839 """Return the parameters XML for profile""" 840 """Return the parameters XML for profile"""
840 profile = session_iface.ISATSession(self.session).profile 841 profile = session_iface.ISATSession(self.session).profile
841 return self.asyncBridgeCall("getParamsUI", C.SECURITY_LIMIT, C.APP_NAME, profile) 842 return self.asyncBridgeCall("getParamsUI", C.SECURITY_LIMIT, C.APP_NAME, profile)
852 d = self.asyncBridgeCall("asyncGetParamA", param, category, attribute, C.SECURITY_LIMIT, profile_key=profile) 853 d = self.asyncBridgeCall("asyncGetParamA", param, category, attribute, C.SECURITY_LIMIT, profile_key=profile)
853 return d 854 return d
854 855
855 def jsonrpc_setParam(self, name, value, category): 856 def jsonrpc_setParam(self, name, value, category):
856 profile = session_iface.ISATSession(self.session).profile 857 profile = session_iface.ISATSession(self.session).profile
857 return self.sat_host.bridge.setParam(name, value, category, C.SECURITY_LIMIT, profile) 858 return self.sat_host.bridgeCall("setParam", name, value, category, C.SECURITY_LIMIT, profile)
858 859
859 def jsonrpc_launchAction(self, callback_id, data): 860 def jsonrpc_launchAction(self, callback_id, data):
860 #FIXME: any action can be launched, this can be a huge security issue if callback_id can be guessed 861 #FIXME: any action can be launched, this can be a huge security issue if callback_id can be guessed
861 # a security system with authorised callback_id must be implemented, similar to the one for authorised params 862 # a security system with authorised callback_id must be implemented, similar to the one for authorised params
862 profile = session_iface.ISATSession(self.session).profile 863 profile = session_iface.ISATSession(self.session).profile
866 def jsonrpc_chatStateComposing(self, to_jid_s): 867 def jsonrpc_chatStateComposing(self, to_jid_s):
867 """Call the method to process a "composing" state. 868 """Call the method to process a "composing" state.
868 @param to_jid_s: contact the user is composing to 869 @param to_jid_s: contact the user is composing to
869 """ 870 """
870 profile = session_iface.ISATSession(self.session).profile 871 profile = session_iface.ISATSession(self.session).profile
871 self.sat_host.bridge.chatStateComposing(to_jid_s, profile) 872 return self.sat_host.bridgeCall("chatStateComposing", to_jid_s, profile)
872 873
873 def jsonrpc_getNewAccountDomain(self): 874 def jsonrpc_getNewAccountDomain(self):
874 """@return: the domain for new account creation""" 875 """@return: the domain for new account creation"""
875 d = self.asyncBridgeCall("getNewAccountDomain") 876 d = self.asyncBridgeCall("getNewAccountDomain")
876 return d 877 return d
881 @param syntax_from: source syntax (e.g. "markdown") 882 @param syntax_from: source syntax (e.g. "markdown")
882 @param syntax_to: dest syntax (e.g.: "XHTML") 883 @param syntax_to: dest syntax (e.g.: "XHTML")
883 @param safe: clean resulting XHTML to avoid malicious code if True (forced here) 884 @param safe: clean resulting XHTML to avoid malicious code if True (forced here)
884 @return: converted text """ 885 @return: converted text """
885 profile = session_iface.ISATSession(self.session).profile 886 profile = session_iface.ISATSession(self.session).profile
886 return self.sat_host.bridge.syntaxConvert(text, syntax_from, syntax_to, True, profile) 887 return self.sat_host.bridgeCall("syntaxConvert", text, syntax_from, syntax_to, True, profile)
887 888
888 def jsonrpc_getLastResource(self, jid_s): 889 def jsonrpc_getLastResource(self, jid_s):
889 """Get the last active resource of that contact.""" 890 """Get the last active resource of that contact."""
890 profile = session_iface.ISATSession(self.session).profile 891 profile = session_iface.ISATSession(self.session).profile
891 return self.sat_host.bridge.getLastResource(jid_s, profile) 892 return self.sat_host.bridgeCall("getLastResource", jid_s, profile)
892 893
893 def jsonrpc_getFeatures(self): 894 def jsonrpc_getFeatures(self):
894 """Return the available features in the backend for profile""" 895 """Return the available features in the backend for profile"""
895 profile = session_iface.ISATSession(self.session).profile 896 profile = session_iface.ISATSession(self.session).profile
896 return self.sat_host.bridge.getFeatures(profile) 897 return self.sat_host.bridgeCall("getFeatures", profile)
897 898
898 def jsonrpc_skipOTR(self): 899 def jsonrpc_skipOTR(self):
899 """Tell the backend to leave OTR handling to Libervia.""" 900 """Tell the backend to leave OTR handling to Libervia."""
900 profile = session_iface.ISATSession(self.session).profile 901 profile = session_iface.ISATSession(self.session).profile
901 return self.sat_host.bridge.skipOTR(profile) 902 return self.sat_host.bridgeCall("skipOTR", profile)
902 903
903 def jsonrpc_namespacesGet(self): 904 def jsonrpc_namespacesGet(self):
904 return self.sat_host.bridgeCall('namespacesGet') 905 return self.sat_host.bridgeCall('namespacesGet')
905 906
906 907
1075 request.finish() 1076 request.finish()
1076 1077
1077 def jsonrpc_isConnected(self): 1078 def jsonrpc_isConnected(self):
1078 _session = self.request.getSession() 1079 _session = self.request.getSession()
1079 profile = session_iface.ISATSession(_session).profile 1080 profile = session_iface.ISATSession(_session).profile
1080 return self.sat_host.bridge.isConnected(profile) 1081 return self.sat_host.bridgeCall("isConnected", profile)
1081 1082
1082 def jsonrpc_connect(self): 1083 def jsonrpc_connect(self):
1083 _session = self.request.getSession() 1084 _session = self.request.getSession()
1084 profile = session_iface.ISATSession(_session).profile 1085 profile = session_iface.ISATSession(_session).profile
1085 if self.waiting_profiles.getRequest(profile): 1086 if self.waiting_profiles.getRequest(profile):
1086 raise jsonrpclib.Fault(1, C.ALREADY_WAITING) # FIXME: define some standard error codes for libervia 1087 raise jsonrpclib.Fault(1, C.ALREADY_WAITING) # FIXME: define some standard error codes for libervia
1087 self.waiting_profiles.setRequest(self.request, profile) 1088 self.waiting_profiles.setRequest(self.request, profile)
1088 self.sat_host.bridge.connect(profile) 1089 self.sat_host.bridgeCall("connect", profile)
1089 return server.NOT_DONE_YET 1090 return server.NOT_DONE_YET
1090 1091
1091 def jsonrpc_getSessionMetadata(self): 1092 def jsonrpc_getSessionMetadata(self):
1092 """Return metadata useful on session start 1093 """Return metadata useful on session start
1093 1094
1118 # self.sat_host.bridge.paramsRegisterApp(params, C.SECURITY_LIMIT, C.APP_NAME) 1119 # self.sat_host.bridge.paramsRegisterApp(params, C.SECURITY_LIMIT, C.APP_NAME)
1119 1120
1120 def jsonrpc_menusGet(self): 1121 def jsonrpc_menusGet(self):
1121 """Return the parameters XML for profile""" 1122 """Return the parameters XML for profile"""
1122 # XXX: we put this method in Register because we get menus before being logged 1123 # XXX: we put this method in Register because we get menus before being logged
1123 return self.sat_host.bridge.menusGet('', C.SECURITY_LIMIT) 1124 return self.sat_host.bridgeCall("menusGet", '', C.SECURITY_LIMIT)
1124 1125
1125 def _getSecurityWarning(self): 1126 def _getSecurityWarning(self):
1126 """@return: a security warning message, or None if the connection is secure""" 1127 """@return: a security warning message, or None if the connection is secure"""
1127 if self.request.URLPath().scheme == 'https' or not self.sat_host.options['security_warning']: 1128 if self.request.URLPath().scheme == 'https' or not self.sat_host.options['security_warning']:
1128 return None 1129 return None
1252 disconnect_delta = time.time() - self._last_service_prof_disconnect 1253 disconnect_delta = time.time() - self._last_service_prof_disconnect
1253 if disconnect_delta < 15: 1254 if disconnect_delta < 15:
1254 log.error(_(u'Service profile disconnected twice in a short time, please check connection')) 1255 log.error(_(u'Service profile disconnected twice in a short time, please check connection'))
1255 else: 1256 else:
1256 log.info(_(u"Service profile has been disconnected, but we need it! Reconnecting it...")) 1257 log.info(_(u"Service profile has been disconnected, but we need it! Reconnecting it..."))
1257 self.sat_host.bridge.connect(profile, 1258 d = self.sat_host.bridgeCall("connect", profile,
1258 self.sat_host.options['passphrase'], 1259 self.sat_host.options['passphrase'],
1259 {}, 1260 {},
1260 errback=lambda failure_: log.error(_(u"Can't reconnect service profile, please check connection: {reason}").format(reason=failure_))
1261 ) 1261 )
1262 d.addErrback(lambda failure_: log.error(_(u"Can't reconnect service profile, please check connection: {reason}").format(
1263 reason=failure_)))
1262 self._last_service_prof_disconnect = time.time() 1264 self._last_service_prof_disconnect = time.time()
1263 return 1265 return
1264 1266
1265 if not profile in self.sat_host.prof_connected: 1267 if not profile in self.sat_host.prof_connected:
1266 log.info(_(u"'disconnected' signal received for a not connected profile ({profile})").format(profile=profile)) 1268 log.info(_(u"'disconnected' signal received for a not connected profile ({profile})").format(profile=profile))
2092 if self.options['connection_type'] == 'both' and self.options['redirect_to_https']: 2094 if self.options['connection_type'] == 'both' and self.options['redirect_to_https']:
2093 reactor.listenTCP(self.options['port'], server.Site(RedirectToHTTPS(self.options['port'], self.options['port_https_ext']))) 2095 reactor.listenTCP(self.options['port'], server.Site(RedirectToHTTPS(self.options['port'], self.options['port_https_ext'])))
2094 else: 2096 else:
2095 reactor.listenTCP(self.options['port'], self.site) 2097 reactor.listenTCP(self.options['port'], self.site)
2096 2098
2099 @defer.inlineCallbacks
2097 def stopService(self): 2100 def stopService(self):
2098 log.info(_("launching cleaning methods")) 2101 log.info(_("launching cleaning methods"))
2099 for callback, args, kwargs in self._cleanup: 2102 for callback, args, kwargs in self._cleanup:
2100 callback(*args, **kwargs) 2103 callback(*args, **kwargs)
2101 try: 2104 try:
2102 self.bridge.disconnect(C.SERVICE_PROFILE) 2105 yield self.bridgeCall("disconnect", C.SERVICE_PROFILE)
2103 except Exception: 2106 except Exception:
2104 log.warning(u"Can't disconnect service profile") 2107 log.warning(u"Can't disconnect service profile")
2105 2108
2106 def run(self): 2109 def run(self):
2107 reactor.run() 2110 reactor.run()