From 310d712d42ee965866ebe89b86958f7ea75fbc16 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 1 Oct 2012 23:53:26 +0100 Subject: [PATCH] Moved login attempt handler code to profanity module --- src/jabber.c | 24 +++--------------------- src/profanity.c | 34 ++++++++++++++++++++++++++++++++++ src/profanity.h | 3 +++ 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/jabber.c b/src/jabber.c index dc80f9ba..b057e637 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -348,16 +348,7 @@ _jabber_conn_handler(xmpp_conn_t * const conn, if (status == XMPP_CONN_CONNECT) { const char *jid = xmpp_conn_get_jid(conn); - const char *msg = " logged in successfully."; - char line[strlen(jid) + 1 + strlen(msg) + 1]; - sprintf(line, "%s %s", jid, msg); - title_bar_set_status(PRESENCE_ONLINE); - - cons_show(line); - log_info(line); - win_page_off(); - status_bar_print_message(jid); - status_bar_refresh(); + prof_handle_login_success(jid); xmpp_stanza_t* pres; xmpp_handler_add(conn, _jabber_message_handler, NULL, "message", NULL, ctx); @@ -370,8 +361,6 @@ _jabber_conn_handler(xmpp_conn_t * const conn, xmpp_send(conn, pres); xmpp_stanza_release(pres); - prefs_add_login(jid); - jabber_conn.conn_status = JABBER_CONNECTED; jabber_conn.presence = PRESENCE_ONLINE; } else { @@ -390,21 +379,14 @@ _jabber_conn_handler(xmpp_conn_t * const conn, // lost connection for unkown reason } else if (jabber_conn.conn_status == JABBER_CONNECTED) { - cons_bad_show("Lost connection."); - log_info("Lost connection"); - win_disconnected(); - win_page_off(); - log_info("disconnected"); + prof_handle_lost_connection(); xmpp_stop(ctx); jabber_conn.conn_status = JABBER_DISCONNECTED; jabber_conn.presence = PRESENCE_OFFLINE; // login attempt failed } else { - cons_bad_show("Login failed."); - log_info("Login failed"); - win_page_off(); - log_info("disconnected"); + prof_handle_failed_login(); xmpp_stop(ctx); jabber_conn.conn_status = JABBER_DISCONNECTED; jabber_conn.presence = PRESENCE_OFFLINE; diff --git a/src/profanity.c b/src/profanity.c index 94de6920..ff0e5518 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -193,6 +193,40 @@ prof_handle_incoming_message(char *from, char *message) win_page_off(); } +void +prof_handle_login_success(const char *jid) +{ + const char *msg = " logged in successfully."; + char line[strlen(jid) + 1 + strlen(msg) + 1]; + sprintf(line, "%s %s", jid, msg); + title_bar_set_status(PRESENCE_ONLINE); + cons_show(line); + log_info(line); + win_page_off(); + status_bar_print_message(jid); + status_bar_refresh(); + prefs_add_login(jid); +} + +void +prof_handle_lost_connection(void) +{ + cons_bad_show("Lost connection."); + log_info("Lost connection"); + win_disconnected(); + win_page_off(); + log_info("disconnected"); +} + +void +prof_handle_failed_login(void) +{ + cons_bad_show("Login failed."); + log_info("Login failed"); + win_page_off(); + log_info("disconnected"); +} + static void _create_config_directory() { diff --git a/src/profanity.h b/src/profanity.h index 8d2ae4fd..e6d79d3e 100644 --- a/src/profanity.h +++ b/src/profanity.h @@ -25,6 +25,9 @@ void profanity_init(const int disable_tls, char *log_level); void profanity_run(void); +void prof_handle_login_success(const char *jid); +void prof_handle_lost_connection(void); +void prof_handle_failed_login(void); void prof_handle_typing(char *from); void prof_handle_incoming_message(char *from, char *message); void profanity_shutdown_init(void);