res_ari_recordings.c 27 KB

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