OpenVAS Libraries  4.0+rc3.SVN
nasl_lex_ctxt.h
1 /* Nessus Attack Scripting Language
2  *
3  * Copyright (C) 2002 - 2003 Michel Arboi and Renaud Deraison
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2,
7  * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef _NASL_LEX_CTXT_H
20 #define _NASL_LEX_CTXT_H
21 
22 /* for tree_cell */
23 #include "nasl_tree.h"
24 
25 /* for nasl_array */
26 #include "nasl_var.h"
27 
28 /* for nasl_func */
29 #include "nasl_func.h"
30 
31 typedef struct struct_lex_ctxt
32 {
33  struct struct_lex_ctxt *up_ctxt;
34  tree_cell *ret_val; /* return value or exit flag */
35  unsigned fct_ctxt:1; /* This is a function context */
36  unsigned break_flag:1; /* Break from loop */
37  unsigned cont_flag:1; /* Next iteration in loop */
38  unsigned authenticated:1; /* Authenticated script */
39  unsigned always_authenticated:1;
40  struct arglist *script_infos;
41  int recv_timeout;
42  /* Named variables hash set + anonymous variables array */
43  nasl_array ctx_vars;
44  /* Functions hash set */
45  nasl_func *functions[FUNC_NAME_HASH];
46 } lex_ctxt;
47 
48 #define NASL_COMPAT_LEX_CTXT "NASL compat lex context"
49 
50 lex_ctxt *init_empty_lex_ctxt (void);
51 void free_lex_ctxt (lex_ctxt *);
52 lex_ctxt *get_top_level_ctxt (lex_ctxt *);
53 
54 void dump_ctxt (lex_ctxt *);
55 
56 nasl_func *get_func_ref_by_name (lex_ctxt *, const char *);
57 tree_cell *decl_nasl_func (lex_ctxt *, tree_cell *);
58 nasl_func *insert_nasl_func (lex_ctxt *, const char *, tree_cell *);
59 tree_cell *nasl_func_call (lex_ctxt *, const nasl_func *, tree_cell *);
60 
61 tree_cell *get_variable_by_name (lex_ctxt *, const char *);
62 tree_cell *get_array_elem (lex_ctxt *, const char * /*array name */ ,
63  tree_cell *);
64 anon_nasl_var *add_numbered_var_to_ctxt (lex_ctxt *, int, tree_cell *);
65 named_nasl_var *add_named_var_to_ctxt (lex_ctxt *, const char *, tree_cell *);
66 tree_cell *nasl_read_var_ref (lex_ctxt *, tree_cell *);
67 tree_cell *nasl_incr_variable (lex_ctxt *, tree_cell *, int, int);
68 tree_cell *nasl_return (lex_ctxt *, tree_cell *);
69 
70 tree_cell *decl_local_variables (lex_ctxt *, tree_cell *);
71 tree_cell *decl_global_variables (lex_ctxt *, tree_cell *);
72 
73 tree_cell *cell2atom (lex_ctxt *, tree_cell *);
74 
75 
76 int get_int_var_by_num (lex_ctxt *, int, int);
77 char *get_str_var_by_num (lex_ctxt *, int);
78 int get_int_var_by_name (lex_ctxt *, const char *, int);
79 int get_int_local_var_by_name (lex_ctxt *, const char *, int);
80 char *get_str_var_by_name (lex_ctxt *, const char *);
81 char *get_str_local_var_by_name (lex_ctxt *, const char *);
82 
83 int get_var_size_by_name (lex_ctxt *, const char *);
84 int get_local_var_size_by_name (lex_ctxt *, const char *);
85 int get_local_var_type_by_name (lex_ctxt *, const char *);
86 
87 
88 int get_var_size_by_num (lex_ctxt *, int);
89 int get_var_type_by_num (lex_ctxt *, int);
90 #endif