Index: cdr_addon_mysql.c =================================================================== RCS file: /usr/cvsroot/asterisk-addons/cdr_addon_mysql.c,v retrieving revision 1.6 diff -u -r1.6 cdr_addon_mysql.c --- cdr_addon_mysql.c 21 Jan 2005 01:43:19 -0000 1.6 +++ cdr_addon_mysql.c 30 Jan 2005 18:35:45 -0000 @@ -266,7 +266,7 @@ struct ast_variable *var; char *tmp; - cfg = ast_load(config); + cfg = ast_config_load(config); if (!cfg) { ast_log(LOG_WARNING, "Unable to load config for mysql CDR's: %s\n", config); return 0; @@ -384,7 +384,7 @@ } } - ast_destroy(cfg); + ast_config_destroy(cfg); ast_log(LOG_DEBUG,"cdr_mysql: got hostname of %s\n",hostname); ast_log(LOG_DEBUG,"cdr_mysql: got port of %d\n",dbport); Index: res_perl/AstAPIBase.c =================================================================== RCS file: /usr/cvsroot/asterisk-addons/res_perl/AstAPIBase.c,v retrieving revision 1.6 diff -u -r1.6 AstAPIBase.c --- res_perl/AstAPIBase.c 10 Jan 2005 21:26:19 -0000 1.6 +++ res_perl/AstAPIBase.c 30 Jan 2005 18:35:45 -0000 @@ -1,6 +1,5 @@ #include #include -#include #include #define CONF_SIZE 160 Index: res_perl/Makefile =================================================================== RCS file: /usr/cvsroot/asterisk-addons/res_perl/Makefile,v retrieving revision 1.3 diff -u -r1.3 Makefile --- res_perl/Makefile 19 Dec 2004 16:04:10 -0000 1.3 +++ res_perl/Makefile 30 Jan 2005 18:35:45 -0000 @@ -41,6 +41,7 @@ CFLAGS += -DASTVARLIBDIR=\"$(ASTVARLIBDIR)\" -DASTVARRUNDIR=\"$(ASTVARRUNDIR)\" -DASTSPOOLDIR=\"$(ASTSPOOLDIR)\" -DASTLOGDIR=\"$(ASTLOGDIR)\" CFLAGS += -DASTCONFPATH=\"$(ASTCONFPATH)\" -DASTMODDIR=\"$(MODULES_DIR)\" -DASTAGIDIR=\"$(AGI_DIR)\" CFLAGS += -DMULTIPLICITY $(shell $(PERL) -MExtUtils::Embed -e ccopts) +CFLAGS += -D_GNU_SOURCE LDFLAGS = $(shell $(PERL) -MExtUtils::Embed -e ldopts) LDFLAGS += $(shell perl -MConfig -e 'print $$Config{libs}') Index: res_perl/res_perl.c =================================================================== RCS file: /usr/cvsroot/asterisk-addons/res_perl/res_perl.c,v retrieving revision 1.6 diff -u -r1.6 res_perl.c --- res_perl/res_perl.c 19 Dec 2004 16:04:10 -0000 1.6 +++ res_perl/res_perl.c 30 Jan 2005 18:35:45 -0000 @@ -37,13 +37,12 @@ int _load_module(void); #ifdef HAVE_AST_CUST_CONFIG -static struct ast_config_reg reg1; static int use_config=0; +static int clone_on_config=1; #endif static int use_switch=0; static int use_cdr=0; -static int clone_on_config=1; static void replace_delim(char *arg,char a,char b) { int i; @@ -774,7 +773,7 @@ for (i = 0; i+1 <= array_size; i++) { if((var = *av_fetch(array, i++, FALSE)) && (val = *av_fetch(array, i, FALSE)) ) { - if((new_v = ast_new_variable(SvPV_nolen(var),SvPV_nolen(val)))) { + if((new_v = ast_variable_new(SvPV_nolen(var),SvPV_nolen(val)))) { if(vars) { next->next = new_v; next = new_v; @@ -824,7 +823,7 @@ return 0; } -static struct ast_config *perl_config(const char *database, const char *table, const char *file, struct ast_config *new_config_s, struct ast_category **new_cat_p, struct ast_variable **new_v_p, int recur) +static struct ast_config *perl_config(const char *database, const char *table, const char *file, struct ast_config *cfg) { PerlInterpreter *my_perl; if (clone_on_config) @@ -832,12 +831,9 @@ else my_perl = global_perl; - struct ast_config *new; - struct ast_variable *cur_v=NULL,*new_v; - struct ast_category *cur_cat=NULL,*new_cat=NULL; - char last[80]; - int cat_started=0; - int var_started=0; + struct ast_variable *new_v; + struct ast_category *cur_cat; + char last[128] = ""; int len=0; AV *array; int i=0,ii=0; @@ -853,24 +849,7 @@ if (file && !strcmp(file,"res_perl.conf")) return NULL; // cant configure myself - if (new_config_s) { - new = new_config_s; - cat_started++; - } else - new = ast_new_config(); - - last[0] = '\0'; - - cat_started=0; - var_started=0; - - cur_cat = *new_cat_p; - cur_v = *new_v_p; - - if (cur_cat) - cat_started=1; - if (cur_v) - var_started=1; + cur_cat = ast_config_get_current_category(cfg); len = strlen(database) + strlen(table) + strlen(file) + 10; args = alloca(len); @@ -897,18 +876,13 @@ if (name && strcmp(last,SvPV_nolen(name))) { // new cat category = SvPV_nolen(name); - strcpy(last,category); - new_cat = (struct ast_category *) ast_new_category(category); - - if (!cat_started) { - cat_started++; - new->root = new_cat; - cur_cat=new->root; - } else { - cur_cat->next = new_cat; - cur_cat = cur_cat->next; + cur_cat = ast_category_new(category); + if (!cur_cat) { + ast_log(LOG_WARNING, "Out of memory!\n"); + break; } - var_started=0; + strcpy(last, category); + ast_category_append(cfg, cur_cat); } if (name && vars && SvTYPE(vars) == SVt_PVAV) { if (vars) @@ -922,31 +896,29 @@ val = *hv_fetch(varshash,"val",3,FALSE); if (category && var && val) { - new_v = ast_new_variable(SvPV_nolen(var),SvPV_nolen(val)); - if (!var_started) { - var_started++; - cur_cat->root = new_v; - cur_v = cur_cat->root; - } else { - cur_v->next = new_v; - cur_v = cur_v->next; - } - - + new_v = ast_variable_new(SvPV_nolen(var), SvPV_nolen(val)); + ast_variable_append(cur_cat, new_v); } } } } } } - if (!i) - new = NULL; - if (clone_on_config) dest_perl(&my_perl); - return new; + if (!i) + return NULL; + else + return cfg; } + +static struct ast_config_engine perl_engine = { + .name = "perl", + .load_func = perl_config, + .realtime_func = realtime_perl, + .update_func = update_perl +}; #endif int _load_module(void) { @@ -990,19 +962,12 @@ use_config = 1; ast_log(LOG_NOTICE,"loading perl config engine.\n"); - memset(®1,0,sizeof(struct ast_config_reg)); - strcpy(reg1.name,"perl"); - reg1.static_func = perl_config; - reg1.realtime_func = realtime_perl; - reg1.update_func = update_perl; - ast_cust_config_register(®1); - + ast_config_engine_register(&perl_engine); } else ast_log(LOG_NOTICE,"perl config engine disabled.\n"); } else ast_log(LOG_NOTICE,"perl config engine disabled.\n"); -#endif if (hv_exists(PERL_CONFIG,"CLONE_ON_CONFIG",strlen("CLONE_ON_CONFIG"))) { rval = get_hash_val(my_perl,PERL_CONFIG,"CLONE_ON_CONFIG"); @@ -1011,6 +976,8 @@ clone_on_config=1; } } +#endif + if (hv_exists(PERL_CONFIG,"USE_CDR",strlen("USE_CDR"))) { rval = get_hash_val(my_perl,PERL_CONFIG,"USE_CDR"); if (rval && ast_true(rval)) { Index: res_perl/res_perl.h =================================================================== RCS file: /usr/cvsroot/asterisk-addons/res_perl/res_perl.h,v retrieving revision 1.1 diff -u -r1.1 res_perl.h --- res_perl/res_perl.h 23 Sep 2004 17:49:42 -0000 1.1 +++ res_perl/res_perl.h 30 Jan 2005 18:35:45 -0000 @@ -1,5 +1,7 @@ #ifndef __RES_PERL_H #define __RES_PERL_H +#include +#include #include #include #include @@ -7,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -19,22 +20,11 @@ #include #include #include -#include #include -#include -#include -#include -#include #include -#include -#include #include #include -#include -#include -#include #include -#include #include #include #include @@ -46,16 +36,6 @@ AV *eval_some_perl(PerlInterpreter *perl,char *func,char *arg); int can_run_nochan(char *test); int process_perl_return_value(struct ast_channel *chan,char *ret); - -#ifdef HAVE_RES_CONFIG -struct ast_config *perl_config(char *file, struct ast_config *new_config_s,struct ast_category **new_cat_p,struct ast_variable **new_v_p,int recur -#ifdef PRESERVE_COMMENTS - ,struct ast_comment_struct *acs -#endif - - ); - -#endif void launch_perl_thread(char *function); Index: res_sqlite3/Makefile =================================================================== RCS file: /usr/cvsroot/asterisk-addons/res_sqlite3/Makefile,v retrieving revision 1.1 diff -u -r1.1 Makefile --- res_sqlite3/Makefile 15 Nov 2004 14:42:03 -0000 1.1 +++ res_sqlite3/Makefile 30 Jan 2005 18:35:46 -0000 @@ -1,5 +1,5 @@ ASTDIR=/usr/src/asterisk -ASTXS=/usr/src/asterisk/contrib/scripts/astxs +ASTXS=$(ASTDIR)/contrib/scripts/astxs ASTMODS=/usr/lib/asterisk/modules ASTSQLITE=/var/lib/asterisk/sqlite SQLITE2=/usr/local/bin/sqlite @@ -13,7 +13,7 @@ res_sqlite.so: - $(ASTXS) "-append=CFLAGS:$(CFLAGS)" "-append=EXTOBJ:./sqlite/.libs/libsqlite3.a" res_sqlite.c + ASTSRC=$(ASTDIR) $(ASTXS) "-append=CFLAGS:$(CFLAGS)" "-append=EXTOBJ:./sqlite/.libs/libsqlite3.a" res_sqlite.c .sqlite: cd sqlite && test -f ./config.status || ./configure --enable-threadsafe Index: res_sqlite3/res_sqlite.c =================================================================== RCS file: /usr/cvsroot/asterisk-addons/res_sqlite3/res_sqlite.c,v retrieving revision 1.1 diff -u -r1.1 res_sqlite.c --- res_sqlite3/res_sqlite.c 15 Nov 2004 14:42:03 -0000 1.1 +++ res_sqlite3/res_sqlite.c 30 Jan 2005 18:35:46 -0000 @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -94,8 +93,6 @@ static int default_timeout = 300; static int do_reload=1; -static struct ast_config_reg reg1; - static char cdr_table[ARRAY_SIZE]; static char cdr_dbfile[ARRAY_SIZE]; @@ -725,39 +722,28 @@ static struct ast_cli_entry cli_sqlite8 = { { "create", NULL }, sqlite_cli, scmd, shelp}; static struct ast_cli_entry cli_sqlite9 = { { "drop", NULL }, sqlite_cli, scmd, shelp}; - - -static struct ast_config *config_sqlite (const char *database, const char *table, const char *file, struct ast_config *new_config_s, struct ast_category **new_cat_p, struct ast_variable **new_v_p, int recur) { - struct ast_config *config, *new; - struct ast_variable *v, *cur_v, *new_v; - struct ast_category *cur_cat, *new_cat; +static struct ast_config *config_sqlite(const char *database, const char *table, const char *file, struct ast_config *cfg) +{ + struct ast_variable *new_v, *v; + struct ast_category *cur_cat; char ttable[ARRAY_SIZE]; int configured = 0, res = 0; sqlite3_stmt *stmt = NULL;; int cat_metric=0, last_cat_metric=0; char sql[ARRAY_SIZE]; - char last[ARRAY_SIZE]; - int cat_started = 0; - int var_started = 0; + char last[ARRAY_SIZE] = ""; char path[ARRAY_SIZE]; sqlite3 *db; int running=0; int i=0; + struct ast_config *config; - if (new_config_s) { - new = new_config_s; - cat_started++; - } else { - new = ast_new_config (); - } - - last[0] = '\0'; /* if the data was not passed from extconfig.conf then get it from sqlite.conf */ if(!database || ast_strlen_zero(database)) { if (!file || !strcmp (file, "res_sqlite.conf")) return NULL; // cant configure myself with myself ! - config = ast_load ("res_sqlite.conf"); + config = ast_config_load ("res_sqlite.conf"); if (config) { for (v = ast_variable_browse (config, "config"); v; v = v->next) { if (!strcmp (v->name, "table")) { @@ -768,7 +754,7 @@ configured++; } } - ast_destroy (config); + ast_config_destroy (config); } } else { pick_path((char *)database,path,ARRAY_SIZE); @@ -791,16 +777,7 @@ return NULL; } - - cat_started = 0; - cur_cat = *new_cat_p; - cur_v = *new_v_p; - - if (cur_cat) - cat_started = 1; - if (cur_v) - var_started = 1; - + cur_cat = ast_config_get_current_category(cfg); /* 0 id int @@ -838,40 +815,23 @@ } if (strcmp (last, sqlite3_column_text(stmt,5)) || last_cat_metric != cat_metric) { + cur_cat = ast_category_new((char *)sqlite3_column_text(stmt,5)); + if (!cur_cat) { + ast_log(LOG_WARNING, "Out of memory!\n"); + break; + } strcpy (last, sqlite3_column_text(stmt,5)); last_cat_metric = cat_metric; - new_cat = (struct ast_category *) ast_new_category((char *)sqlite3_column_text(stmt,5)); - - if (!cat_started) { - cat_started++; - new->root = new_cat; - cur_cat = new->root; - } else { - cur_cat->next = new_cat; - cur_cat = cur_cat->next; - } - var_started = 0; - - } - new_v = ast_new_variable ((char *)sqlite3_column_text(stmt,6), (char *)sqlite3_column_text(stmt,7)); - - if (!var_started) { - var_started++; - cur_cat->root = new_v; - cur_v = cur_cat->root; - } else { - cur_v->next = new_v; - cur_v = cur_v->next; + ast_category_append(cfg, cur_cat); } - + new_v = ast_variable_new ((char *)sqlite3_column_text(stmt,6), (char *)sqlite3_column_text(stmt,7)); + ast_variable_append(cur_cat, new_v); } if ((sqlite3_finalize(stmt))) ast_log(LOG_ERROR,"ERROR: %s\n",sqlite3_errmsg(db)); - - return new; - + return cfg; } @@ -1057,7 +1017,7 @@ char *sql; - config = ast_load ("res_sqlite.conf"); + config = ast_config_load ("res_sqlite.conf"); if (config) { for (v = ast_variable_browse (config, "general"); v; v = v->next) { if (!strcmp (v->name, "reload")) { @@ -1114,7 +1074,7 @@ } } - ast_destroy (config); + ast_config_destroy (config); } @@ -1152,6 +1112,11 @@ return load_config(0); } +static struct ast_config_engine sqlite_engine = { + .name = "sqlite", + .load_func = config_sqlite +}; + int load_module(void) { int res = 0; @@ -1159,10 +1124,7 @@ load_config(1); do_reload = 0; - memset (®1, 0, sizeof (struct ast_config_reg)); - strcpy (reg1.name, "sqlite"); - reg1.static_func = config_sqlite; - ast_cust_config_register (®1); + ast_config_engine_register(&sqlite_engine); ast_verbose(VERBOSE_PREFIX_2 "SQLite Config Handler Registered.\n"); @@ -1214,7 +1176,7 @@ int res = 0; do_reload = 1; - ast_cust_config_deregister (®1); + ast_config_engine_deregister(&sqlite_engine); if (has_cdr) { ast_cdr_unregister(cdr_name); ast_verbose(VERBOSE_PREFIX_2 "SQLite CDR Disabled\n");