[asterisk-commits] tilghman: branch group/ast_strftime r73819 - in /team/group/ast_strftime: ./ ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Jul 7 08:46:53 CDT 2007
Author: tilghman
Date: Sat Jul 7 08:46:52 2007
New Revision: 73819
URL: http://svn.digium.com/view/asterisk?view=rev&rev=73819
Log:
Modify ast_localtime and other functions to use struct timeval, instead of time_t
Modified:
team/group/ast_strftime/ (props changed)
team/group/ast_strftime/apps/app_alarmreceiver.c
team/group/ast_strftime/apps/app_minivm.c
team/group/ast_strftime/apps/app_playback.c
team/group/ast_strftime/apps/app_sms.c
team/group/ast_strftime/apps/app_voicemail.c
team/group/ast_strftime/cdr/cdr_csv.c
team/group/ast_strftime/cdr/cdr_odbc.c
team/group/ast_strftime/cdr/cdr_pgsql.c
team/group/ast_strftime/cdr/cdr_sqlite.c
team/group/ast_strftime/cdr/cdr_tds.c
team/group/ast_strftime/channels/chan_agent.c
team/group/ast_strftime/channels/chan_iax2.c
team/group/ast_strftime/channels/chan_mgcp.c
team/group/ast_strftime/channels/chan_phone.c
team/group/ast_strftime/channels/chan_sip.c
team/group/ast_strftime/channels/chan_zap.c
team/group/ast_strftime/funcs/func_strings.c
team/group/ast_strftime/include/asterisk/localtime.h
team/group/ast_strftime/include/asterisk/options.h
team/group/ast_strftime/include/asterisk/strings.h
team/group/ast_strftime/main/asterisk.c
team/group/ast_strftime/main/callerid.c
team/group/ast_strftime/main/cdr.c
team/group/ast_strftime/main/cli.c
team/group/ast_strftime/main/loader.c
team/group/ast_strftime/main/logger.c
team/group/ast_strftime/main/manager.c
team/group/ast_strftime/main/pbx.c
team/group/ast_strftime/main/say.c
team/group/ast_strftime/main/stdtime/localtime.c
team/group/ast_strftime/main/utils.c
Propchange: team/group/ast_strftime/
------------------------------------------------------------------------------
automerge = *
Propchange: team/group/ast_strftime/
------------------------------------------------------------------------------
automerge-email = tilghman at mail.jeffandtilghman.com
Propchange: team/group/ast_strftime/
------------------------------------------------------------------------------
svnmerge-integrated = /trunk:1-73817
Modified: team/group/ast_strftime/apps/app_alarmreceiver.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/apps/app_alarmreceiver.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/apps/app_alarmreceiver.c (original)
+++ team/group/ast_strftime/apps/app_alarmreceiver.c Sat Jul 7 08:46:52 2007
@@ -306,8 +306,8 @@
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];
@@ -324,12 +324,12 @@
/* 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);
+ strftime(timestamp, sizeof(timestamp), time_stamp_format, (struct tm *)&now);
res = fprintf(logfile, "\n\n[metadata]\n\n");
Modified: team/group/ast_strftime/apps/app_minivm.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/apps/app_minivm.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/apps/app_minivm.c (original)
+++ team/group/ast_strftime/apps/app_minivm.c Sat Jul 7 08:46:52 2007
@@ -425,9 +425,9 @@
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 */
@@ -713,12 +713,11 @@
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 strftime(s, len, "%a %b %e %r %Z %Y", (struct tm *)&tm);
}
@@ -898,8 +897,8 @@
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;
@@ -986,15 +985,15 @@
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);
+ strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", (struct tm *)&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);
+ strftime(date, sizeof(date), template->dateformat, (struct tm *)&tm);
/* Populate channel with channel variables for substitution */
@@ -1550,14 +1549,13 @@
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);
+ strftime(timebuf, sizeof(timebuf), "%H:%M:%S", (struct tm *)&tm);
snprintf(logbuf, sizeof(logbuf),
/* "Mailbox:domain:macrocontext:exten:priority:callerchan:callerid:origdate:origtime:duration:durationstatus:accountcode" */
@@ -1608,7 +1606,7 @@
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) {
@@ -2430,8 +2428,8 @@
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) {
@@ -2697,7 +2695,7 @@
/*! \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");
@@ -2711,11 +2709,11 @@
} 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);
+ strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", (struct tm *)&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);
+ strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", (struct tm *)&time);
ast_cli(fd, " Last reset: %s\n", buf);
ast_cli(fd, "\n");
Modified: team/group/ast_strftime/apps/app_playback.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/apps/app_playback.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/apps/app_playback.c (original)
+++ team/group/ast_strftime/apps/app_playback.c Sat Jul 7 08:46:52 2007
@@ -281,12 +281,13 @@
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,
Modified: team/group/ast_strftime/apps/app_sms.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/apps/app_sms.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/apps/app_sms.c (original)
+++ team/group/ast_strftime/apps/app_sms.c Sat Jul 7 08:46:52 2007
@@ -277,9 +277,10 @@
/*! \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);
+ strftime(buf, len, "%Y-%m-%dT%H:%M:%S", (struct tm *)&tm);
return buf;
}
@@ -511,10 +512,11 @@
/*! \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
@@ -547,7 +549,7 @@
t.tm_min += 15 * ((i[6] & 0x7) * 10 + (i[6] >> 4));
else
t.tm_min -= 15 * ((i[6] & 0x7) * 10 + (i[6] >> 4));
- return mktime(&t);
+ return mktime((struct tm *)&t);
}
/*! \brief unpacks bytes (7 bit encoding) at i, len l septets,
@@ -1113,7 +1115,8 @@
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... */
@@ -1122,7 +1125,7 @@
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)
@@ -1160,14 +1163,15 @@
{
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++];
@@ -1183,14 +1187,14 @@
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 = mktime((struct tm *)&tm);
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;
Modified: team/group/ast_strftime/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/apps/app_voicemail.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/apps/app_voicemail.c (original)
+++ team/group/ast_strftime/apps/app_voicemail.c Sat Jul 7 08:46:52 2007
@@ -1967,10 +1967,10 @@
* 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)) {
@@ -2010,7 +2010,7 @@
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;
@@ -2032,11 +2032,11 @@
*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));
+ strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", (struct tm *)vmu_tm(vmu, &tm));
fprintf(p, "Date: %s" ENDL, date);
/* Set date format for voicemail mail */
- strftime(date, sizeof(date), emaildateformat, &tm);
+ strftime(date, sizeof(date), emaildateformat, (struct tm *)&tm);
if (!ast_strlen_zero(fromstring)) {
struct ast_channel *ast;
@@ -2217,7 +2217,7 @@
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) {
@@ -2230,7 +2230,7 @@
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));
+ strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", (struct tm *)vmu_tm(vmu, &tm));
fprintf(p, "Date: %s\n", date);
if (*pagerfromstring) {
@@ -2269,7 +2269,7 @@
} else
fprintf(p, "Subject: New VM\n\n");
- strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm);
+ strftime(date, sizeof(date), "%A, %B %d, %Y at %r", (struct tm *)&tm);
if (pagerbody) {
struct ast_channel *ast;
if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, 0))) {
@@ -2296,11 +2296,10 @@
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 strftime(s, len, "%a %b %e %r %Z %Y", (struct tm *)&tm);
}
static int invent_message(struct ast_channel *chan, char *context, char *ext, int busy, char *ecodes)
@@ -4462,8 +4461,7 @@
/* 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)
Modified: team/group/ast_strftime/cdr/cdr_csv.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/cdr/cdr_csv.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/cdr/cdr_csv.c (original)
+++ team/group/ast_strftime/cdr/cdr_csv.c Sat Jul 7 08:46:52 2007
@@ -188,21 +188,15 @@
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);
+ strftime(tmp, sizeof(tmp), DATE_FORMAT, (struct tm *)&tm);
return append_string(buf, tmp, bufsize);
}
Modified: team/group/ast_strftime/cdr/cdr_odbc.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/cdr/cdr_odbc.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/cdr/cdr_odbc.c (original)
+++ team/group/ast_strftime/cdr/cdr_odbc.c Sat Jul 7 08:46:52 2007
@@ -95,15 +95,12 @@
int ODBC_res;
char sqlcmd[2048] = "", timestr[128];
int res = 0;
- struct tm tm;
-
- if (usegmtime)
- gmtime_r(&cdr->start.tv_sec,&tm);
- else
- ast_localtime(&cdr->start.tv_sec, &tm, NULL);
+ struct ast_tm tm;
+
+ ast_localtime(&cdr->start, &tm, usegmtime ? "GMT" : NULL);
ast_mutex_lock(&odbc_lock);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
+ strftime(timestr, sizeof(timestr), DATE_FORMAT, (struct tm *)&tm);
memset(sqlcmd,0,2048);
if (loguniqueid) {
snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s "
Modified: team/group/ast_strftime/cdr/cdr_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/cdr/cdr_pgsql.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/cdr/cdr_pgsql.c (original)
+++ team/group/ast_strftime/cdr/cdr_pgsql.c Sat Jul 7 08:46:52 2007
@@ -71,15 +71,15 @@
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);
+ strftime(timestr, sizeof(timestr), DATE_FORMAT, (struct tm *)&tm);
if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) {
conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
Modified: team/group/ast_strftime/cdr/cdr_sqlite.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/cdr/cdr_sqlite.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/cdr/cdr_sqlite.c (original)
+++ team/group/ast_strftime/cdr/cdr_sqlite.c Sat Jul 7 08:46:52 2007
@@ -96,24 +96,20 @@
{
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);
-
- t = cdr->answer.tv_sec;
- ast_localtime(&t, &tm, NULL);
- 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->start, &tm, NULL);
+ strftime(startstr, sizeof(startstr), DATE_FORMAT, (struct tm *)&tm);
+
+ ast_localtime(&cdr->answer, &tm, NULL);
+ strftime(answerstr, sizeof(answerstr), DATE_FORMAT, (struct tm *)&tm);
+
+ ast_localtime(&cdr->end, &tm, NULL);
+ strftime(endstr, sizeof(endstr), DATE_FORMAT, (struct tm *)&tm);
for(count=0; count<5; count++) {
res = sqlite_exec_printf(db,
Modified: team/group/ast_strftime/cdr/cdr_tds.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/cdr/cdr_tds.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/cdr/cdr_tds.c (original)
+++ team/group/ast_strftime/cdr/cdr_tds.c Sat Jul 7 08:46:52 2007
@@ -278,16 +278,14 @@
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);
+ strftime(buf, 80, DATE_FORMAT, (struct tm *)&tm);
sprintf(dateField, "'%s'", buf);
}
else
Modified: team/group/ast_strftime/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/channels/chan_agent.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/channels/chan_agent.c (original)
+++ team/group/ast_strftime/channels/chan_agent.c Sat Jul 7 08:46:52 2007
@@ -1810,7 +1810,7 @@
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 */
Modified: team/group/ast_strftime/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/channels/chan_iax2.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/channels/chan_iax2.c (original)
+++ team/group/ast_strftime/channels/chan_iax2.c Sat Jul 7 08:46:52 2007
@@ -1274,7 +1274,7 @@
{
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;
@@ -1283,7 +1283,6 @@
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)) {
@@ -1369,7 +1368,7 @@
* 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]);
@@ -1872,7 +1871,7 @@
retry:
pvt = iaxs[callno];
- gettimeofday(&lastused[callno], NULL);
+ lastused[callno] = ast_tvnow();
owner = pvt ? pvt->owner : NULL;
@@ -2274,9 +2273,7 @@
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);
@@ -2387,7 +2384,7 @@
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]);
@@ -2400,7 +2397,6 @@
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 */
@@ -2882,14 +2878,10 @@
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 */
@@ -3322,7 +3314,7 @@
}
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) {
@@ -3586,7 +3578,7 @@
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;
}
@@ -3622,7 +3614,7 @@
}
}
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;
}
@@ -3850,7 +3842,7 @@
/* 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 ++;
}
@@ -6241,10 +6233,9 @@
#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 */
@@ -9889,12 +9880,10 @@
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) {
@@ -9923,7 +9912,7 @@
}
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;
Modified: team/group/ast_strftime/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/channels/chan_mgcp.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/channels/chan_mgcp.c (original)
+++ team/group/ast_strftime/channels/chan_mgcp.c Sat Jul 7 08:46:52 2007
@@ -736,15 +736,11 @@
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;
-
- if (gw->retransid == -1)
- gw->retransid = ast_sched_add(sched, DEFAULT_RETRANS, retrans_pkt, (void *)gw);
- }
+ 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);
ast_mutex_unlock(&gw->msgs_lock);
/* SC
if (!gw->messagepending) {
@@ -2232,11 +2228,10 @@
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;
Modified: team/group/ast_strftime/channels/chan_phone.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/channels/chan_phone.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/channels/chan_phone.c (original)
+++ team/group/ast_strftime/channels/chan_phone.c Sat Jul 7 08:46:52 2007
@@ -290,11 +290,10 @@
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));
Modified: team/group/ast_strftime/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/channels/chan_sip.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/channels/chan_sip.c (original)
+++ team/group/ast_strftime/channels/chan_sip.c Sat Jul 7 08:46:52 2007
@@ -1212,7 +1212,7 @@
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 */
@@ -11030,7 +11030,7 @@
#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)
@@ -11039,9 +11039,9 @@
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);
+ strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", (struct tm *)&tm);
} else
tmpdat[0] = '\0';
ast_cli(fd, FORMAT, host, iterator->username, iterator->refresh, regstate2str(iterator->regstate), tmpdat);
@@ -12963,7 +12963,7 @@
}
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");
@@ -16164,7 +16164,7 @@
#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
Modified: team/group/ast_strftime/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/channels/chan_zap.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/channels/chan_zap.c (original)
+++ team/group/ast_strftime/channels/chan_zap.c Sat Jul 7 08:46:52 2007
@@ -3050,7 +3050,7 @@
/* 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);
@@ -4454,7 +4454,7 @@
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:
@@ -4724,7 +4724,7 @@
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);
@@ -4827,7 +4827,7 @@
/* 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);
@@ -8530,7 +8530,7 @@
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) {
@@ -9293,7 +9293,7 @@
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];
@@ -9310,7 +9310,6 @@
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, '@');
@@ -9380,7 +9379,7 @@
}
} 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)) {
Modified: team/group/ast_strftime/funcs/func_strings.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/funcs/func_strings.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/funcs/func_strings.c (original)
+++ team/group/ast_strftime/funcs/func_strings.c Sat Jul 7 08:46:52 2007
@@ -599,20 +599,20 @@
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 (!strftime(buf, len, args.format, (struct tm *)&tm))
ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n");
buf[len - 1] = '\0';
@@ -635,9 +635,7 @@
AST_APP_ARG(timezone);
AST_APP_ARG(format);
);
- struct tm time;
-
- memset(&time, 0, sizeof(struct tm));
+ struct ast_tm time = { 0, };
buf[0] = '\0';
@@ -655,7 +653,7 @@
return -1;
}
- if (!strptime(args.timestring, args.format, &time)) {
+ if (!strptime(args.timestring, args.format, (struct tm *)&time)) {
ast_log(LOG_WARNING, "C function strptime() output nothing?!!\n");
} else {
snprintf(buf, len, "%d", (int) ast_mktime(&time, args.timezone));
Modified: team/group/ast_strftime/include/asterisk/localtime.h
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/include/asterisk/localtime.h?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/include/asterisk/localtime.h (original)
+++ team/group/ast_strftime/include/asterisk/localtime.h Sat Jul 7 08:46:52 2007
@@ -24,11 +24,26 @@
#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);
#endif /* _ASTERISK_LOCALTIME_H */
Modified: team/group/ast_strftime/include/asterisk/options.h
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/include/asterisk/options.h?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/include/asterisk/options.h (original)
+++ team/group/ast_strftime/include/asterisk/options.h Sat Jul 7 08:46:52 2007
@@ -116,8 +116,8 @@
#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];
Modified: team/group/ast_strftime/include/asterisk/strings.h
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/include/asterisk/strings.h?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/include/asterisk/strings.h (original)
+++ team/group/ast_strftime/include/asterisk/strings.h Sat Jul 7 08:46:52 2007
@@ -244,6 +244,16 @@
*/
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.
*
Modified: team/group/ast_strftime/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/main/asterisk.c?view=diff&rev=73819&r1=73818&r2=73819
==============================================================================
--- team/group/ast_strftime/main/asterisk.c (original)
+++ team/group/ast_strftime/main/asterisk.c Sat Jul 7 08:46:52 2007
@@ -193,8 +193,8 @@
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;
@@ -346,7 +346,7 @@
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");
@@ -366,11 +366,11 @@
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);
+ strftime(buf, sizeof(buf), "%H:%M:%S", (struct tm *)&tm);
ast_cli(fd, " Startup time: %s\n", buf);
}
if (ast_localtime(&ast_lastreloadtime, &tm, NULL)) {
- strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
+ strftime(buf, sizeof(buf), "%H:%M:%S", (struct tm *)&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);
@@ -1760,8 +1760,8 @@
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
[... 1963 lines stripped ...]
More information about the asterisk-commits
mailing list