static int reload_module(void) { struct ast_flags flags = { CONFIG_FLAG_NOREALTIME }; struct ast_config *cfg; struct ast_variable *var; if (!(cfg = ast_config_load("res_curl.conf", flags))) { return 0; } else if (cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_WARNING, "res_curl.conf could not be parsed!\n"); return 0; } if (!(var = ast_variable_browse(cfg, "globals")) && !(var = ast_variable_browse(cfg, "global")) && !(var = ast_variable_browse(cfg, "general"))) { ast_log(LOG_WARNING, "[globals] not found in res_curl.conf\n"); ast_config_destroy(cfg); return 0; } for (; var; var = var->next) { if (strncmp(var->name, "CURLOPT(", 8)) { char name[256]; snprintf(name, sizeof(name), "CURLOPT(%s)", var->name); pbx_builtin_setvar_helper(NULL, name, var->value); } else { pbx_builtin_setvar_helper(NULL, var->name, var->value); } } ast_config_destroy(cfg); return 0; }
static int load_module(void) { struct ast_config *cfg; int res; const char *tmp; if ((cfg = ast_config_load(cdr_config))) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid")), RADIUS_FLAG_LOGUNIQUEID); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield")), RADIUS_FLAG_LOGUSERFIELD); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); ast_config_destroy(cfg); } else return AST_MODULE_LOAD_DECLINE; /* start logging */ rc_openlog("asterisk"); /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); return AST_MODULE_LOAD_DECLINE; } res = ast_cdr_register(name, desc, radius_log); return AST_MODULE_LOAD_SUCCESS; }
static int loadconfigurationfile(void) { char *cat; struct ast_config *cfg; struct ast_variable *v; cfg = ast_config_load(CONF_FILE); if (!cfg) { /* Standard configuration */ enablecdr = 0; return 0; } cat = ast_category_browse(cfg, NULL); while (cat) { if (!strcasecmp(cat, "general")) { v = ast_variable_browse(cfg, cat); while (v) { if (!strcasecmp(v->name, "enabled")) { enablecdr = ast_true(v->value); } v = v->next; } } /* Next category */ cat = ast_category_browse(cfg, cat); } ast_config_destroy(cfg); return 1; }
static int read_config(const char *flite_conf) { const char *temp; /* set default values */ target_sample_rate = DEF_RATE; usecache = 0; cachedir = DEF_DIR; voice_name = DEF_VOICE; cfg = ast_config_load(flite_conf, config_flags); if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_WARNING, "Flite: Unable to read config file %s. Using default settings\n", flite_conf); } else { if ((temp = ast_variable_retrieve(cfg, "general", "usecache"))) usecache = ast_true(temp); if ((temp = ast_variable_retrieve(cfg, "general", "cachedir"))) cachedir = temp; if ((temp = ast_variable_retrieve(cfg, "general", "voice"))) voice_name = temp; if ((temp = ast_variable_retrieve(cfg, "general", "samplerate"))) target_sample_rate = (int) strtol(temp, NULL, 10); } if (target_sample_rate != 8000 && target_sample_rate != 16000) { ast_log(LOG_WARNING, "Flite: Unsupported sample rate: %d. Falling back to %d\n", target_sample_rate, DEF_RATE); target_sample_rate = DEF_RATE; } return 0; }
static int load_config(int reload) { const char *cat = NULL; struct ast_config *cfg; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; struct ast_variable *v; int newenablecel = CEL_AMI_ENABLED_DEFAULT; int new_cel_show_user_def = CEL_SHOW_USERDEF_DEFAULT; cfg = ast_config_load(CONF_FILE, config_flags); if (cfg == CONFIG_STATUS_FILEUNCHANGED) { return 0; } if (cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_WARNING, "Configuration file '%s' is invalid. CEL manager Module not activated.\n", CONF_FILE); enablecel = 0; return -1; } else if (!cfg) { ast_log(LOG_WARNING, "Failed to load configuration file. CEL manager Module not activated.\n"); enablecel = 0; return -1; } while ((cat = ast_category_browse(cfg, cat))) { if (strcasecmp(cat, "manager")) { continue; } for (v = ast_variable_browse(cfg, cat); v; v = v->next) { if (!strcasecmp(v->name, "enabled")) { newenablecel = ast_true(v->value) ? 1 : 0; } else if (!strcasecmp(v->name, "show_user_defined")) { new_cel_show_user_def = ast_true(v->value) ? 1 : 0; } else { ast_log(LOG_NOTICE, "Unknown option '%s' specified " "for cel_manager.\n", v->name); } } } ast_config_destroy(cfg); cel_show_user_def = new_cel_show_user_def; if (enablecel && !newenablecel) { if (event_sub) { event_sub = ast_event_unsubscribe(event_sub); } } else if (!enablecel && newenablecel) { event_sub = ast_event_subscribe(AST_EVENT_CEL, manager_log, "Manager Event Logging", NULL, AST_EVENT_IE_END); if (!event_sub) { ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CEL handling\n"); } } enablecel = newenablecel; return 0; }
static struct ast_config *realtime_directory(char *context) { struct ast_config *cfg; struct ast_config *rtdata; struct ast_category *cat; struct ast_variable *var; char *mailbox; char *fullname; char *hidefromdir; char tmp[100]; /* Load flat file config. */ cfg = ast_config_load(VOICEMAIL_CONFIG); if (!cfg) { /* Loading config failed. */ ast_log(LOG_WARNING, "Loading config failed.\n"); return NULL; } /* Get realtime entries, categorized by their mailbox number and present in the requested context */ rtdata = ast_load_realtime_multientry("voicemail", "mailbox LIKE", "%", "context", context, NULL); /* if there are no results, just return the entries from the config file */ if (!rtdata) return cfg; /* Does the context exist within the config file? If not, make one */ cat = ast_category_get(cfg, context); if (!cat) { cat = ast_category_new(context); if (!cat) { ast_log(LOG_WARNING, "Out of memory\n"); ast_config_destroy(cfg); return NULL; } ast_category_append(cfg, cat); } mailbox = ast_category_browse(rtdata, NULL); while (mailbox) { fullname = ast_variable_retrieve(rtdata, mailbox, "fullname"); hidefromdir = ast_variable_retrieve(rtdata, mailbox, "hidefromdir"); snprintf(tmp, sizeof(tmp), "no-password,%s,hidefromdir=%s", fullname ? fullname : "", hidefromdir ? hidefromdir : "no"); var = ast_variable_new(mailbox, tmp); if (var) ast_variable_append(cat, var); else ast_log(LOG_WARNING, "Out of memory adding mailbox '%s'\n", mailbox); mailbox = ast_category_browse(rtdata, mailbox); } ast_config_destroy(rtdata); return cfg; }
static void adsi_load(int reload) { int x = 0; struct ast_config *conf = NULL; struct ast_variable *v; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; char *name, *sname; init_state(); conf = ast_config_load("adsi.conf", config_flags); if (conf == CONFIG_STATUS_FILEMISSING || conf == CONFIG_STATUS_FILEUNCHANGED || conf == CONFIG_STATUS_FILEINVALID) { return; } for (v = ast_variable_browse(conf, "intro"); v; v = v->next) { if (!strcasecmp(v->name, "alignment")) { alignment = str2align(v->value); } else if (!strcasecmp(v->name, "greeting")) { if (x < ADSI_MAX_INTRO) { aligns[x] = alignment; ast_copy_string(intro[x], v->value, sizeof(intro[x])); x++; } } else if (!strcasecmp(v->name, "maxretries")) { if (atoi(v->value) > 0) { maxretries = atoi(v->value); } } } if (x) { total = x; } x = 0; for (v = ast_variable_browse(conf, "speeddial"); v; v = v->next) { char buf[3 * SPEEDDIAL_MAX_LEN]; char *stringp = buf; ast_copy_string(buf, v->value, sizeof(buf)); name = strsep(&stringp, ","); sname = strsep(&stringp, ","); if (!sname) { sname = name; } if (x < ADSI_MAX_SPEED_DIAL) { ast_copy_string(speeddial[x][0], v->name, sizeof(speeddial[x][0])); ast_copy_string(speeddial[x][1], name, 18); ast_copy_string(speeddial[x][2], sname, 7); x++; } } if (x) { speeds = x; } ast_config_destroy(conf); return; }
/** \brief Load UniMRCP engine configuration (/etc/asterisk/res_speech_unimrcp.conf)*/ static apt_bool_t uni_engine_config_load(apr_pool_t *pool) { const char *value = NULL; #if AST_VERSION_AT_LEAST(1,6,0) struct ast_flags config_flags = { 0 }; struct ast_config *cfg = ast_config_load(UNI_ENGINE_CONFIG, config_flags); #else struct ast_config *cfg = ast_config_load(UNI_ENGINE_CONFIG); #endif if(!cfg) { ast_log(LOG_WARNING, "No such configuration file %s\n", UNI_ENGINE_CONFIG); return FALSE; } #if AST_VERSION_AT_LEAST(1,6,2) if(cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_ERROR, "Config file %s is in an invalid format\n", UNI_ENGINE_CONFIG); return FALSE; } #endif if((value = ast_variable_retrieve(cfg, "general", "unimrcp-profile")) != NULL) { ast_log(LOG_DEBUG, "general.unimrcp-profile=%s\n", value); uni_engine.profile = apr_pstrdup(uni_engine.pool, value); } if((value = ast_variable_retrieve(cfg, "general", "log-level")) != NULL) { ast_log(LOG_DEBUG, "general.log-level=%s\n", value); uni_engine.log_level = apt_log_priority_translate(value); } if((value = ast_variable_retrieve(cfg, "general", "log-output")) != NULL) { ast_log(LOG_DEBUG, "general.log-output=%s\n", value); uni_engine.log_output = atoi(value); } uni_engine.grammars = uni_engine_grammars_load(cfg,"grammars",pool); uni_engine.v2_properties = uni_engine_properties_load(cfg,"mrcpv2-properties",MRCP_VERSION_2,pool); uni_engine.v1_properties = uni_engine_properties_load(cfg,"mrcpv1-properties",MRCP_VERSION_1,pool); ast_config_destroy(cfg); return TRUE; }
static void adsi_load(void) { int x; struct ast_config *conf; struct ast_variable *v; char *name, *sname; init_state(); conf = ast_config_load("adsi.conf"); if (conf) { x=0; v = ast_variable_browse(conf, "intro"); while(v) { if (!strcasecmp(v->name, "alignment")) alignment = str2align(v->value); else if (!strcasecmp(v->name, "greeting")) { if (x < ADSI_MAX_INTRO) { aligns[x] = alignment; strncpy(intro[x], v->value, sizeof(intro[x]) - 1); intro[x][sizeof(intro[x]) - 1] = '\0'; x++; } } else if (!strcasecmp(v->name, "maxretries")) { if (atoi(v->value) > 0) maxretries = atoi(v->value); } v = v->next; } v = ast_variable_browse(conf, "speeddial"); if (x) total = x; x = 0; while(v) { char *stringp=NULL; stringp=v->value; name = strsep(&stringp, ","); sname = strsep(&stringp, ","); if (!sname) sname = name; if (x < ADSI_MAX_SPEED_DIAL) { /* Up to 20 digits */ strncpy(speeddial[x][0], v->name, sizeof(speeddial[x][0]) - 1); strncpy(speeddial[x][1], name, 18); strncpy(speeddial[x][2], sname, 7); x++; } v = v->next; } if (x) speeds = x; ast_config_destroy(conf); } }
static int __ast_http_load(int reload) { struct ast_config *cfg; struct ast_variable *v; int enabled=0; int newenablestatic=0; struct sockaddr_in sin; struct hostent *hp; struct ast_hostent ahp; char newprefix[MAX_PREFIX]; memset(&sin, 0, sizeof(sin)); sin.sin_port = 8088; strcpy(newprefix, DEFAULT_PREFIX); cfg = ast_config_load("http.conf"); if (cfg) { v = ast_variable_browse(cfg, "general"); while(v) { if (!strcasecmp(v->name, "enabled")) enabled = ast_true(v->value); else if (!strcasecmp(v->name, "enablestatic")) newenablestatic = ast_true(v->value); else if (!strcasecmp(v->name, "bindport")) sin.sin_port = ntohs(atoi(v->value)); else if (!strcasecmp(v->name, "bindaddr")) { if ((hp = ast_gethostbyname(v->value, &ahp))) { memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr)); } else { ast_log(LOG_WARNING, "Invalid bind address '%s'\n", v->value); } } else if (!strcasecmp(v->name, "prefix")) { if (!ast_strlen_zero(v->value)) { newprefix[0] = '/'; ast_copy_string(newprefix + 1, v->value, sizeof(newprefix) - 1); } else { newprefix[0] = '\0'; } } v = v->next; } ast_config_destroy(cfg); } if (enabled) sin.sin_family = AF_INET; if (strcmp(prefix, newprefix)) { ast_copy_string(prefix, newprefix, sizeof(prefix)); prefix_len = strlen(prefix); } enablestatic = newenablestatic; http_server_start(&sin); return 0; }
static int load_module(void) { struct ast_config *cfg; struct ast_flags config_flags = { 0 }; const char *tmp; if ((cfg = ast_config_load(cel_config, config_flags))) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) { ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); } ast_config_destroy(cfg); } else { return AST_MODULE_LOAD_DECLINE; } /* * start logging * * NOTE: Yes this causes a slight memory leak if the module is * unloaded. However, it is better than a crash if cdr_radius * and cel_radius are both loaded. */ tmp = ast_strdup("asterisk"); if (tmp) { rc_openlog((char *) tmp); } /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } event_sub = ast_event_subscribe(AST_EVENT_CEL, radius_log, "CEL Radius Logging", NULL, AST_EVENT_IE_END); if (!event_sub) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { return AST_MODULE_LOAD_SUCCESS; } }
static int load_module(void) { struct ast_config *cfg; struct ast_flags config_flags = { 0 }; const char *tmp; if ((cfg = ast_config_load(cdr_config, config_flags)) && cfg != CONFIG_STATUS_FILEINVALID) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid")), RADIUS_FLAG_LOGUNIQUEID); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield")), RADIUS_FLAG_LOGUSERFIELD); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); ast_config_destroy(cfg); } else return AST_MODULE_LOAD_DECLINE; /* * start logging * * NOTE: Yes this causes a slight memory leak if the module is * unloaded. However, it is better than a crash if cdr_radius * and cel_radius are both loaded. */ tmp = ast_strdup("asterisk"); if (tmp) { rc_openlog((char *) tmp); } /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } if (ast_cdr_register(name, desc, radius_log)) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { return AST_MODULE_LOAD_SUCCESS; } }
/*! * \brief Load res_snmp.conf config file * \return 1 on load, 0 file does not exist */ static int load_config(void) { struct ast_variable *var; struct ast_config *cfg; struct ast_flags config_flags = { 0 }; char *cat; res_snmp_enabled = 0; res_snmp_agentx_subagent = 1; cfg = ast_config_load("res_snmp.conf", config_flags); if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_WARNING, "Could not load res_snmp.conf\n"); return 0; } cat = ast_category_browse(cfg, NULL); while (cat) { var = ast_variable_browse(cfg, cat); if (strcasecmp(cat, "general") == 0) { while (var) { if (strcasecmp(var->name, "subagent") == 0) { if (ast_true(var->value)) res_snmp_agentx_subagent = 1; else if (ast_false(var->value)) res_snmp_agentx_subagent = 0; else { ast_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value); ast_config_destroy(cfg); return 1; } } else if (strcasecmp(var->name, "enabled") == 0) { res_snmp_enabled = ast_true(var->value); } else { ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat); ast_config_destroy(cfg); return 1; } var = var->next; } } else { ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat); ast_config_destroy(cfg); return 1; } cat = ast_category_browse(cfg, cat); } ast_config_destroy(cfg); return 1; }
static void parse_config(void) { struct ast_variable *var; struct ast_config *cfg = ast_config_load("codecs.conf"); if (!cfg) return; for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) { if (!strcasecmp(var->name, "genericplc")) { alawtolin.useplc = ast_true(var->value) ? 1 : 0; if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "codec_alaw: %susing generic PLC\n", alawtolin.useplc ? "" : "not "); } } ast_config_destroy(cfg); }
static int my_load_module(void) { struct ast_config *cfg; int res; if (!(cfg = ast_config_load(config))) { ast_log(LOG_WARNING, "Unable to load config for PostgreSQL CDR's: %s\n", config); return AST_MODULE_LOAD_DECLINE; } res = process_my_load_module(cfg); ast_config_destroy(cfg); return res; }
static int parse_config(int reload) { struct ast_variable *var; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; struct ast_config *cfg = ast_config_load("codecs.conf", config_flags); if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) return 0; for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) { if (!strcasecmp(var->name, "genericplc")) { alawtolin.useplc = ast_true(var->value) ? 1 : 0; //ast_verb(3, "codec_alaw: %susing generic PLC\n", alawtolin.useplc ? "" : "not "); } } ast_config_destroy(cfg); return 0; }
static int load_config(int reload) { struct ast_config *cfg; struct ast_variable *var; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; int res = -1; if ((cfg = ast_config_load("cdr_custom.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) return 0; if (cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_ERROR, "Invalid config file\n"); return 1; } strcpy(format, ""); strcpy(master, ""); ast_mutex_lock(&lock); if (cfg) { var = ast_variable_browse(cfg, "mappings"); while(var) { if (!ast_strlen_zero(var->name) && !ast_strlen_zero(var->value)) { if (strlen(var->value) > (sizeof(format) - 1)) ast_log(LOG_WARNING, "Format string too long, will be truncated, at line %d\n", var->lineno); ast_copy_string(format, var->value, sizeof(format) - 1); strcat(format,"\n"); snprintf(master, sizeof(master),"%s/%s/%s", ast_config_AST_LOG_DIR, name, var->name); if (var->next) { ast_log(LOG_NOTICE, "Sorry, only one mapping is supported at this time, mapping '%s' will be ignored at line %d.\n", var->next->name, var->next->lineno); break; } } else ast_log(LOG_NOTICE, "Mapping must have both filename and format at line %d\n", var->lineno); var = var->next; } ast_config_destroy(cfg); res = 0; } else { if (reload) ast_log(LOG_WARNING, "Failed to reload configuration file.\n"); else ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n"); } ast_mutex_unlock(&lock); return res; }
static int config_load(char *config_file, struct conf_infos *conf_info) { struct ast_config *cfg = NULL; struct ast_flags config_flags = { 0 }; ast_log(LOG_NOTICE, "Configuring openbsc from %s...\n", config_file); cfg = ast_config_load(config_file, config_flags); if (!cfg) { ast_log(LOG_ERROR, "Unable to load configuration file '%s'\n", config_file); return -1; } parse_config_general(cfg, conf_info); ast_config_destroy(cfg); return 0; }
static void parse_config(void) { struct ast_config *cfg; struct ast_variable *var; if ((cfg = ast_config_load("codecs.conf"))) { if ((var = ast_variable_browse(cfg, "plc"))) { while (var) { if (!strcasecmp(var->name, "genericplc")) { useplc = ast_true(var->value) ? 1 : 0; if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "codec_gsm: %susing generic PLC\n", useplc ? "" : "not "); } var = var->next; } } ast_config_destroy(cfg); } }
/*! \brief Initialize the ENUM support subsystem */ static int private_enum_init(int reload) { struct ast_config *cfg; struct enum_search *s, *sl; struct ast_variable *v; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; if ((cfg = ast_config_load("enum.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) return 0; /* Destroy existing list */ ast_mutex_lock(&enumlock); s = toplevs; while (s) { sl = s; s = s->next; ast_free(sl); } toplevs = NULL; if (cfg) { sl = NULL; v = ast_variable_browse(cfg, "general"); while (v) { if (!strcasecmp(v->name, "search")) { s = enum_newtoplev(v->value); if (s) { if (sl) sl->next = s; else toplevs = s; sl = s; } } v = v->next; } ast_config_destroy(cfg); } else { toplevs = enum_newtoplev(TOPLEV); } enumver++; ast_mutex_unlock(&enumlock); manager_event(EVENT_FLAG_SYSTEM, "Reload", "Module: Enum\r\nStatus: Enabled\r\nMessage: ENUM reload Requested\r\n"); return 0; }
static int load_module(void) { int res = 0; const char *val = NULL; struct ast_flags config_flags = { CONFIG_FLAG_NOCACHE }; struct ast_config *cfg; /* Set some defaults */ cfg_buffer_size = 65535; cfg_goto_exten = 0; samplerate = 8000; /* G711a/G711u */ ast_copy_string(cfg_voice, "Allison-8kHz", sizeof(cfg_voice)); res = ast_register_application(app, app_exec, synopsis, descrip) ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS; cfg = ast_config_load(SWIFT_CONFIG_FILE, config_flags); if (cfg) { if ((val = ast_variable_retrieve(cfg, "general", "buffer_size"))) { cfg_buffer_size = atoi(val); ast_log(LOG_DEBUG, "Config buffer_size is %d\n", cfg_buffer_size); } if ((val = ast_variable_retrieve(cfg, "general", "goto_exten"))) { if (!strcmp(val, "yes")) { cfg_goto_exten = 1; } else { cfg_goto_exten = 0; ast_log(LOG_DEBUG, "Config goto_exten is %d\n", cfg_goto_exten); } } if ((val = ast_variable_retrieve(cfg, "general", "voice"))) { ast_copy_string(cfg_voice, val, sizeof(cfg_voice)); ast_log(LOG_DEBUG, "Config voice is %s\n", cfg_voice); } ast_config_destroy(cfg); } else { ast_log(LOG_NOTICE, "Failed to load config\n"); } return res; }
static int load_config(int reload) { struct ast_config *cfg; struct ast_variable *var; const char *tmp; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; if (!(cfg = ast_config_load(config, config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_WARNING, "unable to load config: %s\n", config); return 0; } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) return 1; usegmtime = 0; loguniqueid = 0; loguserfield = 0; if (!(var = ast_variable_browse(cfg, "csv"))) { ast_config_destroy(cfg); return 0; } if ((tmp = ast_variable_retrieve(cfg, "csv", "usegmtime"))) { usegmtime = ast_true(tmp); if (usegmtime) ast_debug(1, "logging time in GMT\n"); } if ((tmp = ast_variable_retrieve(cfg, "csv", "loguniqueid"))) { loguniqueid = ast_true(tmp); if (loguniqueid) ast_debug(1, "logging CDR field UNIQUEID\n"); } if ((tmp = ast_variable_retrieve(cfg, "csv", "loguserfield"))) { loguserfield = ast_true(tmp); if (loguserfield) ast_debug(1, "logging CDR user-defined field\n"); } ast_config_destroy(cfg); return 1; }
static int process_config(int reload) { struct ast_config *config; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; const char *bindaddr; const char *bindport; const char *prefix; const char *enabled; config = ast_config_load("http.conf", config_flags); if (!config || config == CONFIG_STATUS_FILEINVALID) { return -1; } else if (config == CONFIG_STATUS_FILEUNCHANGED) { return 0; } enabled = ast_config_option(config, "general", "enabled"); if (!enabled || ast_false(enabled)) { ast_config_destroy(config); return -1; } /* Construct our Server URI */ bindaddr = ast_config_option(config, "general", "bindaddr"); if (!bindaddr) { ast_config_destroy(config); return -1; } bindport = ast_config_option(config, "general", "bindport"); if (!bindport) { bindport = "8088"; } prefix = ast_config_option(config, "general", "prefix"); snprintf(server_uri, sizeof(server_uri), "http://%s:%s%s/%s", bindaddr, bindport, S_OR(prefix, ""), TEST_URI); ast_config_destroy(config); return 0; }
/* * remap the 'say' functions to use those in this file */ static int __say_init(int fd, int argc, char *argv[]) { const char *old_mode = say_api_buf[0] ? say_new : say_old; char *mode; if (argc == 2) { ast_cli(fd, "say mode is [%s]\n", old_mode); return RESULT_SUCCESS; } else if (argc != 3) return RESULT_SHOWUSAGE; mode = argv[2]; ast_log(LOG_WARNING, "init say.c from %s to %s\n", old_mode, mode); if (!strcmp(mode, old_mode)) { ast_log(LOG_WARNING, "say mode is %s already\n", mode); } else if (!strcmp(mode, say_new)) { if (say_cfg == NULL) say_cfg = ast_config_load("say.conf"); save_say_mode(say_new); ast_say_number_full = say_number_full; ast_say_enumeration_full = say_enumeration_full; #if 0 ast_say_digits_full = say_digits_full; ast_say_digit_str_full = say_digit_str_full; ast_say_character_str_full = say_character_str_full; ast_say_phonetic_str_full = say_phonetic_str_full; ast_say_datetime_from_now = say_datetime_from_now; #endif ast_say_datetime = say_datetime; ast_say_time = say_time; ast_say_date = say_date; ast_say_date_with_format = say_date_with_format; } else if (!strcmp(mode, say_old) && say_api_buf[0] == say_new) { restore_say_mode(NULL); } else { ast_log(LOG_WARNING, "unrecognized mode %s\n", mode); } return RESULT_SUCCESS; }
/*--- ast_enum_init: Initialize the ENUM support subsystem */ int ast_enum_init(void) { struct ast_config *cfg; struct enum_search *s, *sl; struct ast_variable *v; /* Destroy existing list */ ast_mutex_lock(&enumlock); s = toplevs; while(s) { sl = s; s = s->next; free(sl); } toplevs = NULL; cfg = ast_config_load("enum.conf"); if (cfg) { sl = NULL; v = ast_variable_browse(cfg, "general"); while(v) { if (!strcasecmp(v->name, "search")) { s = enum_newtoplev(v->value); if (s) { if (sl) sl->next = s; else toplevs = s; sl = s; } } v = v->next; } ast_config_destroy(cfg); } else { toplevs = enum_newtoplev(TOPLEV); } enumver++; ast_mutex_unlock(&enumlock); return 0; }
static int load_config(int reload) { struct ast_config *cfg; struct ast_variable *v; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; if (!(cfg = ast_config_load(config, config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_WARNING, "unable to load config: %s\n", config); return 0; } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) { return 1; } accountlogs = 1; usegmtime = 0; loguniqueid = 0; loguserfield = 0; if (!(v = ast_variable_browse(cfg, "csv"))) { ast_config_destroy(cfg); return 0; } for (; v; v = v->next) { if (!strcasecmp(v->name, "usegmtime")) { usegmtime = ast_true(v->value); } else if (!strcasecmp(v->name, "accountlogs")) { /* Turn on/off separate files per accountcode. Default is on (as before) */ accountlogs = ast_true(v->value); } else if (!strcasecmp(v->name, "loguniqueid")) { loguniqueid = ast_true(v->value); } else if (!strcasecmp(v->name, "loguserfield")) { loguserfield = ast_true(v->value); } } ast_config_destroy(cfg); return 1; }
int load_module(void) { #ifdef USE_ODBC_STORAGE struct ast_config *cfg = ast_config_load(VOICEMAIL_CONFIG); char *tmp; if (cfg) { if ((tmp = ast_variable_retrieve(cfg, "general", "odbcstorage"))) { ast_copy_string(odbc_database, tmp, sizeof(odbc_database)); } if ((tmp = ast_variable_retrieve(cfg, "general", "odbctable"))) { ast_copy_string(odbc_table, tmp, sizeof(odbc_table)); } if ((tmp = ast_variable_retrieve(cfg, "general", "format"))) { ast_copy_string(vmfmts, tmp, sizeof(vmfmts)); } ast_config_destroy(cfg); } else ast_log(LOG_WARNING, "Unable to load " VOICEMAIL_CONFIG " - ODBC defaults will be used\n"); #endif return ast_register_application(app, directory_exec, synopsis, descrip); }
static int load_config(int reload) { struct ast_config *cfg; struct ast_variable *var; int res = -1; strcpy(format, ""); strcpy(master, ""); if((cfg = ast_config_load("cdr_custom.conf"))) { var = ast_variable_browse(cfg, "mappings"); while(var) { ast_mutex_lock(&lock); if (!ast_strlen_zero(var->name) && !ast_strlen_zero(var->value)) { if (strlen(var->value) > (sizeof(format) - 2)) ast_log(LOG_WARNING, "Format string too long, will be truncated, at line %d\n", var->lineno); strncpy(format, var->value, sizeof(format) - 2); strcat(format,"\n"); snprintf(master, sizeof(master),"%s/%s/%s", ast_config_AST_LOG_DIR, name, var->name); ast_mutex_unlock(&lock); } else ast_log(LOG_NOTICE, "Mapping must have both filename and format at line %d\n", var->lineno); if (var->next) ast_log(LOG_NOTICE, "Sorry, only one mapping is supported at this time, mapping '%s' will be ignored at line %d.\n", var->next->name, var->next->lineno); var = var->next; } ast_config_destroy(cfg); res = 0; } else { if (reload) ast_log(LOG_WARNING, "Failed to reload configuration file.\n"); else ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n"); } return res; }
/*! \brief Function which passes through an aliased CLI command to the real one */ static char *cli_alias_passthrough(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct cli_alias *alias; struct cli_alias tmp = { .cli_entry.command = e->command, }; char *generator; const char *line; /* Try to find the alias based on the CLI entry */ if (!(alias = ao2_find(cli_aliases, &tmp, OBJ_POINTER))) { return 0; } switch (cmd) { case CLI_INIT: ao2_ref(alias, -1); return NULL; case CLI_GENERATE: line = a->line; line += (strlen(alias->alias)); if (!strncasecmp(alias->alias, alias->real_cmd, strlen(alias->alias))) { generator = NULL; } else if (!ast_strlen_zero(a->word)) { struct ast_str *real_cmd = ast_str_alloca(strlen(alias->real_cmd) + strlen(line) + 1); ast_str_append(&real_cmd, 0, "%s%s", alias->real_cmd, line); generator = ast_cli_generator(ast_str_buffer(real_cmd), a->word, a->n); } else { generator = ast_cli_generator(alias->real_cmd, a->word, a->n); } ao2_ref(alias, -1); return generator; } /* If they gave us extra arguments we need to construct a string to pass in */ if (a->argc != e->args) { struct ast_str *real_cmd = ast_str_alloca(2048); int i; ast_str_append(&real_cmd, 0, "%s", alias->real_cmd); /* Add the additional arguments that have been passed in */ for (i = e->args + 1; i <= a->argc; i++) { ast_str_append(&real_cmd, 0, " %s", a->argv[i - 1]); } ast_cli_command(a->fd, ast_str_buffer(real_cmd)); } else { ast_cli_command(a->fd, alias->real_cmd); } ao2_ref(alias, -1); return CLI_SUCCESS; } /*! \brief CLI Command to display CLI Aliases */ static char *alias_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { #define FORMAT "%-50.50s %-50.50s\n" struct cli_alias *alias; struct ao2_iterator i; switch (cmd) { case CLI_INIT: e->command = "cli show aliases"; e->usage = "Usage: cli show aliases\n" " Displays a list of aliased CLI commands.\n"; return NULL; case CLI_GENERATE: return NULL; } ast_cli(a->fd, FORMAT, "Alias Command", "Real Command"); i = ao2_iterator_init(cli_aliases, 0); for (; (alias = ao2_iterator_next(&i)); ao2_ref(alias, -1)) { ast_cli(a->fd, FORMAT, alias->alias, alias->real_cmd); } ao2_iterator_destroy(&i); return CLI_SUCCESS; #undef FORMAT } /*! \brief CLI commands to interact with things */ static struct ast_cli_entry cli_alias[] = { AST_CLI_DEFINE(alias_show, "Show CLI command aliases"), }; /*! \brief Function called to load or reload the configuration file */ static void load_config(int reload) { struct ast_config *cfg = NULL; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; struct cli_alias *alias; struct ast_variable *v, *v1; if (!(cfg = ast_config_load(config_file, config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_ERROR, "res_clialiases configuration file '%s' not found\n", config_file); return; } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) { return; } /* Destroy any existing CLI aliases */ if (reload) { ao2_callback(cli_aliases, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL); } for (v = ast_variable_browse(cfg, "general"); v; v = v->next) { if (strcmp(v->name, "template")) { ast_log(LOG_WARNING, "%s is not a correct option in [%s]\n", v->name, "general"); continue; } /* Read in those there CLI aliases */ for (v1 = ast_variable_browse(cfg, v->value); v1; v1 = v1->next) { if (!(alias = ao2_alloc((sizeof(*alias) + strlen(v1->name) + strlen(v1->value) + 2), alias_destroy))) { continue; } alias->alias = ((char *) alias) + sizeof(*alias); alias->real_cmd = ((char *) alias->alias) + strlen(v1->name) + 1; strcpy(alias->alias, v1->name); strcpy(alias->real_cmd, v1->value); alias->cli_entry.handler = cli_alias_passthrough; alias->cli_entry.command = alias->alias; alias->cli_entry.usage = "Aliased CLI Command\n"; ast_cli_register(&alias->cli_entry); ao2_link(cli_aliases, alias); ast_verbose(VERBOSE_PREFIX_2 "Aliased CLI command '%s' to '%s'\n", v1->name, v1->value); ao2_ref(alias, -1); } } ast_config_destroy(cfg); return; } /*! \brief Function called to reload the module */ static int reload_module(void) { load_config(1); return 0; }
static int parse_config(int reload) { struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; struct ast_config *cfg = ast_config_load("codecs.conf", config_flags); struct ast_variable *var; int res; float res_f; if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) return 0; for (var = ast_variable_browse(cfg, "speex"); var; var = var->next) { if (!strcasecmp(var->name, "quality")) { res = abs(atoi(var->value)); if (res > -1 && res < 11) { ast_verb(3, "CODEC SPEEX: Setting Quality to %d\n",res); quality = res; } else ast_log(LOG_ERROR,"Error Quality must be 0-10\n"); } else if (!strcasecmp(var->name, "complexity")) { res = abs(atoi(var->value)); if (res > -1 && res < 11) { ast_verb(3, "CODEC SPEEX: Setting Complexity to %d\n",res); complexity = res; } else ast_log(LOG_ERROR,"Error! Complexity must be 0-10\n"); } else if (!strcasecmp(var->name, "vbr_quality")) { if (sscanf(var->value, "%30f", &res_f) == 1 && res_f >= 0 && res_f <= 10) { ast_verb(3, "CODEC SPEEX: Setting VBR Quality to %f\n",res_f); vbr_quality = res_f; } else ast_log(LOG_ERROR,"Error! VBR Quality must be 0-10\n"); } else if (!strcasecmp(var->name, "abr_quality")) { ast_log(LOG_ERROR,"Error! ABR Quality setting obsolete, set ABR to desired bitrate\n"); } else if (!strcasecmp(var->name, "enhancement")) { enhancement = ast_true(var->value) ? 1 : 0; ast_verb(3, "CODEC SPEEX: Perceptual Enhancement Mode. [%s]\n",enhancement ? "on" : "off"); } else if (!strcasecmp(var->name, "vbr")) { vbr = ast_true(var->value) ? 1 : 0; ast_verb(3, "CODEC SPEEX: VBR Mode. [%s]\n",vbr ? "on" : "off"); } else if (!strcasecmp(var->name, "abr")) { res = abs(atoi(var->value)); if (res >= 0) { if (res > 0) ast_verb(3, "CODEC SPEEX: Setting ABR target bitrate to %d\n",res); else ast_verb(3, "CODEC SPEEX: Disabling ABR\n"); abr = res; } else ast_log(LOG_ERROR,"Error! ABR target bitrate must be >= 0\n"); } else if (!strcasecmp(var->name, "vad")) { vad = ast_true(var->value) ? 1 : 0; ast_verb(3, "CODEC SPEEX: VAD Mode. [%s]\n",vad ? "on" : "off"); } else if (!strcasecmp(var->name, "dtx")) { dtx = ast_true(var->value) ? 1 : 0; ast_verb(3, "CODEC SPEEX: DTX Mode. [%s]\n",dtx ? "on" : "off"); } else if (!strcasecmp(var->name, "preprocess")) { preproc = ast_true(var->value) ? 1 : 0; ast_verb(3, "CODEC SPEEX: Preprocessing. [%s]\n",preproc ? "on" : "off"); } else if (!strcasecmp(var->name, "pp_vad")) { pp_vad = ast_true(var->value) ? 1 : 0; ast_verb(3, "CODEC SPEEX: Preprocessor VAD. [%s]\n",pp_vad ? "on" : "off"); } else if (!strcasecmp(var->name, "pp_agc")) { pp_agc = ast_true(var->value) ? 1 : 0; ast_verb(3, "CODEC SPEEX: Preprocessor AGC. [%s]\n",pp_agc ? "on" : "off"); } else if (!strcasecmp(var->name, "pp_agc_level")) { if (sscanf(var->value, "%30f", &res_f) == 1 && res_f >= 0) { ast_verb(3, "CODEC SPEEX: Setting preprocessor AGC Level to %f\n",res_f); pp_agc_level = res_f; } else ast_log(LOG_ERROR,"Error! Preprocessor AGC Level must be >= 0\n"); } else if (!strcasecmp(var->name, "pp_denoise")) { pp_denoise = ast_true(var->value) ? 1 : 0; ast_verb(3, "CODEC SPEEX: Preprocessor Denoise. [%s]\n",pp_denoise ? "on" : "off"); } else if (!strcasecmp(var->name, "pp_dereverb")) { pp_dereverb = ast_true(var->value) ? 1 : 0; ast_verb(3, "CODEC SPEEX: Preprocessor Dereverb. [%s]\n",pp_dereverb ? "on" : "off"); } else if (!strcasecmp(var->name, "pp_dereverb_decay")) { if (sscanf(var->value, "%30f", &res_f) == 1 && res_f >= 0) { ast_verb(3, "CODEC SPEEX: Setting preprocessor Dereverb Decay to %f\n",res_f); pp_dereverb_decay = res_f; } else ast_log(LOG_ERROR,"Error! Preprocessor Dereverb Decay must be >= 0\n"); } else if (!strcasecmp(var->name, "pp_dereverb_level")) { if (sscanf(var->value, "%30f", &res_f) == 1 && res_f >= 0) { ast_verb(3, "CODEC SPEEX: Setting preprocessor Dereverb Level to %f\n",res_f); pp_dereverb_level = res_f; } else ast_log(LOG_ERROR,"Error! Preprocessor Dereverb Level must be >= 0\n"); } } ast_config_destroy(cfg); return 0; }