Asterisk - The Open Source Telephony Project GIT-master-7e7a603
channel.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2006, Digium, Inc.
5 *
6 * Mark Spencer <markster@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/*! \file
20 *
21 * \brief Channel Management
22 *
23 * \author Mark Spencer <markster@digium.com>
24 */
25
26/*** MODULEINFO
27 <support_level>core</support_level>
28 ***/
29
30#include "asterisk.h"
31
32#include "asterisk/_private.h"
33
34#include <sys/time.h>
35#include <signal.h>
36#include <math.h>
37
38#include "asterisk/paths.h" /* use ast_config_AST_SYSTEM_NAME */
39
40#include "asterisk/pbx.h"
41#include "asterisk/frame.h"
42#include "asterisk/mod_format.h"
43#include "asterisk/sched.h"
44#include "asterisk/channel.h"
46#include "asterisk/say.h"
47#include "asterisk/file.h"
48#include "asterisk/cli.h"
49#include "asterisk/translate.h"
50#include "asterisk/manager.h"
51#include "asterisk/chanvars.h"
54#include "asterisk/causes.h"
55#include "asterisk/callerid.h"
56#include "asterisk/utils.h"
57#include "asterisk/lock.h"
58#include "asterisk/app.h"
59#include "asterisk/transcap.h"
63#include "asterisk/audiohook.h"
64#include "asterisk/framehook.h"
65#include "asterisk/timing.h"
66#include "asterisk/autochan.h"
70#include "asterisk/features.h"
71#include "asterisk/bridge.h"
72#include "asterisk/test.h"
75#include "asterisk/stream.h"
76#include "asterisk/message.h"
77
78/*** DOCUMENTATION
79 ***/
80
81#if defined(KEEP_TILL_CHANNEL_PARTY_NUMBER_INFO_NEEDED)
82#if defined(HAVE_PRI)
83#include "libpri.h"
84#endif /* defined(HAVE_PRI) */
85#endif /* defined(KEEP_TILL_CHANNEL_PARTY_NUMBER_INFO_NEEDED) */
86
87/* uncomment if you have problems with 'monitoring' synchronized files */
88#if 0
89#define MONITOR_CONSTANT_DELAY
90#define MONITOR_DELAY 150 * 8 /*!< 150 ms of MONITORING DELAY */
91#endif
92
93static int chancount;
94
95unsigned long global_fin, global_fout;
96
98#define STATE2STR_BUFSIZE 32
99
100/*! Default amount of time to use when emulating a DTMF digit as a begin and end
101 * 100ms */
102#define AST_DEFAULT_EMULATE_DTMF_DURATION 100
103
104/*! Default amount of time to use when emulating an MF digit as a begin and end
105 * 55ms */
106#define DEFAULT_EMULATE_MF_DURATION 55
107
108#define DEFAULT_AMA_FLAGS AST_AMA_DOCUMENTATION
109
110/*! Minimum amount of time between the end of the last digit and the beginning
111 * of a new one - 45ms */
112#define AST_MIN_DTMF_GAP 45
113
114/*! \brief List of channel drivers */
115struct chanlist {
116 const struct ast_channel_tech *tech;
118};
119
120/*! \brief the list of registered channel types */
122
123/*! \brief All active channels on the system */
124static struct ao2_container *channels;
125
126/*! \brief map AST_CAUSE's to readable string representations
127 *
128 * \ref causes.h
129*/
131 int cause;
132 const char *name;
133 const char *desc;
134};
135
136static const struct causes_map causes[] = {
137 { AST_CAUSE_UNALLOCATED, "UNALLOCATED", "Unallocated (unassigned) number" },
138 { AST_CAUSE_NO_ROUTE_TRANSIT_NET, "NO_ROUTE_TRANSIT_NET", "No route to specified transmit network" },
139 { AST_CAUSE_NO_ROUTE_DESTINATION, "NO_ROUTE_DESTINATION", "No route to destination" },
140 { AST_CAUSE_MISDIALLED_TRUNK_PREFIX, "MISDIALLED_TRUNK_PREFIX", "Misdialed trunk prefix" },
141 { AST_CAUSE_CHANNEL_UNACCEPTABLE, "CHANNEL_UNACCEPTABLE", "Channel unacceptable" },
142 { AST_CAUSE_CALL_AWARDED_DELIVERED, "CALL_AWARDED_DELIVERED", "Call awarded and being delivered in an established channel" },
143 { AST_CAUSE_PRE_EMPTED, "PRE_EMPTED", "Pre-empted" },
144 { AST_CAUSE_NUMBER_PORTED_NOT_HERE, "NUMBER_PORTED_NOT_HERE", "Number ported elsewhere" },
145 { AST_CAUSE_NORMAL_CLEARING, "NORMAL_CLEARING", "Normal Clearing" },
146 { AST_CAUSE_USER_BUSY, "USER_BUSY", "User busy" },
147 { AST_CAUSE_NO_USER_RESPONSE, "NO_USER_RESPONSE", "No user responding" },
148 { AST_CAUSE_NO_ANSWER, "NO_ANSWER", "User alerting, no answer" },
149 { AST_CAUSE_SUBSCRIBER_ABSENT, "SUBSCRIBER_ABSENT", "Subscriber absent" },
150 { AST_CAUSE_CALL_REJECTED, "CALL_REJECTED", "Call Rejected" },
151 { AST_CAUSE_NUMBER_CHANGED, "NUMBER_CHANGED", "Number changed" },
152 { AST_CAUSE_REDIRECTED_TO_NEW_DESTINATION, "REDIRECTED_TO_NEW_DESTINATION", "Redirected to new destination" },
153 { AST_CAUSE_ANSWERED_ELSEWHERE, "ANSWERED_ELSEWHERE", "Answered elsewhere" },
154 { AST_CAUSE_DESTINATION_OUT_OF_ORDER, "DESTINATION_OUT_OF_ORDER", "Destination out of order" },
155 { AST_CAUSE_INVALID_NUMBER_FORMAT, "INVALID_NUMBER_FORMAT", "Invalid number format" },
156 { AST_CAUSE_FACILITY_REJECTED, "FACILITY_REJECTED", "Facility rejected" },
157 { AST_CAUSE_RESPONSE_TO_STATUS_ENQUIRY, "RESPONSE_TO_STATUS_ENQUIRY", "Response to STATus ENQuiry" },
158 { AST_CAUSE_NORMAL_UNSPECIFIED, "NORMAL_UNSPECIFIED", "Normal, unspecified" },
159 { AST_CAUSE_NORMAL_CIRCUIT_CONGESTION, "NORMAL_CIRCUIT_CONGESTION", "Circuit/channel congestion" },
160 { AST_CAUSE_NETWORK_OUT_OF_ORDER, "NETWORK_OUT_OF_ORDER", "Network out of order" },
161 { AST_CAUSE_NORMAL_TEMPORARY_FAILURE, "NORMAL_TEMPORARY_FAILURE", "Temporary failure" },
162 { AST_CAUSE_SWITCH_CONGESTION, "SWITCH_CONGESTION", "Switching equipment congestion" },
163 { AST_CAUSE_ACCESS_INFO_DISCARDED, "ACCESS_INFO_DISCARDED", "Access information discarded" },
164 { AST_CAUSE_REQUESTED_CHAN_UNAVAIL, "REQUESTED_CHAN_UNAVAIL", "Requested channel not available" },
165 { AST_CAUSE_FACILITY_NOT_SUBSCRIBED, "FACILITY_NOT_SUBSCRIBED", "Facility not subscribed" },
166 { AST_CAUSE_OUTGOING_CALL_BARRED, "OUTGOING_CALL_BARRED", "Outgoing call barred" },
167 { AST_CAUSE_INCOMING_CALL_BARRED, "INCOMING_CALL_BARRED", "Incoming call barred" },
168 { AST_CAUSE_BEARERCAPABILITY_NOTAUTH, "BEARERCAPABILITY_NOTAUTH", "Bearer capability not authorized" },
169 { AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, "BEARERCAPABILITY_NOTAVAIL", "Bearer capability not available" },
170 { AST_CAUSE_BEARERCAPABILITY_NOTIMPL, "BEARERCAPABILITY_NOTIMPL", "Bearer capability not implemented" },
171 { AST_CAUSE_CHAN_NOT_IMPLEMENTED, "CHAN_NOT_IMPLEMENTED", "Channel not implemented" },
172 { AST_CAUSE_FACILITY_NOT_IMPLEMENTED, "FACILITY_NOT_IMPLEMENTED", "Facility not implemented" },
173 { AST_CAUSE_INVALID_CALL_REFERENCE, "INVALID_CALL_REFERENCE", "Invalid call reference value" },
174 { AST_CAUSE_INCOMPATIBLE_DESTINATION, "INCOMPATIBLE_DESTINATION", "Incompatible destination" },
175 { AST_CAUSE_INVALID_MSG_UNSPECIFIED, "INVALID_MSG_UNSPECIFIED", "Invalid message unspecified" },
176 { AST_CAUSE_MANDATORY_IE_MISSING, "MANDATORY_IE_MISSING", "Mandatory information element is missing" },
177 { AST_CAUSE_MESSAGE_TYPE_NONEXIST, "MESSAGE_TYPE_NONEXIST", "Message type nonexist." },
178 { AST_CAUSE_WRONG_MESSAGE, "WRONG_MESSAGE", "Wrong message" },
179 { AST_CAUSE_IE_NONEXIST, "IE_NONEXIST", "Info. element nonexist or not implemented" },
180 { AST_CAUSE_INVALID_IE_CONTENTS, "INVALID_IE_CONTENTS", "Invalid information element contents" },
181 { AST_CAUSE_WRONG_CALL_STATE, "WRONG_CALL_STATE", "Message not compatible with call state" },
182 { AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE, "RECOVERY_ON_TIMER_EXPIRE", "Recover on timer expiry" },
183 { AST_CAUSE_MANDATORY_IE_LENGTH_ERROR, "MANDATORY_IE_LENGTH_ERROR", "Mandatory IE length error" },
184 { AST_CAUSE_PROTOCOL_ERROR, "PROTOCOL_ERROR", "Protocol error, unspecified" },
185 { AST_CAUSE_INTERWORKING, "INTERWORKING", "Interworking, unspecified" },
186};
187
189{
190 struct chanlist *cl;
191 struct ast_variable *var = NULL, *prev = NULL;
192
194 AST_RWLIST_TRAVERSE(&backends, cl, list) {
195 if (prev) {
196 if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description, "")))
197 prev = prev->next;
198 } else {
199 var = ast_variable_new(cl->tech->type, cl->tech->description, "");
200 prev = var;
201 }
202 }
204
205 return var;
206}
207
208#if defined(KEEP_TILL_CHANNEL_PARTY_NUMBER_INFO_NEEDED)
209static const char *party_number_ton2str(int ton)
210{
211#if defined(HAVE_PRI)
212 switch ((ton >> 4) & 0x07) {
213 case PRI_TON_INTERNATIONAL:
214 return "International";
215 case PRI_TON_NATIONAL:
216 return "National";
217 case PRI_TON_NET_SPECIFIC:
218 return "Network Specific";
219 case PRI_TON_SUBSCRIBER:
220 return "Subscriber";
221 case PRI_TON_ABBREVIATED:
222 return "Abbreviated";
223 case PRI_TON_RESERVED:
224 return "Reserved";
225 case PRI_TON_UNKNOWN:
226 default:
227 break;
228 }
229#endif /* defined(HAVE_PRI) */
230 return "Unknown";
231}
232#endif /* defined(KEEP_TILL_CHANNEL_PARTY_NUMBER_INFO_NEEDED) */
233
234#if defined(KEEP_TILL_CHANNEL_PARTY_NUMBER_INFO_NEEDED)
235static const char *party_number_plan2str(int plan)
236{
237#if defined(HAVE_PRI)
238 switch (plan & 0x0F) {
239 default:
240 case PRI_NPI_UNKNOWN:
241 break;
242 case PRI_NPI_E163_E164:
243 return "Public (E.163/E.164)";
244 case PRI_NPI_X121:
245 return "Data (X.121)";
246 case PRI_NPI_F69:
247 return "Telex (F.69)";
248 case PRI_NPI_NATIONAL:
249 return "National Standard";
250 case PRI_NPI_PRIVATE:
251 return "Private";
252 case PRI_NPI_RESERVED:
253 return "Reserved";
254 }
255#endif /* defined(HAVE_PRI) */
256 return "Unknown";
257}
258#endif /* defined(KEEP_TILL_CHANNEL_PARTY_NUMBER_INFO_NEEDED) */
259
260/*! \brief Show channel types - CLI command */
261static char *handle_cli_core_show_channeltypes(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
262{
263#define FORMAT "%-15.15s %-40.40s %-13.13s %-13.13s %-13.13s %-13.13s\n"
264 struct chanlist *cl;
265 int count_chan = 0;
266
267 switch (cmd) {
268 case CLI_INIT:
269 e->command = "core show channeltypes";
270 e->usage =
271 "Usage: core show channeltypes\n"
272 " Lists available channel types registered in your\n"
273 " Asterisk server.\n";
274 return NULL;
275 case CLI_GENERATE:
276 return NULL;
277 }
278
279 if (a->argc != 3)
280 return CLI_SHOWUSAGE;
281
282 ast_cli(a->fd, FORMAT, "Type", "Description", "Devicestate", "Presencestate", "Indications", "Transfer");
283 ast_cli(a->fd, FORMAT, "-------------", "-------------", "-------------", "-------------", "-------------", "-------------");
284
287 ast_cli(a->fd, FORMAT, cl->tech->type, cl->tech->description,
288 (cl->tech->devicestate) ? "yes" : "no",
289 (cl->tech->presencestate) ? "yes" : "no",
290 (cl->tech->indicate) ? "yes" : "no",
291 (cl->tech->transfer) ? "yes" : "no");
292 count_chan++;
293 }
295
296 ast_cli(a->fd, "----------\n%d channel drivers registered.\n", count_chan);
297
298 return CLI_SUCCESS;
299
300#undef FORMAT
301}
302
304{
305 struct chanlist *cl;
306 int wordlen;
307
308 if (a->pos != 3) {
309 return NULL;
310 }
311
312 wordlen = strlen(a->word);
313
316 if (!strncasecmp(a->word, cl->tech->type, wordlen)) {
318 }
319 }
321
322 return NULL;
323}
324
325/*! \brief Show details about a channel driver - CLI command */
326static char *handle_cli_core_show_channeltype(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
327{
328 struct chanlist *cl = NULL;
330
331 switch (cmd) {
332 case CLI_INIT:
333 e->command = "core show channeltype";
334 e->usage =
335 "Usage: core show channeltype <name>\n"
336 " Show details about the specified channel type, <name>.\n";
337 return NULL;
338 case CLI_GENERATE:
339 return complete_channeltypes(a);
340 }
341
342 if (a->argc != 4)
343 return CLI_SHOWUSAGE;
344
346
347 AST_RWLIST_TRAVERSE(&backends, cl, list) {
348 if (!strncasecmp(cl->tech->type, a->argv[3], strlen(cl->tech->type)))
349 break;
350 }
351
352
353 if (!cl) {
354 ast_cli(a->fd, "\n%s is not a registered channel driver.\n", a->argv[3]);
356 return CLI_FAILURE;
357 }
358
359 ast_cli(a->fd,
360 "-- Info about channel driver: %s --\n"
361 " Device State: %s\n"
362 "Presence State: %s\n"
363 " Indication: %s\n"
364 " Transfer : %s\n"
365 " Capabilities: %s\n"
366 " Digit Begin: %s\n"
367 " Digit End: %s\n"
368 " Send HTML : %s\n"
369 " Image Support: %s\n"
370 " Text Support: %s\n",
371 cl->tech->type,
372 (cl->tech->devicestate) ? "yes" : "no",
373 (cl->tech->presencestate) ? "yes" : "no",
374 (cl->tech->indicate) ? "yes" : "no",
375 (cl->tech->transfer) ? "yes" : "no",
376 ast_format_cap_get_names(cl->tech->capabilities, &codec_buf),
377 (cl->tech->send_digit_begin) ? "yes" : "no",
378 (cl->tech->send_digit_end) ? "yes" : "no",
379 (cl->tech->send_html) ? "yes" : "no",
380 (cl->tech->send_image) ? "yes" : "no",
381 (cl->tech->send_text) ? "yes" : "no"
382
383 );
384
386
387 return CLI_SUCCESS;
388}
389
390static struct ast_cli_entry cli_channel[] = {
391 AST_CLI_DEFINE(handle_cli_core_show_channeltypes, "List available channel types"),
392 AST_CLI_DEFINE(handle_cli_core_show_channeltype, "Give more details on that channel type")
393};
394
395static struct ast_frame *kill_read(struct ast_channel *chan)
396{
397 /* Hangup channel. */
398 return NULL;
399}
400
401static struct ast_frame *kill_exception(struct ast_channel *chan)
402{
403 /* Hangup channel. */
404 return NULL;
405}
406
407static int kill_write(struct ast_channel *chan, struct ast_frame *frame)
408{
409 /* Hangup channel. */
410 return -1;
411}
412
413static int kill_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
414{
415 /* No problem fixing up the channel. */
416 return 0;
417}
418
419static int kill_hangup(struct ast_channel *chan)
420{
422 return 0;
423}
424
425/*!
426 * \brief Kill the channel channel driver technology descriptor.
427 *
428 * \details
429 * The purpose of this channel technology is to encourage the
430 * channel to hangup as quickly as possible.
431 *
432 * \note Used by DTMF atxfer and zombie channels.
433 */
435 .type = "Kill",
436 .description = "Kill channel (should not see this)",
437 .read = kill_read,
438 .exception = kill_exception,
439 .write = kill_write,
440 .fixup = kill_fixup,
441 .hangup = kill_hangup,
442};
443
444/*! \brief Checks to see if a channel is needing hang up */
446{
447 if (ast_channel_softhangup_internal_flag(chan)) /* yes if soft hangup flag set */
448 return 1;
449 if (ast_tvzero(*ast_channel_whentohangup(chan))) /* no if no hangup scheduled */
450 return 0;
451 if (ast_tvdiff_ms(*ast_channel_whentohangup(chan), ast_tvnow()) > 0) /* no if hangup time has not come yet. */
452 return 0;
453 ast_debug(4, "Hangup time has come: %" PRIi64 "\n", ast_tvdiff_ms(*ast_channel_whentohangup(chan), ast_tvnow()));
454 ast_test_suite_event_notify("HANGUP_TIME", "Channel: %s", ast_channel_name(chan));
456 return 1;
457}
458
460{
461 int res;
462 ast_channel_lock(chan);
463 res = ast_check_hangup(chan);
464 ast_channel_unlock(chan);
465 return res;
466}
467
469{
470 ast_channel_lock(chan);
471
472 if (causecode > 0) {
473 ast_debug(1, "Setting hangupcause of channel %s to %d (is %d now)\n",
474 ast_channel_name(chan), causecode, ast_channel_hangupcause(chan));
475
476 ast_channel_hangupcause_set(chan, causecode);
477 }
478
480
481 ast_channel_unlock(chan);
482}
483
484static int ast_channel_softhangup_cb(void *obj, void *arg, int flags)
485{
486 struct ast_channel *chan = obj;
487
489
490 return 0;
491}
492
494{
496}
497
498/*! \brief returns number of active/allocated channels */
500{
502}
503
505{
507}
508
509/*! \brief Set when to hangup channel */
510void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset)
511{
512 if (ast_tvzero(offset)) {
513 ast_channel_whentohangup_set(chan, &offset);
514 } else {
515 struct timeval tv = ast_tvadd(offset, ast_tvnow());
517 }
519 return;
520}
521
522/*! \brief Compare a offset with when to hangup channel */
523int ast_channel_cmpwhentohangup_tv(struct ast_channel *chan, struct timeval offset)
524{
525 struct timeval whentohangup;
526
528 return ast_tvzero(offset) ? 0 : -1;
529
530 if (ast_tvzero(offset))
531 return 1;
532
533 whentohangup = ast_tvadd(offset, ast_tvnow());
534
535 return ast_tvdiff_ms(whentohangup, *ast_channel_whentohangup(chan));
536}
537
538/*! \brief Register a new telephony channel in Asterisk */
540{
541 struct chanlist *chan;
542
544
546 if (!strcasecmp(tech->type, chan->tech->type)) {
547 ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type);
549 return -1;
550 }
551 }
552
553 if (!(chan = ast_calloc(1, sizeof(*chan)))) {
555 return -1;
556 }
557 chan->tech = tech;
559
560 ast_debug(5, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description);
561
562 ast_verb(5, "Registered channel type '%s' (%s)\n", chan->tech->type, chan->tech->description);
563
565
566 return 0;
567}
568
569/*! \brief Unregister channel driver */
571{
572 struct chanlist *chan;
573
574 ast_debug(5, "Unregistering channel type '%s'\n", tech->type);
575
577
579 if (chan->tech == tech) {
581 ast_free(chan);
582 ast_verb(5, "Unregistered channel type '%s'\n", tech->type);
583 break;
584 }
585 }
587
589}
590
591/*! \brief Get handle to channel driver based on name */
593{
594 struct chanlist *chanls;
595 const struct ast_channel_tech *ret = NULL;
596
598
599 AST_RWLIST_TRAVERSE(&backends, chanls, list) {
600 if (!strcasecmp(name, chanls->tech->type)) {
601 ret = chanls->tech;
602 break;
603 }
604 }
605
607
608 return ret;
609}
610
611/*! \brief Gives the string form of a given hangup cause */
612const char *ast_cause2str(int cause)
613{
614 int x;
615
616 for (x = 0; x < ARRAY_LEN(causes); x++) {
617 if (causes[x].cause == cause)
618 return causes[x].desc;
619 }
620
621 return "Unknown";
622}
623
624/*! \brief Convert a symbolic hangup cause to number */
625int ast_str2cause(const char *name)
626{
627 int x;
628
629 for (x = 0; x < ARRAY_LEN(causes); x++)
630 if (!strncasecmp(causes[x].name, name, strlen(causes[x].name)))
631 return causes[x].cause;
632
633 return -1;
634}
635
637{
638 char *buf;
639
640 switch (state) {
641 case AST_STATE_DOWN:
642 return "Down";
644 return "Rsrvd";
646 return "OffHook";
648 return "Dialing";
649 case AST_STATE_RING:
650 return "Ring";
652 return "Ringing";
653 case AST_STATE_UP:
654 return "Up";
655 case AST_STATE_BUSY:
656 return "Busy";
658 return "Dialing Offhook";
660 return "Pre-ring";
661 case AST_STATE_MUTE:
662 return "Mute";
663 default:
665 return "Unknown";
666 snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%u)", state);
667 return buf;
668 }
669}
670
671/*! \brief Gives the string form of a given transfer capability */
672char *ast_transfercapability2str(int transfercapability)
673{
674 switch (transfercapability) {
676 return "SPEECH";
678 return "DIGITAL";
680 return "RESTRICTED_DIGITAL";
682 return "3K1AUDIO";
684 return "DIGITAL_W_TONES";
686 return "VIDEO";
687 default:
688 return "UNKNOWN";
689 }
690}
691
692/*! \brief Channel technology used to extract a channel from a running application. The
693 * channel created with this technology will be immediately hung up - most external
694 * applications won't ever want to see this.
695 */
696static const struct ast_channel_tech surrogate_tech = {
697 .type = "Surrogate",
698 .description = "Surrogate channel used to pull channel from an application",
699 .properties = AST_CHAN_TP_INTERNAL,
700};
701
702static const struct ast_channel_tech null_tech = {
703 .type = "NULL",
704 .description = "Null channel (should not see this)",
705};
706
707static void ast_channel_destructor(void *obj);
708static void ast_dummy_channel_destructor(void *obj);
709static int ast_channel_by_uniqueid_cb(void *obj, void *arg, void *data, int flags);
710
711static int does_id_conflict(const char *uniqueid)
712{
713 struct ast_channel *conflict;
714 size_t length = 0;
715
717 return 0;
718 }
719
721 if (conflict) {
722 ast_log(LOG_ERROR, "Channel Unique ID '%s' already in use by channel %s(%p)\n",
723 uniqueid, ast_channel_name(conflict), conflict);
724 ast_channel_unref(conflict);
725 return 1;
726 }
727
728 return 0;
729}
730
731/*! \brief Create a new channel structure */
732static struct ast_channel *__attribute__((format(printf, 15, 0)))
733__ast_channel_alloc_ap(int needqueue, int state, const char *cid_num, const char *cid_name,
734 const char *acctcode, const char *exten, const char *context, const struct ast_assigned_ids *assignedids,
735 const struct ast_channel *requestor, enum ama_flags amaflag, struct ast_endpoint *endpoint,
736 const char *file, int line,
737 const char *function, const char *name_fmt, va_list ap)
738{
739 struct ast_channel *tmp;
740 struct varshead *headp;
741 char *tech = "", *tech2 = NULL;
742 struct ast_format_cap *nativeformats;
743 struct ast_sched_context *schedctx;
744 struct ast_timer *timer;
745 struct timeval now;
746 const struct ast_channel_tech *channel_tech;
747 struct ast_stream_topology *topology;
748
749 /* If shutting down, don't allocate any new channels */
750 if (ast_shutting_down()) {
751 ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n");
752 return NULL;
753 }
754
756 file, line, function);
757 if (!tmp) {
758 /* Channel structure allocation failure. */
759 return NULL;
760 }
761
763
764 /*
765 * Init file descriptors to unopened state so
766 * the destructor can know not to close them.
767 */
771
773 if (!nativeformats) {
774 /*
775 * Aborting the channel creation. We do not need to complete staging
776 * the channel snapshot because the channel has not been finalized or
777 * linked into the channels container yet. Nobody else knows about
778 * this channel nor will anybody ever know about it.
779 */
780 return ast_channel_unref(tmp);
781 }
782 ast_format_cap_append(nativeformats, ast_format_none, 0);
783 ast_channel_nativeformats_set(tmp, nativeformats);
784 ao2_ref(nativeformats, -1);
785
790
791 if (!(schedctx = ast_sched_context_create())) {
792 ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n");
793 /* See earlier channel creation abort comment above. */
794 return ast_channel_unref(tmp);
795 }
796 ast_channel_sched_set(tmp, schedctx);
797
803
804 if (cid_name) {
807 if (!ast_channel_caller(tmp)->id.name.str) {
808 /* See earlier channel creation abort comment above. */
809 return ast_channel_unref(tmp);
810 }
811 }
812 if (cid_num) {
815 if (!ast_channel_caller(tmp)->id.number.str) {
816 /* See earlier channel creation abort comment above. */
817 return ast_channel_unref(tmp);
818 }
819 }
820
821 if ((timer = ast_timer_open())) {
823 if (strcmp(ast_timer_get_name(ast_channel_timer(tmp)), "timerfd")) {
824 needqueue = 0;
825 }
827 }
828
829 if (needqueue && ast_channel_internal_alertpipe_init(tmp)) {
830 /* See earlier channel creation abort comment above. */
831 return ast_channel_unref(tmp);
832 }
833
834 if (!(topology = ast_stream_topology_alloc())) {
835 return ast_channel_unref(tmp);
836 }
838
839 /* Always watch the alertpipe */
841 /* And timing pipe */
843
844 /* Initial state */
847
850
853
854 now = ast_tvnow();
856
858
859 if (!ast_strlen_zero(name_fmt)) {
860 char *slash, *slash2;
861 /* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call.
862 * And they all use slightly different formats for their name string.
863 * This means, to set the name here, we have to accept variable args, and call the string_field_build from here.
864 * This means, that the stringfields must have a routine that takes the va_lists directly, and
865 * uses them to build the string, instead of forming the va_lists internally from the vararg ... list.
866 * This new function was written so this can be accomplished.
867 */
868 ast_channel_name_build_va(tmp, name_fmt, ap);
870 if ((slash = strchr(tech, '/'))) {
871 if ((slash2 = strchr(slash + 1, '/'))) {
872 tech2 = slash + 1;
873 *slash2 = '\0';
874 }
875 *slash = '\0';
876 }
877 } else {
878 /*
879 * Start the string with '-' so it becomes an empty string
880 * in the destructor.
881 */
882 ast_channel_name_set(tmp, "-**Unknown**");
883 }
884
885 if (amaflag != AST_AMA_NONE) {
887 } else {
889 }
890
891 if (!ast_strlen_zero(acctcode)) {
892 ast_channel_accountcode_set(tmp, acctcode);
893 }
894 ast_channel_language_set(tmp, ast_defaultlanguage);
895
897 ast_channel_exten_set(tmp, S_OR(exten, "s"));
899
900 headp = ast_channel_varshead(tmp);
902
906
907 channel_tech = ast_get_channel_tech(tech);
908 if (!channel_tech && !ast_strlen_zero(tech2)) {
909 channel_tech = ast_get_channel_tech(tech2);
910 }
911 if (channel_tech) {
912 ast_channel_tech_set(tmp, channel_tech);
913 } else {
915 }
916
917 /* You might scream "locking inversion" at seeing this but it is actually perfectly fine.
918 * Since the channel was just created nothing can know about it yet or even acquire it.
919 */
921
923
924 if (assignedids && (does_id_conflict(assignedids->uniqueid) || does_id_conflict(assignedids->uniqueid2))) {
928 /* See earlier channel creation abort comment above. */
929 return ast_channel_unref(tmp);
930 }
931
932 /* Finalize and link into the channels container. */
936
938
939 if (endpoint) {
940 ast_endpoint_add_channel(endpoint, tmp);
941 }
942
943 /*
944 * And now, since the channel structure is built, and has its name, let
945 * the world know of its existance
946 */
948
949 ast_debug(1, "Channel %p '%s' allocated\n", tmp, ast_channel_name(tmp));
950
951 return tmp;
952}
953
954struct ast_channel *__ast_channel_alloc(int needqueue, int state, const char *cid_num,
955 const char *cid_name, const char *acctcode,
956 const char *exten, const char *context, const struct ast_assigned_ids *assignedids,
957 const struct ast_channel *requestor, enum ama_flags amaflag,
958 struct ast_endpoint *endpoint,
959 const char *file, int line, const char *function,
960 const char *name_fmt, ...)
961{
962 va_list ap;
963 struct ast_channel *result;
964
965 va_start(ap, name_fmt);
966 result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context,
967 assignedids, requestor, amaflag, endpoint, file, line, function, name_fmt, ap);
968 va_end(ap);
969
970 return result;
971}
972
973/* only do the minimum amount of work needed here to make a channel
974 * structure that can be used to expand channel vars */
975struct ast_channel *__ast_dummy_channel_alloc(const char *file, int line, const char *function)
976{
977 struct ast_channel *tmp;
978 struct varshead *headp;
979
981 file, line, function);
982 if (!tmp) {
983 /* Dummy channel structure allocation failure. */
984 return NULL;
985 }
986
989
990 /*
991 * Init file descriptors to unopened state just in case
992 * autoservice is called on the channel or something tries to
993 * read a frame from it.
994 */
998
1000
1002
1003 headp = ast_channel_varshead(tmp);
1005
1006 return tmp;
1007}
1008
1009static int __ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin, int head, struct ast_frame *after)
1010{
1011 struct ast_frame *f;
1012 struct ast_frame *cur;
1013 unsigned int new_frames = 0;
1014 unsigned int new_voice_frames = 0;
1015 unsigned int queued_frames = 0;
1016 unsigned int queued_voice_frames = 0;
1018
1019 ast_channel_lock(chan);
1020
1021 /*
1022 * Check the last frame on the queue if we are queuing the new
1023 * frames after it.
1024 */
1025 cur = AST_LIST_LAST(ast_channel_readq(chan));
1026 if (cur && cur->frametype == AST_FRAME_CONTROL && !head && (!after || after == cur)) {
1027 switch (cur->subclass.integer) {
1029 if (fin->frametype == AST_FRAME_CONTROL
1030 && fin->subclass.integer == AST_CONTROL_HANGUP) {
1031 /*
1032 * Destroy the end-of-Q marker frame so we can queue the hangup
1033 * frame in its place.
1034 */
1036 ast_frfree(cur);
1037
1038 /*
1039 * This has degenerated to a normal queue append anyway. Since
1040 * we just destroyed the last frame in the queue we must make
1041 * sure that "after" is NULL or bad things will happen.
1042 */
1043 after = NULL;
1044 break;
1045 }
1046 /* Fall through */
1047 case AST_CONTROL_HANGUP:
1048 /* Don't queue anything. */
1049 ast_channel_unlock(chan);
1050 return 0;
1051 default:
1052 break;
1053 }
1054 }
1055
1056 /* Build copies of all the new frames and count them */
1058 for (cur = fin; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
1059 if (!(f = ast_frdup(cur))) {
1060 if (AST_LIST_FIRST(&frames)) {
1062 }
1063 ast_channel_unlock(chan);
1064 return -1;
1065 }
1066
1068 new_frames++;
1069 if (f->frametype == AST_FRAME_VOICE) {
1070 new_voice_frames++;
1071 }
1072 }
1073
1074 /* Count how many frames exist on the queue */
1076 queued_frames++;
1077 if (cur->frametype == AST_FRAME_VOICE) {
1078 queued_voice_frames++;
1079 }
1080 }
1081
1082 if ((queued_frames + new_frames > 128 || queued_voice_frames + new_voice_frames > 96)) {
1083 int total_queued = queued_frames + new_frames;
1084 int total_voice = queued_voice_frames + new_voice_frames;
1085 int count = 0;
1086 ast_log(LOG_WARNING, "Exceptionally long %squeue length (%d voice / %d total) queuing to %s\n",
1087 queued_frames + new_frames > 128 ? "" : "voice ", total_voice, total_queued, ast_channel_name(chan));
1089 /* Save the most recent frame */
1090 if (!AST_LIST_NEXT(cur, frame_list)) {
1091 break;
1092 } else if (cur->frametype == AST_FRAME_VOICE || cur->frametype == AST_FRAME_VIDEO || cur->frametype == AST_FRAME_NULL) {
1093 if (++count > 64) {
1094 break;
1095 }
1097 ast_frfree(cur);
1098
1099 /* Read from the alert pipe for each flushed frame. */
1101 }
1102 }
1104 if (count) {
1105 ast_debug(4, "Discarded %d frame%s due to queue overload on %s\n", count, ESS(count), ast_channel_name(chan));
1106 }
1107 }
1108
1109 if (after) {
1111 } else {
1112 if (head) {
1115 }
1117 }
1118
1119 if (ast_channel_alert_writable(chan)) {
1120 /* Write to the alert pipe for each added frame */
1121 while (new_frames--) {
1122 if (ast_channel_alert_write(chan)) {
1123 ast_log(LOG_WARNING, "Unable to write to alert pipe on %s (qlen = %u): %s!\n",
1124 ast_channel_name(chan), queued_frames, strerror(errno));
1125 break;
1126 }
1127 }
1128 } else if (ast_channel_timingfd(chan) > -1) {
1131 pthread_kill(ast_channel_blocker(chan), SIGURG);
1132 }
1133
1134 ast_channel_unlock(chan);
1135
1136 return 0;
1137}
1138
1139int ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin)
1140{
1141 return __ast_queue_frame(chan, fin, 0, NULL);
1142}
1143
1144int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *fin)
1145{
1146 return __ast_queue_frame(chan, fin, 1, NULL);
1147}
1148
1149/*! \brief Queue a hangup frame for channel */
1151{
1152 struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
1153 int res;
1154
1155 /* Yeah, let's not change a lock-critical value without locking */
1156 ast_channel_lock(chan);
1159
1160 res = ast_queue_frame(chan, &f);
1161 ast_channel_unlock(chan);
1162 return res;
1163}
1164
1165/*! \brief Queue a hangup frame for channel */
1166int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
1167{
1168 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
1169 struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
1170 int res;
1171
1172 if (cause >= 0) {
1173 f.data.uint32 = cause;
1174 }
1175
1176 /* Yeah, let's not change a lock-critical value without locking */
1177 ast_channel_lock(chan);
1179 if (cause < 0) {
1181 }
1182 blob = ast_json_pack("{s: i}",
1183 "cause", cause);
1185
1186 res = ast_queue_frame(chan, &f);
1187 ast_channel_unlock(chan);
1188 return res;
1189}
1190
1191int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
1192{
1193 struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HOLD };
1194 struct ast_json *blob = NULL;
1195 int res;
1196
1197 if (!ast_strlen_zero(musicclass)) {
1198 f.data.ptr = (void *) musicclass;
1199 f.datalen = strlen(musicclass) + 1;
1200
1201 blob = ast_json_pack("{s: s}",
1202 "musicclass", musicclass);
1203 }
1204
1205 ast_channel_lock(chan);
1207 ast_channel_unlock(chan);
1208
1209 res = ast_queue_frame(chan, &f);
1210
1211 ast_json_unref(blob);
1212
1213 return res;
1214}
1215
1217{
1218 struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_UNHOLD };
1219 int res;
1220
1221 ast_channel_lock(chan);
1223 ast_channel_unlock(chan);
1224
1225 res = ast_queue_frame(chan, &f);
1226
1227 return res;
1228}
1229
1230/*! \brief Queue a control frame */
1232{
1233 struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = control };
1234 return ast_queue_frame(chan, &f);
1235}
1236
1237/*! \brief Queue a control frame with payload */
1239 const void *data, size_t datalen)
1240{
1241 struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = control, .data.ptr = (void *) data, .datalen = datalen };
1242 return ast_queue_frame(chan, &f);
1243}
1244
1245/*! \brief Queue an ANSWER control frame with topology */
1246int ast_queue_answer(struct ast_channel *chan, const struct ast_stream_topology *topology)
1247{
1248 struct ast_frame f = {
1250 .subclass.integer = AST_CONTROL_ANSWER,
1251 .subclass.topology = (struct ast_stream_topology *)topology,
1252 };
1253 return ast_queue_frame(chan, &f);
1254}
1255
1256/*! \brief Set defer DTMF flag on channel */
1258{
1259 int pre = 0;
1260
1261 if (chan) {
1262 ast_channel_lock(chan);
1265 ast_channel_unlock(chan);
1266 }
1267 return pre;
1268}
1269
1270/*! \brief Unset defer DTMF flag on channel */
1272{
1273 if (chan) {
1275 }
1276}
1277
1279 void *data, int ao2_flags)
1280{
1281 return ao2_callback_data(channels, ao2_flags, cb_fn, arg, data);
1282}
1283
1284static int ast_channel_by_name_cb(void *obj, void *arg, void *data, int flags)
1285{
1286 struct ast_channel *chan = obj;
1287 const char *name = arg;
1288 size_t name_len = *(size_t *) data;
1289 int ret = CMP_MATCH;
1290
1291 if (ast_strlen_zero(name)) {
1292 ast_log(LOG_ERROR, "BUG! Must supply a channel name or partial name to match!\n");
1293 return CMP_STOP;
1294 }
1295
1296 ast_channel_lock(chan);
1297 if ((!name_len && strcasecmp(ast_channel_name(chan), name))
1298 || (name_len && strncasecmp(ast_channel_name(chan), name, name_len))) {
1299 ret = 0; /* name match failed, keep looking */
1300 }
1301 ast_channel_unlock(chan);
1302
1303 return ret;
1304}
1305
1306static int ast_channel_by_exten_cb(void *obj, void *arg, void *data, int flags)
1307{
1308 struct ast_channel *chan = obj;
1309 char *context = arg;
1310 char *exten = data;
1311 int ret = CMP_MATCH;
1312
1314 ast_log(LOG_ERROR, "BUG! Must have a context and extension to match!\n");
1315 return CMP_STOP;
1316 }
1317
1318 ast_channel_lock(chan);
1319 if (strcasecmp(ast_channel_context(chan), context)) {
1320 ret = 0; /* Context match failed, continue */
1321 } else if (strcasecmp(ast_channel_exten(chan), exten)) {
1322 ret = 0; /* Extension match failed, continue */
1323 }
1324 ast_channel_unlock(chan);
1325
1326 return ret;
1327}
1328
1329static int ast_channel_by_uniqueid_cb(void *obj, void *arg, void *data, int flags)
1330{
1331 struct ast_channel *chan = obj;
1332 char *uniqueid = arg;
1333 size_t id_len = *(size_t *) data;
1334 int ret = CMP_MATCH;
1335
1337 ast_log(LOG_ERROR, "BUG! Must supply a uniqueid or partial uniqueid to match!\n");
1338 return CMP_STOP;
1339 }
1340
1341 ast_channel_lock(chan);
1342 if ((!id_len && strcasecmp(ast_channel_uniqueid(chan), uniqueid))
1343 || (id_len && strncasecmp(ast_channel_uniqueid(chan), uniqueid, id_len))) {
1344 ret = 0; /* uniqueid match failed, keep looking */
1345 }
1346 ast_channel_unlock(chan);
1347
1348 return ret;
1349}
1350
1352 /* storage for non-dynamically allocated iterator */
1354 /* pointer to the actual iterator (simple_iterator or a dynamically
1355 * allocated iterator)
1356 */
1358};
1359
1361{
1363 ast_free(i);
1364
1365 return NULL;
1366}
1367
1369{
1370 struct ast_channel_iterator *i;
1371 char *l_exten = (char *) exten;
1372 char *l_context = (char *) context;
1373
1374 if (!(i = ast_calloc(1, sizeof(*i)))) {
1375 return NULL;
1376 }
1377
1379 l_context, l_exten, OBJ_MULTIPLE);
1380 if (!i->active_iterator) {
1381 ast_free(i);
1382 return NULL;
1383 }
1384
1385 return i;
1386}
1387
1389{
1390 struct ast_channel_iterator *i;
1391 char *l_name = (char *) name;
1392
1393 if (!(i = ast_calloc(1, sizeof(*i)))) {
1394 return NULL;
1395 }
1396
1398 l_name, &name_len,
1399 OBJ_MULTIPLE | (name_len == 0 /* match the whole word, so optimize */ ? OBJ_KEY : 0));
1400 if (!i->active_iterator) {
1401 ast_free(i);
1402 return NULL;
1403 }
1404
1405 return i;
1406}
1407
1409{
1410 struct ast_channel_iterator *i;
1411
1412 if (!(i = ast_calloc(1, sizeof(*i)))) {
1413 return NULL;
1414 }
1415
1418
1419 return i;
1420}
1421
1423{
1425}
1426
1427/* Legacy function, not currently used for lookups, but we need a cmp_fn */
1428static int ast_channel_cmp_cb(void *obj, void *arg, int flags)
1429{
1430 ast_log(LOG_ERROR, "BUG! Should never be called!\n");
1431 return CMP_STOP;
1432}
1433
1434struct ast_channel *ast_channel_get_by_name_prefix(const char *name, size_t name_len)
1435{
1436 struct ast_channel *chan;
1437 char *l_name = (char *) name;
1438
1439 if (ast_strlen_zero(l_name)) {
1440 /* We didn't have a name to search for so quit. */
1441 return NULL;
1442 }
1443
1444 chan = ast_channel_callback(ast_channel_by_name_cb, l_name, &name_len,
1445 (name_len == 0) /* optimize if it is a complete name match */ ? OBJ_KEY : 0);
1446 if (chan) {
1447 return chan;
1448 }
1449
1450 /* Now try a search for uniqueid. */
1451 return ast_channel_callback(ast_channel_by_uniqueid_cb, l_name, &name_len, 0);
1452}
1453
1455{
1457}
1458
1459struct ast_channel *ast_channel_get_by_exten(const char *exten, const char *context)
1460{
1461 char *l_exten = (char *) exten;
1462 char *l_context = (char *) context;
1463
1464 return ast_channel_callback(ast_channel_by_exten_cb, l_context, l_exten, 0);
1465}
1466
1467int ast_is_deferrable_frame(const struct ast_frame *frame)
1468{
1469 /* Do not add a default entry in this switch statement. Each new
1470 * frame type should be addressed directly as to whether it should
1471 * be queued up or not.
1472 */
1473 switch (frame->frametype) {
1476 case AST_FRAME_CONTROL:
1477 case AST_FRAME_TEXT:
1479 case AST_FRAME_IMAGE:
1480 case AST_FRAME_HTML:
1481 return 1;
1482
1483 case AST_FRAME_DTMF_END:
1485 case AST_FRAME_VOICE:
1486 case AST_FRAME_VIDEO:
1487 case AST_FRAME_NULL:
1488 case AST_FRAME_IAX:
1489 case AST_FRAME_CNG:
1490 case AST_FRAME_MODEM:
1491 case AST_FRAME_RTCP:
1492 return 0;
1493 }
1494 return 0;
1495}
1496
1497/*! \brief Wait, look for hangups and condition arg */
1498static int safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data, unsigned int generate_silence)
1499{
1500 struct ast_frame *f;
1501 struct ast_silence_generator *silgen = NULL;
1502 int res = 0;
1503 struct timeval start;
1504 int ms;
1505 AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames;
1506
1507 AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames);
1508
1509 /* If no other generator is present, start silencegen while waiting */
1510 if (generate_silence && ast_opt_transmit_silence && !ast_channel_generatordata(chan)) {
1512 }
1513
1514 start = ast_tvnow();
1515 while ((ms = ast_remaining_ms(start, timeout_ms))) {
1516 struct ast_frame *dup_f = NULL;
1517
1518 if (cond && ((*cond)(data) == 0)) {
1519 break;
1520 }
1521 ms = ast_waitfor(chan, ms);
1522 if (ms < 0) {
1523 res = -1;
1524 break;
1525 }
1526 if (ms > 0) {
1527 f = ast_read(chan);
1528 if (!f) {
1529 res = -1;
1530 break;
1531 }
1532
1533 if (!ast_is_deferrable_frame(f)) {
1534 ast_frfree(f);
1535 continue;
1536 }
1537
1538 if ((dup_f = ast_frisolate(f))) {
1539 if (dup_f != f) {
1540 ast_frfree(f);
1541 }
1542 AST_LIST_INSERT_HEAD(&deferred_frames, dup_f, frame_list);
1543 }
1544 }
1545 }
1546
1547 /* stop silgen if present */
1548 if (silgen) {
1550 }
1551
1552 /* We need to free all the deferred frames, but we only need to
1553 * queue the deferred frames if there was no error and no
1554 * hangup was received
1555 */
1556 ast_channel_lock(chan);
1557 while ((f = AST_LIST_REMOVE_HEAD(&deferred_frames, frame_list))) {
1558 if (!res) {
1559 ast_queue_frame_head(chan, f);
1560 }
1561 ast_frfree(f);
1562 }
1563 ast_channel_unlock(chan);
1564
1565 return res;
1566}
1567
1568int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data)
1569{
1570 return safe_sleep_conditional(chan, timeout_ms, cond, data, 1);
1571}
1572
1573/*! \brief Wait, look for hangups */
1574int ast_safe_sleep(struct ast_channel *chan, int ms)
1575{
1576 return safe_sleep_conditional(chan, ms, NULL, NULL, 1);
1577}
1578
1580{
1581 return safe_sleep_conditional(chan, ms, NULL, NULL, 0);
1582}
1583
1585{
1586 /* Safe, even if already unlinked. */
1587 ao2_unlink(channels, chan);
1588 return ast_channel_unref(chan);
1589}
1590
1592{
1593 init->str = NULL;
1596 init->valid = 0;
1597}
1598
1599void ast_party_name_copy(struct ast_party_name *dest, const struct ast_party_name *src)
1600{
1601 if (dest == src) {
1602 /* Don't copy to self */
1603 return;
1604 }
1605
1606 ast_free(dest->str);
1607 dest->str = ast_strdup(src->str);
1608 dest->char_set = src->char_set;
1609 dest->presentation = src->presentation;
1610 dest->valid = src->valid;
1611}
1612
1613void ast_party_name_set_init(struct ast_party_name *init, const struct ast_party_name *guide)
1614{
1615 init->str = NULL;
1616 init->char_set = guide->char_set;
1617 init->presentation = guide->presentation;
1618 init->valid = guide->valid;
1619}
1620
1621void ast_party_name_set(struct ast_party_name *dest, const struct ast_party_name *src)
1622{
1623 if (dest == src) {
1624 /* Don't set to self */
1625 return;
1626 }
1627
1628 if (src->str && src->str != dest->str) {
1629 ast_free(dest->str);
1630 dest->str = ast_strdup(src->str);
1631 }
1632
1633 dest->char_set = src->char_set;
1634 dest->presentation = src->presentation;
1635 dest->valid = src->valid;
1636}
1637
1639{
1640 ast_free(doomed->str);
1641 doomed->str = NULL;
1642}
1643
1645{
1646 init->str = NULL;
1647 init->plan = 0;/* Unknown */
1649 init->valid = 0;
1650}
1651
1652void ast_party_number_copy(struct ast_party_number *dest, const struct ast_party_number *src)
1653{
1654 if (dest == src) {
1655 /* Don't copy to self */
1656 return;
1657 }
1658
1659 ast_free(dest->str);
1660 dest->str = ast_strdup(src->str);
1661 dest->plan = src->plan;
1662 dest->presentation = src->presentation;
1663 dest->valid = src->valid;
1664}
1665
1666void ast_party_number_set_init(struct ast_party_number *init, const struct ast_party_number *guide)
1667{
1668 init->str = NULL;
1669 init->plan = guide->plan;
1670 init->presentation = guide->presentation;
1671 init->valid = guide->valid;
1672}
1673
1674void ast_party_number_set(struct ast_party_number *dest, const struct ast_party_number *src)
1675{
1676 if (dest == src) {
1677 /* Don't set to self */
1678 return;
1679 }
1680
1681 if (src->str && src->str != dest->str) {
1682 ast_free(dest->str);
1683 dest->str = ast_strdup(src->str);
1684 }
1685
1686 dest->plan = src->plan;
1687 dest->presentation = src->presentation;
1688 dest->valid = src->valid;
1689}
1690
1692{
1693 ast_free(doomed->str);
1694 doomed->str = NULL;
1695}
1696
1698{
1699 init->str = NULL;
1700 init->type = 0;
1701 init->odd_even_indicator = 0;
1702 init->valid = 0;
1703}
1704
1706{
1707 if (dest == src) {
1708 /* Don't copy to self */
1709 return;
1710 }
1711
1712 ast_free(dest->str);
1713 dest->str = ast_strdup(src->str);
1714 dest->type = src->type;
1716 dest->valid = src->valid;
1717}
1718
1720{
1721 init->str = NULL;
1722 init->type = guide->type;
1724 init->valid = guide->valid;
1725}
1726
1728{
1729 if (dest == src) {
1730 /* Don't set to self */
1731 return;
1732 }
1733
1734 if (src->str && src->str != dest->str) {
1735 ast_free(dest->str);
1736 dest->str = ast_strdup(src->str);
1737 }
1738
1739 dest->type = src->type;
1741 dest->valid = src->valid;
1742}
1743
1745{
1746 ast_free(doomed->str);
1747 doomed->str = NULL;
1748}
1749
1751{
1752 update_id->name = 1;
1753 update_id->number = 1;
1754 update_id->subaddress = 1;
1755}
1756
1758{
1759 ast_party_name_init(&init->name);
1762 init->tag = NULL;
1763}
1764
1765void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src)
1766{
1767 if (dest == src) {
1768 /* Don't copy to self */
1769 return;
1770 }
1771
1772 ast_party_name_copy(&dest->name, &src->name);
1773 ast_party_number_copy(&dest->number, &src->number);
1775
1776 ast_free(dest->tag);
1777 dest->tag = ast_strdup(src->tag);
1778}
1779
1780void ast_party_id_set_init(struct ast_party_id *init, const struct ast_party_id *guide)
1781{
1782 ast_party_name_set_init(&init->name, &guide->name);
1783 ast_party_number_set_init(&init->number, &guide->number);
1785 init->tag = NULL;
1786}
1787
1788void ast_party_id_set(struct ast_party_id *dest, const struct ast_party_id *src, const struct ast_set_party_id *update)
1789{
1790 if (dest == src) {
1791 /* Don't set to self */
1792 return;
1793 }
1794
1795 if (!update || update->name) {
1796 ast_party_name_set(&dest->name, &src->name);
1797 }
1798 if (!update || update->number) {
1799 ast_party_number_set(&dest->number, &src->number);
1800 }
1801 if (!update || update->subaddress) {
1803 }
1804
1805 if (src->tag && src->tag != dest->tag) {
1806 ast_free(dest->tag);
1807 dest->tag = ast_strdup(src->tag);
1808 }
1809}
1810
1812{
1813 ast_party_name_free(&doomed->name);
1814 ast_party_number_free(&doomed->number);
1816
1817 ast_free(doomed->tag);
1818 doomed->tag = NULL;
1819}
1820
1822{
1823 int number_priority;
1824 int number_value;
1825 int number_screening;
1826 int name_priority;
1827 int name_value;
1828
1829 /* Determine name presentation priority. */
1830 if (!id->name.valid) {
1831 name_value = AST_PRES_UNAVAILABLE;
1832 name_priority = 3;
1833 } else {
1834 name_value = id->name.presentation & AST_PRES_RESTRICTION;
1835 switch (name_value) {
1837 name_priority = 0;
1838 break;
1839 case AST_PRES_ALLOWED:
1840 name_priority = 1;
1841 break;
1843 name_priority = 2;
1844 break;
1845 default:
1846 name_value = AST_PRES_UNAVAILABLE;
1847 name_priority = 3;
1848 break;
1849 }
1850 }
1851
1852 /* Determine number presentation priority. */
1853 if (!id->number.valid) {
1854 number_screening = AST_PRES_USER_NUMBER_UNSCREENED;
1855 number_value = AST_PRES_UNAVAILABLE;
1856 number_priority = 3;
1857 } else {
1858 number_screening = id->number.presentation & AST_PRES_NUMBER_TYPE;
1859 number_value = id->number.presentation & AST_PRES_RESTRICTION;
1860 switch (number_value) {
1862 number_priority = 0;
1863 break;
1864 case AST_PRES_ALLOWED:
1865 number_priority = 1;
1866 break;
1868 number_priority = 2;
1869 break;
1870 default:
1871 number_screening = AST_PRES_USER_NUMBER_UNSCREENED;
1872 number_value = AST_PRES_UNAVAILABLE;
1873 number_priority = 3;
1874 break;
1875 }
1876 }
1877
1878 /* Select the wining presentation value. */
1879 if (name_priority < number_priority) {
1880 number_value = name_value;
1881 }
1882 if (number_value == AST_PRES_UNAVAILABLE) {
1884 }
1885
1886 return number_value | number_screening;
1887}
1888
1890{
1891 id->name.valid = 0;
1892 id->number.valid = 0;
1893 id->subaddress.valid = 0;
1894}
1895
1897{
1900}
1901
1902struct ast_party_id ast_party_id_merge(struct ast_party_id *base, struct ast_party_id *overlay)
1903{
1904 struct ast_party_id merged;
1905
1906 merged = *base;
1907 if (overlay->name.valid) {
1908 merged.name = overlay->name;
1909 }
1910 if (overlay->number.valid) {
1911 merged.number = overlay->number;
1912 }
1913 if (overlay->subaddress.valid) {
1914 merged.subaddress = overlay->subaddress;
1915 }
1916 /* Note the actual structure is returned and not a pointer to it! */
1917 return merged;
1918}
1919
1920void ast_party_id_merge_copy(struct ast_party_id *dest, struct ast_party_id *base, struct ast_party_id *overlay)
1921{
1922 struct ast_party_id merged;
1923
1924 merged = ast_party_id_merge(base, overlay);
1925 ast_party_id_copy(dest, &merged);
1926}
1927
1929{
1930 init->number.str = NULL;
1931 init->number.plan = 0;/* Unknown */
1933 init->transit_network_select = 0;
1934}
1935
1936void ast_party_dialed_copy(struct ast_party_dialed *dest, const struct ast_party_dialed *src)
1937{
1938 if (dest == src) {
1939 /* Don't copy to self */
1940 return;
1941 }
1942
1943 ast_free(dest->number.str);
1944 dest->number.str = ast_strdup(src->number.str);
1945 dest->number.plan = src->number.plan;
1948}
1949
1950void ast_party_dialed_set_init(struct ast_party_dialed *init, const struct ast_party_dialed *guide)
1951{
1952 init->number.str = NULL;
1953 init->number.plan = guide->number.plan;
1956}
1957
1958void ast_party_dialed_set(struct ast_party_dialed *dest, const struct ast_party_dialed *src)
1959{
1960 if (src->number.str && src->number.str != dest->number.str) {
1961 ast_free(dest->number.str);
1962 dest->number.str = ast_strdup(src->number.str);
1963 }
1964 dest->number.plan = src->number.plan;
1965
1967
1969}
1970
1972{
1973 ast_free(doomed->number.str);
1974 doomed->number.str = NULL;
1976}
1977
1979{
1980 ast_party_id_init(&init->id);
1981 ast_party_id_init(&init->ani);
1982 ast_party_id_init(&init->priv);
1983 init->ani2 = 0;
1984}
1985
1986void ast_party_caller_copy(struct ast_party_caller *dest, const struct ast_party_caller *src)
1987{
1988 if (dest == src) {
1989 /* Don't copy to self */
1990 return;
1991 }
1992
1993 ast_party_id_copy(&dest->id, &src->id);
1994 ast_party_id_copy(&dest->ani, &src->ani);
1995 ast_party_id_copy(&dest->priv, &src->priv);
1996 dest->ani2 = src->ani2;
1997}
1998
1999void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide)
2000{
2001 ast_party_id_set_init(&init->id, &guide->id);
2002 ast_party_id_set_init(&init->ani, &guide->ani);
2003 ast_party_id_set_init(&init->priv, &guide->priv);
2004 init->ani2 = guide->ani2;
2005}
2006
2007void ast_party_caller_set(struct ast_party_caller *dest, const struct ast_party_caller *src, const struct ast_set_party_caller *update)
2008{
2009 ast_party_id_set(&dest->id, &src->id, update ? &update->id : NULL);
2010 ast_party_id_set(&dest->ani, &src->ani, update ? &update->ani : NULL);
2011 ast_party_id_set(&dest->priv, &src->priv, update ? &update->priv : NULL);
2012 dest->ani2 = src->ani2;
2013}
2014
2016{
2017 ast_party_id_free(&doomed->id);
2018 ast_party_id_free(&doomed->ani);
2019 ast_party_id_free(&doomed->priv);
2020}
2021
2023{
2024 ast_party_id_init(&init->id);
2025 ast_party_id_init(&init->ani);
2026 ast_party_id_init(&init->priv);
2027 init->ani2 = 0;
2029}
2030
2032{
2033 if (dest == src) {
2034 /* Don't copy to self */
2035 return;
2036 }
2037
2038 ast_party_id_copy(&dest->id, &src->id);
2039 ast_party_id_copy(&dest->ani, &src->ani);
2040 ast_party_id_copy(&dest->priv, &src->priv);
2041 dest->ani2 = src->ani2;
2042 dest->source = src->source;
2043}
2044
2046{
2047 ast_party_id_set_init(&init->id, &guide->id);
2048 ast_party_id_set_init(&init->ani, &guide->ani);
2049 ast_party_id_set_init(&init->priv, &guide->priv);
2050 init->ani2 = guide->ani2;
2051 init->source = guide->source;
2052}
2053
2055{
2056 ast_party_id_set(&dest->id, &src->id, update ? &update->id : NULL);
2057 ast_party_id_set(&dest->ani, &src->ani, update ? &update->ani : NULL);
2058 ast_party_id_set(&dest->priv, &src->priv, update ? &update->priv : NULL);
2059 dest->ani2 = src->ani2;
2060 dest->source = src->source;
2061}
2062
2064{
2065 connected->id = caller->id;
2066 connected->ani = caller->ani;
2067 connected->priv = caller->priv;
2068 connected->ani2 = caller->ani2;
2070}
2071
2073{
2074 ast_party_id_free(&doomed->id);
2075 ast_party_id_free(&doomed->ani);
2076 ast_party_id_free(&doomed->priv);
2077}
2078
2080{
2081 init->str = NULL;
2083}
2084
2086{
2087 if (dest == src) {
2088 return;
2089 }
2090
2091 ast_free(dest->str);
2092 dest->str = ast_strdup(src->str);
2093 dest->code = src->code;
2094}
2095
2097{
2098 init->str = NULL;
2099 init->code = guide->code;
2100}
2101
2103{
2104 if (dest == src) {
2105 return;
2106 }
2107
2108 if (src->str && src->str != dest->str) {
2109 ast_free(dest->str);
2110 dest->str = ast_strdup(src->str);
2111 }
2112
2113 dest->code = src->code;
2114}
2115
2117{
2118 ast_free(doomed->str);
2119}
2120
2121
2123{
2124 ast_party_id_init(&init->orig);
2125 ast_party_id_init(&init->from);
2126 ast_party_id_init(&init->to);
2129 ast_party_id_init(&init->priv_to);
2132 init->count = 0;
2133}
2134
2136{
2137 if (dest == src) {
2138 /* Don't copy to self */
2139 return;
2140 }
2141
2142 ast_party_id_copy(&dest->orig, &src->orig);
2143 ast_party_id_copy(&dest->from, &src->from);
2144 ast_party_id_copy(&dest->to, &src->to);
2145 ast_party_id_copy(&dest->priv_orig, &src->priv_orig);
2146 ast_party_id_copy(&dest->priv_from, &src->priv_from);
2147 ast_party_id_copy(&dest->priv_to, &src->priv_to);
2150 dest->count = src->count;
2151}
2152
2154{
2155 ast_party_id_set_init(&init->orig, &guide->orig);
2156 ast_party_id_set_init(&init->from, &guide->from);
2157 ast_party_id_set_init(&init->to, &guide->to);
2158 ast_party_id_set_init(&init->priv_orig, &guide->priv_orig);
2159 ast_party_id_set_init(&init->priv_from, &guide->priv_from);
2160 ast_party_id_set_init(&init->priv_to, &guide->priv_to);
2163 init->count = guide->count;
2164}
2165
2167{
2168 ast_party_id_set(&dest->orig, &src->orig, update ? &update->orig : NULL);
2169 ast_party_id_set(&dest->from, &src->from, update ? &update->from : NULL);
2170 ast_party_id_set(&dest->to, &src->to, update ? &update->to : NULL);
2171 ast_party_id_set(&dest->priv_orig, &src->priv_orig, update ? &update->priv_orig : NULL);
2172 ast_party_id_set(&dest->priv_from, &src->priv_from, update ? &update->priv_from : NULL);
2173 ast_party_id_set(&dest->priv_to, &src->priv_to, update ? &update->priv_to : NULL);
2176 dest->count = src->count;
2177}
2178
2180{
2181 ast_party_id_free(&doomed->orig);
2182 ast_party_id_free(&doomed->from);
2183 ast_party_id_free(&doomed->to);
2184 ast_party_id_free(&doomed->priv_orig);
2185 ast_party_id_free(&doomed->priv_from);
2186 ast_party_id_free(&doomed->priv_to);
2189}
2190
2191/*! \brief Free a channel structure */
2192static void ast_channel_destructor(void *obj)
2193{
2194 struct ast_channel *chan = obj;
2195 struct ast_var_t *vardata;
2196 struct ast_frame *f;
2197 struct varshead *headp;
2198 struct ast_datastore *datastore;
2199 char device_name[AST_CHANNEL_NAME];
2200 ast_callid callid;
2201
2202 ast_debug(1, "Channel %p '%s' destroying\n", chan, ast_channel_name(chan));
2203
2204 /* If there is native format music-on-hold state, free it */
2205 if (ast_channel_music_state(chan)) {
2206 ast_moh_cleanup(chan);
2207 }
2208
2210
2211 /* Things that may possibly raise Stasis messages shouldn't occur after this point */
2213
2215 /* A channel snapshot should not be in the process of being staged now. */
2217
2218 ast_channel_lock(chan);
2220 ast_channel_unlock(chan);
2221 }
2222
2223 ast_channel_lock(chan);
2224
2225 /* Get rid of each of the data stores on the channel */
2226 while ((datastore = AST_LIST_REMOVE_HEAD(ast_channel_datastores(chan), entry)))
2227 /* Free the data store */
2228 ast_datastore_free(datastore);
2229
2230 /* While the channel is locked, take the reference to its callid while we tear down the call. */
2231 callid = ast_channel_callid(chan);
2233
2234 ast_channel_unlock(chan);
2235
2236 /* Lock and unlock the channel just to be sure nobody has it locked still
2237 due to a reference that was stored in a datastore. (i.e. app_chanspy) */
2238 ast_channel_lock(chan);
2239 ast_channel_unlock(chan);
2240
2241 if (ast_channel_tech_pvt(chan)) {
2242 ast_log_callid(LOG_WARNING, callid, "Channel '%s' may not have been hung up properly\n", ast_channel_name(chan));
2244 }
2245
2246 if (ast_channel_sched(chan)) {
2248 }
2249
2251 char *dashptr;
2252
2253 ast_copy_string(device_name, ast_channel_name(chan), sizeof(device_name));
2254 if ((dashptr = strrchr(device_name, '-'))) {
2255 *dashptr = '\0';
2256 }
2257 } else {
2258 device_name[0] = '\0';
2259 }
2260
2261 /* Free translators */
2262 if (ast_channel_readtrans(chan))
2264 if (ast_channel_writetrans(chan))
2266 if (ast_channel_pbx(chan))
2267 ast_log_callid(LOG_WARNING, callid, "PBX may not have been terminated properly on '%s'\n", ast_channel_name(chan));
2268
2269 /* Free formats */
2275
2281
2282 /* Close pipes if appropriate */
2284 if (ast_channel_timer(chan)) {
2287 }
2289 ast_frfree(f);
2290
2291 /* loop over the variables list, freeing all data and deleting list items */
2292 /* no need to lock the list, as the channel is already locked */
2293 headp = ast_channel_varshead(chan);
2294 while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
2295 ast_var_delete(vardata);
2296
2298
2299 /* Destroy the jitterbuffer */
2300 ast_jb_destroy(chan);
2301
2302 if (ast_channel_cdr(chan)) {
2305 }
2306
2307 if (ast_channel_zone(chan)) {
2309 }
2310
2312
2313 if (device_name[0]) {
2314 /*
2315 * We have a device name to notify of a new state.
2316 *
2317 * Queue an unknown state, because, while we know that this particular
2318 * instance is dead, we don't know the state of all other possible
2319 * instances.
2320 */
2322 }
2323
2325
2328
2330}
2331
2332/*! \brief Free a dummy channel structure */
2333static void ast_dummy_channel_destructor(void *obj)
2334{
2335 struct ast_channel *chan = obj;
2336 struct ast_datastore *datastore;
2337 struct ast_var_t *vardata;
2338 struct varshead *headp;
2339
2341
2342 /* Get rid of each of the data stores on the channel */
2343 while ((datastore = AST_LIST_REMOVE_HEAD(ast_channel_datastores(chan), entry))) {
2344 /* Free the data store */
2345 ast_datastore_free(datastore);
2346 }
2347
2353
2354 /* loop over the variables list, freeing all data and deleting list items */
2355 /* no need to lock the list, as the channel is already locked */
2356 headp = ast_channel_varshead(chan);
2357 while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
2358 ast_var_delete(vardata);
2359
2360 if (ast_channel_cdr(chan)) {
2363 }
2364
2366}
2367
2369{
2370 struct ast_datastore *datastore = NULL, *datastore2;
2371
2373 if (datastore->inheritance > 0) {
2374 datastore2 = ast_datastore_alloc(datastore->info, datastore->uid);
2375 if (datastore2) {
2376 datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL;
2377 datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1;
2379 }
2380 }
2381 }
2382 return 0;
2383}
2384
2385int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
2386{
2387 int res = 0;
2388
2390
2391 return res;
2392}
2393
2394int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
2395{
2396 return AST_LIST_REMOVE(ast_channel_datastores(chan), datastore, entry) ? 0 : -1;
2397}
2398
2399struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
2400{
2401 struct ast_datastore *datastore = NULL;
2402
2403 if (info == NULL)
2404 return NULL;
2405
2407 if (datastore->info != info) {
2408 continue;
2409 }
2410
2411 if (uid == NULL) {
2412 /* matched by type only */
2413 break;
2414 }
2415
2416 if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) {
2417 /* Matched by type AND uid */
2418 break;
2419 }
2420 }
2421
2422 return datastore;
2423}
2424
2425/*! Set the file descriptor on the channel */
2426void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
2427{
2428 ast_channel_internal_fd_set(chan, which, fd);
2429 return;
2430}
2431
2433{
2434 ast_channel_lock(chan);
2435
2437
2439 struct ast_frame *fr;
2440
2441 /* If we have completely cleared the softhangup flag,
2442 * then we need to fully abort the hangup process. This requires
2443 * pulling the END_OF_Q frame out of the channel frame queue if it
2444 * still happens to be there. */
2445
2446 fr = AST_LIST_LAST(ast_channel_readq(chan));
2447 if (fr && fr->frametype == AST_FRAME_CONTROL &&
2450 ast_frfree(fr);
2451 }
2452 }
2453
2454 ast_channel_unlock(chan);
2455}
2456
2457/*! \brief Softly hangup a channel, don't lock */
2458int ast_softhangup_nolock(struct ast_channel *chan, int cause)
2459{
2460 ast_debug(1, "Soft-Hanging (%#04x) up channel '%s'\n", (unsigned)cause, ast_channel_name(chan));
2461 /* Inform channel driver that we need to be hung up, if it cares */
2464 /* Interrupt any poll call or such */
2466 pthread_kill(ast_channel_blocker(chan), SIGURG);
2467 return 0;
2468}
2469
2470/*! \brief Softly hangup a channel, lock */
2471int ast_softhangup(struct ast_channel *chan, int cause)
2472{
2473 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
2474 int res;
2475
2476 ast_channel_lock(chan);
2477 res = ast_softhangup_nolock(chan, cause);
2478 blob = ast_json_pack("{s: i, s: b}",
2479 "cause", cause,
2480 "soft", 1);
2482 ast_channel_unlock(chan);
2483
2484 return res;
2485}
2486
2487static void free_translation(struct ast_channel *clonechan)
2488{
2489 if (ast_channel_writetrans(clonechan)) {
2491 }
2492 if (ast_channel_readtrans(clonechan)) {
2494 }
2495 ast_channel_writetrans_set(clonechan, NULL);
2496 ast_channel_readtrans_set(clonechan, NULL);
2497}
2498
2499void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
2500{
2502
2503 ast_channel_lock(chan);
2504 if (force || ast_strlen_zero(ast_channel_hangupsource(chan))) {
2505 ast_channel_hangupsource_set(chan, source);
2506 }
2507 ast_channel_unlock(chan);
2508
2509 if (bridge) {
2510 ast_channel_lock(bridge);
2511 if (force || ast_strlen_zero(ast_channel_hangupsource(bridge))) {
2512 ast_channel_hangupsource_set(bridge, source);
2513 }
2514 ast_channel_unlock(bridge);
2515 }
2516}
2517
2519{
2522}
2523
2525{
2528}
2529
2530static void destroy_hooks(struct ast_channel *chan)
2531{
2532 if (ast_channel_audiohooks(chan)) {
2535 }
2536
2538}
2539
2540/*! \brief Hangup a channel */
2541void ast_hangup(struct ast_channel *chan)
2542{
2543 /* Be NULL safe for RAII_VAR() usage. */
2544 if (!chan) {
2545 return;
2546 }
2547
2548 ast_debug(1, "Channel %p '%s' hanging up. Refs: %d\n", chan, ast_channel_name(chan),
2549 ao2_ref(chan, 0));
2550
2552
2553 ast_channel_lock(chan);
2554
2555 while (ast_channel_masq(chan) || ast_channel_masqr(chan)) {
2557 }
2558
2559 /* Mark as a zombie so a masquerade cannot be setup on this channel. */
2561
2562 ast_channel_unlock(chan);
2563
2564 /*
2565 * XXX if running the hangup handlers here causes problems
2566 * because the handlers take too long to execute, we could move
2567 * the meat of this function into another thread. A thread
2568 * where channels go to die.
2569 *
2570 * If this is done, ast_autoservice_chan_hangup_peer() will no
2571 * longer be needed.
2572 */
2574 ao2_unlink(channels, chan);
2575 ast_channel_lock(chan);
2576
2577 destroy_hooks(chan);
2578
2579 free_translation(chan);
2580 /* Close audio stream */
2581 if (ast_channel_stream(chan)) {
2584 }
2585 /* Close video stream */
2586 if (ast_channel_vstream(chan)) {
2589 }
2590 if (ast_channel_sched(chan)) {
2593 }
2594
2595 if (ast_channel_generatordata(chan)) { /* Clear any tone stuff remaining */
2596 if (ast_channel_generator(chan) && ast_channel_generator(chan)->release) {
2598 }
2599 }
2602
2604 ast_log(LOG_WARNING, "Hard hangup called by thread LWP %d on %s, while blocked by thread LWP %d in procedure %s! Expect a failure\n",
2606 ast_channel_blockproc(chan));
2607 ast_assert(0);
2608 }
2609
2610 if (ast_channel_tech(chan)->hangup) {
2611 ast_channel_tech(chan)->hangup(chan);
2612 }
2613
2614 ast_channel_unlock(chan);
2615
2616 ast_cc_offer(chan);
2617
2618 ast_channel_unref(chan);
2619}
2620
2621/*!
2622 * \internal
2623 * \brief Set channel answered time if not already set.
2624 * \since 13.11.0
2625 *
2626 * \param chan Channel to set answered time.
2627 */
2628static void set_channel_answer_time(struct ast_channel *chan)
2629{
2631 struct timeval answertime;
2632
2633 answertime = ast_tvnow();
2634 ast_channel_answertime_set(chan, &answertime);
2635 }
2636}
2637
2638
2640{
2641 int res = 0;
2642 SCOPE_TRACE(1, "%s\n", ast_channel_name(chan));
2643
2644 ast_channel_lock(chan);
2645
2646 /* You can't answer an outbound call */
2648 ast_channel_unlock(chan);
2649 return 0;
2650 }
2651
2652 /* Stop if we're a zombie or need a soft hangup */
2654 ast_channel_unlock(chan);
2655 return -1;
2656 }
2657
2658 /*
2659 * Mark when incoming channel answered so we can know how
2660 * long the channel has been up.
2661 */
2663
2664 ast_channel_unlock(chan);
2665
2666 switch (ast_channel_state(chan)) {
2667 case AST_STATE_RINGING:
2668 case AST_STATE_RING:
2669 ast_channel_lock(chan);
2670 if (ast_channel_tech(chan)->answer_with_stream_topology) {
2671 res = ast_channel_tech(chan)->answer_with_stream_topology(chan, topology);
2672
2673 } else if (ast_channel_tech(chan)->answer) {
2674 res = ast_channel_tech(chan)->answer(chan);
2675 }
2677 ast_channel_unlock(chan);
2678 break;
2679 case AST_STATE_UP:
2680 break;
2681 default:
2682 break;
2683 }
2684
2685 ast_indicate(chan, -1);
2686
2687 return res;
2688}
2689
2691{
2693}
2694
2695int __ast_answer(struct ast_channel *chan, unsigned int delay)
2696{
2697 int res = 0;
2698 enum ast_channel_state old_state;
2699 SCOPE_TRACE(1, "%s\n", ast_channel_name(chan));
2700
2701 old_state = ast_channel_state(chan);
2702 if ((res = ast_raw_answer(chan))) {
2703 return res;
2704 }
2705
2706 switch (old_state) {
2707 case AST_STATE_RINGING:
2708 case AST_STATE_RING:
2709 /* wait for media to start flowing, but don't wait any longer
2710 * than 'delay' or 500 milliseconds, whichever is longer
2711 */
2712 do {
2714 struct ast_frame *cur;
2715 struct ast_frame *new_frame;
2716 int timeout_ms = MAX(delay, 500);
2717 unsigned int done = 0;
2718 struct timeval start;
2719
2721
2722 start = ast_tvnow();
2723 for (;;) {
2724 int ms = ast_remaining_ms(start, timeout_ms);
2725 ms = ast_waitfor(chan, ms);
2726 if (ms < 0) {
2727 ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", ast_channel_name(chan), strerror(errno));
2728 res = -1;
2729 break;
2730 }
2731 if (ms == 0) {
2732 ast_debug(2, "Didn't receive a media frame from %s within %u ms of answering. Continuing anyway\n", ast_channel_name(chan), MAX(delay, 500));
2733 break;
2734 }
2735 cur = ast_read(chan);
2736 if (!cur || ((cur->frametype == AST_FRAME_CONTROL) &&
2737 (cur->subclass.integer == AST_CONTROL_HANGUP))) {
2738 if (cur) {
2739 ast_frfree(cur);
2740 }
2741 res = -1;
2742 ast_debug(2, "Hangup of channel %s detected in answer routine\n", ast_channel_name(chan));
2743 break;
2744 }
2745
2746 if ((new_frame = ast_frisolate(cur)) != cur) {
2747 ast_frfree(cur);
2748 }
2749
2751
2752 /* if a specific delay period was requested, continue
2753 * until that delay has passed. don't stop just because
2754 * incoming media has arrived.
2755 */
2756 if (delay) {
2757 continue;
2758 }
2759
2760 switch (new_frame->frametype) {
2761 /* all of these frametypes qualify as 'media' */
2762 case AST_FRAME_VOICE:
2763 case AST_FRAME_VIDEO:
2764 case AST_FRAME_TEXT:
2767 case AST_FRAME_DTMF_END:
2768 case AST_FRAME_IMAGE:
2769 case AST_FRAME_HTML:
2770 case AST_FRAME_MODEM:
2771 case AST_FRAME_RTCP:
2772 done = 1;
2773 break;
2774 case AST_FRAME_CONTROL:
2775 case AST_FRAME_IAX:
2778 case AST_FRAME_NULL:
2779 case AST_FRAME_CNG:
2780 break;
2781 }
2782
2783 if (done) {
2784 break;
2785 }
2786 }
2787
2788 ast_channel_lock(chan);
2789 while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
2790 if (res == 0) {
2791 ast_queue_frame_head(chan, cur);
2792 }
2793 ast_frfree(cur);
2794 }
2795 ast_channel_unlock(chan);
2796 } while (0);
2797 break;
2798 default:
2799 break;
2800 }
2801
2802 return res;
2803}
2804
2805int ast_answer(struct ast_channel *chan)
2806{
2807 SCOPE_TRACE(1, "%s\n", ast_channel_name(chan));
2808 return __ast_answer(chan, 0);
2809}
2810
2811inline int ast_auto_answer(struct ast_channel *chan)
2812{
2813 if (ast_channel_state(chan) == AST_STATE_UP) {
2814 /* Already answered */
2815 return 0;
2816 }
2817 return ast_answer(chan);
2818}
2819
2821{
2822 ast_assert(NULL != chan);
2823
2825 return 0;
2826 }
2828}
2829
2831{
2832 return (ast_channel_get_duration_ms(chan) / 1000);
2833}
2834
2836{
2837 ast_assert(NULL != chan);
2838
2840 return 0;
2841 }
2843}
2844
2846{
2847 return (ast_channel_get_up_time_ms(chan) / 1000);
2848}
2849
2850/*!
2851 * \brief Determine whether or not we have to trigger dtmf emulating using 50 fps timer events
2852 * especially when no voice frames are received during dtmf processing (direct media or muted
2853 * sender case using SIP INFO)
2854 */
2855static inline int should_trigger_dtmf_emulating(struct ast_channel *chan)
2856{
2858 /* We're in the middle of emulating a digit, or DTMF has been
2859 * explicitly deferred. Trigger dtmf with periodic 50 pfs timer events, then. */
2860 return 1;
2861 }
2862
2863 if (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
2865 /*
2866 * We're not in the middle of a digit, but it hasn't been long enough
2867 * since the last digit, so we'll have to trigger DTMF further on.
2868 * Using 2 times AST_MIN_DTMF_GAP to trigger readq reading for possible
2869 * buffered next dtmf event
2870 */
2871 return 1;
2872 }
2873
2874 return 0;
2875}
2876
2878{
2879 if (ast_channel_generatordata(chan)) {
2880 struct ast_generator *generator = ast_channel_generator(chan);
2881
2882 if (generator && generator->release) {
2883 generator->release(chan, ast_channel_generatordata(chan));
2884 }
2889 ast_settimeout(chan, 0, NULL, NULL);
2890 }
2891}
2892
2894{
2895 ast_channel_lock(chan);
2898 /* if in the middle of dtmf emulation keep 50 tick per sec timer on rolling */
2900 }
2901 ast_channel_unlock(chan);
2902}
2903
2905{
2906 struct ast_generator *generator;
2907
2908 ast_channel_lock(chan);
2909 generator = ast_channel_generator(chan);
2910 if (generator && generator->write_format_change) {
2911 generator->write_format_change(chan, ast_channel_generatordata(chan));
2912 }
2913 ast_channel_unlock(chan);
2914}
2915
2916static int generator_force(const void *data)
2917{
2918 /* Called if generator doesn't have data */
2919 void *tmp;
2920 int res;
2921 int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = NULL;
2922 struct ast_channel *chan = (struct ast_channel *)data;
2923
2924 ast_channel_lock(chan);
2927 if (ast_channel_generator(chan))
2928 generate = ast_channel_generator(chan)->generate;
2929 ast_channel_unlock(chan);
2930
2931 if (!tmp || !generate) {
2932 return 0;
2933 }
2934
2935 res = generate(chan, tmp, 0, ast_format_get_sample_rate(ast_channel_writeformat(chan)) / 50);
2936
2937 ast_channel_lock(chan);
2938 if (ast_channel_generator(chan) && generate == ast_channel_generator(chan)->generate) {
2940 }
2941 ast_channel_unlock(chan);
2942
2943 if (res) {
2944 ast_debug(1, "Auto-deactivating generator\n");
2946 }
2947
2948 return 0;
2949}
2950
2951int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
2952{
2953 int res = 0;
2954 void *generatordata = NULL;
2955
2956 ast_channel_lock(chan);
2957 if (ast_channel_generatordata(chan)) {
2958 struct ast_generator *generator_old = ast_channel_generator(chan);
2959
2960 if (generator_old && generator_old->release) {
2961 generator_old->release(chan, ast_channel_generatordata(chan));
2962 }
2963 }
2964 if (gen->alloc && !(generatordata = gen->alloc(chan, params))) {
2965 res = -1;
2966 }
2967 ast_channel_generatordata_set(chan, generatordata);
2968 if (!res) {
2969 ast_settimeout(chan, 50, generator_force, chan);
2971 }
2972 ast_channel_unlock(chan);
2973
2974 ast_prod(chan);
2975
2976 return res;
2977}
2978
2979/*! \brief Wait for x amount of time on a file descriptor to have input. */
2980int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception)
2981{
2982 int winner = -1;
2983 ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms);
2984 return winner;
2985}
2986
2987/*! \brief Wait for x amount of time on a file descriptor to have input. */
2988struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds, int nfds,
2989 int *exception, int *outfd, int *ms)
2990{
2991 struct timeval start = { 0 , 0 };
2992 struct pollfd *pfds = NULL;
2993 int res;
2994 long rms;
2995 int x, y, max;
2996 int sz = nfds;
2997 struct timeval now = { 0, 0 };
2998 struct timeval whentohangup = { 0, 0 }, diff;
2999 struct ast_channel *winner = NULL;
3000 struct fdmap {
3001 int chan;
3002 int fdno;
3003 } *fdmap = NULL;
3004
3005 if (outfd) {
3006 *outfd = -99999;
3007 }
3008 if (exception) {
3009 *exception = 0;
3010 }
3011
3012 for (x = 0; x < n; x++) {
3013 ast_channel_lock(c[x]);
3015 if (ast_tvzero(whentohangup))
3016 now = ast_tvnow();
3017 diff = ast_tvsub(*ast_channel_whentohangup(c[x]), now);
3018 if (diff.tv_sec < 0 || ast_tvzero(diff)) {
3019 ast_test_suite_event_notify("HANGUP_TIME", "Channel: %s", ast_channel_name(c[x]));
3020 /* Should already be hungup */
3023 return c[x];
3024 }
3025 if (ast_tvzero(whentohangup) || ast_tvcmp(diff, whentohangup) < 0)
3026 whentohangup = diff;
3027 }
3028 sz += ast_channel_fd_count(c[x]);
3030 }
3031
3032 if (!sz) {
3033 return NULL;
3034 }
3035
3036 pfds = ast_alloca(sizeof(*pfds) * sz);
3037 fdmap = ast_alloca(sizeof(*fdmap) * sz);
3038
3039 /* Wait full interval */
3040 rms = *ms;
3041 /* INT_MAX, not LONG_MAX, because it matters on 64-bit */
3042 if (!ast_tvzero(whentohangup) && whentohangup.tv_sec < INT_MAX / 1000) {
3043 rms = whentohangup.tv_sec * 1000 + whentohangup.tv_usec / 1000; /* timeout in milliseconds */
3044 if (*ms >= 0 && *ms < rms) { /* original *ms still smaller */
3045 rms = *ms;
3046 }
3047 } else if (!ast_tvzero(whentohangup) && rms < 0) {
3048 /* Tiny corner case... call would need to last >24 days */
3049 rms = INT_MAX;
3050 }
3051 /*
3052 * Build the pollfd array, putting the channels' fds first,
3053 * followed by individual fds. Order is important because
3054 * individual fd's must have priority over channel fds.
3055 */
3056 max = 0;
3057 for (x = 0; x < n; x++) {
3058 ast_channel_lock(c[x]);
3059 for (y = 0; y < ast_channel_fd_count(c[x]); y++) {
3060 fdmap[max].fdno = y; /* fd y is linked to this pfds */
3061 fdmap[max].chan = x; /* channel x is linked to this pfds */
3062 max += ast_add_fd(&pfds[max], ast_channel_fd(c[x], y));
3063 }
3064 CHECK_BLOCKING(c[x]);
3066 }
3067 /* Add the individual fds */
3068 for (x = 0; x < nfds; x++) {
3069 fdmap[max].chan = -1;
3070 max += ast_add_fd(&pfds[max], fds[x]);
3071 }
3072
3073 if (*ms > 0) {
3074 start = ast_tvnow();
3075 }
3076
3077 if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */
3078 do {
3079 int kbrms = rms;
3080 if (kbrms > 600000) {
3081 kbrms = 600000;
3082 }
3083 res = ast_poll(pfds, max, kbrms);
3084 if (!res) {
3085 rms -= kbrms;
3086 }
3087 } while (!res && (rms > 0));
3088 } else {
3089 res = ast_poll(pfds, max, rms);
3090 }
3091 for (x = 0; x < n; x++) {
3092 ast_channel_lock(c[x]);
3095 }
3096 if (res < 0) { /* Simulate a timeout if we were interrupted */
3097 if (errno != EINTR) {
3098 *ms = -1;
3099 }
3100 return NULL;
3101 }
3102 if (!ast_tvzero(whentohangup)) { /* if we have a timeout, check who expired */
3103 now = ast_tvnow();
3104 for (x = 0; x < n; x++) {
3106 ast_test_suite_event_notify("HANGUP_TIME", "Channel: %s", ast_channel_name(c[x]));
3108 if (winner == NULL) {
3109 winner = c[x];
3110 }
3111 }
3112 }
3113 }
3114 if (res == 0) { /* no fd ready, reset timeout and done */
3115 *ms = 0; /* XXX use 0 since we may not have an exact timeout. */
3116 return winner;
3117 }
3118 /*
3119 * Then check if any channel or fd has a pending event.
3120 * Remember to check channels first and fds last, as they
3121 * must have priority on setting 'winner'
3122 */
3123 for (x = 0; x < max; x++) {
3124 res = pfds[x].revents;
3125 if (res == 0) {
3126 continue;
3127 }
3128 if (fdmap[x].chan >= 0) { /* this is a channel */
3129 winner = c[fdmap[x].chan]; /* override previous winners */
3130 ast_channel_lock(winner);
3131 if (res & POLLPRI) {
3133 } else {
3135 }
3136 ast_channel_fdno_set(winner, fdmap[x].fdno);
3137 ast_channel_unlock(winner);
3138 } else { /* this is an fd */
3139 if (outfd) {
3140 *outfd = pfds[x].fd;
3141 }
3142 if (exception) {
3143 *exception = (res & POLLPRI) ? -1 : 0;
3144 }
3145 winner = NULL;
3146 }
3147 }
3148 if (*ms > 0) {
3149 *ms -= ast_tvdiff_ms(ast_tvnow(), start);
3150 if (*ms < 0) {
3151 *ms = 0;
3152 }
3153 }
3154 return winner;
3155}
3156
3157struct ast_channel *ast_waitfor_n(struct ast_channel **c, int n, int *ms)
3158{
3159 return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms);
3160}
3161
3162int ast_waitfor(struct ast_channel *c, int ms)
3163{
3164 if (ms < 0) {
3165 do {
3166 ms = 100000;
3167 ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms);
3168 } while (!ms);
3169 } else {
3170 ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms);
3171 }
3172 return ms;
3173}
3174
3175int ast_waitfordigit(struct ast_channel *c, int ms)
3176{
3177 return ast_waitfordigit_full(c, ms, NULL, -1, -1);
3178}
3179
3180int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data)
3181{
3182 return ast_settimeout_full(c, rate, func, data, 0);
3183}
3184
3185int ast_settimeout_full(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data, unsigned int is_ao2_obj)
3186{
3187 int res;
3188 unsigned int real_rate = rate, max_rate;
3189
3191
3192 if (ast_channel_timingfd(c) == -1) {
3194 return -1;
3195 }
3196
3197 if (!func) {
3198 rate = 0;
3199 data = NULL;
3200 }
3201
3202 if (rate && rate > (max_rate = ast_timer_get_max_rate(ast_channel_timer(c)))) {
3203 real_rate = max_rate;
3204 }
3205
3206 ast_debug(3, "Scheduling timer at (%u requested / %u actual) timer ticks per second\n", rate, real_rate);
3207
3208 res = ast_timer_set_rate(ast_channel_timer(c), real_rate);
3209
3212 }
3213
3216
3217 if (data && is_ao2_obj) {
3218 ao2_ref(data, 1);
3220 } else {
3222 }
3223
3224 if (func == NULL && rate == 0 && ast_channel_fdno(c) == AST_TIMING_FD) {
3225 /* Clearing the timing func and setting the rate to 0
3226 * means that we don't want to be reading from the timingfd
3227 * any more. Setting c->fdno to -1 means we won't have any
3228 * errant reads from the timingfd, meaning we won't potentially
3229 * miss any important frames.
3230 */
3232 }
3233
3235
3236 return res;
3237}
3238
3239int ast_waitfordigit_full(struct ast_channel *c, int timeout_ms, const char *breakon, int audiofd, int cmdfd)
3240{
3241 struct timeval start = ast_tvnow();
3242 int ms;
3243
3244 /* Stop if we're a zombie or need a soft hangup */
3246 return -1;
3247
3248 /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */
3250
3251 /* Wait for a digit, no more than timeout_ms milliseconds total.
3252 * Or, wait indefinitely if timeout_ms is <0.
3253 */
3254 while ((ms = ast_remaining_ms(start, timeout_ms))) {
3255 struct ast_channel *rchan;
3256 int outfd = -1;
3257
3258 errno = 0;
3259 /* While ast_waitfor_nandfds tries to help by reducing the timeout by how much was waited,
3260 * it is unhelpful if it waited less than a millisecond.
3261 */
3262 rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
3263
3264 if (!rchan && outfd < 0 && ms) {
3265 if (errno == 0 || errno == EINTR)
3266 continue;
3267 ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
3269 return -1;
3270 } else if (outfd > -1) {
3271 /* The FD we were watching has something waiting */
3272 ast_log(LOG_WARNING, "The FD we were waiting for has something waiting. Waitfordigit returning numeric 1\n");
3274 return 1;
3275 } else if (rchan) {
3276 int res;
3277 struct ast_frame *f = ast_read(c);
3278
3279 if (!f) {
3281
3282 return -1;
3283 }
3284
3285 switch (f->frametype) {
3287 break;
3288 case AST_FRAME_DTMF_END:
3289 res = f->subclass.integer;
3290 if (!breakon || strchr(breakon, res)) {
3291 ast_frfree(f);
3293 return res;
3294 }
3295 break;
3296 case AST_FRAME_CONTROL:
3297 switch (f->subclass.integer) {
3298 case AST_CONTROL_HANGUP:
3299 ast_frfree(f);
3301 return -1;
3307 /* Fall-through and treat as if it were a DTMF signal. Items
3308 * that perform stream control will handle this. */
3309 res = f->subclass.integer;
3310 ast_frfree(f);
3312 return res;
3316 case AST_CONTROL_ANSWER:
3322 case AST_CONTROL_HOLD:
3323 case AST_CONTROL_UNHOLD:
3324 case AST_CONTROL_FLASH:
3325 case -1:
3326 /* Unimportant */
3327 break;
3328 default:
3329 ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass.integer);
3330 break;
3331 }
3332 break;
3333 case AST_FRAME_VOICE:
3334 /* Write audio if appropriate */
3335 if (audiofd > -1) {
3336 if (write(audiofd, f->data.ptr, f->datalen) < 0) {
3337 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
3338 }
3339 }
3340 default:
3341 /* Ignore */
3342 break;
3343 }
3344 ast_frfree(f);
3345 }
3346 }
3347
3349
3350 return 0; /* Time is up */
3351}
3352
3355 DTMF_SENT
3357
3359{
3360 switch (direction) {
3361 case DTMF_RECEIVED:
3362 return "Received";
3363 case DTMF_SENT:
3364 return "Sent";
3365 }
3366
3367 return "?";
3368}
3369
3370static void send_dtmf_begin_event(struct ast_channel *chan,
3371 enum DtmfDirection direction, const char digit)
3372{
3373 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
3374 char digit_str[] = { digit, '\0' };
3375
3376 blob = ast_json_pack("{ s: s, s: s }",
3377 "digit", digit_str,
3378 "direction", dtmf_direction_to_string(direction));
3379 if (!blob) {
3380 return;
3381 }
3382
3384}
3385
3386static void send_dtmf_end_event(struct ast_channel *chan,
3387 enum DtmfDirection direction, const char digit, long duration_ms)
3388{
3389 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
3390 char digit_str[] = { digit, '\0' };
3391
3392 blob = ast_json_pack("{ s: s, s: s, s: I }",
3393 "digit", digit_str,
3394 "direction", dtmf_direction_to_string(direction),
3395 "duration_ms", (ast_json_int_t)duration_ms);
3396 if (!blob) {
3397 return;
3398 }
3399
3401}
3402
3403static void send_flash_event(struct ast_channel *chan)
3404{
3406}
3407
3408static void send_wink_event(struct ast_channel *chan)
3409{
3411}
3412
3413static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f)
3414{
3415 struct ast_generator *generator;
3416 void *gendata;
3417 int res;
3418 int samples;
3419
3420 generator = ast_channel_generator(chan);
3421 if (!generator
3422 || !generator->generate
3423 || f->frametype != AST_FRAME_VOICE
3425 || ast_channel_timingfunc(chan)) {
3426 return;
3427 }
3428
3429 /*
3430 * We must generate frames in phase locked mode since
3431 * we have no internal timer available.
3432 */
3434 float factor;
3436 samples = (int) (((float) f->samples) * factor);
3437 } else {
3438 samples = f->samples;
3439 }
3440
3441 gendata = ast_channel_generatordata(chan);
3442 ast_channel_generatordata_set(chan, NULL); /* reset, to let writes go through */
3443
3444 /*
3445 * This unlock is here based on two assumptions that hold true at
3446 * this point in the code. 1) this function is only called from
3447 * within __ast_read() and 2) all generators call ast_write() in
3448 * their generate callback.
3449 *
3450 * The reason this is added is so that when ast_write is called,
3451 * the lock that occurs there will not recursively lock the
3452 * channel. Doing this will allow deadlock avoidance to work in
3453 * deeper functions.
3454 */
3455 ast_channel_unlock(chan);
3456 res = generator->generate(chan, gendata, f->datalen, samples);
3457 ast_channel_lock(chan);
3458 if (generator == ast_channel_generator(chan)) {
3459 ast_channel_generatordata_set(chan, gendata);
3460 if (res) {
3461 ast_debug(1, "Auto-deactivating generator\n");
3463 }
3464 }
3465}
3466
3467static inline void queue_dtmf_readq(struct ast_channel *chan, struct ast_frame *f)
3468{
3469 struct ast_frame *fr = ast_channel_dtmff(chan);
3470
3473 fr->len = f->len;
3474
3475 /* The only time this function will be called is for a frame that just came
3476 * out of the channel driver. So, we want to stick it on the tail of the
3477 * readq. */
3478
3479 ast_queue_frame(chan, fr);
3480}
3481
3482/*!
3483 * \brief Determine whether or not we should ignore DTMF in the readq
3484 */
3485static inline int should_skip_dtmf(struct ast_channel *chan)
3486{
3488 /* We're in the middle of emulating a digit, or DTMF has been
3489 * explicitly deferred. Skip this digit, then. */
3490 return 1;
3491 }
3492
3493 if (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
3495 /* We're not in the middle of a digit, but it hasn't been long enough
3496 * since the last digit, so we'll have to skip DTMF for now. */
3497 return 1;
3498 }
3499
3500 return 0;
3501}
3502
3503/*!
3504 * \brief calculates the number of samples to jump forward with in a monitor stream.
3505
3506 * \note When using ast_seekstream() with the read and write streams of a monitor,
3507 * the number of samples to seek forward must be of the same sample rate as the stream
3508 * or else the jump will not be calculated correctly.
3509 *
3510 * \retval number of samples to seek forward after rate conversion.
3511 */
3512static inline int calc_monitor_jump(int samples, int sample_rate, int seek_rate)
3513{
3514 int diff = sample_rate - seek_rate;
3515
3516 if (diff > 0) {
3517 samples = samples / (float) (sample_rate / seek_rate);
3518 } else if (diff < 0) {
3519 samples = samples * (float) (seek_rate / sample_rate);
3520 }
3521
3522 return samples;
3523}
3524
3525static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio, int dropnondefault)
3526{
3527 struct ast_frame *f = NULL; /* the return value */
3528 int prestate;
3529 int cause = 0;
3530 struct ast_stream *stream = NULL, *default_stream = NULL;
3531
3532 /* this function is very long so make sure there is only one return
3533 * point at the end (there are only two exceptions to this).
3534 */
3535 ast_channel_lock(chan);
3536
3537 /* Stop if we're a zombie or need a soft hangup */
3539 if (ast_channel_generator(chan))
3541
3542 /*
3543 * It is possible for chan->_softhangup to be set and there
3544 * still be control frames that need to be read. Instead of
3545 * just going to 'done' in the case of ast_check_hangup(), we
3546 * need to queue the end-of-Q frame so that it can mark the end
3547 * of the read queue. If there are frames to be read,
3548 * ast_queue_control() will be called repeatedly, but will only
3549 * queue the first end-of-Q frame.
3550 */
3553 } else {
3554 goto done;
3555 }
3556 } else {
3557#ifdef AST_DEVMODE
3558 /*
3559 * The ast_waitfor() code records which of the channel's file
3560 * descriptors reported that data is available. In theory,
3561 * ast_read() should only be called after ast_waitfor() reports
3562 * that a channel has data available for reading. However,
3563 * there still may be some edge cases throughout the code where
3564 * ast_read() is called improperly. This can potentially cause
3565 * problems, so if this is a developer build, make a lot of
3566 * noise if this happens so that it can be addressed.
3567 *
3568 * One of the potential problems is blocking on a dead channel.
3569 */
3570 if (ast_channel_fdno(chan) == -1) {
3572 "ast_read() on chan '%s' called with no recorded file descriptor.\n",
3573 ast_channel_name(chan));
3574 }
3575#endif
3576 }
3577
3578 prestate = ast_channel_state(chan);
3579
3580 if (ast_channel_timingfd(chan) > -1 && ast_channel_fdno(chan) == AST_TIMING_FD) {
3581 enum ast_timer_event res;
3582 int trigger_dtmf_emulating = should_trigger_dtmf_emulating(chan);
3583
3585
3587
3588 switch (res) {
3590 if (ast_timer_ack(ast_channel_timer(chan), 1) < 0) {
3591 ast_log(LOG_ERROR, "Failed to acknowledge timer in ast_read\n");
3592 goto done;
3593 }
3594
3595 if (ast_channel_timingfunc(chan)) {
3596 /* save a copy of func/data before unlocking the channel */
3598 void *data = ast_channel_timingdata(chan);
3599 int got_ref = 0;
3601 ao2_ref(data, 1);
3602 got_ref = 1;
3603 }
3604 ast_channel_fdno_set(chan, -1);
3605 ast_channel_unlock(chan);
3606 func(data);
3607 if (got_ref) {
3608 ao2_ref(data, -1);
3609 }
3610
3611 if (trigger_dtmf_emulating) {
3612 /*
3613 * Since we're breaking out of this switch block and not
3614 * returning, we need to re-lock the channel.
3615 */
3616 ast_channel_lock(chan);
3617 /* generate null frame to trigger dtmf emulating */
3618 f = &ast_null_frame;
3619 break;
3620 }
3621 } else if (trigger_dtmf_emulating) {
3622 /* generate null frame to trigger dtmf emulating */
3623 f = &ast_null_frame;
3624 break;
3625 } else {
3627 /* generate very last null frame to trigger dtmf emulating */
3628 f = &ast_null_frame;
3629 break;
3630 }
3631
3632 /* cannot 'goto done' because the channel is already unlocked */
3633 return &ast_null_frame;
3634
3636 if (AST_LIST_EMPTY(ast_channel_readq(chan)) ||
3639 }
3640 break;
3641 }
3642
3644 /* if the AST_GENERATOR_FD is set, call the generator with args
3645 * set to -1 so it can do whatever it needs to.
3646 */
3647 void *tmp = ast_channel_generatordata(chan);
3648 ast_channel_generatordata_set(chan, NULL); /* reset to let ast_write get through */
3649 ast_channel_generator(chan)->generate(chan, tmp, -1, -1);
3651 f = &ast_null_frame;
3652 ast_channel_fdno_set(chan, -1);
3653 goto done;
3656 }
3657
3658 /* Read and ignore anything on the alertpipe, but read only
3659 one sizeof(blah) per frame that we send from it */
3661 f = &ast_null_frame;
3662 goto done;
3663 }
3664
3665 /* Check for pending read queue */
3666 if (!AST_LIST_EMPTY(ast_channel_readq(chan))) {
3667 int skipped_dtmf_frame = 0;
3668 int skip_dtmf = should_skip_dtmf(chan);
3669
3671 /* We have to be picky about which frame we pull off of the readq because
3672 * there are cases where we want to leave DTMF frames on the queue until
3673 * some later time. */
3674
3675 if ( (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) && skip_dtmf) {
3676 skipped_dtmf_frame = 1;
3677 continue;
3678 }
3679
3681 break;
3682 }
3684
3685 if (!f) {
3686 /* There were no acceptable frames on the readq. */
3687 f = &ast_null_frame;
3688 if (!skipped_dtmf_frame) {
3689 /*
3690 * Do not trigger alert pipe if only buffered dtmf begin or end frames
3691 * are left in the readq.
3692 */
3694 } else {
3695 /*
3696 * Safely disable continous timer events if only buffered dtmf begin or end
3697 * frames are left in the readq.
3698 */
3700 }
3701 }
3702
3703 /* Interpret hangup and end-of-Q frames to return NULL */
3704 /* XXX why not the same for frames from the channel ? */
3705 if (f->frametype == AST_FRAME_CONTROL) {
3706 switch (f->subclass.integer) {
3707 case AST_CONTROL_HANGUP:
3709 cause = f->data.uint32;
3710 /* Fall through */
3712 ast_frfree(f);
3713 f = NULL;
3714 break;
3715 default:
3716 break;
3717 }
3718 } else if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO) {
3719 if (ast_channel_tech(chan) && ast_channel_tech(chan)->read_stream) {
3722 } else {
3723 /* Since this channel driver does not support multistream determine the default stream this frame
3724 * originated from and update the frame to include it.
3725 */
3726 stream = default_stream = ast_channel_get_default_stream(chan, ast_format_get_type(f->subclass.format));
3727 /* In order to allow media to be passed up the underlying media type has to have a format negotiated on
3728 * the channel itself. In cases where this hasn't happened the channel driver is incorrectly passing up
3729 * a frame for a format that has not been negotiated. If this occurs just drop the frame as we have no
3730 * stream that it came from.
3731 */
3732 if (!stream) {
3733 ast_frfree(f);
3734 f = &ast_null_frame;
3735 } else {
3737 }
3738 }
3739 }
3740 } else {
3742 if (ast_channel_tech(chan)->exception)
3743 f = ast_channel_tech(chan)->exception(chan);
3744 else {
3745 ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", ast_channel_name(chan));
3746 f = &ast_null_frame;
3747 }
3748 /* Clear the exception flag */
3750 } else if (ast_channel_tech(chan) && ast_channel_tech(chan)->read_stream) {
3751 f = ast_channel_tech(chan)->read_stream(chan);
3752
3753 /* This channel driver supports multistream so the stream_num on the frame is valid, the only
3754 * thing different is that we need to find the default stream so we know whether to invoke the
3755 * default stream logic or not (such as transcoding).
3756 */
3757 if (f && (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO)) {
3760 }
3761 } else if (ast_channel_tech(chan) && ast_channel_tech(chan)->read) {
3762 f = ast_channel_tech(chan)->read(chan);
3763
3764 /* Since this channel driver does not support multistream determine the default stream this frame
3765 * originated from and update the frame to include it.
3766 */
3767 if (f && (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO)) {
3768 stream = default_stream = ast_channel_get_default_stream(chan, ast_format_get_type(f->subclass.format));
3769 if (!stream) {
3770 ast_frfree(f);
3771 f = &ast_null_frame;
3772 } else {
3774 }
3775 }
3776 }
3777 else
3778 ast_log(LOG_WARNING, "No read routine on channel %s\n", ast_channel_name(chan));
3779 }
3780
3781 if (stream == default_stream) {
3782 /* Perform the framehook read event here. After the frame enters the framehook list
3783 * there is no telling what will happen, <insert mad scientist laugh here>!!! */
3785 }
3786
3787 /*
3788 * Reset the recorded file descriptor that triggered this read so that we can
3789 * easily detect when ast_read() is called without properly using ast_waitfor().
3790 */
3791 ast_channel_fdno_set(chan, -1);
3792
3793 if (f) {
3794 struct ast_frame *readq_tail = AST_LIST_LAST(ast_channel_readq(chan));
3795 struct ast_control_read_action_payload *read_action_payload;
3797 int hooked = 0;
3798
3799 /* if the channel driver returned more than one frame, stuff the excess
3800 into the readq for the next ast_read call
3801 */
3802 if (AST_LIST_NEXT(f, frame_list)) {
3806 }
3807
3808 if (dropnondefault && stream != default_stream) {
3809 /* If the frame originates from a non-default stream and the caller can not handle other streams
3810 * absorb the frame and replace it with a null one instead.
3811 */
3812 ast_frfree(f);
3813 f = &ast_null_frame;
3814 }
3815
3816 switch (f->frametype) {
3817 case AST_FRAME_CONTROL:
3819 if (prestate == AST_STATE_UP && ast_channel_is_bridged(chan)) {
3820 ast_debug(1, "Dropping duplicate answer!\n");
3821 ast_frfree(f);
3822 f = &ast_null_frame;
3823 } else {
3824 /*
3825 * Mark when outgoing channel answered so we can know how
3826 * long the channel has been up.
3827 */
3829
3831 }
3832 } else if (f->subclass.integer == AST_CONTROL_READ_ACTION) {
3833 read_action_payload = f->data.ptr;
3834 switch (read_action_payload->action) {
3838 if (ast_connected_line_parse_data(read_action_payload->payload,
3839 read_action_payload->payload_size, &connected)) {
3841 break;
3842 }
3843 ast_channel_unlock(chan);
3846 read_action_payload->payload,
3847 read_action_payload->payload_size);
3848 }
3850 ast_channel_lock(chan);
3851 break;
3853 ast_channel_unlock(chan);
3854 ast_sendtext(chan, (const char *)read_action_payload->payload);
3855 ast_channel_lock(chan);
3856 break;
3858 ast_channel_unlock(chan);
3859 ast_sendtext_data(chan, (struct ast_msg_data *)read_action_payload->payload);
3860 ast_channel_lock(chan);
3861 break;
3862 }
3863 ast_frfree(f);
3864 f = &ast_null_frame;
3865 } else if (f->subclass.integer == AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE && dropnondefault) {
3866 /* The caller of this function is incapable of handling streams so we don't accept the change request
3867 * and stick to the streams currently on the channel.
3868 */
3870 ast_frfree(f);
3871 f = &ast_null_frame;
3872 } else if (f->subclass.integer == AST_CONTROL_STREAM_TOPOLOGY_CHANGED && dropnondefault) {
3873 /* The caller of this function is incapable of handling streams so we absorb the notification that the
3874 * stream topology has changed.
3875 */
3876 ast_frfree(f);
3877 f = &ast_null_frame;
3878 } else if (f->subclass.integer == AST_CONTROL_FLASH) {
3879 send_flash_event(chan);
3880 } else if (f->subclass.integer == AST_CONTROL_WINK) {
3881 send_wink_event(chan);
3882 }
3883 break;
3884 case AST_FRAME_DTMF_END:
3886 ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass.integer, ast_channel_name(chan), f->len);
3887 /* Queue it up if DTMF is deferred, or if DTMF emulation is forced. */
3889 queue_dtmf_readq(chan, f);
3890 ast_frfree(f);
3891 f = &ast_null_frame;
3893 if (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
3895 /* If it hasn't been long enough, defer this digit */
3896 queue_dtmf_readq(chan, f);
3897 ast_frfree(f);
3898 f = &ast_null_frame;
3899 } else {
3900 /* There was no begin, turn this into a begin and send the end later */
3901 struct timeval tv = ast_tvnow();
3905 ast_channel_dtmf_tv_set(chan, &tv);
3906 if (f->len) {
3907 if (f->len > option_dtmfminduration)
3909 else
3911 } else
3913 ast_log(LOG_DTMF, "DTMF begin emulation of '%c' with duration %u queued on %s\n", f->subclass.integer, ast_channel_emulate_dtmf_duration(chan), ast_channel_name(chan));
3914
3915 /*
3916 * Start generating 50 fps timer events (null frames) for dtmf emulating
3917 * independently from any existing incoming voice frames.
3918 * If channel generator is already activated in regular mode use these
3919 * timer events to generate null frames.
3920 */
3921 if (!ast_channel_generator(chan)) {
3923 }
3924 }
3925 if (ast_channel_audiohooks(chan)) {
3926 struct ast_frame *old_frame = f;
3927 /*!
3928 * \todo XXX It is possible to write a digit to the audiohook twice
3929 * if the digit was originally read while the channel was in autoservice. */
3931 if (old_frame != f)
3932 ast_frfree(old_frame);
3933 }
3934 } else {
3935 struct timeval now = ast_tvnow();
3937 ast_log(LOG_DTMF, "DTMF end accepted with begin '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
3939 if (!f->len)
3940 f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
3941
3942 /* detect tones that were received on
3943 * the wire with durations shorter than
3944 * option_dtmfminduration and set f->len
3945 * to the actual duration of the DTMF
3946 * frames on the wire. This will cause
3947 * dtmf emulation to be triggered later
3948 * on.
3949 */
3951 f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
3952 ast_log(LOG_DTMF, "DTMF end '%c' detected to have actual duration %ld on the wire, emulation will be triggered on %s\n", f->subclass.integer, f->len, ast_channel_name(chan));
3953 }
3954 } else if (!f->len) {
3955 ast_log(LOG_DTMF, "DTMF end accepted without begin '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
3957 }
3959 ast_log(LOG_DTMF, "DTMF end '%c' has duration %ld but want minimum %u, emulating on %s\n", f->subclass.integer, f->len, option_dtmfminduration, ast_channel_name(chan));
3963 ast_frfree(f);
3964 f = &ast_null_frame;
3965
3966 /* Start generating 50 fps timer events (null frames) for dtmf emulating
3967 * independently from any existing incoming voice frames.
3968 * If channel generator is already activated in regular mode use these
3969 * timer events to generate null frames.
3970 */
3971 if (!ast_channel_generator(chan)) {
3973 }
3974 } else {
3975 ast_log(LOG_DTMF, "DTMF end passthrough '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
3976 if (f->len < option_dtmfminduration) {
3978 }
3979 ast_channel_dtmf_tv_set(chan, &now);
3980
3981 /* Start generating 50 fps timer events (null frames) for dtmf emulating
3982 * independently from any existing incoming voice frames.
3983 * If channel generator is already activated in regular mode use these
3984 * timer events to generate null frames.
3985 */
3986 if (!ast_channel_generator(chan)) {
3988 }
3989 }
3990 if (ast_channel_audiohooks(chan)) {
3991 struct ast_frame *old_frame = f;
3993 if (old_frame != f)
3994 ast_frfree(old_frame);
3995 }
3996 }
3997 break;
4000 ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass.integer, ast_channel_name(chan));
4002 (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
4004 ast_log(LOG_DTMF, "DTMF begin ignored '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
4005 ast_frfree(f);
4006 f = &ast_null_frame;
4007 } else {
4008 struct timeval now = ast_tvnow();
4010 ast_channel_dtmf_tv_set(chan, &now);
4011 ast_log(LOG_DTMF, "DTMF begin passthrough '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
4012 }
4013 break;
4014 case AST_FRAME_NULL:
4015 /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration
4016 * is reached , because we want to make sure we pass at least one
4017 * voice frame through before starting the next digit, to ensure a gap
4018 * between DTMF digits. */
4020 struct timeval now = ast_tvnow();
4024 } else if (ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan)) >= ast_channel_emulate_dtmf_duration(chan)) {
4026 ast_frfree(f);
4027 f = ast_channel_dtmff(chan);
4030 f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
4031 ast_channel_dtmf_tv_set(chan, &now);
4034 ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass.integer, ast_channel_name(chan));
4035 if (ast_channel_audiohooks(chan)) {
4036 struct ast_frame *old_frame = f;
4038 if (old_frame != f) {
4039 ast_frfree(old_frame);
4040 }
4041 }
4042
4043 /* Start generating 50 fps timer events (null frames) for dtmf emulating
4044 * independently from any existing incoming voice frames.
4045 * If channel generator is already activated in regular mode use these
4046 * timer events to generate null frames.
4047 */
4048 if (!ast_channel_generator(chan)) {
4050 }
4051 }
4052 }
4053 break;
4054 case AST_FRAME_VOICE:
4055 /* If media was received from a non-default stream don't perform any actions, let it just go through */
4056 if (stream != default_stream) {
4057 break;
4058 }
4059
4060 /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration
4061 * is reached , because we want to make sure we pass at least one
4062 * voice frame through before starting the next digit, to ensure a gap
4063 * between DTMF digits. */
4067 }
4068
4069 if (dropaudio || ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF)) {
4070 if (dropaudio)
4072 ast_frfree(f);
4073 f = &ast_null_frame;
4074 }
4075
4077 struct timeval now = ast_tvnow();
4080 ast_frfree(f);
4081 f = ast_channel_dtmff(chan);
4084 f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
4085 ast_channel_dtmf_tv_set(chan, &now);
4086 if (ast_channel_audiohooks(chan)) {
4087 struct ast_frame *old_frame = f;
4089 if (old_frame != f)
4090 ast_frfree(old_frame);
4091 }
4092 ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass.integer, ast_channel_name(chan));
4093 } else {
4094 /* Drop voice frames while we're still in the middle of the digit */
4095 ast_frfree(f);
4096 f = &ast_null_frame;
4097 }
4098 break;
4099 }
4100 if (f->frametype != AST_FRAME_VOICE) {
4101 break;
4102 }
4105 struct ast_format *core_format;
4106
4107 /*
4108 * Note: This frame may not be one of the current native
4109 * formats. We may have gotten it out of the read queue from
4110 * a previous multi-frame translation, from a framehook
4111 * injected frame, or the device we're talking to isn't
4112 * respecting negotiated formats. Regardless we will accept
4113 * all frames.
4114 *
4115 * Update the read translation path to handle the new format
4116 * that just came in. If the core wants slinear we need to
4117 * setup a new translation path because the core is usually
4118 * doing something with the audio itself and may not handle
4119 * any other format. e.g., Softmix bridge, holding bridge
4120 * announcer channel, recording, AMD... Otherwise, we'll
4121 * setup to pass the frame as is to the core. In this case
4122 * the core doesn't care. The channel is likely in
4123 * autoservice, safesleep, or the channel is in a bridge.
4124 * Let the bridge technology deal with format compatibility
4125 * between the channels in the bridge.
4126 *
4127 * Beware of the transcode_via_slin and genericplc options as
4128 * they force any transcoding to go through slin on a bridge.
4129 * Unfortunately transcode_via_slin is enabled by default and
4130 * genericplc is enabled in the codecs.conf.sample file.
4131 *
4132 * XXX Only updating translation to slinear frames has some
4133 * corner cases if slinear is one of the native formats and
4134 * there are different sample rates involved. We might wind
4135 * up with conflicting translation paths between channels
4136 * where the read translation path on this channel reduces
4137 * the sample rate followed by a write translation path on
4138 * the peer channel that increases the sample rate.
4139 */
4140 core_format = ast_channel_readformat(chan);
4141 if (!ast_format_cache_is_slinear(core_format)) {
4142 core_format = f->subclass.format;
4143 }
4144 if (ast_set_read_format_path(chan, f->subclass.format, core_format)) {
4145 /* Drop frame. We couldn't make it compatible with the core. */
4146 ast_frfree(f);
4147 f = &ast_null_frame;
4148 break;
4149 }
4150 }
4151 /*
4152 * Send frame to audiohooks if present, if frametype is linear, to preserve
4153 * functional compatibility with previous behavior. If not linear, hold off
4154 * until transcoding is done where we are more likely to have a linear frame
4155 */
4157 /* Place hooked after declaration */
4158 struct ast_frame *old_frame = f;
4159 hooked = 1;
4160
4162 if (old_frame != f) {
4163 ast_frfree(old_frame);
4164 }
4165 }
4166
4167 if (ast_channel_readtrans(chan)
4169 f = ast_translate(ast_channel_readtrans(chan), f, 1);
4170 if (!f) {
4171 f = &ast_null_frame;
4172 }
4173 }
4174
4175 /* Second chance at hooking a linear frame, also the last chance */
4176 if (ast_channel_audiohooks(chan) && !hooked) {
4177 struct ast_frame *old_frame = f;
4178
4180 if (old_frame != f) {
4181 ast_frfree(old_frame);
4182 }
4183 }
4184
4185 /*
4186 * It is possible for the translation process on the channel to have
4187 * produced multiple frames from the single input frame we passed it; if
4188 * this happens, queue the additional frames *before* the frames we may
4189 * have queued earlier. if the readq was empty, put them at the head of
4190 * the queue, and if it was not, put them just after the frame that was
4191 * at the end of the queue.
4192 */
4193 if (AST_LIST_NEXT(f, frame_list)) {
4194 struct ast_frame *cur, *multi_frame = AST_LIST_NEXT(f, frame_list);
4195
4196 /* Mark these frames as being re-queued */
4197 for (cur = multi_frame; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
4199 }
4200
4201 if (!readq_tail) {
4202 ast_queue_frame_head(chan, multi_frame);
4203 } else {
4204 __ast_queue_frame(chan, multi_frame, 0, readq_tail);
4205 }
4206 ast_frfree(multi_frame);
4208 }
4209
4210 /*
4211 * Run generator sitting on the line if timing device not available
4212 * and synchronous generation of outgoing frames is necessary
4213 */
4215 break;
4216 case AST_FRAME_RTCP:
4217 /* Incoming RTCP feedback needs to get to the translator for
4218 * outgoing media, which means we treat it as an ast_write */
4219 if (ast_channel_writetrans(chan)) {
4221 }
4222 break;
4223 default:
4224 /* Just pass it on! */
4225 break;
4226 }
4227 } else {
4228 /* Make sure we always return NULL in the future */
4231 }
4232 if (cause)
4233 ast_channel_hangupcause_set(chan, cause);
4234 if (ast_channel_generator(chan))
4236 /* We no longer End the CDR here */
4237 }
4238
4239 /* High bit prints debugging */
4240 if (ast_channel_fin(chan) & DEBUGCHAN_FLAG)
4241 ast_frame_dump(ast_channel_name(chan), f, "<<");
4243
4244done:
4247
4249 /* The list gets recreated if audiohooks are added again later */
4252 }
4253 ast_channel_unlock(chan);
4254 return f;
4255}
4256
4257struct ast_frame *ast_read(struct ast_channel *chan)
4258{
4259 return __ast_read(chan, 0, 1);
4260}
4261
4263{
4264 return __ast_read(chan, 0, 0);
4265}
4266
4268{
4269 return __ast_read(chan, 1, 1);
4270}
4271
4273{
4274 return __ast_read(chan, 1, 0);
4275}
4276
4277int ast_indicate(struct ast_channel *chan, int condition)
4278{
4279 return ast_indicate_data(chan, condition, NULL, 0);
4280}
4281
4283{
4284 /* Don't include a default case here so that we get compiler warnings
4285 * when a new type is added. */
4286
4287 switch (condition) {
4295 case AST_CONTROL_OPTION:
4296 case AST_CONTROL_WINK:
4297 case AST_CONTROL_FLASH:
4300 case AST_CONTROL_ANSWER:
4301 case AST_CONTROL_HANGUP:
4307 case AST_CONTROL_CC:
4309 case AST_CONTROL_AOC:
4311 case AST_CONTROL_MCID:
4327 break;
4328
4331 case AST_CONTROL_BUSY:
4333 case AST_CONTROL_RING:
4334 case AST_CONTROL_HOLD:
4335 /* You can hear these */
4336 return 1;
4337
4338 case AST_CONTROL_UNHOLD:
4339 /* This is a special case. You stop hearing this. */
4340 break;
4341 }
4342
4343 return 0;
4344}
4345
4347{
4348 char causevar[256];
4349
4350 if (ast_channel_dialed_causes_add(chan, cause_code, datalen)) {
4351 ast_log(LOG_WARNING, "Unable to store hangup cause for %s on %s\n", cause_code->chan_name, ast_channel_name(chan));
4352 }
4353
4354 if (cause_code->emulate_sip_cause) {
4355 snprintf(causevar, sizeof(causevar), "HASH(SIP_CAUSE,%s)", cause_code->chan_name);
4356 ast_func_write(chan, causevar, cause_code->code);
4357 }
4358}
4359
4361{
4362 if (!strcasecmp(flag, "default"))
4363 return DEFAULT_AMA_FLAGS;
4364 if (!strcasecmp(flag, "omit"))
4365 return AST_AMA_OMIT;
4366 if (!strcasecmp(flag, "billing"))
4367 return AST_AMA_BILLING;
4368 if (!strcasecmp(flag, "documentation"))
4369 return AST_AMA_DOCUMENTATION;
4370 return AST_AMA_NONE;
4371}
4372
4374{
4375 switch (flag) {
4376 case AST_AMA_OMIT:
4377 return "OMIT";
4378 case AST_AMA_BILLING:
4379 return "BILLING";
4381 return "DOCUMENTATION";
4382 default:
4383 return "Unknown";
4384 }
4385}
4386
4387/*!
4388 * \internal
4389 * \brief Preprocess connected line update.
4390 * \since 12.0.0
4391 *
4392 * \param chan channel to change the indication
4393 * \param data pointer to payload data
4394 * \param datalen size of payload data
4395 *
4396 * \note This function assumes chan is locked.
4397 *
4398 * \retval 0 keep going.
4399 * \retval -1 quit now.
4400 */
4401static int indicate_connected_line(struct ast_channel *chan, const void *data, size_t datalen)
4402{
4403 struct ast_party_connected_line *chan_connected = ast_channel_connected(chan);
4404 struct ast_party_connected_line *chan_indicated = ast_channel_connected_indicated(chan);
4406 unsigned char current[1024];
4407 unsigned char proposed[1024];
4408 int current_size;
4409 int proposed_size;
4410 int res;
4411
4413 res = ast_connected_line_parse_data(data, datalen, &connected);
4414 if (!res) {
4416 }
4418 if (res) {
4419 return -1;
4420 }
4421
4422 current_size = ast_connected_line_build_data(current, sizeof(current),
4423 chan_indicated, NULL);
4424 proposed_size = ast_connected_line_build_data(proposed, sizeof(proposed),
4425 chan_connected, NULL);
4426 if (current_size == -1 || proposed_size == -1) {
4427 return -1;
4428 }
4429
4430 if (current_size == proposed_size && !memcmp(current, proposed, current_size)) {
4431 ast_debug(1, "%s: Dropping redundant connected line update \"%s\" <%s>.\n",
4432 ast_channel_name(chan),
4433 S_COR(chan_connected->id.name.valid, chan_connected->id.name.str, ""),
4434 S_COR(chan_connected->id.number.valid, chan_connected->id.number.str, ""));
4435 return -1;
4436 }
4437
4438 ast_party_connected_line_copy(chan_indicated, chan_connected);
4439 return 0;
4440}
4441
4442/*!
4443 * \internal
4444 * \brief Preprocess redirecting update.
4445 * \since 12.0.0
4446 *
4447 * \param chan channel to change the indication
4448 * \param data pointer to payload data
4449 * \param datalen size of payload data
4450 *
4451 * \note This function assumes chan is locked.
4452 *
4453 * \retval 0 keep going.
4454 * \retval -1 quit now.
4455 */
4456static int indicate_redirecting(struct ast_channel *chan, const void *data, size_t datalen)
4457{
4458 struct ast_party_redirecting redirecting;
4459 int res;
4460
4462 res = ast_redirecting_parse_data(data, datalen, &redirecting);
4463 if (!res) {
4464 ast_channel_set_redirecting(chan, &redirecting, NULL);
4465 }
4466 ast_party_redirecting_free(&redirecting);
4467 return res ? -1 : 0;
4468}
4469
4470static int indicate_data_internal(struct ast_channel *chan, int _condition, const void *data, size_t datalen)
4471{
4472 /* By using an enum, we'll get compiler warnings for values not handled
4473 * in switch statements. */
4474 enum ast_control_frame_type condition = _condition;
4475 struct ast_tone_zone_sound *ts = NULL;
4476 const struct ast_control_t38_parameters *t38_parameters;
4477 int res;
4478
4479 switch (condition) {
4481 if (indicate_connected_line(chan, data, datalen)) {
4482 res = 0;
4483 return res;
4484 }
4485 break;
4487 if (indicate_redirecting(chan, data, datalen)) {
4488 res = 0;
4489 return res;
4490 }
4491 break;
4492 case AST_CONTROL_HOLD:
4493 case AST_CONTROL_UNHOLD:
4494 ast_channel_hold_state_set(chan, _condition);
4495 break;
4497 t38_parameters = data;
4498 switch (t38_parameters->request_response) {
4500 case AST_T38_NEGOTIATED:
4502 break;
4504 case AST_T38_TERMINATED:
4505 case AST_T38_REFUSED:
4507 break;
4508 default:
4509 break;
4510 }
4511 break;
4512 default:
4513 break;
4514 }
4515
4516 if (is_visible_indication(condition)) {
4517 /* A new visible indication is requested. */
4518 ast_channel_visible_indication_set(chan, _condition);
4519 } else if (condition == AST_CONTROL_UNHOLD || _condition < 0) {
4520 /* Visible indication is cleared/stopped. */
4522 }
4523
4524 if (ast_channel_tech(chan)->indicate) {
4525 /* See if the channel driver can handle this condition. */
4526 res = ast_channel_tech(chan)->indicate(chan, _condition, data, datalen);
4527 } else {
4528 res = -1;
4529 }
4530
4531 if (!res) {
4532 /* The channel driver successfully handled this indication */
4533 res = 0;
4534 return res;
4535 }
4536
4537 /* The channel driver does not support this indication, let's fake
4538 * it by doing our own tone generation if applicable. */
4539
4540 /*!\note If we compare the enumeration type, which does not have any
4541 * negative constants, the compiler may optimize this code away.
4542 * Therefore, we must perform an integer comparison here. */
4543 if (_condition < 0) {
4544 /* Stop any tones that are playing */
4545 ast_playtones_stop(chan);
4546 res = 0;
4547 return res;
4548 }
4549
4550 /* Handle conditions that we have tones for. */
4551 switch (condition) {
4553 /* deprecated T.38 control frame */
4554 res = -1;
4555 return res;
4557 /* there is no way to provide 'default' behavior for these
4558 * control frames, so we need to return failure, but there
4559 * is also no value in the log message below being emitted
4560 * since failure to handle these frames is not an 'error'
4561 * so just return right now. in addition, we want to return
4562 * whatever value the channel driver returned, in case it
4563 * has some meaning.*/
4564 return res;
4566 ts = ast_get_indication_tone(ast_channel_zone(chan), "ring");
4567 /* It is common practice for channel drivers to return -1 if trying
4568 * to indicate ringing on a channel which is up. The idea is to let the
4569 * core generate the ringing inband. However, we don't want the
4570 * warning message about not being able to handle the specific indication
4571 * to print nor do we want ast_indicate_data to return an "error" for this
4572 * condition
4573 */
4574 if (ast_channel_state(chan) == AST_STATE_UP) {
4575 res = 0;
4576 }
4577 break;
4578 case AST_CONTROL_BUSY:
4579 ts = ast_get_indication_tone(ast_channel_zone(chan), "busy");
4580 break;
4583 ts = ast_get_indication_tone(ast_channel_zone(chan), "congestion");
4584 break;
4586 ast_channel_hangupcause_hash_set(chan, data, datalen);
4587 res = 0;
4588 break;
4596 case AST_CONTROL_OPTION:
4597 case AST_CONTROL_WINK:
4598 case AST_CONTROL_FLASH:
4601 case AST_CONTROL_ANSWER:
4602 case AST_CONTROL_HANGUP:
4603 case AST_CONTROL_RING:
4604 case AST_CONTROL_HOLD:
4605 case AST_CONTROL_UNHOLD:
4609 case AST_CONTROL_CC:
4611 case AST_CONTROL_AOC:
4613 case AST_CONTROL_MCID:
4628 /* Nothing left to do for these. */
4629 res = 0;
4630 break;
4631 }
4632
4633 if (ts) {
4634 /* We have a tone to play, yay. */
4635 ast_debug(1, "Driver for channel '%s' does not support indication %u, emulating it\n", ast_channel_name(chan), condition);
4636 res = ast_playtones_start(chan, 0, ts->data, 1);
4637 if (!res) {
4638 ast_test_suite_event_notify("RINGING_INBAND",
4639 "Channel: %s\r\n",
4640 ast_channel_name(chan));
4641 }
4643 }
4644
4645 if (res) {
4646 /* not handled */
4647 ast_log(LOG_WARNING, "Unable to handle indication %u for '%s'\n", condition, ast_channel_name(chan));
4648 }
4649
4650 return res;
4651}
4652
4653int ast_indicate_data(struct ast_channel *chan, int _condition, const void *data, size_t datalen)
4654{
4655 int res;
4656 /* this frame is used by framehooks. if it is set, we must free it at the end of this function */
4657 struct ast_frame *awesome_frame = NULL;
4658
4659 ast_channel_lock(chan);
4660
4661 /* Don't bother if the channel is about to go away, anyway. */
4664 && _condition != AST_CONTROL_MASQUERADE_NOTIFY) {
4665 res = -1;
4666 goto indicate_cleanup;
4667 }
4668
4670 /* Do framehooks now, do it, go, go now */
4671 struct ast_frame frame = {
4673 .subclass.integer = _condition,
4674 .data.ptr = (void *) data, /* this cast from const is only okay because we do the ast_frdup below */
4675 .datalen = datalen
4676 };
4677
4678 /* we have now committed to freeing this frame */
4679 awesome_frame = ast_frdup(&frame);
4680
4681 /* who knows what we will get back! the anticipation is killing me. */
4683 awesome_frame);
4684 if (!awesome_frame
4685 || awesome_frame->frametype != AST_FRAME_CONTROL) {
4686 res = 0;
4687 goto indicate_cleanup;
4688 }
4689
4690 _condition = awesome_frame->subclass.integer;
4691 data = awesome_frame->data.ptr;
4692 datalen = awesome_frame->datalen;
4693 }
4694
4695 res = indicate_data_internal(chan, _condition, data, datalen);
4696
4697indicate_cleanup:
4698 ast_channel_unlock(chan);
4699 if (awesome_frame) {
4700 ast_frfree(awesome_frame);
4701 }
4702
4703 return res;
4704}
4705
4706int ast_recvchar(struct ast_channel *chan, int timeout)
4707{
4708 int c;
4709 char *buf = ast_recvtext(chan, timeout);
4710 if (buf == NULL)
4711 return -1; /* error or timeout */
4712 c = *(unsigned char *)buf;
4713 ast_free(buf);
4714 return c;
4715}
4716
4717char *ast_recvtext(struct ast_channel *chan, int timeout)
4718{
4719 int res;
4720 char *buf = NULL;
4721 struct timeval start = ast_tvnow();
4722 int ms;
4723
4724 while ((ms = ast_remaining_ms(start, timeout))) {
4725 struct ast_frame *f;
4726
4727 if (ast_check_hangup(chan)) {
4728 break;
4729 }
4730 res = ast_waitfor(chan, ms);
4731 if (res <= 0) {/* timeout or error */
4732 break;
4733 }
4734 f = ast_read(chan);
4735 if (f == NULL) {
4736 break; /* no frame */
4737 }
4739 ast_frfree(f);
4740 break;
4741 } else if (f->frametype == AST_FRAME_TEXT) { /* what we want */
4742 buf = ast_strndup((char *) f->data.ptr, f->datalen); /* dup and break */
4743 ast_frfree(f);
4744 break;
4745 }
4746 ast_frfree(f);
4747 }
4748 return buf;
4749}
4750
4751int ast_sendtext_data(struct ast_channel *chan, struct ast_msg_data *msg)
4752{
4753 int res = 0;
4754 const char *body = ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_BODY);
4755 const char *content_type = ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_CONTENT_TYPE);
4756
4757 ast_channel_lock(chan);
4758 /* Stop if we're a zombie or need a soft hangup */
4760 ast_channel_unlock(chan);
4761 return -1;
4762 }
4763
4764 CHECK_BLOCKING(chan);
4765 if (ast_channel_tech(chan)->write_text
4766 && (ast_strlen_zero(content_type) || ast_begins_with(content_type, "text/"))
4768 struct ast_frame f;
4769 /* T.140 payload does not include the null byte terminator */
4770 size_t body_len = strlen(body);
4771
4772 /* Process as T.140 text (moved here from ast_sendtext() */
4773 memset(&f, 0, sizeof(f));
4774 f.src = "DIALPLAN";
4777 f.datalen = body_len;
4779 f.data.ptr = ast_strdup(body);
4780 if (f.data.ptr) {
4781 res = ast_channel_tech(chan)->write_text(chan, &f);
4782 } else {
4783 res = -1;
4784 }
4785 ast_frfree(&f);
4786 } else if ((ast_channel_tech(chan)->properties & AST_CHAN_TP_SEND_TEXT_DATA)
4787 && ast_channel_tech(chan)->send_text_data) {
4788 /* Send enhanced message to a channel driver that supports it */
4789 ast_debug(1, "Sending TEXT_DATA from '%s' to %s:%s %s\n",
4792 ast_channel_name(chan), body);
4793 res = ast_channel_tech(chan)->send_text_data(chan, msg);
4794 } else if (ast_channel_tech(chan)->send_text
4795 && (ast_strlen_zero(content_type) || ast_begins_with(content_type, "text/"))) {
4796 /* Send the body of an enhanced message to a channel driver that supports only a char str */
4797 ast_debug(1, "Sending TEXT to %s: %s\n", ast_channel_name(chan), body);
4798 res = ast_channel_tech(chan)->send_text(chan, body);
4799 } else {
4800 ast_debug(1, "Channel technology does not support sending content type '%s' on channel '%s'\n",
4801 S_OR(content_type, "text/plain"), ast_channel_name(chan));
4802 res = -1;
4803 }
4805 ast_channel_unlock(chan);
4806 return res;
4807}
4808
4809int ast_sendtext(struct ast_channel *chan, const char *text)
4810{
4811 struct ast_msg_data *msg;
4812 int rc;
4813 struct ast_msg_data_attribute attrs[] =
4814 {
4815 {
4817 .value = (char *)text,
4818 }
4819 };
4820
4821 if (ast_strlen_zero(text)) {
4822 return 0;
4823 }
4824
4826 if (!msg) {
4827 return -1;
4828 }
4829 rc = ast_sendtext_data(chan, msg);
4830 ast_free(msg);
4831
4832 return rc;
4833}
4834
4836{
4837 static const char * const mf_tones[] = {
4838 "1300+1500", /* 0 */
4839 "700+900", /* 1 */
4840 "700+1100", /* 2 */
4841 "900+1100", /* 3 */
4842 "700+1300", /* 4 */
4843 "900+1300", /* 5 */
4844 "1100+1300", /* 6 */
4845 "700+1500", /* 7 */
4846 "900+1500", /* 8 */
4847 "1100+1500", /* 9 */
4848 "1100+1700", /* * (KP) */
4849 "1500+1700", /* # (ST) */
4850 "900+1700", /* A (STP) */
4851 "1300+1700", /* B (ST2P) */
4852 "700+1700" /* C (ST3P) */
4853 };
4854
4855 if (digit >= '0' && digit <='9') {
4856 ast_playtones_start(chan, 0, mf_tones[digit-'0'], 0);
4857 } else if (digit == '*') {
4858 ast_playtones_start(chan, 0, mf_tones[10], 0);
4859 } else if (digit == '#') {
4860 ast_playtones_start(chan, 0, mf_tones[11], 0);
4861 } else if (digit == 'A') {
4862 ast_playtones_start(chan, 0, mf_tones[12], 0);
4863 } else if (digit == 'B') {
4864 ast_playtones_start(chan, 0, mf_tones[13], 0);
4865 } else if (digit == 'C') {
4866 ast_playtones_start(chan, 0, mf_tones[14], 0);
4867 } else {
4868 /* not handled */
4869 ast_log(LOG_WARNING, "Unable to generate MF tone '%c' for '%s'\n", digit, ast_channel_name(chan));
4870 }
4871 return 0;
4872}
4873
4875{
4876 /* Device does not support DTMF tones, lets fake
4877 * it by doing our own generation. */
4878 static const char * const dtmf_tones[] = {
4879 "941+1336", /* 0 */
4880 "697+1209", /* 1 */
4881 "697+1336", /* 2 */
4882 "697+1477", /* 3 */
4883 "770+1209", /* 4 */
4884 "770+1336", /* 5 */
4885 "770+1477", /* 6 */
4886 "852+1209", /* 7 */
4887 "852+1336", /* 8 */
4888 "852+1477", /* 9 */
4889 "697+1633", /* A */
4890 "770+1633", /* B */
4891 "852+1633", /* C */
4892 "941+1633", /* D */
4893 "941+1209", /* * */
4894 "941+1477" /* # */
4895 };
4896
4897 if (!ast_channel_tech(chan)->send_digit_begin)
4898 return 0;
4899
4900 ast_channel_lock(chan);
4903 ast_channel_unlock(chan);
4904
4905 if (!ast_channel_tech(chan)->send_digit_begin(chan, digit))
4906 return 0;
4907
4908 if (digit >= '0' && digit <='9')
4909 ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0);
4910 else if (digit >= 'A' && digit <= 'D')
4911 ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0);
4912 else if (digit == '*')
4913 ast_playtones_start(chan, 0, dtmf_tones[14], 0);
4914 else if (digit == '#')
4915 ast_playtones_start(chan, 0, dtmf_tones[15], 0);
4916 else {
4917 /* not handled */
4918 ast_debug(1, "Unable to generate DTMF tone '%c' for '%s'\n", digit, ast_channel_name(chan));
4919 }
4920
4921 return 0;
4922}
4923
4924int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration)
4925{
4926 int res = -1;
4927
4928 if (ast_channel_tech(chan)->send_digit_end)
4929 res = ast_channel_tech(chan)->send_digit_end(chan, digit, duration);
4930
4931 ast_channel_lock(chan);
4934 }
4935 ast_channel_unlock(chan);
4936
4937 if (res && ast_channel_generator(chan))
4938 ast_playtones_stop(chan);
4939
4940 return 0;
4941}
4942
4944{
4945 if (ast_channel_generator(chan)) {
4946 ast_playtones_stop(chan);
4947 return 0;
4948 }
4949 return -1;
4950}
4951
4952int ast_senddigit_mf(struct ast_channel *chan, char digit, unsigned int duration,
4953 unsigned int durationkp, unsigned int durationst, int is_external)
4954{
4955 if (duration < DEFAULT_EMULATE_MF_DURATION) {
4956 duration = DEFAULT_EMULATE_MF_DURATION;
4957 }
4958 if (ast_channel_tech(chan)->send_digit_begin) {
4959 if (digit == '*') {
4960 duration = durationkp;
4961 } else if (digit == '#' || digit == 'A' || digit == 'B' || digit == 'C') {
4962 duration = durationst;
4963 }
4965 if (is_external) {
4966 usleep(duration * 1000);
4967 } else {
4968 ast_safe_sleep(chan, duration);
4969 }
4970 }
4971 return ast_senddigit_mf_end(chan);
4972}
4973
4974int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
4975{
4976 if (duration < AST_DEFAULT_EMULATE_DTMF_DURATION) {
4978 }
4979 if (ast_channel_tech(chan)->send_digit_begin) {
4981 ast_safe_sleep(chan, duration);
4982 }
4983
4984 return ast_senddigit_end(chan, digit, duration);
4985}
4986
4987int ast_senddigit_external(struct ast_channel *chan, char digit, unsigned int duration)
4988{
4989 if (duration < AST_DEFAULT_EMULATE_DTMF_DURATION) {
4991 }
4992 if (ast_channel_tech(chan)->send_digit_begin) {
4994 usleep(duration * 1000);
4995 }
4996
4997 return ast_senddigit_end(chan, digit, duration);
4998}
4999
5000int ast_prod(struct ast_channel *chan)
5001{
5002 struct ast_frame a = { AST_FRAME_VOICE };
5003 char nothing[128];
5004
5005 /* Send an empty audio frame to get things moving */
5006 if (ast_channel_state(chan) != AST_STATE_UP) {
5007 ast_debug(3, "Prodding channel '%s'\n", ast_channel_name(chan));
5008 a.subclass.format = ast_channel_rawwriteformat(chan);
5009 a.data.ptr = nothing + AST_FRIENDLY_OFFSET;
5010 a.src = "ast_prod"; /* this better match check in ast_write */
5011 if (ast_write(chan, &a))
5012 ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", ast_channel_name(chan));
5013 }
5014 return 0;
5015}
5016
5017int ast_write_video(struct ast_channel *chan, struct ast_frame *fr)
5018{
5019 int res;
5020 if (!ast_channel_tech(chan)->write_video)
5021 return 0;
5022 res = ast_write(chan, fr);
5023 if (!res)
5024 res = 1;
5025 return res;
5026}
5027
5028struct plc_ds {
5029 /* A buffer in which to store SLIN PLC
5030 * samples generated by the generic PLC
5031 * functionality in plc.c
5032 */
5034 /* The current number of samples in the
5035 * samples_buf
5036 */
5039};
5040
5041static void plc_ds_destroy(void *data)
5042{
5043 struct plc_ds *plc = data;
5044 ast_free(plc->samples_buf);
5045 ast_free(plc);
5046}
5047
5048static const struct ast_datastore_info plc_ds_info = {
5049 .type = "plc",
5050 .destroy = plc_ds_destroy,
5051};
5052
5053static void adjust_frame_for_plc(struct ast_channel *chan, struct ast_frame *frame, struct ast_datastore *datastore)
5054{
5055 int num_new_samples = frame->samples;
5056 struct plc_ds *plc = datastore->data;
5057
5058 /* As a general note, let me explain the somewhat odd calculations used when taking
5059 * the frame offset into account here. According to documentation in frame.h, the frame's
5060 * offset field indicates the number of bytes that the audio is offset. The plc->samples_buf
5061 * is not an array of bytes, but rather an array of 16-bit integers since it holds SLIN
5062 * samples. So I had two choices to make here with the offset.
5063 *
5064 * 1. Make the offset AST_FRIENDLY_OFFSET bytes. The main downside for this is that
5065 * I can't just add AST_FRIENDLY_OFFSET to the plc->samples_buf and have the pointer
5066 * arithmetic come out right. I would have to do some odd casting or division for this to
5067 * work as I wanted.
5068 * 2. Make the offset AST_FRIENDLY_OFFSET * 2 bytes. This allows the pointer arithmetic
5069 * to work out better with the plc->samples_buf. The downside here is that the buffer's
5070 * allocation contains an extra 64 bytes of unused space.
5071 *
5072 * I decided to go with option 2. This is why in the calloc statement and the statement that
5073 * sets the frame's offset, AST_FRIENDLY_OFFSET is multiplied by 2.
5074 */
5075
5076 /* If this audio frame has no samples to fill in, ignore it */
5077 if (!num_new_samples) {
5078 return;
5079 }
5080
5081 /* First, we need to be sure that our buffer is large enough to accomodate
5082 * the samples we need to fill in. This will likely only occur on the first
5083 * frame we write.
5084 */
5085 if (plc->num_samples < num_new_samples) {
5086 ast_free(plc->samples_buf);
5087 plc->samples_buf = ast_calloc(1, (num_new_samples * sizeof(*plc->samples_buf)) + (AST_FRIENDLY_OFFSET * 2));
5088 if (!plc->samples_buf) {
5089 ast_channel_datastore_remove(chan, datastore);
5090 ast_datastore_free(datastore);
5091 return;
5092 }
5093 plc->num_samples = num_new_samples;
5094 }
5095
5096 if (frame->datalen == 0) {
5098 frame->data.ptr = plc->samples_buf + AST_FRIENDLY_OFFSET;
5099 frame->datalen = num_new_samples * 2;
5100 frame->offset = AST_FRIENDLY_OFFSET * 2;
5101 } else {
5102 plc_rx(&plc->plc_state, frame->data.ptr, frame->samples);
5103 }
5104}
5105
5106static void apply_plc(struct ast_channel *chan, struct ast_frame *frame)
5107{
5108 struct ast_datastore *datastore;
5109 struct plc_ds *plc;
5110
5111 datastore = ast_channel_datastore_find(chan, &plc_ds_info, NULL);
5112 if (datastore) {
5113 plc = datastore->data;
5114 adjust_frame_for_plc(chan, frame, datastore);
5115 return;
5116 }
5117
5118 datastore = ast_datastore_alloc(&plc_ds_info, NULL);
5119 if (!datastore) {
5120 return;
5121 }
5122 plc = ast_calloc(1, sizeof(*plc));
5123 if (!plc) {
5124 ast_datastore_free(datastore);
5125 return;
5126 }
5127 datastore->data = plc;
5128 ast_channel_datastore_add(chan, datastore);
5129 adjust_frame_for_plc(chan, frame, datastore);
5130}
5131
5132static int tech_write(struct ast_channel *chan, struct ast_stream *stream,
5133 struct ast_stream *default_stream, struct ast_frame *frame)
5134{
5135 if (ast_channel_tech(chan)->write_stream) {
5136 return stream ? ast_channel_tech(chan)->write_stream(
5137 chan, ast_stream_get_position(stream), frame) : 0;
5138 }
5139
5140 return ((stream == default_stream) && ast_channel_tech(chan)->write) ?
5141 ast_channel_tech(chan)->write(chan, frame) : 0;
5142}
5143
5144int ast_write(struct ast_channel *chan, struct ast_frame *fr)
5145{
5146 return ast_write_stream(chan, -1, fr);
5147}
5148
5149int ast_write_stream(struct ast_channel *chan, int stream_num, struct ast_frame *fr)
5150{
5151 struct ast_stream *stream = NULL, *default_stream = NULL;
5152 int res = -1;
5153 struct ast_frame *f = NULL;
5154 int count = 0;
5155 int hooked = 0;
5156
5157 /*Deadlock avoidance*/
5158 while(ast_channel_trylock(chan)) {
5159 /*cannot goto done since the channel is not locked*/
5160 if(count++ > 10) {
5161 ast_debug(1, "Deadlock avoided for write to channel '%s'\n", ast_channel_name(chan));
5162 return 0;
5163 }
5164 usleep(1);
5165 }
5166
5167 /* Stop if we're a zombie or need a soft hangup */
5169 goto done;
5170 }
5171
5172 if (stream_num >= 0) {
5173 /* If we were told to write to an explicit stream then allow this frame through, no matter
5174 * if the type is expected or not (a framehook could change)
5175 */
5177 goto done;
5178 }
5180 default_stream = ast_channel_get_default_stream(chan, ast_stream_get_type(stream));
5181 } else if (fr->frametype == AST_FRAME_VOICE || fr->frametype == AST_FRAME_VIDEO || fr->frametype == AST_FRAME_MODEM) {
5182 /* If we haven't been told of a stream then we need to figure out which once we need */
5184
5185 /* Some frame types have a fixed media type */
5186 if (fr->frametype == AST_FRAME_VOICE || fr->frametype == AST_FRAME_VIDEO) {
5188 } else if (fr->frametype == AST_FRAME_MODEM) {
5190 }
5191
5192 /* No stream was specified, so use the default one */
5193 stream = default_stream = ast_channel_get_default_stream(chan, type);
5194 }
5195
5196 /* Perform the framehook write event here. After the frame enters the framehook list
5197 * there is no telling what will happen, how awesome is that!!! */
5198 if ((stream == default_stream) && !(fr = ast_framehook_list_write_event(ast_channel_framehooks(chan), fr))) {
5199 res = 0;
5200 goto done;
5201 }
5202
5203 if (ast_channel_generatordata(chan) && (fr->frametype != AST_FRAME_RTCP) && (!fr->src || strcasecmp(fr->src, "ast_prod"))) {
5206 } else {
5207 if (fr->frametype == AST_FRAME_DTMF_END) {
5208 /* There is a generator running while we're in the middle of a digit.
5209 * It's probably inband DTMF, so go ahead and pass it so it can
5210 * stop the generator */
5211 ast_channel_unlock(chan);
5212 res = ast_senddigit_end(chan, fr->subclass.integer, fr->len);
5213 ast_channel_lock(chan);
5214 } else if (fr->frametype == AST_FRAME_CONTROL
5216 /*
5217 * This is a side case where Echo is basically being called
5218 * and the person put themselves on hold and took themselves
5219 * off hold.
5220 */
5222 fr->datalen);
5223 }
5224 res = 0; /* XXX explain, why 0 ? */
5225 goto done;
5226 }
5227 }
5228 /* High bit prints debugging */
5229 if (ast_channel_fout(chan) & DEBUGCHAN_FLAG)
5230 ast_frame_dump(ast_channel_name(chan), fr, ">>");
5231 switch (fr->frametype) {
5232 case AST_FRAME_CONTROL:
5234 res = 0;
5235 break;
5237 if (ast_channel_audiohooks(chan)) {
5238 struct ast_frame *old_frame = fr;
5240 if (old_frame != fr)
5241 f = fr;
5242 }
5244 ast_channel_unlock(chan);
5245 res = ast_senddigit_begin(chan, fr->subclass.integer);
5246 ast_channel_lock(chan);
5247 break;
5248 case AST_FRAME_DTMF_END:
5249 if (ast_channel_audiohooks(chan)) {
5250 struct ast_frame *new_frame = fr;
5251
5253 if (new_frame != fr) {
5254 ast_frfree(new_frame);
5255 }
5256 }
5258 ast_channel_unlock(chan);
5259 res = ast_senddigit_end(chan, fr->subclass.integer, fr->len);
5260 ast_channel_lock(chan);
5261 break;
5262 case AST_FRAME_TEXT:
5263 CHECK_BLOCKING(chan);
5265 res = (ast_channel_tech(chan)->write_text == NULL) ? 0 :
5266 ast_channel_tech(chan)->write_text(chan, fr);
5267 } else {
5268 res = (ast_channel_tech(chan)->send_text == NULL) ? 0 :
5269 ast_channel_tech(chan)->send_text(chan, (char *) fr->data.ptr);
5270 }
5272 break;
5273 case AST_FRAME_HTML:
5274 CHECK_BLOCKING(chan);
5275 res = (ast_channel_tech(chan)->send_html == NULL) ? 0 :
5276 ast_channel_tech(chan)->send_html(chan, fr->subclass.integer, (char *) fr->data.ptr, fr->datalen);
5278 break;
5279 case AST_FRAME_VIDEO:
5280 /* XXX Handle translation of video codecs one day XXX */
5281 CHECK_BLOCKING(chan);
5282 if (ast_channel_tech(chan)->write_stream) {
5283 if (stream) {
5284 res = ast_channel_tech(chan)->write_stream(chan, ast_stream_get_position(stream), fr);
5285 } else {
5286 res = 0;
5287 }
5288 } else if ((stream == default_stream) && ast_channel_tech(chan)->write_video) {
5289 res = ast_channel_tech(chan)->write_video(chan, fr);
5290 } else {
5291 res = 0;
5292 }
5294 break;
5295 case AST_FRAME_MODEM:
5296 CHECK_BLOCKING(chan);
5297 res = tech_write(chan, stream, default_stream, fr);
5299 break;
5300 case AST_FRAME_VOICE:
5302 apply_plc(chan, fr);
5303 }
5304
5305 f = fr;
5306
5307 /*
5308 * Send frame to audiohooks if present, if frametype is linear (else, later as per
5309 * previous behavior)
5310 */
5311 if ((stream == default_stream) && ast_channel_audiohooks(chan)) {
5313 hooked = 1;
5315 }
5316 }
5317
5318 /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */
5319 if ((stream == default_stream) && ast_format_cmp(fr->subclass.format, ast_channel_rawwriteformat(chan)) != AST_FORMAT_CMP_EQUAL) {
5321 struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5322
5323 /*
5324 * We are not setup to write this frame. Things may have changed
5325 * on the peer side of the world and we try to adjust the format to
5326 * make it compatible again. However, bad things can happen if we
5327 * cannot setup a new translation path. Problems range from no
5328 * audio, one-way audio, to garbled audio. The best we can do is
5329 * request the call to hangup since we could not make it compatible.
5330 *
5331 * Being continuously spammed by this message likely indicates a
5332 * problem with the peer because it cannot make up its mind about
5333 * which format to use.
5334 */
5335 ast_debug(1, "Channel %s changing write format from %s to %s, native formats %s\n",
5336 ast_channel_name(chan),
5340 if (ast_set_write_format(chan, fr->subclass.format)) {
5341 /* Could not handle the new write format. Induce a hangup. */
5342 break;
5343 }
5344 }
5345
5346 if (ast_channel_writetrans(chan)) {
5347 struct ast_frame *trans_frame = ast_translate(ast_channel_writetrans(chan), f, 0);
5348 if (trans_frame != f && f != fr) {
5349 /*
5350 * If translate gives us a new frame and so did the audio
5351 * hook then we need to free the one from the audio hook.
5352 */
5353 ast_frfree(f);
5354 }
5355 f = trans_frame;
5356 }
5357 }
5358
5359 if (!f) {
5360 res = 0;
5361 break;
5362 }
5363
5364 if ((stream == default_stream) && ast_channel_audiohooks(chan) && !hooked) {
5365 struct ast_frame *prev = NULL, *new_frame, *cur, *dup;
5366 int freeoldlist = 0;
5367
5368 if (f != fr) {
5369 freeoldlist = 1;
5370 }
5371
5372 /* Since ast_audiohook_write may return a new frame, and the cur frame is
5373 * an item in a list of frames, create a new list adding each cur frame back to it
5374 * regardless if the cur frame changes or not. */
5375 for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
5377
5378 /* if this frame is different than cur, preserve the end of the list,
5379 * free the old frames, and set cur to be the new frame */
5380 if (new_frame != cur) {
5381
5382 /* doing an ast_frisolate here seems silly, but we are not guaranteed the new_frame
5383 * isn't part of local storage, meaning if ast_audiohook_write is called multiple
5384 * times it may override the previous frame we got from it unless we dup it */
5385 if ((dup = ast_frisolate(new_frame))) {
5387 if (freeoldlist) {
5389 ast_frfree(cur);
5390 }
5391 if (new_frame != dup) {
5392 ast_frfree(new_frame);
5393 }
5394 cur = dup;
5395 }
5396 }
5397
5398 /* now, regardless if cur is new or not, add it to the new list,
5399 * if the new list has not started, cur will become the first item. */
5400 if (prev) {
5401 AST_LIST_NEXT(prev, frame_list) = cur;
5402 } else {
5403 f = cur; /* set f to be the beginning of our new list */
5404 }
5405 prev = cur;
5406 }
5407 }
5408
5409 /* the translator on chan->writetrans may have returned multiple frames
5410 from the single frame we passed in; if so, feed each one of them to the
5411 channel, freeing each one after it has been written */
5412 CHECK_BLOCKING(chan);
5413 if ((f != fr) && AST_LIST_NEXT(f, frame_list)) {
5414 struct ast_frame *cur, *next = NULL;
5415 unsigned int skip = 0;
5416
5417 cur = f;
5418 while (cur) {
5421 if (!skip) {
5422 res = tech_write(chan, stream, default_stream, cur);
5423 if (res < 0) {
5425 skip = 1;
5426 } else if (next) {
5427 /* don't do this for the last frame in the list,
5428 as the code outside the loop will do it once
5429 */
5431 }
5432 }
5433 ast_frfree(cur);
5434 cur = next;
5435 }
5436
5437 /* reset f so the code below doesn't attempt to free it */
5438 f = NULL;
5439 } else {
5440 res = tech_write(chan, stream, default_stream, f);
5441 }
5443 break;
5444 case AST_FRAME_NULL:
5445 case AST_FRAME_IAX:
5446 /* Ignore these */
5447 res = 0;
5448 break;
5449 case AST_FRAME_RTCP:
5450 /* RTCP information is on a per-stream basis and only available on multistream capable channels */
5451 CHECK_BLOCKING(chan);
5452 if (ast_channel_tech(chan)->write_stream && stream) {
5453 res = ast_channel_tech(chan)->write_stream(chan, ast_stream_get_position(stream), fr);
5454 } else {
5455 res = 0;
5456 }
5458 break;
5459 default:
5460 /* At this point, fr is the incoming frame and f is NULL. Channels do
5461 * not expect to get NULL as a frame pointer and will segfault. Hence,
5462 * we output the original frame passed in. */
5463 CHECK_BLOCKING(chan);
5464 res = ast_channel_tech(chan)->write(chan, fr);
5466 break;
5467 }
5468
5469 if (f && f != fr)
5470 ast_frfree(f);
5471
5472 /* Consider a write failure to force a soft hangup */
5473 if (res < 0) {
5475 } else {
5477 }
5478done:
5480 /* The list gets recreated if audiohooks are added again later */
5483 }
5484 ast_channel_unlock(chan);
5485 return res;
5486}
5487
5488int ast_set_read_format_path(struct ast_channel *chan, struct ast_format *raw_format, struct ast_format *core_format)
5489{
5490 struct ast_trans_pvt *trans_old;
5491 struct ast_trans_pvt *trans_new;
5492
5495 /* Nothing to setup */
5496 return 0;
5497 }
5498
5499 ast_debug(1, "Channel %s setting read format path: %s -> %s\n",
5500 ast_channel_name(chan),
5501 ast_format_get_name(raw_format),
5502 ast_format_get_name(core_format));
5503
5504 /* Setup new translation path. */
5505 if (ast_format_cmp(raw_format, core_format) != AST_FORMAT_CMP_EQUAL) {
5506 trans_new = ast_translator_build_path(core_format, raw_format);
5507 if (!trans_new) {
5508 return -1;
5509 }
5510 } else {
5511 /* No translation needed. */
5512 trans_new = NULL;
5513 }
5514 trans_old = ast_channel_readtrans(chan);
5515 if (trans_old) {
5516 ast_translator_free_path(trans_old);
5517 }
5518 ast_channel_readtrans_set(chan, trans_new);
5519 ast_channel_set_rawreadformat(chan, raw_format);
5520 ast_channel_set_readformat(chan, core_format);
5521 return 0;
5522}
5523
5524int ast_set_write_format_path(struct ast_channel *chan, struct ast_format *core_format, struct ast_format *raw_format)
5525{
5526 struct ast_trans_pvt *trans_old;
5527 struct ast_trans_pvt *trans_new;
5528
5531 /* Nothing to setup */
5532 return 0;
5533 }
5534
5535 ast_debug(1, "Channel %s setting write format path: %s -> %s\n",
5536 ast_channel_name(chan),
5537 ast_format_get_name(core_format),
5538 ast_format_get_name(raw_format));
5539
5540 /* Setup new translation path. */
5541 if (ast_format_cmp(raw_format, core_format) != AST_FORMAT_CMP_EQUAL) {
5542 trans_new = ast_translator_build_path(raw_format, core_format);
5543 if (!trans_new) {
5544 return -1;
5545 }
5546 } else {
5547 /* No translation needed. */
5548 trans_new = NULL;
5549 }
5550 trans_old = ast_channel_writetrans(chan);
5551 if (trans_old) {
5552 ast_translator_free_path(trans_old);
5553 }
5554 ast_channel_writetrans_set(chan, trans_new);
5555 ast_channel_set_rawwriteformat(chan, raw_format);
5556 ast_channel_set_writeformat(chan, core_format);
5557 return 0;
5558}
5559
5561 const char *direction;
5562 struct ast_trans_pvt *(*get_trans)(const struct ast_channel *chan);
5563 void (*set_trans)(struct ast_channel *chan, struct ast_trans_pvt *value);
5564 struct ast_format *(*get_format)(struct ast_channel *chan);
5565 void (*set_format)(struct ast_channel *chan, struct ast_format *format);
5566 struct ast_format *(*get_rawformat)(struct ast_channel *chan);
5567 void (*set_rawformat)(struct ast_channel *chan, struct ast_format *format);
5569};
5570
5572 .direction = "read",
5573 .get_trans = ast_channel_readtrans,
5574 .set_trans = ast_channel_readtrans_set,
5575 .get_format = ast_channel_readformat,
5576 .set_format = ast_channel_set_readformat,
5577 .get_rawformat = ast_channel_rawreadformat,
5578 .set_rawformat = ast_channel_set_rawreadformat,
5579 .setoption = AST_OPTION_FORMAT_READ,
5580};
5581
5583 .direction = "write",
5584 .get_trans = ast_channel_writetrans,
5585 .set_trans = ast_channel_writetrans_set,
5586 .get_format = ast_channel_writeformat,
5587 .set_format = ast_channel_set_writeformat,
5588 .get_rawformat = ast_channel_rawwriteformat,
5589 .set_rawformat = ast_channel_set_rawwriteformat,
5590 .setoption = AST_OPTION_FORMAT_WRITE,
5591};
5592
5593static int set_format(struct ast_channel *chan, struct ast_format_cap *cap_set, const int direction, int interleaved_stereo)
5594{
5595 struct ast_trans_pvt *trans_pvt;
5596 struct ast_format_cap *cap_native;
5597 const struct set_format_access *access;
5598 struct ast_format *rawformat;
5599 struct ast_format *format;
5600 RAII_VAR(struct ast_format *, best_set_fmt, NULL, ao2_cleanup);
5601 RAII_VAR(struct ast_format *, best_native_fmt, NULL, ao2_cleanup);
5602 int res;
5603
5604 if (!direction) {
5605 /* reading */
5606 access = &set_format_access_read;
5607 } else {
5608 /* writing */
5609 access = &set_format_access_write;
5610 }
5611
5613 if (!best_set_fmt) {
5614 /*
5615 * Not setting any audio formats?
5616 * Assume a call without any sounds (video, text)
5617 */
5618 return 0;
5619 }
5620
5621 /* See if the underlying channel driver is capable of performing transcoding for us */
5622 res = ast_channel_setoption(chan, access->setoption,
5623 &best_set_fmt, sizeof(best_set_fmt), 0);
5624 if (!res) {
5625 ast_debug(1, "Channel driver natively set channel %s to %s format %s\n",
5626 ast_channel_name(chan), access->direction, ast_format_get_name(best_set_fmt));
5627
5628 ast_channel_lock(chan);
5630 if (!cap_native
5631 || ast_format_cap_append(cap_native, best_set_fmt, 0)) {
5632 ast_channel_unlock(chan);
5633 ao2_cleanup(cap_native);
5634 return -1;
5635 }
5636 ast_channel_nativeformats_set(chan, cap_native);
5637 ao2_cleanup(cap_native);
5638 access->set_format(chan, best_set_fmt);
5639 access->set_rawformat(chan, best_set_fmt);
5640
5641 trans_pvt = access->get_trans(chan);
5642 if (trans_pvt) {
5643 ast_translator_free_path(trans_pvt);
5644 access->set_trans(chan, NULL);
5645 }
5646 ast_channel_unlock(chan);
5647
5648 /* If there is a generator on the channel, it needs to know about this
5649 * change if it is the write format. */
5650 if (direction && ast_channel_generatordata(chan)) {
5652 }
5653
5654 return 0;
5655 }
5656
5657 ast_channel_lock(chan);
5658
5659 format = access->get_format(chan);
5660 rawformat = access->get_rawformat(chan);
5661 ast_assert(format != NULL);
5662 ast_assert(rawformat != NULL);
5663
5664 cap_native = ast_channel_nativeformats(chan);
5665 if (ast_format_cap_empty(cap_native)) {
5666 ast_channel_unlock(chan);
5667 ast_log(LOG_ERROR, "Unable to set format because channel %s supports no formats\n",
5668 ast_channel_name(chan));
5669 return -1;
5670 }
5671
5672 /* Find a translation path from the native format to one of the desired formats */
5673 if (!direction) {
5674 /* reading */
5675 res = ast_translator_best_choice(cap_set, cap_native, &best_set_fmt, &best_native_fmt);
5676 } else {
5677 /* writing */
5678 res = ast_translator_best_choice(cap_native, cap_set, &best_native_fmt, &best_set_fmt);
5679 }
5680 if (res < 0) {
5681 struct ast_str *codec_native = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5682 struct ast_str *codec_set = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5683
5684 ast_format_cap_get_names(cap_native, &codec_native);
5685 ast_channel_unlock(chan);
5686 ast_format_cap_get_names(cap_set, &codec_set);
5687
5688 ast_log(LOG_WARNING, "Unable to find a codec translation path: %s -> %s\n",
5689 ast_str_buffer(direction ? codec_set : codec_native),
5690 ast_str_buffer(direction ? codec_native : codec_set));
5691 return -1;
5692 }
5693
5694 /* Now we have a good choice for both. */
5695 trans_pvt = access->get_trans(chan);
5696 if ((ast_format_cmp(rawformat, best_native_fmt) != AST_FORMAT_CMP_NOT_EQUAL) &&
5697 (ast_format_cmp(format, best_set_fmt) != AST_FORMAT_CMP_NOT_EQUAL) &&
5698 ((ast_format_cmp(rawformat, format) != AST_FORMAT_CMP_NOT_EQUAL) || access->get_trans(chan))) {
5699 /* the channel is already in these formats, so nothing to do, unless the interleaved format is not set correctly */
5700 if (trans_pvt != NULL) {
5701 if (trans_pvt->interleaved_stereo == interleaved_stereo) {
5702 ast_channel_unlock(chan);
5703 return 0;
5704 }
5705 }
5706 }
5707
5708 /* Free any translation we have right now */
5709 if (trans_pvt) {
5710 ast_translator_free_path(trans_pvt);
5711 access->set_trans(chan, NULL);
5712 }
5713
5714 /* Build a translation path from the raw format to the desired format */
5715 if (ast_format_cmp(best_set_fmt, best_native_fmt) != AST_FORMAT_CMP_NOT_EQUAL) {
5716 /*
5717 * If we were able to swap the native format to the format that
5718 * has been requested, then there is no need to try to build
5719 * a translation path.
5720 */
5721 res = 0;
5722 } else {
5723 if (!direction) {
5724 /* reading */
5725 trans_pvt = ast_translator_build_path(best_set_fmt, best_native_fmt);
5726 if (trans_pvt) {
5727 trans_pvt->interleaved_stereo = 0;
5728 }
5729 } else {
5730 /* writing */
5731 trans_pvt = ast_translator_build_path(best_native_fmt, best_set_fmt);
5732 if (trans_pvt) {
5733 trans_pvt->interleaved_stereo = interleaved_stereo;
5734 }
5735 }
5736 access->set_trans(chan, trans_pvt);
5737 res = trans_pvt ? 0 : -1;
5738 }
5739
5740 if (!res) {
5741 access->set_format(chan, best_set_fmt);
5742 access->set_rawformat(chan, best_native_fmt);
5743
5744 ast_debug(1, "Channel %s setting %s format path: %s -> %s\n",
5745 ast_channel_name(chan),
5746 access->direction,
5747 ast_format_get_name(direction ? best_set_fmt : best_native_fmt),
5748 ast_format_get_name(direction ? best_native_fmt : best_set_fmt));
5749 }
5750
5751 ast_channel_unlock(chan);
5752
5753 /* If there is a generator on the channel, it needs to know about this
5754 * change if it is the write format. */
5755 if (direction && ast_channel_generatordata(chan)) {
5757 }
5758
5759 return res;
5760}
5761
5762int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
5763{
5765 int res;
5766
5767 ast_assert(format != NULL);
5768
5769 if (!cap) {
5770 return -1;
5771 }
5772 ast_format_cap_append(cap, format, 0);
5773
5774 res = set_format(chan, cap, 0, 0);
5775
5776 ao2_cleanup(cap);
5777 return res;
5778}
5779
5781{
5782 return set_format(chan, cap, 0, 0);
5783}
5784
5786{
5788 int res;
5789
5790 ast_assert(format != NULL);
5791
5792 if (!cap) {
5793 return -1;
5794 }
5795 ast_format_cap_append(cap, format, 0);
5796
5797 res = set_format(chan, cap, 1, 1);
5798
5799 ao2_cleanup(cap);
5800 return res;
5801}
5802
5803int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
5804{
5806 int res;
5807
5808 ast_assert(format != NULL);
5809
5810 if (!cap) {
5811 return -1;
5812 }
5813 ast_format_cap_append(cap, format, 0);
5814
5815 res = set_format(chan, cap, 1, 0);
5816
5817 ao2_cleanup(cap);
5818 return res;
5819}
5820
5822{
5823 return set_format(chan, cap, 1, 0);
5824}
5825
5826const char *ast_channel_reason2str(int reason)
5827{
5828 switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */
5829 {
5830 case 0:
5831 return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)";
5832 case AST_CONTROL_HANGUP:
5833 return "Hangup";
5834 case AST_CONTROL_RING:
5835 return "Local Ring";
5837 return "Remote end Ringing";
5838 case AST_CONTROL_ANSWER:
5839 return "Remote end has Answered";
5840 case AST_CONTROL_BUSY:
5841 return "Remote end is Busy";
5843 return "Congestion (circuits busy)";
5844 default:
5845 return "Unknown Reason!!";
5846 }
5847}
5848
5849static void handle_cause(int cause, int *outstate)
5850{
5851 if (outstate) {
5852 /* compute error and return */
5853 if (cause == AST_CAUSE_BUSY)
5854 *outstate = AST_CONTROL_BUSY;
5855 else if (cause == AST_CAUSE_CONGESTION)
5856 *outstate = AST_CONTROL_CONGESTION;
5857 else
5858 *outstate = 0;
5859 }
5860}
5861
5862/*!
5863 * \internal
5864 * \brief Helper function to inherit info from parent channel.
5865 *
5866 * \param new_chan Channel inheriting information.
5867 * \param parent Channel new_chan inherits information.
5868 * \param orig Channel being replaced by the call forward channel.
5869 */
5870static void call_forward_inherit(struct ast_channel *new_chan, struct ast_channel *parent, struct ast_channel *orig)
5871{
5873 struct ast_party_redirecting redirecting;
5874
5875 /*
5876 * The parent is not a ZOMBIE or hungup so update it with the
5877 * original channel's redirecting information.
5878 */
5879 ast_party_redirecting_init(&redirecting);
5883 if (ast_channel_redirecting_sub(orig, parent, &redirecting, 0)) {
5884 ast_channel_update_redirecting(parent, &redirecting, NULL);
5885 }
5886 ast_party_redirecting_free(&redirecting);
5887 }
5888
5889 /* Safely inherit variables and datastores from the parent channel. */
5890 ast_channel_lock_both(parent, new_chan);
5891 ast_channel_inherit_variables(parent, new_chan);
5892 ast_channel_datastore_inherit(parent, new_chan);
5894 ast_channel_unlock(new_chan);
5895 ast_channel_unlock(parent);
5896}
5897
5898struct ast_channel *ast_call_forward(struct ast_channel *caller, struct ast_channel *orig, int *timeout, struct ast_format_cap *cap, struct outgoing_helper *oh, int *outstate)
5899{
5900 char tmpchan[256];
5901 char forwarder[AST_CHANNEL_NAME];
5902 struct ast_channel *new_chan = NULL;
5903 char *data, *type;
5904 int cause = 0;
5905 int res;
5906
5907 /* gather data and request the new forward channel */
5908 ast_copy_string(tmpchan, ast_channel_call_forward(orig), sizeof(tmpchan));
5909 ast_copy_string(forwarder, ast_channel_name(orig), sizeof(forwarder));
5910 if ((data = strchr(tmpchan, '/'))) {
5911 *data++ = '\0';
5912 type = tmpchan;
5913 } else {
5914 const char *forward_context;
5915 ast_channel_lock(orig);
5916 forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT");
5917 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(orig), S_OR(forward_context, ast_channel_context(orig)));
5918 ast_channel_unlock(orig);
5919 data = tmpchan;
5920 type = "Local";
5921 }
5922 if (!(new_chan = ast_request(type, cap, NULL, orig, data, &cause))) {
5923 ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause);
5924 handle_cause(cause, outstate);
5925 ast_hangup(orig);
5926 return NULL;
5927 }
5928
5929 /* Copy/inherit important information into new channel */
5930 if (oh) {
5931 if (oh->vars) {
5932 ast_channel_lock(new_chan);
5933 ast_set_variables(new_chan, oh->vars);
5934 ast_channel_unlock(new_chan);
5935 }
5936 if (oh->parent_channel) {
5937 call_forward_inherit(new_chan, oh->parent_channel, orig);
5938 }
5939 if (!ast_strlen_zero(oh->account)) {
5940 ast_channel_lock(new_chan);
5942 ast_channel_accountcode_set(new_chan, oh->account);
5943 ast_channel_peeraccount_set(new_chan, oh->account);
5945 ast_channel_unlock(new_chan);
5946 }
5947 } else if (caller) { /* no outgoing helper so use caller if available */
5948 call_forward_inherit(new_chan, caller, orig);
5949 }
5950
5951 ast_channel_lock_both(orig, new_chan);
5953 pbx_builtin_setvar_helper(new_chan, "FORWARDERNAME", forwarder);
5957 ast_channel_unlock(new_chan);
5958 ast_channel_unlock(orig);
5959
5960 /* call new channel */
5961 res = ast_call(new_chan, data, 0);
5962 if (timeout) {
5963 *timeout = res;
5964 }
5965 if (res) {
5966 ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data);
5967 ast_hangup(orig);
5968 ast_hangup(new_chan);
5969 return NULL;
5970 }
5971 ast_hangup(orig);
5972
5973 return new_chan;
5974}
5975
5976struct ast_channel *__ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int timeout, int *outstate, const char *cid_num, const char *cid_name, struct outgoing_helper *oh)
5977{
5978 int dummy_outstate;
5979 int cause = 0;
5980 struct ast_channel *chan;
5981 int res = 0;
5982 int last_subclass = 0;
5984
5985 if (outstate)
5986 *outstate = 0;
5987 else
5988 outstate = &dummy_outstate; /* make outstate always a valid pointer */
5989
5990 chan = ast_request(type, cap, assignedids, requestor, addr, &cause);
5991 if (!chan) {
5992 ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, addr);
5993 handle_cause(cause, outstate);
5994 return NULL;
5995 }
5996
5997 if (oh) {
5998 if (oh->vars) {
5999 ast_channel_lock(chan);
6000 ast_set_variables(chan, oh->vars);
6001 ast_channel_unlock(chan);
6002 }
6003 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) {
6004 /*
6005 * Use the oh values instead of the function parameters for the
6006 * outgoing CallerID.
6007 */
6008 cid_num = oh->cid_num;
6009 cid_name = oh->cid_name;
6010 }
6011 if (oh->parent_channel) {
6012 /* Safely inherit variables and datastores from the parent channel. */
6018 ast_channel_unlock(chan);
6019 }
6020 if (!ast_strlen_zero(oh->account)) {
6021 ast_channel_lock(chan);
6023 ast_channel_accountcode_set(chan, oh->account);
6024 ast_channel_peeraccount_set(chan, oh->account);
6026 ast_channel_unlock(chan);
6027 }
6028 }
6029
6030 /*
6031 * It seems strange to set the CallerID on an outgoing call leg
6032 * to whom we are calling, but this function's callers are doing
6033 * various Originate methods. This call leg goes to the local
6034 * user. Once the local user answers, the dialplan needs to be
6035 * able to access the CallerID from the CALLERID function as if
6036 * the local user had placed this call.
6037 */
6038 ast_set_callerid(chan, cid_num, cid_name, cid_num);
6039
6040 ast_channel_lock(chan);
6042 ast_channel_unlock(chan);
6044 if (cid_num) {
6045 connected.id.number.valid = 1;
6046 connected.id.number.str = (char *) cid_num;
6048 }
6049 if (cid_name) {
6050 connected.id.name.valid = 1;
6051 connected.id.name.str = (char *) cid_name;
6053 }
6055 if (requestor) {
6056 ast_channel_lock_both(chan, (struct ast_channel *) requestor);
6058 ast_channel_unlock(chan);
6059 ast_channel_unlock((struct ast_channel *) requestor);
6060 }
6061
6062 if (ast_call(chan, addr, 0)) { /* ast_call failed... */
6063 ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, addr);
6064 } else {
6065 struct timeval start = ast_tvnow();
6066 res = 1; /* mark success in case chan->_state is already AST_STATE_UP */
6067 while (timeout && ast_channel_state(chan) != AST_STATE_UP) {
6068 struct ast_frame *f;
6069 int ms = ast_remaining_ms(start, timeout);
6070
6071 res = ast_waitfor(chan, ms);
6072 if (res == 0) { /* timeout, treat it like ringing */
6073 *outstate = AST_CONTROL_RINGING;
6074 break;
6075 }
6076 if (res < 0) /* error or done */
6077 break;
6079 if (!(chan = ast_call_forward(NULL, chan, NULL, cap, oh, outstate))) {
6080 return NULL;
6081 }
6082 continue;
6083 }
6084
6085 f = ast_read(chan);
6086 if (!f) {
6087 *outstate = AST_CONTROL_HANGUP;
6088 res = 0;
6089 break;
6090 }
6091 if (f->frametype == AST_FRAME_CONTROL) {
6092 switch (f->subclass.integer) {
6093 case AST_CONTROL_RINGING: /* record but keep going */
6094 *outstate = f->subclass.integer;
6095 break;
6096
6097 case AST_CONTROL_BUSY:
6098 *outstate = f->subclass.integer;
6099 timeout = 0;
6100 break;
6101
6103 *outstate = AST_CONTROL_CONGESTION;
6104 timeout = 0;
6105 break;
6106
6108 *outstate = f->subclass.integer;
6109 timeout = 0;
6110 break;
6111
6112 case AST_CONTROL_ANSWER:
6113 *outstate = f->subclass.integer;
6114 timeout = 0; /* trick to force exit from the while() */
6115 break;
6116
6119 break;
6120
6122 if (oh && oh->connect_on_early_media) {
6123 *outstate = f->subclass.integer;
6124 timeout = 0; /* trick to force exit from the while() */
6125 break;
6126 }
6127 /* Fallthrough */
6128 /* Ignore these */
6130 case AST_CONTROL_HOLD:
6131 case AST_CONTROL_UNHOLD:
6137 case AST_CONTROL_CC:
6138 case -1: /* Ignore -- just stopping indications */
6139 break;
6140
6141 default:
6142 ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass.integer);
6143 }
6144 last_subclass = f->subclass.integer;
6145 }
6146 ast_frfree(f);
6147 }
6148 }
6149
6150 /* Final fixups */
6151 if (oh) {
6152 if (!ast_strlen_zero(oh->context))
6154 if (!ast_strlen_zero(oh->exten))
6155 ast_channel_exten_set(chan, oh->exten);
6156 if (oh->priority)
6158 }
6159 if (ast_channel_state(chan) == AST_STATE_UP)
6160 *outstate = AST_CONTROL_ANSWER;
6161
6162 if (res <= 0) {
6163 ast_channel_lock(chan);
6164 if (AST_CONTROL_RINGING == last_subclass) {
6166 }
6167 ast_channel_unlock(chan);
6168 ast_hangup(chan);
6169 chan = NULL;
6170 }
6171 return chan;
6172}
6173
6174struct ast_channel *ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int timeout, int *outstate, const char *cidnum, const char *cidname)
6175{
6176 return __ast_request_and_dial(type, cap, assignedids, requestor, addr, timeout, outstate, cidnum, cidname, NULL);
6177}
6178
6179static int set_security_requirements(const struct ast_channel *requestor, struct ast_channel *out)
6180{
6181 int ops[2][2] = {
6184 };
6185 int i;
6186 struct ast_channel *r = (struct ast_channel *) requestor; /* UGLY */
6187 struct ast_datastore *ds;
6188
6189 if (!requestor || !out) {
6190 return 0;
6191 }
6192
6195 struct ast_secure_call_store *encrypt = ds->data;
6196 ops[0][1] = encrypt->signaling;
6197 ops[1][1] = encrypt->media;
6198 } else {
6200 return 0;
6201 }
6203
6204 for (i = 0; i < 2; i++) {
6205 if (ops[i][1]) {
6206 if (ast_channel_setoption(out, ops[i][0], &ops[i][1], sizeof(ops[i][1]), 0)) {
6207 /* We require a security feature, but the channel won't provide it */
6208 return -1;
6209 }
6210 } else {
6211 /* We don't care if we can't clear the option on a channel that doesn't support it */
6212 ast_channel_setoption(out, ops[i][0], &ops[i][1], sizeof(ops[i][1]), 0);
6213 }
6214 }
6215
6216 return 0;
6217}
6218
6219static struct ast_channel *request_channel(const char *type, struct ast_format_cap *request_cap, struct ast_stream_topology *topology,
6220 const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
6221{
6222 struct chanlist *chan;
6223 struct ast_channel *c = NULL;
6224 int res;
6225 int foo;
6226
6227 if (!cause)
6228 cause = &foo;
6229 *cause = AST_CAUSE_NOTDEFINED;
6230
6232 ast_log(LOG_WARNING, "Unable to lock technology backend list\n");
6233 return NULL;
6234 }
6235
6236 AST_RWLIST_TRAVERSE(&backends, chan, list) {
6237 if (strcasecmp(type, chan->tech->type)) {
6238 continue;
6239 }
6240
6241 break;
6242 }
6243
6245
6246 if (!chan) {
6247 ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
6248 *cause = AST_CAUSE_NOSUCHDRIVER;
6249 return NULL;
6250 }
6251
6252 /* Allow either format capabilities or stream topology to be provided and adapt */
6253 if (chan->tech->requester_with_stream_topology) {
6254 struct ast_stream_topology *tmp_converted_topology = NULL;
6255
6256 if (!topology && request_cap) {
6257 /* Turn the requested capabilities into a stream topology */
6258 topology = tmp_converted_topology = ast_stream_topology_create_from_format_cap(request_cap);
6259 }
6260
6261 c = chan->tech->requester_with_stream_topology(type, topology, assignedids, requestor, addr, cause);
6262
6263 ast_stream_topology_free(tmp_converted_topology);
6264 } else if (chan->tech->requester) {
6265 struct ast_format_cap *tmp_converted_cap = NULL;
6266 struct ast_format_cap *tmp_cap;
6267 RAII_VAR(struct ast_format *, tmp_fmt, NULL, ao2_cleanup);
6268 RAII_VAR(struct ast_format *, best_audio_fmt, NULL, ao2_cleanup);
6269 struct ast_format_cap *joint_cap;
6270
6271 if (!request_cap && topology) {
6272 /* Turn the request stream topology into capabilities */
6273 request_cap = tmp_converted_cap = ast_stream_topology_get_formats(topology);
6274 }
6275
6276 /* find the best audio format to use */
6278 if (!tmp_cap) {
6280 return NULL;
6281 }
6282
6284 if (!ast_format_cap_empty(tmp_cap)) {
6285 /* We have audio - is it possible to connect the various calls to each other?
6286 (Avoid this check for calls without audio, like text+video calls)
6287 */
6288 res = ast_translator_best_choice(tmp_cap, chan->tech->capabilities, &tmp_fmt, &best_audio_fmt);
6289 ao2_ref(tmp_cap, -1);
6290 if (res < 0) {
6291 struct ast_str *tech_codecs = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
6292 struct ast_str *request_codecs = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
6293
6294 ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %s) to %s\n", type,
6295 ast_format_cap_get_names(chan->tech->capabilities, &tech_codecs),
6296 ast_format_cap_get_names(request_cap, &request_codecs));
6298 ao2_cleanup(tmp_converted_cap);
6299 return NULL;
6300 }
6301 }
6302
6303 /* XXX Only the audio format calculated as being the best for translation
6304 * purposes is used for the request. This is because we don't have the ability
6305 * to signal to the initiator which one of their codecs that was offered is
6306 * the one that was selected, particularly in a chain of Local channels.
6307 */
6309 if (!joint_cap) {
6310 ao2_cleanup(tmp_converted_cap);
6311 return NULL;
6312 }
6315 if (best_audio_fmt) { /* text+video call? then, this is NULL */
6316 ast_format_cap_append(joint_cap, best_audio_fmt, 0);
6317 }
6318 ao2_cleanup(tmp_converted_cap);
6319
6320 c = chan->tech->requester(type, joint_cap, assignedids, requestor, addr, cause);
6321 ao2_ref(joint_cap, -1);
6322 }
6323
6324 if (!c) {
6325 return NULL;
6326 }
6327
6328 if (requestor) {
6329 ast_callid callid;
6330
6331 ast_channel_lock_both(c, (struct ast_channel *) requestor);
6332
6333 /* Set the newly created channel's callid to the same as the requestor. */
6334 callid = ast_channel_callid(requestor);
6335 if (callid) {
6336 ast_channel_callid_set(c, callid);
6337 }
6338
6340 ast_channel_unlock((struct ast_channel *) requestor);
6341 }
6342
6343 if (set_security_requirements(requestor, c)) {
6344 ast_log(LOG_WARNING, "Setting security requirements failed\n");
6345 ast_hangup(c);
6347 return NULL;
6348 }
6349
6350 /* no need to generate a Newchannel event here; it is done in the channel_alloc call */
6351 return c;
6352}
6353
6354struct ast_channel *ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
6355{
6356 return request_channel(type, request_cap, NULL, assignedids, requestor, addr, cause);
6357}
6358
6359struct ast_channel *ast_request_with_stream_topology(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
6360{
6361 return request_channel(type, NULL, topology, assignedids, requestor, addr, cause);
6362}
6363
6364/*!
6365 * \internal
6366 * \brief Setup new channel accountcodes from the requestor channel after ast_request().
6367 * \since 13.0.0
6368 *
6369 * \param chan New channel to get accountcodes setup.
6370 * \param requestor Requesting channel to get accountcodes from.
6371 * \param relationship What the new channel was created for.
6372 * \param precious TRUE if pre-existing accountcodes on chan will not be overwritten.
6373 *
6374 * \pre The chan and requestor channels are already locked.
6375 */
6376static void channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship, int precious)
6377{
6378 /*
6379 * The primary reason for the existence of this function is
6380 * so local channels can propagate accountcodes to the ;2
6381 * channel before ast_call().
6382 *
6383 * The secondary reason is to propagate the CHANNEL(peeraccount)
6384 * value set before Dial, FollowMe, and Queue while maintaining
6385 * the historic straight across accountcode propagation as a
6386 * fallback.
6387 */
6388 switch (relationship) {
6390 /* Crossover the requestor's accountcode and peeraccount */
6391 if (!precious || ast_strlen_zero(ast_channel_accountcode(chan))) {
6392 /*
6393 * The newly created channel does not have an accountcode
6394 * or we don't care.
6395 */
6396 if (!ast_strlen_zero(ast_channel_peeraccount(requestor))) {
6397 /*
6398 * Set it to the requestor's peeraccount. This allows the
6399 * dialplan to indicate the accountcode to use when dialing
6400 * by setting CHANNEL(peeraccount).
6401 */
6402 ast_channel_accountcode_set(chan, ast_channel_peeraccount(requestor));
6403 } else if (!precious
6404 && !ast_strlen_zero(ast_channel_accountcode(requestor))) {
6405 /*
6406 * Fallback to the historic propagation and set it to the
6407 * requestor's accountcode.
6408 */
6409 ast_channel_accountcode_set(chan, ast_channel_accountcode(requestor));
6410 }
6411 }
6412 if (!ast_strlen_zero(ast_channel_accountcode(requestor))) {
6413 ast_channel_peeraccount_set(chan, ast_channel_accountcode(requestor));
6414 }
6415 break;
6417 /* Pass the requestor's accountcode and peeraccount straight. */
6418 if (!precious || ast_strlen_zero(ast_channel_accountcode(chan))) {
6419 /*
6420 * The newly created channel does not have an accountcode
6421 * or we don't care.
6422 */
6423 if (!ast_strlen_zero(ast_channel_accountcode(requestor))) {
6424 ast_channel_accountcode_set(chan, ast_channel_accountcode(requestor));
6425 }
6426 }
6427 if (!ast_strlen_zero(ast_channel_peeraccount(requestor))) {
6428 ast_channel_peeraccount_set(chan, ast_channel_peeraccount(requestor));
6429 }
6430 break;
6431 }
6432}
6433
6434void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
6435{
6436 channel_req_accountcodes(chan, requestor, relationship, 0);
6437}
6438
6439void ast_channel_req_accountcodes_precious(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
6440{
6441 channel_req_accountcodes(chan, requestor, relationship, 1);
6442}
6443
6444int ast_pre_call(struct ast_channel *chan, const char *sub_args)
6445{
6446 int (*pre_call)(struct ast_channel *chan, const char *sub_args);
6447
6448 ast_channel_lock(chan);
6449 pre_call = ast_channel_tech(chan)->pre_call;
6450 if (pre_call) {
6451 int res;
6452
6453 res = pre_call(chan, sub_args);
6454 ast_channel_unlock(chan);
6455 return res;
6456 }
6457 ast_channel_unlock(chan);
6458 return ast_app_exec_sub(NULL, chan, sub_args, 0);
6459}
6460
6461int ast_call(struct ast_channel *chan, const char *addr, int timeout)
6462{
6463 /* Place an outgoing call, but don't wait any longer than timeout ms before returning.
6464 If the remote end does not answer within the timeout, then do NOT hang up, but
6465 return anyway. */
6466 int res = -1;
6467 /* Stop if we're a zombie or need a soft hangup */
6468 ast_channel_lock(chan);
6470 if (ast_channel_tech(chan)->call)
6471 res = ast_channel_tech(chan)->call(chan, addr, timeout);
6473 }
6474 ast_channel_unlock(chan);
6475 return res;
6476}
6477
6478/*!
6479 \brief Transfer a call to dest, if the channel supports transfer
6480
6481 Called by:
6482 \arg app_transfer
6483 \arg the manager interface
6484*/
6485int ast_transfer(struct ast_channel *chan, char *dest)
6486{
6487 int protocol;
6488 return ast_transfer_protocol(chan, dest, &protocol);
6489}
6490
6491/*!
6492 \brief Transfer a call to dest, if the channel supports transfer
6493
6494 Called by:
6495 \arg app_transfer
6496 \arg the manager interface
6497*/
6498int ast_transfer_protocol(struct ast_channel *chan, char *dest, int *protocol)
6499{
6500 int res = -1;
6501
6502 if (protocol) {
6503 *protocol = 0;
6504 }
6505
6506 /* Stop if we're a zombie or need a soft hangup */
6507 ast_channel_lock(chan);
6509 if (ast_channel_tech(chan)->transfer) {
6510 res = ast_channel_tech(chan)->transfer(chan, dest);
6511 if (!res)
6512 res = 1;
6513 } else
6514 res = 0;
6515 }
6516 ast_channel_unlock(chan);
6517
6518 if (res <= 0) {
6519 return res;
6520 }
6521
6522 for (;;) {
6523 struct ast_frame *fr;
6524
6525 res = ast_waitfor(chan, -1);
6526
6527 if (res < 0 || !(fr = ast_read(chan))) {
6528 res = -1;
6529 break;
6530 }
6531
6534
6535 if (*message == AST_TRANSFER_SUCCESS) {
6536 res = 1;
6537 } else {
6538 res = -1;
6539 /* Message can contain a protocol specific code
6540 AST_TRANSFER_SUCCESS indicates success
6541 Else, failure. Protocol will be set to the failure reason.
6542 SIP example, 0 is success, else error code 3xx-6xx */
6543 if (protocol) {
6544 *protocol = *message;
6545 }
6546 }
6547
6548 ast_frfree(fr);
6549 break;
6550 }
6551
6552 ast_frfree(fr);
6553 }
6554
6555 return res;
6556}
6557
6558int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders)
6559{
6560 return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1);
6561}
6562
6563int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders, int audiofd, int ctrlfd)
6564{
6565 int pos = 0; /* index in the buffer where we accumulate digits */
6566 int to = ftimeout;
6567
6568 struct ast_silence_generator *silgen = NULL;
6569
6570 /* Stop if we're a zombie or need a soft hangup */
6572 return -1;
6573 if (!len)
6574 return -1;
6575 for (;;) {
6576 int d;
6577 if (ast_channel_stream(c)) {
6578 d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd);
6580 if (!silgen && ast_opt_transmit_silence)
6582 usleep(1000);
6583 if (!d)
6584 d = ast_waitfordigit_full(c, to, NULL, audiofd, ctrlfd);
6585 } else {
6586 if (!silgen && ast_opt_transmit_silence)
6588 d = ast_waitfordigit_full(c, to, NULL, audiofd, ctrlfd);
6589 }
6590 if (d < 0) {
6592 return AST_GETDATA_FAILED;
6593 }
6594 if (d == 0) {
6595 s[pos] = '\0';
6597 return AST_GETDATA_TIMEOUT;
6598 }
6599 if (d == 1) {
6600 s[pos] = '\0';
6603 }
6604 if (strchr(enders, d) && (pos == 0)) {
6605 s[pos] = '\0';
6608 }
6609 if (!strchr(enders, d)) {
6610 s[pos++] = d;
6611 }
6612 if (strchr(enders, d) || (pos >= len)) {
6613 s[pos] = '\0';
6615 return AST_GETDATA_COMPLETE;
6616 }
6617 to = timeout;
6618 }
6619 /* Never reached */
6620 return 0;
6621}
6622
6624{
6625 return (ast_channel_tech(chan)->send_html) ? 1 : 0;
6626}
6627
6628int ast_channel_sendhtml(struct ast_channel *chan, int subclass, const char *data, int datalen)
6629{
6630 if (ast_channel_tech(chan)->send_html)
6631 return ast_channel_tech(chan)->send_html(chan, subclass, data, datalen);
6632 return -1;
6633}
6634
6635int ast_channel_sendurl(struct ast_channel *chan, const char *url)
6636{
6637 return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1);
6638}
6639
6640/*! \brief Set up translation from one channel to another */
6642{
6643 struct ast_format_cap *src_cap;
6644 struct ast_format_cap *dst_cap;
6645 RAII_VAR(struct ast_format *, best_src_fmt, NULL, ao2_cleanup);
6646 RAII_VAR(struct ast_format *, best_dst_fmt, NULL, ao2_cleanup);
6647 int no_path;
6648
6649 /*
6650 * We cannot short circuit this code because it is possible to ask
6651 * to make compatible two channels that are "compatible" because
6652 * they already have translation paths setup but together make for
6653 * a sub-optimal path. e.g., The From channel has g722 -> ulaw
6654 * and the To channel has ulaw -> g722. They are "compatible" but
6655 * together the translations are unnecessary and the audio loses
6656 * fidelity in the process.
6657 */
6658
6659 ast_channel_lock_both(from, to);
6660
6661 src_cap = ast_channel_nativeformats(from); /* shallow copy, do not destroy */
6662 dst_cap = ast_channel_nativeformats(to); /* shallow copy, do not destroy */
6663
6664 /* If there's no audio in this call, don't bother with trying to find a translation path */
6668 ast_channel_unlock(from);
6669 return 0;
6670 }
6671
6672 no_path = ast_translator_best_choice(dst_cap, src_cap, &best_dst_fmt, &best_src_fmt);
6673
6675 ast_channel_unlock(from);
6676
6677 if (no_path) {
6678 ast_log(LOG_WARNING, "No path to translate from %s to %s\n",
6680 return -1;
6681 }
6682
6683 /* if the best path is not 'pass through', then
6684 * transcoding is needed; if desired, force transcode path
6685 * to use SLINEAR between channels, but only if there is
6686 * no direct conversion available. If generic PLC is
6687 * desired, then transcoding via SLINEAR is a requirement
6688 * even if the formats are the same.
6689 */
6691 || (ast_format_cmp(best_dst_fmt, best_src_fmt) == AST_FORMAT_CMP_NOT_EQUAL
6693
6694 int use_slin = (ast_format_cache_is_slinear(best_src_fmt)
6695 || ast_format_cache_is_slinear(best_dst_fmt))
6697
6698 if (use_slin || ast_translate_path_steps(best_dst_fmt, best_src_fmt) != 1) {
6699 int best_sample_rate = (ast_format_get_sample_rate(best_src_fmt) > ast_format_get_sample_rate(best_dst_fmt)) ?
6700 ast_format_get_sample_rate(best_src_fmt) : ast_format_get_sample_rate(best_dst_fmt);
6701
6702 /* pick the best signed linear format based upon what preserves the sample rate the best. */
6703 ao2_replace(best_src_fmt, ast_format_cache_get_slin_by_rate(best_sample_rate));
6704 }
6705 }
6706
6707 if (ast_set_read_format(from, best_src_fmt)) {
6708 ast_log(LOG_WARNING, "Unable to set read format on channel %s to %s\n",
6709 ast_channel_name(from), ast_format_get_name(best_src_fmt));
6710 return -1;
6711 }
6712 if (ast_set_write_format(to, best_src_fmt)) {
6713 ast_log(LOG_WARNING, "Unable to set write format on channel %s to %s\n",
6714 ast_channel_name(to), ast_format_get_name(best_src_fmt));
6715 return -1;
6716 }
6717 return 0;
6718}
6719
6721{
6722 /*
6723 * Set up translation from the peer to the chan first in case we
6724 * need to hear any in-band tones and the other direction fails.
6725 */
6726 if (ast_channel_make_compatible_helper(peer, chan)) {
6727 return -1;
6728 }
6729
6730 /* Set up translation from the chan to the peer */
6731 if (ast_channel_make_compatible_helper(chan, peer)) {
6732 return -1;
6733 }
6734
6735 return 0;
6736}
6737
6738/*! \brief this function simply changes the name of the channel and issues a manager_event
6739 * with out unlinking and linking the channel from the ao2_container. This should
6740 * only be used when the channel has already been unlinked from the ao2_container.
6741 */
6742static void __ast_change_name_nolink(struct ast_channel *chan, const char *newname)
6743{
6744 /*** DOCUMENTATION
6745 <managerEvent language="en_US" name="Rename">
6746 <managerEventInstance class="EVENT_FLAG_CALL">
6747 <synopsis>Raised when the name of a channel is changed.</synopsis>
6748 </managerEventInstance>
6749 </managerEvent>
6750 ***/
6751 ast_manager_event(chan, EVENT_FLAG_CALL, "Rename",
6752 "Channel: %s\r\n"
6753 "Newname: %s\r\n"
6754 "Uniqueid: %s\r\n",
6755 ast_channel_name(chan), newname, ast_channel_uniqueid(chan));
6756 ast_channel_name_set(chan, newname);
6757}
6758
6759void ast_change_name(struct ast_channel *chan, const char *newname)
6760{
6761 /* We must re-link, as the hash value will change here. */
6763 ast_channel_lock(chan);
6764 ao2_unlink(channels, chan);
6765 __ast_change_name_nolink(chan, newname);
6766 ao2_link(channels, chan);
6767 ast_channel_unlock(chan);
6769}
6770
6771void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
6772{
6773 struct ast_var_t *current;
6774 struct ast_var_t *newvar;
6775 const char *varname;
6776 int vartype;
6777
6779 varname = ast_var_full_name(current);
6780 if (!varname) {
6781 continue;
6782 }
6783
6784 vartype = 0;
6785 if (varname[0] == '_') {
6786 vartype = 1;
6787 if (varname[1] == '_') {
6788 vartype = 2;
6789 }
6790 }
6791
6792 switch (vartype) {
6793 case 1:
6794 newvar = ast_var_assign(&varname[1], ast_var_value(current));
6795 break;
6796 case 2:
6797 newvar = ast_var_assign(varname, ast_var_value(current));
6798 break;
6799 default:
6800 continue;
6801 }
6802 if (newvar) {
6803 ast_debug(1, "Inheriting variable %s from %s to %s.\n",
6804 ast_var_full_name(newvar), ast_channel_name(parent),
6805 ast_channel_name(child));
6808 ast_var_value(newvar));
6809 }
6810 }
6811}
6812
6813/*!
6814 \brief Clone channel variables from 'clone' channel into 'original' channel
6815
6816 All variables except those related to app_groupcount are cloned.
6817 Variables are actually _removed_ from 'clone' channel, presumably
6818 because it will subsequently be destroyed.
6819
6820 \note Assumes locks will be in place on both channels when called.
6821*/
6822static void clone_variables(struct ast_channel *original, struct ast_channel *clonechan)
6823{
6824 struct ast_var_t *current, *newvar;
6825 /* Append variables from clone channel into original channel */
6826 /* XXX Is this always correct? We have to in order to keep MACROS working XXX */
6828
6829 /* then, dup the varshead list into the clone */
6830
6832 newvar = ast_var_assign(current->name, current->value);
6833 if (newvar)
6835 }
6836}
6837
6838
6839void ast_channel_name_to_dial_string(char *channel_name)
6840{
6841 char *dash;
6842
6843 /* Truncate after the dash */
6844 dash = strrchr(channel_name, '-');
6845 if (dash) {
6846 *dash = '\0';
6847 }
6848}
6849
6850/*!
6851 * \brief Masquerade a channel
6852 *
6853 * \note Assumes _NO_ channels and _NO_ channel pvt's are locked. If a channel is locked while calling
6854 * this function, it invalidates our channel container locking order. All channels
6855 * must be unlocked before it is permissible to lock the channels' ao2 container.
6856 */
6857static void channel_do_masquerade(struct ast_channel *original, struct ast_channel *clonechan)
6858{
6859 int x;
6860 int origstate;
6861 unsigned int orig_disablestatecache;
6862 unsigned int clone_disablestatecache;
6863 int generator_fd;
6864 int visible_indication;
6865 int clone_hold_state;
6866 int moh_is_playing;
6867 struct ast_frame *current;
6868 const struct ast_channel_tech *t;
6869 void *t_pvt;
6870 union {
6872 struct ast_party_dialed dialed;
6873 struct ast_party_caller caller;
6875 struct ast_party_redirecting redirecting;
6876 } exchange;
6877 struct ast_channel *bridged;
6878 struct ast_format *rformat;
6879 struct ast_format *wformat;
6880 struct ast_format *tmp_format;
6881 struct ast_format_cap *tmp_cap;
6882 char tmp_name[AST_CHANNEL_NAME];
6883 char clone_sending_dtmf_digit;
6884 struct timeval clone_sending_dtmf_tv;
6885
6886 /* XXX This operation is a bit odd. We're essentially putting the guts of
6887 * the clone channel into the original channel. Start by killing off the
6888 * original channel's backend. While the features are nice, which is the
6889 * reason we're keeping it, it's still awesomely weird. XXX */
6890
6891 /* Indicate to each channel that a masquerade is about to begin. */
6892 x = 1;
6893 ast_indicate_data(original, AST_CONTROL_MASQUERADE_NOTIFY, &x, sizeof(x));
6894 ast_indicate_data(clonechan, AST_CONTROL_MASQUERADE_NOTIFY, &x, sizeof(x));
6895
6896 /*
6897 * The container lock is necessary for proper locking order
6898 * because the channels must be unlinked to change their
6899 * names.
6900 *
6901 * The original and clonechan locks must be held while the
6902 * channel contents are shuffled around for the masquerade.
6903 *
6904 * The masq and masqr pointers need to be left alone until the masquerade
6905 * has restabilized the channels to hold off ast_hangup() and until
6906 * AST_FLAG_ZOMBIE can be set on the clonechan.
6907 */
6909
6910 /* Bump the refs to ensure that they won't dissapear on us. */
6911 ast_channel_ref(original);
6912 ast_channel_ref(clonechan);
6913
6914 /* unlink from channels container as name (which is the hash value) will change */
6915 ao2_unlink(channels, original);
6916 ao2_unlink(channels, clonechan);
6917
6918 moh_is_playing = ast_test_flag(ast_channel_flags(original), AST_FLAG_MOH);
6919 if (moh_is_playing) {
6920 /* Stop MOH on the old original channel. */
6921 ast_moh_stop(original);
6922 }
6923
6924 /*
6925 * Stop any visible indication on the original channel so we can
6926 * transfer it to the clonechan taking the original's place.
6927 */
6928 ast_channel_lock(original);
6929 visible_indication = ast_channel_visible_indication(original);
6930 ast_channel_unlock(original);
6931 ast_indicate(original, -1);
6932
6933 /* Start the masquerade channel contents rearrangement. */
6934 ast_channel_lock_both(original, clonechan);
6935
6936 ast_debug(1, "Actually Masquerading %s(%u) into the structure of %s(%u)\n",
6937 ast_channel_name(clonechan), ast_channel_state(clonechan),
6938 ast_channel_name(original), ast_channel_state(original));
6939
6940 /* When all is said and done force new snapshot segments so they are
6941 * up to date.
6942 */
6945
6946 /*
6947 * Remember the original read/write formats. We turn off any
6948 * translation on either one
6949 */
6950 rformat = ao2_bump(ast_channel_readformat(original));
6951 wformat = ao2_bump(ast_channel_writeformat(original));
6952 free_translation(clonechan);
6953 free_translation(original);
6954
6955 clone_hold_state = ast_channel_hold_state(clonechan);
6956
6957 /* Save the current DTMF digit being sent if any. */
6958 clone_sending_dtmf_digit = ast_channel_sending_dtmf_digit(clonechan);
6959 clone_sending_dtmf_tv = ast_channel_sending_dtmf_tv(clonechan);
6960
6961 /* Swap uniqueid's of the channels. This needs to happen before channel renames,
6962 * so rename events get the proper id's.
6963 */
6965
6966 /* Make sure the Stasis topic on the channel is updated appropriately */
6967 ast_channel_internal_swap_topics(clonechan, original);
6968
6969 /* Swap endpoint forward so channel created with endpoint exchanges its state
6970 * with other channel for proper endpoint cleanup.
6971 */
6972 ast_channel_internal_swap_endpoint_forward(clonechan, original);
6973
6974 /* The old snapshots need to follow the channels so the snapshot update is correct */
6975 ast_channel_internal_swap_snapshots(clonechan, original);
6976
6977 /* Swap channel names. This uses ast_channel_name_set directly, so we
6978 * don't get any spurious rename events.
6979 */
6980 ast_copy_string(tmp_name, ast_channel_name(clonechan), sizeof(tmp_name));
6981 ast_channel_name_set(clonechan, ast_channel_name(original));
6982 ast_channel_name_set(original, tmp_name);
6983
6984 /* Swap the technologies */
6985 t = ast_channel_tech(original);
6986 ast_channel_tech_set(original, ast_channel_tech(clonechan));
6987 ast_channel_tech_set(clonechan, t);
6988
6989 t_pvt = ast_channel_tech_pvt(original);
6990 ast_channel_tech_pvt_set(original, ast_channel_tech_pvt(clonechan));
6991 ast_channel_tech_pvt_set(clonechan, t_pvt);
6992
6993 /* Swap the alertpipes */
6994 ast_channel_internal_alertpipe_swap(original, clonechan);
6995
6996 /*
6997 * Swap the readq's. The end result should be this:
6998 *
6999 * 1) All frames should be on the new (original) channel.
7000 * 2) Any frames that were already on the new channel before this
7001 * masquerade need to be at the end of the readq, after all of the
7002 * frames on the old (clone) channel.
7003 * 3) The alertpipe needs to get poked for every frame that was already
7004 * on the new channel, since we are now using the alert pipe from the
7005 * old (clone) channel.
7006 */
7007 {
7008 AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq;
7009
7010 AST_LIST_HEAD_INIT_NOLOCK(&tmp_readq);
7011 AST_LIST_APPEND_LIST(&tmp_readq, ast_channel_readq(original), frame_list);
7013
7014 while ((current = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) {
7016 if (ast_channel_alert_write(original)) {
7017 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
7018 }
7019 }
7020 }
7021
7022 /* Swap the raw formats */
7023 tmp_format = ao2_bump(ast_channel_rawreadformat(original));
7025 ast_channel_set_rawreadformat(clonechan, tmp_format);
7026 ao2_cleanup(tmp_format);
7027
7028 tmp_format = ao2_bump(ast_channel_rawwriteformat(original));
7030 ast_channel_set_rawwriteformat(clonechan, tmp_format);
7031 ao2_cleanup(tmp_format);
7032
7034
7035 /* And of course, so does our current state. Note we need not
7036 call ast_setstate since the event manager doesn't really consider
7037 these separate. We do this early so that the clone has the proper
7038 state of the original channel. */
7039 origstate = ast_channel_state(original);
7040 ast_channel_state_set(original, ast_channel_state(clonechan));
7041 ast_channel_state_set(clonechan, origstate);
7042
7043 /* And the swap the cachable state too. Otherwise we'd start caching
7044 * Local channels and ignoring real ones. */
7045 orig_disablestatecache = ast_test_flag(ast_channel_flags(original), AST_FLAG_DISABLE_DEVSTATE_CACHE);
7046 clone_disablestatecache = ast_test_flag(ast_channel_flags(clonechan), AST_FLAG_DISABLE_DEVSTATE_CACHE);
7047 if (orig_disablestatecache != clone_disablestatecache) {
7048 if (orig_disablestatecache) {
7051 } else {
7054 }
7055 }
7056
7057 /* Keep the same language. */
7058 ast_channel_language_set(original, ast_channel_language(clonechan));
7059
7060 /* Keep the same parkinglot. */
7061 ast_channel_parkinglot_set(original, ast_channel_parkinglot(clonechan));
7062
7063 /* Clear all existing file descriptors but retain the generator */
7064 generator_fd = ast_channel_fd(original, AST_GENERATOR_FD);
7066 ast_channel_set_fd(original, AST_GENERATOR_FD, generator_fd);
7067
7068 /* Copy all file descriptors present on clonechan to original, skipping generator */
7069 for (x = 0; x < ast_channel_fd_count(clonechan); x++) {
7070 if (x != AST_GENERATOR_FD)
7071 ast_channel_set_fd(original, x, ast_channel_fd(clonechan, x));
7072 }
7073
7074 ast_app_group_update(clonechan, original);
7075
7076 /* Swap hangup handlers. */
7077 exchange.handlers = *ast_channel_hangup_handlers(original);
7079 *ast_channel_hangup_handlers(clonechan) = exchange.handlers;
7080
7081 /* Call fixup handlers for the clone chan */
7082 if (AST_LIST_FIRST(ast_channel_datastores(clonechan))) {
7083 struct ast_datastore *ds;
7084 /* We use a safe traversal here because some fixup routines actually
7085 * remove the datastore from the list and free them.
7086 */
7088 if (ds->info->chan_fixup) {
7089 ds->info->chan_fixup(ds->data, clonechan, original);
7090 }
7091 }
7093 }
7094
7095 /* Call breakdown handlers for the original chan */
7096 if (AST_LIST_FIRST(ast_channel_datastores(original))) {
7097 struct ast_datastore *ds;
7098 /* We use a safe traversal here because some breakdown routines may
7099 * remove the datastore from the list and free them.
7100 */
7102 if (ds->info->chan_breakdown) {
7103 ds->info->chan_breakdown(ds->data, clonechan, original);
7104 }
7105 }
7107 }
7108
7109 /* Move data stores over */
7110 if (AST_LIST_FIRST(ast_channel_datastores(clonechan))) {
7112 }
7113
7114 /* Move framehooks over */
7115 ast_framehook_list_fixup(clonechan, original);
7116
7117 /* Move audiohooks over */
7118 ast_audiohook_move_all(clonechan, original);
7119
7120 ast_autochan_new_channel(clonechan, original);
7121
7122 clone_variables(original, clonechan);
7123 /* Presense of ADSI capable CPE follows clone */
7124 ast_channel_adsicpe_set(original, ast_channel_adsicpe(clonechan));
7125 /* Bridge remains the same */
7126 /* CDR fields remain the same */
7127 /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */
7128 /* Application and data remain the same */
7129 /* Clone exception becomes real one, as with fdno */
7131 ast_channel_fdno_set(original, ast_channel_fdno(clonechan));
7132 /* Schedule context remains the same */
7133 /* Stream stuff stays the same */
7134 /* Keep the original state. The fixup code will need to work with it most likely */
7135
7136 /*
7137 * Just swap the whole structures, nevermind the allocations,
7138 * they'll work themselves out.
7139 */
7140 exchange.dialed = *ast_channel_dialed(original);
7141 ast_channel_dialed_set(original, ast_channel_dialed(clonechan));
7142 ast_channel_dialed_set(clonechan, &exchange.dialed);
7143
7144 /* Reset any earlier private caller id representations */
7145 ast_party_id_reset(&ast_channel_caller(original)->priv);
7146 ast_party_id_reset(&ast_channel_caller(clonechan)->priv);
7147
7148 exchange.caller = *ast_channel_caller(original);
7149 ast_channel_caller_set(original, ast_channel_caller(clonechan));
7150 ast_channel_caller_set(clonechan, &exchange.caller);
7151
7152 /* Reset any earlier private connected id representations */
7153 ast_party_id_reset(&ast_channel_connected(original)->priv);
7154 ast_party_id_reset(&ast_channel_connected(clonechan)->priv);
7155
7156 exchange.connected = *ast_channel_connected(original);
7158 ast_channel_connected_set(clonechan, &exchange.connected);
7159
7160 /* Reset any earlier private redirecting orig, from or to representations */
7161 ast_party_id_reset(&ast_channel_redirecting(original)->priv_orig);
7162 ast_party_id_reset(&ast_channel_redirecting(clonechan)->priv_orig);
7163 ast_party_id_reset(&ast_channel_redirecting(original)->priv_from);
7164 ast_party_id_reset(&ast_channel_redirecting(clonechan)->priv_from);
7165 ast_party_id_reset(&ast_channel_redirecting(original)->priv_to);
7166 ast_party_id_reset(&ast_channel_redirecting(clonechan)->priv_to);
7167
7168 exchange.redirecting = *ast_channel_redirecting(original);
7170 ast_channel_redirecting_set(clonechan, &exchange.redirecting);
7171
7173
7174 /* Restore original timing file descriptor */
7176
7177 /* Our native formats are different now */
7179 if (tmp_cap) {
7181 ast_channel_nativeformats_set(original, tmp_cap);
7182 ao2_ref(tmp_cap, -1);
7183 }
7184
7185 /* Context, extension, priority, app data, jump table, remain the same */
7186 /* pvt switches. pbx stays the same, as does next */
7187
7188 /* Set the write format */
7189 ast_set_write_format(original, wformat);
7190
7191 /* Set the read format */
7192 ast_set_read_format(original, rformat);
7193
7194 /* Copy the music class */
7195 ast_channel_musicclass_set(original, ast_channel_musicclass(clonechan));
7196
7197 /* copy over accuntcode and set peeraccount across the bridge */
7198 ast_channel_accountcode_set(original, S_OR(ast_channel_accountcode(clonechan), ""));
7199
7200 ast_debug(1, "Putting channel %s in %s/%s formats\n", ast_channel_name(original),
7201 ast_format_get_name(wformat), ast_format_get_name(rformat));
7202
7203 /* Fixup the original clonechan's physical side */
7204 if (ast_channel_tech(original)->fixup && ast_channel_tech(original)->fixup(clonechan, original)) {
7205 ast_log(LOG_WARNING, "Channel type '%s' could not fixup channel %s, strange things may happen. (clonechan)\n",
7206 ast_channel_tech(original)->type, ast_channel_name(original));
7207 }
7208
7209 /* Fixup the original original's physical side */
7210 if (ast_channel_tech(clonechan)->fixup && ast_channel_tech(clonechan)->fixup(original, clonechan)) {
7211 ast_log(LOG_WARNING, "Channel type '%s' could not fixup channel %s, strange things may happen. (original)\n",
7212 ast_channel_tech(clonechan)->type, ast_channel_name(clonechan));
7213 }
7214
7215 ast_channel_internal_swap_stream_topology(original, clonechan);
7216
7217 /*
7218 * Now, at this point, the "clone" channel is totally F'd up.
7219 * We mark it as a zombie so nothing tries to touch it.
7220 *
7221 * This must be done before we unlock clonechan to prevent
7222 * setting up another masquerade on the clonechan.
7223 */
7225 ast_queue_frame(clonechan, &ast_null_frame);
7226
7227 ast_channel_unlock(original);
7228 ast_channel_unlock(clonechan);
7229
7230 /*
7231 * Indicate to each channel that a masquerade is complete.
7232 *
7233 * We can still do this to clonechan even though it is a
7234 * zombie because ast_indicate_data() will explicitly pass
7235 * this control and ast_hangup() is held off until the
7236 * ast_channel_masq() and ast_channel_masqr() pointers are
7237 * cleared.
7238 */
7239 x = 0;
7240 ast_indicate_data(original, AST_CONTROL_MASQUERADE_NOTIFY, &x, sizeof(x));
7241 ast_indicate_data(clonechan, AST_CONTROL_MASQUERADE_NOTIFY, &x, sizeof(x));
7242
7244
7245 if (clone_hold_state == AST_CONTROL_HOLD) {
7246 ast_debug(1, "Channel %s simulating UNHOLD for masquerade.\n",
7247 ast_channel_name(original));
7249 }
7250 if (clone_sending_dtmf_digit) {
7251 /*
7252 * The clonechan was sending a DTMF digit that was not completed
7253 * before the masquerade.
7254 */
7255 ast_channel_end_dtmf(original, clone_sending_dtmf_digit, clone_sending_dtmf_tv,
7256 "masquerade");
7257 }
7258
7259 /*
7260 * If an indication is currently playing, maintain it on the
7261 * channel that is taking the place of original.
7262 *
7263 * This is needed because the masquerade is swapping out the
7264 * internals of the channel, and the new channel private data
7265 * needs to be made aware of the current visible indication
7266 * (RINGING, CONGESTION, etc.)
7267 */
7268 if (visible_indication) {
7269 if (visible_indication == AST_CONTROL_HOLD) {
7270 const char *latest_musicclass;
7271 int len;
7272
7273 ast_channel_lock(original);
7274 latest_musicclass = ast_strdupa(ast_channel_latest_musicclass(original));
7275 ast_channel_unlock(original);
7276 if (ast_strlen_zero(latest_musicclass)) {
7277 latest_musicclass = NULL;
7278 len = 0;
7279 } else {
7280 len = strlen(latest_musicclass) + 1;
7281 }
7282 ast_indicate_data(original, visible_indication, latest_musicclass, len);
7283 } else {
7284 ast_indicate(original, visible_indication);
7285 }
7286 }
7287
7288 /*
7289 * If MOH was playing on the original channel then it needs to be
7290 * maintained on the channel that is replacing it.
7291 */
7292 if (moh_is_playing) {
7293 /* Start MOH on the new original channel. */
7294 ast_moh_start(original, NULL, NULL);
7295 }
7296
7297 ast_channel_lock(original);
7298
7299 /* Signal any blocker */
7301 pthread_kill(ast_channel_blocker(original), SIGURG);
7302 }
7303
7304 ast_debug(1, "Done Masquerading %s (%u)\n", ast_channel_name(original), ast_channel_state(original));
7305 ast_channel_unlock(original);
7306
7307 if ((bridged = ast_channel_bridge_peer(original))) {
7309 ast_channel_unref(bridged);
7310 }
7312
7313 /* Now that the operation is complete, we can clear the masq
7314 * and masqr fields of both channels.
7315 */
7316 ast_channel_lock_both(original, clonechan);
7317 ast_channel_masq_set(original, NULL);
7318 ast_channel_masqr_set(clonechan, NULL);
7319 ast_channel_unlock(original);
7320 ast_channel_unlock(clonechan);
7321
7322 ao2_link(channels, clonechan);
7323 ao2_link(channels, original);
7325
7326 /* Release our held safety references. */
7327 ast_channel_unref(original);
7328 ast_channel_unref(clonechan);
7329
7330 ao2_cleanup(rformat);
7331 ao2_cleanup(wformat);
7332}
7333
7334void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
7335{
7336 ast_channel_lock(chan);
7337
7338 if (cid_num) {
7339 ast_channel_caller(chan)->id.number.valid = 1;
7340 ast_free(ast_channel_caller(chan)->id.number.str);
7341 ast_channel_caller(chan)->id.number.str = ast_strdup(cid_num);
7342 }
7343 if (cid_name) {
7344 ast_channel_caller(chan)->id.name.valid = 1;
7345 ast_free(ast_channel_caller(chan)->id.name.str);
7346 ast_channel_caller(chan)->id.name.str = ast_strdup(cid_name);
7347 }
7348 if (cid_ani) {
7350 ast_free(ast_channel_caller(chan)->ani.number.str);
7351 ast_channel_caller(chan)->ani.number.str = ast_strdup(cid_ani);
7352 }
7353
7355
7356 ast_channel_unlock(chan);
7357}
7358
7359void ast_channel_set_caller(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
7360{
7361 if (ast_channel_caller(chan) == caller) {
7362 /* Don't set to self */
7363 return;
7364 }
7365
7366 ast_channel_lock(chan);
7369 ast_channel_unlock(chan);
7370}
7371
7372void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
7373{
7374 if (ast_channel_caller(chan) == caller) {
7375 /* Don't set to self */
7376 return;
7377 }
7378
7379 ast_channel_lock(chan);
7383 ast_channel_unlock(chan);
7384}
7385
7387{
7388 int oldstate = ast_channel_state(chan);
7389 char name[AST_CHANNEL_NAME], *dashptr;
7390
7391 if (oldstate == state)
7392 return 0;
7393
7394 ast_copy_string(name, ast_channel_name(chan), sizeof(name));
7395 if ((dashptr = strrchr(name, '-'))) {
7396 *dashptr = '\0';
7397 }
7398
7400
7402
7403 /* We have to pass AST_DEVICE_UNKNOWN here because it is entirely possible that the channel driver
7404 * for this channel is using the callback method for device state. If we pass in an actual state here
7405 * we override what they are saying the state is and things go amuck. */
7407
7408 return 0;
7409}
7410
7411/*! \brief Bridge two channels together (early) */
7413{
7414 /* Make sure we can early bridge, if not error out */
7415 if (!ast_channel_tech(c0)->early_bridge || (c1 && (!ast_channel_tech(c1)->early_bridge || ast_channel_tech(c0)->early_bridge != ast_channel_tech(c1)->early_bridge)))
7416 return -1;
7417
7418 return ast_channel_tech(c0)->early_bridge(c0, c1);
7419}
7420
7421/*! \brief Sets an option on a channel */
7422int ast_channel_setoption(struct ast_channel *chan, int option, void *data, int datalen, int block)
7423{
7424 int res;
7425
7426 ast_channel_lock(chan);
7427 if (!ast_channel_tech(chan)->setoption) {
7428 errno = ENOSYS;
7429 ast_channel_unlock(chan);
7430 return -1;
7431 }
7432
7433 if (block)
7434 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
7435
7436 res = ast_channel_tech(chan)->setoption(chan, option, data, datalen);
7437 ast_channel_unlock(chan);
7438
7439 return res;
7440}
7441
7442int ast_channel_queryoption(struct ast_channel *chan, int option, void *data, int *datalen, int block)
7443{
7444 int res;
7445
7446 ast_channel_lock(chan);
7447 if (!ast_channel_tech(chan)->queryoption) {
7448 errno = ENOSYS;
7449 ast_channel_unlock(chan);
7450 return -1;
7451 }
7452
7453 if (block)
7454 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
7455
7456 res = ast_channel_tech(chan)->queryoption(chan, option, data, datalen);
7457 ast_channel_unlock(chan);
7458
7459 return res;
7460}
7461
7466 int vol;
7467};
7468
7470 int fac1;
7471 int fac2;
7472 int v1_1;
7473 int v2_1;
7474 int v3_1;
7475 int v1_2;
7476 int v2_2;
7477 int v3_2;
7479 int pos;
7482 struct ast_frame f;
7484 short data[4000];
7485};
7486
7487static void tonepair_release(struct ast_channel *chan, void *params)
7488{
7489 struct tonepair_state *ts = params;
7490
7491 if (chan) {
7492 ast_set_write_format(chan, ts->origwfmt);
7493 }
7494 ao2_cleanup(ts->origwfmt);
7495 ast_free(ts);
7496}
7497
7498static void *tonepair_alloc(struct ast_channel *chan, void *params)
7499{
7500 struct tonepair_state *ts;
7501 struct tonepair_def *td = params;
7502
7503 if (!(ts = ast_calloc(1, sizeof(*ts)))) {
7504 return NULL;
7505 }
7506
7509 ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", ast_channel_name(chan));
7511 ts = NULL;
7512 } else {
7513 ts->fac1 = 2.0 * cos(2.0 * M_PI * (td->freq1 / 8000.0)) * 32768.0;
7514 ts->v1_1 = 0;
7515 ts->v2_1 = sin(-4.0 * M_PI * (td->freq1 / 8000.0)) * td->vol;
7516 ts->v3_1 = sin(-2.0 * M_PI * (td->freq1 / 8000.0)) * td->vol;
7517 ts->v2_1 = 0;
7518 ts->fac2 = 2.0 * cos(2.0 * M_PI * (td->freq2 / 8000.0)) * 32768.0;
7519 ts->v2_2 = sin(-4.0 * M_PI * (td->freq2 / 8000.0)) * td->vol;
7520 ts->v3_2 = sin(-2.0 * M_PI * (td->freq2 / 8000.0)) * td->vol;
7521 ts->duration = td->duration;
7522 ts->modulate = 0;
7523 }
7524 /* Let interrupts interrupt :) */
7526 return ts;
7527}
7528
7529static int tonepair_generator(struct ast_channel *chan, void *data, int len, int samples)
7530{
7531 struct tonepair_state *ts = data;
7532 int x;
7533
7534 /* we need to prepare a frame with 16 * timelen samples as we're
7535 * generating SLIN audio
7536 */
7537 len = samples * 2;
7538
7539 if (len > sizeof(ts->data) / 2 - 1) {
7540 ast_log(LOG_WARNING, "Can't generate that much data!\n");
7541 return -1;
7542 }
7543 memset(&ts->f, 0, sizeof(ts->f));
7544 for (x=0;x<len/2;x++) {
7545 ts->v1_1 = ts->v2_1;
7546 ts->v2_1 = ts->v3_1;
7547 ts->v3_1 = (ts->fac1 * ts->v2_1 >> 15) - ts->v1_1;
7548
7549 ts->v1_2 = ts->v2_2;
7550 ts->v2_2 = ts->v3_2;
7551 ts->v3_2 = (ts->fac2 * ts->v2_2 >> 15) - ts->v1_2;
7552 if (ts->modulate) {
7553 int p;
7554 p = ts->v3_2 - 32768;
7555 if (p < 0) p = -p;
7556 p = ((p * 9) / 10) + 1;
7557 ts->data[x] = (ts->v3_1 * p) >> 15;
7558 } else
7559 ts->data[x] = ts->v3_1 + ts->v3_2;
7560 }
7563 ts->f.datalen = len;
7564 ts->f.samples = samples;
7566 ts->f.data.ptr = ts->data;
7567 ast_write(chan, &ts->f);
7568 ts->pos += x;
7569 if (ts->duration > 0) {
7570 if (ts->pos >= ts->duration * 8)
7571 return -1;
7572 }
7573 return 0;
7574}
7575
7576static struct ast_generator tonepair = {
7578 .release = tonepair_release,
7579 .generate = tonepair_generator,
7580};
7581
7582int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
7583{
7584 struct tonepair_def d = { 0, };
7585
7586 d.freq1 = freq1;
7587 d.freq2 = freq2;
7588 d.duration = duration;
7589 d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */
7590 if (ast_activate_generator(chan, &tonepair, &d))
7591 return -1;
7592 return 0;
7593}
7594
7596{
7598}
7599
7600int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
7601{
7602 int res;
7603
7604 if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol)))
7605 return res;
7606
7607 /* Give us some wiggle room */
7608 while (ast_channel_generatordata(chan) && ast_waitfor(chan, 100) >= 0) {
7609 struct ast_frame *f = ast_read(chan);
7610 if (f)
7611 ast_frfree(f);
7612 else
7613 return -1;
7614 }
7615 return 0;
7616}
7617
7619{
7620 char *piece;
7621 char *c;
7622 int start=0, finish=0, x;
7623 ast_group_t group = 0;
7624
7625 if (ast_strlen_zero(s))
7626 return 0;
7627
7628 c = ast_strdupa(s);
7629
7630 while ((piece = strsep(&c, ","))) {
7631 if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) {
7632 /* Range */
7633 } else if (sscanf(piece, "%30d", &start)) {
7634 /* Just one */
7635 finish = start;
7636 } else {
7637 ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece);
7638 continue;
7639 }
7640 for (x = start; x <= finish; x++) {
7641 if ((x > 63) || (x < 0)) {
7642 ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x);
7643 } else
7644 group |= ((ast_group_t) 1 << x);
7645 }
7646 }
7647 return group;
7648}
7649
7650/*! \brief Named group member structure */
7652 /*! Pre-built hash of group member name. */
7653 unsigned int hash;
7654 /*! Group member name. (End allocation of name string.) */
7655 char name[1];
7656};
7657
7658/*! \brief Comparison function used for named group container */
7659static int namedgroup_cmp_cb(void *obj, void *arg, int flags)
7660{
7661 const struct namedgroup_member *an = obj;
7662 const struct namedgroup_member *bn = arg;
7663
7664 return strcmp(an->name, bn->name) ? 0 : CMP_MATCH | CMP_STOP;
7665}
7666
7667/*! \brief Hashing function used for named group container */
7668static int namedgroup_hash_cb(const void *obj, const int flags)
7669{
7670 const struct namedgroup_member *member = obj;
7671
7672 return member->hash;
7673}
7674
7675struct ast_namedgroups *ast_get_namedgroups(const char *s)
7676{
7677 struct ao2_container *namedgroups;
7678 char *piece;
7679 char *c;
7680
7681 if (!s) {
7682 return NULL;
7683 }
7684
7685 /*! \brief Remove leading and trailing whitespace */
7687 if (ast_strlen_zero(c)) {
7688 return NULL;
7689 }
7690
7693 if (!namedgroups) {
7694 return NULL;
7695 }
7696
7697 while ((piece = strsep(&c, ","))) {
7698 struct namedgroup_member *member;
7699 size_t len;
7700
7701 /* remove leading/trailing whitespace */
7702 piece = ast_strip(piece);
7703
7704 len = strlen(piece);
7705 if (!len) {
7706 continue;
7707 }
7708
7710 if (!member) {
7711 ao2_ref(namedgroups, -1);
7712 return NULL;
7713 }
7714 strcpy(member->name, piece);/* Safe */
7715 member->hash = ast_str_hash(member->name);
7716
7717 /* every group name may exist only once, delete duplicates */
7718 ao2_find(namedgroups, member, OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
7719 ao2_link(namedgroups, member);
7720 ao2_ref(member, -1);
7721 }
7722
7723 if (!ao2_container_count(namedgroups)) {
7724 /* There were no group names specified. */
7725 ao2_ref(namedgroups, -1);
7726 namedgroups = NULL;
7727 }
7728
7729 return (struct ast_namedgroups *) namedgroups;
7730}
7731
7732struct ast_namedgroups *ast_unref_namedgroups(struct ast_namedgroups *groups)
7733{
7735 return NULL;
7736}
7737
7738struct ast_namedgroups *ast_ref_namedgroups(struct ast_namedgroups *groups)
7739{
7740 if (groups) {
7741 ao2_ref(groups, 1);
7742 }
7743 return groups;
7744}
7745
7746static int (*ast_moh_start_ptr)(struct ast_channel *, const char *, const char *) = NULL;
7747static void (*ast_moh_stop_ptr)(struct ast_channel *) = NULL;
7748static void (*ast_moh_cleanup_ptr)(struct ast_channel *) = NULL;
7749
7750void ast_install_music_functions(int (*start_ptr)(struct ast_channel *, const char *, const char *),
7751 void (*stop_ptr)(struct ast_channel *),
7752 void (*cleanup_ptr)(struct ast_channel *))
7753{
7754 ast_moh_start_ptr = start_ptr;
7755 ast_moh_stop_ptr = stop_ptr;
7756 ast_moh_cleanup_ptr = cleanup_ptr;
7757}
7758
7760{
7764}
7765
7766int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
7767{
7769 return ast_moh_start_ptr(chan, mclass, interpclass);
7770
7771 ast_verb(3, "Music class %s requested but no musiconhold loaded.\n", mclass ? mclass : (interpclass ? interpclass : "default"));
7772
7773 return -1;
7774}
7775
7776void ast_moh_stop(struct ast_channel *chan)
7777{
7778 if (ast_moh_stop_ptr)
7779 ast_moh_stop_ptr(chan);
7780}
7781
7783{
7785 ast_moh_cleanup_ptr(chan);
7786}
7787
7788static int ast_channel_hash_cb(const void *obj, const int flags)
7789{
7790 const char *name = (flags & OBJ_KEY) ? obj : ast_channel_name((struct ast_channel *) obj);
7791
7792 /* If the name isn't set, return 0 so that the ao2_find() search will
7793 * start in the first bucket. */
7794 if (ast_strlen_zero(name)) {
7795 return 0;
7796 }
7797
7798 return ast_str_case_hash(name);
7799}
7800
7801/*!
7802 * \internal
7803 * \brief Print channel object key (name).
7804 * \since 12.0.0
7805 *
7806 * \param v_obj A pointer to the object we want the key printed.
7807 * \param where User data needed by prnt to determine where to put output.
7808 * \param prnt Print output callback function to use.
7809 */
7810static void prnt_channel_key(void *v_obj, void *where, ao2_prnt_fn *prnt)
7811{
7812 struct ast_channel *chan = v_obj;
7813
7814 if (!chan) {
7815 return;
7816 }
7817 prnt(where, "%s", ast_channel_name(chan));
7818}
7819
7820/*!
7821 * \brief List of channel variables to append to all channel-related events.
7822 */
7825 unsigned int isfunc:1;
7826 char name[];
7827};
7828
7830
7833
7834static void free_external_channelvars(struct external_vars *channelvars)
7835{
7837 AST_RWLIST_WRLOCK(channelvars);
7838 while ((var = AST_RWLIST_REMOVE_HEAD(channelvars, entry))) {
7839 ast_free(var);
7840 }
7841 AST_RWLIST_UNLOCK(channelvars);
7842}
7843
7844static int channel_has_external_vars(struct external_vars *channelvars)
7845{
7846 int vars_present;
7847
7848 AST_RWLIST_RDLOCK(channelvars);
7849 vars_present = !AST_LIST_EMPTY(channelvars);
7850 AST_RWLIST_UNLOCK(channelvars);
7851
7852 return vars_present;
7853}
7854
7856{
7858}
7859
7861{
7863}
7864
7865static void channel_set_external_vars(struct external_vars *channelvars, size_t varc, char **vars)
7866{
7867 size_t i;
7868
7869 free_external_channelvars(channelvars);
7870 AST_RWLIST_WRLOCK(channelvars);
7871 for (i = 0; i < varc; ++i) {
7872 const char *var = vars[i];
7873 struct manager_channel_variable *mcv;
7874 if (!(mcv = ast_calloc(1, sizeof(*mcv) + strlen(var) + 1))) {
7875 break;
7876 }
7877 strcpy(mcv->name, var); /* SAFE */
7878 if (strchr(var, '(')) {
7879 mcv->isfunc = 1;
7880 }
7881 AST_RWLIST_INSERT_TAIL(channelvars, mcv, entry);
7882 }
7883 AST_RWLIST_UNLOCK(channelvars);
7884
7885}
7886
7887void ast_channel_set_manager_vars(size_t varc, char **vars)
7888{
7889 channel_set_external_vars(&ami_vars, varc, vars);
7890}
7891
7892void ast_channel_set_ari_vars(size_t varc, char **vars)
7893{
7894 channel_set_external_vars(&ari_vars, varc, vars);
7895}
7896
7897/*!
7898 * \brief Destructor for lists of variables.
7899 * \param obj AO2 object.
7900 */
7901static void varshead_dtor(void *obj)
7902{
7903 struct varshead *head = obj;
7904 struct ast_var_t *var;
7905
7906 while ((var = AST_RWLIST_REMOVE_HEAD(head, entries))) {
7908 }
7909}
7910
7912{
7913 RAII_VAR(struct varshead *, ret, NULL, ao2_cleanup);
7914 struct ast_var_t *cv;
7915
7916 ret = ao2_alloc(sizeof(*ret), varshead_dtor);
7917
7918 if (!ret) {
7919 return NULL;
7920 }
7921
7924
7925 if (!var) {
7926 return NULL;
7927 }
7928
7930 }
7931
7932 ao2_ref(ret, +1);
7933 return ret;
7934}
7935
7936static struct varshead *channel_get_external_vars(struct external_vars *channelvars,
7937 struct ast_channel *chan)
7938{
7939 RAII_VAR(struct varshead *, ret, NULL, ao2_cleanup);
7940 RAII_VAR(struct ast_str *, tmp, NULL, ast_free);
7941 struct manager_channel_variable *mcv;
7943
7944 if (AST_LIST_EMPTY(channelvars)) {
7945 return NULL;
7946 }
7947
7948 ret = ao2_alloc(sizeof(*ret), varshead_dtor);
7949 tmp = ast_str_create(16);
7950
7951 if (!ret || !tmp) {
7952 return NULL;
7953 }
7954
7955 AST_LIST_TRAVERSE(channelvars, mcv, entry) {
7956 const char *val = NULL;
7957 struct ast_var_t *var;
7958
7959 if (mcv->isfunc) {
7960 if (ast_func_read2(chan, mcv->name, &tmp, 0) == 0) {
7962 } else {
7964 "Error invoking function %s\n", mcv->name);
7965 }
7966 } else {
7967 val = pbx_builtin_getvar_helper(chan, mcv->name);
7968 }
7969
7970 var = ast_var_assign(mcv->name, val ? val : "");
7971 if (!var) {
7972 return NULL;
7973 }
7974
7976 }
7977
7978 ao2_ref(ret, +1);
7979 return ret;
7980
7981}
7982
7984{
7985 return channel_get_external_vars(&ami_vars, chan);
7986}
7987
7989{
7990 return channel_get_external_vars(&ari_vars, chan);
7991}
7992
7993static void channels_shutdown(void)
7994{
7997
7999 if (channels) {
8000 ao2_container_unregister("channels");
8001 ao2_ref(channels, -1);
8002 channels = NULL;
8003 }
8005}
8006
8008{
8011 if (!channels) {
8012 return -1;
8013 }
8015
8017
8019
8021
8023
8026
8027 return 0;
8028}
8029
8030/*! \brief Print call group and pickup group ---*/
8031char *ast_print_group(char *buf, int buflen, ast_group_t group)
8032{
8033 unsigned int i;
8034 int first = 1;
8035 char num[3];
8036
8037 buf[0] = '\0';
8038
8039 if (!group) /* Return empty string if no group */
8040 return buf;
8041
8042 for (i = 0; i <= 63; i++) { /* Max group is 63 */
8043 if (group & ((ast_group_t) 1 << i)) {
8044 if (!first) {
8045 strncat(buf, ", ", buflen - strlen(buf) - 1);
8046 } else {
8047 first = 0;
8048 }
8049 snprintf(num, sizeof(num), "%u", i);
8050 strncat(buf, num, buflen - strlen(buf) - 1);
8051 }
8052 }
8053 return buf;
8054}
8055
8056char *ast_print_namedgroups(struct ast_str **buf, struct ast_namedgroups *group)
8057{
8058 struct ao2_container *grp = (struct ao2_container *) group;
8059 struct namedgroup_member *ng;
8060 int first = 1;
8061 struct ao2_iterator it;
8062
8063 if (!grp) {
8064 return ast_str_buffer(*buf);
8065 }
8066
8067 for (it = ao2_iterator_init(grp, 0); (ng = ao2_iterator_next(&it)); ao2_ref(ng, -1)) {
8068 if (!first) {
8069 ast_str_append(buf, 0, ", ");
8070 } else {
8071 first = 0;
8072 }
8073 ast_str_append(buf, 0, "%s", ng->name);
8074 }
8076
8077 return ast_str_buffer(*buf);
8078}
8079
8080static int namedgroup_match(void *obj, void *arg, int flags)
8081{
8082 void *match;
8083
8084 match = ao2_find(arg, obj, OBJ_POINTER);
8086
8087 return match ? CMP_MATCH | CMP_STOP : 0;
8088}
8089
8090int ast_namedgroups_intersect(struct ast_namedgroups *a, struct ast_namedgroups *b)
8091{
8092 void *match;
8093 struct ao2_container *group_a = (struct ao2_container *) a;
8094 struct ao2_container *group_b = (struct ao2_container *) b;
8095
8096 if (!a || !b) {
8097 return 0;
8098 }
8099
8100 /*
8101 * Do groups a and b intersect? Since a and b are hash tables,
8102 * the average time complexity is:
8103 * O(a.count <= b.count ? a.count : b.count)
8104 */
8105 if (ao2_container_count(group_b) < ao2_container_count(group_a)) {
8106 /* Traverse over the smaller group. */
8107 SWAP(group_a, group_b);
8108 }
8109 match = ao2_callback(group_a, 0, namedgroup_match, group_b);
8111
8112 return match != NULL;
8113}
8114
8115void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
8116{
8117 struct ast_variable *cur;
8118
8119 for (cur = vars; cur; cur = cur->next) {
8120 pbx_builtin_setvar_helper(chan, cur->name, cur->value);
8121 }
8122}
8123
8124static void *silence_generator_alloc(struct ast_channel *chan, void *data)
8125{
8126 /* just store the data pointer in the channel structure */
8127 return data;
8128}
8129
8130static void silence_generator_release(struct ast_channel *chan, void *data)
8131{
8132 /* nothing to do */
8133}
8134
8135static int silence_generator_generate(struct ast_channel *chan, void *data, int len, int samples)
8136{
8137 short buf[samples];
8138 struct ast_frame frame = {
8140 .data.ptr = buf,
8141 .samples = samples,
8142 .datalen = sizeof(buf),
8143 };
8145
8146 memset(buf, 0, sizeof(buf));
8147
8148 if (ast_write(chan, &frame))
8149 return -1;
8150
8151 return 0;
8152}
8153
8156 .release = silence_generator_release,
8157 .generate = silence_generator_generate,
8158};
8159
8162};
8163
8165{
8167
8168 if (!(state = ast_calloc(1, sizeof(*state)))) {
8169 return NULL;
8170 }
8171
8172 state->old_write_format = ao2_bump(ast_channel_writeformat(chan));
8173
8174 if (ast_set_write_format(chan, ast_format_slin) < 0) {
8175 ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n");
8176 ast_free(state);
8177 return NULL;
8178 }
8179
8181
8182 ast_debug(1, "Started silence generator on '%s'\n", ast_channel_name(chan));
8183
8184 return state;
8185}
8186
8188{
8189 ast_channel_lock(chan);
8190
8191 if (!ast_channel_generatordata(chan)) {
8192 ast_debug(1, "Trying to stop silence generator when there is no generator on '%s'\n",
8193 ast_channel_name(chan));
8194 ast_channel_unlock(chan);
8195 return 0;
8196 }
8198 ast_debug(1, "Trying to stop silence generator when it is not the current generator on '%s'\n",
8199 ast_channel_name(chan));
8200 ast_channel_unlock(chan);
8201 return 0;
8202 }
8204
8205 ast_channel_unlock(chan);
8206
8207 return 1;
8208}
8209
8211{
8212 if (!state) {
8213 return;
8214 }
8215
8216 if (deactivate_silence_generator(chan)) {
8217 ast_debug(1, "Stopped silence generator on '%s'\n", ast_channel_name(chan));
8218 if (ast_set_write_format(chan, state->old_write_format) < 0) {
8219 ast_log(LOG_ERROR, "Could not return write format to its original state\n");
8220 }
8221 }
8222 ao2_cleanup(state->old_write_format);
8223 ast_free(state);
8224}
8225
8226
8227/*
8228 * Wrappers for various ast_say_*() functions that call the full version
8229 * of the same functions.
8230 * The proper place would be say.c, but that file is optional and one
8231 * must be able to build asterisk even without it (using a loadable 'say'
8232 * implementation that only supplies the 'full' version of the functions.
8233 */
8234
8235int ast_say_number(struct ast_channel *chan, int num,
8236 const char *ints, const char *language, const char *options)
8237{
8238 return ast_say_number_full(chan, num, ints, language, options, -1, -1);
8239}
8240
8241int ast_say_ordinal(struct ast_channel *chan, int num,
8242 const char *ints, const char *language, const char *options)
8243{
8244 return ast_say_ordinal_full(chan, num, ints, language, options, -1, -1);
8245}
8246
8247int ast_say_enumeration(struct ast_channel *chan, int num,
8248 const char *ints, const char *language, const char *options)
8249{
8250 return ast_say_enumeration_full(chan, num, ints, language, options, -1, -1);
8251}
8252
8253int ast_say_digits(struct ast_channel *chan, int num,
8254 const char *ints, const char *lang)
8255{
8256 return ast_say_digits_full(chan, num, ints, lang, -1, -1);
8257}
8258
8259int ast_say_digit_str(struct ast_channel *chan, const char *str,
8260 const char *ints, const char *lang)
8261{
8262 return ast_say_digit_str_full(chan, str, ints, lang, -1, -1);
8263}
8264
8265int ast_say_money_str(struct ast_channel *chan, const char *str,
8266 const char *ints, const char *lang)
8267{
8268 return ast_say_money_str_full(chan, str, ints, lang, -1, -1);
8269}
8270
8271int ast_say_character_str(struct ast_channel *chan, const char *str,
8272 const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity)
8273{
8274 return ast_say_character_str_full(chan, str, ints, lang, sensitivity, -1, -1);
8275}
8276
8277int ast_say_phonetic_str(struct ast_channel *chan, const char *str,
8278 const char *ints, const char *lang)
8279{
8280 return ast_say_phonetic_str_full(chan, str, ints, lang, -1, -1);
8281}
8282
8283int ast_say_digits_full(struct ast_channel *chan, int num,
8284 const char *ints, const char *lang, int audiofd, int ctrlfd)
8285{
8286 char buf[256];
8287
8288 snprintf(buf, sizeof(buf), "%d", num);
8289
8290 return ast_say_digit_str_full(chan, buf, ints, lang, audiofd, ctrlfd);
8291}
8292
8294{
8295 ast_party_id_copy(&dest->id, &src->id);
8296 ast_party_id_copy(&dest->ani, &src->ani);
8297 dest->ani2 = src->ani2;
8298}
8299
8301{
8302 ast_party_id_copy(&dest->id, &src->id);
8303 ast_party_id_copy(&dest->ani, &src->ani);
8304
8305 dest->ani2 = src->ani2;
8306}
8307
8309{
8310 if (ast_channel_connected(chan) == connected) {
8311 /* Don't set to self */
8312 return;
8313 }
8314
8315 ast_channel_lock(chan);
8319 ast_channel_unlock(chan);
8320}
8321
8322/*! \note Should follow struct ast_party_name */
8324 /*! \brief Subscriber name ie */
8325 int str;
8326 /*! \brief Character set ie. */
8328 /*! \brief presentation-indicator ie */
8330 /*! \brief valid/present ie */
8332};
8333
8334/*!
8335 * \internal
8336 * \since 1.8
8337 * \brief Build a party name information data frame component.
8338 *
8339 * \param data Buffer to fill with the frame data
8340 * \param datalen Size of the buffer to fill
8341 * \param name Party name information
8342 * \param label Name of particular party name
8343 * \param ies Data frame ie values for the party name components
8344 *
8345 * \retval -1 if error
8346 * \retval Amount of data buffer used
8347 */
8348static int party_name_build_data(unsigned char *data, size_t datalen, const struct ast_party_name *name, const char *label, const struct ast_party_name_ies *ies)
8349{
8350 size_t length;
8351 size_t pos = 0;
8352
8353 /*
8354 * The size of integer values must be fixed in case the frame is
8355 * shipped to another machine.
8356 */
8357 if (name->str) {
8358 length = strlen(name->str);
8359 if (datalen < pos + (sizeof(data[0]) * 2) + length) {
8360 ast_log(LOG_WARNING, "No space left for %s name\n", label);
8361 return -1;
8362 }
8363 data[pos++] = ies->str;
8364 data[pos++] = length;
8365 memcpy(data + pos, name->str, length);
8366 pos += length;
8367 }
8368
8369 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8370 ast_log(LOG_WARNING, "No space left for %s name char set\n", label);
8371 return -1;
8372 }
8373 data[pos++] = ies->char_set;
8374 data[pos++] = 1;
8375 data[pos++] = name->char_set;
8376
8377 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8378 ast_log(LOG_WARNING, "No space left for %s name presentation\n", label);
8379 return -1;
8380 }
8381 data[pos++] = ies->presentation;
8382 data[pos++] = 1;
8383 data[pos++] = name->presentation;
8384
8385 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8386 ast_log(LOG_WARNING, "No space left for %s name valid\n", label);
8387 return -1;
8388 }
8389 data[pos++] = ies->valid;
8390 data[pos++] = 1;
8391 data[pos++] = name->valid;
8392
8393 return pos;
8394}
8395
8396/*! \note Should follow struct ast_party_number */
8398 /*! \brief Subscriber phone number ie */
8399 int str;
8400 /*! \brief Type-Of-Number and Numbering-Plan ie */
8401 int plan;
8402 /*! \brief presentation-indicator ie */
8404 /*! \brief valid/present ie */
8406};
8407
8408/*!
8409 * \internal
8410 * \since 1.8
8411 * \brief Build a party number information data frame component.
8412 *
8413 * \param data Buffer to fill with the frame data
8414 * \param datalen Size of the buffer to fill
8415 * \param number Party number information
8416 * \param label Name of particular party number
8417 * \param ies Data frame ie values for the party number components
8418 *
8419 * \retval -1 if error
8420 * \retval Amount of data buffer used
8421 */
8422static int party_number_build_data(unsigned char *data, size_t datalen, const struct ast_party_number *number, const char *label, const struct ast_party_number_ies *ies)
8423{
8424 size_t length;
8425 size_t pos = 0;
8426
8427 /*
8428 * The size of integer values must be fixed in case the frame is
8429 * shipped to another machine.
8430 */
8431 if (number->str) {
8432 length = strlen(number->str);
8433 if (datalen < pos + (sizeof(data[0]) * 2) + length) {
8434 ast_log(LOG_WARNING, "No space left for %s number\n", label);
8435 return -1;
8436 }
8437 data[pos++] = ies->str;
8438 data[pos++] = length;
8439 memcpy(data + pos, number->str, length);
8440 pos += length;
8441 }
8442
8443 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8444 ast_log(LOG_WARNING, "No space left for %s numbering plan\n", label);
8445 return -1;
8446 }
8447 data[pos++] = ies->plan;
8448 data[pos++] = 1;
8449 data[pos++] = number->plan;
8450
8451 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8452 ast_log(LOG_WARNING, "No space left for %s number presentation\n", label);
8453 return -1;
8454 }
8455 data[pos++] = ies->presentation;
8456 data[pos++] = 1;
8457 data[pos++] = number->presentation;
8458
8459 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8460 ast_log(LOG_WARNING, "No space left for %s number valid\n", label);
8461 return -1;
8462 }
8463 data[pos++] = ies->valid;
8464 data[pos++] = 1;
8465 data[pos++] = number->valid;
8466
8467 return pos;
8468}
8469
8470/*! \note Should follow struct ast_party_subaddress */
8472 /*! \brief subaddress ie. */
8473 int str;
8474 /*! \brief subaddress type ie */
8475 int type;
8476 /*! \brief odd/even indicator ie */
8478 /*! \brief valid/present ie */
8480};
8481
8482/*!
8483 * \internal
8484 * \since 1.8
8485 * \brief Build a party subaddress information data frame component.
8486 *
8487 * \param data Buffer to fill with the frame data
8488 * \param datalen Size of the buffer to fill
8489 * \param subaddress Party subaddress information
8490 * \param label Name of particular party subaddress
8491 * \param ies Data frame ie values for the party subaddress components
8492 *
8493 * \retval -1 if error
8494 * \retval Amount of data buffer used
8495 */
8496static int party_subaddress_build_data(unsigned char *data, size_t datalen, const struct ast_party_subaddress *subaddress, const char *label, const struct ast_party_subaddress_ies *ies)
8497{
8498 size_t length;
8499 size_t pos = 0;
8500
8501 /*
8502 * The size of integer values must be fixed in case the frame is
8503 * shipped to another machine.
8504 */
8505 if (subaddress->str) {
8506 length = strlen(subaddress->str);
8507 if (datalen < pos + (sizeof(data[0]) * 2) + length) {
8508 ast_log(LOG_WARNING, "No space left for %s subaddress\n", label);
8509 return -1;
8510 }
8511 data[pos++] = ies->str;
8512 data[pos++] = length;
8513 memcpy(data + pos, subaddress->str, length);
8514 pos += length;
8515 }
8516
8517 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8518 ast_log(LOG_WARNING, "No space left for %s type of subaddress\n", label);
8519 return -1;
8520 }
8521 data[pos++] = ies->type;
8522 data[pos++] = 1;
8523 data[pos++] = subaddress->type;
8524
8525 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8527 "No space left for %s subaddress odd-even indicator\n", label);
8528 return -1;
8529 }
8530 data[pos++] = ies->odd_even_indicator;
8531 data[pos++] = 1;
8532 data[pos++] = subaddress->odd_even_indicator;
8533
8534 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8535 ast_log(LOG_WARNING, "No space left for %s subaddress valid\n", label);
8536 return -1;
8537 }
8538 data[pos++] = ies->valid;
8539 data[pos++] = 1;
8540 data[pos++] = subaddress->valid;
8541
8542 return pos;
8543}
8544
8545/*! \note Should follow struct ast_party_id */
8547 /*! \brief Subscriber name ies */
8549 /*! \brief Subscriber phone number ies */
8551 /*! \brief Subscriber subaddress ies. */
8553 /*! \brief User party id tag ie. */
8554 int tag;
8555 /*!
8556 * \brief Combined name and number presentation ie.
8557 * \note Not sent if value is zero.
8558 */
8560};
8561
8562/*!
8563 * \internal
8564 * \since 1.8
8565 * \brief Build a party id information data frame component.
8566 *
8567 * \param data Buffer to fill with the frame data
8568 * \param datalen Size of the buffer to fill
8569 * \param id Party id information
8570 * \param label Name of particular party id
8571 * \param ies Data frame ie values for the party id components
8572 * \param update What id information to build. NULL if all.
8573 *
8574 * \retval -1 if error
8575 * \retval Amount of data buffer used
8576 */
8577static int party_id_build_data(unsigned char *data, size_t datalen,
8578 const struct ast_party_id *id, const char *label, const struct ast_party_id_ies *ies,
8579 const struct ast_set_party_id *update)
8580{
8581 size_t length;
8582 size_t pos = 0;
8583 int res;
8584
8585 /*
8586 * The size of integer values must be fixed in case the frame is
8587 * shipped to another machine.
8588 */
8589
8590 if (!update || update->name) {
8591 res = party_name_build_data(data + pos, datalen - pos, &id->name, label,
8592 &ies->name);
8593 if (res < 0) {
8594 return -1;
8595 }
8596 pos += res;
8597 }
8598
8599 if (!update || update->number) {
8600 res = party_number_build_data(data + pos, datalen - pos, &id->number, label,
8601 &ies->number);
8602 if (res < 0) {
8603 return -1;
8604 }
8605 pos += res;
8606 }
8607
8608 if (!update || update->subaddress) {
8609 res = party_subaddress_build_data(data + pos, datalen - pos, &id->subaddress,
8610 label, &ies->subaddress);
8611 if (res < 0) {
8612 return -1;
8613 }
8614 pos += res;
8615 }
8616
8617 /* *************** Party id user tag **************************** */
8618 if (id->tag) {
8619 length = strlen(id->tag);
8620 if (datalen < pos + (sizeof(data[0]) * 2) + length) {
8621 ast_log(LOG_WARNING, "No space left for %s tag\n", label);
8622 return -1;
8623 }
8624 data[pos++] = ies->tag;
8625 data[pos++] = length;
8626 memcpy(data + pos, id->tag, length);
8627 pos += length;
8628 }
8629
8630 /* *************** Party id combined presentation *************** */
8631 if (ies->combined_presentation && (!update || update->number)) {
8632 int presentation;
8633
8634 if (!update || update->name) {
8635 presentation = ast_party_id_presentation(id);
8636 } else {
8637 /*
8638 * We must compromise because not all the information is available
8639 * to determine a combined presentation value.
8640 * We will only send the number presentation instead.
8641 */
8642 presentation = id->number.presentation;
8643 }
8644
8645 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8646 ast_log(LOG_WARNING, "No space left for %s combined presentation\n", label);
8647 return -1;
8648 }
8649 data[pos++] = ies->combined_presentation;
8650 data[pos++] = 1;
8651 data[pos++] = presentation;
8652 }
8653
8654 return pos;
8655}
8656
8657/*!
8658 * \brief Element identifiers for connected line indication frame data
8659 * \note Only add to the end of this enum.
8660 */
8661enum {
8665 AST_CONNECTED_LINE_ID_PRESENTATION,/* Combined number and name presentation. */
8673 /*
8674 * No more party id combined number and name presentation values
8675 * need to be created.
8676 */
8695};
8696
8697int ast_connected_line_build_data(unsigned char *data, size_t datalen, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
8698{
8699 int32_t value;
8700 size_t pos = 0;
8701 int res;
8702
8703 static const struct ast_party_id_ies ies = {
8705 .name.char_set = AST_CONNECTED_LINE_NAME_CHAR_SET,
8706 .name.presentation = AST_CONNECTED_LINE_NAME_PRESENTATION,
8707 .name.valid = AST_CONNECTED_LINE_NAME_VALID,
8708
8709 .number.str = AST_CONNECTED_LINE_NUMBER,
8710 .number.plan = AST_CONNECTED_LINE_NUMBER_PLAN,
8711 .number.presentation = AST_CONNECTED_LINE_NUMBER_PRESENTATION,
8712 .number.valid = AST_CONNECTED_LINE_NUMBER_VALID,
8713
8714 .subaddress.str = AST_CONNECTED_LINE_SUBADDRESS,
8715 .subaddress.type = AST_CONNECTED_LINE_SUBADDRESS_TYPE,
8716 .subaddress.odd_even_indicator = AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN,
8717 .subaddress.valid = AST_CONNECTED_LINE_SUBADDRESS_VALID,
8718
8720 .combined_presentation = AST_CONNECTED_LINE_ID_PRESENTATION,
8721 };
8722
8723 static const struct ast_party_id_ies priv_ies = {
8726 .name.presentation = AST_CONNECTED_LINE_PRIV_NAME_PRESENTATION,
8728
8729 .number.str = AST_CONNECTED_LINE_PRIV_NUMBER,
8731 .number.presentation = AST_CONNECTED_LINE_PRIV_NUMBER_PRESENTATION,
8733
8734 .subaddress.str = AST_CONNECTED_LINE_PRIV_SUBADDRESS,
8735 .subaddress.type = AST_CONNECTED_LINE_PRIV_SUBADDRESS_TYPE,
8736 .subaddress.odd_even_indicator = AST_CONNECTED_LINE_PRIV_SUBADDRESS_ODD_EVEN,
8737 .subaddress.valid = AST_CONNECTED_LINE_PRIV_SUBADDRESS_VALID,
8738
8740 .combined_presentation = 0,/* Not sent. */
8741 };
8742
8743 /*
8744 * The size of integer values must be fixed in case the frame is
8745 * shipped to another machine.
8746 */
8747
8748 /* Connected line frame version */
8749 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8750 ast_log(LOG_WARNING, "No space left for connected line frame version\n");
8751 return -1;
8752 }
8753 data[pos++] = AST_CONNECTED_LINE_VERSION;
8754 data[pos++] = 1;
8755 data[pos++] = 2;/* Version 1 did not have a version ie */
8756
8757 res = party_id_build_data(data + pos, datalen - pos, &connected->id,
8758 "connected line", &ies, update ? &update->id : NULL);
8759 if (res < 0) {
8760 return -1;
8761 }
8762 pos += res;
8763
8764 res = party_id_build_data(data + pos, datalen - pos, &connected->priv,
8765 "connected line priv", &priv_ies, update ? &update->priv : NULL);
8766 if (res < 0) {
8767 return -1;
8768 }
8769 pos += res;
8770
8771 /* Connected line source */
8772 if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
8773 ast_log(LOG_WARNING, "No space left for connected line source\n");
8774 return -1;
8775 }
8776 data[pos++] = AST_CONNECTED_LINE_SOURCE;
8777 data[pos++] = sizeof(value);
8778 value = htonl(connected->source);
8779 memcpy(data + pos, &value, sizeof(value));
8780 pos += sizeof(value);
8781
8782 return pos;
8783}
8784
8785int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected)
8786{
8787 size_t pos;
8788 unsigned char ie_len;
8789 unsigned char ie_id;
8790 int32_t value;
8791 int frame_version = 1;
8792 int combined_presentation = 0;
8793 int got_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
8794
8795 for (pos = 0; pos < datalen; pos += ie_len) {
8796 if (datalen < pos + sizeof(ie_id) + sizeof(ie_len)) {
8797 ast_log(LOG_WARNING, "Invalid connected line update\n");
8798 return -1;
8799 }
8800 ie_id = data[pos++];
8801 ie_len = data[pos++];
8802 if (datalen < pos + ie_len) {
8803 ast_log(LOG_WARNING, "Invalid connected line update\n");
8804 return -1;
8805 }
8806
8807 switch (ie_id) {
8808/* Connected line party frame version */
8810 if (ie_len != 1) {
8811 ast_log(LOG_WARNING, "Invalid connected line frame version (%u)\n",
8812 (unsigned) ie_len);
8813 break;
8814 }
8815 frame_version = data[pos];
8816 break;
8817/* Connected line party id name */
8819 ast_free(connected->id.name.str);
8820 connected->id.name.str = ast_malloc(ie_len + 1);
8821 if (connected->id.name.str) {
8822 memcpy(connected->id.name.str, data + pos, ie_len);
8823 connected->id.name.str[ie_len] = 0;
8824 }
8825 break;
8827 if (ie_len != 1) {
8828 ast_log(LOG_WARNING, "Invalid connected line name char set (%u)\n",
8829 (unsigned) ie_len);
8830 break;
8831 }
8832 connected->id.name.char_set = data[pos];
8833 break;
8835 if (ie_len != 1) {
8836 ast_log(LOG_WARNING, "Invalid connected line name presentation (%u)\n",
8837 (unsigned) ie_len);
8838 break;
8839 }
8840 connected->id.name.presentation = data[pos];
8841 break;
8843 if (ie_len != 1) {
8844 ast_log(LOG_WARNING, "Invalid connected line name valid (%u)\n",
8845 (unsigned) ie_len);
8846 break;
8847 }
8848 connected->id.name.valid = data[pos];
8849 break;
8850/* Connected line party id number */
8852 ast_free(connected->id.number.str);
8853 connected->id.number.str = ast_malloc(ie_len + 1);
8854 if (connected->id.number.str) {
8855 memcpy(connected->id.number.str, data + pos, ie_len);
8856 connected->id.number.str[ie_len] = 0;
8857 }
8858 break;
8860 if (ie_len != 1) {
8861 ast_log(LOG_WARNING, "Invalid connected line numbering plan (%u)\n",
8862 (unsigned) ie_len);
8863 break;
8864 }
8865 connected->id.number.plan = data[pos];
8866 break;
8868 if (ie_len != 1) {
8869 ast_log(LOG_WARNING, "Invalid connected line number presentation (%u)\n",
8870 (unsigned) ie_len);
8871 break;
8872 }
8873 connected->id.number.presentation = data[pos];
8874 break;
8876 if (ie_len != 1) {
8877 ast_log(LOG_WARNING, "Invalid connected line number valid (%u)\n",
8878 (unsigned) ie_len);
8879 break;
8880 }
8881 connected->id.number.valid = data[pos];
8882 break;
8883/* Connected line party id subaddress */
8885 ast_free(connected->id.subaddress.str);
8886 connected->id.subaddress.str = ast_malloc(ie_len + 1);
8887 if (connected->id.subaddress.str) {
8888 memcpy(connected->id.subaddress.str, data + pos, ie_len);
8889 connected->id.subaddress.str[ie_len] = 0;
8890 }
8891 break;
8893 if (ie_len != 1) {
8894 ast_log(LOG_WARNING, "Invalid connected line type of subaddress (%u)\n",
8895 (unsigned) ie_len);
8896 break;
8897 }
8898 connected->id.subaddress.type = data[pos];
8899 break;
8901 if (ie_len != 1) {
8903 "Invalid connected line subaddress odd-even indicator (%u)\n",
8904 (unsigned) ie_len);
8905 break;
8906 }
8907 connected->id.subaddress.odd_even_indicator = data[pos];
8908 break;
8910 if (ie_len != 1) {
8911 ast_log(LOG_WARNING, "Invalid connected line subaddress valid (%u)\n",
8912 (unsigned) ie_len);
8913 break;
8914 }
8915 connected->id.subaddress.valid = data[pos];
8916 break;
8917/* Connected line party tag */
8919 ast_free(connected->id.tag);
8920 connected->id.tag = ast_malloc(ie_len + 1);
8921 if (connected->id.tag) {
8922 memcpy(connected->id.tag, data + pos, ie_len);
8923 connected->id.tag[ie_len] = 0;
8924 }
8925 break;
8926/* Connected line party id combined presentation */
8928 if (ie_len != 1) {
8929 ast_log(LOG_WARNING, "Invalid connected line combined presentation (%u)\n",
8930 (unsigned) ie_len);
8931 break;
8932 }
8933 combined_presentation = data[pos];
8934 got_combined_presentation = 1;
8935 break;
8936/* Private connected line party id name */
8938 ast_free(connected->priv.name.str);
8939 connected->priv.name.str = ast_malloc(ie_len + 1);
8940 if (connected->priv.name.str) {
8941 memcpy(connected->priv.name.str, data + pos, ie_len);
8942 connected->priv.name.str[ie_len] = 0;
8943 }
8944 break;
8946 if (ie_len != 1) {
8947 ast_log(LOG_WARNING, "Invalid connected line private name char set (%u)\n",
8948 (unsigned) ie_len);
8949 break;
8950 }
8951 connected->priv.name.char_set = data[pos];
8952 break;
8954 if (ie_len != 1) {
8955 ast_log(LOG_WARNING, "Invalid connected line private name presentation (%u)\n",
8956 (unsigned) ie_len);
8957 break;
8958 }
8959 connected->priv.name.presentation = data[pos];
8960 break;
8962 if (ie_len != 1) {
8963 ast_log(LOG_WARNING, "Invalid connected line private name valid (%u)\n",
8964 (unsigned) ie_len);
8965 break;
8966 }
8967 connected->priv.name.valid = data[pos];
8968 break;
8969/* Private connected line party id number */
8971 ast_free(connected->priv.number.str);
8972 connected->priv.number.str = ast_malloc(ie_len + 1);
8973 if (connected->priv.number.str) {
8974 memcpy(connected->priv.number.str, data + pos, ie_len);
8975 connected->priv.number.str[ie_len] = 0;
8976 }
8977 break;
8979 if (ie_len != 1) {
8980 ast_log(LOG_WARNING, "Invalid connected line private numbering plan (%u)\n",
8981 (unsigned) ie_len);
8982 break;
8983 }
8984 connected->priv.number.plan = data[pos];
8985 break;
8987 if (ie_len != 1) {
8988 ast_log(LOG_WARNING, "Invalid connected line private number presentation (%u)\n",
8989 (unsigned) ie_len);
8990 break;
8991 }
8992 connected->priv.number.presentation = data[pos];
8993 break;
8995 if (ie_len != 1) {
8996 ast_log(LOG_WARNING, "Invalid connected line private number valid (%u)\n",
8997 (unsigned) ie_len);
8998 break;
8999 }
9000 connected->priv.number.valid = data[pos];
9001 break;
9002/* Private connected line party id subaddress */
9004 ast_free(connected->priv.subaddress.str);
9005 connected->priv.subaddress.str = ast_malloc(ie_len + 1);
9006 if (connected->priv.subaddress.str) {
9007 memcpy(connected->priv.subaddress.str, data + pos, ie_len);
9008 connected->priv.subaddress.str[ie_len] = 0;
9009 }
9010 break;
9012 if (ie_len != 1) {
9013 ast_log(LOG_WARNING, "Invalid connected line private type of subaddress (%u)\n",
9014 (unsigned) ie_len);
9015 break;
9016 }
9017 connected->priv.subaddress.type = data[pos];
9018 break;
9020 if (ie_len != 1) {
9022 "Invalid connected line private subaddress odd-even indicator (%u)\n",
9023 (unsigned) ie_len);
9024 break;
9025 }
9026 connected->priv.subaddress.odd_even_indicator = data[pos];
9027 break;
9029 if (ie_len != 1) {
9030 ast_log(LOG_WARNING, "Invalid connected line private subaddress valid (%u)\n",
9031 (unsigned) ie_len);
9032 break;
9033 }
9034 connected->priv.subaddress.valid = data[pos];
9035 break;
9036/* Private connected line party tag */
9038 ast_free(connected->priv.tag);
9039 connected->priv.tag = ast_malloc(ie_len + 1);
9040 if (connected->priv.tag) {
9041 memcpy(connected->priv.tag, data + pos, ie_len);
9042 connected->priv.tag[ie_len] = 0;
9043 }
9044 break;
9045/* Connected line party source */
9047 if (ie_len != sizeof(value)) {
9048 ast_log(LOG_WARNING, "Invalid connected line source (%u)\n",
9049 (unsigned) ie_len);
9050 break;
9051 }
9052 memcpy(&value, data + pos, sizeof(value));
9053 connected->source = ntohl(value);
9054 break;
9055/* Connected line party unknown element */
9056 default:
9057 ast_debug(1, "Unknown connected line element: %u (%u)\n",
9058 (unsigned) ie_id, (unsigned) ie_len);
9059 break;
9060 }
9061 }
9062
9063 switch (frame_version) {
9064 case 1:
9065 /*
9066 * The other end is an earlier version that we need to adjust
9067 * for compatibility.
9068 */
9069 connected->id.name.valid = 1;
9070 connected->id.name.char_set = AST_PARTY_CHAR_SET_ISO8859_1;
9071 connected->id.number.valid = 1;
9072 if (got_combined_presentation) {
9073 connected->id.name.presentation = combined_presentation;
9074 connected->id.number.presentation = combined_presentation;
9075 }
9076 break;
9077 case 2:
9078 /* The other end is at the same level as we are. */
9079 break;
9080 default:
9081 /*
9082 * The other end is newer than we are.
9083 * We need to assume that they are compatible with us.
9084 */
9085 ast_debug(1, "Connected line frame has newer version: %u\n",
9086 (unsigned) frame_version);
9087 break;
9088 }
9089
9090 return 0;
9091}
9092
9094{
9095 unsigned char data[1024]; /* This should be large enough */
9096 size_t datalen;
9097
9098 datalen = ast_connected_line_build_data(data, sizeof(data), connected, update);
9099 if (datalen == (size_t) -1) {
9100 return;
9101 }
9102
9103 ast_indicate_data(chan, AST_CONTROL_CONNECTED_LINE, data, datalen);
9104}
9105
9107{
9108 unsigned char data[1024]; /* This should be large enough */
9109 size_t datalen;
9110
9111 datalen = ast_connected_line_build_data(data, sizeof(data), connected, update);
9112 if (datalen == (size_t) -1) {
9113 return;
9114 }
9115
9117}
9118
9119void ast_channel_set_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
9120{
9121 if (ast_channel_redirecting(chan) == redirecting) {
9122 /* Don't set to self */
9123 return;
9124 }
9125
9126 ast_channel_lock(chan);
9130 ast_channel_unlock(chan);
9131}
9132
9133/*!
9134 * \brief Element identifiers for redirecting indication frame data
9135 * \note Only add to the end of this enum.
9136 */
9137enum {
9141 AST_REDIRECTING_FROM_ID_PRESENTATION,/* Combined number and name presentation. */
9145 AST_REDIRECTING_TO_ID_PRESENTATION,/* Combined number and name presentation. */
9159 /*
9160 * No more party id combined number and name presentation values
9161 * need to be created.
9162 */
9228};
9229
9231 int code;
9232 int str;
9233};
9234
9235static int redirecting_reason_build_data(unsigned char *data, size_t datalen,
9236 const struct ast_party_redirecting_reason *reason, const char *label,
9237 const struct ast_party_redirecting_reason_ies *ies)
9238{
9239 size_t length;
9240 size_t pos = 0;
9241 int32_t value;
9242
9243 if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
9244 ast_log(LOG_WARNING, "No space left for %s code\n", label);
9245 return -1;
9246 }
9247 data[pos++] = ies->code;
9248 data[pos++] = sizeof(value);
9249 value = htonl(reason->code);
9250 memcpy(data + pos, &value, sizeof(value));
9251 pos += sizeof(value);
9252
9253 if (reason->str) {
9254 length = strlen(reason->str);
9255 if (datalen < pos + (sizeof(data[0]) * 2) + length) {
9256 ast_log(LOG_WARNING, "No space left for %s string\n", label);
9257 return -1;
9258 }
9259 data[pos++] = ies->str;
9260 data[pos++] = length;
9261 memcpy(data + pos, reason->str, length);
9262 pos += length;
9263 }
9264
9265 return pos;
9266}
9267
9268int ast_redirecting_build_data(unsigned char *data, size_t datalen, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
9269{
9270 int32_t value;
9271 size_t pos = 0;
9272 int res;
9273
9274 static const struct ast_party_id_ies orig_ies = {
9276 .name.char_set = AST_REDIRECTING_ORIG_NAME_CHAR_SET,
9277 .name.presentation = AST_REDIRECTING_ORIG_NAME_PRESENTATION,
9278 .name.valid = AST_REDIRECTING_ORIG_NAME_VALID,
9279
9280 .number.str = AST_REDIRECTING_ORIG_NUMBER,
9281 .number.plan = AST_REDIRECTING_ORIG_NUMBER_PLAN,
9282 .number.presentation = AST_REDIRECTING_ORIG_NUMBER_PRESENTATION,
9283 .number.valid = AST_REDIRECTING_ORIG_NUMBER_VALID,
9284
9285 .subaddress.str = AST_REDIRECTING_ORIG_SUBADDRESS,
9286 .subaddress.type = AST_REDIRECTING_ORIG_SUBADDRESS_TYPE,
9287 .subaddress.odd_even_indicator = AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN,
9288 .subaddress.valid = AST_REDIRECTING_ORIG_SUBADDRESS_VALID,
9289
9291 .combined_presentation = 0,/* Not sent. */
9292 };
9293 static const struct ast_party_id_ies from_ies = {
9295 .name.char_set = AST_REDIRECTING_FROM_NAME_CHAR_SET,
9296 .name.presentation = AST_REDIRECTING_FROM_NAME_PRESENTATION,
9297 .name.valid = AST_REDIRECTING_FROM_NAME_VALID,
9298
9299 .number.str = AST_REDIRECTING_FROM_NUMBER,
9300 .number.plan = AST_REDIRECTING_FROM_NUMBER_PLAN,
9301 .number.presentation = AST_REDIRECTING_FROM_NUMBER_PRESENTATION,
9302 .number.valid = AST_REDIRECTING_FROM_NUMBER_VALID,
9303
9304 .subaddress.str = AST_REDIRECTING_FROM_SUBADDRESS,
9305 .subaddress.type = AST_REDIRECTING_FROM_SUBADDRESS_TYPE,
9306 .subaddress.odd_even_indicator = AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN,
9307 .subaddress.valid = AST_REDIRECTING_FROM_SUBADDRESS_VALID,
9308
9310 .combined_presentation = AST_REDIRECTING_FROM_ID_PRESENTATION,
9311 };
9312 static const struct ast_party_id_ies to_ies = {
9314 .name.char_set = AST_REDIRECTING_TO_NAME_CHAR_SET,
9315 .name.presentation = AST_REDIRECTING_TO_NAME_PRESENTATION,
9316 .name.valid = AST_REDIRECTING_TO_NAME_VALID,
9317
9318 .number.str = AST_REDIRECTING_TO_NUMBER,
9319 .number.plan = AST_REDIRECTING_TO_NUMBER_PLAN,
9320 .number.presentation = AST_REDIRECTING_TO_NUMBER_PRESENTATION,
9321 .number.valid = AST_REDIRECTING_TO_NUMBER_VALID,
9322
9323 .subaddress.str = AST_REDIRECTING_TO_SUBADDRESS,
9324 .subaddress.type = AST_REDIRECTING_TO_SUBADDRESS_TYPE,
9325 .subaddress.odd_even_indicator = AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN,
9326 .subaddress.valid = AST_REDIRECTING_TO_SUBADDRESS_VALID,
9327
9329 .combined_presentation = AST_REDIRECTING_TO_ID_PRESENTATION,
9330 };
9331 static const struct ast_party_id_ies priv_orig_ies = {
9336
9339 .number.presentation = AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION,
9341
9342 .subaddress.str = AST_REDIRECTING_PRIV_ORIG_SUBADDRESS,
9344 .subaddress.odd_even_indicator = AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN,
9346
9348 .combined_presentation = 0,/* Not sent. */
9349 };
9350 static const struct ast_party_id_ies priv_from_ies = {
9355
9358 .number.presentation = AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION,
9360
9361 .subaddress.str = AST_REDIRECTING_PRIV_FROM_SUBADDRESS,
9363 .subaddress.odd_even_indicator = AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN,
9365
9367 .combined_presentation = 0,/* Not sent. */
9368 };
9369 static const struct ast_party_id_ies priv_to_ies = {
9372 .name.presentation = AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION,
9374
9375 .number.str = AST_REDIRECTING_PRIV_TO_NUMBER,
9377 .number.presentation = AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION,
9379
9380 .subaddress.str = AST_REDIRECTING_PRIV_TO_SUBADDRESS,
9381 .subaddress.type = AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE,
9382 .subaddress.odd_even_indicator = AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN,
9383 .subaddress.valid = AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID,
9384
9386 .combined_presentation = 0,/* Not sent. */
9387 };
9388 static const struct ast_party_redirecting_reason_ies reason_ies = {
9391 };
9392
9393 static const struct ast_party_redirecting_reason_ies orig_reason_ies = {
9396 };
9397
9398 /* Redirecting frame version */
9399 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
9400 ast_log(LOG_WARNING, "No space left for redirecting frame version\n");
9401 return -1;
9402 }
9403 data[pos++] = AST_REDIRECTING_VERSION;
9404 data[pos++] = 1;
9405 data[pos++] = 2;/* Version 1 did not have a version ie */
9406
9407 res = party_id_build_data(data + pos, datalen - pos, &redirecting->orig,
9408 "redirecting-orig", &orig_ies, update ? &update->orig : NULL);
9409 if (res < 0) {
9410 return -1;
9411 }
9412 pos += res;
9413
9414 res = party_id_build_data(data + pos, datalen - pos, &redirecting->from,
9415 "redirecting-from", &from_ies, update ? &update->from : NULL);
9416 if (res < 0) {
9417 return -1;
9418 }
9419 pos += res;
9420
9421 res = party_id_build_data(data + pos, datalen - pos, &redirecting->to,
9422 "redirecting-to", &to_ies, update ? &update->to : NULL);
9423 if (res < 0) {
9424 return -1;
9425 }
9426 pos += res;
9427
9428 res = party_id_build_data(data + pos, datalen - pos, &redirecting->priv_orig,
9429 "redirecting-priv-orig", &priv_orig_ies, update ? &update->priv_orig : NULL);
9430 if (res < 0) {
9431 return -1;
9432 }
9433 pos += res;
9434
9435 res = party_id_build_data(data + pos, datalen - pos, &redirecting->priv_from,
9436 "redirecting-priv-from", &priv_from_ies, update ? &update->priv_from : NULL);
9437 if (res < 0) {
9438 return -1;
9439 }
9440 pos += res;
9441
9442 res = party_id_build_data(data + pos, datalen - pos, &redirecting->priv_to,
9443 "redirecting-priv-to", &priv_to_ies, update ? &update->priv_to : NULL);
9444 if (res < 0) {
9445 return -1;
9446 }
9447 pos += res;
9448
9449 /* Redirecting reason */
9450 res = redirecting_reason_build_data(data + pos, datalen - pos, &redirecting->reason,
9451 "redirecting-reason", &reason_ies);
9452 if (res < 0) {
9453 return -1;
9454 }
9455 pos += res;
9456
9457 /* Redirecting original reason */
9458 res = redirecting_reason_build_data(data + pos, datalen - pos, &redirecting->orig_reason,
9459 "redirecting-orig-reason", &orig_reason_ies);
9460 if (res < 0) {
9461 return -1;
9462 }
9463 pos += res;
9464
9465 /* Redirecting count */
9466 if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
9467 ast_log(LOG_WARNING, "No space left for redirecting count\n");
9468 return -1;
9469 }
9470 data[pos++] = AST_REDIRECTING_COUNT;
9471 data[pos++] = sizeof(value);
9472 value = htonl(redirecting->count);
9473 memcpy(data + pos, &value, sizeof(value));
9474 pos += sizeof(value);
9475
9476 return pos;
9477}
9478
9479int ast_redirecting_parse_data(const unsigned char *data, size_t datalen, struct ast_party_redirecting *redirecting)
9480{
9481 size_t pos;
9482 unsigned char ie_len;
9483 unsigned char ie_id;
9484 int32_t value;
9485 int frame_version = 1;
9486 int from_combined_presentation = 0;
9487 int got_from_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
9488 int to_combined_presentation = 0;
9489 int got_to_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
9490
9491 for (pos = 0; pos < datalen; pos += ie_len) {
9492 if (datalen < pos + sizeof(ie_id) + sizeof(ie_len)) {
9493 ast_log(LOG_WARNING, "Invalid redirecting update\n");
9494 return -1;
9495 }
9496 ie_id = data[pos++];
9497 ie_len = data[pos++];
9498 if (datalen < pos + ie_len) {
9499 ast_log(LOG_WARNING, "Invalid redirecting update\n");
9500 return -1;
9501 }
9502
9503 switch (ie_id) {
9504/* Redirecting frame version */
9506 if (ie_len != 1) {
9507 ast_log(LOG_WARNING, "Invalid redirecting frame version (%u)\n",
9508 (unsigned) ie_len);
9509 break;
9510 }
9511 frame_version = data[pos];
9512 break;
9513/* Redirecting-orig party id name */
9515 ast_free(redirecting->orig.name.str);
9516 redirecting->orig.name.str = ast_malloc(ie_len + 1);
9517 if (redirecting->orig.name.str) {
9518 memcpy(redirecting->orig.name.str, data + pos, ie_len);
9519 redirecting->orig.name.str[ie_len] = 0;
9520 }
9521 break;
9523 if (ie_len != 1) {
9524 ast_log(LOG_WARNING, "Invalid redirecting-orig name char set (%u)\n",
9525 (unsigned) ie_len);
9526 break;
9527 }
9528 redirecting->orig.name.char_set = data[pos];
9529 break;
9531 if (ie_len != 1) {
9532 ast_log(LOG_WARNING, "Invalid redirecting-orig name presentation (%u)\n",
9533 (unsigned) ie_len);
9534 break;
9535 }
9536 redirecting->orig.name.presentation = data[pos];
9537 break;
9539 if (ie_len != 1) {
9540 ast_log(LOG_WARNING, "Invalid redirecting-orig name valid (%u)\n",
9541 (unsigned) ie_len);
9542 break;
9543 }
9544 redirecting->orig.name.valid = data[pos];
9545 break;
9546/* Redirecting-orig party id number */
9548 ast_free(redirecting->orig.number.str);
9549 redirecting->orig.number.str = ast_malloc(ie_len + 1);
9550 if (redirecting->orig.number.str) {
9551 memcpy(redirecting->orig.number.str, data + pos, ie_len);
9552 redirecting->orig.number.str[ie_len] = 0;
9553 }
9554 break;
9556 if (ie_len != 1) {
9557 ast_log(LOG_WARNING, "Invalid redirecting-orig numbering plan (%u)\n",
9558 (unsigned) ie_len);
9559 break;
9560 }
9561 redirecting->orig.number.plan = data[pos];
9562 break;
9564 if (ie_len != 1) {
9565 ast_log(LOG_WARNING, "Invalid redirecting-orig number presentation (%u)\n",
9566 (unsigned) ie_len);
9567 break;
9568 }
9569 redirecting->orig.number.presentation = data[pos];
9570 break;
9572 if (ie_len != 1) {
9573 ast_log(LOG_WARNING, "Invalid redirecting-orig number valid (%u)\n",
9574 (unsigned) ie_len);
9575 break;
9576 }
9577 redirecting->orig.number.valid = data[pos];
9578 break;
9579/* Redirecting-orig party id subaddress */
9581 ast_free(redirecting->orig.subaddress.str);
9582 redirecting->orig.subaddress.str = ast_malloc(ie_len + 1);
9583 if (redirecting->orig.subaddress.str) {
9584 memcpy(redirecting->orig.subaddress.str, data + pos, ie_len);
9585 redirecting->orig.subaddress.str[ie_len] = 0;
9586 }
9587 break;
9589 if (ie_len != 1) {
9590 ast_log(LOG_WARNING, "Invalid redirecting-orig type of subaddress (%u)\n",
9591 (unsigned) ie_len);
9592 break;
9593 }
9594 redirecting->orig.subaddress.type = data[pos];
9595 break;
9597 if (ie_len != 1) {
9599 "Invalid redirecting-orig subaddress odd-even indicator (%u)\n",
9600 (unsigned) ie_len);
9601 break;
9602 }
9603 redirecting->orig.subaddress.odd_even_indicator = data[pos];
9604 break;
9606 if (ie_len != 1) {
9607 ast_log(LOG_WARNING, "Invalid redirecting-orig subaddress valid (%u)\n",
9608 (unsigned) ie_len);
9609 break;
9610 }
9611 redirecting->orig.subaddress.valid = data[pos];
9612 break;
9613/* Redirecting-orig party id tag */
9615 ast_free(redirecting->orig.tag);
9616 redirecting->orig.tag = ast_malloc(ie_len + 1);
9617 if (redirecting->orig.tag) {
9618 memcpy(redirecting->orig.tag, data + pos, ie_len);
9619 redirecting->orig.tag[ie_len] = 0;
9620 }
9621 break;
9622/* Redirecting-from party id name */
9624 ast_free(redirecting->from.name.str);
9625 redirecting->from.name.str = ast_malloc(ie_len + 1);
9626 if (redirecting->from.name.str) {
9627 memcpy(redirecting->from.name.str, data + pos, ie_len);
9628 redirecting->from.name.str[ie_len] = 0;
9629 }
9630 break;
9632 if (ie_len != 1) {
9633 ast_log(LOG_WARNING, "Invalid redirecting-from name char set (%u)\n",
9634 (unsigned) ie_len);
9635 break;
9636 }
9637 redirecting->from.name.char_set = data[pos];
9638 break;
9640 if (ie_len != 1) {
9641 ast_log(LOG_WARNING, "Invalid redirecting-from name presentation (%u)\n",
9642 (unsigned) ie_len);
9643 break;
9644 }
9645 redirecting->from.name.presentation = data[pos];
9646 break;
9648 if (ie_len != 1) {
9649 ast_log(LOG_WARNING, "Invalid redirecting-from name valid (%u)\n",
9650 (unsigned) ie_len);
9651 break;
9652 }
9653 redirecting->from.name.valid = data[pos];
9654 break;
9655/* Redirecting-from party id number */
9657 ast_free(redirecting->from.number.str);
9658 redirecting->from.number.str = ast_malloc(ie_len + 1);
9659 if (redirecting->from.number.str) {
9660 memcpy(redirecting->from.number.str, data + pos, ie_len);
9661 redirecting->from.number.str[ie_len] = 0;
9662 }
9663 break;
9665 if (ie_len != 1) {
9666 ast_log(LOG_WARNING, "Invalid redirecting-from numbering plan (%u)\n",
9667 (unsigned) ie_len);
9668 break;
9669 }
9670 redirecting->from.number.plan = data[pos];
9671 break;
9673 if (ie_len != 1) {
9674 ast_log(LOG_WARNING, "Invalid redirecting-from number presentation (%u)\n",
9675 (unsigned) ie_len);
9676 break;
9677 }
9678 redirecting->from.number.presentation = data[pos];
9679 break;
9681 if (ie_len != 1) {
9682 ast_log(LOG_WARNING, "Invalid redirecting-from number valid (%u)\n",
9683 (unsigned) ie_len);
9684 break;
9685 }
9686 redirecting->from.number.valid = data[pos];
9687 break;
9688/* Redirecting-from party id combined presentation */
9690 if (ie_len != 1) {
9691 ast_log(LOG_WARNING, "Invalid redirecting-from combined presentation (%u)\n",
9692 (unsigned) ie_len);
9693 break;
9694 }
9695 from_combined_presentation = data[pos];
9696 got_from_combined_presentation = 1;
9697 break;
9698/* Redirecting-from party id subaddress */
9700 ast_free(redirecting->from.subaddress.str);
9701 redirecting->from.subaddress.str = ast_malloc(ie_len + 1);
9702 if (redirecting->from.subaddress.str) {
9703 memcpy(redirecting->from.subaddress.str, data + pos, ie_len);
9704 redirecting->from.subaddress.str[ie_len] = 0;
9705 }
9706 break;
9708 if (ie_len != 1) {
9709 ast_log(LOG_WARNING, "Invalid redirecting-from type of subaddress (%u)\n",
9710 (unsigned) ie_len);
9711 break;
9712 }
9713 redirecting->from.subaddress.type = data[pos];
9714 break;
9716 if (ie_len != 1) {
9718 "Invalid redirecting-from subaddress odd-even indicator (%u)\n",
9719 (unsigned) ie_len);
9720 break;
9721 }
9722 redirecting->from.subaddress.odd_even_indicator = data[pos];
9723 break;
9725 if (ie_len != 1) {
9726 ast_log(LOG_WARNING, "Invalid redirecting-from subaddress valid (%u)\n",
9727 (unsigned) ie_len);
9728 break;
9729 }
9730 redirecting->from.subaddress.valid = data[pos];
9731 break;
9732/* Redirecting-from party id tag */
9734 ast_free(redirecting->from.tag);
9735 redirecting->from.tag = ast_malloc(ie_len + 1);
9736 if (redirecting->from.tag) {
9737 memcpy(redirecting->from.tag, data + pos, ie_len);
9738 redirecting->from.tag[ie_len] = 0;
9739 }
9740 break;
9741/* Redirecting-to party id name */
9743 ast_free(redirecting->to.name.str);
9744 redirecting->to.name.str = ast_malloc(ie_len + 1);
9745 if (redirecting->to.name.str) {
9746 memcpy(redirecting->to.name.str, data + pos, ie_len);
9747 redirecting->to.name.str[ie_len] = 0;
9748 }
9749 break;
9751 if (ie_len != 1) {
9752 ast_log(LOG_WARNING, "Invalid redirecting-to name char set (%u)\n",
9753 (unsigned) ie_len);
9754 break;
9755 }
9756 redirecting->to.name.char_set = data[pos];
9757 break;
9759 if (ie_len != 1) {
9760 ast_log(LOG_WARNING, "Invalid redirecting-to name presentation (%u)\n",
9761 (unsigned) ie_len);
9762 break;
9763 }
9764 redirecting->to.name.presentation = data[pos];
9765 break;
9767 if (ie_len != 1) {
9768 ast_log(LOG_WARNING, "Invalid redirecting-to name valid (%u)\n",
9769 (unsigned) ie_len);
9770 break;
9771 }
9772 redirecting->to.name.valid = data[pos];
9773 break;
9774/* Redirecting-to party id number */
9776 ast_free(redirecting->to.number.str);
9777 redirecting->to.number.str = ast_malloc(ie_len + 1);
9778 if (redirecting->to.number.str) {
9779 memcpy(redirecting->to.number.str, data + pos, ie_len);
9780 redirecting->to.number.str[ie_len] = 0;
9781 }
9782 break;
9784 if (ie_len != 1) {
9785 ast_log(LOG_WARNING, "Invalid redirecting-to numbering plan (%u)\n",
9786 (unsigned) ie_len);
9787 break;
9788 }
9789 redirecting->to.number.plan = data[pos];
9790 break;
9792 if (ie_len != 1) {
9793 ast_log(LOG_WARNING, "Invalid redirecting-to number presentation (%u)\n",
9794 (unsigned) ie_len);
9795 break;
9796 }
9797 redirecting->to.number.presentation = data[pos];
9798 break;
9800 if (ie_len != 1) {
9801 ast_log(LOG_WARNING, "Invalid redirecting-to number valid (%u)\n",
9802 (unsigned) ie_len);
9803 break;
9804 }
9805 redirecting->to.number.valid = data[pos];
9806 break;
9807/* Redirecting-to party id combined presentation */
9809 if (ie_len != 1) {
9810 ast_log(LOG_WARNING, "Invalid redirecting-to combined presentation (%u)\n",
9811 (unsigned) ie_len);
9812 break;
9813 }
9814 to_combined_presentation = data[pos];
9815 got_to_combined_presentation = 1;
9816 break;
9817/* Redirecting-to party id subaddress */
9819 ast_free(redirecting->to.subaddress.str);
9820 redirecting->to.subaddress.str = ast_malloc(ie_len + 1);
9821 if (redirecting->to.subaddress.str) {
9822 memcpy(redirecting->to.subaddress.str, data + pos, ie_len);
9823 redirecting->to.subaddress.str[ie_len] = 0;
9824 }
9825 break;
9827 if (ie_len != 1) {
9828 ast_log(LOG_WARNING, "Invalid redirecting-to type of subaddress (%u)\n",
9829 (unsigned) ie_len);
9830 break;
9831 }
9832 redirecting->to.subaddress.type = data[pos];
9833 break;
9835 if (ie_len != 1) {
9837 "Invalid redirecting-to subaddress odd-even indicator (%u)\n",
9838 (unsigned) ie_len);
9839 break;
9840 }
9841 redirecting->to.subaddress.odd_even_indicator = data[pos];
9842 break;
9844 if (ie_len != 1) {
9845 ast_log(LOG_WARNING, "Invalid redirecting-to subaddress valid (%u)\n",
9846 (unsigned) ie_len);
9847 break;
9848 }
9849 redirecting->to.subaddress.valid = data[pos];
9850 break;
9851/* Redirecting-to party id tag */
9853 ast_free(redirecting->to.tag);
9854 redirecting->to.tag = ast_malloc(ie_len + 1);
9855 if (redirecting->to.tag) {
9856 memcpy(redirecting->to.tag, data + pos, ie_len);
9857 redirecting->to.tag[ie_len] = 0;
9858 }
9859 break;
9860/* Private redirecting-orig party id name */
9862 ast_free(redirecting->priv_orig.name.str);
9863 redirecting->priv_orig.name.str = ast_malloc(ie_len + 1);
9864 if (redirecting->priv_orig.name.str) {
9865 memcpy(redirecting->priv_orig.name.str, data + pos, ie_len);
9866 redirecting->priv_orig.name.str[ie_len] = 0;
9867 }
9868 break;
9870 if (ie_len != 1) {
9871 ast_log(LOG_WARNING, "Invalid private redirecting-orig name char set (%u)\n",
9872 (unsigned) ie_len);
9873 break;
9874 }
9875 redirecting->priv_orig.name.char_set = data[pos];
9876 break;
9878 if (ie_len != 1) {
9879 ast_log(LOG_WARNING, "Invalid private redirecting-orig name presentation (%u)\n",
9880 (unsigned) ie_len);
9881 break;
9882 }
9883 redirecting->priv_orig.name.presentation = data[pos];
9884 break;
9886 if (ie_len != 1) {
9887 ast_log(LOG_WARNING, "Invalid private redirecting-orig name valid (%u)\n",
9888 (unsigned) ie_len);
9889 break;
9890 }
9891 redirecting->priv_orig.name.valid = data[pos];
9892 break;
9893/* Private redirecting-orig party id number */
9895 ast_free(redirecting->priv_orig.number.str);
9896 redirecting->priv_orig.number.str = ast_malloc(ie_len + 1);
9897 if (redirecting->priv_orig.number.str) {
9898 memcpy(redirecting->priv_orig.number.str, data + pos, ie_len);
9899 redirecting->priv_orig.number.str[ie_len] = 0;
9900 }
9901 break;
9903 if (ie_len != 1) {
9904 ast_log(LOG_WARNING, "Invalid private redirecting-orig numbering plan (%u)\n",
9905 (unsigned) ie_len);
9906 break;
9907 }
9908 redirecting->priv_orig.number.plan = data[pos];
9909 break;
9911 if (ie_len != 1) {
9912 ast_log(LOG_WARNING, "Invalid private redirecting-orig number presentation (%u)\n",
9913 (unsigned) ie_len);
9914 break;
9915 }
9916 redirecting->priv_orig.number.presentation = data[pos];
9917 break;
9919 if (ie_len != 1) {
9920 ast_log(LOG_WARNING, "Invalid private redirecting-orig number valid (%u)\n",
9921 (unsigned) ie_len);
9922 break;
9923 }
9924 redirecting->priv_orig.number.valid = data[pos];
9925 break;
9926/* Private redirecting-orig party id subaddress */
9928 ast_free(redirecting->priv_orig.subaddress.str);
9929 redirecting->priv_orig.subaddress.str = ast_malloc(ie_len + 1);
9930 if (redirecting->priv_orig.subaddress.str) {
9931 memcpy(redirecting->priv_orig.subaddress.str, data + pos, ie_len);
9932 redirecting->priv_orig.subaddress.str[ie_len] = 0;
9933 }
9934 break;
9936 if (ie_len != 1) {
9937 ast_log(LOG_WARNING, "Invalid private redirecting-orig type of subaddress (%u)\n",
9938 (unsigned) ie_len);
9939 break;
9940 }
9941 redirecting->priv_orig.subaddress.type = data[pos];
9942 break;
9944 if (ie_len != 1) {
9946 "Invalid private redirecting-orig subaddress odd-even indicator (%u)\n",
9947 (unsigned) ie_len);
9948 break;
9949 }
9950 redirecting->priv_orig.subaddress.odd_even_indicator = data[pos];
9951 break;
9953 if (ie_len != 1) {
9954 ast_log(LOG_WARNING, "Invalid private redirecting-orig subaddress valid (%u)\n",
9955 (unsigned) ie_len);
9956 break;
9957 }
9958 redirecting->priv_orig.subaddress.valid = data[pos];
9959 break;
9960/* Private redirecting-orig party id tag */
9962 ast_free(redirecting->priv_orig.tag);
9963 redirecting->priv_orig.tag = ast_malloc(ie_len + 1);
9964 if (redirecting->priv_orig.tag) {
9965 memcpy(redirecting->priv_orig.tag, data + pos, ie_len);
9966 redirecting->priv_orig.tag[ie_len] = 0;
9967 }
9968 break;
9969/* Private redirecting-from party id name */
9971 ast_free(redirecting->priv_from.name.str);
9972 redirecting->priv_from.name.str = ast_malloc(ie_len + 1);
9973 if (redirecting->priv_from.name.str) {
9974 memcpy(redirecting->priv_from.name.str, data + pos, ie_len);
9975 redirecting->priv_from.name.str[ie_len] = 0;
9976 }
9977 break;
9979 if (ie_len != 1) {
9980 ast_log(LOG_WARNING, "Invalid private redirecting-from name char set (%u)\n",
9981 (unsigned) ie_len);
9982 break;
9983 }
9984 redirecting->priv_from.name.char_set = data[pos];
9985 break;
9987 if (ie_len != 1) {
9988 ast_log(LOG_WARNING, "Invalid private redirecting-from name presentation (%u)\n",
9989 (unsigned) ie_len);
9990 break;
9991 }
9992 redirecting->priv_from.name.presentation = data[pos];
9993 break;
9995 if (ie_len != 1) {
9996 ast_log(LOG_WARNING, "Invalid private redirecting-from name valid (%u)\n",
9997 (unsigned) ie_len);
9998 break;
9999 }
10000 redirecting->priv_from.name.valid = data[pos];
10001 break;
10002/* Private redirecting-from party id number */
10004 ast_free(redirecting->priv_from.number.str);
10005 redirecting->priv_from.number.str = ast_malloc(ie_len + 1);
10006 if (redirecting->priv_from.number.str) {
10007 memcpy(redirecting->priv_from.number.str, data + pos, ie_len);
10008 redirecting->priv_from.number.str[ie_len] = 0;
10009 }
10010 break;
10012 if (ie_len != 1) {
10013 ast_log(LOG_WARNING, "Invalid private redirecting-from numbering plan (%u)\n",
10014 (unsigned) ie_len);
10015 break;
10016 }
10017 redirecting->priv_from.number.plan = data[pos];
10018 break;
10020 if (ie_len != 1) {
10021 ast_log(LOG_WARNING, "Invalid private redirecting-from number presentation (%u)\n",
10022 (unsigned) ie_len);
10023 break;
10024 }
10025 redirecting->priv_from.number.presentation = data[pos];
10026 break;
10028 if (ie_len != 1) {
10029 ast_log(LOG_WARNING, "Invalid private redirecting-from number valid (%u)\n",
10030 (unsigned) ie_len);
10031 break;
10032 }
10033 redirecting->priv_from.number.valid = data[pos];
10034 break;
10035/* Private redirecting-from party id subaddress */
10037 ast_free(redirecting->priv_from.subaddress.str);
10038 redirecting->priv_from.subaddress.str = ast_malloc(ie_len + 1);
10039 if (redirecting->priv_from.subaddress.str) {
10040 memcpy(redirecting->priv_from.subaddress.str, data + pos, ie_len);
10041 redirecting->priv_from.subaddress.str[ie_len] = 0;
10042 }
10043 break;
10045 if (ie_len != 1) {
10046 ast_log(LOG_WARNING, "Invalid private redirecting-from type of subaddress (%u)\n",
10047 (unsigned) ie_len);
10048 break;
10049 }
10050 redirecting->priv_from.subaddress.type = data[pos];
10051 break;
10053 if (ie_len != 1) {
10055 "Invalid private redirecting-from subaddress odd-even indicator (%u)\n",
10056 (unsigned) ie_len);
10057 break;
10058 }
10059 redirecting->priv_from.subaddress.odd_even_indicator = data[pos];
10060 break;
10062 if (ie_len != 1) {
10063 ast_log(LOG_WARNING, "Invalid private redirecting-from subaddress valid (%u)\n",
10064 (unsigned) ie_len);
10065 break;
10066 }
10067 redirecting->priv_from.subaddress.valid = data[pos];
10068 break;
10069/* Private redirecting-from party id tag */
10071 ast_free(redirecting->priv_from.tag);
10072 redirecting->priv_from.tag = ast_malloc(ie_len + 1);
10073 if (redirecting->priv_from.tag) {
10074 memcpy(redirecting->priv_from.tag, data + pos, ie_len);
10075 redirecting->priv_from.tag[ie_len] = 0;
10076 }
10077 break;
10078/* Private redirecting-to party id name */
10080 ast_free(redirecting->priv_to.name.str);
10081 redirecting->priv_to.name.str = ast_malloc(ie_len + 1);
10082 if (redirecting->priv_to.name.str) {
10083 memcpy(redirecting->priv_to.name.str, data + pos, ie_len);
10084 redirecting->priv_to.name.str[ie_len] = 0;
10085 }
10086 break;
10088 if (ie_len != 1) {
10089 ast_log(LOG_WARNING, "Invalid private redirecting-to name char set (%u)\n",
10090 (unsigned) ie_len);
10091 break;
10092 }
10093 redirecting->priv_to.name.char_set = data[pos];
10094 break;
10096 if (ie_len != 1) {
10097 ast_log(LOG_WARNING, "Invalid private redirecting-to name presentation (%u)\n",
10098 (unsigned) ie_len);
10099 break;
10100 }
10101 redirecting->priv_to.name.presentation = data[pos];
10102 break;
10104 if (ie_len != 1) {
10105 ast_log(LOG_WARNING, "Invalid private redirecting-to name valid (%u)\n",
10106 (unsigned) ie_len);
10107 break;
10108 }
10109 redirecting->priv_to.name.valid = data[pos];
10110 break;
10111/* Private redirecting-to party id number */
10113 ast_free(redirecting->priv_to.number.str);
10114 redirecting->priv_to.number.str = ast_malloc(ie_len + 1);
10115 if (redirecting->priv_to.number.str) {
10116 memcpy(redirecting->priv_to.number.str, data + pos, ie_len);
10117 redirecting->priv_to.number.str[ie_len] = 0;
10118 }
10119 break;
10121 if (ie_len != 1) {
10122 ast_log(LOG_WARNING, "Invalid private redirecting-to numbering plan (%u)\n",
10123 (unsigned) ie_len);
10124 break;
10125 }
10126 redirecting->priv_to.number.plan = data[pos];
10127 break;
10129 if (ie_len != 1) {
10130 ast_log(LOG_WARNING, "Invalid private redirecting-to number presentation (%u)\n",
10131 (unsigned) ie_len);
10132 break;
10133 }
10134 redirecting->priv_to.number.presentation = data[pos];
10135 break;
10137 if (ie_len != 1) {
10138 ast_log(LOG_WARNING, "Invalid private redirecting-to number valid (%u)\n",
10139 (unsigned) ie_len);
10140 break;
10141 }
10142 redirecting->priv_to.number.valid = data[pos];
10143 break;
10144/* Private redirecting-to party id subaddress */
10146 ast_free(redirecting->priv_to.subaddress.str);
10147 redirecting->priv_to.subaddress.str = ast_malloc(ie_len + 1);
10148 if (redirecting->priv_to.subaddress.str) {
10149 memcpy(redirecting->priv_to.subaddress.str, data + pos, ie_len);
10150 redirecting->priv_to.subaddress.str[ie_len] = 0;
10151 }
10152 break;
10154 if (ie_len != 1) {
10155 ast_log(LOG_WARNING, "Invalid private redirecting-to type of subaddress (%u)\n",
10156 (unsigned) ie_len);
10157 break;
10158 }
10159 redirecting->priv_to.subaddress.type = data[pos];
10160 break;
10162 if (ie_len != 1) {
10164 "Invalid private redirecting-to subaddress odd-even indicator (%u)\n",
10165 (unsigned) ie_len);
10166 break;
10167 }
10168 redirecting->priv_to.subaddress.odd_even_indicator = data[pos];
10169 break;
10171 if (ie_len != 1) {
10172 ast_log(LOG_WARNING, "Invalid private redirecting-to subaddress valid (%u)\n",
10173 (unsigned) ie_len);
10174 break;
10175 }
10176 redirecting->priv_to.subaddress.valid = data[pos];
10177 break;
10178/* Private redirecting-to party id tag */
10180 ast_free(redirecting->priv_to.tag);
10181 redirecting->priv_to.tag = ast_malloc(ie_len + 1);
10182 if (redirecting->priv_to.tag) {
10183 memcpy(redirecting->priv_to.tag, data + pos, ie_len);
10184 redirecting->priv_to.tag[ie_len] = 0;
10185 }
10186 break;
10187/* Redirecting reason code */
10189 if (ie_len != sizeof(value)) {
10190 ast_log(LOG_WARNING, "Invalid redirecting reason (%u)\n",
10191 (unsigned) ie_len);
10192 break;
10193 }
10194 memcpy(&value, data + pos, sizeof(value));
10195 redirecting->reason.code = ntohl(value);
10196 break;
10197/* Redirecting reason string */
10199 ast_free(redirecting->reason.str);
10200 redirecting->reason.str = ast_malloc(ie_len + 1);
10201 if (redirecting->reason.str) {
10202 memcpy(redirecting->reason.str, data + pos, ie_len);
10203 redirecting->reason.str[ie_len] = 0;
10204 }
10205 break;
10206/* Redirecting orig-reason code */
10208 if (ie_len != sizeof(value)) {
10209 ast_log(LOG_WARNING, "Invalid redirecting original reason (%u)\n",
10210 (unsigned) ie_len);
10211 break;
10212 }
10213 memcpy(&value, data + pos, sizeof(value));
10214 redirecting->orig_reason.code = ntohl(value);
10215 break;
10216/* Redirecting orig-reason string */
10218 ast_free(redirecting->orig_reason.str);
10219 redirecting->orig_reason.str = ast_malloc(ie_len + 1);
10220 if (redirecting->orig_reason.str) {
10221 memcpy(redirecting->orig_reason.str, data + pos, ie_len);
10222 redirecting->orig_reason.str[ie_len] = 0;
10223 }
10224 break;
10225/* Redirecting count */
10227 if (ie_len != sizeof(value)) {
10228 ast_log(LOG_WARNING, "Invalid redirecting count (%u)\n",
10229 (unsigned) ie_len);
10230 break;
10231 }
10232 memcpy(&value, data + pos, sizeof(value));
10233 redirecting->count = ntohl(value);
10234 break;
10235/* Redirecting unknown element */
10236 default:
10237 ast_debug(1, "Unknown redirecting element: %u (%u)\n",
10238 (unsigned) ie_id, (unsigned) ie_len);
10239 break;
10240 }
10241 }
10242
10243 switch (frame_version) {
10244 case 1:
10245 /*
10246 * The other end is an earlier version that we need to adjust
10247 * for compatibility.
10248 *
10249 * The earlier version did not have the orig party id or
10250 * orig_reason value.
10251 */
10252 redirecting->from.name.valid = 1;
10254 redirecting->from.number.valid = 1;
10255 if (got_from_combined_presentation) {
10256 redirecting->from.name.presentation = from_combined_presentation;
10257 redirecting->from.number.presentation = from_combined_presentation;
10258 }
10259
10260 redirecting->to.name.valid = 1;
10262 redirecting->to.number.valid = 1;
10263 if (got_to_combined_presentation) {
10264 redirecting->to.name.presentation = to_combined_presentation;
10265 redirecting->to.number.presentation = to_combined_presentation;
10266 }
10267 break;
10268 case 2:
10269 /* The other end is at the same level as we are. */
10270 break;
10271 default:
10272 /*
10273 * The other end is newer than we are.
10274 * We need to assume that they are compatible with us.
10275 */
10276 ast_debug(1, "Redirecting frame has newer version: %u\n",
10277 (unsigned) frame_version);
10278 break;
10279 }
10280
10281 return 0;
10282}
10283
10285{
10286 unsigned char data[1024]; /* This should be large enough */
10287 size_t datalen;
10288
10289 datalen = ast_redirecting_build_data(data, sizeof(data), redirecting, update);
10290 if (datalen == (size_t) -1) {
10291 return;
10292 }
10293
10294 ast_indicate_data(chan, AST_CONTROL_REDIRECTING, data, datalen);
10295}
10296
10298{
10299 unsigned char data[1024]; /* This should be large enough */
10300 size_t datalen;
10301
10302 datalen = ast_redirecting_build_data(data, sizeof(data), redirecting, update);
10303 if (datalen == (size_t) -1) {
10304 return;
10305 }
10306
10307 ast_queue_control_data(chan, AST_CONTROL_REDIRECTING, data, datalen);
10308}
10309
10310/*!
10311 * Storage to determine if the current thread is running an intercept dialplan routine.
10312 */
10313AST_THREADSTORAGE_RAW(in_intercept_routine);
10314
10315/*!
10316 * \internal
10317 * \brief Set the current intercept dialplan routine status mode.
10318 * \since 13.14.0
10319 *
10320 * \param in_intercept_mode New intercept mode. (Non-zero if in intercept mode)
10321 */
10322static void channel_set_intercept_mode(int in_intercept_mode)
10323{
10324 int status;
10325
10326 status = ast_threadstorage_set_ptr(&in_intercept_routine,
10327 in_intercept_mode ? &(int) { 1 } : NULL);
10328 if (status) {
10329 ast_log(LOG_ERROR, "Failed to set dialplan intercept mode\n");
10330 }
10331}
10332
10334{
10335 return ast_threadstorage_get_ptr(&in_intercept_routine) ? 1 : 0;
10336}
10337
10338int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int is_frame)
10339{
10340 const char *sub;
10341 const char *sub_args;
10342 int retval;
10343
10344 ast_channel_lock(sub_chan);
10345 sub = pbx_builtin_getvar_helper(sub_chan, "CONNECTED_LINE_SEND_SUB");
10346 sub = ast_strdupa(S_OR(sub, ""));
10347 sub_args = pbx_builtin_getvar_helper(sub_chan, "CONNECTED_LINE_SEND_SUB_ARGS");
10348 sub_args = ast_strdupa(S_OR(sub_args, ""));
10349
10350 if (ast_strlen_zero(sub)) {
10351 ast_channel_unlock(sub_chan);
10352 return -1;
10353 }
10354
10355 if (is_frame) {
10356 const struct ast_frame *frame = connected_info;
10357
10359 } else {
10360 const struct ast_party_connected_line *connected = connected_info;
10361
10363 }
10364 ast_channel_unlock(sub_chan);
10365
10367 retval = ast_app_run_sub(autoservice_chan, sub_chan, sub, sub_args, 0);
10369 if (!retval) {
10370 struct ast_party_connected_line saved_connected;
10371
10372 ast_party_connected_line_init(&saved_connected);
10373 ast_channel_lock(sub_chan);
10374 ast_party_connected_line_copy(&saved_connected, ast_channel_connected(sub_chan));
10375 ast_channel_unlock(sub_chan);
10376 ast_channel_update_connected_line(sub_chan, &saved_connected, NULL);
10377 ast_party_connected_line_free(&saved_connected);
10378 }
10379
10380 return retval;
10381}
10382
10383int ast_channel_redirecting_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *redirecting_info, int is_frame)
10384{
10385 const char *sub;
10386 const char *sub_args;
10387 int retval;
10388
10389 ast_channel_lock(sub_chan);
10390 sub = pbx_builtin_getvar_helper(sub_chan, "REDIRECTING_SEND_SUB");
10391 sub = ast_strdupa(S_OR(sub, ""));
10392 sub_args = pbx_builtin_getvar_helper(sub_chan, "REDIRECTING_SEND_SUB_ARGS");
10393 sub_args = ast_strdupa(S_OR(sub_args, ""));
10394
10395 if (ast_strlen_zero(sub)) {
10396 ast_channel_unlock(sub_chan);
10397 return -1;
10398 }
10399
10400 if (is_frame) {
10401 const struct ast_frame *frame = redirecting_info;
10402
10404 } else {
10405 const struct ast_party_redirecting *redirecting = redirecting_info;
10406
10408 }
10409 ast_channel_unlock(sub_chan);
10410
10412 retval = ast_app_run_sub(autoservice_chan, sub_chan, sub, sub_args, 0);
10414 if (!retval) {
10415 struct ast_party_redirecting saved_redirecting;
10416
10417 ast_party_redirecting_init(&saved_redirecting);
10418 ast_channel_lock(sub_chan);
10419 ast_party_redirecting_copy(&saved_redirecting, ast_channel_redirecting(sub_chan));
10420 ast_channel_unlock(sub_chan);
10421 ast_channel_update_redirecting(sub_chan, &saved_redirecting, NULL);
10422 ast_party_redirecting_free(&saved_redirecting);
10423 }
10424
10425 return retval;
10426}
10427
10428static void *channel_cc_params_copy(void *data)
10429{
10430 const struct ast_cc_config_params *src = data;
10432 if (!dest) {
10433 return NULL;
10434 }
10435 ast_cc_copy_config_params(dest, src);
10436 return dest;
10437}
10438
10439static void channel_cc_params_destroy(void *data)
10440{
10441 struct ast_cc_config_params *cc_params = data;
10443}
10444
10446 .type = "Call Completion",
10447 .duplicate = channel_cc_params_copy,
10448 .destroy = channel_cc_params_destroy,
10449};
10450
10452 const struct ast_cc_config_params *base_params)
10453{
10454 struct ast_cc_config_params *cc_params;
10455 struct ast_datastore *cc_datastore;
10456
10457 if (!(cc_params = ast_cc_config_params_init())) {
10458 return -1;
10459 }
10460
10461 if (!(cc_datastore = ast_datastore_alloc(&cc_channel_datastore_info, NULL))) {
10463 return -1;
10464 }
10465
10466 if (base_params) {
10467 ast_cc_copy_config_params(cc_params, base_params);
10468 }
10469 cc_datastore->data = cc_params;
10470 ast_channel_datastore_add(chan, cc_datastore);
10471 return 0;
10472}
10473
10475{
10476 struct ast_datastore *cc_datastore;
10477
10478 if (!(cc_datastore = ast_channel_datastore_find(chan, &cc_channel_datastore_info, NULL))) {
10479 /* If we can't find the datastore, it almost definitely means that the channel type being
10480 * used has not had its driver modified to parse CC config parameters. The best action
10481 * to take here is to create the parameters on the spot with the defaults set.
10482 */
10483 if (ast_channel_cc_params_init(chan, NULL)) {
10484 return NULL;
10485 }
10486 if (!(cc_datastore = ast_channel_datastore_find(chan, &cc_channel_datastore_info, NULL))) {
10487 /* Should be impossible */
10488 return NULL;
10489 }
10490 }
10491
10492 ast_assert(cc_datastore->data != NULL);
10493 return cc_datastore->data;
10494}
10495
10496int ast_channel_get_device_name(struct ast_channel *chan, char *device_name, size_t name_buffer_length)
10497{
10498 int len = name_buffer_length;
10499 char *dash;
10500 if (!ast_channel_queryoption(chan, AST_OPTION_DEVICE_NAME, device_name, &len, 0)) {
10501 return 0;
10502 }
10503
10504 /* Dang. Do it the old-fashioned way */
10505 ast_copy_string(device_name, ast_channel_name(chan), name_buffer_length);
10506 if ((dash = strrchr(device_name, '-'))) {
10507 *dash = '\0';
10508 }
10509
10510 return 0;
10511}
10512
10513int ast_channel_get_cc_agent_type(struct ast_channel *chan, char *agent_type, size_t size)
10514{
10515 int len = size;
10516 char *slash;
10517
10519 return 0;
10520 }
10521
10523 if ((slash = strchr(agent_type, '/'))) {
10524 *slash = '\0';
10525 }
10526 return 0;
10527}
10528
10530{
10531 ao2_unlink(channels, chan);
10532}
10533
10535{
10536 struct ast_bridge *bridge;
10537
10538 bridge = ast_channel_internal_bridge(chan);
10539 if (bridge) {
10540 ao2_ref(bridge, +1);
10541 }
10542 return bridge;
10543}
10544
10546{
10547 return ast_channel_internal_bridge(chan) != NULL;
10548}
10549
10551{
10552 int hangup_flags = ast_channel_softhangup_internal_flag(chan);
10553 int hangup_test = hangup_flags & AST_SOFTHANGUP_ASYNCGOTO;
10554 int unbridge = ast_channel_unbridged(chan);
10555
10556 /* This function should only return true if either the unbridged flag or
10557 * the ASYNCGOTO soft hangup flag is set and when no other soft hangup
10558 * flags are set. Any other soft hangup flags being set should make it
10559 * return false.
10560 */
10561 return ((hangup_test || unbridge) && (hangup_test == hangup_flags));
10562}
10563
10565{
10566 struct ast_channel *peer;
10567 struct ast_bridge *bridge;
10568
10569 /* Get the bridge the channel is in. */
10570 ast_channel_lock(chan);
10571 bridge = ast_channel_get_bridge(chan);
10572 ast_channel_unlock(chan);
10573 if (!bridge) {
10574 return NULL;
10575 }
10576
10577 peer = ast_bridge_peer(bridge, chan);
10578 ao2_ref(bridge, -1);
10579 return peer;
10580}
10581
10583{
10584 struct ast_bridge_channel *bridge_channel;
10585
10586 bridge_channel = ast_channel_internal_bridge_channel(chan);
10587 if (bridge_channel) {
10588 ao2_ref(bridge_channel, +1);
10589 }
10590 return bridge_channel;
10591}
10592
10594{
10595 struct ast_channel *yanked_chan;
10596 struct {
10597 char *accountcode;
10598 char *exten;
10599 char *context;
10600 char *name;
10601 int amaflags;
10602 int priority;
10603 struct ast_format *readformat;
10604 struct ast_format *writeformat;
10605 } my_vars = { 0, };
10606
10607 ast_channel_lock(yankee);
10608 my_vars.accountcode = ast_strdupa(ast_channel_accountcode(yankee));
10609 my_vars.exten = ast_strdupa(ast_channel_exten(yankee));
10610 my_vars.context = ast_strdupa(ast_channel_context(yankee));
10611 my_vars.name = ast_strdupa(ast_channel_name(yankee));
10612 my_vars.amaflags = ast_channel_amaflags(yankee);
10613 my_vars.priority = ast_channel_priority(yankee);
10614 /* The priority as returned by ast_channel_yank is where the channel
10615 * should go if the dialplan is executed on it. If the channel is
10616 * already executing dialplan then the priority currently set is
10617 * where it is currently. We increment it so it becomes where it should
10618 * execute.
10619 */
10621 my_vars.priority++;
10622 }
10623 my_vars.writeformat = ao2_bump(ast_channel_writeformat(yankee));
10624 my_vars.readformat = ao2_bump(ast_channel_readformat(yankee));
10625 ast_channel_unlock(yankee);
10626
10627 /* Do not hold any channel locks while calling channel_alloc() since the function
10628 * locks the channel container when linking the new channel in. */
10629 if (!(yanked_chan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, my_vars.accountcode,
10630 my_vars.exten, my_vars.context, NULL, yankee, my_vars.amaflags,
10631 "Surrogate/%s", my_vars.name))) {
10632 ao2_cleanup(my_vars.writeformat);
10633 ao2_cleanup(my_vars.readformat);
10634 return NULL;
10635 }
10636
10637 /* Make formats okay */
10638 ast_channel_set_readformat(yanked_chan, my_vars.readformat);
10639 ast_channel_set_writeformat(yanked_chan, my_vars.writeformat);
10640 ao2_cleanup(my_vars.readformat);
10641 ao2_cleanup(my_vars.writeformat);
10642 ast_channel_priority_set(yanked_chan, my_vars.priority);
10643
10644 ast_channel_unlock(yanked_chan);
10645
10646 if (ast_channel_move(yanked_chan, yankee)) {
10647 ast_hangup(yanked_chan);
10648 return NULL;
10649 }
10650
10651 return yanked_chan;
10652}
10653
10654/*!
10655 * Mutex that prevents multiple ast_channel_move() operations
10656 * from occurring simultaneously. This is necessary since the
10657 * involved channels have to be locked and unlocked throughout
10658 * the move operation.
10659 *
10660 * The most important data being protected are the masq and masqr
10661 * data on channels. We don't want them getting criss-crossed due
10662 * to multiple moves mucking with them.
10663 */
10665
10666int ast_channel_move(struct ast_channel *dest, struct ast_channel *source)
10667{
10668 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
10670
10671 if (dest == source) {
10672 ast_log(LOG_WARNING, "Can't move channel '%s' into itself!\n",
10673 ast_channel_name(dest));
10674 return -1;
10675 }
10676
10677 ast_channel_lock_both(dest, source);
10678
10681 /* Zombies! Run! */
10683 "Can't move channel. One or both is dead (%s <-- %s)\n",
10684 ast_channel_name(dest), ast_channel_name(source));
10685 ast_channel_unlock(source);
10686 ast_channel_unlock(dest);
10687 return -1;
10688 }
10689
10690 ast_channel_masq_set(dest, source);
10691 ast_channel_masqr_set(source, dest);
10692
10693 blob = ast_json_pack("{s: s}",
10694 "newchanneluniqueid", ast_channel_uniqueid(dest));
10696
10697 ast_channel_unlock(dest);
10698 ast_channel_unlock(source);
10699
10700 channel_do_masquerade(dest, source);
10701 return 0;
10702}
10703
10704static void suppress_datastore_destroy_cb(void *data)
10705{
10706 ao2_cleanup(data);
10707}
10708
10710 .type = "suppressvoice",
10712};
10713
10714static void suppress_framehook_destroy_cb(void *data)
10715{
10716 ao2_cleanup(data);
10717}
10718
10721 unsigned int direction;
10723};
10724
10725static void suppress_framehook_fixup_cb(void *data, int framehook_id, struct ast_channel *old_chan, struct ast_channel *new_chan)
10726{
10727 struct suppress_data *suppress = data;
10728
10729 suppress->framehook_id = framehook_id;
10730}
10731
10732static struct ast_frame *suppress_framehook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
10733{
10734 struct suppress_data *suppress = data;
10735 int suppress_frame = 0;
10736
10737 if (!frame) {
10738 return NULL;
10739 }
10740
10741 if (frame->frametype != suppress->frametype) {
10742 return frame;
10743 }
10744
10746 suppress_frame = 1;
10747 } else if (event == AST_FRAMEHOOK_EVENT_WRITE && (suppress->direction & AST_MUTE_DIRECTION_WRITE)) {
10748 suppress_frame = 1;
10749 }
10750
10751 if (suppress_frame) {
10752 switch (frame->frametype) {
10753 case AST_FRAME_VOICE:
10755 ast_frfree(frame);
10756 }
10757 frame = &ast_null_frame;
10758 break;
10759 default:
10760 break;
10761 }
10762 }
10763
10764 return frame;
10765}
10766
10768{
10769 switch (frametype) {
10770 case AST_FRAME_VOICE:
10772 default:
10773 return NULL;
10774 }
10775}
10776
10777int ast_channel_suppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
10778{
10779 struct suppress_data *suppress;
10780 const struct ast_datastore_info *datastore_info = NULL;
10781 struct ast_datastore *datastore = NULL;
10782 struct ast_framehook_interface interface = {
10784 .event_cb = suppress_framehook_event_cb,
10785 .destroy_cb = suppress_framehook_destroy_cb,
10786 .chan_fixup_cb = suppress_framehook_fixup_cb,
10787 };
10788 int framehook_id;
10789
10790 if (!(datastore_info = suppress_get_datastore_information(frametype))) {
10791 ast_log(LOG_WARNING, "Attempted to suppress an unsupported frame type (%u).\n", frametype);
10792 return -1;
10793 }
10794
10795 if ((datastore = ast_channel_datastore_find(chan, datastore_info, NULL))) {
10796 suppress = datastore->data;
10797 suppress->direction |= direction;
10798 return 0;
10799 }
10800
10801 if (!(suppress = ao2_alloc(sizeof(*suppress), NULL))) {
10802 ast_log(LOG_WARNING, "Failed to allocate data while attempting to suppress a stream.\n");
10803 return -1;
10804 }
10805
10806 suppress->frametype = frametype;
10807 suppress->direction |= direction;
10808
10809 interface.data = suppress;
10810
10811 framehook_id = ast_framehook_attach(chan, &interface);
10812 if (framehook_id < 0) {
10813 /* Hook attach failed. Get rid of the evidence. */
10814 ast_log(LOG_WARNING, "Failed to attach framehook while attempting to suppress a stream.\n");
10815 ao2_ref(suppress, -1);
10816 return -1;
10817 }
10818
10819 /* One ref for the framehook */
10820 ao2_ref(suppress, +1);
10821
10822 suppress->framehook_id = framehook_id;
10823
10824 if (!(datastore = ast_datastore_alloc(datastore_info, NULL))) {
10825 ast_log(LOG_WARNING, "Failed to allocate datastore while attempting to suppress a stream.\n");
10826 ast_framehook_detach(chan, framehook_id);
10827 ao2_ref(suppress, -1);
10828 return -1;
10829 }
10830
10831 /* the ref provided by the allocation is taken by the datastore */
10832 datastore->data = suppress;
10833
10834 ast_channel_datastore_add(chan, datastore);
10835
10836 return 0;
10837}
10838
10839int ast_channel_unsuppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
10840{
10841 const struct ast_datastore_info *datastore_info = NULL;
10842 struct ast_datastore *datastore = NULL;
10843 struct suppress_data *suppress;
10844
10845 if (!(datastore_info = suppress_get_datastore_information(frametype))) {
10846 ast_log(LOG_WARNING, "Attempted to unsuppress an unsupported frame type (%u).\n", frametype);
10847 return -1;
10848 }
10849
10850 if (!(datastore = ast_channel_datastore_find(chan, datastore_info, NULL))) {
10851 /* Nothing to do! */
10852 return 0;
10853 }
10854
10855 suppress = datastore->data;
10856
10857 suppress->direction &= ~(direction);
10858
10859 if (suppress->direction == 0) {
10860 /* Nothing left to suppress. Bye! */
10861 ast_framehook_detach(chan, suppress->framehook_id);
10862 ast_channel_datastore_remove(chan, datastore);
10863 ast_datastore_free(datastore);
10864 }
10865
10866 return 0;
10867}
10868
10869void ast_channel_end_dtmf(struct ast_channel *chan, char digit, struct timeval start, const char *why)
10870{
10871 int dead;
10872 long duration;
10873
10874 ast_channel_lock(chan);
10877 & ~AST_SOFTHANGUP_ASYNCGOTO);
10878 ast_channel_unlock(chan);
10879 if (dead) {
10880 /* Channel is a zombie or a real hangup. */
10881 return;
10882 }
10883
10884 duration = ast_tvdiff_ms(ast_tvnow(), start);
10885 if (duration < option_dtmfminduration) {
10886 duration = option_dtmfminduration;
10887 }
10888 ast_senddigit_end(chan, digit, duration);
10889 ast_log(LOG_DTMF, "DTMF end '%c' simulated on %s due to %s, duration %ld ms\n",
10890 digit, ast_channel_name(chan), why, duration);
10891}
10892
10893static void features_destroy(void *obj)
10894{
10896}
10897
10899 .type = "bridge-features",
10900 .destroy = features_destroy,
10901};
10902
10904{
10905 struct ast_datastore *datastore;
10906
10908 if (!datastore) {
10909 return NULL;
10910 }
10911 return datastore->data;
10912}
10913
10914static int channel_feature_hooks_set_full(struct ast_channel *chan, struct ast_bridge_features *features, int replace)
10915{
10916 struct ast_datastore *datastore;
10917 struct ast_bridge_features *ds_features;
10918
10920 if (datastore) {
10921 ds_features = datastore->data;
10922 if (replace) {
10923 ast_bridge_features_cleanup(ds_features);
10924 ast_bridge_features_init(ds_features);
10925 }
10926 if (features) {
10927 ast_bridge_features_merge(ds_features, features);
10928 }
10929 return 0;
10930 }
10931
10933 if (!datastore) {
10934 return -1;
10935 }
10936
10937 ds_features = ast_bridge_features_new();
10938 if (!ds_features) {
10939 ast_datastore_free(datastore);
10940 return -1;
10941 }
10942
10943 if (features) {
10944 ast_bridge_features_merge(ds_features, features);
10945 }
10946 datastore->data = ds_features;
10947 ast_channel_datastore_add(chan, datastore);
10948 return 0;
10949}
10950
10952{
10953 return channel_feature_hooks_set_full(chan, features, 0);
10954}
10955
10957{
10958 return channel_feature_hooks_set_full(chan, features, 1);
10959}
10960
10962{
10964}
10965
10967 struct ast_stream_topology *topology, void *change_source)
10968{
10969 int res;
10970
10971 ast_assert(chan != NULL);
10972 ast_assert(topology != NULL);
10973
10974 ast_channel_lock(chan);
10976 ast_channel_unlock(chan);
10977 return -1;
10978 }
10979
10981 ast_debug(2, "%s: Topologies already match. Current: %s Requested: %s\n",
10982 ast_channel_name(chan),
10984 ast_str_tmp(256, ast_stream_topology_to_str(topology, &STR_TMP)));
10985 ast_channel_unlock(chan);
10986 return 0;
10987 }
10988
10990
10991 res = ast_channel_tech(chan)->indicate(chan, AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE, topology, sizeof(topology));
10992 ast_channel_unlock(chan);
10993 return res;
10994}
10995
10997{
10998 ast_assert(chan != NULL);
10999 ast_assert(topology != NULL);
11000
11002 return -1;
11003 }
11004
11005 return ast_channel_tech(chan)->indicate(chan, AST_CONTROL_STREAM_TOPOLOGY_CHANGED, topology, sizeof(topology));
11006}
11007
11009{
11010 int res;
11011 struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_STREAM_TOPOLOGY_CHANGED };
11012
11013 ast_assert(chan != NULL);
11014
11015 if (!ast_channel_is_multistream(chan)) {
11016 return -1;
11017 }
11018
11019 ast_channel_lock(chan);
11021 res = ast_queue_frame(chan, &f);
11022 ast_channel_unlock(chan);
11023
11024 return res;
11025}
11026
11027void ast_channel_set_flag(struct ast_channel *chan, unsigned int flag)
11028{
11029 ast_channel_lock(chan);
11031 ast_channel_unlock(chan);
11032}
11033
11034void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
11035{
11036 ast_channel_lock(chan);
11038 ast_channel_unlock(chan);
11039}
Prototypes for public functions only of internal interest,.
void ast_jb_destroy(struct ast_channel *chan)
Destroys jitterbuffer on a channel.
Definition: abstract_jb.c:502
@ AST_ALERT_READ_FATAL
Definition: alertpipe.h:28
static struct aco_type agent_type
char digit
static struct ast_generator gen
jack_status_t status
Definition: app_jack.c:146
const char * str
Definition: app_jack.c:147
char * text
Definition: app_queue.c:1639
enum queue_result id
Definition: app_queue.c:1638
struct sla_ringing_trunk * first
Definition: app_sla.c:332
ast_cond_t cond
Definition: app_sla.c:330
ast_mutex_t lock
Definition: app_sla.c:331
#define var
Definition: ast_expr2f.c:605
Asterisk main include file. File version handling, generic pbx functions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
int ast_shutting_down(void)
Definition: asterisk.c:1872
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
#define ast_free(a)
Definition: astmm.h:180
#define ast_strndup(str, len)
A wrapper for strndup()
Definition: astmm.h:256
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
#define ast_log
Definition: astobj2.c:42
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532
@ CMP_MATCH
Definition: astobj2.h:1027
@ CMP_STOP
Definition: astobj2.h:1028
#define OBJ_KEY
Definition: astobj2.h:1151
#define OBJ_POINTER
Definition: astobj2.h:1150
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
void ao2_container_unregister(const char *name)
Unregister a container for CLI stats and integrity check.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_callback_data(container, flags, cb_fn, arg, data)
Definition: astobj2.h:1723
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition: astobj2.h:1578
#define ao2_link_flags(container, obj, flags)
Add an object to a container.
Definition: astobj2.h:1554
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition: astobj2.h:501
#define ao2_lock(a)
Definition: astobj2.h:717
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:404
int ao2_container_register(const char *name, struct ao2_container *self, ao2_prnt_obj_fn *prnt_obj)
Register a container for CLI stats and integrity check.
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
int() ao2_callback_data_fn(void *obj, void *arg, void *data, int flags)
Type of a generic callback function.
Definition: astobj2.h:1244
@ OBJ_NOLOCK
Assume that the ao2_container is already locked.
Definition: astobj2.h:1063
@ OBJ_NODATA
Definition: astobj2.h:1044
@ OBJ_MULTIPLE
Definition: astobj2.h:1049
@ OBJ_UNLINK
Definition: astobj2.h:1039
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
void() ao2_prnt_fn(void *where, const char *fmt,...)
Print output.
Definition: astobj2.h:1435
Audiohooks Architecture.
struct ast_frame * ast_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
Pass a frame off to be handled by the audiohook core.
Definition: audiohook.c:1079
@ AST_AUDIOHOOK_DIRECTION_READ
Definition: audiohook.h:49
@ AST_AUDIOHOOK_DIRECTION_WRITE
Definition: audiohook.h:50
int ast_audiohook_write_list_empty(struct ast_audiohook_list *audiohook_list)
Determine if a audiohook_list is empty or not.
Definition: audiohook.c:1071
void ast_audiohook_detach_list(struct ast_audiohook_list *audiohook_list)
Detach audiohooks from list and destroy said list.
Definition: audiohook.c:565
void ast_audiohook_move_all(struct ast_channel *old_chan, struct ast_channel *new_chan)
Move all audiohooks from one channel to another.
Definition: audiohook.c:672
"smart" channels that update automatically if a channel is masqueraded
void ast_autochan_new_channel(struct ast_channel *old_chan, struct ast_channel *new_chan)
Switch what channel autochans point to.
Definition: autochan.c:86
Bridging API.
struct ast_channel * ast_bridge_peer(struct ast_bridge *bridge, struct ast_channel *chan)
Get the channel's bridge peer only if the bridge is two-party.
Definition: bridge.c:4075
void ast_bridge_notify_masquerade(struct ast_channel *chan)
Notify bridging that this channel was just masqueraded.
Definition: bridge.c:1442
int ast_bridge_features_init(struct ast_bridge_features *features)
Initialize bridge features structure.
Definition: bridge.c:3620
struct ast_bridge_features * ast_bridge_features_new(void)
Allocate a new bridge features struct.
Definition: bridge.c:3683
void ast_bridge_features_merge(struct ast_bridge_features *into, const struct ast_bridge_features *from)
Merge one ast_bridge_features into another.
Definition: bridge.c:3595
void ast_bridge_features_cleanup(struct ast_bridge_features *features)
Clean up the contents of a bridge features structure.
Definition: bridge.c:3653
void ast_bridge_features_destroy(struct ast_bridge_features *features)
Destroy an allocated bridge features struct.
Definition: bridge.c:3674
static int tmp()
Definition: bt_open.c:389
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
#define AST_PRES_USER_NUMBER_UNSCREENED
Definition: callerid.h:426
#define AST_PRES_UNAVAILABLE
Definition: callerid.h:434
#define AST_PRES_RESTRICTED
Definition: callerid.h:433
#define AST_PRES_ALLOWED
Definition: callerid.h:432
@ AST_CONNECTED_LINE_UPDATE_SOURCE_UNKNOWN
Definition: callerid.h:552
#define AST_PRES_NUMBER_NOT_AVAILABLE
Definition: callerid.h:461
@ AST_REDIRECTING_REASON_UNKNOWN
Definition: callerid.h:499
#define AST_PRES_NUMBER_TYPE
Definition: callerid.h:425
#define AST_PRES_RESTRICTION
Definition: callerid.h:431
#define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED
Definition: callerid.h:437
Internal Asterisk hangup causes.
#define AST_CAUSE_SWITCH_CONGESTION
Definition: causes.h:123
#define AST_CAUSE_NUMBER_PORTED_NOT_HERE
Definition: causes.h:105
#define AST_CAUSE_CONGESTION
Definition: causes.h:153
#define AST_CAUSE_INVALID_IE_CONTENTS
Definition: causes.h:141
#define AST_CAUSE_UNALLOCATED
Definition: causes.h:98
#define AST_CAUSE_INTERWORKING
Definition: causes.h:146
#define AST_CAUSE_PROTOCOL_ERROR
Definition: causes.h:145
#define AST_CAUSE_NUMBER_CHANGED
Definition: causes.h:112
#define AST_CAUSE_BEARERCAPABILITY_NOTAVAIL
Definition: causes.h:130
#define AST_CAUSE_CALL_AWARDED_DELIVERED
Definition: causes.h:103
#define AST_CAUSE_INVALID_NUMBER_FORMAT
Definition: causes.h:116
#define AST_CAUSE_OUTGOING_CALL_BARRED
Definition: causes.h:127
#define AST_CAUSE_CHAN_NOT_IMPLEMENTED
Definition: causes.h:132
#define AST_CAUSE_WRONG_MESSAGE
Definition: causes.h:139
#define AST_CAUSE_INCOMPATIBLE_DESTINATION
Definition: causes.h:135
#define AST_CAUSE_BEARERCAPABILITY_NOTAUTH
Definition: causes.h:129
#define AST_CAUSE_DESTINATION_OUT_OF_ORDER
Definition: causes.h:115
#define AST_CAUSE_NO_USER_RESPONSE
Definition: causes.h:108
#define AST_CAUSE_NORMAL_TEMPORARY_FAILURE
Definition: causes.h:122
#define AST_CAUSE_MESSAGE_TYPE_NONEXIST
Definition: causes.h:138
#define AST_CAUSE_MANDATORY_IE_LENGTH_ERROR
Definition: causes.h:144
#define AST_CAUSE_REDIRECTED_TO_NEW_DESTINATION
Definition: causes.h:113
#define AST_CAUSE_FACILITY_NOT_SUBSCRIBED
Definition: causes.h:126
#define AST_CAUSE_BEARERCAPABILITY_NOTIMPL
Definition: causes.h:131
#define AST_CAUSE_WRONG_CALL_STATE
Definition: causes.h:142
#define AST_CAUSE_PRE_EMPTED
Definition: causes.h:104
#define AST_CAUSE_REQUESTED_CHAN_UNAVAIL
Definition: causes.h:125
#define AST_CAUSE_NORMAL_CIRCUIT_CONGESTION
Definition: causes.h:120
#define AST_CAUSE_CHANNEL_UNACCEPTABLE
Definition: causes.h:102
#define AST_CAUSE_NOTDEFINED
Definition: causes.h:155
#define AST_CAUSE_CALL_REJECTED
Definition: causes.h:111
#define AST_CAUSE_SUBSCRIBER_ABSENT
Definition: causes.h:110
#define AST_CAUSE_NETWORK_OUT_OF_ORDER
Definition: causes.h:121
#define AST_CAUSE_INVALID_CALL_REFERENCE
Definition: causes.h:134
#define AST_CAUSE_FACILITY_REJECTED
Definition: causes.h:117
#define AST_CAUSE_ANSWERED_ELSEWHERE
Definition: causes.h:114
#define AST_CAUSE_NORMAL_UNSPECIFIED
Definition: causes.h:119
#define AST_CAUSE_FACILITY_NOT_IMPLEMENTED
Definition: causes.h:133
#define AST_CAUSE_INCOMING_CALL_BARRED
Definition: causes.h:128
#define AST_CAUSE_MANDATORY_IE_MISSING
Definition: causes.h:137
#define AST_CAUSE_NOSUCHDRIVER
Definition: causes.h:156
#define AST_CAUSE_ACCESS_INFO_DISCARDED
Definition: causes.h:124
#define AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE
Definition: causes.h:143
#define AST_CAUSE_NO_ROUTE_TRANSIT_NET
Definition: causes.h:99
#define AST_CAUSE_RESPONSE_TO_STATUS_ENQUIRY
Definition: causes.h:118
#define AST_CAUSE_NO_ROUTE_DESTINATION
Definition: causes.h:100
#define AST_CAUSE_BUSY
Definition: causes.h:149
#define AST_CAUSE_INVALID_MSG_UNSPECIFIED
Definition: causes.h:136
#define AST_CAUSE_NO_ANSWER
Definition: causes.h:109
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:106
#define AST_CAUSE_MISDIALLED_TRUNK_PREFIX
Definition: causes.h:101
#define AST_CAUSE_IE_NONEXIST
Definition: causes.h:140
#define AST_CAUSE_USER_BUSY
Definition: causes.h:107
enum cc_state state
Definition: ccss.c:393
#define ast_cc_config_params_init()
Allocate and initialize an ast_cc_config_params structure.
Definition: ccss.h:135
void ast_cc_config_params_destroy(struct ast_cc_config_params *params)
Free memory from CCSS configuration params.
Definition: ccss.c:692
int ast_cc_offer(struct ast_channel *caller_chan)
Offer CC to a caller.
Definition: ccss.c:3716
void ast_cc_copy_config_params(struct ast_cc_config_params *dest, const struct ast_cc_config_params *src)
copy CCSS configuration parameters from one structure to another
Definition: ccss.c:854
void ast_cdr_free(struct ast_cdr *cdr)
Free a CDR record.
Definition: cdr.c:3473
static PGresult * result
Definition: cel_pgsql.c:84
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2362
static struct ast_timer * timer
Definition: chan_iax2.c:364
static char language[MAX_LANGUAGE]
Definition: chan_iax2.c:324
unsigned int cos
Definition: chan_iax2.c:356
static const char type[]
Definition: chan_ooh323.c:109
static int indicate(void *data)
Definition: chan_pjsip.c:1334
static int transfer(void *data)
Definition: chan_pjsip.c:2129
static int hangup(void *data)
Definition: chan_pjsip.c:2516
static int answer(void *data)
Definition: chan_pjsip.c:683
static int call(void *data)
Definition: chan_pjsip.c:2391
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
void ast_party_subaddress_copy(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src)
Copy the source party subaddress information to the destination party subaddress.
Definition: channel.c:1705
static void channels_shutdown(void)
Definition: channel.c:7993
static void channel_do_masquerade(struct ast_channel *original, struct ast_channel *clonechan)
Masquerade a channel.
Definition: channel.c:6857
int ast_say_number(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
says a number
Definition: channel.c:8235
struct varshead * ast_channel_get_manager_vars(struct ast_channel *chan)
Gets the variables for a given channel, as specified by ast_channel_set_manager_vars().
Definition: channel.c:7983
int ast_senddigit_mf_begin(struct ast_channel *chan, char digit)
Send an MF digit to a channel.
Definition: channel.c:4835
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3175
static int kill_write(struct ast_channel *chan, struct ast_frame *frame)
Definition: channel.c:407
void ast_softhangup_all(void)
Soft hangup all active channels.
Definition: channel.c:493
int ast_channel_request_stream_topology_change(struct ast_channel *chan, struct ast_stream_topology *topology, void *change_source)
Request that the stream topology of a channel change.
Definition: channel.c:10966
void ast_channel_end_dtmf(struct ast_channel *chan, char digit, struct timeval start, const char *why)
Simulate a DTMF end on a broken bridge channel.
Definition: channel.c:10869
void ast_party_redirecting_reason_copy(struct ast_party_redirecting_reason *dest, const struct ast_party_redirecting_reason *src)
Copy the source redirecting reason information to the destination redirecting reason.
Definition: channel.c:2085
struct ast_channel * ast_channel_get_by_exten(const char *exten, const char *context)
Find a channel by extension and context.
Definition: channel.c:1459
static void channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship, int precious)
Definition: channel.c:6376
static int indicate_connected_line(struct ast_channel *chan, const void *data, size_t datalen)
Definition: channel.c:4401
void ast_party_name_init(struct ast_party_name *init)
Initialize the given name structure.
Definition: channel.c:1591
char * ast_recvtext(struct ast_channel *chan, int timeout)
Receives a text string from a channel Read a string of text from a channel.
Definition: channel.c:4717
static void generator_write_format_change(struct ast_channel *chan)
Definition: channel.c:2904
enum ast_channel_error ast_channel_errno(void)
Get error code for latest channel operation.
Definition: channel.c:10961
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition: channel.c:2951
struct ast_channel * ast_channel_callback(ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags)
Call a function with every active channel.
Definition: channel.c:1278
void ast_party_dialed_set_init(struct ast_party_dialed *init, const struct ast_party_dialed *guide)
Initialize the given dialed structure using the given guide for a set update operation.
Definition: channel.c:1950
int ast_channel_get_device_name(struct ast_channel *chan, char *device_name, size_t name_buffer_length)
Get a device name given its channel structure.
Definition: channel.c:10496
struct ast_channel * ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds, int nfds, int *exception, int *outfd, int *ms)
Wait for x amount of time on a file descriptor to have input.
Definition: channel.c:2988
static int set_format(struct ast_channel *chan, struct ast_format_cap *cap_set, const int direction, int interleaved_stereo)
Definition: channel.c:5593
int ast_auto_answer(struct ast_channel *chan)
Answer a channel, if it's not already answered.
Definition: channel.c:2811
static int silence_generator_generate(struct ast_channel *chan, void *data, int len, int samples)
Definition: channel.c:8135
void ast_party_redirecting_init(struct ast_party_redirecting *init)
Initialize the given redirecting structure.
Definition: channel.c:2122
int ast_write(struct ast_channel *chan, struct ast_frame *fr)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition: channel.c:5144
int ast_call(struct ast_channel *chan, const char *addr, int timeout)
Make a call.
Definition: channel.c:6461
void ast_channel_set_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
Set the redirecting id information in the Asterisk channel.
Definition: channel.c:9119
static void handle_cause(int cause, int *outstate)
Definition: channel.c:5849
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
Clear a flag on a channel.
Definition: channel.c:11034
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2385
static void send_dtmf_begin_event(struct ast_channel *chan, enum DtmfDirection direction, const char digit)
Definition: channel.c:3370
struct ast_channel * ast_call_forward(struct ast_channel *caller, struct ast_channel *orig, int *timeout, struct ast_format_cap *cap, struct outgoing_helper *oh, int *outstate)
Forwards a call to a new channel specified by the original channel's call_forward str....
Definition: channel.c:5898
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2394
void ast_party_id_init(struct ast_party_id *init)
Initialize the given party id structure.
Definition: channel.c:1757
int ast_set_read_format_path(struct ast_channel *chan, struct ast_format *raw_format, struct ast_format *core_format)
Set specific read path on channel.
Definition: channel.c:5488
#define AST_MIN_DTMF_GAP
Definition: channel.c:112
void ast_channel_clear_softhangup(struct ast_channel *chan, int flag)
Clear a set of softhangup flags from a channel.
Definition: channel.c:2432
static void clone_variables(struct ast_channel *original, struct ast_channel *clonechan)
Clone channel variables from 'clone' channel into 'original' channel.
Definition: channel.c:6822
static char * handle_cli_core_show_channeltype(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Show details about a channel driver - CLI command.
Definition: channel.c:326
struct ast_channel_iterator * ast_channel_iterator_by_name_new(const char *name, size_t name_len)
Create a new channel iterator based on name.
Definition: channel.c:1388
int ast_say_digit_str(struct ast_channel *chan, const char *str, const char *ints, const char *lang)
says digits of a string
Definition: channel.c:8259
struct varshead * ast_channel_get_vars(struct ast_channel *chan)
Gets the variables for a given channel, as set using pbx_builtin_setvar_helper().
Definition: channel.c:7911
int ast_prod(struct ast_channel *chan)
Send empty audio to prime a channel driver.
Definition: channel.c:5000
int __ast_answer(struct ast_channel *chan, unsigned int delay)
Answer a channel, with a selectable delay before returning.
Definition: channel.c:2695
static int calc_monitor_jump(int samples, int sample_rate, int seek_rate)
calculates the number of samples to jump forward with in a monitor stream.
Definition: channel.c:3512
static struct ast_frame * kill_exception(struct ast_channel *chan)
Definition: channel.c:401
static int ast_channel_make_compatible_helper(struct ast_channel *from, struct ast_channel *to)
Set up translation from one channel to another.
Definition: channel.c:6641
void ast_party_number_init(struct ast_party_number *init)
Initialize the given number structure.
Definition: channel.c:1644
static void suppress_framehook_fixup_cb(void *data, int framehook_id, struct ast_channel *old_chan, struct ast_channel *new_chan)
Definition: channel.c:10725
void ast_hangup(struct ast_channel *chan)
Hangup a channel.
Definition: channel.c:2541
void ast_channel_set_caller(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
Set the caller id information in the Asterisk channel.
Definition: channel.c:7359
static int tonepair_generator(struct ast_channel *chan, void *data, int len, int samples)
Definition: channel.c:7529
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition: channel.c:7766
void ast_moh_cleanup(struct ast_channel *chan)
Definition: channel.c:7782
int ast_raw_answer_with_stream_topology(struct ast_channel *chan, struct ast_stream_topology *topology)
Answer a channel passing in a stream topology.
Definition: channel.c:2639
int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders)
Reads multiple digits.
Definition: channel.c:6558
int ast_channel_sendurl(struct ast_channel *chan, const char *url)
Sends a URL on a given link Send URL on link.
Definition: channel.c:6635
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition: channel.c:1360
int ast_queue_hangup(struct ast_channel *chan)
Queue a hangup frame for channel.
Definition: channel.c:1150
static int ast_channel_by_exten_cb(void *obj, void *arg, void *data, int flags)
Definition: channel.c:1306
struct ast_channel * ast_channel_bridge_peer(struct ast_channel *chan)
Get the channel's bridge peer only if the bridge is two-party.
Definition: channel.c:10564
int ast_transfer_protocol(struct ast_channel *chan, char *dest, int *protocol)
Transfer a call to dest, if the channel supports transfer.
Definition: channel.c:6498
static int indicate_redirecting(struct ast_channel *chan, const void *data, size_t datalen)
Definition: channel.c:4456
static void(* ast_moh_cleanup_ptr)(struct ast_channel *)
Definition: channel.c:7748
static int set_security_requirements(const struct ast_channel *requestor, struct ast_channel *out)
Definition: channel.c:6179
static int does_id_conflict(const char *uniqueid)
Definition: channel.c:711
static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f)
Definition: channel.c:3413
void ast_party_subaddress_set_init(struct ast_party_subaddress *init, const struct ast_party_subaddress *guide)
Initialize the given party subaddress structure using the given guide for a set update operation.
Definition: channel.c:1719
void ast_channel_set_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Set the connected line information in the Asterisk channel.
Definition: channel.c:8308
int ast_senddigit_begin(struct ast_channel *chan, char digit)
Send a DTMF digit to a channel.
Definition: channel.c:4874
static int channel_has_external_vars(struct external_vars *channelvars)
Definition: channel.c:7844
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
Definition: channel.c:1821
static int party_subaddress_build_data(unsigned char *data, size_t datalen, const struct ast_party_subaddress *subaddress, const char *label, const struct ast_party_subaddress_ies *ies)
Definition: channel.c:8496
void ast_party_number_copy(struct ast_party_number *dest, const struct ast_party_number *src)
Copy the source party number information to the destination party number.
Definition: channel.c:1652
static int namedgroup_cmp_cb(void *obj, void *arg, int flags)
Comparison function used for named group container.
Definition: channel.c:7659
void ast_channel_unlink(struct ast_channel *chan)
Remove a channel from the global channels container.
Definition: channel.c:10529
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin)
Queue one or more frames to a channel's frame queue.
Definition: channel.c:1139
void ast_party_number_set(struct ast_party_number *dest, const struct ast_party_number *src)
Set the source party number information into the destination party number.
Definition: channel.c:1674
void ast_party_subaddress_init(struct ast_party_subaddress *init)
Initialize the given subaddress structure.
Definition: channel.c:1697
int ast_channel_has_hook_requiring_audio(struct ast_channel *chan)
Check if the channel has any active hooks that require audio.
Definition: channel.c:2524
int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders, int audiofd, int ctrlfd)
Definition: channel.c:6563
static const struct ast_datastore_info suppress_datastore_voice
Definition: channel.c:10709
void ast_party_connected_line_free(struct ast_party_connected_line *doomed)
Destroy the connected line information contents.
Definition: channel.c:2072
static const struct ast_datastore_info plc_ds_info
Definition: channel.c:5048
int64_t ast_channel_get_up_time_ms(struct ast_channel *chan)
Obtain how long it has been since the channel was answered in ms.
Definition: channel.c:2835
void ast_channel_set_manager_vars(size_t varc, char **vars)
Sets the variables to be stored in the manager_vars field of all snapshots.
Definition: channel.c:7887
int ast_sendtext_data(struct ast_channel *chan, struct ast_msg_data *msg)
Sends text to a channel in an ast_msg_data structure wrapper with ast_sendtext as fallback.
Definition: channel.c:4751
static int party_name_build_data(unsigned char *data, size_t datalen, const struct ast_party_name *name, const char *label, const struct ast_party_name_ies *ies)
Definition: channel.c:8348
DtmfDirection
Definition: channel.c:3353
@ DTMF_SENT
Definition: channel.c:3355
@ DTMF_RECEIVED
Definition: channel.c:3354
int ast_set_read_format_from_cap(struct ast_channel *chan, struct ast_format_cap *cap)
Sets read format on channel chan from capabilities Set read format for channel to whichever component...
Definition: channel.c:5780
int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
Definition: channel.c:7582
void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
Set the caller id information in the Asterisk channel and generate an AMI event if the caller id name...
Definition: channel.c:7372
static char * handle_cli_core_show_channeltypes(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Show channel types - CLI command.
Definition: channel.c:261
int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel.
Definition: channel.c:4974
#define AST_DEFAULT_EMULATE_DTMF_DURATION
Definition: channel.c:102
void ast_party_redirecting_set(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src, const struct ast_set_party_redirecting *update)
Set the redirecting information based on another redirecting source.
Definition: channel.c:2166
const struct ast_channel_tech ast_kill_tech
Kill the channel channel driver technology descriptor.
Definition: channel.c:434
int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
Make the frame formats of two channels compatible.
Definition: channel.c:6720
int ast_channel_queryoption(struct ast_channel *chan, int option, void *data, int *datalen, int block)
Checks the value of an option.
Definition: channel.c:7442
AST_THREADSTORAGE_RAW(in_intercept_routine)
struct varshead * ast_channel_get_ari_vars(struct ast_channel *chan)
Gets the variables for a given channel, as specified by ast_channel_set_ari_vars().
Definition: channel.c:7988
static void queue_dtmf_readq(struct ast_channel *chan, struct ast_frame *f)
Definition: channel.c:3467
static int ast_channel_hash_cb(const void *obj, const int flags)
Definition: channel.c:7788
static void * channel_cc_params_copy(void *data)
Definition: channel.c:10428
static int deactivate_silence_generator(struct ast_channel *chan)
Definition: channel.c:8187
static void tonepair_release(struct ast_channel *chan, void *params)
Definition: channel.c:7487
static struct varshead * channel_get_external_vars(struct external_vars *channelvars, struct ast_channel *chan)
Definition: channel.c:7936
int ast_channel_setoption(struct ast_channel *chan, int option, void *data, int datalen, int block)
Sets an option on a channel.
Definition: channel.c:7422
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition: channel.c:7776
void ast_party_id_free(struct ast_party_id *doomed)
Destroy the party id contents.
Definition: channel.c:1811
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister channel driver.
Definition: channel.c:570
static const struct ast_datastore_info * suppress_get_datastore_information(enum ast_frame_type frametype)
Definition: channel.c:10767
void ast_party_subaddress_set(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src)
Set the source party subaddress information into the destination party subaddress.
Definition: channel.c:1727
int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception)
Wait for x amount of time on a file descriptor to have input.
Definition: channel.c:2980
int ast_channel_stream_topology_changed(struct ast_channel *chan, struct ast_stream_topology *topology)
Provide notice to a channel that the stream topology has changed.
Definition: channel.c:10996
int ast_set_write_format_from_cap(struct ast_channel *chan, struct ast_format_cap *cap)
Sets write format on channel chan Set write format for channel to whichever component of "format" is ...
Definition: channel.c:5821
void ast_party_id_set(struct ast_party_id *dest, const struct ast_party_id *src, const struct ast_set_party_id *update)
Set the source party id information into the destination party id.
Definition: channel.c:1788
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition: channel.c:1422
void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
adds a list of channel variables to a channel
Definition: channel.c:8115
struct ast_namedgroups * ast_ref_namedgroups(struct ast_namedgroups *groups)
Definition: channel.c:7738
static const struct ast_channel_tech null_tech
Definition: channel.c:702
int ast_channel_feature_hooks_replace(struct ast_channel *chan, struct ast_bridge_features *features)
Sets the channel-attached features a channel has access to upon being bridged.
Definition: channel.c:10956
static void silence_generator_release(struct ast_channel *chan, void *data)
Definition: channel.c:8130
static int namedgroup_hash_cb(const void *obj, const int flags)
Hashing function used for named group container.
Definition: channel.c:7668
struct ast_silence_generator * ast_channel_start_silence_generator(struct ast_channel *chan)
Starts a silence generator on the given channel.
Definition: channel.c:8164
static int chancount
Definition: channel.c:93
static void(* ast_moh_stop_ptr)(struct ast_channel *)
Definition: channel.c:7747
void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src)
Copy the source connected line information to the destination connected line.
Definition: channel.c:2031
int ast_recvchar(struct ast_channel *chan, int timeout)
Receives a text character from a channel.
Definition: channel.c:4706
static struct external_vars ari_vars
Definition: channel.c:7832
struct ast_channel * ast_channel_yank(struct ast_channel *yankee)
Gain control of a channel in the system.
Definition: channel.c:10593
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame.
Definition: channel.c:1231
int ast_channel_cc_params_init(struct ast_channel *chan, const struct ast_cc_config_params *base_params)
Set up datastore with CCSS parameters for a channel.
Definition: channel.c:10451
int ast_say_ordinal(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
says an ordinal number
Definition: channel.c:8241
int ast_channel_get_intercept_mode(void)
Am I currently running an intercept dialplan routine.
Definition: channel.c:10333
void ast_party_connected_line_set(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src, const struct ast_set_party_connected_line *update)
Set the connected line information based on another connected line source.
Definition: channel.c:2054
int ast_write_stream(struct ast_channel *chan, int stream_num, struct ast_frame *fr)
Write a frame to a stream This function writes the given frame to the indicated stream on the channel...
Definition: channel.c:5149
void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state)
Stops a previously-started silence generator on the given channel.
Definition: channel.c:8210
int ast_settimeout_full(struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data, unsigned int is_ao2_obj)
Definition: channel.c:3185
static int should_skip_dtmf(struct ast_channel *chan)
Determine whether or not we should ignore DTMF in the readq.
Definition: channel.c:3485
void ast_party_dialed_init(struct ast_party_dialed *init)
Initialize the given dialed structure.
Definition: channel.c:1928
void ast_party_caller_copy(struct ast_party_caller *dest, const struct ast_party_caller *src)
Copy the source caller information to the destination caller.
Definition: channel.c:1986
int ast_setstate(struct ast_channel *chan, enum ast_channel_state state)
Change the state of a channel.
Definition: channel.c:7386
void ast_party_redirecting_reason_set(struct ast_party_redirecting_reason *dest, const struct ast_party_redirecting_reason *src)
Set the redirecting reason information based on another redirecting reason source.
Definition: channel.c:2102
int ast_namedgroups_intersect(struct ast_namedgroups *a, struct ast_namedgroups *b)
Return TRUE if group a and b contain at least one common groupname.
Definition: channel.c:8090
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
Inherit datastores from a parent to a child.
Definition: channel.c:2368
char * ast_transfercapability2str(int transfercapability)
Gives the string form of a given transfer capability.
Definition: channel.c:672
void ast_channel_undefer_dtmf(struct ast_channel *chan)
Unset defer DTMF flag on channel.
Definition: channel.c:1271
static void deactivate_generator_nolock(struct ast_channel *chan)
Definition: channel.c:2877
void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
Setup new channel accountcodes from the requestor channel after ast_request().
Definition: channel.c:6434
void ast_deactivate_generator(struct ast_channel *chan)
Definition: channel.c:2893
static void channel_cc_params_destroy(void *data)
Definition: channel.c:10439
void ast_party_id_merge_copy(struct ast_party_id *dest, struct ast_party_id *base, struct ast_party_id *overlay)
Copy a merge of a given party id into another given party id to a given destination party id.
Definition: channel.c:1920
struct ast_channel_iterator * ast_channel_iterator_by_exten_new(const char *exten, const char *context)
Create a new channel iterator based on extension.
Definition: channel.c:1368
int ast_check_hangup_locked(struct ast_channel *chan)
Definition: channel.c:459
static const struct causes_map causes[]
Definition: channel.c:136
static void plc_ds_destroy(void *data)
Definition: channel.c:5041
int ast_channel_cmpwhentohangup_tv(struct ast_channel *chan, struct timeval offset)
Compare a offset with when to hangup channel.
Definition: channel.c:523
unsigned long global_fin
Definition: channel.c:95
struct ast_channel * __ast_channel_alloc(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, enum ama_flags amaflag, struct ast_endpoint *endpoint, const char *file, int line, const char *function, const char *name_fmt,...)
Create a channel structure.
Definition: channel.c:954
void ast_install_music_functions(int(*start_ptr)(struct ast_channel *, const char *, const char *), void(*stop_ptr)(struct ast_channel *), void(*cleanup_ptr)(struct ast_channel *))
Definition: channel.c:7750
char * ast_print_group(char *buf, int buflen, ast_group_t group)
Print call group and pickup group —.
Definition: channel.c:8031
static void varshead_dtor(void *obj)
Destructor for lists of variables.
Definition: channel.c:7901
struct ast_channel * ast_channel_get_by_name_prefix(const char *name, size_t name_len)
Find a channel by a name prefix.
Definition: channel.c:1434
void ast_party_redirecting_reason_set_init(struct ast_party_redirecting_reason *init, const struct ast_party_redirecting_reason *guide)
Initialize the given redirecting reason structure using the given guide for a set update operation.
Definition: channel.c:2096
int ast_set_write_format_interleaved_stereo(struct ast_channel *chan, struct ast_format *format)
Sets write format for a channel. All internal data will than be handled in an interleaved format....
Definition: channel.c:5785
void ast_party_caller_set(struct ast_party_caller *dest, const struct ast_party_caller *src, const struct ast_set_party_caller *update)
Set the caller information based on another caller source.
Definition: channel.c:2007
int ast_channel_suppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
Suppress passing of a frame type on a channel.
Definition: channel.c:10777
int ast_channel_feature_hooks_append(struct ast_channel *chan, struct ast_bridge_features *features)
Appends to the channel-attached features a channel has access to upon being bridged.
Definition: channel.c:10951
static int safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int(*cond)(void *), void *data, unsigned int generate_silence)
Wait, look for hangups and condition arg.
Definition: channel.c:1498
static void __ast_change_name_nolink(struct ast_channel *chan, const char *newname)
this function simply changes the name of the channel and issues a manager_event with out unlinking an...
Definition: channel.c:6742
void ast_channel_softhangup_withcause_locked(struct ast_channel *chan, int causecode)
Lock the given channel, then request softhangup on the channel with the given causecode.
Definition: channel.c:468
int ast_say_digits(struct ast_channel *chan, int num, const char *ints, const char *lang)
says digits
Definition: channel.c:8253
int ast_undestroyed_channels(void)
Definition: channel.c:504
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4257
void ast_party_connected_line_collect_caller(struct ast_party_connected_line *connected, struct ast_party_caller *caller)
Collect the caller party information into a connected line structure.
Definition: channel.c:2063
int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen)
Queue a control frame with payload.
Definition: channel.c:1238
struct ast_bridge_features * ast_channel_feature_hooks_get(struct ast_channel *chan)
Gets the channel-attached features a channel has access to upon being bridged.
Definition: channel.c:10903
void ast_channel_update_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Indicate that the connected line information has changed.
Definition: channel.c:9093
int ast_senddigit_mf_end(struct ast_channel *chan)
End sending an MF digit to a channel.
Definition: channel.c:4943
int ast_channel_move(struct ast_channel *dest, struct ast_channel *source)
Move a channel from its current location to a new location.
Definition: channel.c:10666
void ast_channel_queue_redirecting_update(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
Queue a redirecting update frame on a channel.
Definition: channel.c:10297
void ast_party_redirecting_reason_init(struct ast_party_redirecting_reason *init)
Initialize the given redirecting reason structure.
Definition: channel.c:2079
int ast_senddigit_external(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel from an external thread.
Definition: channel.c:4987
int ast_sendtext(struct ast_channel *chan, const char *text)
Sends text to a channel.
Definition: channel.c:4809
struct ast_channel * ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int timeout, int *outstate, const char *cidnum, const char *cidname)
Request a channel of a given type, with data as optional information used by the low level module and...
Definition: channel.c:6174
struct ast_frame * ast_read_stream(struct ast_channel *chan)
Reads a frame, but does not filter to just the default streams.
Definition: channel.c:4262
void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide)
Initialize the given caller structure using the given guide for a set update operation.
Definition: channel.c:1999
void ast_party_id_set_init(struct ast_party_id *init, const struct ast_party_id *guide)
Initialize the given party id structure using the given guide for a set update operation.
Definition: channel.c:1780
void ast_party_name_free(struct ast_party_name *doomed)
Destroy the party name contents.
Definition: channel.c:1638
@ AST_CONNECTED_LINE_NUMBER_VALID
Definition: channel.c:8680
@ AST_CONNECTED_LINE_SOURCE
Definition: channel.c:8666
@ AST_CONNECTED_LINE_PRIV_SUBADDRESS_VALID
Definition: channel.c:8693
@ AST_CONNECTED_LINE_PRIV_SUBADDRESS_ODD_EVEN
Definition: channel.c:8692
@ AST_CONNECTED_LINE_PRIV_NAME_VALID
Definition: channel.c:8687
@ AST_CONNECTED_LINE_PRIV_SUBADDRESS_TYPE
Definition: channel.c:8691
@ AST_CONNECTED_LINE_PRIV_NUMBER_PRESENTATION
Definition: channel.c:8685
@ AST_CONNECTED_LINE_NAME_CHAR_SET
Definition: channel.c:8678
@ AST_CONNECTED_LINE_SUBADDRESS_VALID
Definition: channel.c:8670
@ AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN
Definition: channel.c:8669
@ AST_CONNECTED_LINE_SUBADDRESS
Definition: channel.c:8667
@ AST_CONNECTED_LINE_PRIV_NUMBER_PLAN
Definition: channel.c:8683
@ AST_CONNECTED_LINE_NUMBER
Definition: channel.c:8662
@ AST_CONNECTED_LINE_ID_PRESENTATION
Definition: channel.c:8665
@ AST_CONNECTED_LINE_PRIV_NAME_PRESENTATION
Definition: channel.c:8689
@ AST_CONNECTED_LINE_PRIV_NAME
Definition: channel.c:8686
@ AST_CONNECTED_LINE_TAG
Definition: channel.c:8671
@ AST_CONNECTED_LINE_PRIV_NUMBER_VALID
Definition: channel.c:8684
@ AST_CONNECTED_LINE_NUMBER_PRESENTATION
Definition: channel.c:8681
@ AST_CONNECTED_LINE_PRIV_NAME_CHAR_SET
Definition: channel.c:8688
@ AST_CONNECTED_LINE_NAME
Definition: channel.c:8663
@ AST_CONNECTED_LINE_NAME_PRESENTATION
Definition: channel.c:8679
@ AST_CONNECTED_LINE_SUBADDRESS_TYPE
Definition: channel.c:8668
@ AST_CONNECTED_LINE_PRIV_SUBADDRESS
Definition: channel.c:8690
@ AST_CONNECTED_LINE_PRIV_TAG
Definition: channel.c:8694
@ AST_CONNECTED_LINE_NAME_VALID
Definition: channel.c:8677
@ AST_CONNECTED_LINE_PRIV_NUMBER
Definition: channel.c:8682
@ AST_CONNECTED_LINE_NUMBER_PLAN
Definition: channel.c:8664
@ AST_CONNECTED_LINE_VERSION
Definition: channel.c:8672
void ast_channel_set_ari_vars(size_t varc, char **vars)
Sets the variables to be stored in the ari_vars field of all snapshots.
Definition: channel.c:7892
void ast_party_dialed_free(struct ast_party_dialed *doomed)
Destroy the dialed party contents.
Definition: channel.c:1971
int ast_say_money_str(struct ast_channel *chan, const char *str, const char *ints, const char *lang)
function to pronounce monetary amounts
Definition: channel.c:8265
void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
Set caller ID number, name and ANI and generate AMI event.
Definition: channel.c:7334
int ast_channel_redirecting_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *redirecting_info, int is_frame)
Run a redirecting interception subroutine and update a channel's redirecting information.
Definition: channel.c:10383
void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
Inherits channel variable from parent to child channel.
Definition: channel.c:6771
static ast_mutex_t channel_move_lock
Definition: channel.c:10664
static int namedgroup_match(void *obj, void *arg, int flags)
Definition: channel.c:8080
int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *fin)
Queue one or more frames to the head of a channel's frame queue.
Definition: channel.c:1144
static const struct ast_datastore_info cc_channel_datastore_info
Definition: channel.c:10445
static int channel_feature_hooks_set_full(struct ast_channel *chan, struct ast_bridge_features *features, int replace)
Definition: channel.c:10914
struct ast_frame * ast_read_stream_noaudio(struct ast_channel *chan)
Reads a frame, but does not filter to just the default streams, returning AST_FRAME_NULL frame if aud...
Definition: channel.c:4272
int ast_channel_sendhtml(struct ast_channel *chan, int subclass, const char *data, int datalen)
Sends HTML on given channel Send HTML or URL on link.
Definition: channel.c:6628
struct ast_channel * __ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int timeout, int *outstate, const char *cid_num, const char *cid_name, struct outgoing_helper *oh)
Request a channel of a given type, with data as optional information used by the low level module and...
Definition: channel.c:5976
void ast_party_redirecting_set_init(struct ast_party_redirecting *init, const struct ast_party_redirecting *guide)
Initialize the given redirecting id structure using the given guide for a set update operation.
Definition: channel.c:2153
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
Definition: channel.c:5762
static void free_external_channelvars(struct external_vars *channelvars)
Definition: channel.c:7834
void ast_party_name_set_init(struct ast_party_name *init, const struct ast_party_name *guide)
Initialize the given party name structure using the given guide for a set update operation.
Definition: channel.c:1613
int ast_say_enumeration(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
says an enumeration
Definition: channel.c:8247
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame for channel.
Definition: channel.c:1166
int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected)
Parse connected line indication frame data.
Definition: channel.c:8785
void ast_party_caller_free(struct ast_party_caller *doomed)
Destroy the caller party contents.
Definition: channel.c:2015
struct ast_channel * __ast_dummy_channel_alloc(const char *file, int line, const char *function)
Definition: channel.c:975
const char * ast_cause2str(int cause)
Gives the string form of a given hangup cause.
Definition: channel.c:612
const char * ast_channel_amaflags2string(enum ama_flags flag)
Convert the enum representation of an AMA flag to a string representation.
Definition: channel.c:4373
void ast_party_dialed_copy(struct ast_party_dialed *dest, const struct ast_party_dialed *src)
Copy the source dialed party information to the destination dialed party.
Definition: channel.c:1936
int ast_active_channels(void)
returns number of active/allocated channels
Definition: channel.c:499
static struct ast_frame * kill_read(struct ast_channel *chan)
Definition: channel.c:395
struct ast_channel * ast_request_with_stream_topology(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
Requests a channel (specifying stream topology)
Definition: channel.c:6359
static const struct set_format_access set_format_access_write
Definition: channel.c:5582
struct ast_namedgroups * ast_get_namedgroups(const char *s)
Create an ast_namedgroups set with group names from comma separated string.
Definition: channel.c:7675
static struct ast_generator tonepair
Definition: channel.c:7576
static int generator_force(const void *data)
Definition: channel.c:2916
static void call_forward_inherit(struct ast_channel *new_chan, struct ast_channel *parent, struct ast_channel *orig)
Definition: channel.c:5870
static void adjust_frame_for_plc(struct ast_channel *chan, struct ast_frame *frame, struct ast_datastore *datastore)
Definition: channel.c:5053
void ast_uninstall_music_functions(void)
Definition: channel.c:7759
static void channel_set_intercept_mode(int in_intercept_mode)
Definition: channel.c:10322
int ast_channels_init(void)
Definition: channel.c:8007
int ast_waitfordigit_full(struct ast_channel *c, int timeout_ms, const char *breakon, int audiofd, int cmdfd)
Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to mon...
Definition: channel.c:3239
int ast_check_hangup(struct ast_channel *chan)
Checks to see if a channel is needing hang up.
Definition: channel.c:445
static void prnt_channel_key(void *v_obj, void *where, ao2_prnt_fn *prnt)
Definition: channel.c:7810
int ast_say_character_str(struct ast_channel *chan, const char *str, const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity)
function to pronounce character and phonetic strings
Definition: channel.c:8271
static struct external_vars ami_vars
Definition: channel.c:7831
void ast_party_name_set(struct ast_party_name *dest, const struct ast_party_name *src)
Set the source party name information into the destination party name.
Definition: channel.c:1621
static void features_destroy(void *obj)
Definition: channel.c:10893
void ast_set_party_id_all(struct ast_set_party_id *update_id)
Set the update marker to update all information of a corresponding party id.
Definition: channel.c:1750
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
Definition: channel.c:10545
static int kill_hangup(struct ast_channel *chan)
Definition: channel.c:419
void ast_party_dialed_set(struct ast_party_dialed *dest, const struct ast_party_dialed *src)
Set the dialed information based on another dialed source.
Definition: channel.c:1958
const char * ast_channel_reason2str(int reason)
return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
Definition: channel.c:5826
struct ast_frame * ast_read_noaudio(struct ast_channel *chan)
Reads a frame, returning AST_FRAME_NULL frame if audio.
Definition: channel.c:4267
int64_t ast_channel_get_duration_ms(struct ast_channel *chan)
Obtain how long it's been, in milliseconds, since the channel was created.
Definition: channel.c:2820
struct ast_bridge * ast_channel_get_bridge(const struct ast_channel *chan)
Get the bridge associated with a channel.
Definition: channel.c:10534
static void suppress_datastore_destroy_cb(void *data)
Definition: channel.c:10704
static struct ast_channel * __ast_channel_alloc_ap(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, enum ama_flags amaflag, struct ast_endpoint *endpoint, const char *file, int line, const char *function, const char *name_fmt, va_list ap)
Create a new channel structure.
Definition: channel.c:733
struct ast_channel * ast_channel_release(struct ast_channel *chan)
Unlink and release reference to a channel.
Definition: channel.c:1584
static int ast_channel_softhangup_cb(void *obj, void *arg, int flags)
Definition: channel.c:484
int ast_redirecting_build_data(unsigned char *data, size_t datalen, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
Build the redirecting id data frame.
Definition: channel.c:9268
void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
Set the source of the hangup in this channel and it's bridge.
Definition: channel.c:2499
void ast_channel_set_flag(struct ast_channel *chan, unsigned int flag)
Set a flag on a channel.
Definition: channel.c:11027
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup a channel, lock.
Definition: channel.c:2471
static void send_flash_event(struct ast_channel *chan)
Definition: channel.c:3403
int ast_write_video(struct ast_channel *chan, struct ast_frame *fr)
Write video frame to a channel This function writes the given frame to the indicated channel.
Definition: channel.c:5017
static void send_dtmf_end_event(struct ast_channel *chan, enum DtmfDirection direction, const char digit, long duration_ms)
Definition: channel.c:3386
void ast_channel_name_to_dial_string(char *channel_name)
Removes the trailing identifiers from a channel name string.
Definition: channel.c:6839
void ast_channel_hangupcause_hash_set(struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen)
Sets the HANGUPCAUSE hash and optionally the SIP_CAUSE hash on the given channel.
Definition: channel.c:4346
int ast_queue_unhold(struct ast_channel *chan)
Queue an unhold frame.
Definition: channel.c:1216
static void destroy_hooks(struct ast_channel *chan)
Definition: channel.c:2530
int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int is_frame)
Run a connected line interception subroutine and update a channel's connected line information.
Definition: channel.c:10338
void ast_channel_update_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
Indicate that the redirecting id has changed.
Definition: channel.c:10284
int ast_channel_has_manager_vars(void)
Return whether or not any manager variables have been set.
Definition: channel.c:7855
void ast_party_id_reset(struct ast_party_id *id)
Destroy and initialize the given party id structure.
Definition: channel.c:1896
void ast_party_id_invalidate(struct ast_party_id *id)
Invalidate all components of the given party id.
Definition: channel.c:1889
int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
Queue a hold frame.
Definition: channel.c:1191
int ast_connected_line_build_data(unsigned char *data, size_t datalen, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Build the connected line information data frame.
Definition: channel.c:8697
int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel.
Definition: channel.c:4924
int ast_channel_has_ari_vars(void)
Return whether or not any ARI variables have been set.
Definition: channel.c:7860
int ast_channel_register(const struct ast_channel_tech *tech)
Register a new telephony channel in Asterisk.
Definition: channel.c:539
int ast_say_phonetic_str(struct ast_channel *chan, const char *str, const char *ints, const char *lang)
Definition: channel.c:8277
struct ast_party_id ast_party_id_merge(struct ast_party_id *base, struct ast_party_id *overlay)
Merge a given party id into another given party id.
Definition: channel.c:1902
int ast_channel_stream_topology_changed_externally(struct ast_channel *chan)
Provide notice from a channel that the topology has changed on it as a result of the remote party ren...
Definition: channel.c:11008
#define DEFAULT_EMULATE_MF_DURATION
Definition: channel.c:106
void ast_party_number_set_init(struct ast_party_number *init, const struct ast_party_number *guide)
Initialize the given party number structure using the given guide for a set update operation.
Definition: channel.c:1666
int ast_settimeout(struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data)
Enable or disable timer ticks for a channel.
Definition: channel.c:3180
static const struct ast_channel_tech surrogate_tech
Channel technology used to extract a channel from a running application. The channel created with thi...
Definition: channel.c:696
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition: channel.c:5803
void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src)
Copy the source party id information to the destination party id.
Definition: channel.c:1765
void ast_party_number_free(struct ast_party_number *doomed)
Destroy the party number contents.
Definition: channel.c:1691
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition: channel.c:2022
int ast_channel_get_up_time(struct ast_channel *chan)
Obtain how long it has been since the channel was answered.
Definition: channel.c:2845
static char * complete_channeltypes(struct ast_cli_args *a)
Definition: channel.c:303
int ast_channel_is_leaving_bridge(struct ast_channel *chan)
Determine if a channel is leaving a bridge, but not hung up.
Definition: channel.c:10550
void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset)
Set when to hangup channel.
Definition: channel.c:510
int ast_redirecting_parse_data(const unsigned char *data, size_t datalen, struct ast_party_redirecting *redirecting)
Parse redirecting indication frame data.
Definition: channel.c:9479
static int indicate_data_internal(struct ast_channel *chan, int _condition, const void *data, size_t datalen)
Definition: channel.c:4470
struct ast_variable * ast_channeltype_list(void)
return an ast_variable list of channeltypes
Definition: channel.c:188
int ast_say_digits_full(struct ast_channel *chan, int num, const char *ints, const char *lang, int audiofd, int ctrlfd)
Same as ast_say_digits() with audiofd for received audio and returns 1 on ctrlfd being readable.
Definition: channel.c:8283
struct ast_bridge_channel * ast_channel_get_bridge_channel(struct ast_channel *chan)
Get a reference to the channel's bridge pointer.
Definition: channel.c:10582
int ast_senddigit_mf(struct ast_channel *chan, char digit, unsigned int duration, unsigned int durationkp, unsigned int durationst, int is_external)
Send an MF digit to a channel.
Definition: channel.c:4952
static struct ast_generator silence_generator
Definition: channel.c:8154
int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int(*cond)(void *), void *data)
Wait for a specified amount of time, looking for hangups and a condition argument.
Definition: channel.c:1568
static void suppress_framehook_destroy_cb(void *data)
Definition: channel.c:10714
static void channel_set_external_vars(struct external_vars *channelvars, size_t varc, char **vars)
Definition: channel.c:7865
int ast_transfer(struct ast_channel *chan, char *dest)
Transfer a call to dest, if the channel supports transfer.
Definition: channel.c:6485
static int ast_channel_by_uniqueid_cb(void *obj, void *arg, void *data, int flags)
Definition: channel.c:1329
static int party_id_build_data(unsigned char *data, size_t datalen, const struct ast_party_id *id, const char *label, const struct ast_party_id_ies *ies, const struct ast_set_party_id *update)
Definition: channel.c:8577
int ast_channel_unsuppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
Stop suppressing of a frame type on a channel.
Definition: channel.c:10839
void ast_party_redirecting_free(struct ast_party_redirecting *doomed)
Destroy the redirecting information contents.
Definition: channel.c:2179
#define FORMAT
static void free_translation(struct ast_channel *clonechan)
Definition: channel.c:2487
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
Definition: channel.c:2426
const char * ast_state2str(enum ast_channel_state state)
Gives the string form of a given channel state.
Definition: channel.c:636
static int tech_write(struct ast_channel *chan, struct ast_stream *stream, struct ast_stream *default_stream, struct ast_frame *frame)
Definition: channel.c:5132
void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src)
Copy the caller information to the connected line information.
Definition: channel.c:8293
int ast_softhangup_nolock(struct ast_channel *chan, int cause)
Softly hangup a channel, don't lock.
Definition: channel.c:2458
enum ama_flags ast_channel_string2amaflag(const char *flag)
Convert a string to a detail record AMA flag.
Definition: channel.c:4360
static int redirecting_reason_build_data(unsigned char *data, size_t datalen, const struct ast_party_redirecting_reason *reason, const char *label, const struct ast_party_redirecting_reason_ies *ies)
Definition: channel.c:9235
int ast_indicate_data(struct ast_channel *chan, int _condition, const void *data, size_t datalen)
Indicates condition of channel, with payload.
Definition: channel.c:4653
static struct ast_frame * suppress_framehook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
Definition: channel.c:10732
static int attribute_const is_visible_indication(enum ast_control_frame_type condition)
Definition: channel.c:4282
static void ast_channel_destructor(void *obj)
Free a channel structure.
Definition: channel.c:2192
void ast_channel_req_accountcodes_precious(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
Setup new channel accountcodes from the requestor channel after ast_request().
Definition: channel.c:6439
static int party_number_build_data(unsigned char *data, size_t datalen, const struct ast_party_number *number, const char *label, const struct ast_party_number_ies *ies)
Definition: channel.c:8422
int ast_set_write_format_path(struct ast_channel *chan, struct ast_format *core_format, struct ast_format *raw_format)
Set specific write path on channel.
Definition: channel.c:5524
static void apply_plc(struct ast_channel *chan, struct ast_frame *frame)
Definition: channel.c:5106
static struct ast_cli_entry cli_channel[]
Definition: channel.c:390
int ast_pre_call(struct ast_channel *chan, const char *sub_args)
Execute a Gosub call on the channel before a call is placed.
Definition: channel.c:6444
int ast_channel_supports_html(struct ast_channel *chan)
Checks for HTML support on a channel.
Definition: channel.c:6623
static int ast_channel_by_name_cb(void *obj, void *arg, void *data, int flags)
Definition: channel.c:1284
int ast_queue_answer(struct ast_channel *chan, const struct ast_stream_topology *topology)
Queue an ANSWER control frame with topology.
Definition: channel.c:1246
int ast_str2cause(const char *name)
Convert a symbolic hangup cause to number.
Definition: channel.c:625
static void * tonepair_alloc(struct ast_channel *chan, void *params)
Definition: channel.c:7498
struct ast_namedgroups * ast_unref_namedgroups(struct ast_namedgroups *groups)
Definition: channel.c:7732
void ast_party_subaddress_free(struct ast_party_subaddress *doomed)
Destroy the party subaddress contents.
Definition: channel.c:1744
static void set_channel_answer_time(struct ast_channel *chan)
Definition: channel.c:2628
static struct ao2_container * channels
All active channels on the system.
Definition: channel.c:124
static void * silence_generator_alloc(struct ast_channel *chan, void *data)
Definition: channel.c:8124
int ast_channel_get_duration(struct ast_channel *chan)
Obtain how long the channel since the channel was created.
Definition: channel.c:2830
void ast_channel_queue_connected_line_update(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Queue a connected line update frame on a channel.
Definition: channel.c:9106
void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide)
Initialize the given connected line structure using the given guide for a set update operation.
Definition: channel.c:2045
unsigned long global_fout
Definition: channel.c:95
static struct ast_frame * __ast_read(struct ast_channel *chan, int dropaudio, int dropnondefault)
Definition: channel.c:3525
static struct ast_channel * request_channel(const char *type, struct ast_format_cap *request_cap, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
Definition: channel.c:6219
static int should_trigger_dtmf_emulating(struct ast_channel *chan)
Determine whether or not we have to trigger dtmf emulating using 50 fps timer events especially when ...
Definition: channel.c:2855
static int kill_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
Definition: channel.c:413
static struct ast_threadstorage state2str_threadbuf
Definition: channel.c:97
int ast_safe_sleep_without_silence(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups, and do not generate silence.
Definition: channel.c:1579
static int __ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin, int head, struct ast_frame *after)
Definition: channel.c:1009
void ast_connected_line_copy_to_caller(struct ast_party_caller *dest, const struct ast_party_connected_line *src)
Copy the connected line information to the caller information.
Definition: channel.c:8300
const struct ast_channel_tech * ast_get_channel_tech(const char *name)
Get handle to channel driver based on name.
Definition: channel.c:592
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
int ast_channel_defer_dtmf(struct ast_channel *chan)
Set defer DTMF flag on channel.
Definition: channel.c:1257
static const struct ast_datastore_info bridge_features_info
Definition: channel.c:10898
int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
Definition: channel.c:7600
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2805
void ast_change_name(struct ast_channel *chan, const char *newname)
Change channel name.
Definition: channel.c:6759
int ast_waitfor(struct ast_channel *c, int ms)
Wait for input on a channel.
Definition: channel.c:3162
static int ast_channel_cmp_cb(void *obj, void *arg, int flags)
Definition: channel.c:1428
ast_group_t ast_get_group(const char *s)
Definition: channel.c:7618
static const struct set_format_access set_format_access_read
Definition: channel.c:5571
int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
Bridge two channels together (early)
Definition: channel.c:7412
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4277
static const char * dtmf_direction_to_string(enum DtmfDirection direction)
Definition: channel.c:3358
int ast_is_deferrable_frame(const struct ast_frame *frame)
Should we keep this frame for later?
Definition: channel.c:1467
struct ast_channel_iterator * ast_channel_iterator_all_new(void)
Create a new channel iterator.
Definition: channel.c:1408
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait, look for hangups.
Definition: channel.c:1574
struct ast_channel * ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
Requests a channel.
Definition: channel.c:6354
static void send_wink_event(struct ast_channel *chan)
Definition: channel.c:3408
static int(* ast_moh_start_ptr)(struct ast_channel *, const char *, const char *)
Definition: channel.c:7746
struct ast_cc_config_params * ast_channel_get_cc_config_params(struct ast_channel *chan)
Get the CCSS parameters from a channel.
Definition: channel.c:10474
#define DEFAULT_AMA_FLAGS
Definition: channel.c:108
int ast_raw_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2690
void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src)
Copy the source redirecting information to the destination redirecting.
Definition: channel.c:2135
@ AST_REDIRECTING_FROM_NAME_PRESENTATION
Definition: channel.c:9165
@ AST_REDIRECTING_TO_NAME
Definition: channel.c:9143
@ AST_REDIRECTING_VERSION
Definition: channel.c:9158
@ AST_REDIRECTING_PRIV_FROM_NAME_VALID
Definition: channel.c:9205
@ AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN
Definition: channel.c:9210
@ AST_REDIRECTING_TO_TAG
Definition: channel.c:9157
@ AST_REDIRECTING_FROM_NUMBER_PLAN
Definition: channel.c:9140
@ AST_REDIRECTING_PRIV_TO_NAME_VALID
Definition: channel.c:9192
@ AST_REDIRECTING_ORIG_TAG
Definition: channel.c:9185
@ AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN
Definition: channel.c:9223
@ AST_REDIRECTING_REASON_CODE
Definition: channel.c:9146
@ AST_REDIRECTING_PRIV_TO_NUMBER_VALID
Definition: channel.c:9189
@ AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION
Definition: channel.c:9190
@ AST_REDIRECTING_ORIG_REASON_CODE
Definition: channel.c:9186
@ AST_REDIRECTING_TO_NAME_PRESENTATION
Definition: channel.c:9170
@ AST_REDIRECTING_PRIV_TO_NAME
Definition: channel.c:9191
@ AST_REDIRECTING_PRIV_ORIG_NAME_VALID
Definition: channel.c:9218
@ AST_REDIRECTING_ORIG_NUMBER_VALID
Definition: channel.c:9174
@ AST_REDIRECTING_FROM_NUMBER_PRESENTATION
Definition: channel.c:9167
@ AST_REDIRECTING_ORIG_SUBADDRESS_VALID
Definition: channel.c:9184
@ AST_REDIRECTING_FROM_NUMBER_VALID
Definition: channel.c:9166
@ AST_REDIRECTING_TO_NAME_VALID
Definition: channel.c:9168
@ AST_REDIRECTING_PRIV_FROM_NAME
Definition: channel.c:9204
@ AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN
Definition: channel.c:9154
@ AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN
Definition: channel.c:9183
@ AST_REDIRECTING_PRIV_FROM_SUBADDRESS_TYPE
Definition: channel.c:9209
@ AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID
Definition: channel.c:9198
@ AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN
Definition: channel.c:9197
@ AST_REDIRECTING_ORIG_NAME_CHAR_SET
Definition: channel.c:9179
@ AST_REDIRECTING_PRIV_FROM_SUBADDRESS
Definition: channel.c:9208
@ AST_REDIRECTING_TO_NUMBER_PLAN
Definition: channel.c:9144
@ AST_REDIRECTING_PRIV_TO_NUMBER
Definition: channel.c:9187
@ AST_REDIRECTING_PRIV_FROM_NUMBER_VALID
Definition: channel.c:9202
@ AST_REDIRECTING_ORIG_NAME
Definition: channel.c:9177
@ AST_REDIRECTING_ORIG_SUBADDRESS
Definition: channel.c:9181
@ AST_REDIRECTING_FROM_TAG
Definition: channel.c:9156
@ AST_REDIRECTING_PRIV_ORIG_NUMBER_PLAN
Definition: channel.c:9215
@ AST_REDIRECTING_TO_NUMBER
Definition: channel.c:9142
@ AST_REDIRECTING_ORIG_SUBADDRESS_TYPE
Definition: channel.c:9182
@ AST_REDIRECTING_FROM_NAME_CHAR_SET
Definition: channel.c:9164
@ AST_REDIRECTING_PRIV_FROM_TAG
Definition: channel.c:9212
@ AST_REDIRECTING_FROM_ID_PRESENTATION
Definition: channel.c:9141
@ AST_REDIRECTING_PRIV_FROM_NUMBER
Definition: channel.c:9200
@ AST_REDIRECTING_PRIV_TO_NUMBER_PLAN
Definition: channel.c:9188
@ AST_REDIRECTING_TO_NUMBER_VALID
Definition: channel.c:9171
@ AST_REDIRECTING_FROM_SUBADDRESS_VALID
Definition: channel.c:9151
@ AST_REDIRECTING_FROM_NAME_VALID
Definition: channel.c:9163
@ AST_REDIRECTING_PRIV_TO_NAME_CHAR_SET
Definition: channel.c:9193
@ AST_REDIRECTING_PRIV_ORIG_TAG
Definition: channel.c:9225
@ AST_REDIRECTING_FROM_SUBADDRESS_TYPE
Definition: channel.c:9149
@ AST_REDIRECTING_PRIV_TO_TAG
Definition: channel.c:9199
@ AST_REDIRECTING_COUNT
Definition: channel.c:9147
@ AST_REDIRECTING_FROM_SUBADDRESS
Definition: channel.c:9148
@ AST_REDIRECTING_PRIV_ORIG_NAME_CHAR_SET
Definition: channel.c:9219
@ AST_REDIRECTING_ORIG_NAME_VALID
Definition: channel.c:9178
@ AST_REDIRECTING_TO_ID_PRESENTATION
Definition: channel.c:9145
@ AST_REDIRECTING_PRIV_FROM_NUMBER_PLAN
Definition: channel.c:9201
@ AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION
Definition: channel.c:9194
@ AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION
Definition: channel.c:9203
@ AST_REDIRECTING_PRIV_FROM_NAME_PRESENTATION
Definition: channel.c:9207
@ AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_TYPE
Definition: channel.c:9222
@ AST_REDIRECTING_ORIG_REASON_STR
Definition: channel.c:9227
@ AST_REDIRECTING_ORIG_NAME_PRESENTATION
Definition: channel.c:9180
@ AST_REDIRECTING_PRIV_FROM_NAME_CHAR_SET
Definition: channel.c:9206
@ AST_REDIRECTING_ORIG_NUMBER
Definition: channel.c:9173
@ AST_REDIRECTING_PRIV_ORIG_NAME
Definition: channel.c:9217
@ AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE
Definition: channel.c:9196
@ AST_REDIRECTING_PRIV_ORIG_NUMBER_VALID
Definition: channel.c:9214
@ AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION
Definition: channel.c:9216
@ AST_REDIRECTING_TO_SUBADDRESS_VALID
Definition: channel.c:9155
@ AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_VALID
Definition: channel.c:9224
@ AST_REDIRECTING_TO_SUBADDRESS_TYPE
Definition: channel.c:9153
@ AST_REDIRECTING_REASON_STR
Definition: channel.c:9226
@ AST_REDIRECTING_FROM_NAME
Definition: channel.c:9139
@ AST_REDIRECTING_PRIV_ORIG_NUMBER
Definition: channel.c:9213
@ AST_REDIRECTING_PRIV_FROM_SUBADDRESS_VALID
Definition: channel.c:9211
@ AST_REDIRECTING_ORIG_NUMBER_PRESENTATION
Definition: channel.c:9176
@ AST_REDIRECTING_PRIV_TO_SUBADDRESS
Definition: channel.c:9195
@ AST_REDIRECTING_PRIV_ORIG_NAME_PRESENTATION
Definition: channel.c:9220
@ AST_REDIRECTING_TO_NUMBER_PRESENTATION
Definition: channel.c:9172
@ AST_REDIRECTING_FROM_NUMBER
Definition: channel.c:9138
@ AST_REDIRECTING_ORIG_NUMBER_PLAN
Definition: channel.c:9175
@ AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN
Definition: channel.c:9150
@ AST_REDIRECTING_PRIV_ORIG_SUBADDRESS
Definition: channel.c:9221
@ AST_REDIRECTING_TO_SUBADDRESS
Definition: channel.c:9152
@ AST_REDIRECTING_TO_NAME_CHAR_SET
Definition: channel.c:9169
char * ast_print_namedgroups(struct ast_str **buf, struct ast_namedgroups *group)
Print named call groups and named pickup groups.
Definition: channel.c:8056
void ast_party_name_copy(struct ast_party_name *dest, const struct ast_party_name *src)
Copy the source party name information to the destination party name.
Definition: channel.c:1599
int ast_channel_get_cc_agent_type(struct ast_channel *chan, char *agent_type, size_t size)
Find the appropriate CC agent type to use given a channel.
Definition: channel.c:10513
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2399
void ast_party_redirecting_reason_free(struct ast_party_redirecting_reason *doomed)
Destroy the redirecting reason contents.
Definition: channel.c:2116
#define STATE2STR_BUFSIZE
Definition: channel.c:98
void ast_party_caller_init(struct ast_party_caller *init)
Initialize the given caller structure.
Definition: channel.c:1978
void ast_tonepair_stop(struct ast_channel *chan)
Definition: channel.c:7595
struct ast_channel * ast_waitfor_n(struct ast_channel **c, int n, int *ms)
Waits for input on a group of channels Wait for input on an array of channels for a given # of millis...
Definition: channel.c:3157
int ast_channel_has_audio_frame_or_monitor(struct ast_channel *chan)
Check if the channel has active audiohooks, active framehooks, or a monitor.
Definition: channel.c:2518
static void ast_dummy_channel_destructor(void *obj)
Free a dummy channel structure.
Definition: channel.c:2333
General Asterisk PBX channel definitions.
void ast_channel_internal_alertpipe_swap(struct ast_channel *chan1, struct ast_channel *chan2)
Swap the interal alertpipe between two channels.
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
const char * ast_channel_name(const struct ast_channel *chan)
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:266
struct ast_bridge * ast_channel_internal_bridge(const struct ast_channel *chan)
struct timeval ast_channel_answertime(struct ast_channel *chan)
void ast_channel_named_pickupgroups_set(struct ast_channel *chan, struct ast_namedgroups *value)
int(* ast_timing_func_t)(const void *data)
Definition: channel.h:899
struct ast_channel * ast_channel_masq(const struct ast_channel *chan)
int ast_channel_blocker_tid(const struct ast_channel *chan)
void ast_channel_stream_set(struct ast_channel *chan, struct ast_filestream *value)
void ast_channel_visible_indication_set(struct ast_channel *chan, int value)
const char * ast_channel_blockproc(const struct ast_channel *chan)
void ast_channel_caller_set(struct ast_channel *chan, struct ast_party_caller *value)
@ AST_CHAN_TP_INTERNAL
Channels with this particular technology are an implementation detail of Asterisk and should generall...
Definition: channel.h:971
@ AST_CHAN_TP_SEND_TEXT_DATA
Channels have this property if they implement send_text_data.
Definition: channel.h:975
void * ast_channel_tech_pvt(const struct ast_channel *chan)
void ast_channel_dialed_set(struct ast_channel *chan, struct ast_party_dialed *value)
struct ast_format * ast_channel_rawreadformat(struct ast_channel *chan)
#define DEBUGCHAN_FLAG
Definition: channel.h:857
void * ast_channel_music_state(const struct ast_channel *chan)
unsigned int ast_channel_fin(const struct ast_channel *chan)
const char * ast_channel_latest_musicclass(const struct ast_channel *chan)
void ast_channel_callid_cleanup(struct ast_channel *chan)
void ast_channel_set_oldwriteformat(struct ast_channel *chan, struct ast_format *format)
void ast_channel_softhangup_internal_flag_clear(struct ast_channel *chan, int value)
struct varshead * ast_channel_varshead(struct ast_channel *chan)
void ast_channel_generator_set(struct ast_channel *chan, struct ast_generator *value)
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition: channel.h:1258
void ast_channel_sending_dtmf_digit_set(struct ast_channel *chan, char value)
void * ast_channel_timingdata(const struct ast_channel *chan)
int ast_channel_internal_alert_readfd(struct ast_channel *chan)
ast_channel_requestor_relationship
Definition: channel.h:1475
@ AST_CHANNEL_REQUESTOR_BRIDGE_PEER
Definition: channel.h:1477
@ AST_CHANNEL_REQUESTOR_REPLACEMENT
Definition: channel.h:1479
#define AST_GENERATOR_FD
Definition: channel.h:203
void ast_channel_dtmf_tv_set(struct ast_channel *chan, struct timeval *value)
struct ast_flags * ast_channel_snapshot_segment_flags(struct ast_channel *chan)
#define DATASTORE_INHERIT_FOREVER
Definition: channel.h:192
#define CHECK_BLOCKING(c)
Set the blocking indication on the channel.
Definition: channel.h:2871
void ast_channel_internal_swap_endpoint_forward(struct ast_channel *a, struct ast_channel *b)
Swap endpoint_forward between two channels.
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
const char * ast_channel_musicclass(const struct ast_channel *chan)
int ast_channel_fdno(const struct ast_channel *chan)
void ast_channel_internal_fd_clear_all(struct ast_channel *chan)
void ast_channel_internal_alertpipe_close(struct ast_channel *chan)
void ast_channel_answertime_set(struct ast_channel *chan, struct timeval *value)
void ast_channel_hold_state_set(struct ast_channel *chan, int value)
#define ast_channel_lock(chan)
Definition: channel.h:2922
struct ast_trans_pvt * ast_channel_readtrans(const struct ast_channel *chan)
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
struct timeval ast_channel_sending_dtmf_tv(const struct ast_channel *chan)
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
struct ast_trans_pvt * ast_channel_writetrans(const struct ast_channel *chan)
void ast_channel_vstreamid_set(struct ast_channel *chan, int value)
static const char ast_stream_topology_changed_external[]
Set as the change source reason when a channel stream topology has been changed externally as a resul...
Definition: channel.h:221
void ast_channel_timingdata_set(struct ast_channel *chan, void *value)
struct ast_cdr * ast_channel_cdr(const struct ast_channel *chan)
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
void ast_channel_redirecting_set(struct ast_channel *chan, struct ast_party_redirecting *value)
unsigned long long ast_group_t
Definition: channel.h:213
ast_channel_error
Definition: channel.h:4793
@ AST_CHANNEL_ERROR_ID_EXISTS
Definition: channel.h:4797
int ast_channel_priority(const struct ast_channel *chan)
void ast_channel_writetrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
void ast_channel_streamid_set(struct ast_channel *chan, int value)
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2947
void ast_channel_generatordata_set(struct ast_channel *chan, void *value)
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2929
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
void ast_channel_softhangup_internal_flag_set(struct ast_channel *chan, int value)
ast_callid ast_channel_callid(const struct ast_channel *chan)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
const char * ast_channel_accountcode(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
char ast_channel_dtmf_digit_to_emulate(const struct ast_channel *chan)
void ast_channel_timingfd_set(struct ast_channel *chan, int value)
#define AST_MUTE_DIRECTION_READ
Definition: channel.h:4712
pthread_t ast_channel_blocker(const struct ast_channel *chan)
ama_flags
Channel AMA Flags.
Definition: channel.h:1177
@ AST_AMA_DOCUMENTATION
Definition: channel.h:1181
@ AST_AMA_OMIT
Definition: channel.h:1179
@ AST_AMA_NONE
Definition: channel.h:1178
@ AST_AMA_BILLING
Definition: channel.h:1180
void ast_channel_sending_dtmf_tv_set(struct ast_channel *chan, struct timeval value)
#define ast_channel_trylock(chan)
Definition: channel.h:2924
const char * ast_channel_parkinglot(const struct ast_channel *chan)
ast_channel_adsicpe
Definition: channel.h:868
void ast_channel_internal_swap_topics(struct ast_channel *a, struct ast_channel *b)
Swap topics beteween two channels.
#define AST_ALERT_FD
Definition: channel.h:200
const char * ast_channel_peeraccount(const struct ast_channel *chan)
struct timeval ast_channel_creationtime(struct ast_channel *chan)
struct ast_bridge_channel * ast_channel_internal_bridge_channel(const struct ast_channel *chan)
struct ast_framehook_list * ast_channel_framehooks(const struct ast_channel *chan)
void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value)
int ast_channel_fd(const struct ast_channel *chan, int which)
void ast_channel_timer_set(struct ast_channel *chan, struct ast_timer *value)
void ast_channel_internal_fd_set(struct ast_channel *chan, int which, int value)
void ast_channel_fin_set(struct ast_channel *chan, unsigned int value)
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format)
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
enum ama_flags ast_channel_amaflags(const struct ast_channel *chan)
void ast_channel_readtrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
void * ast_channel_generatordata(const struct ast_channel *chan)
struct ast_format * ast_channel_rawwriteformat(struct ast_channel *chan)
void ast_channel_set_is_t38_active_nolock(struct ast_channel *chan, int is_t38_active)
Variant of ast_channel_set_is_t38_active. Use this if the channel is already locked prior to calling.
const char * ast_channel_hangupsource(const struct ast_channel *chan)
unsigned int ast_channel_fout(const struct ast_channel *chan)
struct ast_stream_topology * ast_channel_get_stream_topology(const struct ast_channel *chan)
Retrieve the topology of streams on a channel.
#define AST_NUM_CHANNEL_BUCKETS
Definition: channel.h:155
int ast_channel_hangupcause(const struct ast_channel *chan)
int ast_channel_timingfd(const struct ast_channel *chan)
void ast_channel_fdno_set(struct ast_channel *chan, int value)
#define AST_TIMING_FD
Definition: channel.h:201
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format)
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
@ AST_PARTY_CHAR_SET_ISO8859_1
Definition: channel.h:244
void ast_channel_creationtime_set(struct ast_channel *chan, struct timeval *value)
struct ast_tone_zone * ast_channel_zone(const struct ast_channel *chan)
int ast_channel_dialed_causes_add(const struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen)
Add cause code information to the channel.
void ast_channel_named_callgroups_set(struct ast_channel *chan, struct ast_namedgroups *value)
int ast_channel_alert_write(struct ast_channel *chan)
struct ast_readq_list * ast_channel_readq(struct ast_channel *chan)
ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan)
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
void ast_channel_dtmf_digit_to_emulate_set(struct ast_channel *chan, char value)
#define AST_CHANNEL_NAME
Definition: channel.h:171
void ast_channel_softhangup_internal_flag_add(struct ast_channel *chan, int value)
struct timeval * ast_channel_whentohangup(struct ast_channel *chan)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
struct ast_stream * ast_channel_get_default_stream(struct ast_channel *chan, enum ast_media_type type)
Retrieve the default stream of a specific media type on a channel.
struct ast_filestream * ast_channel_vstream(const struct ast_channel *chan)
ast_alert_status_t ast_channel_internal_alert_read(struct ast_channel *chan)
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
@ AST_SOFTHANGUP_ASYNCGOTO
Definition: channel.h:1126
@ AST_SOFTHANGUP_EXPLICIT
Definition: channel.h:1148
@ AST_SOFTHANGUP_DEV
Definition: channel.h:1121
@ AST_SOFTHANGUP_TIMEOUT
Definition: channel.h:1138
@ AST_SOFTHANGUP_SHUTDOWN
Definition: channel.h:1131
void ast_channel_internal_swap_uniqueid_and_linkedid(struct ast_channel *a, struct ast_channel *b)
Swap uniqueid and linkedid beteween two channels.
struct ast_generator * ast_channel_generator(const struct ast_channel *chan)
int ast_channel_unbridged(struct ast_channel *chan)
This function will check if the bridge needs to be re-evaluated due to external changes.
int ast_channel_hold_state(const struct ast_channel *chan)
void ast_channel_emulate_dtmf_duration_set(struct ast_channel *chan, unsigned int value)
void ast_channel_amaflags_set(struct ast_channel *chan, enum ama_flags value)
const char * ast_channel_language(const struct ast_channel *chan)
struct ast_party_connected_line * ast_channel_connected_indicated(struct ast_channel *chan)
void ast_channel_cdr_set(struct ast_channel *chan, struct ast_cdr *value)
void ast_channel_context_set(struct ast_channel *chan, const char *value)
void ast_channel_connected_set(struct ast_channel *chan, struct ast_party_connected_line *value)
void ast_channel_timingfunc_set(struct ast_channel *chan, ast_timing_func_t value)
struct ast_sched_context * ast_channel_sched(const struct ast_channel *chan)
void ast_channel_state_set(struct ast_channel *chan, enum ast_channel_state)
int ast_channel_fd_count(const struct ast_channel *chan)
Retrieve the number of file decriptor positions present on the channel.
#define AST_MUTE_DIRECTION_WRITE
Definition: channel.h:4713
struct ast_frame * ast_channel_dtmff(struct ast_channel *chan)
void ast_channel_internal_swap_snapshots(struct ast_channel *a, struct ast_channel *b)
Swap snapshots beteween two channels.
unsigned int ast_channel_emulate_dtmf_duration(const struct ast_channel *chan)
static int ast_add_fd(struct pollfd *pfd, int fd)
if fd is a valid descriptor, set *pfd with the descriptor
Definition: channel.h:2819
const char * ast_channel_call_forward(const struct ast_channel *chan)
@ AST_FLAG_ZOMBIE
Definition: channel.h:987
@ AST_FLAG_DISABLE_DEVSTATE_CACHE
Definition: channel.h:1029
@ AST_FLAG_SNAPSHOT_STAGE
Definition: channel.h:1050
@ AST_FLAG_OUTGOING
Definition: channel.h:999
@ AST_FLAG_IN_AUTOLOOP
Definition: channel.h:997
@ AST_FLAG_END_DTMF_ONLY
Definition: channel.h:1007
@ AST_FLAG_DEAD
Definition: channel.h:1045
@ AST_FLAG_EXCEPTION
Definition: channel.h:989
@ AST_FLAG_EMULATE_DTMF
Definition: channel.h:1004
@ AST_FLAG_IN_DTMF
Definition: channel.h:1001
@ AST_FLAG_WRITE_INT
Definition: channel.h:983
@ AST_FLAG_DEFER_DTMF
Definition: channel.h:981
@ AST_FLAG_BLOCKING
Definition: channel.h:985
@ AST_FLAG_ORIGINATED
Definition: channel.h:1039
@ AST_FLAG_TIMINGDATA_IS_AO2_OBJ
Definition: channel.h:1054
@ AST_FLAG_MOH
Definition: channel.h:991
#define AST_JITTERBUFFER_FD
Definition: channel.h:204
struct ast_filestream * ast_channel_stream(const struct ast_channel *chan)
struct ast_pbx * ast_channel_pbx(const struct ast_channel *chan)
void ast_channel_fout_set(struct ast_channel *chan, unsigned int value)
struct ast_autochan_list * ast_channel_autochans(struct ast_channel *chan)
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
void ast_channel_zone_set(struct ast_channel *chan, struct ast_tone_zone *value)
struct ast_channel * ast_channel_masqr(const struct ast_channel *chan)
int ast_channel_softhangup_internal_flag(struct ast_channel *chan)
struct timeval * ast_channel_dtmf_tv(struct ast_channel *chan)
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
char ast_channel_sending_dtmf_digit(const struct ast_channel *chan)
int ast_channel_visible_indication(const struct ast_channel *chan)
#define FRAMECOUNT_INC(x)
Definition: channel.h:860
struct ast_timer * ast_channel_timer(const struct ast_channel *chan)
struct ast_hangup_handler_list * ast_channel_hangup_handlers(struct ast_channel *chan)
void ast_channel_masqr_set(struct ast_channel *chan, struct ast_channel *value)
void ast_channel_callid_set(struct ast_channel *chan, ast_callid value)
void ast_channel_internal_alertpipe_clear(struct ast_channel *chan)
void ast_channel_priority_set(struct ast_channel *chan, int value)
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value)
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition: channel.h:2969
int ast_channel_fd_isset(const struct ast_channel *chan, int which)
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
int ast_channel_is_multistream(struct ast_channel *chan)
Determine if a channel is multi-stream capable.
int ast_channel_internal_alertpipe_init(struct ast_channel *chan)
void ast_channel_sched_set(struct ast_channel *chan, struct ast_sched_context *value)
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
const char * ast_channel_exten(const struct ast_channel *chan)
struct ast_datastore_list * ast_channel_datastores(struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2923
void ast_channel_masq_set(struct ast_channel *chan, struct ast_channel *value)
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
void ast_channel_vstream_set(struct ast_channel *chan, struct ast_filestream *value)
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
int ast_channel_alert_writable(struct ast_channel *chan)
Internal channel functions for channel.c to use.
void ast_channel_internal_set_stream_topology_change_source(struct ast_channel *chan, void *change_source)
void ast_channel_internal_set_stream_topology(struct ast_channel *chan, struct ast_stream_topology *topology)
int ast_channel_internal_is_finalized(struct ast_channel *chan)
enum ast_channel_error ast_channel_internal_errno(void)
void ast_channel_internal_swap_stream_topology(struct ast_channel *chan1, struct ast_channel *chan2)
void ast_channel_internal_cleanup(struct ast_channel *chan)
struct ast_channel * __ast_channel_internal_alloc(void(*destructor)(void *obj), const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *file, int line, const char *function)
int ast_channel_internal_setup_topics(struct ast_channel *chan)
void ast_channel_internal_finalize(struct ast_channel *chan)
void ast_channel_internal_errno_set(enum ast_channel_error error)
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_MUTE
Definition: channelstate.h:47
@ AST_STATE_RING
Definition: channelstate.h:40
@ AST_STATE_DIALING_OFFHOOK
Definition: channelstate.h:44
@ AST_STATE_RINGING
Definition: channelstate.h:41
@ AST_STATE_PRERING
Definition: channelstate.h:45
@ AST_STATE_DOWN
Definition: channelstate.h:36
@ AST_STATE_OFFHOOK
Definition: channelstate.h:38
@ AST_STATE_BUSY
Definition: channelstate.h:43
@ AST_STATE_DIALING
Definition: channelstate.h:39
@ AST_STATE_UP
Definition: channelstate.h:42
@ AST_STATE_RESERVED
Definition: channelstate.h:37
Channel Variables.
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:60
#define ast_var_assign(name, value)
Definition: chanvars.h:40
const char * ast_var_full_name(const struct ast_var_t *var)
Definition: chanvars.c:75
const char * ast_var_value(const struct ast_var_t *var)
Definition: chanvars.c:80
void ast_var_delete(struct ast_var_t *var)
Definition: extconf.c:2471
Standard Command Line Interface.
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_SUCCESS
Definition: cli.h:44
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:197
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition: main/cli.c:2756
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define ESS(x)
Definition: cli.h:59
@ CLI_INIT
Definition: cli.h:152
@ CLI_GENERATE
Definition: cli.h:153
#define CLI_FAILURE
Definition: cli.h:46
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
ast_media_type
Types of media.
Definition: codec.h:30
@ AST_MEDIA_TYPE_AUDIO
Definition: codec.h:32
@ AST_MEDIA_TYPE_UNKNOWN
Definition: codec.h:31
@ AST_MEDIA_TYPE_IMAGE
Definition: codec.h:34
@ AST_MEDIA_TYPE_TEXT
Definition: codec.h:35
static void update(int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr)
Definition: codec_g726.c:367
#define attribute_const
Definition: compiler.h:41
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
int int32_t
Definition: db.h:60
short int16_t
Definition: db.h:59
Device state management.
@ AST_DEVSTATE_CACHABLE
Definition: devicestate.h:70
@ AST_DEVSTATE_NOT_CACHABLE
Definition: devicestate.h:69
int ast_devstate_changed_literal(enum ast_device_state state, enum ast_devstate_cache cachable, const char *device)
Tells Asterisk the State for Device is changed.
Definition: devicestate.c:471
@ AST_DEVICE_UNKNOWN
Definition: devicestate.h:53
static const float mf_tones[]
Definition: dsp.c:325
char connected
Definition: eagi_proxy.c:82
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int ast_endpoint_add_channel(struct ast_endpoint *endpoint, struct ast_channel *chan)
Adds a channel to the given endpoint.
long int flag
Definition: f2c.h:83
#define max(a, b)
Definition: f2c.h:198
Call Parking and Pickup API Includes code and algorithms from the Zapata library.
Generic File Format Support. Should be included by clients of the file handling routines....
int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int monfd)
Definition: file.c:1849
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:222
int ast_closestream(struct ast_filestream *f)
Closes a stream.
Definition: file.c:1111
#define AST_DIGIT_ANY
Definition: file.h:48
enum ast_media_type ast_format_get_type(const struct ast_format *format)
Get the media type of a format.
Definition: format.c:354
unsigned int ast_format_get_sample_rate(const struct ast_format *format)
Get the sample rate of a media format.
Definition: format.c:379
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
@ AST_FORMAT_CMP_EQUAL
Definition: format.h:36
@ AST_FORMAT_CMP_NOT_EQUAL
Definition: format.h:38
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
int ast_format_cache_is_slinear(struct ast_format *format)
Determines if a format is one of the cached slin formats.
Definition: format_cache.c:534
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
struct ast_format * ast_format_none
Built-in "null" format.
Definition: format_cache.c:246
struct ast_format * ast_format_cache_get_slin_by_rate(unsigned int rate)
Retrieve the best signed linear format given a sample rate.
Definition: format_cache.c:512
struct ast_format * ast_format_t140
Built-in cached t140 format.
Definition: format_cache.c:231
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:324
int ast_format_cap_empty(const struct ast_format_cap *cap)
Determine if a format cap has no formats in it.
Definition: format_cap.c:744
struct ast_format * ast_format_cap_get_best_by_type(const struct ast_format_cap *cap, enum ast_media_type type)
Get the most preferred format for a particular media type.
Definition: format_cap.c:417
void ast_format_cap_remove_by_type(struct ast_format_cap *cap, enum ast_media_type type)
Remove all formats matching a specific format type.
Definition: format_cap.c:523
@ AST_FORMAT_CAP_FLAG_DEFAULT
Definition: format_cap.h:38
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
const char * ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)
Get the names of codecs of a set of formats.
Definition: format_cap.c:734
int ast_format_cap_has_type(const struct ast_format_cap *cap, enum ast_media_type type)
Find out if the capabilities structure has any formats of a specific type.
Definition: format_cap.c:613
#define ast_format_cap_append(cap, format, framing)
Add format capability to capabilities structure.
Definition: format_cap.h:99
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition: format_cap.h:49
static const char name[]
Definition: format_mp3.c:68
static void write_stream(struct ogg_vorbis_desc *s, FILE *f)
Write out any pending encoded data.
FrameHook Architecture.
int ast_framehook_list_contains_no_active_of_type(struct ast_framehook_list *framehooks, enum ast_frame_type type)
Determine if a framehook list is free of active framehooks consuming a specific type of frame.
Definition: framehook.c:287
int ast_framehook_attach(struct ast_channel *chan, struct ast_framehook_interface *i)
Attach an framehook onto a channel for frame interception.
Definition: framehook.c:132
ast_framehook_event
These are the types of events that the framehook's event callback can receive.
Definition: framehook.h:151
@ AST_FRAMEHOOK_EVENT_WRITE
Definition: framehook.h:153
@ AST_FRAMEHOOK_EVENT_READ
Definition: framehook.h:152
struct ast_frame * ast_framehook_list_read_event(struct ast_framehook_list *framehooks, struct ast_frame *frame)
This is used by the channel API push a frame read event to a channel's framehook list.
Definition: framehook.c:318
int ast_framehook_detach(struct ast_channel *chan, int framehook_id)
Detach an framehook from a channel.
Definition: framehook.c:177
int ast_framehook_list_destroy(struct ast_channel *chan)
This is used by the channel API to detach and destroy all framehooks on a channel during channel dest...
Definition: framehook.c:206
void ast_framehook_list_fixup(struct ast_channel *old_chan, struct ast_channel *new_chan)
This is used by the channel API during a masquerade operation to move all mobile framehooks from the ...
Definition: framehook.c:223
int ast_framehook_list_contains_no_active(struct ast_framehook_list *framehooks)
Determine if a framehook list is free of active framehooks or not.
Definition: framehook.c:282
int ast_framehook_list_is_empty(struct ast_framehook_list *framehooks)
Determine if an framehook list is empty or not.
Definition: framehook.c:274
struct ast_frame * ast_framehook_list_write_event(struct ast_framehook_list *framehooks, struct ast_frame *frame)
This is used by the channel API push a frame write event to a channel's framehook list.
Definition: framehook.c:313
#define AST_FRAMEHOOK_INTERFACE_VERSION
Definition: framehook.h:227
direction
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:888
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
globally accessible channel datastores
const struct ast_datastore_info secure_call_info
#define SCOPE_TRACE(__level,...)
struct stasis_message_type * ast_channel_masquerade_type(void)
Message type for when a channel is being masqueraded.
void ast_channel_publish_varset(struct ast_channel *chan, const char *variable, const char *value)
Publish a ast_channel_publish_varset for a channel.
struct stasis_message_type * ast_channel_hold_type(void)
Message type for when a channel is placed on hold.
struct stasis_message_type * ast_channel_dtmf_begin_type(void)
Message type for when DTMF begins on a channel.
void ast_channel_snapshot_invalidate_segment(struct ast_channel *chan, enum ast_channel_snapshot_segment_invalidation segment)
Invalidate a channel snapshot segment from being reused.
void ast_channel_publish_final_snapshot(struct ast_channel *chan)
Send the final channel snapshot for a channel, thus removing it from cache.
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
struct stasis_message_type * ast_channel_unhold_type(void)
Message type for when a channel is removed from hold.
struct stasis_message_type * ast_channel_hangup_request_type(void)
Message type for when a hangup is requested on a channel.
struct stasis_message_type * ast_channel_flash_type(void)
Message type for when a hook flash occurs on a channel.
struct stasis_message_type * ast_channel_dtmf_end_type(void)
Message type for when DTMF ends on a channel.
struct stasis_message_type * ast_channel_wink_type(void)
Message type for when a wink occurs on a channel.
void ast_channel_publish_snapshot(struct ast_channel *chan)
Publish a ast_channel_snapshot for a channel.
void ast_channel_publish_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
Publish a channel blob message.
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
@ AST_CHANNEL_SNAPSHOT_INVALIDATE_CALLER
@ AST_CHANNEL_SNAPSHOT_INVALIDATE_CONNECTED
const char * ast_msg_data_get_attribute(struct ast_msg_data *msg, enum ast_msg_data_attribute_type attribute_type)
Get attribute from ast_msg_data.
struct ast_msg_data * ast_msg_data_alloc(enum ast_msg_data_source_type source, struct ast_msg_data_attribute attributes[], size_t count)
Allocates an ast_msg_data structure.
@ AST_MSG_DATA_ATTR_BODY
Definition: message.h:458
@ AST_MSG_DATA_ATTR_TO
Definition: message.h:455
@ AST_MSG_DATA_ATTR_FROM
Definition: message.h:456
@ AST_MSG_DATA_ATTR_CONTENT_TYPE
Definition: message.h:457
@ AST_MSG_DATA_SOURCE_TYPE_UNKNOWN
Definition: message.h:447
unsigned int option_dtmfminduration
Definition: options.c:83
static ENTRY retval
Definition: hsearch.c:50
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
@ AST_GETDATA_FAILED
@ AST_GETDATA_INTERRUPTED
@ AST_GETDATA_COMPLETE
@ AST_GETDATA_TIMEOUT
@ AST_GETDATA_EMPTY_END_TERMINATED
int ast_app_run_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_location, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:328
int ast_app_group_update(struct ast_channel *oldchan, struct ast_channel *newchan)
Update all group counting for a channel to a new one.
Definition: main/app.c:2290
int ast_app_group_discard(struct ast_channel *chan)
Discard all group counting for a channel.
Definition: main/app.c:2309
int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:297
char * strsep(char **str, const char *delims)
#define ast_variable_new(name, value, filename)
Asterisk internal frame definitions.
@ AST_FRFLAG_REQUEUED
@ AST_T38_TERMINATED
@ AST_T38_REFUSED
@ AST_T38_REQUEST_TERMINATE
@ AST_T38_NEGOTIATED
@ AST_T38_REQUEST_NEGOTIATE
@ AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO
@ AST_FRAME_READ_ACTION_SEND_TEXT
@ AST_FRAME_READ_ACTION_SEND_TEXT_DATA
#define AST_OPTION_DEVICE_NAME
#define ast_frisolate(fr)
Makes a frame independent of any static storage.
void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix)
Definition: main/frame.c:731
#define ast_frdup(fr)
Copies a frame.
ast_control_transfer
@ AST_TRANSFER_SUCCESS
#define AST_OPTION_FORMAT_WRITE
#define ast_frfree(fr)
#define AST_HTML_URL
#define AST_MALLOCD_DATA
#define AST_OPTION_CC_AGENT_TYPE
#define AST_OPTION_SECURE_MEDIA
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
#define AST_OPTION_FORMAT_READ
#define AST_OPTION_SECURE_SIGNALING
ast_frame_type
Frame types.
@ AST_FRAME_VIDEO
@ AST_FRAME_NULL
@ AST_FRAME_HTML
@ AST_FRAME_IMAGE
@ AST_FRAME_DTMF_END
@ AST_FRAME_DTMF_BEGIN
@ AST_FRAME_BRIDGE_ACTION_SYNC
@ AST_FRAME_VOICE
@ AST_FRAME_RTCP
@ AST_FRAME_MODEM
@ AST_FRAME_TEXT_DATA
@ AST_FRAME_CONTROL
@ AST_FRAME_BRIDGE_ACTION
@ AST_FRAME_TEXT
ast_control_frame_type
Internal control frame subtype field values.
@ AST_CONTROL_RING
@ AST_CONTROL_SRCUPDATE
@ AST_CONTROL_RECORD_CANCEL
@ AST_CONTROL_WINK
@ AST_CONTROL_PROGRESS
@ AST_CONTROL_STREAM_TOPOLOGY_SOURCE_CHANGED
@ AST_CONTROL_OFFHOOK
@ AST_CONTROL_STREAM_RESTART
@ AST_CONTROL_STREAM_SUSPEND
@ AST_CONTROL_RADIO_UNKEY
@ AST_CONTROL_BUSY
@ AST_CONTROL_UNHOLD
@ AST_CONTROL_VIDUPDATE
@ AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE
@ AST_CONTROL_STREAM_REVERSE
@ AST_CONTROL_PROCEEDING
@ AST_CONTROL_REDIRECTING
@ AST_CONTROL_TAKEOFFHOOK
@ AST_CONTROL_MCID
@ AST_CONTROL_T38_PARAMETERS
@ AST_CONTROL_READ_ACTION
@ AST_CONTROL_RECORD_STOP
@ AST_CONTROL_CONGESTION
@ AST_CONTROL_CC
@ AST_CONTROL_ANSWER
@ AST_CONTROL_RECORD_MUTE
@ AST_CONTROL_RINGING
@ AST_CONTROL_HANGUP
@ AST_CONTROL_STREAM_STOP
@ AST_CONTROL_RADIO_KEY
@ AST_CONTROL_HOLD
@ AST_CONTROL_OPTION
@ AST_CONTROL_STREAM_TOPOLOGY_CHANGED
@ AST_CONTROL_CONNECTED_LINE
@ AST_CONTROL_END_OF_Q
@ AST_CONTROL_TRANSFER
@ AST_CONTROL_STREAM_FORWARD
@ AST_CONTROL_FLASH
@ AST_CONTROL_RECORD_SUSPEND
@ AST_CONTROL_AOC
@ AST_CONTROL_SRCCHANGE
@ AST_CONTROL_INCOMPLETE
@ _XXX_AST_CONTROL_T38
@ AST_CONTROL_MASQUERADE_NOTIFY
@ AST_CONTROL_PVT_CAUSE_CODE
@ AST_CONTROL_UPDATE_RTP_PEER
struct ast_frame ast_null_frame
Definition: main/frame.c:79
#define ast_debug(level,...)
Log a DEBUG message.
unsigned int ast_callid
void ast_log_callid(int level, const char *file, int line, const char *function, ast_callid callid, const char *fmt,...)
Used for sending a log message with a known call_id This is a modified logger function which is funct...
Definition: logger.c:2489
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_NOTICE
#define LOG_WARNING
#define LOG_DTMF
Tone Indication Support.
static struct ast_tone_zone_sound * ast_tone_zone_sound_unref(struct ast_tone_zone_sound *ts)
Release a reference to an ast_tone_zone_sound.
Definition: indications.h:227
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
Definition: indications.c:302
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
Definition: indications.c:393
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
Definition: indications.c:461
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:205
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
AST_JSON_INT_T ast_json_int_t
Primarily used to cast when packing to an "I" type.
Definition: json.h:87
A set of macros to manage forward-linked lists.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:681
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
Definition: linkedlists.h:225
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
Definition: linkedlists.h:429
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_LIST_INSERT_LIST_AFTER(head, list, elm, field)
Inserts a whole list after a specific entry in a list.
Definition: linkedlists.h:812
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
#define AST_RWLIST_HEAD_INIT(head)
Initializes an rwlist head structure.
Definition: linkedlists.h:639
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized.
Definition: linkedlists.h:333
#define AST_RWLIST_REMOVE_HEAD
Definition: linkedlists.h:844
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:410
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:615
#define AST_RWLIST_HEAD(name, type)
Defines a structure to be used to hold a read/write list of specified type.
Definition: linkedlists.h:199
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:711
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
Definition: linkedlists.h:856
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:529
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:557
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:718
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:741
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
#define AST_LIST_APPEND_LIST(head, list, field)
Appends a whole list to the tail of a list.
Definition: linkedlists.h:783
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:421
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439
Asterisk locking-related definitions:
#define CHANNEL_DEADLOCK_AVOIDANCE(chan)
Definition: lock.h:474
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:757
#define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc)
Scoped Locks.
Definition: lock.h:583
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
Definition: lock.h:589
#define AST_MUTEX_DEFINE_STATIC(mutex)
Definition: lock.h:520
static struct groups groups
size_t current
Definition: main/cli.c:113
int errno
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
#define EVENT_FLAG_CALL
Definition: manager.h:76
#define ast_manager_event(chan, category, event, contents,...)
Definition: manager.h:255
int ast_max_forwards_decrement(struct ast_channel *chan)
Decrement the max forwards count for a particular channel.
Definition: max_forwards.c:135
Out-of-call text message support.
Header for providers of file and format handling routines. Clients of these routines should include "...
Music on hold handling.
def info(msg)
#define ast_opt_transcode_via_slin
Definition: options.h:118
#define ast_opt_generic_plc_on_equal_codecs
Definition: options.h:136
#define ast_opt_generic_plc
Definition: options.h:134
char ast_defaultlanguage[]
Definition: options.c:98
#define ast_opt_transmit_silence
Definition: options.h:124
static int frames
Definition: parser.c:51
Asterisk file paths, configured in asterisk.conf.
Core PBX routines and definitions.
void ast_pbx_hangup_handler_destroy(struct ast_channel *chan)
Destroy the hangup handler container on a channel.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
int ast_func_read2(struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen)
executes a read operation on a function
void ast_pbx_hangup_handler_init(struct ast_channel *chan)
Init the hangup handler container on a channel.
int ast_pbx_hangup_handler_run(struct ast_channel *chan)
Run all hangup handlers on the channel.
int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
executes a write operation on a function
int plc_fillin(plc_state_t *s, int16_t amp[], int len)
Fill-in a block of missing audio samples.
Definition: plc.c:175
int plc_rx(plc_state_t *s, int16_t amp[], int len)
Process a block of received audio samples.
Definition: plc.c:132
#define ast_poll(a, b, c)
Definition: poll-compat.h:88
static char url[512]
struct stasis_forward * sub
Definition: res_corosync.c:240
#define NULL
Definition: resample.c:96
#define M_PI
Definition: resample.c:83
Say numbers and dates (maybe words one day too)
SAY_EXTERN int(* ast_say_money_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_money_str_full)
Definition: say.h:170
SAY_EXTERN int(* ast_say_number_full)(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd) SAY_INIT(ast_say_number_full)
Same as ast_say_number() with audiofd for received audio and returns 1 on ctrlfd being readable.
Definition: say.h:86
SAY_EXTERN int(* ast_say_enumeration_full)(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd) SAY_INIT(ast_say_enumeration_full)
Same as ast_say_enumeration() with audiofd for received audio and returns 1 on ctrlfd being readable.
Definition: say.h:125
SAY_EXTERN int(* ast_say_ordinal_full)(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd) SAY_INIT(ast_say_ordinal_full)
Same as ast_say_number() with audiofd for received audio and returns 1 on ctrlfd being readable.
Definition: say.h:105
SAY_EXTERN int(* ast_say_character_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity, int audiofd, int ctrlfd) SAY_INIT(ast_say_character_str_full)
Definition: say.h:194
SAY_EXTERN int(* ast_say_digit_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_digit_str_full)
Same as ast_say_digit_str() with audiofd for received audio and returns 1 on ctrlfd being readable.
Definition: say.h:162
ast_say_case_sensitivity
Controls how ast_say_character_str denotes the case of characters in a string.
Definition: say.h:181
SAY_EXTERN int(* ast_say_phonetic_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_phonetic_str_full)
Definition: say.h:199
Scheduler Routines (derived from cheops)
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
Definition: sched.c:271
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
Definition: sched.c:238
A machine to gather up arbitrary frames and convert them to raw slinear on demand.
int ast_stasis_channels_init(void)
Initialize the stasis channel topic and message types.
Media Stream API.
struct ast_stream_topology * ast_stream_topology_alloc(void)
Create a stream topology.
Definition: stream.c:650
int ast_stream_get_position(const struct ast_stream *stream)
Get the position of the stream in the topology.
Definition: stream.c:500
const char * ast_stream_topology_to_str(const struct ast_stream_topology *topology, struct ast_str **buf)
Get a string representing the topology for debugging/display purposes.
Definition: stream.c:936
struct ast_stream * ast_stream_topology_get_stream(const struct ast_stream_topology *topology, unsigned int position)
Get a specific stream from the topology.
Definition: stream.c:788
int ast_stream_topology_get_count(const struct ast_stream_topology *topology)
Get the number of streams in a topology.
Definition: stream.c:765
enum ast_media_type ast_stream_get_type(const struct ast_stream *stream)
Get the media type of a stream.
Definition: stream.c:316
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
Definition: stream.c:743
struct ast_stream_topology * ast_stream_topology_create_from_format_cap(struct ast_format_cap *cap)
A helper function that, given a format capabilities structure, creates a topology and separates the m...
Definition: stream.c:848
struct ast_format_cap * ast_stream_topology_get_formats(struct ast_stream_topology *topology)
Create a format capabilities structure representing the topology.
Definition: stream.c:930
int ast_stream_topology_equal(const struct ast_stream_topology *left, const struct ast_stream_topology *right)
Compare two stream topologies to see if they are equal.
Definition: stream.c:696
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1259
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ast_str_tmp(init_len, __expr)
Provides a temporary ast_str and returns a copy of its buffer.
Definition: strings.h:1189
#define ast_str_alloca(init_len)
Definition: strings.h:848
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
Definition: strings.h:1303
char * ast_trim_blanks(char *str)
Trims trailing whitespace characters from a string.
Definition: strings.h:186
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Checks whether a string begins with another.
Definition: strings.h:97
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:161
Generic container type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821
Structure to pass both assignedid values to channel drivers.
Definition: channel.h:604
Structure that contains information regarding a channel in a bridge.
struct ast_channel * chan
Structure that contains features information.
Structure that contains information about a bridge.
Definition: bridge.h:349
struct ao2_iterator simple_iterator
Definition: channel.c:1353
struct ao2_iterator * active_iterator
Definition: channel.c:1357
Structure to describe a channel "technology", ie a channel driver See for examples:
Definition: channel.h:628
int(*const write)(struct ast_channel *chan, struct ast_frame *frame)
Write a frame, in standard format (see frame.h)
Definition: channel.h:750
struct ast_frame *(*const read)(struct ast_channel *chan)
Read a frame (or chain of frames from the same stream), in standard format (see frame....
Definition: channel.h:734
int(*const write_stream)(struct ast_channel *chan, int stream_num, struct ast_frame *frame)
Write a frame on a specific stream, in standard format (see frame.h)
Definition: channel.h:753
struct ast_frame *(*const read_stream)(struct ast_channel *chan)
Read a frame (or chain of frames from the same stream), in standard format (see frame....
Definition: channel.h:747
int(*const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen)
Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTI...
Definition: channel.h:771
int(*const send_text)(struct ast_channel *chan, const char *text)
Display or transmit text.
Definition: channel.h:756
int(*const write_text)(struct ast_channel *chan, struct ast_frame *frame)
Write a text frame, in standard format.
Definition: channel.h:789
int(*const call)(struct ast_channel *chan, const char *addr, int timeout)
Make a call.
Definition: channel.h:701
enum ast_bridge_result(*const early_bridge)(struct ast_channel *c0, struct ast_channel *c1)
Bridge two channels of the same type together (early)
Definition: channel.h:768
int(*const send_text_data)(struct ast_channel *chan, struct ast_msg_data *data)
Display or transmit text with data.
Definition: channel.h:844
int(*const hangup)(struct ast_channel *chan)
Hangup (and possibly destroy) the channel.
Definition: channel.h:704
const char *const type
Definition: channel.h:629
int(*const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen)
Query a given option. Called with chan locked.
Definition: channel.h:780
int(*const setoption)(struct ast_channel *chan, int option, void *data, int datalen)
Set a given option. Called with chan locked.
Definition: channel.h:777
int(*const answer)(struct ast_channel *chan)
Answer the channel.
Definition: channel.h:707
const char *const description
Definition: channel.h:630
int(* pre_call)(struct ast_channel *chan, const char *sub_args)
Execute a Gosub call on the channel in a technology specific way before a call is placed.
Definition: channel.h:841
int(*const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration)
Stop sending a literal DTMF digit.
Definition: channel.h:690
int(*const transfer)(struct ast_channel *chan, const char *newdest)
Blind transfer other side (see app_transfer.c and ast_transfer()
Definition: channel.h:783
int(*const write_video)(struct ast_channel *chan, struct ast_frame *frame)
Write a frame, in standard format.
Definition: channel.h:786
struct ast_frame *(*const exception)(struct ast_channel *chan)
Handle an exception, reading a frame.
Definition: channel.h:765
int(*const send_html)(struct ast_channel *chan, int subclass, const char *data, int len)
Send HTML data.
Definition: channel.h:762
int(*const answer_with_stream_topology)(struct ast_channel *chan, struct ast_stream_topology *topology)
Answer the channel with topology.
Definition: channel.h:720
Main Channel structure associated with a channel.
struct ast_channel_id uniqueid
struct ast_party_connected_line connected
Channel Connected Line ID information.
const ast_string_field accountcode
struct ast_channel::@331 fds
char exten[AST_MAX_EXTENSION]
const char * data
const struct ast_channel_tech * tech
struct ast_format * writeformat
struct ast_party_redirecting redirecting
Redirecting/Diversion information.
struct ast_party_dialed dialed
Dialed/Called information.
char context[AST_MAX_CONTEXT]
const ast_string_field name
struct ast_format * readformat
struct ast_flags flags
struct ast_party_caller caller
Channel Caller ID information.
descriptor for a cli entry.
Definition: cli.h:171
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
char chan_name[AST_CHANNEL_NAME]
enum ast_frame_read_action action
enum ast_control_t38 request_response
Structure for a data store type.
Definition: datastore.h:31
void *(* duplicate)(void *data)
Definition: datastore.h:33
void(* chan_fixup)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
Fix up channel references on the masquerading channel.
Definition: datastore.h:48
const char * type
Definition: datastore.h:32
void(* chan_breakdown)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
Fix up channel references on the channel being masqueraded into.
Definition: datastore.h:60
Structure for a data store object.
Definition: datastore.h:64
const struct ast_datastore_info * info
Definition: datastore.h:67
const char * uid
Definition: datastore.h:65
void * data
Definition: datastore.h:66
unsigned int inheritance
Definition: datastore.h:69
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
Definition of a media format.
Definition: format.c:43
struct ast_format * format
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
union ast_frame::@226 data
enum ast_frame_type frametype
struct ast_frame * next
const char * src
void(* digit)(struct ast_channel *chan, char digit)
Definition: channel.h:235
int(* generate)(struct ast_channel *chan, void *data, int len, int samples)
Definition: channel.h:233
void *(* alloc)(struct ast_channel *chan, void *params)
Definition: channel.h:226
void(* release)(struct ast_channel *chan, void *data)
Definition: channel.h:228
void(* write_format_change)(struct ast_channel *chan, void *data)
Definition: channel.h:238
Abstract JSON element (object, array, string, int, ...).
enum ast_msg_data_attribute_type type
Definition: message.h:463
Structure used to transport a message through the frame core.
Caller Party information.
Definition: channel.h:418
struct ast_party_id priv
Private caller party ID.
Definition: channel.h:430
struct ast_party_id id
Caller party ID.
Definition: channel.h:420
int ani2
Automatic Number Identification 2 (Info Digits)
Definition: channel.h:433
struct ast_party_id ani
Automatic Number Identification (ANI)
Definition: channel.h:427
Connected Line/Party information.
Definition: channel.h:456
int source
Information about the source of an update.
Definition: channel.h:482
struct ast_party_id priv
Private connected party ID.
Definition: channel.h:468
struct ast_party_id id
Connected party ID.
Definition: channel.h:458
int ani2
Automatic Number Identification 2 (Info Digits)
Definition: channel.h:475
struct ast_party_id ani
Automatic Number Identification (ANI)
Definition: channel.h:465
Dialed/Called Party information.
Definition: channel.h:378
struct ast_party_dialed::@208 number
Dialed/Called number.
struct ast_party_subaddress subaddress
Dialed/Called subaddress.
Definition: channel.h:391
char * str
Subscriber phone number (Malloced)
Definition: channel.h:386
int plan
Q.931 Type-Of-Number and Numbering-Plan encoded fields.
Definition: channel.h:388
int transit_network_select
Transit Network Select.
Definition: channel.h:397
struct ast_party_subaddress_ies subaddress
Subscriber subaddress ies.
Definition: channel.c:8552
struct ast_party_name_ies name
Subscriber name ies.
Definition: channel.c:8548
int combined_presentation
Combined name and number presentation ie.
Definition: channel.c:8559
struct ast_party_number_ies number
Subscriber phone number ies.
Definition: channel.c:8550
int tag
User party id tag ie.
Definition: channel.c:8554
Information needed to identify an endpoint in a call.
Definition: channel.h:338
struct ast_party_subaddress subaddress
Subscriber subaddress.
Definition: channel.h:344
char * tag
User-set "tag".
Definition: channel.h:354
struct ast_party_name name
Subscriber name.
Definition: channel.h:340
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:342
int char_set
Character set ie.
Definition: channel.c:8327
int presentation
presentation-indicator ie
Definition: channel.c:8329
int str
Subscriber name ie.
Definition: channel.c:8325
int valid
valid/present ie
Definition: channel.c:8331
Information needed to specify a name in a call.
Definition: channel.h:262
int char_set
Character set the name is using.
Definition: channel.h:272
int presentation
Q.931 encoded presentation-indicator encoded field.
Definition: channel.h:277
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:279
char * str
Subscriber name (Malloced)
Definition: channel.h:264
int presentation
presentation-indicator ie
Definition: channel.c:8403
int str
Subscriber phone number ie.
Definition: channel.c:8399
int valid
valid/present ie
Definition: channel.c:8405
int plan
Type-Of-Number and Numbering-Plan ie.
Definition: channel.c:8401
Information needed to specify a number in a call.
Definition: channel.h:289
int presentation
Q.931 presentation-indicator and screening-indicator encoded fields.
Definition: channel.h:295
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:297
char * str
Subscriber phone number (Malloced)
Definition: channel.h:291
int plan
Q.931 Type-Of-Number and Numbering-Plan encoded fields.
Definition: channel.h:293
Redirecting reason information.
Definition: channel.h:501
int code
enum AST_REDIRECTING_REASON value for redirection
Definition: channel.h:510
char * str
a string value for the redirecting reason
Definition: channel.h:507
Redirecting Line information. RDNIS (Redirecting Directory Number Information Service) Where a call d...
Definition: channel.h:522
struct ast_party_id priv_to
Call is redirecting to a new party (Sent to the caller) - private representation.
Definition: channel.h:539
struct ast_party_redirecting_reason orig_reason
Reason for the redirection by the original party.
Definition: channel.h:545
struct ast_party_redirecting_reason reason
Reason for the redirection.
Definition: channel.h:542
struct ast_party_id priv_from
Who is redirecting the call (Sent to the party the call is redirected toward) - private representatio...
Definition: channel.h:536
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition: channel.h:527
int count
Number of times the call was redirected.
Definition: channel.h:548
struct ast_party_id to
Call is redirecting to a new party (Sent to the caller)
Definition: channel.h:530
struct ast_party_id orig
Who originally redirected the call (Sent to the party the call is redirected toward)
Definition: channel.h:524
struct ast_party_id priv_orig
Who originally redirected the call (Sent to the party the call is redirected toward) - private repres...
Definition: channel.h:533
int str
subaddress ie.
Definition: channel.c:8473
int odd_even_indicator
odd/even indicator ie
Definition: channel.c:8477
int valid
valid/present ie
Definition: channel.c:8479
int type
subaddress type ie
Definition: channel.c:8475
Information needed to specify a subaddress in a call.
Definition: channel.h:307
unsigned char odd_even_indicator
TRUE if odd number of address signals.
Definition: channel.h:326
unsigned char valid
TRUE if the subaddress information is valid/present.
Definition: channel.h:328
char * str
Malloced subaddress string.
Definition: channel.h:313
int type
Q.931 subaddress type.
Definition: channel.h:320
Indicate what information in ast_party_caller should be set.
Definition: channel.h:440
Indicate what information in ast_party_connected_line should be set.
Definition: channel.h:489
Indicate what information in ast_party_id should be set.
Definition: channel.h:361
unsigned char subaddress
Definition: channel.h:367
unsigned char number
Definition: channel.h:365
unsigned char name
Definition: channel.h:363
Indicate what information in ast_party_redirecting should be set.
Definition: channel.h:555
struct ast_format * old_write_format
Definition: channel.c:8161
Support for dynamic strings.
Definition: strings.h:623
Description of a tone.
Definition: indications.h:35
const char * data
Description of a tone.
Definition: indications.h:52
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
Definition: translate.h:213
int interleaved_stereo
Definition: translate.h:238
struct ast_var_t::@211 entries
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
the list of registered channel types
Definition: channel.c:121
map AST_CAUSE's to readable string representations
Definition: channel.c:130
const char * desc
Definition: channel.c:133
const char * name
Definition: channel.c:132
int cause
Definition: channel.c:131
List of channel drivers.
Definition: app_dial.c:797
struct ast_channel * chan
Definition: app_dial.c:799
const struct ast_channel_tech * tech
Definition: channel.c:116
const char * tech
Definition: app_dial.c:803
struct chanlist::@329 list
Definition: search.h:40
Definition: astman.c:222
List of channel variables to append to all channel-related events.
Definition: channel.c:7823
struct manager_channel_variable::@330 entry
unsigned int isfunc
Definition: channel.c:7825
Named group member structure.
Definition: channel.c:7651
unsigned int hash
Definition: channel.c:7653
Number structure.
Definition: app_followme.c:154
const char * cid_num
Definition: channel.h:1109
struct ast_variable * vars
Definition: channel.h:1112
int connect_on_early_media
Definition: channel.h:1108
const char * account
Definition: channel.h:1111
const char * cid_name
Definition: channel.h:1110
const char * exten
Definition: channel.h:1106
const char * context
Definition: channel.h:1105
struct ast_channel * parent_channel
Definition: channel.h:1113
int16_t * samples_buf
Definition: channel.c:5033
size_t num_samples
Definition: channel.c:5037
plc_state_t plc_state
Definition: channel.c:5038
struct ast_format *(* get_format)(struct ast_channel *chan)
Definition: channel.c:5564
void(* set_trans)(struct ast_channel *chan, struct ast_trans_pvt *value)
Definition: channel.c:5563
void(* set_rawformat)(struct ast_channel *chan, struct ast_format *format)
Definition: channel.c:5567
struct ast_trans_pvt *(* get_trans)(const struct ast_channel *chan)
Definition: channel.c:5562
void(* set_format)(struct ast_channel *chan, struct ast_format *format)
Definition: channel.c:5565
const char * direction
Definition: channel.c:5561
struct ast_format *(* get_rawformat)(struct ast_channel *chan)
Definition: channel.c:5566
int framehook_id
Definition: channel.c:10722
enum ast_frame_type frametype
Definition: channel.c:10720
unsigned int direction
Definition: channel.c:10721
int duration
Definition: channel.c:7465
unsigned char offset[AST_FRIENDLY_OFFSET]
Definition: channel.c:7483
struct ast_format * origwfmt
Definition: channel.c:7478
struct ast_frame f
Definition: channel.c:7482
short data[4000]
Definition: channel.c:7484
Definition: ast_expr2.c:325
int value
Definition: syslog.c:37
Test Framework API.
#define ast_test_suite_event_notify(s, f,...)
Definition: test.h:189
static const struct ast_aeap_message_handler handlers[]
Definition: test_aeap.c:135
int done
Definition: test_amihooks.c:48
static struct test_options options
static struct test_val b
static struct test_val a
static struct test_val d
static struct test_val c
Definitions to aid in the use of thread local storage.
int ast_threadstorage_set_ptr(struct ast_threadstorage *ts, void *ptr)
Set a raw pointer from threadstorage.
void * ast_threadstorage_get_ptr(struct ast_threadstorage *ts)
Retrieve a raw pointer from threadstorage.
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
Definition: threadstorage.h:86
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:117
int ast_tvcmp(struct timeval _a, struct timeval _b)
Compress two struct timeval instances returning -1, 0, 1 if the first arg is smaller,...
Definition: time.h:137
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition: utils.c:2281
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2282
struct timeval ast_tvsub(struct timeval a, struct timeval b)
Returns the difference of two timevals a - b.
Definition: extconf.c:2297
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159
Timing source management.
unsigned int ast_timer_get_max_rate(const struct ast_timer *handle)
Get maximum rate supported for a timer.
Definition: timing.c:191
void ast_timer_close(struct ast_timer *handle)
Close an opened timing handle.
Definition: timing.c:154
int ast_timer_ack(const struct ast_timer *handle, unsigned int quantity)
Acknowledge a timer event.
Definition: timing.c:171
int ast_timer_set_rate(const struct ast_timer *handle, unsigned int rate)
Set the timing tick rate.
Definition: timing.c:166
enum ast_timer_event ast_timer_get_event(const struct ast_timer *handle)
Retrieve timing event.
Definition: timing.c:186
int ast_timer_enable_continuous(const struct ast_timer *handle)
Enable continuous mode.
Definition: timing.c:176
const char * ast_timer_get_name(const struct ast_timer *handle)
Get name of timer in use.
Definition: timing.c:196
int ast_timer_disable_continuous(const struct ast_timer *handle)
Disable continuous mode.
Definition: timing.c:181
struct ast_timer * ast_timer_open(void)
Open a timer.
Definition: timing.c:122
ast_timer_event
Definition: timing.h:57
@ AST_TIMING_EVENT_CONTINUOUS
Definition: timing.h:59
@ AST_TIMING_EVENT_EXPIRED
Definition: timing.h:58
int ast_timer_fd(const struct ast_timer *handle)
Get a poll()-able file descriptor for a timer.
Definition: timing.c:161
General Asterisk channel transcoding definitions.
#define AST_TRANS_CAP_RESTRICTED_DIGITAL
Definition: transcap.h:37
#define AST_TRANS_CAP_DIGITAL
Definition: transcap.h:36
#define AST_TRANS_CAP_DIGITAL_W_TONES
Definition: transcap.h:40
#define AST_TRANS_CAP_SPEECH
Definition: transcap.h:35
#define AST_TRANS_CAP_3_1K_AUDIO
Definition: transcap.h:38
#define AST_TRANS_CAP_VIDEO
Definition: transcap.h:41
Support for translation of data formats. translate.c.
struct ast_frame * ast_translate(struct ast_trans_pvt *tr, struct ast_frame *f, int consume)
translates one or more frames Apply an input frame into the translator and receive zero or one output...
Definition: translate.c:566
int ast_translator_best_choice(struct ast_format_cap *dst_cap, struct ast_format_cap *src_cap, struct ast_format **dst_fmt_out, struct ast_format **src_fmt_out)
Chooses the best translation path.
Definition: translate.c:1402
void ast_translator_free_path(struct ast_trans_pvt *tr)
Frees a translator path Frees the given translator path structure.
Definition: translate.c:476
struct ast_trans_pvt * ast_translator_build_path(struct ast_format *dest, struct ast_format *source)
Builds a translator path Build a path (possibly NULL) from source to dest.
Definition: translate.c:486
unsigned int ast_translate_path_steps(struct ast_format *dest, struct ast_format *src)
Returns the number of steps required to convert from 'src' to 'dest'.
Definition: translate.c:1536
FILE * out
Definition: utils/frame.c:33
Utility functions.
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
#define ast_assert(a)
Definition: utils.h:739
int ast_get_tid(void)
Get current thread ID.
Definition: utils.c:2752
#define ast_clear_flag(p, flag)
Definition: utils.h:77
#define SWAP(a, b)
Definition: utils.h:235
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define ARRAY_LEN(a)
Definition: utils.h:666
#define MAX(a, b)
Definition: utils.h:233
#define AST_FLAGS_ALL
Definition: utils.h:196