comparison src/plugins/plugin_xep_0047.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 c513328ade9d
comparison
equal deleted inserted replaced
393:393b35aa86d2 394:8f3551ceee17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 from logging import debug, info, warning, error 22 from logging import debug, info, warning, error
23 from twisted.internet import protocol
24 from twisted.words.protocols.jabber import client, jid 23 from twisted.words.protocols.jabber import client, jid
25 from twisted.words.protocols.jabber import error as jab_error 24 from twisted.words.protocols.jabber import error as jab_error
26 from twisted.words.xish import domish 25 from twisted.words.xish import domish
27 import twisted.internet.error 26 import twisted.internet.error
28 from twisted.internet import reactor 27 from twisted.internet import reactor
83 warning(_("kill id called on a non existant id")) 82 warning(_("kill id called on a non existant id"))
84 return 83 return
85 if self.current_stream[sid].has_key("observer_cb"): 84 if self.current_stream[sid].has_key("observer_cb"):
86 xmlstream = self.current_stream[sid]["xmlstream"] 85 xmlstream = self.current_stream[sid]["xmlstream"]
87 xmlstream.removeObserver(self.current_stream[sid]["event_data"], self.current_stream[sid]["observer_cb"]) 86 xmlstream.removeObserver(self.current_stream[sid]["event_data"], self.current_stream[sid]["observer_cb"])
88 self.current_stream[sid]['timer'].cancel() 87 if self.current_stream[sid]['timer'].active():
88 self.current_stream[sid]['timer'].cancel()
89 if self.current_stream[sid].has_key("size"): 89 if self.current_stream[sid].has_key("size"):
90 self.host.removeProgressCB(sid) 90 self.host.removeProgressCB(sid)
91 91
92 file_obj = self.current_stream[sid]['file_obj'] 92 file_obj = self.current_stream[sid]['file_obj']
93 success_cb = self.current_stream[sid]['success_cb'] 93 success_cb = self.current_stream[sid]['success_cb']
110 pass 110 pass
111 111
112 def prepareToReceive(self, from_jid, sid, file_obj, size, success_cb, failure_cb): 112 def prepareToReceive(self, from_jid, sid, file_obj, size, success_cb, failure_cb):
113 """Called when a bytestream is imminent 113 """Called when a bytestream is imminent
114 @param from_jid: jid of the sender 114 @param from_jid: jid of the sender
115 @param id: Stream id 115 @param sid: Stream id
116 @param file_obj: File Object where the data will be written""" 116 @param file_obj: File object where data will be written
117 @param size: full size of the data, or None if unknown
118 @param success_cb: method to call when successfuly finished
119 @param failure_cb: method to call when something goes wrong"""
117 data = self.current_stream[sid] = {} 120 data = self.current_stream[sid] = {}
118 data["from"] = from_jid 121 data["from"] = from_jid
119 data["file_obj"] = file_obj 122 data["file_obj"] = file_obj
120 data["seq"] = -1 123 data["seq"] = -1
121 if size: 124 if size:
286 iq_elt.send() 289 iq_elt.send()
287 290
288 def iqResult(self, sid, seq, length, iq_elt): 291 def iqResult(self, sid, seq, length, iq_elt):
289 """Called when the result of open iq is received""" 292 """Called when the result of open iq is received"""
290 data = self.current_stream[sid] 293 data = self.current_stream[sid]
291 if iq_elt.type == "error": 294 if iq_elt["type"] == "error":
292 warning(_("Transfer failed")) 295 warning(_("Transfer failed"))
293 self.terminateStream(sid, "IQ_ERROR") 296 self.terminateStream(sid, "IQ_ERROR")
294 return 297 return
295 298
296 buffer = data["file_obj"].read(data["block_size"]) 299 buffer = data["file_obj"].read(data["block_size"])