OpenVAS Scanner
7.0.0~git
nasl_lex_ctxt.c
Go to the documentation of this file.
1
/* Based on work Copyright (C) 2002 - 2004 Tenable Network Security
2
*
3
* SPDX-License-Identifier: GPL-2.0-only
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* version 2 as published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
*/
18
19
#include "
nasl_lex_ctxt.h
"
20
21
#include "
nasl_func.h
"
22
#include "
nasl_global_ctxt.h
"
23
#include "
nasl_tree.h
"
24
#include "
nasl_var.h
"
25
26
#include <glib.h>
/* for g_free() */
27
28
void
29
init_nasl_library
(
lex_ctxt
*);
30
31
lex_ctxt
*
32
init_empty_lex_ctxt
()
33
{
34
lex_ctxt
*c = g_malloc0 (
sizeof
(
lex_ctxt
));
35
36
c->
ctx_vars
.
hash_elt
= g_malloc0 (
sizeof
(
named_nasl_var
*) *
VAR_NAME_HASH
);
37
c->
ctx_vars
.
num_elt
= NULL;
38
c->
ctx_vars
.
max_idx
= 0;
39
c->
functions
= g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
40
(GDestroyNotify)
free_func
);
41
c->
oid
= NULL;
42
c->
ret_val
= NULL;
43
c->
fct_ctxt
= 0;
44
49
init_nasl_library
(c);
50
51
return
c;
52
}
53
54
void
55
free_lex_ctxt
(
lex_ctxt
*c)
56
{
57
deref_cell
(c->
ret_val
);
58
free_array
(&c->
ctx_vars
);
59
g_hash_table_destroy (c->
functions
);
60
g_free (c);
61
}
62
63
void
64
dump_ctxt
(
lex_ctxt
*c)
65
{
66
int
i;
67
named_nasl_var
*v;
68
69
printf (
"--------<CTXT>--------\n"
);
70
if
(c->
fct_ctxt
)
71
printf (
"Is a function context\n"
);
72
if
(c->
up_ctxt
== NULL)
73
printf (
"Is the top level context\n"
);
74
if
(c->
ret_val
)
75
{
76
printf (
"Return value\n"
);
77
nasl_dump_tree
(c->
ret_val
);
78
}
79
80
printf (
"Variables:\n"
);
81
for
(i = 0; i <
VAR_NAME_HASH
; i++)
82
for
(v = c->
ctx_vars
.
hash_elt
[i]; v != NULL; v = v->
next_var
)
83
printf (
"%s\t"
, v->
var_name
);
84
putchar (
'\n'
);
85
86
printf (
"----------------------\n"
);
87
}
free_array
void free_array(nasl_array *a)
Definition:
nasl_var.c:354
struct_lex_ctxt::ctx_vars
nasl_array ctx_vars
Definition:
nasl_lex_ctxt.h:46
st_n_nasl_var
Definition:
nasl_var.h:65
nasl_dump_tree
void nasl_dump_tree(const tree_cell *c)
Definition:
nasl_tree.c:377
st_nasl_array::max_idx
int max_idx
Definition:
nasl_var.h:45
st_nasl_array::hash_elt
struct st_n_nasl_var ** hash_elt
Definition:
nasl_var.h:47
struct_lex_ctxt::functions
GHashTable * functions
Definition:
nasl_lex_ctxt.h:48
st_n_nasl_var::var_name
char * var_name
Definition:
nasl_var.h:69
struct_lex_ctxt::up_ctxt
struct struct_lex_ctxt * up_ctxt
Definition:
nasl_lex_ctxt.h:35
dump_ctxt
void dump_ctxt(lex_ctxt *c)
Definition:
nasl_lex_ctxt.c:64
st_n_nasl_var::next_var
struct st_n_nasl_var * next_var
Definition:
nasl_var.h:73
nasl_lex_ctxt.h
struct_lex_ctxt::oid
const char * oid
Definition:
nasl_lex_ctxt.h:42
free_lex_ctxt
void free_lex_ctxt(lex_ctxt *c)
Definition:
nasl_lex_ctxt.c:55
struct_lex_ctxt::fct_ctxt
unsigned fct_ctxt
Definition:
nasl_lex_ctxt.h:37
nasl_func.h
free_func
void free_func(nasl_func *f)
Definition:
nasl_func.c:269
init_nasl_library
void init_nasl_library(lex_ctxt *)
Adds "built-in" variable and function definitions to a context.
Definition:
nasl_init.c:446
struct_lex_ctxt
Definition:
nasl_lex_ctxt.h:33
nasl_var.h
nasl_global_ctxt.h
deref_cell
void deref_cell(tree_cell *c)
Definition:
nasl_tree.c:192
init_empty_lex_ctxt
lex_ctxt * init_empty_lex_ctxt()
Definition:
nasl_lex_ctxt.c:32
nasl_tree.h
VAR_NAME_HASH
#define VAR_NAME_HASH
Definition:
nasl_var.h:33
struct_lex_ctxt::ret_val
tree_cell * ret_val
Definition:
nasl_lex_ctxt.h:36
st_nasl_array::num_elt
struct st_a_nasl_var ** num_elt
Definition:
nasl_var.h:46
nasl
nasl_lex_ctxt.c
Generated on Wed Jan 29 2020 00:00:00 for OpenVAS Scanner by
1.8.17