Make the corresponding packet_info available to each tree item. This
authorGerald Combs <gerald@wireshark.org>
Fri, 10 Aug 2012 20:33:01 +0000 (20:33 -0000)
committerGerald Combs <gerald@wireshark.org>
Fri, 10 Aug 2012 20:33:01 +0000 (20:33 -0000)
lets us pass a NULL pinfo to expert_add_info_format() and
expert_add_undecoded_item(), which makes it possible to use those
routines deep in the bowels of many dissectors. As a proof of concept
remove the recent pinfo additions to packet-afp.c. This should also make
it easier to fix bug 3884.

svn path=/trunk/; revision=44435

epan/dissectors/packet-afp.c
epan/dissectors/packet-ncp2222.inc
epan/epan.c
epan/expert.c
epan/expert.h
epan/proto.c
epan/proto.h

index 53b7dfb146d6805af780ef89a52c6664827a4214..8f55ba40cc247275f77bd52afcf6a1f57f5cb1d4 100644 (file)
@@ -4666,7 +4666,7 @@ decode_kauth_ace(tvbuff_t *tvb, proto_tree *tree, gint offset)
 
 #define AFP_MAX_ACL_ENTRIES 500 /* Arbitrary. */
 static gint
-decode_kauth_acl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
+decode_kauth_acl(tvbuff_t *tvb, proto_tree *tree, gint offset)
 {
        int         entries;
        int         i;
@@ -4681,11 +4681,11 @@ decode_kauth_acl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offse
        sub_tree = proto_item_add_subtree(item, ett_afp_ace_entries);
        offset += 4;
 
-       item = proto_tree_add_item(tree, hf_afp_acl_flags, tvb, offset, 4, ENC_BIG_ENDIAN);
+       proto_tree_add_item(tree, hf_afp_acl_flags, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
 
        if (entries > AFP_MAX_ACL_ENTRIES) {
-               expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN, "Too many ACL entries (%u). Stopping dissection.", entries);
+               expert_add_info_format(NULL, item, PI_UNDECODED, PI_WARN, "Too many ACL entries (%u). Stopping dissection.", entries);
                THROW(ReportedBoundsError);
        }
 
@@ -4700,7 +4700,7 @@ decode_kauth_acl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offse
 }
 
 static gint
-decode_uuid_acl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset, guint16 bitmap)
+decode_uuid_acl(tvbuff_t *tvb, proto_tree *tree, gint offset, guint16 bitmap)
 {
        if ((offset & 1))
                PAD(1);
@@ -4716,7 +4716,7 @@ decode_uuid_acl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset
        }
 
        if ((bitmap & kFileSec_ACL)) {
-               offset = decode_kauth_acl(tvb, pinfo, tree, offset);
+               offset = decode_kauth_acl(tvb, tree, offset);
        }
 
        return offset;
@@ -4736,7 +4736,7 @@ dissect_query_afp_set_acl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, g
 
        offset = decode_name(tree, pinfo, tvb, offset);
 
-       offset = decode_uuid_acl(tvb, pinfo, tree, offset, bitmap);
+       offset = decode_uuid_acl(tvb, tree, offset, bitmap);
 
        return offset;
 }
@@ -4768,7 +4768,7 @@ dissect_reply_afp_get_acl(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tre
        bitmap = decode_acl_list_bitmap(tvb, tree, offset);
        offset += 2;
 
-       offset = decode_uuid_acl(tvb, pinfo, tree, offset, bitmap);
+       offset = decode_uuid_acl(tvb, tree, offset, bitmap);
 
        return offset;
 }
@@ -6550,7 +6550,7 @@ proto_register_afp(void)
 
                { &hf_afp_acl_entrycount,
                  { "ACEs count",         "afp.acl_entrycount",
-                   FT_UINT32, BASE_DEC, NULL, 0,
+                   FT_UINT32, BASE_HEX, NULL, 0,
                    "Number of ACL entries", HFILL }},
 
                { &hf_afp_acl_flags,
index 7b676f9622603200a46fc728791262cab2dde5dc..dba265c1a4cc72cb351b699e84c1bee125433624 100644 (file)
@@ -7510,7 +7510,7 @@ dissect_ncp_request(tvbuff_t *tvb, packet_info *pinfo,
     if ((run_info_str || run_req_cond) && !ncp_tree) {
         proto_item *ti;
 
-        temp_tree = proto_tree_create_root();
+        temp_tree = proto_tree_create_root(pinfo);
         proto_tree_set_visible(temp_tree, FALSE);
         ti = proto_tree_add_item(temp_tree, proto_ncp, tvb, 0, -1, FALSE);
         ncp_tree = proto_item_add_subtree(ti, ett_ncp);
@@ -11538,7 +11538,7 @@ dissect_nds_request(tvbuff_t *tvb, packet_info *pinfo,
     if ((run_info_str || run_req_cond) && !ncp_tree) {
         proto_item *ti;
 
-        temp_tree = proto_tree_create_root();
+        temp_tree = proto_tree_create_root(pinfo);
         proto_tree_set_visible(temp_tree, FALSE);
         ti = proto_tree_add_item(temp_tree, proto_ncp, tvb, 0, -1, FALSE);
         ncp_tree = proto_item_add_subtree(ti, ett_ncp);
@@ -11854,7 +11854,7 @@ dissect_ping_req(tvbuff_t *tvb, packet_info *pinfo,
         if (ncp_rec && !ncp_tree) {
             proto_item *ti;
 
-            temp_tree = proto_tree_create_root();
+            temp_tree = proto_tree_create_root(pinfo);
             proto_tree_set_visible(temp_tree, FALSE);
             ti = proto_tree_add_item(temp_tree, proto_ncp, tvb, 0, -1, FALSE);
             ncp_tree = proto_item_add_subtree(ti, ett_ncp);
@@ -12005,4 +12005,3 @@ dissect_ping_req(tvbuff_t *tvb, packet_info *pinfo,
         CLEANUP_CALL_AND_POP;
     }
 }
-
index 28b583a21848adb80df68f120e42c3fe113ab6a1..9b5840069c746304710c7b00f2f33e5b30257b4e 100644 (file)
@@ -168,7 +168,7 @@ epan_dissect_init(epan_dissect_t *edt, const gboolean create_proto_tree, const g
        g_assert(edt);
 
        if (create_proto_tree) {
-               edt->tree = proto_tree_create_root();
+               edt->tree = proto_tree_create_root(&edt->pi);
                proto_tree_set_visible(edt->tree, proto_tree_visible);
        }
        else {
index 147537b0dc9725aa3ab47b1d22cfa4ef09f48d53..414b42320ae32f9b6cc986ced28b315e87bedb5d 100644 (file)
@@ -166,6 +166,10 @@ expert_set_info_vformat(packet_info *pinfo, proto_item *pi, int group, int sever
        proto_tree      *tree;
        proto_item      *ti;
 
+       if (pinfo == NULL && pi->tree_data) {
+               pinfo = PTREE_DATA(pi)->pinfo;
+       }
+
        /* if this packet isn't loaded because of a read filter, don't output anything */
        if (pinfo == NULL || PINFO_FD_NUM(pinfo) == 0) {
                return;
@@ -232,7 +236,7 @@ void
 expert_add_undecoded_item(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, int length, const int severity)
 {
 
-       proto_item *expert_item; 
+       proto_item *expert_item;
 
        expert_item = proto_tree_add_text(tree, tvb, offset, length, "Not dissected yet");
 
@@ -240,4 +244,3 @@ expert_add_undecoded_item(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, i
        PROTO_ITEM_SET_GENERATED(expert_item); \
 
 }
-
index 4db64ad66f87ed02c33d10f4a28d53063200b52c..86478bb66dc2b95d2775f109f50854b80a1133cc 100644 (file)
@@ -63,11 +63,12 @@ expert_get_highest_severity(void);
 
 /** Add an expert info.
  Add an expert info tree to a protocol item, with classification and message.
- @param pinfo packet info of the currently processed packet
- @param pi current protocol item (or NULL)
- @param group the expert group (like PI_CHECKSUM - see: proto.h)
- @param severity the expert severity (like PI_WARN - see: proto.h)
- @param format printf like format string with further infos
+ @param pinfo Packet info of the currently processed packet. May be NULL if
+        pi is supplied
+ @param pi Current protocol item (or NULL)
+ @param group The expert group (like PI_CHECKSUM - see: proto.h)
+ @param severity The expert severity (like PI_WARN - see: proto.h)
+ @param format Printf-style format string for additional arguments
  */
 extern void
 expert_add_info_format(packet_info *pinfo, proto_item *pi, int group,
@@ -76,12 +77,12 @@ expert_add_info_format(packet_info *pinfo, proto_item *pi, int group,
 
 /** Add an expert info about not dissected "item"
  Add an expert info tree to a not dissected protocol item.
- @patam tvb the tvb with the item.
- @param pinfo packet info of the currently processed packet
- @param tree tree to add the item to
- @param offset in tvb
- @param length the length of the item.
- @param severity the expert severity (like PI_WARN - see: proto.h)
+ @patam tvb The tvb associated with the item.
+ @param pinfo Packet info of the currently processed packet. May be NULL.
+ @param tree Tree to add the item to
+ @param offset Offset in tvb
+ @param length The length of the item.
+ @param severity The expert severity (like PI_WARN - see: proto.h)
   */
 
 extern void
index 6bb833d0072d4caec64f44b086b63d5219a561d9..a024176a79898bfeb07ecbed8d82891427ed558a 100644 (file)
@@ -4186,7 +4186,7 @@ proto_item_set_expert_flags(proto_item *pi, const int group, const guint severit
 }
 
 proto_tree *
-proto_tree_create_root(void)
+proto_tree_create_root(packet_info *pinfo)
 {
        proto_node *pnode;
 
@@ -4196,6 +4196,9 @@ proto_tree_create_root(void)
        PNODE_FINFO(pnode) = NULL;
        pnode->tree_data = g_new(tree_data_t, 1);
 
+       /* Make sure we can access pinfo everywhere */
+       pnode->tree_data->pinfo = pinfo;
+
        /* Don't initialize the tree_data_t. Wait until we know we need it */
        pnode->tree_data->interesting_hfids = NULL;
 
index 541212527959f4d153c4ea9d2003a7f3233dc1e6..5a689ee84633693895ff0cec7dcda2c7d6ec1798 100644 (file)
@@ -467,9 +467,10 @@ typedef struct
  * in the protocol tree points to the same copy. */
 typedef struct {
     GHashTable  *interesting_hfids;
-    gboolean    visible;
-    gboolean    fake_protocols;
-    gint        count;
+    gboolean     visible;
+    gboolean     fake_protocols;
+    gint         count;
+    struct _packet_info *pinfo;
 } tree_data_t;
 
 /** Each proto_tree, proto_item is one of these. */
@@ -697,7 +698,7 @@ extern gboolean proto_item_set_expert_flags(proto_item *ti, const int group, con
 
 /** Creates a new proto_tree root.
  @return the new tree root */
-extern proto_tree* proto_tree_create_root(void);
+extern proto_tree* proto_tree_create_root(struct _packet_info *pinfo);
 
 /** Clear memory for entry proto_tree. Clears proto_tree struct also.
  @param tree the tree to free */