res_ari_asterisk.c 38 KB

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