Asterisk - The Open Source Telephony Project  21.4.1
Macros | Functions | Variables
res_ari_playbacks.c File Reference

Playback control resources. More...

#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/stasis_app.h"
#include "ari/resource_playbacks.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_playbacks_control_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 /playbacks/{playbackId}/control. More...
 
int ast_ari_playbacks_control_parse_body (struct ast_json *body, struct ast_ari_playbacks_control_args *args)
 Body parsing function for /playbacks/{playbackId}/control. More...
 
static void ast_ari_playbacks_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 /playbacks/{playbackId}. More...
 
static void ast_ari_playbacks_stop_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 /playbacks/{playbackId}. 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 - Playback control 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,res_stasis_playback", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct stasis_rest_handlers playbacks
 REST handler for /api-docs/playbacks.json.
 
static struct stasis_rest_handlers playbacks_playbackId
 REST handler for /api-docs/playbacks.json.
 
static struct stasis_rest_handlers playbacks_playbackId_control
 REST handler for /api-docs/playbacks.json.
 

Detailed Description

Playback control resources.

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

Definition in file res_ari_playbacks.c.

Function Documentation

static void ast_ari_playbacks_control_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 /playbacks/{playbackId}/control.

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 196 of file res_ari_playbacks.c.

References ast_ari_playbacks_control(), ast_ari_playbacks_control_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_ari_response::message, ast_variable::name, ast_variable::next, ast_ari_playbacks_control_args::operation, ast_ari_playbacks_control_args::playback_id, ast_ari_response::response_code, and ast_variable::value.

200 {
201  struct ast_ari_playbacks_control_args args = {};
202  struct ast_variable *i;
203 #if defined(AST_DEVMODE)
204  int is_valid;
205  int code;
206 #endif /* AST_DEVMODE */
207 
208  for (i = get_params; i; i = i->next) {
209  if (strcmp(i->name, "operation") == 0) {
210  args.operation = (i->value);
211  } else
212  {}
213  }
214  for (i = path_vars; i; i = i->next) {
215  if (strcmp(i->name, "playbackId") == 0) {
216  args.playback_id = (i->value);
217  } else
218  {}
219  }
220  if (ast_ari_playbacks_control_parse_body(body, &args)) {
222  goto fin;
223  }
224  ast_ari_playbacks_control(headers, &args, response);
225 #if defined(AST_DEVMODE)
226  code = response->response_code;
227 
228  switch (code) {
229  case 0: /* Implementation is still a stub, or the code wasn't set */
230  is_valid = response->message == NULL;
231  break;
232  case 500: /* Internal Server Error */
233  case 501: /* Not Implemented */
234  case 400: /* The provided operation parameter was invalid */
235  case 404: /* The playback cannot be found */
236  case 409: /* The operation cannot be performed in the playback's current state */
237  is_valid = 1;
238  break;
239  default:
240  if (200 <= code && code <= 299) {
241  is_valid = ast_ari_validate_void(
242  response->message);
243  } else {
244  ast_log(LOG_ERROR, "Invalid error response %d for /playbacks/{playbackId}/control\n", code);
245  is_valid = 0;
246  }
247  }
248 
249  if (!is_valid) {
250  ast_log(LOG_ERROR, "Response validation failed for /playbacks/{playbackId}/control\n");
251  ast_ari_response_error(response, 500,
252  "Internal Server Error", "Response validation failed");
253  }
254 #endif /* AST_DEVMODE */
255 
256 fin: __attribute__((unused))
257  return;
258 }
struct ast_variable * next
void ast_ari_playbacks_control(struct ast_variable *headers, struct ast_ari_playbacks_control_args *args, struct ast_ari_response *response)
Control a playback.
Structure for variables, used for configurations and for channel variables.
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
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
int ast_ari_playbacks_control_parse_body(struct ast_json *body, struct ast_ari_playbacks_control_args *args)
Body parsing function for /playbacks/{playbackId}/control.
int ast_ari_playbacks_control_parse_body ( struct ast_json body,
struct ast_ari_playbacks_control_args args 
)

Body parsing function for /playbacks/{playbackId}/control.

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 174 of file res_ari_playbacks.c.

References ast_json_object_get(), ast_json_string_get(), and ast_ari_playbacks_control_args::operation.

Referenced by ast_ari_playbacks_control_cb().

177 {
178  struct ast_json *field;
179  /* Parse query parameters out of it */
180  field = ast_json_object_get(body, "operation");
181  if (field) {
182  args->operation = ast_json_string_get(field);
183  }
184  return 0;
185 }
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_playbacks_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 /playbacks/{playbackId}.

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 63 of file res_ari_playbacks.c.

References ast_ari_playbacks_get(), ast_ari_response_error(), ast_ari_validate_playback(), ast_ari_response::message, ast_variable::name, ast_variable::next, ast_ari_playbacks_get_args::playback_id, ast_ari_response::response_code, and ast_variable::value.

67 {
68  struct ast_ari_playbacks_get_args args = {};
69  struct ast_variable *i;
70 #if defined(AST_DEVMODE)
71  int is_valid;
72  int code;
73 #endif /* AST_DEVMODE */
74 
75  for (i = path_vars; i; i = i->next) {
76  if (strcmp(i->name, "playbackId") == 0) {
77  args.playback_id = (i->value);
78  } else
79  {}
80  }
81  ast_ari_playbacks_get(headers, &args, response);
82 #if defined(AST_DEVMODE)
83  code = response->response_code;
84 
85  switch (code) {
86  case 0: /* Implementation is still a stub, or the code wasn't set */
87  is_valid = response->message == NULL;
88  break;
89  case 500: /* Internal Server Error */
90  case 501: /* Not Implemented */
91  case 404: /* The playback cannot be found */
92  is_valid = 1;
93  break;
94  default:
95  if (200 <= code && code <= 299) {
96  is_valid = ast_ari_validate_playback(
97  response->message);
98  } else {
99  ast_log(LOG_ERROR, "Invalid error response %d for /playbacks/{playbackId}\n", code);
100  is_valid = 0;
101  }
102  }
103 
104  if (!is_valid) {
105  ast_log(LOG_ERROR, "Response validation failed for /playbacks/{playbackId}\n");
106  ast_ari_response_error(response, 500,
107  "Internal Server Error", "Response validation failed");
108  }
109 #endif /* AST_DEVMODE */
110 
111 fin: __attribute__((unused))
112  return;
113 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
void ast_ari_playbacks_get(struct ast_variable *headers, struct ast_ari_playbacks_get_args *args, struct ast_ari_response *response)
Get a playback's details.
int response_code
Definition: ari.h:99
int ast_ari_validate_playback(struct ast_json *json)
Validator for Playback.
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_playbacks_stop_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 /playbacks/{playbackId}.

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 123 of file res_ari_playbacks.c.

References ast_ari_playbacks_stop(), ast_ari_response_error(), ast_ari_validate_void(), ast_ari_response::message, ast_variable::name, ast_variable::next, ast_ari_playbacks_stop_args::playback_id, ast_ari_response::response_code, and ast_variable::value.

127 {
128  struct ast_ari_playbacks_stop_args args = {};
129  struct ast_variable *i;
130 #if defined(AST_DEVMODE)
131  int is_valid;
132  int code;
133 #endif /* AST_DEVMODE */
134 
135  for (i = path_vars; i; i = i->next) {
136  if (strcmp(i->name, "playbackId") == 0) {
137  args.playback_id = (i->value);
138  } else
139  {}
140  }
141  ast_ari_playbacks_stop(headers, &args, response);
142 #if defined(AST_DEVMODE)
143  code = response->response_code;
144 
145  switch (code) {
146  case 0: /* Implementation is still a stub, or the code wasn't set */
147  is_valid = response->message == NULL;
148  break;
149  case 500: /* Internal Server Error */
150  case 501: /* Not Implemented */
151  case 404: /* The playback cannot be found */
152  is_valid = 1;
153  break;
154  default:
155  if (200 <= code && code <= 299) {
156  is_valid = ast_ari_validate_void(
157  response->message);
158  } else {
159  ast_log(LOG_ERROR, "Invalid error response %d for /playbacks/{playbackId}\n", code);
160  is_valid = 0;
161  }
162  }
163 
164  if (!is_valid) {
165  ast_log(LOG_ERROR, "Response validation failed for /playbacks/{playbackId}\n");
166  ast_ari_response_error(response, 500,
167  "Internal Server Error", "Response validation failed");
168  }
169 #endif /* AST_DEVMODE */
170 
171 fin: __attribute__((unused))
172  return;
173 }
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_playbacks_stop(struct ast_variable *headers, struct ast_ari_playbacks_stop_args *args, struct ast_ari_response *response)
Stop a playback.