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