7a7ae7805aad503b2a51fb06981af2a8a53683df
[obnox/wireshark/wip.git] / packet-wsp.c
1 /* packet-wsp.c
2  *
3  * Routines to dissect WSP component of WAP traffic.
4  *
5  * $Id: packet-wsp.c,v 1.106 2004/01/23 09:40:37 jmayer Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * WAP dissector based on original work by Ben Fowler
12  * Updated by Neil Hunter <neil.hunter@energis-squared.com>
13  * WTLS support by Alexandre P. Ferreira (Splice IP)
14  * Openwave header support by Dermot Bradley <dermot.bradley@openwave.com>
15  * Code optimizations, header value dissection simplification with parse error
16  * notification and macros, extra missing headers, WBXML registration,
17  * summary line of WSP PDUs,
18  * Session Initiation Request dissection
19  * by Olivier Biot <olivier.biot(ad)siemens.com>.
20  *
21  * TODO - Move parts of dissection before and other parts after "if (tree)",
22  * for example skip almost all but content type in replies if tree is closed.
23  *
24  * This program is free software; you can redistribute it and/or
25  * modify it under the terms of the GNU General Public License
26  * as published by the Free Software Foundation; either version 2
27  * of the License, or (at your option) any later version.
28  *
29  * This program is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32  * GNU General Public License for more details.
33  *
34  * You should have received a copy of the GNU General Public License
35  * along with this program; if not, write to the Free Software
36  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
37  */
38
39 /* Edit with a 4-space tabulation */
40
41 #ifdef HAVE_CONFIG_H
42 # include "config.h"
43 #endif
44
45 #include <stdio.h>
46 #include <stdlib.h>
47
48 #ifdef NEED_SNPRINTF_H
49 # include "snprintf.h"
50 #endif
51
52 #include <string.h>
53 #include <glib.h>
54 #include <epan/packet.h>
55 #include <epan/ipv6-utils.h>
56 #include <epan/conversation.h>
57
58 #include "packet-wap.h"
59 #include "packet-wsp.h"
60
61 #define PLURALIZE(x)    ( (x) == 1 ? "" : "s" )
62
63 /* General-purpose debug logger.
64  * Requires double parentheses because of variable arguments of printf().
65  *
66  * Enable debug logging for WSP by defining AM_CFLAGS
67  * so that it contains "-DDEBUG_wsp"
68  */
69 #ifdef DEBUG_wsp
70 #define DebugLog(x) \
71         printf("%s:%u: ", __FILE__, __LINE__); \
72         printf x; \
73         fflush(stdout)
74 #else
75 #define DebugLog(x) ;
76 #endif
77
78 /* Statistics (see doc/README.tapping) */
79 #include "tap.h"
80 static int wsp_tap = -1;
81
82
83 /* File scoped variables for the protocol and registered fields */
84 static int proto_wsp                                    = HF_EMPTY;
85 static int proto_sir                                    = HF_EMPTY;
86
87 /*
88  * Initialize the header field pointers
89  */
90
91 /* WSP header fields and their subfields if available */
92 static int hf_hdr_name                                  = HF_EMPTY;
93 static int hf_hdr_accept                                = HF_EMPTY;
94 static int hf_hdr_accept_charset                = HF_EMPTY;
95 static int hf_hdr_accept_encoding               = HF_EMPTY;
96 static int hf_hdr_accept_language               = HF_EMPTY;
97 static int hf_hdr_accept_ranges                 = HF_EMPTY;
98 static int hf_hdr_age                                   = HF_EMPTY;
99 static int hf_hdr_allow                                 = HF_EMPTY;
100 static int hf_hdr_authorization                 = HF_EMPTY;
101 static int hf_hdr_authorization_scheme                  = HF_EMPTY; /* Subfield */
102 static int hf_hdr_authorization_user_id                 = HF_EMPTY; /* Subfield */
103 static int hf_hdr_authorization_password                = HF_EMPTY; /* Subfield */
104 static int hf_hdr_cache_control                 = HF_EMPTY;
105 static int hf_hdr_connection                    = HF_EMPTY;
106 static int hf_hdr_content_base                  = HF_EMPTY;
107 static int hf_hdr_content_encoding              = HF_EMPTY;
108 static int hf_hdr_content_language              = HF_EMPTY;
109 static int hf_hdr_content_length                = HF_EMPTY;
110 static int hf_hdr_content_location              = HF_EMPTY;
111 static int hf_hdr_content_md5                   = HF_EMPTY;
112 static int hf_hdr_content_range                 = HF_EMPTY;
113 static int hf_hdr_content_range_first_byte_pos  = HF_EMPTY; /* Subfield */
114 static int hf_hdr_content_range_entity_length   = HF_EMPTY; /* Subfield */
115 static int hf_hdr_content_type                  = HF_EMPTY;
116 static int hf_hdr_date                                  = HF_EMPTY;
117 static int hf_hdr_etag                                  = HF_EMPTY;
118 static int hf_hdr_expires                               = HF_EMPTY;
119 static int hf_hdr_from                                  = HF_EMPTY;
120 static int hf_hdr_host                                  = HF_EMPTY;
121 static int hf_hdr_if_modified_since             = HF_EMPTY;
122 static int hf_hdr_if_match                              = HF_EMPTY;
123 static int hf_hdr_if_none_match                 = HF_EMPTY;
124 static int hf_hdr_if_range                              = HF_EMPTY;
125 static int hf_hdr_if_unmodified_since   = HF_EMPTY;
126 static int hf_hdr_last_modified                 = HF_EMPTY;
127 static int hf_hdr_location                              = HF_EMPTY;
128 static int hf_hdr_max_forwards                  = HF_EMPTY;
129 static int hf_hdr_pragma                                = HF_EMPTY;
130 static int hf_hdr_proxy_authenticate    = HF_EMPTY;
131 static int hf_hdr_proxy_authenticate_scheme             = HF_EMPTY; /* Subfield */
132 static int hf_hdr_proxy_authenticate_realm              = HF_EMPTY; /* Subfield */
133 static int hf_hdr_proxy_authorization   = HF_EMPTY;
134 static int hf_hdr_proxy_authorization_scheme    = HF_EMPTY; /* Subfield */
135 static int hf_hdr_proxy_authorization_user_id   = HF_EMPTY; /* Subfield */
136 static int hf_hdr_proxy_authorization_password  = HF_EMPTY; /* Subfield */
137 static int hf_hdr_public                                = HF_EMPTY;
138 static int hf_hdr_range                                 = HF_EMPTY;
139 static int hf_hdr_range_first_byte_pos                  = HF_EMPTY; /* Subfield */
140 static int hf_hdr_range_last_byte_pos                   = HF_EMPTY; /* Subfield */
141 static int hf_hdr_range_suffix_length                   = HF_EMPTY; /* Subfield */
142 static int hf_hdr_referer                               = HF_EMPTY;
143 static int hf_hdr_retry_after                   = HF_EMPTY;
144 static int hf_hdr_server                                = HF_EMPTY;
145 static int hf_hdr_transfer_encoding             = HF_EMPTY;
146 static int hf_hdr_upgrade                               = HF_EMPTY;
147 static int hf_hdr_user_agent                    = HF_EMPTY;
148 static int hf_hdr_vary                                  = HF_EMPTY;
149 static int hf_hdr_via                                   = HF_EMPTY;
150 static int hf_hdr_warning                               = HF_EMPTY;
151 static int hf_hdr_warning_code                                  = HF_EMPTY; /* Subfield */
152 static int hf_hdr_warning_agent                                 = HF_EMPTY; /* Subfield */
153 static int hf_hdr_warning_text                                  = HF_EMPTY; /* Subfield */
154 static int hf_hdr_www_authenticate              = HF_EMPTY;
155 static int hf_hdr_www_authenticate_scheme               = HF_EMPTY; /* Subfield */
156 static int hf_hdr_www_authenticate_realm                = HF_EMPTY; /* Subfield */
157 static int hf_hdr_content_disposition   = HF_EMPTY;
158 static int hf_hdr_application_id                = HF_EMPTY;
159 static int hf_hdr_content_uri                   = HF_EMPTY;
160 static int hf_hdr_initiator_uri                 = HF_EMPTY;
161 static int hf_hdr_bearer_indication             = HF_EMPTY;
162 static int hf_hdr_push_flag                             = HF_EMPTY;
163 static int hf_hdr_push_flag_auth                                = HF_EMPTY; /* Subfield */
164 static int hf_hdr_push_flag_trust                               = HF_EMPTY; /* Subfield */
165 static int hf_hdr_push_flag_last                                = HF_EMPTY; /* Subfield */
166 static int hf_hdr_profile                               = HF_EMPTY;
167 static int hf_hdr_profile_diff                  = HF_EMPTY;
168 static int hf_hdr_profile_warning               = HF_EMPTY;
169 static int hf_hdr_expect                                = HF_EMPTY;
170 static int hf_hdr_te                                    = HF_EMPTY;
171 static int hf_hdr_trailer                               = HF_EMPTY;
172 static int hf_hdr_x_wap_tod                             = HF_EMPTY;
173 static int hf_hdr_content_id                    = HF_EMPTY;
174 static int hf_hdr_set_cookie                    = HF_EMPTY;
175 static int hf_hdr_cookie                                = HF_EMPTY;
176 static int hf_hdr_encoding_version              = HF_EMPTY;
177 static int hf_hdr_x_wap_security                = HF_EMPTY;
178 static int hf_hdr_x_wap_application_id  = HF_EMPTY;
179 static int hf_hdr_accept_application    = HF_EMPTY;
180
181
182 /* Openwave headers */
183 static int hf_hdr_openwave_x_up_proxy_operator_domain   = HF_EMPTY;
184 static int hf_hdr_openwave_x_up_proxy_home_page                 = HF_EMPTY;
185 static int hf_hdr_openwave_x_up_proxy_uplink_version    = HF_EMPTY;
186 static int hf_hdr_openwave_x_up_proxy_ba_realm                  = HF_EMPTY;
187 static int hf_hdr_openwave_x_up_proxy_request_uri               = HF_EMPTY;
188 #if 0
189 static int hf_hdr_openwave_x_up_proxy_client_id                 = HF_EMPTY;
190 #endif
191 static int hf_hdr_openwave_x_up_proxy_bookmark                  = HF_EMPTY;
192 static int hf_hdr_openwave_x_up_proxy_push_seq                  = HF_EMPTY;
193 static int hf_hdr_openwave_x_up_proxy_notify                    = HF_EMPTY;
194 static int hf_hdr_openwave_x_up_proxy_net_ask                   = HF_EMPTY;
195 static int hf_hdr_openwave_x_up_proxy_tod                               = HF_EMPTY;
196 static int hf_hdr_openwave_x_up_proxy_ba_enable                 = HF_EMPTY;
197 static int hf_hdr_openwave_x_up_proxy_redirect_enable   = HF_EMPTY;
198 static int hf_hdr_openwave_x_up_proxy_redirect_status   = HF_EMPTY;
199 static int hf_hdr_openwave_x_up_proxy_linger                    = HF_EMPTY;
200 static int hf_hdr_openwave_x_up_proxy_enable_trust              = HF_EMPTY;
201 static int hf_hdr_openwave_x_up_proxy_trust                             = HF_EMPTY;
202 static int hf_hdr_openwave_x_up_devcap_has_color                = HF_EMPTY;
203 static int hf_hdr_openwave_x_up_devcap_num_softkeys             = HF_EMPTY;
204 static int hf_hdr_openwave_x_up_devcap_softkey_size             = HF_EMPTY;
205 static int hf_hdr_openwave_x_up_devcap_screen_chars             = HF_EMPTY;
206 static int hf_hdr_openwave_x_up_devcap_screen_pixels    = HF_EMPTY;
207 static int hf_hdr_openwave_x_up_devcap_em_size                  = HF_EMPTY;
208 static int hf_hdr_openwave_x_up_devcap_screen_depth             = HF_EMPTY;
209 static int hf_hdr_openwave_x_up_devcap_immed_alert              = HF_EMPTY;
210 static int hf_hdr_openwave_x_up_devcap_gui                              = HF_EMPTY;
211 static int hf_hdr_openwave_x_up_proxy_trans_charset             = HF_EMPTY;
212 static int hf_hdr_openwave_x_up_proxy_push_accept               = HF_EMPTY;
213
214
215 /* WSP parameter fields */
216 static int hf_parameter_q                                       = HF_EMPTY;
217 static int hf_parameter_charset                         = HF_EMPTY;
218 #if 0
219 static int hf_parameter_textual                         = HF_EMPTY;
220 static int hf_parameter_type                            = HF_EMPTY;
221 static int hf_parameter_name                            = HF_EMPTY;
222 static int hf_parameter_filename                        = HF_EMPTY;
223 static int hf_parameter_start                           = HF_EMPTY;
224 static int hf_parameter_start_info                      = HF_EMPTY;
225 static int hf_parameter_comment                         = HF_EMPTY;
226 static int hf_parameter_domain                          = HF_EMPTY;
227 static int hf_parameter_path                            = HF_EMPTY;
228 static int hf_parameter_sec                                     = HF_EMPTY;
229 static int hf_parameter_mac                                     = HF_EMPTY;
230 static int hf_parameter_upart_type                      = HF_EMPTY;
231 static int hf_parameter_upart_type_value        = HF_EMPTY;
232 static int hf_parameter_level                           = HF_EMPTY;
233 #endif
234
235 /* Old header fields */
236
237 static int hf_wsp_header_tid                            = HF_EMPTY;
238 static int hf_wsp_header_pdu_type                       = HF_EMPTY;
239 static int hf_wsp_version_major                         = HF_EMPTY;
240 static int hf_wsp_version_minor                         = HF_EMPTY;
241 /* Session capabilities (CO-WSP) */
242 static int hf_capabilities_length               = HF_EMPTY;
243 static int hf_capabilities_section              = HF_EMPTY;
244 static int hf_capa_client_sdu_size              = HF_EMPTY;
245 static int hf_capa_server_sdu_size              = HF_EMPTY;
246 static int hf_capa_protocol_options             = HF_EMPTY;
247 static int hf_capa_protocol_option_confirmed_push               = HF_EMPTY; /* Subfield */
248 static int hf_capa_protocol_option_push                                 = HF_EMPTY; /* Subfield */
249 static int hf_capa_protocol_option_session_resume               = HF_EMPTY; /* Subfield */
250 static int hf_capa_protocol_option_ack_headers                  = HF_EMPTY; /* Subfield */
251 static int hf_capa_protocol_option_large_data_transfer  = HF_EMPTY; /* Subfield */
252 static int hf_capa_method_mor                   = HF_EMPTY;
253 static int hf_capa_push_mor                             = HF_EMPTY;
254 static int hf_capa_extended_methods             = HF_EMPTY;
255 static int hf_capa_header_code_pages    = HF_EMPTY;
256 static int hf_capa_aliases                              = HF_EMPTY;
257 static int hf_capa_client_message_size  = HF_EMPTY;
258 static int hf_capa_server_message_size  = HF_EMPTY;
259
260 static int hf_wsp_header_uri_len                        = HF_EMPTY;
261 static int hf_wsp_header_uri                            = HF_EMPTY;
262 static int hf_wsp_server_session_id                     = HF_EMPTY;
263 static int hf_wsp_header_status                         = HF_EMPTY;
264 static int hf_wsp_header_length                         = HF_EMPTY;
265 static int hf_wsp_headers_section                       = HF_EMPTY;
266 static int hf_wsp_parameter_type                        = HF_EMPTY;
267 static int hf_wsp_parameter_name                        = HF_EMPTY;
268 static int hf_wsp_parameter_filename                    = HF_EMPTY;
269 static int hf_wsp_parameter_start                       = HF_EMPTY;
270 static int hf_wsp_parameter_start_info                  = HF_EMPTY;
271 static int hf_wsp_parameter_comment                     = HF_EMPTY;
272 static int hf_wsp_parameter_domain                      = HF_EMPTY;
273 static int hf_wsp_parameter_path                        = HF_EMPTY;
274 static int hf_wsp_parameter_sec                 = HF_EMPTY;
275 static int hf_wsp_parameter_mac                 = HF_EMPTY;
276 static int hf_wsp_parameter_upart_type                  = HF_EMPTY;
277 static int hf_wsp_parameter_level                       = HF_EMPTY;
278 static int hf_wsp_reply_data                            = HF_EMPTY;
279 static int hf_wsp_post_data                             = HF_EMPTY;
280 static int hf_wsp_push_data                             = HF_EMPTY;
281 static int hf_wsp_multipart_data                        = HF_EMPTY;
282 static int hf_wsp_mpart                                 = HF_EMPTY;
283
284 /* Header code page shift sequence */
285 static int hf_wsp_header_shift_code                     = HF_EMPTY;
286
287 /* WSP Redirect fields */
288 static int hf_wsp_redirect_flags                                        = HF_EMPTY;
289 static int hf_wsp_redirect_permanent                            = HF_EMPTY;
290 static int hf_wsp_redirect_reuse_security_session       = HF_EMPTY;
291 static int hf_redirect_addresses                                        = HF_EMPTY;
292
293 /* Address fields */
294 static int hf_address_entry                             = HF_EMPTY;
295 static int hf_address_flags_length              = HF_EMPTY;
296 static int hf_address_flags_length_bearer_type_included = HF_EMPTY; /* Subfield */
297 static int hf_address_flags_length_port_number_included = HF_EMPTY; /* Subfield */
298 static int hf_address_flags_length_address_len                  = HF_EMPTY; /* Subfield */
299 static int hf_address_bearer_type               = HF_EMPTY;
300 static int hf_address_port_num                  = HF_EMPTY;
301 static int hf_address_ipv4_addr                 = HF_EMPTY;
302 static int hf_address_ipv6_addr                 = HF_EMPTY;
303 static int hf_address_addr                              = HF_EMPTY;
304
305 /* Session Initiation Request fields */
306 static int hf_sir_section                                       = HF_EMPTY;
307 static int hf_sir_version                                       = HF_EMPTY;
308 static int hf_sir_app_id_list_len                       = HF_EMPTY;
309 static int hf_sir_app_id_list                           = HF_EMPTY;
310 static int hf_sir_wsp_contact_points_len        = HF_EMPTY;
311 static int hf_sir_wsp_contact_points            = HF_EMPTY;
312 static int hf_sir_contact_points_len            = HF_EMPTY;
313 static int hf_sir_contact_points                        = HF_EMPTY;
314 static int hf_sir_protocol_options_len          = HF_EMPTY;
315 static int hf_sir_protocol_options                      = HF_EMPTY;
316 static int hf_sir_prov_url_len                          = HF_EMPTY;
317 static int hf_sir_prov_url                                      = HF_EMPTY;
318 static int hf_sir_cpi_tag_len                           = HF_EMPTY;
319 static int hf_sir_cpi_tag                                       = HF_EMPTY;
320
321 /*
322  * Initialize the subtree pointers
323  */
324
325 /* WSP tree */
326 static int ett_wsp                                              = ETT_EMPTY;
327 /* WSP headers tree */
328 static int ett_header                                   = ETT_EMPTY;
329 /* WSP header subtree */
330 static int ett_headers                                  = ETT_EMPTY;
331 /* CO-WSP session capabilities */
332 static int ett_capabilities                             = ETT_EMPTY;
333 static int ett_capability                               = ETT_EMPTY;
334 static int ett_post                                             = ETT_EMPTY;
335 static int ett_redirect_flags                   = ETT_EMPTY;
336 static int ett_address_flags                    = ETT_EMPTY;
337 static int ett_multiparts                               = ETT_EMPTY;
338 static int ett_mpartlist                                = ETT_EMPTY;
339 /* Session Initiation Request tree */
340 static int ett_sir                                              = ETT_EMPTY;
341 static int ett_addresses                                = ETT_EMPTY;
342 static int ett_address                                  = ETT_EMPTY;
343
344
345
346 /* Handle for WSP-over-UDP dissector */
347 static dissector_handle_t wsp_fromudp_handle;
348
349 /* Handle for WTP-over-UDP dissector */
350 static dissector_handle_t wtp_fromudp_handle;
351
352 const value_string vals_pdu_type[] = {
353         { 0x00, "Reserved" },
354         { 0x01, "Connect" },
355         { 0x02, "ConnectReply" },
356         { 0x03, "Redirect" },
357         { 0x04, "Reply" },
358         { 0x05, "Disconnect" },
359         { 0x06, "Push" },
360         { 0x07, "ConfirmedPush" },
361         { 0x08, "Suspend" },
362         { 0x09, "Resume" },
363
364         /* 0x10 - 0x3F Unassigned */
365
366         { 0x40, "Get" },
367         { 0x41, "Options" },
368         { 0x42, "Head" },
369         { 0x43, "Delete" },
370         { 0x44, "Trace" },
371
372         /* 0x45 - 0x4F Unassigned (Get PDU) */
373         /* 0x50 - 0x5F Extended method (Get PDU) */
374         { 0x50, "Extended Get Method 0"},
375         { 0x51, "Extended Get Method 1"},
376         { 0x52, "Extended Get Method 2"},
377         { 0x53, "Extended Get Method 3"},
378         { 0x54, "Extended Get Method 4"},
379         { 0x55, "Extended Get Method 5"},
380         { 0x56, "Extended Get Method 6"},
381         { 0x57, "Extended Get Method 7"},
382         { 0x58, "Extended Get Method 8"},
383         { 0x59, "Extended Get Method 9"},
384         { 0x5A, "Extended Get Method 10"},
385         { 0x5B, "Extended Get Method 11"},
386         { 0x5C, "Extended Get Method 12"},
387         { 0x5D, "Extended Get Method 13"},
388         { 0x5E, "Extended Get Method 14"},
389         { 0x5F, "Extended Get Method 15"},
390
391         { 0x60, "Post" },
392         { 0x61, "Put" },
393
394         /* 0x62 - 0x6F Unassigned (Post PDU) */
395         /* 0x70 - 0x7F Extended method (Post PDU) */
396         { 0x70, "Extended Post Method 0"},
397         { 0x71, "Extended Post Method 1"},
398         { 0x72, "Extended Post Method 2"},
399         { 0x73, "Extended Post Method 3"},
400         { 0x74, "Extended Post Method 4"},
401         { 0x75, "Extended Post Method 5"},
402         { 0x76, "Extended Post Method 6"},
403         { 0x77, "Extended Post Method 7"},
404         { 0x78, "Extended Post Method 8"},
405         { 0x79, "Extended Post Method 9"},
406         { 0x7A, "Extended Post Method 10"},
407         { 0x7B, "Extended Post Method 11"},
408         { 0x7C, "Extended Post Method 12"},
409         { 0x7D, "Extended Post Method 13"},
410         { 0x7E, "Extended Post Method 14"},
411         { 0x7F, "Extended Post Method 15"},
412
413         /* 0x80 - 0xFF Reserved */
414
415         { 0x00, NULL }
416
417 };
418
419 /* The WSP status codes are inherited from the HTTP status codes */
420 const value_string vals_status[] = {
421         /* 0x00 - 0x0F Reserved */
422
423         { 0x10, "100 Continue" },
424         { 0x11, "101 Switching Protocols" },
425
426         { 0x20, "200 OK" },
427         { 0x21, "201 Created" },
428         { 0x22, "202 Accepted" },
429         { 0x23, "203 Non-Authoritative Information" },
430         { 0x24, "204 No Content" },
431         { 0x25, "205 Reset Content" },
432         { 0x26, "206 Partial Content" },
433
434         { 0x30, "300 Multiple Choices" },
435         { 0x31, "301 Moved Permanently" },
436         { 0x32, "302 Moved Temporarily" },
437         { 0x33, "303 See Other" },
438         { 0x34, "304 Not Modified" },
439         { 0x35, "305 Use Proxy" },
440         { 0x37, "307 Temporary Redirect" },
441
442         { 0x40, "400 Bad Request" },
443         { 0x41, "401 Unauthorised" },
444         { 0x42, "402 Payment Required" },
445         { 0x43, "403 Forbidden" },
446         { 0x44, "404 Not Found" },
447         { 0x45, "405 Method Not Allowed" },
448         { 0x46, "406 Not Acceptable" },
449         { 0x47, "407 Proxy Authentication Required" },
450         { 0x48, "408 Request Timeout" },
451         { 0x49, "409 Conflict" },
452         { 0x4A, "410 Gone" },
453         { 0x4B, "411 Length Required" },
454         { 0x4C, "412 Precondition Failed" },
455         { 0x4D, "413 Request Entity Too Large" },
456         { 0x4E, "414 Request-URI Too Large" },
457         { 0x4F, "415 Unsupported Media Type" },
458         { 0x50, "416 Requested Range Not Satisfiable" },
459         { 0x51, "417 Expectation Failed" },
460
461         { 0x60, "500 Internal Server Error" },
462         { 0x61, "501 Not Implemented" },
463         { 0x62, "502 Bad Gateway" },
464         { 0x63, "503 Service Unavailable" },
465         { 0x64, "504 Gateway Timeout" },
466         { 0x65, "505 WSP/HTTP Version Not Supported" },
467
468         { 0x00, NULL }
469 };
470
471 const value_string vals_wsp_reason_codes[] = {
472         { 0xE0, "Protocol Error (Illegal PDU)" },
473         { 0xE1, "Session disconnected" },
474         { 0xE2, "Session suspended" },
475         { 0xE3, "Session resumed" },
476         { 0xE4, "Peer congested" },
477         { 0xE5, "Session connect failed" },
478         { 0xE6, "Maximum receive unit size exceeded" },
479         { 0xE7, "Maximum outstanding requests exceeded" },
480         { 0xE8, "Peer request" },
481         { 0xE9, "Network error" },
482         { 0xEA, "User request" },
483         { 0xEB, "No specific cause, no retries" },
484         { 0xEC, "Push message cannot be delivered" },
485         { 0xED, "Push message discarded" },
486         { 0xEE, "Content type cannot be processed" },
487
488         { 0x00, NULL }
489 };
490
491 /*
492  * Field names.
493  */
494 #define FN_ACCEPT               0x00
495 #define FN_ACCEPT_CHARSET_DEP   0x01    /* encoding version 1.1, deprecated */
496 #define FN_ACCEPT_ENCODING_DEP  0x02    /* encoding version 1.1, deprecated */
497 #define FN_ACCEPT_LANGUAGE      0x03
498 #define FN_ACCEPT_RANGES        0x04
499 #define FN_AGE                  0x05
500 #define FN_ALLOW                0x06
501 #define FN_AUTHORIZATION        0x07
502 #define FN_CACHE_CONTROL_DEP    0x08    /* encoding version 1.1, deprecated */
503 #define FN_CONNECTION           0x09
504 #define FN_CONTENT_BASE         0x0A
505 #define FN_CONTENT_ENCODING     0x0B
506 #define FN_CONTENT_LANGUAGE     0x0C
507 #define FN_CONTENT_LENGTH       0x0D
508 #define FN_CONTENT_LOCATION     0x0E
509 #define FN_CONTENT_MD5          0x0F
510 #define FN_CONTENT_RANGE_DEP    0x10    /* encoding version 1.1, deprecated */
511 #define FN_CONTENT_TYPE         0x11
512 #define FN_DATE                 0x12
513 #define FN_ETAG                 0x13
514 #define FN_EXPIRES              0x14
515 #define FN_FROM                 0x15
516 #define FN_HOST                 0x16
517 #define FN_IF_MODIFIED_SINCE    0x17
518 #define FN_IF_MATCH             0x18
519 #define FN_IF_NONE_MATCH        0x19
520 #define FN_IF_RANGE             0x1A
521 #define FN_IF_UNMODIFIED_SINCE  0x1B
522 #define FN_LOCATION             0x1C
523 #define FN_LAST_MODIFIED        0x1D
524 #define FN_MAX_FORWARDS         0x1E
525 #define FN_PRAGMA               0x1F
526 #define FN_PROXY_AUTHENTICATE   0x20
527 #define FN_PROXY_AUTHORIZATION  0x21
528 #define FN_PUBLIC               0x22
529 #define FN_RANGE                0x23
530 #define FN_REFERER              0x24
531 #define FN_RETRY_AFTER          0x25
532 #define FN_SERVER               0x26
533 #define FN_TRANSFER_ENCODING    0x27
534 #define FN_UPGRADE              0x28
535 #define FN_USER_AGENT           0x29
536 #define FN_VARY                 0x2A
537 #define FN_VIA                  0x2B
538 #define FN_WARNING              0x2C
539 #define FN_WWW_AUTHENTICATE     0x2D
540 #define FN_CONTENT_DISPOSITION  0x2E
541 #define FN_X_WAP_APPLICATION_ID 0x2F
542 #define FN_X_WAP_CONTENT_URI    0x30
543 #define FN_X_WAP_INITIATOR_URI  0x31
544 #define FN_ACCEPT_APPLICATION   0x32
545 #define FN_BEARER_INDICATION    0x33
546 #define FN_PUSH_FLAG            0x34
547 #define FN_PROFILE              0x35
548 #define FN_PROFILE_DIFF         0x36
549 #define FN_PROFILE_WARNING      0x37
550 #define FN_EXPECT               0x38
551 #define FN_TE                   0x39
552 #define FN_TRAILER              0x3A
553 #define FN_ACCEPT_CHARSET       0x3B    /* encoding version 1.3 */
554 #define FN_ACCEPT_ENCODING      0x3C    /* encoding version 1.3 */
555 #define FN_CACHE_CONTROL        0x3D    /* encoding version 1.3 */
556 #define FN_CONTENT_RANGE        0x3E    /* encoding version 1.3 */
557 #define FN_X_WAP_TOD            0x3F
558 #define FN_CONTENT_ID           0x40
559 #define FN_SET_COOKIE           0x41
560 #define FN_COOKIE               0x42
561 #define FN_ENCODING_VERSION     0x43
562 #define FN_PROFILE_WARNING14    0x44    /* encoding version 1.4 */
563 #define FN_CONTENT_DISPOSITION14        0x45    /* encoding version 1.4 */
564 #define FN_X_WAP_SECURITY       0x46
565 #define FN_CACHE_CONTROL14      0x47    /* encoding version 1.4 */
566 #define FN_EXPECT15 0x48        /* encoding version 1.5 */
567 #define FN_X_WAP_LOC_INVOCATION 0x49
568 #define FN_X_WAP_LOC_DELIVERY 0x4A
569
570
571 /*
572  * Openwave field names.
573  */
574 #define FN_OPENWAVE_PROXY_PUSH_ADDR             0x00
575 #define FN_OPENWAVE_PROXY_PUSH_ACCEPT           0x01
576 #define FN_OPENWAVE_PROXY_PUSH_SEQ              0x02
577 #define FN_OPENWAVE_PROXY_NOTIFY                0x03
578 #define FN_OPENWAVE_PROXY_OPERATOR_DOMAIN       0x04
579 #define FN_OPENWAVE_PROXY_HOME_PAGE             0x05
580 #define FN_OPENWAVE_DEVCAP_HAS_COLOR            0x06
581 #define FN_OPENWAVE_DEVCAP_NUM_SOFTKEYS         0x07
582 #define FN_OPENWAVE_DEVCAP_SOFTKEY_SIZE         0x08
583 #define FN_OPENWAVE_DEVCAP_SCREEN_CHARS         0x09
584 #define FN_OPENWAVE_DEVCAP_SCREEN_PIXELS        0x0A
585 #define FN_OPENWAVE_DEVCAP_EM_SIZE              0x0B
586 #define FN_OPENWAVE_DEVCAP_SCREEN_DEPTH         0x0C
587 #define FN_OPENWAVE_DEVCAP_IMMED_ALERT          0x0D
588 #define FN_OPENWAVE_PROXY_NET_ASK               0x0E
589 #define FN_OPENWAVE_PROXY_UPLINK_VERSION        0x0F
590 #define FN_OPENWAVE_PROXY_TOD                   0x10
591 #define FN_OPENWAVE_PROXY_BA_ENABLE             0x11
592 #define FN_OPENWAVE_PROXY_BA_REALM              0x12
593 #define FN_OPENWAVE_PROXY_REDIRECT_ENABLE       0x13
594 #define FN_OPENWAVE_PROXY_REQUEST_URI           0x14
595 #define FN_OPENWAVE_PROXY_REDIRECT_STATUS       0x15
596 #define FN_OPENWAVE_PROXY_TRANS_CHARSET         0x16
597 #define FN_OPENWAVE_PROXY_LINGER                0x17
598 #define FN_OPENWAVE_PROXY_CLIENT_ID             0x18
599 #define FN_OPENWAVE_PROXY_ENABLE_TRUST          0x19
600 #define FN_OPENWAVE_PROXY_TRUST_OLD             0x1A
601 #define FN_OPENWAVE_PROXY_TRUST                 0x20
602 #define FN_OPENWAVE_PROXY_BOOKMARK              0x21
603 #define FN_OPENWAVE_DEVCAP_GUI                  0x22
604
605 static const value_string vals_openwave_field_names[] = {
606         { FN_OPENWAVE_PROXY_PUSH_ADDR,         "x-up-proxy-push-addr" },
607         { FN_OPENWAVE_PROXY_PUSH_ACCEPT,       "x-up-proxy-push-accept" },
608         { FN_OPENWAVE_PROXY_PUSH_SEQ,          "x-up-proxy-seq" },
609         { FN_OPENWAVE_PROXY_NOTIFY,            "x-up-proxy-notify" },
610         { FN_OPENWAVE_PROXY_OPERATOR_DOMAIN,   "x-up-proxy-operator-domain" },
611         { FN_OPENWAVE_PROXY_HOME_PAGE,         "x-up-proxy-home-page" },
612         { FN_OPENWAVE_DEVCAP_HAS_COLOR,        "x-up-devcap-has-color" },
613         { FN_OPENWAVE_DEVCAP_NUM_SOFTKEYS,     "x-up-devcap-num-softkeys" },
614         { FN_OPENWAVE_DEVCAP_SOFTKEY_SIZE,     "x-up-devcap-softkey-size" },
615         { FN_OPENWAVE_DEVCAP_SCREEN_CHARS,     "x-up-devcap-screen-chars" },
616         { FN_OPENWAVE_DEVCAP_SCREEN_PIXELS,    "x-up-devcap-screen-pixels" },
617         { FN_OPENWAVE_DEVCAP_EM_SIZE,          "x-up-devcap-em-size" },
618         { FN_OPENWAVE_DEVCAP_SCREEN_DEPTH,     "x-up-devcap-screen-depth" },
619         { FN_OPENWAVE_DEVCAP_IMMED_ALERT,      "x-up-devcap-immed-alert" },
620         { FN_OPENWAVE_PROXY_NET_ASK,           "x-up-proxy-net-ask" },
621         { FN_OPENWAVE_PROXY_UPLINK_VERSION,    "x-up-proxy-uplink-version" },
622         { FN_OPENWAVE_PROXY_TOD,               "x-up-proxy-tod" },
623         { FN_OPENWAVE_PROXY_BA_ENABLE,         "x-up-proxy-ba-enable" },
624         { FN_OPENWAVE_PROXY_BA_REALM,          "x-up-proxy-ba-realm" },
625         { FN_OPENWAVE_PROXY_REDIRECT_ENABLE,   "x-up-proxy-redirect-enable" },
626         { FN_OPENWAVE_PROXY_REQUEST_URI,       "x-up-proxy-request-uri" },
627         { FN_OPENWAVE_PROXY_REDIRECT_STATUS,   "x-up-proxy-redirect-status" },
628         { FN_OPENWAVE_PROXY_TRANS_CHARSET,     "x-up-proxy-trans-charset" },
629         { FN_OPENWAVE_PROXY_LINGER,            "x-up-proxy-linger" },
630         { FN_OPENWAVE_PROXY_CLIENT_ID,         "x-up-proxy-client-id" },
631         { FN_OPENWAVE_PROXY_ENABLE_TRUST,      "x-up-proxy-enable-trust" },
632         { FN_OPENWAVE_PROXY_TRUST_OLD,         "x-up-proxy-trust-old" },
633         { FN_OPENWAVE_PROXY_TRUST,             "x-up-proxy-trust" },
634         { FN_OPENWAVE_PROXY_BOOKMARK,          "x-up-proxy-bookmark" },
635         { FN_OPENWAVE_DEVCAP_GUI,              "x-up-devcap-gui" },
636         { 0,                                   NULL }
637 };
638
639
640 static const value_string vals_field_names[] = {
641         { FN_ACCEPT,               "Accept" },
642         { FN_ACCEPT_CHARSET_DEP,   "Accept-Charset (encoding 1.1)" },
643         { FN_ACCEPT_ENCODING_DEP,  "Accept-Encoding (encoding 1.1)" },
644         { FN_ACCEPT_LANGUAGE,      "Accept-Language" },
645         { FN_ACCEPT_RANGES,        "Accept-Ranges" },
646         { FN_AGE,                  "Age" },
647         { FN_ALLOW,                "Allow" },
648         { FN_AUTHORIZATION,        "Authorization" },
649         { FN_CACHE_CONTROL_DEP,    "Cache-Control (encoding 1.1)" },
650         { FN_CONNECTION,           "Connection" },
651         { FN_CONTENT_BASE,         "Content-Base" },
652         { FN_CONTENT_ENCODING,     "Content-Encoding" },
653         { FN_CONTENT_LANGUAGE,     "Content-Language" },
654         { FN_CONTENT_LENGTH,       "Content-Length" },
655         { FN_CONTENT_LOCATION,     "Content-Location" },
656         { FN_CONTENT_MD5,          "Content-MD5" },
657         { FN_CONTENT_RANGE_DEP,    "Content-Range (encoding 1.1)" },
658         { FN_CONTENT_TYPE,         "Content-Type" },
659         { FN_DATE,                 "Date" },
660         { FN_ETAG,                 "ETag" },
661         { FN_EXPIRES,              "Expires" },
662         { FN_FROM,                 "From" },
663         { FN_HOST,                 "Host" },
664         { FN_IF_MODIFIED_SINCE,    "If-Modified-Since" },
665         { FN_IF_MATCH,             "If-Match" },
666         { FN_IF_NONE_MATCH,        "If-None-Match" },
667         { FN_IF_RANGE,             "If-Range" },
668         { FN_IF_UNMODIFIED_SINCE,  "If-Unmodified-Since" },
669         { FN_LOCATION,             "Location" },
670         { FN_LAST_MODIFIED,        "Last-Modified" },
671         { FN_MAX_FORWARDS,         "Max-Forwards" },
672         { FN_PRAGMA,               "Pragma" },
673         { FN_PROXY_AUTHENTICATE,   "Proxy-Authenticate" },
674         { FN_PROXY_AUTHORIZATION,  "Proxy-Authorization" },
675         { FN_PUBLIC,               "Public" },
676         { FN_RANGE,                "Range" },
677         { FN_REFERER,              "Referer" },
678         { FN_RETRY_AFTER,          "Retry-After" },
679         { FN_SERVER,               "Server" },
680         { FN_TRANSFER_ENCODING,    "Transfer-Encoding" },
681         { FN_UPGRADE,              "Upgrade" },
682         { FN_USER_AGENT,           "User-Agent" },
683         { FN_VARY,                 "Vary" },
684         { FN_VIA,                  "Via" },
685         { FN_WARNING,              "Warning" },
686         { FN_WWW_AUTHENTICATE,     "WWW-Authenticate" },
687         { FN_CONTENT_DISPOSITION,  "Content-Disposition" },
688         { FN_X_WAP_APPLICATION_ID, "X-Wap-Application-ID" },
689         { FN_X_WAP_CONTENT_URI,    "X-Wap-Content-URI" },
690         { FN_X_WAP_INITIATOR_URI,  "X-Wap-Initiator-URI" },
691         { FN_ACCEPT_APPLICATION,   "Accept-Application" },
692         { FN_BEARER_INDICATION,    "Bearer-Indication" },
693         { FN_PUSH_FLAG,            "Push-Flag" },
694         { FN_PROFILE,              "Profile" },
695         { FN_PROFILE_DIFF,         "Profile-Diff" },
696         { FN_PROFILE_WARNING,      "Profile-Warning" },
697         { FN_EXPECT,               "Expect" },
698         { FN_TE,                   "TE" },
699         { FN_TRAILER,              "Trailer" },
700         { FN_ACCEPT_CHARSET,       "Accept-Charset" },
701         { FN_ACCEPT_ENCODING,      "Accept-Encoding" },
702         { FN_CACHE_CONTROL,        "Cache-Control" },
703         { FN_CONTENT_RANGE,        "Content-Range" },
704         { FN_X_WAP_TOD,            "X-Wap-Tod" },
705         { FN_CONTENT_ID,           "Content-ID" },
706         { FN_SET_COOKIE,           "Set-Cookie" },
707         { FN_COOKIE,               "Cookie" },
708         { FN_ENCODING_VERSION,     "Encoding-Version" },
709         { FN_PROFILE_WARNING14,    "Profile-Warning (encoding 1.4)" },
710         { FN_CONTENT_DISPOSITION14,"Content-Disposition (encoding 1.4)" },
711         { FN_X_WAP_SECURITY,       "X-WAP-Security" },
712         { FN_CACHE_CONTROL14,      "Cache-Control (encoding 1.4)" },
713         /* encoding-version 1.5 */
714         { FN_EXPECT15,             "Expect (encoding 1.5)" },
715         { FN_X_WAP_LOC_INVOCATION, "X-Wap-Loc-Invocation" },
716         { FN_X_WAP_LOC_DELIVERY,   "X-Wap-Loc-Delivery" },
717         { 0,                       NULL }
718 };
719
720 /*
721  * Bearer types (from the WDP specification).
722  */
723 #define BT_IPv4                 0x00
724 #define BT_IPv6                 0x01
725 #define BT_GSM_USSD             0x02
726 #define BT_GSM_SMS              0x03
727 #define BT_ANSI_136_GUTS        0x04
728 #define BT_IS_95_SMS            0x05
729 #define BT_IS_95_CSD            0x06
730 #define BT_IS_95_PACKET_DATA    0x07
731 #define BT_ANSI_136_CSD         0x08
732 #define BT_ANSI_136_PACKET_DATA 0x09
733 #define BT_GSM_CSD              0x0A
734 #define BT_GSM_GPRS             0x0B
735 #define BT_GSM_USSD_IPv4        0x0C
736 #define BT_AMPS_CDPD            0x0D
737 #define BT_PDC_CSD              0x0E
738 #define BT_PDC_PACKET_DATA      0x0F
739 #define BT_IDEN_SMS             0x10
740 #define BT_IDEN_CSD             0x11
741 #define BT_IDEN_PACKET_DATA     0x12
742 #define BT_PAGING_FLEX          0x13
743 #define BT_PHS_SMS              0x14
744 #define BT_PHS_CSD              0x15
745 #define BT_GSM_USSD_GSM_SC      0x16
746 #define BT_TETRA_SDS_ITSI       0x17
747 #define BT_TETRA_SDS_MSISDN     0x18
748 #define BT_TETRA_PACKET_DATA    0x19
749 #define BT_PAGING_REFLEX        0x1A
750 #define BT_GSM_USSD_MSISDN      0x1B
751 #define BT_MOBITEX_MPAK         0x1C
752 #define BT_ANSI_136_GHOST       0x1D
753
754 static const value_string vals_bearer_types[] = {
755         { BT_IPv4,                 "IPv4" },
756         { BT_IPv6,                 "IPv6" },
757         { BT_GSM_USSD,             "GSM USSD" },
758         { BT_GSM_SMS,              "GSM SMS" },
759         { BT_ANSI_136_GUTS,        "ANSI-136 GUTS/R-Data" },
760         { BT_IS_95_SMS,            "IS-95 CDMA SMS" },
761         { BT_IS_95_CSD,            "IS-95 CDMA CSD" },
762         { BT_IS_95_PACKET_DATA,    "IS-95 CDMA Packet data" },
763         { BT_ANSI_136_CSD,         "ANSI-136 CSD" },
764         { BT_ANSI_136_PACKET_DATA, "ANSI-136 Packet data" },
765         { BT_GSM_CSD,              "GSM CSD" },
766         { BT_GSM_GPRS,             "GSM GPRS" },
767         { BT_GSM_USSD_IPv4,        "GSM USSD (IPv4 addresses)" },
768         { BT_AMPS_CDPD,            "AMPS CDPD" },
769         { BT_PDC_CSD,              "PDC CSD" },
770         { BT_PDC_PACKET_DATA,      "PDC Packet data" },
771         { BT_IDEN_SMS,             "IDEN SMS" },
772         { BT_IDEN_CSD,             "IDEN CSD" },
773         { BT_IDEN_PACKET_DATA,     "IDEN Packet data" },
774         { BT_PAGING_FLEX,          "Paging network FLEX(TM)" },
775         { BT_PHS_SMS,              "PHS SMS" },
776         { BT_PHS_CSD,              "PHS CSD" },
777         { BT_GSM_USSD_GSM_SC,      "GSM USSD (GSM Service Code addresses)" },
778         { BT_TETRA_SDS_ITSI,       "TETRA SDS (ITSI addresses)" },
779         { BT_TETRA_SDS_MSISDN,     "TETRA SDS (MSISDN addresses)" },
780         { BT_TETRA_PACKET_DATA,    "TETRA Packet data" },
781         { BT_PAGING_REFLEX,        "Paging network ReFLEX(TM)" },
782         { BT_GSM_USSD_MSISDN,      "GSM USSD (MSISDN addresses)" },
783         { BT_MOBITEX_MPAK,         "Mobitex MPAK" },
784         { BT_ANSI_136_GHOST,       "ANSI-136 GHOST/R-Data" },
785         { 0,                       NULL }
786 };
787
788 static const value_string vals_content_types[] = {
789         /* Well-known media types */
790         { 0x00, "*/*" },
791         { 0x01, "text/*" },
792         { 0x02, "text/html" },
793         { 0x03, "text/plain" },
794         { 0x04, "text/x-hdml" },
795         { 0x05, "text/x-ttml" },
796         { 0x06, "text/x-vCalendar" },
797         { 0x07, "text/x-vCard" },
798         { 0x08, "text/vnd.wap.wml" },
799         { 0x09, "text/vnd.wap.wmlscript" },
800         { 0x0A, "text/vnd.wap.channel" },
801         { 0x0B, "multipart/*" },
802         { 0x0C, "multipart/mixed" },
803         { 0x0D, "multipart/form-data" },
804         { 0x0E, "multipart/byteranges" },
805         { 0x0F, "multipart/alternative" },
806         { 0x10, "application/*" },
807         { 0x11, "application/java-vm" },
808         { 0x12, "application/x-www-form-urlencoded" },
809         { 0x13, "application/x-hdmlc" },
810         { 0x14, "application/vnd.wap.wmlc" },
811         { 0x15, "application/vnd.wap.wmlscriptc" },
812         { 0x16, "application/vnd.wap.channelc" },
813         { 0x17, "application/vnd.wap.uaprof" },
814         { 0x18, "application/vnd.wap.wtls-ca-certificate" },
815         { 0x19, "application/vnd.wap.wtls-user-certificate" },
816         { 0x1A, "application/x-x509-ca-cert" },
817         { 0x1B, "application/x-x509-user-cert" },
818         { 0x1C, "image/*" },
819         { 0x1D, "image/gif" },
820         { 0x1E, "image/jpeg" },
821         { 0x1F, "image/tiff" },
822         { 0x20, "image/png" },
823         { 0x21, "image/vnd.wap.wbmp" },
824         { 0x22, "application/vnd.wap.multipart.*" },
825         { 0x23, "application/vnd.wap.multipart.mixed" },
826         { 0x24, "application/vnd.wap.multipart.form-data" },
827         { 0x25, "application/vnd.wap.multipart.byteranges" },
828         { 0x26, "application/vnd.wap.multipart.alternative" },
829         { 0x27, "application/xml" },
830         { 0x28, "text/xml" },
831         { 0x29, "application/vnd.wap.wbxml" },
832         { 0x2A, "application/x-x968-cross-cert" },
833         { 0x2B, "application/x-x968-ca-cert" },
834         { 0x2C, "application/x-x968-user-cert" },
835         { 0x2D, "text/vnd.wap.si" },
836         { 0x2E, "application/vnd.wap.sic" },
837         { 0x2F, "text/vnd.wap.sl" },
838         { 0x30, "application/vnd.wap.slc" },
839         { 0x31, "text/vnd.wap.co" },
840         { 0x32, "application/vnd.wap.coc" },
841         { 0x33, "application/vnd.wap.multipart.related" },
842         { 0x34, "application/vnd.wap.sia" },
843         { 0x35, "text/vnd.wap.connectivity-xml" },
844         { 0x36, "application/vnd.wap.connectivity-wbxml" },
845         { 0x37, "application/pkcs7-mime" },
846         { 0x38, "application/vnd.wap.hashed-certificate" },
847         { 0x39, "application/vnd.wap.signed-certificate" },
848         { 0x3A, "application/vnd.wap.cert-response" },
849         { 0x3B, "application/xhtml+xml" },
850         { 0x3C, "application/wml+xml" },
851         { 0x3D, "text/css" },
852         { 0x3E, "application/vnd.wap.mms-message" },
853         { 0x3F, "application/vnd.wap.rollover-certificate" },
854         { 0x40, "application/vnd.wap.locc+wbxml"},
855         { 0x41, "application/vnd.wap.loc+xml"},
856         { 0x42, "application/vnd.syncml.dm+wbxml"},
857         { 0x43, "application/vnd.syncml.dm+xml"},
858         { 0x44, "application/vnd.syncml.notification"},
859         { 0x45, "application/vnd.wap.xhtml+xml"},
860         { 0x46, "application/vnd.wv.csp.cir"},
861         { 0x47, "application/vnd.oma.dd+xml"},
862         { 0x48, "application/vnd.oma.drm.message"},
863         { 0x49, "application/vnd.oma.drm.content"},
864         { 0x4A, "application/vnd.oma.drm.rights+xml"},
865         { 0x4B, "application/vnd.oma.drm.rights+wbxml"},
866         { 0x4C, "application/vnd.wv.csp+xml"},
867         { 0x4D, "application/vnd.wv.csp+wbxml"},
868         /* The following media types are registered by 3rd parties */ 
869         { 0x0201, "application/vnd.uplanet.cachop-wbxml" },
870         { 0x0202, "application/vnd.uplanet.signal" },
871         { 0x0203, "application/vnd.uplanet.alert-wbxml" },
872         { 0x0204, "application/vnd.uplanet.list-wbxml" },
873         { 0x0205, "application/vnd.uplanet.listcmd-wbxml" },
874         { 0x0206, "application/vnd.uplanet.channel-wbxml" },
875         { 0x0207, "application/vnd.uplanet.provisioning-status-uri" },
876         { 0x0208, "x-wap.multipart/vnd.uplanet.header-set" },
877         { 0x0209, "application/vnd.uplanet.bearer-choice-wbxml" },
878         { 0x020A, "application/vnd.phonecom.mmc-wbxml" },
879         { 0x020B, "application/vnd.nokia.syncset+wbxml" },
880         { 0x020C, "image/x-up-wpng"},
881         { 0x0300, "application/iota.mmc-wbxml"},
882         { 0x0301, "application/iota.mmc-xml"},
883         { 0x00, NULL }
884 };
885
886 static const value_string vals_languages[] = {
887         { 0x01, "Afar (aa)" },
888         { 0x02, "Abkhazian (ab)" },
889         { 0x03, "Afrikaans (af)" },
890         { 0x04, "Amharic (am)" },
891         { 0x05, "Arabic (ar)" },
892         { 0x06, "Assamese (as)" },
893         { 0x07, "Aymara (ay)" },
894         { 0x08, "Azerbaijani (az)" },
895         { 0x09, "Bashkir (ba)" },
896         { 0x0A, "Byelorussian (be)" },
897         { 0x0B, "Bulgarian (bg)" },
898         { 0x0C, "Bihari (bh)" },
899         { 0x0D, "Bislama (bi)" },
900         { 0x0E, "Bengali; Bangla (bn)" },
901         { 0x0F, "Tibetan (bo)" },
902         { 0x10, "Breton (br)" },
903         { 0x11, "Catalan (ca)" },
904         { 0x12, "Corsican (co)" },
905         { 0x13, "Czech (cs)" },
906         { 0x14, "Welsh (cy)" },
907         { 0x15, "Danish (da)" },
908         { 0x16, "German (de)" },
909         { 0x17, "Bhutani (dz)" },
910         { 0x18, "Greek (el)" },
911         { 0x19, "English (en)" },
912         { 0x1A, "Esperanto (eo)" },
913         { 0x1B, "Spanish (es)" },
914         { 0x1C, "Estonian (et)" },
915         { 0x1D, "Basque (eu)" },
916         { 0x1E, "Persian (fa)" },
917         { 0x1F, "Finnish (fi)" },
918         { 0x20, "Fiji (fj)" },
919         { 0x21, "Urdu (ur)" },
920         { 0x22, "French (fr)" },
921         { 0x23, "Uzbek (uz)" },
922         { 0x24, "Irish (ga)" },
923         { 0x25, "Scots Gaelic (gd)" },
924         { 0x26, "Galician (gl)" },
925         { 0x27, "Guarani (gn)" },
926         { 0x28, "Gujarati (gu)" },
927         { 0x29, "Hausa (ha)" },
928         { 0x2A, "Hebrew (formerly iw) (he)" },
929         { 0x2B, "Hindi (hi)" },
930         { 0x2C, "Croatian (hr)" },
931         { 0x2D, "Hungarian (hu)" },
932         { 0x2E, "Armenian (hy)" },
933         { 0x2F, "Vietnamese (vi)" },
934         { 0x30, "Indonesian (formerly in) (id)" },
935         { 0x31, "Wolof (wo)" },
936         { 0x32, "Xhosa (xh)" },
937         { 0x33, "Icelandic (is)" },
938         { 0x34, "Italian (it)" },
939         { 0x35, "Yoruba (yo)" },
940         { 0x36, "Japanese (ja)" },
941         { 0x37, "Javanese (jw)" },
942         { 0x38, "Georgian (ka)" },
943         { 0x39, "Kazakh (kk)" },
944         { 0x3A, "Zhuang (za)" },
945         { 0x3B, "Cambodian (km)" },
946         { 0x3C, "Kannada (kn)" },
947         { 0x3D, "Korean (ko)" },
948         { 0x3E, "Kashmiri (ks)" },
949         { 0x3F, "Kurdish (ku)" },
950         { 0x40, "Kirghiz (ky)" },
951         { 0x41, "Chinese (zh)" },
952         { 0x42, "Lingala (ln)" },
953         { 0x43, "Laothian (lo)" },
954         { 0x44, "Lithuanian (lt)" },
955         { 0x45, "Latvian, Lettish (lv)" },
956         { 0x46, "Malagasy (mg)" },
957         { 0x47, "Maori (mi)" },
958         { 0x48, "Macedonian (mk)" },
959         { 0x49, "Malayalam (ml)" },
960         { 0x4A, "Mongolian (mn)" },
961         { 0x4B, "Moldavian (mo)" },
962         { 0x4C, "Marathi (mr)" },
963         { 0x4D, "Malay (ms)" },
964         { 0x4E, "Maltese (mt)" },
965         { 0x4F, "Burmese (my)" },
966         { 0x50, "Ukrainian (uk)" },
967         { 0x51, "Nepali (ne)" },
968         { 0x52, "Dutch (nl)" },
969         { 0x53, "Norwegian (no)" },
970         { 0x54, "Occitan (oc)" },
971         { 0x55, "(Afan) Oromo (om)" },
972         { 0x56, "Oriya (or)" },
973         { 0x57, "Punjabi (pa)" },
974         { 0x58, "Polish (po)" },
975         { 0x59, "Pashto, Pushto (ps)" },
976         { 0x5A, "Portuguese (pt)" },
977         { 0x5B, "Quechua (qu)" },
978         { 0x5C, "Zulu (zu)" },
979         { 0x5D, "Kirundi (rn)" },
980         { 0x5E, "Romanian (ro)" },
981         { 0x5F, "Russian (ru)" },
982         { 0x60, "Kinyarwanda (rw)" },
983         { 0x61, "Sanskrit (sa)" },
984         { 0x62, "Sindhi (sd)" },
985         { 0x63, "Sangho (sg)" },
986         { 0x64, "Serbo-Croatian (sh)" },
987         { 0x65, "Sinhalese (si)" },
988         { 0x66, "Slovak (sk)" },
989         { 0x67, "Slovenian (sl)" },
990         { 0x68, "Samoan (sm)" },
991         { 0x69, "Shona (sn)" },
992         { 0x6A, "Somali (so)" },
993         { 0x6B, "Albanian (sq)" },
994         { 0x6C, "Serbian (sr)" },
995         { 0x6D, "Siswati (ss)" },
996         { 0x6E, "Sesotho (st)" },
997         { 0x6F, "Sundanese (su)" },
998         { 0x70, "Swedish (sv)" },
999         { 0x71, "Swahili (sw)" },
1000         { 0x72, "Tamil (ta)" },
1001         { 0x73, "Telugu (te)" },
1002         { 0x74, "Tajik (tg)" },
1003         { 0x75, "Thai (th)" },
1004         { 0x76, "Tigrinya (ti)" },
1005         { 0x77, "Turkmen (tk)" },
1006         { 0x78, "Tagalog (tl)" },
1007         { 0x79, "Setswana (tn)" },
1008         { 0x7A, "Tonga (to)" },
1009         { 0x7B, "Turkish (tr)" },
1010         { 0x7C, "Tsonga (ts)" },
1011         { 0x7D, "Tatar (tt)" },
1012         { 0x7E, "Twi (tw)" },
1013         { 0x7F, "Uighur (ug)" },
1014         { 0x81, "Nauru (na)" },
1015         { 0x82, "Faeroese (fo)" },
1016         { 0x83, "Frisian (fy)" },
1017         { 0x84, "Interlingua (ia)" },
1018         { 0x85, "Volapuk (vo)" },
1019         { 0x86, "Interlingue (ie)" },
1020         { 0x87, "Inupiak (ik)" },
1021         { 0x88, "Yiddish (formerly ji) (yi)" },
1022         { 0x89, "Inuktitut (iu)" },
1023         { 0x8A, "Greenlandic (kl)" },
1024         { 0x8B, "Latin (la)" },
1025         { 0x8C, "Rhaeto-Romance (rm)" },
1026         { 0x00, NULL }
1027 };
1028
1029
1030 #define CACHE_CONTROL_NO_CACHE                  0x00
1031 #define CACHE_CONTROL_NO_STORE                  0x01
1032 #define CACHE_CONTROL_MAX_AGE                   0x02
1033 #define CACHE_CONTROL_MAX_STALE                 0x03
1034 #define CACHE_CONTROL_MIN_FRESH                 0x04
1035 #define CACHE_CONTROL_ONLY_IF_CACHED    0x05
1036 #define CACHE_CONTROL_PUBLIC                    0x06
1037 #define CACHE_CONTROL_PRIVATE                   0x07
1038 #define CACHE_CONTROL_NO_TRANSFORM              0x08
1039 #define CACHE_CONTROL_MUST_REVALIDATE   0x09
1040 #define CACHE_CONTROL_PROXY_REVALIDATE  0x0A
1041 #define CACHE_CONTROL_S_MAXAGE                  0x0B
1042
1043 static const value_string vals_cache_control[] = {
1044         { CACHE_CONTROL_NO_CACHE,         "no-cache" },
1045         { CACHE_CONTROL_NO_STORE,         "no-store" },
1046         { CACHE_CONTROL_MAX_AGE,          "max-age" },
1047         { CACHE_CONTROL_MAX_STALE,        "max-stale" },
1048         { CACHE_CONTROL_MIN_FRESH,        "min-fresh" },
1049         { CACHE_CONTROL_ONLY_IF_CACHED,   "only-if-cached" },
1050         { CACHE_CONTROL_PUBLIC,           "public" },
1051         { CACHE_CONTROL_PRIVATE,          "private" },
1052         { CACHE_CONTROL_NO_TRANSFORM,     "no-transform" },
1053         { CACHE_CONTROL_MUST_REVALIDATE,  "must-revalidate" },
1054         { CACHE_CONTROL_PROXY_REVALIDATE, "proxy-revalidate" },
1055         { CACHE_CONTROL_S_MAXAGE,         "s-max-age" },
1056
1057         { 0x00, NULL }
1058 };
1059
1060 static const value_string vals_wap_application_ids[] = {
1061         /* Well-known WAP applications */
1062         { 0x00, "x-wap-application:*"},
1063         { 0x01, "x-wap-application:push.sia"},
1064         { 0x02, "x-wap-application:wml.ua"},
1065         { 0x03, "x-wap-application:wta.ua"},
1066         { 0x04, "x-wap-application:mms.ua"},
1067         { 0x05, "x-wap-application:push.syncml"},
1068         { 0x06, "x-wap-application:loc.ua"},
1069         { 0x07, "x-wap-application:syncml.dm"},
1070         { 0x08, "x-wap-application:drm.ua"},
1071         { 0x09, "x-wap-application:emn.ua"},
1072         { 0x0A, "x-wap-application:wv.ua"},
1073         /* Registered by 3rd parties */
1074         { 0x8000, "x-wap-microsoft:localcontent.ua"},
1075         { 0x8001, "x-wap-microsoft:IMclient.ua"},
1076         { 0x8002, "x-wap-docomo:imode.mail.ua"},
1077         { 0x8003, "x-wap-docomo:imode.mr.ua"},
1078         { 0x8004, "x-wap-docomo:imode.mf.ua"},
1079         { 0x8005, "x-motorola:location.ua"},
1080         { 0x8006, "x-motorola:now.ua"},
1081         { 0x8007, "x-motorola:otaprov.ua"},
1082         { 0x8008, "x-motorola:browser.ua"},
1083         { 0x8009, "x-motorola:splash.ua"},
1084         /* 0x800A: unassigned */
1085         { 0x800B, "x-wap-nai:mvsw.command"},
1086         /* 0x800C -- 0x800F: unassigned */
1087         { 0x8010, "x-wap-openwave:iota.ua"},
1088         /* 0x8011 -- 0x8FFF: unassigned */
1089         { 0x9000, "x-wap-docomo:imode.mail2.ua"},
1090         { 0x9001, "x-oma-nec:otaprov.ua"},
1091         { 0x9002, "x-oma-nokia:call.ua"},
1092         { 0x9003, "x-oma-coremobility:sqa.ua"},
1093
1094         { 0x00, NULL }
1095 };
1096
1097
1098 /* Parameters and well-known encodings */
1099 static const value_string vals_wsp_parameter_sec[] = {
1100         { 0x00, "NETWPIN" },
1101         { 0x01, "USERPIN" },
1102         { 0x02, "USERNETWPIN" },
1103         { 0x03, "USERPINMAC" },
1104
1105         { 0x00, NULL }
1106 };
1107
1108 /* Warning codes and mappings */
1109 static const value_string vals_wsp_warning_code[] = {
1110         { 10, "110 Response is stale" },
1111         { 11, "111 Revalidation failed" },
1112         { 12, "112 Disconnected operation" },
1113         { 13, "113 Heuristic expiration" },
1114         { 14, "214 Transformation applied" },
1115         { 99, "199/299 Miscellaneous warning" },
1116
1117         { 0, NULL }
1118 };
1119
1120 static const value_string vals_wsp_warning_code_short[] = {
1121         { 10, "110" },
1122         { 11, "111" },
1123         { 12, "112" },
1124         { 13, "113" },
1125         { 14, "214" },
1126         { 99, "199/299" },
1127
1128         { 0, NULL }
1129 };
1130
1131 /* Profile-Warning codes - see http://www.w3.org/TR/NOTE-CCPPexchange */
1132 static const value_string vals_wsp_profile_warning_code[] = {
1133         { 0x10, "100 OK" },
1134         { 0x11, "101 Used stale profile" },
1135         { 0x12, "102 Not used profile" },
1136         { 0x20, "200 Not applied" },
1137         { 0x21, "101 Content selection applied" },
1138         { 0x22, "202 Content generation applied" },
1139         { 0x23, "203 Transformation applied" },
1140
1141         { 0x00, NULL }
1142 };
1143
1144 /* Well-known TE values */
1145 static const value_string vals_well_known_te[] = {
1146         { 0x82, "chunked" },
1147         { 0x83, "identity" },
1148         { 0x84, "gzip" },
1149         { 0x85, "compress" },
1150         { 0x86, "deflate" },
1151
1152         { 0x00, NULL }
1153 };
1154
1155
1156 /*
1157  * Redirect flags.
1158  */
1159 #define PERMANENT_REDIRECT              0x80
1160 #define REUSE_SECURITY_SESSION  0x40
1161
1162 /*
1163  * Redirect address flags and length.
1164  */
1165 #define BEARER_TYPE_INCLUDED    0x80
1166 #define PORT_NUMBER_INCLUDED    0x40
1167 #define ADDRESS_LEN                             0x3f
1168
1169 static const true_false_string yes_no_truth = {
1170         "Yes" ,
1171         "No"
1172 };
1173
1174 static const value_string vals_false_true[] = {
1175         { 0, "False" },
1176         { 1, "True" },
1177         { 0, NULL },
1178 };
1179
1180 enum {
1181         WSP_PDU_RESERVED                = 0x00,
1182         WSP_PDU_CONNECT                 = 0x01,
1183         WSP_PDU_CONNECTREPLY            = 0x02,
1184         WSP_PDU_REDIRECT                = 0x03,                 /* No sample data */
1185         WSP_PDU_REPLY                   = 0x04,
1186         WSP_PDU_DISCONNECT              = 0x05,
1187         WSP_PDU_PUSH                    = 0x06,                 /* No sample data */
1188         WSP_PDU_CONFIRMEDPUSH           = 0x07,                 /* No sample data */
1189         WSP_PDU_SUSPEND                 = 0x08,                 /* No sample data */
1190         WSP_PDU_RESUME                  = 0x09,                 /* No sample data */
1191
1192         WSP_PDU_GET                     = 0x40,
1193         WSP_PDU_OPTIONS                 = 0x41,                 /* No sample data */
1194         WSP_PDU_HEAD                    = 0x42,                 /* No sample data */
1195         WSP_PDU_DELETE                  = 0x43,                 /* No sample data */
1196         WSP_PDU_TRACE                   = 0x44,                 /* No sample data */
1197
1198         WSP_PDU_POST                    = 0x60,
1199         WSP_PDU_PUT                     = 0x61                  /* No sample data */
1200 };
1201
1202
1203 /* Dissector tables for handoff */
1204 static dissector_table_t media_type_table;
1205 static heur_dissector_list_t heur_subdissector_list;
1206
1207 static void add_uri (proto_tree *, packet_info *, tvbuff_t *, guint, guint, proto_item *);
1208
1209 static void add_post_variable (proto_tree *, tvbuff_t *, guint, guint, guint, guint);
1210 static void add_multipart_data (proto_tree *, tvbuff_t *, packet_info *pinfo);
1211
1212 static void add_capabilities (proto_tree *tree, tvbuff_t *tvb, guint8 pdu_type);
1213
1214
1215 /*
1216  * Dissect the WSP header part.
1217  * This function calls wkh_XXX functions that dissect well-known headers.
1218  */
1219 static void add_headers (proto_tree *tree, tvbuff_t *tvb, int hf);
1220
1221 /* The following macros define WSP basic data structures as found
1222  * in the ABNF notation of WSP headers.
1223  * Currently all text data types are mapped to text_string.
1224  */
1225 #define is_short_integer(x)             ( (x) & 0x80 )
1226 #define is_long_integer(x)              ( (x) <= 30 )
1227 #define is_date_value(x)                is_long_integer(x)
1228 #define is_integer_value(x)             (is_short_integer(x) || is_long_integer(x))
1229 #define is_delta_seconds_value(x)       is_integer_value(x)
1230 /* Text string == *TEXT 0x00, thus also an empty string matches the rule! */
1231 #define is_text_string(x)       ( ((x) == 0) || ( ((x) >= 32) && ((x) <= 127)) ) 
1232 #define is_quoted_string(x)             ( (x) == 0x22 ) /* " */
1233 #define is_token_text(x)                is_text_string(x)
1234 #define is_text_value(x)                is_text_string(x)
1235 #define is_uri_value(x)                 is_text_string(x)
1236
1237 #define get_uintvar_integer(val,tvb,start,len,ok) \
1238         val = tvb_get_guintvar(tvb,start,&len); \
1239         if (len>5) ok = FALSE; else ok = TRUE;
1240 #define get_short_integer(val,tvb,start,len,ok) \
1241         val = tvb_get_guint8(tvb,start); \
1242         if (val & 0x80) ok = TRUE; else ok=FALSE; \
1243         val &= 0x7F; len = 1;
1244 #define get_long_integer(val,tvb,start,len,ok) \
1245         len = tvb_get_guint8(tvb,start); \
1246         ok = TRUE; /* Valid lengths for us are 1-4 */ \
1247         if (len==1) { val = tvb_get_guint8(tvb,start+1); } \
1248         else if (len==2) { val = tvb_get_ntohs(tvb,start+1); } \
1249         else if (len==3) { val = tvb_get_ntoh24(tvb,start+1); } \
1250         else if (len==4) { val = tvb_get_ntohl(tvb,start+1); } \
1251         else ok = FALSE; \
1252         len++; /* Add the 1st octet to the length */
1253 #define get_integer_value(val,tvb,start,len,ok) \
1254         len = tvb_get_guint8(tvb,start); \
1255         ok = TRUE; \
1256         if (len & 0x80) { val = len & 0x7F; len = 0; } \
1257         else if (len==1) { val = tvb_get_guint8(tvb,start+1); } \
1258         else if (len==2) { val = tvb_get_ntohs(tvb,start+1); } \
1259         else if (len==3) { val = tvb_get_ntoh24(tvb,start+1); } \
1260         else if (len==4) { val = tvb_get_ntohl(tvb,start+1); } \
1261         else ok = FALSE; \
1262         len++; /* Add the 1st octet to the length */
1263 #define get_date_value(val,tvb,start,len,ok) \
1264         get_long_integer(val,tvb,start,len,ok)
1265 #define get_delta_seconds_value(val,tvb,start,len,ok) \
1266         get_integer_value(val,tvb,start,len,ok)
1267
1268 /* NOTE - Don't forget to g_free() the str value after its usage as the
1269  * tvb_get_string[z]() functions return g_malloc()ed memory! */ 
1270 #define get_text_string(str,tvb,start,len,ok) \
1271         if (is_text_string(tvb_get_guint8(tvb,start))) { \
1272                 str = (gchar *)tvb_get_stringz(tvb,start,(gint *)&len); \
1273                 g_assert (str); \
1274                 ok = TRUE; \
1275         } else { len = 0; str = NULL; ok = FALSE; }
1276 #define get_token_text(str,tvb,start,len,ok) \
1277         get_text_string(str,tvb,start,len,ok)
1278 #define get_extension_media(str,tvb,start,len,ok) \
1279         get_text_string(str,tvb,start,len,ok)
1280 #define get_text_value(str,tvb,start,len,ok) \
1281         get_text_string(str,tvb,start,len,ok)
1282 #define get_quoted_string(str,tvb,start,len,ok) \
1283         get_text_string(str,tvb,start,len,ok)
1284 #define get_uri_value(str,tvb,start,len,ok) \
1285         get_text_string(str,tvb,start,len,ok)
1286
1287 #define get_version_value(val,str,tvb,start,len,ok) \
1288         val = tvb_get_guint8(tvb,start); \
1289         ok = TRUE; \
1290         if (val & 0x80) { /* High nibble "." Low nibble */ \
1291                 len = 1; \
1292                 val &= 0x7F; \
1293                 str = g_strdup_printf("%u.%u", val >> 4, val & 0x0F); \
1294         } else { get_text_string(str,tvb,start,len,ok); }
1295         
1296 /* Parameter parser */
1297 static int
1298 parameter (proto_tree *tree, proto_item *ti, tvbuff_t *tvb, int start, int len);
1299 static int
1300 parameter_value_q (proto_tree *tree, proto_item *ti, tvbuff_t *tvb, int start);
1301
1302 #define InvalidValueForHeader(hdr) \
1303         "<Error: Invalid value for the '" hdr "' header>"
1304 #define InvalidTextualHeader \
1305         "<Error: Invalid zero-length textual header>"
1306 #define TrailingQuoteWarning \
1307         " <Warning: Quoted-string value has been encoded with a trailing quote>"
1308
1309 /* WSP well-known header parsing function prototypes;
1310  * will be listed in the function lookup table WellKnownHeaders[] */
1311 static guint32 wkh_default (proto_tree *tree, tvbuff_t *tvb,
1312                 guint32 hdr_start);
1313 static guint32 wkh_accept (proto_tree *tree, tvbuff_t *tvb,
1314                 guint32 hdr_start);
1315 static guint32 wkh_content_type (proto_tree *tree, tvbuff_t *tvb,
1316                 guint32 hdr_start);
1317 static guint32 wkh_accept_charset (proto_tree *tree, tvbuff_t *tvb,
1318                 guint32 hdr_start);
1319 static guint32 wkh_accept_language (proto_tree *tree, tvbuff_t *tvb,
1320                 guint32 hdr_start);
1321 static guint32 wkh_connection (proto_tree *tree, tvbuff_t *tvb,
1322                 guint32 hdr_start);
1323 static guint32 wkh_push_flag (proto_tree *tree, tvbuff_t *tvb,
1324                 guint32 header_start);
1325 static guint32 wkh_vary (proto_tree *tree, tvbuff_t *tvb,
1326                 guint32 hdr_start);
1327 static guint32 wkh_accept_ranges (proto_tree *tree, tvbuff_t *tvb,
1328                 guint32 hdr_start);
1329 static guint32 wkh_content_disposition (proto_tree *tree, tvbuff_t *tvb,
1330                 guint32 hdr_start);
1331 static guint32 wkh_accept_encoding (proto_tree *tree, tvbuff_t *tvb,
1332                 guint32 hdr_start);
1333 static guint32 wkh_content_encoding (proto_tree *tree, tvbuff_t *tvb,
1334                 guint32 hdr_start);
1335 static guint32 wkh_transfer_encoding (proto_tree *tree, tvbuff_t *tvb,
1336                 guint32 hdr_start);
1337 static guint32 wkh_pragma (proto_tree *tree, tvbuff_t *tvb,
1338                 guint32 hdr_start);
1339 /* Single short-integer value */
1340 static guint32 wkh_x_wap_security (proto_tree *tree, tvbuff_t *tvb,
1341                 guint32 hdr_start);
1342 /* Text */
1343 static guint32 wkh_content_base (proto_tree *tree, tvbuff_t *tvb,
1344                 guint32 hdr_start);
1345 static guint32 wkh_content_location (proto_tree *tree, tvbuff_t *tvb,
1346                 guint32 hdr_start);
1347 static guint32 wkh_etag (proto_tree *tree, tvbuff_t *tvb,
1348                 guint32 hdr_start);
1349 static guint32 wkh_from (proto_tree *tree, tvbuff_t *tvb,
1350                 guint32 hdr_start);
1351 static guint32 wkh_host (proto_tree *tree, tvbuff_t *tvb,
1352                 guint32 hdr_start);
1353 static guint32 wkh_if_match (proto_tree *tree, tvbuff_t *tvb,
1354                 guint32 hdr_start);
1355 static guint32 wkh_if_none_match (proto_tree *tree, tvbuff_t *tvb,
1356                 guint32 hdr_start);
1357 static guint32 wkh_location (proto_tree *tree, tvbuff_t *tvb,
1358                 guint32 hdr_start);
1359 static guint32 wkh_referer (proto_tree *tree, tvbuff_t *tvb,
1360                 guint32 hdr_start);
1361 static guint32 wkh_server (proto_tree *tree, tvbuff_t *tvb,
1362                 guint32 hdr_start);
1363 static guint32 wkh_user_agent (proto_tree *tree, tvbuff_t *tvb,
1364                 guint32 hdr_start);
1365 static guint32 wkh_upgrade (proto_tree *tree, tvbuff_t *tvb,
1366                 guint32 hdr_start);
1367 static guint32 wkh_via (proto_tree *tree, tvbuff_t *tvb,
1368                 guint32 hdr_start);
1369 static guint32 wkh_content_uri (proto_tree *tree, tvbuff_t *tvb,
1370                 guint32 hdr_start);
1371 static guint32 wkh_initiator_uri (proto_tree *tree, tvbuff_t *tvb,
1372                 guint32 hdr_start);
1373 static guint32 wkh_profile (proto_tree *tree, tvbuff_t *tvb,
1374                 guint32 hdr_start);
1375 static guint32 wkh_content_id (proto_tree *tree, tvbuff_t *tvb,
1376                 guint32 hdr_start);
1377 /* Date-value or text */
1378 static guint32 wkh_if_range (proto_tree *tree, tvbuff_t *tvb,
1379                 guint32 hdr_start);
1380 /* Date-value */
1381 static guint32 wkh_date (proto_tree *tree, tvbuff_t *tvb,
1382                 guint32 hdr_start);
1383 static guint32 wkh_expires (proto_tree *tree, tvbuff_t *tvb,
1384                 guint32 hdr_start);
1385 static guint32 wkh_if_modified_since (proto_tree *tree, tvbuff_t *tvb,
1386                 guint32 hdr_start);
1387 static guint32 wkh_if_unmodified_since (proto_tree *tree, tvbuff_t *tvb,
1388                 guint32 hdr_start);
1389 static guint32 wkh_last_modified (proto_tree *tree, tvbuff_t *tvb,
1390                 guint32 hdr_start);
1391 /* Date-value with special meaning */
1392 static guint32 wkh_x_wap_tod (proto_tree *tree, tvbuff_t *tvb,
1393                 guint32 hdr_start);
1394 /* Delta-seconds-value */
1395 static guint32 wkh_age (proto_tree *tree, tvbuff_t *tvb,
1396                 guint32 hdr_start);
1397 /* Challenge */
1398 static guint32 wkh_proxy_authenticate (proto_tree *tree, tvbuff_t *tvb,
1399                 guint32 hdr_start);
1400 static guint32 wkh_www_authenticate (proto_tree *tree, tvbuff_t *tvb,
1401                 guint32 hdr_start);
1402 /* Credentials */
1403 static guint32 wkh_authorization (proto_tree *tree, tvbuff_t *tvb,
1404                 guint32 hdr_start);
1405 static guint32 wkh_proxy_authorization (proto_tree *tree, tvbuff_t *tvb,
1406                 guint32 hdr_start);
1407 /* Pragma */
1408 static guint32 wkh_pragma (proto_tree *tree, tvbuff_t *tvb,
1409                 guint32 hdr_start);
1410 /* Integer-value */
1411 static guint32 wkh_content_length (proto_tree *tree, tvbuff_t *tvb,
1412                 guint32 hdr_start);
1413 static guint32 wkh_max_forwards (proto_tree *tree, tvbuff_t *tvb,
1414                 guint32 hdr_start);
1415
1416 /* Integer lookup value */
1417 static guint32 wkh_bearer_indication (proto_tree *tree, tvbuff_t *tvb,
1418                 guint32 hdr_start);
1419
1420 /* WAP application ID value */
1421 static guint32 wkh_x_wap_application_id (proto_tree *tree, tvbuff_t *tvb,
1422                 guint32 hdr_start);
1423 static guint32 wkh_accept_application (proto_tree *tree, tvbuff_t *tvb,
1424                 guint32 hdr_start);
1425 static guint32 wkh_content_language (proto_tree *tree, tvbuff_t *tvb,
1426                 guint32 hdr_start);
1427
1428 /* Allow and Public */
1429 static guint32 wkh_allow(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start);
1430 static guint32 wkh_public(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start);
1431
1432 /* Cache-control */
1433 static guint32 wkh_cache_control (proto_tree *tree, tvbuff_t *tvb,
1434                 guint32 hdr_start);
1435 /* Warning */
1436 static guint32 wkh_warning (proto_tree *tree, tvbuff_t *tvb,
1437                 guint32 hdr_start);
1438 /* Profile-warning */
1439 static guint32 wkh_profile_warning (proto_tree *tree, tvbuff_t *tvb,
1440                 guint32 hdr_start);
1441
1442 /* Content-MD5 */
1443 static guint32 wkh_content_md5 (proto_tree *tree, tvbuff_t *tvb,
1444                 guint32 hdr_start);
1445
1446 /* WSP encoding version */
1447 static guint32 wkh_encoding_version (proto_tree *tree, tvbuff_t *tvb,
1448                 guint32 hdr_start);
1449
1450 /* Content-Range and Range */
1451 static guint32 wkh_content_range (proto_tree *tree, tvbuff_t *tvb,
1452                 guint32 hdr_start);
1453 static guint32 wkh_range (proto_tree *tree, tvbuff_t *tvb,
1454                 guint32 hdr_start);
1455
1456 /* TE */
1457 static guint32 wkh_te (proto_tree *tree, tvbuff_t *tvb,
1458                 guint32 hdr_start);
1459
1460 /* Header value */
1461 static guint32 wkh_trailer (proto_tree *tree, tvbuff_t *tvb,
1462                 guint32 hdr_start);
1463
1464 /* TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO
1465 static guint32 wkh_retry_after (proto_tree *tree, tvbuff_t *tvb,
1466                 guint32 hdr_start);
1467 static guint32 wkh_profile_diff (proto_tree *tree, tvbuff_t *tvb,
1468                 guint32 hdr_start);
1469 static guint32 wkh_expect (proto_tree *tree, tvbuff_t *tvb,
1470                 guint32 hdr_start);
1471 static guint32 wkh_set_cookie (proto_tree *tree, tvbuff_t *tvb,
1472                 guint32 hdr_start);
1473 static guint32 wkh_cookie (proto_tree *tree, tvbuff_t *tvb,
1474                 guint32 hdr_start);
1475 */
1476
1477
1478 /* WSP well-known Openwave header parsing function prototypes;
1479  * will be listed in the function lookup table WellKnownOpenwaveHeaders[] */
1480 static guint32 wkh_openwave_default (proto_tree *tree, tvbuff_t *tvb,
1481                 guint32 hdr_start);
1482 /* Textual headers */
1483 static guint32 wkh_openwave_x_up_proxy_operator_domain(proto_tree *tree,
1484                 tvbuff_t *tvb, guint32 hdr_start);
1485 static guint32 wkh_openwave_x_up_proxy_home_page(proto_tree *tree,
1486                 tvbuff_t *tvb, guint32 hdr_start);
1487 static guint32 wkh_openwave_x_up_proxy_uplink_version(proto_tree *tree,
1488                 tvbuff_t *tvb, guint32 hdr_start);
1489 static guint32 wkh_openwave_x_up_proxy_ba_realm(proto_tree *tree,
1490                 tvbuff_t *tvb, guint32 hdr_start);
1491 static guint32 wkh_openwave_x_up_proxy_request_uri(proto_tree *tree,
1492                 tvbuff_t *tvb, guint32 hdr_start);
1493 static guint32 wkh_openwave_x_up_proxy_bookmark(proto_tree *tree,
1494                 tvbuff_t *tvb, guint32 hdr_start);
1495 /* Integer headers */
1496 static guint32 wkh_openwave_x_up_proxy_push_seq(proto_tree *tree,
1497                 tvbuff_t *tvb, guint32 hdr_start);
1498 static guint32 wkh_openwave_x_up_proxy_notify(proto_tree *tree,
1499                 tvbuff_t *tvb, guint32 hdr_start);
1500 static guint32 wkh_openwave_x_up_proxy_net_ask(proto_tree *tree,
1501                 tvbuff_t *tvb, guint32 hdr_start);
1502 static guint32 wkh_openwave_x_up_proxy_tod (proto_tree *tree,
1503                 tvbuff_t *tvb, guint32 hdr_start);
1504 static guint32 wkh_openwave_x_up_proxy_ba_enable(proto_tree *tree,
1505                 tvbuff_t *tvb, guint32 hdr_start);
1506 static guint32 wkh_openwave_x_up_proxy_redirect_enable(proto_tree *tree,
1507                 tvbuff_t *tvb, guint32 hdr_start);
1508 static guint32 wkh_openwave_x_up_proxy_redirect_status(proto_tree *tree,
1509                 tvbuff_t *tvb, guint32 hdr_start);
1510 static guint32 wkh_openwave_x_up_proxy_linger(proto_tree *tree,
1511                 tvbuff_t *tvb, guint32 hdr_start);
1512 static guint32 wkh_openwave_x_up_proxy_enable_trust(proto_tree *tree,
1513                 tvbuff_t *tvb, guint32 hdr_start);
1514 static guint32 wkh_openwave_x_up_proxy_trust(proto_tree *tree,
1515                 tvbuff_t *tvb, guint32 hdr_start);
1516 static guint32 wkh_openwave_x_up_devcap_has_color(proto_tree *tree,
1517                 tvbuff_t *tvb, guint32 hdr_start);
1518 static guint32 wkh_openwave_x_up_devcap_num_softkeys(proto_tree *tree,
1519                 tvbuff_t *tvb, guint32 hdr_start);
1520 static guint32 wkh_openwave_x_up_devcap_softkey_size(proto_tree *tree,
1521                 tvbuff_t *tvb, guint32 hdr_start);
1522 static guint32 wkh_openwave_x_up_devcap_screen_chars(proto_tree *tree,
1523                 tvbuff_t *tvb, guint32 hdr_start);
1524 static guint32 wkh_openwave_x_up_devcap_screen_pixels(proto_tree *tree,
1525                 tvbuff_t *tvb, guint32 hdr_start);
1526 static guint32 wkh_openwave_x_up_devcap_em_size(proto_tree *tree,
1527                 tvbuff_t *tvb, guint32 hdr_start);
1528 static guint32 wkh_openwave_x_up_devcap_screen_depth(proto_tree *tree,
1529                 tvbuff_t *tvb, guint32 hdr_start);
1530 static guint32 wkh_openwave_x_up_devcap_immed_alert(proto_tree *tree,
1531                 tvbuff_t *tvb, guint32 hdr_start);
1532 static guint32 wkh_openwave_x_up_devcap_gui(proto_tree *tree,
1533                 tvbuff_t *tvb, guint32 hdr_start);
1534
1535 static guint32 wkh_openwave_x_up_proxy_trans_charset(proto_tree *tree,
1536                 tvbuff_t *tvb, guint32 hdr_start);
1537 static guint32 wkh_openwave_x_up_proxy_push_accept(proto_tree *tree,
1538                 tvbuff_t *tvb, guint32 hdr_start);
1539
1540
1541 /* Define a pointer to function data type for the well-known header
1542  * lookup table below */
1543 typedef guint32 (*hdr_parse_func_ptr) (proto_tree *, tvbuff_t *, guint32);
1544
1545 /* Lookup table for well-known header parsing functions */
1546 static const hdr_parse_func_ptr WellKnownHeader[128] = {
1547         /* 0x00 */      wkh_accept,                             /* 0x01 */      wkh_accept_charset,
1548         /* 0x02 */      wkh_accept_encoding,    /* 0x03 */      wkh_accept_language,
1549         /* 0x04 */      wkh_accept_ranges,              /* 0x05 */      wkh_age,
1550         /* 0x06 */      wkh_allow,                              /* 0x07 */      wkh_authorization,
1551         /* 0x08 */      wkh_cache_control,              /* 0x09 */      wkh_connection,
1552         /* 0x0A */      wkh_content_base,               /* 0x0B */      wkh_content_encoding,
1553         /* 0x0C */      wkh_content_language,   /* 0x0D */      wkh_content_length,
1554         /* 0x0E */      wkh_content_location,   /* 0x0F */      wkh_content_md5,
1555         /* 0x10 */      wkh_content_range,              /* 0x11 */      wkh_content_type,
1556         /* 0x12 */      wkh_date,                               /* 0x13 */      wkh_etag,
1557         /* 0x14 */      wkh_expires,                    /* 0x15 */      wkh_from,
1558         /* 0x16 */      wkh_host,                               /* 0x17 */      wkh_if_modified_since,
1559         /* 0x18 */      wkh_if_match,                   /* 0x19 */      wkh_if_none_match,
1560         /* 0x1A */      wkh_if_range,                   /* 0x1B */      wkh_if_unmodified_since,
1561         /* 0x1C */      wkh_location,                   /* 0x1D */      wkh_last_modified,
1562         /* 0x1E */      wkh_max_forwards,               /* 0x1F */      wkh_pragma,
1563         /* 0x20 */      wkh_proxy_authenticate, /* 0x21 */      wkh_proxy_authorization,
1564         /* 0x22 */      wkh_public,                             /* 0x23 */      wkh_range,
1565         /* 0x24 */      wkh_referer,                    /* 0x25 */      wkh_default,
1566         /* 0x26 */      wkh_server,                             /* 0x27 */      wkh_transfer_encoding,
1567         /* 0x28 */      wkh_upgrade,                    /* 0x29 */      wkh_user_agent,
1568         /* 0x2A */      wkh_vary,                               /* 0x2B */      wkh_via,
1569         /* 0x2C */      wkh_warning,                    /* 0x2D */      wkh_www_authenticate,
1570         /* 0x2E */      wkh_content_disposition,/* 0x2F */      wkh_x_wap_application_id,
1571         /* 0x30 */      wkh_content_uri,                /* 0x31 */      wkh_initiator_uri,
1572         /* 0x32 */      wkh_accept_application, /* 0x33 */      wkh_bearer_indication,
1573         /* 0x34 */      wkh_push_flag,                  /* 0x35 */      wkh_profile,
1574         /* 0x36 */      wkh_default,                    /* 0x37 */      wkh_profile_warning,
1575         /* 0x38 */      wkh_default,                    /* 0x39 */      wkh_te,
1576         /* 0x3A */      wkh_trailer,                    /* 0x3B */      wkh_accept_charset,
1577         /* 0x3C */      wkh_accept_encoding,    /* 0x3D */      wkh_cache_control,
1578         /* 0x3E */      wkh_content_range,              /* 0x3F */      wkh_x_wap_tod,
1579         /* 0x40 */      wkh_content_id,                 /* 0x41 */      wkh_default,
1580         /* 0x42 */      wkh_default,                    /* 0x43 */      wkh_encoding_version,
1581         /* 0x44 */      wkh_profile_warning,    /* 0x45 */      wkh_content_disposition,
1582         /* 0x46 */      wkh_x_wap_security,             /* 0x47 */      wkh_cache_control,
1583         /*******************************************************
1584          *** The following headers are not (yet) registered. ***
1585          *******************************************************/
1586         /* 0x48 */      wkh_default,                    /* 0x49 */      wkh_default,
1587         /* 0x4A */      wkh_default,                    /* 0x4B */      wkh_default,
1588         /* 0x4C */      wkh_default,                    /* 0x4D */      wkh_default,
1589         /* 0x4E */      wkh_default,                    /* 0x4F */      wkh_default,
1590         /* 0x50 */      wkh_default,                    /* 0x51 */      wkh_default,
1591         /* 0x52 */      wkh_default,                    /* 0x53 */      wkh_default,
1592         /* 0x54 */      wkh_default,                    /* 0x55 */      wkh_default,
1593         /* 0x56 */      wkh_default,                    /* 0x57 */      wkh_default,
1594         /* 0x58 */      wkh_default,                    /* 0x59 */      wkh_default,
1595         /* 0x5A */      wkh_default,                    /* 0x5B */      wkh_default,
1596         /* 0x5C */      wkh_default,                    /* 0x5D */      wkh_default,
1597         /* 0x5E */      wkh_default,                    /* 0x5F */      wkh_default,
1598         /* 0x60 */      wkh_default,                    /* 0x61 */      wkh_default,
1599         /* 0x62 */      wkh_default,                    /* 0x63 */      wkh_default,
1600         /* 0x64 */      wkh_default,                    /* 0x65 */      wkh_default,
1601         /* 0x66 */      wkh_default,                    /* 0x67 */      wkh_default,
1602         /* 0x68 */      wkh_default,                    /* 0x69 */      wkh_default,
1603         /* 0x6A */      wkh_default,                    /* 0x6B */      wkh_default,
1604         /* 0x6C */      wkh_default,                    /* 0x6D */      wkh_default,
1605         /* 0x6E */      wkh_default,                    /* 0x6F */      wkh_default,
1606         /* 0x70 */      wkh_default,                    /* 0x71 */      wkh_default,
1607         /* 0x72 */      wkh_default,                    /* 0x73 */      wkh_default,
1608         /* 0x74 */      wkh_default,                    /* 0x75 */      wkh_default,
1609         /* 0x76 */      wkh_default,                    /* 0x77 */      wkh_default,
1610         /* 0x78 */      wkh_default,                    /* 0x79 */      wkh_default,
1611         /* 0x7A */      wkh_default,                    /* 0x7B */      wkh_default,
1612         /* 0x7C */      wkh_default,                    /* 0x7D */      wkh_default,
1613         /* 0x7E */      wkh_default,                    /* 0x7F */      wkh_default,
1614 }; 
1615
1616 /* Lookup table for well-known header parsing functions */
1617 static const hdr_parse_func_ptr WellKnownOpenwaveHeader[128] = {
1618         /* 0x00 */      wkh_openwave_default,
1619         /* 0x01 */      wkh_openwave_x_up_proxy_push_accept,
1620         /* 0x02 */      wkh_openwave_x_up_proxy_push_seq,
1621         /* 0x03 */      wkh_openwave_x_up_proxy_notify,
1622         /* 0x04 */      wkh_openwave_x_up_proxy_operator_domain,
1623         /* 0x05 */      wkh_openwave_x_up_proxy_home_page,
1624         /* 0x06 */      wkh_openwave_x_up_devcap_has_color,
1625         /* 0x07 */      wkh_openwave_x_up_devcap_num_softkeys,
1626         /* 0x08 */      wkh_openwave_x_up_devcap_softkey_size,
1627         /* 0x09 */      wkh_openwave_x_up_devcap_screen_chars,
1628         /* 0x0A */      wkh_openwave_x_up_devcap_screen_pixels,
1629         /* 0x0B */      wkh_openwave_x_up_devcap_em_size,
1630         /* 0x0C */      wkh_openwave_x_up_devcap_screen_depth,
1631         /* 0x0D */      wkh_openwave_x_up_devcap_immed_alert,
1632         /* 0x0E */      wkh_openwave_x_up_proxy_net_ask,
1633         /* 0x0F */      wkh_openwave_x_up_proxy_uplink_version,
1634         /* 0x10 */      wkh_openwave_x_up_proxy_tod,
1635         /* 0x11 */      wkh_openwave_x_up_proxy_ba_enable,
1636         /* 0x12 */      wkh_openwave_x_up_proxy_ba_realm,
1637         /* 0x13 */      wkh_openwave_x_up_proxy_redirect_enable,
1638         /* 0x14 */      wkh_openwave_x_up_proxy_request_uri,
1639         /* 0x15 */      wkh_openwave_x_up_proxy_redirect_status,
1640         /* 0x16 */      wkh_openwave_x_up_proxy_trans_charset,
1641         /* 0x17 */      wkh_openwave_x_up_proxy_linger,
1642         /* 0x18 */      wkh_openwave_default,
1643         /* 0x19 */      wkh_openwave_x_up_proxy_enable_trust,
1644         /* 0x1A */      wkh_openwave_x_up_proxy_trust,
1645         /* 0x1B */      wkh_openwave_default,
1646         /* 0x1C */      wkh_openwave_default,
1647         /* 0x1D */      wkh_openwave_default,
1648         /* 0x1E */      wkh_openwave_default,
1649         /* 0x1F */      wkh_openwave_default,
1650         /* 0x20 */      wkh_openwave_x_up_proxy_trust,
1651         /* 0x21 */      wkh_openwave_x_up_proxy_bookmark,
1652         /* 0x22 */      wkh_openwave_x_up_devcap_gui,
1653         /*******************************************************
1654          *** The following headers are not (yet) registered. ***
1655          *******************************************************/
1656         /* 0x23 */      wkh_openwave_default,
1657         /* 0x24 */      wkh_openwave_default,           /* 0x25 */      wkh_openwave_default,
1658         /* 0x26 */      wkh_openwave_default,           /* 0x27 */      wkh_openwave_default,
1659         /* 0x28 */      wkh_openwave_default,           /* 0x29 */      wkh_openwave_default,
1660         /* 0x2A */      wkh_openwave_default,           /* 0x2B */      wkh_openwave_default,
1661         /* 0x2C */      wkh_openwave_default,           /* 0x2D */      wkh_openwave_default,
1662         /* 0x2E */      wkh_openwave_default,           /* 0x2F */      wkh_openwave_default,
1663         /* 0x30 */      wkh_openwave_default,           /* 0x31 */      wkh_openwave_default,
1664         /* 0x32 */      wkh_openwave_default,           /* 0x33 */      wkh_openwave_default,
1665         /* 0x34 */      wkh_openwave_default,           /* 0x35 */      wkh_openwave_default,
1666         /* 0x36 */      wkh_openwave_default,           /* 0x37 */      wkh_openwave_default,
1667         /* 0x38 */      wkh_openwave_default,           /* 0x39 */      wkh_openwave_default,
1668         /* 0x3A */      wkh_openwave_default,           /* 0x3B */      wkh_openwave_default,
1669         /* 0x3C */      wkh_openwave_default,           /* 0x3D */      wkh_openwave_default,
1670         /* 0x3E */      wkh_openwave_default,           /* 0x3F */      wkh_openwave_default,
1671         /* 0x40 */      wkh_openwave_default,           /* 0x41 */      wkh_openwave_default,
1672         /* 0x42 */      wkh_openwave_default,           /* 0x43 */      wkh_openwave_default,
1673         /* 0x44 */      wkh_openwave_default,           /* 0x45 */      wkh_openwave_default,
1674         /* 0x46 */      wkh_openwave_default,           /* 0x47 */      wkh_openwave_default,
1675         /* 0x48 */      wkh_openwave_default,           /* 0x49 */      wkh_openwave_default,
1676         /* 0x4A */      wkh_openwave_default,           /* 0x4B */      wkh_openwave_default,
1677         /* 0x4C */      wkh_openwave_default,           /* 0x4D */      wkh_openwave_default,
1678         /* 0x4E */      wkh_openwave_default,           /* 0x4F */      wkh_openwave_default,
1679         /* 0x50 */      wkh_openwave_default,           /* 0x51 */      wkh_openwave_default,
1680         /* 0x52 */      wkh_openwave_default,           /* 0x53 */      wkh_openwave_default,
1681         /* 0x54 */      wkh_openwave_default,           /* 0x55 */      wkh_openwave_default,
1682         /* 0x56 */      wkh_openwave_default,           /* 0x57 */      wkh_openwave_default,
1683         /* 0x58 */      wkh_openwave_default,           /* 0x59 */      wkh_openwave_default,
1684         /* 0x5A */      wkh_openwave_default,           /* 0x5B */      wkh_openwave_default,
1685         /* 0x5C */      wkh_openwave_default,           /* 0x5D */      wkh_openwave_default,
1686         /* 0x5E */      wkh_openwave_default,           /* 0x5F */      wkh_openwave_default,
1687         /* 0x60 */      wkh_openwave_default,           /* 0x61 */      wkh_openwave_default,
1688         /* 0x62 */      wkh_openwave_default,           /* 0x63 */      wkh_openwave_default,
1689         /* 0x64 */      wkh_openwave_default,           /* 0x65 */      wkh_openwave_default,
1690         /* 0x66 */      wkh_openwave_default,           /* 0x67 */      wkh_openwave_default,
1691         /* 0x68 */      wkh_openwave_default,           /* 0x69 */      wkh_openwave_default,
1692         /* 0x6A */      wkh_openwave_default,           /* 0x6B */      wkh_openwave_default,
1693         /* 0x6C */      wkh_openwave_default,           /* 0x6D */      wkh_openwave_default,
1694         /* 0x6E */      wkh_openwave_default,           /* 0x6F */      wkh_openwave_default,
1695         /* 0x70 */      wkh_openwave_default,           /* 0x71 */      wkh_openwave_default,
1696         /* 0x72 */      wkh_openwave_default,           /* 0x73 */      wkh_openwave_default,
1697         /* 0x74 */      wkh_openwave_default,           /* 0x75 */      wkh_openwave_default,
1698         /* 0x76 */      wkh_openwave_default,           /* 0x77 */      wkh_openwave_default,
1699         /* 0x78 */      wkh_openwave_default,           /* 0x79 */      wkh_openwave_default,
1700         /* 0x7A */      wkh_openwave_default,           /* 0x7B */      wkh_openwave_default,
1701         /* 0x7C */      wkh_openwave_default,           /* 0x7D */      wkh_openwave_default,
1702         /* 0x7E */      wkh_openwave_default,           /* 0x7F */      wkh_openwave_default,
1703 }; 
1704
1705
1706
1707
1708
1709
1710 /* WSP header format
1711  *   1st byte: 0x00        : <Not allowed>
1712  *   1st byte: 0x01 -- 0x1F: <Shorthand Header Code Page switch>
1713  *   1st byte: 0x20 -- 0x7E: <Textual header (C string)>
1714  *       Followed with: <Textual header value (C string)>
1715  *   1st byte: 0x7F        : <Header Code Page switch>
1716  *       Followed with: 2nd byte: <Header Code Page>
1717  *   1st byte: 0x80 -- 0xFF: <Binary header (7-bit encoded ID)>
1718  *       Followed with:
1719  *         2nd byte: 0x00 -- 0x1E: <Value Length (bytes)>
1720  *             Followed with: <Len> bytes of data
1721  *         2nd byte: 0x1F        : <Value Length is a guintvar>
1722  *             Followed with: <guintvar Len>
1723  *             Followed with: <Len> bytes of data
1724  *         2nd byte: 0x20 -- 0x7F: <Textual header value (C string)>
1725  *         2nd byte: 0x80 -- 0xFF: <Binary value (7-bit encoded ID)>
1726  */
1727 static void
1728 add_headers (proto_tree *tree, tvbuff_t *tvb, int hf)
1729 {
1730         guint8 hdr_id, val_id, codepage = 1;
1731         gint32 tvb_len = tvb_length(tvb);
1732         gint32 offset = 0, hdr_len, hdr_start;
1733         gint32 val_len, val_start;
1734         gchar *hdr_str, *val_str;
1735         proto_tree *wsp_headers;
1736         proto_item *ti;
1737         guint8 ok;
1738         guint32 val = 0;
1739         nstime_t tv;
1740
1741         if (! tree)
1742                 return;
1743         if (offset >= tvb_len)
1744                 return; /* No headers! */
1745
1746         ti = proto_tree_add_item(tree, hf,
1747                         tvb, offset, tvb_len, bo_little_endian);
1748         wsp_headers = proto_item_add_subtree(ti, ett_headers);
1749
1750         while (offset < tvb_len) {
1751                 hdr_start = offset;
1752                 hdr_id = tvb_get_guint8(tvb, offset);
1753                 if (hdr_id & 0x80) { /* Well-known header */
1754                         hdr_len = 1;
1755                         val_start = ++offset;
1756                         val_id = tvb_get_guint8(tvb, val_start);
1757                         /* Call header value dissector for given header */
1758                         if (codepage == 1) { /* Default header code page */
1759                                 DebugLog(("add_headers(code page 0): %s\n",
1760                                                         match_strval (hdr_id & 0x7f, vals_field_names)));
1761                                 offset = WellKnownHeader[hdr_id & 0x7F](wsp_headers, tvb,
1762                                                 hdr_start);
1763                         } else { /* Openwave header code page */
1764                                 /* Here I'm delibarately assuming that Openwave is the only
1765                                  * company that defines a WSP header code page. */
1766                                 DebugLog(("add_headers(code page 0x%02x - assumed to be x-up-1): %s\n",
1767                                                         codepage, match_strval (hdr_id & 0x7f, vals_openwave_field_names)));
1768                                 offset = WellKnownOpenwaveHeader[hdr_id & 0x7F](wsp_headers,
1769                                                 tvb, hdr_start);
1770                         }
1771                 } else if (hdr_id == 0x7F) { /* HCP shift sequence */
1772                         codepage = tvb_get_guint8(tvb, offset+1);
1773                         proto_tree_add_uint(wsp_headers, hf_wsp_header_shift_code,
1774                                         tvb, offset, 2, codepage);
1775                         offset += 2;
1776                 } else if (hdr_id >= 0x20) { /* Textual header */
1777                         /* Header name MUST be NUL-ended string ==> tvb_get_stringz() */
1778                         hdr_str = (gchar *)tvb_get_stringz(tvb, hdr_start, (gint *)&hdr_len);
1779                         val_start = hdr_start + hdr_len;
1780                         val_id = tvb_get_guint8(tvb, val_start);
1781                         /* Call header value dissector for given header */
1782                         if (val_id >= 0x20 && val_id <=0x7E) { /* OK! */
1783                                 val_str = (gchar *)tvb_get_stringz(tvb, val_start, (gint *)&val_len);
1784                                 g_assert(val_str);
1785                                 offset = val_start + val_len;
1786                                 proto_tree_add_text(wsp_headers,tvb,hdr_start,offset-hdr_start,
1787                                                 "%s: %s", hdr_str, val_str);
1788                                 g_free (val_str);
1789                         } else {
1790                                 /* Old-style X-WAP-TOD uses a non-textual value
1791                                  * after a textual header. */
1792                                 if (strcasecmp(hdr_str, "x-wap.tod") == 0) {
1793                                         get_delta_seconds_value(val, tvb, val_start, val_len, ok);
1794                                         if (ok) {
1795                                                 if (val == 0) {
1796                                                         ti = proto_tree_add_string (wsp_headers,
1797                                                                         hf_hdr_x_wap_tod,
1798                                                                         tvb, hdr_start, hdr_len + val_len,
1799                                                                         "Requesting Time Of Day");
1800                                                 } else {
1801                                                         tv.secs = val;
1802                                                         tv.nsecs = 0;
1803                                                         val_str = abs_time_to_str(&tv);
1804                                                         g_assert (val_str);
1805                                                         ti = proto_tree_add_string (wsp_headers,
1806                                                                         hf_hdr_x_wap_tod,
1807                                                                         tvb, hdr_start, hdr_len + val_len, val_str);
1808                                                 }
1809                                                 proto_item_append_text(ti, " <Warning: "
1810                                                                 "should be encoded as a textual value>");
1811                                         } else {
1812                                                 /* I prefer using X-Wap-Tod to the real hdr_str */
1813                                                 proto_tree_add_string (wsp_headers, hf_hdr_x_wap_tod,
1814                                                                 tvb, hdr_start, hdr_len + val_len,
1815                                                                 InvalidValueForHeader("X-Wap-Tod"));
1816                                         }
1817                                 } else {
1818                                         proto_tree_add_text (wsp_headers, tvb, hdr_start, hdr_len,
1819                                                         "<Error: Invalid value for the textual '%s' header"
1820                                                         " (should be a textual value)>",
1821                                                         hdr_str);
1822                                 }
1823                                 offset = tvb_len;
1824                         }
1825                         proto_tree_add_string_hidden(wsp_headers, hf_hdr_name,
1826                                         tvb, hdr_start, offset - hdr_start, hdr_str);
1827                 } else if (hdr_id > 0) { /* Shorthand HCP switch */
1828                         codepage = hdr_id;
1829                         proto_tree_add_uint (wsp_headers, hf_wsp_header_shift_code,
1830                                         tvb, offset, 1, codepage);
1831                         offset++;
1832                 } else {
1833                         proto_tree_add_text (wsp_headers, tvb, hdr_start, 1,
1834                                         InvalidTextualHeader);
1835                         offset = tvb_len;
1836                 }
1837         }
1838 }
1839
1840
1841 /* The following macros hide common processing for all well-known headers
1842  * and shortens the code to be written in a wkh_XXX() function.
1843  * Even declarations are hidden by a macro.
1844  *
1845  * Define a wkh_XXX() function as follows:
1846  *
1847  * static guint32
1848  * wkh_XXX (proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
1849  * {
1850  *              wkh_0_Declarations;
1851  *              << add other required declarations here >>
1852  *
1853  *              wkh_1_WellKnownValue;
1854  *                      << add well-known value proto item here; don't forget to set the
1855  *                      ok variable to TRUE if parsing was correct >>
1856  *              wkh_2_TextualValue;
1857  *                      << add textual value proto item here; don't forget to set the
1858  *                      ok variable to TRUE if parsing was correct >>
1859  *              wkh_3_ValueWithLength;
1860  *                      << add custom code for value processing and value proto item here >>
1861  *
1862  *              wkh_4_End(hf);
1863  *                      << This macro takes care of parse errors within the header value;
1864  *                      it requires the header field index if the header has not yet been
1865  *                      written to the protocol tree (ti == NULL). >>
1866  * }
1867  *
1868  *      NOTE:   You only need to write parsing code for the successful case,
1869  *                      Errors are automatically reported through the wkh_4_End() macro
1870  *                      when ok <> TRUE.
1871  */
1872
1873 /* The following code is the generic template with which the value of a
1874  * well-known header can be processed. Not all sections yield a semantically
1875  * correct result, so appropriate error information must be provided.
1876  */
1877
1878
1879 #define wkh_0_Declarations                                      /* Declarations for Parsing */ \
1880         gboolean ok = FALSE; /* Triggers error notification code at end */ \
1881         proto_item *ti = NULL; /* Needed for error notification at end */ \
1882         guint32 val_start = hdr_start + 1; \
1883         guint8 hdr_id = tvb_get_guint8 (tvb, hdr_start) & 0x7F; \
1884         guint8 val_id = tvb_get_guint8 (tvb, val_start); \
1885         guint32 offset = val_start; /* Offset to one past this header */ \
1886         guint32 val_len; /* length for value with length field */ \
1887         guint32 val_len_len; /* length of length field */ \
1888         gchar *val_str = NULL
1889
1890 #define wkh_1_WellKnownValue                            /* Parse Well Known Value */ \
1891         proto_tree_add_string_hidden(tree, hf_hdr_name, \
1892                         tvb, hdr_start, offset - hdr_start, \
1893                         val_to_str (hdr_id, vals_field_names, \
1894                                 "<Unknown WSP header field 0x%02X>")); \
1895         if (val_id & 0x80) { /* Well-known value */ \
1896                 offset++; \
1897                 /* Well-known value processing starts HERE \
1898                  * \
1899                  * BEGIN */
1900
1901 #define wkh_2_TextualValue                                      /* Parse Textual Value */ \
1902                 /* END */ \
1903         } else if ((val_id == 0) || (val_id >= 0x20)) { /* Textual value */ \
1904                 val_str = (gchar *)tvb_get_stringz (tvb, val_start, (gint *)&val_len); \
1905                 g_assert(val_str); \
1906                 offset = val_start + val_len; \
1907                 /* Textual value processing starts HERE \
1908                  * \
1909                  * BEGIN */
1910
1911 #define wkh_3_ValueWithLength                           /* Parse Value With Length */ \
1912                 /* END */ \
1913                 g_free(val_str); \
1914         } else { /* val_start points to 1st byte of length field */ \
1915                 if (val_id == 0x1F) { /* Value Length = guintvar */ \
1916                         val_len = tvb_get_guintvar(tvb, val_start + 1, &val_len_len); \
1917                         val_len_len++; /* 0x1F length indicator byte */ \
1918                 } else { /* Short length followed by Len data octets */ \
1919                         val_len = tvb_get_guint8(tvb, offset); \
1920                         val_len_len = 1; \
1921                 } \
1922                 offset += val_len_len + val_len; \
1923                 /* Value with length processing starts HERE \
1924                  * The value lies between val_start and offset: \
1925                  *  - Value Length:     Start  = val_start \
1926                  *                                      Length = val_len_len \
1927                  *  - Value Data  :     Start  = val_start + val_len_len \
1928                  *                                      Length = val_len \
1929                  *                                      End    = offset - 1 \
1930                  * BEGIN */
1931
1932 #define wkh_4_End(hf)                                           /* End of value parsing */ \
1933                 /* END */ \
1934         } \
1935         /* Check for errors */ \
1936         if (! ok) { \
1937                 if (ti) { /* Append to protocol tree item label */ \
1938                         proto_item_append_text(ti, \
1939                                         " <Error: Invalid header value>"); \
1940                 } else if (hf > 0) { /* Create protocol tree item */ \
1941                         proto_tree_add_string(tree, hf, \
1942                                         tvb, hdr_start, offset - hdr_start, \
1943                                         " <Error: Invalid header value>"); \
1944                 } else { /* Create anonymous header field entry */ \
1945                         proto_tree_add_text(tree, tvb, hdr_start, offset - hdr_start, \
1946                                         "%s: <Error: Invalid header value>", \
1947                                         val_to_str (hdr_id, vals_field_names, \
1948                                                 "<Unknown WSP header field 0x%02X>")); \
1949                 } \
1950         } \
1951         return offset;
1952
1953
1954 /*
1955  * This yields the following default header value parser function body
1956  */
1957 static guint32
1958 wkh_default(proto_tree *tree, tvbuff_t *tvb,
1959                 guint32 hdr_start)
1960 {
1961         wkh_0_Declarations;
1962
1963         ok = TRUE; /* Bypass error checking as we don't parse the values! */
1964
1965         wkh_1_WellKnownValue;
1966                 ti = proto_tree_add_text (tree, tvb, hdr_start, offset - hdr_start,
1967                                 "%s: (Undecoded well-known value 0x%02x)",
1968                                 val_to_str (hdr_id, vals_field_names,
1969                                         "<Unknown WSP header field 0x%02X>"), val_id & 0x7F);
1970         wkh_2_TextualValue;
1971                 ti = proto_tree_add_text(tree, tvb, hdr_start, offset - hdr_start,
1972                                 "%s: %s",
1973                                 val_to_str (hdr_id, vals_field_names,
1974                                         "<Unknown WSP header field 0x%02X>"), val_str);
1975         wkh_3_ValueWithLength;
1976                 ti = proto_tree_add_text (tree, tvb, hdr_start, offset - hdr_start,
1977                                 "%s: (Undecoded value in general form with length indicator)",
1978                                 val_to_str (hdr_id, vals_field_names,
1979                                         "<Unknown WSP header field 0x%02X>"));
1980
1981         wkh_4_End(HF_EMPTY); /* The default parser has no associated hf_index;
1982                                                         additionally the error code is always bypassed */
1983 }
1984
1985
1986 /* Content-type processing uses the following common core: */
1987 #define wkh_content_type_header(underscored,Text) \
1988 static guint32 \
1989 wkh_ ## underscored(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start) \
1990 { \
1991         wkh_0_Declarations; \
1992         guint32 off, val = 0, len; \
1993         guint8 peek; \
1994         proto_tree *parameter_tree = NULL; \
1995         \
1996         wkh_1_WellKnownValue; \
1997                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
1998                                 tvb, hdr_start, offset - hdr_start, \
1999                                 val_to_str(val_id & 0x7F, vals_content_types, \
2000                                         "(Unknown content type identifier 0x%X)")); \
2001                 ok = TRUE; \
2002         wkh_2_TextualValue; \
2003                 /* Sometimes with a No-Content response, a NULL content type \
2004                  * is reported. Process this correctly! */ \
2005                 if (*val_str) { \
2006                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2007                                         tvb, hdr_start, offset - hdr_start, \
2008                                         val_str); \
2009                 } else { \
2010                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2011                                         tvb, hdr_start, offset - hdr_start, \
2012                                         "<no content type has been specified>"); \
2013                 } \
2014                 ok = TRUE; \
2015         wkh_3_ValueWithLength; \
2016                 off = val_start + val_len_len; \
2017                 peek = tvb_get_guint8(tvb, off); \
2018                 if (is_text_string(peek)) { \
2019                         get_extension_media(val_str, tvb, off, len, ok); \
2020                         /* As we're using val_str, it is automatically g_free()d */ \
2021                         off += len; /* off now points to 1st byte after string */ \
2022                         ti = proto_tree_add_string (tree, hf_hdr_ ## underscored, \
2023                                         tvb, hdr_start, offset - hdr_start, val_str); \
2024                 } else if (is_integer_value(peek)) { \
2025                         get_integer_value(val, tvb, off, len, ok); \
2026                         if (ok) { \
2027                                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2028                                                 tvb, hdr_start, offset - hdr_start, \
2029                                                 val_to_str(val, vals_content_types, \
2030                                                         "(Unknown content type identifier 0x%X)")); \
2031                         } \
2032                         off += len; \
2033                 } \
2034                 /* Remember: offset == val_start + val_len + val_len_len */ \
2035                 if (ok && (off < offset)) { /* Add parameters if any */ \
2036                         parameter_tree = proto_item_add_subtree (ti, ett_header); \
2037                         while (off < offset) { \
2038                                 off = parameter (parameter_tree, ti, tvb, off, offset - off); \
2039                         } \
2040                 } \
2041         \
2042         wkh_4_End(hf_hdr_ ## underscored); \
2043 }
2044
2045
2046 /*
2047  * Accept-value =
2048  *        Short-integer
2049  *      | Extension-media
2050  *      | ( Value-length ( Extension-media | Integer-value ) *( Parameter ) )
2051  */
2052 wkh_content_type_header(accept, "Accept")
2053
2054
2055 /*
2056  * Content-type-value =
2057  *        Short-integer
2058  *      | Extension-media
2059  *      | ( Value-length ( Extension-media | Integer-value ) *( Parameter ) )
2060  *
2061  * Beware: this header should not appear as such; it is dissected elsewhere
2062  * and at the same time the content type is used for subdissectors.
2063  * It is here for the sake of completeness.
2064  */
2065 wkh_content_type_header(content_type, "Content-Type")
2066
2067
2068 /*
2069  * Content-type-value =
2070  *        Short-integer
2071  *      | Extension-media
2072  *      | ( Value-length ( Extension-media | Integer-value ) *( Parameter ) )
2073  *
2074  * This function adds the content type value to the protocol tree,
2075  * and computes either the numeric or textual media type in return,
2076  * which will be used for further subdissection (e.g., MMS, WBXML).
2077  */
2078 guint32
2079 add_content_type(proto_tree *tree, tvbuff_t *tvb, guint32 val_start,
2080                 guint32 *well_known_content, const char **textual_content)
2081 {
2082         /* Replace wkh_0_Declarations with slightly modified declarations
2083          * so we can still make use of the wkh_[1-4]_XXX macros! */
2084         guint32 hdr_start = val_start; /* No header name, only value! */
2085         guint8 hdr_id = FN_CONTENT_TYPE; /* Same remark */
2086         guint8 val_id = tvb_get_guint8 (tvb, val_start);
2087         guint32 offset = val_start; /* Offset to one past this header */
2088         guint32 val_len; /* length for value with length field */
2089         guint32 val_len_len; /* length of length field */
2090         gchar *val_str = NULL;
2091         guint32 off, val = 0, len;
2092         guint8 peek;
2093         gboolean ok = FALSE;
2094         proto_item *ti = NULL;
2095         proto_tree *parameter_tree = NULL;
2096
2097         *textual_content = NULL;
2098         *well_known_content = 0;
2099
2100         DebugLog(("add_content_type() - START\n"));
2101
2102         wkh_1_WellKnownValue;
2103                 DebugLog(("add_content_type() - Well-known - Start\n"));
2104                 *textual_content = val_to_str(val_id & 0x7F, vals_content_types,
2105                                 "<Unknown media type identifier 0x%X>");
2106                 ti = proto_tree_add_string(tree, hf_hdr_content_type,
2107                                 tvb, hdr_start, offset - hdr_start,
2108                                 *textual_content);
2109                 *well_known_content = val_id & 0x7F;
2110                 ok = TRUE;
2111                 DebugLog(("add_content_type() - Well-known - End\n"));
2112         wkh_2_TextualValue;
2113                 DebugLog(("add_content_type() - Textual - Start\n"));
2114                 /* Sometimes with a No-Content response, a NULL content type
2115                  * is reported. Process this correctly! */
2116                 if (*val_str) {
2117                         ti = proto_tree_add_string(tree, hf_hdr_content_type,
2118                                         tvb, hdr_start, offset - hdr_start,
2119                                         val_str);
2120                         /* As we're using val_str, it is automatically g_free()d */
2121                         *textual_content = g_strdup(val_str);
2122                         *well_known_content = 0;
2123                 } else {
2124                         ti = proto_tree_add_string(tree, hf_hdr_content_type,
2125                                         tvb, hdr_start, offset - hdr_start,
2126                                         "<no media type has been specified>");
2127                         *textual_content = NULL;
2128                         *well_known_content = 0;
2129                 }
2130                 ok = TRUE;
2131                 DebugLog(("add_content_type() - Textual - End\n"));
2132         wkh_3_ValueWithLength;
2133                 DebugLog(("add_content_type() - General form - Start\n"));
2134                 off = val_start + val_len_len;
2135                 peek = tvb_get_guint8(tvb, off);
2136                 if (is_text_string(peek)) {
2137                         DebugLog(("add_content_type() - General form - extension-media\n"));
2138                         get_extension_media(val_str, tvb, off, len, ok);
2139                         /* As we're using val_str, it is automatically g_free()d */
2140                         /* ??? Not sure anymore, we're in wkh_3, not in wkh_2 ! */
2141                         off += len; /* off now points to 1st byte after string */
2142                         ti = proto_tree_add_string (tree, hf_hdr_content_type,
2143                                         tvb, hdr_start, offset - hdr_start, val_str);
2144                         /* Following statement: required? */
2145                         *textual_content = g_strdup(val_str);
2146                         *well_known_content = 0;
2147                 } else if (is_integer_value(peek)) {
2148                         DebugLog(("add_content_type() - General form - integer_value\n"));
2149                         get_integer_value(val, tvb, off, len, ok);
2150                         if (ok) {
2151                                 *textual_content = val_to_str(val, vals_content_types,
2152                                                 "<Unknown media type identifier 0x%X>");
2153                                 ti = proto_tree_add_string(tree, hf_hdr_content_type,
2154                                                 tvb, hdr_start, offset - hdr_start,
2155                                                 *textual_content);
2156                                 *well_known_content = val;
2157                         }
2158                         off += len;
2159                 } /* else ok = FALSE */
2160                 /* Remember: offset == val_start + val_len_len + val_len */
2161                 if (ok && (off < offset)) { /* Add parameters if any */
2162                         DebugLog(("add_content_type() - General form - parameters\n"));
2163                         parameter_tree = proto_item_add_subtree (ti, ett_header);
2164                         while (off < offset) {
2165                                 DebugLog(("add_content_type() - General form - parameter start "
2166                                                         "(off = %u)\n", off));
2167                                 off = parameter (parameter_tree, ti, tvb, off, offset - off);
2168                                 DebugLog(("add_content_type() - General form - parameter end "
2169                                                         "(off = %u)\n", off));
2170                         }
2171                 }
2172                 DebugLog(("add_content_type() - General form - End\n"));
2173
2174         wkh_4_End(hf_hdr_content_type);
2175 }
2176
2177
2178 /*
2179  * Template for accept_X headers with optional Q parameter value
2180  */
2181 #define wkh_accept_x_q_header(underscored,Text,valueString,valueName) \
2182 static guint32 \
2183 wkh_ ## underscored (proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start) \
2184 { \
2185         wkh_0_Declarations; \
2186         guint32 off, val = 0, len; \
2187         guint8 peek; \
2188         proto_tree *parameter_tree = NULL; \
2189         \
2190         wkh_1_WellKnownValue; \
2191                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2192                                 tvb, hdr_start, offset - hdr_start, \
2193                                 val_to_str(val_id & 0x7F, valueString, \
2194                                         "<Unknown " valueName " identifier 0x%X>")); \
2195                 ok = TRUE; \
2196         wkh_2_TextualValue; \
2197                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2198                                 tvb, hdr_start, offset - hdr_start, val_str); \
2199                 ok = TRUE; \
2200         wkh_3_ValueWithLength; \
2201                 off = val_start + val_len_len; \
2202                 peek = tvb_get_guint8(tvb, off); \
2203                 if (is_text_string(peek)) { \
2204                         get_token_text(val_str, tvb, off, len, ok); \
2205                         /* As we're using val_str, it is automatically g_free()d */ \
2206                         off += len; /* off now points to 1st byte after string */ \
2207                         ti = proto_tree_add_string (tree, hf_hdr_ ## underscored, \
2208                                         tvb, hdr_start, offset - hdr_start, val_str); \
2209                 } else if (is_integer_value(peek)) { \
2210                         get_integer_value(val, tvb, off, len, ok); \
2211                         if (ok) { \
2212                                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2213                                                 tvb, hdr_start, offset - hdr_start, \
2214                                                 val_to_str(val, valueString, \
2215                                                         "<Unknown " valueName " identifier 0x%X>")); \
2216                         } \
2217                         off += len; \
2218                 } /* else ok = FALSE */ \
2219                 /* Remember: offset == val_start + val_len */ \
2220                 if (ok && (off < offset)) { /* Add Q-value if available */ \
2221                         parameter_tree = proto_item_add_subtree (ti, ett_header); \
2222                         off = parameter_value_q (parameter_tree, ti, tvb, off); \
2223                 } \
2224         \
2225         wkh_4_End(hf_hdr_ ## underscored); \
2226 }
2227
2228 /*
2229  * Accept-charset-value =
2230  *        Short-integer
2231  *      | Extension-media
2232  *      | ( Value-length ( Token-text | Integer-value ) [ Q-value ] )
2233  */
2234 wkh_accept_x_q_header(accept_charset, "Accept-Charset",
2235                 vals_character_sets, "character set")
2236 /*
2237  * Accept-language-value =
2238  *        Short-integer
2239  *      | Extension-media
2240  *      | ( Value-length ( Text-string | Integer-value ) [ Q-value ] )
2241  */
2242 wkh_accept_x_q_header(accept_language, "Accept-Language",
2243                 vals_languages, "language")
2244
2245
2246 /*
2247  * Push-flag-value = Short-integer
2248  */
2249 static guint32
2250 wkh_push_flag(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
2251 {
2252         wkh_0_Declarations;
2253         proto_tree *subtree = NULL;
2254
2255         wkh_1_WellKnownValue;
2256                 ti = proto_tree_add_string(tree, hf_hdr_push_flag,
2257                                 tvb, hdr_start, offset - hdr_start, "");
2258                 subtree = proto_item_add_subtree(ti, ett_header);
2259                 proto_tree_add_uint(subtree, hf_hdr_push_flag_auth,
2260                                 tvb, val_start, 1, val_id);
2261                 proto_tree_add_uint(subtree, hf_hdr_push_flag_trust,
2262                                 tvb, val_start, 1, val_id);
2263                 proto_tree_add_uint(subtree, hf_hdr_push_flag_last,
2264                                 tvb, val_start, 1, val_id);
2265                 if (val_id & 0x01)
2266                         proto_item_append_string(ti, " (Initiator URI authenticated)");
2267                 if (val_id & 0x02)
2268                         proto_item_append_string(ti, " (Content trusted)");
2269                 if (val_id & 0x04)
2270                         proto_item_append_string(ti, " (Last push message)");
2271                 if (val_id & 0x78)
2272                         proto_item_append_text(ti, " <Warning: Reserved flags set>");
2273                 else
2274                         ok = TRUE;
2275         wkh_2_TextualValue;
2276                 /* Invalid */
2277         wkh_3_ValueWithLength;
2278                 /* Invalid */
2279         wkh_4_End(hf_hdr_push_flag);
2280 }
2281
2282
2283 /*
2284  * Allow-value =
2285  *     Short-integer
2286  */
2287 static guint32
2288 wkh_allow(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
2289 {
2290         wkh_0_Declarations;
2291
2292         wkh_1_WellKnownValue;
2293                 val_id &= 0x7F;
2294                 if (val_id >= 0x40) { /* Valid WSP method */
2295                         ti = proto_tree_add_string(tree, hf_hdr_allow,
2296                                         tvb, hdr_start, offset - hdr_start,
2297                                         val_to_str(val_id & 0x7F, vals_pdu_type,
2298                                                 "<Unknown WSP method 0x%02X>"));
2299                         ok = TRUE;
2300                 }
2301         wkh_2_TextualValue;
2302                 /* Invalid */
2303         wkh_3_ValueWithLength;
2304                 /* Invalid */
2305         wkh_4_End(hf_hdr_allow);
2306 }
2307
2308
2309 /*
2310  * Public-value =
2311  *     Token-text | Short-integer
2312  */
2313 static guint32
2314 wkh_public(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
2315 {
2316         wkh_0_Declarations;
2317
2318         wkh_1_WellKnownValue;
2319                 val_id &= 0x7F;
2320                 if (val_id >= 0x40) { /* Valid WSP method */
2321                         ti = proto_tree_add_string(tree, hf_hdr_public,
2322                                         tvb, hdr_start, offset - hdr_start,
2323                                         val_to_str(val_id & 0x7F, vals_pdu_type,
2324                                                 "<Unknown WSP method 0x%02X>"));
2325                         ok = TRUE;
2326                 }
2327         wkh_2_TextualValue;
2328                 ti = proto_tree_add_string(tree, hf_hdr_public,
2329                                 tvb, hdr_start, offset - hdr_start, val_str);
2330                 ok = TRUE;
2331         wkh_3_ValueWithLength;
2332                 /* Invalid */
2333         wkh_4_End(hf_hdr_public);
2334 }
2335
2336
2337 /*
2338  * Vary-value =
2339  *     Token-text | Short-integer
2340  */
2341 static guint32
2342 wkh_vary(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
2343 {
2344         wkh_0_Declarations;
2345
2346         wkh_1_WellKnownValue;
2347                 ti = proto_tree_add_string(tree, hf_hdr_vary,
2348                                 tvb, hdr_start, offset - hdr_start,
2349                                 val_to_str(val_id & 0x7F, vals_field_names,
2350                                         "<Unknown WSP header field 0x%02X>"));
2351                 ok = TRUE;
2352         wkh_2_TextualValue;
2353                 ti = proto_tree_add_string(tree, hf_hdr_vary,
2354                                 tvb, hdr_start, offset - hdr_start,
2355                                 val_str);
2356                 ok = TRUE;
2357         wkh_3_ValueWithLength;
2358                 /* Invalid */
2359         wkh_4_End(hf_hdr_vary);
2360 }
2361
2362
2363 /*
2364  * X-wap-security-value = 0x80
2365  */
2366 static guint32
2367 wkh_x_wap_security(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
2368 {
2369         wkh_0_Declarations;
2370
2371         wkh_1_WellKnownValue;
2372                 if (val_id == 0x80) {
2373                         ti = proto_tree_add_string(tree, hf_hdr_x_wap_security,
2374                                         tvb, hdr_start, offset - hdr_start, "close-subordinate");
2375                         ok = TRUE;
2376                 }
2377         wkh_2_TextualValue;
2378                 /* Invalid */
2379         wkh_3_ValueWithLength;
2380                 /* Invalid */
2381         wkh_4_End(hf_hdr_x_wap_security);
2382 }
2383
2384
2385 /*
2386  * Connection-value = 0x80 | Token-text
2387  */
2388 static guint32
2389 wkh_connection(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
2390 {
2391         wkh_0_Declarations;
2392
2393         wkh_1_WellKnownValue;
2394                 if (val_id == 0x80) {
2395                         ti = proto_tree_add_string(tree, hf_hdr_connection,
2396                                         tvb, hdr_start, offset - hdr_start, "close");
2397                         ok = TRUE;
2398                 }
2399         wkh_2_TextualValue;
2400                 ti = proto_tree_add_string(tree, hf_hdr_connection,
2401                                 tvb, hdr_start, offset - hdr_start, val_str);
2402                 ok = TRUE;
2403         wkh_3_ValueWithLength;
2404                 /* Invalid */
2405         wkh_4_End(hf_hdr_connection);
2406 }
2407
2408
2409 /*
2410  * Transfer-encoding-value = 0x80 | Token-text
2411  */
2412 static guint32
2413 wkh_transfer_encoding(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
2414 {
2415         wkh_0_Declarations;
2416
2417         wkh_1_WellKnownValue;
2418                 if (val_id == 0x80) {
2419                         ti = proto_tree_add_string(tree, hf_hdr_transfer_encoding,
2420                                         tvb, hdr_start, offset - hdr_start, "chunked");
2421                         ok = TRUE;
2422                 }
2423         wkh_2_TextualValue;
2424                 ti = proto_tree_add_string(tree, hf_hdr_transfer_encoding,
2425                                 tvb, hdr_start, offset - hdr_start, val_str);
2426                 ok = TRUE;
2427         wkh_3_ValueWithLength;
2428                 /* Invalid */
2429         wkh_4_End(hf_hdr_transfer_encoding);
2430 }
2431
2432
2433 /*
2434  * Accept-range-value = 0x80 | 0x81 | Token-text
2435  */
2436 static guint32
2437 wkh_accept_ranges(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
2438 {
2439         wkh_0_Declarations;
2440
2441         wkh_1_WellKnownValue;
2442                 switch (val_id) {
2443                         case 0x80: /* none */
2444                                 ti = proto_tree_add_string(tree, hf_hdr_accept_ranges,
2445                                                 tvb, hdr_start, offset - hdr_start, "none");
2446                                 ok = TRUE;
2447                                 break;
2448                         case 0x81: /* bytes */
2449                                 ti = proto_tree_add_string(tree, hf_hdr_accept_ranges,
2450                                                 tvb, hdr_start, offset - hdr_start, "bytes");
2451                                 ok = TRUE;
2452                                 break;
2453                 }
2454         wkh_2_TextualValue;
2455                 ti = proto_tree_add_string(tree, hf_hdr_accept_ranges,
2456                                 tvb, hdr_start, offset - hdr_start, val_str);
2457                 ok = TRUE;
2458         wkh_3_ValueWithLength;
2459                 /* Invalid */
2460         wkh_4_End(hf_hdr_accept_ranges);
2461 }
2462
2463
2464 /*
2465  * Content-encoding-value = 0x80 | 0x81 | 0x82 | Token-text
2466  */
2467 static guint32
2468 wkh_content_encoding(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
2469 {
2470         wkh_0_Declarations;
2471
2472         wkh_1_WellKnownValue;
2473                 switch (val_id) {
2474                         case 0x80: /* gzip */
2475                                 ti = proto_tree_add_string(tree, hf_hdr_content_encoding,
2476                                                 tvb, hdr_start, offset - hdr_start, "gzip");
2477                                 ok = TRUE;
2478                                 break;
2479                         case 0x81: /* compress */
2480                                 ti = proto_tree_add_string(tree, hf_hdr_content_encoding,
2481                                                 tvb, hdr_start, offset - hdr_start, "compress");
2482                                 ok = TRUE;
2483                                 break;
2484                         case 0x82: /* deflate */
2485                                 ti = proto_tree_add_string(tree, hf_hdr_content_encoding,
2486                                                 tvb, hdr_start, offset - hdr_start, "deflate");
2487                                 ok = TRUE;
2488                                 break;
2489                 }
2490         wkh_2_TextualValue;
2491                 ti = proto_tree_add_string(tree, hf_hdr_content_encoding,
2492                                 tvb, hdr_start, offset - hdr_start, val_str);
2493                 ok = TRUE;
2494         wkh_3_ValueWithLength;
2495                 /* Invalid */
2496         wkh_4_End(hf_hdr_content_encoding);
2497 }
2498
2499
2500 /*
2501  * Accept-encoding-value =
2502  *        Short-integer
2503  *      | Token-text
2504  *      | ( Value-length ( Short-integer | Text-string ) [ Q-value ] )
2505  */
2506 static guint32
2507 wkh_accept_encoding(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
2508 {
2509         wkh_0_Declarations;
2510         guint32 len, off;
2511         guint8 peek;
2512         gchar *str;
2513         proto_tree *parameter_tree = NULL;
2514
2515         wkh_1_WellKnownValue;
2516                 switch (val_id) {
2517                         case 0x80: /* gzip */
2518                                 ti = proto_tree_add_string(tree, hf_hdr_accept_encoding,
2519                                                 tvb, hdr_start, offset - hdr_start, "gzip");
2520                                 ok = TRUE;
2521                                 break;
2522                         case 0x81: /* compress */
2523                                 ti = proto_tree_add_string(tree, hf_hdr_accept_encoding,
2524                                                 tvb, hdr_start, offset - hdr_start, "compress");
2525                                 ok = TRUE;
2526                                 break;
2527                         case 0x82: /* deflate */
2528                                 ti = proto_tree_add_string(tree, hf_hdr_accept_encoding,
2529                                                 tvb, hdr_start, offset - hdr_start, "deflate");
2530                                 ok = TRUE;
2531                                 break;
2532                 }
2533         wkh_2_TextualValue;
2534                 proto_tree_add_string(tree, hf_hdr_accept_encoding,
2535                                 tvb, hdr_start, offset - hdr_start, val_str);
2536                 ok = TRUE;
2537         wkh_3_ValueWithLength;
2538                 off = val_start + val_len_len;
2539                 peek = tvb_get_guint8(tvb, off);
2540                 if (is_short_integer(peek)) {
2541                         switch (val_id) {
2542                                 case 0x80: /* gzip */
2543                                         ti = proto_tree_add_string(tree, hf_hdr_accept_encoding,
2544                                                         tvb, hdr_start, offset - hdr_start, "gzip");
2545                                         ok = TRUE;
2546                                         break;
2547                                 case 0x81: /* compress */
2548                                         ti = proto_tree_add_string(tree, hf_hdr_accept_encoding,
2549                                                         tvb, hdr_start, offset - hdr_start, "compress");
2550                                         ok = TRUE;
2551                                         break;
2552                                 case 0x82: /* deflate */
2553                                         ti = proto_tree_add_string(tree, hf_hdr_accept_encoding,
2554                                                         tvb, hdr_start, offset - hdr_start, "deflate");
2555                                         ok = TRUE;
2556                                         break;
2557                                 case 0x83: /* any */
2558                                         ti = proto_tree_add_string(tree, hf_hdr_accept_encoding,
2559                                                         tvb, hdr_start, offset - hdr_start, "*");
2560                                         ok = TRUE;
2561                                         break;
2562                         }
2563                         off++;
2564                 } else {
2565                         get_token_text(str, tvb, off, len, ok);
2566                         if (ok) {
2567                                 ti = proto_tree_add_string(tree, hf_hdr_accept_encoding,
2568                                                 tvb, hdr_start, offset - hdr_start, str);
2569                                 g_free(str);
2570                         }
2571                         off += len;
2572                 }
2573                 if (ok) {
2574                         /* Remember: offset == val_start + val_len_len + val_len */
2575                         if (off < offset) { /* Add Q-value if available */
2576                                 parameter_tree = proto_item_add_subtree(ti, ett_header);
2577                                 off = parameter_value_q(parameter_tree, ti, tvb, off);
2578                         }
2579                 }
2580         wkh_4_End(hf_hdr_accept_encoding);
2581 }
2582
2583
2584 /*
2585  * Content-disposition-value = Value-length ( Disposition ) *( Parameter )
2586  *      Disposition = Form-data | Attachment | Inline | Token-text
2587  *      Form-data = 0x80
2588  *      Attachment = 0x81
2589  *      Inline = 0x82
2590  * We handle this as:
2591  *      Value-length ( Short-integer | Text-string ) *( Parameter )
2592  */
2593 static guint32
2594 wkh_content_disposition(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
2595 {
2596         wkh_0_Declarations;
2597         guint32 len, off;
2598         guint8 peek;
2599         gchar *str;
2600         proto_tree *parameter_tree = NULL;
2601
2602         wkh_1_WellKnownValue;
2603                 /* Invalid */
2604         wkh_2_TextualValue;
2605                 /* Invalid */
2606         wkh_3_ValueWithLength;
2607                 off = val_start + val_len_len;
2608                 peek = tvb_get_guint8(tvb, off);
2609                 if (is_short_integer(peek)) {
2610                         switch (peek) {
2611                                 case 0x80: /* form-data */
2612                                         ti = proto_tree_add_string(tree, hf_hdr_content_disposition,
2613                                                         tvb, hdr_start, offset - hdr_start, "form-data");
2614                                         ok = TRUE;
2615                                         break;
2616                                 case 0x81: /* attachment */
2617                                         ti = proto_tree_add_string(tree, hf_hdr_content_disposition,
2618                                                         tvb, hdr_start, offset - hdr_start, "attachment");
2619                                         ok = TRUE;
2620                                         break;
2621                                 case 0x82: /* inline */
2622                                         ti = proto_tree_add_string(tree, hf_hdr_content_disposition,
2623                                                         tvb, hdr_start, offset - hdr_start, "inline");
2624                                         ok = TRUE;
2625                                         break;
2626                         }
2627                         off++;
2628                 } else {
2629                         get_token_text(str, tvb, off, len, ok);
2630                         if (ok) {
2631                                 ti = proto_tree_add_string(tree, hf_hdr_content_disposition,
2632                                                 tvb, hdr_start, offset - hdr_start, str);
2633                                 g_free(str);
2634                         }
2635                         off += len;
2636                 }
2637                 if ((ok) && (off < offset)) {
2638                         /* Remember: offset == val_start + val_len_len + val_len */
2639                         parameter_tree = proto_item_add_subtree(ti, ett_header);
2640                         while (off < offset) { /* Add parameters if available */
2641                                 off = parameter(parameter_tree, ti, tvb, off, offset - off);
2642                         }
2643                 }
2644         wkh_4_End(hf_hdr_content_disposition);
2645 }
2646
2647
2648 /*
2649  * Common code for headers with only a textual value
2650  * is written in the macro below:
2651  */
2652 #define wkh_text_header(underscored,Text) \
2653 static guint32 \
2654 wkh_ ## underscored(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start) \
2655 { \
2656         wkh_0_Declarations; \
2657         \
2658         wkh_1_WellKnownValue; \
2659                 /* Invalid */ \
2660         wkh_2_TextualValue; \
2661                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2662                                 tvb, hdr_start, offset - hdr_start, val_str); \
2663                 ok = TRUE; \
2664         wkh_3_ValueWithLength; \
2665                 /* Invalid */ \
2666         wkh_4_End(hf_hdr_ ## underscored); \
2667 }
2668
2669 /* Text-only headers: */
2670 wkh_text_header(content_base, "Content-Base")
2671 wkh_text_header(content_location, "Content-Location")
2672 wkh_text_header(etag, "ETag")
2673 wkh_text_header(from, "From")
2674 wkh_text_header(host, "Host")
2675 wkh_text_header(if_match, "If-Match")
2676 wkh_text_header(if_none_match, "If-None-Match")
2677 wkh_text_header(location, "Location")
2678 wkh_text_header(referer, "Referer")
2679 wkh_text_header(server, "Server")
2680 wkh_text_header(user_agent, "User-Agent")
2681 wkh_text_header(upgrade, "Upgrade")
2682 wkh_text_header(via, "Via")
2683 wkh_text_header(content_uri, "Content-Uri")
2684 wkh_text_header(initiator_uri, "Initiator-Uri")
2685 wkh_text_header(profile, "Profile")
2686
2687 /*
2688  * Same for quoted-string value
2689  */
2690 #define wkh_quoted_string_header(underscored,Text) \
2691 static guint32 \
2692 wkh_ ## underscored(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start) \
2693 { \
2694         wkh_0_Declarations; \
2695         gchar *str; \
2696         \
2697         wkh_1_WellKnownValue; \
2698                 /* Invalid */ \
2699         wkh_2_TextualValue; \
2700                 if (is_quoted_string(val_str[0])) { \
2701                         if (is_quoted_string(val_str[val_len-2])) { \
2702                                 /* Trailing quote - issue a warning */ \
2703                                 str = g_strdup_printf("%s" TrailingQuoteWarning, val_str); \
2704                         } else { /* OK (no trailing quote) */ \
2705                                 str = g_strdup_printf("%s\"", val_str); \
2706                         } \
2707                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2708                                         tvb, hdr_start, offset - hdr_start, str); \
2709                         g_free(str); \
2710                 } else { \
2711                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2712                                         tvb, hdr_start, offset - hdr_start, val_str); \
2713                         proto_item_append_text(ti, \
2714                                         " <Warning: should be encoded as a Quoted-string>"); \
2715                 } \
2716                 ok = TRUE; \
2717         wkh_3_ValueWithLength; \
2718                 /* Invalid */ \
2719         wkh_4_End(hf_hdr_ ## underscored); \
2720 }
2721
2722 wkh_quoted_string_header(content_id, "Content-ID")
2723
2724
2725 /*
2726  * Common code for headers with only a textual or a date value
2727  * is written in the macro below:
2728  */
2729 #define wkh_text_or_date_value_header(underscored,Text) \
2730 static guint32 \
2731 wkh_ ## underscored(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start) \
2732 { \
2733         wkh_0_Declarations; \
2734         guint32 val = 0, off = val_start, len; \
2735         nstime_t tv; \
2736         gchar *str; /* may not be freed! */ \
2737         \
2738         wkh_1_WellKnownValue; \
2739                 /* Invalid */ \
2740         wkh_2_TextualValue; \
2741                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2742                                 tvb, hdr_start, offset - hdr_start, val_str); \
2743                 ok = TRUE; \
2744         wkh_3_ValueWithLength; \
2745                 if (val_id <= 4) { /* Length field already parsed by macro! */ \
2746                         get_date_value(val, tvb, off, len, ok); \
2747                         if (ok) { \
2748                                 tv.secs = val; \
2749                                 tv.nsecs = 0; \
2750                                 str = abs_time_to_str(&tv); \
2751                                 g_assert(str); \
2752                                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2753                                                 tvb, hdr_start, offset - hdr_start, str); \
2754                                 /* BEHOLD: do NOT try to free str, as this generates a core
2755                                  * dump!  It looks like abs_time_to_str() is buggy or works
2756                                  * with static data. */ \
2757                         } \
2758                 } \
2759         wkh_4_End(hf_hdr_ ## underscored); \
2760 }
2761
2762 /* If-Range */
2763 wkh_text_or_date_value_header(if_range,"If-Range")
2764
2765
2766 /*
2767  * Common code for headers with only a date value
2768  * is written in the macro below:
2769  */
2770 #define wkh_date_value_header(underscored,Text) \
2771 static guint32 \
2772 wkh_ ## underscored(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start) \
2773 { \
2774         wkh_0_Declarations; \
2775         guint32 val = 0, off = val_start, len; \
2776         nstime_t tv; \
2777         gchar *str; /* may not be freed! */ \
2778         \
2779         wkh_1_WellKnownValue; \
2780                 /* Invalid */ \
2781         wkh_2_TextualValue; \
2782                 /* Invalid */ \
2783         wkh_3_ValueWithLength; \
2784                 if (val_id <= 4) { /* Length field already parsed by macro! */ \
2785                         get_date_value(val, tvb, off, len, ok); \
2786                         if (ok) { \
2787                                 tv.secs = val; \
2788                                 tv.nsecs = 0; \
2789                                 str = abs_time_to_str(&tv); \
2790                                 g_assert(str); \
2791                                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2792                                                 tvb, hdr_start, offset - hdr_start, str); \
2793                                 /* BEHOLD: do NOT try to free str, as this generates a core
2794                                  * dump!  It looks like abs_time_to_str() is buggy or works
2795                                  * with static data. */ \
2796                         } \
2797                 } \
2798         wkh_4_End(hf_hdr_ ## underscored); \
2799 }
2800
2801 /* Date-value only headers: */
2802 wkh_date_value_header(date, "Date")
2803 wkh_date_value_header(expires, "Expires")
2804 wkh_date_value_header(if_modified_since, "If-Modified-Since")
2805 wkh_date_value_header(if_unmodified_since, "If-Unmodified-Since")
2806 wkh_date_value_header(last_modified, "Last-Modified")
2807
2808
2809 /* Date-value with special interpretation of zero value */
2810 #define wkh_tod_value_header(underscored,Text) \
2811 static guint32 \
2812 wkh_ ## underscored(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start) \
2813 { \
2814         wkh_0_Declarations; \
2815         guint32 val = 0, off = val_start, len; \
2816         nstime_t tv; \
2817         gchar *str; /* may not be freed! */ \
2818         \
2819         wkh_1_WellKnownValue; \
2820                 if (val_id == 0x80) { /* Openwave TOD header uses this format */ \
2821                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2822                                         tvb, hdr_start, offset - hdr_start, \
2823                                         "Requesting Time Of Day"); \
2824                         proto_item_append_text(ti, \
2825                                         " <Warning: should be encoded as long-integer>"); \
2826                         ok = TRUE; \
2827                 } \
2828                 /* It seems VERY unlikely that we'll see date values within the first \
2829                  * 127 seconds of the UNIX 1-1-1970 00:00:00 start of the date clocks \
2830                  * so I assume such a value is a genuine error */ \
2831         wkh_2_TextualValue; \
2832                 /* Invalid */ \
2833         wkh_3_ValueWithLength; \
2834                 if (val_id <= 4) { /* Length field already parsed by macro! */ \
2835                         get_date_value(val, tvb, off, len, ok); \
2836                         if (ok) { \
2837                                 if (val == 0) { \
2838                                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2839                                                         tvb, hdr_start, offset - hdr_start, \
2840                                                         "Requesting Time Of Day"); \
2841                                 } else { \
2842                                         tv.secs = val; \
2843                                         tv.nsecs = 0; \
2844                                         str = abs_time_to_str(&tv); \
2845                                         g_assert(str); \
2846                                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2847                                                         tvb, hdr_start, offset - hdr_start, str); \
2848                                 } \
2849                         } \
2850                 } \
2851         wkh_4_End(hf_hdr_ ## underscored); \
2852 }
2853
2854 wkh_tod_value_header(x_wap_tod, "X-Wap-Tod")
2855
2856
2857 /*
2858  * Age-value: Delta-seconds-value
2859  */
2860 static guint32
2861 wkh_age(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
2862 {
2863         wkh_0_Declarations;
2864         guint32 val = 0, off = val_start, len;
2865
2866         wkh_1_WellKnownValue;
2867                 val = val_id & 0x7F;
2868                 val_str = g_strdup_printf("%u second%s", val, PLURALIZE(val));
2869                 ti = proto_tree_add_string(tree, hf_hdr_age,
2870                                 tvb, hdr_start, offset - hdr_start, val_str);
2871                 g_free(val_str); /* proto_XXX creates a copy */
2872                 ok = TRUE;
2873         wkh_2_TextualValue;
2874                 /* Invalid */
2875         wkh_3_ValueWithLength;
2876                 if (val_id <= 4) { /* Length field already parsed by macro! */
2877                         get_long_integer(val, tvb, off, len, ok);
2878                         if (ok) {
2879                                 val_str = g_strdup_printf("%u second%s", val, PLURALIZE(val));
2880                                 ti = proto_tree_add_string(tree, hf_hdr_age,
2881                                                 tvb, hdr_start, offset - hdr_start, val_str);
2882                                 g_free(val_str); /* proto_XXX creates a copy */
2883                         }
2884                 }
2885         wkh_4_End(hf_hdr_age);
2886 }
2887
2888
2889 /*
2890  * Template for Integer lookup or text value headers:
2891  */
2892 #define wkh_integer_lookup_or_text_value(underscored,Text,valueString,valueName) \
2893 static guint32 \
2894 wkh_ ## underscored(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start) \
2895 { \
2896         wkh_0_Declarations; \
2897         guint32 val = 0, off = val_start, len; \
2898         \
2899         wkh_1_WellKnownValue; \
2900                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2901                                 tvb, hdr_start, offset - hdr_start, \
2902                                 val_to_str(val_id & 0x7F, valueString, \
2903                                 "(Unknown " valueName " identifier 0x%X)")); \
2904                 ok = TRUE; \
2905         wkh_2_TextualValue; \
2906                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2907                                 tvb, hdr_start, offset - hdr_start, val_str); \
2908                 ok = TRUE; \
2909         wkh_3_ValueWithLength; \
2910                 if (val_id <= 4) { /* Length field already parsed by macro! */ \
2911                         get_long_integer(val, tvb, off, len, ok); \
2912                         if (ok) { \
2913                                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2914                                                 tvb, hdr_start, offset - hdr_start, \
2915                                                 val_to_str(val_id & 0x7F, valueString, \
2916                                                 "(Unknown " valueName " identifier 0x%X)")); \
2917                         } \
2918                 } \
2919         wkh_4_End(hf_hdr_ ## underscored); \
2920 }
2921
2922 /*
2923  * Wap-application-value: Uri-value | Integer-value
2924  */
2925 wkh_integer_lookup_or_text_value(x_wap_application_id, "X-Wap-Application-Id",
2926                 vals_wap_application_ids, "WAP application")
2927 wkh_integer_lookup_or_text_value(accept_application, "Accept-Application",
2928                 vals_wap_application_ids, "WAP application")
2929 wkh_integer_lookup_or_text_value(content_language, "Content-Language",
2930                 vals_languages, "language")
2931 /* NOTE - Although the WSP spec says this is an integer-value, the WSP headers
2932  * are encoded as a 7-bit entity! */
2933 wkh_integer_lookup_or_text_value(trailer, "Trailer",
2934                 vals_field_names, "well-known-header")
2935
2936
2937 /*
2938  * Challenge
2939  */
2940
2941 /*
2942  * Common code for headers with only a challenge value
2943  * is written in the macro below:
2944  */
2945 #define wkh_challenge_value_header(underscored,Text) \
2946 static guint32 \
2947 wkh_ ## underscored(proto_tree *tree, tvbuff_t *tvb, \
2948                 guint32 hdr_start) \
2949 { \
2950         wkh_0_Declarations; \
2951         guint8 peek; \
2952         guint32 off, len; \
2953         proto_tree *subtree; \
2954         gchar *str; \
2955         \
2956         wkh_1_WellKnownValue; \
2957                 /* Invalid */ \
2958         wkh_2_TextualValue; \
2959                 /* Invalid */ \
2960         wkh_3_ValueWithLength; \
2961                 off = val_start + val_len_len; \
2962                 peek = tvb_get_guint8(tvb, off); \
2963                 if (peek == 0x80) { /* Basic */ \
2964                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2965                                         tvb, hdr_start, offset - hdr_start, "basic"); \
2966                         subtree = proto_item_add_subtree(ti, ett_header); \
2967                         proto_tree_add_string(subtree, hf_hdr_ ## underscored ## _scheme, \
2968                                         tvb, off, 1, "basic"); \
2969                         off++; \
2970                         /* Realm: text-string */ \
2971                         get_text_string(str,tvb,off,len,ok); \
2972                         if (ok) { \
2973                                 proto_tree_add_string(subtree, \
2974                                                 hf_hdr_ ## underscored ## _realm, \
2975                                                 tvb, off, len, str); \
2976                                 val_str = g_strdup_printf("; realm=%s", str); \
2977                                 proto_item_append_string(ti, val_str); \
2978                                 g_free(val_str); \
2979                                 g_free(str); \
2980                                 off += len; \
2981                         } \
2982                 } else { /* Authentication-scheme: token-text */ \
2983                         get_token_text(str, tvb, off, len, ok); \
2984                         if (ok) { \
2985                                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
2986                                                 tvb, hdr_start, off - hdr_start, str); \
2987                                 subtree = proto_item_add_subtree(ti, ett_header); \
2988                                 proto_tree_add_string(subtree, \
2989                                                 hf_hdr_ ## underscored ## _scheme, \
2990                                                 tvb, hdr_start, off - hdr_start, str); \
2991                                 g_free(str); \
2992                                 off += len; \
2993                                 /* Realm: text-string */ \
2994                                 get_text_string(str,tvb,off,len,ok); \
2995                                 if (ok) { \
2996                                         proto_tree_add_string(subtree, \
2997                                                         hf_hdr_ ## underscored ## _realm, \
2998                                                         tvb, off, len, str); \
2999                                         val_str = g_strdup_printf("; realm=%s", str); \
3000                                         proto_item_append_string(ti, val_str); \
3001                                         g_free(val_str); \
3002                                         g_free(str); \
3003                                         off += len; \
3004                                         /* Auth-params: parameter - TODO */ \
3005                                         while (off < offset) /* Parse parameters */ \
3006                                                 off = parameter(subtree, ti, tvb, off, offset - off); \
3007                                 } \
3008                         } \
3009                 } \
3010         wkh_4_End(hf_hdr_ ## underscored); \
3011 }
3012
3013 /* Challenge-value only headers: */
3014 wkh_challenge_value_header(www_authenticate, "WWW-Authenticate")
3015 wkh_challenge_value_header(proxy_authenticate, "Proxy-Authenticate")
3016
3017
3018 /*
3019  * Credentials
3020  */
3021
3022 /*
3023  * Common code for headers with only a credentials value
3024  * is written in the macro below:
3025  */
3026 #define wkh_credentials_value_header(underscored,Text) \
3027 static guint32 \
3028 wkh_ ## underscored(proto_tree *tree, tvbuff_t *tvb, \
3029                 guint32 hdr_start) \
3030 { \
3031         wkh_0_Declarations; \
3032         guint8 peek; \
3033         guint32 off, len; \
3034         proto_tree *subtree; \
3035         gchar *str; \
3036         \
3037         wkh_1_WellKnownValue; \
3038                 /* Invalid */ \
3039         wkh_2_TextualValue; \
3040                 /* Invalid */ \
3041         wkh_3_ValueWithLength; \
3042                 off = val_start + val_len_len; \
3043                 peek = tvb_get_guint8(tvb, off); \
3044                 if (peek == 0x80) { /* Basic */ \
3045                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
3046                                         tvb, hdr_start, offset - hdr_start, "basic"); \
3047                         subtree = proto_item_add_subtree(ti, ett_header); \
3048                         proto_tree_add_string(subtree, hf_hdr_ ## underscored ## _scheme, \
3049                                         tvb, off, 1, "basic"); \
3050                         off++; \
3051                         /* User-id: text-string */ \
3052                         get_text_string(str,tvb,off,len,ok); \
3053                         if (ok) { \
3054                                 proto_tree_add_string(subtree, \
3055                                                 hf_hdr_ ## underscored ## _user_id, \
3056                                                 tvb, off, len, str); \
3057                                 val_str = g_strdup_printf("; user-id=%s", str); \
3058                                 proto_item_append_string(ti, val_str); \
3059                                 g_free(val_str); \
3060                                 g_free(str); \
3061                                 off += len; \
3062                                 /* Password: text-string */ \
3063                                 get_text_string(str,tvb,off,len,ok); \
3064                                 if (ok) { \
3065                                         proto_tree_add_string(subtree, \
3066                                                         hf_hdr_ ## underscored ## _password, \
3067                                                         tvb, off, len, str); \
3068                                         val_str = g_strdup_printf("; password=%s", str); \
3069                                         proto_item_append_string(ti, val_str); \
3070                                         g_free(val_str); \
3071                                         g_free(str); \
3072                                         off += len; \
3073                                 } \
3074                         } \
3075                 } else { /* Authentication-scheme: token-text */ \
3076                         get_token_text(str, tvb, off, len, ok); \
3077                         if (ok) { \
3078                                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
3079                                                 tvb, hdr_start, off - hdr_start, str); \
3080                                 subtree = proto_item_add_subtree(ti, ett_header); \
3081                                 proto_tree_add_string(subtree, \
3082                                                 hf_hdr_ ## underscored ## _scheme, \
3083                                                 tvb, hdr_start, off - hdr_start, str); \
3084                                 g_free(str); \
3085                                 off += len; \
3086                                 /* Auth-params: parameter - TODO */ \
3087                                 while (off < offset) /* Parse parameters */ \
3088                                         off = parameter(subtree, ti, tvb, off, offset - off); \
3089                         } \
3090                 } \
3091         wkh_4_End(hf_hdr_ ## underscored); \
3092 }
3093
3094 /* Credentials-value only headers: */
3095 wkh_credentials_value_header(authorization, "Authorization")
3096 wkh_credentials_value_header(proxy_authorization, "Proxy-Authorization")
3097
3098
3099 /*
3100  * Content-md5-value = 16*16 OCTET
3101  */
3102 static guint32
3103 wkh_content_md5 (proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
3104 {
3105         wkh_0_Declarations;
3106         guint32 off;
3107
3108         wkh_1_WellKnownValue;
3109                 /* Invalid */
3110         wkh_2_TextualValue;
3111                 /* Invalid */
3112         wkh_3_ValueWithLength;
3113                 off = val_start + val_len_len;
3114                 if (val_len == 16) {
3115                         val_str = g_strdup_printf(
3116                                         "%02x%02x%02x%02x%02x%02x%02x%02x"
3117                                         "%02x%02x%02x%02x%02x%02x%02x%02x",
3118                                         tvb_get_guint8(tvb, off),
3119                                         tvb_get_guint8(tvb, off + 1),
3120                                         tvb_get_guint8(tvb, off + 2),
3121                                         tvb_get_guint8(tvb, off + 3),
3122                                         tvb_get_guint8(tvb, off + 4),
3123                                         tvb_get_guint8(tvb, off + 5),
3124                                         tvb_get_guint8(tvb, off + 6),
3125                                         tvb_get_guint8(tvb, off + 7),
3126                                         tvb_get_guint8(tvb, off + 8),
3127                                         tvb_get_guint8(tvb, off + 9),
3128                                         tvb_get_guint8(tvb, off + 10),
3129                                         tvb_get_guint8(tvb, off + 11),
3130                                         tvb_get_guint8(tvb, off + 12),
3131                                         tvb_get_guint8(tvb, off + 13),
3132                                         tvb_get_guint8(tvb, off + 14),
3133                                         tvb_get_guint8(tvb, off + 15)
3134                         );
3135                         ti = proto_tree_add_string(tree, hf_hdr_content_md5,
3136                                         tvb, hdr_start, offset - hdr_start, val_str);
3137                         g_free(val_str);
3138                         ok = TRUE;
3139                 }
3140         wkh_4_End(hf_hdr_content_md5);
3141 }
3142
3143
3144 /*
3145  * Pragma-value = 0x80 | Length Parameter
3146  */
3147 static guint32
3148 wkh_pragma(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
3149 {
3150         wkh_0_Declarations;
3151         guint32 off;
3152
3153         wkh_1_WellKnownValue;
3154                 if (val_id == 0x80) {
3155                         ti = proto_tree_add_string(tree, hf_hdr_pragma,
3156                                         tvb, hdr_start, offset - hdr_start, "no-cache");
3157                         ok = TRUE;
3158                 }
3159         wkh_2_TextualValue;
3160                 /* Invalid */
3161         wkh_3_ValueWithLength;
3162                 off = val_start + val_len_len;
3163                 ti = proto_tree_add_string(tree, hf_hdr_pragma,
3164                                 tvb, hdr_start, off - hdr_start, "");
3165                 /* NULL subtree for parameter() results in no subtree
3166                  * TODO - provide a single parameter dissector that appends data
3167                  * to the header field data. */
3168                 off = parameter(NULL, ti, tvb, off, offset - off);
3169                 ok = TRUE;
3170         wkh_4_End(hf_hdr_pragma);
3171 }
3172
3173
3174 /*
3175  * Integer-value
3176  */
3177 #define wkh_integer_value_header(underscored,Text) \
3178 static guint32 \
3179 wkh_ ## underscored(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start) \
3180 { \
3181         wkh_0_Declarations; \
3182         guint32 val = 0, off = val_start, len; \
3183         gchar *str; /* may not be freed! */ \
3184         \
3185         wkh_1_WellKnownValue; \
3186                 str = g_strdup_printf("%u", val_id & 0x7F); \
3187                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
3188                                 tvb, hdr_start, offset - hdr_start, str); \
3189                 g_free(str); \
3190                 ok = TRUE; \
3191         wkh_2_TextualValue; \
3192                 /* Invalid */ \
3193         wkh_3_ValueWithLength; \
3194                 if (val_id <= 4) { /* Length field already parsed by macro! */ \
3195                         get_long_integer(val, tvb, off, len, ok); \
3196                         if (ok) { \
3197                                 str = g_strdup_printf("%u", val); \
3198                                 ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
3199                                                 tvb, hdr_start, offset - hdr_start, str); \
3200                                 g_free(str); \
3201                         } \
3202                 } \
3203         wkh_4_End(hf_hdr_ ## underscored); \
3204 }
3205
3206 wkh_integer_value_header(content_length, "Content-Length")
3207 wkh_integer_value_header(max_forwards, "Max-Forwards")
3208
3209
3210 #define wkh_integer_lookup_value_header(underscored,Text,valueString,valueName) \
3211 static guint32 \
3212 wkh_ ## underscored(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start) \
3213 { \
3214         wkh_0_Declarations; \
3215         guint32 val = 0, off = val_start, len; \
3216         \
3217         wkh_1_WellKnownValue; \
3218                 val_str = match_strval(val_id & 0x7F, valueString); \
3219                 if (val_str) { \
3220                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
3221                                 tvb, hdr_start, offset - hdr_start, val_str); \
3222                         ok = TRUE; \
3223                 } else { \
3224                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
3225                                 tvb, hdr_start, offset - hdr_start, \
3226                                 "<Unknown " valueName ">"); \
3227                 } \
3228         wkh_2_TextualValue; \
3229                 /* Invalid */ \
3230         wkh_3_ValueWithLength; \
3231                 if (val_id <= 4) { /* Length field already parsed by macro! */ \
3232                         get_long_integer(val, tvb, off, len, ok); \
3233                         if (ok) { \
3234                                 val_str = match_strval(val_id & 0x7F, valueString); \
3235                                 if (val_str) { \
3236                                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
3237                                                 tvb, hdr_start, offset - hdr_start, val_str); \
3238                                         ok = TRUE; \
3239                                 } else { \
3240                                         ti = proto_tree_add_string(tree, hf_hdr_ ## underscored, \
3241                                                 tvb, hdr_start, offset - hdr_start, \
3242                                                 "<Unknown " valueName ">"); \
3243                                 } \
3244                         } \
3245                 } \
3246         wkh_4_End(hf_hdr_ ## underscored); \
3247 }
3248
3249 wkh_integer_lookup_value_header(bearer_indication, "Bearer-Indication",
3250                 vals_bearer_types, "bearer type")
3251
3252
3253 /*
3254  * Cache-control-value
3255  */
3256 static guint32
3257 wkh_cache_control(proto_tree *tree, tvbuff_t *tvb, guint32 hdr_start)
3258 {
3259         wkh_0_Declarations;
3260         guint32 off, len, val = 0;
3261         guint8 peek, cache_control_directive;
3262         gchar *str;
3263
3264         wkh_1_WellKnownValue;
3265                 val = val_id & 0x7F;
3266                 val_str = match_strval(val, vals_cache_control);
3267                 if (val_str) {
3268                         ti = proto_tree_add_string(tree, hf_hdr_cache_control,
3269                                         tvb, hdr_start, offset - hdr_start, val_str);
3270                         ok = TRUE;
3271                 }
3272         wkh_2_TextualValue;
3273                 ti = proto_tree_add_string(tree, hf_hdr_cache_control,
3274                                 tvb, hdr_start, offset - hdr_start, val_str);
3275                 ok = TRUE;
3276         wkh_3_ValueWithLength;
3277                 /* General form:
3278                  *        ( no-cache | private ) 1*( Field-name )
3279                  *      | ( max-age | max-stale | min-fresh | s-maxage) Delta-seconds-value
3280                  *      | Token-text ( Integer-value | Text-value )
3281                  * Where:
3282                  *      Field-name = Short-integer | Token-text
3283                  */
3284                 off = val_start + val_len_len;
3285                 cache_control_directive = tvb_get_guint8(tvb, off++);
3286                 if (cache_control_directive & 0x80) { /* Well known cache directive */
3287                         switch (cache_control_directive & 0x7F) {
3288                                 case CACHE_CONTROL_NO_CACHE:
3289                                 case CACHE_CONTROL_PRIVATE:
3290                                         ti = proto_tree_add_string(tree, hf_hdr_cache_control,
3291                                                         tvb, hdr_start, offset - hdr_start,
3292                                                         val_to_str (cache_control_directive & 0x7F, vals_cache_control,
3293                                                                 "<Unknown cache control directive 0x%02X>"));
3294                                         /* TODO: split multiple entries */
3295                                         while (ok && (off < offset)) { /* 1*( Field-name ) */
3296                                                 ok = TRUE;
3297                                                 peek = tvb_get_guint8(tvb, off);
3298                                                 if (peek & 0x80) { /* Well-known-field-name */
3299                                                         proto_item_append_string(ti,
3300                                                                         val_to_str (peek, vals_field_names,
3301                                                                                 "<Unknown WSP header field 0x%02X>"));
3302                                                         off++;
3303                                                 } else { /* Token-text */
3304                                                         get_token_text(val_str, tvb, off, len, ok);
3305                                                         if (ok) {
3306                                                                 proto_item_append_string(ti, val_str);
3307                                                                 g_free(val_str);
3308                                                                 off += len;
3309                                                         }
3310                                                 }
3311                                         }
3312                                         break;
3313
3314                                 case CACHE_CONTROL_MAX_AGE:
3315                                 case CACHE_CONTROL_MAX_STALE:
3316                                 case CACHE_CONTROL_MIN_FRESH:
3317                                 case CACHE_CONTROL_S_MAXAGE:
3318                                         ti = proto_tree_add_string(tree, hf_hdr_cache_control,
3319                                                         tvb, hdr_start, offset - hdr_start,
3320                                                         val_to_str (cache_control_directive & 0x7F, vals_cache_control,
3321                                                                 "<Unknown cache control directive 0x%02X>"));
3322                                         get_delta_seconds_value(val, tvb, off, len, ok);
3323                                         if (ok) {
3324                                                 val_str = g_strdup_printf("=%u second%s",
3325                                                                 val, PLURALIZE(val));
3326                                                 proto_item_append_string(ti, val_str);
3327                                                 g_free(val_str); /* proto_XXX creates a copy */
3328                                         }
3329                                         break;
3330
3331                                 default:
3332