OpenVAS Scanner  7.0.1~git
nasl_isotime.h File Reference

Protos and data structures for ISOTIME functions used by NASL scripts. More...

#include "nasl_lex_ctxt.h"
Include dependency graph for nasl_isotime.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

tree_cellnasl_isotime_now (lex_ctxt *lexic)
 Return the current time in ISO format. More...
 
tree_cellnasl_isotime_is_valid (lex_ctxt *lexic)
 Check whether an ISO time string is valid. More...
 
tree_cellnasl_isotime_scan (lex_ctxt *lexic)
 Convert a string into an ISO time string. More...
 
tree_cellnasl_isotime_print (lex_ctxt *lexic)
 Convert an SIO time string into a better readable string. More...
 
tree_cellnasl_isotime_add (lex_ctxt *lexic)
 Add days or seconds to an ISO time string. More...
 

Detailed Description

Protos and data structures for ISOTIME functions used by NASL scripts.

This file contains the protos for nasl_isotime.c

Definition in file nasl_isotime.h.

Function Documentation

◆ nasl_isotime_add()

tree_cell* nasl_isotime_add ( lex_ctxt lexic)

Add days or seconds to an ISO time string.

NASL Function: isotime_add\n

This function adds days or seconds to an ISO time string and returns the resulting time string. The number of days or seconds are given using the named parameters; if none are given nothing is added; if both are given both additions are performed. This function won't work for dates before the Gregorian calendar switch.

NASL Unnamed Parameters:\n
  • An ISO time string
NASL Named Parameters:\n
  • years An integer with the number of years to add to the timestamp.
  • days An integer with the number of days to add to the timestamp.
  • seconds An integer with the number of seconds to add to the timestamp.
NASL Returns:\n The resulting ISO time string or NULL if the provided ISO
time string is not valid or the result would overflow (i.e. year > 9999).
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
A tree cell.

Definition at line 726 of file nasl_isotime.c.

727 {
728  tree_cell *retc;
729  my_isotime_t timebuf;
730  const char *string;
731  int nyears, ndays, nseconds;
732 
733  string = get_str_var_by_num (lexic, 0);
734  if (!string || get_var_size_by_num (lexic, 0) < ISOTIME_SIZE - 1
735  || check_isotime (string))
736  return NULL;
737  memcpy (timebuf, string, ISOTIME_SIZE - 1);
738  timebuf[ISOTIME_SIZE - 1] = 0;
739 
740  nyears = get_int_var_by_name (lexic, "years", 0);
741  ndays = get_int_var_by_name (lexic, "days", 0);
742  nseconds = get_int_var_by_name (lexic, "seconds", 0);
743 
744  if (nyears && add_years_to_isotime (timebuf, nyears))
745  return NULL;
746  if (ndays && add_days_to_isotime (timebuf, ndays))
747  return NULL;
748  if (nseconds && add_seconds_to_isotime (timebuf, nseconds))
749  return NULL;
750  /* If nothing was added, explicitly add 0 years. */
751  if (!nyears && !ndays && !nseconds && add_years_to_isotime (timebuf, 0))
752  return NULL;
753 
754  retc = alloc_typed_cell (CONST_STR);
755  retc->x.str_val = g_strdup (timebuf);
756  retc->size = strlen (timebuf);
757  return retc;
758 }

References add_days_to_isotime(), add_seconds_to_isotime(), add_years_to_isotime(), alloc_typed_cell(), check_isotime(), CONST_STR, get_int_var_by_name(), get_str_var_by_num(), get_var_size_by_num(), ISOTIME_SIZE, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ nasl_isotime_is_valid()

tree_cell* nasl_isotime_is_valid ( lex_ctxt lexic)

Check whether an ISO time string is valid.

NASL Function: isotime_is_valid\n
NASL Unnamed Parameters:\n
  • A string. Both, the standard 15 byte string and the better human readable up to 19 byte format are accepted here. If a plain data type is is provided only the 15 byte format is accepted.
NASL Returns:\n True is this is an ISO string; false if not.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
A tree cell.

Definition at line 574 of file nasl_isotime.c.

575 {
576  int result = 0;
577  tree_cell *retc;
578  my_isotime_t timebuf;
579  const char *string;
580  int datalen;
581 
582  string = get_str_var_by_num (lexic, 0);
583  if (string)
584  {
585  switch (get_var_type_by_num (lexic, 0))
586  {
587  case VAR2_DATA:
588  datalen = get_var_size_by_num (lexic, 0);
589  if (datalen < ISOTIME_SIZE - 1)
590  break; /* Too short */
591  memcpy (timebuf, string, ISOTIME_SIZE - 1);
592  timebuf[ISOTIME_SIZE - 1] = 0;
593  string = timebuf;
594  /* FALLTHRU */
595  case VAR2_STRING:
596  if (isotime_p (string) || isotime_human_p (string))
597  result = 1;
598  break;
599  default:
600  break;
601  }
602  }
603 
604  retc = alloc_typed_cell (CONST_INT);
605  retc->x.i_val = result;
606  return retc;
607 }

References alloc_typed_cell(), CONST_INT, get_str_var_by_num(), get_var_size_by_num(), get_var_type_by_num(), TC::i_val, isotime_human_p(), isotime_p(), ISOTIME_SIZE, VAR2_DATA, VAR2_STRING, and TC::x.

Here is the call graph for this function:

◆ nasl_isotime_now()

tree_cell* nasl_isotime_now ( lex_ctxt lexic)

Return the current time in ISO format.

NASL Function: isotime_now\n
NASL Unnamed Parameters:\n
  • None
NASL Returns:\n A string with the ISO time. If the current time is not
available an empty string is returned.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
A tree cell.

Definition at line 542 of file nasl_isotime.c.

543 {
544  tree_cell *retc;
545  my_isotime_t timebuf;
546 
547  (void) lexic;
548  get_current_isotime (timebuf);
549 
550  retc = alloc_typed_cell (CONST_STR);
551  retc->x.str_val = g_strdup (timebuf);
552  retc->size = strlen (timebuf);
553  return retc;
554 }

References alloc_typed_cell(), CONST_STR, get_current_isotime(), TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ nasl_isotime_print()

tree_cell* nasl_isotime_print ( lex_ctxt lexic)

Convert an SIO time string into a better readable string.

NASL Function: isotime_print\n
NASL Unnamed Parameters:\n
  • An ISO time string.
NASL Returns:\n A string in the format "YYYY-MM-DD HH:MM:SS" or "[none]"
if the provided time string is not valid.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
A tree cell.

Definition at line 676 of file nasl_isotime.c.

677 {
678  tree_cell *retc;
679  const char *string;
680  char helpbuf[20];
681 
682  string = get_str_var_by_num (lexic, 0);
683  if (!string || get_var_size_by_num (lexic, 0) < 15 || check_isotime (string))
684  strcpy (helpbuf, "[none]");
685  else
686  snprintf (helpbuf, sizeof helpbuf, "%.4s-%.2s-%.2s %.2s:%.2s:%.2s", string,
687  string + 4, string + 6, string + 9, string + 11, string + 13);
688  retc = alloc_typed_cell (CONST_STR);
689  retc->x.str_val = g_strdup (helpbuf);
690  retc->size = strlen (helpbuf);
691  return retc;
692 }

References alloc_typed_cell(), check_isotime(), CONST_STR, get_str_var_by_num(), get_var_size_by_num(), TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ nasl_isotime_scan()

tree_cell* nasl_isotime_scan ( lex_ctxt lexic)

Convert a string into an ISO time string.

NASL Function: isotime_scan\n
NASL Unnamed Parameters:\n
  • A string
NASL Returns:\n A ISO time string on success or NULL on error.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
A tree cell.

Definition at line 625 of file nasl_isotime.c.

626 {
627  tree_cell *retc;
628  my_isotime_t timebuf;
629  int datalen;
630  const char *string;
631 
632  *timebuf = 0;
633  string = get_str_var_by_num (lexic, 0);
634  if (!string)
635  return NULL;
636  switch (get_var_type_by_num (lexic, 0))
637  {
638  case VAR2_DATA:
639  datalen = get_var_size_by_num (lexic, 0);
640  if (datalen < ISOTIME_SIZE - 1)
641  return NULL; /* Too short */
642  memcpy (timebuf, string, ISOTIME_SIZE - 1);
643  timebuf[ISOTIME_SIZE - 1] = 0;
644  string = timebuf;
645  /* FALLTHRU */
646  case VAR2_STRING:
647  if (!string2isotime (timebuf, string))
648  return NULL;
649  break;
650  default:
651  return NULL;
652  }
653 
654  retc = alloc_typed_cell (CONST_STR);
655  retc->x.str_val = g_strdup (timebuf);
656  retc->size = strlen (timebuf);
657  return retc;
658 }

References alloc_typed_cell(), CONST_STR, get_str_var_by_num(), get_var_size_by_num(), get_var_type_by_num(), ISOTIME_SIZE, TC::size, TC::str_val, string2isotime(), VAR2_DATA, VAR2_STRING, and TC::x.

Here is the call graph for this function:
TC::str_val
char * str_val
Definition: nasl_tree.h:112
string2isotime
static int string2isotime(my_isotime_t atime, const char *string)
Definition: nasl_isotime.c:243
CONST_STR
@ CONST_STR
Definition: nasl_tree.h:91
isotime_p
static int isotime_p(const char *string)
Definition: nasl_isotime.c:146
check_isotime
static int check_isotime(const my_isotime_t atime)
Definition: nasl_isotime.c:122
TC::x
union TC::@2 x
my_isotime_t
char my_isotime_t[ISOTIME_SIZE]
Definition: nasl_isotime.c:74
add_days_to_isotime
static int add_days_to_isotime(my_isotime_t atime, int ndays)
Definition: nasl_isotime.c:451
TC::size
int size
Definition: nasl_tree.h:109
get_int_var_by_name
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1113
VAR2_DATA
@ VAR2_DATA
Definition: nasl_var.h:29
ISOTIME_SIZE
#define ISOTIME_SIZE
Definition: nasl_isotime.c:73
add_seconds_to_isotime
static int add_seconds_to_isotime(my_isotime_t atime, int nseconds)
Definition: nasl_isotime.c:404
get_str_var_by_num
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1120
TC
Definition: nasl_tree.h:104
add_years_to_isotime
static int add_years_to_isotime(my_isotime_t atime, int nyears)
Definition: nasl_isotime.c:489
get_current_isotime
static void get_current_isotime(my_isotime_t timebuf)
Definition: nasl_isotime.c:112
CONST_INT
@ CONST_INT
Definition: nasl_tree.h:90
get_var_size_by_num
int get_var_size_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1154
isotime_human_p
static int isotime_human_p(const char *string)
Definition: nasl_isotime.c:172
get_var_type_by_num
int get_var_type_by_num(lex_ctxt *, int)
Returns NASL variable/cell type, VAR2_UNDEF if value is NULL.
Definition: nasl_var.c:1164
VAR2_STRING
@ VAR2_STRING
Definition: nasl_var.h:28
alloc_typed_cell
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
TC::i_val
long int i_val
Definition: nasl_tree.h:113