Use val_to_str_const().
[obnox/wireshark/wip.git] / tap-mgcpstat.c
index f16398311503fdaec8c9f2e776fb5eeecf772e64..f5b0b1ee7995aefe9e01c1a9a3e8a023403783bf 100644 (file)
@@ -37,8 +37,7 @@
 #include <epan/tap.h>
 #include <epan/stat_cmd_args.h>
 #include "epan/value_string.h"
-#include "register.h"
-#include "plugins/mgcp/packet-mgcp.h"
+#include "epan/dissectors/packet-mgcp.h"
 #include "timestats.h"
 
 #define NUM_TIMESTATS 11
@@ -64,6 +63,7 @@ static const value_string mgcp_mesage_type[] = {
   {  7,        "AUEP   "},
   {  8, "AUCX   "},
   {  9, "RSIP   "},
+  {  0, NULL}
 };
 
 static int
@@ -72,6 +72,7 @@ mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const vo
        mgcpstat_t *ms=(mgcpstat_t *)pms;
        const mgcp_info_t *mi=pmi;
        nstime_t delta;
+       int ret = 0;
 
        switch (mi->mgcp_type) {
 
@@ -79,24 +80,20 @@ mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const vo
                if(mi->is_duplicate){
                        /* Duplicate is ignored */
                        ms->req_dup_num++;
-                       return 0;
                }
                else {
                        ms->open_req_num++;
-                       return 0;
                }
-       break;
+               break;
 
        case MGCP_RESPONSE:
                if(mi->is_duplicate){
                        /* Duplicate is ignored */
                        ms->rsp_dup_num++;
-                       return 0;
                }
                else if (!mi->request_available) {
                        /* no request was seen */
                        ms->disc_rsp_num++;
-                       return 0;
                }
                else {
                        ms->open_req_num--;
@@ -105,45 +102,46 @@ mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const vo
 
                        time_stat_update(&(ms->rtd[0]),&delta, pinfo);
 
-                       if (strncasecmp(mi->code, "EPCF", 4) == 0 ) {
+                       if (g_ascii_strncasecmp(mi->code, "EPCF", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[1]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "CRCX", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "CRCX", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[2]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "MDCX", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "MDCX", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[3]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "DLCX", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "DLCX", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[4]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "RQNT", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "RQNT", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[5]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "NTFY", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "NTFY", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[6]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "AUEP", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "AUEP", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[7]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "AUCX", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "AUCX", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[8]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "RSIP", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "RSIP", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[9]),&delta, pinfo);
                        }
                        else {
                                time_stat_update(&(ms->rtd[10]),&delta, pinfo);
                        }
 
-                       return 1;
+                       ret = 1;
                }
-       break;
+               break;
 
        default:
-               return 0;
-       break;
+               break;
        }
+
+       return ret;
 }
 
 static void
@@ -181,19 +179,15 @@ mgcpstat_init(const char *optarg, void* userdata _U_)
 {
        mgcpstat_t *ms;
        int i;
-       const char *filter=NULL;
        GString *error_string;
 
+       ms=g_malloc(sizeof(mgcpstat_t));
        if(!strncmp(optarg,"mgcp,rtd,",9)){
-               filter=optarg+9;
+               ms->filter=g_strdup(optarg+9);
        } else {
-               filter="";
+               ms->filter=NULL;
        }
 
-       ms=g_malloc(sizeof(mgcpstat_t));
-       ms->filter=g_malloc(strlen(filter)+1);
-       strcpy(ms->filter, filter);
-
        for(i=0;i<NUM_TIMESTATS;i++) {
                ms->rtd[i].num=0;
                ms->rtd[i].min_num=0;
@@ -211,7 +205,7 @@ mgcpstat_init(const char *optarg, void* userdata _U_)
        ms->req_dup_num=0;
        ms->rsp_dup_num=0;
 
-       error_string=register_tap_listener("mgcp", ms, filter, NULL, mgcpstat_packet, mgcpstat_draw);
+       error_string=register_tap_listener("mgcp", ms, ms->filter, 0, NULL, mgcpstat_packet, mgcpstat_draw);
        if(error_string){
                /* error, we failed to attach to the tap. clean up */
                g_free(ms->filter);