Asterisk - The Open Source Telephony Project  18.5.0
res_ari_playbacks.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2012 - 2013, Digium, Inc.
5  *
6  * David M. Lee, II <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*
20  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21  * !!!!! DO NOT EDIT !!!!!
22  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23  * This file is generated by a mustache template. Please see the original
24  * template in rest-api-templates/res_ari_resource.c.mustache
25  */
26 
27 /*! \file
28  *
29  * \brief Playback control resources
30  *
31  * \author David M. Lee, II <[email protected]>
32  */
33 
34 /*** MODULEINFO
35  <depend type="module">res_ari</depend>
36  <depend type="module">res_ari_model</depend>
37  <depend type="module">res_stasis</depend>
38  <depend type="module">res_stasis_playback</depend>
39  <support_level>core</support_level>
40  ***/
41 
42 #include "asterisk.h"
43 
44 #include "asterisk/app.h"
45 #include "asterisk/module.h"
46 #include "asterisk/stasis_app.h"
47 #include "ari/resource_playbacks.h"
48 #if defined(AST_DEVMODE)
50 #endif
51 
52 #define MAX_VALS 128
53 
54 /*!
55  * \brief Parameter parsing callback for /playbacks/{playbackId}.
56  * \param get_params GET parameters in the HTTP request.
57  * \param path_vars Path variables extracted from the request.
58  * \param headers HTTP headers.
59  * \param[out] response Response to the HTTP request.
60  */
62  struct ast_tcptls_session_instance *ser,
63  struct ast_variable *get_params, struct ast_variable *path_vars,
64  struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
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 }
112 /*!
113  * \brief Parameter parsing callback for /playbacks/{playbackId}.
114  * \param get_params GET parameters in the HTTP request.
115  * \param path_vars Path variables extracted from the request.
116  * \param headers HTTP headers.
117  * \param[out] response Response to the HTTP request.
118  */
120  struct ast_tcptls_session_instance *ser,
121  struct ast_variable *get_params, struct ast_variable *path_vars,
122  struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
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 }
171  struct ast_json *body,
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 }
182 
183 /*!
184  * \brief Parameter parsing callback for /playbacks/{playbackId}/control.
185  * \param get_params GET parameters in the HTTP request.
186  * \param path_vars Path variables extracted from the request.
187  * \param headers HTTP headers.
188  * \param[out] response Response to the HTTP request.
189  */
191  struct ast_tcptls_session_instance *ser,
192  struct ast_variable *get_params, struct ast_variable *path_vars,
193  struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
194 {
195  struct ast_ari_playbacks_control_args args = {};
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 }
253 
254 /*! \brief REST handler for /api-docs/playbacks.json */
256  .path_segment = "control",
257  .callbacks = {
259  },
260  .num_children = 0,
261  .children = { }
262 };
263 /*! \brief REST handler for /api-docs/playbacks.json */
265  .path_segment = "playbackId",
266  .is_wildcard = 1,
267  .callbacks = {
270  },
271  .num_children = 1,
272  .children = { &playbacks_playbackId_control, }
273 };
274 /*! \brief REST handler for /api-docs/playbacks.json */
276  .path_segment = "playbacks",
277  .callbacks = {
278  },
279  .num_children = 1,
280  .children = { &playbacks_playbackId, }
281 };
282 
283 static int unload_module(void)
284 {
285  ast_ari_remove_handler(&playbacks);
286  return 0;
287 }
288 
289 static int load_module(void)
290 {
291  int res = 0;
292 
293 
294  res |= ast_ari_add_handler(&playbacks);
295  if (res) {
296  unload_module();
298  }
299 
301 }
302 
303 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Playback control resources",
304  .support_level = AST_MODULE_SUPPORT_CORE,
305  .load = load_module,
306  .unload = unload_module,
307  .requires = "res_ari,res_ari_model,res_stasis,res_stasis_playback",
308 );
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.
Asterisk main include file. File version handling, generic pbx functions.
Generated file - declares stubs to be implemented in res/ari/resource_playbacks.c.
Structure for variables, used for configurations and for channel variables.
Generated file - Build validators for ARI model objects.
const char * args
#define NULL
Definition: resample.c:96
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}.
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.
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
static struct stasis_rest_handlers playbacks_playbackId
REST handler for /api-docs/playbacks.json.
int response_code
Definition: ari.h:98
#define ast_log
Definition: astobj2.c:42
static struct stasis_rest_handlers playbacks
REST handler for /api-docs/playbacks.json.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
static int load_module(void)
int ast_ari_validate_playback(struct ast_json *json)
Validator for Playback.
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.
describes a server instance
Definition: tcptls.h:149
#define LOG_ERROR
Definition: logger.h:285
int ast_ari_add_handler(struct stasis_rest_handlers *handler)
Definition: res_ari.c:179
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
Definition: res_ari.c:202
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
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
struct ast_json * message
Definition: ari.h:93
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
const char * path_segment
Definition: ari.h:70
void ast_ari_playbacks_stop(struct ast_variable *headers, struct ast_ari_playbacks_stop_args *args, struct ast_ari_response *response)
Stop a playback.
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.
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
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}.
static struct stasis_rest_handlers playbacks_playbackId_control
REST handler for /api-docs/playbacks.json.
Abstract JSON element (object, array, string, int, ...).
static int unload_module(void)
Stasis Application API. See Stasis Application API for detailed documentation.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
Handler for a single RESTful path segment.
Definition: ari.h:68