Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
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
100AST_THREADSTORAGE(state2str_threadbuf);
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
497
498/*! \brief returns number of active/allocated channels */
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:
664 if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE)))
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_channel_endpoint_set(tmp, endpoint);
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{
1185 int res, cause, tech_cause;
1186
1187 if (!blob) {
1188 return -1;
1189 }
1190
1191 /* Yeah, let's not change a lock-critical value without locking */
1192 ast_channel_lock(chan);
1194
1195 cause = ast_channel_hangupcause(chan);
1196 if (cause) {
1197 ast_json_object_set(blob, "cause", ast_json_integer_create(cause));
1198 }
1199 tech_cause = ast_channel_tech_hangupcause(chan);
1200 if (tech_cause) {
1201 ast_json_object_set(blob, "tech_cause", ast_json_integer_create(tech_cause));
1202 }
1203
1205
1206 res = ast_queue_frame(chan, &f);
1207 ast_channel_unlock(chan);
1208 return res;
1209}
1210
1211/*! \brief Queue a hangup frame for channel */
1212int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
1213{
1214 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
1216 int res;
1217 int tech_cause = 0;
1218
1219 if (cause >= 0) {
1220 f.data.uint32 = cause;
1221 }
1222
1223 /* Yeah, let's not change a lock-critical value without locking */
1224 ast_channel_lock(chan);
1226 if (cause < 0) {
1228 }
1229 blob = ast_json_pack("{s: i}",
1230 "cause", cause);
1231 if (!blob) {
1232 ast_channel_unlock(chan);
1233 return -1;
1234 }
1235
1236 tech_cause = ast_channel_tech_hangupcause(chan);
1237 if (tech_cause) {
1238 ast_json_object_set(blob, "tech_cause", ast_json_integer_create(tech_cause));
1239 }
1240
1242
1243 res = ast_queue_frame(chan, &f);
1244 ast_channel_unlock(chan);
1245 return res;
1246}
1247
1248int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
1249{
1251 struct ast_json *blob = NULL;
1252 int res;
1253
1254 if (!ast_strlen_zero(musicclass)) {
1255 f.data.ptr = (void *) musicclass;
1256 f.datalen = strlen(musicclass) + 1;
1257
1258 blob = ast_json_pack("{s: s}",
1259 "musicclass", musicclass);
1260 }
1261
1262 ast_channel_lock(chan);
1264 ast_channel_unlock(chan);
1265
1266 res = ast_queue_frame(chan, &f);
1267
1268 ast_json_unref(blob);
1269
1270 return res;
1271}
1272
1274{
1276 int res;
1277
1278 ast_channel_lock(chan);
1280 ast_channel_unlock(chan);
1281
1282 res = ast_queue_frame(chan, &f);
1283
1284 return res;
1285}
1286
1287/*! \brief Queue a control frame */
1289{
1290 struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = control };
1291 return ast_queue_frame(chan, &f);
1292}
1293
1294/*! \brief Queue a control frame with payload */
1296 const void *data, size_t datalen)
1297{
1298 struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = control, .data.ptr = (void *) data, .datalen = datalen };
1299 return ast_queue_frame(chan, &f);
1300}
1301
1302/*! \brief Queue an ANSWER control frame with topology */
1303int ast_queue_answer(struct ast_channel *chan, const struct ast_stream_topology *topology)
1304{
1305 struct ast_frame f = {
1308 .subclass.topology = (struct ast_stream_topology *)topology,
1309 };
1310 return ast_queue_frame(chan, &f);
1311}
1312
1313/*! \brief Set defer DTMF flag on channel */
1315{
1316 int pre = 0;
1317
1318 if (chan) {
1319 ast_channel_lock(chan);
1322 ast_channel_unlock(chan);
1323 }
1324 return pre;
1325}
1326
1327/*! \brief Unset defer DTMF flag on channel */
1329{
1330 if (chan) {
1332 }
1333}
1334
1336 ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags)
1337{
1339 return NULL;
1340 }
1341 if (!cb_fn) {
1342 ast_log(LOG_ERROR, "callback function must be provided\n");
1343 return NULL;
1344 }
1345 return CHANNELSTORAGE_API(current_channel_storage_instance, callback, cb_fn, arg, data, ao2_flags);
1346}
1347
1355
1356struct ast_channel_iterator *ast_channel_iterator_by_exten_new(const char *exten, const char *context)
1357{
1359 return NULL;
1360 }
1361 if (ast_strlen_zero(exten) || ast_strlen_zero(context)) {
1362 ast_log(LOG_ERROR, "exten and context must be provided\n");
1363 return NULL;
1364 }
1366}
1368{
1370 return NULL;
1371 }
1372 if (ast_strlen_zero(name)) {
1373 ast_log(LOG_ERROR, "name must be provided\n");
1374 return NULL;
1375 }
1377}
1378
1386
1394
1395/*
1396 * REMINDER: Historically, this function can be provided a channel name
1397 * or uniqueid. This is a bit confusing, but it is what it is.
1398 */
1399struct ast_channel *ast_channel_get_by_name_prefix(const char *name, size_t name_len)
1400{
1402 return NULL;
1403 }
1404 if (ast_strlen_zero(name)) {
1405 ast_log(LOG_ERROR, "name must be provided\n");
1406 return NULL;
1407 }
1408
1409 return CHANNELSTORAGE_API(current_channel_storage_instance, get_by_name_prefix_or_uniqueid, name, name_len);
1410}
1411
1412/*
1413 * REMINDER: Historically, this function can be provided a channel name
1414 * or uniqueid. This is a bit confusing, but it is what it is.
1415 */
1417{
1419 return NULL;
1420 }
1421 if (ast_strlen_zero(name)) {
1422 ast_log(LOG_ERROR, "name must be provided\n");
1423 return NULL;
1424 }
1425
1426 return CHANNELSTORAGE_API(current_channel_storage_instance, get_by_name_prefix_or_uniqueid, name, 0);
1427}
1428
1429struct ast_channel *ast_channel_get_by_exten(const char *exten, const char *context)
1430{
1432 return NULL;
1433 }
1435 ast_log(LOG_ERROR, "exten and context must be provided\n");
1436 return NULL;
1437 }
1439}
1440
1442{
1444 return NULL;
1445 }
1447 ast_log(LOG_ERROR, "uniqueid must be provided\n");
1448 return NULL;
1449 }
1451}
1452
1453int ast_is_deferrable_frame(const struct ast_frame *frame)
1454{
1455 /* Do not add a default entry in this switch statement. Each new
1456 * frame type should be addressed directly as to whether it should
1457 * be queued up or not.
1458 */
1459 switch (frame->frametype) {
1462 case AST_FRAME_CONTROL:
1463 case AST_FRAME_TEXT:
1465 case AST_FRAME_IMAGE:
1466 case AST_FRAME_HTML:
1467 return 1;
1468
1469 case AST_FRAME_DTMF_END:
1471 case AST_FRAME_VOICE:
1472 case AST_FRAME_VIDEO:
1473 case AST_FRAME_NULL:
1474 case AST_FRAME_IAX:
1475 case AST_FRAME_CNG:
1476 case AST_FRAME_MODEM:
1477 case AST_FRAME_RTCP:
1478 return 0;
1479 }
1480 return 0;
1481}
1482
1483/*! \brief Wait, look for hangups and condition arg */
1484static int safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data, unsigned int generate_silence)
1485{
1486 struct ast_frame *f;
1487 struct ast_silence_generator *silgen = NULL;
1488 int res = 0;
1489 struct timeval start;
1490 int ms;
1491 AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames;
1492
1493 AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames);
1494
1495 /* If no other generator is present, start silencegen while waiting */
1496 if (generate_silence && ast_opt_transmit_silence && !ast_channel_generatordata(chan)) {
1498 }
1499
1500 start = ast_tvnow();
1501 while ((ms = ast_remaining_ms(start, timeout_ms))) {
1502 struct ast_frame *dup_f = NULL;
1503
1504 if (cond && ((*cond)(data) == 0)) {
1505 break;
1506 }
1507 ms = ast_waitfor(chan, ms);
1508 if (ms < 0) {
1509 res = -1;
1510 break;
1511 }
1512 if (ms > 0) {
1513 f = ast_read(chan);
1514 if (!f) {
1515 res = -1;
1516 break;
1517 }
1518
1519 if (!ast_is_deferrable_frame(f)) {
1520 ast_frfree(f);
1521 continue;
1522 }
1523
1524 if ((dup_f = ast_frisolate(f))) {
1525 if (dup_f != f) {
1526 ast_frfree(f);
1527 }
1528 AST_LIST_INSERT_HEAD(&deferred_frames, dup_f, frame_list);
1529 }
1530 }
1531 }
1532
1533 /* stop silgen if present */
1534 if (silgen) {
1536 }
1537
1538 /* We need to free all the deferred frames, but we only need to
1539 * queue the deferred frames if there was no error and no
1540 * hangup was received
1541 */
1542 ast_channel_lock(chan);
1543 while ((f = AST_LIST_REMOVE_HEAD(&deferred_frames, frame_list))) {
1544 if (!res) {
1545 ast_queue_frame_head(chan, f);
1546 }
1547 ast_frfree(f);
1548 }
1549 ast_channel_unlock(chan);
1550
1551 return res;
1552}
1553
1554int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data)
1555{
1556 return safe_sleep_conditional(chan, timeout_ms, cond, data, 1);
1557}
1558
1559/*! \brief Wait, look for hangups */
1560int ast_safe_sleep(struct ast_channel *chan, int ms)
1561{
1562 return safe_sleep_conditional(chan, ms, NULL, NULL, 1);
1563}
1564
1566{
1567 return safe_sleep_conditional(chan, ms, NULL, NULL, 0);
1568}
1569
1571{
1572 /* Safe, even if already unlinked. */
1573 ast_channel_unlink(chan);
1574 return ast_channel_unref(chan);
1575}
1576
1578{
1579 init->str = NULL;
1582 init->valid = 0;
1583}
1584
1585void ast_party_name_copy(struct ast_party_name *dest, const struct ast_party_name *src)
1586{
1587 if (dest == src) {
1588 /* Don't copy to self */
1589 return;
1590 }
1591
1592 ast_free(dest->str);
1593 dest->str = ast_strdup(src->str);
1594 dest->char_set = src->char_set;
1595 dest->presentation = src->presentation;
1596 dest->valid = src->valid;
1597}
1598
1599void ast_party_name_set_init(struct ast_party_name *init, const struct ast_party_name *guide)
1600{
1601 init->str = NULL;
1602 init->char_set = guide->char_set;
1603 init->presentation = guide->presentation;
1604 init->valid = guide->valid;
1605}
1606
1607void ast_party_name_set(struct ast_party_name *dest, const struct ast_party_name *src)
1608{
1609 if (dest == src) {
1610 /* Don't set to self */
1611 return;
1612 }
1613
1614 if (src->str && src->str != dest->str) {
1615 ast_free(dest->str);
1616 dest->str = ast_strdup(src->str);
1617 }
1618
1619 dest->char_set = src->char_set;
1620 dest->presentation = src->presentation;
1621 dest->valid = src->valid;
1622}
1623
1625{
1626 ast_free(doomed->str);
1627 doomed->str = NULL;
1628}
1629
1631{
1632 init->str = NULL;
1633 init->plan = 0;/* Unknown */
1635 init->valid = 0;
1636}
1637
1638void ast_party_number_copy(struct ast_party_number *dest, const struct ast_party_number *src)
1639{
1640 if (dest == src) {
1641 /* Don't copy to self */
1642 return;
1643 }
1644
1645 ast_free(dest->str);
1646 dest->str = ast_strdup(src->str);
1647 dest->plan = src->plan;
1648 dest->presentation = src->presentation;
1649 dest->valid = src->valid;
1650}
1651
1652void ast_party_number_set_init(struct ast_party_number *init, const struct ast_party_number *guide)
1653{
1654 init->str = NULL;
1655 init->plan = guide->plan;
1656 init->presentation = guide->presentation;
1657 init->valid = guide->valid;
1658}
1659
1660void ast_party_number_set(struct ast_party_number *dest, const struct ast_party_number *src)
1661{
1662 if (dest == src) {
1663 /* Don't set to self */
1664 return;
1665 }
1666
1667 if (src->str && src->str != dest->str) {
1668 ast_free(dest->str);
1669 dest->str = ast_strdup(src->str);
1670 }
1671
1672 dest->plan = src->plan;
1673 dest->presentation = src->presentation;
1674 dest->valid = src->valid;
1675}
1676
1678{
1679 ast_free(doomed->str);
1680 doomed->str = NULL;
1681}
1682
1684{
1685 init->str = NULL;
1686 init->type = 0;
1687 init->odd_even_indicator = 0;
1688 init->valid = 0;
1689}
1690
1692{
1693 if (dest == src) {
1694 /* Don't copy to self */
1695 return;
1696 }
1697
1698 ast_free(dest->str);
1699 dest->str = ast_strdup(src->str);
1700 dest->type = src->type;
1702 dest->valid = src->valid;
1703}
1704
1706{
1707 init->str = NULL;
1708 init->type = guide->type;
1710 init->valid = guide->valid;
1711}
1712
1714{
1715 if (dest == src) {
1716 /* Don't set to self */
1717 return;
1718 }
1719
1720 if (src->str && src->str != dest->str) {
1721 ast_free(dest->str);
1722 dest->str = ast_strdup(src->str);
1723 }
1724
1725 dest->type = src->type;
1727 dest->valid = src->valid;
1728}
1729
1731{
1732 ast_free(doomed->str);
1733 doomed->str = NULL;
1734}
1735
1737{
1738 update_id->name = 1;
1739 update_id->number = 1;
1740 update_id->subaddress = 1;
1741}
1742
1744{
1745 ast_party_name_init(&init->name);
1748 init->tag = NULL;
1749}
1750
1751void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src)
1752{
1753 if (dest == src) {
1754 /* Don't copy to self */
1755 return;
1756 }
1757
1758 ast_party_name_copy(&dest->name, &src->name);
1759 ast_party_number_copy(&dest->number, &src->number);
1761
1762 ast_free(dest->tag);
1763 dest->tag = ast_strdup(src->tag);
1764}
1765
1766void ast_party_id_set_init(struct ast_party_id *init, const struct ast_party_id *guide)
1767{
1768 ast_party_name_set_init(&init->name, &guide->name);
1769 ast_party_number_set_init(&init->number, &guide->number);
1771 init->tag = NULL;
1772}
1773
1774void ast_party_id_set(struct ast_party_id *dest, const struct ast_party_id *src, const struct ast_set_party_id *update)
1775{
1776 if (dest == src) {
1777 /* Don't set to self */
1778 return;
1779 }
1780
1781 if (!update || update->name) {
1782 ast_party_name_set(&dest->name, &src->name);
1783 }
1784 if (!update || update->number) {
1785 ast_party_number_set(&dest->number, &src->number);
1786 }
1787 if (!update || update->subaddress) {
1789 }
1790
1791 if (src->tag && src->tag != dest->tag) {
1792 ast_free(dest->tag);
1793 dest->tag = ast_strdup(src->tag);
1794 }
1795}
1796
1798{
1799 ast_party_name_free(&doomed->name);
1800 ast_party_number_free(&doomed->number);
1802
1803 ast_free(doomed->tag);
1804 doomed->tag = NULL;
1805}
1806
1808{
1809 int number_priority;
1810 int number_value;
1811 int number_screening;
1812 int name_priority;
1813 int name_value;
1814
1815 /* Determine name presentation priority. */
1816 if (!id->name.valid) {
1817 name_value = AST_PRES_UNAVAILABLE;
1818 name_priority = 3;
1819 } else {
1820 name_value = id->name.presentation & AST_PRES_RESTRICTION;
1821 switch (name_value) {
1823 name_priority = 0;
1824 break;
1825 case AST_PRES_ALLOWED:
1826 name_priority = 1;
1827 break;
1829 name_priority = 2;
1830 break;
1831 default:
1832 name_value = AST_PRES_UNAVAILABLE;
1833 name_priority = 3;
1834 break;
1835 }
1836 }
1837
1838 /* Determine number presentation priority. */
1839 if (!id->number.valid) {
1840 number_screening = AST_PRES_USER_NUMBER_UNSCREENED;
1841 number_value = AST_PRES_UNAVAILABLE;
1842 number_priority = 3;
1843 } else {
1844 number_screening = id->number.presentation & AST_PRES_NUMBER_TYPE;
1845 number_value = id->number.presentation & AST_PRES_RESTRICTION;
1846 switch (number_value) {
1848 number_priority = 0;
1849 break;
1850 case AST_PRES_ALLOWED:
1851 number_priority = 1;
1852 break;
1854 number_priority = 2;
1855 break;
1856 default:
1857 number_screening = AST_PRES_USER_NUMBER_UNSCREENED;
1858 number_value = AST_PRES_UNAVAILABLE;
1859 number_priority = 3;
1860 break;
1861 }
1862 }
1863
1864 /* Select the wining presentation value. */
1865 if (name_priority < number_priority) {
1866 number_value = name_value;
1867 }
1868 if (number_value == AST_PRES_UNAVAILABLE) {
1870 }
1871
1872 return number_value | number_screening;
1873}
1874
1876{
1877 id->name.valid = 0;
1878 id->number.valid = 0;
1879 id->subaddress.valid = 0;
1880}
1881
1883{
1886}
1887
1888struct ast_party_id ast_party_id_merge(struct ast_party_id *base, struct ast_party_id *overlay)
1889{
1890 struct ast_party_id merged;
1891
1892 merged = *base;
1893 if (overlay->name.valid) {
1894 merged.name = overlay->name;
1895 }
1896 if (overlay->number.valid) {
1897 merged.number = overlay->number;
1898 }
1899 if (overlay->subaddress.valid) {
1900 merged.subaddress = overlay->subaddress;
1901 }
1902 /* Note the actual structure is returned and not a pointer to it! */
1903 return merged;
1904}
1905
1906void ast_party_id_merge_copy(struct ast_party_id *dest, struct ast_party_id *base, struct ast_party_id *overlay)
1907{
1908 struct ast_party_id merged;
1909
1910 merged = ast_party_id_merge(base, overlay);
1911 ast_party_id_copy(dest, &merged);
1912}
1913
1915{
1916 init->number.str = NULL;
1917 init->number.plan = 0;/* Unknown */
1919 init->transit_network_select = 0;
1920}
1921
1922void ast_party_dialed_copy(struct ast_party_dialed *dest, const struct ast_party_dialed *src)
1923{
1924 if (dest == src) {
1925 /* Don't copy to self */
1926 return;
1927 }
1928
1929 ast_free(dest->number.str);
1930 dest->number.str = ast_strdup(src->number.str);
1931 dest->number.plan = src->number.plan;
1934}
1935
1936void ast_party_dialed_set_init(struct ast_party_dialed *init, const struct ast_party_dialed *guide)
1937{
1938 init->number.str = NULL;
1939 init->number.plan = guide->number.plan;
1942}
1943
1944void ast_party_dialed_set(struct ast_party_dialed *dest, const struct ast_party_dialed *src)
1945{
1946 if (src->number.str && src->number.str != dest->number.str) {
1947 ast_free(dest->number.str);
1948 dest->number.str = ast_strdup(src->number.str);
1949 }
1950 dest->number.plan = src->number.plan;
1951
1953
1955}
1956
1958{
1959 ast_free(doomed->number.str);
1960 doomed->number.str = NULL;
1962}
1963
1965{
1966 ast_party_id_init(&init->id);
1967 ast_party_id_init(&init->ani);
1968 ast_party_id_init(&init->priv);
1969 init->ani2 = 0;
1970}
1971
1972void ast_party_caller_copy(struct ast_party_caller *dest, const struct ast_party_caller *src)
1973{
1974 if (dest == src) {
1975 /* Don't copy to self */
1976 return;
1977 }
1978
1979 ast_party_id_copy(&dest->id, &src->id);
1980 ast_party_id_copy(&dest->ani, &src->ani);
1981 ast_party_id_copy(&dest->priv, &src->priv);
1982 dest->ani2 = src->ani2;
1983}
1984
1985void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide)
1986{
1987 ast_party_id_set_init(&init->id, &guide->id);
1988 ast_party_id_set_init(&init->ani, &guide->ani);
1989 ast_party_id_set_init(&init->priv, &guide->priv);
1990 init->ani2 = guide->ani2;
1991}
1992
1993void ast_party_caller_set(struct ast_party_caller *dest, const struct ast_party_caller *src, const struct ast_set_party_caller *update)
1994{
1995 ast_party_id_set(&dest->id, &src->id, update ? &update->id : NULL);
1996 ast_party_id_set(&dest->ani, &src->ani, update ? &update->ani : NULL);
1997 ast_party_id_set(&dest->priv, &src->priv, update ? &update->priv : NULL);
1998 dest->ani2 = src->ani2;
1999}
2000
2002{
2003 ast_party_id_free(&doomed->id);
2004 ast_party_id_free(&doomed->ani);
2005 ast_party_id_free(&doomed->priv);
2006}
2007
2009{
2010 ast_party_id_init(&init->id);
2011 ast_party_id_init(&init->ani);
2012 ast_party_id_init(&init->priv);
2013 init->ani2 = 0;
2015}
2016
2018{
2019 if (dest == src) {
2020 /* Don't copy to self */
2021 return;
2022 }
2023
2024 ast_party_id_copy(&dest->id, &src->id);
2025 ast_party_id_copy(&dest->ani, &src->ani);
2026 ast_party_id_copy(&dest->priv, &src->priv);
2027 dest->ani2 = src->ani2;
2028 dest->source = src->source;
2029}
2030
2032{
2033 ast_party_id_set_init(&init->id, &guide->id);
2034 ast_party_id_set_init(&init->ani, &guide->ani);
2035 ast_party_id_set_init(&init->priv, &guide->priv);
2036 init->ani2 = guide->ani2;
2037 init->source = guide->source;
2038}
2039
2041{
2042 ast_party_id_set(&dest->id, &src->id, update ? &update->id : NULL);
2043 ast_party_id_set(&dest->ani, &src->ani, update ? &update->ani : NULL);
2044 ast_party_id_set(&dest->priv, &src->priv, update ? &update->priv : NULL);
2045 dest->ani2 = src->ani2;
2046 dest->source = src->source;
2047}
2048
2050{
2051 connected->id = caller->id;
2052 connected->ani = caller->ani;
2053 connected->priv = caller->priv;
2054 connected->ani2 = caller->ani2;
2056}
2057
2059{
2060 ast_party_id_free(&doomed->id);
2061 ast_party_id_free(&doomed->ani);
2062 ast_party_id_free(&doomed->priv);
2063}
2064
2070
2072{
2073 if (dest == src) {
2074 return;
2075 }
2076
2077 ast_free(dest->str);
2078 dest->str = ast_strdup(src->str);
2079 dest->code = src->code;
2080}
2081
2083{
2084 init->str = NULL;
2085 init->code = guide->code;
2086}
2087
2089{
2090 if (dest == src) {
2091 return;
2092 }
2093
2094 if (src->str && src->str != dest->str) {
2095 ast_free(dest->str);
2096 dest->str = ast_strdup(src->str);
2097 }
2098
2099 dest->code = src->code;
2100}
2101
2103{
2104 ast_free(doomed->str);
2105}
2106
2107
2120
2122{
2123 if (dest == src) {
2124 /* Don't copy to self */
2125 return;
2126 }
2127
2128 ast_party_id_copy(&dest->orig, &src->orig);
2129 ast_party_id_copy(&dest->from, &src->from);
2130 ast_party_id_copy(&dest->to, &src->to);
2131 ast_party_id_copy(&dest->priv_orig, &src->priv_orig);
2132 ast_party_id_copy(&dest->priv_from, &src->priv_from);
2133 ast_party_id_copy(&dest->priv_to, &src->priv_to);
2136 dest->count = src->count;
2137}
2138
2140{
2141 ast_party_id_set_init(&init->orig, &guide->orig);
2142 ast_party_id_set_init(&init->from, &guide->from);
2143 ast_party_id_set_init(&init->to, &guide->to);
2144 ast_party_id_set_init(&init->priv_orig, &guide->priv_orig);
2145 ast_party_id_set_init(&init->priv_from, &guide->priv_from);
2146 ast_party_id_set_init(&init->priv_to, &guide->priv_to);
2149 init->count = guide->count;
2150}
2151
2153{
2154 ast_party_id_set(&dest->orig, &src->orig, update ? &update->orig : NULL);
2155 ast_party_id_set(&dest->from, &src->from, update ? &update->from : NULL);
2156 ast_party_id_set(&dest->to, &src->to, update ? &update->to : NULL);
2157 ast_party_id_set(&dest->priv_orig, &src->priv_orig, update ? &update->priv_orig : NULL);
2158 ast_party_id_set(&dest->priv_from, &src->priv_from, update ? &update->priv_from : NULL);
2159 ast_party_id_set(&dest->priv_to, &src->priv_to, update ? &update->priv_to : NULL);
2162 dest->count = src->count;
2163}
2164
2176
2177static void moh_cleanup(struct ast_channel *chan);
2178
2179/*! \brief Free a channel structure */
2180static void ast_channel_destructor(void *obj)
2181{
2182 struct ast_channel *chan = obj;
2183 struct ast_var_t *vardata;
2184 struct ast_frame *f;
2185 struct varshead *headp;
2186 struct ast_datastore *datastore;
2187 char device_name[AST_CHANNEL_NAME];
2188 ast_callid callid;
2189
2190 ast_debug(1, "Channel %p '%s' destroying\n", chan, ast_channel_name(chan));
2191
2192 /* If there is native format music-on-hold state, free it */
2193 if (ast_channel_music_state(chan)) {
2194 moh_cleanup(chan);
2195 }
2196
2198
2199 /* Things that may possibly raise Stasis messages shouldn't occur after this point */
2201
2203 /* A channel snapshot should not be in the process of being staged now. */
2205
2206 ast_channel_lock(chan);
2208 ast_channel_unlock(chan);
2209 }
2210
2211 ast_channel_lock(chan);
2212
2214
2215 /* Get rid of each of the data stores on the channel */
2216 while ((datastore = AST_LIST_REMOVE_HEAD(ast_channel_datastores(chan), entry)))
2217 /* Free the data store */
2218 ast_datastore_free(datastore);
2219
2220 /* While the channel is locked, take the reference to its callid while we tear down the call. */
2221 callid = ast_channel_callid(chan);
2223
2224 ast_channel_unlock(chan);
2225
2226 /* Lock and unlock the channel just to be sure nobody has it locked still
2227 due to a reference that was stored in a datastore. (i.e. app_chanspy) */
2228 ast_channel_lock(chan);
2229 ast_channel_unlock(chan);
2230
2231 if (ast_channel_tech_pvt(chan)) {
2232 ast_log_callid(LOG_WARNING, callid, "Channel '%s' may not have been hung up properly\n", ast_channel_name(chan));
2234 }
2235
2236 if (ast_channel_sched(chan)) {
2238 }
2239
2241 char *dashptr;
2242
2243 ast_copy_string(device_name, ast_channel_name(chan), sizeof(device_name));
2244 if ((dashptr = strrchr(device_name, '-'))) {
2245 *dashptr = '\0';
2246 }
2247 } else {
2248 device_name[0] = '\0';
2249 }
2250
2251 /* Free translators */
2252 if (ast_channel_readtrans(chan))
2254 if (ast_channel_writetrans(chan))
2256 if (ast_channel_pbx(chan))
2257 ast_log_callid(LOG_WARNING, callid, "PBX may not have been terminated properly on '%s'\n", ast_channel_name(chan));
2258
2259 /* Free formats */
2265
2271
2272 /* Close pipes if appropriate */
2274 if (ast_channel_timer(chan)) {
2277 }
2279 ast_frfree(f);
2280
2281 /* loop over the variables list, freeing all data and deleting list items */
2282 /* no need to lock the list, as the channel is already locked */
2283 headp = ast_channel_varshead(chan);
2284 while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
2285 ast_var_delete(vardata);
2286
2288
2289 /* Destroy the jitterbuffer */
2290 ast_jb_destroy(chan);
2291
2292 if (ast_channel_cdr(chan)) {
2295 }
2296
2297 if (ast_channel_zone(chan)) {
2299 }
2300
2302
2303 if (device_name[0]) {
2304 /*
2305 * We have a device name to notify of a new state.
2306 *
2307 * Queue an unknown state, because, while we know that this particular
2308 * instance is dead, we don't know the state of all other possible
2309 * instances.
2310 */
2312 }
2313
2315
2318
2320}
2321
2322/*! \brief Free a dummy channel structure */
2323static void ast_dummy_channel_destructor(void *obj)
2324{
2325 struct ast_channel *chan = obj;
2326 struct ast_datastore *datastore;
2327 struct ast_var_t *vardata;
2328 struct varshead *headp;
2329
2331
2332 /* Get rid of each of the data stores on the channel */
2333 while ((datastore = AST_LIST_REMOVE_HEAD(ast_channel_datastores(chan), entry))) {
2334 /* Free the data store */
2335 ast_datastore_free(datastore);
2336 }
2337
2343
2344 /* loop over the variables list, freeing all data and deleting list items */
2345 /* no need to lock the list, as the channel is already locked */
2346 headp = ast_channel_varshead(chan);
2347 while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
2348 ast_var_delete(vardata);
2349
2350 if (ast_channel_cdr(chan)) {
2353 }
2354
2356}
2357
2359{
2360 struct ast_datastore *datastore = NULL, *datastore2;
2361
2363 if (datastore->inheritance > 0) {
2364 datastore2 = ast_datastore_alloc(datastore->info, datastore->uid);
2365 if (datastore2) {
2366 datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL;
2367 datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1;
2369 }
2370 }
2371 }
2372 return 0;
2373}
2374
2375int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
2376{
2377 int res = 0;
2378
2380
2381 return res;
2382}
2383
2384int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
2385{
2386 return AST_LIST_REMOVE(ast_channel_datastores(chan), datastore, entry) ? 0 : -1;
2387}
2388
2389struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
2390{
2391 struct ast_datastore *datastore = NULL;
2392
2393 if (info == NULL)
2394 return NULL;
2395
2397 if (datastore->info != info) {
2398 continue;
2399 }
2400
2401 if (uid == NULL) {
2402 /* matched by type only */
2403 break;
2404 }
2405
2406 if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) {
2407 /* Matched by type AND uid */
2408 break;
2409 }
2410 }
2411
2412 return datastore;
2413}
2414
2415/*! Set the file descriptor on the channel */
2416void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
2417{
2418 ast_channel_internal_fd_set(chan, which, fd);
2419 return;
2420}
2421
2423{
2424 ast_channel_lock(chan);
2425
2427
2429 struct ast_frame *fr;
2430
2431 /* If we have completely cleared the softhangup flag,
2432 * then we need to fully abort the hangup process. This requires
2433 * pulling the END_OF_Q frame out of the channel frame queue if it
2434 * still happens to be there. */
2435
2436 fr = AST_LIST_LAST(ast_channel_readq(chan));
2437 if (fr && fr->frametype == AST_FRAME_CONTROL &&
2440 ast_frfree(fr);
2441 }
2442 }
2443
2444 ast_channel_unlock(chan);
2445}
2446
2447/*! \brief Softly hangup a channel, don't lock */
2448int ast_softhangup_nolock(struct ast_channel *chan, int cause)
2449{
2450 ast_debug(1, "Soft-Hanging (%#04x) up channel '%s'\n", (unsigned)cause, ast_channel_name(chan));
2451 /* Inform channel driver that we need to be hung up, if it cares */
2454 /* Interrupt any poll call or such */
2456 pthread_kill(ast_channel_blocker(chan), SIGURG);
2457 return 0;
2458}
2459
2460/*! \brief Softly hangup a channel, lock */
2461int ast_softhangup(struct ast_channel *chan, int cause)
2462{
2463 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
2464 int res;
2465 int tech_cause = 0;
2466
2467 ast_channel_lock(chan);
2468 res = ast_softhangup_nolock(chan, cause);
2469 blob = ast_json_pack("{s: i, s: b}",
2470 "cause", cause,
2471 "soft", 1);
2472
2473 tech_cause = ast_channel_tech_hangupcause(chan);
2474 if (tech_cause) {
2475 ast_json_object_set(blob, "tech_cause", ast_json_integer_create(tech_cause));
2476 }
2477
2479 ast_channel_unlock(chan);
2480
2481 return res;
2482}
2483
2484static void free_translation(struct ast_channel *clonechan)
2485{
2486 if (ast_channel_writetrans(clonechan)) {
2488 }
2489 if (ast_channel_readtrans(clonechan)) {
2491 }
2492 ast_channel_writetrans_set(clonechan, NULL);
2493 ast_channel_readtrans_set(clonechan, NULL);
2494}
2495
2496void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
2497{
2499
2500 ast_channel_lock(chan);
2501 if (force || ast_strlen_zero(ast_channel_hangupsource(chan))) {
2502 ast_channel_hangupsource_set(chan, source);
2503 }
2504 ast_channel_unlock(chan);
2505
2506 if (bridge) {
2507 ast_channel_lock(bridge);
2508 if (force || ast_strlen_zero(ast_channel_hangupsource(bridge))) {
2509 ast_channel_hangupsource_set(bridge, source);
2510 }
2511 ast_channel_unlock(bridge);
2512 }
2513}
2514
2520
2526
2527static void destroy_hooks(struct ast_channel *chan)
2528{
2529 if (ast_channel_audiohooks(chan)) {
2532 }
2533
2535}
2536
2537/*! \brief Hangup a channel */
2538void ast_hangup(struct ast_channel *chan)
2539{
2540 /* Be NULL safe for RAII_VAR() usage. */
2541 if (!chan) {
2542 return;
2543 }
2544
2545 ast_debug(1, "Channel %p '%s' hanging up. Refs: %d\n", chan, ast_channel_name(chan),
2546 ao2_ref(chan, 0));
2547
2549
2550 ast_channel_lock(chan);
2551
2552 while (ast_channel_masq(chan) || ast_channel_masqr(chan)) {
2554 }
2555
2556 /* Mark as a zombie so a masquerade cannot be setup on this channel. */
2558
2559 ast_channel_unlock(chan);
2560
2561 /*
2562 * XXX if running the hangup handlers here causes problems
2563 * because the handlers take too long to execute, we could move
2564 * the meat of this function into another thread. A thread
2565 * where channels go to die.
2566 *
2567 * If this is done, ast_autoservice_chan_hangup_peer() will no
2568 * longer be needed.
2569 */
2571 ast_channel_unlink(chan);
2572 ast_channel_lock(chan);
2573
2574 destroy_hooks(chan);
2575
2576 free_translation(chan);
2577 /* Close audio stream */
2578 if (ast_channel_stream(chan)) {
2581 }
2582 /* Close video stream */
2583 if (ast_channel_vstream(chan)) {
2586 }
2587 if (ast_channel_sched(chan)) {
2590 }
2591
2592 if (ast_channel_generatordata(chan)) { /* Clear any tone stuff remaining */
2593 if (ast_channel_generator(chan) && ast_channel_generator(chan)->release) {
2595 }
2596 }
2599
2601 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",
2603 ast_channel_blockproc(chan));
2604 ast_assert(0);
2605 }
2606
2607 if (ast_channel_tech(chan)->hangup) {
2608 ast_channel_tech(chan)->hangup(chan);
2609 }
2610
2611 ast_channel_unlock(chan);
2612
2613 ast_cc_offer(chan);
2614
2615 ast_channel_unref(chan);
2616}
2617
2618/*!
2619 * \internal
2620 * \brief Set channel answered time if not already set.
2621 * \since 13.11.0
2622 *
2623 * \param chan Channel to set answered time.
2624 */
2625static void set_channel_answer_time(struct ast_channel *chan)
2626{
2628 struct timeval answertime;
2629
2630 answertime = ast_tvnow();
2631 ast_channel_answertime_set(chan, &answertime);
2632 }
2633}
2634
2635
2637{
2638 int res = 0;
2639 SCOPE_TRACE(1, "%s\n", ast_channel_name(chan));
2640
2641 ast_channel_lock(chan);
2642
2643 /* You can't answer an outbound call */
2645 ast_channel_unlock(chan);
2646 return 0;
2647 }
2648
2649 /* Stop if we're a zombie or need a soft hangup */
2651 ast_channel_unlock(chan);
2652 return -1;
2653 }
2654
2655 /*
2656 * Mark when incoming channel answered so we can know how
2657 * long the channel has been up.
2658 */
2660
2661 ast_channel_unlock(chan);
2662
2663 switch (ast_channel_state(chan)) {
2664 case AST_STATE_RINGING:
2665 case AST_STATE_RING:
2666 ast_channel_lock(chan);
2667 if (ast_channel_tech(chan)->answer_with_stream_topology) {
2668 res = ast_channel_tech(chan)->answer_with_stream_topology(chan, topology);
2669
2670 } else if (ast_channel_tech(chan)->answer) {
2671 res = ast_channel_tech(chan)->answer(chan);
2672 }
2674 ast_channel_unlock(chan);
2675 break;
2676 case AST_STATE_UP:
2677 /* Fall through */
2678 default:
2679 ast_debug(2, "Skipping answer, since channel state on %s is %s\n", ast_channel_name(chan), ast_state2str(ast_channel_state(chan)));
2680 break;
2681 }
2682
2683 ast_indicate(chan, -1);
2684
2685 return res;
2686}
2687
2689{
2691}
2692
2693int __ast_answer(struct ast_channel *chan, unsigned int delay)
2694{
2695 int res = 0;
2696 enum ast_channel_state old_state;
2697 SCOPE_TRACE(1, "%s\n", ast_channel_name(chan));
2698
2699 old_state = ast_channel_state(chan);
2700 if ((res = ast_raw_answer(chan))) {
2701 return res;
2702 }
2703
2704 switch (old_state) {
2705 case AST_STATE_RINGING:
2706 case AST_STATE_RING:
2707 /* wait for media to start flowing, but don't wait any longer
2708 * than 'delay' or 500 milliseconds, whichever is longer
2709 */
2710 do {
2712 struct ast_frame *cur;
2713 struct ast_frame *new_frame;
2714 int timeout_ms = MAX(delay, 500);
2715 unsigned int done = 0;
2716 struct timeval start;
2717
2719
2720 start = ast_tvnow();
2721 for (;;) {
2722 int ms = ast_remaining_ms(start, timeout_ms);
2723 ms = ast_waitfor(chan, ms);
2724 if (ms < 0) {
2725 ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", ast_channel_name(chan), strerror(errno));
2726 res = -1;
2727 break;
2728 }
2729 if (ms == 0) {
2730 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));
2731 break;
2732 }
2733 cur = ast_read(chan);
2734 if (!cur || ((cur->frametype == AST_FRAME_CONTROL) &&
2735 (cur->subclass.integer == AST_CONTROL_HANGUP))) {
2736 if (cur) {
2737 ast_frfree(cur);
2738 }
2739 res = -1;
2740 ast_debug(2, "Hangup of channel %s detected in answer routine\n", ast_channel_name(chan));
2741 break;
2742 }
2743
2744 if ((new_frame = ast_frisolate(cur)) != cur) {
2745 ast_frfree(cur);
2746 }
2747
2749
2750 /* if a specific delay period was requested, continue
2751 * until that delay has passed. don't stop just because
2752 * incoming media has arrived.
2753 */
2754 if (delay) {
2755 continue;
2756 }
2757
2758 switch (new_frame->frametype) {
2759 /* all of these frametypes qualify as 'media' */
2760 case AST_FRAME_VOICE:
2761 case AST_FRAME_VIDEO:
2762 case AST_FRAME_TEXT:
2765 case AST_FRAME_DTMF_END:
2766 case AST_FRAME_IMAGE:
2767 case AST_FRAME_HTML:
2768 case AST_FRAME_MODEM:
2769 case AST_FRAME_RTCP:
2770 done = 1;
2771 break;
2772 case AST_FRAME_CONTROL:
2773 case AST_FRAME_IAX:
2776 case AST_FRAME_NULL:
2777 case AST_FRAME_CNG:
2778 break;
2779 }
2780
2781 if (done) {
2782 break;
2783 }
2784 }
2785
2786 ast_channel_lock(chan);
2787 while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
2788 if (res == 0) {
2789 ast_queue_frame_head(chan, cur);
2790 }
2791 ast_frfree(cur);
2792 }
2793 ast_channel_unlock(chan);
2794 } while (0);
2795 break;
2796 default:
2797 break;
2798 }
2799
2800 return res;
2801}
2802
2803int ast_answer(struct ast_channel *chan)
2804{
2805 SCOPE_TRACE(1, "%s\n", ast_channel_name(chan));
2806 return __ast_answer(chan, 0);
2807}
2808
2809inline int ast_auto_answer(struct ast_channel *chan)
2810{
2811 if (ast_channel_state(chan) == AST_STATE_UP) {
2812 /* Already answered */
2813 return 0;
2814 }
2815 return ast_answer(chan);
2816}
2817
2819{
2820 ast_assert(NULL != chan);
2821
2823 return 0;
2824 }
2826}
2827
2829{
2830 return (ast_channel_get_duration_ms(chan) / 1000);
2831}
2832
2834{
2835 ast_assert(NULL != chan);
2836
2838 return 0;
2839 }
2841}
2842
2844{
2845 return (ast_channel_get_up_time_ms(chan) / 1000);
2846}
2847
2848/*!
2849 * \brief Determine whether or not we have to trigger dtmf emulating using 50 fps timer events
2850 * especially when no voice frames are received during dtmf processing (direct media or muted
2851 * sender case using SIP INFO)
2852 */
2853static inline int should_trigger_dtmf_emulating(struct ast_channel *chan)
2854{
2856 /* We're in the middle of emulating a digit, or DTMF has been
2857 * explicitly deferred. Trigger dtmf with periodic 50 pfs timer events, then. */
2858 return 1;
2859 }
2860
2861 if (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
2863 /*
2864 * We're not in the middle of a digit, but it hasn't been long enough
2865 * since the last digit, so we'll have to trigger DTMF further on.
2866 * Using 2 times AST_MIN_DTMF_GAP to trigger readq reading for possible
2867 * buffered next dtmf event
2868 */
2869 return 1;
2870 }
2871
2872 return 0;
2873}
2874
2876{
2877 if (ast_channel_generatordata(chan)) {
2878 struct ast_generator *generator = ast_channel_generator(chan);
2879
2880 if (generator && generator->release) {
2881 generator->release(chan, ast_channel_generatordata(chan));
2882 }
2886 ast_settimeout(chan, 0, NULL, NULL);
2887 }
2888}
2889
2891{
2892 ast_channel_lock(chan);
2895 /* if in the middle of dtmf emulation keep 50 tick per sec timer on rolling */
2897 }
2898 ast_channel_unlock(chan);
2899}
2900
2902{
2903 struct ast_generator *generator;
2904
2905 ast_channel_lock(chan);
2906 generator = ast_channel_generator(chan);
2907 if (generator && generator->write_format_change) {
2908 generator->write_format_change(chan, ast_channel_generatordata(chan));
2909 }
2910 ast_channel_unlock(chan);
2911}
2912
2913static int generator_force(const void *data)
2914{
2915 /* Called if generator doesn't have data */
2916 void *tmp;
2917 int res;
2918 int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = NULL;
2919 struct ast_channel *chan = (struct ast_channel *)data;
2920
2921 ast_channel_lock(chan);
2922 tmp = ast_channel_generatordata(chan);
2924 if (ast_channel_generator(chan))
2925 generate = ast_channel_generator(chan)->generate;
2926 ast_channel_unlock(chan);
2927
2928 if (!tmp || !generate) {
2929 return 0;
2930 }
2931
2932 res = generate(chan, tmp, 0, ast_format_get_sample_rate(ast_channel_writeformat(chan)) / 50);
2933
2934 ast_channel_lock(chan);
2935 if (ast_channel_generator(chan) && generate == ast_channel_generator(chan)->generate) {
2937 }
2938 ast_channel_unlock(chan);
2939
2940 if (res) {
2941 ast_debug(1, "Auto-deactivating generator\n");
2943 }
2944
2945 return 0;
2946}
2947
2948int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
2949{
2950 int res = 0;
2951 void *generatordata = NULL;
2952
2953 ast_channel_lock(chan);
2954 if (ast_channel_generatordata(chan)) {
2955 struct ast_generator *generator_old = ast_channel_generator(chan);
2956
2957 if (generator_old && generator_old->release) {
2958 generator_old->release(chan, ast_channel_generatordata(chan));
2959 }
2960 }
2961 if (gen->alloc && !(generatordata = gen->alloc(chan, params))) {
2962 res = -1;
2963 }
2964 ast_channel_generatordata_set(chan, generatordata);
2965 if (!res) {
2966 ast_settimeout(chan, 50, generator_force, chan);
2968 }
2969 ast_channel_unlock(chan);
2970
2971 ast_prod(chan);
2972
2973 return res;
2974}
2975
2976/*! \brief Wait for x amount of time on a file descriptor to have input. */
2977int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception)
2978{
2979 int winner = -1;
2980 ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms);
2981 return winner;
2982}
2983
2984/*! \brief Wait for x amount of time on a file descriptor to have input. */
2985struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds, int nfds,
2986 int *exception, int *outfd, int *ms)
2987{
2988 struct timeval start = { 0 , 0 };
2989 struct pollfd *pfds = NULL;
2990 int res;
2991 long rms;
2992 int x, y, max;
2993 int sz = nfds;
2994 struct timeval now = { 0, 0 };
2995 struct timeval whentohangup = { 0, 0 }, diff;
2996 struct ast_channel *winner = NULL;
2997 struct fdmap {
2998 int chan;
2999 int fdno;
3000 } *fdmap = NULL;
3001
3002 if (outfd) {
3003 *outfd = -99999;
3004 }
3005 if (exception) {
3006 *exception = 0;
3007 }
3008
3009 for (x = 0; x < n; x++) {
3010 ast_channel_lock(c[x]);
3012 if (ast_tvzero(whentohangup))
3013 now = ast_tvnow();
3014 diff = ast_tvsub(*ast_channel_whentohangup(c[x]), now);
3015 if (diff.tv_sec < 0 || ast_tvzero(diff)) {
3016 ast_test_suite_event_notify("HANGUP_TIME", "Channel: %s", ast_channel_name(c[x]));
3017 /* Should already be hungup */
3020 return c[x];
3021 }
3022 if (ast_tvzero(whentohangup) || ast_tvcmp(diff, whentohangup) < 0)
3023 whentohangup = diff;
3024 }
3025 sz += ast_channel_fd_count(c[x]);
3027 }
3028
3029 if (!sz) {
3030 return NULL;
3031 }
3032
3033 pfds = ast_alloca(sizeof(*pfds) * sz);
3034 fdmap = ast_alloca(sizeof(*fdmap) * sz);
3035
3036 /* Wait full interval */
3037 rms = *ms;
3038 /* INT_MAX, not LONG_MAX, because it matters on 64-bit */
3039 if (!ast_tvzero(whentohangup) && whentohangup.tv_sec < INT_MAX / 1000) {
3040 rms = whentohangup.tv_sec * 1000 + whentohangup.tv_usec / 1000; /* timeout in milliseconds */
3041 if (*ms >= 0 && *ms < rms) { /* original *ms still smaller */
3042 rms = *ms;
3043 }
3044 } else if (!ast_tvzero(whentohangup) && rms < 0) {
3045 /* Tiny corner case... call would need to last >24 days */
3046 rms = INT_MAX;
3047 }
3048 /*
3049 * Build the pollfd array, putting the channels' fds first,
3050 * followed by individual fds. Order is important because
3051 * individual fd's must have priority over channel fds.
3052 */
3053 max = 0;
3054 for (x = 0; x < n; x++) {
3055 ast_channel_lock(c[x]);
3056 for (y = 0; y < ast_channel_fd_count(c[x]); y++) {
3057 fdmap[max].fdno = y; /* fd y is linked to this pfds */
3058 fdmap[max].chan = x; /* channel x is linked to this pfds */
3059 max += ast_add_fd(&pfds[max], ast_channel_fd(c[x], y));
3060 }
3061 CHECK_BLOCKING(c[x]);
3063 }
3064 /* Add the individual fds */
3065 for (x = 0; x < nfds; x++) {
3066 fdmap[max].chan = -1;
3067 max += ast_add_fd(&pfds[max], fds[x]);
3068 }
3069
3070 if (*ms > 0) {
3071 start = ast_tvnow();
3072 }
3073
3074 if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */
3075 do {
3076 int kbrms = rms;
3077 if (kbrms > 600000) {
3078 kbrms = 600000;
3079 }
3080 res = ast_poll(pfds, max, kbrms);
3081 if (!res) {
3082 rms -= kbrms;
3083 }
3084 } while (!res && (rms > 0));
3085 } else {
3086 res = ast_poll(pfds, max, rms);
3087 }
3088 for (x = 0; x < n; x++) {
3089 ast_channel_lock(c[x]);
3092 }
3093 if (res < 0) { /* Simulate a timeout if we were interrupted */
3094 if (errno != EINTR) {
3095 *ms = -1;
3096 }
3097 return NULL;
3098 }
3099 if (!ast_tvzero(whentohangup)) { /* if we have a timeout, check who expired */
3100 now = ast_tvnow();
3101 for (x = 0; x < n; x++) {
3103 ast_test_suite_event_notify("HANGUP_TIME", "Channel: %s", ast_channel_name(c[x]));
3105 if (winner == NULL) {
3106 winner = c[x];
3107 }
3108 }
3109 }
3110 }
3111 if (res == 0) { /* no fd ready, reset timeout and done */
3112 *ms = 0; /* XXX use 0 since we may not have an exact timeout. */
3113 return winner;
3114 }
3115 /*
3116 * Then check if any channel or fd has a pending event.
3117 * Remember to check channels first and fds last, as they
3118 * must have priority on setting 'winner'
3119 */
3120 for (x = 0; x < max; x++) {
3121 res = pfds[x].revents;
3122 if (res == 0) {
3123 continue;
3124 }
3125 if (fdmap[x].chan >= 0) { /* this is a channel */
3126 winner = c[fdmap[x].chan]; /* override previous winners */
3127 ast_channel_lock(winner);
3128 if (res & POLLPRI) {
3130 } else {
3132 }
3133 ast_channel_fdno_set(winner, fdmap[x].fdno);
3134 ast_channel_unlock(winner);
3135 } else { /* this is an fd */
3136 if (outfd) {
3137 *outfd = pfds[x].fd;
3138 }
3139 if (exception) {
3140 *exception = (res & POLLPRI) ? -1 : 0;
3141 }
3142 winner = NULL;
3143 }
3144 }
3145 if (*ms > 0) {
3146 *ms -= ast_tvdiff_ms(ast_tvnow(), start);
3147 if (*ms < 0) {
3148 *ms = 0;
3149 }
3150 }
3151 return winner;
3152}
3153
3154struct ast_channel *ast_waitfor_n(struct ast_channel **c, int n, int *ms)
3155{
3156 return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms);
3157}
3158
3159int ast_waitfor(struct ast_channel *c, int ms)
3160{
3161 if (ms < 0) {
3162 do {
3163 ms = 100000;
3164 ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms);
3165 } while (!ms);
3166 } else {
3167 ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms);
3168 }
3169 return ms;
3170}
3171
3172int ast_waitfordigit(struct ast_channel *c, int ms)
3173{
3174 return ast_waitfordigit_full(c, ms, NULL, -1, -1);
3175}
3176
3177int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data)
3178{
3179 return ast_settimeout_full(c, rate, func, data, 0);
3180}
3181
3182int ast_settimeout_full(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data, unsigned int is_ao2_obj)
3183{
3184 int res;
3185 unsigned int real_rate = rate, max_rate;
3186
3188
3189 if (ast_channel_timingfd(c) == -1) {
3191 return -1;
3192 }
3193
3194 if (!func) {
3195 rate = 0;
3196 data = NULL;
3197 }
3198
3199 if (rate && rate > (max_rate = ast_timer_get_max_rate(ast_channel_timer(c)))) {
3200 real_rate = max_rate;
3201 }
3202
3203 ast_debug(3, "Scheduling timer at (%u requested / %u actual) timer ticks per second\n", rate, real_rate);
3204
3205 res = ast_timer_set_rate(ast_channel_timer(c), real_rate);
3206
3209 }
3210
3213
3214 if (data && is_ao2_obj) {
3215 ao2_ref(data, 1);
3217 } else {
3219 }
3220
3221 if (func == NULL && rate == 0 && ast_channel_fdno(c) == AST_TIMING_FD) {
3222 /* Clearing the timing func and setting the rate to 0
3223 * means that we don't want to be reading from the timingfd
3224 * any more. Setting c->fdno to -1 means we won't have any
3225 * errant reads from the timingfd, meaning we won't potentially
3226 * miss any important frames.
3227 */
3229 }
3230
3232
3233 return res;
3234}
3235
3236int ast_waitfordigit_full(struct ast_channel *c, int timeout_ms, const char *breakon, int audiofd, int cmdfd)
3237{
3238 struct timeval start = ast_tvnow();
3239 int ms;
3240
3241 /* Stop if we're a zombie or need a soft hangup */
3243 return -1;
3244
3245 /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */
3247
3248 /* Wait for a digit, no more than timeout_ms milliseconds total.
3249 * Or, wait indefinitely if timeout_ms is <0.
3250 */
3251 while ((ms = ast_remaining_ms(start, timeout_ms))) {
3252 struct ast_channel *rchan;
3253 int outfd = -1;
3254
3255 errno = 0;
3256 /* While ast_waitfor_nandfds tries to help by reducing the timeout by how much was waited,
3257 * it is unhelpful if it waited less than a millisecond.
3258 */
3259 rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
3260
3261 if (!rchan && outfd < 0 && ms) {
3262 if (errno == 0 || errno == EINTR)
3263 continue;
3264 ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
3266 return -1;
3267 } else if (outfd > -1) {
3268 /* The FD we were watching has something waiting */
3269 ast_log(LOG_WARNING, "The FD we were waiting for has something waiting. Waitfordigit returning numeric 1\n");
3271 return 1;
3272 } else if (rchan) {
3273 int res;
3274 struct ast_frame *f = ast_read(c);
3275
3276 if (!f) {
3278
3279 return -1;
3280 }
3281
3282 switch (f->frametype) {
3284 break;
3285 case AST_FRAME_DTMF_END:
3286 res = f->subclass.integer;
3287 if (!breakon || strchr(breakon, res)) {
3288 ast_frfree(f);
3290 return res;
3291 }
3292 break;
3293 case AST_FRAME_CONTROL:
3294 switch (f->subclass.integer) {
3295 case AST_CONTROL_HANGUP:
3296 ast_frfree(f);
3298 return -1;
3304 /* Fall-through and treat as if it were a DTMF signal. Items
3305 * that perform stream control will handle this. */
3306 res = f->subclass.integer;
3307 ast_frfree(f);
3309 return res;
3313 case AST_CONTROL_ANSWER:
3319 case AST_CONTROL_HOLD:
3320 case AST_CONTROL_UNHOLD:
3321 case AST_CONTROL_FLASH:
3322 case -1:
3323 /* Unimportant */
3324 break;
3325 default:
3326 ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass.integer);
3327 break;
3328 }
3329 break;
3330 case AST_FRAME_VOICE:
3331 /* Write audio if appropriate */
3332 if (audiofd > -1) {
3333 if (write(audiofd, f->data.ptr, f->datalen) < 0) {
3334 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
3335 }
3336 }
3337 default:
3338 /* Ignore */
3339 break;
3340 }
3341 ast_frfree(f);
3342 }
3343 }
3344
3346
3347 return 0; /* Time is up */
3348}
3349
3354
3356{
3357 switch (direction) {
3358 case DTMF_RECEIVED:
3359 return "Received";
3360 case DTMF_SENT:
3361 return "Sent";
3362 }
3363
3364 return "?";
3365}
3366
3367static void send_dtmf_begin_event(struct ast_channel *chan,
3368 enum DtmfDirection direction, const char digit)
3369{
3370 RAII_VAR(struct ast_json *, channel_blob, NULL, ast_json_unref);
3371 char digit_str[] = { digit, '\0' };
3372
3373 channel_blob = ast_json_pack("{ s: s, s: s }",
3374 "digit", digit_str,
3375 "direction", dtmf_direction_to_string(direction));
3376
3377 if (channel_blob) {
3379 }
3380}
3381
3382static void send_dtmf_end_event(struct ast_channel *chan,
3383 enum DtmfDirection direction, const char digit, long duration_ms)
3384{
3385 RAII_VAR(struct ast_json *, channel_blob, NULL, ast_json_unref);
3386 RAII_VAR(struct ast_json *, cel_blob, NULL, ast_json_unref);
3387 char digit_str[] = { digit, '\0' };
3388
3389 channel_blob = ast_json_pack("{ s: s, s: s, s: I }",
3390 "digit", digit_str,
3391 "direction", dtmf_direction_to_string(direction),
3392 "duration_ms", (ast_json_int_t)duration_ms);
3393
3394 if (channel_blob) {
3396 }
3397
3398 cel_blob = ast_json_pack("{ s: s, s: { s: s, s: I }}",
3400 "extra",
3401 "digit", digit_str,
3402 "duration_ms", (ast_json_int_t)duration_ms);
3403
3404 if (cel_blob) {
3405 ast_cel_publish_event(chan, AST_CEL_DTMF, cel_blob);
3406 } else {
3407 ast_log(LOG_WARNING, "Unable to build extradata for DTMF CEL event on channel %s", ast_channel_name(chan));
3408 }
3409}
3410
3411static void send_flash_event(struct ast_channel *chan)
3412{
3414}
3415
3416static void send_wink_event(struct ast_channel *chan)
3417{
3419}
3420
3421static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f)
3422{
3423 struct ast_generator *generator;
3424 void *gendata;
3425 int res;
3426 int samples;
3427
3428 generator = ast_channel_generator(chan);
3429 if (!generator
3430 || !generator->generate
3431 || f->frametype != AST_FRAME_VOICE
3433 || ast_channel_timingfunc(chan)) {
3434 return;
3435 }
3436
3437 /*
3438 * We must generate frames in phase locked mode since
3439 * we have no internal timer available.
3440 */
3442 float factor;
3444 samples = (int) (((float) f->samples) * factor);
3445 } else {
3446 samples = f->samples;
3447 }
3448
3449 gendata = ast_channel_generatordata(chan);
3450 ast_channel_generatordata_set(chan, NULL); /* reset, to let writes go through */
3451
3452 /*
3453 * This unlock is here based on two assumptions that hold true at
3454 * this point in the code. 1) this function is only called from
3455 * within __ast_read() and 2) all generators call ast_write() in
3456 * their generate callback.
3457 *
3458 * The reason this is added is so that when ast_write is called,
3459 * the lock that occurs there will not recursively lock the
3460 * channel. Doing this will allow deadlock avoidance to work in
3461 * deeper functions.
3462 */
3463 ast_channel_unlock(chan);
3464 res = generator->generate(chan, gendata, f->datalen, samples);
3465 ast_channel_lock(chan);
3466 if (generator == ast_channel_generator(chan)) {
3467 ast_channel_generatordata_set(chan, gendata);
3468 if (res) {
3469 ast_debug(1, "Auto-deactivating generator\n");
3471 }
3472 }
3473}
3474
3475static inline void queue_dtmf_readq(struct ast_channel *chan, struct ast_frame *f)
3476{
3477 struct ast_frame *fr = ast_channel_dtmff(chan);
3478
3481 fr->len = f->len;
3482
3483 /* The only time this function will be called is for a frame that just came
3484 * out of the channel driver. So, we want to stick it on the tail of the
3485 * readq. */
3486
3487 ast_queue_frame(chan, fr);
3488}
3489
3490/*!
3491 * \brief Determine whether or not we should ignore DTMF in the readq
3492 */
3493static inline int should_skip_dtmf(struct ast_channel *chan)
3494{
3496 /* We're in the middle of emulating a digit, or DTMF has been
3497 * explicitly deferred. Skip this digit, then. */
3498 return 1;
3499 }
3500
3501 if (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
3503 /* We're not in the middle of a digit, but it hasn't been long enough
3504 * since the last digit, so we'll have to skip DTMF for now. */
3505 return 1;
3506 }
3507
3508 return 0;
3509}
3510
3511/*!
3512 * \brief calculates the number of samples to jump forward with in a monitor stream.
3513
3514 * \note When using ast_seekstream() with the read and write streams of a monitor,
3515 * the number of samples to seek forward must be of the same sample rate as the stream
3516 * or else the jump will not be calculated correctly.
3517 *
3518 * \retval number of samples to seek forward after rate conversion.
3519 */
3520static inline int calc_monitor_jump(int samples, int sample_rate, int seek_rate)
3521{
3522 int diff = sample_rate - seek_rate;
3523
3524 if (diff > 0) {
3525 samples = samples / (float) (sample_rate / seek_rate);
3526 } else if (diff < 0) {
3527 samples = samples * (float) (seek_rate / sample_rate);
3528 }
3529
3530 return samples;
3531}
3532
3533static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio, int dropnondefault)
3534{
3535 struct ast_frame *f = NULL; /* the return value */
3536 int prestate;
3537 int cause = 0;
3538 struct ast_stream *stream = NULL, *default_stream = NULL;
3539
3540 /* this function is very long so make sure there is only one return
3541 * point at the end (there are only two exceptions to this).
3542 */
3543 ast_channel_lock(chan);
3544
3545 /* Stop if we're a zombie or need a soft hangup */
3547 if (ast_channel_generator(chan))
3549
3550 /*
3551 * It is possible for chan->_softhangup to be set and there
3552 * still be control frames that need to be read. Instead of
3553 * just going to 'done' in the case of ast_check_hangup(), we
3554 * need to queue the end-of-Q frame so that it can mark the end
3555 * of the read queue. If there are frames to be read,
3556 * ast_queue_control() will be called repeatedly, but will only
3557 * queue the first end-of-Q frame.
3558 */
3561 } else {
3562 goto done;
3563 }
3564 } else {
3565#ifdef AST_DEVMODE
3566 /*
3567 * The ast_waitfor() code records which of the channel's file
3568 * descriptors reported that data is available. In theory,
3569 * ast_read() should only be called after ast_waitfor() reports
3570 * that a channel has data available for reading but certain
3571 * situations with stasis and ARI could give a false indication.
3572 * For this reason, we don't stop any processing.
3573 */
3574 if (ast_channel_fdno(chan) == -1) {
3575 ast_debug(3,
3576 "ast_read() on chan '%s' called with no recorded file descriptor.\n",
3577 ast_channel_name(chan));
3578 }
3579#endif
3580 }
3581
3582 prestate = ast_channel_state(chan);
3583
3584 if (ast_channel_timingfd(chan) > -1 && ast_channel_fdno(chan) == AST_TIMING_FD) {
3585 enum ast_timer_event res;
3586 int trigger_dtmf_emulating = should_trigger_dtmf_emulating(chan);
3587
3589
3591
3592 switch (res) {
3594 if (ast_timer_ack(ast_channel_timer(chan), 1) < 0) {
3595 ast_log(LOG_ERROR, "Failed to acknowledge timer in ast_read\n");
3596 goto done;
3597 }
3598
3599 if (ast_channel_timingfunc(chan)) {
3600 /* save a copy of func/data before unlocking the channel */
3602 void *data = ast_channel_timingdata(chan);
3603 int got_ref = 0;
3605 ao2_ref(data, 1);
3606 got_ref = 1;
3607 }
3608 ast_channel_fdno_set(chan, -1);
3609 ast_channel_unlock(chan);
3610 func(data);
3611 if (got_ref) {
3612 ao2_ref(data, -1);
3613 }
3614
3615 if (trigger_dtmf_emulating) {
3616 /*
3617 * Since we're breaking out of this switch block and not
3618 * returning, we need to re-lock the channel.
3619 */
3620 ast_channel_lock(chan);
3621 /* generate null frame to trigger dtmf emulating */
3622 f = &ast_null_frame;
3623 break;
3624 }
3625 } else if (trigger_dtmf_emulating) {
3626 /* generate null frame to trigger dtmf emulating */
3627 f = &ast_null_frame;
3628 break;
3629 } else {
3631 /* generate very last null frame to trigger dtmf emulating */
3632 f = &ast_null_frame;
3633 break;
3634 }
3635
3636 /* cannot 'goto done' because the channel is already unlocked */
3637 return &ast_null_frame;
3638
3640 if (AST_LIST_EMPTY(ast_channel_readq(chan)) ||
3643 }
3644 break;
3645 }
3646
3649 }
3650
3651 /* Read and ignore anything on the alertpipe, but read only
3652 one sizeof(blah) per frame that we send from it */
3654 f = &ast_null_frame;
3655 goto done;
3656 }
3657
3658 /* Check for pending read queue */
3659 if (!AST_LIST_EMPTY(ast_channel_readq(chan))) {
3660 int skipped_dtmf_frame = 0;
3661 int skip_dtmf = should_skip_dtmf(chan);
3662
3664 /* We have to be picky about which frame we pull off of the readq because
3665 * there are cases where we want to leave DTMF frames on the queue until
3666 * some later time. */
3667
3668 if ( (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) && skip_dtmf) {
3669 skipped_dtmf_frame = 1;
3670 continue;
3671 }
3672
3674 break;
3675 }
3677
3678 if (!f) {
3679 /* There were no acceptable frames on the readq. */
3680 f = &ast_null_frame;
3681 if (!skipped_dtmf_frame) {
3682 /*
3683 * Do not trigger alert pipe if only buffered dtmf begin or end frames
3684 * are left in the readq.
3685 */
3687 } else {
3688 /*
3689 * Safely disable continuous timer events if only buffered dtmf begin or end
3690 * frames are left in the readq.
3691 */
3693 }
3694 }
3695
3696 /* Interpret hangup and end-of-Q frames to return NULL */
3697 /* XXX why not the same for frames from the channel ? */
3698 if (f->frametype == AST_FRAME_CONTROL) {
3699 switch (f->subclass.integer) {
3700 case AST_CONTROL_HANGUP:
3702 cause = f->data.uint32;
3703 /* Fall through */
3705 ast_frfree(f);
3706 f = NULL;
3707 break;
3708 default:
3709 break;
3710 }
3711 } else if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO) {
3712 if (ast_channel_tech(chan) && ast_channel_tech(chan)->read_stream) {
3715 } else {
3716 /* Since this channel driver does not support multistream determine the default stream this frame
3717 * originated from and update the frame to include it.
3718 */
3719 stream = default_stream = ast_channel_get_default_stream(chan, ast_format_get_type(f->subclass.format));
3720 /* In order to allow media to be passed up the underlying media type has to have a format negotiated on
3721 * the channel itself. In cases where this hasn't happened the channel driver is incorrectly passing up
3722 * a frame for a format that has not been negotiated. If this occurs just drop the frame as we have no
3723 * stream that it came from.
3724 */
3725 if (!stream) {
3726 ast_frfree(f);
3727 f = &ast_null_frame;
3728 } else {
3730 }
3731 }
3732 }
3733 } else {
3735 if (ast_channel_tech(chan)->exception)
3736 f = ast_channel_tech(chan)->exception(chan);
3737 else {
3738 ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", ast_channel_name(chan));
3739 f = &ast_null_frame;
3740 }
3741 /* Clear the exception flag */
3743 } else if (ast_channel_tech(chan) && ast_channel_tech(chan)->read_stream) {
3744 f = ast_channel_tech(chan)->read_stream(chan);
3745
3746 /* This channel driver supports multistream so the stream_num on the frame is valid, the only
3747 * thing different is that we need to find the default stream so we know whether to invoke the
3748 * default stream logic or not (such as transcoding).
3749 */
3750 if (f && (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO)) {
3753 }
3754 } else if (ast_channel_tech(chan) && ast_channel_tech(chan)->read) {
3755 f = ast_channel_tech(chan)->read(chan);
3756
3757 /* Since this channel driver does not support multistream determine the default stream this frame
3758 * originated from and update the frame to include it.
3759 */
3760 if (f && (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO)) {
3761 stream = default_stream = ast_channel_get_default_stream(chan, ast_format_get_type(f->subclass.format));
3762 if (!stream) {
3763 ast_frfree(f);
3764 f = &ast_null_frame;
3765 } else {
3767 }
3768 }
3769 }
3770 else
3771 ast_log(LOG_WARNING, "No read routine on channel %s\n", ast_channel_name(chan));
3772 }
3773
3774 if (stream == default_stream) {
3775 /* Perform the framehook read event here. After the frame enters the framehook list
3776 * there is no telling what will happen, <insert mad scientist laugh here>!!! */
3778 }
3779
3780 /*
3781 * Reset the recorded file descriptor that triggered this read so that we can
3782 * easily detect when ast_read() is called without properly using ast_waitfor().
3783 */
3784 ast_channel_fdno_set(chan, -1);
3785
3786 if (f) {
3787 struct ast_frame *readq_tail = AST_LIST_LAST(ast_channel_readq(chan));
3788 struct ast_control_read_action_payload *read_action_payload;
3790 int hooked = 0;
3791
3792 /* if the channel driver returned more than one frame, stuff the excess
3793 into the readq for the next ast_read call
3794 */
3795 if (AST_LIST_NEXT(f, frame_list)) {
3799 }
3800
3801 if (dropnondefault && stream != default_stream) {
3802 /* If the frame originates from a non-default stream and the caller can not handle other streams
3803 * absorb the frame and replace it with a null one instead.
3804 */
3805 ast_frfree(f);
3806 f = &ast_null_frame;
3807 }
3808
3809 switch (f->frametype) {
3810 case AST_FRAME_CONTROL:
3812 if (prestate == AST_STATE_UP && ast_channel_is_bridged(chan)) {
3813 ast_debug(1, "Dropping duplicate answer!\n");
3814 ast_frfree(f);
3815 f = &ast_null_frame;
3816 } else {
3817 /*
3818 * Mark when outgoing channel answered so we can know how
3819 * long the channel has been up.
3820 */
3822
3824 }
3825 } else if (f->subclass.integer == AST_CONTROL_READ_ACTION) {
3826 read_action_payload = f->data.ptr;
3827 switch (read_action_payload->action) {
3831 if (ast_connected_line_parse_data(read_action_payload->payload,
3832 read_action_payload->payload_size, &connected)) {
3834 break;
3835 }
3836 ast_channel_unlock(chan);
3839 read_action_payload->payload,
3840 read_action_payload->payload_size);
3841 }
3843 ast_channel_lock(chan);
3844 break;
3846 ast_channel_unlock(chan);
3847 ast_sendtext(chan, (const char *)read_action_payload->payload);
3848 ast_channel_lock(chan);
3849 break;
3851 ast_channel_unlock(chan);
3852 ast_sendtext_data(chan, (struct ast_msg_data *)read_action_payload->payload);
3853 ast_channel_lock(chan);
3854 break;
3855 }
3856 ast_frfree(f);
3857 f = &ast_null_frame;
3858 } else if (f->subclass.integer == AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE && dropnondefault) {
3859 /* The caller of this function is incapable of handling streams so we don't accept the change request
3860 * and stick to the streams currently on the channel.
3861 */
3863 ast_frfree(f);
3864 f = &ast_null_frame;
3865 } else if (f->subclass.integer == AST_CONTROL_STREAM_TOPOLOGY_CHANGED && dropnondefault) {
3866 /* The caller of this function is incapable of handling streams so we absorb the notification that the
3867 * stream topology has changed.
3868 */
3869 ast_frfree(f);
3870 f = &ast_null_frame;
3871 } else if (f->subclass.integer == AST_CONTROL_FLASH) {
3872 send_flash_event(chan);
3873 } else if (f->subclass.integer == AST_CONTROL_WINK) {
3874 send_wink_event(chan);
3875 }
3876 break;
3877 case AST_FRAME_DTMF_END:
3879 ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass.integer, ast_channel_name(chan), f->len);
3880 /* Queue it up if DTMF is deferred, or if DTMF emulation is forced. */
3882 queue_dtmf_readq(chan, f);
3883 ast_frfree(f);
3884 f = &ast_null_frame;
3886 if (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
3888 /* If it hasn't been long enough, defer this digit */
3889 queue_dtmf_readq(chan, f);
3890 ast_frfree(f);
3891 f = &ast_null_frame;
3892 } else {
3893 /* There was no begin, turn this into a begin and send the end later */
3894 struct timeval tv = ast_tvnow();
3898 ast_channel_dtmf_tv_set(chan, &tv);
3899 if (f->len) {
3900 if (f->len > option_dtmfminduration)
3902 else
3904 } else
3906 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));
3907
3908 /*
3909 * Start generating 50 fps timer events (null frames) for dtmf emulating
3910 * independently from any existing incoming voice frames.
3911 * If channel generator is already activated in regular mode use these
3912 * timer events to generate null frames.
3913 */
3914 if (!ast_channel_generator(chan)) {
3916 }
3917 }
3918 if (ast_channel_audiohooks(chan)) {
3919 struct ast_frame *old_frame = f;
3920 /*!
3921 * \todo XXX It is possible to write a digit to the audiohook twice
3922 * if the digit was originally read while the channel was in autoservice. */
3924 if (old_frame != f)
3925 ast_frfree(old_frame);
3926 }
3927 } else {
3928 struct timeval now = ast_tvnow();
3930 ast_log(LOG_DTMF, "DTMF end accepted with begin '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
3932 if (!f->len)
3933 f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
3934
3935 /* detect tones that were received on
3936 * the wire with durations shorter than
3937 * option_dtmfminduration and set f->len
3938 * to the actual duration of the DTMF
3939 * frames on the wire. This will cause
3940 * dtmf emulation to be triggered later
3941 * on.
3942 */
3944 f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
3945 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));
3946 }
3947 } else if (!f->len) {
3948 ast_log(LOG_DTMF, "DTMF end accepted without begin '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
3950 }
3952 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));
3956 ast_frfree(f);
3957 f = &ast_null_frame;
3958
3959 /* Start generating 50 fps timer events (null frames) for dtmf emulating
3960 * independently from any existing incoming voice frames.
3961 * If channel generator is already activated in regular mode use these
3962 * timer events to generate null frames.
3963 */
3964 if (!ast_channel_generator(chan)) {
3966 }
3967 } else {
3968 ast_log(LOG_DTMF, "DTMF end passthrough '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
3969 if (f->len < option_dtmfminduration) {
3971 }
3972 ast_channel_dtmf_tv_set(chan, &now);
3973
3974 /* Start generating 50 fps timer events (null frames) for dtmf emulating
3975 * independently from any existing incoming voice frames.
3976 * If channel generator is already activated in regular mode use these
3977 * timer events to generate null frames.
3978 */
3979 if (!ast_channel_generator(chan)) {
3981 }
3982 }
3983 if (ast_channel_audiohooks(chan)) {
3984 struct ast_frame *old_frame = f;
3986 if (old_frame != f)
3987 ast_frfree(old_frame);
3988 }
3989 }
3990 break;
3993 ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass.integer, ast_channel_name(chan));
3995 (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
3997 ast_log(LOG_DTMF, "DTMF begin ignored '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
3998 ast_frfree(f);
3999 f = &ast_null_frame;
4000 } else {
4001 struct timeval now = ast_tvnow();
4003 ast_channel_dtmf_tv_set(chan, &now);
4004 ast_log(LOG_DTMF, "DTMF begin passthrough '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
4005 }
4006 break;
4007 case AST_FRAME_NULL:
4008 /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration
4009 * is reached , because we want to make sure we pass at least one
4010 * voice frame through before starting the next digit, to ensure a gap
4011 * between DTMF digits. */
4013 struct timeval now = ast_tvnow();
4017 } else if (ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan)) >= ast_channel_emulate_dtmf_duration(chan)) {
4019 ast_frfree(f);
4020 f = ast_channel_dtmff(chan);
4023 f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
4024 ast_channel_dtmf_tv_set(chan, &now);
4027 ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass.integer, ast_channel_name(chan));
4028 if (ast_channel_audiohooks(chan)) {
4029 struct ast_frame *old_frame = f;
4031 if (old_frame != f) {
4032 ast_frfree(old_frame);
4033 }
4034 }
4035
4036 /* Start generating 50 fps timer events (null frames) for dtmf emulating
4037 * independently from any existing incoming voice frames.
4038 * If channel generator is already activated in regular mode use these
4039 * timer events to generate null frames.
4040 */
4041 if (!ast_channel_generator(chan)) {
4043 }
4044 }
4045 }
4046 break;
4047 case AST_FRAME_VOICE:
4048 /* If media was received from a non-default stream don't perform any actions, let it just go through */
4049 if (stream != default_stream) {
4050 break;
4051 }
4052
4053 /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration
4054 * is reached , because we want to make sure we pass at least one
4055 * voice frame through before starting the next digit, to ensure a gap
4056 * between DTMF digits. */
4060 }
4061
4062 if (dropaudio || ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF)) {
4063 if (dropaudio)
4065 ast_frfree(f);
4066 f = &ast_null_frame;
4067 }
4068
4070 struct timeval now = ast_tvnow();
4073 ast_frfree(f);
4074 f = ast_channel_dtmff(chan);
4077 f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
4078 ast_channel_dtmf_tv_set(chan, &now);
4079 if (ast_channel_audiohooks(chan)) {
4080 struct ast_frame *old_frame = f;
4082 if (old_frame != f)
4083 ast_frfree(old_frame);
4084 }
4085 ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass.integer, ast_channel_name(chan));
4086 } else {
4087 /* Drop voice frames while we're still in the middle of the digit */
4088 ast_frfree(f);
4089 f = &ast_null_frame;
4090 }
4091 break;
4092 }
4093 if (f->frametype != AST_FRAME_VOICE) {
4094 break;
4095 }
4098 struct ast_format *core_format;
4099
4100 /*
4101 * Note: This frame may not be one of the current native
4102 * formats. We may have gotten it out of the read queue from
4103 * a previous multi-frame translation, from a framehook
4104 * injected frame, or the device we're talking to isn't
4105 * respecting negotiated formats. Regardless we will accept
4106 * all frames.
4107 *
4108 * Update the read translation path to handle the new format
4109 * that just came in. If the core wants slinear we need to
4110 * setup a new translation path because the core is usually
4111 * doing something with the audio itself and may not handle
4112 * any other format. e.g., Softmix bridge, holding bridge
4113 * announcer channel, recording, AMD... Otherwise, we'll
4114 * setup to pass the frame as is to the core. In this case
4115 * the core doesn't care. The channel is likely in
4116 * autoservice, safesleep, or the channel is in a bridge.
4117 * Let the bridge technology deal with format compatibility
4118 * between the channels in the bridge.
4119 *
4120 * Beware of the transcode_via_slin and genericplc options as
4121 * they force any transcoding to go through slin on a bridge.
4122 * Unfortunately transcode_via_slin is enabled by default and
4123 * genericplc is enabled in the codecs.conf.sample file.
4124 *
4125 * XXX Only updating translation to slinear frames has some
4126 * corner cases if slinear is one of the native formats and
4127 * there are different sample rates involved. We might wind
4128 * up with conflicting translation paths between channels
4129 * where the read translation path on this channel reduces
4130 * the sample rate followed by a write translation path on
4131 * the peer channel that increases the sample rate.
4132 */
4133 core_format = ast_channel_readformat(chan);
4134 if (!ast_format_cache_is_slinear(core_format)) {
4135 core_format = f->subclass.format;
4136 }
4137 if (ast_set_read_format_path(chan, f->subclass.format, core_format)) {
4138 /* Drop frame. We couldn't make it compatible with the core. */
4139 ast_frfree(f);
4140 f = &ast_null_frame;
4141 break;
4142 }
4143 }
4144 /*
4145 * Send frame to audiohooks if present, if frametype is linear, to preserve
4146 * functional compatibility with previous behavior. If not linear, hold off
4147 * until transcoding is done where we are more likely to have a linear frame
4148 */
4150 /* Place hooked after declaration */
4151 struct ast_frame *old_frame = f;
4152 hooked = 1;
4153
4155 if (old_frame != f) {
4156 ast_frfree(old_frame);
4157 }
4158 }
4159
4160 if (ast_channel_readtrans(chan)
4162 f = ast_translate(ast_channel_readtrans(chan), f, 1);
4163 if (!f) {
4164 f = &ast_null_frame;
4165 }
4166 }
4167
4168 /* Second chance at hooking a linear frame, also the last chance */
4169 if (ast_channel_audiohooks(chan) && !hooked) {
4170 struct ast_frame *old_frame = f;
4171
4173 if (old_frame != f) {
4174 ast_frfree(old_frame);
4175 }
4176 }
4177
4178 /*
4179 * It is possible for the translation process on the channel to have
4180 * produced multiple frames from the single input frame we passed it; if
4181 * this happens, queue the additional frames *before* the frames we may
4182 * have queued earlier. if the readq was empty, put them at the head of
4183 * the queue, and if it was not, put them just after the frame that was
4184 * at the end of the queue.
4185 */
4186 if (AST_LIST_NEXT(f, frame_list)) {
4187 struct ast_frame *cur, *multi_frame = AST_LIST_NEXT(f, frame_list);
4188
4189 /* Mark these frames as being re-queued */
4190 for (cur = multi_frame; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
4192 }
4193
4194 if (!readq_tail) {
4195 ast_queue_frame_head(chan, multi_frame);
4196 } else {
4197 __ast_queue_frame(chan, multi_frame, 0, readq_tail);
4198 }
4199 ast_frfree(multi_frame);
4201 }
4202
4203 /*
4204 * Run generator sitting on the line if timing device not available
4205 * and synchronous generation of outgoing frames is necessary
4206 */
4208 break;
4209 case AST_FRAME_RTCP:
4210 /* Incoming RTCP feedback needs to get to the translator for
4211 * outgoing media, which means we treat it as an ast_write */
4212 if (ast_channel_writetrans(chan)) {
4214 }
4215 break;
4216 default:
4217 /* Just pass it on! */
4218 break;
4219 }
4220 } else {
4221 /* Make sure we always return NULL in the future */
4224 }
4225 if (cause)
4226 ast_channel_hangupcause_set(chan, cause);
4227 if (ast_channel_generator(chan))
4229 /* We no longer End the CDR here */
4230 }
4231
4232 /* High bit prints debugging */
4233 if (ast_channel_fin(chan) & DEBUGCHAN_FLAG)
4234 ast_frame_dump(ast_channel_name(chan), f, "<<");
4236
4237done:
4240
4242 /* The list gets recreated if audiohooks are added again later */
4245 }
4246 ast_channel_unlock(chan);
4247 return f;
4248}
4249
4250struct ast_frame *ast_read(struct ast_channel *chan)
4251{
4252 return __ast_read(chan, 0, 1);
4253}
4254
4256{
4257 return __ast_read(chan, 0, 0);
4258}
4259
4261{
4262 return __ast_read(chan, 1, 1);
4263}
4264
4266{
4267 return __ast_read(chan, 1, 0);
4268}
4269
4270int ast_indicate(struct ast_channel *chan, int condition)
4271{
4272 return ast_indicate_data(chan, condition, NULL, 0);
4273}
4274
4276{
4277 /* Don't include a default case here so that we get compiler warnings
4278 * when a new type is added. */
4279
4280 switch (condition) {
4288 case AST_CONTROL_OPTION:
4289 case AST_CONTROL_WINK:
4290 case AST_CONTROL_FLASH:
4293 case AST_CONTROL_ANSWER:
4294 case AST_CONTROL_HANGUP:
4300 case AST_CONTROL_CC:
4302 case AST_CONTROL_AOC:
4304 case AST_CONTROL_MCID:
4321 break;
4322
4325 case AST_CONTROL_BUSY:
4327 case AST_CONTROL_RING:
4328 case AST_CONTROL_HOLD:
4329 /* You can hear these */
4330 return 1;
4331
4332 case AST_CONTROL_UNHOLD:
4333 /* This is a special case. You stop hearing this. */
4334 break;
4335 }
4336
4337 return 0;
4338}
4339
4341{
4342 char causevar[256];
4343
4344 if (ast_channel_dialed_causes_add(chan, cause_code, datalen)) {
4345 ast_log(LOG_WARNING, "Unable to store hangup cause for %s on %s\n", cause_code->chan_name, ast_channel_name(chan));
4346 }
4347
4348 if (cause_code->emulate_sip_cause) {
4349 snprintf(causevar, sizeof(causevar), "HASH(SIP_CAUSE,%s)", cause_code->chan_name);
4350 ast_func_write(chan, causevar, cause_code->code);
4351 }
4352}
4353
4355{
4356 if (!strcasecmp(flag, "default"))
4357 return DEFAULT_AMA_FLAGS;
4358 if (!strcasecmp(flag, "omit"))
4359 return AST_AMA_OMIT;
4360 if (!strcasecmp(flag, "billing"))
4361 return AST_AMA_BILLING;
4362 if (!strcasecmp(flag, "documentation"))
4363 return AST_AMA_DOCUMENTATION;
4364 return AST_AMA_NONE;
4365}
4366
4368{
4369 switch (flag) {
4370 case AST_AMA_OMIT:
4371 return "OMIT";
4372 case AST_AMA_BILLING:
4373 return "BILLING";
4375 return "DOCUMENTATION";
4376 default:
4377 return "Unknown";
4378 }
4379}
4380
4381/*!
4382 * \internal
4383 * \brief Preprocess connected line update.
4384 * \since 12.0.0
4385 *
4386 * \param chan channel to change the indication
4387 * \param data pointer to payload data
4388 * \param datalen size of payload data
4389 *
4390 * \note This function assumes chan is locked.
4391 *
4392 * \retval 0 keep going.
4393 * \retval -1 quit now.
4394 */
4395static int indicate_connected_line(struct ast_channel *chan, const void *data, size_t datalen)
4396{
4397 struct ast_party_connected_line *chan_connected = ast_channel_connected(chan);
4398 struct ast_party_connected_line *chan_indicated = ast_channel_connected_indicated(chan);
4400 unsigned char current[1024];
4401 unsigned char proposed[1024];
4402 int current_size;
4403 int proposed_size;
4404 int res;
4405
4407 res = ast_connected_line_parse_data(data, datalen, &connected);
4408 if (!res) {
4410 }
4412 if (res) {
4413 return -1;
4414 }
4415
4416 current_size = ast_connected_line_build_data(current, sizeof(current),
4417 chan_indicated, NULL);
4418 proposed_size = ast_connected_line_build_data(proposed, sizeof(proposed),
4419 chan_connected, NULL);
4420 if (current_size == -1 || proposed_size == -1) {
4421 return -1;
4422 }
4423
4424 if (current_size == proposed_size && !memcmp(current, proposed, current_size)) {
4425 ast_debug(1, "%s: Dropping redundant connected line update \"%s\" <%s>.\n",
4426 ast_channel_name(chan),
4427 S_COR(chan_connected->id.name.valid, chan_connected->id.name.str, ""),
4428 S_COR(chan_connected->id.number.valid, chan_connected->id.number.str, ""));
4429 return -1;
4430 }
4431
4432 ast_party_connected_line_copy(chan_indicated, chan_connected);
4433 return 0;
4434}
4435
4436/*!
4437 * \internal
4438 * \brief Preprocess redirecting update.
4439 * \since 12.0.0
4440 *
4441 * \param chan channel to change the indication
4442 * \param data pointer to payload data
4443 * \param datalen size of payload data
4444 *
4445 * \note This function assumes chan is locked.
4446 *
4447 * \retval 0 keep going.
4448 * \retval -1 quit now.
4449 */
4450static int indicate_redirecting(struct ast_channel *chan, const void *data, size_t datalen)
4451{
4452 struct ast_party_redirecting redirecting;
4453 int res;
4454
4456 res = ast_redirecting_parse_data(data, datalen, &redirecting);
4457 if (!res) {
4458 ast_channel_set_redirecting(chan, &redirecting, NULL);
4459 }
4460 ast_party_redirecting_free(&redirecting);
4461 return res ? -1 : 0;
4462}
4463
4464static int indicate_data_internal(struct ast_channel *chan, int _condition, const void *data, size_t datalen)
4465{
4466 /* By using an enum, we'll get compiler warnings for values not handled
4467 * in switch statements. */
4468 enum ast_control_frame_type condition = _condition;
4469 struct ast_tone_zone_sound *ts = NULL;
4470 const struct ast_control_t38_parameters *t38_parameters;
4471 int res;
4472
4473 switch (condition) {
4475 if (indicate_connected_line(chan, data, datalen)) {
4476 res = 0;
4477 return res;
4478 }
4479 break;
4481 if (indicate_redirecting(chan, data, datalen)) {
4482 res = 0;
4483 return res;
4484 }
4485 break;
4486 case AST_CONTROL_HOLD:
4487 case AST_CONTROL_UNHOLD:
4488 ast_channel_hold_state_set(chan, _condition);
4489 break;
4491 t38_parameters = data;
4492 switch (t38_parameters->request_response) {
4494 case AST_T38_NEGOTIATED:
4496 break;
4498 case AST_T38_TERMINATED:
4499 case AST_T38_REFUSED:
4501 break;
4502 default:
4503 break;
4504 }
4505 break;
4506 default:
4507 break;
4508 }
4509
4510 if (is_visible_indication(condition)) {
4511 /* A new visible indication is requested. */
4512 ast_channel_visible_indication_set(chan, _condition);
4513 } else if (condition == AST_CONTROL_UNHOLD || _condition < 0) {
4514 /* Visible indication is cleared/stopped. */
4516 }
4517
4518 if (ast_channel_tech(chan)->indicate) {
4519 /* See if the channel driver can handle this condition. */
4520 res = ast_channel_tech(chan)->indicate(chan, _condition, data, datalen);
4521 } else {
4522 res = -1;
4523 }
4524
4525 if (!res) {
4526 /* The channel driver successfully handled this indication */
4527 res = 0;
4528 return res;
4529 }
4530
4531 /* The channel driver does not support this indication, let's fake
4532 * it by doing our own tone generation if applicable. */
4533
4534 /*!\note If we compare the enumeration type, which does not have any
4535 * negative constants, the compiler may optimize this code away.
4536 * Therefore, we must perform an integer comparison here. */
4537 if (_condition < 0) {
4538 /* Stop any tones that are playing */
4539 ast_playtones_stop(chan);
4540 res = 0;
4541 return res;
4542 }
4543
4544 /* Handle conditions that we have tones for. */
4545 switch (condition) {
4547 /* deprecated T.38 control frame */
4548 res = -1;
4549 return res;
4551 /* there is no way to provide 'default' behavior for these
4552 * control frames, so we need to return failure, but there
4553 * is also no value in the log message below being emitted
4554 * since failure to handle these frames is not an 'error'
4555 * so just return right now. in addition, we want to return
4556 * whatever value the channel driver returned, in case it
4557 * has some meaning.*/
4558 return res;
4560 ts = ast_get_indication_tone(ast_channel_zone(chan), "ring");
4561 /* It is common practice for channel drivers to return -1 if trying
4562 * to indicate ringing on a channel which is up. The idea is to let the
4563 * core generate the ringing inband. However, we don't want the
4564 * warning message about not being able to handle the specific indication
4565 * to print nor do we want ast_indicate_data to return an "error" for this
4566 * condition
4567 */
4568 if (ast_channel_state(chan) == AST_STATE_UP) {
4569 res = 0;
4570 }
4571 break;
4572 case AST_CONTROL_BUSY:
4573 ts = ast_get_indication_tone(ast_channel_zone(chan), "busy");
4574 break;
4577 ts = ast_get_indication_tone(ast_channel_zone(chan), "congestion");
4578 break;
4580 ast_channel_hangupcause_hash_set(chan, data, datalen);
4581 res = 0;
4582 break;
4590 case AST_CONTROL_OPTION:
4591 case AST_CONTROL_WINK:
4592 case AST_CONTROL_FLASH:
4595 case AST_CONTROL_ANSWER:
4596 case AST_CONTROL_HANGUP:
4597 case AST_CONTROL_RING:
4598 case AST_CONTROL_HOLD:
4599 case AST_CONTROL_UNHOLD:
4603 case AST_CONTROL_CC:
4605 case AST_CONTROL_AOC:
4607 case AST_CONTROL_MCID:
4623 /* Nothing left to do for these. */
4624 res = 0;
4625 break;
4626 }
4627
4628 if (ts) {
4629 /* We have a tone to play, yay. */
4630 ast_debug(1, "Driver for channel '%s' does not support indication %u, emulating it\n", ast_channel_name(chan), condition);
4631 res = ast_playtones_start(chan, 0, ts->data, 1);
4632 if (!res) {
4633 ast_test_suite_event_notify("RINGING_INBAND",
4634 "Channel: %s\r\n",
4635 ast_channel_name(chan));
4636 }
4638 }
4639
4640 if (res) {
4641 /* not handled */
4642 ast_log(LOG_WARNING, "Unable to handle indication %u for '%s'\n", condition, ast_channel_name(chan));
4643 }
4644
4645 return res;
4646}
4647
4648int ast_indicate_data(struct ast_channel *chan, int _condition, const void *data, size_t datalen)
4649{
4650 int res;
4651 /* this frame is used by framehooks. if it is set, we must free it at the end of this function */
4652 struct ast_frame *awesome_frame = NULL;
4653
4654 ast_channel_lock(chan);
4655
4656 /* Don't bother if the channel is about to go away, anyway. */
4659 && _condition != AST_CONTROL_MASQUERADE_NOTIFY) {
4660 res = -1;
4661 goto indicate_cleanup;
4662 }
4663
4665 /* Do framehooks now, do it, go, go now */
4666 struct ast_frame frame = {
4668 .subclass.integer = _condition,
4669 .data.ptr = (void *) data, /* this cast from const is only okay because we do the ast_frdup below */
4670 .datalen = datalen
4671 };
4672
4673 /* we have now committed to freeing this frame */
4674 awesome_frame = ast_frdup(&frame);
4675
4676 /* who knows what we will get back! the anticipation is killing me. */
4678 awesome_frame);
4679 if (!awesome_frame
4680 || awesome_frame->frametype != AST_FRAME_CONTROL) {
4681 res = 0;
4682 goto indicate_cleanup;
4683 }
4684
4685 _condition = awesome_frame->subclass.integer;
4686 data = awesome_frame->data.ptr;
4687 datalen = awesome_frame->datalen;
4688 }
4689
4690 res = indicate_data_internal(chan, _condition, data, datalen);
4691
4692indicate_cleanup:
4693 ast_channel_unlock(chan);
4694 if (awesome_frame) {
4695 ast_frfree(awesome_frame);
4696 }
4697
4698 return res;
4699}
4700
4701int ast_recvchar(struct ast_channel *chan, int timeout)
4702{
4703 int c;
4704 char *buf = ast_recvtext(chan, timeout);
4705 if (buf == NULL)
4706 return -1; /* error or timeout */
4707 c = *(unsigned char *)buf;
4708 ast_free(buf);
4709 return c;
4710}
4711
4712char *ast_recvtext(struct ast_channel *chan, int timeout)
4713{
4714 int res;
4715 char *buf = NULL;
4716 struct timeval start = ast_tvnow();
4717 int ms;
4718
4719 while ((ms = ast_remaining_ms(start, timeout))) {
4720 struct ast_frame *f;
4721
4722 if (ast_check_hangup(chan)) {
4723 break;
4724 }
4725 res = ast_waitfor(chan, ms);
4726 if (res <= 0) {/* timeout or error */
4727 break;
4728 }
4729 f = ast_read(chan);
4730 if (f == NULL) {
4731 break; /* no frame */
4732 }
4734 ast_frfree(f);
4735 break;
4736 } else if (f->frametype == AST_FRAME_TEXT) { /* what we want */
4737 buf = ast_strndup((char *) f->data.ptr, f->datalen); /* dup and break */
4738 ast_frfree(f);
4739 break;
4740 }
4741 ast_frfree(f);
4742 }
4743 return buf;
4744}
4745
4746int ast_sendtext_data(struct ast_channel *chan, struct ast_msg_data *msg)
4747{
4748 int res = 0;
4749 const char *body = ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_BODY);
4750 const char *content_type = ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_CONTENT_TYPE);
4751
4752 ast_channel_lock(chan);
4753 /* Stop if we're a zombie or need a soft hangup */
4755 ast_channel_unlock(chan);
4756 return -1;
4757 }
4758
4759 CHECK_BLOCKING(chan);
4760 if (ast_channel_tech(chan)->write_text
4761 && (ast_strlen_zero(content_type) || ast_begins_with(content_type, "text/"))
4763 struct ast_frame f;
4764 /* T.140 payload does not include the null byte terminator */
4765 size_t body_len = strlen(body);
4766
4767 /* Process as T.140 text (moved here from ast_sendtext() */
4768 memset(&f, 0, sizeof(f));
4769 f.src = "DIALPLAN";
4772 f.datalen = body_len;
4774 f.data.ptr = ast_strdup(body);
4775 if (f.data.ptr) {
4776 res = ast_channel_tech(chan)->write_text(chan, &f);
4777 } else {
4778 res = -1;
4779 }
4780 ast_frfree(&f);
4781 } else if ((ast_channel_tech(chan)->properties & AST_CHAN_TP_SEND_TEXT_DATA)
4782 && ast_channel_tech(chan)->send_text_data) {
4783 /* Send enhanced message to a channel driver that supports it */
4784 ast_debug(1, "Sending TEXT_DATA from '%s' to %s:%s %s\n",
4787 ast_channel_name(chan), body);
4788 res = ast_channel_tech(chan)->send_text_data(chan, msg);
4789 } else if (ast_channel_tech(chan)->send_text
4790 && (ast_strlen_zero(content_type) || ast_begins_with(content_type, "text/"))) {
4791 /* Send the body of an enhanced message to a channel driver that supports only a char str */
4792 ast_debug(1, "Sending TEXT to %s: %s\n", ast_channel_name(chan), body);
4793 res = ast_channel_tech(chan)->send_text(chan, body);
4794 } else {
4795 ast_debug(1, "Channel technology does not support sending content type '%s' on channel '%s'\n",
4796 S_OR(content_type, "text/plain"), ast_channel_name(chan));
4797 res = -1;
4798 }
4800 ast_channel_unlock(chan);
4801 return res;
4802}
4803
4804int ast_sendtext(struct ast_channel *chan, const char *text)
4805{
4806 struct ast_msg_data *msg;
4807 int rc;
4808 struct ast_msg_data_attribute attrs[] =
4809 {
4810 {
4812 .value = (char *)text,
4813 }
4814 };
4815
4816 if (ast_strlen_zero(text)) {
4817 return 0;
4818 }
4819
4821 if (!msg) {
4822 return -1;
4823 }
4824 rc = ast_sendtext_data(chan, msg);
4825 ast_free(msg);
4826
4827 return rc;
4828}
4829
4831{
4832 static const char * const mf_tones[] = {
4833 "1300+1500", /* 0 */
4834 "700+900", /* 1 */
4835 "700+1100", /* 2 */
4836 "900+1100", /* 3 */
4837 "700+1300", /* 4 */
4838 "900+1300", /* 5 */
4839 "1100+1300", /* 6 */
4840 "700+1500", /* 7 */
4841 "900+1500", /* 8 */
4842 "1100+1500", /* 9 */
4843 "1100+1700", /* * (KP) */
4844 "1500+1700", /* # (ST) */
4845 "900+1700", /* A (STP) */
4846 "1300+1700", /* B (ST2P) */
4847 "700+1700" /* C (ST3P) */
4848 };
4849
4850 if (digit >= '0' && digit <='9') {
4851 ast_playtones_start(chan, 0, mf_tones[digit-'0'], 0);
4852 } else if (digit == '*') {
4853 ast_playtones_start(chan, 0, mf_tones[10], 0);
4854 } else if (digit == '#') {
4855 ast_playtones_start(chan, 0, mf_tones[11], 0);
4856 } else if (digit == 'A') {
4857 ast_playtones_start(chan, 0, mf_tones[12], 0);
4858 } else if (digit == 'B') {
4859 ast_playtones_start(chan, 0, mf_tones[13], 0);
4860 } else if (digit == 'C') {
4861 ast_playtones_start(chan, 0, mf_tones[14], 0);
4862 } else {
4863 /* not handled */
4864 ast_log(LOG_WARNING, "Unable to generate MF tone '%c' for '%s'\n", digit, ast_channel_name(chan));
4865 }
4866 return 0;
4867}
4868
4870{
4871 /* Device does not support DTMF tones, lets fake
4872 * it by doing our own generation. */
4873 static const char * const dtmf_tones[] = {
4874 "941+1336", /* 0 */
4875 "697+1209", /* 1 */
4876 "697+1336", /* 2 */
4877 "697+1477", /* 3 */
4878 "770+1209", /* 4 */
4879 "770+1336", /* 5 */
4880 "770+1477", /* 6 */
4881 "852+1209", /* 7 */
4882 "852+1336", /* 8 */
4883 "852+1477", /* 9 */
4884 "697+1633", /* A */
4885 "770+1633", /* B */
4886 "852+1633", /* C */
4887 "941+1633", /* D */
4888 "941+1209", /* * */
4889 "941+1477" /* # */
4890 };
4891
4892 if (!ast_channel_tech(chan)->send_digit_begin)
4893 return 0;
4894
4895 ast_channel_lock(chan);
4898 ast_channel_unlock(chan);
4899
4900 if (!ast_channel_tech(chan)->send_digit_begin(chan, digit))
4901 return 0;
4902
4903 if (digit >= '0' && digit <='9')
4904 ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0);
4905 else if (digit >= 'A' && digit <= 'D')
4906 ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0);
4907 else if (digit == '*')
4908 ast_playtones_start(chan, 0, dtmf_tones[14], 0);
4909 else if (digit == '#')
4910 ast_playtones_start(chan, 0, dtmf_tones[15], 0);
4911 else {
4912 /* not handled */
4913 ast_debug(1, "Unable to generate DTMF tone '%c' for '%s'\n", digit, ast_channel_name(chan));
4914 }
4915
4916 return 0;
4917}
4918
4919int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration)
4920{
4921 int res = -1;
4922
4923 if (ast_channel_tech(chan)->send_digit_end)
4924 res = ast_channel_tech(chan)->send_digit_end(chan, digit, duration);
4925
4926 ast_channel_lock(chan);
4929 }
4930 ast_channel_unlock(chan);
4931
4932 if (res && ast_channel_generator(chan))
4933 ast_playtones_stop(chan);
4934
4935 return 0;
4936}
4937
4939{
4940 if (ast_channel_generator(chan)) {
4941 ast_playtones_stop(chan);
4942 return 0;
4943 }
4944 return -1;
4945}
4946
4947int ast_senddigit_mf(struct ast_channel *chan, char digit, unsigned int duration,
4948 unsigned int durationkp, unsigned int durationst, int is_external)
4949{
4950 if (duration < DEFAULT_EMULATE_MF_DURATION) {
4951 duration = DEFAULT_EMULATE_MF_DURATION;
4952 }
4953 if (ast_channel_tech(chan)->send_digit_begin) {
4954 if (digit == '*') {
4955 duration = durationkp;
4956 } else if (digit == '#' || digit == 'A' || digit == 'B' || digit == 'C') {
4957 duration = durationst;
4958 }
4960 if (is_external) {
4961 usleep(duration * 1000);
4962 } else {
4963 ast_safe_sleep(chan, duration);
4964 }
4965 }
4966 return ast_senddigit_mf_end(chan);
4967}
4968
4969int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
4970{
4971 if (duration < AST_DEFAULT_EMULATE_DTMF_DURATION) {
4973 }
4974 if (ast_channel_tech(chan)->send_digit_begin) {
4976 ast_safe_sleep(chan, duration);
4977 }
4978
4979 return ast_senddigit_end(chan, digit, duration);
4980}
4981
4982int ast_senddigit_external(struct ast_channel *chan, char digit, unsigned int duration)
4983{
4984 if (duration < AST_DEFAULT_EMULATE_DTMF_DURATION) {
4986 }
4987 if (ast_channel_tech(chan)->send_digit_begin) {
4989 usleep(duration * 1000);
4990 }
4991
4992 return ast_senddigit_end(chan, digit, duration);
4993}
4994
4995int ast_prod(struct ast_channel *chan)
4996{
4997 struct ast_frame a = { AST_FRAME_VOICE };
4998 char nothing[128];
4999
5000 /* Send an empty audio frame to get things moving */
5001 if (ast_channel_state(chan) != AST_STATE_UP) {
5002 ast_debug(3, "Prodding channel '%s'\n", ast_channel_name(chan));
5003 a.subclass.format = ast_channel_rawwriteformat(chan);
5004 a.data.ptr = nothing + AST_FRIENDLY_OFFSET;
5005 a.src = "ast_prod"; /* this better match check in ast_write */
5006 if (ast_write(chan, &a))
5007 ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", ast_channel_name(chan));
5008 }
5009 return 0;
5010}
5011
5012int ast_write_video(struct ast_channel *chan, struct ast_frame *fr)
5013{
5014 int res;
5015 if (!ast_channel_tech(chan)->write_video)
5016 return 0;
5017 res = ast_write(chan, fr);
5018 if (!res)
5019 res = 1;
5020 return res;
5021}
5022
5023struct plc_ds {
5024 /* A buffer in which to store SLIN PLC
5025 * samples generated by the generic PLC
5026 * functionality in plc.c
5027 */
5028 int16_t *samples_buf;
5029 /* The current number of samples in the
5030 * samples_buf
5031 */
5034};
5035
5036static void plc_ds_destroy(void *data)
5037{
5038 struct plc_ds *plc = data;
5039 ast_free(plc->samples_buf);
5040 ast_free(plc);
5041}
5042
5043static const struct ast_datastore_info plc_ds_info = {
5044 .type = "plc",
5045 .destroy = plc_ds_destroy,
5046};
5047
5048static void adjust_frame_for_plc(struct ast_channel *chan, struct ast_frame *frame, struct ast_datastore *datastore)
5049{
5050 int num_new_samples = frame->samples;
5051 struct plc_ds *plc = datastore->data;
5052
5053 /* As a general note, let me explain the somewhat odd calculations used when taking
5054 * the frame offset into account here. According to documentation in frame.h, the frame's
5055 * offset field indicates the number of bytes that the audio is offset. The plc->samples_buf
5056 * is not an array of bytes, but rather an array of 16-bit integers since it holds SLIN
5057 * samples. So I had two choices to make here with the offset.
5058 *
5059 * 1. Make the offset AST_FRIENDLY_OFFSET bytes. The main downside for this is that
5060 * I can't just add AST_FRIENDLY_OFFSET to the plc->samples_buf and have the pointer
5061 * arithmetic come out right. I would have to do some odd casting or division for this to
5062 * work as I wanted.
5063 * 2. Make the offset AST_FRIENDLY_OFFSET * 2 bytes. This allows the pointer arithmetic
5064 * to work out better with the plc->samples_buf. The downside here is that the buffer's
5065 * allocation contains an extra 64 bytes of unused space.
5066 *
5067 * I decided to go with option 2. This is why in the calloc statement and the statement that
5068 * sets the frame's offset, AST_FRIENDLY_OFFSET is multiplied by 2.
5069 */
5070
5071 /* If this audio frame has no samples to fill in, ignore it */
5072 if (!num_new_samples) {
5073 return;
5074 }
5075
5076 /* First, we need to be sure that our buffer is large enough to accommodate
5077 * the samples we need to fill in. This will likely only occur on the first
5078 * frame we write.
5079 */
5080 if (plc->num_samples < num_new_samples) {
5081 ast_free(plc->samples_buf);
5082 plc->samples_buf = ast_calloc(1, (num_new_samples * sizeof(*plc->samples_buf)) + (AST_FRIENDLY_OFFSET * 2));
5083 if (!plc->samples_buf) {
5084 ast_channel_datastore_remove(chan, datastore);
5085 ast_datastore_free(datastore);
5086 return;
5087 }
5088 plc->num_samples = num_new_samples;
5089 }
5090
5091 if (frame->datalen == 0) {
5093 frame->data.ptr = plc->samples_buf + AST_FRIENDLY_OFFSET;
5094 frame->datalen = num_new_samples * 2;
5095 frame->offset = AST_FRIENDLY_OFFSET * 2;
5096 } else {
5097 plc_rx(&plc->plc_state, frame->data.ptr, frame->samples);
5098 }
5099}
5100
5101static void apply_plc(struct ast_channel *chan, struct ast_frame *frame)
5102{
5103 struct ast_datastore *datastore;
5104 struct plc_ds *plc;
5105
5106 datastore = ast_channel_datastore_find(chan, &plc_ds_info, NULL);
5107 if (datastore) {
5108 plc = datastore->data;
5109 adjust_frame_for_plc(chan, frame, datastore);
5110 return;
5111 }
5112
5113 datastore = ast_datastore_alloc(&plc_ds_info, NULL);
5114 if (!datastore) {
5115 return;
5116 }
5117 plc = ast_calloc(1, sizeof(*plc));
5118 if (!plc) {
5119 ast_datastore_free(datastore);
5120 return;
5121 }
5122 datastore->data = plc;
5123 ast_channel_datastore_add(chan, datastore);
5124 adjust_frame_for_plc(chan, frame, datastore);
5125}
5126
5127static int tech_write(struct ast_channel *chan, struct ast_stream *stream,
5128 struct ast_stream *default_stream, struct ast_frame *frame)
5129{
5130 if (ast_channel_tech(chan)->write_stream) {
5131 return stream ? ast_channel_tech(chan)->write_stream(
5132 chan, ast_stream_get_position(stream), frame) : 0;
5133 }
5134
5135 return ((stream == default_stream) && ast_channel_tech(chan)->write) ?
5136 ast_channel_tech(chan)->write(chan, frame) : 0;
5137}
5138
5139int ast_write(struct ast_channel *chan, struct ast_frame *fr)
5140{
5141 return ast_write_stream(chan, -1, fr);
5142}
5143
5144int ast_write_stream(struct ast_channel *chan, int stream_num, struct ast_frame *fr)
5145{
5146 struct ast_stream *stream = NULL, *default_stream = NULL;
5147 int res = -1;
5148 struct ast_frame *f = NULL;
5149 int count = 0;
5150 int hooked = 0;
5151
5152 /*Deadlock avoidance*/
5153 while(ast_channel_trylock(chan)) {
5154 /*cannot goto done since the channel is not locked*/
5155 if(count++ > 10) {
5156 ast_debug(1, "Deadlock avoided for write to channel '%s'\n", ast_channel_name(chan));
5157 return 0;
5158 }
5159 usleep(1);
5160 }
5161
5162 /* Stop if we're a zombie or need a soft hangup */
5164 goto done;
5165 }
5166
5167 if (stream_num >= 0) {
5168 /* If we were told to write to an explicit stream then allow this frame through, no matter
5169 * if the type is expected or not (a framehook could change)
5170 */
5172 goto done;
5173 }
5175 default_stream = ast_channel_get_default_stream(chan, ast_stream_get_type(stream));
5176 } else if (fr->frametype == AST_FRAME_VOICE || fr->frametype == AST_FRAME_VIDEO || fr->frametype == AST_FRAME_MODEM) {
5177 /* If we haven't been told of a stream then we need to figure out which once we need */
5179
5180 /* Some frame types have a fixed media type */
5181 if (fr->frametype == AST_FRAME_VOICE || fr->frametype == AST_FRAME_VIDEO) {
5183 } else if (fr->frametype == AST_FRAME_MODEM) {
5185 }
5186
5187 /* No stream was specified, so use the default one */
5188 stream = default_stream = ast_channel_get_default_stream(chan, type);
5189 }
5190
5191 /* Perform the framehook write event here. After the frame enters the framehook list
5192 * there is no telling what will happen, how awesome is that!!! */
5193 if ((stream == default_stream) && !(fr = ast_framehook_list_write_event(ast_channel_framehooks(chan), fr))) {
5194 res = 0;
5195 goto done;
5196 }
5197
5198 if (ast_channel_generatordata(chan) && (fr->frametype != AST_FRAME_RTCP) && (!fr->src || strcasecmp(fr->src, "ast_prod"))) {
5201 } else {
5202 if (fr->frametype == AST_FRAME_DTMF_END) {
5203 /* There is a generator running while we're in the middle of a digit.
5204 * It's probably inband DTMF, so go ahead and pass it so it can
5205 * stop the generator */
5206 ast_channel_unlock(chan);
5207 res = ast_senddigit_end(chan, fr->subclass.integer, fr->len);
5208 ast_channel_lock(chan);
5209 } else if (fr->frametype == AST_FRAME_CONTROL
5211 /*
5212 * This is a side case where Echo is basically being called
5213 * and the person put themselves on hold and took themselves
5214 * off hold.
5215 */
5217 fr->datalen);
5218 }
5219 res = 0; /* XXX explain, why 0 ? */
5220 goto done;
5221 }
5222 }
5223 /* High bit prints debugging */
5224 if (ast_channel_fout(chan) & DEBUGCHAN_FLAG)
5225 ast_frame_dump(ast_channel_name(chan), fr, ">>");
5226 switch (fr->frametype) {
5227 case AST_FRAME_CONTROL:
5229 res = 0;
5230 break;
5232 if (ast_channel_audiohooks(chan)) {
5233 struct ast_frame *old_frame = fr;
5235 if (old_frame != fr)
5236 f = fr;
5237 }
5239 ast_channel_unlock(chan);
5240 res = ast_senddigit_begin(chan, fr->subclass.integer);
5241 ast_channel_lock(chan);
5242 break;
5243 case AST_FRAME_DTMF_END:
5244 if (ast_channel_audiohooks(chan)) {
5245 struct ast_frame *new_frame = fr;
5246
5248 if (new_frame != fr) {
5249 ast_frfree(new_frame);
5250 }
5251 }
5253 ast_channel_unlock(chan);
5254 res = ast_senddigit_end(chan, fr->subclass.integer, fr->len);
5255 ast_channel_lock(chan);
5256 break;
5257 case AST_FRAME_TEXT:
5258 CHECK_BLOCKING(chan);
5260 res = (ast_channel_tech(chan)->write_text == NULL) ? 0 :
5261 ast_channel_tech(chan)->write_text(chan, fr);
5262 } else {
5263 res = (ast_channel_tech(chan)->send_text == NULL) ? 0 :
5264 ast_channel_tech(chan)->send_text(chan, (char *) fr->data.ptr);
5265 }
5267 break;
5268 case AST_FRAME_HTML:
5269 CHECK_BLOCKING(chan);
5270 res = (ast_channel_tech(chan)->send_html == NULL) ? 0 :
5271 ast_channel_tech(chan)->send_html(chan, fr->subclass.integer, (char *) fr->data.ptr, fr->datalen);
5273 break;
5274 case AST_FRAME_VIDEO:
5275 /* XXX Handle translation of video codecs one day XXX */
5276 CHECK_BLOCKING(chan);
5277 if (ast_channel_tech(chan)->write_stream) {
5278 if (stream) {
5279 res = ast_channel_tech(chan)->write_stream(chan, ast_stream_get_position(stream), fr);
5280 } else {
5281 res = 0;
5282 }
5283 } else if ((stream == default_stream) && ast_channel_tech(chan)->write_video) {
5284 res = ast_channel_tech(chan)->write_video(chan, fr);
5285 } else {
5286 res = 0;
5287 }
5289 break;
5290 case AST_FRAME_MODEM:
5291 CHECK_BLOCKING(chan);
5292 res = tech_write(chan, stream, default_stream, fr);
5294 break;
5295 case AST_FRAME_VOICE:
5297 apply_plc(chan, fr);
5298 }
5299
5300 f = fr;
5301
5302 /*
5303 * Send frame to audiohooks if present, if frametype is linear (else, later as per
5304 * previous behavior)
5305 */
5306 if ((stream == default_stream) && ast_channel_audiohooks(chan)) {
5308 hooked = 1;
5310 }
5311 }
5312
5313 /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */
5314 if ((stream == default_stream) && ast_format_cmp(fr->subclass.format, ast_channel_rawwriteformat(chan)) != AST_FORMAT_CMP_EQUAL) {
5316 struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5317
5318 /*
5319 * We are not setup to write this frame. Things may have changed
5320 * on the peer side of the world and we try to adjust the format to
5321 * make it compatible again. However, bad things can happen if we
5322 * cannot setup a new translation path. Problems range from no
5323 * audio, one-way audio, to garbled audio. The best we can do is
5324 * request the call to hangup since we could not make it compatible.
5325 *
5326 * Being continuously spammed by this message likely indicates a
5327 * problem with the peer because it cannot make up its mind about
5328 * which format to use.
5329 */
5330 ast_debug(1, "Channel %s changing write format from %s to %s, native formats %s\n",
5331 ast_channel_name(chan),
5335 if (ast_set_write_format(chan, fr->subclass.format)) {
5336 /* Could not handle the new write format. Induce a hangup. */
5337 break;
5338 }
5339 }
5340
5341 if (ast_channel_writetrans(chan)) {
5342 struct ast_frame *trans_frame = ast_translate(ast_channel_writetrans(chan), f, 0);
5343 if (trans_frame != f && f != fr) {
5344 /*
5345 * If translate gives us a new frame and so did the audio
5346 * hook then we need to free the one from the audio hook.
5347 */
5348 ast_frfree(f);
5349 }
5350 f = trans_frame;
5351 }
5352 }
5353
5354 if (!f) {
5355 res = 0;
5356 break;
5357 }
5358
5359 if ((stream == default_stream) && ast_channel_audiohooks(chan) && !hooked) {
5360 struct ast_frame *prev = NULL, *new_frame, *cur, *dup;
5361 int freeoldlist = 0;
5362
5363 if (f != fr) {
5364 freeoldlist = 1;
5365 }
5366
5367 /* Since ast_audiohook_write may return a new frame, and the cur frame is
5368 * an item in a list of frames, create a new list adding each cur frame back to it
5369 * regardless if the cur frame changes or not. */
5370 for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
5372
5373 /* if this frame is different than cur, preserve the end of the list,
5374 * free the old frames, and set cur to be the new frame */
5375 if (new_frame != cur) {
5376
5377 /* doing an ast_frisolate here seems silly, but we are not guaranteed the new_frame
5378 * isn't part of local storage, meaning if ast_audiohook_write is called multiple
5379 * times it may override the previous frame we got from it unless we dup it */
5380 if ((dup = ast_frisolate(new_frame))) {
5382 if (freeoldlist) {
5384 ast_frfree(cur);
5385 }
5386 if (new_frame != dup) {
5387 ast_frfree(new_frame);
5388 }
5389 cur = dup;
5390 }
5391 }
5392
5393 /* now, regardless if cur is new or not, add it to the new list,
5394 * if the new list has not started, cur will become the first item. */
5395 if (prev) {
5396 AST_LIST_NEXT(prev, frame_list) = cur;
5397 } else {
5398 f = cur; /* set f to be the beginning of our new list */
5399 }
5400 prev = cur;
5401 }
5402 }
5403
5404 /* the translator on chan->writetrans may have returned multiple frames
5405 from the single frame we passed in; if so, feed each one of them to the
5406 channel, freeing each one after it has been written */
5407 CHECK_BLOCKING(chan);
5408 if ((f != fr) && AST_LIST_NEXT(f, frame_list)) {
5409 struct ast_frame *cur, *next = NULL;
5410 unsigned int skip = 0;
5411
5412 cur = f;
5413 while (cur) {
5416 if (!skip) {
5417 res = tech_write(chan, stream, default_stream, cur);
5418 if (res < 0) {
5420 skip = 1;
5421 } else if (next) {
5422 /* don't do this for the last frame in the list,
5423 as the code outside the loop will do it once
5424 */
5426 }
5427 }
5428 ast_frfree(cur);
5429 cur = next;
5430 }
5431
5432 /* reset f so the code below doesn't attempt to free it */
5433 f = NULL;
5434 } else {
5435 res = tech_write(chan, stream, default_stream, f);
5436 }
5438 break;
5439 case AST_FRAME_NULL:
5440 case AST_FRAME_IAX:
5441 /* Ignore these */
5442 res = 0;
5443 break;
5444 case AST_FRAME_RTCP:
5445 /* RTCP information is on a per-stream basis and only available on multistream capable channels */
5446 CHECK_BLOCKING(chan);
5447 if (ast_channel_tech(chan)->write_stream && stream) {
5448 res = ast_channel_tech(chan)->write_stream(chan, ast_stream_get_position(stream), fr);
5449 } else {
5450 res = 0;
5451 }
5453 break;
5454 default:
5455 /* At this point, fr is the incoming frame and f is NULL. Channels do
5456 * not expect to get NULL as a frame pointer and will segfault. Hence,
5457 * we output the original frame passed in. */
5458 CHECK_BLOCKING(chan);
5459 res = ast_channel_tech(chan)->write(chan, fr);
5461 break;
5462 }
5463
5464 if (f && f != fr)
5465 ast_frfree(f);
5466
5467 /* Consider a write failure to force a soft hangup */
5468 if (res < 0) {
5470 } else {
5472 }
5473done:
5475 /* The list gets recreated if audiohooks are added again later */
5478 }
5479 ast_channel_unlock(chan);
5480 return res;
5481}
5482
5483int ast_set_read_format_path(struct ast_channel *chan, struct ast_format *raw_format, struct ast_format *core_format)
5484{
5485 struct ast_trans_pvt *trans_old;
5486 struct ast_trans_pvt *trans_new;
5487
5490 /* Nothing to setup */
5491 return 0;
5492 }
5493
5494 ast_debug(1, "Channel %s setting read format path: %s -> %s\n",
5495 ast_channel_name(chan),
5496 ast_format_get_name(raw_format),
5497 ast_format_get_name(core_format));
5498
5499 /* Setup new translation path. */
5500 if (ast_format_cmp(raw_format, core_format) != AST_FORMAT_CMP_EQUAL) {
5501 trans_new = ast_translator_build_path(core_format, raw_format);
5502 if (!trans_new) {
5503 return -1;
5504 }
5505 } else {
5506 /* No translation needed. */
5507 trans_new = NULL;
5508 }
5509 trans_old = ast_channel_readtrans(chan);
5510 if (trans_old) {
5511 ast_translator_free_path(trans_old);
5512 }
5513 ast_channel_readtrans_set(chan, trans_new);
5514 ast_channel_set_rawreadformat(chan, raw_format);
5515 ast_channel_set_readformat(chan, core_format);
5516 return 0;
5517}
5518
5519int ast_set_write_format_path(struct ast_channel *chan, struct ast_format *core_format, struct ast_format *raw_format)
5520{
5521 struct ast_trans_pvt *trans_old;
5522 struct ast_trans_pvt *trans_new;
5523
5526 /* Nothing to setup */
5527 return 0;
5528 }
5529
5530 ast_debug(1, "Channel %s setting write format path: %s -> %s\n",
5531 ast_channel_name(chan),
5532 ast_format_get_name(core_format),
5533 ast_format_get_name(raw_format));
5534
5535 /* Setup new translation path. */
5536 if (ast_format_cmp(raw_format, core_format) != AST_FORMAT_CMP_EQUAL) {
5537 trans_new = ast_translator_build_path(raw_format, core_format);
5538 if (!trans_new) {
5539 return -1;
5540 }
5541 } else {
5542 /* No translation needed. */
5543 trans_new = NULL;
5544 }
5545 trans_old = ast_channel_writetrans(chan);
5546 if (trans_old) {
5547 ast_translator_free_path(trans_old);
5548 }
5549 ast_channel_writetrans_set(chan, trans_new);
5550 ast_channel_set_rawwriteformat(chan, raw_format);
5551 ast_channel_set_writeformat(chan, core_format);
5552 return 0;
5553}
5554
5556 const char *direction;
5557 struct ast_trans_pvt *(*get_trans)(const struct ast_channel *chan);
5558 void (*set_trans)(struct ast_channel *chan, struct ast_trans_pvt *value);
5559 struct ast_format *(*get_format)(struct ast_channel *chan);
5560 void (*set_format)(struct ast_channel *chan, struct ast_format *format);
5561 struct ast_format *(*get_rawformat)(struct ast_channel *chan);
5562 void (*set_rawformat)(struct ast_channel *chan, struct ast_format *format);
5564};
5565
5567 .direction = "read",
5568 .get_trans = ast_channel_readtrans,
5569 .set_trans = ast_channel_readtrans_set,
5570 .get_format = ast_channel_readformat,
5571 .set_format = ast_channel_set_readformat,
5572 .get_rawformat = ast_channel_rawreadformat,
5573 .set_rawformat = ast_channel_set_rawreadformat,
5574 .setoption = AST_OPTION_FORMAT_READ,
5575};
5576
5578 .direction = "write",
5579 .get_trans = ast_channel_writetrans,
5580 .set_trans = ast_channel_writetrans_set,
5581 .get_format = ast_channel_writeformat,
5582 .set_format = ast_channel_set_writeformat,
5583 .get_rawformat = ast_channel_rawwriteformat,
5584 .set_rawformat = ast_channel_set_rawwriteformat,
5585 .setoption = AST_OPTION_FORMAT_WRITE,
5586};
5587
5588static int set_format(struct ast_channel *chan, struct ast_format_cap *cap_set, const int direction, int interleaved_stereo)
5589{
5590 struct ast_trans_pvt *trans_pvt;
5591 struct ast_format_cap *cap_native;
5592 const struct set_format_access *access;
5593 struct ast_format *rawformat;
5594 struct ast_format *format;
5595 RAII_VAR(struct ast_format *, best_set_fmt, NULL, ao2_cleanup);
5596 RAII_VAR(struct ast_format *, best_native_fmt, NULL, ao2_cleanup);
5597 int res;
5598
5599 if (!direction) {
5600 /* reading */
5601 access = &set_format_access_read;
5602 } else {
5603 /* writing */
5604 access = &set_format_access_write;
5605 }
5606
5608 if (!best_set_fmt) {
5609 /*
5610 * Not setting any audio formats?
5611 * Assume a call without any sounds (video, text)
5612 */
5613 return 0;
5614 }
5615
5616 /* See if the underlying channel driver is capable of performing transcoding for us */
5617 res = ast_channel_setoption(chan, access->setoption,
5618 &best_set_fmt, sizeof(best_set_fmt), 0);
5619 if (!res) {
5620 ast_debug(1, "Channel driver natively set channel %s to %s format %s\n",
5621 ast_channel_name(chan), access->direction, ast_format_get_name(best_set_fmt));
5622
5623 ast_channel_lock(chan);
5625 if (!cap_native
5626 || ast_format_cap_append(cap_native, best_set_fmt, 0)) {
5627 ast_channel_unlock(chan);
5628 ao2_cleanup(cap_native);
5629 return -1;
5630 }
5631 ast_channel_nativeformats_set(chan, cap_native);
5632 ao2_cleanup(cap_native);
5633 access->set_format(chan, best_set_fmt);
5634 access->set_rawformat(chan, best_set_fmt);
5635
5636 trans_pvt = access->get_trans(chan);
5637 if (trans_pvt) {
5638 ast_translator_free_path(trans_pvt);
5639 access->set_trans(chan, NULL);
5640 }
5641 ast_channel_unlock(chan);
5642
5643 /* If there is a generator on the channel, it needs to know about this
5644 * change if it is the write format. */
5645 if (direction && ast_channel_generatordata(chan)) {
5647 }
5648
5649 return 0;
5650 }
5651
5652 ast_channel_lock(chan);
5653
5654 format = access->get_format(chan);
5655 rawformat = access->get_rawformat(chan);
5656 ast_assert(format != NULL);
5657 ast_assert(rawformat != NULL);
5658
5659 cap_native = ast_channel_nativeformats(chan);
5660 if (ast_format_cap_empty(cap_native)) {
5661 ast_channel_unlock(chan);
5662 ast_log(LOG_ERROR, "Unable to set format because channel %s supports no formats\n",
5663 ast_channel_name(chan));
5664 return -1;
5665 }
5666
5667 /* Find a translation path from the native format to one of the desired formats */
5668 if (!direction) {
5669 /* reading */
5670 res = ast_translator_best_choice(cap_set, cap_native, &best_set_fmt, &best_native_fmt);
5671 } else {
5672 /* writing */
5673 res = ast_translator_best_choice(cap_native, cap_set, &best_native_fmt, &best_set_fmt);
5674 }
5675 if (res < 0) {
5676 struct ast_str *codec_native = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5677 struct ast_str *codec_set = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5678
5679 ast_format_cap_get_names(cap_native, &codec_native);
5680 ast_channel_unlock(chan);
5681 ast_format_cap_get_names(cap_set, &codec_set);
5682
5683 ast_log(LOG_WARNING, "Unable to find a codec translation path: %s -> %s\n",
5684 ast_str_buffer(direction ? codec_set : codec_native),
5685 ast_str_buffer(direction ? codec_native : codec_set));
5686 return -1;
5687 }
5688
5689 /* Now we have a good choice for both. */
5690 trans_pvt = access->get_trans(chan);
5691 if ((ast_format_cmp(rawformat, best_native_fmt) != AST_FORMAT_CMP_NOT_EQUAL) &&
5692 (ast_format_cmp(format, best_set_fmt) != AST_FORMAT_CMP_NOT_EQUAL) &&
5693 ((ast_format_cmp(rawformat, format) != AST_FORMAT_CMP_NOT_EQUAL) || access->get_trans(chan))) {
5694 /* the channel is already in these formats, so nothing to do, unless the interleaved format is not set correctly */
5695 if (trans_pvt != NULL) {
5696 if (trans_pvt->interleaved_stereo == interleaved_stereo) {
5697 ast_channel_unlock(chan);
5698 return 0;
5699 }
5700 }
5701 }
5702
5703 /* Free any translation we have right now */
5704 if (trans_pvt) {
5705 ast_translator_free_path(trans_pvt);
5706 access->set_trans(chan, NULL);
5707 }
5708
5709 /* Build a translation path from the raw format to the desired format */
5710 if (ast_format_cmp(best_set_fmt, best_native_fmt) != AST_FORMAT_CMP_NOT_EQUAL) {
5711 /*
5712 * If we were able to swap the native format to the format that
5713 * has been requested, then there is no need to try to build
5714 * a translation path.
5715 */
5716 res = 0;
5717 } else {
5718 if (!direction) {
5719 /* reading */
5720 trans_pvt = ast_translator_build_path(best_set_fmt, best_native_fmt);
5721 if (trans_pvt) {
5722 trans_pvt->interleaved_stereo = 0;
5723 }
5724 } else {
5725 /* writing */
5726 trans_pvt = ast_translator_build_path(best_native_fmt, best_set_fmt);
5727 if (trans_pvt) {
5728 trans_pvt->interleaved_stereo = interleaved_stereo;
5729 }
5730 }
5731 access->set_trans(chan, trans_pvt);
5732 res = trans_pvt ? 0 : -1;
5733 }
5734
5735 if (!res) {
5736 access->set_format(chan, best_set_fmt);
5737 access->set_rawformat(chan, best_native_fmt);
5738
5739 ast_debug(1, "Channel %s setting %s format path: %s -> %s\n",
5740 ast_channel_name(chan),
5741 access->direction,
5742 ast_format_get_name(direction ? best_set_fmt : best_native_fmt),
5743 ast_format_get_name(direction ? best_native_fmt : best_set_fmt));
5744 }
5745
5746 ast_channel_unlock(chan);
5747
5748 /* If there is a generator on the channel, it needs to know about this
5749 * change if it is the write format. */
5750 if (direction && ast_channel_generatordata(chan)) {
5752 }
5753
5754 return res;
5755}
5756
5757int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
5758{
5760 int res;
5761
5762 ast_assert(format != NULL);
5763
5764 if (!cap) {
5765 return -1;
5766 }
5767 ast_format_cap_append(cap, format, 0);
5768
5769 res = set_format(chan, cap, 0, 0);
5770
5771 ao2_cleanup(cap);
5772 return res;
5773}
5774
5776{
5777 return set_format(chan, cap, 0, 0);
5778}
5779
5781{
5783 int res;
5784
5785 ast_assert(format != NULL);
5786
5787 if (!cap) {
5788 return -1;
5789 }
5790 ast_format_cap_append(cap, format, 0);
5791
5792 res = set_format(chan, cap, 1, 1);
5793
5794 ao2_cleanup(cap);
5795 return res;
5796}
5797
5798int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
5799{
5801 int res;
5802
5803 ast_assert(format != NULL);
5804
5805 if (!cap) {
5806 return -1;
5807 }
5808 ast_format_cap_append(cap, format, 0);
5809
5810 res = set_format(chan, cap, 1, 0);
5811
5812 ao2_cleanup(cap);
5813 return res;
5814}
5815
5817{
5818 return set_format(chan, cap, 1, 0);
5819}
5820
5821const char *ast_channel_reason2str(int reason)
5822{
5823 switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */
5824 {
5825 case 0:
5826 return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)";
5827 case AST_CONTROL_HANGUP:
5828 return "Hangup";
5829 case AST_CONTROL_RING:
5830 return "Local Ring";
5832 return "Remote end Ringing";
5833 case AST_CONTROL_ANSWER:
5834 return "Remote end has Answered";
5835 case AST_CONTROL_BUSY:
5836 return "Remote end is Busy";
5838 return "Congestion (circuits busy)";
5839 default:
5840 return "Unknown Reason!!";
5841 }
5842}
5843
5844static void handle_cause(int cause, int *outstate)
5845{
5846 if (outstate) {
5847 /* compute error and return */
5848 if (cause == AST_CAUSE_BUSY)
5849 *outstate = AST_CONTROL_BUSY;
5850 else if (cause == AST_CAUSE_CONGESTION)
5851 *outstate = AST_CONTROL_CONGESTION;
5852 else
5853 *outstate = 0;
5854 }
5855}
5856
5857/*!
5858 * \internal
5859 * \brief Helper function to inherit info from parent channel.
5860 *
5861 * \param new_chan Channel inheriting information.
5862 * \param parent Channel new_chan inherits information.
5863 * \param orig Channel being replaced by the call forward channel.
5864 */
5865static void call_forward_inherit(struct ast_channel *new_chan, struct ast_channel *parent, struct ast_channel *orig)
5866{
5868 struct ast_party_redirecting redirecting;
5869
5870 /*
5871 * The parent is not a ZOMBIE or hungup so update it with the
5872 * original channel's redirecting information.
5873 */
5874 ast_party_redirecting_init(&redirecting);
5878 if (ast_channel_redirecting_sub(orig, parent, &redirecting, 0)) {
5879 ast_channel_update_redirecting(parent, &redirecting, NULL);
5880 }
5881 ast_party_redirecting_free(&redirecting);
5882 }
5883
5884 /* Safely inherit variables and datastores from the parent channel. */
5885 ast_channel_lock_both(parent, new_chan);
5886 ast_channel_inherit_variables(parent, new_chan);
5887 ast_channel_datastore_inherit(parent, new_chan);
5889 ast_channel_unlock(new_chan);
5890 ast_channel_unlock(parent);
5891}
5892
5893struct 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)
5894{
5895 char tmpchan[256];
5896 char forwarder[AST_CHANNEL_NAME];
5897 struct ast_channel *new_chan = NULL;
5898 char *data, *type;
5899 int cause = 0;
5900 int res;
5901
5902 /* gather data and request the new forward channel */
5903 ast_copy_string(tmpchan, ast_channel_call_forward(orig), sizeof(tmpchan));
5904 ast_copy_string(forwarder, ast_channel_name(orig), sizeof(forwarder));
5905 if ((data = strchr(tmpchan, '/'))) {
5906 *data++ = '\0';
5907 type = tmpchan;
5908 } else {
5909 const char *forward_context;
5910 ast_channel_lock(orig);
5911 forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT");
5912 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(orig), S_OR(forward_context, ast_channel_context(orig)));
5913 ast_channel_unlock(orig);
5914 data = tmpchan;
5915 type = "Local";
5916 }
5917 if (!(new_chan = ast_request(type, cap, NULL, orig, data, &cause))) {
5918 ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause);
5919 handle_cause(cause, outstate);
5920 ast_hangup(orig);
5921 return NULL;
5922 }
5923
5924 /* Copy/inherit important information into new channel */
5925 if (oh) {
5926 if (oh->vars) {
5927 ast_channel_lock(new_chan);
5928 ast_set_variables(new_chan, oh->vars);
5929 ast_channel_unlock(new_chan);
5930 }
5931 if (oh->parent_channel) {
5932 call_forward_inherit(new_chan, oh->parent_channel, orig);
5933 }
5934 if (!ast_strlen_zero(oh->account)) {
5935 ast_channel_lock(new_chan);
5937 ast_channel_accountcode_set(new_chan, oh->account);
5938 ast_channel_peeraccount_set(new_chan, oh->account);
5940 ast_channel_unlock(new_chan);
5941 }
5942 } else if (caller) { /* no outgoing helper so use caller if available */
5943 call_forward_inherit(new_chan, caller, orig);
5944 }
5945
5946 ast_channel_lock_both(orig, new_chan);
5948 pbx_builtin_setvar_helper(new_chan, "FORWARDERNAME", forwarder);
5952 ast_channel_unlock(new_chan);
5953 ast_channel_unlock(orig);
5954
5955 /* call new channel */
5956 res = ast_call(new_chan, data, 0);
5957 if (timeout) {
5958 *timeout = res;
5959 }
5960 if (res) {
5961 ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data);
5962 ast_hangup(orig);
5963 ast_hangup(new_chan);
5964 return NULL;
5965 }
5966 ast_hangup(orig);
5967
5968 return new_chan;
5969}
5970
5971struct 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)
5972{
5973 int dummy_outstate;
5974 int cause = 0;
5975 struct ast_channel *chan;
5976 int res = 0;
5977 int last_subclass = 0;
5979
5980 if (outstate)
5981 *outstate = 0;
5982 else
5983 outstate = &dummy_outstate; /* make outstate always a valid pointer */
5984
5985 chan = ast_request(type, cap, assignedids, requestor, addr, &cause);
5986 if (!chan) {
5987 ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, addr);
5988 handle_cause(cause, outstate);
5989 return NULL;
5990 }
5991
5992 if (oh) {
5993 if (oh->vars) {
5994 ast_channel_lock(chan);
5995 ast_set_variables(chan, oh->vars);
5996 ast_channel_unlock(chan);
5997 }
5998 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) {
5999 /*
6000 * Use the oh values instead of the function parameters for the
6001 * outgoing CallerID.
6002 */
6003 cid_num = oh->cid_num;
6004 cid_name = oh->cid_name;
6005 }
6006 if (oh->parent_channel) {
6007 /* Safely inherit variables and datastores from the parent channel. */
6013 ast_channel_unlock(chan);
6014 }
6015 if (!ast_strlen_zero(oh->account)) {
6016 ast_channel_lock(chan);
6018 ast_channel_accountcode_set(chan, oh->account);
6019 ast_channel_peeraccount_set(chan, oh->account);
6021 ast_channel_unlock(chan);
6022 }
6023 }
6024
6025 /*
6026 * It seems strange to set the CallerID on an outgoing call leg
6027 * to whom we are calling, but this function's callers are doing
6028 * various Originate methods. This call leg goes to the local
6029 * user. Once the local user answers, the dialplan needs to be
6030 * able to access the CallerID from the CALLERID function as if
6031 * the local user had placed this call.
6032 */
6033 ast_set_callerid(chan, cid_num, cid_name, cid_num);
6034
6035 ast_channel_lock(chan);
6037 ast_channel_unlock(chan);
6039 if (cid_num) {
6040 connected.id.number.valid = 1;
6041 connected.id.number.str = (char *) cid_num;
6043 }
6044 if (cid_name) {
6045 connected.id.name.valid = 1;
6046 connected.id.name.str = (char *) cid_name;
6048 }
6050 if (requestor) {
6051 ast_channel_lock_both(chan, (struct ast_channel *) requestor);
6053 ast_channel_unlock(chan);
6054 ast_channel_unlock((struct ast_channel *) requestor);
6055 }
6056
6057 if (ast_call(chan, addr, 0)) { /* ast_call failed... */
6058 ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, addr);
6059 } else {
6060 struct timeval start = ast_tvnow();
6061 res = 1; /* mark success in case chan->_state is already AST_STATE_UP */
6062 while (timeout && ast_channel_state(chan) != AST_STATE_UP) {
6063 struct ast_frame *f;
6064 int ms = ast_remaining_ms(start, timeout);
6065
6066 res = ast_waitfor(chan, ms);
6067 if (res == 0) { /* timeout, treat it like ringing */
6068 *outstate = AST_CONTROL_RINGING;
6069 break;
6070 }
6071 if (res < 0) /* error or done */
6072 break;
6074 if (!(chan = ast_call_forward(NULL, chan, NULL, cap, oh, outstate))) {
6075 return NULL;
6076 }
6077 continue;
6078 }
6079
6080 f = ast_read(chan);
6081 if (!f) {
6082 *outstate = AST_CONTROL_HANGUP;
6083 res = 0;
6084 break;
6085 }
6086 if (f->frametype == AST_FRAME_CONTROL) {
6087 switch (f->subclass.integer) {
6088 case AST_CONTROL_RINGING: /* record but keep going */
6089 *outstate = f->subclass.integer;
6090 break;
6091
6092 case AST_CONTROL_BUSY:
6093 *outstate = f->subclass.integer;
6094 timeout = 0;
6095 break;
6096
6098 *outstate = AST_CONTROL_CONGESTION;
6099 timeout = 0;
6100 break;
6101
6103 *outstate = f->subclass.integer;
6104 timeout = 0;
6105 break;
6106
6107 case AST_CONTROL_ANSWER:
6108 *outstate = f->subclass.integer;
6109 timeout = 0; /* trick to force exit from the while() */
6110 break;
6111
6114 break;
6115
6117 if (oh && oh->connect_on_early_media) {
6118 *outstate = f->subclass.integer;
6119 timeout = 0; /* trick to force exit from the while() */
6120 break;
6121 }
6122 /* Fallthrough */
6123 /* Ignore these */
6125 case AST_CONTROL_HOLD:
6126 case AST_CONTROL_UNHOLD:
6132 case AST_CONTROL_CC:
6133 case -1: /* Ignore -- just stopping indications */
6134 break;
6135
6136 default:
6137 ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass.integer);
6138 }
6139 last_subclass = f->subclass.integer;
6140 }
6141 ast_frfree(f);
6142 }
6143 }
6144
6145 /* Final fixups */
6146 if (oh) {
6147 if (!ast_strlen_zero(oh->context))
6149 if (!ast_strlen_zero(oh->exten))
6150 ast_channel_exten_set(chan, oh->exten);
6151 if (oh->priority)
6153 }
6154 if (ast_channel_state(chan) == AST_STATE_UP)
6155 *outstate = AST_CONTROL_ANSWER;
6156
6157 if (res <= 0) {
6158 ast_channel_lock(chan);
6159 if (AST_CONTROL_RINGING == last_subclass) {
6161 }
6162 ast_channel_unlock(chan);
6163 ast_hangup(chan);
6164 chan = NULL;
6165 }
6166 return chan;
6167}
6168
6169struct 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)
6170{
6171 return __ast_request_and_dial(type, cap, assignedids, requestor, addr, timeout, outstate, cidnum, cidname, NULL);
6172}
6173
6174static int set_security_requirements(const struct ast_channel *requestor, struct ast_channel *out)
6175{
6176 int ops[2][2] = {
6179 };
6180 int i;
6181 struct ast_channel *r = (struct ast_channel *) requestor; /* UGLY */
6182 struct ast_datastore *ds;
6183
6184 if (!requestor || !out) {
6185 return 0;
6186 }
6187
6190 struct ast_secure_call_store *encrypt = ds->data;
6191 ops[0][1] = encrypt->signaling;
6192 ops[1][1] = encrypt->media;
6193 } else {
6195 return 0;
6196 }
6198
6199 for (i = 0; i < 2; i++) {
6200 if (ops[i][1]) {
6201 if (ast_channel_setoption(out, ops[i][0], &ops[i][1], sizeof(ops[i][1]), 0)) {
6202 /* We require a security feature, but the channel won't provide it */
6203 return -1;
6204 }
6205 } else {
6206 /* We don't care if we can't clear the option on a channel that doesn't support it */
6207 ast_channel_setoption(out, ops[i][0], &ops[i][1], sizeof(ops[i][1]), 0);
6208 }
6209 }
6210
6211 return 0;
6212}
6213
6214static struct ast_channel *request_channel(const char *type, struct ast_format_cap *request_cap, struct ast_stream_topology *topology,
6215 const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
6216{
6217 struct chanlist *chan;
6218 struct ast_channel *c = NULL;
6219 int res;
6220 int foo;
6221
6222 if (!cause)
6223 cause = &foo;
6224 *cause = AST_CAUSE_NOTDEFINED;
6225
6227 ast_log(LOG_WARNING, "Unable to lock technology backend list\n");
6228 return NULL;
6229 }
6230
6231 AST_RWLIST_TRAVERSE(&backends, chan, list) {
6232 if (strcasecmp(type, chan->tech->type)) {
6233 continue;
6234 }
6235
6236 break;
6237 }
6238
6240
6241 if (!chan) {
6242 ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
6243 *cause = AST_CAUSE_NOSUCHDRIVER;
6244 return NULL;
6245 }
6246
6247 /* Allow either format capabilities or stream topology to be provided and adapt */
6248 if (chan->tech->requester_with_stream_topology) {
6249 struct ast_stream_topology *tmp_converted_topology = NULL;
6250
6251 if (!topology && request_cap) {
6252 /* Turn the requested capabilities into a stream topology */
6253 topology = tmp_converted_topology = ast_stream_topology_create_from_format_cap(request_cap);
6254 }
6255
6256 c = chan->tech->requester_with_stream_topology(type, topology, assignedids, requestor, addr, cause);
6257
6258 ast_stream_topology_free(tmp_converted_topology);
6259 } else if (chan->tech->requester) {
6260 struct ast_format_cap *tmp_converted_cap = NULL;
6261 struct ast_format_cap *tmp_cap;
6262 RAII_VAR(struct ast_format *, tmp_fmt, NULL, ao2_cleanup);
6263 RAII_VAR(struct ast_format *, best_audio_fmt, NULL, ao2_cleanup);
6264 struct ast_format_cap *joint_cap;
6265
6266 if (!request_cap && topology) {
6267 /* Turn the request stream topology into capabilities */
6268 request_cap = tmp_converted_cap = ast_stream_topology_get_formats(topology);
6269 }
6270
6271 /* find the best audio format to use */
6273 if (!tmp_cap) {
6275 return NULL;
6276 }
6277
6279 if (!ast_format_cap_empty(tmp_cap)) {
6280 /* We have audio - is it possible to connect the various calls to each other?
6281 (Avoid this check for calls without audio, like text+video calls)
6282 */
6283 res = ast_translator_best_choice(tmp_cap, chan->tech->capabilities, &tmp_fmt, &best_audio_fmt);
6284 ao2_ref(tmp_cap, -1);
6285 if (res < 0) {
6286 struct ast_str *tech_codecs = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
6287 struct ast_str *request_codecs = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
6288
6289 ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %s) to %s\n", type,
6290 ast_format_cap_get_names(chan->tech->capabilities, &tech_codecs),
6291 ast_format_cap_get_names(request_cap, &request_codecs));
6293 ao2_cleanup(tmp_converted_cap);
6294 return NULL;
6295 }
6296 }
6297
6298 /* XXX Only the audio format calculated as being the best for translation
6299 * purposes is used for the request. This is because we don't have the ability
6300 * to signal to the initiator which one of their codecs that was offered is
6301 * the one that was selected, particularly in a chain of Local channels.
6302 */
6304 if (!joint_cap) {
6305 ao2_cleanup(tmp_converted_cap);
6306 return NULL;
6307 }
6310 if (best_audio_fmt) { /* text+video call? then, this is NULL */
6311 ast_format_cap_append(joint_cap, best_audio_fmt, 0);
6312 }
6313 ao2_cleanup(tmp_converted_cap);
6314
6315 c = chan->tech->requester(type, joint_cap, assignedids, requestor, addr, cause);
6316 ao2_ref(joint_cap, -1);
6317 }
6318
6319 if (!c) {
6320 return NULL;
6321 }
6322
6323 if (requestor) {
6324 ast_callid callid;
6325
6326 ast_channel_lock_both(c, (struct ast_channel *) requestor);
6327
6328 /* Set the newly created channel's callid to the same as the requestor. */
6329 callid = ast_channel_callid(requestor);
6330 if (callid) {
6331 ast_channel_callid_set(c, callid);
6332 }
6333
6335 ast_channel_unlock((struct ast_channel *) requestor);
6336 }
6337
6338 if (set_security_requirements(requestor, c)) {
6339 ast_log(LOG_WARNING, "Setting security requirements failed\n");
6340 ast_hangup(c);
6342 return NULL;
6343 }
6344
6345 /* no need to generate a Newchannel event here; it is done in the channel_alloc call */
6346 return c;
6347}
6348
6349struct 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)
6350{
6351 return request_channel(type, request_cap, NULL, assignedids, requestor, addr, cause);
6352}
6353
6354struct 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)
6355{
6356 return request_channel(type, NULL, topology, assignedids, requestor, addr, cause);
6357}
6358
6359/*!
6360 * \internal
6361 * \brief Setup new channel accountcodes from the requestor channel after ast_request().
6362 * \since 13.0.0
6363 *
6364 * \param chan New channel to get accountcodes setup.
6365 * \param requestor Requesting channel to get accountcodes from.
6366 * \param relationship What the new channel was created for.
6367 * \param precious TRUE if pre-existing accountcodes on chan will not be overwritten.
6368 *
6369 * \pre The chan and requestor channels are already locked.
6370 */
6371static void channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship, int precious)
6372{
6373 /*
6374 * The primary reason for the existence of this function is
6375 * so local channels can propagate accountcodes to the ;2
6376 * channel before ast_call().
6377 *
6378 * The secondary reason is to propagate the CHANNEL(peeraccount)
6379 * value set before Dial, FollowMe, and Queue while maintaining
6380 * the historic straight across accountcode propagation as a
6381 * fallback.
6382 */
6383 switch (relationship) {
6385 /* Crossover the requestor's accountcode and peeraccount */
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_peeraccount(requestor))) {
6392 /*
6393 * Set it to the requestor's peeraccount. This allows the
6394 * dialplan to indicate the accountcode to use when dialing
6395 * by setting CHANNEL(peeraccount).
6396 */
6397 ast_channel_accountcode_set(chan, ast_channel_peeraccount(requestor));
6398 } else if (!precious
6399 && !ast_strlen_zero(ast_channel_accountcode(requestor))) {
6400 /*
6401 * Fallback to the historic propagation and set it to the
6402 * requestor's accountcode.
6403 */
6404 ast_channel_accountcode_set(chan, ast_channel_accountcode(requestor));
6405 }
6406 }
6407 if (!ast_strlen_zero(ast_channel_accountcode(requestor))) {
6408 ast_channel_peeraccount_set(chan, ast_channel_accountcode(requestor));
6409 }
6410 break;
6412 /* Pass the requestor's accountcode and peeraccount straight. */
6413 if (!precious || ast_strlen_zero(ast_channel_accountcode(chan))) {
6414 /*
6415 * The newly created channel does not have an accountcode
6416 * or we don't care.
6417 */
6418 if (!ast_strlen_zero(ast_channel_accountcode(requestor))) {
6419 ast_channel_accountcode_set(chan, ast_channel_accountcode(requestor));
6420 }
6421 }
6422 if (!ast_strlen_zero(ast_channel_peeraccount(requestor))) {
6423 ast_channel_peeraccount_set(chan, ast_channel_peeraccount(requestor));
6424 }
6425 break;
6426 }
6427}
6428
6429void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
6430{
6431 channel_req_accountcodes(chan, requestor, relationship, 0);
6432}
6433
6434void ast_channel_req_accountcodes_precious(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
6435{
6436 channel_req_accountcodes(chan, requestor, relationship, 1);
6437}
6438
6439int ast_pre_call(struct ast_channel *chan, const char *sub_args)
6440{
6441 int (*pre_call)(struct ast_channel *chan, const char *sub_args);
6442
6443 ast_channel_lock(chan);
6444 pre_call = ast_channel_tech(chan)->pre_call;
6445 if (pre_call) {
6446 int res;
6447
6448 res = pre_call(chan, sub_args);
6449 ast_channel_unlock(chan);
6450 return res;
6451 }
6452 ast_channel_unlock(chan);
6453 return ast_app_exec_sub(NULL, chan, sub_args, 0);
6454}
6455
6456int ast_call(struct ast_channel *chan, const char *addr, int timeout)
6457{
6458 /* Place an outgoing call, but don't wait any longer than timeout ms before returning.
6459 If the remote end does not answer within the timeout, then do NOT hang up, but
6460 return anyway. */
6461 int res = -1;
6462 /* Stop if we're a zombie or need a soft hangup */
6463 ast_channel_lock(chan);
6465 if (ast_channel_tech(chan)->call)
6466 res = ast_channel_tech(chan)->call(chan, addr, timeout);
6468 }
6469 ast_channel_unlock(chan);
6470 return res;
6471}
6472
6473/*!
6474 \brief Transfer a call to dest, if the channel supports transfer
6475
6476 Called by:
6477 \arg app_transfer
6478 \arg the manager interface
6479*/
6480int ast_transfer(struct ast_channel *chan, char *dest)
6481{
6482 int protocol;
6483 return ast_transfer_protocol(chan, dest, &protocol);
6484}
6485
6486/*!
6487 \brief Transfer a call to dest, if the channel supports transfer
6488
6489 Called by:
6490 \arg app_transfer
6491 \arg the manager interface
6492*/
6493int ast_transfer_protocol(struct ast_channel *chan, char *dest, int *protocol)
6494{
6495 int res = -1;
6496
6497 if (protocol) {
6498 *protocol = 0;
6499 }
6500
6501 /* Stop if we're a zombie or need a soft hangup */
6502 ast_channel_lock(chan);
6504 if (ast_channel_tech(chan)->transfer) {
6505 res = ast_channel_tech(chan)->transfer(chan, dest);
6506 if (!res)
6507 res = 1;
6508 } else
6509 res = 0;
6510 }
6511 ast_channel_unlock(chan);
6512
6513 if (res <= 0) {
6514 return res;
6515 }
6516
6517 for (;;) {
6518 struct ast_frame *fr;
6519
6520 res = ast_waitfor(chan, -1);
6521
6522 if (res < 0 || !(fr = ast_read(chan))) {
6523 res = -1;
6524 break;
6525 }
6526
6529
6530 if (*message == AST_TRANSFER_SUCCESS) {
6531 res = 1;
6532 } else {
6533 res = -1;
6534 /* Message can contain a protocol specific code
6535 AST_TRANSFER_SUCCESS indicates success
6536 Else, failure. Protocol will be set to the failure reason.
6537 SIP example, 0 is success, else error code 3xx-6xx */
6538 if (protocol) {
6539 *protocol = *message;
6540 }
6541 }
6542
6543 ast_frfree(fr);
6544 break;
6545 }
6546
6547 ast_frfree(fr);
6548 }
6549
6550 return res;
6551}
6552
6553int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders)
6554{
6555 return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1);
6556}
6557
6558int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders, int audiofd, int ctrlfd)
6559{
6560 int pos = 0; /* index in the buffer where we accumulate digits */
6561 int to = ftimeout;
6562
6563 struct ast_silence_generator *silgen = NULL;
6564
6565 /* Stop if we're a zombie or need a soft hangup */
6567 return -1;
6568 if (!len)
6569 return -1;
6570 for (;;) {
6571 int d;
6572 if (ast_channel_stream(c)) {
6573 d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd);
6575 if (!silgen && ast_opt_transmit_silence)
6577 usleep(1000);
6578 if (!d)
6579 d = ast_waitfordigit_full(c, to, NULL, audiofd, ctrlfd);
6580 } else {
6581 if (!silgen && ast_opt_transmit_silence)
6583 d = ast_waitfordigit_full(c, to, NULL, audiofd, ctrlfd);
6584 }
6585 if (d < 0) {
6587 return AST_GETDATA_FAILED;
6588 }
6589 if (d == 0) {
6590 s[pos] = '\0';
6592 return AST_GETDATA_TIMEOUT;
6593 }
6594 if (d == 1) {
6595 s[pos] = '\0';
6598 }
6599 if (strchr(enders, d) && (pos == 0)) {
6600 s[pos] = '\0';
6603 }
6604 if (!strchr(enders, d)) {
6605 s[pos++] = d;
6606 }
6607 if (strchr(enders, d) || (pos >= len)) {
6608 s[pos] = '\0';
6610 return AST_GETDATA_COMPLETE;
6611 }
6612 to = timeout;
6613 }
6614 /* Never reached */
6615 return 0;
6616}
6617
6619{
6620 return (ast_channel_tech(chan)->send_html) ? 1 : 0;
6621}
6622
6623int ast_channel_sendhtml(struct ast_channel *chan, int subclass, const char *data, int datalen)
6624{
6625 if (ast_channel_tech(chan)->send_html)
6626 return ast_channel_tech(chan)->send_html(chan, subclass, data, datalen);
6627 return -1;
6628}
6629
6630int ast_channel_sendurl(struct ast_channel *chan, const char *url)
6631{
6632 return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1);
6633}
6634
6635/*! \brief Set up translation from one channel to another */
6637{
6638 struct ast_format_cap *src_cap;
6639 struct ast_format_cap *dst_cap;
6640 RAII_VAR(struct ast_format *, best_src_fmt, NULL, ao2_cleanup);
6641 RAII_VAR(struct ast_format *, best_dst_fmt, NULL, ao2_cleanup);
6642 int no_path;
6643
6644 /*
6645 * We cannot short circuit this code because it is possible to ask
6646 * to make compatible two channels that are "compatible" because
6647 * they already have translation paths setup but together make for
6648 * a sub-optimal path. e.g., The From channel has g722 -> ulaw
6649 * and the To channel has ulaw -> g722. They are "compatible" but
6650 * together the translations are unnecessary and the audio loses
6651 * fidelity in the process.
6652 */
6653
6654 ast_channel_lock_both(from, to);
6655
6656 src_cap = ast_channel_nativeformats(from); /* shallow copy, do not destroy */
6657 dst_cap = ast_channel_nativeformats(to); /* shallow copy, do not destroy */
6658
6659 /* If there's no audio in this call, don't bother with trying to find a translation path */
6663 ast_channel_unlock(from);
6664 return 0;
6665 }
6666
6667 no_path = ast_translator_best_choice(dst_cap, src_cap, &best_dst_fmt, &best_src_fmt);
6668
6670 ast_channel_unlock(from);
6671
6672 if (no_path) {
6673 ast_log(LOG_WARNING, "No path to translate from %s to %s\n",
6675 return -1;
6676 }
6677
6678 /* if the best path is not 'pass through', then
6679 * transcoding is needed; if desired, force transcode path
6680 * to use SLINEAR between channels, but only if there is
6681 * no direct conversion available. If generic PLC is
6682 * desired, then transcoding via SLINEAR is a requirement
6683 * even if the formats are the same.
6684 */
6686 || (ast_format_cmp(best_dst_fmt, best_src_fmt) == AST_FORMAT_CMP_NOT_EQUAL
6688
6689 int use_slin = (ast_format_cache_is_slinear(best_src_fmt)
6690 || ast_format_cache_is_slinear(best_dst_fmt))
6692
6693 if (use_slin || ast_translate_path_steps(best_dst_fmt, best_src_fmt) != 1) {
6694 int best_sample_rate = (ast_format_get_sample_rate(best_src_fmt) > ast_format_get_sample_rate(best_dst_fmt)) ?
6695 ast_format_get_sample_rate(best_src_fmt) : ast_format_get_sample_rate(best_dst_fmt);
6696
6697 /* pick the best signed linear format based upon what preserves the sample rate the best. */
6698 ao2_replace(best_src_fmt, ast_format_cache_get_slin_by_rate(best_sample_rate));
6699 }
6700 }
6701
6702 if (ast_set_read_format(from, best_src_fmt)) {
6703 ast_log(LOG_WARNING, "Unable to set read format on channel %s to %s\n",
6704 ast_channel_name(from), ast_format_get_name(best_src_fmt));
6705 return -1;
6706 }
6707 if (ast_set_write_format(to, best_src_fmt)) {
6708 ast_log(LOG_WARNING, "Unable to set write format on channel %s to %s\n",
6709 ast_channel_name(to), ast_format_get_name(best_src_fmt));
6710 return -1;
6711 }
6712 return 0;
6713}
6714
6716{
6717 /*
6718 * Set up translation from the peer to the chan first in case we
6719 * need to hear any in-band tones and the other direction fails.
6720 */
6721 if (ast_channel_make_compatible_helper(peer, chan)) {
6722 return -1;
6723 }
6724
6725 /* Set up translation from the chan to the peer */
6726 if (ast_channel_make_compatible_helper(chan, peer)) {
6727 return -1;
6728 }
6729
6730 return 0;
6731}
6732
6733/*! \brief this function simply changes the name of the channel and issues a manager_event
6734 * with out unlinking and linking the channel from the ao2_container. This should
6735 * only be used when the channel has already been unlinked from the ao2_container.
6736 */
6737static void __ast_change_name_nolink(struct ast_channel *chan, const char *newname)
6738{
6739 /*** DOCUMENTATION
6740 <managerEvent language="en_US" name="Rename">
6741 <managerEventInstance class="EVENT_FLAG_CALL">
6742 <since>
6743 <version>16.24.0</version>
6744 <version>18.10.0</version>
6745 <version>19.2.0</version>
6746 </since>
6747 <synopsis>Raised when the name of a channel is changed.</synopsis>
6748 </managerEventInstance>
6749 </managerEvent>
6750 ***/
6751 ast_manager_event(chan, EVENT_FLAG_CALL, "Rename",
6752 "Channel: %s\r\n"
6753 "Newname: %s\r\n"
6754 "Uniqueid: %s\r\n",
6755 ast_channel_name(chan), newname, ast_channel_uniqueid(chan));
6756 ast_channel_name_set(chan, newname);
6757}
6758
6759void ast_change_name(struct ast_channel *chan, const char *newname)
6760{
6761 /* We must re-link, as the hash value will change here. */
6763 ast_channel_lock(chan);
6765 __ast_change_name_nolink(chan, newname);
6767 ast_channel_unlock(chan);
6769}
6770
6771void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
6772{
6773 struct ast_var_t *current;
6774 struct ast_var_t *newvar;
6775 const char *varname;
6776 int vartype;
6777
6779 varname = ast_var_full_name(current);
6780 if (!varname) {
6781 continue;
6782 }
6783
6784 vartype = 0;
6785 if (varname[0] == '_') {
6786 vartype = 1;
6787 if (varname[1] == '_') {
6788 vartype = 2;
6789 }
6790 }
6791
6792 switch (vartype) {
6793 case 1:
6794 newvar = ast_var_assign(&varname[1], ast_var_value(current));
6795 break;
6796 case 2:
6797 newvar = ast_var_assign(varname, ast_var_value(current));
6798 break;
6799 default:
6800 continue;
6801 }
6802 if (newvar) {
6803 ast_debug(1, "Inheriting variable %s from %s to %s.\n",
6804 ast_var_full_name(newvar), ast_channel_name(parent),
6805 ast_channel_name(child));
6808 ast_var_value(newvar));
6809 }
6810 }
6811}
6812
6813/*!
6814 \brief Clone channel variables from 'clone' channel into 'original' channel
6815
6816 All variables except those related to app_groupcount are cloned.
6817 Variables are actually _removed_ from 'clone' channel, presumably
6818 because it will subsequently be destroyed.
6819
6820 \note Assumes locks will be in place on both channels when called.
6821*/
6822static void clone_variables(struct ast_channel *original, struct ast_channel *clonechan)
6823{
6824 struct ast_var_t *current, *newvar;
6825 /* Append variables from clone channel into original channel */
6826 /* XXX Is this always correct? We have to in order to keep MACROS working XXX */
6828
6829 /* then, dup the varshead list into the clone */
6830
6832 newvar = ast_var_assign(current->name, current->value);
6833 if (newvar)
6835 }
6836}
6837
6838
6839void ast_channel_name_to_dial_string(char *channel_name)
6840{
6841 char *dash;
6842
6843 /* Truncate after the dash */
6844 dash = strrchr(channel_name, '-');
6845 if (dash) {
6846 *dash = '\0';
6847 }
6848}
6849
6850/*!
6851 * \brief Masquerade a channel
6852 *
6853 * \note Assumes _NO_ channels and _NO_ channel pvt's are locked. If a channel is locked while calling
6854 * this function, it invalidates our channel container locking order. All channels
6855 * must be unlocked before it is permissible to lock the channels' ao2 container.
6856 */
6857static void channel_do_masquerade(struct ast_channel *original, struct ast_channel *clonechan)
6858{
6859 int x;
6860 int origstate;
6861 unsigned int orig_disablestatecache;
6862 unsigned int clone_disablestatecache;
6863 int visible_indication;
6864 int clone_hold_state;
6865 int moh_is_playing;
6866 struct ast_frame *current;
6867 const struct ast_channel_tech *t;
6868 void *t_pvt;
6869 union {
6871 struct ast_party_dialed dialed;
6872 struct ast_party_caller caller;
6874 struct ast_party_redirecting redirecting;
6875 } exchange;
6876 struct ast_channel *bridged;
6877 struct ast_format *rformat;
6878 struct ast_format *wformat;
6879 struct ast_format *tmp_format;
6880 struct ast_format_cap *tmp_cap;
6881 char tmp_name[AST_CHANNEL_NAME];
6882 char clone_sending_dtmf_digit;
6883 struct timeval clone_sending_dtmf_tv;
6884
6885 ast_debug(3, "Masquerading %s(%u) into the structure of %s(%u)\n",
6886 ast_channel_name(clonechan), ast_channel_state(clonechan),
6887 ast_channel_name(original), ast_channel_state(original));
6888 /* XXX This operation is a bit odd. We're essentially putting the guts of
6889 * the clone channel into the original channel. Start by killing off the
6890 * original channel's backend. While the features are nice, which is the
6891 * reason we're keeping it, it's still awesomely weird. XXX */
6892
6893 /* Indicate to each channel that a masquerade is about to begin. */
6894 x = 1;
6895 ast_indicate_data(original, AST_CONTROL_MASQUERADE_NOTIFY, &x, sizeof(x));
6896 ast_indicate_data(clonechan, AST_CONTROL_MASQUERADE_NOTIFY, &x, sizeof(x));
6897
6898 /*
6899 * The container lock is necessary for proper locking order
6900 * because the channels must be unlinked to change their
6901 * names.
6902 *
6903 * The original and clonechan locks must be held while the
6904 * channel contents are shuffled around for the masquerade.
6905 *
6906 * The masq and masqr pointers need to be left alone until the masquerade
6907 * has restabilized the channels to hold off ast_hangup() and until
6908 * AST_FLAG_ZOMBIE can be set on the clonechan.
6909 */
6911
6912 /* Bump the refs to ensure that they won't disappear on us. */
6913 ast_channel_ref(original);
6914 ast_channel_ref(clonechan);
6915
6916 /*
6917 * Since channel name and unique id will change, and both could be keys
6918 * in the channel storage backend, we need to remove them from the backend.
6919 * We'll add them back in after the changes are compete.
6920 */
6923
6925
6926 moh_is_playing = ast_test_flag(ast_channel_flags(original), AST_FLAG_MOH);
6927 if (moh_is_playing) {
6928 /* Stop MOH on the old original channel. */
6929 ast_moh_stop(original);
6930 }
6931
6932 /*
6933 * Stop any visible indication on the original channel so we can
6934 * transfer it to the clonechan taking the original's place.
6935 */
6936 ast_channel_lock(original);
6937 visible_indication = ast_channel_visible_indication(original);
6938 ast_channel_unlock(original);
6939 ast_indicate(original, -1);
6940
6941 /* Start the masquerade channel contents rearrangement. */
6942 ast_channel_lock_both(original, clonechan);
6943
6944 ast_debug(1, "Actually Masquerading %s(%u) into the structure of %s(%u)\n",
6945 ast_channel_name(clonechan), ast_channel_state(clonechan),
6946 ast_channel_name(original), ast_channel_state(original));
6947
6948 /* When all is said and done force new snapshot segments so they are
6949 * up to date.
6950 */
6953
6954 /*
6955 * Remember the original read/write formats. We turn off any
6956 * translation on either one
6957 */
6958 rformat = ao2_bump(ast_channel_readformat(original));
6959 wformat = ao2_bump(ast_channel_writeformat(original));
6960 free_translation(clonechan);
6961 free_translation(original);
6962
6963 clone_hold_state = ast_channel_hold_state(clonechan);
6964
6965 /* Save the current DTMF digit being sent if any. */
6966 clone_sending_dtmf_digit = ast_channel_sending_dtmf_digit(clonechan);
6967 clone_sending_dtmf_tv = ast_channel_sending_dtmf_tv(clonechan);
6968
6969 /* Swap uniqueid's of the channels. This needs to happen before channel renames,
6970 * so rename events get the proper id's.
6971 */
6973
6974 /* Make sure the Stasis topic on the channel is updated appropriately */
6975 ast_channel_internal_swap_topics(clonechan, original);
6976
6977 /* Swap endpoint forward so channel created with endpoint exchanges its state
6978 * with other channel for proper endpoint cleanup.
6979 */
6980 ast_channel_internal_swap_endpoint_forward(clonechan, original);
6981
6982 /* The old snapshots need to follow the channels so the snapshot update is correct */
6983 ast_channel_internal_swap_snapshots(clonechan, original);
6984
6985 /* Now we swap the endpoints if present */
6986 ast_channel_internal_swap_endpoints(clonechan, original);
6987
6988 /* Swap channel names. This uses ast_channel_name_set directly, so we
6989 * don't get any spurious rename events.
6990 */
6991 ast_copy_string(tmp_name, ast_channel_name(clonechan), sizeof(tmp_name));
6992 ast_channel_name_set(clonechan, ast_channel_name(original));
6993 ast_channel_name_set(original, tmp_name);
6994
6995 /* Swap the technologies */
6996 t = ast_channel_tech(original);
6997 ast_channel_tech_set(original, ast_channel_tech(clonechan));
6998 ast_channel_tech_set(clonechan, t);
6999
7000 t_pvt = ast_channel_tech_pvt(original);
7001 ast_channel_tech_pvt_set(original, ast_channel_tech_pvt(clonechan));
7002 ast_channel_tech_pvt_set(clonechan, t_pvt);
7003
7004 /* Swap the alertpipes */
7005 ast_channel_internal_alertpipe_swap(original, clonechan);
7006
7007 /*
7008 * Swap the readq's. The end result should be this:
7009 *
7010 * 1) All frames should be on the new (original) channel.
7011 * 2) Any frames that were already on the new channel before this
7012 * masquerade need to be at the end of the readq, after all of the
7013 * frames on the old (clone) channel.
7014 * 3) The alertpipe needs to get poked for every frame that was already
7015 * on the new channel, since we are now using the alert pipe from the
7016 * old (clone) channel.
7017 */
7018 {
7019 AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq;
7020
7021 AST_LIST_HEAD_INIT_NOLOCK(&tmp_readq);
7022 AST_LIST_APPEND_LIST(&tmp_readq, ast_channel_readq(original), frame_list);
7024
7025 while ((current = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) {
7027 if (ast_channel_alert_write(original)) {
7028 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
7029 }
7030 }
7031 }
7032
7033 /* Swap the raw formats */
7034 tmp_format = ao2_bump(ast_channel_rawreadformat(original));
7036 ast_channel_set_rawreadformat(clonechan, tmp_format);
7037 ao2_cleanup(tmp_format);
7038
7039 tmp_format = ao2_bump(ast_channel_rawwriteformat(original));
7041 ast_channel_set_rawwriteformat(clonechan, tmp_format);
7042 ao2_cleanup(tmp_format);
7043
7045
7046 /* And of course, so does our current state. Note we need not
7047 call ast_setstate since the event manager doesn't really consider
7048 these separate. We do this early so that the clone has the proper
7049 state of the original channel. */
7050 origstate = ast_channel_state(original);
7051 ast_channel_state_set(original, ast_channel_state(clonechan));
7052 ast_channel_state_set(clonechan, origstate);
7053
7054 /* And the swap the cachable state too. Otherwise we'd start caching
7055 * Local channels and ignoring real ones. */
7056 orig_disablestatecache = ast_test_flag(ast_channel_flags(original), AST_FLAG_DISABLE_DEVSTATE_CACHE);
7057 clone_disablestatecache = ast_test_flag(ast_channel_flags(clonechan), AST_FLAG_DISABLE_DEVSTATE_CACHE);
7058 if (orig_disablestatecache != clone_disablestatecache) {
7059 if (orig_disablestatecache) {
7062 } else {
7065 }
7066 }
7067
7068 /* Keep the same language. */
7069 ast_channel_language_set(original, ast_channel_language(clonechan));
7070
7071 /* Keep the same parkinglot. */
7072 ast_channel_parkinglot_set(original, ast_channel_parkinglot(clonechan));
7073
7074 /* Clear all existing file descriptors */
7076
7077 /* Copy all file descriptors present on clonechan to original */
7078 for (x = 0; x < ast_channel_fd_count(clonechan); x++) {
7079 ast_channel_set_fd(original, x, ast_channel_fd(clonechan, x));
7080 }
7081
7082 ast_app_group_update(clonechan, original);
7083
7084 /* Swap hangup handlers. */
7085 exchange.handlers = *ast_channel_hangup_handlers(original);
7087 *ast_channel_hangup_handlers(clonechan) = exchange.handlers;
7088
7089 /* Call fixup handlers for the clone chan */
7090 if (AST_LIST_FIRST(ast_channel_datastores(clonechan))) {
7091 struct ast_datastore *ds;
7092 /* We use a safe traversal here because some fixup routines actually
7093 * remove the datastore from the list and free them.
7094 */
7096 if (ds->info->chan_fixup) {
7097 ds->info->chan_fixup(ds->data, clonechan, original);
7098 }
7099 }
7101 }
7102
7103 /* Call breakdown handlers for the original chan */
7104 if (AST_LIST_FIRST(ast_channel_datastores(original))) {
7105 struct ast_datastore *ds;
7106 /* We use a safe traversal here because some breakdown routines may
7107 * remove the datastore from the list and free them.
7108 */
7110 if (ds->info->chan_breakdown) {
7111 ds->info->chan_breakdown(ds->data, clonechan, original);
7112 }
7113 }
7115 }
7116
7117 /* Move data stores over */
7118 if (AST_LIST_FIRST(ast_channel_datastores(clonechan))) {
7120 }
7121
7122 /* Move framehooks over */
7123 ast_framehook_list_fixup(clonechan, original);
7124
7125 /* Move audiohooks over */
7126 ast_audiohook_move_all(clonechan, original);
7127
7128 ast_autochan_new_channel(clonechan, original);
7129
7130 clone_variables(original, clonechan);
7131 /* Presence of ADSI capable CPE follows clone */
7132 ast_channel_adsicpe_set(original, ast_channel_adsicpe(clonechan));
7133 /* Bridge remains the same */
7134 /* CDR fields remain the same */
7135 /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */
7136 /* Application and data remain the same */
7137 /* Clone exception becomes real one, as with fdno */
7139 ast_channel_fdno_set(original, ast_channel_fdno(clonechan));
7140 /* Schedule context remains the same */
7141 /* Stream stuff stays the same */
7142 /* Keep the original state. The fixup code will need to work with it most likely */
7143
7144 /*
7145 * Just swap the whole structures, nevermind the allocations,
7146 * they'll work themselves out.
7147 */
7148 exchange.dialed = *ast_channel_dialed(original);
7149 ast_channel_dialed_set(original, ast_channel_dialed(clonechan));
7150 ast_channel_dialed_set(clonechan, &exchange.dialed);
7151
7152 /* Reset any earlier private caller id representations */
7153 ast_party_id_reset(&ast_channel_caller(original)->priv);
7154 ast_party_id_reset(&ast_channel_caller(clonechan)->priv);
7155
7156 exchange.caller = *ast_channel_caller(original);
7157 ast_channel_caller_set(original, ast_channel_caller(clonechan));
7158 ast_channel_caller_set(clonechan, &exchange.caller);
7159
7160 /* Reset any earlier private connected id representations */
7161 ast_party_id_reset(&ast_channel_connected(original)->priv);
7162 ast_party_id_reset(&ast_channel_connected(clonechan)->priv);
7163
7164 exchange.connected = *ast_channel_connected(original);
7166 ast_channel_connected_set(clonechan, &exchange.connected);
7167
7168 /* Reset any earlier private redirecting orig, from or to representations */
7169 ast_party_id_reset(&ast_channel_redirecting(original)->priv_orig);
7170 ast_party_id_reset(&ast_channel_redirecting(clonechan)->priv_orig);
7171 ast_party_id_reset(&ast_channel_redirecting(original)->priv_from);
7172 ast_party_id_reset(&ast_channel_redirecting(clonechan)->priv_from);
7173 ast_party_id_reset(&ast_channel_redirecting(original)->priv_to);
7174 ast_party_id_reset(&ast_channel_redirecting(clonechan)->priv_to);
7175
7176 exchange.redirecting = *ast_channel_redirecting(original);
7178 ast_channel_redirecting_set(clonechan, &exchange.redirecting);
7179
7181
7182 /* Restore original timing file descriptor */
7184
7185 /* Our native formats are different now */
7187 if (tmp_cap) {
7189 ast_channel_nativeformats_set(original, tmp_cap);
7190 ao2_ref(tmp_cap, -1);
7191 }
7192
7193 /* Context, extension, priority, app data, jump table, remain the same */
7194 /* pvt switches. pbx stays the same, as does next */
7195
7196 /* Set the write format */
7197 ast_set_write_format(original, wformat);
7198
7199 /* Set the read format */
7200 ast_set_read_format(original, rformat);
7201
7202 /* Copy the music class */
7203 ast_channel_musicclass_set(original, ast_channel_musicclass(clonechan));
7204
7205 /* copy over accuntcode and set peeraccount across the bridge */
7206 ast_channel_accountcode_set(original, S_OR(ast_channel_accountcode(clonechan), ""));
7207
7208 /* copy over userfield */
7209 ast_channel_userfield_set(original, ast_channel_userfield(clonechan));
7210
7211 ast_debug(1, "Putting channel %s in %s/%s formats\n", ast_channel_name(original),
7212 ast_format_get_name(wformat), ast_format_get_name(rformat));
7213
7214 /* Fixup the original clonechan's physical side */
7215 if (ast_channel_tech(original)->fixup && ast_channel_tech(original)->fixup(clonechan, original)) {
7216 ast_log(LOG_WARNING, "Channel type '%s' could not fixup channel %s, strange things may happen. (clonechan)\n",
7217 ast_channel_tech(original)->type, ast_channel_name(original));
7218 }
7219
7220 /* Fixup the original original's physical side */
7221 if (ast_channel_tech(clonechan)->fixup && ast_channel_tech(clonechan)->fixup(original, clonechan)) {
7222 ast_log(LOG_WARNING, "Channel type '%s' could not fixup channel %s, strange things may happen. (original)\n",
7223 ast_channel_tech(clonechan)->type, ast_channel_name(clonechan));
7224 }
7225
7226 ast_channel_internal_swap_stream_topology(original, clonechan);
7227
7228 /*
7229 * Now, at this point, the "clone" channel is totally F'd up.
7230 * We mark it as a zombie so nothing tries to touch it.
7231 *
7232 * This must be done before we unlock clonechan to prevent
7233 * setting up another masquerade on the clonechan.
7234 */
7236 ast_queue_frame(clonechan, &ast_null_frame);
7237
7238 ast_channel_unlock(original);
7239 ast_channel_unlock(clonechan);
7240
7241 /*
7242 * Indicate to each channel that a masquerade is complete.
7243 *
7244 * We can still do this to clonechan even though it is a
7245 * zombie because ast_indicate_data() will explicitly pass
7246 * this control and ast_hangup() is held off until the
7247 * ast_channel_masq() and ast_channel_masqr() pointers are
7248 * cleared.
7249 */
7250 x = 0;
7251 ast_indicate_data(original, AST_CONTROL_MASQUERADE_NOTIFY, &x, sizeof(x));
7252 ast_indicate_data(clonechan, AST_CONTROL_MASQUERADE_NOTIFY, &x, sizeof(x));
7253
7255
7256 if (clone_hold_state == AST_CONTROL_HOLD) {
7257 ast_debug(1, "Channel %s simulating UNHOLD for masquerade.\n",
7258 ast_channel_name(original));
7260 }
7261 if (clone_sending_dtmf_digit) {
7262 /*
7263 * The clonechan was sending a DTMF digit that was not completed
7264 * before the masquerade.
7265 */
7266 ast_channel_end_dtmf(original, clone_sending_dtmf_digit, clone_sending_dtmf_tv,
7267 "masquerade");
7268 }
7269
7270 /*
7271 * If an indication is currently playing, maintain it on the
7272 * channel that is taking the place of original.
7273 *
7274 * This is needed because the masquerade is swapping out the
7275 * internals of the channel, and the new channel private data
7276 * needs to be made aware of the current visible indication
7277 * (RINGING, CONGESTION, etc.)
7278 */
7279 if (visible_indication) {
7280 if (visible_indication == AST_CONTROL_HOLD) {
7281 const char *latest_musicclass;
7282 int len;
7283
7284 ast_channel_lock(original);
7285 latest_musicclass = ast_strdupa(ast_channel_latest_musicclass(original));
7286 ast_channel_unlock(original);
7287 if (ast_strlen_zero(latest_musicclass)) {
7288 latest_musicclass = NULL;
7289 len = 0;
7290 } else {
7291 len = strlen(latest_musicclass) + 1;
7292 }
7293 ast_indicate_data(original, visible_indication, latest_musicclass, len);
7294 } else {
7295 ast_indicate(original, visible_indication);
7296 }
7297 }
7298
7299 /*
7300 * If MOH was playing on the original channel then it needs to be
7301 * maintained on the channel that is replacing it.
7302 */
7303 if (moh_is_playing) {
7304 /* Start MOH on the new original channel. */
7305 ast_moh_start(original, NULL, NULL);
7306 }
7307
7308 ast_channel_lock(original);
7309
7310 /* Signal any blocker */
7312 pthread_kill(ast_channel_blocker(original), SIGURG);
7313 }
7314
7315 ast_debug(1, "Done Masquerading %s (%u)\n", ast_channel_name(original), ast_channel_state(original));
7316 ast_channel_unlock(original);
7317
7318 if ((bridged = ast_channel_bridge_peer(original))) {
7320 ast_channel_unref(bridged);
7321 }
7323
7324 /* Now that the operation is complete, we can clear the masq
7325 * and masqr fields of both channels.
7326 */
7327 ast_channel_lock_both(original, clonechan);
7328 ast_channel_masq_set(original, NULL);
7329 ast_channel_masqr_set(clonechan, NULL);
7330 ast_channel_unlock(original);
7331 ast_channel_unlock(clonechan);
7332
7334 CHANNELSTORAGE_API(current_channel_storage_instance, insert, clonechan, 0, 0);
7337
7338 /* Release our held safety references. */
7339 ast_channel_unref(original);
7340 ast_channel_unref(clonechan);
7341
7342 ao2_cleanup(rformat);
7343 ao2_cleanup(wformat);
7344}
7345
7346void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
7347{
7348 ast_channel_lock(chan);
7349
7350 if (cid_num) {
7351 ast_channel_caller(chan)->id.number.valid = 1;
7352 ast_free(ast_channel_caller(chan)->id.number.str);
7353 ast_channel_caller(chan)->id.number.str = ast_strdup(cid_num);
7354 }
7355 if (cid_name) {
7356 ast_channel_caller(chan)->id.name.valid = 1;
7357 ast_free(ast_channel_caller(chan)->id.name.str);
7358 ast_channel_caller(chan)->id.name.str = ast_strdup(cid_name);
7359 }
7360 if (cid_ani) {
7362 ast_free(ast_channel_caller(chan)->ani.number.str);
7363 ast_channel_caller(chan)->ani.number.str = ast_strdup(cid_ani);
7364 }
7365
7367
7368 ast_channel_unlock(chan);
7369}
7370
7371void ast_channel_set_caller(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
7372{
7373 if (ast_channel_caller(chan) == caller) {
7374 /* Don't set to self */
7375 return;
7376 }
7377
7378 ast_channel_lock(chan);
7381 ast_channel_unlock(chan);
7382}
7383
7384void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
7385{
7386 if (ast_channel_caller(chan) == caller) {
7387 /* Don't set to self */
7388 return;
7389 }
7390
7391 ast_channel_lock(chan);
7395 ast_channel_unlock(chan);
7396}
7397
7399{
7400 int oldstate = ast_channel_state(chan);
7401 char name[AST_CHANNEL_NAME], *dashptr;
7402
7403 if (oldstate == state)
7404 return 0;
7405
7406 ast_copy_string(name, ast_channel_name(chan), sizeof(name));
7407 if ((dashptr = strrchr(name, '-'))) {
7408 *dashptr = '\0';
7409 }
7410
7412
7414
7415 /* We have to pass AST_DEVICE_UNKNOWN here because it is entirely possible that the channel driver
7416 * for this channel is using the callback method for device state. If we pass in an actual state here
7417 * we override what they are saying the state is and things go amuck. */
7419
7420 return 0;
7421}
7422
7423/*! \brief Bridge two channels together (early) */
7425{
7426 /* Make sure we can early bridge, if not error out */
7427 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)))
7428 return -1;
7429
7430 return ast_channel_tech(c0)->early_bridge(c0, c1);
7431}
7432
7433/*! \brief Sets an option on a channel */
7434int ast_channel_setoption(struct ast_channel *chan, int option, void *data, int datalen, int block)
7435{
7436 int res;
7437
7438 ast_channel_lock(chan);
7439 if (!ast_channel_tech(chan)->setoption) {
7440 errno = ENOSYS;
7441 ast_channel_unlock(chan);
7442 return -1;
7443 }
7444
7445 if (block)
7446 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
7447
7448 res = ast_channel_tech(chan)->setoption(chan, option, data, datalen);
7449 ast_channel_unlock(chan);
7450
7451 return res;
7452}
7453
7454int ast_channel_queryoption(struct ast_channel *chan, int option, void *data, int *datalen, int block)
7455{
7456 int res;
7457
7458 ast_channel_lock(chan);
7459 if (!ast_channel_tech(chan)->queryoption) {
7460 errno = ENOSYS;
7461 ast_channel_unlock(chan);
7462 return -1;
7463 }
7464
7465 if (block)
7466 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
7467
7468 res = ast_channel_tech(chan)->queryoption(chan, option, data, datalen);
7469 ast_channel_unlock(chan);
7470
7471 return res;
7472}
7473
7478 int vol;
7479};
7480
7482 int fac1;
7483 int fac2;
7484 int v1_1;
7485 int v2_1;
7486 int v3_1;
7487 int v1_2;
7488 int v2_2;
7489 int v3_2;
7491 int pos;
7494 struct ast_frame f;
7496 short data[4000];
7497};
7498
7499static void tonepair_release(struct ast_channel *chan, void *params)
7500{
7501 struct tonepair_state *ts = params;
7502
7503 if (chan) {
7504 ast_set_write_format(chan, ts->origwfmt);
7505 }
7506 ao2_cleanup(ts->origwfmt);
7507 ast_free(ts);
7508}
7509
7510static void *tonepair_alloc(struct ast_channel *chan, void *params)
7511{
7512 struct tonepair_state *ts;
7513 struct tonepair_def *td = params;
7514
7515 if (!(ts = ast_calloc(1, sizeof(*ts)))) {
7516 return NULL;
7517 }
7518
7521 ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", ast_channel_name(chan));
7523 ts = NULL;
7524 } else {
7525 ts->fac1 = 2.0 * cos(2.0 * M_PI * (td->freq1 / 8000.0)) * 32768.0;
7526 ts->v1_1 = 0;
7527 ts->v2_1 = sin(-4.0 * M_PI * (td->freq1 / 8000.0)) * td->vol;
7528 ts->v3_1 = sin(-2.0 * M_PI * (td->freq1 / 8000.0)) * td->vol;
7529 ts->v2_1 = 0;
7530 ts->fac2 = 2.0 * cos(2.0 * M_PI * (td->freq2 / 8000.0)) * 32768.0;
7531 ts->v2_2 = sin(-4.0 * M_PI * (td->freq2 / 8000.0)) * td->vol;
7532 ts->v3_2 = sin(-2.0 * M_PI * (td->freq2 / 8000.0)) * td->vol;
7533 ts->duration = td->duration;
7534 ts->modulate = 0;
7535 }
7536 /* Let interrupts interrupt :) */
7538 return ts;
7539}
7540
7541static int tonepair_generator(struct ast_channel *chan, void *data, int len, int samples)
7542{
7543 struct tonepair_state *ts = data;
7544 int x;
7545
7546 /* we need to prepare a frame with 16 * timelen samples as we're
7547 * generating SLIN audio
7548 */
7549 len = samples * 2;
7550
7551 if (len > sizeof(ts->data) / 2 - 1) {
7552 ast_log(LOG_WARNING, "Can't generate that much data!\n");
7553 return -1;
7554 }
7555 memset(&ts->f, 0, sizeof(ts->f));
7556 for (x=0;x<len/2;x++) {
7557 ts->v1_1 = ts->v2_1;
7558 ts->v2_1 = ts->v3_1;
7559 ts->v3_1 = (ts->fac1 * ts->v2_1 >> 15) - ts->v1_1;
7560
7561 ts->v1_2 = ts->v2_2;
7562 ts->v2_2 = ts->v3_2;
7563 ts->v3_2 = (ts->fac2 * ts->v2_2 >> 15) - ts->v1_2;
7564 if (ts->modulate) {
7565 int p;
7566 p = ts->v3_2 - 32768;
7567 if (p < 0) p = -p;
7568 p = ((p * 9) / 10) + 1;
7569 ts->data[x] = (ts->v3_1 * p) >> 15;
7570 } else
7571 ts->data[x] = ts->v3_1 + ts->v3_2;
7572 }
7575 ts->f.datalen = len;
7576 ts->f.samples = samples;
7578 ts->f.data.ptr = ts->data;
7579 ast_write(chan, &ts->f);
7580 ts->pos += x;
7581 if (ts->duration > 0) {
7582 if (ts->pos >= ts->duration * 8)
7583 return -1;
7584 }
7585 return 0;
7586}
7587
7588static struct ast_generator tonepair = {
7590 .release = tonepair_release,
7591 .generate = tonepair_generator,
7592};
7593
7594int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
7595{
7596 struct tonepair_def d = { 0, };
7597
7598 d.freq1 = freq1;
7599 d.freq2 = freq2;
7600 d.duration = duration;
7601 d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */
7602 if (ast_activate_generator(chan, &tonepair, &d))
7603 return -1;
7604 return 0;
7605}
7606
7608{
7610}
7611
7612int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
7613{
7614 int res;
7615
7616 if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol)))
7617 return res;
7618
7619 /* Give us some wiggle room */
7620 while (ast_channel_generatordata(chan) && ast_waitfor(chan, 100) >= 0) {
7621 struct ast_frame *f = ast_read(chan);
7622 if (f)
7623 ast_frfree(f);
7624 else
7625 return -1;
7626 }
7627 return 0;
7628}
7629
7631{
7632 char *piece;
7633 char *c;
7634 int start=0, finish=0, x;
7635 ast_group_t group = 0;
7636
7637 if (ast_strlen_zero(s))
7638 return 0;
7639
7640 c = ast_strdupa(s);
7641
7642 while ((piece = strsep(&c, ","))) {
7643 if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) {
7644 /* Range */
7645 } else if (sscanf(piece, "%30d", &start)) {
7646 /* Just one */
7647 finish = start;
7648 } else {
7649 ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece);
7650 continue;
7651 }
7652 for (x = start; x <= finish; x++) {
7653 if ((x > 63) || (x < 0)) {
7654 ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x);
7655 } else
7656 group |= ((ast_group_t) 1 << x);
7657 }
7658 }
7659 return group;
7660}
7661
7662/*! \brief Named group member structure */
7664 /*! Pre-built hash of group member name. */
7665 unsigned int hash;
7666 /*! Group member name. (End allocation of name string.) */
7667 char name[1];
7668};
7669
7670/*! \brief Comparison function used for named group container */
7671static int namedgroup_cmp_cb(void *obj, void *arg, int flags)
7672{
7673 const struct namedgroup_member *an = obj;
7674 const struct namedgroup_member *bn = arg;
7675
7676 return strcmp(an->name, bn->name) ? 0 : CMP_MATCH | CMP_STOP;
7677}
7678
7679/*! \brief Hashing function used for named group container */
7680static int namedgroup_hash_cb(const void *obj, const int flags)
7681{
7682 const struct namedgroup_member *member = obj;
7683
7684 return member->hash;
7685}
7686
7687struct ast_namedgroups *ast_get_namedgroups(const char *s)
7688{
7689 struct ao2_container *namedgroups;
7690 char *piece;
7691 char *c;
7692
7693 if (!s) {
7694 return NULL;
7695 }
7696
7697 /*! \brief Remove leading and trailing whitespace */
7699 if (ast_strlen_zero(c)) {
7700 return NULL;
7701 }
7702
7705 if (!namedgroups) {
7706 return NULL;
7707 }
7708
7709 while ((piece = strsep(&c, ","))) {
7710 struct namedgroup_member *member;
7711 size_t len;
7712
7713 /* remove leading/trailing whitespace */
7714 piece = ast_strip(piece);
7715
7716 len = strlen(piece);
7717 if (!len) {
7718 continue;
7719 }
7720
7722 if (!member) {
7723 ao2_ref(namedgroups, -1);
7724 return NULL;
7725 }
7726 strcpy(member->name, piece);/* Safe */
7727 member->hash = ast_str_hash(member->name);
7728
7729 /* every group name may exist only once, delete duplicates */
7730 ao2_find(namedgroups, member, OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
7731 ao2_link(namedgroups, member);
7732 ao2_ref(member, -1);
7733 }
7734
7735 if (!ao2_container_count(namedgroups)) {
7736 /* There were no group names specified. */
7737 ao2_ref(namedgroups, -1);
7738 namedgroups = NULL;
7739 }
7740
7741 return (struct ast_namedgroups *) namedgroups;
7742}
7743
7744struct ast_namedgroups *ast_unref_namedgroups(struct ast_namedgroups *groups)
7745{
7747 return NULL;
7748}
7749
7750struct ast_namedgroups *ast_ref_namedgroups(struct ast_namedgroups *groups)
7751{
7752 if (groups) {
7753 ao2_ref(groups, 1);
7754 }
7755 return groups;
7756}
7757
7758static int (*ast_moh_start_ptr)(struct ast_channel *, const char *, const char *) = NULL;
7759static void (*ast_moh_stop_ptr)(struct ast_channel *) = NULL;
7760static void (*ast_moh_cleanup_ptr)(struct ast_channel *) = NULL;
7761
7762void ast_install_music_functions(int (*start_ptr)(struct ast_channel *, const char *, const char *),
7763 void (*stop_ptr)(struct ast_channel *),
7764 void (*cleanup_ptr)(struct ast_channel *))
7765{
7766 ast_moh_start_ptr = start_ptr;
7767 ast_moh_stop_ptr = stop_ptr;
7768 ast_moh_cleanup_ptr = cleanup_ptr;
7769}
7770
7777
7778int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
7779{
7781 return ast_moh_start_ptr(chan, mclass, interpclass);
7782
7783 ast_verb(3, "Music class %s requested but no musiconhold loaded.\n", mclass ? mclass : (interpclass ? interpclass : "default"));
7784
7785 return -1;
7786}
7787
7788void ast_moh_stop(struct ast_channel *chan)
7789{
7790 if (ast_moh_stop_ptr)
7791 ast_moh_stop_ptr(chan);
7792}
7793
7795{
7796 /* A nop but needed for API compat */
7797}
7798
7799static void moh_cleanup(struct ast_channel *chan)
7800{
7802 ast_moh_cleanup_ptr(chan);
7803}
7804
7805/*!
7806 * \brief List of channel variables to append to all channel-related events.
7807 */
7813
7815
7818
7819static void free_external_channelvars(struct external_vars *channelvars)
7820{
7822 AST_RWLIST_WRLOCK(channelvars);
7823 while ((var = AST_RWLIST_REMOVE_HEAD(channelvars, entry))) {
7824 ast_free(var);
7825 }
7826 AST_RWLIST_UNLOCK(channelvars);
7827}
7828
7829static int channel_has_external_vars(struct external_vars *channelvars)
7830{
7831 int vars_present;
7832
7833 AST_RWLIST_RDLOCK(channelvars);
7834 vars_present = !AST_LIST_EMPTY(channelvars);
7835 AST_RWLIST_UNLOCK(channelvars);
7836
7837 return vars_present;
7838}
7839
7844
7849
7850static void channel_set_external_vars(struct external_vars *channelvars, size_t varc, char **vars)
7851{
7852 size_t i;
7853
7854 free_external_channelvars(channelvars);
7855 AST_RWLIST_WRLOCK(channelvars);
7856 for (i = 0; i < varc; ++i) {
7857 const char *var = vars[i];
7858 struct manager_channel_variable *mcv;
7859 if (!(mcv = ast_calloc(1, sizeof(*mcv) + strlen(var) + 1))) {
7860 break;
7861 }
7862 strcpy(mcv->name, var); /* SAFE */
7863 if (strchr(var, '(')) {
7864 mcv->isfunc = 1;
7865 }
7866 AST_RWLIST_INSERT_TAIL(channelvars, mcv, entry);
7867 }
7868 AST_RWLIST_UNLOCK(channelvars);
7869
7870}
7871
7872void ast_channel_set_manager_vars(size_t varc, char **vars)
7873{
7874 channel_set_external_vars(&ami_vars, varc, vars);
7875}
7876
7877void ast_channel_set_ari_vars(size_t varc, char **vars)
7878{
7879 channel_set_external_vars(&ari_vars, varc, vars);
7880}
7881
7882/*!
7883 * \brief Destructor for lists of variables.
7884 * \param obj AO2 object.
7885 */
7886static void varshead_dtor(void *obj)
7887{
7888 struct varshead *head = obj;
7889 struct ast_var_t *var;
7890
7891 while ((var = AST_RWLIST_REMOVE_HEAD(head, entries))) {
7893 }
7894}
7895
7897{
7898 RAII_VAR(struct varshead *, ret, NULL, ao2_cleanup);
7899 struct ast_var_t *cv;
7900
7901 ret = ao2_alloc(sizeof(*ret), varshead_dtor);
7902
7903 if (!ret) {
7904 return NULL;
7905 }
7906
7909
7910 if (!var) {
7911 return NULL;
7912 }
7913
7915 }
7916
7917 ao2_ref(ret, +1);
7918 return ret;
7919}
7920
7921static struct varshead *channel_get_external_vars(struct external_vars *channelvars,
7922 struct ast_channel *chan)
7923{
7924 RAII_VAR(struct varshead *, ret, NULL, ao2_cleanup);
7925 RAII_VAR(struct ast_str *, tmp, NULL, ast_free);
7926 struct manager_channel_variable *mcv;
7928
7929 if (AST_LIST_EMPTY(channelvars)) {
7930 return NULL;
7931 }
7932
7933 ret = ao2_alloc(sizeof(*ret), varshead_dtor);
7934 tmp = ast_str_create(16);
7935
7936 if (!ret || !tmp) {
7937 return NULL;
7938 }
7939
7940 AST_LIST_TRAVERSE(channelvars, mcv, entry) {
7941 const char *val = NULL;
7942 struct ast_var_t *var;
7943
7944 if (mcv->isfunc) {
7945 if (ast_func_read2(chan, mcv->name, &tmp, 0) == 0) {
7946 val = ast_str_buffer(tmp);
7947 } else {
7949 "Error invoking function %s\n", mcv->name);
7950 }
7951 } else {
7952 val = pbx_builtin_getvar_helper(chan, mcv->name);
7953 }
7954
7955 var = ast_var_assign(mcv->name, val ? val : "");
7956 if (!var) {
7957 return NULL;
7958 }
7959
7961 }
7962
7963 ao2_ref(ret, +1);
7964 return ret;
7965
7966}
7967
7969{
7970 return channel_get_external_vars(&ami_vars, chan);
7971}
7972
7974{
7975 return channel_get_external_vars(&ari_vars, chan);
7976}
7977
7982
7995
7997{
8000 if (rc) {
8001 ast_log(LOG_ERROR, "No channel storage backends available\n");
8002 return -1;
8003 }
8004 }
8005
8009 ast_log(LOG_ERROR, "Failed to open channel storage driver '%s'\n",
8011 return -1;
8012 }
8013
8014 return 0;
8015}
8016
8022
8024{
8025 if (ast_fully_booted) {
8026 ast_log(LOG_ERROR, "Cannot change channel storage driver after Asterisk has started\n");
8027 return -1;
8028 }
8031 return 0;
8032 }
8034 "Invalid channel storage backend '%s' specified. Attempting to use default '%s'.\n",
8035 driver_name, AST_CHANNELSTORAGE_DEFAULT_TYPE);
8038 return 0;
8039 }
8040 ast_log(LOG_ERROR, "Unable to find default channel storage backend '%s'.\n",
8042 return -1;
8043}
8044
8046{
8047
8048 if (ast_channelstorage_init() != 0) {
8049 return -1;
8050 }
8051
8052 /*
8053 * channel_storage_type is a global variable set by options.c
8054 * from the "channel_storage_backend" option in asterisk.conf.
8055 */
8056 if (ast_channel_open_storage() != 0) {
8057 return -1;
8058 }
8059
8061
8063
8065
8067
8070
8071 return 0;
8072}
8073
8074/*! \brief Print call group and pickup group ---*/
8075char *ast_print_group(char *buf, int buflen, ast_group_t group)
8076{
8077 unsigned int i;
8078 int first = 1;
8079 char num[3];
8080
8081 buf[0] = '\0';
8082
8083 if (!group) /* Return empty string if no group */
8084 return buf;
8085
8086 for (i = 0; i <= 63; i++) { /* Max group is 63 */
8087 if (group & ((ast_group_t) 1 << i)) {
8088 if (!first) {
8089 strncat(buf, ", ", buflen - strlen(buf) - 1);
8090 } else {
8091 first = 0;
8092 }
8093 snprintf(num, sizeof(num), "%u", i);
8094 strncat(buf, num, buflen - strlen(buf) - 1);
8095 }
8096 }
8097 return buf;
8098}
8099
8100char *ast_print_namedgroups(struct ast_str **buf, struct ast_namedgroups *group)
8101{
8102 struct ao2_container *grp = (struct ao2_container *) group;
8103 struct namedgroup_member *ng;
8104 int first = 1;
8105 struct ao2_iterator it;
8106
8107 if (!grp) {
8108 return ast_str_buffer(*buf);
8109 }
8110
8111 for (it = ao2_iterator_init(grp, 0); (ng = ao2_iterator_next(&it)); ao2_ref(ng, -1)) {
8112 if (!first) {
8113 ast_str_append(buf, 0, ", ");
8114 } else {
8115 first = 0;
8116 }
8117 ast_str_append(buf, 0, "%s", ng->name);
8118 }
8120
8121 return ast_str_buffer(*buf);
8122}
8123
8124static int namedgroup_match(void *obj, void *arg, int flags)
8125{
8126 void *match;
8127
8128 match = ao2_find(arg, obj, OBJ_POINTER);
8130
8131 return match ? CMP_MATCH | CMP_STOP : 0;
8132}
8133
8134int ast_namedgroups_intersect(struct ast_namedgroups *a, struct ast_namedgroups *b)
8135{
8136 void *match;
8137 struct ao2_container *group_a = (struct ao2_container *) a;
8138 struct ao2_container *group_b = (struct ao2_container *) b;
8139
8140 if (!a || !b) {
8141 return 0;
8142 }
8143
8144 /*
8145 * Do groups a and b intersect? Since a and b are hash tables,
8146 * the average time complexity is:
8147 * O(a.count <= b.count ? a.count : b.count)
8148 */
8149 if (ao2_container_count(group_b) < ao2_container_count(group_a)) {
8150 /* Traverse over the smaller group. */
8151 SWAP(group_a, group_b);
8152 }
8153 match = ao2_callback(group_a, 0, namedgroup_match, group_b);
8155
8156 return match != NULL;
8157}
8158
8159void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
8160{
8161 struct ast_variable *cur;
8162
8163 for (cur = vars; cur; cur = cur->next) {
8164 pbx_builtin_setvar_helper(chan, cur->name, cur->value);
8165 }
8166}
8167
8168static void *silence_generator_alloc(struct ast_channel *chan, void *data)
8169{
8170 /* just store the data pointer in the channel structure */
8171 return data;
8172}
8173
8174static void silence_generator_release(struct ast_channel *chan, void *data)
8175{
8176 /* nothing to do */
8177}
8178
8179static int silence_generator_generate(struct ast_channel *chan, void *data, int len, int samples)
8180{
8181 short buf[samples];
8182 struct ast_frame frame = {
8184 .data.ptr = buf,
8185 .samples = samples,
8186 .datalen = sizeof(buf),
8187 };
8189
8190 memset(buf, 0, sizeof(buf));
8191
8192 if (ast_write(chan, &frame))
8193 return -1;
8194
8195 return 0;
8196}
8197
8203
8207
8209{
8211
8212 if (!(state = ast_calloc(1, sizeof(*state)))) {
8213 return NULL;
8214 }
8215
8216 state->old_write_format = ao2_bump(ast_channel_writeformat(chan));
8217
8218 if (ast_set_write_format(chan, ast_format_slin) < 0) {
8219 ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n");
8220 ast_free(state);
8221 return NULL;
8222 }
8223
8225
8226 ast_debug(1, "Started silence generator on '%s'\n", ast_channel_name(chan));
8227
8228 return state;
8229}
8230
8232{
8233 ast_channel_lock(chan);
8234
8235 if (!ast_channel_generatordata(chan)) {
8236 ast_debug(1, "Trying to stop silence generator when there is no generator on '%s'\n",
8237 ast_channel_name(chan));
8238 ast_channel_unlock(chan);
8239 return 0;
8240 }
8242 ast_debug(1, "Trying to stop silence generator when it is not the current generator on '%s'\n",
8243 ast_channel_name(chan));
8244 ast_channel_unlock(chan);
8245 return 0;
8246 }
8248
8249 ast_channel_unlock(chan);
8250
8251 return 1;
8252}
8253
8255{
8256 if (!state) {
8257 return;
8258 }
8259
8260 if (deactivate_silence_generator(chan)) {
8261 ast_debug(1, "Stopped silence generator on '%s'\n", ast_channel_name(chan));
8262 if (ast_set_write_format(chan, state->old_write_format) < 0) {
8263 ast_log(LOG_ERROR, "Could not return write format to its original state\n");
8264 }
8265 }
8266 ao2_cleanup(state->old_write_format);
8267 ast_free(state);
8268}
8269
8270
8271/*
8272 * Wrappers for various ast_say_*() functions that call the full version
8273 * of the same functions.
8274 * The proper place would be say.c, but that file is optional and one
8275 * must be able to build asterisk even without it (using a loadable 'say'
8276 * implementation that only supplies the 'full' version of the functions.
8277 */
8278
8279int ast_say_number(struct ast_channel *chan, int num,
8280 const char *ints, const char *language, const char *options)
8281{
8282 return ast_say_number_full(chan, num, ints, language, options, -1, -1);
8283}
8284
8285int ast_say_ordinal(struct ast_channel *chan, int num,
8286 const char *ints, const char *language, const char *options)
8287{
8288 return ast_say_ordinal_full(chan, num, ints, language, options, -1, -1);
8289}
8290
8291int ast_say_enumeration(struct ast_channel *chan, int num,
8292 const char *ints, const char *language, const char *options)
8293{
8294 return ast_say_enumeration_full(chan, num, ints, language, options, -1, -1);
8295}
8296
8297int ast_say_digits(struct ast_channel *chan, int num,
8298 const char *ints, const char *lang)
8299{
8300 return ast_say_digits_full(chan, num, ints, lang, -1, -1);
8301}
8302
8303int ast_say_digit_str(struct ast_channel *chan, const char *str,
8304 const char *ints, const char *lang)
8305{
8306 return ast_say_digit_str_full(chan, str, ints, lang, -1, -1);
8307}
8308
8309int ast_say_money_str(struct ast_channel *chan, const char *str,
8310 const char *ints, const char *lang)
8311{
8312 return ast_say_money_str_full(chan, str, ints, lang, -1, -1);
8313}
8314
8315int ast_say_character_str(struct ast_channel *chan, const char *str,
8316 const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity)
8317{
8318 return ast_say_character_str_full(chan, str, ints, lang, sensitivity, -1, -1);
8319}
8320
8321int ast_say_phonetic_str(struct ast_channel *chan, const char *str,
8322 const char *ints, const char *lang)
8323{
8324 return ast_say_phonetic_str_full(chan, str, ints, lang, -1, -1);
8325}
8326
8327int ast_say_digits_full(struct ast_channel *chan, int num,
8328 const char *ints, const char *lang, int audiofd, int ctrlfd)
8329{
8330 char buf[256];
8331
8332 snprintf(buf, sizeof(buf), "%d", num);
8333
8334 return ast_say_digit_str_full(chan, buf, ints, lang, audiofd, ctrlfd);
8335}
8336
8338{
8339 ast_party_id_copy(&dest->id, &src->id);
8340 ast_party_id_copy(&dest->ani, &src->ani);
8341 dest->ani2 = src->ani2;
8342}
8343
8345{
8346 ast_party_id_copy(&dest->id, &src->id);
8347 ast_party_id_copy(&dest->ani, &src->ani);
8348
8349 dest->ani2 = src->ani2;
8350}
8351
8365
8366/*! \note Should follow struct ast_party_name */
8368 /*! \brief Subscriber name ie */
8369 int str;
8370 /*! \brief Character set ie. */
8372 /*! \brief presentation-indicator ie */
8374 /*! \brief valid/present ie */
8376};
8377
8378/*!
8379 * \internal
8380 * \since 1.8
8381 * \brief Build a party name information data frame component.
8382 *
8383 * \param data Buffer to fill with the frame data
8384 * \param datalen Size of the buffer to fill
8385 * \param name Party name information
8386 * \param label Name of particular party name
8387 * \param ies Data frame ie values for the party name components
8388 *
8389 * \retval -1 if error
8390 * \retval Amount of data buffer used
8391 */
8392static 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)
8393{
8394 size_t length;
8395 size_t pos = 0;
8396
8397 /*
8398 * The size of integer values must be fixed in case the frame is
8399 * shipped to another machine.
8400 */
8401 if (name->str) {
8402 length = strlen(name->str);
8403 if (datalen < pos + (sizeof(data[0]) * 2) + length) {
8404 ast_log(LOG_WARNING, "No space left for %s name\n", label);
8405 return -1;
8406 }
8407 data[pos++] = ies->str;
8408 data[pos++] = length;
8409 memcpy(data + pos, name->str, length);
8410 pos += length;
8411 }
8412
8413 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8414 ast_log(LOG_WARNING, "No space left for %s name char set\n", label);
8415 return -1;
8416 }
8417 data[pos++] = ies->char_set;
8418 data[pos++] = 1;
8419 data[pos++] = name->char_set;
8420
8421 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8422 ast_log(LOG_WARNING, "No space left for %s name presentation\n", label);
8423 return -1;
8424 }
8425 data[pos++] = ies->presentation;
8426 data[pos++] = 1;
8427 data[pos++] = name->presentation;
8428
8429 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8430 ast_log(LOG_WARNING, "No space left for %s name valid\n", label);
8431 return -1;
8432 }
8433 data[pos++] = ies->valid;
8434 data[pos++] = 1;
8435 data[pos++] = name->valid;
8436
8437 return pos;
8438}
8439
8440/*! \note Should follow struct ast_party_number */
8442 /*! \brief Subscriber phone number ie */
8443 int str;
8444 /*! \brief Type-Of-Number and Numbering-Plan ie */
8445 int plan;
8446 /*! \brief presentation-indicator ie */
8448 /*! \brief valid/present ie */
8450};
8451
8452/*!
8453 * \internal
8454 * \since 1.8
8455 * \brief Build a party number information data frame component.
8456 *
8457 * \param data Buffer to fill with the frame data
8458 * \param datalen Size of the buffer to fill
8459 * \param number Party number information
8460 * \param label Name of particular party number
8461 * \param ies Data frame ie values for the party number components
8462 *
8463 * \retval -1 if error
8464 * \retval Amount of data buffer used
8465 */
8466static 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)
8467{
8468 size_t length;
8469 size_t pos = 0;
8470
8471 /*
8472 * The size of integer values must be fixed in case the frame is
8473 * shipped to another machine.
8474 */
8475 if (number->str) {
8476 length = strlen(number->str);
8477 if (datalen < pos + (sizeof(data[0]) * 2) + length) {
8478 ast_log(LOG_WARNING, "No space left for %s number\n", label);
8479 return -1;
8480 }
8481 data[pos++] = ies->str;
8482 data[pos++] = length;
8483 memcpy(data + pos, number->str, length);
8484 pos += length;
8485 }
8486
8487 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8488 ast_log(LOG_WARNING, "No space left for %s numbering plan\n", label);
8489 return -1;
8490 }
8491 data[pos++] = ies->plan;
8492 data[pos++] = 1;
8493 data[pos++] = number->plan;
8494
8495 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8496 ast_log(LOG_WARNING, "No space left for %s number presentation\n", label);
8497 return -1;
8498 }
8499 data[pos++] = ies->presentation;
8500 data[pos++] = 1;
8501 data[pos++] = number->presentation;
8502
8503 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8504 ast_log(LOG_WARNING, "No space left for %s number valid\n", label);
8505 return -1;
8506 }
8507 data[pos++] = ies->valid;
8508 data[pos++] = 1;
8509 data[pos++] = number->valid;
8510
8511 return pos;
8512}
8513
8514/*! \note Should follow struct ast_party_subaddress */
8516 /*! \brief subaddress ie. */
8517 int str;
8518 /*! \brief subaddress type ie */
8519 int type;
8520 /*! \brief odd/even indicator ie */
8522 /*! \brief valid/present ie */
8524};
8525
8526/*!
8527 * \internal
8528 * \since 1.8
8529 * \brief Build a party subaddress information data frame component.
8530 *
8531 * \param data Buffer to fill with the frame data
8532 * \param datalen Size of the buffer to fill
8533 * \param subaddress Party subaddress information
8534 * \param label Name of particular party subaddress
8535 * \param ies Data frame ie values for the party subaddress components
8536 *
8537 * \retval -1 if error
8538 * \retval Amount of data buffer used
8539 */
8540static 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)
8541{
8542 size_t length;
8543 size_t pos = 0;
8544
8545 /*
8546 * The size of integer values must be fixed in case the frame is
8547 * shipped to another machine.
8548 */
8549 if (subaddress->str) {
8550 length = strlen(subaddress->str);
8551 if (datalen < pos + (sizeof(data[0]) * 2) + length) {
8552 ast_log(LOG_WARNING, "No space left for %s subaddress\n", label);
8553 return -1;
8554 }
8555 data[pos++] = ies->str;
8556 data[pos++] = length;
8557 memcpy(data + pos, subaddress->str, length);
8558 pos += length;
8559 }
8560
8561 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8562 ast_log(LOG_WARNING, "No space left for %s type of subaddress\n", label);
8563 return -1;
8564 }
8565 data[pos++] = ies->type;
8566 data[pos++] = 1;
8567 data[pos++] = subaddress->type;
8568
8569 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8571 "No space left for %s subaddress odd-even indicator\n", label);
8572 return -1;
8573 }
8574 data[pos++] = ies->odd_even_indicator;
8575 data[pos++] = 1;
8576 data[pos++] = subaddress->odd_even_indicator;
8577
8578 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8579 ast_log(LOG_WARNING, "No space left for %s subaddress valid\n", label);
8580 return -1;
8581 }
8582 data[pos++] = ies->valid;
8583 data[pos++] = 1;
8584 data[pos++] = subaddress->valid;
8585
8586 return pos;
8587}
8588
8589/*! \note Should follow struct ast_party_id */
8591 /*! \brief Subscriber name ies */
8593 /*! \brief Subscriber phone number ies */
8595 /*! \brief Subscriber subaddress ies. */
8597 /*! \brief User party id tag ie. */
8598 int tag;
8599 /*!
8600 * \brief Combined name and number presentation ie.
8601 * \note Not sent if value is zero.
8602 */
8604};
8605
8606/*!
8607 * \internal
8608 * \since 1.8
8609 * \brief Build a party id information data frame component.
8610 *
8611 * \param data Buffer to fill with the frame data
8612 * \param datalen Size of the buffer to fill
8613 * \param id Party id information
8614 * \param label Name of particular party id
8615 * \param ies Data frame ie values for the party id components
8616 * \param update What id information to build. NULL if all.
8617 *
8618 * \retval -1 if error
8619 * \retval Amount of data buffer used
8620 */
8621static int party_id_build_data(unsigned char *data, size_t datalen,
8622 const struct ast_party_id *id, const char *label, const struct ast_party_id_ies *ies,
8623 const struct ast_set_party_id *update)
8624{
8625 size_t length;
8626 size_t pos = 0;
8627 int res;
8628
8629 /*
8630 * The size of integer values must be fixed in case the frame is
8631 * shipped to another machine.
8632 */
8633
8634 if (!update || update->name) {
8635 res = party_name_build_data(data + pos, datalen - pos, &id->name, label,
8636 &ies->name);
8637 if (res < 0) {
8638 return -1;
8639 }
8640 pos += res;
8641 }
8642
8643 if (!update || update->number) {
8644 res = party_number_build_data(data + pos, datalen - pos, &id->number, label,
8645 &ies->number);
8646 if (res < 0) {
8647 return -1;
8648 }
8649 pos += res;
8650 }
8651
8652 if (!update || update->subaddress) {
8653 res = party_subaddress_build_data(data + pos, datalen - pos, &id->subaddress,
8654 label, &ies->subaddress);
8655 if (res < 0) {
8656 return -1;
8657 }
8658 pos += res;
8659 }
8660
8661 /* *************** Party id user tag **************************** */
8662 if (id->tag) {
8663 length = strlen(id->tag);
8664 if (datalen < pos + (sizeof(data[0]) * 2) + length) {
8665 ast_log(LOG_WARNING, "No space left for %s tag\n", label);
8666 return -1;
8667 }
8668 data[pos++] = ies->tag;
8669 data[pos++] = length;
8670 memcpy(data + pos, id->tag, length);
8671 pos += length;
8672 }
8673
8674 /* *************** Party id combined presentation *************** */
8675 if (ies->combined_presentation && (!update || update->number)) {
8676 int presentation;
8677
8678 if (!update || update->name) {
8679 presentation = ast_party_id_presentation(id);
8680 } else {
8681 /*
8682 * We must compromise because not all the information is available
8683 * to determine a combined presentation value.
8684 * We will only send the number presentation instead.
8685 */
8686 presentation = id->number.presentation;
8687 }
8688
8689 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8690 ast_log(LOG_WARNING, "No space left for %s combined presentation\n", label);
8691 return -1;
8692 }
8693 data[pos++] = ies->combined_presentation;
8694 data[pos++] = 1;
8695 data[pos++] = presentation;
8696 }
8697
8698 return pos;
8699}
8700
8701/*!
8702 * \brief Element identifiers for connected line indication frame data
8703 * \note Only add to the end of this enum.
8704 */
8705enum {
8709 AST_CONNECTED_LINE_ID_PRESENTATION,/* Combined number and name presentation. */
8717 /*
8718 * No more party id combined number and name presentation values
8719 * need to be created.
8720 */
8739};
8740
8741int 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)
8742{
8743 int32_t value;
8744 size_t pos = 0;
8745 int res;
8746
8747 static const struct ast_party_id_ies ies = {
8749 .name.char_set = AST_CONNECTED_LINE_NAME_CHAR_SET,
8750 .name.presentation = AST_CONNECTED_LINE_NAME_PRESENTATION,
8751 .name.valid = AST_CONNECTED_LINE_NAME_VALID,
8752
8753 .number.str = AST_CONNECTED_LINE_NUMBER,
8754 .number.plan = AST_CONNECTED_LINE_NUMBER_PLAN,
8755 .number.presentation = AST_CONNECTED_LINE_NUMBER_PRESENTATION,
8756 .number.valid = AST_CONNECTED_LINE_NUMBER_VALID,
8757
8758 .subaddress.str = AST_CONNECTED_LINE_SUBADDRESS,
8759 .subaddress.type = AST_CONNECTED_LINE_SUBADDRESS_TYPE,
8760 .subaddress.odd_even_indicator = AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN,
8761 .subaddress.valid = AST_CONNECTED_LINE_SUBADDRESS_VALID,
8762
8764 .combined_presentation = AST_CONNECTED_LINE_ID_PRESENTATION,
8765 };
8766
8767 static const struct ast_party_id_ies priv_ies = {
8770 .name.presentation = AST_CONNECTED_LINE_PRIV_NAME_PRESENTATION,
8772
8773 .number.str = AST_CONNECTED_LINE_PRIV_NUMBER,
8775 .number.presentation = AST_CONNECTED_LINE_PRIV_NUMBER_PRESENTATION,
8777
8778 .subaddress.str = AST_CONNECTED_LINE_PRIV_SUBADDRESS,
8779 .subaddress.type = AST_CONNECTED_LINE_PRIV_SUBADDRESS_TYPE,
8780 .subaddress.odd_even_indicator = AST_CONNECTED_LINE_PRIV_SUBADDRESS_ODD_EVEN,
8781 .subaddress.valid = AST_CONNECTED_LINE_PRIV_SUBADDRESS_VALID,
8782
8784 .combined_presentation = 0,/* Not sent. */
8785 };
8786
8787 /*
8788 * The size of integer values must be fixed in case the frame is
8789 * shipped to another machine.
8790 */
8791
8792 /* Connected line frame version */
8793 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
8794 ast_log(LOG_WARNING, "No space left for connected line frame version\n");
8795 return -1;
8796 }
8797 data[pos++] = AST_CONNECTED_LINE_VERSION;
8798 data[pos++] = 1;
8799 data[pos++] = 2;/* Version 1 did not have a version ie */
8800
8801 res = party_id_build_data(data + pos, datalen - pos, &connected->id,
8802 "connected line", &ies, update ? &update->id : NULL);
8803 if (res < 0) {
8804 return -1;
8805 }
8806 pos += res;
8807
8808 res = party_id_build_data(data + pos, datalen - pos, &connected->priv,
8809 "connected line priv", &priv_ies, update ? &update->priv : NULL);
8810 if (res < 0) {
8811 return -1;
8812 }
8813 pos += res;
8814
8815 /* Connected line source */
8816 if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
8817 ast_log(LOG_WARNING, "No space left for connected line source\n");
8818 return -1;
8819 }
8820 data[pos++] = AST_CONNECTED_LINE_SOURCE;
8821 data[pos++] = sizeof(value);
8822 value = htonl(connected->source);
8823 memcpy(data + pos, &value, sizeof(value));
8824 pos += sizeof(value);
8825
8826 return pos;
8827}
8828
8829int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected)
8830{
8831 size_t pos;
8832 unsigned char ie_len;
8833 unsigned char ie_id;
8834 int32_t value;
8835 int frame_version = 1;
8836 int combined_presentation = 0;
8837 int got_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
8838
8839 for (pos = 0; pos < datalen; pos += ie_len) {
8840 if (datalen < pos + sizeof(ie_id) + sizeof(ie_len)) {
8841 ast_log(LOG_WARNING, "Invalid connected line update\n");
8842 return -1;
8843 }
8844 ie_id = data[pos++];
8845 ie_len = data[pos++];
8846 if (datalen < pos + ie_len) {
8847 ast_log(LOG_WARNING, "Invalid connected line update\n");
8848 return -1;
8849 }
8850
8851 switch (ie_id) {
8852/* Connected line party frame version */
8854 if (ie_len != 1) {
8855 ast_log(LOG_WARNING, "Invalid connected line frame version (%u)\n",
8856 (unsigned) ie_len);
8857 break;
8858 }
8859 frame_version = data[pos];
8860 break;
8861/* Connected line party id name */
8863 ast_free(connected->id.name.str);
8864 connected->id.name.str = ast_malloc(ie_len + 1);
8865 if (connected->id.name.str) {
8866 memcpy(connected->id.name.str, data + pos, ie_len);
8867 connected->id.name.str[ie_len] = 0;
8868 }
8869 break;
8871 if (ie_len != 1) {
8872 ast_log(LOG_WARNING, "Invalid connected line name char set (%u)\n",
8873 (unsigned) ie_len);
8874 break;
8875 }
8876 connected->id.name.char_set = data[pos];
8877 break;
8879 if (ie_len != 1) {
8880 ast_log(LOG_WARNING, "Invalid connected line name presentation (%u)\n",
8881 (unsigned) ie_len);
8882 break;
8883 }
8884 connected->id.name.presentation = data[pos];
8885 break;
8887 if (ie_len != 1) {
8888 ast_log(LOG_WARNING, "Invalid connected line name valid (%u)\n",
8889 (unsigned) ie_len);
8890 break;
8891 }
8892 connected->id.name.valid = data[pos];
8893 break;
8894/* Connected line party id number */
8896 ast_free(connected->id.number.str);
8897 connected->id.number.str = ast_malloc(ie_len + 1);
8898 if (connected->id.number.str) {
8899 memcpy(connected->id.number.str, data + pos, ie_len);
8900 connected->id.number.str[ie_len] = 0;
8901 }
8902 break;
8904 if (ie_len != 1) {
8905 ast_log(LOG_WARNING, "Invalid connected line numbering plan (%u)\n",
8906 (unsigned) ie_len);
8907 break;
8908 }
8909 connected->id.number.plan = data[pos];
8910 break;
8912 if (ie_len != 1) {
8913 ast_log(LOG_WARNING, "Invalid connected line number presentation (%u)\n",
8914 (unsigned) ie_len);
8915 break;
8916 }
8917 connected->id.number.presentation = data[pos];
8918 break;
8920 if (ie_len != 1) {
8921 ast_log(LOG_WARNING, "Invalid connected line number valid (%u)\n",
8922 (unsigned) ie_len);
8923 break;
8924 }
8925 connected->id.number.valid = data[pos];
8926 break;
8927/* Connected line party id subaddress */
8929 ast_free(connected->id.subaddress.str);
8930 connected->id.subaddress.str = ast_malloc(ie_len + 1);
8931 if (connected->id.subaddress.str) {
8932 memcpy(connected->id.subaddress.str, data + pos, ie_len);
8933 connected->id.subaddress.str[ie_len] = 0;
8934 }
8935 break;
8937 if (ie_len != 1) {
8938 ast_log(LOG_WARNING, "Invalid connected line type of subaddress (%u)\n",
8939 (unsigned) ie_len);
8940 break;
8941 }
8942 connected->id.subaddress.type = data[pos];
8943 break;
8945 if (ie_len != 1) {
8947 "Invalid connected line subaddress odd-even indicator (%u)\n",
8948 (unsigned) ie_len);
8949 break;
8950 }
8951 connected->id.subaddress.odd_even_indicator = data[pos];
8952 break;
8954 if (ie_len != 1) {
8955 ast_log(LOG_WARNING, "Invalid connected line subaddress valid (%u)\n",
8956 (unsigned) ie_len);
8957 break;
8958 }
8959 connected->id.subaddress.valid = data[pos];
8960 break;
8961/* Connected line party tag */
8963 ast_free(connected->id.tag);
8964 connected->id.tag = ast_malloc(ie_len + 1);
8965 if (connected->id.tag) {
8966 memcpy(connected->id.tag, data + pos, ie_len);
8967 connected->id.tag[ie_len] = 0;
8968 }
8969 break;
8970/* Connected line party id combined presentation */
8972 if (ie_len != 1) {
8973 ast_log(LOG_WARNING, "Invalid connected line combined presentation (%u)\n",
8974 (unsigned) ie_len);
8975 break;
8976 }
8977 combined_presentation = data[pos];
8978 got_combined_presentation = 1;
8979 break;
8980/* Private connected line party id name */
8982 ast_free(connected->priv.name.str);
8983 connected->priv.name.str = ast_malloc(ie_len + 1);
8984 if (connected->priv.name.str) {
8985 memcpy(connected->priv.name.str, data + pos, ie_len);
8986 connected->priv.name.str[ie_len] = 0;
8987 }
8988 break;
8990 if (ie_len != 1) {
8991 ast_log(LOG_WARNING, "Invalid connected line private name char set (%u)\n",
8992 (unsigned) ie_len);
8993 break;
8994 }
8995 connected->priv.name.char_set = data[pos];
8996 break;
8998 if (ie_len != 1) {
8999 ast_log(LOG_WARNING, "Invalid connected line private name presentation (%u)\n",
9000 (unsigned) ie_len);
9001 break;
9002 }
9003 connected->priv.name.presentation = data[pos];
9004 break;
9006 if (ie_len != 1) {
9007 ast_log(LOG_WARNING, "Invalid connected line private name valid (%u)\n",
9008 (unsigned) ie_len);
9009 break;
9010 }
9011 connected->priv.name.valid = data[pos];
9012 break;
9013/* Private connected line party id number */
9015 ast_free(connected->priv.number.str);
9016 connected->priv.number.str = ast_malloc(ie_len + 1);
9017 if (connected->priv.number.str) {
9018 memcpy(connected->priv.number.str, data + pos, ie_len);
9019 connected->priv.number.str[ie_len] = 0;
9020 }
9021 break;
9023 if (ie_len != 1) {
9024 ast_log(LOG_WARNING, "Invalid connected line private numbering plan (%u)\n",
9025 (unsigned) ie_len);
9026 break;
9027 }
9028 connected->priv.number.plan = data[pos];
9029 break;
9031 if (ie_len != 1) {
9032 ast_log(LOG_WARNING, "Invalid connected line private number presentation (%u)\n",
9033 (unsigned) ie_len);
9034 break;
9035 }
9036 connected->priv.number.presentation = data[pos];
9037 break;
9039 if (ie_len != 1) {
9040 ast_log(LOG_WARNING, "Invalid connected line private number valid (%u)\n",
9041 (unsigned) ie_len);
9042 break;
9043 }
9044 connected->priv.number.valid = data[pos];
9045 break;
9046/* Private connected line party id subaddress */
9048 ast_free(connected->priv.subaddress.str);
9049 connected->priv.subaddress.str = ast_malloc(ie_len + 1);
9050 if (connected->priv.subaddress.str) {
9051 memcpy(connected->priv.subaddress.str, data + pos, ie_len);
9052 connected->priv.subaddress.str[ie_len] = 0;
9053 }
9054 break;
9056 if (ie_len != 1) {
9057 ast_log(LOG_WARNING, "Invalid connected line private type of subaddress (%u)\n",
9058 (unsigned) ie_len);
9059 break;
9060 }
9061 connected->priv.subaddress.type = data[pos];
9062 break;
9064 if (ie_len != 1) {
9066 "Invalid connected line private subaddress odd-even indicator (%u)\n",
9067 (unsigned) ie_len);
9068 break;
9069 }
9070 connected->priv.subaddress.odd_even_indicator = data[pos];
9071 break;
9073 if (ie_len != 1) {
9074 ast_log(LOG_WARNING, "Invalid connected line private subaddress valid (%u)\n",
9075 (unsigned) ie_len);
9076 break;
9077 }
9078 connected->priv.subaddress.valid = data[pos];
9079 break;
9080/* Private connected line party tag */
9082 ast_free(connected->priv.tag);
9083 connected->priv.tag = ast_malloc(ie_len + 1);
9084 if (connected->priv.tag) {
9085 memcpy(connected->priv.tag, data + pos, ie_len);
9086 connected->priv.tag[ie_len] = 0;
9087 }
9088 break;
9089/* Connected line party source */
9091 if (ie_len != sizeof(value)) {
9092 ast_log(LOG_WARNING, "Invalid connected line source (%u)\n",
9093 (unsigned) ie_len);
9094 break;
9095 }
9096 memcpy(&value, data + pos, sizeof(value));
9097 connected->source = ntohl(value);
9098 break;
9099/* Connected line party unknown element */
9100 default:
9101 ast_debug(1, "Unknown connected line element: %u (%u)\n",
9102 (unsigned) ie_id, (unsigned) ie_len);
9103 break;
9104 }
9105 }
9106
9107 switch (frame_version) {
9108 case 1:
9109 /*
9110 * The other end is an earlier version that we need to adjust
9111 * for compatibility.
9112 */
9113 connected->id.name.valid = 1;
9114 connected->id.name.char_set = AST_PARTY_CHAR_SET_ISO8859_1;
9115 connected->id.number.valid = 1;
9116 if (got_combined_presentation) {
9117 connected->id.name.presentation = combined_presentation;
9118 connected->id.number.presentation = combined_presentation;
9119 }
9120 break;
9121 case 2:
9122 /* The other end is at the same level as we are. */
9123 break;
9124 default:
9125 /*
9126 * The other end is newer than we are.
9127 * We need to assume that they are compatible with us.
9128 */
9129 ast_debug(1, "Connected line frame has newer version: %u\n",
9130 (unsigned) frame_version);
9131 break;
9132 }
9133
9134 return 0;
9135}
9136
9138{
9139 unsigned char data[1024]; /* This should be large enough */
9140 size_t datalen;
9141
9142 datalen = ast_connected_line_build_data(data, sizeof(data), connected, update);
9143 if (datalen == (size_t) -1) {
9144 return;
9145 }
9146
9147 ast_indicate_data(chan, AST_CONTROL_CONNECTED_LINE, data, datalen);
9148}
9149
9151{
9152 unsigned char data[1024]; /* This should be large enough */
9153 size_t datalen;
9154
9155 datalen = ast_connected_line_build_data(data, sizeof(data), connected, update);
9156 if (datalen == (size_t) -1) {
9157 return;
9158 }
9159
9161}
9162
9163void ast_channel_set_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
9164{
9165 if (ast_channel_redirecting(chan) == redirecting) {
9166 /* Don't set to self */
9167 return;
9168 }
9169
9170 ast_channel_lock(chan);
9174 ast_channel_unlock(chan);
9175}
9176
9177/*!
9178 * \brief Element identifiers for redirecting indication frame data
9179 * \note Only add to the end of this enum.
9180 */
9181enum {
9185 AST_REDIRECTING_FROM_ID_PRESENTATION,/* Combined number and name presentation. */
9189 AST_REDIRECTING_TO_ID_PRESENTATION,/* Combined number and name presentation. */
9203 /*
9204 * No more party id combined number and name presentation values
9205 * need to be created.
9206 */
9272};
9273
9278
9279static int redirecting_reason_build_data(unsigned char *data, size_t datalen,
9280 const struct ast_party_redirecting_reason *reason, const char *label,
9281 const struct ast_party_redirecting_reason_ies *ies)
9282{
9283 size_t length;
9284 size_t pos = 0;
9285 int32_t value;
9286
9287 if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
9288 ast_log(LOG_WARNING, "No space left for %s code\n", label);
9289 return -1;
9290 }
9291 data[pos++] = ies->code;
9292 data[pos++] = sizeof(value);
9293 value = htonl(reason->code);
9294 memcpy(data + pos, &value, sizeof(value));
9295 pos += sizeof(value);
9296
9297 if (reason->str) {
9298 length = strlen(reason->str);
9299 if (datalen < pos + (sizeof(data[0]) * 2) + length) {
9300 ast_log(LOG_WARNING, "No space left for %s string\n", label);
9301 return -1;
9302 }
9303 data[pos++] = ies->str;
9304 data[pos++] = length;
9305 memcpy(data + pos, reason->str, length);
9306 pos += length;
9307 }
9308
9309 return pos;
9310}
9311
9312int ast_redirecting_build_data(unsigned char *data, size_t datalen, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
9313{
9314 int32_t value;
9315 size_t pos = 0;
9316 int res;
9317
9318 static const struct ast_party_id_ies orig_ies = {
9320 .name.char_set = AST_REDIRECTING_ORIG_NAME_CHAR_SET,
9321 .name.presentation = AST_REDIRECTING_ORIG_NAME_PRESENTATION,
9322 .name.valid = AST_REDIRECTING_ORIG_NAME_VALID,
9323
9324 .number.str = AST_REDIRECTING_ORIG_NUMBER,
9325 .number.plan = AST_REDIRECTING_ORIG_NUMBER_PLAN,
9326 .number.presentation = AST_REDIRECTING_ORIG_NUMBER_PRESENTATION,
9327 .number.valid = AST_REDIRECTING_ORIG_NUMBER_VALID,
9328
9329 .subaddress.str = AST_REDIRECTING_ORIG_SUBADDRESS,
9330 .subaddress.type = AST_REDIRECTING_ORIG_SUBADDRESS_TYPE,
9331 .subaddress.odd_even_indicator = AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN,
9332 .subaddress.valid = AST_REDIRECTING_ORIG_SUBADDRESS_VALID,
9333
9335 .combined_presentation = 0,/* Not sent. */
9336 };
9337 static const struct ast_party_id_ies from_ies = {
9339 .name.char_set = AST_REDIRECTING_FROM_NAME_CHAR_SET,
9340 .name.presentation = AST_REDIRECTING_FROM_NAME_PRESENTATION,
9341 .name.valid = AST_REDIRECTING_FROM_NAME_VALID,
9342
9343 .number.str = AST_REDIRECTING_FROM_NUMBER,
9344 .number.plan = AST_REDIRECTING_FROM_NUMBER_PLAN,
9345 .number.presentation = AST_REDIRECTING_FROM_NUMBER_PRESENTATION,
9346 .number.valid = AST_REDIRECTING_FROM_NUMBER_VALID,
9347
9348 .subaddress.str = AST_REDIRECTING_FROM_SUBADDRESS,
9349 .subaddress.type = AST_REDIRECTING_FROM_SUBADDRESS_TYPE,
9350 .subaddress.odd_even_indicator = AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN,
9351 .subaddress.valid = AST_REDIRECTING_FROM_SUBADDRESS_VALID,
9352
9354 .combined_presentation = AST_REDIRECTING_FROM_ID_PRESENTATION,
9355 };
9356 static const struct ast_party_id_ies to_ies = {
9358 .name.char_set = AST_REDIRECTING_TO_NAME_CHAR_SET,
9359 .name.presentation = AST_REDIRECTING_TO_NAME_PRESENTATION,
9360 .name.valid = AST_REDIRECTING_TO_NAME_VALID,
9361
9362 .number.str = AST_REDIRECTING_TO_NUMBER,
9363 .number.plan = AST_REDIRECTING_TO_NUMBER_PLAN,
9364 .number.presentation = AST_REDIRECTING_TO_NUMBER_PRESENTATION,
9365 .number.valid = AST_REDIRECTING_TO_NUMBER_VALID,
9366
9367 .subaddress.str = AST_REDIRECTING_TO_SUBADDRESS,
9368 .subaddress.type = AST_REDIRECTING_TO_SUBADDRESS_TYPE,
9369 .subaddress.odd_even_indicator = AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN,
9370 .subaddress.valid = AST_REDIRECTING_TO_SUBADDRESS_VALID,
9371
9373 .combined_presentation = AST_REDIRECTING_TO_ID_PRESENTATION,
9374 };
9375 static const struct ast_party_id_ies priv_orig_ies = {
9380
9383 .number.presentation = AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION,
9385
9386 .subaddress.str = AST_REDIRECTING_PRIV_ORIG_SUBADDRESS,
9388 .subaddress.odd_even_indicator = AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN,
9390
9392 .combined_presentation = 0,/* Not sent. */
9393 };
9394 static const struct ast_party_id_ies priv_from_ies = {
9399
9402 .number.presentation = AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION,
9404
9405 .subaddress.str = AST_REDIRECTING_PRIV_FROM_SUBADDRESS,
9407 .subaddress.odd_even_indicator = AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN,
9409
9411 .combined_presentation = 0,/* Not sent. */
9412 };
9413 static const struct ast_party_id_ies priv_to_ies = {
9416 .name.presentation = AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION,
9418
9419 .number.str = AST_REDIRECTING_PRIV_TO_NUMBER,
9421 .number.presentation = AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION,
9423
9424 .subaddress.str = AST_REDIRECTING_PRIV_TO_SUBADDRESS,
9425 .subaddress.type = AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE,
9426 .subaddress.odd_even_indicator = AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN,
9427 .subaddress.valid = AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID,
9428
9430 .combined_presentation = 0,/* Not sent. */
9431 };
9432 static const struct ast_party_redirecting_reason_ies reason_ies = {
9435 };
9436
9437 static const struct ast_party_redirecting_reason_ies orig_reason_ies = {
9440 };
9441
9442 /* Redirecting frame version */
9443 if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
9444 ast_log(LOG_WARNING, "No space left for redirecting frame version\n");
9445 return -1;
9446 }
9447 data[pos++] = AST_REDIRECTING_VERSION;
9448 data[pos++] = 1;
9449 data[pos++] = 2;/* Version 1 did not have a version ie */
9450
9451 res = party_id_build_data(data + pos, datalen - pos, &redirecting->orig,
9452 "redirecting-orig", &orig_ies, update ? &update->orig : NULL);
9453 if (res < 0) {
9454 return -1;
9455 }
9456 pos += res;
9457
9458 res = party_id_build_data(data + pos, datalen - pos, &redirecting->from,
9459 "redirecting-from", &from_ies, update ? &update->from : NULL);
9460 if (res < 0) {
9461 return -1;
9462 }
9463 pos += res;
9464
9465 res = party_id_build_data(data + pos, datalen - pos, &redirecting->to,
9466 "redirecting-to", &to_ies, update ? &update->to : NULL);
9467 if (res < 0) {
9468 return -1;
9469 }
9470 pos += res;
9471
9472 res = party_id_build_data(data + pos, datalen - pos, &redirecting->priv_orig,
9473 "redirecting-priv-orig", &priv_orig_ies, update ? &update->priv_orig : NULL);
9474 if (res < 0) {
9475 return -1;
9476 }
9477 pos += res;
9478
9479 res = party_id_build_data(data + pos, datalen - pos, &redirecting->priv_from,
9480 "redirecting-priv-from", &priv_from_ies, update ? &update->priv_from : NULL);
9481 if (res < 0) {
9482 return -1;
9483 }
9484 pos += res;
9485
9486 res = party_id_build_data(data + pos, datalen - pos, &redirecting->priv_to,
9487 "redirecting-priv-to", &priv_to_ies, update ? &update->priv_to : NULL);
9488 if (res < 0) {
9489 return -1;
9490 }
9491 pos += res;
9492
9493 /* Redirecting reason */
9494 res = redirecting_reason_build_data(data + pos, datalen - pos, &redirecting->reason,
9495 "redirecting-reason", &reason_ies);
9496 if (res < 0) {
9497 return -1;
9498 }
9499 pos += res;
9500
9501 /* Redirecting original reason */
9502 res = redirecting_reason_build_data(data + pos, datalen - pos, &redirecting->orig_reason,
9503 "redirecting-orig-reason", &orig_reason_ies);
9504 if (res < 0) {
9505 return -1;
9506 }
9507 pos += res;
9508
9509 /* Redirecting count */
9510 if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
9511 ast_log(LOG_WARNING, "No space left for redirecting count\n");
9512 return -1;
9513 }
9514 data[pos++] = AST_REDIRECTING_COUNT;
9515 data[pos++] = sizeof(value);
9516 value = htonl(redirecting->count);
9517 memcpy(data + pos, &value, sizeof(value));
9518 pos += sizeof(value);
9519
9520 return pos;
9521}
9522
9523int ast_redirecting_parse_data(const unsigned char *data, size_t datalen, struct ast_party_redirecting *redirecting)
9524{
9525 size_t pos;
9526 unsigned char ie_len;
9527 unsigned char ie_id;
9528 int32_t value;
9529 int frame_version = 1;
9530 int from_combined_presentation = 0;
9531 int got_from_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
9532 int to_combined_presentation = 0;
9533 int got_to_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
9534
9535 for (pos = 0; pos < datalen; pos += ie_len) {
9536 if (datalen < pos + sizeof(ie_id) + sizeof(ie_len)) {
9537 ast_log(LOG_WARNING, "Invalid redirecting update\n");
9538 return -1;
9539 }
9540 ie_id = data[pos++];
9541 ie_len = data[pos++];
9542 if (datalen < pos + ie_len) {
9543 ast_log(LOG_WARNING, "Invalid redirecting update\n");
9544 return -1;
9545 }
9546
9547 switch (ie_id) {
9548/* Redirecting frame version */
9550 if (ie_len != 1) {
9551 ast_log(LOG_WARNING, "Invalid redirecting frame version (%u)\n",
9552 (unsigned) ie_len);
9553 break;
9554 }
9555 frame_version = data[pos];
9556 break;
9557/* Redirecting-orig party id name */
9559 ast_free(redirecting->orig.name.str);
9560 redirecting->orig.name.str = ast_malloc(ie_len + 1);
9561 if (redirecting->orig.name.str) {
9562 memcpy(redirecting->orig.name.str, data + pos, ie_len);
9563 redirecting->orig.name.str[ie_len] = 0;
9564 }
9565 break;
9567 if (ie_len != 1) {
9568 ast_log(LOG_WARNING, "Invalid redirecting-orig name char set (%u)\n",
9569 (unsigned) ie_len);
9570 break;
9571 }
9572 redirecting->orig.name.char_set = data[pos];
9573 break;
9575 if (ie_len != 1) {
9576 ast_log(LOG_WARNING, "Invalid redirecting-orig name presentation (%u)\n",
9577 (unsigned) ie_len);
9578 break;
9579 }
9580 redirecting->orig.name.presentation = data[pos];
9581 break;
9583 if (ie_len != 1) {
9584 ast_log(LOG_WARNING, "Invalid redirecting-orig name valid (%u)\n",
9585 (unsigned) ie_len);
9586 break;
9587 }
9588 redirecting->orig.name.valid = data[pos];
9589 break;
9590/* Redirecting-orig party id number */
9592 ast_free(redirecting->orig.number.str);
9593 redirecting->orig.number.str = ast_malloc(ie_len + 1);
9594 if (redirecting->orig.number.str) {
9595 memcpy(redirecting->orig.number.str, data + pos, ie_len);
9596 redirecting->orig.number.str[ie_len] = 0;
9597 }
9598 break;
9600 if (ie_len != 1) {
9601 ast_log(LOG_WARNING, "Invalid redirecting-orig numbering plan (%u)\n",
9602 (unsigned) ie_len);
9603 break;
9604 }
9605 redirecting->orig.number.plan = data[pos];
9606 break;
9608 if (ie_len != 1) {
9609 ast_log(LOG_WARNING, "Invalid redirecting-orig number presentation (%u)\n",
9610 (unsigned) ie_len);
9611 break;
9612 }
9613 redirecting->orig.number.presentation = data[pos];
9614 break;
9616 if (ie_len != 1) {
9617 ast_log(LOG_WARNING, "Invalid redirecting-orig number valid (%u)\n",
9618 (unsigned) ie_len);
9619 break;
9620 }
9621 redirecting->orig.number.valid = data[pos];
9622 break;
9623/* Redirecting-orig party id subaddress */
9625 ast_free(redirecting->orig.subaddress.str);
9626 redirecting->orig.subaddress.str = ast_malloc(ie_len + 1);
9627 if (redirecting->orig.subaddress.str) {
9628 memcpy(redirecting->orig.subaddress.str, data + pos, ie_len);
9629 redirecting->orig.subaddress.str[ie_len] = 0;
9630 }
9631 break;
9633 if (ie_len != 1) {
9634 ast_log(LOG_WARNING, "Invalid redirecting-orig type of subaddress (%u)\n",
9635 (unsigned) ie_len);
9636 break;
9637 }
9638 redirecting->orig.subaddress.type = data[pos];
9639 break;
9641 if (ie_len != 1) {
9643 "Invalid redirecting-orig subaddress odd-even indicator (%u)\n",
9644 (unsigned) ie_len);
9645 break;
9646 }
9647 redirecting->orig.subaddress.odd_even_indicator = data[pos];
9648 break;
9650 if (ie_len != 1) {
9651 ast_log(LOG_WARNING, "Invalid redirecting-orig subaddress valid (%u)\n",
9652 (unsigned) ie_len);
9653 break;
9654 }
9655 redirecting->orig.subaddress.valid = data[pos];
9656 break;
9657/* Redirecting-orig party id tag */
9659 ast_free(redirecting->orig.tag);
9660 redirecting->orig.tag = ast_malloc(ie_len + 1);
9661 if (redirecting->orig.tag) {
9662 memcpy(redirecting->orig.tag, data + pos, ie_len);
9663 redirecting->orig.tag[ie_len] = 0;
9664 }
9665 break;
9666/* Redirecting-from party id name */
9668 ast_free(redirecting->from.name.str);
9669 redirecting->from.name.str = ast_malloc(ie_len + 1);
9670 if (redirecting->from.name.str) {
9671 memcpy(redirecting->from.name.str, data + pos, ie_len);
9672 redirecting->from.name.str[ie_len] = 0;
9673 }
9674 break;
9676 if (ie_len != 1) {
9677 ast_log(LOG_WARNING, "Invalid redirecting-from name char set (%u)\n",
9678 (unsigned) ie_len);
9679 break;
9680 }
9681 redirecting->from.name.char_set = data[pos];
9682 break;
9684 if (ie_len != 1) {
9685 ast_log(LOG_WARNING, "Invalid redirecting-from name presentation (%u)\n",
9686 (unsigned) ie_len);
9687 break;
9688 }
9689 redirecting->from.name.presentation = data[pos];
9690 break;
9692 if (ie_len != 1) {
9693 ast_log(LOG_WARNING, "Invalid redirecting-from name valid (%u)\n",
9694 (unsigned) ie_len);
9695 break;
9696 }
9697 redirecting->from.name.valid = data[pos];
9698 break;
9699/* Redirecting-from party id number */
9701 ast_free(redirecting->from.number.str);
9702 redirecting->from.number.str = ast_malloc(ie_len + 1);
9703 if (redirecting->from.number.str) {
9704 memcpy(redirecting->from.number.str, data + pos, ie_len);
9705 redirecting->from.number.str[ie_len] = 0;
9706 }
9707 break;
9709 if (ie_len != 1) {
9710 ast_log(LOG_WARNING, "Invalid redirecting-from numbering plan (%u)\n",
9711 (unsigned) ie_len);
9712 break;
9713 }
9714 redirecting->from.number.plan = data[pos];
9715 break;
9717 if (ie_len != 1) {
9718 ast_log(LOG_WARNING, "Invalid redirecting-from number presentation (%u)\n",
9719 (unsigned) ie_len);
9720 break;
9721 }
9722 redirecting->from.number.presentation = data[pos];
9723 break;
9725 if (ie_len != 1) {
9726 ast_log(LOG_WARNING, "Invalid redirecting-from number valid (%u)\n",
9727 (unsigned) ie_len);
9728 break;
9729 }
9730 redirecting->from.number.valid = data[pos];
9731 break;
9732/* Redirecting-from party id combined presentation */
9734 if (ie_len != 1) {
9735 ast_log(LOG_WARNING, "Invalid redirecting-from combined presentation (%u)\n",
9736 (unsigned) ie_len);
9737 break;
9738 }
9739 from_combined_presentation = data[pos];
9740 got_from_combined_presentation = 1;
9741 break;
9742/* Redirecting-from party id subaddress */
9744 ast_free(redirecting->from.subaddress.str);
9745 redirecting->from.subaddress.str = ast_malloc(ie_len + 1);
9746 if (redirecting->from.subaddress.str) {
9747 memcpy(redirecting->from.subaddress.str, data + pos, ie_len);
9748 redirecting->from.subaddress.str[ie_len] = 0;
9749 }
9750 break;
9752 if (ie_len != 1) {
9753 ast_log(LOG_WARNING, "Invalid redirecting-from type of subaddress (%u)\n",
9754 (unsigned) ie_len);
9755 break;
9756 }
9757 redirecting->from.subaddress.type = data[pos];
9758 break;
9760 if (ie_len != 1) {
9762 "Invalid redirecting-from subaddress odd-even indicator (%u)\n",
9763 (unsigned) ie_len);
9764 break;
9765 }
9766 redirecting->from.subaddress.odd_even_indicator = data[pos];
9767 break;
9769 if (ie_len != 1) {
9770 ast_log(LOG_WARNING, "Invalid redirecting-from subaddress valid (%u)\n",
9771 (unsigned) ie_len);
9772 break;
9773 }
9774 redirecting->from.subaddress.valid = data[pos];
9775 break;
9776/* Redirecting-from party id tag */
9778 ast_free(redirecting->from.tag);
9779 redirecting->from.tag = ast_malloc(ie_len + 1);
9780 if (redirecting->from.tag) {
9781 memcpy(redirecting->from.tag, data + pos, ie_len);
9782 redirecting->from.tag[ie_len] = 0;
9783 }
9784 break;
9785/* Redirecting-to party id name */
9787 ast_free(redirecting->to.name.str);
9788 redirecting->to.name.str = ast_malloc(ie_len + 1);
9789 if (redirecting->to.name.str) {
9790 memcpy(redirecting->to.name.str, data + pos, ie_len);
9791 redirecting->to.name.str[ie_len] = 0;
9792 }
9793 break;
9795 if (ie_len != 1) {
9796 ast_log(LOG_WARNING, "Invalid redirecting-to name char set (%u)\n",
9797 (unsigned) ie_len);
9798 break;
9799 }
9800 redirecting->to.name.char_set = data[pos];
9801 break;
9803 if (ie_len != 1) {
9804 ast_log(LOG_WARNING, "Invalid redirecting-to name presentation (%u)\n",
9805 (unsigned) ie_len);
9806 break;
9807 }
9808 redirecting->to.name.presentation = data[pos];
9809 break;
9811 if (ie_len != 1) {
9812 ast_log(LOG_WARNING, "Invalid redirecting-to name valid (%u)\n",
9813 (unsigned) ie_len);
9814 break;
9815 }
9816 redirecting->to.name.valid = data[pos];
9817 break;
9818/* Redirecting-to party id number */
9820 ast_free(redirecting->to.number.str);
9821 redirecting->to.number.str = ast_malloc(ie_len + 1);
9822 if (redirecting->to.number.str) {
9823 memcpy(redirecting->to.number.str, data + pos, ie_len);
9824 redirecting->to.number.str[ie_len] = 0;
9825 }
9826 break;
9828 if (ie_len != 1) {
9829 ast_log(LOG_WARNING, "Invalid redirecting-to numbering plan (%u)\n",
9830 (unsigned) ie_len);
9831 break;
9832 }
9833 redirecting->to.number.plan = data[pos];
9834 break;
9836 if (ie_len != 1) {
9837 ast_log(LOG_WARNING, "Invalid redirecting-to number presentation (%u)\n",
9838 (unsigned) ie_len);
9839 break;
9840 }
9841 redirecting->to.number.presentation = data[pos];
9842 break;
9844 if (ie_len != 1) {
9845 ast_log(LOG_WARNING, "Invalid redirecting-to number valid (%u)\n",
9846 (unsigned) ie_len);
9847 break;
9848 }
9849 redirecting->to.number.valid = data[pos];
9850 break;
9851/* Redirecting-to party id combined presentation */
9853 if (ie_len != 1) {
9854 ast_log(LOG_WARNING, "Invalid redirecting-to combined presentation (%u)\n",
9855 (unsigned) ie_len);
9856 break;
9857 }
9858 to_combined_presentation = data[pos];
9859 got_to_combined_presentation = 1;
9860 break;
9861/* Redirecting-to party id subaddress */
9863 ast_free(redirecting->to.subaddress.str);
9864 redirecting->to.subaddress.str = ast_malloc(ie_len + 1);
9865 if (redirecting->to.subaddress.str) {
9866 memcpy(redirecting->to.subaddress.str, data + pos, ie_len);
9867 redirecting->to.subaddress.str[ie_len] = 0;
9868 }
9869 break;
9871 if (ie_len != 1) {
9872 ast_log(LOG_WARNING, "Invalid redirecting-to type of subaddress (%u)\n",
9873 (unsigned) ie_len);
9874 break;
9875 }
9876 redirecting->to.subaddress.type = data[pos];
9877 break;
9879 if (ie_len != 1) {
9881 "Invalid redirecting-to subaddress odd-even indicator (%u)\n",
9882 (unsigned) ie_len);
9883 break;
9884 }
9885 redirecting->to.subaddress.odd_even_indicator = data[pos];
9886 break;
9888 if (ie_len != 1) {
9889 ast_log(LOG_WARNING, "Invalid redirecting-to subaddress valid (%u)\n",
9890 (unsigned) ie_len);
9891 break;
9892 }
9893 redirecting->to.subaddress.valid = data[pos];
9894 break;
9895/* Redirecting-to party id tag */
9897 ast_free(redirecting->to.tag);
9898 redirecting->to.tag = ast_malloc(ie_len + 1);
9899 if (redirecting->to.tag) {
9900 memcpy(redirecting->to.tag, data + pos, ie_len);
9901 redirecting->to.tag[ie_len] = 0;
9902 }
9903 break;
9904/* Private redirecting-orig party id name */
9906 ast_free(redirecting->priv_orig.name.str);
9907 redirecting->priv_orig.name.str = ast_malloc(ie_len + 1);
9908 if (redirecting->priv_orig.name.str) {
9909 memcpy(redirecting->priv_orig.name.str, data + pos, ie_len);
9910 redirecting->priv_orig.name.str[ie_len] = 0;
9911 }
9912 break;
9914 if (ie_len != 1) {
9915 ast_log(LOG_WARNING, "Invalid private redirecting-orig name char set (%u)\n",
9916 (unsigned) ie_len);
9917 break;
9918 }
9919 redirecting->priv_orig.name.char_set = data[pos];
9920 break;
9922 if (ie_len != 1) {
9923 ast_log(LOG_WARNING, "Invalid private redirecting-orig name presentation (%u)\n",
9924 (unsigned) ie_len);
9925 break;
9926 }
9927 redirecting->priv_orig.name.presentation = data[pos];
9928 break;
9930 if (ie_len != 1) {
9931 ast_log(LOG_WARNING, "Invalid private redirecting-orig name valid (%u)\n",
9932 (unsigned) ie_len);
9933 break;
9934 }
9935 redirecting->priv_orig.name.valid = data[pos];
9936 break;
9937/* Private redirecting-orig party id number */
9939 ast_free(redirecting->priv_orig.number.str);
9940 redirecting->priv_orig.number.str = ast_malloc(ie_len + 1);
9941 if (redirecting->priv_orig.number.str) {
9942 memcpy(redirecting->priv_orig.number.str, data + pos, ie_len);
9943 redirecting->priv_orig.number.str[ie_len] = 0;
9944 }
9945 break;
9947 if (ie_len != 1) {
9948 ast_log(LOG_WARNING, "Invalid private redirecting-orig numbering plan (%u)\n",
9949 (unsigned) ie_len);
9950 break;
9951 }
9952 redirecting->priv_orig.number.plan = data[pos];
9953 break;
9955 if (ie_len != 1) {
9956 ast_log(LOG_WARNING, "Invalid private redirecting-orig number presentation (%u)\n",
9957 (unsigned) ie_len);
9958 break;
9959 }
9960 redirecting->priv_orig.number.presentation = data[pos];
9961 break;
9963 if (ie_len != 1) {
9964 ast_log(LOG_WARNING, "Invalid private redirecting-orig number valid (%u)\n",
9965 (unsigned) ie_len);
9966 break;
9967 }
9968 redirecting->priv_orig.number.valid = data[pos];
9969 break;
9970/* Private redirecting-orig party id subaddress */
9972 ast_free(redirecting->priv_orig.subaddress.str);
9973 redirecting->priv_orig.subaddress.str = ast_malloc(ie_len + 1);
9974 if (redirecting->priv_orig.subaddress.str) {
9975 memcpy(redirecting->priv_orig.subaddress.str, data + pos, ie_len);
9976 redirecting->priv_orig.subaddress.str[ie_len] = 0;
9977 }
9978 break;
9980 if (ie_len != 1) {
9981 ast_log(LOG_WARNING, "Invalid private redirecting-orig type of subaddress (%u)\n",
9982 (unsigned) ie_len);
9983 break;
9984 }
9985 redirecting->priv_orig.subaddress.type = data[pos];
9986 break;
9988 if (ie_len != 1) {
9990 "Invalid private redirecting-orig subaddress odd-even indicator (%u)\n",
9991 (unsigned) ie_len);
9992 break;
9993 }
9994 redirecting->priv_orig.subaddress.odd_even_indicator = data[pos];
9995 break;
9997 if (ie_len != 1) {
9998 ast_log(LOG_WARNING, "Invalid private redirecting-orig subaddress valid (%u)\n",
9999 (unsigned) ie_len);
10000 break;
10001 }
10002 redirecting->priv_orig.subaddress.valid = data[pos];
10003 break;
10004/* Private redirecting-orig party id tag */
10006 ast_free(redirecting->priv_orig.tag);
10007 redirecting->priv_orig.tag = ast_malloc(ie_len + 1);
10008 if (redirecting->priv_orig.tag) {
10009 memcpy(redirecting->priv_orig.tag, data + pos, ie_len);
10010 redirecting->priv_orig.tag[ie_len] = 0;
10011 }
10012 break;
10013/* Private redirecting-from party id name */
10015 ast_free(redirecting->priv_from.name.str);
10016 redirecting->priv_from.name.str = ast_malloc(ie_len + 1);
10017 if (redirecting->priv_from.name.str) {
10018 memcpy(redirecting->priv_from.name.str, data + pos, ie_len);
10019 redirecting->priv_from.name.str[ie_len] = 0;
10020 }
10021 break;
10023 if (ie_len != 1) {
10024 ast_log(LOG_WARNING, "Invalid private redirecting-from name char set (%u)\n",
10025 (unsigned) ie_len);
10026 break;
10027 }
10028 redirecting->priv_from.name.char_set = data[pos];
10029 break;
10031 if (ie_len != 1) {
10032 ast_log(LOG_WARNING, "Invalid private redirecting-from name presentation (%u)\n",
10033 (unsigned) ie_len);
10034 break;
10035 }
10036 redirecting->priv_from.name.presentation = data[pos];
10037 break;
10039 if (ie_len != 1) {
10040 ast_log(LOG_WARNING, "Invalid private redirecting-from name valid (%u)\n",
10041 (unsigned) ie_len);
10042 break;
10043 }
10044 redirecting->priv_from.name.valid = data[pos];
10045 break;
10046/* Private redirecting-from party id number */
10048 ast_free(redirecting->priv_from.number.str);
10049 redirecting->priv_from.number.str = ast_malloc(ie_len + 1);
10050 if (redirecting->priv_from.number.str) {
10051 memcpy(redirecting->priv_from.number.str, data + pos, ie_len);
10052 redirecting->priv_from.number.str[ie_len] = 0;
10053 }
10054 break;
10056 if (ie_len != 1) {
10057 ast_log(LOG_WARNING, "Invalid private redirecting-from numbering plan (%u)\n",
10058 (unsigned) ie_len);
10059 break;
10060 }
10061 redirecting->priv_from.number.plan = data[pos];
10062 break;
10064 if (ie_len != 1) {
10065 ast_log(LOG_WARNING, "Invalid private redirecting-from number presentation (%u)\n",
10066 (unsigned) ie_len);
10067 break;
10068 }
10069 redirecting->priv_from.number.presentation = data[pos];
10070 break;
10072 if (ie_len != 1) {
10073 ast_log(LOG_WARNING, "Invalid private redirecting-from number valid (%u)\n",
10074 (unsigned) ie_len);
10075 break;
10076 }
10077 redirecting->priv_from.number.valid = data[pos];
10078 break;
10079/* Private redirecting-from party id subaddress */
10081 ast_free(redirecting->priv_from.subaddress.str);
10082 redirecting->priv_from.subaddress.str = ast_malloc(ie_len + 1);
10083 if (redirecting->priv_from.subaddress.str) {
10084 memcpy(redirecting->priv_from.subaddress.str, data + pos, ie_len);
10085 redirecting->priv_from.subaddress.str[ie_len] = 0;
10086 }
10087 break;
10089 if (ie_len != 1) {
10090 ast_log(LOG_WARNING, "Invalid private redirecting-from type of subaddress (%u)\n",
10091 (unsigned) ie_len);
10092 break;
10093 }
10094 redirecting->priv_from.subaddress.type = data[pos];
10095 break;
10097 if (ie_len != 1) {
10099 "Invalid private redirecting-from subaddress odd-even indicator (%u)\n",
10100 (unsigned) ie_len);
10101 break;
10102 }
10103 redirecting->priv_from.subaddress.odd_even_indicator = data[pos];
10104 break;
10106 if (ie_len != 1) {
10107 ast_log(LOG_WARNING, "Invalid private redirecting-from subaddress valid (%u)\n",
10108 (unsigned) ie_len);
10109 break;
10110 }
10111 redirecting->priv_from.subaddress.valid = data[pos];
10112 break;
10113/* Private redirecting-from party id tag */
10115 ast_free(redirecting->priv_from.tag);
10116 redirecting->priv_from.tag = ast_malloc(ie_len + 1);
10117 if (redirecting->priv_from.tag) {
10118 memcpy(redirecting->priv_from.tag, data + pos, ie_len);
10119 redirecting->priv_from.tag[ie_len] = 0;
10120 }
10121 break;
10122/* Private redirecting-to party id name */
10124 ast_free(redirecting->priv_to.name.str);
10125 redirecting->priv_to.name.str = ast_malloc(ie_len + 1);
10126 if (redirecting->priv_to.name.str) {
10127 memcpy(redirecting->priv_to.name.str, data + pos, ie_len);
10128 redirecting->priv_to.name.str[ie_len] = 0;
10129 }
10130 break;
10132 if (ie_len != 1) {
10133 ast_log(LOG_WARNING, "Invalid private redirecting-to name char set (%u)\n",
10134 (unsigned) ie_len);
10135 break;
10136 }
10137 redirecting->priv_to.name.char_set = data[pos];
10138 break;
10140 if (ie_len != 1) {
10141 ast_log(LOG_WARNING, "Invalid private redirecting-to name presentation (%u)\n",
10142 (unsigned) ie_len);
10143 break;
10144 }
10145 redirecting->priv_to.name.presentation = data[pos];
10146 break;
10148 if (ie_len != 1) {
10149 ast_log(LOG_WARNING, "Invalid private redirecting-to name valid (%u)\n",
10150 (unsigned) ie_len);
10151 break;
10152 }
10153 redirecting->priv_to.name.valid = data[pos];
10154 break;
10155/* Private redirecting-to party id number */
10157 ast_free(redirecting->priv_to.number.str);
10158 redirecting->priv_to.number.str = ast_malloc(ie_len + 1);
10159 if (redirecting->priv_to.number.str) {
10160 memcpy(redirecting->priv_to.number.str, data + pos, ie_len);
10161 redirecting->priv_to.number.str[ie_len] = 0;
10162 }
10163 break;
10165 if (ie_len != 1) {
10166 ast_log(LOG_WARNING, "Invalid private redirecting-to numbering plan (%u)\n",
10167 (unsigned) ie_len);
10168 break;
10169 }
10170 redirecting->priv_to.number.plan = data[pos];
10171 break;
10173 if (ie_len != 1) {
10174 ast_log(LOG_WARNING, "Invalid private redirecting-to number presentation (%u)\n",
10175 (unsigned) ie_len);
10176 break;
10177 }
10178 redirecting->priv_to.number.presentation = data[pos];
10179 break;
10181 if (ie_len != 1) {
10182 ast_log(LOG_WARNING, "Invalid private redirecting-to number valid (%u)\n",
10183 (unsigned) ie_len);
10184 break;
10185 }
10186 redirecting->priv_to.number.valid = data[pos];
10187 break;
10188/* Private redirecting-to party id subaddress */
10190 ast_free(redirecting->priv_to.subaddress.str);
10191 redirecting->priv_to.subaddress.str = ast_malloc(ie_len + 1);
10192 if (redirecting->priv_to.subaddress.str) {
10193 memcpy(redirecting->priv_to.subaddress.str, data + pos, ie_len);
10194 redirecting->priv_to.subaddress.str[ie_len] = 0;
10195 }
10196 break;
10198 if (ie_len != 1) {
10199 ast_log(LOG_WARNING, "Invalid private redirecting-to type of subaddress (%u)\n",
10200 (unsigned) ie_len);
10201 break;
10202 }
10203 redirecting->priv_to.subaddress.type = data[pos];
10204 break;
10206 if (ie_len != 1) {
10208 "Invalid private redirecting-to subaddress odd-even indicator (%u)\n",
10209 (unsigned) ie_len);
10210 break;
10211 }
10212 redirecting->priv_to.subaddress.odd_even_indicator = data[pos];
10213 break;
10215 if (ie_len != 1) {
10216 ast_log(LOG_WARNING, "Invalid private redirecting-to subaddress valid (%u)\n",
10217 (unsigned) ie_len);
10218 break;
10219 }
10220 redirecting->priv_to.subaddress.valid = data[pos];
10221 break;
10222/* Private redirecting-to party id tag */
10224 ast_free(redirecting->priv_to.tag);
10225 redirecting->priv_to.tag = ast_malloc(ie_len + 1);
10226 if (redirecting->priv_to.tag) {
10227 memcpy(redirecting->priv_to.tag, data + pos, ie_len);
10228 redirecting->priv_to.tag[ie_len] = 0;
10229 }
10230 break;
10231/* Redirecting reason code */
10233 if (ie_len != sizeof(value)) {
10234 ast_log(LOG_WARNING, "Invalid redirecting reason (%u)\n",
10235 (unsigned) ie_len);
10236 break;
10237 }
10238 memcpy(&value, data + pos, sizeof(value));
10239 redirecting->reason.code = ntohl(value);
10240 break;
10241/* Redirecting reason string */
10243 ast_free(redirecting->reason.str);
10244 redirecting->reason.str = ast_malloc(ie_len + 1);
10245 if (redirecting->reason.str) {
10246 memcpy(redirecting->reason.str, data + pos, ie_len);
10247 redirecting->reason.str[ie_len] = 0;
10248 }
10249 break;
10250/* Redirecting orig-reason code */
10252 if (ie_len != sizeof(value)) {
10253 ast_log(LOG_WARNING, "Invalid redirecting original reason (%u)\n",
10254 (unsigned) ie_len);
10255 break;
10256 }
10257 memcpy(&value, data + pos, sizeof(value));
10258 redirecting->orig_reason.code = ntohl(value);
10259 break;
10260/* Redirecting orig-reason string */
10262 ast_free(redirecting->orig_reason.str);
10263 redirecting->orig_reason.str = ast_malloc(ie_len + 1);
10264 if (redirecting->orig_reason.str) {
10265 memcpy(redirecting->orig_reason.str, data + pos, ie_len);
10266 redirecting->orig_reason.str[ie_len] = 0;
10267 }
10268 break;
10269/* Redirecting count */
10271 if (ie_len != sizeof(value)) {
10272 ast_log(LOG_WARNING, "Invalid redirecting count (%u)\n",
10273 (unsigned) ie_len);
10274 break;
10275 }
10276 memcpy(&value, data + pos, sizeof(value));
10277 redirecting->count = ntohl(value);
10278 break;
10279/* Redirecting unknown element */
10280 default:
10281 ast_debug(1, "Unknown redirecting element: %u (%u)\n",
10282 (unsigned) ie_id, (unsigned) ie_len);
10283 break;
10284 }
10285 }
10286
10287 switch (frame_version) {
10288 case 1:
10289 /*
10290 * The other end is an earlier version that we need to adjust
10291 * for compatibility.
10292 *
10293 * The earlier version did not have the orig party id or
10294 * orig_reason value.
10295 */
10296 redirecting->from.name.valid = 1;
10298 redirecting->from.number.valid = 1;
10299 if (got_from_combined_presentation) {
10300 redirecting->from.name.presentation = from_combined_presentation;
10301 redirecting->from.number.presentation = from_combined_presentation;
10302 }
10303
10304 redirecting->to.name.valid = 1;
10306 redirecting->to.number.valid = 1;
10307 if (got_to_combined_presentation) {
10308 redirecting->to.name.presentation = to_combined_presentation;
10309 redirecting->to.number.presentation = to_combined_presentation;
10310 }
10311 break;
10312 case 2:
10313 /* The other end is at the same level as we are. */
10314 break;
10315 default:
10316 /*
10317 * The other end is newer than we are.
10318 * We need to assume that they are compatible with us.
10319 */
10320 ast_debug(1, "Redirecting frame has newer version: %u\n",
10321 (unsigned) frame_version);
10322 break;
10323 }
10324
10325 return 0;
10326}
10327
10329{
10330 unsigned char data[1024]; /* This should be large enough */
10331 size_t datalen;
10332
10333 datalen = ast_redirecting_build_data(data, sizeof(data), redirecting, update);
10334 if (datalen == (size_t) -1) {
10335 return;
10336 }
10337
10338 ast_indicate_data(chan, AST_CONTROL_REDIRECTING, data, datalen);
10339}
10340
10342{
10343 unsigned char data[1024]; /* This should be large enough */
10344 size_t datalen;
10345
10346 datalen = ast_redirecting_build_data(data, sizeof(data), redirecting, update);
10347 if (datalen == (size_t) -1) {
10348 return;
10349 }
10350
10351 ast_queue_control_data(chan, AST_CONTROL_REDIRECTING, data, datalen);
10352}
10353
10354/*!
10355 * Storage to determine if the current thread is running an intercept dialplan routine.
10356 */
10357AST_THREADSTORAGE_RAW(in_intercept_routine);
10358
10359/*!
10360 * \internal
10361 * \brief Set the current intercept dialplan routine status mode.
10362 * \since 13.14.0
10363 *
10364 * \param in_intercept_mode New intercept mode. (Non-zero if in intercept mode)
10365 */
10366static void channel_set_intercept_mode(int in_intercept_mode)
10367{
10368 int status;
10369
10370 status = ast_threadstorage_set_ptr(&in_intercept_routine,
10371 in_intercept_mode ? &(int) { 1 } : NULL);
10372 if (status) {
10373 ast_log(LOG_ERROR, "Failed to set dialplan intercept mode\n");
10374 }
10375}
10376
10378{
10379 return ast_threadstorage_get_ptr(&in_intercept_routine) ? 1 : 0;
10380}
10381
10382int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int is_frame)
10383{
10384 const char *sub;
10385 const char *sub_args;
10386 int retval;
10387
10388 ast_channel_lock(sub_chan);
10389 sub = pbx_builtin_getvar_helper(sub_chan, "CONNECTED_LINE_SEND_SUB");
10390 sub = ast_strdupa(S_OR(sub, ""));
10391 sub_args = pbx_builtin_getvar_helper(sub_chan, "CONNECTED_LINE_SEND_SUB_ARGS");
10392 sub_args = ast_strdupa(S_OR(sub_args, ""));
10393
10394 if (ast_strlen_zero(sub)) {
10395 ast_channel_unlock(sub_chan);
10396 return -1;
10397 }
10398
10399 if (is_frame) {
10400 const struct ast_frame *frame = connected_info;
10401
10403 } else {
10404 const struct ast_party_connected_line *connected = connected_info;
10405
10407 }
10408 ast_channel_unlock(sub_chan);
10409
10411 retval = ast_app_run_sub(autoservice_chan, sub_chan, sub, sub_args, 0);
10413 if (!retval) {
10414 struct ast_party_connected_line saved_connected;
10415
10416 ast_party_connected_line_init(&saved_connected);
10417 ast_channel_lock(sub_chan);
10418 ast_party_connected_line_copy(&saved_connected, ast_channel_connected(sub_chan));
10419 ast_channel_unlock(sub_chan);
10420 ast_channel_update_connected_line(sub_chan, &saved_connected, NULL);
10421 ast_party_connected_line_free(&saved_connected);
10422 }
10423
10424 return retval;
10425}
10426
10427int ast_channel_redirecting_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *redirecting_info, int is_frame)
10428{
10429 const char *sub;
10430 const char *sub_args;
10431 int retval;
10432
10433 ast_channel_lock(sub_chan);
10434 sub = pbx_builtin_getvar_helper(sub_chan, "REDIRECTING_SEND_SUB");
10435 sub = ast_strdupa(S_OR(sub, ""));
10436 sub_args = pbx_builtin_getvar_helper(sub_chan, "REDIRECTING_SEND_SUB_ARGS");
10437 sub_args = ast_strdupa(S_OR(sub_args, ""));
10438
10439 if (ast_strlen_zero(sub)) {
10440 ast_channel_unlock(sub_chan);
10441 return -1;
10442 }
10443
10444 if (is_frame) {
10445 const struct ast_frame *frame = redirecting_info;
10446
10448 } else {
10449 const struct ast_party_redirecting *redirecting = redirecting_info;
10450
10452 }
10453 ast_channel_unlock(sub_chan);
10454
10456 retval = ast_app_run_sub(autoservice_chan, sub_chan, sub, sub_args, 0);
10458 if (!retval) {
10459 struct ast_party_redirecting saved_redirecting;
10460
10461 ast_party_redirecting_init(&saved_redirecting);
10462 ast_channel_lock(sub_chan);
10463 ast_party_redirecting_copy(&saved_redirecting, ast_channel_redirecting(sub_chan));
10464 ast_channel_unlock(sub_chan);
10465 ast_channel_update_redirecting(sub_chan, &saved_redirecting, NULL);
10466 ast_party_redirecting_free(&saved_redirecting);
10467 }
10468
10469 return retval;
10470}
10471
10472static void *channel_cc_params_copy(void *data)
10473{
10474 const struct ast_cc_config_params *src = data;
10476 if (!dest) {
10477 return NULL;
10478 }
10479 ast_cc_copy_config_params(dest, src);
10480 return dest;
10481}
10482
10483static void channel_cc_params_destroy(void *data)
10484{
10485 struct ast_cc_config_params *cc_params = data;
10487}
10488
10490 .type = "Call Completion",
10491 .duplicate = channel_cc_params_copy,
10492 .destroy = channel_cc_params_destroy,
10493};
10494
10496 const struct ast_cc_config_params *base_params)
10497{
10498 struct ast_cc_config_params *cc_params;
10499 struct ast_datastore *cc_datastore;
10500
10501 if (!(cc_params = ast_cc_config_params_init())) {
10502 return -1;
10503 }
10504
10505 if (!(cc_datastore = ast_datastore_alloc(&cc_channel_datastore_info, NULL))) {
10507 return -1;
10508 }
10509
10510 if (base_params) {
10511 ast_cc_copy_config_params(cc_params, base_params);
10512 }
10513 cc_datastore->data = cc_params;
10514 ast_channel_datastore_add(chan, cc_datastore);
10515 return 0;
10516}
10517
10519{
10520 struct ast_datastore *cc_datastore;
10521
10522 if (!(cc_datastore = ast_channel_datastore_find(chan, &cc_channel_datastore_info, NULL))) {
10523 /* If we can't find the datastore, it almost definitely means that the channel type being
10524 * used has not had its driver modified to parse CC config parameters. The best action
10525 * to take here is to create the parameters on the spot with the defaults set.
10526 */
10527 if (ast_channel_cc_params_init(chan, NULL)) {
10528 return NULL;
10529 }
10530 if (!(cc_datastore = ast_channel_datastore_find(chan, &cc_channel_datastore_info, NULL))) {
10531 /* Should be impossible */
10532 return NULL;
10533 }
10534 }
10535
10536 ast_assert(cc_datastore->data != NULL);
10537 return cc_datastore->data;
10538}
10539
10540int ast_channel_get_device_name(struct ast_channel *chan, char *device_name, size_t name_buffer_length)
10541{
10542 int len = name_buffer_length;
10543 char *dash;
10544 if (!ast_channel_queryoption(chan, AST_OPTION_DEVICE_NAME, device_name, &len, 0)) {
10545 return 0;
10546 }
10547
10548 /* Dang. Do it the old-fashioned way */
10549 ast_copy_string(device_name, ast_channel_name(chan), name_buffer_length);
10550 if ((dash = strrchr(device_name, '-'))) {
10551 *dash = '\0';
10552 }
10553
10554 return 0;
10555}
10556
10557int ast_channel_get_cc_agent_type(struct ast_channel *chan, char *agent_type, size_t size)
10558{
10559 int len = size;
10560 char *slash;
10561
10563 return 0;
10564 }
10565
10567 if ((slash = strchr(agent_type, '/'))) {
10568 *slash = '\0';
10569 }
10570 return 0;
10571}
10572
10577
10579{
10580 struct ast_bridge *bridge;
10581
10582 bridge = ast_channel_internal_bridge(chan);
10583 if (bridge) {
10584 ao2_ref(bridge, +1);
10585 }
10586 return bridge;
10587}
10588
10590{
10591 return ast_channel_internal_bridge(chan) != NULL;
10592}
10593
10595{
10596 int hangup_flags = ast_channel_softhangup_internal_flag(chan);
10597 int hangup_test = hangup_flags & AST_SOFTHANGUP_ASYNCGOTO;
10598 int unbridge = ast_channel_unbridged(chan);
10599
10600 /* This function should only return true if either the unbridged flag or
10601 * the ASYNCGOTO soft hangup flag is set and when no other soft hangup
10602 * flags are set. Any other soft hangup flags being set should make it
10603 * return false.
10604 */
10605 return ((hangup_test || unbridge) && (hangup_test == hangup_flags));
10606}
10607
10609{
10610 struct ast_channel *peer;
10611 struct ast_bridge *bridge;
10612
10613 /* Get the bridge the channel is in. */
10614 ast_channel_lock(chan);
10615 bridge = ast_channel_get_bridge(chan);
10616 ast_channel_unlock(chan);
10617 if (!bridge) {
10618 return NULL;
10619 }
10620
10621 peer = ast_bridge_peer(bridge, chan);
10622 ao2_ref(bridge, -1);
10623 return peer;
10624}
10625
10627{
10628 struct ast_bridge_channel *bridge_channel;
10629
10630 bridge_channel = ast_channel_internal_bridge_channel(chan);
10631 if (bridge_channel) {
10632 ao2_ref(bridge_channel, +1);
10633 }
10634 return bridge_channel;
10635}
10636
10638{
10639 struct ast_channel *yanked_chan;
10640 struct {
10641 char *accountcode;
10642 char *exten;
10643 char *context;
10644 char *name;
10645 int amaflags;
10646 int priority;
10647 struct ast_format *readformat;
10648 struct ast_format *writeformat;
10649 } my_vars = { 0, };
10650
10651 ast_channel_lock(yankee);
10652 my_vars.accountcode = ast_strdupa(ast_channel_accountcode(yankee));
10653 my_vars.exten = ast_strdupa(ast_channel_exten(yankee));
10654 my_vars.context = ast_strdupa(ast_channel_context(yankee));
10655 my_vars.name = ast_strdupa(ast_channel_name(yankee));
10656 my_vars.amaflags = ast_channel_amaflags(yankee);
10657 my_vars.priority = ast_channel_priority(yankee);
10658 /* The priority as returned by ast_channel_yank is where the channel
10659 * should go if the dialplan is executed on it. If the channel is
10660 * already executing dialplan then the priority currently set is
10661 * where it is currently. We increment it so it becomes where it should
10662 * execute.
10663 */
10665 my_vars.priority++;
10666 }
10667 my_vars.writeformat = ao2_bump(ast_channel_writeformat(yankee));
10668 my_vars.readformat = ao2_bump(ast_channel_readformat(yankee));
10669 ast_channel_unlock(yankee);
10670
10671 /* Do not hold any channel locks while calling channel_alloc() since the function
10672 * locks the channel container when linking the new channel in. */
10673 if (!(yanked_chan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, my_vars.accountcode,
10674 my_vars.exten, my_vars.context, NULL, yankee, my_vars.amaflags,
10675 "Surrogate/%s", my_vars.name))) {
10676 ao2_cleanup(my_vars.writeformat);
10677 ao2_cleanup(my_vars.readformat);
10678 return NULL;
10679 }
10680
10681 /* Make formats okay */
10682 ast_channel_set_readformat(yanked_chan, my_vars.readformat);
10683 ast_channel_set_writeformat(yanked_chan, my_vars.writeformat);
10684 ao2_cleanup(my_vars.readformat);
10685 ao2_cleanup(my_vars.writeformat);
10686 ast_channel_priority_set(yanked_chan, my_vars.priority);
10687
10688 ast_channel_unlock(yanked_chan);
10689
10690 if (ast_channel_move(yanked_chan, yankee)) {
10691 ast_hangup(yanked_chan);
10692 return NULL;
10693 }
10694
10695 return yanked_chan;
10696}
10697
10698/*!
10699 * Mutex that prevents multiple ast_channel_move() operations
10700 * from occurring simultaneously. This is necessary since the
10701 * involved channels have to be locked and unlocked throughout
10702 * the move operation.
10703 *
10704 * The most important data being protected are the masq and masqr
10705 * data on channels. We don't want them getting criss-crossed due
10706 * to multiple moves mucking with them.
10707 */
10709
10710int ast_channel_move(struct ast_channel *dest, struct ast_channel *source)
10711{
10712 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
10714
10715 if (dest == source) {
10716 ast_log(LOG_WARNING, "Can't move channel '%s' into itself!\n",
10717 ast_channel_name(dest));
10718 return -1;
10719 }
10720
10721 ast_channel_lock_both(dest, source);
10722
10725 /* Zombies! Run! */
10727 "Can't move channel. One or both is dead (%s <-- %s)\n",
10728 ast_channel_name(dest), ast_channel_name(source));
10729 ast_channel_unlock(source);
10730 ast_channel_unlock(dest);
10731 return -1;
10732 }
10733
10734 ast_channel_masq_set(dest, source);
10735 ast_channel_masqr_set(source, dest);
10736
10737 blob = ast_json_pack("{s: s}",
10738 "newchanneluniqueid", ast_channel_uniqueid(dest));
10740
10741 ast_channel_unlock(dest);
10742 ast_channel_unlock(source);
10743
10744 channel_do_masquerade(dest, source);
10745 return 0;
10746}
10747
10748static void suppress_datastore_destroy_cb(void *data)
10749{
10750 ao2_cleanup(data);
10751}
10752
10754 .type = "suppressvoice",
10756};
10757
10758static void suppress_framehook_destroy_cb(void *data)
10759{
10760 ao2_cleanup(data);
10761}
10762
10768
10769static void suppress_framehook_fixup_cb(void *data, int framehook_id, struct ast_channel *old_chan, struct ast_channel *new_chan)
10770{
10771 struct suppress_data *suppress = data;
10772
10773 suppress->framehook_id = framehook_id;
10774}
10775
10776static struct ast_frame *suppress_framehook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
10777{
10778 struct suppress_data *suppress = data;
10779 int suppress_frame = 0;
10780
10781 if (!frame) {
10782 return NULL;
10783 }
10784
10785 if (frame->frametype != suppress->frametype) {
10786 return frame;
10787 }
10788
10790 suppress_frame = 1;
10791 } else if (event == AST_FRAMEHOOK_EVENT_WRITE && (suppress->direction & AST_MUTE_DIRECTION_WRITE)) {
10792 suppress_frame = 1;
10793 }
10794
10795 if (suppress_frame) {
10796 switch (frame->frametype) {
10797 case AST_FRAME_VOICE:
10799 ast_frfree(frame);
10800 }
10801 frame = &ast_null_frame;
10802 break;
10803 default:
10804 break;
10805 }
10806 }
10807
10808 return frame;
10809}
10810
10812{
10813 switch (frametype) {
10814 case AST_FRAME_VOICE:
10816 default:
10817 return NULL;
10818 }
10819}
10820
10821int ast_channel_suppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
10822{
10823 struct suppress_data *suppress;
10824 const struct ast_datastore_info *datastore_info = NULL;
10825 struct ast_datastore *datastore = NULL;
10826 struct ast_framehook_interface interface = {
10828 .event_cb = suppress_framehook_event_cb,
10829 .destroy_cb = suppress_framehook_destroy_cb,
10830 .chan_fixup_cb = suppress_framehook_fixup_cb,
10831 };
10832 int framehook_id;
10833
10834 if (!(datastore_info = suppress_get_datastore_information(frametype))) {
10835 ast_log(LOG_WARNING, "Attempted to suppress an unsupported frame type (%u).\n", frametype);
10836 return -1;
10837 }
10838
10839 if ((datastore = ast_channel_datastore_find(chan, datastore_info, NULL))) {
10840 suppress = datastore->data;
10841 suppress->direction |= direction;
10842 return 0;
10843 }
10844
10845 if (!(suppress = ao2_alloc(sizeof(*suppress), NULL))) {
10846 ast_log(LOG_WARNING, "Failed to allocate data while attempting to suppress a stream.\n");
10847 return -1;
10848 }
10849
10850 suppress->frametype = frametype;
10851 suppress->direction |= direction;
10852
10853 interface.data = suppress;
10854
10855 framehook_id = ast_framehook_attach(chan, &interface);
10856 if (framehook_id < 0) {
10857 /* Hook attach failed. Get rid of the evidence. */
10858 ast_log(LOG_WARNING, "Failed to attach framehook while attempting to suppress a stream.\n");
10859 ao2_ref(suppress, -1);
10860 return -1;
10861 }
10862
10863 /* One ref for the framehook */
10864 ao2_ref(suppress, +1);
10865
10866 suppress->framehook_id = framehook_id;
10867
10868 if (!(datastore = ast_datastore_alloc(datastore_info, NULL))) {
10869 ast_log(LOG_WARNING, "Failed to allocate datastore while attempting to suppress a stream.\n");
10870 ast_framehook_detach(chan, framehook_id);
10871 ao2_ref(suppress, -1);
10872 return -1;
10873 }
10874
10875 /* the ref provided by the allocation is taken by the datastore */
10876 datastore->data = suppress;
10877
10878 ast_channel_datastore_add(chan, datastore);
10879
10880 return 0;
10881}
10882
10883int ast_channel_unsuppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
10884{
10885 const struct ast_datastore_info *datastore_info = NULL;
10886 struct ast_datastore *datastore = NULL;
10887 struct suppress_data *suppress;
10888
10889 if (!(datastore_info = suppress_get_datastore_information(frametype))) {
10890 ast_log(LOG_WARNING, "Attempted to unsuppress an unsupported frame type (%u).\n", frametype);
10891 return -1;
10892 }
10893
10894 if (!(datastore = ast_channel_datastore_find(chan, datastore_info, NULL))) {
10895 /* Nothing to do! */
10896 return 0;
10897 }
10898
10899 suppress = datastore->data;
10900
10901 suppress->direction &= ~(direction);
10902
10903 if (suppress->direction == 0) {
10904 /* Nothing left to suppress. Bye! */
10905 ast_framehook_detach(chan, suppress->framehook_id);
10906 ast_channel_datastore_remove(chan, datastore);
10907 ast_datastore_free(datastore);
10908 }
10909
10910 return 0;
10911}
10912
10913void ast_channel_end_dtmf(struct ast_channel *chan, char digit, struct timeval start, const char *why)
10914{
10915 int dead;
10916 long duration;
10917
10918 ast_channel_lock(chan);
10921 & ~AST_SOFTHANGUP_ASYNCGOTO);
10922 ast_channel_unlock(chan);
10923 if (dead) {
10924 /* Channel is a zombie or a real hangup. */
10925 return;
10926 }
10927
10928 duration = ast_tvdiff_ms(ast_tvnow(), start);
10929 if (duration < option_dtmfminduration) {
10930 duration = option_dtmfminduration;
10931 }
10932 ast_senddigit_end(chan, digit, duration);
10933 ast_log(LOG_DTMF, "DTMF end '%c' simulated on %s due to %s, duration %ld ms\n",
10934 digit, ast_channel_name(chan), why, duration);
10935}
10936
10937static void features_destroy(void *obj)
10938{
10940}
10941
10943 .type = "bridge-features",
10944 .destroy = features_destroy,
10945};
10946
10948{
10949 struct ast_datastore *datastore;
10950
10952 if (!datastore) {
10953 return NULL;
10954 }
10955 return datastore->data;
10956}
10957
10958static int channel_feature_hooks_set_full(struct ast_channel *chan, struct ast_bridge_features *features, int replace)
10959{
10960 struct ast_datastore *datastore;
10961 struct ast_bridge_features *ds_features;
10962
10964 if (datastore) {
10965 ds_features = datastore->data;
10966 if (replace) {
10967 ast_bridge_features_cleanup(ds_features);
10968 ast_bridge_features_init(ds_features);
10969 }
10970 if (features) {
10971 ast_bridge_features_merge(ds_features, features);
10972 }
10973 return 0;
10974 }
10975
10977 if (!datastore) {
10978 return -1;
10979 }
10980
10981 ds_features = ast_bridge_features_new();
10982 if (!ds_features) {
10983 ast_datastore_free(datastore);
10984 return -1;
10985 }
10986
10987 if (features) {
10988 ast_bridge_features_merge(ds_features, features);
10989 }
10990 datastore->data = ds_features;
10991 ast_channel_datastore_add(chan, datastore);
10992 return 0;
10993}
10994
10996{
10997 return channel_feature_hooks_set_full(chan, features, 0);
10998}
10999
11001{
11002 return channel_feature_hooks_set_full(chan, features, 1);
11003}
11004
11006{
11008}
11009
11011 struct ast_stream_topology *topology, void *change_source)
11012{
11013 int res;
11014
11015 ast_assert(chan != NULL);
11016 ast_assert(topology != NULL);
11017
11018 ast_channel_lock(chan);
11020 ast_channel_unlock(chan);
11021 return -1;
11022 }
11023
11025 ast_debug(2, "%s: Topologies already match. Current: %s Requested: %s\n",
11026 ast_channel_name(chan),
11028 ast_str_tmp(256, ast_stream_topology_to_str(topology, &STR_TMP)));
11029 ast_channel_unlock(chan);
11030 return 0;
11031 }
11032
11034
11035 res = ast_channel_tech(chan)->indicate(chan, AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE, topology, sizeof(topology));
11036 ast_channel_unlock(chan);
11037 return res;
11038}
11039
11041{
11042 ast_assert(chan != NULL);
11043 ast_assert(topology != NULL);
11044
11046 return -1;
11047 }
11048
11049 return ast_channel_tech(chan)->indicate(chan, AST_CONTROL_STREAM_TOPOLOGY_CHANGED, topology, sizeof(topology));
11050}
11051
11053{
11054 int res;
11056
11057 ast_assert(chan != NULL);
11058
11059 if (!ast_channel_is_multistream(chan)) {
11060 return -1;
11061 }
11062
11063 ast_channel_lock(chan);
11065 res = ast_queue_frame(chan, &f);
11066 ast_channel_unlock(chan);
11067
11068 return res;
11069}
11070
11071void ast_channel_set_flag(struct ast_channel *chan, unsigned int flag)
11072{
11073 ast_channel_lock(chan);
11075 ast_channel_unlock(chan);
11076}
11077
11078void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
11079{
11080 ast_channel_lock(chan);
11082 ast_channel_unlock(chan);
11083}
11084
Prototypes for public functions only of internal interest,.
void ast_jb_destroy(struct ast_channel *chan)
Destroys jitterbuffer on a channel.
void ast_cli_unregister_multiple(void)
Definition ael_main.c:408
@ 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:1772
enum queue_result id
Definition app_queue.c:1771
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
#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
static int connected
Definition cdr_pgsql.c:73
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[]
static int indicate(void *data)
static int transfer(void *data)
static int hangup(void *data)
static int answer(void *data)
Definition chan_pjsip.c:687
static int call(void *data)
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:1691
static void channels_shutdown(void)
Definition channel.c:7983
static void channel_do_masquerade(struct ast_channel *original, struct ast_channel *clonechan)
Masquerade a channel.
Definition channel.c:6857
int ast_say_number(struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
says a number
Definition channel.c:8279
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:7968
int ast_senddigit_mf_begin(struct ast_channel *chan, char digit)
Send an MF digit to a channel.
Definition channel.c:4830
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition channel.c:3172
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:11010
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:10913
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:2071
struct ast_channel * ast_channel_get_by_exten(const char *exten, const char *context)
Find a channel by extension and context.
Definition channel.c:1429
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:6371
static int indicate_connected_line(struct ast_channel *chan, const void *data, size_t datalen)
Definition channel.c:4395
void ast_party_name_init(struct ast_party_name *init)
Initialize the given name structure.
Definition channel.c:1577
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:4712
static void generator_write_format_change(struct ast_channel *chan)
Definition channel.c:2901
enum ast_channel_error ast_channel_errno(void)
Get error code for latest channel operation.
Definition channel.c:11005
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition channel.c:2948
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:1335
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:1936
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:10540
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:2985
static int set_format(struct ast_channel *chan, struct ast_format_cap *cap_set, const int direction, int interleaved_stereo)
Definition channel.c:5588
int ast_auto_answer(struct ast_channel *chan)
Answer a channel, if it's not already answered.
Definition channel.c:2809
static int silence_generator_generate(struct ast_channel *chan, void *data, int len, int samples)
Definition channel.c:8179
void ast_party_redirecting_init(struct ast_party_redirecting *init)
Initialize the given redirecting structure.
Definition channel.c:2108
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:5139
int ast_call(struct ast_channel *chan, const char *addr, int timeout)
Make a call.
Definition channel.c:6456
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:9163
static void handle_cause(int cause, int *outstate)
Definition channel.c:5844
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
Clear a flag on a channel.
Definition channel.c:11078
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition channel.c:2375
static void send_dtmf_begin_event(struct ast_channel *chan, enum DtmfDirection direction, const char digit)
Definition channel.c:3367
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:5893
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition channel.c:2384
void ast_party_id_init(struct ast_party_id *init)
Initialize the given party id structure.
Definition channel.c:1743
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:5483
#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:2422
static void clone_variables(struct ast_channel *original, struct ast_channel *clonechan)
Clone channel variables from 'clone' channel into 'original' channel.
Definition channel.c:6822
static char * handle_cli_core_show_channeltype(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Show details about a channel driver - CLI command.
Definition channel.c:326
struct ast_channel_iterator * ast_channel_iterator_by_name_new(const char *name, size_t name_len)
Create a new channel iterator based on name.
Definition channel.c:1367
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:8303
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:7896
int ast_prod(struct ast_channel *chan)
Send empty audio to prime a channel driver.
Definition channel.c:4995
int __ast_answer(struct ast_channel *chan, unsigned int delay)
Answer a channel, with a selectable delay before returning.
Definition channel.c:2693
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:3520
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:6636
void ast_party_number_init(struct ast_party_number *init)
Initialize the given number structure.
Definition channel.c:1630
static void suppress_framehook_fixup_cb(void *data, int framehook_id, struct ast_channel *old_chan, struct ast_channel *new_chan)
Definition channel.c:10769
void ast_hangup(struct ast_channel *chan)
Hangup a channel.
Definition channel.c:2538
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:7371
static int tonepair_generator(struct ast_channel *chan, void *data, int len, int samples)
Definition channel.c:7541
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:7778
void ast_moh_cleanup(struct ast_channel *chan)
Clean up music on hold state on a given channel.
Definition channel.c:7794
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:2636
int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders)
Reads multiple digits.
Definition channel.c:6553
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:6630
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition channel.c:1348
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:10608
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:6493
static int indicate_redirecting(struct ast_channel *chan, const void *data, size_t datalen)
Definition channel.c:4450
static void(* ast_moh_cleanup_ptr)(struct ast_channel *)
Definition channel.c:7760
static int set_security_requirements(const struct ast_channel *requestor, struct ast_channel *out)
Definition channel.c:6174
static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f)
Definition channel.c:3421
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:1705
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:8352
int ast_senddigit_begin(struct ast_channel *chan, char digit)
Send a DTMF digit to a channel.
Definition channel.c:4869
static int channel_has_external_vars(struct external_vars *channelvars)
Definition channel.c:7829
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
Definition channel.c:1807
struct ast_channel * ast_channel_get_by_uniqueid(const char *uniqueid)
Find a channel by a uniqueid.
Definition channel.c:1441
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:8540
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:1638
static void moh_cleanup(struct ast_channel *chan)
Definition channel.c:7799
static int namedgroup_cmp_cb(void *obj, void *arg, int flags)
Comparison function used for named group container.
Definition channel.c:7671
void ast_channel_unlink(struct ast_channel *chan)
Remove a channel from the global channels container.
Definition channel.c:10573
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:1660
void ast_party_subaddress_init(struct ast_party_subaddress *init)
Initialize the given subaddress structure.
Definition channel.c:1683
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:2521
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:6558
static const struct ast_datastore_info suppress_datastore_voice
Definition channel.c:10753
void ast_party_connected_line_free(struct ast_party_connected_line *doomed)
Destroy the connected line information contents.
Definition channel.c:2058
static const struct ast_datastore_info plc_ds_info
Definition channel.c:5043
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:2833
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:7872
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:4746
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:8392
DtmfDirection
Definition channel.c:3350
@ DTMF_SENT
Definition channel.c:3352
@ DTMF_RECEIVED
Definition channel.c:3351
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:5775
int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
Definition channel.c:7594
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:7384
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:4969
#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:2152
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:6715
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:7454
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:7973
static void queue_dtmf_readq(struct ast_channel *chan, struct ast_frame *f)
Definition channel.c:3475
static void * channel_cc_params_copy(void *data)
Definition channel.c:10472
static int deactivate_silence_generator(struct ast_channel *chan)
Definition channel.c:8231
static void tonepair_release(struct ast_channel *chan, void *params)
Definition channel.c:7499
static struct varshead * channel_get_external_vars(struct external_vars *channelvars, struct ast_channel *chan)
Definition channel.c:7921
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:7434
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition channel.c:7788
void ast_party_id_free(struct ast_party_id *doomed)
Destroy the party id contents.
Definition channel.c:1797
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:10811
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:1713
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:2977
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:11040
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:5816
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:1774
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition channel.c:1387
void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
adds a list of channel variables to a channel
Definition channel.c:8159
struct ast_namedgroups * ast_ref_namedgroups(struct ast_namedgroups *groups)
Definition channel.c:7750
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:11000
static void silence_generator_release(struct ast_channel *chan, void *data)
Definition channel.c:8174
static int namedgroup_hash_cb(const void *obj, const int flags)
Hashing function used for named group container.
Definition channel.c:7680
struct ast_silence_generator * ast_channel_start_silence_generator(struct ast_channel *chan)
Starts a silence generator on the given channel.
Definition channel.c:8208
int internal_channel_set_current_storage_driver(const char *driver_name)
Definition channel.c:8023
static int chancount
Definition channel.c:96
static void(* ast_moh_stop_ptr)(struct ast_channel *)
Definition channel.c:7759
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:2017
int ast_recvchar(struct ast_channel *chan, int timeout)
Receives a text character from a channel.
Definition channel.c:4701
static struct external_vars ari_vars
Definition channel.c:7817
struct ast_channel * ast_channel_yank(struct ast_channel *yankee)
Gain control of a channel in the system.
Definition channel.c:10637
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame.
Definition channel.c:1288
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:10495
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:8285
void ast_channel_close_storage(void)
Definition channel.c:7978
int ast_channel_get_intercept_mode(void)
Am I currently running an intercept dialplan routine.
Definition channel.c:10377
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:2040
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:5144
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:8254
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:3182
static int should_skip_dtmf(struct ast_channel *chan)
Determine whether or not we should ignore DTMF in the readq.
Definition channel.c:3493
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:1914
const char * ast_channel_get_current_storage_driver_name(void)
Get the name of the current channel storage driver.
Definition channel.c:8017
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:1972
int ast_setstate(struct ast_channel *chan, enum ast_channel_state state)
Change the state of a channel.
Definition channel.c:7398
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:2088
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:8134
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
Inherit datastores from a parent to a child.
Definition channel.c:2358
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:1328
static void deactivate_generator_nolock(struct ast_channel *chan)
Definition channel.c:2875
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:6429
void ast_deactivate_generator(struct ast_channel *chan)
Definition channel.c:2890
static void channel_cc_params_destroy(void *data)
Definition channel.c:10483
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:1906
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:1356
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:5036
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:7762
char * ast_print_group(char *buf, int buflen, ast_group_t group)
Print call group and pickup group —.
Definition channel.c:8075
static void varshead_dtor(void *obj)
Destructor for lists of variables.
Definition channel.c:7886
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:1399
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:2082
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:5780
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:1993
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:10821
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:10995
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:1484
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:6737
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:8297
int ast_undestroyed_channels(void)
Definition channel.c:504
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition channel.c:4250
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:2049
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:1295
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:10947
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:9137
int ast_senddigit_mf_end(struct ast_channel *chan)
End sending an MF digit to a channel.
Definition channel.c:4938
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:10710
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:10341
void ast_party_redirecting_reason_init(struct ast_party_redirecting_reason *init)
Initialize the given redirecting reason structure.
Definition channel.c:2065
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:4982
int ast_sendtext(struct ast_channel *chan, const char *text)
Sends text to a channel.
Definition channel.c:4804
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:6169
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:4255
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:1985
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:1766
void ast_party_name_free(struct ast_party_name *doomed)
Destroy the party name contents.
Definition channel.c:1624
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:7877
void ast_party_dialed_free(struct ast_party_dialed *doomed)
Destroy the dialed party contents.
Definition channel.c:1957
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:8309
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:7346
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:10427
void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
Inherits channel variable from parent to child channel.
Definition channel.c:6771
static ast_mutex_t channel_move_lock
Definition channel.c:10708
static int namedgroup_match(void *obj, void *arg, int flags)
Definition channel.c:8124
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:10489
static int channel_feature_hooks_set_full(struct ast_channel *chan, struct ast_bridge_features *features, int replace)
Definition channel.c:10958
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:4265
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:6623
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:5971
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:2139
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
Definition channel.c:5757
static void free_external_channelvars(struct external_vars *channelvars)
Definition channel.c:7819
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:1599
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:8291
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame for channel.
Definition channel.c:1212
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:8829
void ast_party_caller_free(struct ast_party_caller *doomed)
Destroy the caller party contents.
Definition channel.c:2001
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:4367
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:1922
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:6354
static const struct set_format_access set_format_access_write
Definition channel.c:5577
struct ast_namedgroups * ast_get_namedgroups(const char *s)
Create an ast_namedgroups set with group names from comma separated string.
Definition channel.c:7687
static struct ast_generator tonepair
Definition channel.c:7588
static int generator_force(const void *data)
Definition channel.c:2913
static void call_forward_inherit(struct ast_channel *new_chan, struct ast_channel *parent, struct ast_channel *orig)
Definition channel.c:5865
static void adjust_frame_for_plc(struct ast_channel *chan, struct ast_frame *frame, struct ast_datastore *datastore)
Definition channel.c:5048
void ast_uninstall_music_functions(void)
Definition channel.c:7771
static void channel_set_intercept_mode(int in_intercept_mode)
Definition channel.c:10366
int ast_channels_init(void)
Definition channel.c:8045
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:3236
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:8315
static struct external_vars ami_vars
Definition channel.c:7816
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:1607
static void features_destroy(void *obj)
Definition channel.c:10937
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:1736
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
Definition channel.c:10589
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:1944
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:5821
struct ast_frame * ast_read_noaudio(struct ast_channel *chan)
Reads a frame, returning AST_FRAME_NULL frame if audio.
Definition channel.c:4260
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:2818
struct ast_bridge * ast_channel_get_bridge(const struct ast_channel *chan)
Get the bridge associated with a channel.
Definition channel.c:10578
static void suppress_datastore_destroy_cb(void *data)
Definition channel.c:10748
struct ast_channel * ast_channel_release(struct ast_channel *chan)
Unlink and release reference to a channel.
Definition channel.c:1570
int ast_channel_open_storage()
Definition channel.c:7996
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:9312
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:2496
void ast_channel_set_flag(struct ast_channel *chan, unsigned int flag)
Set a flag on a channel.
Definition channel.c:11071
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup a channel, lock.
Definition channel.c:2461
static void send_flash_event(struct ast_channel *chan)
Definition channel.c:3411
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:5012
static void send_dtmf_end_event(struct ast_channel *chan, enum DtmfDirection direction, const char digit, long duration_ms)
Definition channel.c:3382
void ast_channel_name_to_dial_string(char *channel_name)
Removes the trailing identifiers from a channel name string.
Definition channel.c:6839
void ast_channel_hangupcause_hash_set(struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen)
Sets the HANGUPCAUSE hash and optionally the SIP_CAUSE hash on the given channel.
Definition channel.c:4340
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:1273
static void destroy_hooks(struct ast_channel *chan)
Definition channel.c:2527
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:10382
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:10328
int ast_channel_has_manager_vars(void)
Return whether or not any manager variables have been set.
Definition channel.c:7840
void ast_party_id_reset(struct ast_party_id *id)
Destroy and initialize the given party id structure.
Definition channel.c:1882
void ast_party_id_invalidate(struct ast_party_id *id)
Invalidate all components of the given party id.
Definition channel.c:1875
int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
Queue a hold frame.
Definition channel.c:1248
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:8741
int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel.
Definition channel.c:4919
int ast_channel_has_ari_vars(void)
Return whether or not any ARI variables have been set.
Definition channel.c:7845
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:8321
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:1888
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:11052
#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:1652
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:3177
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:5798
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:1751
void ast_party_number_free(struct ast_party_number *doomed)
Destroy the party number contents.
Definition channel.c:1677
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition channel.c:2008
int ast_channel_get_up_time(struct ast_channel *chan)
Obtain how long it has been since the channel was answered.
Definition channel.c:2843
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:10594
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:9523
static int indicate_data_internal(struct ast_channel *chan, int _condition, const void *data, size_t datalen)
Definition channel.c:4464
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:8327
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:10626
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:4947
static struct ast_generator silence_generator
Definition channel.c:8198
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:1554
static void suppress_framehook_destroy_cb(void *data)
Definition channel.c:10758
static void channel_set_external_vars(struct external_vars *channelvars, size_t varc, char **vars)
Definition channel.c:7850
int ast_transfer(struct ast_channel *chan, char *dest)
Transfer a call to dest, if the channel supports transfer.
Definition channel.c:6480
@ AST_REDIRECTING_FROM_NAME_PRESENTATION
Definition channel.c:9209
@ AST_REDIRECTING_TO_NAME
Definition channel.c:9187
@ AST_REDIRECTING_VERSION
Definition channel.c:9202
@ AST_REDIRECTING_PRIV_FROM_NAME_VALID
Definition channel.c:9249
@ AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN
Definition channel.c:9254
@ AST_REDIRECTING_TO_TAG
Definition channel.c:9201
@ AST_REDIRECTING_FROM_NUMBER_PLAN
Definition channel.c:9184
@ AST_REDIRECTING_PRIV_TO_NAME_VALID
Definition channel.c:9236
@ AST_REDIRECTING_ORIG_TAG
Definition channel.c:9229
@ AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN
Definition channel.c:9267
@ AST_REDIRECTING_REASON_CODE
Definition channel.c:9190
@ AST_REDIRECTING_PRIV_TO_NUMBER_VALID
Definition channel.c:9233
@ AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION
Definition channel.c:9234
@ AST_REDIRECTING_ORIG_REASON_CODE
Definition channel.c:9230
@ AST_REDIRECTING_TO_NAME_PRESENTATION
Definition channel.c:9214
@ AST_REDIRECTING_PRIV_TO_NAME
Definition channel.c:9235
@ AST_REDIRECTING_PRIV_ORIG_NAME_VALID
Definition channel.c:9262
@ AST_REDIRECTING_ORIG_NUMBER_VALID
Definition channel.c:9218
@ AST_REDIRECTING_FROM_NUMBER_PRESENTATION
Definition channel.c:9211
@ AST_REDIRECTING_ORIG_SUBADDRESS_VALID
Definition channel.c:9228
@ AST_REDIRECTING_FROM_NUMBER_VALID
Definition channel.c:9210
@ AST_REDIRECTING_TO_NAME_VALID
Definition channel.c:9212
@ AST_REDIRECTING_PRIV_FROM_NAME
Definition channel.c:9248
@ AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN
Definition channel.c:9198
@ AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN
Definition channel.c:9227
@ AST_REDIRECTING_PRIV_FROM_SUBADDRESS_TYPE
Definition channel.c:9253
@ AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID
Definition channel.c:9242
@ AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN
Definition channel.c:9241
@ AST_REDIRECTING_ORIG_NAME_CHAR_SET
Definition channel.c:9223
@ AST_REDIRECTING_PRIV_FROM_SUBADDRESS
Definition channel.c:9252
@ AST_REDIRECTING_TO_NUMBER_PLAN
Definition channel.c:9188
@ AST_REDIRECTING_PRIV_TO_NUMBER
Definition channel.c:9231
@ AST_REDIRECTING_PRIV_FROM_NUMBER_VALID
Definition channel.c:9246
@ AST_REDIRECTING_ORIG_NAME
Definition channel.c:9221
@ AST_REDIRECTING_ORIG_SUBADDRESS
Definition channel.c:9225
@ AST_REDIRECTING_FROM_TAG
Definition channel.c:9200
@ AST_REDIRECTING_PRIV_ORIG_NUMBER_PLAN
Definition channel.c:9259
@ AST_REDIRECTING_TO_NUMBER
Definition channel.c:9186
@ AST_REDIRECTING_ORIG_SUBADDRESS_TYPE
Definition channel.c:9226
@ AST_REDIRECTING_FROM_NAME_CHAR_SET
Definition channel.c:9208
@ AST_REDIRECTING_PRIV_FROM_TAG
Definition channel.c:9256
@ AST_REDIRECTING_FROM_ID_PRESENTATION
Definition channel.c:9185
@ AST_REDIRECTING_PRIV_FROM_NUMBER
Definition channel.c:9244
@ AST_REDIRECTING_PRIV_TO_NUMBER_PLAN
Definition channel.c:9232
@ AST_REDIRECTING_TO_NUMBER_VALID
Definition channel.c:9215
@ AST_REDIRECTING_FROM_SUBADDRESS_VALID
Definition channel.c:9195
@ AST_REDIRECTING_FROM_NAME_VALID
Definition channel.c:9207
@ AST_REDIRECTING_PRIV_TO_NAME_CHAR_SET
Definition channel.c:9237
@ AST_REDIRECTING_PRIV_ORIG_TAG
Definition channel.c:9269
@ AST_REDIRECTING_FROM_SUBADDRESS_TYPE
Definition channel.c:9193
@ AST_REDIRECTING_PRIV_TO_TAG
Definition channel.c:9243
@ AST_REDIRECTING_COUNT
Definition channel.c:9191
@ AST_REDIRECTING_FROM_SUBADDRESS
Definition channel.c:9192
@ AST_REDIRECTING_PRIV_ORIG_NAME_CHAR_SET
Definition channel.c:9263
@ AST_REDIRECTING_ORIG_NAME_VALID
Definition channel.c:9222
@ AST_REDIRECTING_TO_ID_PRESENTATION
Definition channel.c:9189
@ AST_REDIRECTING_PRIV_FROM_NUMBER_PLAN
Definition channel.c:9245
@ AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION
Definition channel.c:9238
@ AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION
Definition channel.c:9247
@ AST_REDIRECTING_PRIV_FROM_NAME_PRESENTATION
Definition channel.c:9251
@ AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_TYPE
Definition channel.c:9266
@ AST_REDIRECTING_ORIG_REASON_STR
Definition channel.c:9271
@ AST_REDIRECTING_ORIG_NAME_PRESENTATION
Definition channel.c:9224
@ AST_REDIRECTING_PRIV_FROM_NAME_CHAR_SET
Definition channel.c:9250
@ AST_REDIRECTING_ORIG_NUMBER
Definition channel.c:9217
@ AST_REDIRECTING_PRIV_ORIG_NAME
Definition channel.c:9261
@ AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE
Definition channel.c:9240
@ AST_REDIRECTING_PRIV_ORIG_NUMBER_VALID
Definition channel.c:9258
@ AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION
Definition channel.c:9260
@ AST_REDIRECTING_TO_SUBADDRESS_VALID
Definition channel.c:9199
@ AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_VALID
Definition channel.c:9268
@ AST_REDIRECTING_TO_SUBADDRESS_TYPE
Definition channel.c:9197
@ AST_REDIRECTING_REASON_STR
Definition channel.c:9270
@ AST_REDIRECTING_FROM_NAME
Definition channel.c:9183
@ AST_REDIRECTING_PRIV_ORIG_NUMBER
Definition channel.c:9257
@ AST_REDIRECTING_PRIV_FROM_SUBADDRESS_VALID
Definition channel.c:9255
@ AST_REDIRECTING_ORIG_NUMBER_PRESENTATION
Definition channel.c:9220
@ AST_REDIRECTING_PRIV_TO_SUBADDRESS
Definition channel.c:9239
@ AST_REDIRECTING_PRIV_ORIG_NAME_PRESENTATION
Definition channel.c:9264
@ AST_REDIRECTING_TO_NUMBER_PRESENTATION
Definition channel.c:9216
@ AST_REDIRECTING_FROM_NUMBER
Definition channel.c:9182
@ AST_REDIRECTING_ORIG_NUMBER_PLAN
Definition channel.c:9219
@ AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN
Definition channel.c:9194
@ AST_REDIRECTING_PRIV_ORIG_SUBADDRESS
Definition channel.c:9265
@ AST_REDIRECTING_TO_SUBADDRESS
Definition channel.c:9196
@ AST_REDIRECTING_TO_NAME_CHAR_SET
Definition channel.c:9213
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:8621
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:10883
void ast_party_redirecting_free(struct ast_party_redirecting *doomed)
Destroy the redirecting information contents.
Definition channel.c:2165
#define FORMAT
static void free_translation(struct ast_channel *clonechan)
Definition channel.c:2484
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
Definition channel.c:2416
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:5127
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:8337
int ast_softhangup_nolock(struct ast_channel *chan, int cause)
Softly hangup a channel, don't lock.
Definition channel.c:2448
enum ama_flags ast_channel_string2amaflag(const char *flag)
Convert a string to a detail record AMA flag.
Definition channel.c:4354
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:9279
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:4648
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:10776
static int attribute_const is_visible_indication(enum ast_control_frame_type condition)
Definition channel.c:4275
static void ast_channel_destructor(void *obj)
Free a channel structure.
Definition channel.c:2180
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:6434
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:8466
@ AST_CONNECTED_LINE_NUMBER_VALID
Definition channel.c:8724
@ AST_CONNECTED_LINE_SOURCE
Definition channel.c:8710
@ AST_CONNECTED_LINE_PRIV_SUBADDRESS_VALID
Definition channel.c:8737
@ AST_CONNECTED_LINE_PRIV_SUBADDRESS_ODD_EVEN
Definition channel.c:8736
@ AST_CONNECTED_LINE_PRIV_NAME_VALID
Definition channel.c:8731
@ AST_CONNECTED_LINE_PRIV_SUBADDRESS_TYPE
Definition channel.c:8735
@ AST_CONNECTED_LINE_PRIV_NUMBER_PRESENTATION
Definition channel.c:8729
@ AST_CONNECTED_LINE_NAME_CHAR_SET
Definition channel.c:8722
@ AST_CONNECTED_LINE_SUBADDRESS_VALID
Definition channel.c:8714
@ AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN
Definition channel.c:8713
@ AST_CONNECTED_LINE_SUBADDRESS
Definition channel.c:8711
@ AST_CONNECTED_LINE_PRIV_NUMBER_PLAN
Definition channel.c:8727
@ AST_CONNECTED_LINE_NUMBER
Definition channel.c:8706
@ AST_CONNECTED_LINE_ID_PRESENTATION
Definition channel.c:8709
@ AST_CONNECTED_LINE_PRIV_NAME_PRESENTATION
Definition channel.c:8733
@ AST_CONNECTED_LINE_PRIV_NAME
Definition channel.c:8730
@ AST_CONNECTED_LINE_TAG
Definition channel.c:8715
@ AST_CONNECTED_LINE_PRIV_NUMBER_VALID
Definition channel.c:8728
@ AST_CONNECTED_LINE_NUMBER_PRESENTATION
Definition channel.c:8725
@ AST_CONNECTED_LINE_PRIV_NAME_CHAR_SET
Definition channel.c:8732
@ AST_CONNECTED_LINE_NAME
Definition channel.c:8707
@ AST_CONNECTED_LINE_NAME_PRESENTATION
Definition channel.c:8723
@ AST_CONNECTED_LINE_SUBADDRESS_TYPE
Definition channel.c:8712
@ AST_CONNECTED_LINE_PRIV_SUBADDRESS
Definition channel.c:8734
@ AST_CONNECTED_LINE_PRIV_TAG
Definition channel.c:8738
@ AST_CONNECTED_LINE_NAME_VALID
Definition channel.c:8721
@ AST_CONNECTED_LINE_PRIV_NUMBER
Definition channel.c:8726
@ AST_CONNECTED_LINE_NUMBER_PLAN
Definition channel.c:8708
@ AST_CONNECTED_LINE_VERSION
Definition channel.c:8716
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:5519
static void apply_plc(struct ast_channel *chan, struct ast_frame *frame)
Definition channel.c:5101
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:6439
int ast_channel_supports_html(struct ast_channel *chan)
Checks for HTML support on a channel.
Definition channel.c:6618
int ast_queue_answer(struct ast_channel *chan, const struct ast_stream_topology *topology)
Queue an ANSWER control frame with topology.
Definition channel.c:1303
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:7510
struct ast_namedgroups * ast_unref_namedgroups(struct ast_namedgroups *groups)
Definition channel.c:7744
void ast_party_subaddress_free(struct ast_party_subaddress *doomed)
Destroy the party subaddress contents.
Definition channel.c:1730
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:2625
static void * silence_generator_alloc(struct ast_channel *chan, void *data)
Definition channel.c:8168
int ast_channel_get_duration(struct ast_channel *chan)
Obtain how long the channel since the channel was created.
Definition channel.c:2828
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:9150
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:2031
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:3533
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:6214
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:2853
static int kill_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
Definition channel.c:413
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:1565
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:8344
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:1416
int ast_channel_defer_dtmf(struct ast_channel *chan)
Set defer DTMF flag on channel.
Definition channel.c:1314
static const struct ast_datastore_info bridge_features_info
Definition channel.c:10942
int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
Definition channel.c:7612
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition channel.c:2803
void ast_change_name(struct ast_channel *chan, const char *newname)
Change channel name.
Definition channel.c:6759
int ast_waitfor(struct ast_channel *c, int ms)
Wait for input on a channel.
Definition channel.c:3159
ast_group_t ast_get_group(const char *s)
Definition channel.c:7630
static const struct set_format_access set_format_access_read
Definition channel.c:5566
int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
Bridge two channels together (early)
Definition channel.c:7424
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition channel.c:4270
static const char * dtmf_direction_to_string(enum DtmfDirection direction)
Definition channel.c:3355
int ast_is_deferrable_frame(const struct ast_frame *frame)
Should we keep this frame for later?
Definition channel.c:1453
struct ast_channel_iterator * ast_channel_iterator_all_new(void)
Create a new channel iterator.
Definition channel.c:1379
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait, look for hangups.
Definition channel.c:1560
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:6349
static void send_wink_event(struct ast_channel *chan)
Definition channel.c:3416
static int(* ast_moh_start_ptr)(struct ast_channel *, const char *, const char *)
Definition channel.c:7758
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:10518
#define DEFAULT_AMA_FLAGS
Definition channel.c:111
int ast_raw_answer(struct ast_channel *chan)
Answer a channel.
Definition channel.c:2688
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:2121
char * ast_print_namedgroups(struct ast_str **buf, struct ast_namedgroups *group)
Print named call groups and named pickup groups.
Definition channel.c:8100
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:1585
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:10557
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:2389
void ast_party_redirecting_reason_free(struct ast_party_redirecting_reason *doomed)
Destroy the redirecting reason contents.
Definition channel.c:2102
#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:1964
void ast_tonepair_stop(struct ast_channel *chan)
Definition channel.c:7607
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:3154
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:2515
static void ast_dummy_channel_destructor(void *obj)
Free a dummy channel structure.
Definition channel.c:2323
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_channel_tech_hangupcause(const struct ast_channel *chan)
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
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:2931
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:2982
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:4903
@ AST_CHANNEL_ERROR_ID_EXISTS
Definition channel.h:4907
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:3007
void ast_channel_generatordata_set(struct ast_channel *chan, void *value)
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition channel.h:2989
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
void ast_channel_softhangup_internal_flag_set(struct ast_channel *chan, int value)
ast_callid ast_channel_callid(const struct ast_channel *chan)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
const char * ast_channel_accountcode(const struct ast_channel *chan)
void ast_channel_internal_swap_endpoints(struct ast_channel *a, struct ast_channel *b)
Swap endpoints between two channels.
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:4822
void ast_channel_endpoint_set(struct ast_channel *chan, struct ast_endpoint *endpoint)
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:2984
const char * ast_channel_parkinglot(const struct ast_channel *chan)
ast_channel_adsicpe
Definition channel.h:888
void ast_channel_internal_swap_topics(struct ast_channel *a, struct ast_channel *b)
Swap topics beteween two channels.
#define AST_ALERT_FD
Definition channel.h:202
const char * ast_channel_peeraccount(const struct ast_channel *chan)
struct timeval ast_channel_creationtime(struct ast_channel *chan)
struct ast_bridge_channel * ast_channel_internal_bridge_channel(const struct ast_channel *chan)
struct ast_framehook_list * ast_channel_framehooks(const struct ast_channel *chan)
void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value)
int ast_channel_fd(const struct ast_channel *chan, int which)
void ast_channel_timer_set(struct ast_channel *chan, struct ast_timer *value)
void ast_channel_internal_fd_set(struct ast_channel *chan, int which, int value)
void ast_channel_fin_set(struct ast_channel *chan, unsigned int value)
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format)
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
enum ama_flags ast_channel_amaflags(const struct ast_channel *chan)
void ast_channel_readtrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
void * ast_channel_generatordata(const struct ast_channel *chan)
struct ast_format * ast_channel_rawwriteformat(struct ast_channel *chan)
void ast_channel_set_is_t38_active_nolock(struct ast_channel *chan, int is_t38_active)
Variant of ast_channel_set_is_t38_active. Use this if the channel is already locked prior to calling.
const char * ast_channel_hangupsource(const struct ast_channel *chan)
unsigned int ast_channel_fout(const struct ast_channel *chan)
struct ast_stream_topology * ast_channel_get_stream_topology(const struct ast_channel *chan)
Retrieve the topology of streams on a channel.
int ast_channel_hangupcause(const struct ast_channel *chan)
int ast_channel_timingfd(const struct ast_channel *chan)
void ast_channel_fdno_set(struct ast_channel *chan, int value)
#define AST_TIMING_FD
Definition channel.h:203
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format)
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
@ AST_PARTY_CHAR_SET_ISO8859_1
Definition channel.h:246
void ast_channel_creationtime_set(struct ast_channel *chan, struct timeval *value)
struct ast_tone_zone * ast_channel_zone(const struct ast_channel *chan)
int ast_channel_dialed_causes_add(const struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen)
Add cause code information to the channel.
void ast_channel_named_callgroups_set(struct ast_channel *chan, struct ast_namedgroups *value)
int ast_channel_alert_write(struct ast_channel *chan)
struct ast_readq_list * ast_channel_readq(struct ast_channel *chan)
ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan)
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
void ast_channel_dtmf_digit_to_emulate_set(struct ast_channel *chan, char value)
#define AST_CHANNEL_NAME
Definition channel.h:173
void ast_channel_softhangup_internal_flag_add(struct ast_channel *chan, int value)
struct timeval * ast_channel_whentohangup(struct ast_channel *chan)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3018
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)
@ 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
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:4823
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:2879
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)
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
@ 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
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:3029
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)
@ 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
struct ast_datastore_list * ast_channel_datastores(struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition channel.h:2983
void ast_channel_masq_set(struct ast_channel *chan, struct ast_channel *value)
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
void ast_channel_vstream_set(struct ast_channel *chan, struct ast_filestream *value)
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
int ast_channel_alert_writable(struct ast_channel *chan)
Internal channel functions for channel.c to use.
void ast_channel_internal_set_stream_topology_change_source(struct ast_channel *chan, void *change_source)
void ast_channel_internal_set_stream_topology(struct ast_channel *chan, struct ast_stream_topology *topology)
int ast_channel_internal_is_finalized(struct ast_channel *chan)
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
@ AST_STATE_MUTE
@ AST_STATE_RING
@ AST_STATE_DIALING_OFFHOOK
@ AST_STATE_RINGING
@ AST_STATE_PRERING
@ AST_STATE_DOWN
@ AST_STATE_OFFHOOK
@ AST_STATE_BUSY
@ AST_STATE_DIALING
@ AST_STATE_UP
@ AST_STATE_RESERVED
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:2469
Standard Command Line Interface.
#define CLI_SHOWUSAGE
Definition cli.h:45
#define CLI_SUCCESS
Definition cli.h:44
#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.
@ AST_DEVICE_UNKNOWN
Definition devicestate.h:53
static const float mf_tones[]
Definition dsp.c:325
char buf[BUFSIZE]
Definition eagi_proxy.c:66
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.
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
struct ast_format * ast_format_none
Built-in "null" format.
struct ast_format * ast_format_cache_get_slin_by_rate(unsigned int rate)
Retrieve the best signed linear format given a sample rate.
struct ast_format * ast_format_t140
Built-in cached t140 format.
#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)
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_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
@ AST_FRFLAG_REQUEUED
#define ast_frdup(fr)
Copies a frame.
@ 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_DTMF_END
@ AST_FRAME_DTMF_BEGIN
@ AST_FRAME_BRIDGE_ACTION_SYNC
@ AST_FRAME_TEXT_DATA
@ AST_FRAME_CONTROL
@ AST_FRAME_BRIDGE_ACTION
ast_control_frame_type
Internal control frame subtype field values.
@ AST_CONTROL_SRCUPDATE
@ AST_CONTROL_RECORD_CANCEL
@ 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_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_T38_PARAMETERS
@ AST_CONTROL_READ_ACTION
@ AST_CONTROL_RECORD_STOP
@ AST_CONTROL_CONGESTION
@ AST_CONTROL_PLAYBACK_BEGIN
@ AST_CONTROL_ANSWER
@ AST_CONTROL_RECORD_MUTE
@ AST_CONTROL_RINGING
@ AST_CONTROL_HANGUP
@ AST_CONTROL_STREAM_STOP
@ AST_CONTROL_RADIO_KEY
@ 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_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.
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
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_object_create(void)
Create a new JSON object.
Definition json.c:399
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition json.c:612
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition json.c:327
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition json.c:414
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.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define AST_LIST_INSERT_LIST_AFTER(head, list, elm, field)
Inserts a whole list after a specific entry in a list.
#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.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_RWLIST_HEAD_INIT(head)
Initializes an rwlist head structure.
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized.
#define AST_RWLIST_REMOVE_HEAD
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_RWLIST_HEAD(name, type)
Defines a structure to be used to hold a read/write list of specified type.
#define AST_RWLIST_TRAVERSE
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define AST_RWLIST_INSERT_HEAD
#define AST_RWLIST_INSERT_TAIL
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define AST_LIST_APPEND_LIST(head, list, field)
Appends a whole list to the tail of a list.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
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
#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.
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.
#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 struct stasis_subscription * sub
Statsd channel stats. Exmaple of how to subscribe to Stasis events.
static char url[512]
#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
#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
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
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 *attribute_pure 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_endpoint * endpoint
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
enum ast_control_t38 request_response
Structure for a data store type.
Definition datastore.h:31
void *(* duplicate)(void *data)
Definition datastore.h:33
void(* chan_fixup)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
Fix up channel references on the masquerading channel.
Definition datastore.h:48
const char * type
Definition datastore.h:32
void(* chan_breakdown)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
Fix up channel references on the channel being masqueraded into.
Definition datastore.h:60
Structure for a data store object.
Definition datastore.h:64
const struct ast_datastore_info * info
Definition datastore.h:67
const char * uid
Definition datastore.h:65
void * data
Definition datastore.h:66
struct ast_datastore::@227 entry
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::@239 data
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
int plan
Q.931 Type-Of-Number and Numbering-Plan encoded fields.
Definition channel.h:390
struct ast_party_dialed::@221 number
Dialed/Called number.
int transit_network_select
Transit Network Select.
Definition channel.h:399
struct ast_party_subaddress_ies subaddress
Subscriber subaddress ies.
Definition channel.c:8596
struct ast_party_name_ies name
Subscriber name ies.
Definition channel.c:8592
int combined_presentation
Combined name and number presentation ie.
Definition channel.c:8603
struct ast_party_number_ies number
Subscriber phone number ies.
Definition channel.c:8594
int tag
User party id tag ie.
Definition channel.c:8598
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:8371
int presentation
presentation-indicator ie
Definition channel.c:8373
int str
Subscriber name ie.
Definition channel.c:8369
int valid
valid/present ie
Definition channel.c:8375
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:8447
int str
Subscriber phone number ie.
Definition channel.c:8443
int valid
valid/present ie
Definition channel.c:8449
int plan
Type-Of-Number and Numbering-Plan ie.
Definition channel.c:8445
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:8517
int odd_even_indicator
odd/even indicator ie
Definition channel.c:8521
int valid
valid/present ie
Definition channel.c:8523
int type
subaddress type ie
Definition channel.c:8519
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:8205
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::@224 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:804
struct chanlist::@352 list
struct ast_channel * chan
Definition app_dial.c:806
const struct ast_channel_tech * tech
Definition channel.c:119
const char * tech
Definition app_dial.c:810
List of channel variables to append to all channel-related events.
Definition channel.c:7808
struct manager_channel_variable::@353 entry
Named group member structure.
Definition channel.c:7663
unsigned int hash
Definition channel.c:7665
Number structure.
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:5028
size_t num_samples
Definition channel.c:5032
plc_state_t plc_state
Definition channel.c:5033
struct ast_format *(* get_format)(struct ast_channel *chan)
Definition channel.c:5559
void(* set_trans)(struct ast_channel *chan, struct ast_trans_pvt *value)
Definition channel.c:5558
void(* set_rawformat)(struct ast_channel *chan, struct ast_format *format)
Definition channel.c:5562
struct ast_trans_pvt *(* get_trans)(const struct ast_channel *chan)
Definition channel.c:5557
void(* set_format)(struct ast_channel *chan, struct ast_format *format)
Definition channel.c:5560
const char * direction
Definition channel.c:5556
struct ast_format *(* get_rawformat)(struct ast_channel *chan)
Definition channel.c:5561
enum ast_frame_type frametype
Definition channel.c:10764
unsigned int direction
Definition channel.c:10765
unsigned char offset[AST_FRIENDLY_OFFSET]
Definition channel.c:7495
struct ast_format * origwfmt
Definition channel.c:7490
struct ast_frame f
Definition channel.c:7494
short data[4000]
Definition channel.c:7496
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
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.
#define AST_THREADSTORAGE_RAW(name)
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:2280
struct timeval ast_tvsub(struct timeval a, struct timeval b)
Returns the difference of two timevals a - b.
Definition extconf.c:2295
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:64
#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:981
#define ast_assert(a)
Definition utils.h:779
int ast_get_tid(void)
Get current thread ID.
Definition utils.c:2788
#define ast_clear_flag(p, flag)
Definition utils.h:78
#define SWAP(a, b)
Definition utils.h:256
#define ast_set_flag(p, flag)
Definition utils.h:71
#define ARRAY_LEN(a)
Definition utils.h:706
#define MAX(a, b)
Definition utils.h:254
#define AST_FLAGS_ALL
Definition utils.h:217