2001-02-01 20:31:21 +00:00
|
|
|
/*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
2008-01-08 22:54:51 +00:00
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2001-02-01 20:31:21 +00:00
|
|
|
* Copyright 2001 Gerald Combs
|
|
|
|
*
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2001-02-01 20:31:21 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2001-02-01 20:31:21 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2001-02-01 20:31:21 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2001-02-01 20:31:21 +00:00
|
|
|
*/
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
#include "syntax-tree.h"
|
|
|
|
#include "sttype-test.h"
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
guint32 magic;
|
|
|
|
test_op_t op;
|
|
|
|
stnode_t *val1;
|
|
|
|
stnode_t *val2;
|
|
|
|
} test_t;
|
|
|
|
|
|
|
|
#define TEST_MAGIC 0xab9009ba
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
test_new(gpointer junk)
|
|
|
|
{
|
|
|
|
test_t *test;
|
|
|
|
|
|
|
|
g_assert(junk == NULL);
|
|
|
|
|
|
|
|
test = g_new(test_t, 1);
|
|
|
|
|
|
|
|
test->magic = TEST_MAGIC;
|
|
|
|
test->op = TEST_OP_UNINITIALIZED;
|
|
|
|
test->val1 = NULL;
|
|
|
|
test->val2 = NULL;
|
|
|
|
|
|
|
|
return (gpointer) test;
|
|
|
|
}
|
|
|
|
|
2012-06-19 12:12:41 +00:00
|
|
|
static gpointer
|
|
|
|
test_dup(gconstpointer data)
|
|
|
|
{
|
2013-03-05 06:16:45 +00:00
|
|
|
const test_t *org = (const test_t *)data;
|
2012-06-19 12:12:41 +00:00
|
|
|
test_t *test;
|
|
|
|
|
2013-03-05 06:16:45 +00:00
|
|
|
test = (test_t *)test_new(NULL);
|
2012-06-19 12:12:41 +00:00
|
|
|
test->op = org->op;
|
|
|
|
test->val1 = stnode_dup(org->val1);
|
|
|
|
test->val2 = stnode_dup(org->val1);
|
|
|
|
|
|
|
|
return (gpointer) test;
|
|
|
|
}
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
static void
|
|
|
|
test_free(gpointer value)
|
|
|
|
{
|
2012-06-03 20:59:41 +00:00
|
|
|
test_t *test = (test_t *)value;
|
2001-02-01 20:21:25 +00:00
|
|
|
assert_magic(test, TEST_MAGIC);
|
|
|
|
|
|
|
|
if (test->val1)
|
|
|
|
stnode_free(test->val1);
|
|
|
|
if (test->val2)
|
|
|
|
stnode_free(test->val2);
|
|
|
|
|
|
|
|
g_free(test);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
num_operands(test_op_t op)
|
|
|
|
{
|
|
|
|
switch(op) {
|
|
|
|
case TEST_OP_UNINITIALIZED:
|
2011-10-25 14:19:34 +00:00
|
|
|
break;
|
2001-02-01 20:21:25 +00:00
|
|
|
case TEST_OP_EXISTS:
|
|
|
|
case TEST_OP_NOT:
|
|
|
|
return 1;
|
|
|
|
case TEST_OP_AND:
|
|
|
|
case TEST_OP_OR:
|
|
|
|
case TEST_OP_EQ:
|
|
|
|
case TEST_OP_NE:
|
|
|
|
case TEST_OP_GT:
|
|
|
|
case TEST_OP_GE:
|
|
|
|
case TEST_OP_LT:
|
|
|
|
case TEST_OP_LE:
|
2004-02-27 12:00:32 +00:00
|
|
|
case TEST_OP_BITWISE_AND:
|
2003-08-27 15:23:11 +00:00
|
|
|
case TEST_OP_CONTAINS:
|
2003-12-06 16:35:20 +00:00
|
|
|
case TEST_OP_MATCHES:
|
|
|
|
return 2;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
g_assert_not_reached();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
sttype_test_set1(stnode_t *node, test_op_t op, stnode_t *val1)
|
|
|
|
{
|
|
|
|
test_t *test;
|
|
|
|
|
2012-06-03 20:59:41 +00:00
|
|
|
test = (test_t*)stnode_data(node);
|
2001-02-01 20:21:25 +00:00
|
|
|
assert_magic(test, TEST_MAGIC);
|
|
|
|
|
|
|
|
g_assert(num_operands(op) == 1);
|
|
|
|
test->op = op;
|
|
|
|
test->val1 = val1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sttype_test_set2(stnode_t *node, test_op_t op, stnode_t *val1, stnode_t *val2)
|
|
|
|
{
|
|
|
|
test_t *test;
|
|
|
|
|
2012-06-03 20:59:41 +00:00
|
|
|
test = (test_t*)stnode_data(node);
|
2001-02-01 20:21:25 +00:00
|
|
|
assert_magic(test, TEST_MAGIC);
|
|
|
|
|
|
|
|
g_assert(num_operands(op) == 2);
|
|
|
|
test->op = op;
|
|
|
|
test->val1 = val1;
|
|
|
|
test->val2 = val2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sttype_test_set2_args(stnode_t *node, stnode_t *val1, stnode_t *val2)
|
|
|
|
{
|
|
|
|
test_t *test;
|
|
|
|
|
2012-06-03 20:59:41 +00:00
|
|
|
test = (test_t*)stnode_data(node);
|
2001-02-01 20:21:25 +00:00
|
|
|
assert_magic(test, TEST_MAGIC);
|
|
|
|
|
|
|
|
if (num_operands(test->op) == 1) {
|
|
|
|
g_assert(val2 == NULL);
|
|
|
|
}
|
|
|
|
test->val1 = val1;
|
|
|
|
test->val2 = val2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sttype_test_get(stnode_t *node, test_op_t *p_op, stnode_t **p_val1, stnode_t **p_val2)
|
|
|
|
{
|
|
|
|
test_t *test;
|
|
|
|
|
2012-06-03 20:59:41 +00:00
|
|
|
test = (test_t*)stnode_data(node);
|
2001-02-01 20:21:25 +00:00
|
|
|
assert_magic(test, TEST_MAGIC);
|
|
|
|
|
2012-06-19 12:12:41 +00:00
|
|
|
if (p_op)
|
|
|
|
*p_op = test->op;
|
|
|
|
if (p_val1)
|
|
|
|
*p_val1 = test->val1;
|
|
|
|
if (p_val2)
|
|
|
|
*p_val2 = test->val2;
|
2001-02-01 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sttype_register_test(void)
|
|
|
|
{
|
|
|
|
static sttype_t test_type = {
|
|
|
|
STTYPE_TEST,
|
|
|
|
"TEST",
|
|
|
|
test_new,
|
|
|
|
test_free,
|
2012-06-19 12:12:41 +00:00
|
|
|
test_dup
|
2001-02-01 20:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
sttype_register(&test_type);
|
|
|
|
}
|