aboutsummaryrefslogtreecommitdiffstats
path: root/epan/ftypes/ftype-string.c
diff options
context:
space:
mode:
authorGilbert Ramirez <gram@alumni.rice.edu>2001-02-01 20:21:25 +0000
committerGilbert Ramirez <gram@alumni.rice.edu>2001-02-01 20:21:25 +0000
commit8f1fff2e6a5c114c6beafd2983afb55acd3d66ae (patch)
treee33c08662c708dcfe71591897fe6ffab53bce135 /epan/ftypes/ftype-string.c
parent07a925ef8b0568a2c5b8098d5734364a40eeb2f6 (diff)
Create a more modular type system for the FT_* types. Put them
into epan/ftypes. Re-write display filter routines using Lemon parser instead of yacc. Besides using a different tool, the new grammar is much simpler, while the display filter engine itself is more powerful and more easily extended. Add dftest executable, to test display filter "bytecode" generation. Add option to "configure" to build dftest or randpkt, both of which are not built by default. Implement Ed Warnicke's ideas about dranges in the new display filter and ftype code. Remove type FT_TEXT_ONLY in favor of FT_NONE, and have protocols registered as FT_PROTOCOL. Thus, FT_NONE is used only for simple labels in the proto tree, while FT_PROTOCOL is used for protocols. This was necessary for being able to make byte slices (ranges) out of protocols, like "frame[0:3]" Win32 Makefile.nmake's will be added tonight. svn path=/trunk/; revision=2967
Diffstat (limited to 'epan/ftypes/ftype-string.c')
-rw-r--r--epan/ftypes/ftype-string.c198
1 files changed, 198 insertions, 0 deletions
diff --git a/epan/ftypes/ftype-string.c b/epan/ftypes/ftype-string.c
new file mode 100644
index 0000000000..38ce87faa0
--- /dev/null
+++ b/epan/ftypes/ftype-string.c
@@ -0,0 +1,198 @@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <ftypes-int.h>
+#include <string.h>
+
+static void
+ftype_from_tvbuff(field_info *fi, tvbuff_t *tvb, int start, int length,
+ gboolean little_endian)
+{
+ /* XXX */
+ g_assert_not_reached();
+}
+
+
+static void
+string_fvalue_new(fvalue_t *fv)
+{
+ fv->value.string = NULL;
+}
+
+static void
+string_fvalue_free(fvalue_t *fv)
+{
+ if (fv->value.string) {
+ g_free(fv->value.string);
+ }
+}
+
+static void
+string_fvalue_set(fvalue_t *fv, gpointer value, gboolean already_copied)
+{
+ if (already_copied) {
+ fv->value.string = value;
+ }
+ else {
+ fv->value.string = g_strdup(value);
+ }
+}
+
+static gpointer
+value_get(fvalue_t *fv)
+{
+ return fv->value.string;
+}
+
+static gboolean
+val_from_string(fvalue_t *fv, char *s, LogFunc log)
+{
+ fv->value.string = g_strdup(s);
+ return TRUE;
+}
+
+static guint
+len(fvalue_t *fv)
+{
+ return strlen(fv->value.string);
+}
+
+static void
+slice(fvalue_t *fv, GByteArray *bytes, guint offset, guint length)
+{
+ guint8* data;
+
+ data = fv->value.string + offset;
+
+ g_byte_array_append(bytes, data, length);
+}
+
+
+static gboolean
+cmp_eq(fvalue_t *a, fvalue_t *b)
+{
+ return (strcmp(a->value.string, b->value.string) == 0);
+}
+
+static gboolean
+cmp_ne(fvalue_t *a, fvalue_t *b)
+{
+ return (strcmp(a->value.string, b->value.string) != 0);
+}
+
+static gboolean
+cmp_gt(fvalue_t *a, fvalue_t *b)
+{
+ return (strcmp(a->value.string, b->value.string) > 0);
+}
+
+static gboolean
+cmp_ge(fvalue_t *a, fvalue_t *b)
+{
+ return (strcmp(a->value.string, b->value.string) >= 0);
+}
+
+static gboolean
+cmp_lt(fvalue_t *a, fvalue_t *b)
+{
+ return (strcmp(a->value.string, b->value.string) < 0);
+}
+
+static gboolean
+cmp_le(fvalue_t *a, fvalue_t *b)
+{
+ return (strcmp(a->value.string, b->value.string) <= 0);
+}
+
+void
+ftype_register_string(void)
+{
+
+ static ftype_t string_type = {
+ "FT_STRING",
+ "character string",
+ 0,
+ string_fvalue_new,
+ string_fvalue_free,
+ ftype_from_tvbuff,
+ val_from_string,
+
+ string_fvalue_set,
+ NULL,
+ NULL,
+
+ value_get,
+ NULL,
+ NULL,
+
+ cmp_eq,
+ cmp_ne,
+ cmp_gt,
+ cmp_ge,
+ cmp_lt,
+ cmp_le,
+
+ len,
+ slice,
+ };
+ static ftype_t stringz_type = {
+ "FT_STRINGZ",
+ "character string",
+ 0,
+ string_fvalue_new,
+ string_fvalue_free,
+ ftype_from_tvbuff,
+ val_from_string,
+
+ string_fvalue_set,
+ NULL,
+ NULL,
+
+ value_get,
+ NULL,
+ NULL,
+
+ cmp_eq,
+ cmp_ne,
+ cmp_gt,
+ cmp_ge,
+ cmp_lt,
+ cmp_le,
+
+ len,
+ slice,
+ };
+ static ftype_t uint_string_type = {
+ "FT_UINT_STRING",
+ "character string",
+ 0,
+ string_fvalue_new,
+ string_fvalue_free,
+ ftype_from_tvbuff,
+ val_from_string,
+
+ string_fvalue_set,
+ NULL,
+ NULL,
+
+ value_get,
+ NULL,
+ NULL,
+
+ cmp_eq,
+ cmp_ne,
+ cmp_gt,
+ cmp_ge,
+ cmp_lt,
+ cmp_le,
+
+ len,
+ slice,
+ };
+
+ ftype_register(FT_STRING, &string_type);
+ ftype_register(FT_STRINGZ, &stringz_type);
+ ftype_register(FT_UINT_STRING, &uint_string_type);
+}