2 * tap-httpstat 2003 Jean-Michel FAYARD
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include "epan/packet_info.h"
33 #include "epan/value_string.h"
35 #include <epan/stat_cmd_args.h>
37 #include <epan/dissectors/packet-http.h>
40 /* used to keep track of the statictics for an entire program interface */
41 typedef struct _http_stats_t {
43 GHashTable *hash_responses;
44 GHashTable *hash_requests;
47 /* used to keep track of the stats for a specific response code
48 * for example it can be { 3, 404, "Not Found" ,...}
49 * which means we captured 3 reply http/1.1 404 Not Found */
50 typedef struct _http_response_code_t {
51 guint32 packets; /* 3 */
52 guint response_code; /* 404 */
53 const gchar *name; /* Not Found */
55 } http_response_code_t;
57 /* used to keep track of the stats for a specific request string */
58 typedef struct _http_request_methode_t {
59 gchar *response; /* eg. : GET */
62 } http_request_methode_t;
65 static const value_string vals_status_code[] = {
67 { 101, "Switching Protocols" },
68 { 199, "Informational - Others" },
73 { 203, "Non-authoritative Information"},
75 { 205, "Reset Content"},
76 { 206, "Partial Content"},
77 { 299, "Success - Others"}, /* used to keep track of others Success packets */
79 { 300, "Multiple Choices"},
80 { 301, "Moved Permanently"},
81 { 302, "Moved Temporarily"},
83 { 304, "Not Modified"},
85 { 399, "Redirection - Others"},
87 { 400, "Bad Request"},
88 { 401, "Unauthorized"},
89 { 402, "Payment Required"},
92 { 405, "Method Not Allowed"},
93 { 406, "Not Acceptable"},
94 { 407, "Proxy Authentication Required"},
95 { 408, "Request Time-out"},
98 { 411, "Length Required"},
99 { 412, "Precondition Failed"},
100 { 413, "Request Entity Too Large"},
101 { 414, "Request-URI Too Large"},
102 { 415, "Unsupported Media Type"},
103 { 499, "Client Error - Others"},
105 { 500, "Internal Server Error"},
106 { 501, "Not Implemented"},
107 { 502, "Bad Gateway"},
108 { 503, "Service Unavailable"},
109 { 504, "Gateway Time-out"},
110 { 505, "HTTP Version not supported"},
111 { 599, "Server Error - Others"},
116 /* insert some entries */
118 http_init_hash( httpstat_t *sp)
122 sp->hash_responses = g_hash_table_new( g_int_hash, g_int_equal);
124 for (i=0 ; vals_status_code[i].strptr ; i++ )
126 gint *key = g_malloc (sizeof(gint));
127 http_response_code_t *sc = g_malloc (sizeof(http_response_code_t));
128 *key = vals_status_code[i].value;
130 sc->response_code = *key;
131 sc->name=vals_status_code[i].strptr;
133 g_hash_table_insert( sc->sp->hash_responses, key, sc);
135 sp->hash_requests = g_hash_table_new( g_str_hash, g_str_equal);
138 http_draw_hash_requests( gchar *key _U_ , http_request_methode_t *data, gchar * format)
140 if (data->packets==0)
142 printf( format, data->response, data->packets);
146 http_draw_hash_responses( gint * key _U_ , http_response_code_t *data, char * format)
149 g_warning("No data available, key=%d\n", *key);
152 if (data->packets==0)
154 /* " HTTP %3d %-35s %9d packets", */
155 printf(format, data->response_code, data->name, data->packets );
160 /* NOT USED at this moment */
163 http_free_hash( gpointer key, gpointer value, gpointer user_data _U_ )
170 http_reset_hash_responses(gchar *key _U_ , http_response_code_t *data, gpointer ptr _U_ )
175 http_reset_hash_requests(gchar *key _U_ , http_request_methode_t *data, gpointer ptr _U_ )
181 httpstat_reset(void *psp )
185 g_hash_table_foreach( sp->hash_responses, (GHFunc)http_reset_hash_responses, NULL);
186 g_hash_table_foreach( sp->hash_requests, (GHFunc)http_reset_hash_requests, NULL);
191 httpstat_packet(void *psp , packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
193 const http_info_value_t *value=pri;
194 httpstat_t *sp=(httpstat_t *) psp;
196 /* We are only interested in reply packets with a status code */
197 /* Request or reply packets ? */
198 if (value->response_code!=0) {
199 guint *key=g_malloc( sizeof(guint) );
200 http_response_code_t *sc;
202 *key=value->response_code;
203 sc = g_hash_table_lookup(
207 /* non standard status code ; we classify it as others
208 * in the relevant category (Informational,Success,Redirection,Client Error,Server Error)
210 int i = value->response_code;
211 if ((i<100) || (i>=600)) {
215 *key=199; /* Hopefully, this status code will never be used */
229 sc = g_hash_table_lookup(
237 else if (value->request_method){
238 http_request_methode_t *sc;
240 sc = g_hash_table_lookup(
242 value->request_method);
244 sc=g_malloc( sizeof(http_request_methode_t) );
245 sc->response=g_strdup( value->request_method );
248 g_hash_table_insert( sp->hash_requests, sc->response, sc);
260 httpstat_draw(void *psp )
264 printf("===================================================================\n");
266 printf("HTTP Statistics\n");
268 printf("HTTP Statistics with filter %s\n", sp->filter);
270 printf( "* HTTP Status Codes in reply packets\n");
271 g_hash_table_foreach( sp->hash_responses, (GHFunc)http_draw_hash_responses,
273 printf("* List of HTTP Request methods\n");
274 g_hash_table_foreach( sp->hash_requests, (GHFunc)http_draw_hash_requests,
276 printf("===================================================================\n");
281 /* When called, this function will create a new instance of gtk_httpstat.
284 gtk_httpstat_init(const char *optarg,void* userdata _U_)
287 const char *filter=NULL;
288 GString *error_string;
290 if (!strncmp (optarg, "http,stat,", 10)){
296 sp = g_malloc( sizeof(httpstat_t) );
298 sp->filter=g_strdup(filter);
302 /*g_hash_table_foreach( http_status, (GHFunc)http_reset_hash_responses, NULL);*/
305 error_string = register_tap_listener(
313 /* error, we failed to attach to the tap. clean up */
316 fprintf (stderr, "tshark: Couldn't register http,stat tap: %s\n",
318 g_string_free(error_string, TRUE);
326 register_tap_listener_gtkhttpstat(void)
328 register_stat_cmd_arg("http,stat,", gtk_httpstat_init,NULL);