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