ncurses: refactored filter window functions

This commit is contained in:
Kaian 2018-11-19 13:28:09 +01:00
parent a03d0d67c2
commit 056728b95d
8 changed files with 357 additions and 374 deletions

View File

@ -38,7 +38,7 @@ set(SOURCES
src/ncurses/call_list_win.c
src/ncurses/call_raw_win.c
src/ncurses/column_select_win.c
src/ncurses/ui_filter.c
src/ncurses/filter_win.c
src/ncurses/ui_msg_diff.c
src/ncurses/ui_save.c
src/ncurses/ui_settings.c

View File

@ -175,3 +175,35 @@ filter_reset_calls()
{
g_ptr_array_foreach(storage_calls(), (GFunc) filter_mark_call_unfiltered, NULL);
}
void
filter_method_from_setting(const char *value)
{
char methods[200], method_expr[256];
int methods_len = strlen(value);
char *comma;
// If there's a method filter
if (methods_len) {
// Copy value into temporal array
memset(methods, 0, sizeof(methods));
strncpy(methods, value, methods_len);
// Replace all commas with pippes
while ((comma = strchr(methods, ',')))
*comma = '|';
// Create a regular expression
memset(method_expr, 0, sizeof(method_expr));
sprintf(method_expr, "(%s)", methods);
filter_set(FILTER_METHOD, method_expr);
} else {
filter_set(FILTER_METHOD, " ");
}
}
void
filter_payload_from_setting(const char *value)
{
if (value) filter_set(FILTER_PAYLOAD, value);
}

View File

@ -127,4 +127,16 @@ filter_check_expr(filter_t filter, const char *data);
void
filter_reset_calls();
/**
* @brief Set Method filtering from filter.methods setting format
*/
void
filter_method_from_setting(const char *value);
/**
* @brief Set Payload filter from filter.payload setting
*/
void
filter_payload_from_setting(const char *value);
#endif /* __SNGREP_FILTER_H_ */

View File

@ -45,7 +45,7 @@
#include "ncurses/call_flow_win.h"
#include "ncurses/call_raw_win.h"
#include "ncurses/stats_win.h"
#include "ncurses/ui_filter.h"
#include "ncurses/filter_win.h"
#include "ncurses/ui_save.h"
#include "storage.h"
#include "column_select_win.h"
@ -918,7 +918,7 @@ call_list_handle_key(Window *window, int key)
}
break;
case ACTION_SHOW_FILTERS:
ncurses_create_window(PANEL_FILTER);
ncurses_create_window(WINDOW_FILTER);
break;
case ACTION_SHOW_COLUMNS:
column_select_win_set_columns(ncurses_create_window(WINDOW_COLUMN_SELECT), info->columns);

View File

@ -32,173 +32,172 @@
#include <form.h>
#include "packet/dissectors/packet_sip.h"
#include "ncurses/manager.h"
#include "ncurses/ui_filter.h"
#include "ncurses/filter_win.h"
#include "ncurses/call_list_win.h"
#include "storage.h"
#include "filter.h"
#include "setting.h"
/**
* Ui Structure definition for Filter panel
* @brief Get custom information of given panel
*
* Return ncurses users pointer of the given panel into panel's
* information structure pointer.
*
* @param ui UI structure pointer
* @return a pointer to info structure of given panel
*/
Window ui_filter = {
.type = PANEL_FILTER,
.panel = NULL,
.create = filter_create,
.handle_key = filter_handle_key,
.destroy = filter_destroy
};
void
filter_create(Window *ui)
{
filter_info_t *info;
const char *method, *payload;
// Cerate a new indow for the panel and form
window_init(ui, 17, 50);
// Initialize Filter panel specific data
info = g_malloc0(sizeof(filter_info_t));
// Store it into panel userptr
set_panel_userptr(ui->panel, (void*) info);
// Initialize the fields
info->fields[FLD_FILTER_SIPFROM] = new_field(1, 28, 3, 18, 0, 0);
info->fields[FLD_FILTER_SIPTO] = new_field(1, 28, 4, 18, 0, 0);
info->fields[FLD_FILTER_SRC] = new_field(1, 18, 5, 18, 0, 0);
info->fields[FLD_FILTER_DST] = new_field(1, 18, 6, 18, 0, 0);
info->fields[FLD_FILTER_PAYLOAD] = new_field(1, 28, 7, 18, 0, 0);
info->fields[FLD_FILTER_REGISTER] = new_field(1, 1, 9, 15, 0, 0);
info->fields[FLD_FILTER_INVITE] = new_field(1, 1, 10, 15, 0, 0);
info->fields[FLD_FILTER_SUBSCRIBE] = new_field(1, 1, 11, 15, 0, 0);
info->fields[FLD_FILTER_NOTIFY] = new_field(1, 1, 12, 15, 0, 0);
info->fields[FLD_FILTER_INFO] = new_field(1, 1, 13, 15, 0, 0);
info->fields[FLD_FILTER_OPTIONS] = new_field(1, 1, 9, 37, 0, 0);
info->fields[FLD_FILTER_PUBLISH] = new_field(1, 1, 10, 37, 0, 0);
info->fields[FLD_FILTER_MESSAGE] = new_field(1, 1, 11, 37, 0, 0);
info->fields[FLD_FILTER_REFER] = new_field(1, 1, 12, 37, 0, 0);
info->fields[FLD_FILTER_UPDATE] = new_field(1, 1, 13, 37, 0, 0);
info->fields[FLD_FILTER_FILTER] = new_field(1, 10, ui->height - 2, 11, 0, 0);
info->fields[FLD_FILTER_CANCEL] = new_field(1, 10, ui->height - 2, 30, 0, 0);
info->fields[FLD_FILTER_COUNT] = NULL;
// Set fields options
field_opts_off(info->fields[FLD_FILTER_SIPFROM], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_SIPTO], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_SRC], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_DST], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_PAYLOAD], O_AUTOSKIP | O_STATIC);
field_opts_off(info->fields[FLD_FILTER_REGISTER], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_INVITE], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_SUBSCRIBE], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_NOTIFY], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_INFO], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_OPTIONS], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_PUBLISH], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_MESSAGE], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_REFER], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_UPDATE], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_FILTER], O_EDIT);
field_opts_off(info->fields[FLD_FILTER_CANCEL], O_EDIT);
// Change background of input fields
set_field_back(info->fields[FLD_FILTER_SIPFROM], A_UNDERLINE);
set_field_back(info->fields[FLD_FILTER_SIPTO], A_UNDERLINE);
set_field_back(info->fields[FLD_FILTER_SRC], A_UNDERLINE);
set_field_back(info->fields[FLD_FILTER_DST], A_UNDERLINE);
set_field_back(info->fields[FLD_FILTER_PAYLOAD], A_UNDERLINE);
// Create the form and post it
info->form = new_form(info->fields);
set_form_sub(info->form, ui->win);
post_form(info->form);
// Fields labels
mvwprintw(ui->win, 3, 3, "SIP From:");
mvwprintw(ui->win, 4, 3, "SIP To:");
mvwprintw(ui->win, 5, 3, "Source:");
mvwprintw(ui->win, 6, 3, "Destination:");
mvwprintw(ui->win, 7, 3, "Payload:");
mvwprintw(ui->win, 9, 3, "REGISTER [ ]");
mvwprintw(ui->win, 10, 3, "INVITE [ ]");
mvwprintw(ui->win, 11, 3, "SUBSCRIBE [ ]");
mvwprintw(ui->win, 12, 3, "NOTIFY [ ]");
mvwprintw(ui->win, 13, 3, "INFO [ ]");
mvwprintw(ui->win, 9, 25, "OPTIONS [ ]");
mvwprintw(ui->win, 10, 25, "PUBLISH [ ]");
mvwprintw(ui->win, 11, 25, "MESSAGE [ ]");
mvwprintw(ui->win, 12, 25, "REFER [ ]");
mvwprintw(ui->win, 13, 25, "UPDATE [ ]");
// Get Method filter
if (!(method = filter_get(FILTER_METHOD)))
method = setting_get_value(SETTING_FILTER_METHODS);
// Get Payload filter
if (!(payload = filter_get(FILTER_PAYLOAD)))
payload = setting_get_value(SETTING_FILTER_PAYLOAD);
// Set Default field values
set_field_buffer(info->fields[FLD_FILTER_SIPFROM], 0, filter_get(FILTER_SIPFROM));
set_field_buffer(info->fields[FLD_FILTER_SIPTO], 0, filter_get(FILTER_SIPTO));
set_field_buffer(info->fields[FLD_FILTER_SRC], 0, filter_get(FILTER_SOURCE));
set_field_buffer(info->fields[FLD_FILTER_DST], 0, filter_get(FILTER_DESTINATION));
set_field_buffer(info->fields[FLD_FILTER_PAYLOAD], 0, filter_get(FILTER_PAYLOAD));
set_field_buffer(info->fields[FLD_FILTER_REGISTER], 0,
strcasestr(method, sip_method_str(SIP_METHOD_REGISTER)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_INVITE], 0,
strcasestr(method, sip_method_str(SIP_METHOD_INVITE)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_SUBSCRIBE], 0,
strcasestr(method,sip_method_str(SIP_METHOD_SUBSCRIBE)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_NOTIFY], 0,
strcasestr(method, sip_method_str(SIP_METHOD_NOTIFY)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_INFO], 0,
strcasestr(method, sip_method_str(SIP_METHOD_INFO)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_OPTIONS], 0,
strcasestr(method, sip_method_str(SIP_METHOD_OPTIONS)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_PUBLISH], 0,
strcasestr(method, sip_method_str(SIP_METHOD_PUBLISH)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_MESSAGE], 0,
strcasestr(method, sip_method_str(SIP_METHOD_MESSAGE)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_REFER], 0,
strcasestr(method, sip_method_str(SIP_METHOD_REFER)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_UPDATE], 0,
strcasestr(method, sip_method_str(SIP_METHOD_UPDATE)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_FILTER], 0, "[ Filter ]");
set_field_buffer(info->fields[FLD_FILTER_CANCEL], 0, "[ Cancel ]");
// Set the window title and boxes
mvwprintw(ui->win, 1, 18, "Filter options");
wattron(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF));
title_foot_box(ui->panel);
mvwhline(ui->win, 8, 1, ACS_HLINE, 49);
mvwaddch(ui->win, 8, 0, ACS_LTEE);
mvwaddch(ui->win, 8, 49, ACS_RTEE);
wattroff(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF));
// Set default cursor position
set_current_field(info->form, info->fields[FLD_FILTER_SIPFROM]);
wmove(ui->win, 3, 18);
curs_set(1);
}
void
filter_destroy(Window *ui)
{
curs_set(0);
window_deinit(ui);
}
filter_info_t *
static FilterWinInfo *
filter_info(Window *ui)
{
return (filter_info_t*) panel_userptr(ui->panel);
return (FilterWinInfo*) panel_userptr(ui->panel);
}
int
/**
* @brief Return String value for a filter field
*
* @return method name
*/
static const char*
filter_field_method(int field_id)
{
int method;
switch(field_id) {
case FLD_FILTER_REGISTER:
method = SIP_METHOD_REGISTER;
break;
case FLD_FILTER_INVITE:
method = SIP_METHOD_INVITE;
break;
case FLD_FILTER_SUBSCRIBE:
method = SIP_METHOD_SUBSCRIBE;
break;
case FLD_FILTER_NOTIFY:
method = SIP_METHOD_NOTIFY;
break;
case FLD_FILTER_OPTIONS:
method = SIP_METHOD_OPTIONS;
break;
case FLD_FILTER_PUBLISH:
method = SIP_METHOD_PUBLISH;
break;
case FLD_FILTER_MESSAGE:
method = SIP_METHOD_MESSAGE;
break;
case FLD_FILTER_INFO:
method = SIP_METHOD_INFO;
break;
case FLD_FILTER_REFER:
method = SIP_METHOD_REFER;
break;
case FLD_FILTER_UPDATE:
method = SIP_METHOD_UPDATE;
break;
default:
method = -1;
break;
}
return sip_method_str(method);
}
/**
* @brief Save form data to options
*
* This function will update the options values
* of filter fields with its new value.
*
* @param ui UI structure pointer
*/
static void
filter_save_options(Window *ui)
{
char field_value[MAX_SETTING_LEN];
char *expr;
int field_id;
char method_expr[256];
// Initialize variables
memset(method_expr, 0, sizeof(method_expr));
// Get panel information
FilterWinInfo *info = filter_info(ui);
g_return_if_fail(info != NULL);
for (field_id = 0; field_id < FLD_FILTER_COUNT; field_id++) {
// Get current field value.
// We trim spaces with sscanf because and empty field is stored as
// space characters
memset(field_value, 0, sizeof(field_value));
strcpy(field_value, field_buffer(info->fields[field_id], 0));
g_strstrip(field_value);
// Set filter expression
expr = strlen(field_value) ? field_value : NULL;
switch (field_id) {
case FLD_FILTER_SIPFROM:
filter_set(FILTER_SIPFROM, expr);
break;
case FLD_FILTER_SIPTO:
filter_set(FILTER_SIPTO, expr);
break;
case FLD_FILTER_SRC:
filter_set(FILTER_SOURCE, expr);
break;
case FLD_FILTER_DST:
filter_set(FILTER_DESTINATION, expr);
break;
case FLD_FILTER_PAYLOAD:
filter_set(FILTER_PAYLOAD, expr);
break;
case FLD_FILTER_REGISTER:
case FLD_FILTER_INVITE:
case FLD_FILTER_SUBSCRIBE:
case FLD_FILTER_NOTIFY:
case FLD_FILTER_OPTIONS:
case FLD_FILTER_PUBLISH:
case FLD_FILTER_MESSAGE:
case FLD_FILTER_INFO:
case FLD_FILTER_REFER:
case FLD_FILTER_UPDATE:
if (!strcmp(field_value, "*")) {
if (strlen(method_expr)) {
sprintf(method_expr + strlen(method_expr), ",%s", filter_field_method(field_id));
} else {
strcpy(method_expr, filter_field_method(field_id));
}
}
break;
default:
break;
}
}
// Set Method filter
filter_method_from_setting(method_expr);
// Force filter evaluation
filter_reset_calls();
// TODO FIXME Refresh call list FIXME
call_list_win_clear(ncurses_find_by_type(WINDOW_CALL_LIST));
}
/**
* @brief Manage pressed keys for filter panel
*
* This function is called by UI manager every time a
* key is pressed. This allow the filter panel to manage
* its own keys.
*
* @param ui UI structure pointer
* @param key key code
* @return enum @key_handler_ret
*/
static int
filter_handle_key(Window *ui, int key)
{
int field_idx;
@ -206,7 +205,8 @@ filter_handle_key(Window *ui, int key)
int action = -1;
// Get panel information
filter_info_t *info = filter_info(ui);
FilterWinInfo *info = filter_info(ui);
g_return_val_if_fail(info != NULL, -1);
// Get current field id
field_idx = field_index(current_field(info->form));
@ -289,6 +289,7 @@ filter_handle_key(Window *ui, int key)
filter_save_options(ui);
window_destroy(ui);
return KEY_HANDLED;
default:break;
}
break;
case ACTION_CONFIRM:
@ -325,152 +326,147 @@ filter_handle_key(Window *ui, int key)
}
void
filter_save_options(Window *ui)
filter_win_free(Window *ui)
{
char field_value[MAX_SETTING_LEN];
char *expr;
int field_id;
char method_expr[256];
// Initialize variables
memset(method_expr, 0, sizeof(method_expr));
// Get panel information
filter_info_t *info = filter_info(ui);
for (field_id = 0; field_id < FLD_FILTER_COUNT; field_id++) {
// Get current field value.
// We trim spaces with sscanf because and empty field is stored as
// space characters
memset(field_value, 0, sizeof(field_value));
strcpy(field_value, field_buffer(info->fields[field_id], 0));
g_strstrip(field_value);
// Set filter expression
expr = strlen(field_value) ? field_value : NULL;
switch (field_id) {
case FLD_FILTER_SIPFROM:
filter_set(FILTER_SIPFROM, expr);
break;
case FLD_FILTER_SIPTO:
filter_set(FILTER_SIPTO, expr);
break;
case FLD_FILTER_SRC:
filter_set(FILTER_SOURCE, expr);
break;
case FLD_FILTER_DST:
filter_set(FILTER_DESTINATION, expr);
break;
case FLD_FILTER_PAYLOAD:
filter_set(FILTER_PAYLOAD, expr);
break;
case FLD_FILTER_REGISTER:
case FLD_FILTER_INVITE:
case FLD_FILTER_SUBSCRIBE:
case FLD_FILTER_NOTIFY:
case FLD_FILTER_OPTIONS:
case FLD_FILTER_PUBLISH:
case FLD_FILTER_MESSAGE:
case FLD_FILTER_INFO:
case FLD_FILTER_REFER:
case FLD_FILTER_UPDATE:
if (!strcmp(field_value, "*")) {
if (strlen(method_expr)) {
sprintf(method_expr + strlen(method_expr), ",%s", filter_field_method(field_id));
} else {
strcpy(method_expr, filter_field_method(field_id));
}
}
break;
default:
break;
}
}
// Set Method filter
filter_method_from_setting(method_expr);
// Force filter evaluation
filter_reset_calls();
// TODO FIXME Refresh call list FIXME
call_list_win_clear(ncurses_find_by_type(WINDOW_CALL_LIST));
curs_set(0);
window_deinit(ui);
}
const char*
filter_field_method(int field_id)
Window *
filter_win_new()
{
int method;
Window *window = g_malloc0(sizeof(Window));
window->type = WINDOW_FILTER;
window->destroy = filter_win_free;
window->handle_key = filter_handle_key;
switch(field_id) {
case FLD_FILTER_REGISTER:
method = SIP_METHOD_REGISTER;
break;
case FLD_FILTER_INVITE:
method = SIP_METHOD_INVITE;
break;
case FLD_FILTER_SUBSCRIBE:
method = SIP_METHOD_SUBSCRIBE;
break;
case FLD_FILTER_NOTIFY:
method = SIP_METHOD_NOTIFY;
break;
case FLD_FILTER_OPTIONS:
method = SIP_METHOD_OPTIONS;
break;
case FLD_FILTER_PUBLISH:
method = SIP_METHOD_PUBLISH;
break;
case FLD_FILTER_MESSAGE:
method = SIP_METHOD_MESSAGE;
break;
case FLD_FILTER_INFO:
method = SIP_METHOD_INFO;
break;
case FLD_FILTER_REFER:
method = SIP_METHOD_REFER;
break;
case FLD_FILTER_UPDATE:
method = SIP_METHOD_UPDATE;
break;
default:
method = -1;
break;
}
const char *method, *payload;
return sip_method_str(method);
// Cerate a new indow for the panel and form
window_init(window, 17, 50);
// Initialize Filter panel specific data
FilterWinInfo *info = g_malloc0(sizeof(FilterWinInfo));
set_panel_userptr(window->panel, (gpointer) info);
// Initialize the fields
info->fields[FLD_FILTER_SIPFROM] = new_field(1, 28, 3, 18, 0, 0);
info->fields[FLD_FILTER_SIPTO] = new_field(1, 28, 4, 18, 0, 0);
info->fields[FLD_FILTER_SRC] = new_field(1, 18, 5, 18, 0, 0);
info->fields[FLD_FILTER_DST] = new_field(1, 18, 6, 18, 0, 0);
info->fields[FLD_FILTER_PAYLOAD] = new_field(1, 28, 7, 18, 0, 0);
info->fields[FLD_FILTER_REGISTER] = new_field(1, 1, 9, 15, 0, 0);
info->fields[FLD_FILTER_INVITE] = new_field(1, 1, 10, 15, 0, 0);
info->fields[FLD_FILTER_SUBSCRIBE] = new_field(1, 1, 11, 15, 0, 0);
info->fields[FLD_FILTER_NOTIFY] = new_field(1, 1, 12, 15, 0, 0);
info->fields[FLD_FILTER_INFO] = new_field(1, 1, 13, 15, 0, 0);
info->fields[FLD_FILTER_OPTIONS] = new_field(1, 1, 9, 37, 0, 0);
info->fields[FLD_FILTER_PUBLISH] = new_field(1, 1, 10, 37, 0, 0);
info->fields[FLD_FILTER_MESSAGE] = new_field(1, 1, 11, 37, 0, 0);
info->fields[FLD_FILTER_REFER] = new_field(1, 1, 12, 37, 0, 0);
info->fields[FLD_FILTER_UPDATE] = new_field(1, 1, 13, 37, 0, 0);
info->fields[FLD_FILTER_FILTER] = new_field(1, 10, window->height - 2, 11, 0, 0);
info->fields[FLD_FILTER_CANCEL] = new_field(1, 10, window->height - 2, 30, 0, 0);
info->fields[FLD_FILTER_COUNT] = NULL;
// Set fields options
field_opts_off(info->fields[FLD_FILTER_SIPFROM], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_SIPTO], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_SRC], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_DST], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_PAYLOAD], O_AUTOSKIP | O_STATIC);
field_opts_off(info->fields[FLD_FILTER_REGISTER], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_INVITE], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_SUBSCRIBE], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_NOTIFY], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_INFO], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_OPTIONS], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_PUBLISH], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_MESSAGE], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_REFER], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_UPDATE], O_AUTOSKIP);
field_opts_off(info->fields[FLD_FILTER_FILTER], O_EDIT);
field_opts_off(info->fields[FLD_FILTER_CANCEL], O_EDIT);
// Change background of input fields
set_field_back(info->fields[FLD_FILTER_SIPFROM], A_UNDERLINE);
set_field_back(info->fields[FLD_FILTER_SIPTO], A_UNDERLINE);
set_field_back(info->fields[FLD_FILTER_SRC], A_UNDERLINE);
set_field_back(info->fields[FLD_FILTER_DST], A_UNDERLINE);
set_field_back(info->fields[FLD_FILTER_PAYLOAD], A_UNDERLINE);
// Create the form and post it
info->form = new_form(info->fields);
set_form_sub(info->form, window->win);
post_form(info->form);
// Fields labels
mvwprintw(window->win, 3, 3, "SIP From:");
mvwprintw(window->win, 4, 3, "SIP To:");
mvwprintw(window->win, 5, 3, "Source:");
mvwprintw(window->win, 6, 3, "Destination:");
mvwprintw(window->win, 7, 3, "Payload:");
mvwprintw(window->win, 9, 3, "REGISTER [ ]");
mvwprintw(window->win, 10, 3, "INVITE [ ]");
mvwprintw(window->win, 11, 3, "SUBSCRIBE [ ]");
mvwprintw(window->win, 12, 3, "NOTIFY [ ]");
mvwprintw(window->win, 13, 3, "INFO [ ]");
mvwprintw(window->win, 9, 25, "OPTIONS [ ]");
mvwprintw(window->win, 10, 25, "PUBLISH [ ]");
mvwprintw(window->win, 11, 25, "MESSAGE [ ]");
mvwprintw(window->win, 12, 25, "REFER [ ]");
mvwprintw(window->win, 13, 25, "UPDATE [ ]");
// Get Method filter
if (!(method = filter_get(FILTER_METHOD)))
method = setting_get_value(SETTING_FILTER_METHODS);
// Get Payload filter
if (!(payload = filter_get(FILTER_PAYLOAD)))
payload = setting_get_value(SETTING_FILTER_PAYLOAD);
// Set Default field values
set_field_buffer(info->fields[FLD_FILTER_SIPFROM], 0, filter_get(FILTER_SIPFROM));
set_field_buffer(info->fields[FLD_FILTER_SIPTO], 0, filter_get(FILTER_SIPTO));
set_field_buffer(info->fields[FLD_FILTER_SRC], 0, filter_get(FILTER_SOURCE));
set_field_buffer(info->fields[FLD_FILTER_DST], 0, filter_get(FILTER_DESTINATION));
set_field_buffer(info->fields[FLD_FILTER_PAYLOAD], 0, filter_get(FILTER_PAYLOAD));
set_field_buffer(info->fields[FLD_FILTER_REGISTER], 0,
strcasestr(method, sip_method_str(SIP_METHOD_REGISTER)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_INVITE], 0,
strcasestr(method, sip_method_str(SIP_METHOD_INVITE)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_SUBSCRIBE], 0,
strcasestr(method,sip_method_str(SIP_METHOD_SUBSCRIBE)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_NOTIFY], 0,
strcasestr(method, sip_method_str(SIP_METHOD_NOTIFY)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_INFO], 0,
strcasestr(method, sip_method_str(SIP_METHOD_INFO)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_OPTIONS], 0,
strcasestr(method, sip_method_str(SIP_METHOD_OPTIONS)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_PUBLISH], 0,
strcasestr(method, sip_method_str(SIP_METHOD_PUBLISH)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_MESSAGE], 0,
strcasestr(method, sip_method_str(SIP_METHOD_MESSAGE)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_REFER], 0,
strcasestr(method, sip_method_str(SIP_METHOD_REFER)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_UPDATE], 0,
strcasestr(method, sip_method_str(SIP_METHOD_UPDATE)) ? "*" : "");
set_field_buffer(info->fields[FLD_FILTER_FILTER], 0, "[ Filter ]");
set_field_buffer(info->fields[FLD_FILTER_CANCEL], 0, "[ Cancel ]");
// Set the window title and boxes
mvwprintw(window->win, 1, 18, "Filter options");
wattron(window->win, COLOR_PAIR(CP_BLUE_ON_DEF));
title_foot_box(window->panel);
mvwhline(window->win, 8, 1, ACS_HLINE, 49);
mvwaddch(window->win, 8, 0, ACS_LTEE);
mvwaddch(window->win, 8, 49, ACS_RTEE);
wattroff(window->win, COLOR_PAIR(CP_BLUE_ON_DEF));
// Set default cursor position
set_current_field(info->form, info->fields[FLD_FILTER_SIPFROM]);
wmove(window->win, 3, 18);
curs_set(1);
return window;
}
void
filter_method_from_setting(const char *value)
{
char methods[200], method_expr[256];
int methods_len = strlen(value);
char *comma;
// If there's a method filter
if (methods_len) {
// Copy value into temporal array
memset(methods, 0, sizeof(methods));
strncpy(methods, value, methods_len);
// Replace all commas with pippes
while ((comma = strchr(methods, ',')))
*comma = '|';
// Create a regular expression
memset(method_expr, 0, sizeof(method_expr));
sprintf(method_expr, "(%s)", methods);
filter_set(FILTER_METHOD, method_expr);
} else {
filter_set(FILTER_METHOD, " ");
}
}
void
filter_payload_from_setting(const char *value)
{
if (value) filter_set(FILTER_PAYLOAD, value);
}

View File

@ -29,8 +29,8 @@
* dialog, that can be used to filter the lines in call list window.
*/
#ifndef __UI_FILTER_H
#define __UI_FILTER_H
#ifndef __SNGREP_FILTER_WIN_H
#define __SNGREP_FILTER_WIN_H
#include "config.h"
#include <form.h>
@ -43,7 +43,7 @@
* order this fields are stored in panel info structure.
*
*/
enum filter_field_list {
enum FilterWinFields {
FLD_FILTER_SIPFROM = 0,
FLD_FILTER_SIPTO,
FLD_FILTER_SRC,
@ -61,19 +61,18 @@ enum filter_field_list {
FLD_FILTER_UPDATE,
FLD_FILTER_FILTER,
FLD_FILTER_CANCEL,
//! Never remove this field id @see filter_info
FLD_FILTER_COUNT
};
//! Sorter declaration of struct filter_info
typedef struct filter_info filter_info_t;
//! Sorter declaration of struct _FilterWinInfo
typedef struct _FilterWinInfo FilterWinInfo;
/**
* @brief Filter panel private information
*
* This structure contains the durable data of filter panel.
*/
struct filter_info {
struct _FilterWinInfo {
//! Form that contains the filter fields
FORM *form;
//! An array of fields
@ -87,11 +86,9 @@ struct filter_info {
* displaying the filter panel. It also draws all the
* static information of the panel that will never be
* redrawn.
*
* @param ui UI structure pointer
*/
void
filter_create(Window *ui);
Window *
filter_win_new();
/**
* @brief Destroy filter panel
@ -100,63 +97,6 @@ filter_create(Window *ui);
* @param ui UI structure pointer
*/
void
filter_destroy(Window *ui);
filter_win_free(Window *ui);
/**
* @brief Get custom information of given panel
*
* Return ncurses users pointer of the given panel into panel's
* information structure pointer.
*
* @param ui UI structure pointer
* @return a pointer to info structure of given panel
*/
filter_info_t *
filter_info(Window *ui);
/**
* @brief Manage pressed keys for filter panel
*
* This function is called by UI manager every time a
* key is pressed. This allow the filter panel to manage
* its own keys.
*
* @param ui UI structure pointer
* @param key key code
* @return enum @key_handler_ret
*/
int
filter_handle_key(Window *ui, int key);
/**
* @brief Save form data to options
*
* This function will update the options values
* of filter fields with its new value.
*
* @param ui UI structure pointer
*/
void
filter_save_options(Window *ui);
/**
* @brief Return String value for a filter field
*
* @return method name
*/
const char*
filter_field_method(int field_id);
/**
* @brief Set Method filtering from filter.methods setting format
*/
void
filter_method_from_setting(const char *value);
/**
* @brief Set Payload filter from filter.payload setting
*/
void
filter_payload_from_setting(const char *value);
#endif
#endif /* __SNGREP_FILTER_WIN_H */

View File

@ -39,7 +39,7 @@
#include "ncurses/call_list_win.h"
#include "ncurses/call_flow_win.h"
#include "ncurses/call_raw_win.h"
#include "ncurses/ui_filter.h"
#include "ncurses/filter_win.h"
#include "ncurses/ui_msg_diff.h"
#include "ncurses/column_select_win.h"
#include "ncurses/stats_win.h"
@ -218,6 +218,9 @@ ncurses_find_by_type(enum WindowTypes type)
case WINDOW_CALL_RAW:
window = call_raw_win_new();
break;
case WINDOW_FILTER:
window = filter_win_new();
break;
default: break;
}

View File

@ -61,7 +61,7 @@ enum WindowTypes {
//! Raw SIP messages ui screen
WINDOW_CALL_RAW,
//! Filters panel
PANEL_FILTER,
WINDOW_FILTER,
//! Save to pcap panel
PANEL_SAVE,
//! Message comprare