[asterisk-commits] tilghman: trunk r75706 - in /trunk: apps/ cdr/ channels/ channels/misdn/ func...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 18 14:47:21 CDT 2007


Author: tilghman
Date: Wed Jul 18 14:47:20 2007
New Revision: 75706

URL: http://svn.digium.com/view/asterisk?view=rev&rev=75706
Log:
Merge in ast_strftime branch, which changes timestamps to be accurate to the microsecond, instead of only to the second

Modified:
    trunk/apps/app_alarmreceiver.c
    trunk/apps/app_minivm.c
    trunk/apps/app_playback.c
    trunk/apps/app_rpt.c
    trunk/apps/app_sms.c
    trunk/apps/app_voicemail.c
    trunk/cdr/cdr_csv.c
    trunk/cdr/cdr_manager.c
    trunk/cdr/cdr_odbc.c
    trunk/cdr/cdr_pgsql.c
    trunk/cdr/cdr_radius.c
    trunk/cdr/cdr_sqlite.c
    trunk/cdr/cdr_tds.c
    trunk/channels/chan_agent.c
    trunk/channels/chan_iax2.c
    trunk/channels/chan_mgcp.c
    trunk/channels/chan_phone.c
    trunk/channels/chan_sip.c
    trunk/channels/chan_skinny.c
    trunk/channels/chan_zap.c
    trunk/channels/iax2-parser.c
    trunk/channels/misdn/ie.c
    trunk/funcs/func_strings.c
    trunk/funcs/func_timeout.c
    trunk/include/asterisk/localtime.h
    trunk/include/asterisk/options.h
    trunk/include/asterisk/strings.h
    trunk/main/asterisk.c
    trunk/main/callerid.c
    trunk/main/cdr.c
    trunk/main/cli.c
    trunk/main/http.c
    trunk/main/loader.c
    trunk/main/logger.c
    trunk/main/manager.c
    trunk/main/pbx.c
    trunk/main/say.c
    trunk/main/stdtime/localtime.c
    trunk/main/utils.c
    trunk/res/snmp/agent.c

Modified: trunk/apps/app_alarmreceiver.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_alarmreceiver.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/apps/app_alarmreceiver.c (original)
+++ trunk/apps/app_alarmreceiver.c Wed Jul 18 14:47:20 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); 
+	ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now); 
 
 	
 	res = fprintf(logfile, "\n\n[metadata]\n\n");

Modified: trunk/apps/app_minivm.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_minivm.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/apps/app_minivm.c (original)
+++ trunk/apps/app_minivm.c Wed Jul 18 14:47:20 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);
-	ast_localtime(&t, &tm, NULL);
-	return strftime(s, len, "%a %b %e %r %Z %Y", &tm);
+	struct ast_tm tm;
+	struct timeval tv = ast_tvnow();
+
+	ast_localtime(&tv, &tm, NULL);
+	return ast_strftime(s, len, "%a %b %e %r %Z %Y", &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);
+	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 */
@@ -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);
+		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" */
@@ -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) {
@@ -2384,8 +2382,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) {
@@ -2651,7 +2649,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");
@@ -2665,11 +2663,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);
+		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");

Modified: trunk/apps/app_playback.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_playback.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/apps/app_playback.c (original)
+++ trunk/apps/app_playback.c Wed Jul 18 14:47:20 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: trunk/apps/app_rpt.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_rpt.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/apps/app_rpt.c (original)
+++ trunk/apps/app_rpt.c Wed Jul 18 14:47:20 2007
@@ -587,6 +587,7 @@
 	int i, j;
 	long long diff;
 	char a[100] = "";
+	struct ast_tm tm;
 	struct timeval lasttv;
 
 	ast_mutex_lock(&locklock);
@@ -597,8 +598,8 @@
 	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;
@@ -1890,7 +1891,7 @@
 	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
@@ -5619,7 +5620,7 @@
 static void do_scheduler(struct rpt *myrpt)
 {
 	int res;
-	struct tm tmnow;
+	struct ast_tm tmnow;
 
 	memcpy(&myrpt->lasttv, &myrpt->curtv, sizeof(struct timeval));
 	

Modified: trunk/apps/app_sms.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_sms.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/apps/app_sms.c (original)
+++ trunk/apps/app_sms.c Wed Jul 18 14:47:20 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);
+	ast_strftime(buf, len, "%Y-%m-%dT%H:%M:%S", &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
@@ -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 = 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;

Modified: trunk/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_voicemail.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/apps/app_voicemail.c (original)
+++ trunk/apps/app_voicemail.c Wed Jul 18 14:47:20 2007
@@ -1964,10 +1964,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)) {
@@ -2007,7 +2007,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;
@@ -2029,11 +2029,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));
+	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;
@@ -2214,7 +2214,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) {
@@ -2227,7 +2227,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));
+	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) {
@@ -2266,7 +2266,7 @@
 	} 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))) {
@@ -2293,11 +2293,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 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)
@@ -4472,8 +4471,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: trunk/cdr/cdr_csv.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_csv.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/cdr/cdr_csv.c (original)
+++ trunk/cdr/cdr_csv.c Wed Jul 18 14:47:20 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);
+	ast_strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
 	return append_string(buf, tmp, bufsize);
 }
 

Modified: trunk/cdr/cdr_manager.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_manager.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/cdr/cdr_manager.c (original)
+++ trunk/cdr/cdr_manager.c Wed Jul 18 14:47:20 2007
@@ -103,8 +103,7 @@
 
 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] = "";
@@ -114,19 +113,16 @@
 	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);
-	}
-
-	t = cdr->end.tv_sec;
-	ast_localtime(&t, &timeresult, NULL);
-	strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
+		ast_localtime(&cdr->answer, &timeresult, NULL);
+		ast_strftime(strAnswerTime, sizeof(strAnswerTime), 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));

Modified: trunk/cdr/cdr_odbc.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_odbc.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/cdr/cdr_odbc.c (original)
+++ trunk/cdr/cdr_odbc.c Wed Jul 18 14:47:20 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);
+	ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 	memset(sqlcmd,0,2048);
 	if (loguniqueid) {
 		snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s "

Modified: trunk/cdr/cdr_pgsql.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_pgsql.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/cdr/cdr_pgsql.c (original)
+++ trunk/cdr/cdr_pgsql.c Wed Jul 18 14:47:20 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);
+	ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 
 	if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) {
 		conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);

Modified: trunk/cdr/cdr_radius.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_radius.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/cdr/cdr_radius.c (original)
+++ trunk/cdr/cdr_radius.c Wed Jul 18 14:47:20 2007
@@ -98,7 +98,7 @@
 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;
 
@@ -143,29 +143,23 @@
 
 
 	/* 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;
 

Modified: trunk/cdr/cdr_sqlite.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_sqlite.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/cdr/cdr_sqlite.c (original)
+++ trunk/cdr/cdr_sqlite.c Wed Jul 18 14:47:20 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);
+	ast_strftime(startstr, sizeof(startstr), DATE_FORMAT, &tm);
+
+	ast_localtime(&cdr->answer, &tm, NULL);
+	ast_strftime(answerstr, sizeof(answerstr), 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,

Modified: trunk/cdr/cdr_tds.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_tds.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/cdr/cdr_tds.c (original)
+++ trunk/cdr/cdr_tds.c Wed Jul 18 14:47:20 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);
+		ast_strftime(buf, 80, DATE_FORMAT, &tm);
 		sprintf(dateField, "'%s'", buf);
 	}
 	else

Modified: trunk/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_agent.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/channels/chan_agent.c (original)
+++ trunk/channels/chan_agent.c Wed Jul 18 14:47:20 2007
@@ -1812,7 +1812,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: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Wed Jul 18 14:47:20 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 ++; 
 		}
@@ -6243,10 +6235,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 */
@@ -9898,12 +9889,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) {
@@ -9932,7 +9921,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: trunk/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_mgcp.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/channels/chan_mgcp.c (original)
+++ trunk/channels/chan_mgcp.c Wed Jul 18 14:47:20 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: trunk/channels/chan_phone.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_phone.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/channels/chan_phone.c (original)
+++ trunk/channels/chan_phone.c Wed Jul 18 14:47:20 2007
@@ -293,11 +293,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: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Wed Jul 18 14:47:20 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 */
@@ -11042,7 +11042,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)
@@ -11051,9 +11051,9 @@
 	ASTOBJ_CONTAINER_TRAVERSE(&regl, 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);
@@ -12975,7 +12975,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");
@@ -16177,7 +16177,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: trunk/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_skinny.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/channels/chan_skinny.c (original)
+++ trunk/channels/chan_skinny.c Wed Jul 18 14:47:20 2007
@@ -3735,21 +3735,21 @@
 
 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;
 }

Modified: trunk/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_zap.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/channels/chan_zap.c (original)
+++ trunk/channels/chan_zap.c Wed Jul 18 14:47:20 2007
@@ -3059,7 +3059,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);
@@ -4463,7 +4463,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:
@@ -4733,7 +4733,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);
@@ -4836,7 +4836,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);
@@ -8539,7 +8539,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) {
@@ -9302,7 +9302,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];
@@ -9319,7 +9319,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, '@');
@@ -9389,7 +9388,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: trunk/channels/iax2-parser.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/iax2-parser.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/channels/iax2-parser.c (original)
+++ trunk/channels/iax2-parser.c Wed Jul 18 14:47:20 2007
@@ -140,7 +140,7 @@
 
 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;
@@ -149,7 +149,7 @@
 		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);
 }

Modified: trunk/channels/misdn/ie.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/misdn/ie.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/channels/misdn/ie.c (original)
+++ trunk/channels/misdn/ie.c Wed Jul 18 14:47:20 2007
@@ -852,17 +852,11 @@
 	unsigned char *p;
 	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
 	int l;
-
-	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);
+	struct timeval tv = { ti, 0 };
+	struct ast_tm tm;
+
+	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);
@@ -872,11 +866,11 @@
 		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;
 }
 
 

Modified: trunk/funcs/func_strings.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_strings.c?view=diff&rev=75706&r1=75705&r2=75706
==============================================================================
--- trunk/funcs/func_strings.c (original)
+++ trunk/funcs/func_strings.c Wed Jul 18 14:47:20 2007
@@ -599,20 +599,20 @@
 			     AST_APP_ARG(timezone);
 			     AST_APP_ARG(format);
 	);
-	time_t epochi;
-	struct tm tm;

[... 2337 lines stripped ...]



More information about the asterisk-commits mailing list