2001-02-01 20:31:21 +00:00
|
|
|
/*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2001-02-01 20:31:21 +00:00
|
|
|
* Copyright 2001 Gerald Combs
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2018-02-08 16:59:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2001-02-01 20:31:21 +00:00
|
|
|
*/
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2021-10-15 22:47:28 +00:00
|
|
|
#include "ftypes-int.h"
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2021-06-18 18:21:42 +00:00
|
|
|
#include <wsutil/ws_assert.h>
|
2021-10-15 22:47:28 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
/* Keep track of ftype_t's via their ftenum number */
|
2022-02-27 09:56:41 +00:00
|
|
|
ftype_t* type_list[FT_NUM_TYPES];
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
/* Initialize the ftype module. */
|
|
|
|
void
|
|
|
|
ftypes_initialize(void)
|
|
|
|
{
|
|
|
|
ftype_register_bytes();
|
|
|
|
ftype_register_double();
|
2015-09-06 17:01:47 +00:00
|
|
|
ftype_register_ieee_11073_float();
|
2001-02-01 20:21:25 +00:00
|
|
|
ftype_register_integers();
|
|
|
|
ftype_register_ipv4();
|
2011-09-07 11:03:47 +00:00
|
|
|
ftype_register_ipv6();
|
2006-03-10 11:58:22 +00:00
|
|
|
ftype_register_guid();
|
2001-02-01 20:21:25 +00:00
|
|
|
ftype_register_none();
|
|
|
|
ftype_register_string();
|
|
|
|
ftype_register_time();
|
|
|
|
ftype_register_tvbuff();
|
|
|
|
}
|
|
|
|
|
2021-12-07 15:02:00 +00:00
|
|
|
void
|
|
|
|
ftypes_register_pseudofields(void)
|
|
|
|
{
|
|
|
|
static int proto_ftypes;
|
|
|
|
|
|
|
|
proto_ftypes = proto_register_protocol(
|
|
|
|
"Wireshark Field/Fundamental Types",
|
|
|
|
"Wireshark FTypes",
|
|
|
|
"_ws.ftypes");
|
|
|
|
|
|
|
|
ftype_register_pseudofields_bytes(proto_ftypes);
|
|
|
|
ftype_register_pseudofields_double(proto_ftypes);
|
|
|
|
ftype_register_pseudofields_ieee_11073_float(proto_ftypes);
|
|
|
|
ftype_register_pseudofields_integer(proto_ftypes);
|
|
|
|
ftype_register_pseudofields_ipv4(proto_ftypes);
|
|
|
|
ftype_register_pseudofields_ipv6(proto_ftypes);
|
|
|
|
ftype_register_pseudofields_guid(proto_ftypes);
|
|
|
|
ftype_register_pseudofields_string(proto_ftypes);
|
|
|
|
ftype_register_pseudofields_time(proto_ftypes);
|
|
|
|
ftype_register_pseudofields_tvbuff(proto_ftypes);
|
|
|
|
|
|
|
|
proto_set_cant_toggle(proto_ftypes);
|
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
/* Each ftype_t is registered via this function */
|
|
|
|
void
|
|
|
|
ftype_register(enum ftenum ftype, ftype_t *ft)
|
|
|
|
{
|
|
|
|
/* Check input */
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(ftype < FT_NUM_TYPES);
|
|
|
|
ws_assert(ftype == ft->ftype);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
/* Don't re-register. */
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(type_list[ftype] == NULL);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
type_list[ftype] = ft;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-21 02:12:25 +00:00
|
|
|
/* from README.dissector:
|
|
|
|
Note that the formats used must all belong to the same list as defined below:
|
|
|
|
- FT_INT8, FT_INT16, FT_INT24 and FT_INT32
|
|
|
|
- FT_UINT8, FT_UINT16, FT_UINT24, FT_UINT32, FT_IPXNET and FT_FRAMENUM
|
|
|
|
- FT_UINT64 and FT_EUI64
|
|
|
|
- FT_STRING, FT_STRINGZ and FT_UINT_STRING
|
|
|
|
- FT_FLOAT and FT_DOUBLE
|
|
|
|
- FT_BYTES, FT_UINT_BYTES, FT_AX25, FT_ETHER, FT_VINES, FT_OID and FT_REL_OID
|
|
|
|
- FT_ABSOLUTE_TIME and FT_RELATIVE_TIME
|
|
|
|
*/
|
|
|
|
static enum ftenum
|
|
|
|
same_ftype(const enum ftenum ftype)
|
|
|
|
{
|
|
|
|
switch (ftype) {
|
|
|
|
case FT_INT8:
|
|
|
|
case FT_INT16:
|
|
|
|
case FT_INT24:
|
|
|
|
case FT_INT32:
|
|
|
|
return FT_INT32;
|
|
|
|
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
|
|
|
return FT_UINT32;
|
|
|
|
|
2017-10-30 18:00:02 +00:00
|
|
|
case FT_INT40:
|
|
|
|
case FT_INT48:
|
|
|
|
case FT_INT56:
|
2014-12-17 20:19:20 +00:00
|
|
|
case FT_INT64:
|
2017-10-30 18:00:02 +00:00
|
|
|
return FT_INT64;
|
2014-12-17 20:19:20 +00:00
|
|
|
|
|
|
|
case FT_UINT40:
|
|
|
|
case FT_UINT48:
|
|
|
|
case FT_UINT56:
|
|
|
|
case FT_UINT64:
|
2017-10-30 18:00:02 +00:00
|
|
|
return FT_UINT64;
|
2014-12-17 20:19:20 +00:00
|
|
|
|
2014-02-21 02:12:25 +00:00
|
|
|
case FT_STRING:
|
|
|
|
case FT_STRINGZ:
|
|
|
|
case FT_UINT_STRING:
|
|
|
|
return FT_STRING;
|
|
|
|
|
|
|
|
case FT_FLOAT:
|
|
|
|
case FT_DOUBLE:
|
|
|
|
return FT_DOUBLE;
|
|
|
|
|
|
|
|
case FT_BYTES:
|
|
|
|
case FT_UINT_BYTES:
|
|
|
|
return FT_BYTES;
|
|
|
|
|
|
|
|
case FT_OID:
|
|
|
|
case FT_REL_OID:
|
|
|
|
return FT_OID;
|
|
|
|
|
2017-10-30 18:28:21 +00:00
|
|
|
/* XXX: the folowing are unique for now */
|
2014-02-21 02:12:25 +00:00
|
|
|
case FT_IPv4:
|
|
|
|
case FT_IPv6:
|
|
|
|
|
|
|
|
/* everything else is unique */
|
|
|
|
default:
|
|
|
|
return ftype;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* given two types, are they similar - for example can two
|
|
|
|
* duplicate fields be registered of these two types. */
|
|
|
|
gboolean
|
|
|
|
ftype_similar_types(const enum ftenum ftype_a, const enum ftenum ftype_b)
|
|
|
|
{
|
|
|
|
return (same_ftype(ftype_a) == same_ftype(ftype_b));
|
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
/* Returns a string representing the name of the type. Useful
|
|
|
|
* for glossary production. */
|
|
|
|
const char*
|
|
|
|
ftype_name(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
2003-11-25 08:50:38 +00:00
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
2001-02-01 20:21:25 +00:00
|
|
|
return ft->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
ftype_pretty_name(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
2003-11-25 08:50:38 +00:00
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
2001-02-01 20:21:25 +00:00
|
|
|
return ft->pretty_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ftype_length(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
2003-11-25 08:50:38 +00:00
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
2001-02-01 20:21:25 +00:00
|
|
|
return ft->wire_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ftype_can_slice(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
2003-11-25 08:50:38 +00:00
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
2001-02-01 20:21:25 +00:00
|
|
|
return ft->slice ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ftype_can_eq(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
2003-11-25 08:50:38 +00:00
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
2021-10-10 15:00:51 +00:00
|
|
|
return ft->cmp_order != NULL;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2021-10-27 20:56:03 +00:00
|
|
|
ftype_can_cmp(enum ftenum ftype)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
2003-11-25 08:50:38 +00:00
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
2021-10-10 15:00:51 +00:00
|
|
|
return ft->cmp_order != NULL;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
2004-02-27 12:00:32 +00:00
|
|
|
gboolean
|
|
|
|
ftype_can_bitwise_and(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
2022-02-25 19:37:53 +00:00
|
|
|
return ft->bitwise_and ? TRUE : FALSE;
|
2004-02-27 12:00:32 +00:00
|
|
|
}
|
|
|
|
|
2022-02-27 09:56:41 +00:00
|
|
|
gboolean
|
|
|
|
ftype_can_unary_minus(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
|
|
|
return ft->unary_minus != NULL;
|
|
|
|
}
|
|
|
|
|
2022-02-27 14:47:31 +00:00
|
|
|
gboolean
|
|
|
|
ftype_can_add(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
|
|
|
return ft->add != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ftype_can_subtract(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
|
|
|
return ft->subtract != NULL;
|
|
|
|
}
|
|
|
|
|
2022-03-31 13:50:20 +00:00
|
|
|
gboolean
|
|
|
|
ftype_can_multiply(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
|
|
|
return ft->multiply != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ftype_can_divide(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
|
|
|
return ft->divide != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ftype_can_modulo(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
|
|
|
return ft->modulo != NULL;
|
|
|
|
}
|
|
|
|
|
2003-08-27 15:23:11 +00:00
|
|
|
gboolean
|
|
|
|
ftype_can_contains(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
2003-11-25 08:50:38 +00:00
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
2003-08-27 15:23:11 +00:00
|
|
|
return ft->cmp_contains ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
2003-12-06 16:35:20 +00:00
|
|
|
gboolean
|
|
|
|
ftype_can_matches(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
|
|
|
return ft->cmp_matches ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
2022-02-25 19:37:53 +00:00
|
|
|
gboolean
|
2022-03-23 00:50:24 +00:00
|
|
|
ftype_can_is_zero(enum ftenum ftype)
|
2022-02-25 19:37:53 +00:00
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
2022-03-23 00:50:24 +00:00
|
|
|
return ft->is_zero ? TRUE : FALSE;
|
2022-02-25 19:37:53 +00:00
|
|
|
}
|
|
|
|
|
2022-04-13 14:30:36 +00:00
|
|
|
gboolean
|
|
|
|
ftype_can_is_negative(enum ftenum ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
|
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
|
|
|
return ft->is_negative ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
/* ---------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* Allocate and initialize an fvalue_t, given an ftype */
|
|
|
|
fvalue_t*
|
|
|
|
fvalue_new(ftenum_t ftype)
|
|
|
|
{
|
|
|
|
fvalue_t *fv;
|
|
|
|
ftype_t *ft;
|
|
|
|
FvalueNewFunc new_value;
|
|
|
|
|
2013-03-09 20:02:19 +00:00
|
|
|
fv = g_slice_new(fvalue_t);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2003-11-25 08:50:38 +00:00
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
2003-12-03 09:28:26 +00:00
|
|
|
fv->ftype = ft;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
new_value = ft->new_value;
|
|
|
|
if (new_value) {
|
|
|
|
new_value(fv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
|
2022-03-14 20:38:26 +00:00
|
|
|
fvalue_t*
|
|
|
|
fvalue_dup(const fvalue_t *fv_orig)
|
|
|
|
{
|
|
|
|
fvalue_t *fv_new;
|
|
|
|
FvalueCopyFunc copy_value;
|
|
|
|
|
|
|
|
fv_new = g_slice_new(fvalue_t);
|
|
|
|
fv_new->ftype = fv_orig->ftype;
|
|
|
|
copy_value = fv_new->ftype->copy_value;
|
|
|
|
if (copy_value != NULL) {
|
|
|
|
/* deep copy */
|
|
|
|
copy_value(fv_new, fv_orig);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* shallow copy */
|
|
|
|
memcpy(&fv_new->value, &fv_orig->value, sizeof(fv_orig->value));
|
|
|
|
}
|
|
|
|
|
|
|
|
return fv_new;
|
|
|
|
}
|
|
|
|
|
2010-05-12 17:34:11 +00:00
|
|
|
void
|
2003-12-02 21:15:49 +00:00
|
|
|
fvalue_init(fvalue_t *fv, ftenum_t ftype)
|
|
|
|
{
|
|
|
|
ftype_t *ft;
|
|
|
|
FvalueNewFunc new_value;
|
|
|
|
|
|
|
|
FTYPE_LOOKUP(ftype, ft);
|
2003-12-03 09:28:26 +00:00
|
|
|
fv->ftype = ft;
|
2003-12-02 21:15:49 +00:00
|
|
|
|
|
|
|
new_value = ft->new_value;
|
|
|
|
if (new_value) {
|
|
|
|
new_value(fv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-11 00:54:00 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2003-07-25 03:44:05 +00:00
|
|
|
fvalue_t*
|
2022-02-23 00:47:00 +00:00
|
|
|
fvalue_from_literal(ftenum_t ftype, const char *s, gboolean allow_partial_value, gchar **err_msg)
|
2003-07-25 03:44:05 +00:00
|
|
|
{
|
|
|
|
fvalue_t *fv;
|
2022-03-03 12:41:20 +00:00
|
|
|
gboolean ok = FALSE;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2003-07-25 03:44:05 +00:00
|
|
|
fv = fvalue_new(ftype);
|
2022-02-23 00:47:00 +00:00
|
|
|
if (fv->ftype->val_from_literal) {
|
2022-04-06 16:29:56 +00:00
|
|
|
ok = fv->ftype->val_from_literal(fv, s, allow_partial_value, err_msg);
|
2022-03-03 12:41:20 +00:00
|
|
|
if (ok) {
|
2015-01-18 10:22:19 +00:00
|
|
|
/* Success */
|
|
|
|
if (err_msg != NULL)
|
|
|
|
*err_msg = NULL;
|
2003-07-25 03:44:05 +00:00
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-01-18 10:22:19 +00:00
|
|
|
if (err_msg != NULL) {
|
2021-12-16 18:06:18 +00:00
|
|
|
*err_msg = ws_strdup_printf("\"%s\" cannot be converted to %s.",
|
2015-01-18 10:22:19 +00:00
|
|
|
s, ftype_pretty_name(ftype));
|
|
|
|
}
|
2003-07-25 03:44:05 +00:00
|
|
|
}
|
2021-11-11 00:54:00 +00:00
|
|
|
fvalue_free(fv);
|
2003-07-25 03:44:05 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
fvalue_t*
|
2015-01-18 10:22:19 +00:00
|
|
|
fvalue_from_string(ftenum_t ftype, const char *s, gchar **err_msg)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
|
|
|
fvalue_t *fv;
|
|
|
|
|
|
|
|
fv = fvalue_new(ftype);
|
2003-12-03 09:28:26 +00:00
|
|
|
if (fv->ftype->val_from_string) {
|
2015-01-18 10:22:19 +00:00
|
|
|
if (fv->ftype->val_from_string(fv, s, err_msg)) {
|
|
|
|
/* Success */
|
|
|
|
if (err_msg != NULL)
|
|
|
|
*err_msg = NULL;
|
2001-02-01 20:21:25 +00:00
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-01-18 10:22:19 +00:00
|
|
|
if (err_msg != NULL) {
|
2021-12-16 18:06:18 +00:00
|
|
|
*err_msg = ws_strdup_printf("\"%s\" cannot be converted to %s.",
|
2015-01-18 10:22:19 +00:00
|
|
|
s, ftype_pretty_name(ftype));
|
|
|
|
}
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
2021-11-11 00:54:00 +00:00
|
|
|
fvalue_free(fv);
|
2001-02-01 20:21:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-11-23 21:20:34 +00:00
|
|
|
fvalue_t*
|
|
|
|
fvalue_from_charconst(ftenum_t ftype, unsigned long num, gchar **err_msg)
|
|
|
|
{
|
|
|
|
fvalue_t *fv;
|
|
|
|
|
|
|
|
fv = fvalue_new(ftype);
|
|
|
|
if (fv->ftype->val_from_charconst) {
|
|
|
|
if (fv->ftype->val_from_charconst(fv, num, err_msg)) {
|
|
|
|
/* Success */
|
|
|
|
if (err_msg != NULL)
|
|
|
|
*err_msg = NULL;
|
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (err_msg != NULL) {
|
|
|
|
if (num <= 0x7f && g_ascii_isprint(num)) {
|
2021-12-16 18:06:18 +00:00
|
|
|
*err_msg = ws_strdup_printf("Character constant '%c' (0x%lx) cannot be converted to %s.",
|
2021-11-23 21:20:34 +00:00
|
|
|
(int)num, num, ftype_pretty_name(ftype));
|
|
|
|
}
|
|
|
|
else {
|
2021-12-16 18:06:18 +00:00
|
|
|
*err_msg = ws_strdup_printf("Character constant 0x%lx cannot be converted to %s.",
|
2021-11-23 21:20:34 +00:00
|
|
|
num, ftype_pretty_name(ftype));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fvalue_free(fv);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-12 22:06:00 +00:00
|
|
|
ftenum_t
|
|
|
|
fvalue_type_ftenum(fvalue_t *fv)
|
2006-05-02 14:26:17 +00:00
|
|
|
{
|
2013-11-12 22:06:00 +00:00
|
|
|
return fv->ftype->ftype;
|
2006-05-02 14:26:17 +00:00
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
const char*
|
2021-10-26 12:53:06 +00:00
|
|
|
fvalue_type_name(const fvalue_t *fv)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
2003-12-03 09:28:26 +00:00
|
|
|
return fv->ftype->name;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
guint
|
|
|
|
fvalue_length(fvalue_t *fv)
|
|
|
|
{
|
2003-12-03 09:28:26 +00:00
|
|
|
if (fv->ftype->len)
|
|
|
|
return fv->ftype->len(fv);
|
2001-02-01 20:21:25 +00:00
|
|
|
else
|
2003-12-03 09:28:26 +00:00
|
|
|
return fv->ftype->wire_size;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
2003-02-08 04:22:37 +00:00
|
|
|
char *
|
2021-10-26 12:53:06 +00:00
|
|
|
fvalue_to_string_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype, int field_display)
|
2003-02-08 04:22:37 +00:00
|
|
|
{
|
2013-11-12 22:06:00 +00:00
|
|
|
if (fv->ftype->val_to_string_repr == NULL) {
|
|
|
|
/* no value-to-string-representation function, so the value cannot be represented */
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-05-10 20:04:14 +00:00
|
|
|
|
2021-11-08 15:55:03 +00:00
|
|
|
return fv->ftype->val_to_string_repr(scope, fv, rtype, field_display);
|
2003-02-08 04:22:37 +00:00
|
|
|
}
|
|
|
|
|
2001-02-27 19:23:30 +00:00
|
|
|
typedef struct {
|
|
|
|
fvalue_t *fv;
|
2001-02-01 20:21:25 +00:00
|
|
|
GByteArray *bytes;
|
2001-02-27 19:23:30 +00:00
|
|
|
gboolean slice_failure;
|
|
|
|
} slice_data_t;
|
|
|
|
|
|
|
|
static void
|
|
|
|
slice_func(gpointer data, gpointer user_data)
|
|
|
|
{
|
2012-06-02 15:32:54 +00:00
|
|
|
drange_node *drnode = (drange_node *)data;
|
|
|
|
slice_data_t *slice_data = (slice_data_t *)user_data;
|
2001-03-02 17:04:25 +00:00
|
|
|
gint start_offset;
|
|
|
|
gint length = 0;
|
|
|
|
gint end_offset = 0;
|
2001-02-27 19:23:30 +00:00
|
|
|
guint field_length;
|
|
|
|
fvalue_t *fv;
|
2001-03-02 17:04:25 +00:00
|
|
|
drange_node_end_t ending;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2001-02-27 19:23:30 +00:00
|
|
|
if (slice_data->slice_failure) {
|
|
|
|
return;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
2001-03-02 17:04:25 +00:00
|
|
|
start_offset = drange_node_get_start_offset(drnode);
|
|
|
|
ending = drange_node_get_ending(drnode);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2001-02-27 19:23:30 +00:00
|
|
|
fv = slice_data->fv;
|
|
|
|
field_length = fvalue_length(fv);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2001-03-02 17:04:25 +00:00
|
|
|
/* Check for negative start */
|
|
|
|
if (start_offset < 0) {
|
|
|
|
start_offset = field_length + start_offset;
|
2004-06-03 07:34:49 +00:00
|
|
|
if (start_offset < 0) {
|
|
|
|
slice_data->slice_failure = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
2004-06-28 06:01:33 +00:00
|
|
|
/* Check the end type and set the length */
|
2004-05-09 08:29:48 +00:00
|
|
|
|
2010-01-19 19:37:03 +00:00
|
|
|
if (ending == DRANGE_NODE_END_T_TO_THE_END) {
|
2004-06-28 06:01:33 +00:00
|
|
|
length = field_length - start_offset;
|
|
|
|
if (length <= 0) {
|
|
|
|
slice_data->slice_failure = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
2001-02-27 19:23:30 +00:00
|
|
|
}
|
2010-01-19 19:37:03 +00:00
|
|
|
else if (ending == DRANGE_NODE_END_T_LENGTH) {
|
2001-03-02 17:04:25 +00:00
|
|
|
length = drange_node_get_length(drnode);
|
2004-06-28 06:01:33 +00:00
|
|
|
if (start_offset + length > (int) field_length) {
|
|
|
|
slice_data->slice_failure = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
2010-01-19 19:37:03 +00:00
|
|
|
else if (ending == DRANGE_NODE_END_T_OFFSET) {
|
2001-03-02 17:04:25 +00:00
|
|
|
end_offset = drange_node_get_end_offset(drnode);
|
|
|
|
if (end_offset < 0) {
|
|
|
|
end_offset = field_length + end_offset;
|
2004-06-03 07:34:49 +00:00
|
|
|
if (end_offset < start_offset) {
|
2001-03-02 17:04:25 +00:00
|
|
|
slice_data->slice_failure = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
2004-06-28 06:01:33 +00:00
|
|
|
} else if (end_offset >= (int) field_length) {
|
|
|
|
slice_data->slice_failure = TRUE;
|
|
|
|
return;
|
2001-03-02 17:04:25 +00:00
|
|
|
}
|
2004-06-03 07:34:49 +00:00
|
|
|
length = end_offset - start_offset + 1;
|
2001-03-02 17:04:25 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_not_reached();
|
2001-03-02 17:04:25 +00:00
|
|
|
}
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(start_offset >=0 && length > 0);
|
2003-12-03 09:28:26 +00:00
|
|
|
fv->ftype->slice(fv, slice_data->bytes, start_offset, length);
|
2001-02-27 19:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Returns a new FT_BYTES fvalue_t* if possible, otherwise NULL */
|
|
|
|
fvalue_t*
|
2013-03-05 06:16:45 +00:00
|
|
|
fvalue_slice(fvalue_t *fv, drange_t *d_range)
|
2001-02-27 19:23:30 +00:00
|
|
|
{
|
|
|
|
slice_data_t slice_data;
|
|
|
|
fvalue_t *new_fv;
|
|
|
|
|
|
|
|
slice_data.fv = fv;
|
|
|
|
slice_data.bytes = g_byte_array_new();
|
|
|
|
slice_data.slice_failure = FALSE;
|
|
|
|
|
|
|
|
/* XXX - We could make some optimizations here based on
|
|
|
|
* drange_has_total_length() and
|
|
|
|
* drange_get_max_offset().
|
|
|
|
*/
|
|
|
|
|
2008-06-23 20:23:29 +00:00
|
|
|
drange_foreach_drange_node(d_range, slice_func, &slice_data);
|
2001-02-27 19:23:30 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
new_fv = fvalue_new(FT_BYTES);
|
2014-01-15 01:05:03 +00:00
|
|
|
fvalue_set_byte_array(new_fv, slice_data.bytes);
|
2001-02-01 20:21:25 +00:00
|
|
|
return new_fv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2014-01-15 01:05:03 +00:00
|
|
|
fvalue_set_byte_array(fvalue_t *fv, GByteArray *value)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_BYTES ||
|
2017-03-04 15:15:54 +00:00
|
|
|
fv->ftype->ftype == FT_UINT_BYTES ||
|
|
|
|
fv->ftype->ftype == FT_OID ||
|
|
|
|
fv->ftype->ftype == FT_REL_OID ||
|
|
|
|
fv->ftype->ftype == FT_SYSTEM_ID);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->set_value.set_value_byte_array);
|
2017-03-04 15:15:54 +00:00
|
|
|
fv->ftype->set_value.set_value_byte_array(fv, value);
|
2014-01-15 01:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fvalue_set_bytes(fvalue_t *fv, const guint8 *value)
|
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_AX25 ||
|
2017-03-07 21:16:02 +00:00
|
|
|
fv->ftype->ftype == FT_VINES ||
|
|
|
|
fv->ftype->ftype == FT_ETHER ||
|
|
|
|
fv->ftype->ftype == FT_FCWWN ||
|
|
|
|
fv->ftype->ftype == FT_IPv6);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->set_value.set_value_bytes);
|
2017-03-07 21:16:02 +00:00
|
|
|
fv->ftype->set_value.set_value_bytes(fv, value);
|
2014-01-15 01:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fvalue_set_guid(fvalue_t *fv, const e_guid_t *value)
|
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_GUID);
|
|
|
|
ws_assert(fv->ftype->set_value.set_value_guid);
|
2017-03-07 21:35:45 +00:00
|
|
|
fv->ftype->set_value.set_value_guid(fv, value);
|
2014-01-15 01:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fvalue_set_time(fvalue_t *fv, const nstime_t *value)
|
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(IS_FT_TIME(fv->ftype->ftype));
|
|
|
|
ws_assert(fv->ftype->set_value.set_value_time);
|
2017-03-07 21:43:04 +00:00
|
|
|
fv->ftype->set_value.set_value_time(fv, value);
|
2014-01-15 01:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fvalue_set_string(fvalue_t *fv, const gchar *value)
|
|
|
|
{
|
2022-06-20 19:35:47 +00:00
|
|
|
ws_assert(IS_FT_STRING(fv->ftype->ftype));
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->set_value.set_value_string);
|
2017-03-09 21:56:07 +00:00
|
|
|
fv->ftype->set_value.set_value_string(fv, value);
|
2014-01-15 01:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-05-22 20:02:22 +00:00
|
|
|
fvalue_set_protocol(fvalue_t *fv, tvbuff_t *value, const gchar *name, int length)
|
2014-01-15 01:05:03 +00:00
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_PROTOCOL);
|
|
|
|
ws_assert(fv->ftype->set_value.set_value_protocol);
|
2022-05-22 20:02:22 +00:00
|
|
|
fv->ftype->set_value.set_value_protocol(fv, value, name, length);
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-01-18 11:02:26 +00:00
|
|
|
fvalue_set_uinteger(fvalue_t *fv, guint32 value)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_IEEE_11073_SFLOAT ||
|
2017-03-12 18:15:19 +00:00
|
|
|
fv->ftype->ftype == FT_IEEE_11073_FLOAT ||
|
|
|
|
fv->ftype->ftype == FT_CHAR ||
|
|
|
|
fv->ftype->ftype == FT_UINT8 ||
|
|
|
|
fv->ftype->ftype == FT_UINT16 ||
|
|
|
|
fv->ftype->ftype == FT_UINT24 ||
|
|
|
|
fv->ftype->ftype == FT_UINT32 ||
|
|
|
|
fv->ftype->ftype == FT_IPXNET ||
|
|
|
|
fv->ftype->ftype == FT_FRAMENUM ||
|
|
|
|
fv->ftype->ftype == FT_IPv4);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->set_value.set_value_uinteger);
|
2017-03-12 18:15:19 +00:00
|
|
|
fv->ftype->set_value.set_value_uinteger(fv, value);
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
2007-01-18 11:02:26 +00:00
|
|
|
void
|
|
|
|
fvalue_set_sinteger(fvalue_t *fv, gint32 value)
|
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_INT8 ||
|
2017-03-12 18:49:42 +00:00
|
|
|
fv->ftype->ftype == FT_INT16 ||
|
|
|
|
fv->ftype->ftype == FT_INT24 ||
|
|
|
|
fv->ftype->ftype == FT_INT32);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->set_value.set_value_sinteger);
|
2017-03-12 18:49:42 +00:00
|
|
|
fv->ftype->set_value.set_value_sinteger(fv, value);
|
2007-01-18 11:02:26 +00:00
|
|
|
}
|
|
|
|
|
2014-12-17 20:19:20 +00:00
|
|
|
void
|
|
|
|
fvalue_set_uinteger64(fvalue_t *fv, guint64 value)
|
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_UINT40 ||
|
2017-03-13 17:46:48 +00:00
|
|
|
fv->ftype->ftype == FT_UINT48 ||
|
|
|
|
fv->ftype->ftype == FT_UINT56 ||
|
|
|
|
fv->ftype->ftype == FT_UINT64 ||
|
|
|
|
fv->ftype->ftype == FT_BOOLEAN ||
|
|
|
|
fv->ftype->ftype == FT_EUI64);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->set_value.set_value_uinteger64);
|
2017-03-13 17:46:48 +00:00
|
|
|
fv->ftype->set_value.set_value_uinteger64(fv, value);
|
2014-12-17 20:19:20 +00:00
|
|
|
}
|
2007-01-18 11:02:26 +00:00
|
|
|
|
2004-08-22 00:31:58 +00:00
|
|
|
void
|
2014-12-17 20:19:20 +00:00
|
|
|
fvalue_set_sinteger64(fvalue_t *fv, gint64 value)
|
2004-08-22 00:31:58 +00:00
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_INT40 ||
|
2017-03-14 22:00:36 +00:00
|
|
|
fv->ftype->ftype == FT_INT48 ||
|
|
|
|
fv->ftype->ftype == FT_INT56 ||
|
|
|
|
fv->ftype->ftype == FT_INT64);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->set_value.set_value_sinteger64);
|
2017-03-14 22:00:36 +00:00
|
|
|
fv->ftype->set_value.set_value_sinteger64(fv, value);
|
2004-08-22 00:31:58 +00:00
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
void
|
|
|
|
fvalue_set_floating(fvalue_t *fv, gdouble value)
|
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_FLOAT ||
|
2017-03-15 08:37:03 +00:00
|
|
|
fv->ftype->ftype == FT_DOUBLE);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->set_value.set_value_floating);
|
2017-03-15 08:37:03 +00:00
|
|
|
fv->ftype->set_value.set_value_floating(fv, value);
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 23:31:30 +00:00
|
|
|
const guint8 *
|
|
|
|
fvalue_get_bytes(fvalue_t *fv)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_BYTES ||
|
2017-03-19 20:16:03 +00:00
|
|
|
fv->ftype->ftype == FT_UINT_BYTES ||
|
|
|
|
fv->ftype->ftype == FT_AX25 ||
|
|
|
|
fv->ftype->ftype == FT_VINES ||
|
|
|
|
fv->ftype->ftype == FT_ETHER ||
|
|
|
|
fv->ftype->ftype == FT_OID ||
|
|
|
|
fv->ftype->ftype == FT_REL_OID ||
|
|
|
|
fv->ftype->ftype == FT_SYSTEM_ID ||
|
|
|
|
fv->ftype->ftype == FT_FCWWN ||
|
2022-06-18 23:31:30 +00:00
|
|
|
fv->ftype->ftype == FT_IPv6);
|
|
|
|
ws_assert(fv->ftype->get_value.get_value_bytes);
|
|
|
|
return fv->ftype->get_value.get_value_bytes(fv);
|
|
|
|
}
|
|
|
|
|
|
|
|
const e_guid_t *
|
|
|
|
fvalue_get_guid(fvalue_t *fv)
|
|
|
|
{
|
|
|
|
ws_assert(fv->ftype->ftype == FT_GUID);
|
|
|
|
ws_assert(fv->ftype->get_value.get_value_guid);
|
|
|
|
return fv->ftype->get_value.get_value_guid(fv);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nstime_t *
|
|
|
|
fvalue_get_time(fvalue_t *fv)
|
|
|
|
{
|
|
|
|
ws_assert(IS_FT_TIME(fv->ftype->ftype));
|
|
|
|
ws_assert(fv->ftype->get_value.get_value_time);
|
|
|
|
return fv->ftype->get_value.get_value_time(fv);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
fvalue_get_string(fvalue_t *fv)
|
|
|
|
{
|
2022-06-20 19:35:47 +00:00
|
|
|
ws_assert(IS_FT_STRING(fv->ftype->ftype));
|
2022-06-18 23:31:30 +00:00
|
|
|
ws_assert(fv->ftype->get_value.get_value_string);
|
|
|
|
return fv->ftype->get_value.get_value_string(fv);
|
|
|
|
}
|
|
|
|
|
|
|
|
tvbuff_t *
|
|
|
|
fvalue_get_protocol(fvalue_t *fv)
|
|
|
|
{
|
|
|
|
ws_assert(fv->ftype->ftype == FT_PROTOCOL);
|
|
|
|
ws_assert(fv->ftype->get_value.get_value_protocol);
|
|
|
|
return fv->ftype->get_value.get_value_protocol(fv);
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
2007-01-18 11:02:26 +00:00
|
|
|
fvalue_get_uinteger(fvalue_t *fv)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_IEEE_11073_SFLOAT ||
|
2017-03-19 19:57:43 +00:00
|
|
|
fv->ftype->ftype == FT_IEEE_11073_FLOAT ||
|
|
|
|
fv->ftype->ftype == FT_CHAR ||
|
|
|
|
fv->ftype->ftype == FT_UINT8 ||
|
|
|
|
fv->ftype->ftype == FT_UINT16 ||
|
|
|
|
fv->ftype->ftype == FT_UINT24 ||
|
|
|
|
fv->ftype->ftype == FT_UINT32 ||
|
|
|
|
fv->ftype->ftype == FT_IPXNET ||
|
2017-10-30 09:40:46 +00:00
|
|
|
fv->ftype->ftype == FT_FRAMENUM ||
|
|
|
|
fv->ftype->ftype == FT_IPv4);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->get_value.get_value_uinteger);
|
2017-03-19 19:57:43 +00:00
|
|
|
return fv->ftype->get_value.get_value_uinteger(fv);
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
2007-01-18 11:02:26 +00:00
|
|
|
gint32
|
|
|
|
fvalue_get_sinteger(fvalue_t *fv)
|
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_INT8 ||
|
2017-03-19 19:32:20 +00:00
|
|
|
fv->ftype->ftype == FT_INT16 ||
|
|
|
|
fv->ftype->ftype == FT_INT24 ||
|
|
|
|
fv->ftype->ftype == FT_INT32);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->get_value.get_value_sinteger);
|
2017-03-19 19:32:20 +00:00
|
|
|
return fv->ftype->get_value.get_value_sinteger(fv);
|
2007-01-18 11:02:26 +00:00
|
|
|
}
|
|
|
|
|
2004-08-22 00:31:58 +00:00
|
|
|
guint64
|
2014-12-17 20:19:20 +00:00
|
|
|
fvalue_get_uinteger64(fvalue_t *fv)
|
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_UINT40 ||
|
2017-03-19 12:31:53 +00:00
|
|
|
fv->ftype->ftype == FT_UINT48 ||
|
|
|
|
fv->ftype->ftype == FT_UINT56 ||
|
|
|
|
fv->ftype->ftype == FT_UINT64 ||
|
|
|
|
fv->ftype->ftype == FT_BOOLEAN ||
|
|
|
|
fv->ftype->ftype == FT_EUI64);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->get_value.get_value_uinteger64);
|
2017-03-19 12:31:53 +00:00
|
|
|
return fv->ftype->get_value.get_value_uinteger64(fv);
|
2014-12-17 20:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gint64
|
|
|
|
fvalue_get_sinteger64(fvalue_t *fv)
|
2004-08-22 00:31:58 +00:00
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_INT40 ||
|
2017-03-19 12:08:06 +00:00
|
|
|
fv->ftype->ftype == FT_INT48 ||
|
|
|
|
fv->ftype->ftype == FT_INT56 ||
|
|
|
|
fv->ftype->ftype == FT_INT64);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->get_value.get_value_sinteger64);
|
2017-03-19 12:08:06 +00:00
|
|
|
return fv->ftype->get_value.get_value_sinteger64(fv);
|
2004-08-22 00:31:58 +00:00
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
double
|
|
|
|
fvalue_get_floating(fvalue_t *fv)
|
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->ftype == FT_FLOAT ||
|
2017-03-16 21:34:49 +00:00
|
|
|
fv->ftype->ftype == FT_DOUBLE);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(fv->ftype->get_value.get_value_floating);
|
2017-03-16 21:34:49 +00:00
|
|
|
return fv->ftype->get_value.get_value_floating(fv);
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 15:00:51 +00:00
|
|
|
static inline int
|
|
|
|
_fvalue_cmp(const fvalue_t *a, const fvalue_t *b)
|
|
|
|
{
|
|
|
|
/* XXX - check compatibility of a and b */
|
|
|
|
ws_assert(a->ftype->cmp_order);
|
|
|
|
return a->ftype->cmp_order(a, b);
|
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
gboolean
|
2012-11-06 13:28:59 +00:00
|
|
|
fvalue_eq(const fvalue_t *a, const fvalue_t *b)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
2021-10-10 15:00:51 +00:00
|
|
|
return _fvalue_cmp(a, b) == 0;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-11-06 13:28:59 +00:00
|
|
|
fvalue_ne(const fvalue_t *a, const fvalue_t *b)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
2021-10-10 15:00:51 +00:00
|
|
|
return _fvalue_cmp(a, b) != 0;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-11-06 13:28:59 +00:00
|
|
|
fvalue_gt(const fvalue_t *a, const fvalue_t *b)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
2021-10-10 15:00:51 +00:00
|
|
|
return _fvalue_cmp(a, b) > 0;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-11-06 13:28:59 +00:00
|
|
|
fvalue_ge(const fvalue_t *a, const fvalue_t *b)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
2021-10-10 15:00:51 +00:00
|
|
|
return _fvalue_cmp(a, b) >= 0;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-11-06 13:28:59 +00:00
|
|
|
fvalue_lt(const fvalue_t *a, const fvalue_t *b)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
2021-10-10 15:00:51 +00:00
|
|
|
return _fvalue_cmp(a, b) < 0;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-11-06 13:28:59 +00:00
|
|
|
fvalue_le(const fvalue_t *a, const fvalue_t *b)
|
2001-02-01 20:21:25 +00:00
|
|
|
{
|
2021-10-10 15:00:51 +00:00
|
|
|
return _fvalue_cmp(a, b) <= 0;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
2003-08-27 15:23:11 +00:00
|
|
|
|
|
|
|
gboolean
|
2012-11-06 13:28:59 +00:00
|
|
|
fvalue_contains(const fvalue_t *a, const fvalue_t *b)
|
2003-08-27 15:23:11 +00:00
|
|
|
{
|
|
|
|
/* XXX - check compatibility of a and b */
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(a->ftype->cmp_contains);
|
2003-12-03 09:28:26 +00:00
|
|
|
return a->ftype->cmp_contains(a, b);
|
2003-08-27 15:23:11 +00:00
|
|
|
}
|
2003-12-06 16:35:20 +00:00
|
|
|
|
|
|
|
gboolean
|
2021-11-12 15:55:14 +00:00
|
|
|
fvalue_matches(const fvalue_t *a, const ws_regex_t *re)
|
2003-12-06 16:35:20 +00:00
|
|
|
{
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert(a->ftype->cmp_matches);
|
2021-11-12 15:55:14 +00:00
|
|
|
return a->ftype->cmp_matches(a, re);
|
2021-10-15 22:47:28 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 19:37:53 +00:00
|
|
|
gboolean
|
2022-03-23 00:50:24 +00:00
|
|
|
fvalue_is_zero(const fvalue_t *a)
|
2022-02-25 19:37:53 +00:00
|
|
|
{
|
2022-03-23 00:50:24 +00:00
|
|
|
return a->ftype->is_zero(a);
|
2022-02-25 19:37:53 +00:00
|
|
|
}
|
|
|
|
|
2022-04-13 14:30:36 +00:00
|
|
|
gboolean
|
|
|
|
fvalue_is_negative(const fvalue_t *a)
|
|
|
|
{
|
|
|
|
return a->ftype->is_negative(a);
|
|
|
|
}
|
|
|
|
|
2022-03-31 13:50:20 +00:00
|
|
|
static fvalue_t *
|
|
|
|
_fvalue_binop(FvalueBinaryOp op, const fvalue_t *a, const fvalue_t *b, char **err_msg)
|
2022-02-25 19:37:53 +00:00
|
|
|
{
|
|
|
|
fvalue_t *result;
|
|
|
|
|
|
|
|
result = fvalue_new(a->ftype->ftype);
|
2022-03-31 13:50:20 +00:00
|
|
|
if (op(result, a, b, err_msg) != FT_OK) {
|
2022-02-25 19:37:53 +00:00
|
|
|
fvalue_free(result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-02-27 14:47:31 +00:00
|
|
|
fvalue_t *
|
2022-03-31 13:50:20 +00:00
|
|
|
fvalue_bitwise_and(const fvalue_t *a, const fvalue_t *b, char **err_msg)
|
2022-02-27 14:47:31 +00:00
|
|
|
{
|
2022-03-31 13:50:20 +00:00
|
|
|
/* XXX - check compatibility of a and b */
|
|
|
|
ws_assert(a->ftype->bitwise_and);
|
|
|
|
return _fvalue_binop(a->ftype->bitwise_and, a, b, err_msg);
|
|
|
|
}
|
2022-02-27 14:47:31 +00:00
|
|
|
|
2022-03-31 13:50:20 +00:00
|
|
|
fvalue_t *
|
|
|
|
fvalue_add(const fvalue_t *a, const fvalue_t *b, gchar **err_msg)
|
|
|
|
{
|
2022-02-27 14:47:31 +00:00
|
|
|
/* XXX - check compatibility of a and b */
|
|
|
|
ws_assert(a->ftype->add);
|
2022-03-31 13:50:20 +00:00
|
|
|
return _fvalue_binop(a->ftype->add, a, b, err_msg);
|
2022-02-27 14:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fvalue_t *
|
|
|
|
fvalue_subtract(const fvalue_t *a, const fvalue_t *b, gchar **err_msg)
|
|
|
|
{
|
|
|
|
/* XXX - check compatibility of a and b */
|
|
|
|
ws_assert(a->ftype->subtract);
|
2022-03-31 13:50:20 +00:00
|
|
|
return _fvalue_binop(a->ftype->subtract, a, b, err_msg);
|
|
|
|
}
|
2022-02-27 14:47:31 +00:00
|
|
|
|
2022-03-31 13:50:20 +00:00
|
|
|
fvalue_t *
|
|
|
|
fvalue_multiply(const fvalue_t *a, const fvalue_t *b, gchar **err_msg)
|
|
|
|
{
|
|
|
|
/* XXX - check compatibility of a and b */
|
|
|
|
ws_assert(a->ftype->multiply);
|
|
|
|
return _fvalue_binop(a->ftype->multiply, a, b, err_msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
fvalue_t *
|
|
|
|
fvalue_divide(const fvalue_t *a, const fvalue_t *b, gchar **err_msg)
|
|
|
|
{
|
|
|
|
/* XXX - check compatibility of a and b */
|
|
|
|
ws_assert(a->ftype->divide);
|
|
|
|
return _fvalue_binop(a->ftype->divide, a, b, err_msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
fvalue_t *
|
|
|
|
fvalue_modulo(const fvalue_t *a, const fvalue_t *b, gchar **err_msg)
|
|
|
|
{
|
|
|
|
/* XXX - check compatibility of a and b */
|
|
|
|
ws_assert(a->ftype->modulo);
|
|
|
|
return _fvalue_binop(a->ftype->modulo, a, b, err_msg);
|
2022-02-27 14:47:31 +00:00
|
|
|
}
|
|
|
|
|
2022-02-27 09:56:41 +00:00
|
|
|
fvalue_t*
|
|
|
|
fvalue_unary_minus(const fvalue_t *fv, char **err_msg)
|
|
|
|
{
|
|
|
|
fvalue_t *result;
|
|
|
|
|
|
|
|
ws_assert(fv->ftype->unary_minus);
|
|
|
|
|
|
|
|
result = fvalue_new(fv->ftype->ftype);
|
|
|
|
if (fv->ftype->unary_minus(result, fv, err_msg) != FT_OK) {
|
|
|
|
fvalue_free(result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-02-15 03:31:53 +00:00
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2015-02-15 03:31:53 +00:00
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|