TRY_TO_FAKE_THIS_ITEM now fakes FT_PROTOCOL per default. If there are any users ...
authorKovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>
Tue, 11 Aug 2009 18:08:03 +0000 (18:08 -0000)
committerKovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>
Tue, 11 Aug 2009 18:08:03 +0000 (18:08 -0000)
Also make use of TRY_TO_FAKE_THIS_ITEM in proto_tree_add_text_node(), proto_tree_add_none_format() and proto_tree_add_protocol_format().

svn path=/trunk/; revision=29380

epan/epan.c
epan/epan.h
epan/libwireshark.def
epan/proto.c
epan/proto.h
proto_hier_stats.c

index de33d7a4d951ef42a1c1af1a84e659040a57e86e..7c088914d37b1fc729cead88b215e5b15a4b942c 100644 (file)
@@ -162,6 +162,13 @@ epan_dissect_new(gboolean create_proto_tree, gboolean proto_tree_visible)
        return edt;
 }
 
+void
+epan_dissect_fake_protocols(epan_dissect_t *edt, gboolean fake_protocols)
+{
+       if (edt)
+               proto_tree_set_fake_protocols(edt->tree, fake_protocols);
+}
+
 void
 epan_dissect_run(epan_dissect_t *edt, void* pseudo_header,
         const guint8* data, frame_data *fd, column_info *cinfo)
index d70c6139087e733f83bc5b3b7cfc0da6cb5a8129..2d5396f4cd2ef274eb0495f90eba1ddd3988c4bf 100644 (file)
@@ -90,6 +90,10 @@ epan_get_version(void);
 epan_dissect_t*
 epan_dissect_new(gboolean create_proto_tree, gboolean proto_tree_visible);
 
+/* Indicate whether we should fake protocols or not */
+void
+epan_dissect_fake_protocols(epan_dissect_t *edt, gboolean fake_protocols);
+
 /* run a single packet dissection */
 void
 epan_dissect_run(epan_dissect_t *edt, void* pseudo_header,
index 0e9a36c137a73fb6805a1cf9eb1820be8953e65a..1b52d4265185a60824ec65738793487f5b031a6d 100644 (file)
@@ -353,6 +353,7 @@ ep_strsplit
 ep_tvb_memdup
 epan_base64_decode
 epan_cleanup
+epan_dissect_fake_protocols
 epan_dissect_fill_in_columns
 epan_dissect_free
 epan_dissect_new
index 4d89ebceea9ad861b357ebb1587948edc5f2acf9..63a61401e04aefa7f2be3346748898de85ce44b7 100644 (file)
@@ -94,15 +94,16 @@ wrs_count_bitshift(guint32 bitmask)
           DONT try to fake a node where PTREE_FINFO(tree) is NULL      \
           since dissectors that want to do proto_item_set_len() or     \
           other operations that dereference this would crash.          \
-          We dont fake FT_PROTOCOL either since these are cheap and    \
-          some stuff (proto hier stat) assumes they always exist.      \
+          We fake FT_PROTOCOL unless some clients have requested us    \
+          not to do so. \
        */                                                              \
        if(!(PTREE_DATA(tree)->visible)){                               \
                if(PTREE_FINFO(tree)){                                  \
                        register header_field_info *hfinfo;             \
                        PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo);       \
                        if((hfinfo->ref_count == HF_REF_TYPE_NONE)      \
-                       && (hfinfo->type!=FT_PROTOCOL)){                \
+                       && (hfinfo->type!=FT_PROTOCOL ||        \
+                               PTREE_DATA(tree)->fake_protocols)){     \
                                /* just return tree back to the caller */\
                                return tree;                            \
                        }                                               \
@@ -608,6 +609,12 @@ proto_tree_set_visible(proto_tree *tree, gboolean visible)
        PTREE_DATA(tree)->visible = visible;
 }
 
+void
+proto_tree_set_fake_protocols(proto_tree *tree, gboolean fake_protocols)
+{
+       PTREE_DATA(tree)->fake_protocols = fake_protocols;
+}
+
 /* Assume dissector set only its protocol fields.
    This function is called by dissectors and allowes to speed up filtering
    in wireshark, if this function returns FALSE it is safe to reset tree to NULL
@@ -939,6 +946,11 @@ proto_tree_add_text_node(proto_tree *tree, tvbuff_t *tvb, gint start, gint lengt
 {
        proto_item      *pi;
 
+       if (!tree)
+               return(NULL);
+
+       TRY_TO_FAKE_THIS_ITEM(tree, hf_text_only);
+
        pi = proto_tree_add_pi(tree, hf_text_only, tvb, start, &length, NULL);
        if (pi == NULL)
                return(NULL);
@@ -1420,6 +1432,8 @@ proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint st
        if (!tree)
                return (NULL);
 
+       TRY_TO_FAKE_THIS_ITEM(tree, hfindex);
+
        PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo);
        DISSECTOR_ASSERT(hfinfo->type == FT_NONE);
 
@@ -1475,6 +1489,8 @@ proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gin
        if (!tree)
                return (NULL);
 
+       TRY_TO_FAKE_THIS_ITEM(tree, hfindex);
+
        PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo);
        DISSECTOR_ASSERT(hfinfo->type == FT_PROTOCOL);
 
@@ -3313,6 +3329,9 @@ proto_tree_create_root(void)
         * changed, then we'll find out very quickly. */
        pnode->tree_data->visible = FALSE;
 
+       /* Make sure that we fake protocols (if possible) */
+       pnode->tree_data->fake_protocols = TRUE;
+
        /* Keep track of the number of children */
        pnode->tree_data->count = 0;
 
index 37aebef0277c5ba72d9f27b66472aaa0d5a6727a..8b74613f94fe4a206da3a889a32cfbc0d94b063d 100644 (file)
@@ -256,6 +256,7 @@ typedef struct field_info {
 typedef struct {
     GHashTable  *interesting_hfids;
     gboolean    visible;
+    gboolean    fake_protocols;
     gint        count;
 } tree_data_t;
 
@@ -471,6 +472,12 @@ extern void proto_tree_free(proto_tree *tree);
 extern void
 proto_tree_set_visible(proto_tree *tree, gboolean visible);
 
+/** Indicate whether we should fake protocols during dissection (default = TRUE)
+ @param tree the tree to be set
+ @param fake_protocols TRUE if we should fake protocols */
+extern void
+proto_tree_set_fake_protocols(proto_tree *tree, gboolean fake_protocols);
+
 /** Mark a field/protocol ID as "interesting".
  @param tree the tree to be set
  @param hfid the interesting field id
index 510821da32ebd855683a1b3902cc7ddd82b465f1..8e6b58acffcd965e6ffe4e0a9de432dcad66c2e6 100644 (file)
@@ -155,6 +155,8 @@ process_frame(frame_data *frame, column_info *cinfo, ph_stats_t* ps)
 
        /* Dissect the frame   tree  not visible */
        edt = epan_dissect_new(TRUE, FALSE);
+       /* Don't fake protocols. We need them for the protocol hierarchy */
+       epan_dissect_fake_protocols(edt, FALSE);
        epan_dissect_run(edt, &phdr, pd, frame, cinfo);
 
        /* Get stats from this protocol tree */