Asterisk - The Open Source Telephony Project
21.4.1
|
#include "asterisk.h"
#include <signal.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <float.h>
#include <stdlib.h>
#include <sys/inotify.h>
#include "private.h"
#include "tzfile.h"
#include "asterisk/_private.h"
#include "asterisk/lock.h"
#include "asterisk/localtime.h"
#include "asterisk/strings.h"
#include "asterisk/linkedlists.h"
#include "asterisk/utils.h"
#include "asterisk/test.h"
Go to the source code of this file.
Data Structures | |
struct | locale_entry |
struct | localelist |
struct | lsinfo |
leap second information More... | |
struct | rule |
struct | state |
struct | ttinfo |
time type information More... | |
struct | zonelist |
Macros | |
#define | BIGGEST(a, b) (((a) > (b)) ? (a) : (b)) |
#define | DAY_OF_YEAR 1 /* n - day of year */ |
#define | JULIAN_DAY 0 /* Jn - Julian day */ |
#define | MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */ |
#define | MY_TZNAME_MAX 255 |
#define | OPEN_MODE O_RDONLY |
#define | SP_HEAP_FREE(sp) do {} while (0) |
#define | SP_HEAP_INIT(sp) |
#define | SP_STACK_CHECK(sp) ((sp)->wd[0] == SP_STACK_FLAG) |
#define | SP_STACK_FLAG INT_MIN |
#define | SP_STACK_INIT(sp) |
#define | TZ_ABBR_CHAR_SET "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 :+-._" |
#define | TZ_ABBR_ERR_CHAR '_' |
#define | TZ_ABBR_MAX_LEN 16 |
#define | TZ_STRLEN_MAX 255 |
#define | TZDEFRULESTRING ",M4.1.0,M10.5.0" |
Functions | |
static void | add_notify (struct state *sp, const char *path) |
void | ast_get_dst_info (const time_t *const timep, int *dst_enabled, time_t *dst_start, time_t *dst_end, int *gmt_off, const char *const zone) |
struct ast_tm * | ast_localtime (const struct timeval *timep, struct ast_tm *tmp, const char *zone) |
Timezone-independent version of localtime_r(3). More... | |
void | ast_localtime_wakeup_monitor (struct ast_test *info) |
struct timeval | ast_mktime (struct ast_tm *tmp, const char *zone) |
Timezone-independent version of mktime(3). More... | |
const char * | ast_setlocale (const char *locale) |
Set the thread-local representation of the current locale. | |
int | ast_strftime (char *buf, size_t len, const char *tmp, const struct ast_tm *tm) |
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strftime(3), with the addition of q, which specifies microseconds. More... | |
int | ast_strftime_locale (char *buf, size_t len, const char *tmp, const struct ast_tm *tm, const char *locale) |
char * | ast_strptime (const char *s, const char *format, struct ast_tm *tm) |
Special version of strptime(3) which places the answer in the common structure ast_tm. Also, unlike strptime(3), ast_strptime() initializes its memory prior to use. More... | |
char * | ast_strptime_locale (const char *s, const char *format, struct ast_tm *tm, const char *locale) |
static const struct state * | ast_tzset (const char *zone) |
void | clean_time_zones (void) |
static void | common_startup (void) |
static long | detzcode (const char *const codep) |
static time_t | detzcode64 (const char *const codep) |
static int | differ_by_repeat (const time_t t1, const time_t t0) |
static struct locale_entry * | find_by_locale (locale_t locale) |
static struct locale_entry * | find_by_name (const char *name) |
static const char * | getnum (const char *strp, int *nump, const int min, const int max) |
Given a pointer into a time zone string, extract a number from that string. Check that the number is within a specified range; if it is not, return NULL. Otherwise, return a pointer to the first character not part of the number. | |
static const char * | getoffset (const char *strp, long *offsetp) |
Given a pointer into a time zone string, extract an offset, in [+-]hh[:mm[:ss]] form, from the string. If any error occurs, return NULL. Otherwise, return a pointer to the first character not part of the time. | |
static const char * | getqzname (const char *strp, const int delim) |
Given a pointer into an extended time zone string, scan until the ending delimiter of the zone name is located. Return a pointer to the delimiter. More... | |
static const char * | getrule (const char *strp, struct rule *rulep) |
Given a pointer into a time zone string, extract a rule in the form date[/time]. See POSIX section 8 for the format of "date" and "time". If a valid rule is not found, return NULL. Otherwise, return a pointer to the first character not part of the rule. | |
static const char * | getsecs (const char *strp, long *const secsp) |
Given a pointer into a time zone string, extract a number of seconds, in hh[:mm[:ss]] form, from the string. If any error occurs, return NULL. Otherwise, return a pointer to the first character not part of the number of seconds. | |
static const char * | getzname (const char *strp) |
Given a pointer into a time zone string, scan until a character that is not a valid character in a zone name is found. Return a pointer to that character. | |
static int | gmtload (struct state *sp) |
static struct ast_tm * | gmtsub (const struct timeval *timep, const long offset, struct ast_tm *tmp) |
static int | increment_overflow (int *number, int delta) |
Simplified normalize logic courtesy Paul Eggert. More... | |
static void * | inotify_daemon (void *data) |
static int | leaps_thru_end_of (const int y) |
Return the number of leap years through the end of the given year where, to make the math easy, the answer for year zero is defined as zero. | |
static struct ast_tm * | localsub (const struct timeval *timep, const long offset, struct ast_tm *tmp, const struct state *sp) |
static int | long_increment_overflow (long *number, int delta) |
static int | long_normalize_overflow (long *tensptr, int *unitsptr, const int base) |
static int | normalize_overflow (int *tensptr, int *unitsptr, const int base) |
static long detzcode | P ((const char *codep)) |
static int differ_by_repeat | P ((time_t t1, time_t t0)) |
static const char *getzname | P ((const char *strp)) |
static const char *getqzname | P ((const char *strp, const int delim)) |
static const char *getnum | P ((const char *strp, int *nump, int min, int max)) |
static const char *getsecs | P ((const char *strp, long *secsp)) |
static const char *getoffset | P ((const char *strp, long *offsetp)) |
static const char *getrule | P ((const char *strp, struct rule *rulep)) |
static int gmtload | P ((struct state *sp)) |
static struct ast_tm *gmtsub | P ((const struct timeval *timep, long offset, struct ast_tm *tmp)) |
static struct ast_tm *localsub | P ((const struct timeval *timep, long offset, struct ast_tm *tmp, const struct state *sp)) |
static int increment_overflow | P ((int *number, int delta)) |
static int leaps_thru_end_of | P ((int y)) |
static int long_increment_overflow | P ((long *number, int delta)) |
static int long_normalize_overflow | P ((long *tensptr, int *unitsptr, const int base)) |
static int normalize_overflow | P ((int *tensptr, int *unitsptr, const int base)) |
static struct timeval time1 | P ((struct ast_tm *tmp, struct ast_tm *(*funcp) P((const struct timeval *, long, struct ast_tm *, const struct state *sp)), long offset, const struct state *sp)) |
static struct timeval time2sub | P ((struct ast_tm *tmp, struct ast_tm *(*funcp)(const struct timeval *, long, struct ast_tm *, const struct state *sp), long offset, int *okayp, int do_norm_secs, const struct state *sp)) |
static struct timeval time2 | P ((struct ast_tm *tmp, struct ast_tm *(*funcp) P((const struct timeval *, long, struct ast_tm *, const struct state *sp)), long offset, int *okayp, const struct state *sp)) |
static struct ast_tm *timesub | P ((const struct timeval *timep, long offset, const struct state *sp, struct ast_tm *tmp)) |
static int tmcomp | P ((const struct ast_tm *atmp, const struct ast_tm *btmp)) |
static time_t transtime | P ((time_t janfirst, int year, const struct rule *rulep, long offset)) |
static int tzload | P ((const char *name, struct state *sp, int doextend)) |
static int tzparse | P ((const char *name, struct state *sp, int lastditch)) |
static struct state * | sstate_alloc (void) |
static void | sstate_free (struct state *p) |
static const char * | store_by_locale (locale_t prevlocale) |
static struct timeval | time1 (struct ast_tm *tmp, struct ast_tm *(*const funcp)(const struct timeval *, long, struct ast_tm *, const struct state *), const long offset, const struct state *sp) |
static struct timeval | time2 (struct ast_tm *tmp, struct ast_tm *(*const funcp)(const struct timeval *, long, struct ast_tm *, const struct state *sp), const long offset, int *okayp, const struct state *sp) |
static struct timeval | time2sub (struct ast_tm *tmp, struct ast_tm *(*const funcp)(const struct timeval *, long, struct ast_tm *, const struct state *), const long offset, int *okayp, const int do_norm_secs, const struct state *sp) |
static struct ast_tm * | timesub (const struct timeval *timep, const long offset, const struct state *sp, struct ast_tm *tmp) |
static int | tmcomp (const struct ast_tm *atmp, const struct ast_tm *btmp) |
static time_t | transtime (const time_t janfirst, const int year, const struct rule *rulep, const long offset) |
Given the Epoch-relative time of January 1, 00:00:00 UTC, in a year, the year, a rule, and the offset from UTC at the time that rule takes effect, calculate the Epoch-relative time that rule takes effect. | |
static int | tzload (const char *name, struct state *const sp, const int doextend) |
static int | tzparse (const char *name, struct state *sp, const int lastditch) |
Variables | |
static char | elsieid [] = "@(#)localtime.c 8.5" |
static const char | gmt [] = "GMT" |
static ast_cond_t | initialization |
static ast_mutex_t | initialization_lock |
static int | inotify_fd = -1 |
static pthread_t | inotify_thread = AST_PTHREADT_NULL |
static struct localelist | localelist = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , } |
static const int | mon_lengths [2][MONSPERYEAR] |
static const struct timeval | WRONG = { 0, 0 } |
static const int | year_lengths [2] |
static struct zonelist | zonelist = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , } |
Multi-timezone Localtime code
The original source from this file may be obtained from ftp://elsie.nci.nih.gov/pub/
Definition in file localtime.c.
#define SP_HEAP_INIT | ( | sp | ) |
Definition at line 195 of file localtime.c.
#define SP_STACK_INIT | ( | sp | ) |
Definition at line 191 of file localtime.c.
#define TZDEFRULESTRING ",M4.1.0,M10.5.0" |
Definition at line 128 of file localtime.c.
Referenced by tzparse().
struct ast_tm* ast_localtime | ( | const struct timeval * | timep, |
struct ast_tm * | p_tm, | ||
const char * | zone | ||
) |
Timezone-independent version of localtime_r(3).
timep | Current time, including microseconds |
p_tm | Pointer to memory where the broken-out time will be stored |
zone | Text string of a standard system zoneinfo file. If NULL, the system localtime will be used. |
p_tm | is returned for convenience |
Definition at line 1739 of file localtime.c.
References localsub().
Referenced by action_corestatus(), ast_cel_fabricate_channel_from_event(), ast_check_timing2(), ast_http_send(), ast_json_timeval(), ast_say_date_da(), ast_say_date_de(), ast_say_date_en(), ast_say_date_fr(), ast_say_date_gr(), ast_say_date_he(), ast_say_date_hu(), ast_say_date_ka(), ast_say_date_nl(), ast_say_date_pt(), ast_say_date_th(), ast_say_date_with_format_da(), ast_say_date_with_format_de(), ast_say_date_with_format_en(), ast_say_date_with_format_es(), ast_say_date_with_format_fr(), ast_say_date_with_format_gr(), ast_say_date_with_format_he(), ast_say_date_with_format_it(), ast_say_date_with_format_nl(), ast_say_date_with_format_pl(), ast_say_date_with_format_pt(), ast_say_date_with_format_th(), ast_say_date_with_format_vi(), ast_say_date_with_format_zh(), ast_say_datetime_de(), ast_say_datetime_en(), ast_say_datetime_fr(), ast_say_datetime_from_now_en(), ast_say_datetime_from_now_fr(), ast_say_datetime_from_now_he(), ast_say_datetime_from_now_ka(), ast_say_datetime_from_now_pt(), ast_say_datetime_gr(), ast_say_datetime_he(), ast_say_datetime_hu(), ast_say_datetime_ka(), ast_say_datetime_nl(), ast_say_datetime_pt(), ast_say_datetime_pt_BR(), ast_say_datetime_th(), ast_say_datetime_zh(), ast_say_time_de(), ast_say_time_en(), ast_say_time_fr(), ast_say_time_gr(), ast_say_time_he(), ast_say_time_hu(), ast_say_time_ka(), ast_say_time_nl(), ast_say_time_pt(), ast_say_time_pt_BR(), ast_say_time_th(), ast_say_time_zh(), get_date(), handle_minivm_show_stats(), handle_show_settings(), isodate(), make_email_file(), packdate(), set_timezone_variables(), sms_handleincoming_proto2(), vmu_tm(), and write_metadata().
struct timeval ast_mktime | ( | struct ast_tm *const | tmp, |
const char * | zone | ||
) |
Timezone-independent version of mktime(3).
tmp | Current broken-out time, including microseconds |
zone | Text string of a standard system zoneinfo file. If NULL, the system localtime will be used. |
A | structure containing both seconds and fractional thereof since January 1st, 1970 UTC |
Definition at line 2357 of file localtime.c.
References localsub().
Referenced by sms_handleincoming_proto2(), sms_readfile(), and unpackdate().
int ast_strftime | ( | char * | buf, |
size_t | len, | ||
const char * | format, | ||
const struct ast_tm * | tm | ||
) |
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strftime(3), with the addition of q, which specifies microseconds.
buf | Address in memory where the resulting string will be stored. |
len | Size of the chunk of memory buf. |
format | A string specifying the format of time to be placed into buf. |
tm | Pointer to the broken out time to be used for the format. |
An | integer value specifying the number of bytes placed into buf or -1 on error. |
Definition at line 2524 of file localtime.c.
Referenced by action_corestatus(), ast_cel_fabricate_channel_from_event(), ast_http_send(), ast_json_timeval(), get_date(), handle_minivm_show_stats(), handle_show_settings(), isodate(), make_email_file(), and write_metadata().
char* ast_strptime | ( | const char * | s, |
const char * | format, | ||
struct ast_tm * | tm | ||
) |
Special version of strptime(3) which places the answer in the common structure ast_tm. Also, unlike strptime(3), ast_strptime() initializes its memory prior to use.
s | A string specifying some portion of a date and time. |
format | The format in which the string, s, is expected. |
tm | The broken-out time structure into which the parsed data is expected. |
A | pointer to the first character within s not used to parse the date and time. |
Definition at line 2550 of file localtime.c.
void clean_time_zones | ( | void | ) |
Provided by localtime.c
Definition at line 1590 of file localtime.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, and AST_LIST_UNLOCK.
Referenced by really_quit().
|
static |
Start a notification for every entry already in the list.
Definition at line 328 of file localtime.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, and state::name.
|
static |
Definition at line 822 of file localtime.c.
|
static |
Given a pointer into an extended time zone string, scan until the ending delimiter of the zone name is located. Return a pointer to the delimiter.
As with getzname above, the legal character set is actually quite restricted, with other characters producing undefined results. We don't do any checking here; checking is done later in common-case code.
Definition at line 1137 of file localtime.c.
Referenced by tzparse().
|
static |
Simplified normalize logic courtesy Paul Eggert.
Definition at line 2051 of file localtime.c.
|
static |
The unused offset argument is for the benefit of mktime variants.
Definition at line 1648 of file localtime.c.
References ast_tm::tm_gmtoff, ast_tm::tm_isdst, ast_tm::tm_usec, and ast_tm::tm_year.
Referenced by ast_localtime(), and ast_mktime().
|
static |
Definition at line 2279 of file localtime.c.
|
static |
Definition at line 1385 of file localtime.c.
References getoffset(), getqzname(), getrule(), getzname(), state::name, transtime(), and TZDEFRULESTRING.
|
static |
Definition at line 1103 of file localtime.c.
|
static |
Definition at line 1108 of file localtime.c.