Review Board 1.7.16


Use POST / DELETE to toggle bridge moh

Review Request #2911 - Created Oct. 15, 2013 and submitted

Paul Belanger
trunk
Reviewers
asterisk-dev
Asterisk
Another candidate for using POST / DELETE to toggle functionality.
local development box with python-ari

Diff revision 1 (Latest)

  1. trunk/res/res_ari_bridges.c: Loading...
  2. trunk/rest-api/api-docs/bridges.json: Loading...
trunk/res/res_ari_bridges.c
Revision 401007 New Change
1
/*
1
/*
2
 * Asterisk -- An open source telephony toolkit.
2
 * Asterisk -- An open source telephony toolkit.
3
 *
3
 *
4
 * Copyright (C) 2012 - 2013, Digium, Inc.
4
 * Copyright (C) 2012 - 2013, Digium, Inc.
5
 *
5
 *
6
 * David M. Lee, II <dlee@digium.com>
6
 * David M. Lee, II <dlee@digium.com>
7
 *
7
 *
8
 * See http://www.asterisk.org for more information about
8
 * See http://www.asterisk.org for more information about
9
 * the Asterisk project. Please do not directly contact
9
 * the Asterisk project. Please do not directly contact
10
 * any of the maintainers of this project for assistance;
10
 * any of the maintainers of this project for assistance;
11
 * the project provides a web site, mailing lists and IRC
11
 * the project provides a web site, mailing lists and IRC
12
 * channels for your use.
12
 * channels for your use.
13
 *
13
 *
14
 * This program is free software, distributed under the terms of
14
 * This program is free software, distributed under the terms of
15
 * the GNU General Public License Version 2. See the LICENSE file
15
 * the GNU General Public License Version 2. See the LICENSE file
16
 * at the top of the source tree.
16
 * at the top of the source tree.
17
 */
17
 */
18

    
   
18

   
19
/*
19
/*
20
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21
 * !!!!!                               DO NOT EDIT                        !!!!!
21
 * !!!!!                               DO NOT EDIT                        !!!!!
22
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
22
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23
 * This file is generated by a mustache template. Please see the original
23
 * This file is generated by a mustache template. Please see the original
24
 * template in rest-api-templates/res_ari_resource.c.mustache
24
 * template in rest-api-templates/res_ari_resource.c.mustache
25
 */
25
 */
26

    
   
26

   
27
/*! \file
27
/*! \file
28
 *
28
 *
29
 * \brief Bridge resources
29
 * \brief Bridge resources
30
 *
30
 *
31
 * \author David M. Lee, II <dlee@digium.com>
31
 * \author David M. Lee, II <dlee@digium.com>
32
 */
32
 */
33

    
   
33

   
34
/*** MODULEINFO
34
/*** MODULEINFO
35
	<depend type="module">res_ari</depend>
35
	<depend type="module">res_ari</depend>
36
	<depend type="module">res_stasis</depend>
36
	<depend type="module">res_stasis</depend>
37
	<support_level>core</support_level>
37
	<support_level>core</support_level>
38
 ***/
38
 ***/
39

    
   
39

   
40
#include "asterisk.h"
40
#include "asterisk.h"
41

    
   
41

   
42
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
42
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
43

    
   
43

   
44
#include "asterisk/app.h"
44
#include "asterisk/app.h"
45
#include "asterisk/module.h"
45
#include "asterisk/module.h"
46
#include "asterisk/stasis_app.h"
46
#include "asterisk/stasis_app.h"
47
#include "ari/resource_bridges.h"
47
#include "ari/resource_bridges.h"
48
#if defined(AST_DEVMODE)
48
#if defined(AST_DEVMODE)
49
#include "ari/ari_model_validators.h"
49
#include "ari/ari_model_validators.h"
50
#endif
50
#endif
51

    
   
51

   
52
#define MAX_VALS 128
52
#define MAX_VALS 128
53

    
   
53

   
54
/*!
54
/*!
55
 * \brief Parameter parsing callback for /bridges.
55
 * \brief Parameter parsing callback for /bridges.
56
 * \param get_params GET parameters in the HTTP request.
56
 * \param get_params GET parameters in the HTTP request.
57
 * \param path_vars Path variables extracted from the request.
57
 * \param path_vars Path variables extracted from the request.
58
 * \param headers HTTP headers.
58
 * \param headers HTTP headers.
59
 * \param[out] response Response to the HTTP request.
59
 * \param[out] response Response to the HTTP request.
60
 */
60
 */
61
static void ast_ari_get_bridges_cb(
61
static void ast_ari_get_bridges_cb(
62
	struct ast_variable *get_params, struct ast_variable *path_vars,
62
	struct ast_variable *get_params, struct ast_variable *path_vars,
63
	struct ast_variable *headers, struct ast_ari_response *response)
63
	struct ast_variable *headers, struct ast_ari_response *response)
64
{
64
{
65
	struct ast_get_bridges_args args = {};
65
	struct ast_get_bridges_args args = {};
66
#if defined(AST_DEVMODE)
66
#if defined(AST_DEVMODE)
67
	int is_valid;
67
	int is_valid;
68
	int code;
68
	int code;
69
#endif /* AST_DEVMODE */
69
#endif /* AST_DEVMODE */
70

    
   
70

   
71
	ast_ari_get_bridges(headers, &args, response);
71
	ast_ari_get_bridges(headers, &args, response);
72
#if defined(AST_DEVMODE)
72
#if defined(AST_DEVMODE)
73
	code = response->response_code;
73
	code = response->response_code;
74

    
   
74

   
75
	switch (code) {
75
	switch (code) {
76
	case 0: /* Implementation is still a stub, or the code wasn't set */
76
	case 0: /* Implementation is still a stub, or the code wasn't set */
77
		is_valid = response->message == NULL;
77
		is_valid = response->message == NULL;
78
		break;
78
		break;
79
	case 500: /* Internal Server Error */
79
	case 500: /* Internal Server Error */
80
	case 501: /* Not Implemented */
80
	case 501: /* Not Implemented */
81
		is_valid = 1;
81
		is_valid = 1;
82
		break;
82
		break;
83
	default:
83
	default:
84
		if (200 <= code && code <= 299) {
84
		if (200 <= code && code <= 299) {
85
			is_valid = ast_ari_validate_list(response->message,
85
			is_valid = ast_ari_validate_list(response->message,
86
				ast_ari_validate_bridge_fn());
86
				ast_ari_validate_bridge_fn());
87
		} else {
87
		} else {
88
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges\n", code);
88
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges\n", code);
89
			is_valid = 0;
89
			is_valid = 0;
90
		}
90
		}
91
	}
91
	}
92

    
   
92

   
93
	if (!is_valid) {
93
	if (!is_valid) {
94
		ast_log(LOG_ERROR, "Response validation failed for /bridges\n");
94
		ast_log(LOG_ERROR, "Response validation failed for /bridges\n");
95
		ast_ari_response_error(response, 500,
95
		ast_ari_response_error(response, 500,
96
			"Internal Server Error", "Response validation failed");
96
			"Internal Server Error", "Response validation failed");
97
	}
97
	}
98
#endif /* AST_DEVMODE */
98
#endif /* AST_DEVMODE */
99

    
   
99

   
100
fin: __attribute__((unused))
100
fin: __attribute__((unused))
101
	return;
101
	return;
102
}
102
}
103
/*!
103
/*!
104
 * \brief Parameter parsing callback for /bridges.
104
 * \brief Parameter parsing callback for /bridges.
105
 * \param get_params GET parameters in the HTTP request.
105
 * \param get_params GET parameters in the HTTP request.
106
 * \param path_vars Path variables extracted from the request.
106
 * \param path_vars Path variables extracted from the request.
107
 * \param headers HTTP headers.
107
 * \param headers HTTP headers.
108
 * \param[out] response Response to the HTTP request.
108
 * \param[out] response Response to the HTTP request.
109
 */
109
 */
110
static void ast_ari_new_bridge_cb(
110
static void ast_ari_new_bridge_cb(
111
	struct ast_variable *get_params, struct ast_variable *path_vars,
111
	struct ast_variable *get_params, struct ast_variable *path_vars,
112
	struct ast_variable *headers, struct ast_ari_response *response)
112
	struct ast_variable *headers, struct ast_ari_response *response)
113
{
113
{
114
	struct ast_new_bridge_args args = {};
114
	struct ast_new_bridge_args args = {};
115
	struct ast_variable *i;
115
	struct ast_variable *i;
116
#if defined(AST_DEVMODE)
116
#if defined(AST_DEVMODE)
117
	int is_valid;
117
	int is_valid;
118
	int code;
118
	int code;
119
#endif /* AST_DEVMODE */
119
#endif /* AST_DEVMODE */
120

    
   
120

   
121
	for (i = get_params; i; i = i->next) {
121
	for (i = get_params; i; i = i->next) {
122
		if (strcmp(i->name, "type") == 0) {
122
		if (strcmp(i->name, "type") == 0) {
123
			args.type = (i->value);
123
			args.type = (i->value);
124
		} else
124
		} else
125
		{}
125
		{}
126
	}
126
	}
127
	ast_ari_new_bridge(headers, &args, response);
127
	ast_ari_new_bridge(headers, &args, response);
128
#if defined(AST_DEVMODE)
128
#if defined(AST_DEVMODE)
129
	code = response->response_code;
129
	code = response->response_code;
130

    
   
130

   
131
	switch (code) {
131
	switch (code) {
132
	case 0: /* Implementation is still a stub, or the code wasn't set */
132
	case 0: /* Implementation is still a stub, or the code wasn't set */
133
		is_valid = response->message == NULL;
133
		is_valid = response->message == NULL;
134
		break;
134
		break;
135
	case 500: /* Internal Server Error */
135
	case 500: /* Internal Server Error */
136
	case 501: /* Not Implemented */
136
	case 501: /* Not Implemented */
137
		is_valid = 1;
137
		is_valid = 1;
138
		break;
138
		break;
139
	default:
139
	default:
140
		if (200 <= code && code <= 299) {
140
		if (200 <= code && code <= 299) {
141
			is_valid = ast_ari_validate_bridge(
141
			is_valid = ast_ari_validate_bridge(
142
				response->message);
142
				response->message);
143
		} else {
143
		} else {
144
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges\n", code);
144
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges\n", code);
145
			is_valid = 0;
145
			is_valid = 0;
146
		}
146
		}
147
	}
147
	}
148

    
   
148

   
149
	if (!is_valid) {
149
	if (!is_valid) {
150
		ast_log(LOG_ERROR, "Response validation failed for /bridges\n");
150
		ast_log(LOG_ERROR, "Response validation failed for /bridges\n");
151
		ast_ari_response_error(response, 500,
151
		ast_ari_response_error(response, 500,
152
			"Internal Server Error", "Response validation failed");
152
			"Internal Server Error", "Response validation failed");
153
	}
153
	}
154
#endif /* AST_DEVMODE */
154
#endif /* AST_DEVMODE */
155

    
   
155

   
156
fin: __attribute__((unused))
156
fin: __attribute__((unused))
157
	return;
157
	return;
158
}
158
}
159
/*!
159
/*!
160
 * \brief Parameter parsing callback for /bridges/{bridgeId}.
160
 * \brief Parameter parsing callback for /bridges/{bridgeId}.
161
 * \param get_params GET parameters in the HTTP request.
161
 * \param get_params GET parameters in the HTTP request.
162
 * \param path_vars Path variables extracted from the request.
162
 * \param path_vars Path variables extracted from the request.
163
 * \param headers HTTP headers.
163
 * \param headers HTTP headers.
164
 * \param[out] response Response to the HTTP request.
164
 * \param[out] response Response to the HTTP request.
165
 */
165
 */
166
static void ast_ari_get_bridge_cb(
166
static void ast_ari_get_bridge_cb(
167
	struct ast_variable *get_params, struct ast_variable *path_vars,
167
	struct ast_variable *get_params, struct ast_variable *path_vars,
168
	struct ast_variable *headers, struct ast_ari_response *response)
168
	struct ast_variable *headers, struct ast_ari_response *response)
169
{
169
{
170
	struct ast_get_bridge_args args = {};
170
	struct ast_get_bridge_args args = {};
171
	struct ast_variable *i;
171
	struct ast_variable *i;
172
#if defined(AST_DEVMODE)
172
#if defined(AST_DEVMODE)
173
	int is_valid;
173
	int is_valid;
174
	int code;
174
	int code;
175
#endif /* AST_DEVMODE */
175
#endif /* AST_DEVMODE */
176

    
   
176

   
177
	for (i = path_vars; i; i = i->next) {
177
	for (i = path_vars; i; i = i->next) {
178
		if (strcmp(i->name, "bridgeId") == 0) {
178
		if (strcmp(i->name, "bridgeId") == 0) {
179
			args.bridge_id = (i->value);
179
			args.bridge_id = (i->value);
180
		} else
180
		} else
181
		{}
181
		{}
182
	}
182
	}
183
	ast_ari_get_bridge(headers, &args, response);
183
	ast_ari_get_bridge(headers, &args, response);
184
#if defined(AST_DEVMODE)
184
#if defined(AST_DEVMODE)
185
	code = response->response_code;
185
	code = response->response_code;
186

    
   
186

   
187
	switch (code) {
187
	switch (code) {
188
	case 0: /* Implementation is still a stub, or the code wasn't set */
188
	case 0: /* Implementation is still a stub, or the code wasn't set */
189
		is_valid = response->message == NULL;
189
		is_valid = response->message == NULL;
190
		break;
190
		break;
191
	case 500: /* Internal Server Error */
191
	case 500: /* Internal Server Error */
192
	case 501: /* Not Implemented */
192
	case 501: /* Not Implemented */
193
	case 404: /* Bridge not found */
193
	case 404: /* Bridge not found */
194
		is_valid = 1;
194
		is_valid = 1;
195
		break;
195
		break;
196
	default:
196
	default:
197
		if (200 <= code && code <= 299) {
197
		if (200 <= code && code <= 299) {
198
			is_valid = ast_ari_validate_bridge(
198
			is_valid = ast_ari_validate_bridge(
199
				response->message);
199
				response->message);
200
		} else {
200
		} else {
201
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}\n", code);
201
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}\n", code);
202
			is_valid = 0;
202
			is_valid = 0;
203
		}
203
		}
204
	}
204
	}
205

    
   
205

   
206
	if (!is_valid) {
206
	if (!is_valid) {
207
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}\n");
207
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}\n");
208
		ast_ari_response_error(response, 500,
208
		ast_ari_response_error(response, 500,
209
			"Internal Server Error", "Response validation failed");
209
			"Internal Server Error", "Response validation failed");
210
	}
210
	}
211
#endif /* AST_DEVMODE */
211
#endif /* AST_DEVMODE */
212

    
   
212

   
213
fin: __attribute__((unused))
213
fin: __attribute__((unused))
214
	return;
214
	return;
215
}
215
}
216
/*!
216
/*!
217
 * \brief Parameter parsing callback for /bridges/{bridgeId}.
217
 * \brief Parameter parsing callback for /bridges/{bridgeId}.
218
 * \param get_params GET parameters in the HTTP request.
218
 * \param get_params GET parameters in the HTTP request.
219
 * \param path_vars Path variables extracted from the request.
219
 * \param path_vars Path variables extracted from the request.
220
 * \param headers HTTP headers.
220
 * \param headers HTTP headers.
221
 * \param[out] response Response to the HTTP request.
221
 * \param[out] response Response to the HTTP request.
222
 */
222
 */
223
static void ast_ari_delete_bridge_cb(
223
static void ast_ari_delete_bridge_cb(
224
	struct ast_variable *get_params, struct ast_variable *path_vars,
224
	struct ast_variable *get_params, struct ast_variable *path_vars,
225
	struct ast_variable *headers, struct ast_ari_response *response)
225
	struct ast_variable *headers, struct ast_ari_response *response)
226
{
226
{
227
	struct ast_delete_bridge_args args = {};
227
	struct ast_delete_bridge_args args = {};
228
	struct ast_variable *i;
228
	struct ast_variable *i;
229
#if defined(AST_DEVMODE)
229
#if defined(AST_DEVMODE)
230
	int is_valid;
230
	int is_valid;
231
	int code;
231
	int code;
232
#endif /* AST_DEVMODE */
232
#endif /* AST_DEVMODE */
233

    
   
233

   
234
	for (i = path_vars; i; i = i->next) {
234
	for (i = path_vars; i; i = i->next) {
235
		if (strcmp(i->name, "bridgeId") == 0) {
235
		if (strcmp(i->name, "bridgeId") == 0) {
236
			args.bridge_id = (i->value);
236
			args.bridge_id = (i->value);
237
		} else
237
		} else
238
		{}
238
		{}
239
	}
239
	}
240
	ast_ari_delete_bridge(headers, &args, response);
240
	ast_ari_delete_bridge(headers, &args, response);
241
#if defined(AST_DEVMODE)
241
#if defined(AST_DEVMODE)
242
	code = response->response_code;
242
	code = response->response_code;
243

    
   
243

   
244
	switch (code) {
244
	switch (code) {
245
	case 0: /* Implementation is still a stub, or the code wasn't set */
245
	case 0: /* Implementation is still a stub, or the code wasn't set */
246
		is_valid = response->message == NULL;
246
		is_valid = response->message == NULL;
247
		break;
247
		break;
248
	case 500: /* Internal Server Error */
248
	case 500: /* Internal Server Error */
249
	case 501: /* Not Implemented */
249
	case 501: /* Not Implemented */
250
	case 404: /* Bridge not found */
250
	case 404: /* Bridge not found */
251
		is_valid = 1;
251
		is_valid = 1;
252
		break;
252
		break;
253
	default:
253
	default:
254
		if (200 <= code && code <= 299) {
254
		if (200 <= code && code <= 299) {
255
			is_valid = ast_ari_validate_void(
255
			is_valid = ast_ari_validate_void(
256
				response->message);
256
				response->message);
257
		} else {
257
		} else {
258
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}\n", code);
258
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}\n", code);
259
			is_valid = 0;
259
			is_valid = 0;
260
		}
260
		}
261
	}
261
	}
262

    
   
262

   
263
	if (!is_valid) {
263
	if (!is_valid) {
264
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}\n");
264
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}\n");
265
		ast_ari_response_error(response, 500,
265
		ast_ari_response_error(response, 500,
266
			"Internal Server Error", "Response validation failed");
266
			"Internal Server Error", "Response validation failed");
267
	}
267
	}
268
#endif /* AST_DEVMODE */
268
#endif /* AST_DEVMODE */
269

    
   
269

   
270
fin: __attribute__((unused))
270
fin: __attribute__((unused))
271
	return;
271
	return;
272
}
272
}
273
/*!
273
/*!
274
 * \brief Parameter parsing callback for /bridges/{bridgeId}/addChannel.
274
 * \brief Parameter parsing callback for /bridges/{bridgeId}/addChannel.
275
 * \param get_params GET parameters in the HTTP request.
275
 * \param get_params GET parameters in the HTTP request.
276
 * \param path_vars Path variables extracted from the request.
276
 * \param path_vars Path variables extracted from the request.
277
 * \param headers HTTP headers.
277
 * \param headers HTTP headers.
278
 * \param[out] response Response to the HTTP request.
278
 * \param[out] response Response to the HTTP request.
279
 */
279
 */
280
static void ast_ari_add_channel_to_bridge_cb(
280
static void ast_ari_add_channel_to_bridge_cb(
281
	struct ast_variable *get_params, struct ast_variable *path_vars,
281
	struct ast_variable *get_params, struct ast_variable *path_vars,
282
	struct ast_variable *headers, struct ast_ari_response *response)
282
	struct ast_variable *headers, struct ast_ari_response *response)
283
{
283
{
284
	struct ast_add_channel_to_bridge_args args = {};
284
	struct ast_add_channel_to_bridge_args args = {};
285
	struct ast_variable *i;
285
	struct ast_variable *i;
286
#if defined(AST_DEVMODE)
286
#if defined(AST_DEVMODE)
287
	int is_valid;
287
	int is_valid;
288
	int code;
288
	int code;
289
#endif /* AST_DEVMODE */
289
#endif /* AST_DEVMODE */
290

    
   
290

   
291
	for (i = get_params; i; i = i->next) {
291
	for (i = get_params; i; i = i->next) {
292
		if (strcmp(i->name, "channel") == 0) {
292
		if (strcmp(i->name, "channel") == 0) {
293
			/* Parse comma separated list */
293
			/* Parse comma separated list */
294
			char *vals[MAX_VALS];
294
			char *vals[MAX_VALS];
295
			size_t j;
295
			size_t j;
296

    
   
296

   
297
			args.channel_parse = ast_strdup(i->value);
297
			args.channel_parse = ast_strdup(i->value);
298
			if (!args.channel_parse) {
298
			if (!args.channel_parse) {
299
				ast_ari_response_alloc_failed(response);
299
				ast_ari_response_alloc_failed(response);
300
				goto fin;
300
				goto fin;
301
			}
301
			}
302

    
   
302

   
303
			if (strlen(args.channel_parse) == 0) {
303
			if (strlen(args.channel_parse) == 0) {
304
				/* ast_app_separate_args can't handle "" */
304
				/* ast_app_separate_args can't handle "" */
305
				args.channel_count = 1;
305
				args.channel_count = 1;
306
				vals[0] = args.channel_parse;
306
				vals[0] = args.channel_parse;
307
			} else {
307
			} else {
308
				args.channel_count = ast_app_separate_args(
308
				args.channel_count = ast_app_separate_args(
309
					args.channel_parse, ',', vals,
309
					args.channel_parse, ',', vals,
310
					ARRAY_LEN(vals));
310
					ARRAY_LEN(vals));
311
			}
311
			}
312

    
   
312

   
313
			if (args.channel_count == 0) {
313
			if (args.channel_count == 0) {
314
				ast_ari_response_alloc_failed(response);
314
				ast_ari_response_alloc_failed(response);
315
				goto fin;
315
				goto fin;
316
			}
316
			}
317

    
   
317

   
318
			if (args.channel_count >= MAX_VALS) {
318
			if (args.channel_count >= MAX_VALS) {
319
				ast_ari_response_error(response, 400,
319
				ast_ari_response_error(response, 400,
320
					"Bad Request",
320
					"Bad Request",
321
					"Too many values for channel");
321
					"Too many values for channel");
322
				goto fin;
322
				goto fin;
323
			}
323
			}
324

    
   
324

   
325
			args.channel = ast_malloc(sizeof(*args.channel) * args.channel_count);
325
			args.channel = ast_malloc(sizeof(*args.channel) * args.channel_count);
326
			if (!args.channel) {
326
			if (!args.channel) {
327
				ast_ari_response_alloc_failed(response);
327
				ast_ari_response_alloc_failed(response);
328
				goto fin;
328
				goto fin;
329
			}
329
			}
330

    
   
330

   
331
			for (j = 0; j < args.channel_count; ++j) {
331
			for (j = 0; j < args.channel_count; ++j) {
332
				args.channel[j] = (vals[j]);
332
				args.channel[j] = (vals[j]);
333
			}
333
			}
334
		} else
334
		} else
335
		if (strcmp(i->name, "role") == 0) {
335
		if (strcmp(i->name, "role") == 0) {
336
			args.role = (i->value);
336
			args.role = (i->value);
337
		} else
337
		} else
338
		{}
338
		{}
339
	}
339
	}
340
	for (i = path_vars; i; i = i->next) {
340
	for (i = path_vars; i; i = i->next) {
341
		if (strcmp(i->name, "bridgeId") == 0) {
341
		if (strcmp(i->name, "bridgeId") == 0) {
342
			args.bridge_id = (i->value);
342
			args.bridge_id = (i->value);
343
		} else
343
		} else
344
		{}
344
		{}
345
	}
345
	}
346
	ast_ari_add_channel_to_bridge(headers, &args, response);
346
	ast_ari_add_channel_to_bridge(headers, &args, response);
347
#if defined(AST_DEVMODE)
347
#if defined(AST_DEVMODE)
348
	code = response->response_code;
348
	code = response->response_code;
349

    
   
349

   
350
	switch (code) {
350
	switch (code) {
351
	case 0: /* Implementation is still a stub, or the code wasn't set */
351
	case 0: /* Implementation is still a stub, or the code wasn't set */
352
		is_valid = response->message == NULL;
352
		is_valid = response->message == NULL;
353
		break;
353
		break;
354
	case 500: /* Internal Server Error */
354
	case 500: /* Internal Server Error */
355
	case 501: /* Not Implemented */
355
	case 501: /* Not Implemented */
356
	case 400: /* Channel not found */
356
	case 400: /* Channel not found */
357
	case 404: /* Bridge not found */
357
	case 404: /* Bridge not found */
358
	case 409: /* Bridge not in Stasis application */
358
	case 409: /* Bridge not in Stasis application */
359
	case 422: /* Channel not in Stasis application */
359
	case 422: /* Channel not in Stasis application */
360
		is_valid = 1;
360
		is_valid = 1;
361
		break;
361
		break;
362
	default:
362
	default:
363
		if (200 <= code && code <= 299) {
363
		if (200 <= code && code <= 299) {
364
			is_valid = ast_ari_validate_void(
364
			is_valid = ast_ari_validate_void(
365
				response->message);
365
				response->message);
366
		} else {
366
		} else {
367
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/addChannel\n", code);
367
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/addChannel\n", code);
368
			is_valid = 0;
368
			is_valid = 0;
369
		}
369
		}
370
	}
370
	}
371

    
   
371

   
372
	if (!is_valid) {
372
	if (!is_valid) {
373
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/addChannel\n");
373
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/addChannel\n");
374
		ast_ari_response_error(response, 500,
374
		ast_ari_response_error(response, 500,
375
			"Internal Server Error", "Response validation failed");
375
			"Internal Server Error", "Response validation failed");
376
	}
376
	}
377
#endif /* AST_DEVMODE */
377
#endif /* AST_DEVMODE */
378

    
   
378

   
379
fin: __attribute__((unused))
379
fin: __attribute__((unused))
380
	ast_free(args.channel_parse);
380
	ast_free(args.channel_parse);
381
	ast_free(args.channel);
381
	ast_free(args.channel);
382
	return;
382
	return;
383
}
383
}
384
/*!
384
/*!
385
 * \brief Parameter parsing callback for /bridges/{bridgeId}/removeChannel.
385
 * \brief Parameter parsing callback for /bridges/{bridgeId}/removeChannel.
386
 * \param get_params GET parameters in the HTTP request.
386
 * \param get_params GET parameters in the HTTP request.
387
 * \param path_vars Path variables extracted from the request.
387
 * \param path_vars Path variables extracted from the request.
388
 * \param headers HTTP headers.
388
 * \param headers HTTP headers.
389
 * \param[out] response Response to the HTTP request.
389
 * \param[out] response Response to the HTTP request.
390
 */
390
 */
391
static void ast_ari_remove_channel_from_bridge_cb(
391
static void ast_ari_remove_channel_from_bridge_cb(
392
	struct ast_variable *get_params, struct ast_variable *path_vars,
392
	struct ast_variable *get_params, struct ast_variable *path_vars,
393
	struct ast_variable *headers, struct ast_ari_response *response)
393
	struct ast_variable *headers, struct ast_ari_response *response)
394
{
394
{
395
	struct ast_remove_channel_from_bridge_args args = {};
395
	struct ast_remove_channel_from_bridge_args args = {};
396
	struct ast_variable *i;
396
	struct ast_variable *i;
397
#if defined(AST_DEVMODE)
397
#if defined(AST_DEVMODE)
398
	int is_valid;
398
	int is_valid;
399
	int code;
399
	int code;
400
#endif /* AST_DEVMODE */
400
#endif /* AST_DEVMODE */
401

    
   
401

   
402
	for (i = get_params; i; i = i->next) {
402
	for (i = get_params; i; i = i->next) {
403
		if (strcmp(i->name, "channel") == 0) {
403
		if (strcmp(i->name, "channel") == 0) {
404
			/* Parse comma separated list */
404
			/* Parse comma separated list */
405
			char *vals[MAX_VALS];
405
			char *vals[MAX_VALS];
406
			size_t j;
406
			size_t j;
407

    
   
407

   
408
			args.channel_parse = ast_strdup(i->value);
408
			args.channel_parse = ast_strdup(i->value);
409
			if (!args.channel_parse) {
409
			if (!args.channel_parse) {
410
				ast_ari_response_alloc_failed(response);
410
				ast_ari_response_alloc_failed(response);
411
				goto fin;
411
				goto fin;
412
			}
412
			}
413

    
   
413

   
414
			if (strlen(args.channel_parse) == 0) {
414
			if (strlen(args.channel_parse) == 0) {
415
				/* ast_app_separate_args can't handle "" */
415
				/* ast_app_separate_args can't handle "" */
416
				args.channel_count = 1;
416
				args.channel_count = 1;
417
				vals[0] = args.channel_parse;
417
				vals[0] = args.channel_parse;
418
			} else {
418
			} else {
419
				args.channel_count = ast_app_separate_args(
419
				args.channel_count = ast_app_separate_args(
420
					args.channel_parse, ',', vals,
420
					args.channel_parse, ',', vals,
421
					ARRAY_LEN(vals));
421
					ARRAY_LEN(vals));
422
			}
422
			}
423

    
   
423

   
424
			if (args.channel_count == 0) {
424
			if (args.channel_count == 0) {
425
				ast_ari_response_alloc_failed(response);
425
				ast_ari_response_alloc_failed(response);
426
				goto fin;
426
				goto fin;
427
			}
427
			}
428

    
   
428

   
429
			if (args.channel_count >= MAX_VALS) {
429
			if (args.channel_count >= MAX_VALS) {
430
				ast_ari_response_error(response, 400,
430
				ast_ari_response_error(response, 400,
431
					"Bad Request",
431
					"Bad Request",
432
					"Too many values for channel");
432
					"Too many values for channel");
433
				goto fin;
433
				goto fin;
434
			}
434
			}
435

    
   
435

   
436
			args.channel = ast_malloc(sizeof(*args.channel) * args.channel_count);
436
			args.channel = ast_malloc(sizeof(*args.channel) * args.channel_count);
437
			if (!args.channel) {
437
			if (!args.channel) {
438
				ast_ari_response_alloc_failed(response);
438
				ast_ari_response_alloc_failed(response);
439
				goto fin;
439
				goto fin;
440
			}
440
			}
441

    
   
441

   
442
			for (j = 0; j < args.channel_count; ++j) {
442
			for (j = 0; j < args.channel_count; ++j) {
443
				args.channel[j] = (vals[j]);
443
				args.channel[j] = (vals[j]);
444
			}
444
			}
445
		} else
445
		} else
446
		{}
446
		{}
447
	}
447
	}
448
	for (i = path_vars; i; i = i->next) {
448
	for (i = path_vars; i; i = i->next) {
449
		if (strcmp(i->name, "bridgeId") == 0) {
449
		if (strcmp(i->name, "bridgeId") == 0) {
450
			args.bridge_id = (i->value);
450
			args.bridge_id = (i->value);
451
		} else
451
		} else
452
		{}
452
		{}
453
	}
453
	}
454
	ast_ari_remove_channel_from_bridge(headers, &args, response);
454
	ast_ari_remove_channel_from_bridge(headers, &args, response);
455
#if defined(AST_DEVMODE)
455
#if defined(AST_DEVMODE)
456
	code = response->response_code;
456
	code = response->response_code;
457

    
   
457

   
458
	switch (code) {
458
	switch (code) {
459
	case 0: /* Implementation is still a stub, or the code wasn't set */
459
	case 0: /* Implementation is still a stub, or the code wasn't set */
460
		is_valid = response->message == NULL;
460
		is_valid = response->message == NULL;
461
		break;
461
		break;
462
	case 500: /* Internal Server Error */
462
	case 500: /* Internal Server Error */
463
	case 501: /* Not Implemented */
463
	case 501: /* Not Implemented */
464
	case 400: /* Channel not found */
464
	case 400: /* Channel not found */
465
	case 404: /* Bridge not found */
465
	case 404: /* Bridge not found */
466
	case 409: /* Bridge not in Stasis application */
466
	case 409: /* Bridge not in Stasis application */
467
	case 422: /* Channel not in this bridge */
467
	case 422: /* Channel not in this bridge */
468
		is_valid = 1;
468
		is_valid = 1;
469
		break;
469
		break;
470
	default:
470
	default:
471
		if (200 <= code && code <= 299) {
471
		if (200 <= code && code <= 299) {
472
			is_valid = ast_ari_validate_void(
472
			is_valid = ast_ari_validate_void(
473
				response->message);
473
				response->message);
474
		} else {
474
		} else {
475
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/removeChannel\n", code);
475
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/removeChannel\n", code);
476
			is_valid = 0;
476
			is_valid = 0;
477
		}
477
		}
478
	}
478
	}
479

    
   
479

   
480
	if (!is_valid) {
480
	if (!is_valid) {
481
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/removeChannel\n");
481
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/removeChannel\n");
482
		ast_ari_response_error(response, 500,
482
		ast_ari_response_error(response, 500,
483
			"Internal Server Error", "Response validation failed");
483
			"Internal Server Error", "Response validation failed");
484
	}
484
	}
485
#endif /* AST_DEVMODE */
485
#endif /* AST_DEVMODE */
486

    
   
486

   
487
fin: __attribute__((unused))
487
fin: __attribute__((unused))
488
	ast_free(args.channel_parse);
488
	ast_free(args.channel_parse);
489
	ast_free(args.channel);
489
	ast_free(args.channel);
490
	return;
490
	return;
491
}
491
}
492
/*!
492
/*!
493
 * \brief Parameter parsing callback for /bridges/{bridgeId}/mohStart.
493
 * \brief Parameter parsing callback for /bridges/{bridgeId}/moh.
494
 * \param get_params GET parameters in the HTTP request.
494
 * \param get_params GET parameters in the HTTP request.
495
 * \param path_vars Path variables extracted from the request.
495
 * \param path_vars Path variables extracted from the request.
496
 * \param headers HTTP headers.
496
 * \param headers HTTP headers.
497
 * \param[out] response Response to the HTTP request.
497
 * \param[out] response Response to the HTTP request.
498
 */
498
 */
499
static void ast_ari_moh_start_bridge_cb(
499
static void ast_ari_moh_start_bridge_cb(
500
	struct ast_variable *get_params, struct ast_variable *path_vars,
500
	struct ast_variable *get_params, struct ast_variable *path_vars,
501
	struct ast_variable *headers, struct ast_ari_response *response)
501
	struct ast_variable *headers, struct ast_ari_response *response)
502
{
502
{
503
	struct ast_moh_start_bridge_args args = {};
503
	struct ast_moh_start_bridge_args args = {};
504
	struct ast_variable *i;
504
	struct ast_variable *i;
505
#if defined(AST_DEVMODE)
505
#if defined(AST_DEVMODE)
506
	int is_valid;
506
	int is_valid;
507
	int code;
507
	int code;
508
#endif /* AST_DEVMODE */
508
#endif /* AST_DEVMODE */
509

    
   
509

   
510
	for (i = get_params; i; i = i->next) {
510
	for (i = get_params; i; i = i->next) {
511
		if (strcmp(i->name, "mohClass") == 0) {
511
		if (strcmp(i->name, "mohClass") == 0) {
512
			args.moh_class = (i->value);
512
			args.moh_class = (i->value);
513
		} else
513
		} else
514
		{}
514
		{}
515
	}
515
	}
516
	for (i = path_vars; i; i = i->next) {
516
	for (i = path_vars; i; i = i->next) {
517
		if (strcmp(i->name, "bridgeId") == 0) {
517
		if (strcmp(i->name, "bridgeId") == 0) {
518
			args.bridge_id = (i->value);
518
			args.bridge_id = (i->value);
519
		} else
519
		} else
520
		{}
520
		{}
521
	}
521
	}
522
	ast_ari_moh_start_bridge(headers, &args, response);
522
	ast_ari_moh_start_bridge(headers, &args, response);
523
#if defined(AST_DEVMODE)
523
#if defined(AST_DEVMODE)
524
	code = response->response_code;
524
	code = response->response_code;
525

    
   
525

   
526
	switch (code) {
526
	switch (code) {
527
	case 0: /* Implementation is still a stub, or the code wasn't set */
527
	case 0: /* Implementation is still a stub, or the code wasn't set */
528
		is_valid = response->message == NULL;
528
		is_valid = response->message == NULL;
529
		break;
529
		break;
530
	case 500: /* Internal Server Error */
530
	case 500: /* Internal Server Error */
531
	case 501: /* Not Implemented */
531
	case 501: /* Not Implemented */
532
	case 404: /* Bridge not found */
532
	case 404: /* Bridge not found */
533
	case 409: /* Bridge not in Stasis application */
533
	case 409: /* Bridge not in Stasis application */
534
		is_valid = 1;
534
		is_valid = 1;
535
		break;
535
		break;
536
	default:
536
	default:
537
		if (200 <= code && code <= 299) {
537
		if (200 <= code && code <= 299) {
538
			is_valid = ast_ari_validate_void(
538
			is_valid = ast_ari_validate_void(
539
				response->message);
539
				response->message);
540
		} else {
540
		} else {
541
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/mohStart\n", code);
541
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/moh\n", code);
542
			is_valid = 0;
542
			is_valid = 0;
543
		}
543
		}
544
	}
544
	}
545

    
   
545

   
546
	if (!is_valid) {
546
	if (!is_valid) {
547
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/mohStart\n");
547
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/moh\n");
548
		ast_ari_response_error(response, 500,
548
		ast_ari_response_error(response, 500,
549
			"Internal Server Error", "Response validation failed");
549
			"Internal Server Error", "Response validation failed");
550
	}
550
	}
551
#endif /* AST_DEVMODE */
551
#endif /* AST_DEVMODE */
552

    
   
552

   
553
fin: __attribute__((unused))
553
fin: __attribute__((unused))
554
	return;
554
	return;
555
}
555
}
556
/*!
556
/*!
557
 * \brief Parameter parsing callback for /bridges/{bridgeId}/mohStop.
557
 * \brief Parameter parsing callback for /bridges/{bridgeId}/moh.
558
 * \param get_params GET parameters in the HTTP request.
558
 * \param get_params GET parameters in the HTTP request.
559
 * \param path_vars Path variables extracted from the request.
559
 * \param path_vars Path variables extracted from the request.
560
 * \param headers HTTP headers.
560
 * \param headers HTTP headers.
561
 * \param[out] response Response to the HTTP request.
561
 * \param[out] response Response to the HTTP request.
562
 */
562
 */
563
static void ast_ari_moh_stop_bridge_cb(
563
static void ast_ari_moh_stop_bridge_cb(
564
	struct ast_variable *get_params, struct ast_variable *path_vars,
564
	struct ast_variable *get_params, struct ast_variable *path_vars,
565
	struct ast_variable *headers, struct ast_ari_response *response)
565
	struct ast_variable *headers, struct ast_ari_response *response)
566
{
566
{
567
	struct ast_moh_stop_bridge_args args = {};
567
	struct ast_moh_stop_bridge_args args = {};
568
	struct ast_variable *i;
568
	struct ast_variable *i;
569
#if defined(AST_DEVMODE)
569
#if defined(AST_DEVMODE)
570
	int is_valid;
570
	int is_valid;
571
	int code;
571
	int code;
572
#endif /* AST_DEVMODE */
572
#endif /* AST_DEVMODE */
573

    
   
573

   
574
	for (i = path_vars; i; i = i->next) {
574
	for (i = path_vars; i; i = i->next) {
575
		if (strcmp(i->name, "bridgeId") == 0) {
575
		if (strcmp(i->name, "bridgeId") == 0) {
576
			args.bridge_id = (i->value);
576
			args.bridge_id = (i->value);
577
		} else
577
		} else
578
		{}
578
		{}
579
	}
579
	}
580
	ast_ari_moh_stop_bridge(headers, &args, response);
580
	ast_ari_moh_stop_bridge(headers, &args, response);
581
#if defined(AST_DEVMODE)
581
#if defined(AST_DEVMODE)
582
	code = response->response_code;
582
	code = response->response_code;
583

    
   
583

   
584
	switch (code) {
584
	switch (code) {
585
	case 0: /* Implementation is still a stub, or the code wasn't set */
585
	case 0: /* Implementation is still a stub, or the code wasn't set */
586
		is_valid = response->message == NULL;
586
		is_valid = response->message == NULL;
587
		break;
587
		break;
588
	case 500: /* Internal Server Error */
588
	case 500: /* Internal Server Error */
589
	case 501: /* Not Implemented */
589
	case 501: /* Not Implemented */
590
	case 404: /* Bridge not found */
590
	case 404: /* Bridge not found */
591
	case 409: /* Bridge not in Stasis application */
591
	case 409: /* Bridge not in Stasis application */
592
		is_valid = 1;
592
		is_valid = 1;
593
		break;
593
		break;
594
	default:
594
	default:
595
		if (200 <= code && code <= 299) {
595
		if (200 <= code && code <= 299) {
596
			is_valid = ast_ari_validate_void(
596
			is_valid = ast_ari_validate_void(
597
				response->message);
597
				response->message);
598
		} else {
598
		} else {
599
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/mohStop\n", code);
599
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/moh\n", code);
600
			is_valid = 0;
600
			is_valid = 0;
601
		}
601
		}
602
	}
602
	}
603

    
   
603

   
604
	if (!is_valid) {
604
	if (!is_valid) {
605
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/mohStop\n");
605
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/moh\n");
606
		ast_ari_response_error(response, 500,
606
		ast_ari_response_error(response, 500,
607
			"Internal Server Error", "Response validation failed");
607
			"Internal Server Error", "Response validation failed");
608
	}
608
	}
609
#endif /* AST_DEVMODE */
609
#endif /* AST_DEVMODE */
610

    
   
610

   
611
fin: __attribute__((unused))
611
fin: __attribute__((unused))
612
	return;
612
	return;
613
}
613
}
614
/*!
614
/*!
615
 * \brief Parameter parsing callback for /bridges/{bridgeId}/play.
615
 * \brief Parameter parsing callback for /bridges/{bridgeId}/play.
616
 * \param get_params GET parameters in the HTTP request.
616
 * \param get_params GET parameters in the HTTP request.
617
 * \param path_vars Path variables extracted from the request.
617
 * \param path_vars Path variables extracted from the request.
618
 * \param headers HTTP headers.
618
 * \param headers HTTP headers.
619
 * \param[out] response Response to the HTTP request.
619
 * \param[out] response Response to the HTTP request.
620
 */
620
 */
621
static void ast_ari_play_on_bridge_cb(
621
static void ast_ari_play_on_bridge_cb(
622
	struct ast_variable *get_params, struct ast_variable *path_vars,
622
	struct ast_variable *get_params, struct ast_variable *path_vars,
623
	struct ast_variable *headers, struct ast_ari_response *response)
623
	struct ast_variable *headers, struct ast_ari_response *response)
624
{
624
{
625
	struct ast_play_on_bridge_args args = {};
625
	struct ast_play_on_bridge_args args = {};
626
	struct ast_variable *i;
626
	struct ast_variable *i;
627
#if defined(AST_DEVMODE)
627
#if defined(AST_DEVMODE)
628
	int is_valid;
628
	int is_valid;
629
	int code;
629
	int code;
630
#endif /* AST_DEVMODE */
630
#endif /* AST_DEVMODE */
631

    
   
631

   
632
	for (i = get_params; i; i = i->next) {
632
	for (i = get_params; i; i = i->next) {
633
		if (strcmp(i->name, "media") == 0) {
633
		if (strcmp(i->name, "media") == 0) {
634
			args.media = (i->value);
634
			args.media = (i->value);
635
		} else
635
		} else
636
		if (strcmp(i->name, "lang") == 0) {
636
		if (strcmp(i->name, "lang") == 0) {
637
			args.lang = (i->value);
637
			args.lang = (i->value);
638
		} else
638
		} else
639
		if (strcmp(i->name, "offsetms") == 0) {
639
		if (strcmp(i->name, "offsetms") == 0) {
640
			args.offsetms = atoi(i->value);
640
			args.offsetms = atoi(i->value);
641
		} else
641
		} else
642
		if (strcmp(i->name, "skipms") == 0) {
642
		if (strcmp(i->name, "skipms") == 0) {
643
			args.skipms = atoi(i->value);
643
			args.skipms = atoi(i->value);
644
		} else
644
		} else
645
		{}
645
		{}
646
	}
646
	}
647
	for (i = path_vars; i; i = i->next) {
647
	for (i = path_vars; i; i = i->next) {
648
		if (strcmp(i->name, "bridgeId") == 0) {
648
		if (strcmp(i->name, "bridgeId") == 0) {
649
			args.bridge_id = (i->value);
649
			args.bridge_id = (i->value);
650
		} else
650
		} else
651
		{}
651
		{}
652
	}
652
	}
653
	ast_ari_play_on_bridge(headers, &args, response);
653
	ast_ari_play_on_bridge(headers, &args, response);
654
#if defined(AST_DEVMODE)
654
#if defined(AST_DEVMODE)
655
	code = response->response_code;
655
	code = response->response_code;
656

    
   
656

   
657
	switch (code) {
657
	switch (code) {
658
	case 0: /* Implementation is still a stub, or the code wasn't set */
658
	case 0: /* Implementation is still a stub, or the code wasn't set */
659
		is_valid = response->message == NULL;
659
		is_valid = response->message == NULL;
660
		break;
660
		break;
661
	case 500: /* Internal Server Error */
661
	case 500: /* Internal Server Error */
662
	case 501: /* Not Implemented */
662
	case 501: /* Not Implemented */
663
	case 404: /* Bridge not found */
663
	case 404: /* Bridge not found */
664
	case 409: /* Bridge not in a Stasis application */
664
	case 409: /* Bridge not in a Stasis application */
665
		is_valid = 1;
665
		is_valid = 1;
666
		break;
666
		break;
667
	default:
667
	default:
668
		if (200 <= code && code <= 299) {
668
		if (200 <= code && code <= 299) {
669
			is_valid = ast_ari_validate_playback(
669
			is_valid = ast_ari_validate_playback(
670
				response->message);
670
				response->message);
671
		} else {
671
		} else {
672
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/play\n", code);
672
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/play\n", code);
673
			is_valid = 0;
673
			is_valid = 0;
674
		}
674
		}
675
	}
675
	}
676

    
   
676

   
677
	if (!is_valid) {
677
	if (!is_valid) {
678
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/play\n");
678
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/play\n");
679
		ast_ari_response_error(response, 500,
679
		ast_ari_response_error(response, 500,
680
			"Internal Server Error", "Response validation failed");
680
			"Internal Server Error", "Response validation failed");
681
	}
681
	}
682
#endif /* AST_DEVMODE */
682
#endif /* AST_DEVMODE */
683

    
   
683

   
684
fin: __attribute__((unused))
684
fin: __attribute__((unused))
685
	return;
685
	return;
686
}
686
}
687
/*!
687
/*!
688
 * \brief Parameter parsing callback for /bridges/{bridgeId}/record.
688
 * \brief Parameter parsing callback for /bridges/{bridgeId}/record.
689
 * \param get_params GET parameters in the HTTP request.
689
 * \param get_params GET parameters in the HTTP request.
690
 * \param path_vars Path variables extracted from the request.
690
 * \param path_vars Path variables extracted from the request.
691
 * \param headers HTTP headers.
691
 * \param headers HTTP headers.
692
 * \param[out] response Response to the HTTP request.
692
 * \param[out] response Response to the HTTP request.
693
 */
693
 */
694
static void ast_ari_record_bridge_cb(
694
static void ast_ari_record_bridge_cb(
695
	struct ast_variable *get_params, struct ast_variable *path_vars,
695
	struct ast_variable *get_params, struct ast_variable *path_vars,
696
	struct ast_variable *headers, struct ast_ari_response *response)
696
	struct ast_variable *headers, struct ast_ari_response *response)
697
{
697
{
698
	struct ast_record_bridge_args args = {};
698
	struct ast_record_bridge_args args = {};
699
	struct ast_variable *i;
699
	struct ast_variable *i;
700
#if defined(AST_DEVMODE)
700
#if defined(AST_DEVMODE)
701
	int is_valid;
701
	int is_valid;
702
	int code;
702
	int code;
703
#endif /* AST_DEVMODE */
703
#endif /* AST_DEVMODE */
704

    
   
704

   
705
	for (i = get_params; i; i = i->next) {
705
	for (i = get_params; i; i = i->next) {
706
		if (strcmp(i->name, "name") == 0) {
706
		if (strcmp(i->name, "name") == 0) {
707
			args.name = (i->value);
707
			args.name = (i->value);
708
		} else
708
		} else
709
		if (strcmp(i->name, "format") == 0) {
709
		if (strcmp(i->name, "format") == 0) {
710
			args.format = (i->value);
710
			args.format = (i->value);
711
		} else
711
		} else
712
		if (strcmp(i->name, "maxDurationSeconds") == 0) {
712
		if (strcmp(i->name, "maxDurationSeconds") == 0) {
713
			args.max_duration_seconds = atoi(i->value);
713
			args.max_duration_seconds = atoi(i->value);
714
		} else
714
		} else
715
		if (strcmp(i->name, "maxSilenceSeconds") == 0) {
715
		if (strcmp(i->name, "maxSilenceSeconds") == 0) {
716
			args.max_silence_seconds = atoi(i->value);
716
			args.max_silence_seconds = atoi(i->value);
717
		} else
717
		} else
718
		if (strcmp(i->name, "ifExists") == 0) {
718
		if (strcmp(i->name, "ifExists") == 0) {
719
			args.if_exists = (i->value);
719
			args.if_exists = (i->value);
720
		} else
720
		} else
721
		if (strcmp(i->name, "beep") == 0) {
721
		if (strcmp(i->name, "beep") == 0) {
722
			args.beep = ast_true(i->value);
722
			args.beep = ast_true(i->value);
723
		} else
723
		} else
724
		if (strcmp(i->name, "terminateOn") == 0) {
724
		if (strcmp(i->name, "terminateOn") == 0) {
725
			args.terminate_on = (i->value);
725
			args.terminate_on = (i->value);
726
		} else
726
		} else
727
		{}
727
		{}
728
	}
728
	}
729
	for (i = path_vars; i; i = i->next) {
729
	for (i = path_vars; i; i = i->next) {
730
		if (strcmp(i->name, "bridgeId") == 0) {
730
		if (strcmp(i->name, "bridgeId") == 0) {
731
			args.bridge_id = (i->value);
731
			args.bridge_id = (i->value);
732
		} else
732
		} else
733
		{}
733
		{}
734
	}
734
	}
735
	ast_ari_record_bridge(headers, &args, response);
735
	ast_ari_record_bridge(headers, &args, response);
736
#if defined(AST_DEVMODE)
736
#if defined(AST_DEVMODE)
737
	code = response->response_code;
737
	code = response->response_code;
738

    
   
738

   
739
	switch (code) {
739
	switch (code) {
740
	case 0: /* Implementation is still a stub, or the code wasn't set */
740
	case 0: /* Implementation is still a stub, or the code wasn't set */
741
		is_valid = response->message == NULL;
741
		is_valid = response->message == NULL;
742
		break;
742
		break;
743
	case 500: /* Internal Server Error */
743
	case 500: /* Internal Server Error */
744
	case 501: /* Not Implemented */
744
	case 501: /* Not Implemented */
745
		is_valid = 1;
745
		is_valid = 1;
746
		break;
746
		break;
747
	default:
747
	default:
748
		if (200 <= code && code <= 299) {
748
		if (200 <= code && code <= 299) {
749
			is_valid = ast_ari_validate_live_recording(
749
			is_valid = ast_ari_validate_live_recording(
750
				response->message);
750
				response->message);
751
		} else {
751
		} else {
752
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/record\n", code);
752
			ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/record\n", code);
753
			is_valid = 0;
753
			is_valid = 0;
754
		}
754
		}
755
	}
755
	}
756

    
   
756

   
757
	if (!is_valid) {
757
	if (!is_valid) {
758
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/record\n");
758
		ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/record\n");
759
		ast_ari_response_error(response, 500,
759
		ast_ari_response_error(response, 500,
760
			"Internal Server Error", "Response validation failed");
760
			"Internal Server Error", "Response validation failed");
761
	}
761
	}
762
#endif /* AST_DEVMODE */
762
#endif /* AST_DEVMODE */
763

    
   
763

   
764
fin: __attribute__((unused))
764
fin: __attribute__((unused))
765
	return;
765
	return;
766
}
766
}
767

    
   
767

   
768
/*! \brief REST handler for /api-docs/bridges.{format} */
768
/*! \brief REST handler for /api-docs/bridges.{format} */
769
static struct stasis_rest_handlers bridges_bridgeId_addChannel = {
769
static struct stasis_rest_handlers bridges_bridgeId_addChannel = {
770
	.path_segment = "addChannel",
770
	.path_segment = "addChannel",
771
	.callbacks = {
771
	.callbacks = {
772
		[AST_HTTP_POST] = ast_ari_add_channel_to_bridge_cb,
772
		[AST_HTTP_POST] = ast_ari_add_channel_to_bridge_cb,
773
	},
773
	},
774
	.num_children = 0,
774
	.num_children = 0,
775
	.children = {  }
775
	.children = {  }
776
};
776
};
777
/*! \brief REST handler for /api-docs/bridges.{format} */
777
/*! \brief REST handler for /api-docs/bridges.{format} */
778
static struct stasis_rest_handlers bridges_bridgeId_removeChannel = {
778
static struct stasis_rest_handlers bridges_bridgeId_removeChannel = {
779
	.path_segment = "removeChannel",
779
	.path_segment = "removeChannel",
780
	.callbacks = {
780
	.callbacks = {
781
		[AST_HTTP_POST] = ast_ari_remove_channel_from_bridge_cb,
781
		[AST_HTTP_POST] = ast_ari_remove_channel_from_bridge_cb,
782
	},
782
	},
783
	.num_children = 0,
783
	.num_children = 0,
784
	.children = {  }
784
	.children = {  }
785
};
785
};
786
/*! \brief REST handler for /api-docs/bridges.{format} */
786
/*! \brief REST handler for /api-docs/bridges.{format} */
787
static struct stasis_rest_handlers bridges_bridgeId_mohStart = {
787
static struct stasis_rest_handlers bridges_bridgeId_moh = {
788
	.path_segment = "mohStart",
788
	.path_segment = "moh",
789
	.callbacks = {
789
	.callbacks = {
790
		[AST_HTTP_POST] = ast_ari_moh_start_bridge_cb,
790
		[AST_HTTP_POST] = ast_ari_moh_start_bridge_cb,

    
   
791
		[AST_HTTP_DELETE] = ast_ari_moh_stop_bridge_cb,
791
	},
792
	},
792
	.num_children = 0,
793
	.num_children = 0,
793
	.children = {  }
794
	.children = {  }
794
};
795
};
795
/*! \brief REST handler for /api-docs/bridges.{format} */
796
/*! \brief REST handler for /api-docs/bridges.{format} */
796
static struct stasis_rest_handlers bridges_bridgeId_mohStop = {

   
797
	.path_segment = "mohStop",

   
798
	.callbacks = {

   
799
		[AST_HTTP_POST] = ast_ari_moh_stop_bridge_cb,

   
800
	},

   
801
	.num_children = 0,

   
802
	.children = {  }

   
803
};

   
804
/*! \brief REST handler for /api-docs/bridges.{format} */

   
805
static struct stasis_rest_handlers bridges_bridgeId_play = {
797
static struct stasis_rest_handlers bridges_bridgeId_play = {
806
	.path_segment = "play",
798
	.path_segment = "play",
807
	.callbacks = {
799
	.callbacks = {
808
		[AST_HTTP_POST] = ast_ari_play_on_bridge_cb,
800
		[AST_HTTP_POST] = ast_ari_play_on_bridge_cb,
809
	},
801
	},
810
	.num_children = 0,
802
	.num_children = 0,
811
	.children = {  }
803
	.children = {  }
812
};
804
};
813
/*! \brief REST handler for /api-docs/bridges.{format} */
805
/*! \brief REST handler for /api-docs/bridges.{format} */
814
static struct stasis_rest_handlers bridges_bridgeId_record = {
806
static struct stasis_rest_handlers bridges_bridgeId_record = {
815
	.path_segment = "record",
807
	.path_segment = "record",
816
	.callbacks = {
808
	.callbacks = {
817
		[AST_HTTP_POST] = ast_ari_record_bridge_cb,
809
		[AST_HTTP_POST] = ast_ari_record_bridge_cb,
818
	},
810
	},
819
	.num_children = 0,
811
	.num_children = 0,
820
	.children = {  }
812
	.children = {  }
821
};
813
};
822
/*! \brief REST handler for /api-docs/bridges.{format} */
814
/*! \brief REST handler for /api-docs/bridges.{format} */
823
static struct stasis_rest_handlers bridges_bridgeId = {
815
static struct stasis_rest_handlers bridges_bridgeId = {
824
	.path_segment = "bridgeId",
816
	.path_segment = "bridgeId",
825
	.is_wildcard = 1,
817
	.is_wildcard = 1,
826
	.callbacks = {
818
	.callbacks = {
827
		[AST_HTTP_GET] = ast_ari_get_bridge_cb,
819
		[AST_HTTP_GET] = ast_ari_get_bridge_cb,
828
		[AST_HTTP_DELETE] = ast_ari_delete_bridge_cb,
820
		[AST_HTTP_DELETE] = ast_ari_delete_bridge_cb,
829
	},
821
	},
830
	.num_children = 6,
822
	.num_children = 5,
831
	.children = { &bridges_bridgeId_addChannel,&bridges_bridgeId_removeChannel,&bridges_bridgeId_mohStart,&bridges_bridgeId_mohStop,&bridges_bridgeId_play,&bridges_bridgeId_record, }
823
	.children = { &bridges_bridgeId_addChannel,&bridges_bridgeId_removeChannel,&bridges_bridgeId_moh,&bridges_bridgeId_play,&bridges_bridgeId_record, }
832
};
824
};
833
/*! \brief REST handler for /api-docs/bridges.{format} */
825
/*! \brief REST handler for /api-docs/bridges.{format} */
834
static struct stasis_rest_handlers bridges = {
826
static struct stasis_rest_handlers bridges = {
835
	.path_segment = "bridges",
827
	.path_segment = "bridges",
836
	.callbacks = {
828
	.callbacks = {
837
		[AST_HTTP_GET] = ast_ari_get_bridges_cb,
829
		[AST_HTTP_GET] = ast_ari_get_bridges_cb,
838
		[AST_HTTP_POST] = ast_ari_new_bridge_cb,
830
		[AST_HTTP_POST] = ast_ari_new_bridge_cb,
839
	},
831
	},
840
	.num_children = 1,
832
	.num_children = 1,
841
	.children = { &bridges_bridgeId, }
833
	.children = { &bridges_bridgeId, }
842
};
834
};
843

    
   
835

   
844
static int load_module(void)
836
static int load_module(void)
845
{
837
{
846
	int res = 0;
838
	int res = 0;
847
	stasis_app_ref();
839
	stasis_app_ref();
848
	res |= ast_ari_add_handler(&bridges);
840
	res |= ast_ari_add_handler(&bridges);
849
	return res;
841
	return res;
850
}
842
}
851

    
   
843

   
852
static int unload_module(void)
844
static int unload_module(void)
853
{
845
{
854
	ast_ari_remove_handler(&bridges);
846
	ast_ari_remove_handler(&bridges);
855
	stasis_app_unref();
847
	stasis_app_unref();
856
	return 0;
848
	return 0;
857
}
849
}
858

    
   
850

   
859
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Bridge resources",
851
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Bridge resources",
860
	.load = load_module,
852
	.load = load_module,
861
	.unload = unload_module,
853
	.unload = unload_module,
862
	.nonoptreq = "res_ari,res_stasis",
854
	.nonoptreq = "res_ari,res_stasis",
863
	);
855
	);
trunk/rest-api/api-docs/bridges.json
Revision 401007 New Change
 
  1. trunk/res/res_ari_bridges.c: Loading...
  2. trunk/rest-api/api-docs/bridges.json: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.