ccss.h File Reference

Call Completion Supplementary Services API. More...

#include "asterisk.h"
#include "asterisk/linkedlists.h"
#include "asterisk/devicestate.h"

Include dependency graph for ccss.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_cc_agent
struct  ast_cc_agent_callbacks
struct  ast_cc_interface
 Structure with information about an outbound interface. More...
struct  ast_cc_monitor
struct  ast_cc_monitor_callbacks
 Callbacks defined by CC monitors. More...

Defines

#define ast_cc_config_params_init()   __ast_cc_config_params_init(__FILE__, __LINE__, __PRETTY_FUNCTION__)
 Allocate and initialize an ast_cc_config_params structure.
#define AST_CC_GENERIC_MONITOR_TYPE   "generic"

Typedefs

typedef void(* ast_cc_callback_fn )(struct ast_channel *chan, struct ast_cc_config_params *cc_params, const char *monitor_type, const char *const device_name, const char *const dialstring, void *private_data)
 Callback made from ast_cc_callback for certain channel types.

Enumerations

enum  ast_cc_agent_flags { AST_CC_AGENT_SKIP_OFFER = (1 << 0) }
 agent flags that can alter core behavior More...
enum  ast_cc_agent_policies { AST_CC_AGENT_NEVER, AST_CC_AGENT_NATIVE, AST_CC_AGENT_GENERIC }
 The various possibilities for cc_agent_policy values. More...
enum  ast_cc_agent_response_reason { AST_CC_AGENT_RESPONSE_SUCCESS, AST_CC_AGENT_RESPONSE_FAILURE_INVALID, AST_CC_AGENT_RESPONSE_FAILURE_TOO_MANY }
enum  ast_cc_monitor_class { AST_CC_DEVICE_MONITOR, AST_CC_EXTENSION_MONITOR }
enum  ast_cc_monitor_policies { AST_CC_MONITOR_NEVER, AST_CC_MONITOR_NATIVE, AST_CC_MONITOR_GENERIC, AST_CC_MONITOR_ALWAYS }
 The various possibilities for cc_monitor_policy values. More...
enum  ast_cc_service_type { AST_CC_NONE, AST_CC_CCBS, AST_CC_CCNR, AST_CC_CCNL }

Functions

struct ast_cc_config_params__ast_cc_config_params_init (const char *file, int line, const char *function)
 Allocate and initialize an ast_cc_config_params structure.
int ast_cc_agent_accept_request (int core_id, const char *const debug,...)
 Accept inbound CC request.
struct ast_cc_agentast_cc_agent_callback (int flags, ao2_callback_fn *function, void *arg, const char *const type)
 Call a callback on all agents of a specific type.
int ast_cc_agent_caller_available (int core_id, const char *const debug,...)
 Indicate that a previously unavailable caller has become available.
int ast_cc_agent_caller_busy (int core_id, const char *const debug,...)
 Indicate that the caller is busy.
int ast_cc_agent_recalling (int core_id, const char *const debug,...)
 Tell the CC core that a caller is currently recalling.
int ast_cc_agent_register (const struct ast_cc_agent_callbacks *callbacks)
 Register a set of agent callbacks with the core.
int ast_cc_agent_set_interfaces_chanvar (struct ast_channel *chan)
 Set the first level CC_INTERFACES channel variable for a channel.
int ast_cc_agent_status_response (int core_id, enum ast_device_state devstate)
 Response with a caller's current status.
void ast_cc_agent_unregister (const struct ast_cc_agent_callbacks *callbacks)
 Unregister a set of agent callbacks with the core.
int ast_cc_available_timer_expire (const void *data)
 Scheduler callback for available timer expiration.
int ast_cc_build_frame (struct ast_channel *chan, struct ast_cc_config_params *cc_params, const char *monitor_type, const char *const device_name, const char *const dialstring, enum ast_cc_service_type service, void *private_data, struct ast_frame *frame)
 Create a CC Control frame.
void ast_cc_busy_interface (struct ast_channel *inbound, struct ast_cc_config_params *cc_params, const char *monitor_type, const char *const device_name, const char *const dialstring, void *private_data)
 Callback made from ast_cc_callback for certain channel types.
void ast_cc_call_failed (struct ast_channel *incoming, struct ast_channel *outgoing, const char *const dialstring)
 Make CCBS available in the case that ast_call fails.
int ast_cc_call_init (struct ast_channel *chan, int *ignore_cc)
 Start the CC process on a call.
int ast_cc_callback (struct ast_channel *inbound, const char *const tech, const char *const dest, ast_cc_callback_fn callback)
 Run a callback for potential matching destinations.
int ast_cc_completed (struct ast_channel *chan, const char *const debug,...)
 Indicate recall has been acknowledged.
void ast_cc_config_params_destroy (struct ast_cc_config_params *params)
 Free memory from CCSS configuration params.
void ast_cc_copy_config_params (struct ast_cc_config_params *dest, const struct ast_cc_config_params *src)
 copy CCSS configuration parameters from one structure to another
void ast_cc_default_config_params (struct ast_cc_config_params *params)
 Set the specified CC config params to default values.
void ast_cc_extension_monitor_add_dialstring (struct ast_channel *incoming, const char *const dialstring, const char *const device_name)
 Add a child dialstring to an extension monitor.
int ast_cc_failed (int core_id, const char *const debug,...)
 Indicate failure has occurred.
int ast_cc_get_current_core_id (struct ast_channel *chan)
 Get the core id for the current call.
struct ast_cc_monitorast_cc_get_monitor_by_recall_core_id (const int core_id, const char *const device_name)
 Get the associated monitor given the device name and core_id.
int ast_cc_get_param (struct ast_cc_config_params *params, const char *const name, char *buf, size_t buf_len)
 get a CCSS configuration parameter, given its name
int ast_cc_init (void)
 Initialize CCSS.
int ast_cc_is_config_param (const char *const name)
 Is this a CCSS configuration parameter?
int ast_cc_is_recall (struct ast_channel *chan, int *core_id, const char *const monitor_type)
 Decide if a call to a particular channel is a CC recall.
int ast_cc_monitor_callee_available (const int core_id, const char *const debug,...)
 Alert the core that a device being monitored has become available.
int ast_cc_monitor_count (const char *const name, const char *const type)
 Return the number of outstanding CC requests to a specific device.
int ast_cc_monitor_failed (int core_id, const char *const monitor_name, const char *const debug,...)
 Indicate that a failure has occurred on a specific monitor.
int ast_cc_monitor_party_b_free (int core_id)
 Alert a caller that though the callee has become free, the caller himself is not and may not call back.
int ast_cc_monitor_register (const struct ast_cc_monitor_callbacks *callbacks)
 Register a set of monitor callbacks with the core.
int ast_cc_monitor_request_acked (int core_id, const char *const debug,...)
 Indicate that an outbound entity has accepted our CC request.
int ast_cc_monitor_status_request (int core_id)
 Request the status of a caller or callers.
int ast_cc_monitor_stop_ringing (int core_id)
 Alert a caller to stop ringing.
void ast_cc_monitor_unregister (const struct ast_cc_monitor_callbacks *callbacks)
 Unregister a set of monitor callbacks with the core.
int ast_cc_offer (struct ast_channel *caller_chan)
 Offer CC to a caller.
int ast_cc_request_is_within_limits (void)
 Check if the incoming CC request is within the bounds set by the cc_max_requests configuration option.
int ast_cc_set_param (struct ast_cc_config_params *params, const char *const name, const char *value)
 set a CCSS configuration parameter, given its name
const char * ast_get_cc_agent_dialstring (struct ast_cc_config_params *config)
 Get the cc_agent_dialstring.
enum ast_cc_agent_policies ast_get_cc_agent_policy (struct ast_cc_config_params *config)
 Get the cc_agent_policy.
const char * ast_get_cc_callback_macro (struct ast_cc_config_params *config)
 Get the name of the callback_macro.
const char * ast_get_cc_callback_sub (struct ast_cc_config_params *config)
 Get the name of the callback subroutine.
unsigned int ast_get_cc_max_agents (struct ast_cc_config_params *config)
 Get the cc_max_agents.
unsigned int ast_get_cc_max_monitors (struct ast_cc_config_params *config)
 Get the cc_max_monitors.
enum ast_cc_monitor_policies ast_get_cc_monitor_policy (struct ast_cc_config_params *config)
 Get the cc_monitor_policy.
unsigned int ast_get_cc_offer_timer (struct ast_cc_config_params *config)
 Get the cc_offer_timer.
unsigned int ast_get_cc_recall_timer (struct ast_cc_config_params *config)
 Get the cc_recall_timer.
unsigned int ast_get_ccbs_available_timer (struct ast_cc_config_params *config)
 Get the ccbs_available_timer.
unsigned int ast_get_ccnr_available_timer (struct ast_cc_config_params *config)
 Get the ccnr_available_timer.
void ast_handle_cc_control_frame (struct ast_channel *inbound, struct ast_channel *outbound, void *frame_data)
 Properly react to a CC control frame.
void ast_ignore_cc (struct ast_channel *chan)
 Mark the channel to ignore further CC activity.
int ast_queue_cc_frame (struct ast_channel *chan, const char *const monitor_type, const char *const dialstring, enum ast_cc_service_type service, void *private_data)
 Queue an AST_CONTROL_CC frame.
void ast_set_cc_agent_dialstring (struct ast_cc_config_params *config, const char *const value)
 Set the cc_agent_dialstring.
int ast_set_cc_agent_policy (struct ast_cc_config_params *config, enum ast_cc_agent_policies value)
 Set the cc_agent_policy.
void ast_set_cc_callback_macro (struct ast_cc_config_params *config, const char *const value)
 Set the callback_macro name.
void ast_set_cc_callback_sub (struct ast_cc_config_params *config, const char *const value)
 Set the callback subroutine name.
int ast_set_cc_interfaces_chanvar (struct ast_channel *chan, const char *const extension)
 Set the CC_INTERFACES channel variable for a channel using an.
void ast_set_cc_max_agents (struct ast_cc_config_params *config, unsigned int value)
 Set the cc_max_agents.
void ast_set_cc_max_monitors (struct ast_cc_config_params *config, unsigned int value)
 Set the cc_max_monitors.
int ast_set_cc_monitor_policy (struct ast_cc_config_params *config, enum ast_cc_monitor_policies value)
 Set the cc_monitor_policy.
void ast_set_cc_offer_timer (struct ast_cc_config_params *config, unsigned int value)
 Set the cc_offer_timer.
void ast_set_cc_recall_timer (struct ast_cc_config_params *config, unsigned int value)
 Set the cc_recall_timer.
void ast_set_ccbs_available_timer (struct ast_cc_config_params *config, unsigned int value)
 Set the ccbs_available_timer.
void ast_set_ccnr_available_timer (struct ast_cc_config_params *config, unsigned int value)
 Set the ccnr_available_timer.
int ast_setup_cc_recall_datastore (struct ast_channel *chan, const int core_id)
 Set up a CC recall datastore on a channel.


Detailed Description

Call Completion Supplementary Services API.

Author:
Mark Michelson <mmichelson@digium.com>

Definition in file ccss.h.


Define Documentation

 
#define ast_cc_config_params_init (  )     __ast_cc_config_params_init(__FILE__, __LINE__, __PRETTY_FUNCTION__)

Allocate and initialize an ast_cc_config_params structure.

Note:
Reasonable default values are chosen for the parameters upon allocation.
Return values:
NULL Unable to allocate the structure
non-NULL A pointer to the newly allocated and initialized structure

Definition at line 135 of file ccss.h.

Referenced by __sip_alloc(), ast_channel_cc_params_init(), build_peer(), cc_agent_init(), cc_device_monitor_init(), channel_cc_params_copy(), dahdi_chan_conf_default(), duplicate_pseudo(), mkintf(), and temp_peer().

#define AST_CC_GENERIC_MONITOR_TYPE   "generic"

It is recommended that monitors use a pointer to an ast_cc_monitor_callbacks::type when creating an AST_CONTROL_CC frame. Since the generic monitor callbacks are opaque and channel drivers will wish to use that, this string is made globally available for all to use

Definition at line 489 of file ccss.h.

Referenced by analog_call(), ast_cc_call_failed(), dahdi_cc_callback(), and sip_handle_cc().


Typedef Documentation

typedef void(* ast_cc_callback_fn)(struct ast_channel *chan, struct ast_cc_config_params *cc_params, const char *monitor_type, const char *const device_name, const char *const dialstring, void *private_data)

Callback made from ast_cc_callback for certain channel types.

Since:
1.8
Parameters:
chan A channel involved in the call. What we want is on a datastore on both incoming and outgoing so either may be provided
cc_params The CC configuration parameters for the outbound target
monitor_type The type of monitor to use when CC is requested
device_name The name of the outbound target device.
dialstring The dial string used when calling this specific interface
private_data If a native monitor is being used, and some channel-driver-specific private data has been allocated, then this parameter should contain a pointer to that data. If using a generic monitor, this parameter should remain NULL. Note that if this function should fail at some point, it is the responsibility of the caller to free the private data upon return.
For channel types that fail ast_request when the device is busy, we call into the channel driver with ast_cc_callback. This is the callback that is called in that case for each device found which could have been returned by ast_request.

Returns:
Nothing

Definition at line 1602 of file ccss.h.


Enumeration Type Documentation

agent flags that can alter core behavior

Enumerator:
AST_CC_AGENT_SKIP_OFFER 

Definition at line 59 of file ccss.h.

00059                         {
00060    /* Some agent types allow for a caller to
00061     * request CC without reaching the CC_CALLER_OFFERED
00062     * state. In other words, the caller can request
00063     * CC while he is still on the phone from the failed
00064     * call. The generic agent is an agent which allows
00065     * for this behavior.
00066     */
00067    AST_CC_AGENT_SKIP_OFFER = (1 << 0),
00068 };

The various possibilities for cc_agent_policy values.

Since:
1.8
Enumerator:
AST_CC_AGENT_NEVER  Never offer CCSS to the caller
AST_CC_AGENT_NATIVE  Offer CCSS using native signaling
AST_CC_AGENT_GENERIC  Use generic agent for caller

Definition at line 47 of file ccss.h.

00047                            {
00048    /*! Never offer CCSS to the caller */
00049    AST_CC_AGENT_NEVER,
00050    /*! Offer CCSS using native signaling */
00051    AST_CC_AGENT_NATIVE,
00052    /*! Use generic agent for caller */
00053    AST_CC_AGENT_GENERIC,
00054 };

Enumerator:
AST_CC_AGENT_RESPONSE_SUCCESS  CC request accepted
AST_CC_AGENT_RESPONSE_FAILURE_INVALID  CC request not allowed at this time. Invalid state transition.
AST_CC_AGENT_RESPONSE_FAILURE_TOO_MANY  Too many CC requests in the system.

Definition at line 878 of file ccss.h.

00878                                   {
00879    /*! CC request accepted */
00880    AST_CC_AGENT_RESPONSE_SUCCESS,
00881    /*! CC request not allowed at this time. Invalid state transition. */
00882    AST_CC_AGENT_RESPONSE_FAILURE_INVALID,
00883    /*! Too many CC requests in the system. */
00884    AST_CC_AGENT_RESPONSE_FAILURE_TOO_MANY,
00885 };

Used to determine which type of monitor an ast_cc_device_monitor is.

Enumerator:
AST_CC_DEVICE_MONITOR 
AST_CC_EXTENSION_MONITOR 

Definition at line 496 of file ccss.h.

00496                           {
00497    AST_CC_DEVICE_MONITOR,
00498    AST_CC_EXTENSION_MONITOR,
00499 };

The various possibilities for cc_monitor_policy values.

Since:
1.8
Enumerator:
AST_CC_MONITOR_NEVER  Never accept CCSS offers from callee
AST_CC_MONITOR_NATIVE 
AST_CC_MONITOR_GENERIC  Always use CCSS generic monitor for callee Note that if callee offers CCSS natively, we still will use a generic CCSS monitor if this is set
AST_CC_MONITOR_ALWAYS  Accept native CCSS offers, but if no offer is present, use a generic CCSS monitor

Definition at line 74 of file ccss.h.

00074                              {
00075    /*! Never accept CCSS offers from callee */
00076    AST_CC_MONITOR_NEVER,
00077    /* CCSS only available if callee offers it through signaling */
00078    AST_CC_MONITOR_NATIVE,
00079    /*! Always use CCSS generic monitor for callee
00080     * Note that if callee offers CCSS natively, we still
00081     * will use a generic CCSS monitor if this is set
00082     */
00083    AST_CC_MONITOR_GENERIC,
00084    /*! Accept native CCSS offers, but if no offer is present,
00085     * use a generic CCSS monitor
00086     */
00087    AST_CC_MONITOR_ALWAYS,
00088 };

Enumerator:
AST_CC_NONE 
AST_CC_CCBS 
AST_CC_CCNR 
AST_CC_CCNL 

Definition at line 32 of file ccss.h.

00032                          {
00033    /* No Service available/requested */
00034    AST_CC_NONE,
00035    /* Call Completion Busy Subscriber */
00036    AST_CC_CCBS,
00037    /* Call Completion No Response */
00038    AST_CC_CCNR,
00039    /* Call Completion Not Logged In (currently SIP only) */
00040    AST_CC_CCNL,
00041 };


Function Documentation

struct ast_cc_config_params* __ast_cc_config_params_init ( const char *  file,
int  line,
const char *  function 
) [read]

Allocate and initialize an ast_cc_config_params structure.

Note:
Reasonable default values are chosen for the parameters upon allocation.
Return values:
NULL Unable to allocate the structure
non-NULL A pointer to the newly allocated and initialized structure

Definition at line 683 of file ccss.c.

References __ast_malloc(), ast_cc_default_config_params(), ast_malloc, and NULL.

00684 {
00685 #if defined(__AST_DEBUG_MALLOC)
00686    struct ast_cc_config_params *params = __ast_malloc(sizeof(*params), file, line, function);
00687 #else
00688    struct ast_cc_config_params *params = ast_malloc(sizeof(*params));
00689 #endif
00690 
00691    if (!params) {
00692       return NULL;
00693    }
00694 
00695    ast_cc_default_config_params(params);
00696    return params;
00697 }

int ast_cc_agent_accept_request ( int  core_id,
const char *const   debug,
  ... 
)

Accept inbound CC request.

Since:
1.8
When a caller requests CC, this function should be called to let the core know that the request has been accepted.

Parameters:
core_id core_id of the CC transaction
debug optional string to print for debugging purposes
Return values:
0 Success
-1 Failure

Definition at line 3773 of file ccss.c.

References CC_CALLER_REQUESTED, and cc_request_state_change().

Referenced by ccreq_exec(), and handle_cc_subscribe().

03774 {
03775    va_list ap;
03776    int res;
03777 
03778    va_start(ap, debug);
03779    res = cc_request_state_change(CC_CALLER_REQUESTED, core_id, debug, ap);
03780    va_end(ap);
03781    return res;
03782 }

struct ast_cc_agent* ast_cc_agent_callback ( int  flags,
ao2_callback_fn function,
void *  arg,
const char *const   type 
) [read]

Call a callback on all agents of a specific type.

Since the container of CC core instances is private, and so are the items which the container contains, we have to provide an ao2_callback-like method so that a specific agent may be found or so that an operation can be made on all agents of a particular type. The first three arguments should be familiar to anyone who has used ao2_callback. The final argument is the type of agent you wish to have the callback called on.

Note:
Since agents are refcounted, and this function returns a reference to the agent, it is imperative that you decrement the refcount of the agent once you have finished using it.
Parameters:
flags astobj2 search flags
function an ao2 callback function to call
arg the argument to the callback function
type The type of agents to call the callback on

Definition at line 458 of file ccss.c.

References cc_core_instance::agent, ao2_t_callback, cc_agent_callback_helper(), cc_ref(), cc_unref(), cc_callback_helper::function, and NULL.

Referenced by find_sip_cc_agent_by_notify_uri(), find_sip_cc_agent_by_original_callid(), and find_sip_cc_agent_by_subscribe_uri().

00459 {
00460    struct cc_callback_helper helper = {.function = function, .args = args, .type = type};
00461    struct cc_core_instance *core_instance;
00462    if ((core_instance = ao2_t_callback(cc_core_instances, flags, cc_agent_callback_helper, &helper,
00463                "Calling provided agent callback function"))) {
00464       struct ast_cc_agent *agent = cc_ref(core_instance->agent, "An outside entity needs the agent");
00465       cc_unref(core_instance, "agent callback done with the core_instance");
00466       return agent;
00467    }
00468    return NULL;
00469 }

int ast_cc_agent_caller_available ( int  core_id,
const char *const   debug,
  ... 
)

Indicate that a previously unavailable caller has become available.

Since:
1.8
If a monitor is suspended due to a caller becoming unavailable, then this function should be called to indicate that the caller has become available.

Parameters:
core_id core_id of the CC transaction
debug optional string to print for debugging purposes
Return values:
0 Success
-1 Failure

Definition at line 3817 of file ccss.c.

References CC_ACTIVE, and cc_request_state_change().

Referenced by generic_agent_devstate_cb().

03818 {
03819    va_list ap;
03820    int res;
03821 
03822    va_start(ap, debug);
03823    res = cc_request_state_change(CC_ACTIVE, core_id, debug, ap);
03824    va_end(ap);
03825    return res;
03826 }

int ast_cc_agent_caller_busy ( int  core_id,
const char *const   debug,
  ... 
)

Indicate that the caller is busy.

Since:
1.8
When the callee makes it known that he is available, the core will let the caller's channel driver know that it may attempt to let the caller know to attempt a recall. If the channel driver can detect, though, that the caller is busy, then the channel driver should call this function to let the CC core know.

Parameters:
core_id core_id of the CC transaction
debug optional string to print for debugging purposes
Return values:
0 Success
-1 Failure

Definition at line 3806 of file ccss.c.

References CC_CALLER_BUSY, and cc_request_state_change().

Referenced by cc_generic_agent_recall(), and sip_cc_agent_recall().

03807 {
03808    va_list ap;
03809    int res;
03810 
03811    va_start(ap, debug);
03812    res = cc_request_state_change(CC_CALLER_BUSY, core_id, debug, ap);
03813    va_end(ap);
03814    return res;
03815 }

int ast_cc_agent_recalling ( int  core_id,
const char *const   debug,
  ... 
)

Tell the CC core that a caller is currently recalling.

Since:
1.8
The main purpose of this is so that the core can alert the monitor to stop its available timer since the caller has begun its recall phase.

Parameters:
core_id core_id of the CC transaction
debug optional string to print for debugging purposes
Return values:
0 Success
-1 Failure

Definition at line 3828 of file ccss.c.

References CC_RECALLING, and cc_request_state_change().

Referenced by generic_recall(), and get_destination().

03829 {
03830    va_list ap;
03831    int res;
03832 
03833    va_start(ap, debug);
03834    res = cc_request_state_change(CC_RECALLING, core_id, debug, ap);
03835    va_end(ap);
03836    return res;
03837 }

int ast_cc_agent_register ( const struct ast_cc_agent_callbacks callbacks  ) 

Register a set of agent callbacks with the core.

Since:
1.8
This is made so that at agent creation time, the proper callbacks may be installed and the proper .init callback may be called for the monitor to establish private data.

Parameters:
callbacks The callbacks used by the agent implementation
Return values:
0 Successfully registered
-1 Failure to register

Definition at line 1228 of file ccss.c.

References ast_calloc, AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and cc_agent_backend::callbacks.

Referenced by ast_cc_init(), and load_module().

01229 {
01230    struct cc_agent_backend *backend = ast_calloc(1, sizeof(*backend));
01231 
01232    if (!backend) {
01233       return -1;
01234    }
01235 
01236    backend->callbacks = callbacks;
01237    AST_RWLIST_WRLOCK(&cc_agent_backends);
01238    AST_RWLIST_INSERT_TAIL(&cc_agent_backends, backend, next);
01239    AST_RWLIST_UNLOCK(&cc_agent_backends);
01240    return 0;
01241 }

int ast_cc_agent_set_interfaces_chanvar ( struct ast_channel chan  ) 

Set the first level CC_INTERFACES channel variable for a channel.

Since:
1.8
Note:
Implementers of protocol-specific CC agents should call this function after calling ast_setup_cc_recall_datastore.

This function will lock the channel as well as the list of monitors stored on the channel's CC recall datastore, though neither are held at the same time. Callers of this function should be aware of potential lock ordering problems that may arise.

The CC_INTERFACES channel variable will have the interfaces that should be called back for a specific PBX instance.

Parameters:
chan The channel to set the CC_INTERFACES variable on

Definition at line 3628 of file ccss.c.

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_free, AST_LIST_FIRST, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log_dynamic_level, ast_str_buffer(), ast_str_create(), build_cc_interfaces_chanvar(), cc_recall_ds_data::core_id, ast_datastore::data, cc_recall_ds_data::interface_tree, monitor, NULL, pbx_builtin_setvar_helper(), and str.

Referenced by generic_recall(), and handle_request_invite().

03629 {
03630    struct ast_datastore *recall_datastore;
03631    struct cc_monitor_tree *interface_tree;
03632    struct ast_cc_monitor *monitor;
03633    struct cc_recall_ds_data *recall_data;
03634    struct ast_str *str = ast_str_create(64);
03635    int core_id;
03636 
03637    if (!str) {
03638       return -1;
03639    }
03640 
03641    ast_channel_lock(chan);
03642    if (!(recall_datastore = ast_channel_datastore_find(chan, &recall_ds_info, NULL))) {
03643       ast_channel_unlock(chan);
03644       ast_free(str);
03645       return -1;
03646    }
03647    recall_data = recall_datastore->data;
03648    interface_tree = recall_data->interface_tree;
03649    core_id = recall_data->core_id;
03650    ast_channel_unlock(chan);
03651 
03652    AST_LIST_LOCK(interface_tree);
03653    monitor = AST_LIST_FIRST(interface_tree);
03654    build_cc_interfaces_chanvar(monitor, &str);
03655    AST_LIST_UNLOCK(interface_tree);
03656 
03657    pbx_builtin_setvar_helper(chan, "CC_INTERFACES", ast_str_buffer(str));
03658    ast_log_dynamic_level(cc_logger_level, "Core %d: CC_INTERFACES set to %s\n",
03659          core_id, ast_str_buffer(str));
03660 
03661    ast_free(str);
03662    return 0;
03663 }

int ast_cc_agent_status_response ( int  core_id,
enum ast_device_state  devstate 
)

Response with a caller's current status.

When an ISDN PTMP monitor requests the caller's status, the agent must respond to the request using this function. For simplicity it is recommended that the devstate parameter be one of AST_DEVICE_INUSE or AST_DEVICE_NOT_INUSE.

Parameters:
core_id The core ID of the CC transaction
devstate The current state of the caller to which the agent pertains
Return values:
0 Successfully responded with our status
-1 Failed to respond with our status

Definition at line 4090 of file ccss.c.

References args, ast_calloc, ast_free, ast_taskprocessor_push(), cc_status_response(), cc_unref(), cc_status_response_args::core_instance, cc_status_response_args::devstate, and find_cc_core_instance().

Referenced by cc_generic_agent_status_request(), and sip_cc_agent_status_request().

04091 {
04092    struct cc_status_response_args *args;
04093    struct cc_core_instance *core_instance;
04094    int res;
04095 
04096    args = ast_calloc(1, sizeof(*args));
04097    if (!args) {
04098       return -1;
04099    }
04100 
04101    core_instance = find_cc_core_instance(core_id);
04102    if (!core_instance) {
04103       ast_free(args);
04104       return -1;
04105    }
04106 
04107    args->core_instance = core_instance;
04108    args->devstate = devstate;
04109 
04110    res = ast_taskprocessor_push(cc_core_taskprocessor, cc_status_response, args);
04111    if (res) {
04112       cc_unref(core_instance, "Unref core instance. ast_taskprocessor_push failed");
04113       ast_free(args);
04114    }
04115    return res;
04116 }

void ast_cc_agent_unregister ( const struct ast_cc_agent_callbacks callbacks  ) 

Unregister a set of agent callbacks with the core.

Since:
1.8
If a module which makes use of a CC agent is unloaded, then it may unregister its agent callbacks with the core.

Parameters:
callbacks The callbacks used by the agent implementation
Return values:
0 Successfully unregistered
-1 Failure to unregister

Definition at line 1243 of file ccss.c.

References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, cc_agent_backend::callbacks, and cc_monitor_backend::next.

Referenced by __unload_module(), cc_shutdown(), and unload_module().

01244 {
01245    struct cc_agent_backend *backend;
01246    AST_RWLIST_WRLOCK(&cc_agent_backends);
01247    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&cc_agent_backends, backend, next) {
01248       if (backend->callbacks == callbacks) {
01249          AST_RWLIST_REMOVE_CURRENT(next);
01250          ast_free(backend);
01251          break;
01252       }
01253    }
01254    AST_RWLIST_TRAVERSE_SAFE_END;
01255    AST_RWLIST_UNLOCK(&cc_agent_backends);
01256 }

int ast_cc_available_timer_expire ( const void *  data  ) 

Scheduler callback for available timer expiration.

Since:
1.8
Note:
When arming the available timer from within a device monitor, you MUST use this function as the callback for the scheduler.
Parameters:
data A reference to the CC monitor on which the timer was running.

Definition at line 1507 of file ccss.c.

References ast_cc_monitor_failed(), ast_cc_monitor::available_timer_id, cc_unref(), ast_cc_monitor::core_id, ast_cc_interface::device_name, ast_cc_monitor::interface, and monitor.

Referenced by cc_generic_monitor_request_cc(), and sip_cc_monitor_request_cc().

01508 {
01509    struct ast_cc_monitor *monitor = (struct ast_cc_monitor *) data;
01510    int res;
01511    monitor->available_timer_id = -1;
01512    res = ast_cc_monitor_failed(monitor->core_id, monitor->interface->device_name, "Available timer expired for monitor");
01513    cc_unref(monitor, "Unref reference from scheduler\n");
01514    return res;
01515 }

int ast_cc_build_frame ( struct ast_channel chan,
struct ast_cc_config_params cc_params,
const char *  monitor_type,
const char *const   device_name,
const char *const   dialstring,
enum ast_cc_service_type  service,
void *  private_data,
struct ast_frame frame 
)

Create a CC Control frame.

Since:
1.8
chan_dahdi is weird. It doesn't seem to actually queue frames when it needs to tell an application something. Instead it wakes up, tells the application that it has data ready, and then based on set flags, creates the proper frame type. For chan_dahdi, we provide this function. It provides us the data we need, and we'll make its frame for it.

Parameters:
chan A channel involved in the call. What we want is on a datastore on both incoming and outgoing so either may be provided
cc_params The CC configuration parameters for the outbound target
monitor_type The type of monitor to use when CC is requested
device_name The name of the outbound target device.
dialstring The dial string used when calling this specific interface
service What kind of CC service is being offered. (CCBS/CCNR/etc...)
private_data If a native monitor is being used, and some channel-driver-specific private data has been allocated, then this parameter should contain a pointer to that data. If using a generic monitor, this parameter should remain NULL. Note that if this function should fail at some point, it is the responsibility of the caller to free the private data upon return.
[out] frame The frame we will be returning to the caller. It is vital that ast_frame_free be called on this frame since the payload will be allocated on the heap.
Return values:
-1 Failure. At some point there was a failure. Do not attempt to use the frame in this case.
0 Success

Definition at line 4173 of file ccss.c.

References ast_calloc, AST_CONTROL_CC, AST_FRAME_CONTROL, ast_free, AST_MALLOCD_DATA, cc_build_payload(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, ast_frame_subclass::integer, ast_frame::mallocd, ast_frame::ptr, and ast_frame::subclass.

Referenced by ast_queue_cc_frame().

04177 {
04178    struct cc_control_payload *payload = ast_calloc(1, sizeof(*payload));
04179 
04180    if (!payload) {
04181       return -1;
04182    }
04183    if (cc_build_payload(chan, cc_params, monitor_type, device_name, dialstring, service, private_data, payload)) {
04184       /* Something screwed up, we can't make a frame with this */
04185       ast_free(payload);
04186       return -1;
04187    }
04188    frame->frametype = AST_FRAME_CONTROL;
04189    frame->subclass.integer = AST_CONTROL_CC;
04190    frame->data.ptr = payload;
04191    frame->datalen = sizeof(*payload);
04192    frame->mallocd = AST_MALLOCD_DATA;
04193    return 0;
04194 }

void ast_cc_busy_interface ( struct ast_channel inbound,
struct ast_cc_config_params cc_params,
const char *  monitor_type,
const char *const   device_name,
const char *const   dialstring,
void *  private_data 
)

Callback made from ast_cc_callback for certain channel types.

Since:
1.8
Parameters:
inbound Incoming asterisk channel.
cc_params The CC configuration parameters for the outbound target
monitor_type The type of monitor to use when CC is requested
device_name The name of the outbound target device.
dialstring The dial string used when calling this specific interface
private_data If a native monitor is being used, and some channel-driver-specific private data has been allocated, then this parameter should contain a pointer to that data. If using a generic monitor, this parameter should remain NULL. Note that if this function should fail at some point, it is the responsibility of the caller to free the private data upon return.
For channel types that fail ast_request when the device is busy, we call into the channel driver with ast_cc_callback. This is the callback that is called in that case for each device found which could have been returned by ast_request.

This function creates a CC control frame payload, simulating the act of reading it from the nonexistent outgoing channel's frame queue. We then handle this simulated frame just as we would a normal CC frame which had actually been queued by the channel driver.

Definition at line 4229 of file ccss.c.

References AST_CC_CCBS, ast_handle_cc_control_frame(), call_destructor_with_no_monitor(), cc_build_payload(), and NULL.

Referenced by dial_exec_full().

04231 {
04232    struct cc_control_payload payload;
04233    if (cc_build_payload(inbound, cc_params, monitor_type, device_name, dialstring, AST_CC_CCBS, private_data, &payload)) {
04234       /* Something screwed up. Don't try to handle this payload */
04235       call_destructor_with_no_monitor(monitor_type, private_data);
04236       return;
04237    }
04238    ast_handle_cc_control_frame(inbound, NULL, &payload);
04239 }

void ast_cc_call_failed ( struct ast_channel incoming,
struct ast_channel outgoing,
const char *const   dialstring 
)

Make CCBS available in the case that ast_call fails.

Since:
1.8 In some situations, notably if a call-limit is reached in SIP, ast_call will fail due to Asterisk's knowing that the desired device is currently busy. In such a situation, CCBS should be made available to the caller.
One caveat is that this may only be used if generic monitoring is being used. The reason is that since Asterisk determined that the device was busy without actually placing a call to it, the far end will have no idea what call we are requesting call completion for if we were to send a call completion request.

Definition at line 4196 of file ccss.c.

References AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CC_CCBS, AST_CC_GENERIC_MONITOR_TYPE, AST_CC_MONITOR_GENERIC, ast_channel_get_cc_config_params(), ast_channel_get_device_name(), ast_channel_hangupcause(), AST_CHANNEL_NAME, ast_get_cc_monitor_policy(), ast_handle_cc_control_frame(), cc_build_payload(), and NULL.

Referenced by dial_exec_full().

04197 {
04198    char device_name[AST_CHANNEL_NAME];
04199    struct cc_control_payload payload;
04200    struct ast_cc_config_params *cc_params;
04201 
04202    if (ast_channel_hangupcause(outgoing) != AST_CAUSE_BUSY && ast_channel_hangupcause(outgoing) != AST_CAUSE_CONGESTION) {
04203       /* It doesn't make sense to try to offer CCBS to the caller if the reason for ast_call
04204        * failing is something other than busy or congestion
04205        */
04206       return;
04207    }
04208 
04209    cc_params = ast_channel_get_cc_config_params(outgoing);
04210    if (!cc_params) {
04211       return;
04212    }
04213    if (ast_get_cc_monitor_policy(cc_params) != AST_CC_MONITOR_GENERIC) {
04214       /* This sort of CCBS only works if using generic CC. For native, we would end up sending
04215        * a CC request for a non-existent call. The far end will reject this every time
04216        */
04217       return;
04218    }
04219 
04220    ast_channel_get_device_name(outgoing, device_name, sizeof(device_name));
04221    if (cc_build_payload(outgoing, cc_params, AST_CC_GENERIC_MONITOR_TYPE, device_name,
04222       dialstring, AST_CC_CCBS, NULL, &payload)) {
04223       /* Something screwed up, we can't make a frame with this */
04224       return;
04225    }
04226    ast_handle_cc_control_frame(incoming, outgoing, &payload);
04227 }

int ast_cc_call_init ( struct ast_channel chan,
int *  ignore_cc 
)

Start the CC process on a call.

Since:
1.8
Whenever a CC-capable application, such as Dial, wishes to engage in CC activity, it initiates the process by calling this function. If the CC core should discover that a previous application has called ast_ignore_cc on this channel or a "parent" channel, then the value of the ignore_cc integer passed in will be set nonzero.

The ignore_cc parameter is a convenience parameter. It can save an application the trouble of trying to call CC APIs when it knows that it should just ignore further attempts at CC actions.

Parameters:
chan The inbound channel calling the CC-capable application.
[out] ignore_cc Will be set non-zero if no further CC actions need to be taken
Return values:
0 Success
-1 Failure

Definition at line 2409 of file ccss.c.

References AST_CC_AGENT_NEVER, ast_channel_context(), ast_channel_datastore_find(), ast_channel_exten(), ast_channel_get_cc_config_params(), ast_channel_lock, ast_channel_macrocontext(), ast_channel_macroexten(), ast_channel_name(), ast_channel_unlock, ast_get_cc_agent_policy(), AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log_dynamic_level, cc_extension_monitor_init(), cc_interfaces_datastore_init(), cc_ref(), cc_unref(), dialed_cc_interfaces::core_id, ast_cc_monitor::core_id, ast_datastore::data, dialed_cc_interfaces::dial_parent_id, ast_cc_monitor::id, dialed_cc_interfaces::ignore, dialed_cc_interfaces::interface_tree, interfaces, monitor, NULL, and S_OR.

Referenced by dial_exec_full().

02410 {
02411    /* There are three situations to deal with here:
02412     *
02413     * 1. The channel does not have a dialed_cc_interfaces datastore on
02414     * it. This means that this is the first time that Dial has
02415     * been called. We need to create/initialize the datastore.
02416     *
02417     * 2. The channel does have a cc_interface datastore on it and
02418     * the "ignore" indicator is 0. This means that a Local channel
02419     * was called by a "parent" dial. We can check the datastore's
02420     * parent field to see who the root of this particular dial tree
02421     * is.
02422     *
02423     * 3. The channel does have a cc_interface datastore on it and
02424     * the "ignore" indicator is 1. This means that a second Dial call
02425     * is being made from an extension. In this case, we do not
02426     * want to make any additions/modifications to the datastore. We
02427     * will instead set a flag to indicate that CCSS is completely
02428     * disabled for this Dial attempt.
02429     */
02430 
02431    struct ast_datastore *cc_interfaces_datastore;
02432    struct dialed_cc_interfaces *interfaces;
02433    struct ast_cc_monitor *monitor;
02434    struct ast_cc_config_params *cc_params;
02435 
02436    ast_channel_lock(chan);
02437 
02438    cc_params = ast_channel_get_cc_config_params(chan);
02439    if (!cc_params) {
02440       ast_channel_unlock(chan);
02441       return -1;
02442    }
02443    if (ast_get_cc_agent_policy(cc_params) == AST_CC_AGENT_NEVER) {
02444       /* We can't offer CC to this caller anyway, so don't bother with CC on this call
02445        */
02446       *ignore_cc = 1;
02447       ast_channel_unlock(chan);
02448       ast_log_dynamic_level(cc_logger_level, "Agent policy for %s is 'never'. CC not possible\n", ast_channel_name(chan));
02449       return 0;
02450    }
02451 
02452    if (!(cc_interfaces_datastore = ast_channel_datastore_find(chan, &dialed_cc_interfaces_info, NULL))) {
02453       /* Situation 1 has occurred */
02454       ast_channel_unlock(chan);
02455       return cc_interfaces_datastore_init(chan);
02456    }
02457    interfaces = cc_interfaces_datastore->data;
02458    ast_channel_unlock(chan);
02459 
02460    if (interfaces->ignore) {
02461       /* Situation 3 has occurred */
02462       *ignore_cc = 1;
02463       ast_log_dynamic_level(cc_logger_level, "Datastore is present with ignore flag set. Ignoring CC offers on this call\n");
02464       return 0;
02465    }
02466 
02467    /* Situation 2 has occurred */
02468    if (!(monitor = cc_extension_monitor_init(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)),
02469          S_OR(ast_channel_macrocontext(chan), ast_channel_context(chan)), interfaces->dial_parent_id))) {
02470       return -1;
02471    }
02472    monitor->core_id = interfaces->core_id;
02473    AST_LIST_LOCK(interfaces->interface_tree);
02474    cc_ref(monitor, "monitor tree's reference to the monitor");
02475    AST_LIST_INSERT_TAIL(interfaces->interface_tree, monitor, next);
02476    AST_LIST_UNLOCK(interfaces->interface_tree);
02477    interfaces->dial_parent_id = monitor->id;
02478    cc_unref(monitor, "Unref monitor's allocation reference");
02479    return 0;
02480 }

int ast_cc_callback ( struct ast_channel inbound,
const char *const   tech,
const char *const   dest,
ast_cc_callback_fn  callback 
)

Run a callback for potential matching destinations.

Since:
1.8
Note:
See the explanation in ast_channel_tech::cc_callback for more details.
Parameters:
inbound 
tech Channel technology to use
dest Channel/group/peer or whatever the specific technology uses
callback Function to call when a target is reached
Return values:
Always 0, I guess.

Definition at line 4241 of file ccss.c.

References ast_get_channel_tech(), and ast_channel_tech::cc_callback.

Referenced by dial_exec_full().

04242 {
04243    const struct ast_channel_tech *chantech = ast_get_channel_tech(tech);
04244 
04245    if (chantech && chantech->cc_callback) {
04246       chantech->cc_callback(inbound, dest, callback);
04247    }
04248 
04249    return 0;
04250 }

int ast_cc_completed ( struct ast_channel chan,
const char *const   debug,
  ... 
)

Indicate recall has been acknowledged.

Since:
1.8
When we receive confirmation that an endpoint has responded to our CC recall, we call this function.

Parameters:
chan The inbound channel making the CC recall
debug optional string to print for debugging purposes
Return values:
0 Success
-1 Failure

Definition at line 3839 of file ccss.c.

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, CC_COMPLETE, cc_request_state_change(), cc_recall_ds_data::core_id, ast_datastore::data, cc_recall_ds_data::ignore, cc_recall_ds_data::nested, and NULL.

Referenced by wait_for_answer().

03840 {
03841    struct ast_datastore *recall_datastore;
03842    struct cc_recall_ds_data *recall_data;
03843    int core_id;
03844    va_list ap;
03845    int res;
03846 
03847    ast_channel_lock(chan);
03848    if (!(recall_datastore = ast_channel_datastore_find(chan, &recall_ds_info, NULL))) {
03849       /* Silly! Why did you call this function if there's no recall DS? */
03850       ast_channel_unlock(chan);
03851       return -1;
03852    }
03853    recall_data = recall_datastore->data;
03854    if (recall_data->nested || recall_data->ignore) {
03855       /* If this is being called from a nested Dial, it is too
03856        * early to determine if the recall has actually completed.
03857        * The outermost dial is the only one with the authority to
03858        * declare the recall to be complete.
03859        *
03860        * Similarly, if this function has been called when the
03861        * recall has progressed beyond the first dial, this is not
03862        * a legitimate time to declare the recall to be done. In fact,
03863        * that should have been done already.
03864        */
03865       ast_channel_unlock(chan);
03866       return -1;
03867    }
03868    core_id = recall_data->core_id;
03869    ast_channel_unlock(chan);
03870    va_start(ap, debug);
03871    res = cc_request_state_change(CC_COMPLETE, core_id, debug, ap);
03872    va_end(ap);
03873    return res;
03874 }

void ast_cc_config_params_destroy ( struct ast_cc_config_params params  ) 

Free memory from CCSS configuration params.

Note:
Just a call to ast_free for now...
Parameters:
params Pointer to structure whose memory we need to free
Return values:
void 

Definition at line 699 of file ccss.c.

References ast_free.

Referenced by __sip_destroy(), agent_destroy(), ast_channel_cc_params_init(), cc_interface_destroy(), channel_cc_params_destroy(), dahdi_create_channel_range(), destroy_dahdi_pvt(), process_dahdi(), setup_dahdi(), and sip_destroy_peer().

00700 {
00701    ast_free(params);
00702 }

void ast_cc_copy_config_params ( struct ast_cc_config_params dest,
const struct ast_cc_config_params src 
)

copy CCSS configuration parameters from one structure to another

Since:
1.8
For now, this is a simple memcpy, but this function is necessary since the size of an ast_cc_config_params structure is unknown outside of main/ccss.c. Also, this allows for easier expansion of the function in case it becomes more complex than just a memcpy.

Parameters:
src The structure from which data is copied
dest The structure to which data is copied
Returns:
Nothing

Definition at line 867 of file ccss.c.

Referenced by ast_channel_cc_params_init(), cc_agent_init(), cc_build_payload(), cc_device_monitor_init(), channel_cc_params_copy(), check_peer_ok(), create_addr_from_peer(), dahdi_new(), deep_copy_dahdi_chan_conf(), duplicate_pseudo(), and mkintf().

00868 {
00869    *dest = *src;
00870 }

void ast_cc_default_config_params ( struct ast_cc_config_params params  ) 

Set the specified CC config params to default values.

Since:
1.8
This is just like ast_cc_copy_config_params() and could be used in place of it if you need to set the config params to defaults instead. You are simply "copying" defaults into the destination.

Parameters:
params CC config params to set to default values.
Returns:
Nothing

Definition at line 678 of file ccss.c.

Referenced by __ast_cc_config_params_init().

00679 {
00680    *params = cc_default_params;
00681 }

void ast_cc_extension_monitor_add_dialstring ( struct ast_channel incoming,
const char *const   dialstring,
const char *const   device_name 
)

Add a child dialstring to an extension monitor.

Since:
1.8
Whenever we request a channel, the parent extension monitor needs to store the dialstring of the device requested. The reason is so that we can call the device back during the recall even if we are not monitoring the device.

Parameters:
incoming The caller's channel
dialstring The dialstring used when requesting the outbound channel
device_name The device name associated with the requested outbound channel
Return values:
void 

Definition at line 2003 of file ccss.c.

References ast_calloc, ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, extension_monitor_pvt::child_dialstrings, ast_datastore::data, extension_child_dialstring::device_name, dialed_cc_interfaces::dial_parent_id, ast_cc_monitor::id, id, dialed_cc_interfaces::interface_tree, extension_child_dialstring::is_valid, monitor, NULL, extension_child_dialstring::original_dialstring, and ast_cc_monitor::private_data.

Referenced by dial_exec_full().

02004 {
02005    struct ast_datastore *cc_datastore;
02006    struct dialed_cc_interfaces *cc_interfaces;
02007    struct ast_cc_monitor *monitor;
02008    struct extension_monitor_pvt *extension_pvt;
02009    struct extension_child_dialstring *child_dialstring;
02010    struct cc_monitor_tree *interface_tree;
02011    int id;
02012 
02013    ast_channel_lock(incoming);
02014    if (!(cc_datastore = ast_channel_datastore_find(incoming, &dialed_cc_interfaces_info, NULL))) {
02015       ast_channel_unlock(incoming);
02016       return;
02017    }
02018 
02019    cc_interfaces = cc_datastore->data;
02020    interface_tree = cc_interfaces->interface_tree;
02021    id = cc_interfaces->dial_parent_id;
02022    ast_channel_unlock(incoming);
02023 
02024    AST_LIST_LOCK(interface_tree);
02025    AST_LIST_TRAVERSE(interface_tree, monitor, next) {
02026       if (monitor->id == id) {
02027          break;
02028       }
02029    }
02030 
02031    if (!monitor) {
02032       AST_LIST_UNLOCK(interface_tree);
02033       return;
02034    }
02035 
02036    extension_pvt = monitor->private_data;
02037    if (!(child_dialstring = ast_calloc(1, sizeof(*child_dialstring)))) {
02038       AST_LIST_UNLOCK(interface_tree);
02039       return;
02040    }
02041    ast_copy_string(child_dialstring->original_dialstring, dialstring, sizeof(child_dialstring->original_dialstring));
02042    ast_copy_string(child_dialstring->device_name, device_name, sizeof(child_dialstring->device_name));
02043    child_dialstring->is_valid = 1;
02044    AST_LIST_INSERT_TAIL(&extension_pvt->child_dialstrings, child_dialstring, next);
02045    AST_LIST_UNLOCK(interface_tree);
02046 }

int ast_cc_failed ( int  core_id,
const char *const   debug,
  ... 
)

Indicate failure has occurred.

Since:
1.8
If at any point a failure occurs, this is the function to call so that the core can initiate cleanup procedures.

Parameters:
core_id core_id of the CC transaction
debug optional string to print for debugging purposes
Return values:
0 Success
-1 Failure

Definition at line 3876 of file ccss.c.

References CC_FAILED, and cc_request_state_change().

Referenced by cancel_available_timer(), cc_caller_offered(), cc_caller_requested(), cc_monitor_failed(), cccancel_exec(), ccreq_exec(), generic_recall(), handle_cc_subscribe(), kill_cores(), offer_timer_expire(), request_cc(), sip_offer_timer_expire(), suspend(), unsuspend(), and wait_for_answer().

03877 {
03878    va_list ap;
03879    int res;
03880 
03881    va_start(ap, debug);
03882    res = cc_request_state_change(CC_FAILED, core_id, debug, ap);
03883    va_end(ap);
03884    return res;
03885 }

int ast_cc_get_current_core_id ( struct ast_channel chan  ) 

Get the core id for the current call.

Since:
1.8
The main use of this function is for channel drivers who queue an AST_CONTROL_CC frame. A channel driver may call this function in order to get the core_id for what may become a CC request. This way, when monitor functions are called which use a core_id as a means of identification, the channel driver will have saved this information.

The channel given to this function may be an inbound or outbound channel. Both will have the necessary info on it.

Parameters:
chan The channel from which to get the core_id.
Return values:
core_id on success
-1 Failure

Definition at line 2487 of file ccss.c.

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, dialed_cc_interfaces::core_id, ast_datastore::data, dialed_cc_interfaces::ignore, and NULL.

Referenced by sip_handle_cc().

02488 {
02489    struct ast_datastore *datastore;
02490    struct dialed_cc_interfaces *cc_interfaces;
02491    int core_id_return;
02492 
02493    ast_channel_lock(chan);
02494    if (!(datastore = ast_channel_datastore_find(chan, &dialed_cc_interfaces_info, NULL))) {
02495       ast_channel_unlock(chan);
02496       return -1;
02497    }
02498 
02499    cc_interfaces = datastore->data;
02500    core_id_return = cc_interfaces->ignore ? -1 : cc_interfaces->core_id;
02501    ast_channel_unlock(chan);
02502    return core_id_return;
02503 
02504 }

struct ast_cc_monitor* ast_cc_get_monitor_by_recall_core_id ( const int  core_id,
const char *const   device_name 
) [read]

Get the associated monitor given the device name and core_id.

Since:
1.8
The function ast_cc_is_recall is helpful for determining if a call to a specific channel is a recall. However, once you have determined that this is a recall, you will most likely need access to the private data within the associated monitor. This function is what one uses to get that monitor.

Note:
This function locks the list of monitors that correspond to the core_id passed in. Be sure that you have no potential lock order issues when calling this function.
Parameters:
core_id The core ID to which this recall corresponds. This likely will have been obtained using the ast_cc_is_recall function
device_name Which device to find the monitor for.
Return values:
NULL Appropriate monitor does not exist
non-NULL The monitor to use for this recall

Definition at line 3516 of file ccss.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, cc_ref(), cc_unref(), ast_cc_interface::device_name, find_cc_core_instance(), ast_cc_monitor::interface, cc_core_instance::monitors, and NULL.

Referenced by sip_call().

03517 {
03518    struct cc_core_instance *core_instance = find_cc_core_instance(core_id);
03519    struct ast_cc_monitor *monitor_iter;
03520 
03521    if (!core_instance) {
03522       return NULL;
03523    }
03524 
03525    AST_LIST_LOCK(core_instance->monitors);
03526    AST_LIST_TRAVERSE(core_instance->monitors, monitor_iter, next) {
03527       if (!strcmp(monitor_iter->interface->device_name, device_name)) {
03528          /* Found a monitor. */
03529          cc_ref(monitor_iter, "Hand the requester of the monitor a reference");
03530          break;
03531       }
03532    }
03533    AST_LIST_UNLOCK(core_instance->monitors);
03534    cc_unref(core_instance, "Done with core instance ref in ast_cc_get_monitor_by_recall_core_id");
03535    return monitor_iter;
03536 }

int ast_cc_get_param ( struct ast_cc_config_params params,
const char *const   name,
char *  buf,
size_t  buf_len 
)

get a CCSS configuration parameter, given its name

Note:
Useful when reading input as a string, like from dialplan or manager.
Parameters:
params The CCSS configuration from which to get the value
name The name of the CCSS parameter we want
buf A preallocated buffer to hold the value
buf_len The size of buf
Return values:
0 Success
-1 Failure

Definition at line 765 of file ccss.c.

References agent_policy_to_str(), ast_copy_string(), ast_get_cc_agent_dialstring(), ast_get_cc_agent_policy(), ast_get_cc_callback_macro(), ast_get_cc_callback_sub(), ast_get_cc_max_agents(), ast_get_cc_max_monitors(), ast_get_cc_monitor_policy(), ast_get_cc_offer_timer(), ast_get_cc_recall_timer(), ast_get_ccbs_available_timer(), ast_get_ccnr_available_timer(), ast_log, LOG_WARNING, monitor_policy_to_str(), NULL, and value.

Referenced by acf_cc_read().

00767 {
00768    const char *value = NULL;
00769 
00770    if (!strcasecmp(name, "cc_callback_macro")) {
00771       value = ast_get_cc_callback_macro(params);
00772    } else if (!strcasecmp(name, "cc_callback_sub")) {
00773       value = ast_get_cc_callback_sub(params);
00774    } else if (!strcasecmp(name, "cc_agent_policy")) {
00775       value = agent_policy_to_str(ast_get_cc_agent_policy(params));
00776    } else if (!strcasecmp(name, "cc_monitor_policy")) {
00777       value = monitor_policy_to_str(ast_get_cc_monitor_policy(params));
00778    } else if (!strcasecmp(name, "cc_agent_dialstring")) {
00779       value = ast_get_cc_agent_dialstring(params);
00780    }
00781    if (value) {
00782       ast_copy_string(buf, value, buf_len);
00783       return 0;
00784    }
00785 
00786    /* The rest of these are all ints of some sort and require some
00787     * snprintf-itude
00788     */
00789 
00790    if (!strcasecmp(name, "cc_offer_timer")) {
00791       snprintf(buf, buf_len, "%u", ast_get_cc_offer_timer(params));
00792    } else if (!strcasecmp(name, "ccnr_available_timer")) {
00793       snprintf(buf, buf_len, "%u", ast_get_ccnr_available_timer(params));
00794    } else if (!strcasecmp(name, "ccbs_available_timer")) {
00795       snprintf(buf, buf_len, "%u", ast_get_ccbs_available_timer(params));
00796    } else if (!strcasecmp(name, "cc_max_agents")) {
00797       snprintf(buf, buf_len, "%u", ast_get_cc_max_agents(params));
00798    } else if (!strcasecmp(name, "cc_max_monitors")) {
00799       snprintf(buf, buf_len, "%u", ast_get_cc_max_monitors(params));
00800    } else if (!strcasecmp(name, "cc_recall_timer")) {
00801       snprintf(buf, buf_len, "%u", ast_get_cc_recall_timer(params));
00802    } else {
00803       ast_log(LOG_WARNING, "%s is not a valid CC parameter. Ignoring.\n", name);
00804       return -1;
00805    }
00806 
00807    return 0;
00808 }

int ast_cc_init ( void   ) 

Initialize CCSS.

Since:
1.8 Performs startup routines necessary for CC operation.
Return values:
0 Success
nonzero Failure

Definition at line 4654 of file ccss.c.

References ao2_t_container_alloc, ARRAY_LEN, ast_cc_agent_register(), ast_cc_monitor_register(), ast_cli_register_multiple(), ast_devstate_prov_add(), ast_logger_register_level(), ast_register_application2(), ast_register_cleanup(), ast_sched_context_create(), ast_sched_start_thread(), ast_taskprocessor_get(), cc_core_instance_cmp_fn(), cc_core_instance_hash_fn(), cc_shutdown(), cccancel_exec(), ccreq_exec(), ccss_device_state(), generic_monitor_cbs, generic_monitor_cmp_fn(), generic_monitor_hash_fn(), generic_monitors, initialize_cc_devstate_map(), initialize_cc_max_requests(), NULL, and TPS_REF_DEFAULT.

Referenced by main().

04655 {
04656    int res;
04657 
04658    if (!(cc_core_instances = ao2_t_container_alloc(CC_CORE_INSTANCES_BUCKETS,
04659                cc_core_instance_hash_fn, cc_core_instance_cmp_fn,
04660                "Create core instance container"))) {
04661       return -1;
04662    }
04663    if (!(generic_monitors = ao2_t_container_alloc(CC_CORE_INSTANCES_BUCKETS,
04664                generic_monitor_hash_fn, generic_monitor_cmp_fn,
04665                "Create generic monitor container"))) {
04666       return -1;
04667    }
04668    if (!(cc_core_taskprocessor = ast_taskprocessor_get("CCSS core", TPS_REF_DEFAULT))) {
04669       return -1;
04670    }
04671    if (!(cc_sched_context = ast_sched_context_create())) {
04672       return -1;
04673    }
04674    if (ast_sched_start_thread(cc_sched_context)) {
04675       return -1;
04676    }
04677    res = ast_register_application2(ccreq_app, ccreq_exec, NULL, NULL, NULL);
04678    res |= ast_register_application2(cccancel_app, cccancel_exec, NULL, NULL, NULL);
04679    res |= ast_cc_monitor_register(&generic_monitor_cbs);
04680    res |= ast_cc_agent_register(&generic_agent_callbacks);
04681 
04682    ast_cli_register_multiple(cc_cli, ARRAY_LEN(cc_cli));
04683    cc_logger_level = ast_logger_register_level(CC_LOGGER_LEVEL_NAME);
04684    dialed_cc_interface_counter = 1;
04685    initialize_cc_max_requests();
04686 
04687    /* Read the map and register the device state callback for generic agents */
04688    initialize_cc_devstate_map();
04689    res |= ast_devstate_prov_add("ccss", ccss_device_state);
04690 
04691    ast_register_cleanup(cc_shutdown);
04692 
04693    return res;
04694 }

int ast_cc_is_config_param ( const char *const   name  ) 

Is this a CCSS configuration parameter?

Since:
1.8
Parameters:
name Name of configuration option being parsed.
Return values:
1 Yes, this is a CCSS configuration parameter.
0 No, this is not a CCSS configuration parameter.

Definition at line 852 of file ccss.c.

Referenced by build_peer(), and process_dahdi().

00853 {
00854    return (!strcasecmp(name, "cc_agent_policy") ||
00855             !strcasecmp(name, "cc_monitor_policy") ||
00856             !strcasecmp(name, "cc_offer_timer") ||
00857             !strcasecmp(name, "ccnr_available_timer") ||
00858             !strcasecmp(name, "ccbs_available_timer") ||
00859             !strcasecmp(name, "cc_max_agents") ||
00860             !strcasecmp(name, "cc_max_monitors") ||
00861             !strcasecmp(name, "cc_callback_macro") ||
00862             !strcasecmp(name, "cc_callback_sub") ||
00863             !strcasecmp(name, "cc_agent_dialstring") ||
00864             !strcasecmp(name, "cc_recall_timer"));
00865 }

int ast_cc_is_recall ( struct ast_channel chan,
int *  core_id,
const char *const   monitor_type 
)

Decide if a call to a particular channel is a CC recall.

Since:
1.8
When a CC recall happens, it is important on the called side to know that the call is a CC recall and not a normal call. This function will determine first if the call in question is a CC recall. Then it will determine based on the chan parameter if the channel is being called is being recalled.

As a quick example, let's say a call is placed to SIP/1000 and SIP/1000 is currently on the phone. The caller requests CCBS. SIP/1000 finishes his call, and so the caller attempts to recall. Now, the dialplan administrator has set up this second call so that not only is SIP/1000 called, but also SIP/2000 is called. If SIP/1000's channel were passed to this function, the return value would be non-zero, but if SIP/2000's channel were passed into this function, then the return would be 0 since SIP/2000 was not one of the original devices dialed.

Note:
This function may be called on a calling channel as well to determine if it is part of a CC recall.

This function will lock the channel as well as the list of monitors on the channel datastore, though the locks are not held at the same time. Be sure that you have no potential lock order issues here.

Parameters:
chan The channel to check
[out] core_id If this is a valid CC recall, the core_id of the failed call will be placed in this output parameter
monitor_type Clarify which type of monitor type we are looking for if this is happening on a called channel. For incoming channels, this parameter is not used.
Return values:
0 Either this is not a recall or it is but this channel is not part of the recall
non-zero This is a recall and the channel in question is directly involved.

Definition at line 3435 of file ccss.c.

References ast_assert, ast_channel_datastore_find(), ast_channel_get_device_name(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_unlock, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strlen_zero, cc_recall_ds_data::core_id, ast_datastore::data, ast_cc_interface::device_name, cc_recall_ds_data::ignore, ast_cc_monitor::interface, cc_recall_ds_data::interface_tree, ast_cc_interface::monitor_type, cc_recall_ds_data::nested, and NULL.

Referenced by cc_core_init_instance(), sip_call(), and wait_for_answer().

03436 {
03437    struct ast_datastore *recall_datastore;
03438    struct cc_recall_ds_data *recall_data;
03439    struct cc_monitor_tree *interface_tree;
03440    char device_name[AST_CHANNEL_NAME];
03441    struct ast_cc_monitor *device_monitor;
03442    int core_id_candidate;
03443 
03444    ast_assert(core_id != NULL);
03445 
03446    *core_id = -1;
03447 
03448    ast_channel_lock(chan);
03449    if (!(recall_datastore = ast_channel_datastore_find(chan, &recall_ds_info, NULL))) {
03450       /* Obviously not a recall if the datastore isn't present */
03451       ast_channel_unlock(chan);
03452       return 0;
03453    }
03454 
03455    recall_data = recall_datastore->data;
03456 
03457    if (recall_data->ignore) {
03458       /* Though this is a recall, the call to this particular interface is not part of the
03459        * recall either because this is a call forward or because this is not the first
03460        * invocation of Dial during this call
03461        */
03462       ast_channel_unlock(chan);
03463       return 0;
03464    }
03465 
03466    if (!recall_data->nested) {
03467       /* If the nested flag is not set, then this means that
03468        * the channel passed to this function is the caller making
03469        * the recall. This means that we shouldn't look through
03470        * the monitor tree for the channel because it shouldn't be
03471        * there. However, this is a recall though, so return true.
03472        */
03473       *core_id = recall_data->core_id;
03474       ast_channel_unlock(chan);
03475       return 1;
03476    }
03477 
03478    if (ast_strlen_zero(monitor_type)) {
03479       /* If someone passed a NULL or empty monitor type, then it is clear
03480        * the channel they passed in was an incoming channel, and so searching
03481        * the list of dialed interfaces is not going to be helpful. Just return
03482        * false immediately.
03483        */
03484       ast_channel_unlock(chan);
03485       return 0;
03486    }
03487 
03488    interface_tree = recall_data->interface_tree;
03489    ast_channel_get_device_name(chan, device_name, sizeof(device_name));
03490    /* We grab the value of the recall_data->core_id so that we
03491     * can unlock the channel before we start looking through the
03492     * interface list. That way we don't have to worry about a possible
03493     * clash between the channel lock and the monitor tree lock.
03494     */
03495    core_id_candidate = recall_data->core_id;
03496    ast_channel_unlock(chan);
03497 
03498    /*
03499     * Now we need to find out if the channel device name
03500     * is in the list of interfaces in the called tree.
03501     */
03502    AST_LIST_LOCK(interface_tree);
03503    AST_LIST_TRAVERSE(interface_tree, device_monitor, next) {
03504       if (!strcmp(device_monitor->interface->device_name, device_name) &&
03505             !strcmp(device_monitor->interface->monitor_type, monitor_type)) {
03506          /* BOOM! Device is in the tree! We have a winner! */
03507          *core_id = core_id_candidate;
03508          AST_LIST_UNLOCK(interface_tree);
03509          return 1;
03510       }
03511    }
03512    AST_LIST_UNLOCK(interface_tree);
03513    return 0;
03514 }

int ast_cc_monitor_callee_available ( const int  core_id,
const char *const   debug,
  ... 
)

Alert the core that a device being monitored has become available.

Since:
1.8
Note:
The code in the core will take care of making sure that the information gets passed up the ladder correctly.
core_id The core ID of the corresponding CC transaction
debug
Return values:
0 Request successfully queued
-1 Request could not be queued

Definition at line 3795 of file ccss.c.

References CC_CALLEE_READY, and cc_request_state_change().

Referenced by cc_generic_monitor_destructor(), cc_generic_monitor_suspend(), cc_generic_monitor_unsuspend(), generic_monitor_devstate_tp_cb(), and handle_cc_notify().

03796 {
03797    va_list ap;
03798    int res;
03799 
03800    va_start(ap, debug);
03801    res = cc_request_state_change(CC_CALLEE_READY, core_id, debug, ap);
03802    va_end(ap);
03803    return res;
03804 }

int ast_cc_monitor_count ( const char *const   name,
const char *const   type 
)

Return the number of outstanding CC requests to a specific device.

Since:
1.8
Note:
This function will lock the list of monitors stored on every instance of the CC core. Callers of this function should be aware of this and avoid any potential lock ordering problems.
Parameters:
name The name of the monitored device
type The type of the monitored device (e.g. "generic")
Returns:
The number of CC requests for the monitor

Definition at line 4365 of file ccss.c.

References ao2_t_callback, ast_log_dynamic_level, count_monitors_cb_data::count, count_monitors_cb(), count_monitors_cb_data::device_name, and OBJ_NODATA.

Referenced by ast_queue_cc_frame().

04366 {
04367    struct count_monitors_cb_data data = {.device_name = name, .monitor_type = type,};
04368 
04369    ao2_t_callback(cc_core_instances, OBJ_NODATA, count_monitors_cb, &data, "Counting agents");
04370    ast_log_dynamic_level(cc_logger_level, "Counted %d monitors\n", data.count);
04371    return data.count;
04372 }

int ast_cc_monitor_failed ( int  core_id,
const char *const   monitor_name,
const char *const   debug,
  ... 
)

Indicate that a failure has occurred on a specific monitor.

Since:
1.8
If a monitor should detect that a failure has occurred when communicating with its endpoint, then ast_cc_monitor_failed should be called. The big difference between ast_cc_monitor_failed and ast_cc_failed is that ast_cc_failed indicates a global failure for a CC transaction, where as ast_cc_monitor_failed is localized to a particular monitor. When ast_cc_failed is called, the entire CC transaction is torn down. When ast_cc_monitor_failed is called, only the monitor on which the failure occurred is pruned from the tree of monitors.

If there are no more devices left to monitor when this function is called, then the core will fail the CC transaction globally.

Parameters:
core_id The core ID for the CC transaction
monitor_name The name of the monitor on which the failure occurred
debug A debug message to print to the CC log
Returns:
void

Definition at line 3938 of file ccss.c.

References ast_calloc, ast_free, ast_strdup, ast_taskprocessor_push(), ast_vasprintf, cc_monitor_failed(), ast_cc_monitor_failure_data::core_id, ast_cc_monitor_failure_data::debug, and ast_cc_monitor_failure_data::device_name.

Referenced by ast_cc_available_timer_expire(), cc_handle_publish_error(), and handle_response_subscribe().

03939 {
03940    struct ast_cc_monitor_failure_data *failure_data;
03941    int res;
03942    va_list ap;
03943 
03944    if (!(failure_data = ast_calloc(1, sizeof(*failure_data)))) {
03945       return -1;
03946    }
03947 
03948    if (!(failure_data->device_name = ast_strdup(monitor_name))) {
03949       ast_free(failure_data);
03950       return -1;
03951    }
03952 
03953    va_start(ap, debug);
03954    if (ast_vasprintf(&failure_data->debug, debug, ap) == -1) {
03955       va_end(ap);
03956       ast_free((char *)failure_data->device_name);
03957       ast_free(failure_data);
03958       return -1;
03959    }
03960    va_end(ap);
03961 
03962    failure_data->core_id = core_id;
03963 
03964    res = ast_taskprocessor_push(cc_core_taskprocessor, cc_monitor_failed, failure_data);
03965    if (res) {
03966       ast_free((char *)failure_data->device_name);
03967       ast_free((char *)failure_data->debug);
03968       ast_free(failure_data);
03969    }
03970    return res;
03971 }

int ast_cc_monitor_party_b_free ( int  core_id  ) 

Alert a caller that though the callee has become free, the caller himself is not and may not call back.

When an ISDN PTMP monitor senses that his monitored party has become available, he will request the status of the called party. If he determines that the caller is currently not available, then he will call this function so that an appropriate message is sent to the caller.

Yes, you just read that correctly. The callee asks the caller what his current status is, and if the caller is currently unavailable, the monitor must send him a message anyway. WTF?

This function results in the agent's party_b_free callback being called. It is most likely that you will not need to actually implement the party_b_free callback in an agent because it is not likely that you will need to or even want to send a caller a message indicating the callee's status if the caller himself is not also free.

Parameters:
core_id The core ID of the CC transaction
Return values:
0 Successfully alerted the core that party B is free
-1 Could not alert the core that party B is free

Definition at line 4048 of file ccss.c.

References ast_taskprocessor_push(), cc_party_b_free(), cc_unref(), and find_cc_core_instance().

04049 {
04050    int res;
04051    struct cc_core_instance *core_instance = find_cc_core_instance(core_id);
04052 
04053    if (!core_instance) {
04054       return -1;
04055    }
04056 
04057    res = ast_taskprocessor_push(cc_core_taskprocessor, cc_party_b_free, core_instance);
04058    if (res) {
04059       cc_unref(core_instance, "Unref core instance. ast_taskprocessor_push failed");
04060    }
04061    return res;
04062 }

int ast_cc_monitor_register ( const struct ast_cc_monitor_callbacks callbacks  ) 

Register a set of monitor callbacks with the core.

Since:
1.8
This is made so that at monitor creation time, the proper callbacks may be installed and the proper .init callback may be called for the monitor to establish private data.

Parameters:
callbacks The callbacks used by the monitor implementation
Return values:
0 Successfully registered
-1 Failure to register

Definition at line 1173 of file ccss.c.

References ast_calloc, AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and cc_monitor_backend::callbacks.

Referenced by ast_cc_init(), and load_module().

01174 {
01175    struct cc_monitor_backend *backend = ast_calloc(1, sizeof(*backend));
01176 
01177    if (!backend) {
01178       return -1;
01179    }
01180 
01181    backend->callbacks = callbacks;
01182 
01183    AST_RWLIST_WRLOCK(&cc_monitor_backends);
01184    AST_RWLIST_INSERT_TAIL(&cc_monitor_backends, backend, next);
01185    AST_RWLIST_UNLOCK(&cc_monitor_backends);
01186    return 0;
01187 }

int ast_cc_monitor_request_acked ( int  core_id,
const char *const   debug,
  ... 
)

Indicate that an outbound entity has accepted our CC request.

Since:
1.8
When we receive confirmation that an outbound device has accepted the CC request we sent it, this function must be called.

Parameters:
core_id core_id of the CC transaction
debug optional string to print for debugging purposes
Return values:
0 Success
-1 Failure

Definition at line 3784 of file ccss.c.

References CC_ACTIVE, and cc_request_state_change().

Referenced by cc_generic_monitor_request_cc(), cc_stop_ringing(), and handle_cc_notify().

03785 {
03786    va_list ap;
03787    int res;
03788 
03789    va_start(ap, debug);
03790    res = cc_request_state_change(CC_ACTIVE, core_id, debug, ap);
03791    va_end(ap);
03792    return res;
03793 }

int ast_cc_monitor_status_request ( int  core_id  ) 

Request the status of a caller or callers.

The following are all functions which are required due to the unique case where Asterisk is acting as the NT side of an ISDN PTMP connection to the caller and as the TE side of an ISDN PTMP connection to the callee. In such a case, there are several times where the PTMP monitor needs information from the agent in order to formulate the appropriate messages to send.

When an ISDN PTMP monitor senses that the callee has become available, it needs to know the current status of the caller in order to determine the appropriate response to send to the caller. In order to do this, the monitor calls this function. Responses will arrive asynchronously.

Note:
Zero or more responses may come as a result.
Parameters:
core_id The core ID of the CC transaction
Return values:
0 Successfully requested status
-1 Failed to request status

Definition at line 3983 of file ccss.c.

References ast_taskprocessor_push(), cc_status_request(), cc_unref(), and find_cc_core_instance().

03984 {
03985    int res;
03986    struct cc_core_instance *core_instance = find_cc_core_instance(core_id);
03987 
03988    if (!core_instance) {
03989       return -1;
03990    }
03991 
03992    res = ast_taskprocessor_push(cc_core_taskprocessor, cc_status_request, core_instance);
03993    if (res) {
03994       cc_unref(core_instance, "Unref core instance. ast_taskprocessor_push failed");
03995    }
03996    return res;
03997 }

int ast_cc_monitor_stop_ringing ( int  core_id  ) 

Alert a caller to stop ringing.

When an ISDN PTMP monitor becomes available, it is assumed that the agent will then cause the caller's phone to ring. In some cases, this is literally what happens. In other cases, it may be that the caller gets a visible indication on his phone that he may attempt to recall the callee. If multiple callers are recalled (since it may be possible to have a group of callers configured as a single party A), and one of those callers picks up his phone, then the ISDN PTMP monitor will alert the other callers to stop ringing. The agent's stop_ringing callback will be called, and it is up to the agent's driver to send an appropriate message to make his caller stop ringing.

Parameters:
core_id The core ID of the CC transaction
Return values:
0 Successfully requested for the phone to stop ringing
-1 Could not request for the phone to stop ringing

Definition at line 4020 of file ccss.c.

References ast_taskprocessor_push(), cc_stop_ringing(), cc_unref(), and find_cc_core_instance().

04021 {
04022    int res;
04023    struct cc_core_instance *core_instance = find_cc_core_instance(core_id);
04024 
04025    if (!core_instance) {
04026       return -1;
04027    }
04028 
04029    res = ast_taskprocessor_push(cc_core_taskprocessor, cc_stop_ringing, core_instance);
04030    if (res) {
04031       cc_unref(core_instance, "Unref core instance. ast_taskprocessor_push failed");
04032    }
04033    return res;
04034 }

void ast_cc_monitor_unregister ( const struct ast_cc_monitor_callbacks callbacks  ) 

Unregister a set of monitor callbacks with the core.

Since:
1.8
If a module which makes use of a CC monitor is unloaded, then it may unregister its monitor callbacks with the core.

Parameters:
callbacks The callbacks used by the monitor implementation
Return values:
0 Successfully unregistered
-1 Failure to unregister

Definition at line 1206 of file ccss.c.

References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, cc_monitor_backend::callbacks, and cc_monitor_backend::next.

Referenced by __unload_module(), cc_shutdown(), and unload_module().

01207 {
01208    struct cc_monitor_backend *backend;
01209    AST_RWLIST_WRLOCK(&cc_monitor_backends);
01210    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&cc_monitor_backends, backend, next) {
01211       if (backend->callbacks == callbacks) {
01212          AST_RWLIST_REMOVE_CURRENT(next);
01213          ast_free(backend);
01214          break;
01215       }
01216    }
01217    AST_RWLIST_TRAVERSE_SAFE_END;
01218    AST_RWLIST_UNLOCK(&cc_monitor_backends);
01219 }

int ast_cc_offer ( struct ast_channel caller_chan  ) 

Offer CC to a caller.

Since:
1.8
This function is called from ast_hangup if the caller is eligible to be offered call completion service.

Parameters:
caller_chan The calling channel
Return values:
-1 Error
0 Success

Definition at line 3748 of file ccss.c.

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, cc_offer(), dialed_cc_interfaces::core_id, cc_recall_ds_data::core_id, ast_datastore::data, dialed_cc_interfaces::is_original_caller, and NULL.

Referenced by ast_hangup().

03749 {
03750    int core_id;
03751    int res = -1;
03752    struct ast_datastore *datastore;
03753    struct dialed_cc_interfaces *cc_interfaces;
03754    char cc_is_offerable;
03755 
03756    ast_channel_lock(caller_chan);
03757    if (!(datastore = ast_channel_datastore_find(caller_chan, &dialed_cc_interfaces_info, NULL))) {
03758       ast_channel_unlock(caller_chan);
03759       return res;
03760    }
03761 
03762    cc_interfaces = datastore->data;
03763    cc_is_offerable = cc_interfaces->is_original_caller;
03764    core_id = cc_interfaces->core_id;
03765    ast_channel_unlock(caller_chan);
03766 
03767    if (cc_is_offerable) {
03768       res = cc_offer(core_id, "CC offered to caller %s", ast_channel_name(caller_chan));
03769    }
03770    return res;
03771 }

int ast_cc_request_is_within_limits ( void   ) 

Check if the incoming CC request is within the bounds set by the cc_max_requests configuration option.

Since:
1.8
It is recommended that an entity which receives an incoming CC request calls this function before calling ast_cc_agent_accept_request. This way, immediate feedback can be given to the caller about why his request was rejected.

If this is not called and a state change to CC_CALLER_REQUESTED is made, then the core will still not allow for the request to succeed. However, if done this way, it may not be obvious to the requestor why the request failed.

Return values:
0 Not within the limits. Fail.
non-zero Within the limits. Success.

Definition at line 2482 of file ccss.c.

Referenced by cc_caller_requested(), cc_interfaces_datastore_init(), and ccreq_exec().

02483 {
02484    return cc_request_count < global_cc_max_requests;
02485 }

int ast_cc_set_param ( struct ast_cc_config_params params,
const char *const   name,
const char *  value 
)

set a CCSS configuration parameter, given its name

Note:
Useful when parsing config files when used in conjunction with ast_ccss_is_cc_config_param.
Parameters:
params The parameter structure to set the value on
name The name of the cc parameter
value The value of the parameter
Return values:
0 Success
-1 Failure

Definition at line 810 of file ccss.c.

References ast_log, ast_set_cc_agent_dialstring(), ast_set_cc_agent_policy(), ast_set_cc_callback_macro(), ast_set_cc_callback_sub(), ast_set_cc_max_agents(), ast_set_cc_max_monitors(), ast_set_cc_monitor_policy(), ast_set_cc_offer_timer(), ast_set_cc_recall_timer(), ast_set_ccbs_available_timer(), ast_set_ccnr_available_timer(), LOG_WARNING, str_to_agent_policy(), and str_to_monitor_policy().

Referenced by acf_cc_write(), build_peer(), and process_dahdi().

00812 {
00813    unsigned int value_as_uint;
00814    if (!strcasecmp(name, "cc_agent_policy")) {
00815       return ast_set_cc_agent_policy(params, str_to_agent_policy(value));
00816    } else if (!strcasecmp(name, "cc_monitor_policy")) {
00817       return ast_set_cc_monitor_policy(params, str_to_monitor_policy(value));
00818    } else if (!strcasecmp(name, "cc_agent_dialstring")) {
00819       ast_set_cc_agent_dialstring(params, value);
00820    } else if (!strcasecmp(name, "cc_callback_macro")) {
00821       ast_set_cc_callback_macro(params, value);
00822       return 0;
00823    } else if (!strcasecmp(name, "cc_callback_sub")) {
00824       ast_set_cc_callback_sub(params, value);
00825       return 0;
00826    }
00827 
00828    if (sscanf(value, "%30u", &value_as_uint) != 1) {
00829       return -1;
00830    }
00831 
00832    if (!strcasecmp(name, "cc_offer_timer")) {
00833       ast_set_cc_offer_timer(params, value_as_uint);
00834    } else if (!strcasecmp(name, "ccnr_available_timer")) {
00835       ast_set_ccnr_available_timer(params, value_as_uint);
00836    } else if (!strcasecmp(name, "ccbs_available_timer")) {
00837       ast_set_ccbs_available_timer(params, value_as_uint);
00838    } else if (!strcasecmp(name, "cc_max_agents")) {
00839       ast_set_cc_max_agents(params, value_as_uint);
00840    } else if (!strcasecmp(name, "cc_max_monitors")) {
00841       ast_set_cc_max_monitors(params, value_as_uint);
00842    } else if (!strcasecmp(name, "cc_recall_timer")) {
00843       ast_set_cc_recall_timer(params, value_as_uint);
00844    } else {
00845       ast_log(LOG_WARNING, "%s is not a valid CC parameter. Ignoring.\n", name);
00846       return -1;
00847    }
00848 
00849    return 0;
00850 }

const char* ast_get_cc_agent_dialstring ( struct ast_cc_config_params config  ) 

Get the cc_agent_dialstring.

Since:
1.8
Parameters:
config The configuration to retrieve the cc_agent_dialstring from
Returns:
The cc_agent_dialstring from this configuration

Definition at line 966 of file ccss.c.

References ast_cc_config_params::cc_agent_dialstring.

Referenced by ast_cc_get_param(), and generic_recall().

00967 {
00968    return config->cc_agent_dialstring;
00969 }

enum ast_cc_agent_policies ast_get_cc_agent_policy ( struct ast_cc_config_params config  ) 

Get the cc_agent_policy.

Since:
1.8
Parameters:
config The configuration to retrieve the policy from
Returns:
The current cc_agent_policy for this configuration

Definition at line 872 of file ccss.c.

References ast_cc_config_params::cc_agent_policy.

Referenced by ast_cc_call_init(), ast_cc_get_param(), build_peer(), cc_core_init_instance(), and find_agent_callbacks().

00873 {
00874    return config->cc_agent_policy;
00875 }

const char* ast_get_cc_callback_macro ( struct ast_cc_config_params config  ) 

Get the name of the callback_macro.

Since:
1.8
Parameters:
config The configuration to retrieve the callback_macro from
Returns:
The callback_macro name

Definition at line 1000 of file ccss.c.

References ast_cc_config_params::cc_callback_macro.

Referenced by ast_cc_get_param(), and generic_recall().

01001 {
01002    return config->cc_callback_macro;
01003 }

const char* ast_get_cc_callback_sub ( struct ast_cc_config_params config  ) 

Get the name of the callback subroutine.

Since:
11
Parameters:
config The configuration to retrieve the callback_sub from
Returns:
The callback_sub name

Definition at line 1005 of file ccss.c.

References ast_cc_config_params::cc_callback_sub.

Referenced by ast_cc_get_param(), and generic_recall().

01006 {
01007    return config->cc_callback_sub;
01008 }

unsigned int ast_get_cc_max_agents ( struct ast_cc_config_params config  ) 

Get the cc_max_agents.

Since:
1.8
Parameters:
config The configuration to retrieve the cc_max_agents from
Returns:
The cc_max_agents from this configuration

Definition at line 980 of file ccss.c.

References ast_cc_config_params::cc_max_agents.

Referenced by ast_cc_get_param(), and cc_core_init_instance().

00981 {
00982    return config->cc_max_agents;
00983 }

unsigned int ast_get_cc_max_monitors ( struct ast_cc_config_params config  ) 

Get the cc_max_monitors.

Since:
1.8
Parameters:
config The configuration to retrieve the cc_max_monitors from
Returns:
The cc_max_monitors from this configuration

Definition at line 990 of file ccss.c.

References ast_cc_config_params::cc_max_monitors.

Referenced by ast_cc_get_param(), and ast_queue_cc_frame().

00991 {
00992    return config->cc_max_monitors;
00993 }

enum ast_cc_monitor_policies ast_get_cc_monitor_policy ( struct ast_cc_config_params config  ) 

Get the cc_monitor_policy.

Since:
1.8
Parameters:
config The configuration to retrieve the cc_monitor_policy from
Returns:
The cc_monitor_policy retrieved from the configuration

Definition at line 889 of file ccss.c.

References ast_cc_config_params::cc_monitor_policy.

Referenced by analog_call(), ast_cc_call_failed(), ast_cc_get_param(), dahdi_cc_callback(), and sip_handle_cc().

00890 {
00891    return config->cc_monitor_policy;
00892 }

unsigned int ast_get_cc_offer_timer ( struct ast_cc_config_params config  ) 

Get the cc_offer_timer.

Since:
1.8
Parameters:
config The configuration to retrieve the cc_offer_timer from
Returns:
The cc_offer_timer from this configuration

Definition at line 906 of file ccss.c.

References ast_cc_config_params::cc_offer_timer.

Referenced by ast_cc_get_param(), cc_generic_agent_start_offer_timer(), and sip_cc_agent_start_offer_timer().

00907 {
00908    return config->cc_offer_timer;
00909 }

unsigned int ast_get_cc_recall_timer ( struct ast_cc_config_params config  ) 

Get the cc_recall_timer.

Since:
1.8
Parameters:
config The configuration to retrieve the cc_recall_timer from
Returns:
The cc_recall_timer from this configuration

Definition at line 936 of file ccss.c.

References ast_cc_config_params::cc_recall_timer.

Referenced by ast_cc_get_param(), and generic_recall().

00937 {
00938    return config->cc_recall_timer;
00939 }

unsigned int ast_get_ccbs_available_timer ( struct ast_cc_config_params config  ) 

Get the ccbs_available_timer.

Since:
1.8
Parameters:
config The configuration to retrieve the ccbs_available_timer from
Returns:
The ccbs_available_timer from this configuration

Definition at line 951 of file ccss.c.

References ast_cc_config_params::ccbs_available_timer.

Referenced by ast_cc_get_param(), cc_generic_monitor_request_cc(), and sip_cc_monitor_request_cc().

00952 {
00953    return config->ccbs_available_timer;
00954 }

unsigned int ast_get_ccnr_available_timer ( struct ast_cc_config_params config  ) 

Get the ccnr_available_timer.

Since:
1.8
Parameters:
config The configuration to retrieve the ccnr_available_timer from
Returns:
The ccnr_available_timer from this configuration

Definition at line 921 of file ccss.c.

References ast_cc_config_params::ccnr_available_timer.

Referenced by ast_cc_get_param(), cc_generic_monitor_request_cc(), and sip_cc_monitor_request_cc().

00922 {
00923    return config->ccnr_available_timer;
00924 }

void ast_handle_cc_control_frame ( struct ast_channel inbound,
struct ast_channel outbound,
void *  frame_data 
)

Properly react to a CC control frame.

Since:
1.8
When a CC-capable application, such as Dial, receives a frame of type AST_CONTROL_CC, then it may call this function in order to have the device which sent the frame added to the tree of interfaces which is kept on the inbound channel.

Parameters:
inbound The inbound channel
outbound The outbound channel (The one from which the CC frame was read)
frame_data The ast_frame's data.ptr field.
Return values:
void Unless we are ignoring CC for some reason, we will always call this function when we read an AST_CONTROL_CC frame from an outbound channel.
This function will call cc_device_monitor_init to create the new cc_monitor for the device from which we read the frame. In addition, the new device will be added to the monitor tree on the dialed_cc_interfaces datastore on the inbound channel.

If this is the first AST_CONTROL_CC frame that we have handled for this call, then we will also initialize the CC core for this call.

Definition at line 2316 of file ccss.c.

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, AST_CONTROL_CC, ast_indicate_data(), AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log, ast_log_dynamic_level, call_destructor_with_no_monitor(), cc_core_init_instance(), cc_device_monitor_init(), cc_extension_monitor_change_is_valid(), cc_publish_available(), cc_ref(), cc_service_to_string(), cc_unref(), cc_core_instance::core_id, dialed_cc_interfaces::core_id, ast_datastore::data, ast_cc_interface::device_name, cc_control_payload::device_name, cc_control_payload::dialstring, ast_cc_monitor::dialstring, find_cc_core_instance(), dialed_cc_interfaces::ignore, ast_cc_monitor::interface, dialed_cc_interfaces::interface_tree, dialed_cc_interfaces::is_original_caller, LOG_WARNING, monitor, cc_control_payload::monitor_type, NULL, ast_cc_monitor::parent_id, cc_control_payload::private_data, and cc_control_payload::service.

Referenced by ast_cc_busy_interface(), ast_cc_call_failed(), and wait_for_answer().

02317 {
02318    char *device_name;
02319    char *dialstring;
02320    struct ast_cc_monitor *monitor;
02321    struct ast_datastore *cc_datastore;
02322    struct dialed_cc_interfaces *cc_interfaces;
02323    struct cc_control_payload *cc_data = frame_data;
02324    struct cc_core_instance *core_instance;
02325 
02326    device_name = cc_data->device_name;
02327    dialstring = cc_data->dialstring;
02328 
02329    ast_channel_lock(inbound);
02330    if (!(cc_datastore = ast_channel_datastore_find(inbound, &dialed_cc_interfaces_info, NULL))) {
02331       ast_log(LOG_WARNING, "Unable to retrieve CC datastore while processing CC frame from '%s'. CC services will be unavailable.\n", device_name);
02332       ast_channel_unlock(inbound);
02333       call_destructor_with_no_monitor(cc_data->monitor_type, cc_data->private_data);
02334       return;
02335    }
02336 
02337    cc_interfaces = cc_datastore->data;
02338 
02339    if (cc_interfaces->ignore) {
02340       ast_channel_unlock(inbound);
02341       call_destructor_with_no_monitor(cc_data->monitor_type, cc_data->private_data);
02342       return;
02343    }
02344 
02345    if (!cc_interfaces->is_original_caller) {
02346       /* If the is_original_caller is not set on the *inbound* channel, then
02347        * it must be a local channel. As such, we do not want to create a core instance
02348        * or an agent for the local channel. Instead, we want to pass this along to the
02349        * other side of the local channel so that the original caller can benefit.
02350        */
02351       ast_channel_unlock(inbound);
02352       ast_indicate_data(inbound, AST_CONTROL_CC, cc_data, sizeof(*cc_data));
02353       return;
02354    }
02355 
02356    core_instance = find_cc_core_instance(cc_interfaces->core_id);
02357    if (!core_instance) {
02358       core_instance = cc_core_init_instance(inbound, cc_interfaces->interface_tree,
02359          cc_interfaces->core_id, cc_data);
02360       if (!core_instance) {
02361          cc_interfaces->ignore = 1;
02362          ast_channel_unlock(inbound);
02363          call_destructor_with_no_monitor(cc_data->monitor_type, cc_data->private_data);
02364          return;
02365       }
02366    }
02367 
02368    ast_channel_unlock(inbound);
02369 
02370    /* Yeah this kind of sucks, but luckily most people
02371     * aren't dialing thousands of interfaces on every call
02372     *
02373     * This traversal helps us to not create duplicate monitors in
02374     * case a device queues multiple CC control frames.
02375     */
02376    AST_LIST_LOCK(cc_interfaces->interface_tree);
02377    AST_LIST_TRAVERSE(cc_interfaces->interface_tree, monitor, next) {
02378       if (!strcmp(monitor->interface->device_name, device_name)) {
02379          ast_log_dynamic_level(cc_logger_level, "Core %d: Device %s sent us multiple CC control frames. Ignoring those beyond the first.\n",
02380                core_instance->core_id, device_name);
02381          AST_LIST_UNLOCK(cc_interfaces->interface_tree);
02382          cc_unref(core_instance, "Returning early from ast_handle_cc_control_frame. Unref core_instance");
02383          call_destructor_with_no_monitor(cc_data->monitor_type, cc_data->private_data);
02384          return;
02385       }
02386    }
02387    AST_LIST_UNLOCK(cc_interfaces->interface_tree);
02388 
02389    if (!(monitor = cc_device_monitor_init(device_name, dialstring, cc_data, core_instance->core_id))) {
02390       ast_log(LOG_WARNING, "Unable to create CC device interface for '%s'. CC services will be unavailable on this interface.\n", device_name);
02391       cc_unref(core_instance, "Returning early from ast_handle_cc_control_frame. Unref core_instance");
02392       call_destructor_with_no_monitor(cc_data->monitor_type, cc_data->private_data);
02393       return;
02394    }
02395 
02396    AST_LIST_LOCK(cc_interfaces->interface_tree);
02397    cc_ref(monitor, "monitor tree's reference to the monitor");
02398    AST_LIST_INSERT_TAIL(cc_interfaces->interface_tree, monitor, next);
02399    AST_LIST_UNLOCK(cc_interfaces->interface_tree);
02400 
02401    cc_extension_monitor_change_is_valid(core_instance, monitor->parent_id, monitor->interface->device_name, 0);
02402 
02403    cc_publish_available(cc_interfaces->core_id, device_name, cc_service_to_string(cc_data->service));
02404 
02405    cc_unref(core_instance, "Done with core_instance after handling CC control frame");
02406    cc_unref(monitor, "Unref reference from allocating monitor");
02407 }

void ast_ignore_cc ( struct ast_channel chan  ) 

Mark the channel to ignore further CC activity.

Since:
1.8
When a CC-capable application, such as Dial, has finished with all CC processing for a channel and knows that any further CC processing should be ignored, this function should be called.

Parameters:
chan The channel for which further CC processing should be ignored.
Return values:
void 

Definition at line 3717 of file ccss.c.

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_datastore::data, cc_recall_ds_data::ignore, dialed_cc_interfaces::ignore, and NULL.

Referenced by dial_exec_full(), and do_forward().

03718 {
03719    struct ast_datastore *cc_datastore;
03720    struct ast_datastore *cc_recall_datastore;
03721    struct dialed_cc_interfaces *cc_interfaces;
03722    struct cc_recall_ds_data *recall_cc_data;
03723 
03724    ast_channel_lock(chan);
03725    if ((cc_datastore = ast_channel_datastore_find(chan, &dialed_cc_interfaces_info, NULL))) {
03726       cc_interfaces = cc_datastore->data;
03727       cc_interfaces->ignore = 1;
03728    }
03729 
03730    if ((cc_recall_datastore = ast_channel_datastore_find(chan, &recall_ds_info, NULL))) {
03731       recall_cc_data = cc_recall_datastore->data;
03732       recall_cc_data->ignore = 1;
03733    }
03734    ast_channel_unlock(chan);
03735 }

int ast_queue_cc_frame ( struct ast_channel chan,
const char *const   monitor_type,
const char *const   dialstring,
enum ast_cc_service_type  service,
void *  private_data 
)

Queue an AST_CONTROL_CC frame.

Since:
1.8
Note:
Since this function calls ast_queue_frame, the channel will be locked during the course of this function.
Parameters:
chan The channel onto which to queue the frame
monitor_type The type of monitor to use when CC is requested
dialstring The dial string used to call the device
service The type of CC service the device is willing to offer
private_data If a native monitor is being used, and some channel-driver-specific private data has been allocated, then this parameter should contain a pointer to that data. If using a generic monitor, this parameter should remain NULL. Note that if this function should fail at some point, it is the responsibility of the caller to free the private data upon return.
Return values:
0 Success
-1 Error

Definition at line 4146 of file ccss.c.

References ast_cc_build_frame(), ast_cc_monitor_count(), ast_channel_get_cc_config_params(), ast_channel_get_device_name(), AST_CHANNEL_NAME, ast_frfree, ast_get_cc_max_monitors(), ast_log, ast_queue_frame(), LOG_NOTICE, and retval.

Referenced by analog_call(), and sip_handle_cc().

04148 {
04149    struct ast_frame frame = {0,};
04150    char device_name[AST_CHANNEL_NAME];
04151    int retval;
04152    struct ast_cc_config_params *cc_params;
04153 
04154    cc_params = ast_channel_get_cc_config_params(chan);
04155    if (!cc_params) {
04156       return -1;
04157    }
04158    ast_channel_get_device_name(chan, device_name, sizeof(device_name));
04159    if (ast_cc_monitor_count(device_name, monitor_type) >= ast_get_cc_max_monitors(cc_params)) {
04160       ast_log(LOG_NOTICE, "Not queuing a CC frame for device %s since it already has its maximum monitors allocated\n", device_name);
04161       return -1;
04162    }
04163 
04164    if (ast_cc_build_frame(chan, cc_params, monitor_type, device_name, dialstring, service, private_data, &frame)) {
04165       /* Frame building failed. We can't use this. */
04166       return -1;
04167    }
04168    retval = ast_queue_frame(chan, &frame);
04169    ast_frfree(&frame);
04170    return retval;
04171 }

void ast_set_cc_agent_dialstring ( struct ast_cc_config_params config,
const char *const   value 
)

Set the cc_agent_dialstring.

Since:
1.8
Parameters:
config The configuration to set the cc_agent_dialstring on
value The new cc_agent_dialstring we want to change to
Return values:
void 

Definition at line 971 of file ccss.c.

References ast_copy_string(), ast_strlen_zero, and ast_cc_config_params::cc_agent_dialstring.

Referenced by ast_cc_set_param().

00972 {
00973    if (ast_strlen_zero(value)) {
00974       config->cc_agent_dialstring[0] = '\0';
00975    } else {
00976       ast_copy_string(config->cc_agent_dialstring, value, sizeof(config->cc_agent_dialstring));
00977    }
00978 }

int ast_set_cc_agent_policy ( struct ast_cc_config_params config,
enum ast_cc_agent_policies  value 
)

Set the cc_agent_policy.

Since:
1.8
Parameters:
config The configuration to set the cc_agent_policy on
value The new cc_agent_policy we want to change to
Return values:
0 Success
-1 Failure (likely due to bad input)

Definition at line 877 of file ccss.c.

References AST_CC_AGENT_GENERIC, and ast_cc_config_params::cc_agent_policy.

Referenced by ast_cc_set_param(), and build_peer().

00878 {
00879    /* Screw C and its weak type checking for making me have to do this
00880     * validation at runtime.
00881     */
00882    if (value < AST_CC_AGENT_NEVER || value > AST_CC_AGENT_GENERIC) {
00883       return -1;
00884    }
00885    config->cc_agent_policy = value;
00886    return 0;
00887 }

void ast_set_cc_callback_macro ( struct ast_cc_config_params config,
const char *const   value 
)

Set the callback_macro name.

Since:
1.8
Parameters:
config The configuration to set the callback_macro on
value The new callback macro we want to change to
Return values:
void 

Definition at line 1010 of file ccss.c.

References ast_copy_string(), ast_log, ast_strlen_zero, ast_cc_config_params::cc_callback_macro, and LOG_WARNING.

Referenced by ast_cc_set_param().

01011 {
01012    ast_log(LOG_WARNING, "Usage of cc_callback_macro is deprecated.  Please use cc_callback_sub instead.\n");
01013    if (ast_strlen_zero(value)) {
01014       config->cc_callback_macro[0] = '\0';
01015    } else {
01016       ast_copy_string(config->cc_callback_macro, value, sizeof(config->cc_callback_macro));
01017    }
01018 }

void ast_set_cc_callback_sub ( struct ast_cc_config_params config,
const char *const   value 
)

Set the callback subroutine name.

Since:
11
Parameters:
config The configuration to set the callback_sub on
value The new callback subroutine we want to change to
Return values:
void 

Definition at line 1020 of file ccss.c.

References ast_copy_string(), ast_strlen_zero, and ast_cc_config_params::cc_callback_sub.

Referenced by ast_cc_set_param().

01021 {
01022    if (ast_strlen_zero(value)) {
01023       config->cc_callback_sub[0] = '\0';
01024    } else {
01025       ast_copy_string(config->cc_callback_sub, value, sizeof(config->cc_callback_sub));
01026    }
01027 }

int ast_set_cc_interfaces_chanvar ( struct ast_channel chan,
const char *const   extension 
)

Set the CC_INTERFACES channel variable for a channel using an.

Since:
1.8
extension@context 
as a starting point
The CC_INTERFACES channel variable will have the interfaces that should be called back for a specific PBX instance. This version of the function is used mainly by local channels, wherein we need to set CC_INTERFACES based on an extension and context that appear in the middle of the tree of dialed interfaces.

Note:
This function will lock the channel as well as the list of monitors stored on the channel's CC recall datastore, though neither are held at the same time. Callers of this function should be aware of potential lock ordering problems that may arise.
Parameters:
chan The channel to set the CC_INTERFACES variable on
extension The name of the extension for which we're setting the variable. This should be in the form of
exten@context 

Definition at line 3665 of file ccss.c.

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_free, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log_dynamic_level, ast_str_buffer(), ast_str_create(), build_cc_interfaces_chanvar(), cc_recall_ds_data::core_id, ast_datastore::data, ast_cc_interface::device_name, ast_cc_monitor::interface, cc_recall_ds_data::interface_tree, NULL, pbx_builtin_setvar_helper(), and str.

Referenced by local_call().

03666 {
03667    struct ast_datastore *recall_datastore;
03668    struct cc_monitor_tree *interface_tree;
03669    struct ast_cc_monitor *monitor_iter;
03670    struct cc_recall_ds_data *recall_data;
03671    struct ast_str *str = ast_str_create(64);
03672    int core_id;
03673 
03674    if (!str) {
03675       return -1;
03676    }
03677 
03678    ast_channel_lock(chan);
03679    if (!(recall_datastore = ast_channel_datastore_find(chan, &recall_ds_info, NULL))) {
03680       ast_channel_unlock(chan);
03681       ast_free(str);
03682       return -1;
03683    }
03684    recall_data = recall_datastore->data;
03685    interface_tree = recall_data->interface_tree;
03686    core_id = recall_data->core_id;
03687    ast_channel_unlock(chan);
03688 
03689    AST_LIST_LOCK(interface_tree);
03690    AST_LIST_TRAVERSE(interface_tree, monitor_iter, next) {
03691       if (!strcmp(monitor_iter->interface->device_name, extension)) {
03692          break;
03693       }
03694    }
03695 
03696    if (!monitor_iter) {
03697       /* We couldn't find this extension. This may be because
03698        * we have been directed into an unexpected extension because
03699        * the admin has changed a CC_INTERFACES variable at some point.
03700        */
03701       AST_LIST_UNLOCK(interface_tree);
03702       ast_free(str);
03703       return -1;
03704    }
03705 
03706    build_cc_interfaces_chanvar(monitor_iter, &str);
03707    AST_LIST_UNLOCK(interface_tree);
03708 
03709    pbx_builtin_setvar_helper(chan, "CC_INTERFACES", ast_str_buffer(str));
03710    ast_log_dynamic_level(cc_logger_level, "Core %d: CC_INTERFACES set to %s\n",
03711          core_id, ast_str_buffer(str));
03712 
03713    ast_free(str);
03714    return 0;
03715 }

void ast_set_cc_max_agents ( struct ast_cc_config_params config,
unsigned int  value 
)

Set the cc_max_agents.

Since:
1.8
Parameters:
config The configuration to set the cc_max_agents on
value The new cc_max_agents we want to change to
Return values:
void 

Definition at line 985 of file ccss.c.

References ast_cc_config_params::cc_max_agents.

Referenced by ast_cc_set_param().

00986 {
00987    config->cc_max_agents = value;
00988 }

void ast_set_cc_max_monitors ( struct ast_cc_config_params config,
unsigned int  value 
)

Set the cc_max_monitors.

Since:
1.8
Parameters:
config The configuration to set the cc_max_monitors on
value The new cc_max_monitors we want to change to
Return values:
void 

Definition at line 995 of file ccss.c.

References ast_cc_config_params::cc_max_monitors.

Referenced by ast_cc_set_param().

00996 {
00997    config->cc_max_monitors = value;
00998 }

int ast_set_cc_monitor_policy ( struct ast_cc_config_params config,
enum ast_cc_monitor_policies  value 
)

Set the cc_monitor_policy.

Since:
1.8
Parameters:
config The configuration to set the cc_monitor_policy on
value The new cc_monitor_policy we want to change to
Return values:
0 Success
-1 Failure (likely due to bad input)

Definition at line 894 of file ccss.c.

References AST_CC_MONITOR_ALWAYS, and ast_cc_config_params::cc_monitor_policy.

Referenced by ast_cc_set_param().

00895 {
00896    /* Screw C and its weak type checking for making me have to do this
00897     * validation at runtime.
00898     */
00899    if (value < AST_CC_MONITOR_NEVER || value > AST_CC_MONITOR_ALWAYS) {
00900       return -1;
00901    }
00902    config->cc_monitor_policy = value;
00903    return 0;
00904 }

void ast_set_cc_offer_timer ( struct ast_cc_config_params config,
unsigned int  value 
)

Set the cc_offer_timer.

Since:
1.8
Parameters:
config The configuration to set the cc_offer_timer on
value The new cc_offer_timer we want to change to
Return values:
void 

Definition at line 911 of file ccss.c.

References ast_log, ast_cc_config_params::cc_offer_timer, and LOG_WARNING.

Referenced by ast_cc_set_param().

00912 {
00913    /* 0 is an unreasonable value for any timer. Stick with the default */
00914    if (value == 0) {
00915       ast_log(LOG_WARNING, "0 is an invalid value for cc_offer_timer. Retaining value as %u\n", config->cc_offer_timer);
00916       return;
00917    }
00918    config->cc_offer_timer = value;
00919 }

void ast_set_cc_recall_timer ( struct ast_cc_config_params config,
unsigned int  value 
)

Set the cc_recall_timer.

Since:
1.8
Parameters:
config The configuration to set the cc_recall_timer on
value The new cc_recall_timer we want to change to
Return values:
void 

Definition at line 941 of file ccss.c.

References ast_log, ast_cc_config_params::cc_recall_timer, and LOG_WARNING.

Referenced by ast_cc_set_param().

00942 {
00943    /* 0 is an unreasonable value for any timer. Stick with the default */
00944    if (value == 0) {
00945       ast_log(LOG_WARNING, "0 is an invalid value for ccnr_available_timer. Retaining value as %u\n", config->cc_recall_timer);
00946       return;
00947    }
00948    config->cc_recall_timer = value;
00949 }

void ast_set_ccbs_available_timer ( struct ast_cc_config_params config,
unsigned int  value 
)

Set the ccbs_available_timer.

Since:
1.8
Parameters:
config The configuration to set the ccbs_available_timer on
value The new ccbs_available_timer we want to change to
Return values:
void 

Definition at line 956 of file ccss.c.

References ast_log, ast_cc_config_params::ccbs_available_timer, and LOG_WARNING.

Referenced by ast_cc_set_param().

00957 {
00958    /* 0 is an unreasonable value for any timer. Stick with the default */
00959    if (value == 0) {
00960       ast_log(LOG_WARNING, "0 is an invalid value for ccbs_available_timer. Retaining value as %u\n", config->ccbs_available_timer);
00961       return;
00962    }
00963    config->ccbs_available_timer = value;
00964 }

void ast_set_ccnr_available_timer ( struct ast_cc_config_params config,
unsigned int  value 
)

Set the ccnr_available_timer.

Since:
1.8
Parameters:
config The configuration to set the ccnr_available_timer on
value The new ccnr_available_timer we want to change to
Return values:
void 

Definition at line 926 of file ccss.c.

References ast_log, ast_cc_config_params::ccnr_available_timer, and LOG_WARNING.

Referenced by ast_cc_set_param().

00927 {
00928    /* 0 is an unreasonable value for any timer. Stick with the default */
00929    if (value == 0) {
00930       ast_log(LOG_WARNING, "0 is an invalid value for ccnr_available_timer. Retaining value as %u\n", config->ccnr_available_timer);
00931       return;
00932    }
00933    config->ccnr_available_timer = value;
00934 }

int ast_setup_cc_recall_datastore ( struct ast_channel chan,
const int  core_id 
)

Set up a CC recall datastore on a channel.

Since:
1.8
Implementers of protocol-specific CC agents will need to call this function in order for the channel to have the necessary interfaces to recall.

This function must be called by the implementer once it has been detected that an inbound call is a cc_recall. After allocating the channel, call this function, followed by ast_cc_set_cc_interfaces_chanvar. While it would be nice to be able to have the core do this automatically, it just cannot be done given the current architecture.

Definition at line 3402 of file ccss.c.

References ast_calloc, ast_channel_datastore_add(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc, ast_datastore_free(), ast_free, cc_ref(), cc_unref(), cc_recall_ds_data::core_id, ast_datastore::data, DATASTORE_INHERIT_FOREVER, find_cc_core_instance(), ast_datastore::inheritance, cc_recall_ds_data::interface_tree, cc_core_instance::monitors, and NULL.

Referenced by generic_recall(), and handle_request_invite().

03403 {
03404    struct ast_datastore *recall_datastore = ast_datastore_alloc(&recall_ds_info, NULL);
03405    struct cc_recall_ds_data *recall_data;
03406    struct cc_core_instance *core_instance;
03407 
03408    if (!recall_datastore) {
03409       return -1;
03410    }
03411 
03412    if (!(recall_data = ast_calloc(1, sizeof(*recall_data)))) {
03413       ast_datastore_free(recall_datastore);
03414       return -1;
03415    }
03416 
03417    if (!(core_instance = find_cc_core_instance(core_id))) {
03418       ast_free(recall_data);
03419       ast_datastore_free(recall_datastore);
03420       return -1;
03421    }
03422 
03423    recall_data->interface_tree = cc_ref(core_instance->monitors,
03424          "Bump refcount for monitor tree for recall datastore");
03425    recall_data->core_id = core_id;
03426    recall_datastore->data = recall_data;
03427    recall_datastore->inheritance = DATASTORE_INHERIT_FOREVER;
03428    ast_channel_lock(chan);
03429    ast_channel_datastore_add(chan, recall_datastore);
03430    ast_channel_unlock(chan);
03431    cc_unref(core_instance, "Recall datastore set up. No need for core_instance ref");
03432    return 0;
03433 }


Generated on Thu Apr 16 06:29:20 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6