res_ari_channels.c 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2012 - 2013, Digium, Inc.
  5. *
  6. * David M. Lee, II <dlee@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*
  19. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  20. * !!!!! DO NOT EDIT !!!!!
  21. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  22. * This file is generated by a mustache template. Please see the original
  23. * template in rest-api-templates/res_ari_resource.c.mustache
  24. */
  25. /*! \file
  26. *
  27. * \brief Channel resources
  28. *
  29. * \author David M. Lee, II <dlee@digium.com>
  30. */
  31. /*** MODULEINFO
  32. <depend type="module">res_ari</depend>
  33. <depend type="module">res_ari_model</depend>
  34. <depend type="module">res_stasis</depend>
  35. <depend type="module">res_stasis_answer</depend>
  36. <depend type="module">res_stasis_playback</depend>
  37. <depend type="module">res_stasis_recording</depend>
  38. <depend type="module">res_stasis_snoop</depend>
  39. <support_level>core</support_level>
  40. ***/
  41. #include "asterisk.h"
  42. #include "asterisk/app.h"
  43. #include "asterisk/module.h"
  44. #include "asterisk/stasis_app.h"
  45. #include "ari/resource_channels.h"
  46. #if defined(AST_DEVMODE)
  47. #include "ari/ari_model_validators.h"
  48. #endif
  49. #define MAX_VALS 128
  50. /*!
  51. * \brief Parameter parsing callback for /channels.
  52. * \param ser TCP/TLS session object
  53. * \param get_params GET parameters in the HTTP request.
  54. * \param path_vars Path variables extracted from the request.
  55. * \param headers HTTP headers.
  56. * \param body
  57. * \param[out] response Response to the HTTP request.
  58. */
  59. static void ast_ari_channels_list_cb(
  60. struct ast_tcptls_session_instance *ser,
  61. struct ast_variable *get_params, struct ast_variable *path_vars,
  62. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  63. {
  64. struct ast_ari_channels_list_args args = {};
  65. #if defined(AST_DEVMODE)
  66. int is_valid;
  67. int code;
  68. #endif /* AST_DEVMODE */
  69. ast_ari_channels_list(headers, &args, response);
  70. #if defined(AST_DEVMODE)
  71. code = response->response_code;
  72. switch (code) {
  73. case 0: /* Implementation is still a stub, or the code wasn't set */
  74. is_valid = response->message == NULL;
  75. break;
  76. case 500: /* Internal Server Error */
  77. case 501: /* Not Implemented */
  78. is_valid = 1;
  79. break;
  80. default:
  81. if (200 <= code && code <= 299) {
  82. is_valid = ast_ari_validate_list(response->message,
  83. ast_ari_validate_channel_fn());
  84. } else {
  85. ast_log(LOG_ERROR, "Invalid error response %d for /channels\n", code);
  86. is_valid = 0;
  87. }
  88. }
  89. if (!is_valid) {
  90. ast_log(LOG_ERROR, "Response validation failed for /channels\n");
  91. ast_ari_response_error(response, 500,
  92. "Internal Server Error", "Response validation failed");
  93. }
  94. #endif /* AST_DEVMODE */
  95. fin: __attribute__((unused))
  96. return;
  97. }
  98. int ast_ari_channels_originate_parse_body(
  99. struct ast_json *body,
  100. struct ast_ari_channels_originate_args *args)
  101. {
  102. struct ast_json *field;
  103. /* Parse query parameters out of it */
  104. field = ast_json_object_get(body, "endpoint");
  105. if (field) {
  106. args->endpoint = ast_json_string_get(field);
  107. }
  108. field = ast_json_object_get(body, "extension");
  109. if (field) {
  110. args->extension = ast_json_string_get(field);
  111. }
  112. field = ast_json_object_get(body, "context");
  113. if (field) {
  114. args->context = ast_json_string_get(field);
  115. }
  116. field = ast_json_object_get(body, "priority");
  117. if (field) {
  118. args->priority = ast_json_integer_get(field);
  119. }
  120. field = ast_json_object_get(body, "label");
  121. if (field) {
  122. args->label = ast_json_string_get(field);
  123. }
  124. field = ast_json_object_get(body, "app");
  125. if (field) {
  126. args->app = ast_json_string_get(field);
  127. }
  128. field = ast_json_object_get(body, "appArgs");
  129. if (field) {
  130. args->app_args = ast_json_string_get(field);
  131. }
  132. field = ast_json_object_get(body, "callerId");
  133. if (field) {
  134. args->caller_id = ast_json_string_get(field);
  135. }
  136. field = ast_json_object_get(body, "timeout");
  137. if (field) {
  138. args->timeout = ast_json_integer_get(field);
  139. }
  140. field = ast_json_object_get(body, "channelId");
  141. if (field) {
  142. args->channel_id = ast_json_string_get(field);
  143. }
  144. field = ast_json_object_get(body, "otherChannelId");
  145. if (field) {
  146. args->other_channel_id = ast_json_string_get(field);
  147. }
  148. field = ast_json_object_get(body, "originator");
  149. if (field) {
  150. args->originator = ast_json_string_get(field);
  151. }
  152. field = ast_json_object_get(body, "formats");
  153. if (field) {
  154. args->formats = ast_json_string_get(field);
  155. }
  156. return 0;
  157. }
  158. /*!
  159. * \brief Parameter parsing callback for /channels.
  160. * \param ser TCP/TLS session object
  161. * \param get_params GET parameters in the HTTP request.
  162. * \param path_vars Path variables extracted from the request.
  163. * \param headers HTTP headers.
  164. * \param body
  165. * \param[out] response Response to the HTTP request.
  166. */
  167. static void ast_ari_channels_originate_cb(
  168. struct ast_tcptls_session_instance *ser,
  169. struct ast_variable *get_params, struct ast_variable *path_vars,
  170. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  171. {
  172. struct ast_ari_channels_originate_args args = {};
  173. struct ast_variable *i;
  174. #if defined(AST_DEVMODE)
  175. int is_valid;
  176. int code;
  177. #endif /* AST_DEVMODE */
  178. for (i = get_params; i; i = i->next) {
  179. if (strcmp(i->name, "endpoint") == 0) {
  180. args.endpoint = (i->value);
  181. } else
  182. if (strcmp(i->name, "extension") == 0) {
  183. args.extension = (i->value);
  184. } else
  185. if (strcmp(i->name, "context") == 0) {
  186. args.context = (i->value);
  187. } else
  188. if (strcmp(i->name, "priority") == 0) {
  189. args.priority = atol(i->value);
  190. } else
  191. if (strcmp(i->name, "label") == 0) {
  192. args.label = (i->value);
  193. } else
  194. if (strcmp(i->name, "app") == 0) {
  195. args.app = (i->value);
  196. } else
  197. if (strcmp(i->name, "appArgs") == 0) {
  198. args.app_args = (i->value);
  199. } else
  200. if (strcmp(i->name, "callerId") == 0) {
  201. args.caller_id = (i->value);
  202. } else
  203. if (strcmp(i->name, "timeout") == 0) {
  204. args.timeout = atoi(i->value);
  205. } else
  206. if (strcmp(i->name, "channelId") == 0) {
  207. args.channel_id = (i->value);
  208. } else
  209. if (strcmp(i->name, "otherChannelId") == 0) {
  210. args.other_channel_id = (i->value);
  211. } else
  212. if (strcmp(i->name, "originator") == 0) {
  213. args.originator = (i->value);
  214. } else
  215. if (strcmp(i->name, "formats") == 0) {
  216. args.formats = (i->value);
  217. } else
  218. {}
  219. }
  220. args.variables = body;
  221. ast_ari_channels_originate(headers, &args, response);
  222. #if defined(AST_DEVMODE)
  223. code = response->response_code;
  224. switch (code) {
  225. case 0: /* Implementation is still a stub, or the code wasn't set */
  226. is_valid = response->message == NULL;
  227. break;
  228. case 500: /* Internal Server Error */
  229. case 501: /* Not Implemented */
  230. case 400: /* Invalid parameters for originating a channel. */
  231. case 409: /* Channel with given unique ID already exists. */
  232. is_valid = 1;
  233. break;
  234. default:
  235. if (200 <= code && code <= 299) {
  236. is_valid = ast_ari_validate_channel(
  237. response->message);
  238. } else {
  239. ast_log(LOG_ERROR, "Invalid error response %d for /channels\n", code);
  240. is_valid = 0;
  241. }
  242. }
  243. if (!is_valid) {
  244. ast_log(LOG_ERROR, "Response validation failed for /channels\n");
  245. ast_ari_response_error(response, 500,
  246. "Internal Server Error", "Response validation failed");
  247. }
  248. #endif /* AST_DEVMODE */
  249. fin: __attribute__((unused))
  250. return;
  251. }
  252. int ast_ari_channels_create_parse_body(
  253. struct ast_json *body,
  254. struct ast_ari_channels_create_args *args)
  255. {
  256. struct ast_json *field;
  257. /* Parse query parameters out of it */
  258. field = ast_json_object_get(body, "endpoint");
  259. if (field) {
  260. args->endpoint = ast_json_string_get(field);
  261. }
  262. field = ast_json_object_get(body, "app");
  263. if (field) {
  264. args->app = ast_json_string_get(field);
  265. }
  266. field = ast_json_object_get(body, "appArgs");
  267. if (field) {
  268. args->app_args = ast_json_string_get(field);
  269. }
  270. field = ast_json_object_get(body, "channelId");
  271. if (field) {
  272. args->channel_id = ast_json_string_get(field);
  273. }
  274. field = ast_json_object_get(body, "otherChannelId");
  275. if (field) {
  276. args->other_channel_id = ast_json_string_get(field);
  277. }
  278. field = ast_json_object_get(body, "originator");
  279. if (field) {
  280. args->originator = ast_json_string_get(field);
  281. }
  282. field = ast_json_object_get(body, "formats");
  283. if (field) {
  284. args->formats = ast_json_string_get(field);
  285. }
  286. return 0;
  287. }
  288. /*!
  289. * \brief Parameter parsing callback for /channels/create.
  290. * \param ser TCP/TLS session object
  291. * \param get_params GET parameters in the HTTP request.
  292. * \param path_vars Path variables extracted from the request.
  293. * \param headers HTTP headers.
  294. * \param body
  295. * \param[out] response Response to the HTTP request.
  296. */
  297. static void ast_ari_channels_create_cb(
  298. struct ast_tcptls_session_instance *ser,
  299. struct ast_variable *get_params, struct ast_variable *path_vars,
  300. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  301. {
  302. struct ast_ari_channels_create_args args = {};
  303. struct ast_variable *i;
  304. #if defined(AST_DEVMODE)
  305. int is_valid;
  306. int code;
  307. #endif /* AST_DEVMODE */
  308. for (i = get_params; i; i = i->next) {
  309. if (strcmp(i->name, "endpoint") == 0) {
  310. args.endpoint = (i->value);
  311. } else
  312. if (strcmp(i->name, "app") == 0) {
  313. args.app = (i->value);
  314. } else
  315. if (strcmp(i->name, "appArgs") == 0) {
  316. args.app_args = (i->value);
  317. } else
  318. if (strcmp(i->name, "channelId") == 0) {
  319. args.channel_id = (i->value);
  320. } else
  321. if (strcmp(i->name, "otherChannelId") == 0) {
  322. args.other_channel_id = (i->value);
  323. } else
  324. if (strcmp(i->name, "originator") == 0) {
  325. args.originator = (i->value);
  326. } else
  327. if (strcmp(i->name, "formats") == 0) {
  328. args.formats = (i->value);
  329. } else
  330. {}
  331. }
  332. args.variables = body;
  333. ast_ari_channels_create(headers, &args, response);
  334. #if defined(AST_DEVMODE)
  335. code = response->response_code;
  336. switch (code) {
  337. case 0: /* Implementation is still a stub, or the code wasn't set */
  338. is_valid = response->message == NULL;
  339. break;
  340. case 500: /* Internal Server Error */
  341. case 501: /* Not Implemented */
  342. case 409: /* Channel with given unique ID already exists. */
  343. is_valid = 1;
  344. break;
  345. default:
  346. if (200 <= code && code <= 299) {
  347. is_valid = ast_ari_validate_channel(
  348. response->message);
  349. } else {
  350. ast_log(LOG_ERROR, "Invalid error response %d for /channels/create\n", code);
  351. is_valid = 0;
  352. }
  353. }
  354. if (!is_valid) {
  355. ast_log(LOG_ERROR, "Response validation failed for /channels/create\n");
  356. ast_ari_response_error(response, 500,
  357. "Internal Server Error", "Response validation failed");
  358. }
  359. #endif /* AST_DEVMODE */
  360. fin: __attribute__((unused))
  361. return;
  362. }
  363. /*!
  364. * \brief Parameter parsing callback for /channels/{channelId}.
  365. * \param ser TCP/TLS session object
  366. * \param get_params GET parameters in the HTTP request.
  367. * \param path_vars Path variables extracted from the request.
  368. * \param headers HTTP headers.
  369. * \param body
  370. * \param[out] response Response to the HTTP request.
  371. */
  372. static void ast_ari_channels_get_cb(
  373. struct ast_tcptls_session_instance *ser,
  374. struct ast_variable *get_params, struct ast_variable *path_vars,
  375. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  376. {
  377. struct ast_ari_channels_get_args args = {};
  378. struct ast_variable *i;
  379. #if defined(AST_DEVMODE)
  380. int is_valid;
  381. int code;
  382. #endif /* AST_DEVMODE */
  383. for (i = path_vars; i; i = i->next) {
  384. if (strcmp(i->name, "channelId") == 0) {
  385. args.channel_id = (i->value);
  386. } else
  387. {}
  388. }
  389. ast_ari_channels_get(headers, &args, response);
  390. #if defined(AST_DEVMODE)
  391. code = response->response_code;
  392. switch (code) {
  393. case 0: /* Implementation is still a stub, or the code wasn't set */
  394. is_valid = response->message == NULL;
  395. break;
  396. case 500: /* Internal Server Error */
  397. case 501: /* Not Implemented */
  398. case 404: /* Channel not found */
  399. is_valid = 1;
  400. break;
  401. default:
  402. if (200 <= code && code <= 299) {
  403. is_valid = ast_ari_validate_channel(
  404. response->message);
  405. } else {
  406. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
  407. is_valid = 0;
  408. }
  409. }
  410. if (!is_valid) {
  411. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
  412. ast_ari_response_error(response, 500,
  413. "Internal Server Error", "Response validation failed");
  414. }
  415. #endif /* AST_DEVMODE */
  416. fin: __attribute__((unused))
  417. return;
  418. }
  419. int ast_ari_channels_originate_with_id_parse_body(
  420. struct ast_json *body,
  421. struct ast_ari_channels_originate_with_id_args *args)
  422. {
  423. struct ast_json *field;
  424. /* Parse query parameters out of it */
  425. field = ast_json_object_get(body, "endpoint");
  426. if (field) {
  427. args->endpoint = ast_json_string_get(field);
  428. }
  429. field = ast_json_object_get(body, "extension");
  430. if (field) {
  431. args->extension = ast_json_string_get(field);
  432. }
  433. field = ast_json_object_get(body, "context");
  434. if (field) {
  435. args->context = ast_json_string_get(field);
  436. }
  437. field = ast_json_object_get(body, "priority");
  438. if (field) {
  439. args->priority = ast_json_integer_get(field);
  440. }
  441. field = ast_json_object_get(body, "label");
  442. if (field) {
  443. args->label = ast_json_string_get(field);
  444. }
  445. field = ast_json_object_get(body, "app");
  446. if (field) {
  447. args->app = ast_json_string_get(field);
  448. }
  449. field = ast_json_object_get(body, "appArgs");
  450. if (field) {
  451. args->app_args = ast_json_string_get(field);
  452. }
  453. field = ast_json_object_get(body, "callerId");
  454. if (field) {
  455. args->caller_id = ast_json_string_get(field);
  456. }
  457. field = ast_json_object_get(body, "timeout");
  458. if (field) {
  459. args->timeout = ast_json_integer_get(field);
  460. }
  461. field = ast_json_object_get(body, "otherChannelId");
  462. if (field) {
  463. args->other_channel_id = ast_json_string_get(field);
  464. }
  465. field = ast_json_object_get(body, "originator");
  466. if (field) {
  467. args->originator = ast_json_string_get(field);
  468. }
  469. field = ast_json_object_get(body, "formats");
  470. if (field) {
  471. args->formats = ast_json_string_get(field);
  472. }
  473. return 0;
  474. }
  475. /*!
  476. * \brief Parameter parsing callback for /channels/{channelId}.
  477. * \param ser TCP/TLS session object
  478. * \param get_params GET parameters in the HTTP request.
  479. * \param path_vars Path variables extracted from the request.
  480. * \param headers HTTP headers.
  481. * \param body
  482. * \param[out] response Response to the HTTP request.
  483. */
  484. static void ast_ari_channels_originate_with_id_cb(
  485. struct ast_tcptls_session_instance *ser,
  486. struct ast_variable *get_params, struct ast_variable *path_vars,
  487. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  488. {
  489. struct ast_ari_channels_originate_with_id_args args = {};
  490. struct ast_variable *i;
  491. #if defined(AST_DEVMODE)
  492. int is_valid;
  493. int code;
  494. #endif /* AST_DEVMODE */
  495. for (i = get_params; i; i = i->next) {
  496. if (strcmp(i->name, "endpoint") == 0) {
  497. args.endpoint = (i->value);
  498. } else
  499. if (strcmp(i->name, "extension") == 0) {
  500. args.extension = (i->value);
  501. } else
  502. if (strcmp(i->name, "context") == 0) {
  503. args.context = (i->value);
  504. } else
  505. if (strcmp(i->name, "priority") == 0) {
  506. args.priority = atol(i->value);
  507. } else
  508. if (strcmp(i->name, "label") == 0) {
  509. args.label = (i->value);
  510. } else
  511. if (strcmp(i->name, "app") == 0) {
  512. args.app = (i->value);
  513. } else
  514. if (strcmp(i->name, "appArgs") == 0) {
  515. args.app_args = (i->value);
  516. } else
  517. if (strcmp(i->name, "callerId") == 0) {
  518. args.caller_id = (i->value);
  519. } else
  520. if (strcmp(i->name, "timeout") == 0) {
  521. args.timeout = atoi(i->value);
  522. } else
  523. if (strcmp(i->name, "otherChannelId") == 0) {
  524. args.other_channel_id = (i->value);
  525. } else
  526. if (strcmp(i->name, "originator") == 0) {
  527. args.originator = (i->value);
  528. } else
  529. if (strcmp(i->name, "formats") == 0) {
  530. args.formats = (i->value);
  531. } else
  532. {}
  533. }
  534. for (i = path_vars; i; i = i->next) {
  535. if (strcmp(i->name, "channelId") == 0) {
  536. args.channel_id = (i->value);
  537. } else
  538. {}
  539. }
  540. args.variables = body;
  541. ast_ari_channels_originate_with_id(headers, &args, response);
  542. #if defined(AST_DEVMODE)
  543. code = response->response_code;
  544. switch (code) {
  545. case 0: /* Implementation is still a stub, or the code wasn't set */
  546. is_valid = response->message == NULL;
  547. break;
  548. case 500: /* Internal Server Error */
  549. case 501: /* Not Implemented */
  550. case 400: /* Invalid parameters for originating a channel. */
  551. case 409: /* Channel with given unique ID already exists. */
  552. is_valid = 1;
  553. break;
  554. default:
  555. if (200 <= code && code <= 299) {
  556. is_valid = ast_ari_validate_channel(
  557. response->message);
  558. } else {
  559. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
  560. is_valid = 0;
  561. }
  562. }
  563. if (!is_valid) {
  564. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
  565. ast_ari_response_error(response, 500,
  566. "Internal Server Error", "Response validation failed");
  567. }
  568. #endif /* AST_DEVMODE */
  569. fin: __attribute__((unused))
  570. return;
  571. }
  572. int ast_ari_channels_hangup_parse_body(
  573. struct ast_json *body,
  574. struct ast_ari_channels_hangup_args *args)
  575. {
  576. struct ast_json *field;
  577. /* Parse query parameters out of it */
  578. field = ast_json_object_get(body, "reason_code");
  579. if (field) {
  580. args->reason_code = ast_json_string_get(field);
  581. }
  582. field = ast_json_object_get(body, "reason");
  583. if (field) {
  584. args->reason = ast_json_string_get(field);
  585. }
  586. return 0;
  587. }
  588. /*!
  589. * \brief Parameter parsing callback for /channels/{channelId}.
  590. * \param ser TCP/TLS session object
  591. * \param get_params GET parameters in the HTTP request.
  592. * \param path_vars Path variables extracted from the request.
  593. * \param headers HTTP headers.
  594. * \param body
  595. * \param[out] response Response to the HTTP request.
  596. */
  597. static void ast_ari_channels_hangup_cb(
  598. struct ast_tcptls_session_instance *ser,
  599. struct ast_variable *get_params, struct ast_variable *path_vars,
  600. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  601. {
  602. struct ast_ari_channels_hangup_args args = {};
  603. struct ast_variable *i;
  604. #if defined(AST_DEVMODE)
  605. int is_valid;
  606. int code;
  607. #endif /* AST_DEVMODE */
  608. for (i = get_params; i; i = i->next) {
  609. if (strcmp(i->name, "reason_code") == 0) {
  610. args.reason_code = (i->value);
  611. } else
  612. if (strcmp(i->name, "reason") == 0) {
  613. args.reason = (i->value);
  614. } else
  615. {}
  616. }
  617. for (i = path_vars; i; i = i->next) {
  618. if (strcmp(i->name, "channelId") == 0) {
  619. args.channel_id = (i->value);
  620. } else
  621. {}
  622. }
  623. if (ast_ari_channels_hangup_parse_body(body, &args)) {
  624. ast_ari_response_alloc_failed(response);
  625. goto fin;
  626. }
  627. ast_ari_channels_hangup(headers, &args, response);
  628. #if defined(AST_DEVMODE)
  629. code = response->response_code;
  630. switch (code) {
  631. case 0: /* Implementation is still a stub, or the code wasn't set */
  632. is_valid = response->message == NULL;
  633. break;
  634. case 500: /* Internal Server Error */
  635. case 501: /* Not Implemented */
  636. case 400: /* Invalid reason for hangup provided */
  637. case 404: /* Channel not found */
  638. is_valid = 1;
  639. break;
  640. default:
  641. if (200 <= code && code <= 299) {
  642. is_valid = ast_ari_validate_void(
  643. response->message);
  644. } else {
  645. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
  646. is_valid = 0;
  647. }
  648. }
  649. if (!is_valid) {
  650. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
  651. ast_ari_response_error(response, 500,
  652. "Internal Server Error", "Response validation failed");
  653. }
  654. #endif /* AST_DEVMODE */
  655. fin: __attribute__((unused))
  656. return;
  657. }
  658. int ast_ari_channels_continue_in_dialplan_parse_body(
  659. struct ast_json *body,
  660. struct ast_ari_channels_continue_in_dialplan_args *args)
  661. {
  662. struct ast_json *field;
  663. /* Parse query parameters out of it */
  664. field = ast_json_object_get(body, "context");
  665. if (field) {
  666. args->context = ast_json_string_get(field);
  667. }
  668. field = ast_json_object_get(body, "extension");
  669. if (field) {
  670. args->extension = ast_json_string_get(field);
  671. }
  672. field = ast_json_object_get(body, "priority");
  673. if (field) {
  674. args->priority = ast_json_integer_get(field);
  675. }
  676. field = ast_json_object_get(body, "label");
  677. if (field) {
  678. args->label = ast_json_string_get(field);
  679. }
  680. return 0;
  681. }
  682. /*!
  683. * \brief Parameter parsing callback for /channels/{channelId}/continue.
  684. * \param ser TCP/TLS session object
  685. * \param get_params GET parameters in the HTTP request.
  686. * \param path_vars Path variables extracted from the request.
  687. * \param headers HTTP headers.
  688. * \param body
  689. * \param[out] response Response to the HTTP request.
  690. */
  691. static void ast_ari_channels_continue_in_dialplan_cb(
  692. struct ast_tcptls_session_instance *ser,
  693. struct ast_variable *get_params, struct ast_variable *path_vars,
  694. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  695. {
  696. struct ast_ari_channels_continue_in_dialplan_args args = {};
  697. struct ast_variable *i;
  698. #if defined(AST_DEVMODE)
  699. int is_valid;
  700. int code;
  701. #endif /* AST_DEVMODE */
  702. for (i = get_params; i; i = i->next) {
  703. if (strcmp(i->name, "context") == 0) {
  704. args.context = (i->value);
  705. } else
  706. if (strcmp(i->name, "extension") == 0) {
  707. args.extension = (i->value);
  708. } else
  709. if (strcmp(i->name, "priority") == 0) {
  710. args.priority = atoi(i->value);
  711. } else
  712. if (strcmp(i->name, "label") == 0) {
  713. args.label = (i->value);
  714. } else
  715. {}
  716. }
  717. for (i = path_vars; i; i = i->next) {
  718. if (strcmp(i->name, "channelId") == 0) {
  719. args.channel_id = (i->value);
  720. } else
  721. {}
  722. }
  723. if (ast_ari_channels_continue_in_dialplan_parse_body(body, &args)) {
  724. ast_ari_response_alloc_failed(response);
  725. goto fin;
  726. }
  727. ast_ari_channels_continue_in_dialplan(headers, &args, response);
  728. #if defined(AST_DEVMODE)
  729. code = response->response_code;
  730. switch (code) {
  731. case 0: /* Implementation is still a stub, or the code wasn't set */
  732. is_valid = response->message == NULL;
  733. break;
  734. case 500: /* Internal Server Error */
  735. case 501: /* Not Implemented */
  736. case 404: /* Channel not found */
  737. case 409: /* Channel not in a Stasis application */
  738. case 412: /* Channel in invalid state */
  739. is_valid = 1;
  740. break;
  741. default:
  742. if (200 <= code && code <= 299) {
  743. is_valid = ast_ari_validate_void(
  744. response->message);
  745. } else {
  746. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/continue\n", code);
  747. is_valid = 0;
  748. }
  749. }
  750. if (!is_valid) {
  751. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/continue\n");
  752. ast_ari_response_error(response, 500,
  753. "Internal Server Error", "Response validation failed");
  754. }
  755. #endif /* AST_DEVMODE */
  756. fin: __attribute__((unused))
  757. return;
  758. }
  759. int ast_ari_channels_move_parse_body(
  760. struct ast_json *body,
  761. struct ast_ari_channels_move_args *args)
  762. {
  763. struct ast_json *field;
  764. /* Parse query parameters out of it */
  765. field = ast_json_object_get(body, "app");
  766. if (field) {
  767. args->app = ast_json_string_get(field);
  768. }
  769. field = ast_json_object_get(body, "appArgs");
  770. if (field) {
  771. args->app_args = ast_json_string_get(field);
  772. }
  773. return 0;
  774. }
  775. /*!
  776. * \brief Parameter parsing callback for /channels/{channelId}/move.
  777. * \param ser TCP/TLS session object
  778. * \param get_params GET parameters in the HTTP request.
  779. * \param path_vars Path variables extracted from the request.
  780. * \param headers HTTP headers.
  781. * \param body
  782. * \param[out] response Response to the HTTP request.
  783. */
  784. static void ast_ari_channels_move_cb(
  785. struct ast_tcptls_session_instance *ser,
  786. struct ast_variable *get_params, struct ast_variable *path_vars,
  787. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  788. {
  789. struct ast_ari_channels_move_args args = {};
  790. struct ast_variable *i;
  791. #if defined(AST_DEVMODE)
  792. int is_valid;
  793. int code;
  794. #endif /* AST_DEVMODE */
  795. for (i = get_params; i; i = i->next) {
  796. if (strcmp(i->name, "app") == 0) {
  797. args.app = (i->value);
  798. } else
  799. if (strcmp(i->name, "appArgs") == 0) {
  800. args.app_args = (i->value);
  801. } else
  802. {}
  803. }
  804. for (i = path_vars; i; i = i->next) {
  805. if (strcmp(i->name, "channelId") == 0) {
  806. args.channel_id = (i->value);
  807. } else
  808. {}
  809. }
  810. if (ast_ari_channels_move_parse_body(body, &args)) {
  811. ast_ari_response_alloc_failed(response);
  812. goto fin;
  813. }
  814. ast_ari_channels_move(headers, &args, response);
  815. #if defined(AST_DEVMODE)
  816. code = response->response_code;
  817. switch (code) {
  818. case 0: /* Implementation is still a stub, or the code wasn't set */
  819. is_valid = response->message == NULL;
  820. break;
  821. case 500: /* Internal Server Error */
  822. case 501: /* Not Implemented */
  823. case 404: /* Channel not found */
  824. case 409: /* Channel not in a Stasis application */
  825. is_valid = 1;
  826. break;
  827. default:
  828. if (200 <= code && code <= 299) {
  829. is_valid = ast_ari_validate_void(
  830. response->message);
  831. } else {
  832. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/move\n", code);
  833. is_valid = 0;
  834. }
  835. }
  836. if (!is_valid) {
  837. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/move\n");
  838. ast_ari_response_error(response, 500,
  839. "Internal Server Error", "Response validation failed");
  840. }
  841. #endif /* AST_DEVMODE */
  842. fin: __attribute__((unused))
  843. return;
  844. }
  845. int ast_ari_channels_redirect_parse_body(
  846. struct ast_json *body,
  847. struct ast_ari_channels_redirect_args *args)
  848. {
  849. struct ast_json *field;
  850. /* Parse query parameters out of it */
  851. field = ast_json_object_get(body, "endpoint");
  852. if (field) {
  853. args->endpoint = ast_json_string_get(field);
  854. }
  855. return 0;
  856. }
  857. /*!
  858. * \brief Parameter parsing callback for /channels/{channelId}/redirect.
  859. * \param ser TCP/TLS session object
  860. * \param get_params GET parameters in the HTTP request.
  861. * \param path_vars Path variables extracted from the request.
  862. * \param headers HTTP headers.
  863. * \param body
  864. * \param[out] response Response to the HTTP request.
  865. */
  866. static void ast_ari_channels_redirect_cb(
  867. struct ast_tcptls_session_instance *ser,
  868. struct ast_variable *get_params, struct ast_variable *path_vars,
  869. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  870. {
  871. struct ast_ari_channels_redirect_args args = {};
  872. struct ast_variable *i;
  873. #if defined(AST_DEVMODE)
  874. int is_valid;
  875. int code;
  876. #endif /* AST_DEVMODE */
  877. for (i = get_params; i; i = i->next) {
  878. if (strcmp(i->name, "endpoint") == 0) {
  879. args.endpoint = (i->value);
  880. } else
  881. {}
  882. }
  883. for (i = path_vars; i; i = i->next) {
  884. if (strcmp(i->name, "channelId") == 0) {
  885. args.channel_id = (i->value);
  886. } else
  887. {}
  888. }
  889. if (ast_ari_channels_redirect_parse_body(body, &args)) {
  890. ast_ari_response_alloc_failed(response);
  891. goto fin;
  892. }
  893. ast_ari_channels_redirect(headers, &args, response);
  894. #if defined(AST_DEVMODE)
  895. code = response->response_code;
  896. switch (code) {
  897. case 0: /* Implementation is still a stub, or the code wasn't set */
  898. is_valid = response->message == NULL;
  899. break;
  900. case 500: /* Internal Server Error */
  901. case 501: /* Not Implemented */
  902. case 400: /* Endpoint parameter not provided */
  903. case 404: /* Channel or endpoint not found */
  904. case 409: /* Channel not in a Stasis application */
  905. case 422: /* Endpoint is not the same type as the channel */
  906. case 412: /* Channel in invalid state */
  907. is_valid = 1;
  908. break;
  909. default:
  910. if (200 <= code && code <= 299) {
  911. is_valid = ast_ari_validate_void(
  912. response->message);
  913. } else {
  914. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/redirect\n", code);
  915. is_valid = 0;
  916. }
  917. }
  918. if (!is_valid) {
  919. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/redirect\n");
  920. ast_ari_response_error(response, 500,
  921. "Internal Server Error", "Response validation failed");
  922. }
  923. #endif /* AST_DEVMODE */
  924. fin: __attribute__((unused))
  925. return;
  926. }
  927. /*!
  928. * \brief Parameter parsing callback for /channels/{channelId}/answer.
  929. * \param ser TCP/TLS session object
  930. * \param get_params GET parameters in the HTTP request.
  931. * \param path_vars Path variables extracted from the request.
  932. * \param headers HTTP headers.
  933. * \param body
  934. * \param[out] response Response to the HTTP request.
  935. */
  936. static void ast_ari_channels_answer_cb(
  937. struct ast_tcptls_session_instance *ser,
  938. struct ast_variable *get_params, struct ast_variable *path_vars,
  939. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  940. {
  941. struct ast_ari_channels_answer_args args = {};
  942. struct ast_variable *i;
  943. #if defined(AST_DEVMODE)
  944. int is_valid;
  945. int code;
  946. #endif /* AST_DEVMODE */
  947. for (i = path_vars; i; i = i->next) {
  948. if (strcmp(i->name, "channelId") == 0) {
  949. args.channel_id = (i->value);
  950. } else
  951. {}
  952. }
  953. ast_ari_channels_answer(headers, &args, response);
  954. #if defined(AST_DEVMODE)
  955. code = response->response_code;
  956. switch (code) {
  957. case 0: /* Implementation is still a stub, or the code wasn't set */
  958. is_valid = response->message == NULL;
  959. break;
  960. case 500: /* Internal Server Error */
  961. case 501: /* Not Implemented */
  962. case 404: /* Channel not found */
  963. case 409: /* Channel not in a Stasis application */
  964. case 412: /* Channel in invalid state */
  965. is_valid = 1;
  966. break;
  967. default:
  968. if (200 <= code && code <= 299) {
  969. is_valid = ast_ari_validate_void(
  970. response->message);
  971. } else {
  972. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/answer\n", code);
  973. is_valid = 0;
  974. }
  975. }
  976. if (!is_valid) {
  977. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/answer\n");
  978. ast_ari_response_error(response, 500,
  979. "Internal Server Error", "Response validation failed");
  980. }
  981. #endif /* AST_DEVMODE */
  982. fin: __attribute__((unused))
  983. return;
  984. }
  985. /*!
  986. * \brief Parameter parsing callback for /channels/{channelId}/ring.
  987. * \param ser TCP/TLS session object
  988. * \param get_params GET parameters in the HTTP request.
  989. * \param path_vars Path variables extracted from the request.
  990. * \param headers HTTP headers.
  991. * \param body
  992. * \param[out] response Response to the HTTP request.
  993. */
  994. static void ast_ari_channels_ring_cb(
  995. struct ast_tcptls_session_instance *ser,
  996. struct ast_variable *get_params, struct ast_variable *path_vars,
  997. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  998. {
  999. struct ast_ari_channels_ring_args args = {};
  1000. struct ast_variable *i;
  1001. #if defined(AST_DEVMODE)
  1002. int is_valid;
  1003. int code;
  1004. #endif /* AST_DEVMODE */
  1005. for (i = path_vars; i; i = i->next) {
  1006. if (strcmp(i->name, "channelId") == 0) {
  1007. args.channel_id = (i->value);
  1008. } else
  1009. {}
  1010. }
  1011. ast_ari_channels_ring(headers, &args, response);
  1012. #if defined(AST_DEVMODE)
  1013. code = response->response_code;
  1014. switch (code) {
  1015. case 0: /* Implementation is still a stub, or the code wasn't set */
  1016. is_valid = response->message == NULL;
  1017. break;
  1018. case 500: /* Internal Server Error */
  1019. case 501: /* Not Implemented */
  1020. case 404: /* Channel not found */
  1021. case 409: /* Channel not in a Stasis application */
  1022. case 412: /* Channel in invalid state */
  1023. is_valid = 1;
  1024. break;
  1025. default:
  1026. if (200 <= code && code <= 299) {
  1027. is_valid = ast_ari_validate_void(
  1028. response->message);
  1029. } else {
  1030. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/ring\n", code);
  1031. is_valid = 0;
  1032. }
  1033. }
  1034. if (!is_valid) {
  1035. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/ring\n");
  1036. ast_ari_response_error(response, 500,
  1037. "Internal Server Error", "Response validation failed");
  1038. }
  1039. #endif /* AST_DEVMODE */
  1040. fin: __attribute__((unused))
  1041. return;
  1042. }
  1043. /*!
  1044. * \brief Parameter parsing callback for /channels/{channelId}/ring.
  1045. * \param ser TCP/TLS session object
  1046. * \param get_params GET parameters in the HTTP request.
  1047. * \param path_vars Path variables extracted from the request.
  1048. * \param headers HTTP headers.
  1049. * \param body
  1050. * \param[out] response Response to the HTTP request.
  1051. */
  1052. static void ast_ari_channels_ring_stop_cb(
  1053. struct ast_tcptls_session_instance *ser,
  1054. struct ast_variable *get_params, struct ast_variable *path_vars,
  1055. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1056. {
  1057. struct ast_ari_channels_ring_stop_args args = {};
  1058. struct ast_variable *i;
  1059. #if defined(AST_DEVMODE)
  1060. int is_valid;
  1061. int code;
  1062. #endif /* AST_DEVMODE */
  1063. for (i = path_vars; i; i = i->next) {
  1064. if (strcmp(i->name, "channelId") == 0) {
  1065. args.channel_id = (i->value);
  1066. } else
  1067. {}
  1068. }
  1069. ast_ari_channels_ring_stop(headers, &args, response);
  1070. #if defined(AST_DEVMODE)
  1071. code = response->response_code;
  1072. switch (code) {
  1073. case 0: /* Implementation is still a stub, or the code wasn't set */
  1074. is_valid = response->message == NULL;
  1075. break;
  1076. case 500: /* Internal Server Error */
  1077. case 501: /* Not Implemented */
  1078. case 404: /* Channel not found */
  1079. case 409: /* Channel not in a Stasis application */
  1080. case 412: /* Channel in invalid state */
  1081. is_valid = 1;
  1082. break;
  1083. default:
  1084. if (200 <= code && code <= 299) {
  1085. is_valid = ast_ari_validate_void(
  1086. response->message);
  1087. } else {
  1088. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/ring\n", code);
  1089. is_valid = 0;
  1090. }
  1091. }
  1092. if (!is_valid) {
  1093. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/ring\n");
  1094. ast_ari_response_error(response, 500,
  1095. "Internal Server Error", "Response validation failed");
  1096. }
  1097. #endif /* AST_DEVMODE */
  1098. fin: __attribute__((unused))
  1099. return;
  1100. }
  1101. int ast_ari_channels_send_dtmf_parse_body(
  1102. struct ast_json *body,
  1103. struct ast_ari_channels_send_dtmf_args *args)
  1104. {
  1105. struct ast_json *field;
  1106. /* Parse query parameters out of it */
  1107. field = ast_json_object_get(body, "dtmf");
  1108. if (field) {
  1109. args->dtmf = ast_json_string_get(field);
  1110. }
  1111. field = ast_json_object_get(body, "before");
  1112. if (field) {
  1113. args->before = ast_json_integer_get(field);
  1114. }
  1115. field = ast_json_object_get(body, "between");
  1116. if (field) {
  1117. args->between = ast_json_integer_get(field);
  1118. }
  1119. field = ast_json_object_get(body, "duration");
  1120. if (field) {
  1121. args->duration = ast_json_integer_get(field);
  1122. }
  1123. field = ast_json_object_get(body, "after");
  1124. if (field) {
  1125. args->after = ast_json_integer_get(field);
  1126. }
  1127. return 0;
  1128. }
  1129. /*!
  1130. * \brief Parameter parsing callback for /channels/{channelId}/dtmf.
  1131. * \param ser TCP/TLS session object
  1132. * \param get_params GET parameters in the HTTP request.
  1133. * \param path_vars Path variables extracted from the request.
  1134. * \param headers HTTP headers.
  1135. * \param body
  1136. * \param[out] response Response to the HTTP request.
  1137. */
  1138. static void ast_ari_channels_send_dtmf_cb(
  1139. struct ast_tcptls_session_instance *ser,
  1140. struct ast_variable *get_params, struct ast_variable *path_vars,
  1141. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1142. {
  1143. struct ast_ari_channels_send_dtmf_args args = {};
  1144. struct ast_variable *i;
  1145. #if defined(AST_DEVMODE)
  1146. int is_valid;
  1147. int code;
  1148. #endif /* AST_DEVMODE */
  1149. for (i = get_params; i; i = i->next) {
  1150. if (strcmp(i->name, "dtmf") == 0) {
  1151. args.dtmf = (i->value);
  1152. } else
  1153. if (strcmp(i->name, "before") == 0) {
  1154. args.before = atoi(i->value);
  1155. } else
  1156. if (strcmp(i->name, "between") == 0) {
  1157. args.between = atoi(i->value);
  1158. } else
  1159. if (strcmp(i->name, "duration") == 0) {
  1160. args.duration = atoi(i->value);
  1161. } else
  1162. if (strcmp(i->name, "after") == 0) {
  1163. args.after = atoi(i->value);
  1164. } else
  1165. {}
  1166. }
  1167. for (i = path_vars; i; i = i->next) {
  1168. if (strcmp(i->name, "channelId") == 0) {
  1169. args.channel_id = (i->value);
  1170. } else
  1171. {}
  1172. }
  1173. if (ast_ari_channels_send_dtmf_parse_body(body, &args)) {
  1174. ast_ari_response_alloc_failed(response);
  1175. goto fin;
  1176. }
  1177. ast_ari_channels_send_dtmf(headers, &args, response);
  1178. #if defined(AST_DEVMODE)
  1179. code = response->response_code;
  1180. switch (code) {
  1181. case 0: /* Implementation is still a stub, or the code wasn't set */
  1182. is_valid = response->message == NULL;
  1183. break;
  1184. case 500: /* Internal Server Error */
  1185. case 501: /* Not Implemented */
  1186. case 400: /* DTMF is required */
  1187. case 404: /* Channel not found */
  1188. case 409: /* Channel not in a Stasis application */
  1189. case 412: /* Channel in invalid state */
  1190. is_valid = 1;
  1191. break;
  1192. default:
  1193. if (200 <= code && code <= 299) {
  1194. is_valid = ast_ari_validate_void(
  1195. response->message);
  1196. } else {
  1197. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/dtmf\n", code);
  1198. is_valid = 0;
  1199. }
  1200. }
  1201. if (!is_valid) {
  1202. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/dtmf\n");
  1203. ast_ari_response_error(response, 500,
  1204. "Internal Server Error", "Response validation failed");
  1205. }
  1206. #endif /* AST_DEVMODE */
  1207. fin: __attribute__((unused))
  1208. return;
  1209. }
  1210. int ast_ari_channels_mute_parse_body(
  1211. struct ast_json *body,
  1212. struct ast_ari_channels_mute_args *args)
  1213. {
  1214. struct ast_json *field;
  1215. /* Parse query parameters out of it */
  1216. field = ast_json_object_get(body, "direction");
  1217. if (field) {
  1218. args->direction = ast_json_string_get(field);
  1219. }
  1220. return 0;
  1221. }
  1222. /*!
  1223. * \brief Parameter parsing callback for /channels/{channelId}/mute.
  1224. * \param ser TCP/TLS session object
  1225. * \param get_params GET parameters in the HTTP request.
  1226. * \param path_vars Path variables extracted from the request.
  1227. * \param headers HTTP headers.
  1228. * \param body
  1229. * \param[out] response Response to the HTTP request.
  1230. */
  1231. static void ast_ari_channels_mute_cb(
  1232. struct ast_tcptls_session_instance *ser,
  1233. struct ast_variable *get_params, struct ast_variable *path_vars,
  1234. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1235. {
  1236. struct ast_ari_channels_mute_args args = {};
  1237. struct ast_variable *i;
  1238. #if defined(AST_DEVMODE)
  1239. int is_valid;
  1240. int code;
  1241. #endif /* AST_DEVMODE */
  1242. for (i = get_params; i; i = i->next) {
  1243. if (strcmp(i->name, "direction") == 0) {
  1244. args.direction = (i->value);
  1245. } else
  1246. {}
  1247. }
  1248. for (i = path_vars; i; i = i->next) {
  1249. if (strcmp(i->name, "channelId") == 0) {
  1250. args.channel_id = (i->value);
  1251. } else
  1252. {}
  1253. }
  1254. if (ast_ari_channels_mute_parse_body(body, &args)) {
  1255. ast_ari_response_alloc_failed(response);
  1256. goto fin;
  1257. }
  1258. ast_ari_channels_mute(headers, &args, response);
  1259. #if defined(AST_DEVMODE)
  1260. code = response->response_code;
  1261. switch (code) {
  1262. case 0: /* Implementation is still a stub, or the code wasn't set */
  1263. is_valid = response->message == NULL;
  1264. break;
  1265. case 500: /* Internal Server Error */
  1266. case 501: /* Not Implemented */
  1267. case 404: /* Channel not found */
  1268. case 409: /* Channel not in a Stasis application */
  1269. case 412: /* Channel in invalid state */
  1270. is_valid = 1;
  1271. break;
  1272. default:
  1273. if (200 <= code && code <= 299) {
  1274. is_valid = ast_ari_validate_void(
  1275. response->message);
  1276. } else {
  1277. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mute\n", code);
  1278. is_valid = 0;
  1279. }
  1280. }
  1281. if (!is_valid) {
  1282. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mute\n");
  1283. ast_ari_response_error(response, 500,
  1284. "Internal Server Error", "Response validation failed");
  1285. }
  1286. #endif /* AST_DEVMODE */
  1287. fin: __attribute__((unused))
  1288. return;
  1289. }
  1290. int ast_ari_channels_unmute_parse_body(
  1291. struct ast_json *body,
  1292. struct ast_ari_channels_unmute_args *args)
  1293. {
  1294. struct ast_json *field;
  1295. /* Parse query parameters out of it */
  1296. field = ast_json_object_get(body, "direction");
  1297. if (field) {
  1298. args->direction = ast_json_string_get(field);
  1299. }
  1300. return 0;
  1301. }
  1302. /*!
  1303. * \brief Parameter parsing callback for /channels/{channelId}/mute.
  1304. * \param ser TCP/TLS session object
  1305. * \param get_params GET parameters in the HTTP request.
  1306. * \param path_vars Path variables extracted from the request.
  1307. * \param headers HTTP headers.
  1308. * \param body
  1309. * \param[out] response Response to the HTTP request.
  1310. */
  1311. static void ast_ari_channels_unmute_cb(
  1312. struct ast_tcptls_session_instance *ser,
  1313. struct ast_variable *get_params, struct ast_variable *path_vars,
  1314. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1315. {
  1316. struct ast_ari_channels_unmute_args args = {};
  1317. struct ast_variable *i;
  1318. #if defined(AST_DEVMODE)
  1319. int is_valid;
  1320. int code;
  1321. #endif /* AST_DEVMODE */
  1322. for (i = get_params; i; i = i->next) {
  1323. if (strcmp(i->name, "direction") == 0) {
  1324. args.direction = (i->value);
  1325. } else
  1326. {}
  1327. }
  1328. for (i = path_vars; i; i = i->next) {
  1329. if (strcmp(i->name, "channelId") == 0) {
  1330. args.channel_id = (i->value);
  1331. } else
  1332. {}
  1333. }
  1334. if (ast_ari_channels_unmute_parse_body(body, &args)) {
  1335. ast_ari_response_alloc_failed(response);
  1336. goto fin;
  1337. }
  1338. ast_ari_channels_unmute(headers, &args, response);
  1339. #if defined(AST_DEVMODE)
  1340. code = response->response_code;
  1341. switch (code) {
  1342. case 0: /* Implementation is still a stub, or the code wasn't set */
  1343. is_valid = response->message == NULL;
  1344. break;
  1345. case 500: /* Internal Server Error */
  1346. case 501: /* Not Implemented */
  1347. case 404: /* Channel not found */
  1348. case 409: /* Channel not in a Stasis application */
  1349. case 412: /* Channel in invalid state */
  1350. is_valid = 1;
  1351. break;
  1352. default:
  1353. if (200 <= code && code <= 299) {
  1354. is_valid = ast_ari_validate_void(
  1355. response->message);
  1356. } else {
  1357. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mute\n", code);
  1358. is_valid = 0;
  1359. }
  1360. }
  1361. if (!is_valid) {
  1362. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mute\n");
  1363. ast_ari_response_error(response, 500,
  1364. "Internal Server Error", "Response validation failed");
  1365. }
  1366. #endif /* AST_DEVMODE */
  1367. fin: __attribute__((unused))
  1368. return;
  1369. }
  1370. /*!
  1371. * \brief Parameter parsing callback for /channels/{channelId}/hold.
  1372. * \param ser TCP/TLS session object
  1373. * \param get_params GET parameters in the HTTP request.
  1374. * \param path_vars Path variables extracted from the request.
  1375. * \param headers HTTP headers.
  1376. * \param body
  1377. * \param[out] response Response to the HTTP request.
  1378. */
  1379. static void ast_ari_channels_hold_cb(
  1380. struct ast_tcptls_session_instance *ser,
  1381. struct ast_variable *get_params, struct ast_variable *path_vars,
  1382. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1383. {
  1384. struct ast_ari_channels_hold_args args = {};
  1385. struct ast_variable *i;
  1386. #if defined(AST_DEVMODE)
  1387. int is_valid;
  1388. int code;
  1389. #endif /* AST_DEVMODE */
  1390. for (i = path_vars; i; i = i->next) {
  1391. if (strcmp(i->name, "channelId") == 0) {
  1392. args.channel_id = (i->value);
  1393. } else
  1394. {}
  1395. }
  1396. ast_ari_channels_hold(headers, &args, response);
  1397. #if defined(AST_DEVMODE)
  1398. code = response->response_code;
  1399. switch (code) {
  1400. case 0: /* Implementation is still a stub, or the code wasn't set */
  1401. is_valid = response->message == NULL;
  1402. break;
  1403. case 500: /* Internal Server Error */
  1404. case 501: /* Not Implemented */
  1405. case 404: /* Channel not found */
  1406. case 409: /* Channel not in a Stasis application */
  1407. case 412: /* Channel in invalid state */
  1408. is_valid = 1;
  1409. break;
  1410. default:
  1411. if (200 <= code && code <= 299) {
  1412. is_valid = ast_ari_validate_void(
  1413. response->message);
  1414. } else {
  1415. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
  1416. is_valid = 0;
  1417. }
  1418. }
  1419. if (!is_valid) {
  1420. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
  1421. ast_ari_response_error(response, 500,
  1422. "Internal Server Error", "Response validation failed");
  1423. }
  1424. #endif /* AST_DEVMODE */
  1425. fin: __attribute__((unused))
  1426. return;
  1427. }
  1428. /*!
  1429. * \brief Parameter parsing callback for /channels/{channelId}/hold.
  1430. * \param ser TCP/TLS session object
  1431. * \param get_params GET parameters in the HTTP request.
  1432. * \param path_vars Path variables extracted from the request.
  1433. * \param headers HTTP headers.
  1434. * \param body
  1435. * \param[out] response Response to the HTTP request.
  1436. */
  1437. static void ast_ari_channels_unhold_cb(
  1438. struct ast_tcptls_session_instance *ser,
  1439. struct ast_variable *get_params, struct ast_variable *path_vars,
  1440. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1441. {
  1442. struct ast_ari_channels_unhold_args args = {};
  1443. struct ast_variable *i;
  1444. #if defined(AST_DEVMODE)
  1445. int is_valid;
  1446. int code;
  1447. #endif /* AST_DEVMODE */
  1448. for (i = path_vars; i; i = i->next) {
  1449. if (strcmp(i->name, "channelId") == 0) {
  1450. args.channel_id = (i->value);
  1451. } else
  1452. {}
  1453. }
  1454. ast_ari_channels_unhold(headers, &args, response);
  1455. #if defined(AST_DEVMODE)
  1456. code = response->response_code;
  1457. switch (code) {
  1458. case 0: /* Implementation is still a stub, or the code wasn't set */
  1459. is_valid = response->message == NULL;
  1460. break;
  1461. case 500: /* Internal Server Error */
  1462. case 501: /* Not Implemented */
  1463. case 404: /* Channel not found */
  1464. case 409: /* Channel not in a Stasis application */
  1465. case 412: /* Channel in invalid state */
  1466. is_valid = 1;
  1467. break;
  1468. default:
  1469. if (200 <= code && code <= 299) {
  1470. is_valid = ast_ari_validate_void(
  1471. response->message);
  1472. } else {
  1473. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
  1474. is_valid = 0;
  1475. }
  1476. }
  1477. if (!is_valid) {
  1478. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
  1479. ast_ari_response_error(response, 500,
  1480. "Internal Server Error", "Response validation failed");
  1481. }
  1482. #endif /* AST_DEVMODE */
  1483. fin: __attribute__((unused))
  1484. return;
  1485. }
  1486. int ast_ari_channels_start_moh_parse_body(
  1487. struct ast_json *body,
  1488. struct ast_ari_channels_start_moh_args *args)
  1489. {
  1490. struct ast_json *field;
  1491. /* Parse query parameters out of it */
  1492. field = ast_json_object_get(body, "mohClass");
  1493. if (field) {
  1494. args->moh_class = ast_json_string_get(field);
  1495. }
  1496. return 0;
  1497. }
  1498. /*!
  1499. * \brief Parameter parsing callback for /channels/{channelId}/moh.
  1500. * \param ser TCP/TLS session object
  1501. * \param get_params GET parameters in the HTTP request.
  1502. * \param path_vars Path variables extracted from the request.
  1503. * \param headers HTTP headers.
  1504. * \param body
  1505. * \param[out] response Response to the HTTP request.
  1506. */
  1507. static void ast_ari_channels_start_moh_cb(
  1508. struct ast_tcptls_session_instance *ser,
  1509. struct ast_variable *get_params, struct ast_variable *path_vars,
  1510. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1511. {
  1512. struct ast_ari_channels_start_moh_args args = {};
  1513. struct ast_variable *i;
  1514. #if defined(AST_DEVMODE)
  1515. int is_valid;
  1516. int code;
  1517. #endif /* AST_DEVMODE */
  1518. for (i = get_params; i; i = i->next) {
  1519. if (strcmp(i->name, "mohClass") == 0) {
  1520. args.moh_class = (i->value);
  1521. } else
  1522. {}
  1523. }
  1524. for (i = path_vars; i; i = i->next) {
  1525. if (strcmp(i->name, "channelId") == 0) {
  1526. args.channel_id = (i->value);
  1527. } else
  1528. {}
  1529. }
  1530. if (ast_ari_channels_start_moh_parse_body(body, &args)) {
  1531. ast_ari_response_alloc_failed(response);
  1532. goto fin;
  1533. }
  1534. ast_ari_channels_start_moh(headers, &args, response);
  1535. #if defined(AST_DEVMODE)
  1536. code = response->response_code;
  1537. switch (code) {
  1538. case 0: /* Implementation is still a stub, or the code wasn't set */
  1539. is_valid = response->message == NULL;
  1540. break;
  1541. case 500: /* Internal Server Error */
  1542. case 501: /* Not Implemented */
  1543. case 404: /* Channel not found */
  1544. case 409: /* Channel not in a Stasis application */
  1545. case 412: /* Channel in invalid state */
  1546. is_valid = 1;
  1547. break;
  1548. default:
  1549. if (200 <= code && code <= 299) {
  1550. is_valid = ast_ari_validate_void(
  1551. response->message);
  1552. } else {
  1553. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/moh\n", code);
  1554. is_valid = 0;
  1555. }
  1556. }
  1557. if (!is_valid) {
  1558. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/moh\n");
  1559. ast_ari_response_error(response, 500,
  1560. "Internal Server Error", "Response validation failed");
  1561. }
  1562. #endif /* AST_DEVMODE */
  1563. fin: __attribute__((unused))
  1564. return;
  1565. }
  1566. /*!
  1567. * \brief Parameter parsing callback for /channels/{channelId}/moh.
  1568. * \param ser TCP/TLS session object
  1569. * \param get_params GET parameters in the HTTP request.
  1570. * \param path_vars Path variables extracted from the request.
  1571. * \param headers HTTP headers.
  1572. * \param body
  1573. * \param[out] response Response to the HTTP request.
  1574. */
  1575. static void ast_ari_channels_stop_moh_cb(
  1576. struct ast_tcptls_session_instance *ser,
  1577. struct ast_variable *get_params, struct ast_variable *path_vars,
  1578. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1579. {
  1580. struct ast_ari_channels_stop_moh_args args = {};
  1581. struct ast_variable *i;
  1582. #if defined(AST_DEVMODE)
  1583. int is_valid;
  1584. int code;
  1585. #endif /* AST_DEVMODE */
  1586. for (i = path_vars; i; i = i->next) {
  1587. if (strcmp(i->name, "channelId") == 0) {
  1588. args.channel_id = (i->value);
  1589. } else
  1590. {}
  1591. }
  1592. ast_ari_channels_stop_moh(headers, &args, response);
  1593. #if defined(AST_DEVMODE)
  1594. code = response->response_code;
  1595. switch (code) {
  1596. case 0: /* Implementation is still a stub, or the code wasn't set */
  1597. is_valid = response->message == NULL;
  1598. break;
  1599. case 500: /* Internal Server Error */
  1600. case 501: /* Not Implemented */
  1601. case 404: /* Channel not found */
  1602. case 409: /* Channel not in a Stasis application */
  1603. case 412: /* Channel in invalid state */
  1604. is_valid = 1;
  1605. break;
  1606. default:
  1607. if (200 <= code && code <= 299) {
  1608. is_valid = ast_ari_validate_void(
  1609. response->message);
  1610. } else {
  1611. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/moh\n", code);
  1612. is_valid = 0;
  1613. }
  1614. }
  1615. if (!is_valid) {
  1616. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/moh\n");
  1617. ast_ari_response_error(response, 500,
  1618. "Internal Server Error", "Response validation failed");
  1619. }
  1620. #endif /* AST_DEVMODE */
  1621. fin: __attribute__((unused))
  1622. return;
  1623. }
  1624. /*!
  1625. * \brief Parameter parsing callback for /channels/{channelId}/silence.
  1626. * \param ser TCP/TLS session object
  1627. * \param get_params GET parameters in the HTTP request.
  1628. * \param path_vars Path variables extracted from the request.
  1629. * \param headers HTTP headers.
  1630. * \param body
  1631. * \param[out] response Response to the HTTP request.
  1632. */
  1633. static void ast_ari_channels_start_silence_cb(
  1634. struct ast_tcptls_session_instance *ser,
  1635. struct ast_variable *get_params, struct ast_variable *path_vars,
  1636. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1637. {
  1638. struct ast_ari_channels_start_silence_args args = {};
  1639. struct ast_variable *i;
  1640. #if defined(AST_DEVMODE)
  1641. int is_valid;
  1642. int code;
  1643. #endif /* AST_DEVMODE */
  1644. for (i = path_vars; i; i = i->next) {
  1645. if (strcmp(i->name, "channelId") == 0) {
  1646. args.channel_id = (i->value);
  1647. } else
  1648. {}
  1649. }
  1650. ast_ari_channels_start_silence(headers, &args, response);
  1651. #if defined(AST_DEVMODE)
  1652. code = response->response_code;
  1653. switch (code) {
  1654. case 0: /* Implementation is still a stub, or the code wasn't set */
  1655. is_valid = response->message == NULL;
  1656. break;
  1657. case 500: /* Internal Server Error */
  1658. case 501: /* Not Implemented */
  1659. case 404: /* Channel not found */
  1660. case 409: /* Channel not in a Stasis application */
  1661. case 412: /* Channel in invalid state */
  1662. is_valid = 1;
  1663. break;
  1664. default:
  1665. if (200 <= code && code <= 299) {
  1666. is_valid = ast_ari_validate_void(
  1667. response->message);
  1668. } else {
  1669. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/silence\n", code);
  1670. is_valid = 0;
  1671. }
  1672. }
  1673. if (!is_valid) {
  1674. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/silence\n");
  1675. ast_ari_response_error(response, 500,
  1676. "Internal Server Error", "Response validation failed");
  1677. }
  1678. #endif /* AST_DEVMODE */
  1679. fin: __attribute__((unused))
  1680. return;
  1681. }
  1682. /*!
  1683. * \brief Parameter parsing callback for /channels/{channelId}/silence.
  1684. * \param ser TCP/TLS session object
  1685. * \param get_params GET parameters in the HTTP request.
  1686. * \param path_vars Path variables extracted from the request.
  1687. * \param headers HTTP headers.
  1688. * \param body
  1689. * \param[out] response Response to the HTTP request.
  1690. */
  1691. static void ast_ari_channels_stop_silence_cb(
  1692. struct ast_tcptls_session_instance *ser,
  1693. struct ast_variable *get_params, struct ast_variable *path_vars,
  1694. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1695. {
  1696. struct ast_ari_channels_stop_silence_args args = {};
  1697. struct ast_variable *i;
  1698. #if defined(AST_DEVMODE)
  1699. int is_valid;
  1700. int code;
  1701. #endif /* AST_DEVMODE */
  1702. for (i = path_vars; i; i = i->next) {
  1703. if (strcmp(i->name, "channelId") == 0) {
  1704. args.channel_id = (i->value);
  1705. } else
  1706. {}
  1707. }
  1708. ast_ari_channels_stop_silence(headers, &args, response);
  1709. #if defined(AST_DEVMODE)
  1710. code = response->response_code;
  1711. switch (code) {
  1712. case 0: /* Implementation is still a stub, or the code wasn't set */
  1713. is_valid = response->message == NULL;
  1714. break;
  1715. case 500: /* Internal Server Error */
  1716. case 501: /* Not Implemented */
  1717. case 404: /* Channel not found */
  1718. case 409: /* Channel not in a Stasis application */
  1719. case 412: /* Channel in invalid state */
  1720. is_valid = 1;
  1721. break;
  1722. default:
  1723. if (200 <= code && code <= 299) {
  1724. is_valid = ast_ari_validate_void(
  1725. response->message);
  1726. } else {
  1727. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/silence\n", code);
  1728. is_valid = 0;
  1729. }
  1730. }
  1731. if (!is_valid) {
  1732. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/silence\n");
  1733. ast_ari_response_error(response, 500,
  1734. "Internal Server Error", "Response validation failed");
  1735. }
  1736. #endif /* AST_DEVMODE */
  1737. fin: __attribute__((unused))
  1738. return;
  1739. }
  1740. int ast_ari_channels_play_parse_body(
  1741. struct ast_json *body,
  1742. struct ast_ari_channels_play_args *args)
  1743. {
  1744. struct ast_json *field;
  1745. /* Parse query parameters out of it */
  1746. field = ast_json_object_get(body, "media");
  1747. if (field) {
  1748. /* If they were silly enough to both pass in a query param and a
  1749. * JSON body, free up the query value.
  1750. */
  1751. ast_free(args->media);
  1752. if (ast_json_typeof(field) == AST_JSON_ARRAY) {
  1753. /* Multiple param passed as array */
  1754. size_t i;
  1755. args->media_count = ast_json_array_size(field);
  1756. args->media = ast_malloc(sizeof(*args->media) * args->media_count);
  1757. if (!args->media) {
  1758. return -1;
  1759. }
  1760. for (i = 0; i < args->media_count; ++i) {
  1761. args->media[i] = ast_json_string_get(ast_json_array_get(field, i));
  1762. }
  1763. } else {
  1764. /* Multiple param passed as single value */
  1765. args->media_count = 1;
  1766. args->media = ast_malloc(sizeof(*args->media) * args->media_count);
  1767. if (!args->media) {
  1768. return -1;
  1769. }
  1770. args->media[0] = ast_json_string_get(field);
  1771. }
  1772. }
  1773. field = ast_json_object_get(body, "lang");
  1774. if (field) {
  1775. args->lang = ast_json_string_get(field);
  1776. }
  1777. field = ast_json_object_get(body, "offsetms");
  1778. if (field) {
  1779. args->offsetms = ast_json_integer_get(field);
  1780. }
  1781. field = ast_json_object_get(body, "skipms");
  1782. if (field) {
  1783. args->skipms = ast_json_integer_get(field);
  1784. }
  1785. field = ast_json_object_get(body, "playbackId");
  1786. if (field) {
  1787. args->playback_id = ast_json_string_get(field);
  1788. }
  1789. return 0;
  1790. }
  1791. /*!
  1792. * \brief Parameter parsing callback for /channels/{channelId}/play.
  1793. * \param ser TCP/TLS session object
  1794. * \param get_params GET parameters in the HTTP request.
  1795. * \param path_vars Path variables extracted from the request.
  1796. * \param headers HTTP headers.
  1797. * \param body
  1798. * \param[out] response Response to the HTTP request.
  1799. */
  1800. static void ast_ari_channels_play_cb(
  1801. struct ast_tcptls_session_instance *ser,
  1802. struct ast_variable *get_params, struct ast_variable *path_vars,
  1803. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1804. {
  1805. struct ast_ari_channels_play_args args = {};
  1806. struct ast_variable *i;
  1807. #if defined(AST_DEVMODE)
  1808. int is_valid;
  1809. int code;
  1810. #endif /* AST_DEVMODE */
  1811. for (i = get_params; i; i = i->next) {
  1812. if (strcmp(i->name, "media") == 0) {
  1813. /* Parse comma separated list */
  1814. char *vals[MAX_VALS];
  1815. size_t j;
  1816. args.media_parse = ast_strdup(i->value);
  1817. if (!args.media_parse) {
  1818. ast_ari_response_alloc_failed(response);
  1819. goto fin;
  1820. }
  1821. if (strlen(args.media_parse) == 0) {
  1822. /* ast_app_separate_args can't handle "" */
  1823. args.media_count = 1;
  1824. vals[0] = args.media_parse;
  1825. } else {
  1826. args.media_count = ast_app_separate_args(
  1827. args.media_parse, ',', vals,
  1828. ARRAY_LEN(vals));
  1829. }
  1830. if (args.media_count == 0) {
  1831. ast_ari_response_alloc_failed(response);
  1832. goto fin;
  1833. }
  1834. if (args.media_count >= MAX_VALS) {
  1835. ast_ari_response_error(response, 400,
  1836. "Bad Request",
  1837. "Too many values for media");
  1838. goto fin;
  1839. }
  1840. args.media = ast_malloc(sizeof(*args.media) * args.media_count);
  1841. if (!args.media) {
  1842. ast_ari_response_alloc_failed(response);
  1843. goto fin;
  1844. }
  1845. for (j = 0; j < args.media_count; ++j) {
  1846. args.media[j] = (vals[j]);
  1847. }
  1848. } else
  1849. if (strcmp(i->name, "lang") == 0) {
  1850. args.lang = (i->value);
  1851. } else
  1852. if (strcmp(i->name, "offsetms") == 0) {
  1853. args.offsetms = atoi(i->value);
  1854. } else
  1855. if (strcmp(i->name, "skipms") == 0) {
  1856. args.skipms = atoi(i->value);
  1857. } else
  1858. if (strcmp(i->name, "playbackId") == 0) {
  1859. args.playback_id = (i->value);
  1860. } else
  1861. {}
  1862. }
  1863. for (i = path_vars; i; i = i->next) {
  1864. if (strcmp(i->name, "channelId") == 0) {
  1865. args.channel_id = (i->value);
  1866. } else
  1867. {}
  1868. }
  1869. if (ast_ari_channels_play_parse_body(body, &args)) {
  1870. ast_ari_response_alloc_failed(response);
  1871. goto fin;
  1872. }
  1873. ast_ari_channels_play(headers, &args, response);
  1874. #if defined(AST_DEVMODE)
  1875. code = response->response_code;
  1876. switch (code) {
  1877. case 0: /* Implementation is still a stub, or the code wasn't set */
  1878. is_valid = response->message == NULL;
  1879. break;
  1880. case 500: /* Internal Server Error */
  1881. case 501: /* Not Implemented */
  1882. case 404: /* Channel not found */
  1883. case 409: /* Channel not in a Stasis application */
  1884. case 412: /* Channel in invalid state */
  1885. is_valid = 1;
  1886. break;
  1887. default:
  1888. if (200 <= code && code <= 299) {
  1889. is_valid = ast_ari_validate_playback(
  1890. response->message);
  1891. } else {
  1892. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/play\n", code);
  1893. is_valid = 0;
  1894. }
  1895. }
  1896. if (!is_valid) {
  1897. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/play\n");
  1898. ast_ari_response_error(response, 500,
  1899. "Internal Server Error", "Response validation failed");
  1900. }
  1901. #endif /* AST_DEVMODE */
  1902. fin: __attribute__((unused))
  1903. ast_free(args.media_parse);
  1904. ast_free(args.media);
  1905. return;
  1906. }
  1907. int ast_ari_channels_play_with_id_parse_body(
  1908. struct ast_json *body,
  1909. struct ast_ari_channels_play_with_id_args *args)
  1910. {
  1911. struct ast_json *field;
  1912. /* Parse query parameters out of it */
  1913. field = ast_json_object_get(body, "media");
  1914. if (field) {
  1915. /* If they were silly enough to both pass in a query param and a
  1916. * JSON body, free up the query value.
  1917. */
  1918. ast_free(args->media);
  1919. if (ast_json_typeof(field) == AST_JSON_ARRAY) {
  1920. /* Multiple param passed as array */
  1921. size_t i;
  1922. args->media_count = ast_json_array_size(field);
  1923. args->media = ast_malloc(sizeof(*args->media) * args->media_count);
  1924. if (!args->media) {
  1925. return -1;
  1926. }
  1927. for (i = 0; i < args->media_count; ++i) {
  1928. args->media[i] = ast_json_string_get(ast_json_array_get(field, i));
  1929. }
  1930. } else {
  1931. /* Multiple param passed as single value */
  1932. args->media_count = 1;
  1933. args->media = ast_malloc(sizeof(*args->media) * args->media_count);
  1934. if (!args->media) {
  1935. return -1;
  1936. }
  1937. args->media[0] = ast_json_string_get(field);
  1938. }
  1939. }
  1940. field = ast_json_object_get(body, "lang");
  1941. if (field) {
  1942. args->lang = ast_json_string_get(field);
  1943. }
  1944. field = ast_json_object_get(body, "offsetms");
  1945. if (field) {
  1946. args->offsetms = ast_json_integer_get(field);
  1947. }
  1948. field = ast_json_object_get(body, "skipms");
  1949. if (field) {
  1950. args->skipms = ast_json_integer_get(field);
  1951. }
  1952. return 0;
  1953. }
  1954. /*!
  1955. * \brief Parameter parsing callback for /channels/{channelId}/play/{playbackId}.
  1956. * \param ser TCP/TLS session object
  1957. * \param get_params GET parameters in the HTTP request.
  1958. * \param path_vars Path variables extracted from the request.
  1959. * \param headers HTTP headers.
  1960. * \param body
  1961. * \param[out] response Response to the HTTP request.
  1962. */
  1963. static void ast_ari_channels_play_with_id_cb(
  1964. struct ast_tcptls_session_instance *ser,
  1965. struct ast_variable *get_params, struct ast_variable *path_vars,
  1966. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  1967. {
  1968. struct ast_ari_channels_play_with_id_args args = {};
  1969. struct ast_variable *i;
  1970. #if defined(AST_DEVMODE)
  1971. int is_valid;
  1972. int code;
  1973. #endif /* AST_DEVMODE */
  1974. for (i = get_params; i; i = i->next) {
  1975. if (strcmp(i->name, "media") == 0) {
  1976. /* Parse comma separated list */
  1977. char *vals[MAX_VALS];
  1978. size_t j;
  1979. args.media_parse = ast_strdup(i->value);
  1980. if (!args.media_parse) {
  1981. ast_ari_response_alloc_failed(response);
  1982. goto fin;
  1983. }
  1984. if (strlen(args.media_parse) == 0) {
  1985. /* ast_app_separate_args can't handle "" */
  1986. args.media_count = 1;
  1987. vals[0] = args.media_parse;
  1988. } else {
  1989. args.media_count = ast_app_separate_args(
  1990. args.media_parse, ',', vals,
  1991. ARRAY_LEN(vals));
  1992. }
  1993. if (args.media_count == 0) {
  1994. ast_ari_response_alloc_failed(response);
  1995. goto fin;
  1996. }
  1997. if (args.media_count >= MAX_VALS) {
  1998. ast_ari_response_error(response, 400,
  1999. "Bad Request",
  2000. "Too many values for media");
  2001. goto fin;
  2002. }
  2003. args.media = ast_malloc(sizeof(*args.media) * args.media_count);
  2004. if (!args.media) {
  2005. ast_ari_response_alloc_failed(response);
  2006. goto fin;
  2007. }
  2008. for (j = 0; j < args.media_count; ++j) {
  2009. args.media[j] = (vals[j]);
  2010. }
  2011. } else
  2012. if (strcmp(i->name, "lang") == 0) {
  2013. args.lang = (i->value);
  2014. } else
  2015. if (strcmp(i->name, "offsetms") == 0) {
  2016. args.offsetms = atoi(i->value);
  2017. } else
  2018. if (strcmp(i->name, "skipms") == 0) {
  2019. args.skipms = atoi(i->value);
  2020. } else
  2021. {}
  2022. }
  2023. for (i = path_vars; i; i = i->next) {
  2024. if (strcmp(i->name, "channelId") == 0) {
  2025. args.channel_id = (i->value);
  2026. } else
  2027. if (strcmp(i->name, "playbackId") == 0) {
  2028. args.playback_id = (i->value);
  2029. } else
  2030. {}
  2031. }
  2032. if (ast_ari_channels_play_with_id_parse_body(body, &args)) {
  2033. ast_ari_response_alloc_failed(response);
  2034. goto fin;
  2035. }
  2036. ast_ari_channels_play_with_id(headers, &args, response);
  2037. #if defined(AST_DEVMODE)
  2038. code = response->response_code;
  2039. switch (code) {
  2040. case 0: /* Implementation is still a stub, or the code wasn't set */
  2041. is_valid = response->message == NULL;
  2042. break;
  2043. case 500: /* Internal Server Error */
  2044. case 501: /* Not Implemented */
  2045. case 404: /* Channel not found */
  2046. case 409: /* Channel not in a Stasis application */
  2047. case 412: /* Channel in invalid state */
  2048. is_valid = 1;
  2049. break;
  2050. default:
  2051. if (200 <= code && code <= 299) {
  2052. is_valid = ast_ari_validate_playback(
  2053. response->message);
  2054. } else {
  2055. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/play/{playbackId}\n", code);
  2056. is_valid = 0;
  2057. }
  2058. }
  2059. if (!is_valid) {
  2060. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/play/{playbackId}\n");
  2061. ast_ari_response_error(response, 500,
  2062. "Internal Server Error", "Response validation failed");
  2063. }
  2064. #endif /* AST_DEVMODE */
  2065. fin: __attribute__((unused))
  2066. ast_free(args.media_parse);
  2067. ast_free(args.media);
  2068. return;
  2069. }
  2070. int ast_ari_channels_record_parse_body(
  2071. struct ast_json *body,
  2072. struct ast_ari_channels_record_args *args)
  2073. {
  2074. struct ast_json *field;
  2075. /* Parse query parameters out of it */
  2076. field = ast_json_object_get(body, "name");
  2077. if (field) {
  2078. args->name = ast_json_string_get(field);
  2079. }
  2080. field = ast_json_object_get(body, "format");
  2081. if (field) {
  2082. args->format = ast_json_string_get(field);
  2083. }
  2084. field = ast_json_object_get(body, "maxDurationSeconds");
  2085. if (field) {
  2086. args->max_duration_seconds = ast_json_integer_get(field);
  2087. }
  2088. field = ast_json_object_get(body, "maxSilenceSeconds");
  2089. if (field) {
  2090. args->max_silence_seconds = ast_json_integer_get(field);
  2091. }
  2092. field = ast_json_object_get(body, "ifExists");
  2093. if (field) {
  2094. args->if_exists = ast_json_string_get(field);
  2095. }
  2096. field = ast_json_object_get(body, "beep");
  2097. if (field) {
  2098. args->beep = ast_json_is_true(field);
  2099. }
  2100. field = ast_json_object_get(body, "terminateOn");
  2101. if (field) {
  2102. args->terminate_on = ast_json_string_get(field);
  2103. }
  2104. return 0;
  2105. }
  2106. /*!
  2107. * \brief Parameter parsing callback for /channels/{channelId}/record.
  2108. * \param ser TCP/TLS session object
  2109. * \param get_params GET parameters in the HTTP request.
  2110. * \param path_vars Path variables extracted from the request.
  2111. * \param headers HTTP headers.
  2112. * \param body
  2113. * \param[out] response Response to the HTTP request.
  2114. */
  2115. static void ast_ari_channels_record_cb(
  2116. struct ast_tcptls_session_instance *ser,
  2117. struct ast_variable *get_params, struct ast_variable *path_vars,
  2118. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  2119. {
  2120. struct ast_ari_channels_record_args args = {};
  2121. struct ast_variable *i;
  2122. #if defined(AST_DEVMODE)
  2123. int is_valid;
  2124. int code;
  2125. #endif /* AST_DEVMODE */
  2126. for (i = get_params; i; i = i->next) {
  2127. if (strcmp(i->name, "name") == 0) {
  2128. args.name = (i->value);
  2129. } else
  2130. if (strcmp(i->name, "format") == 0) {
  2131. args.format = (i->value);
  2132. } else
  2133. if (strcmp(i->name, "maxDurationSeconds") == 0) {
  2134. args.max_duration_seconds = atoi(i->value);
  2135. } else
  2136. if (strcmp(i->name, "maxSilenceSeconds") == 0) {
  2137. args.max_silence_seconds = atoi(i->value);
  2138. } else
  2139. if (strcmp(i->name, "ifExists") == 0) {
  2140. args.if_exists = (i->value);
  2141. } else
  2142. if (strcmp(i->name, "beep") == 0) {
  2143. args.beep = ast_true(i->value);
  2144. } else
  2145. if (strcmp(i->name, "terminateOn") == 0) {
  2146. args.terminate_on = (i->value);
  2147. } else
  2148. {}
  2149. }
  2150. for (i = path_vars; i; i = i->next) {
  2151. if (strcmp(i->name, "channelId") == 0) {
  2152. args.channel_id = (i->value);
  2153. } else
  2154. {}
  2155. }
  2156. if (ast_ari_channels_record_parse_body(body, &args)) {
  2157. ast_ari_response_alloc_failed(response);
  2158. goto fin;
  2159. }
  2160. ast_ari_channels_record(headers, &args, response);
  2161. #if defined(AST_DEVMODE)
  2162. code = response->response_code;
  2163. switch (code) {
  2164. case 0: /* Implementation is still a stub, or the code wasn't set */
  2165. is_valid = response->message == NULL;
  2166. break;
  2167. case 500: /* Internal Server Error */
  2168. case 501: /* Not Implemented */
  2169. case 400: /* Invalid parameters */
  2170. case 404: /* Channel not found */
  2171. 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 */
  2172. case 422: /* The format specified is unknown on this system */
  2173. is_valid = 1;
  2174. break;
  2175. default:
  2176. if (200 <= code && code <= 299) {
  2177. is_valid = ast_ari_validate_live_recording(
  2178. response->message);
  2179. } else {
  2180. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/record\n", code);
  2181. is_valid = 0;
  2182. }
  2183. }
  2184. if (!is_valid) {
  2185. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/record\n");
  2186. ast_ari_response_error(response, 500,
  2187. "Internal Server Error", "Response validation failed");
  2188. }
  2189. #endif /* AST_DEVMODE */
  2190. fin: __attribute__((unused))
  2191. return;
  2192. }
  2193. int ast_ari_channels_get_channel_var_parse_body(
  2194. struct ast_json *body,
  2195. struct ast_ari_channels_get_channel_var_args *args)
  2196. {
  2197. struct ast_json *field;
  2198. /* Parse query parameters out of it */
  2199. field = ast_json_object_get(body, "variable");
  2200. if (field) {
  2201. args->variable = ast_json_string_get(field);
  2202. }
  2203. return 0;
  2204. }
  2205. /*!
  2206. * \brief Parameter parsing callback for /channels/{channelId}/variable.
  2207. * \param ser TCP/TLS session object
  2208. * \param get_params GET parameters in the HTTP request.
  2209. * \param path_vars Path variables extracted from the request.
  2210. * \param headers HTTP headers.
  2211. * \param body
  2212. * \param[out] response Response to the HTTP request.
  2213. */
  2214. static void ast_ari_channels_get_channel_var_cb(
  2215. struct ast_tcptls_session_instance *ser,
  2216. struct ast_variable *get_params, struct ast_variable *path_vars,
  2217. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  2218. {
  2219. struct ast_ari_channels_get_channel_var_args args = {};
  2220. struct ast_variable *i;
  2221. #if defined(AST_DEVMODE)
  2222. int is_valid;
  2223. int code;
  2224. #endif /* AST_DEVMODE */
  2225. for (i = get_params; i; i = i->next) {
  2226. if (strcmp(i->name, "variable") == 0) {
  2227. args.variable = (i->value);
  2228. } else
  2229. {}
  2230. }
  2231. for (i = path_vars; i; i = i->next) {
  2232. if (strcmp(i->name, "channelId") == 0) {
  2233. args.channel_id = (i->value);
  2234. } else
  2235. {}
  2236. }
  2237. if (ast_ari_channels_get_channel_var_parse_body(body, &args)) {
  2238. ast_ari_response_alloc_failed(response);
  2239. goto fin;
  2240. }
  2241. ast_ari_channels_get_channel_var(headers, &args, response);
  2242. #if defined(AST_DEVMODE)
  2243. code = response->response_code;
  2244. switch (code) {
  2245. case 0: /* Implementation is still a stub, or the code wasn't set */
  2246. is_valid = response->message == NULL;
  2247. break;
  2248. case 500: /* Internal Server Error */
  2249. case 501: /* Not Implemented */
  2250. case 400: /* Missing variable parameter. */
  2251. case 404: /* Channel or variable not found */
  2252. case 409: /* Channel not in a Stasis application */
  2253. is_valid = 1;
  2254. break;
  2255. default:
  2256. if (200 <= code && code <= 299) {
  2257. is_valid = ast_ari_validate_variable(
  2258. response->message);
  2259. } else {
  2260. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
  2261. is_valid = 0;
  2262. }
  2263. }
  2264. if (!is_valid) {
  2265. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
  2266. ast_ari_response_error(response, 500,
  2267. "Internal Server Error", "Response validation failed");
  2268. }
  2269. #endif /* AST_DEVMODE */
  2270. fin: __attribute__((unused))
  2271. return;
  2272. }
  2273. int ast_ari_channels_set_channel_var_parse_body(
  2274. struct ast_json *body,
  2275. struct ast_ari_channels_set_channel_var_args *args)
  2276. {
  2277. struct ast_json *field;
  2278. /* Parse query parameters out of it */
  2279. field = ast_json_object_get(body, "variable");
  2280. if (field) {
  2281. args->variable = ast_json_string_get(field);
  2282. }
  2283. field = ast_json_object_get(body, "value");
  2284. if (field) {
  2285. args->value = ast_json_string_get(field);
  2286. }
  2287. return 0;
  2288. }
  2289. /*!
  2290. * \brief Parameter parsing callback for /channels/{channelId}/variable.
  2291. * \param ser TCP/TLS session object
  2292. * \param get_params GET parameters in the HTTP request.
  2293. * \param path_vars Path variables extracted from the request.
  2294. * \param headers HTTP headers.
  2295. * \param body
  2296. * \param[out] response Response to the HTTP request.
  2297. */
  2298. static void ast_ari_channels_set_channel_var_cb(
  2299. struct ast_tcptls_session_instance *ser,
  2300. struct ast_variable *get_params, struct ast_variable *path_vars,
  2301. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  2302. {
  2303. struct ast_ari_channels_set_channel_var_args args = {};
  2304. struct ast_variable *i;
  2305. #if defined(AST_DEVMODE)
  2306. int is_valid;
  2307. int code;
  2308. #endif /* AST_DEVMODE */
  2309. for (i = get_params; i; i = i->next) {
  2310. if (strcmp(i->name, "variable") == 0) {
  2311. args.variable = (i->value);
  2312. } else
  2313. if (strcmp(i->name, "value") == 0) {
  2314. args.value = (i->value);
  2315. } else
  2316. {}
  2317. }
  2318. for (i = path_vars; i; i = i->next) {
  2319. if (strcmp(i->name, "channelId") == 0) {
  2320. args.channel_id = (i->value);
  2321. } else
  2322. {}
  2323. }
  2324. if (ast_ari_channels_set_channel_var_parse_body(body, &args)) {
  2325. ast_ari_response_alloc_failed(response);
  2326. goto fin;
  2327. }
  2328. ast_ari_channels_set_channel_var(headers, &args, response);
  2329. #if defined(AST_DEVMODE)
  2330. code = response->response_code;
  2331. switch (code) {
  2332. case 0: /* Implementation is still a stub, or the code wasn't set */
  2333. is_valid = response->message == NULL;
  2334. break;
  2335. case 500: /* Internal Server Error */
  2336. case 501: /* Not Implemented */
  2337. case 400: /* Missing variable parameter. */
  2338. case 404: /* Channel not found */
  2339. case 409: /* Channel not in a Stasis application */
  2340. is_valid = 1;
  2341. break;
  2342. default:
  2343. if (200 <= code && code <= 299) {
  2344. is_valid = ast_ari_validate_void(
  2345. response->message);
  2346. } else {
  2347. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
  2348. is_valid = 0;
  2349. }
  2350. }
  2351. if (!is_valid) {
  2352. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
  2353. ast_ari_response_error(response, 500,
  2354. "Internal Server Error", "Response validation failed");
  2355. }
  2356. #endif /* AST_DEVMODE */
  2357. fin: __attribute__((unused))
  2358. return;
  2359. }
  2360. int ast_ari_channels_snoop_channel_parse_body(
  2361. struct ast_json *body,
  2362. struct ast_ari_channels_snoop_channel_args *args)
  2363. {
  2364. struct ast_json *field;
  2365. /* Parse query parameters out of it */
  2366. field = ast_json_object_get(body, "spy");
  2367. if (field) {
  2368. args->spy = ast_json_string_get(field);
  2369. }
  2370. field = ast_json_object_get(body, "whisper");
  2371. if (field) {
  2372. args->whisper = ast_json_string_get(field);
  2373. }
  2374. field = ast_json_object_get(body, "app");
  2375. if (field) {
  2376. args->app = ast_json_string_get(field);
  2377. }
  2378. field = ast_json_object_get(body, "appArgs");
  2379. if (field) {
  2380. args->app_args = ast_json_string_get(field);
  2381. }
  2382. field = ast_json_object_get(body, "snoopId");
  2383. if (field) {
  2384. args->snoop_id = ast_json_string_get(field);
  2385. }
  2386. return 0;
  2387. }
  2388. /*!
  2389. * \brief Parameter parsing callback for /channels/{channelId}/snoop.
  2390. * \param ser TCP/TLS session object
  2391. * \param get_params GET parameters in the HTTP request.
  2392. * \param path_vars Path variables extracted from the request.
  2393. * \param headers HTTP headers.
  2394. * \param body
  2395. * \param[out] response Response to the HTTP request.
  2396. */
  2397. static void ast_ari_channels_snoop_channel_cb(
  2398. struct ast_tcptls_session_instance *ser,
  2399. struct ast_variable *get_params, struct ast_variable *path_vars,
  2400. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  2401. {
  2402. struct ast_ari_channels_snoop_channel_args args = {};
  2403. struct ast_variable *i;
  2404. #if defined(AST_DEVMODE)
  2405. int is_valid;
  2406. int code;
  2407. #endif /* AST_DEVMODE */
  2408. for (i = get_params; i; i = i->next) {
  2409. if (strcmp(i->name, "spy") == 0) {
  2410. args.spy = (i->value);
  2411. } else
  2412. if (strcmp(i->name, "whisper") == 0) {
  2413. args.whisper = (i->value);
  2414. } else
  2415. if (strcmp(i->name, "app") == 0) {
  2416. args.app = (i->value);
  2417. } else
  2418. if (strcmp(i->name, "appArgs") == 0) {
  2419. args.app_args = (i->value);
  2420. } else
  2421. if (strcmp(i->name, "snoopId") == 0) {
  2422. args.snoop_id = (i->value);
  2423. } else
  2424. {}
  2425. }
  2426. for (i = path_vars; i; i = i->next) {
  2427. if (strcmp(i->name, "channelId") == 0) {
  2428. args.channel_id = (i->value);
  2429. } else
  2430. {}
  2431. }
  2432. if (ast_ari_channels_snoop_channel_parse_body(body, &args)) {
  2433. ast_ari_response_alloc_failed(response);
  2434. goto fin;
  2435. }
  2436. ast_ari_channels_snoop_channel(headers, &args, response);
  2437. #if defined(AST_DEVMODE)
  2438. code = response->response_code;
  2439. switch (code) {
  2440. case 0: /* Implementation is still a stub, or the code wasn't set */
  2441. is_valid = response->message == NULL;
  2442. break;
  2443. case 500: /* Internal Server Error */
  2444. case 501: /* Not Implemented */
  2445. case 400: /* Invalid parameters */
  2446. case 404: /* Channel not found */
  2447. is_valid = 1;
  2448. break;
  2449. default:
  2450. if (200 <= code && code <= 299) {
  2451. is_valid = ast_ari_validate_channel(
  2452. response->message);
  2453. } else {
  2454. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/snoop\n", code);
  2455. is_valid = 0;
  2456. }
  2457. }
  2458. if (!is_valid) {
  2459. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/snoop\n");
  2460. ast_ari_response_error(response, 500,
  2461. "Internal Server Error", "Response validation failed");
  2462. }
  2463. #endif /* AST_DEVMODE */
  2464. fin: __attribute__((unused))
  2465. return;
  2466. }
  2467. int ast_ari_channels_snoop_channel_with_id_parse_body(
  2468. struct ast_json *body,
  2469. struct ast_ari_channels_snoop_channel_with_id_args *args)
  2470. {
  2471. struct ast_json *field;
  2472. /* Parse query parameters out of it */
  2473. field = ast_json_object_get(body, "spy");
  2474. if (field) {
  2475. args->spy = ast_json_string_get(field);
  2476. }
  2477. field = ast_json_object_get(body, "whisper");
  2478. if (field) {
  2479. args->whisper = ast_json_string_get(field);
  2480. }
  2481. field = ast_json_object_get(body, "app");
  2482. if (field) {
  2483. args->app = ast_json_string_get(field);
  2484. }
  2485. field = ast_json_object_get(body, "appArgs");
  2486. if (field) {
  2487. args->app_args = ast_json_string_get(field);
  2488. }
  2489. return 0;
  2490. }
  2491. /*!
  2492. * \brief Parameter parsing callback for /channels/{channelId}/snoop/{snoopId}.
  2493. * \param ser TCP/TLS session object
  2494. * \param get_params GET parameters in the HTTP request.
  2495. * \param path_vars Path variables extracted from the request.
  2496. * \param headers HTTP headers.
  2497. * \param body
  2498. * \param[out] response Response to the HTTP request.
  2499. */
  2500. static void ast_ari_channels_snoop_channel_with_id_cb(
  2501. struct ast_tcptls_session_instance *ser,
  2502. struct ast_variable *get_params, struct ast_variable *path_vars,
  2503. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  2504. {
  2505. struct ast_ari_channels_snoop_channel_with_id_args args = {};
  2506. struct ast_variable *i;
  2507. #if defined(AST_DEVMODE)
  2508. int is_valid;
  2509. int code;
  2510. #endif /* AST_DEVMODE */
  2511. for (i = get_params; i; i = i->next) {
  2512. if (strcmp(i->name, "spy") == 0) {
  2513. args.spy = (i->value);
  2514. } else
  2515. if (strcmp(i->name, "whisper") == 0) {
  2516. args.whisper = (i->value);
  2517. } else
  2518. if (strcmp(i->name, "app") == 0) {
  2519. args.app = (i->value);
  2520. } else
  2521. if (strcmp(i->name, "appArgs") == 0) {
  2522. args.app_args = (i->value);
  2523. } else
  2524. {}
  2525. }
  2526. for (i = path_vars; i; i = i->next) {
  2527. if (strcmp(i->name, "channelId") == 0) {
  2528. args.channel_id = (i->value);
  2529. } else
  2530. if (strcmp(i->name, "snoopId") == 0) {
  2531. args.snoop_id = (i->value);
  2532. } else
  2533. {}
  2534. }
  2535. if (ast_ari_channels_snoop_channel_with_id_parse_body(body, &args)) {
  2536. ast_ari_response_alloc_failed(response);
  2537. goto fin;
  2538. }
  2539. ast_ari_channels_snoop_channel_with_id(headers, &args, response);
  2540. #if defined(AST_DEVMODE)
  2541. code = response->response_code;
  2542. switch (code) {
  2543. case 0: /* Implementation is still a stub, or the code wasn't set */
  2544. is_valid = response->message == NULL;
  2545. break;
  2546. case 500: /* Internal Server Error */
  2547. case 501: /* Not Implemented */
  2548. case 400: /* Invalid parameters */
  2549. case 404: /* Channel not found */
  2550. is_valid = 1;
  2551. break;
  2552. default:
  2553. if (200 <= code && code <= 299) {
  2554. is_valid = ast_ari_validate_channel(
  2555. response->message);
  2556. } else {
  2557. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/snoop/{snoopId}\n", code);
  2558. is_valid = 0;
  2559. }
  2560. }
  2561. if (!is_valid) {
  2562. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/snoop/{snoopId}\n");
  2563. ast_ari_response_error(response, 500,
  2564. "Internal Server Error", "Response validation failed");
  2565. }
  2566. #endif /* AST_DEVMODE */
  2567. fin: __attribute__((unused))
  2568. return;
  2569. }
  2570. int ast_ari_channels_dial_parse_body(
  2571. struct ast_json *body,
  2572. struct ast_ari_channels_dial_args *args)
  2573. {
  2574. struct ast_json *field;
  2575. /* Parse query parameters out of it */
  2576. field = ast_json_object_get(body, "caller");
  2577. if (field) {
  2578. args->caller = ast_json_string_get(field);
  2579. }
  2580. field = ast_json_object_get(body, "timeout");
  2581. if (field) {
  2582. args->timeout = ast_json_integer_get(field);
  2583. }
  2584. return 0;
  2585. }
  2586. /*!
  2587. * \brief Parameter parsing callback for /channels/{channelId}/dial.
  2588. * \param ser TCP/TLS session object
  2589. * \param get_params GET parameters in the HTTP request.
  2590. * \param path_vars Path variables extracted from the request.
  2591. * \param headers HTTP headers.
  2592. * \param body
  2593. * \param[out] response Response to the HTTP request.
  2594. */
  2595. static void ast_ari_channels_dial_cb(
  2596. struct ast_tcptls_session_instance *ser,
  2597. struct ast_variable *get_params, struct ast_variable *path_vars,
  2598. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  2599. {
  2600. struct ast_ari_channels_dial_args args = {};
  2601. struct ast_variable *i;
  2602. #if defined(AST_DEVMODE)
  2603. int is_valid;
  2604. int code;
  2605. #endif /* AST_DEVMODE */
  2606. for (i = get_params; i; i = i->next) {
  2607. if (strcmp(i->name, "caller") == 0) {
  2608. args.caller = (i->value);
  2609. } else
  2610. if (strcmp(i->name, "timeout") == 0) {
  2611. args.timeout = atoi(i->value);
  2612. } else
  2613. {}
  2614. }
  2615. for (i = path_vars; i; i = i->next) {
  2616. if (strcmp(i->name, "channelId") == 0) {
  2617. args.channel_id = (i->value);
  2618. } else
  2619. {}
  2620. }
  2621. if (ast_ari_channels_dial_parse_body(body, &args)) {
  2622. ast_ari_response_alloc_failed(response);
  2623. goto fin;
  2624. }
  2625. ast_ari_channels_dial(headers, &args, response);
  2626. #if defined(AST_DEVMODE)
  2627. code = response->response_code;
  2628. switch (code) {
  2629. case 0: /* Implementation is still a stub, or the code wasn't set */
  2630. is_valid = response->message == NULL;
  2631. break;
  2632. case 500: /* Internal Server Error */
  2633. case 501: /* Not Implemented */
  2634. case 404: /* Channel cannot be found. */
  2635. case 409: /* Channel cannot be dialed. */
  2636. is_valid = 1;
  2637. break;
  2638. default:
  2639. if (200 <= code && code <= 299) {
  2640. is_valid = ast_ari_validate_void(
  2641. response->message);
  2642. } else {
  2643. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/dial\n", code);
  2644. is_valid = 0;
  2645. }
  2646. }
  2647. if (!is_valid) {
  2648. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/dial\n");
  2649. ast_ari_response_error(response, 500,
  2650. "Internal Server Error", "Response validation failed");
  2651. }
  2652. #endif /* AST_DEVMODE */
  2653. fin: __attribute__((unused))
  2654. return;
  2655. }
  2656. /*!
  2657. * \brief Parameter parsing callback for /channels/{channelId}/rtp_statistics.
  2658. * \param ser TCP/TLS session object
  2659. * \param get_params GET parameters in the HTTP request.
  2660. * \param path_vars Path variables extracted from the request.
  2661. * \param headers HTTP headers.
  2662. * \param body
  2663. * \param[out] response Response to the HTTP request.
  2664. */
  2665. static void ast_ari_channels_rtpstatistics_cb(
  2666. struct ast_tcptls_session_instance *ser,
  2667. struct ast_variable *get_params, struct ast_variable *path_vars,
  2668. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  2669. {
  2670. struct ast_ari_channels_rtpstatistics_args args = {};
  2671. struct ast_variable *i;
  2672. #if defined(AST_DEVMODE)
  2673. int is_valid;
  2674. int code;
  2675. #endif /* AST_DEVMODE */
  2676. for (i = path_vars; i; i = i->next) {
  2677. if (strcmp(i->name, "channelId") == 0) {
  2678. args.channel_id = (i->value);
  2679. } else
  2680. {}
  2681. }
  2682. ast_ari_channels_rtpstatistics(headers, &args, response);
  2683. #if defined(AST_DEVMODE)
  2684. code = response->response_code;
  2685. switch (code) {
  2686. case 0: /* Implementation is still a stub, or the code wasn't set */
  2687. is_valid = response->message == NULL;
  2688. break;
  2689. case 500: /* Internal Server Error */
  2690. case 501: /* Not Implemented */
  2691. case 404: /* Channel cannot be found. */
  2692. is_valid = 1;
  2693. break;
  2694. default:
  2695. if (200 <= code && code <= 299) {
  2696. is_valid = ast_ari_validate_rtpstat(
  2697. response->message);
  2698. } else {
  2699. ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/rtp_statistics\n", code);
  2700. is_valid = 0;
  2701. }
  2702. }
  2703. if (!is_valid) {
  2704. ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/rtp_statistics\n");
  2705. ast_ari_response_error(response, 500,
  2706. "Internal Server Error", "Response validation failed");
  2707. }
  2708. #endif /* AST_DEVMODE */
  2709. fin: __attribute__((unused))
  2710. return;
  2711. }
  2712. int ast_ari_channels_external_media_parse_body(
  2713. struct ast_json *body,
  2714. struct ast_ari_channels_external_media_args *args)
  2715. {
  2716. struct ast_json *field;
  2717. /* Parse query parameters out of it */
  2718. field = ast_json_object_get(body, "channelId");
  2719. if (field) {
  2720. args->channel_id = ast_json_string_get(field);
  2721. }
  2722. field = ast_json_object_get(body, "app");
  2723. if (field) {
  2724. args->app = ast_json_string_get(field);
  2725. }
  2726. field = ast_json_object_get(body, "external_host");
  2727. if (field) {
  2728. args->external_host = ast_json_string_get(field);
  2729. }
  2730. field = ast_json_object_get(body, "encapsulation");
  2731. if (field) {
  2732. args->encapsulation = ast_json_string_get(field);
  2733. }
  2734. field = ast_json_object_get(body, "transport");
  2735. if (field) {
  2736. args->transport = ast_json_string_get(field);
  2737. }
  2738. field = ast_json_object_get(body, "connection_type");
  2739. if (field) {
  2740. args->connection_type = ast_json_string_get(field);
  2741. }
  2742. field = ast_json_object_get(body, "format");
  2743. if (field) {
  2744. args->format = ast_json_string_get(field);
  2745. }
  2746. field = ast_json_object_get(body, "direction");
  2747. if (field) {
  2748. args->direction = ast_json_string_get(field);
  2749. }
  2750. field = ast_json_object_get(body, "data");
  2751. if (field) {
  2752. args->data = ast_json_string_get(field);
  2753. }
  2754. return 0;
  2755. }
  2756. /*!
  2757. * \brief Parameter parsing callback for /channels/externalMedia.
  2758. * \param ser TCP/TLS session object
  2759. * \param get_params GET parameters in the HTTP request.
  2760. * \param path_vars Path variables extracted from the request.
  2761. * \param headers HTTP headers.
  2762. * \param body
  2763. * \param[out] response Response to the HTTP request.
  2764. */
  2765. static void ast_ari_channels_external_media_cb(
  2766. struct ast_tcptls_session_instance *ser,
  2767. struct ast_variable *get_params, struct ast_variable *path_vars,
  2768. struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
  2769. {
  2770. struct ast_ari_channels_external_media_args args = {};
  2771. struct ast_variable *i;
  2772. #if defined(AST_DEVMODE)
  2773. int is_valid;
  2774. int code;
  2775. #endif /* AST_DEVMODE */
  2776. for (i = get_params; i; i = i->next) {
  2777. if (strcmp(i->name, "channelId") == 0) {
  2778. args.channel_id = (i->value);
  2779. } else
  2780. if (strcmp(i->name, "app") == 0) {
  2781. args.app = (i->value);
  2782. } else
  2783. if (strcmp(i->name, "external_host") == 0) {
  2784. args.external_host = (i->value);
  2785. } else
  2786. if (strcmp(i->name, "encapsulation") == 0) {
  2787. args.encapsulation = (i->value);
  2788. } else
  2789. if (strcmp(i->name, "transport") == 0) {
  2790. args.transport = (i->value);
  2791. } else
  2792. if (strcmp(i->name, "connection_type") == 0) {
  2793. args.connection_type = (i->value);
  2794. } else
  2795. if (strcmp(i->name, "format") == 0) {
  2796. args.format = (i->value);
  2797. } else
  2798. if (strcmp(i->name, "direction") == 0) {
  2799. args.direction = (i->value);
  2800. } else
  2801. if (strcmp(i->name, "data") == 0) {
  2802. args.data = (i->value);
  2803. } else
  2804. {}
  2805. }
  2806. args.variables = body;
  2807. ast_ari_channels_external_media(headers, &args, response);
  2808. #if defined(AST_DEVMODE)
  2809. code = response->response_code;
  2810. switch (code) {
  2811. case 0: /* Implementation is still a stub, or the code wasn't set */
  2812. is_valid = response->message == NULL;
  2813. break;
  2814. case 500: /* Internal Server Error */
  2815. case 501: /* Not Implemented */
  2816. case 400: /* Invalid parameters */
  2817. case 409: /* Channel is not in a Stasis application; Channel is already bridged */
  2818. is_valid = 1;
  2819. break;
  2820. default:
  2821. if (200 <= code && code <= 299) {
  2822. is_valid = ast_ari_validate_channel(
  2823. response->message);
  2824. } else {
  2825. ast_log(LOG_ERROR, "Invalid error response %d for /channels/externalMedia\n", code);
  2826. is_valid = 0;
  2827. }
  2828. }
  2829. if (!is_valid) {
  2830. ast_log(LOG_ERROR, "Response validation failed for /channels/externalMedia\n");
  2831. ast_ari_response_error(response, 500,
  2832. "Internal Server Error", "Response validation failed");
  2833. }
  2834. #endif /* AST_DEVMODE */
  2835. fin: __attribute__((unused))
  2836. return;
  2837. }
  2838. /*! \brief REST handler for /api-docs/channels.json */
  2839. static struct stasis_rest_handlers channels_create = {
  2840. .path_segment = "create",
  2841. .callbacks = {
  2842. [AST_HTTP_POST] = ast_ari_channels_create_cb,
  2843. },
  2844. .num_children = 0,
  2845. .children = { }
  2846. };
  2847. /*! \brief REST handler for /api-docs/channels.json */
  2848. static struct stasis_rest_handlers channels_channelId_continue = {
  2849. .path_segment = "continue",
  2850. .callbacks = {
  2851. [AST_HTTP_POST] = ast_ari_channels_continue_in_dialplan_cb,
  2852. },
  2853. .num_children = 0,
  2854. .children = { }
  2855. };
  2856. /*! \brief REST handler for /api-docs/channels.json */
  2857. static struct stasis_rest_handlers channels_channelId_move = {
  2858. .path_segment = "move",
  2859. .callbacks = {
  2860. [AST_HTTP_POST] = ast_ari_channels_move_cb,
  2861. },
  2862. .num_children = 0,
  2863. .children = { }
  2864. };
  2865. /*! \brief REST handler for /api-docs/channels.json */
  2866. static struct stasis_rest_handlers channels_channelId_redirect = {
  2867. .path_segment = "redirect",
  2868. .callbacks = {
  2869. [AST_HTTP_POST] = ast_ari_channels_redirect_cb,
  2870. },
  2871. .num_children = 0,
  2872. .children = { }
  2873. };
  2874. /*! \brief REST handler for /api-docs/channels.json */
  2875. static struct stasis_rest_handlers channels_channelId_answer = {
  2876. .path_segment = "answer",
  2877. .callbacks = {
  2878. [AST_HTTP_POST] = ast_ari_channels_answer_cb,
  2879. },
  2880. .num_children = 0,
  2881. .children = { }
  2882. };
  2883. /*! \brief REST handler for /api-docs/channels.json */
  2884. static struct stasis_rest_handlers channels_channelId_ring = {
  2885. .path_segment = "ring",
  2886. .callbacks = {
  2887. [AST_HTTP_POST] = ast_ari_channels_ring_cb,
  2888. [AST_HTTP_DELETE] = ast_ari_channels_ring_stop_cb,
  2889. },
  2890. .num_children = 0,
  2891. .children = { }
  2892. };
  2893. /*! \brief REST handler for /api-docs/channels.json */
  2894. static struct stasis_rest_handlers channels_channelId_dtmf = {
  2895. .path_segment = "dtmf",
  2896. .callbacks = {
  2897. [AST_HTTP_POST] = ast_ari_channels_send_dtmf_cb,
  2898. },
  2899. .num_children = 0,
  2900. .children = { }
  2901. };
  2902. /*! \brief REST handler for /api-docs/channels.json */
  2903. static struct stasis_rest_handlers channels_channelId_mute = {
  2904. .path_segment = "mute",
  2905. .callbacks = {
  2906. [AST_HTTP_POST] = ast_ari_channels_mute_cb,
  2907. [AST_HTTP_DELETE] = ast_ari_channels_unmute_cb,
  2908. },
  2909. .num_children = 0,
  2910. .children = { }
  2911. };
  2912. /*! \brief REST handler for /api-docs/channels.json */
  2913. static struct stasis_rest_handlers channels_channelId_hold = {
  2914. .path_segment = "hold",
  2915. .callbacks = {
  2916. [AST_HTTP_POST] = ast_ari_channels_hold_cb,
  2917. [AST_HTTP_DELETE] = ast_ari_channels_unhold_cb,
  2918. },
  2919. .num_children = 0,
  2920. .children = { }
  2921. };
  2922. /*! \brief REST handler for /api-docs/channels.json */
  2923. static struct stasis_rest_handlers channels_channelId_moh = {
  2924. .path_segment = "moh",
  2925. .callbacks = {
  2926. [AST_HTTP_POST] = ast_ari_channels_start_moh_cb,
  2927. [AST_HTTP_DELETE] = ast_ari_channels_stop_moh_cb,
  2928. },
  2929. .num_children = 0,
  2930. .children = { }
  2931. };
  2932. /*! \brief REST handler for /api-docs/channels.json */
  2933. static struct stasis_rest_handlers channels_channelId_silence = {
  2934. .path_segment = "silence",
  2935. .callbacks = {
  2936. [AST_HTTP_POST] = ast_ari_channels_start_silence_cb,
  2937. [AST_HTTP_DELETE] = ast_ari_channels_stop_silence_cb,
  2938. },
  2939. .num_children = 0,
  2940. .children = { }
  2941. };
  2942. /*! \brief REST handler for /api-docs/channels.json */
  2943. static struct stasis_rest_handlers channels_channelId_play_playbackId = {
  2944. .path_segment = "playbackId",
  2945. .is_wildcard = 1,
  2946. .callbacks = {
  2947. [AST_HTTP_POST] = ast_ari_channels_play_with_id_cb,
  2948. },
  2949. .num_children = 0,
  2950. .children = { }
  2951. };
  2952. /*! \brief REST handler for /api-docs/channels.json */
  2953. static struct stasis_rest_handlers channels_channelId_play = {
  2954. .path_segment = "play",
  2955. .callbacks = {
  2956. [AST_HTTP_POST] = ast_ari_channels_play_cb,
  2957. },
  2958. .num_children = 1,
  2959. .children = { &channels_channelId_play_playbackId, }
  2960. };
  2961. /*! \brief REST handler for /api-docs/channels.json */
  2962. static struct stasis_rest_handlers channels_channelId_record = {
  2963. .path_segment = "record",
  2964. .callbacks = {
  2965. [AST_HTTP_POST] = ast_ari_channels_record_cb,
  2966. },
  2967. .num_children = 0,
  2968. .children = { }
  2969. };
  2970. /*! \brief REST handler for /api-docs/channels.json */
  2971. static struct stasis_rest_handlers channels_channelId_variable = {
  2972. .path_segment = "variable",
  2973. .callbacks = {
  2974. [AST_HTTP_GET] = ast_ari_channels_get_channel_var_cb,
  2975. [AST_HTTP_POST] = ast_ari_channels_set_channel_var_cb,
  2976. },
  2977. .num_children = 0,
  2978. .children = { }
  2979. };
  2980. /*! \brief REST handler for /api-docs/channels.json */
  2981. static struct stasis_rest_handlers channels_channelId_snoop_snoopId = {
  2982. .path_segment = "snoopId",
  2983. .is_wildcard = 1,
  2984. .callbacks = {
  2985. [AST_HTTP_POST] = ast_ari_channels_snoop_channel_with_id_cb,
  2986. },
  2987. .num_children = 0,
  2988. .children = { }
  2989. };
  2990. /*! \brief REST handler for /api-docs/channels.json */
  2991. static struct stasis_rest_handlers channels_channelId_snoop = {
  2992. .path_segment = "snoop",
  2993. .callbacks = {
  2994. [AST_HTTP_POST] = ast_ari_channels_snoop_channel_cb,
  2995. },
  2996. .num_children = 1,
  2997. .children = { &channels_channelId_snoop_snoopId, }
  2998. };
  2999. /*! \brief REST handler for /api-docs/channels.json */
  3000. static struct stasis_rest_handlers channels_channelId_dial = {
  3001. .path_segment = "dial",
  3002. .callbacks = {
  3003. [AST_HTTP_POST] = ast_ari_channels_dial_cb,
  3004. },
  3005. .num_children = 0,
  3006. .children = { }
  3007. };
  3008. /*! \brief REST handler for /api-docs/channels.json */
  3009. static struct stasis_rest_handlers channels_channelId_rtp_statistics = {
  3010. .path_segment = "rtp_statistics",
  3011. .callbacks = {
  3012. [AST_HTTP_GET] = ast_ari_channels_rtpstatistics_cb,
  3013. },
  3014. .num_children = 0,
  3015. .children = { }
  3016. };
  3017. /*! \brief REST handler for /api-docs/channels.json */
  3018. static struct stasis_rest_handlers channels_channelId = {
  3019. .path_segment = "channelId",
  3020. .is_wildcard = 1,
  3021. .callbacks = {
  3022. [AST_HTTP_GET] = ast_ari_channels_get_cb,
  3023. [AST_HTTP_POST] = ast_ari_channels_originate_with_id_cb,
  3024. [AST_HTTP_DELETE] = ast_ari_channels_hangup_cb,
  3025. },
  3026. .num_children = 16,
  3027. .children = { &channels_channelId_continue,&channels_channelId_move,&channels_channelId_redirect,&channels_channelId_answer,&channels_channelId_ring,&channels_channelId_dtmf,&channels_channelId_mute,&channels_channelId_hold,&channels_channelId_moh,&channels_channelId_silence,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable,&channels_channelId_snoop,&channels_channelId_dial,&channels_channelId_rtp_statistics, }
  3028. };
  3029. /*! \brief REST handler for /api-docs/channels.json */
  3030. static struct stasis_rest_handlers channels_externalMedia = {
  3031. .path_segment = "externalMedia",
  3032. .callbacks = {
  3033. [AST_HTTP_POST] = ast_ari_channels_external_media_cb,
  3034. },
  3035. .num_children = 0,
  3036. .children = { }
  3037. };
  3038. /*! \brief REST handler for /api-docs/channels.json */
  3039. static struct stasis_rest_handlers channels = {
  3040. .path_segment = "channels",
  3041. .callbacks = {
  3042. [AST_HTTP_GET] = ast_ari_channels_list_cb,
  3043. [AST_HTTP_POST] = ast_ari_channels_originate_cb,
  3044. },
  3045. .num_children = 3,
  3046. .children = { &channels_create,&channels_channelId,&channels_externalMedia, }
  3047. };
  3048. static int unload_module(void)
  3049. {
  3050. ast_ari_remove_handler(&channels);
  3051. return 0;
  3052. }
  3053. static int load_module(void)
  3054. {
  3055. int res = 0;
  3056. res |= ast_ari_add_handler(&channels);
  3057. if (res) {
  3058. unload_module();
  3059. return AST_MODULE_LOAD_DECLINE;
  3060. }
  3061. return AST_MODULE_LOAD_SUCCESS;
  3062. }
  3063. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Channel resources",
  3064. .support_level = AST_MODULE_SUPPORT_CORE,
  3065. .load = load_module,
  3066. .unload = unload_module,
  3067. .requires = "res_ari,res_ari_model,res_stasis,res_stasis_answer,res_stasis_playback,res_stasis_recording,res_stasis_snoop",
  3068. );