res_ari_channels.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500
  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 Channel 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_channels.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 /channels.
  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_channels_list_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_channels_list_args args = {};
  60. #if defined(AST_DEVMODE)
  61. int is_valid;
  62. int code;
  63. #endif /* AST_DEVMODE */
  64. ast_ari_channels_list(headers, &args, response);
  65. #if defined(AST_DEVMODE)
  66. code = response->response_code;
  67. switch (code) {
  68. case 0: /* Implementation is still a stub, or the code wasn't set */
  69. is_valid = response->message == NULL;
  70. break;
  71. case 500: /* Internal Server Error */
  72. case 501: /* Not Implemented */
  73. is_valid = 1;
  74. break;
  75. default:
  76. if (200 <= code && code <= 299) {
  77. is_valid = ast_ari_validate_list(response->message,
  78. ast_ari_validate_channel_fn());
  79. } else {
  80. ast_log(LOG_ERROR, "Invalid error response %d for /channels\n", code);
  81. is_valid = 0;
  82. }
  83. }
  84. if (!is_valid) {
  85. ast_log(LOG_ERROR, "Response validation failed for /channels\n");
  86. ast_ari_response_error(response, 500,
  87. "Internal Server Error", "Response validation failed");
  88. }
  89. #endif /* AST_DEVMODE */
  90. fin: __attribute__((unused))
  91. return;
  92. }
  93. int ast_ari_channels_originate_parse_body(
  94. struct ast_json *body,
  95. struct ast_ari_channels_originate_args *args)
  96. {
  97. struct ast_json *field;
  98. /* Parse query parameters out of it */
  99. field = ast_json_object_get(body, "endpoint");
  100. if (field) {
  101. args->endpoint = ast_json_string_get(field);
  102. }
  103. field = ast_json_object_get(body, "extension");
  104. if (field) {
  105. args->extension = ast_json_string_get(field);
  106. }
  107. field = ast_json_object_get(body, "context");
  108. if (field) {
  109. args->context = ast_json_string_get(field);
  110. }
  111. field = ast_json_object_get(body, "priority");
  112. if (field) {
  113. args->priority = ast_json_integer_get(field);
  114. }
  115. field = ast_json_object_get(body, "label");
  116. if (field) {
  117. args->label = ast_json_string_get(field);
  118. }
  119. field = ast_json_object_get(body, "app");
  120. if (field) {
  121. args->app = ast_json_string_get(field);
  122. }
  123. field = ast_json_object_get(body, "appArgs");
  124. if (field) {
  125. args->app_args = ast_json_string_get(field);
  126. }
  127. field = ast_json_object_get(body, "callerId");
  128. if (field) {
  129. args->caller_id = ast_json_string_get(field);
  130. }
  131. field = ast_json_object_get(body, "timeout");
  132. if (field) {
  133. args->timeout = ast_json_integer_get(field);
  134. }
  135. field = ast_json_object_get(body, "channelId");
  136. if (field) {
  137. args->channel_id = ast_json_string_get(field);
  138. }
  139. field = ast_json_object_get(body, "otherChannelId");
  140. if (field) {
  141. args->other_channel_id = ast_json_string_get(field);
  142. }
  143. field = ast_json_object_get(body, "originator");
  144. if (field) {
  145. args->originator = ast_json_string_get(field);
  146. }
  147. field = ast_json_object_get(body, "formats");
  148. if (field) {
  149. args->formats = ast_json_string_get(field);
  150. }
  151. return 0;
  152. }
  153. /*!
  154. * \brief Parameter parsing callback for /channels.
  155. * \param get_params GET parameters in the HTTP request.
  156. * \param path_vars Path variables extracted from the request.
  157. * \param headers HTTP headers.
  158. * \param[out] response Response to the HTTP request.
  159. */
  160. static void ast_ari_channels_originate_cb(
  161. struct ast_tcptls_session_instance *ser,
  162. struct ast_variable *get_params, struct ast_variable *path_vars,
  163. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  164. {
  165. struct ast_ari_channels_originate_args args = {};
  166. struct ast_variable *i;
  167. #if defined(AST_DEVMODE)
  168. int is_valid;
  169. int code;
  170. #endif /* AST_DEVMODE */
  171. for (i = get_params; i; i = i->next) {
  172. if (strcmp(i->name, "endpoint") == 0) {
  173. args.endpoint = (i->value);
  174. } else
  175. if (strcmp(i->name, "extension") == 0) {
  176. args.extension = (i->value);
  177. } else
  178. if (strcmp(i->name, "context") == 0) {
  179. args.context = (i->value);
  180. } else
  181. if (strcmp(i->name, "priority") == 0) {
  182. args.priority = atol(i->value);
  183. } else
  184. if (strcmp(i->name, "label") == 0) {
  185. args.label = (i->value);
  186. } else
  187. if (strcmp(i->name, "app") == 0) {
  188. args.app = (i->value);
  189. } else
  190. if (strcmp(i->name, "appArgs") == 0) {
  191. args.app_args = (i->value);
  192. } else
  193. if (strcmp(i->name, "callerId") == 0) {
  194. args.caller_id = (i->value);
  195. } else
  196. if (strcmp(i->name, "timeout") == 0) {
  197. args.timeout = atoi(i->value);
  198. } else
  199. if (strcmp(i->name, "channelId") == 0) {
  200. args.channel_id = (i->value);
  201. } else
  202. if (strcmp(i->name, "otherChannelId") == 0) {
  203. args.other_channel_id = (i->value);
  204. } else
  205. if (strcmp(i->name, "originator") == 0) {
  206. args.originator = (i->value);
  207. } else
  208. if (strcmp(i->name, "formats") == 0) {
  209. args.formats = (i->value);
  210. } else
  211. {}
  212. }
  213. args.variables = body;
  214. ast_ari_channels_originate(headers, &args, response);
  215. #if defined(AST_DEVMODE)
  216. code = response->response_code;
  217. switch (code) {
  218. case 0: /* Implementation is still a stub, or the code wasn't set */
  219. is_valid = response->message == NULL;
  220. break;
  221. case 500: /* Internal Server Error */
  222. case 501: /* Not Implemented */
  223. case 400: /* Invalid parameters for originating a channel. */
  224. case 409: /* Channel with given unique ID already exists. */
  225. is_valid = 1;
  226. break;
  227. default:
  228. if (200 <= code && code <= 299) {
  229. is_valid = ast_ari_validate_channel(
  230. response->message);
  231. } else {
  232. ast_log(LOG_ERROR, "Invalid error response %d for /channels\n", code);
  233. is_valid = 0;
  234. }
  235. }
  236. if (!is_valid) {
  237. ast_log(LOG_ERROR, "Response validation failed for /channels\n");
  238. ast_ari_response_error(response, 500,
  239. "Internal Server Error", "Response validation failed");
  240. }
  241. #endif /* AST_DEVMODE */
  242. fin: __attribute__((unused))
  243. return;
  244. }
  245. /*!
  246. * \brief Parameter parsing callback for /channels/{channelId}.
  247. * \param get_params GET parameters in the HTTP request.
  248. * \param path_vars Path variables extracted from the request.
  249. * \param headers HTTP headers.
  250. * \param[out] response Response to the HTTP request.
  251. */
  252. static void ast_ari_channels_get_cb(
  253. struct ast_tcptls_session_instance *ser,
  254. struct ast_variable *get_params, struct ast_variable *path_vars,
  255. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  256. {
  257. struct ast_ari_channels_get_args args = {};
  258. struct ast_variable *i;
  259. #if defined(AST_DEVMODE)
  260. int is_valid;
  261. int code;
  262. #endif /* AST_DEVMODE */
  263. for (i = path_vars; i; i = i->next) {
  264. if (strcmp(i->name, "channelId") == 0) {
  265. args.channel_id = (i->value);
  266. } else
  267. {}
  268. }
  269. ast_ari_channels_get(headers, &args, response);
  270. #if defined(AST_DEVMODE)
  271. code = response->response_code;
  272. switch (code) {
  273. case 0: /* Implementation is still a stub, or the code wasn't set */
  274. is_valid = response->message == NULL;
  275. break;
  276. case 500: /* Internal Server Error */
  277. case 501: /* Not Implemented */
  278. case 404: /* Channel not found */
  279. is_valid = 1;
  280. break;
  281. default:
  282. if (200 <= code && code <= 299) {
  283. is_valid = ast_ari_validate_channel(
  284. response->message);
  285. } else {
  286. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
  287. is_valid = 0;
  288. }
  289. }
  290. if (!is_valid) {
  291. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
  292. ast_ari_response_error(response, 500,
  293. "Internal Server Error", "Response validation failed");
  294. }
  295. #endif /* AST_DEVMODE */
  296. fin: __attribute__((unused))
  297. return;
  298. }
  299. int ast_ari_channels_originate_with_id_parse_body(
  300. struct ast_json *body,
  301. struct ast_ari_channels_originate_with_id_args *args)
  302. {
  303. struct ast_json *field;
  304. /* Parse query parameters out of it */
  305. field = ast_json_object_get(body, "endpoint");
  306. if (field) {
  307. args->endpoint = ast_json_string_get(field);
  308. }
  309. field = ast_json_object_get(body, "extension");
  310. if (field) {
  311. args->extension = ast_json_string_get(field);
  312. }
  313. field = ast_json_object_get(body, "context");
  314. if (field) {
  315. args->context = ast_json_string_get(field);
  316. }
  317. field = ast_json_object_get(body, "priority");
  318. if (field) {
  319. args->priority = ast_json_integer_get(field);
  320. }
  321. field = ast_json_object_get(body, "label");
  322. if (field) {
  323. args->label = ast_json_string_get(field);
  324. }
  325. field = ast_json_object_get(body, "app");
  326. if (field) {
  327. args->app = ast_json_string_get(field);
  328. }
  329. field = ast_json_object_get(body, "appArgs");
  330. if (field) {
  331. args->app_args = ast_json_string_get(field);
  332. }
  333. field = ast_json_object_get(body, "callerId");
  334. if (field) {
  335. args->caller_id = ast_json_string_get(field);
  336. }
  337. field = ast_json_object_get(body, "timeout");
  338. if (field) {
  339. args->timeout = ast_json_integer_get(field);
  340. }
  341. field = ast_json_object_get(body, "otherChannelId");
  342. if (field) {
  343. args->other_channel_id = ast_json_string_get(field);
  344. }
  345. field = ast_json_object_get(body, "originator");
  346. if (field) {
  347. args->originator = ast_json_string_get(field);
  348. }
  349. field = ast_json_object_get(body, "formats");
  350. if (field) {
  351. args->formats = ast_json_string_get(field);
  352. }
  353. return 0;
  354. }
  355. /*!
  356. * \brief Parameter parsing callback for /channels/{channelId}.
  357. * \param get_params GET parameters in the HTTP request.
  358. * \param path_vars Path variables extracted from the request.
  359. * \param headers HTTP headers.
  360. * \param[out] response Response to the HTTP request.
  361. */
  362. static void ast_ari_channels_originate_with_id_cb(
  363. struct ast_tcptls_session_instance *ser,
  364. struct ast_variable *get_params, struct ast_variable *path_vars,
  365. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  366. {
  367. struct ast_ari_channels_originate_with_id_args args = {};
  368. struct ast_variable *i;
  369. #if defined(AST_DEVMODE)
  370. int is_valid;
  371. int code;
  372. #endif /* AST_DEVMODE */
  373. for (i = get_params; i; i = i->next) {
  374. if (strcmp(i->name, "endpoint") == 0) {
  375. args.endpoint = (i->value);
  376. } else
  377. if (strcmp(i->name, "extension") == 0) {
  378. args.extension = (i->value);
  379. } else
  380. if (strcmp(i->name, "context") == 0) {
  381. args.context = (i->value);
  382. } else
  383. if (strcmp(i->name, "priority") == 0) {
  384. args.priority = atol(i->value);
  385. } else
  386. if (strcmp(i->name, "label") == 0) {
  387. args.label = (i->value);
  388. } else
  389. if (strcmp(i->name, "app") == 0) {
  390. args.app = (i->value);
  391. } else
  392. if (strcmp(i->name, "appArgs") == 0) {
  393. args.app_args = (i->value);
  394. } else
  395. if (strcmp(i->name, "callerId") == 0) {
  396. args.caller_id = (i->value);
  397. } else
  398. if (strcmp(i->name, "timeout") == 0) {
  399. args.timeout = atoi(i->value);
  400. } else
  401. if (strcmp(i->name, "otherChannelId") == 0) {
  402. args.other_channel_id = (i->value);
  403. } else
  404. if (strcmp(i->name, "originator") == 0) {
  405. args.originator = (i->value);
  406. } else
  407. if (strcmp(i->name, "formats") == 0) {
  408. args.formats = (i->value);
  409. } else
  410. {}
  411. }
  412. for (i = path_vars; i; i = i->next) {
  413. if (strcmp(i->name, "channelId") == 0) {
  414. args.channel_id = (i->value);
  415. } else
  416. {}
  417. }
  418. args.variables = body;
  419. ast_ari_channels_originate_with_id(headers, &args, response);
  420. #if defined(AST_DEVMODE)
  421. code = response->response_code;
  422. switch (code) {
  423. case 0: /* Implementation is still a stub, or the code wasn't set */
  424. is_valid = response->message == NULL;
  425. break;
  426. case 500: /* Internal Server Error */
  427. case 501: /* Not Implemented */
  428. case 400: /* Invalid parameters for originating a channel. */
  429. case 409: /* Channel with given unique ID already exists. */
  430. is_valid = 1;
  431. break;
  432. default:
  433. if (200 <= code && code <= 299) {
  434. is_valid = ast_ari_validate_channel(
  435. response->message);
  436. } else {
  437. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
  438. is_valid = 0;
  439. }
  440. }
  441. if (!is_valid) {
  442. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
  443. ast_ari_response_error(response, 500,
  444. "Internal Server Error", "Response validation failed");
  445. }
  446. #endif /* AST_DEVMODE */
  447. fin: __attribute__((unused))
  448. return;
  449. }
  450. int ast_ari_channels_hangup_parse_body(
  451. struct ast_json *body,
  452. struct ast_ari_channels_hangup_args *args)
  453. {
  454. struct ast_json *field;
  455. /* Parse query parameters out of it */
  456. field = ast_json_object_get(body, "reason");
  457. if (field) {
  458. args->reason = ast_json_string_get(field);
  459. }
  460. return 0;
  461. }
  462. /*!
  463. * \brief Parameter parsing callback for /channels/{channelId}.
  464. * \param get_params GET parameters in the HTTP request.
  465. * \param path_vars Path variables extracted from the request.
  466. * \param headers HTTP headers.
  467. * \param[out] response Response to the HTTP request.
  468. */
  469. static void ast_ari_channels_hangup_cb(
  470. struct ast_tcptls_session_instance *ser,
  471. struct ast_variable *get_params, struct ast_variable *path_vars,
  472. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  473. {
  474. struct ast_ari_channels_hangup_args args = {};
  475. struct ast_variable *i;
  476. #if defined(AST_DEVMODE)
  477. int is_valid;
  478. int code;
  479. #endif /* AST_DEVMODE */
  480. for (i = get_params; i; i = i->next) {
  481. if (strcmp(i->name, "reason") == 0) {
  482. args.reason = (i->value);
  483. } else
  484. {}
  485. }
  486. for (i = path_vars; i; i = i->next) {
  487. if (strcmp(i->name, "channelId") == 0) {
  488. args.channel_id = (i->value);
  489. } else
  490. {}
  491. }
  492. if (ast_ari_channels_hangup_parse_body(body, &args)) {
  493. ast_ari_response_alloc_failed(response);
  494. goto fin;
  495. }
  496. ast_ari_channels_hangup(headers, &args, response);
  497. #if defined(AST_DEVMODE)
  498. code = response->response_code;
  499. switch (code) {
  500. case 0: /* Implementation is still a stub, or the code wasn't set */
  501. is_valid = response->message == NULL;
  502. break;
  503. case 500: /* Internal Server Error */
  504. case 501: /* Not Implemented */
  505. case 400: /* Invalid reason for hangup provided */
  506. case 404: /* Channel not found */
  507. is_valid = 1;
  508. break;
  509. default:
  510. if (200 <= code && code <= 299) {
  511. is_valid = ast_ari_validate_void(
  512. response->message);
  513. } else {
  514. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
  515. is_valid = 0;
  516. }
  517. }
  518. if (!is_valid) {
  519. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
  520. ast_ari_response_error(response, 500,
  521. "Internal Server Error", "Response validation failed");
  522. }
  523. #endif /* AST_DEVMODE */
  524. fin: __attribute__((unused))
  525. return;
  526. }
  527. int ast_ari_channels_continue_in_dialplan_parse_body(
  528. struct ast_json *body,
  529. struct ast_ari_channels_continue_in_dialplan_args *args)
  530. {
  531. struct ast_json *field;
  532. /* Parse query parameters out of it */
  533. field = ast_json_object_get(body, "context");
  534. if (field) {
  535. args->context = ast_json_string_get(field);
  536. }
  537. field = ast_json_object_get(body, "extension");
  538. if (field) {
  539. args->extension = ast_json_string_get(field);
  540. }
  541. field = ast_json_object_get(body, "priority");
  542. if (field) {
  543. args->priority = ast_json_integer_get(field);
  544. }
  545. field = ast_json_object_get(body, "label");
  546. if (field) {
  547. args->label = ast_json_string_get(field);
  548. }
  549. return 0;
  550. }
  551. /*!
  552. * \brief Parameter parsing callback for /channels/{channelId}/continue.
  553. * \param get_params GET parameters in the HTTP request.
  554. * \param path_vars Path variables extracted from the request.
  555. * \param headers HTTP headers.
  556. * \param[out] response Response to the HTTP request.
  557. */
  558. static void ast_ari_channels_continue_in_dialplan_cb(
  559. struct ast_tcptls_session_instance *ser,
  560. struct ast_variable *get_params, struct ast_variable *path_vars,
  561. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  562. {
  563. struct ast_ari_channels_continue_in_dialplan_args args = {};
  564. struct ast_variable *i;
  565. #if defined(AST_DEVMODE)
  566. int is_valid;
  567. int code;
  568. #endif /* AST_DEVMODE */
  569. for (i = get_params; i; i = i->next) {
  570. if (strcmp(i->name, "context") == 0) {
  571. args.context = (i->value);
  572. } else
  573. if (strcmp(i->name, "extension") == 0) {
  574. args.extension = (i->value);
  575. } else
  576. if (strcmp(i->name, "priority") == 0) {
  577. args.priority = atoi(i->value);
  578. } else
  579. if (strcmp(i->name, "label") == 0) {
  580. args.label = (i->value);
  581. } else
  582. {}
  583. }
  584. for (i = path_vars; i; i = i->next) {
  585. if (strcmp(i->name, "channelId") == 0) {
  586. args.channel_id = (i->value);
  587. } else
  588. {}
  589. }
  590. if (ast_ari_channels_continue_in_dialplan_parse_body(body, &args)) {
  591. ast_ari_response_alloc_failed(response);
  592. goto fin;
  593. }
  594. ast_ari_channels_continue_in_dialplan(headers, &args, response);
  595. #if defined(AST_DEVMODE)
  596. code = response->response_code;
  597. switch (code) {
  598. case 0: /* Implementation is still a stub, or the code wasn't set */
  599. is_valid = response->message == NULL;
  600. break;
  601. case 500: /* Internal Server Error */
  602. case 501: /* Not Implemented */
  603. case 404: /* Channel not found */
  604. case 409: /* Channel not in a Stasis application */
  605. is_valid = 1;
  606. break;
  607. default:
  608. if (200 <= code && code <= 299) {
  609. is_valid = ast_ari_validate_void(
  610. response->message);
  611. } else {
  612. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/continue\n", code);
  613. is_valid = 0;
  614. }
  615. }
  616. if (!is_valid) {
  617. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/continue\n");
  618. ast_ari_response_error(response, 500,
  619. "Internal Server Error", "Response validation failed");
  620. }
  621. #endif /* AST_DEVMODE */
  622. fin: __attribute__((unused))
  623. return;
  624. }
  625. int ast_ari_channels_redirect_parse_body(
  626. struct ast_json *body,
  627. struct ast_ari_channels_redirect_args *args)
  628. {
  629. struct ast_json *field;
  630. /* Parse query parameters out of it */
  631. field = ast_json_object_get(body, "endpoint");
  632. if (field) {
  633. args->endpoint = ast_json_string_get(field);
  634. }
  635. return 0;
  636. }
  637. /*!
  638. * \brief Parameter parsing callback for /channels/{channelId}/redirect.
  639. * \param get_params GET parameters in the HTTP request.
  640. * \param path_vars Path variables extracted from the request.
  641. * \param headers HTTP headers.
  642. * \param[out] response Response to the HTTP request.
  643. */
  644. static void ast_ari_channels_redirect_cb(
  645. struct ast_tcptls_session_instance *ser,
  646. struct ast_variable *get_params, struct ast_variable *path_vars,
  647. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  648. {
  649. struct ast_ari_channels_redirect_args args = {};
  650. struct ast_variable *i;
  651. #if defined(AST_DEVMODE)
  652. int is_valid;
  653. int code;
  654. #endif /* AST_DEVMODE */
  655. for (i = get_params; i; i = i->next) {
  656. if (strcmp(i->name, "endpoint") == 0) {
  657. args.endpoint = (i->value);
  658. } else
  659. {}
  660. }
  661. for (i = path_vars; i; i = i->next) {
  662. if (strcmp(i->name, "channelId") == 0) {
  663. args.channel_id = (i->value);
  664. } else
  665. {}
  666. }
  667. if (ast_ari_channels_redirect_parse_body(body, &args)) {
  668. ast_ari_response_alloc_failed(response);
  669. goto fin;
  670. }
  671. ast_ari_channels_redirect(headers, &args, response);
  672. #if defined(AST_DEVMODE)
  673. code = response->response_code;
  674. switch (code) {
  675. case 0: /* Implementation is still a stub, or the code wasn't set */
  676. is_valid = response->message == NULL;
  677. break;
  678. case 500: /* Internal Server Error */
  679. case 501: /* Not Implemented */
  680. case 400: /* Endpoint parameter not provided */
  681. case 404: /* Channel or endpoint not found */
  682. case 409: /* Channel not in a Stasis application */
  683. case 422: /* Endpoint is not the same type as the channel */
  684. is_valid = 1;
  685. break;
  686. default:
  687. if (200 <= code && code <= 299) {
  688. is_valid = ast_ari_validate_void(
  689. response->message);
  690. } else {
  691. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/redirect\n", code);
  692. is_valid = 0;
  693. }
  694. }
  695. if (!is_valid) {
  696. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/redirect\n");
  697. ast_ari_response_error(response, 500,
  698. "Internal Server Error", "Response validation failed");
  699. }
  700. #endif /* AST_DEVMODE */
  701. fin: __attribute__((unused))
  702. return;
  703. }
  704. /*!
  705. * \brief Parameter parsing callback for /channels/{channelId}/answer.
  706. * \param get_params GET parameters in the HTTP request.
  707. * \param path_vars Path variables extracted from the request.
  708. * \param headers HTTP headers.
  709. * \param[out] response Response to the HTTP request.
  710. */
  711. static void ast_ari_channels_answer_cb(
  712. struct ast_tcptls_session_instance *ser,
  713. struct ast_variable *get_params, struct ast_variable *path_vars,
  714. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  715. {
  716. struct ast_ari_channels_answer_args args = {};
  717. struct ast_variable *i;
  718. #if defined(AST_DEVMODE)
  719. int is_valid;
  720. int code;
  721. #endif /* AST_DEVMODE */
  722. for (i = path_vars; i; i = i->next) {
  723. if (strcmp(i->name, "channelId") == 0) {
  724. args.channel_id = (i->value);
  725. } else
  726. {}
  727. }
  728. ast_ari_channels_answer(headers, &args, response);
  729. #if defined(AST_DEVMODE)
  730. code = response->response_code;
  731. switch (code) {
  732. case 0: /* Implementation is still a stub, or the code wasn't set */
  733. is_valid = response->message == NULL;
  734. break;
  735. case 500: /* Internal Server Error */
  736. case 501: /* Not Implemented */
  737. case 404: /* Channel not found */
  738. case 409: /* Channel not in a Stasis application */
  739. is_valid = 1;
  740. break;
  741. default:
  742. if (200 <= code && code <= 299) {
  743. is_valid = ast_ari_validate_void(
  744. response->message);
  745. } else {
  746. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/answer\n", code);
  747. is_valid = 0;
  748. }
  749. }
  750. if (!is_valid) {
  751. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/answer\n");
  752. ast_ari_response_error(response, 500,
  753. "Internal Server Error", "Response validation failed");
  754. }
  755. #endif /* AST_DEVMODE */
  756. fin: __attribute__((unused))
  757. return;
  758. }
  759. /*!
  760. * \brief Parameter parsing callback for /channels/{channelId}/ring.
  761. * \param get_params GET parameters in the HTTP request.
  762. * \param path_vars Path variables extracted from the request.
  763. * \param headers HTTP headers.
  764. * \param[out] response Response to the HTTP request.
  765. */
  766. static void ast_ari_channels_ring_cb(
  767. struct ast_tcptls_session_instance *ser,
  768. struct ast_variable *get_params, struct ast_variable *path_vars,
  769. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  770. {
  771. struct ast_ari_channels_ring_args args = {};
  772. struct ast_variable *i;
  773. #if defined(AST_DEVMODE)
  774. int is_valid;
  775. int code;
  776. #endif /* AST_DEVMODE */
  777. for (i = path_vars; i; i = i->next) {
  778. if (strcmp(i->name, "channelId") == 0) {
  779. args.channel_id = (i->value);
  780. } else
  781. {}
  782. }
  783. ast_ari_channels_ring(headers, &args, response);
  784. #if defined(AST_DEVMODE)
  785. code = response->response_code;
  786. switch (code) {
  787. case 0: /* Implementation is still a stub, or the code wasn't set */
  788. is_valid = response->message == NULL;
  789. break;
  790. case 500: /* Internal Server Error */
  791. case 501: /* Not Implemented */
  792. case 404: /* Channel not found */
  793. case 409: /* Channel not in a Stasis application */
  794. is_valid = 1;
  795. break;
  796. default:
  797. if (200 <= code && code <= 299) {
  798. is_valid = ast_ari_validate_void(
  799. response->message);
  800. } else {
  801. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/ring\n", code);
  802. is_valid = 0;
  803. }
  804. }
  805. if (!is_valid) {
  806. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/ring\n");
  807. ast_ari_response_error(response, 500,
  808. "Internal Server Error", "Response validation failed");
  809. }
  810. #endif /* AST_DEVMODE */
  811. fin: __attribute__((unused))
  812. return;
  813. }
  814. /*!
  815. * \brief Parameter parsing callback for /channels/{channelId}/ring.
  816. * \param get_params GET parameters in the HTTP request.
  817. * \param path_vars Path variables extracted from the request.
  818. * \param headers HTTP headers.
  819. * \param[out] response Response to the HTTP request.
  820. */
  821. static void ast_ari_channels_ring_stop_cb(
  822. struct ast_tcptls_session_instance *ser,
  823. struct ast_variable *get_params, struct ast_variable *path_vars,
  824. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  825. {
  826. struct ast_ari_channels_ring_stop_args args = {};
  827. struct ast_variable *i;
  828. #if defined(AST_DEVMODE)
  829. int is_valid;
  830. int code;
  831. #endif /* AST_DEVMODE */
  832. for (i = path_vars; i; i = i->next) {
  833. if (strcmp(i->name, "channelId") == 0) {
  834. args.channel_id = (i->value);
  835. } else
  836. {}
  837. }
  838. ast_ari_channels_ring_stop(headers, &args, response);
  839. #if defined(AST_DEVMODE)
  840. code = response->response_code;
  841. switch (code) {
  842. case 0: /* Implementation is still a stub, or the code wasn't set */
  843. is_valid = response->message == NULL;
  844. break;
  845. case 500: /* Internal Server Error */
  846. case 501: /* Not Implemented */
  847. case 404: /* Channel not found */
  848. case 409: /* Channel not in a Stasis application */
  849. is_valid = 1;
  850. break;
  851. default:
  852. if (200 <= code && code <= 299) {
  853. is_valid = ast_ari_validate_void(
  854. response->message);
  855. } else {
  856. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/ring\n", code);
  857. is_valid = 0;
  858. }
  859. }
  860. if (!is_valid) {
  861. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/ring\n");
  862. ast_ari_response_error(response, 500,
  863. "Internal Server Error", "Response validation failed");
  864. }
  865. #endif /* AST_DEVMODE */
  866. fin: __attribute__((unused))
  867. return;
  868. }
  869. int ast_ari_channels_send_dtmf_parse_body(
  870. struct ast_json *body,
  871. struct ast_ari_channels_send_dtmf_args *args)
  872. {
  873. struct ast_json *field;
  874. /* Parse query parameters out of it */
  875. field = ast_json_object_get(body, "dtmf");
  876. if (field) {
  877. args->dtmf = ast_json_string_get(field);
  878. }
  879. field = ast_json_object_get(body, "before");
  880. if (field) {
  881. args->before = ast_json_integer_get(field);
  882. }
  883. field = ast_json_object_get(body, "between");
  884. if (field) {
  885. args->between = ast_json_integer_get(field);
  886. }
  887. field = ast_json_object_get(body, "duration");
  888. if (field) {
  889. args->duration = ast_json_integer_get(field);
  890. }
  891. field = ast_json_object_get(body, "after");
  892. if (field) {
  893. args->after = ast_json_integer_get(field);
  894. }
  895. return 0;
  896. }
  897. /*!
  898. * \brief Parameter parsing callback for /channels/{channelId}/dtmf.
  899. * \param get_params GET parameters in the HTTP request.
  900. * \param path_vars Path variables extracted from the request.
  901. * \param headers HTTP headers.
  902. * \param[out] response Response to the HTTP request.
  903. */
  904. static void ast_ari_channels_send_dtmf_cb(
  905. struct ast_tcptls_session_instance *ser,
  906. struct ast_variable *get_params, struct ast_variable *path_vars,
  907. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  908. {
  909. struct ast_ari_channels_send_dtmf_args args = {};
  910. struct ast_variable *i;
  911. #if defined(AST_DEVMODE)
  912. int is_valid;
  913. int code;
  914. #endif /* AST_DEVMODE */
  915. for (i = get_params; i; i = i->next) {
  916. if (strcmp(i->name, "dtmf") == 0) {
  917. args.dtmf = (i->value);
  918. } else
  919. if (strcmp(i->name, "before") == 0) {
  920. args.before = atoi(i->value);
  921. } else
  922. if (strcmp(i->name, "between") == 0) {
  923. args.between = atoi(i->value);
  924. } else
  925. if (strcmp(i->name, "duration") == 0) {
  926. args.duration = atoi(i->value);
  927. } else
  928. if (strcmp(i->name, "after") == 0) {
  929. args.after = atoi(i->value);
  930. } else
  931. {}
  932. }
  933. for (i = path_vars; i; i = i->next) {
  934. if (strcmp(i->name, "channelId") == 0) {
  935. args.channel_id = (i->value);
  936. } else
  937. {}
  938. }
  939. if (ast_ari_channels_send_dtmf_parse_body(body, &args)) {
  940. ast_ari_response_alloc_failed(response);
  941. goto fin;
  942. }
  943. ast_ari_channels_send_dtmf(headers, &args, response);
  944. #if defined(AST_DEVMODE)
  945. code = response->response_code;
  946. switch (code) {
  947. case 0: /* Implementation is still a stub, or the code wasn't set */
  948. is_valid = response->message == NULL;
  949. break;
  950. case 500: /* Internal Server Error */
  951. case 501: /* Not Implemented */
  952. case 400: /* DTMF is required */
  953. case 404: /* Channel not found */
  954. case 409: /* Channel not in a Stasis application */
  955. is_valid = 1;
  956. break;
  957. default:
  958. if (200 <= code && code <= 299) {
  959. is_valid = ast_ari_validate_void(
  960. response->message);
  961. } else {
  962. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/dtmf\n", code);
  963. is_valid = 0;
  964. }
  965. }
  966. if (!is_valid) {
  967. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/dtmf\n");
  968. ast_ari_response_error(response, 500,
  969. "Internal Server Error", "Response validation failed");
  970. }
  971. #endif /* AST_DEVMODE */
  972. fin: __attribute__((unused))
  973. return;
  974. }
  975. int ast_ari_channels_mute_parse_body(
  976. struct ast_json *body,
  977. struct ast_ari_channels_mute_args *args)
  978. {
  979. struct ast_json *field;
  980. /* Parse query parameters out of it */
  981. field = ast_json_object_get(body, "direction");
  982. if (field) {
  983. args->direction = ast_json_string_get(field);
  984. }
  985. return 0;
  986. }
  987. /*!
  988. * \brief Parameter parsing callback for /channels/{channelId}/mute.
  989. * \param get_params GET parameters in the HTTP request.
  990. * \param path_vars Path variables extracted from the request.
  991. * \param headers HTTP headers.
  992. * \param[out] response Response to the HTTP request.
  993. */
  994. static void ast_ari_channels_mute_cb(
  995. struct ast_tcptls_session_instance *ser,
  996. struct ast_variable *get_params, struct ast_variable *path_vars,
  997. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  998. {
  999. struct ast_ari_channels_mute_args args = {};
  1000. struct ast_variable *i;
  1001. #if defined(AST_DEVMODE)
  1002. int is_valid;
  1003. int code;
  1004. #endif /* AST_DEVMODE */
  1005. for (i = get_params; i; i = i->next) {
  1006. if (strcmp(i->name, "direction") == 0) {
  1007. args.direction = (i->value);
  1008. } else
  1009. {}
  1010. }
  1011. for (i = path_vars; i; i = i->next) {
  1012. if (strcmp(i->name, "channelId") == 0) {
  1013. args.channel_id = (i->value);
  1014. } else
  1015. {}
  1016. }
  1017. if (ast_ari_channels_mute_parse_body(body, &args)) {
  1018. ast_ari_response_alloc_failed(response);
  1019. goto fin;
  1020. }
  1021. ast_ari_channels_mute(headers, &args, response);
  1022. #if defined(AST_DEVMODE)
  1023. code = response->response_code;
  1024. switch (code) {
  1025. case 0: /* Implementation is still a stub, or the code wasn't set */
  1026. is_valid = response->message == NULL;
  1027. break;
  1028. case 500: /* Internal Server Error */
  1029. case 501: /* Not Implemented */
  1030. case 404: /* Channel not found */
  1031. case 409: /* Channel not in a Stasis application */
  1032. is_valid = 1;
  1033. break;
  1034. default:
  1035. if (200 <= code && code <= 299) {
  1036. is_valid = ast_ari_validate_void(
  1037. response->message);
  1038. } else {
  1039. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mute\n", code);
  1040. is_valid = 0;
  1041. }
  1042. }
  1043. if (!is_valid) {
  1044. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mute\n");
  1045. ast_ari_response_error(response, 500,
  1046. "Internal Server Error", "Response validation failed");
  1047. }
  1048. #endif /* AST_DEVMODE */
  1049. fin: __attribute__((unused))
  1050. return;
  1051. }
  1052. int ast_ari_channels_unmute_parse_body(
  1053. struct ast_json *body,
  1054. struct ast_ari_channels_unmute_args *args)
  1055. {
  1056. struct ast_json *field;
  1057. /* Parse query parameters out of it */
  1058. field = ast_json_object_get(body, "direction");
  1059. if (field) {
  1060. args->direction = ast_json_string_get(field);
  1061. }
  1062. return 0;
  1063. }
  1064. /*!
  1065. * \brief Parameter parsing callback for /channels/{channelId}/mute.
  1066. * \param get_params GET parameters in the HTTP request.
  1067. * \param path_vars Path variables extracted from the request.
  1068. * \param headers HTTP headers.
  1069. * \param[out] response Response to the HTTP request.
  1070. */
  1071. static void ast_ari_channels_unmute_cb(
  1072. struct ast_tcptls_session_instance *ser,
  1073. struct ast_variable *get_params, struct ast_variable *path_vars,
  1074. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1075. {
  1076. struct ast_ari_channels_unmute_args args = {};
  1077. struct ast_variable *i;
  1078. #if defined(AST_DEVMODE)
  1079. int is_valid;
  1080. int code;
  1081. #endif /* AST_DEVMODE */
  1082. for (i = get_params; i; i = i->next) {
  1083. if (strcmp(i->name, "direction") == 0) {
  1084. args.direction = (i->value);
  1085. } else
  1086. {}
  1087. }
  1088. for (i = path_vars; i; i = i->next) {
  1089. if (strcmp(i->name, "channelId") == 0) {
  1090. args.channel_id = (i->value);
  1091. } else
  1092. {}
  1093. }
  1094. if (ast_ari_channels_unmute_parse_body(body, &args)) {
  1095. ast_ari_response_alloc_failed(response);
  1096. goto fin;
  1097. }
  1098. ast_ari_channels_unmute(headers, &args, response);
  1099. #if defined(AST_DEVMODE)
  1100. code = response->response_code;
  1101. switch (code) {
  1102. case 0: /* Implementation is still a stub, or the code wasn't set */
  1103. is_valid = response->message == NULL;
  1104. break;
  1105. case 500: /* Internal Server Error */
  1106. case 501: /* Not Implemented */
  1107. case 404: /* Channel not found */
  1108. case 409: /* Channel not in a Stasis application */
  1109. is_valid = 1;
  1110. break;
  1111. default:
  1112. if (200 <= code && code <= 299) {
  1113. is_valid = ast_ari_validate_void(
  1114. response->message);
  1115. } else {
  1116. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mute\n", code);
  1117. is_valid = 0;
  1118. }
  1119. }
  1120. if (!is_valid) {
  1121. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mute\n");
  1122. ast_ari_response_error(response, 500,
  1123. "Internal Server Error", "Response validation failed");
  1124. }
  1125. #endif /* AST_DEVMODE */
  1126. fin: __attribute__((unused))
  1127. return;
  1128. }
  1129. /*!
  1130. * \brief Parameter parsing callback for /channels/{channelId}/hold.
  1131. * \param get_params GET parameters in the HTTP request.
  1132. * \param path_vars Path variables extracted from the request.
  1133. * \param headers HTTP headers.
  1134. * \param[out] response Response to the HTTP request.
  1135. */
  1136. static void ast_ari_channels_hold_cb(
  1137. struct ast_tcptls_session_instance *ser,
  1138. struct ast_variable *get_params, struct ast_variable *path_vars,
  1139. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1140. {
  1141. struct ast_ari_channels_hold_args args = {};
  1142. struct ast_variable *i;
  1143. #if defined(AST_DEVMODE)
  1144. int is_valid;
  1145. int code;
  1146. #endif /* AST_DEVMODE */
  1147. for (i = path_vars; i; i = i->next) {
  1148. if (strcmp(i->name, "channelId") == 0) {
  1149. args.channel_id = (i->value);
  1150. } else
  1151. {}
  1152. }
  1153. ast_ari_channels_hold(headers, &args, response);
  1154. #if defined(AST_DEVMODE)
  1155. code = response->response_code;
  1156. switch (code) {
  1157. case 0: /* Implementation is still a stub, or the code wasn't set */
  1158. is_valid = response->message == NULL;
  1159. break;
  1160. case 500: /* Internal Server Error */
  1161. case 501: /* Not Implemented */
  1162. case 404: /* Channel not found */
  1163. case 409: /* Channel not in a Stasis application */
  1164. is_valid = 1;
  1165. break;
  1166. default:
  1167. if (200 <= code && code <= 299) {
  1168. is_valid = ast_ari_validate_void(
  1169. response->message);
  1170. } else {
  1171. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
  1172. is_valid = 0;
  1173. }
  1174. }
  1175. if (!is_valid) {
  1176. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
  1177. ast_ari_response_error(response, 500,
  1178. "Internal Server Error", "Response validation failed");
  1179. }
  1180. #endif /* AST_DEVMODE */
  1181. fin: __attribute__((unused))
  1182. return;
  1183. }
  1184. /*!
  1185. * \brief Parameter parsing callback for /channels/{channelId}/hold.
  1186. * \param get_params GET parameters in the HTTP request.
  1187. * \param path_vars Path variables extracted from the request.
  1188. * \param headers HTTP headers.
  1189. * \param[out] response Response to the HTTP request.
  1190. */
  1191. static void ast_ari_channels_unhold_cb(
  1192. struct ast_tcptls_session_instance *ser,
  1193. struct ast_variable *get_params, struct ast_variable *path_vars,
  1194. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1195. {
  1196. struct ast_ari_channels_unhold_args args = {};
  1197. struct ast_variable *i;
  1198. #if defined(AST_DEVMODE)
  1199. int is_valid;
  1200. int code;
  1201. #endif /* AST_DEVMODE */
  1202. for (i = path_vars; i; i = i->next) {
  1203. if (strcmp(i->name, "channelId") == 0) {
  1204. args.channel_id = (i->value);
  1205. } else
  1206. {}
  1207. }
  1208. ast_ari_channels_unhold(headers, &args, response);
  1209. #if defined(AST_DEVMODE)
  1210. code = response->response_code;
  1211. switch (code) {
  1212. case 0: /* Implementation is still a stub, or the code wasn't set */
  1213. is_valid = response->message == NULL;
  1214. break;
  1215. case 500: /* Internal Server Error */
  1216. case 501: /* Not Implemented */
  1217. case 404: /* Channel not found */
  1218. case 409: /* Channel not in a Stasis application */
  1219. is_valid = 1;
  1220. break;
  1221. default:
  1222. if (200 <= code && code <= 299) {
  1223. is_valid = ast_ari_validate_void(
  1224. response->message);
  1225. } else {
  1226. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
  1227. is_valid = 0;
  1228. }
  1229. }
  1230. if (!is_valid) {
  1231. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
  1232. ast_ari_response_error(response, 500,
  1233. "Internal Server Error", "Response validation failed");
  1234. }
  1235. #endif /* AST_DEVMODE */
  1236. fin: __attribute__((unused))
  1237. return;
  1238. }
  1239. int ast_ari_channels_start_moh_parse_body(
  1240. struct ast_json *body,
  1241. struct ast_ari_channels_start_moh_args *args)
  1242. {
  1243. struct ast_json *field;
  1244. /* Parse query parameters out of it */
  1245. field = ast_json_object_get(body, "mohClass");
  1246. if (field) {
  1247. args->moh_class = ast_json_string_get(field);
  1248. }
  1249. return 0;
  1250. }
  1251. /*!
  1252. * \brief Parameter parsing callback for /channels/{channelId}/moh.
  1253. * \param get_params GET parameters in the HTTP request.
  1254. * \param path_vars Path variables extracted from the request.
  1255. * \param headers HTTP headers.
  1256. * \param[out] response Response to the HTTP request.
  1257. */
  1258. static void ast_ari_channels_start_moh_cb(
  1259. struct ast_tcptls_session_instance *ser,
  1260. struct ast_variable *get_params, struct ast_variable *path_vars,
  1261. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1262. {
  1263. struct ast_ari_channels_start_moh_args args = {};
  1264. struct ast_variable *i;
  1265. #if defined(AST_DEVMODE)
  1266. int is_valid;
  1267. int code;
  1268. #endif /* AST_DEVMODE */
  1269. for (i = get_params; i; i = i->next) {
  1270. if (strcmp(i->name, "mohClass") == 0) {
  1271. args.moh_class = (i->value);
  1272. } else
  1273. {}
  1274. }
  1275. for (i = path_vars; i; i = i->next) {
  1276. if (strcmp(i->name, "channelId") == 0) {
  1277. args.channel_id = (i->value);
  1278. } else
  1279. {}
  1280. }
  1281. if (ast_ari_channels_start_moh_parse_body(body, &args)) {
  1282. ast_ari_response_alloc_failed(response);
  1283. goto fin;
  1284. }
  1285. ast_ari_channels_start_moh(headers, &args, response);
  1286. #if defined(AST_DEVMODE)
  1287. code = response->response_code;
  1288. switch (code) {
  1289. case 0: /* Implementation is still a stub, or the code wasn't set */
  1290. is_valid = response->message == NULL;
  1291. break;
  1292. case 500: /* Internal Server Error */
  1293. case 501: /* Not Implemented */
  1294. case 404: /* Channel not found */
  1295. case 409: /* Channel not in a Stasis application */
  1296. is_valid = 1;
  1297. break;
  1298. default:
  1299. if (200 <= code && code <= 299) {
  1300. is_valid = ast_ari_validate_void(
  1301. response->message);
  1302. } else {
  1303. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/moh\n", code);
  1304. is_valid = 0;
  1305. }
  1306. }
  1307. if (!is_valid) {
  1308. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/moh\n");
  1309. ast_ari_response_error(response, 500,
  1310. "Internal Server Error", "Response validation failed");
  1311. }
  1312. #endif /* AST_DEVMODE */
  1313. fin: __attribute__((unused))
  1314. return;
  1315. }
  1316. /*!
  1317. * \brief Parameter parsing callback for /channels/{channelId}/moh.
  1318. * \param get_params GET parameters in the HTTP request.
  1319. * \param path_vars Path variables extracted from the request.
  1320. * \param headers HTTP headers.
  1321. * \param[out] response Response to the HTTP request.
  1322. */
  1323. static void ast_ari_channels_stop_moh_cb(
  1324. struct ast_tcptls_session_instance *ser,
  1325. struct ast_variable *get_params, struct ast_variable *path_vars,
  1326. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1327. {
  1328. struct ast_ari_channels_stop_moh_args args = {};
  1329. struct ast_variable *i;
  1330. #if defined(AST_DEVMODE)
  1331. int is_valid;
  1332. int code;
  1333. #endif /* AST_DEVMODE */
  1334. for (i = path_vars; i; i = i->next) {
  1335. if (strcmp(i->name, "channelId") == 0) {
  1336. args.channel_id = (i->value);
  1337. } else
  1338. {}
  1339. }
  1340. ast_ari_channels_stop_moh(headers, &args, response);
  1341. #if defined(AST_DEVMODE)
  1342. code = response->response_code;
  1343. switch (code) {
  1344. case 0: /* Implementation is still a stub, or the code wasn't set */
  1345. is_valid = response->message == NULL;
  1346. break;
  1347. case 500: /* Internal Server Error */
  1348. case 501: /* Not Implemented */
  1349. case 404: /* Channel not found */
  1350. case 409: /* Channel not in a Stasis application */
  1351. is_valid = 1;
  1352. break;
  1353. default:
  1354. if (200 <= code && code <= 299) {
  1355. is_valid = ast_ari_validate_void(
  1356. response->message);
  1357. } else {
  1358. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/moh\n", code);
  1359. is_valid = 0;
  1360. }
  1361. }
  1362. if (!is_valid) {
  1363. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/moh\n");
  1364. ast_ari_response_error(response, 500,
  1365. "Internal Server Error", "Response validation failed");
  1366. }
  1367. #endif /* AST_DEVMODE */
  1368. fin: __attribute__((unused))
  1369. return;
  1370. }
  1371. /*!
  1372. * \brief Parameter parsing callback for /channels/{channelId}/silence.
  1373. * \param get_params GET parameters in the HTTP request.
  1374. * \param path_vars Path variables extracted from the request.
  1375. * \param headers HTTP headers.
  1376. * \param[out] response Response to the HTTP request.
  1377. */
  1378. static void ast_ari_channels_start_silence_cb(
  1379. struct ast_tcptls_session_instance *ser,
  1380. struct ast_variable *get_params, struct ast_variable *path_vars,
  1381. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1382. {
  1383. struct ast_ari_channels_start_silence_args args = {};
  1384. struct ast_variable *i;
  1385. #if defined(AST_DEVMODE)
  1386. int is_valid;
  1387. int code;
  1388. #endif /* AST_DEVMODE */
  1389. for (i = path_vars; i; i = i->next) {
  1390. if (strcmp(i->name, "channelId") == 0) {
  1391. args.channel_id = (i->value);
  1392. } else
  1393. {}
  1394. }
  1395. ast_ari_channels_start_silence(headers, &args, response);
  1396. #if defined(AST_DEVMODE)
  1397. code = response->response_code;
  1398. switch (code) {
  1399. case 0: /* Implementation is still a stub, or the code wasn't set */
  1400. is_valid = response->message == NULL;
  1401. break;
  1402. case 500: /* Internal Server Error */
  1403. case 501: /* Not Implemented */
  1404. case 404: /* Channel not found */
  1405. case 409: /* Channel not in a Stasis application */
  1406. is_valid = 1;
  1407. break;
  1408. default:
  1409. if (200 <= code && code <= 299) {
  1410. is_valid = ast_ari_validate_void(
  1411. response->message);
  1412. } else {
  1413. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/silence\n", code);
  1414. is_valid = 0;
  1415. }
  1416. }
  1417. if (!is_valid) {
  1418. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/silence\n");
  1419. ast_ari_response_error(response, 500,
  1420. "Internal Server Error", "Response validation failed");
  1421. }
  1422. #endif /* AST_DEVMODE */
  1423. fin: __attribute__((unused))
  1424. return;
  1425. }
  1426. /*!
  1427. * \brief Parameter parsing callback for /channels/{channelId}/silence.
  1428. * \param get_params GET parameters in the HTTP request.
  1429. * \param path_vars Path variables extracted from the request.
  1430. * \param headers HTTP headers.
  1431. * \param[out] response Response to the HTTP request.
  1432. */
  1433. static void ast_ari_channels_stop_silence_cb(
  1434. struct ast_tcptls_session_instance *ser,
  1435. struct ast_variable *get_params, struct ast_variable *path_vars,
  1436. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1437. {
  1438. struct ast_ari_channels_stop_silence_args args = {};
  1439. struct ast_variable *i;
  1440. #if defined(AST_DEVMODE)
  1441. int is_valid;
  1442. int code;
  1443. #endif /* AST_DEVMODE */
  1444. for (i = path_vars; i; i = i->next) {
  1445. if (strcmp(i->name, "channelId") == 0) {
  1446. args.channel_id = (i->value);
  1447. } else
  1448. {}
  1449. }
  1450. ast_ari_channels_stop_silence(headers, &args, response);
  1451. #if defined(AST_DEVMODE)
  1452. code = response->response_code;
  1453. switch (code) {
  1454. case 0: /* Implementation is still a stub, or the code wasn't set */
  1455. is_valid = response->message == NULL;
  1456. break;
  1457. case 500: /* Internal Server Error */
  1458. case 501: /* Not Implemented */
  1459. case 404: /* Channel not found */
  1460. case 409: /* Channel not in a Stasis application */
  1461. is_valid = 1;
  1462. break;
  1463. default:
  1464. if (200 <= code && code <= 299) {
  1465. is_valid = ast_ari_validate_void(
  1466. response->message);
  1467. } else {
  1468. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/silence\n", code);
  1469. is_valid = 0;
  1470. }
  1471. }
  1472. if (!is_valid) {
  1473. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/silence\n");
  1474. ast_ari_response_error(response, 500,
  1475. "Internal Server Error", "Response validation failed");
  1476. }
  1477. #endif /* AST_DEVMODE */
  1478. fin: __attribute__((unused))
  1479. return;
  1480. }
  1481. int ast_ari_channels_play_parse_body(
  1482. struct ast_json *body,
  1483. struct ast_ari_channels_play_args *args)
  1484. {
  1485. struct ast_json *field;
  1486. /* Parse query parameters out of it */
  1487. field = ast_json_object_get(body, "media");
  1488. if (field) {
  1489. args->media = ast_json_string_get(field);
  1490. }
  1491. field = ast_json_object_get(body, "lang");
  1492. if (field) {
  1493. args->lang = ast_json_string_get(field);
  1494. }
  1495. field = ast_json_object_get(body, "offsetms");
  1496. if (field) {
  1497. args->offsetms = ast_json_integer_get(field);
  1498. }
  1499. field = ast_json_object_get(body, "skipms");
  1500. if (field) {
  1501. args->skipms = ast_json_integer_get(field);
  1502. }
  1503. field = ast_json_object_get(body, "playbackId");
  1504. if (field) {
  1505. args->playback_id = ast_json_string_get(field);
  1506. }
  1507. return 0;
  1508. }
  1509. /*!
  1510. * \brief Parameter parsing callback for /channels/{channelId}/play.
  1511. * \param get_params GET parameters in the HTTP request.
  1512. * \param path_vars Path variables extracted from the request.
  1513. * \param headers HTTP headers.
  1514. * \param[out] response Response to the HTTP request.
  1515. */
  1516. static void ast_ari_channels_play_cb(
  1517. struct ast_tcptls_session_instance *ser,
  1518. struct ast_variable *get_params, struct ast_variable *path_vars,
  1519. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1520. {
  1521. struct ast_ari_channels_play_args args = {};
  1522. struct ast_variable *i;
  1523. #if defined(AST_DEVMODE)
  1524. int is_valid;
  1525. int code;
  1526. #endif /* AST_DEVMODE */
  1527. for (i = get_params; i; i = i->next) {
  1528. if (strcmp(i->name, "media") == 0) {
  1529. args.media = (i->value);
  1530. } else
  1531. if (strcmp(i->name, "lang") == 0) {
  1532. args.lang = (i->value);
  1533. } else
  1534. if (strcmp(i->name, "offsetms") == 0) {
  1535. args.offsetms = atoi(i->value);
  1536. } else
  1537. if (strcmp(i->name, "skipms") == 0) {
  1538. args.skipms = atoi(i->value);
  1539. } else
  1540. if (strcmp(i->name, "playbackId") == 0) {
  1541. args.playback_id = (i->value);
  1542. } else
  1543. {}
  1544. }
  1545. for (i = path_vars; i; i = i->next) {
  1546. if (strcmp(i->name, "channelId") == 0) {
  1547. args.channel_id = (i->value);
  1548. } else
  1549. {}
  1550. }
  1551. if (ast_ari_channels_play_parse_body(body, &args)) {
  1552. ast_ari_response_alloc_failed(response);
  1553. goto fin;
  1554. }
  1555. ast_ari_channels_play(headers, &args, response);
  1556. #if defined(AST_DEVMODE)
  1557. code = response->response_code;
  1558. switch (code) {
  1559. case 0: /* Implementation is still a stub, or the code wasn't set */
  1560. is_valid = response->message == NULL;
  1561. break;
  1562. case 500: /* Internal Server Error */
  1563. case 501: /* Not Implemented */
  1564. case 404: /* Channel not found */
  1565. case 409: /* Channel not in a Stasis application */
  1566. is_valid = 1;
  1567. break;
  1568. default:
  1569. if (200 <= code && code <= 299) {
  1570. is_valid = ast_ari_validate_playback(
  1571. response->message);
  1572. } else {
  1573. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/play\n", code);
  1574. is_valid = 0;
  1575. }
  1576. }
  1577. if (!is_valid) {
  1578. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/play\n");
  1579. ast_ari_response_error(response, 500,
  1580. "Internal Server Error", "Response validation failed");
  1581. }
  1582. #endif /* AST_DEVMODE */
  1583. fin: __attribute__((unused))
  1584. return;
  1585. }
  1586. int ast_ari_channels_play_with_id_parse_body(
  1587. struct ast_json *body,
  1588. struct ast_ari_channels_play_with_id_args *args)
  1589. {
  1590. struct ast_json *field;
  1591. /* Parse query parameters out of it */
  1592. field = ast_json_object_get(body, "media");
  1593. if (field) {
  1594. args->media = ast_json_string_get(field);
  1595. }
  1596. field = ast_json_object_get(body, "lang");
  1597. if (field) {
  1598. args->lang = ast_json_string_get(field);
  1599. }
  1600. field = ast_json_object_get(body, "offsetms");
  1601. if (field) {
  1602. args->offsetms = ast_json_integer_get(field);
  1603. }
  1604. field = ast_json_object_get(body, "skipms");
  1605. if (field) {
  1606. args->skipms = ast_json_integer_get(field);
  1607. }
  1608. return 0;
  1609. }
  1610. /*!
  1611. * \brief Parameter parsing callback for /channels/{channelId}/play/{playbackId}.
  1612. * \param get_params GET parameters in the HTTP request.
  1613. * \param path_vars Path variables extracted from the request.
  1614. * \param headers HTTP headers.
  1615. * \param[out] response Response to the HTTP request.
  1616. */
  1617. static void ast_ari_channels_play_with_id_cb(
  1618. struct ast_tcptls_session_instance *ser,
  1619. struct ast_variable *get_params, struct ast_variable *path_vars,
  1620. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1621. {
  1622. struct ast_ari_channels_play_with_id_args args = {};
  1623. struct ast_variable *i;
  1624. #if defined(AST_DEVMODE)
  1625. int is_valid;
  1626. int code;
  1627. #endif /* AST_DEVMODE */
  1628. for (i = get_params; i; i = i->next) {
  1629. if (strcmp(i->name, "media") == 0) {
  1630. args.media = (i->value);
  1631. } else
  1632. if (strcmp(i->name, "lang") == 0) {
  1633. args.lang = (i->value);
  1634. } else
  1635. if (strcmp(i->name, "offsetms") == 0) {
  1636. args.offsetms = atoi(i->value);
  1637. } else
  1638. if (strcmp(i->name, "skipms") == 0) {
  1639. args.skipms = atoi(i->value);
  1640. } else
  1641. {}
  1642. }
  1643. for (i = path_vars; i; i = i->next) {
  1644. if (strcmp(i->name, "channelId") == 0) {
  1645. args.channel_id = (i->value);
  1646. } else
  1647. if (strcmp(i->name, "playbackId") == 0) {
  1648. args.playback_id = (i->value);
  1649. } else
  1650. {}
  1651. }
  1652. if (ast_ari_channels_play_with_id_parse_body(body, &args)) {
  1653. ast_ari_response_alloc_failed(response);
  1654. goto fin;
  1655. }
  1656. ast_ari_channels_play_with_id(headers, &args, response);
  1657. #if defined(AST_DEVMODE)
  1658. code = response->response_code;
  1659. switch (code) {
  1660. case 0: /* Implementation is still a stub, or the code wasn't set */
  1661. is_valid = response->message == NULL;
  1662. break;
  1663. case 500: /* Internal Server Error */
  1664. case 501: /* Not Implemented */
  1665. case 404: /* Channel not found */
  1666. case 409: /* Channel not in a Stasis application */
  1667. is_valid = 1;
  1668. break;
  1669. default:
  1670. if (200 <= code && code <= 299) {
  1671. is_valid = ast_ari_validate_playback(
  1672. response->message);
  1673. } else {
  1674. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/play/{playbackId}\n", code);
  1675. is_valid = 0;
  1676. }
  1677. }
  1678. if (!is_valid) {
  1679. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/play/{playbackId}\n");
  1680. ast_ari_response_error(response, 500,
  1681. "Internal Server Error", "Response validation failed");
  1682. }
  1683. #endif /* AST_DEVMODE */
  1684. fin: __attribute__((unused))
  1685. return;
  1686. }
  1687. int ast_ari_channels_record_parse_body(
  1688. struct ast_json *body,
  1689. struct ast_ari_channels_record_args *args)
  1690. {
  1691. struct ast_json *field;
  1692. /* Parse query parameters out of it */
  1693. field = ast_json_object_get(body, "name");
  1694. if (field) {
  1695. args->name = ast_json_string_get(field);
  1696. }
  1697. field = ast_json_object_get(body, "format");
  1698. if (field) {
  1699. args->format = ast_json_string_get(field);
  1700. }
  1701. field = ast_json_object_get(body, "maxDurationSeconds");
  1702. if (field) {
  1703. args->max_duration_seconds = ast_json_integer_get(field);
  1704. }
  1705. field = ast_json_object_get(body, "maxSilenceSeconds");
  1706. if (field) {
  1707. args->max_silence_seconds = ast_json_integer_get(field);
  1708. }
  1709. field = ast_json_object_get(body, "ifExists");
  1710. if (field) {
  1711. args->if_exists = ast_json_string_get(field);
  1712. }
  1713. field = ast_json_object_get(body, "beep");
  1714. if (field) {
  1715. args->beep = ast_json_is_true(field);
  1716. }
  1717. field = ast_json_object_get(body, "terminateOn");
  1718. if (field) {
  1719. args->terminate_on = ast_json_string_get(field);
  1720. }
  1721. return 0;
  1722. }
  1723. /*!
  1724. * \brief Parameter parsing callback for /channels/{channelId}/record.
  1725. * \param get_params GET parameters in the HTTP request.
  1726. * \param path_vars Path variables extracted from the request.
  1727. * \param headers HTTP headers.
  1728. * \param[out] response Response to the HTTP request.
  1729. */
  1730. static void ast_ari_channels_record_cb(
  1731. struct ast_tcptls_session_instance *ser,
  1732. struct ast_variable *get_params, struct ast_variable *path_vars,
  1733. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1734. {
  1735. struct ast_ari_channels_record_args args = {};
  1736. struct ast_variable *i;
  1737. #if defined(AST_DEVMODE)
  1738. int is_valid;
  1739. int code;
  1740. #endif /* AST_DEVMODE */
  1741. for (i = get_params; i; i = i->next) {
  1742. if (strcmp(i->name, "name") == 0) {
  1743. args.name = (i->value);
  1744. } else
  1745. if (strcmp(i->name, "format") == 0) {
  1746. args.format = (i->value);
  1747. } else
  1748. if (strcmp(i->name, "maxDurationSeconds") == 0) {
  1749. args.max_duration_seconds = atoi(i->value);
  1750. } else
  1751. if (strcmp(i->name, "maxSilenceSeconds") == 0) {
  1752. args.max_silence_seconds = atoi(i->value);
  1753. } else
  1754. if (strcmp(i->name, "ifExists") == 0) {
  1755. args.if_exists = (i->value);
  1756. } else
  1757. if (strcmp(i->name, "beep") == 0) {
  1758. args.beep = ast_true(i->value);
  1759. } else
  1760. if (strcmp(i->name, "terminateOn") == 0) {
  1761. args.terminate_on = (i->value);
  1762. } else
  1763. {}
  1764. }
  1765. for (i = path_vars; i; i = i->next) {
  1766. if (strcmp(i->name, "channelId") == 0) {
  1767. args.channel_id = (i->value);
  1768. } else
  1769. {}
  1770. }
  1771. if (ast_ari_channels_record_parse_body(body, &args)) {
  1772. ast_ari_response_alloc_failed(response);
  1773. goto fin;
  1774. }
  1775. ast_ari_channels_record(headers, &args, response);
  1776. #if defined(AST_DEVMODE)
  1777. code = response->response_code;
  1778. switch (code) {
  1779. case 0: /* Implementation is still a stub, or the code wasn't set */
  1780. is_valid = response->message == NULL;
  1781. break;
  1782. case 500: /* Internal Server Error */
  1783. case 501: /* Not Implemented */
  1784. case 400: /* Invalid parameters */
  1785. case 404: /* Channel not found */
  1786. case 409: /* Channel is not in a Stasis application; the channel is currently bridged with other hcannels; A recording with the same name already exists on the system and can not be overwritten because it is in progress or ifExists=fail */
  1787. case 422: /* The format specified is unknown on this system */
  1788. is_valid = 1;
  1789. break;
  1790. default:
  1791. if (200 <= code && code <= 299) {
  1792. is_valid = ast_ari_validate_live_recording(
  1793. response->message);
  1794. } else {
  1795. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/record\n", code);
  1796. is_valid = 0;
  1797. }
  1798. }
  1799. if (!is_valid) {
  1800. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/record\n");
  1801. ast_ari_response_error(response, 500,
  1802. "Internal Server Error", "Response validation failed");
  1803. }
  1804. #endif /* AST_DEVMODE */
  1805. fin: __attribute__((unused))
  1806. return;
  1807. }
  1808. int ast_ari_channels_get_channel_var_parse_body(
  1809. struct ast_json *body,
  1810. struct ast_ari_channels_get_channel_var_args *args)
  1811. {
  1812. struct ast_json *field;
  1813. /* Parse query parameters out of it */
  1814. field = ast_json_object_get(body, "variable");
  1815. if (field) {
  1816. args->variable = ast_json_string_get(field);
  1817. }
  1818. return 0;
  1819. }
  1820. /*!
  1821. * \brief Parameter parsing callback for /channels/{channelId}/variable.
  1822. * \param get_params GET parameters in the HTTP request.
  1823. * \param path_vars Path variables extracted from the request.
  1824. * \param headers HTTP headers.
  1825. * \param[out] response Response to the HTTP request.
  1826. */
  1827. static void ast_ari_channels_get_channel_var_cb(
  1828. struct ast_tcptls_session_instance *ser,
  1829. struct ast_variable *get_params, struct ast_variable *path_vars,
  1830. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1831. {
  1832. struct ast_ari_channels_get_channel_var_args args = {};
  1833. struct ast_variable *i;
  1834. #if defined(AST_DEVMODE)
  1835. int is_valid;
  1836. int code;
  1837. #endif /* AST_DEVMODE */
  1838. for (i = get_params; i; i = i->next) {
  1839. if (strcmp(i->name, "variable") == 0) {
  1840. args.variable = (i->value);
  1841. } else
  1842. {}
  1843. }
  1844. for (i = path_vars; i; i = i->next) {
  1845. if (strcmp(i->name, "channelId") == 0) {
  1846. args.channel_id = (i->value);
  1847. } else
  1848. {}
  1849. }
  1850. if (ast_ari_channels_get_channel_var_parse_body(body, &args)) {
  1851. ast_ari_response_alloc_failed(response);
  1852. goto fin;
  1853. }
  1854. ast_ari_channels_get_channel_var(headers, &args, response);
  1855. #if defined(AST_DEVMODE)
  1856. code = response->response_code;
  1857. switch (code) {
  1858. case 0: /* Implementation is still a stub, or the code wasn't set */
  1859. is_valid = response->message == NULL;
  1860. break;
  1861. case 500: /* Internal Server Error */
  1862. case 501: /* Not Implemented */
  1863. case 400: /* Missing variable parameter. */
  1864. case 404: /* Channel or variable not found */
  1865. case 409: /* Channel not in a Stasis application */
  1866. is_valid = 1;
  1867. break;
  1868. default:
  1869. if (200 <= code && code <= 299) {
  1870. is_valid = ast_ari_validate_variable(
  1871. response->message);
  1872. } else {
  1873. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
  1874. is_valid = 0;
  1875. }
  1876. }
  1877. if (!is_valid) {
  1878. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
  1879. ast_ari_response_error(response, 500,
  1880. "Internal Server Error", "Response validation failed");
  1881. }
  1882. #endif /* AST_DEVMODE */
  1883. fin: __attribute__((unused))
  1884. return;
  1885. }
  1886. int ast_ari_channels_set_channel_var_parse_body(
  1887. struct ast_json *body,
  1888. struct ast_ari_channels_set_channel_var_args *args)
  1889. {
  1890. struct ast_json *field;
  1891. /* Parse query parameters out of it */
  1892. field = ast_json_object_get(body, "variable");
  1893. if (field) {
  1894. args->variable = ast_json_string_get(field);
  1895. }
  1896. field = ast_json_object_get(body, "value");
  1897. if (field) {
  1898. args->value = ast_json_string_get(field);
  1899. }
  1900. return 0;
  1901. }
  1902. /*!
  1903. * \brief Parameter parsing callback for /channels/{channelId}/variable.
  1904. * \param get_params GET parameters in the HTTP request.
  1905. * \param path_vars Path variables extracted from the request.
  1906. * \param headers HTTP headers.
  1907. * \param[out] response Response to the HTTP request.
  1908. */
  1909. static void ast_ari_channels_set_channel_var_cb(
  1910. struct ast_tcptls_session_instance *ser,
  1911. struct ast_variable *get_params, struct ast_variable *path_vars,
  1912. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1913. {
  1914. struct ast_ari_channels_set_channel_var_args args = {};
  1915. struct ast_variable *i;
  1916. #if defined(AST_DEVMODE)
  1917. int is_valid;
  1918. int code;
  1919. #endif /* AST_DEVMODE */
  1920. for (i = get_params; i; i = i->next) {
  1921. if (strcmp(i->name, "variable") == 0) {
  1922. args.variable = (i->value);
  1923. } else
  1924. if (strcmp(i->name, "value") == 0) {
  1925. args.value = (i->value);
  1926. } else
  1927. {}
  1928. }
  1929. for (i = path_vars; i; i = i->next) {
  1930. if (strcmp(i->name, "channelId") == 0) {
  1931. args.channel_id = (i->value);
  1932. } else
  1933. {}
  1934. }
  1935. if (ast_ari_channels_set_channel_var_parse_body(body, &args)) {
  1936. ast_ari_response_alloc_failed(response);
  1937. goto fin;
  1938. }
  1939. ast_ari_channels_set_channel_var(headers, &args, response);
  1940. #if defined(AST_DEVMODE)
  1941. code = response->response_code;
  1942. switch (code) {
  1943. case 0: /* Implementation is still a stub, or the code wasn't set */
  1944. is_valid = response->message == NULL;
  1945. break;
  1946. case 500: /* Internal Server Error */
  1947. case 501: /* Not Implemented */
  1948. case 400: /* Missing variable parameter. */
  1949. case 404: /* Channel not found */
  1950. case 409: /* Channel not in a Stasis application */
  1951. is_valid = 1;
  1952. break;
  1953. default:
  1954. if (200 <= code && code <= 299) {
  1955. is_valid = ast_ari_validate_void(
  1956. response->message);
  1957. } else {
  1958. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
  1959. is_valid = 0;
  1960. }
  1961. }
  1962. if (!is_valid) {
  1963. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
  1964. ast_ari_response_error(response, 500,
  1965. "Internal Server Error", "Response validation failed");
  1966. }
  1967. #endif /* AST_DEVMODE */
  1968. fin: __attribute__((unused))
  1969. return;
  1970. }
  1971. int ast_ari_channels_snoop_channel_parse_body(
  1972. struct ast_json *body,
  1973. struct ast_ari_channels_snoop_channel_args *args)
  1974. {
  1975. struct ast_json *field;
  1976. /* Parse query parameters out of it */
  1977. field = ast_json_object_get(body, "spy");
  1978. if (field) {
  1979. args->spy = ast_json_string_get(field);
  1980. }
  1981. field = ast_json_object_get(body, "whisper");
  1982. if (field) {
  1983. args->whisper = ast_json_string_get(field);
  1984. }
  1985. field = ast_json_object_get(body, "app");
  1986. if (field) {
  1987. args->app = ast_json_string_get(field);
  1988. }
  1989. field = ast_json_object_get(body, "appArgs");
  1990. if (field) {
  1991. args->app_args = ast_json_string_get(field);
  1992. }
  1993. field = ast_json_object_get(body, "snoopId");
  1994. if (field) {
  1995. args->snoop_id = ast_json_string_get(field);
  1996. }
  1997. return 0;
  1998. }
  1999. /*!
  2000. * \brief Parameter parsing callback for /channels/{channelId}/snoop.
  2001. * \param get_params GET parameters in the HTTP request.
  2002. * \param path_vars Path variables extracted from the request.
  2003. * \param headers HTTP headers.
  2004. * \param[out] response Response to the HTTP request.
  2005. */
  2006. static void ast_ari_channels_snoop_channel_cb(
  2007. struct ast_tcptls_session_instance *ser,
  2008. struct ast_variable *get_params, struct ast_variable *path_vars,
  2009. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  2010. {
  2011. struct ast_ari_channels_snoop_channel_args args = {};
  2012. struct ast_variable *i;
  2013. #if defined(AST_DEVMODE)
  2014. int is_valid;
  2015. int code;
  2016. #endif /* AST_DEVMODE */
  2017. for (i = get_params; i; i = i->next) {
  2018. if (strcmp(i->name, "spy") == 0) {
  2019. args.spy = (i->value);
  2020. } else
  2021. if (strcmp(i->name, "whisper") == 0) {
  2022. args.whisper = (i->value);
  2023. } else
  2024. if (strcmp(i->name, "app") == 0) {
  2025. args.app = (i->value);
  2026. } else
  2027. if (strcmp(i->name, "appArgs") == 0) {
  2028. args.app_args = (i->value);
  2029. } else
  2030. if (strcmp(i->name, "snoopId") == 0) {
  2031. args.snoop_id = (i->value);
  2032. } else
  2033. {}
  2034. }
  2035. for (i = path_vars; i; i = i->next) {
  2036. if (strcmp(i->name, "channelId") == 0) {
  2037. args.channel_id = (i->value);
  2038. } else
  2039. {}
  2040. }
  2041. if (ast_ari_channels_snoop_channel_parse_body(body, &args)) {
  2042. ast_ari_response_alloc_failed(response);
  2043. goto fin;
  2044. }
  2045. ast_ari_channels_snoop_channel(headers, &args, response);
  2046. #if defined(AST_DEVMODE)
  2047. code = response->response_code;
  2048. switch (code) {
  2049. case 0: /* Implementation is still a stub, or the code wasn't set */
  2050. is_valid = response->message == NULL;
  2051. break;
  2052. case 500: /* Internal Server Error */
  2053. case 501: /* Not Implemented */
  2054. case 400: /* Invalid parameters */
  2055. case 404: /* Channel not found */
  2056. is_valid = 1;
  2057. break;
  2058. default:
  2059. if (200 <= code && code <= 299) {
  2060. is_valid = ast_ari_validate_channel(
  2061. response->message);
  2062. } else {
  2063. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/snoop\n", code);
  2064. is_valid = 0;
  2065. }
  2066. }
  2067. if (!is_valid) {
  2068. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/snoop\n");
  2069. ast_ari_response_error(response, 500,
  2070. "Internal Server Error", "Response validation failed");
  2071. }
  2072. #endif /* AST_DEVMODE */
  2073. fin: __attribute__((unused))
  2074. return;
  2075. }
  2076. int ast_ari_channels_snoop_channel_with_id_parse_body(
  2077. struct ast_json *body,
  2078. struct ast_ari_channels_snoop_channel_with_id_args *args)
  2079. {
  2080. struct ast_json *field;
  2081. /* Parse query parameters out of it */
  2082. field = ast_json_object_get(body, "spy");
  2083. if (field) {
  2084. args->spy = ast_json_string_get(field);
  2085. }
  2086. field = ast_json_object_get(body, "whisper");
  2087. if (field) {
  2088. args->whisper = ast_json_string_get(field);
  2089. }
  2090. field = ast_json_object_get(body, "app");
  2091. if (field) {
  2092. args->app = ast_json_string_get(field);
  2093. }
  2094. field = ast_json_object_get(body, "appArgs");
  2095. if (field) {
  2096. args->app_args = ast_json_string_get(field);
  2097. }
  2098. return 0;
  2099. }
  2100. /*!
  2101. * \brief Parameter parsing callback for /channels/{channelId}/snoop/{snoopId}.
  2102. * \param get_params GET parameters in the HTTP request.
  2103. * \param path_vars Path variables extracted from the request.
  2104. * \param headers HTTP headers.
  2105. * \param[out] response Response to the HTTP request.
  2106. */
  2107. static void ast_ari_channels_snoop_channel_with_id_cb(
  2108. struct ast_tcptls_session_instance *ser,
  2109. struct ast_variable *get_params, struct ast_variable *path_vars,
  2110. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  2111. {
  2112. struct ast_ari_channels_snoop_channel_with_id_args args = {};
  2113. struct ast_variable *i;
  2114. #if defined(AST_DEVMODE)
  2115. int is_valid;
  2116. int code;
  2117. #endif /* AST_DEVMODE */
  2118. for (i = get_params; i; i = i->next) {
  2119. if (strcmp(i->name, "spy") == 0) {
  2120. args.spy = (i->value);
  2121. } else
  2122. if (strcmp(i->name, "whisper") == 0) {
  2123. args.whisper = (i->value);
  2124. } else
  2125. if (strcmp(i->name, "app") == 0) {
  2126. args.app = (i->value);
  2127. } else
  2128. if (strcmp(i->name, "appArgs") == 0) {
  2129. args.app_args = (i->value);
  2130. } else
  2131. {}
  2132. }
  2133. for (i = path_vars; i; i = i->next) {
  2134. if (strcmp(i->name, "channelId") == 0) {
  2135. args.channel_id = (i->value);
  2136. } else
  2137. if (strcmp(i->name, "snoopId") == 0) {
  2138. args.snoop_id = (i->value);
  2139. } else
  2140. {}
  2141. }
  2142. if (ast_ari_channels_snoop_channel_with_id_parse_body(body, &args)) {
  2143. ast_ari_response_alloc_failed(response);
  2144. goto fin;
  2145. }
  2146. ast_ari_channels_snoop_channel_with_id(headers, &args, response);
  2147. #if defined(AST_DEVMODE)
  2148. code = response->response_code;
  2149. switch (code) {
  2150. case 0: /* Implementation is still a stub, or the code wasn't set */
  2151. is_valid = response->message == NULL;
  2152. break;
  2153. case 500: /* Internal Server Error */
  2154. case 501: /* Not Implemented */
  2155. case 400: /* Invalid parameters */
  2156. case 404: /* Channel not found */
  2157. is_valid = 1;
  2158. break;
  2159. default:
  2160. if (200 <= code && code <= 299) {
  2161. is_valid = ast_ari_validate_channel(
  2162. response->message);
  2163. } else {
  2164. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/snoop/{snoopId}\n", code);
  2165. is_valid = 0;
  2166. }
  2167. }
  2168. if (!is_valid) {
  2169. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/snoop/{snoopId}\n");
  2170. ast_ari_response_error(response, 500,
  2171. "Internal Server Error", "Response validation failed");
  2172. }
  2173. #endif /* AST_DEVMODE */
  2174. fin: __attribute__((unused))
  2175. return;
  2176. }
  2177. /*! \brief REST handler for /api-docs/channels.json */
  2178. static struct stasis_rest_handlers channels_channelId_continue = {
  2179. .path_segment = "continue",
  2180. .callbacks = {
  2181. [AST_HTTP_POST] = ast_ari_channels_continue_in_dialplan_cb,
  2182. },
  2183. .num_children = 0,
  2184. .children = { }
  2185. };
  2186. /*! \brief REST handler for /api-docs/channels.json */
  2187. static struct stasis_rest_handlers channels_channelId_redirect = {
  2188. .path_segment = "redirect",
  2189. .callbacks = {
  2190. [AST_HTTP_POST] = ast_ari_channels_redirect_cb,
  2191. },
  2192. .num_children = 0,
  2193. .children = { }
  2194. };
  2195. /*! \brief REST handler for /api-docs/channels.json */
  2196. static struct stasis_rest_handlers channels_channelId_answer = {
  2197. .path_segment = "answer",
  2198. .callbacks = {
  2199. [AST_HTTP_POST] = ast_ari_channels_answer_cb,
  2200. },
  2201. .num_children = 0,
  2202. .children = { }
  2203. };
  2204. /*! \brief REST handler for /api-docs/channels.json */
  2205. static struct stasis_rest_handlers channels_channelId_ring = {
  2206. .path_segment = "ring",
  2207. .callbacks = {
  2208. [AST_HTTP_POST] = ast_ari_channels_ring_cb,
  2209. [AST_HTTP_DELETE] = ast_ari_channels_ring_stop_cb,
  2210. },
  2211. .num_children = 0,
  2212. .children = { }
  2213. };
  2214. /*! \brief REST handler for /api-docs/channels.json */
  2215. static struct stasis_rest_handlers channels_channelId_dtmf = {
  2216. .path_segment = "dtmf",
  2217. .callbacks = {
  2218. [AST_HTTP_POST] = ast_ari_channels_send_dtmf_cb,
  2219. },
  2220. .num_children = 0,
  2221. .children = { }
  2222. };
  2223. /*! \brief REST handler for /api-docs/channels.json */
  2224. static struct stasis_rest_handlers channels_channelId_mute = {
  2225. .path_segment = "mute",
  2226. .callbacks = {
  2227. [AST_HTTP_POST] = ast_ari_channels_mute_cb,
  2228. [AST_HTTP_DELETE] = ast_ari_channels_unmute_cb,
  2229. },
  2230. .num_children = 0,
  2231. .children = { }
  2232. };
  2233. /*! \brief REST handler for /api-docs/channels.json */
  2234. static struct stasis_rest_handlers channels_channelId_hold = {
  2235. .path_segment = "hold",
  2236. .callbacks = {
  2237. [AST_HTTP_POST] = ast_ari_channels_hold_cb,
  2238. [AST_HTTP_DELETE] = ast_ari_channels_unhold_cb,
  2239. },
  2240. .num_children = 0,
  2241. .children = { }
  2242. };
  2243. /*! \brief REST handler for /api-docs/channels.json */
  2244. static struct stasis_rest_handlers channels_channelId_moh = {
  2245. .path_segment = "moh",
  2246. .callbacks = {
  2247. [AST_HTTP_POST] = ast_ari_channels_start_moh_cb,
  2248. [AST_HTTP_DELETE] = ast_ari_channels_stop_moh_cb,
  2249. },
  2250. .num_children = 0,
  2251. .children = { }
  2252. };
  2253. /*! \brief REST handler for /api-docs/channels.json */
  2254. static struct stasis_rest_handlers channels_channelId_silence = {
  2255. .path_segment = "silence",
  2256. .callbacks = {
  2257. [AST_HTTP_POST] = ast_ari_channels_start_silence_cb,
  2258. [AST_HTTP_DELETE] = ast_ari_channels_stop_silence_cb,
  2259. },
  2260. .num_children = 0,
  2261. .children = { }
  2262. };
  2263. /*! \brief REST handler for /api-docs/channels.json */
  2264. static struct stasis_rest_handlers channels_channelId_play_playbackId = {
  2265. .path_segment = "playbackId",
  2266. .is_wildcard = 1,
  2267. .callbacks = {
  2268. [AST_HTTP_POST] = ast_ari_channels_play_with_id_cb,
  2269. },
  2270. .num_children = 0,
  2271. .children = { }
  2272. };
  2273. /*! \brief REST handler for /api-docs/channels.json */
  2274. static struct stasis_rest_handlers channels_channelId_play = {
  2275. .path_segment = "play",
  2276. .callbacks = {
  2277. [AST_HTTP_POST] = ast_ari_channels_play_cb,
  2278. },
  2279. .num_children = 1,
  2280. .children = { &channels_channelId_play_playbackId, }
  2281. };
  2282. /*! \brief REST handler for /api-docs/channels.json */
  2283. static struct stasis_rest_handlers channels_channelId_record = {
  2284. .path_segment = "record",
  2285. .callbacks = {
  2286. [AST_HTTP_POST] = ast_ari_channels_record_cb,
  2287. },
  2288. .num_children = 0,
  2289. .children = { }
  2290. };
  2291. /*! \brief REST handler for /api-docs/channels.json */
  2292. static struct stasis_rest_handlers channels_channelId_variable = {
  2293. .path_segment = "variable",
  2294. .callbacks = {
  2295. [AST_HTTP_GET] = ast_ari_channels_get_channel_var_cb,
  2296. [AST_HTTP_POST] = ast_ari_channels_set_channel_var_cb,
  2297. },
  2298. .num_children = 0,
  2299. .children = { }
  2300. };
  2301. /*! \brief REST handler for /api-docs/channels.json */
  2302. static struct stasis_rest_handlers channels_channelId_snoop_snoopId = {
  2303. .path_segment = "snoopId",
  2304. .is_wildcard = 1,
  2305. .callbacks = {
  2306. [AST_HTTP_POST] = ast_ari_channels_snoop_channel_with_id_cb,
  2307. },
  2308. .num_children = 0,
  2309. .children = { }
  2310. };
  2311. /*! \brief REST handler for /api-docs/channels.json */
  2312. static struct stasis_rest_handlers channels_channelId_snoop = {
  2313. .path_segment = "snoop",
  2314. .callbacks = {
  2315. [AST_HTTP_POST] = ast_ari_channels_snoop_channel_cb,
  2316. },
  2317. .num_children = 1,
  2318. .children = { &channels_channelId_snoop_snoopId, }
  2319. };
  2320. /*! \brief REST handler for /api-docs/channels.json */
  2321. static struct stasis_rest_handlers channels_channelId = {
  2322. .path_segment = "channelId",
  2323. .is_wildcard = 1,
  2324. .callbacks = {
  2325. [AST_HTTP_GET] = ast_ari_channels_get_cb,
  2326. [AST_HTTP_POST] = ast_ari_channels_originate_with_id_cb,
  2327. [AST_HTTP_DELETE] = ast_ari_channels_hangup_cb,
  2328. },
  2329. .num_children = 13,
  2330. .children = { &channels_channelId_continue,&channels_channelId_redirect,&channels_channelId_answer,&channels_channelId_ring,&channels_channelId_dtmf,&channels_channelId_mute,&channels_channelId_hold,&channels_channelId_moh,&channels_channelId_silence,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable,&channels_channelId_snoop, }
  2331. };
  2332. /*! \brief REST handler for /api-docs/channels.json */
  2333. static struct stasis_rest_handlers channels = {
  2334. .path_segment = "channels",
  2335. .callbacks = {
  2336. [AST_HTTP_GET] = ast_ari_channels_list_cb,
  2337. [AST_HTTP_POST] = ast_ari_channels_originate_cb,
  2338. },
  2339. .num_children = 1,
  2340. .children = { &channels_channelId, }
  2341. };
  2342. static int unload_module(void)
  2343. {
  2344. ast_ari_remove_handler(&channels);
  2345. stasis_app_unref();
  2346. return 0;
  2347. }
  2348. static int load_module(void)
  2349. {
  2350. int res = 0;
  2351. CHECK_ARI_MODULE_LOADED();
  2352. stasis_app_ref();
  2353. res |= ast_ari_add_handler(&channels);
  2354. if (res) {
  2355. unload_module();
  2356. return AST_MODULE_LOAD_DECLINE;
  2357. }
  2358. return AST_MODULE_LOAD_SUCCESS;
  2359. }
  2360. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Channel resources",
  2361. .support_level = AST_MODULE_SUPPORT_CORE,
  2362. .load = load_module,
  2363. .unload = unload_module,
  2364. );