forked from osmocom/wireshark
Minor cleanup:
- simplify code related to use of GHashTables; - use consistent whitespace and formatting style. svn path=/trunk/; revision=44932
This commit is contained in:
parent
fa2c82bb7b
commit
3f04e5b7d0
1 changed files with 51 additions and 57 deletions
|
@ -189,26 +189,24 @@ sip_init_hash(sipstat_t *sp)
|
|||
int i;
|
||||
|
||||
/* Create responses table */
|
||||
sp->hash_responses = g_hash_table_new(g_int_hash, g_int_equal);
|
||||
sp->hash_responses = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
|
||||
|
||||
/* 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->response_code = vals_status_code[i].value;
|
||||
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);
|
||||
g_hash_table_insert(sc->sp->hash_responses, GUINT_TO_POINTER(vals_status_code[i].value), sc);
|
||||
}
|
||||
|
||||
/* Create empty requests table */
|
||||
sp->hash_requests = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
sp->hash_requests = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
}
|
||||
|
||||
/* Draw the entry for an individual request message */
|
||||
|
@ -335,15 +333,6 @@ sip_draw_hash_responses(gint * key _U_ , sip_response_code_t *data, gchar * unus
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
sip_free_hash(gpointer key, gpointer value, gpointer user_data _U_)
|
||||
{
|
||||
g_free(key);
|
||||
g_free(value);
|
||||
}
|
||||
|
||||
static void
|
||||
sip_reset_hash_responses(gchar *key _U_, sip_response_code_t *data, gpointer ptr _U_)
|
||||
{
|
||||
|
@ -391,20 +380,25 @@ sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const
|
|||
}
|
||||
|
||||
/* Calculate average setup time */
|
||||
if (value->setup_time){
|
||||
if (value->setup_time)
|
||||
{
|
||||
sp->no_of_completed_calls++;
|
||||
/* Check if it's the first value */
|
||||
if ( sp->total_setup_time == 0 ){
|
||||
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{
|
||||
} else
|
||||
{
|
||||
sp->total_setup_time = sp->total_setup_time + value->setup_time;
|
||||
if (sp->max_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){
|
||||
if (sp->min_setup_time > value->setup_time)
|
||||
{
|
||||
sp->min_setup_time = value->setup_time;
|
||||
}
|
||||
/* Calculate average */
|
||||
|
@ -416,19 +410,20 @@ sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const
|
|||
if (value->response_code != 0)
|
||||
{
|
||||
/* Responses */
|
||||
guint *key = g_malloc(sizeof(guint));
|
||||
sip_response_code_t *sc;
|
||||
|
||||
/* Look up response code in hash table */
|
||||
*key = value->response_code;
|
||||
sc = g_hash_table_lookup(sp->hash_responses, key);
|
||||
sc = g_hash_table_lookup(sp->hash_responses, GUINT_TO_POINTER(value->response_code));
|
||||
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;
|
||||
guint key;
|
||||
guint i = value->response_code;
|
||||
|
||||
|
||||
if ((i < 100) || (i >= 700))
|
||||
{
|
||||
/* Forget about crazy values */
|
||||
|
@ -436,31 +431,31 @@ sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const
|
|||
}
|
||||
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)
|
||||
{
|
||||
*key = 599;
|
||||
key = 599;
|
||||
}
|
||||
else
|
||||
{
|
||||
*key = 699;
|
||||
key = 699;
|
||||
}
|
||||
|
||||
/* Now look up this fallback code to get its text description */
|
||||
sc = g_hash_table_lookup(sp->hash_responses, key);
|
||||
sc = g_hash_table_lookup(sp->hash_responses, GUINT_TO_POINTER(key));
|
||||
if (sc == NULL)
|
||||
{
|
||||
return 0;
|
||||
|
@ -537,7 +532,7 @@ sipstat_draw(void *psp)
|
|||
* remove_tap_listener() from modifying the list while draw_tap_listener()
|
||||
* 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
|
||||
|
@ -549,9 +544,7 @@ win_destroy_cb(GtkWindow *win _U_, gpointer data)
|
|||
remove_tap_listener(sp);
|
||||
unprotect_thread_critical_region();
|
||||
|
||||
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_destroy(sp->hash_requests);
|
||||
g_free(sp->filter);
|
||||
g_free(sp);
|
||||
|
@ -743,7 +736,8 @@ register_tap_listener_gtksipstat(void)
|
|||
register_dfilter_stat(&sip_stat_dlg, "_SIP", REGISTER_STAT_GROUP_TELEPHONY);
|
||||
}
|
||||
|
||||
void sipstat_cb(GtkAction *action, gpointer user_data _U_)
|
||||
void
|
||||
sipstat_cb(GtkAction *action, gpointer user_data _U_)
|
||||
{
|
||||
tap_param_dlg_cb(action, &sip_stat_dlg);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue