OpenVAS Scanner 23.32.3
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.
tree_cellnasl_isotime_is_valid (lex_ctxt *lexic)
 Check whether an ISO time string is valid.
tree_cellnasl_isotime_scan (lex_ctxt *lexic)
 Convert a string into an ISO time string.
tree_cellnasl_isotime_print (lex_ctxt *lexic)
 Convert an SIO time string into a better readable string.
tree_cellnasl_isotime_add (lex_ctxt *lexic)
 Add days or seconds to an ISO time string.

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
756 retc->x.str_val = g_strdup (timebuf);
757 retc->size = strlen (timebuf);
758 return retc;
759}
#define ISOTIME_SIZE
static int check_isotime(const my_isotime_t atime)
static int add_seconds_to_isotime(my_isotime_t atime, int nseconds)
static int add_days_to_isotime(my_isotime_t atime, int ndays)
char my_isotime_t[ISOTIME_SIZE]
static int add_years_to_isotime(my_isotime_t atime, int nyears)
int get_var_size_by_num(lex_ctxt *, int)
Definition nasl_var.c:1145
char * get_str_var_by_num(lex_ctxt *, int)
Definition nasl_var.c:1108
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition nasl_var.c:1101
tree_cell * alloc_typed_cell(int typ)
Definition nasl_tree.c:25
@ CONST_STR
Definition nasl_tree.h:80
struct TC tree_cell
int size
Definition nasl_tree.h:99
union TC::@332262321161220155002104006201360276211317150140 x
char * str_val
Definition nasl_tree.h:103
Define a string struct for storing the response.

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
606 retc->x.i_val = result;
607 return retc;
608}
static int isotime_p(const char *string)
static int isotime_human_p(const char *string)
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
@ CONST_INT
Definition nasl_tree.h:79
@ VAR2_STRING
Definition nasl_var.h:17
@ VAR2_DATA
Definition nasl_var.h:18
long int i_val
Definition nasl_tree.h:104

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
552 retc->x.str_val = g_strdup (timebuf);
553 retc->size = strlen (timebuf);
554 return retc;
555}
static void get_current_isotime(my_isotime_t timebuf)

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);
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
656 retc->x.str_val = g_strdup (timebuf);
657 retc->size = strlen (timebuf);
658 return retc;
659}
static int string2isotime(my_isotime_t atime, const char *string)

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: