*/
SWITCH_DECLARE(switch_status_t) switch_strftime(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm);
+/**
+ * formats the exploded time according to the format specified (does not validate format string)
+ * @param s string to write to
+ * @param retsize The length of the returned string
+ * @param max The maximum length of the string
+ * @param format The format for the time string
+ * @param tm The time to convert
+ */
+SWITCH_DECLARE(switch_status_t) switch_strftime_nocheck(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm);
+
/**
* switch_rfc822_date formats dates in the RFC822
* format in an efficient manner. It is a fixed length
thetime = switch_timestamp_now();
}
switch_time_exp_lt(&tm, thetime);
- switch_strftime(date, &retsize, sizeof(date), switch_strlen_zero(cmd) ? "%Y-%m-%d %T" : cmd, &tm);
+ if (switch_strlen_zero(cmd)) {
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ } else {
+ switch_strftime(date, &retsize, sizeof(date), cmd, &tm);
+ }
stream->write_function(stream, "%s", date);
return SWITCH_STATUS_SUCCESS;
ts = switch_timestamp_now();
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_channel_set_variable(channel, "fifo_status", "WAITING");
switch_channel_set_variable(channel, "fifo_timestamp", date);
} else {
ts = switch_timestamp_now();
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_channel_set_variable(channel, "fifo_status", cd.do_orbit ? "TIMEOUT" : "ABORTED");
switch_channel_set_variable(channel, "fifo_timestamp", date);
ts = switch_timestamp_now();
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_channel_set_variable(channel, "fifo_status", "WAITING");
switch_channel_set_variable(channel, "fifo_timestamp", date);
ts = switch_timestamp_now();
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_channel_set_variable(channel, "fifo_status", "TALKING");
switch_channel_set_variable(channel, "fifo_target", uuid);
switch_channel_set_variable(channel, "fifo_timestamp", date);
ts = switch_timestamp_now();
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_channel_set_variable(channel, "fifo_status", "WAITING");
switch_channel_set_variable(channel, "fifo_timestamp", date);
char dtmf[5] = "";
switch_time_exp_lt(&tm, switch_timestamp_now());
- switch_strftime(date, &retsize, sizeof(date), "%I:%M %p", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%I:%M %p", &tm);
switch_snprintf(buf, sizeof(buf),
free(dbuf);
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_channel_set_variable(channel, "RECORD_DATE", date);
switch_channel_set_variable(channel, "RECORD_SOFTWARE", "FreeSWITCH");
switch_channel_set_variable(channel, "RECORD_TITLE", profile->record_title);
if (l_created) {
switch_time_exp_lt(&tm, l_created);
- switch_strftime(create_date, &retsize, sizeof(create_date), fmt, &tm);
- switch_strftime(rss_date, &retsize, sizeof(create_date), "%D %T", &tm);
+ switch_strftime_nocheck(create_date, &retsize, sizeof(create_date), fmt, &tm);
+ switch_strftime_nocheck(rss_date, &retsize, sizeof(create_date), "%D %T", &tm);
}
if (l_read) {
switch_time_exp_lt(&tm, l_read);
- switch_strftime(read_date, &retsize, sizeof(read_date), fmt, &tm);
+ switch_strftime_nocheck(read_date, &retsize, sizeof(read_date), fmt, &tm);
}
switch_snprintf(heard, sizeof(heard), *read_date == '\0' ? "never" : read_date);
if (l_created) {
switch_time_exp_lt(&tm, l_created);
- switch_strftime(create_date, &retsize, sizeof(create_date), fmt, &tm);
- switch_strftime(rss_date, &retsize, sizeof(create_date), fmt, &tm);
+ switch_strftime_nocheck(create_date, &retsize, sizeof(create_date), fmt, &tm);
+ switch_strftime_nocheck(rss_date, &retsize, sizeof(create_date), fmt, &tm);
}
if (l_read) {
switch_time_exp_lt(&tm, l_read);
- switch_strftime(read_date, &retsize, sizeof(read_date), fmt, &tm);
+ switch_strftime_nocheck(read_date, &retsize, sizeof(read_date), fmt, &tm);
}
holder->x_item = switch_xml_add_child_d(holder->x_channel, "item", holder->items++);
switch_size_t retsize;
switch_time_exp_lt(&tm, switch_time_from_sec(etime));
- switch_strftime(exp_buf, &retsize, sizeof(exp_buf), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(exp_buf, &retsize, sizeof(exp_buf), "%Y-%m-%d %T", &tm);
}
cb->stream->write_function(cb->stream,
if (globals.rotate) {
switch_time_exp_lt(&tm, switch_timestamp_now());
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
len = strlen(fd->path) + strlen(date) + 2;
p = switch_mprintf("%s.%s", fd->path, date);
switch_mutex_lock(globals.mutex);
switch_time_exp_lt(&tm, switch_timestamp_now());
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
profile->log_size = 0;
/* string functions */
SWITCH_DECLARE(switch_status_t) switch_strftime(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
+{
+ const char *p = format;
+
+ if (!p) return SWITCH_STATUS_FALSE;
+
+ while (*p) {
+ if (*p == '%') {
+ switch (*(++p)) {
+ case 'C':
+ case 'D':
+ case 'r':
+ case 'R':
+ case 'T':
+ case 'e':
+ case 'a':
+ case 'A':
+ case 'b':
+ case 'B':
+ case 'c':
+ case 'd':
+ case 'H':
+ case 'I':
+ case 'j':
+ case 'm':
+ case 'M':
+ case 'p':
+ case 'S':
+ case 'U':
+ case 'w':
+ case 'W':
+ case 'x':
+ case 'X':
+ case 'y':
+ case 'Y':
+ case 'z':
+ case 'Z':
+ case '%':
+ p++;
+ continue;
+ case '\0':
+ default:
+ return SWITCH_STATUS_FALSE;
+ }
+ }
+ p++;
+ }
+
+ return apr_strftime(s, retsize, max, format, (apr_time_exp_t *) tm);
+}
+
+SWITCH_DECLARE(switch_status_t) switch_strftime_nocheck(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
{
return apr_strftime(s, retsize, max, format, (apr_time_exp_t *) tm);
}
cid_buf = caller_profile->caller_id_number;
}
-
if (caller_profile->times) {
switch_time_exp_t tm;
switch_size_t retsize;
const char *fmt = "%Y-%m-%d %T";
switch_time_exp_lt(&tm, caller_profile->times->created);
- switch_strftime(start, &retsize, sizeof(start), fmt, &tm);
+ switch_strftime_nocheck(start, &retsize, sizeof(start), fmt, &tm);
switch_channel_set_variable(channel, "start_stamp", start);
switch_time_exp_lt(&tm, caller_profile->times->profile_created);
- switch_strftime(profile_start, &retsize, sizeof(profile_start), fmt, &tm);
+ switch_strftime_nocheck(profile_start, &retsize, sizeof(profile_start), fmt, &tm);
switch_channel_set_variable(channel, "profile_start_stamp", profile_start);
if (caller_profile->times->answered) {
switch_time_exp_lt(&tm, caller_profile->times->answered);
- switch_strftime(answer, &retsize, sizeof(answer), fmt, &tm);
+ switch_strftime_nocheck(answer, &retsize, sizeof(answer), fmt, &tm);
switch_channel_set_variable(channel, "answer_stamp", answer);
}
if (caller_profile->times->progress) {
switch_time_exp_lt(&tm, caller_profile->times->progress);
- switch_strftime(progress, &retsize, sizeof(progress), fmt, &tm);
+ switch_strftime_nocheck(progress, &retsize, sizeof(progress), fmt, &tm);
switch_channel_set_variable(channel, "progress_stamp", progress);
}
if (caller_profile->times->progress_media) {
switch_time_exp_lt(&tm, caller_profile->times->progress_media);
- switch_strftime(progress_media, &retsize, sizeof(progress_media), fmt, &tm);
+ switch_strftime_nocheck(progress_media, &retsize, sizeof(progress_media), fmt, &tm);
switch_channel_set_variable(channel, "progress_media_stamp", progress_media);
}
switch_time_exp_lt(&tm, caller_profile->times->hungup);
- switch_strftime(end, &retsize, sizeof(end), fmt, &tm);
+ switch_strftime_nocheck(end, &retsize, sizeof(end), fmt, &tm);
switch_channel_set_variable(channel, "end_stamp", end);
tt_created = (time_t) (caller_profile->times->created / 1000000);
}
switch_time_exp_lt(&tm, switch_timestamp_now());
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
if (channel == SWITCH_CHANNEL_ID_LOG) {
fprintf(handle, "[%d] %s %s:%d %s() %s", (int) getpid(), date, filep, line, func, data);
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "FreeSWITCH-IPv6", guess_ip_v6);
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Date-Local", date);
switch_rfc822_date(date, ts);
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Date-GMT", date);
switch_time_exp_t tm;
switch_time_exp_lt(&tm, now);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
len = (uint32_t) (strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(funcp) + strlen(fmt));
new_fmt = malloc(len + 1);
if (tzdef) { /* The lookup of the zone may fail. */
tztime( &timep, tzdef, &tm );
tm2switchtime( &tm, &stm );
- switch_strftime(date, &retsize, len, switch_strlen_zero(format) ? "%Y-%m-%d %T" : format, &stm);
+ switch_strftime_nocheck(date, &retsize, len, switch_strlen_zero(format) ? "%Y-%m-%d %T" : format, &stm);
if (!switch_strlen_zero_buf(date)) {
return SWITCH_STATUS_SUCCESS;
}