Example #1
0
		} else if (!strcasecmp(what, "off")) {
			logging_mode = LOGGING_MODE_DISABLED;
			ast_cli(a->fd, "PJSIP Logging disabled\n");
			return CLI_SUCCESS;
		}
	} else if (a->argc == e->args + 1) {
		if (!strcasecmp(what, "host")) {
			return pjsip_enable_logger_host(a->fd, a->argv[e->args]);
		}
	}

	return CLI_SHOWUSAGE;
}

static struct ast_cli_entry cli_pjsip[] = {
	AST_CLI_DEFINE(pjsip_set_logger, "Enable/Disable PJSIP Logger Output")
};

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);
Example #2
0
		ast_cli(a->fd, "say mode is [%s]\n", old_mode);
		return CLI_SUCCESS;
	} else if (a->argc != e->args)
		return CLI_SHOWUSAGE;
	mode = a->argv[2];
	if (!strcmp(mode, old_mode))
		ast_cli(a->fd, "say mode is %s already\n", mode);
	else
		if (say_init_mode(mode) == 0)
			ast_cli(a->fd, "setting say mode from %s to %s\n", old_mode, mode);

	return CLI_SUCCESS;
}

static struct ast_cli_entry cli_playback[] = {
	AST_CLI_DEFINE(__say_cli_init, "Set or show the say mode"),
};

static int playback_exec(struct ast_channel *chan, const char *data)
{
	int res = 0;
	int mres = 0;
	char *tmp;
	int option_skip=0;
	int option_say=0;
	int option_noanswer = 0;

	AST_DECLARE_APP_ARGS(args,
		AST_APP_ARG(filenames);
		AST_APP_ARG(options);
	);
Example #3
0
	if (fs_out) {
		ast_closestream(fs_out);
		if (ret != CLI_SUCCESS)
			ast_filedelete(name_out, ext_out);
	}

	if (fs_in) 
		ast_closestream(fs_in);

	ast_module_unref(ast_module_info->self);

	return ret;
}

static struct ast_cli_entry cli_convert[] = {
	AST_CLI_DEFINE(handle_cli_file_convert, "Convert audio file")
};

static int unload_module(void)
{
	ast_cli_unregister_multiple(cli_convert, ARRAY_LEN(cli_convert));
	return 0;
}

static int load_module(void)
{
	ast_cli_register_multiple(cli_convert, ARRAY_LEN(cli_convert));
	return AST_MODULE_LOAD_SUCCESS;
}

AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "File format conversion CLI command");
#define MAX_DB_OPTION_SIZE 64

static char dbhost[MAX_DB_OPTION_SIZE] = "";
static char dbuser[MAX_DB_OPTION_SIZE] = "";
static char dbpass[MAX_DB_OPTION_SIZE] = "";
static char dbname[MAX_DB_OPTION_SIZE] = "";
static char dbsock[MAX_DB_OPTION_SIZE] = "";
static int dbport = 5432;
static time_t connect_time = 0;

static int parse_config(int reload);
static int pgsql_reconnect(const char *database);
static char *handle_cli_realtime_pgsql_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);

static struct ast_cli_entry cli_realtime[] = {
	AST_CLI_DEFINE(handle_cli_realtime_pgsql_status, "Shows connection information for the PostgreSQL RealTime driver"),
};

static struct ast_variable *realtime_pgsql(const char *database, const char *table, va_list ap)
{
	PGresult *result = NULL;
	int num_rows = 0, pgerror;
	char sql[256], escapebuf[513];
	char *stringp;
	char *chunk;
	char *op;
	const char *newparam, *newval;
	struct ast_variable *var = NULL, *prev = NULL;

	if (!table) {
		ast_log(LOG_WARNING, "PostgreSQL RealTime: No table specified.\n");
	it = ao2_iterator_init(locals, 0);
	while ((p = ao2_iterator_next(&it))) {
		ao2_lock(p);
		ast_cli(a->fd, "%s -- %s\n",
			p->base.owner ? ast_channel_name(p->base.owner) : "<unowned>",
			p->base.name);
		ao2_unlock(p);
		ao2_ref(p, -1);
	}
	ao2_iterator_destroy(&it);

	return CLI_SUCCESS;
}

static struct ast_cli_entry cli_local[] = {
	AST_CLI_DEFINE(locals_show, "List status of local channels"),
};

static int manager_optimize_away(struct mansession *s, const struct message *m)
{
	const char *channel;
	struct local_pvt *p;
	struct local_pvt *found;
	struct ast_channel *chan;

	channel = astman_get_header(m, "Channel");
	if (ast_strlen_zero(channel)) {
		astman_send_error(s, m, "'Channel' not specified.");
		return 0;
	}
Example #6
0
		case ALLOC_ERROR:
			ast_cli(a->fd, "Unable to allocate NOTIFY task data\n");
			return CLI_FAILURE;
		case TASK_PUSH_ERROR:
			ast_cli(a->fd, "Unable to push NOTIFY task\n");
			return CLI_FAILURE;
		default:
			break;
		}
	}

	return CLI_SUCCESS;
}

static struct ast_cli_entry cli_options[] = {
	AST_CLI_DEFINE(cli_notify, "Send a NOTIFY request to a SIP endpoint")
};

/*!
 * \interanl
 * \brief Completes SIPNotify AMI command in Endpoint mode.
 */
static void manager_notify_endpoint(struct mansession *s,
	const struct message *m, const char *endpoint_name)
{
	struct ast_variable *vars = astman_get_variables_order(m, ORDER_NATURAL);

	if (!strncasecmp(endpoint_name, "sip/", 4)) {
		endpoint_name += 4;
	}
Example #7
0
		}

		if (records == totalrecords) {
			ast_cli(a->fd, "  Wrote %d records since last restart.\n", totalrecords);
		} else {
			ast_cli(a->fd, "  Wrote %d records since last restart and %d records since last reconnect.\n", totalrecords, records);
		}
	} else {
		ast_cli(a->fd, "Not currently connected to a MongoDB server.\n");
	}

	return CLI_SUCCESS;
}

static struct ast_cli_entry cdr_mongodb_status_cli[] = {
	AST_CLI_DEFINE(handle_cli_cdr_mongodb_status, "Show connection status of cdr_mongodb"),
};

static int load_config_number(struct ast_config *cfg, const char *category, const char *variable, int *field, int def)
{
	const char *tmp;

	tmp = ast_variable_retrieve(cfg, category, variable);

	if (!tmp || sscanf(tmp, "%d", field) < 1) {
		*field = def;
	}

	return 0;
}
Example #8
0
	}

	ao2_callback(appset, OBJ_NODATA, print_app, a);

	if (!(sub = ast_event_subscribe_new(AST_EVENT_SUB, print_cel_sub, a))) {
		return CLI_FAILURE;
	}
	ast_event_sub_append_ie_uint(sub, AST_EVENT_IE_EVENTTYPE, AST_EVENT_CEL);
	ast_event_report_subs(sub);
	ast_event_sub_destroy(sub);
	sub = NULL;

	return CLI_SUCCESS;
}

static struct ast_cli_entry cli_status = AST_CLI_DEFINE(handle_cli_status, "Display the CEL status");

enum ast_cel_event_type ast_cel_str_to_event_type(const char *name)
{
	unsigned int i;

	for (i = 0; i < ARRAY_LEN(cel_event_types); i++) {
		if (!cel_event_types[i]) {
			continue;
		}

		if (!strcasecmp(name, cel_event_types[i])) {
			return i;
		}
	}
Example #9
0
	codec = ao2_callback(codecs, 0, codec_id_cmp, &type_punned_codec);
	if (!codec) {
		ast_cli(a->fd, "Codec %d not found\n", type_punned_codec);
		return CLI_SUCCESS;
	}

	ast_cli(a->fd, "%11u %s\n", (unsigned int) codec->id, codec->description);

	ao2_ref(codec, -1);

	return CLI_SUCCESS;
}

/* Builtin Asterisk CLI-commands for debugging */
static struct ast_cli_entry codec_cli[] = {
	AST_CLI_DEFINE(show_codecs, "Displays a list of registered codecs"),
	AST_CLI_DEFINE(show_codec, "Shows a specific codec"),
};

/*! \brief Function called when the process is shutting down */
static void codec_shutdown(void)
{
	ast_cli_unregister_multiple(codec_cli, ARRAY_LEN(codec_cli));
	ao2_cleanup(codecs);
	codecs = NULL;
}

int ast_codec_init(void)
{
	codecs = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, CODEC_BUCKETS, codec_hash, codec_cmp);
	if (!codecs) {
Example #10
0
static char *timing_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
	struct ast_timer *timer;
	int count = 0;
	struct timeval start, end;
	unsigned int test_rate = 50;

	switch (cmd) {
	case CLI_INIT:
		e->command = "timing test";
		e->usage = "Usage: timing test <rate>\n"
		           "   Test a timer with a specified rate, 50/sec by default.\n"
		           "";
		return NULL;
	case CLI_GENERATE:
		return NULL;
	}

	if (a->argc != 2 && a->argc != 3) {
		return CLI_SHOWUSAGE;
	}

	if (a->argc == 3) {
		unsigned int rate;
		if (sscanf(a->argv[2], "%30u", &rate) == 1) {
			test_rate = rate;
		} else {
			ast_cli(a->fd, "Invalid rate '%s', using default of %u\n", a->argv[2], test_rate);
		}
	}

	ast_cli(a->fd, "Attempting to test a timer with %u ticks per second.\n", test_rate);

	if (!(timer = ast_timer_open())) {
		ast_cli(a->fd, "Failed to open timing fd\n");
		return CLI_FAILURE;
	}

	ast_cli(a->fd, "Using the '%s' timing module for this test.\n", timer->holder->iface->name);

	start = ast_tvnow();

	ast_timer_set_rate(timer, test_rate);

	while (ast_tvdiff_ms((end = ast_tvnow()), start) < 1000) {
		int res;
		struct pollfd pfd = {
			.fd = ast_timer_fd(timer),
			.events = POLLIN | POLLPRI,
		};

		res = ast_poll(&pfd, 1, 100);

		if (res == 1) {
			count++;
			if (ast_timer_ack(timer, 1) < 0) {
				ast_cli(a->fd, "Timer failed to acknowledge.\n");
				ast_timer_close(timer);
				return CLI_FAILURE;
			}
		} else if (!res) {
			ast_cli(a->fd, "poll() timed out!  This is bad.\n");
		} else if (errno != EAGAIN && errno != EINTR) {
			ast_cli(a->fd, "poll() returned error: %s\n", strerror(errno));
		}
	}

	ast_timer_close(timer);
	timer = NULL;

	ast_cli(a->fd, "It has been %" PRIi64 " milliseconds, and we got %d timer ticks\n",
		ast_tvdiff_ms(end, start), count);

	return CLI_SUCCESS;
}

static struct ast_cli_entry cli_timing[] = {
	AST_CLI_DEFINE(timing_test, "Run a timing test"),
};

static void timing_shutdown(void)
{
	ast_cli_unregister_multiple(cli_timing, ARRAY_LEN(cli_timing));

	ast_heap_destroy(timing_interfaces);
	timing_interfaces = NULL;
}
				return RESULT_SHOWUSAGE;

			/* Print result */	
			if(level)
				ast_cli(a->fd, "app_h324m Debugging enabled level: %d\n", level);
			else
				ast_cli(a->fd, "app_h324m Debugging disabled\n");

			/* Set log level */
			H324MLoggerSetLevel(level);

			return CLI_SUCCESS;
	}
}

static struct ast_cli_entry  cli_debug = AST_CLI_DEFINE(h324m_do_debug,"Set app_h324m debug log level");

#else
/* Commands */
static int h324m_do_debug(int fd, int argc, char *argv[])
{
	int level;

	/* Check number of arguments */
	if (argc != 4)
		return RESULT_SHOWUSAGE;

	/* Get level */
	level = atoi(argv[3]);

	/* Check it's correct */
Example #12
0
	return ret;
}

void ast_db_freetree(struct ast_db_entry *dbe)
{
	struct ast_db_entry *last;
	while (dbe) {
		last = dbe;
		dbe = dbe->next;
		ast_free(last);
	}
}

static struct ast_cli_entry cli_database[] = {
	AST_CLI_DEFINE(handle_cli_database_show,    "Shows database contents"),
	AST_CLI_DEFINE(handle_cli_database_showkey, "Shows database contents"),
	AST_CLI_DEFINE(handle_cli_database_get,     "Gets database value"),
	AST_CLI_DEFINE(handle_cli_database_put,     "Adds/updates database value"),
	AST_CLI_DEFINE(handle_cli_database_del,     "Removes database key/value"),
	AST_CLI_DEFINE(handle_cli_database_deltree, "Removes database keytree/values")
};

static int manager_dbput(struct mansession *s, const struct message *m)
{
	const char *family = astman_get_header(m, "Family");
	const char *key = astman_get_header(m, "Key");
	const char *val = astman_get_header(m, "Val");
	int res;

	if (ast_strlen_zero(family)) {
Example #13
0
                .name = "opus",
                .type = AST_MEDIA_TYPE_AUDIO,
                .sample_rate = 48000,
        },
        .format = "opus",
        .newpvt = lintoopus_new,
        .framein = lintoopus_framein,
        .frameout = lintoopus_frameout,
        .destroy = lintoopus_destroy,
        .desc_size = sizeof(struct opus_coder_pvt),
        .buffer_samples = BUFFER_SAMPLES,
        .buf_size = BUFFER_SAMPLES * 2,
};

static struct ast_cli_entry cli[] = {
	AST_CLI_DEFINE(handle_cli_opus_show, "Display Opus codec utilization.")
};

static int reload(void)
{
	/* Reload does nothing */
	return AST_MODULE_LOAD_SUCCESS;
}

static int unload_module(void)
{
	int res;

	res = ast_unregister_translator(&opustolin);
	res |= ast_unregister_translator(&lintoopus);
	res |= ast_unregister_translator(&opustolin12);
	if (a->argc >= 5) {
		return CLI_SHOWUSAGE;
	}

	date_tv = ast_tvnow();
	ast_localtime(&date_tv, &tm, zone);
	tm.tm_usec = 123;
	ast_strftime(buf, sizeof(buf), format, &tm);

	ast_cli(a->fd, "%s\nus: %d\n", buf, tm.tm_usec);

	return CLI_SUCCESS;
}

static struct ast_cli_entry cli_entries[] = {
	AST_CLI_DEFINE(cli_time, ""),
};

static int load_module(void)
{
	ast_cli_register_multiple(cli_entries, ARRAY_LEN(cli_entries));

	return AST_MODULE_LOAD_SUCCESS;
}

static int unload_module(void)
{
	ast_cli_unregister_multiple(cli_entries, ARRAY_LEN(cli_entries));

	return 0;
}
Example #15
0
	}

	if (a->argc != 3) {
		return CLI_SHOWUSAGE;
	}

	ast_mutex_lock(&dblock);
	db_execute_sql(a->argv[2], display_results, a);
	db_sync(); /* Go ahead and sync the db in case they write */
	ast_mutex_unlock(&dblock);

	return CLI_SUCCESS;
}

static struct ast_cli_entry cli_database[] = {
	AST_CLI_DEFINE(handle_cli_database_show,    "Shows database contents"),
	AST_CLI_DEFINE(handle_cli_database_showkey, "Shows database contents"),
	AST_CLI_DEFINE(handle_cli_database_get,     "Gets database value"),
	AST_CLI_DEFINE(handle_cli_database_put,     "Adds/updates database value"),
	AST_CLI_DEFINE(handle_cli_database_del,     "Removes database key/value"),
	AST_CLI_DEFINE(handle_cli_database_deltree, "Removes database keytree/values"),
	AST_CLI_DEFINE(handle_cli_database_query,   "Run a user-specified query on the astdb"),
};

static int manager_dbput(struct mansession *s, const struct message *m)
{
	const char *family = astman_get_header(m, "Family");
	const char *key = astman_get_header(m, "Key");
	const char *val = astman_get_header(m, "Val");
	int res;
Example #16
0
			ast_cli(a->fd, "Could not update mailbox %s.\n",
				ast_sorcery_object_get_id(mailbox));
		} else {
			ast_cli(a->fd, "Updated mailbox %s.\n", ast_sorcery_object_get_id(mailbox));
		}

		ast_mwi_mailbox_unref(mailbox);
	}

	return CLI_SUCCESS;
}
#endif	/* defined(MWI_DEBUG_CLI) */

#if defined(MWI_DEBUG_CLI)
static struct ast_cli_entry mwi_cli[] = {
	AST_CLI_DEFINE(handle_mwi_delete_all, "Delete all external MWI mailboxes"),
	AST_CLI_DEFINE(handle_mwi_delete_like, "Delete external MWI mailboxes matching regex"),
	AST_CLI_DEFINE(handle_mwi_delete_mailbox, "Delete a specific external MWI mailbox"),
	AST_CLI_DEFINE(handle_mwi_list_all, "List all external MWI mailboxes"),
	AST_CLI_DEFINE(handle_mwi_list_like, "List external MWI mailboxes matching regex"),
	AST_CLI_DEFINE(handle_mwi_show_mailbox, "Show a specific external MWI mailbox"),
	AST_CLI_DEFINE(handle_mwi_update_mailbox, "Update a specific external MWI mailbox"),
};
#endif	/* defined(MWI_DEBUG_CLI) */

/*!
 * \internal
 * \brief Post initial MWI count events.
 * \since 12.1.0
 *
 * \return Nothing
Example #17
0
		contacts = ast_sip_location_retrieve_aor_contacts(aor);
		if (contacts) {
			ao2_callback(contacts, OBJ_NODATA, ami_contact_cb, NULL);
			ao2_ref(contacts, -1);
		}

		ao2_ref(aor, -1);
	}

	astman_send_ack(s, m, "Endpoint found, will qualify");
	return 0;
}

static struct ast_cli_entry cli_options[] = {
	AST_CLI_DEFINE(cli_qualify, "Send an OPTIONS request to a PJSIP endpoint")
};

static int sched_qualifies_hash_fn(const void *obj, int flags)
{
	const struct sched_data *object;
	const struct ast_sip_contact *key;

	switch (flags & OBJ_SEARCH_MASK) {
	case OBJ_SEARCH_KEY:
		key = obj;
		break;
	case OBJ_SEARCH_OBJECT:
		object = obj;
		key = object->contact;
		break;
Example #18
0
	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 struct ast_cli_entry cli_memory[] = {
	AST_CLI_DEFINE(handle_memory_atexit_list, "Enable memory allocations not freed at exit list."),
	AST_CLI_DEFINE(handle_memory_atexit_summary, "Enable memory allocations not freed at exit summary."),
	AST_CLI_DEFINE(handle_memory_show_allocations, "Display outstanding memory allocations"),
	AST_CLI_DEFINE(handle_memory_show_summary, "Summarize outstanding memory allocations"),
	AST_CLI_DEFINE(handle_memory_backtrace, "Enable dumping an allocation backtrace with memory diagnostics."),
};

AST_LIST_HEAD_NOLOCK(region_list, ast_region);

/*!
 * \internal
 * \brief Convert the allocated regions hash table to a list.
 *
 * \param list Fill list with the allocated regions.
 *
 * \details
Example #19
0
		} else {
			ast_cli(a->fd, "%s%s for %d seconds.\n", status, status2, ctime);
		}
		if (records == totalrecords)
			ast_cli(a->fd, "  Wrote %d records since last restart.\n", totalrecords);
		else
			ast_cli(a->fd, "  Wrote %d records since last restart and %d records since last reconnect.\n", totalrecords, records);
		return CLI_SUCCESS;
	} else {
		ast_cli(a->fd, "Not currently connected to a MySQL server.\n");
		return CLI_FAILURE;
	}
}

static struct ast_cli_entry cli_cbmysql[] = {
	AST_CLI_DEFINE( handle_cb_mysql_status, "Show connection status of CBMySQL"),
};

static int load_config(void)
{
	/* int res; */
	struct ast_config *cfg;
	struct ast_variable *var;
	const char *tmp;
	struct ast_flags config_flags = { 0 };

	cfg = ast_config_load(CBMYSQL_CONFIG, config_flags);
	if (!cfg) {
		ast_log(LOG_WARNING, "Unable to load config for CBMySQL: %s\n", CBMYSQL_CONFIG);
		return 0;
	}
Example #20
0
			schtd->interval / 1000.0,
			schtd->run_count,
			schtd->is_running ? "running" : "waiting",
			datelen, queued, last_start, last_end);
		ao2_cleanup(schtd);
	}
	ao2_iterator_destroy(&i);
	ao2_unlock(tasks);
	ao2_ref(tasks, -1);
	ast_cli(a->fd, "\n");

	return CLI_SUCCESS;
}

static struct ast_cli_entry cli_commands[] = {
	AST_CLI_DEFINE(cli_show_tasks, "Show all scheduled tasks"),
};

int ast_sip_initialize_scheduler(void)
{
	if (!(scheduler_context = ast_sched_context_create())) {
		ast_log(LOG_ERROR, "Failed to create scheduler. Aborting load\n");
		return -1;
	}

	if (ast_sched_start_thread(scheduler_context)) {
		ast_log(LOG_ERROR, "Failed to start scheduler. Aborting load\n");
		ast_sched_context_destroy(scheduler_context);
		return -1;
	}
Example #21
0
			found = 1;
			ast_cli(a->fd, "%11u %s\n", (unsigned int) format_id, f_list[x].desc);
		}
	}

	if (!found) {
		ast_cli(a->fd, "Codec %d not found\n", format_id);
	}

	f_list = ast_format_list_destroy(f_list);
	return CLI_SUCCESS;
}

/* Builtin Asterisk CLI-commands for debugging */
static struct ast_cli_entry my_clis[] = {
	AST_CLI_DEFINE(show_codecs, "Displays a list of codecs"),
	AST_CLI_DEFINE(show_codec_n, "Shows a specific codec"),
};
int init_framer(void)
{
	ast_cli_register_multiple(my_clis, ARRAY_LEN(my_clis));
	return 0;
}

static int format_list_add_custom(struct ast_format_list *new)
{
	struct ast_format_list *entry;
	if (!(entry = ao2_alloc(sizeof(*entry), NULL))) {
		return -1;
	}
	memcpy(entry, new, sizeof(struct ast_format_list));
Example #22
0
		e->usage = ""
			"Usage: amihook unregister"
			"";
		return NULL;
	case CLI_GENERATE:
		return NULL;
	case CLI_HANDLER:
		unregister_hook();
		return CLI_SUCCESS;
	}

	return CLI_FAILURE;
}

static struct ast_cli_entry cli_amihook_evt[] = {
	AST_CLI_DEFINE(handle_cli_amihook_send, "Send an AMI event"),
	AST_CLI_DEFINE(handle_cli_amihook_register_hook, "Register module for AMI hook"),
	AST_CLI_DEFINE(handle_cli_amihook_unregister_hook, "Unregister module for AMI hook"),
};

static int unload_module(void)
{
	ast_manager_unregister_hook(&test_hook);
	return ast_cli_unregister_multiple(cli_amihook_evt, ARRAY_LEN(cli_amihook_evt));
}

static int load_module(void)
{
	int res;

	res = ast_cli_register_multiple(cli_amihook_evt, ARRAY_LEN(cli_amihook_evt));
Example #23
0
#include <asterisk/stasis.h>
#endif

#include "../include/pbx_event_message_serializer.h"
#include "../include/message_queue_pubsub.h"
#include "../include/shared.h"

pthread_rwlock_t msq_event_channel_map_rwlock = PTHREAD_RWLOCK_INITIALIZER;

/*
 * declarations
 */
static char *redis_show_config(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static char *redis_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static struct ast_cli_entry redis_cli[] = {
    AST_CLI_DEFINE(redis_show_config, "Show configuration"),
    AST_CLI_DEFINE(redis_ping, "Send a test ping to the cluster"),
};

/*
 * globals
 */
//AST_RWLOCK_DEFINE_STATIC(event_types_lock);
AST_MUTEX_DEFINE_STATIC(reload_lock);
static char *default_eid_str;

AST_RWLOCK_DEFINE_STATIC(event_map_lock);

typedef struct event_map {
    const char *name;
    boolean_t publish;
Example #24
0
	} else {
		return CLI_SHOWUSAGE;
	}

	if (res < 0) {
		ast_cli(a->fd, "Failed to remove record. Check the debug log for possible SQL related entries.\n");
		return CLI_FAILURE;
	}

	ast_cli(a->fd, "Removed %d RealTime record%s.\n", res, ESS(res));

	return CLI_SUCCESS;
}

static struct ast_cli_entry cli_realtime[] = {
	AST_CLI_DEFINE(cli_realtime_load, "Used to print out RealTime variables."),
	AST_CLI_DEFINE(cli_realtime_update, "Used to update RealTime variables."),
	AST_CLI_DEFINE(cli_realtime_update2, "Used to test the RealTime update2 method"),
	AST_CLI_DEFINE(cli_realtime_store, "Store a new row into a RealTime database"),
	AST_CLI_DEFINE(cli_realtime_destroy, "Delete a row from a RealTime database"),
};

static int unload_module(void)
{
	ast_cli_unregister_multiple(cli_realtime, ARRAY_LEN(cli_realtime));
	return 0;
}

static int load_module(void)
{
	ast_cli_register_multiple(cli_realtime, ARRAY_LEN(cli_realtime));
Example #25
0
	ast_cli(a->fd, "\n");

	if (a->argc == 2) {
		cli_display_parking_global(a->fd);
		cli_display_parking_lot_list(a->fd);
		return CLI_SUCCESS;
	}

	if (a->argc == 3) {
		cli_display_parking_lot(a->fd, a->argv[2]);
		return CLI_SUCCESS;
	}

	return CLI_SHOWUSAGE;
}

static struct ast_cli_entry cli_parking_lot[] = {
	AST_CLI_DEFINE(handle_show_parking_lot_cmd, "Show a parking lot or a list of all parking lots."),
};

int load_parking_ui(void)
{
	return ast_cli_register_multiple(cli_parking_lot, ARRAY_LEN(cli_parking_lot));
}

void unload_parking_ui(void)
{
	ast_cli_unregister_multiple(cli_parking_lot, ARRAY_LEN(cli_parking_lot));
}
Example #26
0
#define MAX_DB_OPTION_SIZE 64
static char hostname[MAX_DB_OPTION_SIZE] = "";
//static char dbuser[MAX_DB_OPTION_SIZE] = "";
//static char dbpass[MAX_DB_OPTION_SIZE] = "";
//static char dbname[MAX_DB_OPTION_SIZE] = "";
//static char dbappname[MAX_DB_OPTION_SIZE] = "";
//static char dbsock[MAX_DB_OPTION_SIZE] = "";
static int port = 6379;
struct timeval timeout = { 1, 500000 }; 	// 1.5 seconds

static int parse_config(int reload);
static int redis_reconnect(const char *database);
static char *handle_cli_realtime_redis_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);

static struct ast_cli_entry cli_realtime[] = {
	AST_CLI_DEFINE(handle_cli_realtime_redis_status, "Shows connection information for the Redis RealTime driver"),
};


#ifdef HAVE_PBX_VERSION_11
static struct ast_variable *realtime_redis(const char *database, const char *tablename, va_list ap)
#else
static struct ast_variable *realtime_redis(const char *database, const char *tablename, const struct ast_variable *fields)
#endif
{
	struct ast_variable *var = NULL;
	return var;
}

#ifdef HAVE_PBX_VERSION_11
static struct ast_config *realtime_multi_redis(const char *database, const char *table, va_list ap)
Example #27
0
		}
	}

	ast_cli(a->fd, "Test complete - %" PRIi64 " us\n", ast_tvdiff_us(ast_tvnow(), start));

return_cleanup:
	ast_sched_context_destroy(con);
	if (sched_ids) {
		ast_free(sched_ids);
	}

	return CLI_SUCCESS;
}

static struct ast_cli_entry cli_sched[] = {
	AST_CLI_DEFINE(handle_cli_sched_bench, "Benchmark ast_sched add/del performance"),
};

static int unload_module(void)
{
	AST_TEST_UNREGISTER(sched_test_order);
	ast_cli_unregister_multiple(cli_sched, ARRAY_LEN(cli_sched));
	return 0;
}

static int load_module(void)
{
	AST_TEST_REGISTER(sched_test_order);
	ast_cli_register_multiple(cli_sched, ARRAY_LEN(cli_sched));
	return AST_MODULE_LOAD_SUCCESS;
}
Example #28
0
	if (!decoded || !(msg = ast_str_create(1024))) {
		return;
	}

	if (decoding) {
		ast_str_append(&msg, 0, "---- DECODED AOC MSG ----\r\n");
	} else {
		ast_str_append(&msg, 0, "---- ENCODED AOC MSG ----\r\n");
	}
	if (chan) {
		ast_str_append(&msg, 0, "CHANNEL: %s\r\n", ast_channel_name(chan));
	}

	if (ast_aoc_decoded2str(decoded, &msg)) {
		ast_free(msg);
		return;
	}

	ast_verb(1, "%s\r\n", ast_str_buffer(msg));
	ast_free(msg);
}

static struct ast_cli_entry aoc_cli[] = {
	AST_CLI_DEFINE(aoc_cli_debug_enable, "enable cli debugging of AOC messages"),
};

int ast_aoc_cli_init(void)
{
	return ast_cli_register_multiple(aoc_cli, ARRAY_LEN(aoc_cli));
}
Example #29
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;
}
Example #30
0

	term_color(strategy, "Strategy", COLOR_YELLOW, 0, sizeof(strategy));
	term_color(desc, "Description", COLOR_BRWHITE, 0, sizeof(desc));
	term_color(params, "Parameters", COLOR_BRWHITE, 0, sizeof(params));

	for (; i < (sizeof(strategies) / sizeof(struct strategy)); ++i)
		ast_cli(a->fd, "%s: %s\n%s: %s\n%s: %s\n%s", strategy, strategies[i].name,
				desc, strategies[i].desc, params, strategies[i].desc_params ? strategies[i].desc_params : "(none)",
				(i + 1) < (sizeof(strategies) / sizeof(struct strategy)) ? "\n" : "");

	return CLI_SUCCESS;
}

static struct ast_cli_entry csel_clis[] = {
	AST_CLI_DEFINE(csel_list_strategies, "List channel selection strategies")
};

__static__ int load_module (void)
{
	ast_cli_register_multiple(csel_clis, sizeof(csel_clis) / sizeof(struct ast_cli_entry));

	return 0;
}

__static__ int unload_module (void)
{
	ast_cli_unregister_multiple(csel_clis, sizeof(csel_clis) / sizeof(struct ast_cli_entry));
	
	return 0;
}