Asterisk - The Open Source Telephony Project  GIT-master-a24979a
Data Structures | Macros | Enumerations | Functions | Variables
ccss.c File Reference

Call Completion Supplementary Services implementation. More...

#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/strings.h"
#include "asterisk/ccss.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/devicestate.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/cli.h"
#include "asterisk/manager.h"
#include "asterisk/causes.h"
#include "asterisk/stasis_system.h"
#include "asterisk/format_cache.h"
Include dependency graph for ccss.c:

Go to the source code of this file.

Data Structures

struct  ast_cc_config_params
 
struct  ast_cc_monitor_failure_data
 
struct  cc_agent_backend
 
struct  cc_agent_backends
 
struct  cc_callback_helper
 
struct  cc_control_payload
 The payload for an AST_CONTROL_CC frame. More...
 
struct  cc_core_instance
 
struct  cc_generic_agent_pvt
 
struct  cc_monitor_backend
 
struct  cc_monitor_backends
 
struct  cc_monitor_tree
 The "tree" of interfaces that is dialed. More...
 
struct  cc_recall_ds_data
 
struct  cc_state_change_args
 
struct  cc_status_response_args
 
struct  count_agents_cb_data
 
struct  count_monitors_cb_data
 
struct  dialed_cc_interfaces
 
struct  extension_child_dialstring
 Data regarding an extension monitor's child's dialstrings. More...
 
struct  extension_monitor_pvt
 Private data for an extension monitor. More...
 
struct  generic_monitor_instance
 
struct  generic_monitor_instance_list
 
struct  generic_monitor_pvt
 private data for generic device monitor More...
 

Macros

#define CC_ACTIVE_DEVSTATE_DEFAULT   AST_DEVICE_INUSE
 
#define CC_AVAILABLE_DEVSTATE_DEFAULT   AST_DEVICE_NOT_INUSE
 
#define CC_CALLEE_READY_DEVSTATE_DEFAULT   AST_DEVICE_RINGING
 
#define CC_CALLER_BUSY_DEVSTATE_DEFAULT   AST_DEVICE_ONHOLD
 
#define CC_CALLER_OFFERED_DEVSTATE_DEFAULT   AST_DEVICE_NOT_INUSE
 
#define CC_CALLER_REQUESTED_DEVSTATE_DEFAULT   AST_DEVICE_NOT_INUSE
 
#define CC_COMPLETE_DEVSTATE_DEFAULT   AST_DEVICE_NOT_INUSE
 
#define CC_FAILED_DEVSTATE_DEFAULT   AST_DEVICE_NOT_INUSE
 
#define CC_MAX_AGENTS_DEFAULT   5
 
#define CC_MAX_MONITORS_DEFAULT   5
 
#define CC_OFFER_TIMER_DEFAULT   20 /* Seconds */
 
#define CC_RECALL_TIMER_DEFAULT   20 /* Seconds */
 
#define CC_RECALLING_DEVSTATE_DEFAULT   AST_DEVICE_RINGING
 
#define CCBS_AVAILABLE_TIMER_DEFAULT   4800 /* Seconds */
 
#define CCNR_AVAILABLE_TIMER_DEFAULT   7200 /* Seconds */
 
#define GLOBAL_CC_MAX_REQUESTS_DEFAULT   20
 

Enumerations

enum  cc_state {
  CC_AVAILABLE , CC_CALLER_OFFERED , CC_CALLER_REQUESTED , CC_ACTIVE ,
  CC_CALLEE_READY , CC_CALLER_BUSY , CC_RECALLING , CC_COMPLETE ,
  CC_FAILED
}
 The states used in the CCSS core state machine. More...
 
enum  match_flags { MATCH_NO_REQUEST = (1 << 0) , MATCH_REQUEST = (1 << 1) }
 

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. More...
 
static void __reg_module (void)
 
static void __unreg_module (void)
 
static void agent_destroy (void *data)
 
static const char * agent_policy_to_str (enum ast_cc_agent_policies policy)
 
int ast_cc_agent_accept_request (int core_id, const char *const debug,...)
 Accept inbound CC request. More...
 
struct ast_cc_agentast_cc_agent_callback (int flags, ao2_callback_fn *function, void *args, const char *const type)
 Call a callback on all agents of a specific type. More...
 
int ast_cc_agent_caller_available (int core_id, const char *const debug,...)
 Indicate that a previously unavailable caller has become available. More...
 
int ast_cc_agent_caller_busy (int core_id, const char *debug,...)
 Indicate that the caller is busy. More...
 
int ast_cc_agent_recalling (int core_id, const char *const debug,...)
 Tell the CC core that a caller is currently recalling. More...
 
int ast_cc_agent_register (const struct ast_cc_agent_callbacks *callbacks)
 Register a set of agent callbacks with the core. More...
 
int ast_cc_agent_set_interfaces_chanvar (struct ast_channel *chan)
 Set the first level CC_INTERFACES channel variable for a channel. More...
 
int ast_cc_agent_status_response (int core_id, enum ast_device_state devstate)
 Response with a caller's current status. More...
 
void ast_cc_agent_unregister (const struct ast_cc_agent_callbacks *callbacks)
 Unregister a set of agent callbacks with the core. More...
 
int ast_cc_available_timer_expire (const void *data)
 Scheduler callback for available timer expiration. More...
 
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. More...
 
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. More...
 
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. More...
 
int ast_cc_call_init (struct ast_channel *chan, int *ignore_cc)
 Start the CC process on a call. More...
 
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. More...
 
int ast_cc_completed (struct ast_channel *chan, const char *const debug,...)
 Indicate recall has been acknowledged. More...
 
void ast_cc_config_params_destroy (struct ast_cc_config_params *params)
 Free memory from CCSS configuration params. More...
 
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 More...
 
void ast_cc_default_config_params (struct ast_cc_config_params *params)
 Set the specified CC config params to default values. More...
 
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. More...
 
int ast_cc_failed (int core_id, const char *const debug,...)
 Indicate failure has occurred. More...
 
int ast_cc_get_current_core_id (struct ast_channel *chan)
 Get the core id for the current call. More...
 
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. More...
 
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 More...
 
int ast_cc_is_config_param (const char *const name)
 Is this a CCSS configuration parameter? More...
 
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. More...
 
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. More...
 
int ast_cc_monitor_count (const char *const name, const char *const type)
 Return the number of outstanding CC requests to a specific device. More...
 
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. More...
 
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. More...
 
int ast_cc_monitor_register (const struct ast_cc_monitor_callbacks *callbacks)
 Register a set of monitor callbacks with the core. More...
 
int ast_cc_monitor_request_acked (int core_id, const char *const debug,...)
 Indicate that an outbound entity has accepted our CC request. More...
 
int ast_cc_monitor_status_request (int core_id)
 Request the status of a caller or callers. More...
 
int ast_cc_monitor_stop_ringing (int core_id)
 Alert a caller to stop ringing. More...
 
void ast_cc_monitor_unregister (const struct ast_cc_monitor_callbacks *callbacks)
 Unregister a set of monitor callbacks with the core. More...
 
int ast_cc_offer (struct ast_channel *caller_chan)
 Offer CC to a caller. More...
 
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. More...
 
int ast_cc_set_param (struct ast_cc_config_params *params, const char *const name, const char *const value)
 set a CCSS configuration parameter, given its name More...
 
const char * ast_get_cc_agent_dialstring (struct ast_cc_config_params *config)
 Get the cc_agent_dialstring. More...
 
enum ast_cc_agent_policies ast_get_cc_agent_policy (struct ast_cc_config_params *config)
 Get the cc_agent_policy. More...
 
const char * ast_get_cc_callback_macro (struct ast_cc_config_params *config)
 Get the name of the callback_macro. More...
 
const char * ast_get_cc_callback_sub (struct ast_cc_config_params *config)
 Get the name of the callback subroutine. More...
 
unsigned int ast_get_cc_max_agents (struct ast_cc_config_params *config)
 Get the cc_max_agents. More...
 
unsigned int ast_get_cc_max_monitors (struct ast_cc_config_params *config)
 Get the cc_max_monitors. More...
 
enum ast_cc_monitor_policies ast_get_cc_monitor_policy (struct ast_cc_config_params *config)
 Get the cc_monitor_policy. More...
 
unsigned int ast_get_cc_offer_timer (struct ast_cc_config_params *config)
 Get the cc_offer_timer. More...
 
unsigned int ast_get_cc_recall_timer (struct ast_cc_config_params *config)
 Get the cc_recall_timer. More...
 
unsigned int ast_get_ccbs_available_timer (struct ast_cc_config_params *config)
 Get the ccbs_available_timer. More...
 
unsigned int ast_get_ccnr_available_timer (struct ast_cc_config_params *config)
 Get the ccnr_available_timer. More...
 
void ast_handle_cc_control_frame (struct ast_channel *inbound, struct ast_channel *outbound, void *frame_data)
 Properly react to a CC control frame. More...
 
void ast_ignore_cc (struct ast_channel *chan)
 Mark the channel to ignore further CC activity. More...
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
int ast_queue_cc_frame (struct ast_channel *chan, const char *monitor_type, const char *const dialstring, enum ast_cc_service_type service, void *private_data)
 Queue an AST_CONTROL_CC frame. More...
 
void ast_set_cc_agent_dialstring (struct ast_cc_config_params *config, const char *const value)
 Set the cc_agent_dialstring. More...
 
int ast_set_cc_agent_policy (struct ast_cc_config_params *config, enum ast_cc_agent_policies value)
 Set the cc_agent_policy. More...
 
void ast_set_cc_callback_macro (struct ast_cc_config_params *config, const char *const value)
 Set the callback_macro name. More...
 
void ast_set_cc_callback_sub (struct ast_cc_config_params *config, const char *const value)
 Set the callback subroutine name. More...
 
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. More...
 
void ast_set_cc_max_agents (struct ast_cc_config_params *config, unsigned int value)
 Set the cc_max_agents. More...
 
void ast_set_cc_max_monitors (struct ast_cc_config_params *config, unsigned int value)
 Set the cc_max_monitors. More...
 
int ast_set_cc_monitor_policy (struct ast_cc_config_params *config, enum ast_cc_monitor_policies value)
 Set the cc_monitor_policy. More...
 
void ast_set_cc_offer_timer (struct ast_cc_config_params *config, unsigned int value)
 Set the cc_offer_timer. More...
 
void ast_set_cc_recall_timer (struct ast_cc_config_params *config, unsigned int value)
 Set the cc_recall_timer. More...
 
void ast_set_ccbs_available_timer (struct ast_cc_config_params *config, unsigned int value)
 Set the ccbs_available_timer. More...
 
void ast_set_ccnr_available_timer (struct ast_cc_config_params *config, unsigned int value)
 Set the ccnr_available_timer. More...
 
int ast_setup_cc_recall_datastore (struct ast_channel *chan, const int core_id)
 Set up a CC recall datastore on a channel. More...
 
static void build_cc_interfaces_chanvar (struct ast_cc_monitor *starting_point, struct ast_str **str)
 
static void call_destructor_with_no_monitor (const char *const monitor_type, void *private_data)
 
static void cancel_available_timer (struct cc_core_instance *core_instance)
 
static int cc_active (struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
 
static int cc_agent_callback_helper (void *obj, void *args, int flags)
 
static struct ast_cc_agentcc_agent_init (struct ast_channel *caller_chan, const char *const caller_name, const int core_id, struct cc_monitor_tree *interface_tree)
 
static int cc_available (struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
 
static int cc_build_payload (struct ast_channel *chan, struct ast_cc_config_params *cc_params, const char *monitor_type, const char *const device_name, const char *dialstring, enum ast_cc_service_type service, void *private_data, struct cc_control_payload *payload)
 
static int cc_callee_ready (struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
 
static int cc_caller_busy (struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
 
static int cc_caller_offered (struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
 
static int cc_caller_requested (struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
 
static int cc_cli_output_status (void *data)
 
static void cc_cli_print_monitor_stats (struct ast_cc_monitor *monitor, int fd, int parent_id)
 
static int cc_complete (struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
 
static struct cc_core_instancecc_core_init_instance (struct ast_channel *caller_chan, struct cc_monitor_tree *called_tree, const int core_id, struct cc_control_payload *cc_data)
 
static int cc_core_instance_cmp_fn (void *obj, void *arg, int flags)
 
static void cc_core_instance_destructor (void *data)
 
static int cc_core_instance_hash_fn (const void *obj, const int flags)
 
static struct ast_cc_monitorcc_device_monitor_init (const char *const device_name, const char *const dialstring, const struct cc_control_payload *cc_data, int core_id)
 
static int cc_do_state_change (void *datap)
 
static void cc_extension_monitor_change_is_valid (struct cc_core_instance *core_instance, unsigned int parent_id, const char *const device_name, int is_valid)
 
static void cc_extension_monitor_destructor (void *private_data)
 
static struct ast_cc_monitorcc_extension_monitor_init (const char *const exten, const char *const context, const unsigned int parent_id)
 
static int cc_failed (struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
 
static void cc_generic_agent_destructor (struct ast_cc_agent *agent)
 
static int cc_generic_agent_init (struct ast_cc_agent *agent, struct ast_channel *chan)
 
static int cc_generic_agent_recall (struct ast_cc_agent *agent)
 
static void cc_generic_agent_respond (struct ast_cc_agent *agent, enum ast_cc_agent_response_reason reason)
 
static int cc_generic_agent_start_monitoring (struct ast_cc_agent *agent)
 
static int cc_generic_agent_start_offer_timer (struct ast_cc_agent *agent)
 
static int cc_generic_agent_status_request (struct ast_cc_agent *agent)
 
static int cc_generic_agent_stop_offer_timer (struct ast_cc_agent *agent)
 
static int cc_generic_agent_stop_ringing (struct ast_cc_agent *agent)
 
static int cc_generic_is_device_available (enum ast_device_state state)
 
static int cc_generic_monitor_cancel_available_timer (struct ast_cc_monitor *monitor, int *sched_id)
 
static void cc_generic_monitor_destructor (void *private_data)
 
static int cc_generic_monitor_request_cc (struct ast_cc_monitor *monitor, int *available_timer_id)
 
static int cc_generic_monitor_suspend (struct ast_cc_monitor *monitor)
 
static int cc_generic_monitor_unsuspend (struct ast_cc_monitor *monitor)
 
static void cc_interface_destroy (void *data)
 
static void cc_interface_tree_destroy (void *data)
 
static int cc_interfaces_datastore_init (struct ast_channel *chan)
 
static void cc_monitor_destroy (void *data)
 
static int cc_monitor_failed (void *data)
 
static int cc_offer (const int core_id, const char *const debug,...)
 
static int cc_party_b_free (void *data)
 
static int cc_publish (struct stasis_message_type *message_type, int core_id, struct ast_json *extras)
 
static void cc_publish_available (int core_id, const char *callee, const char *service)
 
static void cc_publish_callerrecalling (int core_id, const char *caller)
 
static void cc_publish_callerstartmonitoring (int core_id, const char *caller)
 
static void cc_publish_callerstopmonitoring (int core_id, const char *caller)
 
static void cc_publish_failure (int core_id, const char *caller, const char *reason)
 
static void cc_publish_monitorfailed (int core_id, const char *callee)
 
static void cc_publish_offertimerstart (int core_id, const char *caller, unsigned int expires)
 
static void cc_publish_recallcomplete (int core_id, const char *caller)
 
static void cc_publish_requestacknowledged (int core_id, const char *caller)
 
static void cc_publish_requested (int core_id, const char *caller, const char *callee)
 
static void cc_recall_ds_destroy (void *data)
 
static void * cc_recall_ds_duplicate (void *data)
 
static int cc_recalling (struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
 
static void * cc_ref (void *obj, const char *debug)
 
static int cc_request_state_change (enum cc_state state, const int core_id, const char *debug, va_list ap)
 
static const char * cc_service_to_string (enum ast_cc_service_type service)
 
static enum ast_device_state cc_state_to_devstate (enum cc_state state)
 
static const char * cc_state_to_string (enum cc_state state)
 
static int cc_status_request (void *data)
 
static int cc_status_response (void *data)
 
static int cc_stop_ringing (void *data)
 
static void cc_unique_append (struct ast_str **str, const char *dialstring)
 
static void * cc_unref (void *obj, const char *debug)
 
static int cccancel_exec (struct ast_channel *chan, const char *data)
 
static int ccreq_exec (struct ast_channel *chan, const char *data)
 
static enum ast_device_state ccss_device_state (const char *device_name)
 
static void ccss_notify_device_state_change (const char *device, enum cc_state state)
 
static void check_callback_sanity (const struct ast_cc_agent_callbacks *callbacks)
 
static char * complete_core_id (const char *word)
 
static long count_agents (const char *const caller, const int core_id_exception)
 
static int count_agents_cb (void *obj, void *arg, void *data, int flags)
 
static int count_monitors_cb (void *obj, void *arg, int flags)
 
static struct generic_monitor_instance_listcreate_new_generic_list (struct ast_cc_monitor *monitor)
 
static void dialed_cc_interfaces_destroy (void *data)
 
static void * dialed_cc_interfaces_duplicate (void *data)
 
static struct extension_monitor_pvtextension_monitor_pvt_init (void)
 
static const struct ast_cc_agent_callbacksfind_agent_callbacks (struct ast_channel *chan)
 
static struct cc_core_instancefind_cc_core_instance (const int core_id)
 
static struct generic_monitor_instance_listfind_generic_monitor_instance_list (const char *const device_name)
 
static const struct ast_cc_monitor_callbacksfind_monitor_callbacks (const char *const type)
 
static void generic_agent_devstate_cb (void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
 
static void generic_monitor_devstate_cb (void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
 
static int generic_monitor_devstate_tp_cb (void *data)
 
static void generic_monitor_instance_list_destructor (void *obj)
 
static void * generic_recall (void *data)
 
static char * handle_cc_kill (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_cc_status (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int has_device_monitors (struct cc_core_instance *core_instance)
 check if the core instance has any device monitors More...
 
static void initialize_cc_devstate_map (void)
 
static void initialize_cc_devstate_map_helper (struct ast_config *cc_config, enum cc_state state, const char *cc_setting)
 
static void initialize_cc_max_requests (void)
 
static int is_state_change_valid (enum cc_state current_state, const enum cc_state new_state, struct ast_cc_agent *agent)
 
static int kill_cores (void *obj, void *arg, int flags)
 
static void kill_duplicate_offers (char *caller)
 
static int load_module (void)
 
static int match_agent (void *obj, void *arg, void *data, int flags)
 
static const char * monitor_policy_to_str (enum ast_cc_monitor_policies policy)
 
static int offer_timer_expire (const void *data)
 
static int print_stats_cb (void *obj, void *arg, int flags)
 
static void request_cc (struct cc_core_instance *core_instance)
 
static enum ast_cc_agent_policies str_to_agent_policy (const char *const value)
 
static enum ast_cc_monitor_policies str_to_monitor_policy (const char *const value)
 
static void suspend (struct cc_core_instance *core_instance)
 
static int unload_module (void)
 
static void unsuspend (struct cc_core_instance *core_instance)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Call Completion Supplementary Services" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
struct cc_agent_backends cc_agent_backends = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static struct ast_cli_entry cc_cli []
 
static struct ao2_containercc_core_instances
 
static const int CC_CORE_INSTANCES_BUCKETS = 17
 
static struct ast_taskprocessorcc_core_taskprocessor
 
static const struct ast_cc_config_params cc_default_params
 
static int cc_logger_level
 
static const char * CC_LOGGER_LEVEL_NAME = "CC"
 
struct cc_monitor_backends cc_monitor_backends = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static int cc_request_count
 
static struct ast_sched_contextcc_sched_context
 
struct {
   enum ast_cc_service_type   service
 
   const char *   service_string
 
cc_service_to_string_map []
 
static enum ast_device_state cc_state_to_devstate_map []
 
struct {
   enum cc_state   state
 
   const char *   state_string
 
cc_state_to_string_map []
 
static const char * cccancel_app = "CallCompletionCancel"
 
static const char * ccreq_app = "CallCompletionRequest"
 
static int core_id_counter
 
static int dialed_cc_interface_counter
 
static const struct ast_datastore_info dialed_cc_interfaces_info
 
static struct ast_cc_agent_callbacks generic_agent_callbacks
 
static struct ast_cc_monitor_callbacks generic_monitor_cbs
 
struct ao2_containergeneric_monitors
 
static unsigned int global_cc_max_requests
 
static const struct ast_datastore_info recall_ds_info
 
static int(*const state_change_funcs [])(struct cc_core_instance *, struct cc_state_change_args *, enum cc_state previous_state)
 

Detailed Description

Call Completion Supplementary Services implementation.

Author
Mark Michelson mmich.nosp@m.elso.nosp@m.n@dig.nosp@m.ium..nosp@m.com

Definition in file ccss.c.

Macro Definition Documentation

◆ CC_ACTIVE_DEVSTATE_DEFAULT

#define CC_ACTIVE_DEVSTATE_DEFAULT   AST_DEVICE_INUSE

Definition at line 553 of file ccss.c.

◆ CC_AVAILABLE_DEVSTATE_DEFAULT

#define CC_AVAILABLE_DEVSTATE_DEFAULT   AST_DEVICE_NOT_INUSE

Definition at line 550 of file ccss.c.

◆ CC_CALLEE_READY_DEVSTATE_DEFAULT

#define CC_CALLEE_READY_DEVSTATE_DEFAULT   AST_DEVICE_RINGING

Definition at line 554 of file ccss.c.

◆ CC_CALLER_BUSY_DEVSTATE_DEFAULT

#define CC_CALLER_BUSY_DEVSTATE_DEFAULT   AST_DEVICE_ONHOLD

Definition at line 555 of file ccss.c.

◆ CC_CALLER_OFFERED_DEVSTATE_DEFAULT

#define CC_CALLER_OFFERED_DEVSTATE_DEFAULT   AST_DEVICE_NOT_INUSE

Definition at line 551 of file ccss.c.

◆ CC_CALLER_REQUESTED_DEVSTATE_DEFAULT

#define CC_CALLER_REQUESTED_DEVSTATE_DEFAULT   AST_DEVICE_NOT_INUSE

Definition at line 552 of file ccss.c.

◆ CC_COMPLETE_DEVSTATE_DEFAULT

#define CC_COMPLETE_DEVSTATE_DEFAULT   AST_DEVICE_NOT_INUSE

Definition at line 557 of file ccss.c.

◆ CC_FAILED_DEVSTATE_DEFAULT

#define CC_FAILED_DEVSTATE_DEFAULT   AST_DEVICE_NOT_INUSE

Definition at line 558 of file ccss.c.

◆ CC_MAX_AGENTS_DEFAULT

#define CC_MAX_AGENTS_DEFAULT   5

Definition at line 659 of file ccss.c.

◆ CC_MAX_MONITORS_DEFAULT

#define CC_MAX_MONITORS_DEFAULT   5

Definition at line 660 of file ccss.c.

◆ CC_OFFER_TIMER_DEFAULT

#define CC_OFFER_TIMER_DEFAULT   20 /* Seconds */

Definition at line 655 of file ccss.c.

◆ CC_RECALL_TIMER_DEFAULT

#define CC_RECALL_TIMER_DEFAULT   20 /* Seconds */

Definition at line 658 of file ccss.c.

◆ CC_RECALLING_DEVSTATE_DEFAULT

#define CC_RECALLING_DEVSTATE_DEFAULT   AST_DEVICE_RINGING

Definition at line 556 of file ccss.c.

◆ CCBS_AVAILABLE_TIMER_DEFAULT

#define CCBS_AVAILABLE_TIMER_DEFAULT   4800 /* Seconds */

Definition at line 657 of file ccss.c.

◆ CCNR_AVAILABLE_TIMER_DEFAULT

#define CCNR_AVAILABLE_TIMER_DEFAULT   7200 /* Seconds */

Definition at line 656 of file ccss.c.

◆ GLOBAL_CC_MAX_REQUESTS_DEFAULT

#define GLOBAL_CC_MAX_REQUESTS_DEFAULT   20

Definition at line 661 of file ccss.c.

Enumeration Type Documentation

◆ cc_state

enum cc_state

The states used in the CCSS core state machine.

Since
1.8

For more information, see doc/CCSS_architecture.pdf

Enumerator
CC_AVAILABLE 

Entered when it is determined that CCSS may be used for the call

CC_CALLER_OFFERED 

Entered when a CCSS agent has offered CCSS to a caller

CC_CALLER_REQUESTED 

Entered when a CCSS agent confirms that a caller has requested CCSS

CC_ACTIVE 

Entered when a CCSS monitor confirms acknowledgment of an outbound CCSS request

CC_CALLEE_READY 

Entered when a CCSS monitor alerts the core that the called party has become available

CC_CALLER_BUSY 

Entered when a CCSS agent alerts the core that the calling party may not be recalled because he is unavailable

CC_RECALLING 

Entered when a CCSS agent alerts the core that the calling party is attempting to recall the called party

CC_COMPLETE 

Entered when an application alerts the core that the calling party's recall attempt has had a call progress response indicated

CC_FAILED 

Entered any time that something goes wrong during the process, thus resulting in the failure of the attempted CCSS transaction. Note also that cancellations of CC are treated as failures.

Definition at line 181 of file ccss.c.

181  {
182  /*! Entered when it is determined that CCSS may be used for the call */
183  CC_AVAILABLE,
184  /*! Entered when a CCSS agent has offered CCSS to a caller */
186  /*! Entered when a CCSS agent confirms that a caller has
187  * requested CCSS */
189  /*! Entered when a CCSS monitor confirms acknowledgment of an
190  * outbound CCSS request */
191  CC_ACTIVE,
192  /*! Entered when a CCSS monitor alerts the core that the called party
193  * has become available */
195  /*! Entered when a CCSS agent alerts the core that the calling party
196  * may not be recalled because he is unavailable
197  */
199  /*! Entered when a CCSS agent alerts the core that the calling party
200  * is attempting to recall the called party
201  */
202  CC_RECALLING,
203  /*! Entered when an application alerts the core that the calling party's
204  * recall attempt has had a call progress response indicated
205  */
206  CC_COMPLETE,
207  /*! Entered any time that something goes wrong during the process, thus
208  * resulting in the failure of the attempted CCSS transaction. Note also
209  * that cancellations of CC are treated as failures.
210  */
211  CC_FAILED,
212 };
@ CC_COMPLETE
Definition: ccss.c:206
@ CC_CALLEE_READY
Definition: ccss.c:194
@ CC_CALLER_OFFERED
Definition: ccss.c:185
@ CC_ACTIVE
Definition: ccss.c:191
@ CC_FAILED
Definition: ccss.c:211
@ CC_CALLER_BUSY
Definition: ccss.c:198
@ CC_AVAILABLE
Definition: ccss.c:183
@ CC_RECALLING
Definition: ccss.c:202
@ CC_CALLER_REQUESTED
Definition: ccss.c:188

◆ match_flags

Enumerator
MATCH_NO_REQUEST 
MATCH_REQUEST 

Definition at line 470 of file ccss.c.

470  {
471  /* Only match agents that have not yet
472  * made a CC request
473  */
474  MATCH_NO_REQUEST = (1 << 0),
475  /* Only match agents that have made
476  * a CC request
477  */
478  MATCH_REQUEST = (1 << 1),
479 };
@ MATCH_REQUEST
Definition: ccss.c:478
@ MATCH_NO_REQUEST
Definition: ccss.c:474

Function Documentation

◆ __ast_cc_config_params_init()

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.

Note
Reasonable default values are chosen for the parameters upon allocation.
Return values
NULLUnable to allocate the structure
non-NULLA pointer to the newly allocated and initialized structure

Definition at line 682 of file ccss.c.

683 {
684  struct ast_cc_config_params *params = __ast_malloc(sizeof(*params), file, line, function);
685 
686  if (!params) {
687  return NULL;
688  }
689 
691  return params;
692 }
void * __ast_malloc(size_t size, const char *file, int lineno, const char *func) attribute_malloc
Definition: astmm.c:1628
void ast_cc_default_config_params(struct ast_cc_config_params *params)
Set the specified CC config params to default values.
Definition: ccss.c:677
#define NULL
Definition: resample.c:96

References __ast_malloc(), ast_cc_default_config_params(), make_ari_stubs::file, and NULL.

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 4701 of file ccss.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 4701 of file ccss.c.

◆ agent_destroy()

static void agent_destroy ( void *  data)
static

Definition at line 2544 of file ccss.c.

2545 {
2546  struct ast_cc_agent *agent = data;
2547 
2548  if (agent->callbacks) {
2549  agent->callbacks->destructor(agent);
2550  }
2552 }
void ast_cc_config_params_destroy(struct ast_cc_config_params *params)
Free memory from CCSS configuration params.
Definition: ccss.c:694
void(* destructor)(struct ast_cc_agent *agent)
Destroy private data on the agent.
Definition: ccss.h:1051
const struct ast_cc_agent_callbacks * callbacks
Definition: ccss.h:833
struct ast_cc_config_params * cc_params
Definition: ccss.h:838

References ast_cc_config_params_destroy(), ast_cc_agent::callbacks, ast_cc_agent::cc_params, and ast_cc_agent_callbacks::destructor.

Referenced by cc_agent_init().

◆ agent_policy_to_str()

static const char* agent_policy_to_str ( enum ast_cc_agent_policies  policy)
static

Definition at line 729 of file ccss.c.

730 {
731  switch (policy) {
732  case AST_CC_AGENT_NEVER:
733  return "never";
734  case AST_CC_AGENT_NATIVE:
735  return "native";
737  return "generic";
738  default:
739  /* This should never happen... */
740  return "";
741  }
742 }
@ AST_CC_AGENT_NEVER
Definition: ccss.h:49
@ AST_CC_AGENT_GENERIC
Definition: ccss.h:53
@ AST_CC_AGENT_NATIVE
Definition: ccss.h:51

References AST_CC_AGENT_GENERIC, AST_CC_AGENT_NATIVE, and AST_CC_AGENT_NEVER.

Referenced by ast_cc_get_param().

◆ ast_cc_agent_accept_request()

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_idcore_id of the CC transaction
debugoptional string to print for debugging purposes
Return values
0Success
-1Failure

Definition at line 3774 of file ccss.c.

3775 {
3776  va_list ap;
3777  int res;
3778 
3779  va_start(ap, debug);
3780  res = cc_request_state_change(CC_CALLER_REQUESTED, core_id, debug, ap);
3781  va_end(ap);
3782  return res;
3783 }
static int cc_request_state_change(enum cc_state state, const int core_id, const char *debug, va_list ap)
Definition: ccss.c:3328
static int debug
Global debug status.
Definition: res_xmpp.c:441

References CC_CALLER_REQUESTED, cc_request_state_change(), dialed_cc_interfaces::core_id, and debug.

Referenced by ccreq_exec(), and handle_cc_subscribe().

◆ ast_cc_agent_callback()

struct ast_cc_agent* ast_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.

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
flagsastobj2 search flags
functionan ao2 callback function to call
argthe argument to the callback function
typeThe type of agents to call the callback on

Definition at line 457 of file ccss.c.

458 {
459  struct cc_callback_helper helper = {.function = function, .args = args, .type = type};
460  struct cc_core_instance *core_instance;
461  if ((core_instance = ao2_t_callback(cc_core_instances, flags, cc_agent_callback_helper, &helper,
462  "Calling provided agent callback function"))) {
463  struct ast_cc_agent *agent = cc_ref(core_instance->agent, "An outside entity needs the agent");
464  cc_unref(core_instance, "agent callback done with the core_instance");
465  return agent;
466  }
467  return NULL;
468 }
#define ao2_t_callback(c, flags, cb_fn, arg, tag)
Definition: astobj2.h:1696
static void * cc_ref(void *obj, const char *debug)
Definition: ccss.c:143
static void * cc_unref(void *obj, const char *debug)
Definition: ccss.c:149
static struct ao2_container * cc_core_instances
Definition: ccss.c:327
static int cc_agent_callback_helper(void *obj, void *args, int flags)
Definition: ccss.c:445
static const char type[]
Definition: chan_ooh323.c:109
ao2_callback_fn * function
Definition: ccss.c:440
struct ast_cc_agent * agent
Definition: ccss.c:341
const char * args

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

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

◆ ast_cc_agent_caller_available()

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_idcore_id of the CC transaction
debugoptional string to print for debugging purposes
Return values
0Success
-1Failure

Definition at line 3818 of file ccss.c.

3819 {
3820  va_list ap;
3821  int res;
3822 
3823  va_start(ap, debug);
3824  res = cc_request_state_change(CC_ACTIVE, core_id, debug, ap);
3825  va_end(ap);
3826  return res;
3827 }

References CC_ACTIVE, cc_request_state_change(), dialed_cc_interfaces::core_id, and debug.

Referenced by cc_esc_publish_handler(), and generic_agent_devstate_cb().

◆ ast_cc_agent_caller_busy()

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_idcore_id of the CC transaction
debugoptional string to print for debugging purposes
Return values
0Success
-1Failure

Definition at line 3807 of file ccss.c.

3808 {
3809  va_list ap;
3810  int res;
3811 
3812  va_start(ap, debug);
3813  res = cc_request_state_change(CC_CALLER_BUSY, core_id, debug, ap);
3814  va_end(ap);
3815  return res;
3816 }

References CC_CALLER_BUSY, cc_request_state_change(), dialed_cc_interfaces::core_id, and debug.

Referenced by cc_esc_publish_handler(), cc_generic_agent_recall(), and sip_cc_agent_recall().

◆ ast_cc_agent_recalling()

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_idcore_id of the CC transaction
debugoptional string to print for debugging purposes
Return values
0Success
-1Failure

Definition at line 3829 of file ccss.c.

3830 {
3831  va_list ap;
3832  int res;
3833 
3834  va_start(ap, debug);
3835  res = cc_request_state_change(CC_RECALLING, core_id, debug, ap);
3836  va_end(ap);
3837  return res;
3838 }

References CC_RECALLING, cc_request_state_change(), dialed_cc_interfaces::core_id, and debug.

Referenced by generic_recall().

◆ ast_cc_agent_register()

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
callbacksThe callbacks used by the agent implementation
Return values
0Successfully registered
-1Failure to register

Definition at line 1240 of file ccss.c.

1241 {
1242  struct cc_agent_backend *backend = ast_calloc(1, sizeof(*backend));
1243 
1244  if (!backend) {
1245  return -1;
1246  }
1247 
1248  backend->callbacks = callbacks;
1252  return 0;
1253 }
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:741
struct @498 callbacks
const struct ast_cc_agent_callbacks * callbacks
Definition: ccss.c:1235
struct cc_agent_backend * next
Definition: ccss.c:1234

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

Referenced by load_module().

◆ ast_cc_agent_set_interfaces_chanvar()

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
chanThe channel to set the CC_INTERFACES variable on

Definition at line 3629 of file ccss.c.

3630 {
3631  struct ast_datastore *recall_datastore;
3632  struct cc_monitor_tree *interface_tree;
3633  struct ast_cc_monitor *monitor;
3634  struct cc_recall_ds_data *recall_data;
3635  struct ast_str *str = ast_str_create(64);
3636  int core_id;
3637 
3638  if (!str) {
3639  return -1;
3640  }
3641 
3642  ast_channel_lock(chan);
3643  if (!(recall_datastore = ast_channel_datastore_find(chan, &recall_ds_info, NULL))) {
3644  ast_channel_unlock(chan);
3645  ast_free(str);
3646  return -1;
3647  }
3648  recall_data = recall_datastore->data;
3649  interface_tree = recall_data->interface_tree;
3650  core_id = recall_data->core_id;
3651  ast_channel_unlock(chan);
3652 
3653  AST_LIST_LOCK(interface_tree);
3654  monitor = AST_LIST_FIRST(interface_tree);
3655  build_cc_interfaces_chanvar(monitor, &str);
3656  AST_LIST_UNLOCK(interface_tree);
3657 
3658  pbx_builtin_setvar_helper(chan, "CC_INTERFACES", ast_str_buffer(str));
3659  ast_log_dynamic_level(cc_logger_level, "Core %d: CC_INTERFACES set to %s\n",
3660  core_id, ast_str_buffer(str));
3661 
3662  ast_free(str);
3663  return 0;
3664 }
const char * str
Definition: app_jack.c:147
#define ast_free(a)
Definition: astmm.h:180
static const struct ast_datastore_info recall_ds_info
Definition: ccss.c:3399
static void build_cc_interfaces_chanvar(struct ast_cc_monitor *starting_point, struct ast_str **str)
Definition: ccss.c:3586
static int cc_logger_level
Definition: ccss.c:133
#define ast_channel_lock(chan)
Definition: channel.h:2922
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2398
#define ast_channel_unlock(chan)
Definition: channel.h:2923
#define ast_log_dynamic_level(level,...)
Send a log message to a dynamically registered log level.
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:40
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:140
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:421
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:739
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:640
Structure for a data store object.
Definition: datastore.h:64
void * data
Definition: datastore.h:66
Support for dynamic strings.
Definition: strings.h:604
The "tree" of interfaces that is dialed.
Definition: ccss.c:324
struct cc_monitor_tree * interface_tree
Definition: ccss.c:3375

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_logger_level, cc_recall_ds_data::core_id, ast_datastore::data, cc_recall_ds_data::interface_tree, NULL, pbx_builtin_setvar_helper(), recall_ds_info, and str.

Referenced by generic_recall(), and handle_request_invite().

◆ ast_cc_agent_status_response()

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_idThe core ID of the CC transaction
devstateThe current state of the caller to which the agent pertains
Return values
0Successfully responded with our status
-1Failed to respond with our status

Definition at line 4091 of file ccss.c.

4092 {
4093  struct cc_status_response_args *args;
4094  struct cc_core_instance *core_instance;
4095  int res;
4096 
4097  args = ast_calloc(1, sizeof(*args));
4098  if (!args) {
4099  return -1;
4100  }
4101 
4102  core_instance = find_cc_core_instance(core_id);
4103  if (!core_instance) {
4104  ast_free(args);
4105  return -1;
4106  }
4107 
4108  args->core_instance = core_instance;
4109  args->devstate = devstate;
4110 
4112  if (res) {
4113  cc_unref(core_instance, "Unref core instance. ast_taskprocessor_push failed");
4114  ast_free(args);
4115  }
4116  return res;
4117 }
static struct cc_core_instance * find_cc_core_instance(const int core_id)
Definition: ccss.c:432
static struct ast_taskprocessor * cc_core_taskprocessor
Definition: ccss.c:125
static int cc_status_response(void *data)
Definition: ccss.c:4070
int ast_taskprocessor_push(struct ast_taskprocessor *tps, int(*task_exe)(void *datap), void *datap) attribute_warn_unused_result
Push a task into the specified taskprocessor queue and signal the taskprocessor thread.

References args, ast_calloc, ast_free, ast_taskprocessor_push(), cc_core_taskprocessor, cc_status_response(), cc_unref(), cc_core_instance::core_id, and find_cc_core_instance().

Referenced by cc_generic_agent_status_request(), and sip_cc_agent_status_request().

◆ ast_cc_agent_unregister()

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
callbacksThe callbacks used by the agent implementation

Definition at line 1255 of file ccss.c.

1256 {
1257  struct cc_agent_backend *backend;
1260  if (backend->callbacks == callbacks) {
1262  ast_free(backend);
1263  break;
1264  }
1265  }
1268 }
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:570
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617

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, callbacks, and cc_agent_backend::next.

Referenced by __unload_module(), and unload_module().

◆ ast_cc_available_timer_expire()

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
dataA reference to the CC monitor on which the timer was running.

Definition at line 1510 of file ccss.c.

1511 {
1512  struct ast_cc_monitor *monitor = (struct ast_cc_monitor *) data;
1513  int res;
1514  monitor->available_timer_id = -1;
1515  res = ast_cc_monitor_failed(monitor->core_id, monitor->interface->device_name, "Available timer expired for monitor");
1516  cc_unref(monitor, "Unref reference from scheduler\n");
1517  return res;
1518 }
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.
Definition: ccss.c:3939
char device_name[1]
Definition: ccss.h:818
struct ast_cc_interface * interface
Definition: ccss.h:496
int core_id
Definition: ccss.h:510
int available_timer_id
Definition: ccss.h:529

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

Referenced by cc_generic_monitor_request_cc(), and sip_cc_monitor_request_cc().

◆ ast_cc_build_frame()

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
chanA channel involved in the call. What we want is on a datastore on both incoming and outgoing so either may be provided
cc_paramsThe CC configuration parameters for the outbound target
monitor_typeThe type of monitor to use when CC is requested
device_nameThe name of the outbound target device.
dialstringThe dial string used when calling this specific interface
serviceWhat kind of CC service is being offered. (CCBS/CCNR/etc...)
private_dataIf 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]frameThe 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
-1Failure. At some point there was a failure. Do not attempt to use the frame in this case.
0Success

Definition at line 4174 of file ccss.c.

4178 {
4179  struct cc_control_payload *payload = ast_calloc(1, sizeof(*payload));
4180 
4181  if (!payload) {
4182  return -1;
4183  }
4184  if (cc_build_payload(chan, cc_params, monitor_type, device_name, dialstring, service, private_data, payload)) {
4185  /* Something screwed up, we can't make a frame with this */
4186  ast_free(payload);
4187  return -1;
4188  }
4189  frame->frametype = AST_FRAME_CONTROL;
4190  frame->subclass.integer = AST_CONTROL_CC;
4191  frame->data.ptr = payload;
4192  frame->datalen = sizeof(*payload);
4193  frame->mallocd = AST_MALLOCD_DATA;
4194  return 0;
4195 }
enum ast_cc_service_type service
Definition: ccss.c:384
static int cc_build_payload(struct ast_channel *chan, struct ast_cc_config_params *cc_params, const char *monitor_type, const char *const device_name, const char *dialstring, enum ast_cc_service_type service, void *private_data, struct cc_control_payload *payload)
Definition: ccss.c:4119
#define AST_MALLOCD_DATA
@ AST_FRAME_CONTROL
@ AST_CONTROL_CC
struct ast_frame_subclass subclass
union ast_frame::@254 data
enum ast_frame_type frametype
The payload for an AST_CONTROL_CC frame.
Definition: ccss.c:222
const char * monitor_type
The type of monitor to allocate.
Definition: ccss.c:240
char device_name[AST_CHANNEL_NAME]
Name of device to be monitored.
Definition: ccss.c:293
char dialstring[AST_CHANNEL_NAME]
Recall dialstring.
Definition: ccss.c:305
void * private_data
Private data allocated by the callee.
Definition: ccss.c:257

References ast_calloc, AST_CONTROL_CC, AST_FRAME_CONTROL, ast_free, AST_MALLOCD_DATA, cc_build_payload(), ast_frame::data, ast_frame::datalen, cc_control_payload::device_name, cc_control_payload::dialstring, ast_frame::frametype, ast_frame_subclass::integer, ast_frame::mallocd, cc_control_payload::monitor_type, cc_control_payload::private_data, ast_frame::ptr, service, and ast_frame::subclass.

Referenced by ast_queue_cc_frame().

◆ ast_cc_busy_interface()

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
inboundIncoming asterisk channel.
cc_paramsThe CC configuration parameters for the outbound target
monitor_typeThe type of monitor to use when CC is requested
device_nameThe name of the outbound target device.
dialstringThe dial string used when calling this specific interface
private_dataIf 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 4230 of file ccss.c.

4232 {
4233  struct cc_control_payload payload;
4234  if (cc_build_payload(inbound, cc_params, monitor_type, device_name, dialstring, AST_CC_CCBS, private_data, &payload)) {
4235  /* Something screwed up. Don't try to handle this payload */
4237  return;
4238  }
4239  ast_handle_cc_control_frame(inbound, NULL, &payload);
4240 }
void ast_handle_cc_control_frame(struct ast_channel *inbound, struct ast_channel *outbound, void *frame_data)
Properly react to a CC control frame.
Definition: ccss.c:2316
static void call_destructor_with_no_monitor(const char *const monitor_type, void *private_data)
Definition: ccss.c:2215
@ AST_CC_CCBS
Definition: ccss.h:36

References AST_CC_CCBS, ast_handle_cc_control_frame(), call_destructor_with_no_monitor(), cc_build_payload(), cc_control_payload::device_name, cc_control_payload::dialstring, cc_control_payload::monitor_type, NULL, and cc_control_payload::private_data.

Referenced by dial_exec_full().

◆ ast_cc_call_failed()

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 4197 of file ccss.c.

4198 {
4199  char device_name[AST_CHANNEL_NAME];
4200  struct cc_control_payload payload;
4201  struct ast_cc_config_params *cc_params;
4202 
4204  /* It doesn't make sense to try to offer CCBS to the caller if the reason for ast_call
4205  * failing is something other than busy or congestion
4206  */
4207  return;
4208  }
4209 
4211  if (!cc_params) {
4212  return;
4213  }
4215  /* This sort of CCBS only works if using generic CC. For native, we would end up sending
4216  * a CC request for a non-existent call. The far end will reject this every time
4217  */
4218  return;
4219  }
4220 
4221  ast_channel_get_device_name(outgoing, device_name, sizeof(device_name));
4222  if (cc_build_payload(outgoing, cc_params, AST_CC_GENERIC_MONITOR_TYPE, device_name,
4223  dialstring, AST_CC_CCBS, NULL, &payload)) {
4224  /* Something screwed up, we can't make a frame with this */
4225  return;
4226  }
4227  ast_handle_cc_control_frame(incoming, outgoing, &payload);
4228 }
#define AST_CAUSE_CONGESTION
Definition: causes.h:153
#define AST_CAUSE_BUSY
Definition: causes.h:149
enum ast_cc_monitor_policies ast_get_cc_monitor_policy(struct ast_cc_config_params *config)
Get the cc_monitor_policy.
Definition: ccss.c:884
#define AST_CC_GENERIC_MONITOR_TYPE
Definition: ccss.h:471
@ AST_CC_MONITOR_GENERIC
Definition: ccss.h:83
int ast_channel_get_device_name(struct ast_channel *chan, char *device_name, size_t name_buffer_length)
Get a device name given its channel structure.
Definition: channel.c:10682
struct ast_cc_config_params * ast_channel_get_cc_config_params(struct ast_channel *chan)
Get the CCSS parameters from a channel.
Definition: channel.c:10660
int ast_channel_hangupcause(const struct ast_channel *chan)
#define AST_CHANNEL_NAME
Definition: channel.h:171

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(), cc_control_payload::device_name, and NULL.

Referenced by dial_exec_full().

◆ ast_cc_call_init()

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
chanThe inbound channel calling the CC-capable application.
[out]ignore_ccWill be set non-zero if no further CC actions need to be taken
Return values
0Success
-1Failure

Definition at line 2409 of file ccss.c.

2410 {
2411  /* There are three situations to deal with here:
2412  *
2413  * 1. The channel does not have a dialed_cc_interfaces datastore on
2414  * it. This means that this is the first time that Dial has
2415  * been called. We need to create/initialize the datastore.
2416  *
2417  * 2. The channel does have a cc_interface datastore on it and
2418  * the "ignore" indicator is 0. This means that a Local channel
2419  * was called by a "parent" dial. We can check the datastore's
2420  * parent field to see who the root of this particular dial tree
2421  * is.
2422  *
2423  * 3. The channel does have a cc_interface datastore on it and
2424  * the "ignore" indicator is 1. This means that a second Dial call
2425  * is being made from an extension. In this case, we do not
2426  * want to make any additions/modifications to the datastore. We
2427  * will instead set a flag to indicate that CCSS is completely
2428  * disabled for this Dial attempt.
2429  */
2430 
2431  struct ast_datastore *cc_interfaces_datastore;
2433  struct ast_cc_monitor *monitor;
2434  struct ast_cc_config_params *cc_params;
2435 
2436  ast_channel_lock(chan);
2437 
2438  cc_params = ast_channel_get_cc_config_params(chan);
2439  if (!cc_params) {
2440  ast_channel_unlock(chan);
2441  return -1;
2442  }
2443  if (ast_get_cc_agent_policy(cc_params) == AST_CC_AGENT_NEVER) {
2444  /* We can't offer CC to this caller anyway, so don't bother with CC on this call
2445  */
2446  *ignore_cc = 1;
2447  ast_channel_unlock(chan);
2448  ast_log_dynamic_level(cc_logger_level, "Agent policy for %s is 'never'. CC not possible\n", ast_channel_name(chan));
2449  return 0;
2450  }
2451 
2452  if (!(cc_interfaces_datastore = ast_channel_datastore_find(chan, &dialed_cc_interfaces_info, NULL))) {
2453  /* Situation 1 has occurred */
2454  ast_channel_unlock(chan);
2455  return cc_interfaces_datastore_init(chan);
2456  }
2457  interfaces = cc_interfaces_datastore->data;
2458  ast_channel_unlock(chan);
2459 
2460  if (interfaces->ignore) {
2461  /* Situation 3 has occurred */
2462  *ignore_cc = 1;
2463  ast_log_dynamic_level(cc_logger_level, "Datastore is present with ignore flag set. Ignoring CC offers on this call\n");
2464  return 0;
2465  }
2466 
2467  /* Situation 2 has occurred */
2469  S_OR(ast_channel_macrocontext(chan), ast_channel_context(chan)), interfaces->dial_parent_id))) {
2470  return -1;
2471  }
2472  monitor->core_id = interfaces->core_id;
2473  AST_LIST_LOCK(interfaces->interface_tree);
2474  cc_ref(monitor, "monitor tree's reference to the monitor");
2475  AST_LIST_INSERT_TAIL(interfaces->interface_tree, monitor, next);
2476  AST_LIST_UNLOCK(interfaces->interface_tree);
2477  interfaces->dial_parent_id = monitor->id;
2478  cc_unref(monitor, "Unref monitor's allocation reference");
2479  return 0;
2480 }
static const struct ast_datastore_info dialed_cc_interfaces_info
Definition: ccss.c:1990
enum ast_cc_agent_policies ast_get_cc_agent_policy(struct ast_cc_config_params *config)
Get the cc_agent_policy.
Definition: ccss.c:867
static int cc_interfaces_datastore_init(struct ast_channel *chan)
Definition: ccss.c:2139
static struct ast_cc_monitor * cc_extension_monitor_init(const char *const exten, const char *const context, const unsigned int parent_id)
Definition: ccss.c:2090
const char * ast_channel_context(const struct ast_channel *chan)
const char * ast_channel_name(const struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
const char * ast_channel_macroexten(const struct ast_channel *chan)
const char * ast_channel_macrocontext(const struct ast_channel *chan)
static struct ao2_container * interfaces
Container for registered format interfaces.
Definition: format.c:65
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
unsigned int id
Definition: ccss.h:501

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_logger_level, cc_ref(), cc_unref(), ast_cc_monitor::core_id, ast_datastore::data, dialed_cc_interfaces_info, ast_cc_monitor::id, interfaces, NULL, and S_OR.

Referenced by dial_exec_full().

◆ ast_cc_callback()

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
techChannel technology to use
destChannel/group/peer or whatever the specific technology uses
callbackFunction to call when a target is reached
Return values
0Always, I guess.

Definition at line 4242 of file ccss.c.

4243 {
4244  const struct ast_channel_tech *chantech = ast_get_channel_tech(tech);
4245 
4246  if (chantech && chantech->cc_callback) {
4247  chantech->cc_callback(inbound, dest, callback);
4248  }
4249 
4250  return 0;
4251 }
const struct ast_channel_tech * ast_get_channel_tech(const char *name)
Get a channel technology structure by name.
Definition: channel.c:592
Structure to describe a channel "technology", ie a channel driver See for examples:
Definition: channel.h:628
int(* cc_callback)(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback)
Call a function with cc parameters as a function parameter.
Definition: channel.h:827

References ast_get_channel_tech(), and ast_channel_tech::cc_callback.

Referenced by dial_exec_full().

◆ ast_cc_completed()

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
chanThe inbound channel making the CC recall
debugoptional string to print for debugging purposes
Return values
0Success
-1Failure

Definition at line 3840 of file ccss.c.

3841 {
3842  struct ast_datastore *recall_datastore;
3843  struct cc_recall_ds_data *recall_data;
3844  int core_id;
3845  va_list ap;
3846  int res;
3847 
3848  ast_channel_lock(chan);
3849  if (!(recall_datastore = ast_channel_datastore_find(chan, &recall_ds_info, NULL))) {
3850  /* Silly! Why did you call this function if there's no recall DS? */
3851  ast_channel_unlock(chan);
3852  return -1;
3853  }
3854  recall_data = recall_datastore->data;
3855  if (recall_data->nested || recall_data->ignore) {
3856  /* If this is being called from a nested Dial, it is too
3857  * early to determine if the recall has actually completed.
3858  * The outermost dial is the only one with the authority to
3859  * declare the recall to be complete.
3860  *
3861  * Similarly, if this function has been called when the
3862  * recall has progressed beyond the first dial, this is not
3863  * a legitimate time to declare the recall to be done. In fact,
3864  * that should have been done already.
3865  */
3866  ast_channel_unlock(chan);
3867  return -1;
3868  }
3869  core_id = recall_data->core_id;
3870  ast_channel_unlock(chan);
3871  va_start(ap, debug);
3873  va_end(ap);
3874  return res;
3875 }

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, debug, cc_recall_ds_data::ignore, cc_recall_ds_data::nested, NULL, and recall_ds_info.

Referenced by wait_for_answer().

◆ ast_cc_config_params_destroy()

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
paramsPointer to structure whose memory we need to free

Definition at line 694 of file ccss.c.

695 {
696  ast_free(params);
697 }

References ast_free.

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

◆ ast_cc_copy_config_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

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
srcThe structure from which data is copied
destThe structure to which data is copied

Definition at line 862 of file ccss.c.

863 {
864  *dest = *src;
865 }

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

◆ ast_cc_default_config_params()

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
paramsCC config params to set to default values.

Definition at line 677 of file ccss.c.

678 {
679  *params = cc_default_params;
680 }
static const struct ast_cc_config_params cc_default_params
Definition: ccss.c:663

References cc_default_params.

Referenced by __ast_cc_config_params_init().

◆ ast_cc_extension_monitor_add_dialstring()

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
incomingThe caller's channel
dialstringThe dialstring used when requesting the outbound channel
device_nameThe device name associated with the requested outbound channel

Definition at line 2006 of file ccss.c.

2007 {
2008  struct ast_datastore *cc_datastore;
2009  struct dialed_cc_interfaces *cc_interfaces;
2010  struct ast_cc_monitor *monitor;
2011  struct extension_monitor_pvt *extension_pvt;
2012  struct extension_child_dialstring *child_dialstring;
2013  struct cc_monitor_tree *interface_tree;
2014  int id;
2015 
2016  ast_channel_lock(incoming);
2017  if (!(cc_datastore = ast_channel_datastore_find(incoming, &dialed_cc_interfaces_info, NULL))) {
2018  ast_channel_unlock(incoming);
2019  return;
2020  }
2021 
2022  cc_interfaces = cc_datastore->data;
2023  interface_tree = cc_interfaces->interface_tree;
2024  id = cc_interfaces->dial_parent_id;
2025  ast_channel_unlock(incoming);
2026 
2027  AST_LIST_LOCK(interface_tree);
2028  AST_LIST_TRAVERSE(interface_tree, monitor, next) {
2029  if (monitor->id == id) {
2030  break;
2031  }
2032  }
2033 
2034  if (!monitor) {
2035  AST_LIST_UNLOCK(interface_tree);
2036  return;
2037  }
2038 
2039  extension_pvt = monitor->private_data;
2040  if (!(child_dialstring = ast_calloc(1, sizeof(*child_dialstring)))) {
2041  AST_LIST_UNLOCK(interface_tree);
2042  return;
2043  }
2044  ast_copy_string(child_dialstring->original_dialstring, dialstring, sizeof(child_dialstring->original_dialstring));
2045  ast_copy_string(child_dialstring->device_name, device_name, sizeof(child_dialstring->device_name));
2046  child_dialstring->is_valid = 1;
2047  AST_LIST_INSERT_TAIL(&extension_pvt->child_dialstrings, child_dialstring, next);
2048  AST_LIST_UNLOCK(interface_tree);
2049 }
enum queue_result id
Definition: app_queue.c:1640
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:406
void * private_data
Data that is private to a monitor technology.
Definition: ccss.h:543
struct cc_monitor_tree * interface_tree
Definition: ccss.c:1930
unsigned int dial_parent_id
Definition: ccss.c:1903
Data regarding an extension monitor's child's dialstrings.
Definition: ccss.c:1761
char device_name[AST_CHANNEL_NAME]
The name of the device being dialed.
Definition: ccss.c:1796
int is_valid
Is this structure valid for use in CC_INTERFACES?
Definition: ccss.c:1811
char original_dialstring[AST_CHANNEL_NAME]
the original dialstring used to call a particular device
Definition: ccss.c:1777
Private data for an extension monitor.
Definition: ccss.c:1818
struct extension_monitor_pvt::@356 child_dialstrings

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, dialed_cc_interfaces_info, id, ast_cc_monitor::id, dialed_cc_interfaces::interface_tree, extension_child_dialstring::is_valid, NULL, extension_child_dialstring::original_dialstring, and ast_cc_monitor::private_data.

Referenced by dial_exec_full().

◆ ast_cc_failed()

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_idcore_id of the CC transaction
debugoptional string to print for debugging purposes
Return values
0Success
-1Failure

Definition at line 3877 of file ccss.c.

3878 {
3879  va_list ap;
3880  int res;
3881 
3882  va_start(ap, debug);
3883  res = cc_request_state_change(CC_FAILED, core_id, debug, ap);
3884  va_end(ap);
3885  return res;
3886 }

References CC_FAILED, cc_request_state_change(), cc_recall_ds_data::core_id, and debug.

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().

◆ ast_cc_get_current_core_id()

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
chanThe channel from which to get the core_id.
Return values
core_idon success
-1Failure

Definition at line 2487 of file ccss.c.

2488 {
2489  struct ast_datastore *datastore;
2490  struct dialed_cc_interfaces *cc_interfaces;
2491  int core_id_return;
2492 
2493  ast_channel_lock(chan);
2494  if (!(datastore = ast_channel_datastore_find(chan, &dialed_cc_interfaces_info, NULL))) {
2495  ast_channel_unlock(chan);
2496  return -1;
2497  }
2498 
2499  cc_interfaces = datastore->data;
2500  core_id_return = cc_interfaces->ignore ? -1 : cc_interfaces->core_id;
2501  ast_channel_unlock(chan);
2502  return core_id_return;
2503 
2504 }

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

◆ ast_cc_get_monitor_by_recall_core_id()

struct ast_cc_monitor* ast_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.

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_idThe core ID to which this recall corresponds. This likely will have been obtained using the ast_cc_is_recall function
device_nameWhich device to find the monitor for.
Return values
NULLAppropriate monitor does not exist
non-NULLThe monitor to use for this recall

Definition at line 3519 of file ccss.c.

3520 {
3521  struct cc_core_instance *core_instance = find_cc_core_instance(core_id);
3522  struct ast_cc_monitor *monitor_iter;
3523 
3524  if (!core_instance) {
3525  return NULL;
3526  }
3527 
3528  AST_LIST_LOCK(core_instance->monitors);
3529  AST_LIST_TRAVERSE(core_instance->monitors, monitor_iter, next) {
3530  if (!strcmp(monitor_iter->interface->device_name, device_name)) {
3531  /* Found a monitor. */
3532  cc_ref(monitor_iter, "Hand the requester of the monitor a reference");
3533  break;
3534  }
3535  }
3536  AST_LIST_UNLOCK(core_instance->monitors);
3537  cc_unref(core_instance, "Done with core instance ref in ast_cc_get_monitor_by_recall_core_id");
3538  return monitor_iter;
3539 }
struct ast_cc_monitor * next
Definition: ccss.h:544
struct cc_monitor_tree * monitors
Definition: ccss.c:345

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

Referenced by sip_call().

◆ ast_cc_get_param()

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
paramsThe CCSS configuration from which to get the value
nameThe name of the CCSS parameter we want
bufA preallocated buffer to hold the value
buf_lenThe size of buf
Return values
0Success
-1Failure

Definition at line 760 of file ccss.c.

762 {
763  const char *value = NULL;
764 
765  if (!strcasecmp(name, "cc_callback_macro")) {
767  } else if (!strcasecmp(name, "cc_callback_sub")) {
768  value = ast_get_cc_callback_sub(params);
769  } else if (!strcasecmp(name, "cc_agent_policy")) {
771  } else if (!strcasecmp(name, "cc_monitor_policy")) {
773  } else if (!strcasecmp(name, "cc_agent_dialstring")) {
775  }
776  if (value) {
777  ast_copy_string(buf, value, buf_len);
778  return 0;
779  }
780 
781  /* The rest of these are all ints of some sort and require some
782  * snprintf-itude
783  */
784 
785  if (!strcasecmp(name, "cc_offer_timer")) {
786  snprintf(buf, buf_len, "%u", ast_get_cc_offer_timer(params));
787  } else if (!strcasecmp(name, "ccnr_available_timer")) {
788  snprintf(buf, buf_len, "%u", ast_get_ccnr_available_timer(params));
789  } else if (!strcasecmp(name, "ccbs_available_timer")) {
790  snprintf(buf, buf_len, "%u", ast_get_ccbs_available_timer(params));
791  } else if (!strcasecmp(name, "cc_max_agents")) {
792  snprintf(buf, buf_len, "%u", ast_get_cc_max_agents(params));
793  } else if (!strcasecmp(name, "cc_max_monitors")) {
794  snprintf(buf, buf_len, "%u", ast_get_cc_max_monitors(params));
795  } else if (!strcasecmp(name, "cc_recall_timer")) {
796  snprintf(buf, buf_len, "%u", ast_get_cc_recall_timer(params));
797  } else {
798  ast_log(LOG_WARNING, "%s is not a valid CC parameter. Ignoring.\n", name);
799  return -1;
800  }
801 
802  return 0;
803 }
#define ast_log
Definition: astobj2.c:42
unsigned int ast_get_cc_recall_timer(struct ast_cc_config_params *config)
Get the cc_recall_timer.
Definition: ccss.c:931
static const char * monitor_policy_to_str(enum ast_cc_monitor_policies policy)
Definition: ccss.c:744
unsigned int ast_get_cc_offer_timer(struct ast_cc_config_params *config)
Get the cc_offer_timer.
Definition: ccss.c:901
const char * ast_get_cc_agent_dialstring(struct ast_cc_config_params *config)
Get the cc_agent_dialstring.
Definition: ccss.c:961
unsigned int ast_get_ccbs_available_timer(struct ast_cc_config_params *config)
Get the ccbs_available_timer.
Definition: ccss.c:946
const char * ast_get_cc_callback_macro(struct ast_cc_config_params *config)
Get the name of the callback_macro.
Definition: ccss.c:995
unsigned int ast_get_ccnr_available_timer(struct ast_cc_config_params *config)
Get the ccnr_available_timer.
Definition: ccss.c:916
unsigned int ast_get_cc_max_agents(struct ast_cc_config_params *config)
Get the cc_max_agents.
Definition: ccss.c:975
unsigned int ast_get_cc_max_monitors(struct ast_cc_config_params *config)
Get the cc_max_monitors.
Definition: ccss.c:985
static const char * agent_policy_to_str(enum ast_cc_agent_policies policy)
Definition: ccss.c:729
const char * ast_get_cc_callback_sub(struct ast_cc_config_params *config)
Get the name of the callback subroutine.
Definition: ccss.c:1000
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static const char name[]
Definition: format_mp3.c:68
#define LOG_WARNING
int value
Definition: syslog.c:37

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, buf, LOG_WARNING, monitor_policy_to_str(), name, NULL, and value.

Referenced by acf_cc_read().

◆ ast_cc_is_config_param()

int ast_cc_is_config_param ( const char *const  name)

Is this a CCSS configuration parameter?

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

Definition at line 847 of file ccss.c.

848 {
849  return (!strcasecmp(name, "cc_agent_policy") ||
850  !strcasecmp(name, "cc_monitor_policy") ||
851  !strcasecmp(name, "cc_offer_timer") ||
852  !strcasecmp(name, "ccnr_available_timer") ||
853  !strcasecmp(name, "ccbs_available_timer") ||
854  !strcasecmp(name, "cc_max_agents") ||
855  !strcasecmp(name, "cc_max_monitors") ||
856  !strcasecmp(name, "cc_callback_macro") ||
857  !strcasecmp(name, "cc_callback_sub") ||
858  !strcasecmp(name, "cc_agent_dialstring") ||
859  !strcasecmp(name, "cc_recall_timer"));
860 }

References name.

Referenced by build_peer(), and process_dahdi().

◆ ast_cc_is_recall()

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
chanThe channel to check
[out]core_idIf this is a valid CC recall, the core_id of the failed call will be placed in this output parameter
monitor_typeClarify 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
0Either this is not a recall or it is but this channel is not part of the recall
non-zeroThis is a recall and the channel in question is directly involved.

Definition at line 3438 of file ccss.c.

3439 {
3440  struct ast_datastore *recall_datastore;
3441  struct cc_recall_ds_data *recall_data;
3442  struct cc_monitor_tree *interface_tree;
3443  char device_name[AST_CHANNEL_NAME];
3444  struct ast_cc_monitor *device_monitor;
3445  int core_id_candidate;
3446 
3447  ast_assert(core_id != NULL);
3448 
3449  *core_id = -1;
3450 
3451  ast_channel_lock(chan);
3452  if (!(recall_datastore = ast_channel_datastore_find(chan, &recall_ds_info, NULL))) {
3453  /* Obviously not a recall if the datastore isn't present */
3454  ast_channel_unlock(chan);
3455  return 0;
3456  }
3457 
3458  recall_data = recall_datastore->data;
3459 
3460  if (recall_data->ignore) {
3461  /* Though this is a recall, the call to this particular interface is not part of the
3462  * recall either because this is a call forward or because this is not the first
3463  * invocation of Dial during this call
3464  */
3465  ast_channel_unlock(chan);
3466  return 0;
3467  }
3468 
3469  if (!recall_data->nested) {
3470  /* If the nested flag is not set, then this means that
3471  * the channel passed to this function is the caller making
3472  * the recall. This means that we shouldn't look through
3473  * the monitor tree for the channel because it shouldn't be
3474  * there. However, this is a recall though, so return true.
3475  */
3476  *core_id = recall_data->core_id;
3477  ast_channel_unlock(chan);
3478  return 1;
3479  }
3480 
3481  if (ast_strlen_zero(monitor_type)) {
3482  /* If someone passed a NULL or empty monitor type, then it is clear
3483  * the channel they passed in was an incoming channel, and so searching
3484  * the list of dialed interfaces is not going to be helpful. Just return
3485  * false immediately.
3486  */
3487  ast_channel_unlock(chan);
3488  return 0;
3489  }
3490 
3491  interface_tree = recall_data->interface_tree;
3492  ast_channel_get_device_name(chan, device_name, sizeof(device_name));
3493  /* We grab the value of the recall_data->core_id so that we
3494  * can unlock the channel before we start looking through the
3495  * interface list. That way we don't have to worry about a possible
3496  * clash between the channel lock and the monitor tree lock.
3497  */
3498  core_id_candidate = recall_data->core_id;
3499  ast_channel_unlock(chan);
3500 
3501  /*
3502  * Now we need to find out if the channel device name
3503  * is in the list of interfaces in the called tree.
3504  */
3505  AST_LIST_LOCK(interface_tree);
3506  AST_LIST_TRAVERSE(interface_tree, device_monitor, next) {
3507  if (!strcmp(device_monitor->interface->device_name, device_name) &&
3508  !strcmp(device_monitor->interface->monitor_type, monitor_type)) {
3509  /* BOOM! Device is in the tree! We have a winner! */
3510  *core_id = core_id_candidate;
3511  AST_LIST_UNLOCK(interface_tree);
3512  return 1;
3513  }
3514  }
3515  AST_LIST_UNLOCK(interface_tree);
3516  return 0;
3517 }
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
const char * monitor_type
The type of monitor that should be used for this interface.
Definition: ccss.h:809
#define ast_assert(a)
Definition: utils.h:734

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(), ast_cc_monitor::core_id, 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, ast_cc_monitor::next, NULL, and recall_ds_info.

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

◆ ast_cc_monitor_callee_available()

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
0Request successfully queued
-1Request could not be queued

Definition at line 3796 of file ccss.c.

3797 {
3798  va_list ap;
3799  int res;
3800 
3801  va_start(ap, debug);
3802  res = cc_request_state_change(CC_CALLEE_READY, core_id, debug, ap);
3803  va_end(ap);
3804  return res;
3805 }

References CC_CALLEE_READY, cc_request_state_change(), dialed_cc_interfaces::core_id, and debug.

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

◆ ast_cc_monitor_count()

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
nameThe name of the monitored device
typeThe type of the monitored device (e.g. "generic")
Returns
The number of CC requests for the monitor

Definition at line 4366 of file ccss.c.

4367 {
4368  struct count_monitors_cb_data data = {.device_name = name, .monitor_type = type,};
4369 
4370  ao2_t_callback(cc_core_instances, OBJ_NODATA, count_monitors_cb, &data, "Counting agents");
4371  ast_log_dynamic_level(cc_logger_level, "Counted %d monitors\n", data.count);
4372  return data.count;
4373 }
@ OBJ_NODATA
Definition: astobj2.h:1044
static int count_monitors_cb(void *obj, void *arg, int flags)
Definition: ccss.c:4346
const char * device_name
Definition: ccss.c:4341

References ao2_t_callback, ast_log_dynamic_level, cc_core_instances, cc_logger_level, count_monitors_cb_data::count, count_monitors_cb(), count_monitors_cb_data::device_name, name, OBJ_NODATA, and type.

Referenced by ast_queue_cc_frame().

◆ ast_cc_monitor_failed()

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_idThe core ID for the CC transaction
monitor_nameThe name of the monitor on which the failure occurred
debugA debug message to print to the CC log

Definition at line 3939 of file ccss.c.

3940 {
3941  struct ast_cc_monitor_failure_data *failure_data;
3942  int res;
3943  va_list ap;
3944 
3945  if (!(failure_data = ast_calloc(1, sizeof(*failure_data)))) {
3946  return -1;
3947  }
3948 
3949  if (!(failure_data->device_name = ast_strdup(monitor_name))) {
3950  ast_free(failure_data);
3951  return -1;
3952  }
3953 
3954  va_start(ap, debug);
3955  if (ast_vasprintf(&failure_data->debug, debug, ap) == -1) {
3956  va_end(ap);
3957  ast_free((char *)failure_data->device_name);
3958  ast_free(failure_data);
3959  return -1;
3960  }
3961  va_end(ap);
3962 
3963  failure_data->core_id = core_id;
3964 
3966  if (res) {
3967  ast_free((char *)failure_data->device_name);
3968  ast_free((char *)failure_data->debug);
3969  ast_free(failure_data);
3970  }
3971  return res;
3972 }
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_vasprintf(ret, fmt, ap)
A wrapper for vasprintf()
Definition: astmm.h:278
static int cc_monitor_failed(void *data)
Definition: ccss.c:3894
const char * device_name
Definition: ccss.c:3889

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

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

◆ ast_cc_monitor_party_b_free()

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_idThe core ID of the CC transaction
Return values
0Successfully alerted the core that party B is free
-1Could not alert the core that party B is free

Definition at line 4049 of file ccss.c.

4050 {
4051  int res;
4052  struct cc_core_instance *core_instance = find_cc_core_instance(core_id);
4053 
4054  if (!core_instance) {
4055  return -1;
4056  }
4057 
4059  if (res) {
4060  cc_unref(core_instance, "Unref core instance. ast_taskprocessor_push failed");
4061  }
4062  return res;
4063 }
static int cc_party_b_free(void *data)
Definition: ccss.c:4037

References ast_taskprocessor_push(), cc_core_taskprocessor, cc_party_b_free(), cc_unref(), cc_core_instance::core_id, and find_cc_core_instance().

◆ ast_cc_monitor_register()

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
callbacksThe callbacks used by the monitor implementation
Return values
0Successfully registered
-1Failure to register

Definition at line 1185 of file ccss.c.

1186 {
1187  struct cc_monitor_backend *backend = ast_calloc(1, sizeof(*backend));
1188 
1189  if (!backend) {
1190  return -1;
1191  }
1192 
1193  backend->callbacks = callbacks;
1194 
1198  return 0;
1199 }
const struct ast_cc_monitor_callbacks * callbacks
Definition: ccss.c:1180
struct cc_monitor_backend * next
Definition: ccss.c:1179

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

Referenced by load_module().

◆ ast_cc_monitor_request_acked()

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_idcore_id of the CC transaction
debugoptional string to print for debugging purposes
Return values
0Success
-1Failure

Definition at line 3785 of file ccss.c.

3786 {
3787  va_list ap;
3788  int res;
3789 
3790  va_start(ap, debug);
3791  res = cc_request_state_change(CC_ACTIVE, core_id, debug, ap);
3792  va_end(ap);
3793  return res;
3794 }

References CC_ACTIVE, cc_request_state_change(), dialed_cc_interfaces::core_id, and debug.

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

◆ ast_cc_monitor_status_request()

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_idThe core ID of the CC transaction
Return values
0Successfully requested status
-1Failed to request status

Definition at line 3984 of file ccss.c.

3985 {
3986  int res;
3987  struct cc_core_instance *core_instance = find_cc_core_instance(core_id);
3988 
3989  if (!core_instance) {
3990  return -1;
3991  }
3992 
3994  if (res) {
3995  cc_unref(core_instance, "Unref core instance. ast_taskprocessor_push failed");
3996  }
3997  return res;
3998 }
static int cc_status_request(void *data)
Definition: ccss.c:3974

References ast_taskprocessor_push(), cc_core_taskprocessor, cc_status_request(), cc_unref(), cc_core_instance::core_id, and find_cc_core_instance().

◆ ast_cc_monitor_stop_ringing()

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_idThe core ID of the CC transaction
Return values
0Successfully requested for the phone to stop ringing
-1Could not request for the phone to stop ringing

Definition at line 4021 of file ccss.c.

4022 {
4023  int res;
4024  struct cc_core_instance *core_instance = find_cc_core_instance(core_id);
4025 
4026  if (!core_instance) {
4027  return -1;
4028  }
4029 
4031  if (res) {
4032  cc_unref(core_instance, "Unref core instance. ast_taskprocessor_push failed");
4033  }
4034  return res;
4035 }
static int cc_stop_ringing(void *data)
Definition: ccss.c:4000

References ast_taskprocessor_push(), cc_core_taskprocessor, cc_stop_ringing(), cc_unref(), cc_core_instance::core_id, and find_cc_core_instance().

◆ ast_cc_monitor_unregister()

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
callbacksThe callbacks used by the monitor implementation

Definition at line 1218 of file ccss.c.

1219 {
1220  struct cc_monitor_backend *backend;
1223  if (backend->callbacks == callbacks) {
1225  ast_free(backend);
1226  break;
1227  }
1228  }
1231 }

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, callbacks, and cc_monitor_backend::next.

Referenced by __unload_module(), and unload_module().

◆ ast_cc_offer()

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_chanThe calling channel
Return values
-1Error
0Success

Definition at line 3749 of file ccss.c.

3750 {
3751  int core_id;
3752  int res = -1;
3753  struct ast_datastore *datastore;
3754  struct dialed_cc_interfaces *cc_interfaces;
3755  char cc_is_offerable;
3756 
3757  ast_channel_lock(caller_chan);
3758  if (!(datastore = ast_channel_datastore_find(caller_chan, &dialed_cc_interfaces_info, NULL))) {
3759  ast_channel_unlock(caller_chan);
3760  return res;
3761  }
3762 
3763  cc_interfaces = datastore->data;
3764  cc_is_offerable = cc_interfaces->is_original_caller;
3765  core_id = cc_interfaces->core_id;
3766  ast_channel_unlock(caller_chan);
3767 
3768  if (cc_is_offerable) {
3769  res = cc_offer(core_id, "CC offered to caller %s", ast_channel_name(caller_chan));
3770  }
3771  return res;
3772 }
static int cc_offer(const int core_id, const char *const debug,...)
Definition: ccss.c:3738
char is_original_caller
Definition: ccss.c:1926

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_info, dialed_cc_interfaces::is_original_caller, and NULL.

Referenced by ast_hangup().

◆ ast_cc_request_is_within_limits()

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
0Not within the limits. Fail.
non-zeroWithin the limits. Success.

Definition at line 2482 of file ccss.c.

2483 {
2485 }
static unsigned int global_cc_max_requests
Definition: ccss.c:137
static int cc_request_count
Definition: ccss.c:141

References cc_request_count, and global_cc_max_requests.

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

◆ ast_cc_set_param()

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
paramsThe parameter structure to set the value on
nameThe name of the cc parameter
valueThe value of the parameter
Return values
0Success
-1Failure

Definition at line 805 of file ccss.c.

807 {
808  unsigned int value_as_uint;
809  if (!strcasecmp(name, "cc_agent_policy")) {
811  } else if (!strcasecmp(name, "cc_monitor_policy")) {
813  } else if (!strcasecmp(name, "cc_agent_dialstring")) {
815  } else if (!strcasecmp(name, "cc_callback_macro")) {
817  return 0;
818  } else if (!strcasecmp(name, "cc_callback_sub")) {
820  return 0;
821  }
822 
823  if (sscanf(value, "%30u", &value_as_uint) != 1) {
824  return -1;
825  }
826 
827  if (!strcasecmp(name, "cc_offer_timer")) {
828  ast_set_cc_offer_timer(params, value_as_uint);
829  } else if (!strcasecmp(name, "ccnr_available_timer")) {
830  ast_set_ccnr_available_timer(params, value_as_uint);
831  } else if (!strcasecmp(name, "ccbs_available_timer")) {
832  ast_set_ccbs_available_timer(params, value_as_uint);
833  } else if (!strcasecmp(name, "cc_max_agents")) {
834  ast_set_cc_max_agents(params, value_as_uint);
835  } else if (!strcasecmp(name, "cc_max_monitors")) {
836  ast_set_cc_max_monitors(params, value_as_uint);
837  } else if (!strcasecmp(name, "cc_recall_timer")) {
838  ast_set_cc_recall_timer(params, value_as_uint);
839  } else {
840  ast_log(LOG_WARNING, "%s is not a valid CC parameter. Ignoring.\n", name);
841  return -1;
842  }
843 
844  return 0;
845 }
int ast_set_cc_agent_policy(struct ast_cc_config_params *config, enum ast_cc_agent_policies value)
Set the cc_agent_policy.
Definition: ccss.c:872
void ast_set_cc_max_monitors(struct ast_cc_config_params *config, unsigned int value)
Set the cc_max_monitors.
Definition: ccss.c:990
void ast_set_ccbs_available_timer(struct ast_cc_config_params *config, unsigned int value)
Set the ccbs_available_timer.
Definition: ccss.c:951
void ast_set_cc_callback_sub(struct ast_cc_config_params *config, const char *const value)
Set the callback subroutine name.
Definition: ccss.c:1015
void ast_set_cc_callback_macro(struct ast_cc_config_params *config, const char *const value)
Set the callback_macro name.
Definition: ccss.c:1005
void ast_set_cc_agent_dialstring(struct ast_cc_config_params *config, const char *const value)
Set the cc_agent_dialstring.
Definition: ccss.c:966
void ast_set_cc_offer_timer(struct ast_cc_config_params *config, unsigned int value)
Set the cc_offer_timer.
Definition: ccss.c:906
void ast_set_cc_max_agents(struct ast_cc_config_params *config, unsigned int value)
Set the cc_max_agents.
Definition: ccss.c:980
static enum ast_cc_monitor_policies str_to_monitor_policy(const char *const value)
Definition: ccss.c:713
void ast_set_ccnr_available_timer(struct ast_cc_config_params *config, unsigned int value)
Set the ccnr_available_timer.
Definition: ccss.c:921
static enum ast_cc_agent_policies str_to_agent_policy(const char *const value)
Definition: ccss.c:699
int ast_set_cc_monitor_policy(struct ast_cc_config_params *config, enum ast_cc_monitor_policies value)
Set the cc_monitor_policy.
Definition: ccss.c:889
void ast_set_cc_recall_timer(struct ast_cc_config_params *config, unsigned int value)
Set the cc_recall_timer.
Definition: ccss.c:936

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, name, str_to_agent_policy(), str_to_monitor_policy(), and value.

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

◆ ast_get_cc_agent_dialstring()

const char* ast_get_cc_agent_dialstring ( struct ast_cc_config_params config)

Get the cc_agent_dialstring.

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

Definition at line 961 of file ccss.c.

962 {
963  return config->cc_agent_dialstring;
964 }
static const char config[]
Definition: chan_ooh323.c:111

References config.

Referenced by ast_cc_get_param(), and generic_recall().

◆ ast_get_cc_agent_policy()

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
configThe configuration to retrieve the policy from
Returns
The current cc_agent_policy for this configuration

Definition at line 862 of file ccss.c.

868 {
869  return config->cc_agent_policy;
870 }

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

◆ ast_get_cc_callback_macro()

const char* ast_get_cc_callback_macro ( struct ast_cc_config_params config)

Get the name of the callback_macro.

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

Definition at line 995 of file ccss.c.

996 {
997  return config->cc_callback_macro;
998 }

References config.

Referenced by ast_cc_get_param(), and generic_recall().

◆ ast_get_cc_callback_sub()

const char* ast_get_cc_callback_sub ( struct ast_cc_config_params config)

Get the name of the callback subroutine.

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

Definition at line 1000 of file ccss.c.

1001 {
1002  return config->cc_callback_sub;
1003 }

References config.

Referenced by ast_cc_get_param(), and generic_recall().

◆ ast_get_cc_max_agents()

unsigned int ast_get_cc_max_agents ( struct ast_cc_config_params config)

Get the cc_max_agents.

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

Definition at line 975 of file ccss.c.

976 {
977  return config->cc_max_agents;
978 }

References config.

Referenced by ast_cc_get_param(), and cc_core_init_instance().

◆ ast_get_cc_max_monitors()

unsigned int ast_get_cc_max_monitors ( struct ast_cc_config_params config)

Get the cc_max_monitors.

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

Definition at line 985 of file ccss.c.

986 {
987  return config->cc_max_monitors;
988 }

References config.

Referenced by ast_cc_get_param(), and ast_queue_cc_frame().

◆ ast_get_cc_monitor_policy()

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
configThe configuration to retrieve the cc_monitor_policy from
Returns
The cc_monitor_policy retrieved from the configuration

Definition at line 872 of file ccss.c.

885 {
886  return config->cc_monitor_policy;
887 }

References AST_CC_AGENT_GENERIC, config, and value.

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

◆ ast_get_cc_offer_timer()

unsigned int ast_get_cc_offer_timer ( struct ast_cc_config_params config)

Get the cc_offer_timer.

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

Definition at line 901 of file ccss.c.

902 {
903  return config->cc_offer_timer;
904 }

References config.

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

◆ ast_get_cc_recall_timer()

unsigned int ast_get_cc_recall_timer ( struct ast_cc_config_params config)

Get the cc_recall_timer.

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

Definition at line 931 of file ccss.c.

932 {
933  return config->cc_recall_timer;
934 }

References config.

Referenced by ast_cc_get_param(), and generic_recall().

◆ ast_get_ccbs_available_timer()

unsigned int ast_get_ccbs_available_timer ( struct ast_cc_config_params config)

Get the ccbs_available_timer.

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

Definition at line 946 of file ccss.c.

947 {
948  return config->ccbs_available_timer;
949 }

References config.

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

◆ ast_get_ccnr_available_timer()

unsigned int ast_get_ccnr_available_timer ( struct ast_cc_config_params config)

Get the ccnr_available_timer.

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

Definition at line 916 of file ccss.c.

917 {
918  return config->ccnr_available_timer;
919 }

References config.

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

◆ ast_handle_cc_control_frame()

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

Properly react to a CC control frame.

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.

2317 {
2318  char *device_name;
2319  char *dialstring;
2320  struct ast_cc_monitor *monitor;
2321  struct ast_datastore *cc_datastore;
2322  struct dialed_cc_interfaces *cc_interfaces;
2323  struct cc_control_payload *cc_data = frame_data;
2324  struct cc_core_instance *core_instance;
2325 
2326  device_name = cc_data->device_name;
2327  dialstring = cc_data->dialstring;
2328 
2329  ast_channel_lock(inbound);
2330  if (!(cc_datastore = ast_channel_datastore_find(inbound, &dialed_cc_interfaces_info, NULL))) {
2331  ast_log(LOG_WARNING, "Unable to retrieve CC datastore while processing CC frame from '%s'. CC services will be unavailable.\n", device_name);
2332  ast_channel_unlock(inbound);
2334  return;
2335  }
2336 
2337  cc_interfaces = cc_datastore->data;
2338 
2339  if (cc_interfaces->ignore) {
2340  ast_channel_unlock(inbound);
2342  return;
2343  }
2344 
2345  if (!cc_interfaces->is_original_caller) {
2346  /* If the is_original_caller is not set on the *inbound* channel, then
2347  * it must be a local channel. As such, we do not want to create a core instance
2348  * or an agent for the local channel. Instead, we want to pass this along to the
2349  * other side of the local channel so that the original caller can benefit.
2350  */
2351  ast_channel_unlock(inbound);
2352  ast_indicate_data(inbound, AST_CONTROL_CC, cc_data, sizeof(*cc_data));
2353  return;
2354  }
2355 
2356  core_instance = find_cc_core_instance(cc_interfaces->core_id);
2357  if (!core_instance) {
2358  core_instance = cc_core_init_instance(inbound, cc_interfaces->interface_tree,
2359  cc_interfaces->core_id, cc_data);
2360  if (!core_instance) {
2361  cc_interfaces->ignore = 1;
2362  ast_channel_unlock(inbound);
2364  return;
2365  }
2366  }
2367 
2368  ast_channel_unlock(inbound);
2369 
2370  /* Yeah this kind of sucks, but luckily most people
2371  * aren't dialing thousands of interfaces on every call
2372  *
2373  * This traversal helps us to not create duplicate monitors in
2374  * case a device queues multiple CC control frames.
2375  */
2376  AST_LIST_LOCK(cc_interfaces->interface_tree);
2377  AST_LIST_TRAVERSE(cc_interfaces->interface_tree, monitor, next) {
2378  if (!strcmp(monitor->interface->device_name, device_name)) {
2379  ast_log_dynamic_level(cc_logger_level, "Core %d: Device %s sent us multiple CC control frames. Ignoring those beyond the first.\n",
2380  core_instance->core_id, device_name);
2381  AST_LIST_UNLOCK(cc_interfaces->interface_tree);
2382  cc_unref(core_instance, "Returning early from ast_handle_cc_control_frame. Unref core_instance");
2384  return;
2385  }
2386  }
2387  AST_LIST_UNLOCK(cc_interfaces->interface_tree);
2388 
2389  if (!(monitor = cc_device_monitor_init(device_name, dialstring, cc_data, core_instance->core_id))) {
2390  ast_log(LOG_WARNING, "Unable to create CC device interface for '%s'. CC services will be unavailable on this interface.\n", device_name);
2391  cc_unref(core_instance, "Returning early from ast_handle_cc_control_frame. Unref core_instance");
2393  return;
2394  }
2395 
2396  AST_LIST_LOCK(cc_interfaces->interface_tree);
2397  cc_ref(monitor, "monitor tree's reference to the monitor");
2398  AST_LIST_INSERT_TAIL(cc_interfaces->interface_tree, monitor, next);
2399  AST_LIST_UNLOCK(cc_interfaces->interface_tree);
2400 
2401  cc_extension_monitor_change_is_valid(core_instance, monitor->parent_id, monitor->interface->device_name, 0);
2402 
2403  cc_publish_available(cc_interfaces->core_id, device_name, cc_service_to_string(cc_data->service));
2404 
2405  cc_unref(core_instance, "Done with core_instance after handling CC control frame");
2406  cc_unref(monitor, "Unref reference from allocating monitor");
2407 }
static void cc_publish_available(int core_id, const char *callee, const char *service)
Definition: ccss.c:1064
static struct ast_cc_monitor * cc_device_monitor_init(const char *const device_name, const char *const dialstring, const struct cc_control_payload *cc_data, int core_id)
Definition: ccss.c:2250
static struct cc_core_instance * cc_core_init_instance(struct ast_channel *caller_chan, struct cc_monitor_tree *called_tree, const int core_id, struct cc_control_payload *cc_data)
Definition: ccss.c:2940
static void cc_extension_monitor_change_is_valid(struct cc_core_instance *core_instance, unsigned int parent_id, const char *const device_name, int is_valid)
Definition: ccss.c:2051
static const char * cc_service_to_string(enum ast_cc_service_type service)
Definition: ccss.c:413
int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen)
Indicates condition of channel, with payload.
Definition: channel.c:4688
unsigned int parent_id
Definition: ccss.h:506
enum ast_cc_service_type service
Service offered by the endpoint.
Definition: ccss.c:266

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_logger_level, 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, dialed_cc_interfaces_info, ast_cc_monitor::dialstring, cc_control_payload::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, 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().

◆ ast_ignore_cc()

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
chanThe channel for which further CC processing should be ignored.

Definition at line 3718 of file ccss.c.

3719 {
3720  struct ast_datastore *cc_datastore;
3721  struct ast_datastore *cc_recall_datastore;
3722  struct dialed_cc_interfaces *cc_interfaces;
3723  struct cc_recall_ds_data *recall_cc_data;
3724 
3725  ast_channel_lock(chan);
3726  if ((cc_datastore = ast_channel_datastore_find(chan, &dialed_cc_interfaces_info, NULL))) {
3727  cc_interfaces = cc_datastore->data;
3728  cc_interfaces->ignore = 1;
3729  }
3730 
3731  if ((cc_recall_datastore = ast_channel_datastore_find(chan, &recall_ds_info, NULL))) {
3732  recall_cc_data = cc_recall_datastore->data;
3733  recall_cc_data->ignore = 1;
3734  }
3735  ast_channel_unlock(chan);
3736 }

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

Referenced by dial_exec_full(), and do_forward().

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 4701 of file ccss.c.

◆ ast_queue_cc_frame()

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
chanThe channel onto which to queue the frame
monitor_typeThe type of monitor to use when CC is requested
dialstringThe dial string used to call the device
serviceThe type of CC service the device is willing to offer
private_dataIf 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
0Success
-1Error

Definition at line 4147 of file ccss.c.

4149 {
4150  struct ast_frame frame = {0,};
4151  char device_name[AST_CHANNEL_NAME];
4152  int retval;
4153  struct ast_cc_config_params *cc_params;
4154 
4155  cc_params = ast_channel_get_cc_config_params(chan);
4156  if (!cc_params) {
4157  return -1;
4158  }
4159  ast_channel_get_device_name(chan, device_name, sizeof(device_name));
4160  if (ast_cc_monitor_count(device_name, monitor_type) >= ast_get_cc_max_monitors(cc_params)) {
4161  ast_log(LOG_NOTICE, "Not queuing a CC frame for device %s since it already has its maximum monitors allocated\n", device_name);
4162  return -1;
4163  }
4164 
4165  if (ast_cc_build_frame(chan, cc_params, monitor_type, device_name, dialstring, service, private_data, &frame)) {
4166  /* Frame building failed. We can't use this. */
4167  return -1;
4168  }
4169  retval = ast_queue_frame(chan, &frame);
4170  ast_frfree(&frame);
4171  return retval;
4172 }
int ast_cc_monitor_count(const char *const name, const char *const type)
Return the number of outstanding CC requests to a specific device.
Definition: ccss.c:4366
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.
Definition: ccss.c:4174
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel's frame queue.
Definition: channel.c:1133
static ENTRY retval
Definition: hsearch.c:50
#define ast_frfree(fr)
#define LOG_NOTICE
Data structure associated with a single frame of data.

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, retval, and service.

Referenced by analog_call().

◆ ast_set_cc_agent_dialstring()

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
configThe configuration to set the cc_agent_dialstring on
valueThe new cc_agent_dialstring we want to change to

Definition at line 966 of file ccss.c.

967 {
968  if (ast_strlen_zero(value)) {
969  config->cc_agent_dialstring[0] = '\0';
970  } else {
971  ast_copy_string(config->cc_agent_dialstring, value, sizeof(config->cc_agent_dialstring));
972  }
973 }

References ast_copy_string(), ast_strlen_zero(), config, and value.

Referenced by ast_cc_set_param().

◆ ast_set_cc_agent_policy()

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
configThe configuration to set the cc_agent_policy on
valueThe new cc_agent_policy we want to change to
Return values
0Success
-1Failure (likely due to bad input)

Definition at line 872 of file ccss.c.

873 {
874  /* Screw C and its weak type checking for making me have to do this
875  * validation at runtime.
876  */
877  if (value < AST_CC_AGENT_NEVER || value > AST_CC_AGENT_GENERIC) {
878  return -1;
879  }
880  config->cc_agent_policy = value;
881  return 0;
882 }

Referenced by ast_cc_set_param(), and build_peer().

◆ ast_set_cc_callback_macro()

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
configThe configuration to set the callback_macro on
valueThe new callback macro we want to change to

Definition at line 1005 of file ccss.c.

1006 {
1007  ast_log(LOG_WARNING, "Usage of cc_callback_macro is deprecated. Please use cc_callback_sub instead.\n");
1008  if (ast_strlen_zero(value)) {
1009  config->cc_callback_macro[0] = '\0';
1010  } else {
1011  ast_copy_string(config->cc_callback_macro, value, sizeof(config->cc_callback_macro));
1012  }
1013 }

References ast_copy_string(), ast_log, ast_strlen_zero(), config, LOG_WARNING, and value.

Referenced by ast_cc_set_param().

◆ ast_set_cc_callback_sub()

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

Set the callback subroutine name.

Since
11
Parameters
configThe configuration to set the callback_sub on
valueThe new callback subroutine we want to change to

Definition at line 1015 of file ccss.c.

1016 {
1017  if (ast_strlen_zero(value)) {
1018  config->cc_callback_sub[0] = '\0';
1019  } else {
1020  ast_copy_string(config->cc_callback_sub, value, sizeof(config->cc_callback_sub));
1021  }
1022 }

References ast_copy_string(), ast_strlen_zero(), config, and value.

Referenced by ast_cc_set_param().

◆ ast_set_cc_interfaces_chanvar()

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
chanThe channel to set the CC_INTERFACES variable on
extensionThe name of the extension for which we're setting the variable. This should be in the form of
exten@context 

Definition at line 3666 of file ccss.c.

3667 {
3668  struct ast_datastore *recall_datastore;
3669  struct cc_monitor_tree *interface_tree;
3670  struct ast_cc_monitor *monitor_iter;
3671  struct cc_recall_ds_data *recall_data;
3672  struct ast_str *str = ast_str_create(64);
3673  int core_id;
3674 
3675  if (!str) {
3676  return -1;
3677  }
3678 
3679  ast_channel_lock(chan);
3680  if (!(recall_datastore = ast_channel_datastore_find(chan, &recall_ds_info, NULL))) {
3681  ast_channel_unlock(chan);
3682  ast_free(str);
3683  return -1;
3684  }
3685  recall_data = recall_datastore->data;
3686  interface_tree = recall_data->interface_tree;
3687  core_id = recall_data->core_id;
3688  ast_channel_unlock(chan);
3689 
3690  AST_LIST_LOCK(interface_tree);
3691  AST_LIST_TRAVERSE(interface_tree, monitor_iter, next) {
3692  if (!strcmp(monitor_iter->interface->device_name, extension)) {
3693  break;
3694  }
3695  }
3696 
3697  if (!monitor_iter) {
3698  /* We couldn't find this extension. This may be because
3699  * we have been directed into an unexpected extension because
3700  * the admin has changed a CC_INTERFACES variable at some point.
3701  */
3702  AST_LIST_UNLOCK(interface_tree);
3703  ast_free(str);
3704  return -1;
3705  }
3706 
3707  build_cc_interfaces_chanvar(monitor_iter, &str);
3708  AST_LIST_UNLOCK(interface_tree);
3709 
3710  pbx_builtin_setvar_helper(chan, "CC_INTERFACES", ast_str_buffer(str));
3711  ast_log_dynamic_level(cc_logger_level, "Core %d: CC_INTERFACES set to %s\n",
3712  core_id, ast_str_buffer(str));
3713 
3714  ast_free(str);
3715  return 0;
3716 }
structure to hold extensions

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_logger_level, 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(), recall_ds_info, and str.

Referenced by local_call().

◆ ast_set_cc_max_agents()

void ast_set_cc_max_agents ( struct ast_cc_config_params config,
unsigned int  value 
)

Set the cc_max_agents.

Since
1.8
Parameters
configThe configuration to set the cc_max_agents on
valueThe new cc_max_agents we want to change to

Definition at line 980 of file ccss.c.

981 {
982  config->cc_max_agents = value;
983 }

References config, and value.

Referenced by ast_cc_set_param().

◆ ast_set_cc_max_monitors()

void ast_set_cc_max_monitors ( struct ast_cc_config_params config,
unsigned int  value 
)

Set the cc_max_monitors.

Since
1.8
Parameters
configThe configuration to set the cc_max_monitors on
valueThe new cc_max_monitors we want to change to

Definition at line 990 of file ccss.c.

991 {
992  config->cc_max_monitors = value;
993 }

References config, and value.

Referenced by ast_cc_set_param().

◆ ast_set_cc_monitor_policy()

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
configThe configuration to set the cc_monitor_policy on
valueThe new cc_monitor_policy we want to change to
Return values
0Success
-1Failure (likely due to bad input)

Definition at line 889 of file ccss.c.

890 {
891  /* Screw C and its weak type checking for making me have to do this
892  * validation at runtime.
893  */
894  if (value < AST_CC_MONITOR_NEVER || value > AST_CC_MONITOR_ALWAYS) {
895  return -1;
896  }
897  config->cc_monitor_policy = value;
898  return 0;
899 }
@ AST_CC_MONITOR_ALWAYS
Definition: ccss.h:87

References AST_CC_MONITOR_ALWAYS, config, and value.

Referenced by ast_cc_set_param().

◆ ast_set_cc_offer_timer()

void ast_set_cc_offer_timer ( struct ast_cc_config_params config,
unsigned int  value 
)

Set the cc_offer_timer.

Since
1.8
Parameters
configThe configuration to set the cc_offer_timer on
valueThe new cc_offer_timer we want to change to

Definition at line 906 of file ccss.c.

907 {
908  /* 0 is an unreasonable value for any timer. Stick with the default */
909  if (value == 0) {
910  ast_log(LOG_WARNING, "0 is an invalid value for cc_offer_timer. Retaining value as %u\n", config->cc_offer_timer);
911  return;
912  }
913  config->cc_offer_timer = value;
914 }

References ast_log, config, LOG_WARNING, and value.

Referenced by ast_cc_set_param().

◆ ast_set_cc_recall_timer()

void ast_set_cc_recall_timer ( struct ast_cc_config_params config,
unsigned int  value 
)

Set the cc_recall_timer.

Since
1.8
Parameters
configThe configuration to set the cc_recall_timer on
valueThe new cc_recall_timer we want to change to

Definition at line 936 of file ccss.c.

937 {
938  /* 0 is an unreasonable value for any timer. Stick with the default */
939  if (value == 0) {
940  ast_log(LOG_WARNING, "0 is an invalid value for ccnr_available_timer. Retaining value as %u\n", config->cc_recall_timer);
941  return;
942  }
943  config->cc_recall_timer = value;
944 }

References ast_log, config, LOG_WARNING, and value.

Referenced by ast_cc_set_param().

◆ ast_set_ccbs_available_timer()

void ast_set_ccbs_available_timer ( struct ast_cc_config_params config,
unsigned int  value 
)

Set the ccbs_available_timer.

Since
1.8
Parameters
configThe configuration to set the ccbs_available_timer on
valueThe new ccbs_available_timer we want to change to

Definition at line 951 of file ccss.c.

952 {
953  /* 0 is an unreasonable value for any timer. Stick with the default */
954  if (value == 0) {
955  ast_log(LOG_WARNING, "0 is an invalid value for ccbs_available_timer. Retaining value as %u\n", config->ccbs_available_timer);
956  return;
957  }
958  config->ccbs_available_timer = value;
959 }

References ast_log, config, LOG_WARNING, and value.

Referenced by ast_cc_set_param().

◆ ast_set_ccnr_available_timer()

void ast_set_ccnr_available_timer ( struct ast_cc_config_params config,
unsigned int  value 
)

Set the ccnr_available_timer.

Since
1.8
Parameters
configThe configuration to set the ccnr_available_timer on
valueThe new ccnr_available_timer we want to change to

Definition at line 921 of file ccss.c.

922 {
923  /* 0 is an unreasonable value for any timer. Stick with the default */
924  if (value == 0) {
925  ast_log(LOG_WARNING, "0 is an invalid value for ccnr_available_timer. Retaining value as %u\n", config->ccnr_available_timer);
926  return;
927  }
928  config->ccnr_available_timer = value;
929 }

References ast_log, config, LOG_WARNING, and value.

Referenced by ast_cc_set_param().

◆ ast_setup_cc_recall_datastore()

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 3405 of file ccss.c.

3406 {
3407  struct ast_datastore *recall_datastore = ast_datastore_alloc(&recall_ds_info, NULL);
3408  struct cc_recall_ds_data *recall_data;
3409  struct cc_core_instance *core_instance;
3410 
3411  if (!recall_datastore) {
3412  return -1;
3413  }
3414 
3415  if (!(recall_data = ast_calloc(1, sizeof(*recall_data)))) {
3416  ast_datastore_free(recall_datastore);
3417  return -1;
3418  }
3419 
3420  if (!(core_instance = find_cc_core_instance(core_id))) {
3421  ast_free(recall_data);
3422  ast_datastore_free(recall_datastore);
3423  return -1;
3424  }
3425 
3426  recall_data->interface_tree = cc_ref(core_instance->monitors,
3427  "Bump refcount for monitor tree for recall datastore");
3428  recall_data->core_id = core_id;
3429  recall_datastore->data = recall_data;
3430  recall_datastore->inheritance = DATASTORE_INHERIT_FOREVER;
3431  ast_channel_lock(chan);
3432  ast_channel_datastore_add(chan, recall_datastore);
3433  ast_channel_unlock(chan);
3434  cc_unref(core_instance, "Recall datastore set up. No need for core_instance ref");
3435  return 0;
3436 }
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2384
#define DATASTORE_INHERIT_FOREVER
Definition: channel.h:192
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
unsigned int inheritance
Definition: datastore.h:69

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_core_instance::core_id, 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, NULL, and recall_ds_info.

Referenced by generic_recall(), and handle_request_invite().

◆ build_cc_interfaces_chanvar()

static void build_cc_interfaces_chanvar ( struct ast_cc_monitor starting_point,
struct ast_str **  str 
)
static

Definition at line 3586 of file ccss.c.

3587 {
3588  struct extension_monitor_pvt *extension_pvt;
3589  struct extension_child_dialstring *child_dialstring;
3590  struct ast_cc_monitor *monitor_iter = starting_point;
3591  int top_level_id = starting_point->id;
3592  size_t length;
3593 
3594  /* Init to an empty string. */
3595  ast_str_truncate(*str, 0);
3596 
3597  /* First we need to take all of the is_valid child_dialstrings from
3598  * the extension monitor we found and add them to the CC_INTERFACES
3599  * chanvar
3600  */
3601  extension_pvt = starting_point->private_data;
3602  AST_LIST_TRAVERSE(&extension_pvt->child_dialstrings, child_dialstring, next) {
3603  if (child_dialstring->is_valid) {
3604  cc_unique_append(str, child_dialstring->original_dialstring);
3605  }
3606  }
3607 
3608  /* And now we get the dialstrings from each of the device monitors */
3609  while ((monitor_iter = AST_LIST_NEXT(monitor_iter, next))) {
3610  if (monitor_iter->parent_id == top_level_id) {
3611  cc_unique_append(str, monitor_iter->dialstring);
3612  }
3613  }
3614 
3615  /* str will have an extra '&' tacked onto the end of it, so we need
3616  * to get rid of that.
3617  */
3618  length = ast_str_strlen(*str);
3619  if (length) {
3620  ast_str_truncate(*str, length - 1);
3621  }
3622  if (length <= 1) {
3623  /* Nothing to recall? This should not happen. */
3624  ast_log(LOG_ERROR, "CC_INTERFACES is empty. starting device_name:'%s'\n",
3625  starting_point->interface->device_name);
3626  }
3627 }
static void cc_unique_append(struct ast_str **str, const char *dialstring)
Definition: ccss.c:3557
#define LOG_ERROR
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
Definition: strings.h:764
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:711
char * dialstring
Name that should be used to recall specified interface.
Definition: ccss.h:525

References AST_LIST_NEXT, AST_LIST_TRAVERSE, ast_log, ast_str_strlen(), ast_str_truncate(), cc_unique_append(), extension_monitor_pvt::child_dialstrings, ast_cc_interface::device_name, ast_cc_monitor::dialstring, ast_cc_monitor::id, ast_cc_monitor::interface, extension_child_dialstring::is_valid, LOG_ERROR, ast_cc_monitor::next, extension_child_dialstring::original_dialstring, ast_cc_monitor::parent_id, ast_cc_monitor::private_data, and str.

Referenced by ast_cc_agent_set_interfaces_chanvar(), and ast_set_cc_interfaces_chanvar().

◆ call_destructor_with_no_monitor()

static void call_destructor_with_no_monitor ( const char *const  monitor_type,
void *  private_data 
)
static

Definition at line 2215 of file ccss.c.

2216 {
2217  const struct ast_cc_monitor_callbacks *monitor_callbacks = find_monitor_callbacks(monitor_type);
2218 
2219  if (!monitor_callbacks) {
2220  return;
2221  }
2222 
2223  monitor_callbacks->destructor(private_data);
2224 }
static const struct ast_cc_monitor_callbacks * find_monitor_callbacks(const char *const type)
Definition: ccss.c:1201
Callbacks defined by CC monitors.
Definition: ccss.h:558
void(* destructor)(void *private_data)
Destroy private data on the monitor.
Definition: ccss.h:650

References ast_cc_monitor_callbacks::destructor, and find_monitor_callbacks().

Referenced by ast_cc_busy_interface(), and ast_handle_cc_control_frame().

◆ cancel_available_timer()

static void cancel_available_timer ( struct cc_core_instance core_instance)
static

Definition at line 3226 of file ccss.c.

3227 {
3228  struct ast_cc_monitor *monitor_iter;
3229  AST_LIST_LOCK(core_instance->monitors);
3230  AST_LIST_TRAVERSE_SAFE_BEGIN(core_instance->monitors, monitor_iter, next) {
3231  if (monitor_iter->interface->monitor_class == AST_CC_DEVICE_MONITOR) {
3232  if (monitor_iter->callbacks->cancel_available_timer(monitor_iter, &monitor_iter->available_timer_id)) {
3234  cc_extension_monitor_change_is_valid(core_instance, monitor_iter->parent_id,
3235  monitor_iter->interface->device_name, 1);
3236  cc_unref(monitor_iter, "cancel_available_timer failed. Unref list's reference to monitor");
3237  }
3238  }
3239  }
3241 
3242  if (!has_device_monitors(core_instance)) {
3243  ast_cc_failed(core_instance->core_id, "All device monitors failed to cancel their available timers");
3244  }
3245  AST_LIST_UNLOCK(core_instance->monitors);
3246 }
static int has_device_monitors(struct cc_core_instance *core_instance)
check if the core instance has any device monitors
Definition: ccss.c:3093
int ast_cc_failed(int core_id, const char *const debug,...)
Indicate failure has occurred.
Definition: ccss.c:3877
@ AST_CC_DEVICE_MONITOR
Definition: ccss.h:479
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:615
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:529
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:557
enum ast_cc_monitor_class monitor_class
Definition: ccss.h:800
int(* cancel_available_timer)(struct ast_cc_monitor *monitor, int *sched_id)
Cancel the running available timer.
Definition: ccss.h:639
const struct ast_cc_monitor_callbacks * callbacks
Definition: ccss.h:533

References AST_CC_DEVICE_MONITOR, ast_cc_failed(), AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_cc_monitor::available_timer_id, ast_cc_monitor::callbacks, ast_cc_monitor_callbacks::cancel_available_timer, cc_extension_monitor_change_is_valid(), cc_unref(), cc_core_instance::core_id, ast_cc_interface::device_name, has_device_monitors(), ast_cc_monitor::interface, ast_cc_interface::monitor_class, cc_core_instance::monitors, ast_cc_monitor::next, and ast_cc_monitor::parent_id.

Referenced by cc_recalling().

◆ cc_active()

static int cc_active ( struct cc_core_instance core_instance,
struct cc_state_change_args args,
enum cc_state  previous_state 
)
static

Definition at line 3168 of file ccss.c.

3169 {
3170  /* Either
3171  * 1. Callee accepted CC request, call agent's ack callback.
3172  * 2. Caller became available, call agent's stop_monitoring callback and
3173  * call monitor's unsuspend callback.
3174  */
3175  if (previous_state == CC_CALLER_REQUESTED) {
3176  core_instance->agent->callbacks->respond(core_instance->agent,
3178  cc_publish_requestacknowledged(core_instance->core_id, core_instance->agent->device_name);
3179  } else if (previous_state == CC_CALLER_BUSY) {
3180  cc_publish_callerstopmonitoring(core_instance->core_id, core_instance->agent->device_name);
3181  unsuspend(core_instance);
3182  }
3183  /* Not possible for previous_state to be anything else due to the is_state_change_valid check at the beginning */
3184  return 0;
3185 }
static void cc_publish_requestacknowledged(int core_id, const char *caller)
Definition: ccss.c:1100
static void unsuspend(struct cc_core_instance *core_instance)
Definition: ccss.c:3146
static void cc_publish_callerstopmonitoring(int core_id, const char *caller)
Definition: ccss.c:1111
@ AST_CC_AGENT_RESPONSE_SUCCESS
Definition: ccss.h:859
void(* respond)(struct ast_cc_agent *agent, enum ast_cc_agent_response_reason reason)
Respond to a CC request.
Definition: ccss.h:944
char device_name[1]
Definition: ccss.h:854

References cc_core_instance::agent, AST_CC_AGENT_RESPONSE_SUCCESS, ast_cc_agent::callbacks, CC_CALLER_BUSY, CC_CALLER_REQUESTED, cc_publish_callerstopmonitoring(), cc_publish_requestacknowledged(), cc_core_instance::core_id, ast_cc_agent::device_name, ast_cc_agent_callbacks::respond, and unsuspend().

◆ cc_agent_callback_helper()

static int cc_agent_callback_helper ( void *  obj,
void *  args,
int  flags 
)
static

Definition at line 445 of file ccss.c.

446 {
447  struct cc_core_instance *core_instance = obj;
448  struct cc_callback_helper *helper = args;
449 
450  if (strcmp(core_instance->agent->callbacks->type, helper->type)) {
451  return 0;
452  }
453 
454  return helper->function(core_instance->agent, helper->args, flags);
455 }
const char * type
Type of agent the callbacks belong to.
Definition: ccss.h:873
const char * type
Definition: ccss.c:442
void * args
Definition: ccss.c:441

References cc_core_instance::agent, cc_callback_helper::args, args, ast_cc_agent::callbacks, cc_callback_helper::function, ast_cc_agent_callbacks::type, and cc_callback_helper::type.

Referenced by ast_cc_agent_callback().

◆ cc_agent_init()

static struct ast_cc_agent* cc_agent_init ( struct ast_channel caller_chan,
const char *const  caller_name,
const int  core_id,
struct cc_monitor_tree interface_tree 
)
static

Definition at line 2554 of file ccss.c.

2557 {
2558  struct ast_cc_agent *agent;
2559  struct ast_cc_config_params *cc_params;
2560 
2561  if (!(agent = ao2_t_alloc(sizeof(*agent) + strlen(caller_name), agent_destroy,
2562  "Allocating new ast_cc_agent"))) {
2563  return NULL;
2564  }
2565 
2566  agent->core_id = core_id;
2567  strcpy(agent->device_name, caller_name);
2568 
2569  cc_params = ast_channel_get_cc_config_params(caller_chan);
2570  if (!cc_params) {
2571  cc_unref(agent, "Could not get channel config params.");
2572  return NULL;
2573  }
2574  if (!(agent->cc_params = ast_cc_config_params_init())) {
2575  cc_unref(agent, "Could not init agent config params.");
2576  return NULL;
2577  }
2578  ast_cc_copy_config_params(agent->cc_params, cc_params);
2579 
2580  if (!(agent->callbacks = find_agent_callbacks(caller_chan))) {
2581  cc_unref(agent, "Could not find agent callbacks.");
2582  return NULL;
2583  }
2585 
2586  if (agent->callbacks->init(agent, caller_chan)) {
2587  cc_unref(agent, "Agent init callback failed.");
2588  return NULL;
2589  }
2590  ast_log_dynamic_level(cc_logger_level, "Core %u: Created an agent for caller %s\n",
2591  agent->core_id, agent->device_name);
2592  return agent;
2593 }
#define ao2_t_alloc(data_size, destructor_fn, debug_msg)
Definition: astobj2.h:407
static void agent_destroy(void *data)
Definition: ccss.c:2544
void ast_cc_copy_config_params(struct ast_cc_config_params *dest, const struct ast_cc_config_params *src)
copy CCSS configuration parameters from one structure to another
Definition: ccss.c:862
static void check_callback_sanity(const struct ast_cc_agent_callbacks *callbacks)
Definition: ccss.c:2532
static const struct ast_cc_agent_callbacks * find_agent_callbacks(struct ast_channel *chan)
Definition: ccss.c:1270
#define ast_cc_config_params_init()
Allocate and initialize an ast_cc_config_params structure.
Definition: ccss.h:135
int(* init)(struct ast_cc_agent *agent, struct ast_channel *chan)
CC agent initialization.
Definition: ccss.h:892
unsigned int core_id
Definition: ccss.h:828

References agent_destroy(), ao2_t_alloc, ast_cc_config_params_init, ast_cc_copy_config_params(), ast_channel_get_cc_config_params(), ast_log_dynamic_level, ast_cc_agent::callbacks, cc_logger_level, ast_cc_agent::cc_params, cc_unref(), check_callback_sanity(), ast_cc_agent::core_id, ast_cc_agent::device_name, find_agent_callbacks(), ast_cc_agent_callbacks::init, and NULL.

Referenced by cc_core_init_instance().

◆ cc_available()

static int cc_available ( struct cc_core_instance core_instance,
struct cc_state_change_args args,
enum cc_state  previous_state 
)
static

Definition at line 3057 of file ccss.c.

3058 {
3059  /* This should never happen... */
3060  ast_log(LOG_WARNING, "Someone requested to change to CC_AVAILABLE? Ignoring.\n");
3061  return -1;
3062 }

References ast_log, and LOG_WARNING.

◆ cc_build_payload()

static int cc_build_payload ( struct ast_channel chan,
struct ast_cc_config_params cc_params,
const char *  monitor_type,
const char *const  device_name,
const char *  dialstring,
enum ast_cc_service_type  service,
void *  private_data,
struct cc_control_payload payload 
)
static

Definition at line 4119 of file ccss.c.

4122 {
4123  struct ast_datastore *datastore;
4124  struct dialed_cc_interfaces *cc_interfaces;
4125  int dial_parent_id;
4126 
4127  ast_channel_lock(chan);
4129  if (!datastore) {
4130  ast_channel_unlock(chan);
4131  return -1;
4132  }
4133  cc_interfaces = datastore->data;
4134  dial_parent_id = cc_interfaces->dial_parent_id;
4135  ast_channel_unlock(chan);
4136 
4137  payload->monitor_type = monitor_type;
4138  payload->private_data = private_data;
4139  payload->service = service;
4140  ast_cc_copy_config_params(&payload->config_params, cc_params);
4142  ast_copy_string(payload->device_name, device_name, sizeof(payload->device_name));
4143  ast_copy_string(payload->dialstring, dialstring, sizeof(payload->dialstring));
4144  return 0;
4145 }
int parent_interface_id
ID of parent extension.
Definition: ccss.c:284
struct ast_cc_config_params config_params
Configuration parameters used by this endpoint.
Definition: ccss.c:275

References ast_cc_copy_config_params(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), cc_control_payload::config_params, ast_datastore::data, cc_control_payload::device_name, dialed_cc_interfaces::dial_parent_id, dialed_cc_interfaces_info, cc_control_payload::dialstring, cc_control_payload::monitor_type, NULL, cc_control_payload::parent_interface_id, cc_control_payload::private_data, cc_control_payload::service, and service.

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

◆ cc_callee_ready()

static int cc_callee_ready ( struct cc_core_instance core_instance,
struct cc_state_change_args args,
enum cc_state  previous_state 
)
static

Definition at line 3187 of file ccss.c.

3188 {
3189  core_instance->agent->callbacks->callee_available(core_instance->agent);
3190  return 0;
3191 }
int(* callee_available)(struct ast_cc_agent *agent)
Alert the caller that it is time to try recalling.
Definition: ccss.h:1037

References cc_core_instance::agent, ast_cc_agent::callbacks, and ast_cc_agent_callbacks::callee_available.

◆ cc_caller_busy()

static int cc_caller_busy ( struct cc_core_instance core_instance,
struct cc_state_change_args args,
enum cc_state  previous_state 
)
static

Definition at line 3215 of file ccss.c.

3216 {
3217  /* Callee was available, but caller was busy, call agent's begin_monitoring callback
3218  * and call monitor's suspend callback.
3219  */
3220  suspend(core_instance);
3221  core_instance->agent->callbacks->start_monitoring(core_instance->agent);
3222  cc_publish_callerstartmonitoring(core_instance->core_id, core_instance->agent->device_name);
3223  return 0;
3224 }
static void cc_publish_callerstartmonitoring(int core_id, const char *caller)
Definition: ccss.c:1122
static void suspend(struct cc_core_instance *core_instance)
Definition: ccss.c:3193
int(* start_monitoring)(struct ast_cc_agent *agent)
Begin monitoring a busy device.
Definition: ccss.h:1018

References cc_core_instance::agent, ast_cc_agent::callbacks, cc_publish_callerstartmonitoring(), cc_core_instance::core_id, ast_cc_agent::device_name, ast_cc_agent_callbacks::start_monitoring, and suspend().

◆ cc_caller_offered()

static int cc_caller_offered ( struct cc_core_instance core_instance,
struct cc_state_change_args args,
enum cc_state  previous_state 
)
static

Definition at line 3064 of file ccss.c.

3065 {
3066  if (core_instance->agent->callbacks->start_offer_timer(core_instance->agent)) {
3067  ast_cc_failed(core_instance->core_id, "Failed to start the offer timer for %s\n",
3068  core_instance->agent->device_name);
3069  return -1;
3070  }
3071  cc_publish_offertimerstart(core_instance->core_id, core_instance->agent->device_name, core_instance->agent->cc_params->cc_offer_timer);
3072  ast_log_dynamic_level(cc_logger_level, "Core %d: Started the offer timer for the agent %s!\n",
3073  core_instance->core_id, core_instance->agent->device_name);
3074  return 0;
3075 }
static void cc_publish_offertimerstart(int core_id, const char *caller, unsigned int expires)
Definition: ccss.c:1076
int(* start_offer_timer)(struct ast_cc_agent *agent)
Start the offer timer.
Definition: ccss.h:913
unsigned int cc_offer_timer
Definition: ccss.c:164

References cc_core_instance::agent, ast_cc_failed(), ast_log_dynamic_level, ast_cc_agent::callbacks, cc_logger_level, ast_cc_config_params::cc_offer_timer, ast_cc_agent::cc_params, cc_publish_offertimerstart(), cc_core_instance::core_id, ast_cc_agent::device_name, and ast_cc_agent_callbacks::start_offer_timer.

◆ cc_caller_requested()

static int cc_caller_requested ( struct cc_core_instance core_instance,
struct cc_state_change_args args,
enum cc_state  previous_state 
)
static

Definition at line 3132 of file ccss.c.

3133 {
3135  ast_log(LOG_WARNING, "Cannot request CC since there is no more room for requests\n");
3136  core_instance->agent->callbacks->respond(core_instance->agent,
3138  ast_cc_failed(core_instance->core_id, "Too many requests in the system");
3139  return -1;
3140  }
3141  core_instance->agent->callbacks->stop_offer_timer(core_instance->agent);
3142  request_cc(core_instance);
3143  return 0;
3144 }
static void request_cc(struct cc_core_instance *core_instance)
Definition: ccss.c:3108
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...
Definition: ccss.c:2482
@ AST_CC_AGENT_RESPONSE_FAILURE_TOO_MANY
Definition: ccss.h:863
int(* stop_offer_timer)(struct ast_cc_agent *agent)
Stop the offer timer.
Definition: ccss.h:926

References cc_core_instance::agent, AST_CC_AGENT_RESPONSE_FAILURE_TOO_MANY, ast_cc_failed(), ast_cc_request_is_within_limits(), ast_log, ast_cc_agent::callbacks, cc_core_instance::core_id, LOG_WARNING, request_cc(), ast_cc_agent_callbacks::respond, and ast_cc_agent_callbacks::stop_offer_timer.

◆ cc_cli_output_status()

static int cc_cli_output_status ( void *  data)
static

Definition at line 4492 of file ccss.c.

4493 {
4494  int *cli_fd = data;
4496 
4497  if (!count) {
4498  ast_cli(*cli_fd, "There are currently no active call completion transactions\n");
4499  } else {
4500  ast_cli(*cli_fd, "%d Call completion transactions\n", count);
4501  ast_cli(*cli_fd, "Core ID\t\tCaller\t\t\t\tStatus\n");
4502  ast_cli(*cli_fd, "----------------------------------------------------------------------------\n");
4503  ao2_t_callback(cc_core_instances, OBJ_NODATA, print_stats_cb, cli_fd, "Printing stats to CLI");
4504  }
4505  ast_free(cli_fd);
4506  return 0;
4507 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
static int print_stats_cb(void *obj, void *arg, int flags)
Definition: ccss.c:4479
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6

References ao2_container_count(), ao2_t_callback, ast_cli(), ast_free, cc_core_instances, OBJ_NODATA, and print_stats_cb().

Referenced by handle_cc_status().

◆ cc_cli_print_monitor_stats()

static void cc_cli_print_monitor_stats ( struct ast_cc_monitor monitor,
int  fd,
int  parent_id 
)
static

Definition at line 4459 of file ccss.c.

4460 {
4461  struct ast_cc_monitor *child_monitor_iter = monitor;
4462  if (!monitor) {
4463  return;
4464  }
4465 
4466  ast_cli(fd, "\t\t|-->%s", monitor->interface->device_name);
4467  if (monitor->interface->monitor_class == AST_CC_DEVICE_MONITOR) {
4468  ast_cli(fd, "(%s)", cc_service_to_string(monitor->service_offered));
4469  }
4470  ast_cli(fd, "\n");
4471 
4472  while ((child_monitor_iter = AST_LIST_NEXT(child_monitor_iter, next))) {
4473  if (child_monitor_iter->parent_id == monitor->id) {
4474  cc_cli_print_monitor_stats(child_monitor_iter, fd, child_monitor_iter->id);
4475  }
4476  }
4477 }
static void cc_cli_print_monitor_stats(struct ast_cc_monitor *monitor, int fd, int parent_id)
Definition: ccss.c:4459
enum ast_cc_service_type service_offered
Definition: ccss.h:514

References AST_CC_DEVICE_MONITOR, ast_cli(), AST_LIST_NEXT, cc_service_to_string(), ast_cc_interface::device_name, ast_cc_monitor::id, ast_cc_monitor::interface, ast_cc_interface::monitor_class, ast_cc_monitor::next, ast_cc_monitor::parent_id, and ast_cc_monitor::service_offered.

Referenced by print_stats_cb().

◆ cc_complete()

static int cc_complete ( struct cc_core_instance core_instance,
struct cc_state_change_args args,
enum cc_state  previous_state 
)
static

Definition at line 3257 of file ccss.c.

3258 {
3259  /* Recall has made progress, call agent and monitor destructor functions
3260  */
3261  cc_publish_recallcomplete(core_instance->core_id, core_instance->agent->device_name);
3262  ao2_t_unlink(cc_core_instances, core_instance, "Unlink core instance since CC recall has completed");
3263  return 0;
3264 }
#define ao2_t_unlink(container, obj, tag)
Definition: astobj2.h:1580
static void cc_publish_recallcomplete(int core_id, const char *caller)
Definition: ccss.c:1144

References cc_core_instance::agent, ao2_t_unlink, cc_core_instances, cc_publish_recallcomplete(), cc_core_instance::core_id, and ast_cc_agent::device_name.

◆ cc_core_init_instance()

static struct cc_core_instance * cc_core_init_instance ( struct ast_channel caller_chan,
struct cc_monitor_tree called_tree,
const int  core_id,
struct cc_control_payload cc_data 
)
static

Definition at line 2940 of file ccss.c.

2942 {
2943  char caller[AST_CHANNEL_NAME];
2944  struct cc_core_instance *core_instance;
2945  struct ast_cc_config_params *cc_params;
2946  long agent_count;
2947  int recall_core_id;
2948 
2949  ast_channel_get_device_name(caller_chan, caller, sizeof(caller));
2950  cc_params = ast_channel_get_cc_config_params(caller_chan);
2951  if (!cc_params) {
2952  ast_log_dynamic_level(cc_logger_level, "Could not get CC parameters for %s\n",
2953  caller);
2954  return NULL;
2955  }
2956  /* First, we need to kill off other pending CC offers from caller. If the caller is going
2957  * to request a CC service, it may only be for the latest call he made.
2958  */
2959  if (ast_get_cc_agent_policy(cc_params) == AST_CC_AGENT_GENERIC) {
2960  kill_duplicate_offers(caller);
2961  }
2962 
2963  ast_cc_is_recall(caller_chan, &recall_core_id, NULL);
2964  agent_count = count_agents(caller, recall_core_id);
2965  if (agent_count >= ast_get_cc_max_agents(cc_params)) {
2966  ast_log_dynamic_level(cc_logger_level, "Caller %s already has the maximum number of agents configured\n", caller);
2967  return NULL;
2968  }
2969 
2970  /* Generic agents can only have a single outstanding CC request per caller. */
2971  if (agent_count > 0 && ast_get_cc_agent_policy(cc_params) == AST_CC_AGENT_GENERIC) {
2972  ast_log_dynamic_level(cc_logger_level, "Generic agents can only have a single outstanding request\n");
2973  return NULL;
2974  }
2975 
2976  /* Next, we need to create the core instance for this call */
2977  if (!(core_instance = ao2_t_alloc(sizeof(*core_instance), cc_core_instance_destructor, "Creating core instance for CC"))) {
2978  return NULL;
2979  }
2980 
2981  core_instance->core_id = core_id;
2982  if (!(core_instance->agent = cc_agent_init(caller_chan, caller, core_instance->core_id, called_tree))) {
2983  cc_unref(core_instance, "Couldn't allocate agent, unref core_instance");
2984  return NULL;
2985  }
2986 
2987  core_instance->monitors = cc_ref(called_tree, "Core instance getting ref to monitor tree");
2988 
2989  ao2_t_link(cc_core_instances, core_instance, "Link core instance into container");
2990 
2991  return core_instance;
2992 }
#define ao2_t_link(container, obj, tag)
Definition: astobj2.h:1534
static struct ast_cc_agent * cc_agent_init(struct ast_channel *caller_chan, const char *const caller_name, const int core_id, struct cc_monitor_tree *interface_tree)
Definition: ccss.c:2554
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.
Definition: ccss.c:3438
static void kill_duplicate_offers(char *caller)
Definition: ccss.c:2515
static void cc_core_instance_destructor(void *data)
Definition: ccss.c:2928
static long count_agents(const char *const caller, const int core_id_exception)
Definition: ccss.c:2506

References cc_core_instance::agent, ao2_t_alloc, ao2_t_link, AST_CC_AGENT_GENERIC, ast_cc_is_recall(), ast_channel_get_cc_config_params(), ast_channel_get_device_name(), AST_CHANNEL_NAME, ast_get_cc_agent_policy(), ast_get_cc_max_agents(), ast_log_dynamic_level, cc_agent_init(), cc_core_instance_destructor(), cc_core_instances, cc_logger_level, cc_ref(), cc_unref(), cc_core_instance::core_id, count_agents(), kill_duplicate_offers(), cc_core_instance::monitors, and NULL.

Referenced by ast_handle_cc_control_frame().

◆ cc_core_instance_cmp_fn()

static int cc_core_instance_cmp_fn ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 424 of file ccss.c.

425 {
426  struct cc_core_instance *core_instance1 = obj;
427  struct cc_core_instance *core_instance2 = arg;
428 
429  return core_instance1->core_id == core_instance2->core_id ? CMP_MATCH | CMP_STOP : 0;
430 }
@ CMP_MATCH
Definition: astobj2.h:1027
@ CMP_STOP
Definition: astobj2.h:1028

References CMP_MATCH, CMP_STOP, and cc_core_instance::core_id.

◆ cc_core_instance_destructor()

static void cc_core_instance_destructor ( void *  data)
static

Definition at line 2928 of file ccss.c.

2929 {
2930  struct cc_core_instance *core_instance = data;
2931  ast_log_dynamic_level(cc_logger_level, "Core %d: Destroying core instance\n", core_instance->core_id);
2932  if (core_instance->agent) {
2933  cc_unref(core_instance->agent, "Core instance is done with the agent now");
2934  }
2935  if (core_instance->monitors) {
2936  core_instance->monitors = cc_unref(core_instance->monitors, "Core instance is done with interface list");
2937  }
2938 }

References cc_core_instance::agent, ast_log_dynamic_level, cc_logger_level, cc_unref(), cc_core_instance::core_id, and cc_core_instance::monitors.

Referenced by cc_core_init_instance().

◆ cc_core_instance_hash_fn()

static int cc_core_instance_hash_fn ( const void *  obj,
const int  flags 
)
static

Definition at line 418 of file ccss.c.

419 {
420  const struct cc_core_instance *core_instance = obj;
421  return core_instance->core_id;
422 }

References cc_core_instance::core_id.

◆ cc_device_monitor_init()

static struct ast_cc_monitor* cc_device_monitor_init ( const char *const  device_name,
const char *const  dialstring,
const struct cc_control_payload cc_data,
int  core_id 
)
static

Definition at line 2250 of file ccss.c.

2251 {
2252  struct ast_cc_interface *cc_interface;
2253  struct ast_cc_monitor *monitor;
2254  size_t device_name_len = strlen(device_name);
2255  int parent_id = cc_data->parent_interface_id;
2256 
2257  if (!(cc_interface = ao2_t_alloc(sizeof(*cc_interface) + device_name_len, cc_interface_destroy,
2258  "Allocating new ast_cc_interface"))) {
2259  return NULL;
2260  }
2261 
2262  if (!(cc_interface->config_params = ast_cc_config_params_init())) {
2263  cc_unref(cc_interface, "Failed to allocate config params, unref interface");
2264  return NULL;
2265  }
2266 
2267  if (!(monitor = ao2_t_alloc(sizeof(*monitor), cc_monitor_destroy, "Allocating new ast_cc_monitor"))) {
2268  cc_unref(cc_interface, "Failed to allocate monitor, unref interface");
2269  return NULL;
2270  }
2271 
2272  if (!(monitor->dialstring = ast_strdup(dialstring))) {
2273  cc_unref(monitor, "Failed to copy dialable name. Unref monitor");
2274  cc_unref(cc_interface, "Failed to copy dialable name");
2275  return NULL;
2276  }
2277 
2278  if (!(monitor->callbacks = find_monitor_callbacks(cc_data->monitor_type))) {
2279  cc_unref(monitor, "Failed to find monitor callbacks. Unref monitor");
2280  cc_unref(cc_interface, "Failed to find monitor callbacks");
2281  return NULL;
2282  }
2283 
2284  strcpy(cc_interface->device_name, device_name);
2286  monitor->parent_id = parent_id;
2287  monitor->core_id = core_id;
2288  monitor->service_offered = cc_data->service;
2289  monitor->private_data = cc_data->private_data;
2290  cc_interface->monitor_type = cc_data->monitor_type;
2291  cc_interface->monitor_class = AST_CC_DEVICE_MONITOR;
2292  monitor->interface = cc_interface;
2293  monitor->available_timer_id = -1;
2294  ast_cc_copy_config_params(cc_interface->config_params, &cc_data->config_params);
2295  ast_log_dynamic_level(cc_logger_level, "Core %d: Created a device cc interface for '%s' with id %u and parent %u\n",
2296  monitor->core_id, cc_interface->device_name, monitor->id, monitor->parent_id);
2297  return monitor;
2298 }
static int dialed_cc_interface_counter
Definition: ccss.c:1876
static void cc_interface_destroy(void *data)
Definition: ccss.c:1738
static void cc_monitor_destroy(void *data)
Definition: ccss.c:1838
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
Structure with information about an outbound interface.
Definition: ccss.h:797
struct ast_cc_config_params * config_params
Definition: ccss.h:813

References ao2_t_alloc, ast_atomic_fetchadd_int(), ast_cc_config_params_init, ast_cc_copy_config_params(), AST_CC_DEVICE_MONITOR, ast_log_dynamic_level, ast_strdup, ast_cc_monitor::available_timer_id, ast_cc_monitor::callbacks, cc_interface_destroy(), cc_logger_level, cc_monitor_destroy(), cc_unref(), ast_cc_interface::config_params, cc_control_payload::config_params, ast_cc_monitor::core_id, ast_cc_interface::device_name, dialed_cc_interface_counter, ast_cc_monitor::dialstring, find_monitor_callbacks(), ast_cc_monitor::id, ast_cc_monitor::interface, ast_cc_interface::monitor_class, ast_cc_interface::monitor_type, cc_control_payload::monitor_type, NULL, ast_cc_monitor::parent_id, cc_control_payload::parent_interface_id, ast_cc_monitor::private_data, cc_control_payload::private_data, cc_control_payload::service, and ast_cc_monitor::service_offered.

Referenced by ast_handle_cc_control_frame().

◆ cc_do_state_change()

static int cc_do_state_change ( void *  datap)
static

Definition at line 3285 of file ccss.c.

3286 {
3287  struct cc_state_change_args *args = datap;
3288  struct cc_core_instance *core_instance;
3289  enum cc_state previous_state;
3290  int res;
3291 
3292  ast_log_dynamic_level(cc_logger_level, "Core %d: State change to %u requested. Reason: %s\n",
3293  args->core_id, args->state, args->debug);
3294 
3295  core_instance = args->core_instance;
3296 
3297  if (!is_state_change_valid(core_instance->current_state, args->state, core_instance->agent)) {
3298  ast_log_dynamic_level(cc_logger_level, "Core %d: Invalid state change requested. Cannot go from %s to %s\n",
3299  args->core_id, cc_state_to_string(core_instance->current_state), cc_state_to_string(args->state));
3300  if (args->state == CC_CALLER_REQUESTED) {
3301  /*
3302  * For out-of-order requests, we need to let the requester know that
3303  * we can't handle the request now.
3304  */
3305  core_instance->agent->callbacks->respond(core_instance->agent,
3307  }
3308  ast_free(args);
3309  cc_unref(core_instance, "Unref core instance from when it was found earlier");
3310  return -1;
3311  }
3312 
3313  /* We can change to the new state now. */
3314  previous_state = core_instance->current_state;
3315  core_instance->current_state = args->state;
3316  res = state_change_funcs[core_instance->current_state](core_instance, args, previous_state);
3317 
3318  /* If state change successful then notify any device state watchers of the change */
3319  if (!res && !strcmp(core_instance->agent->callbacks->type, "generic")) {
3320  ccss_notify_device_state_change(core_instance->agent->device_name, core_instance->current_state);
3321  }
3322 
3323  ast_free(args);
3324  cc_unref(core_instance, "Unref since state change has completed"); /* From ao2_find */
3325  return res;
3326 }
static void ccss_notify_device_state_change(const char *device, enum cc_state state)
Definition: ccss.c:642
cc_state
The states used in the CCSS core state machine.
Definition: ccss.c:181
static const char * cc_state_to_string(enum cc_state state)
Definition: ccss.c:408
static int(*const state_change_funcs[])(struct cc_core_instance *, struct cc_state_change_args *, enum cc_state previous_state)
Definition: ccss.c:3273
static int is_state_change_valid(enum cc_state current_state, const enum cc_state new_state, struct ast_cc_agent *agent)
Definition: ccss.c:3001
@ AST_CC_AGENT_RESPONSE_FAILURE_INVALID
Definition: ccss.h:861
enum cc_state current_state
Definition: ccss.c:337

References cc_core_instance::agent, args, AST_CC_AGENT_RESPONSE_FAILURE_INVALID, ast_free, ast_log_dynamic_level, ast_cc_agent::callbacks, CC_CALLER_REQUESTED, cc_logger_level, cc_state_to_string(), cc_unref(), ccss_notify_device_state_change(), cc_core_instance::current_state, ast_cc_agent::device_name, is_state_change_valid(), ast_cc_agent_callbacks::respond, state_change_funcs, and ast_cc_agent_callbacks::type.

Referenced by cc_request_state_change().

◆ cc_extension_monitor_change_is_valid()

static void cc_extension_monitor_change_is_valid ( struct cc_core_instance core_instance,
unsigned int  parent_id,
const char *const  device_name,
int  is_valid 
)
static

Definition at line 2051 of file ccss.c.

2052 {
2053  struct ast_cc_monitor *monitor_iter;
2054  struct extension_monitor_pvt *extension_pvt;
2055  struct extension_child_dialstring *child_dialstring;
2056 
2057  AST_LIST_TRAVERSE(core_instance->monitors, monitor_iter, next) {
2058  if (monitor_iter->id == parent_id) {
2059  break;
2060  }
2061  }
2062 
2063  if (!monitor_iter) {
2064  return;
2065  }
2066  extension_pvt = monitor_iter->private_data;
2067 
2068  AST_LIST_TRAVERSE(&extension_pvt->child_dialstrings, child_dialstring, next) {
2069  if (!strcmp(child_dialstring->device_name, device_name)) {
2070  child_dialstring->is_valid = is_valid;
2071  break;
2072  }
2073  }
2074 }
struct extension_child_dialstring * next
Definition: ccss.c:1812

References AST_LIST_TRAVERSE, extension_monitor_pvt::child_dialstrings, extension_child_dialstring::device_name, ast_cc_monitor::id, extension_child_dialstring::is_valid, cc_core_instance::monitors, extension_child_dialstring::next, and ast_cc_monitor::private_data.

Referenced by ast_handle_cc_control_frame(), cancel_available_timer(), cc_monitor_failed(), request_cc(), suspend(), and unsuspend().

◆ cc_extension_monitor_destructor()

static void cc_extension_monitor_destructor ( void *  private_data)
static

Definition at line 1822 of file ccss.c.

1823 {
1824  struct extension_monitor_pvt *extension_pvt = private_data;
1825  struct extension_child_dialstring *child_dialstring;
1826 
1827  /* This shouldn't be possible, but I'm paranoid */
1828  if (!extension_pvt) {
1829  return;
1830  }
1831 
1832  while ((child_dialstring = AST_LIST_REMOVE_HEAD(&extension_pvt->child_dialstrings, next))) {
1833  ast_free(child_dialstring);
1834  }
1835  ast_free(extension_pvt);
1836 }
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833

References ast_free, AST_LIST_REMOVE_HEAD, extension_monitor_pvt::child_dialstrings, and extension_child_dialstring::next.

Referenced by cc_monitor_destroy().

◆ cc_extension_monitor_init()

static struct ast_cc_monitor* cc_extension_monitor_init ( const char *const  exten,
const char *const  context,
const unsigned int  parent_id 
)
static

Definition at line 2090 of file ccss.c.

2091 {
2093  struct ast_cc_interface *cc_interface;
2094  struct ast_cc_monitor *monitor;
2095 
2096  ast_str_set(&str, 0, "%s@%s", exten, context);
2097 
2098  if (!(cc_interface = ao2_t_alloc(sizeof(*cc_interface) + ast_str_strlen(str), cc_interface_destroy,
2099  "Allocating new ast_cc_interface"))) {
2100  return NULL;
2101  }
2102 
2103  if (!(monitor = ao2_t_alloc(sizeof(*monitor), cc_monitor_destroy, "Allocating new ast_cc_monitor"))) {
2104  cc_unref(cc_interface, "failed to allocate the monitor, so unref the interface");
2105  return NULL;
2106  }
2107 
2108  if (!(monitor->private_data = extension_monitor_pvt_init())) {
2109  cc_unref(monitor, "Failed to initialize extension monitor private data. uref monitor");
2110  cc_unref(cc_interface, "Failed to initialize extension monitor private data. unref cc_interface");
2111  }
2112 
2114  monitor->parent_id = parent_id;
2115  cc_interface->monitor_type = "extension";
2116  cc_interface->monitor_class = AST_CC_EXTENSION_MONITOR;
2117  strcpy(cc_interface->device_name, ast_str_buffer(str));
2118  monitor->interface = cc_interface;
2119  ast_log_dynamic_level(cc_logger_level, "Created an extension cc interface for '%s' with id %u and parent %u\n", cc_interface->device_name, monitor->id, monitor->parent_id);
2120  return monitor;
2121 }
static struct extension_monitor_pvt * extension_monitor_pvt_init(void)
Definition: ccss.c:1996
@ AST_CC_EXTENSION_MONITOR
Definition: ccss.h:480
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:122
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:120
#define AST_MAX_EXTENSION
Definition: channel.h:134
#define ast_str_alloca(init_len)
Definition: strings.h:826
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1091

References ao2_t_alloc, ast_atomic_fetchadd_int(), AST_CC_EXTENSION_MONITOR, ast_log_dynamic_level, AST_MAX_EXTENSION, ast_str_alloca, ast_str_buffer(), ast_str_set(), ast_str_strlen(), cc_interface_destroy(), cc_logger_level, cc_monitor_destroy(), cc_unref(), context, ast_cc_interface::device_name, dialed_cc_interface_counter, exten, extension_monitor_pvt_init(), ast_cc_monitor::id, ast_cc_monitor::interface, ast_cc_interface::monitor_class, ast_cc_interface::monitor_type, NULL, ast_cc_monitor::parent_id, ast_cc_monitor::private_data, and str.

Referenced by ast_cc_call_init(), and cc_interfaces_datastore_init().

◆ cc_failed()

static int cc_failed ( struct cc_core_instance core_instance,
struct cc_state_change_args args,
enum cc_state  previous_state 
)
static

Definition at line 3266 of file ccss.c.

3267 {
3268  cc_publish_failure(core_instance->core_id, core_instance->agent->device_name, args->debug);
3269  ao2_t_unlink(cc_core_instances, core_instance, "Unlink core instance since CC failed");
3270  return 0;
3271 }
static void cc_publish_failure(int core_id, const char *caller, const char *reason)
Definition: ccss.c:1155

References cc_core_instance::agent, ao2_t_unlink, args, cc_core_instances, cc_publish_failure(), cc_core_instance::core_id, and ast_cc_agent::device_name.

◆ cc_generic_agent_destructor()

static void cc_generic_agent_destructor ( struct ast_cc_agent agent)
static

Definition at line 2911 of file ccss.c.

2912 {
2913  struct cc_generic_agent_pvt *agent_pvt = agent->private_data;
2914 
2915  if (!agent_pvt) {
2916  /* The agent constructor probably failed. */
2917  return;
2918  }
2919 
2921  if (agent_pvt->sub) {
2922  agent_pvt->sub = stasis_unsubscribe(agent_pvt->sub);
2923  }
2924 
2926 }
static int cc_generic_agent_stop_offer_timer(struct ast_cc_agent *agent)
Definition: ccss.c:2722
struct stasis_subscription * stasis_unsubscribe(struct stasis_subscription *subscription)
Cancel a subscription.
Definition: stasis.c:973
Structure representing an agent.
void * private_data
Definition: ccss.h:850

References ast_free, cc_generic_agent_stop_offer_timer(), ast_cc_agent::private_data, and stasis_unsubscribe().

◆ cc_generic_agent_init()

static int cc_generic_agent_init ( struct ast_cc_agent agent,
struct ast_channel chan 
)
static

Definition at line 2669 of file ccss.c.

2670 {
2671  struct cc_generic_agent_pvt *generic_pvt = ast_calloc(1, sizeof(*generic_pvt));
2672 
2673  if (!generic_pvt) {
2674  return -1;
2675  }
2676 
2677  generic_pvt->offer_timer_id = -1;
2678  if (ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str) {
2679  ast_copy_string(generic_pvt->cid_num, ast_channel_caller(chan)->id.number.str, sizeof(generic_pvt->cid_num));
2680  }
2681  if (ast_channel_caller(chan)->id.name.valid && ast_channel_caller(chan)->id.name.str) {
2682  ast_copy_string(generic_pvt->cid_name, ast_channel_caller(chan)->id.name.str, sizeof(generic_pvt->cid_name));
2683  }
2684  ast_copy_string(generic_pvt->exten, S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)), sizeof(generic_pvt->exten));
2685  ast_copy_string(generic_pvt->context, S_OR(ast_channel_macrocontext(chan), ast_channel_context(chan)), sizeof(generic_pvt->context));
2686  agent->private_data = generic_pvt;
2688  return 0;
2689 }
@ AST_CC_AGENT_SKIP_OFFER
Definition: ccss.h:67
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
char context[AST_CHANNEL_NAME]
Definition: ccss.c:2666
char cid_num[AST_CHANNEL_NAME]
Definition: ccss.c:2642
char cid_name[AST_CHANNEL_NAME]
Definition: ccss.c:2650
char exten[AST_CHANNEL_NAME]
Definition: ccss.c:2658
Number structure.
Definition: app_followme.c:154
#define ast_set_flag(p, flag)
Definition: utils.h:70

References ast_calloc, AST_CC_AGENT_SKIP_OFFER, ast_channel_caller(), ast_channel_context(), ast_channel_exten(), ast_channel_macrocontext(), ast_channel_macroexten(), ast_copy_string(), ast_set_flag, cc_generic_agent_pvt::cid_name, cc_generic_agent_pvt::cid_num, cc_generic_agent_pvt::context, cc_generic_agent_pvt::exten, name, cc_generic_agent_pvt::offer_timer_id, ast_cc_agent::private_data, and S_OR.

◆ cc_generic_agent_recall()

static int cc_generic_agent_recall ( struct ast_cc_agent agent)
static

Definition at line 2895 of file ccss.c.

2896 {
2897  pthread_t clotho;
2898  enum ast_device_state current_state = ast_device_state(agent->device_name);
2899 
2900  if (!cc_generic_is_device_available(current_state)) {
2901  /* We can't try to contact the device right now because he's not available
2902  * Let the core know he's busy.
2903  */
2904  ast_cc_agent_caller_busy(agent->core_id, "Generic agent caller %s is busy", agent->device_name);
2905  return 0;
2906  }
2908  return 0;
2909 }
int ast_cc_agent_caller_busy(int core_id, const char *debug,...)
Indicate that the caller is busy.
Definition: ccss.c:3807
static int cc_generic_is_device_available(enum ast_device_state state)
Definition: ccss.c:1314
static void * generic_recall(void *data)
Definition: ccss.c:2816
ast_device_state
Device States.
Definition: devicestate.h:52
#define ast_pthread_create_detached_background(a, b, c, d)
Definition: utils.h:592

References ast_cc_agent_caller_busy(), ast_pthread_create_detached_background, cc_generic_is_device_available(), ast_cc_agent::core_id, ast_cc_agent::device_name, generic_recall(), and NULL.

◆ cc_generic_agent_respond()

static void cc_generic_agent_respond ( struct ast_cc_agent agent,
enum ast_cc_agent_response_reason  reason 
)
static

Definition at line 2735 of file ccss.c.

2736 {
2737  /* The generic agent doesn't have to do anything special to
2738  * acknowledge a CC request. Just return.
2739  */
2740  return;
2741 }

◆ cc_generic_agent_start_monitoring()

static int cc_generic_agent_start_monitoring ( struct ast_cc_agent agent)
static

Definition at line 2791 of file ccss.c.

2792 {
2793  struct cc_generic_agent_pvt *generic_pvt = agent->private_data;
2794  struct ast_str *str = ast_str_alloca(128);
2795  struct stasis_topic *device_specific_topic;
2796 
2797  ast_assert(generic_pvt->sub == NULL);
2798  ast_str_set(&str, 0, "Agent monitoring %s device state since it is busy\n",
2799  agent->device_name);
2800 
2801  device_specific_topic = ast_device_state_topic(agent->device_name);
2802  if (!device_specific_topic) {
2803  return -1;
2804  }
2805 
2806  if (!(generic_pvt->sub = stasis_subscribe(device_specific_topic, generic_agent_devstate_cb, agent))) {
2807  return -1;
2808  }
2812  cc_ref(agent, "Ref agent for subscription");
2813  return 0;
2814 }
static void generic_agent_devstate_cb(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
Definition: ccss.c:2761
struct stasis_topic * ast_device_state_topic(const char *device)
Get the Stasis topic for device state messages for a specific device.
Definition: devicestate.c:683
struct stasis_message_type * ast_device_state_message_type(void)
Get the Stasis message type for device state messages.
struct stasis_message_type * stasis_subscription_change_type(void)
Gets the message type for subscription change notices.
@ STASIS_SUBSCRIPTION_FILTER_SELECTIVE
Definition: stasis.h:297
int stasis_subscription_accept_message_type(struct stasis_subscription *subscription, const struct stasis_message_type *type)
Indicate to a subscription that we are interested in a message type.
Definition: stasis.c:1025
int stasis_subscription_set_filter(struct stasis_subscription *subscription, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a subscription.
Definition: stasis.c:1079
#define stasis_subscribe(topic, callback, data)
Definition: stasis.h:649
struct stasis_subscription * sub
Definition: ccss.c:2628

References ast_assert, ast_device_state_message_type(), ast_device_state_topic(), ast_str_alloca, ast_str_set(), cc_ref(), ast_cc_agent::device_name, generic_agent_devstate_cb(), NULL, ast_cc_agent::private_data, stasis_subscribe, stasis_subscription_accept_message_type(), stasis_subscription_change_type(), STASIS_SUBSCRIPTION_FILTER_SELECTIVE, stasis_subscription_set_filter(), str, and cc_generic_agent_pvt::sub.

◆ cc_generic_agent_start_offer_timer()

static int cc_generic_agent_start_offer_timer ( struct ast_cc_agent agent)
static

Definition at line 2703 of file ccss.c.

2704 {
2705  int when;
2706  int sched_id;
2707  struct cc_generic_agent_pvt *generic_pvt = agent->private_data;
2708 
2710  ast_assert(agent->cc_params != NULL);
2711 
2712  when = ast_get_cc_offer_timer(agent->cc_params) * 1000;
2713  ast_log_dynamic_level(cc_logger_level, "Core %u: About to schedule offer timer expiration for %d ms\n",
2714  agent->core_id, when);
2715  if ((sched_id = ast_sched_add(cc_sched_context, when, offer_timer_expire, cc_ref(agent, "Give scheduler an agent ref"))) == -1) {
2716  return -1;
2717  }
2718  generic_pvt->offer_timer_id = sched_id;
2719  return 0;
2720 }
static struct ast_sched_context * cc_sched_context
Definition: ccss.c:115
static int offer_timer_expire(const void *data)
Definition: ccss.c:2691
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event.
Definition: sched.c:567
Scheduler ID holder.
Definition: sched.c:70

References ast_assert, ast_get_cc_offer_timer(), ast_log_dynamic_level, ast_sched_add(), cc_logger_level, ast_cc_agent::cc_params, cc_ref(), cc_sched_context, ast_cc_agent::core_id, NULL, offer_timer_expire(), cc_generic_agent_pvt::offer_timer_id, and ast_cc_agent::private_data.

◆ cc_generic_agent_status_request()

static int cc_generic_agent_status_request ( struct ast_cc_agent agent)
static

Definition at line 2743 of file ccss.c.

2744 {
2746  return 0;
2747 }
int ast_cc_agent_status_response(int core_id, enum ast_device_state devstate)
Response with a caller's current status.
Definition: ccss.c:4091

References ast_cc_agent_status_response(), ast_cc_agent::core_id, and ast_cc_agent::device_name.

◆ cc_generic_agent_stop_offer_timer()

static int cc_generic_agent_stop_offer_timer ( struct ast_cc_agent agent)
static

Definition at line 2722 of file ccss.c.

2723 {
2724  struct cc_generic_agent_pvt *generic_pvt = agent->private_data;
2725 
2726  if (generic_pvt->offer_timer_id != -1) {
2727  if (!ast_sched_del(cc_sched_context, generic_pvt->offer_timer_id)) {
2728  cc_unref(agent, "Remove scheduler's reference to the agent");
2729  }
2730  generic_pvt->offer_timer_id = -1;
2731  }
2732  return 0;
2733 }
int ast_sched_del(struct ast_sched_context *con, int id) attribute_warn_unused_result
Deletes a scheduled event.
Definition: sched.c:614

References ast_sched_del(), cc_sched_context, cc_unref(), cc_generic_agent_pvt::offer_timer_id, and ast_cc_agent::private_data.

Referenced by cc_generic_agent_destructor().

◆ cc_generic_agent_stop_ringing()

static int cc_generic_agent_stop_ringing ( struct ast_cc_agent agent)
static

Definition at line 2749 of file ccss.c.

2750 {
2751  struct ast_channel *recall_chan = ast_channel_get_by_name_prefix(agent->device_name, strlen(agent->device_name));
2752 
2753  if (!recall_chan) {
2754  return 0;
2755  }
2756 
2758  return 0;
2759 }
@ AST_SOFTHANGUP_EXPLICIT
Definition: channel.h:1148
struct ast_channel * ast_channel_get_by_name_prefix(const char *name, size_t name_len)
Find a channel by a name prefix.
Definition: channel.c:1428
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup up a channel.
Definition: channel.c:2470
Main Channel structure associated with a channel.

References ast_channel_get_by_name_prefix(), ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, and ast_cc_agent::device_name.

◆ cc_generic_is_device_available()

static int cc_generic_is_device_available ( enum ast_device_state  state)
static

◆ cc_generic_monitor_cancel_available_timer()

static int cc_generic_monitor_cancel_available_timer ( struct ast_cc_monitor monitor,
int *  sched_id 
)
static

Definition at line 1652 of file ccss.c.

1653 {
1654  ast_assert(sched_id != NULL);
1655 
1656  if (*sched_id == -1) {
1657  return 0;
1658  }
1659 
1660  ast_log_dynamic_level(cc_logger_level, "Core %d: Canceling generic monitor available timer for monitor %s\n",
1661  monitor->core_id, monitor->interface->device_name);
1663  cc_unref(monitor, "Remove scheduler's reference to the monitor");
1664  }
1665  *sched_id = -1;
1666  return 0;
1667 }

References ast_assert, ast_log_dynamic_level, ast_sched_del(), cc_logger_level, cc_sched_context, cc_unref(), ast_cc_monitor::core_id, ast_cc_interface::device_name, ast_cc_monitor::interface, and NULL.

◆ cc_generic_monitor_destructor()

static void cc_generic_monitor_destructor ( void *  private_data)
static

Definition at line 1669 of file ccss.c.

1670 {
1671  struct generic_monitor_pvt *gen_mon_pvt = private_data;
1672  struct generic_monitor_instance_list *generic_list;
1673  struct generic_monitor_instance *generic_instance;
1674 
1675  if (!private_data) {
1676  /* If the private data is NULL, that means that the monitor hasn't even
1677  * been created yet, but that the destructor was called. While this sort
1678  * of behavior is useful for native monitors, with a generic one, there is
1679  * nothing in particular to do.
1680  */
1681  return;
1682  }
1683 
1684  ast_log_dynamic_level(cc_logger_level, "Core %d: Destroying generic monitor %s\n",
1685  gen_mon_pvt->core_id, gen_mon_pvt->device_name);
1686 
1687  if (!(generic_list = find_generic_monitor_instance_list(gen_mon_pvt->device_name))) {
1688  /* If there's no generic list, that means that the monitor is being destroyed
1689  * before we actually got to request CC. Not a biggie. Same in the situation
1690  * below if the list traversal should complete without finding an entry.
1691  */
1692  ast_free((char *)gen_mon_pvt->device_name);
1693  ast_free(gen_mon_pvt);
1694  return;
1695  }
1696 
1697  AST_LIST_TRAVERSE_SAFE_BEGIN(&generic_list->list, generic_instance, next) {
1698  if (generic_instance->core_id == gen_mon_pvt->core_id) {
1700  ast_free(generic_instance);
1701  break;
1702  }
1703  }
1705 
1706  if (AST_LIST_EMPTY(&generic_list->list)) {
1707  /* No more monitors with this device name exist. Time to unlink this
1708  * list from the container
1709  */
1710  ao2_t_unlink(generic_monitors, generic_list, "Generic list is empty. Unlink it from the container");
1711  } else {
1712  /* There are still instances for this particular device. The situation
1713  * may be that we were attempting a CC recall and a failure occurred, perhaps
1714  * on the agent side. If a failure happens here and the device being monitored
1715  * is available, then we need to signal on the first unsuspended instance that
1716  * the device is available for recall.
1717  */
1718 
1719  /* First things first. We don't even want to consider this action if
1720  * the device in question isn't available right now.
1721  */
1722  if (generic_list->fit_for_recall
1723  && cc_generic_is_device_available(generic_list->current_state)) {
1724  AST_LIST_TRAVERSE(&generic_list->list, generic_instance, next) {
1725  if (!generic_instance->is_suspended && generic_instance->monitoring) {
1726  ast_cc_monitor_callee_available(generic_instance->core_id, "Signaling generic monitor "
1727  "availability due to other instance's failure.");
1728  break;
1729  }
1730  }
1731  }
1732  }
1733  cc_unref(generic_list, "Done with generic list in generic monitor destructor");
1734  ast_free((char *)gen_mon_pvt->device_name);
1735  ast_free(gen_mon_pvt);
1736 }
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.
Definition: ccss.c:3796
struct ao2_container * generic_monitors
Definition: ccss.c:1334
static struct generic_monitor_instance_list * find_generic_monitor_instance_list(const char *const device_name)
Definition: ccss.c:1387
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
enum ast_device_state current_state
Definition: ccss.c:1345
struct generic_monitor_instance_list::@354 list
struct generic_monitor_instance * next
Definition: ccss.c:1340
private data for generic device monitor
Definition: ccss.c:1369
const char * device_name
Definition: ccss.c:1374

References ao2_t_unlink, ast_cc_monitor_callee_available(), ast_free, AST_LIST_EMPTY, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log_dynamic_level, cc_generic_is_device_available(), cc_logger_level, cc_unref(), generic_monitor_instance::core_id, generic_monitor_pvt::core_id, generic_monitor_instance_list::current_state, generic_monitor_pvt::device_name, find_generic_monitor_instance_list(), generic_monitor_instance_list::fit_for_recall, generic_monitors, generic_monitor_instance::is_suspended, generic_monitor_instance_list::list, generic_monitor_instance::monitoring, and generic_monitor_instance::next.

◆ cc_generic_monitor_request_cc()

static int cc_generic_monitor_request_cc ( struct ast_cc_monitor monitor,
int *  available_timer_id 
)
static

Definition at line 1520 of file ccss.c.

1521 {
1522  struct generic_monitor_instance_list *generic_list;
1523  struct generic_monitor_instance *generic_instance;
1524  struct generic_monitor_pvt *gen_mon_pvt;
1526  int when;
1527 
1528  /* First things first. Native channel drivers will have their private data allocated
1529  * at the time that they tell the core that they can offer CC. Generic is quite a bit
1530  * different, and we wait until this point to allocate our private data.
1531  */
1532  if (!(gen_mon_pvt = ast_calloc(1, sizeof(*gen_mon_pvt)))) {
1533  return -1;
1534  }
1535 
1536  if (!(gen_mon_pvt->device_name = ast_strdup(monitor->interface->device_name))) {
1537  ast_free(gen_mon_pvt);
1538  return -1;
1539  }
1540 
1541  gen_mon_pvt->core_id = monitor->core_id;
1542 
1543  monitor->private_data = gen_mon_pvt;
1544 
1545  if (!(generic_list = find_generic_monitor_instance_list(monitor->interface->device_name))) {
1546  if (!(generic_list = create_new_generic_list(monitor))) {
1547  return -1;
1548  }
1549  }
1550 
1551  if (!(generic_instance = ast_calloc(1, sizeof(*generic_instance)))) {
1552  /* The generic monitor destructor will take care of the appropriate
1553  * deallocations
1554  */
1555  cc_unref(generic_list, "Generic monitor instance failed to allocate");
1556  return -1;
1557  }
1558  generic_instance->core_id = monitor->core_id;
1559  generic_instance->monitoring = 1;
1560  AST_LIST_INSERT_TAIL(&generic_list->list, generic_instance, next);
1562  ast_get_ccnr_available_timer(monitor->interface->config_params);
1563 
1564  *available_timer_id = ast_sched_add(cc_sched_context, when * 1000,
1565  ast_cc_available_timer_expire, cc_ref(monitor, "Give the scheduler a monitor reference"));
1566  if (*available_timer_id == -1) {
1567  cc_unref(monitor, "Failed to schedule available timer. (monitor)");
1568  cc_unref(generic_list, "Failed to schedule available timer. (generic_list)");
1569  return -1;
1570  }
1571  /* If the new instance was created as CCNR, then that means this device is not currently
1572  * fit for recall even if it previously was.
1573  */
1574  if (service == AST_CC_CCNR || service == AST_CC_CCNL) {
1575  generic_list->fit_for_recall = 0;
1576  }
1577  ast_cc_monitor_request_acked(monitor->core_id, "Generic monitor for %s subscribed to device state.",
1578  monitor->interface->device_name);
1579  cc_unref(generic_list, "Finished with monitor instance reference in request cc callback");
1580  return 0;
1581 }
int ast_cc_available_timer_expire(const void *data)
Scheduler callback for available timer expiration.
Definition: ccss.c:1510
static struct generic_monitor_instance_list * create_new_generic_list(struct ast_cc_monitor *monitor)
Definition: ccss.c:1410
int ast_cc_monitor_request_acked(int core_id, const char *const debug,...)
Indicate that an outbound entity has accepted our CC request.
Definition: ccss.c:3785
ast_cc_service_type
Definition: ccss.h:32
@ AST_CC_CCNL
Definition: ccss.h:40
@ AST_CC_CCNR
Definition: ccss.h:38

References ast_calloc, ast_cc_available_timer_expire(), AST_CC_CCBS, AST_CC_CCNL, AST_CC_CCNR, ast_cc_monitor_request_acked(), ast_free, ast_get_ccbs_available_timer(), ast_get_ccnr_available_timer(), AST_LIST_INSERT_TAIL, ast_sched_add(), ast_strdup, cc_ref(), cc_sched_context, cc_unref(), ast_cc_interface::config_params, ast_cc_monitor::core_id, generic_monitor_instance::core_id, generic_monitor_pvt::core_id, create_new_generic_list(), ast_cc_interface::device_name, generic_monitor_pvt::device_name, find_generic_monitor_instance_list(), generic_monitor_instance_list::fit_for_recall, ast_cc_monitor::interface, generic_monitor_instance_list::list, generic_monitor_instance::monitoring, ast_cc_monitor::private_data, service, and ast_cc_monitor::service_offered.

◆ cc_generic_monitor_suspend()

static int cc_generic_monitor_suspend ( struct ast_cc_monitor monitor)
static

Definition at line 1583 of file ccss.c.

1584 {
1585  struct generic_monitor_instance_list *generic_list;
1586  struct generic_monitor_instance *generic_instance;
1588 
1589  if (!(generic_list = find_generic_monitor_instance_list(monitor->interface->device_name))) {
1590  return -1;
1591  }
1592 
1593  /* First we need to mark this particular monitor as being suspended. */
1594  AST_LIST_TRAVERSE(&generic_list->list, generic_instance, next) {
1595  if (generic_instance->core_id == monitor->core_id) {
1596  generic_instance->is_suspended = 1;
1597  break;
1598  }
1599  }
1600 
1601  /* If the device being suspended is currently in use, then we don't need to
1602  * take any further actions
1603  */
1605  cc_unref(generic_list, "Device is in use. Nothing to do. Unref generic list.");
1606  return 0;
1607  }
1608 
1609  /* If the device is not in use, though, then it may be possible to report the
1610  * device's availability using a different monitor which is monitoring the
1611  * same device
1612  */
1613 
1614  AST_LIST_TRAVERSE(&generic_list->list, generic_instance, next) {
1615  if (!generic_instance->is_suspended) {
1616  ast_cc_monitor_callee_available(generic_instance->core_id, "Generic monitored party has become available");
1617  break;
1618  }
1619  }
1620  cc_unref(generic_list, "Done with generic list in suspend callback");
1621  return 0;
1622 }

References ast_cc_monitor_callee_available(), AST_LIST_TRAVERSE, cc_generic_is_device_available(), cc_unref(), ast_cc_monitor::core_id, generic_monitor_instance::core_id, ast_cc_interface::device_name, find_generic_monitor_instance_list(), ast_cc_monitor::interface, generic_monitor_instance::is_suspended, generic_monitor_instance_list::list, and generic_monitor_instance::next.

◆ cc_generic_monitor_unsuspend()

static int cc_generic_monitor_unsuspend ( struct ast_cc_monitor monitor)
static

Definition at line 1624 of file ccss.c.

1625 {
1626  struct generic_monitor_instance *generic_instance;
1629 
1630  if (!generic_list) {
1631  return -1;
1632  }
1633  /* If the device is currently available, we can immediately announce
1634  * its availability
1635  */
1637  ast_cc_monitor_callee_available(monitor->core_id, "Generic monitored party has become available");
1638  }
1639 
1640  /* In addition, we need to mark this generic_monitor_instance as not being suspended anymore */
1641  AST_LIST_TRAVERSE(&generic_list->list, generic_instance, next) {
1642  if (generic_instance->core_id == monitor->core_id) {
1643  generic_instance->is_suspended = 0;
1644  generic_instance->monitoring = 1;
1645  break;
1646  }
1647  }
1648  cc_unref(generic_list, "Done with generic list in cc_generic_monitor_unsuspend");
1649  return 0;
1650 }

References ast_cc_monitor_callee_available(), AST_LIST_TRAVERSE, cc_generic_is_device_available(), cc_unref(), ast_cc_monitor::core_id, generic_monitor_instance::core_id, ast_cc_interface::device_name,