Handle authentication and connection errors. fixed #1994

parent af651cbc
......@@ -50,7 +50,7 @@ class Connection(sleekxmpp.ClientXMPP):
sleekxmpp.ClientXMPP.__init__(self, jid, password, ssl=True)
self.registerPlugin('xep_0030')
self.registerPlugin('xep_0045')
def start(self):
# TODO, try multiple servers
# With anon auth.
......@@ -58,10 +58,13 @@ class Connection(sleekxmpp.ClientXMPP):
custom_host = config.get('custom_host', '')
custom_port = config.get('custom_port', -1)
if custom_host and custom_port != -1:
self.connect((custom_host, custom_port))
res = self.connect((custom_host, custom_port), reattempt=False)
else:
self.connect()
res = self.connect(reattempt=False)
if not res:
return False
self.process(threaded=True)
return True
# Global connection object
connection = Connection()
......@@ -147,7 +147,10 @@ class Core(object):
}
# Add handlers
self.xmpp.add_event_handler("session_start", self.on_connected)
self.xmpp.add_event_handler('connected', self.on_connected)
self.xmpp.add_event_handler('disconnected', self.on_disconnected)
self.xmpp.add_event_handler('failed_auth', self.on_failed_auth)
self.xmpp.add_event_handler("session_start", self.on_session_start)
self.xmpp.add_event_handler("groupchat_presence", self.on_groupchat_presence)
self.xmpp.add_event_handler("groupchat_message", self.on_groupchat_message)
self.xmpp.add_event_handler("groupchat_subject", self.on_groupchat_subject)
......@@ -157,6 +160,9 @@ class Core(object):
self.xmpp.add_event_handler("roster_update", self.on_roster_update)
self.xmpp.add_event_handler("changed_status", self.on_presence)
self.information(_('Welcome to poezio!'))
self.refresh_window()
def on_exception(self, typ, value, trace):
"""
When an exception in raised, open a special tab
......@@ -240,14 +246,36 @@ class Core(object):
if tab and isinstance(tab, tabs.ConversationTab):
self.add_message_to_text_buffer(tab.get_room(), msg)
def on_failed_connection(self):
"""
We cannot contact the remote server
"""
self.information(_("Connection to remote server failed"))
def on_disconnected(self, event):
"""
When we are disconnected from remote server
"""
self.information(_("Disconnected from server."))
def on_failed_auth(self, event):
"""
Authentication failed
"""
self.information(_("Authentication failed."))
def on_connected(self, event):
"""
Remote host responded, but we are not yet authenticated
"""
self.information(_("Connected to server."))
def on_session_start(self, event):
"""
Called when we are connected and authenticated
"""
self.information(_("Welcome on Poezio \o/!"))
self.information(_("Authentication success."))
self.information(_("Your JID is %s") % self.xmpp.boundjid.full)
if not self.xmpp.anon:
# request the roster
self.xmpp.getRoster()
......@@ -598,15 +626,15 @@ class Core(object):
"""
main loop waiting for the user to press a key
"""
self.refresh_window()
curses.ungetch('\n') # FIXME
while self.running:
self.doupdate()
char=read_char(self.stdscr)
char = read_char(self.stdscr)
# search for keyboard shortcut
if char in list(self.key_func.keys()):
self.key_func[char]()
else:
self.do_command(char)
self.doupdate()
def current_tab(self):
"""
......
......@@ -34,7 +34,8 @@ if __name__ == '__main__':
signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore ctrl-c
if options.debug:
logging.basicConfig(filename=options.debug,level=logging.DEBUG)
connection.start() # Connect to remote server
if not connection.start(): # Connect to remote server
core.on_failed_connection()
# Disable any display of non-wanted text on the terminal
# by redirecting stderr to /dev/null
# sys.stderr = open('/dev/null', 'a')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment