Make it possible to run checkapi on all plugins trough makefile.nmake
[obnox/wireshark/wip.git] / plugins / tpg / packet-http.c
1
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
5
6 #include "http-parser.h"
7 #include <gmodule.h>
8
9 static const value_string http_response_codes[] = {
10 { 200, "OK" },
11 { 302, "Later" },
12 {0,NULL}
13 };
14
15 static gint ett_http = -1;
16 static int proto_http = -1;
17
18 static int hf_http_is_response = -1;
19 static int hf_http_request_method = -1;
20 static int hf_http_response_code = -1;
21 static int hf_http_transfer_encoding = -1;
22 static int hf_http_content_length = -1;
23 static int hf_http_media = -1;
24 static int hf_http_host = -1;
25 static int hf_http_request_uri = -1;
26
27 static dissector_handle_t http_handle;
28
29 static void dissect_http(tvbuff_t* tvb, packet_info* pinfo _U_, proto_tree* tree) {
30     http_info_value_t* msgdata = ep_alloc0(sizeof(http_info_value_t));
31     tvbparse_elem_t* reqresp;
32     tpg_parser_data_t* tpg;
33     proto_item* pi = proto_tree_add_item(tree,proto_http,tvb,0,-1,FALSE);
34     proto_tree* pt = proto_item_add_subtree(pi,ett_http);
35     
36     tpg = tpg_start(pt,tvb,0,-1,http_tpg_data.wanted_http_sp, msgdata);
37     
38     if (( reqresp = TPG_GET(tpg,http_tpg_data.wanted_http_req_resp) )) {
39         tvbparse_elem_t* hdr;
40         
41         while(( hdr = TPG_GET(tpg,http_tpg_data.wanted_http_header) ))
42             ;
43         
44         if ( TPG_GET(tpg,http_tpg_data.wanted_http_crlf) ) {
45             pi = proto_tree_add_boolean(pt,hf_http_is_response,tvb,0,0,msgdata->is_response);
46             pt = proto_item_add_subtree(pi,ett_http);
47             
48
49             if (msgdata->is_response) {
50                 proto_tree_add_uint(pt,hf_http_response_code,tvb,0,0,msgdata->response_code);
51                 proto_tree_add_uint(pt,hf_http_content_length,tvb,0,0,msgdata->content_length);
52                 if (msgdata->transfer_encoding) proto_tree_add_string(pt,hf_http_transfer_encoding,tvb,0,0,msgdata->transfer_encoding);
53                 if (msgdata->media) proto_tree_add_string(pt,hf_http_media,tvb,0,0,msgdata->media);
54             } else {
55                 if (msgdata->request_method) proto_tree_add_string(pt,hf_http_request_method,tvb,0,0,msgdata->request_method);
56                 if (msgdata->http_host) proto_tree_add_string(pt,hf_http_host,tvb,0,0,msgdata->http_host);
57                 if (msgdata->request_uri) proto_tree_add_string(pt,hf_http_request_uri,tvb,0,0,msgdata->request_uri);
58             }
59             
60     } else {
61             /* header fragment */
62         }
63     } else {
64         /* no header  */
65         return;
66     }
67 }
68
69 static void proto_register_http(void) {
70     static hf_register_info hf[] = {
71         HF_HTTP_PARSER,
72         { &hf_http_is_response, { "=Is Response", "hyttp.info.is_response", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
73         { &hf_http_request_method, { "=Method", "hyttp.info.method", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
74         { &hf_http_response_code, { "=Response Code", "hyttp.info.response.code", FT_UINT32, BASE_DEC, VALS( http_response_codes ), 0x0, "", HFILL }},
75         { &hf_http_transfer_encoding, { "=Transfer-Encoding", "hyttp.info.transfer_encoding", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
76         { &hf_http_content_length, { "=Content-Length", "hyttp.info.content_length", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
77         { &hf_http_request_uri, { "=Request URI", "hyttp.info.uri", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
78         { &hf_http_media, { "=Media", "hyttp.info.media", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
79         { &hf_http_host, { "=Host", "hyttp.info.host", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }}
80     };
81     
82     gint *ett[] = {
83         ETT_HTTP_PARSER,
84         &ett_http
85         };
86     
87     tpg_http_init();
88     
89     proto_http = proto_register_protocol("HyTTP",
90                                          "HyTTP", "hyttp");
91         proto_register_field_array(proto_http, hf, array_length(hf));
92         proto_register_subtree_array(ett, array_length(ett));
93             
94 }
95
96
97 static void proto_reg_handoff_http(void) {
98     http_handle = create_dissector_handle(dissect_http, proto_http);
99
100     dissector_delete("tcp.port", 80, NULL);
101     dissector_add("tcp.port", 80, http_handle);
102
103 }
104
105 #ifndef ENABLE_STATIC
106
107 G_MODULE_EXPORT const gchar version[] = "0.0.0";
108
109 G_MODULE_EXPORT void
110 plugin_register(void)
111 {
112         /* register the new protocol, protocol fields, and subtrees */
113         if (proto_http == -1) { /* execute protocol initialization only once */
114                 proto_register_http();
115         }
116 }
117
118 G_MODULE_EXPORT void
119 plugin_reg_handoff(void){
120         proto_reg_handoff_http();
121 }
122
123 #endif
124