2 * tap-httpstat 2003 Jean-Michel FAYARD
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
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"
36 #include <epan/dissectors/packet-http.h>
39 /* used to keep track of the statictics for an entire program interface */
40 typedef struct _http_stats_t {
42 GHashTable *hash_responses;
43 GHashTable *hash_requests;
46 /* used to keep track of the stats for a specific response code
47 * for example it can be { 3, 404, "Not Found" ,...}
48 * which means we captured 3 reply http/1.1 404 Not Found */
49 typedef struct _http_response_code_t {
50 guint32 packets; /* 3 */
51 guint response_code; /* 404 */
52 gchar *name; /* Not Found */
54 } http_response_code_t;
56 /* used to keep track of the stats for a specific request string */
57 typedef struct _http_request_methode_t {
58 gchar *response; /* eg. : GET */
61 } http_request_methode_t;
64 static const value_string vals_status_code[] = {
66 { 101, "Switching Protocols" },
67 { 199, "Informational - Others" },
72 { 203, "Non-authoritative Information"},
74 { 205, "Reset Content"},
75 { 206, "Partial Content"},
76 { 299, "Success - Others"}, /* used to keep track of others Success packets */
78 { 300, "Multiple Choices"},
79 { 301, "Moved Permanently"},
80 { 302, "Moved Temporarily"},
82 { 304, "Not Modified"},
84 { 399, "Redirection - Others"},
86 { 400, "Bad Request"},
87 { 401, "Unauthorized"},
88 { 402, "Payment Required"},
91 { 405, "Method Not Allowed"},
92 { 406, "Not Acceptable"},
93 { 407, "Proxy Authentication Required"},
94 { 408, "Request Time-out"},
97 { 411, "Length Required"},
98 { 412, "Precondition Failed"},
99 { 413, "Request Entity Too Large"},
100 { 414, "Request-URI Too Large"},
101 { 415, "Unsupported Media Type"},
102 { 499, "Client Error - Others"},
104 { 500, "Internal Server Error"},
105 { 501, "Not Implemented"},
106 { 502, "Bad Gateway"},
107 { 503, "Service Unavailable"},
108 { 504, "Gateway Time-out"},
109 { 505, "HTTP Version not supported"},
110 { 599, "Server Error - Others"},
115 /* insert some entries */
117 http_init_hash( httpstat_t *sp)
121 sp->hash_responses = g_hash_table_new( g_int_hash, g_int_equal);
123 for (i=0 ; vals_status_code[i].strptr ; i++ )
125 gint *key = g_malloc (sizeof(gint));
126 http_response_code_t *sc = g_malloc (sizeof(http_response_code_t));
127 *key = vals_status_code[i].value;
129 sc->response_code = *key;
130 sc->name=vals_status_code[i].strptr;
132 g_hash_table_insert( sc->sp->hash_responses, key, sc);
134 sp->hash_requests = g_hash_table_new( g_str_hash, g_str_equal);
137 http_draw_hash_requests( gchar *key _U_ , http_request_methode_t *data, gchar * format)
139 if (data->packets==0)
141 printf( format, data->response, data->packets);
145 http_draw_hash_responses( gint * key _U_ , http_response_code_t *data, char * format)
148 g_warning("C'est quoi ce borderl key=%d\n", *key);
151 if (data->packets==0)
153 /* " HTTP %3d %-35s %9d packets", */
154 printf(format, data->response_code, data->name, data->packets );
159 /* NOT USED at this moment */
162 http_free_hash( gpointer key, gpointer value, gpointer user_data _U_ )
169 http_reset_hash_responses(gchar *key _U_ , http_response_code_t *data, gpointer ptr _U_ )
174 http_reset_hash_requests(gchar *key _U_ , http_request_methode_t *data, gpointer ptr _U_ )
180 httpstat_reset(void *psp )
184 g_hash_table_foreach( sp->hash_responses, (GHFunc)http_reset_hash_responses, NULL);
185 g_hash_table_foreach( sp->hash_responses, (GHFunc)http_reset_hash_requests, NULL);
190 httpstat_packet(void *psp , packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
192 const http_info_value_t *value=pri;
193 httpstat_t *sp=(httpstat_t *) psp;
195 /* We are only interested in reply packets with a status code */
196 /* Request or reply packets ? */
197 if (value->response_code!=0) {
198 guint *key=g_malloc( sizeof(guint) );
199 http_response_code_t *sc;
201 *key=value->response_code;
202 sc = g_hash_table_lookup(
206 /* non standard status code ; we classify it as others
207 * in the relevant category (Informational,Success,Redirection,Client Error,Server Error)
209 int i = value->response_code;
210 if ((i<100) || (i>=600)) {
214 *key=199; /* Hopefully, this status code will never be used */
228 sc = g_hash_table_lookup(
236 else if (value->request_method){
237 http_request_methode_t *sc;
239 sc = g_hash_table_lookup(
241 value->request_method);
243 sc=g_malloc( sizeof(http_request_methode_t) );
244 sc->response=g_strdup( value->request_method );
247 g_hash_table_insert( sp->hash_requests, sc->response, sc);
259 httpstat_draw(void *psp )
263 printf("===================================================================\n");
265 printf("HTTP Statistics\n");
267 printf("HTTP Statistics with filter %s\n", sp->filter);
269 printf( "* HTTP Status Codes in reply packets\n");
270 g_hash_table_foreach( sp->hash_responses, (GHFunc)http_draw_hash_responses,
272 printf("* List of HTTP Request methods\n");
273 g_hash_table_foreach( sp->hash_requests, (GHFunc)http_draw_hash_requests,
275 printf("===================================================================\n");
280 /* When called, this function will create a new instance of gtk_httpstat.
283 gtk_httpstat_init(char *optarg)
287 GString *error_string;
289 if (!strncmp (optarg, "http,stat,", 10)){
295 sp = g_malloc( sizeof(httpstat_t) );
297 sp->filter=g_malloc(strlen(filter)+1);
298 strcpy(sp->filter,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, "tethereal: Coulnd't register http,stat tap: %s\n",
318 g_string_free(error_string, TRUE);
326 register_tap_listener_gtkhttpstat(void)
328 register_tap_listener_cmd_arg("http,stat,", gtk_httpstat_init);