From fe1d3004ccf6ec30296bc9b894ddfa2925f2a27b Mon Sep 17 00:00:00 2001 From: Brian Beggs Date: Fri, 2 Jul 2010 02:17:48 +0800 Subject: xep_0047 initial module checkin --- sleekxmpp/plugins/xep_0047.py | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 sleekxmpp/plugins/xep_0047.py diff --git a/sleekxmpp/plugins/xep_0047.py b/sleekxmpp/plugins/xep_0047.py new file mode 100644 index 00000000..beaadcdc --- /dev/null +++ b/sleekxmpp/plugins/xep_0047.py @@ -0,0 +1,52 @@ +''' +Created on Jul 1, 2010 + +@author: bbeggs +''' +from . import base +import logging +import threading +from xml.etree import cElementTree as ET + +class xep_0047(base.base_plugin): + ''' + In-band file transfer for xmpp. + + Both message and iq transfer is supported with message being attempted first. + ''' + + def plugin_init(self): + self.xep = 'xep-047' + self.description = 'in-band file transfer' + self.acceptTransfers = self.config.get('acceptTransfers', True) + self.saveDirectory = self.config.get('saveDirectory', '/tmp') + self.stanzaType = self.config.get('stanzaType', 'message') + self.maxSendThreads = self.config.get('maxSendThreads', 1) + self.maxReceiveThreads = self.config.get('maxReceiveThreads', 1) + + #thread setup + self.receiveThreads = {} #id:thread + self.sendThreads = {} + + #add handlers to listen for incoming requests + self.xmpp.add_handler("", self._handleIncomingTransferRequest) + + def post_init(self): + self.post_inited = True + + + def sendFile(self, filePath, threaded=True): + #TODO use this method to send a file + pass + + def _handleIncomingTransferRequest(self, xml): + pass + +class receiverThread(threading.Thread): + def run(self): + pass + +class senderThread(threading.Thread): + def run(self): + pass + -- cgit v1.2.3 From 4b00baab1e99efe0a075116337422da4eb18b37f Mon Sep 17 00:00:00 2001 From: Brian Beggs Date: Fri, 2 Jul 2010 21:34:43 +0800 Subject: reconnection fix: xmlstream now catches XMLParserError and restarts the stream --- sleekxmpp/xmlstream/xmlstream.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index 842dfee2..1fb3f8bb 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -42,9 +42,6 @@ if sys.version_info < (3, 0): class RestartStream(Exception): pass -class CloseStream(Exception): - pass - stanza_extensions = {} RECONNECT_MAX_DELAY = 3600 @@ -225,9 +222,6 @@ class XMLStream(object): except socket.timeout: logging.debug('socket rcv timeout') pass - except CloseStream: - # TODO warn that the listener thread is exiting!!! - pass except RestartStream: logging.debug("Restarting stream...") continue # DON'T re-initialize the stream -- this exception is sent @@ -236,13 +230,14 @@ class XMLStream(object): logging.debug("System interrupt detected") self.shutdown() self.eventqueue.put(('quit', None, None)) - except cElementTree.XMLParserError: + except cElementTree.XMLParserError: #if there is an xml parsing exception, assume stream needs to be restarted logging.warn('XML RCV parsing error!', exc_info=1) - # don't restart the stream on an XML parse error. + if self.should_reconnect: self.disconnect(reconnect=True) + else: self.disconnect() except: logging.exception('Unexpected error in RCV thread') - if self.should_reconnect: - self.disconnect(reconnect=True) + if self.should_reconnect: self.disconnect(reconnect=True) + else: self.disconnect() logging.debug('Quitting Process thread') -- cgit v1.2.3