Exemplo n.º 1
0
static char *assign_uuid(struct ast_json *json_channel)
{
	const char *channel_name = ast_json_string_get(ast_json_object_get(json_channel, "name"));
	enum hep_uuid_type uuid_type = hepv3_get_uuid_type();
	char *uuid = NULL;

	if (!channel_name) {
		return NULL;
	}

	if (uuid_type == HEP_UUID_TYPE_CALL_ID) {
		struct ast_channel *chan = NULL;
		char buf[128];

		if (ast_begins_with(channel_name, "PJSIP")) {
			chan = ast_channel_get_by_name(channel_name);

			if (chan && !ast_func_read(chan, "CHANNEL(pjsip,call-id)", buf, sizeof(buf))) {
				uuid = ast_strdup(buf);
			}
		} else if (ast_begins_with(channel_name, "SIP")) {
			chan = ast_channel_get_by_name(channel_name);

			if (chan && !ast_func_read(chan, "SIP_HEADER(call-id)", buf, sizeof(buf))) {
				uuid = ast_strdup(buf);
			}
		}

		ast_channel_cleanup(chan);
	}

	/* If we couldn't get the call-id or didn't want it, just use the channel name */
	if (!uuid) {
		uuid = ast_strdup(channel_name);
	}

	return uuid;
}
Exemplo n.º 2
0
/*!
 * \brief [lua_CFunction] Used to get the value of a variable or dialplan
 * function (for access from lua, don't call directly)
 *
 * The value of the variable or function is returned.  This function is the
 * 'get()' function in the following example as would be seen in
 * extensions.lua.
 *
 * \code
 * channel.variable:get()
 * \endcode
 */
static int lua_get_variable_value(lua_State *L)
{
	struct ast_channel *chan;
	char *value = NULL, *name;
	char *workspace = alloca(LUA_BUF_SIZE);
	int autoservice;

	workspace[0] = '\0';

	if (!lua_istable(L, 1)) {
		lua_pushstring(L, "User probably used '.' instead of ':' for retrieving a channel variable value");
		return lua_error(L);
	}
	
	lua_getfield(L, LUA_REGISTRYINDEX, "channel");
	chan = lua_touserdata(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, 1, "name");
	name = ast_strdupa(lua_tostring(L, -1));
	lua_pop(L, 1);
	
	lua_getfield(L, LUA_REGISTRYINDEX, "autoservice");
	autoservice = lua_toboolean(L, -1);
	lua_pop(L, 1);

	if (autoservice)
		ast_autoservice_stop(chan);
	
	/* if this is a dialplan function then use ast_func_read(), otherwise
	 * use pbx_retrieve_variable() */
	if (!ast_strlen_zero(name) && name[strlen(name) - 1] == ')') {
		value = ast_func_read(chan, name, workspace, LUA_BUF_SIZE) ? NULL : workspace;
	} else {
		pbx_retrieve_variable(chan, name, &value, workspace, LUA_BUF_SIZE, ast_channel_varshead(chan));
	}
	
	if (autoservice)
		ast_autoservice_start(chan);

	if (value) {
		lua_pushstring(L, value);
	} else {
		lua_pushnil(L);
	}

	return 1;
}