From: Sipwise Development Team Date: Mon, 21 Feb 2022 14:17:23 +0100 Subject: sipwise_vm_ext_timezone --- apps/app_voicemail.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index f26bbfa..f9a9d1d 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -948,6 +948,8 @@ static int passwordlocation; static char aliasescontext[MAX_VM_CONTEXT_LEN]; static char sw_normalize_user_match[256]; static char sw_normalize_user_replace[256]; +static char sw_timezone_table[256]; +static char sw_default_timezone[80]; /*! Poll mailboxes for changes since there is something external to * app_voicemail that may change them. */ @@ -1092,6 +1094,7 @@ static int vm_msg_remove(const char *mailbox, const char *context, size_t num_ms static int vm_msg_play(struct ast_channel *chan, const char *mailbox, const char *context, const char *folder, const char *msg_num, ast_vm_msg_play_cb cb); static struct vm_zone *get_vmu_timezone(struct ast_vm_user *vmu); +static void load_vmu_timezone(struct ast_vm_user *vmu); #ifdef TEST_FRAMEWORK static int vm_test_destroy_user(const char *context, const char *mailbox); @@ -1707,6 +1710,8 @@ static void apply_options_full(struct ast_vm_user *retval, struct ast_variable * } else if (!strcasecmp(var->name, "mailbox")) { /* granig: but save number for announcement */ ast_copy_string(retval->dialed_num, var->value, sizeof(retval->dialed_num)); // ast_log (LOG_DEBUG,"setting dialed_num to '%s'\n", var->value); + } else if (!strcasecmp(var->name, "tz")) { + load_vmu_timezone(retval); #ifdef IMAP_STORAGE } else if (!strcasecmp(var->name, "imapuser")) { ast_copy_string(retval->imapuser, var->value, sizeof(retval->imapuser)); @@ -8076,6 +8081,58 @@ static struct vm_zone * get_vmu_timezone(struct ast_vm_user *vmu) return tz; } +static void load_vmu_timezone(struct ast_vm_user *vmu) +{ + int res; + char *argv[] = { vmu->mailbox }; + char sql[PATH_MAX]; + struct generic_prepare_struct gps = { .sql = sql, .argc = 1, .argv = argv }; + struct odbc_obj *obj = NULL; + SQLHSTMT stmt = NULL; + + if (vmu->mailbox == NULL || ast_strlen_zero(sw_timezone_table)) + return; + + snprintf(sql, sizeof(sql), + "select name from %s where uuid = ?", sw_timezone_table); + + obj = ast_odbc_request_obj(odbc_database, 0); + stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); + if (!stmt) { + ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); + ast_odbc_release_obj(obj); + return; + } + res = SQLFetch(stmt); + if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { + ast_log(LOG_NOTICE, "Failed to timezone for mailbox '%s'\n", vmu->mailbox); + SQLFreeHandle (SQL_HANDLE_STMT, stmt); + + ast_odbc_release_obj(obj); + return; + } + res = SQLGetData(stmt, 1, SQL_CHAR, vmu->zonetag, sizeof(vmu->zonetag), NULL); + if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { + if (ast_strlen_zero(sw_default_timezone)) { + ast_log(LOG_DEBUG, + "Undefined timezone for mailbox '%s', local will be used\n", + vmu->mailbox); + ast_copy_string(vmu->zonetag, "", sizeof(vmu->zonetag)); + } else { + ast_log(LOG_DEBUG, + "Using default timezone '%s' for mailbox '%s' \n", + sw_default_timezone, vmu->mailbox); + ast_copy_string(vmu->zonetag, sw_default_timezone, sizeof(vmu->zonetag)); + } + } else { + ast_log(LOG_DEBUG, "Using timezeone '%s' for mailbox '%s'\n", vmu->zonetag, vmu->mailbox); + } + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + ast_odbc_release_obj(obj); + + return; +} + /*! * \brief Sends email notification that a user has a new voicemail waiting for them. * \param chan @@ -13324,6 +13381,9 @@ static int actual_load_config(int reload, struct ast_config *cfg, struct ast_con long tps_queue_high; const char *ast_sw_normalize_user_match = NULL; const char *ast_sw_normalize_user_replace = NULL; + const char *ast_sw_timezone_table = NULL; + const char *ast_sw_default_timezone = NULL; + #ifdef IMAP_STORAGE ast_copy_string(imapparentfolder, "\0", sizeof(imapparentfolder)); @@ -13401,6 +13461,13 @@ static int actual_load_config(int reload, struct ast_config *cfg, struct ast_con sw_normalize_user_replace[0] = '\0'; } + /* sipwise timezone table */ + if ((ast_sw_timezone_table = ast_variable_retrieve(cfg, "general", "sw_timezone_table"))) + ast_copy_string(sw_timezone_table, ast_sw_timezone_table, sizeof(sw_timezone_table)); + /* sipwise default timezone */ + if ((ast_sw_default_timezone = ast_variable_retrieve(cfg, "general", "sw_default_timezone"))) + ast_copy_string(sw_default_timezone, ast_sw_default_timezone, sizeof(sw_default_timezone)); + /* Mail command */ strcpy(mailcmd, SENDMAIL); if ((val = ast_variable_retrieve(cfg, "general", "mailcmd")))