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