Asterisk - The Open Source Telephony Project GIT-master-f36a736
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 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 = AST_BUILDOPT_SUM, .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 314 of file res_ari_playbacks.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 314 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
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.

200{
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 }
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
256fin: __attribute__((unused))
257 return;
258}
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
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
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
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.
#define NULL
Definition: resample.c:96
void ast_ari_playbacks_control(struct ast_variable *headers, struct ast_ari_playbacks_control_args *args, struct ast_ari_response *response)
Control a playback.
struct ast_json * message
Definition: ari.h:94
int response_code
Definition: ari.h:99
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
const char * args

References args, 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_response::response_code, and ast_variable::value.

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

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, ...).

References args, ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_playbacks_control_cb().

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

67{
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) {
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
111fin: __attribute__((unused))
112 return;
113}
int ast_ari_validate_playback(struct ast_json *json)
Validator for Playback.
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.

References args, 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_response::response_code, and ast_variable::value.

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

127{
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
171fin: __attribute__((unused))
172 return;
173}
void ast_ari_playbacks_stop(struct ast_variable *headers, struct ast_ari_playbacks_stop_args *args, struct ast_ari_response *response)
Stop a playback.

References args, 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_response::response_code, and ast_variable::value.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 314 of file res_ari_playbacks.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 295 of file res_ari_playbacks.c.

296{
297 int res = 0;
298
299
301 if (res) {
304 }
305
307}
int ast_ari_add_handler(struct stasis_rest_handlers *handler)
Definition: res_ari.c:179
@ 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 playbacks
REST handler for /api-docs/playbacks.json.
static int unload_module(void)

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

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 289 of file res_ari_playbacks.c.

290{
292 return 0;
293}
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
Definition: res_ari.c:202

References ast_ari_remove_handler(), and playbacks.

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 - 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 = AST_BUILDOPT_SUM, .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 314 of file res_ari_playbacks.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 314 of file res_ari_playbacks.c.

◆ playbacks

struct stasis_rest_handlers playbacks
static

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

Definition at line 281 of file res_ari_playbacks.c.

Referenced by load_module(), and unload_module().

◆ playbacks_playbackId

struct stasis_rest_handlers playbacks_playbackId
static

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

Definition at line 270 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 261 of file res_ari_playbacks.c.