Asterisk - The Open Source Telephony Project GIT-master-b023714
Loading...
Searching...
No Matches
Macros | Functions | Variables
res_ari_endpoints.c File Reference

Endpoint resources. More...

#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/stasis_app.h"
#include "ari/resource_endpoints.h"
Include dependency graph for res_ari_endpoints.c:

Go to the source code of this file.

Macros

#define MAX_VALS   128
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static void ast_ari_endpoints_get_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /endpoints/{tech}/{resource}.
 
static void ast_ari_endpoints_list_by_tech_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /endpoints/{tech}.
 
static void ast_ari_endpoints_list_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /endpoints.
 
static void ast_ari_endpoints_refer_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /endpoints/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.
 
static void ast_ari_endpoints_refer_to_endpoint_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /endpoints/{tech}/{resource}/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.
 
static void ast_ari_endpoints_send_message_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /endpoints/sendMessage.
 
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.
 
static void ast_ari_endpoints_send_message_to_endpoint_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /endpoints/{tech}/{resource}/sendMessage.
 
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.
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "RESTful API module - Endpoint resources" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_ari,res_ari_model,res_stasis", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct stasis_rest_handlers endpoints
 REST handler for /api-docs/endpoints.json.
 
static struct stasis_rest_handlers endpoints_refer
 REST handler for /api-docs/endpoints.json.
 
static struct stasis_rest_handlers endpoints_sendMessage
 REST handler for /api-docs/endpoints.json.
 
static struct stasis_rest_handlers endpoints_tech
 REST handler for /api-docs/endpoints.json.
 
static struct stasis_rest_handlers endpoints_tech_resource
 REST handler for /api-docs/endpoints.json.
 
static struct stasis_rest_handlers endpoints_tech_resource_refer
 REST handler for /api-docs/endpoints.json.
 
static struct stasis_rest_handlers endpoints_tech_resource_sendMessage
 REST handler for /api-docs/endpoints.json.
 

Detailed Description

Endpoint resources.

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

Definition in file res_ari_endpoints.c.

Macro Definition Documentation

◆ MAX_VALS

#define MAX_VALS   128

Definition at line 51 of file res_ari_endpoints.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 695 of file res_ari_endpoints.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 695 of file res_ari_endpoints.c.

◆ ast_ari_endpoints_get_cb()

static void ast_ari_endpoints_get_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /endpoints/{tech}/{resource}.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 359 of file res_ari_endpoints.c.

363{
365 struct ast_variable *i;
366#if defined(AST_DEVMODE)
367 int is_valid;
368 int code;
369#endif /* AST_DEVMODE */
370
371 for (i = path_vars; i; i = i->next) {
372 if (strcmp(i->name, "tech") == 0) {
373 args.tech = (i->value);
374 } else
375 if (strcmp(i->name, "resource") == 0) {
376 args.resource = (i->value);
377 } else
378 {}
379 }
380 ast_ari_endpoints_get(headers, &args, response);
381#if defined(AST_DEVMODE)
382 code = response->response_code;
383
384 switch (code) {
385 case 0: /* Implementation is still a stub, or the code wasn't set */
386 is_valid = response->message == NULL;
387 break;
388 case 500: /* Internal Server Error */
389 case 501: /* Not Implemented */
390 case 400: /* Invalid parameters for sending a message. */
391 case 404: /* Endpoints not found */
392 is_valid = 1;
393 break;
394 default:
395 if (200 <= code && code <= 299) {
396 is_valid = ast_ari_validate_endpoint(
397 response->message);
398 } else {
399 ast_log(LOG_ERROR, "Invalid error response %d for /endpoints/{tech}/{resource}\n", code);
400 is_valid = 0;
401 }
402 }
403
404 if (!is_valid) {
405 ast_log(LOG_ERROR, "Response validation failed for /endpoints/{tech}/{resource}\n");
406 ast_ari_response_error(response, 500,
407 "Internal Server Error", "Response validation failed");
408 }
409#endif /* AST_DEVMODE */
410
411fin: __attribute__((unused))
412 return;
413}
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:212
int ast_ari_validate_endpoint(struct ast_json *json)
Validator for Endpoint.
#define ast_log
Definition astobj2.c:42
#define LOG_ERROR
static struct @519 args
#define NULL
Definition resample.c:96
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.
struct ast_json * message
Definition ari.h:103
int response_code
Definition ari.h:108
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next

References args, ast_ari_endpoints_get(), ast_ari_response_error(), ast_ari_validate_endpoint(), ast_log, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ ast_ari_endpoints_list_by_tech_cb()

static void ast_ari_endpoints_list_by_tech_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /endpoints/{tech}.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 299 of file res_ari_endpoints.c.

303{
305 struct ast_variable *i;
306#if defined(AST_DEVMODE)
307 int is_valid;
308 int code;
309#endif /* AST_DEVMODE */
310
311 for (i = path_vars; i; i = i->next) {
312 if (strcmp(i->name, "tech") == 0) {
313 args.tech = (i->value);
314 } else
315 {}
316 }
317 ast_ari_endpoints_list_by_tech(headers, &args, response);
318#if defined(AST_DEVMODE)
319 code = response->response_code;
320
321 switch (code) {
322 case 0: /* Implementation is still a stub, or the code wasn't set */
323 is_valid = response->message == NULL;
324 break;
325 case 500: /* Internal Server Error */
326 case 501: /* Not Implemented */
327 case 404: /* Endpoints not found */
328 is_valid = 1;
329 break;
330 default:
331 if (200 <= code && code <= 299) {
332 is_valid = ast_ari_validate_list(response->message,
334 } else {
335 ast_log(LOG_ERROR, "Invalid error response %d for /endpoints/{tech}\n", code);
336 is_valid = 0;
337 }
338 }
339
340 if (!is_valid) {
341 ast_log(LOG_ERROR, "Response validation failed for /endpoints/{tech}\n");
342 ast_ari_response_error(response, 500,
343 "Internal Server Error", "Response validation failed");
344 }
345#endif /* AST_DEVMODE */
346
347fin: __attribute__((unused))
348 return;
349}
ari_validator ast_ari_validate_endpoint_fn(void)
Function pointer to ast_ari_validate_endpoint().
int ast_ari_validate_list(struct ast_json *json, int(*fn)(struct ast_json *))
Validator for a Swagger List[]/JSON array.
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.

References args, ast_ari_endpoints_list_by_tech(), ast_ari_response_error(), ast_ari_validate_endpoint_fn(), ast_ari_validate_list(), ast_log, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ ast_ari_endpoints_list_cb()

static void ast_ari_endpoints_list_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /endpoints.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 62 of file res_ari_endpoints.c.

66{
68#if defined(AST_DEVMODE)
69 int is_valid;
70 int code;
71#endif /* AST_DEVMODE */
72
73 ast_ari_endpoints_list(headers, &args, response);
74#if defined(AST_DEVMODE)
75 code = response->response_code;
76
77 switch (code) {
78 case 0: /* Implementation is still a stub, or the code wasn't set */
79 is_valid = response->message == NULL;
80 break;
81 case 500: /* Internal Server Error */
82 case 501: /* Not Implemented */
83 is_valid = 1;
84 break;
85 default:
86 if (200 <= code && code <= 299) {
87 is_valid = ast_ari_validate_list(response->message,
89 } else {
90 ast_log(LOG_ERROR, "Invalid error response %d for /endpoints\n", code);
91 is_valid = 0;
92 }
93 }
94
95 if (!is_valid) {
96 ast_log(LOG_ERROR, "Response validation failed for /endpoints\n");
97 ast_ari_response_error(response, 500,
98 "Internal Server Error", "Response validation failed");
99 }
100#endif /* AST_DEVMODE */
101
102fin: __attribute__((unused))
103 return;
104}
void ast_ari_endpoints_list(struct ast_variable *headers, struct ast_ari_endpoints_list_args *args, struct ast_ari_response *response)
List all endpoints.

References args, ast_ari_endpoints_list(), ast_ari_response_error(), ast_ari_validate_endpoint_fn(), ast_ari_validate_list(), ast_log, LOG_ERROR, ast_ari_response::message, NULL, and ast_ari_response::response_code.

◆ ast_ari_endpoints_refer_cb()

static void ast_ari_endpoints_refer_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /endpoints/refer.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 228 of file res_ari_endpoints.c.

232{
234 struct ast_variable *i;
235#if defined(AST_DEVMODE)
236 int is_valid;
237 int code;
238#endif /* AST_DEVMODE */
239
240 for (i = get_params; i; i = i->next) {
241 if (strcmp(i->name, "to") == 0) {
242 args.to = (i->value);
243 } else
244 if (strcmp(i->name, "from") == 0) {
245 args.from = (i->value);
246 } else
247 if (strcmp(i->name, "refer_to") == 0) {
248 args.refer_to = (i->value);
249 } else
250 if (strcmp(i->name, "to_self") == 0) {
251 args.to_self = ast_true(i->value);
252 } else
253 {}
254 }
255 args.variables = body;
256 ast_ari_endpoints_refer(headers, &args, response);
257#if defined(AST_DEVMODE)
258 code = response->response_code;
259
260 switch (code) {
261 case 0: /* Implementation is still a stub, or the code wasn't set */
262 is_valid = response->message == NULL;
263 break;
264 case 500: /* Internal Server Error */
265 case 501: /* Not Implemented */
266 case 400: /* Invalid parameters for referring. */
267 case 404: /* Endpoint not found */
268 is_valid = 1;
269 break;
270 default:
271 if (200 <= code && code <= 299) {
272 is_valid = ast_ari_validate_void(
273 response->message);
274 } else {
275 ast_log(LOG_ERROR, "Invalid error response %d for /endpoints/refer\n", code);
276 is_valid = 0;
277 }
278 }
279
280 if (!is_valid) {
281 ast_log(LOG_ERROR, "Response validation failed for /endpoints/refer\n");
282 ast_ari_response_error(response, 500,
283 "Internal Server Error", "Response validation failed");
284 }
285#endif /* AST_DEVMODE */
286
287fin: __attribute__((unused))
288 return;
289}
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
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 attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition utils.c:2235

References args, ast_ari_endpoints_refer(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_true(), LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ 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
Abstract JSON element (object, array, string, int, ...).

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_cb()

static void ast_ari_endpoints_refer_to_endpoint_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /endpoints/{tech}/{resource}/refer.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 535 of file res_ari_endpoints.c.

539{
541 struct ast_variable *i;
542#if defined(AST_DEVMODE)
543 int is_valid;
544 int code;
545#endif /* AST_DEVMODE */
546
547 for (i = get_params; i; i = i->next) {
548 if (strcmp(i->name, "from") == 0) {
549 args.from = (i->value);
550 } else
551 if (strcmp(i->name, "refer_to") == 0) {
552 args.refer_to = (i->value);
553 } else
554 if (strcmp(i->name, "to_self") == 0) {
555 args.to_self = ast_true(i->value);
556 } else
557 {}
558 }
559 for (i = path_vars; i; i = i->next) {
560 if (strcmp(i->name, "tech") == 0) {
561 args.tech = (i->value);
562 } else
563 if (strcmp(i->name, "resource") == 0) {
564 args.resource = (i->value);
565 } else
566 {}
567 }
568 args.variables = body;
569 ast_ari_endpoints_refer_to_endpoint(headers, &args, response);
570#if defined(AST_DEVMODE)
571 code = response->response_code;
572
573 switch (code) {
574 case 0: /* Implementation is still a stub, or the code wasn't set */
575 is_valid = response->message == NULL;
576 break;
577 case 500: /* Internal Server Error */
578 case 501: /* Not Implemented */
579 case 400: /* Invalid parameters for referring. */
580 case 404: /* Endpoint not found */
581 is_valid = 1;
582 break;
583 default:
584 if (200 <= code && code <= 299) {
585 is_valid = ast_ari_validate_void(
586 response->message);
587 } else {
588 ast_log(LOG_ERROR, "Invalid error response %d for /endpoints/{tech}/{resource}/refer\n", code);
589 is_valid = 0;
590 }
591 }
592
593 if (!is_valid) {
594 ast_log(LOG_ERROR, "Response validation failed for /endpoints/{tech}/{resource}/refer\n");
595 ast_ari_response_error(response, 500,
596 "Internal Server Error", "Response validation failed");
597 }
598#endif /* AST_DEVMODE */
599
600fin: __attribute__((unused))
601 return;
602}
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.

References args, ast_ari_endpoints_refer_to_endpoint(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_true(), LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ 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_cb()

static void ast_ari_endpoints_send_message_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /endpoints/sendMessage.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 135 of file res_ari_endpoints.c.

139{
141 struct ast_variable *i;
142#if defined(AST_DEVMODE)
143 int is_valid;
144 int code;
145#endif /* AST_DEVMODE */
146
147 for (i = get_params; i; i = i->next) {
148 if (strcmp(i->name, "to") == 0) {
149 args.to = (i->value);
150 } else
151 if (strcmp(i->name, "from") == 0) {
152 args.from = (i->value);
153 } else
154 if (strcmp(i->name, "body") == 0) {
155 args.body = (i->value);
156 } else
157 {}
158 }
159 args.variables = body;
160 ast_ari_endpoints_send_message(headers, &args, response);
161#if defined(AST_DEVMODE)
162 code = response->response_code;
163
164 switch (code) {
165 case 0: /* Implementation is still a stub, or the code wasn't set */
166 is_valid = response->message == NULL;
167 break;
168 case 500: /* Internal Server Error */
169 case 501: /* Not Implemented */
170 case 400: /* Invalid parameters for sending a message. */
171 case 404: /* Endpoint not found */
172 is_valid = 1;
173 break;
174 default:
175 if (200 <= code && code <= 299) {
176 is_valid = ast_ari_validate_void(
177 response->message);
178 } else {
179 ast_log(LOG_ERROR, "Invalid error response %d for /endpoints/sendMessage\n", code);
180 is_valid = 0;
181 }
182 }
183
184 if (!is_valid) {
185 ast_log(LOG_ERROR, "Response validation failed for /endpoints/sendMessage\n");
186 ast_ari_response_error(response, 500,
187 "Internal Server Error", "Response validation failed");
188 }
189#endif /* AST_DEVMODE */
190
191fin: __attribute__((unused))
192 return;
193}
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.

References args, ast_ari_endpoints_send_message(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ 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_cb()

static void ast_ari_endpoints_send_message_to_endpoint_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /endpoints/{tech}/{resource}/sendMessage.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 440 of file res_ari_endpoints.c.

444{
446 struct ast_variable *i;
447#if defined(AST_DEVMODE)
448 int is_valid;
449 int code;
450#endif /* AST_DEVMODE */
451
452 for (i = get_params; i; i = i->next) {
453 if (strcmp(i->name, "from") == 0) {
454 args.from = (i->value);
455 } else
456 if (strcmp(i->name, "body") == 0) {
457 args.body = (i->value);
458 } else
459 {}
460 }
461 for (i = path_vars; i; i = i->next) {
462 if (strcmp(i->name, "tech") == 0) {
463 args.tech = (i->value);
464 } else
465 if (strcmp(i->name, "resource") == 0) {
466 args.resource = (i->value);
467 } else
468 {}
469 }
470 args.variables = body;
472#if defined(AST_DEVMODE)
473 code = response->response_code;
474
475 switch (code) {
476 case 0: /* Implementation is still a stub, or the code wasn't set */
477 is_valid = response->message == NULL;
478 break;
479 case 500: /* Internal Server Error */
480 case 501: /* Not Implemented */
481 case 400: /* Invalid parameters for sending a message. */
482 case 404: /* Endpoint not found */
483 is_valid = 1;
484 break;
485 default:
486 if (200 <= code && code <= 299) {
487 is_valid = ast_ari_validate_void(
488 response->message);
489 } else {
490 ast_log(LOG_ERROR, "Invalid error response %d for /endpoints/{tech}/{resource}/sendMessage\n", code);
491 is_valid = 0;
492 }
493 }
494
495 if (!is_valid) {
496 ast_log(LOG_ERROR, "Response validation failed for /endpoints/{tech}/{resource}/sendMessage\n");
497 ast_ari_response_error(response, 500,
498 "Internal Server Error", "Response validation failed");
499 }
500#endif /* AST_DEVMODE */
501
502fin: __attribute__((unused))
503 return;
504}
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.

References args, ast_ari_endpoints_send_message_to_endpoint(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ 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().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 695 of file res_ari_endpoints.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 676 of file res_ari_endpoints.c.

677{
678 int res = 0;
679
680
682 if (res) {
685 }
686
688}
int ast_ari_add_handler(struct stasis_rest_handlers *handler)
Definition res_ari.c:132
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition module.h:78
static struct stasis_rest_handlers endpoints
REST handler for /api-docs/endpoints.json.
static int unload_module(void)

References ast_ari_add_handler(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, endpoints, and unload_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 670 of file res_ari_endpoints.c.

671{
673 return 0;
674}
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
Definition res_ari.c:155

References ast_ari_remove_handler(), and endpoints.

Referenced by load_module().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "RESTful API module - Endpoint resources" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_ari,res_ari_model,res_stasis", }
static

Definition at line 695 of file res_ari_endpoints.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 695 of file res_ari_endpoints.c.

◆ endpoints

struct stasis_rest_handlers endpoints
static

REST handler for /api-docs/endpoints.json.

Definition at line 661 of file res_ari_endpoints.c.

661 {
662 .path_segment = "endpoints",
663 .callbacks = {
665 },
666 .num_children = 3,
668};
@ AST_HTTP_GET
Definition http.h:60
static void ast_ari_endpoints_list_cb(struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Parameter parsing callback for /endpoints.
static struct stasis_rest_handlers endpoints_sendMessage
REST handler for /api-docs/endpoints.json.
static struct stasis_rest_handlers endpoints_refer
REST handler for /api-docs/endpoints.json.
static struct stasis_rest_handlers endpoints_tech
REST handler for /api-docs/endpoints.json.

Referenced by load_module(), and unload_module().

◆ endpoints_refer

struct stasis_rest_handlers endpoints_refer
static

REST handler for /api-docs/endpoints.json.

Definition at line 614 of file res_ari_endpoints.c.

614 {
615 .path_segment = "refer",
616 .callbacks = {
618 },
619 .num_children = 0,
620 .children = { }
621};
@ AST_HTTP_POST
Definition http.h:61
static void ast_ari_endpoints_refer_cb(struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Parameter parsing callback for /endpoints/refer.

◆ endpoints_sendMessage

struct stasis_rest_handlers endpoints_sendMessage
static

REST handler for /api-docs/endpoints.json.

Definition at line 605 of file res_ari_endpoints.c.

605 {
606 .path_segment = "sendMessage",
607 .callbacks = {
609 },
610 .num_children = 0,
611 .children = { }
612};
@ AST_HTTP_PUT
Definition http.h:63
static void ast_ari_endpoints_send_message_cb(struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Parameter parsing callback for /endpoints/sendMessage.

◆ endpoints_tech

struct stasis_rest_handlers endpoints_tech
static

REST handler for /api-docs/endpoints.json.

Definition at line 651 of file res_ari_endpoints.c.

651 {
652 .path_segment = "tech",
653 .is_wildcard = 1,
654 .callbacks = {
656 },
657 .num_children = 1,
658 .children = { &endpoints_tech_resource, }
659};
static void ast_ari_endpoints_list_by_tech_cb(struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Parameter parsing callback for /endpoints/{tech}.
static struct stasis_rest_handlers endpoints_tech_resource
REST handler for /api-docs/endpoints.json.

◆ endpoints_tech_resource

struct stasis_rest_handlers endpoints_tech_resource
static

REST handler for /api-docs/endpoints.json.

Definition at line 641 of file res_ari_endpoints.c.

641 {
642 .path_segment = "resource",
643 .is_wildcard = 1,
644 .callbacks = {
646 },
647 .num_children = 2,
649};
static struct stasis_rest_handlers endpoints_tech_resource_refer
REST handler for /api-docs/endpoints.json.
static struct stasis_rest_handlers endpoints_tech_resource_sendMessage
REST handler for /api-docs/endpoints.json.
static void ast_ari_endpoints_get_cb(struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Parameter parsing callback for /endpoints/{tech}/{resource}.

◆ endpoints_tech_resource_refer

struct stasis_rest_handlers endpoints_tech_resource_refer
static

REST handler for /api-docs/endpoints.json.

Definition at line 632 of file res_ari_endpoints.c.

632 {
633 .path_segment = "refer",
634 .callbacks = {
636 },
637 .num_children = 0,
638 .children = { }
639};
static void ast_ari_endpoints_refer_to_endpoint_cb(struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Parameter parsing callback for /endpoints/{tech}/{resource}/refer.

◆ endpoints_tech_resource_sendMessage

struct stasis_rest_handlers endpoints_tech_resource_sendMessage
static

REST handler for /api-docs/endpoints.json.

Definition at line 623 of file res_ari_endpoints.c.

623 {
624 .path_segment = "sendMessage",
625 .callbacks = {
627 },
628 .num_children = 0,
629 .children = { }
630};
static void ast_ari_endpoints_send_message_to_endpoint_cb(struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Parameter parsing callback for /endpoints/{tech}/{resource}/sendMessage.