2006-05-02 14:26:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006 by Gilbert Ramirez <gram@alumni.rice.edu>
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
2006-05-02 14:26:17 +00:00
|
|
|
*
|
2018-02-08 16:59:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2006-05-02 14:26:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "syntax-tree.h"
|
|
|
|
#include "sttype-function.h"
|
2021-06-18 18:21:42 +00:00
|
|
|
#include <wsutil/ws_assert.h>
|
2006-05-02 14:26:17 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
guint32 magic;
|
2015-02-13 19:02:43 +00:00
|
|
|
df_func_def_t *funcdef;
|
|
|
|
GSList *params;
|
2006-05-02 14:26:17 +00:00
|
|
|
} function_t;
|
|
|
|
|
|
|
|
#define FUNCTION_MAGIC 0xe10f0f99
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
function_new(gpointer funcdef)
|
|
|
|
{
|
|
|
|
function_t *stfuncrec;
|
|
|
|
|
|
|
|
stfuncrec = g_new(function_t, 1);
|
|
|
|
|
|
|
|
stfuncrec->magic = FUNCTION_MAGIC;
|
2021-10-26 12:53:06 +00:00
|
|
|
stfuncrec->funcdef = funcdef;
|
2006-05-02 14:26:17 +00:00
|
|
|
stfuncrec->params = NULL;
|
|
|
|
|
2021-10-26 12:53:06 +00:00
|
|
|
return stfuncrec;
|
2006-05-02 14:26:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 12:12:41 +00:00
|
|
|
static gpointer
|
|
|
|
function_dup(gconstpointer data)
|
|
|
|
{
|
2021-10-26 12:53:06 +00:00
|
|
|
const function_t *org = data;
|
2012-06-19 12:12:41 +00:00
|
|
|
function_t *stfuncrec;
|
|
|
|
GSList *p;
|
|
|
|
|
2021-10-26 12:53:06 +00:00
|
|
|
stfuncrec = function_new(org->funcdef);
|
2012-06-19 12:12:41 +00:00
|
|
|
|
|
|
|
for (p = org->params; p; p = p->next) {
|
2021-10-26 12:53:06 +00:00
|
|
|
const stnode_t *param = p->data;
|
2013-10-18 15:08:19 +00:00
|
|
|
stfuncrec->params = g_slist_append(stfuncrec->params, stnode_dup(param));
|
2012-06-19 12:12:41 +00:00
|
|
|
}
|
2021-10-26 12:53:06 +00:00
|
|
|
return stfuncrec;
|
2012-06-19 12:12:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-26 15:28:39 +00:00
|
|
|
static char *
|
2021-10-11 11:45:13 +00:00
|
|
|
function_tostr(const void *data, gboolean pretty)
|
2021-09-26 15:28:39 +00:00
|
|
|
{
|
2021-10-26 12:53:06 +00:00
|
|
|
const function_t *stfuncrec = data;
|
2021-09-26 15:28:39 +00:00
|
|
|
const df_func_def_t *def = stfuncrec->funcdef;
|
2021-10-01 13:26:43 +00:00
|
|
|
GSList *params = stfuncrec->params;
|
|
|
|
GString *repr = g_string_new("");
|
2021-09-26 15:28:39 +00:00
|
|
|
|
|
|
|
ws_assert(def);
|
|
|
|
|
2022-04-04 22:42:52 +00:00
|
|
|
g_string_printf(repr, "%s: ", def->name);
|
2021-10-01 13:26:43 +00:00
|
|
|
while (params != NULL) {
|
|
|
|
ws_assert(params->data);
|
2021-10-11 11:45:13 +00:00
|
|
|
g_string_append(repr, stnode_tostr(params->data, pretty));
|
2021-10-01 13:26:43 +00:00
|
|
|
params = params->next;
|
|
|
|
if (params != NULL) {
|
|
|
|
g_string_append(repr, ", ");
|
|
|
|
}
|
|
|
|
}
|
2021-09-26 15:28:39 +00:00
|
|
|
|
2021-10-01 13:26:43 +00:00
|
|
|
return g_string_free(repr, FALSE);
|
2021-09-26 15:28:39 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 14:26:17 +00:00
|
|
|
static void
|
2018-04-17 10:48:35 +00:00
|
|
|
slist_stnode_free(gpointer data)
|
2006-05-02 14:26:17 +00:00
|
|
|
{
|
2021-10-26 12:53:06 +00:00
|
|
|
stnode_free(data);
|
2006-05-02 14:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
st_funcparams_free(GSList *params)
|
|
|
|
{
|
2018-04-17 10:48:35 +00:00
|
|
|
g_slist_free_full(params, slist_stnode_free);
|
2006-05-02 14:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
function_free(gpointer value)
|
|
|
|
{
|
2021-10-26 12:53:06 +00:00
|
|
|
function_t *stfuncrec = value;
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_magic(stfuncrec, FUNCTION_MAGIC);
|
2015-02-13 19:02:43 +00:00
|
|
|
st_funcparams_free(stfuncrec->params);
|
2006-05-02 14:26:17 +00:00
|
|
|
g_free(stfuncrec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Set the parameters for a function stnode_t. */
|
|
|
|
void
|
|
|
|
sttype_function_set_params(stnode_t *node, GSList *params)
|
|
|
|
{
|
|
|
|
|
|
|
|
function_t *stfuncrec;
|
|
|
|
|
2021-10-26 12:53:06 +00:00
|
|
|
stfuncrec = stnode_data(node);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_magic(stfuncrec, FUNCTION_MAGIC);
|
2006-05-02 14:26:17 +00:00
|
|
|
|
|
|
|
stfuncrec->params = params;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the function-definition record for a function stnode_t. */
|
|
|
|
df_func_def_t*
|
|
|
|
sttype_function_funcdef(stnode_t *node)
|
|
|
|
{
|
|
|
|
function_t *stfuncrec;
|
|
|
|
|
2021-10-26 12:53:06 +00:00
|
|
|
stfuncrec = stnode_data(node);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_magic(stfuncrec, FUNCTION_MAGIC);
|
2015-02-13 19:02:43 +00:00
|
|
|
return stfuncrec->funcdef;
|
2006-05-02 14:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the parameters for a function stnode_t. */
|
|
|
|
GSList*
|
|
|
|
sttype_function_params(stnode_t *node)
|
|
|
|
{
|
|
|
|
function_t *stfuncrec;
|
|
|
|
|
2021-10-26 12:53:06 +00:00
|
|
|
stfuncrec = stnode_data(node);
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_magic(stfuncrec, FUNCTION_MAGIC);
|
2015-02-13 19:02:43 +00:00
|
|
|
return stfuncrec->params;
|
2006-05-02 14:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
sttype_register_function(void)
|
|
|
|
{
|
|
|
|
static sttype_t function_type = {
|
|
|
|
STTYPE_FUNCTION,
|
|
|
|
"FUNCTION",
|
|
|
|
function_new,
|
|
|
|
function_free,
|
2021-09-26 15:28:39 +00:00
|
|
|
function_dup,
|
|
|
|
function_tostr
|
2006-05-02 14:26:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
sttype_register(&function_type);
|
|
|
|
}
|
|
|
|
|
2015-02-13 19:02:43 +00:00
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2015-02-13 19:02:43 +00:00
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|