res_ari_asterisk.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  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 Asterisk 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_asterisk.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 /asterisk/config/dynamic/{configClass}/{objectType}/{id}.
  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_asterisk_get_object_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_asterisk_get_object_args args = {};
  60. struct ast_variable *i;
  61. #if defined(AST_DEVMODE)
  62. int is_valid;
  63. int code;
  64. #endif /* AST_DEVMODE */
  65. for (i = path_vars; i; i = i->next) {
  66. if (strcmp(i->name, "configClass") == 0) {
  67. args.config_class = (i->value);
  68. } else
  69. if (strcmp(i->name, "objectType") == 0) {
  70. args.object_type = (i->value);
  71. } else
  72. if (strcmp(i->name, "id") == 0) {
  73. args.id = (i->value);
  74. } else
  75. {}
  76. }
  77. ast_ari_asterisk_get_object(headers, &args, response);
  78. #if defined(AST_DEVMODE)
  79. code = response->response_code;
  80. switch (code) {
  81. case 0: /* Implementation is still a stub, or the code wasn't set */
  82. is_valid = response->message == NULL;
  83. break;
  84. case 500: /* Internal Server Error */
  85. case 501: /* Not Implemented */
  86. case 404: /* {configClass|objectType|id} not found */
  87. is_valid = 1;
  88. break;
  89. default:
  90. if (200 <= code && code <= 299) {
  91. is_valid = ast_ari_validate_list(response->message,
  92. ast_ari_validate_config_tuple_fn());
  93. } else {
  94. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/config/dynamic/{configClass}/{objectType}/{id}\n", code);
  95. is_valid = 0;
  96. }
  97. }
  98. if (!is_valid) {
  99. ast_log(LOG_ERROR, "Response validation failed for /asterisk/config/dynamic/{configClass}/{objectType}/{id}\n");
  100. ast_ari_response_error(response, 500,
  101. "Internal Server Error", "Response validation failed");
  102. }
  103. #endif /* AST_DEVMODE */
  104. fin: __attribute__((unused))
  105. return;
  106. }
  107. int ast_ari_asterisk_update_object_parse_body(
  108. struct ast_json *body,
  109. struct ast_ari_asterisk_update_object_args *args)
  110. {
  111. /* Parse query parameters out of it */
  112. return 0;
  113. }
  114. /*!
  115. * \brief Parameter parsing callback for /asterisk/config/dynamic/{configClass}/{objectType}/{id}.
  116. * \param get_params GET parameters in the HTTP request.
  117. * \param path_vars Path variables extracted from the request.
  118. * \param headers HTTP headers.
  119. * \param[out] response Response to the HTTP request.
  120. */
  121. static void ast_ari_asterisk_update_object_cb(
  122. struct ast_tcptls_session_instance *ser,
  123. struct ast_variable *get_params, struct ast_variable *path_vars,
  124. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  125. {
  126. struct ast_ari_asterisk_update_object_args args = {};
  127. struct ast_variable *i;
  128. #if defined(AST_DEVMODE)
  129. int is_valid;
  130. int code;
  131. #endif /* AST_DEVMODE */
  132. for (i = path_vars; i; i = i->next) {
  133. if (strcmp(i->name, "configClass") == 0) {
  134. args.config_class = (i->value);
  135. } else
  136. if (strcmp(i->name, "objectType") == 0) {
  137. args.object_type = (i->value);
  138. } else
  139. if (strcmp(i->name, "id") == 0) {
  140. args.id = (i->value);
  141. } else
  142. {}
  143. }
  144. args.fields = body;
  145. ast_ari_asterisk_update_object(headers, &args, response);
  146. #if defined(AST_DEVMODE)
  147. code = response->response_code;
  148. switch (code) {
  149. case 0: /* Implementation is still a stub, or the code wasn't set */
  150. is_valid = response->message == NULL;
  151. break;
  152. case 500: /* Internal Server Error */
  153. case 501: /* Not Implemented */
  154. case 400: /* Bad request body */
  155. case 403: /* Could not create or update object */
  156. case 404: /* {configClass|objectType} not found */
  157. is_valid = 1;
  158. break;
  159. default:
  160. if (200 <= code && code <= 299) {
  161. is_valid = ast_ari_validate_list(response->message,
  162. ast_ari_validate_config_tuple_fn());
  163. } else {
  164. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/config/dynamic/{configClass}/{objectType}/{id}\n", code);
  165. is_valid = 0;
  166. }
  167. }
  168. if (!is_valid) {
  169. ast_log(LOG_ERROR, "Response validation failed for /asterisk/config/dynamic/{configClass}/{objectType}/{id}\n");
  170. ast_ari_response_error(response, 500,
  171. "Internal Server Error", "Response validation failed");
  172. }
  173. #endif /* AST_DEVMODE */
  174. fin: __attribute__((unused))
  175. return;
  176. }
  177. /*!
  178. * \brief Parameter parsing callback for /asterisk/config/dynamic/{configClass}/{objectType}/{id}.
  179. * \param get_params GET parameters in the HTTP request.
  180. * \param path_vars Path variables extracted from the request.
  181. * \param headers HTTP headers.
  182. * \param[out] response Response to the HTTP request.
  183. */
  184. static void ast_ari_asterisk_delete_object_cb(
  185. struct ast_tcptls_session_instance *ser,
  186. struct ast_variable *get_params, struct ast_variable *path_vars,
  187. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  188. {
  189. struct ast_ari_asterisk_delete_object_args args = {};
  190. struct ast_variable *i;
  191. #if defined(AST_DEVMODE)
  192. int is_valid;
  193. int code;
  194. #endif /* AST_DEVMODE */
  195. for (i = path_vars; i; i = i->next) {
  196. if (strcmp(i->name, "configClass") == 0) {
  197. args.config_class = (i->value);
  198. } else
  199. if (strcmp(i->name, "objectType") == 0) {
  200. args.object_type = (i->value);
  201. } else
  202. if (strcmp(i->name, "id") == 0) {
  203. args.id = (i->value);
  204. } else
  205. {}
  206. }
  207. ast_ari_asterisk_delete_object(headers, &args, response);
  208. #if defined(AST_DEVMODE)
  209. code = response->response_code;
  210. switch (code) {
  211. case 0: /* Implementation is still a stub, or the code wasn't set */
  212. is_valid = response->message == NULL;
  213. break;
  214. case 500: /* Internal Server Error */
  215. case 501: /* Not Implemented */
  216. case 403: /* Could not delete object */
  217. case 404: /* {configClass|objectType|id} not found */
  218. is_valid = 1;
  219. break;
  220. default:
  221. if (200 <= code && code <= 299) {
  222. is_valid = ast_ari_validate_void(
  223. response->message);
  224. } else {
  225. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/config/dynamic/{configClass}/{objectType}/{id}\n", code);
  226. is_valid = 0;
  227. }
  228. }
  229. if (!is_valid) {
  230. ast_log(LOG_ERROR, "Response validation failed for /asterisk/config/dynamic/{configClass}/{objectType}/{id}\n");
  231. ast_ari_response_error(response, 500,
  232. "Internal Server Error", "Response validation failed");
  233. }
  234. #endif /* AST_DEVMODE */
  235. fin: __attribute__((unused))
  236. return;
  237. }
  238. int ast_ari_asterisk_get_info_parse_body(
  239. struct ast_json *body,
  240. struct ast_ari_asterisk_get_info_args *args)
  241. {
  242. struct ast_json *field;
  243. /* Parse query parameters out of it */
  244. field = ast_json_object_get(body, "only");
  245. if (field) {
  246. /* If they were silly enough to both pass in a query param and a
  247. * JSON body, free up the query value.
  248. */
  249. ast_free(args->only);
  250. if (ast_json_typeof(field) == AST_JSON_ARRAY) {
  251. /* Multiple param passed as array */
  252. size_t i;
  253. args->only_count = ast_json_array_size(field);
  254. args->only = ast_malloc(sizeof(*args->only) * args->only_count);
  255. if (!args->only) {
  256. return -1;
  257. }
  258. for (i = 0; i < args->only_count; ++i) {
  259. args->only[i] = ast_json_string_get(ast_json_array_get(field, i));
  260. }
  261. } else {
  262. /* Multiple param passed as single value */
  263. args->only_count = 1;
  264. args->only = ast_malloc(sizeof(*args->only) * args->only_count);
  265. if (!args->only) {
  266. return -1;
  267. }
  268. args->only[0] = ast_json_string_get(field);
  269. }
  270. }
  271. return 0;
  272. }
  273. /*!
  274. * \brief Parameter parsing callback for /asterisk/info.
  275. * \param get_params GET parameters in the HTTP request.
  276. * \param path_vars Path variables extracted from the request.
  277. * \param headers HTTP headers.
  278. * \param[out] response Response to the HTTP request.
  279. */
  280. static void ast_ari_asterisk_get_info_cb(
  281. struct ast_tcptls_session_instance *ser,
  282. struct ast_variable *get_params, struct ast_variable *path_vars,
  283. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  284. {
  285. struct ast_ari_asterisk_get_info_args args = {};
  286. struct ast_variable *i;
  287. #if defined(AST_DEVMODE)
  288. int is_valid;
  289. int code;
  290. #endif /* AST_DEVMODE */
  291. for (i = get_params; i; i = i->next) {
  292. if (strcmp(i->name, "only") == 0) {
  293. /* Parse comma separated list */
  294. char *vals[MAX_VALS];
  295. size_t j;
  296. args.only_parse = ast_strdup(i->value);
  297. if (!args.only_parse) {
  298. ast_ari_response_alloc_failed(response);
  299. goto fin;
  300. }
  301. if (strlen(args.only_parse) == 0) {
  302. /* ast_app_separate_args can't handle "" */
  303. args.only_count = 1;
  304. vals[0] = args.only_parse;
  305. } else {
  306. args.only_count = ast_app_separate_args(
  307. args.only_parse, ',', vals,
  308. ARRAY_LEN(vals));
  309. }
  310. if (args.only_count == 0) {
  311. ast_ari_response_alloc_failed(response);
  312. goto fin;
  313. }
  314. if (args.only_count >= MAX_VALS) {
  315. ast_ari_response_error(response, 400,
  316. "Bad Request",
  317. "Too many values for only");
  318. goto fin;
  319. }
  320. args.only = ast_malloc(sizeof(*args.only) * args.only_count);
  321. if (!args.only) {
  322. ast_ari_response_alloc_failed(response);
  323. goto fin;
  324. }
  325. for (j = 0; j < args.only_count; ++j) {
  326. args.only[j] = (vals[j]);
  327. }
  328. } else
  329. {}
  330. }
  331. if (ast_ari_asterisk_get_info_parse_body(body, &args)) {
  332. ast_ari_response_alloc_failed(response);
  333. goto fin;
  334. }
  335. ast_ari_asterisk_get_info(headers, &args, response);
  336. #if defined(AST_DEVMODE)
  337. code = response->response_code;
  338. switch (code) {
  339. case 0: /* Implementation is still a stub, or the code wasn't set */
  340. is_valid = response->message == NULL;
  341. break;
  342. case 500: /* Internal Server Error */
  343. case 501: /* Not Implemented */
  344. is_valid = 1;
  345. break;
  346. default:
  347. if (200 <= code && code <= 299) {
  348. is_valid = ast_ari_validate_asterisk_info(
  349. response->message);
  350. } else {
  351. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/info\n", code);
  352. is_valid = 0;
  353. }
  354. }
  355. if (!is_valid) {
  356. ast_log(LOG_ERROR, "Response validation failed for /asterisk/info\n");
  357. ast_ari_response_error(response, 500,
  358. "Internal Server Error", "Response validation failed");
  359. }
  360. #endif /* AST_DEVMODE */
  361. fin: __attribute__((unused))
  362. ast_free(args.only_parse);
  363. ast_free(args.only);
  364. return;
  365. }
  366. /*!
  367. * \brief Parameter parsing callback for /asterisk/ping.
  368. * \param get_params GET parameters in the HTTP request.
  369. * \param path_vars Path variables extracted from the request.
  370. * \param headers HTTP headers.
  371. * \param[out] response Response to the HTTP request.
  372. */
  373. static void ast_ari_asterisk_ping_cb(
  374. struct ast_tcptls_session_instance *ser,
  375. struct ast_variable *get_params, struct ast_variable *path_vars,
  376. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  377. {
  378. struct ast_ari_asterisk_ping_args args = {};
  379. #if defined(AST_DEVMODE)
  380. int is_valid;
  381. int code;
  382. #endif /* AST_DEVMODE */
  383. ast_ari_asterisk_ping(headers, &args, response);
  384. #if defined(AST_DEVMODE)
  385. code = response->response_code;
  386. switch (code) {
  387. case 0: /* Implementation is still a stub, or the code wasn't set */
  388. is_valid = response->message == NULL;
  389. break;
  390. case 500: /* Internal Server Error */
  391. case 501: /* Not Implemented */
  392. is_valid = 1;
  393. break;
  394. default:
  395. if (200 <= code && code <= 299) {
  396. is_valid = ast_ari_validate_asterisk_ping(
  397. response->message);
  398. } else {
  399. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/ping\n", code);
  400. is_valid = 0;
  401. }
  402. }
  403. if (!is_valid) {
  404. ast_log(LOG_ERROR, "Response validation failed for /asterisk/ping\n");
  405. ast_ari_response_error(response, 500,
  406. "Internal Server Error", "Response validation failed");
  407. }
  408. #endif /* AST_DEVMODE */
  409. fin: __attribute__((unused))
  410. return;
  411. }
  412. /*!
  413. * \brief Parameter parsing callback for /asterisk/modules.
  414. * \param get_params GET parameters in the HTTP request.
  415. * \param path_vars Path variables extracted from the request.
  416. * \param headers HTTP headers.
  417. * \param[out] response Response to the HTTP request.
  418. */
  419. static void ast_ari_asterisk_list_modules_cb(
  420. struct ast_tcptls_session_instance *ser,
  421. struct ast_variable *get_params, struct ast_variable *path_vars,
  422. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  423. {
  424. struct ast_ari_asterisk_list_modules_args args = {};
  425. #if defined(AST_DEVMODE)
  426. int is_valid;
  427. int code;
  428. #endif /* AST_DEVMODE */
  429. ast_ari_asterisk_list_modules(headers, &args, response);
  430. #if defined(AST_DEVMODE)
  431. code = response->response_code;
  432. switch (code) {
  433. case 0: /* Implementation is still a stub, or the code wasn't set */
  434. is_valid = response->message == NULL;
  435. break;
  436. case 500: /* Internal Server Error */
  437. case 501: /* Not Implemented */
  438. is_valid = 1;
  439. break;
  440. default:
  441. if (200 <= code && code <= 299) {
  442. is_valid = ast_ari_validate_list(response->message,
  443. ast_ari_validate_module_fn());
  444. } else {
  445. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/modules\n", code);
  446. is_valid = 0;
  447. }
  448. }
  449. if (!is_valid) {
  450. ast_log(LOG_ERROR, "Response validation failed for /asterisk/modules\n");
  451. ast_ari_response_error(response, 500,
  452. "Internal Server Error", "Response validation failed");
  453. }
  454. #endif /* AST_DEVMODE */
  455. fin: __attribute__((unused))
  456. return;
  457. }
  458. /*!
  459. * \brief Parameter parsing callback for /asterisk/modules/{moduleName}.
  460. * \param get_params GET parameters in the HTTP request.
  461. * \param path_vars Path variables extracted from the request.
  462. * \param headers HTTP headers.
  463. * \param[out] response Response to the HTTP request.
  464. */
  465. static void ast_ari_asterisk_get_module_cb(
  466. struct ast_tcptls_session_instance *ser,
  467. struct ast_variable *get_params, struct ast_variable *path_vars,
  468. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  469. {
  470. struct ast_ari_asterisk_get_module_args args = {};
  471. struct ast_variable *i;
  472. #if defined(AST_DEVMODE)
  473. int is_valid;
  474. int code;
  475. #endif /* AST_DEVMODE */
  476. for (i = path_vars; i; i = i->next) {
  477. if (strcmp(i->name, "moduleName") == 0) {
  478. args.module_name = (i->value);
  479. } else
  480. {}
  481. }
  482. ast_ari_asterisk_get_module(headers, &args, response);
  483. #if defined(AST_DEVMODE)
  484. code = response->response_code;
  485. switch (code) {
  486. case 0: /* Implementation is still a stub, or the code wasn't set */
  487. is_valid = response->message == NULL;
  488. break;
  489. case 500: /* Internal Server Error */
  490. case 501: /* Not Implemented */
  491. case 404: /* Module could not be found in running modules. */
  492. case 409: /* Module information could not be retrieved. */
  493. is_valid = 1;
  494. break;
  495. default:
  496. if (200 <= code && code <= 299) {
  497. is_valid = ast_ari_validate_module(
  498. response->message);
  499. } else {
  500. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/modules/{moduleName}\n", code);
  501. is_valid = 0;
  502. }
  503. }
  504. if (!is_valid) {
  505. ast_log(LOG_ERROR, "Response validation failed for /asterisk/modules/{moduleName}\n");
  506. ast_ari_response_error(response, 500,
  507. "Internal Server Error", "Response validation failed");
  508. }
  509. #endif /* AST_DEVMODE */
  510. fin: __attribute__((unused))
  511. return;
  512. }
  513. /*!
  514. * \brief Parameter parsing callback for /asterisk/modules/{moduleName}.
  515. * \param get_params GET parameters in the HTTP request.
  516. * \param path_vars Path variables extracted from the request.
  517. * \param headers HTTP headers.
  518. * \param[out] response Response to the HTTP request.
  519. */
  520. static void ast_ari_asterisk_load_module_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_asterisk_load_module_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, "moduleName") == 0) {
  533. args.module_name = (i->value);
  534. } else
  535. {}
  536. }
  537. ast_ari_asterisk_load_module(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 409: /* Module could not be loaded. */
  547. is_valid = 1;
  548. break;
  549. default:
  550. if (200 <= code && code <= 299) {
  551. is_valid = ast_ari_validate_void(
  552. response->message);
  553. } else {
  554. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/modules/{moduleName}\n", code);
  555. is_valid = 0;
  556. }
  557. }
  558. if (!is_valid) {
  559. ast_log(LOG_ERROR, "Response validation failed for /asterisk/modules/{moduleName}\n");
  560. ast_ari_response_error(response, 500,
  561. "Internal Server Error", "Response validation failed");
  562. }
  563. #endif /* AST_DEVMODE */
  564. fin: __attribute__((unused))
  565. return;
  566. }
  567. /*!
  568. * \brief Parameter parsing callback for /asterisk/modules/{moduleName}.
  569. * \param get_params GET parameters in the HTTP request.
  570. * \param path_vars Path variables extracted from the request.
  571. * \param headers HTTP headers.
  572. * \param[out] response Response to the HTTP request.
  573. */
  574. static void ast_ari_asterisk_unload_module_cb(
  575. struct ast_tcptls_session_instance *ser,
  576. struct ast_variable *get_params, struct ast_variable *path_vars,
  577. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  578. {
  579. struct ast_ari_asterisk_unload_module_args args = {};
  580. struct ast_variable *i;
  581. #if defined(AST_DEVMODE)
  582. int is_valid;
  583. int code;
  584. #endif /* AST_DEVMODE */
  585. for (i = path_vars; i; i = i->next) {
  586. if (strcmp(i->name, "moduleName") == 0) {
  587. args.module_name = (i->value);
  588. } else
  589. {}
  590. }
  591. ast_ari_asterisk_unload_module(headers, &args, response);
  592. #if defined(AST_DEVMODE)
  593. code = response->response_code;
  594. switch (code) {
  595. case 0: /* Implementation is still a stub, or the code wasn't set */
  596. is_valid = response->message == NULL;
  597. break;
  598. case 500: /* Internal Server Error */
  599. case 501: /* Not Implemented */
  600. case 404: /* Module not found in running modules. */
  601. case 409: /* Module could not be unloaded. */
  602. is_valid = 1;
  603. break;
  604. default:
  605. if (200 <= code && code <= 299) {
  606. is_valid = ast_ari_validate_void(
  607. response->message);
  608. } else {
  609. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/modules/{moduleName}\n", code);
  610. is_valid = 0;
  611. }
  612. }
  613. if (!is_valid) {
  614. ast_log(LOG_ERROR, "Response validation failed for /asterisk/modules/{moduleName}\n");
  615. ast_ari_response_error(response, 500,
  616. "Internal Server Error", "Response validation failed");
  617. }
  618. #endif /* AST_DEVMODE */
  619. fin: __attribute__((unused))
  620. return;
  621. }
  622. /*!
  623. * \brief Parameter parsing callback for /asterisk/modules/{moduleName}.
  624. * \param get_params GET parameters in the HTTP request.
  625. * \param path_vars Path variables extracted from the request.
  626. * \param headers HTTP headers.
  627. * \param[out] response Response to the HTTP request.
  628. */
  629. static void ast_ari_asterisk_reload_module_cb(
  630. struct ast_tcptls_session_instance *ser,
  631. struct ast_variable *get_params, struct ast_variable *path_vars,
  632. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  633. {
  634. struct ast_ari_asterisk_reload_module_args args = {};
  635. struct ast_variable *i;
  636. #if defined(AST_DEVMODE)
  637. int is_valid;
  638. int code;
  639. #endif /* AST_DEVMODE */
  640. for (i = path_vars; i; i = i->next) {
  641. if (strcmp(i->name, "moduleName") == 0) {
  642. args.module_name = (i->value);
  643. } else
  644. {}
  645. }
  646. ast_ari_asterisk_reload_module(headers, &args, response);
  647. #if defined(AST_DEVMODE)
  648. code = response->response_code;
  649. switch (code) {
  650. case 0: /* Implementation is still a stub, or the code wasn't set */
  651. is_valid = response->message == NULL;
  652. break;
  653. case 500: /* Internal Server Error */
  654. case 501: /* Not Implemented */
  655. case 404: /* Module not found in running modules. */
  656. case 409: /* Module could not be reloaded. */
  657. is_valid = 1;
  658. break;
  659. default:
  660. if (200 <= code && code <= 299) {
  661. is_valid = ast_ari_validate_void(
  662. response->message);
  663. } else {
  664. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/modules/{moduleName}\n", code);
  665. is_valid = 0;
  666. }
  667. }
  668. if (!is_valid) {
  669. ast_log(LOG_ERROR, "Response validation failed for /asterisk/modules/{moduleName}\n");
  670. ast_ari_response_error(response, 500,
  671. "Internal Server Error", "Response validation failed");
  672. }
  673. #endif /* AST_DEVMODE */
  674. fin: __attribute__((unused))
  675. return;
  676. }
  677. /*!
  678. * \brief Parameter parsing callback for /asterisk/logging.
  679. * \param get_params GET parameters in the HTTP request.
  680. * \param path_vars Path variables extracted from the request.
  681. * \param headers HTTP headers.
  682. * \param[out] response Response to the HTTP request.
  683. */
  684. static void ast_ari_asterisk_list_log_channels_cb(
  685. struct ast_tcptls_session_instance *ser,
  686. struct ast_variable *get_params, struct ast_variable *path_vars,
  687. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  688. {
  689. struct ast_ari_asterisk_list_log_channels_args args = {};
  690. #if defined(AST_DEVMODE)
  691. int is_valid;
  692. int code;
  693. #endif /* AST_DEVMODE */
  694. ast_ari_asterisk_list_log_channels(headers, &args, response);
  695. #if defined(AST_DEVMODE)
  696. code = response->response_code;
  697. switch (code) {
  698. case 0: /* Implementation is still a stub, or the code wasn't set */
  699. is_valid = response->message == NULL;
  700. break;
  701. case 500: /* Internal Server Error */
  702. case 501: /* Not Implemented */
  703. is_valid = 1;
  704. break;
  705. default:
  706. if (200 <= code && code <= 299) {
  707. is_valid = ast_ari_validate_list(response->message,
  708. ast_ari_validate_log_channel_fn());
  709. } else {
  710. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/logging\n", code);
  711. is_valid = 0;
  712. }
  713. }
  714. if (!is_valid) {
  715. ast_log(LOG_ERROR, "Response validation failed for /asterisk/logging\n");
  716. ast_ari_response_error(response, 500,
  717. "Internal Server Error", "Response validation failed");
  718. }
  719. #endif /* AST_DEVMODE */
  720. fin: __attribute__((unused))
  721. return;
  722. }
  723. int ast_ari_asterisk_add_log_parse_body(
  724. struct ast_json *body,
  725. struct ast_ari_asterisk_add_log_args *args)
  726. {
  727. struct ast_json *field;
  728. /* Parse query parameters out of it */
  729. field = ast_json_object_get(body, "configuration");
  730. if (field) {
  731. args->configuration = ast_json_string_get(field);
  732. }
  733. return 0;
  734. }
  735. /*!
  736. * \brief Parameter parsing callback for /asterisk/logging/{logChannelName}.
  737. * \param get_params GET parameters in the HTTP request.
  738. * \param path_vars Path variables extracted from the request.
  739. * \param headers HTTP headers.
  740. * \param[out] response Response to the HTTP request.
  741. */
  742. static void ast_ari_asterisk_add_log_cb(
  743. struct ast_tcptls_session_instance *ser,
  744. struct ast_variable *get_params, struct ast_variable *path_vars,
  745. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  746. {
  747. struct ast_ari_asterisk_add_log_args args = {};
  748. struct ast_variable *i;
  749. #if defined(AST_DEVMODE)
  750. int is_valid;
  751. int code;
  752. #endif /* AST_DEVMODE */
  753. for (i = get_params; i; i = i->next) {
  754. if (strcmp(i->name, "configuration") == 0) {
  755. args.configuration = (i->value);
  756. } else
  757. {}
  758. }
  759. for (i = path_vars; i; i = i->next) {
  760. if (strcmp(i->name, "logChannelName") == 0) {
  761. args.log_channel_name = (i->value);
  762. } else
  763. {}
  764. }
  765. if (ast_ari_asterisk_add_log_parse_body(body, &args)) {
  766. ast_ari_response_alloc_failed(response);
  767. goto fin;
  768. }
  769. ast_ari_asterisk_add_log(headers, &args, response);
  770. #if defined(AST_DEVMODE)
  771. code = response->response_code;
  772. switch (code) {
  773. case 0: /* Implementation is still a stub, or the code wasn't set */
  774. is_valid = response->message == NULL;
  775. break;
  776. case 500: /* Internal Server Error */
  777. case 501: /* Not Implemented */
  778. case 400: /* Bad request body */
  779. case 409: /* Log channel could not be created. */
  780. is_valid = 1;
  781. break;
  782. default:
  783. if (200 <= code && code <= 299) {
  784. is_valid = ast_ari_validate_void(
  785. response->message);
  786. } else {
  787. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/logging/{logChannelName}\n", code);
  788. is_valid = 0;
  789. }
  790. }
  791. if (!is_valid) {
  792. ast_log(LOG_ERROR, "Response validation failed for /asterisk/logging/{logChannelName}\n");
  793. ast_ari_response_error(response, 500,
  794. "Internal Server Error", "Response validation failed");
  795. }
  796. #endif /* AST_DEVMODE */
  797. fin: __attribute__((unused))
  798. return;
  799. }
  800. /*!
  801. * \brief Parameter parsing callback for /asterisk/logging/{logChannelName}.
  802. * \param get_params GET parameters in the HTTP request.
  803. * \param path_vars Path variables extracted from the request.
  804. * \param headers HTTP headers.
  805. * \param[out] response Response to the HTTP request.
  806. */
  807. static void ast_ari_asterisk_delete_log_cb(
  808. struct ast_tcptls_session_instance *ser,
  809. struct ast_variable *get_params, struct ast_variable *path_vars,
  810. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  811. {
  812. struct ast_ari_asterisk_delete_log_args args = {};
  813. struct ast_variable *i;
  814. #if defined(AST_DEVMODE)
  815. int is_valid;
  816. int code;
  817. #endif /* AST_DEVMODE */
  818. for (i = path_vars; i; i = i->next) {
  819. if (strcmp(i->name, "logChannelName") == 0) {
  820. args.log_channel_name = (i->value);
  821. } else
  822. {}
  823. }
  824. ast_ari_asterisk_delete_log(headers, &args, response);
  825. #if defined(AST_DEVMODE)
  826. code = response->response_code;
  827. switch (code) {
  828. case 0: /* Implementation is still a stub, or the code wasn't set */
  829. is_valid = response->message == NULL;
  830. break;
  831. case 500: /* Internal Server Error */
  832. case 501: /* Not Implemented */
  833. case 404: /* Log channel does not exist. */
  834. is_valid = 1;
  835. break;
  836. default:
  837. if (200 <= code && code <= 299) {
  838. is_valid = ast_ari_validate_void(
  839. response->message);
  840. } else {
  841. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/logging/{logChannelName}\n", code);
  842. is_valid = 0;
  843. }
  844. }
  845. if (!is_valid) {
  846. ast_log(LOG_ERROR, "Response validation failed for /asterisk/logging/{logChannelName}\n");
  847. ast_ari_response_error(response, 500,
  848. "Internal Server Error", "Response validation failed");
  849. }
  850. #endif /* AST_DEVMODE */
  851. fin: __attribute__((unused))
  852. return;
  853. }
  854. /*!
  855. * \brief Parameter parsing callback for /asterisk/logging/{logChannelName}/rotate.
  856. * \param get_params GET parameters in the HTTP request.
  857. * \param path_vars Path variables extracted from the request.
  858. * \param headers HTTP headers.
  859. * \param[out] response Response to the HTTP request.
  860. */
  861. static void ast_ari_asterisk_rotate_log_cb(
  862. struct ast_tcptls_session_instance *ser,
  863. struct ast_variable *get_params, struct ast_variable *path_vars,
  864. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  865. {
  866. struct ast_ari_asterisk_rotate_log_args args = {};
  867. struct ast_variable *i;
  868. #if defined(AST_DEVMODE)
  869. int is_valid;
  870. int code;
  871. #endif /* AST_DEVMODE */
  872. for (i = path_vars; i; i = i->next) {
  873. if (strcmp(i->name, "logChannelName") == 0) {
  874. args.log_channel_name = (i->value);
  875. } else
  876. {}
  877. }
  878. ast_ari_asterisk_rotate_log(headers, &args, response);
  879. #if defined(AST_DEVMODE)
  880. code = response->response_code;
  881. switch (code) {
  882. case 0: /* Implementation is still a stub, or the code wasn't set */
  883. is_valid = response->message == NULL;
  884. break;
  885. case 500: /* Internal Server Error */
  886. case 501: /* Not Implemented */
  887. case 404: /* Log channel does not exist. */
  888. is_valid = 1;
  889. break;
  890. default:
  891. if (200 <= code && code <= 299) {
  892. is_valid = ast_ari_validate_void(
  893. response->message);
  894. } else {
  895. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/logging/{logChannelName}/rotate\n", code);
  896. is_valid = 0;
  897. }
  898. }
  899. if (!is_valid) {
  900. ast_log(LOG_ERROR, "Response validation failed for /asterisk/logging/{logChannelName}/rotate\n");
  901. ast_ari_response_error(response, 500,
  902. "Internal Server Error", "Response validation failed");
  903. }
  904. #endif /* AST_DEVMODE */
  905. fin: __attribute__((unused))
  906. return;
  907. }
  908. int ast_ari_asterisk_get_global_var_parse_body(
  909. struct ast_json *body,
  910. struct ast_ari_asterisk_get_global_var_args *args)
  911. {
  912. struct ast_json *field;
  913. /* Parse query parameters out of it */
  914. field = ast_json_object_get(body, "variable");
  915. if (field) {
  916. args->variable = ast_json_string_get(field);
  917. }
  918. return 0;
  919. }
  920. /*!
  921. * \brief Parameter parsing callback for /asterisk/variable.
  922. * \param get_params GET parameters in the HTTP request.
  923. * \param path_vars Path variables extracted from the request.
  924. * \param headers HTTP headers.
  925. * \param[out] response Response to the HTTP request.
  926. */
  927. static void ast_ari_asterisk_get_global_var_cb(
  928. struct ast_tcptls_session_instance *ser,
  929. struct ast_variable *get_params, struct ast_variable *path_vars,
  930. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  931. {
  932. struct ast_ari_asterisk_get_global_var_args args = {};
  933. struct ast_variable *i;
  934. #if defined(AST_DEVMODE)
  935. int is_valid;
  936. int code;
  937. #endif /* AST_DEVMODE */
  938. for (i = get_params; i; i = i->next) {
  939. if (strcmp(i->name, "variable") == 0) {
  940. args.variable = (i->value);
  941. } else
  942. {}
  943. }
  944. if (ast_ari_asterisk_get_global_var_parse_body(body, &args)) {
  945. ast_ari_response_alloc_failed(response);
  946. goto fin;
  947. }
  948. ast_ari_asterisk_get_global_var(headers, &args, response);
  949. #if defined(AST_DEVMODE)
  950. code = response->response_code;
  951. switch (code) {
  952. case 0: /* Implementation is still a stub, or the code wasn't set */
  953. is_valid = response->message == NULL;
  954. break;
  955. case 500: /* Internal Server Error */
  956. case 501: /* Not Implemented */
  957. case 400: /* Missing variable parameter. */
  958. is_valid = 1;
  959. break;
  960. default:
  961. if (200 <= code && code <= 299) {
  962. is_valid = ast_ari_validate_variable(
  963. response->message);
  964. } else {
  965. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/variable\n", code);
  966. is_valid = 0;
  967. }
  968. }
  969. if (!is_valid) {
  970. ast_log(LOG_ERROR, "Response validation failed for /asterisk/variable\n");
  971. ast_ari_response_error(response, 500,
  972. "Internal Server Error", "Response validation failed");
  973. }
  974. #endif /* AST_DEVMODE */
  975. fin: __attribute__((unused))
  976. return;
  977. }
  978. int ast_ari_asterisk_set_global_var_parse_body(
  979. struct ast_json *body,
  980. struct ast_ari_asterisk_set_global_var_args *args)
  981. {
  982. struct ast_json *field;
  983. /* Parse query parameters out of it */
  984. field = ast_json_object_get(body, "variable");
  985. if (field) {
  986. args->variable = ast_json_string_get(field);
  987. }
  988. field = ast_json_object_get(body, "value");
  989. if (field) {
  990. args->value = ast_json_string_get(field);
  991. }
  992. return 0;
  993. }
  994. /*!
  995. * \brief Parameter parsing callback for /asterisk/variable.
  996. * \param get_params GET parameters in the HTTP request.
  997. * \param path_vars Path variables extracted from the request.
  998. * \param headers HTTP headers.
  999. * \param[out] response Response to the HTTP request.
  1000. */
  1001. static void ast_ari_asterisk_set_global_var_cb(
  1002. struct ast_tcptls_session_instance *ser,
  1003. struct ast_variable *get_params, struct ast_variable *path_vars,
  1004. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1005. {
  1006. struct ast_ari_asterisk_set_global_var_args args = {};
  1007. struct ast_variable *i;
  1008. #if defined(AST_DEVMODE)
  1009. int is_valid;
  1010. int code;
  1011. #endif /* AST_DEVMODE */
  1012. for (i = get_params; i; i = i->next) {
  1013. if (strcmp(i->name, "variable") == 0) {
  1014. args.variable = (i->value);
  1015. } else
  1016. if (strcmp(i->name, "value") == 0) {
  1017. args.value = (i->value);
  1018. } else
  1019. {}
  1020. }
  1021. if (ast_ari_asterisk_set_global_var_parse_body(body, &args)) {
  1022. ast_ari_response_alloc_failed(response);
  1023. goto fin;
  1024. }
  1025. ast_ari_asterisk_set_global_var(headers, &args, response);
  1026. #if defined(AST_DEVMODE)
  1027. code = response->response_code;
  1028. switch (code) {
  1029. case 0: /* Implementation is still a stub, or the code wasn't set */
  1030. is_valid = response->message == NULL;
  1031. break;
  1032. case 500: /* Internal Server Error */
  1033. case 501: /* Not Implemented */
  1034. case 400: /* Missing variable parameter. */
  1035. is_valid = 1;
  1036. break;
  1037. default:
  1038. if (200 <= code && code <= 299) {
  1039. is_valid = ast_ari_validate_void(
  1040. response->message);
  1041. } else {
  1042. ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/variable\n", code);
  1043. is_valid = 0;
  1044. }
  1045. }
  1046. if (!is_valid) {
  1047. ast_log(LOG_ERROR, "Response validation failed for /asterisk/variable\n");
  1048. ast_ari_response_error(response, 500,
  1049. "Internal Server Error", "Response validation failed");
  1050. }
  1051. #endif /* AST_DEVMODE */
  1052. fin: __attribute__((unused))
  1053. return;
  1054. }
  1055. /*! \brief REST handler for /api-docs/asterisk.json */
  1056. static struct stasis_rest_handlers asterisk_config_dynamic_configClass_objectType_id = {
  1057. .path_segment = "id",
  1058. .is_wildcard = 1,
  1059. .callbacks = {
  1060. [AST_HTTP_GET] = ast_ari_asterisk_get_object_cb,
  1061. [AST_HTTP_PUT] = ast_ari_asterisk_update_object_cb,
  1062. [AST_HTTP_DELETE] = ast_ari_asterisk_delete_object_cb,
  1063. },
  1064. .num_children = 0,
  1065. .children = { }
  1066. };
  1067. /*! \brief REST handler for /api-docs/asterisk.json */
  1068. static struct stasis_rest_handlers asterisk_config_dynamic_configClass_objectType = {
  1069. .path_segment = "objectType",
  1070. .is_wildcard = 1,
  1071. .callbacks = {
  1072. },
  1073. .num_children = 1,
  1074. .children = { &asterisk_config_dynamic_configClass_objectType_id, }
  1075. };
  1076. /*! \brief REST handler for /api-docs/asterisk.json */
  1077. static struct stasis_rest_handlers asterisk_config_dynamic_configClass = {
  1078. .path_segment = "configClass",
  1079. .is_wildcard = 1,
  1080. .callbacks = {
  1081. },
  1082. .num_children = 1,
  1083. .children = { &asterisk_config_dynamic_configClass_objectType, }
  1084. };
  1085. /*! \brief REST handler for /api-docs/asterisk.json */
  1086. static struct stasis_rest_handlers asterisk_config_dynamic = {
  1087. .path_segment = "dynamic",
  1088. .callbacks = {
  1089. },
  1090. .num_children = 1,
  1091. .children = { &asterisk_config_dynamic_configClass, }
  1092. };
  1093. /*! \brief REST handler for /api-docs/asterisk.json */
  1094. static struct stasis_rest_handlers asterisk_config = {
  1095. .path_segment = "config",
  1096. .callbacks = {
  1097. },
  1098. .num_children = 1,
  1099. .children = { &asterisk_config_dynamic, }
  1100. };
  1101. /*! \brief REST handler for /api-docs/asterisk.json */
  1102. static struct stasis_rest_handlers asterisk_info = {
  1103. .path_segment = "info",
  1104. .callbacks = {
  1105. [AST_HTTP_GET] = ast_ari_asterisk_get_info_cb,
  1106. },
  1107. .num_children = 0,
  1108. .children = { }
  1109. };
  1110. /*! \brief REST handler for /api-docs/asterisk.json */
  1111. static struct stasis_rest_handlers asterisk_ping = {
  1112. .path_segment = "ping",
  1113. .callbacks = {
  1114. [AST_HTTP_GET] = ast_ari_asterisk_ping_cb,
  1115. },
  1116. .num_children = 0,
  1117. .children = { }
  1118. };
  1119. /*! \brief REST handler for /api-docs/asterisk.json */
  1120. static struct stasis_rest_handlers asterisk_modules_moduleName = {
  1121. .path_segment = "moduleName",
  1122. .is_wildcard = 1,
  1123. .callbacks = {
  1124. [AST_HTTP_GET] = ast_ari_asterisk_get_module_cb,
  1125. [AST_HTTP_POST] = ast_ari_asterisk_load_module_cb,
  1126. [AST_HTTP_DELETE] = ast_ari_asterisk_unload_module_cb,
  1127. [AST_HTTP_PUT] = ast_ari_asterisk_reload_module_cb,
  1128. },
  1129. .num_children = 0,
  1130. .children = { }
  1131. };
  1132. /*! \brief REST handler for /api-docs/asterisk.json */
  1133. static struct stasis_rest_handlers asterisk_modules = {
  1134. .path_segment = "modules",
  1135. .callbacks = {
  1136. [AST_HTTP_GET] = ast_ari_asterisk_list_modules_cb,
  1137. },
  1138. .num_children = 1,
  1139. .children = { &asterisk_modules_moduleName, }
  1140. };
  1141. /*! \brief REST handler for /api-docs/asterisk.json */
  1142. static struct stasis_rest_handlers asterisk_logging_logChannelName_rotate = {
  1143. .path_segment = "rotate",
  1144. .callbacks = {
  1145. [AST_HTTP_PUT] = ast_ari_asterisk_rotate_log_cb,
  1146. },
  1147. .num_children = 0,
  1148. .children = { }
  1149. };
  1150. /*! \brief REST handler for /api-docs/asterisk.json */
  1151. static struct stasis_rest_handlers asterisk_logging_logChannelName = {
  1152. .path_segment = "logChannelName",
  1153. .is_wildcard = 1,
  1154. .callbacks = {
  1155. [AST_HTTP_POST] = ast_ari_asterisk_add_log_cb,
  1156. [AST_HTTP_DELETE] = ast_ari_asterisk_delete_log_cb,
  1157. },
  1158. .num_children = 1,
  1159. .children = { &asterisk_logging_logChannelName_rotate, }
  1160. };
  1161. /*! \brief REST handler for /api-docs/asterisk.json */
  1162. static struct stasis_rest_handlers asterisk_logging = {
  1163. .path_segment = "logging",
  1164. .callbacks = {
  1165. [AST_HTTP_GET] = ast_ari_asterisk_list_log_channels_cb,
  1166. },
  1167. .num_children = 1,
  1168. .children = { &asterisk_logging_logChannelName, }
  1169. };
  1170. /*! \brief REST handler for /api-docs/asterisk.json */
  1171. static struct stasis_rest_handlers asterisk_variable = {
  1172. .path_segment = "variable",
  1173. .callbacks = {
  1174. [AST_HTTP_GET] = ast_ari_asterisk_get_global_var_cb,
  1175. [AST_HTTP_POST] = ast_ari_asterisk_set_global_var_cb,
  1176. },
  1177. .num_children = 0,
  1178. .children = { }
  1179. };
  1180. /*! \brief REST handler for /api-docs/asterisk.json */
  1181. static struct stasis_rest_handlers asterisk = {
  1182. .path_segment = "asterisk",
  1183. .callbacks = {
  1184. },
  1185. .num_children = 6,
  1186. .children = { &asterisk_config,&asterisk_info,&asterisk_ping,&asterisk_modules,&asterisk_logging,&asterisk_variable, }
  1187. };
  1188. static int unload_module(void)
  1189. {
  1190. ast_ari_remove_handler(&asterisk);
  1191. stasis_app_unref();
  1192. return 0;
  1193. }
  1194. static int load_module(void)
  1195. {
  1196. int res = 0;
  1197. CHECK_ARI_MODULE_LOADED();
  1198. stasis_app_ref();
  1199. res |= ast_ari_add_handler(&asterisk);
  1200. if (res) {
  1201. unload_module();
  1202. return AST_MODULE_LOAD_DECLINE;
  1203. }
  1204. return AST_MODULE_LOAD_SUCCESS;
  1205. }
  1206. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Asterisk resources",
  1207. .support_level = AST_MODULE_SUPPORT_CORE,
  1208. .load = load_module,
  1209. .unload = unload_module,
  1210. );