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