Asterisk - The Open Source Telephony Project  18.5.0
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"
#include "ari/ari_model_validators.h"
Include dependency graph for res_ari_playbacks.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_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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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. More...
 
static struct stasis_rest_handlers playbacks_playbackId
 REST handler for /api-docs/playbacks.json. More...
 
static struct stasis_rest_handlers playbacks_playbackId_control
 REST handler for /api-docs/playbacks.json. More...
 

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.

Macro Definition Documentation

◆ MAX_VALS

#define MAX_VALS   128

Definition at line 52 of file res_ari_playbacks.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 308 of file res_ari_playbacks.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 308 of file res_ari_playbacks.c.

◆ ast_ari_playbacks_control_cb()

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
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
[out]responseResponse to the HTTP request.

Definition at line 190 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_log, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_playbacks_control_args::operation, ast_ari_playbacks_control_args::playback_id, ast_ari_response::response_code, and ast_variable::value.

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

◆ ast_ari_playbacks_control_parse_body()

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

173 {
174  struct ast_json *field;
175  /* Parse query parameters out of it */
176  field = ast_json_object_get(body, "operation");
177  if (field) {
178  args->operation = ast_json_string_get(field);
179  }
180  return 0;
181 }
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
Abstract JSON element (object, array, string, int, ...).

◆ ast_ari_playbacks_get_cb()

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
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
[out]responseResponse to the HTTP request.

Definition at line 61 of file res_ari_playbacks.c.

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

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

◆ ast_ari_playbacks_stop_cb()

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
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
[out]responseResponse to the HTTP request.

Definition at line 119 of file res_ari_playbacks.c.

References ast_ari_playbacks_stop(), 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_playbacks_stop_args::playback_id, ast_ari_response::response_code, and ast_variable::value.

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

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 308 of file res_ari_playbacks.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 289 of file res_ari_playbacks.c.

References ast_ari_add_handler(), AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ASTERISK_GPL_KEY, and unload_module().

290 {
291  int res = 0;
292 
293 
295  if (res) {
296  unload_module();
298  }
299 
301 }
static struct stasis_rest_handlers playbacks
REST handler for /api-docs/playbacks.json.
int ast_ari_add_handler(struct stasis_rest_handlers *handler)
Definition: res_ari.c:179
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static int unload_module(void)

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 283 of file res_ari_playbacks.c.

References ast_ari_remove_handler().

Referenced by load_module().

284 {
286  return 0;
287 }
static struct stasis_rest_handlers playbacks
REST handler for /api-docs/playbacks.json.
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
Definition: res_ari.c:202

Variable Documentation

◆ __mod_info

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_ari,res_ari_model,res_stasis,res_stasis_playback", }
static

Definition at line 308 of file res_ari_playbacks.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 308 of file res_ari_playbacks.c.

◆ playbacks

struct stasis_rest_handlers playbacks
static

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

Definition at line 275 of file res_ari_playbacks.c.

◆ playbacks_playbackId

struct stasis_rest_handlers playbacks_playbackId
static

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

Definition at line 264 of file res_ari_playbacks.c.

◆ playbacks_playbackId_control

struct stasis_rest_handlers playbacks_playbackId_control
static

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

Definition at line 255 of file res_ari_playbacks.c.