res_ari_endpoints.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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 Endpoint 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_endpoints.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 /endpoints.
  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_endpoints_list_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_endpoints_list_args args = {};
  61. #if defined(AST_DEVMODE)
  62. int is_valid;
  63. int code;
  64. #endif /* AST_DEVMODE */
  65. ast_ari_endpoints_list(headers, &args, response);
  66. #if defined(AST_DEVMODE)
  67. code = response->response_code;
  68. switch (code) {
  69. case 0: /* Implementation is still a stub, or the code wasn't set */
  70. is_valid = response->message == NULL;
  71. break;
  72. case 500: /* Internal Server Error */
  73. case 501: /* Not Implemented */
  74. is_valid = 1;
  75. break;
  76. default:
  77. if (200 <= code && code <= 299) {
  78. is_valid = ast_ari_validate_list(response->message,
  79. ast_ari_validate_endpoint_fn());
  80. } else {
  81. ast_log(LOG_ERROR, "Invalid error response %d for /endpoints\n", code);
  82. is_valid = 0;
  83. }
  84. }
  85. if (!is_valid) {
  86. ast_log(LOG_ERROR, "Response validation failed for /endpoints\n");
  87. ast_ari_response_error(response, 500,
  88. "Internal Server Error", "Response validation failed");
  89. }
  90. #endif /* AST_DEVMODE */
  91. fin: __attribute__((unused))
  92. return;
  93. }
  94. int ast_ari_endpoints_send_message_parse_body(
  95. struct ast_json *body,
  96. struct ast_ari_endpoints_send_message_args *args)
  97. {
  98. struct ast_json *field;
  99. /* Parse query parameters out of it */
  100. field = ast_json_object_get(body, "to");
  101. if (field) {
  102. args->to = ast_json_string_get(field);
  103. }
  104. field = ast_json_object_get(body, "from");
  105. if (field) {
  106. args->from = ast_json_string_get(field);
  107. }
  108. field = ast_json_object_get(body, "body");
  109. if (field) {
  110. args->body = ast_json_string_get(field);
  111. }
  112. return 0;
  113. }
  114. /*!
  115. * \brief Parameter parsing callback for /endpoints/sendMessage.
  116. * \param ser TCP/TLS session object
  117. * \param get_params GET parameters in the HTTP request.
  118. * \param path_vars Path variables extracted from the request.
  119. * \param headers HTTP headers.
  120. * \param body
  121. * \param[out] response Response to the HTTP request.
  122. */
  123. static void ast_ari_endpoints_send_message_cb(
  124. struct ast_tcptls_session_instance *ser,
  125. struct ast_variable *get_params, struct ast_variable *path_vars,
  126. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  127. {
  128. struct ast_ari_endpoints_send_message_args args = {};
  129. struct ast_variable *i;
  130. #if defined(AST_DEVMODE)
  131. int is_valid;
  132. int code;
  133. #endif /* AST_DEVMODE */
  134. for (i = get_params; i; i = i->next) {
  135. if (strcmp(i->name, "to") == 0) {
  136. args.to = (i->value);
  137. } else
  138. if (strcmp(i->name, "from") == 0) {
  139. args.from = (i->value);
  140. } else
  141. if (strcmp(i->name, "body") == 0) {
  142. args.body = (i->value);
  143. } else
  144. {}
  145. }
  146. args.variables = body;
  147. ast_ari_endpoints_send_message(headers, &args, response);
  148. #if defined(AST_DEVMODE)
  149. code = response->response_code;
  150. switch (code) {
  151. case 0: /* Implementation is still a stub, or the code wasn't set */
  152. is_valid = response->message == NULL;
  153. break;
  154. case 500: /* Internal Server Error */
  155. case 501: /* Not Implemented */
  156. case 400: /* Invalid parameters for sending a message. */
  157. case 404: /* Endpoint not found */
  158. is_valid = 1;
  159. break;
  160. default:
  161. if (200 <= code && code <= 299) {
  162. is_valid = ast_ari_validate_void(
  163. response->message);
  164. } else {
  165. ast_log(LOG_ERROR, "Invalid error response %d for /endpoints/sendMessage\n", code);
  166. is_valid = 0;
  167. }
  168. }
  169. if (!is_valid) {
  170. ast_log(LOG_ERROR, "Response validation failed for /endpoints/sendMessage\n");
  171. ast_ari_response_error(response, 500,
  172. "Internal Server Error", "Response validation failed");
  173. }
  174. #endif /* AST_DEVMODE */
  175. fin: __attribute__((unused))
  176. return;
  177. }
  178. int ast_ari_endpoints_refer_parse_body(
  179. struct ast_json *body,
  180. struct ast_ari_endpoints_refer_args *args)
  181. {
  182. struct ast_json *field;
  183. /* Parse query parameters out of it */
  184. field = ast_json_object_get(body, "to");
  185. if (field) {
  186. args->to = ast_json_string_get(field);
  187. }
  188. field = ast_json_object_get(body, "from");
  189. if (field) {
  190. args->from = ast_json_string_get(field);
  191. }
  192. field = ast_json_object_get(body, "refer_to");
  193. if (field) {
  194. args->refer_to = ast_json_string_get(field);
  195. }
  196. field = ast_json_object_get(body, "to_self");
  197. if (field) {
  198. args->to_self = ast_json_is_true(field);
  199. }
  200. return 0;
  201. }
  202. /*!
  203. * \brief Parameter parsing callback for /endpoints/refer.
  204. * \param ser TCP/TLS session object
  205. * \param get_params GET parameters in the HTTP request.
  206. * \param path_vars Path variables extracted from the request.
  207. * \param headers HTTP headers.
  208. * \param body
  209. * \param[out] response Response to the HTTP request.
  210. */
  211. static void ast_ari_endpoints_refer_cb(
  212. struct ast_tcptls_session_instance *ser,
  213. struct ast_variable *get_params, struct ast_variable *path_vars,
  214. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  215. {
  216. struct ast_ari_endpoints_refer_args args = {};
  217. struct ast_variable *i;
  218. #if defined(AST_DEVMODE)
  219. int is_valid;
  220. int code;
  221. #endif /* AST_DEVMODE */
  222. for (i = get_params; i; i = i->next) {
  223. if (strcmp(i->name, "to") == 0) {
  224. args.to = (i->value);
  225. } else
  226. if (strcmp(i->name, "from") == 0) {
  227. args.from = (i->value);
  228. } else
  229. if (strcmp(i->name, "refer_to") == 0) {
  230. args.refer_to = (i->value);
  231. } else
  232. if (strcmp(i->name, "to_self") == 0) {
  233. args.to_self = ast_true(i->value);
  234. } else
  235. {}
  236. }
  237. args.variables = body;
  238. ast_ari_endpoints_refer(headers, &args, response);
  239. #if defined(AST_DEVMODE)
  240. code = response->response_code;
  241. switch (code) {
  242. case 0: /* Implementation is still a stub, or the code wasn't set */
  243. is_valid = response->message == NULL;
  244. break;
  245. case 500: /* Internal Server Error */
  246. case 501: /* Not Implemented */
  247. case 400: /* Invalid parameters for referring. */
  248. case 404: /* Endpoint not found */
  249. is_valid = 1;
  250. break;
  251. default:
  252. if (200 <= code && code <= 299) {
  253. is_valid = ast_ari_validate_void(
  254. response->message);
  255. } else {
  256. ast_log(LOG_ERROR, "Invalid error response %d for /endpoints/refer\n", code);
  257. is_valid = 0;
  258. }
  259. }
  260. if (!is_valid) {
  261. ast_log(LOG_ERROR, "Response validation failed for /endpoints/refer\n");
  262. ast_ari_response_error(response, 500,
  263. "Internal Server Error", "Response validation failed");
  264. }
  265. #endif /* AST_DEVMODE */
  266. fin: __attribute__((unused))
  267. return;
  268. }
  269. /*!
  270. * \brief Parameter parsing callback for /endpoints/{tech}.
  271. * \param ser TCP/TLS session object
  272. * \param get_params GET parameters in the HTTP request.
  273. * \param path_vars Path variables extracted from the request.
  274. * \param headers HTTP headers.
  275. * \param body
  276. * \param[out] response Response to the HTTP request.
  277. */
  278. static void ast_ari_endpoints_list_by_tech_cb(
  279. struct ast_tcptls_session_instance *ser,
  280. struct ast_variable *get_params, struct ast_variable *path_vars,
  281. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  282. {
  283. struct ast_ari_endpoints_list_by_tech_args args = {};
  284. struct ast_variable *i;
  285. #if defined(AST_DEVMODE)
  286. int is_valid;
  287. int code;
  288. #endif /* AST_DEVMODE */
  289. for (i = path_vars; i; i = i->next) {
  290. if (strcmp(i->name, "tech") == 0) {
  291. args.tech = (i->value);
  292. } else
  293. {}
  294. }
  295. ast_ari_endpoints_list_by_tech(headers, &args, response);
  296. #if defined(AST_DEVMODE)
  297. code = response->response_code;
  298. switch (code) {
  299. case 0: /* Implementation is still a stub, or the code wasn't set */
  300. is_valid = response->message == NULL;
  301. break;
  302. case 500: /* Internal Server Error */
  303. case 501: /* Not Implemented */
  304. case 404: /* Endpoints not found */
  305. is_valid = 1;
  306. break;
  307. default:
  308. if (200 <= code && code <= 299) {
  309. is_valid = ast_ari_validate_list(response->message,
  310. ast_ari_validate_endpoint_fn());
  311. } else {
  312. ast_log(LOG_ERROR, "Invalid error response %d for /endpoints/{tech}\n", code);
  313. is_valid = 0;
  314. }
  315. }
  316. if (!is_valid) {
  317. ast_log(LOG_ERROR, "Response validation failed for /endpoints/{tech}\n");
  318. ast_ari_response_error(response, 500,
  319. "Internal Server Error", "Response validation failed");
  320. }
  321. #endif /* AST_DEVMODE */
  322. fin: __attribute__((unused))
  323. return;
  324. }
  325. /*!
  326. * \brief Parameter parsing callback for /endpoints/{tech}/{resource}.
  327. * \param ser TCP/TLS session object
  328. * \param get_params GET parameters in the HTTP request.
  329. * \param path_vars Path variables extracted from the request.
  330. * \param headers HTTP headers.
  331. * \param body
  332. * \param[out] response Response to the HTTP request.
  333. */
  334. static void ast_ari_endpoints_get_cb(
  335. struct ast_tcptls_session_instance *ser,
  336. struct ast_variable *get_params, struct ast_variable *path_vars,
  337. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  338. {
  339. struct ast_ari_endpoints_get_args args = {};
  340. struct ast_variable *i;
  341. #if defined(AST_DEVMODE)
  342. int is_valid;
  343. int code;
  344. #endif /* AST_DEVMODE */
  345. for (i = path_vars; i; i = i->next) {
  346. if (strcmp(i->name, "tech") == 0) {
  347. args.tech = (i->value);
  348. } else
  349. if (strcmp(i->name, "resource") == 0) {
  350. args.resource = (i->value);
  351. } else
  352. {}
  353. }
  354. ast_ari_endpoints_get(headers, &args, response);
  355. #if defined(AST_DEVMODE)
  356. code = response->response_code;
  357. switch (code) {
  358. case 0: /* Implementation is still a stub, or the code wasn't set */
  359. is_valid = response->message == NULL;
  360. break;
  361. case 500: /* Internal Server Error */
  362. case 501: /* Not Implemented */
  363. case 400: /* Invalid parameters for sending a message. */
  364. case 404: /* Endpoints not found */
  365. is_valid = 1;
  366. break;
  367. default:
  368. if (200 <= code && code <= 299) {
  369. is_valid = ast_ari_validate_endpoint(
  370. response->message);
  371. } else {
  372. ast_log(LOG_ERROR, "Invalid error response %d for /endpoints/{tech}/{resource}\n", code);
  373. is_valid = 0;
  374. }
  375. }
  376. if (!is_valid) {
  377. ast_log(LOG_ERROR, "Response validation failed for /endpoints/{tech}/{resource}\n");
  378. ast_ari_response_error(response, 500,
  379. "Internal Server Error", "Response validation failed");
  380. }
  381. #endif /* AST_DEVMODE */
  382. fin: __attribute__((unused))
  383. return;
  384. }
  385. int ast_ari_endpoints_send_message_to_endpoint_parse_body(
  386. struct ast_json *body,
  387. struct ast_ari_endpoints_send_message_to_endpoint_args *args)
  388. {
  389. struct ast_json *field;
  390. /* Parse query parameters out of it */
  391. field = ast_json_object_get(body, "from");
  392. if (field) {
  393. args->from = ast_json_string_get(field);
  394. }
  395. field = ast_json_object_get(body, "body");
  396. if (field) {
  397. args->body = ast_json_string_get(field);
  398. }
  399. return 0;
  400. }
  401. /*!
  402. * \brief Parameter parsing callback for /endpoints/{tech}/{resource}/sendMessage.
  403. * \param ser TCP/TLS session object
  404. * \param get_params GET parameters in the HTTP request.
  405. * \param path_vars Path variables extracted from the request.
  406. * \param headers HTTP headers.
  407. * \param body
  408. * \param[out] response Response to the HTTP request.
  409. */
  410. static void ast_ari_endpoints_send_message_to_endpoint_cb(
  411. struct ast_tcptls_session_instance *ser,
  412. struct ast_variable *get_params, struct ast_variable *path_vars,
  413. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  414. {
  415. struct ast_ari_endpoints_send_message_to_endpoint_args args = {};
  416. struct ast_variable *i;
  417. #if defined(AST_DEVMODE)
  418. int is_valid;
  419. int code;
  420. #endif /* AST_DEVMODE */
  421. for (i = get_params; i; i = i->next) {
  422. if (strcmp(i->name, "from") == 0) {
  423. args.from = (i->value);
  424. } else
  425. if (strcmp(i->name, "body") == 0) {
  426. args.body = (i->value);
  427. } else
  428. {}
  429. }
  430. for (i = path_vars; i; i = i->next) {
  431. if (strcmp(i->name, "tech") == 0) {
  432. args.tech = (i->value);
  433. } else
  434. if (strcmp(i->name, "resource") == 0) {
  435. args.resource = (i->value);
  436. } else
  437. {}
  438. }
  439. args.variables = body;
  440. ast_ari_endpoints_send_message_to_endpoint(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. case 400: /* Invalid parameters for sending a message. */
  450. case 404: /* Endpoint not found */
  451. is_valid = 1;
  452. break;
  453. default:
  454. if (200 <= code && code <= 299) {
  455. is_valid = ast_ari_validate_void(
  456. response->message);
  457. } else {
  458. ast_log(LOG_ERROR, "Invalid error response %d for /endpoints/{tech}/{resource}/sendMessage\n", code);
  459. is_valid = 0;
  460. }
  461. }
  462. if (!is_valid) {
  463. ast_log(LOG_ERROR, "Response validation failed for /endpoints/{tech}/{resource}/sendMessage\n");
  464. ast_ari_response_error(response, 500,
  465. "Internal Server Error", "Response validation failed");
  466. }
  467. #endif /* AST_DEVMODE */
  468. fin: __attribute__((unused))
  469. return;
  470. }
  471. int ast_ari_endpoints_refer_to_endpoint_parse_body(
  472. struct ast_json *body,
  473. struct ast_ari_endpoints_refer_to_endpoint_args *args)
  474. {
  475. struct ast_json *field;
  476. /* Parse query parameters out of it */
  477. field = ast_json_object_get(body, "from");
  478. if (field) {
  479. args->from = ast_json_string_get(field);
  480. }
  481. field = ast_json_object_get(body, "refer_to");
  482. if (field) {
  483. args->refer_to = ast_json_string_get(field);
  484. }
  485. field = ast_json_object_get(body, "to_self");
  486. if (field) {
  487. args->to_self = ast_json_is_true(field);
  488. }
  489. return 0;
  490. }
  491. /*!
  492. * \brief Parameter parsing callback for /endpoints/{tech}/{resource}/refer.
  493. * \param ser TCP/TLS session object
  494. * \param get_params GET parameters in the HTTP request.
  495. * \param path_vars Path variables extracted from the request.
  496. * \param headers HTTP headers.
  497. * \param body
  498. * \param[out] response Response to the HTTP request.
  499. */
  500. static void ast_ari_endpoints_refer_to_endpoint_cb(
  501. struct ast_tcptls_session_instance *ser,
  502. struct ast_variable *get_params, struct ast_variable *path_vars,
  503. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  504. {
  505. struct ast_ari_endpoints_refer_to_endpoint_args args = {};
  506. struct ast_variable *i;
  507. #if defined(AST_DEVMODE)
  508. int is_valid;
  509. int code;
  510. #endif /* AST_DEVMODE */
  511. for (i = get_params; i; i = i->next) {
  512. if (strcmp(i->name, "from") == 0) {
  513. args.from = (i->value);
  514. } else
  515. if (strcmp(i->name, "refer_to") == 0) {
  516. args.refer_to = (i->value);
  517. } else
  518. if (strcmp(i->name, "to_self") == 0) {
  519. args.to_self = ast_true(i->value);
  520. } else
  521. {}
  522. }
  523. for (i = path_vars; i; i = i->next) {
  524. if (strcmp(i->name, "tech") == 0) {
  525. args.tech = (i->value);
  526. } else
  527. if (strcmp(i->name, "resource") == 0) {
  528. args.resource = (i->value);
  529. } else
  530. {}
  531. }
  532. args.variables = body;
  533. ast_ari_endpoints_refer_to_endpoint(headers, &args, response);
  534. #if defined(AST_DEVMODE)
  535. code = response->response_code;
  536. switch (code) {
  537. case 0: /* Implementation is still a stub, or the code wasn't set */
  538. is_valid = response->message == NULL;
  539. break;
  540. case 500: /* Internal Server Error */
  541. case 501: /* Not Implemented */
  542. case 400: /* Invalid parameters for referring. */
  543. case 404: /* Endpoint not found */
  544. is_valid = 1;
  545. break;
  546. default:
  547. if (200 <= code && code <= 299) {
  548. is_valid = ast_ari_validate_void(
  549. response->message);
  550. } else {
  551. ast_log(LOG_ERROR, "Invalid error response %d for /endpoints/{tech}/{resource}/refer\n", code);
  552. is_valid = 0;
  553. }
  554. }
  555. if (!is_valid) {
  556. ast_log(LOG_ERROR, "Response validation failed for /endpoints/{tech}/{resource}/refer\n");
  557. ast_ari_response_error(response, 500,
  558. "Internal Server Error", "Response validation failed");
  559. }
  560. #endif /* AST_DEVMODE */
  561. fin: __attribute__((unused))
  562. return;
  563. }
  564. /*! \brief REST handler for /api-docs/endpoints.json */
  565. static struct stasis_rest_handlers endpoints_sendMessage = {
  566. .path_segment = "sendMessage",
  567. .callbacks = {
  568. [AST_HTTP_PUT] = ast_ari_endpoints_send_message_cb,
  569. },
  570. .num_children = 0,
  571. .children = { }
  572. };
  573. /*! \brief REST handler for /api-docs/endpoints.json */
  574. static struct stasis_rest_handlers endpoints_refer = {
  575. .path_segment = "refer",
  576. .callbacks = {
  577. [AST_HTTP_POST] = ast_ari_endpoints_refer_cb,
  578. },
  579. .num_children = 0,
  580. .children = { }
  581. };
  582. /*! \brief REST handler for /api-docs/endpoints.json */
  583. static struct stasis_rest_handlers endpoints_tech_resource_sendMessage = {
  584. .path_segment = "sendMessage",
  585. .callbacks = {
  586. [AST_HTTP_PUT] = ast_ari_endpoints_send_message_to_endpoint_cb,
  587. },
  588. .num_children = 0,
  589. .children = { }
  590. };
  591. /*! \brief REST handler for /api-docs/endpoints.json */
  592. static struct stasis_rest_handlers endpoints_tech_resource_refer = {
  593. .path_segment = "refer",
  594. .callbacks = {
  595. [AST_HTTP_POST] = ast_ari_endpoints_refer_to_endpoint_cb,
  596. },
  597. .num_children = 0,
  598. .children = { }
  599. };
  600. /*! \brief REST handler for /api-docs/endpoints.json */
  601. static struct stasis_rest_handlers endpoints_tech_resource = {
  602. .path_segment = "resource",
  603. .is_wildcard = 1,
  604. .callbacks = {
  605. [AST_HTTP_GET] = ast_ari_endpoints_get_cb,
  606. },
  607. .num_children = 2,
  608. .children = { &endpoints_tech_resource_sendMessage,&endpoints_tech_resource_refer, }
  609. };
  610. /*! \brief REST handler for /api-docs/endpoints.json */
  611. static struct stasis_rest_handlers endpoints_tech = {
  612. .path_segment = "tech",
  613. .is_wildcard = 1,
  614. .callbacks = {
  615. [AST_HTTP_GET] = ast_ari_endpoints_list_by_tech_cb,
  616. },
  617. .num_children = 1,
  618. .children = { &endpoints_tech_resource, }
  619. };
  620. /*! \brief REST handler for /api-docs/endpoints.json */
  621. static struct stasis_rest_handlers endpoints = {
  622. .path_segment = "endpoints",
  623. .callbacks = {
  624. [AST_HTTP_GET] = ast_ari_endpoints_list_cb,
  625. },
  626. .num_children = 3,
  627. .children = { &endpoints_sendMessage,&endpoints_refer,&endpoints_tech, }
  628. };
  629. static int unload_module(void)
  630. {
  631. ast_ari_remove_handler(&endpoints);
  632. return 0;
  633. }
  634. static int load_module(void)
  635. {
  636. int res = 0;
  637. res |= ast_ari_add_handler(&endpoints);
  638. if (res) {
  639. unload_module();
  640. return AST_MODULE_LOAD_DECLINE;
  641. }
  642. return AST_MODULE_LOAD_SUCCESS;
  643. }
  644. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Endpoint resources",
  645. .support_level = AST_MODULE_SUPPORT_CORE,
  646. .load = load_module,
  647. .unload = unload_module,
  648. .requires = "res_ari,res_ari_model,res_stasis",
  649. );