Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 */
272};
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 */
298};
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 Send DTMF to the channel associated with this control.
573 *
574 * \param control Control for \c res_stasis.
575 * \param dtmf DTMF string.
576 * \param before Amount of time to wait before sending DTMF digits.
577 * \param between Amount of time between each DTMF digit.
578 * \param duration Amount of time each DTMF digit lasts for.
579 * \param after Amount of time to wait after sending DTMF digits.
580 *
581 * \return 0 for success.
582 * \return -1 for error.
583 */
584int stasis_app_control_dtmf(struct stasis_app_control *control, const char *dtmf, int before, int between, unsigned int duration, int after);
585
586/*!
587 * \brief Mute the channel associated with this control.
588 *
589 * \param control Control for \c res_stasis.
590 * \param direction The direction in which the audio should be muted.
591 * \param frametype The type of stream that should be muted.
592 *
593 * \return 0 for success
594 * \return -1 for error.
595 */
596int stasis_app_control_mute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype);
597
598/*!
599 * \brief Unmute the channel associated with this control.
600 *
601 * \param control Control for \c res_stasis.
602 * \param direction The direction in which the audio should be unmuted.
603 * \param frametype The type of stream that should be unmuted.
604 *
605 * \return 0 for success
606 * \return -1 for error.
607 */
608int stasis_app_control_unmute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype);
609
610/*!
611 * \brief Answer the channel associated with this control.
612 * \param control Control for \c res_stasis.
613 * \return 0 for success.
614 * \return Non-zero for error.
615 */
617
618/*!
619 * \brief Set a variable on the channel associated with this control to value.
620 * \param control Control for \c res_stasis.
621 * \param variable The name of the variable
622 * \param value The value to set the variable to
623 *
624 * \return 0 for success.
625 * \return -1 for error.
626 */
627int stasis_app_control_set_channel_var(struct stasis_app_control *control, const char *variable, const char *value);
628
629/*!
630 * \brief Place the channel associated with the control on hold.
631 * \param control Control for \c res_stasis.
632 */
633void stasis_app_control_hold(struct stasis_app_control *control);
634
635/*!
636 * \brief Remove the channel associated with the control from hold.
637 * \param control Control for \c res_stasis.
638 */
640
641/*!
642 * \brief Play music on hold to a channel (does not affect hold status)
643 * \param control Control for \c res_stasis.
644 * \param moh_class class of music on hold to play (NULL allowed)
645 */
646void stasis_app_control_moh_start(struct stasis_app_control *control, const char *moh_class);
647
648/*!
649 * \brief Stop playing music on hold to a channel (does not affect hold status)
650 * \param control Control for \c res_stasis.
651 */
653
654/*!
655 * \brief Start playing silence to a channel.
656 * \param control Control for \c res_stasis.
657 */
659
660/*!
661 * \brief Stop playing silence to a channel.
662 * \param control Control for \c res_stasis.
663 */
665
666/*!
667 * \brief Returns the most recent snapshot for the associated channel.
668 *
669 * The returned pointer is AO2 managed, so ao2_cleanup() when you're done.
670 *
671 * \param control Control for \c res_stasis.
672 *
673 * \return Most recent snapshot. ao2_cleanup() when done.
674 * \retval NULL if channel isn't in cache.
675 */
677 const struct stasis_app_control *control);
678
679/*!
680 * \brief Publish a message to the \a control's channel's topic.
681 *
682 * \param control Control to publish to
683 * \param message Message to publish
684 */
686 struct stasis_app_control *control, struct stasis_message *message);
687
688/*!
689 * \brief Returns the stasis topic for an app
690 *
691 * \param app Stasis app to get topic of
692 */
694
695/*!
696 * \brief Queue a control frame without payload.
697 *
698 * \param control Control to publish to.
699 * \param frame_type type of control frame.
700 *
701 * \return zero on success
702 * \return non-zero on failure
703 */
706
707/*!
708 * \brief Create a bridge of the specified type.
709 *
710 * \param type The type of bridge to be created
711 * \param name Optional name to give to the bridge
712 * \param id Optional Unique ID to give to the bridge
713 *
714 * \return New bridge.
715 * \retval NULL on error.
716 */
717struct ast_bridge *stasis_app_bridge_create(const char *type, const char *name, const char *id);
718
719/*!
720 * \brief Create an invisible bridge of the specified type.
721 *
722 * \param type The type of bridge to be created
723 * \param name Optional name to give to the bridge
724 * \param id Optional Unique ID to give to the bridge
725 *
726 * \return New bridge.
727 * \retval NULL on error.
728 */
729struct ast_bridge *stasis_app_bridge_create_invisible(const char *type, const char *name, const char *id);
730
731/*!
732 * \brief Returns the bridge with the given id.
733 * \param bridge_id Uniqueid of the bridge.
734 *
735 * \return NULL bridge not created by a Stasis application, or bridge does not exist.
736 * \return Pointer to bridge.
737 */
739 const char *bridge_id);
740
741/*!
742 * \brief Finds or creates an announcer channel in a bridge that can play music on hold.
743 *
744 * \param bridge Bridge we want an MOH channel for
745 *
746 * \return NULL if the music on hold channel fails to be created or join the bridge for any reason.
747 * \return Pointer to the ;1 end of the announcer channel chain.
748 */
750 struct ast_bridge *bridge);
751
752/*!
753 * \brief Breaks down MOH channels playing on the bridge created by stasis_app_bridge_moh_channel
754 *
755 * \param bridge Bridge we want to stop the MOH on
756 *
757 * \return -1 if no moh channel could be found and stopped
758 * \return 0 on success
759 */
761 struct ast_bridge *bridge);
762
763/*!
764 * \brief Finds an existing ARI playback channel in a bridge
765 *
766 * \param bridge Bridge we want to find the playback channel for
767 *
768 * \return NULL if the playback channel can not be found for any reason.
769 * \return Pointer to the ;1 end of the playback channel chain.
770 */
772 struct ast_bridge *bridge);
773
774/*!
775 * \brief Adds a channel to the list of ARI playback channels for bridges.
776 *
777 * \param bridge Bridge we are adding the playback channel for
778 * \param chan Channel being added as a playback channel (must be ;1)
779 * \param control The app control structure for the playback channel
780 *
781 * \retval -1 failed to add channel for any reason
782 * \retval 0 on success
783 */
785 struct ast_channel *chan,
786 struct stasis_app_control *control);
787
788/*!
789 * \brief remove channel from list of ARI playback channels for bridges.
790 *
791 * \param bridge_id The unique ID of the bridge the playback channel is in.
792 * \param control The app control structure for the playback channel
793 */
795 struct stasis_app_control *control);
796
797/*!
798 * \brief Result codes used when adding/removing channels to/from bridges.
799 */
801 /*! The channel is okay to be added/removed */
803 /*! The channel is currently recording */
806
807/*!
808 * \brief Add a channel to the bridge.
809 *
810 * \param control Control whose channel should be added to the bridge
811 * \param bridge Pointer to the bridge
812 *
813 * \return non-zero on failure
814 * \return zero on success
815 */
817 struct stasis_app_control *control, struct ast_bridge *bridge);
818
819/*!
820 * \brief Remove a channel from the bridge.
821 *
822 * \param control Control whose channel should be removed from the bridge
823 * \param bridge Pointer to the bridge
824 *
825 * \return non-zero on failure
826 * \return zero on success
827 */
829 struct stasis_app_control *control, struct ast_bridge *bridge);
830
831/*!
832 * \brief Initialize bridge features into a channel control
833 *
834 * \note Bridge features on a control are destroyed after each bridge session,
835 * so new features need to be initialized before each bridge add.
836 *
837 * \param control Control in which to store the features
838 *
839 * \return non-zero on failure
840 * \return zero on success
841 */
843 struct stasis_app_control *control);
844
845/*!
846 * \brief Set whether DTMF from the channel is absorbed instead of passing through to the bridge
847 *
848 * \param control Control whose channel should have its DTMF absorbed when bridged
849 * \param absorb Whether DTMF should be absorbed (1) instead of passed through (0).
850 */
852 struct stasis_app_control *control, int absorb);
853
854/*!
855 * \brief Set whether audio from the channel is muted instead of passing through to the bridge
856 *
857 * \param control Control whose channel should have its audio muted when bridged
858 * \param mute Whether audio should be muted (1) instead of passed through (0).
859 */
861 struct stasis_app_control *control, int mute);
862
863/*!
864 * \since 18
865 * \brief Set whether COLP frames should be generated when joining the bridge
866 *
867 * \param control Control whose channel should have its COLP frames inhibited when bridged
868 * \param inhibit_colp Whether COLP frames should be generated (0) or not (1).
869 */
871 struct stasis_app_control *control, int inhibit_colp);
872
873/*!
874 * \since 12
875 * \brief Gets the bridge currently associated with a control object.
876 *
877 * \note If the bridge returned by this function is to be held for any
878 * length of time, its refcount should be incremented until the
879 * caller is finished with it.
880 *
881 * \param control Control object for the channel to query.
882 *
883 * \return Associated \ref ast_bridge.
884 * \retval NULL if not associated with a bridge.
885 */
887
888/*!
889 * \brief Destroy the bridge.
890 *
891 * \param bridge_id Uniqueid of bridge to be destroyed
892 */
893void stasis_app_bridge_destroy(const char *bridge_id);
894
895/*!
896 * \brief Get the Stasis message sanitizer for app_stasis applications
897 *
898 * \retval The stasis message sanitizer
899 */
901
902/*!
903 * \brief Indicate that this channel has had a StasisEnd published for it
904 *
905 * \param chan The channel that is exiting Stasis.
906 */
908
909/*!
910 * \brief Has this channel had a StasisEnd published on it?
911 *
912 * \param chan The channel upon which the query rests.
913 *
914 * \retval 0 No
915 * \retval 1 Yes
916 */
918
919/*!
920 * \brief Is this channel internal to Stasis?
921 *
922 * \param chan The channel to check.
923 *
924 * \retval 0 No
925 * \retval 1 Yes
926 */
928
929/*!
930 * \brief Mark this unreal channel and it's other half as being internal to Stasis.
931 *
932 * \param chan The channel to mark.
933 *
934 * \retval zero Success
935 * \retval non-zero Failure
936 */
938
939/*!
940 * \brief Mark this channel as being internal to Stasis.
941 *
942 * \param chan The channel to mark.
943 *
944 * \retval zero Success
945 * \retval non-zero Failure
946 */
948
949/*!
950 * \brief Dial a channel
951 * \param control Control for \c res_stasis.
952 * \param dialstring The dialstring to pass to the channel driver
953 * \param timeout Optional timeout in milliseconds
954 */
956 const char *dialstring, unsigned int timeout);
957
958/*!
959 * \brief Let Stasis app internals shut down
960 *
961 * This is called when res_stasis is unloaded. It ensures that
962 * the Stasis app internals can free any resources they may have
963 * allocated during the time that res_stasis was loaded.
964 */
966
967/*!
968 * \brief Enable/disable request/response and event logging on an application
969 *
970 * \param app The app to debug
971 * \param debug If non-zero, enable debugging. If zero, disable.
972 */
973void stasis_app_set_debug(struct stasis_app *app, int debug);
974
975/*!
976 * \brief Enable/disable request/response and event logging on an application
977 *
978 * \param app_name The app name to debug
979 * \param debug If non-zero, enable debugging. If zero, disable.
980 */
981void stasis_app_set_debug_by_name(const char *app_name, int debug);
982
983/*!
984 * \brief Get debug status of an application
985 *
986 * \param app The app to check
987 * \return The debug flag for the app || the global debug flag
988 */
990
991/*!
992 * \brief Get debug status of an application
993 *
994 * \param app_name The app_name to check
995 * \return The debug flag for the app || the global debug flag
996 */
998
999/*!
1000 * \brief Enable/disable request/response and event logging on all applications
1001 *
1002 * \param debug If non-zero, enable debugging. If zero, disable.
1003 */
1005
1006struct ast_cli_args;
1007
1008/*!
1009 * \brief Dump properties of a \c stasis_app to the CLI
1010 *
1011 * \param app The application
1012 * \param a The CLI arguments
1013 */
1014void stasis_app_to_cli(const struct stasis_app *app, struct ast_cli_args *a);
1015
1016/*!
1017 * \brief Convert and add the app's event type filter(s) to the given json object.
1018 *
1019 * \param app The application
1020 * \param json The json object to add the filter data to
1021 *
1022 * \return The given json object
1023 */
1024struct ast_json *stasis_app_event_filter_to_json(struct stasis_app *app, struct ast_json *json);
1025
1026/*!
1027 * \brief Set the application's event type filter
1028 *
1029 * \param app The application
1030 * \param filter The allowed and/or disallowed event filter
1031 *
1032 * \return 0 if successfully set
1033 */
1035
1036/*!
1037 * \brief Check if the given event should be filtered.
1038 *
1039 * Attempts first to find the event in the application's disallowed events list.
1040 * If found then the event won't be sent to the remote. If not found in the
1041 * disallowed list then a search is done to see if it can be found in the allowed
1042 * list. If found the event message is sent, otherwise it is not sent.
1043 *
1044 * \param app_name The application name
1045 * \param event The event to check
1046 *
1047 * \return True if allowed, false otherwise
1048 */
1049int stasis_app_event_allowed(const char *app_name, struct ast_json *event);
1050
1051/*! @} */
1052
1053#endif /* _ASTERISK_STASIS_APP_H */
static const char app[]
Definition: app_adsiprog.c:56
enum queue_result id
Definition: app_queue.c:1808
static int priority
static const char type[]
Definition: chan_ooh323.c:109
General Asterisk PBX channel definitions.
frame_type
Definition: codec_builtin.c:44
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)
Definition: func_strings.c:899
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.
Definition: linkedlists.h:410
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
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:1500
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:769
struct ast_json * stasis_app_object_to_json(struct stasis_app *app)
Return the JSON representation of a Stasis application.
Definition: res_stasis.c:1945
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.
Definition: res_stasis.c:2343
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:806
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:1460
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:896
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:1475
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?
Definition: res_stasis.c:2401
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:685
void stasis_app_control_unhold(struct stasis_app_control *control)
Remove the channel associated with the control from hold.
Definition: control.c:787
int stasis_app_send(const char *app_name, struct ast_json *message)
Send a message to the given Stasis application.
Definition: res_stasis.c:1704
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:1413
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.
Definition: res_stasis.c:2124
int stasis_app_is_registered(const char *name)
Check if a Stasis application is registered.
Definition: res_stasis.c:1747
void stasis_app_control_silence_start(struct stasis_app_control *control)
Start playing silence to a channel.
Definition: control.c:858
void stasis_app_control_silence_stop(struct stasis_app_control *control)
Stop playing silence to a channel.
Definition: control.c:881
void stasis_app_channel_set_stasis_end_published(struct ast_channel *chan)
Indicate that this channel has had a StasisEnd published for it.
Definition: res_stasis.c:1332
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:901
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.
Definition: res_stasis.c:1955
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.
Definition: res_stasis.c:1838
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:1466
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:824
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.
Definition: res_stasis.c:2390
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:800
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:891
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:657
void stasis_app_unregister_event_source(struct stasis_app_event_source *obj)
Unregister an application event source.
Definition: res_stasis.c:1902
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:1494
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.
Definition: res_stasis.c:2063
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.
Definition: res_stasis.c:1295
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)
Definition: res_stasis.c:2174
void stasis_app_set_global_debug(int debug)
Enable/disable request/response and event logging on all applications.
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.
Definition: res_stasis.c:1323
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.
Definition: res_stasis.c:2367
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:1506
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:1450
struct ast_bridge * stasis_app_get_bridge(struct stasis_app_control *control)
Gets the bridge currently associated with a control object.
Definition: control.c:957
int stasis_app_control_bridge_features_init(struct stasis_app_control *control)
Initialize bridge features into a channel control.
Definition: control.c:1481
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:731
void stasis_app_unregister(const char *app_name)
Unregister a Stasis application and unsubscribe from all event sources.
Definition: res_stasis.c:1848
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.
Definition: res_stasis.c:2165
void stasis_app_control_hold(struct stasis_app_control *control)
Place the channel associated with the control on hold.
Definition: control.c:774
struct stasis_app * stasis_app_get_by_name(const char *name)
Retrieve a handle to a Stasis application by its name.
Definition: res_stasis.c:1742
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.
Definition: res_stasis.c:1895
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:785
struct ao2_container * stasis_app_get_all(void)
Gets the names of all registered Stasis applications.
Definition: res_stasis.c:1769
int stasis_app_control_is_done(struct stasis_app_control *control)
Check if a control is marked as done.
Definition: res_stasis.c:1318
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:1696
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:886
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:800
@ STASIS_APP_CHANNEL_RECORDING
Definition: stasis_app.h:804
@ STASIS_APP_CHANNEL_OKAY
Definition: stasis_app.h:802
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?
Definition: res_stasis.c:1344
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:737
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.
Definition: res_stasis.c:1843
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
void stasis_app_control_shutdown(void)
Let Stasis app internals shut down.
Definition: control.c:1710
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:353
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, ...).
Definition: astman.c:222
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