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
|
2001-02-01 20:21:25 +00:00
|
|
|
*
|
2018-02-08 16:59:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2001-02-01 20:21:25 +00:00
|
|
|
*/
|
2001-02-01 20:31:21 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
#ifndef SYNTAX_TREE_H
|
|
|
|
#define SYNTAX_TREE_H
|
|
|
|
|
2021-09-26 15:28:39 +00:00
|
|
|
#include <stdio.h>
|
2021-10-08 03:14:56 +00:00
|
|
|
#include <inttypes.h>
|
2001-02-01 20:21:25 +00:00
|
|
|
#include <glib.h>
|
2021-10-06 00:56:00 +00:00
|
|
|
|
2021-10-08 03:14:56 +00:00
|
|
|
#include <wsutil/ws_assert.h>
|
|
|
|
#include <wsutil/wslog.h>
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** @file
|
|
|
|
*/
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
typedef enum {
|
|
|
|
STTYPE_UNINITIALIZED,
|
|
|
|
STTYPE_TEST,
|
2003-07-25 03:44:05 +00:00
|
|
|
STTYPE_UNPARSED,
|
2001-02-01 20:21:25 +00:00
|
|
|
STTYPE_STRING,
|
2016-09-19 01:48:50 +00:00
|
|
|
STTYPE_CHARCONST,
|
2001-02-01 20:21:25 +00:00
|
|
|
STTYPE_FIELD,
|
|
|
|
STTYPE_FVALUE,
|
2001-02-27 19:23:30 +00:00
|
|
|
STTYPE_INTEGER,
|
2001-02-01 20:21:25 +00:00
|
|
|
STTYPE_RANGE,
|
2006-05-02 14:26:17 +00:00
|
|
|
STTYPE_FUNCTION,
|
2015-08-19 03:03:41 +00:00
|
|
|
STTYPE_SET,
|
2021-03-21 10:06:17 +00:00
|
|
|
STTYPE_PCRE,
|
2001-02-01 20:21:25 +00:00
|
|
|
STTYPE_NUM_TYPES
|
|
|
|
} sttype_id_t;
|
|
|
|
|
|
|
|
typedef gpointer (*STTypeNewFunc)(gpointer);
|
2012-06-19 12:12:41 +00:00
|
|
|
typedef gpointer (*STTypeDupFunc)(gconstpointer);
|
2001-02-01 20:21:25 +00:00
|
|
|
typedef void (*STTypeFreeFunc)(gpointer);
|
2021-09-26 15:28:39 +00:00
|
|
|
typedef char* (*STTypeToStrFunc)(gconstpointer);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Type information */
|
|
|
|
typedef struct {
|
|
|
|
sttype_id_t id;
|
|
|
|
const char *name;
|
|
|
|
STTypeNewFunc func_new;
|
|
|
|
STTypeFreeFunc func_free;
|
2012-06-19 12:12:41 +00:00
|
|
|
STTypeDupFunc func_dup;
|
2021-09-26 15:28:39 +00:00
|
|
|
STTypeToStrFunc func_tostr;
|
2001-02-01 20:21:25 +00:00
|
|
|
} sttype_t;
|
|
|
|
|
2021-09-27 00:54:41 +00:00
|
|
|
#define STNODE_F_INSIDE_PARENS (1 << 0)
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Node (type instance) information */
|
2001-02-01 20:21:25 +00:00
|
|
|
typedef struct {
|
2021-09-26 15:28:39 +00:00
|
|
|
uint32_t magic;
|
2001-02-01 20:21:25 +00:00
|
|
|
sttype_t *type;
|
2021-09-27 00:54:41 +00:00
|
|
|
uint16_t flags;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2001-02-27 19:23:30 +00:00
|
|
|
/* This could be made an enum, but I haven't
|
|
|
|
* set aside to time to do so. */
|
|
|
|
gpointer data;
|
2021-09-26 15:28:39 +00:00
|
|
|
int32_t value;
|
2021-09-26 21:22:50 +00:00
|
|
|
|
|
|
|
char *token_value;
|
2001-02-01 20:21:25 +00:00
|
|
|
} stnode_t;
|
|
|
|
|
2005-07-23 06:49:07 +00:00
|
|
|
/* These are the sttype_t registration function prototypes. */
|
2006-05-02 14:26:17 +00:00
|
|
|
void sttype_register_function(void);
|
2005-07-23 06:49:07 +00:00
|
|
|
void sttype_register_integer(void);
|
|
|
|
void sttype_register_pointer(void);
|
|
|
|
void sttype_register_range(void);
|
2015-08-19 03:03:41 +00:00
|
|
|
void sttype_register_set(void);
|
2005-07-23 06:49:07 +00:00
|
|
|
void sttype_register_string(void);
|
|
|
|
void sttype_register_test(void);
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
void
|
|
|
|
sttype_init(void);
|
|
|
|
|
|
|
|
void
|
|
|
|
sttype_cleanup(void);
|
|
|
|
|
|
|
|
void
|
|
|
|
sttype_register(sttype_t *type);
|
|
|
|
|
|
|
|
stnode_t*
|
2021-09-26 21:22:50 +00:00
|
|
|
stnode_new(sttype_id_t type_id, gpointer data, const char *token_value);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2012-06-19 12:12:41 +00:00
|
|
|
stnode_t*
|
|
|
|
stnode_dup(const stnode_t *org);
|
|
|
|
|
2021-10-06 09:21:37 +00:00
|
|
|
void
|
|
|
|
stnode_clear(stnode_t *node);
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
void
|
2021-09-26 21:22:50 +00:00
|
|
|
stnode_init(stnode_t *node, sttype_id_t type_id, gpointer data, const char *token_value);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2001-02-27 19:23:30 +00:00
|
|
|
void
|
2021-09-26 21:22:50 +00:00
|
|
|
stnode_init_int(stnode_t *node, sttype_id_t type_id, gint32 value, const char *token_value);
|
2001-02-27 19:23:30 +00:00
|
|
|
|
2021-10-06 09:21:37 +00:00
|
|
|
void
|
|
|
|
stnode_replace(stnode_t *node, sttype_id_t type_id, gpointer data);
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
void
|
|
|
|
stnode_free(stnode_t *node);
|
|
|
|
|
|
|
|
const char*
|
|
|
|
stnode_type_name(stnode_t *node);
|
|
|
|
|
|
|
|
sttype_id_t
|
|
|
|
stnode_type_id(stnode_t *node);
|
|
|
|
|
|
|
|
gpointer
|
|
|
|
stnode_data(stnode_t *node);
|
|
|
|
|
2019-01-27 17:02:03 +00:00
|
|
|
gpointer
|
|
|
|
stnode_steal_data(stnode_t *node);
|
|
|
|
|
2004-06-03 07:36:25 +00:00
|
|
|
gint32
|
2001-02-27 19:23:30 +00:00
|
|
|
stnode_value(stnode_t *node);
|
|
|
|
|
2021-10-05 05:18:28 +00:00
|
|
|
const char *
|
|
|
|
stnode_token_value(stnode_t *node);
|
|
|
|
|
2021-09-26 15:28:39 +00:00
|
|
|
char *
|
|
|
|
stnode_tostr(stnode_t *node);
|
|
|
|
|
2021-09-27 00:54:41 +00:00
|
|
|
gboolean
|
|
|
|
stnode_inside_parens(stnode_t *node);
|
|
|
|
|
|
|
|
void
|
|
|
|
stnode_set_inside_parens(stnode_t *node, gboolean inside);
|
|
|
|
|
2021-09-26 15:28:39 +00:00
|
|
|
void
|
2021-09-30 19:09:17 +00:00
|
|
|
log_stnode_full(enum ws_log_level level,
|
2021-09-26 15:28:39 +00:00
|
|
|
const char *file, int line, const char *func,
|
|
|
|
stnode_t *node, const char *msg);
|
|
|
|
|
|
|
|
#ifdef WS_DISABLE_DEBUG
|
2021-09-30 19:09:17 +00:00
|
|
|
#define log_stnode(node) (void)0;
|
2021-09-26 15:28:39 +00:00
|
|
|
#else
|
2021-09-30 19:09:17 +00:00
|
|
|
#define log_stnode(node) \
|
|
|
|
log_stnode_full(LOG_LEVEL_NOISY, __FILE__, __LINE__, __func__, node, #node)
|
2021-09-26 15:28:39 +00:00
|
|
|
#endif
|
|
|
|
|
2021-10-06 10:52:13 +00:00
|
|
|
void
|
|
|
|
log_syntax_tree(enum ws_log_level, stnode_t *root, const char *msg);
|
2021-09-26 15:28:39 +00:00
|
|
|
|
2021-10-06 11:21:59 +00:00
|
|
|
#ifdef WS_DISABLE_DEBUG
|
|
|
|
#define ws_assert_magic(obj, mnum) (void)0
|
2021-06-18 18:21:42 +00:00
|
|
|
#else
|
2021-10-06 10:52:13 +00:00
|
|
|
#define ws_assert_magic(obj, mnum) \
|
2021-10-08 03:14:56 +00:00
|
|
|
do { \
|
|
|
|
ws_assert(obj); \
|
|
|
|
if ((obj)->magic != (mnum)) { \
|
|
|
|
ws_log_full(LOG_DOMAIN_DFILTER, LOG_LEVEL_CRITICAL, \
|
|
|
|
__FILE__, __LINE__, __func__, \
|
|
|
|
"Magic num is 0x%08"PRIx32", " \
|
|
|
|
"but should be 0x%08"PRIx32, \
|
|
|
|
(obj)->magic, (mnum)); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2021-06-18 18:21:42 +00:00
|
|
|
#endif
|
|
|
|
|
2021-10-06 00:56:00 +00:00
|
|
|
#endif /* SYNTAX_TREE_H */
|