Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Functions
resource_endpoints.h File Reference

Generated file - declares stubs to be implemented in res/ari/resource_endpoints.c. More...

#include "asterisk/ari.h"
Include dependency graph for resource_endpoints.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_ari_endpoints_get_args
 
struct  ast_ari_endpoints_list_args
 
struct  ast_ari_endpoints_list_by_tech_args
 
struct  ast_ari_endpoints_refer_args
 
struct  ast_ari_endpoints_refer_to_endpoint_args
 
struct  ast_ari_endpoints_send_message_args
 
struct  ast_ari_endpoints_send_message_to_endpoint_args
 

Functions

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. More...
 
void ast_ari_endpoints_list (struct ast_variable *headers, struct ast_ari_endpoints_list_args *args, struct ast_ari_response *response)
 List all endpoints. More...
 
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. More...
 
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. More...
 
int ast_ari_endpoints_refer_parse_body (struct ast_json *body, struct ast_ari_endpoints_refer_args *args)
 Body parsing function for /endpoints/refer. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

Detailed Description

Generated file - declares stubs to be implemented in res/ari/resource_endpoints.c.

Endpoint resources

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m

Definition in file resource_endpoints.h.

Function Documentation

◆ ast_ari_endpoints_get()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 154 of file resource_endpoints.c.

157{
158 struct ast_json *json;
159 RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
160
161 snapshot = ast_endpoint_latest_snapshot(args->tech, args->resource);
162 if (!snapshot) {
163 ast_ari_response_error(response, 404, "Not Found",
164 "Endpoint not found");
165 return;
166 }
167
169 if (!json) {
171 return;
172 }
173
174 ast_ari_response_ok(response, json);
175}
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.
Definition: res_ari.c:259
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
void ast_ari_response_alloc_failed(struct ast_ari_response *response)
Fill in response with a 500 message for allocation failures.
Definition: res_ari.c:298
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
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.
#define NULL
Definition: resample.c:96
struct stasis_message_sanitizer * stasis_app_get_sanitizer(void)
Get the Stasis message sanitizer for app_stasis applications.
Definition: res_stasis.c:2267
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.
A snapshot of an endpoint's state.
Abstract JSON element (object, array, string, int, ...).
const char * args
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941

References ao2_cleanup, args, ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_response_ok(), ast_endpoint_latest_snapshot(), ast_endpoint_snapshot_to_json(), NULL, RAII_VAR, and stasis_app_get_sanitizer().

Referenced by ast_ari_endpoints_get_cb().

◆ ast_ari_endpoints_list()

void ast_ari_endpoints_list ( struct ast_variable headers,
struct ast_ari_endpoints_list_args args,
struct ast_ari_response response 
)

List all endpoints.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 38 of file resource_endpoints.c.

41{
43 RAII_VAR(struct ao2_container *, snapshots, NULL, ao2_cleanup);
44 RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
45 struct ao2_iterator i;
46 void *obj;
47
49 if (!cache) {
51 response, 500, "Internal Server Error",
52 "Message bus not initialized");
53 return;
54 }
55 ao2_ref(cache, +1);
56
58 if (!snapshots) {
60 return;
61 }
62
63 json = ast_json_array_create();
64 if (!json) {
66 return;
67 }
68
69 i = ao2_iterator_init(snapshots, 0);
70 while ((obj = ao2_iterator_next(&i))) {
71 RAII_VAR(struct stasis_message *, msg, obj, ao2_cleanup);
72 struct ast_endpoint_snapshot *snapshot = stasis_message_data(msg);
73 struct ast_json *json_endpoint = ast_endpoint_snapshot_to_json(snapshot, stasis_app_get_sanitizer());
74
75 if (!json_endpoint || ast_json_array_append(json, json_endpoint)) {
78 return;
79 }
80 }
82
83 ast_ari_response_ok(response, ast_json_ref(json));
84}
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
struct stasis_message_type * ast_endpoint_snapshot_type(void)
Message type for ast_endpoint_snapshot.
struct stasis_cache * ast_endpoint_cache(void)
Backend cache for ast_endpoint_topic_all_cached().
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:378
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:362
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
struct ao2_container * cache
Definition: pbx_realtime.c:77
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.
Definition: stasis_cache.c:736
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
Generic container type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_response_ok(), ast_endpoint_cache(), ast_endpoint_snapshot_to_json(), ast_endpoint_snapshot_type(), ast_json_array_append(), ast_json_array_create(), ast_json_ref(), ast_json_unref(), cache, NULL, RAII_VAR, stasis_app_get_sanitizer(), stasis_cache_dump(), and stasis_message_data().

Referenced by ast_ari_endpoints_list_cb().

◆ ast_ari_endpoints_list_by_tech()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 86 of file resource_endpoints.c.

89{
91 RAII_VAR(struct ao2_container *, snapshots, NULL, ao2_cleanup);
92 RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
93 struct ast_endpoint *tech_endpoint;
94 struct ao2_iterator i;
95 void *obj;
96
97 tech_endpoint = ast_endpoint_find_by_id(args->tech);
98 if (!tech_endpoint) {
99 ast_ari_response_error(response, 404, "Not Found",
100 "No Endpoints found - invalid tech %s", args->tech);
101 return;
102 }
103 ao2_ref(tech_endpoint, -1);
104
106 if (!cache) {
108 response, 500, "Internal Server Error",
109 "Message bus not initialized");
110 return;
111 }
112 ao2_ref(cache, +1);
113
115 if (!snapshots) {
117 return;
118 }
119
120 json = ast_json_array_create();
121 if (!json) {
123 return;
124 }
125
126 i = ao2_iterator_init(snapshots, 0);
127 while ((obj = ao2_iterator_next(&i))) {
128 RAII_VAR(struct stasis_message *, msg, obj, ao2_cleanup);
129 struct ast_endpoint_snapshot *snapshot = stasis_message_data(msg);
130 struct ast_json *json_endpoint;
131 int r;
132
133 if (strcasecmp(args->tech, snapshot->tech) != 0) {
134 continue;
135 }
136
137 json_endpoint = ast_endpoint_snapshot_to_json(snapshot, stasis_app_get_sanitizer());
138 if (!json_endpoint) {
139 continue;
140 }
141
143 json, json_endpoint);
144 if (r != 0) {
147 return;
148 }
149 }
151 ast_ari_response_ok(response, ast_json_ref(json));
152}
struct ast_endpoint * ast_endpoint_find_by_id(const char *id)
Finds the endpoint with the given tech[/resource] id.
const ast_string_field tech

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, args, ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_response_ok(), ast_endpoint_cache(), ast_endpoint_find_by_id(), ast_endpoint_snapshot_to_json(), ast_endpoint_snapshot_type(), ast_json_array_append(), ast_json_array_create(), ast_json_ref(), ast_json_unref(), cache, NULL, RAII_VAR, stasis_app_get_sanitizer(), stasis_cache_dump(), stasis_message_data(), and ast_endpoint_snapshot::tech.

Referenced by ast_ari_endpoints_list_by_tech_cb().

◆ ast_ari_endpoints_refer()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 398 of file resource_endpoints.c.

401{
402 struct ast_variable *variables = NULL;
403
405
406 if (parse_refer_json(args->variables, response, &variables)) {
407 return;
408 }
409
410 send_refer(args->to, args->from, args->refer_to, args->to_self, variables, response);
411 ast_variables_destroy(variables);
412}
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1262
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)
static int parse_refer_json(struct ast_json *body, struct ast_ari_response *response, struct ast_variable **variables)
int ast_ari_endpoints_refer_parse_body(struct ast_json *body, struct ast_ari_endpoints_refer_args *args)
Body parsing function for /endpoints/refer.
Structure for variables, used for configurations and for channel variables.

References args, ast_ari_endpoints_refer_parse_body(), ast_variables_destroy(), NULL, parse_refer_json(), and send_refer().

Referenced by ast_ari_endpoints_refer_cb().

◆ ast_ari_endpoints_refer_parse_body()

int ast_ari_endpoints_refer_parse_body ( struct ast_json body,
struct ast_ari_endpoints_refer_args args 
)

Body parsing function for /endpoints/refer.

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 194 of file res_ari_endpoints.c.

197{
198 struct ast_json *field;
199 /* Parse query parameters out of it */
200 field = ast_json_object_get(body, "to");
201 if (field) {
202 args->to = ast_json_string_get(field);
203 }
204 field = ast_json_object_get(body, "from");
205 if (field) {
206 args->from = ast_json_string_get(field);
207 }
208 field = ast_json_object_get(body, "refer_to");
209 if (field) {
210 args->refer_to = ast_json_string_get(field);
211 }
212 field = ast_json_object_get(body, "to_self");
213 if (field) {
214 args->to_self = ast_json_is_true(field);
215 }
216 return 0;
217}
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:283
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:407
int ast_json_is_true(const struct ast_json *value)
Check if value is JSON true.
Definition: json.c:263

References args, ast_json_is_true(), ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_endpoints_refer().

◆ ast_ari_endpoints_refer_to_endpoint()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 414 of file resource_endpoints.c.

417{
418 struct ast_variable *variables = NULL;
419 struct ast_endpoint_snapshot *snapshot;
420 char to[128];
421 char *tech = ast_strdupa(args->tech);
422
423 /* Really, we just want to know if this thing exists */
424 snapshot = ast_endpoint_latest_snapshot(args->tech, args->resource);
425 if (!snapshot) {
426 ast_ari_response_error(response, 404, "Not Found",
427 "Endpoint not found");
428 return;
429 }
430 ao2_ref(snapshot, -1);
431
433
434 if (parse_refer_json(args->variables, response, &variables)) {
435 return;
436 }
437
438 snprintf(to, sizeof(to), "%s:%s", ast_str_to_lower(tech), args->resource);
439
440 send_refer(to, args->from, args->refer_to, args->to_self, variables, response);
441 ast_variables_destroy(variables);
442}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
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.
static force_inline char * ast_str_to_lower(char *str)
Convert a string to all lower-case.
Definition: strings.h:1321

References ao2_ref, args, ast_ari_endpoints_refer_to_endpoint_parse_body(), ast_ari_response_error(), ast_endpoint_latest_snapshot(), ast_str_to_lower(), ast_strdupa, ast_variables_destroy(), NULL, parse_refer_json(), send_refer(), and ast_endpoint_snapshot::tech.

Referenced by ast_ari_endpoints_refer_to_endpoint_cb().

◆ ast_ari_endpoints_refer_to_endpoint_parse_body()

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.

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 505 of file res_ari_endpoints.c.

508{
509 struct ast_json *field;
510 /* Parse query parameters out of it */
511 field = ast_json_object_get(body, "from");
512 if (field) {
513 args->from = ast_json_string_get(field);
514 }
515 field = ast_json_object_get(body, "refer_to");
516 if (field) {
517 args->refer_to = ast_json_string_get(field);
518 }
519 field = ast_json_object_get(body, "to_self");
520 if (field) {
521 args->to_self = ast_json_is_true(field);
522 }
523 return 0;
524}

References args, ast_json_is_true(), ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_endpoints_refer_to_endpoint().

◆ ast_ari_endpoints_send_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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 256 of file resource_endpoints.c.

259{
260 struct ast_variable *variables = NULL;
261
262 if (args->variables) {
263 struct ast_json *json_variables;
264
266 json_variables = ast_json_object_get(args->variables, "variables");
267 if (json_variables
268 && json_to_ast_variables(response, json_variables, &variables)) {
269 return;
270 }
271 }
272
273 send_message(args->to, args->from, args->body, variables, response);
274 ast_variables_destroy(variables);
275}
static int json_to_ast_variables(struct ast_ari_response *response, struct ast_json *json_variables, struct ast_variable **variables)
static void send_message(const char *to, const char *from, const char *body, struct ast_variable *variables, struct ast_ari_response *response)
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.

References args, ast_ari_endpoints_send_message_parse_body(), ast_json_object_get(), ast_variables_destroy(), json_to_ast_variables(), NULL, and send_message().

Referenced by ast_ari_endpoints_send_message_cb().

◆ ast_ari_endpoints_send_message_parse_body()

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.

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 105 of file res_ari_endpoints.c.

108{
109 struct ast_json *field;
110 /* Parse query parameters out of it */
111 field = ast_json_object_get(body, "to");
112 if (field) {
113 args->to = ast_json_string_get(field);
114 }
115 field = ast_json_object_get(body, "from");
116 if (field) {
117 args->from = ast_json_string_get(field);
118 }
119 field = ast_json_object_get(body, "body");
120 if (field) {
121 args->body = ast_json_string_get(field);
122 }
123 return 0;
124}

References args, ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_endpoints_send_message().

◆ ast_ari_endpoints_send_message_to_endpoint()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 277 of file resource_endpoints.c.

280{
281 struct ast_variable *variables = NULL;
282 struct ast_endpoint_snapshot *snapshot;
283 char msg_to[128];
284 char *tech = ast_strdupa(args->tech);
285
286 /* Really, we just want to know if this thing exists */
287 snapshot = ast_endpoint_latest_snapshot(args->tech, args->resource);
288 if (!snapshot) {
289 ast_ari_response_error(response, 404, "Not Found",
290 "Endpoint not found");
291 return;
292 }
293 ao2_ref(snapshot, -1);
294
295 if (args->variables) {
296 struct ast_json *json_variables;
297
299 json_variables = ast_json_object_get(args->variables, "variables");
300 if (json_variables
301 && json_to_ast_variables(response, json_variables, &variables)) {
302 return;
303 }
304 }
305
306 snprintf(msg_to, sizeof(msg_to), "%s:%s", ast_str_to_lower(tech), args->resource);
307
308 send_message(msg_to, args->from, args->body, variables, response);
309 ast_variables_destroy(variables);
310}
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.

References ao2_ref, args, ast_ari_endpoints_send_message_to_endpoint_parse_body(), ast_ari_response_error(), ast_endpoint_latest_snapshot(), ast_json_object_get(), ast_str_to_lower(), ast_strdupa, ast_variables_destroy(), json_to_ast_variables(), NULL, send_message(), and ast_endpoint_snapshot::tech.

Referenced by ast_ari_endpoints_send_message_to_endpoint_cb().

◆ ast_ari_endpoints_send_message_to_endpoint_parse_body()

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.

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 414 of file res_ari_endpoints.c.

417{
418 struct ast_json *field;
419 /* Parse query parameters out of it */
420 field = ast_json_object_get(body, "from");
421 if (field) {
422 args->from = ast_json_string_get(field);
423 }
424 field = ast_json_object_get(body, "body");
425 if (field) {
426 args->body = ast_json_string_get(field);
427 }
428 return 0;
429}

References args, ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_endpoints_send_message_to_endpoint().