res_ari_recordings.c 25 KB

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