diff --git a/src/command/command.c b/src/command/command.c index 97442e45..245d0cfa 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -796,6 +796,14 @@ static struct cmd_t command_defs[] = "The default is 'all' for all windows.", NULL } } }, + { "/xmlconsole", + cmd_xmlconsole, parse_args, 0, 0, NULL, + { "/xmlconsole", "Open the XML console", + { "/xmlconsole", + "-----------", + "Open the XML console to view incoming and outgoing XMPP traffic.", + NULL } } }, + { "/away", cmd_away, parse_args_with_freetext, 0, 1, NULL, { "/away [msg]", "Set status to away.", @@ -1402,6 +1410,7 @@ cmd_execute_default(const char * const inp) break; case WIN_CONSOLE: + case WIN_XML: cons_show("Unknown command: %s", inp); break; diff --git a/src/command/commands.c b/src/command/commands.c index ed01bb87..0ddd1596 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2446,6 +2446,18 @@ cmd_vercheck(gchar **args, struct cmd_help_t help) } } +gboolean +cmd_xmlconsole(gchar **args, struct cmd_help_t help) +{ + if (!ui_xmlconsole_exists()) { + ui_create_xmlconsole_win(); + } else { + ui_open_xmlconsole_win(); + } + + return TRUE; +} + gboolean cmd_flash(gchar **args, struct cmd_help_t help) { diff --git a/src/command/commands.h b/src/command/commands.h index 57a5da14..5a8238f8 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -111,5 +111,6 @@ gboolean cmd_win(gchar **args, struct cmd_help_t help); gboolean cmd_wins(gchar **args, struct cmd_help_t help); gboolean cmd_xa(gchar **args, struct cmd_help_t help); gboolean cmd_alias(gchar **args, struct cmd_help_t help); +gboolean cmd_xmlconsole(gchar **args, struct cmd_help_t help); #endif diff --git a/src/server_events.c b/src/server_events.c index d7fbe772..a920050f 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -553,3 +553,9 @@ handle_bookmark_autojoin(char *jid) ui_room_join(jid, FALSE); muc_remove_invite(jid); } + +void +handle_xmpp_stanza(const char * const msg) +{ + ui_handle_stanza(msg); +} diff --git a/src/server_events.h b/src/server_events.h index ebff2223..ea49e1f1 100644 --- a/src/server_events.h +++ b/src/server_events.h @@ -79,5 +79,6 @@ void handle_message_error(const char * const from, const char * const type, void handle_presence_error(const char *from, const char * const type, const char *err_msg); void handle_bookmark_autojoin(char *jid); +void handle_xmpp_stanza(const char * const msg); #endif diff --git a/src/ui/core.c b/src/ui/core.c index 0bead88f..c5a5817c 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -220,6 +220,35 @@ _ui_duck_exists(void) return wins_duck_exists(); } +static gboolean +_ui_xmlconsole_exists(void) +{ + return wins_xmlconsole_exists(); +} + +static void +_ui_handle_stanza(const char * const msg) +{ + if (ui_xmlconsole_exists()) { + ProfWin *xmlconsole = wins_get_xmlconsole(); + + if (g_str_has_prefix(msg, "SENT:")) { + win_print_line_no_time(xmlconsole, 0, "SENT:"); + win_print_line_no_time(xmlconsole, COLOUR_ONLINE, &msg[6]); + win_print_line_no_time(xmlconsole, COLOUR_ONLINE, ""); + } else if (g_str_has_prefix(msg, "RECV:")) { + win_print_line_no_time(xmlconsole, 0, "RECV:"); + win_print_line_no_time(xmlconsole, COLOUR_AWAY, &msg[6]); + win_print_line_no_time(xmlconsole, COLOUR_ONLINE, ""); + } + + if (wins_is_current(xmlconsole)) { + win_update_virtual(xmlconsole); + ui_current_page_off(); + } + } +} + static void _ui_contact_typing(const char * const barejid) { @@ -1105,6 +1134,14 @@ _ui_create_duck_win(void) win_print_line(window, '-', 0, "Type ':help' to find out more."); } +static void +_ui_create_xmlconsole_win(void) +{ + ProfWin *window = wins_new("XML Console", WIN_XML); + int num = wins_get_num(window); + ui_switch_win(num); +} + static void _ui_open_duck_win(void) { @@ -1928,4 +1965,7 @@ ui_init_module(void) ui_input_nonblocking = _ui_input_nonblocking; ui_replace_input = _ui_replace_input; ui_invalid_command_usage = _ui_invalid_command_usage; + ui_handle_stanza = _ui_handle_stanza; + ui_create_xmlconsole_win = _ui_create_xmlconsole_win; + ui_xmlconsole_exists = _ui_xmlconsole_exists; } diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 55f025a4..dd7c73d8 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -302,14 +302,6 @@ status_bar_clear(void) message = NULL; } - int i; - is_active[1] = TRUE; - is_new[1] = FALSE; - for (i = 2; i < 12; i++) { - is_active[i] = FALSE; - is_new[i] = FALSE; - } - werase(status_bar); int cols = getmaxx(stdscr); diff --git a/src/ui/ui.h b/src/ui/ui.h index c863fb4c..788dfd48 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -92,6 +92,8 @@ gboolean (*ui_win_exists)(int index); int (*ui_win_unread)(int index); char * (*ui_ask_password)(void); +void (*ui_handle_stanza)(const char * const msg); + // ui events void (*ui_contact_typing)(const char * const from); void (*ui_incoming_msg)(const char * const from, const char * const message, @@ -161,6 +163,10 @@ void (*ui_replace_input)(char *input, const char * const new_input, int *size); void (*ui_invalid_command_usage)(const char * const usage, void (**setting_func)(void)); +void (*ui_create_xmlconsole_win)(void); +gboolean (*ui_xmlconsole_exists)(void); +void (*ui_open_xmlconsole_win)(void); + // console window actions void (*cons_show)(const char * const msg, ...); void (*cons_about)(void); diff --git a/src/ui/window.c b/src/ui/window.c index fa2ab804..bdc55aca 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -89,6 +89,14 @@ win_print_line(ProfWin *window, const char show_char, int attrs, wattroff(window->win, attrs); } +void +win_print_line_no_time(ProfWin *window, int attrs, const char * const msg) +{ + wattron(window->win, attrs); + wprintw(window->win, "%s\n", msg); + wattroff(window->win, attrs); +} + void win_vprint_line(ProfWin *window, const char show_char, int attrs, const char * const msg, ...) diff --git a/src/ui/window.h b/src/ui/window.h index 75bd5d25..1e0909ca 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -42,7 +42,8 @@ typedef enum { WIN_MUC, WIN_PRIVATE, WIN_DUCK, - WIN_PLUGIN + WIN_PLUGIN, + WIN_XML } win_type_t; typedef struct prof_win_t { @@ -63,6 +64,7 @@ void win_vprint_line(ProfWin *self, const char show_char, int attrs, const char * const msg, ...); void win_print_line(ProfWin *self, const char show_char, int attrs, const char * const msg); +void win_print_line_no_time(ProfWin *window, int attrs, const char * const msg); void win_update_virtual(ProfWin *window); void win_move_to_end(ProfWin *window); void win_print_time(ProfWin *window, char show_char); diff --git a/src/ui/windows.c b/src/ui/windows.c index 09074131..751c5ed5 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -297,6 +297,38 @@ wins_duck_exists(void) return FALSE; } +gboolean +wins_xmlconsole_exists(void) +{ + GList *values = g_hash_table_get_values(windows); + GList *curr = values; + + while (curr != NULL) { + ProfWin *window = curr->data; + if (window->type == WIN_XML) + return TRUE; + curr = g_list_next(curr); + } + + return FALSE; +} + +ProfWin * +wins_get_xmlconsole(void) +{ + GList *values = g_hash_table_get_values(windows); + GList *curr = values; + + while (curr != NULL) { + ProfWin *window = curr->data; + if (window->type == WIN_XML) + return window; + curr = g_list_next(curr); + } + + return NULL; +} + GSList * wins_get_chat_recipients(void) { @@ -429,6 +461,7 @@ wins_create_summary(void) GString *muc_string; GString *duck_string; GString *plugin_string; + GString *xml_string; switch (window->type) { @@ -516,6 +549,14 @@ wins_create_summary(void) g_string_free(plugin_string, TRUE); break; + case WIN_XML: + xml_string = g_string_new(""); + g_string_printf(xml_string, "%d: XML console", ui_index); + result = g_slist_append(result, strdup(xml_string->str)); + g_string_free(xml_string, TRUE); + + break; + default: break; } diff --git a/src/ui/windows.h b/src/ui/windows.h index 91b60c07..de7c5c1b 100644 --- a/src/ui/windows.h +++ b/src/ui/windows.h @@ -50,5 +50,7 @@ gboolean wins_tidy(void); GSList * wins_create_summary(void); void wins_destroy(void); GList * wins_get_nums(void); +gboolean wins_xmlconsole_exists(void); +ProfWin * wins_get_xmlconsole(void); #endif diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index d3c6d978..c058dab2 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -534,6 +534,9 @@ _xmpp_file_logger(void * const userdata, const xmpp_log_level_t level, { log_level_t prof_level = _get_log_level(level); log_msg(prof_level, area, msg); + if ((g_strcmp0(area, "xmpp") == 0) || (g_strcmp0(area, "conn")) == 0) { + handle_xmpp_stanza(msg); + } } static xmpp_log_t *