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; }
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 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 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 process_config(int reload) { struct ast_config *config; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; const char *bindaddr; const char *bindport; const char *prefix; const char *enabled; config = ast_config_load("http.conf", config_flags); if (!config || config == CONFIG_STATUS_FILEINVALID) { return -1; } else if (config == CONFIG_STATUS_FILEUNCHANGED) { return 0; } enabled = ast_config_option(config, "general", "enabled"); if (!enabled || ast_false(enabled)) { ast_config_destroy(config); return -1; } /* Construct our Server URI */ bindaddr = ast_config_option(config, "general", "bindaddr"); if (!bindaddr) { ast_config_destroy(config); return -1; } bindport = ast_config_option(config, "general", "bindport"); if (!bindport) { bindport = "8088"; } prefix = ast_config_option(config, "general", "prefix"); snprintf(server_uri, sizeof(server_uri), "http://%s:%s%s/%s", bindaddr, bindport, S_OR(prefix, ""), TEST_URI); ast_config_destroy(config); return 0; }
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; }
static int func_channel_write_real(struct ast_channel *chan, const char *function, char *data, const char *value) { int ret = 0; signed char gainset; if (!strcasecmp(data, "language")) locked_string_field_set(chan, language, value); else if (!strcasecmp(data, "parkinglot")) locked_string_field_set(chan, parkinglot, value); else if (!strcasecmp(data, "musicclass")) locked_string_field_set(chan, musicclass, value); else if (!strcasecmp(data, "accountcode")) locked_string_field_set(chan, accountcode, value); else if (!strcasecmp(data, "userfield")) locked_string_field_set(chan, userfield, value); else if (!strcasecmp(data, "after_bridge_goto")) { if (ast_strlen_zero(value)) { ast_bridge_discard_after_goto(chan); } else { ast_bridge_set_after_go_on(chan, ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan), value); } } else if (!strcasecmp(data, "amaflags")) { ast_channel_lock(chan); if (isdigit(*value)) { int amaflags; sscanf(value, "%30d", &amaflags); ast_channel_amaflags_set(chan, amaflags); } else if (!strcasecmp(value,"OMIT")){ ast_channel_amaflags_set(chan, 1); } else if (!strcasecmp(value,"BILLING")){ ast_channel_amaflags_set(chan, 2); } else if (!strcasecmp(value,"DOCUMENTATION")){ ast_channel_amaflags_set(chan, 3); } ast_channel_unlock(chan); } else if (!strcasecmp(data, "peeraccount")) locked_string_field_set(chan, peeraccount, value); else if (!strcasecmp(data, "hangupsource")) /* XXX - should we be forcing this here? */ ast_set_hangupsource(chan, value, 0); #ifdef CHANNEL_TRACE else if (!strcasecmp(data, "trace")) { ast_channel_lock(chan); if (ast_true(value)) ret = ast_channel_trace_enable(chan); else if (ast_false(value)) ret = ast_channel_trace_disable(chan); else { ret = -1; ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace).\n"); } ast_channel_unlock(chan); } #endif else if (!strcasecmp(data, "tonezone")) { struct ast_tone_zone *new_zone; if (!(new_zone = ast_get_indication_zone(value))) { ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value); ret = -1; } else { ast_channel_lock(chan); if (ast_channel_zone(chan)) { ast_channel_zone_set(chan, ast_tone_zone_unref(ast_channel_zone(chan))); } ast_channel_zone_set(chan, ast_tone_zone_ref(new_zone)); ast_channel_unlock(chan); new_zone = ast_tone_zone_unref(new_zone); } } else if (!strcasecmp(data, "dtmf_features")) { ret = ast_bridge_features_ds_set_string(chan, value); } else if (!strcasecmp(data, "callgroup")) { ast_channel_lock(chan); ast_channel_callgroup_set(chan, ast_get_group(value)); ast_channel_unlock(chan); } else if (!strcasecmp(data, "pickupgroup")) { ast_channel_lock(chan); ast_channel_pickupgroup_set(chan, ast_get_group(value)); ast_channel_unlock(chan); } else if (!strcasecmp(data, "namedcallgroup")) { struct ast_namedgroups *groups = ast_get_namedgroups(value); ast_channel_lock(chan); ast_channel_named_callgroups_set(chan, groups); ast_channel_unlock(chan); ast_unref_namedgroups(groups); } else if (!strcasecmp(data, "namedpickupgroup")) { struct ast_namedgroups *groups = ast_get_namedgroups(value); ast_channel_lock(chan); ast_channel_named_pickupgroups_set(chan, groups); ast_channel_unlock(chan); ast_unref_namedgroups(groups); } else if (!strcasecmp(data, "txgain")) { sscanf(value, "%4hhd", &gainset); ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0); } else if (!strcasecmp(data, "rxgain")) { sscanf(value, "%4hhd", &gainset); ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0); } else if (!strcasecmp(data, "transfercapability")) { unsigned short i; ast_channel_lock(chan); for (i = 0; i < 0x20; i++) { if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) { ast_channel_transfercapability_set(chan, i); break; } } ast_channel_unlock(chan); } else if (!strcasecmp(data, "hangup_handler_pop")) { /* Pop one hangup handler before pushing the new handler. */ ast_pbx_hangup_handler_pop(chan); ast_pbx_hangup_handler_push(chan, value); } else if (!strcasecmp(data, "hangup_handler_push")) { ast_pbx_hangup_handler_push(chan, value); } else if (!strcasecmp(data, "hangup_handler_wipe")) { /* Pop all hangup handlers before pushing the new handler. */ while (ast_pbx_hangup_handler_pop(chan)) { } ast_pbx_hangup_handler_push(chan, value); } else if (!strncasecmp(data, "secure_bridge_", 14)) { struct ast_datastore *ds; struct ast_secure_call_store *store; if (!chan || !value) { return -1; } ast_channel_lock(chan); if (!(ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) { if (!(ds = ast_datastore_alloc(&secure_call_info, NULL))) { ast_channel_unlock(chan); return -1; } if (!(store = ast_calloc(1, sizeof(*store)))) { ast_channel_unlock(chan); ast_free(ds); return -1; } ds->data = store; ast_channel_datastore_add(chan, ds); } else { store = ds->data; } if (!strcasecmp(data, "secure_bridge_signaling")) { store->signaling = ast_true(value) ? 1 : 0; } else if (!strcasecmp(data, "secure_bridge_media")) { store->media = ast_true(value) ? 1 : 0; } ast_channel_unlock(chan); } else if (!strcasecmp(data, "max_forwards")) { int max_forwards; if (sscanf(value, "%d", &max_forwards) != 1) { ast_log(LOG_WARNING, "Unable to set max forwards to '%s'\n", value); ret = -1; } else { ast_channel_lock(chan); ret = ast_max_forwards_set(chan, max_forwards); ast_channel_unlock(chan); } } else if (!ast_channel_tech(chan)->func_channel_write || ast_channel_tech(chan)->func_channel_write(chan, function, data, value)) { ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data); ret = -1; } return ret; }
static char *handle_memory_atexit_summary(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { char buf[80]; switch (cmd) { case CLI_INIT: e->command = "memory atexit summary"; e->usage = "Usage: memory atexit summary {off|byline|byfunc|byfile}\n" " Summary of still allocated memory segments at exit options.\n" " off - Disable at exit summary.\n" " byline - Enable at exit summary by file line number.\n" " byfunc - Enable at exit summary by function name.\n" " byfile - Enable at exit summary by file.\n" "\n" " Note: byline, byfunc, and byfile are cumulative enables.\n"; return NULL; case CLI_GENERATE: if (a->pos == 3) { const char * const options[] = { "off", "byline", "byfunc", "byfile", NULL }; return ast_cli_complete(a->word, options, a->n); } return NULL; } if (a->argc != 4) { return CLI_SHOWUSAGE; } if (ast_false(a->argv[3])) { atexit_summary = SUMMARY_OFF; } else if (!strcasecmp(a->argv[3], "byline")) { atexit_summary |= SUMMARY_BY_LINE; } else if (!strcasecmp(a->argv[3], "byfunc")) { atexit_summary |= SUMMARY_BY_FUNC; } else if (!strcasecmp(a->argv[3], "byfile")) { atexit_summary |= SUMMARY_BY_FILE; } else { return CLI_SHOWUSAGE; } if (atexit_summary) { buf[0] = '\0'; if (atexit_summary & SUMMARY_BY_LINE) { strcat(buf, "byline"); } if (atexit_summary & SUMMARY_BY_FUNC) { if (buf[0]) { strcat(buf, " | "); } strcat(buf, "byfunc"); } if (atexit_summary & SUMMARY_BY_FILE) { if (buf[0]) { strcat(buf, " | "); } strcat(buf, "byfile"); } } else { strcpy(buf, "Off"); } ast_cli(a->fd, "The atexit summary is: %s\n", buf); return CLI_SUCCESS; }
static int func_channel_write_real(struct ast_channel *chan, const char *function, char *data, const char *value) { int ret = 0; signed char gainset; if (!strcasecmp(data, "language")) locked_string_field_set(chan, language, value); else if (!strcasecmp(data, "parkinglot")) locked_string_field_set(chan, parkinglot, value); else if (!strcasecmp(data, "musicclass")) locked_string_field_set(chan, musicclass, value); else if (!strcasecmp(data, "accountcode")) locked_string_field_set(chan, accountcode, value); else if (!strcasecmp(data, "userfield")) locked_string_field_set(chan, userfield, value); else if (!strcasecmp(data, "amaflags")) { ast_channel_lock(chan); if(isdigit(*value)) { sscanf(value, "%30d", &chan->amaflags); } else if (!strcasecmp(value,"OMIT")) { chan->amaflags = 1; } else if (!strcasecmp(value,"BILLING")) { chan->amaflags = 2; } else if (!strcasecmp(value,"DOCUMENTATION")) { chan->amaflags = 3; } ast_channel_unlock(chan); } else if (!strcasecmp(data, "peeraccount")) locked_string_field_set(chan, peeraccount, value); else if (!strcasecmp(data, "hangupsource")) /* XXX - should we be forcing this here? */ ast_set_hangupsource(chan, value, 0); #ifdef CHANNEL_TRACE else if (!strcasecmp(data, "trace")) { ast_channel_lock(chan); if (ast_true(value)) ret = ast_channel_trace_enable(chan); else if (ast_false(value)) ret = ast_channel_trace_disable(chan); else { ret = -1; ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace)."); } ast_channel_unlock(chan); } #endif else if (!strcasecmp(data, "tonezone")) { struct ast_tone_zone *new_zone; if (!(new_zone = ast_get_indication_zone(value))) { ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value); ret = -1; } else { ast_channel_lock(chan); if (chan->zone) { chan->zone = ast_tone_zone_unref(chan->zone); } chan->zone = ast_tone_zone_ref(new_zone); ast_channel_unlock(chan); new_zone = ast_tone_zone_unref(new_zone); } } else if (!strcasecmp(data, "callgroup")) { chan->callgroup = ast_get_group(value); } else if (!strcasecmp(data, "pickupgroup")) { chan->pickupgroup = ast_get_group(value); } else if (!strcasecmp(data, "txgain")) { sscanf(value, "%4hhd", &gainset); ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0); } else if (!strcasecmp(data, "rxgain")) { sscanf(value, "%4hhd", &gainset); ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0); } else if (!strcasecmp(data, "transfercapability")) { unsigned short i; for (i = 0; i < 0x20; i++) { if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) { chan->transfercapability = i; break; } } } else if (!strncasecmp(data, "secure_bridge_", 14)) { struct ast_datastore *ds; struct ast_secure_call_store *store; if (!chan || !value) { return -1; } ast_channel_lock(chan); if (!(ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) { if (!(ds = ast_datastore_alloc(&secure_call_info, NULL))) { ast_channel_unlock(chan); return -1; } if (!(store = ast_calloc(1, sizeof(*store)))) { ast_channel_unlock(chan); ast_free(ds); return -1; } ds->data = store; ast_channel_datastore_add(chan, ds); } else { store = ds->data; } ast_channel_unlock(chan); if (!strcasecmp(data, "secure_bridge_signaling")) { store->signaling = ast_true(value) ? 1 : 0; } else if (!strcasecmp(data, "secure_bridge_media")) { store->media = ast_true(value) ? 1 : 0; } } else if (!chan->tech->func_channel_write || chan->tech->func_channel_write(chan, function, data, value)) { ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data); ret = -1; } return ret; }
static int func_channel_write(struct ast_channel *chan, const char *function, char *data, const char *value) { int ret = 0; signed char gainset; if (!strcasecmp(data, "language")) locked_string_field_set(chan, language, value); else if (!strcasecmp(data, "parkinglot")) locked_string_field_set(chan, parkinglot, value); else if (!strcasecmp(data, "musicclass")) locked_string_field_set(chan, musicclass, value); #ifdef CHANNEL_TRACE else if (!strcasecmp(data, "trace")) { ast_channel_lock(chan); if (ast_true(value)) ret = ast_channel_trace_enable(chan); else if (ast_false(value)) ret = ast_channel_trace_disable(chan); else { ret = -1; ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace)."); } ast_channel_unlock(chan); } #endif else if (!strcasecmp(data, "tonezone")) { struct ast_tone_zone *new_zone; if (!(new_zone = ast_get_indication_zone(value))) { ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value); ret = -1; } else { ast_channel_lock(chan); if (chan->zone) { chan->zone = ast_tone_zone_unref(chan->zone); } chan->zone = ast_tone_zone_ref(new_zone); ast_channel_unlock(chan); new_zone = ast_tone_zone_unref(new_zone); } } else if (!strcasecmp(data, "callgroup")) chan->callgroup = ast_get_group(value); else if (!strcasecmp(data, "txgain")) { sscanf(value, "%4hhd", &gainset); ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0); } else if (!strcasecmp(data, "rxgain")) { sscanf(value, "%4hhd", &gainset); ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0); } else if (!strcasecmp(data, "transfercapability")) { unsigned short i; for (i = 0; i < 0x20; i++) { if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) { chan->transfercapability = i; break; } } } else if (!chan->tech->func_channel_write || chan->tech->func_channel_write(chan, function, data, value)) { ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data); ret = -1; } return ret; }