Asterisk - The Open Source Telephony Project GIT-master-5467495
Loading...
Searching...
No Matches
stasis_app.h
Go to the documentation of this file.
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#ifndef _ASTERISK_STASIS_APP_H
20#define _ASTERISK_STASIS_APP_H
21
22/*! \file
23 *
24 * \brief Stasis Application API. See \ref res_stasis "Stasis Application API"
25 * for detailed documentation.
26 *
27 * \author David M. Lee, II <dlee@digium.com>
28 * \since 12
29 *
30 * \page res_stasis Stasis Application API
31 *
32 * This is the API that binds the Stasis dialplan application to external
33 * Stasis applications, such as \c res_stasis_websocket.
34 *
35 * The associated \c res_stasis module registers a dialplan function named \c
36 * Stasis, which uses \c res_stasis to put a channel into the named Stasis
37 * app. As a channel enters and leaves the Stasis diaplan application, the
38 * Stasis app receives a \c 'stasis-start' and \c 'stasis-end' events.
39 *
40 * Stasis apps register themselves using the \ref stasis_app_register and
41 * stasis_app_unregister functions. Messages are sent to an appliction using
42 * \ref stasis_app_send.
43 *
44 * Finally, Stasis apps control channels through the use of the \ref
45 * stasis_app_control object, and the family of \c stasis_app_control_*
46 * functions.
47 *
48 * Since module unload order is based on reference counting, any module that
49 * uses the API defined in this file must list "res_stasis" in the requires
50 * field.
51 */
52
53#include "asterisk/channel.h"
54
55/*! @{ */
56
57/*!
58 * \brief Callback for Stasis application handler.
59 *
60 * The message given to the handler is a borrowed copy. If you want to keep a
61 * reference to it, you should use \c ao2_ref() to keep it around.
62 *
63 * \param data Data ptr given when registered.
64 * \param app_name Name of the application being dispatched to.
65 * \param message Message to handle. (borrowed copy)
66 */
67typedef void (*stasis_app_cb)(void *data, const char *app_name,
68 struct ast_json *message);
69
70/*!
71 * \brief Gets the names of all registered Stasis applications.
72 *
73 * \return \c ast_str_container of container names.
74 * \retval NULL on error.
75 */
77
78/*!
79 * \brief Retrieve a handle to a Stasis application by its name
80 *
81 * \param name The name of the registered Stasis application
82 *
83 * \return \c stasis_app on success.
84 * \retval NULL on error.
85 */
86struct stasis_app *stasis_app_get_by_name(const char *name);
87
88/*!
89 * \brief Check if a Stasis application is registered.
90 *
91 * \param name The name of the registered Stasis application
92 *
93 * \return 1 if the application is registered.
94 * \return 0 if the application is not registered.
95 */
96int stasis_app_is_registered(const char *name);
97
98/*!
99 * \brief Register a new Stasis application.
100 *
101 * If an application is already registered with the given name, the old
102 * application is sent a 'replaced' message and unregistered.
103 *
104 * \param app_name Name of this application.
105 * \param handler Callback for application messages.
106 * \param data Data blob to pass to the callback. Must be AO2 managed.
107 *
108 * \return 0 for success
109 * \return -1 for error.
110 */
111int stasis_app_register(const char *app_name, stasis_app_cb handler, void *data);
112
113/*!
114 * \brief Register a new Stasis application that receives all Asterisk events.
115 *
116 * If an application is already registered with the given name, the old
117 * application is sent a 'replaced' message and unregistered.
118 *
119 * \param app_name Name of this application.
120 * \param handler Callback for application messages.
121 * \param data Data blob to pass to the callback. Must be AO2 managed.
122 *
123 * \return 0 for success
124 * \return -1 for error.
125 */
127
128/*!
129 * \brief Unregister a Stasis application and unsubscribe from all event sources.
130 * \param app_name Name of the application to unregister.
131 */
132void stasis_app_unregister(const char *app_name);
133
134/*!
135 * \brief Send a message to the given Stasis application.
136 *
137 * The message given to the handler is a borrowed copy. If you want to keep a
138 * reference to it, you should use \c ao2_ref() to keep it around.
139 *
140 * \param app_name Name of the application to invoke.
141 * \param message Message to send (borrowed reference)
142 *
143 * \return 0 for success.
144 * \return -1 for error.
145 */
146int stasis_app_send(const char *app_name, struct ast_json *message);
147
148/*! \brief Forward declare app */
149struct stasis_app;
150
151/*!
152 * \brief Retrieve an application's name
153 *
154 * \param app An application
155 *
156 * \return The name of the application.
157 */
158const char *stasis_app_name(const struct stasis_app *app);
159
160/*!
161 * \brief Return the JSON representation of a Stasis application.
162 * \since 16.3.0
163 *
164 * \param app The application.
165 *
166 * \return JSON representation of app with given name.
167 * \retval NULL on error.
168 */
170
171/*!
172 * \brief Return the JSON representation of a Stasis application.
173 *
174 * \param app_name Name of the application.
175 *
176 * \return JSON representation of app with given name.
177 * \retval NULL on error.
178 */
179struct ast_json *stasis_app_to_json(const char *app_name);
180
181/*!
182 * \brief Event source information and callbacks.
183 */
185 /*! \brief The scheme to match against on [un]subscribes */
186 const char *scheme;
187
188 /*!
189 * \brief Find an event source data object by the given id/name.
190 *
191 * \param app Application
192 * \param id A unique identifier to search on
193 *
194 * \return The data object associated with the id/name.
195 */
196 void *(*find)(const struct stasis_app *app, const char *id);
197
198 /*!
199 * \brief Subscribe an application to an event source.
200 *
201 * \param app Application
202 * \param obj an event source data object
203 *
204 * \return 0 on success, failure code otherwise
205 */
206 int (*subscribe)(struct stasis_app *app, void *obj);
207
208 /*!
209 * \brief Cancel the subscription an app has to an event source.
210 *
211 * \param app Application
212 * \param id a previously subscribed object id
213 *
214 * \return 0 on success, failure code otherwise
215 */
216 int (*unsubscribe)(struct stasis_app *app, const char *id);
217
218 /*!
219 * \brief Find an event source by the given id/name.
220 *
221 * \param app Application
222 * \param id A unique identifier to check
223 *
224 * \return true if id is subscribed, false otherwise.
225 */
226 int (*is_subscribed)(struct stasis_app *app, const char *id);
227
228 /*!
229 * \brief Convert event source data to json
230 *
231 * \param app Application
232 * \param id json object to fill
233 */
234 void (*to_json)(const struct stasis_app *app, struct ast_json *json);
235
236 /*! Next item in the list */
238};
239
240/*!
241 * \brief Register an application event source.
242 *
243 * \param obj the event source to register
244 */
246
247/*!
248 * \brief Register core event sources.
249 */
251
252/*!
253 * \brief Unregister an application event source.
254 *
255 * \param obj the event source to unregister
256 */
258
259/*!
260 * \brief Unregister core event sources.
261 */
263
264/*! \brief Return code for stasis_app_user_event */
273
274/*!
275 * \brief Generate a Userevent for stasis app (echo to AMI)
276 *
277 * \param app_name Name of the application to generate event for/to.
278 * \param event_name Name of the Userevent.
279 * \param source_uris URIs for the source objects to attach to event.
280 * \param sources_count Array size of source_uris.
281 * \param json_variables event blob variables.
282 *
283 * \return \ref stasis_app_user_event_res return code.
284 */
286 const char *event_name,
287 const char **source_uris, int sources_count,
288 struct ast_json *json_variables);
289
290
291/*! \brief Return code for stasis_app_[un]subscribe */
299
300/*!
301 * \brief Subscribes an application to a list of event sources.
302 *
303 * \param app_name Name of the application to subscribe.
304 * \param event_source_uris URIs for the event sources to subscribe to.
305 * \param event_sources_count Array size of event_source_uris.
306 * \param json Optional output pointer for JSON representation of the app
307 * after adding the subscription.
308 *
309 * \return \ref stasis_app_subscribe_res return code.
310 *
311 * \note Do not hold any channel locks if subscribing to a channel.
312 */
314 const char **event_source_uris, int event_sources_count,
315 struct ast_json **json);
316
317/*!
318 * \brief Unsubscribes an application from a list of event sources.
319 *
320 * \param app_name Name of the application to subscribe.
321 * \param event_source_uris URIs for the event sources to subscribe to.
322 * \param event_sources_count Array size of event_source_uris.
323 * \param json Optional output pointer for JSON representation of the app
324 * after adding the subscription.
325 *
326 * \return \ref stasis_app_subscribe_res return code.
327 */
329 const char **event_source_uris, int event_sources_count,
330 struct ast_json **json);
331
332/*!
333 * \brief Directly subscribe an application to a channel
334 *
335 * \param app_name Name of the application to subscribe.
336 * \param chan The channel to subscribe to
337 *
338 * \return \ref stasis_app_subscribe_res return code.
339 *
340 * \note This method can be used when you already hold a channel and its
341 * lock. This bypasses the channel lookup that would normally be
342 * performed by \ref stasis_app_subscribe.
343 */
345 struct ast_channel *chan);
346
347/*! @} */
348
349/*! @{ */
350
351/*! \brief Handler for controlling a channel that's in a Stasis application */
352struct stasis_app_control;
353
354/*! \brief Rule to check to see if an operation is allowed */
356 /*!
357 * \brief Checks to see if an operation is allowed on the control
358 *
359 * \param control Control object to check
360 * \return 0 on success, otherwise a failure code
361 */
363 const struct stasis_app_control *control);
364 /*! Next item in the list */
366};
367
368/*!
369 * \brief Registers an add channel to bridge rule.
370 *
371 * \param control Control object
372 * \param rule The rule to register
373 */
375 struct stasis_app_control *control,
377
378/*!
379 * \brief UnRegister an add channel to bridge rule.
380 *
381 * \param control Control object
382 * \param rule The rule to unregister
383 */
385 struct stasis_app_control *control,
387
388/*!
389 * \brief Registers a remove channel from bridge rule.
390 *
391 * \param control Control object
392 * \param rule The rule to register
393 */
395 struct stasis_app_control *control,
397
398/*!
399 * \brief Unregisters a remove channel from bridge rule.
400 *
401 * \param control Control object
402 * \param rule The rule to unregister
403 */
405 struct stasis_app_control *control,
407
408/*!
409 * \brief Returns the handler for the given channel.
410 * \param chan Channel to handle.
411 *
412 * \return NULL channel not in Stasis application.
413 * \return Pointer to \c res_stasis handler.
414 */
416 const struct ast_channel *chan);
417
418/*!
419 * \brief Returns the handler for the channel with the given id.
420 * \param channel_id Uniqueid of the channel.
421 *
422 * \return NULL channel not in Stasis application, or channel does not exist.
423 * \return Pointer to \c res_stasis handler.
424 */
426 const char *channel_id);
427
428/*!
429 * \brief Creates a control handler for a channel that isn't in a stasis app.
430 * \since 12.0.0
431 *
432 * \param chan Channel to create controller handle for
433 *
434 * \return NULL on failure to create the handle
435 * \return Pointer to \c res_stasis handler.
436 */
438 struct ast_channel *chan);
439
440/*!
441 * \brief Act on a stasis app control queue until it is empty
442 * \since 12.0.0
443 *
444 * \param chan Channel to handle
445 * \param control Control object to execute
446 */
448 struct ast_channel *chan,
449 struct stasis_app_control *control);
450
451/*!
452 * \brief Check if a control is marked as done
453 * \since 12.2.0
454 *
455 * \param control Which control object is being evaluated
456 */
458 struct stasis_app_control *control);
459
460/*!
461 * \brief Set the failed flag on a control structure
462 *
463 * \param control Control object to be updated
464 */
466
467/*!
468 * \brief Check if a control object is marked as "failed"
469 *
470 * \param control Control object to check
471 */
472int stasis_app_control_is_failed(const struct stasis_app_control *control);
473
474/*!
475 * \brief Flush the control command queue.
476 * \since 13.9.0
477 *
478 * \param control Control object to flush command queue.
479 */
481
482/*!
483 * \brief Returns the uniqueid of the channel associated with this control
484 *
485 * \param control Control object.
486 *
487 * \return Uniqueid of the associate channel.
488 * \retval NULL if \a control is \c NULL.
489 */
491 const struct stasis_app_control *control);
492
493/*!
494 * \brief Apply a bridge role to a channel controlled by a stasis app control
495 *
496 * \param control Control for \c res_stasis
497 * \param role Role to apply
498 *
499 * \return 0 for success
500 * \return -1 for error.
501 */
502int stasis_app_control_add_role(struct stasis_app_control *control, const char *role);
503
504/*!
505 * \brief Clear bridge roles currently applied to a channel controlled by a stasis app control
506 *
507 * \param control Control for \c res_stasis
508 */
510
511/*!
512 * \brief Exit \c res_stasis and continue execution in the dialplan.
513 *
514 * If the channel is no longer in \c res_stasis, this function does nothing.
515 *
516 * \param control Control for \c res_stasis
517 * \param context An optional context to continue to
518 * \param extension An optional extension to continue to
519 * \param priority An optional priority to continue to
520 *
521 * \return 0 for success
522 * \return -1 for error.
523 */
524int stasis_app_control_continue(struct stasis_app_control *control, const char *context, const char *extension, int priority);
525
526/*!
527 * \brief Exit \c res_stasis and move to another Stasis application.
528 *
529 * If the channel is no longer in \c res_stasis, this function does nothing.
530 *
531 * \param control Control for \c res_stasis
532 * \param app_name The name of the application to switch to
533 * \param app_args The list of arguments to pass to the application
534 *
535 * \return 0 for success
536 * \return -1 for error
537 */
538int stasis_app_control_move(struct stasis_app_control *control, const char *app_name, const char *app_args);
539
540/*!
541 * \brief Redirect a channel in \c res_stasis to a particular endpoint
542 *
543 * \param control Control for \c res_stasis
544 * \param endpoint The endpoint transfer string where the channel should be sent to
545 *
546 * \return 0 for success
547 * \return -1 for error
548 */
549int stasis_app_control_redirect(struct stasis_app_control *control, const char *endpoint);
550
551/*!
552 * \brief Indicate ringing to the channel associated with this control.
553 *
554 * \param control Control for \c res_stasis.
555 *
556 * \return 0 for success.
557 * \return -1 for error.
558 */
560
561/*!
562 * \brief Stop locally generated ringing on the channel associated with this control.
563 *
564 * \param control Control for \c res_stasis.
565 *
566 * \return 0 for success.
567 * \return -1 for error.
568 */
570
571/*!
572 * \brief Indicate progress to the channel associated with this control.
573 *
574 * \param control Control for \c res_stasis.
575 *
576 * \return 0 for success.
577 * \return -1 for error.
578 */
580
581/*!
582 * \brief Send DTMF to the channel associated with this control.
583 *
584 * \param control Control for \c res_stasis.
585 * \param dtmf DTMF string.
586 * \param before Amount of time to wait before sending DTMF digits.
587 * \param between Amount of time between each DTMF digit.
588 * \param duration Amount of time each DTMF digit lasts for.
589 * \param after Amount of time to wait after sending DTMF digits.
590 *
591 * \return 0 for success.
592 * \return -1 for error.
593 */
594int stasis_app_control_dtmf(struct stasis_app_control *control, const char *dtmf, int before, int between, unsigned int duration, int after);
595
596/*!
597 * \brief Mute the channel associated with this control.
598 *
599 * \param control Control for \c res_stasis.
600 * \param direction The direction in which the audio should be muted.
601 * \param frametype The type of stream that should be muted.
602 *
603 * \return 0 for success
604 * \return -1 for error.
605 */
606int stasis_app_control_mute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype);
607
608/*!
609 * \brief Unmute the channel associated with this control.
610 *
611 * \param control Control for \c res_stasis.
612 * \param direction The direction in which the audio should be unmuted.
613 * \param frametype The type of stream that should be unmuted.
614 *
615 * \return 0 for success
616 * \return -1 for error.
617 */
618int stasis_app_control_unmute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype);
619
620/*!
621 * \brief Answer the channel associated with this control.
622 * \param control Control for \c res_stasis.
623 * \return 0 for success.
624 * \return Non-zero for error.
625 */
627
628/*!
629 * \brief Set a variable on the channel associated with this control to value.
630 * \param control Control for \c res_stasis.
631 * \param variable The name of the variable
632 * \param value The value to set the variable to
633 *
634 * \note The thread that actually does the set will have the inhibit_escalations
635 * flag set before the call to pbx_builtin_setvar_helper to prevent dangerous
636 * dialplan function execution from ARI. The flag will be reset to its original
637 * state when pbx_builtin_setvar_helper returns.
638 *
639 * \return 0 for success.
640 * \return -1 for error.
641 */
642int stasis_app_control_set_channel_var(struct stasis_app_control *control, const char *variable, const char *value);
643
644/*!
645 * \brief Set a variable on the channel associated with this control to value with option of including in events.
646 * \param control Control for \c res_stasis.
647 * \param variable The name of the variable
648 * \param value The value to set the variable to
649 * \param report_events Whether to include this variable in channel events.
650 *
651 * \return 0 for success.
652 * \return -1 for error.
653 */
654int stasis_app_control_set_channel_var_reportable(struct stasis_app_control *control, const char *variable, const char *value, int report_events);
655
656
657/*!
658 * \brief Place the channel associated with the control on hold.
659 * \param control Control for \c res_stasis.
660 */
661void stasis_app_control_hold(struct stasis_app_control *control);
662
663/*!
664 * \brief Remove the channel associated with the control from hold.
665 * \param control Control for \c res_stasis.
666 */
668
669/*!
670 * \brief Play music on hold to a channel (does not affect hold status)
671 * \param control Control for \c res_stasis.
672 * \param moh_class class of music on hold to play (NULL allowed)
673 */
674void stasis_app_control_moh_start(struct stasis_app_control *control, const char *moh_class);
675
676/*!
677 * \brief Stop playing music on hold to a channel (does not affect hold status)
678 * \param control Control for \c res_stasis.
679 */
681
682/*!
683 * \brief Start playing silence to a channel.
684 * \param control Control for \c res_stasis.
685 */
687
688/*!
689 * \brief Stop playing silence to a channel.
690 * \param control Control for \c res_stasis.
691 */
693
694/*!
695 * \brief Returns the most recent snapshot for the associated channel.
696 *
697 * The returned pointer is AO2 managed, so ao2_cleanup() when you're done.
698 *
699 * \param control Control for \c res_stasis.
700 *
701 * \return Most recent snapshot. ao2_cleanup() when done.
702 * \retval NULL if channel isn't in cache.
703 */
705 const struct stasis_app_control *control);
706
707/*!
708 * \brief Publish a message to the \a control's channel's topic.
709 *
710 * \param control Control to publish to
711 * \param message Message to publish
712 */
714 struct stasis_app_control *control, struct stasis_message *message);
715
716/*!
717 * \brief Returns the stasis topic for an app
718 *
719 * \param app Stasis app to get topic of
720 */
722
723/*!
724 * \brief Queue a control frame without payload.
725 *
726 * \param control Control to publish to.
727 * \param frame_type type of control frame.
728 *
729 * \return zero on success
730 * \return non-zero on failure
731 */
734
735/*!
736 * \brief Create a bridge of the specified type.
737 *
738 * \param type The type of bridge to be created
739 * \param name Optional name to give to the bridge
740 * \param id Optional Unique ID to give to the bridge
741 *
742 * \return New bridge.
743 * \retval NULL on error.
744 */
745struct ast_bridge *stasis_app_bridge_create(const char *type, const char *name, const char *id);
746
747/*!
748 * \brief Create an invisible bridge of the specified type.
749 *
750 * \param type The type of bridge to be created
751 * \param name Optional name to give to the bridge
752 * \param id Optional Unique ID to give to the bridge
753 *
754 * \return New bridge.
755 * \retval NULL on error.
756 */
757struct ast_bridge *stasis_app_bridge_create_invisible(const char *type, const char *name, const char *id);
758
759/*!
760 * \brief Returns the bridge with the given id.
761 * \param bridge_id Uniqueid of the bridge.
762 *
763 * \return NULL bridge not created by a Stasis application, or bridge does not exist.
764 * \return Pointer to bridge.
765 */
767 const char *bridge_id);
768
769/*!
770 * \brief Finds or creates an announcer channel in a bridge that can play music on hold.
771 *
772 * \param bridge Bridge we want an MOH channel for
773 *
774 * \return NULL if the music on hold channel fails to be created or join the bridge for any reason.
775 * \return Pointer to the ;1 end of the announcer channel chain.
776 */
778 struct ast_bridge *bridge);
779
780/*!
781 * \brief Breaks down MOH channels playing on the bridge created by stasis_app_bridge_moh_channel
782 *
783 * \param bridge Bridge we want to stop the MOH on
784 *
785 * \return -1 if no moh channel could be found and stopped
786 * \return 0 on success
787 */
789 struct ast_bridge *bridge);
790
791/*!
792 * \brief Finds an existing ARI playback channel in a bridge
793 *
794 * \param bridge Bridge we want to find the playback channel for
795 *
796 * \return NULL if the playback channel can not be found for any reason.
797 * \return Pointer to the ;1 end of the playback channel chain.
798 */
800 struct ast_bridge *bridge);
801
802/*!
803 * \brief Adds a channel to the list of ARI playback channels for bridges.
804 *
805 * \param bridge Bridge we are adding the playback channel for
806 * \param chan Channel being added as a playback channel (must be ;1)
807 * \param control The app control structure for the playback channel
808 *
809 * \retval -1 failed to add channel for any reason
810 * \retval 0 on success
811 */
813 struct ast_channel *chan,
814 struct stasis_app_control *control);
815
816/*!
817 * \brief Remove a bridge playback channel's control from the app controls list.
818 *
819 * \param bridge_id The unique ID of the bridge the playback channel is in.
820 * \param control The app control structure for the playback channel
821 */
823 struct stasis_app_control *control);
824
825/*!
826 * \brief remove channel from list of ARI playback channels for bridges.
827 *
828 * \param bridge_id The unique ID of the bridge the playback channel is in.
829 * \param control The app control structure for the playback channel
830 */
832 struct stasis_app_control *control);
833
834/*!
835 * \brief Result codes used when adding/removing channels to/from bridges.
836 */
838 /*! The channel is okay to be added/removed */
840 /*! The channel is currently recording */
843
844/*!
845 * \brief Add a channel to the bridge.
846 *
847 * \param control Control whose channel should be added to the bridge
848 * \param bridge Pointer to the bridge
849 *
850 * \return non-zero on failure
851 * \return zero on success
852 */
854 struct stasis_app_control *control, struct ast_bridge *bridge);
855
856/*!
857 * \brief Remove a channel from the bridge.
858 *
859 * \param control Control whose channel should be removed from the bridge
860 * \param bridge Pointer to the bridge
861 *
862 * \return non-zero on failure
863 * \return zero on success
864 */
866 struct stasis_app_control *control, struct ast_bridge *bridge);
867
868/*!
869 * \brief Initialize bridge features into a channel control
870 *
871 * \note Bridge features on a control are destroyed after each bridge session,
872 * so new features need to be initialized before each bridge add.
873 *
874 * \param control Control in which to store the features
875 *
876 * \return non-zero on failure
877 * \return zero on success
878 */
880 struct stasis_app_control *control);
881
882/*!
883 * \brief Set whether DTMF from the channel is absorbed instead of passing through to the bridge
884 *
885 * \param control Control whose channel should have its DTMF absorbed when bridged
886 * \param absorb Whether DTMF should be absorbed (1) instead of passed through (0).
887 */
889 struct stasis_app_control *control, int absorb);
890
891/*!
892 * \brief Set whether audio from the channel is muted instead of passing through to the bridge
893 *
894 * \param control Control whose channel should have its audio muted when bridged
895 * \param mute Whether audio should be muted (1) instead of passed through (0).
896 */
898 struct stasis_app_control *control, int mute);
899
900/*!
901 * \since 18
902 * \brief Set whether COLP frames should be generated when joining the bridge
903 *
904 * \param control Control whose channel should have its COLP frames inhibited when bridged
905 * \param inhibit_colp Whether COLP frames should be generated (0) or not (1).
906 */
908 struct stasis_app_control *control, int inhibit_colp);
909
910/*!
911 * \since 12
912 * \brief Gets the bridge currently associated with a control object.
913 *
914 * \note If the bridge returned by this function is to be held for any
915 * length of time, its refcount should be incremented until the
916 * caller is finished with it.
917 *
918 * \param control Control object for the channel to query.
919 *
920 * \return Associated \ref ast_bridge.
921 * \retval NULL if not associated with a bridge.
922 */
924
925/*!
926 * \brief Destroy the bridge.
927 *
928 * \param bridge_id Uniqueid of bridge to be destroyed
929 */
930void stasis_app_bridge_destroy(const char *bridge_id);
931
932/*!
933 * \brief Set or clear a variable on a bridge and control ARI event reporting for it.
934 *
935 * \param bridge_id Uniqueid of bridge
936 * \param variable Variable name
937 * \param value Variable value (NULL/empty clears)
938 * \param report_events Non-zero to include in ARI bridge events
939 *
940 * \retval 0 on success
941 * \retval -1 on failure
942 */
943int stasis_app_bridge_set_var_reportable(const char *bridge_id, const char *variable,
944 const char *value, int report_events);
945
946/*!
947 * \brief Get the Stasis message sanitizer for app_stasis applications
948 *
949 * \retval The stasis message sanitizer
950 */
952
953/*!
954 * \brief Indicate that this channel has had a StasisEnd published for it
955 *
956 * \param chan The channel that is exiting Stasis.
957 */
959
960/*!
961 * \brief Has this channel had a StasisEnd published on it?
962 *
963 * \param chan The channel upon which the query rests.
964 *
965 * \retval 0 No
966 * \retval 1 Yes
967 */
969
970/*!
971 * \brief Is this channel internal to Stasis?
972 *
973 * \param chan The channel to check.
974 *
975 * \retval 0 No
976 * \retval 1 Yes
977 */
979
980/*!
981 * \brief Mark this unreal channel and it's other half as being internal to Stasis.
982 *
983 * \param chan The channel to mark.
984 *
985 * \retval zero Success
986 * \retval non-zero Failure
987 */
989
990/*!
991 * \brief Mark this channel as being internal to Stasis.
992 *
993 * \param chan The channel to mark.
994 *
995 * \retval zero Success
996 * \retval non-zero Failure
997 */
999
1000/*!
1001 * \brief Dial a channel
1002 * \param control Control for \c res_stasis.
1003 * \param dialstring The dialstring to pass to the channel driver
1004 * \param timeout Optional timeout in milliseconds
1005 */
1007 const char *dialstring, unsigned int timeout);
1008
1009/*!
1010 * \brief Let Stasis app internals shut down
1011 *
1012 * This is called when res_stasis is unloaded. It ensures that
1013 * the Stasis app internals can free any resources they may have
1014 * allocated during the time that res_stasis was loaded.
1015 */
1017
1018/*!
1019 * \brief Enable/disable request/response and event logging on an application
1020 *
1021 * \param app The app to debug
1022 * \param debug If non-zero, enable debugging. If zero, disable.
1023 */
1024void stasis_app_set_debug(struct stasis_app *app, int debug);
1025
1026/*!
1027 * \brief Enable/disable request/response and event logging on an application
1028 *
1029 * \param app_name The app name to debug
1030 * \param debug If non-zero, enable debugging. If zero, disable.
1031 */
1032void stasis_app_set_debug_by_name(const char *app_name, int debug);
1033
1034/*!
1035 * \brief Get debug status of an application
1036 *
1037 * \param app The app to check
1038 * \return The debug flag for the app || the global debug flag
1039 */
1041
1042/*!
1043 * \brief Get debug status of an application
1044 *
1045 * \param app_name The app_name to check
1046 * \return The debug flag for the app || the global debug flag
1047 */
1048int stasis_app_get_debug_by_name(const char *app_name);
1049
1050/*!
1051 * \brief Enable/disable request/response and event logging on all applications
1052 *
1053 * \param debug If non-zero, enable debugging. If zero, disable.
1054 */
1056
1057struct ast_cli_args;
1058
1059/*!
1060 * \brief Dump properties of a \c stasis_app to the CLI
1061 *
1062 * \param app The application
1063 * \param a The CLI arguments
1064 */
1065void stasis_app_to_cli(const struct stasis_app *app, struct ast_cli_args *a);
1066
1067/*!
1068 * \brief Convert and add the app's event type filter(s) to the given json object.
1069 *
1070 * \param app The application
1071 * \param json The json object to add the filter data to
1072 *
1073 * \return The given json object
1074 */
1075struct ast_json *stasis_app_event_filter_to_json(struct stasis_app *app, struct ast_json *json);
1076
1077/*!
1078 * \brief Set the application's event type filter
1079 *
1080 * \param app The application
1081 * \param filter The allowed and/or disallowed event filter
1082 *
1083 * \return 0 if successfully set
1084 */
1086
1087/*!
1088 * \brief Check if the given event should be filtered.
1089 *
1090 * Attempts first to find the event in the application's disallowed events list.
1091 * If found then the event won't be sent to the remote. If not found in the
1092 * disallowed list then a search is done to see if it can be found in the allowed
1093 * list. If found the event message is sent, otherwise it is not sent.
1094 *
1095 * \param app_name The application name
1096 * \param event The event to check
1097 *
1098 * \return True if allowed, false otherwise
1099 */
1100int stasis_app_event_allowed(const char *app_name, struct ast_json *event);
1101
1102/*! @} */
1103
1104#endif /* _ASTERISK_STASIS_APP_H */
static const char app[]
enum queue_result id
Definition app_queue.c:1790
static int priority
static const char type[]
General Asterisk PBX channel definitions.
frame_type
static const char name[]
Definition format_mp3.c:68
direction
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
ast_frame_type
Frame types.
ast_control_frame_type
Internal control frame subtype field values.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
const char * app_name(struct ast_app *app)
Definition pbx_app.c:475
static int debug
Global debug status.
Definition res_xmpp.c:570
void stasis_app_control_mute_in_bridge(struct stasis_app_control *control, int mute)
Set whether audio from the channel is muted instead of passing through to the bridge.
Definition control.c:1543
void stasis_app_bridge_playback_channel_remove(char *bridge_id, struct stasis_app_control *control)
remove channel from list of ARI playback channels for bridges.
Definition res_stasis.c:776
struct ast_json * stasis_app_object_to_json(struct stasis_app *app)
Return the JSON representation of a Stasis application.
void stasis_app_set_debug(struct stasis_app *app, int debug)
Enable/disable request/response and event logging on an application.
struct stasis_message_sanitizer * stasis_app_get_sanitizer(void)
Get the Stasis message sanitizer for app_stasis applications.
void stasis_app_control_register_remove_rule(struct stasis_app_control *control, struct stasis_app_control_rule *rule)
Registers a remove channel from bridge rule.
Definition control.c:239
void stasis_app_control_moh_start(struct stasis_app_control *control, const char *moh_class)
Play music on hold to a channel (does not affect hold status)
Definition control.c:842
const char * stasis_app_control_get_channel_id(const struct stasis_app_control *control)
Returns the uniqueid of the channel associated with this control.
Definition control.c:1503
struct stasis_topic * ast_app_get_topic(struct stasis_app *app)
Returns the stasis topic for an app.
struct ast_bridge * stasis_app_bridge_create_invisible(const char *type, const char *name, const char *id)
Create an invisible bridge of the specified type.
Definition res_stasis.c:903
int stasis_app_control_queue_control(struct stasis_app_control *control, enum ast_control_frame_type frame_type)
Queue a control frame without payload.
Definition control.c:1518
void stasis_app_control_mark_failed(struct stasis_app_control *control)
Set the failed flag on a control structure.
Definition control.c:377
int stasis_app_channel_is_internal(struct ast_channel *chan)
Is this channel internal to Stasis?
void stasis_app_control_unregister_remove_rule(struct stasis_app_control *control, struct stasis_app_control_rule *rule)
Unregisters a remove channel from bridge rule.
Definition control.c:246
int stasis_app_event_allowed(const char *app_name, struct ast_json *event)
Check if the given event should be filtered.
int stasis_app_control_unmute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype)
Unmute the channel associated with this control.
Definition control.c:700
void stasis_app_control_unhold(struct stasis_app_control *control)
Remove the channel associated with the control from hold.
Definition control.c:823
int stasis_app_send(const char *app_name, struct ast_json *message)
Send a message to the given Stasis application.
int stasis_app_control_add_channel_to_bridge(struct stasis_app_control *control, struct ast_bridge *bridge)
Add a channel to the bridge.
Definition control.c:1456
void stasis_app_unregister_event_sources(void)
Unregister core event sources.
int stasis_app_control_is_failed(const struct stasis_app_control *control)
Check if a control object is marked as "failed".
Definition control.c:382
enum stasis_app_subscribe_res stasis_app_subscribe(const char *app_name, const char **event_source_uris, int event_sources_count, struct ast_json **json)
Subscribes an application to a list of event sources.
int stasis_app_is_registered(const char *name)
Check if a Stasis application is registered.
void stasis_app_control_silence_start(struct stasis_app_control *control)
Start playing silence to a channel.
Definition control.c:894
void stasis_app_control_silence_stop(struct stasis_app_control *control)
Stop playing silence to a channel.
Definition control.c:917
void stasis_app_channel_set_stasis_end_published(struct ast_channel *chan)
Indicate that this channel has had a StasisEnd published for it.
void stasis_app_control_clear_roles(struct stasis_app_control *control)
Clear bridge roles currently applied to a channel controlled by a stasis app control.
Definition control.c:353
void stasis_app_bridge_destroy(const char *bridge_id)
Destroy the bridge.
Definition res_stasis.c:908
int stasis_app_control_continue(struct stasis_app_control *control, const char *context, const char *extension, int priority)
Exit res_stasis and continue execution in the dialplan.
Definition control.c:415
stasis_app_user_event_res
Return code for stasis_app_user_event.
Definition stasis_app.h:265
@ STASIS_APP_USER_APP_NOT_FOUND
Definition stasis_app.h:267
@ STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND
Definition stasis_app.h:268
@ STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME
Definition stasis_app.h:269
@ STASIS_APP_USER_USEREVENT_INVALID
Definition stasis_app.h:270
@ STASIS_APP_USER_OK
Definition stasis_app.h:266
@ STASIS_APP_USER_INTERNAL_ERROR
Definition stasis_app.h:271
struct ast_json * stasis_app_to_json(const char *app_name)
Return the JSON representation of a Stasis application.
void stasis_app_set_debug_by_name(const char *app_name, int debug)
Enable/disable request/response and event logging on an application.
int stasis_app_register(const char *app_name, stasis_app_cb handler, void *data)
Register a new Stasis application.
void stasis_app_control_publish(struct stasis_app_control *control, struct stasis_message *message)
Publish a message to the control's channel's topic.
Definition control.c:1509
int stasis_app_control_redirect(struct stasis_app_control *control, const char *endpoint)
Redirect a channel in res_stasis to a particular endpoint.
Definition control.c:526
void stasis_app_control_moh_stop(struct stasis_app_control *control)
Stop playing music on hold to a channel (does not affect hold status)
Definition control.c:860
int stasis_app_control_move(struct stasis_app_control *control, const char *app_name, const char *app_args)
Exit res_stasis and move to another Stasis application.
Definition control.c:477
int stasis_app_channel_set_internal(struct ast_channel *chan)
Mark this channel as being internal to Stasis.
struct ast_json * stasis_app_event_filter_to_json(struct stasis_app *app, struct ast_json *json)
Convert and add the app's event type filter(s) to the given json object.
struct ast_bridge * stasis_app_bridge_find_by_id(const char *bridge_id)
Returns the bridge with the given id.
Definition res_stasis.c:807
void stasis_app_register_event_sources(void)
Register core event sources.
struct ast_bridge * stasis_app_bridge_create(const char *type, const char *name, const char *id)
Create a bridge of the specified type.
Definition res_stasis.c:898
int stasis_app_control_mute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype)
Mute the channel associated with this control.
Definition control.c:672
void stasis_app_unregister_event_source(struct stasis_app_event_source *obj)
Unregister an application event source.
void stasis_app_control_absorb_dtmf_in_bridge(struct stasis_app_control *control, int absorb)
Set whether DTMF from the channel is absorbed instead of passing through to the bridge.
Definition control.c:1537
int stasis_app_event_filter_set(struct stasis_app *app, struct ast_json *filter)
Set the application's event type filter.
enum stasis_app_subscribe_res stasis_app_subscribe_channel(const char *app_name, struct ast_channel *chan)
Directly subscribe an application to a channel.
void(* stasis_app_cb)(void *data, const char *app_name, struct ast_json *message)
Callback for Stasis application handler.
Definition stasis_app.h:67
void stasis_app_control_execute_until_exhausted(struct ast_channel *chan, struct stasis_app_control *control)
Act on a stasis app control queue until it is empty.
struct ast_channel * stasis_app_bridge_moh_channel(struct ast_bridge *bridge)
Finds or creates an announcer channel in a bridge that can play music on hold.
Definition res_stasis.c:655
enum stasis_app_user_event_res stasis_app_user_event(const char *app_name, const char *event_name, const char **source_uris, int sources_count, struct ast_json *json_variables)
Generate a Userevent for stasis app (echo to AMI)
void stasis_app_set_global_debug(int debug)
Enable/disable request/response and event logging on all applications.
void stasis_app_bridge_playback_channel_control_remove(const char *bridge_id, struct stasis_app_control *control)
Remove a bridge playback channel's control from the app controls list.
Definition res_stasis.c:717
int stasis_app_control_dtmf(struct stasis_app_control *control, const char *dtmf, int before, int between, unsigned int duration, int after)
Send DTMF to the channel associated with this control.
Definition control.c:591
int stasis_app_get_debug(struct stasis_app *app)
Get debug status of an application.
void stasis_app_control_flush_queue(struct stasis_app_control *control)
Flush the control command queue.
void stasis_app_to_cli(const struct stasis_app *app, struct ast_cli_args *a)
Dump properties of a stasis_app to the CLI.
int stasis_app_control_add_role(struct stasis_app_control *control, const char *role)
Apply a bridge role to a channel controlled by a stasis app control.
Definition control.c:331
int stasis_app_channel_unreal_set_internal(struct ast_channel *chan)
Mark this unreal channel and it's other half as being internal to Stasis.
void stasis_app_control_inhibit_colp_in_bridge(struct stasis_app_control *control, int inhibit_colp)
Set whether COLP frames should be generated when joining the bridge.
Definition control.c:1549
int stasis_app_control_remove_channel_from_bridge(struct stasis_app_control *control, struct ast_bridge *bridge)
Remove a channel from the bridge.
Definition control.c:1493
struct ast_bridge * stasis_app_get_bridge(struct stasis_app_control *control)
Gets the bridge currently associated with a control object.
Definition control.c:993
int stasis_app_control_bridge_features_init(struct stasis_app_control *control)
Initialize bridge features into a channel control.
Definition control.c:1524
int stasis_app_bridge_playback_channel_add(struct ast_bridge *bridge, struct ast_channel *chan, struct stasis_app_control *control)
Adds a channel to the list of ARI playback channels for bridges.
Definition res_stasis.c:738
void stasis_app_unregister(const char *app_name)
Unregister a Stasis application and unsubscribe from all event sources.
int stasis_app_control_set_channel_var_reportable(struct stasis_app_control *control, const char *variable, const char *value, int report_events)
Set a variable on the channel associated with this control to value with option of including in event...
Definition control.c:773
enum stasis_app_subscribe_res stasis_app_unsubscribe(const char *app_name, const char **event_source_uris, int event_sources_count, struct ast_json **json)
Unsubscribes an application from a list of event sources.
void stasis_app_control_hold(struct stasis_app_control *control)
Place the channel associated with the control on hold.
Definition control.c:810
struct stasis_app * stasis_app_get_by_name(const char *name)
Retrieve a handle to a Stasis application by its name.
int stasis_app_bridge_set_var_reportable(const char *bridge_id, const char *variable, const char *value, int report_events)
Set or clear a variable on a bridge and control ARI event reporting for it.
Definition res_stasis.c:923
void stasis_app_control_unregister_add_rule(struct stasis_app_control *control, struct stasis_app_control_rule *rule)
UnRegister an add channel to bridge rule.
Definition control.c:232
struct stasis_app_control * stasis_app_control_find_by_channel_id(const char *channel_id)
Returns the handler for the channel with the given id.
Definition res_stasis.c:349
void stasis_app_register_event_source(struct stasis_app_event_source *obj)
Register an application event source.
struct ast_channel * stasis_app_bridge_playback_channel_find(struct ast_bridge *bridge)
Finds an existing ARI playback channel in a bridge.
Definition res_stasis.c:792
struct ao2_container * stasis_app_get_all(void)
Gets the names of all registered Stasis applications.
int stasis_app_control_is_done(struct stasis_app_control *control)
Check if a control is marked as done.
int stasis_app_control_ring_stop(struct stasis_app_control *control)
Stop locally generated ringing on the channel associated with this control.
Definition control.c:633
int stasis_app_control_dial(struct stasis_app_control *control, const char *dialstring, unsigned int timeout)
Dial a channel.
Definition control.c:1739
struct ast_channel_snapshot * stasis_app_control_get_snapshot(const struct stasis_app_control *control)
Returns the most recent snapshot for the associated channel.
Definition control.c:922
const char * stasis_app_name(const struct stasis_app *app)
Retrieve an application's name.
void stasis_app_control_register_add_rule(struct stasis_app_control *control, struct stasis_app_control_rule *rule)
Registers an add channel to bridge rule.
Definition control.c:225
stasis_app_control_channel_result
Result codes used when adding/removing channels to/from bridges.
Definition stasis_app.h:837
@ STASIS_APP_CHANNEL_RECORDING
Definition stasis_app.h:841
@ STASIS_APP_CHANNEL_OKAY
Definition stasis_app.h:839
stasis_app_subscribe_res
Return code for stasis_app_[un]subscribe.
Definition stasis_app.h:292
@ STASIS_ASR_OK
Definition stasis_app.h:293
@ STASIS_ASR_EVENT_SOURCE_BAD_SCHEME
Definition stasis_app.h:296
@ STASIS_ASR_INTERNAL_ERROR
Definition stasis_app.h:297
@ STASIS_ASR_EVENT_SOURCE_NOT_FOUND
Definition stasis_app.h:295
@ STASIS_ASR_APP_NOT_FOUND
Definition stasis_app.h:294
int stasis_app_channel_is_stasis_end_published(struct ast_channel *chan)
Has this channel had a StasisEnd published on it?
struct stasis_app_control * stasis_app_control_find_by_channel(const struct ast_channel *chan)
Returns the handler for the given channel.
Definition res_stasis.c:338
int stasis_app_control_set_channel_var(struct stasis_app_control *control, const char *variable, const char *value)
Set a variable on the channel associated with this control to value.
Definition control.c:768
int stasis_app_register_all(const char *app_name, stasis_app_cb handler, void *data)
Register a new Stasis application that receives all Asterisk events.
struct stasis_app_control * stasis_app_control_create(struct ast_channel *chan)
Creates a control handler for a channel that isn't in a stasis app.
Definition res_stasis.c:333
int stasis_app_get_debug_by_name(const char *app_name)
Get debug status of an application.
int stasis_app_control_ring(struct stasis_app_control *control)
Indicate ringing to the channel associated with this control.
Definition control.c:618
int stasis_app_control_progress(struct stasis_app_control *control)
Indicate progress to the channel associated with this control.
Definition control.c:648
void stasis_app_control_shutdown(void)
Let Stasis app internals shut down.
Definition control.c:1753
int stasis_app_bridge_moh_stop(struct ast_bridge *bridge)
Breaks down MOH channels playing on the bridge created by stasis_app_bridge_moh_channel.
Definition res_stasis.c:675
int stasis_app_control_answer(struct stasis_app_control *control)
Answer the channel associated with this control.
Generic container type.
Structure that contains information about a bridge.
Definition bridge.h:355
Structure representing a snapshot of channel state.
Main Channel structure associated with a channel.
struct ast_bridge * bridge
Abstract JSON element (object, array, string, int, ...).
structure to hold extensions
Rule to check to see if an operation is allowed.
Definition stasis_app.h:355
enum stasis_app_control_channel_result(* check_rule)(const struct stasis_app_control *control)
Checks to see if an operation is allowed on the control.
Definition stasis_app.h:362
struct stasis_app_control_rule * next
Definition stasis_app.h:365
Event source information and callbacks.
Definition stasis_app.h:184
const char * scheme
The scheme to match against on [un]subscribes.
Definition stasis_app.h:186
int(* unsubscribe)(struct stasis_app *app, const char *id)
Cancel the subscription an app has to an event source.
Definition stasis_app.h:216
void(* to_json)(const struct stasis_app *app, struct ast_json *json)
Convert event source data to json.
Definition stasis_app.h:234
struct stasis_app_event_source * next
Definition stasis_app.h:237
int(* is_subscribed)(struct stasis_app *app, const char *id)
Find an event source by the given id/name.
Definition stasis_app.h:226
int(* subscribe)(struct stasis_app *app, void *obj)
Subscribe an application to an event source.
Definition stasis_app.h:206
Structure containing callbacks for Stasis message sanitization.
Definition stasis.h:200
int value
Definition syslog.c:37
static void handler(const char *name, int response_code, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Definition test_ari.c:59
static struct test_val a