add WERR_INVALID_STATE
[wireshark-wip.git] / plugins / tpg / packet-http.c
blob9d6d4a57882b5a0ab18e478240996c4e89ceeab6
1 /* packet-http.c
3 * $Id$
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "config.h"
26 #include <epan/wmem/wmem.h>
28 #include "http-parser.h"
29 #include <gmodule.h>
31 static const value_string http_response_codes[] = {
32 { 200, "OK" },
33 { 302, "Later" },
34 { 0, NULL }
37 static gint ett_http = -1;
38 static int proto_http = -1;
40 static int hf_http_is_response = -1;
41 static int hf_http_request_method = -1;
42 static int hf_http_response_code = -1;
43 static int hf_http_transfer_encoding = -1;
44 static int hf_http_content_length = -1;
45 static int hf_http_media = -1;
46 static int hf_http_host = -1;
47 static int hf_http_request_uri = -1;
49 static dissector_handle_t http_handle;
51 static void dissect_http(tvbuff_t* tvb, packet_info* pinfo _U_, proto_tree* tree) {
52 http_info_value_t* msgdata = wmem_alloc0(wmem_packet_scope(), sizeof(http_info_value_t));
53 tvbparse_elem_t* reqresp;
54 tpg_parser_data_t* tpg;
55 proto_item* pi = proto_tree_add_item(tree,proto_http,tvb,0,-1,ENC_NA);
56 proto_tree* pt = proto_item_add_subtree(pi,ett_http);
58 tpg = tpg_start(pt,tvb,0,-1,http_tpg_data.wanted_http_sp, msgdata);
60 if (( reqresp = TPG_GET(tpg,http_tpg_data.wanted_http_req_resp) )) {
61 tvbparse_elem_t* hdr;
63 while(( hdr = TPG_GET(tpg,http_tpg_data.wanted_http_header) ))
66 if ( TPG_GET(tpg,http_tpg_data.wanted_http_crlf) ) {
67 pi = proto_tree_add_boolean(pt,hf_http_is_response,tvb,0,0,msgdata->is_response);
68 pt = proto_item_add_subtree(pi,ett_http);
71 if (msgdata->is_response) {
72 proto_tree_add_uint(pt,hf_http_response_code,tvb,0,0,msgdata->response_code);
73 proto_tree_add_uint(pt,hf_http_content_length,tvb,0,0,msgdata->content_length);
74 if (msgdata->transfer_encoding) proto_tree_add_string(pt,hf_http_transfer_encoding,tvb,0,0,msgdata->transfer_encoding);
75 if (msgdata->media) proto_tree_add_string(pt,hf_http_media,tvb,0,0,msgdata->media);
76 } else {
77 if (msgdata->request_method) proto_tree_add_string(pt,hf_http_request_method,tvb,0,0,msgdata->request_method);
78 if (msgdata->http_host) proto_tree_add_string(pt,hf_http_host,tvb,0,0,msgdata->http_host);
79 if (msgdata->request_uri) proto_tree_add_string(pt,hf_http_request_uri,tvb,0,0,msgdata->request_uri);
82 } else {
83 /* header fragment */
85 } else {
86 /* no header */
87 return;
91 static void proto_register_http(void) {
92 static hf_register_info hf[] = {
93 HF_HTTP_PARSER,
94 { &hf_http_is_response, { "=Is Response", "hyttp.info.is_response", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
95 { &hf_http_request_method, { "=Method", "hyttp.info.method", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
96 { &hf_http_response_code, { "=Response Code", "hyttp.info.response.code", FT_UINT32, BASE_DEC, VALS( http_response_codes ), 0x0, "", HFILL }},
97 { &hf_http_transfer_encoding, { "=Transfer-Encoding", "hyttp.info.transfer_encoding", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
98 { &hf_http_content_length, { "=Content-Length", "hyttp.info.content_length", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
99 { &hf_http_request_uri, { "=Request URI", "hyttp.info.uri", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
100 { &hf_http_media, { "=Media", "hyttp.info.media", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
101 { &hf_http_host, { "=Host", "hyttp.info.host", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }}
104 gint *ett[] = {
105 ETT_HTTP_PARSER,
106 &ett_http
109 tpg_http_init();
111 proto_http = proto_register_protocol("HyTTP", "HyTTP", "hyttp");
112 proto_register_field_array(proto_http, hf, array_length(hf));
113 proto_register_subtree_array(ett, array_length(ett));
117 static void proto_reg_handoff_http(void) {
118 http_handle = create_dissector_handle(dissect_http, proto_http);
120 dissector_delete_uint("tcp.port", 80, NULL);
121 dissector_add_uint("tcp.port", 80, http_handle);
125 #ifndef ENABLE_STATIC
127 WS_DLL_PUBLIC_DEF const gchar version[] = "0.0.0";
129 WS_DLL_PUBLIC_DEF void
130 plugin_register(void)
132 /* register the new protocol, protocol fields, and subtrees */
133 if (proto_http == -1) { /* execute protocol initialization only once */
134 proto_register_http();
138 WS_DLL_PUBLIC_DEF void
139 plugin_reg_handoff(void){
140 proto_reg_handoff_http();
143 #endif