# HG changeset patch # User Charly COSTE # Date 1259358447 -3600 # Node ID 59401ac0f47a2091ac8c69732cf4b970b75bc1dc # Parent ec4fbec1f160e44bfee97e655caba0902faecf06 handle XMPP remote-server-not-found Signed-off-by: Charly COSTE diff --git a/bot.py b/bot.py --- a/bot.py +++ b/bot.py @@ -257,6 +257,35 @@ class bot(Thread): if p != None: bridge.removeParticipant('xmpp', resource, presence.getStatus()) + elif presence.getType() == 'error': + error = presence.getTag('error') + if error: + for c in error.getChildren(): + if c.getNamespace() == 'urn:ietf:params:xml:ns:xmpp-stanzas' and c.getName() != 'text': + err = error.getAttr('type')+' '+c.getName() + if err == 'cancel remote-server-not-found': + # Remote server not found + error_message = '[Error] XMPP Remote server not found: '+from_.getDomain() + + # Stop bridges that depend on this server + bridges = self.findBridges([from_.getDomain()]) + if len(bridges) > 0: + error_message += '\nThese bridges will be stopped:' + for b in bridges: + error_message += '\n'+str(b) + if hasattr(b, 'reconnecting'): + leave_message = 'MUC server seems to be down' + else: + leave_message = 'MUC server seems to be down, will try to recreate the bridge in 1 minute' + self.reconnecting = True + self.irc.execute_delayed(60, b.init2) + b.stop(message=leave_message) + + self.error(error_message, send_to_admins=True) + self.error(presence.__str__(fancy=1).encode('utf-8'), debug=True) + else: + raise Exception(presence.__str__(fancy=1).encode('utf-8')) + elif resource != bridge.bot.nickname: real_jid = None if item and item.has_attr('jid'): diff --git a/bridge.py b/bridge.py --- a/bridge.py +++ b/bridge.py @@ -114,6 +114,8 @@ class bridge: def _xmpp_join_callback(self, errors): """Called by muc._xmpp_presence_handler""" if len(errors) == 0: + if hasattr(self, reconnecting): + del self.reconnecting if self.mode == None: return self.bot.error('===> Debug: succesfully connected on XMPP side of bridge "'+str(self)+'"', debug=True) diff --git a/muc.py b/muc.py --- a/muc.py +++ b/muc.py @@ -29,6 +29,7 @@ class muc: class RoomIsLocked(Exception): pass class ForgotNickname(Exception): pass class UnknownError(Exception): pass + class RemoteServerNotFound(Exception): pass def __init__(self, room_jid): self.room_jid = room_jid @@ -89,6 +90,9 @@ class muc: elif err == 'modify jid-malformed': # forgot to give a nickname errors.append(self.__class__.ForgotNickname(self.jid)) + elif err == 'cancel remote-server-not-found': + # MUC server is down or doesn't exist + errors.append(self.__class__.RemoteServerNotFound(self.jid)) else: errors.append(self.__class__.UnknownError(presence.__str__(fancy=1).encode('utf-8'))) break