From f5eab875884feda2b1e40e0dcd76150ca1b0763f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 27 May 2012 19:53:16 +0100 Subject: [PATCH] Added _cmd_away Not yet sending message to server --- command.c | 17 +++++++++++++++++ jabber.c | 5 +++++ jabber.h | 2 ++ 3 files changed, 24 insertions(+) diff --git a/command.c b/command.c index 1cde6293..f8f7eb7d 100644 --- a/command.c +++ b/command.c @@ -44,6 +44,7 @@ static gboolean _cmd_msg(const char * const inp); static gboolean _cmd_close(const char * const inp); static gboolean _cmd_set_beep(const char * const inp); static gboolean _cmd_set_flash(const char * const inp); +static gboolean _cmd_away(const char * const inp); static gboolean _cmd_default(const char * const inp); gboolean process_input(char *inp) @@ -100,6 +101,8 @@ static gboolean _handle_command(const char * const command, const char * const i result = _cmd_set_beep(inp); } else if (strcmp(command, "/flash") == 0) { result = _cmd_set_flash(inp); + } else if (strcmp(command, "/away") == 0) { + result = _cmd_away(inp); } else { result = _cmd_default(inp); } @@ -250,6 +253,20 @@ static gboolean _cmd_set_flash(const char * const inp) return TRUE; } +static gboolean _cmd_away(const char * const inp) +{ + jabber_conn_status_t conn_status = jabber_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currently connected."); + } else { + jabber_update_presence(PRESENCE_AWAY); + cons_show("Status set to \"away\""); + } + + return TRUE; +} + static gboolean _cmd_default(const char * const inp) { if (win_in_chat()) { diff --git a/jabber.c b/jabber.c index d361b049..4867e3e1 100644 --- a/jabber.c +++ b/jabber.c @@ -179,6 +179,11 @@ void jabber_roster_request(void) xmpp_stanza_release(iq); } +void jabber_update_presence(jabber_presence_t status) +{ + jabber_conn.presence = status; +} + static int _jabber_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { diff --git a/jabber.h b/jabber.h index 51d0cada..fc7766d2 100644 --- a/jabber.h +++ b/jabber.h @@ -38,6 +38,7 @@ typedef enum { void jabber_init(const int disable_tls); jabber_conn_status_t jabber_connection_status(void); +jabber_presence_t jabber_presence_status(void); jabber_conn_status_t jabber_connect(const char * const user, const char * const passwd); void jabber_disconnect(void); @@ -45,5 +46,6 @@ void jabber_roster_request(void); void jabber_process_events(void); void jabber_send(const char * const msg, const char * const recipient); const char * jabber_get_jid(void); +void jabber_update_presence(jabber_presence_t status); #endif