mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 10:47:18 +00:00 
			
		
		
		
	Merge in ast_strftime branch, which changes timestamps to be accurate to the microsecond, instead of only to the second
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@75706 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
		| @@ -599,20 +599,20 @@ static int acf_strftime(struct ast_channel *chan, const char *cmd, char *parse, | ||||
| 			     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'; | ||||
| @@ -624,6 +624,14 @@ static struct ast_custom_function strftime_function = { | ||||
| 	.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, | ||||
| }; | ||||
|  | ||||
| @@ -635,9 +643,10 @@ static int acf_strptime(struct ast_channel *chan, const char *cmd, char *data, | ||||
| 			     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'; | ||||
|  | ||||
| @@ -655,10 +664,10 @@ static int acf_strptime(struct ast_channel *chan, const char *cmd, char *data, | ||||
| 		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; | ||||
|   | ||||
| @@ -92,7 +92,7 @@ static int timeout_write(struct ast_channel *chan, const char *cmd, char *data, | ||||
| { | ||||
| 	int x; | ||||
| 	char timestr[64]; | ||||
| 	struct tm myt; | ||||
| 	struct ast_tm myt; | ||||
|  | ||||
| 	if (!chan) | ||||
| 		return -1; | ||||
| @@ -113,8 +113,9 @@ static int timeout_write(struct ast_channel *chan, const char *cmd, char *data, | ||||
| 		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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user