From Ivan Lawrow: Added IEEE 802.15.4-2003 AES-CCM security modes
[obnox/wireshark/wip.git] / tap-httpstat.c
index e03101c5905e542a7eafe7c2c9ffae6faa7ba92e..fc12fcd9b2ec7f1b71b6a93f3ea472fae129c00e 100644 (file)
@@ -1,22 +1,22 @@
 /* tap-httpstat.c
  * tap-httpstat   2003 Jean-Michel FAYARD
  *
- * $Id: tap-httpstat.c,v 1.1 2003/09/02 22:47:58 guy Exp $
+ * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
- * 
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #endif
 
 #include <stdio.h>
+#include <string.h>
 
 #include "epan/packet_info.h"
 #include "epan/value_string.h"
-#include "tap.h"
-#include "register.h"
-#include "packet-http.h"
-#include <string.h>
+#include <epan/tap.h>
+#include <epan/stat_cmd_args.h>
+#include <epan/dissectors/packet-http.h>
+
 
-       
 /* used to keep track of the statictics for an entire program interface */
 typedef struct _http_stats_t {
        char            *filter;
@@ -46,12 +46,13 @@ typedef struct _http_stats_t {
 /* used to keep track of the stats for a specific response code
  * for example it can be { 3, 404, "Not Found" ,...}
  * which means we captured 3 reply http/1.1 404 Not Found */
-typedef struct _http_response_methode_t {
+typedef struct _http_response_code_t {
        guint32          packets;               /* 3 */
-       guint            response_method;       /* 404 */
-       gchar           *name;                  /* Not Found */
+       guint            response_code;         /* 404 */
+       const gchar     *name;                  /* Not Found */
        httpstat_t      *sp;
-} http_response_methode_t;
+} http_response_code_t;
+
 /* used to keep track of the stats for a specific request string */
 typedef struct _http_request_methode_t {
        gchar           *response;      /* eg. : GET */
@@ -99,7 +100,7 @@ static const value_string vals_status_code[] = {
         { 414, "Request-URI Too Large"},
         { 415, "Unsupported Media Type"},
        { 499, "Client Error - Others"},
-       
+
         { 500, "Internal Server Error"},
         { 501, "Not Implemented"},
         { 502, "Bad Gateway"},
@@ -117,15 +118,15 @@ http_init_hash( httpstat_t *sp)
 {
        int i;
 
-       sp->hash_responses = g_hash_table_new( g_int_hash, g_int_equal);                
-                       
+       sp->hash_responses = g_hash_table_new( g_int_hash, g_int_equal);
+
        for (i=0 ; vals_status_code[i].strptr ; i++ )
        {
                gint *key = g_malloc (sizeof(gint));
-               http_response_methode_t *sc = g_malloc (sizeof(http_response_methode_t));
+               http_response_code_t *sc = g_malloc (sizeof(http_response_code_t));
                *key = vals_status_code[i].value;
                sc->packets=0;
-               sc->response_method =  *key;
+               sc->response_code =  *key;
                sc->name=vals_status_code[i].strptr;
                sc->sp = sp;
                g_hash_table_insert( sc->sp->hash_responses, key, sc);
@@ -137,24 +138,24 @@ http_draw_hash_requests( gchar *key _U_ , http_request_methode_t *data, gchar *
 {
        if (data->packets==0)
                return;
-       printf( format, data->response, data->packets);                 
+       printf( format, data->response, data->packets);
 }
 
 static void
-http_draw_hash_responses( gint * key _U_ , http_response_methode_t *data, char * format)
+http_draw_hash_responses( gint * key _U_ , http_response_code_t *data, char * format)
 {
-       if (data==NULL){
-               g_warning("C'est quoi ce borderl key=%d\n", *key);
+       if (data==NULL) {
+               g_warning("No data available, key=%d\n", *key);
                exit(EXIT_FAILURE);
        }
        if (data->packets==0)
                return;
        /* "     HTTP %3d %-35s %9d packets", */
-       printf(format,  data->response_method, data->name, data->packets );
+       printf(format,  data->response_code, data->name, data->packets );
 }
-               
 
-               
+
+
 /* NOT USED at this moment */
 /*
 static void
@@ -165,13 +166,13 @@ http_free_hash( gpointer key, gpointer value, gpointer user_data _U_ )
 }
 */
 static void
-http_reset_hash_responses(gchar *key _U_ , http_response_methode_t *data, gpointer ptr _U_ ) 
-{      
+http_reset_hash_responses(gchar *key _U_ , http_response_code_t *data, gpointer ptr _U_ )
+{
        data->packets = 0;
 }
 static void
-http_reset_hash_requests(gchar *key _U_ , http_request_methode_t *data, gpointer ptr _U_ ) 
-{      
+http_reset_hash_requests(gchar *key _U_ , http_request_methode_t *data, gpointer ptr _U_ )
+{
        data->packets = 0;
 }
 
@@ -179,33 +180,33 @@ static void
 httpstat_reset(void *psp  )
 {
        httpstat_t *sp=psp;
-       if (!sp) {
-               g_hash_table_foreach( sp->hash_responses, (GHFunc)http_reset_hash_responses, NULL);
-               g_hash_table_foreach( sp->hash_responses, (GHFunc)http_reset_hash_requests, NULL);
-       }
+
+       g_hash_table_foreach( sp->hash_responses, (GHFunc)http_reset_hash_responses, NULL);
+       g_hash_table_foreach( sp->hash_requests, (GHFunc)http_reset_hash_requests, NULL);
+
 }
 
 static int
-httpstat_packet(void *psp , packet_info *pinfo _U_, epan_dissect_t *edt _U_, void *pri)
+httpstat_packet(void *psp , packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
 {
-       http_info_value_t *value=pri;
+       const http_info_value_t *value=pri;
        httpstat_t *sp=(httpstat_t *) psp;
 
        /* We are only interested in reply packets with a status code */
        /* Request or reply packets ? */
-       if (value->response_method!=0) {
+       if (value->response_code!=0) {
                guint *key=g_malloc( sizeof(guint) );
-               http_response_methode_t *sc;
-               
-               *key=value->response_method ;
-               sc =  g_hash_table_lookup( 
-                               sp->hash_responses, 
+               http_response_code_t *sc;
+
+               *key=value->response_code;
+               sc =  g_hash_table_lookup(
+                               sp->hash_responses,
                                key);
                if (sc==NULL){
                        /* non standard status code ; we classify it as others
                         * in the relevant category (Informational,Success,Redirection,Client Error,Server Error)
                         */
-                       int i = value->response_method;
+                       int i = value->response_code;
                        if ((i<100) || (i>=600)) {
                                return 0;
                        }
@@ -224,19 +225,19 @@ httpstat_packet(void *psp , packet_info *pinfo _U_, epan_dissect_t *edt _U_, voi
                        else{
                                *key=599;
                        }
-                       sc =  g_hash_table_lookup( 
-                               sp->hash_responses, 
+                       sc =  g_hash_table_lookup(
+                               sp->hash_responses,
                                key);
                        if (sc==NULL)
                                return 0;
                }
                sc->packets++;
-       } 
+       }
        else if (value->request_method){
                http_request_methode_t *sc;
 
-               sc =  g_hash_table_lookup( 
-                               sp->hash_requests, 
+               sc =  g_hash_table_lookup(
+                               sp->hash_requests,
                                value->request_method);
                if (sc==NULL){
                        sc=g_malloc( sizeof(http_request_methode_t) );
@@ -254,7 +255,6 @@ httpstat_packet(void *psp , packet_info *pinfo _U_, epan_dissect_t *edt _U_, voi
 }
 
 
-
 static void
 httpstat_draw(void *psp  )
 {
@@ -267,10 +267,10 @@ httpstat_draw(void *psp  )
                printf("HTTP Statistics with filter %s\n", sp->filter);
 
        printf( "* HTTP Status Codes in reply packets\n");
-       g_hash_table_foreach( sp->hash_responses, (GHFunc)http_draw_hash_responses, 
+       g_hash_table_foreach( sp->hash_responses, (GHFunc)http_draw_hash_responses,
                "    HTTP %3d %s\n");
        printf("* List of HTTP Request methods\n");
-       g_hash_table_foreach( sp->hash_requests,  (GHFunc)http_draw_hash_requests, 
+       g_hash_table_foreach( sp->hash_requests,  (GHFunc)http_draw_hash_requests,
                "    %9s %d \n");
        printf("===================================================================\n");
 }
@@ -280,32 +280,32 @@ httpstat_draw(void *psp  )
 /* When called, this function will create a new instance of gtk_httpstat.
  */
 static void
-gtk_httpstat_init(char *optarg)
+gtk_httpstat_init(const char *optarg,void* userdata _U_)
 {
        httpstat_t *sp;
-       char *filter=NULL;
-       GString         *error_string;
-       
+       const char *filter=NULL;
+       GString *error_string;
+
        if (!strncmp (optarg, "http,stat,", 10)){
                filter=optarg+10;
        } else {
                filter=NULL;
        }
-       
+
        sp = g_malloc( sizeof(httpstat_t) );
        if(filter){
-               sp->filter=g_malloc(strlen(filter)+1);
-               strcpy(sp->filter,filter);
+               sp->filter=g_strdup(filter);
        } else {
                sp->filter=NULL;
        }
        /*g_hash_table_foreach( http_status, (GHFunc)http_reset_hash_responses, NULL);*/
 
 
-       error_string = register_tap_listener( 
+       error_string = register_tap_listener(
                        "http",
                        sp,
                        filter,
+                       0,
                        httpstat_reset,
                        httpstat_packet,
                        httpstat_draw);
@@ -313,7 +313,7 @@ gtk_httpstat_init(char *optarg)
                /* error, we failed to attach to the tap. clean up */
                g_free(sp->filter);
                g_free(sp);
-               fprintf (stderr, "tethereal: Coulnd't register http,stat tap: %s\n",
+               fprintf (stderr, "tshark: Couldn't register http,stat tap: %s\n",
                                error_string->str);
                g_string_free(error_string, TRUE);
                exit(1);
@@ -325,5 +325,5 @@ gtk_httpstat_init(char *optarg)
 void
 register_tap_listener_gtkhttpstat(void)
 {
-       register_ethereal_tap("http,stat,", gtk_httpstat_init);
+       register_stat_cmd_arg("http,stat,", gtk_httpstat_init,NULL);
 }