[asterisk-commits] tilghman: branch group/ast_strftime r75031 - in /team/group/ast_strftime: app...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 13 01:23:05 CDT 2007


Author: tilghman
Date: Fri Jul 13 01:23:05 2007
New Revision: 75031

URL: http://svn.digium.com/view/asterisk?view=rev&rev=75031
Log:
Convert a few more places I initially missed to use fractional seconds for timestamps

Modified:
    team/group/ast_strftime/apps/app_rpt.c
    team/group/ast_strftime/apps/app_sms.c
    team/group/ast_strftime/cdr/cdr_radius.c
    team/group/ast_strftime/funcs/func_strings.c
    team/group/ast_strftime/funcs/func_timeout.c
    team/group/ast_strftime/main/http.c
    team/group/ast_strftime/main/say.c

Modified: team/group/ast_strftime/apps/app_rpt.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/apps/app_rpt.c?view=diff&rev=75031&r1=75030&r2=75031
==============================================================================
--- team/group/ast_strftime/apps/app_rpt.c (original)
+++ team/group/ast_strftime/apps/app_rpt.c Fri Jul 13 01:23:05 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;

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=75031&r1=75030&r2=75031
==============================================================================
--- team/group/ast_strftime/apps/app_sms.c (original)
+++ team/group/ast_strftime/apps/app_sms.c Fri Jul 13 01:23:05 2007
@@ -1194,7 +1194,7 @@
 			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((struct tm *)&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: team/group/ast_strftime/cdr/cdr_radius.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/cdr/cdr_radius.c?view=diff&rev=75031&r1=75030&r2=75031
==============================================================================
--- team/group/ast_strftime/cdr/cdr_radius.c (original)
+++ team/group/ast_strftime/cdr/cdr_radius.c Fri Jul 13 01:23:05 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: 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=75031&r1=75030&r2=75031
==============================================================================
--- team/group/ast_strftime/funcs/func_strings.c (original)
+++ team/group/ast_strftime/funcs/func_strings.c Fri Jul 13 01:23:05 2007
@@ -643,7 +643,10 @@
 			     AST_APP_ARG(timezone);
 			     AST_APP_ARG(format);
 	);
-	struct ast_tm time = { 0, };
+	union {
+		struct ast_tm atm;
+		struct tm time;
+	} t = { { 0, }, };
 
 	buf[0] = '\0';
 
@@ -661,10 +664,10 @@
 		return -1;
 	}
 
-	if (!strptime(args.timestring, args.format, (struct tm *)&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;

Modified: team/group/ast_strftime/funcs/func_timeout.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/funcs/func_timeout.c?view=diff&rev=75031&r1=75030&r2=75031
==============================================================================
--- team/group/ast_strftime/funcs/func_timeout.c (original)
+++ team/group/ast_strftime/funcs/func_timeout.c Fri Jul 13 01:23:05 2007
@@ -92,7 +92,7 @@
 {
 	int x;
 	char timestr[64];
-	struct tm myt;
+	struct ast_tm myt;
 
 	if (!chan)
 		return -1;
@@ -113,8 +113,9 @@
 		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 {

Modified: team/group/ast_strftime/main/http.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/main/http.c?view=diff&rev=75031&r1=75030&r2=75031
==============================================================================
--- team/group/ast_strftime/main/http.c (original)
+++ team/group/ast_strftime/main/http.c Fri Jul 13 01:23:05 2007
@@ -154,8 +154,9 @@
 	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. */
@@ -186,8 +187,7 @@
 	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"
@@ -843,10 +843,11 @@
 		ast_variables_destroy(vars);
 
 	if (out) {
-		time_t t = time(NULL);
+		struct timeval tv = ast_tvnow();
 		char timebuf[256];
-
-		strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
+		struct ast_tm tm;
+
+		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"

Modified: team/group/ast_strftime/main/say.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/main/say.c?view=diff&rev=75031&r1=75030&r2=75031
==============================================================================
--- team/group/ast_strftime/main/say.c (original)
+++ team/group/ast_strftime/main/say.c Fri Jul 13 01:23:05 2007
@@ -3362,13 +3362,13 @@
 				{
 					struct timeval now = ast_tvnow();
 					struct ast_tm tmnow;
-					time_t beg_today, tt;
+					time_t beg_today;
 
 					gettimeofday(&now,NULL);
 					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);
@@ -3398,13 +3398,13 @@
 				{
 					struct timeval now;
 					struct ast_tm tmnow;
-					time_t beg_today, tt;
+					time_t beg_today;
 
 					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) {
@@ -5465,12 +5465,12 @@
 				{
 					struct timeval now = ast_tvnow();
 					struct ast_tm tmnow;
-					time_t beg_today, tt;
+					time_t beg_today;
 
 					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);




More information about the asterisk-commits mailing list