dect
/
asterisk
Archived
13
0
Fork 0

move ODBC API into ast_ namespace

git-svn-id: http://svn.digium.com/svn/asterisk/trunk@43311 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
kpfleming 2006-09-20 04:57:20 +00:00
parent 7b3a5c9a1a
commit 99788749f1
4 changed files with 60 additions and 60 deletions

View File

@ -119,7 +119,7 @@ static int acf_odbc_write(struct ast_channel *chan, char *cmd, char *s, const ch
return -1;
}
obj = odbc_request_obj(query->dsn, 0);
obj = ast_odbc_request_obj(query->dsn, 0);
if (!obj) {
ast_log(LOG_ERROR, "No database handle available with the name of '%s' (check res_odbc.conf)\n", query->dsn);
@ -169,7 +169,7 @@ static int acf_odbc_write(struct ast_channel *chan, char *cmd, char *s, const ch
AST_LIST_UNLOCK(&queries);
stmt = odbc_prepare_and_execute(obj, generic_prepare, buf);
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, buf);
if (stmt) {
/* Rows affected */
@ -186,7 +186,7 @@ static int acf_odbc_write(struct ast_channel *chan, char *cmd, char *s, const ch
if (stmt)
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
if (obj)
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return 0;
}
@ -217,7 +217,7 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf
return -1;
}
obj = odbc_request_obj(query->dsn, 0);
obj = ast_odbc_request_obj(query->dsn, 0);
if (!obj) {
ast_log(LOG_ERROR, "No such DSN registered (or out of connections): %s (check res_odbc.conf)\n", query->dsn);
@ -244,10 +244,10 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf
AST_LIST_UNLOCK(&queries);
stmt = odbc_prepare_and_execute(obj, generic_prepare, sql);
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, sql);
if (!stmt) {
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return -1;
}
@ -255,7 +255,7 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return -1;
}
@ -273,7 +273,7 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf
ast_log(LOG_WARNING, "Error %d in FETCH [%s]\n", res, sql);
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return res1;
}
@ -291,7 +291,7 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return -1;
}
@ -316,7 +316,7 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf
buf[buflen - 1] = '\0';
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return 0;
}

View File

@ -60,7 +60,7 @@ struct odbc_obj {
* This function really only ever worked with MySQL, where the statement handle is
* not prepared on the server. If you are not using MySQL, you should avoid it.
*/
int odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt); /* DEPRECATED */
int ast_odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt); /* DEPRECATED */
/*! \brief Retrieves a connected ODBC object
* \param name The name of the ODBC class for which a connection is needed.
@ -72,18 +72,18 @@ int odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt); /* DEPRECATED */
* thread which requests it. Note that all connections should be released
* when the thread is done by calling odbc_release_obj(), below.
*/
struct odbc_obj *odbc_request_obj(const char *name, int check);
struct odbc_obj *ast_odbc_request_obj(const char *name, int check);
/*! \brief Releases an ODBC object previously allocated by odbc_request_obj()
* \param obj The ODBC object
*/
void odbc_release_obj(struct odbc_obj *obj);
void ast_odbc_release_obj(struct odbc_obj *obj);
/*! \brief Checks an ODBC object to ensure it is still connected
* \param obj The ODBC object
* \return Returns 0 if connected, -1 otherwise.
*/
int odbc_sanity_check(struct odbc_obj *obj);
int ast_odbc_sanity_check(struct odbc_obj *obj);
/*! \brief Prepares, executes, and returns the resulting statement handle.
* \param obj The ODBC object
@ -91,6 +91,6 @@ int odbc_sanity_check(struct odbc_obj *obj);
* \param data A parameter to be passed to the prepare_cb parameter function, indicating which statement handle is to be prepared.
* \return Returns a statement handle or NULL on error.
*/
SQLHSTMT odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data);
SQLHSTMT ast_odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data);
#endif /* _ASTERISK_RES_ODBC_H */

View File

@ -81,21 +81,21 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
if (!table)
return NULL;
obj = odbc_request_obj(database, 0);
obj = ast_odbc_request_obj(database, 0);
if (!obj)
return NULL;
res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
newparam = va_arg(aq, const char *);
if (!newparam) {
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
newval = va_arg(aq, const char *);
@ -111,7 +111,7 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
@ -123,12 +123,12 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
SQLBindParameter(stmt, x++, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(newval), 0, (void *)newval, 0, NULL);
}
res = odbc_smart_execute(obj, stmt);
res = ast_odbc_smart_execute(obj, stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
@ -136,20 +136,20 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
res = SQLFetch(stmt);
if (res == SQL_NO_DATA) {
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
for (x = 0; x < colcount; x++) {
@ -161,7 +161,7 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
if (var)
ast_variables_destroy(var);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
@ -174,7 +174,7 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
if (var)
ast_variables_destroy(var);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
stringp = rowdata;
@ -194,7 +194,7 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return var;
}
@ -232,21 +232,21 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
return NULL;
memset(&ra, 0, sizeof(ra));
obj = odbc_request_obj(database, 0);
obj = ast_odbc_request_obj(database, 0);
if (!obj)
return NULL;
res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
newparam = va_arg(aq, const char *);
if (!newparam) {
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
initfield = ast_strdupa(newparam);
@ -267,7 +267,7 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
@ -279,12 +279,12 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
SQLBindParameter(stmt, x++, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(newval), 0, (void *)newval, 0, NULL);
}
res = odbc_smart_execute(obj, stmt);
res = ast_odbc_smart_execute(obj, stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
@ -292,7 +292,7 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
@ -300,7 +300,7 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
if (!cfg) {
ast_log(LOG_WARNING, "Out of memory!\n");
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
@ -351,7 +351,7 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return cfg;
}
@ -371,21 +371,21 @@ static int update_odbc(const char *database, const char *table, const char *keyf
if (!table)
return -1;
obj = odbc_request_obj(database, 0);
obj = ast_odbc_request_obj(database, 0);
if (!obj)
return -1;
res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return -1;
}
newparam = va_arg(aq, const char *);
if (!newparam) {
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return -1;
}
newval = va_arg(aq, const char *);
@ -401,7 +401,7 @@ static int update_odbc(const char *database, const char *table, const char *keyf
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return -1;
}
@ -415,18 +415,18 @@ static int update_odbc(const char *database, const char *table, const char *keyf
SQLBindParameter(stmt, x++, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(lookup), 0, (void *)lookup, 0, NULL);
res = odbc_smart_execute(obj, stmt);
res = ast_odbc_smart_execute(obj, stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return -1;
}
res = SQLRowCount(stmt, &rowcount);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
@ -503,18 +503,18 @@ static struct ast_config *config_odbc(const char *database, const char *table, c
if (!file || !strcmp (file, "res_config_odbc.conf"))
return NULL; /* cant configure myself with myself ! */
obj = odbc_request_obj(database, 0);
obj = ast_odbc_request_obj(database, 0);
if (!obj)
return NULL;
snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE filename='%s' and commented=0 ORDER BY filename,cat_metric desc,var_metric asc,category,var_name,var_val,id", table, file);
q.sql = sql;
stmt = odbc_prepare_and_execute(obj, config_odbc_prepare, &q);
stmt = ast_odbc_prepare_and_execute(obj, config_odbc_prepare, &q);
if (!stmt) {
ast_log(LOG_WARNING, "SQL select error!\n[%s]\n\n", sql);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
@ -523,13 +523,13 @@ static struct ast_config *config_odbc(const char *database, const char *table, c
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL NumResultCols error!\n[%s]\n\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
if (!rowcount) {
ast_log(LOG_NOTICE, "found nothing\n");
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return cfg;
}
@ -539,7 +539,7 @@ static struct ast_config *config_odbc(const char *database, const char *table, c
if (!strcmp (q.var_name, "#include")) {
if (!ast_config_internal_load(q.var_val, cfg, 0)) {
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return NULL;
}
continue;
@ -560,7 +560,7 @@ static struct ast_config *config_odbc(const char *database, const char *table, c
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
odbc_release_obj(obj);
ast_odbc_release_obj(obj);
return cfg;
}

View File

@ -75,7 +75,7 @@ static odbc_status odbc_obj_disconnect(struct odbc_obj *obj);
static int odbc_register_class(struct odbc_class *class, int connect);
SQLHSTMT odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data)
SQLHSTMT ast_odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data)
{
int res = 0, i, attempt;
SQLINTEGER nativeerror=0, numfields=0;
@ -130,7 +130,7 @@ SQLHSTMT odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(s
return stmt;
}
int odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt)
int ast_odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt)
{
int res = 0, i;
SQLINTEGER nativeerror=0, numfields=0;
@ -172,7 +172,7 @@ int odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt)
}
int odbc_sanity_check(struct odbc_obj *obj)
int ast_odbc_sanity_check(struct odbc_obj *obj)
{
char *test_sql = "select 1";
SQLHSTMT stmt;
@ -319,12 +319,12 @@ static int odbc_show_command(int fd, int argc, char **argv)
ast_cli(fd, "Pooled: yes\nLimit: %d\nConnections in use: %d\n", class->limit, class->count);
AST_LIST_TRAVERSE(&(class->odbc_obj), current, list) {
ast_cli(fd, " Connection %d: %s", ++count, current->up && odbc_sanity_check(current) ? "connected" : "disconnected");
ast_cli(fd, " Connection %d: %s", ++count, current->up && ast_odbc_sanity_check(current) ? "connected" : "disconnected");
}
} else {
/* Should only ever be one of these */
AST_LIST_TRAVERSE(&(class->odbc_obj), current, list) {
ast_cli(fd, "Pooled: no\nConnected: %s\n", current->up && odbc_sanity_check(current) ? "yes" : "no");
ast_cli(fd, "Pooled: no\nConnected: %s\n", current->up && ast_odbc_sanity_check(current) ? "yes" : "no");
}
}
@ -362,8 +362,8 @@ static int odbc_register_class(struct odbc_class *class, int connect)
if (connect) {
/* Request and release builds a connection */
obj = odbc_request_obj(class->name, 0);
odbc_release_obj(obj);
obj = ast_odbc_request_obj(class->name, 0);
ast_odbc_release_obj(obj);
}
return 0;
@ -373,14 +373,14 @@ static int odbc_register_class(struct odbc_class *class, int connect)
}
}
void odbc_release_obj(struct odbc_obj *obj)
void ast_odbc_release_obj(struct odbc_obj *obj)
{
/* For pooled connections, this frees the connection to be
* reused. For non-pooled connections, it does nothing. */
obj->used = 0;
}
struct odbc_obj *odbc_request_obj(const char *name, int check)
struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
{
struct odbc_obj *obj = NULL;
struct odbc_class *class;
@ -445,7 +445,7 @@ struct odbc_obj *odbc_request_obj(const char *name, int check)
AST_LIST_UNLOCK(&class->odbc_obj);
if (obj && check) {
odbc_sanity_check(obj);
ast_odbc_sanity_check(obj);
}
return obj;
}