Fri Jan 18 19:57:11 2013

Asterisk developer's documentation


channel.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2006, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief General Asterisk PBX channel definitions.
00021  * \par See also:
00022  *  \arg \ref Def_Channel
00023  *  \arg \ref channel_drivers
00024  */
00025 
00026 /*! \page Def_Channel Asterisk Channels
00027    \par What is a Channel?
00028    A phone call through Asterisk consists of an incoming
00029    connection and an outbound connection. Each call comes
00030    in through a channel driver that supports one technology,
00031    like SIP, DAHDI, IAX2 etc.
00032    \par
00033    Each channel driver, technology, has it's own private
00034    channel or dialog structure, that is technology-dependent.
00035    Each private structure is "owned" by a generic Asterisk
00036    channel structure, defined in channel.h and handled by
00037    channel.c .
00038    \par Call scenario
00039    This happens when an incoming call arrives to Asterisk
00040    -# Call arrives on a channel driver interface
00041    -# Channel driver creates a PBX channel and starts a
00042       pbx thread on the channel
00043    -# The dial plan is executed
00044    -# At this point at least two things can happen:
00045       -# The call is answered by Asterisk and
00046          Asterisk plays a media stream or reads media
00047       -# The dial plan forces Asterisk to create an outbound
00048          call somewhere with the dial (see \ref app_dial.c)
00049          application
00050    .
00051 
00052    \par Bridging channels
00053    If Asterisk dials out this happens:
00054    -# Dial creates an outbound PBX channel and asks one of the
00055       channel drivers to create a call
00056    -# When the call is answered, Asterisk bridges the media streams
00057       so the caller on the first channel can speak with the callee
00058       on the second, outbound channel
00059    -# In some cases where we have the same technology on both
00060       channels and compatible codecs, a native bridge is used.
00061       In a native bridge, the channel driver handles forwarding
00062       of incoming audio to the outbound stream internally, without
00063       sending audio frames through the PBX.
00064    -# In SIP, theres an "external native bridge" where Asterisk
00065       redirects the endpoint, so audio flows directly between the
00066       caller's phone and the callee's phone. Signalling stays in
00067       Asterisk in order to be able to provide a proper CDR record
00068       for the call.
00069 
00070 
00071    \par Masquerading channels
00072    In some cases, a channel can masquerade itself into another
00073    channel. This happens frequently in call transfers, where
00074    a new channel takes over a channel that is already involved
00075    in a call. The new channel sneaks in and takes over the bridge
00076    and the old channel, now a zombie, is hung up.
00077 
00078    \par Reference
00079    \arg channel.c - generic functions
00080    \arg channel.h - declarations of functions, flags and structures
00081    \arg translate.h - Transcoding support functions
00082    \arg \ref channel_drivers - Implemented channel drivers
00083    \arg \ref Def_Frame Asterisk Multimedia Frames
00084    \arg \ref Def_Bridge
00085 
00086 */
00087 /*! \page Def_Bridge Asterisk Channel Bridges
00088 
00089    In Asterisk, there's several media bridges.
00090 
00091    The Core bridge handles two channels (a "phone call") and bridge
00092    them together.
00093 
00094    The conference bridge (meetme) handles several channels simultaneously
00095    with the support of an external timer (DAHDI timer). This is used
00096    not only by the Conference application (meetme) but also by the
00097    page application and the SLA system introduced in 1.4.
00098    The conference bridge does not handle video.
00099 
00100    When two channels of the same type connect, the channel driver
00101    or the media subsystem used by the channel driver (i.e. RTP)
00102    can create a native bridge without sending media through the
00103    core.
00104 
00105    Native bridging can be disabled by a number of reasons,
00106    like DTMF being needed by the core or codecs being incompatible
00107    so a transcoding module is needed.
00108 
00109 References:
00110    \li \see ast_channel_early_bridge()
00111    \li \see ast_channel_bridge()
00112    \li \see app_meetme.c
00113    \li \ref AstRTPbridge
00114    \li \see ast_rtp_bridge()
00115    \li \ref Def_Channel
00116 */
00117 
00118 /*! \page AstFileDesc File descriptors
00119    Asterisk File descriptors are connected to each channel (see \ref Def_Channel)
00120    in the \ref ast_channel structure.
00121 */
00122 
00123 #ifndef _ASTERISK_CHANNEL_H
00124 #define _ASTERISK_CHANNEL_H
00125 
00126 #include "asterisk/abstract_jb.h"
00127 #include "asterisk/astobj2.h"
00128 
00129 #include "asterisk/poll-compat.h"
00130 
00131 #if defined(__cplusplus) || defined(c_plusplus)
00132 extern "C" {
00133 #endif
00134 
00135 #define AST_MAX_EXTENSION  80 /*!< Max length of an extension */
00136 #define AST_MAX_CONTEXT    80 /*!< Max length of a context */
00137 #define AST_CHANNEL_NAME   80 /*!< Max length of an ast_channel name */
00138 #define MAX_LANGUAGE    40 /*!< Max length of the language setting */
00139 #define MAX_MUSICCLASS     80 /*!< Max length of the music class setting */
00140 
00141 #include "asterisk/frame.h"
00142 #include "asterisk/sched.h"
00143 #include "asterisk/chanvars.h"
00144 #include "asterisk/config.h"
00145 #include "asterisk/lock.h"
00146 #include "asterisk/cdr.h"
00147 #include "asterisk/utils.h"
00148 #include "asterisk/linkedlists.h"
00149 #include "asterisk/stringfields.h"
00150 #include "asterisk/datastore.h"
00151 #include "asterisk/data.h"
00152 #include "asterisk/channelstate.h"
00153 #include "asterisk/ccss.h"
00154 #include "asterisk/framehook.h"
00155 
00156 #define DATASTORE_INHERIT_FOREVER   INT_MAX
00157 
00158 #define AST_MAX_FDS     10
00159 /*
00160  * We have AST_MAX_FDS file descriptors in a channel.
00161  * Some of them have a fixed use:
00162  */
00163 #define AST_ALERT_FD (AST_MAX_FDS-1)      /*!< used for alertpipe */
00164 #define AST_TIMING_FD   (AST_MAX_FDS-2)      /*!< used for timingfd */
00165 #define AST_AGENT_FD (AST_MAX_FDS-3)      /*!< used by agents for pass through */
00166 #define AST_GENERATOR_FD   (AST_MAX_FDS-4)   /*!< used by generator */
00167 
00168 enum ast_bridge_result {
00169    AST_BRIDGE_COMPLETE = 0,
00170    AST_BRIDGE_FAILED = -1,
00171    AST_BRIDGE_FAILED_NOWARN = -2,
00172    AST_BRIDGE_RETRY = -3,
00173 };
00174 
00175 typedef unsigned long long ast_group_t;
00176 
00177 /*! \todo Add an explanation of an Asterisk generator
00178 */
00179 struct ast_generator {
00180    void *(*alloc)(struct ast_channel *chan, void *params);
00181    void (*release)(struct ast_channel *chan, void *data);
00182    /*! This function gets called with the channel unlocked, but is called in
00183     *  the context of the channel thread so we know the channel is not going
00184     *  to disappear.  This callback is responsible for locking the channel as
00185     *  necessary. */
00186    int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
00187    /*! This gets called when DTMF_END frames are read from the channel */
00188    void (*digit)(struct ast_channel *chan, char digit);
00189 };
00190 
00191 /*! Party name character set enumeration values (values from Q.SIG) */
00192 enum AST_PARTY_CHAR_SET {
00193    AST_PARTY_CHAR_SET_UNKNOWN = 0,
00194    AST_PARTY_CHAR_SET_ISO8859_1 = 1,
00195    AST_PARTY_CHAR_SET_WITHDRAWN = 2,/* ITU withdrew this enum value. */
00196    AST_PARTY_CHAR_SET_ISO8859_2 = 3,
00197    AST_PARTY_CHAR_SET_ISO8859_3 = 4,
00198    AST_PARTY_CHAR_SET_ISO8859_4 = 5,
00199    AST_PARTY_CHAR_SET_ISO8859_5 = 6,
00200    AST_PARTY_CHAR_SET_ISO8859_7 = 7,
00201    AST_PARTY_CHAR_SET_ISO10646_BMPSTRING = 8,
00202    AST_PARTY_CHAR_SET_ISO10646_UTF_8STRING = 9,
00203 };
00204 
00205 /*!
00206  * \since 1.8
00207  * \brief Information needed to specify a name in a call.
00208  * \note All string fields here are malloc'ed, so they need to be
00209  * freed when the structure is deleted.
00210  * \note NULL and "" must be considered equivalent.
00211  */
00212 struct ast_party_name {
00213    /*! \brief Subscriber name (Malloced) */
00214    char *str;
00215    /*!
00216     * \brief Character set the name is using.
00217     * \see enum AST_PARTY_CHAR_SET
00218     * \note
00219     * Set to AST_PARTY_CHAR_SET_ISO8859_1 if unsure what to use.
00220     * \todo Start using the party name character set value.  Not currently used.
00221     */
00222    int char_set;
00223    /*!
00224     * \brief Q.931 encoded presentation-indicator encoded field
00225     * \note Must tolerate the Q.931 screening-indicator field values being present.
00226     */
00227    int presentation;
00228    /*! \brief TRUE if the name information is valid/present */
00229    unsigned char valid;
00230 };
00231 
00232 /*!
00233  * \since 1.8
00234  * \brief Information needed to specify a number in a call.
00235  * \note All string fields here are malloc'ed, so they need to be
00236  * freed when the structure is deleted.
00237  * \note NULL and "" must be considered equivalent.
00238  */
00239 struct ast_party_number {
00240    /*! \brief Subscriber phone number (Malloced) */
00241    char *str;
00242    /*! \brief Q.931 Type-Of-Number and Numbering-Plan encoded fields */
00243    int plan;
00244    /*! \brief Q.931 presentation-indicator and screening-indicator encoded fields */
00245    int presentation;
00246    /*! \brief TRUE if the number information is valid/present */
00247    unsigned char valid;
00248 };
00249 
00250 /*!
00251  * \since 1.8
00252  * \brief Information needed to specify a subaddress in a call.
00253  * \note All string fields here are malloc'ed, so they need to be
00254  * freed when the structure is deleted.
00255  * \note NULL and "" must be considered equivalent.
00256  */
00257 struct ast_party_subaddress {
00258    /*!
00259     * \brief Malloced subaddress string.
00260     * \note If the subaddress type is user specified then the subaddress is
00261     * a string of ASCII hex because the actual subaddress is likely BCD encoded.
00262     */
00263    char *str;
00264    /*!
00265     * \brief Q.931 subaddress type.
00266     * \details
00267     * nsap(0),
00268     * user_specified(2)
00269     */
00270    int type;
00271    /*!
00272     * \brief TRUE if odd number of address signals
00273     * \note The odd/even indicator is used when the type of subaddress is
00274     * user_specified and the coding is BCD.
00275     */
00276    unsigned char odd_even_indicator;
00277    /*! \brief TRUE if the subaddress information is valid/present */
00278    unsigned char valid;
00279 };
00280 
00281 /*!
00282  * \since 1.8
00283  * \brief Information needed to identify an endpoint in a call.
00284  * \note All string fields here are malloc'ed, so they need to be
00285  * freed when the structure is deleted.
00286  * \note NULL and "" must be considered equivalent.
00287  */
00288 struct ast_party_id {
00289    /*! \brief Subscriber name */
00290    struct ast_party_name name;
00291    /*! \brief Subscriber phone number */
00292    struct ast_party_number number;
00293    /*! \brief Subscriber subaddress. */
00294    struct ast_party_subaddress subaddress;
00295 
00296    /*!
00297     * \brief User-set "tag"
00298     * \details
00299     * A user-settable field used to help associate some extrinsic information
00300     * about the channel or user of the channel to the party ID.  This information
00301     * is normally not transmitted over the wire and so is only useful within an
00302     * Asterisk environment.
00303     */
00304    char *tag;
00305 };
00306 
00307 /*!
00308  * \since 1.8
00309  * \brief Indicate what information in ast_party_id should be set.
00310  */
00311 struct ast_set_party_id {
00312    /*! TRUE if the ast_party_name information should be set. */
00313    unsigned char name;
00314    /*! TRUE if the ast_party_number information should be set. */
00315    unsigned char number;
00316    /*! TRUE if the ast_party_subaddress information should be set. */
00317    unsigned char subaddress;
00318 };
00319 
00320 /*!
00321  * \since 1.8
00322  * \brief Dialed/Called Party information.
00323  * \note Dialed Number Identifier (DNID)
00324  * \note All string fields here are malloc'ed, so they need to be
00325  * freed when the structure is deleted.
00326  * \note NULL and "" must be considered equivalent.
00327  */
00328 struct ast_party_dialed {
00329    /*!
00330     * \brief Dialed/Called number
00331     * \note Done this way in case we ever really need to use ast_party_number.
00332     * We currently do not need all of the ast_party_number fields.
00333     */
00334    struct {
00335       /*! \brief Subscriber phone number (Malloced) */
00336       char *str;
00337       /*! \brief Q.931 Type-Of-Number and Numbering-Plan encoded fields */
00338       int plan;
00339    } number;
00340    /*! \brief Dialed/Called subaddress */
00341    struct ast_party_subaddress subaddress;
00342    /*!
00343     * \brief Transit Network Select
00344     * \note Currently this value is just passed around the system.
00345     * You can read it and set it but it is never used for anything.
00346     */
00347    int transit_network_select;
00348 };
00349 
00350 /*!
00351  * \since 1.8
00352  * \brief Caller Party information.
00353  * \note All string fields here are malloc'ed, so they need to be
00354  * freed when the structure is deleted.
00355  * \note NULL and "" must be considered equivalent.
00356  *
00357  * \note SIP and IAX2 has UTF8 encoded Unicode Caller ID names.
00358  * In some cases, we also have an alternative (RPID) E.164 number that can
00359  * be used as Caller ID on numeric E.164 phone networks (DAHDI or SIP/IAX2 to
00360  * PSTN gateway).
00361  *
00362  * \todo Implement settings for transliteration between UTF8 Caller ID names in
00363  *       to ASCII Caller ID's (DAHDI). Östen Åsklund might be transliterated into
00364  *       Osten Asklund or Oesten Aasklund depending upon language and person...
00365  *       We need automatic routines for incoming calls and static settings for
00366  *       our own accounts.
00367  */
00368 struct ast_party_caller {
00369    /*! \brief Caller party ID */
00370    struct ast_party_id id;
00371 
00372    /*!
00373     * \brief Automatic Number Identification (ANI)
00374     * \note The name subcomponent is only likely to be used by SIP.
00375     * \note The subaddress subcomponent is not likely to be used.
00376     */
00377    struct ast_party_id ani;
00378 
00379    /*! \brief Automatic Number Identification 2 (Info Digits) */
00380    int ani2;
00381 };
00382 
00383 /*!
00384  * \since 1.8
00385  * \brief Indicate what information in ast_party_caller should be set.
00386  */
00387 struct ast_set_party_caller {
00388    /*! What caller id information to set. */
00389    struct ast_set_party_id id;
00390    /*! What ANI id information to set. */
00391    struct ast_set_party_id ani;
00392 };
00393 
00394 /*!
00395  * \since 1.8
00396  * \brief Connected Line/Party information.
00397  * \note All string fields here are malloc'ed, so they need to be
00398  * freed when the structure is deleted.
00399  * \note NULL and "" must be considered equivalent.
00400  */
00401 struct ast_party_connected_line {
00402    /*! \brief Connected party ID */
00403    struct ast_party_id id;
00404 
00405    /*!
00406     * \brief Automatic Number Identification (ANI)
00407     * \note Not really part of connected line data but needed to
00408     * save the corresponding caller id value.
00409     */
00410    struct ast_party_id ani;
00411 
00412    /*!
00413     * \brief Automatic Number Identification 2 (Info Digits)
00414     * \note Not really part of connected line data but needed to
00415     * save the corresponding caller id value.
00416     */
00417    int ani2;
00418 
00419    /*!
00420     * \brief Information about the source of an update.
00421     * \note enum AST_CONNECTED_LINE_UPDATE_SOURCE values
00422     * for Normal-Answer and Call-transfer.
00423     */
00424    int source;
00425 };
00426 
00427 /*!
00428  * \since 1.8
00429  * \brief Indicate what information in ast_party_connected_line should be set.
00430  */
00431 struct ast_set_party_connected_line {
00432    /*! What connected line id information to set. */
00433    struct ast_set_party_id id;
00434    /*! What ANI id information to set. */
00435    struct ast_set_party_id ani;
00436 };
00437 
00438 /*!
00439  * \since 1.8
00440  * \brief Redirecting Line information.
00441  * RDNIS (Redirecting Directory Number Information Service)
00442  * Where a call diversion or transfer was invoked.
00443  * \note All string fields here are malloc'ed, so they need to be
00444  * freed when the structure is deleted.
00445  * \note NULL and "" must be considered equivalent.
00446  */
00447 struct ast_party_redirecting {
00448    /*! \brief Who is redirecting the call (Sent to the party the call is redirected toward) */
00449    struct ast_party_id from;
00450 
00451    /*! \brief Call is redirecting to a new party (Sent to the caller) */
00452    struct ast_party_id to;
00453 
00454    /*! \brief Number of times the call was redirected */
00455    int count;
00456 
00457    /*! \brief enum AST_REDIRECTING_REASON value for redirection */
00458    int reason;
00459 };
00460 
00461 /*!
00462  * \since 1.8
00463  * \brief Indicate what information in ast_party_redirecting should be set.
00464  */
00465 struct ast_set_party_redirecting {
00466    /*! What redirecting-from id information to set. */
00467    struct ast_set_party_id from;
00468    /*! What redirecting-to id information to set. */
00469    struct ast_set_party_id to;
00470 };
00471 
00472 /*! \brief Typedef for a custom read function */
00473 typedef int (*ast_acf_read_fn_t)(struct ast_channel *, const char *, char *, char *, size_t);
00474 
00475 /*! \brief Typedef for a custom read2 function */
00476 typedef int (*ast_acf_read2_fn_t)(struct ast_channel *, const char *, char *, struct ast_str **, ssize_t);
00477 
00478 /*! \brief Typedef for a custom write function */
00479 typedef int (*ast_acf_write_fn_t)(struct ast_channel *, const char *, char *, const char *);
00480 
00481 /*! \brief Structure to handle passing func_channel_write info to channels via setoption */
00482 typedef struct {
00483    /*! \brief ast_chan_write_info_t version. Must be incremented if structure is changed */
00484    #define AST_CHAN_WRITE_INFO_T_VERSION 1
00485    uint32_t version;
00486    ast_acf_write_fn_t write_fn;
00487    struct ast_channel *chan;
00488    const char *function;
00489    char *data;
00490    const char *value;
00491 } ast_chan_write_info_t;
00492 
00493 /*!
00494  * \brief
00495  * Structure to describe a channel "technology", ie a channel driver
00496  * See for examples:
00497  * \arg chan_iax2.c - The Inter-Asterisk exchange protocol
00498  * \arg chan_sip.c - The SIP channel driver
00499  * \arg chan_dahdi.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
00500  *
00501  * \details
00502  * If you develop your own channel driver, this is where you
00503  * tell the PBX at registration of your driver what properties
00504  * this driver supports and where different callbacks are
00505  * implemented.
00506  */
00507 struct ast_channel_tech {
00508    const char * const type;
00509    const char * const description;
00510 
00511    format_t capabilities;  /*!< Bitmap of formats this channel can handle */
00512 
00513    int properties;         /*!< Technology Properties */
00514 
00515    /*!
00516     * \brief Requester - to set up call data structures (pvt's)
00517     * \note data should be treated as const char *.
00518     */
00519    struct ast_channel *(* const requester)(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
00520 
00521    int (* const devicestate)(void *data); /*!< Devicestate call back */
00522 
00523    /*!
00524     * \brief Start sending a literal DTMF digit
00525     *
00526     * \note The channel is not locked when this function gets called.
00527     */
00528    int (* const send_digit_begin)(struct ast_channel *chan, char digit);
00529 
00530    /*!
00531     * \brief Stop sending a literal DTMF digit
00532     *
00533     * \note The channel is not locked when this function gets called.
00534     */
00535    int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);
00536 
00537    /*!
00538     * \brief Call a given phone number (address, etc), but don't
00539     * take longer than timeout seconds to do so.
00540     * \note addr should be treated as const char *.
00541     */
00542    int (* const call)(struct ast_channel *chan, char *addr, int timeout);
00543 
00544    /*! \brief Hangup (and possibly destroy) the channel */
00545    int (* const hangup)(struct ast_channel *chan);
00546 
00547    /*! \brief Answer the channel */
00548    int (* const answer)(struct ast_channel *chan);
00549 
00550    /*! \brief Read a frame, in standard format (see frame.h) */
00551    struct ast_frame * (* const read)(struct ast_channel *chan);
00552 
00553    /*! \brief Write a frame, in standard format (see frame.h) */
00554    int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
00555 
00556    /*! \brief Display or transmit text */
00557    int (* const send_text)(struct ast_channel *chan, const char *text);
00558 
00559    /*! \brief Display or send an image */
00560    int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
00561 
00562    /*! \brief Send HTML data */
00563    int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
00564 
00565    /*! \brief Handle an exception, reading a frame */
00566    struct ast_frame * (* const exception)(struct ast_channel *chan);
00567 
00568    /*! \brief Bridge two channels of the same type together */
00569    enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags,
00570                   struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
00571 
00572    /*! \brief Bridge two channels of the same type together (early) */
00573    enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1);
00574 
00575    /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
00576    int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);
00577 
00578    /*! \brief Fix up a channel:  If a channel is consumed, this is called.  Basically update any ->owner links */
00579    int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
00580 
00581    /*! \brief Set a given option. Called with chan locked */
00582    int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
00583 
00584    /*! \brief Query a given option. Called with chan locked */
00585    int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
00586 
00587    /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
00588    int (* const transfer)(struct ast_channel *chan, const char *newdest);
00589 
00590    /*! \brief Write a frame, in standard format */
00591    int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
00592 
00593    /*! \brief Write a text frame, in standard format */
00594    int (* const write_text)(struct ast_channel *chan, struct ast_frame *frame);
00595 
00596    /*! \brief Find bridged channel */
00597    struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge);
00598 
00599    /*! \brief Provide additional read items for CHANNEL() dialplan function */
00600    int (* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
00601 
00602    /*! \brief Provide additional write items for CHANNEL() dialplan function */
00603    int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);
00604 
00605    /*! \brief Retrieve base channel (agent and local) */
00606    struct ast_channel* (* get_base_channel)(struct ast_channel *chan);
00607 
00608    /*! \brief Set base channel (agent and local) */
00609    int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base);
00610 
00611    /*! \brief Get the unique identifier for the PVT, i.e. SIP call-ID for SIP */
00612    const char * (* get_pvt_uniqueid)(struct ast_channel *chan);
00613 
00614    /*! \brief Call a function with cc parameters as a function parameter
00615     *
00616     * \details
00617     * This is a highly specialized callback that is not likely to be needed in many
00618     * channel drivers. When dealing with a busy channel, for instance, most channel
00619     * drivers will successfully return a channel to the requester. Once called, the channel
00620     * can then queue a busy frame when it receives an appropriate message from the far end.
00621     * In such a case, the channel driver has the opportunity to also queue a CC frame.
00622     * The parameters for the CC channel can be retrieved from the channel structure.
00623     *
00624     * For other channel drivers, notably those that deal with "dumb" phones, the channel
00625     * driver will not return a channel when one is requested. In such a scenario, there is never
00626     * an opportunity for the channel driver to queue a CC frame since the channel is never
00627     * called. Furthermore, it is not possible to retrieve the CC configuration parameters
00628     * for the desired channel because no channel is ever allocated or returned to the
00629     * requester. In such a case, call completion may still be a viable option. What we do is
00630     * pass the same string that the requester used originally to request the channel to the
00631     * channel driver. The channel driver can then find any potential channels/devices that
00632     * match the input and return call the designated callback with the device's call completion
00633     * parameters as a parameter.
00634     */
00635    int (* cc_callback)(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);
00636 };
00637 
00638 /*! Kill the channel channel driver technology descriptor. */
00639 extern const struct ast_channel_tech ast_kill_tech;
00640 
00641 struct ast_epoll_data;
00642 
00643 /*!
00644  * The high bit of the frame count is used as a debug marker, so
00645  * increments of the counters must be done with care.
00646  * Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.
00647  */
00648 #define  DEBUGCHAN_FLAG  0x80000000
00649 
00650 /* XXX not ideal to evaluate x twice... */
00651 #define  FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
00652 
00653 /*!
00654  * The current value of the debug flags is stored in the two
00655  * variables global_fin and global_fout (declared in main/channel.c)
00656  */
00657 extern unsigned long global_fin, global_fout;
00658 
00659 enum ast_channel_adsicpe {
00660    AST_ADSI_UNKNOWN,
00661    AST_ADSI_AVAILABLE,
00662    AST_ADSI_UNAVAILABLE,
00663    AST_ADSI_OFFHOOKONLY,
00664 };
00665 
00666 /*!
00667  * \brief Possible T38 states on channels
00668  */
00669 enum ast_t38_state {
00670    T38_STATE_UNAVAILABLE,  /*!< T38 is unavailable on this channel or disabled by configuration */
00671    T38_STATE_UNKNOWN,   /*!< The channel supports T38 but the current status is unknown */
00672    T38_STATE_NEGOTIATING,  /*!< T38 is being negotiated */
00673    T38_STATE_REJECTED,  /*!< Remote side has rejected our offer */
00674    T38_STATE_NEGOTIATED,   /*!< T38 established */
00675 };
00676 
00677 /*!
00678  * \page AstChannel ast_channel locking and reference tracking
00679  *
00680  * \par Creating Channels
00681  * A channel is allocated using the ast_channel_alloc() function.  When created, it is
00682  * automatically inserted into the main channels hash table that keeps track of all
00683  * active channels in the system.  The hash key is based on the channel name.  Because
00684  * of this, if you want to change the name, you _must_ use ast_change_name(), not change
00685  * the name field directly.  When ast_channel_alloc() returns a channel pointer, you now
00686  * hold a reference to that channel.  In most cases this reference is given to ast_pbx_run().
00687  *
00688  * \par Channel Locking
00689  * There is a lock associated with every ast_channel.  It is allocated internally via astobj2.
00690  * To lock or unlock a channel, you must use the ast_channel_lock() wrappers.
00691  *
00692  * Previously, before ast_channel was converted to astobj2, the channel lock was used in some
00693  * additional ways that are no longer necessary.  Before, the only way to ensure that a channel
00694  * did not disappear out from under you if you were working with a channel outside of the channel
00695  * thread that owns it, was to hold the channel lock.  Now, that is no longer necessary.
00696  * You simply must hold a reference to the channel to ensure it does not go away.
00697  *
00698  * The channel must be locked if you need to ensure that data that you reading from the channel
00699  * does not change while you access it.  Further, you must hold the channel lock if you are
00700  * making a non-atomic change to channel data.
00701  *
00702  * \par Channel References
00703  * There are multiple ways to get a reference to a channel.  The first is that you hold a reference
00704  * to a channel after creating it.  The other ways involve using the channel search or the channel
00705  * traversal APIs.  These functions are the ast_channel_get_*() functions or ast_channel_iterator_*()
00706  * functions.  Once a reference is retrieved by one of these methods, you know that the channel will
00707  * not go away.  So, the channel should only get locked as needed for data access or modification.
00708  * But, make sure that the reference gets released when you are done with it!
00709  *
00710  * There are different things you can do when you are done with a reference to a channel.  The first
00711  * is to simply release the reference using ast_channel_unref().  The other option is to call
00712  * ast_channel_release().  This function is generally used where ast_channel_free() was used in
00713  * the past.  The release function releases a reference as well as ensures that the channel is no
00714  * longer in the global channels container.  That way, the channel will get destroyed as soon as any
00715  * other pending references get released.
00716  *
00717  * \par Exceptions to the rules
00718  * Even though ast_channel is reference counted, there are some places where pointers to an ast_channel
00719  * get stored, but the reference count does not reflect it.  The reason is mostly historical.
00720  * The only places where this happens should be places where because of how the code works, we
00721  * _know_ that the pointer to the channel will get removed before the channel goes away.  The main
00722  * example of this is in channel drivers.  Channel drivers generally store a pointer to their owner
00723  * ast_channel in their technology specific pvt struct.  In this case, the channel drivers _know_
00724  * that this pointer to the channel will be removed in time, because the channel's hangup callback
00725  * gets called before the channel goes away.
00726  */
00727 
00728 /*!
00729  * \brief Main Channel structure associated with a channel.
00730  *
00731  * \note XXX It is important to remember to increment .cleancount each time
00732  *       this structure is changed. XXX
00733  *
00734  * \note When adding fields to this structure, it is important to add the field
00735  *       'in position' with like-aligned fields, so as to keep the compiler from
00736  *       having to add padding to align fields. The structure's fields are sorted
00737  *       in this order: pointers, structures, long, int/enum, short, char. This
00738  *       is especially important on 64-bit architectures, where mixing 4-byte
00739  *       and 8-byte fields causes 4 bytes of padding to be added before many
00740  *       8-byte fields.
00741  */
00742 struct ast_channel {
00743    const struct ast_channel_tech *tech;      /*!< Technology (point to channel driver) */
00744    void *tech_pvt;               /*!< Private data used by the technology driver */
00745    void *music_state;            /*!< Music State*/
00746    void *generatordata;          /*!< Current generator data if there is any */
00747    struct ast_generator *generator;    /*!< Current active data generator */
00748    struct ast_channel *_bridge;        /*!< Who are we bridged to, if we're bridged.
00749                       *   Who is proxying for us, if we are proxied (i.e. chan_agent).
00750                       *   Do not access directly, use ast_bridged_channel(chan) */
00751    struct ast_channel *masq;        /*!< Channel that will masquerade as us */
00752    struct ast_channel *masqr;       /*!< Who we are masquerading as */
00753    const char *blockproc;           /*!< Procedure causing blocking */
00754    const char *appl;          /*!< Current application */
00755    const char *data;          /*!< Data passed to current application */
00756    struct sched_context *sched;        /*!< Schedule context */
00757    struct ast_filestream *stream;         /*!< Stream itself. */
00758    struct ast_filestream *vstream;        /*!< Video Stream itself. */
00759    int (*timingfunc)(const void *data);
00760    void *timingdata;
00761    struct ast_pbx *pbx;          /*!< PBX private structure for this channel */
00762    struct ast_trans_pvt *writetrans;      /*!< Write translation path */
00763    struct ast_trans_pvt *readtrans;    /*!< Read translation path */
00764    struct ast_audiohook_list *audiohooks;
00765    struct ast_framehook_list *framehooks;
00766    struct ast_cdr *cdr;          /*!< Call Detail Record */
00767    struct ast_tone_zone *zone;         /*!< Tone zone as set in indications.conf or
00768                       *   in the CHANNEL dialplan function */
00769    struct ast_channel_monitor *monitor;      /*!< Channel monitoring */
00770 #ifdef HAVE_EPOLL
00771    struct ast_epoll_data *epfd_data[AST_MAX_FDS];
00772 #endif
00773 
00774    AST_DECLARE_STRING_FIELDS(
00775       AST_STRING_FIELD(name);       /*!< ASCII unique channel name */
00776       AST_STRING_FIELD(language);      /*!< Language requested for voice prompts */
00777       AST_STRING_FIELD(musicclass);    /*!< Default music class */
00778       AST_STRING_FIELD(accountcode);      /*!< Account code for billing */
00779       AST_STRING_FIELD(peeraccount);      /*!< Peer account code for billing */
00780       AST_STRING_FIELD(userfield);     /*!< Userfield for CEL billing */
00781       AST_STRING_FIELD(call_forward);     /*!< Where to forward to if asked to dial on this interface */
00782       AST_STRING_FIELD(uniqueid);      /*!< Unique Channel Identifier */
00783       AST_STRING_FIELD(linkedid);      /*!< Linked Channel Identifier -- gets propagated by linkage */
00784       AST_STRING_FIELD(parkinglot);    /*! Default parking lot, if empty, default parking lot  */
00785       AST_STRING_FIELD(hangupsource);     /*! Who is responsible for hanging up this channel */
00786       AST_STRING_FIELD(dialcontext);      /*!< Dial: Extension context that we were called from */
00787    );
00788 
00789    struct timeval whentohangup;              /*!< Non-zero, set to actual time when channel is to be hung up */
00790    pthread_t blocker;            /*!< If anyone is blocking, this is them */
00791 
00792    /*!
00793     * \brief Dialed/Called information.
00794     * \note Set on incoming channels to indicate the originally dialed party.
00795     * \note Dialed Number Identifier (DNID)
00796     */
00797    struct ast_party_dialed dialed;
00798 
00799    /*!
00800     * \brief Channel Caller ID information.
00801     * \note The caller id information is the caller id of this
00802     * channel when it is used to initiate a call.
00803     */
00804    struct ast_party_caller caller;
00805 
00806    /*!
00807     * \brief Channel Connected Line ID information.
00808     * \note The connected line information identifies the channel
00809     * connected/bridged to this channel.
00810     */
00811    struct ast_party_connected_line connected;
00812 
00813    /*! \brief Redirecting/Diversion information */
00814    struct ast_party_redirecting redirecting;
00815 
00816    struct ast_frame dtmff;          /*!< DTMF frame */
00817    struct varshead varshead;        /*!< A linked list for channel variables. See \ref AstChanVar */
00818    ast_group_t callgroup;           /*!< Call group for call pickups */
00819    ast_group_t pickupgroup;         /*!< Pickup group - which calls groups can be picked up? */
00820    AST_LIST_HEAD_NOLOCK(, ast_frame) readq;
00821    struct ast_jb jb;          /*!< The jitterbuffer state */
00822    struct timeval dtmf_tv;          /*!< The time that an in process digit began, or the last digit ended */
00823    AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores; /*!< Data stores on the channel */
00824    AST_LIST_HEAD_NOLOCK(autochans, ast_autochan) autochans; /*!< Autochans on the channel */
00825 
00826    unsigned long insmpl;            /*!< Track the read/written samples for monitor use */
00827    unsigned long outsmpl;           /*!< Track the read/written samples for monitor use */
00828 
00829    int fds[AST_MAX_FDS];            /*!< File descriptors for channel -- Drivers will poll on
00830                       *   these file descriptors, so at least one must be non -1.
00831                       *   See \arg \ref AstFileDesc */
00832    int _softhangup;           /*!< Whether or not we have been hung up...  Do not set this value
00833                       *   directly, use ast_softhangup() */
00834    int fdno;               /*!< Which fd had an event detected on */
00835    int streamid;              /*!< For streaming playback, the schedule ID */
00836    int vstreamid;             /*!< For streaming video playback, the schedule ID */
00837    format_t oldwriteformat;      /*!< Original writer format */
00838    int timingfd;              /*!< Timing fd */
00839    enum ast_channel_state _state;         /*!< State of line -- Don't write directly, use ast_setstate() */
00840    int rings;              /*!< Number of rings so far */
00841    int priority;              /*!< Dialplan: Current extension priority */
00842    int macropriority;            /*!< Macro: Current non-macro priority. See app_macro.c */
00843    int amaflags;              /*!< Set BEFORE PBX is started to determine AMA flags */
00844    enum ast_channel_adsicpe adsicpe;      /*!< Whether or not ADSI is detected on CPE */
00845    unsigned int fin;          /*!< Frames in counters. The high bit is a debug mask, so
00846                       *   the counter is only in the remaining bits */
00847    unsigned int fout;            /*!< Frames out counters. The high bit is a debug mask, so
00848                       *   the counter is only in the remaining bits */
00849    int hangupcause;           /*!< Why is the channel hanged up. See causes.h */
00850    unsigned int flags;           /*!< channel flags of AST_FLAG_ type */
00851    int alertpipe[2];
00852    format_t nativeformats;         /*!< Kinds of data this channel can natively handle */
00853    format_t readformat;            /*!< Requested read format (after translation) */
00854    format_t writeformat;           /*!< Requested write format (after translation) */
00855    format_t rawreadformat;         /*!< Raw read format (before translation) */
00856    format_t rawwriteformat;        /*!< Raw write format (before translation) */
00857    unsigned int emulate_dtmf_duration;    /*!< Number of ms left to emulate DTMF for */
00858 #ifdef HAVE_EPOLL
00859    int epfd;
00860 #endif
00861    int visible_indication;                         /*!< Indication currently playing on the channel */
00862 
00863    unsigned short transfercapability;     /*!< ISDN Transfer Capability - AST_FLAG_DIGITAL is not enough */
00864 
00865    struct ast_bridge *bridge;                      /*!< Bridge this channel is participating in */
00866    struct ast_timer *timer;         /*!< timer object that provided timingfd */
00867 
00868    char context[AST_MAX_CONTEXT];         /*!< Dialplan: Current extension context */
00869    char exten[AST_MAX_EXTENSION];         /*!< Dialplan: Current extension number */
00870    char macrocontext[AST_MAX_CONTEXT];    /*!< Macro: Current non-macro context. See app_macro.c */
00871    char macroexten[AST_MAX_EXTENSION];    /*!< Macro: Current non-macro extension. See app_macro.c */
00872    char emulate_dtmf_digit;         /*!< Digit being emulated */
00873    char sending_dtmf_digit;         /*!< Digit this channel is currently sending out. (zero if not sending) */
00874    struct timeval sending_dtmf_tv;     /*!< The time this channel started sending the current digit. (Invalid if sending_dtmf_digit is zero.) */
00875 };
00876 
00877 /*! \brief ast_channel_tech Properties */
00878 enum {
00879    /*!
00880      * \brief Channels have this property if they can accept input with jitter;
00881     * i.e. most VoIP channels
00882     */
00883    AST_CHAN_TP_WANTSJITTER = (1 << 0),
00884    /*!
00885      * \brief Channels have this property if they can create jitter;
00886     * i.e. most VoIP channels
00887     */
00888    AST_CHAN_TP_CREATESJITTER = (1 << 1),
00889 };
00890 
00891 /*! \brief ast_channel flags */
00892 enum {
00893    /*! Queue incoming DTMF, to be released when this flag is turned off */
00894    AST_FLAG_DEFER_DTMF =    (1 << 1),
00895    /*! write should be interrupt generator */
00896    AST_FLAG_WRITE_INT =     (1 << 2),
00897    /*! a thread is blocking on this channel */
00898    AST_FLAG_BLOCKING =      (1 << 3),
00899    /*! This is a zombie channel */
00900    AST_FLAG_ZOMBIE =        (1 << 4),
00901    /*! There is an exception pending */
00902    AST_FLAG_EXCEPTION =     (1 << 5),
00903    /*! Listening to moh XXX anthm promises me this will disappear XXX */
00904    AST_FLAG_MOH =           (1 << 6),
00905    /*! This channel is spying on another channel */
00906    AST_FLAG_SPYING =        (1 << 7),
00907    /*! This channel is in a native bridge */
00908    AST_FLAG_NBRIDGE =       (1 << 8),
00909    /*! the channel is in an auto-incrementing dialplan processor,
00910     *  so when ->priority is set, it will get incremented before
00911     *  finding the next priority to run */
00912    AST_FLAG_IN_AUTOLOOP =   (1 << 9),
00913    /*! This is an outgoing call */
00914    AST_FLAG_OUTGOING =      (1 << 10),
00915    /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
00916    AST_FLAG_IN_DTMF =       (1 << 12),
00917    /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
00918     *  currently being emulated */
00919    AST_FLAG_EMULATE_DTMF =  (1 << 13),
00920    /*! This is set to tell the channel not to generate DTMF begin frames, and
00921     *  to instead only generate END frames. */
00922    AST_FLAG_END_DTMF_ONLY = (1 << 14),
00923    /*! Flag to show channels that this call is hangup due to the fact that the call
00924        was indeed answered, but in another channel */
00925    AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15),
00926    /*! This flag indicates that on a masquerade, an active stream should not
00927     *  be carried over */
00928    AST_FLAG_MASQ_NOSTREAM = (1 << 16),
00929    /*! This flag indicates that the hangup exten was run when the bridge terminated,
00930     *  a message aimed at preventing a subsequent hangup exten being run at the pbx_run
00931     *  level */
00932    AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 17),
00933    /*! This flag indicates that the hangup exten should NOT be run when the
00934     *  bridge terminates, this will allow the hangup in the pbx loop to be run instead.
00935     *  */
00936    AST_FLAG_BRIDGE_HANGUP_DONT = (1 << 18),
00937    /*! Disable certain workarounds.  This reintroduces certain bugs, but allows
00938     *  some non-traditional dialplans (like AGI) to continue to function.
00939     */
00940    AST_FLAG_DISABLE_WORKAROUNDS = (1 << 20),
00941    /*! Disable device state event caching.  This allows allows channel
00942     * drivers to selectively prevent device state events from being cached
00943     * by certain channels such as anonymous calls which have no persistent
00944     * represenatation that can be tracked.
00945     */
00946    AST_FLAG_DISABLE_DEVSTATE_CACHE = (1 << 21),
00947 };
00948 
00949 /*! \brief ast_bridge_config flags */
00950 enum {
00951    AST_FEATURE_PLAY_WARNING = (1 << 0),
00952    AST_FEATURE_REDIRECT =     (1 << 1),
00953    AST_FEATURE_DISCONNECT =   (1 << 2),
00954    AST_FEATURE_ATXFER =       (1 << 3),
00955    AST_FEATURE_AUTOMON =      (1 << 4),
00956    AST_FEATURE_PARKCALL =     (1 << 5),
00957    AST_FEATURE_AUTOMIXMON =   (1 << 6),
00958    AST_FEATURE_NO_H_EXTEN =   (1 << 7),
00959    AST_FEATURE_WARNING_ACTIVE = (1 << 8),
00960 };
00961 
00962 /*! \brief bridge configuration */
00963 struct ast_bridge_config {
00964    struct ast_flags features_caller;
00965    struct ast_flags features_callee;
00966    struct timeval start_time;
00967    struct timeval nexteventts;
00968    struct timeval feature_start_time;
00969    long feature_timer;
00970    long timelimit;
00971    long play_warning;
00972    long warning_freq;
00973    const char *warning_sound;
00974    const char *end_sound;
00975    const char *start_sound;
00976    unsigned int flags;
00977    void (* end_bridge_callback)(void *);   /*!< A callback that is called after a bridge attempt */
00978    void *end_bridge_callback_data;         /*!< Data passed to the callback */
00979    /*! If the end_bridge_callback_data refers to a channel which no longer is going to
00980     * exist when the end_bridge_callback is called, then it needs to be fixed up properly
00981     */
00982    void (*end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator);
00983 };
00984 
00985 struct chanmon;
00986 
00987 struct outgoing_helper {
00988    const char *context;
00989    const char *exten;
00990    int priority;
00991    const char *cid_num;
00992    const char *cid_name;
00993    const char *account;
00994    struct ast_variable *vars;
00995    struct ast_channel *parent_channel;
00996 };
00997 
00998 enum {
00999    /*!
01000     * Soft hangup requested by device or other internal reason.
01001     * Actual hangup needed.
01002     */
01003    AST_SOFTHANGUP_DEV =       (1 << 0),
01004    /*!
01005     * Used to break the normal frame flow so an async goto can be
01006     * done instead of actually hanging up.
01007     */
01008    AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
01009    /*!
01010     * Soft hangup requested by system shutdown.  Actual hangup
01011     * needed.
01012     */
01013    AST_SOFTHANGUP_SHUTDOWN =  (1 << 2),
01014    /*!
01015     * Used to break the normal frame flow after a timeout so an
01016     * implicit async goto can be done to the 'T' exten if it exists
01017     * instead of actually hanging up.  If the exten does not exist
01018     * then actually hangup.
01019     */
01020    AST_SOFTHANGUP_TIMEOUT =   (1 << 3),
01021    /*!
01022     * Soft hangup requested by application/channel-driver being
01023     * unloaded.  Actual hangup needed.
01024     */
01025    AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
01026    /*!
01027     * Soft hangup requested by non-associated party.  Actual hangup
01028     * needed.
01029     */
01030    AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
01031    /*!
01032     * Used to break a bridge so the channel can be spied upon
01033     * instead of actually hanging up.
01034     */
01035    AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
01036 
01037 
01038    /*!
01039     * \brief All softhangup flags.
01040     *
01041     * This can be used as an argument to ast_channel_softhangup_clear
01042     * to clear all softhangup flags from a channel.
01043     */
01044    AST_SOFTHANGUP_ALL =       (0xFFFFFFFF)
01045 };
01046 
01047 
01048 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
01049 enum channelreloadreason {
01050    CHANNEL_MODULE_LOAD,
01051    CHANNEL_MODULE_RELOAD,
01052    CHANNEL_CLI_RELOAD,
01053    CHANNEL_MANAGER_RELOAD,
01054 };
01055 
01056 /*!
01057  * \note None of the datastore API calls lock the ast_channel they are using.
01058  *       So, the channel should be locked before calling the functions that
01059  *       take a channel argument.
01060  */
01061 
01062 /*!
01063  * \brief Create a channel data store object
01064  * \deprecated You should use the ast_datastore_alloc() generic function instead.
01065  * \version 1.6.1 deprecated
01066  */
01067 struct ast_datastore * attribute_malloc ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
01068    __attribute__((deprecated));
01069 
01070 /*!
01071  * \brief Free a channel data store object
01072  * \deprecated You should use the ast_datastore_free() generic function instead.
01073  * \version 1.6.1 deprecated
01074  */
01075 int ast_channel_datastore_free(struct ast_datastore *datastore)
01076    __attribute__((deprecated));
01077 
01078 /*! \brief Inherit datastores from a parent to a child. */
01079 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
01080 
01081 /*!
01082  * \brief Add a datastore to a channel
01083  *
01084  * \note The channel should be locked before calling this function.
01085  *
01086  * \retval 0 success
01087  * \retval non-zero failure
01088  */
01089 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
01090 
01091 /*!
01092  * \brief Remove a datastore from a channel
01093  *
01094  * \note The channel should be locked before calling this function.
01095  *
01096  * \retval 0 success
01097  * \retval non-zero failure
01098  */
01099 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
01100 
01101 /*!
01102  * \brief Find a datastore on a channel
01103  *
01104  * \note The channel should be locked before calling this function.
01105  *
01106  * \note The datastore returned from this function must not be used if the
01107  *       reference to the channel is released.
01108  *
01109  * \retval pointer to the datastore if found
01110  * \retval NULL if not found
01111  */
01112 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid);
01113 
01114 /*!
01115  * \brief Create a channel structure
01116  * \since 1.8
01117  *
01118  * \retval NULL failure
01119  * \retval non-NULL successfully allocated channel
01120  *
01121  * \note Absolutely _NO_ channel locks should be held before calling this function.
01122  * \note By default, new channels are set to the "s" extension
01123  *       and "default" context.
01124  */
01125 struct ast_channel * attribute_malloc __attribute__((format(printf, 13, 14)))
01126    __ast_channel_alloc(int needqueue, int state, const char *cid_num,
01127              const char *cid_name, const char *acctcode,
01128              const char *exten, const char *context,
01129              const char *linkedid, const int amaflag,
01130              const char *file, int line, const char *function,
01131              const char *name_fmt, ...);
01132 
01133 /*!
01134  * \brief Create a channel structure
01135  *
01136  * \retval NULL failure
01137  * \retval non-NULL successfully allocated channel
01138  *
01139  * \note Absolutely _NO_ channel locks should be held before calling this function.
01140  * \note By default, new channels are set to the "s" extension
01141  *       and "default" context.
01142  */
01143 #define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag, ...) \
01144    __ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag, \
01145              __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
01146 
01147 #if defined(REF_DEBUG) || defined(__AST_DEBUG_MALLOC)
01148 /*!
01149  * \brief Create a fake channel structure
01150  *
01151  * \retval NULL failure
01152  * \retval non-NULL successfully allocated channel
01153  *
01154  * \note This function should ONLY be used to create a fake channel
01155  *       that can then be populated with data for use in variable
01156  *       substitution when a real channel does not exist.
01157  *
01158  * \note The created dummy channel should be destroyed by
01159  * ast_channel_unref().  Using ast_channel_release() needlessly
01160  * grabs the channel container lock and can cause a deadlock as
01161  * a result.  Also grabbing the channel container lock reduces
01162  * system performance.
01163  */
01164 #define ast_dummy_channel_alloc()   __ast_dummy_channel_alloc(__FILE__, __LINE__, __PRETTY_FUNCTION__)
01165 struct ast_channel *__ast_dummy_channel_alloc(const char *file, int line, const char *function);
01166 #else
01167 /*!
01168  * \brief Create a fake channel structure
01169  *
01170  * \retval NULL failure
01171  * \retval non-NULL successfully allocated channel
01172  *
01173  * \note This function should ONLY be used to create a fake channel
01174  *       that can then be populated with data for use in variable
01175  *       substitution when a real channel does not exist.
01176  *
01177  * \note The created dummy channel should be destroyed by
01178  * ast_channel_unref().  Using ast_channel_release() needlessly
01179  * grabs the channel container lock and can cause a deadlock as
01180  * a result.  Also grabbing the channel container lock reduces
01181  * system performance.
01182  */
01183 struct ast_channel *ast_dummy_channel_alloc(void);
01184 #endif
01185 
01186 /*!
01187  * \brief Queue one or more frames to a channel's frame queue
01188  *
01189  * \param chan the channel to queue the frame(s) on
01190  * \param f the frame(s) to queue.  Note that the frame(s) will be duplicated
01191  *        by this function.  It is the responsibility of the caller to handle
01192  *        freeing the memory associated with the frame(s) being passed if
01193  *        necessary.
01194  *
01195  * \retval 0 success
01196  * \retval non-zero failure
01197  */
01198 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
01199 
01200 /*!
01201  * \brief Queue one or more frames to the head of a channel's frame queue
01202  *
01203  * \param chan the channel to queue the frame(s) on
01204  * \param f the frame(s) to queue.  Note that the frame(s) will be duplicated
01205  *        by this function.  It is the responsibility of the caller to handle
01206  *        freeing the memory associated with the frame(s) being passed if
01207  *        necessary.
01208  *
01209  * \retval 0 success
01210  * \retval non-zero failure
01211  */
01212 int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f);
01213 
01214 /*!
01215  * \brief Queue a hangup frame
01216  *
01217  * \note The channel does not need to be locked before calling this function.
01218  */
01219 int ast_queue_hangup(struct ast_channel *chan);
01220 
01221 /*!
01222  * \brief Queue a hangup frame with hangupcause set
01223  *
01224  * \note The channel does not need to be locked before calling this function.
01225  * \param[in] chan channel to queue frame onto
01226  * \param[in] cause the hangup cause
01227  * \return 0 on success, -1 on error
01228  * \since 1.6.1
01229  */
01230 int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause);
01231 
01232 /*!
01233  * \brief Queue a control frame with payload
01234  *
01235  * \param chan channel to queue frame onto
01236  * \param control type of control frame
01237  *
01238  * \note The channel does not need to be locked before calling this function.
01239  *
01240  * \retval zero on success
01241  * \retval non-zero on failure
01242  */
01243 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
01244 
01245 /*!
01246  * \brief Queue a control frame with payload
01247  *
01248  * \param chan channel to queue frame onto
01249  * \param control type of control frame
01250  * \param data pointer to payload data to be included in frame
01251  * \param datalen number of bytes of payload data
01252  *
01253  * \retval 0 success
01254  * \retval non-zero failure
01255  *
01256  * \details
01257  * The supplied payload data is copied into the frame, so the caller's copy
01258  * is not modified nor freed, and the resulting frame will retain a copy of
01259  * the data even if the caller frees their local copy.
01260  *
01261  * \note This method should be treated as a 'network transport'; in other
01262  * words, your frames may be transferred across an IAX2 channel to another
01263  * system, which may be a different endianness than yours. Because of this,
01264  * you should ensure that either your frames will never be expected to work
01265  * across systems, or that you always put your payload data into 'network byte
01266  * order' before calling this function.
01267  *
01268  * \note The channel does not need to be locked before calling this function.
01269  */
01270 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
01271             const void *data, size_t datalen);
01272 
01273 /*!
01274  * \brief Change channel name
01275  *
01276  * \pre Absolutely all channels _MUST_ be unlocked before calling this function.
01277  *
01278  * \param chan the channel to change the name of
01279  * \param newname the name to change to
01280  *
01281  * \return nothing
01282  *
01283  * \note this function must _NEVER_ be used when any channels are locked
01284  * regardless if it is the channel who's name is being changed or not because
01285  * it invalidates our channel container locking order... lock container first,
01286  * then the individual channels, never the other way around.
01287  */
01288 void ast_change_name(struct ast_channel *chan, const char *newname);
01289 
01290 /*!
01291  * \brief Unlink and release reference to a channel
01292  *
01293  * This function will unlink the channel from the global channels container
01294  * if it is still there and also release the current reference to the channel.
01295  *
01296  * \return NULL, convenient for clearing invalid pointers
01297  * \note Absolutely _NO_ channel locks should be held before calling this function.
01298  *
01299  * \since 1.8
01300  */
01301 struct ast_channel *ast_channel_release(struct ast_channel *chan);
01302 
01303 /*!
01304  * \brief Requests a channel
01305  *
01306  * \param type type of channel to request
01307  * \param format requested channel format (codec)
01308  * \param requestor channel asking for data
01309  * \param data data to pass to the channel requester (Should be treated as const char *)
01310  * \param status status
01311  *
01312  * \details
01313  * Request a channel of a given type, with data as optional information used
01314  * by the low level module
01315  *
01316  * \retval NULL failure
01317  * \retval non-NULL channel on success
01318  */
01319 struct ast_channel *ast_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *status);
01320 
01321 /*!
01322  * \brief Request a channel of a given type, with data as optional information used
01323  *        by the low level module and attempt to place a call on it
01324  *
01325  * \param type type of channel to request
01326  * \param format requested channel format
01327  * \param requestor channel asking for data
01328  * \param data data to pass to the channel requester
01329  * \param timeout maximum amount of time to wait for an answer
01330  * \param reason why unsuccessful (if unsuccessful)
01331  * \param cid_num Caller-ID Number
01332  * \param cid_name Caller-ID Name (ascii)
01333  *
01334  * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
01335  * to know if the call was answered or not.
01336  */
01337 struct ast_channel *ast_request_and_dial(const char *type, format_t format, const struct ast_channel *requestor, void *data,
01338    int timeout, int *reason, const char *cid_num, const char *cid_name);
01339 
01340 /*!
01341  * \brief Request a channel of a given type, with data as optional information used
01342  * by the low level module and attempt to place a call on it
01343  * \param type type of channel to request
01344  * \param format requested channel format
01345  * \param requestor channel requesting data
01346  * \param data data to pass to the channel requester
01347  * \param timeout maximum amount of time to wait for an answer
01348  * \param reason why unsuccessful (if unsuccessful)
01349  * \param cid_num Caller-ID Number
01350  * \param cid_name Caller-ID Name (ascii)
01351  * \param oh Outgoing helper
01352  * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
01353  * to know if the call was answered or not.
01354  */
01355 struct ast_channel *__ast_request_and_dial(const char *type, format_t format, const struct ast_channel *requestor, void *data,
01356    int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh);
01357 
01358 /*!
01359  * \brief Forwards a call to a new channel specified by the original channel's call_forward str.  If possible, the new forwarded channel is created and returned while the original one is terminated.
01360  * \param caller in channel that requested orig
01361  * \param orig channel being replaced by the call forward channel
01362  * \param timeout maximum amount of time to wait for setup of new forward channel
01363  * \param format requested channel format
01364  * \param oh outgoing helper used with original channel
01365  * \param outstate reason why unsuccessful (if uncuccessful)
01366  * \return Returns the forwarded call's ast_channel on success or NULL on failure
01367  */
01368 struct ast_channel *ast_call_forward(struct ast_channel *caller, struct ast_channel *orig, int *timeout, format_t format, struct outgoing_helper *oh, int *outstate);
01369 
01370 /*!
01371  * \brief Register a channel technology (a new channel driver)
01372  * Called by a channel module to register the kind of channels it supports.
01373  * \param tech Structure defining channel technology or "type"
01374  * \return Returns 0 on success, -1 on failure.
01375  */
01376 int ast_channel_register(const struct ast_channel_tech *tech);
01377 
01378 /*!
01379  * \brief Unregister a channel technology
01380  * \param tech Structure defining channel technology or "type" that was previously registered
01381  * \return No return value.
01382  */
01383 void ast_channel_unregister(const struct ast_channel_tech *tech);
01384 
01385 /*!
01386  * \brief Get a channel technology structure by name
01387  * \param name name of technology to find
01388  * \return a pointer to the structure, or NULL if no matching technology found
01389  */
01390 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
01391 
01392 #ifdef CHANNEL_TRACE
01393 /*!
01394  * \brief Update the context backtrace if tracing is enabled
01395  * \return Returns 0 on success, -1 on failure
01396  */
01397 int ast_channel_trace_update(struct ast_channel *chan);
01398 
01399 /*!
01400  * \brief Enable context tracing in the channel
01401  * \return Returns 0 on success, -1 on failure
01402  */
01403 int ast_channel_trace_enable(struct ast_channel *chan);
01404 
01405 /*!
01406  * \brief Disable context tracing in the channel.
01407  * \note Does not remove current trace entries
01408  * \return Returns 0 on success, -1 on failure
01409  */
01410 int ast_channel_trace_disable(struct ast_channel *chan);
01411 
01412 /*!
01413  * \brief Whether or not context tracing is enabled
01414  * \return Returns -1 when the trace is enabled. 0 if not.
01415  */
01416 int ast_channel_trace_is_enabled(struct ast_channel *chan);
01417 
01418 /*!
01419  * \brief Put the channel backtrace in a string
01420  * \return Returns the amount of lines in the backtrace. -1 on error.
01421  */
01422 int ast_channel_trace_serialize(struct ast_channel *chan, struct ast_str **out);
01423 #endif
01424 
01425 /*!
01426  * \brief Hang up a channel
01427  * \note Absolutely _NO_ channel locks should be held before calling this function.
01428  * \note This function performs a hard hangup on a channel.  Unlike the soft-hangup, this function
01429  * performs all stream stopping, etc, on the channel that needs to end.
01430  * chan is no longer valid after this call.
01431  * \param chan channel to hang up
01432  * \return Returns 0 on success, -1 on failure.
01433  */
01434 int ast_hangup(struct ast_channel *chan);
01435 
01436 /*!
01437  * \brief Softly hangup up a channel
01438  *
01439  * \param chan channel to be soft-hung-up
01440  * \param reason an AST_SOFTHANGUP_* reason code
01441  *
01442  * \details
01443  * Call the protocol layer, but don't destroy the channel structure
01444  * (use this if you are trying to
01445  * safely hangup a channel managed by another thread.
01446  *
01447  * \note The channel passed to this function does not need to be locked.
01448  *
01449  * \return Returns 0 regardless
01450  */
01451 int ast_softhangup(struct ast_channel *chan, int reason);
01452 
01453 /*!
01454  * \brief Softly hangup up a channel (no channel lock)
01455  * \param chan channel to be soft-hung-up
01456  * \param reason an AST_SOFTHANGUP_* reason code
01457  */
01458 int ast_softhangup_nolock(struct ast_channel *chan, int reason);
01459 
01460 /*!
01461  * \brief Clear a set of softhangup flags from a channel
01462  *
01463  * Never clear a softhangup flag from a channel directly.  Instead,
01464  * use this function.  This ensures that all aspects of the softhangup
01465  * process are aborted.
01466  *
01467  * \param chan the channel to clear the flag on
01468  * \param flag the flag or flags to clear
01469  *
01470  * \return Nothing.
01471  */
01472 void ast_channel_clear_softhangup(struct ast_channel *chan, int flag);
01473 
01474 /*!
01475  * \brief Set the source of the hangup in this channel and it's bridge
01476  *
01477  * \param chan channel to set the field on
01478  * \param source a string describing the source of the hangup for this channel
01479  * \param force
01480  *
01481  * \note Absolutely _NO_ channel locks should be held before calling this function.
01482  *
01483  * \since 1.8
01484  *
01485  * Hangupsource is generally the channel name that caused the bridge to be
01486  * hung up, but it can also be other things such as "dialplan/agi"
01487  * This can then be logged in the CDR or CEL
01488  */
01489 void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force);
01490 
01491 /*! \brief Check to see if a channel is needing hang up
01492  * \param chan channel on which to check for hang up
01493  * This function determines if the channel is being requested to be hung up.
01494  * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
01495  */
01496 int ast_check_hangup(struct ast_channel *chan);
01497 
01498 int ast_check_hangup_locked(struct ast_channel *chan);
01499 
01500 /*!
01501  * \brief Compare a offset with the settings of when to hang a channel up
01502  * \param chan channel on which to check for hang up
01503  * \param offset offset in seconds from current time
01504  * \return 1, 0, or -1
01505  * \details
01506  * This function compares a offset from current time with the absolute time
01507  * out on a channel (when to hang up). If the absolute time out on a channel
01508  * is earlier than current time plus the offset, it returns 1, if the two
01509  * time values are equal, it return 0, otherwise, it return -1.
01510  * \sa ast_channel_cmpwhentohangup_tv()
01511  * \version 1.6.1 deprecated function (only had seconds precision)
01512  */
01513 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
01514 
01515 /*!
01516  * \brief Compare a offset with the settings of when to hang a channel up
01517  * \param chan channel on which to check for hangup
01518  * \param offset offset in seconds and microseconds from current time
01519  * \return 1, 0, or -1
01520  * This function compares a offset from current time with the absolute time
01521  * out on a channel (when to hang up). If the absolute time out on a channel
01522  * is earlier than current time plus the offset, it returns 1, if the two
01523  * time values are equal, it return 0, otherwise, it return -1.
01524  * \since 1.6.1
01525  */
01526 int ast_channel_cmpwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
01527 
01528 /*!
01529  * \brief Set when to hang a channel up
01530  *
01531  * \param chan channel on which to check for hang up
01532  * \param offset offset in seconds relative to the current time of when to hang up
01533  *
01534  * \details
01535  * This function sets the absolute time out on a channel (when to hang up).
01536  *
01537  * \note This function does not require that the channel is locked before
01538  *       calling it.
01539  *
01540  * \return Nothing
01541  * \sa ast_channel_setwhentohangup_tv()
01542  * \version 1.6.1 deprecated function (only had seconds precision)
01543  */
01544 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
01545 
01546 /*!
01547  * \brief Set when to hang a channel up
01548  *
01549  * \param chan channel on which to check for hang up
01550  * \param offset offset in seconds and useconds relative to the current time of when to hang up
01551  *
01552  * This function sets the absolute time out on a channel (when to hang up).
01553  *
01554  * \note This function does not require that the channel is locked before
01555  * calling it.
01556  *
01557  * \return Nothing
01558  * \since 1.6.1
01559  */
01560 void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
01561 
01562 /*!
01563  * \brief Answer a channel
01564  *
01565  * \param chan channel to answer
01566  *
01567  * \details
01568  * This function answers a channel and handles all necessary call
01569  * setup functions.
01570  *
01571  * \note The channel passed does not need to be locked, but is locked
01572  * by the function when needed.
01573  *
01574  * \note This function will wait up to 500 milliseconds for media to
01575  * arrive on the channel before returning to the caller, so that the
01576  * caller can properly assume the channel is 'ready' for media flow.
01577  *
01578  * \retval 0 on success
01579  * \retval non-zero on failure
01580  */
01581 int ast_answer(struct ast_channel *chan);
01582 
01583 /*!
01584  * \brief Answer a channel
01585  *
01586  * \param chan channel to answer
01587  * \param cdr_answer flag to control whether any associated CDR should be marked as 'answered'
01588  *
01589  * This function answers a channel and handles all necessary call
01590  * setup functions.
01591  *
01592  * \note The channel passed does not need to be locked, but is locked
01593  * by the function when needed.
01594  *
01595  * \note Unlike ast_answer(), this function will not wait for media
01596  * flow to begin. The caller should be careful before sending media
01597  * to the channel before incoming media arrives, as the outgoing
01598  * media may be lost.
01599  *
01600  * \retval 0 on success
01601  * \retval non-zero on failure
01602  */
01603 int ast_raw_answer(struct ast_channel *chan, int cdr_answer);
01604 
01605 /*!
01606  * \brief Answer a channel, with a selectable delay before returning
01607  *
01608  * \param chan channel to answer
01609  * \param delay maximum amount of time to wait for incoming media
01610  * \param cdr_answer flag to control whether any associated CDR should be marked as 'answered'
01611  *
01612  * This function answers a channel and handles all necessary call
01613  * setup functions.
01614  *
01615  * \note The channel passed does not need to be locked, but is locked
01616  * by the function when needed.
01617  *
01618  * \note This function will wait up to 'delay' milliseconds for media to
01619  * arrive on the channel before returning to the caller, so that the
01620  * caller can properly assume the channel is 'ready' for media flow. If
01621  * 'delay' is less than 500, the function will wait up to 500 milliseconds.
01622  *
01623  * \retval 0 on success
01624  * \retval non-zero on failure
01625  */
01626 int __ast_answer(struct ast_channel *chan, unsigned int delay, int cdr_answer);
01627 
01628 /*!
01629  * \brief Make a call
01630  * \note Absolutely _NO_ channel locks should be held before calling this function.
01631  * \param chan which channel to make the call on
01632  * \param addr destination of the call (Should be treated as const char *)
01633  * \param timeout time to wait on for connect
01634  * \details
01635  * Place a call, take no longer than timeout ms.
01636  * \return -1 on failure, 0 on not enough time
01637  * (does not automatically stop ringing), and
01638  * the number of seconds the connect took otherwise.
01639  */
01640 int ast_call(struct ast_channel *chan, char *addr, int timeout);
01641 
01642 /*!
01643  * \brief Indicates condition of channel
01644  * \note Absolutely _NO_ channel locks should be held before calling this function.
01645  * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
01646  * \param chan channel to change the indication
01647  * \param condition which condition to indicate on the channel
01648  * \return Returns 0 on success, -1 on failure
01649  */
01650 int ast_indicate(struct ast_channel *chan, int condition);
01651 
01652 /*!
01653  * \brief Indicates condition of channel, with payload
01654  * \note Absolutely _NO_ channel locks should be held before calling this function.
01655  * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
01656  * \param chan channel to change the indication
01657  * \param condition which condition to indicate on the channel
01658  * \param data pointer to payload data
01659  * \param datalen size of payload data
01660  * \return Returns 0 on success, -1 on failure
01661  */
01662 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
01663 
01664 /* Misc stuff ------------------------------------------------ */
01665 
01666 /*!
01667  * \brief Wait for input on a channel
01668  * \param chan channel to wait on
01669  * \param ms length of time to wait on the channel
01670  * \details
01671  * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
01672  * \retval < 0 on failure
01673  * \retval 0 if nothing ever arrived
01674  * \retval the # of ms remaining otherwise
01675  */
01676 int ast_waitfor(struct ast_channel *chan, int ms);
01677 
01678 /*!
01679  * \brief Should we keep this frame for later?
01680  *
01681  * There are functions such as ast_safe_sleep which will
01682  * service a channel to ensure that it does not have a
01683  * large backlog of queued frames. When this happens,
01684  * we want to hold on to specific frame types and just drop
01685  * others. This function will tell if the frame we just
01686  * read should be held onto.
01687  *
01688  * \param frame The frame we just read
01689  * \retval 1 frame should be kept
01690  * \retval 0 frame should be dropped
01691  */
01692 int ast_is_deferrable_frame(const struct ast_frame *frame);
01693 
01694 /*!
01695  * \brief Wait for a specified amount of time, looking for hangups
01696  * \param chan channel to wait for
01697  * \param ms length of time in milliseconds to sleep. This should never be less than zero.
01698  * \details
01699  * Waits for a specified amount of time, servicing the channel as required.
01700  * \return returns -1 on hangup, otherwise 0.
01701  */
01702 int ast_safe_sleep(struct ast_channel *chan, int ms);
01703 
01704 /*!
01705  * \brief Wait for a specified amount of time, looking for hangups and a condition argument
01706  * \param chan channel to wait for
01707  * \param ms length of time in milliseconds to sleep.
01708  * \param cond a function pointer for testing continue condition
01709  * \param data argument to be passed to the condition test function
01710  * \return returns -1 on hangup, otherwise 0.
01711  * \details
01712  * Waits for a specified amount of time, servicing the channel as required. If cond
01713  * returns 0, this function returns.
01714  */
01715 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
01716 
01717 /*!
01718  * \brief Waits for activity on a group of channels
01719  * \param chan an array of pointers to channels
01720  * \param n number of channels that are to be waited upon
01721  * \param fds an array of fds to wait upon
01722  * \param nfds the number of fds to wait upon
01723  * \param exception exception flag
01724  * \param outfd fd that had activity on it
01725  * \param ms how long the wait was
01726  * \details
01727  * Big momma function here.  Wait for activity on any of the n channels, or any of the nfds
01728  * file descriptors.
01729  * \return Returns the channel with activity, or NULL on error or if an FD
01730  * came first.  If the FD came first, it will be returned in outfd, otherwise, outfd
01731  * will be -1
01732  */
01733 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n,
01734    int *fds, int nfds, int *exception, int *outfd, int *ms);
01735 
01736 /*!
01737  * \brief Waits for input on a group of channels
01738  * Wait for input on an array of channels for a given # of milliseconds.
01739  * \return Return channel with activity, or NULL if none has activity.
01740  * \param chan an array of pointers to channels
01741  * \param n number of channels that are to be waited upon
01742  * \param ms time "ms" is modified in-place, if applicable
01743  */
01744 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
01745 
01746 /*!
01747  * \brief Waits for input on an fd
01748  * \note This version works on fd's only.  Be careful with it.
01749  */
01750 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
01751 
01752 
01753 /*!
01754  * \brief Reads a frame
01755  * \param chan channel to read a frame from
01756  * \return Returns a frame, or NULL on error.  If it returns NULL, you
01757  * best just stop reading frames and assume the channel has been
01758  * disconnected.
01759  */
01760 struct ast_frame *ast_read(struct ast_channel *chan);
01761 
01762 /*!
01763  * \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
01764  * \param chan channel to read a frame from
01765  * \return  Returns a frame, or NULL on error.  If it returns NULL, you
01766  * best just stop reading frames and assume the channel has been
01767  * disconnected.
01768  * \note Audio is replaced with AST_FRAME_NULL to avoid
01769  * transcode when the resulting audio is not necessary.
01770  */
01771 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
01772 
01773 /*!
01774  * \brief Write a frame to a channel
01775  * This function writes the given frame to the indicated channel.
01776  * \param chan destination channel of the frame
01777  * \param frame frame that will be written
01778  * \return It returns 0 on success, -1 on failure.
01779  */
01780 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
01781 
01782 /*!
01783  * \brief Write video frame to a channel
01784  * This function writes the given frame to the indicated channel.
01785  * \param chan destination channel of the frame
01786  * \param frame frame that will be written
01787  * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
01788  */
01789 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
01790 
01791 /*!
01792  * \brief Write text frame to a channel
01793  * This function writes the given frame to the indicated channel.
01794  * \param chan destination channel of the frame
01795  * \param frame frame that will be written
01796  * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
01797  */
01798 int ast_write_text(struct ast_channel *chan, struct ast_frame *frame);
01799 
01800 /*! \brief Send empty audio to prime a channel driver */
01801 int ast_prod(struct ast_channel *chan);
01802 
01803 /*!
01804  * \brief Sets read format on channel chan
01805  * Set read format for channel to whichever component of "format" is best.
01806  * \param chan channel to change
01807  * \param format format to change to
01808  * \return Returns 0 on success, -1 on failure
01809  */
01810 int ast_set_read_format(struct ast_channel *chan, format_t format);
01811 
01812 /*!
01813  * \brief Sets write format on channel chan
01814  * Set write format for channel to whichever component of "format" is best.
01815  * \param chan channel to change
01816  * \param format new format for writing
01817  * \return Returns 0 on success, -1 on failure
01818  */
01819 int ast_set_write_format(struct ast_channel *chan, format_t format);
01820 
01821 /*!
01822  * \brief Sends text to a channel
01823  *
01824  * \param chan channel to act upon
01825  * \param text string of text to send on the channel
01826  *
01827  * \details
01828  * Write text to a display on a channel
01829  *
01830  * \note The channel does not need to be locked before calling this function.
01831  *
01832  * \retval 0 on success
01833  * \retval -1 on failure
01834  */
01835 int ast_sendtext(struct ast_channel *chan, const char *text);
01836 
01837 /*!
01838  * \brief Receives a text character from a channel
01839  * \param chan channel to act upon
01840  * \param timeout timeout in milliseconds (0 for infinite wait)
01841  * \details
01842  * Read a char of text from a channel
01843  * \return 0 on success, -1 on failure
01844  */
01845 int ast_recvchar(struct ast_channel *chan, int timeout);
01846 
01847 /*!
01848  * \brief Send a DTMF digit to a channel.
01849  * \param chan channel to act upon
01850  * \param digit the DTMF digit to send, encoded in ASCII
01851  * \param duration the duration of the digit ending in ms
01852  * \return 0 on success, -1 on failure
01853  */
01854 int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration);
01855 
01856 /*!
01857  * \brief Send a DTMF digit to a channel.
01858  * \param chan channel to act upon
01859  * \param digit the DTMF digit to send, encoded in ASCII
01860  * \return 0 on success, -1 on failure
01861  */
01862 int ast_senddigit_begin(struct ast_channel *chan, char digit);
01863 
01864 /*!
01865  * \brief Send a DTMF digit to a channel.
01866  * \param chan channel to act upon
01867  * \param digit the DTMF digit to send, encoded in ASCII
01868  * \param duration the duration of the digit ending in ms
01869  * \return Returns 0 on success, -1 on failure
01870  */
01871 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
01872 
01873 /*!
01874  * \brief Receives a text string from a channel
01875  * Read a string of text from a channel
01876  * \param chan channel to act upon
01877  * \param timeout timeout in milliseconds (0 for infinite wait)
01878  * \return the received text, or NULL to signify failure.
01879  */
01880 char *ast_recvtext(struct ast_channel *chan, int timeout);
01881 
01882 /*!
01883  * \brief Waits for a digit
01884  * \param c channel to wait for a digit on
01885  * \param ms how many milliseconds to wait (<0 for indefinite).
01886  * \return Returns <0 on error, 0 on no entry, and the digit on success.
01887  */
01888 int ast_waitfordigit(struct ast_channel *c, int ms);
01889 
01890 /*!
01891  * \brief Wait for a digit
01892  * Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
01893  * \param c channel to wait for a digit on
01894  * \param ms how many milliseconds to wait (<0 for indefinite).
01895  * \param audiofd audio file descriptor to write to if audio frames are received
01896  * \param ctrlfd control file descriptor to monitor for reading
01897  * \return Returns 1 if ctrlfd becomes available
01898  */
01899 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
01900 
01901 /*!
01902  * \brief Reads multiple digits
01903  * \param c channel to read from
01904  * \param s string to read in to.  Must be at least the size of your length
01905  * \param len how many digits to read (maximum)
01906  * \param timeout how long to timeout between digits
01907  * \param rtimeout timeout to wait on the first digit
01908  * \param enders digits to end the string
01909  * \details
01910  * Read in a digit string "s", max length "len", maximum timeout between
01911  * digits "timeout" (-1 for none), terminated by anything in "enders".  Give them rtimeout
01912  * for the first digit.
01913  * \return Returns 0 on normal return, or 1 on a timeout.  In the case of
01914  * a timeout, any digits that were read before the timeout will still be available in s.
01915  * RETURNS 2 in full version when ctrlfd is available, NOT 1
01916  */
01917 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
01918 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
01919 
01920 /*! \brief Report DTMF on channel 0 */
01921 #define AST_BRIDGE_DTMF_CHANNEL_0      (1 << 0)
01922 /*! \brief Report DTMF on channel 1 */
01923 #define AST_BRIDGE_DTMF_CHANNEL_1      (1 << 1)
01924 /*! \brief Return all voice frames on channel 0 */
01925 #define AST_BRIDGE_REC_CHANNEL_0    (1 << 2)
01926 /*! \brief Return all voice frames on channel 1 */
01927 #define AST_BRIDGE_REC_CHANNEL_1    (1 << 3)
01928 /*! \brief Ignore all signal frames except NULL */
01929 #define AST_BRIDGE_IGNORE_SIGS         (1 << 4)
01930 
01931 
01932 /*!
01933  * \brief Makes two channel formats compatible
01934  * \param c0 first channel to make compatible
01935  * \param c1 other channel to make compatible
01936  * \details
01937  * Set two channels to compatible formats -- call before ast_channel_bridge in general.
01938  * \return Returns 0 on success and -1 if it could not be done
01939  */
01940 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
01941 
01942 /*!
01943  * \brief Bridge two channels together (early)
01944  * \param c0 first channel to bridge
01945  * \param c1 second channel to bridge
01946  * \details
01947  * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
01948  * \return Returns 0 on success and -1 if it could not be done
01949  */
01950 int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
01951 
01952 /*!
01953  * \brief Bridge two channels together
01954  * \param c0 first channel to bridge
01955  * \param c1 second channel to bridge
01956  * \param config config for the channels
01957  * \param fo destination frame(?)
01958  * \param rc destination channel(?)
01959  * \details
01960  * Bridge two channels (c0 and c1) together.  If an important frame occurs, we return that frame in
01961  * *rf (remember, it could be NULL) and which channel (0 or 1) in rc
01962  */
01963 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
01964 int ast_channel_bridge(struct ast_channel *c0,struct ast_channel *c1,
01965    struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc);
01966 
01967 /*!
01968  * \brief Weird function made for call transfers
01969  *
01970  * \param original channel to make a copy of
01971  * \param clone copy of the original channel
01972  *
01973  * \details
01974  * This is a very strange and freaky function used primarily for transfer.  Suppose that
01975  * "original" and "clone" are two channels in random situations.  This function takes
01976  * the guts out of "clone" and puts them into the "original" channel, then alerts the
01977  * channel driver of the change, asking it to fixup any private information (like the
01978  * p->owner pointer) that is affected by the change.  The physical layer of the original
01979  * channel is hung up.
01980  *
01981  * \note Neither channel passed here should be locked before
01982  * calling this function.  This function performs deadlock
01983  * avoidance involving these two channels.
01984  */
01985 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
01986 
01987 /*!
01988  * \brief Setup a masquerade to transfer a call.
01989  * \since 1.8
01990  *
01991  * \param target_chan Target of the call transfer.  (Masquerade original channel)
01992  * \param target_id New connected line information for the target channel.
01993  * \param target_held TRUE if the target call is on hold.
01994  * \param transferee_chan Transferee of the call transfer. (Masquerade clone channel)
01995  * \param transferee_id New connected line information for the transferee channel.
01996  * \param transferee_held TRUE if the transferee call is on hold.
01997  *
01998  * \details
01999  * Party A - Transferee
02000  * Party B - Transferer
02001  * Party C - Target of transfer
02002  *
02003  * Party B transfers A to C.
02004  *
02005  * Party A is connected to bridged channel B1.
02006  * Party B is connected to channels C1 and C2.
02007  * Party C is connected to bridged channel B2.
02008  *
02009  * Party B -- C1 == B1 -- Party A
02010  *               __/
02011  *              /
02012  * Party B -- C2 == B2 -- Party C
02013  *
02014  * Bridged channel B1 is masqueraded into channel C2.  Where B1
02015  * is the masquerade clone channel and C2 is the masquerade
02016  * original channel.
02017  *
02018  * \see ast_channel_masquerade()
02019  *
02020  * \note Has the same locking requirements as ast_channel_masquerade().
02021  *
02022  * \retval 0 on success.
02023  * \retval -1 on error.
02024  */
02025 int ast_channel_transfer_masquerade(
02026    struct ast_channel *target_chan,
02027    const struct ast_party_connected_line *target_id,
02028    int target_held,
02029    struct ast_channel *transferee_chan,
02030    const struct ast_party_connected_line *transferee_id,
02031    int transferee_held);
02032 
02033 /*!
02034  * \brief Gives the string form of a given cause code.
02035  *
02036  * \param state cause to get the description of
02037  * \return the text form of the binary cause code given
02038  */
02039 const char *ast_cause2str(int state) attribute_pure;
02040 
02041 /*!
02042  * \brief Convert the string form of a cause code to a number
02043  *
02044  * \param name string form of the cause
02045  * \return the cause code
02046  */
02047 int ast_str2cause(const char *name) attribute_pure;
02048 
02049 /*!
02050  * \brief Gives the string form of a given channel state
02051  *
02052  * \param ast_channel_state state to get the name of
02053  * \return the text form of the binary state given
02054  */
02055 const char *ast_state2str(enum ast_channel_state);
02056 
02057 /*!
02058  * \brief Gives the string form of a given transfer capability
02059  *
02060  * \param transfercapability transfer capability to get the name of
02061  * \return the text form of the binary transfer capability
02062  */
02063 char *ast_transfercapability2str(int transfercapability) attribute_const;
02064 
02065 /*
02066  * Options: Some low-level drivers may implement "options" allowing fine tuning of the
02067  * low level channel.  See frame.h for options.  Note that many channel drivers may support
02068  * none or a subset of those features, and you should not count on this if you want your
02069  * asterisk application to be portable.  They're mainly useful for tweaking performance
02070  */
02071 
02072 /*!
02073  * \brief Sets an option on a channel
02074  *
02075  * \param channel channel to set options on
02076  * \param option option to change
02077  * \param data data specific to option
02078  * \param datalen length of the data
02079  * \param block blocking or not
02080  * \details
02081  * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
02082  * \return 0 on success and -1 on failure
02083  */
02084 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
02085 
02086 /*! Pick the best codec
02087  * Choose the best codec...  Uhhh...   Yah. */
02088 format_t ast_best_codec(format_t fmts);
02089 
02090 
02091 /*!
02092  * \brief Checks the value of an option
02093  *
02094  * Query the value of an option
02095  * Works similarly to setoption except only reads the options.
02096  */
02097 int ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
02098 
02099 /*!
02100  * \brief Checks for HTML support on a channel
02101  * \return 0 if channel does not support HTML or non-zero if it does
02102  */
02103 int ast_channel_supports_html(struct ast_channel *channel);
02104 
02105 /*!
02106  * \brief Sends HTML on given channel
02107  * Send HTML or URL on link.
02108  * \return 0 on success or -1 on failure
02109  */
02110 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
02111 
02112 /*!
02113  * \brief Sends a URL on a given link
02114  * Send URL on link.
02115  * \return 0 on success or -1 on failure
02116  */
02117 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
02118 
02119 /*!
02120  * \brief Defers DTMF so that you only read things like hangups and audio.
02121  * \return non-zero if channel was already DTMF-deferred or
02122  * 0 if channel is just now being DTMF-deferred
02123  */
02124 int ast_channel_defer_dtmf(struct ast_channel *chan);
02125 
02126 /*! Undo defer.  ast_read will return any DTMF characters that were queued */
02127 void ast_channel_undefer_dtmf(struct ast_channel *chan);
02128 
02129 /*! Initiate system shutdown -- prevents new channels from being allocated.
02130  * \param hangup  If "hangup" is non-zero, all existing channels will receive soft
02131  *  hangups */
02132 void ast_begin_shutdown(int hangup);
02133 
02134 /*! Cancels an existing shutdown and returns to normal operation */
02135 void ast_cancel_shutdown(void);
02136 
02137 /*! \return number of channels available for lookup */
02138 int ast_active_channels(void);
02139 
02140 /*! \return the number of channels not yet destroyed */
02141 int ast_undestroyed_channels(void);
02142 
02143 /*! \return non-zero if Asterisk is being shut down */
02144 int ast_shutting_down(void);
02145 
02146 /*! Activate a given generator */
02147 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
02148 
02149 /*! Deactivate an active generator */
02150 void ast_deactivate_generator(struct ast_channel *chan);
02151 
02152 /*!
02153  * \brief Set caller ID number, name and ANI and generate AMI event.
02154  *
02155  * \note Use ast_channel_set_caller() and ast_channel_set_caller_event() instead.
02156  * \note The channel does not need to be locked before calling this function.
02157  */
02158 void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani);
02159 
02160 /*!
02161  * \brief Set the caller id information in the Asterisk channel
02162  * \since 1.8
02163  *
02164  * \param chan Asterisk channel to set caller id information
02165  * \param caller Caller id information
02166  * \param update What caller information to update.  NULL if all.
02167  *
02168  * \return Nothing
02169  *
02170  * \note The channel does not need to be locked before calling this function.
02171  */
02172 void ast_channel_set_caller(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update);
02173 
02174 /*!
02175  * \brief Set the caller id information in the Asterisk channel and generate an AMI event
02176  * if the caller id name or number changed.
02177  * \since 1.8
02178  *
02179  * \param chan Asterisk channel to set caller id information
02180  * \param caller Caller id information
02181  * \param update What caller information to update.  NULL if all.
02182  *
02183  * \return Nothing
02184  *
02185  * \note The channel does not need to be locked before calling this function.
02186  */
02187 void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update);
02188 
02189 /*! Set the file descriptor on the channel */
02190 void ast_channel_set_fd(struct ast_channel *chan, int which, int fd);
02191 
02192 /*! Add a channel to an optimized waitfor */
02193 void ast_poll_channel_add(struct ast_channel *chan0, struct ast_channel *chan1);
02194 
02195 /*! Delete a channel from an optimized waitfor */
02196 void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1);
02197 
02198 /*! Start a tone going */
02199 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
02200 /*! Stop a tone from playing */
02201 void ast_tonepair_stop(struct ast_channel *chan);
02202 /*! Play a tone pair for a given amount of time */
02203 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
02204 
02205 /*!
02206  * \brief Automatically service a channel for us...
02207  *
02208  * \retval 0 success
02209  * \retval -1 failure, or the channel is already being autoserviced
02210  */
02211 int ast_autoservice_start(struct ast_channel *chan);
02212 
02213 /*!
02214  * \brief Stop servicing a channel for us...
02215  *
02216  * \note if chan is locked prior to calling ast_autoservice_stop, it
02217  * is likely that there will be a deadlock between the thread that calls
02218  * ast_autoservice_stop and the autoservice thread. It is important
02219  * that chan is not locked prior to this call
02220  *
02221  * \param chan
02222  * \retval 0 success
02223  * \retval -1 error, or the channel has been hungup
02224  */
02225 int ast_autoservice_stop(struct ast_channel *chan);
02226 
02227 /*!
02228  * \brief Ignore certain frame types
02229  * \note Normally, we cache DTMF, IMAGE, HTML, TEXT, and CONTROL frames
02230  * while a channel is in autoservice and queue them up when taken out of
02231  * autoservice.  When this is not desireable, this API may be used to
02232  * cause the channel to ignore those frametypes after the channel is put
02233  * into autoservice, but before autoservice is stopped.
02234  * \retval 0 success
02235  * \retval -1 channel is not in autoservice
02236  */
02237 int ast_autoservice_ignore(struct ast_channel *chan, enum ast_frame_type ftype);
02238 
02239 /*!
02240  * \brief Enable or disable timer ticks for a channel
02241  *
02242  * \param c channel
02243  * \param rate number of timer ticks per second
02244  * \param func callback function
02245  * \param data
02246  *
02247  * \details
02248  * If timers are supported, force a scheduled expiration on the
02249  * timer fd, at which point we call the callback function / data
02250  *
02251  * \note Call this function with a rate of 0 to turn off the timer ticks
02252  *
02253  * \version 1.6.1 changed samples parameter to rate, accomodates new timing methods
02254  */
02255 int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data);
02256 
02257 /*!
02258  * \brief Transfer a channel (if supported).
02259  * \retval -1 on error
02260  * \retval 0 if not supported
02261  * \retval 1 if supported and requested
02262  * \param chan current channel
02263  * \param dest destination extension for transfer
02264  */
02265 int ast_transfer(struct ast_channel *chan, char *dest);
02266 
02267 /*!
02268  * \brief Start masquerading a channel
02269  * \note absolutely _NO_ channel locks should be held before calling this function.
02270  * \details
02271  * XXX This is a seriously whacked out operation.  We're essentially putting the guts of
02272  *     the clone channel into the original channel.  Start by killing off the original
02273  *     channel's backend.   I'm not sure we're going to keep this function, because
02274  *     while the features are nice, the cost is very high in terms of pure nastiness. XXX
02275  * \param chan Channel to masquerade
02276  */
02277 int ast_do_masquerade(struct ast_channel *chan);
02278 
02279 /*!
02280  * \brief Find bridged channel
02281  *
02282  * \note This function does _not_ return a reference to the bridged channel.
02283  * The reason for this is mostly historical.  It _should_ return a reference,
02284  * but it will take a lot of work to make the code base account for that.
02285  * So, for now, the old rules still apply for how to handle this function.
02286  * If this function is being used from the channel thread that owns the channel,
02287  * then a reference is already held, and channel locking is not required to
02288  * guarantee that the channel will stay around.  If this function is used
02289  * outside of the associated channel thread, the channel parameter 'chan'
02290  * MUST be locked before calling this function.  Also, 'chan' must remain locked
02291  * for the entire time that the result of this function is being used.
02292  *
02293  * \param chan Current channel
02294  *
02295  * \return A pointer to the bridged channel
02296 */
02297 struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
02298 
02299 /*!
02300  * \brief Inherits channel variable from parent to child channel
02301  * \param parent Parent channel
02302  * \param child Child channel
02303  *
02304  * \details
02305  * Scans all channel variables in the parent channel, looking for those
02306  * that should be copied into the child channel.
02307  * Variables whose names begin with a single '_' are copied into the
02308  * child channel with the prefix removed.
02309  * Variables whose names begin with '__' are copied into the child
02310  * channel with their names unchanged.
02311  */
02312 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
02313 
02314 /*!
02315  * \brief adds a list of channel variables to a channel
02316  * \param chan the channel
02317  * \param vars a linked list of variables
02318  *
02319  * \details
02320  * Variable names can be for a regular channel variable or a dialplan function
02321  * that has the ability to be written to.
02322  */
02323 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
02324 
02325 /*!
02326  * \brief An opaque 'object' structure use by silence generators on channels.
02327  */
02328 struct ast_silence_generator;
02329 
02330 /*!
02331  * \brief Starts a silence generator on the given channel.
02332  * \param chan The channel to generate silence on
02333  * \return An ast_silence_generator pointer, or NULL if an error occurs
02334  *
02335  * \details
02336  * This function will cause SLINEAR silence to be generated on the supplied
02337  * channel until it is disabled; if the channel cannot be put into SLINEAR
02338  * mode then the function will fail.
02339  *
02340  * \note
02341  * The pointer returned by this function must be preserved and passed to
02342  * ast_channel_stop_silence_generator when you wish to stop the silence
02343  * generation.
02344  */
02345 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
02346 
02347 /*!
02348  * \brief Stops a previously-started silence generator on the given channel.
02349  * \param chan The channel to operate on
02350  * \param state The ast_silence_generator pointer return by a previous call to
02351  * ast_channel_start_silence_generator.
02352  * \return nothing
02353  *
02354  * \details
02355  * This function will stop the operating silence generator and return the channel
02356  * to its previous write format.
02357  */
02358 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
02359 
02360 /*!
02361  * \brief Check if the channel can run in internal timing mode.
02362  * \param chan The channel to check
02363  * \return boolean
02364  *
02365  * \details
02366  * This function will return 1 if internal timing is enabled and the timing
02367  * device is available.
02368  */
02369 int ast_internal_timing_enabled(struct ast_channel *chan);
02370 
02371 /* Misc. functions below */
02372 
02373 /*!
02374  * \brief if fd is a valid descriptor, set *pfd with the descriptor
02375  * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
02376  * return value to the index into the array)
02377  */
02378 static inline int ast_add_fd(struct pollfd *pfd, int fd)
02379 {
02380    pfd->fd = fd;
02381    pfd->events = POLLIN | POLLPRI;
02382    return fd >= 0;
02383 }
02384 
02385 /*! \brief Helper function for migrating select to poll */
02386 static inline int ast_fdisset(struct pollfd *pfds, int fd, int maximum, int *start)
02387 {
02388    int x;
02389    int dummy = 0;
02390 
02391    if (fd < 0)
02392       return 0;
02393    if (!start)
02394       start = &dummy;
02395    for (x = *start; x < maximum; x++)
02396       if (pfds[x].fd == fd) {
02397          if (x == *start)
02398             (*start)++;
02399          return pfds[x].revents;
02400       }
02401    return 0;
02402 }
02403 
02404 /*! \brief Retrieves the current T38 state of a channel */
02405 static inline enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan)
02406 {
02407    enum ast_t38_state state = T38_STATE_UNAVAILABLE;
02408    int datalen = sizeof(state);
02409 
02410    ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0);
02411 
02412    return state;
02413 }
02414 
02415 #define CHECK_BLOCKING(c) do {    \
02416    if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
02417       if (option_debug) \
02418          ast_log(LOG_DEBUG, "Thread %ld Blocking '%s', already blocked by thread %ld in procedure %s\n", (long) pthread_self(), (c)->name, (long) (c)->blocker, (c)->blockproc); \
02419    } else { \
02420       (c)->blocker = pthread_self(); \
02421       (c)->blockproc = __PRETTY_FUNCTION__; \
02422       ast_set_flag(c, AST_FLAG_BLOCKING); \
02423    } } while (0)
02424 
02425 ast_group_t ast_get_group(const char *s);
02426 
02427 /*! \brief print call- and pickup groups into buffer */
02428 char *ast_print_group(char *buf, int buflen, ast_group_t group);
02429 
02430 /*!
02431  * \brief Convert enum channelreloadreason to text string for manager event
02432  * \param reason The reason for reload (manager, cli, start etc)
02433  */
02434 const char *channelreloadreason2txt(enum channelreloadreason reason);
02435 
02436 /*! \brief return an ast_variable list of channeltypes */
02437 struct ast_variable *ast_channeltype_list(void);
02438 
02439 /*!
02440  * \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
02441  * \param reason  The integer argument, usually taken from AST_CONTROL_ macros
02442  * \return char pointer explaining the code
02443  */
02444 const char *ast_channel_reason2str(int reason);
02445 
02446 /*! \brief channel group info */
02447 struct ast_group_info {
02448    struct ast_channel *chan;
02449    char *category;
02450    char *group;
02451    AST_LIST_ENTRY(ast_group_info) group_list;
02452 };
02453 
02454 #define ast_channel_lock(chan) ao2_lock(chan)
02455 #define ast_channel_unlock(chan) ao2_unlock(chan)
02456 #define ast_channel_trylock(chan) ao2_trylock(chan)
02457 
02458 /*!
02459  * \brief Lock two channels.
02460  */
02461 #define ast_channel_lock_both(chan1, chan2) do { \
02462       ast_channel_lock(chan1); \
02463       while (ast_channel_trylock(chan2)) { \
02464          ast_channel_unlock(chan1); \
02465          sched_yield(); \
02466          ast_channel_lock(chan1); \
02467       } \
02468    } while (0)
02469 
02470 /*!
02471  * \brief Increase channel reference count
02472  *
02473  * \param c the channel
02474  *
02475  * \retval c always
02476  *
02477  * \since 1.8
02478  */
02479 #define ast_channel_ref(c) ({ ao2_ref(c, +1); (c); })
02480 
02481 /*!
02482  * \brief Decrease channel reference count
02483  *
02484  * \param c the channel
02485  *
02486  * \retval NULL always
02487  *
02488  * \since 1.8
02489  */
02490 #define ast_channel_unref(c) ({ ao2_ref(c, -1); (struct ast_channel *) (NULL); })
02491 
02492 /*! Channel Iterating @{ */
02493 
02494 /*!
02495  * \brief A channel iterator
02496  *
02497  * This is an opaque type.
02498  */
02499 struct ast_channel_iterator;
02500 
02501 /*!
02502  * \brief Destroy a channel iterator
02503  *
02504  * \arg i the itereator to destroy
02505  *
02506  * This function is used to destroy a channel iterator that was retrieved by
02507  * using one of the channel_iterator_new() functions.
02508  *
02509  * \return NULL, for convenience to clear out the pointer to the iterator that
02510  * was just destroyed.
02511  *
02512  * \since 1.8
02513  */
02514 struct ast_channel_iterator *ast_channel_iterator_destroy(struct ast_channel_iterator *i);
02515 
02516 /*!
02517  * \brief Create a new channel iterator based on extension
02518  *
02519  * \arg exten The extension that channels must be in
02520  * \arg context The context that channels must be in (optional)
02521  *
02522  * After creating an iterator using this function, the ast_channel_iterator_next()
02523  * function can be used to iterate through all channels that are currently
02524  * in the specified context and extension.
02525  *
02526  * \retval NULL on failure
02527  * \retval a new channel iterator based on the specified parameters
02528  *
02529  * \since 1.8
02530  */
02531 struct ast_channel_iterator *ast_channel_iterator_by_exten_new(const char *exten, const char *context);
02532 
02533 /*!
02534  * \brief Create a new channel iterator based on name
02535  *
02536  * \arg name channel name or channel uniqueid to match
02537  * \arg name_len number of characters in the channel name to match on.  This
02538  *      would be used to match based on name prefix.  If matching on the full
02539  *      channel name is desired, then this parameter should be 0.
02540  *
02541  * After creating an iterator using this function, the ast_channel_iterator_next()
02542  * function can be used to iterate through all channels that exist that have
02543  * the specified name or name prefix.
02544  *
02545  * \retval NULL on failure
02546  * \retval a new channel iterator based on the specified parameters
02547  *
02548  * \since 1.8
02549  */
02550 struct ast_channel_iterator *ast_channel_iterator_by_name_new(const char *name,  size_t name_len);
02551 
02552 /*!
02553  * \brief Create a new channel iterator
02554  *
02555  * After creating an iterator using this function, the ast_channel_iterator_next()
02556  * function can be used to iterate through all channels that exist.
02557  *
02558  * \retval NULL on failure
02559  * \retval a new channel iterator
02560  *
02561  * \since 1.8
02562  */
02563 struct ast_channel_iterator *ast_channel_iterator_all_new(void);
02564 
02565 /*!
02566  * \brief Get the next channel for a channel iterator
02567  *
02568  * \arg i the channel iterator that was created using one of the
02569  *  channel_iterator_new() functions.
02570  *
02571  * This function should be used to iterate through all channels that match a
02572  * specified set of parameters that were provided when the iterator was created.
02573  *
02574  * \retval the next channel that matches the parameters used when the iterator
02575  *         was created.
02576  * \retval NULL, if no more channels match the iterator parameters.
02577  *
02578  * \since 1.8
02579  */
02580 struct ast_channel *ast_channel_iterator_next(struct ast_channel_iterator *i);
02581 
02582 /*! @} End channel iterator definitions. */
02583 
02584 /*!
02585  * \brief Call a function with every active channel
02586  *
02587  * This function executes a callback one time for each active channel on the
02588  * system.  The channel is provided as an argument to the function.
02589  *
02590  * \note Absolutely _NO_ channel locks should be held before calling this function.
02591  * \since 1.8
02592  */
02593 struct ast_channel *ast_channel_callback(ao2_callback_data_fn *cb_fn, void *arg,
02594       void *data, int ao2_flags);
02595 
02596 /*! @{ Channel search functions */
02597 
02598 /*!
02599  * \brief Find a channel by name
02600  *
02601  * \arg name the name or uniqueid of the channel to search for
02602  *
02603  * Find a channel that has the same name as the provided argument.
02604  *
02605  * \retval a channel with the name specified by the argument
02606  * \retval NULL if no channel was found
02607  *
02608  * \since 1.8
02609  */
02610 struct ast_channel *ast_channel_get_by_name(const char *name);
02611 
02612 /*!
02613  * \brief Find a channel by a name prefix
02614  *
02615  * \arg name The channel name or uniqueid prefix to search for
02616  * \arg name_len Only search for up to this many characters from the name
02617  *
02618  * Find a channel that has the same name prefix as specified by the arguments.
02619  *
02620  * \retval a channel with the name prefix specified by the arguments
02621  * \retval NULL if no channel was found
02622  *
02623  * \since 1.8
02624  */
02625 struct ast_channel *ast_channel_get_by_name_prefix(const char *name, size_t name_len);
02626 
02627 /*!
02628  * \brief Find a channel by extension and context
02629  *
02630  * \arg exten the extension to search for
02631  * \arg context the context to search for (optional)
02632  *
02633  * Return a channel that is currently at the specified extension and context.
02634  *
02635  * \retval a channel that is at the specified extension and context
02636  * \retval NULL if no channel was found
02637  *
02638  * \since 1.8
02639  */
02640 struct ast_channel *ast_channel_get_by_exten(const char *exten, const char *context);
02641 
02642 /*! @} End channel search functions. */
02643 
02644 /*!
02645   \brief propagate the linked id between chan and peer
02646  */
02647 void ast_channel_set_linkgroup(struct ast_channel *chan, struct ast_channel *peer);
02648 
02649 
02650 /*!
02651  * \brief Initialize the given name structure.
02652  * \since 1.8
02653  *
02654  * \param init Name structure to initialize.
02655  *
02656  * \return Nothing
02657  */
02658 void ast_party_name_init(struct ast_party_name *init);
02659 
02660 /*!
02661  * \brief Copy the source party name information to the destination party name.
02662  * \since 1.8
02663  *
02664  * \param dest Destination party name
02665  * \param src Source party name
02666  *
02667  * \return Nothing
02668  */
02669 void ast_party_name_copy(struct ast_party_name *dest, const struct ast_party_name *src);
02670 
02671 /*!
02672  * \brief Initialize the given party name structure using the given guide
02673  * for a set update operation.
02674  * \since 1.8
02675  *
02676  * \details
02677  * The initialization is needed to allow a set operation to know if a
02678  * value needs to be updated.  Simple integers need the guide's original
02679  * value in case the set operation is not trying to set a new value.
02680  * String values are simply set to NULL pointers if they are not going
02681  * to be updated.
02682  *
02683  * \param init Party name structure to initialize.
02684  * \param guide Source party name to use as a guide in initializing.
02685  *
02686  * \return Nothing
02687  */
02688 void ast_party_name_set_init(struct ast_party_name *init, const struct ast_party_name *guide);
02689 
02690 /*!
02691  * \brief Set the source party name information into the destination party name.
02692  * \since 1.8
02693  *
02694  * \param dest The name one wishes to update
02695  * \param src The new name values to update the dest
02696  *
02697  * \return Nothing
02698  */
02699 void ast_party_name_set(struct ast_party_name *dest, const struct ast_party_name *src);
02700 
02701 /*!
02702  * \brief Destroy the party name contents
02703  * \since 1.8
02704  *
02705  * \param doomed The party name to destroy.
02706  *
02707  * \return Nothing
02708  */
02709 void ast_party_name_free(struct ast_party_name *doomed);
02710 
02711 /*!
02712  * \brief Initialize the given number structure.
02713  * \since 1.8
02714  *
02715  * \param init Number structure to initialize.
02716  *
02717  * \return Nothing
02718  */
02719 void ast_party_number_init(struct ast_party_number *init);
02720 
02721 /*!
02722  * \brief Copy the source party number information to the destination party number.
02723  * \since 1.8
02724  *
02725  * \param dest Destination party number
02726  * \param src Source party number
02727  *
02728  * \return Nothing
02729  */
02730 void ast_party_number_copy(struct ast_party_number *dest, const struct ast_party_number *src);
02731 
02732 /*!
02733  * \brief Initialize the given party number structure using the given guide
02734  * for a set update operation.
02735  * \since 1.8
02736  *
02737  * \details
02738  * The initialization is needed to allow a set operation to know if a
02739  * value needs to be updated.  Simple integers need the guide's original
02740  * value in case the set operation is not trying to set a new value.
02741  * String values are simply set to NULL pointers if they are not going
02742  * to be updated.
02743  *
02744  * \param init Party number structure to initialize.
02745  * \param guide Source party number to use as a guide in initializing.
02746  *
02747  * \return Nothing
02748  */
02749 void ast_party_number_set_init(struct ast_party_number *init, const struct ast_party_number *guide);
02750 
02751 /*!
02752  * \brief Set the source party number information into the destination party number.
02753  * \since 1.8
02754  *
02755  * \param dest The number one wishes to update
02756  * \param src The new number values to update the dest
02757  *
02758  * \return Nothing
02759  */
02760 void ast_party_number_set(struct ast_party_number *dest, const struct ast_party_number *src);
02761 
02762 /*!
02763  * \brief Destroy the party number contents
02764  * \since 1.8
02765  *
02766  * \param doomed The party number to destroy.
02767  *
02768  * \return Nothing
02769  */
02770 void ast_party_number_free(struct ast_party_number *doomed);
02771 
02772 /*!
02773  * \since 1.8
02774  * \brief Initialize the given subaddress structure.
02775  *
02776  * \param init Subaddress structure to initialize.
02777  *
02778  * \return Nothing
02779  */
02780 void ast_party_subaddress_init(struct ast_party_subaddress *init);
02781 
02782 /*!
02783  * \since 1.8
02784  * \brief Copy the source party subaddress information to the destination party subaddress.
02785  *
02786  * \param dest Destination party subaddress
02787  * \param src Source party subaddress
02788  *
02789  * \return Nothing
02790  */
02791 void ast_party_subaddress_copy(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);
02792 
02793 /*!
02794  * \since 1.8
02795  * \brief Initialize the given party subaddress structure using the given guide
02796  * for a set update operation.
02797  *
02798  * \details
02799  * The initialization is needed to allow a set operation to know if a
02800  * value needs to be updated.  Simple integers need the guide's original
02801  * value in case the set operation is not trying to set a new value.
02802  * String values are simply set to NULL pointers if they are not going
02803  * to be updated.
02804  *
02805  * \param init Party subaddress structure to initialize.
02806  * \param guide Source party subaddress to use as a guide in initializing.
02807  *
02808  * \return Nothing
02809  */
02810 void ast_party_subaddress_set_init(struct ast_party_subaddress *init, const struct ast_party_subaddress *guide);
02811 
02812 /*!
02813  * \since 1.8
02814  * \brief Set the source party subaddress information into the destination party subaddress.
02815  *
02816  * \param dest The subaddress one wishes to update
02817  * \param src The new subaddress values to update the dest
02818  *
02819  * \return Nothing
02820  */
02821 void ast_party_subaddress_set(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);
02822 
02823 /*!
02824  * \since 1.8
02825  * \brief Destroy the party subaddress contents
02826  *
02827  * \param doomed The party subaddress to destroy.
02828  *
02829  * \return Nothing
02830  */
02831 void ast_party_subaddress_free(struct ast_party_subaddress *doomed);
02832 
02833 /*!
02834  * \brief Initialize the given party id structure.
02835  * \since 1.8
02836  *
02837  * \param init Party id structure to initialize.
02838  *
02839  * \return Nothing
02840  */
02841 void ast_party_id_init(struct ast_party_id *init);
02842 
02843 /*!
02844  * \brief Copy the source party id information to the destination party id.
02845  * \since 1.8
02846  *
02847  * \param dest Destination party id
02848  * \param src Source party id
02849  *
02850  * \return Nothing
02851  */
02852 void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src);
02853 
02854 /*!
02855  * \brief Initialize the given party id structure using the given guide
02856  * for a set update operation.
02857  * \since 1.8
02858  *
02859  * \details
02860  * The initialization is needed to allow a set operation to know if a
02861  * value needs to be updated.  Simple integers need the guide's original
02862  * value in case the set operation is not trying to set a new value.
02863  * String values are simply set to NULL pointers if they are not going
02864  * to be updated.
02865  *
02866  * \param init Party id structure to initialize.
02867  * \param guide Source party id to use as a guide in initializing.
02868  *
02869  * \return Nothing
02870  */
02871 void ast_party_id_set_init(struct ast_party_id *init, const struct ast_party_id *guide);
02872 
02873 /*!
02874  * \brief Set the source party id information into the destination party id.
02875  * \since 1.8
02876  *
02877  * \param dest The id one wishes to update
02878  * \param src The new id values to update the dest
02879  * \param update What id information to update.  NULL if all.
02880  *
02881  * \return Nothing
02882  */
02883 void ast_party_id_set(struct ast_party_id *dest, const struct ast_party_id *src, const struct ast_set_party_id *update);
02884 
02885 /*!
02886  * \brief Destroy the party id contents
02887  * \since 1.8
02888  *
02889  * \param doomed The party id to destroy.
02890  *
02891  * \return Nothing
02892  */
02893 void ast_party_id_free(struct ast_party_id *doomed);
02894 
02895 /*!
02896  * \brief Determine the overall presentation value for the given party.
02897  * \since 1.8
02898  *
02899  * \param id Party to determine the overall presentation value.
02900  *
02901  * \return Overall presentation value for the given party.
02902  */
02903 int ast_party_id_presentation(const struct ast_party_id *id);
02904 
02905 /*!
02906  * \brief Initialize the given dialed structure.
02907  * \since 1.8
02908  *
02909  * \param init Dialed structure to initialize.
02910  *
02911  * \return Nothing
02912  */
02913 void ast_party_dialed_init(struct ast_party_dialed *init);
02914 
02915 /*!
02916  * \brief Copy the source dialed party information to the destination dialed party.
02917  * \since 1.8
02918  *
02919  * \param dest Destination dialed party
02920  * \param src Source dialed party
02921  *
02922  * \return Nothing
02923  */
02924 void ast_party_dialed_copy(struct ast_party_dialed *dest, const struct ast_party_dialed *src);
02925 
02926 /*!
02927  * \brief Initialize the given dialed structure using the given
02928  * guide for a set update operation.
02929  * \since 1.8
02930  *
02931  * \details
02932  * The initialization is needed to allow a set operation to know if a
02933  * value needs to be updated.  Simple integers need the guide's original
02934  * value in case the set operation is not trying to set a new value.
02935  * String values are simply set to NULL pointers if they are not going
02936  * to be updated.
02937  *
02938  * \param init Caller structure to initialize.
02939  * \param guide Source dialed to use as a guide in initializing.
02940  *
02941  * \return Nothing
02942  */
02943 void ast_party_dialed_set_init(struct ast_party_dialed *init, const struct ast_party_dialed *guide);
02944 
02945 /*!
02946  * \brief Set the dialed information based on another dialed source
02947  * \since 1.8
02948  *
02949  * This is similar to ast_party_dialed_copy, except that NULL values for
02950  * strings in the src parameter indicate not to update the corresponding dest values.
02951  *
02952  * \param dest The dialed one wishes to update
02953  * \param src The new dialed values to update the dest
02954  *
02955  * \return Nada
02956  */
02957 void ast_party_dialed_set(struct ast_party_dialed *dest, const struct ast_party_dialed *src);
02958 
02959 /*!
02960  * \brief Destroy the dialed party contents
02961  * \since 1.8
02962  *
02963  * \param doomed The dialed party to destroy.
02964  *
02965  * \return Nothing
02966  */
02967 void ast_party_dialed_free(struct ast_party_dialed *doomed);
02968 
02969 /*!
02970  * \since 1.8
02971  * \brief Initialize the given caller structure.
02972  *
02973  * \param init Caller structure to initialize.
02974  *
02975  * \return Nothing
02976  */
02977 void ast_party_caller_init(struct ast_party_caller *init);
02978 
02979 /*!
02980  * \since 1.8
02981  * \brief Copy the source caller information to the destination caller.
02982  *
02983  * \param dest Destination caller
02984  * \param src Source caller
02985  *
02986  * \return Nothing
02987  */
02988 void ast_party_caller_copy(struct ast_party_caller *dest, const struct ast_party_caller *src);
02989 
02990 /*!
02991  * \brief Initialize the given caller structure using the given
02992  * guide for a set update operation.
02993  * \since 1.8
02994  *
02995  * \details
02996  * The initialization is needed to allow a set operation to know if a
02997  * value needs to be updated.  Simple integers need the guide's original
02998  * value in case the set operation is not trying to set a new value.
02999  * String values are simply set to NULL pointers if they are not going
03000  * to be updated.
03001  *
03002  * \param init Caller structure to initialize.
03003  * \param guide Source caller to use as a guide in initializing.
03004  *
03005  * \return Nothing
03006  */
03007 void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide);
03008 
03009 /*!
03010  * \brief Set the caller information based on another caller source
03011  * \since 1.8
03012  *
03013  * This is similar to ast_party_caller_copy, except that NULL values for
03014  * strings in the src parameter indicate not to update the corresponding dest values.
03015  *
03016  * \param dest The caller one wishes to update
03017  * \param src The new caller values to update the dest
03018  * \param update What caller information to update.  NULL if all.
03019  *
03020  * \return Nada
03021  */
03022 void ast_party_caller_set(struct ast_party_caller *dest, const struct ast_party_caller *src, const struct ast_set_party_caller *update);
03023 
03024 /*!
03025  * \brief Destroy the caller party contents
03026  * \since 1.8
03027  *
03028  * \param doomed The caller party to destroy.
03029  *
03030  * \return Nothing
03031  */
03032 void ast_party_caller_free(struct ast_party_caller *doomed);
03033 
03034 /*!
03035  * \since 1.8
03036  * \brief Initialize the given connected line structure.
03037  *
03038  * \param init Connected line structure to initialize.
03039  *
03040  * \return Nothing
03041  */
03042 void ast_party_connected_line_init(struct ast_party_connected_line *init);
03043 
03044 /*!
03045  * \since 1.8
03046  * \brief Copy the source connected line information to the destination connected line.
03047  *
03048  * \param dest Destination connected line
03049  * \param src Source connected line
03050  *
03051  * \return Nothing
03052  */
03053 void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src);
03054 
03055 /*!
03056  * \since 1.8
03057  * \brief Initialize the given connected line structure using the given
03058  * guide for a set update operation.
03059  *
03060  * \details
03061  * The initialization is needed to allow a set operation to know if a
03062  * value needs to be updated.  Simple integers need the guide's original
03063  * value in case the set operation is not trying to set a new value.
03064  * String values are simply set to NULL pointers if they are not going
03065  * to be updated.
03066  *
03067  * \param init Connected line structure to initialize.
03068  * \param guide Source connected line to use as a guide in initializing.
03069  *
03070  * \return Nothing
03071  */
03072 void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide);
03073 
03074 /*!
03075  * \since 1.8
03076  * \brief Set the connected line information based on another connected line source
03077  *
03078  * This is similar to ast_party_connected_line_copy, except that NULL values for
03079  * strings in the src parameter indicate not to update the corresponding dest values.
03080  *
03081  * \param dest The connected line one wishes to update
03082  * \param src The new connected line values to update the dest
03083  * \param update What connected line information to update.  NULL if all.
03084  *
03085  * \return Nothing
03086  */
03087 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);
03088 
03089 /*!
03090  * \since 1.8
03091  * \brief Collect the caller party information into a connected line structure.
03092  *
03093  * \param connected Collected caller information for the connected line
03094  * \param caller Caller information.
03095  *
03096  * \return Nothing
03097  *
03098  * \warning This is a shallow copy.
03099  * \warning DO NOT call ast_party_connected_line_free() on the filled in
03100  * connected line structure!
03101  */
03102 void ast_party_connected_line_collect_caller(struct ast_party_connected_line *connected, struct ast_party_caller *caller);
03103 
03104 /*!
03105  * \since 1.8
03106  * \brief Destroy the connected line information contents
03107  *
03108  * \param doomed The connected line information to destroy.
03109  *
03110  * \return Nothing
03111  */
03112 void ast_party_connected_line_free(struct ast_party_connected_line *doomed);
03113 
03114 /*!
03115  * \brief Initialize the given redirecting structure.
03116  * \since 1.8
03117  *
03118  * \param init Redirecting structure to initialize.
03119  *
03120  * \return Nothing
03121  */
03122 void ast_party_redirecting_init(struct ast_party_redirecting *init);
03123 
03124 /*!
03125  * \since 1.8
03126  * \brief Copy the source redirecting information to the destination redirecting.
03127  *
03128  * \param dest Destination redirecting
03129  * \param src Source redirecting
03130  *
03131  * \return Nothing
03132  */
03133 void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src);
03134 
03135 /*!
03136  * \since 1.8
03137  * \brief Initialize the given redirecting id structure using the given guide
03138  * for a set update operation.
03139  *
03140  * \details
03141  * The initialization is needed to allow a set operation to know if a
03142  * value needs to be updated.  Simple integers need the guide's original
03143  * value in case the set operation is not trying to set a new value.
03144  * String values are simply set to NULL pointers if they are not going
03145  * to be updated.
03146  *
03147  * \param init Redirecting id structure to initialize.
03148  * \param guide Source redirecting id to use as a guide in initializing.
03149  *
03150  * \return Nothing
03151  */
03152 void ast_party_redirecting_set_init(struct ast_party_redirecting *init, const struct ast_party_redirecting *guide);
03153 
03154 /*!
03155  * \brief Set the redirecting information based on another redirecting source
03156  * \since 1.8
03157  *
03158  * This is similar to ast_party_redirecting_copy, except that NULL values for
03159  * strings in the src parameter indicate not to update the corresponding dest values.
03160  *
03161  * \param dest The redirecting one wishes to update
03162  * \param src The new redirecting values to update the dest
03163  * \param update What redirecting information to update.  NULL if all.
03164  *
03165  * \return Nothing
03166  */
03167 void ast_party_redirecting_set(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src, const struct ast_set_party_redirecting *update);
03168 
03169 /*!
03170  * \since 1.8
03171  * \brief Destroy the redirecting information contents
03172  *
03173  * \param doomed The redirecting information to destroy.
03174  *
03175  * \return Nothing
03176  */
03177 void ast_party_redirecting_free(struct ast_party_redirecting *doomed);
03178 
03179 /*!
03180  * \since 1.8
03181  * \brief Copy the caller information to the connected line information.
03182  *
03183  * \param dest Destination connected line information
03184  * \param src Source caller information
03185  *
03186  * \return Nothing
03187  *
03188  * \note Assumes locks are already acquired
03189  */
03190 void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src);
03191 
03192 /*!
03193  * \since 1.8
03194  * \brief Copy the connected line information to the caller information.
03195  *
03196  * \param dest Destination caller information
03197  * \param src Source connected line information
03198  *
03199  * \return Nothing
03200  *
03201  * \note Assumes locks are already acquired
03202  */
03203 void ast_connected_line_copy_to_caller(struct ast_party_caller *dest, const struct ast_party_connected_line *src);
03204 
03205 /*!
03206  * \since 1.8
03207  * \brief Set the connected line information in the Asterisk channel
03208  *
03209  * \param chan Asterisk channel to set connected line information
03210  * \param connected Connected line information
03211  * \param update What connected line information to update.  NULL if all.
03212  *
03213  * \return Nothing
03214  *
03215  * \note The channel does not need to be locked before calling this function.
03216  */
03217 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);
03218 
03219 /*!
03220  * \since 1.8
03221  * \brief Build the connected line information data frame.
03222  *
03223  * \param data Buffer to fill with the frame data
03224  * \param datalen Size of the buffer to fill
03225  * \param connected Connected line information
03226  * \param update What connected line information to build.  NULL if all.
03227  *
03228  * \retval -1 if error
03229  * \retval Amount of data buffer used
03230  */
03231 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);
03232 
03233 /*!
03234  * \since 1.8
03235  * \brief Parse connected line indication frame data
03236  *
03237  * \param data Buffer with the frame data to parse
03238  * \param datalen Size of the buffer
03239  * \param connected Extracted connected line information
03240  *
03241  * \retval 0 on success.
03242  * \retval -1 on error.
03243  *
03244  * \note The filled in connected line structure needs to be initialized by
03245  * ast_party_connected_line_set_init() before calling.  If defaults are not
03246  * required use ast_party_connected_line_init().
03247  * \note The filled in connected line structure needs to be destroyed by
03248  * ast_party_connected_line_free() when it is no longer needed.
03249  */
03250 int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected);
03251 
03252 /*!
03253  * \since 1.8
03254  * \brief Indicate that the connected line information has changed
03255  *
03256  * \param chan Asterisk channel to indicate connected line information
03257  * \param connected Connected line information
03258  * \param update What connected line information to update.  NULL if all.
03259  *
03260  * \return Nothing
03261  */
03262 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);
03263 
03264 /*!
03265  * \since 1.8
03266  * \brief Queue a connected line update frame on a channel
03267  *
03268  * \param chan Asterisk channel to indicate connected line information
03269  * \param connected Connected line information
03270  * \param update What connected line information to update.  NULL if all.
03271  *
03272  * \return Nothing
03273  */
03274 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);
03275 
03276 /*!
03277  * \since 1.8
03278  * \brief Set the redirecting id information in the Asterisk channel
03279  *
03280  * \param chan Asterisk channel to set redirecting id information
03281  * \param redirecting Redirecting id information
03282  * \param update What redirecting information to update.  NULL if all.
03283  *
03284  * \return Nothing
03285  *
03286  * \note The channel does not need to be locked before calling this function.
03287  */
03288 void ast_channel_set_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
03289 
03290 /*!
03291  * \since 1.8
03292  * \brief Build the redirecting id data frame.
03293  *
03294  * \param data Buffer to fill with the frame data
03295  * \param datalen Size of the buffer to fill
03296  * \param redirecting Redirecting id information
03297  * \param update What redirecting information to build.  NULL if all.
03298  *
03299  * \retval -1 if error
03300  * \retval Amount of data buffer used
03301  */
03302 int ast_redirecting_build_data(unsigned char *data, size_t datalen, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
03303 
03304 /*!
03305  * \since 1.8
03306  * \brief Parse redirecting indication frame data
03307  *
03308  * \param data Buffer with the frame data to parse
03309  * \param datalen Size of the buffer
03310  * \param redirecting Extracted redirecting id information
03311  *
03312  * \retval 0 on success.
03313  * \retval -1 on error.
03314  *
03315  * \note The filled in id structure needs to be initialized by
03316  * ast_party_redirecting_set_init() before calling.
03317  * \note The filled in id structure needs to be destroyed by
03318  * ast_party_redirecting_free() when it is no longer needed.
03319  */
03320 int ast_redirecting_parse_data(const unsigned char *data, size_t datalen, struct ast_party_redirecting *redirecting);
03321 
03322 /*!
03323  * \since 1.8
03324  * \brief Indicate that the redirecting id has changed
03325  *
03326  * \param chan Asterisk channel to indicate redirecting id information
03327  * \param redirecting Redirecting id information
03328  * \param update What redirecting information to update.  NULL if all.
03329  *
03330  * \return Nothing
03331  */
03332 void ast_channel_update_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
03333 
03334 /*!
03335  * \since 1.8
03336  * \brief Queue a redirecting update frame on a channel
03337  *
03338  * \param chan Asterisk channel to indicate redirecting id information
03339  * \param redirecting Redirecting id information
03340  * \param update What redirecting information to update.  NULL if all.
03341  *
03342  * \return Nothing
03343  */
03344 void ast_channel_queue_redirecting_update(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
03345 
03346 /*!
03347  * \since 1.8
03348  * \brief Run a connected line interception macro and update a channel's connected line
03349  * information
03350  *
03351  * Whenever we want to update a channel's connected line information, we may need to run
03352  * a macro so that an administrator can manipulate the information before sending it
03353  * out. This function both runs the macro and sends the update to the channel.
03354  *
03355  * \param autoservice_chan Channel to place into autoservice while the macro is running.
03356  *    It is perfectly safe for this to be NULL
03357  * \param macro_chan The channel to run the macro on. Also the channel from which we
03358  *    determine which macro we need to run.
03359  * \param connected_info Either an ast_party_connected_line or ast_frame pointer of type
03360  *    AST_CONTROL_CONNECTED_LINE
03361  * \param caller If true, then run CONNECTED_LINE_CALLER_SEND_MACRO, otherwise run
03362  *    CONNECTED_LINE_CALLEE_SEND_MACRO
03363  * \param frame If true, then connected_info is an ast_frame pointer, otherwise it is an
03364  *    ast_party_connected_line pointer.
03365  * \retval 0 Success
03366  * \retval -1 Either the macro does not exist, or there was an error while attempting to
03367  *    run the macro
03368  *
03369  * \todo Have multiple return codes based on the MACRO_RESULT
03370  * \todo Make constants so that caller and frame can be more expressive than just '1' and
03371  *    '0'
03372  */
03373 int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int caller, int frame);
03374 
03375 /*!
03376  * \brief Insert into an astdata tree, the channel structure.
03377  * \param[in] tree The ast data tree.
03378  * \param[in] chan The channel structure to add to tree.
03379  * \param[in] add_bridged Add the bridged channel to the structure.
03380  * \retval <0 on error.
03381  * \retval 0 on success.
03382  */
03383 int ast_channel_data_add_structure(struct ast_data *tree, struct ast_channel *chan, int add_bridged);
03384 
03385 /*!
03386  * \brief Compare to channel structures using the data api.
03387  * \param[in] tree The search tree generated by the data api.
03388  * \param[in] chan The channel to compare.
03389  * \param[in] structure_name The name of the node of the channel structure.
03390  * \retval 0 The structure matches.
03391  * \retval 1 The structure doesn't matches.
03392  */
03393 int ast_channel_data_cmp_structure(const struct ast_data_search *tree, struct ast_channel *chan,
03394    const char *structure_name);
03395 
03396 /*!
03397  * \since 1.8
03398  * \brief Run a redirecting interception macro and update a channel's redirecting information
03399  *
03400  * \details
03401  * Whenever we want to update a channel's redirecting information, we may need to run
03402  * a macro so that an administrator can manipulate the information before sending it
03403  * out. This function both runs the macro and sends the update to the channel.
03404  *
03405  * \param autoservice_chan Channel to place into autoservice while the macro is running.
03406  * It is perfectly safe for this to be NULL
03407  * \param macro_chan The channel to run the macro on. Also the channel from which we
03408  * determine which macro we need to run.
03409  * \param redirecting_info Either an ast_party_redirecting or ast_frame pointer of type
03410  * AST_CONTROL_REDIRECTING
03411  * \param is_caller If true, then run REDIRECTING_CALLER_SEND_MACRO, otherwise run
03412  * REDIRECTING_CALLEE_SEND_MACRO
03413  * \param is_frame If true, then redirecting_info is an ast_frame pointer, otherwise it is an
03414  * ast_party_redirecting pointer.
03415  *
03416  * \retval 0 Success
03417  * \retval -1 Either the macro does not exist, or there was an error while attempting to
03418  * run the macro
03419  *
03420  * \todo Have multiple return codes based on the MACRO_RESULT
03421  * \todo Make constants so that caller and frame can be more expressive than just '1' and
03422  * '0'
03423  */
03424 int ast_channel_redirecting_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *redirecting_info, int is_caller, int is_frame);
03425 
03426 #include "asterisk/ccss.h"
03427 
03428 /*!
03429  * \since 1.8
03430  * \brief Set up datastore with CCSS parameters for a channel
03431  *
03432  * \note
03433  * If base_params is NULL, the channel will get the default
03434  * values for all CCSS parameters.
03435  *
03436  * \details
03437  * This function makes use of datastore operations on the channel, so
03438  * it is important to lock the channel before calling this function.
03439  *
03440  * \param chan The channel to create the datastore on
03441  * \param base_params CCSS parameters we wish to copy into the channel
03442  * \retval 0 Success
03443  * \retval -1 Failure
03444  */
03445 int ast_channel_cc_params_init(struct ast_channel *chan,
03446       const struct ast_cc_config_params *base_params);
03447 
03448 /*!
03449  * \since 1.8
03450  * \brief Get the CCSS parameters from a channel
03451  *
03452  * \details
03453  * This function makes use of datastore operations on the channel, so
03454  * it is important to lock the channel before calling this function.
03455  *
03456  * \param chan Channel to retrieve parameters from
03457  * \retval NULL Failure
03458  * \retval non-NULL The parameters desired
03459  */
03460 struct ast_cc_config_params *ast_channel_get_cc_config_params(struct ast_channel *chan);
03461 
03462 
03463 /*!
03464  * \since 1.8
03465  * \brief Get a device name given its channel structure
03466  *
03467  * \details
03468  * A common practice in Asterisk is to determine the device being talked
03469  * to by dissecting the channel name. For certain channel types, this is not
03470  * accurate. For instance, an ISDN channel is named based on what B channel is
03471  * used, not the device being communicated with.
03472  *
03473  * This function interfaces with a channel tech's queryoption callback to
03474  * retrieve the name of the device being communicated with. If the channel does not
03475  * implement this specific option, then the traditional method of using the channel
03476  * name is used instead.
03477  *
03478  * \param chan The channel to retrieve the information from
03479  * \param[out] device_name The buffer to place the device's name into
03480  * \param name_buffer_length The allocated space for the device_name
03481  * \return 0 always
03482  */
03483 int ast_channel_get_device_name(struct ast_channel *chan, char *device_name, size_t name_buffer_length);
03484 
03485 /*!
03486  * \since 1.8
03487  * \brief Find the appropriate CC agent type to use given a channel
03488  *
03489  * \details
03490  * During call completion, we will need to create a call completion agent structure. To
03491  * figure out the type of agent to construct, we need to ask the channel driver for the
03492  * appropriate type.
03493  *
03494  * Prior to adding this function, the call completion core attempted to figure this
03495  * out for itself by stripping the technology off the channel's name. However, in the
03496  * case of chan_dahdi, there are multiple agent types registered, and so simply searching
03497  * for an agent type called "DAHDI" is not possible. In a case where multiple agent types
03498  * are defined, the channel driver must have a queryoption callback defined in its
03499  * channel_tech, and the queryoption callback must handle AST_OPTION_CC_AGENT_TYPE
03500  *
03501  * If a channel driver does not have a queryoption callback or if the queryoption callback
03502  * does not handle AST_OPTION_CC_AGENT_TYPE, then the old behavior of using the technology
03503  * portion of the channel name is used instead. This is perfectly suitable for channel drivers
03504  * whose channel technologies are a one-to-one match with the agent types defined within.
03505  *
03506  * Note that this function is only called when the agent policy on a given channel is set
03507  * to "native." Generic agents' type can be determined automatically by the core.
03508  *
03509  * \param chan The channel for which we wish to retrieve the agent type
03510  * \param[out] agent_type The type of agent the channel driver wants us to use
03511  * \param size The size of the buffer to write to
03512  */
03513 int ast_channel_get_cc_agent_type(struct ast_channel *chan, char *agent_type, size_t size);
03514 #if defined(__cplusplus) || defined(c_plusplus)
03515 }
03516 #endif
03517 
03518 #endif /* _ASTERISK_CHANNEL_H */

Generated on 18 Jan 2013 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1