OpenVAS Scanner 23.32.3
nasl_lex_ctxt.c File Reference
#include "nasl_lex_ctxt.h"
#include "nasl_func.h"
#include "nasl_global_ctxt.h"
#include "nasl_tree.h"
#include "nasl_var.h"
#include <glib.h>
Include dependency graph for nasl_lex_ctxt.c:

Go to the source code of this file.

Functions

void init_nasl_library (lex_ctxt *)
 Adds "built-in" variable and function definitions to a context.
lex_ctxtinit_empty_lex_ctxt ()
void free_lex_ctxt (lex_ctxt *c)
void dump_ctxt (lex_ctxt *c)

Function Documentation

◆ dump_ctxt()

void dump_ctxt ( lex_ctxt * c)

Definition at line 52 of file nasl_lex_ctxt.c.

53{
54 int i;
56
57 printf ("--------<CTXT>--------\n");
58 if (c->fct_ctxt)
59 printf ("Is a function context\n");
60 if (c->up_ctxt == NULL)
61 printf ("Is the top level context\n");
62 if (c->ret_val)
63 {
64 printf ("Return value\n");
66 }
67
68 printf ("Variables:\n");
69 for (i = 0; i < VAR_NAME_HASH; i++)
70 for (v = c->ctx_vars.hash_elt[i]; v != NULL; v = v->next_var)
71 printf ("%s\t", v->var_name);
72 putchar ('\n');
73
74 printf ("----------------------\n");
75}
void nasl_dump_tree(const tree_cell *c)
Definition nasl_tree.c:363
#define VAR_NAME_HASH
Definition nasl_var.h:22
struct st_n_nasl_var named_nasl_var
char * var_name
Definition nasl_var.h:58
struct st_n_nasl_var * next_var
Definition nasl_var.h:62
struct st_n_nasl_var ** hash_elt
Definition nasl_var.h:36
nasl_array ctx_vars
tree_cell * ret_val
struct struct_lex_ctxt * up_ctxt

References struct_lex_ctxt::ctx_vars, struct_lex_ctxt::fct_ctxt, st_nasl_array::hash_elt, nasl_dump_tree(), st_n_nasl_var::next_var, struct_lex_ctxt::ret_val, struct_lex_ctxt::up_ctxt, st_n_nasl_var::var_name, and VAR_NAME_HASH.

Referenced by nasl_dump_ctxt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_lex_ctxt()

void free_lex_ctxt ( lex_ctxt * c)

Definition at line 43 of file nasl_lex_ctxt.c.

44{
46 free_array (&c->ctx_vars);
47 g_hash_table_destroy (c->functions);
48 g_free (c);
49}
void deref_cell(tree_cell *c)
Definition nasl_tree.c:178
void free_array(nasl_array *a)
Definition nasl_var.c:339
GHashTable * functions

References struct_lex_ctxt::ctx_vars, deref_cell(), free_array(), struct_lex_ctxt::functions, and struct_lex_ctxt::ret_val.

Referenced by exec_nasl_script(), nasl_func_call(), and nasl_lint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_empty_lex_ctxt()

lex_ctxt * init_empty_lex_ctxt ( void )
Todo
Initialization of the library seems intuitively be necessary only once (involves "linking" the nasl functions to c code). Consider a "prototype" context that has to be created only once and of which copies are made when needed.

Definition at line 20 of file nasl_lex_ctxt.c.

21{
22 lex_ctxt *c = g_malloc0 (sizeof (lex_ctxt));
23
24 c->ctx_vars.hash_elt = g_malloc0 (sizeof (named_nasl_var *) * VAR_NAME_HASH);
25 c->ctx_vars.num_elt = NULL;
26 c->ctx_vars.max_idx = 0;
27 c->functions = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
28 (GDestroyNotify) free_func);
29 c->oid = NULL;
30 c->ret_val = NULL;
31 c->fct_ctxt = 0;
32
38
39 return c;
40}
void free_func(nasl_func *f)
Definition nasl_func.c:266
void init_nasl_library(lex_ctxt *)
Adds "built-in" variable and function definitions to a context.
Definition nasl_init.c:514
struct struct_lex_ctxt lex_ctxt
struct st_a_nasl_var ** num_elt
Definition nasl_var.h:35
const char * oid

References struct_lex_ctxt::ctx_vars, struct_lex_ctxt::fct_ctxt, free_func(), struct_lex_ctxt::functions, st_nasl_array::hash_elt, init_nasl_library(), st_nasl_array::max_idx, st_nasl_array::num_elt, struct_lex_ctxt::oid, struct_lex_ctxt::ret_val, and VAR_NAME_HASH.

Referenced by exec_nasl_script(), nasl_func_call(), and nasl_lint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_nasl_library()

void init_nasl_library ( lex_ctxt * lexic)

Adds "built-in" variable and function definitions to a context.

Definition at line 514 of file nasl_init.c.

515{
516 tree_cell tc;
517 unsigned i;
518
519 memset (&tc, 0, sizeof (tc));
520
521 // Initialize constant integer terms
522 tc.type = CONST_INT;
523 for (i = 0; i < sizeof (libivars) / sizeof (libivars[0]) - 1; i++)
524 {
525 tc.x.i_val = libivars[i].val;
526 if (add_named_var_to_ctxt (lexic, libivars[i].name, &tc) == NULL)
527 {
528 nasl_perror (lexic, "init_nasl_library: could not define var '%s'\n",
529 libivars[i].name);
530 continue;
531 }
532 }
533
534 // Initialize constant string terms
535 tc.type = CONST_DATA;
536 for (i = 0; i < sizeof (libsvars) / sizeof (libsvars[0]) - 1; i++)
537 {
538 tc.x.str_val = (char *) libsvars[i].val;
539 tc.size = strlen (libsvars[i].val);
540 if (add_named_var_to_ctxt (lexic, libsvars[i].name, &tc) == NULL)
541 {
542 nasl_perror (lexic, "init_nasl_library: could not define var '%s'\n",
543 libsvars[i].name);
544 continue;
545 }
546 }
547
548 // Add the "NULL" variable
549 if (add_named_var_to_ctxt (lexic, "NULL", NULL) == NULL)
550 nasl_perror (lexic, "init_nasl_library: could not define var 'NULL'\n");
551}
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition nasl_debug.c:105
static struct @260365312376163127012272224246062244353077307342 libsvars[]
const char * name
Definition nasl_init.c:439
static struct @002143073300314243041325344242175301040162155246 libivars[]
const char * val
Definition nasl_init.c:440
named_nasl_var * add_named_var_to_ctxt(lex_ctxt *, const char *, tree_cell *)
Definition nasl_var.c:810
@ CONST_DATA
Definition nasl_tree.h:82
@ CONST_INT
Definition nasl_tree.h:79
struct TC tree_cell
int size
Definition nasl_tree.h:99
long int i_val
Definition nasl_tree.h:104
union TC::@332262321161220155002104006201360276211317150140 x
char * str_val
Definition nasl_tree.h:103
short type
Definition nasl_tree.h:95

References add_named_var_to_ctxt(), CONST_DATA, CONST_INT, TC::i_val, libivars, libsvars, name, nasl_perror(), TC::size, TC::str_val, TC::type, val, and TC::x.

Referenced by init_empty_lex_ctxt().

Here is the call graph for this function:
Here is the caller graph for this function: