diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f0e69f..8c4daa8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ set(SOURCES src/ncurses/ui_msg_diff.c src/ncurses/ui_save.c src/ncurses/ui_settings.c - src/ncurses/ui_stats.c + src/ncurses/stats.c src/ncurses/window.c src/ncurses/keybinding.c src/ncurses/scrollbar.c diff --git a/src/Makefile.am b/src/Makefile.am index 169a55e..7dfbd43 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,7 +40,7 @@ sngrep_SOURCES+=storage.c sngrep_SOURCES+=ncurses/keybinding.c sngrep_SOURCES+=ncurses/scrollbar.c sngrep_SOURCES+=ncurses/manager.c -sngrep_SOURCES+=ncurses/ui_stats.c +sngrep_SOURCES+=ncurses/stats.c sngrep_SOURCES+=ncurses/ui_filter.c sngrep_SOURCES+=ncurses/window.c sngrep_SOURCES+=ncurses/ui_settings.c diff --git a/src/ncurses/call_list.c b/src/ncurses/call_list.c index 3058c8b..2873e72 100644 --- a/src/ncurses/call_list.c +++ b/src/ncurses/call_list.c @@ -927,7 +927,7 @@ call_list_handle_key(Window *window, int key) column_select_set_columns(next_window, info->columns); break; case ACTION_SHOW_STATS: - ncurses_create_window(PANEL_STATS); + ncurses_create_window(WINDOW_STATS); break; case ACTION_SAVE: if (capture_sources_count(capture_manager()) > 1) { diff --git a/src/ncurses/manager.c b/src/ncurses/manager.c index b1f7676..d6848a1 100644 --- a/src/ncurses/manager.c +++ b/src/ncurses/manager.c @@ -42,6 +42,7 @@ #include "ncurses/ui_filter.h" #include "ncurses/ui_msg_diff.h" #include "ncurses/column_select.h" +#include "ncurses/stats.h" #include "ncurses/ui_save.h" #include "ncurses/ui_settings.h" @@ -58,8 +59,7 @@ static Window *panel_pool[] = { &ui_filter, &ui_save, &ui_msg_diff, - &ui_settings, - &ui_stats + &ui_settings }; static GPtrArray *windows; @@ -225,6 +225,12 @@ ncurses_find_by_type(enum WindowTypes type) return window; } + if (type == WINDOW_STATS) { + Window *window = stats_new(); + g_ptr_array_add(windows, window); + return window; + } + // Return ui pointer if found for (i = 0; i < PANEL_COUNT; i++) { diff --git a/src/ncurses/ui_stats.c b/src/ncurses/stats.c similarity index 57% rename from src/ncurses/ui_stats.c rename to src/ncurses/stats.c index e84717c..78a6a9a 100644 --- a/src/ncurses/ui_stats.c +++ b/src/ncurses/stats.c @@ -20,10 +20,10 @@ ** ****************************************************************************/ /** - * @file ui_stats.c + * @file stats.c * @author Ivan Alonso [aka Kaian] * - * @brief Source of functions defined in ui_stats.h + * @brief Source of functions defined in stats.h */ /* * +---------------------------------------------------------+ @@ -58,24 +58,14 @@ #include "glib-utils.h" #include "storage.h" #include "packet/dissectors/packet_sip.h" -#include "ui_stats.h" +#include "stats.h" -/** - * Ui Structure definition for Stats panel - */ -Window ui_stats = { - .type = PANEL_STATS, - .panel = NULL, - .create = stats_create, - .destroy = window_deinit, - .handle_key = NULL -}; - -void -stats_create(Window *ui) +Window * +stats_new() { - Call *call; - Message *msg; + Window *window = g_malloc0(sizeof(Window)); + window->type = WINDOW_STATS; + window->destroy = window_deinit; // Counters! struct { @@ -87,17 +77,17 @@ stats_create(Window *ui) memset(&stats, 0, sizeof(stats)); // Calculate window dimensions - window_init(ui, 25, 60); + window_init(window, 25, 60); // Set the window title and boxes - mvwprintw(ui->win, 1, ui->width / 2 - 9, "Stats Information"); - wattron(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF)); - title_foot_box(ui->panel); - mvwhline(ui->win, 10, 1, ACS_HLINE, ui->width - 1); - mvwaddch(ui->win, 10, 0, ACS_LTEE); - mvwaddch(ui->win, 10, ui->width - 1, ACS_RTEE); - mvwprintw(ui->win, ui->height - 2, ui->width / 2 - 9, "Press ESC to leave"); - wattroff(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF)); + mvwprintw(window->win, 1, window->width / 2 - 9, "Stats Information"); + wattron(window->win, COLOR_PAIR(CP_BLUE_ON_DEF)); + title_foot_box(window->panel); + mvwhline(window->win, 10, 1, ACS_HLINE, window->width - 1); + mvwaddch(window->win, 10, 0, ACS_LTEE); + mvwaddch(window->win, 10, window->width - 1, ACS_RTEE); + mvwprintw(window->win, window->height - 2, window->width / 2 - 9, "Press ESC to leave"); + wattroff(window->win, COLOR_PAIR(CP_BLUE_ON_DEF)); // Parse the data GPtrArray *calls = storage_calls(); @@ -105,12 +95,12 @@ stats_create(Window *ui) // Ignore this screen when no dialog exists if (!stats.dtotal) { - mvwprintw(ui->win, 3, 3, "No information to display"); - return; + mvwprintw(window->win, 3, 3, "No information to display"); + return window; } for (guint i = 0; i < g_ptr_array_len(calls); i++) { - call = g_ptr_array_index(calls, i); + Call *call = g_ptr_array_index(calls, i); // If this dialog is a call if (call->state) { @@ -130,7 +120,7 @@ stats_create(Window *ui) // For each message in call for (guint i = 0; i < g_ptr_array_len(call->msgs); i++) { - msg = g_ptr_array_index(call->msgs, i); + Message *msg = g_ptr_array_index(call->msgs, i); guint method = packet_sip_method(msg->packet); // Increase message counter @@ -167,38 +157,40 @@ stats_create(Window *ui) } // Print parses data - mvwprintw(ui->win, 3, 3, "Dialogs: %d", stats.dtotal); - mvwprintw(ui->win, 4, 3, "Calls: %d (%.1f\\%)", stats.dcalls, (float) stats.dcalls * 100 / stats.dtotal); - mvwprintw(ui->win, 5, 3, "Messages: %d", stats.mtotal); + mvwprintw(window->win, 3, 3, "Dialogs: %d", stats.dtotal); + mvwprintw(window->win, 4, 3, "Calls: %d (%.1f%%)", stats.dcalls, (float) stats.dcalls * 100 / stats.dtotal); + mvwprintw(window->win, 5, 3, "Messages: %d", stats.mtotal); // Print status of calls if any if (stats.dcalls) { - mvwprintw(ui->win, 3, 33, "COMPLETED: %d (%.1f\\%)", stats.completed, (float) stats.completed * 100 / stats.dcalls); - mvwprintw(ui->win, 4, 33, "CANCELLED: %d (%.1f\\%)", stats.cancelled, (float) stats.cancelled * 100 / stats.dcalls); - mvwprintw(ui->win, 5, 33, "IN CALL: %d (%.1f\\%)", stats.incall, (float) stats.incall * 100 / stats.dcalls); - mvwprintw(ui->win, 6, 33, "REJECTED: %d (%.1f\\%)", stats.rejected, (float) stats.rejected * 100 / stats.dcalls); - mvwprintw(ui->win, 7, 33, "BUSY: %d (%.1f\\%)", stats.busy, (float) stats.busy * 100 / stats.dcalls); - mvwprintw(ui->win, 8, 33, "DIVERTED: %d (%.1f\\%)", stats.diverted, (float) stats.diverted * 100 / stats.dcalls); - mvwprintw(ui->win, 9, 33, "CALL SETUP: %d (%.1f\\%)", stats.setup, (float) stats.setup * 100 / stats.dcalls); + mvwprintw(window->win, 3, 33, "COMPLETED: %d (%.1f%%)", stats.completed, (float) stats.completed * 100 / stats.dcalls); + mvwprintw(window->win, 4, 33, "CANCELLED: %d (%.1f%%)", stats.cancelled, (float) stats.cancelled * 100 / stats.dcalls); + mvwprintw(window->win, 5, 33, "IN CALL: %d (%.1f%%)", stats.incall, (float) stats.incall * 100 / stats.dcalls); + mvwprintw(window->win, 6, 33, "REJECTED: %d (%.1f%%)", stats.rejected, (float) stats.rejected * 100 / stats.dcalls); + mvwprintw(window->win, 7, 33, "BUSY: %d (%.1f%%)", stats.busy, (float) stats.busy * 100 / stats.dcalls); + mvwprintw(window->win, 8, 33, "DIVERTED: %d (%.1f%%)", stats.diverted, (float) stats.diverted * 100 / stats.dcalls); + mvwprintw(window->win, 9, 33, "CALL SETUP: %d (%.1f%%)", stats.setup, (float) stats.setup * 100 / stats.dcalls); } - mvwprintw(ui->win, 11, 3, "INVITE: %d (%.1f\\%)", stats.invite, (float) stats.invite * 100 / stats.mtotal); - mvwprintw(ui->win, 12, 3, "REGISTER: %d (%.1f\\%)", stats.regist, (float) stats.regist * 100 / stats.mtotal); - mvwprintw(ui->win, 13, 3, "SUBSCRIBE: %d (%.1f\\%)", stats.subscribe, (float) stats.subscribe * 100 / stats.mtotal); - mvwprintw(ui->win, 14, 3, "UPDATE: %d (%.1f\\%)", stats.update, (float) stats.update * 100 / stats.mtotal); - mvwprintw(ui->win, 15, 3, "NOTIFY: %d (%.1f\\%)", stats.notify, (float) stats.notify * 100 / stats.mtotal); - mvwprintw(ui->win, 16, 3, "OPTIONS: %d (%.1f\\%)", stats.options, (float) stats.options * 100 / stats.mtotal); - mvwprintw(ui->win, 17, 3, "PUBLISH: %d (%.1f\\%)", stats.publish, (float) stats.publish * 100 / stats.mtotal); - mvwprintw(ui->win, 18, 3, "MESSAGE: %d (%.1f\\%)", stats.message, (float) stats.message * 100 / stats.mtotal); - mvwprintw(ui->win, 19, 3, "INFO: %d (%.1f\\%)", stats.info, (float) stats.info * 100 / stats.mtotal); - mvwprintw(ui->win, 20, 3, "BYE: %d (%.1f\\%)", stats.bye, (float) stats.bye * 100 / stats.mtotal); - mvwprintw(ui->win, 21, 3, "CANCEL: %d (%.1f\\%)", stats.cancel, (float) stats.cancel * 100 / stats.mtotal); + mvwprintw(window->win, 11, 3, "INVITE: %d (%.1f%%)", stats.invite, (float) stats.invite * 100 / stats.mtotal); + mvwprintw(window->win, 12, 3, "REGISTER: %d (%.1f%%)", stats.regist, (float) stats.regist * 100 / stats.mtotal); + mvwprintw(window->win, 13, 3, "SUBSCRIBE: %d (%.1f%%)", stats.subscribe, (float) stats.subscribe * 100 / stats.mtotal); + mvwprintw(window->win, 14, 3, "UPDATE: %d (%.1f%%)", stats.update, (float) stats.update * 100 / stats.mtotal); + mvwprintw(window->win, 15, 3, "NOTIFY: %d (%.1f%%)", stats.notify, (float) stats.notify * 100 / stats.mtotal); + mvwprintw(window->win, 16, 3, "OPTIONS: %d (%.1f%%)", stats.options, (float) stats.options * 100 / stats.mtotal); + mvwprintw(window->win, 17, 3, "PUBLISH: %d (%.1f%%)", stats.publish, (float) stats.publish * 100 / stats.mtotal); + mvwprintw(window->win, 18, 3, "MESSAGE: %d (%.1f%%)", stats.message, (float) stats.message * 100 / stats.mtotal); + mvwprintw(window->win, 19, 3, "INFO: %d (%.1f%%)", stats.info, (float) stats.info * 100 / stats.mtotal); + mvwprintw(window->win, 20, 3, "BYE: %d (%.1f%%)", stats.bye, (float) stats.bye * 100 / stats.mtotal); + mvwprintw(window->win, 21, 3, "CANCEL: %d (%.1f%%)", stats.cancel, (float) stats.cancel * 100 / stats.mtotal); - mvwprintw(ui->win, 11, 33, "1XX: %d (%.1f\\%)", stats.r100, (float) stats.r100 * 100 / stats.mtotal); - mvwprintw(ui->win, 12, 33, "2XX: %d (%.1f\\%)", stats.r200, (float) stats.r200 * 100 / stats.mtotal); - mvwprintw(ui->win, 13, 33, "3XX: %d (%.1f\\%)", stats.r300, (float) stats.r300 * 100 / stats.mtotal); - mvwprintw(ui->win, 14, 33, "4XX: %d (%.1f\\%)", stats.r400, (float) stats.r400 * 100 / stats.mtotal); - mvwprintw(ui->win, 15, 33, "5XX: %d (%.1f\\%)", stats.r500, (float) stats.r500 * 100 / stats.mtotal); - mvwprintw(ui->win, 16, 33, "6XX: %d (%.1f\\%)", stats.r600, (float) stats.r600 * 100 / stats.mtotal); - mvwprintw(ui->win, 17, 33, "7XX: %d (%.1f\\%)", stats.r700, (float) stats.r700 * 100 / stats.mtotal); - mvwprintw(ui->win, 18, 33, "8XX: %d (%.1f\\%)", stats.r800, (float) stats.r800 * 100 / stats.mtotal); + mvwprintw(window->win, 11, 33, "1XX: %d (%.1f%%)", stats.r100, (float) stats.r100 * 100 / stats.mtotal); + mvwprintw(window->win, 12, 33, "2XX: %d (%.1f%%)", stats.r200, (float) stats.r200 * 100 / stats.mtotal); + mvwprintw(window->win, 13, 33, "3XX: %d (%.1f%%)", stats.r300, (float) stats.r300 * 100 / stats.mtotal); + mvwprintw(window->win, 14, 33, "4XX: %d (%.1f%%)", stats.r400, (float) stats.r400 * 100 / stats.mtotal); + mvwprintw(window->win, 15, 33, "5XX: %d (%.1f%%)", stats.r500, (float) stats.r500 * 100 / stats.mtotal); + mvwprintw(window->win, 16, 33, "6XX: %d (%.1f%%)", stats.r600, (float) stats.r600 * 100 / stats.mtotal); + mvwprintw(window->win, 17, 33, "7XX: %d (%.1f%%)", stats.r700, (float) stats.r700 * 100 / stats.mtotal); + mvwprintw(window->win, 18, 33, "8XX: %d (%.1f%%)", stats.r800, (float) stats.r800 * 100 / stats.mtotal); + + return window; } diff --git a/src/ncurses/ui_stats.h b/src/ncurses/stats.h similarity index 88% rename from src/ncurses/ui_stats.h rename to src/ncurses/stats.h index 6e60d0a..5b29b36 100644 --- a/src/ncurses/ui_stats.h +++ b/src/ncurses/stats.h @@ -20,13 +20,13 @@ ** ****************************************************************************/ /** - * @file ui_stats.h + * @file stats.h * @author Ivan Alonso [aka Kaian] * * @brief Functions to manage ui window for capture stats display */ -#ifndef __SNGREP_UI_STATS_H -#define __SNGREP_UI_STATS_H +#ifndef __SNGREP_STATS_H +#define __SNGREP_STATS_H #include "ncurses/manager.h" @@ -38,9 +38,8 @@ * static information of the panel that will never be * redrawn. * - * @param ui UI structure pointer */ -void -stats_create(Window *ui); +Window * +stats_new(); -#endif /* __SNGREP_UI_STATS_H */ +#endif /* __SNGREP_STATS_H */ diff --git a/src/ncurses/window.h b/src/ncurses/window.h index 59b4d91..d38eb70 100644 --- a/src/ncurses/window.h +++ b/src/ncurses/window.h @@ -71,7 +71,7 @@ enum WindowTypes { //! Settings panel PANEL_SETTINGS, //! Stats panel - PANEL_STATS, + WINDOW_STATS, //! Panel Counter PANEL_COUNT, };