OpenVAS Libraries  9.0.3
nasl_var.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  st_nasl_string
 
struct  st_nasl_array
 
struct  st_a_nasl_var
 
struct  st_n_nasl_var
 
struct  nasl_iterator
 

Macros

#define VAR_NAME_HASH   17
 

Typedefs

typedef struct st_nasl_string nasl_string_t
 
typedef struct st_nasl_array nasl_array
 
typedef struct st_a_nasl_var anon_nasl_var
 
typedef struct st_n_nasl_var named_nasl_var
 

Enumerations

enum  {
  VAR2_UNDEF = 0, VAR2_INT, VAR2_STRING, VAR2_DATA,
  VAR2_ARRAY
}
 

Functions

tree_cellnasl_affect (tree_cell *, tree_cell *)
 
void clear_unnamed_var (anon_nasl_var *)
 
const char * var2str (const anon_nasl_var *)
 
anon_nasl_varnasl_get_var_by_num (void *, nasl_array *, int, int)
 
nasl_iterator nasl_array_iterator (void *, tree_cell *)
 
tree_cellnasl_iterate_array (nasl_iterator *)
 
int add_var_to_list (nasl_array *, int, const anon_nasl_var *)
 
int add_var_to_array (nasl_array *, char *, const anon_nasl_var *)
 
int array_max_index (nasl_array *)
 
void free_array (nasl_array *)
 
tree_cellcopy_ref_array (const tree_cell *)
 
int hash_str2 (const char *, int)
 
tree_cellvar2cell (anon_nasl_var *)
 
tree_cellmake_array_from_elems (tree_cell *)
 
char * array2str (const nasl_array *)
 

Macro Definition Documentation

◆ VAR_NAME_HASH

#define VAR_NAME_HASH   17

Definition at line 31 of file nasl_var.h.

Typedef Documentation

◆ anon_nasl_var

typedef struct st_a_nasl_var anon_nasl_var

◆ named_nasl_var

typedef struct st_n_nasl_var named_nasl_var

◆ nasl_array

typedef struct st_nasl_array nasl_array

◆ nasl_string_t

typedef struct st_nasl_string nasl_string_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
VAR2_UNDEF 
VAR2_INT 
VAR2_STRING 
VAR2_DATA 
VAR2_ARRAY 

Definition at line 22 of file nasl_var.h.

23 {
24  VAR2_UNDEF = 0,
25  VAR2_INT,
27  VAR2_DATA,
29 };

Function Documentation

◆ add_var_to_array()

int add_var_to_array ( nasl_array ,
char *  ,
const anon_nasl_var  
)

Definition at line 1432 of file nasl_var.c.

1433 {
1434  named_nasl_var *v2;
1435  int h = hash_str (name);
1436 
1437  if (a->hash_elt == NULL)
1438  {
1439  a->hash_elt = g_malloc0 (VAR_NAME_HASH * sizeof (named_nasl_var *));
1440  }
1441 
1442  v2 = g_malloc0 (sizeof (named_nasl_var));
1443  v2->var_name = g_strdup (name);
1444  v2->u.var_type = VAR2_UNDEF;
1445  v2->next_var = a->hash_elt[h];
1446  a->hash_elt[h] = v2;
1447 
1448  copy_anon_var (&(v2->u), v);
1449  return 0;
1450 }
struct st_n_nasl_var * next_var
Definition: nasl_var.h:74
char * var_name
Definition: nasl_var.h:70
struct st_a_nasl_var u
Definition: nasl_var.h:68
int var_type
Definition: nasl_var.h:54
#define VAR_NAME_HASH
Definition: nasl_var.h:31
const char * name
Definition: nasl_init.c:524

Referenced by make_array_from_elems(), nasl_localtime(), and nasl_make_array().

Here is the caller graph for this function:

◆ add_var_to_list()

int add_var_to_list ( nasl_array ,
int  ,
const anon_nasl_var  
)

Definition at line 1403 of file nasl_var.c.

1404 {
1405  anon_nasl_var *v2;
1406 
1407  if (i < 0)
1408  {
1409  nasl_perror (NULL,
1410  "add_var_to_list: negative index are not (yet) supported\n");
1411  return -1;
1412  }
1413 
1414  if (i >= a->max_idx)
1415  {
1416  a->num_elt = g_realloc (a->num_elt, sizeof (anon_nasl_var *) * (i + 1));
1417  bzero (a->num_elt + a->max_idx,
1418  sizeof (anon_nasl_var *) * (i + 1 - a->max_idx));
1419  a->max_idx = i + 1;
1420  }
1421 
1422  free_anon_var (a->num_elt[i]);
1423  v2 = dup_anon_var (v); /* May return NULL */
1424  a->num_elt[i] = v2;
1425  if (v2 == NULL)
1426  return 0;
1427  else
1428  return 1;
1429 }
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94

References st_nasl_array::max_idx, nasl_perror(), and st_nasl_array::num_elt.

Referenced by make_array_from_elems(), nasl_bf_cbc(), nasl_eregmatch(), nasl_func_named_args(), nasl_get_sock_info(), nasl_keys(), nasl_make_array(), nasl_make_list(), and nasl_split().

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

◆ array2str()

char* array2str ( const nasl_array )

Definition at line 1119 of file nasl_var.c.

1120 {
1121  GString *str;
1122  int i, n1 = 0;
1123  anon_nasl_var *u;
1124  named_nasl_var *v;
1125 
1126  if (a == NULL)
1127  return NULL;
1128 
1129  str = g_string_new ("[ ");
1130  if (a->num_elt != NULL)
1131  for (i = 0; i < a->max_idx; i++)
1132  if ((u = a->num_elt[i]) != NULL && u->var_type != VAR2_UNDEF)
1133  {
1134  if (n1 > 0)
1135  g_string_append (str, ", ");
1136  n1++;
1137  switch (u->var_type)
1138  {
1139  case VAR2_INT:
1140  g_string_append_printf (str, "%d: %ld", i, u->v.v_int);
1141  break;
1142  case VAR2_STRING:
1143  case VAR2_DATA:
1144  if (u->v.v_str.s_siz < 64)
1145  g_string_append_printf (str, "%d: '%s'", i, u->v.v_str.s_val);
1146  else
1147  g_string_append_printf (str, "%d: '%s'...", i, u->v.v_str.s_val);
1148  break;
1149  default:
1150  g_string_append_printf (str, "%d: ????", i);
1151  break;
1152  }
1153  }
1154 
1155  if (a->hash_elt != NULL)
1156  for (i = 0; i < VAR_NAME_HASH; i++)
1157  for (v = a->hash_elt[i]; v != NULL; v = v->next_var)
1158  if (v->u.var_type != VAR2_UNDEF)
1159  {
1160  u = &v->u;
1161  if (n1 > 0)
1162  g_string_append (str, ", ");
1163  n1++;
1164  switch (u->var_type)
1165  {
1166  case VAR2_INT:
1167  g_string_append_printf (str, "%s: %ld", v->var_name, u->v.v_int);
1168  break;
1169  case VAR2_STRING:
1170  case VAR2_DATA:
1171  if (u->v.v_str.s_siz < 64)
1172  g_string_append_printf (str, "%s: '%s'", v->var_name,
1173  u->v.v_str.s_val);
1174  else
1175  g_string_append_printf (str, "%s: '%s'...", v->var_name,
1176  u->v.v_str.s_val);
1177  break;
1178  default:
1179  g_string_append_printf (str, "%s: ????", v->var_name);
1180  break;
1181  }
1182  }
1183 
1184  g_string_append (str, " ]");
1185  return g_string_free (str, FALSE);
1186 }
struct st_n_nasl_var * next_var
Definition: nasl_var.h:74
char * var_name
Definition: nasl_var.h:70
union st_a_nasl_var::@9 v
struct st_a_nasl_var u
Definition: nasl_var.h:68
nasl_string_t v_str
Definition: nasl_var.h:60
int var_type
Definition: nasl_var.h:54
#define VAR_NAME_HASH
Definition: nasl_var.h:31
unsigned char * s_val
Definition: nasl_var.h:35
long int v_int
Definition: nasl_var.h:61

References st_nasl_array::hash_elt, st_nasl_array::max_idx, st_n_nasl_var::next_var, st_nasl_array::num_elt, st_nasl_string::s_siz, st_nasl_string::s_val, st_n_nasl_var::u, st_a_nasl_var::v, st_a_nasl_var::v_int, st_a_nasl_var::v_str, VAR2_DATA, VAR2_INT, VAR2_STRING, VAR2_UNDEF, st_n_nasl_var::var_name, VAR_NAME_HASH, and st_a_nasl_var::var_type.

◆ array_max_index()

int array_max_index ( nasl_array a)

The name is not great: this function does not returns the index of the last element, but the index of the next free slot

Definition at line 1457 of file nasl_var.c.

1458 {
1459  int i;
1460 
1461  for (i = a->max_idx - 1; i >= 0; i--)
1462  if (a->num_elt[i] != NULL && a->num_elt[i]->var_type != VAR2_UNDEF)
1463  {
1464  /* Fixing max_index will realloc() at next store.
1465  * I am not sure it is a good idea
1466  * Wait and see */
1467  a->max_idx = i + 1;
1468  return i + 1;
1469  }
1470  return 0;
1471 }
int var_type
Definition: nasl_var.h:54
struct st_a_nasl_var ** num_elt
Definition: nasl_var.h:44

References st_nasl_array::max_idx, st_nasl_array::num_elt, VAR2_UNDEF, and st_a_nasl_var::var_type.

Referenced by nasl_max_index(), nasl_rawstring(), nasl_strcat(), and nasl_string().

Here is the caller graph for this function:

◆ clear_unnamed_var()

void clear_unnamed_var ( anon_nasl_var )

◆ copy_ref_array()

tree_cell* copy_ref_array ( const tree_cell )

Definition at line 566 of file nasl_var.c.

567 {
568  tree_cell *c2;
569  nasl_array *a2;
570 
571  if (c1 == NULL || c1 == FAKE_CELL || c1->type != REF_ARRAY)
572  return NULL;
573 
574  c2 = alloc_tree_cell (0, NULL);
575  c2->type = DYN_ARRAY;
576  c2->x.ref_val = a2 = g_malloc0 (sizeof (nasl_array));
577  copy_array (a2, c1->x.ref_val, 1);
578  return c2;
579 }
#define FAKE_CELL
Definition: nasl_tree.h:120
short type
Definition: nasl_tree.h:107
void * ref_val
Definition: nasl_tree.h:115
union TC::@7 x
Definition: nasl_tree.h:105
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37

References alloc_tree_cell(), DYN_ARRAY, FAKE_CELL, REF_ARRAY, TC::ref_val, TC::type, and TC::x.

Referenced by nasl_return().

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

◆ free_array()

void free_array ( nasl_array a)

Note: the function does not free the nasl_array structure. Do it if necessary

Definition at line 366 of file nasl_var.c.

367 {
368  int i;
369 
370  if (a == NULL)
371  return;
372  if (a->num_elt != NULL)
373  {
374  for (i = 0; i < a->max_idx; i++)
375  free_anon_var (a->num_elt[i]);
376  g_free (a->num_elt);
377  a->num_elt = NULL;
378  }
379  a->max_idx = 0;
380  if (a->hash_elt != NULL)
381  {
382  for (i = 0; i < VAR_NAME_HASH; i++)
383  free_var_chain (a->hash_elt[i]);
384  g_free (a->hash_elt);
385  a->hash_elt = NULL;
386  }
387 }
#define VAR_NAME_HASH
Definition: nasl_var.h:31
struct st_a_nasl_var ** num_elt
Definition: nasl_var.h:44
struct st_n_nasl_var ** hash_elt
Definition: nasl_var.h:45

References st_nasl_array::max_idx, and st_nasl_array::num_elt.

Referenced by clear_anon_var(), and free_lex_ctxt().

Here is the caller graph for this function:

◆ hash_str2()

int hash_str2 ( const char *  s,
int  n 
)
Todo:
Consider using GLibs string hash function.

Definition at line 51 of file nasl_var.c.

52 {
53  unsigned long h = 0;
54  const char *p;
55 
56  if (s == NULL)
57  return 0;
58 
59  for (p = s; *p != '\0'; p++)
60  h = (h << 3) + (unsigned char) *p;
61  return h % n;
62 }

◆ make_array_from_elems()

tree_cell* make_array_from_elems ( tree_cell el)

make_array_from_list is used by the parser only The list of elements is freed after use

Definition at line 1478 of file nasl_var.c.

1479 {
1480  int n;
1481  tree_cell *c, *c2;
1482  nasl_array *a;
1483  anon_nasl_var v;
1484 
1485  a = g_malloc0 (sizeof (nasl_array));
1486  /* Either the elements are all "named", or they are "numbered". No mix! */
1487  if (el->x.str_val == NULL) /* numbered */
1488  {
1489  for (n = 0, c = el; c != NULL; c = c->link[1])
1490  n++;
1491  a->max_idx = n;
1492  a->num_elt = g_malloc0 (sizeof (anon_nasl_var *) * n);
1493  a->hash_elt = NULL;
1494  }
1495  else
1496  {
1497  a->num_elt = NULL;
1498  a->hash_elt = g_malloc0 (VAR_NAME_HASH * sizeof (named_nasl_var *));
1499  }
1500 
1501  for (n = 0, c = el; c != NULL; c = c->link[1])
1502  {
1503  c2 = c->link[0];
1504  if (c2 != NULL && c2 != FAKE_CELL)
1505  {
1506  memset (&v, 0, sizeof (v));
1507  switch (c2->type)
1508  {
1509  case CONST_INT:
1510  v.var_type = VAR2_INT;
1511  v.v.v_int = c2->x.i_val;
1512  break;
1513  case CONST_STR:
1514  case CONST_DATA:
1515  v.var_type = c2->type == CONST_STR ? VAR2_STRING : VAR2_DATA;
1516  if (c2->x.str_val == NULL)
1517  {
1518  v.v.v_str.s_val = NULL;
1519  v.v.v_str.s_siz = 0;
1520  }
1521  else
1522  {
1523  v.v.v_str.s_siz = c2->size;
1524  v.v.v_str.s_val = (unsigned char *) c2->x.str_val;
1525  }
1526  break;
1527  default:
1528  nasl_perror (NULL,
1529  "make_array_from_list: unhandled cell type %s at position %d\n",
1530  nasl_type_name (c2->type), n);
1531  v.var_type = VAR2_UNDEF;
1532  break;
1533  }
1534  }
1535 
1536  if (c->x.str_val == NULL)
1537  add_var_to_list (a, n++, &v);
1538  else
1539  add_var_to_array (a, c->x.str_val, &v);
1540  }
1541 
1543  c->x.ref_val = a;
1544  deref_cell (el);
1545  return c;
1546 }
#define FAKE_CELL
Definition: nasl_tree.h:120
struct TC * link[4]
Definition: nasl_tree.h:117
short type
Definition: nasl_tree.h:107
union st_a_nasl_var::@9 v
char * str_val
Definition: nasl_tree.h:113
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:202
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
Definition: nasl_var.c:1432
void * ref_val
Definition: nasl_tree.h:115
nasl_string_t v_str
Definition: nasl_var.h:60
union TC::@7 x
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition: nasl_var.c:1403
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
int var_type
Definition: nasl_var.h:54
Definition: nasl_tree.h:105
#define VAR_NAME_HASH
Definition: nasl_var.h:31
struct st_a_nasl_var ** num_elt
Definition: nasl_var.h:44
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
long int i_val
Definition: nasl_tree.h:114
struct st_n_nasl_var ** hash_elt
Definition: nasl_var.h:45
const char * nasl_type_name(int t)
Definition: nasl_tree.c:420
unsigned char * s_val
Definition: nasl_var.h:35
long int v_int
Definition: nasl_var.h:61
int size
Definition: nasl_tree.h:110

References add_var_to_array(), add_var_to_list(), alloc_typed_cell(), CONST_DATA, CONST_INT, CONST_STR, deref_cell(), DYN_ARRAY, FAKE_CELL, st_nasl_array::hash_elt, TC::i_val, TC::link, st_nasl_array::max_idx, nasl_perror(), nasl_type_name(), st_nasl_array::num_elt, TC::ref_val, st_nasl_string::s_siz, st_nasl_string::s_val, TC::size, TC::str_val, TC::type, st_a_nasl_var::v, st_a_nasl_var::v_int, st_a_nasl_var::v_str, VAR2_DATA, VAR2_INT, VAR2_STRING, VAR2_UNDEF, VAR_NAME_HASH, st_a_nasl_var::var_type, and TC::x.

Here is the call graph for this function:

◆ nasl_affect()

tree_cell* nasl_affect ( tree_cell ,
tree_cell  
)

Definition at line 782 of file nasl_var.c.

783 {
784  anon_nasl_var *v1 = NULL;
785 
786  if (lval == NULL)
787  {
788  nasl_perror (NULL, "nasl_effect: invalid lvalue\n");
789  return NULL;
790  }
791 
792  if (lval->type != REF_VAR)
793  {
794  nasl_perror (NULL, "nasl_affect: cannot affect to non variable %s\n",
795  nasl_type_name (lval->type));
796  return NULL;
797  }
798 
799  v1 = lval->x.ref_val;
800  return affect_to_anon_var (v1, rval);
801 }
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
const char * nasl_type_name(int t)
Definition: nasl_tree.c:420

References nasl_perror(), nasl_type_name(), TC::ref_val, REF_VAR, TC::type, and TC::x.

Here is the call graph for this function:

◆ nasl_array_iterator()

nasl_iterator nasl_array_iterator ( void *  ,
tree_cell  
)

Definition at line 1329 of file nasl_var.c.

1330 {
1331  nasl_iterator it;
1332  anon_nasl_var *v;
1333 
1334  it.a = NULL;
1335  it.v = NULL;
1336  it.i1 = 0;
1337  it.iH = 0;
1338 
1339  if (c == NULL || c == FAKE_CELL)
1340  return it;
1341 
1342  if (c->type == REF_VAR)
1343  {
1344  v = c->x.ref_val;
1345  if (v == NULL || v->var_type != VAR2_ARRAY)
1346  return it;
1347  it.a = &v->v.v_arr;
1348  }
1349  else if (c->type == REF_ARRAY || c->type == DYN_ARRAY)
1350  {
1351  it.a = c->x.ref_val;
1352  }
1353  else
1354  {
1355  nasl_perror (ctxt, "nasl_array_iterator: unhandled type %d (0x%x)\n",
1356  c->type, c->type);
1357  }
1358 
1359  return it;
1360 }
#define FAKE_CELL
Definition: nasl_tree.h:120
union st_a_nasl_var::@9 v
named_nasl_var * v
Definition: nasl_var.h:82
nasl_array v_arr
Definition: nasl_var.h:62
int var_type
Definition: nasl_var.h:54
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
nasl_array * a
Definition: nasl_var.h:79

References nasl_iterator::a, DYN_ARRAY, FAKE_CELL, nasl_iterator::i1, nasl_iterator::iH, nasl_perror(), REF_ARRAY, TC::ref_val, REF_VAR, TC::type, st_a_nasl_var::v, nasl_iterator::v, st_a_nasl_var::v_arr, VAR2_ARRAY, st_a_nasl_var::var_type, and TC::x.

Here is the call graph for this function:

◆ nasl_get_var_by_num()

anon_nasl_var* nasl_get_var_by_num ( void *  ,
nasl_array ,
int  ,
int   
)

Definition at line 71 of file nasl_var.c.

72 {
73  anon_nasl_var *v = NULL;
74 
75  if (num < 0)
76  {
77  /* TBD: implement a min_index field, just like $[ in Perl */
78  nasl_perror (ctxt,
79  "Negative integer index %d are not supported yet!\n", num);
80  return NULL;
81  }
82 
83  if (num < a->max_idx)
84  v = a->num_elt[num];
85  if (v != NULL || !create)
86  return v;
87 
88  if (num >= a->max_idx)
89  {
90  a->num_elt = g_realloc (a->num_elt, sizeof (anon_nasl_var *) * (num + 1));
91  bzero (a->num_elt + a->max_idx,
92  sizeof (anon_nasl_var *) * (num + 1 - a->max_idx));
93  a->max_idx = num + 1;
94  }
95  v = g_malloc0 (sizeof (anon_nasl_var));
96  v->var_type = VAR2_UNDEF;
97 
98  a->num_elt[num] = v;
99  return v;
100 }
int var_type
Definition: nasl_var.h:54
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94

References st_nasl_array::max_idx, nasl_perror(), st_nasl_array::num_elt, VAR2_UNDEF, and st_a_nasl_var::var_type.

Referenced by nasl_keys(), nasl_make_array(), nasl_make_list(), nasl_max_index(), and nasl_typeof().

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

◆ nasl_iterate_array()

tree_cell* nasl_iterate_array ( nasl_iterator )

Definition at line 1363 of file nasl_var.c.

1364 {
1365  anon_nasl_var *av;
1366 
1367  if (it == NULL || it->a == NULL)
1368  return NULL;
1369 
1370  if (it->i1 >= 0)
1371  {
1372  while (it->i1 < it->a->max_idx)
1373  {
1374  av = it->a->num_elt[it->i1++];
1375  if (av != NULL && av->var_type != VAR2_UNDEF)
1376  return var2cell (av);
1377  }
1378  it->i1 = -1;
1379  }
1380 
1381  if (it->a->hash_elt == NULL)
1382  return NULL;
1383 
1384  if (it->v != NULL)
1385  it->v = it->v->next_var;
1386  do
1387  {
1388  while (it->v == NULL)
1389  if (it->iH >= VAR_NAME_HASH)
1390  return NULL;
1391  else
1392  it->v = it->a->hash_elt[it->iH++];
1393 
1394  while (it->v != NULL && it->v->u.var_type == VAR2_UNDEF)
1395  it->v = it->v->next_var;
1396  }
1397  while (it->v == NULL);
1398 
1399  return var2cell (&it->v->u);
1400 }
int var_type
Definition: nasl_var.h:54
#define VAR_NAME_HASH
Definition: nasl_var.h:31
tree_cell * var2cell(anon_nasl_var *v)
Definition: nasl_var.c:196

References nasl_iterator::a, st_nasl_array::hash_elt, nasl_iterator::i1, nasl_iterator::iH, st_nasl_array::max_idx, st_n_nasl_var::next_var, st_nasl_array::num_elt, st_n_nasl_var::u, nasl_iterator::v, VAR2_UNDEF, var2cell(), VAR_NAME_HASH, and st_a_nasl_var::var_type.

Here is the call graph for this function:

◆ var2cell()

tree_cell* var2cell ( anon_nasl_var )

Definition at line 196 of file nasl_var.c.

197 {
198  tree_cell *tc = alloc_tree_cell (0, NULL);
199 
200  tc->type = REF_VAR;
201  tc->x.ref_val = v; /* No need to free this later! */
202  return tc;
203 }
short type
Definition: nasl_tree.h:107
void * ref_val
Definition: nasl_tree.h:115
union TC::@7 x
Definition: nasl_tree.h:105
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37

References alloc_tree_cell(), TC::ref_val, REF_VAR, TC::type, and TC::x.

Referenced by nasl_iterate_array().

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

◆ var2str()

const char* var2str ( const anon_nasl_var )

Definition at line 1189 of file nasl_var.c.

1190 {
1191  static char s1[16];
1192 
1193  if (v == NULL)
1194  return NULL;
1195 
1196  switch (v->var_type)
1197  {
1198  case VAR2_INT:
1199  snprintf (s1, sizeof (s1), "%ld", v->v.v_int);
1200  return s1; /* buggy if called twice in a row */
1201 
1202  case VAR2_STRING:
1203  case VAR2_DATA:
1204  return v->v.v_str.s_val == NULL ? "" : (const char *) v->v.v_str.s_val;
1205 
1206  case VAR2_UNDEF:
1207 #if NASL_DEBUG > 1
1208  nasl_perror (NULL, "var2str: variable %s is undefined!\n",
1209  get_var_name (v));
1210 #endif
1211  return NULL;
1212 
1213  case VAR2_ARRAY:
1214  return array2str (&v->v.v_arr);
1215 
1216  default:
1217 #if NASL_DEBUG > 0
1218  nasl_perror (NULL, "var2str: variable %s has unhandled type %d\n",
1219  get_var_name (v), v->var_type);
1220 #endif
1221  return "";
1222  }
1223 }
#define NASL_DEBUG
Definition: nasl_var.c:34
char * array2str(const nasl_array *a)
Definition: nasl_var.c:1119
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94

References NASL_DEBUG, nasl_perror(), st_nasl_string::s_val, st_a_nasl_var::v, st_a_nasl_var::v_int, st_a_nasl_var::v_str, VAR2_DATA, VAR2_INT, VAR2_STRING, VAR2_UNDEF, and st_a_nasl_var::var_type.

Referenced by nasl_make_array().

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