Expand the ability of fvalue_to_string_repr, and modify more FT_* types
to provide that method. svn path=/trunk/; revision=7849
This commit is contained in:
parent
03731079ca
commit
6823d063ee
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Id: ftype-bytes.c,v 1.14 2003/02/08 04:22:37 gram Exp $
|
||||
* $Id: ftype-bytes.c,v 1.15 2003/06/11 21:24:53 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -58,23 +58,21 @@ bytes_fvalue_set(fvalue_t *fv, gpointer value, gboolean already_copied)
|
|||
}
|
||||
|
||||
static int
|
||||
bytes_strlen(fvalue_t *fv)
|
||||
bytes_repr_len(fvalue_t *fv, ftrepr_t rtype _U_)
|
||||
{
|
||||
/* 3 bytes for each byte of the byte "NN:" minus 1 byte
|
||||
* as there's no trailing ":" */
|
||||
* as there's no trailing ":". */
|
||||
return fv->value.bytes->len * 3 - 1;
|
||||
}
|
||||
|
||||
static char *
|
||||
bytes_to_string(fvalue_t *fv)
|
||||
static void
|
||||
bytes_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
|
||||
{
|
||||
guint8 *c;
|
||||
char *buf;
|
||||
char *write_cursor;
|
||||
unsigned int i;
|
||||
|
||||
c = fv->value.bytes->data;
|
||||
buf = g_malloc0(bytes_strlen(fv));
|
||||
write_cursor = buf;
|
||||
|
||||
for (i = 0; i < fv->value.bytes->len; i++) {
|
||||
|
@ -88,7 +86,6 @@ bytes_to_string(fvalue_t *fv)
|
|||
write_cursor += 3;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -591,8 +588,8 @@ ftype_register_bytes(void)
|
|||
bytes_fvalue_new, /* new_value */
|
||||
bytes_fvalue_free, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
bytes_to_string, /* val_to_string_repr */
|
||||
bytes_strlen, /* len_string_repr */
|
||||
bytes_to_repr, /* val_to_string_repr */
|
||||
bytes_repr_len, /* len_string_repr */
|
||||
|
||||
bytes_fvalue_set, /* set_value */
|
||||
NULL, /* set_value_integer */
|
||||
|
@ -620,8 +617,8 @@ ftype_register_bytes(void)
|
|||
bytes_fvalue_new, /* new_value */
|
||||
bytes_fvalue_free, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
bytes_to_string, /* val_to_string_repr */
|
||||
bytes_strlen, /* len_string_repr */
|
||||
bytes_to_repr, /* val_to_string_repr */
|
||||
bytes_repr_len, /* len_string_repr */
|
||||
|
||||
bytes_fvalue_set, /* set_value */
|
||||
NULL, /* set_value_integer */
|
||||
|
@ -649,8 +646,8 @@ ftype_register_bytes(void)
|
|||
bytes_fvalue_new, /* new_value */
|
||||
bytes_fvalue_free, /* free_value */
|
||||
ether_from_string, /* val_from_string */
|
||||
bytes_to_string, /* val_to_string_repr */
|
||||
bytes_strlen, /* len_string_repr */
|
||||
bytes_to_repr, /* val_to_string_repr */
|
||||
bytes_repr_len, /* len_string_repr */
|
||||
|
||||
ether_fvalue_set, /* set_value */
|
||||
NULL, /* set_value_integer */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Id: ftype-integer.c,v 1.12 2003/02/08 04:22:37 gram Exp $
|
||||
* $Id: ftype-integer.c,v 1.13 2003/06/11 21:24:53 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -170,6 +170,18 @@ boolean_fvalue_new(fvalue_t *fv)
|
|||
fv->value.integer = TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
boolean_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
boolean_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
|
||||
{
|
||||
sprintf(buf, "%s", fv->value.integer ? "1" : "0");
|
||||
}
|
||||
|
||||
/* Checks for equality with zero or non-zero */
|
||||
static gboolean
|
||||
bool_eq(fvalue_t *a, fvalue_t *b)
|
||||
|
@ -206,22 +218,22 @@ ftype_register_integers(void)
|
|||
{
|
||||
|
||||
static ftype_t uint8_type = {
|
||||
"FT_UINT8",
|
||||
"unsigned, 1 byte",
|
||||
1,
|
||||
int_fvalue_new,
|
||||
NULL,
|
||||
val_from_string,
|
||||
"FT_UINT8", /* name */
|
||||
"unsigned, 1 byte", /* pretty name */
|
||||
1, /* wire_size */
|
||||
int_fvalue_new, /* new_value */
|
||||
NULL, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
NULL, /* val_to_string_repr */
|
||||
NULL, /* len_string_repr */
|
||||
|
||||
NULL,
|
||||
set_integer,
|
||||
NULL,
|
||||
NULL, /* set_value */
|
||||
set_integer, /* set_value_integer */
|
||||
NULL, /* set_value_floating */
|
||||
|
||||
NULL,
|
||||
get_integer,
|
||||
NULL,
|
||||
NULL, /* get_value */
|
||||
get_integer, /* get_value_integer */
|
||||
NULL, /* get_value_floating */
|
||||
|
||||
cmp_eq,
|
||||
cmp_ne,
|
||||
|
@ -230,26 +242,26 @@ ftype_register_integers(void)
|
|||
u_cmp_lt,
|
||||
u_cmp_le,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* len */
|
||||
NULL, /* slice */
|
||||
};
|
||||
static ftype_t uint16_type = {
|
||||
"FT_UINT16",
|
||||
"unsigned, 2 bytes",
|
||||
2,
|
||||
int_fvalue_new,
|
||||
NULL,
|
||||
val_from_string,
|
||||
"FT_UINT16", /* name */
|
||||
"unsigned, 2 bytes", /* pretty_name */
|
||||
2, /* wire_size */
|
||||
int_fvalue_new, /* new_value */
|
||||
NULL, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
NULL, /* val_to_string_repr */
|
||||
NULL, /* len_string_repr */
|
||||
|
||||
NULL,
|
||||
set_integer,
|
||||
NULL,
|
||||
NULL, /* set_value */
|
||||
set_integer, /* set_value_integer */
|
||||
NULL, /* set_value_floating */
|
||||
|
||||
NULL,
|
||||
get_integer,
|
||||
NULL,
|
||||
NULL, /* get_value */
|
||||
get_integer, /* get_value_integer */
|
||||
NULL, /* get_value_floating */
|
||||
|
||||
cmp_eq,
|
||||
cmp_ne,
|
||||
|
@ -258,26 +270,26 @@ ftype_register_integers(void)
|
|||
u_cmp_lt,
|
||||
u_cmp_le,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* len */
|
||||
NULL, /* slice */
|
||||
};
|
||||
static ftype_t uint24_type = {
|
||||
"FT_UINT24",
|
||||
"unsigned, 3 bytes",
|
||||
3,
|
||||
int_fvalue_new,
|
||||
NULL,
|
||||
val_from_string,
|
||||
"FT_UINT24", /* name */
|
||||
"unsigned, 3 bytes", /* pretty_name */
|
||||
3, /* wire_size */
|
||||
int_fvalue_new, /* new_value */
|
||||
NULL, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
NULL, /* val_to_string_repr */
|
||||
NULL, /* len_string_repr */
|
||||
|
||||
NULL,
|
||||
set_integer,
|
||||
NULL,
|
||||
NULL, /* set_value */
|
||||
set_integer, /* set_value_integer */
|
||||
NULL, /* set_value_floating */
|
||||
|
||||
NULL,
|
||||
get_integer,
|
||||
NULL,
|
||||
NULL, /* get_value */
|
||||
get_integer, /* get_value_integer */
|
||||
NULL, /* get_value_floating */
|
||||
|
||||
cmp_eq,
|
||||
cmp_ne,
|
||||
|
@ -286,26 +298,26 @@ ftype_register_integers(void)
|
|||
u_cmp_lt,
|
||||
u_cmp_le,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* len */
|
||||
NULL, /* slice */
|
||||
};
|
||||
static ftype_t uint32_type = {
|
||||
"FT_UINT32",
|
||||
"unsigned, 4 bytes",
|
||||
4,
|
||||
int_fvalue_new,
|
||||
NULL,
|
||||
val_from_string,
|
||||
"FT_UINT32", /* name */
|
||||
"unsigned, 4 bytes", /* pretty_name */
|
||||
4, /* wire_size */
|
||||
int_fvalue_new, /* new_value */
|
||||
NULL, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
NULL, /* val_to_string_repr */
|
||||
NULL, /* len_string_repr */
|
||||
|
||||
NULL,
|
||||
set_integer,
|
||||
NULL,
|
||||
NULL, /* set_value */
|
||||
set_integer, /* set_value_integer */
|
||||
NULL, /* set_value_floating */
|
||||
|
||||
NULL,
|
||||
get_integer,
|
||||
NULL,
|
||||
NULL, /* get_value */
|
||||
get_integer, /* get_value_integer */
|
||||
NULL, /* get_value_floating */
|
||||
|
||||
cmp_eq,
|
||||
cmp_ne,
|
||||
|
@ -314,26 +326,26 @@ ftype_register_integers(void)
|
|||
u_cmp_lt,
|
||||
u_cmp_le,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* len */
|
||||
NULL, /* slice */
|
||||
};
|
||||
static ftype_t int8_type = {
|
||||
"FT_INT8",
|
||||
"signed, 1 byte",
|
||||
1,
|
||||
int_fvalue_new,
|
||||
NULL,
|
||||
val_from_string,
|
||||
"FT_INT8", /* name */
|
||||
"signed, 1 byte", /* pretty_name */
|
||||
1, /* wire_size */
|
||||
int_fvalue_new, /* new_value */
|
||||
NULL, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
NULL, /* val_to_string_repr */
|
||||
NULL, /* len_string_repr */
|
||||
|
||||
NULL,
|
||||
set_integer,
|
||||
NULL,
|
||||
NULL, /* set_value */
|
||||
set_integer, /* set_value_integer */
|
||||
NULL, /* set_value_floating */
|
||||
|
||||
NULL,
|
||||
get_integer,
|
||||
NULL,
|
||||
NULL, /* get_value */
|
||||
get_integer, /* get_value_integer */
|
||||
NULL, /* get_value_floating */
|
||||
|
||||
cmp_eq,
|
||||
cmp_ne,
|
||||
|
@ -342,26 +354,26 @@ ftype_register_integers(void)
|
|||
s_cmp_lt,
|
||||
s_cmp_le,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* len */
|
||||
NULL, /* slice */
|
||||
};
|
||||
static ftype_t int16_type = {
|
||||
"FT_INT16",
|
||||
"signed, 2 bytes",
|
||||
2,
|
||||
int_fvalue_new,
|
||||
NULL,
|
||||
val_from_string,
|
||||
"FT_INT16", /* name */
|
||||
"signed, 2 bytes", /* pretty_name */
|
||||
2, /* wire_size */
|
||||
int_fvalue_new, /* new_value */
|
||||
NULL, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
NULL, /* val_to_string_repr */
|
||||
NULL, /* len_string_repr */
|
||||
|
||||
NULL,
|
||||
set_integer,
|
||||
NULL,
|
||||
NULL, /* set_value */
|
||||
set_integer, /* set_value_integer */
|
||||
NULL, /* set_value_floating */
|
||||
|
||||
NULL,
|
||||
get_integer,
|
||||
NULL,
|
||||
NULL, /* get_value */
|
||||
get_integer, /* get_value_integer */
|
||||
NULL, /* get_value_floating */
|
||||
|
||||
cmp_eq,
|
||||
cmp_ne,
|
||||
|
@ -370,26 +382,26 @@ ftype_register_integers(void)
|
|||
s_cmp_lt,
|
||||
s_cmp_le,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* len */
|
||||
NULL, /* slice */
|
||||
};
|
||||
static ftype_t int24_type = {
|
||||
"FT_INT24",
|
||||
"signed, 3 bytes",
|
||||
3,
|
||||
int_fvalue_new,
|
||||
NULL,
|
||||
val_from_string,
|
||||
"FT_INT24", /* name */
|
||||
"signed, 3 bytes", /* pretty_name */
|
||||
3, /* wire_size */
|
||||
int_fvalue_new, /* new_value */
|
||||
NULL, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
NULL, /* val_to_string_repr */
|
||||
NULL, /* len_string_repr */
|
||||
|
||||
NULL,
|
||||
set_integer,
|
||||
NULL,
|
||||
NULL, /* set_value */
|
||||
set_integer, /* set_value_integer */
|
||||
NULL, /* set_value_floating */
|
||||
|
||||
NULL,
|
||||
get_integer,
|
||||
NULL,
|
||||
NULL, /* get_value */
|
||||
get_integer, /* get_value_integer */
|
||||
NULL, /* get_value_floating */
|
||||
|
||||
cmp_eq,
|
||||
cmp_ne,
|
||||
|
@ -398,26 +410,26 @@ ftype_register_integers(void)
|
|||
s_cmp_lt,
|
||||
s_cmp_le,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* len */
|
||||
NULL, /* slice */
|
||||
};
|
||||
static ftype_t int32_type = {
|
||||
"FT_INT32",
|
||||
"signed, 4 bytes",
|
||||
4,
|
||||
int_fvalue_new,
|
||||
NULL,
|
||||
val_from_string,
|
||||
"FT_INT32", /* name */
|
||||
"signed, 4 bytes", /* pretty_name */
|
||||
4, /* wire_size */
|
||||
int_fvalue_new, /* new_value */
|
||||
NULL, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
NULL, /* val_to_string_repr */
|
||||
NULL, /* len_string_repr */
|
||||
|
||||
NULL,
|
||||
set_integer,
|
||||
NULL,
|
||||
NULL, /* set_value */
|
||||
set_integer, /* set_value_integer */
|
||||
NULL, /* set_value_floating */
|
||||
|
||||
NULL,
|
||||
get_integer,
|
||||
NULL,
|
||||
NULL, /* get_value */
|
||||
get_integer, /* get_value_integer */
|
||||
NULL, /* get_value_floating */
|
||||
|
||||
cmp_eq,
|
||||
cmp_ne,
|
||||
|
@ -426,55 +438,55 @@ ftype_register_integers(void)
|
|||
s_cmp_lt,
|
||||
s_cmp_le,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* len */
|
||||
NULL, /* slice */
|
||||
};
|
||||
static ftype_t boolean_type = {
|
||||
"FT_BOOLEAN",
|
||||
"Boolean",
|
||||
0,
|
||||
boolean_fvalue_new,
|
||||
NULL,
|
||||
val_from_string,
|
||||
NULL, /* val_to_string_repr */
|
||||
NULL, /* len_string_repr */
|
||||
"FT_BOOLEAN", /* name */
|
||||
"Boolean", /* pretty_name */
|
||||
0, /* wire_size */
|
||||
boolean_fvalue_new, /* new_value */
|
||||
NULL, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
boolean_to_repr, /* val_to_string_repr */
|
||||
boolean_repr_len, /* len_string_repr */
|
||||
|
||||
NULL,
|
||||
set_integer,
|
||||
NULL,
|
||||
NULL, /* set_value */
|
||||
set_integer, /* set_value_integer */
|
||||
NULL, /* set_value_floating */
|
||||
|
||||
NULL,
|
||||
get_integer,
|
||||
NULL,
|
||||
NULL, /* get_value */
|
||||
get_integer, /* get_value_integer */
|
||||
NULL, /* get_value_floating */
|
||||
|
||||
bool_eq,
|
||||
bool_ne,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
bool_eq, /* cmp_eq */
|
||||
bool_ne, /* cmp_ne */
|
||||
NULL, /* cmp_gt */
|
||||
NULL, /* cmp_ge */
|
||||
NULL, /* cmp_lt */
|
||||
NULL, /* cmp_le */
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* len */
|
||||
NULL, /* slice */
|
||||
};
|
||||
|
||||
static ftype_t ipxnet_type = {
|
||||
"FT_IPXNET",
|
||||
"IPX network number",
|
||||
4,
|
||||
int_fvalue_new,
|
||||
NULL,
|
||||
ipxnet_from_string,
|
||||
"FT_IPXNET", /* name */
|
||||
"IPX network number", /* pretty_name */
|
||||
4, /* wire_size */
|
||||
int_fvalue_new, /* new_value */
|
||||
NULL, /* free_value */
|
||||
ipxnet_from_string, /* val_from_string */
|
||||
NULL, /* val_to_string_repr */
|
||||
NULL, /* len_string_repr */
|
||||
|
||||
NULL,
|
||||
set_integer,
|
||||
NULL,
|
||||
NULL, /* set_value */
|
||||
set_integer, /* set_value_integer */
|
||||
NULL, /* set_value_floating */
|
||||
|
||||
NULL,
|
||||
get_integer,
|
||||
NULL,
|
||||
NULL, /* get_value */
|
||||
get_integer, /* get_value_integer */
|
||||
NULL, /* get_value_floating */
|
||||
|
||||
cmp_eq,
|
||||
cmp_ne,
|
||||
|
@ -483,27 +495,27 @@ ftype_register_integers(void)
|
|||
u_cmp_lt,
|
||||
u_cmp_le,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* len */
|
||||
NULL, /* slice */
|
||||
};
|
||||
|
||||
static ftype_t framenum_type = {
|
||||
"FT_FRAMENUM",
|
||||
"frame number",
|
||||
4,
|
||||
int_fvalue_new,
|
||||
NULL,
|
||||
val_from_string,
|
||||
"FT_FRAMENUM", /* name */
|
||||
"frame number", /* pretty_name */
|
||||
4, /* wire_size */
|
||||
int_fvalue_new, /* new_value */
|
||||
NULL, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
NULL, /* val_to_string_repr */
|
||||
NULL, /* len_string_repr */
|
||||
|
||||
NULL,
|
||||
set_integer,
|
||||
NULL,
|
||||
NULL, /* set_value */
|
||||
set_integer, /* set_value_integer */
|
||||
NULL, /* set_value_floating */
|
||||
|
||||
NULL,
|
||||
get_integer,
|
||||
NULL,
|
||||
NULL, /* get_value */
|
||||
get_integer, /* get_value_integer */
|
||||
NULL, /* get_value_floating */
|
||||
|
||||
cmp_eq,
|
||||
cmp_ne,
|
||||
|
@ -512,8 +524,8 @@ ftype_register_integers(void)
|
|||
u_cmp_lt,
|
||||
u_cmp_le,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* len */
|
||||
NULL, /* slice */
|
||||
};
|
||||
|
||||
ftype_register(FT_UINT8, &uint8_type);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Id: ftype-string.c,v 1.8 2003/02/08 04:22:37 gram Exp $
|
||||
* $Id: ftype-string.c,v 1.9 2003/06/11 21:24:53 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -53,6 +53,31 @@ string_fvalue_set(fvalue_t *fv, gpointer value, gboolean already_copied)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
string_repr_len(fvalue_t *fv, ftrepr_t rtype)
|
||||
{
|
||||
switch (rtype) {
|
||||
case FTREPR_DISPLAY:
|
||||
return strlen(fv->value.string);
|
||||
case FTREPR_DFILTER:
|
||||
return strlen(fv->value.string) + 2;
|
||||
}
|
||||
g_assert_not_reached();
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
string_to_repr(fvalue_t *fv, ftrepr_t rtype, char *buf)
|
||||
{
|
||||
if (rtype == FTREPR_DFILTER) {
|
||||
sprintf(buf, "\"%s\"", fv->value.string);
|
||||
}
|
||||
else {
|
||||
strcpy(buf, fv->value.string);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static gpointer
|
||||
value_get(fvalue_t *fv)
|
||||
{
|
||||
|
@ -124,22 +149,22 @@ ftype_register_string(void)
|
|||
{
|
||||
|
||||
static ftype_t string_type = {
|
||||
"FT_STRING",
|
||||
"character string",
|
||||
0,
|
||||
string_fvalue_new,
|
||||
string_fvalue_free,
|
||||
val_from_string,
|
||||
NULL, /* val_to_string_repr */
|
||||
NULL, /* len_string_repr */
|
||||
"FT_STRING", /* name */
|
||||
"character string", /* pretty_name */
|
||||
0, /* wire_size */
|
||||
string_fvalue_new, /* new_value */
|
||||
string_fvalue_free, /* free_value */
|
||||
val_from_string, /* val_from_string */
|
||||
string_to_repr, /* val_to_string_repr */
|
||||
string_repr_len, /* len_string_repr */
|
||||
|
||||
string_fvalue_set,
|
||||
NULL,
|
||||
NULL,
|
||||
string_fvalue_set, /* set_value */
|
||||
NULL, /* set_value_integer */
|
||||
NULL, /* set_value_floating */
|
||||
|
||||
value_get,
|
||||
NULL,
|
||||
NULL,
|
||||
value_get, /* get_value */
|
||||
NULL, /* get_value_integer */
|
||||
NULL, /* get_value_floating */
|
||||
|
||||
cmp_eq,
|
||||
cmp_ne,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Id: ftypes-int.h,v 1.7 2003/02/08 04:22:37 gram Exp $
|
||||
* $Id: ftypes-int.h,v 1.8 2003/06/11 21:24:54 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -30,8 +30,8 @@ typedef void (*FvalueNewFunc)(fvalue_t*);
|
|||
typedef void (*FvalueFreeFunc)(fvalue_t*);
|
||||
|
||||
typedef gboolean (*FvalueFromString)(fvalue_t*, char*, LogFunc);
|
||||
typedef char* (*FvalueToStringRepr)(fvalue_t*);
|
||||
typedef int (*FvalueStringReprLen)(fvalue_t*);
|
||||
typedef void (*FvalueToStringRepr)(fvalue_t*, ftrepr_t, char*);
|
||||
typedef int (*FvalueStringReprLen)(fvalue_t*, ftrepr_t);
|
||||
|
||||
typedef void (*FvalueSetFunc)(fvalue_t*, gpointer, gboolean);
|
||||
typedef void (*FvalueSetIntegerFunc)(fvalue_t*, guint32);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Id: ftypes.c,v 1.8 2003/02/08 04:22:37 gram Exp $
|
||||
* $Id: ftypes.c,v 1.9 2003/06/11 21:24:54 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -25,6 +25,7 @@
|
|||
#endif
|
||||
|
||||
#include <ftypes-int.h>
|
||||
#include <glib.h>
|
||||
|
||||
/* Keep track of ftype_t's via their ftenum number */
|
||||
static ftype_t* type_list[FT_NUM_TYPES];
|
||||
|
@ -272,17 +273,21 @@ fvalue_length(fvalue_t *fv)
|
|||
}
|
||||
|
||||
int
|
||||
fvalue_string_repr_len(fvalue_t *fv)
|
||||
fvalue_string_repr_len(fvalue_t *fv, ftrepr_t rtype)
|
||||
{
|
||||
g_assert(fv->ftype->len_string_repr);
|
||||
return fv->ftype->len_string_repr(fv);
|
||||
return fv->ftype->len_string_repr(fv, rtype);
|
||||
}
|
||||
|
||||
char *
|
||||
fvalue_to_string_repr(fvalue_t *fv)
|
||||
fvalue_to_string_repr(fvalue_t *fv, ftrepr_t rtype, char *buf)
|
||||
{
|
||||
g_assert(fv->ftype->val_to_string_repr);
|
||||
return fv->ftype->val_to_string_repr(fv);
|
||||
if (!buf) {
|
||||
buf = g_malloc0(fvalue_string_repr_len(fv, rtype) + 1);
|
||||
}
|
||||
fv->ftype->val_to_string_repr(fv, rtype, buf);
|
||||
return buf;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* ftypes.h
|
||||
* Definitions for field types
|
||||
*
|
||||
* $Id: ftypes.h,v 1.16 2003/02/08 04:22:37 gram Exp $
|
||||
* $Id: ftypes.h,v 1.17 2003/06/11 21:24:54 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -65,6 +65,14 @@ enum ftenum {
|
|||
typedef enum ftenum ftenum_t;
|
||||
typedef struct _ftype_t ftype_t;
|
||||
|
||||
/* String representation types. */
|
||||
enum ftrepr {
|
||||
FTREPR_DISPLAY,
|
||||
FTREPR_DFILTER
|
||||
};
|
||||
|
||||
typedef enum ftrepr ftrepr_t;
|
||||
|
||||
/* Initialize the ftypes subsytem. Called once. */
|
||||
void
|
||||
ftypes_initialize(void);
|
||||
|
@ -145,11 +153,22 @@ typedef void (*LogFunc)(char*,...);
|
|||
fvalue_t*
|
||||
fvalue_from_string(ftenum_t ftype, char *s, LogFunc log);
|
||||
|
||||
/* Returns the length of the string required to hold the
|
||||
* string representation of the the field value.
|
||||
* The length DOES NOT include the terminating NUL. */
|
||||
int
|
||||
fvalue_string_repr_len(fvalue_t *fv);
|
||||
fvalue_string_repr_len(fvalue_t *fv, ftrepr_t rtype);
|
||||
|
||||
/* Creates the string representation of the field value.
|
||||
* If given non-NULL 'buf', the string is written at the memory
|
||||
* location pointed to by 'buf'. If 'buf' is NULL, new memory
|
||||
* is malloc'ed and the string representation is written there.
|
||||
* The pointer to the beginning of the string representation is
|
||||
* returned. If 'buf' was NULL, this points to the newly-allocated
|
||||
* memory. if 'buf' was non-NULL, then the return value will be
|
||||
* 'buf'. */
|
||||
char *
|
||||
fvalue_to_string_repr(fvalue_t *fv);
|
||||
fvalue_to_string_repr(fvalue_t *fv, ftrepr_t rtype, char *buf);
|
||||
|
||||
const char*
|
||||
fvalue_type_name(fvalue_t *fv);
|
||||
|
|
55
epan/proto.c
55
epan/proto.c
|
@ -1,7 +1,7 @@
|
|||
/* proto.c
|
||||
* Routines for protocol tree
|
||||
*
|
||||
* $Id: proto.c,v 1.90 2003/06/10 18:03:23 guy Exp $
|
||||
* $Id: proto.c,v 1.91 2003/06/11 21:24:53 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -3421,6 +3421,7 @@ proto_can_match_selected(field_info *finfo, epan_dissect_t *edt)
|
|||
case FT_ETHER:
|
||||
case FT_BYTES:
|
||||
case FT_UINT_BYTES:
|
||||
case FT_PROTOCOL:
|
||||
/*
|
||||
* These all have values, so we can match.
|
||||
*/
|
||||
|
@ -3511,19 +3512,6 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
|
|||
*/
|
||||
switch(hfinfo->type) {
|
||||
|
||||
case FT_BOOLEAN:
|
||||
/*
|
||||
* 4 bytes for " == ".
|
||||
* 1 byte for 1 or 0.
|
||||
* 1 byte for the trailing '\0'.
|
||||
*/
|
||||
dfilter_len = abbrev_len + 4 + 1 + 1;
|
||||
buf = g_malloc0(dfilter_len);
|
||||
snprintf(buf, dfilter_len, "%s == %s",
|
||||
hfinfo->abbrev,
|
||||
fvalue_get_integer(finfo->value) ? "1" : "0");
|
||||
break;
|
||||
|
||||
case FT_UINT8:
|
||||
case FT_UINT16:
|
||||
case FT_UINT24:
|
||||
|
@ -3680,38 +3668,33 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
|
|||
hfinfo->abbrev, value_str);
|
||||
break;
|
||||
|
||||
case FT_STRING:
|
||||
case FT_STRINGZ:
|
||||
case FT_UINT_STRING:
|
||||
/*
|
||||
* 4 bytes for " == ".
|
||||
* N bytes for the string.
|
||||
* 2 bytes for the opening and closing quotes.
|
||||
* 1 byte for the trailing '\0'.
|
||||
*/
|
||||
value_str = fvalue_get(finfo->value);
|
||||
dfilter_len = abbrev_len + strlen(value_str) + 4 + 2 + 1;
|
||||
buf = g_malloc0(dfilter_len);
|
||||
snprintf(buf, dfilter_len, "%s == \"%s\"",
|
||||
hfinfo->abbrev, value_str);
|
||||
break;
|
||||
|
||||
/* These use the fvalue's "to_string_repr" method. */
|
||||
case FT_BOOLEAN:
|
||||
case FT_STRING:
|
||||
case FT_ETHER:
|
||||
case FT_BYTES:
|
||||
case FT_UINT_BYTES:
|
||||
/*
|
||||
* 4 bytes for " == ".
|
||||
* 1 byte for the trailing '\0'.
|
||||
/* Figure out the string length needed.
|
||||
* The ft_repr length.
|
||||
* 4 bytes for " == ".
|
||||
* 1 byte for trailing NUL.
|
||||
*/
|
||||
dfilter_len = fvalue_string_repr_len(finfo->value);
|
||||
dfilter_len = fvalue_string_repr_len(finfo->value,
|
||||
FTREPR_DFILTER);
|
||||
dfilter_len += abbrev_len + 4 + 1;
|
||||
buf = g_malloc0(dfilter_len);
|
||||
|
||||
/* Create the string */
|
||||
snprintf(buf, dfilter_len, "%s == ", hfinfo->abbrev);
|
||||
stringified = fvalue_to_string_repr(finfo->value);
|
||||
strcat(buf, stringified);
|
||||
g_free(stringified);
|
||||
fvalue_to_string_repr(finfo->value,
|
||||
FTREPR_DFILTER,
|
||||
&buf[abbrev_len + 4]);
|
||||
break;
|
||||
|
||||
case FT_PROTOCOL:
|
||||
buf = g_strdup(finfo->hfinfo->abbrev);
|
||||
|
||||
default:
|
||||
/*
|
||||
* This doesn't have a value, so we'd match
|
||||
|
|
Loading…
Reference in New Issue