/*
- * $Id: ftype-string.c,v 1.17 2003/12/09 23:02:39 obiot Exp $
+ * $Id$
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
#include <ftypes-int.h>
#include <string.h>
+#include <epan/emem.h>
#ifdef HAVE_LIBPCRE
#include <pcre.h>
#define CMP_MATCHES NULL
#endif
+#include <ctype.h>
+
static void
string_fvalue_new(fvalue_t *fv)
{
static void
string_fvalue_set(fvalue_t *fv, gpointer value, gboolean already_copied)
{
- g_assert(value != NULL);
+ DISSECTOR_ASSERT(value != NULL);
/* Free up the old value, if we have one */
string_fvalue_free(fv);
case FTREPR_DFILTER:
repr_len = 0;
for (p = fv->value.string; (c = *p) != '\0'; p++) {
+ /* Backslashes and double-quotes must
+ * be escaped */
if (c == '\\' || c == '"') {
- /* Backslashes and double-quotes
- must be escaped. */
+ repr_len += 2;
+ }
+ /* Values that can't nicely be represented
+ * in ASCII need to be escaped. */
+ else if (!isprint((unsigned char)c)) {
+ /* c --> \xNN */
+ repr_len += 4;
+ }
+ /* Other characters are just passed through. */
+ else {
repr_len++;
}
- repr_len++;
}
return repr_len + 2; /* string plus leading and trailing quotes */
}
{
gchar *p, c;
char *bufp;
+ char hex[3];
if (rtype == FTREPR_DFILTER) {
bufp = buf;
*bufp++ = '"';
for (p = fv->value.string; (c = *p) != '\0'; p++) {
+ /* Backslashes and double-quotes must
+ * be escaped. */
if (c == '\\' || c == '"') {
- /* Backslashes and double-quotes
- must be escaped. */
*bufp++ = '\\';
+ *bufp++ = c;
+ }
+ /* Values that can't nicely be represented
+ * in ASCII need to be escaped. */
+ else if (!isprint((unsigned char)c)) {
+ /* c --> \xNN */
+ sprintf(hex, "%02x", (unsigned char) c);
+ *bufp++ = '\\';
+ *bufp++ = 'x';
+ *bufp++ = hex[0];
+ *bufp++ = hex[1];
+ }
+ /* Other characters are just passed through. */
+ else {
+ *bufp++ = c;
}
- *bufp++ = c;
}
*bufp++ = '"';
*bufp = '\0';
int num_bytes = fv_bytes->value.bytes->len;
fv->value.string = g_malloc(num_bytes + 1);
- memcpy(fv->value.string, fv->value.bytes->data, num_bytes);
+ memcpy(fv->value.string, fv_bytes->value.bytes->data, num_bytes);
fv->value.string[num_bytes] = '\0';
FVALUE_FREE(fv_bytes);
{
guint8* data;
- data = fv->value.string + offset;
+ data = fv->value.ustring + offset;
g_byte_array_append(bytes, data, length);
}
static gboolean
cmp_matches(fvalue_t *fv_a, fvalue_t *fv_b)
{
+ char *str = fv_a->value.string;
+ pcre_tuple_t *pcre = fv_b->value.re;
int options = 0;
int rc;
if (strcmp(fv_b->ftype->name, "FT_PCRE") != 0) {
return FALSE;
}
- if (! fv_b->value.re) {
+ if (! pcre) {
return FALSE;
}
rc = pcre_exec(
- (fv_b->value.re)->re, /* Compiled PCRE */
- (fv_b->value.re)->ex, /* PCRE extra from pcre_study() */
- fv_a->value.string, /* The data to check for the pattern... */
- (int)strlen(fv_a->value.string), /* ... and its length */
+ pcre->re, /* Compiled PCRE */
+ pcre->ex, /* PCRE extra from pcre_study() */
+ str, /* The data to check for the pattern... */
+ (int)strlen(str), /* ... and its length */
0, /* Start offset within data */
options, /* PCRE options */
NULL, /* We are not interested in the matched string */
{
static ftype_t string_type = {
+ FT_STRING, /* ftype */
"FT_STRING", /* name */
"character string", /* pretty_name */
0, /* wire_size */
string_fvalue_set, /* set_value */
NULL, /* set_value_integer */
+ NULL, /* set_value_integer64 */
NULL, /* set_value_floating */
value_get, /* get_value */
NULL, /* get_value_integer */
+ NULL, /* get_value_integer64 */
NULL, /* get_value_floating */
cmp_eq,
cmp_ge,
cmp_lt,
cmp_le,
+ NULL, /* cmp_bitwise_and */
cmp_contains,
CMP_MATCHES,
slice,
};
static ftype_t stringz_type = {
- "FT_STRINGZ",
- "character string",
- 0,
- string_fvalue_new,
- string_fvalue_free,
+ FT_STRINGZ, /* ftype */
+ "FT_STRINGZ", /* name */
+ "character string", /* pretty name */
+ 0, /* wire_size */
+ string_fvalue_new, /* new_value */
+ string_fvalue_free, /* free_value */
val_from_unparsed, /* val_from_unparsed */
val_from_string, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ 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_integer64 */
+ NULL, /* set_value_floating */
- value_get,
- NULL,
- NULL,
+ value_get, /* get_value */
+ NULL, /* get_value_integer */
+ NULL, /* get_value_integer64 */
+ NULL, /* get_value_floating */
cmp_eq,
cmp_ne,
cmp_ge,
cmp_lt,
cmp_le,
+ NULL, /* cmp_bitwise_and */
cmp_contains, /* cmp_contains */
CMP_MATCHES,
slice,
};
static ftype_t uint_string_type = {
- "FT_UINT_STRING",
- "character string",
- 0,
- string_fvalue_new,
- string_fvalue_free,
+ FT_UINT_STRING, /* ftype */
+ "FT_UINT_STRING", /* name */
+ "character string", /* pretty_name */
+ 0, /* wire_size */
+ string_fvalue_new, /* new_value */
+ string_fvalue_free, /* free_value */
val_from_unparsed, /* val_from_unparsed */
val_from_string, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ 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_integer64 */
+ NULL, /* set_value_floating */
- value_get,
- NULL,
- NULL,
+ value_get, /* get_value */
+ NULL, /* get_value_integer */
+ NULL, /* get_value_integer64 */
+ NULL, /* get_value_floating */
cmp_eq,
cmp_ne,
cmp_ge,
cmp_lt,
cmp_le,
+ NULL, /* cmp_bitwise_and */
cmp_contains, /* cmp_contains */
CMP_MATCHES,