Exemplo n.º 1
0
struct ast_json *ast_json_dialplan_cep(const char *context, const char *exten, int priority)
{
	return ast_json_pack("{s: o, s: o, s: o}",
			     "context", context ? ast_json_string_create(context) : ast_json_null(),
			     "exten", exten ? ast_json_string_create(exten) : ast_json_null(),
			     "priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null());
}
Exemplo n.º 2
0
struct stasis_message *ast_endpoint_blob_create(struct ast_endpoint *endpoint,
	struct stasis_message_type *type, struct ast_json *blob)
{
	RAII_VAR(struct ast_endpoint_blob *, obj, NULL, ao2_cleanup);
	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);

	if (!type) {
		return NULL;
	}
	if (!blob) {
		blob = ast_json_null();
	}

	if (!(obj = ao2_alloc(sizeof(*obj), endpoint_blob_dtor))) {
		return NULL;
	}

	if (endpoint) {
		if (!(obj->snapshot = ast_endpoint_snapshot_create(endpoint))) {
			return NULL;
		}
	}

	obj->blob = ast_json_ref(blob);

	if (!(msg = stasis_message_create(type, obj))) {
		return NULL;
	}

	ao2_ref(msg, +1);
	return msg;
}
Exemplo n.º 3
0
static struct stasis_message *create_channel_blob_message(struct ast_channel_snapshot *snapshot,
		struct stasis_message_type *type,
		struct ast_json *blob)
{
	struct stasis_message *msg;
	struct ast_channel_blob *obj;

	obj = ao2_alloc(sizeof(*obj), channel_blob_dtor);
	if (!obj) {
		return NULL;
	}

	if (snapshot) {
		obj->snapshot = snapshot;
		ao2_ref(obj->snapshot, +1);
	}
	if (!blob) {
		blob = ast_json_null();
	}
	obj->blob = ast_json_ref(blob);

	msg = stasis_message_create(type, obj);
	ao2_cleanup(obj);
	return msg;
}
Exemplo n.º 4
0
void ast_ari_recordings_get_stored_file(struct ast_tcptls_session_instance *ser,
	struct ast_variable *headers, struct ast_ari_recordings_get_stored_file_args *args,
	struct ast_ari_response *response)
{
	RAII_VAR(struct stasis_app_stored_recording *, recording,
		stasis_app_stored_recording_find_by_name(args->recording_name),
		ao2_cleanup);
	static const char *format_type_names[AST_MEDIA_TYPE_TEXT + 1] = {
		[AST_MEDIA_TYPE_UNKNOWN] = "binary",
		[AST_MEDIA_TYPE_AUDIO] = "audio",
		[AST_MEDIA_TYPE_VIDEO] = "video",
		[AST_MEDIA_TYPE_IMAGE] = "image",
		[AST_MEDIA_TYPE_TEXT] = "text",
	};
	struct ast_format *format;

	response->message = ast_json_null();

	if (!recording) {
		ast_ari_response_error(response, 404, "Not Found",
			"Recording not found");
		return;
	}

	format = ast_get_format_for_file_ext(stasis_app_stored_recording_get_extension(recording));
	if (!format) {
		ast_ari_response_error(response, 500, "Internal Server Error",
			"Format specified by recording not available or loaded");
		return;
	}

	response->fd = open(stasis_app_stored_recording_get_filename(recording), O_RDONLY);
	if (response->fd < 0) {
		ast_ari_response_error(response, 403, "Forbidden",
			"Recording could not be opened");
		return;
	}

	ast_str_append(&response->headers, 0, "Content-Type: %s/%s\r\n",
		format_type_names[ast_format_get_type(format)],
		stasis_app_stored_recording_get_extension(recording));
	ast_ari_response_ok(response, ast_json_null());
}
Exemplo n.º 5
0
void ast_channel_publish_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
{
	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);

	if (!blob) {
		blob = ast_json_null();
	}

	message = ast_channel_blob_create(chan, type, blob);
	if (message) {
		stasis_publish(ast_channel_topic(chan), message);
	}
}
Exemplo n.º 6
0
static int send_call_pickup_stasis_message(struct ast_channel *picking_up, struct ast_channel_snapshot *chan, struct ast_channel_snapshot *target)
{
	RAII_VAR(struct ast_multi_channel_blob *, pickup_payload, NULL, ao2_cleanup);
	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);

	if (!(pickup_payload = ast_multi_channel_blob_create(ast_json_null()))) {
		return -1;
	}

	ast_multi_channel_blob_add_channel(pickup_payload, "channel", chan);
	ast_multi_channel_blob_add_channel(pickup_payload, "target", target);

	if (!(msg = stasis_message_create(ast_call_pickup_type(), pickup_payload))) {
		return -1;
	}

	stasis_publish(ast_channel_topic(picking_up), msg);
	return 0;
}
Exemplo n.º 7
0
/*! \internal
 * \brief Publish the chanspy message over Stasis-Core
 * \param spyer The channel doing the spying
 * \param spyee Who is being spied upon
 * \start start If non-zero, the spying is starting. Otherwise, the spyer is
 * finishing
 */
static void publish_chanspy_message(struct ast_channel *spyer,
									struct ast_channel *spyee,
									int start)
{
	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
	RAII_VAR(struct ast_multi_channel_blob *, payload, NULL, ao2_cleanup);
	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);

	if (!spyer) {
		ast_log(AST_LOG_WARNING, "Attempt to publish ChanSpy message for NULL spyer channel\n");
		return;
	}
	blob = ast_json_null();
	if (!blob) {
		return;
	}

	payload = ast_multi_channel_blob_create(blob);
	if (!payload) {
		return;
	}

	if (pack_channel_into_message(spyer, "spyer_channel", payload)) {
		return;
	}

	if (spyee) {
		if (pack_channel_into_message(spyee, "spyee_channel", payload)) {
			return;
		}
	}

	message = stasis_message_create(
			start ? ast_channel_chanspy_start_type(): ast_channel_chanspy_stop_type(),
					payload);
	if (!message) {
		return;
	}
	stasis_publish(ast_channel_topic(spyer), message);
}
Exemplo n.º 8
0
/*! \internal
 * \brief Publish the chanspy message over Stasis-Core
 * \param snoop The snoop structure
 * \start start If non-zero, the spying is starting. Otherwise, the spyer is
 * finishing
 */
static void publish_chanspy_message(struct stasis_app_snoop *snoop, int start)
{
	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
	RAII_VAR(struct ast_multi_channel_blob *, payload, NULL, ao2_cleanup);
	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
	RAII_VAR(struct ast_channel_snapshot *, snoop_snapshot, NULL, ao2_cleanup);
	RAII_VAR(struct ast_channel_snapshot *, spyee_snapshot, NULL, ao2_cleanup);
	struct stasis_message_type *type = start ? ast_channel_chanspy_start_type(): ast_channel_chanspy_stop_type();

	blob = ast_json_null();
	if (!blob || !type) {
		return;
	}

	payload = ast_multi_channel_blob_create(blob);
	if (!payload) {
		return;
	}

	snoop_snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(snoop->chan));
	if (!snoop_snapshot) {
		return;
	}
	ast_multi_channel_blob_add_channel(payload, "spyer_channel", snoop_snapshot);

	spyee_snapshot = ast_channel_snapshot_get_latest(snoop->uniqueid);
	if (spyee_snapshot) {
		ast_multi_channel_blob_add_channel(payload, "spyee_channel", spyee_snapshot);
	}

	message = stasis_message_create(type, payload);
	if (!message) {
		return;
	}

	stasis_publish(ast_channel_topic(snoop->chan), message);
}
Exemplo n.º 9
0
void ast_ari_response_no_content(struct ast_ari_response *response)
{
    response->message = ast_json_null();
    response->response_code = 204;
    response->response_text = "No Content";
}
Exemplo n.º 10
0
void ast_ari_response_accepted(struct ast_ari_response *response)
{
	response->message = ast_json_null();
	response->response_code = 202;
	response->response_text = "Accepted";
}