res_ari_bridges.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2012 - 2013, Digium, Inc.
  5. *
  6. * David M. Lee, II <dlee@digium.com>
  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. * !!!!! DO NOT EDIT !!!!!
  21. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  22. * This file is generated by a mustache template. Please see the original
  23. * template in rest-api-templates/res_ari_resource.c.mustache
  24. */
  25. /*! \file
  26. *
  27. * \brief Bridge resources
  28. *
  29. * \author David M. Lee, II <dlee@digium.com>
  30. */
  31. /*** MODULEINFO
  32. <depend type="module">res_ari</depend>
  33. <depend type="module">res_ari_model</depend>
  34. <depend type="module">res_stasis</depend>
  35. <support_level>core</support_level>
  36. ***/
  37. #include "asterisk.h"
  38. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  39. #include "asterisk/app.h"
  40. #include "asterisk/module.h"
  41. #include "asterisk/stasis_app.h"
  42. #include "ari/resource_bridges.h"
  43. #if defined(AST_DEVMODE)
  44. #include "ari/ari_model_validators.h"
  45. #endif
  46. #define MAX_VALS 128
  47. /*!
  48. * \brief Parameter parsing callback for /bridges.
  49. * \param get_params GET parameters in the HTTP request.
  50. * \param path_vars Path variables extracted from the request.
  51. * \param headers HTTP headers.
  52. * \param[out] response Response to the HTTP request.
  53. */
  54. static void ast_ari_bridges_list_cb(
  55. struct ast_tcptls_session_instance *ser,
  56. struct ast_variable *get_params, struct ast_variable *path_vars,
  57. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  58. {
  59. struct ast_ari_bridges_list_args args = {};
  60. #if defined(AST_DEVMODE)
  61. int is_valid;
  62. int code;
  63. #endif /* AST_DEVMODE */
  64. ast_ari_bridges_list(headers, &args, response);
  65. #if defined(AST_DEVMODE)
  66. code = response->response_code;
  67. switch (code) {
  68. case 0: /* Implementation is still a stub, or the code wasn't set */
  69. is_valid = response->message == NULL;
  70. break;
  71. case 500: /* Internal Server Error */
  72. case 501: /* Not Implemented */
  73. is_valid = 1;
  74. break;
  75. default:
  76. if (200 <= code && code <= 299) {
  77. is_valid = ast_ari_validate_list(response->message,
  78. ast_ari_validate_bridge_fn());
  79. } else {
  80. ast_log(LOG_ERROR, "Invalid error response %d for /bridges\n", code);
  81. is_valid = 0;
  82. }
  83. }
  84. if (!is_valid) {
  85. ast_log(LOG_ERROR, "Response validation failed for /bridges\n");
  86. ast_ari_response_error(response, 500,
  87. "Internal Server Error", "Response validation failed");
  88. }
  89. #endif /* AST_DEVMODE */
  90. fin: __attribute__((unused))
  91. return;
  92. }
  93. int ast_ari_bridges_create_parse_body(
  94. struct ast_json *body,
  95. struct ast_ari_bridges_create_args *args)
  96. {
  97. struct ast_json *field;
  98. /* Parse query parameters out of it */
  99. field = ast_json_object_get(body, "type");
  100. if (field) {
  101. args->type = ast_json_string_get(field);
  102. }
  103. field = ast_json_object_get(body, "bridgeId");
  104. if (field) {
  105. args->bridge_id = ast_json_string_get(field);
  106. }
  107. field = ast_json_object_get(body, "name");
  108. if (field) {
  109. args->name = ast_json_string_get(field);
  110. }
  111. return 0;
  112. }
  113. /*!
  114. * \brief Parameter parsing callback for /bridges.
  115. * \param get_params GET parameters in the HTTP request.
  116. * \param path_vars Path variables extracted from the request.
  117. * \param headers HTTP headers.
  118. * \param[out] response Response to the HTTP request.
  119. */
  120. static void ast_ari_bridges_create_cb(
  121. struct ast_tcptls_session_instance *ser,
  122. struct ast_variable *get_params, struct ast_variable *path_vars,
  123. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  124. {
  125. struct ast_ari_bridges_create_args args = {};
  126. struct ast_variable *i;
  127. #if defined(AST_DEVMODE)
  128. int is_valid;
  129. int code;
  130. #endif /* AST_DEVMODE */
  131. for (i = get_params; i; i = i->next) {
  132. if (strcmp(i->name, "type") == 0) {
  133. args.type = (i->value);
  134. } else
  135. if (strcmp(i->name, "bridgeId") == 0) {
  136. args.bridge_id = (i->value);
  137. } else
  138. if (strcmp(i->name, "name") == 0) {
  139. args.name = (i->value);
  140. } else
  141. {}
  142. }
  143. if (ast_ari_bridges_create_parse_body(body, &args)) {
  144. ast_ari_response_alloc_failed(response);
  145. goto fin;
  146. }
  147. ast_ari_bridges_create(headers, &args, response);
  148. #if defined(AST_DEVMODE)
  149. code = response->response_code;
  150. switch (code) {
  151. case 0: /* Implementation is still a stub, or the code wasn't set */
  152. is_valid = response->message == NULL;
  153. break;
  154. case 500: /* Internal Server Error */
  155. case 501: /* Not Implemented */
  156. is_valid = 1;
  157. break;
  158. default:
  159. if (200 <= code && code <= 299) {
  160. is_valid = ast_ari_validate_bridge(
  161. response->message);
  162. } else {
  163. ast_log(LOG_ERROR, "Invalid error response %d for /bridges\n", code);
  164. is_valid = 0;
  165. }
  166. }
  167. if (!is_valid) {
  168. ast_log(LOG_ERROR, "Response validation failed for /bridges\n");
  169. ast_ari_response_error(response, 500,
  170. "Internal Server Error", "Response validation failed");
  171. }
  172. #endif /* AST_DEVMODE */
  173. fin: __attribute__((unused))
  174. return;
  175. }
  176. int ast_ari_bridges_create_with_id_parse_body(
  177. struct ast_json *body,
  178. struct ast_ari_bridges_create_with_id_args *args)
  179. {
  180. struct ast_json *field;
  181. /* Parse query parameters out of it */
  182. field = ast_json_object_get(body, "type");
  183. if (field) {
  184. args->type = ast_json_string_get(field);
  185. }
  186. field = ast_json_object_get(body, "name");
  187. if (field) {
  188. args->name = ast_json_string_get(field);
  189. }
  190. return 0;
  191. }
  192. /*!
  193. * \brief Parameter parsing callback for /bridges/{bridgeId}.
  194. * \param get_params GET parameters in the HTTP request.
  195. * \param path_vars Path variables extracted from the request.
  196. * \param headers HTTP headers.
  197. * \param[out] response Response to the HTTP request.
  198. */
  199. static void ast_ari_bridges_create_with_id_cb(
  200. struct ast_tcptls_session_instance *ser,
  201. struct ast_variable *get_params, struct ast_variable *path_vars,
  202. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  203. {
  204. struct ast_ari_bridges_create_with_id_args args = {};
  205. struct ast_variable *i;
  206. #if defined(AST_DEVMODE)
  207. int is_valid;
  208. int code;
  209. #endif /* AST_DEVMODE */
  210. for (i = get_params; i; i = i->next) {
  211. if (strcmp(i->name, "type") == 0) {
  212. args.type = (i->value);
  213. } else
  214. if (strcmp(i->name, "name") == 0) {
  215. args.name = (i->value);
  216. } else
  217. {}
  218. }
  219. for (i = path_vars; i; i = i->next) {
  220. if (strcmp(i->name, "bridgeId") == 0) {
  221. args.bridge_id = (i->value);
  222. } else
  223. {}
  224. }
  225. if (ast_ari_bridges_create_with_id_parse_body(body, &args)) {
  226. ast_ari_response_alloc_failed(response);
  227. goto fin;
  228. }
  229. ast_ari_bridges_create_with_id(headers, &args, response);
  230. #if defined(AST_DEVMODE)
  231. code = response->response_code;
  232. switch (code) {
  233. case 0: /* Implementation is still a stub, or the code wasn't set */
  234. is_valid = response->message == NULL;
  235. break;
  236. case 500: /* Internal Server Error */
  237. case 501: /* Not Implemented */
  238. is_valid = 1;
  239. break;
  240. default:
  241. if (200 <= code && code <= 299) {
  242. is_valid = ast_ari_validate_bridge(
  243. response->message);
  244. } else {
  245. ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}\n", code);
  246. is_valid = 0;
  247. }
  248. }
  249. if (!is_valid) {
  250. ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}\n");
  251. ast_ari_response_error(response, 500,
  252. "Internal Server Error", "Response validation failed");
  253. }
  254. #endif /* AST_DEVMODE */
  255. fin: __attribute__((unused))
  256. return;
  257. }
  258. /*!
  259. * \brief Parameter parsing callback for /bridges/{bridgeId}.
  260. * \param get_params GET parameters in the HTTP request.
  261. * \param path_vars Path variables extracted from the request.
  262. * \param headers HTTP headers.
  263. * \param[out] response Response to the HTTP request.
  264. */
  265. static void ast_ari_bridges_get_cb(
  266. struct ast_tcptls_session_instance *ser,
  267. struct ast_variable *get_params, struct ast_variable *path_vars,
  268. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  269. {
  270. struct ast_ari_bridges_get_args args = {};
  271. struct ast_variable *i;
  272. #if defined(AST_DEVMODE)
  273. int is_valid;
  274. int code;
  275. #endif /* AST_DEVMODE */
  276. for (i = path_vars; i; i = i->next) {
  277. if (strcmp(i->name, "bridgeId") == 0) {
  278. args.bridge_id = (i->value);
  279. } else
  280. {}
  281. }
  282. ast_ari_bridges_get(headers, &args, response);
  283. #if defined(AST_DEVMODE)
  284. code = response->response_code;
  285. switch (code) {
  286. case 0: /* Implementation is still a stub, or the code wasn't set */
  287. is_valid = response->message == NULL;
  288. break;
  289. case 500: /* Internal Server Error */
  290. case 501: /* Not Implemented */
  291. case 404: /* Bridge not found */
  292. is_valid = 1;
  293. break;
  294. default:
  295. if (200 <= code && code <= 299) {
  296. is_valid = ast_ari_validate_bridge(
  297. response->message);
  298. } else {
  299. ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}\n", code);
  300. is_valid = 0;
  301. }
  302. }
  303. if (!is_valid) {
  304. ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}\n");
  305. ast_ari_response_error(response, 500,
  306. "Internal Server Error", "Response validation failed");
  307. }
  308. #endif /* AST_DEVMODE */
  309. fin: __attribute__((unused))
  310. return;
  311. }
  312. /*!
  313. * \brief Parameter parsing callback for /bridges/{bridgeId}.
  314. * \param get_params GET parameters in the HTTP request.
  315. * \param path_vars Path variables extracted from the request.
  316. * \param headers HTTP headers.
  317. * \param[out] response Response to the HTTP request.
  318. */
  319. static void ast_ari_bridges_destroy_cb(
  320. struct ast_tcptls_session_instance *ser,
  321. struct ast_variable *get_params, struct ast_variable *path_vars,
  322. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  323. {
  324. struct ast_ari_bridges_destroy_args args = {};
  325. struct ast_variable *i;
  326. #if defined(AST_DEVMODE)
  327. int is_valid;
  328. int code;
  329. #endif /* AST_DEVMODE */
  330. for (i = path_vars; i; i = i->next) {
  331. if (strcmp(i->name, "bridgeId") == 0) {
  332. args.bridge_id = (i->value);
  333. } else
  334. {}
  335. }
  336. ast_ari_bridges_destroy(headers, &args, response);
  337. #if defined(AST_DEVMODE)
  338. code = response->response_code;
  339. switch (code) {
  340. case 0: /* Implementation is still a stub, or the code wasn't set */
  341. is_valid = response->message == NULL;
  342. break;
  343. case 500: /* Internal Server Error */
  344. case 501: /* Not Implemented */
  345. case 404: /* Bridge not found */
  346. is_valid = 1;
  347. break;
  348. default:
  349. if (200 <= code && code <= 299) {
  350. is_valid = ast_ari_validate_void(
  351. response->message);
  352. } else {
  353. ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}\n", code);
  354. is_valid = 0;
  355. }
  356. }
  357. if (!is_valid) {
  358. ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}\n");
  359. ast_ari_response_error(response, 500,
  360. "Internal Server Error", "Response validation failed");
  361. }
  362. #endif /* AST_DEVMODE */
  363. fin: __attribute__((unused))
  364. return;
  365. }
  366. int ast_ari_bridges_add_channel_parse_body(
  367. struct ast_json *body,
  368. struct ast_ari_bridges_add_channel_args *args)
  369. {
  370. struct ast_json *field;
  371. /* Parse query parameters out of it */
  372. field = ast_json_object_get(body, "channel");
  373. if (field) {
  374. /* If they were silly enough to both pass in a query param and a
  375. * JSON body, free up the query value.
  376. */
  377. ast_free(args->channel);
  378. if (ast_json_typeof(field) == AST_JSON_ARRAY) {
  379. /* Multiple param passed as array */
  380. size_t i;
  381. args->channel_count = ast_json_array_size(field);
  382. args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
  383. if (!args->channel) {
  384. return -1;
  385. }
  386. for (i = 0; i < args->channel_count; ++i) {
  387. args->channel[i] = ast_json_string_get(ast_json_array_get(field, i));
  388. }
  389. } else {
  390. /* Multiple param passed as single value */
  391. args->channel_count = 1;
  392. args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
  393. if (!args->channel) {
  394. return -1;
  395. }
  396. args->channel[0] = ast_json_string_get(field);
  397. }
  398. }
  399. field = ast_json_object_get(body, "role");
  400. if (field) {
  401. args->role = ast_json_string_get(field);
  402. }
  403. return 0;
  404. }
  405. /*!
  406. * \brief Parameter parsing callback for /bridges/{bridgeId}/addChannel.
  407. * \param get_params GET parameters in the HTTP request.
  408. * \param path_vars Path variables extracted from the request.
  409. * \param headers HTTP headers.
  410. * \param[out] response Response to the HTTP request.
  411. */
  412. static void ast_ari_bridges_add_channel_cb(
  413. struct ast_tcptls_session_instance *ser,
  414. struct ast_variable *get_params, struct ast_variable *path_vars,
  415. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  416. {
  417. struct ast_ari_bridges_add_channel_args args = {};
  418. struct ast_variable *i;
  419. #if defined(AST_DEVMODE)
  420. int is_valid;
  421. int code;
  422. #endif /* AST_DEVMODE */
  423. for (i = get_params; i; i = i->next) {
  424. if (strcmp(i->name, "channel") == 0) {
  425. /* Parse comma separated list */
  426. char *vals[MAX_VALS];
  427. size_t j;
  428. args.channel_parse = ast_strdup(i->value);
  429. if (!args.channel_parse) {
  430. ast_ari_response_alloc_failed(response);
  431. goto fin;
  432. }
  433. if (strlen(args.channel_parse) == 0) {
  434. /* ast_app_separate_args can't handle "" */
  435. args.channel_count = 1;
  436. vals[0] = args.channel_parse;
  437. } else {
  438. args.channel_count = ast_app_separate_args(
  439. args.channel_parse, ',', vals,
  440. ARRAY_LEN(vals));
  441. }
  442. if (args.channel_count == 0) {
  443. ast_ari_response_alloc_failed(response);
  444. goto fin;
  445. }
  446. if (args.channel_count >= MAX_VALS) {
  447. ast_ari_response_error(response, 400,
  448. "Bad Request",
  449. "Too many values for channel");
  450. goto fin;
  451. }
  452. args.channel = ast_malloc(sizeof(*args.channel) * args.channel_count);
  453. if (!args.channel) {
  454. ast_ari_response_alloc_failed(response);
  455. goto fin;
  456. }
  457. for (j = 0; j < args.channel_count; ++j) {
  458. args.channel[j] = (vals[j]);
  459. }
  460. } else
  461. if (strcmp(i->name, "role") == 0) {
  462. args.role = (i->value);
  463. } else
  464. {}
  465. }
  466. for (i = path_vars; i; i = i->next) {
  467. if (strcmp(i->name, "bridgeId") == 0) {
  468. args.bridge_id = (i->value);
  469. } else
  470. {}
  471. }
  472. if (ast_ari_bridges_add_channel_parse_body(body, &args)) {
  473. ast_ari_response_alloc_failed(response);
  474. goto fin;
  475. }
  476. ast_ari_bridges_add_channel(headers, &args, response);
  477. #if defined(AST_DEVMODE)
  478. code = response->response_code;
  479. switch (code) {
  480. case 0: /* Implementation is still a stub, or the code wasn't set */
  481. is_valid = response->message == NULL;
  482. break;
  483. case 500: /* Internal Server Error */
  484. case 501: /* Not Implemented */
  485. case 400: /* Channel not found */
  486. case 404: /* Bridge not found */
  487. case 409: /* Bridge not in Stasis application; Channel currently recording */
  488. case 422: /* Channel not in Stasis application */
  489. is_valid = 1;
  490. break;
  491. default:
  492. if (200 <= code && code <= 299) {
  493. is_valid = ast_ari_validate_void(
  494. response->message);
  495. } else {
  496. ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/addChannel\n", code);
  497. is_valid = 0;
  498. }
  499. }
  500. if (!is_valid) {
  501. ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/addChannel\n");
  502. ast_ari_response_error(response, 500,
  503. "Internal Server Error", "Response validation failed");
  504. }
  505. #endif /* AST_DEVMODE */
  506. fin: __attribute__((unused))
  507. ast_free(args.channel_parse);
  508. ast_free(args.channel);
  509. return;
  510. }
  511. int ast_ari_bridges_remove_channel_parse_body(
  512. struct ast_json *body,
  513. struct ast_ari_bridges_remove_channel_args *args)
  514. {
  515. struct ast_json *field;
  516. /* Parse query parameters out of it */
  517. field = ast_json_object_get(body, "channel");
  518. if (field) {
  519. /* If they were silly enough to both pass in a query param and a
  520. * JSON body, free up the query value.
  521. */
  522. ast_free(args->channel);
  523. if (ast_json_typeof(field) == AST_JSON_ARRAY) {
  524. /* Multiple param passed as array */
  525. size_t i;
  526. args->channel_count = ast_json_array_size(field);
  527. args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
  528. if (!args->channel) {
  529. return -1;
  530. }
  531. for (i = 0; i < args->channel_count; ++i) {
  532. args->channel[i] = ast_json_string_get(ast_json_array_get(field, i));
  533. }
  534. } else {
  535. /* Multiple param passed as single value */
  536. args->channel_count = 1;
  537. args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
  538. if (!args->channel) {
  539. return -1;
  540. }
  541. args->channel[0] = ast_json_string_get(field);
  542. }
  543. }
  544. return 0;
  545. }
  546. /*!
  547. * \brief Parameter parsing callback for /bridges/{bridgeId}/removeChannel.
  548. * \param get_params GET parameters in the HTTP request.
  549. * \param path_vars Path variables extracted from the request.
  550. * \param headers HTTP headers.
  551. * \param[out] response Response to the HTTP request.
  552. */
  553. static void ast_ari_bridges_remove_channel_cb(
  554. struct ast_tcptls_session_instance *ser,
  555. struct ast_variable *get_params, struct ast_variable *path_vars,
  556. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  557. {
  558. struct ast_ari_bridges_remove_channel_args args = {};
  559. struct ast_variable *i;
  560. #if defined(AST_DEVMODE)
  561. int is_valid;
  562. int code;
  563. #endif /* AST_DEVMODE */
  564. for (i = get_params; i; i = i->next) {
  565. if (strcmp(i->name, "channel") == 0) {
  566. /* Parse comma separated list */
  567. char *vals[MAX_VALS];
  568. size_t j;
  569. args.channel_parse = ast_strdup(i->value);
  570. if (!args.channel_parse) {
  571. ast_ari_response_alloc_failed(response);
  572. goto fin;
  573. }
  574. if (strlen(args.channel_parse) == 0) {
  575. /* ast_app_separate_args can't handle "" */
  576. args.channel_count = 1;
  577. vals[0] = args.channel_parse;
  578. } else {
  579. args.channel_count = ast_app_separate_args(
  580. args.channel_parse, ',', vals,
  581. ARRAY_LEN(vals));
  582. }
  583. if (args.channel_count == 0) {
  584. ast_ari_response_alloc_failed(response);
  585. goto fin;
  586. }
  587. if (args.channel_count >= MAX_VALS) {
  588. ast_ari_response_error(response, 400,
  589. "Bad Request",
  590. "Too many values for channel");
  591. goto fin;
  592. }
  593. args.channel = ast_malloc(sizeof(*args.channel) * args.channel_count);
  594. if (!args.channel) {
  595. ast_ari_response_alloc_failed(response);
  596. goto fin;
  597. }
  598. for (j = 0; j < args.channel_count; ++j) {
  599. args.channel[j] = (vals[j]);
  600. }
  601. } else
  602. {}
  603. }
  604. for (i = path_vars; i; i = i->next) {
  605. if (strcmp(i->name, "bridgeId") == 0) {
  606. args.bridge_id = (i->value);
  607. } else
  608. {}
  609. }
  610. if (ast_ari_bridges_remove_channel_parse_body(body, &args)) {
  611. ast_ari_response_alloc_failed(response);
  612. goto fin;
  613. }
  614. ast_ari_bridges_remove_channel(headers, &args, response);
  615. #if defined(AST_DEVMODE)
  616. code = response->response_code;
  617. switch (code) {
  618. case 0: /* Implementation is still a stub, or the code wasn't set */
  619. is_valid = response->message == NULL;
  620. break;
  621. case 500: /* Internal Server Error */
  622. case 501: /* Not Implemented */
  623. case 400: /* Channel not found */
  624. case 404: /* Bridge not found */
  625. case 409: /* Bridge not in Stasis application */
  626. case 422: /* Channel not in this bridge */
  627. is_valid = 1;
  628. break;
  629. default:
  630. if (200 <= code && code <= 299) {
  631. is_valid = ast_ari_validate_void(
  632. response->message);
  633. } else {
  634. ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/removeChannel\n", code);
  635. is_valid = 0;
  636. }
  637. }
  638. if (!is_valid) {
  639. ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/removeChannel\n");
  640. ast_ari_response_error(response, 500,
  641. "Internal Server Error", "Response validation failed");
  642. }
  643. #endif /* AST_DEVMODE */
  644. fin: __attribute__((unused))
  645. ast_free(args.channel_parse);
  646. ast_free(args.channel);
  647. return;
  648. }
  649. /*!
  650. * \brief Parameter parsing callback for /bridges/{bridgeId}/videoSource/{channelId}.
  651. * \param get_params GET parameters in the HTTP request.
  652. * \param path_vars Path variables extracted from the request.
  653. * \param headers HTTP headers.
  654. * \param[out] response Response to the HTTP request.
  655. */
  656. static void ast_ari_bridges_set_video_source_cb(
  657. struct ast_tcptls_session_instance *ser,
  658. struct ast_variable *get_params, struct ast_variable *path_vars,
  659. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  660. {
  661. struct ast_ari_bridges_set_video_source_args args = {};
  662. struct ast_variable *i;
  663. #if defined(AST_DEVMODE)
  664. int is_valid;
  665. int code;
  666. #endif /* AST_DEVMODE */
  667. for (i = path_vars; i; i = i->next) {
  668. if (strcmp(i->name, "bridgeId") == 0) {
  669. args.bridge_id = (i->value);
  670. } else
  671. if (strcmp(i->name, "channelId") == 0) {
  672. args.channel_id = (i->value);
  673. } else
  674. {}
  675. }
  676. ast_ari_bridges_set_video_source(headers, &args, response);
  677. #if defined(AST_DEVMODE)
  678. code = response->response_code;
  679. switch (code) {
  680. case 0: /* Implementation is still a stub, or the code wasn't set */
  681. is_valid = response->message == NULL;
  682. break;
  683. case 500: /* Internal Server Error */
  684. case 501: /* Not Implemented */
  685. case 404: /* Bridge or Channel not found */
  686. case 409: /* Channel not in Stasis application */
  687. case 422: /* Channel not in this Bridge */
  688. is_valid = 1;
  689. break;
  690. default:
  691. if (200 <= code && code <= 299) {
  692. is_valid = ast_ari_validate_void(
  693. response->message);
  694. } else {
  695. ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/videoSource/{channelId}\n", code);
  696. is_valid = 0;
  697. }
  698. }
  699. if (!is_valid) {
  700. ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/videoSource/{channelId}\n");
  701. ast_ari_response_error(response, 500,
  702. "Internal Server Error", "Response validation failed");
  703. }
  704. #endif /* AST_DEVMODE */
  705. fin: __attribute__((unused))
  706. return;
  707. }
  708. /*!
  709. * \brief Parameter parsing callback for /bridges/{bridgeId}/videoSource.
  710. * \param get_params GET parameters in the HTTP request.
  711. * \param path_vars Path variables extracted from the request.
  712. * \param headers HTTP headers.
  713. * \param[out] response Response to the HTTP request.
  714. */
  715. static void ast_ari_bridges_clear_video_source_cb(
  716. struct ast_tcptls_session_instance *ser,
  717. struct ast_variable *get_params, struct ast_variable *path_vars,
  718. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  719. {
  720. struct ast_ari_bridges_clear_video_source_args args = {};
  721. struct ast_variable *i;
  722. #if defined(AST_DEVMODE)
  723. int is_valid;
  724. int code;
  725. #endif /* AST_DEVMODE */
  726. for (i = path_vars; i; i = i->next) {
  727. if (strcmp(i->name, "bridgeId") == 0) {
  728. args.bridge_id = (i->value);
  729. } else
  730. {}
  731. }
  732. ast_ari_bridges_clear_video_source(headers, &args, response);
  733. #if defined(AST_DEVMODE)
  734. code = response->response_code;
  735. switch (code) {
  736. case 0: /* Implementation is still a stub, or the code wasn't set */
  737. is_valid = response->message == NULL;
  738. break;
  739. case 500: /* Internal Server Error */
  740. case 501: /* Not Implemented */
  741. case 404: /* Bridge not found */
  742. is_valid = 1;
  743. break;
  744. default:
  745. if (200 <= code && code <= 299) {
  746. is_valid = ast_ari_validate_void(
  747. response->message);
  748. } else {
  749. ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/videoSource\n", code);
  750. is_valid = 0;
  751. }
  752. }
  753. if (!is_valid) {
  754. ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/videoSource\n");
  755. ast_ari_response_error(response, 500,
  756. "Internal Server Error", "Response validation failed");
  757. }
  758. #endif /* AST_DEVMODE */
  759. fin: __attribute__((unused))
  760. return;
  761. }
  762. int ast_ari_bridges_start_moh_parse_body(
  763. struct ast_json *body,
  764. struct ast_ari_bridges_start_moh_args *args)
  765. {
  766. struct ast_json *field;
  767. /* Parse query parameters out of it */
  768. field = ast_json_object_get(body, "mohClass");
  769. if (field) {
  770. args->moh_class = ast_json_string_get(field);
  771. }
  772. return 0;
  773. }
  774. /*!
  775. * \brief Parameter parsing callback for /bridges/{bridgeId}/moh.
  776. * \param get_params GET parameters in the HTTP request.
  777. * \param path_vars Path variables extracted from the request.
  778. * \param headers HTTP headers.
  779. * \param[out] response Response to the HTTP request.
  780. */
  781. static void ast_ari_bridges_start_moh_cb(
  782. struct ast_tcptls_session_instance *ser,
  783. struct ast_variable *get_params, struct ast_variable *path_vars,
  784. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  785. {
  786. struct ast_ari_bridges_start_moh_args args = {};
  787. struct ast_variable *i;
  788. #if defined(AST_DEVMODE)
  789. int is_valid;
  790. int code;
  791. #endif /* AST_DEVMODE */
  792. for (i = get_params; i; i = i->next) {
  793. if (strcmp(i->name, "mohClass") == 0) {
  794. args.moh_class = (i->value);
  795. } else
  796. {}
  797. }
  798. for (i = path_vars; i; i = i->next) {
  799. if (strcmp(i->name, "bridgeId") == 0) {
  800. args.bridge_id = (i->value);
  801. } else
  802. {}
  803. }
  804. if (ast_ari_bridges_start_moh_parse_body(body, &args)) {
  805. ast_ari_response_alloc_failed(response);
  806. goto fin;
  807. }
  808. ast_ari_bridges_start_moh(headers, &args, response);
  809. #if defined(AST_DEVMODE)
  810. code = response->response_code;
  811. switch (code) {
  812. case 0: /* Implementation is still a stub, or the code wasn't set */
  813. is_valid = response->message == NULL;
  814. break;
  815. case 500: /* Internal Server Error */
  816. case 501: /* Not Implemented */
  817. case 404: /* Bridge not found */
  818. case 409: /* Bridge not in Stasis application */
  819. is_valid = 1;
  820. break;
  821. default:
  822. if (200 <= code && code <= 299) {
  823. is_valid = ast_ari_validate_void(
  824. response->message);
  825. } else {
  826. ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/moh\n", code);
  827. is_valid = 0;
  828. }
  829. }
  830. if (!is_valid) {
  831. ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/moh\n");
  832. ast_ari_response_error(response, 500,
  833. "Internal Server Error", "Response validation failed");
  834. }
  835. #endif /* AST_DEVMODE */
  836. fin: __attribute__((unused))
  837. return;
  838. }
  839. /*!
  840. * \brief Parameter parsing callback for /bridges/{bridgeId}/moh.
  841. * \param get_params GET parameters in the HTTP request.
  842. * \param path_vars Path variables extracted from the request.
  843. * \param headers HTTP headers.
  844. * \param[out] response Response to the HTTP request.
  845. */
  846. static void ast_ari_bridges_stop_moh_cb(
  847. struct ast_tcptls_session_instance *ser,
  848. struct ast_variable *get_params, struct ast_variable *path_vars,
  849. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  850. {
  851. struct ast_ari_bridges_stop_moh_args args = {};
  852. struct ast_variable *i;
  853. #if defined(AST_DEVMODE)
  854. int is_valid;
  855. int code;
  856. #endif /* AST_DEVMODE */
  857. for (i = path_vars; i; i = i->next) {
  858. if (strcmp(i->name, "bridgeId") == 0) {
  859. args.bridge_id = (i->value);
  860. } else
  861. {}
  862. }
  863. ast_ari_bridges_stop_moh(headers, &args, response);
  864. #if defined(AST_DEVMODE)
  865. code = response->response_code;
  866. switch (code) {
  867. case 0: /* Implementation is still a stub, or the code wasn't set */
  868. is_valid = response->message == NULL;
  869. break;
  870. case 500: /* Internal Server Error */
  871. case 501: /* Not Implemented */
  872. case 404: /* Bridge not found */
  873. case 409: /* Bridge not in Stasis application */
  874. is_valid = 1;
  875. break;
  876. default:
  877. if (200 <= code && code <= 299) {
  878. is_valid = ast_ari_validate_void(
  879. response->message);
  880. } else {
  881. ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/moh\n", code);
  882. is_valid = 0;
  883. }
  884. }
  885. if (!is_valid) {
  886. ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/moh\n");
  887. ast_ari_response_error(response, 500,
  888. "Internal Server Error", "Response validation failed");
  889. }
  890. #endif /* AST_DEVMODE */
  891. fin: __attribute__((unused))
  892. return;
  893. }
  894. int ast_ari_bridges_play_parse_body(
  895. struct ast_json *body,
  896. struct ast_ari_bridges_play_args *args)
  897. {
  898. struct ast_json *field;
  899. /* Parse query parameters out of it */
  900. field = ast_json_object_get(body, "media");
  901. if (field) {
  902. args->media = ast_json_string_get(field);
  903. }
  904. field = ast_json_object_get(body, "lang");
  905. if (field) {
  906. args->lang = ast_json_string_get(field);
  907. }
  908. field = ast_json_object_get(body, "offsetms");
  909. if (field) {
  910. args->offsetms = ast_json_integer_get(field);
  911. }
  912. field = ast_json_object_get(body, "skipms");
  913. if (field) {
  914. args->skipms = ast_json_integer_get(field);
  915. }
  916. field = ast_json_object_get(body, "playbackId");
  917. if (field) {
  918. args->playback_id = ast_json_string_get(field);
  919. }
  920. return 0;
  921. }
  922. /*!
  923. * \brief Parameter parsing callback for /bridges/{bridgeId}/play.
  924. * \param get_params GET parameters in the HTTP request.
  925. * \param path_vars Path variables extracted from the request.
  926. * \param headers HTTP headers.
  927. * \param[out] response Response to the HTTP request.
  928. */
  929. static void ast_ari_bridges_play_cb(
  930. struct ast_tcptls_session_instance *ser,
  931. struct ast_variable *get_params, struct ast_variable *path_vars,
  932. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  933. {
  934. struct ast_ari_bridges_play_args args = {};
  935. struct ast_variable *i;
  936. #if defined(AST_DEVMODE)
  937. int is_valid;
  938. int code;
  939. #endif /* AST_DEVMODE */
  940. for (i = get_params; i; i = i->next) {
  941. if (strcmp(i->name, "media") == 0) {
  942. args.media = (i->value);
  943. } else
  944. if (strcmp(i->name, "lang") == 0) {
  945. args.lang = (i->value);
  946. } else
  947. if (strcmp(i->name, "offsetms") == 0) {
  948. args.offsetms = atoi(i->value);
  949. } else
  950. if (strcmp(i->name, "skipms") == 0) {
  951. args.skipms = atoi(i->value);
  952. } else
  953. if (strcmp(i->name, "playbackId") == 0) {
  954. args.playback_id = (i->value);
  955. } else
  956. {}
  957. }
  958. for (i = path_vars; i; i = i->next) {
  959. if (strcmp(i->name, "bridgeId") == 0) {
  960. args.bridge_id = (i->value);
  961. } else
  962. {}
  963. }
  964. if (ast_ari_bridges_play_parse_body(body, &args)) {
  965. ast_ari_response_alloc_failed(response);
  966. goto fin;
  967. }
  968. ast_ari_bridges_play(headers, &args, response);
  969. #if defined(AST_DEVMODE)
  970. code = response->response_code;
  971. switch (code) {
  972. case 0: /* Implementation is still a stub, or the code wasn't set */
  973. is_valid = response->message == NULL;
  974. break;
  975. case 500: /* Internal Server Error */
  976. case 501: /* Not Implemented */
  977. case 404: /* Bridge not found */
  978. case 409: /* Bridge not in a Stasis application */
  979. is_valid = 1;
  980. break;
  981. default:
  982. if (200 <= code && code <= 299) {
  983. is_valid = ast_ari_validate_playback(
  984. response->message);
  985. } else {
  986. ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/play\n", code);
  987. is_valid = 0;
  988. }
  989. }
  990. if (!is_valid) {
  991. ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/play\n");
  992. ast_ari_response_error(response, 500,
  993. "Internal Server Error", "Response validation failed");
  994. }
  995. #endif /* AST_DEVMODE */
  996. fin: __attribute__((unused))
  997. return;
  998. }
  999. int ast_ari_bridges_play_with_id_parse_body(
  1000. struct ast_json *body,
  1001. struct ast_ari_bridges_play_with_id_args *args)
  1002. {
  1003. struct ast_json *field;
  1004. /* Parse query parameters out of it */
  1005. field = ast_json_object_get(body, "media");
  1006. if (field) {
  1007. args->media = ast_json_string_get(field);
  1008. }
  1009. field = ast_json_object_get(body, "lang");
  1010. if (field) {
  1011. args->lang = ast_json_string_get(field);
  1012. }
  1013. field = ast_json_object_get(body, "offsetms");
  1014. if (field) {
  1015. args->offsetms = ast_json_integer_get(field);
  1016. }
  1017. field = ast_json_object_get(body, "skipms");
  1018. if (field) {
  1019. args->skipms = ast_json_integer_get(field);
  1020. }
  1021. return 0;
  1022. }
  1023. /*!
  1024. * \brief Parameter parsing callback for /bridges/{bridgeId}/play/{playbackId}.
  1025. * \param get_params GET parameters in the HTTP request.
  1026. * \param path_vars Path variables extracted from the request.
  1027. * \param headers HTTP headers.
  1028. * \param[out] response Response to the HTTP request.
  1029. */
  1030. static void ast_ari_bridges_play_with_id_cb(
  1031. struct ast_tcptls_session_instance *ser,
  1032. struct ast_variable *get_params, struct ast_variable *path_vars,
  1033. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1034. {
  1035. struct ast_ari_bridges_play_with_id_args args = {};
  1036. struct ast_variable *i;
  1037. #if defined(AST_DEVMODE)
  1038. int is_valid;
  1039. int code;
  1040. #endif /* AST_DEVMODE */
  1041. for (i = get_params; i; i = i->next) {
  1042. if (strcmp(i->name, "media") == 0) {
  1043. args.media = (i->value);
  1044. } else
  1045. if (strcmp(i->name, "lang") == 0) {
  1046. args.lang = (i->value);
  1047. } else
  1048. if (strcmp(i->name, "offsetms") == 0) {
  1049. args.offsetms = atoi(i->value);
  1050. } else
  1051. if (strcmp(i->name, "skipms") == 0) {
  1052. args.skipms = atoi(i->value);
  1053. } else
  1054. {}
  1055. }
  1056. for (i = path_vars; i; i = i->next) {
  1057. if (strcmp(i->name, "bridgeId") == 0) {
  1058. args.bridge_id = (i->value);
  1059. } else
  1060. if (strcmp(i->name, "playbackId") == 0) {
  1061. args.playback_id = (i->value);
  1062. } else
  1063. {}
  1064. }
  1065. if (ast_ari_bridges_play_with_id_parse_body(body, &args)) {
  1066. ast_ari_response_alloc_failed(response);
  1067. goto fin;
  1068. }
  1069. ast_ari_bridges_play_with_id(headers, &args, response);
  1070. #if defined(AST_DEVMODE)
  1071. code = response->response_code;
  1072. switch (code) {
  1073. case 0: /* Implementation is still a stub, or the code wasn't set */
  1074. is_valid = response->message == NULL;
  1075. break;
  1076. case 500: /* Internal Server Error */
  1077. case 501: /* Not Implemented */
  1078. case 404: /* Bridge not found */
  1079. case 409: /* Bridge not in a Stasis application */
  1080. is_valid = 1;
  1081. break;
  1082. default:
  1083. if (200 <= code && code <= 299) {
  1084. is_valid = ast_ari_validate_playback(
  1085. response->message);
  1086. } else {
  1087. ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/play/{playbackId}\n", code);
  1088. is_valid = 0;
  1089. }
  1090. }
  1091. if (!is_valid) {
  1092. ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/play/{playbackId}\n");
  1093. ast_ari_response_error(response, 500,
  1094. "Internal Server Error", "Response validation failed");
  1095. }
  1096. #endif /* AST_DEVMODE */
  1097. fin: __attribute__((unused))
  1098. return;
  1099. }
  1100. int ast_ari_bridges_record_parse_body(
  1101. struct ast_json *body,
  1102. struct ast_ari_bridges_record_args *args)
  1103. {
  1104. struct ast_json *field;
  1105. /* Parse query parameters out of it */
  1106. field = ast_json_object_get(body, "name");
  1107. if (field) {
  1108. args->name = ast_json_string_get(field);
  1109. }
  1110. field = ast_json_object_get(body, "format");
  1111. if (field) {
  1112. args->format = ast_json_string_get(field);
  1113. }
  1114. field = ast_json_object_get(body, "maxDurationSeconds");
  1115. if (field) {
  1116. args->max_duration_seconds = ast_json_integer_get(field);
  1117. }
  1118. field = ast_json_object_get(body, "maxSilenceSeconds");
  1119. if (field) {
  1120. args->max_silence_seconds = ast_json_integer_get(field);
  1121. }
  1122. field = ast_json_object_get(body, "ifExists");
  1123. if (field) {
  1124. args->if_exists = ast_json_string_get(field);
  1125. }
  1126. field = ast_json_object_get(body, "beep");
  1127. if (field) {
  1128. args->beep = ast_json_is_true(field);
  1129. }
  1130. field = ast_json_object_get(body, "terminateOn");
  1131. if (field) {
  1132. args->terminate_on = ast_json_string_get(field);
  1133. }
  1134. return 0;
  1135. }
  1136. /*!
  1137. * \brief Parameter parsing callback for /bridges/{bridgeId}/record.
  1138. * \param get_params GET parameters in the HTTP request.
  1139. * \param path_vars Path variables extracted from the request.
  1140. * \param headers HTTP headers.
  1141. * \param[out] response Response to the HTTP request.
  1142. */
  1143. static void ast_ari_bridges_record_cb(
  1144. struct ast_tcptls_session_instance *ser,
  1145. struct ast_variable *get_params, struct ast_variable *path_vars,
  1146. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1147. {
  1148. struct ast_ari_bridges_record_args args = {};
  1149. struct ast_variable *i;
  1150. #if defined(AST_DEVMODE)
  1151. int is_valid;
  1152. int code;
  1153. #endif /* AST_DEVMODE */
  1154. for (i = get_params; i; i = i->next) {
  1155. if (strcmp(i->name, "name") == 0) {
  1156. args.name = (i->value);
  1157. } else
  1158. if (strcmp(i->name, "format") == 0) {
  1159. args.format = (i->value);
  1160. } else
  1161. if (strcmp(i->name, "maxDurationSeconds") == 0) {
  1162. args.max_duration_seconds = atoi(i->value);
  1163. } else
  1164. if (strcmp(i->name, "maxSilenceSeconds") == 0) {
  1165. args.max_silence_seconds = atoi(i->value);
  1166. } else
  1167. if (strcmp(i->name, "ifExists") == 0) {
  1168. args.if_exists = (i->value);
  1169. } else
  1170. if (strcmp(i->name, "beep") == 0) {
  1171. args.beep = ast_true(i->value);
  1172. } else
  1173. if (strcmp(i->name, "terminateOn") == 0) {
  1174. args.terminate_on = (i->value);
  1175. } else
  1176. {}
  1177. }
  1178. for (i = path_vars; i; i = i->next) {
  1179. if (strcmp(i->name, "bridgeId") == 0) {
  1180. args.bridge_id = (i->value);
  1181. } else
  1182. {}
  1183. }
  1184. if (ast_ari_bridges_record_parse_body(body, &args)) {
  1185. ast_ari_response_alloc_failed(response);
  1186. goto fin;
  1187. }
  1188. ast_ari_bridges_record(headers, &args, response);
  1189. #if defined(AST_DEVMODE)
  1190. code = response->response_code;
  1191. switch (code) {
  1192. case 0: /* Implementation is still a stub, or the code wasn't set */
  1193. is_valid = response->message == NULL;
  1194. break;
  1195. case 500: /* Internal Server Error */
  1196. case 501: /* Not Implemented */
  1197. case 400: /* Invalid parameters */
  1198. case 404: /* Bridge not found */
  1199. case 409: /* Bridge is not in a Stasis application; A recording with the same name already exists on the system and can not be overwritten because it is in progress or ifExists=fail */
  1200. case 422: /* The format specified is unknown on this system */
  1201. is_valid = 1;
  1202. break;
  1203. default:
  1204. if (200 <= code && code <= 299) {
  1205. is_valid = ast_ari_validate_live_recording(
  1206. response->message);
  1207. } else {
  1208. ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/record\n", code);
  1209. is_valid = 0;
  1210. }
  1211. }
  1212. if (!is_valid) {
  1213. ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/record\n");
  1214. ast_ari_response_error(response, 500,
  1215. "Internal Server Error", "Response validation failed");
  1216. }
  1217. #endif /* AST_DEVMODE */
  1218. fin: __attribute__((unused))
  1219. return;
  1220. }
  1221. /*! \brief REST handler for /api-docs/bridges.json */
  1222. static struct stasis_rest_handlers bridges_bridgeId_addChannel = {
  1223. .path_segment = "addChannel",
  1224. .callbacks = {
  1225. [AST_HTTP_POST] = ast_ari_bridges_add_channel_cb,
  1226. },
  1227. .num_children = 0,
  1228. .children = { }
  1229. };
  1230. /*! \brief REST handler for /api-docs/bridges.json */
  1231. static struct stasis_rest_handlers bridges_bridgeId_removeChannel = {
  1232. .path_segment = "removeChannel",
  1233. .callbacks = {
  1234. [AST_HTTP_POST] = ast_ari_bridges_remove_channel_cb,
  1235. },
  1236. .num_children = 0,
  1237. .children = { }
  1238. };
  1239. /*! \brief REST handler for /api-docs/bridges.json */
  1240. static struct stasis_rest_handlers bridges_bridgeId_videoSource_channelId = {
  1241. .path_segment = "channelId",
  1242. .is_wildcard = 1,
  1243. .callbacks = {
  1244. [AST_HTTP_POST] = ast_ari_bridges_set_video_source_cb,
  1245. },
  1246. .num_children = 0,
  1247. .children = { }
  1248. };
  1249. /*! \brief REST handler for /api-docs/bridges.json */
  1250. static struct stasis_rest_handlers bridges_bridgeId_videoSource = {
  1251. .path_segment = "videoSource",
  1252. .callbacks = {
  1253. [AST_HTTP_DELETE] = ast_ari_bridges_clear_video_source_cb,
  1254. },
  1255. .num_children = 1,
  1256. .children = { &bridges_bridgeId_videoSource_channelId, }
  1257. };
  1258. /*! \brief REST handler for /api-docs/bridges.json */
  1259. static struct stasis_rest_handlers bridges_bridgeId_moh = {
  1260. .path_segment = "moh",
  1261. .callbacks = {
  1262. [AST_HTTP_POST] = ast_ari_bridges_start_moh_cb,
  1263. [AST_HTTP_DELETE] = ast_ari_bridges_stop_moh_cb,
  1264. },
  1265. .num_children = 0,
  1266. .children = { }
  1267. };
  1268. /*! \brief REST handler for /api-docs/bridges.json */
  1269. static struct stasis_rest_handlers bridges_bridgeId_play_playbackId = {
  1270. .path_segment = "playbackId",
  1271. .is_wildcard = 1,
  1272. .callbacks = {
  1273. [AST_HTTP_POST] = ast_ari_bridges_play_with_id_cb,
  1274. },
  1275. .num_children = 0,
  1276. .children = { }
  1277. };
  1278. /*! \brief REST handler for /api-docs/bridges.json */
  1279. static struct stasis_rest_handlers bridges_bridgeId_play = {
  1280. .path_segment = "play",
  1281. .callbacks = {
  1282. [AST_HTTP_POST] = ast_ari_bridges_play_cb,
  1283. },
  1284. .num_children = 1,
  1285. .children = { &bridges_bridgeId_play_playbackId, }
  1286. };
  1287. /*! \brief REST handler for /api-docs/bridges.json */
  1288. static struct stasis_rest_handlers bridges_bridgeId_record = {
  1289. .path_segment = "record",
  1290. .callbacks = {
  1291. [AST_HTTP_POST] = ast_ari_bridges_record_cb,
  1292. },
  1293. .num_children = 0,
  1294. .children = { }
  1295. };
  1296. /*! \brief REST handler for /api-docs/bridges.json */
  1297. static struct stasis_rest_handlers bridges_bridgeId = {
  1298. .path_segment = "bridgeId",
  1299. .is_wildcard = 1,
  1300. .callbacks = {
  1301. [AST_HTTP_POST] = ast_ari_bridges_create_with_id_cb,
  1302. [AST_HTTP_GET] = ast_ari_bridges_get_cb,
  1303. [AST_HTTP_DELETE] = ast_ari_bridges_destroy_cb,
  1304. },
  1305. .num_children = 6,
  1306. .children = { &bridges_bridgeId_addChannel,&bridges_bridgeId_removeChannel,&bridges_bridgeId_videoSource,&bridges_bridgeId_moh,&bridges_bridgeId_play,&bridges_bridgeId_record, }
  1307. };
  1308. /*! \brief REST handler for /api-docs/bridges.json */
  1309. static struct stasis_rest_handlers bridges = {
  1310. .path_segment = "bridges",
  1311. .callbacks = {
  1312. [AST_HTTP_GET] = ast_ari_bridges_list_cb,
  1313. [AST_HTTP_POST] = ast_ari_bridges_create_cb,
  1314. },
  1315. .num_children = 1,
  1316. .children = { &bridges_bridgeId, }
  1317. };
  1318. static int unload_module(void)
  1319. {
  1320. ast_ari_remove_handler(&bridges);
  1321. stasis_app_unref();
  1322. return 0;
  1323. }
  1324. static int load_module(void)
  1325. {
  1326. int res = 0;
  1327. CHECK_ARI_MODULE_LOADED();
  1328. stasis_app_ref();
  1329. res |= ast_ari_add_handler(&bridges);
  1330. if (res) {
  1331. unload_module();
  1332. return AST_MODULE_LOAD_DECLINE;
  1333. }
  1334. return AST_MODULE_LOAD_SUCCESS;
  1335. }
  1336. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Bridge resources",
  1337. .support_level = AST_MODULE_SUPPORT_CORE,
  1338. .load = load_module,
  1339. .unload = unload_module,
  1340. );