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