diff options
author | João Valverde <j@v6e.pt> | 2021-11-11 00:54:00 +0000 |
---|---|---|
committer | Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2021-11-11 03:15:31 +0000 |
commit | 1a32a75a621086349f8eb30693bab5dec14b19f3 (patch) | |
tree | b6f281e91fd5401befffdd8e86377b7d681d46f9 | |
parent | 37f1cf1a925d67ce495ba44b77a08904ca1ee21b (diff) |
ftypes: Internal headers need to be internal
The header ftypes-int.h should not be used outside of epan/ftypes
because it is a private header.
The functions fvalue_free() and fvalue_cleanup() need not and should
not be macros either.
-rw-r--r-- | epan/dfilter/dfilter-macro.c | 17 | ||||
-rw-r--r-- | epan/dfilter/dfunctions.c | 1 | ||||
-rw-r--r-- | epan/dfilter/dfvm.c | 6 | ||||
-rw-r--r-- | epan/dfilter/semcheck.c | 2 | ||||
-rw-r--r-- | epan/dfilter/sttype-pointer.c | 12 | ||||
-rw-r--r-- | epan/ftypes/ftype-ipv4.c | 2 | ||||
-rw-r--r-- | epan/ftypes/ftype-ipv6.c | 2 | ||||
-rw-r--r-- | epan/ftypes/ftypes-int.h | 22 | ||||
-rw-r--r-- | epan/ftypes/ftypes.c | 19 | ||||
-rw-r--r-- | epan/ftypes/ftypes.h | 6 | ||||
-rw-r--r-- | epan/print.c | 10 | ||||
-rw-r--r-- | epan/proto.c | 6 | ||||
-rw-r--r-- | epan/wslua/wslua_field.c | 34 | ||||
-rw-r--r-- | rawshark.c | 25 | ||||
-rwxr-xr-x | tools/ncp2222.py | 2 |
15 files changed, 81 insertions, 85 deletions
diff --git a/epan/dfilter/dfilter-macro.c b/epan/dfilter/dfilter-macro.c index bf1bc3c154..33c0c0e637 100644 --- a/epan/dfilter/dfilter-macro.c +++ b/epan/dfilter/dfilter-macro.c @@ -18,7 +18,7 @@ #include "dfilter-int.h" #include "dfilter.h" #include "dfilter-macro.h" -#include <ftypes/ftypes-int.h> +#include <ftypes/ftypes.h> #include <epan/uat-int.h> #include <epan/proto.h> #include <wsutil/glib-compat.h> @@ -50,7 +50,7 @@ static gboolean fvt_cache_cb(proto_node * node, gpointer data _U_) { if ((e = (fvt_cache_entry_t*)g_hash_table_lookup(fvt_cache,finfo->hfinfo->abbrev))) { e->usable = FALSE; - } else if (finfo->value.ftype->val_to_string_repr) { + } else { switch (finfo->hfinfo->type) { case FT_NONE: case FT_PROTOCOL: @@ -58,11 +58,14 @@ static gboolean fvt_cache_cb(proto_node * node, gpointer data _U_) { default: break; } - e = g_new(fvt_cache_entry_t,1); - e->name = finfo->hfinfo->abbrev; - e->repr = fvalue_to_string_repr(NULL, &(finfo->value), FTREPR_DFILTER, finfo->hfinfo->display); - e->usable = TRUE; - g_hash_table_insert(fvt_cache,(void*)finfo->hfinfo->abbrev,e); + char *repr = fvalue_to_string_repr(NULL, &(finfo->value), FTREPR_DFILTER, finfo->hfinfo->display); + if (repr) { + e = g_new(fvt_cache_entry_t,1); + e->name = finfo->hfinfo->abbrev; + e->repr = repr; + e->usable = TRUE; + g_hash_table_insert(fvt_cache,(void*)finfo->hfinfo->abbrev,e); + } } return FALSE; } diff --git a/epan/dfilter/dfunctions.c b/epan/dfilter/dfunctions.c index dd50f27b5b..69f5ec576f 100644 --- a/epan/dfilter/dfunctions.c +++ b/epan/dfilter/dfunctions.c @@ -15,7 +15,6 @@ #include <string.h> -#include <ftypes/ftypes-int.h> #include <ftypes/ftypes.h> #include <epan/exceptions.h> #include <wsutil/ws_assert.h> diff --git a/epan/dfilter/dfvm.c b/epan/dfilter/dfvm.c index 67a83a016c..c573f350ee 100644 --- a/epan/dfilter/dfvm.c +++ b/epan/dfilter/dfvm.c @@ -10,7 +10,7 @@ #include "dfvm.h" -#include <ftypes/ftypes-int.h> +#include <ftypes/ftypes.h> #include <wsutil/ws_assert.h> dfvm_insn_t* @@ -32,7 +32,7 @@ dfvm_value_free(dfvm_value_t *v) { switch (v->type) { case FVALUE: - FVALUE_FREE(v->value.fvalue); + fvalue_free(v->value.fvalue); break; case DRANGE: drange_free(v->value.drange); @@ -504,7 +504,7 @@ static void free_owned_register(gpointer data, gpointer user_data _U_) { fvalue_t *value = (fvalue_t *)data; - FVALUE_FREE(value); + fvalue_free(value); } /* Clear registers that were populated during evaluation (leaving constants diff --git a/epan/dfilter/semcheck.c b/epan/dfilter/semcheck.c index 252042aa4a..fcca66cafe 100644 --- a/epan/dfilter/semcheck.c +++ b/epan/dfilter/semcheck.c @@ -26,7 +26,7 @@ #include <wsutil/ws_assert.h> #include <wsutil/wslog.h> -#include <ftypes/ftypes-int.h> +#include <ftypes/ftypes.h> #define FAIL(dfw, ...) \ diff --git a/epan/dfilter/sttype-pointer.c b/epan/dfilter/sttype-pointer.c index 4f7e02e9df..184831c74f 100644 --- a/epan/dfilter/sttype-pointer.c +++ b/epan/dfilter/sttype-pointer.c @@ -10,17 +10,17 @@ #include "config.h" #include "ftypes/ftypes.h" -#include "ftypes/ftypes-int.h" #include "syntax-tree.h" +#include <epan/proto.h> // For BASE_NONE static void -fvalue_free(gpointer value) +sttype_fvalue_free(gpointer value) { fvalue_t *fvalue = value; /* If the data was not claimed with stnode_steal_data(), free it. */ if (fvalue) { - FVALUE_FREE(fvalue); + fvalue_free(fvalue); } } @@ -41,7 +41,7 @@ pcre_free(gpointer value) } static char * -fvalue_tostr(const void *data, gboolean pretty) +sttype_fvalue_tostr(const void *data, gboolean pretty) { const fvalue_t *fvalue = data; @@ -87,9 +87,9 @@ sttype_register_pointer(void) STTYPE_FVALUE, "FVALUE", NULL, - fvalue_free, + sttype_fvalue_free, NULL, - fvalue_tostr + sttype_fvalue_tostr }; static sttype_t pcre_type = { STTYPE_PCRE, diff --git a/epan/ftypes/ftype-ipv4.c b/epan/ftypes/ftype-ipv4.c index cac7ac0107..10d893ee5e 100644 --- a/epan/ftypes/ftype-ipv4.c +++ b/epan/ftypes/ftype-ipv4.c @@ -76,7 +76,7 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, return FALSE; } nmask_bits = fvalue_get_uinteger(nmask_fvalue); - FVALUE_FREE(nmask_fvalue); + fvalue_free(nmask_fvalue); if (nmask_bits > 32) { if (err_msg != NULL) { diff --git a/epan/ftypes/ftype-ipv6.c b/epan/ftypes/ftype-ipv6.c index 4ef71ed69a..0fcf4188fd 100644 --- a/epan/ftypes/ftype-ipv6.c +++ b/epan/ftypes/ftype-ipv6.c @@ -61,7 +61,7 @@ ipv6_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_ return FALSE; } nmask_bits = fvalue_get_uinteger(nmask_fvalue); - FVALUE_FREE(nmask_fvalue); + fvalue_free(nmask_fvalue); if (nmask_bits > 128) { if (err_msg != NULL) { diff --git a/epan/ftypes/ftypes-int.h b/epan/ftypes/ftypes-int.h index e9fe410ea2..6b8f02202d 100644 --- a/epan/ftypes/ftypes-int.h +++ b/epan/ftypes/ftypes-int.h @@ -111,26 +111,8 @@ struct _ftype_t { FvalueSlice slice; }; -/* Free all memory used by an fvalue_t. With MSVC and a - * libwireshark.dll, we need a special declaration. - */ - -#define FVALUE_CLEANUP(fv) \ - { \ - register FvalueFreeFunc free_value; \ - free_value = (fv)->ftype->free_value; \ - if (free_value) { \ - free_value((fv)); \ - } \ - } - -#define FVALUE_FREE(fv) \ - { \ - FVALUE_CLEANUP(fv) \ - g_slice_free(fvalue_t, fv); \ - } - -GByteArray *byte_array_from_unparsed(const char *s, gchar **err_msg); +GByteArray * +byte_array_from_unparsed(const char *s, gchar **err_msg); gboolean parse_charconst(const char *s, unsigned long *valuep, gchar **err_msg); diff --git a/epan/ftypes/ftypes.c b/epan/ftypes/ftypes.c index b122e7e4c6..68d20a054b 100644 --- a/epan/ftypes/ftypes.c +++ b/epan/ftypes/ftypes.c @@ -252,6 +252,21 @@ fvalue_init(fvalue_t *fv, ftenum_t ftype) } } +void +fvalue_cleanup(fvalue_t *fv) +{ + if (!fv->ftype->free_value) + return; + fv->ftype->free_value(fv); +} + +void +fvalue_free(fvalue_t *fv) +{ + fvalue_cleanup(fv); + g_slice_free(fvalue_t, fv); +} + fvalue_t* fvalue_from_unparsed(ftenum_t ftype, const char *s, gboolean allow_partial_value, gchar **err_msg) { @@ -272,7 +287,7 @@ fvalue_from_unparsed(ftenum_t ftype, const char *s, gboolean allow_partial_value s, ftype_pretty_name(ftype)); } } - FVALUE_FREE(fv); + fvalue_free(fv); return NULL; } @@ -296,7 +311,7 @@ fvalue_from_string(ftenum_t ftype, const char *s, gchar **err_msg) s, ftype_pretty_name(ftype)); } } - FVALUE_FREE(fv); + fvalue_free(fv); return NULL; } diff --git a/epan/ftypes/ftypes.h b/epan/ftypes/ftypes.h index 85e6769106..3e9177b0a9 100644 --- a/epan/ftypes/ftypes.h +++ b/epan/ftypes/ftypes.h @@ -242,6 +242,12 @@ fvalue_new(ftenum_t ftype); void fvalue_init(fvalue_t *fv, ftenum_t ftype); +void +fvalue_cleanup(fvalue_t *fv); + +void +fvalue_free(fvalue_t *fv); + WS_DLL_PUBLIC fvalue_t* fvalue_from_unparsed(ftenum_t ftype, const char *s, gboolean allow_partial_value, gchar **err_msg); diff --git a/epan/print.c b/epan/print.c index eb023a154a..21788f6a28 100644 --- a/epan/print.c +++ b/epan/print.c @@ -31,7 +31,7 @@ #include <wsutil/filesystem.h> #include <wsutil/utf8_entities.h> #include <wsutil/ws_assert.h> -#include <ftypes/ftypes-int.h> +#include <ftypes/ftypes.h> #define PDML_VERSION "0" #define PSML_VERSION "0" @@ -580,7 +580,7 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data) fputs("\" value=\"", pdata->fh); if (fi->hfinfo->bitmask!=0) { - switch (fi->value.ftype->ftype) { + switch (fvalue_type_ftenum(&fi->value)) { case FT_INT8: case FT_INT16: case FT_INT24: @@ -943,7 +943,7 @@ write_json_proto_node_hex_dump(proto_node *node, write_json_data *pdata) json_dumper_begin_array(pdata->dumper); if (fi->hfinfo->bitmask!=0) { - switch (fi->value.ftype->ftype) { + switch (fvalue_type_ftenum(&fi->value)) { case FT_INT8: case FT_INT16: case FT_INT24: @@ -981,7 +981,7 @@ write_json_proto_node_hex_dump(proto_node *node, write_json_data *pdata) json_dumper_value_anyf(pdata->dumper, "%" G_GINT32_MODIFIER "d", fi->start); json_dumper_value_anyf(pdata->dumper, "%" G_GINT32_MODIFIER "d", fi->length); json_dumper_value_anyf(pdata->dumper, "%" G_GUINT64_FORMAT, fi->hfinfo->bitmask); - json_dumper_value_anyf(pdata->dumper, "%" G_GINT32_MODIFIER "d", (gint32)fi->value.ftype->ftype); + json_dumper_value_anyf(pdata->dumper, "%" G_GINT32_MODIFIER "d", (gint32)fvalue_type_ftenum(&fi->value)); json_dumper_end_array(pdata->dumper); } @@ -1266,7 +1266,7 @@ static void ek_write_hex(field_info *fi, write_json_data *pdata) { if (fi->hfinfo->bitmask != 0) { - switch (fi->value.ftype->ftype) { + switch (fvalue_type_ftenum(&fi->value)) { case FT_INT8: case FT_INT16: case FT_INT24: diff --git a/epan/proto.c b/epan/proto.c index 6d7f61b268..d5a9a279b5 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -25,7 +25,7 @@ #include <wsutil/wslog.h> #include <wsutil/ws_assert.h> -#include <ftypes/ftypes-int.h> +#include <ftypes/ftypes.h> #include "packet.h" #include "exceptions.h" @@ -794,7 +794,7 @@ proto_tree_free_node(proto_node *node, gpointer data _U_) proto_tree_children_foreach(node, proto_tree_free_node, NULL); - FVALUE_CLEANUP(&finfo->value); + fvalue_cleanup(&finfo->value); } void @@ -7074,7 +7074,7 @@ finfo_set_len(field_info *fi, const gint length) * larger, if there's no data to back that length; * you can only make it smaller. */ - if (fi->value.ftype->ftype == FT_BYTES && fi->length <= (gint)fi->value.value.bytes->len) + if (fvalue_type_ftenum(&fi->value) == FT_BYTES && fi->length <= (gint)fi->value.value.bytes->len) fi->value.value.bytes->len = fi->length; } diff --git a/epan/wslua/wslua_field.c b/epan/wslua/wslua_field.c index d8bdf6c6fe..b8b0446593 100644 --- a/epan/wslua/wslua_field.c +++ b/epan/wslua/wslua_field.c @@ -15,7 +15,7 @@ #include "config.h" #include <epan/dfilter/dfilter.h> -#include <epan/ftypes/ftypes-int.h> +#include <epan/ftypes/ftypes.h> /* WSLUA_MODULE Field Obtaining Dissection Data */ @@ -209,30 +209,22 @@ WSLUA_METAMETHOD FieldInfo__tostring(lua_State* L) { /* The string representation of the field. */ FieldInfo fi = checkFieldInfo(L,1); - if (fi->ws_fi->value.ftype->val_to_string_repr) { - gchar* repr = NULL; + gchar* repr = NULL; - if (fi->ws_fi->hfinfo->type == FT_PROTOCOL) { - repr = fvalue_to_string_repr(NULL, &fi->ws_fi->value,FTREPR_DFILTER,BASE_NONE); - } - else { - repr = fvalue_to_string_repr(NULL, &fi->ws_fi->value,FTREPR_DISPLAY,fi->ws_fi->hfinfo->display); - } - - if (repr) { - lua_pushstring(L,repr); - /* fvalue_to_string_repr() wmem_alloc's the string's buffer */ - wmem_free(NULL, repr); - } - else { - lua_pushstring(L,"(unknown)"); - } + if (fi->ws_fi->hfinfo->type == FT_PROTOCOL) { + repr = fvalue_to_string_repr(NULL, &fi->ws_fi->value,FTREPR_DFILTER,BASE_NONE); + } + else { + repr = fvalue_to_string_repr(NULL, &fi->ws_fi->value,FTREPR_DISPLAY,fi->ws_fi->hfinfo->display); } - else if (fi->ws_fi->hfinfo->type == FT_NONE) { - lua_pushstring(L, "(none)"); + + if (repr) { + lua_pushstring(L,repr); + /* fvalue_to_string_repr() wmem_alloc's the string's buffer */ + wmem_free(NULL, repr); } else { - lua_pushstring(L,"(n/a)"); + lua_pushstring(L,"(unknown)"); } return 1; diff --git a/rawshark.c b/rawshark.c index 1df8268055..a1919e71bf 100644 --- a/rawshark.c +++ b/rawshark.c @@ -54,7 +54,7 @@ #include "globals.h" #include <epan/packet.h> -#include <epan/ftypes/ftypes-int.h> +#include <epan/ftypes/ftypes.h> #include "file.h" #include "frame_tvbuff.h" #include <epan/disabled_protos.h> @@ -1111,8 +1111,8 @@ static void field_display_to_string(header_field_info *hfi, char* buf, int size) static gboolean print_field_value(field_info *finfo, int cmd_line_index) { header_field_info *hfinfo; - char *fs_buf = NULL; - char *fs_ptr = NULL; + char *fs_buf; + char *fs_ptr; static GString *label_s = NULL; size_t fs_len; guint i; @@ -1129,19 +1129,18 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index) label_s = g_string_new(""); } - if(finfo->value.ftype->val_to_string_repr) - { - /* - * this field has an associated value, - * e.g: ip.hdr_len - */ - fs_buf = fvalue_to_string_repr(NULL, &finfo->value, - FTREPR_DFILTER, finfo->hfinfo->display); + /* + * this field has an associated value, + * e.g: ip.hdr_len + */ + fs_buf = fvalue_to_string_repr(NULL, &finfo->value, + FTREPR_DFILTER, finfo->hfinfo->display); + if (fs_buf != NULL) { fs_len = strlen(fs_buf); fs_ptr = fs_buf; /* String types are quoted. Remove them. */ - if (IS_FT_STRING(finfo->value.ftype->ftype) && fs_len > 2) { + if (IS_FT_STRING(fvalue_type_ftenum(&finfo->value)) && fs_len > 2) { fs_buf[fs_len - 1] = '\0'; fs_ptr++; } @@ -1230,7 +1229,7 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index) return TRUE; } - if(finfo->value.ftype->val_to_string_repr) + if(fs_buf) { printf(" %d=\"%s\"", cmd_line_index, fs_ptr); wmem_free(NULL, fs_buf); diff --git a/tools/ncp2222.py b/tools/ncp2222.py index e4c95228e0..6d284caa07 100755 --- a/tools/ncp2222.py +++ b/tools/ncp2222.py @@ -5909,7 +5909,7 @@ def produce_code(): #include <epan/packet.h> #include <epan/dfilter/dfilter.h> #include <epan/exceptions.h> -#include <ftypes/ftypes-int.h> +#include <ftypes/ftypes.h> #include <epan/to_str.h> #include <epan/conversation.h> #include <epan/ptvcursor.h> |