59 for (p = s; *p !=
'\0'; p++)
60 h = (h << 3) + (
unsigned char) *p;
65 hash_str (
const char *s)
79 "Negative integer index %d are not supported yet!\n", num);
85 if (v != NULL || !create)
103 get_var_by_name (
nasl_array * a,
const char *s)
105 int h = hash_str (s);
129 get_var_ref_by_name (
lex_ctxt * ctxt,
const char *
name,
int climb)
132 int h = hash_str (
name);
137 for (c = ctxt; c != NULL; c = c->
up_ctxt)
166 get_var_ref_by_num (
lex_ctxt * ctxt,
int num)
172 nasl_perror (ctxt,
"Negative index %d is invalid for array\n", num);
211 if (strcmp (
name,
"_FCT_ANON_ARGS") == 0)
229 #ifdef ALL_VARIABLES_NAMED 230 if (v->av_name != NULL)
233 snprintf (str,
sizeof (str),
"[%p]", v);
246 if (strcmp (
name,
"_FCT_ANON_ARGS") == 0)
267 nasl_perror (ctxt,
"get_array_elem: NULL index\n");
286 strcmp (
name,
"_FCT_ANON_ARGS"));
292 return var2cell (nv != NULL ? &nv->
u : NULL);
295 nasl_perror (ctxt,
"get_array_elem: unhandled index type 0x%x for " 302 nasl_perror (ctxt,
"get_array_elem: variable %s is an integer\n",
name);
314 "get_array_elem: requesting character after end " 315 "of string %s (%d >= %d)\n",
name, idx->
x.
i_val, l);
327 "get_array_elem: Negative index (%d) passed to " 343 "get_array_elem: Cannot use a non integer index" 344 " (type 0x%x) in string. Variable: %s\n",
351 nasl_perror (ctxt,
"Severe bug: unknown variable type 0x%x %s\n",
374 for (i = 0; i < a->
max_idx; i++)
501 copy_anon_var (v1, v);
514 copy_anon_var (&v1->
u, &v->
u);
533 if (a1 == NULL || a2 == NULL)
535 nasl_perror (NULL,
"Internal inconsistency - null array\n");
545 for (i = 0; i < a2->
max_idx; i++)
548 if (copy_named && a2->
hash_elt != NULL)
556 v = dup_named_var (v2);
601 "nasl_affect: affecting NULL or FAKE cell undefines variable %s %s\n",
606 nasl_trace (NULL,
"NASL> %s <- undef\n", get_var_name (v1));
635 "Copying variable %s to itself is useless and dangerous!\n",
654 "Copying array %s to itself is useless and dangerous!\n",
662 nasl_perror (NULL,
"Cannot affect rvalue 0x%x to variable\n", rval->
type);
676 nasl_perror (NULL,
"Warning: Undefining defined variable %s %s\n",
684 "Warning: affecting non array (0x%x) to array variable %s\n",
693 "Warning: affecting array to atomic variable (0x%x) %s\n",
699 memset (v1, 0,
sizeof (*v1));
719 p = g_malloc0 (rval->
size + 1);
748 copy_array (&v1->
v.
v_arr, a, 1);
753 bzero (&v0,
sizeof (v0));
766 nasl_trace (NULL,
"NASL> %s <- \"%s\"\n", get_var_name (v1),
770 nasl_trace (NULL,
"NASL> %s <- (VAR2_ARRAY)\n", get_var_name (v1));
773 nasl_trace (NULL,
"NASL> %s <- (Type 0x%x)\n", get_var_name (v1), t2);
788 nasl_perror (NULL,
"nasl_effect: invalid lvalue\n");
794 nasl_perror (NULL,
"nasl_affect: cannot affect to non variable %s\n",
800 return affect_to_anon_var (v1, rval);
816 "create_named_var: affecting NULL or FAKE cell to variable %s\n",
823 tc = affect_to_anon_var (&v->
u,
val);
839 "create_anon_var: affecting NULL or FAKE cell to variable %s\n",
846 tc = affect_to_anon_var (v,
val);
857 for (t = vars; t != NULL; t = t->
link[0])
859 nasl_perror (lexic,
"decl_local_variables: null name!\n");
887 nasl_perror (lexic,
"Cannot add existing variable %d\n", num);
890 nasl_perror (lexic,
"Will not clear existing variable %d\n", num);
894 free_anon_var (a->
num_elt[num]);
910 int h = hash_str (
name);
925 v = create_named_var (
name,
val);
945 nasl_perror (lexic,
"nasl_read_var_ref: cannot read NULL or FAKE cell\n");
951 "nasl_read_var_ref: argument (type=%d) is not REF_VAR %s\n",
960 nasl_perror (lexic,
"nasl_read_var_ref: NULL variable in REF_VAR\n");
982 nasl_perror (lexic,
"nasl_read_var_ref: Bad string length fixed\n");
999 nasl_trace (lexic,
"NASL> %s -> \"%s\"\n", get_var_name (v),
1010 name = get_var_name (v);
1011 if (strcmp (
name,
"NULL") != 0)
1012 nasl_perror (lexic,
"nasl_read_var_ref: variable %s is undefined %s\n",
1016 nasl_trace (lexic,
"NASL> %s -> undef\n", get_var_name (v),
1021 nasl_perror (lexic,
"nasl_read_var_ref: unhandled variable type %d\n",
1024 nasl_trace (lexic,
"NASL> %s -> ???? (Var type %d)\n", get_var_name (v),
1037 int old_val = 0, new_val;
1043 "nasl_incr_variable: argument (type=%d) is not REF_VAR %s\n",
1059 "nasl_incr_variable: variable %s is a STRING %s - converting to integer\n",
1066 nasl_perror (lexic,
"nasl_incr_variable: variable %s is undefined %s\n",
1074 "nasl_incr_variable: variable %s has bad type %d %s\n",
1078 new_val = old_val +
val;
1086 retc->
x.
i_val = pre ? new_val : old_val;
1109 nasl_perror (NULL,
"var2int: variable %s is undefined!\n",
1129 str = g_string_new (
"[ ");
1131 for (i = 0; i < a->
max_idx; i++)
1135 g_string_append (str,
", ");
1140 g_string_append_printf (str,
"%d: %ld", i, u->
v.
v_int);
1145 g_string_append_printf (str,
"%d: '%s'", i, u->
v.
v_str.
s_val);
1147 g_string_append_printf (str,
"%d: '%s'...", i, u->
v.
v_str.
s_val);
1150 g_string_append_printf (str,
"%d: ????", i);
1162 g_string_append (str,
", ");
1167 g_string_append_printf (str,
"%s: %ld", v->
var_name, u->
v.
v_int);
1172 g_string_append_printf (str,
"%s: '%s'", v->
var_name,
1175 g_string_append_printf (str,
"%s: '%s'...", v->
var_name,
1179 g_string_append_printf (str,
"%s: ????", v->
var_name);
1184 g_string_append (str,
" ]");
1185 return g_string_free (str, FALSE);
1199 snprintf (s1,
sizeof (s1),
"%ld", v->
v.
v_int);
1208 nasl_perror (NULL,
"var2str: variable %s is undefined!\n",
1218 nasl_perror (NULL,
"var2str: variable %s has unhandled type %d\n",
1229 return var2int (v, defval);
1236 return var2int (&v->
u, defval);
1243 return var2int (&v->
u, defval);
1294 return get_var_size (&v->
u);
1301 return get_var_size (&v->
u);
1308 return get_var_size (v);
1355 nasl_perror (ctxt,
"nasl_array_iterator: unhandled type %d (0x%x)\n",
1367 if (it == NULL || it->
a == NULL)
1388 while (it->
v == NULL)
1397 while (it->
v == NULL);
1410 "add_var_to_list: negative index are not (yet) supported\n");
1422 free_anon_var (a->
num_elt[i]);
1423 v2 = dup_anon_var (v);
1435 int h = hash_str (
name);
1448 copy_anon_var (&(v2->
u), v);
1461 for (i = a->
max_idx - 1; i >= 0; i--)
1489 for (n = 0, c = el; c != NULL; c = c->
link[1])
1501 for (n = 0, c = el; c != NULL; c = c->
link[1])
1506 memset (&v, 0,
sizeof (v));
1529 "make_array_from_list: unhandled cell type %s at position %d\n",
int nasl_trace_enabled(void)
Checks if the nasl_trace_fp is set.
anon_nasl_var * nasl_get_var_by_num(void *ctxt, nasl_array *a, int num, int create)
char * get_str_var_by_num(lex_ctxt *lexic, int num)
struct st_n_nasl_var * next_var
tree_cell * copy_ref_array(const tree_cell *c1)
union st_a_nasl_var::@9 v
long int get_int_local_var_by_name(lex_ctxt *lexic, const char *name, int defval)
tree_cell * make_array_from_elems(tree_cell *el)
void deref_cell(tree_cell *c)
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
tree_cell * get_variable_by_name(lex_ctxt *ctxt, const char *name)
void clear_anon_var(anon_nasl_var *v)
named_nasl_var * add_named_var_to_ctxt(lex_ctxt *lexic, const char *name, tree_cell *val)
long int get_int_var_by_num(lex_ctxt *lexic, int num, int defval)
tree_cell * decl_global_variables(lex_ctxt *lexic, tree_cell *vars)
tree_cell * get_array_elem(lex_ctxt *ctxt, const char *name, tree_cell *idx)
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
tree_cell * alloc_typed_cell(int typ)
void nasl_trace(lex_ctxt *lexic, char *msg,...)
Prints debug message in printf fashion to nasl_trace_fp if it exists.
int get_var_size_by_name(lex_ctxt *lexic, const char *name)
struct st_a_nasl_var ** num_elt
char * array2str(const nasl_array *a)
tree_cell * nasl_read_var_ref(lex_ctxt *lexic, tree_cell *tc)
char * get_str_local_var_by_name(lex_ctxt *lexic, const char *name)
void nasl_perror(lex_ctxt *lexic, char *msg,...)
int get_local_var_size_by_name(lex_ctxt *lexic, const char *name)
tree_cell * var2cell(anon_nasl_var *v)
nasl_iterator nasl_array_iterator(void *ctxt, tree_cell *c)
tree_cell * nasl_iterate_array(nasl_iterator *it)
struct st_n_nasl_var ** hash_elt
tree_cell * alloc_tree_cell(int lnb, char *s)
const char * var2str(const anon_nasl_var *v)
int get_var_size_by_num(lex_ctxt *lexic, int num)
int array_max_index(nasl_array *a)
const char * nasl_type_name(int t)
int hash_str2(const char *s, int n)
tree_cell * decl_local_variables(lex_ctxt *lexic, tree_cell *vars)
char * get_str_var_by_name(lex_ctxt *lexic, const char *name)
void free_array(nasl_array *a)
anon_nasl_var * add_numbered_var_to_ctxt(lex_ctxt *lexic, int num, tree_cell *val)
long int get_int_var_by_name(lex_ctxt *lexic, const char *name, int defval)
char * get_line_nb(const tree_cell *c)
tree_cell * alloc_expr_cell(int lnb, int t, tree_cell *l, tree_cell *r)
int get_local_var_type_by_name(lex_ctxt *lexic, const char *name)
tree_cell * nasl_affect(tree_cell *lval, tree_cell *rval)
struct struct_lex_ctxt * up_ctxt
tree_cell * nasl_incr_variable(lex_ctxt *lexic, tree_cell *tc, int pre, int val)
int get_var_type_by_num(lex_ctxt *lexic, int num)
Returns NASL variable/cell type, VAR2_UNDEF if value is NULL.