From a667908c0fae9eeb7677f2e17ee832c39c64306b Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Wed, 28 Jan 2015 14:07:53 +0100 Subject: [PATCH] MT#10879 Try fallback to uuid for mailbox search. --- apps/app_voicemail.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 3358f87..7549343 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -2862,6 +2862,9 @@ static struct ast_vm_user *find_user_realtime_by_alias(struct ast_vm_user *ivm, "left join provisioning.voip_dbaliases vda on pvs.id = vda.subscriber_id " \ "where vda.username = ?"; struct generic_prepare_struct gps = { .sql = sql, .argc = 1, .argv = argv }; + char *sql_uuid = "select distinct(mailbox) from kamailio.voicemail_users "\ + "where mailbox = ? and customer_id = mailbox"; + struct generic_prepare_struct gps_uuid = { .sql = sql_uuid, .argc = 1, .argv = argv }; struct odbc_obj *obj = NULL; SQLHSTMT stmt = NULL; @@ -2874,10 +2877,23 @@ static struct ast_vm_user *find_user_realtime_by_alias(struct ast_vm_user *ivm, } res = SQLFetch(stmt); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(LOG_NOTICE, "Failed to fetch mailbox for alias '%s'\n", alias); + ast_log(LOG_NOTICE, "Failed to fetch mailbox for alias '%s', falling back to uuid search\n", alias); SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - return NULL; + + stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps_uuid); + if (!stmt) { + ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql_uuid); + ast_odbc_release_obj(obj); + return NULL; + } + res = SQLFetch(stmt); + if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { + ast_log(LOG_NOTICE, "Failed to fetch mailbox for alias '%s' via uuid\n", alias); + SQLFreeHandle (SQL_HANDLE_STMT, stmt); + + ast_odbc_release_obj(obj); + return NULL; + } } res = SQLGetData(stmt, 1, SQL_CHAR, mailbox, sizeof(mailbox), NULL); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {