summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--epan/tpg.h5
-rw-r--r--epan/tvbparse.c3
-rw-r--r--plugins/tpg/http.tpg74
-rw-r--r--tools/tpg/tpg.pl29
-rw-r--r--tools/tpg/tpg.yp30
5 files changed, 89 insertions, 52 deletions
diff --git a/epan/tpg.h b/epan/tpg.h
index 02360ac108..ee6deddbea 100644
--- a/epan/tpg.h
+++ b/epan/tpg.h
@@ -3,7 +3,7 @@
*
* (c) 2005, Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
*
- * $Id:$
+ * $Id$
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -78,6 +78,7 @@ extern tpg_stack_frame_t* tpg_pop(tpg_parser_data_t* tpg);
#define TPG_POP(tpg) tpg_pop(((tpg_parser_data_t*)tpg))
#define TPG_ADD_STRING(tpg, hfid, elem) proto_tree_add_item(((tpg_parser_data_t*)tpg)->stack->tree, hfid, (elem)->tvb, (elem)->offset, (elem)->len, FALSE)
+#define TPG_ADD_BOOLEAN(tpg, hfid, elem) proto_tree_add_boolean(((tpg_parser_data_t*)tpg)->stack->tree, hfid, (elem)->tvb, (elem)->offset, (elem)->len, TRUE)
#define TPG_ADD_INT(tpg, hfid, elem, value) proto_tree_add_int(((tpg_parser_data_t*)tpg)->stack->tree, hfid, (elem)->tvb, (elem)->offset, (elem)->len, value)
#define TPG_ADD_UINT(tpg, hfid, elem, value) proto_tree_add_uint(((tpg_parser_data_t*)tpg)->stack->tree, hfid, (elem)->tvb, (elem)->offset, (elem)->len, value)
#define TPG_ADD_IPV4(tpg, hfid, elem, value) proto_tree_add_ipv4(((tpg_parser_data_t*)tpg)->stack->tree, hfid, (elem)->tvb, (elem)->offset, (elem)->len, value)
@@ -85,4 +86,6 @@ extern tpg_stack_frame_t* tpg_pop(tpg_parser_data_t* tpg);
#define TPG_ADD_TEXT(tpg, elem) proto_tree_add_text(((tpg_parser_data_t*)tpg)->stack->tree, (elem)->tvb, (elem)->offset, (elem)->len, \
"%s",tvb_format_text((elem)->tvb, (elem)->offset, (elem)->len))
+#define TPG_SET_TEXT(pi, elem) proto_item_set_text((pi), "%s",tvb_format_text((elem)->tvb, (elem)->offset, (elem)->len))
+
#endif /* _TPG_H_ */
diff --git a/epan/tvbparse.c b/epan/tvbparse.c
index 94a23c2526..0007104817 100644
--- a/epan/tvbparse.c
+++ b/epan/tvbparse.c
@@ -680,9 +680,6 @@ tvbparse_elem_t* tvbparse_get(tvbparse_t* tt,
tok->len = (tok->offset - offset) + tok->len;
} else {
tok->len = (tok->offset - offset);
-
- tt->offset = save_offset + tok->len;
- tt->max_len = save_len - tok->len;
}
tok->offset = offset;
diff --git a/plugins/tpg/http.tpg b/plugins/tpg/http.tpg
index c9313e5313..a1cfb17169 100644
--- a/plugins/tpg/http.tpg
+++ b/plugins/tpg/http.tpg
@@ -51,7 +51,7 @@ typedef struct _http_info_value_t
%field version hyttp.version "HTTP Version" FT_STRING.
%rule http_version = "HTTP/" ( "1.0" | "1.1" )<version> .
-%field response hyttp.response "Response" FT_BOOLEAN .
+%field response hyttp.response "Response" FT_STRING .
%field response_code hyttp.response.code "Response Code" FT_UINT32 BASE_DEC %{ http_response_codes %} .
%rule response = (http_version sp [0-9]+<response_code:RESPONSE> ... { crlf } )<response:%plain_text> . {
%root response
@@ -61,7 +61,7 @@ typedef struct _http_info_value_t
%}
}
-%field request hyttp.request "Request" FT_BOOLEAN .
+%field request hyttp.request "Request" FT_STRING .
%field method hyttp.request.method "Request Method" FT_STRING .
%field uri hyttp.request.uri "Request URI" FT_STRING .
%rule request = ([A-Z]+<method:METHOD> sp [^ ]+<uri:URI> sp http_version crlf )<request:%plain_text> . {
@@ -78,48 +78,83 @@ typedef struct _http_info_value_t
%rule media = [a-z]+ "/" [a-z]+ .
%field content_type hyttp.content_type "Content-Type" FT_STRING .
-%rule content_type = "Content-Type: " media<content_type:MEDIA> sp? crlf . {
- %code %{
+
+#crash %rule content_type = 'Content-type: ' (media<content_type:MEDIA> crlf | ( media<content_type:MEDIA> ... { crlf } )) . {
+%rule content_type = 'Content-type: ' media<content_type:MEDIA> ... { crlf } . {
+%code %{
TT_DATA->media = TPG_STRING(MEDIA);
%}
}
%field content_length hyttp.headers.content_length "Content-Length" FT_UINT32 BASE_DEC .
-%rule content_length = "Content-Length: " media<content_length:LENGTH> sp? crlf . {
+%rule content_length = 'Content-length: ' [0-9]+<content_length:LENGTH> crlf . {
%code %{
TT_DATA->content_length = TPG_UINT(LENGTH);
%}
}
%field transfer_encoding hyttp.transfer_encoding "Transfer-Encoding" FT_STRING .
-%rule transfer_encoding = "Transfer-Encoding: " ...<transfer_encoding:ENCODING> { crlf }. {
+%rule transfer_encoding = 'Transfer-encoding: ' ...<transfer_encoding:ENCODING> { crlf }. {
%code %{
TT_DATA->transfer_encoding = TPG_STRING(ENCODING);
%}
}
%field authorization hyttp.authorization "Authorization" FT_STRING .
-%rule authorization = "Authorization: " ...<authorization> { crlf } .
+%rule authorization = 'Authorization: ' ...<authorization> { crlf } .
%field proxy_authorization hyttp.proxy_authorization "Proxy-Authorization" FT_STRING .
-%rule proxy_author = "Proxy-Authorization: " ...<proxy_authorization> { crlf } .
+%rule proxy_author = 'Proxy-authorization: ' ...<proxy_authorization> { crlf } .
%field proxy_authen hyttp.proxy_authenti "Proxy-Authenticate" FT_STRING .
-%rule proxy_authen = "Proxy-Authenticate: " ...<proxy_authen> { crlf } .
+%rule proxy_authen = 'Proxy-authenticate: ' ...<proxy_authen> { crlf } .
%field www_auth hyttp.www_authenticate "WWW-Authenticate" FT_STRING .
-%rule www_auth = "WWW-Authenticate: " ...<www_auth> { crlf } .
+%rule www_auth = 'WWW-authenticate: ' ...<www_auth> { crlf } .
%field content_encoding hyttp.content_encoding "Content-Encoding" FT_STRING .
-%rule content_encoding = "Content-Encoding: " ...<content_encoding> { crlf } .
+%rule content_encoding = 'Content-Encoding: ' ...<content_encoding> { crlf } .
%field user_agent hyttp.content_encoding "User-Agent" FT_STRING .
-%rule user_agent = "User-Agent: " ...<user_agent> { crlf } .
+%rule user_agent = 'User-Agent: ' ...<user_agent> { crlf } .
%field host hyttp.host "Host" FT_STRING .
-%rule host = "Host: " ...<host> { crlf } .
+%rule host = 'Host: ' ...<host> { crlf } .
+
+%field accept hyttp.accept "Accept" FT_STRING .
+%rule accept = 'Accept: ' ...<accept> { crlf } .
+
+%field accept_language hyttp.accept_language "Accept-Language" FT_STRING .
+%rule accept_language = 'Accept-language: ' ...<accept_language> { crlf } .
+
+%field accept_encoding hyttp.accept_encoding "Accept-Language" FT_STRING .
+%rule accept_encoding = 'Accept-encoding: ' ...<accept_encoding> { crlf } .
+
+%field accept_ranges hyttp.accept_encoding "Accept-Ranges" FT_STRING .
+%rule accept_ranges = 'Accept-Ranges: ' ...<accept_ranges> { crlf } .
+
+%field keep_alive hyttp.keep_alive "Keep-Alive" FT_UINT32 BASE_DEC .
+%rule keep_alive = 'Keep-Alive: ' ...<keep_alive> { crlf } .
+
+%field connection hyttp.connection "Connection" FT_STRING .
+%rule connection = 'Connection: ' ...<connection> { crlf } .
+
+%field referer hyttp.referer "Referer" FT_STRING .
+%rule referer = 'Referer: ' ...<referer> { crlf } .
+
+%field cookie hyttp.cookie "Cookie" FT_STRING .
+%rule cookie = 'Cookie: ' ...<cookie> { crlf } .
+
+%field etag hyttp.etag "Etag" FT_STRING .
+%rule etag = 'Etag: ' ["] [^"]+<etag> ["] crlf .
+
+%field last_modified hyttp.last_modified "Last-Modified" FT_STRING .
+%rule last_modified = 'Last-Modified: ' ...<last_modified> { crlf } .
+
+%field server hyttp.server "Server" FT_STRING .
+%rule server = 'Server: ' ...<server> { crlf } .
-%rule other_header = ([A-Z] [a-zA-Z-]+)<NAME> ": " ...<VALUE> { crlf } .
+%rule other_header = ([A-Z] [a-zA-Z-]+) ": " ... { crlf } .
%field header hyttp.headers.line "HTTP Header Line" FT_BOOLEAN .
%rule header = (
@@ -133,6 +168,17 @@ typedef struct _http_info_value_t
| content_encoding
| user_agent
| host
+ | accept
+ | accept_language
+ | accept_encoding
+ | accept_ranges
+ | keep_alive
+ | connection
+ | referer
+ | cookie
+ | etag
+ | last_modified
+ | server
| other_header)<header:%plain_text> . {
%root header
}
diff --git a/tools/tpg/tpg.pl b/tools/tpg/tpg.pl
index 6c56815076..77cdf45ded 100644
--- a/tools/tpg/tpg.pl
+++ b/tools/tpg/tpg.pl
@@ -302,7 +302,7 @@ sub make_rule {
if (length $tree_code_body ) {
my $cb_name = ${$r}{before_cb_name} = "${$r}{name}\_before_cb";
- ${$r}{before_cb_code} = "static void $cb_name(void* tpg _U_, const void* wd _U_, struct _tvbparse_elem_t* elem _U_) {\n$tree_code_head\n$tree_code_body\n}";
+ ${$r}{before_cb_code} = "static void $cb_name(void* tpg _U_, const void* wd _U_, struct _tvbparse_elem_t* elem _U_) {\n\tproto_item* pi;\n$tree_code_head\n$tree_code_body\n}";
${$r}{code} .= $tree_code_after;
}
@@ -394,7 +394,7 @@ sub make_rule {
} elsif (${$r}{type} eq 'until') {
${$code} .= $indent ."tvbparse_until(0,$wd_data,$before_fn,$after_fn,\n";
$dd++;
- ${$code} .= $indent_more . make_rule(${$r}{subrule},$dd) . ", TRUE)";
+ ${$code} .= $indent_more . make_rule(${$r}{subrule},$dd) . ", FALSE)";
$dd--;
}
@@ -416,7 +416,7 @@ sub make_vars {
my $v = shift;
my $r = shift;
my $base = shift;
-
+
if (exists ${$r}{var}) {
${$v}{${$r}{var}} = $base;
}
@@ -454,7 +454,7 @@ sub make_tree_code {
if (exists ${$r}{tree}) {
$root_var = "root_$fieldname";
- ${$head} .= "\tproto_item* $root_var;\n";
+ ${$head} .= "\tproto_item* $root_var;\n\n";
${$body} .= "\t$root_var = ";
$ett_arr .= "\t&$proto_name\_hfis.ett_$fieldname,\\\n";
$ett_decl .= "\tguint ett_$fieldname; \n";
@@ -463,27 +463,32 @@ sub make_tree_code {
} else {
${$body} .= "\t";
}
+
if (${$f}{type} eq 'FT_STRING') {
- ${$body} .= "TPG_ADD_STRING(tpg,${$f}{vname},$elem);\n";
+ ${$body} .= "\tpi = TPG_ADD_STRING(tpg,${$f}{vname},$elem);\n";
} elsif (${$f}{type} =~ /^FT_UINT/) {
my $fieldvar = "tpg_uint_$fieldname";
${$head} .= "\tguint $fieldvar = TPG_UINT($elem);\n";
- ${$body} .= "TPG_ADD_UINT(tpg,${$f}{vname},$elem,$fieldvar);\n";
+ ${$body} .= "\tpi = TPG_ADD_UINT(tpg,${$f}{vname},$elem,$fieldvar);\n";
} elsif (${$f}{type} =~ /^FT_INT/) {
my $fieldvar = "tpg_int_$fieldname";
${$head} .= "\tgint $fieldvar = TPG_INT($elem);\n";
- ${$body} .= "TPG_ADD_INT(tpg,${$f}{vname},$elem,$fieldvar);\n";
+ ${$body} .= "\tpi = TPG_ADD_INT(tpg,${$f}{vname},$elem,$fieldvar);\n";
} elsif (${$f}{type} eq 'FT_IPV4') {
my $fieldvar = "tpg_ipv4_$fieldname";
${$head} .= "\tguint32 $fieldvar = TPG_IPV4($elem);\n";
- ${$body} .= "TPG_ADD_IPV4(tpg,${$f}{vname},$elem,$fieldvar);\n";
+ ${$body} .= "\tpi = TPG_ADD_IPV4(tpg,${$f}{vname},$elem,$fieldvar);\n";
} elsif (${$f}{type} eq 'FT_IPV6') {
my $fieldvar = "tpg_ipv6_$fieldname";
${$head} .= "\tguint8* $fieldvar = TPG_IPV6($elem);\n";
- ${$body} .= "TPG_ADD_IPV6(tpg,${$f}{vname},$elem,$fieldvar);\n";
+ ${$body} .= "\tpi = TPG_ADD_IPV6(tpg,${$f}{vname},$elem,$fieldvar);\n";
} else {
- ${$body} .= "TPG_ADD_TEXT(tpg,$elem);\n";
+ ${$body} .= "\tpi = TPG_ADD_TEXT(tpg,$elem);\n";
+ }
+
+ if (exists ${$r}{plain_text}) {
+ ${$body} .= "\tTPG_SET_TEXT(pi,$elem);\n"
}
if (exists ${$r}{tree}) {
@@ -525,10 +530,10 @@ sub tokenizer {
[ '([A-Z][A-Z0-9_]*)', sub { [ 'UPPERCASE', $_[0] ] }],
[ '([0-9]+|0x[0-9a-fA-F]+)', sub { [ 'NUMBER', $_[0] ] }],
[ '(\%\%[0-9]+\%\%)', \&c_code ],
- [ "('(\\\\'|[^'])*')", sub { [ 'SQUOTED', $_[0] ] }],
+ [ "'((\\\\'|[^'])*)'", sub { [ 'SQUOTED', $_[0] ] }],
[ '\[\^((\\\\\\]|[^\\]])*)\]', sub { [ 'NOTCHARS', $_[0] ] }],
[ '\[((\\\\\\]|[^\\]])*)\]', sub { [ 'CHARS', $_[0] ] }],
- [ '("(\\\\"|[^"])*")', sub { [ 'DQUOTED', $_[0] ] }],
+ [ '"((\\\\"|[^"])*)"', sub { [ 'DQUOTED', $_[0] ] }],
[ '(\%[a-z_]+|\%[A-Z][A-Z-]*|\=|\.\.\.|\.|\:|\;|\(|\)|\{|\}|\+|\*|\?|\<|\>|\|)', sub { [ $_[0], $_[0] ] }],
]
}
diff --git a/tools/tpg/tpg.yp b/tools/tpg/tpg.yp
index 81bcb4137b..d9282e9208 100644
--- a/tools/tpg/tpg.yp
+++ b/tools/tpg/tpg.yp
@@ -53,6 +53,7 @@ sub from_to {
sub chars_control {
$_ = $_[0];
s/([a-zA-Z0-9])-([a-zA-Z0-9])/from_to($1,$2)/ge;
+ s/"/\\"/g;
"\"$_\"";
}
@@ -71,24 +72,9 @@ statement:
rule_statement {
my $rulename = ${$_[1]}{name};
- if (exists ${${$parser_info}{rules}}{$rulename}) {
-
- my $rule = ${${$parser_info}{rules}}{$rulename};
- if (exists ${${$parser_info}{rules}}{root}) {
- # a root rule exists already add this to its subrules
- push @{${${$parser_info}{rules}}{subrules}}, $_[1];
- } else {
- # this rule becomes the first subrule of a choice
- ${${$parser_info}{rules}}{$rulename} = {
- root=>'',
- type=>'choice',
- subrules=>[$rule,\$_[1]],
- name=>${$_[1]}{name},
- }
- }
- } else {
- ${${$parser_info}{rules}}{$rulename} = $_[1];
- }
+ abort($_[0],"%rule $rulename already defined") if exists ${${$parser_info}{rules}}{$rulename};
+
+ ${${$parser_info}{rules}}{$rulename} = $_[1];
}
| parser_name_statement {
abort($_[0],"%parser_name already defined") if exists ${$parser_info}{name};
@@ -184,7 +170,7 @@ base_rule:
| until_rule
| CHARS {{control=>chars_control($_[1]),type=>'chars'}}
| NOTCHARS {{control=>chars_control($_[1]),type=>'not_chars'}}
- | DQUOTED {{control=>"$_[1]",type=>'string'}}
+ | DQUOTED {{control=>"\"$_[1]\"",type=>'string'}}
| SQUOTED {{control=>"\"$_[1]\"",type=>'caseless'}}
| LOWERCASE {{control=>$_[1],type=>'named'}}
;
@@ -277,7 +263,7 @@ value_string_items:
;
value_string_item:
- NUMBER QUOTED { [ $_[1], "\"$_[2]\"" ] }
+ NUMBER DQUOTED { [ $_[1], "\"$_[2]\"" ] }
;
static_field_statement:
@@ -290,7 +276,7 @@ static_field_statement:
field_name:
#empty {undef}
- | DQUOTED
+ | DQUOTED { "\"$_[1]\""}
;
field_type:
@@ -310,7 +296,7 @@ field_value_string:
field_description:
#empty {'""'}
- | SQUOTED
+ | SQUOTED { "\"$_[1]\""}
;
quoted: DQUOTED | SQUOTED ;