2004-06-11 00:12:35 +00:00
/*
* Asterisk - - A telephony toolkit for Linux .
*
2005-01-21 07:06:25 +00:00
* Copyright ( C ) 1999 - 2005 , Digium , Inc .
2004-06-11 00:12:35 +00:00
*
2004-10-05 06:46:11 +00:00
* Mark Spencer < markster @ digium . com >
2004-06-11 00:12:35 +00:00
*
* res_config_odbc . c < odbc + odbc plugin for portable configuration engine >
2005-01-21 07:06:25 +00:00
* Copyright ( C ) 2004 - 2005 Anthony Minessale II < anthmct @ yahoo . com >
2004-06-11 00:12:35 +00:00
*/
# include <asterisk/file.h>
# include <asterisk/logger.h>
# include <asterisk/channel.h>
# include <asterisk/pbx.h>
# include <asterisk/config.h>
# include <asterisk/module.h>
2004-06-22 18:49:00 +00:00
# include <asterisk/lock.h>
2004-10-05 06:46:11 +00:00
# include <asterisk/options.h>
2004-06-11 00:12:35 +00:00
# include <stdlib.h>
# include <unistd.h>
# include <string.h>
# include <asterisk/res_odbc.h>
2004-10-05 06:46:11 +00:00
# include <asterisk/utils.h>
2004-06-11 00:12:35 +00:00
2004-07-08 20:16:28 +00:00
static char * tdesc = " ODBC Configuration " ;
2004-06-11 00:12:35 +00:00
STANDARD_LOCAL_USER ;
LOCAL_USER_DECL ;
2004-10-07 19:57:50 +00:00
static struct ast_variable * realtime_odbc ( const char * database , const char * table , va_list ap )
2004-07-08 20:16:28 +00:00
{
2004-10-05 06:46:11 +00:00
odbc_obj * obj ;
SQLHSTMT stmt ;
2004-11-22 05:03:03 +00:00
char sql [ 1024 ] ;
2004-10-05 06:46:11 +00:00
char coltitle [ 256 ] ;
char rowdata [ 2048 ] ;
2004-11-22 05:03:03 +00:00
char * op ;
2004-10-07 19:57:50 +00:00
const char * newparam , * newval ;
2004-10-05 06:46:11 +00:00
char * stringp ;
char * chunk ;
SQLSMALLINT collen ;
int res ;
int x ;
struct ast_variable * var = NULL , * prev = NULL ;
SQLLEN rowcount = 0 ;
SQLULEN colsize ;
SQLSMALLINT colcount = 0 ;
SQLSMALLINT datatype ;
SQLSMALLINT decimaldigits ;
SQLSMALLINT nullable ;
2004-10-07 19:57:50 +00:00
va_list aq ;
va_copy ( aq , ap ) ;
2004-10-05 06:46:11 +00:00
if ( ! table )
return NULL ;
obj = fetch_odbc_obj ( database ) ;
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 " ) ;
return NULL ;
}
2004-10-07 19:57:50 +00:00
newparam = va_arg ( aq , const char * ) ;
if ( ! newparam ) {
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return NULL ;
}
newval = va_arg ( aq , const char * ) ;
2004-11-22 18:39:40 +00:00
if ( ! strchr ( newparam , ' ' ) ) op = " = " ; else op = " " ;
snprintf ( sql , sizeof ( sql ) , " SELECT * FROM %s WHERE %s%s ? " , table , newparam , op ) ;
2004-10-07 19:57:50 +00:00
while ( ( newparam = va_arg ( aq , const char * ) ) ) {
2004-11-22 18:39:40 +00:00
if ( ! strchr ( newparam , ' ' ) ) op = " = " ; else op = " " ;
snprintf ( sql + strlen ( sql ) , sizeof ( sql ) - strlen ( sql ) , " AND %s%s ? " , newparam , op ) ;
2004-10-07 19:57:50 +00:00
newval = va_arg ( aq , const char * ) ;
}
va_end ( aq ) ;
2004-10-05 06:46:11 +00:00
res = SQLPrepare ( stmt , sql , SQL_NTS ) ;
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
ast_log ( LOG_WARNING , " SQL Prepare failed![%s] \n " , sql ) ;
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return NULL ;
}
2004-10-07 19:57:50 +00:00
/* Now bind the parameters */
x = 1 ;
2004-10-05 06:46:11 +00:00
2004-10-07 19:57:50 +00:00
while ( ( newparam = va_arg ( ap , const char * ) ) ) {
newval = va_arg ( ap , const char * ) ;
SQLBindParameter ( stmt , x + + , SQL_PARAM_INPUT , SQL_C_CHAR , SQL_CHAR , strlen ( newval ) , 0 , ( void * ) newval , 0 , NULL ) ;
}
2004-10-05 06:46:11 +00:00
res = SQLExecute ( 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 ) ;
return NULL ;
}
res = SQLRowCount ( stmt , & rowcount ) ;
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
ast_log ( LOG_WARNING , " SQL Row Count error! \n [%s] \n \n " , sql ) ;
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return NULL ;
}
res = SQLNumResultCols ( stmt , & colcount ) ;
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 ) ;
return NULL ;
}
if ( rowcount ) {
res = SQLFetch ( stmt ) ;
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 ) ;
return NULL ;
}
for ( x = 0 ; x < colcount ; x + + ) {
2004-10-09 20:08:41 +00:00
rowdata [ 0 ] = ' \0 ' ;
2004-10-05 06:46:11 +00:00
collen = sizeof ( coltitle ) ;
res = SQLDescribeCol ( stmt , x + 1 , coltitle , sizeof ( coltitle ) , & collen ,
& datatype , & colsize , & decimaldigits , & nullable ) ;
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
ast_log ( LOG_WARNING , " SQL Describe Column error! \n [%s] \n \n " , sql ) ;
if ( var )
2005-01-25 06:10:20 +00:00
ast_variables_destroy ( var ) ;
2004-10-05 06:46:11 +00:00
return NULL ;
}
res = SQLGetData ( stmt , x + 1 , SQL_CHAR , rowdata , sizeof ( rowdata ) , NULL ) ;
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
ast_log ( LOG_WARNING , " SQL Get Data error! \n [%s] \n \n " , sql ) ;
if ( var )
2005-01-25 06:10:20 +00:00
ast_variables_destroy ( var ) ;
2004-10-05 06:46:11 +00:00
return NULL ;
}
stringp = rowdata ;
while ( stringp ) {
chunk = strsep ( & stringp , " ; " ) ;
if ( chunk & & ! ast_strlen_zero ( ast_strip ( chunk ) ) ) {
if ( prev ) {
2005-01-25 06:10:20 +00:00
prev - > next = ast_variable_new ( coltitle , chunk ) ;
2004-10-05 06:46:11 +00:00
if ( prev - > next )
prev = prev - > next ;
} else
2005-01-25 06:10:20 +00:00
prev = var = ast_variable_new ( coltitle , chunk ) ;
2004-10-05 06:46:11 +00:00
}
}
}
}
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return var ;
}
2004-11-23 17:58:59 +00:00
static struct ast_config * realtime_multi_odbc ( const char * database , const char * table , va_list ap )
{
odbc_obj * obj ;
SQLHSTMT stmt ;
char sql [ 1024 ] ;
char coltitle [ 256 ] ;
char rowdata [ 2048 ] ;
2004-11-24 03:07:08 +00:00
const char * initfield = NULL ;
2004-11-23 17:58:59 +00:00
char * op ;
const char * newparam , * newval ;
char * stringp ;
char * chunk ;
SQLSMALLINT collen ;
int res ;
int x ;
2005-01-25 06:10:20 +00:00
struct ast_variable * var = NULL ;
2004-11-23 17:58:59 +00:00
struct ast_config * cfg = NULL ;
struct ast_category * cat = NULL ;
2005-01-20 04:53:17 +00:00
struct ast_realloca ra ;
2004-11-23 17:58:59 +00:00
SQLLEN rowcount = 0 ;
SQLULEN colsize ;
SQLSMALLINT colcount = 0 ;
SQLSMALLINT datatype ;
SQLSMALLINT decimaldigits ;
SQLSMALLINT nullable ;
2005-01-20 04:53:17 +00:00
2004-11-23 17:58:59 +00:00
va_list aq ;
va_copy ( aq , ap ) ;
if ( ! table )
return NULL ;
2005-01-20 04:53:17 +00:00
memset ( & ra , 0 , sizeof ( ra ) ) ;
2004-11-23 17:58:59 +00:00
obj = fetch_odbc_obj ( database ) ;
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 " ) ;
return NULL ;
}
newparam = va_arg ( aq , const char * ) ;
if ( ! newparam ) {
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return NULL ;
}
2004-11-24 03:07:08 +00:00
initfield = ast_strdupa ( newparam ) ;
if ( initfield & & ( op = strchr ( initfield , ' ' ) ) )
* op = ' \0 ' ;
2004-11-23 17:58:59 +00:00
newval = va_arg ( aq , const char * ) ;
if ( ! strchr ( newparam , ' ' ) ) op = " = " ; else op = " " ;
snprintf ( sql , sizeof ( sql ) , " SELECT * FROM %s WHERE %s%s ? " , table , newparam , op ) ;
while ( ( newparam = va_arg ( aq , const char * ) ) ) {
if ( ! strchr ( newparam , ' ' ) ) op = " = " ; else op = " " ;
snprintf ( sql + strlen ( sql ) , sizeof ( sql ) - strlen ( sql ) , " AND %s%s ? " , newparam , op ) ;
newval = va_arg ( aq , const char * ) ;
}
2004-11-24 03:07:08 +00:00
if ( initfield )
snprintf ( sql + strlen ( sql ) , sizeof ( sql ) - strlen ( sql ) , " ORDER BY %s " , initfield ) ;
2004-11-23 17:58:59 +00:00
va_end ( aq ) ;
res = SQLPrepare ( stmt , sql , SQL_NTS ) ;
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
ast_log ( LOG_WARNING , " SQL Prepare failed![%s] \n " , sql ) ;
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return NULL ;
}
/* Now bind the parameters */
x = 1 ;
while ( ( newparam = va_arg ( ap , const char * ) ) ) {
newval = va_arg ( ap , const char * ) ;
SQLBindParameter ( stmt , x + + , SQL_PARAM_INPUT , SQL_C_CHAR , SQL_CHAR , strlen ( newval ) , 0 , ( void * ) newval , 0 , NULL ) ;
}
res = SQLExecute ( 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 ) ;
return NULL ;
}
res = SQLRowCount ( stmt , & rowcount ) ;
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
ast_log ( LOG_WARNING , " SQL Row Count error! \n [%s] \n \n " , sql ) ;
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return NULL ;
}
res = SQLNumResultCols ( stmt , & colcount ) ;
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 ) ;
return NULL ;
}
2005-01-25 06:10:20 +00:00
cfg = ast_config_new ( ) ;
if ( ! cfg ) {
ast_log ( LOG_WARNING , " Out of memory! \n " ) ;
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return NULL ;
}
2004-11-24 03:07:08 +00:00
while ( rowcount - - ) {
2004-11-23 17:58:59 +00:00
var = NULL ;
res = SQLFetch ( stmt ) ;
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
ast_log ( LOG_WARNING , " SQL Fetch error! \n [%s] \n \n " , sql ) ;
continue ;
}
2005-01-25 06:10:20 +00:00
cat = ast_category_new ( " " ) ;
if ( ! cat ) {
ast_log ( LOG_WARNING , " Out of memory! \n " ) ;
continue ;
}
2004-11-23 17:58:59 +00:00
for ( x = 0 ; x < colcount ; x + + ) {
rowdata [ 0 ] = ' \0 ' ;
collen = sizeof ( coltitle ) ;
res = SQLDescribeCol ( stmt , x + 1 , coltitle , sizeof ( coltitle ) , & collen ,
& datatype , & colsize , & decimaldigits , & nullable ) ;
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
ast_log ( LOG_WARNING , " SQL Describe Column error! \n [%s] \n \n " , sql ) ;
2005-01-25 06:10:20 +00:00
ast_category_destroy ( cat ) ;
2004-11-23 17:58:59 +00:00
continue ;
}
res = SQLGetData ( stmt , x + 1 , SQL_CHAR , rowdata , sizeof ( rowdata ) , NULL ) ;
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
ast_log ( LOG_WARNING , " SQL Get Data error! \n [%s] \n \n " , sql ) ;
2005-01-25 06:10:20 +00:00
ast_category_destroy ( cat ) ;
2004-11-23 17:58:59 +00:00
continue ;
}
stringp = rowdata ;
while ( stringp ) {
chunk = strsep ( & stringp , " ; " ) ;
if ( chunk & & ! ast_strlen_zero ( ast_strip ( chunk ) ) ) {
2005-01-25 06:10:20 +00:00
if ( initfield & & ! strcmp ( initfield , coltitle ) )
ast_category_rename ( cat , chunk ) ;
var = ast_variable_new ( coltitle , chunk ) ;
ast_variable_append ( cat , var ) ;
2004-11-23 17:58:59 +00:00
}
}
2004-11-24 03:07:08 +00:00
}
2005-01-25 06:10:20 +00:00
ast_category_append ( cfg , cat ) ;
2004-11-23 17:58:59 +00:00
}
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return cfg ;
}
2004-10-05 06:46:11 +00:00
static int update_odbc ( const char * database , const char * table , const char * keyfield , const char * lookup , va_list ap )
{
odbc_obj * obj ;
SQLHSTMT stmt ;
char sql [ 256 ] ;
SQLLEN rowcount = 0 ;
const char * newparam , * newval ;
int res ;
int x ;
va_list aq ;
va_copy ( aq , ap ) ;
if ( ! table )
return - 1 ;
obj = fetch_odbc_obj ( database ) ;
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 " ) ;
return - 1 ;
}
newparam = va_arg ( aq , const char * ) ;
if ( ! newparam ) {
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return - 1 ;
}
newval = va_arg ( aq , const char * ) ;
snprintf ( sql , sizeof ( sql ) , " UPDATE %s SET %s=? " , table , newparam ) ;
while ( ( newparam = va_arg ( aq , const char * ) ) ) {
snprintf ( sql + strlen ( sql ) , sizeof ( sql ) - strlen ( sql ) , " , %s=? " , newparam ) ;
newval = va_arg ( aq , const char * ) ;
}
va_end ( aq ) ;
snprintf ( sql + strlen ( sql ) , sizeof ( sql ) - strlen ( sql ) , " WHERE %s=? " , keyfield ) ;
res = SQLPrepare ( stmt , sql , SQL_NTS ) ;
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
ast_log ( LOG_WARNING , " SQL Prepare failed![%s] \n " , sql ) ;
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return - 1 ;
}
/* Now bind the parameters */
x = 1 ;
while ( ( newparam = va_arg ( ap , const char * ) ) ) {
newval = va_arg ( ap , const char * ) ;
SQLBindParameter ( stmt , x + + , SQL_PARAM_INPUT , SQL_C_CHAR , SQL_CHAR , strlen ( newval ) , 0 , ( void * ) newval , 0 , NULL ) ;
}
SQLBindParameter ( stmt , x + + , SQL_PARAM_INPUT , SQL_C_CHAR , SQL_CHAR , strlen ( lookup ) , 0 , ( void * ) lookup , 0 , NULL ) ;
res = SQLExecute ( 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 ) ;
return - 1 ;
}
res = SQLRowCount ( stmt , & rowcount ) ;
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
ast_log ( LOG_WARNING , " SQL Row Count error! \n [%s] \n \n " , sql ) ;
return - 1 ;
}
if ( rowcount )
return 0 ;
return - 1 ;
}
2005-01-25 06:10:20 +00:00
static struct ast_config * config_odbc ( const char * database , const char * table , const char * file , struct ast_config * cfg )
2004-10-05 06:46:11 +00:00
{
2005-01-25 06:10:20 +00:00
struct ast_variable * new_v ;
struct ast_category * cur_cat ;
2004-10-05 06:46:11 +00:00
int res = 0 ;
2004-07-08 20:16:28 +00:00
odbc_obj * obj ;
2004-07-13 22:53:17 +00:00
SQLINTEGER err = 0 , commented = 0 , cat_metric = 0 , var_metric = 0 , last_cat_metric = 0 ;
2004-07-08 20:16:28 +00:00
SQLBIGINT id ;
2004-11-24 03:19:27 +00:00
char sql [ 255 ] = " " , filename [ 128 ] , category [ 128 ] , var_name [ 128 ] , var_val [ 512 ] ;
2004-07-13 22:53:17 +00:00
SQLSMALLINT rowcount = 0 ;
2004-07-08 20:16:28 +00:00
SQLHSTMT stmt ;
2005-01-25 06:10:20 +00:00
char last [ 128 ] = " " ;
2004-07-08 20:16:28 +00:00
if ( ! file | | ! strcmp ( file , " res_config_odbc.conf " ) )
2004-12-18 22:04:07 +00:00
return NULL ; /* cant configure myself with myself ! */
2004-07-08 20:16:28 +00:00
2004-10-05 06:46:11 +00:00
obj = fetch_odbc_obj ( database ) ;
2004-07-08 20:16:28 +00:00
if ( ! obj )
return NULL ;
res = SQLAllocHandle ( SQL_HANDLE_STMT , obj - > con , & stmt ) ;
SQLBindCol ( stmt , 1 , SQL_C_ULONG , & id , sizeof ( id ) , & err ) ;
SQLBindCol ( stmt , 2 , SQL_C_ULONG , & cat_metric , sizeof ( cat_metric ) , & err ) ;
SQLBindCol ( stmt , 3 , SQL_C_ULONG , & var_metric , sizeof ( var_metric ) , & err ) ;
SQLBindCol ( stmt , 4 , SQL_C_ULONG , & commented , sizeof ( commented ) , & err ) ;
SQLBindCol ( stmt , 5 , SQL_C_CHAR , & filename , sizeof ( filename ) , & err ) ;
SQLBindCol ( stmt , 6 , SQL_C_CHAR , & category , sizeof ( category ) , & err ) ;
SQLBindCol ( stmt , 7 , SQL_C_CHAR , & var_name , sizeof ( var_name ) , & err ) ;
SQLBindCol ( stmt , 8 , SQL_C_CHAR , & var_val , sizeof ( var_val ) , & err ) ;
2004-10-05 06:46:11 +00:00
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 ) ;
2004-07-08 20:16:28 +00:00
res = SQLExecDirect ( stmt , sql , SQL_NTS ) ;
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
ast_log ( LOG_WARNING , " SQL select error! \n [%s] \n \n " , sql ) ;
2005-01-25 06:10:20 +00:00
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
2004-07-08 20:16:28 +00:00
return NULL ;
2004-06-11 00:12:35 +00:00
}
2004-07-08 20:16:28 +00:00
res = SQLNumResultCols ( stmt , & rowcount ) ;
2004-06-11 00:12:35 +00:00
2004-07-08 20:16:28 +00:00
if ( ( res ! = SQL_SUCCESS ) & & ( res ! = SQL_SUCCESS_WITH_INFO ) ) {
2005-01-25 06:10:20 +00:00
ast_log ( LOG_WARNING , " SQL NumResultCols error! \n [%s] \n \n " , sql ) ;
2004-10-05 06:46:11 +00:00
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return NULL ;
}
2005-01-25 06:10:20 +00:00
if ( ! rowcount ) {
ast_log ( LOG_NOTICE , " found nothing \n " ) ;
return cfg ;
}
2004-07-08 20:16:28 +00:00
2005-01-25 06:10:20 +00:00
cur_cat = ast_config_get_current_category ( cfg ) ;
2004-07-08 20:16:28 +00:00
2005-01-25 06:10:20 +00:00
while ( ( res = SQLFetch ( stmt ) ) ! = SQL_NO_DATA ) {
if ( ! strcmp ( var_name , " #include " ) ) {
if ( ! ast_config_internal_load ( var_val , cfg ) ) {
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return NULL ;
2004-07-08 20:16:28 +00:00
}
2005-01-25 06:10:20 +00:00
continue ;
}
if ( strcmp ( last , category ) | | last_cat_metric ! = cat_metric ) {
cur_cat = ast_category_new ( category ) ;
if ( ! cur_cat ) {
ast_log ( LOG_WARNING , " Out of memory! \n " ) ;
break ;
}
strcpy ( last , category ) ;
last_cat_metric = cat_metric ;
ast_category_append ( cfg , cur_cat ) ;
2004-07-08 20:16:28 +00:00
}
2005-01-25 06:10:20 +00:00
new_v = ast_variable_new ( var_name , var_val ) ;
ast_variable_append ( cur_cat , new_v ) ;
2004-07-08 20:16:28 +00:00
}
2004-06-11 00:12:35 +00:00
2005-01-25 06:10:20 +00:00
SQLFreeHandle ( SQL_HANDLE_STMT , stmt ) ;
return cfg ;
2004-07-08 20:16:28 +00:00
}
2004-06-11 00:12:35 +00:00
2005-01-25 06:10:20 +00:00
static struct ast_config_engine odbc_engine = {
. name = " odbc " ,
. load_func = config_odbc ,
. realtime_func = realtime_odbc ,
. realtime_multi_func = realtime_multi_odbc ,
. update_func = update_odbc
} ;
2004-07-08 20:16:28 +00:00
int unload_module ( void )
2004-06-11 00:12:35 +00:00
{
2005-01-25 06:10:20 +00:00
ast_config_engine_deregister ( & odbc_engine ) ;
2004-10-05 06:46:11 +00:00
if ( option_verbose )
ast_verbose ( " res_config_odbc unloaded. \n " ) ;
2004-06-11 00:12:35 +00:00
STANDARD_HANGUP_LOCALUSERS ;
return 0 ;
}
2004-07-08 20:16:28 +00:00
int load_module ( void )
2004-06-11 00:12:35 +00:00
{
2005-01-25 06:10:20 +00:00
ast_config_engine_register ( & odbc_engine ) ;
2004-10-05 06:46:11 +00:00
if ( option_verbose )
ast_verbose ( " res_config_odbc loaded. \n " ) ;
2004-06-11 00:12:35 +00:00
return 0 ;
}
2004-07-08 20:16:28 +00:00
char * description ( void )
2004-06-11 00:12:35 +00:00
{
2004-07-08 20:16:28 +00:00
return tdesc ;
2004-06-11 00:12:35 +00:00
}
2004-07-08 20:16:28 +00:00
int usecount ( void )
2004-06-11 00:12:35 +00:00
{
/* never unload a config module */
return 1 ;
}
2004-07-08 20:16:28 +00:00
char * key ( )
2004-06-11 00:12:35 +00:00
{
2004-07-08 20:16:28 +00:00
return ASTERISK_GPL_KEY ;
2004-06-11 00:12:35 +00:00
}