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 __ast_http_post_load(int reload) { struct ast_config *cfg; struct ast_variable *v; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; cfg = ast_config_load2("http.conf", "http", config_flags); if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) { return 0; } if (reload) { ast_http_uri_unlink_all_with_key(__FILE__); } if (cfg) { for (v = ast_variable_browse(cfg, "general"); v; v = v->next) { if (!strcasecmp(v->name, "prefix")) { ast_copy_string(prefix, v->value, sizeof(prefix)); if (prefix[strlen(prefix)] == '/') { prefix[strlen(prefix)] = '\0'; } } } for (v = ast_variable_browse(cfg, "post_mappings"); v; v = v->next) { struct ast_http_uri *urih; struct ast_str *ds; if (!(urih = ast_calloc(sizeof(*urih), 1))) { ast_config_destroy(cfg); return -1; } if (!(ds = ast_str_create(32))) { ast_free(urih); ast_config_destroy(cfg); return -1; } urih->description = ast_strdup("HTTP POST mapping"); urih->uri = ast_strdup(v->name); ast_str_set(&ds, 0, "%s", v->value); urih->data = ds; urih->has_subtree = 0; urih->supports_get = 0; urih->supports_post = 1; urih->callback = http_post_callback; urih->key = __FILE__; urih->mallocd = urih->dmallocd = 1; ast_http_uri_link(urih); } ast_config_destroy(cfg); } return 0; }
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; }
static void adsi_load(void) { int x; struct ast_config *conf; struct ast_variable *v; char *name, *sname; init_state(); conf = ast_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_destroy(conf); } }
/* 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 void loadconfigurationfile(void) { char *cat; struct ast_config *cfg; struct ast_variable *v; cfg = ast_load(CONF_FILE); if (!cfg) { /* Standard configuration */ enablecdr = 0; return; } 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_destroy(cfg); }
/*! * \brief Tests that the contents of an ast_config is what is expected * * \param cfg Config to test * \retval -1 Failed to pass a test * \retval 0 Config passes checks */ static int test_config_validity(struct ast_config *cfg) { int i; const char *cat_iter = NULL; /* Okay, let's see if the correct content is there */ for (i = 0; i < ARRAY_LEN(categories); ++i) { struct ast_variable *var = NULL; size_t j; cat_iter = ast_category_browse(cfg, cat_iter); if (strcmp(cat_iter, categories[i].category)) { ast_log(LOG_ERROR, "Category name mismatch, %s does not match %s\n", cat_iter, categories[i].category); return -1; } for (j = 0; j < ARRAY_LEN(categories[i].vars); ++j) { var = var ? var->next : ast_variable_browse(cfg, cat_iter); if (strcmp(var->name, categories[i].vars[j].name)) { ast_log(LOG_ERROR, "Variable name mismatch, %s does not match %s\n", var->name, categories[i].vars[j].name); return -1; } if (strcmp(var->value, categories[i].vars[j].val)) { ast_log(LOG_ERROR, "Variable value mismatch, %s does not match %s\n", var->value, categories[i].vars[j].val); return -1; } } } 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; }
/** \brief Load grammars from config */ static apr_table_t* uni_engine_grammars_load(struct ast_config *cfg, const char *category, apr_pool_t *pool) { struct ast_variable *var; apr_table_t *grammars = apr_table_make(pool,0); for(var = ast_variable_browse(cfg, category); var; var = var->next) { ast_log(LOG_DEBUG, "%s.%s=%s\n", category, var->name, var->value); apr_table_set(grammars,var->name,var->value); } return grammars; }
/** \brief Load properties from config */ static mrcp_message_header_t* uni_engine_properties_load(struct ast_config *cfg, const char *category, mrcp_version_e version, apr_pool_t *pool) { struct ast_variable *var; mrcp_message_header_t *properties = NULL; #if defined(TRANSPARENT_HEADER_FIELDS_SUPPORT) apt_header_field_t *header_field; properties = mrcp_message_header_create( mrcp_generic_header_vtable_get(version), mrcp_recog_header_vtable_get(version), pool); for(var = ast_variable_browse(cfg, category); var; var = var->next) { ast_log(LOG_DEBUG, "%s.%s=%s\n", category, var->name, var->value); header_field = apt_header_field_create_c(var->name,var->value,pool); if(header_field) { if(mrcp_header_field_add(properties,header_field,pool) == FALSE) { ast_log(LOG_WARNING, "Unknown MRCP header %s.%s=%s\n", category, var->name, var->value); } } } #else apt_pair_t pair; properties = apr_palloc(pool,sizeof(mrcp_message_header_t)); mrcp_message_header_init(properties); properties->generic_header_accessor.vtable = mrcp_generic_header_vtable_get(version); properties->resource_header_accessor.vtable = mrcp_recog_header_vtable_get(version); mrcp_header_allocate(&properties->generic_header_accessor,pool); mrcp_header_allocate(&properties->resource_header_accessor,pool); for(var = ast_variable_browse(cfg, category); var; var = var->next) { ast_log(LOG_DEBUG, "%s.%s=%s\n", category, var->name, var->value); apt_string_set(&pair.name,var->name); apt_string_set(&pair.value,var->value); if(mrcp_header_parse(&properties->resource_header_accessor,&pair,pool) != TRUE) { if(mrcp_header_parse(&properties->generic_header_accessor,&pair,pool) != TRUE) { ast_log(LOG_WARNING, "Unknown MRCP header %s.%s=%s\n", category, var->name, var->value); } } } #endif return properties; }
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; }
/*! * \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 load_config(int startup) { struct ast_flags config_flags = { 0, }; struct ast_config *cfg; struct ast_variable *v; if (!startup) { ast_set_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED); } cfg = ast_config_load2(stun_conf_file, "res_stun_monitor", config_flags); if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_WARNING, "Unable to load config %s\n", stun_conf_file); return -1; } if (cfg == CONFIG_STATUS_FILEUNCHANGED) { return 0; } /* clean up any previous open socket */ stun_close_sock(); args.stun_poll_failed_gripe = 0; /* set defaults */ args.monitor_enabled = 0; args.refresh = DEFAULT_MONITOR_REFRESH; for (v = ast_variable_browse(cfg, "general"); v; v = v->next) { if (!strcasecmp(v->name, "stunaddr")) { if (setup_stunaddr(v->value)) { ast_log(LOG_WARNING, "Invalid STUN server address: %s at line %d\n", v->value, v->lineno); } } else if (!strcasecmp(v->name, "stunrefresh")) { if ((sscanf(v->value, "%30u", &args.refresh) != 1) || !args.refresh) { ast_log(LOG_WARNING, "Invalid stunrefresh value '%s', must be an integer > 0 at line %d\n", v->value, v->lineno); args.refresh = DEFAULT_MONITOR_REFRESH; } } else { ast_log(LOG_WARNING, "Invalid config option %s at line %d\n", v->value, v->lineno); } } ast_config_destroy(cfg); return 0; }
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 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_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; }
/*--- 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; }
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; }
static int parse_config_general(struct ast_config *cfg, struct conf_infos *conf_info) { struct ast_variable *var = NULL; for (var = ast_variable_browse(cfg, "general"); var != NULL; var = var->next) { if (!strcasecmp(var->name, "hlr_db")) { ast_copy_string(conf_info->hlr_db_path, var->value, sizeof(conf_info->hlr_db_path)); continue; } else if (!strcasecmp(var->name, "openbsc_cfg")) { ast_copy_string(conf_info->openbsc_cfg_path, var->value, sizeof(conf_info->openbsc_cfg_path)); continue; } else if (!strcasecmp(var->name, "log")) { ast_copy_string(conf_info->log_path, var->value, sizeof(conf_info->log_path)); } else if (!strcasecmp(var->name, "context")) { ast_copy_string(conf_info->context, var->value, sizeof(conf_info->context)); } } return 0; }
/*! \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; }
/*! \brief * the string is 'prefix:data' or prefix:fmt:data' * with ':' being invalid in strings. */ static int do_say(say_args_t *a, const char *s, const char *options, int depth) { struct ast_variable *v; char *lang, *x, *rule = NULL; int ret = 0; struct varshead head = { .first = NULL, .last = NULL }; struct ast_var_t *n; ast_debug(2, "string <%s> depth <%d>\n", s, depth); if (depth++ > 10) { ast_log(LOG_WARNING, "recursion too deep, exiting\n"); return -1; } else if (!say_cfg) { ast_log(LOG_WARNING, "no say.conf, cannot spell '%s'\n", s); return -1; } /* scan languages same as in file.c */ if (a->language == NULL) a->language = "en"; /* default */ ast_debug(2, "try <%s> in <%s>\n", s, a->language); lang = ast_strdupa(a->language); for (;;) { for (v = ast_variable_browse(say_cfg, lang); v ; v = v->next) { if (ast_extension_match(v->name, s)) { rule = ast_strdupa(v->value); break; } } if (rule) break; if ( (x = strchr(lang, '_')) ) *x = '\0'; /* try without suffix */ else if (strcmp(lang, "en")) lang = "en"; /* last resort, try 'en' if not done yet */ else break; } if (!rule) return 0; /* skip up to two prefixes to get the value */ if ( (x = strchr(s, ':')) ) s = x + 1; if ( (x = strchr(s, ':')) ) s = x + 1; ast_debug(2, "value is <%s>\n", s); n = ast_var_assign("SAY", s); if (!n) { ast_log(LOG_ERROR, "Memory allocation error in do_say\n"); return -1; } AST_LIST_INSERT_HEAD(&head, n, entries); /* scan the body, one piece at a time */ while ( !ret && (x = strsep(&rule, ",")) ) { /* exit on key */ char fn[128]; const char *p, *fmt, *data; /* format and data pointers */ /* prepare a decent file name */ x = ast_skip_blanks(x); ast_trim_blanks(x); /* replace variables */ pbx_substitute_variables_varshead(&head, x, fn, sizeof(fn)); ast_debug(2, "doing [%s]\n", fn); /* locate prefix and data, if any */ fmt = strchr(fn, ':'); if (!fmt || fmt == fn) { /* regular filename */ ret = s_streamwait3(a, fn); continue; } fmt++; data = strchr(fmt, ':'); /* colon before data */ if (!data || data == fmt) { /* simple prefix-fmt */ ret = do_say(a, fn, options, depth); continue; } /* prefix:fmt:data */ for (p = fmt; p < data && ret <= 0; p++) { char fn2[sizeof(fn)]; if (*p == ' ' || *p == '\t') /* skip blanks */ continue; if (*p == '\'') {/* file name - we trim them */ char *y; strcpy(fn2, ast_skip_blanks(p+1)); /* make a full copy */ y = strchr(fn2, '\''); if (!y) { p = data; /* invalid. prepare to end */ break; } *y = '\0'; ast_trim_blanks(fn2); p = strchr(p+1, '\''); ret = s_streamwait3(a, fn2); } else { int l = fmt-fn; strcpy(fn2, fn); /* copy everything */ /* after prefix, append the format */ fn2[l++] = *p; strcpy(fn2 + l, data); ret = do_say(a, fn2, options, depth); } if (ret) { break; } } } ast_var_delete(n); return ret; }
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; }
static struct ast_config *config_sqlite(const char *database, const char *table, const char *file, struct ast_config *cfg) { struct ast_variable *new_v, *v; struct ast_category *cur_cat; char ttable[ARRAY_SIZE]; int configured = 0, res = 0; sqlite3_stmt *stmt = NULL;; int cat_metric=0, last_cat_metric=0; char sql[ARRAY_SIZE]; char last[ARRAY_SIZE] = ""; char path[ARRAY_SIZE]; sqlite3 *db; int running=0; int i=0; struct ast_config *config; /* if the data was not passed from extconfig.conf then get it from sqlite.conf */ if(!database || ast_strlen_zero(database)) { if (!file || !strcmp (file, "res_sqlite.conf")) return NULL; // cant configure myself with myself ! config = ast_config_load ("res_sqlite.conf"); if (config) { for (v = ast_variable_browse (config, "config"); v; v = v->next) { if (!strcmp (v->name, "table")) { strncpy (ttable, v->value, sizeof (ttable)); configured++; } else if (!strcmp (v->name, "dbfile")) { pick_path(v->value,path,ARRAY_SIZE); configured++; } } ast_config_destroy (config); } } else { pick_path((char *)database,path,ARRAY_SIZE); strncpy (ttable, table, sizeof (ttable)); configured = 2; } if (configured < 2) return NULL; db=open_db(path); if (!db) return NULL; sprintf (sql, "select * from %s where filename='%s' and commented=0 order by filename,cat_metric desc,var_metric asc,id", ttable, file); res = sqlite3_prepare(db,sql,0,&stmt,0); if (res) { ast_log (LOG_WARNING, "SQL select error [%s]!\n[%s]\n\n",sqlite3_errmsg(db), sql); return NULL; } cur_cat = ast_config_get_current_category(cfg); /* 0 id int 1 cat_metric int not null default 0, 2 var_metric int not null default 0, 3 commented int not null default 0, 4 filename varchar(128) not null, 5 category varchar(128) not null default 'default', 6 var_name varchar(128) not null, 7 var_val varchar(128) not null */ running = 1; while (running) { res = sqlite3_step(stmt); running = 1; switch( res ){ case SQLITE_DONE: running = 0 ; break; case SQLITE_BUSY: sleep(2); running = 2; break ; case SQLITE_ERROR: running = 0; break; case SQLITE_MISUSE: running = 0; break; case SQLITE_ROW: default: break; } if (!running) break; if (running == 2) continue; if(option_verbose > 4) for(i=0;i<8;i++){ ast_verbose(VERBOSE_PREFIX_3"SQLite Config: %d=%s\n",i,sqlite3_column_text(stmt,i)); } if (strcmp (last, sqlite3_column_text(stmt,5)) || last_cat_metric != cat_metric) { cur_cat = ast_category_new((char *)sqlite3_column_text(stmt,5)); if (!cur_cat) { ast_log(LOG_WARNING, "Out of memory!\n"); break; } strcpy (last, sqlite3_column_text(stmt,5)); last_cat_metric = cat_metric; ast_category_append(cfg, cur_cat); } new_v = ast_variable_new ((char *)sqlite3_column_text(stmt,6), (char *)sqlite3_column_text(stmt,7)); ast_variable_append(cur_cat, new_v); } if ((sqlite3_finalize(stmt))) ast_log(LOG_ERROR,"ERROR: %s\n",sqlite3_errmsg(db)); return cfg; }
static int load_config(int hard) { struct ast_config *config; struct ast_variable *v; char *sql; config = ast_config_load ("res_sqlite.conf"); if (config) { for (v = ast_variable_browse (config, "general"); v; v = v->next) { if (!strcmp (v->name, "reload")) { do_reload = ast_true(v->value); } } if (!hard) if (!do_reload) { ast_verbose(VERBOSE_PREFIX_2 "RES SQLite Skipping Reload set reload => yes in [general]\n"); return 0; } ast_verbose(VERBOSE_PREFIX_2 "RES SQLite Loading Defaults\n"); has_cdr=-1; has_switch=-1; has_config=-1; has_cli=0; for (v = ast_variable_browse (config, "cdr"); v; v = v->next) { if (!strcmp (v->name, "table")) { strncpy (cdr_table, v->value, sizeof (cdr_table)); has_cdr++; } else if (!strcmp (v->name, "dbfile")) { pick_path(v->value,cdr_dbfile,ARRAY_SIZE); has_cdr++; } } for (v = ast_variable_browse (config, "config"); v; v = v->next) { if (!strcmp (v->name, "table")) { strncpy (config_table, v->value, sizeof (cdr_table)); has_config++; } else if (!strcmp (v->name, "dbfile")) { pick_path(v->value,config_dbfile,ARRAY_SIZE); has_config++; } } for (v = ast_variable_browse (config, "switch"); v; v = v->next) { if (!strcmp (v->name, "table")) { strncpy (switch_table, v->value, sizeof (cdr_table)); has_switch++; } else if (!strcmp (v->name, "dbfile")) { pick_path(v->value,switch_dbfile,ARRAY_SIZE); has_switch++; } } for (v = ast_variable_browse (config, "cli"); v; v = v->next) { if (!strcmp (v->name, "dbfile")) { pick_path(v->value,clidb,ARRAY_SIZE); has_cli++; } } ast_config_destroy (config); } if(has_cdr > 0) { if((sql = sqlite3_mprintf("select count(*) from %q limit 1",cdr_table))) { check_table_exists(cdr_dbfile,sql,create_cdr_sql); sqlite3_free(sql); sql = NULL; } } if(has_config > 0) { if((sql = sqlite3_mprintf("select count(*) from %q limit 1",config_table))) { check_table_exists(config_dbfile,sql,create_config_sql); sqlite3_free(sql); sql = NULL; } } if(has_switch > 0) { if((sql = sqlite3_mprintf("select count(*) from %q limit 1",switch_table))) { check_table_exists(switch_dbfile,sql,create_dialplan_sql); sqlite3_free(sql); sql = NULL; } } return 0; }
/*--- conf_exec: The meetme() application */ static int conf_exec(struct ast_channel *chan, void *data) { int res=-1; struct localuser *u; char confno[AST_MAX_EXTENSION] = ""; int allowretry = 0; int retrycnt = 0; struct ast_conference *cnf; int confflags = 0; int dynamic = 0; int empty = 0, empty_no_pin = 0; char *notdata, *info, *inflags = NULL, *inpin = NULL, the_pin[AST_MAX_EXTENSION] = ""; if (!data || ast_strlen_zero(data)) { allowretry = 1; notdata = ""; } else { notdata = data; } LOCAL_USER_ADD(u); if (chan->_state != AST_STATE_UP) ast_answer(chan); info = ast_strdupa((char *)notdata); if (info) { char *tmp = strsep(&info, "|"); strncpy(confno, tmp, sizeof(confno) - 1); if (ast_strlen_zero(confno)) { allowretry = 1; } } if (info) inflags = strsep(&info, "|"); if (info) inpin = strsep(&info, "|"); if (inpin) strncpy(the_pin, inpin, sizeof(the_pin) - 1); if (inflags) { if (strchr(inflags, 'a')) confflags |= CONFFLAG_ADMIN; if (strchr(inflags, 'm')) confflags |= CONFFLAG_MONITOR; if (strchr(inflags, 'p')) confflags |= CONFFLAG_POUNDEXIT; if (strchr(inflags, 's')) confflags |= CONFFLAG_STARMENU; if (strchr(inflags, 't')) confflags |= CONFFLAG_TALKER; if (strchr(inflags, 'q')) confflags |= CONFFLAG_QUIET; if (strchr(inflags, 'M')) confflags |= CONFFLAG_MOH; if (strchr(inflags, 'x')) confflags |= CONFFLAG_MARKEDEXIT; if (strchr(inflags, 'X')) confflags |= CONFFLAG_EXIT_CONTEXT; if (strchr(inflags, 'A')) confflags |= CONFFLAG_MARKEDUSER; if (strchr(inflags, 'b')) confflags |= CONFFLAG_AGI; if (strchr(inflags, 'w')) confflags |= CONFFLAG_WAITMARKED; if (strchr(inflags, 'd')) dynamic = 1; if (strchr(inflags, 'D')) { dynamic = 1; if (! inpin) { strncpy(the_pin, "q", sizeof(the_pin) - 1); } } if (strchr(inflags, 'e')) empty = 1; if (strchr(inflags, 'E')) { empty = 1; empty_no_pin = 1; } } do { if (retrycnt > 3) allowretry = 0; if (empty) { int i, map[1024]; struct ast_config *cfg; struct ast_variable *var; int confno_int; memset(map, 0, sizeof(map)); ast_mutex_lock(&conflock); cnf = confs; while (cnf) { if (sscanf(cnf->confno, "%d", &confno_int) == 1) { /* Disqualify in use conference */ if (confno_int >= 0 && confno_int < 1024) map[confno_int]++; } cnf = cnf->next; } ast_mutex_unlock(&conflock); /* We only need to load the config file for static and empty_no_pin (otherwise we don't care) */ if ((empty_no_pin) || (!dynamic)) { cfg = ast_load("meetme.conf"); if (cfg) { var = ast_variable_browse(cfg, "rooms"); while(var) { if (!strcasecmp(var->name, "conf")) { char *stringp = ast_strdupa(var->value); if (stringp) { char *confno_tmp = strsep(&stringp, "|,"); int found = 0; if (sscanf(confno_tmp, "%d", &confno_int) == 1) { if ((confno_int >= 0) && (confno_int < 1024)) { if (stringp && empty_no_pin) { map[confno_int]++; } } } if (! dynamic) { /* For static: run through the list and see if this conference is empty */ ast_mutex_lock(&conflock); cnf = confs; while (cnf) { if (!strcmp(confno_tmp, cnf->confno)) { /* The conference exists, therefore it's not empty */ found = 1; break; } cnf = cnf->next; } ast_mutex_unlock(&conflock); if (!found) { /* At this point, we have a confno_tmp (static conference) that is empty */ if ((empty_no_pin && ((!stringp) || (stringp && (stringp[0] == '\0')))) || (!empty_no_pin)) { /* Case 1: empty_no_pin and pin is nonexistant (NULL) * Case 2: empty_no_pin and pin is blank (but not NULL) * Case 3: not empty_no_pin */ strncpy(confno, confno_tmp, sizeof(confno) - 1); break; /* XXX the map is not complete (but we do have a confno) */ } } } } else { ast_log(LOG_ERROR, "Out of memory\n"); } } var = var->next; } ast_destroy(cfg); } } /* Select first conference number not in use */ if (ast_strlen_zero(confno) && dynamic) { for (i=0;i<1024;i++) { if (!map[i]) { snprintf(confno, sizeof(confno), "%d", i); break; } } } /* Not found? */ if (ast_strlen_zero(confno)) { res = ast_streamfile(chan, "conf-noempty", chan->language); if (!res) ast_waitstream(chan, ""); } else { if (sscanf(confno, "%d", &confno_int) == 1) { res = ast_streamfile(chan, "conf-enteringno", chan->language); if (!res) { ast_waitstream(chan, ""); res = ast_say_digits(chan, confno_int, "", chan->language); } } else { ast_log(LOG_ERROR, "Could not scan confno '%s'\n", confno); } } } while (allowretry && (ast_strlen_zero(confno)) && (++retrycnt < 4)) { /* Prompt user for conference number */ res = ast_app_getdata(chan, "conf-getconfno", confno, sizeof(confno) - 1, 0); if (res < 0) { /* Don't try to validate when we catch an error */ confno[0] = '\0'; allowretry = 0; break; } } if (!ast_strlen_zero(confno)) { /* Check the validity of the conference */ cnf = find_conf(chan, confno, 1, dynamic, the_pin); if (!cnf) { res = ast_streamfile(chan, "conf-invalid", chan->language); if (!res) ast_waitstream(chan, ""); res = -1; if (allowretry) confno[0] = '\0'; } else { if (!ast_strlen_zero(cnf->pin)) { char pin[AST_MAX_EXTENSION]=""; int j; /* Allow the pin to be retried up to 3 times */ for (j=0; j<3; j++) { if (*the_pin) { strncpy(pin, the_pin, sizeof(pin) - 1); res = 0; } else { /* Prompt user for pin if pin is required */ res = ast_app_getdata(chan, "conf-getpin", pin + strlen(pin), sizeof(pin) - 1 - strlen(pin), 0); } if (res >= 0) { if (!strcasecmp(pin, cnf->pin)) { /* Pin correct */ allowretry = 0; /* Run the conference */ res = conf_run(chan, cnf, confflags); break; } else { /* Pin invalid */ res = ast_streamfile(chan, "conf-invalidpin", chan->language); if (!res) ast_waitstream(chan, AST_DIGIT_ANY); if (res < 0) break; pin[0] = res; pin[1] = '\0'; res = -1; if (allowretry) confno[0] = '\0'; } } else { res = -1; allowretry = 0; break; } /* Don't retry pin with a static pin */ if (*the_pin) { break; } } } else { /* No pin required */ allowretry = 0; /* Run the conference */ res = conf_run(chan, cnf, confflags); } } } } while (allowretry); /* Do the conference */ LOCAL_USER_REMOVE(u); return res; }
static struct ast_conference *find_conf(struct ast_channel *chan, char *confno, int make, int dynamic, char *dynamic_pin) { struct ast_config *cfg; struct ast_variable *var; struct ast_conference *cnf; /* Check first in the conference list */ ast_mutex_lock(&conflock); cnf = confs; while (cnf) { if (!strcmp(confno, cnf->confno)) break; cnf = cnf->next; } ast_mutex_unlock(&conflock); if (!cnf) { if (dynamic) { /* No need to parse meetme.conf */ ast_log(LOG_DEBUG, "Building dynamic conference '%s'\n", confno); if (dynamic_pin) { if (dynamic_pin[0] == 'q') { /* Query the user to enter a PIN */ ast_app_getdata(chan, "conf-getpin", dynamic_pin, AST_MAX_EXTENSION - 1, 0); } cnf = build_conf(confno, dynamic_pin, make, dynamic); } else { cnf = build_conf(confno, "", make, dynamic); } } else { /* Check the config */ cfg = ast_load("meetme.conf"); if (!cfg) { ast_log(LOG_WARNING, "No meetme.conf file :(\n"); return NULL; } var = ast_variable_browse(cfg, "rooms"); while(var) { if (!strcasecmp(var->name, "conf")) { /* Separate the PIN */ char *pin, *conf; if ((pin = ast_strdupa(var->value))) { conf = strsep(&pin, "|,"); if (!strcasecmp(conf, confno)) { /* Bingo it's a valid conference */ if (pin) cnf = build_conf(confno, pin, make, dynamic); else cnf = build_conf(confno, "", make, dynamic); break; } } } var = var->next; } if (!var) { ast_log(LOG_DEBUG, "%s isn't a valid conference\n", confno); } ast_destroy(cfg); } } else if (dynamic_pin) { /* Correct for the user selecting 'D' instead of 'd' to have someone join into a conference that has already been created with a pin. */ if (dynamic_pin[0] == 'q') dynamic_pin[0] = '\0'; } return cnf; }