This commit is contained in:
Goffi 2011-09-29 14:59:14 +02:00
commit c64b06921b
3 changed files with 51 additions and 51 deletions

View file

@ -101,7 +101,7 @@ class XEP_0047():
failure_cb(sid, file_obj, NS_IBB, failure_reason)
def getProgress(self, sid, data):
"""Fill data with position of current transfert"""
"""Fill data with position of current transfer"""
try:
file_obj = self.current_stream[sid]["file_obj"]
data["position"] = str(file_obj.tell())
@ -134,11 +134,11 @@ class XEP_0047():
sid = open_elt.getAttribute('sid')
stanza = open_elt.getAttribute('stanza', 'iq')
if not sid or not block_size or int(block_size)>65535:
warning(_("malformed IBB transfert: %s" % IQ['id']))
warning(_("malformed IBB transfer: %s" % IQ['id']))
self.sendNotAcceptableError(IQ['id'], IQ['from'], xmlstream)
return
if not sid in self.current_stream:
warning(_("Ignoring unexpected IBB transfert: %s" % sid))
warning(_("Ignoring unexpected IBB transfer: %s" % sid))
self.sendNotAcceptableError(IQ['id'], IQ['from'], xmlstream)
return
if self.current_stream[sid]["from"] != jid.JID(IQ['from']):

View file

@ -109,11 +109,11 @@ class XEP_0095():
self.sendError(id, to_jid, 400, 'cancel', profile=profile)
def sendFailedError(self, id, to_jid, profile):
"""Helper method to send when we transfert failed
"""Helper method to send when we transfer failed
@param id: IQ id
@param to_jid: recipient
@param profile: %(doc_profile)s"""
self.sendError(id, to_jid, 500, 'cancel', {'custom':'failed'}, profile=profile) #as there is no error code for failed transfert, we use 500 (undefined-condition)
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)
def sendError(self, id, to_jid, err_code, err_type='cancel', data={}, profile='@NONE@'):
"""Send IQ error as a result

View file

@ -46,7 +46,7 @@ PLUGIN_INFO = {
"dependencies": ["XEP-0020", "XEP-0095", "XEP-0065", "XEP-0047"],
"main": "XEP_0096",
"handler": "no",
"description": _("""Implementation of SI File Transfert""")
"description": _("""Implementation of SI File Transfer""")
}
class XEP_0096():
@ -54,30 +54,30 @@ class XEP_0096():
def __init__(self, host):
info(_("Plugin XEP_0096 initialization"))
self.host = host
self._waiting_for_approval = {} #key = id, value = [transfert data, IdelayedCall Reactor timeout,
self._waiting_for_approval = {} #key = id, value = [transfer data, IdelayedCall Reactor timeout,
# current stream method, [failed stream methods], profile]
self.managed_stream_m = [#self.host.plugins["XEP-0065"].NS_BS,
self.host.plugins["XEP-0047"].NAMESPACE] #Stream methods managed
self.host.plugins["XEP-0095"].registerSIProfile(PROFILE_NAME, self.transfertRequest)
self.host.plugins["XEP-0095"].registerSIProfile(PROFILE_NAME, self.transferRequest)
host.bridge.addMethod("sendFile", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self.sendFile)
def _kill_id(self, approval_id):
"""Delete a waiting_for_approval id, called after timeout
@param approval_id: id of _waiting_for_approval"""
info(_("SI File Transfert: TimeOut reached for id %s") % approval_id);
info(_("SI File Transfer: TimeOut reached for id %s") % approval_id);
try:
del self._waiting_for_approval[approval_id]
except KeyError:
warning(_("kill id called on a non existant approval id"))
def transfertRequest(self, from_jid, si_id, si_mime_type, si_el, profile):
"""Called when a file transfert is requested
def transferRequest(self, from_jid, si_id, si_mime_type, si_el, profile):
"""Called when a file transfer is requested
@param from_jid: jid of the sender
@param si_id: Stream Initiation session id
@param si_mime_type: Mime type of the file (or default "application/octet-stream" if unknown)
@param si_el: domish.Element of the request
@param profile: %(doc_profile)s"""
info (_("XEP-0096 file transfert requested"))
info (_("XEP-0096 file transfer requested"))
debug(si_el.toXml())
filename = ""
file_size = ""
@ -123,11 +123,11 @@ class XEP_0096():
self.host.plugins["XEP-0095"].sendBadRequestError(si_id, from_jid, profile)
return
#if we are here, the transfert can start, we just need user's agreement
#if we are here, the transfer can start, we just need user's agreement
data={ "filename":filename, "from":from_jid, "size":file_size, "date":file_date, "hash":file_hash, "desc":file_desc, "can_range": str(can_range) }
self._waiting_for_approval[si_id] = [data, reactor.callLater(300, self._kill_id, si_id), stream_method, [], profile]
self.host.askConfirmation(si_id, "FILE_TRANSFERT", data, self.confirmationCB)
self.host.askConfirmation(si_id, "FILE_TRANSFER", data, self.confirmationCB)
def _getFileObject(self, dest_path, can_range = False):
@ -139,8 +139,8 @@ class XEP_0096():
def confirmationCB(self, id, accepted, frontend_data):
"""Called on confirmation answer
@param id: file transfert session id
@param accepted: True if file transfert is accepted
@param id: file transfer session id
@param accepted: True if file transfer is accepted
@param frontend_data: data sent by frontend"""
data, timeout, stream_method, failed_methods, profile = self._waiting_for_approval[id]
can_range = data['can_range'] == "True"
@ -161,7 +161,7 @@ class XEP_0096():
range_offset = file_obj.tell()
self.host.plugins["XEP-0047"].prepareToReceive(jid.JID(data['from']), id, file_obj, int(data["size"]), self._transferSucceeded, self._transferFailed)
else:
error(_("Unknown stream method, this should not happen at this stage, cancelling transfert"))
error(_("Unknown stream method, this should not happen at this stage, cancelling transfer"))
del(self._waiting_for_approval[id])
return
@ -176,29 +176,29 @@ class XEP_0096():
misc_elts.append(range_elt)
self.host.plugins["XEP-0095"].acceptStream(id, data['from'], feature_elt, misc_elts, profile)
else:
debug (_("Transfert [%s] refused"), id)
debug (_("Transfer [%s] refused"), id)
self.host.plugins["XEP-0095"].sendRejectedError (id, data['from'], profile=profile)
del(self._waiting_for_approval[id])
def _transferSucceeded(self, sid, file_obj, stream_method):
"""Called by the stream method when transfert successfuly finished
"""Called by the stream method when transfer successfuly finished
@param id: stream id"""
file_obj.close()
info(_('Transfert %s successfuly finished') % sid)
info(_('Transfer %s successfuly finished') % sid)
del(self._waiting_for_approval[sid])
def _transferFailed(self, sid, file_obj, stream_method, reason):
"""Called when something went wrong with the transfert
"""Called when something went wrong with the transfer
@param id: stream id
@param reason: can be TIMEOUT, IO_ERROR, PROTOCOL_ERROR"""
data, timeout, stream_method, failed_methods, profile = self._waiting_for_approval[sid]
warning(_('Transfert %(id)s failed with stream method %(s_method)s') % { 'id': sid,
warning(_('Transfer %(id)s failed with stream method %(s_method)s') % { 'id': sid,
's_method': stream_method })
filepath = file_obj.name
file_obj.close()
os.remove(filepath)
#TODO: session remenber (within a time limit) when a stream method fail, and avoid that stream method with full jid for the rest of the session
warning(_("All stream methods failed, can't transfert the file"))
warning(_("All stream methods failed, can't transfer the file"))
self.host.plugins["XEP-0095"].sendFailedError(id, data['from'], profile)
del(self._waiting_for_approval[id])
@ -206,10 +206,10 @@ class XEP_0096():
if IQ['type'] == "error":
stanza_err = jab_error.exceptionFromStanza(IQ)
if stanza_err.code == '403' and stanza_err.condition == 'forbidden':
debug(_("File transfert refused by %s") % IQ['from'])
debug(_("File transfer refused by %s") % IQ['from'])
self.host.bridge.newAlert(_("The contact %s refused your file") % IQ['from'], _("File refused"), "INFO", profile)
else:
warning(_("Error during file transfert with %s") % IQ['from'])
warning(_("Error during file transfer with %s") % IQ['from'])
self.host.bridge.newAlert(_("Something went wrong during the file transfer session intialisation with %s") % IQ['from'], _("File transfer error"), "ERROR", profile)
return
@ -248,8 +248,8 @@ class XEP_0096():
#query=offer.addElement('query', 'http://jabber.org/protocol/bytestreams')
query['mode']='tcp'
streamhost=query.addElement('streamhost')
streamhost['host']=self.host.memory.getParamA("IP", "File Transfert")
streamhost['port']=self.host.memory.getParamA("Port", "File Transfert")
streamhost['host']=self.host.memory.getParamA("IP", "File Transfer")
streamhost['port']=self.host.memory.getParamA("Port", "File Transfer")
streamhost['jid']=current_jid.full()
offer.send()"""
elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE:
@ -267,7 +267,7 @@ class XEP_0096():
@data: dictionnary with the optional following keys:
- "description": description of the file
@param profile_key: %(doc_profile_key)s
@return: an unique id to identify the transfert
@return: an unique id to identify the transfer
"""
profile = self.host.memory.getProfileName(profile_key)
if not profile:
@ -298,4 +298,4 @@ class XEP_0096():
def sendFailureCb(self, sid, file_obj, stream_method, reason):
file_obj.close()
warning(_('Transfert %(id)s failed with stream method %(s_method)s') % { 'id': sid, s_method: stream_method })
warning(_('Transfer %(id)s failed with stream method %(s_method)s') % { 'id': sid, s_method: stream_method })