OpenVAS Scanner  22.7.9
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 727 of file nasl_isotime.c.

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

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 575 of file nasl_isotime.c.

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

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 543 of file nasl_isotime.c.

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

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 677 of file nasl_isotime.c.

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

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 626 of file nasl_isotime.c.

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

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:103
string2isotime
static int string2isotime(my_isotime_t atime, const char *string)
Definition: nasl_isotime.c:234
CONST_STR
@ CONST_STR
Definition: nasl_tree.h:80
TC::x
union TC::@5 x
isotime_p
static int isotime_p(const char *string)
Definition: nasl_isotime.c:137
check_isotime
static int check_isotime(const my_isotime_t atime)
Definition: nasl_isotime.c:113
VAR2_STRING
@ VAR2_STRING
Definition: nasl_var.h:17
VAR2_DATA
@ VAR2_DATA
Definition: nasl_var.h:18
my_isotime_t
char my_isotime_t[ISOTIME_SIZE]
Definition: nasl_isotime.c:65
add_days_to_isotime
static int add_days_to_isotime(my_isotime_t atime, int ndays)
Definition: nasl_isotime.c:452
TC::size
int size
Definition: nasl_tree.h:99
get_int_var_by_name
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1104
ISOTIME_SIZE
#define ISOTIME_SIZE
Definition: nasl_isotime.c:64
add_seconds_to_isotime
static int add_seconds_to_isotime(my_isotime_t atime, int nseconds)
Definition: nasl_isotime.c:405
get_str_var_by_num
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1111
TC
Definition: nasl_tree.h:94
add_years_to_isotime
static int add_years_to_isotime(my_isotime_t atime, int nyears)
Definition: nasl_isotime.c:490
get_current_isotime
static void get_current_isotime(my_isotime_t timebuf)
Definition: nasl_isotime.c:103
CONST_INT
@ CONST_INT
Definition: nasl_tree.h:79
get_var_size_by_num
int get_var_size_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1145
isotime_human_p
static int isotime_human_p(const char *string)
Definition: nasl_isotime.c:163
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:1155
alloc_typed_cell
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:28
TC::i_val
long int i_val
Definition: nasl_tree.h:104