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.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;
}

View File

@ -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>

View File

@ -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

View File

@ -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, ...) \

View File

@ -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,

View File

@ -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) {

View File

@ -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) {

View File

@ -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);

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_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;
}

View File

@ -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);

View File

@ -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:

View File

@ -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;
}

View File

@ -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)");
}
}
else if (fi->ws_fi->hfinfo->type == FT_NONE) {
lua_pushstring(L, "(none)");
if (fi->ws_fi->hfinfo->type == FT_PROTOCOL) {
repr = fvalue_to_string_repr(NULL, &fi->ws_fi->value,FTREPR_DFILTER,BASE_NONE);
}
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;

View File

@ -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);

View File

@ -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>