OpenVAS Libraries  9.0.3
nasl_init.c File Reference
#include "nasl_raw.h"
#include <string.h>
#include <stdlib.h>
#include "../misc/nvt_categories.h"
#include "../misc/network.h"
#include "nasl.h"
#include "nasl_tree.h"
#include "nasl_global_ctxt.h"
#include "nasl_func.h"
#include "nasl_var.h"
#include "nasl_lex_ctxt.h"
#include "exec.h"
#include "nasl_packet_forgery.h"
#include "nasl_debug.h"
#include "nasl_socket.h"
#include "nasl_http.h"
#include "nasl_host.h"
#include "nasl_text_utils.h"
#include "nasl_scanner_glue.h"
#include "nasl_misc_funcs.h"
#include "nasl_cmd_exec.h"
#include "nasl_crypto.h"
#include "nasl_crypto2.h"
#include "nasl_wmi.h"
#include "nasl_smb.h"
#include "nasl_packet_forgery_v6.h"
#include "nasl_builtin_plugins.h"
#include "nasl_ssh.h"
#include "nasl_snmp.h"
#include "nasl_cert.h"
#include "nasl_isotime.h"
Include dependency graph for nasl_init.c:

Go to the source code of this file.

Data Structures

struct  init_func
 

Functions

int init_nasl_library (lex_ctxt *lexic)
 Adds "built-in" variable and function definitions to a context. More...
 
char * nasl_version ()
 

Function Documentation

◆ init_nasl_library()

int init_nasl_library ( lex_ctxt lexic)

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

Returns
Number of definitions done -1.

Definition at line 651 of file nasl_init.c.

Referenced by exec_nasl_script().

652 {
653  int i, j, c;
654  nasl_func *pf;
655  tree_cell tc;
656  const char **p, *q;
657 
658  memset (&tc, 0, sizeof (tc));
659  for (i = 0, c = 0; i < sizeof (libfuncs) / sizeof (libfuncs[0]) - 1; i++)
660  {
661  if ((pf = insert_nasl_func (lexic, libfuncs[i].name, NULL)) == NULL)
662  {
663  nasl_perror (lexic, "init_nasl_library: could not define fct '%s'\n",
664  libfuncs[i].name);
665  continue;
666  }
667  pf->block = libfuncs[i].c_code;
668  pf->flags |= FUNC_FLAG_INTERNAL;
669  pf->nb_unnamed_args = libfuncs[i].unnamed;
670 
671  for (j = 0, p = libfuncs[i].args, q = NULL; (*p) != NULL; j++)
672  {
673  if (q != NULL && strcmp (q, *p) > 0)
674  nasl_perror (lexic,
675  "init_nasl_library: unsorted args for function %s: %s > %s\n",
676  libfuncs[i].name, q, (*p));
677  q = (*p);
678  p++;
679  }
680  pf->nb_named_args = j;
681  pf->args_names = (char **) libfuncs[i].args;
682 
683  c++;
684  }
685 
686  // Initialize constant integer terms
687  tc.type = CONST_INT;
688  for (i = 0; i < sizeof (libivars) / sizeof (libivars[0]) - 1; i++)
689  {
690  tc.x.i_val = libivars[i].val;
691  if (add_named_var_to_ctxt (lexic, libivars[i].name, &tc) == NULL)
692  {
693  nasl_perror (lexic, "init_nasl_library: could not define var '%s'\n",
694  libivars[i].name);
695  continue;
696  }
697  c++;
698  }
699 
700  // Initialize constant string terms
701  tc.type = CONST_DATA;
702  for (i = 0; i < sizeof (libsvars) / sizeof (libsvars[0]) - 1; i++)
703  {
704  tc.x.str_val = (char *) libsvars[i].val;
705  tc.size = strlen (libsvars[i].val);
706  if (add_named_var_to_ctxt (lexic, libsvars[i].name, &tc) == NULL)
707  {
708  nasl_perror (lexic, "init_nasl_library: could not define var '%s'\n",
709  libsvars[i].name);
710  continue;
711  }
712  c++;
713  }
714 
715  // Add the "NULL" variable
716  if (add_named_var_to_ctxt (lexic, "NULL", NULL) == NULL)
717  nasl_perror (lexic, "init_nasl_library: could not define var 'NULL'\n");
718 
719  return c;
720 }
void * block
Definition: nasl_func.h:36
const char * val
Definition: nasl_init.c:525
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
char ** args_names
Definition: nasl_func.h:35
int nb_named_args
Definition: nasl_func.h:34
union TC::@7 x
nasl_func * insert_nasl_func(lex_ctxt *lexic, const char *fname, tree_cell *decl_node)
Definition: nasl_func.c:65
int unnamed
Definition: nasl_init.c:63
#define FUNC_FLAG_INTERNAL
Definition: nasl_func.h:25
named_nasl_var * add_named_var_to_ctxt(lex_ctxt *, const char *, tree_cell *)
Definition: nasl_var.c:908
Definition: nasl_tree.h:105
const char * name
Definition: nasl_init.c:524
tree_cell *(* c_code)(lex_ctxt *)
Definition: nasl_init.c:62
int nb_unnamed_args
Definition: nasl_func.h:34
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
long int i_val
Definition: nasl_tree.h:114
int size
Definition: nasl_tree.h:110
Here is the caller graph for this function:

◆ nasl_version()

char* nasl_version ( void  )

Definition at line 724 of file nasl_init.c.

Referenced by main().

725 {
726  static char vers[sizeof (OPENVASLIB_VERSION) + 1];
727  strncpy (vers, OPENVASLIB_VERSION, sizeof (vers) - 1);
728  vers[sizeof (vers) - 1] = '\0';
729  return vers;
730 }
Here is the caller graph for this function:

Variable Documentation

◆ name

◆ val