mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
Add schedule extensions to app_meetme. In addition, the reporter found a
problem within strptime(3), which we are correcting here with ast_strptime(). (closes issue #11040) Reported by: DEA Patches: 20080910__bug11040.diff.txt uploaded by Corydon76 (license 14) Tested by: DEA git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@145649 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -691,10 +691,7 @@ static int acf_strptime(struct ast_channel *chan, const char *cmd, char *data,
|
||||
AST_APP_ARG(timezone);
|
||||
AST_APP_ARG(format);
|
||||
);
|
||||
union {
|
||||
struct ast_tm atm;
|
||||
struct tm time;
|
||||
} t = { { 0, }, };
|
||||
struct ast_tm tm;
|
||||
|
||||
buf[0] = '\0';
|
||||
|
||||
@@ -712,13 +709,11 @@ static int acf_strptime(struct ast_channel *chan, const char *cmd, char *data,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!strptime(args.timestring, args.format, &t.time)) {
|
||||
ast_log(LOG_WARNING, "C function strptime() output nothing?!!\n");
|
||||
if (!ast_strptime(args.timestring, args.format, &tm)) {
|
||||
ast_log(LOG_WARNING, "STRPTIME() found no time specified within the string\n");
|
||||
} else {
|
||||
struct timeval when;
|
||||
/* Since strptime(3) does not check DST, force ast_mktime() to calculate it. */
|
||||
t.atm.tm_isdst = -1;
|
||||
when = ast_mktime(&t.atm, args.timezone);
|
||||
when = ast_mktime(&tm, args.timezone);
|
||||
snprintf(buf, buflen, "%d", (int) when.tv_sec);
|
||||
}
|
||||
|
||||
|
@@ -40,9 +40,42 @@ struct ast_tm {
|
||||
int tm_usec; /*!< microseconds */
|
||||
};
|
||||
|
||||
/*!\brief Timezone-independent version of localtime_r(3).
|
||||
* \param timep Current time, including microseconds
|
||||
* \param p_tm Pointer to memory where the broken-out time will be stored
|
||||
* \param zone Text string of a standard system zoneinfo file. If NULL, the system localtime will be used.
|
||||
* \retval p_tm is returned for convenience
|
||||
*/
|
||||
struct ast_tm *ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone);
|
||||
|
||||
void ast_get_dst_info(const time_t * const timep, int *dst_enabled, time_t *dst_start, time_t *dst_end, int *gmt_off, const char * const zone);
|
||||
|
||||
/*!\brief Timezone-independent version of mktime(3).
|
||||
* \param tmp Current broken-out time, including microseconds
|
||||
* \param zone Text string of a standard system zoneinfo file. If NULL, the system localtime will be used.
|
||||
* \retval A structure containing both seconds and fractional thereof since January 1st, 1970 UTC
|
||||
*/
|
||||
struct timeval ast_mktime(struct ast_tm * const tmp, const char *zone);
|
||||
|
||||
/*!\brief Special version of strftime(3) that handles fractions of a second.
|
||||
* Takes the same arguments as strftime(3), with the addition of %q, which
|
||||
* specifies microseconds.
|
||||
* \param buf Address in memory where the resulting string will be stored.
|
||||
* \param len Size of the chunk of memory buf.
|
||||
* \param format A string specifying the format of time to be placed into buf.
|
||||
* \param tm Pointer to the broken out time to be used for the format.
|
||||
* \retval An integer value specifying the number of bytes placed into buf or -1 on error.
|
||||
*/
|
||||
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm);
|
||||
|
||||
/*!\brief Special version of strptime(3) which places the answer in the common
|
||||
* structure ast_tm. Also, unlike strptime(3), ast_strptime() initializes its
|
||||
* memory prior to use.
|
||||
* \param s A string specifying some portion of a date and time.
|
||||
* \param format The format in which the string, s, is expected.
|
||||
* \param tm The broken-out time structure into which the parsed data is expected.
|
||||
* \retval A pointer to the first character within s not used to parse the date and time.
|
||||
*/
|
||||
char *ast_strptime(const char *s, const char *format, struct ast_tm *tm);
|
||||
|
||||
#endif /* _ASTERISK_LOCALTIME_H */
|
||||
|
@@ -1819,3 +1819,15 @@ defcase: *fptr++ = *tmp;
|
||||
return res;
|
||||
}
|
||||
|
||||
char *ast_strptime(const char *s, const char *format, struct ast_tm *tm)
|
||||
{
|
||||
struct tm tm2 = { 0, };
|
||||
char *res = strptime(s, format, &tm2);
|
||||
memcpy(tm, &tm2, sizeof(*tm));
|
||||
tm->tm_usec = 0;
|
||||
/* strptime(3) doesn't set .tm_isdst correctly, so to force ast_mktime(3)
|
||||
* to deal with it correctly, we set it to -1. */
|
||||
tm->tm_isdst = -1;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user