aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--epan/tpg.c3
-rw-r--r--epan/tpg.h2
-rw-r--r--epan/tvbparse.c10
-rw-r--r--plugins/tpg/http.tpg70
-rw-r--r--plugins/tpg/packet-http.c5
-rw-r--r--tools/tpg/tpg.yp15
6 files changed, 69 insertions, 36 deletions
diff --git a/epan/tpg.c b/epan/tpg.c
index 2813b795c0..5a29b8ba4a 100644
--- a/epan/tpg.c
+++ b/epan/tpg.c
@@ -47,10 +47,11 @@ extern tpg_parser_data_t* tpg_start(proto_tree* root_tree,
tvbuff_t* tvb,
int offset,
int len,
+ tvbparse_wanted_t* ignore,
void* private_data) {
tpg_parser_data_t* tpg = ep_alloc(sizeof(tpg_parser_data_t));
tpg->private_data = private_data;
- tpg->tt = tvbparse_init(tvb,offset,len,tpg,NULL);
+ tpg->tt = tvbparse_init(tvb,offset,len,tpg,ignore);
tpg->stack = ep_stack_new();
ep_stack_push(tpg->stack,root_tree);
diff --git a/epan/tpg.h b/epan/tpg.h
index 84b3ba02f0..4f0170e755 100644
--- a/epan/tpg.h
+++ b/epan/tpg.h
@@ -45,7 +45,9 @@ extern tpg_parser_data_t* tpg_start(proto_tree* root_tree,
tvbuff_t* tvb,
int offset,
int len,
+ tvbparse_wanted_t* ignore,
void* private_data);
+
#define TPG_START(tree,tvb,offset,len,data) tpg_start((tree),(tvb),(offset),(len),(data))
#define TPG_GET(tpg, wanted) tvbparse_get((tpg)->tt,(wanted))
diff --git a/epan/tvbparse.c b/epan/tvbparse.c
index f6950e75fa..78dbffbde2 100644
--- a/epan/tvbparse.c
+++ b/epan/tvbparse.c
@@ -663,7 +663,7 @@ tvbparse_elem_t* tvbparse_get(tvbparse_t* tt,
tvbparse_wanted_t* w = g_ptr_array_index(wanted->elems,0);
if ( wanted->min == 0 ) {
- new_tok(tt,wanted->id,tt->offset,0,wanted);
+ tok = new_tok(tt,wanted->id,tt->offset,0,wanted);
}
while (got_so_far < wanted->max) {
@@ -672,8 +672,12 @@ tvbparse_elem_t* tvbparse_get(tvbparse_t* tt,
if(new) {
if (tok) {
tok->len = (new->offset - tok->offset) + new->len;
- tok->sub->last->next = new;
- tok->sub->last = new;
+ if (tok->sub) {
+ tok->sub->last->next = new;
+ tok->sub->last = new;
+ } else {
+ tok->sub = new;
+ }
} else {
tok = new_tok(tt, wanted->id, new->offset, new->len, wanted);
tok->sub = new;
diff --git a/plugins/tpg/http.tpg b/plugins/tpg/http.tpg
index 9bc45d7537..790f1cf065 100644
--- a/plugins/tpg/http.tpg
+++ b/plugins/tpg/http.tpg
@@ -39,8 +39,7 @@ typedef struct _http_info_value_t
%}
%parser_name http .
-%export req_resp header crlf .
-
+%export req_resp header crlf sp.
%tt_type %{ http_info_value_t %}
@@ -57,7 +56,7 @@ typedef struct _http_info_value_t
%field response hyttp.response "Response" FT_STRING .
%field response_code hyttp.response.code "Response Code" FT_UINT32 BASE_DEC %{ http_response_codes %} .
-%sequence %tree response = http_version & sp & [0-9]+<response_code:RESPONSE> & ... ( crlf ) . <response:%plain_text> %{
+%sequence %tree response = http_version & [0-9]+<response_code:RESPONSE> & ... ( crlf ) . <response:%plain_text> %{
TT_DATA->is_response = TRUE;
TT_DATA->response_code = TPG_UINT(RESPONSE);
%}
@@ -66,7 +65,7 @@ typedef struct _http_info_value_t
%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 .
-%sequence %tree request = [A-Z]+<method:METHOD> & sp & [^ ]+<uri:URI> & sp & http_version & crlf . <request:%plain_text> %{
+%sequence %tree request = [A-Z]+<method:METHOD> & [^ ]+<uri:URI> & http_version & crlf . <request:%plain_text> %{
TT_DATA->is_response = FALSE;
TT_DATA->request_method = TPG_STRING(METHOD);
TT_DATA->request_uri = TPG_STRING(URI);
@@ -76,82 +75,95 @@ typedef struct _http_info_value_t
%field media hyttp.content_type.media "Content-Type Media" FT_STRING .
-%sequence media = [a-z]+ & "/" & [a-z]+ . <media:MEDIA> %{
+%sequence media = [a-zA-Z0-9-]+ & "/" & [a-zA-Z0-9-]+ . <media:MEDIA> %{
TT_DATA->media = TPG_STRING(MEDIA);
%}
-%sequence content_type_value = media & ... ( crlf %leave ) . <content_type>
-%field content_type hyttp.content_type "Content-Type" FT_STRING .
-%sequence content_type_hdr = 'Content-type: ' & content_type_value & crlf .
+%sequence quoted_string = ["] & [^"]* & ["] .
+
+%choice value = [a-zA-Z0-9-]+ | quoted_string.
+
+%field charset hyttp.content_type.charset "Content-Type Charset" FT_STRING .
+
+%sequence parameter = [a-zA-Z0-9-]+ & [=] & value.
+%sequence charset_parameter = 'charset' & '=' & [a-z0-9-]+<charset> .
+
+%choice content_type_param = charset_parameter | parameter .
+
+%sequence content_type_params = [;] & content_type_param .
+
+%sequence content_type_value = media & content_type_params* .
+
+%sequence content_type_hdr = 'Content-type:' & content_type_value & crlf .
%field content_length hyttp.headers.content_length "Content-Length" FT_UINT32 BASE_DEC .
-%sequence content_length = 'Content-length: ' & [0-9]+<content_length:LENGTH> & crlf. %{
+%sequence content_length = 'Content-length:' & [0-9]+<content_length:LENGTH> & crlf. %{
TT_DATA->content_length = TPG_UINT(LENGTH);
%}
%field transfer_encoding hyttp.transfer_encoding "Transfer-Encoding" FT_STRING .
-%sequence transfer_encoding = 'Transfer-encoding: ' & ...<transfer_encoding:ENCODING> ( crlf %leave ) & crlf. %{
+%sequence transfer_encoding = 'Transfer-encoding:' & ...<transfer_encoding:ENCODING> ( crlf %leave ) & crlf. %{
TT_DATA->transfer_encoding = TPG_STRING(ENCODING);
%}
%field authorization hyttp.authorization "Authorization" FT_STRING .
-%sequence authorization = 'Authorization: ' & ...<authorization> ( crlf %leave ) & crlf.
+%sequence authorization = 'Authorization:' & ...<authorization> ( crlf %leave ) & crlf.
%field proxy_authorization hyttp.proxy_authorization "Proxy-Authorization" FT_STRING .
-%sequence proxy_author = 'Proxy-authorization: ' & ...<proxy_authorization> ( crlf %leave ) & crlf.
+%sequence proxy_author = 'Proxy-authorization:' & ...<proxy_authorization> ( crlf %leave ) & crlf.
%field proxy_authen hyttp.proxy_authenti "Proxy-Authenticate" FT_STRING .
-%sequence proxy_authen = 'Proxy-authenticate: ' & ...<proxy_authen> ( crlf %leave ) & crlf.
+%sequence proxy_authen = 'Proxy-authenticate:' & ...<proxy_authen> ( crlf %leave ) & crlf.
%field www_auth hyttp.www_authenticate "WWW-Authenticate" FT_STRING .
-%sequence www_auth = 'WWW-authenticate: ' & ...<www_auth> ( crlf %leave ) & crlf.
+%sequence www_auth = 'WWW-authenticate:' & ...<www_auth> ( crlf %leave ) & crlf.
%field content_encoding hyttp.content_encoding "Content-Encoding" FT_STRING .
-%sequence content_encoding = 'Content-Encoding: ' & ...<content_encoding> ( crlf %leave ) & crlf.
+%sequence content_encoding = 'Content-Encoding:' & ...<content_encoding> ( crlf %leave ) & crlf.
%field user_agent hyttp.content_encoding "User-Agent" FT_STRING .
-%sequence user_agent = 'User-Agent: ' & ...<user_agent> ( crlf %leave ) & crlf.
+%sequence user_agent = 'User-Agent:' & ...<user_agent> ( crlf %leave ) & crlf.
%field host hyttp.host "Host" FT_STRING .
-%sequence host = 'Host: ' & ...<host:HOST> ( crlf %leave ) & crlf. %{
+%sequence host = 'Host:' & ...<host:HOST> ( crlf %leave ) & crlf. %{
TT_DATA->http_host = TPG_STRING(HOST);
%}
%field accept hyttp.accept "Accept" FT_STRING .
-%sequence accept = 'Accept: ' & ...<accept> ( crlf %leave ) & crlf.
+%sequence accept = 'Accept:' & ...<accept> ( crlf %leave ) & crlf.
%field accept_language hyttp.accept_language "Accept-Language" FT_STRING .
-%sequence accept_language = 'Accept-language: ' & ...<accept_language> ( crlf %leave ) & crlf.
+%sequence accept_language = 'Accept-language:' & ...<accept_language> ( crlf %leave ) & crlf.
%field accept_encoding hyttp.accept_encoding "Accept-Language" FT_STRING .
-%sequence accept_encoding = 'Accept-encoding: ' & ...<accept_encoding> ( crlf %leave ) & crlf.
+%sequence accept_encoding = 'Accept-encoding:' & ...<accept_encoding> ( crlf %leave ) & crlf.
%field accept_ranges hyttp.accept_encoding "Accept-Ranges" FT_STRING .
-%sequence accept_ranges = 'Accept-Ranges: ' & ...<accept_ranges> ( crlf %leave ) & crlf.
+%sequence accept_ranges = 'Accept-Ranges:' & ...<accept_ranges> ( crlf %leave ) & crlf.
%field keep_alive hyttp.keep_alive "Keep-Alive" FT_UINT32 BASE_DEC .
-%sequence keep_alive = 'Keep-Alive: ' & ...<keep_alive> ( crlf %leave ) & crlf.
+%sequence keep_alive = 'Keep-Alive:' & ...<keep_alive> ( crlf %leave ) & crlf.
%field connection hyttp.connection "Connection" FT_STRING .
-%sequence connection = 'Connection: ' & ...<connection> ( crlf %leave ) & crlf.
+%sequence connection = 'Connection:' & ...<connection> ( crlf %leave ) & crlf.
%field referer hyttp.referer "Referer" FT_STRING .
-%sequence referer = 'Referer: ' & ...<referer> ( crlf %leave ) & crlf.
+%sequence referer = 'Referer:' & ...<referer> ( crlf %leave ) & crlf.
%field cookie hyttp.cookie "Cookie" FT_STRING .
-%sequence cookie = 'Cookie: ' & ...<cookie> ( crlf %leave ) & crlf.
+%sequence cookie = 'Cookie:' & ...<cookie> ( crlf %leave ) & crlf.
%field etag hyttp.etag "Etag" FT_STRING .
-%sequence etag = 'Etag: ' & ["] & [^"]+<etag> & ["] & crlf .
+%sequence etag = 'Etag:' & ["] & [^"]+<etag> & ["] & crlf .
%field last_modified hyttp.last_modified "Last-Modified" FT_STRING .
-%sequence last_modified = 'Last-Modified: ' & ...<last_modified> ( crlf %leave ) & crlf.
+%sequence last_modified = 'Last-Modified:' & ...<last_modified> ( crlf %leave ) & crlf.
%field server hyttp.server "Server" FT_STRING .
-%sequence server = 'Server: ' & ...<server> ( crlf %leave ) & crlf.
+%sequence server = 'Server:' & ...<server> ( crlf %leave ) & crlf.
-%sequence other_header = [A-Z] & [a-zA-Z-]+ & ": " & ... ( crlf %leave ) & crlf.
+%sequence other_header = [A-Z] & [a-zA-Z-]+ & ":" & ... ( crlf %leave ) & crlf.
%field header hyttp.headers.line "HTTP Header Line" FT_BOOLEAN .
%choice %tree header =
diff --git a/plugins/tpg/packet-http.c b/plugins/tpg/packet-http.c
index c37ea25235..c54df654bc 100644
--- a/plugins/tpg/packet-http.c
+++ b/plugins/tpg/packet-http.c
@@ -33,12 +33,13 @@ static void dissect_http(tvbuff_t* tvb, packet_info* pinfo _U_, proto_tree* tree
proto_item* pi = proto_tree_add_item(tree,proto_http,tvb,0,-1,FALSE);
proto_tree* pt = proto_item_add_subtree(pi,ett_http);
- tpg = tpg_start(pt,tvb,0,-1,msgdata);
+ tpg = tpg_start(pt,tvb,0,-1,http_tpg_data.wanted_http_sp, msgdata);
if (( reqresp = TPG_GET(tpg,http_tpg_data.wanted_http_req_resp) )) {
tvbparse_elem_t* hdr;
- while(( hdr = TPG_GET(tpg,http_tpg_data.wanted_http_header) )) ;
+ while(( hdr = TPG_GET(tpg,http_tpg_data.wanted_http_header) ))
+ ;
if ( TPG_GET(tpg,http_tpg_data.wanted_http_crlf) ) {
pi = proto_tree_add_boolean(pt,hf_http_is_response,tvb,0,0,msgdata->is_response);
diff --git a/tools/tpg/tpg.yp b/tools/tpg/tpg.yp
index 983d587d3f..98b7e9556c 100644
--- a/tools/tpg/tpg.yp
+++ b/tools/tpg/tpg.yp
@@ -50,10 +50,16 @@ sub from_to {
$b;
}
+
+sub to_hexesc {
+ sprintf "\\x%.2x", unpack("C",$_[0]);
+}
+
sub chars_control {
$_ = $_[0];
s/([a-zA-Z0-9])-([a-zA-Z0-9])/from_to($1,$2)/ge;
s/"/\\"/g;
+ s/\\(.)/to_hexesc($1)/ge;
"\"$_\"";
}
@@ -113,6 +119,13 @@ statement:
abort($_[0],"%value_string $name already defined") if exists ${${$parser_info}{vs}}{$name};
${${$parser_info}{vs}}{$name} = $_[1];
}
+ | ignore_statement {
+ ${$parser_info}{ignore} = $_[1];
+ }
+ ;
+
+ignore_statement:
+ '%ignore' LOWERCASE {$_[2]}
;
rule_statement:
@@ -151,7 +164,7 @@ tree:
complete_rule:
base_rule cardinality qualification {hj($_[1],hj($_[2],$_[3]))}
- | named_rule
+ | named_rule cardinality { hj($_[1],$_[2]) }
| until_rule
;