#include "ui/gtk/old-gtk-compat.h"
-#define SUM_STR_MAX 1024
+#define SUM_STR_MAX 1024
/* Used to keep track of the statistics for an entire program interface */
typedef struct _sip_stats_t {
- char *filter;
- GtkWidget *win;
+ char *filter;
+ GtkWidget *win;
GHashTable *hash_responses;
GHashTable *hash_requests;
- guint32 packets; /* number of sip packets, including continuations */
- guint32 resent_packets;
- guint32 average_setup_time;
- guint32 max_setup_time;
- guint32 min_setup_time;
- guint32 no_of_completed_calls;
- guint64 total_setup_time;
+ guint32 packets; /* number of sip packets, including continuations */
+ guint32 resent_packets;
+ guint32 average_setup_time;
+ guint32 max_setup_time;
+ guint32 min_setup_time;
+ guint32 no_of_completed_calls;
+ guint64 total_setup_time;
GtkWidget *packets_label;
GtkWidget *resent_label;
GtkWidget *average_setup_time_label;
- GtkWidget *request_box; /* container for INVITE, ... */
+ GtkWidget *request_box; /* container for INVITE, ... */
- GtkWidget *informational_table; /* Status code between 100 and 199 */
+ GtkWidget *informational_table; /* Status code between 100 and 199 */
GtkWidget *success_table; /* 200 and 299 */
- GtkWidget *redirection_table; /* 300 and 399 */
- GtkWidget *client_error_table; /* 400 and 499 */
- GtkWidget *server_errors_table; /* 500 and 599 */
+ GtkWidget *redirection_table; /* 300 and 399 */
+ GtkWidget *client_error_table; /* 400 and 499 */
+ GtkWidget *server_errors_table; /* 500 and 599 */
GtkWidget *global_failures_table; /* 600 and 699 */
} sipstat_t;
* for example it can be { 3, 404, "Not Found" ,...}
* which means we captured 3 reply sip/1.1 404 Not Found */
typedef struct _sip_response_code_t {
- guint32 packets; /* 3 */
- guint response_code; /* 404 */
- const gchar *name; /* "Not Found" */
- GtkWidget *widget; /* Label where we display it */
- GtkWidget *table; /* Table in which we put it,
- e.g. client_error_table */
- sipstat_t *sp; /* Pointer back to main struct */
+ guint32 packets; /* 3 */
+ guint response_code; /* 404 */
+ const gchar *name; /* "Not Found" */
+ GtkWidget *widget; /* Label where we display it */
+ GtkWidget *table; /* Table in which we put it,
+ e.g. client_error_table */
+ sipstat_t *sp; /* Pointer back to main struct */
} sip_response_code_t;
/* Used to keep track of the stats for a specific request string */
typedef struct _sip_request_method_t {
- gchar *response; /* eg. : INVITE */
- guint32 packets;
- GtkWidget *widget;
- sipstat_t *sp; /* Pointer back to main struct */
+ gchar *response; /* eg. : INVITE */
+ guint32 packets;
+ GtkWidget *widget;
+ sipstat_t *sp; /* Pointer back to main struct */
} sip_request_method_t;
/* TODO: extra codes to be added from SIP extensions? */
{ 200, "OK"},
{ 202, "Accepted"},
{ 204, "No Notification"},
- { 299, "Success - Others"}, /* used to keep track of other Success packets */
+ { 299, "Success - Others"}, /* used to keep track of other Success packets */
{ 300, "Multiple Choices"},
{ 301, "Moved Permanently"},
{ 606, "Not Acceptable"},
{ 699, "Global Failure - Others"},
- { 0, NULL}
+ { 0, NULL}
};
void register_tap_listener_gtksipstat(void);
/* Add all response codes */
for (i=0 ; vals_status_code[i].strptr ; i++)
{
- gint *key = g_malloc (sizeof(gint));
- sip_response_code_t *sc = g_malloc (sizeof(sip_response_code_t));
- *key = vals_status_code[i].value;
- sc->packets=0;
- sc->response_code = *key;
- sc->name=vals_status_code[i].strptr;
- sc->widget=NULL;
- sc->table=NULL;
- sc->sp = sp;
+ gint *key = g_malloc (sizeof(gint));
+ sip_response_code_t *sc = g_malloc (sizeof(sip_response_code_t));
+
+ *key = vals_status_code[i].value;
+ sc->packets = 0;
+ sc->response_code = *key;
+ sc->name = vals_status_code[i].strptr;
+ sc->widget = NULL;
+ sc->table = NULL;
+ sc->sp = sp;
g_hash_table_insert(sc->sp->hash_responses, key, sc);
}
/* Draw the entry for an individual request message */
static void
-sip_draw_hash_requests(gchar *key _U_ , sip_request_method_t *data, gchar * unused _U_)
+sip_draw_hash_requests(gchar *key _U_, sip_request_method_t *data, gchar *unused _U_)
{
gchar string_buff[SUM_STR_MAX];
- g_assert(data!=NULL);
+ g_assert(data != NULL);
- if (data->packets==0)
+ if (data->packets == 0)
{
return;
}
/* Build string showing method and count */
g_snprintf(string_buff, sizeof(string_buff),
" %-11s : %3d packets", data->response, data->packets);
- if (data->widget==NULL)
+ if (data->widget == NULL)
{
/* Create new label */
- data->widget=gtk_label_new(string_buff);
+ data->widget = gtk_label_new(string_buff);
gtk_misc_set_alignment(GTK_MISC(data->widget), 0.0f, 0.5f);
- gtk_box_pack_start(GTK_BOX(data->sp->request_box), data->widget,FALSE,FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(data->sp->request_box), data->widget, FALSE, FALSE, 0);
gtk_widget_show(data->widget);
}
else
{
gchar string_buff[SUM_STR_MAX];
- g_assert(data!=NULL);
+ g_assert(data != NULL);
- if (data->packets==0)
+ if (data->packets == 0)
{
return;
}
/* Create an entry in the relevant box of the window */
- if (data->widget==NULL)
+ if (data->widget == NULL)
{
guint x;
GtkWidget *tmp;
guint i = data->response_code;
/* Out of valid range - ignore */
- if ((i<100)||(i>=700))
+ if ((i < 100) || (i >= 700))
{
return;
}
#if GTK_CHECK_VERSION(2,22,0)
gtk_table_get_size(GTK_TABLE(data->table), &x, NULL);
#else
- /* Work around GTK bug: Sealed in 2.14, accessor provided in 2.22 */
-# if GTK_CHECK_VERSION (2, 14, 0) && defined(GSEAL_ENABLE)
- x = GTK_TABLE(data->table)->_g_sealed__nrows;
-# else
- x = GTK_TABLE(data->table)->nrows;
-# endif
+ /* Work around GTK bug: Sealed in 2.14, accessor provided in 2.22 */
+# if GTK_CHECK_VERSION (2, 14, 0) && defined(GSEAL_ENABLE)
+ x = GTK_TABLE(data->table)->_g_sealed__nrows;
+# else
+ x = GTK_TABLE(data->table)->nrows;
+# endif
#endif
/* Create a new label with this response, e.g. "SIP 180 Ringing" */
/* Show number of packets */
g_snprintf(string_buff, sizeof(string_buff), "%9d", data->packets);
- data->widget=gtk_label_new(string_buff);
+ data->widget = gtk_label_new(string_buff);
/* Show this widget in the right place */
gtk_table_attach_defaults(GTK_TABLE(data->table), data->widget, 1, 2,x,x+1);
{
/* Just update the existing label string */
g_snprintf(string_buff, sizeof(string_buff), "%9d", data->packets);
- gtk_label_set_text(GTK_LABEL(data->widget), string_buff);
+ gtk_label_set_text(GTK_LABEL(data->widget), string_buff);
}
}
sipstat_t *sp = psp;
if (sp)
{
- sp->packets = 0;
- sp->resent_packets = 0;
- sp->average_setup_time = 0;
- sp->max_setup_time = 0;
- sp->max_setup_time = 0;
- sp->no_of_completed_calls = 0;
- sp->total_setup_time = 0;
+ sp->packets = 0;
+ sp->resent_packets = 0;
+ sp->average_setup_time = 0;
+ sp->max_setup_time = 0;
+ sp->max_setup_time = 0;
+ sp->no_of_completed_calls = 0;
+ sp->total_setup_time = 0;
g_hash_table_foreach(sp->hash_responses, (GHFunc)sip_reset_hash_responses, NULL);
- g_hash_table_foreach(sp->hash_requests, (GHFunc)sip_reset_hash_requests, NULL);
+ g_hash_table_foreach(sp->hash_requests, (GHFunc)sip_reset_hash_requests, NULL);
}
}
static int
sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
{
- const sip_info_value_t *value=pri;
+ const sip_info_value_t *value = pri;
sipstat_t *sp = (sipstat_t *)psp;
/* Total number of packets, including continuation packets */
sp->resent_packets++;
}
- /* Calculate average setup time */
- if (value->setup_time){
- sp->no_of_completed_calls++;
- /* Check if it's the first value */
- if ( sp->total_setup_time == 0 ){
- sp->average_setup_time = value->setup_time;
- sp->total_setup_time = value->setup_time;
- sp->max_setup_time = value->setup_time;
- sp->min_setup_time = value->setup_time;
- }else{
- sp->total_setup_time = sp->total_setup_time + value->setup_time;
- if (sp->max_setup_time < value->setup_time){
- sp->max_setup_time = value->setup_time;
- }
- if (sp->min_setup_time > value->setup_time){
- sp->min_setup_time = value->setup_time;
- }
- /* Calculate average */
- sp->average_setup_time = (guint32)(sp->total_setup_time / sp->no_of_completed_calls);
- }
- }
+ /* Calculate average setup time */
+ if (value->setup_time){
+ sp->no_of_completed_calls++;
+ /* Check if it's the first value */
+ if ( sp->total_setup_time == 0 ){
+ sp->average_setup_time = value->setup_time;
+ sp->total_setup_time = value->setup_time;
+ sp->max_setup_time = value->setup_time;
+ sp->min_setup_time = value->setup_time;
+ }else{
+ sp->total_setup_time = sp->total_setup_time + value->setup_time;
+ if (sp->max_setup_time < value->setup_time){
+ sp->max_setup_time = value->setup_time;
+ }
+ if (sp->min_setup_time > value->setup_time){
+ sp->min_setup_time = value->setup_time;
+ }
+ /* Calculate average */
+ sp->average_setup_time = (guint32)(sp->total_setup_time / sp->no_of_completed_calls);
+ }
+ }
/* Looking at both requests and responses */
if (value->response_code != 0)
/* Look up response code in hash table */
*key = value->response_code;
sc = g_hash_table_lookup(sp->hash_responses, key);
- if (sc==NULL)
+ if (sc == NULL)
{
/* Non-standard status code ; we classify it as others
* in the relevant category
* (Informational,Success,Redirection,Client Error,Server Error,Global Failure)
*/
int i = value->response_code;
- if ((i<100) || (i>=700))
+ if ((i < 100) || (i >= 700))
{
/* Forget about crazy values */
return 0;
}
else if (i<200)
{
- *key=199; /* Hopefully, this status code will never be used */
+ *key = 199; /* Hopefully, this status code will never be used */
}
else if (i<300)
{
- *key=299;
+ *key = 299;
}
else if (i<400)
{
- *key=399;
+ *key = 399;
}
else if (i<500)
{
- *key=499;
+ *key = 499;
}
- else if (i<600)
+ else if (i < 600)
{
- *key=599;
+ *key = 599;
}
else
{
/* Now look up this fallback code to get its text description */
sc = g_hash_table_lookup(sp->hash_responses, key);
- if (sc==NULL)
+ if (sc == NULL)
{
return 0;
}
if (sc == NULL)
{
/* First of this type. Create structure and initialise */
- sc=g_malloc(sizeof(sip_request_method_t));
+ sc = g_malloc(sizeof(sip_request_method_t));
sc->response = g_strdup(value->request_method);
- sc->packets = 1;
- sc->widget = NULL;
- sc->sp = sp;
+ sc->packets = 1;
+ sc->widget = NULL;
+ sc->sp = sp;
/* Insert it into request table */
g_hash_table_insert(sp->hash_requests, sc->response, sc);
}
sipstat_draw(void *psp)
{
gchar string_buff[SUM_STR_MAX];
- sipstat_t *sp=psp;
+ sipstat_t *sp = psp;
/* Set summary label */
g_snprintf(string_buff, sizeof(string_buff),
"SIP stats (%d packets)", sp->packets);
- gtk_label_set_text(GTK_LABEL(sp->packets_label), string_buff);
+ gtk_label_set_text(GTK_LABEL(sp->packets_label), string_buff);
/* Set resend count label */
g_snprintf(string_buff, sizeof(string_buff),
"(%d resent packets)", sp->resent_packets);
- gtk_label_set_text(GTK_LABEL(sp->resent_label), string_buff);
+ gtk_label_set_text(GTK_LABEL(sp->resent_label), string_buff);
/* Draw responses and requests from their tables */
g_hash_table_foreach(sp->hash_responses, (GHFunc)sip_draw_hash_responses, NULL);
- g_hash_table_foreach(sp->hash_requests, (GHFunc)sip_draw_hash_requests, NULL);
+ g_hash_table_foreach(sp->hash_requests, (GHFunc)sip_draw_hash_requests, NULL);
/* Set resend count label */
g_snprintf(string_buff, sizeof(string_buff),
- "Average setup time %d ms\n Min %d ms\n Max %d ms", sp->average_setup_time, sp->min_setup_time, sp->max_setup_time);
- gtk_label_set_text(GTK_LABEL(sp->average_setup_time_label), string_buff);
+ "Average setup time %d ms\n Min %d ms\n Max %d ms",
+ sp->average_setup_time, sp->min_setup_time, sp->max_setup_time);
+ gtk_label_set_text(GTK_LABEL(sp->average_setup_time_label), string_buff);
- gtk_widget_show_all(sp->win);
+ gtk_widget_show_all(sp->win);
}
-/* since the gtk2 implementation of tap is multithreaded we must protect
+/* Since the gtk2 implementation of tap is multithreaded we must protect
* remove_tap_listener() from modifying the list while draw_tap_listener()
- * is running. the other protected block is in main.c
+ * is running. The other protected block is in main.c
*
- * there should not be any other critical regions in gtk2
+ * There should not be any other critical regions in gtk2
*/
/* When window is destroyed, clean up */
static void
win_destroy_cb(GtkWindow *win _U_, gpointer data)
{
- sipstat_t *sp=(sipstat_t *)data;
+ sipstat_t *sp = (sipstat_t *)data;
protect_thread_critical_region();
remove_tap_listener(sp);
g_hash_table_foreach(sp->hash_responses, (GHFunc)sip_free_hash, NULL);
g_hash_table_destroy(sp->hash_responses);
- g_hash_table_foreach(sp->hash_requests, (GHFunc)sip_free_hash, NULL);
+ g_hash_table_foreach(sp->hash_requests, (GHFunc)sip_free_hash, NULL);
g_hash_table_destroy(sp->hash_requests);
g_free(sp->filter);
g_free(sp);
static void
gtk_sipstat_init(const char *optarg, void *userdata _U_)
{
- sipstat_t *sp;
- const char *filter = NULL;
- GString *error_string;
- char *title = NULL;
+ sipstat_t *sp;
+ const char *filter;
+ GString *error_string;
+ char *title;
GtkWidget *main_vb, *separator,
*informational_fr, *success_fr, *redirection_fr,
*client_errors_fr, *server_errors_fr, *global_failures_fr,
*request_fr;
- GtkWidget *bt_close;
- GtkWidget *bbox;
+ GtkWidget *bt_close;
+ GtkWidget *bbox;
if (strncmp (optarg, "sip,stat,", 9) == 0)
{
/* Skip those characters from filter to display */
- filter=optarg + 9;
+ filter = optarg + 9;
}
else
{
/* Create sip stats window structure */
sp = g_malloc(sizeof(sipstat_t));
- sp->win = dlg_window_new("sip-stat"); /* transient_for top_level */
- gtk_window_set_destroy_with_parent (GTK_WINDOW(sp->win), TRUE);
+ sp->win = dlg_window_new("sip-stat"); /* transient_for top_level */
+ gtk_window_set_destroy_with_parent (GTK_WINDOW(sp->win), TRUE);
/* Set title to include any filter given */
if (filter)
gtk_container_add(GTK_CONTAINER(informational_fr), sp->informational_table);
/* Success table and frame */
- success_fr = gtk_frame_new ("Success SIP 2xx");
+ success_fr = gtk_frame_new("Success SIP 2xx");
gtk_box_pack_start(GTK_BOX(main_vb), success_fr, TRUE, TRUE, 0);
sp->success_table = gtk_table_new(0, 2, FALSE);
gtk_container_add(GTK_CONTAINER(success_fr), sp->success_table);
/* Redirection table and frame */
- redirection_fr = gtk_frame_new ("Redirection SIP 3xx");
+ redirection_fr = gtk_frame_new("Redirection SIP 3xx");
gtk_box_pack_start(GTK_BOX(main_vb), redirection_fr, TRUE, TRUE, 0);
sp->redirection_table = gtk_table_new(0, 2, FALSE);
gtk_container_add(GTK_CONTAINER(request_fr), sp->request_box);
sp->average_setup_time = 0;
- sp->max_setup_time =0;
- sp->min_setup_time =0;
+ sp->max_setup_time =0;
+ sp->min_setup_time =0;
sp->average_setup_time_label = gtk_label_new("(Not calculated)");
gtk_box_pack_start(GTK_BOX(main_vb), sp->average_setup_time_label, TRUE, TRUE, 0);
gtk_widget_show(sp->average_setup_time_label);
return;
}
- /* Button row. */
+ /* Button row. */
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
}
static tap_param sip_stat_params[] = {
- { PARAM_FILTER, "Filter", NULL }
+ { PARAM_FILTER, "Filter", NULL }
};
static tap_param_dlg sip_stat_dlg = {
- "SIP Packet Counter",
- "sip,stat",
- gtk_sipstat_init,
- -1,
- G_N_ELEMENTS(sip_stat_params),
- sip_stat_params
+ "SIP Packet Counter",
+ "sip,stat",
+ gtk_sipstat_init,
+ -1,
+ G_N_ELEMENTS(sip_stat_params),
+ sip_stat_params
};
/* Register this tap listener and add menu item. */
void sipstat_cb(GtkAction *action, gpointer user_data _U_)
{
- tap_param_dlg_cb(action, &sip_stat_dlg);
+ tap_param_dlg_cb(action, &sip_stat_dlg);
}