OpenVAS Scanner
7.0.0~git
|
Implementation of an API for ISOTIME values. More...
#include "nasl_isotime.h"
#include "nasl_debug.h"
#include "nasl_global_ctxt.h"
#include "nasl_lex_ctxt.h"
#include "nasl_tree.h"
#include "nasl_var.h"
#include <ctype.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
Go to the source code of this file.
Macros | |
#define | DIM(v) (sizeof (v) / sizeof ((v)[0])) |
#define | DIMof(type, member) DIM (((type *) 0)->member) |
#define | ISOTIME_SIZE 19 |
#define | JD_DIFF 1721060L |
#define | spacep(p) (*(p) == ' ' || *(p) == '\t') |
#define | digitp(p) (*(p) >= '0' && *(p) <= '9') |
#define | atoi_1(p) (*(p) - '0') |
#define | atoi_2(p) ((atoi_1 (p) * 10) + atoi_1 ((p) + 1)) |
#define | atoi_4(p) ((atoi_2 (p) * 100) + atoi_2 ((p) + 2)) |
Typedefs | |
typedef char | my_isotime_t[ISOTIME_SIZE] |
Functions | |
static void | epoch2isotime (my_isotime_t timebuf, time_t atime) |
static void | get_current_isotime (my_isotime_t timebuf) |
static int | check_isotime (const my_isotime_t atime) |
static int | isotime_p (const char *string) |
static int | isotime_human_p (const char *string) |
static int | string2isotime (my_isotime_t atime, const char *string) |
static int | days_per_year (int y) |
static int | days_per_month (int y, int m) |
static unsigned long | date2jd (int year, int month, int day) |
static int | jd2date (unsigned long jd, int *year, int *month, int *day) |
static int | add_seconds_to_isotime (my_isotime_t atime, int nseconds) |
static int | add_days_to_isotime (my_isotime_t atime, int ndays) |
static int | add_years_to_isotime (my_isotime_t atime, int nyears) |
tree_cell * | nasl_isotime_now (lex_ctxt *lexic) |
Return the current time in ISO format. More... | |
tree_cell * | nasl_isotime_is_valid (lex_ctxt *lexic) |
Check whether an ISO time string is valid. More... | |
tree_cell * | nasl_isotime_scan (lex_ctxt *lexic) |
Convert a string into an ISO time string. More... | |
tree_cell * | nasl_isotime_print (lex_ctxt *lexic) |
Convert an SIO time string into a better readable string. More... | |
tree_cell * | nasl_isotime_add (lex_ctxt *lexic) |
Add days or seconds to an ISO time string. More... | |
Implementation of an API for ISOTIME values.
This file contains the implementation of the isotime_* NASL builtin functions.
Most 32 bit systems use a signed 32 bit time_t to represent the system time. The problem is that in 2038 this time type will overflow. However, we sometimes need to compute dates in the future; for example some certificates are (for whatever reasons) valid for 30 years. To solve this problem in a platform independent way, we represent the time as a string and provide functions to work with them. This is not an elegant solution, but all proposed new time APIs have never been implemented on main stream systems - we can't expect that this will happen any time soon.
Definition in file nasl_isotime.c.
#define atoi_1 | ( | p | ) | (*(p) - '0') |
Definition at line 84 of file nasl_isotime.c.
Definition at line 85 of file nasl_isotime.c.
Definition at line 86 of file nasl_isotime.c.
#define digitp | ( | p | ) | (*(p) >= '0' && *(p) <= '9') |
Definition at line 81 of file nasl_isotime.c.
#define DIM | ( | v | ) | (sizeof (v) / sizeof ((v)[0])) |
Definition at line 67 of file nasl_isotime.c.
#define DIMof | ( | type, | |
member | |||
) | DIM (((type *) 0)->member) |
Definition at line 68 of file nasl_isotime.c.
#define ISOTIME_SIZE 19 |
Definition at line 73 of file nasl_isotime.c.
#define JD_DIFF 1721060L |
Definition at line 77 of file nasl_isotime.c.
#define spacep | ( | p | ) | (*(p) == ' ' || *(p) == '\t') |
Definition at line 80 of file nasl_isotime.c.
typedef char my_isotime_t[ISOTIME_SIZE] |
Definition at line 74 of file nasl_isotime.c.
|
static |
Definition at line 443 of file nasl_isotime.c.
References atoi_2, atoi_4, check_isotime(), date2jd(), ISOTIME_SIZE, and jd2date().
Referenced by nasl_isotime_add().
|
static |
Definition at line 399 of file nasl_isotime.c.
References atoi_2, atoi_4, check_isotime(), date2jd(), ISOTIME_SIZE, and jd2date().
Referenced by nasl_isotime_add().
|
static |
Definition at line 479 of file nasl_isotime.c.
References atoi_2, atoi_4, check_isotime(), date2jd(), ISOTIME_SIZE, and jd2date().
Referenced by nasl_isotime_add().
|
static |
Definition at line 117 of file nasl_isotime.c.
References digitp.
Referenced by add_days_to_isotime(), add_seconds_to_isotime(), add_years_to_isotime(), nasl_isotime_add(), and nasl_isotime_print().
|
static |
Definition at line 329 of file nasl_isotime.c.
References JD_DIFF.
Referenced by add_days_to_isotime(), add_seconds_to_isotime(), add_years_to_isotime(), and jd2date().
|
static |
Definition at line 296 of file nasl_isotime.c.
Referenced by jd2date().
|
static |
Definition at line 283 of file nasl_isotime.c.
Referenced by jd2date().
|
static |
Definition at line 90 of file nasl_isotime.c.
References ISOTIME_SIZE.
Referenced by get_current_isotime().
|
static |
Definition at line 107 of file nasl_isotime.c.
References epoch2isotime().
Referenced by nasl_isotime_now().
|
static |
Definition at line 167 of file nasl_isotime.c.
References atoi_2, digitp, and spacep.
Referenced by nasl_isotime_is_valid(), and string2isotime().
|
static |
Definition at line 141 of file nasl_isotime.c.
References digitp.
Referenced by nasl_isotime_is_valid(), and string2isotime().
|
static |
Definition at line 349 of file nasl_isotime.c.
References date2jd(), days_per_month(), days_per_year(), and JD_DIFF.
Referenced by add_days_to_isotime(), add_seconds_to_isotime(), and add_years_to_isotime().
Add days or seconds to an ISO time string.
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.
[in] | lexic | Lexical context of the NASL interpreter. |
Definition at line 713 of file nasl_isotime.c.
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.
Check whether an ISO time string is valid.
[in] | lexic | Lexical context of the NASL interpreter. |
Definition at line 561 of file nasl_isotime.c.
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.
Return the current time in ISO format.
[in] | lexic | Lexical context of the NASL interpreter. |
Definition at line 529 of file nasl_isotime.c.
References alloc_typed_cell(), CONST_STR, get_current_isotime(), TC::size, TC::str_val, and TC::x.
Convert an SIO time string into a better readable string.
[in] | lexic | Lexical context of the NASL interpreter. |
Definition at line 663 of file nasl_isotime.c.
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.
Convert a string into an ISO time string.
[in] | lexic | Lexical context of the NASL interpreter. |
Definition at line 612 of file nasl_isotime.c.
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.
|
static |
Definition at line 238 of file nasl_isotime.c.
References isotime_human_p(), isotime_p(), and spacep.
Referenced by nasl_isotime_scan().