Have separate proto_construct_match_selected_string() and
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 24 Nov 2006 18:25:23 +0000 (18:25 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 24 Nov 2006 18:25:23 +0000 (18:25 +0000)
proto_can_match_selected() routines, to more clearly separate the two
functions - but have them both call the same underlying routine, so
they both make the same decisions as to whether a match-selected string
can be constructed or not.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@19976 f5534014-38df-0310-8fa8-9805f1628bb7

epan/libwireshark.def
epan/proto.c
epan/proto.h
gtk/expert_comp_table.c
gtk/main.c
gtk/menu.c
print.c
tap-protocolinfo.c

index 9b9407146371c3eb6950ca29f7d20fdb388b9323..9f8664210e0e0d6957524fe26b087ed410cd7aa1 100644 (file)
@@ -483,6 +483,7 @@ process_reassembled_data
 process_stat_cmd_arg
 protocols_module                DATA
 proto_all_finfos
+proto_can_match_selected
 proto_can_toggle_protocol
 proto_construct_match_selected_string
 proto_data                      DATA
index 9746c5476fee944b4463dda279282a1c9d77f300..ffc4227cbdeb9516f8fbef5d00036e344ad8ca32 100644 (file)
@@ -5078,8 +5078,8 @@ hfinfo_numeric_format(header_field_info *hfinfo)
  * You do not need to [g_]free() this string since it will be automatically
  * freed once the next packet is dissected.
  */
-gboolean
-proto_construct_match_selected_string(field_info *finfo, epan_dissect_t *edt,
+static gboolean
+construct_match_selected_string(field_info *finfo, epan_dissect_t *edt,
     char **filter)
 {
        header_field_info       *hfinfo;
@@ -5282,3 +5282,31 @@ proto_construct_match_selected_string(field_info *finfo, epan_dissect_t *edt,
 
        return TRUE;
 }
+
+/*
+ * Returns TRUE if we can do a "match selected" on the field, FALSE
+ * otherwise.
+ */
+gboolean
+proto_can_match_selected(field_info *finfo, epan_dissect_t *edt)
+{
+       return construct_match_selected_string(finfo, edt, NULL);
+}
+
+/* This function attempts to construct a "match selected" display filter
+ * string for the specified field; if it can do so, it returns a pointer
+ * to the string, otherwise it returns NULL.
+ *
+ * The string is allocated with packet lifetime scope.
+ * You do not need to [g_]free() this string since it will be automatically
+ * freed once the next packet is dissected.
+ */
+char*
+proto_construct_match_selected_string(field_info *finfo, epan_dissect_t *edt)
+{
+       char *filter;
+
+       if (!construct_match_selected_string(finfo, edt, &filter))
+               return NULL;
+       return filter;
+}
index 78c1096843fea4e32aef4c932de461a23ca31be5..361d5ecd014fa741dd528bb46602f6292ab9491c 100644 (file)
@@ -1532,16 +1532,19 @@ hfinfo_bitwidth(header_field_info *hfinfo);
 
 #include "epan.h"
 
-/** Check whether we can do a "match selected" on this field and, if
-    requested to, return the filter that does so.
+/** Can we do a "match selected" on this field.
  @param finfo field_info
  @param edt epan dissecting
- @param filter if non-null, the display filter string is constructed and
- *filter is set to point to it
  @return TRUE if we can do a "match selected" on the field, FALSE otherwise. */
 extern gboolean
-proto_construct_match_selected_string(field_info *finfo, epan_dissect_t *edt,
-    char **filter);
+proto_can_match_selected(field_info *finfo, epan_dissect_t *edt);
+
+/** Construct a "match selected" display filter string.
+ @param finfo field_info
+ @param edt epan dissecting
+ @return the display filter string */
+extern char*
+proto_construct_match_selected_string(field_info *finfo, epan_dissect_t *edt);
 
 /** Find field from offset in tvb.
  @param tree 
index 607baa7a38d9c7c4b94569ac68b202da82a7521d..24a9a826d62c361ee2e85646b1a6e3916f931fd2 100644 (file)
@@ -750,7 +750,9 @@ init_error_table_row(error_equiv_table *err, const expert_info_t *expert_data)
         /* If an expert item was passed then build the filter string */
         if (expert_data->pitem) {
             char *filter;
-            if (proto_construct_match_selected_string(expert_data->pitem->finfo, NULL, &filter))
+
+            filter = proto_construct_match_selected_string(expert_data->pitem->finfo, NULL);
+            if (filter != NULL)
                 err->procedures[row].fvalue_value = g_strdup(filter);
         }
         /* Store the updated count of events */
index e4d37fa9d441786ea5f4fa7cb14a19413f54b28b..d64fcf348f57ab7c0de7cab6d6b0b77db4107837 100644 (file)
@@ -309,8 +309,9 @@ match_selected_ptree_cb(GtkWidget *w, gpointer data, MATCH_SELECTED_E action)
     char *filter;
 
     if (cfile.finfo_selected) {
-        if (proto_construct_match_selected_string(cfile.finfo_selected,
-                                                  cfile.edt, &filter))
+        filter = proto_construct_match_selected_string(cfile.finfo_selected,
+                                                       cfile.edt);
+        if (filter != NULL)
             match_selected_cb_do((data ? data : w), action, filter);
     }
 }
index aa0470714076219405d3c960e969f27d3ca47901..86e0e5a2b6689de4805d1d84d889773ee94d8ea3 100644 (file)
@@ -2430,13 +2430,13 @@ set_menus_for_selected_tree_row(capture_file *cf)
        set_menu_sensitivity(tree_view_menu_factory,
          "/Go to Corresponding Packet", hfinfo->type == FT_FRAMENUM);
        set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Filter",
-         proto_construct_match_selected_string(cf->finfo_selected, cf->edt, NULL));
+         proto_can_match_selected(cf->finfo_selected, cf->edt));
        set_menu_sensitivity(tree_view_menu_factory, "/Apply as Filter",
-         proto_construct_match_selected_string(cf->finfo_selected, cf->edt, NULL));
+         proto_can_match_selected(cf->finfo_selected, cf->edt));
        set_menu_sensitivity(main_menu_factory, "/Analyze/Prepare a Filter",
-         proto_construct_match_selected_string(cf->finfo_selected, cf->edt, NULL));
+         proto_can_match_selected(cf->finfo_selected, cf->edt));
        set_menu_sensitivity(tree_view_menu_factory, "/Prepare a Filter",
-         proto_construct_match_selected_string(cf->finfo_selected, cf->edt, NULL));
+         proto_can_match_selected(cf->finfo_selected, cf->edt));
        set_menu_sensitivity(tree_view_menu_factory, "/Protocol Preferences...",
          properties);
        set_menu_sensitivity(main_menu_factory, "/View/Expand Subtrees", cf->finfo_selected->tree_type != -1);
diff --git a/print.c b/print.c
index ed5a3ba74d6f62e1aa94b09f9b79db048887d95a..7297c10daf6bd16a9733fcec06cdb58254171b8e 100644 (file)
--- a/print.c
+++ b/print.c
@@ -343,8 +343,9 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
                default:
                        /* XXX - this is a hack until we can just call
                         * fvalue_to_string_repr() for *all* FT_* types. */
-                       if (proto_construct_match_selected_string(fi,
-                           pdata->edt, &dfilter_string)) {
+                       dfilter_string = proto_construct_match_selected_string(fi,
+                           pdata->edt);
+                       if (dfilter_string != NULL) {
                                chop_len = strlen(fi->hfinfo->abbrev) + 4; /* for " == " */
 
                                /* XXX - Remove double-quotes. Again, once we
index 0c9f8fbfc454fdb0b0ffb2fc56519b29cb23a9ce..dfaea88099fbdef8dc676a142601d63d7077cf09 100644 (file)
@@ -76,7 +76,8 @@ protocolinfo_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, const vo
        }
 
        for(i=0;i<gp->len;i++){
-               if(proto_construct_match_selected_string(gp->pdata[i], NULL, &str)){
+               str=proto_construct_match_selected_string(gp->pdata[i], NULL);
+               if(str){
                        col_append_fstr(pinfo->cinfo, COL_INFO, "  %s",str);
                }
        }