summaryrefslogtreecommitdiff
path: root/include/asterisk/bridge_features.h
blob: 38b478e7ad49006f5bb73572c4174135fed3fa32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
/*
 * Asterisk -- An open source telephony toolkit.
 *
 * Copyright (C) 2009, Digium, Inc.
 *
 * Joshua Colp <jcolp@digium.com>
 *
 * See http://www.asterisk.org for more information about
 * the Asterisk project. Please do not directly contact
 * any of the maintainers of this project for assistance;
 * the project provides a web site, mailing lists and IRC
 * channels for your use.
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License Version 2. See the LICENSE file
 * at the top of the source tree.
 */

/*!
 * \file
 * \brief Channel Bridging API
 * \author Joshua Colp <jcolp@digium.com>
 */

#ifndef _ASTERISK_BRIDGING_FEATURES_H
#define _ASTERISK_BRIDGING_FEATURES_H

#include "asterisk/channel.h"

#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

/*! \brief Flags used for bridge features */
enum ast_bridge_feature_flags {
	/*! Upon channel hangup all bridge participants should be kicked out. */
	AST_BRIDGE_FLAG_DISSOLVE_HANGUP = (1 << 0),
	/*! The last channel to leave the bridge dissolves it. */
	AST_BRIDGE_FLAG_DISSOLVE_EMPTY = (1 << 1),
	/*! Move between bridging technologies as needed. */
	AST_BRIDGE_FLAG_SMART = (1 << 2),
	/*! Bridge channels cannot be merged from this bridge. */
	AST_BRIDGE_FLAG_MERGE_INHIBIT_FROM = (1 << 3),
	/*! Bridge channels cannot be merged to this bridge. */
	AST_BRIDGE_FLAG_MERGE_INHIBIT_TO = (1 << 4),
	/*! Bridge channels cannot be local channel swap optimized from this bridge. */
	AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM = (1 << 5),
	/*! Bridge channels cannot be local channel swap optimized to this bridge. */
	AST_BRIDGE_FLAG_SWAP_INHIBIT_TO = (1 << 6),
	/*! Bridge channels can be moved to another bridge only by masquerade (ConfBridge) */
	AST_BRIDGE_FLAG_MASQUERADE_ONLY = (1 << 7),
	/*! Bridge does not allow transfers of channels out */
	AST_BRIDGE_FLAG_TRANSFER_PROHIBITED = (1 << 8),
	/*! Bridge transfers require transfer of entire bridge rather than individual channels */
	AST_BRIDGE_FLAG_TRANSFER_BRIDGE_ONLY = (1 << 9),
};

/*! \brief Flags used for per bridge channel features */
enum ast_bridge_channel_feature_flags {
	/*! Upon channel hangup all bridge participants should be kicked out. */
	AST_BRIDGE_CHANNEL_FLAG_DISSOLVE_HANGUP = (1 << 0),
	/*! This channel leaves the bridge if all participants have this flag set. */
	AST_BRIDGE_CHANNEL_FLAG_LONELY = (1 << 1),
	/*! This channel cannot be moved to another bridge. */
	AST_BRIDGE_CHANNEL_FLAG_IMMOVABLE = (1 << 2),
};

/*! \brief Built in DTMF features */
enum ast_bridge_builtin_feature {
	/*! DTMF based Blind Transfer */
	AST_BRIDGE_BUILTIN_BLINDTRANSFER,
	/*! DTMF based Attended Transfer */
	AST_BRIDGE_BUILTIN_ATTENDEDTRANSFER,
	/*!
	 * DTMF based depart bridge feature
	 *
	 * \note Imparted channels are optionally hangup depending upon
	 * how it was imparted.
	 *
	 * \note Joined channels exit the bridge with
	 * BRIDGE_CHANNEL_STATE_END_WITH_DISSOLVE.
	 */
	AST_BRIDGE_BUILTIN_HANGUP,
	/*!
	 * DTMF based Park
	 *
	 * \details The bridge is parked and the channel hears the
	 * parking slot to which it was parked.
	 */
	AST_BRIDGE_BUILTIN_PARKCALL,
	/*!
	 * DTMF one-touch-record toggle using Monitor app.
	 *
	 * \note Only valid on two party bridges.
	 */
	AST_BRIDGE_BUILTIN_AUTOMON,
	/*!
	 * DTMF one-touch-record toggle using MixMonitor app.
	 *
	 * \note Only valid on two party bridges.
	 */
	AST_BRIDGE_BUILTIN_AUTOMIXMON,

	/*! End terminator for list of built in features. Must remain last. */
	AST_BRIDGE_BUILTIN_END
};

enum ast_bridge_builtin_interval {
	/*! Apply Call Duration Limits */
	AST_BRIDGE_BUILTIN_INTERVAL_LIMITS,

	/*! End terminator for list of built in interval features. Must remain last. */
	AST_BRIDGE_BUILTIN_INTERVAL_END
};

struct ast_bridge;
struct ast_bridge_channel;

/*!
 * \brief Hook callback type
 *
 * \param bridge_channel Channel executing the feature
 * \param hook_pvt Private data passed in when the hook was created
 *
 * For interval hooks:
 * \retval 0 Setup to fire again at the last interval.
 * \retval positive Setup to fire again at the new interval returned.
 * \retval -1 Remove the callback hook.
 *
 * For other hooks:
 * \retval 0 Keep the callback hook.
 * \retval -1 Remove the callback hook.
 */
typedef int (*ast_bridge_hook_callback)(struct ast_bridge_channel *bridge_channel, void *hook_pvt);

/*!
 * \brief Hook pvt destructor callback
 *
 * \param hook_pvt Private data passed in when the hook was created to destroy
 */
typedef void (*ast_bridge_hook_pvt_destructor)(void *hook_pvt);

/*!
 * \brief Talking indicator callback
 *
 * \details
 * This callback can be registered with the bridge channel in
 * order to receive updates when the bridge_channel has started
 * and stopped talking.
 *
 * \param bridge_channel Channel executing the feature
 * \param hook_pvt Private data passed in when the hook was created
 * \param talking TRUE if the channel is now talking
 *
 * \retval 0 Keep the callback hook.
 * \retval -1 Remove the callback hook.
 */
typedef int (*ast_bridge_talking_indicate_callback)(struct ast_bridge_channel *bridge_channel, void *hook_pvt, int talking);

/*!
 * \brief Move indicator callback
 *
 * \details
 * This callback can be registered with the bridge channel in order
 * to be notified when the bridge channel is being moved from one
 * bridge to another.
 *
 * \param bridge_channel The channel executing the feature
 * \param hook_pvt Private data passed in when the hook was created
 * \param src The bridge from which the bridge channel is moving
 * \param dst The bridge into which the bridge channel is moving
 *
 * \retval 0 Keep the callback hook.
 * \retval -1 Remove the callback hook.
 */
typedef int (*ast_bridge_move_indicate_callback)(struct ast_bridge_channel *bridge_channel,
		void *hook_pvt, struct ast_bridge *src, struct ast_bridge *dst);

enum ast_bridge_hook_remove_flags {
	/*! The hook is removed when the channel is pulled from the bridge. */
	AST_BRIDGE_HOOK_REMOVE_ON_PULL = (1 << 0),
	/*! The hook is removed when the bridge's personality changes. */
	AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE = (1 << 1),
};

enum ast_bridge_hook_type {
	/*! The hook type has not been specified. */
	AST_BRIDGE_HOOK_TYPE_NONE,
	AST_BRIDGE_HOOK_TYPE_DTMF,
	AST_BRIDGE_HOOK_TYPE_TIMER,
	AST_BRIDGE_HOOK_TYPE_HANGUP,
	AST_BRIDGE_HOOK_TYPE_JOIN,
	AST_BRIDGE_HOOK_TYPE_LEAVE,
	AST_BRIDGE_HOOK_TYPE_TALK,
	AST_BRIDGE_HOOK_TYPE_MOVE,
};

/*! \brief Structure that is the essence of a feature hook. */
struct ast_bridge_hook {
	/*! Callback that is called when hook is tripped */
	ast_bridge_hook_callback callback;
	/*! Callback to destroy hook_pvt data right before destruction. */
	ast_bridge_hook_pvt_destructor destructor;
	/*! Unique data that was passed into us */
	void *hook_pvt;
	/*! Flags determining when hooks should be removed from a bridge channel */
	struct ast_flags remove_flags;
	/*! What kind of hook this is. */
	enum ast_bridge_hook_type type;
};

/*!
 * \brief Maximum length of a DTMF feature string
 */
#define MAXIMUM_DTMF_FEATURE_STRING (11 + 1)

/*! Extra parameters for a DTMF feature hook. */
struct ast_bridge_hook_dtmf_parms {
	/*! DTMF String that is examined during a feature hook lookup */
	char code[MAXIMUM_DTMF_FEATURE_STRING];
};

/*! DTMF specific hook. */
struct ast_bridge_hook_dtmf {
	/*! Generic feature hook information. */
	struct ast_bridge_hook generic;
	/*! Extra parameters for a DTMF feature hook. */
	struct ast_bridge_hook_dtmf_parms dtmf;
};

enum ast_bridge_hook_timer_option {
	/*! The timer temporarily affects media. (Like a custom playfile.) */
	AST_BRIDGE_HOOK_TIMER_OPTION_MEDIA = (1 << 0),
};

/*! Extra parameters for an interval timer hook. */
struct ast_bridge_hook_timer_parms {
	/*! Time at which the hook should actually trip */
	struct timeval trip_time;
	/*! Heap index for interval hook */
	ssize_t heap_index;
	/*! Interval that the hook should execute at in milliseconds */
	unsigned int interval;
	/*! Sequence number for the hook to ensure expiration ordering */
	unsigned int seqno;
	/*! Option flags determining how callback is called. */
	unsigned int flags;
};

/*! Timer specific hook. */
struct ast_bridge_hook_timer {
	/*! Generic feature hook information. */
	struct ast_bridge_hook generic;
	/*! Extra parameters for an interval timer hook. */
	struct ast_bridge_hook_timer_parms timer;
};

/*!
 * \brief Structure that contains features information
 */
struct ast_bridge_features {
	/*! Attached DTMF feature hooks */
	struct ao2_container *dtmf_hooks;
	/*! Attached miscellaneous other hooks. */
	struct ao2_container *other_hooks;
	/*! Attached interval hooks */
	struct ast_heap *interval_hooks;
	/*! Feature flags that are enabled */
	struct ast_flags feature_flags;
	/*! Used to assign the sequence number to the next interval hook added. */
	unsigned int interval_sequence;
	/*! TRUE if feature_flags is setup */
	unsigned int usable:1;
	/*! TRUE if the channel/bridge is muted. */
	unsigned int mute:1;
	/*! TRUE if DTMF should be passed into the bridge tech.  */
	unsigned int dtmf_passthrough:1;
};

/*!
 * \brief Structure that contains configuration information for the blind transfer built in feature
 */
struct ast_bridge_features_blind_transfer {
	/*! Context to use for transfers (If not empty.) */
	char context[AST_MAX_CONTEXT];
};

/*!
 * \brief Structure that contains configuration information for the attended transfer built in feature
 */
struct ast_bridge_features_attended_transfer {
	/*! Context to use for transfers (If not empty.) */
	char context[AST_MAX_CONTEXT];
	/*! DTMF string used to abort the transfer (If not empty.) */
	char abort[MAXIMUM_DTMF_FEATURE_STRING];
	/*! DTMF string used to turn the transfer into a three way conference (If not empty.) */
	char threeway[MAXIMUM_DTMF_FEATURE_STRING];
	/*! DTMF string used to complete the transfer (If not empty.) */
	char complete[MAXIMUM_DTMF_FEATURE_STRING];
	/*! DTMF string used to swap bridged targets (If not empty.) */
	char swap[MAXIMUM_DTMF_FEATURE_STRING];
};

enum ast_bridge_features_monitor {
	/*! Toggle start/stop of Monitor/MixMonitor. */
	AUTO_MONITOR_TOGGLE,
	/*! Start Monitor/MixMonitor if not already started. */
	AUTO_MONITOR_START,
	/*! Stop Monitor/MixMonitor if not already stopped. */
	AUTO_MONITOR_STOP,
};

struct ast_bridge_features_automonitor {
	/*! Start/Stop behavior. */
	enum ast_bridge_features_monitor start_stop;
};

struct ast_bridge_features_automixmonitor {
	/*! Start/Stop behavior. */
	enum ast_bridge_features_monitor start_stop;
};

/*!
 * \brief Structure that contains configuration information for the limits feature
 */
struct ast_bridge_features_limits {
	AST_DECLARE_STRING_FIELDS(
		/*! Sound file to play when the maximum duration is reached (if empty, then nothing will be played) */
		AST_STRING_FIELD(duration_sound);
		/*! Sound file to play when the warning time is reached (if empty, then the remaining time will be played) */
		AST_STRING_FIELD(warning_sound);
		/*! Sound file to play when the call is first entered (if empty, then the remaining time will be played) */
		AST_STRING_FIELD(connect_sound);
	);
	/*! Time when the bridge will be terminated by the limits feature */
	struct timeval quitting_time;
	/*! Maximum duration that the channel is allowed to be in the bridge (specified in milliseconds) */
	unsigned int duration;
	/*! Duration into the call when warnings should begin (specified in milliseconds or 0 to disable) */
	unsigned int warning;
	/*! Interval between the warnings (specified in milliseconds or 0 to disable) */
	unsigned int frequency;
};

/*!
 * \brief Register a handler for a built in feature
 *
 * \param feature The feature that the handler will be responsible for
 * \param callback The callback function that will handle it
 * \param dtmf Default DTMF string used to activate the feature
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_features_register(AST_BRIDGE_BUILTIN_ATTENDED_TRANSFER, bridge_builtin_attended_transfer, "*1");
 * \endcode
 *
 * This registers the function bridge_builtin_attended_transfer as the function responsible for the built in
 * attended transfer feature.
 */
int ast_bridge_features_register(enum ast_bridge_builtin_feature feature, ast_bridge_hook_callback callback, const char *dtmf);

/*!
 * \brief Unregister a handler for a built in feature
 *
 * \param feature The feature to unregister
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_features_unregister(AST_BRIDGE_BUILTIN_ATTENDED_TRANSFER);
 * \endcode
 *
 * This unregisters the function that is handling the built in attended transfer feature.
 */
int ast_bridge_features_unregister(enum ast_bridge_builtin_feature feature);

/*!
 * \brief Invoke a built in feature hook now.
 *
 * \param feature The feature to invoke
 * \param bridge_channel Channel executing the feature
 * \param hook_pvt Private data passed in when the hook was created
 *
 * \note This API call is only meant to be used by bridge
 * subclasses and hook callbacks to request a builtin feature
 * hook to be executed.
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_features_do(AST_BRIDGE_BUILTIN_ATTENDED_TRANSFER, bridge_channel, hook_pvt);
 * \endcode
 */
int ast_bridge_features_do(enum ast_bridge_builtin_feature feature, struct ast_bridge_channel *bridge_channel, void *hook_pvt);

/*!
 * \brief Attach interval hooks to a bridge features structure
 *
 * \param features Bridge features structure
 * \param limits Configured limits applicable to the channel
 * \param remove_flags Dictates what situations the hook should be removed.
 *
 * \retval 0 on success
 * \retval -1 on failure
 */
typedef int (*ast_bridge_builtin_set_limits_fn)(struct ast_bridge_features *features,
		struct ast_bridge_features_limits *limits, enum ast_bridge_hook_remove_flags remove_flags);

/*!
 * \brief Register a handler for a built in interval feature
 *
 * \param interval The interval feature that the handler will be responsible for
 * \param callback the Callback function that will handle it
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_interval_register(AST_BRIDGE_BUILTIN_INTERVAL_LIMITS, bridge_builtin_set_limits);
 * \endcode
 *
 * This registers the function bridge_builtin_set_limits as the function responsible for the built in
 * duration limit feature.
 */
int ast_bridge_interval_register(enum ast_bridge_builtin_interval interval, ast_bridge_builtin_set_limits_fn callback);

/*!
 * \brief Unregisters a handler for a built in interval feature
 *
 * \param interval the interval feature to unregister
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * ast_bridge_interval_unregister(AST_BRIDGE_BULTIN_INTERVAL_LIMITS)
 * /endcode
 *
 * This unregisters the function that is handling the built in duration limit feature.
 */
int ast_bridge_interval_unregister(enum ast_bridge_builtin_interval interval);

/*!
 * \brief Attach a bridge channel join hook to a bridge features structure
 *
 * \param features Bridge features structure
 * \param callback Function to execute upon activation
 * \param hook_pvt Unique data
 * \param destructor Optional destructor callback for hook_pvt data
 * \param remove_flags Dictates what situations the hook should be removed.
 *
 * \retval 0 on success
 * \retval -1 on failure (The caller must cleanup any hook_pvt resources.)
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features features;
 * ast_bridge_features_init(&features);
 * ast_bridge_join_hook(&features, join_callback, NULL, NULL, 0);
 * \endcode
 *
 * This makes the bridging core call join_callback when a
 * channel successfully joins the bridging system.  A pointer to
 * useful data may be provided to the hook_pvt parameter.
 */
int ast_bridge_join_hook(struct ast_bridge_features *features,
	ast_bridge_hook_callback callback,
	void *hook_pvt,
	ast_bridge_hook_pvt_destructor destructor,
	enum ast_bridge_hook_remove_flags remove_flags);

/*!
 * \brief Attach a bridge channel leave hook to a bridge features structure
 *
 * \param features Bridge features structure
 * \param callback Function to execute upon activation
 * \param hook_pvt Unique data
 * \param destructor Optional destructor callback for hook_pvt data
 * \param remove_flags Dictates what situations the hook should be removed.
 *
 * \retval 0 on success
 * \retval -1 on failure (The caller must cleanup any hook_pvt resources.)
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features features;
 * ast_bridge_features_init(&features);
 * ast_bridge_leave_hook(&features, leave_callback, NULL, NULL, 0);
 * \endcode
 *
 * This makes the bridging core call leave_callback when a
 * channel successfully leaves the bridging system.  A pointer
 * to useful data may be provided to the hook_pvt parameter.
 */
int ast_bridge_leave_hook(struct ast_bridge_features *features,
	ast_bridge_hook_callback callback,
	void *hook_pvt,
	ast_bridge_hook_pvt_destructor destructor,
	enum ast_bridge_hook_remove_flags remove_flags);

/*!
 * \brief Attach a hangup hook to a bridge features structure
 *
 * \param features Bridge features structure
 * \param callback Function to execute upon activation
 * \param hook_pvt Unique data
 * \param destructor Optional destructor callback for hook_pvt data
 * \param remove_flags Dictates what situations the hook should be removed.
 *
 * \retval 0 on success
 * \retval -1 on failure (The caller must cleanup any hook_pvt resources.)
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features features;
 * ast_bridge_features_init(&features);
 * ast_bridge_hangup_hook(&features, hangup_callback, NULL, NULL, 0);
 * \endcode
 *
 * This makes the bridging core call hangup_callback if a
 * channel that has this hook hangs up.  A pointer to useful
 * data may be provided to the hook_pvt parameter.
 */
int ast_bridge_hangup_hook(struct ast_bridge_features *features,
	ast_bridge_hook_callback callback,
	void *hook_pvt,
	ast_bridge_hook_pvt_destructor destructor,
	enum ast_bridge_hook_remove_flags remove_flags);

/*!
 * \brief Attach a DTMF hook to a bridge features structure
 *
 * \param features Bridge features structure
 * \param dtmf DTMF string to be activated upon
 * \param callback Function to execute upon activation
 * \param hook_pvt Unique data
 * \param destructor Optional destructor callback for hook_pvt data
 * \param remove_flags Dictates what situations the hook should be removed.
 *
 * \retval 0 on success
 * \retval -1 on failure (The caller must cleanup any hook_pvt resources.)
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features features;
 * ast_bridge_features_init(&features);
 * ast_bridge_dtmf_hook(&features, "#", pound_callback, NULL, NULL, 0);
 * \endcode
 *
 * This makes the bridging core call pound_callback if a channel that has this
 * feature structure inputs the DTMF string '#'. A pointer to useful data may be
 * provided to the hook_pvt parameter.
 */
int ast_bridge_dtmf_hook(struct ast_bridge_features *features,
	const char *dtmf,
	ast_bridge_hook_callback callback,
	void *hook_pvt,
	ast_bridge_hook_pvt_destructor destructor,
	enum ast_bridge_hook_remove_flags remove_flags);

/*!
 * \brief Attach an interval hook to a bridge features structure
 *
 * \param features Bridge features structure
 * \param flags Interval timer callback option flags.
 * \param interval The interval that the hook should execute at in milliseconds
 * \param callback Function to execute upon activation
 * \param hook_pvt Unique data
 * \param destructor Optional destructor callback for hook_pvt data
 * \param remove_flags Dictates what situations the hook should be removed.
 *
 * \retval 0 on success
 * \retval -1 on failure (The caller must cleanup any hook_pvt resources.)
 *
 * \code
 * struct ast_bridge_features features;
 * ast_bridge_features_init(&features);
 * ast_bridge_interval_hook(&features, 1000, playback_callback, NULL, NULL, 0);
 * \endcode
 *
 * This makes the bridging core call playback_callback every second. A pointer to useful
 * data may be provided to the hook_pvt parameter.
 */
int ast_bridge_interval_hook(struct ast_bridge_features *features,
	enum ast_bridge_hook_timer_option flags,
	unsigned int interval,
	ast_bridge_hook_callback callback,
	void *hook_pvt,
	ast_bridge_hook_pvt_destructor destructor,
	enum ast_bridge_hook_remove_flags remove_flags);

/*!
 * \brief Attach a bridge channel talk detection hook to a bridge features structure
 *
 * \param features Bridge features structure
 * \param callback Function to execute upon activation
 * \param hook_pvt Unique data
 * \param destructor Optional destructor callback for hook_pvt data
 * \param remove_flags Dictates what situations the hook should be removed.
 *
 * \retval 0 on success
 * \retval -1 on failure (The caller must cleanup any hook_pvt resources.)
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features features;
 * ast_bridge_features_init(&features);
 * ast_bridge_talk_hook(&features, talk_callback, NULL, NULL, 0);
 * \endcode
 *
 * This makes the bridging technology call talk_callback when a
 * channel is recognized as starting and stopping talking.  A
 * pointer to useful data may be provided to the hook_pvt
 * parameter.
 *
 * \note This hook is currently only supported by softmix.
 */
int ast_bridge_talk_detector_hook(struct ast_bridge_features *features,
	ast_bridge_talking_indicate_callback callback,
	void *hook_pvt,
	ast_bridge_hook_pvt_destructor destructor,
	enum ast_bridge_hook_remove_flags remove_flags);

/*!
 * \brief Attach a bridge channel move detection hook to a bridge features structure
 *
 * \param features Bridge features structure
 * \param callback Function to execute upon activation
 * \param hook_pvt Unique data
 * \param destructor Optional destructor callback for hook_pvt data
 * \param remove_flags Dictates what situations the hook should be removed.
 *
 * \retval 0 on success
 * \retval -1 on failure (The caller must cleanup any hook_pvt resources.)
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features features;
 * ast_bridge_features_init(&features);
 * ast_bridge_move_hook(&features, move_callback, NULL, NULL, 0);
 * \endcode
 *
 * This makes the bridging core call \ref callback when a
 * channel is moved from one bridge to another.  A
 * pointer to useful data may be provided to the hook_pvt
 * parameter.
 */
int ast_bridge_move_hook(struct ast_bridge_features *features,
	ast_bridge_move_indicate_callback callback,
	void *hook_pvt,
	ast_bridge_hook_pvt_destructor destructor,
	enum ast_bridge_hook_remove_flags remove_flags);

/*!
 * \brief Enable a built in feature on a bridge features structure
 *
 * \param features Bridge features structure
 * \param feature Feature to enable
 * \param dtmf Optionally the DTMF stream to trigger the feature, if not specified it will be the default
 * \param config Configuration structure unique to the built in type
 * \param destructor Optional destructor callback for config data
 * \param remove_flags Dictates what situations the hook should be removed.
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features features;
 * ast_bridge_features_init(&features);
 * ast_bridge_features_enable(&features, AST_BRIDGE_BUILTIN_ATTENDEDTRANSFER, NULL, NULL, 0);
 * \endcode
 *
 * This enables the attended transfer DTMF option using the default DTMF string. An alternate
 * string may be provided using the dtmf parameter. Internally this is simply setting up a hook
 * to a built in feature callback function.
 */
int ast_bridge_features_enable(struct ast_bridge_features *features,
	enum ast_bridge_builtin_feature feature,
	const char *dtmf,
	void *config,
	ast_bridge_hook_pvt_destructor destructor,
	enum ast_bridge_hook_remove_flags remove_flags);

/*!
 * \brief Constructor function for ast_bridge_features_limits
 *
 * \param limits pointer to a ast_bridge_features_limits struct that has been allocted, but not initialized
 *
 * \retval 0 on success
 * \retval -1 on failure
 */
int ast_bridge_features_limits_construct(struct ast_bridge_features_limits *limits);

/*!
 * \brief Destructor function for ast_bridge_features_limits
 *
 * \param limits pointer to an ast_bridge_features_limits struct that needs to be destroyed
 *
 * This function does not free memory allocated to the ast_bridge_features_limits struct, it only frees elements within the struct.
 * You must still call ast_free on the struct if you allocated it with malloc.
 */
void ast_bridge_features_limits_destroy(struct ast_bridge_features_limits *limits);

/*!
 * \brief Limit the amount of time a channel may stay in the bridge and optionally play warning messages as time runs out
 *
 * \param features Bridge features structure
 * \param limits Configured limits applicable to the channel
 * \param remove_flags Dictates what situations the hook should be removed.
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features features;
 * struct ast_bridge_features_limits limits;
 * ast_bridge_features_init(&features);
 * ast_bridge_features_limits_construct(&limits);
 * ast_bridge_features_set_limits(&features, &limits, 0);
 * ast_bridge_features_limits_destroy(&limits);
 * \endcode
 *
 * This sets the maximum time the channel can be in the bridge to 10 seconds and does not play any warnings.
 *
 * \note This API call can only be used on a features structure that will be used in association with a bridge channel.
 * \note The ast_bridge_features_limits structure must remain accessible for the lifetime of the features structure.
 */
int ast_bridge_features_set_limits(struct ast_bridge_features *features, struct ast_bridge_features_limits *limits, enum ast_bridge_hook_remove_flags remove_flags);

/*!
 * \brief Set a flag on a bridge channel features structure
 *
 * \param features Bridge channel features structure
 * \param flag Flag to enable
 *
 * \return Nothing
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features features;
 * ast_bridge_features_init(&features);
 * ast_bridge_features_set_flag(&features, AST_BRIDGE_CHANNEL_FLAG_DISSOLVE_HANGUP);
 * \endcode
 *
 * This sets the AST_BRIDGE_CHANNEL_FLAG_DISSOLVE_HANGUP feature
 * to be enabled on the features structure 'features'.
 */
void ast_bridge_features_set_flag(struct ast_bridge_features *features, unsigned int flag);

/*!
 * \brief Merge one ast_bridge_features into another
 *
 * \param into The ast_bridge_features that will be merged into
 * \param from The ast_bridge_features that will be merged from
 */
void ast_bridge_features_merge(struct ast_bridge_features *into, const struct ast_bridge_features *from);

/*!
 * \brief Initialize bridge features structure
 *
 * \param features Bridge featues structure
 *
 * \retval 0 on success
 * \retval -1 on failure
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features features;
 * ast_bridge_features_init(&features);
 * \endcode
 *
 * This initializes the feature structure 'features' to have nothing enabled.
 *
 * \note This MUST be called before enabling features or flags. Failure to do so
 *       may result in a crash.
 */
int ast_bridge_features_init(struct ast_bridge_features *features);

/*!
 * \brief Clean up the contents of a bridge features structure
 *
 * \param features Bridge features structure
 *
 * \return Nothing
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features features;
 * ast_bridge_features_init(&features);
 * ast_bridge_features_cleanup(&features);
 * \endcode
 *
 * This cleans up the feature structure 'features'.
 *
 * \note This MUST be called after the features structure is done being used
 *       or a memory leak may occur.
 */
void ast_bridge_features_cleanup(struct ast_bridge_features *features);

/*!
 * \brief Allocate a new bridge features struct.
 * \since 12.0.0
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features *features;
 * features = ast_bridge_features_new();
 * ast_bridge_features_destroy(features);
 * \endcode
 *
 * \retval features New allocated features struct.
 * \retval NULL on error.
 */
struct ast_bridge_features *ast_bridge_features_new(void);

/*!
 * \brief Destroy an allocated bridge features struct.
 * \since 12.0.0
 *
 * \param features Bridge features structure
 *
 * Example usage:
 *
 * \code
 * struct ast_bridge_features *features;
 * features = ast_bridge_features_new();
 * ast_bridge_features_destroy(features);
 * \endcode
 *
 * \return Nothing
 */
void ast_bridge_features_destroy(struct ast_bridge_features *features);

#if defined(__cplusplus) || defined(c_plusplus)
}
#endif

#endif /* _ASTERISK_BRIDGING_FEATURES_H */