static int load_module(void) { struct ast_config *cfg; int res; const char *tmp; if ((cfg = ast_config_load(cdr_config))) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid")), RADIUS_FLAG_LOGUNIQUEID); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield")), RADIUS_FLAG_LOGUSERFIELD); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); ast_config_destroy(cfg); } else return AST_MODULE_LOAD_DECLINE; /* start logging */ rc_openlog("asterisk"); /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); return AST_MODULE_LOAD_DECLINE; } res = ast_cdr_register(name, desc, radius_log); return AST_MODULE_LOAD_SUCCESS; }
static int load_config(int reload) { const char *cat = NULL; struct ast_config *cfg; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; struct ast_variable *v; int newenablecel = CEL_AMI_ENABLED_DEFAULT; int new_cel_show_user_def = CEL_SHOW_USERDEF_DEFAULT; cfg = ast_config_load(CONF_FILE, config_flags); if (cfg == CONFIG_STATUS_FILEUNCHANGED) { return 0; } if (cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_WARNING, "Configuration file '%s' is invalid. CEL manager Module not activated.\n", CONF_FILE); enablecel = 0; return -1; } else if (!cfg) { ast_log(LOG_WARNING, "Failed to load configuration file. CEL manager Module not activated.\n"); enablecel = 0; return -1; } while ((cat = ast_category_browse(cfg, cat))) { if (strcasecmp(cat, "manager")) { continue; } for (v = ast_variable_browse(cfg, cat); v; v = v->next) { if (!strcasecmp(v->name, "enabled")) { newenablecel = ast_true(v->value) ? 1 : 0; } else if (!strcasecmp(v->name, "show_user_defined")) { new_cel_show_user_def = ast_true(v->value) ? 1 : 0; } else { ast_log(LOG_NOTICE, "Unknown option '%s' specified " "for cel_manager.\n", v->name); } } } ast_config_destroy(cfg); cel_show_user_def = new_cel_show_user_def; if (enablecel && !newenablecel) { if (event_sub) { event_sub = ast_event_unsubscribe(event_sub); } } else if (!enablecel && newenablecel) { event_sub = ast_event_subscribe(AST_EVENT_CEL, manager_log, "Manager Event Logging", NULL, AST_EVENT_IE_END); if (!event_sub) { ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CEL handling\n"); } } enablecel = newenablecel; return 0; }
static int __ast_http_load(int reload) { struct ast_config *cfg; struct ast_variable *v; int enabled=0; int newenablestatic=0; struct sockaddr_in sin; struct hostent *hp; struct ast_hostent ahp; char newprefix[MAX_PREFIX]; memset(&sin, 0, sizeof(sin)); sin.sin_port = 8088; strcpy(newprefix, DEFAULT_PREFIX); cfg = ast_config_load("http.conf"); if (cfg) { v = ast_variable_browse(cfg, "general"); while(v) { if (!strcasecmp(v->name, "enabled")) enabled = ast_true(v->value); else if (!strcasecmp(v->name, "enablestatic")) newenablestatic = ast_true(v->value); else if (!strcasecmp(v->name, "bindport")) sin.sin_port = ntohs(atoi(v->value)); else if (!strcasecmp(v->name, "bindaddr")) { if ((hp = ast_gethostbyname(v->value, &ahp))) { memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr)); } else { ast_log(LOG_WARNING, "Invalid bind address '%s'\n", v->value); } } else if (!strcasecmp(v->name, "prefix")) { if (!ast_strlen_zero(v->value)) { newprefix[0] = '/'; ast_copy_string(newprefix + 1, v->value, sizeof(newprefix) - 1); } else { newprefix[0] = '\0'; } } v = v->next; } ast_config_destroy(cfg); } if (enabled) sin.sin_family = AF_INET; if (strcmp(prefix, newprefix)) { ast_copy_string(prefix, newprefix, sizeof(prefix)); prefix_len = strlen(prefix); } enablestatic = newenablestatic; http_server_start(&sin); return 0; }
static int load_module(void) { struct ast_config *cfg; struct ast_flags config_flags = { 0 }; const char *tmp; if ((cfg = ast_config_load(cdr_config, config_flags)) && cfg != CONFIG_STATUS_FILEINVALID) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid")), RADIUS_FLAG_LOGUNIQUEID); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield")), RADIUS_FLAG_LOGUSERFIELD); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); ast_config_destroy(cfg); } else return AST_MODULE_LOAD_DECLINE; /* * start logging * * NOTE: Yes this causes a slight memory leak if the module is * unloaded. However, it is better than a crash if cdr_radius * and cel_radius are both loaded. */ tmp = ast_strdup("asterisk"); if (tmp) { rc_openlog((char *) tmp); } /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } if (ast_cdr_register(name, desc, radius_log)) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { return AST_MODULE_LOAD_SUCCESS; } }
/*! * \brief Load res_snmp.conf config file * \return 1 on load, 0 file does not exist */ static int load_config(void) { struct ast_variable *var; struct ast_config *cfg; struct ast_flags config_flags = { 0 }; char *cat; res_snmp_enabled = 0; res_snmp_agentx_subagent = 1; cfg = ast_config_load("res_snmp.conf", config_flags); if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_WARNING, "Could not load res_snmp.conf\n"); return 0; } cat = ast_category_browse(cfg, NULL); while (cat) { var = ast_variable_browse(cfg, cat); if (strcasecmp(cat, "general") == 0) { while (var) { if (strcasecmp(var->name, "subagent") == 0) { if (ast_true(var->value)) res_snmp_agentx_subagent = 1; else if (ast_false(var->value)) res_snmp_agentx_subagent = 0; else { ast_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value); ast_config_destroy(cfg); return 1; } } else if (strcasecmp(var->name, "enabled") == 0) { res_snmp_enabled = ast_true(var->value); } else { ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat); ast_config_destroy(cfg); return 1; } var = var->next; } } else { ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat); ast_config_destroy(cfg); return 1; } cat = ast_category_browse(cfg, cat); } ast_config_destroy(cfg); return 1; }
static 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 macroif_exec(struct ast_channel *chan, void *data) { char *expr = NULL, *label_a = NULL, *label_b = NULL; int res = 0; struct localuser *u; LOCAL_USER_ADD(u); expr = ast_strdupa(data); if (!expr) { ast_log(LOG_ERROR, "Out of Memory!\n"); LOCAL_USER_REMOVE(u); return -1; } if ((label_a = strchr(expr, '?'))) { *label_a = '\0'; label_a++; if ((label_b = strchr(label_a, ':'))) { *label_b = '\0'; label_b++; } if (ast_true(expr)) macro_exec(chan, label_a); else if (label_b) macro_exec(chan, label_b); } else ast_log(LOG_WARNING, "Invalid Syntax.\n"); LOCAL_USER_REMOVE(u); return res; }
static int action_setcdruserfield(struct mansession *s, struct message *m) { struct ast_channel *c = NULL; char *userfield = astman_get_header(m, "UserField"); char *channel = astman_get_header(m, "Channel"); char *append = astman_get_header(m, "Append"); if (ast_strlen_zero(channel)) { astman_send_error(s, m, "No Channel specified"); return 0; } if (ast_strlen_zero(userfield)) { astman_send_error(s, m, "No UserField specified"); return 0; } c = ast_get_channel_by_name_locked(channel); if (!c) { astman_send_error(s, m, "No such channel"); return 0; } if (ast_true(append)) ast_cdr_appenduserfield(c, userfield); else ast_cdr_setuserfield(c, userfield); ast_mutex_unlock(&c->lock); astman_send_ack(s, m, "CDR Userfield Set"); return 0; }
static char *aoc_cli_debug_enable(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { switch (cmd) { case CLI_INIT: e->command = "aoc set debug"; e->usage = "Usage: 'aoc set debug on' to enable aoc debug, 'aoc set debug off' to disable debug.\n"; return NULL; case CLI_GENERATE: return NULL; case CLI_HANDLER: if (a->argc != 4) { return CLI_SHOWUSAGE; } else if(ast_true(a->argv[3])) { ast_cli(a->fd, "aoc debug enabled\n"); aoc_debug_enabled = 1; } else if (ast_false(a->argv[3])) { ast_cli(a->fd, "aoc debug disabled\n"); aoc_debug_enabled = 0; } else { return CLI_SHOWUSAGE; } } return CLI_SUCCESS; }
/*! \brief Custom handler for TLS boolean settings */ static int transport_tls_bool_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) { struct ast_sip_transport *transport = obj; if (!strcasecmp(var->name, "verify_server")) { transport->tls.verify_server = ast_true(var->value) ? PJ_TRUE : PJ_FALSE; } else if (!strcasecmp(var->name, "verify_client")) { transport->tls.verify_client = ast_true(var->value) ? PJ_TRUE : PJ_FALSE; } else if (!strcasecmp(var->name, "require_client_cert")) { transport->tls.require_client_cert = ast_true(var->value) ? PJ_TRUE : PJ_FALSE; } else { return -1; } return 0; }
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); }
static char *handle_memory_atexit_list(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { switch (cmd) { case CLI_INIT: e->command = "memory atexit list"; e->usage = "Usage: memory atexit list {on|off}\n" " Enable dumping a list of still allocated memory segments at exit.\n"; return NULL; case CLI_GENERATE: if (a->pos == 3) { const char * const options[] = { "off", "on", NULL }; return ast_cli_complete(a->word, options, a->n); } return NULL; } if (a->argc != 4) { return CLI_SHOWUSAGE; } if (ast_true(a->argv[3])) { atexit_list = 1; } else if (ast_false(a->argv[3])) { atexit_list = 0; } else { return CLI_SHOWUSAGE; } ast_cli(a->fd, "The atexit list is: %s\n", atexit_list ? "On" : "Off"); return CLI_SUCCESS; }
int ast_tls_read_conf(struct ast_tls_config *tls_cfg, struct ast_tcptls_session_args *tls_desc, const char *varname, const char *value) { if (!strcasecmp(varname, "tlsenable") || !strcasecmp(varname, "sslenable")) { tls_cfg->enabled = ast_true(value) ? 1 : 0; } else if (!strcasecmp(varname, "tlscertfile") || !strcasecmp(varname, "sslcert") || !strcasecmp(varname, "tlscert")) { ast_free(tls_cfg->certfile); tls_cfg->certfile = ast_strdup(value); } else if (!strcasecmp(varname, "tlsprivatekey") || !strcasecmp(varname, "sslprivatekey")) { ast_free(tls_cfg->pvtfile); tls_cfg->pvtfile = ast_strdup(value); } else if (!strcasecmp(varname, "tlscipher") || !strcasecmp(varname, "sslcipher")) { ast_free(tls_cfg->cipher); tls_cfg->cipher = ast_strdup(value); } else if (!strcasecmp(varname, "tlscafile")) { ast_free(tls_cfg->cafile); tls_cfg->cafile = ast_strdup(value); } else if (!strcasecmp(varname, "tlscapath") || !strcasecmp(varname, "tlscadir")) { ast_free(tls_cfg->capath); tls_cfg->capath = ast_strdup(value); } else if (!strcasecmp(varname, "tlsverifyclient")) { ast_set2_flag(&tls_cfg->flags, ast_true(value), AST_SSL_VERIFY_CLIENT); } else if (!strcasecmp(varname, "tlsdontverifyserver")) { ast_set2_flag(&tls_cfg->flags, ast_true(value), AST_SSL_DONT_VERIFY_SERVER); } else if (!strcasecmp(varname, "tlsbindaddr") || !strcasecmp(varname, "sslbindaddr")) { if (ast_parse_arg(value, PARSE_ADDR, &tls_desc->local_address)) ast_log(LOG_ERROR, "Invalid %s '%s'\n", varname, value); } else if (!strcasecmp(varname, "tlsclientmethod") || !strcasecmp(varname, "sslclientmethod")) { if (!strcasecmp(value, "tlsv1")) { ast_set_flag(&tls_cfg->flags, AST_SSL_TLSV1_CLIENT); ast_clear_flag(&tls_cfg->flags, AST_SSL_SSLV3_CLIENT); ast_clear_flag(&tls_cfg->flags, AST_SSL_SSLV2_CLIENT); } else if (!strcasecmp(value, "sslv3")) { ast_set_flag(&tls_cfg->flags, AST_SSL_SSLV3_CLIENT); ast_clear_flag(&tls_cfg->flags, AST_SSL_SSLV2_CLIENT); ast_clear_flag(&tls_cfg->flags, AST_SSL_TLSV1_CLIENT); } else if (!strcasecmp(value, "sslv2")) { ast_set_flag(&tls_cfg->flags, AST_SSL_SSLV2_CLIENT); ast_clear_flag(&tls_cfg->flags, AST_SSL_TLSV1_CLIENT); ast_clear_flag(&tls_cfg->flags, AST_SSL_SSLV3_CLIENT); } } else { return -1; } return 0; }
/*! \brief Mute dialplan function */ static int func_mute_write(struct ast_channel *chan, const char *cmd, char *data, const char *value) { if (!chan) { ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); return -1; } return mute_channel(chan, data, ast_true(value)); }
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; }
/*! \brief Mute dialplan function */ static int func_mute_write(struct ast_channel *chan, const char *cmd, char *data, const char *value) { struct ast_datastore *datastore = NULL; struct mute_information *mute = NULL; int is_new = 0; if (!chan) { ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); return -1; } ast_channel_lock(chan); if (!(datastore = ast_channel_datastore_find(chan, &mute_datastore, NULL))) { if (!(datastore = initialize_mutehook(chan))) { ast_channel_unlock(chan); return 0; } is_new = 1; } mute = datastore->data; if (!strcasecmp(data, "out")) { mute->mute_write = ast_true(value); ast_debug(1, "%s channel - outbound \n", ast_true(value) ? "Muting" : "Unmuting"); } else if (!strcasecmp(data, "in")) { mute->mute_read = ast_true(value); ast_debug(1, "%s channel - inbound \n", ast_true(value) ? "Muting" : "Unmuting"); } else if (!strcasecmp(data,"all")) { mute->mute_write = mute->mute_read = ast_true(value); } if (is_new) { if (mute_add_audiohook(chan, mute, datastore)) { /* Can't add audiohook - already printed error message */ ast_datastore_free(datastore); ast_free(mute); } } ast_channel_unlock(chan); 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; }
/*! \brief Custom handler for TLS boolean settings */ static int transport_tls_bool_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) { struct ast_sip_transport *transport = obj; RAII_VAR(struct ast_sip_transport_state *, state, find_or_create_temporary_state(transport), ao2_cleanup); if (!state) { return -1; } if (!strcasecmp(var->name, "verify_server")) { state->tls.verify_server = ast_true(var->value) ? PJ_TRUE : PJ_FALSE; } else if (!strcasecmp(var->name, "verify_client")) { state->tls.verify_client = ast_true(var->value) ? PJ_TRUE : PJ_FALSE; } else if (!strcasecmp(var->name, "require_client_cert")) { state->tls.require_client_cert = ast_true(var->value) ? PJ_TRUE : PJ_FALSE; } else { return -1; } return 0; }
static int load_module(void) { struct ast_config *cfg; struct ast_flags config_flags = { 0 }; const char *tmp; if ((cfg = ast_config_load(cel_config, config_flags))) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) { ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); } ast_config_destroy(cfg); } else { return AST_MODULE_LOAD_DECLINE; } /* * start logging * * NOTE: Yes this causes a slight memory leak if the module is * unloaded. However, it is better than a crash if cdr_radius * and cel_radius are both loaded. */ tmp = ast_strdup("asterisk"); if (tmp) { rc_openlog((char *) tmp); } /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } event_sub = ast_event_subscribe(AST_EVENT_CEL, radius_log, "CEL Radius Logging", NULL, AST_EVENT_IE_END); if (!event_sub) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { return AST_MODULE_LOAD_SUCCESS; } }
static int load_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; }
/*! \brief Encoding format handler converts from boolean to enum. */ static int encoding_format_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) { struct ast_ari_conf_general *general = obj; if (!strcasecmp(var->name, "pretty")) { general->format = ast_true(var->value) ? AST_JSON_PRETTY : AST_JSON_COMPACT; } else { return -1; } return 0; }
int ast_jb_read_conf(struct ast_jb_conf *conf, const char *varname, const char *value) { int prefixlen = sizeof(AST_JB_CONF_PREFIX) - 1; const char *name; int tmp; if (strncasecmp(AST_JB_CONF_PREFIX, varname, prefixlen)) { return -1; } name = varname + prefixlen; if (!strcasecmp(name, AST_JB_CONF_ENABLE)) { ast_set2_flag(conf, ast_true(value), AST_JB_ENABLED); } else if (!strcasecmp(name, AST_JB_CONF_FORCE)) { ast_set2_flag(conf, ast_true(value), AST_JB_FORCED); } else if (!strcasecmp(name, AST_JB_CONF_MAX_SIZE)) { if ((tmp = atoi(value)) > 0) conf->max_size = tmp; } else if (!strcasecmp(name, AST_JB_CONF_RESYNCH_THRESHOLD)) { if ((tmp = atoi(value)) > 0) conf->resync_threshold = tmp; } else if (!strcasecmp(name, AST_JB_CONF_IMPL)) { if (!ast_strlen_zero(value)) snprintf(conf->impl, sizeof(conf->impl), "%s", value); } else if (!strcasecmp(name, AST_JB_CONF_TARGET_EXTRA)) { if (sscanf(value, "%30d", &tmp) == 1) { conf->target_extra = tmp; } } else if (!strcasecmp(name, AST_JB_CONF_LOG)) { ast_set2_flag(conf, ast_true(value), AST_JB_LOG); } else { return -1; } return 0; }
static int start_monitor_action(struct mansession *s, struct message *m) { struct ast_channel *c = NULL; char *name = astman_get_header(m, "Channel"); char *fname = astman_get_header(m, "File"); char *format = astman_get_header(m, "Format"); char *mix = astman_get_header(m, "Mix"); char *d; if (ast_strlen_zero(name)) { astman_send_error(s, m, "No channel specified"); return 0; } c = ast_get_channel_by_name_locked(name); if (!c) { astman_send_error(s, m, "No such channel"); return 0; } if (ast_strlen_zero(fname)) { /* No filename base specified, default to channel name as per CLI */ fname = malloc (FILENAME_MAX); if (!fname) { astman_send_error(s, m, "Could not start monitoring channel"); ast_mutex_unlock(&c->lock); return 0; } memset(fname, 0, FILENAME_MAX); ast_copy_string(fname, c->name, FILENAME_MAX); /* Channels have the format technology/channel_name - have to replace that / */ if ((d=strchr(fname, '/'))) *d='-'; } if (ast_monitor_start(c, format, fname, 1)) { if (ast_monitor_change_fname(c, fname, 1)) { astman_send_error(s, m, "Could not start monitoring channel"); ast_mutex_unlock(&c->lock); return 0; } } if (ast_true(mix)) { ast_monitor_setjoinfiles(c, 1); } ast_mutex_unlock(&c->lock); astman_send_ack(s, m, "Started monitoring channel"); return 0; }
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 enum play_tone_action parse_playtone(const char *playtone_val) { if (ast_strlen_zero(playtone_val) || ast_false(playtone_val)) { return PLAYTONE_NONE; } if (!strcasecmp(playtone_val, "channel1")) { return PLAYTONE_CHANNEL1; } else if (!strcasecmp(playtone_val, "channel2") || ast_true(playtone_val)) { return PLAYTONE_CHANNEL2; } else if (!strcasecmp(playtone_val, "both")) { return PLAYTONE_BOTH; } else { /* Invalid input. Assume none */ return PLAYTONE_NONE; } }
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 manager_mutestream(struct mansession *s, const struct message *m) { const char *channel = astman_get_header(m, "Channel"); const char *id = astman_get_header(m,"ActionID"); const char *state = astman_get_header(m,"State"); const char *direction = astman_get_header(m,"Direction"); char id_text[256]; struct ast_channel *c = NULL; if (ast_strlen_zero(channel)) { astman_send_error(s, m, "Channel not specified"); return 0; } if (ast_strlen_zero(state)) { astman_send_error(s, m, "State not specified"); return 0; } if (ast_strlen_zero(direction)) { astman_send_error(s, m, "Direction not specified"); return 0; } /* Ok, we have everything */ c = ast_channel_get_by_name(channel); if (!c) { astman_send_error(s, m, "No such channel"); return 0; } if (mute_channel(c, direction, ast_true(state))) { astman_send_error(s, m, "Failed to mute/unmute stream"); ast_channel_unref(c); return 0; } ast_channel_unref(c); if (!ast_strlen_zero(id)) { snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id); } else { id_text[0] = '\0'; } astman_append(s, "Response: Success\r\n" "%s" "\r\n", id_text); return 0; }
static void parse_config(void) { struct ast_config *cfg; struct ast_variable *var; if ((cfg = ast_config_load("codecs.conf"))) { if ((var = ast_variable_browse(cfg, "plc"))) { while (var) { if (!strcasecmp(var->name, "genericplc")) { useplc = ast_true(var->value) ? 1 : 0; if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "codec_gsm: %susing generic PLC\n", useplc ? "" : "not "); } var = var->next; } } ast_config_destroy(cfg); } }
static void check_debug(void) { RAII_VAR(char *, debug, ast_sip_get_debug(), ast_free); if (ast_false(debug)) { logging_mode = LOGGING_MODE_DISABLED; return; } logging_mode = LOGGING_MODE_ENABLED; if (ast_true(debug)) { ast_sockaddr_setnull(&log_addr); return; } /* assume host */ if (ast_sockaddr_resolve_first_af(&log_addr, debug, 0, AST_AF_UNSPEC)) { ast_log(LOG_WARNING, "Could not resolve host %s for debug " "logging\n", debug); } }
static char *handle_memory_backtrace(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { switch (cmd) { case CLI_INIT: e->command = "memory backtrace"; e->usage = "Usage: memory backtrace {on|off}\n" " Enable dumping an allocation backtrace with memory diagnostics.\n" " Note that saving the backtrace data for each allocation\n" " can be CPU intensive.\n"; return NULL; case CLI_GENERATE: if (a->pos == 2) { const char * const options[] = { "off", "on", NULL }; return ast_cli_complete(a->word, options, a->n); } return NULL; } if (a->argc != 3) { return CLI_SHOWUSAGE; } if (ast_true(a->argv[2])) { backtrace_enabled = 1; } else if (ast_false(a->argv[2])) { backtrace_enabled = 0; } else { return CLI_SHOWUSAGE; } ast_cli(a->fd, "The memory backtrace is: %s\n", backtrace_enabled ? "On" : "Off"); return CLI_SUCCESS; }