diff options
author | Gilbert Ramirez <gram@alumni.rice.edu> | 2000-08-01 18:10:06 +0000 |
---|---|---|
committer | Gilbert Ramirez <gram@alumni.rice.edu> | 2000-08-01 18:10:06 +0000 |
commit | 5f3191082f81e0c596259143eeb805ab78086351 (patch) | |
tree | 2c043dd3320e0997cabbd9902b688a45ce1a8f06 /dfilter.c | |
parent | 2bcc0d3c1366e47f1f26f0f65d862aa578281590 (diff) |
Allow filtering on strings.
svn path=/trunk/; revision=2193
Diffstat (limited to 'dfilter.c')
-rw-r--r-- | dfilter.c | 72 |
1 files changed, 71 insertions, 1 deletions
@@ -1,7 +1,7 @@ /* dfilter.c * Routines for display filters * - * $Id: dfilter.c,v 1.35 2000/07/22 15:58:53 gram Exp $ + * $Id: dfilter.c,v 1.36 2000/08/01 18:10:05 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -225,10 +225,19 @@ dfilter_new(void) df->node_memchunk = g_mem_chunk_new("df->node_memchunk", sizeof(dfilter_node), 20 * sizeof(dfilter_node), G_ALLOC_ONLY); df->list_of_byte_arrays = NULL; + df->list_of_strings = NULL; return df; } +static void +free_string(gpointer data, gpointer user_data) +{ + char *string = data; + if (string) + g_free(string); +} + /* Frees all memory used by dfilter, and frees dfilter itself */ void dfilter_destroy(dfilter *df) @@ -249,8 +258,15 @@ dfilter_destroy(dfilter *df) g_slist_free(df->list_of_byte_arrays); } + /* clear the allocated strings */ + if (df->list_of_strings) { + g_slist_foreach(df->list_of_strings, free_string, NULL); + g_slist_free(df->list_of_strings); + } + df->dftree = NULL; df->list_of_byte_arrays = NULL; + df->list_of_strings = NULL; /* Git rid of memchunk */ if (df->node_memchunk) @@ -537,6 +553,12 @@ fill_array_ipv6_variable(field_info *finfo, GArray *array, const guint8 *pd) } void +fill_array_string_variable(field_info *finfo, GArray *array, const guint8 *pd) +{ + g_array_append_val(array, finfo->value.string); +} + +void fill_array_bytes_variable(field_info *finfo, GArray *array, const guint8 *pd) { GByteArray *barray; @@ -640,6 +662,16 @@ gboolean fill_array_bytes_value(GNode *gnode, gpointer data) return FALSE; /* FALSE = do not end traversal of GNode tree */ } +gboolean fill_array_string_value(GNode *gnode, gpointer data) +{ + GArray *array = (GArray*)data; + dfilter_node *dnode = (dfilter_node*) (gnode->data); + + g_array_append_val(array, dnode->value.string); + + return FALSE; /* FALSE = do not end traversal of GNode tree */ +} + gboolean check_relation_numeric(gint operand, GArray *a, GArray *b) { int i, j, len_a, len_b; @@ -1009,3 +1041,41 @@ gboolean check_relation_bytes(gint operand, GArray *a, GArray *b) g_assert_not_reached(); return FALSE; } + +gboolean check_relation_string(gint operand, GArray *a, GArray *b) +{ + int i, j, len_a, len_b; + char *ptr_a, *ptr_b; + + len_a = a->len; + len_b = b->len; + + + switch(operand) { + case TOK_EQ: + for(i = 0; i < len_a; i++) { + ptr_a = g_array_index(a, char*, i); + for (j = 0; j < len_b; j++) { + ptr_b = g_array_index(b, char*, j); + if (strcmp(ptr_a, ptr_b) == 0) + return TRUE; + } + } + return FALSE; + + case TOK_NE: + for(i = 0; i < len_a; i++) { + ptr_a = g_array_index(a, char*, i); + for (j = 0; j < len_b; j++) { + ptr_b = g_array_index(b, char*, j); + if (strcmp(ptr_a, ptr_b) != 0) + return TRUE; + } + } + return FALSE; + } + + g_assert_not_reached(); + return FALSE; +} + |