示例#1
0
static int dumpchan_exec(struct ast_channel *chan, const char *data)
{
	struct ast_str *vars = ast_str_thread_get(&ast_str_thread_global_buf, 16);
	char info[2048];
	int level = 0;
	static char *line = "================================================================================";

	if (!ast_strlen_zero(data))
		level = atoi(data);

	if (VERBOSITY_ATLEAST(level)) {
		serialize_showchan(chan, info, sizeof(info));
		pbx_builtin_serialize_variables(chan, &vars);
		ast_verb(level, "\n"
			"Dumping Info For Channel: %s:\n"
			"%s\n"
			"Info:\n"
			"%s\n"
			"Variables:\n"
			"%s%s\n", ast_channel_name(chan), line, info, ast_str_buffer(vars), line);
	}

	return 0;
}
示例#2
0
static int timeout_write(struct ast_channel *chan, const char *cmd, char *data,
			 const char *value)
{
	double x = 0.0;
	long sec = 0L;
	char timestr[64];
	struct ast_tm myt;
	struct timeval when = {0,};
	int res;

	if (!chan)
		return -1;

	if (!data) {
		ast_log(LOG_ERROR, "Must specify type of timeout to set.\n");
		return -1;
	}

	if (!value)
		return -1;

	res = sscanf(value, "%30ld%30lf", &sec, &x);
	if (res == 0 || sec < 0) {
		when.tv_sec = 0;
		when.tv_usec = 0;
	} else if (res == 1) {
		when.tv_sec = sec;
	} else if (res == 2) {
		when.tv_sec = sec;
		when.tv_usec = x * 1000000;
	}

	switch (*data) {
	case 'a':
	case 'A':
		ast_channel_lock(chan);
		ast_channel_setwhentohangup_tv(chan, when);
		ast_channel_unlock(chan);
		if (VERBOSITY_ATLEAST(3)) {
			if (!ast_tvzero(*ast_channel_whentohangup(chan))) {
				when = ast_tvadd(when, ast_tvnow());
				ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S.%3q %Z",
					ast_localtime(&when, &myt, NULL));
				ast_verb(3, "Channel will hangup at %s.\n", timestr);
			} else {
				ast_verb(3, "Channel hangup cancelled.\n");
			}
		}
		break;

	case 'r':
	case 'R':
		if (ast_channel_pbx(chan)) {
			ast_channel_pbx(chan)->rtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000;
			ast_verb(3, "Response timeout set to %.3f\n", ast_channel_pbx(chan)->rtimeoutms / 1000.0);
		}
		break;

	case 'd':
	case 'D':
		if (ast_channel_pbx(chan)) {
			ast_channel_pbx(chan)->dtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000;
			ast_verb(3, "Digit timeout set to %.3f\n", ast_channel_pbx(chan)->dtimeoutms / 1000.0);
		}
		break;

	default:
		ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
		break;
	}

	return 0;
}