1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Moved login attempt handler code to profanity module

This commit is contained in:
James Booth 2012-10-01 23:53:26 +01:00
parent 9f00ef14d2
commit 310d712d42
3 changed files with 40 additions and 21 deletions

View File

@ -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;

View File

@ -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()
{

View File

@ -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);