TT#44177 fix store_file ODBC object connection

* store_file uses direct ODBC commands instead of
      ast_odbc_prepare_and_execute, and therefore,
      no checks if the ODBC object is not connected anymore.
      the connection object is now checked if it is actually
      connected before issuing the store message SQL.

Change-Id: I0d6b607728c22948b88013225c07af516905d3cc
changes/63/26863/3
Kirill Solomko 7 years ago
parent 869f32d952
commit 8a4d09540e

@ -19,3 +19,4 @@ sipwise_vm_find_user_by_alias_prio_uuid.patch
sipwise_vm_ast_load_realtime_use_uuid.patch
sipwise_vm_fix_odbc_retreive_file.patch
sipwise_fix_chan_usage.patch
sipwise_vm_store_message_reconnect.patch

@ -0,0 +1,51 @@
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -4488,6 +4488,22 @@
struct insert_data *data = vdata;
int res;
SQLHSTMT stmt;
+ char sql[PATH_MAX];
+ char *argv[] = {};
+ struct generic_prepare_struct gps = { .sql = sql, .argc = 0, .argv = argv };
+
+ SQLSMALLINT msg_len = 0;
+ SQLCHAR sql_state[6], message[256];
+ SQLINTEGER native_error = 0;
+
+ snprintf(sql, sizeof(sql), "SELECT 1");
+ stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
+ if (!stmt) {
+ ast_log(AST_LOG_WARNING, "SQL Server has gone away\n");
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+ return NULL;
+ }
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
@@ -4516,7 +4532,8 @@
}
res = SQLExecDirect(stmt, (unsigned char *) data->sql, SQL_NTS);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(AST_LOG_WARNING, "SQL Direct Execute failed!\n");
+ res = SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, sql_state, &native_error, message, sizeof(message), &msg_len);
+ ast_log(AST_LOG_WARNING, "SQL Direct Execute failed: code: %d msg: %s!\n", (int)native_error, message);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
return NULL;
}
@@ -4638,7 +4655,14 @@
if ((stmt = ast_odbc_direct_execute(obj, insert_data_cb, &idata))) {
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
} else {
- ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
+ ast_log(AST_LOG_WARNING, "SQL Execute error!\n");
+/*
+ if (!ast_strlen_zero(idata.category)) {
+ ast_log(AST_LOG_WARNING, "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext,flag,msg_id,category) VALUES (%s,%s,<recording>,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", odbc_table, idata.dir, idata.msgnums, idata.context, idata.macrocontext, idata.callerid, idata.origtime, idata.duration, idata.mailboxuser, idata.mailboxcontext, idata.flag, idata.msg_id, idata.category);
+ } else {
+ ast_log(AST_LOG_WARNING, "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext,flag,msg_id) VALUES (%s,%s,<recording>,%s,%s,%s,%s,%s,%s,%s,%s,%s)", odbc_table, idata.dir, idata.msgnums, idata.context, idata.macrocontext, idata.callerid, idata.origtime, idata.duration, idata.mailboxuser, idata.mailboxcontext, idata.flag, idata.msg_id);
+ }
+*/
res = -1;
}
} while (0);
Loading…
Cancel
Save