예제 #1
0
/*!
 * \brief handle for orgination app or exten.
 * \param e pointer to the CLI structure to initialize
 * \param cmd operation to execute
 * \param a structure that contains either application or extension arguments
 * \retval CLI_SUCCESS on success.
 * \retval CLI_SHOWUSAGE on failure.
*/
static char *handle_orig(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
	static char *choices[] = { "application", "extension", NULL };
	char *res;
	switch (cmd) {
	case CLI_INIT:
		e->command = "channel originate";
		e->usage = 
			"  There are two ways to use this command. A call can be originated between a\n"
			"channel and a specific application, or between a channel and an extension in\n"
			"the dialplan. This is similar to call files or the manager originate action.\n"
			"Calls originated with this command are given a timeout of 30 seconds.\n\n"

			"Usage1: channel originate <tech/data> application <appname> [appdata]\n"
			"  This will originate a call between the specified channel tech/data and the\n"
			"given application. Arguments to the application are optional. If the given\n"
			"arguments to the application include spaces, all of the arguments to the\n"
			"application need to be placed in quotation marks.\n\n"

			"Usage2: channel originate <tech/data> extension [exten@][context]\n"
			"  This will originate a call between the specified channel tech/data and the\n"
			"given extension. If no context is specified, the 'default' context will be\n"
			"used. If no extension is given, the 's' extension will be used.\n";
		return NULL;
	case CLI_GENERATE:
		if (a->pos != 3)
			return NULL;

		/* ugly, can be removed when CLI entries have ast_module pointers */
		ast_module_ref(ast_module_info->self);
		res = ast_cli_complete(a->word, choices, a->n);
		ast_module_unref(ast_module_info->self);

		return res;
	}

	if (ast_strlen_zero(a->argv[2]) || ast_strlen_zero(a->argv[3]))
		return CLI_SHOWUSAGE;

	/* ugly, can be removed when CLI entries have ast_module pointers */
	ast_module_ref(ast_module_info->self);

	if (!strcasecmp("application", a->argv[3])) {
		res = orig_app(a->fd, a->argv[2], a->argv[4], a->argv[5]);	
	} else if (!strcasecmp("extension", a->argv[3])) {
		res = orig_exten(a->fd, a->argv[2], a->argv[4]);
	} else {
		ast_log(LOG_WARNING, "else");
		res = CLI_SHOWUSAGE;
	}

	ast_module_unref(ast_module_info->self);

	return res;
}
static void bridge_features_limits_dtor(void *vdoomed)
{
	struct ast_bridge_features_limits *doomed = vdoomed;

	ast_bridge_features_limits_destroy(doomed);
	ast_module_unref(ast_module_info->self);
}
예제 #3
0
파일: timing.c 프로젝트: aderbas/asterisk
void ast_timer_close(struct ast_timer *handle)
{
	handle->holder->iface->timer_close(handle->fd);
	handle->fd = -1;
	ast_module_unref(handle->holder->mod);
	ast_free(handle);
}
예제 #4
0
파일: res_ari.c 프로젝트: popsodav/asterisk
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
{
    RAII_VAR(struct stasis_rest_handlers *, new_handler, NULL, ao2_cleanup);
    size_t size, i, j;

    ast_assert(root_handler != NULL);

    ast_mutex_lock(&root_handler_lock);
    size = sizeof(*new_handler) +
           root_handler->num_children * sizeof(handler);

    new_handler = ao2_alloc(size, NULL);
    if (!new_handler) {
        return -1;
    }
    memcpy(new_handler, root_handler, sizeof(*new_handler));

    for (i = 0, j = 0; i < root_handler->num_children; ++i) {
        if (root_handler->children[i] == handler) {
            ast_module_unref(ast_module_info->self);
            continue;
        }
        new_handler->children[j++] = root_handler->children[i];
    }
    new_handler->num_children = j;

    ao2_cleanup(root_handler);
    ao2_ref(new_handler, +1);
    root_handler = new_handler;
    ast_mutex_unlock(&root_handler_lock);
    return 0;
}
예제 #5
0
파일: codec.c 프로젝트: GGGO/asterisk
static void codec_dtor(void *obj)
{
	struct ast_codec *codec;

	codec = obj;

	ast_module_unref(codec->mod);
}
예제 #6
0
void csel_destroy (struct csel *cs)
{
	ast_mutex_destroy(&cs->lock);
	cs->m->destroy(cs);
	free(cs);
	
	ast_module_unref(ast_module_info->self);
}
예제 #7
0
/*! Datastore destroy audiohook callback */
static void destroy_callback(void *data)
{
	struct mute_information *mute = data;

	/* Destroy the audiohook, and destroy ourselves */
	ast_audiohook_destroy(&mute->audiohook);
	ast_free(mute);
	ast_module_unref(ast_module_info->self);
}
static int bridge_builtin_set_limits(struct ast_bridge_features *features,
	struct ast_bridge_features_limits *limits,
	enum ast_bridge_hook_remove_flags remove_flags)
{
	RAII_VAR(struct ast_bridge_features_limits *, feature_limits, NULL, ao2_cleanup);

	if (!limits->duration) {
		return -1;
	}

	/* Create limits hook_pvt data. */
	ast_module_ref(ast_module_info->self);
	feature_limits = ao2_alloc_options(sizeof(*feature_limits),
		bridge_features_limits_dtor, AO2_ALLOC_OPT_LOCK_NOLOCK);
	if (!feature_limits) {
		ast_module_unref(ast_module_info->self);
		return -1;
	}
	if (ast_bridge_features_limits_construct(feature_limits)) {
		return -1;
	}
	bridge_features_limits_copy(feature_limits, limits);
	feature_limits->quitting_time = ast_tvadd(ast_tvnow(),
		ast_samp2tv(feature_limits->duration, 1000));

	/* Install limit hooks. */
	ao2_ref(feature_limits, +1);
	if (ast_bridge_interval_hook(features, AST_BRIDGE_HOOK_TIMER_OPTION_MEDIA,
		feature_limits->duration,
		bridge_features_duration_callback, feature_limits, __ao2_cleanup, remove_flags)) {
		ast_log(LOG_ERROR, "Failed to schedule the duration limiter to the bridge channel.\n");
		ao2_ref(feature_limits, -1);
		return -1;
	}
	if (!ast_strlen_zero(feature_limits->connect_sound)) {
		ao2_ref(feature_limits, +1);
		if (ast_bridge_interval_hook(features, AST_BRIDGE_HOOK_TIMER_OPTION_MEDIA, 1,
			bridge_features_connect_callback, feature_limits, __ao2_cleanup, remove_flags)) {
			ast_log(LOG_WARNING, "Failed to schedule connect sound to the bridge channel.\n");
			ao2_ref(feature_limits, -1);
		}
	}
	if (feature_limits->warning && feature_limits->warning < feature_limits->duration) {
		ao2_ref(feature_limits, +1);
		if (ast_bridge_interval_hook(features, AST_BRIDGE_HOOK_TIMER_OPTION_MEDIA,
			feature_limits->duration - feature_limits->warning,
			bridge_features_warning_callback, feature_limits, __ao2_cleanup, remove_flags)) {
			ast_log(LOG_WARNING, "Failed to schedule warning sound playback to the bridge channel.\n");
			ao2_ref(feature_limits, -1);
		}
	}

	return 0;
}
예제 #9
0
void* ooh323c_call_thread(void* dummy)
{
 struct callthread* mycthread = (struct callthread *)dummy;
 struct pollfd pfds[1];
 char c;
 int res = 0;

 do {

 	ooMonitorCallChannels((ooCallData*)mycthread->call);
	mycthread->call = NULL;
	mycthread->prev = NULL;
	mycthread->inUse = FALSE;

	ast_mutex_lock(&callThreadsLock);
	mycthread->next = callThreads;
	callThreads = mycthread;
	if (mycthread->next) mycthread->next->prev = mycthread;
	ast_mutex_unlock(&callThreadsLock);

	pfds[0].fd = mycthread->thePipe[0];
	pfds[0].events = POLLIN;
	ooSocketPoll(pfds, 1, SEC_TO_HOLD_THREAD * 1000);
	if (ooPDRead(pfds, 1, mycthread->thePipe[0]))
		res = read(mycthread->thePipe[0], &c, 1);

 	ast_mutex_lock(&callThreadsLock);
	ast_mutex_lock(&mycthread->lock);
 	if (mycthread->prev)
		mycthread->prev->next = mycthread->next;
 	else
		callThreads = mycthread->next;
 	if (mycthread->next)
		mycthread->next->prev = mycthread->prev;
	ast_mutex_unlock(&mycthread->lock);
 	ast_mutex_unlock(&callThreadsLock);

 } while (mycthread->call != NULL && res >= 0);

 
 ast_mutex_destroy(&mycthread->lock);

 close(mycthread->thePipe[0]);
 close(mycthread->thePipe[1]);
 ast_free(mycthread);
 ast_module_unref(myself);
 ast_update_use_count();
 return NULL;
}
예제 #10
0
static void hook_datastore_destroy_callback(void *data)
{
	struct hook_state *state = data;

	ast_audiohook_lock(&state->audiohook);
	ast_audiohook_detach(&state->audiohook);
	ast_audiohook_unlock(&state->audiohook);
	ast_audiohook_destroy(&state->audiohook);

	ast_free(state->context);
	ast_free(state->exten);
	ast_free(state);

	ast_module_unref(ast_module_info->self);
}
예제 #11
0
int ast_datastore_free(struct ast_datastore *datastore)
{
	int res = 0;

	/* Using the destroy function (if present) destroy the data */
	if (datastore->info->destroy != NULL && datastore->data != NULL) {
		datastore->info->destroy(datastore->data);
		datastore->data = NULL;
	}

	/* Free allocated UID memory */
	if (datastore->uid != NULL) {
		ast_free((void *) datastore->uid);
		datastore->uid = NULL;
	}

	ast_module_unref(datastore->mod);

	/* Finally free memory used by ourselves */
	ast_free(datastore);

	return res;
}
예제 #12
0
파일: res_ari.c 프로젝트: litnimax/asterisk
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
{
	struct stasis_rest_handlers *new_handler;
	size_t size;
	size_t i;
	size_t j;

	ast_assert(root_handler != NULL);

	ast_mutex_lock(&root_handler_lock);
	size = sizeof(*new_handler) + root_handler->num_children * sizeof(handler);

	new_handler = ao2_alloc(size, NULL);
	if (!new_handler) {
		ast_mutex_unlock(&root_handler_lock);
		return -1;
	}

	/* Create replacement root_handler less the handler to remove. */
	memcpy(new_handler, root_handler, sizeof(*new_handler));
	for (i = 0, j = 0; i < root_handler->num_children; ++i) {
		if (root_handler->children[i] == handler) {
			ast_module_unref(ast_module_info->self);
			continue;
		}
		new_handler->children[j++] = root_handler->children[i];
	}
	new_handler->num_children = j;

	/* Replace the old root_handler with the new. */
	ao2_cleanup(root_handler);
	root_handler = new_handler;

	ast_mutex_unlock(&root_handler_lock);
	return 0;
}
예제 #13
0
/*! 
 * \brief Convert a file from one format to another 
 * \param e CLI entry
 * \param cmd command number
 * \param a list of cli arguments
 * \retval CLI_SUCCESS on success.
 * \retval CLI_SHOWUSAGE or CLI_FAILURE on failure.
*/
static char *handle_cli_file_convert(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
	char *ret = CLI_FAILURE;
	struct ast_filestream *fs_in = NULL, *fs_out = NULL;
	struct ast_frame *f;
	struct timeval start;
	int cost;
	char *file_in = NULL, *file_out = NULL;
	char *name_in, *ext_in, *name_out, *ext_out;

	switch (cmd) {
	case CLI_INIT:
		e->command = "file convert";
		e->usage =
			"Usage: file convert <file_in> <file_out>\n"
			"       Convert from file_in to file_out. If an absolute path\n"
			"       is not given, the default Asterisk sounds directory\n"
			"       will be used.\n\n"
			"       Example:\n"
			"           file convert tt-weasels.gsm tt-weasels.ulaw\n";
		return NULL;
	case CLI_GENERATE:
		return NULL;
	}
	
	/* ugly, can be removed when CLI entries have ast_module pointers */
	ast_module_ref(ast_module_info->self);

	if (a->argc != 4 || ast_strlen_zero(a->argv[2]) || ast_strlen_zero(a->argv[3])) {
		ret = CLI_SHOWUSAGE;
		goto fail_out;	
	}

	file_in = ast_strdupa(a->argv[2]);
	file_out = ast_strdupa(a->argv[3]);

	if (split_ext(file_in, &name_in, &ext_in)) {
		ast_cli(a->fd, "'%s' is an invalid filename!\n", a->argv[2]);
		goto fail_out;
	}
	if (!(fs_in = ast_readfile(name_in, ext_in, NULL, O_RDONLY, 0, 0))) {
		ast_cli(a->fd, "Unable to open input file: %s\n", a->argv[2]);
		goto fail_out;
	}
	
	if (split_ext(file_out, &name_out, &ext_out)) {
		ast_cli(a->fd, "'%s' is an invalid filename!\n", a->argv[3]);
		goto fail_out;
	}
	if (!(fs_out = ast_writefile(name_out, ext_out, NULL, O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
		ast_cli(a->fd, "Unable to open output file: %s\n", a->argv[3]);
		goto fail_out;
	}

	start = ast_tvnow();
	
	while ((f = ast_readframe(fs_in))) {
		if (ast_writestream(fs_out, f)) {
			ast_frfree(f);
			ast_cli(a->fd, "Failed to convert %s.%s to %s.%s!\n", name_in, ext_in, name_out, ext_out);
			goto fail_out;
		}
		ast_frfree(f);
	}

	cost = ast_tvdiff_ms(ast_tvnow(), start);
	ast_cli(a->fd, "Converted %s.%s to %s.%s in %dms\n", name_in, ext_in, name_out, ext_out, cost);
	ret = CLI_SUCCESS;

fail_out:
	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;
}
예제 #14
0
static void websocket_server_dtor(void *obj)
{
	websocket_server_internal_dtor(obj);
	ast_module_unref(ast_module_info->self);
}
예제 #15
0
void ast_mwi_external_unref(void)
{
	ast_module_unref(ast_module_info->self);
}