Asterisk - The Open Source Telephony Project  21.4.1
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"

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}. More...
 
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}. More...
 
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. More...
 
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. 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...
 
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. 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...
 
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. 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...
 
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. 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...
 
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 = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "da6642af068ee5e6490c5b1d2cc1d238" , .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.

Function Documentation

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.

References ast_ari_endpoints_get(), ast_ari_response_error(), ast_ari_validate_endpoint(), ast_ari_response::message, ast_variable::name, ast_variable::next, ast_ari_endpoints_get_args::resource, ast_ari_response::response_code, ast_ari_endpoints_get_args::tech, and ast_variable::value.

363 {
364  struct ast_ari_endpoints_get_args args = {};
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 
411 fin: __attribute__((unused))
412  return;
413 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
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.
int response_code
Definition: ari.h:99
int ast_ari_validate_endpoint(struct ast_json *json)
Validator for Endpoint.
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
struct ast_json * message
Definition: ari.h:94
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.

References ast_ari_endpoints_list_by_tech(), ast_ari_response_error(), ast_ari_validate_endpoint_fn(), ast_ari_validate_list(), ast_ari_response::message, ast_variable::name, ast_variable::next, ast_ari_response::response_code, ast_ari_endpoints_list_by_tech_args::tech, and ast_variable::value.

303 {
304  struct ast_ari_endpoints_list_by_tech_args args = {};
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 
347 fin: __attribute__((unused))
348  return;
349 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
int response_code
Definition: ari.h:99
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.
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
struct ast_json * message
Definition: ari.h:94
int ast_ari_validate_list(struct ast_json *json, int(*fn)(struct ast_json *))
Validator for a Swagger List[]/JSON array.
ari_validator ast_ari_validate_endpoint_fn(void)
Function pointer to ast_ari_validate_endpoint().
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.

References ast_ari_endpoints_list(), ast_ari_response_error(), ast_ari_validate_endpoint_fn(), ast_ari_validate_list(), ast_ari_response::message, and ast_ari_response::response_code.

66 {
67  struct ast_ari_endpoints_list_args args = {};
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 
102 fin: __attribute__((unused))
103  return;
104 }
int response_code
Definition: ari.h:99
void ast_ari_endpoints_list(struct ast_variable *headers, struct ast_ari_endpoints_list_args *args, struct ast_ari_response *response)
List all endpoints.
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
struct ast_json * message
Definition: ari.h:94
int ast_ari_validate_list(struct ast_json *json, int(*fn)(struct ast_json *))
Validator for a Swagger List[]/JSON array.
ari_validator ast_ari_validate_endpoint_fn(void)
Function pointer to ast_ari_validate_endpoint().
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.

References ast_ari_endpoints_refer(), ast_ari_response_error(), ast_ari_validate_void(), ast_true(), ast_ari_endpoints_refer_args::from, ast_ari_response::message, ast_variable::name, ast_variable::next, ast_ari_endpoints_refer_args::refer_to, ast_ari_response::response_code, ast_ari_endpoints_refer_args::to, ast_ari_endpoints_refer_args::to_self, ast_variable::value, and ast_ari_endpoints_refer_args::variables.

232 {
233  struct ast_ari_endpoints_refer_args args = {};
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 
287 fin: __attribute__((unused))
288  return;
289 }
struct ast_variable * next
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_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
int response_code
Definition: ari.h:99
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: utils.c:2199
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
struct ast_json * message
Definition: ari.h:94
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.

References ast_json_is_true(), ast_json_object_get(), ast_json_string_get(), ast_ari_endpoints_refer_args::from, ast_ari_endpoints_refer_args::refer_to, ast_ari_endpoints_refer_args::to, and ast_ari_endpoints_refer_args::to_self.

Referenced by ast_ari_endpoints_refer().

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 }
int ast_json_is_true(const struct ast_json *value)
Check if value is JSON true.
Definition: json.c:263
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
Abstract JSON element (object, array, string, int, ...).
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.

References ast_ari_endpoints_refer_to_endpoint(), ast_ari_response_error(), ast_ari_validate_void(), ast_true(), ast_ari_endpoints_refer_to_endpoint_args::from, ast_ari_response::message, ast_variable::name, ast_variable::next, ast_ari_endpoints_refer_to_endpoint_args::refer_to, ast_ari_endpoints_refer_to_endpoint_args::resource, ast_ari_response::response_code, ast_ari_endpoints_refer_to_endpoint_args::tech, ast_ari_endpoints_refer_to_endpoint_args::to_self, ast_variable::value, and ast_ari_endpoints_refer_to_endpoint_args::variables.

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 
600 fin: __attribute__((unused))
601  return;
602 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
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.
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
int response_code
Definition: ari.h:99
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: utils.c:2199
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
struct ast_json * message
Definition: ari.h:94
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.

References ast_json_is_true(), ast_json_object_get(), ast_json_string_get(), ast_ari_endpoints_refer_to_endpoint_args::from, ast_ari_endpoints_refer_to_endpoint_args::refer_to, and ast_ari_endpoints_refer_to_endpoint_args::to_self.

Referenced by ast_ari_endpoints_refer_to_endpoint().

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 }
int ast_json_is_true(const struct ast_json *value)
Check if value is JSON true.
Definition: json.c:263
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
Abstract JSON element (object, array, string, int, ...).
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.

References ast_ari_endpoints_send_message(), ast_ari_response_error(), ast_ari_validate_void(), ast_ari_endpoints_send_message_args::body, ast_ari_endpoints_send_message_args::from, ast_ari_response::message, ast_variable::name, ast_variable::next, ast_ari_response::response_code, ast_ari_endpoints_send_message_args::to, and ast_variable::value.

139 {
140  struct ast_ari_endpoints_send_message_args args = {};
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 
191 fin: __attribute__((unused))
192  return;
193 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
int response_code
Definition: ari.h:99
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
struct ast_json * message
Definition: ari.h:94
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.
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.

References ast_json_object_get(), ast_json_string_get(), ast_ari_endpoints_send_message_args::body, ast_ari_endpoints_send_message_args::from, and ast_ari_endpoints_send_message_args::to.

Referenced by ast_ari_endpoints_send_message().

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

References ast_ari_endpoints_send_message_to_endpoint(), ast_ari_response_error(), ast_ari_validate_void(), ast_ari_endpoints_send_message_to_endpoint_args::body, ast_ari_endpoints_send_message_to_endpoint_args::from, ast_ari_response::message, ast_variable::name, ast_variable::next, ast_ari_endpoints_send_message_to_endpoint_args::resource, ast_ari_response::response_code, ast_ari_endpoints_send_message_to_endpoint_args::tech, and ast_variable::value.

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;
471  ast_ari_endpoints_send_message_to_endpoint(headers, &args, response);
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 
502 fin: __attribute__((unused))
503  return;
504 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
int response_code
Definition: ari.h:99
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
struct ast_json * message
Definition: ari.h:94
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_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.

References ast_json_object_get(), ast_json_string_get(), ast_ari_endpoints_send_message_to_endpoint_args::body, and ast_ari_endpoints_send_message_to_endpoint_args::from.

Referenced by ast_ari_endpoints_send_message_to_endpoint().

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