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_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 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 int do_reload(void) { struct ast_config *config; const char *enabled_value; const char *val; int res = 0; struct ast_flags config_flags = { 0, }; const char *s; ast_mutex_lock(&reload_lock); /* Reset all settings before reloading configuration */ cel_enabled = CEL_ENALBED_DEFAULT; eventset = CEL_DEFAULT_EVENTS; *cel_dateformat = '\0'; ao2_callback(appset, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL); config = ast_config_load2("cel.conf", "cel", config_flags); if (config == CONFIG_STATUS_FILEMISSING) { config = NULL; goto return_cleanup; } if ((enabled_value = ast_variable_retrieve(config, "general", "enable"))) { cel_enabled = ast_true(enabled_value); } if (!cel_enabled) { goto return_cleanup; } /* get the date format for logging */ if ((s = ast_variable_retrieve(config, "general", "dateformat"))) { ast_copy_string(cel_dateformat, s, sizeof(cel_dateformat)); } if ((val = ast_variable_retrieve(config, "general", "events"))) { parse_events(val); } if ((val = ast_variable_retrieve(config, "general", "apps"))) { parse_apps(val); } return_cleanup: ast_verb(3, "CEL logging %sabled.\n", cel_enabled ? "en" : "dis"); ast_mutex_unlock(&reload_lock); if (config) { ast_config_destroy(config); } return res; }
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; } }
/* read config and translate to values */ for (v = ast_variable_browse (cfg, cat); v; v = v->next) { if (!strcasecmp (v->name, "context")) { ast_copy_string (config->context, v->value, sizeof (config->context)); } else if (!strcasecmp (v->name, "exten")) { ast_copy_string (config->exten, v->value, sizeof (config->exten)); } else if (!strcasecmp (v->name, "language")) { ast_copy_string (config->language, v->value, sizeof (config->language));/* set channel language */ } else if (!strcasecmp (v->name, "group")) { config->group = (int) strtol (v->value, (char**) NULL, 10); /* group is set to 0 if invalid */ } else if (!strcasecmp (v->name, "rxgain")) { config->rxgain = (int) strtol (v->value, (char**) NULL, 10); /* rxgain is set to 0 if invalid */ } else if (!strcasecmp (v->name, "txgain")) { config->txgain = (int) strtol (v->value, (char**) NULL, 10); /* txgain is set to 0 if invalid */ } else if (!strcasecmp (v->name, "u2diag")) { errno = 0; config->u2diag = (int) strtol (v->value, (char**) NULL, 10); /* u2diag is set to -1 if invalid */ if (config->u2diag == 0 && errno == EINVAL) { config->u2diag = -1; } } else if (!strcasecmp (v->name, "callingpres")) { config->callingpres = ast_parse_caller_presentation (v->value); if (config->callingpres == -1) { errno = 0; config->callingpres = (int) strtol (v->value, (char**) NULL, 10);/* callingpres is set to -1 if invalid */ if (config->callingpres == 0 && errno == EINVAL) { config->callingpres = -1; } } } else if (!strcasecmp (v->name, "usecallingpres")) { config->usecallingpres = ast_true (v->value); /* usecallingpres is set to 0 if invalid */ } else if (!strcasecmp (v->name, "autodeletesms")) { config->autodeletesms = ast_true (v->value); /* autodeletesms is set to 0 if invalid */ } else if (!strcasecmp (v->name, "resetdongle")) { config->resetdongle = ast_true (v->value); /* resetdongle is set to 0 if invalid */ } else if (!strcasecmp (v->name, "disablesms")) { config->disablesms = ast_true (v->value); /* disablesms is set to 0 if invalid */ } else if (!strcasecmp (v->name, "smsaspdu")) { config->smsaspdu = ast_true (v->value); /* send_sms_as_pdu us set to 0 if invalid */ } else if (!strcasecmp (v->name, "disable")) { config->initstate = ast_true (v->value) ? DEV_STATE_REMOVED : DEV_STATE_STARTED; } else if (!strcasecmp (v->name, "initstate")) { int val = str2enum(v->value, dev_state_strs, ITEMS_OF(dev_state_strs)); if(val == DEV_STATE_STOPPED || val == DEV_STATE_STARTED || val == DEV_STATE_REMOVED) config->initstate = val; else ast_log(LOG_ERROR, "Invalid value for 'initstate': '%s', must be one of 'stop' 'start' 'remove' default is 'start'\n", v->value); } else if (!strcasecmp (v->name, "callwaiting")) { if(strcasecmp(v->value, "auto")) config->callwaiting = ast_true (v->value); } else if (!strcasecmp (v->name, "dtmf")) { int val = dc_dtmf_str2setting(v->value); if(val >= 0) config->dtmf = val; else ast_log(LOG_ERROR, "Invalid value for 'dtmf': '%s', setting default 'relax'\n", v->value); } else if (!strcasecmp (v->name, "mindtmfgap")) { errno = 0; config->mindtmfgap = (int) strtol (v->value, (char**) NULL, 10); if ((config->mindtmfgap == 0 && errno == EINVAL) || config->mindtmfgap < 0) { ast_log(LOG_ERROR, "Invalid value for 'mindtmfgap' '%s', setting default %d\n", v->value, DEFAULT_MINDTMFGAP); config->mindtmfgap = DEFAULT_MINDTMFGAP; } } else if (!strcasecmp (v->name, "mindtmfduration")) { errno = 0; config->mindtmfduration = (int) strtol (v->value, (char**) NULL, 10); if ((config->mindtmfduration == 0 && errno == EINVAL) || config->mindtmfduration < 0) { ast_log(LOG_ERROR, "Invalid value for 'mindtmfgap' '%s', setting default %d\n", v->value, DEFAULT_MINDTMFDURATION); config->mindtmfduration = DEFAULT_MINDTMFDURATION; } } else if (!strcasecmp (v->name, "mindtmfinterval")) { errno = 0; config->mindtmfinterval = (int) strtol (v->value, (char**) NULL, 10); if ((config->mindtmfinterval == 0 && errno == EINVAL) || config->mindtmfinterval < 0) { ast_log(LOG_ERROR, "Invalid value for 'mindtmfinterval' '%s', setting default %d\n", v->value, DEFAULT_MINDTMFINTERVAL); config->mindtmfduration = DEFAULT_MINDTMFINTERVAL; } } } } #/* */ EXPORT_DEF void dc_gconfig_fill(struct ast_config * cfg, const char * cat, struct dc_gconfig * config) { struct ast_variable * v; int tmp; const char * stmp; /* set default values */ memcpy(&config->jbconf, &jbconf_default, sizeof(config->jbconf)); config->discovery_interval = DEFAULT_DISCOVERY_INT; stmp = ast_variable_retrieve (cfg, cat, "interval"); if(stmp) { errno = 0; tmp = (int) strtol (stmp, (char**) NULL, 10); if (tmp == 0 && errno == EINVAL) ast_log (LOG_NOTICE, "Error parsing 'interval' in general section, using default value %d\n", config->discovery_interval); else config->discovery_interval = tmp; } for (v = ast_variable_browse (cfg, cat); v; v = v->next) /* handle jb conf */ ast_jb_read_conf (&config->jbconf, v->name, v->value); }
static int load_config_string(struct ast_config *cfg, const char *category, const char *variable, struct ast_str **field, const char *def) { struct unload_string *us; const char *tmp; if (!(us = ast_calloc(1, sizeof(*us)))) { return -1; } if (!(*field = ast_str_create(16))) { ast_free(us); return -1; } tmp = ast_variable_retrieve(cfg, category, variable); ast_str_set(field, 0, "%s", tmp ? tmp : def); us->str = *field; AST_LIST_LOCK(&unload_strings); AST_LIST_INSERT_HEAD(&unload_strings, us, entry); AST_LIST_UNLOCK(&unload_strings); return 0; }
/* Copyright (C) 2010 */ #ifdef HAVE_CONFIG_H #include <config.h> #endif /* HAVE_CONFIG_H */ #include "dc_config.h" #include <asterisk/callerid.h> /* ast_parse_caller_presentation() */ static struct ast_jb_conf jbconf_default = { .flags = 0, .max_size = -1, .resync_threshold = -1, .impl = "", .target_extra = -1, }; static const char * const dtmf_values[] = { "off", "inband", "relax" }; EXPORT_DEF int dc_dtmf_str2setting(const char * value) { return str2enum(value, dtmf_values, ITEMS_OF(dtmf_values)); } EXPORT_DEF const char * dc_dtmf_setting2str(dc_dtmf_setting_t dtmf) { return enum2str(dtmf, dtmf_values, ITEMS_OF(dtmf_values)); } #/* assume config is zerofill */ static int dc_uconfig_fill(struct ast_config * cfg, const char * cat, struct dc_uconfig * config) { const char * audio_tty; const char * data_tty; const char * imei; const char * imsi; audio_tty = ast_variable_retrieve (cfg, cat, "audio"); data_tty = ast_variable_retrieve (cfg, cat, "data"); imei = ast_variable_retrieve (cfg, cat, "imei"); imsi = ast_variable_retrieve (cfg, cat, "imsi"); if(imei && strlen(imei) != IMEI_SIZE) { ast_log (LOG_WARNING, "[%s] Ignore invalid IMEI value '%s'\n", cat, imei); imei = NULL; } if(imsi && strlen(imsi) != IMSI_SIZE) { ast_log (LOG_WARNING, "[%s] Ignore invalid IMSI value '%s'\n", cat, imsi); imsi = NULL; } if(!audio_tty && !imei && !imsi) { ast_log (LOG_ERROR, "Skipping device %s. Missing required audio_tty setting\n", cat); return 1; } if(!data_tty && !imei && !imsi) { ast_log (LOG_ERROR, "Skipping device %s. Missing required data_tty setting\n", cat); return 1; } if((!data_tty && audio_tty) || (data_tty && !audio_tty)) { ast_log (LOG_ERROR, "Skipping device %s. data_tty and audio_tty should use together\n", cat); return 1; } ast_copy_string (config->id, cat, sizeof (config->id)); ast_copy_string (config->data_tty, S_OR(data_tty, ""), sizeof (config->data_tty)); ast_copy_string (config->audio_tty, S_OR(audio_tty, ""), sizeof (config->audio_tty)); ast_copy_string (config->imei, S_OR(imei, ""), sizeof (config->imei)); ast_copy_string (config->imsi, S_OR(imsi, ""), sizeof (config->imsi)); 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; }
/** \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 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 load_config_number(struct ast_config *cfg, const char *category, const char *variable, int *field, int def) { const char *tmp; tmp = ast_variable_retrieve(cfg, category, variable); if (!tmp || sscanf(tmp, "%d", field) < 1) { *field = def; } return 0; }
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); }
/*! \brief Initialize the ENUM support subsystem */ static int private_enum_init(int reload) { struct ast_config *cfg; const char *string; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; if ((cfg = ast_config_load2("enum.conf", "enum", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) return 0; if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) { return 0; } /* Destroy existing list */ ast_mutex_lock(&enumlock); if (cfg) { if ((string = ast_variable_retrieve(cfg, "ienum", "branchlabel"))) { ast_copy_string(ienum_branchlabel, string, sizeof(ienum_branchlabel)); } if ((string = ast_variable_retrieve(cfg, "ienum", "ebl_alg"))) { ebl_alg = ENUMLOOKUP_BLR_CC; /* default */ if (!strcasecmp(string, "txt")) ebl_alg = ENUMLOOKUP_BLR_TXT; else if (!strcasecmp(string, "ebl")) ebl_alg = ENUMLOOKUP_BLR_EBL; else if (!strcasecmp(string, "cc")) ebl_alg = ENUMLOOKUP_BLR_CC; else ast_log(LOG_WARNING, "No valid parameter for ienum/ebl_alg.\n"); } ast_config_destroy(cfg); } ast_mutex_unlock(&enumlock); manager_event(EVENT_FLAG_SYSTEM, "Reload", "Module: Enum\r\nStatus: Enabled\r\nMessage: ENUM reload Requested\r\n"); return 0; }
/*! \brief Helper function which returns if an object is matching or not */ static int realtime_is_object_matching(const char *object_id, const struct ast_variable *fields) { const struct ast_variable *field; for (field = fields; field; field = field->next) { char *name = ast_strdupa(field->name), *like; const char *value; /* If we are doing a pattern matching we need to remove the LIKE from the name */ if ((like = strstr(name, " LIKE"))) { char *pattern, *field_value = ast_strdupa(field->value); *like = '\0'; value = ast_strdupa(ast_variable_retrieve(realtime_objects, object_id, name)); if (!(pattern = strchr(field_value, '%'))) { return 0; } *pattern = '\0'; if (strncmp(value, field_value, strlen(field_value))) { return 0; } } else { value = ast_variable_retrieve(realtime_objects, object_id, name); if (ast_strlen_zero(value) || strcmp(value, field->value)) { return 0; } } } return 1; }
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; } /* create dir /var/lib/cdr if it does not exist. add by liucl */ if (access(cdr_directory,F_OK) == -1){ ast_log(LOG_DEBUG,"cdr_directory %s is not exist, I will create it.\n",cdr_directory); if(ast_mkdir(cdr_directory, 0755) == -1) { ast_log(LOG_ERROR,"Failed to create %s\n", cdr_directory); }else{ ast_log(LOG_DEBUG,"Create directory %s is OK\n",cdr_directory); } } /* liucl add end*/ /* * 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_cel_backend_register(RADIUS_BACKEND_NAME, radius_log)) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { /* * * Create a independent thread to monitoring /var/lib/cdr. * * If there is file in the directory, then send it to radius. * * add by liucl * */ start_monitor(); return AST_MODULE_LOAD_SUCCESS; } }
static int load_config(void) { /* int res; */ struct ast_config *cfg; struct ast_variable *var; const char *tmp; struct ast_flags config_flags = { 0 }; cfg = ast_config_load(CBMYSQL_CONFIG, config_flags); if (!cfg) { ast_log(LOG_WARNING, "Unable to load config for CBMySQL: %s\n", CBMYSQL_CONFIG); return 0; } var = ast_variable_browse(cfg, "global"); if (!var) { return 0; } tmp = ast_variable_retrieve(cfg,"global","hostname"); if (tmp) { hostname = malloc(strlen(tmp) + 1); if (hostname != NULL) { hostname_alloc = 1; strcpy(hostname,tmp); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } else { hostname = malloc(strlen("localhost") + 1); if (hostname != NULL) { ast_log(LOG_WARNING,"MySQL server hostname not specified. Assuming localhost\n"); hostname_alloc = 1; strcpy(hostname,"localhost"); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } tmp = ast_variable_retrieve(cfg,"global","dbname"); if (tmp) { dbname = malloc(strlen(tmp) + 1); if (dbname != NULL) { dbname_alloc = 1; strcpy(dbname,tmp); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } else { dbname = malloc(strlen("meetme") + 1); if (dbname != NULL) { ast_log(LOG_WARNING,"MySQL database not specified. Assuming meetme\n"); dbname_alloc = 1; strcpy(dbname,"meetme"); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } tmp = ast_variable_retrieve(cfg,"global","table"); if (tmp) { table = malloc(strlen(tmp) + 1); if (table != NULL) { table_alloc = 1; strcpy(table,tmp); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } else { table = malloc(strlen("booking") + 1); if (table != NULL) { ast_log(LOG_WARNING,"MySQL table not specified. Assuming booking\n"); table_alloc = 1; strcpy(table,"booking"); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } tmp = ast_variable_retrieve(cfg,"global","user"); if (tmp) { dbuser = malloc(strlen(tmp) + 1); if (dbuser != NULL) { dbuser_alloc = 1; strcpy(dbuser,tmp); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } else { dbuser = malloc(strlen("root") + 1); if (dbuser != NULL) { ast_log(LOG_WARNING,"MySQL database user not specified. Assuming root\n"); strcpy(password,"root"); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } tmp = ast_variable_retrieve(cfg,"global","sock"); if (tmp) { dbsock = malloc(strlen(tmp) + 1); if (dbsock != NULL) { dbsock_alloc = 1; strcpy(dbsock,tmp); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } else { ast_log(LOG_WARNING,"MySQL database sock file not specified. Using default\n"); dbsock = NULL; } tmp = ast_variable_retrieve(cfg,"global","password"); if (tmp) { password = malloc(strlen(tmp) + 1); if (password != NULL) { password_alloc = 1; strcpy(password,tmp); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } else { password = malloc(strlen("") + 1); if (password != NULL) { ast_log(LOG_WARNING,"MySQL database password not specified. Assuming blank\n"); password_alloc = 1; strcpy(password,""); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } tmp = ast_variable_retrieve(cfg,"global","port"); if (tmp) { if (sscanf(tmp,"%d",&dbport) < 1) { ast_log(LOG_WARNING,"Invalid MySQL port number. Using default\n"); dbport = 0; } } tmp = ast_variable_retrieve(cfg,"global","DBOpts"); if (tmp) { DBOpts = ast_true(tmp); } if (!DBOpts){ tmp = ast_variable_retrieve(cfg,"global","OptsAdm"); if (tmp) { OptsAdm = malloc(strlen(tmp) + 1); if (OptsAdm != NULL) { strcpy(OptsAdm,tmp); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } else { ast_log(LOG_WARNING,"Invalid Conference Admin options. Using default\n"); } tmp = ast_variable_retrieve(cfg,"global","OptsUsr"); if (tmp) { OptsUsr = malloc(strlen(tmp) + 1); if (OptsUsr != NULL) { strcpy(OptsUsr,tmp); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } else { ast_log(LOG_WARNING,"Invalid Conference User options. Using default\n"); } } tmp = ast_variable_retrieve(cfg,"global","ConfApp"); if (tmp) { ConfApp = malloc(strlen(tmp) + 1); if (ConfApp != NULL) { strcpy(ConfApp,tmp); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } else { ConfApp = malloc(strlen("MeetMe") + 1); if (ConfApp!= NULL) { ast_log(LOG_WARNING,"No Conference application. Using MeetMe\n"); strcpy(ConfApp, "MeetMe"); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } tmp = ast_variable_retrieve(cfg,"global","ConfAppCount"); if (tmp) { ConfAppCount = malloc(strlen(tmp) + 1); if (ConfAppCount!= NULL) { strcpy(ConfAppCount,tmp); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } else { ConfAppCount = malloc(strlen("MeetMeCount") + 1); if (ConfAppCount!= NULL) { ast_log(LOG_WARNING,"No Conference count application. Using MeetMe\n"); strcpy(ConfAppCount, "MeetMeCount"); } else { ast_log(LOG_ERROR,"Out of memory error.\n"); return -1; } } tmp = ast_variable_retrieve(cfg,"global","earlyalert"); if (tmp) { if (sscanf(tmp,"%d",&earlyalert) < 1) ast_log(LOG_WARNING,"Invalid Early Alert time.\n"); } tmp = ast_variable_retrieve(cfg,"global","fuzzystart"); if (tmp) { if (sscanf(tmp,"%d",&fuzzystart) < 1) ast_log(LOG_WARNING,"Invalid Fuzzy Start time.\n"); } ast_config_destroy(cfg); if (option_debug > 3){ ast_log(LOG_DEBUG,"CBMySQL: got hostname of %s\n",hostname); ast_log(LOG_DEBUG,"CBMySQL: got port of %d\n",dbport); if (dbsock) ast_log(LOG_DEBUG,"CBMySQL: got sock file of %s\n",dbsock); ast_log(LOG_DEBUG,"CBMySQL: got user of %s\n",dbuser); ast_log(LOG_DEBUG,"CBMySQL: got dbname of %s\n",dbname); ast_log(LOG_DEBUG,"CBMySQL: got password of %s\n",password); if (DBOpts) { ast_log(LOG_DEBUG,"CBMySQL: Using Database for Admin & User Options\n "); } else { ast_log(LOG_DEBUG,"CBMySQL: got Admin Options of %s\n",OptsAdm); ast_log(LOG_DEBUG,"CBMySQL: got User Options of %s\n",OptsUsr); } ast_log(LOG_DEBUG,"CBMySQL: got Connference Application of %s\n",ConfApp); ast_log(LOG_DEBUG,"CBMySQL: got Conference Count Application of %s\n",ConfAppCount); if (earlyalert) ast_log(LOG_DEBUG, "CBMySQL: Early Alert set to %i seconds.\n", earlyalert); if (fuzzystart) ast_log(LOG_DEBUG, "CBMySQL: Fuzzy Start set to %i seconds.\n", fuzzystart); } ast_mutex_lock(&handle.lock); mysql_init(&handle.mysql); if (!mysql_real_connect(&handle.mysql, hostname, dbuser, password, dbname, dbport, dbsock, 0)) { ast_log(LOG_ERROR, "Failed to connect to mysql database %s on %s.\n", dbname, hostname); connected = 0; records = 0; } else { ast_log(LOG_NOTICE,"Successfully connected to MySQL database.\n"); connected = 1; records = 0; connect_time = time(NULL); } ast_mutex_unlock(&handle.lock); if (connected) return 1; else return 0; }
int load_mrcp_config(const char *filename, const char *who_asked) { const char *cat = NULL; struct ast_variable *var; const char *value = NULL; #if AST_VERSION_AT_LEAST(1,6,0) struct ast_flags config_flags = { 0 }; struct ast_config *cfg = ast_config_load2(filename, who_asked, config_flags); #else struct ast_config *cfg = ast_config_load(filename); #endif if (!cfg) { ast_log(LOG_WARNING, "No such configuration file %s\n", filename); return -1; } #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", filename); return -1; } #endif globals_clear(); globals_default(); if ((value = ast_variable_retrieve(cfg, "general", "default-tts-profile")) != NULL) { ast_log(LOG_DEBUG, "general.default-tts-profile=%s\n", value); globals.unimrcp_default_synth_profile = apr_pstrdup(globals.pool, value); } else { ast_log(LOG_ERROR, "Unable to load genreal.default-tts-profile from config file, aborting\n"); ast_config_destroy(cfg); return -1; } if ((value = ast_variable_retrieve(cfg, "general", "default-asr-profile")) != NULL) { ast_log(LOG_DEBUG, "general.default-asr-profile=%s\n", value); globals.unimrcp_default_recog_profile = apr_pstrdup(globals.pool, value); } else { ast_log(LOG_ERROR, "Unable to load genreal.default-asr-profile from config file, aborting\n"); ast_config_destroy(cfg); return -1; } if ((value = ast_variable_retrieve(cfg, "general", "log-level")) != NULL) { ast_log(LOG_DEBUG, "general.log-level=%s\n", value); globals.unimrcp_log_level = apr_pstrdup(globals.pool, value); } if ((value = ast_variable_retrieve(cfg, "general", "max-connection-count")) != NULL) { ast_log(LOG_DEBUG, "general.max-connection-count=%s\n", value); globals.unimrcp_max_connection_count = apr_pstrdup(globals.pool, value); } if ((value = ast_variable_retrieve(cfg, "general", "offer-new-connection")) != NULL) { ast_log(LOG_DEBUG, "general.offer-new-connection=%s\n", value); globals.unimrcp_offer_new_connection = apr_pstrdup(globals.pool, value); } if ((value = ast_variable_retrieve(cfg, "general", "rx-buffer-size")) != NULL) { ast_log(LOG_DEBUG, "general.rx-buffer-size=%s\n", value); globals.unimrcp_rx_buffer_size = apr_pstrdup(globals.pool, value); } if ((value = ast_variable_retrieve(cfg, "general", "tx-buffer-size")) != NULL) { ast_log(LOG_DEBUG, "general.tx-buffer-size=%s\n", value); globals.unimrcp_tx_buffer_size = apr_pstrdup(globals.pool, value); } if ((value = ast_variable_retrieve(cfg, "general", "request-timeout")) != NULL) { ast_log(LOG_DEBUG, "general.request-timeout=%s\n", value); globals.unimrcp_request_timeout = apr_pstrdup(globals.pool, value); } while ((cat = ast_category_browse(cfg, cat)) != NULL) { if (strcasecmp(cat, "general") != 0) { if ((value = ast_variable_retrieve(cfg, cat, "version")) != NULL) { ast_mrcp_profile_t *mod_profile = NULL; if (profile_create(&mod_profile, cat, value, globals.pool) == 0) { apr_hash_set(globals.profiles, apr_pstrdup(globals.pool, mod_profile->name), APR_HASH_KEY_STRING, mod_profile); for (var = ast_variable_browse(cfg, cat); var; var = var->next) { ast_log(LOG_DEBUG, "%s.%s=%s\n", cat, var->name, var->value); apr_hash_set(mod_profile->cfg, apr_pstrdup(globals.pool, var->name), APR_HASH_KEY_STRING, apr_pstrdup(globals.pool, var->value)); } } else ast_log(LOG_WARNING, "Unable to create a profile for %s\n", cat); } else ast_log(LOG_WARNING, "Category %s does not have a version variable defined\n", cat); } } ast_config_destroy(cfg); return 0; }
static int odbc_load_module(void) { int res = 0; struct ast_config *cfg; struct ast_variable *var; const char *tmp; ast_mutex_lock(&odbc_lock); cfg = ast_config_load(config); if (!cfg) { ast_log(LOG_WARNING, "cdr_odbc: Unable to load config for ODBC CDR's: %s\n", config); res = AST_MODULE_LOAD_DECLINE; goto out; } var = ast_variable_browse(cfg, "global"); if (!var) { /* nothing configured */ goto out; } tmp = ast_variable_retrieve(cfg,"global","dsn"); if (tmp == NULL) { ast_log(LOG_WARNING,"cdr_odbc: dsn not specified. Assuming asteriskdb\n"); tmp = "asteriskdb"; } dsn = strdup(tmp); if (dsn == NULL) { ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n"); res = -1; goto out; } tmp = ast_variable_retrieve(cfg,"global","dispositionstring"); if (tmp) { dispositionstring = ast_true(tmp); } else { dispositionstring = 0; } tmp = ast_variable_retrieve(cfg,"global","username"); if (tmp) { username = strdup(tmp); if (username == NULL) { ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n"); res = -1; goto out; } } tmp = ast_variable_retrieve(cfg,"global","password"); if (tmp) { password = strdup(tmp); if (password == NULL) { ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n"); res = -1; goto out; } } tmp = ast_variable_retrieve(cfg,"global","loguniqueid"); if (tmp) { loguniqueid = ast_true(tmp); if (loguniqueid) { ast_log(LOG_DEBUG,"cdr_odbc: Logging uniqueid\n"); } else { ast_log(LOG_DEBUG,"cdr_odbc: Not logging uniqueid\n"); } } else { ast_log(LOG_DEBUG,"cdr_odbc: Not logging uniqueid\n"); loguniqueid = 0; } tmp = ast_variable_retrieve(cfg,"global","usegmtime"); if (tmp) { usegmtime = ast_true(tmp); if (usegmtime) { ast_log(LOG_DEBUG,"cdr_odbc: Logging in GMT\n"); } else { ast_log(LOG_DEBUG,"cdr_odbc: Not logging in GMT\n"); } } else { ast_log(LOG_DEBUG,"cdr_odbc: Not logging in GMT\n"); usegmtime = 0; } tmp = ast_variable_retrieve(cfg,"global","table"); if (tmp == NULL) { ast_log(LOG_WARNING,"cdr_odbc: table not specified. Assuming cdr\n"); tmp = "cdr"; } table = strdup(tmp); if (table == NULL) { ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n"); res = -1; goto out; } if (option_verbose > 2) { ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: dsn is %s\n",dsn); if (username) { ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: username is %s\n",username); ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: password is [secret]\n"); } else ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: retreiving username and password from odbc config\n"); ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: table is %s\n",table); } res = odbc_init(); if (res < 0) { ast_log(LOG_ERROR, "cdr_odbc: Unable to connect to datasource: %s\n", dsn); if (option_verbose > 2) { ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: Unable to connect to datasource: %s\n", dsn); } } res = ast_cdr_register(name, ast_module_info->description, odbc_log); if (res) { ast_log(LOG_ERROR, "cdr_odbc: Unable to register ODBC CDR handling\n"); } out: if (cfg) ast_config_destroy(cfg); ast_mutex_unlock(&odbc_lock); return res; }
static int parse_config(void) { struct ast_config *config; const char *s; config = ast_config_load(RES_CONFIG_PGSQL_CONF); if (!config) { ast_log(LOG_WARNING, "Unable to load config %s\n",RES_CONFIG_PGSQL_CONF); return 0; } if (!(s = ast_variable_retrieve(config, "general", "dbuser"))) { ast_log(LOG_WARNING, "Postgresql RealTime: No database user found, using 'asterisk' as default.\n"); strcpy(dbuser, "asterisk"); } else { ast_copy_string(dbuser, s, sizeof(dbuser)); } if (!(s = ast_variable_retrieve(config, "general", "dbpass"))) { ast_log(LOG_WARNING, "Postgresql RealTime: No database password found, using 'asterisk' as default.\n"); strcpy(dbpass, "asterisk"); } else { ast_copy_string(dbpass, s, sizeof(dbpass)); } if (!(s = ast_variable_retrieve(config, "general", "dbhost"))) { ast_log(LOG_WARNING, "Postgresql RealTime: No database host found, using localhost via socket.\n"); dbhost[0] = '\0'; } else { ast_copy_string(dbhost, s, sizeof(dbhost)); } if (!(s = ast_variable_retrieve(config, "general", "dbname"))) { ast_log(LOG_WARNING, "Postgresql RealTime: No database name found, using 'asterisk' as default.\n"); strcpy(dbname, "asterisk"); } else { ast_copy_string(dbname, s, sizeof(dbname)); } if (!(s = ast_variable_retrieve(config, "general", "dbport"))) { ast_log(LOG_WARNING, "Postgresql RealTime: No database port found, using 5432 as default.\n"); dbport = 5432; } else { dbport = atoi(s); } if (dbhost && !(s = ast_variable_retrieve(config, "general", "dbsock"))) { ast_log(LOG_WARNING, "Postgresql RealTime: No database socket found, using '/tmp/pgsql.sock' as default.\n"); strcpy(dbsock, "/tmp/pgsql.sock"); } else { ast_copy_string(dbsock, s, sizeof(dbsock)); } ast_config_destroy(config); if (dbhost) { ast_log(LOG_DEBUG, "Postgresql RealTime Host: %s\n", dbhost); ast_log(LOG_DEBUG, "Postgresql RealTime Port: %i\n", dbport); } else { ast_log(LOG_DEBUG, "Postgresql RealTime Socket: %s\n", dbsock); } ast_log(LOG_DEBUG, "Postgresql RealTime User: %s\n", dbuser); ast_log(LOG_DEBUG, "Postgresql RealTime Password: %s\n", dbpass); ast_log(LOG_DEBUG, "Postgresql RealTime DBName: %s\n", dbname); return 1; }
static int do_directory(struct ast_channel *chan, struct ast_config *cfg, struct ast_config *ucfg, char *context, char *dialcontext, char digit, int last, int readext, int fromappvm) { /* Read in the first three digits.. "digit" is the first digit, already read */ char ext[NUMDIGITS + 1], *cat; char name[80] = ""; struct ast_variable *v; int res; int found=0; int lastuserchoice = 0; char *start, *conv, *stringp = NULL; const char *pos; int breakout = 0; if (ast_strlen_zero(context)) { ast_log(LOG_WARNING, "Directory must be called with an argument " "(context in which to interpret extensions)\n"); return -1; } if (digit == '0') { if (!ast_goto_if_exists(chan, dialcontext, "o", 1) || (!ast_strlen_zero(chan->macrocontext) && !ast_goto_if_exists(chan, chan->macrocontext, "o", 1))) { return 0; } else { ast_log(LOG_WARNING, "Can't find extension 'o' in current context. " "Not Exiting the Directory!\n"); res = 0; } } if (digit == '*') { if (!ast_goto_if_exists(chan, dialcontext, "a", 1) || (!ast_strlen_zero(chan->macrocontext) && !ast_goto_if_exists(chan, chan->macrocontext, "a", 1))) { return 0; } else { ast_log(LOG_WARNING, "Can't find extension 'a' in current context. " "Not Exiting the Directory!\n"); res = 0; } } memset(ext, 0, sizeof(ext)); ext[0] = digit; res = 0; if (ast_readstring(chan, ext + 1, NUMDIGITS - 1, 3000, 3000, "#") < 0) res = -1; if (!res) { /* Search for all names which start with those digits */ v = ast_variable_browse(cfg, context); while(v && !res) { /* Find all candidate extensions */ while(v) { /* Find a candidate extension */ start = strdup(v->value); if (start && !strcasestr(start, "hidefromdir=yes")) { stringp=start; strsep(&stringp, ","); pos = strsep(&stringp, ","); if (pos) { ast_copy_string(name, pos, sizeof(name)); /* Grab the last name */ if (last && strrchr(pos,' ')) pos = strrchr(pos, ' ') + 1; conv = convert(pos); if (conv) { if (!strncmp(conv, ext, strlen(ext))) { /* Match! */ found++; free(conv); free(start); break; } free(conv); } } free(start); } v = v->next; } if (v) { /* We have a match -- play a greeting if they have it */ res = play_mailbox_owner(chan, context, dialcontext, v->name, name, readext, fromappvm); switch (res) { case -1: /* user pressed '1' but extension does not exist, or * user hungup */ lastuserchoice = 0; break; case '1': /* user pressed '1' and extensions exists; play_mailbox_owner will already have done a goto() on the channel */ lastuserchoice = res; break; case '*': /* user pressed '*' to skip something found */ lastuserchoice = res; res = 0; break; default: break; } v = v->next; } } if (!res && ucfg) { /* Search users.conf for all names which start with those digits */ for (cat = ast_category_browse(ucfg, NULL); cat && !res ; cat = ast_category_browse(ucfg, cat)) { if (!strcasecmp(cat, "general")) continue; if (!ast_true(ast_config_option(ucfg, cat, "hasdirectory"))) continue; /* Find all candidate extensions */ if ((pos = ast_variable_retrieve(ucfg, cat, "fullname"))) { ast_copy_string(name, pos, sizeof(name)); /* Grab the last name */ if (last && strrchr(pos,' ')) pos = strrchr(pos, ' ') + 1; conv = convert(pos); if (conv) { if (!strcmp(conv, ext)) { /* Match! */ found++; /* We have a match -- play a greeting if they have it */ res = play_mailbox_owner(chan, context, dialcontext, cat, name, readext, fromappvm); switch (res) { case -1: /* user pressed '1' but extension does not exist, or * user hungup */ lastuserchoice = 0; breakout = 1; break; case '1': /* user pressed '1' and extensions exists; play_mailbox_owner will already have done a goto() on the channel */ lastuserchoice = res; breakout = 1; break; case '*': /* user pressed '*' to skip something found */ lastuserchoice = res; breakout = 0; res = 0; break; default: breakout = 1; break; } free(conv); if (breakout) break; } else free(conv); } } } } if (lastuserchoice != '1') { res = ast_streamfile(chan, found ? "dir-nomore" : "dir-nomatch", chan->language); if (!res) res = 1; return res; } return 0; } return res; }
/* * Load module stuff */ static int ind_load_module(void) { struct ast_config *cfg; struct ast_variable *v; char *cxt; char *c; struct ind_tone_zone *tones; const char *country = NULL; /* that the following cast is needed, is yuk! */ /* yup, checked it out. It is NOT written to. */ cfg = ast_config_load((char *)config); if (!cfg) return -1; /* Use existing config to populate the Indication table */ cxt = ast_category_browse(cfg, NULL); while(cxt) { /* All categories but "general" are considered countries */ if (!strcasecmp(cxt, "general")) { cxt = ast_category_browse(cfg, cxt); continue; } if (!(tones = ast_calloc(1, sizeof(*tones)))) { ast_config_destroy(cfg); return -1; } ast_copy_string(tones->country,cxt,sizeof(tones->country)); v = ast_variable_browse(cfg, cxt); while(v) { if (!strcasecmp(v->name, "description")) { ast_copy_string(tones->description, v->value, sizeof(tones->description)); } else if ((!strcasecmp(v->name,"ringcadence"))||(!strcasecmp(v->name,"ringcadance"))) { char *ring,*rings = ast_strdupa(v->value); c = rings; ring = strsep(&c,","); while (ring) { int *tmp, val; if (!isdigit(ring[0]) || (val=atoi(ring))==-1) { ast_log(LOG_WARNING,"Invalid ringcadence given '%s' at line %d.\n",ring,v->lineno); ring = strsep(&c,","); continue; } if (!(tmp = ast_realloc(tones->ringcadence, (tones->nrringcadence + 1) * sizeof(int)))) { ast_config_destroy(cfg); return -1; } tones->ringcadence = tmp; tmp[tones->nrringcadence] = val; tones->nrringcadence++; /* next item */ ring = strsep(&c,","); } } else if (!strcasecmp(v->name,"alias")) { char *countries = ast_strdupa(v->value); c = countries; country = strsep(&c,","); while (country) { struct ind_tone_zone* azone; if (!(azone = ast_calloc(1, sizeof(*azone)))) { ast_config_destroy(cfg); return -1; } ast_copy_string(azone->country, country, sizeof(azone->country)); ast_copy_string(azone->alias, cxt, sizeof(azone->alias)); if (ast_register_indication_country(azone)) { ast_log(LOG_WARNING, "Unable to register indication alias at line %d.\n",v->lineno); free(tones); } /* next item */ country = strsep(&c,","); } } else { /* add tone to country */ struct ind_tone_zone_sound *ps,*ts; for (ps=NULL,ts=tones->tones; ts; ps=ts, ts=ts->next) { if (strcasecmp(v->name,ts->name)==0) { /* already there */ ast_log(LOG_NOTICE,"Duplicate entry '%s', skipped.\n",v->name); goto out; } } /* not there, add it to the back */ if (!(ts = ast_malloc(sizeof(*ts)))) { ast_config_destroy(cfg); return -1; } ts->next = NULL; ts->name = strdup(v->name); ts->data = strdup(v->value); if (ps) ps->next = ts; else tones->tones = ts; } out: v = v->next; } if (tones->description[0] || tones->alias[0] || tones->tones) { if (ast_register_indication_country(tones)) { ast_log(LOG_WARNING, "Unable to register indication at line %d.\n",v->lineno); free(tones); } } else free(tones); cxt = ast_category_browse(cfg, cxt); } /* determine which country is the default */ country = ast_variable_retrieve(cfg,"general","country"); if (!country || !*country || ast_set_indication_country(country)) ast_log(LOG_WARNING,"Unable to set the default country (for indication tones)\n"); ast_config_destroy(cfg); return 0; }
static int tds_load_module(void) { int res = 0; struct ast_config *cfg; struct ast_variable *var; char *ptr = NULL; #ifdef FREETDS_PRE_0_62 TDS_INT result_type; #endif cfg = ast_config_load(config); if (!cfg) { ast_log(LOG_NOTICE, "Unable to load config for MSSQL CDR's: %s\n", config); return 0; } var = ast_variable_browse(cfg, "global"); if (!var) /* nothing configured */ return 0; ptr = ast_variable_retrieve(cfg, "global", "hostname"); if (ptr) hostname = strdup(ptr); else ast_log(LOG_ERROR,"Database server hostname not specified.\n"); ptr = ast_variable_retrieve(cfg, "global", "dbname"); if (ptr) dbname = strdup(ptr); else ast_log(LOG_ERROR,"Database dbname not specified.\n"); ptr = ast_variable_retrieve(cfg, "global", "user"); if (ptr) dbuser = strdup(ptr); else ast_log(LOG_ERROR,"Database dbuser not specified.\n"); ptr = ast_variable_retrieve(cfg, "global", "password"); if (ptr) password = strdup(ptr); else ast_log(LOG_ERROR,"Database password not specified.\n"); ptr = ast_variable_retrieve(cfg, "global", "charset"); if (ptr) charset = strdup(ptr); else charset = strdup("iso_1"); ptr = ast_variable_retrieve(cfg, "global", "language"); if (ptr) language = strdup(ptr); else language = strdup("us_english"); ast_config_destroy(cfg); mssql_connect(); /* Register MSSQL CDR handler */ res = ast_cdr_register(name, desc, tds_log); if (res) { ast_log(LOG_ERROR, "Unable to register MSSQL CDR handling\n"); } return res; }
/* * Load the configuration from the configuration file */ static int load_config(void) { struct ast_config *cfg; const char *p; struct ast_flags config_flags = { 0 }; /* Read in the config file */ cfg = ast_config_load(ALMRCV_CONFIG, config_flags); if (!cfg) { ast_verb(4, "AlarmReceiver: No config file\n"); return 0; } else if (cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_ERROR, "Config file %s is in an invalid format. Aborting.\n", ALMRCV_CONFIG); return 0; } else { p = ast_variable_retrieve(cfg, "general", "eventcmd"); if (p) { ast_copy_string(event_app, p, sizeof(event_app)); } p = ast_variable_retrieve(cfg, "general", "loudness"); if (p) { toneloudness = atoi(p); if(toneloudness < 100) toneloudness = 100; if(toneloudness > 8192) toneloudness = 8192; } p = ast_variable_retrieve(cfg, "general", "fdtimeout"); if (p) { fdtimeout = atoi(p); if(fdtimeout < 1000) fdtimeout = 1000; if(fdtimeout > 10000) fdtimeout = 10000; } p = ast_variable_retrieve(cfg, "general", "sdtimeout"); if (p) { sdtimeout = atoi(p); if(sdtimeout < 110) sdtimeout = 110; if(sdtimeout > 4000) sdtimeout = 4000; } p = ast_variable_retrieve(cfg, "general", "logindividualevents"); if (p) log_individual_events = ast_true(p); p = ast_variable_retrieve(cfg, "general", "eventspooldir"); if (p) { ast_copy_string(event_spool_dir, p, sizeof(event_spool_dir)); } p = ast_variable_retrieve(cfg, "general", "timestampformat"); if (p) { ast_copy_string(time_stamp_format, p, sizeof(time_stamp_format)); } p = ast_variable_retrieve(cfg, "general", "db-family"); if (p) { ast_copy_string(db_family, p, sizeof(db_family)); } ast_config_destroy(cfg); } return 1; }
static int parse_config(int reload) { struct ast_config *config; const char *s; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; if ((config = ast_config_load(RES_CONFIG_PGSQL_CONF, config_flags)) == CONFIG_STATUS_FILEUNCHANGED) return 0; if (!config) { ast_log(LOG_WARNING, "Unable to load config %s\n", RES_CONFIG_PGSQL_CONF); return 0; } ast_mutex_lock(&pgsql_lock); if (pgsqlConn) { PQfinish(pgsqlConn); pgsqlConn = NULL; } if (!(s = ast_variable_retrieve(config, "general", "dbuser"))) { ast_log(LOG_WARNING, "PostgreSQL RealTime: No database user found, using 'asterisk' as default.\n"); strcpy(dbuser, "asterisk"); } else { ast_copy_string(dbuser, s, sizeof(dbuser)); } if (!(s = ast_variable_retrieve(config, "general", "dbpass"))) { ast_log(LOG_WARNING, "PostgreSQL RealTime: No database password found, using 'asterisk' as default.\n"); strcpy(dbpass, "asterisk"); } else { ast_copy_string(dbpass, s, sizeof(dbpass)); } if (!(s = ast_variable_retrieve(config, "general", "dbhost"))) { ast_log(LOG_WARNING, "PostgreSQL RealTime: No database host found, using localhost via socket.\n"); dbhost[0] = '\0'; } else { ast_copy_string(dbhost, s, sizeof(dbhost)); } if (!(s = ast_variable_retrieve(config, "general", "dbname"))) { ast_log(LOG_WARNING, "PostgreSQL RealTime: No database name found, using 'asterisk' as default.\n"); strcpy(dbname, "asterisk"); } else { ast_copy_string(dbname, s, sizeof(dbname)); } if (!(s = ast_variable_retrieve(config, "general", "dbport"))) { ast_log(LOG_WARNING, "PostgreSQL RealTime: No database port found, using 5432 as default.\n"); dbport = 5432; } else { dbport = atoi(s); } if (!ast_strlen_zero(dbhost)) { /* No socket needed */ } else if (!(s = ast_variable_retrieve(config, "general", "dbsock"))) { ast_log(LOG_WARNING, "PostgreSQL RealTime: No database socket found, using '/tmp/pgsql.sock' as default.\n"); strcpy(dbsock, "/tmp/pgsql.sock"); } else { ast_copy_string(dbsock, s, sizeof(dbsock)); } ast_config_destroy(config); if (option_debug) { if (!ast_strlen_zero(dbhost)) { ast_debug(1, "PostgreSQL RealTime Host: %s\n", dbhost); ast_debug(1, "PostgreSQL RealTime Port: %i\n", dbport); } else { ast_debug(1, "PostgreSQL RealTime Socket: %s\n", dbsock); } ast_debug(1, "PostgreSQL RealTime User: %s\n", dbuser); ast_debug(1, "PostgreSQL RealTime Password: %s\n", dbpass); ast_debug(1, "PostgreSQL RealTime DBName: %s\n", dbname); } if (!pgsql_reconnect(NULL)) { ast_log(LOG_WARNING, "PostgreSQL RealTime: Couldn't establish connection. Check debug.\n"); ast_debug(1, "PostgreSQL RealTime: Cannot Connect: %s\n", PQerrorMessage(pgsqlConn)); } ast_verb(2, "PostgreSQL RealTime reloaded.\n"); /* Done reloading. Release lock so others can now use driver. */ ast_mutex_unlock(&pgsql_lock); return 1; }
static int festival_exec(struct ast_channel *chan, void *vdata) { int usecache; int res=0; struct localuser *u; struct sockaddr_in serv_addr; struct hostent *serverhost; struct ast_hostent ahp; int fd; FILE *fs; char *host; char *cachedir; char *temp; char *festivalcommand; int port=1314; int n; char ack[4]; char *waveform; int filesize; int wave; char bigstring[MAXFESTLEN]; int i; struct MD5Context md5ctx; unsigned char MD5Res[16]; char MD5Hex[33] = ""; char koko[4] = ""; char cachefile[MAXFESTLEN]=""; int readcache=0; int writecache=0; int strln; int fdesc = -1; char buffer[16384]; int seekpos = 0; char *data; char *intstr; struct ast_config *cfg; char *newfestivalcommand; if (ast_strlen_zero(vdata)) { ast_log(LOG_WARNING, "festival requires an argument (text)\n"); return -1; } LOCAL_USER_ADD(u); cfg = ast_config_load(FESTIVAL_CONFIG); if (!cfg) { ast_log(LOG_WARNING, "No such configuration file %s\n", FESTIVAL_CONFIG); LOCAL_USER_REMOVE(u); return -1; } if (!(host = ast_variable_retrieve(cfg, "general", "host"))) { host = "localhost"; } if (!(temp = ast_variable_retrieve(cfg, "general", "port"))) { port = 1314; } else { port = atoi(temp); } if (!(temp = ast_variable_retrieve(cfg, "general", "usecache"))) { usecache=0; } else { usecache = ast_true(temp); } if (!(cachedir = ast_variable_retrieve(cfg, "general", "cachedir"))) { cachedir = "/tmp/"; } if (!(festivalcommand = ast_variable_retrieve(cfg, "general", "festivalcommand"))) { festivalcommand = "(tts_textasterisk \"%s\" 'file)(quit)\n"; } else { /* This else parses the festivalcommand that we're sent from the config file for \n's, etc */ int i, j; newfestivalcommand = alloca(strlen(festivalcommand) + 1); for (i = 0, j = 0; i < strlen(festivalcommand); i++) { if (festivalcommand[i] == '\\' && festivalcommand[i + 1] == 'n') { newfestivalcommand[j++] = '\n'; i++; } else if (festivalcommand[i] == '\\') { newfestivalcommand[j++] = festivalcommand[i + 1]; i++; } else newfestivalcommand[j++] = festivalcommand[i]; } newfestivalcommand[j] = '\0'; festivalcommand = newfestivalcommand; } data = ast_strdupa(vdata); intstr = strchr(data, '|'); if (intstr) { *intstr = '\0'; intstr++; if (!strcasecmp(intstr, "any")) intstr = AST_DIGIT_ANY; } ast_log(LOG_DEBUG, "Text passed to festival server : %s\n",(char *)data); /* Connect to local festival server */ fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd < 0) { ast_log(LOG_WARNING,"festival_client: can't get socket\n"); ast_config_destroy(cfg); LOCAL_USER_REMOVE(u); return -1; } memset(&serv_addr, 0, sizeof(serv_addr)); if ((serv_addr.sin_addr.s_addr = inet_addr(host)) == -1) { /* its a name rather than an ipnum */ serverhost = ast_gethostbyname(host, &ahp); if (serverhost == (struct hostent *)0) { ast_log(LOG_WARNING,"festival_client: gethostbyname failed\n"); ast_config_destroy(cfg); LOCAL_USER_REMOVE(u); return -1; } memmove(&serv_addr.sin_addr,serverhost->h_addr, serverhost->h_length); } serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(port); if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != 0) { ast_log(LOG_WARNING,"festival_client: connect to server failed\n"); ast_config_destroy(cfg); LOCAL_USER_REMOVE(u); return -1; } /* Compute MD5 sum of string */ MD5Init(&md5ctx); MD5Update(&md5ctx,(unsigned char const *)data,strlen(data)); MD5Final(MD5Res,&md5ctx); MD5Hex[0] = '\0'; /* Convert to HEX and look if there is any matching file in the cache directory */ for (i=0; i<16; i++) { snprintf(koko, sizeof(koko), "%X",MD5Res[i]); strncat(MD5Hex, koko, sizeof(MD5Hex) - strlen(MD5Hex) - 1); } readcache=0; writecache=0; if (strlen(cachedir)+strlen(MD5Hex)+1<=MAXFESTLEN && (usecache==-1)) { snprintf(cachefile, sizeof(cachefile), "%s/%s", cachedir, MD5Hex); fdesc=open(cachefile,O_RDWR); if (fdesc==-1) { fdesc=open(cachefile,O_CREAT|O_RDWR,0777); if (fdesc!=-1) { writecache=1; strln=strlen((char *)data); ast_log(LOG_DEBUG,"line length : %d\n",strln); write(fdesc,&strln,sizeof(int)); write(fdesc,data,strln); seekpos=lseek(fdesc,0,SEEK_CUR); ast_log(LOG_DEBUG,"Seek position : %d\n",seekpos); } } else { read(fdesc,&strln,sizeof(int)); ast_log(LOG_DEBUG,"Cache file exists, strln=%d, strlen=%d\n",strln,(int)strlen((char *)data)); if (strlen((char *)data)==strln) { ast_log(LOG_DEBUG,"Size OK\n"); read(fdesc,&bigstring,strln); bigstring[strln] = 0; if (strcmp(bigstring,data)==0) { readcache=1; } else { ast_log(LOG_WARNING,"Strings do not match\n"); } } else { ast_log(LOG_WARNING,"Size mismatch\n"); } } } if (readcache==1) { close(fd); fd=fdesc; ast_log(LOG_DEBUG,"Reading from cache...\n"); } else { ast_log(LOG_DEBUG,"Passing text to festival...\n"); fs=fdopen(dup(fd),"wb"); fprintf(fs,festivalcommand,(char *)data); fflush(fs); fclose(fs); } /* Write to cache and then pass it down */ if (writecache==1) { ast_log(LOG_DEBUG,"Writing result to cache...\n"); while ((strln=read(fd,buffer,16384))!=0) { write(fdesc,buffer,strln); } close(fd); close(fdesc); fd=open(cachefile,O_RDWR); lseek(fd,seekpos,SEEK_SET); } ast_log(LOG_DEBUG,"Passing data to channel...\n"); /* Read back info from server */ /* This assumes only one waveform will come back, also LP is unlikely */ wave = 0; do { int read_data; for (n=0; n < 3; ) { read_data = read(fd,ack+n,3-n); /* this avoids falling in infinite loop * in case that festival server goes down * */ if ( read_data == -1 ) { ast_log(LOG_WARNING,"Unable to read from cache/festival fd"); close(fd); ast_config_destroy(cfg); LOCAL_USER_REMOVE(u); return -1; } n += read_data; } ack[3] = '\0'; if (strcmp(ack,"WV\n") == 0) { /* receive a waveform */ ast_log(LOG_DEBUG,"Festival WV command\n"); waveform = socket_receive_file_to_buff(fd,&filesize); res = send_waveform_to_channel(chan,waveform,filesize, intstr); free(waveform); break; } else if (strcmp(ack,"LP\n") == 0) { /* receive an s-expr */ ast_log(LOG_DEBUG,"Festival LP command\n"); waveform = socket_receive_file_to_buff(fd,&filesize); waveform[filesize]='\0'; ast_log(LOG_WARNING,"Festival returned LP : %s\n",waveform); free(waveform); } else if (strcmp(ack,"ER\n") == 0) { /* server got an error */ ast_log(LOG_WARNING,"Festival returned ER\n"); res=-1; break; } } while (strcmp(ack,"OK\n") != 0); close(fd); ast_config_destroy(cfg); LOCAL_USER_REMOVE(u); return res; }
static int odbc_load_module(int reload) { int res = 0; struct ast_config *cfg; struct ast_variable *var; const char *tmp; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; do { cfg = ast_config_load(config_file, config_flags); if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_WARNING, "cdr_odbc: Unable to load config for ODBC CDR's: %s\n", config_file); res = AST_MODULE_LOAD_DECLINE; break; } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) break; var = ast_variable_browse(cfg, "global"); if (!var) { /* nothing configured */ break; } if ((tmp = ast_variable_retrieve(cfg, "global", "dsn")) == NULL) { ast_log(LOG_WARNING, "cdr_odbc: dsn not specified. Assuming asteriskdb\n"); tmp = "asteriskdb"; } if (dsn) ast_free(dsn); dsn = ast_strdup(tmp); if (dsn == NULL) { res = -1; break; } if (((tmp = ast_variable_retrieve(cfg, "global", "dispositionstring"))) && ast_true(tmp)) ast_set_flag(&config, CONFIG_DISPOSITIONSTRING); else ast_clear_flag(&config, CONFIG_DISPOSITIONSTRING); if (((tmp = ast_variable_retrieve(cfg, "global", "loguniqueid"))) && ast_true(tmp)) { ast_set_flag(&config, CONFIG_LOGUNIQUEID); ast_debug(1, "cdr_odbc: Logging uniqueid\n"); } else { ast_clear_flag(&config, CONFIG_LOGUNIQUEID); ast_debug(1, "cdr_odbc: Not logging uniqueid\n"); } if (((tmp = ast_variable_retrieve(cfg, "global", "usegmtime"))) && ast_true(tmp)) { ast_set_flag(&config, CONFIG_USEGMTIME); ast_debug(1, "cdr_odbc: Logging in GMT\n"); } else { ast_clear_flag(&config, CONFIG_USEGMTIME); ast_debug(1, "cdr_odbc: Logging in local time\n"); } if (((tmp = ast_variable_retrieve(cfg, "global", "hrtime"))) && ast_true(tmp)) { ast_set_flag(&config, CONFIG_HRTIME); ast_debug(1, "cdr_odbc: Logging billsec and duration fields as floats\n"); } else { ast_clear_flag(&config, CONFIG_HRTIME); ast_debug(1, "cdr_odbc: Logging billsec and duration fields as integers\n"); } if ((tmp = ast_variable_retrieve(cfg, "global", "table")) == NULL) { ast_log(LOG_WARNING, "cdr_odbc: table not specified. Assuming cdr\n"); tmp = "cdr"; } if (table) ast_free(table); table = ast_strdup(tmp); if (table == NULL) { res = -1; break; } ast_verb(3, "cdr_odbc: dsn is %s\n", dsn); ast_verb(3, "cdr_odbc: table is %s\n", table); if (!ast_test_flag(&config, CONFIG_REGISTERED)) { res = ast_cdr_register(name, ast_module_info->description, odbc_log); if (res) { ast_log(LOG_ERROR, "cdr_odbc: Unable to register ODBC CDR handling\n"); } else { ast_set_flag(&config, CONFIG_REGISTERED); } } } while (0); if (ast_test_flag(&config, CONFIG_REGISTERED) && (!cfg || dsn == NULL || table == NULL)) { ast_cdr_unregister(name); ast_clear_flag(&config, CONFIG_REGISTERED); } if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID) { ast_config_destroy(cfg); } return res; }
/*! * \brief Load the configuration from the configuration file * * \param reload True on reload * * \retval 1 success * \retval 0 failure */ static int load_config(int reload) { struct ast_config *cfg; const char *value; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; /* Read in the config file */ cfg = ast_config_load(ALMRCV_CONFIG, config_flags); if (!cfg) { ast_verb(4, "AlarmReceiver: No config file\n"); return 0; } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) { return 1; } else if (cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_ERROR, "Config file %s is in an invalid format. Aborting.\n", ALMRCV_CONFIG); return 0; } if ((value = ast_variable_retrieve(cfg, "general", "eventcmd")) != NULL) { ast_copy_string(event_app, value, sizeof(event_app)); } if ((value = ast_variable_retrieve(cfg, "general", "loudness")) != NULL) { toneloudness = atoi(value); if (toneloudness < 100) { toneloudness = 100; } else if (toneloudness > 8192) { toneloudness = 8192; } } if ((value = ast_variable_retrieve(cfg, "general", "fdtimeout")) != NULL) { fdtimeout = atoi(value); if (fdtimeout < 1000) { fdtimeout = 1000; } else if (fdtimeout > 10000) { fdtimeout = 10000; } } if ((value = ast_variable_retrieve(cfg, "general", "sdtimeout")) != NULL) { sdtimeout = atoi(value); if (sdtimeout < 110) { sdtimeout = 110; } else if (sdtimeout > 4000) { sdtimeout = 4000; } } if ((value = ast_variable_retrieve(cfg, "general", "answait")) != NULL) { answait = atoi(value); if (answait < 500) { answait = 500; } else if (answait > 10000) { answait = 10000; } } if ((value = ast_variable_retrieve(cfg, "general", "no_group_meta")) != NULL) { no_group_meta = ast_true(value); } if ((value = ast_variable_retrieve(cfg, "general", "logindividualevents")) != NULL) { log_individual_events = ast_true(value); } if ((value = ast_variable_retrieve(cfg, "general", "eventspooldir")) != NULL) { ast_copy_string(event_spool_dir, value, sizeof(event_spool_dir)); } if ((value = ast_variable_retrieve(cfg, "general", "timestampformat")) != NULL) { ast_copy_string(time_stamp_format, value, sizeof(time_stamp_format)); } if ((value = ast_variable_retrieve(cfg, "general", "db-family")) != NULL) { ast_copy_string(db_family, value, sizeof(db_family)); } ast_config_destroy(cfg); return 1; }
/* Configuration file */ static int load_config(void) { struct ast_config *cfg; struct ast_variable *var; char *tmp; int level, reverse; cfg = (void *)ast_config_load(config); if (!cfg) { ast_log(LOG_WARNING, "Unable to load config for h324m : %s\n", config); return -1; } var = (void *)ast_variable_browse(cfg, "general"); if (!var) { ast_log(LOG_WARNING, "Nothing configured for h324m.\n"); /* nothing configured */ return 0; } tmp = (void *)ast_variable_retrieve(cfg, "general", "debug"); if (tmp) { if (sscanf(tmp, "%d", &level) < 0) { ast_log(LOG_WARNING, "Invalid debug.\n"); level = 1; } if((level < 0) || (level > 9)) { ast_log(LOG_WARNING, "Invalid debug (>max).\n"); level = 1; level = 1; } else { H324MLoggerSetLevel(level); } } else { level = 1; } tmp = (void *)ast_variable_retrieve(cfg, "general", "boardcodec"); if ((tmp) && (strlen(tmp) < 9)) { if (!strcmp(tmp, "alaw")) strcpy(boardcodec, tmp); else if (!strcmp(tmp, "ulaw")) strcpy(boardcodec, tmp); else if (!strcmp(tmp, "both")) strcpy(boardcodec, tmp); else { if (level > 0) ast_verbose(VERBOSE_PREFIX_3 "Bad board law, set to %s.\n", DEFAULT_BOARDCODEC); strcpy(boardcodec, DEFAULT_BOARDCODEC); } } else { strcpy(boardcodec, DEFAULT_BOARDCODEC); } tmp = (void *)ast_variable_retrieve(cfg, "h245", "reversebits"); if (tmp) { if (sscanf(tmp, "%d", &reverse) >=1 ) { ast_verbose(VERBOSE_PREFIX_3 "H245 reverse bits : %s\n", (reverse == 0)?"no":"yes"); H324MSetReverseBits(reverse); } else { ast_log(LOG_WARNING, "Invalid reverse bit flag %s. Bits will be reversed.\n", tmp); } } ast_config_destroy(cfg); if (level > 0) { ast_verbose(VERBOSE_PREFIX_3 "Debug level : %d\n", level); ast_verbose(VERBOSE_PREFIX_3 "Board codec : %s\n", boardcodec); } return 0; }