Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0095.py @ 587:952322b1d490
Remove trailing whitespaces.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:34 +0100 |
parents | ca13633d3b6b |
children | beaf6bec2fcd |
comparison
equal
deleted
inserted
replaced
586:6a718ede8be1 | 587:952322b1d490 |
---|---|
56 | 56 |
57 def __init__(self, host): | 57 def __init__(self, host): |
58 info(_("Plugin XEP_0095 initialization")) | 58 info(_("Plugin XEP_0095 initialization")) |
59 self.host = host | 59 self.host = host |
60 self.si_profiles = {} #key: SI profile, value: callback | 60 self.si_profiles = {} #key: SI profile, value: callback |
61 | 61 |
62 def getHandler(self, profile): | 62 def getHandler(self, profile): |
63 return XEP_0095_handler(self) | 63 return XEP_0095_handler(self) |
64 | 64 |
65 def registerSIProfile(self, si_profile, callback): | 65 def registerSIProfile(self, si_profile, callback): |
66 """Add a callback for a SI Profile | 66 """Add a callback for a SI Profile |
67 param si_profile: SI profile name (e.g. file-transfer) | 67 param si_profile: SI profile name (e.g. file-transfer) |
68 param callback: method to call when the profile name is asked""" | 68 param callback: method to call when the profile name is asked""" |
105 """Helper method to send when we don't know the SI profile | 105 """Helper method to send when we don't know the SI profile |
106 @param iq_id: IQ id | 106 @param iq_id: IQ id |
107 @param to_jid: recipient | 107 @param to_jid: recipient |
108 @param profile: %(doc_profile)s""" | 108 @param profile: %(doc_profile)s""" |
109 self.sendError(iq_id, to_jid, 400, 'cancel', profile=profile) | 109 self.sendError(iq_id, to_jid, 400, 'cancel', profile=profile) |
110 | 110 |
111 def sendFailedError(self, iq_id, to_jid, profile): | 111 def sendFailedError(self, iq_id, to_jid, profile): |
112 """Helper method to send when we transfer failed | 112 """Helper method to send when we transfer failed |
113 @param iq_id: IQ id | 113 @param iq_id: IQ id |
114 @param to_jid: recipient | 114 @param to_jid: recipient |
115 @param profile: %(doc_profile)s""" | 115 @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) | 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 | 117 |
118 def sendError(self, iq_id, to_jid, err_code, err_type='cancel', data={}, profile='@NONE@'): | 118 def sendError(self, iq_id, to_jid, err_code, err_type='cancel', data={}, profile='@NONE@'): |
119 """Send IQ error as a result | 119 """Send IQ error as a result |
120 @param iq_id: IQ id | 120 @param iq_id: IQ id |
121 @param to_jid: recipient | 121 @param to_jid: recipient |
122 @param err_code: error err_code (see XEP-0095 #4.2) | 122 @param err_code: error err_code (see XEP-0095 #4.2) |
127 _client = self.host.getClient(profile) | 127 _client = self.host.getClient(profile) |
128 assert(_client) | 128 assert(_client) |
129 result = domish.Element((None, 'iq')) | 129 result = domish.Element((None, 'iq')) |
130 result['type'] = 'result' | 130 result['type'] = 'result' |
131 result['id'] = iq_id | 131 result['id'] = iq_id |
132 result['to'] = to_jid | 132 result['to'] = to_jid |
133 error_el = result.addElement('error') | 133 error_el = result.addElement('error') |
134 error_el['err_code'] = str(err_code) | 134 error_el['err_code'] = str(err_code) |
135 error_el['type'] = err_type | 135 error_el['type'] = err_type |
136 if err_code==400 and err_type=='cancel': | 136 if err_code==400 and err_type=='cancel': |
137 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','bad-request')) | 137 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','bad-request')) |
160 assert(_client) | 160 assert(_client) |
161 info (_("sending stream initiation accept answer")) | 161 info (_("sending stream initiation accept answer")) |
162 result = domish.Element((None, 'iq')) | 162 result = domish.Element((None, 'iq')) |
163 result['type'] = 'result' | 163 result['type'] = 'result' |
164 result['id'] = iq_id | 164 result['id'] = iq_id |
165 result['to'] = to_jid | 165 result['to'] = to_jid |
166 si = result.addElement('si', NS_SI) | 166 si = result.addElement('si', NS_SI) |
167 si.addChild(feature_elt) | 167 si.addChild(feature_elt) |
168 for elt in misc_elts: | 168 for elt in misc_elts: |
169 si.addChild(elt) | 169 si.addChild(elt) |
170 _client.xmlstream.send(result) | 170 _client.xmlstream.send(result) |
180 @return: session id, offer""" | 180 @return: session id, offer""" |
181 current_jid, xmlstream = self.host.getJidNStream(profile_key) | 181 current_jid, xmlstream = self.host.getJidNStream(profile_key) |
182 if not xmlstream: | 182 if not xmlstream: |
183 error (_('Asking for an non-existant or not connected profile')) | 183 error (_('Asking for an non-existant or not connected profile')) |
184 return "" | 184 return "" |
185 | 185 |
186 offer = client.IQ(xmlstream,'set') | 186 offer = client.IQ(xmlstream,'set') |
187 sid = str(uuid.uuid4()) | 187 sid = str(uuid.uuid4()) |
188 debug (_("Stream Session ID: %s") % offer["id"]) | 188 debug (_("Stream Session ID: %s") % offer["id"]) |
189 | 189 |
190 offer["from"] = current_jid.full() | 190 offer["from"] = current_jid.full() |
191 offer["to"] = to_jid.full() | 191 offer["to"] = to_jid.full() |
192 si=offer.addElement('si',NS_SI) | 192 si=offer.addElement('si',NS_SI) |
198 si.addChild(feature_elt) | 198 si.addChild(feature_elt) |
199 | 199 |
200 offer.send() | 200 offer.send() |
201 return sid, offer | 201 return sid, offer |
202 | 202 |
203 | 203 |
204 class XEP_0095_handler(XMPPHandler): | 204 class XEP_0095_handler(XMPPHandler): |
205 implements(iwokkel.IDisco) | 205 implements(iwokkel.IDisco) |
206 | 206 |
207 def __init__(self, plugin_parent): | 207 def __init__(self, plugin_parent): |
208 self.plugin_parent = plugin_parent | 208 self.plugin_parent = plugin_parent |
209 self.host = plugin_parent.host | 209 self.host = plugin_parent.host |
210 | 210 |
211 def connectionInitialized(self): | 211 def connectionInitialized(self): |