From 9d79b3233a940a393c88d90f86511592048692cd Mon Sep 17 00:00:00 2001 From: Jakub Zawadzki Date: Fri, 16 Aug 2013 21:21:52 +0000 Subject: [PATCH] Introduce new proto_tree API required for hf_ variables removal. svn path=/trunk/; revision=51396 --- epan/proto.c | 66 ++++++++++++++++++++++++++++++++++++++++------------ epan/proto.h | 19 ++++++++++++--- 2 files changed, 67 insertions(+), 18 deletions(-) diff --git a/epan/proto.c b/epan/proto.c index 9fd4ed56fb..d778db4a30 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -22,6 +22,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#define NEW_PROTO_TREE_API + #include "config.h" #include @@ -1811,18 +1813,18 @@ test_length(header_field_info *hfinfo, proto_tree *tree, tvbuff_t *tvb, /* Add an item to a proto_tree, using the text label registered to that item; the item is extracted from the tvbuff handed to it. */ proto_item * -proto_tree_add_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb, +proto_tree_add_item(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb, const gint start, gint length, const guint encoding) { field_info *new_fi; - header_field_info *hfinfo; gint item_length; - PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo); + DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi!"); + get_hfi_length(hfinfo, tvb, start, &length, &item_length); test_length(hfinfo, tree, tvb, start, item_length, encoding); - TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo); + TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo); new_fi = new_field_info(tree, hfinfo, tvb, start, item_length); @@ -1832,6 +1834,13 @@ proto_tree_add_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb, return proto_tree_new_item(new_fi, tree, tvb, start, length, encoding); } +proto_item * +proto_tree_add_item_old(proto_tree *tree, int hfindex, tvbuff_t *tvb, + const gint start, gint length, const guint encoding) +{ + return proto_tree_add_item(tree, proto_registrar_get_nth(hfindex), tvb, start, length, encoding); +} + /* Add a FT_NONE to a proto_tree */ proto_item * proto_tree_add_none_format(proto_tree *tree, const int hfindex, tvbuff_t *tvb, @@ -1867,7 +1876,7 @@ ptvcursor_add_no_advance(ptvcursor_t* ptvc, int hf, gint length, { proto_item *item; - item = proto_tree_add_item(ptvc->tree, hf, ptvc->tvb, ptvc->offset, + item = proto_tree_add_item_old(ptvc->tree, hf, ptvc->tvb, ptvc->offset, length, encoding); return item; @@ -4450,29 +4459,25 @@ header_field_info * proto_get_first_protocol_field(const int proto_id, void **cookie) { protocol_t *protocol = find_protocol_by_id(proto_id); - hf_register_info *ptr; if ((protocol == NULL) || (protocol->fields == NULL)) return NULL; *cookie = protocol->fields; - ptr = (hf_register_info *)protocol->fields->data; - return &ptr->hfinfo; + return (header_field_info *)protocol->fields->data; } header_field_info * proto_get_next_protocol_field(void **cookie) { GSList *list_item = (GSList *)*cookie; - hf_register_info *ptr; list_item = g_slist_next(list_item); if (list_item == NULL) return NULL; *cookie = list_item; - ptr = (hf_register_info *)list_item->data; - return &ptr->hfinfo; + return (header_field_info *)list_item->data; } protocol_t * @@ -4640,11 +4645,11 @@ proto_register_field_array(const int parent, hf_register_info *hf, const int num if (proto != NULL) { if (proto->fields == NULL) { - proto->fields = g_slist_append(NULL, ptr); + proto->fields = g_slist_append(NULL, &ptr->hfinfo); proto->last_field = proto->fields; } else { proto->last_field = - g_slist_append(proto->last_field, ptr)->next; + g_slist_append(proto->last_field, &ptr->hfinfo)->next; } } field_id = proto_register_field_init(&ptr->hfinfo, parent); @@ -4652,6 +4657,37 @@ proto_register_field_array(const int parent, hf_register_info *hf, const int num } } +void +proto_register_fields(const int parent, header_field_info **hfi, const int num_records) +{ + int i; + protocol_t *proto; + + proto = find_protocol_by_id(parent); + for (i = 0; i < num_records; i++) { + /* + * Make sure we haven't registered this yet. + */ + if (hfi[i]->id != -1) { + fprintf(stderr, + "Duplicate field detected in call to proto_register_field_array: %s is already registered\n", + hfi[i]->abbrev); + return; + } + + if (proto != NULL) { + if (proto->fields == NULL) { + proto->fields = g_slist_append(NULL, hfi[i]); + proto->last_field = proto->fields; + } else { + proto->last_field = + g_slist_append(proto->last_field, hfi[i])->next; + } + } + proto_register_field_init(hfi[i], parent); + } +} + /* unregister already registered fields */ void proto_unregister_field (const int parent, gint hf_id) @@ -6732,7 +6768,7 @@ proto_item_add_bitmask_tree(proto_item *item, tvbuff_t *tvb, const int offset, continue; } - proto_tree_add_item(tree, **fields, tvb, offset, len, encoding); + proto_tree_add_item_old(tree, **fields, tvb, offset, len, encoding); if (flags & BMT_NO_APPEND) { fields++; continue; @@ -6840,7 +6876,7 @@ proto_tree_add_bitmask(proto_tree *parent_tree, tvbuff_t *tvb, len = ftype_length(hf->type); if (parent_tree) { - item = proto_tree_add_item(parent_tree, hf_hdr, tvb, offset, len, encoding); + item = proto_tree_add_item_old(parent_tree, hf_hdr, tvb, offset, len, encoding); proto_item_add_bitmask_tree(item, tvb, offset, len, ett, fields, encoding, BMT_NO_INT|BMT_NO_TFS, FALSE); } diff --git a/epan/proto.h b/epan/proto.h index fb366b77ba..36865a2e40 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -382,7 +382,7 @@ struct _header_field_info { * _header_field_info. If new fields are added or removed, it should * be changed as necessary. */ -#define HFILL 0, 0, HF_REF_TYPE_NONE, -1, NULL +#define HFILL -1, 0, HF_REF_TYPE_NONE, -1, NULL /** Used when registering many fields at once, using proto_register_field_array() */ typedef struct hf_register_info { @@ -756,16 +756,25 @@ WS_DLL_PUBLIC void proto_tree_set_appendix(proto_tree *tree, tvbuff_t *tvb, gint /** Add an item to a proto_tree, using the text label registered to that item. The item is extracted from the tvbuff handed to it. @param tree the tree to append this item to - @param hfindex field index + @param hfinfo field @param tvb the tv buffer of the current data @param start start of data in tvb @param length length of data in tvb @param encoding data encoding @return the newly created item */ WS_DLL_PUBLIC proto_item * -proto_tree_add_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb, +proto_tree_add_item(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb, const gint start, gint length, const guint encoding); +#ifndef NEW_PROTO_TREE_API +#define proto_tree_add_item(tree, hfindex, tvb, start, length, encoding) \ + proto_tree_add_item_old(tree, hfindex, tvb, start, length, encoding) +#endif + +WS_DLL_PUBLIC proto_item * +proto_tree_add_item_old(proto_tree *tree, int hfindex, tvbuff_t *tvb, + const gint start, gint length, const guint encoding); + /** Add a text-only node to a proto_tree. @param tree the tree to append this item to @param tvb the tv buffer of the current data @@ -1662,6 +1671,10 @@ proto_register_prefix(const char *prefix, prefix_initializer_t initializer); /** Initialize every remaining uninitialized prefix. */ WS_DLL_PUBLIC void proto_initialize_all_prefixes(void); +#define HFI_INIT(proto) + +WS_DLL_PUBLIC void proto_register_fields(const int parent, header_field_info **hfi, const int num_records); + /** Register a header_field array. @param parent the protocol handle from proto_register_protocol() @param hf the hf_register_info array