diff -Nru a/apps/app_alarmreceiver.c b/apps/app_alarmreceiver.c --- a/apps/app_alarmreceiver.c 2005-01-22 20:43:12 -07:00 +++ b/apps/app_alarmreceiver.c 2005-01-22 20:43:12 -07:00 @@ -817,7 +817,7 @@ strncpy(db_family, p, sizeof(db_family) - 1); db_family[sizeof(db_family) - 1] = '\0'; } - ast_destroy(cfg); + ast_config_destroy(cfg); } return 0; diff -Nru a/apps/app_directory.c b/apps/app_directory.c --- a/apps/app_directory.c 2005-01-22 20:43:12 -07:00 +++ b/apps/app_directory.c 2005-01-22 20:43:12 -07:00 @@ -400,7 +400,7 @@ } } } - ast_destroy(cfg); + ast_config_destroy(cfg); LOCAL_USER_REMOVE(u); return res; } diff -Nru a/apps/app_enumlookup.c b/apps/app_enumlookup.c --- a/apps/app_enumlookup.c 2005-01-22 20:43:12 -07:00 +++ b/apps/app_enumlookup.c 2005-01-22 20:43:12 -07:00 @@ -152,7 +152,7 @@ } else { strncpy(h323driver, s, sizeof(h323driver) - 1); } - ast_destroy(cfg); + ast_config_destroy(cfg); return 0; } ast_log(LOG_NOTICE, "No ENUM Config file, using defaults\n"); diff -Nru a/apps/app_festival.c b/apps/app_festival.c --- a/apps/app_festival.c 2005-01-22 20:43:12 -07:00 +++ b/apps/app_festival.c 2005-01-22 20:43:12 -07:00 @@ -308,7 +308,7 @@ } if (!vdata || ast_strlen_zero(vdata)) { ast_log(LOG_WARNING, "festival requires an argument (text)\n"); - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } strncpy(data, vdata, sizeof(data) - 1); @@ -326,7 +326,7 @@ if (fd < 0) { ast_log(LOG_WARNING,"festival_client: can't get socket\n"); - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } memset(&serv_addr, 0, sizeof(serv_addr)); @@ -335,7 +335,7 @@ serverhost = ast_gethostbyname(host, &ahp); if (serverhost == (struct hostent *)0) { ast_log(LOG_WARNING,"festival_client: gethostbyname failed\n"); - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } memmove(&serv_addr.sin_addr,serverhost->h_addr, serverhost->h_length); @@ -345,7 +345,7 @@ if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != 0) { ast_log(LOG_WARNING,"festival_client: connect to server failed\n"); - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } @@ -448,7 +448,7 @@ } } while (strcmp(ack,"OK\n") != 0); close(fd); - ast_destroy(cfg); + ast_config_destroy(cfg); LOCAL_USER_REMOVE(u); return res; diff -Nru a/apps/app_meetme.c b/apps/app_meetme.c --- a/apps/app_meetme.c 2005-01-22 20:43:12 -07:00 +++ b/apps/app_meetme.c 2005-01-22 20:43:12 -07:00 @@ -1215,7 +1215,7 @@ if (!var) { ast_log(LOG_DEBUG, "%s isn't a valid conference\n", confno); } - ast_destroy(cfg); + ast_config_destroy(cfg); } } else if (dynamic_pin) { /* Correct for the user selecting 'D' instead of 'd' to have @@ -1421,7 +1421,7 @@ } var = var->next; } - ast_destroy(cfg); + ast_config_destroy(cfg); } } /* Select first conference number not in use */ diff -Nru a/apps/app_privacy.c b/apps/app_privacy.c --- a/apps/app_privacy.c 2005-01-22 20:43:12 -07:00 +++ b/apps/app_privacy.c 2005-01-22 20:43:12 -07:00 @@ -144,7 +144,7 @@ chan->priority+=100; } if (cfg) - ast_destroy(cfg); + ast_config_destroy(cfg); } LOCAL_USER_REMOVE (u); diff -Nru a/apps/app_queue.c b/apps/app_queue.c --- a/apps/app_queue.c 2005-01-22 20:43:12 -07:00 +++ b/apps/app_queue.c 2005-01-22 20:43:12 -07:00 @@ -2578,7 +2578,7 @@ } cat = ast_category_browse(cfg, cat); } - ast_destroy(cfg); + ast_config_destroy(cfg); q = queues; ql = NULL; while(q) { diff -Nru a/apps/app_realtime.c b/apps/app_realtime.c --- a/apps/app_realtime.c 2005-01-22 20:43:12 -07:00 +++ b/apps/app_realtime.c 2005-01-22 20:43:12 -07:00 @@ -185,7 +185,7 @@ pbx_builtin_setvar_helper(chan, vname, itt->value); } - ast_destroy_realtime(var); + ast_variables_destroy(var); } else if (option_verbose > 3) ast_verbose(VERBOSE_PREFIX_4"No Realtime Matches Found.\n"); } diff -Nru a/apps/app_txtcidname.c b/apps/app_txtcidname.c --- a/apps/app_txtcidname.c 2005-01-22 20:43:12 -07:00 +++ b/apps/app_txtcidname.c 2005-01-22 20:43:12 -07:00 @@ -94,7 +94,7 @@ } else { strncpy(h323driver, s, sizeof(h323driver) - 1); } - ast_destroy(cfg); + ast_config_destroy(cfg); return 0; } ast_log(LOG_NOTICE, "No ENUM Config file, using defaults\n"); diff -Nru a/apps/app_voicemail.c b/apps/app_voicemail.c --- a/apps/app_voicemail.c 2005-01-22 20:43:12 -07:00 +++ b/apps/app_voicemail.c 2005-01-22 20:43:12 -07:00 @@ -1144,7 +1144,7 @@ ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); yuck: if (cfg) - ast_destroy(cfg); + ast_config_destroy(cfg); if (fdm) munmap(fdm, fdlen); if (fd > -1) @@ -3105,7 +3105,7 @@ sendpage(myserveremail, vmtmp->pager, todircount, vmtmp->mailbox, chan->cid.cid_num, chan->cid.cid_name, duration, vmtmp); } - ast_destroy(mif); /* or here */ + ast_config_destroy(mif); /* or here */ } /* Leave voicemail for someone */ manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, has_voicemail(ext_context, NULL)); @@ -3364,7 +3364,7 @@ /* Allow pressing '1' to skip envelope / callerid */ if (res == '1') res = 0; - ast_destroy(msg_cfg); + ast_config_destroy(msg_cfg); if (!res) { make_file(vms->fn, sizeof(vms->fn), vms->curdir, vms->curmsg); @@ -5461,7 +5461,7 @@ tmpread = tmpwrite+len; } } - ast_destroy(cfg); + ast_config_destroy(cfg); ast_mutex_unlock(&vmlock); return 0; } else { @@ -5721,7 +5721,7 @@ } } - ast_destroy(msg_cfg); + ast_config_destroy(msg_cfg); if (!res) { make_file(vms->fn, sizeof(vms->fn), vms->curdir, msg); diff -Nru a/asterisk.c b/asterisk.c --- a/asterisk.c 2005-01-22 20:43:12 -07:00 +++ b/asterisk.c 2005-01-22 20:43:12 -07:00 @@ -48,7 +48,6 @@ #include "editline/histedit.h" #include "asterisk.h" #include -#include #include #include #include @@ -1571,7 +1570,7 @@ } v = v->next; } - ast_destroy(cfg); + ast_config_destroy(cfg); } int main(int argc, char *argv[]) @@ -1742,10 +1741,10 @@ ast_readconfig(); if (option_console && !option_verbose) - ast_verbose("[ Initializing Custom Configuration Options]"); + ast_verbose("[ Initializing Custom Configuration Options ]"); /* custom config setup */ register_config_cli(); - read_ast_cust_config(); + read_config_maps(); if (option_console) { diff -Nru a/cdr/cdr_manager.c b/cdr/cdr_manager.c --- a/cdr/cdr_manager.c 2005-01-22 20:43:12 -07:00 +++ b/cdr/cdr_manager.c 2005-01-22 20:43:12 -07:00 @@ -60,7 +60,7 @@ cat = ast_category_browse(cfg, cat); } - ast_destroy(cfg); + ast_config_destroy(cfg); } static int manager_log(struct ast_cdr *cdr) diff -Nru a/cdr/cdr_odbc.c b/cdr/cdr_odbc.c --- a/cdr/cdr_odbc.c 2005-01-22 20:43:12 -07:00 +++ b/cdr/cdr_odbc.c 2005-01-22 20:43:12 -07:00 @@ -331,7 +331,7 @@ table = "cdr"; } - ast_destroy(cfg); + ast_config_destroy(cfg); if (option_verbose > 2) { ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: dsn is %s\n",dsn); ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: username is %s\n",username); diff -Nru a/cdr/cdr_pgsql.c b/cdr/cdr_pgsql.c --- a/cdr/cdr_pgsql.c 2005-01-22 20:43:12 -07:00 +++ b/cdr/cdr_pgsql.c 2005-01-22 20:43:12 -07:00 @@ -336,7 +336,7 @@ return 0; } res = process_my_load_module(cfg); - ast_destroy(cfg); + ast_config_destroy(cfg); return res; } diff -Nru a/cdr/cdr_tds.c b/cdr/cdr_tds.c --- a/cdr/cdr_tds.c 2005-01-22 20:43:12 -07:00 +++ b/cdr/cdr_tds.c 2005-01-22 20:43:12 -07:00 @@ -462,7 +462,7 @@ language = strdupa("us_english"); } - ast_destroy(cfg); + ast_config_destroy(cfg); /* Connect to M$SQL Server */ if (!(login = tds_alloc_login())) diff -Nru a/channels/chan_agent.c b/channels/chan_agent.c --- a/channels/chan_agent.c 2005-01-22 20:43:12 -07:00 +++ b/channels/chan_agent.c 2005-01-22 20:43:12 -07:00 @@ -988,7 +988,7 @@ p = pn; } ast_mutex_unlock(&agentlock); - ast_destroy(cfg); + ast_config_destroy(cfg); return 0; } diff -Nru a/channels/chan_alsa.c b/channels/chan_alsa.c --- a/channels/chan_alsa.c 2005-01-22 20:43:12 -07:00 +++ b/channels/chan_alsa.c 2005-01-22 20:43:12 -07:00 @@ -1011,7 +1011,7 @@ strncpy(outdevname, v->value, sizeof(outdevname)-1); v=v->next; } - ast_destroy(cfg); + ast_config_destroy(cfg); } res = pipe(sndcmd); if (res) { diff -Nru a/channels/chan_h323.c b/channels/chan_h323.c --- a/channels/chan_h323.c 2005-01-22 20:43:12 -07:00 +++ b/channels/chan_h323.c 2005-01-22 20:43:12 -07:00 @@ -1867,7 +1867,7 @@ } cat = ast_category_browse(cfg, cat); } - ast_destroy(cfg); + ast_config_destroy(cfg); /* Register our H.323 aliases if any*/ while (alias) { diff -Nru a/channels/chan_iax2.c b/channels/chan_iax2.c --- a/channels/chan_iax2.c 2005-01-22 20:43:12 -07:00 +++ b/channels/chan_iax2.c 2005-01-22 20:43:12 -07:00 @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -1470,7 +1469,7 @@ } if (!owner) { if (pvt->vars) { - ast_destroy_realtime(pvt->vars); + ast_variables_destroy(pvt->vars); pvt->vars = NULL; } free(pvt); @@ -2170,7 +2169,7 @@ } } } - ast_destroy_realtime(var); + ast_variables_destroy(var); } return peer; } @@ -2201,12 +2200,12 @@ tmp = tmp->next; } } - ast_destroy_realtime(var); + ast_variables_destroy(var); } return user; } -static void realtime_update(const char *peername, struct sockaddr_in *sin) +static void realtime_update_peer(const char *peername, struct sockaddr_in *sin) { char port[10]; char ipaddr[20]; @@ -4090,7 +4089,7 @@ /* We found our match (use the first) */ /* copy vars */ for (v = user->vars ; v ; v = v->next) { - if((tmpvar = ast_new_variable(v->name, v->value))) { + if((tmpvar = ast_variable_new(v->name, v->value))) { tmpvar->next = iaxs[callno]->vars; iaxs[callno]->vars = tmpvar; } @@ -4871,7 +4870,7 @@ p = find_peer(name); if (p) { if (ast_test_flag(p, IAX_TEMPONLY)) - realtime_update(name, sin); + realtime_update_peer(name, sin); if (inaddrcmp(&p->addr, sin)) { if (iax2_regfunk) iax2_regfunk(p->name, 1); @@ -7297,7 +7296,7 @@ if (varname && (varval = strchr(varname,'='))) { *varval = '\0'; varval++; - if((tmpvar = ast_new_variable(varname, varval))) { + if((tmpvar = ast_variable_new(varname, varval))) { tmpvar->next = user->vars; user->vars = tmpvar; } @@ -7421,7 +7420,7 @@ ast_free_ha(user->ha); free_context(user->contexts); if(user->vars) { - ast_destroy_realtime(user->vars); + ast_variables_destroy(user->vars); user->vars = NULL; } free(user); @@ -7688,7 +7687,7 @@ } cat = ast_category_browse(cfg, cat); } - ast_destroy(cfg); + ast_config_destroy(cfg); set_timing(); return capability; } diff -Nru a/channels/chan_mgcp.c b/channels/chan_mgcp.c --- a/channels/chan_mgcp.c 2005-01-22 20:43:12 -07:00 +++ b/channels/chan_mgcp.c 2005-01-22 20:43:12 -07:00 @@ -4144,7 +4144,7 @@ hp = ast_gethostbyname(ourhost, &ahp); if (!hp) { ast_log(LOG_WARNING, "Unable to get our IP address, MGCP disabled\n"); - ast_destroy(cfg); + ast_config_destroy(cfg); return 0; } memcpy(&__ourip, hp->h_addr, sizeof(__ourip)); @@ -4181,7 +4181,7 @@ } } ast_mutex_unlock(&netlock); - ast_destroy(cfg); + ast_config_destroy(cfg); /* SC: send audit only to the new endpoints */ g = gateways; diff -Nru a/channels/chan_modem.c b/channels/chan_modem.c --- a/channels/chan_modem.c 2005-01-22 20:43:12 -07:00 +++ b/channels/chan_modem.c 2005-01-22 20:43:12 -07:00 @@ -972,7 +972,7 @@ } else { ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value); - ast_destroy(cfg); + ast_config_destroy(cfg); ast_mutex_unlock(&iflock); __unload_module(); return -1; @@ -984,7 +984,7 @@ if (ast_load_resource(driver)) { ast_log(LOG_ERROR, "Failed to load driver %s\n", driver); - ast_destroy(cfg); + ast_config_destroy(cfg); ast_mutex_unlock(&iflock); __unload_module(); return -1; @@ -1055,11 +1055,11 @@ if (ast_channel_register(type, tdesc, /* XXX Don't know our types -- maybe we should register more than one XXX */ AST_FORMAT_SLINEAR, modem_request)) { ast_log(LOG_ERROR, "Unable to register channel class %s\n", type); - ast_destroy(cfg); + ast_config_destroy(cfg); __unload_module(); return -1; } - ast_destroy(cfg); + ast_config_destroy(cfg); /* And start the monitor for the first time */ restart_monitor(); return 0; diff -Nru a/channels/chan_oss.c b/channels/chan_oss.c --- a/channels/chan_oss.c 2005-01-22 20:43:12 -07:00 +++ b/channels/chan_oss.c 2005-01-22 20:43:12 -07:00 @@ -1045,7 +1045,7 @@ playbackonly = ast_true(v->value); v=v->next; } - ast_destroy(cfg); + ast_config_destroy(cfg); } ast_pthread_create(&sthread, NULL, sound_thread, NULL); return 0; diff -Nru a/channels/chan_phone.c b/channels/chan_phone.c --- a/channels/chan_phone.c 2005-01-22 20:43:12 -07:00 +++ b/channels/chan_phone.c 2005-01-22 20:43:12 -07:00 @@ -1255,7 +1255,7 @@ } else { ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value); - ast_destroy(cfg); + ast_config_destroy(cfg); ast_mutex_unlock(&iflock); __unload_module(); return -1; @@ -1316,11 +1316,11 @@ AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW : prefformat, phone_request)) { ast_log(LOG_ERROR, "Unable to register channel class %s\n", type); - ast_destroy(cfg); + ast_config_destroy(cfg); __unload_module(); return -1; } - ast_destroy(cfg); + ast_config_destroy(cfg); /* And start the monitor for the first time */ restart_monitor(); return 0; diff -Nru a/channels/chan_sip.c b/channels/chan_sip.c --- a/channels/chan_sip.c 2005-01-22 20:43:12 -07:00 +++ b/channels/chan_sip.c 2005-01-22 20:43:12 -07:00 @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -1137,7 +1136,7 @@ while(tmp) { if (!strcasecmp(tmp->name, "type") && !strcasecmp(tmp->value, "user")) { - ast_destroy_realtime(var); + ast_variables_destroy(var); return NULL; } tmp = tmp->next; @@ -1146,7 +1145,7 @@ peer = build_peer(peername, var, 1); if (peer) ast_set_flag(peer, SIP_REALTIME); - ast_destroy_realtime(var); + ast_variables_destroy(var); return peer; } @@ -1180,7 +1179,7 @@ { ast_free_ha(user->ha); if(user->vars) { - ast_destroy_realtime(user->vars); + ast_variables_destroy(user->vars); user->vars = NULL; } if (ast_test_flag(user, SIP_REALTIME)) @@ -1206,7 +1205,7 @@ while (tmp) { if (!strcasecmp(tmp->name, "type") && !strcasecmp(tmp->value, "peer")) { - ast_destroy_realtime(var); + ast_variables_destroy(var); return NULL; } tmp = tmp->next; @@ -1220,7 +1219,7 @@ /* Add some finishing touches, addresses, etc */ ast_set_flag(user, SIP_REALTIME); } - ast_destroy_realtime(var); + ast_variables_destroy(var); return user; } @@ -1531,7 +1530,7 @@ } ast_mutex_destroy(&p->lock); if(p->vars) { - ast_destroy_realtime(p->vars); + ast_variables_destroy(p->vars); p->vars = NULL; } free(p); @@ -2295,7 +2294,7 @@ ast_log(LOG_WARNING, "Unable to create RTP session: %s\n", strerror(errno)); ast_mutex_destroy(&p->lock); if(p->vars) { - ast_destroy_realtime(p->vars); + ast_variables_destroy(p->vars); p->vars = NULL; } free(p); @@ -5569,7 +5568,7 @@ ast_copy_flags(p, user, SIP_TRUSTRPID | SIP_USECLIENTCODE | SIP_NAT | SIP_PROG_INBAND | SIP_OSPAUTH); /* copy vars */ for (v = user->vars ; v ; v = v->next) { - if((tmpvar = ast_new_variable(v->name, v->value))) { + if((tmpvar = ast_variable_new(v->name, v->value))) { tmpvar->next = p->vars; p->vars = tmpvar; } @@ -8693,7 +8692,7 @@ if (varname && (varval = strchr(varname,'='))) { *varval = '\0'; varval++; - if((tmpvar = ast_new_variable(varname, varval))) { + if((tmpvar = ast_variable_new(varname, varval))) { tmpvar->next = user->vars; user->vars = tmpvar; } @@ -9252,7 +9251,7 @@ if (!hp) { ast_log(LOG_WARNING, "Unable to get IP address for %s, SIP disabled\n", ourhost); if (!__ourip.s_addr) { - ast_destroy(cfg); + ast_config_destroy(cfg); return 0; } } else @@ -9297,11 +9296,11 @@ ast_mutex_unlock(&netlock); /* Release configuration from memory */ - ast_destroy(cfg); + ast_config_destroy(cfg); /* Load the list of manual NOTIFY types to support */ if (notify_types) - ast_destroy(notify_types); + ast_config_destroy(notify_types); notify_types = ast_load(notify_config); return 0; @@ -9740,7 +9739,7 @@ /* Free associated memory */ ast_mutex_destroy(&pl->lock); if(pl->vars) { - ast_destroy_realtime(pl->vars); + ast_variables_destroy(pl->vars); pl->vars = NULL; } free(pl); diff -Nru a/channels/chan_skinny.c b/channels/chan_skinny.c --- a/channels/chan_skinny.c 2005-01-22 20:43:12 -07:00 +++ b/channels/chan_skinny.c 2005-01-22 20:43:12 -07:00 @@ -2600,7 +2600,7 @@ hp = ast_gethostbyname(ourhost, &ahp); if (!hp) { ast_log(LOG_WARNING, "Unable to get our IP address, Skinny disabled\n"); - ast_destroy(cfg); + ast_config_destroy(cfg); return 0; } memcpy(&__ourip, hp->h_addr, sizeof(__ourip)); @@ -2636,7 +2636,7 @@ skinnysock = socket(AF_INET, SOCK_STREAM, 0); if(setsockopt(skinnysock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) { ast_log(LOG_ERROR, "Set Socket Options failed: errno %d, %s", errno, strerror(errno)); - ast_destroy(cfg); + ast_config_destroy(cfg); return 0; } @@ -2649,7 +2649,7 @@ strerror(errno)); close(skinnysock); skinnysock = -1; - ast_destroy(cfg); + ast_config_destroy(cfg); return 0; } @@ -2659,7 +2659,7 @@ strerror(errno)); close(skinnysock); skinnysock = -1; - ast_destroy(cfg); + ast_config_destroy(cfg); return 0; } @@ -2673,7 +2673,7 @@ ast_mutex_unlock(&netlock); /* and unload the configuration when were done */ - ast_destroy(cfg); + ast_config_destroy(cfg); return 0; } diff -Nru a/channels/chan_vpb.c b/channels/chan_vpb.c --- a/channels/chan_vpb.c 2005-01-22 20:43:12 -07:00 +++ b/channels/chan_vpb.c 2005-01-22 20:43:12 -07:00 @@ -2530,7 +2530,7 @@ done: (void)0; } ast_mutex_unlock(&iflock); - ast_destroy(cfg); + ast_config_destroy(cfg); if (!error && ast_channel_register(type, tdesc, prefformat, vpb_request) != 0) { ast_log(LOG_ERROR, "Unable to register channel class %s\n", type); diff -Nru a/channels/chan_zap.c b/channels/chan_zap.c --- a/channels/chan_zap.c 2005-01-22 20:43:12 -07:00 +++ b/channels/chan_zap.c 2005-01-22 20:43:12 -07:00 @@ -9321,7 +9321,7 @@ if (reload == 0) { if (cur_signalling < 0) { ast_log(LOG_ERROR, "Signalling must be specified before any channels are.\n"); - ast_destroy(cfg); + ast_config_destroy(cfg); ast_mutex_unlock(&iflock); return -1; } @@ -9333,13 +9333,13 @@ if (!strcasecmp(v->name, "crv")) { if (sscanf(c, "%d:%n", &trunkgroup, &y) != 1) { ast_log(LOG_WARNING, "CRV must begin with trunkgroup followed by a colon at line %d\n", v->lineno); - ast_destroy(cfg); + ast_config_destroy(cfg); ast_mutex_unlock(&iflock); return -1; } if (trunkgroup < 1) { ast_log(LOG_WARNING, "CRV trunk group must be a postive number at line %d\n", v->lineno); - ast_destroy(cfg); + ast_config_destroy(cfg); ast_mutex_unlock(&iflock); return -1; } @@ -9352,7 +9352,7 @@ } if (!pri) { ast_log(LOG_WARNING, "No such trunk group %d at CRV declaration at line %d\n", trunkgroup, v->lineno); - ast_destroy(cfg); + ast_config_destroy(cfg); ast_mutex_unlock(&iflock); return -1; } @@ -9370,7 +9370,7 @@ found_pseudo = 1; } else { ast_log(LOG_ERROR, "Syntax error parsing '%s' at '%s'\n", v->value, chan); - ast_destroy(cfg); + ast_config_destroy(cfg); ast_mutex_unlock(&iflock); return -1; } @@ -9401,7 +9401,7 @@ ast_log(LOG_ERROR, "Unable to reconfigure channel '%s'\n", v->value); else ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value); - ast_destroy(cfg); + ast_config_destroy(cfg); ast_mutex_unlock(&iflock); return -1; } @@ -9741,7 +9741,7 @@ switchtype = PRI_SWITCH_QSIG; else { ast_log(LOG_ERROR, "Unknown switchtype '%s'\n", v->value); - ast_destroy(cfg); + ast_config_destroy(cfg); ast_mutex_unlock(&iflock); return -1; } @@ -9923,7 +9923,7 @@ } } ast_mutex_unlock(&iflock); - ast_destroy(cfg); + ast_config_destroy(cfg); #ifdef ZAPATA_PRI if (!reload) { for (x=0;x #endif #include -#include #include #include #include @@ -40,8 +39,7 @@ #define COMMENT_META ';' #define COMMENT_TAG '-' -static int ast_cust_config=0; -static config_static_func *global_load_func; +static char *extconfig_conf = "extconfig.conf"; static struct ast_config_map { struct ast_config_map *next; @@ -50,44 +48,32 @@ char *database; char *table; char stuff[0]; -} *maps = NULL; +} *config_maps = NULL; -AST_MUTEX_DEFINE_STATIC(ast_cust_config_lock); -static struct ast_config_reg *ast_cust_config_list; -static char *config_conf_file = "extconfig.conf"; +AST_MUTEX_DEFINE_STATIC(config_lock); +static struct ast_config_engine *config_engine_list; -void ast_destroy_realtime(struct ast_variable *v) -{ - struct ast_variable *vn; - while(v) { - vn = v; - v = v->next; - free(vn); - } -} +#define MAX_INCLUDE_LEVEL 10 -void ast_category_destroy(struct ast_category *cat) -{ - ast_destroy_realtime(cat->root); - free(cat); -} - -void ast_destroy(struct ast_config *ast) -{ - struct ast_category *cat, *catn; - - if (!ast) - return; - - cat = ast->root; - while(cat) { - ast_destroy_realtime(cat->root); - catn = cat; - cat = cat->next; - free(catn); - } - free(ast); -} +struct ast_comment { + struct ast_comment *next; + char cmt[0]; +}; + +struct ast_category { + char name[80]; + struct ast_variable *root; + struct ast_variable *last; + struct ast_category *next; +}; + +struct ast_config { + struct ast_category *root; + struct ast_category *last; + struct ast_category *current; + int include_level; + int max_include_level; +}; int ast_true(const char *s) { @@ -119,6 +105,40 @@ return 0; } +struct ast_variable *ast_variable_new(char *name, char *value) +{ + struct ast_variable *variable; + int length = strlen(name) + strlen(value) + 2 + sizeof(struct ast_variable); + variable = malloc(length); + if (variable) { + memset(variable, 0, length); + variable->name = variable->stuff; + variable->value = variable->stuff + strlen(name) + 1; + strcpy(variable->name,name); + strcpy(variable->value,value); + } + return variable; +} + +void ast_variable_append(struct ast_category *category, struct ast_variable *variable) +{ + if (category->last) + category->last->next = variable; + else + category->root = variable; + category->last = variable; +} + +void ast_variables_destroy(struct ast_variable *v) +{ + struct ast_variable *vn; + while(v) { + vn = v; + v = v->next; + free(vn); + } +} + struct ast_variable *ast_variable_browse(const struct ast_config *config, const char *category) { struct ast_category *cat; @@ -169,6 +189,17 @@ return NULL; } +struct ast_category *ast_category_new(char *name) +{ + struct ast_category *category; + category = malloc(sizeof(struct ast_category)); + if (category) { + memset(category, 0, sizeof(struct ast_category)); + strncpy(category->name, name, sizeof(category->name) - 1); + } + return category; +} + struct ast_category *ast_category_get(const struct ast_config *config, const char *category_name) { struct ast_category *category = config->root; @@ -187,74 +218,112 @@ return !!ast_category_get(config, category_name); } +void ast_category_append(struct ast_config *config, struct ast_category *category) +{ + if (config->last) + config->last->next = category; + else + config->root = category; + config->last = category; + config->current = category; +} -static struct ast_config_reg *get_ast_cust_config_keyword(const char *name, char *database, int dbsiz, char *table, int tabsiz) +void ast_category_destroy(struct ast_category *cat) { - struct ast_config_reg *reg,*ret=NULL; - struct ast_config_map *map; + ast_variables_destroy(cat->root); + free(cat); +} - ast_mutex_lock(&ast_cust_config_lock); - map = maps; - while(map) { - if (!strcasecmp(name, map->name)) { - strncpy(database, map->database, dbsiz - 1); - if (map->table) - strncpy(table, map->table, tabsiz - 1); +char *ast_category_browse(struct ast_config *config, char *prev) +{ + struct ast_category *cat; + if (!prev) { + if (config->root) + return config->root->name; + else + return NULL; + } + cat = config->root; + while (cat) { + if (cat->name == prev) { + if (cat->next) + return cat->next->name; else - strncpy(table, name, tabsiz - 1); - break; + return NULL; } - map = map->next; + cat = cat->next; } - if (map) { - for (reg=ast_cust_config_list;reg && !ret;reg=reg->next) { - if (!strcmp(reg->name,map->driver)) - ret=reg; + cat = config->root; + while (cat) { + if (!strcasecmp(cat->name, prev)) { + if (cat->next) + return cat->next->name; + else + return NULL; } + cat = cat->next; } - ast_mutex_unlock(&ast_cust_config_lock); - return ret; + return NULL; +} + +struct ast_variable *ast_category_detach_variables(struct ast_category *cat) +{ + struct ast_variable *v; + + v = cat->root; + cat->root = NULL; + return v; } -void ast_config_destroy_all(void) +void ast_category_rename(struct ast_category *cat, const char *name) { - struct ast_config_reg *key; - ast_mutex_lock(&ast_cust_config_lock); - for (key=ast_cust_config_list;key;key=key->next) { - ast_config_deregister(key); + strncpy(cat->name, name, sizeof(cat->name) - 1); +} + +struct ast_config *ast_config_new(void) +{ + struct ast_config *config; + + config = malloc(sizeof(*config)); + if (config) { + memset(config, 0, sizeof(*config)); + config->max_include_level = MAX_INCLUDE_LEVEL; } - ast_cust_config_list = NULL; - ast_mutex_unlock(&ast_cust_config_lock); + + return config; } -static struct ast_config_reg *get_config_registrations(void) +void ast_config_destroy(struct ast_config *cfg) { - return ast_cust_config_list; + struct ast_category *cat, *catn; + + if (!cfg) + return; + + cat = cfg->root; + while(cat) { + ast_variables_destroy(cat->root); + catn = cat; + cat = cat->next; + free(catn); + } + free(cfg); } -void ast_category_append(struct ast_config *config, struct ast_category *category) +struct ast_category *ast_config_get_current_category(const struct ast_config *cfg) { - if (config->last) - config->last->next = category; - else - config->root = category; - config->last = category; + return cfg->current; } -static void variable_append(struct ast_category *category, struct ast_variable *variable) +void ast_config_set_current_category(struct ast_config *cfg, struct ast_category *cat) { - if (category->last) - category->last->next = variable; - else - category->root = variable; - category->last = variable; + cfg->current = cat; } -static int cfg_process(struct ast_config *tmp, struct ast_category **cat, char *buf, int lineno, const char *configfile, int includelevel) +static int process_text_line(struct ast_config *cfg, struct ast_category **cat, char *buf, int lineno, const char *configfile) { char *c; char *cur; - char *arg=NULL; struct ast_variable *v; int object; @@ -267,19 +336,19 @@ /* A category header */ c = strchr(cur, ']'); if (!c) { - ast_destroy(tmp); + ast_config_destroy(cfg); ast_log(LOG_WARNING, "parse error: no closing ']', line %d of %s\n", lineno, configfile); return -1; } *c = '\0'; cur++; - *cat = ast_new_category(cur); + *cat = ast_category_new(cur); if (!*cat) { - ast_destroy(tmp); + ast_config_destroy(cfg); ast_log(LOG_WARNING, "Out of memory, line %d of %s\n", lineno, configfile); return -1; } - ast_category_append(tmp, *cat); + ast_category_append(cfg, *cat); } else if (cur[0] == '#') { /* A directive */ cur++; @@ -309,21 +378,8 @@ break; } - if((c = strchr(cur,':'))) { - *c = '\0'; - c++; - arg = c; - } - - if (includelevel < MAX_INCLUDE_LEVEL) { - if(arg && cur) { - ast_log(LOG_WARNING, "Including files with explicit config engine no longer permitted. Please use extconfig.conf to specify all mappings\n"); - } else { - if (!ast_internal_load(cur, tmp, cat, includelevel + 1)) - return -1; - } - } else - ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", includelevel); + if (!ast_internal_load(cur, cfg)) + return -1; } else ast_log(LOG_WARNING, "Directive '#include' needs an argument (filename) at line %d of %s\n", lineno, configfile); } @@ -334,7 +390,7 @@ if (!*cat) { ast_log(LOG_WARNING, "parse error: No category context for line %d of %s\n", lineno, configfile); - ast_destroy(tmp); + ast_config_destroy(cfg); return -1; } c = strchr(cur, '='); @@ -347,15 +403,15 @@ c++; } else object = 0; - v = ast_new_variable(ast_strip(cur), ast_strip(c)); + v = ast_variable_new(ast_strip(cur), ast_strip(c)); if (v) { v->lineno = lineno; v->object = object; /* Put and reset comments */ v->blanklines = 0; - variable_append(*cat, v); + ast_variable_append(*cat, v); } else { - ast_destroy(tmp); + ast_config_destroy(cfg); ast_log(LOG_WARNING, "Out of memory, line %d\n", lineno); return -1; } @@ -367,154 +423,24 @@ return 0; } -int ast_save(char *configfile, struct ast_config *cfg, char *generator) -{ - FILE *f; - char fn[256]; - char date[256]=""; - time_t t; - struct ast_variable *var; - struct ast_category *cat; - int blanklines = 0; - if (configfile[0] == '/') { - strncpy(fn, configfile, sizeof(fn)-1); - } else { - snprintf(fn, sizeof(fn), "%s/%s", AST_CONFIG_DIR, configfile); - } - time(&t); - strncpy(date, ctime(&t), sizeof(date) - 1); - if ((f = fopen(fn, "w"))) { - if ((option_verbose > 1) && !option_debug) - ast_verbose( VERBOSE_PREFIX_2 "Saving '%s': ", fn); - fprintf(f, ";!\n"); - fprintf(f, ";! Automatically generated configuration file\n"); - fprintf(f, ";! Filename: %s (%s)\n", configfile, fn); - fprintf(f, ";! Generator: %s\n", generator); - fprintf(f, ";! Creation Date: %s", date); - fprintf(f, ";!\n"); - cat = cfg->root; - while(cat) { - /* Dump section with any appropriate comment */ - fprintf(f, "[%s]\n", cat->name); - var = cat->root; - while(var) { - if (var->sameline) - fprintf(f, "%s %s %s ; %s\n", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt); - else - fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value); - if (var->blanklines) { - blanklines = var->blanklines; - while (blanklines) { - fprintf(f, "\n"); - blanklines--; - } - } - - var = var->next; - } -#if 0 - /* Put an empty line */ - fprintf(f, "\n"); -#endif - cat = cat->next; - } - } else { - if (option_debug) - printf("Unable to open for writing: %s\n", fn); - else if (option_verbose > 1) - printf( "Unable to write (%s)", strerror(errno)); - return -1; - } - fclose(f); - return 0; -} - -struct ast_variable *ast_load_realtime(const char *family, ...) -{ - struct ast_config_reg *reg; - char db[256]=""; - char table[256]=""; - struct ast_variable *res=NULL; - va_list ap; - va_start(ap, family); - reg = get_ast_cust_config_keyword(family, db, sizeof(db), table, sizeof(table)); - if (reg && reg->realtime_func) - res = reg->realtime_func(db, table, ap); - va_end(ap); - return res; -} - -struct ast_config *ast_load_realtime_multientry(const char *family, ...) -{ - struct ast_config_reg *reg; - char db[256]=""; - char table[256]=""; - struct ast_config *res=NULL; - va_list ap; - va_start(ap, family); - reg = get_ast_cust_config_keyword(family, db, sizeof(db), table, sizeof(table)); - if (reg && reg->realtime_multi_func) - res = reg->realtime_multi_func(db, table, ap); - va_end(ap); - return res; -} - -int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...) -{ - struct ast_config_reg *reg; - int res = -1; - char db[256]=""; - char table[256]=""; - va_list ap; - va_start(ap, lookup); - reg = get_ast_cust_config_keyword(family, db, sizeof(db), table, sizeof(table)); - if (reg && reg->update_func) - res = reg->update_func(db, table, keyfield, lookup, ap); - va_end(ap); - return res; -} - -struct ast_config *ast_internal_load(const char *configfile, struct ast_config *tmp, struct ast_category **cat, int includelevel) +static struct ast_config *config_text_file_load(const char *database, const char *table, const char *filename, struct ast_config *cfg) { char fn[256]; char buf[8192]; - char db[256]; - char table[256]; + char *new_buf, *comment_p, *process_buf; FILE *f; int lineno=0; int comment = 0, nest[MAX_NESTED_COMMENTS]; + struct ast_category *cat = NULL; - struct ast_config_reg *reg=NULL; - config_static_func *load_func; - char *comment_p, *process_buf, *new_buf=NULL; - - load_func=NULL; - if (strcmp(configfile,config_conf_file) && strcmp(configfile,"asterisk.conf") && ast_cust_config_list) { - if (global_load_func) { - load_func = global_load_func; - } else { - reg = get_ast_cust_config_keyword(configfile, db, sizeof(db), table, sizeof(table)); - if (reg && reg->static_func) { - load_func = reg->static_func; - } else { - reg = get_ast_cust_config_keyword(configfile, db, sizeof(db), table, sizeof(table)); - if (reg && reg->static_func) - global_load_func = load_func = reg->static_func; - } - } - - if (load_func) { - ast_log(LOG_NOTICE,"Loading Config %s via %s engine\n",configfile,reg && reg->name ? reg->name : "global"); - if((tmp = load_func(db, table, configfile, tmp, cat, includelevel))) - return tmp; - } - } + cat = ast_config_get_current_category(cfg); - if (configfile[0] == '/') { - strncpy(fn, configfile, sizeof(fn)-1); + if (filename[0] == '/') { + strncpy(fn, filename, sizeof(fn)-1); } else { - snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, configfile); + snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, filename); } + #ifdef AST_INCLUDE_GLOB { int glob_ret; @@ -546,13 +472,6 @@ ast_log(LOG_DEBUG, "Parsing %s\n", fn); else if (option_verbose > 2) ast_verbose("Found\n"); - if (!tmp) - tmp = ast_new_config(); - if (!tmp) { - ast_log(LOG_WARNING, "Out of memory\n"); - fclose(f); - return tmp; - } while(!feof(f)) { lineno++; if (fgets(buf, sizeof(buf), f)) { @@ -603,8 +522,8 @@ new_buf = comment_p + 1; } } - if (process_buf && cfg_process(tmp, cat, process_buf, lineno, configfile, includelevel)) { - tmp = NULL; + if (process_buf && process_text_line(cfg, &cat, process_buf, lineno, filename)) { + cfg = NULL; break; } } @@ -620,7 +539,7 @@ ast_log(LOG_WARNING,"Unterminated comment detected beginning on line %d\n", nest[comment]); } #ifdef AST_INCLUDE_GLOB - if (!tmp) + if (!cfg) break; } globfree(&globbuf); @@ -628,233 +547,342 @@ } #endif - return tmp; + return cfg; } -int ast_config_register(struct ast_config_reg *new) +int config_text_file_save(char *configfile, struct ast_config *cfg, char *generator) { - struct ast_config_reg *ptr; - ast_mutex_lock(&ast_cust_config_lock); - if (!ast_cust_config_list) { - ast_cust_config_list = new; + FILE *f; + char fn[256]; + char date[256]=""; + time_t t; + struct ast_variable *var; + struct ast_category *cat; + int blanklines = 0; + + if (configfile[0] == '/') { + strncpy(fn, configfile, sizeof(fn)-1); } else { - for(ptr=ast_cust_config_list;ptr->next;ptr=ptr->next); - ptr->next = new; + snprintf(fn, sizeof(fn), "%s/%s", AST_CONFIG_DIR, configfile); } - ast_mutex_unlock(&ast_cust_config_lock); - ast_log(LOG_NOTICE,"Registered Config Engine %s\n",new->name); - return 1; -} - -int ast_config_deregister(struct ast_config_reg *del) -{ - struct ast_config_reg *ptr=NULL,*last=NULL; - ast_mutex_lock(&ast_cust_config_lock); - for (ptr=ast_cust_config_list;ptr;ptr=ptr->next) { - if (ptr == del) { - if (last && ptr->next) { - last->next = ptr->next; - } else if (last && ! ptr->next) { - last->next = NULL; - } else if (!last && ptr->next) { - ast_cust_config_list = ptr->next; - } else if (!last && !ptr->next) { - ast_cust_config_list = NULL; + time(&t); + strncpy(date, ctime(&t), sizeof(date) - 1); + if ((f = fopen(fn, "w"))) { + if ((option_verbose > 1) && !option_debug) + ast_verbose( VERBOSE_PREFIX_2 "Saving '%s': ", fn); + fprintf(f, ";!\n"); + fprintf(f, ";! Automatically generated configuration file\n"); + fprintf(f, ";! Filename: %s (%s)\n", configfile, fn); + fprintf(f, ";! Generator: %s\n", generator); + fprintf(f, ";! Creation Date: %s", date); + fprintf(f, ";!\n"); + cat = cfg->root; + while(cat) { + /* Dump section with any appropriate comment */ + fprintf(f, "[%s]\n", cat->name); + var = cat->root; + while(var) { + if (var->sameline) + fprintf(f, "%s %s %s ; %s\n", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt); + else + fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value); + if (var->blanklines) { + blanklines = var->blanklines; + while (blanklines--) + fprintf(f, "\n"); + } + + var = var->next; } +#if 0 + /* Put an empty line */ + fprintf(f, "\n"); +#endif + cat = cat->next; } - last = ptr; + } else { + if (option_debug) + printf("Unable to open for writing: %s\n", fn); + else if (option_verbose > 1) + printf( "Unable to write (%s)", strerror(errno)); + return -1; } - ast_mutex_unlock(&ast_cust_config_lock); + fclose(f); return 0; } -int ast_cust_config_active(void) { - return (ast_cust_config >0) ? 1 : 0; +static void clear_config_maps(void) +{ + struct ast_config_map *map; + + ast_mutex_lock(&config_lock); + + while (config_maps) { + map = config_maps; + config_maps = config_maps->next; + free(map); + } + + ast_mutex_unlock(&config_lock); } -struct ast_config *ast_load(char *configfile) +void read_config_maps(void) { - struct ast_category *category = NULL; + struct ast_config *config; + struct ast_variable *v; + struct ast_config_map *map; + int length; + char *driver, *table, *database, *stringp; + + clear_config_maps(); + + config = ast_config_new(); + config->max_include_level = 1; + config = ast_internal_load(extconfig_conf, config); + if (!config) + return; - return ast_internal_load(configfile, NULL, &category, 0); + for (v = ast_variable_browse(config, "settings"); v; v = v->next) { + stringp = v->value; + driver = strsep(&stringp, ","); + database = strsep(&stringp, ","); + table = strsep(&stringp, ","); + + if (!strcmp(v->name, extconfig_conf) || !strcmp(v->name, "asterisk.conf")) { + ast_log(LOG_WARNING, "Cannot bind asterisk.conf or extconfig.conf!\n"); + continue; + } + + if (!driver || !database) + continue; + + length = sizeof(*map); + length += strlen(v->name) + 1; + length += strlen(driver) + 1; + length += strlen(database) + 1; + if (table) + length += strlen(table) + 1; + map = malloc(length); + + if (!map) + continue; + + memset(map, 0, length); + map->name = map->stuff; + strcpy(map->name, v->name); + map->driver = map->name + strlen(map->name) + 1; + strcpy(map->driver, driver); + map->database = map->driver + strlen(map->driver) + 1; + strcpy(map->database, database); + if (table) { + map->table = map->database + strlen(map->database) + 1; + strcpy(map->table, table); + } + map->next = config_maps; + + if (option_verbose > 1) + ast_verbose(VERBOSE_PREFIX_2 "Binding %s to %s/%s/%s\n", + map->name, map->driver, map->database, map->table ? map->table : map->name); + + config_maps = map; + } + + ast_config_destroy(config); } -char *ast_category_browse(struct ast_config *config, char *prev) -{ - struct ast_category *cat; - if (!prev) { - if (config->root) - return config->root->name; - else - return NULL; +int ast_config_engine_register(struct ast_config_engine *new) +{ + struct ast_config_engine *ptr; + + ast_mutex_lock(&config_lock); + if (!config_engine_list) { + config_engine_list = new; + } else { + for(ptr = config_engine_list; ptr->next; ptr=ptr->next); + ptr->next = new; } - cat = config->root; - while(cat) { - if (cat->name == prev) { - if (cat->next) - return cat->next->name; + ast_mutex_unlock(&config_lock); + ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name); + return 1; +} + +int ast_config_engine_deregister(struct ast_config_engine *del) +{ + struct ast_config_engine *ptr, *last=NULL; + + ast_mutex_lock(&config_lock); + for (ptr = config_engine_list; ptr; ptr=ptr->next) { + if (ptr == del) { + if (last) + last->next = ptr->next; else - return NULL; + config_engine_list = ptr->next; + break; } - cat = cat->next; + last = ptr; } - cat = config->root; - while(cat) { - if (!strcasecmp(cat->name, prev)) { - if (cat->next) - return cat->next->name; + ast_mutex_unlock(&config_lock); + return 0; +} + +static struct ast_config_engine *find_engine(const char *filename, char *database, int dbsiz, char *table, int tabsiz) +{ + struct ast_config_engine *eng, *ret=NULL; + struct ast_config_map *map; + + ast_mutex_lock(&config_lock); + map = config_maps; + while (map) { + if (!strcasecmp(filename, map->name)) { + strncpy(database, map->database, dbsiz-1); + if (map->table) + strncpy(table, map->table, tabsiz-1); else - return NULL; + strncpy(table, filename, tabsiz-1); + break; } - cat = cat->next; + map = map->next; } - return NULL; + if (map) { + for (eng = config_engine_list; eng; eng = eng->next) { + if (!strcmp(eng->name, map->driver)) { + ret = eng; + break; + } + } + } + ast_mutex_unlock(&config_lock); + return ret; } +static struct ast_config_engine text_file_engine = { + .name = "text", + .load_func = config_text_file_load, +}; -struct ast_config *ast_new_config(void) +struct ast_config *ast_internal_load(const char *filename, struct ast_config *cfg) { - struct ast_config *config; - config = malloc(sizeof(struct ast_config)); - memset(config,0,sizeof(struct ast_config)); - return config; -} + char db[256]; + char table[256]; + struct ast_config_engine *loader = &text_file_engine; + struct ast_config *result; -struct ast_category *ast_new_category(char *name) -{ - struct ast_category *category; - category = malloc(sizeof(struct ast_category)); - if (category) { - memset(category, 0, sizeof(struct ast_category)); - strncpy(category->name, name, sizeof(category->name) - 1); + if (cfg->include_level == cfg->max_include_level) { + ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level); + return NULL; } - return category; + + cfg->include_level++; + + if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) { + struct ast_config_engine *eng; + + eng = find_engine(filename, db, sizeof(db), table, sizeof(table)); + if (eng && eng->load_func) { + loader = eng; + } else { + eng = find_engine("global", db, sizeof(db), table, sizeof(table)); + if (eng && eng->load_func) + loader = eng; + } + } + + result = loader->load_func(db, table, filename, cfg); + if (result) + result->include_level--; + + return result; } -struct ast_variable *ast_new_variable(char *name, char *value) +struct ast_config *ast_load(char *filename) { - struct ast_variable *variable; - int length = strlen(name) + strlen(value) + 2 + sizeof(struct ast_variable); - variable = malloc(length); - if (variable) { - memset(variable, 0, length); - variable->name = variable->stuff; - variable->value = variable->stuff + strlen(name) + 1; - strcpy(variable->name,name); - strcpy(variable->value,value); - } - return variable; + struct ast_config *cfg; + + cfg = ast_config_new(); + if (cfg) + return ast_internal_load(filename, cfg); + else + return NULL; } -int ast_cust_config_register(struct ast_config_reg *new) +struct ast_variable *ast_load_realtime(const char *family, ...) { - ast_config_register(new); - read_ast_cust_config(); - return 1; + struct ast_config_engine *eng; + char db[256]=""; + char table[256]=""; + struct ast_variable *res=NULL; + va_list ap; + + va_start(ap, family); + eng = find_engine(family, db, sizeof(db), table, sizeof(table)); + if (eng && eng->realtime_func) + res = eng->realtime_func(db, table, ap); + va_end(ap); + return res; } -int ast_cust_config_deregister(struct ast_config_reg *new) + +struct ast_config *ast_load_realtime_multientry(const char *family, ...) { - ast_config_deregister(new); - read_ast_cust_config(); - return 1; + struct ast_config_engine *eng; + char db[256]=""; + char table[256]=""; + struct ast_config *res=NULL; + va_list ap; + + va_start(ap, family); + eng = find_engine(family, db, sizeof(db), table, sizeof(table)); + if (eng && eng->realtime_multi_func) + res = eng->realtime_multi_func(db, table, ap); + va_end(ap); + return res; } -static void clear_cust_keywords(void) +int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...) { - struct ast_config_map *map, *prev; - ast_mutex_lock(&ast_cust_config_lock); - map = maps; - while(map) { - prev = map; - map = map->next; - free(prev); - } - maps = NULL; - ast_mutex_unlock(&ast_cust_config_lock); + struct ast_config_engine *eng; + int res = -1; + char db[256]=""; + char table[256]=""; + va_list ap; + + va_start(ap, lookup); + eng = find_engine(family, db, sizeof(db), table, sizeof(table)); + if (eng && eng->update_func) + res = eng->update_func(db, table, keyfield, lookup, ap); + va_end(ap); + return res; } static int config_command(int fd, int argc, char **argv) { - struct ast_config_reg *key; + struct ast_config_engine *eng; struct ast_config_map *map; - ast_cli(fd,"\n\n"); - ast_mutex_lock(&ast_cust_config_lock); - for (key=get_config_registrations();key;key=key->next) { - ast_cli(fd,"\nConfig Engine: %s\n",key->name); - map = maps; - while(map) { - if (!strcasecmp(map->driver, key->name)) - ast_cli(fd,"===> %s (db=%s, table=%s)\n",map->name, map->database, map->table ? map->table : map->name); + ast_cli(fd, "\n\n"); + ast_mutex_lock(&config_lock); + for (eng = config_engine_list; eng; eng = eng->next) { + ast_cli(fd, "\nConfig Engine: %s\n", eng->name); + map = config_maps; + while (map) { + if (!strcasecmp(map->driver, eng->name)) { + ast_cli(fd, "===> %s (db=%s, table=%s)\n", map->name, map->database, map->table ? map->table : map->name); + break; + } map = map->next; } } - ast_mutex_unlock(&ast_cust_config_lock); + ast_mutex_unlock(&config_lock); ast_cli(fd,"\n\n"); return 0; } static struct ast_cli_entry config_command_struct = { - { "show","config","handles", NULL }, config_command, - "Show Config Handles", NULL }; + { "show","config","handles" }, config_command, "Show Config Handles" +}; int register_config_cli() { return ast_cli_register(&config_command_struct); } -int read_ast_cust_config(void) -{ - char *cfg = config_conf_file; - struct ast_config *config; - struct ast_variable *v; - struct ast_config_map *map; - int length; - char *driver, *table, *database, *stringp; - - clear_cust_keywords(); - config = ast_load(cfg); - if (config) { - for (v = ast_variable_browse(config,"settings");v;v=v->next) { - stringp = v->value; - driver = strsep(&stringp, ","); - database = strsep(&stringp, ","); - table = strsep(&stringp, ","); - - if (!strcmp(v->name,config_conf_file) || !strcmp(v->name,"asterisk.conf")) { - ast_log(LOG_WARNING, "Cannot bind asterisk.conf or extconfig.conf!\n"); - } else if (driver && database) { - length = sizeof(struct ast_config_map); - length += strlen(v->name) + 1; - length += strlen(driver) + 1; - length += strlen(database) + 1; - if (table) - length += strlen(table) + 1; - map = malloc(length); - if (map) { - memset(map, 0, length); - map->name = map->stuff; - strcpy(map->name, v->name); - map->driver = map->name + strlen(map->name) + 1; - strcpy(map->driver, driver); - map->database = map->driver + strlen(map->driver) + 1; - strcpy(map->database, database); - if (table) { - map->table = map->database + strlen(map->database) + 1; - strcpy(map->table, table); - } else - map->table = NULL; - map->next = maps; - if (option_verbose > 1) - ast_verbose(VERBOSE_PREFIX_2 "Binding %s to %s/%s/%s\n",map->name,map->driver, map->database, map->table ? map->table : map->name); - maps = map; - } - } - } - - ast_destroy(config); - } - - return 0; -} diff -Nru a/enum.c b/enum.c --- a/enum.c 2005-01-22 20:43:12 -07:00 +++ b/enum.c 2005-01-22 20:43:12 -07:00 @@ -430,7 +430,7 @@ } v = v->next; } - ast_destroy(cfg); + ast_config_destroy(cfg); } else { toplevs = enum_newtoplev(TOPLEV); } diff -Nru a/include/asterisk/config.h b/include/asterisk/config.h --- a/include/asterisk/config.h 2005-01-22 20:43:12 -07:00 +++ b/include/asterisk/config.h 2005-01-22 20:43:12 -07:00 @@ -3,9 +3,9 @@ * * Configuration File Parser * - * Copyright (C) 1999, Mark Spencer + * Copyright (C) 1999-2005, Mark Spencer * - * Mark Spencer + * Mark Spencer * * This program is free software, distributed under the terms of * the GNU General Public License @@ -18,12 +18,11 @@ extern "C" { #endif +#include + struct ast_config; -struct ast_comment { - struct ast_comment *next; - char cmt[0]; -}; +struct ast_category; struct ast_variable { char *name; @@ -37,6 +36,20 @@ char stuff[0]; }; +typedef struct ast_config *config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config); +typedef struct ast_variable *realtime_var_get(const char *database, const char *table, va_list ap); +typedef struct ast_config *realtime_multi_get(const char *database, const char *table, va_list ap); +typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap); + +struct ast_config_engine { + char *name; + config_load_func *load_func; + realtime_var_get *realtime_func; + realtime_multi_get *realtime_multi_func; + realtime_update *update_func; + struct ast_config_engine *next; +}; + /*! Load a config file */ /*! * \param configfile path of file to open. If no preceding '/' character, path is considered relative to AST_CONFIG_DIR @@ -51,7 +64,7 @@ * Free memory associated with a given config * Returns nothing */ -void ast_destroy(struct ast_config *config); +void ast_config_destroy(struct ast_config *config); /*! Goes through categories */ /*! @@ -148,18 +161,39 @@ */ int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...); -/*! Free realtime configuration */ +/*! Free variable list */ /*! * \param var the linked list of variables to free - * This command free's a list of variables and should ONLY be used - * in conjunction with ast_load_realtime and not with the regular ast_load. + * This function frees a list of variables. */ -void ast_destroy_realtime(struct ast_variable *var); +void ast_variables_destroy(struct ast_variable *var); + +int ast_config_engine_register(struct ast_config_engine *new); +int ast_config_engine_deregister(struct ast_config_engine *del); +int register_config_cli(void); +void read_config_maps(void); + +struct ast_config *ast_config_new(void); +struct ast_category *ast_config_get_current_category(const struct ast_config *cfg); +void ast_config_set_current_category(struct ast_config *cfg, struct ast_category *cat); + +struct ast_category *ast_category_new(char *name); +void ast_category_append(struct ast_config *config, struct ast_category *cat); +int ast_category_delete(struct ast_config *cfg, char *category); +void ast_category_destroy(struct ast_category *cat); +struct ast_variable *ast_category_detach_variables(struct ast_category *cat); +void ast_category_rename(struct ast_category *cat, const char *name); + +struct ast_variable *ast_variable_new(char *name,char *value); +void ast_variable_append(struct ast_category *category, struct ast_variable *variable); +int ast_variable_delete(struct ast_config *cfg, char *category, char *variable, char *value); + +int config_text_file_save(char *filename, struct ast_config *cfg, char *generator); + +struct ast_config *ast_internal_load(const char *configfile, struct ast_config *cfg); #if defined(__cplusplus) || defined(c_plusplus) } #endif - - #endif diff -Nru a/include/asterisk/config_pvt.h b/include/asterisk/config_pvt.h --- a/include/asterisk/config_pvt.h 2005-01-22 20:43:12 -07:00 +++ /dev/null Wed Dec 31 16:00:00 196900 @@ -1,66 +0,0 @@ -#ifndef _ASTERISK_CONFIG_PVT_H -#define _ASTERISK_CONFIG_PVT_H -#if defined(__cplusplus) || defined(c_plusplus) -extern "C" { -#endif - -#include -#define CONFIG_KEYWORD_STRLEN 128 -#define CONFIG_KEYWORD_ARRAYLEN 512 -#include - -#define MAX_INCLUDE_LEVEL 10 - -struct ast_category { - char name[80]; - struct ast_variable *root; - struct ast_variable *last; - struct ast_category *next; -}; - -struct ast_config { - struct ast_category *root; - struct ast_category *last; -}; - -typedef struct ast_config *config_static_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_category **cat, int includelevel); - -struct ast_config_reg { - char name[CONFIG_KEYWORD_STRLEN]; - config_static_func *static_func; - struct ast_variable *(*realtime_func)(const char *database, const char *table, va_list ap); - struct ast_config *(*realtime_multi_func)(const char *database, const char *table, va_list ap); - int (*update_func)(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap); - struct ast_config_reg *next; -}; - -int ast_config_register(struct ast_config_reg *new); -int ast_config_deregister(struct ast_config_reg *del); -void ast_cust_config_on(void); -void ast_cust_config_off(void); -int ast_cust_config_active(void); -void ast_config_destroy_all(void); -int ast_cust_config_register(struct ast_config_reg *new); -int ast_cust_config_deregister(struct ast_config_reg *new); -int register_config_cli(void); -int read_ast_cust_config(void); - -struct ast_config *ast_new_config(void); - -struct ast_category *ast_new_category(char *name); -void ast_category_append(struct ast_config *config, struct ast_category *cat); -int ast_category_delete(struct ast_config *cfg, char *category); -void ast_category_destroy(struct ast_category *cat); - -struct ast_variable *ast_new_variable(char *name,char *value); -int ast_variable_delete(struct ast_config *cfg, char *category, char *variable, char *value); -int ast_save(char *filename, struct ast_config *cfg, char *generator); - -struct ast_config *ast_internal_load(const char *configfile, struct ast_config *tmp, struct ast_category **cat, int includelevel); - -#if defined(__cplusplus) || defined(c_plusplus) -} -#endif - - -#endif diff -Nru a/loader.c b/loader.c --- a/loader.c 2005-01-22 20:43:12 -07:00 +++ b/loader.c 2005-01-22 20:43:12 -07:00 @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -169,9 +168,9 @@ ret = strdup(m->resource); } else { ret = NULL; - if (!strncasecmp(word, "astconfig", strlen(word))) { + if (!strncasecmp(word, "extconfig", strlen(word))) { if (++which > state) - ret = strdup("astconfig"); + ret = strdup("extconfig"); } else if (!strncasecmp(word, "manager", strlen(word))) { if (++which > state) ret = strdup("manager"); @@ -200,8 +199,8 @@ ast_verbose("The previous reload command didn't finish yet\n"); return -1; } - if (!name || !strcasecmp(name, "astconfig")) { - read_ast_cust_config(); + if (!name || !strcasecmp(name, "extconfig")) { + read_config_maps(); reloaded = 2; } if (!name || !strcasecmp(name, "manager")) { @@ -407,7 +406,7 @@ option_verbose = o; res = __load_resource(resource_name, cfg); if (cfg) - ast_destroy(cfg); + ast_config_destroy(cfg); return res; } @@ -459,7 +458,7 @@ if (__load_resource(v->value, cfg)) { ast_log(LOG_WARNING, "Loading module %s failed!\n", v->value); if (cfg) - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } } @@ -509,7 +508,7 @@ if (__load_resource(d->d_name, cfg)) { ast_log(LOG_WARNING, "Loading module %s failed!\n", d->d_name); if (cfg) - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } } @@ -521,7 +520,7 @@ } } } - ast_destroy(cfg); + ast_config_destroy(cfg); return 0; } diff -Nru a/logger.c b/logger.c --- a/logger.c 2005-01-22 20:43:12 -07:00 +++ b/logger.c 2005-01-22 20:43:12 -07:00 @@ -299,7 +299,7 @@ var = var->next; } - ast_destroy(cfg); + ast_config_destroy(cfg); ast_mutex_unlock(&loglock); } diff -Nru a/manager.c b/manager.c --- a/manager.c 2005-01-22 20:43:12 -07:00 +++ b/manager.c 2005-01-22 20:43:12 -07:00 @@ -423,7 +423,7 @@ if (ha && !ast_apply_ha(ha, &(s->sin))) { ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr), user); ast_free_ha(ha); - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } else if (ha) ast_free_ha(ha); @@ -443,7 +443,7 @@ if (!strcmp(md5key, key)) break; else { - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } } @@ -451,7 +451,7 @@ break; } else { ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr), user); - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } } @@ -462,13 +462,13 @@ strncpy(s->username, cat, sizeof(s->username) - 1); s->readperm = get_perm(ast_variable_retrieve(cfg, cat, "read")); s->writeperm = get_perm(ast_variable_retrieve(cfg, cat, "write")); - ast_destroy(cfg); + ast_config_destroy(cfg); if (events) set_eventmask(s, events); return 0; } ast_log(LOG_NOTICE, "%s tried to authenticate with non-existant user '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr), user); - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } @@ -1507,7 +1507,7 @@ ast_log(LOG_WARNING, "Unable to change management port / enabled\n"); #endif } - ast_destroy(cfg); + ast_config_destroy(cfg); /* If not enabled, do nothing */ if (!enabled) { diff -Nru a/pbx/pbx_config.c b/pbx/pbx_config.c --- a/pbx/pbx_config.c 2005-01-22 20:43:12 -07:00 +++ b/pbx/pbx_config.c 2005-01-22 20:43:12 -07:00 @@ -978,7 +978,7 @@ if (ast_lock_contexts()) { ast_cli(fd, "Failed to lock contexts list\n"); ast_mutex_unlock(&save_dialplan_lock); - ast_destroy(cfg); + ast_config_destroy(cfg); return RESULT_FAILURE; } @@ -988,7 +988,7 @@ filename); ast_unlock_contexts(); ast_mutex_unlock(&save_dialplan_lock); - ast_destroy(cfg); + ast_config_destroy(cfg); return RESULT_FAILURE; } @@ -1006,7 +1006,7 @@ fprintf(output, "\n"); } - ast_destroy(cfg); + ast_config_destroy(cfg); /* walk all contexts */ c = ast_walk_contexts(NULL); @@ -1775,7 +1775,7 @@ } cxt = ast_category_browse(cfg, cxt); } - ast_destroy(cfg); + ast_config_destroy(cfg); } ast_merge_contexts_and_delete(&local_contexts,registrar); diff -Nru a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c --- a/pbx/pbx_dundi.c 2005-01-22 20:43:12 -07:00 +++ b/pbx/pbx_dundi.c 2005-01-22 20:43:12 -07:00 @@ -4569,7 +4569,7 @@ cat = ast_category_browse(cfg, cat); } prune_peers(); - ast_destroy(cfg); + ast_config_destroy(cfg); load_password(); if (globalpcmodel & DUNDI_MODEL_OUTBOUND) dundi_precache_full(); diff -Nru a/pbx/pbx_realtime.c b/pbx/pbx_realtime.c --- a/pbx/pbx_realtime.c 2005-01-22 20:43:12 -07:00 +++ b/pbx/pbx_realtime.c 2005-01-22 20:43:12 -07:00 @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -92,7 +91,6 @@ { struct ast_variable *var; struct ast_config *cfg; - struct ast_category *cat; char pri[20]; char *ematch; char rexten[AST_MAX_EXTENSION + 20]=""; @@ -116,27 +114,27 @@ if (!var) { cfg = ast_load_realtime_multientry(table, "exten LIKE", "\\_%", "context", context, "priority", pri, NULL); if (cfg) { - cat = cfg->root; + char *cat = ast_category_browse(cfg, NULL); + while(cat) { switch(mode) { case MODE_MATCHMORE: - match = ast_extension_close(cat->name, exten, 1); + match = ast_extension_close(cat, exten, 1); break; case MODE_CANMATCH: - match = ast_extension_close(cat->name, exten, 0); + match = ast_extension_close(cat, exten, 0); break; case MODE_MATCH: default: - match = ast_extension_match(cat->name, exten); + match = ast_extension_match(cat, exten); } if (match) { - var = cat->root; - cat->root = NULL; + var = ast_category_detach_variables(ast_category_get(cfg, cat)); break; } - cat = cat->next; + cat = ast_category_browse(cfg, cat); } - ast_destroy(cfg); + ast_config_destroy(cfg); } } return var; @@ -145,7 +143,7 @@ static int realtime_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data) { REALTIME_COMMON(MODE_MATCH); - if (var) ast_destroy_realtime(var); + if (var) ast_variables_destroy(var); if (var) res = 1; return res > 0 ? res : 0; @@ -154,7 +152,7 @@ static int realtime_canmatch(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data) { REALTIME_COMMON(MODE_CANMATCH); - if (var) ast_destroy_realtime(var); + if (var) ast_variables_destroy(var); if (var) res = 1; return res > 0 ? res : 0; @@ -180,7 +178,7 @@ tmp = ast_strdupa(v->value); v = v->next; } - ast_destroy_realtime(var); + ast_variables_destroy(var); if (!ast_strlen_zero(app)) { a = pbx_findapp(app); if (a) { @@ -212,7 +210,7 @@ static int realtime_matchmore(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data) { REALTIME_COMMON(MODE_MATCHMORE); - if (var) ast_destroy_realtime(var); + if (var) ast_variables_destroy(var); if (var) res = 1; return res > 0 ? res : 0; diff -Nru a/res/res_adsi.c b/res/res_adsi.c --- a/res/res_adsi.c 2005-01-22 20:43:12 -07:00 +++ b/res/res_adsi.c 2005-01-22 20:43:12 -07:00 @@ -1067,7 +1067,7 @@ } if (x) speeds = x; - ast_destroy(conf); + ast_config_destroy(conf); } } diff -Nru a/res/res_config_odbc.c b/res/res_config_odbc.c --- a/res/res_config_odbc.c 2005-01-22 20:43:12 -07:00 +++ b/res/res_config_odbc.c 2005-01-22 20:43:12 -07:00 @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -25,8 +24,6 @@ #include static char *tdesc = "ODBC Configuration"; -static struct ast_config_reg reg1; - STANDARD_LOCAL_USER; LOCAL_USER_DECL; @@ -136,14 +133,14 @@ if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql); if (var) - ast_destroy_realtime(var); + ast_variables_destroy(var); 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) - ast_destroy_realtime(var); + ast_variables_destroy(var); return NULL; } stringp = rowdata; @@ -151,11 +148,11 @@ chunk = strsep(&stringp, ";"); if (chunk && !ast_strlen_zero(ast_strip(chunk))) { if (prev) { - prev->next = ast_new_variable(coltitle, chunk); + prev->next = ast_variable_new(coltitle, chunk); if (prev->next) prev = prev->next; } else - prev = var = ast_new_variable(coltitle, chunk); + prev = var = ast_variable_new(coltitle, chunk); } } @@ -174,7 +171,6 @@ char sql[1024]; char coltitle[256]; char rowdata[2048]; - char *title=NULL; const char *initfield=NULL; char *op; const char *newparam, *newval; @@ -183,7 +179,7 @@ SQLSMALLINT collen; int res; int x; - struct ast_variable *var=NULL, *prev=NULL; + struct ast_variable *var=NULL; struct ast_config *cfg=NULL; struct ast_category *cat=NULL; struct ast_realloca ra; @@ -268,15 +264,25 @@ return NULL; } + cfg = ast_config_new(); + if (!cfg) { + ast_log(LOG_WARNING, "Out of memory!\n"); + SQLFreeHandle (SQL_HANDLE_STMT, stmt); + return NULL; + } + while (rowcount--) { var = NULL; - prev = NULL; - title = 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; } + cat = ast_category_new(""); + if (!cat) { + ast_log(LOG_WARNING, "Out of memory!\n"); + continue; + } for (x=0;xnext = ast_new_variable(coltitle, chunk); - if (prev->next) - prev = prev->next; - } else - prev = var = ast_new_variable(coltitle, chunk); - + if (initfield && !strcmp(initfield, coltitle)) + ast_category_rename(cat, chunk); + var = ast_variable_new(coltitle, chunk); + ast_variable_append(cat, var); } } } - if (var) { - cat = ast_new_category(title ? title : ""); - if (cat) { - cat->root = var; - if (!cfg) - cfg = ast_new_config(); - if (cfg) - ast_category_append(cfg, cat); - else - ast_category_destroy(cat); - } else { - ast_log(LOG_WARNING, "Out of memory!\n"); - ast_destroy_realtime(var); - } - } + ast_category_append(cfg, cat); } SQLFreeHandle (SQL_HANDLE_STMT, stmt); @@ -410,11 +395,10 @@ return -1; } -static struct ast_config *config_odbc(const char *database, const char *table, const char *file, struct ast_config *new_config_s, struct ast_category **new_cat_p, int recur) +static struct ast_config *config_odbc(const char *database, const char *table, const char *file, struct ast_config *cfg) { - struct ast_config *new; - struct ast_variable *cur_v, *new_v; - struct ast_category *cur_cat, *new_cat; + struct ast_variable *new_v; + struct ast_category *cur_cat; int res = 0; odbc_obj *obj; SQLINTEGER err=0, commented=0, cat_metric=0, var_metric=0, last_cat_metric=0; @@ -422,10 +406,7 @@ char sql[255] = "", filename[128], category[128], var_name[128], var_val[512]; SQLSMALLINT rowcount=0; SQLHSTMT stmt; - char last[80] = ""; - int cat_started = 0; - int var_started = 0; - + char last[128] = ""; if (!file || !strcmp (file, "res_config_odbc.conf")) return NULL; /* cant configure myself with myself ! */ @@ -434,8 +415,6 @@ if (!obj) return NULL; - last[0] = '\0'; - res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt); SQLBindCol (stmt, 1, SQL_C_ULONG, &id, sizeof (id), &err); @@ -452,90 +431,65 @@ if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { ast_log (LOG_WARNING, "SQL select error!\n[%s]\n\n", sql); + SQLFreeHandle (SQL_HANDLE_STMT, stmt); return NULL; } res = SQLNumResultCols (stmt, &rowcount); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log (LOG_WARNING, "SQL select error!\n[%s]\n\n", sql); - return NULL; - } - - if (new_config_s) { - new = new_config_s; - cat_started++; - } else { - new = ast_new_config (); - } - - if (!new) { - ast_log(LOG_WARNING, "Out of memory!\n"); + ast_log (LOG_WARNING, "SQL NumResultCols error!\n[%s]\n\n", sql); SQLFreeHandle (SQL_HANDLE_STMT, stmt); return NULL; } - if (rowcount) { - res = SQLFetch (stmt); - cat_started = 0; - - cur_cat = *new_cat_p; - cur_v = NULL; - - if (cur_cat) - cat_started = 1; - if (cur_v) - var_started = 1; - - while (res != SQL_NO_DATA) { - if (!strcmp (var_name, "#include") && recur < MAX_INCLUDE_LEVEL) { - - config_odbc(database, table, var_val, new, &cur_cat, recur + 1); - } else { - if (strcmp (last, category) || last_cat_metric != cat_metric) { - strncpy(last, category, sizeof(last) - 1); - last_cat_metric = cat_metric; - 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; - } - var_started = 0; - - } + if (!rowcount) { + ast_log (LOG_NOTICE, "found nothing\n"); + return cfg; + } - new_v = ast_new_variable (var_name, var_val); + res = SQLFetch (stmt); + cur_cat = ast_config_get_current_category(cfg); - 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; - } + while (res != SQL_NO_DATA) { + if (!strcmp (var_name, "#include")) { + if (!ast_internal_load(var_val, cfg)) { + SQLFreeHandle (SQL_HANDLE_STMT, stmt); + return NULL; } - - /* next row */ - res = SQLFetch (stmt); + 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); } - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - } else { - ast_log (LOG_NOTICE, "found nothing\n"); + new_v = ast_variable_new(var_name, var_val); + ast_variable_append(cur_cat, new_v); + res = SQLFetch (stmt); } - return new; + SQLFreeHandle (SQL_HANDLE_STMT, stmt); + return cfg; } +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 +}; + int unload_module (void) { - ast_cust_config_deregister (®1); + ast_config_engine_deregister(&odbc_engine); if (option_verbose) ast_verbose("res_config_odbc unloaded.\n"); STANDARD_HANGUP_LOCALUSERS; @@ -544,13 +498,7 @@ int load_module (void) { - memset (®1, 0, sizeof (struct ast_config_reg)); - strncpy(reg1.name, "odbc", sizeof(reg1.name) - 1); - reg1.static_func = config_odbc; - reg1.realtime_func = realtime_odbc; - reg1.realtime_multi_func = realtime_multi_odbc; - reg1.update_func = update_odbc; - ast_cust_config_register (®1); + ast_config_engine_register(&odbc_engine); if (option_verbose) ast_verbose("res_config_odbc loaded.\n"); return 0; diff -Nru a/res/res_features.c b/res/res_features.c --- a/res/res_features.c 2005-01-22 20:43:12 -07:00 +++ b/res/res_features.c 2005-01-22 20:43:12 -07:00 @@ -1501,7 +1501,7 @@ ast_log(LOG_NOTICE, "Unknown feature '%s'\n", var->name); var = var->next; } - ast_destroy(cfg); + ast_config_destroy(cfg); } if (con) diff -Nru a/res/res_indications.c b/res/res_indications.c --- a/res/res_indications.c 2005-01-22 20:43:12 -07:00 +++ b/res/res_indications.c 2005-01-22 20:43:12 -07:00 @@ -245,7 +245,7 @@ tones = malloc(sizeof(struct tone_zone)); if (!tones) { ast_log(LOG_WARNING,"Out of memory\n"); - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } memset(tones,0,sizeof(struct tone_zone)); @@ -269,7 +269,7 @@ tmp = realloc(tones->ringcadance,(tones->nrringcadance+1)*sizeof(int)); if (!tmp) { ast_log(LOG_WARNING, "Out of memory\n"); - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } tones->ringcadance = tmp; @@ -286,7 +286,7 @@ struct tone_zone* azone = malloc(sizeof(struct tone_zone)); if (!azone) { ast_log(LOG_WARNING,"Out of memory\n"); - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } memset(azone,0,sizeof(struct tone_zone)); @@ -313,7 +313,7 @@ ts = malloc(sizeof(struct tone_zone_sound)); if (!ts) { ast_log(LOG_WARNING, "Out of memory\n"); - ast_destroy(cfg); + ast_config_destroy(cfg); return -1; } ts->next = NULL; @@ -341,7 +341,7 @@ if (!country || !*country || ast_set_indication_country(country)) ast_log(LOG_WARNING,"Unable to set the default country (for indication tones)\n"); - ast_destroy(cfg); + ast_config_destroy(cfg); return 0; } diff -Nru a/res/res_musiconhold.c b/res/res_musiconhold.c --- a/res/res_musiconhold.c 2005-01-22 20:43:12 -07:00 +++ b/res/res_musiconhold.c 2005-01-22 20:43:12 -07:00 @@ -897,7 +897,7 @@ var = var->next; } - ast_destroy(cfg); + ast_config_destroy(cfg); return x; } diff -Nru a/res/res_odbc.c b/res/res_odbc.c --- a/res/res_odbc.c 2005-01-22 20:43:12 -07:00 +++ b/res/res_odbc.c 2005-01-22 20:43:12 -07:00 @@ -140,7 +140,7 @@ } } - ast_destroy(config); + ast_config_destroy(config); } return 0; } diff -Nru a/res/res_osp.c b/res/res_osp.c --- a/res/res_osp.c 2005-01-22 20:43:12 -07:00 +++ b/res/res_osp.c 2005-01-22 20:43:12 -07:00 @@ -766,7 +766,7 @@ osp_build(cfg, cat); cat = ast_category_browse(cfg, cat); } - ast_destroy(cfg); + ast_config_destroy(cfg); } else ast_log(LOG_NOTICE, "No OSP configuration found. OSP support disabled\n"); ast_mutex_lock(&osplock); diff -Nru a/rtp.c b/rtp.c --- a/rtp.c 2005-01-22 20:43:12 -07:00 +++ b/rtp.c 2005-01-22 20:43:12 -07:00 @@ -1780,7 +1780,7 @@ ast_log(LOG_WARNING, "Disabling RTP checksums is not supported on this operating system!\n"); #endif } - ast_destroy(cfg); + ast_config_destroy(cfg); } if (rtpstart >= rtpend) { ast_log(LOG_WARNING, "Unreasonable values for RTP start in rtp.conf/end\n");