aboutsummaryrefslogtreecommitdiffstats
path: root/ui/gtk/sip_stat.c
diff options
context:
space:
mode:
authorBill Meier <wmeier@newsguy.com>2012-09-14 15:19:15 +0000
committerBill Meier <wmeier@newsguy.com>2012-09-14 15:19:15 +0000
commitdd7a2708bed9bc9af5004ab679a93622925f1259 (patch)
tree33fe8309097908abf2a80c485fb39d0636a57ab6 /ui/gtk/sip_stat.c
parentebda6f06b74af80d4d5b33224825628d1600e871 (diff)
Use consistent indentation and formatting style;
Fix a few typos; Fix long line. svn path=/trunk/; revision=44902
Diffstat (limited to 'ui/gtk/sip_stat.c')
-rw-r--r--ui/gtk/sip_stat.c266
1 files changed, 134 insertions, 132 deletions
diff --git a/ui/gtk/sip_stat.c b/ui/gtk/sip_stat.c
index 8a715e309f..f84b6c3c77 100644
--- a/ui/gtk/sip_stat.c
+++ b/ui/gtk/sip_stat.c
@@ -46,32 +46,32 @@
#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;
@@ -79,21 +79,21 @@ typedef struct _sip_stats_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? */
@@ -108,7 +108,7 @@ static const value_string vals_status_code[] = {
{ 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"},
@@ -176,7 +176,7 @@ static const value_string vals_status_code[] = {
{ 606, "Not Acceptable"},
{ 699, "Global Failure - Others"},
- { 0, NULL}
+ { 0, NULL}
};
void register_tap_listener_gtksipstat(void);
@@ -194,15 +194,16 @@ sip_init_hash(sipstat_t *sp)
/* 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);
}
@@ -212,13 +213,13 @@ sip_init_hash(sipstat_t *sp)
/* 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;
}
@@ -226,12 +227,12 @@ sip_draw_hash_requests(gchar *key _U_ , sip_request_method_t *data, gchar * unus
/* 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
@@ -247,22 +248,22 @@ sip_draw_hash_responses(gint * key _U_ , sip_response_code_t *data, gchar * unus
{
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;
}
@@ -297,12 +298,12 @@ sip_draw_hash_responses(gint * key _U_ , sip_response_code_t *data, gchar * unus
#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" */
@@ -317,7 +318,7 @@ sip_draw_hash_responses(gint * key _U_ , sip_response_code_t *data, gchar * unus
/* 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);
@@ -330,7 +331,7 @@ sip_draw_hash_responses(gint * key _U_ , sip_response_code_t *data, gchar * unus
{
/* 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);
}
}
@@ -361,15 +362,15 @@ sipstat_reset(void *psp)
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);
}
}
@@ -377,7 +378,7 @@ sipstat_reset(void *psp)
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 */
@@ -389,27 +390,27 @@ sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const
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)
@@ -421,37 +422,37 @@ sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const
/* 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
{
@@ -460,7 +461,7 @@ sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const
/* 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;
}
@@ -477,11 +478,11 @@ sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const
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);
}
@@ -506,42 +507,43 @@ static void
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);
@@ -549,7 +551,7 @@ win_destroy_cb(GtkWindow *win _U_, gpointer data)
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);
@@ -560,22 +562,22 @@ win_destroy_cb(GtkWindow *win _U_, gpointer data)
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
{
@@ -585,8 +587,8 @@ gtk_sipstat_init(const char *optarg, void *userdata _U_)
/* 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)
@@ -629,14 +631,14 @@ gtk_sipstat_init(const char *optarg, void *userdata _U_)
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);
@@ -677,8 +679,8 @@ gtk_sipstat_init(const char *optarg, void *userdata _U_)
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);
@@ -702,7 +704,7 @@ gtk_sipstat_init(const char *optarg, void *userdata _U_)
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);
@@ -722,16 +724,16 @@ gtk_sipstat_init(const char *optarg, void *userdata _U_)
}
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. */
@@ -743,6 +745,6 @@ register_tap_listener_gtksipstat(void)
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);
}