[asterisk-commits] kpfleming: trunk r43311 - in /trunk: funcs/ include/asterisk/ res/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Sep 19 21:57:21 MST 2006


Author: kpfleming
Date: Tue Sep 19 23:57:20 2006
New Revision: 43311

URL: http://svn.digium.com/view/asterisk?rev=43311&view=rev
Log:
move ODBC API into ast_ namespace

Modified:
    trunk/funcs/func_odbc.c
    trunk/include/asterisk/res_odbc.h
    trunk/res/res_config_odbc.c
    trunk/res/res_odbc.c

Modified: trunk/funcs/func_odbc.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_odbc.c?rev=43311&r1=43310&r2=43311&view=diff
==============================================================================
--- trunk/funcs/func_odbc.c (original)
+++ trunk/funcs/func_odbc.c Tue Sep 19 23:57:20 2006
@@ -119,7 +119,7 @@
 		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 @@
 
 	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 @@
 	if (stmt)
 		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 	if (obj)
-		odbc_release_obj(obj);
+		ast_odbc_release_obj(obj);
 
 	return 0;
 }
@@ -217,7 +217,7 @@
 		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 @@
 
 	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 @@
 	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 @@
 			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 @@
 		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 @@
 	buf[buflen - 1] = '\0';
 
 	SQLFreeHandle(SQL_HANDLE_STMT, stmt);
-	odbc_release_obj(obj);
+	ast_odbc_release_obj(obj);
 	return 0;
 }
 

Modified: trunk/include/asterisk/res_odbc.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/res_odbc.h?rev=43311&r1=43310&r2=43311&view=diff
==============================================================================
--- trunk/include/asterisk/res_odbc.h (original)
+++ trunk/include/asterisk/res_odbc.h Tue Sep 19 23:57:20 2006
@@ -60,7 +60,7 @@
  * 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 @@
  * 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 @@
  * \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 */

Modified: trunk/res/res_config_odbc.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_config_odbc.c?rev=43311&r1=43310&r2=43311&view=diff
==============================================================================
--- trunk/res/res_config_odbc.c (original)
+++ trunk/res/res_config_odbc.c Tue Sep 19 23:57:20 2006
@@ -81,21 +81,21 @@
 	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 @@
 	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 @@
 		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 @@
 	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 @@
 			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 @@
 			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 @@
 
 
 	SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-	odbc_release_obj(obj);
+	ast_odbc_release_obj(obj);
 	return var;
 }
 
@@ -232,21 +232,21 @@
 		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 @@
 	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 @@
 		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 @@
 	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 @@
 	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 @@
 	}
 
 	SQLFreeHandle(SQL_HANDLE_STMT, stmt);
-	odbc_release_obj(obj);
+	ast_odbc_release_obj(obj);
 	return cfg;
 }
 
@@ -371,21 +371,21 @@
 	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 @@
 	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 @@
 		
 	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 @@
 	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 @@
 	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 @@
 		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 @@
 	}
 
 	SQLFreeHandle(SQL_HANDLE_STMT, stmt);
-	odbc_release_obj(obj);
+	ast_odbc_release_obj(obj);
 	return cfg;
 }
 

Modified: trunk/res/res_odbc.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_odbc.c?rev=43311&r1=43310&r2=43311&view=diff
==============================================================================
--- trunk/res/res_odbc.c (original)
+++ trunk/res/res_odbc.c Tue Sep 19 23:57:20 2006
@@ -75,7 +75,7 @@
 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 @@
 	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_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 @@
 				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 @@
 
 		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 @@
 	}
 }
 
-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 @@
 	AST_LIST_UNLOCK(&class->odbc_obj);
 
 	if (obj && check) {
-		odbc_sanity_check(obj);
+		ast_odbc_sanity_check(obj);
 	}
 	return obj;
 }



More information about the asterisk-commits mailing list