Пример #1
0
static char *assign_uuid(const pj_str_t *call_id, const pj_str_t *local_tag, const pj_str_t *remote_tag)
{
	RAII_VAR(struct ast_sip_session *, session, NULL, ao2_cleanup);
	pjsip_dialog *dlg;
	char *uuid = NULL;
	enum hep_uuid_type uuid_type = hepv3_get_uuid_type();

	if ((uuid_type == HEP_UUID_TYPE_CHANNEL)
		&& (dlg = pjsip_ua_find_dialog(call_id, local_tag, remote_tag, PJ_FALSE))
	    && (session = ast_sip_dialog_get_session(dlg))
	    && (session->channel)) {

		uuid = ast_strdup(ast_channel_name(session->channel));
	}

	/* If we couldn't get the channel or we never wanted it, default to the call-id */
	if (!uuid) {

		uuid = ast_malloc(pj_strlen(call_id) + 1);
		if (uuid) {
			ast_copy_pj_str(uuid, call_id, pj_strlen(call_id) + 1);
		}
	}

	return uuid;
}
Пример #2
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;
}