mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-07 02:18:15 +00:00
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@224450 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -4462,16 +4462,15 @@ static void free_zone(struct vm_zone *z)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ODBC_STORAGE
|
#ifdef ODBC_STORAGE
|
||||||
/*! XXX \todo Fix this function to support multiple mailboxes in the intput string */
|
|
||||||
static int inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
|
static int inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
|
||||||
{
|
{
|
||||||
int x = -1;
|
int x = -1;
|
||||||
int res;
|
int res;
|
||||||
SQLHSTMT stmt;
|
SQLHSTMT stmt = NULL;
|
||||||
char sql[PATH_MAX];
|
char sql[PATH_MAX];
|
||||||
char rowdata[20];
|
char rowdata[20];
|
||||||
char tmp[PATH_MAX] = "";
|
char tmp[PATH_MAX] = "";
|
||||||
struct odbc_obj *obj;
|
struct odbc_obj *obj = NULL;
|
||||||
char *context;
|
char *context;
|
||||||
struct generic_prepare_struct gps = { .sql = sql, .argc = 0 };
|
struct generic_prepare_struct gps = { .sql = sql, .argc = 0 };
|
||||||
|
|
||||||
@@ -4488,6 +4487,26 @@ static int inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *
|
|||||||
|
|
||||||
ast_copy_string(tmp, mailbox, sizeof(tmp));
|
ast_copy_string(tmp, mailbox, sizeof(tmp));
|
||||||
|
|
||||||
|
if (strchr(mailbox, ' ') || strchr(mailbox, ',')) {
|
||||||
|
int u, n, o;
|
||||||
|
char *next, *remaining = tmp;
|
||||||
|
while ((next = strsep(&remaining, " ,"))) {
|
||||||
|
if (inboxcount2(next, urgentmsgs ? &u : NULL, &n, &o)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (urgentmsgs) {
|
||||||
|
*urgentmsgs += u;
|
||||||
|
}
|
||||||
|
if (newmsgs) {
|
||||||
|
*newmsgs += n;
|
||||||
|
}
|
||||||
|
if (oldmsgs) {
|
||||||
|
*oldmsgs += o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
context = strchr(tmp, '@');
|
context = strchr(tmp, '@');
|
||||||
if (context) {
|
if (context) {
|
||||||
*context = '\0';
|
*context = '\0';
|
||||||
@@ -4495,91 +4514,80 @@ static int inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *
|
|||||||
} else
|
} else
|
||||||
context = "default";
|
context = "default";
|
||||||
|
|
||||||
obj = ast_odbc_request_obj(odbc_database, 0);
|
if ((obj = ast_odbc_request_obj(odbc_database, 0))) {
|
||||||
if (obj) {
|
do {
|
||||||
|
if (newmsgs) {
|
||||||
snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, tmp, "INBOX");
|
snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, tmp, "INBOX");
|
||||||
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
|
if (!(stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps))) {
|
||||||
if (!stmt) {
|
|
||||||
ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
|
ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
|
||||||
ast_odbc_release_obj(obj);
|
break;
|
||||||
goto yuck;
|
|
||||||
}
|
}
|
||||||
res = SQLFetch(stmt);
|
res = SQLFetch(stmt);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
break;
|
||||||
ast_odbc_release_obj(obj);
|
|
||||||
goto yuck;
|
|
||||||
}
|
}
|
||||||
res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
|
res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
break;
|
||||||
ast_odbc_release_obj(obj);
|
|
||||||
goto yuck;
|
|
||||||
}
|
}
|
||||||
*newmsgs = atoi(rowdata);
|
*newmsgs = atoi(rowdata);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldmsgs) {
|
||||||
snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, tmp, "Old");
|
snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, tmp, "Old");
|
||||||
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
|
if (!(stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps))) {
|
||||||
if (!stmt) {
|
|
||||||
ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
|
ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
|
||||||
ast_odbc_release_obj(obj);
|
break;
|
||||||
goto yuck;
|
|
||||||
}
|
}
|
||||||
res = SQLFetch(stmt);
|
res = SQLFetch(stmt);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
break;
|
||||||
ast_odbc_release_obj(obj);
|
|
||||||
goto yuck;
|
|
||||||
}
|
}
|
||||||
res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
|
res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
break;
|
||||||
ast_odbc_release_obj(obj);
|
|
||||||
goto yuck;
|
|
||||||
}
|
}
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||||
*oldmsgs = atoi(rowdata);
|
*oldmsgs = atoi(rowdata);
|
||||||
|
|
||||||
if (!urgentmsgs) {
|
|
||||||
x = 0;
|
|
||||||
ast_odbc_release_obj(obj);
|
|
||||||
goto yuck;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (urgentmsgs) {
|
||||||
snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, tmp, "Urgent");
|
snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, tmp, "Urgent");
|
||||||
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
|
if (!(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_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
|
||||||
ast_odbc_release_obj(obj);
|
break;
|
||||||
goto yuck;
|
|
||||||
}
|
}
|
||||||
res = SQLFetch(stmt);
|
res = SQLFetch(stmt);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
break;
|
||||||
ast_odbc_release_obj(obj);
|
|
||||||
goto yuck;
|
|
||||||
}
|
}
|
||||||
res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
|
res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
break;
|
||||||
ast_odbc_release_obj(obj);
|
|
||||||
goto yuck;
|
|
||||||
}
|
}
|
||||||
*urgentmsgs = atoi(rowdata);
|
*urgentmsgs = atoi(rowdata);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
}
|
||||||
ast_odbc_release_obj(obj);
|
|
||||||
x = 0;
|
x = 0;
|
||||||
} else
|
} while (0);
|
||||||
ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
|
} else {
|
||||||
|
ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stmt) {
|
||||||
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
|
}
|
||||||
|
if (obj) {
|
||||||
|
ast_odbc_release_obj(obj);
|
||||||
|
}
|
||||||
|
|
||||||
yuck:
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user