res_ari_recordings.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  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 Recording 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_recordings.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 /recordings/stored.
  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_recordings_list_stored_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_recordings_list_stored_args args = {};
  60. #if defined(AST_DEVMODE)
  61. int is_valid;
  62. int code;
  63. #endif /* AST_DEVMODE */
  64. ast_ari_recordings_list_stored(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_stored_recording_fn());
  79. } else {
  80. ast_log(LOG_ERROR, "Invalid error response %d for /recordings/stored\n", code);
  81. is_valid = 0;
  82. }
  83. }
  84. if (!is_valid) {
  85. ast_log(LOG_ERROR, "Response validation failed for /recordings/stored\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. /*!
  94. * \brief Parameter parsing callback for /recordings/stored/{recordingName}.
  95. * \param get_params GET parameters in the HTTP request.
  96. * \param path_vars Path variables extracted from the request.
  97. * \param headers HTTP headers.
  98. * \param[out] response Response to the HTTP request.
  99. */
  100. static void ast_ari_recordings_get_stored_cb(
  101. struct ast_tcptls_session_instance *ser,
  102. struct ast_variable *get_params, struct ast_variable *path_vars,
  103. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  104. {
  105. struct ast_ari_recordings_get_stored_args args = {};
  106. struct ast_variable *i;
  107. #if defined(AST_DEVMODE)
  108. int is_valid;
  109. int code;
  110. #endif /* AST_DEVMODE */
  111. for (i = path_vars; i; i = i->next) {
  112. if (strcmp(i->name, "recordingName") == 0) {
  113. args.recording_name = (i->value);
  114. } else
  115. {}
  116. }
  117. ast_ari_recordings_get_stored(headers, &args, response);
  118. #if defined(AST_DEVMODE)
  119. code = response->response_code;
  120. switch (code) {
  121. case 0: /* Implementation is still a stub, or the code wasn't set */
  122. is_valid = response->message == NULL;
  123. break;
  124. case 500: /* Internal Server Error */
  125. case 501: /* Not Implemented */
  126. case 404: /* Recording not found */
  127. is_valid = 1;
  128. break;
  129. default:
  130. if (200 <= code && code <= 299) {
  131. is_valid = ast_ari_validate_stored_recording(
  132. response->message);
  133. } else {
  134. ast_log(LOG_ERROR, "Invalid error response %d for /recordings/stored/{recordingName}\n", code);
  135. is_valid = 0;
  136. }
  137. }
  138. if (!is_valid) {
  139. ast_log(LOG_ERROR, "Response validation failed for /recordings/stored/{recordingName}\n");
  140. ast_ari_response_error(response, 500,
  141. "Internal Server Error", "Response validation failed");
  142. }
  143. #endif /* AST_DEVMODE */
  144. fin: __attribute__((unused))
  145. return;
  146. }
  147. /*!
  148. * \brief Parameter parsing callback for /recordings/stored/{recordingName}.
  149. * \param get_params GET parameters in the HTTP request.
  150. * \param path_vars Path variables extracted from the request.
  151. * \param headers HTTP headers.
  152. * \param[out] response Response to the HTTP request.
  153. */
  154. static void ast_ari_recordings_delete_stored_cb(
  155. struct ast_tcptls_session_instance *ser,
  156. struct ast_variable *get_params, struct ast_variable *path_vars,
  157. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  158. {
  159. struct ast_ari_recordings_delete_stored_args args = {};
  160. struct ast_variable *i;
  161. #if defined(AST_DEVMODE)
  162. int is_valid;
  163. int code;
  164. #endif /* AST_DEVMODE */
  165. for (i = path_vars; i; i = i->next) {
  166. if (strcmp(i->name, "recordingName") == 0) {
  167. args.recording_name = (i->value);
  168. } else
  169. {}
  170. }
  171. ast_ari_recordings_delete_stored(headers, &args, response);
  172. #if defined(AST_DEVMODE)
  173. code = response->response_code;
  174. switch (code) {
  175. case 0: /* Implementation is still a stub, or the code wasn't set */
  176. is_valid = response->message == NULL;
  177. break;
  178. case 500: /* Internal Server Error */
  179. case 501: /* Not Implemented */
  180. case 404: /* Recording not found */
  181. is_valid = 1;
  182. break;
  183. default:
  184. if (200 <= code && code <= 299) {
  185. is_valid = ast_ari_validate_void(
  186. response->message);
  187. } else {
  188. ast_log(LOG_ERROR, "Invalid error response %d for /recordings/stored/{recordingName}\n", code);
  189. is_valid = 0;
  190. }
  191. }
  192. if (!is_valid) {
  193. ast_log(LOG_ERROR, "Response validation failed for /recordings/stored/{recordingName}\n");
  194. ast_ari_response_error(response, 500,
  195. "Internal Server Error", "Response validation failed");
  196. }
  197. #endif /* AST_DEVMODE */
  198. fin: __attribute__((unused))
  199. return;
  200. }
  201. int ast_ari_recordings_copy_stored_parse_body(
  202. struct ast_json *body,
  203. struct ast_ari_recordings_copy_stored_args *args)
  204. {
  205. struct ast_json *field;
  206. /* Parse query parameters out of it */
  207. field = ast_json_object_get(body, "destinationRecordingName");
  208. if (field) {
  209. args->destination_recording_name = ast_json_string_get(field);
  210. }
  211. return 0;
  212. }
  213. /*!
  214. * \brief Parameter parsing callback for /recordings/stored/{recordingName}/copy.
  215. * \param get_params GET parameters in the HTTP request.
  216. * \param path_vars Path variables extracted from the request.
  217. * \param headers HTTP headers.
  218. * \param[out] response Response to the HTTP request.
  219. */
  220. static void ast_ari_recordings_copy_stored_cb(
  221. struct ast_tcptls_session_instance *ser,
  222. struct ast_variable *get_params, struct ast_variable *path_vars,
  223. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  224. {
  225. struct ast_ari_recordings_copy_stored_args args = {};
  226. struct ast_variable *i;
  227. #if defined(AST_DEVMODE)
  228. int is_valid;
  229. int code;
  230. #endif /* AST_DEVMODE */
  231. for (i = get_params; i; i = i->next) {
  232. if (strcmp(i->name, "destinationRecordingName") == 0) {
  233. args.destination_recording_name = (i->value);
  234. } else
  235. {}
  236. }
  237. for (i = path_vars; i; i = i->next) {
  238. if (strcmp(i->name, "recordingName") == 0) {
  239. args.recording_name = (i->value);
  240. } else
  241. {}
  242. }
  243. if (ast_ari_recordings_copy_stored_parse_body(body, &args)) {
  244. ast_ari_response_alloc_failed(response);
  245. goto fin;
  246. }
  247. ast_ari_recordings_copy_stored(headers, &args, response);
  248. #if defined(AST_DEVMODE)
  249. code = response->response_code;
  250. switch (code) {
  251. case 0: /* Implementation is still a stub, or the code wasn't set */
  252. is_valid = response->message == NULL;
  253. break;
  254. case 500: /* Internal Server Error */
  255. case 501: /* Not Implemented */
  256. case 404: /* Recording not found */
  257. case 409: /* A recording with the same name already exists on the system */
  258. is_valid = 1;
  259. break;
  260. default:
  261. if (200 <= code && code <= 299) {
  262. is_valid = ast_ari_validate_stored_recording(
  263. response->message);
  264. } else {
  265. ast_log(LOG_ERROR, "Invalid error response %d for /recordings/stored/{recordingName}/copy\n", code);
  266. is_valid = 0;
  267. }
  268. }
  269. if (!is_valid) {
  270. ast_log(LOG_ERROR, "Response validation failed for /recordings/stored/{recordingName}/copy\n");
  271. ast_ari_response_error(response, 500,
  272. "Internal Server Error", "Response validation failed");
  273. }
  274. #endif /* AST_DEVMODE */
  275. fin: __attribute__((unused))
  276. return;
  277. }
  278. /*!
  279. * \brief Parameter parsing callback for /recordings/live/{recordingName}.
  280. * \param get_params GET parameters in the HTTP request.
  281. * \param path_vars Path variables extracted from the request.
  282. * \param headers HTTP headers.
  283. * \param[out] response Response to the HTTP request.
  284. */
  285. static void ast_ari_recordings_get_live_cb(
  286. struct ast_tcptls_session_instance *ser,
  287. struct ast_variable *get_params, struct ast_variable *path_vars,
  288. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  289. {
  290. struct ast_ari_recordings_get_live_args args = {};
  291. struct ast_variable *i;
  292. #if defined(AST_DEVMODE)
  293. int is_valid;
  294. int code;
  295. #endif /* AST_DEVMODE */
  296. for (i = path_vars; i; i = i->next) {
  297. if (strcmp(i->name, "recordingName") == 0) {
  298. args.recording_name = (i->value);
  299. } else
  300. {}
  301. }
  302. ast_ari_recordings_get_live(headers, &args, response);
  303. #if defined(AST_DEVMODE)
  304. code = response->response_code;
  305. switch (code) {
  306. case 0: /* Implementation is still a stub, or the code wasn't set */
  307. is_valid = response->message == NULL;
  308. break;
  309. case 500: /* Internal Server Error */
  310. case 501: /* Not Implemented */
  311. case 404: /* Recording not found */
  312. is_valid = 1;
  313. break;
  314. default:
  315. if (200 <= code && code <= 299) {
  316. is_valid = ast_ari_validate_live_recording(
  317. response->message);
  318. } else {
  319. ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live/{recordingName}\n", code);
  320. is_valid = 0;
  321. }
  322. }
  323. if (!is_valid) {
  324. ast_log(LOG_ERROR, "Response validation failed for /recordings/live/{recordingName}\n");
  325. ast_ari_response_error(response, 500,
  326. "Internal Server Error", "Response validation failed");
  327. }
  328. #endif /* AST_DEVMODE */
  329. fin: __attribute__((unused))
  330. return;
  331. }
  332. /*!
  333. * \brief Parameter parsing callback for /recordings/live/{recordingName}.
  334. * \param get_params GET parameters in the HTTP request.
  335. * \param path_vars Path variables extracted from the request.
  336. * \param headers HTTP headers.
  337. * \param[out] response Response to the HTTP request.
  338. */
  339. static void ast_ari_recordings_cancel_cb(
  340. struct ast_tcptls_session_instance *ser,
  341. struct ast_variable *get_params, struct ast_variable *path_vars,
  342. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  343. {
  344. struct ast_ari_recordings_cancel_args args = {};
  345. struct ast_variable *i;
  346. #if defined(AST_DEVMODE)
  347. int is_valid;
  348. int code;
  349. #endif /* AST_DEVMODE */
  350. for (i = path_vars; i; i = i->next) {
  351. if (strcmp(i->name, "recordingName") == 0) {
  352. args.recording_name = (i->value);
  353. } else
  354. {}
  355. }
  356. ast_ari_recordings_cancel(headers, &args, response);
  357. #if defined(AST_DEVMODE)
  358. code = response->response_code;
  359. switch (code) {
  360. case 0: /* Implementation is still a stub, or the code wasn't set */
  361. is_valid = response->message == NULL;
  362. break;
  363. case 500: /* Internal Server Error */
  364. case 501: /* Not Implemented */
  365. case 404: /* Recording not found */
  366. is_valid = 1;
  367. break;
  368. default:
  369. if (200 <= code && code <= 299) {
  370. is_valid = ast_ari_validate_void(
  371. response->message);
  372. } else {
  373. ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live/{recordingName}\n", code);
  374. is_valid = 0;
  375. }
  376. }
  377. if (!is_valid) {
  378. ast_log(LOG_ERROR, "Response validation failed for /recordings/live/{recordingName}\n");
  379. ast_ari_response_error(response, 500,
  380. "Internal Server Error", "Response validation failed");
  381. }
  382. #endif /* AST_DEVMODE */
  383. fin: __attribute__((unused))
  384. return;
  385. }
  386. /*!
  387. * \brief Parameter parsing callback for /recordings/live/{recordingName}/stop.
  388. * \param get_params GET parameters in the HTTP request.
  389. * \param path_vars Path variables extracted from the request.
  390. * \param headers HTTP headers.
  391. * \param[out] response Response to the HTTP request.
  392. */
  393. static void ast_ari_recordings_stop_cb(
  394. struct ast_tcptls_session_instance *ser,
  395. struct ast_variable *get_params, struct ast_variable *path_vars,
  396. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  397. {
  398. struct ast_ari_recordings_stop_args args = {};
  399. struct ast_variable *i;
  400. #if defined(AST_DEVMODE)
  401. int is_valid;
  402. int code;
  403. #endif /* AST_DEVMODE */
  404. for (i = path_vars; i; i = i->next) {
  405. if (strcmp(i->name, "recordingName") == 0) {
  406. args.recording_name = (i->value);
  407. } else
  408. {}
  409. }
  410. ast_ari_recordings_stop(headers, &args, response);
  411. #if defined(AST_DEVMODE)
  412. code = response->response_code;
  413. switch (code) {
  414. case 0: /* Implementation is still a stub, or the code wasn't set */
  415. is_valid = response->message == NULL;
  416. break;
  417. case 500: /* Internal Server Error */
  418. case 501: /* Not Implemented */
  419. case 404: /* Recording not found */
  420. is_valid = 1;
  421. break;
  422. default:
  423. if (200 <= code && code <= 299) {
  424. is_valid = ast_ari_validate_void(
  425. response->message);
  426. } else {
  427. ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live/{recordingName}/stop\n", code);
  428. is_valid = 0;
  429. }
  430. }
  431. if (!is_valid) {
  432. ast_log(LOG_ERROR, "Response validation failed for /recordings/live/{recordingName}/stop\n");
  433. ast_ari_response_error(response, 500,
  434. "Internal Server Error", "Response validation failed");
  435. }
  436. #endif /* AST_DEVMODE */
  437. fin: __attribute__((unused))
  438. return;
  439. }
  440. /*!
  441. * \brief Parameter parsing callback for /recordings/live/{recordingName}/pause.
  442. * \param get_params GET parameters in the HTTP request.
  443. * \param path_vars Path variables extracted from the request.
  444. * \param headers HTTP headers.
  445. * \param[out] response Response to the HTTP request.
  446. */
  447. static void ast_ari_recordings_pause_cb(
  448. struct ast_tcptls_session_instance *ser,
  449. struct ast_variable *get_params, struct ast_variable *path_vars,
  450. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  451. {
  452. struct ast_ari_recordings_pause_args args = {};
  453. struct ast_variable *i;
  454. #if defined(AST_DEVMODE)
  455. int is_valid;
  456. int code;
  457. #endif /* AST_DEVMODE */
  458. for (i = path_vars; i; i = i->next) {
  459. if (strcmp(i->name, "recordingName") == 0) {
  460. args.recording_name = (i->value);
  461. } else
  462. {}
  463. }
  464. ast_ari_recordings_pause(headers, &args, response);
  465. #if defined(AST_DEVMODE)
  466. code = response->response_code;
  467. switch (code) {
  468. case 0: /* Implementation is still a stub, or the code wasn't set */
  469. is_valid = response->message == NULL;
  470. break;
  471. case 500: /* Internal Server Error */
  472. case 501: /* Not Implemented */
  473. case 404: /* Recording not found */
  474. case 409: /* Recording not in session */
  475. is_valid = 1;
  476. break;
  477. default:
  478. if (200 <= code && code <= 299) {
  479. is_valid = ast_ari_validate_void(
  480. response->message);
  481. } else {
  482. ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live/{recordingName}/pause\n", code);
  483. is_valid = 0;
  484. }
  485. }
  486. if (!is_valid) {
  487. ast_log(LOG_ERROR, "Response validation failed for /recordings/live/{recordingName}/pause\n");
  488. ast_ari_response_error(response, 500,
  489. "Internal Server Error", "Response validation failed");
  490. }
  491. #endif /* AST_DEVMODE */
  492. fin: __attribute__((unused))
  493. return;
  494. }
  495. /*!
  496. * \brief Parameter parsing callback for /recordings/live/{recordingName}/pause.
  497. * \param get_params GET parameters in the HTTP request.
  498. * \param path_vars Path variables extracted from the request.
  499. * \param headers HTTP headers.
  500. * \param[out] response Response to the HTTP request.
  501. */
  502. static void ast_ari_recordings_unpause_cb(
  503. struct ast_tcptls_session_instance *ser,
  504. struct ast_variable *get_params, struct ast_variable *path_vars,
  505. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  506. {
  507. struct ast_ari_recordings_unpause_args args = {};
  508. struct ast_variable *i;
  509. #if defined(AST_DEVMODE)
  510. int is_valid;
  511. int code;
  512. #endif /* AST_DEVMODE */
  513. for (i = path_vars; i; i = i->next) {
  514. if (strcmp(i->name, "recordingName") == 0) {
  515. args.recording_name = (i->value);
  516. } else
  517. {}
  518. }
  519. ast_ari_recordings_unpause(headers, &args, response);
  520. #if defined(AST_DEVMODE)
  521. code = response->response_code;
  522. switch (code) {
  523. case 0: /* Implementation is still a stub, or the code wasn't set */
  524. is_valid = response->message == NULL;
  525. break;
  526. case 500: /* Internal Server Error */
  527. case 501: /* Not Implemented */
  528. case 404: /* Recording not found */
  529. case 409: /* Recording not in session */
  530. is_valid = 1;
  531. break;
  532. default:
  533. if (200 <= code && code <= 299) {
  534. is_valid = ast_ari_validate_void(
  535. response->message);
  536. } else {
  537. ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live/{recordingName}/pause\n", code);
  538. is_valid = 0;
  539. }
  540. }
  541. if (!is_valid) {
  542. ast_log(LOG_ERROR, "Response validation failed for /recordings/live/{recordingName}/pause\n");
  543. ast_ari_response_error(response, 500,
  544. "Internal Server Error", "Response validation failed");
  545. }
  546. #endif /* AST_DEVMODE */
  547. fin: __attribute__((unused))
  548. return;
  549. }
  550. /*!
  551. * \brief Parameter parsing callback for /recordings/live/{recordingName}/mute.
  552. * \param get_params GET parameters in the HTTP request.
  553. * \param path_vars Path variables extracted from the request.
  554. * \param headers HTTP headers.
  555. * \param[out] response Response to the HTTP request.
  556. */
  557. static void ast_ari_recordings_mute_cb(
  558. struct ast_tcptls_session_instance *ser,
  559. struct ast_variable *get_params, struct ast_variable *path_vars,
  560. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  561. {
  562. struct ast_ari_recordings_mute_args args = {};
  563. struct ast_variable *i;
  564. #if defined(AST_DEVMODE)
  565. int is_valid;
  566. int code;
  567. #endif /* AST_DEVMODE */
  568. for (i = path_vars; i; i = i->next) {
  569. if (strcmp(i->name, "recordingName") == 0) {
  570. args.recording_name = (i->value);
  571. } else
  572. {}
  573. }
  574. ast_ari_recordings_mute(headers, &args, response);
  575. #if defined(AST_DEVMODE)
  576. code = response->response_code;
  577. switch (code) {
  578. case 0: /* Implementation is still a stub, or the code wasn't set */
  579. is_valid = response->message == NULL;
  580. break;
  581. case 500: /* Internal Server Error */
  582. case 501: /* Not Implemented */
  583. case 404: /* Recording not found */
  584. case 409: /* Recording not in session */
  585. is_valid = 1;
  586. break;
  587. default:
  588. if (200 <= code && code <= 299) {
  589. is_valid = ast_ari_validate_void(
  590. response->message);
  591. } else {
  592. ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live/{recordingName}/mute\n", code);
  593. is_valid = 0;
  594. }
  595. }
  596. if (!is_valid) {
  597. ast_log(LOG_ERROR, "Response validation failed for /recordings/live/{recordingName}/mute\n");
  598. ast_ari_response_error(response, 500,
  599. "Internal Server Error", "Response validation failed");
  600. }
  601. #endif /* AST_DEVMODE */
  602. fin: __attribute__((unused))
  603. return;
  604. }
  605. /*!
  606. * \brief Parameter parsing callback for /recordings/live/{recordingName}/mute.
  607. * \param get_params GET parameters in the HTTP request.
  608. * \param path_vars Path variables extracted from the request.
  609. * \param headers HTTP headers.
  610. * \param[out] response Response to the HTTP request.
  611. */
  612. static void ast_ari_recordings_unmute_cb(
  613. struct ast_tcptls_session_instance *ser,
  614. struct ast_variable *get_params, struct ast_variable *path_vars,
  615. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  616. {
  617. struct ast_ari_recordings_unmute_args args = {};
  618. struct ast_variable *i;
  619. #if defined(AST_DEVMODE)
  620. int is_valid;
  621. int code;
  622. #endif /* AST_DEVMODE */
  623. for (i = path_vars; i; i = i->next) {
  624. if (strcmp(i->name, "recordingName") == 0) {
  625. args.recording_name = (i->value);
  626. } else
  627. {}
  628. }
  629. ast_ari_recordings_unmute(headers, &args, response);
  630. #if defined(AST_DEVMODE)
  631. code = response->response_code;
  632. switch (code) {
  633. case 0: /* Implementation is still a stub, or the code wasn't set */
  634. is_valid = response->message == NULL;
  635. break;
  636. case 500: /* Internal Server Error */
  637. case 501: /* Not Implemented */
  638. case 404: /* Recording not found */
  639. case 409: /* Recording not in session */
  640. is_valid = 1;
  641. break;
  642. default:
  643. if (200 <= code && code <= 299) {
  644. is_valid = ast_ari_validate_void(
  645. response->message);
  646. } else {
  647. ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live/{recordingName}/mute\n", code);
  648. is_valid = 0;
  649. }
  650. }
  651. if (!is_valid) {
  652. ast_log(LOG_ERROR, "Response validation failed for /recordings/live/{recordingName}/mute\n");
  653. ast_ari_response_error(response, 500,
  654. "Internal Server Error", "Response validation failed");
  655. }
  656. #endif /* AST_DEVMODE */
  657. fin: __attribute__((unused))
  658. return;
  659. }
  660. /*! \brief REST handler for /api-docs/recordings.json */
  661. static struct stasis_rest_handlers recordings_stored_recordingName_copy = {
  662. .path_segment = "copy",
  663. .callbacks = {
  664. [AST_HTTP_POST] = ast_ari_recordings_copy_stored_cb,
  665. },
  666. .num_children = 0,
  667. .children = { }
  668. };
  669. /*! \brief REST handler for /api-docs/recordings.json */
  670. static struct stasis_rest_handlers recordings_stored_recordingName = {
  671. .path_segment = "recordingName",
  672. .is_wildcard = 1,
  673. .callbacks = {
  674. [AST_HTTP_GET] = ast_ari_recordings_get_stored_cb,
  675. [AST_HTTP_DELETE] = ast_ari_recordings_delete_stored_cb,
  676. },
  677. .num_children = 1,
  678. .children = { &recordings_stored_recordingName_copy, }
  679. };
  680. /*! \brief REST handler for /api-docs/recordings.json */
  681. static struct stasis_rest_handlers recordings_stored = {
  682. .path_segment = "stored",
  683. .callbacks = {
  684. [AST_HTTP_GET] = ast_ari_recordings_list_stored_cb,
  685. },
  686. .num_children = 1,
  687. .children = { &recordings_stored_recordingName, }
  688. };
  689. /*! \brief REST handler for /api-docs/recordings.json */
  690. static struct stasis_rest_handlers recordings_live_recordingName_stop = {
  691. .path_segment = "stop",
  692. .callbacks = {
  693. [AST_HTTP_POST] = ast_ari_recordings_stop_cb,
  694. },
  695. .num_children = 0,
  696. .children = { }
  697. };
  698. /*! \brief REST handler for /api-docs/recordings.json */
  699. static struct stasis_rest_handlers recordings_live_recordingName_pause = {
  700. .path_segment = "pause",
  701. .callbacks = {
  702. [AST_HTTP_POST] = ast_ari_recordings_pause_cb,
  703. [AST_HTTP_DELETE] = ast_ari_recordings_unpause_cb,
  704. },
  705. .num_children = 0,
  706. .children = { }
  707. };
  708. /*! \brief REST handler for /api-docs/recordings.json */
  709. static struct stasis_rest_handlers recordings_live_recordingName_mute = {
  710. .path_segment = "mute",
  711. .callbacks = {
  712. [AST_HTTP_POST] = ast_ari_recordings_mute_cb,
  713. [AST_HTTP_DELETE] = ast_ari_recordings_unmute_cb,
  714. },
  715. .num_children = 0,
  716. .children = { }
  717. };
  718. /*! \brief REST handler for /api-docs/recordings.json */
  719. static struct stasis_rest_handlers recordings_live_recordingName = {
  720. .path_segment = "recordingName",
  721. .is_wildcard = 1,
  722. .callbacks = {
  723. [AST_HTTP_GET] = ast_ari_recordings_get_live_cb,
  724. [AST_HTTP_DELETE] = ast_ari_recordings_cancel_cb,
  725. },
  726. .num_children = 3,
  727. .children = { &recordings_live_recordingName_stop,&recordings_live_recordingName_pause,&recordings_live_recordingName_mute, }
  728. };
  729. /*! \brief REST handler for /api-docs/recordings.json */
  730. static struct stasis_rest_handlers recordings_live = {
  731. .path_segment = "live",
  732. .callbacks = {
  733. },
  734. .num_children = 1,
  735. .children = { &recordings_live_recordingName, }
  736. };
  737. /*! \brief REST handler for /api-docs/recordings.json */
  738. static struct stasis_rest_handlers recordings = {
  739. .path_segment = "recordings",
  740. .callbacks = {
  741. },
  742. .num_children = 2,
  743. .children = { &recordings_stored,&recordings_live, }
  744. };
  745. static int unload_module(void)
  746. {
  747. ast_ari_remove_handler(&recordings);
  748. stasis_app_unref();
  749. return 0;
  750. }
  751. static int load_module(void)
  752. {
  753. int res = 0;
  754. CHECK_ARI_MODULE_LOADED();
  755. stasis_app_ref();
  756. res |= ast_ari_add_handler(&recordings);
  757. if (res) {
  758. unload_module();
  759. return AST_MODULE_LOAD_DECLINE;
  760. }
  761. return AST_MODULE_LOAD_SUCCESS;
  762. }
  763. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Recording resources",
  764. .support_level = AST_MODULE_SUPPORT_CORE,
  765. .load = load_module,
  766. .unload = unload_module,
  767. );