diff options
author | James Booth <boothj5@gmail.com> | 2012-10-27 19:34:26 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-10-27 19:34:26 +0100 |
commit | d4fb72f6c9fd4d646afff94db86b7345d6a96d71 (patch) | |
tree | 97e2c0482da9ade2ffcc3895ebf4b33160dc66cc /src | |
parent | 053a5f3120bec49bf4d9cbf9264ba03faa033533 (diff) | |
parent | 847850742c55876676e22e6b7918361dfe086145 (diff) | |
download | profani-tty-d4fb72f6c9fd4d646afff94db86b7345d6a96d71.tar.gz |
Merge branch 'master' into chatstates
Conflicts: docs/profanity.1
Diffstat (limited to 'src')
-rw-r--r-- | src/command.c | 29 | ||||
-rw-r--r-- | src/jabber.c | 22 | ||||
-rw-r--r-- | src/jabber.h | 3 | ||||
-rw-r--r-- | src/profanity.c | 23 | ||||
-rw-r--r-- | src/windows.c | 2 |
5 files changed, 47 insertions, 32 deletions
diff --git a/src/command.c b/src/command.c index b30e9cae..361f53b4 100644 --- a/src/command.c +++ b/src/command.c @@ -65,6 +65,7 @@ static gboolean _cmd_about(const char * const inp, struct cmd_help_t help); static gboolean _cmd_prefs(const char * const inp, struct cmd_help_t help); static gboolean _cmd_who(const char * const inp, struct cmd_help_t help); static gboolean _cmd_connect(const char * const inp, struct cmd_help_t help); +static gboolean _cmd_disconnect(const char * const inp, struct cmd_help_t help); static gboolean _cmd_msg(const char * const inp, struct cmd_help_t help); static gboolean _cmd_tiny(const char * const inp, struct cmd_help_t help); static gboolean _cmd_close(const char * const inp, struct cmd_help_t help); @@ -124,6 +125,15 @@ static struct cmd_t main_commands[] = "Example: /connect myuser@gmail.com", NULL } } }, + { "/disconnect", + _cmd_disconnect, + { "/disconnect", "Logout of current jabber session.", + { "/disconnect", + "------------------", + "Disconnect from the current jabber session.", + "See the /connect command for connecting again.", + NULL } } }, + { "/prefs", _cmd_prefs, { "/prefs", "Show current preferences.", @@ -272,7 +282,7 @@ static struct cmd_t setting_commands[] = "Config file section : [ui]", "Config file value : showsplash=true|false", NULL } } }, - + { "/vercheck", _cmd_vercheck, { "/vercheck [on|off]", "Check for a new release.", @@ -565,6 +575,23 @@ _cmd_connect(const char * const inp, struct cmd_help_t help) } static gboolean +_cmd_disconnect(const char * const inp, struct cmd_help_t help) +{ + if (jabber_get_connection_status() == JABBER_CONNECTED) { + char *jid = strdup(jabber_get_jid()); + jabber_disconnect(); + contact_list_clear(); + jabber_restart(); + cons_show("%s logged out successfully.", jid); + free(jid); + } else { + cons_show("You are not currently connected."); + } + + return TRUE; +} + +static gboolean _cmd_quit(const char * const inp, struct cmd_help_t help) { log_info("Profanity is shutting down..."); diff --git a/src/jabber.c b/src/jabber.c index ea7e38c4..e6436f91 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -70,6 +70,13 @@ jabber_init(const int disable_tls) jabber_conn.tls_disabled = disable_tls; } +void +jabber_restart(void) +{ + jabber_conn.conn_status = JABBER_STARTED; + jabber_conn.presence = PRESENCE_OFFLINE; +} + jabber_conn_status_t jabber_connect(const char * const user, const char * const passwd) @@ -98,7 +105,7 @@ jabber_connect(const char * const user, return jabber_conn.conn_status; } -gboolean +void jabber_disconnect(void) { // if connected, send end stream and wait for response @@ -106,16 +113,11 @@ jabber_disconnect(void) log_info("Closing connection"); xmpp_disconnect(jabber_conn.conn); jabber_conn.conn_status = JABBER_DISCONNECTING; - return TRUE; - - // if disconnected dont wait just shutdown - } else if (jabber_conn.conn_status == JABBER_DISCONNECTED) { - log_info("No connection open"); - return FALSE; - // any other states, just shutdown - } else { - return FALSE; + while (jabber_get_connection_status() == JABBER_DISCONNECTING) { + jabber_process_events(); + } + jabber_free_resources(); } } diff --git a/src/jabber.h b/src/jabber.h index b7e3f87c..d12d00b3 100644 --- a/src/jabber.h +++ b/src/jabber.h @@ -43,7 +43,7 @@ typedef enum { void jabber_init(const int disable_tls); jabber_conn_status_t jabber_connect(const char * const user, const char * const passwd); -gboolean jabber_disconnect(void); +void jabber_disconnect(void); void jabber_roster_request(void); void jabber_process_events(void); void jabber_send(const char * const msg, const char * const recipient); @@ -51,5 +51,6 @@ void jabber_update_presence(jabber_presence_t status, const char * const msg); const char * jabber_get_jid(void); jabber_conn_status_t jabber_get_connection_status(void); void jabber_free_resources(void); +void jabber_restart(void); #endif diff --git a/src/profanity.c b/src/profanity.c index 4e240b21..3d8235a0 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -43,7 +43,6 @@ static gboolean _process_input(char *inp); static void _create_config_directory(); static void _free_roster_entry(jabber_roster_entry *entry); static void _init(const int disable_tls, char *log_level); -static void _shutdown_init(void); static void _shutdown(void); void @@ -137,7 +136,7 @@ loop_out: void prof_handle_login_success(const char *jid) { - const char *msg = " logged in successfully."; + const char *msg = "logged in successfully."; cons_show("%s %s", jid, msg); title_bar_set_status(PRESENCE_ONLINE); log_info("%s %s", jid, msg); @@ -204,7 +203,7 @@ prof_handle_roster(GSList *roster) } static void -_create_config_directory() +_create_config_directory(void) { GString *dir = g_string_new(getenv("HOME")); g_string_append(dir, "/.profanity"); @@ -289,27 +288,13 @@ _init(const int disable_tls, char *log_level) cmd_init(); log_info("Initialising contact list"); contact_list_init(); - atexit(_shutdown_init); -} - -static void -_shutdown_init(void) -{ - gboolean wait_response = jabber_disconnect(); - - if (wait_response) { - while (jabber_get_connection_status() == JABBER_DISCONNECTING) { - jabber_process_events(); - } - jabber_free_resources(); - } - - _shutdown(); + atexit(_shutdown); } static void _shutdown(void) { + jabber_disconnect(); contact_list_clear(); gui_close(); chat_log_close(); diff --git a/src/windows.c b/src/windows.c index bd06165d..957e90f5 100644 --- a/src/windows.c +++ b/src/windows.c @@ -961,7 +961,7 @@ _cons_splash_logo(void) _win_show_time(_cons_win); wprintw(_cons_win, "\n"); _win_show_time(_cons_win); - if (strcmp(PACKAGE_STATUS, "dev") == 0) { + if (strcmp(PACKAGE_STATUS, "development") == 0) { wprintw(_cons_win, "Version %sdev\n", PACKAGE_VERSION); } else { wprintw(_cons_win, "Version %s\n", PACKAGE_VERSION); |