Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0166.py @ 2129:6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 04 Feb 2017 17:59:13 +0100 |
parents | 2daf7b4c6756 |
children | 1d3f73e065e1 |
comparison
equal
deleted
inserted
replaced
2128:aa94f33fd2ad | 2129:6a66c8c5a567 |
---|---|
137 if jingle_condition is not None: | 137 if jingle_condition is not None: |
138 iq_elt.error.addElement((NS_JINGLE_ERROR, jingle_condition)) | 138 iq_elt.error.addElement((NS_JINGLE_ERROR, jingle_condition)) |
139 if error.STANZA_CONDITIONS[error_condition]['type'] == 'cancel' and sid: | 139 if error.STANZA_CONDITIONS[error_condition]['type'] == 'cancel' and sid: |
140 self._delSession(client, sid) | 140 self._delSession(client, sid) |
141 log.warning(u"Error while managing jingle session, cancelling: {condition}".format(error_condition)) | 141 log.warning(u"Error while managing jingle session, cancelling: {condition}".format(error_condition)) |
142 client.xmlstream.send(iq_elt) | 142 client.send(iq_elt) |
143 | 143 |
144 def terminate(self, reason, session, profile): | 144 def terminate(self, reason, session, profile): |
145 """Terminate the session | 145 """Terminate the session |
146 | 146 |
147 send the session-terminate action, and delete the session data | 147 send the session-terminate action, and delete the session data |
690 # there MUST be at least one content | 690 # there MUST be at least one content |
691 self.sendError('bad-request', session['id'], request, profile=client.profile) | 691 self.sendError('bad-request', session['id'], request, profile=client.profile) |
692 return | 692 return |
693 | 693 |
694 # at this point we can send the <iq/> result to confirm reception of the request | 694 # at this point we can send the <iq/> result to confirm reception of the request |
695 client.xmlstream.send(xmlstream.toResponse(request, 'result')) | 695 client.send(xmlstream.toResponse(request, 'result')) |
696 | 696 |
697 # we now request each application plugin confirmation | 697 # we now request each application plugin confirmation |
698 # and if all are accepted, we can accept the session | 698 # and if all are accepted, we can accept the session |
699 confirm_defers = self._callPlugins(XEP_0166.A_SESSION_INITIATE, session, 'jingleRequestConfirmation', None, self.jingleRequestConfirmationDefault, delete=False, profile=client.profile) | 699 confirm_defers = self._callPlugins(XEP_0166.A_SESSION_INITIATE, session, 'jingleRequestConfirmation', None, self.jingleRequestConfirmationDefault, delete=False, profile=client.profile) |
700 | 700 |
768 | 768 |
769 terminate_defers = self._callPlugins(XEP_0166.A_SESSION_TERMINATE, session, 'jingleTerminate', 'jingleTerminate', self._ignore, self._ignore, elements=False, force_element=reason_elt, profile=client.profile) | 769 terminate_defers = self._callPlugins(XEP_0166.A_SESSION_TERMINATE, session, 'jingleTerminate', 'jingleTerminate', self._ignore, self._ignore, elements=False, force_element=reason_elt, profile=client.profile) |
770 terminate_dlist = defer.DeferredList(terminate_defers) | 770 terminate_dlist = defer.DeferredList(terminate_defers) |
771 | 771 |
772 terminate_dlist.addCallback(lambda dummy: self._delSession(client, session['id'])) | 772 terminate_dlist.addCallback(lambda dummy: self._delSession(client, session['id'])) |
773 client.xmlstream.send(xmlstream.toResponse(request, 'result')) | 773 client.send(xmlstream.toResponse(request, 'result')) |
774 | 774 |
775 def onSessionAccept(self, client, request, jingle_elt, session): | 775 def onSessionAccept(self, client, request, jingle_elt, session): |
776 """Method called once session is accepted | 776 """Method called once session is accepted |
777 | 777 |
778 This method is only called for initiator | 778 This method is only called for initiator |
787 self._parseElements(jingle_elt, session, request, client) | 787 self._parseElements(jingle_elt, session, request, client) |
788 except exceptions.CancelError: | 788 except exceptions.CancelError: |
789 return | 789 return |
790 | 790 |
791 # at this point we can send the <iq/> result to confirm reception of the request | 791 # at this point we can send the <iq/> result to confirm reception of the request |
792 client.xmlstream.send(xmlstream.toResponse(request, 'result')) | 792 client.send(xmlstream.toResponse(request, 'result')) |
793 # and change the state | 793 # and change the state |
794 session['state'] = STATE_ACTIVE | 794 session['state'] = STATE_ACTIVE |
795 | 795 |
796 negociate_defers = [] | 796 negociate_defers = [] |
797 negociate_defers = self._callPlugins(XEP_0166.A_SESSION_ACCEPT, session, profile=client.profile) | 797 negociate_defers = self._callPlugins(XEP_0166.A_SESSION_ACCEPT, session, profile=client.profile) |
800 | 800 |
801 # after negociations we start the transfer | 801 # after negociations we start the transfer |
802 negociate_dlist.addCallback(lambda dummy: self._callPlugins(XEP_0166.A_START, session, app_method_name=None, elements=False, profile=client.profile)) | 802 negociate_dlist.addCallback(lambda dummy: self._callPlugins(XEP_0166.A_START, session, app_method_name=None, elements=False, profile=client.profile)) |
803 | 803 |
804 def _onSessionCb(self, result, client, request, jingle_elt, session): | 804 def _onSessionCb(self, result, client, request, jingle_elt, session): |
805 client.xmlstream.send(xmlstream.toResponse(request, 'result')) | 805 client.send(xmlstream.toResponse(request, 'result')) |
806 | 806 |
807 def _onSessionEb(self, failure_, client, request, jingle_elt, session): | 807 def _onSessionEb(self, failure_, client, request, jingle_elt, session): |
808 log.error(u"Error while handling onSessionInfo: {}".format(failure_.value)) | 808 log.error(u"Error while handling onSessionInfo: {}".format(failure_.value)) |
809 # XXX: only error managed so far, maybe some applications/transports need more | 809 # XXX: only error managed so far, maybe some applications/transports need more |
810 self.sendError('feature-not-implemented', None, request, 'unsupported-info', client.profile) | 810 self.sendError('feature-not-implemented', None, request, 'unsupported-info', client.profile) |
818 @param jingle_elt(domish.Element): the <jingle> element | 818 @param jingle_elt(domish.Element): the <jingle> element |
819 @param session(dict): session data | 819 @param session(dict): session data |
820 """ | 820 """ |
821 if not jingle_elt.children: | 821 if not jingle_elt.children: |
822 # this is a session ping, see XEP-0166 §6.8 | 822 # this is a session ping, see XEP-0166 §6.8 |
823 client.xmlstream.send(xmlstream.toResponse(request, 'result')) | 823 client.send(xmlstream.toResponse(request, 'result')) |
824 return | 824 return |
825 | 825 |
826 try: | 826 try: |
827 # XXX: session-info is most likely only used for application, so we don't call transport plugins | 827 # XXX: session-info is most likely only used for application, so we don't call transport plugins |
828 # if a future transport use it, this behaviour must be adapted | 828 # if a future transport use it, this behaviour must be adapted |
850 try: | 850 try: |
851 self._parseElements(jingle_elt, session, request, client, with_application=False) | 851 self._parseElements(jingle_elt, session, request, client, with_application=False) |
852 except exceptions.CancelError: | 852 except exceptions.CancelError: |
853 defer.returnValue(None) | 853 defer.returnValue(None) |
854 | 854 |
855 client.xmlstream.send(xmlstream.toResponse(request, 'result')) | 855 client.send(xmlstream.toResponse(request, 'result')) |
856 | 856 |
857 content_name = None | 857 content_name = None |
858 to_replace = [] | 858 to_replace = [] |
859 | 859 |
860 for content_name, content_data in session['contents'].iteritems(): | 860 for content_name, content_data in session['contents'].iteritems(): |
914 self._parseElements(jingle_elt, session, request, client, with_application=False) | 914 self._parseElements(jingle_elt, session, request, client, with_application=False) |
915 except exceptions.CancelError: | 915 except exceptions.CancelError: |
916 return | 916 return |
917 | 917 |
918 # at this point we can send the <iq/> result to confirm reception of the request | 918 # at this point we can send the <iq/> result to confirm reception of the request |
919 client.xmlstream.send(xmlstream.toResponse(request, 'result')) | 919 client.send(xmlstream.toResponse(request, 'result')) |
920 | 920 |
921 negociate_defers = [] | 921 negociate_defers = [] |
922 negociate_defers = self._callPlugins(XEP_0166.A_TRANSPORT_ACCEPT, session, app_method_name=None, profile=client.profile) | 922 negociate_defers = self._callPlugins(XEP_0166.A_TRANSPORT_ACCEPT, session, app_method_name=None, profile=client.profile) |
923 | 923 |
924 negociate_dlist = defer.DeferredList(negociate_defers) | 924 negociate_dlist = defer.DeferredList(negociate_defers) |
953 self._parseElements(jingle_elt, session, request, client, with_application=False) | 953 self._parseElements(jingle_elt, session, request, client, with_application=False) |
954 except exceptions.CancelError: | 954 except exceptions.CancelError: |
955 return | 955 return |
956 | 956 |
957 # The parsing was OK, we send the <iq> result | 957 # The parsing was OK, we send the <iq> result |
958 client.xmlstream.send(xmlstream.toResponse(request, 'result')) | 958 client.send(xmlstream.toResponse(request, 'result')) |
959 | 959 |
960 for content_name, content_data in session['contents'].iteritems(): | 960 for content_name, content_data in session['contents'].iteritems(): |
961 try: | 961 try: |
962 transport_elt = content_data.pop('transport_elt') | 962 transport_elt = content_data.pop('transport_elt') |
963 except KeyError: | 963 except KeyError: |