You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
asterisk-voicemail/debian/patches/sipwise_vm_app_playback_tim...

89 lines
2.8 KiB

From: Sipwise Development Team <support@sipwise.com>
Date: Mon, 21 Feb 2022 14:17:23 +0100
Subject: sipwise_vm_app_playback_timezone
---
apps/app_playback.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/apps/app_playback.c b/apps/app_playback.c
index 613e8c8..0a73b39 100644
--- a/apps/app_playback.c
+++ b/apps/app_playback.c
@@ -244,6 +244,15 @@ static int do_say(say_args_t *a, const char *s, const char *options, int depth)
}
AST_LIST_INSERT_HEAD(&head, n, entries);
+ if (options) {
+ n = ast_var_assign("SAY_WHEN", options);
+ if (!n) {
+ ast_log(LOG_ERROR, "Memory allocation error in do_say\n");
+ return -1;
+ }
+ AST_LIST_INSERT_HEAD(&head, n, entries);
+ }
+
/* scan the body, one piece at a time */
while ( !ret && (x = strsep(&rule, ",")) ) { /* exit on key */
char fn[128];
@@ -257,6 +266,15 @@ static int do_say(say_args_t *a, const char *s, const char *options, int depth)
pbx_substitute_variables_varshead(&head, x, fn, sizeof(fn));
ast_debug(2, "doing [%s]\n", fn);
+ /* remove double quotes from possible expressions */
+ int pos = 0, offset = 0;
+ while(fn[pos] != '\0') {
+ if (fn[pos] != '"')
+ fn[offset++] = fn[pos];
+ pos++;
+ }
+ fn[offset] = '\0';
+
/* locate prefix and data, if any */
fmt = strchr(fn, ':');
if (!fmt || fmt == fn) { /* regular filename */
@@ -340,10 +358,34 @@ static int say_date_generic(struct ast_channel *chan, time_t t,
struct ast_tm tm;
struct timeval when = { t, 0 };
say_args_t a = { chan, ints, lang, -1, -1 };
+ struct timeval now;
+ struct ast_tm tmnow;
+ time_t beg_today;
+ char when_fmt[16] = "";
+
if (format == NULL)
format = "";
ast_localtime(&when, &tm, timezonename);
+
+ now = ast_tvnow();
+ ast_localtime(&now, &tmnow, timezonename);
+ /* 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 = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
+ if (beg_today < t)
+ strcpy(when_fmt, "today");
+ else if ((beg_today - 86400) < t)
+ strcpy(when_fmt, "yday");
+ else if (beg_today - 86400 * 6 < t)
+ strcpy(when_fmt, "ltweek");
+ else if (beg_today - 2628000 < t)
+ strcpy(when_fmt, "ltmonth");
+ else if (beg_today - 15768000 < t)
+ strcpy(when_fmt, "ltyear");
+ else
+ strcpy(when_fmt, "gtyear");
+
snprintf(buf, sizeof(buf), "%s:%s:%04d%02d%02d%02d%02d.%02d-%d-%3d",
prefix,
format,
@@ -355,7 +397,7 @@ static int say_date_generic(struct ast_channel *chan, time_t t,
tm.tm_sec,
tm.tm_wday,
tm.tm_yday);
- return do_say(&a, buf, NULL, 0);
+ return do_say(&a, buf, when_fmt, 0);
}
static int say_date_with_format(struct ast_channel *chan, time_t t,