51 response, 500,
"Internal Server Error",
52 "Message bus not initialized");
70 while ((obj = ao2_iterator_next(&i))) {
100 "No Endpoints found - invalid tech %s", args->
tech);
108 response, 500,
"Internal Server Error",
109 "Message bus not initialized");
127 while ((obj = ao2_iterator_next(&i))) {
133 if (strcasecmp(args->
tech, snapshot->
tech) != 0) {
138 if (!json_endpoint) {
143 json, json_endpoint);
164 "Endpoint not found");
177 static void send_message(
const char *to,
const char *from,
const char *body,
struct ast_variable *variables,
struct ast_ari_response *response)
183 if (ast_strlen_zero(to)) {
185 "To must be specified");
198 if (!ast_strlen_zero(body)) {
202 for (current = variables; current; current = current->
next) {
214 "Endpoint not found");
245 "Only string values in the 'variables' object allowed");
251 ast_log(AST_LOG_ERROR,
"Unable to convert 'variables' in JSON body to Asterisk variables\n");
262 if (args->variables) {
268 && json_to_ast_variables(response, json_variables, &variables)) {
273 send_message(args->
to, args->
from, args->
body, variables, response);
290 "Endpoint not found");
295 if (args->variables) {
301 && json_to_ast_variables(response, json_variables, &variables)) {
308 send_message(msg_to, args->
from, args->
body, variables, response);
312 static void send_refer(
const char *to,
const char *from,
const char *refer_to,
int to_self,
struct ast_variable *variables,
struct ast_ari_response *response)
318 if (ast_strlen_zero(to)) {
320 "To must be specified");
333 if (!ast_strlen_zero(from)) {
336 if (!ast_strlen_zero(refer_to)) {
340 for (current = variables; current; current = current->
next) {
352 "Endpoint not found");
361 static int parse_refer_json(
struct ast_json *body,
365 const char *known_variables[] = {
"display_name" };
378 err = json_to_ast_variables(response, json_variable, variables);
384 for (i = 0; i <
sizeof(known_variables) /
sizeof(*known_variables); ++i) {
386 if (json_variable &&
ast_json_typeof(json_variable) == AST_JSON_STRING) {
388 new_var = ast_variable_new(known_variables[i], value,
"");
390 ast_variable_list_append(variables, new_var);
406 if (parse_refer_json(args->
variables, response, &variables)) {
427 "Endpoint not found");
434 if (parse_refer_json(args->
variables, response, &variables)) {
int ast_ari_endpoints_send_message_parse_body(struct ast_json *body, struct ast_ari_endpoints_send_message_args *args)
Body parsing function for /endpoints/sendMessage.
struct ast_variable * next
Out-of-call refer support.
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Asterisk main include file. File version handling, generic pbx functions.
int ast_refer_set_var_outbound(struct ast_refer *refer, const char *name, const char *value)
Set a variable on the refer being sent to a refer tech directly.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
int ast_msg_set_body(struct ast_msg *msg, const char *fmt,...)
Set the 'body' text of a message (in UTF-8)
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
struct stasis_message_type * ast_endpoint_snapshot_type(void)
Message type for ast_endpoint_snapshot.
struct ast_endpoint_snapshot * ast_endpoint_latest_snapshot(const char *tech, const char *resource)
Retrieve the most recent snapshot for the endpoint with the given name.
struct ast_msg * ast_msg_alloc(void)
Allocate a message.
Structure for variables, used for configurations and for channel variables.
void ast_ari_endpoints_refer(struct ast_variable *headers, struct ast_ari_endpoints_refer_args *args, struct ast_ari_response *response)
Refer an endpoint or technology URI to some technology URI or endpoint.
int ast_refer_set_to_self(struct ast_refer *refer, int val)
Set the 'to_self' value of a refer.
int ast_ari_endpoints_refer_parse_body(struct ast_json *body, struct ast_ari_endpoints_refer_args *args)
Body parsing function for /endpoints/refer.
void ast_ari_endpoints_get(struct ast_variable *headers, struct ast_ari_endpoints_get_args *args, struct ast_ari_response *response)
Details for an endpoint.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
struct ast_endpoint * ast_endpoint_find_by_id(const char *id)
Finds the endpoint with the given tech[/resource] id.
struct ao2_container * stasis_cache_dump(struct stasis_cache *cache, struct stasis_message_type *type)
Dump cached items to a subscription for the ast_eid_default entity.
Out-of-call text message support.
void ast_ari_endpoints_refer_to_endpoint(struct ast_variable *headers, struct ast_ari_endpoints_refer_to_endpoint_args *args, struct ast_ari_response *response)
Refer an endpoint or technology URI to some technology URI or endpoint.
void ast_ari_response_alloc_failed(struct ast_ari_response *response)
Fill in response with a 500 message for allocation failures.
int ast_msg_set_to(struct ast_msg *msg, const char *fmt,...)
Set the 'to' URI of a message.
int ast_ari_endpoints_send_message_to_endpoint_parse_body(struct ast_json *body, struct ast_ari_endpoints_send_message_to_endpoint_args *args)
Body parsing function for /endpoints/{tech}/{resource}/sendMessage.
int ast_msg_send(struct ast_msg *msg, const char *to, const char *from)
Send a msg directly to an endpoint.
int ast_refer_send(struct ast_refer *refer)
Send a refer directly to an endpoint.
struct ast_json * ast_json_null(void)
Get the JSON null value.
Conversion failed because invalid value type supplied.
int ast_refer_set_refer_to(struct ast_refer *refer, const char *fmt,...)
Set the 'refer_to' URI of a refer.
void ast_ari_endpoints_list(struct ast_variable *headers, struct ast_ari_endpoints_list_args *args, struct ast_ari_response *response)
List all endpoints.
General Asterisk PBX channel definitions.
struct ast_json * variables
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
int ast_refer_set_to(struct ast_refer *refer, const char *fmt,...)
Set the 'to' URI of a refer.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
static force_inline char * ast_str_to_lower(char *str)
Convert a string to all lower-case.
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
A snapshot of an endpoint's state.
void ast_ari_endpoints_list_by_tech(struct ast_variable *headers, struct ast_ari_endpoints_list_by_tech_args *args, struct ast_ari_response *response)
List available endoints for a given endpoint technology.
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
struct stasis_message_sanitizer * stasis_app_get_sanitizer(void)
Get the Stasis message sanitizer for app_stasis applications.
int ast_refer_set_from(struct ast_refer *refer, const char *fmt,...)
Set the 'from' URI of a refer.
int ast_ari_endpoints_refer_to_endpoint_parse_body(struct ast_json *body, struct ast_ari_endpoints_refer_to_endpoint_args *args)
Body parsing function for /endpoints/{tech}/{resource}/refer.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
const ast_string_field tech
enum ast_json_to_ast_vars_code ast_json_to_ast_variables(struct ast_json *json_variables, struct ast_variable **variables)
Convert a ast_json list of key/value pair tuples into a ast_variable list.
Conversion failed because of allocation failure. (Out Of Memory)
const char * response_text
void ast_ari_response_error(struct ast_ari_response *response, int response_code, const char *response_text, const char *message_fmt,...)
Fill in an error ast_ari_response.
struct ast_json * variables
enum ast_json_type ast_json_typeof(const struct ast_json *value)
Get the type of value.
struct ast_json * message
void ast_ari_endpoints_send_message_to_endpoint(struct ast_variable *headers, struct ast_ari_endpoints_send_message_to_endpoint_args *args, struct ast_ari_response *response)
Send a message to some endpoint in a technology.
int ast_msg_set_from(struct ast_msg *msg, const char *fmt,...)
Set the 'from' URI of a message.
void ast_ari_endpoints_send_message(struct ast_variable *headers, struct ast_ari_endpoints_send_message_args *args, struct ast_ari_response *response)
Send a message to some technology URI or endpoint.
Generated file - declares stubs to be implemented in res/ari/resource_endpoints.c.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
int ast_msg_set_var_outbound(struct ast_msg *msg, const char *name, const char *value)
Set a variable on the message being sent to a message tech directly.
struct ast_refer * ast_refer_destroy(struct ast_refer *refer)
Destroy an ast_refer.
Abstract JSON element (object, array, string, int, ...).
Stasis Application API. See Stasis Application API for detailed documentation.
static struct sorcery_test_caching cache
Global scope caching structure for testing.
struct ast_msg * ast_msg_destroy(struct ast_msg *msg)
Destroy an ast_msg.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
ast_json_to_ast_vars_code
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
struct ast_json * ast_endpoint_snapshot_to_json(const struct ast_endpoint_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_endpoint_snapshot.
struct ast_refer * ast_refer_alloc(void)
Allocate a refer.
struct stasis_cache * ast_endpoint_cache(void)
Backend cache for ast_endpoint_topic_all_cached().