Backport r29665 to template file so that the change is not overwritten when we regene...
[obnox/wireshark/wip.git] / plugins / tpg / http.tpg
1 #
2 # HTTP header TPG description
3 #
4 # (c) 2005 Luis E. Garcia Ontanon <luis@ontanon.org>
5 #
6 # $Id$
7 #
8 # Wireshark - Network traffic analyzer
9 # By Gerald Combs <gerald@wireshark.org>
10 # Copyright 2004 Gerald Combs
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
26 %header_head %{
27 typedef struct _http_info_value_t
28 {
29         guint32  framenum;
30         gchar   *request_method;        
31         guint    response_code;
32         gchar   *http_host;
33         gchar   *request_uri;
34     guint content_length;
35     gchar* media;
36     gboolean is_response;
37     gchar* transfer_encoding;
38 } http_info_value_t;
39 %}
40
41 %parser_name http .
42 %export req_resp header crlf sp.
43
44 %tt_type %{ http_info_value_t %}
45
46 %rule crlf = "\r\n" .
47
48 %rule sp = [ ]+ .
49
50 %choice versions = "1.0" | "1.1". <version>
51
52 %field version hyttp.version "HTTP Version" FT_STRING .
53
54 %sequence http_version = "HTTP/" & versions .
55
56 %field response hyttp.response "Response" FT_STRING .
57 %field response_code hyttp.response.code "Response Code" FT_UINT32 BASE_DEC %{ http_response_codes %} .
58
59 %sequence %tree response = http_version & [0-9]+<response_code:RESPONSE> & ... ( crlf ) . <response:%plain_text>  %{
60     TT_DATA->is_response = TRUE;
61     TT_DATA->response_code = TPG_UINT(RESPONSE);
62 %}
63
64
65 %field request hyttp.request "Request" FT_STRING .
66 %field method hyttp.request.method "Request Method" FT_STRING  .
67 %field uri hyttp.request.uri "Request URI" FT_STRING  .
68 %sequence %tree request  = [A-Z]+<method:METHOD> & [^ ]+<uri:URI> & http_version & crlf . <request:%plain_text>  %{
69     TT_DATA->is_response = FALSE;
70     TT_DATA->request_method = TPG_STRING(METHOD);
71     TT_DATA->request_uri = TPG_STRING(URI);
72 %}
73
74 %choice req_resp = request | response.
75
76 %field media hyttp.content_type.media "Content-Type Media" FT_STRING  .
77
78 %sequence media  = [a-zA-Z0-9-]+ & "/"  & [a-zA-Z0-9-]+ . <media:MEDIA> %{
79         TT_DATA->media = TPG_STRING(MEDIA);
80 %}
81
82
83 %sequence quoted_string = ["] & [^"]* & ["] .
84
85 %choice value = [a-zA-Z0-9-]+ | quoted_string. 
86
87 %field charset hyttp.content_type.charset "Content-Type Charset" FT_STRING  .
88
89 %sequence parameter  = [a-zA-Z0-9-]+ & [=] & value.
90 %sequence charset_parameter = 'charset' & '=' & [a-z0-9-]+<charset> .
91
92 %choice content_type_param = charset_parameter | parameter .
93
94 %sequence content_type_params =  [;] & content_type_param .
95
96 %sequence content_type_value = media  & content_type_params* .
97
98 %sequence content_type_hdr = 'Content-type:' & content_type_value & crlf .
99
100 %field content_length hyttp.headers.content_length "Content-Length" FT_UINT32 BASE_DEC .
101 %sequence content_length = 'Content-length:'  & [0-9]+<content_length:LENGTH>  & crlf. %{
102     TT_DATA->content_length = TPG_UINT(LENGTH);
103 %}
104
105 %field transfer_encoding hyttp.transfer_encoding "Transfer-Encoding" FT_STRING  .
106 %sequence transfer_encoding = 'Transfer-encoding:' & ...<transfer_encoding:ENCODING> ( crlf     %leave )  & crlf.  %{
107     TT_DATA->transfer_encoding = TPG_STRING(ENCODING);
108 %}
109
110 %field authorization hyttp.authorization "Authorization" FT_STRING  .
111 %sequence authorization = 'Authorization:' & ...<authorization> ( crlf     %leave ) & crlf.
112
113 %field proxy_authorization hyttp.proxy_authorization "Proxy-Authorization" FT_STRING  .
114 %sequence proxy_author = 'Proxy-authorization:' & ...<proxy_authorization> ( crlf     %leave ) & crlf.
115
116 %field proxy_authen hyttp.proxy_authenti "Proxy-Authenticate" FT_STRING  .
117 %sequence proxy_authen = 'Proxy-authenticate:' & ...<proxy_authen> ( crlf     %leave ) & crlf.
118
119 %field www_auth hyttp.www_authenticate "WWW-Authenticate" FT_STRING  .
120 %sequence www_auth = 'WWW-authenticate:' & ...<www_auth> ( crlf     %leave ) & crlf.
121
122 %field content_encoding hyttp.content_encoding "Content-Encoding" FT_STRING  .
123 %sequence content_encoding = 'Content-Encoding:' & ...<content_encoding> ( crlf     %leave ) & crlf.
124
125 %field user_agent hyttp.content_encoding "User-Agent" FT_STRING  .
126 %sequence user_agent = 'User-Agent:' & ...<user_agent> ( crlf     %leave ) & crlf.
127
128 %field host hyttp.host "Host" FT_STRING  .
129 %sequence host  = 'Host:' & ...<host:HOST> ( crlf     %leave ) & crlf. %{
130     TT_DATA->http_host = TPG_STRING(HOST);
131 %}
132
133 %field accept hyttp.accept "Accept" FT_STRING  .
134 %sequence accept  = 'Accept:' & ...<accept> ( crlf     %leave ) & crlf.
135
136 %field accept_language hyttp.accept_language "Accept-Language" FT_STRING  .
137 %sequence accept_language  = 'Accept-language:' & ...<accept_language> ( crlf     %leave ) & crlf.
138
139 %field accept_encoding hyttp.accept_encoding "Accept-Language" FT_STRING  .
140 %sequence accept_encoding  = 'Accept-encoding:' & ...<accept_encoding> ( crlf     %leave ) & crlf.
141
142 %field accept_ranges hyttp.accept_encoding "Accept-Ranges" FT_STRING  .
143 %sequence accept_ranges  = 'Accept-Ranges:' & ...<accept_ranges> ( crlf     %leave ) & crlf.
144
145 %field keep_alive hyttp.keep_alive "Keep-Alive" FT_UINT32 BASE_DEC .
146 %sequence keep_alive  = 'Keep-Alive:' & ...<keep_alive> ( crlf     %leave ) & crlf.
147
148 %field connection hyttp.connection "Connection" FT_STRING .
149 %sequence connection  = 'Connection:' & ...<connection> ( crlf     %leave ) & crlf.
150
151 %field referer hyttp.referer "Referer" FT_STRING .
152 %sequence referer  = 'Referer:' & ...<referer> ( crlf     %leave ) & crlf.
153
154 %field cookie hyttp.cookie "Cookie" FT_STRING .
155 %sequence cookie  = 'Cookie:' & ...<cookie> ( crlf     %leave ) & crlf.
156
157 %field etag hyttp.etag "Etag" FT_STRING .
158 %sequence etag  = 'Etag:' & ["] & [^"]+<etag> & ["] & crlf .
159
160 %field last_modified hyttp.last_modified "Last-Modified" FT_STRING .
161 %sequence last_modified  = 'Last-Modified:' & ...<last_modified> ( crlf     %leave ) & crlf.
162
163 %field server hyttp.server "Server" FT_STRING .
164 %sequence server  = 'Server:' & ...<server> ( crlf     %leave ) & crlf.
165
166 %sequence other_header = [A-Z] & [a-zA-Z-]+ & ":" & ... ( crlf     %leave ) &  crlf.
167
168 %field header hyttp.headers.line "HTTP Header Line" FT_BOOLEAN  .
169 %choice %tree header =
170     content_type_hdr
171     | transfer_encoding
172     | content_length
173     | authorization
174     | proxy_author
175     | proxy_authen
176     | www_auth
177     | content_encoding
178     | user_agent
179     | host
180     | accept
181     | accept_language
182     | accept_encoding
183     | accept_ranges
184     | keep_alive
185     | connection
186     | referer
187     | cookie
188     | etag
189     | last_modified
190     | server
191     | other_header . <header:%plain_text> 
192
193
194 %tail %{
195 /* tail */
196 %}