static int write_metadata( FILE *logfile, char *signalling_type, struct ast_channel *chan)
{
int res = 0;
- time_t t;
- struct tm now;
+ struct timeval t;
+ struct ast_tm now;
char *cl,*cn;
char workstring[80];
char timestamp[80];
/* Get the current time */
- time(&t);
+ t = ast_tvnow();
ast_localtime(&t, &now, NULL);
/* Format the time */
- strftime(timestamp, sizeof(timestamp), time_stamp_format, &now);
+ ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now);
res = fprintf(logfile, "\n\n[metadata]\n\n");
int timezones; /*!< Number of time zones */
int templates; /*!< Number of templates */
- time_t reset; /*!< Time for last reset */
+ struct timeval reset; /*!< Time for last reset */
int receivedmessages; /*!< Number of received messages since reset */
- time_t lastreceived; /*!< Time for last voicemail sent */
+ struct timeval lastreceived; /*!< Time for last voicemail sent */
};
/*! \brief Statistics for voicemail */
static int get_date(char *s, int len)
{
- struct tm tm;
- time_t t;
+ struct ast_tm tm;
+ struct timeval tv = ast_tvnow();
- t = time(0);
- ast_localtime(&t, &tm, NULL);
- return strftime(s, len, "%a %b %e %r %Z %Y", &tm);
+ ast_localtime(&tv, &tm, NULL);
+ return ast_strftime(s, len, "%a %b %e %r %Z %Y", &tm);
}
char dur[PATH_MAX];
char tmp[80] = "/tmp/astmail-XXXXXX";
char tmp2[PATH_MAX];
- time_t now;
- struct tm tm;
+ struct timeval now;
+ struct ast_tm tm;
struct minivm_zone *the_zone = NULL;
int len_passdata;
struct ast_channel *ast;
AST_LIST_UNLOCK(&minivm_zones);
}
- time(&now);
+ now = ast_tvnow();
ast_localtime(&now, &tm, the_zone ? the_zone->timezone : NULL);
- strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", &tm);
+ ast_strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", &tm);
/* Start printing the email to the temporary file */
fprintf(p, "Date: %s\n", date);
/* Set date format for voicemail mail */
- strftime(date, sizeof(date), template->dateformat, &tm);
+ ast_strftime(date, sizeof(date), template->dateformat, &tm);
/* Populate channel with channel variables for substitution */
if (!txt) {
ast_log(LOG_WARNING, "Error opening text file for output\n");
} else {
- struct tm tm;
- time_t now;
+ struct ast_tm tm;
+ struct timeval now = ast_tvnow();
char timebuf[30];
char logbuf[BUFSIZ];
get_date(date, sizeof(date));
- now = time(NULL);
ast_localtime(&now, &tm, NULL);
- strftime(timebuf, sizeof(timebuf), "%H:%M:%S", &tm);
+ ast_strftime(timebuf, sizeof(timebuf), "%H:%M:%S", &tm);
snprintf(logbuf, sizeof(logbuf),
/* "Mailbox:domain:macrocontext:exten:priority:callerchan:callerid:origdate:origtime:duration:durationstatus:accountcode" */
pbx_builtin_setvar_helper(chan, "MVM_FORMAT", fmt);
}
- global_stats.lastreceived = time(NULL);
+ global_stats.lastreceived = ast_tvnow();
global_stats.receivedmessages++;
// /* Go ahead and delete audio files from system, they're not needed any more */
// if (ast_fileexists(tmptxtfile, NULL, NULL) <= 0) {
ast_set2_flag((&globalflags), FALSE, MVM_OPERATOR);
strcpy(global_charset, "ISO-8859-1");
/* Reset statistics */
- memset(&global_stats, 0, sizeof(struct minivm_stats));
- global_stats.reset = time(NULL);
+ memset(&global_stats, 0, sizeof(global_stats));
+ global_stats.reset = ast_tvnow();
/* Make sure we could load configuration file */
if (!cfg) {
/*! \brief Show stats */
static int handle_minivm_show_stats(int fd, int argc, char *argv[])
{
- struct tm time;
+ struct ast_tm time;
char buf[BUFSIZ];
ast_cli(fd, "* Mini-Voicemail statistics\n");
} else {
ast_cli(fd, " Received messages since last reset: %d\n", global_stats.receivedmessages);
ast_localtime(&global_stats.lastreceived, &time, NULL);
- strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time);
+ ast_strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time);
ast_cli(fd, " Last received voicemail: %s\n", buf);
}
ast_localtime(&global_stats.reset, &time, NULL);
- strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time);
+ ast_strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time);
ast_cli(fd, " Last reset: %s\n", buf);
ast_cli(fd, "\n");
const char *ints, const char *lang, const char *format, const char *timezone, const char *prefix)
{
char buf[128];
- struct tm tm;
+ struct ast_tm tm;
+ struct timeval tv = { t, 0 };
say_args_t a = { chan, ints, lang, -1, -1 };
if (format == NULL)
format = "";
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
snprintf(buf, sizeof(buf), "%s:%s:%04d%02d%02d%02d%02d.%02d-%d-%3d",
prefix,
format,
int i, j;
long long diff;
char a[100] = "";
+ struct ast_tm tm;
struct timeval lasttv;
ast_mutex_lock(&locklock);
lasttv.tv_sec = lasttv.tv_usec = 0;
for (i = 0; i < 32; i++) {
j = (i + lock_ring_index_copy) % 32;
- strftime(a, sizeof(a) - 1, "%m/%d/%Y %H:%M:%S",
- localtime(&lock_ring_copy[j].tv.tv_sec));
+ ast_strftime(a, sizeof(a) - 1, "%m/%d/%Y %H:%M:%S",
+ ast_localtime(&lock_ring_copy[j].tv, &tm, NULL));
diff = 0;
if (lasttv.tv_sec) {
diff = (lock_ring_copy[j].tv.tv_sec - lasttv.tv_sec) * 1000000;
struct ast_channel *mychannel;
const char *p, *ct;
time_t t;
- struct tm localtm;
+ struct ast_tm localtm;
#ifdef APP_RPT_LOCK_DEBUG
struct lockthread *t;
#endif
static void do_scheduler(struct rpt *myrpt)
{
int res;
- struct tm tmnow;
+ struct ast_tm tmnow;
memcpy(&myrpt->lasttv, &myrpt->curtv, sizeof(struct timeval));
/*! \brief static, return a date/time in ISO format */
static char *isodate(time_t t, char *buf, int len)
{
- struct tm tm;
- ast_localtime(&t, &tm, NULL);
- strftime(buf, len, "%Y-%m-%dT%H:%M:%S", &tm);
+ struct ast_tm tm;
+ struct timeval tv = { t, 0 };
+ ast_localtime(&tv, &tm, NULL);
+ ast_strftime(buf, len, "%Y-%m-%dT%H:%M:%S", &tm);
return buf;
}
/*! \brief pack a date and return */
static void packdate(unsigned char *o, time_t w)
{
- struct tm t;
+ struct ast_tm t;
+ struct timeval tv = { w, 0 };
int z;
- ast_localtime(&w, &t, NULL);
+ ast_localtime(&tv, &t, NULL);
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__)
z = -t.tm_gmtoff / 60 / 15;
#else
static void sms_compose2(sms_t *h, int more)
{
- struct tm tm;
+ struct ast_tm tm;
+ struct timeval tv = { h->scts, 0 };
char stm[9];
h->omsg[0] = 0x00; /* set later... */
if (h->smsc) { /* deliver */
h->omsg[0] = 0x11; /* SMS_DELIVERY */
/* Required: 10 11 12 13 14 15 17 (seems they must be ordered!) */
- ast_localtime(&h->scts, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
sprintf(stm, "%02d%02d%02d%02d", tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min); /* Date mmddHHMM */
adddata_proto2(h, 0x14, stm, 8); /* Date */
if (*h->oa == 0)
{
int f, i, sz = 0;
int msg, msgsz;
- struct tm tm;
+ struct ast_tm tm;
+ struct timeval tv = { 0, 0 };
char debug_buf[MAX_DEBUG_LEN * 3 + 1];
sz = h->imsg[1] + 2;
/* ast_verbose(VERBOSE_PREFIX_3 "SMS-P2 Frame: %s\n", sms_hexdump(h->imsg, sz, debug_buf)); */
/* Parse message body (called payload) */
- h->scts = time(NULL);
+ tv.tv_sec = h->scts = time(NULL);
for (f = 4; f < sz; ) {
msg = h->imsg[f++];
msgsz = h->imsg[f++];
h->udl = msgsz;
break;
case 0x14: /* Date SCTS */
- h->scts = time(NULL);
- ast_localtime(&h->scts, &tm, NULL);
+ tv.tv_sec = h->scts = time(NULL);
+ ast_localtime(&tv, &tm, NULL);
tm.tm_mon = ( (h->imsg[f] * 10) + h->imsg[f + 1] ) - 1;
tm.tm_mday = ( (h->imsg[f + 2] * 10) + h->imsg[f + 3] );
tm.tm_hour = ( (h->imsg[f + 4] * 10) + h->imsg[f + 5] );
tm.tm_min = ( (h->imsg[f + 6] * 10) + h->imsg[f + 7] );
tm.tm_sec = 0;
- h->scts = mktime(&tm);
+ h->scts = ast_mktime(&tm, NULL);
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "SMS-P2 Date#%02X=%02d/%02d %02d:%02d\n", msg, tm.tm_mday, tm.tm_mon + 1, tm.tm_hour, tm.tm_min);
break;
* fill in *tm for current time according to the proper timezone, if any.
* Return tm so it can be used as a function argument.
*/
-static const struct tm *vmu_tm(const struct ast_vm_user *vmu, struct tm *tm)
+static const struct ast_tm *vmu_tm(const struct ast_vm_user *vmu, struct ast_tm *tm)
{
const struct vm_zone *z = NULL;
- time_t t = time(NULL);
+ struct timeval t = ast_tvnow();
/* Does this user have a timezone specified? */
if (!ast_strlen_zero(vmu->zonetag)) {
char fname[256];
char dur[256];
char tmpcmd[256];
- struct tm tm;
+ struct ast_tm tm;
char *passdata2;
size_t len_passdata;
char *greeting_attachment;
*greeting_attachment++ = '\0';
snprintf(dur, sizeof(dur), "%d:%02d", duration / 60, duration % 60);
- strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", vmu_tm(vmu, &tm));
+ ast_strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", vmu_tm(vmu, &tm));
fprintf(p, "Date: %s" ENDL, date);
/* Set date format for voicemail mail */
- strftime(date, sizeof(date), emaildateformat, &tm);
+ ast_strftime(date, sizeof(date), emaildateformat, &tm);
if (!ast_strlen_zero(fromstring)) {
struct ast_channel *ast;
char dur[PATH_MAX];
char tmp[80] = "/tmp/astmail-XXXXXX";
char tmp2[PATH_MAX];
- struct tm tm;
+ struct ast_tm tm;
FILE *p;
if ((p = vm_mkftemp(tmp)) == NULL) {
else
snprintf(who, sizeof(who), "%s@%s", srcemail, host);
snprintf(dur, sizeof(dur), "%d:%02d", duration / 60, duration % 60);
- strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", vmu_tm(vmu, &tm));
+ ast_strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", vmu_tm(vmu, &tm));
fprintf(p, "Date: %s\n", date);
if (*pagerfromstring) {
} else
fprintf(p, "Subject: New VM\n\n");
- strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm);
+ ast_strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm);
if (pagerbody) {
struct ast_channel *ast;
if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, 0))) {
static int get_date(char *s, int len)
{
- struct tm tm;
- time_t t;
- t = time(0);
+ struct ast_tm tm;
+ struct timeval t = ast_tvnow();
ast_localtime(&t, &tm, NULL);
- return strftime(s, len, "%a %b %e %r %Z %Y", &tm);
+ return ast_strftime(s, len, "%a %b %e %r %Z %Y", &tm);
}
static int invent_message(struct ast_channel *chan, char *context, char *ext, int busy, char *ecodes)
/* Set the DIFF_* variables */
ast_localtime(&t, &time_now, NULL);
tv_now = ast_tvnow();
- tnow = tv_now.tv_sec;
- ast_localtime(&tnow, &time_then, NULL);
+ ast_localtime(&tv_now, &time_then, NULL);
/* Day difference */
if (time_now.tm_year == time_then.tm_year)
static int append_date(char *buf, struct timeval tv, size_t bufsize)
{
char tmp[80] = "";
- struct tm tm;
- time_t t;
- t = tv.tv_sec;
+ struct ast_tm tm;
if (strlen(buf) > bufsize - 3)
return -1;
if (ast_tvzero(tv)) {
strncat(buf, ",", bufsize - strlen(buf) - 1);
return 0;
}
- if (usegmtime) {
- gmtime_r(&t,&tm);
- } else {
- ast_localtime(&t, &tm, NULL);
- }
- strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
+ ast_localtime(&tv, &tm, usegmtime ? "GMT" : NULL);
+ ast_strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
return append_string(buf, tmp, bufsize);
}
static int manager_log(struct ast_cdr *cdr)
{
- time_t t;
- struct tm timeresult;
+ struct ast_tm timeresult;
char strStartTime[80] = "";
char strAnswerTime[80] = "";
char strEndTime[80] = "";
if (!enablecdr)
return 0;
- t = cdr->start.tv_sec;
- ast_localtime(&t, &timeresult, NULL);
- strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
+ ast_localtime(&cdr->start, &timeresult, NULL);
+ ast_strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
if (cdr->answer.tv_sec) {
- t = cdr->answer.tv_sec;
- ast_localtime(&t, &timeresult, NULL);
- strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
+ ast_localtime(&cdr->answer, &timeresult, NULL);
+ ast_strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
}
- t = cdr->end.tv_sec;
- ast_localtime(&t, &timeresult, NULL);
- strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
+ ast_localtime(&cdr->end, &timeresult, NULL);
+ ast_strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
/* Custom fields handling */
memset(buf, 0 , sizeof(buf));
int ODBC_res;
char sqlcmd[2048] = "", timestr[128];
int res = 0;
- struct tm tm;
+ struct ast_tm tm;
- if (usegmtime)
- gmtime_r(&cdr->start.tv_sec,&tm);
- else
- ast_localtime(&cdr->start.tv_sec, &tm, NULL);
+ ast_localtime(&cdr->start, &tm, usegmtime ? "GMT" : NULL);
ast_mutex_lock(&odbc_lock);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+ ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
memset(sqlcmd,0,2048);
if (loguniqueid) {
snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s "
static int pgsql_log(struct ast_cdr *cdr)
{
- struct tm tm;
+ struct ast_tm tm;
char sqlcmd[2048] = "", timestr[128];
char *pgerror;
PGresult *result;
ast_mutex_lock(&pgsql_lock);
- ast_localtime(&cdr->start.tv_sec, &tm, NULL);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+ ast_localtime(&cdr->start, &tm, NULL);
+ ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) {
conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
static int build_radius_record(VALUE_PAIR **send, struct ast_cdr *cdr)
{
int recordtype = PW_STATUS_STOP;
- struct tm tm;
+ struct ast_tm tm;
char timestr[128];
char *tmp;
/* Start Time */
- if (ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME))
- gmtime_r(&(cdr->start.tv_sec), &tm);
- else
- ast_localtime(&(cdr->start.tv_sec), &tm, NULL);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+ ast_strftime(timestr, sizeof(timestr), DATE_FORMAT,
+ ast_localtime(&cdr->start, &tm,
+ ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL));
if (!rc_avpair_add(rh, send, PW_AST_START_TIME, timestr, strlen(timestr), VENDOR_CODE))
return -1;
/* Answer Time */
- if (ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME))
- gmtime_r(&(cdr->answer.tv_sec), &tm);
- else
- ast_localtime(&(cdr->answer.tv_sec), &tm, NULL);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+ ast_strftime(timestr, sizeof(timestr), DATE_FORMAT,
+ ast_localtime(&cdr->answer, &tm,
+ ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL));
if (!rc_avpair_add(rh, send, PW_AST_ANSWER_TIME, timestr, strlen(timestr), VENDOR_CODE))
return -1;
/* End Time */
- if (ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME))
- gmtime_r(&(cdr->end.tv_sec), &tm);
- else
- ast_localtime(&(cdr->end.tv_sec), &tm, NULL);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+ ast_strftime(timestr, sizeof(timestr), DATE_FORMAT,
+ ast_localtime(&cdr->end, &tm,
+ ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL));
if (!rc_avpair_add(rh, send, PW_AST_END_TIME, timestr, strlen(timestr), VENDOR_CODE))
return -1;
{
int res = 0;
char *zErr = 0;
- struct tm tm;
- time_t t;
+ struct ast_tm tm;
char startstr[80], answerstr[80], endstr[80];
int count;
ast_mutex_lock(&sqlite_lock);
- t = cdr->start.tv_sec;
- ast_localtime(&t, &tm, NULL);
- strftime(startstr, sizeof(startstr), DATE_FORMAT, &tm);
+ ast_localtime(&cdr->start, &tm, NULL);
+ ast_strftime(startstr, sizeof(startstr), DATE_FORMAT, &tm);
- t = cdr->answer.tv_sec;
- ast_localtime(&t, &tm, NULL);
- strftime(answerstr, sizeof(answerstr), DATE_FORMAT, &tm);
+ ast_localtime(&cdr->answer, &tm, NULL);
+ ast_strftime(answerstr, sizeof(answerstr), DATE_FORMAT, &tm);
- t = cdr->end.tv_sec;
- ast_localtime(&t, &tm, NULL);
- strftime(endstr, sizeof(endstr), DATE_FORMAT, &tm);
+ ast_localtime(&cdr->end, &tm, NULL);
+ ast_strftime(endstr, sizeof(endstr), DATE_FORMAT, &tm);
for(count=0; count<5; count++) {
res = sqlite_exec_printf(db,
static void get_date(char *dateField, struct timeval tv)
{
- struct tm tm;
- time_t t;
+ struct ast_tm tm;
char buf[80];
/* To make sure we have date variable if not insert null to SQL */
if (!ast_tvzero(tv))
{
- t = tv.tv_sec;
- ast_localtime(&t, &tm, NULL);
- strftime(buf, 80, DATE_FORMAT, &tm);
+ ast_localtime(&tv, &tm, NULL);
+ ast_strftime(buf, 80, DATE_FORMAT, &tm);
sprintf(dateField, "'%s'", buf);
}
else
login_state = 1; /* Successful Login */
/* Ensure we can't be gotten until we're done */
- gettimeofday(&p->lastdisc, NULL);
+ p->lastdisc = ast_tvnow();
p->lastdisc.tv_sec++;
/* Set Channel Specific Agent Overrides */
{
int x;
int res= 0;
- struct timeval now;
+ struct timeval now = ast_tvnow();
if (iaxs[callno]->oseqno) {
ast_log(LOG_WARNING, "Can't make trunk once a call has started!\n");
return -1;
ast_log(LOG_WARNING, "Call %d is already a trunk\n", callno);
return -1;
}
- gettimeofday(&now, NULL);
for (x=TRUNK_CALL_START;x<IAX_MAX_CALLS - 1; x++) {
ast_mutex_lock(&iaxsl[x]);
if (!iaxs[x] && ((now.tv_sec - lastused[x].tv_sec) > MIN_REUSE_TIME)) {
* correct, but it will be changed if needed after authentication. */
if (!iax2_getpeername(*sin, host, sizeof(host), lockpeer))
snprintf(host, sizeof(host), "%s:%d", ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
- gettimeofday(&now, NULL);
+ now = ast_tvnow();
for (x=1;x<TRUNK_CALL_START;x++) {
/* Find first unused call number that hasn't been used in a while */
ast_mutex_lock(&iaxsl[x]);
retry:
pvt = iaxs[callno];
- gettimeofday(&lastused[callno], NULL);
+ lastused[callno] = ast_tvnow();
owner = pvt ? pvt->owner : NULL;
struct iax2_dpcache *dp = NULL;
char tmp[1024], *pc = NULL;
int s, x, y;
- struct timeval tv;
-
- gettimeofday(&tv, NULL);
+ struct timeval tv = ast_tvnow();
AST_LIST_LOCK(&dpcache);
int ret;
long now;
long next;
- struct timeval tv;
+ struct timeval tv = ast_tvnow();
/* Make sure we have a valid private structure before going on */
ast_mutex_lock(&iaxsl[callno]);
pvt->jbid = -1;
- gettimeofday(&tv,NULL);
/* round up a millisecond since ast_sched_runq does; */
/* prevents us from spinning while waiting for our now */
/* to catch up with runq's now */
static unsigned int iax2_datetime(const char *tz)
{
- time_t t;
- struct tm tm;
+ struct timeval t = ast_tvnow();
+ struct ast_tm tm;
unsigned int tmp;
- time(&t);
- if (!ast_strlen_zero(tz))
- ast_localtime(&t, &tm, tz);
- else
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&t, &tm, ast_strlen_zero(tz) ? NULL : tz);
tmp = (tm.tm_sec >> 1) & 0x1f; /* 5 bits of seconds */
tmp |= (tm.tm_min & 0x3f) << 5; /* 6 bits of minutes */
tmp |= (tm.tm_hour & 0x1f) << 11; /* 5 bits of hours */
}
if ((iaxs[callno0]->transferring == TRANSFER_RELEASED) && (iaxs[callno1]->transferring == TRANSFER_RELEASED)) {
/* Call has been transferred. We're no longer involved */
- gettimeofday(&tv, NULL);
+ tv = ast_tvnow();
if (ast_tvzero(waittimer)) {
waittimer = tv;
} else if (tv.tv_sec - waittimer.tv_sec > IAX_LINGER_TIMEOUT) {
long ms; /* NOT unsigned */
if (ast_tvzero(iaxs[callno]->rxcore)) {
/* Initialize rxcore time if appropriate */
- gettimeofday(&iaxs[callno]->rxcore, NULL);
+ iaxs[callno]->rxcore = ast_tvnow();
/* Round to nearest 20ms so traces look pretty */
iaxs[callno]->rxcore.tv_usec -= iaxs[callno]->rxcore.tv_usec % 20000;
}
}
}
if (ast_tvzero(p->offset)) {
- gettimeofday(&p->offset, NULL);
+ p->offset = ast_tvnow();
/* Round to nearest 20ms for nice looking traces */
p->offset.tv_usec -= p->offset.tv_usec % 20000;
}
/* if we have enough for a full MTU, ship it now without waiting */
if (global_max_trunk_mtu > 0 && tpeer->trunkdatalen + f->datalen + 4 >= global_max_trunk_mtu) {
- gettimeofday(&now, NULL);
+ now = ast_tvnow();
res = send_trunk(tpeer, &now);
trunk_untimed ++;
}
#ifdef ZT_TIMERACK
int x = 1;
#endif
- struct timeval now;
+ struct timeval now = ast_tvnow();
if (iaxtrunkdebug)
ast_verbose("Beginning trunk processing. Trunk queue ceiling is %d bytes per host\n", trunkmaxsize);
- gettimeofday(&now, NULL);
if (events & AST_IO_PRI) {
#ifdef ZT_TIMERACK
/* Great, this is a timing interface, just call the ioctl */
static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *data, const char *context, const char *exten, int priority)
{
struct iax2_dpcache *dp = NULL;
- struct timeval tv;
+ struct timeval tv = ast_tvnow();
int x, com[2], timeout, old = 0, outfd, abort, callno;
struct ast_channel *c = NULL;
struct ast_frame *f = NULL;
- gettimeofday(&tv, NULL);
-
AST_LIST_TRAVERSE_SAFE_BEGIN(&dpcache, dp, cache_list) {
if (ast_tvcmp(tv, dp->expiry) > 0) {
AST_LIST_REMOVE_CURRENT(&dpcache, cache_list);
}
ast_copy_string(dp->peercontext, data, sizeof(dp->peercontext));
ast_copy_string(dp->exten, exten, sizeof(dp->exten));
- gettimeofday(&dp->expiry, NULL);
+ dp->expiry = ast_tvnow();
dp->orig = dp->expiry;
/* Expires in 30 mins by default */
dp->expiry.tv_sec += iaxdefaultdpcache;
gw->msgs = msg;
}
- if (gettimeofday(&tv, NULL) < 0) {
- /* This shouldn't ever happen, but let's be sure */
- ast_log(LOG_NOTICE, "gettimeofday() failed!\n");
- } else {
- msg->expire = tv.tv_sec * 1000 + tv.tv_usec / 1000 + DEFAULT_RETRANS;
+ tv = ast_tvnow();
+ msg->expire = tv.tv_sec * 1000 + tv.tv_usec / 1000 + DEFAULT_RETRANS;
- if (gw->retransid == -1)
- gw->retransid = ast_sched_add(sched, DEFAULT_RETRANS, retrans_pkt, (void *)gw);
- }
+ if (gw->retransid == -1)
+ gw->retransid = ast_sched_add(sched, DEFAULT_RETRANS, retrans_pkt, (void *)gw);
ast_mutex_unlock(&gw->msgs_lock);
/* SC
if (!gw->messagepending) {
struct mgcp_request resp;
char tone2[256];
char *l, *n;
- time_t t;
- struct tm tm;
+ struct timeval t = ast_tvnow();
+ struct ast_tm tm;
struct mgcp_endpoint *p = sub->parent;
- time(&t);
ast_localtime(&t, &tm, NULL);
n = callername;
l = callernum;
struct phone_pvt *p;
PHONE_CID cid;
- time_t UtcTime;
- struct tm tm;
+ struct timeval UtcTime = ast_tvnow();
+ struct ast_tm tm;
int start;
- time(&UtcTime);
ast_localtime(&UtcTime, &tm, NULL);
memset(&cid, 0, sizeof(PHONE_CID));
int refresh; /*!< How often to refresh */
struct sip_pvt *call; /*!< create a sip_pvt structure for each outbound "registration dialog" in progress */
enum sipregistrystate regstate; /*!< Registration state (see above) */
- time_t regtime; /*!< Last successful registration time */
+ struct timeval regtime; /*!< Last successful registration time */
int callid_valid; /*!< 0 means we haven't chosen callid for this registry yet. */
unsigned int ocseq; /*!< Sequence number we got to for REGISTERs for this registry */
struct sockaddr_in us; /*!< Who the server thinks we are */
#define FORMAT "%-30.30s %-12.12s %8d %-20.20s %-25.25s\n"
char host[80];
char tmpdat[256];
- struct tm tm;
+ struct ast_tm tm;
int counter = 0;
if (argc != 3)
ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do {
ASTOBJ_RDLOCK(iterator);
snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT);
- if (iterator->regtime) {
+ if (iterator->regtime.tv_sec) {
ast_localtime(&iterator->regtime, &tm, NULL);
- strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm);
+ ast_strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm);
} else
tmpdat[0] = '\0';
ast_cli(fd, FORMAT, host, iterator->username, iterator->refresh, regstate2str(iterator->regstate), tmpdat);
}
r->regstate = REG_STATE_REGISTERED;
- r->regtime = time(NULL); /* Reset time of last succesful registration */
+ r->regtime = ast_tvnow(); /* Reset time of last succesful registration */
manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nDomain: %s\r\nStatus: %s\r\n", r->hostname, regstate2str(r->regstate));
r->regattempts = 0;
ast_debug(1, "Registration successful\n");
#else
xmitres = transmit_invite(p, SIP_OPTIONS, 0, 2);
#endif
- gettimeofday(&peer->ps, NULL);
+ peer->ps = ast_tvnow();
if (xmitres == XMIT_ERROR)
sip_poke_noanswer(peer); /* Immediately unreachable, network problems */
else
static int handle_time_date_req_message(struct skinny_req *req, struct skinnysession *s)
{
- time_t timer;
- struct tm *cmtime;
+ struct timeval tv = ast_tvnow();
+ struct ast_tm cmtime;
if (!(req = req_alloc(sizeof(struct definetimedate_message), DEFINETIMEDATE_MESSAGE)))
return -1;
- timer = time(NULL);
- cmtime = localtime(&timer);
- req->data.definetimedate.year = htolel(cmtime->tm_year+1900);
- req->data.definetimedate.month = htolel(cmtime->tm_mon+1);
- req->data.definetimedate.dayofweek = htolel(cmtime->tm_wday);
- req->data.definetimedate.day = htolel(cmtime->tm_mday);
- req->data.definetimedate.hour = htolel(cmtime->tm_hour);
- req->data.definetimedate.minute = htolel(cmtime->tm_min);
- req->data.definetimedate.seconds = htolel(cmtime->tm_sec);
+ ast_localtime(&tv, &cmtime, NULL);
+ req->data.definetimedate.year = htolel(cmtime.tm_year+1900);
+ req->data.definetimedate.month = htolel(cmtime.tm_mon+1);
+ req->data.definetimedate.dayofweek = htolel(cmtime.tm_wday);
+ req->data.definetimedate.day = htolel(cmtime.tm_mday);
+ req->data.definetimedate.hour = htolel(cmtime.tm_hour);
+ req->data.definetimedate.minute = htolel(cmtime.tm_min);
+ req->data.definetimedate.seconds = htolel(cmtime.tm_sec);
+ req->data.definetimedate.milliseconds = htolel(cmtime.tm_usec / 1000);
transmit_response(s, req);
return 1;
}
/* Pick up the line */
ast_debug(1, "Took %s off hook\n", ast->name);
if (p->hanguponpolarityswitch) {
- gettimeofday(&p->polaritydelaytv, NULL);
+ p->polaritydelaytv = ast_tvnow();
}
res = zt_set_hook(p->subs[SUB_REAL].zfd, ZT_OFFHOOK);
tone_zone_play_tone(p->subs[index].zfd, -1);
break;
}
/* Remember last time we got a flash-hook */
- gettimeofday(&p->flashtime, NULL);
+ p->flashtime = ast_tvnow();
switch (mysig) {
case SIG_FXOLS:
case SIG_FXOGS:
ast_debug(1, "Answering on polarity switch!\n");
ast_setstate(p->owner, AST_STATE_UP);
if (p->hanguponpolarityswitch) {
- gettimeofday(&p->polaritydelaytv, NULL);
+ p->polaritydelaytv = ast_tvnow();
}
} else
ast_debug(1, "Ignore switch to REVERSED Polarity on channel %d, state %d\n", p->channel, ast->_state);
/* Do nothing */
break;
case ZT_EVENT_WINKFLASH:
- gettimeofday(&p->flashtime, NULL);
+ p->flashtime = ast_tvnow();
if (p->owner) {
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Channel %d flashed to other channel %s\n", p->channel, p->owner->name);
while(1) {
ast_mutex_lock(&linkset->lock);
if ((next = ss7_schedule_next(ss7))) {
- gettimeofday(&tv, NULL);
+ tv = ast_tvnow();
tv.tv_sec = next->tv_sec - tv.tv_sec;
tv.tv_usec = next->tv_usec - tv.tv_usec;
if (tv.tv_usec < 0) {
int nextidle = -1;
struct ast_channel *c;
struct timeval tv, lowest, *next;
- struct timeval lastidle = { 0, 0 };
+ struct timeval lastidle = ast_tvnow();
int doidling=0;
char *cc;
char idlen[80];
char plancallingani[256];
char calledtonstr[10];
- gettimeofday(&lastidle, NULL);
if (!ast_strlen_zero(pri->idledial) && !ast_strlen_zero(pri->idleext)) {
/* Need to do idle dialing, check to be sure though */
cc = strchr(pri->idleext, '@');
}
} else
ast_log(LOG_WARNING, "Unable to request channel 'Zap/%s' for idle call\n", idlen);
- gettimeofday(&lastidle, NULL);
+ lastidle = ast_tvnow();
}
} else if ((haveidles < pri->minunused) &&
(activeidles > pri->minidle)) {
static void dump_datetime(char *output, int maxlen, void *value, int len)
{
- struct tm tm;
+ struct ast_tm tm;
unsigned long val = (unsigned long) ntohl(get_unaligned_uint32(value));
if (len == (int)sizeof(unsigned int)) {
tm.tm_sec = (val & 0x1f) << 1;
tm.tm_mday = (val >> 16) & 0x1f;
tm.tm_mon = ((val >> 21) & 0x0f) - 1;
tm.tm_year = ((val >> 25) & 0x7f) + 100;
- strftime(output, maxlen, "%Y-%m-%d %T", &tm);
+ ast_strftime(output, maxlen, "%Y-%m-%d %T", &tm);
} else
ast_copy_string(output, "Invalid DATETIME format!", maxlen);
}
unsigned char *p;
Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
int l;
+ struct timeval tv = { ti, 0 };
+ struct ast_tm tm;
- struct tm *tm;
-
- tm = localtime(&ti);
- if (!tm)
- {
- printf("%s: ERROR: gettimeofday() returned NULL.\n", __FUNCTION__);
- return;
- }
-
- if (MISDN_IE_DEBG) printf(" year=%d month=%d day=%d hour=%d minute=%d\n", tm->tm_year%100, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min);
+ ast_localtime(&tv, &tm, NULL);
+ if (MISDN_IE_DEBG) printf(" year=%d month=%d day=%d hour=%d minute=%d\n", tm.tm_year%100, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min);
l = 5;
p = msg_put(msg, l+2);
qi->QI_ELEMENT(date) = p - (unsigned char *)qi - sizeof(Q931_info_t);
p[0] = IE_DATE;
p[1] = l;
- p[2] = tm->tm_year % 100;
- p[3] = tm->tm_mon + 1;
- p[4] = tm->tm_mday;
- p[5] = tm->tm_hour;
- p[6] = tm->tm_min;
+ p[2] = tm.tm_year % 100;
+ p[3] = tm.tm_mon + 1;
+ p[4] = tm.tm_mday;
+ p[5] = tm.tm_hour;
+ p[6] = tm.tm_min;
}
AST_APP_ARG(timezone);
AST_APP_ARG(format);
);
- time_t epochi;
- struct tm tm;
+ struct timeval tv;
+ struct ast_tm tm;
buf[0] = '\0';
AST_STANDARD_APP_ARGS(args, parse);
- ast_get_time_t(args.epoch, &epochi, time(NULL), NULL);
- ast_localtime(&epochi, &tm, args.timezone);
+ ast_get_timeval(args.epoch, &tv, ast_tvnow(), NULL);
+ ast_localtime(&tv, &tm, args.timezone);
if (!args.format)
args.format = "%c";
- if (!strftime(buf, len, args.format, &tm))
+ if (ast_strftime(buf, len, args.format, &tm) <= 0)
ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n");
buf[len - 1] = '\0';
.name = "STRFTIME",
.synopsis = "Returns the current date/time in a specified format.",
.syntax = "STRFTIME([<epoch>][|[timezone][|format]])",
+ .desc =
+"STRFTIME sports all of the same formats as the underlying C function\n"
+"strftime(3) - see the man page for details. It also supports the\n"
+"following format:\n"
+" %[n]q - fractions of a second, with leading zeroes. For example, %3q will\n"
+" give milliseconds and %1q will give tenths of a second. The default\n"
+" is to output milliseconds (n=3). The common case is to use it in\n"
+" combination with %S, as in \"%S.%3q\".\n",
.read = acf_strftime,
};
AST_APP_ARG(timezone);
AST_APP_ARG(format);
);
- struct tm time;
-
- memset(&time, 0, sizeof(struct tm));
+ union {
+ struct ast_tm atm;
+ struct tm time;
+ } t = { { 0, }, };
buf[0] = '\0';
return -1;
}
- if (!strptime(args.timestring, args.format, &time)) {
+ if (!strptime(args.timestring, args.format, &t.time)) {
ast_log(LOG_WARNING, "C function strptime() output nothing?!!\n");
} else {
- snprintf(buf, len, "%d", (int) ast_mktime(&time, args.timezone));
+ snprintf(buf, len, "%d", (int) ast_mktime(&t.atm, args.timezone));
}
return 0;
{
int x;
char timestr[64];
- struct tm myt;
+ struct ast_tm myt;
if (!chan)
return -1;
ast_channel_setwhentohangup(chan, x);
if (option_verbose > 2) {
if (chan->whentohangup) {
- strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S UTC",
- gmtime_r(&chan->whentohangup, &myt));
+ struct timeval tv = { chan->whentohangup, 0 };
+ ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S.%3q %Z",
+ ast_localtime(&tv, &myt, NULL));
ast_verbose(VERBOSE_PREFIX_3 "Channel will hangup at %s.\n",
timestr);
} else {
#ifndef _ASTERISK_LOCALTIME_H
#define _ASTERISK_LOCALTIME_H
+struct ast_tm {
+ int tm_sec; /* Seconds. [0-60] (1 leap second) */
+ int tm_min; /* Minutes. [0-59] */
+ int tm_hour; /* Hours. [0-23] */
+ int tm_mday; /* Day. [1-31] */
+ int tm_mon; /* Month. [0-11] */
+ int tm_year; /* Year - 1900. */
+ int tm_wday; /* Day of week. [0-6] */
+ int tm_yday; /* Days in year.[0-365] */
+ int tm_isdst; /* DST. [-1/0/1]*/
+ long int tm_gmtoff; /* Seconds east of UTC. */
+ char *tm_zone; /* Timezone abbreviation. */
+ /* NOTE: do NOT reorder this final item. The order needs to remain compatible with struct tm */
+ int tm_usec; /* microseconds */
+};
+
int ast_tzsetwall(void);
void ast_tzset(const char *name);
-struct tm *ast_localtime(const time_t *timep, struct tm *p_tm, const char *zone);
-time_t ast_mktime(struct tm * const tmp, const char *zone);
-char *ast_ctime(const time_t * const timep);
-char *ast_ctime_r(const time_t * const timep, char *buf);
+struct ast_tm *ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone);
+time_t ast_mktime(struct ast_tm * const tmp, const char *zone);
+char *ast_ctime(const struct timeval * const timep, char *buf);
+int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm);
#endif /* _ASTERISK_LOCALTIME_H */
#endif
extern char defaultlanguage[];
-extern time_t ast_startuptime;
-extern time_t ast_lastreloadtime;
+extern struct timeval ast_startuptime;
+extern struct timeval ast_lastreloadtime;
extern pid_t ast_mainpid;
extern char record_cache_dir[AST_CACHE_DIR_LEN];
*/
int ast_get_time_t(const char *src, time_t *dst, time_t _default, int *consumed);
+/*
+ \brief Parse a time (float) string.
+ \param src String to parse
+ \param dst Destination
+ \param _default Value to use if the string does not contain a valid time
+ \param consumed The number of characters 'consumed' in the string by the parse (see 'man sscanf' for details)
+ \return zero on success, non-zero on failure
+*/
+int ast_get_timeval(const char *src, struct timeval *tv, struct timeval _default, int *consumed);
+
/*!
* Support for dynamic strings.
*
static AST_RWLIST_HEAD_STATIC(atexits, ast_atexit);
-time_t ast_startuptime;
-time_t ast_lastreloadtime;
+struct timeval ast_startuptime;
+struct timeval ast_lastreloadtime;
static History *el_hist;
static EditLine *el;
static int handle_show_settings(int fd, int argc, char *argv[])
{
char buf[BUFSIZ];
- struct tm tm;
+ struct ast_tm tm;
ast_cli(fd, "\nPBX Core settings\n");
ast_cli(fd, "-----------------\n");
ast_cli(fd, " Min Free Memory: %ld MB\n", option_minmemfree);
#endif
if (ast_localtime(&ast_startuptime, &tm, NULL)) {
- strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
+ ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
ast_cli(fd, " Startup time: %s\n", buf);
}
if (ast_localtime(&ast_lastreloadtime, &tm, NULL)) {
- strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
+ ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
ast_cli(fd, " Last reload time: %s\n", buf);
}
ast_cli(fd, " System: %s/%s built by %s on %s %s\n", ast_build_os, ast_build_kernel, ast_build_user, ast_build_machine, ast_build_date);
if (*t == '%') {
char hostname[MAXHOSTNAMELEN]="";
int i;
- time_t ts;
- struct tm tm;
+ struct timeval ts = ast_tvnow();
+ struct ast_tm tm = { 0, };
#ifdef linux
FILE *LOADAVG;
#endif
color_used = ((fgcolor == COLOR_WHITE) && (bgcolor == COLOR_BLACK)) ? 0 : 1;
break;
case 'd': /* date */
- memset(&tm, 0, sizeof(tm));
- time(&ts);
if (ast_localtime(&ts, &tm, NULL))
- strftime(p, sizeof(prompt) - strlen(prompt), "%Y-%m-%d", &tm);
+ ast_strftime(p, sizeof(prompt) - strlen(prompt), "%Y-%m-%d", &tm);
break;
case 'h': /* hostname */
if (!gethostname(hostname, sizeof(hostname) - 1))
strncat(p, ast_config_AST_SYSTEM_NAME, sizeof(prompt) - strlen(prompt) - 1);
break;
case 't': /* time */
- memset(&tm, 0, sizeof(tm));
- time(&ts);
if (ast_localtime(&ts, &tm, NULL))
- strftime(p, sizeof(prompt) - strlen(prompt), "%H:%M:%S", &tm);
+ ast_strftime(p, sizeof(prompt) - strlen(prompt), "%H:%M:%S", &tm);
break;
case '#': /* process console or remote? */
if (!ast_opt_remote)
__ast_mm_init();
#endif
- time(&ast_startuptime);
+ ast_startuptime = ast_tvnow();
ast_cli_register_multiple(cli_asterisk, sizeof(cli_asterisk) / sizeof(struct ast_cli_entry));
if (ast_opt_console) {
static int callerid_genmsg(char *msg, int size, const char *number, const char *name, int flags)
{
- time_t t;
- struct tm tm;
+ struct timeval tv = ast_tvnow();
+ struct ast_tm tm;
char *ptr;
int res;
int i, x;
/* Get the time */
- time(&t);
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
ptr = msg;
if (fmt == NULL) { /* raw mode */
snprintf(buf, bufsize, "%ld.%06ld", (long)tv.tv_sec, (long)tv.tv_usec);
} else {
- time_t t = tv.tv_sec;
- if (t) {
- struct tm tm;
+ struct ast_tm tm;
- ast_localtime(&t, &tm, NULL);
- strftime(buf, bufsize, fmt, &tm);
- }
+ ast_localtime(&tv, &tm, NULL);
+ ast_strftime(buf, bufsize, fmt, &tm);
}
}
return 0;
}
-static void print_uptimestr(int fd, time_t timeval, const char *prefix, int printsec)
+static void print_uptimestr(int fd, struct timeval timeval, const char *prefix, int printsec)
{
int x; /* the main part - years, weeks, etc. */
struct ast_str *out;
#define WEEK (DAY*7)
#define YEAR (DAY*365)
#define NEEDCOMMA(x) ((x)? ",": "") /* define if we need a comma */
- if (timeval < 0) /* invalid, nothing to show */
+ if (timeval.tv_sec < 0) /* invalid, nothing to show */
return;
if (printsec) { /* plain seconds output */
- ast_cli(fd, "%s: %lu\n", prefix, (u_long)timeval);
+ ast_cli(fd, "%s: %lu\n", prefix, (u_long)timeval.tv_sec);
return;
}
out = ast_str_alloca(256);
- if (timeval > YEAR) {
- x = (timeval / YEAR);
- timeval -= (x * YEAR);
- ast_str_append(&out, 0, "%d year%s%s ", x, ESS(x),NEEDCOMMA(timeval));
- }
- if (timeval > WEEK) {
- x = (timeval / WEEK);
- timeval -= (x * WEEK);
- ast_str_append(&out, 0, "%d week%s%s ", x, ESS(x),NEEDCOMMA(timeval));
- }
- if (timeval > DAY) {
- x = (timeval / DAY);
- timeval -= (x * DAY);
- ast_str_append(&out, 0, "%d day%s%s ", x, ESS(x),NEEDCOMMA(timeval));
- }
- if (timeval > HOUR) {
- x = (timeval / HOUR);
- timeval -= (x * HOUR);
- ast_str_append(&out, 0, "%d hour%s%s ", x, ESS(x),NEEDCOMMA(timeval));
- }
- if (timeval > MINUTE) {
- x = (timeval / MINUTE);
- timeval -= (x * MINUTE);
- ast_str_append(&out, 0, "%d minute%s%s ", x, ESS(x),NEEDCOMMA(timeval));
- }
- x = timeval;
+ if (timeval.tv_sec > YEAR) {
+ x = (timeval.tv_sec / YEAR);
+ timeval.tv_sec -= (x * YEAR);
+ ast_str_append(&out, 0, "%d year%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec));
+ }
+ if (timeval.tv_sec > WEEK) {
+ x = (timeval.tv_sec / WEEK);
+ timeval.tv_sec -= (x * WEEK);
+ ast_str_append(&out, 0, "%d week%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec));
+ }
+ if (timeval.tv_sec > DAY) {
+ x = (timeval.tv_sec / DAY);
+ timeval.tv_sec -= (x * DAY);
+ ast_str_append(&out, 0, "%d day%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec));
+ }
+ if (timeval.tv_sec > HOUR) {
+ x = (timeval.tv_sec / HOUR);
+ timeval.tv_sec -= (x * HOUR);
+ ast_str_append(&out, 0, "%d hour%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec));
+ }
+ if (timeval.tv_sec > MINUTE) {
+ x = (timeval.tv_sec / MINUTE);
+ timeval.tv_sec -= (x * MINUTE);
+ ast_str_append(&out, 0, "%d minute%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec));
+ }
+ x = timeval.tv_sec;
if (x > 0 || out->used == 0) /* if there is nothing, print 0 seconds */
ast_str_append(&out, 0, "%d second%s ", x, ESS(x));
ast_cli(fd, "%s: %s\n", prefix, out->str);
static char * handle_showuptime(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- time_t curtime;
+ struct timeval curtime = ast_tvnow();
int printsec;
switch (cmd) {
printsec = 0;
else
return CLI_SHOWUSAGE;
- curtime = time(NULL);
- if (ast_startuptime)
- print_uptimestr(a->fd, curtime - ast_startuptime, "System uptime", printsec);
- if (ast_lastreloadtime)
- print_uptimestr(a->fd, curtime - ast_lastreloadtime, "Last reload", printsec);
+ if (ast_startuptime.tv_sec)
+ print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime", printsec);
+ if (ast_lastreloadtime.tv_sec)
+ print_uptimestr(a->fd, ast_tvsub(curtime, ast_lastreloadtime), "Last reload", printsec);
return CLI_SUCCESS;
}
struct stat st;
int len;
int fd;
- time_t t;
+ struct timeval tv = ast_tvnow();
char buf[256];
+ struct ast_tm tm;
/* Yuck. I'm not really sold on this, but if you don't deliver static content it makes your configuration
substantially more challenging, but this seems like a rather irritating feature creep on Asterisk. */
if (fd < 0)
goto out403;
- time(&t);
- strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
+ ast_strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S %Z", ast_localtime(&tv, &tm, "GMT"));
fprintf(ser->f, "HTTP/1.1 200 OK\r\n"
"Server: Asterisk/%s\r\n"
"Date: %s\r\n"
ast_variables_destroy(vars);
if (out) {
- time_t t = time(NULL);
+ struct timeval tv = ast_tvnow();
char timebuf[256];
+ struct ast_tm tm;
- strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
+ ast_strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S %Z", ast_localtime(&tv, &tm, "GMT"));
fprintf(ser->f, "HTTP/1.1 %d %s\r\n"
"Server: Asterisk/%s\r\n"
"Date: %s\r\n"
ast_verbose("The previous reload command didn't finish yet\n");
return -1; /* reload already in progress */
}
- ast_lastreloadtime = time(NULL);
+ ast_lastreloadtime = ast_tvnow();
/* Call "predefined" reload here first */
for (i = 0; reload_classes[i].name; i++) {
{
struct logmsg *logmsg = NULL;
struct ast_str *buf = NULL;
- struct tm tm;
- time_t t;
+ struct ast_tm tm;
+ struct timeval tv = ast_tvnow();
int res = 0;
va_list ap;
logmsg->type = LOGMSG_NORMAL;
/* Create our date/time */
- time(&t);
- ast_localtime(&t, &tm, NULL);
- strftime(logmsg->date, sizeof(logmsg->date), dateformat, &tm);
+ ast_localtime(&tv, &tm, NULL);
+ ast_strftime(logmsg->date, sizeof(logmsg->date), dateformat, &tm);
/* Copy over data */
logmsg->level = level;
return;
if (ast_opt_timestamp) {
- time_t t;
- struct tm tm;
+ struct timeval tv;
+ struct ast_tm tm;
char date[40];
char *datefmt;
- time(&t);
- ast_localtime(&t, &tm, NULL);
- strftime(date, sizeof(date), dateformat, &tm);
+ tv = ast_tvnow();
+ ast_localtime(&tv, &tm, NULL);
+ ast_strftime(date, sizeof(date), dateformat, &tm);
datefmt = alloca(strlen(date) + 3 + strlen(fmt) + 1);
sprintf(datefmt, "[%s] %s", date, fmt);
fmt = datefmt;
char idText[150];
char startuptime[150];
char reloadtime[150];
- struct tm tm;
+ struct ast_tm tm;
if (!ast_strlen_zero(actionid))
snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
ast_localtime(&ast_startuptime, &tm, NULL);
- strftime(startuptime, sizeof(startuptime), "%H:%M:%S", &tm);
+ ast_strftime(startuptime, sizeof(startuptime), "%H:%M:%S", &tm);
ast_localtime(&ast_lastreloadtime, &tm, NULL);
- strftime(reloadtime, sizeof(reloadtime), "%H:%M:%S", &tm);
+ ast_strftime(reloadtime, sizeof(reloadtime), "%H:%M:%S", &tm);
astman_append(s, "Response: Success\r\n"
"%s"
int ast_check_timing(const struct ast_timing *i)
{
- struct tm tm;
- time_t t = time(NULL);
+ struct ast_tm tm;
+ struct timeval tv = ast_tvnow();
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
/* If it's not the right month, return */
if (!(i->monthmask & (1 << tm.tm_mon)))
/* English syntax */
int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct ast_tm tm;
+ struct timeval tv = { t, 0 };
char fn[256];
int res = 0;
- ast_localtime(&t,&tm,NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
/* Danish syntax */
int ast_say_date_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
- ast_localtime(&t,&tm,NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
/* German syntax */
int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
- ast_localtime(&t,&tm,NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
/* Hungarian syntax */
int ast_say_date_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
- ast_localtime(&t,&tm,NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res)
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
/* French syntax */
int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
- ast_localtime(&t,&tm,NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
/* Dutch syntax */
int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
- ast_localtime(&t,&tm,NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
/* Thai syntax */
int ast_say_date_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
- ast_localtime(&t,&tm,NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
/* Portuguese syntax */
int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
if (!res)
res = wait_file(chan, ints, fn, lang);
/* English syntax */
int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
- struct tm tm;
+ struct timeval tv = { time, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
if (format == NULL)
format = "ABdY 'digits/at' IMp";
- ast_localtime(&time,&tm,timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
res = wait_file(chan,ints, "digits/today",lang);
* upon how recent the date is. XXX */
{
struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ now = ast_tvnow();
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
} else if ((beg_today - 86400) < time) {
/* Danish syntax */
int ast_say_date_with_format_da(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
- struct tm tm;
+ struct timeval tv = { time, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
if (!format)
format = "A dBY HMS";
- ast_localtime(&time,&tm,timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
res = wait_file(chan,ints, "digits/today",lang);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
} else if ((beg_today - 86400) < time) {
/* German syntax */
int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
- struct tm tm;
+ struct timeval tv = { time, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
if (!format)
format = "A dBY HMS";
- ast_localtime(&time,&tm,timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
res = wait_file(chan,ints, "digits/today",lang);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
/* Thai syntax */
int ast_say_date_with_format_th(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
- struct tm tm;
+ struct timeval tv = { time, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
if (format == NULL)
format = "a 'digits/tee' e 'digits/duan' hY I 'digits/naliga' M 'digits/natee'";
- ast_localtime(&time,&tm,timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
res = wait_file(chan,ints, "digits/today",lang);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
} else if ((beg_today - 86400) < time) {
/* TODO: This whole function is cut&paste from
* ast_say_date_with_format_en . Is that considered acceptable?
**/
- struct tm tm;
+ struct timeval tv = { time, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
if (!format)
format = IL_DATE_STR_FULL;
- ast_localtime(&time,&tm,timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
char todo = format[offset]; /* The letter to format*/
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
if (todo == 'Q') {
/* Spanish syntax */
int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
- struct tm tm;
+ struct timeval tv = { time, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
if (format == NULL)
format = "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y 'digits/at' IMp";
- ast_localtime(&time,&tm,timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
res = wait_file(chan,ints, "digits/today",lang);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
res = wait_file(chan,ints, "digits/today",lang);
*/
int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
- struct tm tm;
+ struct timeval tv = { time, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
if (format == NULL)
format = "AdBY 'digits/at' IMp";
- ast_localtime(&time,&tm,timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
res = wait_file(chan,ints, "digits/today",lang);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
} else if ((beg_today - 86400) < time) {
int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
- struct tm tm;
+ struct timeval tv = { time, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
if (format == NULL)
format = "AdB 'digits/at' IMp";
- ast_localtime(&time,&tm,timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
/* Literal name of a sound file */
sndoffset=0;
for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
+ sndfile[sndoffset] = format[offset];
sndfile[sndoffset] = '\0';
res = wait_file(chan,ints,sndfile,lang);
break;
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
res = wait_file(chan,ints, "digits/today",lang);
case 'q':
/* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
} else if ((beg_today - 86400) < time) {
/* Dutch syntax */
int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
- struct tm tm;
+ struct timeval tv = { time, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
if (format == NULL)
format = "ABdY 'digits/at' IMp";
- ast_localtime(&time,&tm,timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
res = wait_file(chan,ints, "digits/today",lang);
case 'q':
/* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
} else if ((beg_today - 86400) < time) {
/* Polish syntax */
int ast_say_date_with_format_pl(struct ast_channel *chan, time_t thetime, const char *ints, const char *lang, const char *format, const char *timezone)
{
- struct tm tm;
+ struct timeval tv = { thetime, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
- ast_localtime(&thetime, &tm, timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset = 0 ; format[offset] != '\0' ; offset++) {
int remainder;
case 'Q':
/* Shorthand for "Today", "Yesterday", or AdBY */
{
- time_t tv_sec = time(NULL);
- struct tm tmnow;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
time_t beg_today;
- ast_localtime(&tv_sec,&tmnow, timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < thetime) {
/* Today */
res = wait_file(chan, ints, "digits/today", lang);
case 'q':
/* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
{
- time_t tv_sec = time(NULL);
- struct tm tmnow;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
time_t beg_today;
- ast_localtime(&tv_sec, &tmnow, timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < thetime) {
/* Today */
} else if ((beg_today - 86400) < thetime) {
/* Portuguese syntax */
int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
- struct tm tm;
+ struct timeval tv = { time, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
if (format == NULL)
format = "Ad 'digits/pt-de' B 'digits/pt-de' Y 'digits/at' IMp";
- ast_localtime(&time,&tm,timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
res = wait_file(chan,ints, "digits/today",lang);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
} else if ((beg_today - 86400) < time) {
/* Taiwanese / Chinese syntax */
int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
- struct tm tm;
+ struct timeval tv = { time, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
if (format == NULL)
format = "YBdAkM";
- ast_localtime(&time,&tm,timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
res = wait_file(chan,ints, "digits/today",lang);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
} else if ((beg_today - 86400) < time) {
/* English syntax */
int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
int hour, pm=0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
hour = tm.tm_hour;
if (!hour)
hour = 12;
/* German syntax */
int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res)
res = ast_say_number(chan, tm.tm_hour, ints, lang, "n");
if (!res)
/* Hungarian syntax */
int ast_say_time_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res)
res = ast_say_number(chan, tm.tm_hour, ints, lang, "n");
if (!res)
/* French syntax */
int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
if (!res)
/* Dutch syntax */
int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res)
res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
if (!res)
/* Portuguese syntax */
int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
int hour;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
hour = tm.tm_hour;
if (!res)
res = ast_say_number(chan, hour, ints, lang, "f");
/* Brazilian Portuguese syntax */
int ast_say_time_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
if (!res) {
/* Thai syntax */
int ast_say_time_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
int hour;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
hour = tm.tm_hour;
if (!hour)
hour = 24;
/* Taiwanese / Chinese syntax */
int ast_say_time_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
int hour, pm=0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
hour = tm.tm_hour;
if (!hour)
hour = 12;
/* English syntax */
int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
int hour, pm=0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
/* German syntax */
int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
res = ast_say_date(chan, t, ints, lang);
if (!res)
ast_say_time(chan, t, ints, lang);
/* Hungarian syntax */
int ast_say_datetime_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
res = ast_say_date(chan, t, ints, lang);
if (!res)
ast_say_time(chan, t, ints, lang);
/* French syntax */
int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res)
res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
/* Dutch syntax */
int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
res = ast_say_date(chan, t, ints, lang);
if (!res) {
res = ast_streamfile(chan, "digits/nl-om", lang);
/* Portuguese syntax */
int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
int hour, pm=0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
/* Brazilian Portuguese syntax */
int ast_say_datetime_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
res = ast_say_date(chan, t, ints, lang);
if (!res)
res = ast_say_time(chan, t, ints, lang);
/* Thai syntax */
int ast_say_datetime_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
int hour;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
/* Taiwanese / Chinese syntax */
int ast_say_datetime_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
int hour, pm=0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res)
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
if (!res) {
int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
int res=0;
- time_t nowt;
+ struct timeval nowtv = ast_tvnow(), tv = { t, 0 };
int daydiff;
- struct tm tm;
- struct tm now;
+ struct ast_tm tm;
+ struct ast_tm now;
char fn[256];
- time(&nowt);
-
- ast_localtime(&t, &tm, NULL);
- ast_localtime(&nowt,&now, NULL);
+ ast_localtime(&tv, &tm, NULL);
+ ast_localtime(&nowtv, &now, NULL);
daydiff = now.tm_yday - tm.tm_yday;
if ((daydiff < 0) || (daydiff > 6)) {
/* Day of month and month */
int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
int res=0;
- time_t nowt;
+ struct timeval nowtv = ast_tvnow(), tv = { t, 0 };
int daydiff;
- struct tm tm;
- struct tm now;
+ struct ast_tm tm;
+ struct ast_tm now;
char fn[256];
- time(&nowt);
-
- ast_localtime(&t, &tm, NULL);
- ast_localtime(&nowt, &now, NULL);
+ ast_localtime(&tv, &tm, NULL);
+ ast_localtime(&nowtv, &now, NULL);
daydiff = now.tm_yday - tm.tm_yday;
if ((daydiff < 0) || (daydiff > 6)) {
/* Day of month and month */
int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
int res=0;
- time_t nowt;
int daydiff;
- struct tm tm;
- struct tm now;
+ struct ast_tm tm;
+ struct ast_tm now;
+ struct timeval nowtv = ast_tvnow(), tv = { t, 0 };
char fn[256];
- time(&nowt);
-
- ast_localtime(&t, &tm, NULL);
- ast_localtime(&nowt, &now, NULL);
+ ast_localtime(&tv, &tm, NULL);
+ ast_localtime(&nowtv, &now, NULL);
daydiff = now.tm_yday - tm.tm_yday;
if ((daydiff < 0) || (daydiff > 6)) {
/* Day of month and month */
static int ast_say_date_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct ast_tm tm;
+ struct timeval tv = { t, 0 };
char fn[256];
int res = 0;
- ast_localtime(&t,&tm,NULL);
+ ast_localtime(&tv, &tm, NULL);
/* W E E K - D A Y */
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
static int ast_say_time_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
int hour, pm=0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
hour = tm.tm_hour;
if (!hour)
static int ast_say_datetime_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
-
/* W E E K - D A Y */
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
-
- struct tm tm;
+ struct timeval tv = { time, 0 };
+ struct ast_tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
if (!format)
format = "AdBY 'digits/at' IMp";
- ast_localtime(&time,&tm,timezone);
+ ast_localtime(&tv, &tm, timezone);
for (offset=0 ; format[offset] != '\0' ; offset++) {
ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
res = wait_file(chan,ints, "digits/today",lang);
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
- struct timeval now;
- struct tm tmnow;
- time_t beg_today, tt;
+ struct timeval now = ast_tvnow();
+ struct ast_tm tmnow;
+ time_t beg_today;
- gettimeofday(&now,NULL);
- tt = now.tv_sec;
- ast_localtime(&tt,&tmnow,timezone);
+ ast_localtime(&now, &tmnow, timezone);
/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
/* In any case, it saves not having to do ast_mktime() */
- beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
} else if ((beg_today - 86400) < time) {
/* Georgian syntax. e.g. "oriatas xuti tslis 5 noemberi". */
static int ast_say_date_ge(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
char fn[256];
int res = 0;
- ast_localtime(&t,&tm,NULL);
+ ast_localtime(&tv, &tm, NULL);
if (!res)
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
/* Georgian syntax. e.g. "otxi saati da eqvsi tsuti" */
static int ast_say_time_ge(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
res = ast_say_number(chan, tm.tm_hour, ints, lang, (char*)NULL);
if (!res) {
/* Georgian syntax. Say date, then say time. */
static int ast_say_datetime_ge(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
- struct tm tm;
+ struct timeval tv = { t, 0 };
+ struct ast_tm tm;
int res = 0;
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
res = ast_say_date(chan, t, ints, lang);
if (!res)
ast_say_time(chan, t, ints, lang);
static int ast_say_datetime_from_now_ge(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
int res=0;
- time_t nowt;
int daydiff;
- struct tm tm;
- struct tm now;
+ struct ast_tm tm;
+ struct ast_tm now;
+ struct timeval tv = { t, 0 }, nowt = ast_tvnow();
char fn[256];
- time(&nowt);
-
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&tv, &tm, NULL);
ast_localtime(&nowt, &now, NULL);
daydiff = now.tm_yday - tm.tm_yday;
if ((daydiff < 0) || (daydiff > 6)) {
static const char * getoffset P((const char * strp, long * offsetp));
static const char * getrule P((const char * strp, struct rule * rulep));
static void gmtload P((struct state * sp));
-static void gmtsub P((const time_t * timep, long offset,
- struct tm * tmp, const char * zone));
-static void localsub P((const time_t * timep, long offset,
- struct tm * tmp, const char * zone));
+static void gmtsub P((const struct timeval * timep, long offset,
+ struct ast_tm * tmp, const char * zone));
+static void localsub P((const struct timeval * timep, long offset,
+ struct ast_tm * tmp, const char * zone));
static int increment_overflow P((int * number, int delta));
static int normalize_overflow P((int * tensptr, int * unitsptr,
int base));
-static time_t time1 P((struct tm * tmp,
- void(*funcp) P((const time_t *,
- long, struct tm *, const char*)),
+static time_t time1 P((struct ast_tm * tmp,
+ void(*funcp) P((const struct timeval *,
+ long, struct ast_tm *, const char *)),
long offset, const char * zone));
-static time_t time2 P((struct tm *tmp,
- void(*funcp) P((const time_t *,
- long, struct tm*, const char*)),
+static time_t time2 P((struct ast_tm *tmp,
+ void(*funcp) P((const struct timeval *,
+ long, struct ast_tm *, const char *)),
long offset, int * okayp, const char * zone));
-static void timesub P((const time_t * timep, long offset,
- const struct state * sp, struct tm * tmp));
-static int tmcomp P((const struct tm * atmp,
- const struct tm * btmp));
+static void 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));
/*ARGSUSED*/
static void
localsub(timep, offset, tmp, zone)
-const time_t * const timep;
+const struct timeval * const timep;
const long offset;
-struct tm * const tmp;
+struct ast_tm * const tmp;
const char * const zone;
{
register struct state * sp;
register const struct ttinfo * ttisp;
register int i;
- const time_t t = *timep;
+ struct timeval t;
+ memcpy(&t, timep, sizeof(t));
sp = lclptr;
/* Find the right zone record */
gmtsub(timep, offset, tmp, zone);
return;
}
- if (sp->timecnt == 0 || t < sp->ats[0]) {
+ if (sp->timecnt == 0 || t.tv_sec < sp->ats[0]) {
i = 0;
while (sp->ttis[i].tt_isdst)
if (++i >= sp->typecnt) {
}
} else {
for (i = 1; i < sp->timecnt; ++i)
- if (t < sp->ats[i])
+ if (t.tv_sec < sp->ats[i])
break;
i = sp->types[i - 1];
}
#ifdef TM_ZONE
tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind];
#endif /* defined TM_ZONE */
+ tmp->tm_usec = timep->tv_usec;
}
-struct tm *
+struct ast_tm *
ast_localtime(timep, p_tm, zone)
-const time_t * const timep;
-struct tm *p_tm;
+const struct timeval * const timep;
+struct ast_tm *p_tm;
const char * const zone;
{
#ifdef _THREAD_SAFE
static void
gmtsub(timep, offset, tmp, zone)
-const time_t * const timep;
+const struct timeval * const timep;
const long offset;
-struct tm * const tmp;
+struct ast_tm * const tmp;
const char * const zone;
{
#ifdef _THREAD_SAFE
static void
timesub(timep, offset, sp, tmp)
-const time_t * const timep;
+const struct timeval * const timep;
const long offset;
register const struct state * const sp;
-register struct tm * const tmp;
+register struct ast_tm * const tmp;
{
register const struct lsinfo * lp;
register long days;
i = (sp == NULL) ? 0 : sp->leapcnt;
while (--i >= 0) {
lp = &sp->lsis[i];
- if (*timep >= lp->ls_trans) {
- if (*timep == lp->ls_trans) {
+ if (timep->tv_sec >= lp->ls_trans) {
+ if (timep->tv_sec == lp->ls_trans) {
hit = ((i == 0 && lp->ls_corr > 0) ||
lp->ls_corr > sp->lsis[i - 1].ls_corr);
if (hit)
break;
}
}
- days = *timep / SECSPERDAY;
- rem = *timep % SECSPERDAY;
+ days = timep->tv_sec / SECSPERDAY;
+ rem = timep->tv_sec % SECSPERDAY;
#ifdef mc68k
- if (*timep == 0x80000000) {
+ if (timep->tv_sec == 0x80000000) {
/*
** A 3B1 muffs the division on the most negative number.
*/
#ifdef TM_GMTOFF
tmp->TM_GMTOFF = offset;
#endif /* defined TM_GMTOFF */
+ tmp->tm_usec = timep->tv_usec;
}
char *
-ast_ctime(timep)
-const time_t * const timep;
-{
-/*
-** Section 4.12.3.2 of X3.159-1989 requires that
-** The ctime funciton converts the calendar time pointed to by timer
-** to local time in the form of a string. It is equivalent to
-** asctime(localtime(timer))
-*/
- return asctime(localtime(timep));
-}
-
-char *
-ast_ctime_r(timep, buf)
-const time_t * const timep;
+ast_ctime(timep, buf)
+const struct timeval * const timep;
char *buf;
{
- struct tm tm;
- return asctime_r(ast_localtime(timep, &tm, NULL), buf);
+ struct ast_tm tm;
+ return asctime_r((struct tm *)ast_localtime(timep, &tm, NULL), buf);
}
/*
static int
tmcomp(atmp, btmp)
-register const struct tm * const atmp;
-register const struct tm * const btmp;
+register const struct ast_tm * const atmp;
+register const struct ast_tm * const btmp;
{
register int result;
static time_t
time2(tmp, funcp, offset, okayp, zone)
-struct tm * const tmp;
-void (* const funcp) P((const time_t*, long, struct tm*, const char*));
+struct ast_tm * const tmp;
+void (* const funcp) P((const struct timeval *, long, struct ast_tm*, const char*));
const long offset;
int * const okayp;
const char * const zone;
register int bits;
register int i, j ;
register int saved_seconds;
- time_t newt;
- time_t t;
- struct tm yourtm, mytm;
+ struct timeval newt = { 0, 0 };
+ struct timeval t = { 0, 0 };
+ struct ast_tm yourtm, mytm;
*okayp = FALSE;
yourtm = *tmp;
** assuming two's complement arithmetic.
** If time_t is unsigned, then (1 << bits) is just above the median.
*/
- t = TYPE_SIGNED(time_t) ? 0 : (((time_t) 1) << bits);
+ t.tv_sec = 0;
for ( ; ; ) {
(*funcp)(&t, offset, &mytm, zone);
dir = tmcomp(&mytm, &yourtm);
if (bits-- < 0)
return WRONG;
if (bits < 0)
- --t; /* may be needed if new t is minimal */
+ --t.tv_sec; /* may be needed if new t is minimal */
else if (dir > 0)
- t -= ((time_t) 1) << bits;
- else t += ((time_t) 1) << bits;
+ t.tv_sec -= ((time_t) 1) << bits;
+ else t.tv_sec += ((time_t) 1) << bits;
continue;
}
if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
for (j = sp->typecnt - 1; j >= 0; --j) {
if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
continue;
- newt = t + sp->ttis[j].tt_gmtoff -
+ newt.tv_sec = t.tv_sec + sp->ttis[j].tt_gmtoff -
sp->ttis[i].tt_gmtoff;
(*funcp)(&newt, offset, &mytm, zone);
if (tmcomp(&mytm, &yourtm) != 0)
return WRONG;
}
label:
- newt = t + saved_seconds;
- if ((newt < t) != (saved_seconds < 0))
+ newt.tv_sec = t.tv_sec + saved_seconds;
+ if ((newt.tv_sec < t.tv_sec) != (saved_seconds < 0))
return WRONG;
- t = newt;
+ t.tv_sec = newt.tv_sec;
(*funcp)(&t, offset, tmp, zone);
*okayp = TRUE;
- return t;
+ return t.tv_sec;
}
static time_t
time1(tmp, funcp, offset, zone)
-struct tm * const tmp;
-void (* const funcp) P((const time_t *, long, struct tm *, const char*));
+struct ast_tm * const tmp;
+void (* const funcp) P((const struct timeval *, long, struct ast_tm *, const char*));
const long offset;
const char * const zone;
{
time_t
ast_mktime(tmp,zone)
-struct tm * const tmp;
+struct ast_tm * const tmp;
const char * const zone;
{
time_t mktime_return_value;
return(mktime_return_value);
}
+int ast_strftime(char *buf, size_t len, const char *tmp, const struct ast_tm *tm)
+{
+ size_t fmtlen = strlen(tmp) + 1;
+ char *format = ast_calloc(1, fmtlen), *fptr = format, *newfmt;
+ int decimals = -1, i, res;
+ long fraction;
+
+ if (!format)
+ return -1;
+ for (; *tmp; tmp++) {
+ if (*tmp == '%') {
+ switch (tmp[1]) {
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ if (tmp[2] != 'q')
+ goto defcase;
+ decimals = tmp[1] - '0';
+ tmp++;
+ /* Fall through */
+ case 'q': /* Milliseconds */
+ if (decimals == -1)
+ decimals = 3;
+
+ /* Juggle some memory to fit the item */
+ newfmt = ast_realloc(format, fmtlen + decimals);
+ if (!newfmt) {
+ ast_free(format);
+ return -1;
+ }
+ fptr = fptr - format + newfmt;
+ format = newfmt;
+ fmtlen += decimals;
+
+ /* Reduce the fraction of time to the accuracy needed */
+ for (i = 6, fraction = tm->tm_usec; i > decimals; i--)
+ fraction /= 10;
+ fptr += sprintf(fptr, "%0*ld", decimals, fraction);
+
+ /* Reset, in case more than one 'q' specifier exists */
+ decimals = -1;
+ tmp++;
+ break;
+ default:
+ goto defcase;
+ }
+ } else
+defcase: *fptr++ = *tmp;
+ }
+ *fptr = '\0';
+#undef strftime
+ res = (int)strftime(buf, len, format, (struct tm *)tm);
+ ast_free(format);
+ return res;
+}
+
return ret;
}
+/*! \brief
+ * get values from config variables.
+ */
+int ast_get_timeval(const char *src, struct timeval *dst, struct timeval _default, int *consumed)
+{
+ long double dtv = 0.0;
+ int scanned;
+
+ if (dst == NULL)
+ return -1;
+
+ *dst = _default;
+
+ if (ast_strlen_zero(src))
+ return -1;
+
+ /* only integer at the moment, but one day we could accept more formats */
+ if (sscanf(src, "%Lf%n", &dtv, &scanned) > 0) {
+ dst->tv_sec = dtv;
+ dst->tv_usec = (dtv - dst->tv_sec) * 1000000.0;
+ if (consumed)
+ *consumed = scanned;
+ return 0;
+ } else
+ return -1;
+}
+
/*! \brief
* get values from config variables.
*/
switch (vp->magic) {
case ASTCONFUPTIME:
gettimeofday(&tval, NULL);
- long_ret = difftime(tval.tv_sec, ast_startuptime) * 100 + tval.tv_usec / 10000;
+ long_ret = difftime(tval.tv_sec, ast_startuptime.tv_sec) * 100 + tval.tv_usec / 10000 - ast_startuptime.tv_usec / 10000;
return (u_char *)&long_ret;
case ASTCONFRELOADTIME:
gettimeofday(&tval, NULL);
- if (ast_lastreloadtime)
- long_ret = difftime(tval.tv_sec, ast_lastreloadtime) * 100 + tval.tv_usec / 10000;
+ if (ast_lastreloadtime.tv_sec)
+ long_ret = difftime(tval.tv_sec, ast_lastreloadtime.tv_sec) * 100 + tval.tv_usec / 10000 - ast_lastreloadtime.tv_usec / 10000;
else
- long_ret = difftime(tval.tv_sec, ast_startuptime) * 100 + tval.tv_usec / 10000;
+ long_ret = difftime(tval.tv_sec, ast_startuptime.tv_sec) * 100 + tval.tv_usec / 10000 - ast_startuptime.tv_usec / 10000;
return (u_char *)&long_ret;
case ASTCONFPID:
long_ret = getpid();