res_ari_channels.c 74 KB

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