aboutsummaryrefslogtreecommitdiffstats
path: root/asn1/p1/packet-p1-template.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2013-06-28 12:43:29 +0000
committerMichael Mann <mmann78@netscape.net>2013-06-28 12:43:29 +0000
commit9009944d517462a907f8e650988425a45b4babd9 (patch)
tree54af917ad67f985f413019de614520b55649ed8f /asn1/p1/packet-p1-template.c
parentc29fb44886e56322cf4e3663993b803404026e21 (diff)
Remove all global variables in P1 dissector. Bug 8515 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8515)
Added a "subtree context" structure to asn1_ctx_t. This should allow other ASN.1 dissector global variables to be replaced when only used for transferring data between fields in a subtree. svn path=/trunk/; revision=50208
Diffstat (limited to 'asn1/p1/packet-p1-template.c')
-rw-r--r--asn1/p1/packet-p1-template.c126
1 files changed, 94 insertions, 32 deletions
diff --git a/asn1/p1/packet-p1-template.c b/asn1/p1/packet-p1-template.c
index 6335ae450e..a00e384eee 100644
--- a/asn1/p1/packet-p1-template.c
+++ b/asn1/p1/packet-p1-template.c
@@ -58,21 +58,6 @@ static void prefs_register_p1(void); /* forward declaration for use in preferenc
static int proto_p1 = -1;
static int proto_p3 = -1;
-static struct SESSION_DATA_STRUCTURE* session = NULL;
-static int extension_id = -1; /* integer extension id */
-static const char *object_identifier_id = NULL; /* extensions identifier */
-static const char *content_type_id = NULL; /* content type identifier */
-static gboolean report_unknown_content_type = FALSE;
-
-#define MAX_ORA_STR_LEN 256
-static char *oraddress = NULL;
-static char *ddatype = NULL;
-static gboolean doing_address=FALSE;
-static gboolean doing_subjectid=FALSE;
-static proto_item *address_item = NULL;
-
-static proto_tree *top_tree=NULL;
-
static int hf_p1_MTS_APDU_PDU = -1;
static int hf_p1_MTABindArgument_PDU = -1;
static int hf_p1_MTABindResult_PDU = -1;
@@ -103,6 +88,65 @@ static dissector_table_t p1_tokendata_dissector_table;
#include "packet-p1-table.c" /* operation and error codes */
+typedef struct p1_address_ctx {
+ gboolean do_address;
+ const char *content_type_id;
+ gboolean report_unknown_content_type;
+ emem_strbuf_t* oraddress;
+} p1_address_ctx_t;
+
+static void set_do_address(asn1_ctx_t* actx, gboolean do_address)
+{
+ p1_address_ctx_t* ctx;
+
+ if (actx->subtree.tree_ctx == NULL) {
+ actx->subtree.tree_ctx = ep_new0(p1_address_ctx_t);
+ }
+
+ ctx = (p1_address_ctx_t*)actx->subtree.tree_ctx;
+ ctx->do_address = do_address;
+}
+
+static void do_address(const char* address, tvbuff_t* tvb_string, asn1_ctx_t* actx)
+{
+ p1_address_ctx_t* ctx = (p1_address_ctx_t*)actx->subtree.tree_ctx;
+
+ if (ctx && ctx->do_address) {
+ if (address) {
+ ep_strbuf_append(ctx->oraddress, address);
+ }
+ if (tvb_string) {
+ ep_strbuf_append(ctx->oraddress, tvb_format_text(tvb_string, 0, tvb_length(tvb_string)));
+ }
+ }
+
+}
+
+static void do_address_str(const char* address, tvbuff_t* tvb_string, asn1_ctx_t* actx)
+{
+ emem_strbuf_t *ddatype = (emem_strbuf_t *)actx->value_ptr;
+ p1_address_ctx_t* ctx = (p1_address_ctx_t*)actx->subtree.tree_ctx;
+
+ do_address(address, tvb_string, actx);
+
+ if (ctx && ctx->do_address && ddatype && tvb_string)
+ ep_strbuf_append(ddatype, tvb_format_text(tvb_string, 0, tvb_length(tvb_string)));
+}
+
+static void do_address_str_tree(const char* address, tvbuff_t* tvb_string, asn1_ctx_t* actx, proto_tree* tree)
+{
+ emem_strbuf_t *ddatype = (emem_strbuf_t *)actx->value_ptr;
+ p1_address_ctx_t* ctx = (p1_address_ctx_t*)actx->subtree.tree_ctx;
+
+ do_address(address, tvb_string, actx);
+
+ if (ctx && ctx->do_address && tvb_string && ddatype) {
+ if (ddatype->len > 0) {
+ proto_item_append_text (tree, " (%%s=%%s)", ddatype->str, tvb_format_text(tvb_string, 0, tvb_length(tvb_string)));
+ }
+ }
+}
+
#include "packet-p1-fn.c"
#include "packet-p1-table11.c" /* operation argument/result dissectors */
@@ -118,17 +162,34 @@ static const ros_info_t p3_ros_info = {
p3_err_tab
};
-void p1_initialize_content_globals (proto_tree *tree, gboolean report_unknown_cont_type)
+void p1_initialize_content_globals (asn1_ctx_t* actx, proto_tree *tree, gboolean report_unknown_cont_type)
{
- top_tree = tree;
- content_type_id = NULL;
- report_unknown_content_type = report_unknown_cont_type;
- address_item = NULL;
+ p1_address_ctx_t* ctx;
+
+ if (actx->subtree.tree_ctx == NULL) {
+ actx->subtree.tree_ctx = ep_new0(p1_address_ctx_t);
+ }
+
+ ctx = (p1_address_ctx_t*)actx->subtree.tree_ctx;
+
+ actx->subtree.top_tree = tree;
+ actx->external.direct_reference = NULL;
+ ctx->content_type_id = NULL;
+ ctx->report_unknown_content_type = report_unknown_cont_type;
}
-char* p1_get_last_oraddress (void)
-{
- return oraddress;
+char* p1_get_last_oraddress (asn1_ctx_t* actx)
+{
+ p1_address_ctx_t* ctx;
+
+ if ((actx == NULL) || (actx->subtree.tree_ctx == NULL))
+ return "";
+
+ ctx = (p1_address_ctx_t*)actx->subtree.tree_ctx;
+ if (ctx->oraddress->len <= 0)
+ return "";
+
+ return ctx->oraddress->str;
}
/*
@@ -143,7 +204,7 @@ dissect_p1_mts_apdu (tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
/* save parent_tree so subdissectors can create new top nodes */
- p1_initialize_content_globals (parent_tree, TRUE);
+ p1_initialize_content_globals (&asn1_ctx, parent_tree, TRUE);
if(parent_tree){
item = proto_tree_add_item(parent_tree, proto_p1, tvb, 0, -1, ENC_NA);
@@ -154,7 +215,7 @@ dissect_p1_mts_apdu (tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
col_set_str(pinfo->cinfo, COL_INFO, "Transfer");
dissect_p1_MTS_APDU (FALSE, tvb, 0, &asn1_ctx, tree, hf_p1_MTS_APDU_PDU);
- p1_initialize_content_globals (NULL, FALSE);
+ p1_initialize_content_globals (&asn1_ctx, NULL, FALSE);
}
/*
@@ -167,6 +228,7 @@ dissect_p1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
int old_offset;
proto_item *item=NULL;
proto_tree *tree=NULL;
+ struct SESSION_DATA_STRUCTURE* session;
int (*p1_dissector)(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, asn1_ctx_t *actx _U_, proto_tree *tree, int hf_index _U_) = NULL;
const char *p1_op_name;
int hf_p1_index = -1;
@@ -174,7 +236,7 @@ dissect_p1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
/* save parent_tree so subdissectors can create new top nodes */
- p1_initialize_content_globals (parent_tree, TRUE);
+ p1_initialize_content_globals (&asn1_ctx, parent_tree, TRUE);
/* do we have operation information from the ROS dissector? */
if( !pinfo->private_data ){
@@ -182,17 +244,17 @@ dissect_p1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
proto_tree_add_text(parent_tree, tvb, offset, -1,
"Internal error: can't get operation information from ROS dissector.");
}
- return ;
- } else {
- session = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
+ return;
}
+ session = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
+
if(parent_tree){
item = proto_tree_add_item(parent_tree, proto_p1, tvb, 0, -1, ENC_NA);
tree = proto_item_add_subtree(item, ett_p1);
}
col_set_str(pinfo->cinfo, COL_PROTOCOL, "P1");
- col_clear(pinfo->cinfo, COL_INFO);
+ col_clear(pinfo->cinfo, COL_INFO);
switch(session->ros_op & ROS_OP_MASK) {
case (ROS_OP_BIND | ROS_OP_ARGUMENT): /* BindInvoke */
@@ -230,7 +292,7 @@ dissect_p1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
break;
}
}
- p1_initialize_content_globals (NULL, FALSE);
+ p1_initialize_content_globals (&asn1_ctx, NULL, FALSE);
}
@@ -240,7 +302,7 @@ void proto_register_p1(void) {
/* List of fields */
static hf_register_info hf[] =
{
- /* "Created by defining PDU in .cnf */
+ /* "Created by defining PDU in .cnf */
{ &hf_p1_MTABindArgument_PDU,
{ "MTABindArgument", "p1.MTABindArgument",
FT_UINT32, BASE_DEC, VALS(p1_MTABindArgument_vals), 0,