Add an additional "title" attribute for UAT fields; that's what's
[obnox/wireshark/wip.git] / epan / dfilter / sttype-function.c
1 /*
2  * $Id$
3  *
4  * Copyright (c) 2006 by Gilbert Ramirez <gram@alumni.rice.edu>
5  *
6  * Wireshark - Network traffic analyzer
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "syntax-tree.h"
28 #include "sttype-function.h"
29
30 typedef struct {
31         guint32         magic;
32     df_func_def_t *funcdef;
33     GSList *params;
34 } function_t;
35
36 #define FUNCTION_MAGIC  0xe10f0f99
37
38 static gpointer
39 function_new(gpointer funcdef)
40 {
41         function_t              *stfuncrec;
42
43         g_assert(funcdef != NULL);
44
45         stfuncrec = g_new(function_t, 1);
46
47         stfuncrec->magic = FUNCTION_MAGIC;
48         stfuncrec->funcdef = funcdef;
49         stfuncrec->params = NULL;
50
51         return (gpointer) stfuncrec;
52 }
53
54 static void
55 slist_stnode_free(gpointer data, gpointer user_data _U_)
56 {
57     stnode_free(data);
58 }
59
60 void
61 st_funcparams_free(GSList *params)
62 {
63     g_slist_foreach(params, slist_stnode_free, NULL);
64     g_slist_free(params);
65 }
66
67 static void
68 function_free(gpointer value)
69 {
70         function_t      *stfuncrec = value;
71         assert_magic(stfuncrec, FUNCTION_MAGIC);
72     st_funcparams_free(stfuncrec->params);
73         g_free(stfuncrec);
74 }
75
76
77 /* Set the parameters for a function stnode_t. */
78 void
79 sttype_function_set_params(stnode_t *node, GSList *params)
80 {
81
82         function_t      *stfuncrec;
83
84         stfuncrec = stnode_data(node);
85         assert_magic(stfuncrec, FUNCTION_MAGIC);
86
87         stfuncrec->params = params;
88 }
89
90 /* Get the function-definition record for a function stnode_t. */
91 df_func_def_t*
92 sttype_function_funcdef(stnode_t *node)
93 {
94         function_t      *stfuncrec;
95
96         stfuncrec = stnode_data(node);
97         assert_magic(stfuncrec, FUNCTION_MAGIC);
98     return stfuncrec->funcdef;
99 }
100
101 /* Get the parameters for a function stnode_t. */
102 GSList*
103 sttype_function_params(stnode_t *node)
104 {
105         function_t      *stfuncrec;
106
107         stfuncrec = stnode_data(node);
108         assert_magic(stfuncrec, FUNCTION_MAGIC);
109     return stfuncrec->params;
110 }
111
112
113 void
114 sttype_register_function(void)
115 {
116         static sttype_t function_type = {
117                 STTYPE_FUNCTION,
118                 "FUNCTION",
119                 function_new,
120                 function_free,
121         };
122
123         sttype_register(&function_type);
124 }
125