comparison src/plugins/plugin_xep_0095.py @ 394:8f3551ceee17

plugin XEP-0065: refactored and misc stuff fixed. Still not finished plugins XEP-0096: XEP-0065 (Socks5 stream method) managed
author Goffi <goffi@goffi.org>
date Mon, 03 Oct 2011 18:05:15 +0200
parents c34fd9d6242e
children cb0285372818
comparison
equal deleted inserted replaced
393:393b35aa86d2 394:8f3551ceee17
84 self.si_profiles[si_profile_key](iq_el['from'], si_id, si_mime_type, si_el, profile) 84 self.si_profiles[si_profile_key](iq_el['from'], si_id, si_mime_type, si_el, profile)
85 else: 85 else:
86 #We don't know this profile, we send an error 86 #We don't know this profile, we send an error
87 self.sendBadProfileError(iq_el['id'], iq_el['from'], profile) 87 self.sendBadProfileError(iq_el['id'], iq_el['from'], profile)
88 88
89 def sendRejectedError(self, id, to_jid, reason = 'Offer Declined', profile='@NONE@'): 89 def sendRejectedError(self, iq_id, to_jid, reason = 'Offer Declined', profile='@NONE@'):
90 """Helper method to send when the stream is rejected 90 """Helper method to send when the stream is rejected
91 @param id: IQ id 91 @param iq_id: IQ id
92 @param to_jid: recipient 92 @param to_jid: recipient
93 @param reason: human readable reason (string) 93 @param reason: human readable reason (string)
94 @param profile: %(doc_profile)s""" 94 @param profile: %(doc_profile)s"""
95 self.sendError(id, to_jid, 403, 'cancel', {'text':reason}, profile=profile) 95 self.sendError(iq_id, to_jid, 403, 'cancel', {'text':reason}, profile=profile)
96 96
97 def sendBadProfileError(self, id, to_jid, profile): 97 def sendBadProfileError(self, iq_id, to_jid, profile):
98 """Helper method to send when we don't know the SI profile 98 """Helper method to send when we don't know the SI profile
99 @param id: IQ id 99 @param iq_id: IQ id
100 @param to_jid: recipient 100 @param to_jid: recipient
101 @param profile: %(doc_profile)s""" 101 @param profile: %(doc_profile)s"""
102 self.sendError(id, to_jid, 400, 'modify', profile=profile) 102 self.sendError(iq_id, to_jid, 400, 'modify', profile=profile)
103 103
104 def sendBadRequestError(self, id, to_jid, profile): 104 def sendBadRequestError(self, iq_id, to_jid, profile):
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 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(id, to_jid, 400, 'cancel', profile=profile) 109 self.sendError(iq_id, to_jid, 400, 'cancel', profile=profile)
110 110
111 def sendFailedError(self, 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 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(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, 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 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)
123 @param err_type: one of cancel, modify 123 @param err_type: one of cancel, modify
124 @param data: error specific data (dictionary) 124 @param data: error specific data (dictionary)
125 @param profile: %(doc_profile)s 125 @param profile: %(doc_profile)s
126 """ 126 """
127 client = self.host.getClient(profile) 127 client = self.host.getClient(profile)
128 assert(client) 128 assert(client)
129 result = domish.Element(('', 'iq')) 129 result = domish.Element(('', 'iq'))
130 result['type'] = 'result' 130 result['type'] = 'result'
131 result['id'] = 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':
148 if data.has_key('custom') and data['custom']=='failed': 148 if data.has_key('custom') and data['custom']=='failed':
149 condition_el.addContent('Stream failed') 149 condition_el.addContent('Stream failed')
150 150
151 client.xmlstream.send(result) 151 client.xmlstream.send(result)
152 152
153 def acceptStream(self, id, to_jid, feature_elt, misc_elts=[], profile='@NONE@'): 153 def acceptStream(self, iq_id, to_jid, feature_elt, misc_elts=[], profile='@NONE@'):
154 """Send the accept stream initiation answer 154 """Send the accept stream initiation answer
155 @param id: stream initiation id 155 @param iq_id: IQ id
156 @param feature_elt: domish element 'feature' containing stream method to use 156 @param feature_elt: domish element 'feature' containing stream method to use
157 @param misc_elts: list of domish element to add 157 @param misc_elts: list of domish element to add
158 @param profile: %(doc_profile)s""" 158 @param profile: %(doc_profile)s"""
159 client = self.host.getClient(profile) 159 client = self.host.getClient(profile)
160 assert(client) 160 assert(client)
161 info (_("sending stream initiation accept answer")) 161 info (_("sending stream initiation accept answer"))
162 result = domish.Element(('', 'iq')) 162 result = domish.Element(('', 'iq'))
163 result['type'] = 'result' 163 result['type'] = 'result'
164 result['id'] = 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)