OpenVAS Libraries  4.0+rc3.SVN
nasl/nasl_var.h
00001 /* Nessus Attack Scripting Language 
00002  *
00003  * Copyright (C) 2002 - 2003 Michel Arboi and Renaud Deraison
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2,
00007  * as published by the Free Software Foundation
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #ifndef NASL_VAR_H_INCLUDED
00020 #define NASL_VAR_H_INCLUDED
00021 
00022 enum
00023 {
00024   VAR2_UNDEF = 0,
00025   VAR2_INT,
00026   VAR2_STRING,
00027   VAR2_DATA,
00028   VAR2_ARRAY
00029 };
00030 
00031 #define VAR_NAME_HASH 17
00032 
00033 typedef struct st_nasl_string
00034 {
00035   unsigned char *s_val;
00036   int s_siz;
00037 } nasl_string_t;
00038 
00039 struct st_a_nasl_var;
00040 
00041 typedef struct st_nasl_array
00042 {
00043   int max_idx;                  /* max index - 1! */
00044   struct st_a_nasl_var **num_elt;       /* max_idx elements */
00045   struct st_n_nasl_var **hash_elt;      /* VAR_NAME_HASH elements */
00046 } nasl_array;
00047 
00048 #if NASL_DEBUG > 0
00049 #define ALL_VARIABLES_NAMED
00050 #endif
00051 
00052 typedef struct st_a_nasl_var
00053 {
00054   int var_type;
00055 #ifdef ALL_VARIABLES_NAMED
00056   char *av_name;
00057 #endif
00058   union
00059   {
00060     nasl_string_t v_str;        /* character string / data */
00061     int v_int;                  /* integer */
00062     nasl_array v_arr;           /* array */
00063   } v;
00064 } anon_nasl_var;
00065 
00066 typedef struct st_n_nasl_var
00067 {
00068   struct st_a_nasl_var u;
00069 #ifndef ALL_VARIABLES_NAMED
00070   char *var_name;
00071 #else
00072 #define var_name  u.av_name
00073 #endif
00074   struct st_n_nasl_var *next_var;       /* next variable with same name hash */
00075 } named_nasl_var;
00076 
00077 typedef struct
00078 {
00079   nasl_array *a;                /* array */
00080   int i1;                       /* index of numbered elements */
00081   int iH;                       /* index of hash */
00082   named_nasl_var *v;            /* current variable in hash */
00083 } nasl_iterator;
00084 
00085 tree_cell *nasl_affect (tree_cell *, tree_cell *);
00086 
00087 void clear_unnamed_var (anon_nasl_var *);
00088 const char *var2str (const anon_nasl_var *);
00089 
00090 anon_nasl_var *nasl_get_var_by_num (nasl_array *, int, int);
00091 
00092 nasl_iterator nasl_array_iterator (tree_cell *);
00093 tree_cell *nasl_iterate_array (nasl_iterator *);
00094 int add_var_to_list (nasl_array *, int, const anon_nasl_var *);
00095 int add_var_to_array (nasl_array *, char *, const anon_nasl_var *);
00096 int array_max_index (nasl_array *);
00097 void free_array (nasl_array *);
00098 
00099 tree_cell *copy_ref_array (const tree_cell *);
00100 int hash_str2 (const char *, int);
00101 tree_cell *var2cell (anon_nasl_var *);
00102 
00103 tree_cell *make_array_from_elems (tree_cell *);
00104 const char *array2str (const nasl_array *);
00105 
00106 
00107 
00108 #endif