Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0095.py @ 916:1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 21 Mar 2014 16:27:09 +0100 |
parents | 1fe00f0c9a91 |
children | c6d8fc63b1db |
comparison
equal
deleted
inserted
replaced
915:6f96ee4d8cc0 | 916:1a759096ccbd |
---|---|
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | |
21 from logging import debug, info, error | 22 from logging import debug, info, error |
22 from twisted.words.xish import domish | 23 from twisted.words.xish import domish |
23 from twisted.internet import protocol | 24 from twisted.internet import protocol |
24 from twisted.words.protocols.jabber import client, jid | 25 from twisted.words.protocols.jabber import client, jid |
25 from twisted.words.protocols.jabber import error as jab_error | 26 from twisted.words.protocols.jabber import error as jab_error |
84 self.si_profiles[si_profile_key](iq_el['id'], iq_el['from'], si_id, si_mime_type, si_el, profile) | 85 self.si_profiles[si_profile_key](iq_el['id'], iq_el['from'], si_id, si_mime_type, si_el, profile) |
85 else: | 86 else: |
86 #We don't know this profile, we send an error | 87 #We don't know this profile, we send an error |
87 self.sendBadProfileError(iq_el['id'], iq_el['from'], profile) | 88 self.sendBadProfileError(iq_el['id'], iq_el['from'], profile) |
88 | 89 |
89 def sendRejectedError(self, iq_id, to_jid, reason='Offer Declined', profile='@NONE@'): | 90 def sendRejectedError(self, iq_id, to_jid, reason='Offer Declined', profile=C.PROF_KEY_NONE): |
90 """Helper method to send when the stream is rejected | 91 """Helper method to send when the stream is rejected |
91 @param iq_id: IQ id | 92 @param iq_id: IQ id |
92 @param to_jid: recipient | 93 @param to_jid: recipient |
93 @param reason: human readable reason (string) | 94 @param reason: human readable reason (string) |
94 @param profile: %(doc_profile)s""" | 95 @param profile: %(doc_profile)s""" |
113 @param iq_id: IQ id | 114 @param iq_id: IQ id |
114 @param to_jid: recipient | 115 @param to_jid: recipient |
115 @param profile: %(doc_profile)s""" | 116 @param profile: %(doc_profile)s""" |
116 self.sendError(iq_id, to_jid, 500, 'cancel', {'custom': 'failed'}, profile=profile) # as there is no error code for failed transfer, we use 500 (undefined-condition) | 117 self.sendError(iq_id, to_jid, 500, 'cancel', {'custom': 'failed'}, profile=profile) # as there is no error code for failed transfer, we use 500 (undefined-condition) |
117 | 118 |
118 def sendError(self, iq_id, to_jid, err_code, err_type='cancel', data={}, profile='@NONE@'): | 119 def sendError(self, iq_id, to_jid, err_code, err_type='cancel', data={}, profile=C.PROF_KEY_NONE): |
119 """Send IQ error as a result | 120 """Send IQ error as a result |
120 @param iq_id: IQ id | 121 @param iq_id: IQ id |
121 @param to_jid: recipient | 122 @param to_jid: recipient |
122 @param err_code: error err_code (see XEP-0095 #4.2) | 123 @param err_code: error err_code (see XEP-0095 #4.2) |
123 @param err_type: one of cancel, modify | 124 @param err_type: one of cancel, modify |
148 if 'custom' in data and data['custom'] == 'failed': | 149 if 'custom' in data and data['custom'] == 'failed': |
149 condition_el.addContent('Stream failed') | 150 condition_el.addContent('Stream failed') |
150 | 151 |
151 _client.xmlstream.send(result) | 152 _client.xmlstream.send(result) |
152 | 153 |
153 def acceptStream(self, iq_id, to_jid, feature_elt, misc_elts=[], profile='@NONE@'): | 154 def acceptStream(self, iq_id, to_jid, feature_elt, misc_elts=[], profile=C.PROF_KEY_NONE): |
154 """Send the accept stream initiation answer | 155 """Send the accept stream initiation answer |
155 @param iq_id: IQ id | 156 @param iq_id: IQ id |
156 @param feature_elt: domish element 'feature' containing stream method to use | 157 @param feature_elt: domish element 'feature' containing stream method to use |
157 @param misc_elts: list of domish element to add | 158 @param misc_elts: list of domish element to add |
158 @param profile: %(doc_profile)s""" | 159 @param profile: %(doc_profile)s""" |
167 si.addChild(feature_elt) | 168 si.addChild(feature_elt) |
168 for elt in misc_elts: | 169 for elt in misc_elts: |
169 si.addChild(elt) | 170 si.addChild(elt) |
170 _client.xmlstream.send(result) | 171 _client.xmlstream.send(result) |
171 | 172 |
172 def proposeStream(self, to_jid, si_profile, feature_elt, misc_elts, mime_type='application/octet-stream', profile_key='@NONE@'): | 173 def proposeStream(self, to_jid, si_profile, feature_elt, misc_elts, mime_type='application/octet-stream', profile_key=C.PROF_KEY_NONE): |
173 """Propose a stream initiation | 174 """Propose a stream initiation |
174 @param to_jid: recipient (JID) | 175 @param to_jid: recipient (JID) |
175 @param si_profile: Stream initiation profile (XEP-0095) | 176 @param si_profile: Stream initiation profile (XEP-0095) |
176 @param feature_elt: feature domish element, according to XEP-0020 | 177 @param feature_elt: feature domish element, according to XEP-0020 |
177 @param misc_elts: list of domish element to add for this profile | 178 @param misc_elts: list of domish element to add for this profile |