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.
This commit is contained in:
João Valverde 2021-11-11 00:54:00 +00:00 committed by Wireshark GitLab Utility
parent 37f1cf1a92
commit 1a32a75a62
15 changed files with 82 additions and 86 deletions

View File

@ -18,7 +18,7 @@
#include "dfilter-int.h" #include "dfilter-int.h"
#include "dfilter.h" #include "dfilter.h"
#include "dfilter-macro.h" #include "dfilter-macro.h"
#include <ftypes/ftypes-int.h> #include <ftypes/ftypes.h>
#include <epan/uat-int.h> #include <epan/uat-int.h>
#include <epan/proto.h> #include <epan/proto.h>
#include <wsutil/glib-compat.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))) { if ((e = (fvt_cache_entry_t*)g_hash_table_lookup(fvt_cache,finfo->hfinfo->abbrev))) {
e->usable = FALSE; e->usable = FALSE;
} else if (finfo->value.ftype->val_to_string_repr) { } else {
switch (finfo->hfinfo->type) { switch (finfo->hfinfo->type) {
case FT_NONE: case FT_NONE:
case FT_PROTOCOL: case FT_PROTOCOL:
@ -58,11 +58,14 @@ static gboolean fvt_cache_cb(proto_node * node, gpointer data _U_) {
default: default:
break; break;
} }
e = g_new(fvt_cache_entry_t,1); char *repr = fvalue_to_string_repr(NULL, &(finfo->value), FTREPR_DFILTER, finfo->hfinfo->display);
e->name = finfo->hfinfo->abbrev; if (repr) {
e->repr = fvalue_to_string_repr(NULL, &(finfo->value), FTREPR_DFILTER, finfo->hfinfo->display); e = g_new(fvt_cache_entry_t,1);
e->usable = TRUE; e->name = finfo->hfinfo->abbrev;
g_hash_table_insert(fvt_cache,(void*)finfo->hfinfo->abbrev,e); e->repr = repr;
e->usable = TRUE;
g_hash_table_insert(fvt_cache,(void*)finfo->hfinfo->abbrev,e);
}
} }
return FALSE; return FALSE;
} }

View File

@ -15,7 +15,6 @@
#include <string.h> #include <string.h>
#include <ftypes/ftypes-int.h>
#include <ftypes/ftypes.h> #include <ftypes/ftypes.h>
#include <epan/exceptions.h> #include <epan/exceptions.h>
#include <wsutil/ws_assert.h> #include <wsutil/ws_assert.h>

View File

@ -10,7 +10,7 @@
#include "dfvm.h" #include "dfvm.h"
#include <ftypes/ftypes-int.h> #include <ftypes/ftypes.h>
#include <wsutil/ws_assert.h> #include <wsutil/ws_assert.h>
dfvm_insn_t* dfvm_insn_t*
@ -32,7 +32,7 @@ dfvm_value_free(dfvm_value_t *v)
{ {
switch (v->type) { switch (v->type) {
case FVALUE: case FVALUE:
FVALUE_FREE(v->value.fvalue); fvalue_free(v->value.fvalue);
break; break;
case DRANGE: case DRANGE:
drange_free(v->value.drange); drange_free(v->value.drange);
@ -504,7 +504,7 @@ static void
free_owned_register(gpointer data, gpointer user_data _U_) free_owned_register(gpointer data, gpointer user_data _U_)
{ {
fvalue_t *value = (fvalue_t *)data; fvalue_t *value = (fvalue_t *)data;
FVALUE_FREE(value); fvalue_free(value);
} }
/* Clear registers that were populated during evaluation (leaving constants /* Clear registers that were populated during evaluation (leaving constants

View File

@ -26,7 +26,7 @@
#include <wsutil/ws_assert.h> #include <wsutil/ws_assert.h>
#include <wsutil/wslog.h> #include <wsutil/wslog.h>
#include <ftypes/ftypes-int.h> #include <ftypes/ftypes.h>
#define FAIL(dfw, ...) \ #define FAIL(dfw, ...) \

View File

@ -10,17 +10,17 @@
#include "config.h" #include "config.h"
#include "ftypes/ftypes.h" #include "ftypes/ftypes.h"
#include "ftypes/ftypes-int.h"
#include "syntax-tree.h" #include "syntax-tree.h"
#include <epan/proto.h> // For BASE_NONE
static void static void
fvalue_free(gpointer value) sttype_fvalue_free(gpointer value)
{ {
fvalue_t *fvalue = value; fvalue_t *fvalue = value;
/* If the data was not claimed with stnode_steal_data(), free it. */ /* If the data was not claimed with stnode_steal_data(), free it. */
if (fvalue) { if (fvalue) {
FVALUE_FREE(fvalue); fvalue_free(fvalue);
} }
} }
@ -41,7 +41,7 @@ pcre_free(gpointer value)
} }
static char * static char *
fvalue_tostr(const void *data, gboolean pretty) sttype_fvalue_tostr(const void *data, gboolean pretty)
{ {
const fvalue_t *fvalue = data; const fvalue_t *fvalue = data;
@ -87,9 +87,9 @@ sttype_register_pointer(void)
STTYPE_FVALUE, STTYPE_FVALUE,
"FVALUE", "FVALUE",
NULL, NULL,
fvalue_free, sttype_fvalue_free,
NULL, NULL,
fvalue_tostr sttype_fvalue_tostr
}; };
static sttype_t pcre_type = { static sttype_t pcre_type = {
STTYPE_PCRE, STTYPE_PCRE,

View File

@ -76,7 +76,7 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_,
return FALSE; return FALSE;
} }
nmask_bits = fvalue_get_uinteger(nmask_fvalue); nmask_bits = fvalue_get_uinteger(nmask_fvalue);
FVALUE_FREE(nmask_fvalue); fvalue_free(nmask_fvalue);
if (nmask_bits > 32) { if (nmask_bits > 32) {
if (err_msg != NULL) { if (err_msg != NULL) {

View File

@ -61,7 +61,7 @@ ipv6_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_
return FALSE; return FALSE;
} }
nmask_bits = fvalue_get_uinteger(nmask_fvalue); nmask_bits = fvalue_get_uinteger(nmask_fvalue);
FVALUE_FREE(nmask_fvalue); fvalue_free(nmask_fvalue);
if (nmask_bits > 128) { if (nmask_bits > 128) {
if (err_msg != NULL) { if (err_msg != NULL) {

View File

@ -111,26 +111,8 @@ struct _ftype_t {
FvalueSlice slice; FvalueSlice slice;
}; };
/* Free all memory used by an fvalue_t. With MSVC and a GByteArray *
* libwireshark.dll, we need a special declaration. byte_array_from_unparsed(const char *s, gchar **err_msg);
*/
#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);
gboolean gboolean
parse_charconst(const char *s, unsigned long *valuep, gchar **err_msg); parse_charconst(const char *s, unsigned long *valuep, gchar **err_msg);

View File

@ -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_t*
fvalue_from_unparsed(ftenum_t ftype, const char *s, gboolean allow_partial_value, gchar **err_msg) 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)); s, ftype_pretty_name(ftype));
} }
} }
FVALUE_FREE(fv); fvalue_free(fv);
return NULL; return NULL;
} }
@ -296,7 +311,7 @@ fvalue_from_string(ftenum_t ftype, const char *s, gchar **err_msg)
s, ftype_pretty_name(ftype)); s, ftype_pretty_name(ftype));
} }
} }
FVALUE_FREE(fv); fvalue_free(fv);
return NULL; return NULL;
} }

View File

@ -242,6 +242,12 @@ fvalue_new(ftenum_t ftype);
void void
fvalue_init(fvalue_t *fv, ftenum_t ftype); fvalue_init(fvalue_t *fv, ftenum_t ftype);
void
fvalue_cleanup(fvalue_t *fv);
void
fvalue_free(fvalue_t *fv);
WS_DLL_PUBLIC WS_DLL_PUBLIC
fvalue_t* fvalue_t*
fvalue_from_unparsed(ftenum_t ftype, const char *s, gboolean allow_partial_value, gchar **err_msg); fvalue_from_unparsed(ftenum_t ftype, const char *s, gboolean allow_partial_value, gchar **err_msg);

View File

@ -31,7 +31,7 @@
#include <wsutil/filesystem.h> #include <wsutil/filesystem.h>
#include <wsutil/utf8_entities.h> #include <wsutil/utf8_entities.h>
#include <wsutil/ws_assert.h> #include <wsutil/ws_assert.h>
#include <ftypes/ftypes-int.h> #include <ftypes/ftypes.h>
#define PDML_VERSION "0" #define PDML_VERSION "0"
#define PSML_VERSION "0" #define PSML_VERSION "0"
@ -580,7 +580,7 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
fputs("\" value=\"", pdata->fh); fputs("\" value=\"", pdata->fh);
if (fi->hfinfo->bitmask!=0) { if (fi->hfinfo->bitmask!=0) {
switch (fi->value.ftype->ftype) { switch (fvalue_type_ftenum(&fi->value)) {
case FT_INT8: case FT_INT8:
case FT_INT16: case FT_INT16:
case FT_INT24: 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); json_dumper_begin_array(pdata->dumper);
if (fi->hfinfo->bitmask!=0) { if (fi->hfinfo->bitmask!=0) {
switch (fi->value.ftype->ftype) { switch (fvalue_type_ftenum(&fi->value)) {
case FT_INT8: case FT_INT8:
case FT_INT16: case FT_INT16:
case FT_INT24: 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->start);
json_dumper_value_anyf(pdata->dumper, "%" G_GINT32_MODIFIER "d", fi->length); 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_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); json_dumper_end_array(pdata->dumper);
} }
@ -1266,7 +1266,7 @@ static void
ek_write_hex(field_info *fi, write_json_data *pdata) ek_write_hex(field_info *fi, write_json_data *pdata)
{ {
if (fi->hfinfo->bitmask != 0) { if (fi->hfinfo->bitmask != 0) {
switch (fi->value.ftype->ftype) { switch (fvalue_type_ftenum(&fi->value)) {
case FT_INT8: case FT_INT8:
case FT_INT16: case FT_INT16:
case FT_INT24: case FT_INT24:

View File

@ -25,7 +25,7 @@
#include <wsutil/wslog.h> #include <wsutil/wslog.h>
#include <wsutil/ws_assert.h> #include <wsutil/ws_assert.h>
#include <ftypes/ftypes-int.h> #include <ftypes/ftypes.h>
#include "packet.h" #include "packet.h"
#include "exceptions.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); proto_tree_children_foreach(node, proto_tree_free_node, NULL);
FVALUE_CLEANUP(&finfo->value); fvalue_cleanup(&finfo->value);
} }
void void
@ -7074,7 +7074,7 @@ finfo_set_len(field_info *fi, const gint length)
* larger, if there's no data to back that length; * larger, if there's no data to back that length;
* you can only make it smaller. * 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; fi->value.value.bytes->len = fi->length;
} }

View File

@ -15,7 +15,7 @@
#include "config.h" #include "config.h"
#include <epan/dfilter/dfilter.h> #include <epan/dfilter/dfilter.h>
#include <epan/ftypes/ftypes-int.h> #include <epan/ftypes/ftypes.h>
/* WSLUA_MODULE Field Obtaining Dissection Data */ /* WSLUA_MODULE Field Obtaining Dissection Data */
@ -209,30 +209,22 @@ WSLUA_METAMETHOD FieldInfo__tostring(lua_State* L) {
/* The string representation of the field. */ /* The string representation of the field. */
FieldInfo fi = checkFieldInfo(L,1); 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) { if (fi->ws_fi->hfinfo->type == FT_PROTOCOL) {
repr = fvalue_to_string_repr(NULL, &fi->ws_fi->value,FTREPR_DFILTER,BASE_NONE); 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)");
}
}
else if (fi->ws_fi->hfinfo->type == FT_NONE) {
lua_pushstring(L, "(none)");
} }
else { else {
lua_pushstring(L,"(n/a)"); 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)");
} }
return 1; return 1;

View File

@ -54,7 +54,7 @@
#include "globals.h" #include "globals.h"
#include <epan/packet.h> #include <epan/packet.h>
#include <epan/ftypes/ftypes-int.h> #include <epan/ftypes/ftypes.h>
#include "file.h" #include "file.h"
#include "frame_tvbuff.h" #include "frame_tvbuff.h"
#include <epan/disabled_protos.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) static gboolean print_field_value(field_info *finfo, int cmd_line_index)
{ {
header_field_info *hfinfo; header_field_info *hfinfo;
char *fs_buf = NULL; char *fs_buf;
char *fs_ptr = NULL; char *fs_ptr;
static GString *label_s = NULL; static GString *label_s = NULL;
size_t fs_len; size_t fs_len;
guint i; guint i;
@ -1129,19 +1129,18 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
label_s = g_string_new(""); label_s = g_string_new("");
} }
if(finfo->value.ftype->val_to_string_repr) /*
{ * this field has an associated value,
/* * e.g: ip.hdr_len
* 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);
fs_buf = fvalue_to_string_repr(NULL, &finfo->value, if (fs_buf != NULL) {
FTREPR_DFILTER, finfo->hfinfo->display);
fs_len = strlen(fs_buf); fs_len = strlen(fs_buf);
fs_ptr = fs_buf; fs_ptr = fs_buf;
/* String types are quoted. Remove them. */ /* 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_buf[fs_len - 1] = '\0';
fs_ptr++; fs_ptr++;
} }
@ -1230,7 +1229,7 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
return TRUE; return TRUE;
} }
if(finfo->value.ftype->val_to_string_repr) if(fs_buf)
{ {
printf(" %d=\"%s\"", cmd_line_index, fs_ptr); printf(" %d=\"%s\"", cmd_line_index, fs_ptr);
wmem_free(NULL, fs_buf); wmem_free(NULL, fs_buf);

View File

@ -5909,7 +5909,7 @@ def produce_code():
#include <epan/packet.h> #include <epan/packet.h>
#include <epan/dfilter/dfilter.h> #include <epan/dfilter/dfilter.h>
#include <epan/exceptions.h> #include <epan/exceptions.h>
#include <ftypes/ftypes-int.h> #include <ftypes/ftypes.h>
#include <epan/to_str.h> #include <epan/to_str.h>
#include <epan/conversation.h> #include <epan/conversation.h>
#include <epan/ptvcursor.h> #include <epan/ptvcursor.h>