#include "asterisk.h"
#include <sys/time.h>
#include <sys/signal.h>
#include <netinet/in.h>
#include <ctype.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/app.h"
#include "asterisk/linkedlists.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/say.h"
#include "asterisk/features.h"
#include "asterisk/musiconhold.h"
#include "asterisk/cli.h"
#include "asterisk/manager.h"
#include "asterisk/config.h"
#include "asterisk/monitor.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/astdb.h"
#include "asterisk/devicestate.h"
#include "asterisk/stringfields.h"
#include "asterisk/event.h"
#include "asterisk/astobj2.h"
#include "asterisk/strings.h"
#include "asterisk/global_datastores.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/aoc.h"
#include "asterisk/callerid.h"
#include "asterisk/cel.h"
#include "asterisk/data.h"

Go to the source code of this file.
Data Structures | |
| struct | autopause |
| struct | call_queue |
| struct | callattempt |
| We define a custom "local user" structure because we use it not only for keeping track of what is in use but also for keeping track of who we're dialing. More... | |
| struct | member |
| struct | penalty_rule |
| struct | queue_end_bridge |
| struct | queue_ent |
| struct | queue_transfer_ds |
| struct | rule_list |
| struct | rule_lists |
| struct | statechange |
| struct | strategy |
Defines | |
| #define | ANNOUNCEHOLDTIME_ALWAYS 1 |
| #define | ANNOUNCEHOLDTIME_ONCE 2 |
| #define | ANNOUNCEPOSITION_LIMIT 4 |
| #define | ANNOUNCEPOSITION_MORE_THAN 3 |
| #define | ANNOUNCEPOSITION_NO 2 |
| #define | ANNOUNCEPOSITION_YES 1 |
| #define | AST_MAX_WATCHERS 256 |
| #define | DATA_EXPORT_CALL_QUEUE(MEMBER) |
| #define | DATA_EXPORT_MEMBER(MEMBER) |
| #define | DATA_EXPORT_QUEUE_ENT(MEMBER) |
| #define | DEFAULT_MIN_ANNOUNCE_FREQUENCY 15 |
| #define | DEFAULT_RETRY 5 |
| #define | DEFAULT_TIMEOUT 15 |
| #define | MAX_PERIODIC_ANNOUNCEMENTS 10 |
| #define | MAX_QUEUE_BUCKETS 53 |
| #define | PM_MAX_LEN 8192 |
| #define | QUEUE_EVENT_VARIABLES 3 |
| #define | queue_t_ref(a, b) queue_ref(a) |
| #define | queue_t_unref(a, b) queue_unref(a) |
| #define | queues_t_link(c, q, tag) ao2_t_link(c,q,tag) |
| #define | queues_t_unlink(c, q, tag) ao2_t_unlink(c,q,tag) |
| #define | RECHECK 1 |
| #define | RES_EXISTS (-1) |
| #define | RES_NOSUCHQUEUE (-3) |
| #define | RES_NOT_DYNAMIC (-4) |
| #define | RES_OKAY 0 |
| #define | RES_OUTOFMEMORY (-2) |
Enumerations | |
| enum | { QUEUE_STRATEGY_RINGALL = 0, QUEUE_STRATEGY_LEASTRECENT, QUEUE_STRATEGY_FEWESTCALLS, QUEUE_STRATEGY_RANDOM, QUEUE_STRATEGY_RRMEMORY, QUEUE_STRATEGY_LINEAR, QUEUE_STRATEGY_WRANDOM } |
| enum | { QUEUE_AUTOPAUSE_OFF = 0, QUEUE_AUTOPAUSE_ON, QUEUE_AUTOPAUSE_ALL } |
| enum | agent_complete_reason { CALLER, AGENT, TRANSFER } |
| enum | empty_conditions { QUEUE_EMPTY_PENALTY = (1 << 0), QUEUE_EMPTY_PAUSED = (1 << 1), QUEUE_EMPTY_INUSE = (1 << 2), QUEUE_EMPTY_RINGING = (1 << 3), QUEUE_EMPTY_UNAVAILABLE = (1 << 4), QUEUE_EMPTY_INVALID = (1 << 5), QUEUE_EMPTY_UNKNOWN = (1 << 6), QUEUE_EMPTY_WRAPUP = (1 << 7) } |
| enum | queue_reload_mask { QUEUE_RELOAD_PARAMETERS = (1 << 0), QUEUE_RELOAD_MEMBER = (1 << 1), QUEUE_RELOAD_RULES = (1 << 2), QUEUE_RESET_STATS = (1 << 3) } |
| enum | queue_result { QUEUE_UNKNOWN = 0, QUEUE_TIMEOUT = 1, QUEUE_JOINEMPTY = 2, QUEUE_LEAVEEMPTY = 3, QUEUE_JOINUNAVAIL = 4, QUEUE_LEAVEUNAVAIL = 5, QUEUE_FULL = 6, QUEUE_CONTINUE = 7 } |
| enum | queue_timeout_priority { TIMEOUT_PRIORITY_APP, TIMEOUT_PRIORITY_CONF } |
Functions | |
| static char * | __queues_show (struct mansession *s, int fd, int argc, const char *const *argv) |
| Show queue(s) status and statistics. | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static int | add_to_queue (const char *queuename, const char *interface, const char *membername, int penalty, int paused, int dump, const char *state_interface) |
| Add member to queue. | |
| static struct call_queue * | alloc_queue (const char *queuename) |
| static int | aqm_exec (struct ast_channel *chan, const char *data) |
| AddQueueMember application. | |
| AST_DATA_STRUCTURE (queue_ent, DATA_EXPORT_QUEUE_ENT) | |
| AST_DATA_STRUCTURE (member, DATA_EXPORT_MEMBER) | |
| AST_DATA_STRUCTURE (call_queue, DATA_EXPORT_CALL_QUEUE) | |
| static int | attended_transfer_occurred (struct ast_channel *chan) |
| mechanism to tell if a queue caller was atxferred by a queue member. | |
| static int | autopause2int (const char *autopause) |
| static int | calc_metric (struct call_queue *q, struct member *mem, int pos, struct queue_ent *qe, struct callattempt *tmp) |
| Calculate the metric of each member in the outgoing callattempts. | |
| static void | callattempt_free (struct callattempt *doomed) |
| static void | clear_queue (struct call_queue *q) |
| static int | clear_stats (const char *queuename) |
| Facilitates resetting statistics for a queue. | |
| static int | compare_weight (struct call_queue *rq, struct member *member) |
| static char * | complete_queue (const char *line, const char *word, int pos, int state) |
| static char * | complete_queue_add_member (const char *line, const char *word, int pos, int state) |
| static char * | complete_queue_pause_member (const char *line, const char *word, int pos, int state) |
| static char * | complete_queue_remove_member (const char *line, const char *word, int pos, int state) |
| static char * | complete_queue_rule_show (const char *line, const char *word, int pos, int state) |
| static char * | complete_queue_set_member_penalty (const char *line, const char *word, int pos, int state) |
| static char * | complete_queue_show (const char *line, const char *word, int pos, int state) |
| static int | compress_char (const char c) |
| static void | copy_rules (struct queue_ent *qe, const char *rulename) |
| Copy rule from global list into specified queue. | |
| static struct member * | create_queue_member (const char *interface, const char *membername, int penalty, int paused, const char *state_interface) |
| allocate space for new queue member and set fields based on parameters passed | |
| static void | destroy_queue (void *obj) |
| Free queue's member list then its string fields. | |
| static void | device_state_cb (const struct ast_event *event, void *unused) |
| static void | do_hang (struct callattempt *o) |
| common hangup actions | |
| static void | do_print (struct mansession *s, int fd, const char *str) |
| direct ouput to manager or cli with proper terminator | |
| static void | dump_queue_members (struct call_queue *pm_queue) |
| Dump all members in a specific queue to the database. | |
| static void | end_bridge_callback (void *data) |
| static void | end_bridge_callback_data_fixup (struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) |
| static int | extension_state_cb (char *context, char *exten, enum ast_extension_states state, void *data) |
| static int | extensionstate2devicestate (int state) |
| Helper function which converts from extension state to device state values. | |
| static struct callattempt * | find_best (struct callattempt *outgoing) |
| find the entry with the best metric, or NULL | |
| static struct call_queue * | find_queue_by_name_rt (const char *queuename, struct ast_variable *queue_vars, struct ast_config *member_config) |
| Reload a single queue via realtime. | |
| static void | free_members (struct call_queue *q, int all) |
| Iterate through queue's member list and delete them. | |
| static int | get_member_penalty (char *queuename, char *interface) |
| static int | get_member_status (struct call_queue *q, int max_penalty, int min_penalty, enum empty_conditions conditions) |
| Check if members are available. | |
| static int | get_queue_member_status (struct member *cur) |
| Return the current state of a member. | |
| static char * | handle_queue_add_member (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_queue_pause_member (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_queue_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_queue_remove_member (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_queue_reset (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_queue_rule_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_queue_set_member_penalty (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static int | handle_statechange (void *datap) |
| set a member's status based on device state of that member's interface | |
| static void | hangupcalls (struct callattempt *outgoing, struct ast_channel *exception, int cancel_answered_elsewhere) |
| Hang up a list of outgoing calls. | |
| static void | init_queue (struct call_queue *q) |
| Initialize Queue default values. | |
| static void | insert_entry (struct call_queue *q, struct queue_ent *prev, struct queue_ent *new, int *pos) |
| Insert the 'new' entry after the 'prev' entry of queue 'q'. | |
| static int | insert_penaltychange (const char *list_name, const char *content, const int linenum) |
| Change queue penalty by adding rule. | |
| static const char * | int2strat (int strategy) |
| static struct member * | interface_exists (struct call_queue *q, const char *interface) |
| static int | is_our_turn (struct queue_ent *qe) |
| Check if we should start attempting to call queue members. | |
| static int | join_queue (char *queuename, struct queue_ent *qe, enum queue_result *reason, int position) |
| static int | kill_dead_members (void *obj, void *arg, int flags) |
| static int | kill_dead_queues (void *obj, void *arg, int flags) |
| static void | leave_queue (struct queue_ent *qe) |
| Caller leaving queue. | |
| static int | load_module (void) |
| static struct call_queue * | load_realtime_queue (const char *queuename) |
| static int | manager_add_queue_member (struct mansession *s, const struct message *m) |
| static int | manager_pause_queue_member (struct mansession *s, const struct message *m) |
| static int | manager_queue_log_custom (struct mansession *s, const struct message *m) |
| static int | manager_queue_member_penalty (struct mansession *s, const struct message *m) |
| static int | manager_queue_reload (struct mansession *s, const struct message *m) |
| static int | manager_queue_reset (struct mansession *s, const struct message *m) |
| static int | manager_queue_rule_show (struct mansession *s, const struct message *m) |
| static int | manager_queues_show (struct mansession *s, const struct message *m) |
| static int | manager_queues_status (struct mansession *s, const struct message *m) |
| Queue status info via AMI. | |
| static int | manager_queues_summary (struct mansession *s, const struct message *m) |
| Summary of queue info via the AMI. | |
| static int | manager_remove_queue_member (struct mansession *s, const struct message *m) |
| static int | mark_dead_and_unfound (void *obj, void *arg, int flags) |
| static int | mark_member_dead (void *obj, void *arg, int flags) |
| static int | member_cmp_fn (void *obj1, void *obj2, int flags) |
| static int | member_hash_fn (const void *obj, const int flags) |
| static int | num_available_members (struct call_queue *q) |
| Get the number of members available to accept a call. | |
| static void | parse_empty_options (const char *value, enum empty_conditions *empty, int joinempty) |
| static int | play_file (struct ast_channel *chan, const char *filename) |
| static int | pqm_exec (struct ast_channel *chan, const char *data) |
| PauseQueueMember application. | |
| static int | ql_exec (struct ast_channel *chan, const char *data) |
| QueueLog application. | |
| static int | queue_cmp_cb (void *obj, void *arg, int flags) |
| static int | queue_exec (struct ast_channel *chan, const char *data) |
| The starting point for all queue calls. | |
| static int | queue_function_exists (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| Check if a given queue exists. | |
| static int | queue_function_memberpenalty_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| Dialplan function QUEUE_MEMBER_PENALTY() Gets the members penalty. | |
| static int | queue_function_memberpenalty_write (struct ast_channel *chan, const char *cmd, char *data, const char *value) |
| Dialplan function QUEUE_MEMBER_PENALTY() Sets the members penalty. | |
| static int | queue_function_qac (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| Get number either busy / free / ready or total members of a specific queue. | |
| static int | queue_function_qac_dep (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| Get the total number of members in a specific queue (Deprecated). | |
| static int | queue_function_queuememberlist (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| Dialplan function QUEUE_MEMBER_LIST() Get list of members in a specific queue. | |
| static int | queue_function_queuewaitingcount (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| Dialplan function QUEUE_WAITING_COUNT() Get number callers waiting in a specific queue. | |
| static int | queue_function_var (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| create interface var with all queue details. | |
| static int | queue_hash_cb (const void *obj, const int flags) |
| static struct call_queue * | queue_ref (struct call_queue *q) |
| static void | queue_set_global_params (struct ast_config *cfg) |
| static void | queue_set_param (struct call_queue *q, const char *param, const char *val, int linenum, int failunknown) |
| Configure a queue parameter. | |
| static char * | queue_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static void | queue_transfer_destroy (void *data) |
| static void | queue_transfer_fixup (void *data, struct ast_channel *old_chan, struct ast_channel *new_chan) |
| Log an attended transfer when a queue caller channel is masqueraded. | |
| static struct call_queue * | queue_unref (struct call_queue *q) |
| static int | queues_data_provider_get (const struct ast_data_search *search, struct ast_data *data_root) |
| static void | queues_data_provider_get_helper (const struct ast_data_search *search, struct ast_data *data_root, struct call_queue *queue) |
| static void | recalc_holdtime (struct queue_ent *qe, int newholdtime) |
| static void | record_abandoned (struct queue_ent *qe) |
| Record that a caller gave up on waiting in queue. | |
| static int | reload (void) |
| static int | reload_handler (int reload, struct ast_flags *mask, const char *queuename) |
| The command center for all reload operations. | |
| static void | reload_queue_members (void) |
| Reload dynamic queue members persisted into the astdb. | |
| static int | reload_queue_rules (int reload) |
| Reload the rules defined in queuerules.conf. | |
| static int | reload_queues (int reload, struct ast_flags *mask, const char *queuename) |
| reload the queues.conf file | |
| static void | reload_single_member (const char *memberdata, struct call_queue *q) |
| reload information pertaining to a single member | |
| static void | reload_single_queue (struct ast_config *cfg, struct ast_flags *mask, const char *queuename) |
| Reload information pertaining to a particular queue. | |
| static int | remove_from_queue (const char *queuename, const char *interface) |
| Remove member from queue. | |
| static int | ring_entry (struct queue_ent *qe, struct callattempt *tmp, int *busies) |
| Part 2 of ring_one. | |
| static int | ring_one (struct queue_ent *qe, struct callattempt *outgoing, int *busies) |
| Place a call to a queue member. | |
| static void | rna (int rnatime, struct queue_ent *qe, char *interface, char *membername, int pause) |
| RNA == Ring No Answer. Common code that is executed when we try a queue member and they don't answer. | |
| static int | rqm_exec (struct ast_channel *chan, const char *data) |
| RemoveQueueMember application. | |
| static void | rt_handle_member_record (struct call_queue *q, char *interface, const char *rt_uniqueid, const char *membername, const char *penalty_str, const char *paused_str, const char *state_interface) |
| Find rt member record to update otherwise create one. | |
| static int | say_periodic_announcement (struct queue_ent *qe, int ringing) |
| Playback announcement to queued members if peroid has elapsed. | |
| static int | say_position (struct queue_ent *qe, int ringing) |
| static void | send_agent_complete (const struct queue_ent *qe, const char *queuename, const struct ast_channel *peer, const struct member *member, time_t callstart, char *vars, size_t vars_len, enum agent_complete_reason rsn) |
| Send out AMI message with member call completion status information. | |
| static int | set_member_paused (const char *queuename, const char *interface, const char *reason, int paused) |
| static int | set_member_penalty (const char *queuename, const char *interface, int penalty) |
| static void | set_queue_result (struct ast_channel *chan, enum queue_result res) |
| sets the QUEUESTATUS channel variable | |
| static void | set_queue_variables (struct call_queue *q, struct ast_channel *chan) |
| Set variables of queue. | |
| static struct ast_datastore * | setup_transfer_datastore (struct queue_ent *qe, struct member *member, time_t starttime, int callcompletedinsl) |
| create a datastore for storing relevant info to log attended transfers in the queue_log | |
| static int | store_next_lin (struct queue_ent *qe, struct callattempt *outgoing) |
| Search for best metric and add to Linear queue. | |
| static int | store_next_rr (struct queue_ent *qe, struct callattempt *outgoing) |
| Search for best metric and add to Round Robbin queue. | |
| static int | strat2int (const char *strategy) |
| static int | try_calling (struct queue_ent *qe, const char *options, char *announceoverride, const char *url, int *tries, int *noption, const char *agi, const char *macro, const char *gosub, int ringing) |
| A large function which calls members, updates statistics, and bridges the caller and a member. | |
| static int | unload_module (void) |
| static void | update_qe_rule (struct queue_ent *qe) |
| update rules for queues | |
| static int | update_queue (struct call_queue *q, struct member *member, int callcompletedinsl, int newtalktime) |
| update the queue status | |
| static int | update_realtime_member_field (struct member *mem, const char *queue_name, const char *field, const char *value) |
| static void | update_realtime_members (struct call_queue *q) |
| static int | update_status (struct call_queue *q, struct member *m, const int status) |
| set a member's status based on device state of that member's state_interface. | |
| static int | upqm_exec (struct ast_channel *chan, const char *data) |
| UnPauseQueueMember application. | |
| static int | valid_exit (struct queue_ent *qe, char digit) |
| Check for valid exit from queue via goto. | |
| static char * | vars2manager (struct ast_channel *chan, char *vars, size_t len) |
| convert "\n" to "\nVariable: " ready for manager to use | |
| static int | wait_a_bit (struct queue_ent *qe) |
| static struct callattempt * | wait_for_answer (struct queue_ent *qe, struct callattempt *outgoing, int *to, char *digit, int prebusies, int caller_disconnect, int forwardsallowed, int update_connectedline) |
| Wait for a member to answer the call. | |
| static int | wait_our_turn (struct queue_ent *qe, int ringing, enum queue_result *reason) |
| The waiting areas for callers who are not actively calling members. | |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "True Call Queueing" , .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, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_DEVSTATE_CONSUMER, .nonoptreq = "res_monitor", } |
| static char * | app = "Queue" |
| static char * | app_aqm = "AddQueueMember" |
| static char * | app_pqm = "PauseQueueMember" |
| static char * | app_ql = "QueueLog" |
| static char * | app_rqm = "RemoveQueueMember" |
| static char * | app_upqm = "UnpauseQueueMember" |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static int | autofill_default = 1 |
| queues.conf [general] option | |
| static struct autopause | autopausesmodes [] |
| static struct ast_cli_entry | cli_queue [] |
| static struct ast_event_sub * | device_state_sub |
| Subscription to device state change events. | |
| static struct ast_taskprocessor * | devicestate_tps |
| static int | montype_default = 0 |
| queues.conf [general] option | |
| static const char *const | pm_family = "Queue/PersistentMembers" |
| Persistent Members astdb family. | |
| static const char | qpm_cmd_usage [] |
| static const char | qsmp_cmd_usage [] |
| static struct ast_data_entry | queue_data_providers [] |
| static int | queue_persistent_members = 0 |
| queues.conf [general] option | |
| struct { | |
| enum queue_result id | |
| char * text | |
| } | queue_results [] |
| static struct ast_datastore_info | queue_transfer_info |
| a datastore used to help correctly log attended transfers of queue callers | |
| static struct ast_custom_function | queueexists_function |
| static struct ast_custom_function | queuemembercount_dep |
| static struct ast_custom_function | queuemembercount_function |
| static struct ast_custom_function | queuememberlist_function |
| static struct ast_custom_function | queuememberpenalty_function |
| static struct ao2_container * | queues |
| static struct ast_data_handler | queues_data_provider |
| static struct ast_custom_function | queuevar_function |
| static struct ast_custom_function | queuewaitingcount_function |
| static const char | qum_cmd_usage [] |
| static int | shared_lastcall = 1 |
| queues.conf [general] option | |
| static struct strategy | strategies [] |
| static int | update_cdr = 0 |
| queues.conf [general] option | |
| static int | use_weight = 0 |
| queues.conf per-queue weight option | |
These features added by David C. Troy <dave@toad.net>:
Added servicelevel statistic by Michiel Betel <michiel@betel.nl> Added Priority jumping code for adding and removing queue members by Jonathan Stanton <asterisk@doilooklikeicare.com>
Fixed to work with CVS as of 2004-02-25 and released as 1.07a by Matthew Enger <m.enger@xi.com.au>
Definition in file app_queue.c.
| #define ANNOUNCEHOLDTIME_ALWAYS 1 |
| #define ANNOUNCEHOLDTIME_ONCE 2 |
| #define ANNOUNCEPOSITION_LIMIT 4 |
We not announce position more than <limit>
Definition at line 916 of file app_queue.c.
Referenced by queue_set_param(), queues_data_provider_get_helper(), and say_position().
| #define ANNOUNCEPOSITION_MORE_THAN 3 |
We say "Currently there are more than <limit>"
Definition at line 915 of file app_queue.c.
Referenced by queue_set_param(), queues_data_provider_get_helper(), and say_position().
| #define ANNOUNCEPOSITION_NO 2 |
We don't announce position
Definition at line 914 of file app_queue.c.
Referenced by queue_set_param(), and queues_data_provider_get_helper().
| #define ANNOUNCEPOSITION_YES 1 |
We announce position
Definition at line 913 of file app_queue.c.
Referenced by init_queue(), queue_set_param(), queues_data_provider_get_helper(), and say_position().
| #define AST_MAX_WATCHERS 256 |
Definition at line 3243 of file app_queue.c.
| #define DATA_EXPORT_CALL_QUEUE | ( | MEMBER | ) |
Definition at line 7800 of file app_queue.c.
| #define DATA_EXPORT_MEMBER | ( | MEMBER | ) |
Definition at line 7865 of file app_queue.c.
| #define DATA_EXPORT_QUEUE_ENT | ( | MEMBER | ) |
Definition at line 7879 of file app_queue.c.
| #define DEFAULT_MIN_ANNOUNCE_FREQUENCY 15 |
The minimum number of seconds between position announcements \ The default value of 15 provides backwards compatibility
Definition at line 729 of file app_queue.c.
Referenced by init_queue().
| #define DEFAULT_RETRY 5 |
| #define DEFAULT_TIMEOUT 15 |
| #define MAX_PERIODIC_ANNOUNCEMENTS 10 |
The maximum periodic announcements we can have
Definition at line 728 of file app_queue.c.
Referenced by destroy_queue(), init_queue(), and queue_set_param().
| #define MAX_QUEUE_BUCKETS 53 |
| #define PM_MAX_LEN 8192 |
Definition at line 754 of file app_queue.c.
Referenced by dump_queue_members(), and reload_queue_members().
| #define QUEUE_EVENT_VARIABLES 3 |
Definition at line 902 of file app_queue.c.
Referenced by queue_set_param(), ring_entry(), rna(), send_agent_complete(), and try_calling().
| #define queue_t_ref | ( | a, | |||
| b | ) | queue_ref(a) |
| #define queue_t_unref | ( | a, | |||
| b | ) | queue_unref(a) |
Definition at line 1115 of file app_queue.c.
Referenced by __queues_show(), add_to_queue(), alloc_queue(), clear_stats(), compare_weight(), complete_queue(), complete_queue_remove_member(), end_bridge_callback(), extension_state_cb(), find_queue_by_name_rt(), get_member_penalty(), handle_statechange(), leave_queue(), manager_queues_status(), manager_queues_summary(), queue_function_exists(), queue_function_qac(), queue_function_qac_dep(), queue_function_queuememberlist(), queue_function_queuewaitingcount(), queue_function_var(), reload_queue_members(), reload_single_queue(), remove_from_queue(), set_member_paused(), set_member_penalty(), unload_module(), and update_queue().
| #define queues_t_link | ( | c, | |||
| q, | |||||
| tag | ) | ao2_t_link(c,q,tag) |
Definition at line 1116 of file app_queue.c.
Referenced by find_queue_by_name_rt(), and reload_single_queue().
| #define queues_t_unlink | ( | c, | |||
| q, | |||||
| tag | ) | ao2_t_unlink(c,q,tag) |
Definition at line 1117 of file app_queue.c.
Referenced by find_queue_by_name_rt(), leave_queue(), and unload_module().
| #define RECHECK 1 |
Recheck every second to see we we're at the top yet
Definition at line 727 of file app_queue.c.
Referenced by wait_our_turn().
| #define RES_EXISTS (-1) |
Entry already exists
Definition at line 734 of file app_queue.c.
Referenced by add_to_queue(), aqm_exec(), handle_queue_add_member(), handle_queue_remove_member(), manager_add_queue_member(), manager_remove_queue_member(), remove_from_queue(), and rqm_exec().
| #define RES_NOSUCHQUEUE (-3) |
No such queue
Definition at line 736 of file app_queue.c.
Referenced by add_to_queue(), aqm_exec(), handle_queue_add_member(), handle_queue_remove_member(), manager_add_queue_member(), manager_remove_queue_member(), remove_from_queue(), and rqm_exec().
| #define RES_NOT_DYNAMIC (-4) |
Member is not dynamic
Definition at line 737 of file app_queue.c.
Referenced by handle_queue_add_member(), handle_queue_remove_member(), manager_remove_queue_member(), remove_from_queue(), and rqm_exec().
| #define RES_OKAY 0 |
Action completed
Definition at line 733 of file app_queue.c.
Referenced by add_to_queue(), aqm_exec(), handle_queue_add_member(), handle_queue_remove_member(), manager_add_queue_member(), manager_remove_queue_member(), remove_from_queue(), and rqm_exec().
| #define RES_OUTOFMEMORY (-2) |
Out of memory
Definition at line 735 of file app_queue.c.
Referenced by add_to_queue(), aqm_exec(), handle_queue_add_member(), handle_queue_remove_member(), manager_add_queue_member(), manager_remove_queue_member(), and reload_queue_members().
| anonymous enum |
| QUEUE_STRATEGY_RINGALL | |
| QUEUE_STRATEGY_LEASTRECENT | |
| QUEUE_STRATEGY_FEWESTCALLS | |
| QUEUE_STRATEGY_RANDOM | |
| QUEUE_STRATEGY_RRMEMORY | |
| QUEUE_STRATEGY_LINEAR | |
| QUEUE_STRATEGY_WRANDOM |
Definition at line 676 of file app_queue.c.
00676 { 00677 QUEUE_STRATEGY_RINGALL = 0, 00678 QUEUE_STRATEGY_LEASTRECENT, 00679 QUEUE_STRATEGY_FEWESTCALLS, 00680 QUEUE_STRATEGY_RANDOM, 00681 QUEUE_STRATEGY_RRMEMORY, 00682 QUEUE_STRATEGY_LINEAR, 00683 QUEUE_STRATEGY_WRANDOM 00684 };
| anonymous enum |
Definition at line 686 of file app_queue.c.
00686 { 00687 QUEUE_AUTOPAUSE_OFF = 0, 00688 QUEUE_AUTOPAUSE_ON, 00689 QUEUE_AUTOPAUSE_ALL 00690 };
| enum empty_conditions |
| QUEUE_EMPTY_PENALTY | |
| QUEUE_EMPTY_PAUSED | |
| QUEUE_EMPTY_INUSE | |
| QUEUE_EMPTY_RINGING | |
| QUEUE_EMPTY_UNAVAILABLE | |
| QUEUE_EMPTY_INVALID | |
| QUEUE_EMPTY_UNKNOWN | |
| QUEUE_EMPTY_WRAPUP |
Definition at line 888 of file app_queue.c.
00888 { 00889 QUEUE_EMPTY_PENALTY = (1 << 0), 00890 QUEUE_EMPTY_PAUSED = (1 << 1), 00891 QUEUE_EMPTY_INUSE = (1 << 2), 00892 QUEUE_EMPTY_RINGING = (1 << 3), 00893 QUEUE_EMPTY_UNAVAILABLE = (1 << 4), 00894 QUEUE_EMPTY_INVALID = (1 << 5), 00895 QUEUE_EMPTY_UNKNOWN = (1 << 6), 00896 QUEUE_EMPTY_WRAPUP = (1 << 7), 00897 };
| enum queue_reload_mask |
Definition at line 692 of file app_queue.c.
00692 { 00693 QUEUE_RELOAD_PARAMETERS = (1 << 0), 00694 QUEUE_RELOAD_MEMBER = (1 << 1), 00695 QUEUE_RELOAD_RULES = (1 << 2), 00696 QUEUE_RESET_STATS = (1 << 3), 00697 };
| enum queue_result |
| QUEUE_UNKNOWN | |
| QUEUE_TIMEOUT | |
| QUEUE_JOINEMPTY | |
| QUEUE_LEAVEEMPTY | |
| QUEUE_JOINUNAVAIL | |
| QUEUE_LEAVEUNAVAIL | |
| QUEUE_FULL | |
| QUEUE_CONTINUE |
Definition at line 777 of file app_queue.c.
00777 { 00778 QUEUE_UNKNOWN = 0, 00779 QUEUE_TIMEOUT = 1, 00780 QUEUE_JOINEMPTY = 2, 00781 QUEUE_LEAVEEMPTY = 3, 00782 QUEUE_JOINUNAVAIL = 4, 00783 QUEUE_LEAVEUNAVAIL = 5, 00784 QUEUE_FULL = 6, 00785 QUEUE_CONTINUE = 7, 00786 };
Definition at line 802 of file app_queue.c.
00802 { 00803 TIMEOUT_PRIORITY_APP, 00804 TIMEOUT_PRIORITY_CONF, 00805 };
| static char* __queues_show | ( | struct mansession * | s, | |
| int | fd, | |||
| int | argc, | |||
| const char *const * | argv | |||
| ) | [static] |
Show queue(s) status and statistics.
List the queues strategy, calls processed, members logged in, other queue statistics such as avg hold time.
Definition at line 6712 of file app_queue.c.
References ao2_container_count(), ao2_iterator_destroy(), AO2_ITERATOR_DONTLOCK, ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_t_iterator_next, ao2_unlock, ast_category_browse(), ast_check_realtime(), ast_config_destroy(), ast_devstate2str(), ast_load_realtime_multientry(), ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_strlen_zero(), member::calls, call_queue::callsabandoned, call_queue::callscompleted, call_queue::callscompletedinsl, queue_ent::chan, CLI_SHOWUSAGE, CLI_SUCCESS, call_queue::count, do_print(), member::dynamic, call_queue::head, call_queue::holdtime, int2strat(), member::interface, member::lastcall, load_realtime_queue(), call_queue::maxlen, member::membername, call_queue::members, ast_channel::name, call_queue::name, queue_ent::next, member::paused, member::penalty, queue_ent::pos, queue_ent::prio, queue_t_unref, queues, member::realtime, call_queue::realtime, SENTINEL, call_queue::servicelevel, queue_ent::start, member::status, call_queue::strategy, call_queue::talktime, and call_queue::weight.
Referenced by manager_queues_show(), and queue_show().
06713 { 06714 struct call_queue *q; 06715 struct ast_str *out = ast_str_alloca(240); 06716 int found = 0; 06717 time_t now = time(NULL); 06718 struct ao2_iterator queue_iter; 06719 struct ao2_iterator mem_iter; 06720 06721 if (argc != 2 && argc != 3) 06722 return CLI_SHOWUSAGE; 06723 06724 if (argc == 3) { /* specific queue */ 06725 if ((q = load_realtime_queue(argv[2]))) { 06726 queue_t_unref(q, "Done with temporary pointer"); 06727 } 06728 } else if (ast_check_realtime("queues")) { 06729 /* This block is to find any queues which are defined in realtime but 06730 * which have not yet been added to the in-core container 06731 */ 06732 struct ast_config *cfg = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL); 06733 char *queuename; 06734 if (cfg) { 06735 for (queuename = ast_category_browse(cfg, NULL); !ast_strlen_zero(queuename); queuename = ast_category_browse(cfg, queuename)) { 06736 if ((q = load_realtime_queue(queuename))) { 06737 queue_t_unref(q, "Done with temporary pointer"); 06738 } 06739 } 06740 ast_config_destroy(cfg); 06741 } 06742 } 06743 06744 queue_iter = ao2_iterator_init(queues, AO2_ITERATOR_DONTLOCK); 06745 ao2_lock(queues); 06746 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) { 06747 float sl; 06748 struct call_queue *realtime_queue = NULL; 06749 06750 ao2_lock(q); 06751 /* This check is to make sure we don't print information for realtime 06752 * queues which have been deleted from realtime but which have not yet 06753 * been deleted from the in-core container 06754 */ 06755 if (q->realtime && !(realtime_queue = load_realtime_queue(q->name))) { 06756 ao2_unlock(q); 06757 queue_t_unref(q, "Done with iterator"); 06758 continue; 06759 } else if (q->realtime) { 06760 queue_t_unref(realtime_queue, "Queue is already in memory"); 06761 } 06762 if (argc == 3 && strcasecmp(q->name, argv[2])) { 06763 ao2_unlock(q); 06764 queue_t_unref(q, "Done with iterator"); 06765 continue; 06766 } 06767 found = 1; 06768 06769 ast_str_set(&out, 0, "%s has %d calls (max ", q->name, q->count); 06770 if (q->maxlen) 06771 ast_str_append(&out, 0, "%d", q->maxlen); 06772 else 06773 ast_str_append(&out, 0, "unlimited"); 06774 sl = 0; 06775 if (q->callscompleted > 0) 06776 sl = 100 * ((float) q->callscompletedinsl / (float) q->callscompleted); 06777 ast_str_append(&out, 0, ") in '%s' strategy (%ds holdtime, %ds talktime), W:%d, C:%d, A:%d, SL:%2.1f%% within %ds", 06778 int2strat(q->strategy), q->holdtime, q->talktime, q->weight, 06779 q->callscompleted, q->callsabandoned,sl,q->servicelevel); 06780 do_print(s, fd, ast_str_buffer(out)); 06781 if (!ao2_container_count(q->members)) 06782 do_print(s, fd, " No Members"); 06783 else { 06784 struct member *mem; 06785 06786 do_print(s, fd, " Members: "); 06787 mem_iter = ao2_iterator_init(q->members, 0); 06788 while ((mem = ao2_iterator_next(&mem_iter))) { 06789 ast_str_set(&out, 0, " %s", mem->membername); 06790 if (strcasecmp(mem->membername, mem->interface)) { 06791 ast_str_append(&out, 0, " (%s)", mem->interface); 06792 } 06793 if (mem->penalty) 06794 ast_str_append(&out, 0, " with penalty %d", mem->penalty); 06795 ast_str_append(&out, 0, "%s%s%s (%s)", 06796 mem->dynamic ? " (dynamic)" : "", 06797 mem->realtime ? " (realtime)" : "", 06798 mem->paused ? " (paused)" : "", 06799 ast_devstate2str(mem->status)); 06800 if (mem->calls) 06801 ast_str_append(&out, 0, " has taken %d calls (last was %ld secs ago)", 06802 mem->calls, (long) (time(NULL) - mem->lastcall)); 06803 else 06804 ast_str_append(&out, 0, " has taken no calls yet"); 06805 do_print(s, fd, ast_str_buffer(out)); 06806 ao2_ref(mem, -1); 06807 } 06808 ao2_iterator_destroy(&mem_iter); 06809 } 06810 if (!q->head) 06811 do_print(s, fd, " No Callers"); 06812 else { 06813 struct queue_ent *qe; 06814 int pos = 1; 06815 06816 do_print(s, fd, " Callers: "); 06817 for (qe = q->head; qe; qe = qe->next) { 06818 ast_str_set(&out, 0, " %d. %s (wait: %ld:%2.2ld, prio: %d)", 06819 pos++, qe->chan->name, (long) (now - qe->start) / 60, 06820 (long) (now - qe->start) % 60, qe->prio); 06821 do_print(s, fd, ast_str_buffer(out)); 06822 } 06823 } 06824 do_print(s, fd, ""); /* blank line between entries */ 06825 ao2_unlock(q); 06826 queue_t_unref(q, "Done with iterator"); /* Unref the iterator's reference */ 06827 } 06828 ao2_iterator_destroy(&queue_iter); 06829 ao2_unlock(queues); 06830 if (!found) { 06831 if (argc == 3) 06832 ast_str_set(&out, 0, "No such queue: %s.", argv[2]); 06833 else 06834 ast_str_set(&out, 0, "No queues."); 06835 do_print(s, fd, ast_str_buffer(out)); 06836 } 06837 return CLI_SUCCESS; 06838 }
| static void __reg_module | ( | void | ) | [static] |
Definition at line 8200 of file app_queue.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 8200 of file app_queue.c.
| static int add_to_queue | ( | const char * | queuename, | |
| const char * | interface, | |||
| const char * | membername, | |||
| int | penalty, | |||
| int | paused, | |||
| int | dump, | |||
| const char * | state_interface | |||
| ) | [static] |
Add member to queue.
| RES_NOT_DYNAMIC | when they aren't a RT member | |
| RES_NOSUCHQUEUE | queue does not exist | |
| RES_OKAY | added member from queue | |
| RES_EXISTS | queue exists but no members | |
| RES_OUT_OF_MEMORY | queue exists but not enough memory to create member |
Definition at line 5032 of file app_queue.c.
References ao2_link, ao2_lock, ao2_ref, ao2_unlock, member::calls, create_queue_member(), dump_queue_members(), member::dynamic, EVENT_FLAG_AGENT, member::interface, interface_exists(), member::lastcall, load_realtime_queue(), manager_event, call_queue::membercount, member::membername, call_queue::members, call_queue::name, member::paused, member::penalty, queue_t_unref, queues, RES_EXISTS, RES_NOSUCHQUEUE, RES_OKAY, RES_OUTOFMEMORY, and member::status.
Referenced by aqm_exec(), handle_queue_add_member(), manager_add_queue_member(), and reload_queue_members().
05033 { 05034 struct call_queue *q; 05035 struct member *new_member, *old_member; 05036 int res = RES_NOSUCHQUEUE; 05037 05038 /*! \note Ensure the appropriate realtime queue is loaded. Note that this 05039 * short-circuits if the queue is already in memory. */ 05040 if (!(q = load_realtime_queue(queuename))) 05041 return res; 05042 05043 ao2_lock(queues); 05044 05045 ao2_lock(q); 05046 if ((old_member = interface_exists(q, interface)) == NULL) { 05047 if ((new_member = create_queue_member(interface, membername, penalty, paused, state_interface))) { 05048 new_member->dynamic = 1; 05049 ao2_link(q->members, new_member); 05050 q->membercount++; 05051 manager_event(EVENT_FLAG_AGENT, "QueueMemberAdded", 05052 "Queue: %s\r\n" 05053 "Location: %s\r\n" 05054 "MemberName: %s\r\n" 05055 "Membership: %s\r\n" 05056 "Penalty: %d\r\n" 05057 "CallsTaken: %d\r\n" 05058 "LastCall: %d\r\n" 05059 "Status: %d\r\n" 05060 "Paused: %d\r\n", 05061 q->name, new_member->interface, new_member->membername, 05062 "dynamic", 05063 new_member->penalty, new_member->calls, (int) new_member->lastcall, 05064 new_member->status, new_member->paused); 05065 05066 ao2_ref(new_member, -1); 05067 new_member = NULL; 05068 05069 if (dump) 05070 dump_queue_members(q); 05071 05072 res = RES_OKAY; 05073 } else { 05074 res = RES_OUTOFMEMORY; 05075 } 05076 } else { 05077 ao2_ref(old_member, -1); 05078 res = RES_EXISTS; 05079 } 05080 ao2_unlock(q); 05081 ao2_unlock(queues); 05082 queue_t_unref(q, "Expiring temporary reference"); 05083 05084 return res; 05085 }
| static struct call_queue* alloc_queue | ( | const char * | queuename | ) | [static, read] |
Definition at line 2002 of file app_queue.c.
References ao2_t_alloc, ast_string_field_init, ast_string_field_set, destroy_queue(), and queue_t_unref.
Referenced by find_queue_by_name_rt(), and reload_single_queue().
02003 { 02004 struct call_queue *q; 02005 02006 if ((q = ao2_t_alloc(sizeof(*q), destroy_queue, "Allocate queue"))) { 02007 if (ast_string_field_init(q, 64)) { 02008 queue_t_unref(q, "String field allocation failed"); 02009 return NULL; 02010 } 02011 ast_string_field_set(q, name, queuename); 02012 } 02013 return q; 02014 }
| static int aqm_exec | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) | [static] |
AddQueueMember application.
Definition at line 5471 of file app_queue.c.
References add_to_queue(), args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), ast_queue_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::name, parse(), pbx_builtin_setvar_helper(), RES_EXISTS, RES_NOSUCHQUEUE, RES_OKAY, RES_OUTOFMEMORY, and ast_channel::uniqueid.
Referenced by load_module().
05472 { 05473 int res=-1; 05474 char *parse, *temppos = NULL; 05475 AST_DECLARE_APP_ARGS(args, 05476 AST_APP_ARG(queuename); 05477 AST_APP_ARG(interface); 05478 AST_APP_ARG(penalty); 05479 AST_APP_ARG(options); 05480 AST_APP_ARG(membername); 05481 AST_APP_ARG(state_interface); 05482 ); 05483 int penalty = 0; 05484 05485 if (ast_strlen_zero(data)) { 05486 ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename[,interface[,penalty[,options[,membername[,stateinterface]]]]])\n"); 05487 return -1; 05488 } 05489 05490 parse = ast_strdupa(data); 05491 05492 AST_STANDARD_APP_ARGS(args, parse); 05493 05494 if (ast_strlen_zero(args.interface)) { 05495 args.interface = ast_strdupa(chan->name); 05496 temppos = strrchr(args.interface, '-'); 05497 if (temppos) 05498 *temppos = '\0'; 05499 } 05500 05501 if (!ast_strlen_zero(args.penalty)) { 05502 if ((sscanf(args.penalty, "%30d", &penalty) != 1) || penalty < 0) { 05503 ast_log(LOG_WARNING, "Penalty '%s' is invalid, must be an integer >= 0\n", args.penalty); 05504 penalty = 0; 05505 } 05506 } 05507 05508 switch (add_to_queue(args.queuename, args.interface, args.membername, penalty, 0, queue_persistent_members, args.state_interface)) { 05509 case RES_OKAY: 05510 ast_queue_log(args.queuename, chan->uniqueid, args.interface, "ADDMEMBER", "%s", ""); 05511 ast_log(LOG_NOTICE, "Added interface '%s' to queue '%s'\n", args.interface, args.queuename); 05512 pbx_builtin_setvar_helper(chan, "AQMSTATUS", "ADDED"); 05513 res = 0; 05514 break; 05515 case RES_EXISTS: 05516 ast_log(LOG_WARNING, "Unable to add interface '%s' to queue '%s': Already there\n", args.interface, args.queuename); 05517 pbx_builtin_setvar_helper(chan, "AQMSTATUS", "MEMBERALREADY"); 05518 res = 0; 05519 break; 05520 case RES_NOSUCHQUEUE: 05521 ast_log(LOG_WARNING, "Unable to add interface to queue '%s': No such queue\n", args.queuename); 05522 pbx_builtin_setvar_helper(chan, "AQMSTATUS", "NOSUCHQUEUE"); 05523 res = 0; 05524 break; 05525 case RES_OUTOFMEMORY: 05526 ast_log(LOG_ERROR, "Out of memory adding member %s to queue %s\n", args.interface, args.queuename); 05527 break; 05528 } 05529 05530 return res; 05531 }
| AST_DATA_STRUCTURE | ( | queue_ent | , | |
| DATA_EXPORT_QUEUE_ENT | ||||
| ) |
| AST_DATA_STRUCTURE | ( | member | , | |
| DATA_EXPORT_MEMBER | ||||
| ) |
| AST_DATA_STRUCTURE | ( | call_queue | , | |
| DATA_EXPORT_CALL_QUEUE | ||||
| ) |
| static int attended_transfer_occurred | ( | struct ast_channel * | chan | ) | [static] |
mechanism to tell if a queue caller was atxferred by a queue member.
When a caller is atxferred, then the queue_transfer_info datastore is removed from the channel. If it's still there after the bridge is broken, then the caller was not atxferred.
Definition at line 4045 of file app_queue.c.
References ast_channel_datastore_find(), and queue_transfer_info.
Referenced by try_calling().
04046 { 04047 return ast_channel_datastore_find(chan, &queue_transfer_info, NULL) ? 0 : 1; 04048 }
| static int autopause2int | ( | const char * | autopause | ) | [static] |
Definition at line 1073 of file app_queue.c.
References ARRAY_LEN, ast_strlen_zero(), ast_true(), autopausesmodes, QUEUE_AUTOPAUSE_OFF, and QUEUE_AUTOPAUSE_ON.
Referenced by queue_set_param().
01074 { 01075 int x; 01076 /*This 'double check' that default value is OFF */ 01077 if (ast_strlen_zero(autopause)) 01078 return QUEUE_AUTOPAUSE_OFF; 01079 01080 /*This 'double check' is to ensure old values works */ 01081 if(ast_true(autopause)) 01082 return QUEUE_AUTOPAUSE_ON; 01083 01084 for (x = 0; x < ARRAY_LEN(autopausesmodes); x++) { 01085 if (!strcasecmp(autopause, autopausesmodes[x].name)) 01086 return autopausesmodes[x].autopause; 01087 } 01088 01089 /*This 'double check' that default value is OFF */ 01090 return QUEUE_AUTOPAUSE_OFF; 01091 }
| static int calc_metric | ( | struct call_queue * | q, | |
| struct member * | mem, | |||
| int | pos, | |||
| struct queue_ent * | qe, | |||
| struct callattempt * | tmp | |||
| ) | [static] |
Calculate the metric of each member in the outgoing callattempts.
A numeric metric is given to each member depending on the ring strategy used by the queue. Members with lower metrics will be called before members with higher metrics
| -1 | if penalties are exceeded | |
| 0 | otherwise |
Definition at line 3874 of file app_queue.c.
References ast_debug, ast_log(), ast_random(), member::calls, member::lastcall, queue_ent::linpos, queue_ent::linwrapped, LOG_WARNING, queue_ent::max_penalty, call_queue::membercount, callattempt::metric, queue_ent::min_penalty, member::penalty, call_queue::penaltymemberslimit, QUEUE_STRATEGY_FEWESTCALLS, QUEUE_STRATEGY_LEASTRECENT, QUEUE_STRATEGY_LINEAR, QUEUE_STRATEGY_RANDOM, QUEUE_STRATEGY_RINGALL, QUEUE_STRATEGY_RRMEMORY, QUEUE_STRATEGY_WRANDOM, call_queue::rrpos, call_queue::strategy, and call_queue::wrapped.
Referenced by try_calling().
03875 { 03876 /* disregarding penalty on too few members? */ 03877 unsigned char usepenalty = (q->membercount <= q->penaltymemberslimit) ? 0 : 1; 03878 03879 if (usepenalty) { 03880 if ((qe->max_penalty && (mem->penalty > qe->max_penalty)) || 03881 (qe->min_penalty && (mem->penalty < qe->min_penalty))) { 03882 return -1; 03883 } 03884 } else { 03885 ast_debug(1, "Disregarding penalty, %d members and %d in penaltymemberslimit.\n", 03886 q->membercount, q->penaltymemberslimit); 03887 } 03888 03889 switch (q->strategy) { 03890 case QUEUE_STRATEGY_RINGALL: 03891 /* Everyone equal, except for penalty */ 03892 tmp->metric = mem->penalty * 1000000 * usepenalty; 03893 break; 03894 case QUEUE_STRATEGY_LINEAR: 03895 if (pos < qe->linpos) { 03896 tmp->metric = 1000 + pos; 03897 } else { 03898 if (pos > qe->linpos) 03899 /* Indicate there is another priority */ 03900 qe->linwrapped = 1; 03901 tmp->metric = pos; 03902 } 03903 tmp->metric += mem->penalty * 1000000 * usepenalty; 03904 break; 03905 case QUEUE_STRATEGY_RRMEMORY: 03906 if (pos < q->rrpos) { 03907 tmp->metric = 1000 + pos; 03908 } else { 03909 if (pos > q->rrpos) 03910 /* Indicate there is another priority */ 03911 q->wrapped = 1; 03912 tmp->metric = pos; 03913 } 03914 tmp->metric += mem->penalty * 1000000 * usepenalty; 03915 break; 03916 case QUEUE_STRATEGY_RANDOM: 03917 tmp->metric = ast_random() % 1000; 03918 tmp->metric += mem->penalty * 1000000 * usepenalty; 03919 break; 03920 case QUEUE_STRATEGY_WRANDOM: 03921 tmp->metric = ast_random() % ((1 + mem->penalty) * 1000); 03922 break; 03923 case QUEUE_STRATEGY_FEWESTCALLS: 03924 tmp->metric = mem->calls; 03925 tmp->metric += mem->penalty * 1000000 * usepenalty; 03926 break; 03927 case QUEUE_STRATEGY_LEASTRECENT: 03928 if (!mem->lastcall) 03929 tmp->metric = 0; 03930 else 03931 tmp->metric = 1000000 - (time(NULL) - mem->lastcall); 03932 tmp->metric += mem->penalty * 1000000 * usepenalty; 03933 break; 03934 default: 03935 ast_log(LOG_WARNING, "Can't calculate metric for unknown strategy %d\n", q->strategy); 03936 break; 03937 } 03938 return 0; 03939 }
| static void callattempt_free | ( | struct callattempt * | doomed | ) | [static] |
Definition at line 2657 of file app_queue.c.
References ao2_ref, ast_free, ast_party_connected_line_free(), callattempt::connected, and callattempt::member.
Referenced by hangupcalls(), and try_calling().
02658 { 02659 if (doomed->member) { 02660 ao2_ref(doomed->member, -1); 02661 } 02662 ast_party_connected_line_free(&doomed->connected); 02663 ast_free(doomed); 02664 }
| static void clear_queue | ( | struct call_queue * | q | ) | [static] |
Definition at line 1567 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, member::calls, call_queue::callsabandoned, call_queue::callscompleted, call_queue::callscompletedinsl, call_queue::holdtime, member::lastcall, call_queue::members, and call_queue::talktime.
Referenced by clear_stats(), and find_queue_by_name_rt().
01568 { 01569 q->holdtime = 0; 01570 q->callscompleted = 0; 01571 q->callsabandoned = 0; 01572 q->callscompletedinsl = 0; 01573 q->talktime = 0; 01574 01575 if (q->members) { 01576 struct member *mem; 01577 struct ao2_iterator mem_iter = ao2_iterator_init(q->members, 0); 01578 while ((mem = ao2_iterator_next(&mem_iter))) { 01579 mem->calls = 0; 01580 mem->lastcall = 0; 01581 ao2_ref(mem, -1); 01582 } 01583 ao2_iterator_destroy(&mem_iter); 01584 } 01585 }
| static int clear_stats | ( | const char * | queuename | ) | [static] |
Facilitates resetting statistics for a queue.
This function actually does not reset any statistics, but rather finds a call_queue struct which corresponds to the passed-in queue name and passes that structure to the clear_queue function. If no queuename is passed in, then all queues will have their statistics reset.
| queuename | The name of the queue to reset the statistics for. If this is NULL or zero-length, then this means to reset the statistics for all queues |
| void |
Definition at line 6653 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock, ao2_t_iterator_next, ao2_unlock, ast_strlen_zero(), clear_queue(), call_queue::name, queue_t_unref, and queues.
Referenced by reload_handler().
06654 { 06655 struct call_queue *q; 06656 struct ao2_iterator queue_iter = ao2_iterator_init(queues, 0); 06657 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) { 06658 ao2_lock(q); 06659 if (ast_strlen_zero(queuename) || !strcasecmp(q->name, queuename)) 06660 clear_queue(q); 06661 ao2_unlock(q); 06662 queue_t_unref(q, "Done with iterator"); 06663 } 06664 ao2_iterator_destroy(&queue_iter); 06665 return 0; 06666 }
| static int compare_weight | ( | struct call_queue * | rq, | |
| struct member * | member | |||
| ) | [static] |
Definition at line 2737 of file app_queue.c.
References ao2_find, ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock, ao2_ref, ao2_t_iterator_next, ao2_unlock, ast_debug, call_queue::count, member::interface, call_queue::members, call_queue::name, num_available_members(), OBJ_POINTER, queue_t_unref, queues, and call_queue::weight.
Referenced by ring_entry().
02738 { 02739 struct call_queue *q; 02740 struct member *mem; 02741 int found = 0; 02742 struct ao2_iterator queue_iter; 02743 02744 /* q's lock and rq's lock already set by try_calling() 02745 * to solve deadlock */ 02746 queue_iter = ao2_iterator_init(queues, 0); 02747 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) { 02748 if (q == rq) { /* don't check myself, could deadlock */ 02749 queue_t_unref(q, "Done with iterator"); 02750 continue; 02751 } 02752 ao2_lock(q); 02753 if (q->count && q->members) { 02754 if ((mem = ao2_find(q->members, member, OBJ_POINTER))) { 02755 ast_debug(1, "Found matching member %s in queue '%s'\n", mem->interface, q->name); 02756 if (q->weight > rq->weight && q->count >= num_available_members(q)) { 02757 ast_debug(1, "Queue '%s' (weight %d, calls %d) is preferred over '%s' (weight %d, calls %d)\n", q->name, q->weight, q->count, rq->name, rq->weight, rq->count); 02758 found = 1; 02759 } 02760 ao2_ref(mem, -1); 02761 } 02762 } 02763 ao2_unlock(q); 02764 queue_t_unref(q, "Done with iterator"); 02765 if (found) { 02766 break; 02767 } 02768 } 02769 ao2_iterator_destroy(&queue_iter); 02770 return found; 02771 }
| static char* complete_queue | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Definition at line 6840 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ast_strdup, call_queue::name, queue_t_unref, and queues.
Referenced by complete_queue_add_member(), complete_queue_pause_member(), complete_queue_remove_member(), complete_queue_set_member_penalty(), complete_queue_show(), handle_queue_reload(), and handle_queue_reset().
06841 { 06842 struct call_queue *q; 06843 char *ret = NULL; 06844 int which = 0; 06845 int wordlen = strlen(word); 06846 struct ao2_iterator queue_iter; 06847 06848 queue_iter = ao2_iterator_init(queues, 0); 06849 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) { 06850 if (!strncasecmp(word, q->name, wordlen) && ++which > state) { 06851 ret = ast_strdup(q->name); 06852 queue_t_unref(q, "Done with iterator"); 06853 break; 06854 } 06855 queue_t_unref(q, "Done with iterator"); 06856 } 06857 ao2_iterator_destroy(&queue_iter); 06858 06859 return ret; 06860 }
| static char* complete_queue_add_member | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Definition at line 7272 of file app_queue.c.
References ast_malloc, ast_strdup, and complete_queue().
Referenced by handle_queue_add_member().
07273 { 07274 /* 0 - queue; 1 - add; 2 - member; 3 - <interface>; 4 - to; 5 - <queue>; 6 - penalty; 7 - <penalty>; 8 - as; 9 - <membername> */ 07275 switch (pos) { 07276 case 3: /* Don't attempt to complete name of interface (infinite possibilities) */ 07277 return NULL; 07278 case 4: /* only one possible match, "to" */ 07279 return state == 0 ? ast_strdup("to") : NULL; 07280 case 5: /* <queue> */ 07281 return complete_queue(line, word, pos, state); 07282 case 6: /* only one possible match, "penalty" */ 07283 return state == 0 ? ast_strdup("penalty") : NULL; 07284 case 7: 07285 if (state < 100) { /* 0-99 */ 07286 char *num; 07287 if ((num = ast_malloc(3))) { 07288 sprintf(num, "%d", state); 07289 } 07290 return num; 07291 } else { 07292 return NULL; 07293 } 07294 case 8: /* only one possible match, "as" */ 07295 return state == 0 ? ast_strdup("as") : NULL; 07296 case 9: /* Don't attempt to complete name of member (infinite possibilities) */ 07297 return NULL; 07298 default: 07299 return NULL; 07300 } 07301 }
| static char* complete_queue_pause_member | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Definition at line 7493 of file app_queue.c.
References ast_strdup, and complete_queue().
Referenced by handle_queue_pause_member().
07494 { 07495 /* 0 - queue; 1 - pause; 2 - member; 3 - <interface>; 4 - queue; 5 - <queue>; 6 - reason; 7 - <reason> */ 07496 switch (pos) { 07497 case 3: /* Don't attempt to complete name of interface (infinite possibilities) */ 07498 return NULL; 07499 case 4: /* only one possible match, "queue" */ 07500 return state == 0 ? ast_strdup("queue") : NULL; 07501 case 5: /* <queue> */ 07502 return complete_queue(line, word, pos, state); 07503 case 6: /* "reason" */ 07504 return state == 0 ? ast_strdup("reason") : NULL; 07505 case 7: /* Can't autocomplete a reason, since it's 100% customizeable */ 07506 return NULL; 07507 default: 07508 return NULL; 07509 } 07510 }
| static char* complete_queue_remove_member | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Definition at line 7402 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_t_iterator_next, ao2_unlock, ast_strdup, complete_queue(), member::interface, member::membername, call_queue::members, queue_t_unref, and queues.
Referenced by handle_queue_remove_member().
07403 { 07404 int which = 0; 07405 struct call_queue *q; 07406 struct member *m; 07407 struct ao2_iterator queue_iter; 07408 struct ao2_iterator mem_iter; 07409 int wordlen = strlen(word); 07410 07411 /* 0 - queue; 1 - remove; 2 - member; 3 - <member>; 4 - from; 5 - <queue> */ 07412 if (pos > 5 || pos < 3) 07413 return NULL; 07414 if (pos == 4) /* only one possible match, 'from' */ 07415 return (state == 0 ? ast_strdup("from") : NULL); 07416 07417 if (pos == 5) /* No need to duplicate code */ 07418 return complete_queue(line, word, pos, state); 07419 07420 /* here is the case for 3, <member> */ 07421 queue_iter = ao2_iterator_init(queues, 0); 07422 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) { 07423 ao2_lock(q); 07424 mem_iter = ao2_iterator_init(q->members, 0); 07425 while ((m = ao2_iterator_next(&mem_iter))) { 07426 if (!strncasecmp(word, m->membername, wordlen) && ++which > state) { 07427 char *tmp; 07428 ao2_unlock(q); 07429 tmp = ast_strdup(m->interface); 07430 ao2_ref(m, -1); 07431 queue_t_unref(q, "Done with iterator, returning interface name"); 07432 ao2_iterator_destroy(&mem_iter); 07433 ao2_iterator_destroy(&queue_iter); 07434 return tmp; 07435 } 07436 ao2_ref(m, -1); 07437 } 07438 ao2_iterator_destroy(&mem_iter); 07439 ao2_unlock(q); 07440 queue_t_unref(q, "Done with iterator"); 07441 } 07442 ao2_iterator_destroy(&queue_iter); 07443 07444 return NULL; 07445 }
| static char* complete_queue_rule_show | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Definition at line 7626 of file app_queue.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strdup, and rule_list::name.
Referenced by handle_queue_rule_show().
07627 { 07628 int which = 0; 07629 struct rule_list *rl_iter; 07630 int wordlen = strlen(word); 07631 char *ret = NULL; 07632 if (pos != 3) /* Wha? */ { 07633 return NULL; 07634 } 07635 07636 AST_LIST_LOCK(&rule_lists); 07637 AST_LIST_TRAVERSE(&rule_lists, rl_iter, list) { 07638 if (!strncasecmp(word, rl_iter->name, wordlen) && ++which > state) { 07639 ret = ast_strdup(rl_iter->name); 07640 break; 07641 } 07642 } 07643 AST_LIST_UNLOCK(&rule_lists); 07644 07645 return ret; 07646 }
| static char* complete_queue_set_member_penalty | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Definition at line 7563 of file app_queue.c.
References ast_strdup, and complete_queue().
Referenced by handle_queue_set_member_penalty().
07564 { 07565 /* 0 - queue; 1 - set; 2 - penalty; 3 - <penalty>; 4 - on; 5 - <member>; 6 - in; 7 - <queue>;*/ 07566 switch (pos) { 07567 case 4: 07568 if (state == 0) { 07569 return ast_strdup("on"); 07570 } else { 07571 return NULL; 07572 } 07573 case 6: 07574 if (state == 0) { 07575 return ast_strdup("in"); 07576 } else { 07577 return NULL; 07578 } 07579 case 7: 07580 return complete_queue(line, word, pos, state); 07581 default: 07582 return NULL; 07583 } 07584 }
| static char* complete_queue_show | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Definition at line 6862 of file app_queue.c.
References complete_queue().
Referenced by queue_show().
06863 { 06864 if (pos == 2) 06865 return complete_queue(line, word, pos, state); 06866 return NULL; 06867 }
| static int compress_char | ( | const char | c | ) | [static] |
Definition at line 1464 of file app_queue.c.
Referenced by member_hash_fn().
01465 { 01466 if (c < 32) 01467 return 0; 01468 else if (c > 96) 01469 return c - 64; 01470 else 01471 return c - 32; 01472 }
| static void copy_rules | ( | struct queue_ent * | qe, | |
| const char * | rulename | |||
| ) | [static] |
Copy rule from global list into specified queue.
Definition at line 5568 of file app_queue.c.
References ast_calloc, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_strlen_zero(), call_queue::defaultrule, LOG_ERROR, penalty_rule::max_relative, penalty_rule::max_value, penalty_rule::min_relative, penalty_rule::min_value, rule_list::name, queue_ent::parent, queue_ent::qe_rules, rule_list::rules, and penalty_rule::time.
Referenced by queue_exec().
05569 { 05570 struct penalty_rule *pr_iter; 05571 struct rule_list *rl_iter; 05572 const char *tmp = ast_strlen_zero(rulename) ? qe->parent->defaultrule : rulename; 05573 AST_LIST_LOCK(&rule_lists); 05574 AST_LIST_TRAVERSE(&rule_lists, rl_iter, list) { 05575 if (!strcasecmp(rl_iter->name, tmp)) 05576 break; 05577 } 05578 if (rl_iter) { 05579 AST_LIST_TRAVERSE(&rl_iter->rules, pr_iter, list) { 05580 struct penalty_rule *new_pr = ast_calloc(1, sizeof(*new_pr)); 05581 if (!new_pr) { 05582 ast_log(LOG_ERROR, "Memory allocation error when copying penalty rules! Aborting!\n"); 05583 AST_LIST_UNLOCK(&rule_lists); 05584 break; 05585 } 05586 new_pr->time = pr_iter->time; 05587 new_pr->max_value = pr_iter->max_value; 05588 new_pr->min_value = pr_iter->min_value; 05589 new_pr->max_relative = pr_iter->max_relative; 05590 new_pr->min_relative = pr_iter->min_relative; 05591 AST_LIST_INSERT_TAIL(&qe->qe_rules, new_pr, list); 05592 } 05593 } 05594 AST_LIST_UNLOCK(&rule_lists); 05595 }
| static struct member* create_queue_member | ( | const char * | interface, | |
| const char * | membername, | |||
| int | penalty, | |||
| int | paused, | |||
| const char * | state_interface | |||
| ) | [static, read] |
allocate space for new queue member and set fields based on parameters passed
Definition at line 1432 of file app_queue.c.
References ao2_alloc, ast_copy_string(), ast_log(), ast_strdupa, ast_strlen_zero(), queue_ent::context, exten, get_queue_member_status(), member::interface, LOG_WARNING, member::membername, member::paused, member::penalty, S_OR, member::state_context, member::state_exten, member::state_interface, member::status, and strsep().
Referenced by add_to_queue(), reload_single_member(), and rt_handle_member_record().
01433 { 01434 struct member *cur; 01435 01436 if ((cur = ao2_alloc(sizeof(*cur), NULL))) { 01437 cur->penalty = penalty; 01438 cur->paused = paused; 01439 ast_copy_string(cur->interface, interface, sizeof(cur->interface)); 01440 if (!ast_strlen_zero(state_interface)) 01441 ast_copy_string(cur->state_interface, state_interface, sizeof(cur->state_interface)); 01442 else 01443 ast_copy_string(cur->state_interface, interface, sizeof(cur->state_interface)); 01444 if (!ast_strlen_zero(membername)) 01445 ast_copy_string(cur->membername, membername, sizeof(cur->membername)); 01446 else 01447 ast_copy_string(cur->membername, interface, sizeof(cur->membername)); 01448 if (!strchr(cur->interface, '/')) 01449 ast_log(LOG_WARNING, "No location at interface '%s'\n", interface); 01450 if (!strncmp(cur->state_interface, "hint:", 5)) { 01451 char *tmp = ast_strdupa(cur->state_interface), *context = tmp; 01452 char *exten = strsep(&context, "@") + 5; 01453 01454 ast_copy_string(cur->state_exten, exten, sizeof(cur->state_exten)); 01455 ast_copy_string(cur->state_context, S_OR(context, "default"), sizeof(cur->state_context)); 01456 } 01457 cur->status = get_queue_member_status(cur); 01458 } 01459 01460 return cur; 01461 }
| static void destroy_queue | ( | void * | obj | ) | [static] |
Free queue's member list then its string fields.
Definition at line 1988 of file app_queue.c.
References ao2_ref, ast_string_field_free_memory, free, free_members(), MAX_PERIODIC_ANNOUNCEMENTS, call_queue::members, and call_queue::sound_periodicannounce.
Referenced by alloc_queue().
01989 { 01990 struct call_queue *q = obj; 01991 int i; 01992 01993 free_members(q, 1); 01994 ast_string_field_free_memory(q); 01995 for (i = 0; i < MAX_PERIODIC_ANNOUNCEMENTS; i++) { 01996 if (q->sound_periodicannounce[i]) 01997 free(q->sound_periodicannounce[i]); 01998 } 01999 ao2_ref(q->members, -1); 02000 }
| static void device_state_cb | ( | const struct ast_event * | event, | |
| void * | unused | |||
| ) | [static] |
Definition at line 1330 of file app_queue.c.
References ast_calloc, ast_event_get_ie_str(), ast_event_get_ie_uint(), AST_EVENT_IE_DEVICE, AST_EVENT_IE_STATE, ast_free, ast_log(), ast_strlen_zero(), ast_taskprocessor_push(), statechange::dev, handle_statechange(), LOG_ERROR, and statechange::state.
Referenced by load_module().
01331 { 01332 enum ast_device_state state; 01333 const char *device; 01334 struct statechange *sc; 01335 size_t datapsize; 01336 01337 state = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE); 01338 device = ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE); 01339 01340 if (ast_strlen_zero(device)) { 01341 ast_log(LOG_ERROR, "Received invalid event that had no device IE\n"); 01342 return; 01343 } 01344 datapsize = sizeof(*sc) + strlen(device) + 1; 01345 if (!(sc = ast_calloc(1, datapsize))) { 01346 ast_log(LOG_ERROR, "failed to calloc a state change struct\n"); 01347 return; 01348 } 01349 sc->state = state; 01350 strcpy(sc->dev, device); 01351 if (ast_taskprocessor_push(devicestate_tps, handle_statechange, sc) < 0) { 01352 ast_free(sc); 01353 } 01354 }
| static void do_hang | ( | struct callattempt * | o | ) | [static] |
common hangup actions
Definition at line 2774 of file app_queue.c.
References ast_hangup(), callattempt::chan, and callattempt::stillgoing.
Referenced by ring_entry(), and wait_for_answer().
02775 { 02776 o->stillgoing = 0; 02777 ast_hangup(o->chan); 02778 o->chan = NULL; 02779 }
| static void do_print | ( | struct mansession * | s, | |
| int | fd, | |||
| const char * | str | |||
| ) | [static] |
direct ouput to manager or cli with proper terminator
Definition at line 6698 of file app_queue.c.
References ast_cli(), and astman_append().
Referenced by __queues_show().
06699 { 06700 if (s) 06701 astman_append(s, "%s\r\n", str); 06702 else 06703 ast_cli(fd, "%s\n", str); 06704 }
| static void dump_queue_members | ( | struct call_queue * | pm_queue | ) | [static] |
Dump all members in a specific queue to the database.
<pm_family>/<queuename> = <interface>;<penalty>;<paused>;<state_interface>[|...]
Definition at line 4933 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_db_del(), ast_db_put(), ast_log(), member::dynamic, member::interface, LOG_WARNING, member::membername, call_queue::members, call_queue::name, member::paused, member::penalty, PM_MAX_LEN, member::state_interface, and value.
Referenced by add_to_queue(), remove_from_queue(), and set_member_paused().
04934 { 04935 struct member *cur_member; 04936 char value[PM_MAX_LEN]; 04937 int value_len = 0; 04938 int res; 04939 struct ao2_iterator mem_iter; 04940 04941 memset(value, 0, sizeof(value)); 04942 04943 if (!pm_queue) 04944 return; 04945 04946 mem_iter = ao2_iterator_init(pm_queue->members, 0); 04947 while ((cur_member = ao2_iterator_next(&mem_iter))) { 04948 if (!cur_member->dynamic) { 04949 ao2_ref(cur_member, -1); 04950 continue; 04951 } 04952 04953 res = snprintf(value + value_len, sizeof(value) - value_len, "%s%s;%d;%d;%s;%s", 04954 value_len ? "|" : "", cur_member->interface, cur_member->penalty, cur_member->paused, cur_member->membername, cur_member->state_interface); 04955 04956 ao2_ref(cur_member, -1); 04957 04958 if (res != strlen(value + value_len)) { 04959 ast_log(LOG_WARNING, "Could not create persistent member string, out of space\n"); 04960 break; 04961 } 04962 value_len += res; 04963 } 04964 ao2_iterator_destroy(&mem_iter); 04965 04966 if (value_len && !cur_member) { 04967 if (ast_db_put(pm_family, pm_queue->name, value)) 04968 ast_log(LOG_WARNING, "failed to create persistent dynamic entry!\n"); 04969 } else 04970 /* Delete the entry if the queue is empty or there is an error */ 04971 ast_db_del(pm_family, pm_queue->name); 04972 }
| static void end_bridge_callback | ( | void * | data | ) | [static] |
Definition at line 4092 of file app_queue.c.
References ao2_lock, ao2_ref, ao2_unlock, queue_end_bridge::chan, queue_ent::chan, queue_end_bridge::q, queue_t_unref, and set_queue_variables().
Referenced by try_calling().
04093 { 04094 struct queue_end_bridge *qeb = data; 04095 struct call_queue *q = qeb->q; 04096 struct ast_channel *chan = qeb->chan; 04097 04098 if (ao2_ref(qeb, -1) == 1) { 04099 ao2_lock(q); 04100 set_queue_variables(q, chan); 04101 ao2_unlock(q); 04102 /* This unrefs the reference we made in try_calling when we allocated qeb */ 04103 queue_t_unref(q, "Expire bridge_config reference"); 04104 } 04105 }
| static void end_bridge_callback_data_fixup | ( | struct ast_bridge_config * | bconfig, | |
| struct ast_channel * | originator, | |||
| struct ast_channel * | terminator | |||
| ) | [static] |
Definition at line 4085 of file app_queue.c.
References ao2_ref, queue_end_bridge::chan, and ast_bridge_config::end_bridge_callback_data.
Referenced by try_calling().
04086 { 04087 struct queue_end_bridge *qeb = bconfig->end_bridge_callback_data; 04088 ao2_ref(qeb, +1); 04089 qeb->chan = originator; 04090 }
| static int extension_state_cb | ( | char * | context, | |
| char * | exten, | |||
| enum ast_extension_states | state, | |||
| void * | data | |||
| ) | [static] |
Definition at line 1388 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_t_iterator_next, ao2_unlock, ast_debug, ast_devstate2str(), extensionstate2devicestate(), call_queue::found, call_queue::members, queue_t_unref, queues, member::state_context, member::state_exten, and update_status().
Referenced by load_module(), and unload_module().
01389 { 01390 struct ao2_iterator miter, qiter; 01391 struct member *m; 01392 struct call_queue *q; 01393 int found = 0, device_state = extensionstate2devicestate(state); 01394 01395 qiter = ao2_iterator_init(queues, 0); 01396 while ((q = ao2_t_iterator_next(&qiter, "Iterate through queues"))) { 01397 ao2_lock(q); 01398 01399 miter = ao2_iterator_init(q->members, 0); 01400 for (; (m = ao2_iterator_next(&miter)); ao2_ref(m, -1)) { 01401 if (!strcmp(m->state_context, context) && !strcmp(m->state_exten, exten)) { 01402 update_status(q, m, device_state); 01403 ao2_ref(m, -1); 01404 found = 1; 01405 break; 01406 } 01407 } 01408 ao2_iterator_destroy(&miter); 01409 01410 ao2_unlock(q); 01411 queue_t_unref(q, "Done with iterator"); 01412 } 01413 ao2_iterator_destroy(&qiter); 01414 01415 if (found) { 01416 ast_debug(1, "Extension '%s@%s' changed to state '%d' (%s)\n", exten, context, device_state, ast_devstate2str(device_state)); 01417 } else { 01418 ast_debug(3, "Extension '%s@%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n", 01419 exten, context, device_state, ast_devstate2str(device_state)); 01420 } 01421 01422 return 0; 01423 }
| static int extensionstate2devicestate | ( | int | state | ) | [static] |
Helper function which converts from extension state to device state values.
Definition at line 1357 of file app_queue.c.
References AST_DEVICE_BUSY, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_ONHOLD, AST_DEVICE_RINGING, AST_DEVICE_UNAVAILABLE, AST_EXTENSION_BUSY, AST_EXTENSION_DEACTIVATED, AST_EXTENSION_INUSE, AST_EXTENSION_NOT_INUSE, AST_EXTENSION_ONHOLD, AST_EXTENSION_REMOVED, AST_EXTENSION_RINGING, and AST_EXTENSION_UNAVAILABLE.
Referenced by extension_state_cb(), and get_queue_member_status().
01358 { 01359 switch (state) { 01360 case AST_EXTENSION_NOT_INUSE: 01361 state = AST_DEVICE_NOT_INUSE; 01362 break; 01363 case AST_EXTENSION_INUSE: 01364 state = AST_DEVICE_INUSE; 01365 break; 01366 case AST_EXTENSION_BUSY: 01367 state = AST_DEVICE_BUSY; 01368 break; 01369 case AST_EXTENSION_RINGING: 01370 state = AST_DEVICE_RINGING; 01371 break; 01372 case AST_EXTENSION_ONHOLD: 01373 state = AST_DEVICE_ONHOLD; 01374 break; 01375 case AST_EXTENSION_UNAVAILABLE: 01376 state = AST_DEVICE_UNAVAILABLE; 01377 break; 01378 case AST_EXTENSION_REMOVED: 01379 case AST_EXTENSION_DEACTIVATED: 01380 default: 01381 state = AST_DEVICE_INVALID; 01382 break; 01383 } 01384 01385 return state; 01386 }
| static struct callattempt* find_best | ( | struct callattempt * | outgoing | ) | [static, read] |
find the entry with the best metric, or NULL
Definition at line 3008 of file app_queue.c.
References callattempt::metric, and callattempt::q_next.
Referenced by ring_one(), store_next_lin(), and store_next_rr().
03009 { 03010 struct callattempt *best = NULL, *cur; 03011 03012 for (cur = outgoing; cur; cur = cur->q_next) { 03013 if (cur->stillgoing && /* Not already done */ 03014 !cur->chan && /* Isn't already going */ 03015 (!best || cur->metric < best->metric)) { /* We haven't found one yet, or it's better */ 03016 best = cur; 03017 } 03018 } 03019 03020 return best; 03021 }
| static struct call_queue* find_queue_by_name_rt | ( | const char * | queuename, | |
| struct ast_variable * | queue_vars, | |||
| struct ast_config * | member_config | |||
| ) | [static, read] |
Reload a single queue via realtime.
Check for statically defined queue first, check if deleted RT queue, check for new RT queue, if queue vars are not defined init them with defaults. reload RT queue vars, set RT queue members dead and reload them, return finished queue.
| the | queue, | |
| NULL | if it doesn't exist. |
Definition at line 2026 of file app_queue.c.
References alloc_queue(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_t_find, ao2_unlink, ao2_unlock, ast_category_browse(), ast_copy_string(), ast_debug, ast_log(), ast_queue_log(), ast_variable_retrieve(), clear_queue(), member::dead, call_queue::dead, init_queue(), member::interface, LOG_WARNING, call_queue::membercount, call_queue::members, ast_variable::name, call_queue::name, ast_variable::next, OBJ_POINTER, queue_set_param(), QUEUE_STRATEGY_RINGALL, queue_t_unref, queues, queues_t_link, queues_t_unlink, member::realtime, call_queue::realtime, rt_handle_member_record(), S_OR, strat2int(), call_queue::strategy, and ast_variable::value.
Referenced by load_realtime_queue().
02027 { 02028 struct ast_variable *v; 02029 struct call_queue *q, tmpq = { 02030 .name = queuename, 02031 }; 02032 struct member *m; 02033 struct ao2_iterator mem_iter; 02034 char *interface = NULL; 02035 const char *tmp_name; 02036 char *tmp; 02037 char tmpbuf[64]; /* Must be longer than the longest queue param name. */ 02038 02039 /* Static queues override realtime. */ 02040 if ((q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Check if static queue exists"))) { 02041 ao2_lock(q); 02042 if (!q->realtime) { 02043 if (q->dead) { 02044 ao2_unlock(q); 02045 queue_t_unref(q, "Queue is dead; can't return it"); 02046 return NULL; 02047 } else { 02048 ast_log(LOG_WARNING, "Static queue '%s' already exists. Not loading from realtime\n", q->name); 02049 ao2_unlock(q); 02050 return q; 02051 } 02052 } 02053 } else if (!member_config) 02054 /* Not found in the list, and it's not realtime ... */ 02055 return NULL; 02056 02057 /* Check if queue is defined in realtime. */ 02058 if (!queue_vars) { 02059 /* Delete queue from in-core list if it has been deleted in realtime. */ 02060 if (q) { 02061 /*! \note Hmm, can't seem to distinguish a DB failure from a not 02062 found condition... So we might delete an in-core queue 02063 in case of DB failure. */ 02064 ast_debug(1, "Queue %s not found in realtime.\n", queuename); 02065 02066 q->dead = 1; 02067 /* Delete if unused (else will be deleted when last caller leaves). */ 02068 queues_t_unlink(queues, q, "Unused; removing from container"); 02069 ao2_unlock(q); 02070 queue_t_unref(q, "Queue is dead; can't return it"); 02071 } 02072 return NULL; 02073 } 02074 02075 /* Create a new queue if an in-core entry does not exist yet. */ 02076 if (!q) { 02077 struct ast_variable *tmpvar = NULL; 02078 if (!(q = alloc_queue(queuename))) 02079 return NULL; 02080 ao2_lock(q); 02081 clear_queue(q); 02082 q->realtime = 1; 02083 q->membercount = 0; 02084 /*Before we initialize the queue, we need to set the strategy, so that linear strategy 02085 * will allocate the members properly 02086 */ 02087 for (tmpvar = queue_vars; tmpvar; tmpvar = tmpvar->next) { 02088 if (!strcasecmp(tmpvar->name, "strategy")) { 02089 q->strategy = strat2int(tmpvar->value); 02090 if (q->strategy < 0) { 02091 ast_log(LOG_WARNING, "'%s' isn't a valid strategy for queue '%s', using ringall instead\n", 02092 tmpvar->value, q->name); 02093 q->strategy = QUEUE_STRATEGY_RINGALL; 02094 } 02095 break; 02096 } 02097 } 02098 /* We traversed all variables and didn't find a strategy */ 02099 if (!tmpvar) 02100 q->strategy = QUEUE_STRATEGY_RINGALL; 02101 queues_t_link(queues, q, "Add queue to container"); 02102 } 02103 init_queue(q); /* Ensure defaults for all parameters not set explicitly. */ 02104 02105 memset(tmpbuf, 0, sizeof(tmpbuf)); 02106 for (v = queue_vars; v; v = v->next) { 02107 /* Convert to dashes `-' from underscores `_' as the latter are more SQL friendly. */ 02108 if ((tmp = strchr(v->name, '_'))) { 02109 ast_copy_string(tmpbuf, v->name, sizeof(tmpbuf)); 02110 tmp_name = tmpbuf; 02111 tmp = tmpbuf; 02112 while ((tmp = strchr(tmp, '_'))) 02113 *tmp++ = '-'; 02114 } else 02115 tmp_name = v->name; 02116 02117 /* NULL values don't get returned from realtime; blank values should 02118 * still get set. If someone doesn't want a value to be set, they 02119 * should set the realtime column to NULL, not blank. */ 02120 queue_set_param(q, tmp_name, v->value, -1, 0); 02121 } 02122 02123 /* Temporarily set realtime members dead so we can detect deleted ones. 02124 * Also set the membercount correctly for realtime*/ 02125 mem_iter = ao2_iterator_init(q->members, 0); 02126 while ((m = ao2_iterator_next(&mem_iter))) { 02127 q->membercount++; 02128 if (m->realtime) 02129 m->dead = 1; 02130 ao2_ref(m, -1); 02131 } 02132 ao2_iterator_destroy(&mem_iter); 02133 02134 while ((interface = ast_category_browse(member_config, interface))) { 02135 rt_handle_member_record(q, interface, 02136 ast_variable_retrieve(member_config, interface, "uniqueid"), 02137 S_OR(ast_variable_retrieve(member_config, interface, "membername"),interface), 02138 ast_variable_retrieve(member_config, interface, "penalty"), 02139 ast_variable_retrieve(member_config, interface, "paused"), 02140 S_OR(ast_variable_retrieve(member_config, interface, "state_interface"),interface)); 02141 } 02142 02143 /* Delete all realtime members that have been deleted in DB. */ 02144 mem_iter = ao2_iterator_init(q->members, 0); 02145 while ((m = ao2_iterator_next(&mem_iter))) { 02146 if (m->dead) { 02147 ast_queue_log(q->name, "REALTIME", m->interface, "REMOVEMEMBER", "%s", ""); 02148 ao2_unlink(q->members, m); 02149 q->membercount--; 02150 } 02151 ao2_ref(m, -1); 02152 } 02153 ao2_iterator_destroy(&mem_iter); 02154 02155 ao2_unlock(q); 02156 02157 return q; 02158 }
| static void free_members | ( | struct call_queue * | q, | |
| int | all | |||
| ) | [static] |
Iterate through queue's member list and delete them.
Definition at line 1971 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ao2_unlink, member::dynamic, call_queue::membercount, and call_queue::members.
Referenced by destroy_queue().
01972 { 01973 /* Free non-dynamic members */ 01974 struct member *cur; 01975 struct ao2_iterator mem_iter = ao2_iterator_init(q->members, 0); 01976 01977 while ((cur = ao2_iterator_next(&mem_iter))) { 01978 if (all || !cur->dynamic) { 01979 ao2_unlink(q->members, cur); 01980 q->membercount--; 01981 } 01982 ao2_ref(cur, -1); 01983 } 01984 ao2_iterator_destroy(&mem_iter); 01985 }
| static int get_member_penalty | ( | char * | queuename, | |
| char * | interface | |||
| ) | [static] |
Definition at line 5213 of file app_queue.c.
References ao2_lock, ao2_ref, ao2_t_find, ao2_unlock, ast_log(), interface_exists(), LOG_ERROR, OBJ_POINTER, member::penalty, queue_t_unref, queues, and RESULT_FAILURE.
Referenced by queue_function_memberpenalty_read().
05214 { 05215 int foundqueue = 0, penalty; 05216 struct call_queue *q, tmpq = { 05217 .name = queuename, 05218 }; 05219 struct member *mem; 05220 05221 if ((q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Search for queue"))) { 05222 foundqueue = 1; 05223 ao2_lock(q); 05224 if ((mem = interface_exists(q, interface))) { 05225 penalty = mem->penalty; 05226 ao2_ref(mem, -1); 05227 ao2_unlock(q); 05228 queue_t_unref(q, "Search complete"); 05229 return penalty; 05230 } 05231 ao2_unlock(q); 05232 queue_t_unref(q, "Search complete"); 05233 } 05234 05235 /* some useful debuging */ 05236 if (foundqueue) 05237 ast_log (LOG_ERROR, "Invalid queuename\n"); 05238 else 05239 ast_log (LOG_ERROR, "Invalid interface\n"); 05240 05241 return RESULT_FAILURE; 05242 }
| static int get_member_status | ( | struct call_queue * | q, | |
| int | max_penalty, | |||
| int | min_penalty, | |||
| enum empty_conditions | conditions | |||
| ) | [static] |
Check if members are available.
This function checks to see if members are available to be called. If any member is available, the function immediately returns 0. If no members are available, then -1 is returned.
Definition at line 1181 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, ast_debug, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_RINGING, AST_DEVICE_UNAVAILABLE, AST_DEVICE_UNKNOWN, member::lastcall, member::membername, call_queue::members, member::paused, member::penalty, QUEUE_EMPTY_INUSE, QUEUE_EMPTY_INVALID, QUEUE_EMPTY_PAUSED, QUEUE_EMPTY_PENALTY, QUEUE_EMPTY_RINGING, QUEUE_EMPTY_UNAVAILABLE, QUEUE_EMPTY_UNKNOWN, QUEUE_EMPTY_WRAPUP, member::status, and call_queue::wrapuptime.
Referenced by join_queue(), queue_exec(), and wait_our_turn().
01182 { 01183 struct member *member; 01184 struct ao2_iterator mem_iter; 01185 01186 ao2_lock(q); 01187 mem_iter = ao2_iterator_init(q->members, 0); 01188 for (; (member = ao2_iterator_next(&mem_iter)); ao2_ref(member, -1)) { 01189 if ((max_penalty && (member->penalty > max_penalty)) || (min_penalty && (member->penalty < min_penalty))) { 01190 if (conditions & QUEUE_EMPTY_PENALTY) { 01191 ast_debug(4, "%s is unavailable because his penalty is not between %d and %d\n", member->membername, min_penalty, max_penalty); 01192 continue; 01193 } 01194 } 01195 01196 switch (member->status) { 01197 case AST_DEVICE_INVALID: 01198 if (conditions & QUEUE_EMPTY_INVALID) { 01199 ast_debug(4, "%s is unavailable because his device state is 'invalid'\n", member->membername); 01200 break; 01201 } 01202 goto default_case; 01203 case AST_DEVICE_UNAVAILABLE: 01204 if (conditions & QUEUE_EMPTY_UNAVAILABLE) { 01205 ast_debug(4, "%s is unavailable because his device state is 'unavailable'\n", member->membername); 01206 break; 01207 } 01208 goto default_case; 01209 case AST_DEVICE_INUSE: 01210 if (conditions & QUEUE_EMPTY_INUSE) { 01211 ast_debug(4, "%s is unavailable because his device state is 'inuse'\n", member->membername); 01212 break; 01213 } 01214 goto default_case; 01215 case AST_DEVICE_RINGING: 01216 if (conditions & QUEUE_EMPTY_RINGING) { 01217 ast_debug(4, "%s is unavailable because his device state is 'ringing'\n", member->membername); 01218 break; 01219 } 01220 case AST_DEVICE_UNKNOWN: 01221 if (conditions & QUEUE_EMPTY_UNKNOWN) { 01222 ast_debug(4, "%s is unavailable because his device state is 'unknown'\n", member->membername); 01223 break; 01224 } 01225 /* Fall-through */ 01226 default: 01227 default_case: 01228 if (member->paused && (conditions & QUEUE_EMPTY_PAUSED)) { 01229 ast_debug(4, "%s is unavailable because he is paused'\n", member->membername); 01230 break; 01231 } else if ((conditions & QUEUE_EMPTY_WRAPUP) && member->lastcall && q->wrapuptime && (time(NULL) - q->wrapuptime < member->lastcall)) { 01232 ast_debug(4, "%s is unavailable because it has only been %d seconds since his last call (wrapup time is %d)\n", member->membername, (int) (time(NULL) - member->lastcall), q->wrapuptime); 01233 break; 01234 } else { 01235 ao2_unlock(q); 01236 ao2_ref(member, -1); 01237 ao2_iterator_destroy(&mem_iter); 01238 ast_debug(4, "%s is available.\n", member->membername); 01239 return 0; 01240 } 01241 break; 01242 } 01243 } 01244 ao2_iterator_destroy(&mem_iter); 01245 01246 ao2_unlock(q); 01247 return -1; 01248 }
| static int get_queue_member_status | ( | struct member * | cur | ) | [static] |
Return the current state of a member.
Definition at line 1426 of file app_queue.c.
References ast_extension_state(), ast_strlen_zero(), extensionstate2devicestate(), member::state_context, member::state_exten, and member::state_interface.
Referenced by create_queue_member(), kill_dead_members(), and ring_entry().
01427 { 01428 return ast_strlen_zero(cur->state_exten) ? ast_device_state(cur->state_interface) : extensionstate2devicestate(ast_extension_state(NULL, cur->state_context, cur->state_exten)); 01429 }
| static char* handle_queue_add_member | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 7328 of file app_queue.c.
References add_to_queue(), ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_queue_log(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_queue_add_member(), ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, RES_EXISTS, RES_NOSUCHQUEUE, RES_NOT_DYNAMIC, RES_OKAY, RES_OUTOFMEMORY, ast_cli_entry::usage, and ast_cli_args::word.
07329 { 07330 const char *queuename, *interface, *membername = NULL, *state_interface = NULL; 07331 int penalty; 07332 07333 switch ( cmd ) { 07334 case CLI_INIT: 07335 e->command = "queue add member"; 07336 e->usage = 07337 "Usage: queue add member <channel> to <queue> [[[penalty <penalty>] as <membername>] state_interface <interface>]\n" 07338 " Add a channel to a queue with optionally: a penalty, membername and a state_interface\n"; 07339 return NULL; 07340 case CLI_GENERATE: 07341 return complete_queue_add_member(a->line, a->word, a->pos, a->n); 07342 } 07343 07344 if ((a->argc != 6) && (a->argc != 8) && (a->argc != 10) && (a->argc != 12)) { 07345 return CLI_SHOWUSAGE; 07346 } else if (strcmp(a->argv[4], "to")) { 07347 return CLI_SHOWUSAGE; 07348 } else if ((a->argc >= 8) && strcmp(a->argv[6], "penalty")) { 07349 return CLI_SHOWUSAGE; 07350 } else if ((a->argc >= 10) && strcmp(a->argv[8], "as")) { 07351 return CLI_SHOWUSAGE; 07352 } else if ((a->argc == 12) && strcmp(a->argv[10], "state_interface")) { 07353 return CLI_SHOWUSAGE; 07354 } 07355 07356 queuename = a->argv[5]; 07357 interface = a->argv[3]; 07358 if (a->argc >= 8) { 07359 if (sscanf(a->argv[7], "%30d", &penalty) == 1) { 07360 if (penalty < 0) { 07361 ast_cli(a->fd, "Penalty must be >= 0\n"); 07362 penalty = 0; 07363 } 07364 } else { 07365 ast_cli(a->fd, "Penalty must be an integer >= 0\n"); 07366 penalty = 0; 07367 } 07368 } else { 07369 penalty = 0; 07370 } 07371 07372 if (a->argc >= 10) { 07373 membername = a->argv[9]; 07374 } 07375 07376 if (a->argc >= 12) { 07377 state_interface = a->argv[11]; 07378 } 07379 07380 switch (add_to_queue(queuename, interface, membername, penalty, 0, queue_persistent_members, state_interface)) { 07381 case RES_OKAY: 07382 ast_queue_log(queuename, "CLI", interface, "ADDMEMBER", "%s", ""); 07383 ast_cli(a->fd, "Added interface '%s' to queue '%s'\n", interface, queuename); 07384 return CLI_SUCCESS; 07385 case RES_EXISTS: 07386 ast_cli(a->fd, "Unable to add interface '%s' to queue '%s': Already there\n", interface, queuename); 07387 return CLI_FAILURE; 07388 case RES_NOSUCHQUEUE: 07389 ast_cli(a->fd, "Unable to add interface to queue '%s': No such queue\n", queuename); 07390 return CLI_FAILURE; 07391 case RES_OUTOFMEMORY: 07392 ast_cli(a->fd, "Out of memory\n"); 07393 return CLI_FAILURE; 07394 case RES_NOT_DYNAMIC: 07395 ast_cli(a->fd, "Member not dynamic\n"); 07396 return CLI_FAILURE; 07397 default: 07398 return CLI_FAILURE; 07399 } 07400 }
| static char* handle_queue_pause_member | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 7512 of file app_queue.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_strlen_zero(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_queue_pause_member(), ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, RESULT_SUCCESS, set_member_paused(), ast_cli_entry::usage, and word.
07513 { 07514 const char *queuename, *interface, *reason; 07515 int paused; 07516 07517 switch (cmd) { 07518 case CLI_INIT: 07519 e->command = "queue {pause|unpause} member"; 07520 e->usage = 07521 "Usage: queue {pause|unpause} member <member> [queue <queue> [reason <reason>]]\n" 07522 " Pause or unpause a queue member. Not specifying a particular queue\n" 07523 " will pause or unpause a member across all queues to which the member\n" 07524 " belongs.\n"; 07525 return NULL; 07526 case CLI_GENERATE: 07527 return complete_queue_pause_member(a->line, a-> word, a->pos, a->n); 07528 } 07529 07530 if (a->argc < 4 || a->argc == 5 || a->argc == 7 || a->argc > 8) { 07531 return CLI_SHOWUSAGE; 07532 } else if (a->argc >= 5 && strcmp(a->argv[4], "queue")) { 07533 return CLI_SHOWUSAGE; 07534 } else if (a->argc == 8 && strcmp(a->argv[6], "reason")) { 07535 return CLI_SHOWUSAGE; 07536 } 07537 07538 07539 interface = a->argv[3]; 07540 queuename = a->argc >= 6 ? a->argv[5] : NULL; 07541 reason = a->argc == 8 ? a->argv[7] : NULL; 07542 paused = !strcasecmp(a->argv[1], "pause"); 07543 07544 if (set_member_paused(queuename, interface, reason, paused) == RESULT_SUCCESS) { 07545 ast_cli(a->fd, "%spaused interface '%s'", paused ? "" : "un", interface); 07546 if (!ast_strlen_zero(queuename)) 07547 ast_cli(a->fd, " in queue '%s'", queuename); 07548 if (!ast_strlen_zero(reason)) 07549 ast_cli(a->fd, " for reason '%s'", reason); 07550 ast_cli(a->fd, "\n"); 07551 return CLI_SUCCESS; 07552 } else { 07553 ast_cli(a->fd, "Unable to %spause interface '%s'", paused ? "" : "un", interface); 07554 if (!ast_strlen_zero(queuename)) 07555 ast_cli(a->fd, " in queue '%s'", queuename); 07556 if (!ast_strlen_zero(reason)) 07557 ast_cli(a->fd, " for reason '%s'", reason); 07558 ast_cli(a->fd, "\n"); 07559 return CLI_FAILURE; 07560 } 07561 }
| static char* handle_queue_reload | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 7721 of file app_queue.c.
References ast_cli_args::argc, ast_cli_args::argv, AST_FLAGS_ALL, ast_set_flag, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_queue(), ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, QUEUE_RELOAD_MEMBER, QUEUE_RELOAD_PARAMETERS, QUEUE_RELOAD_RULES, reload_handler(), ast_cli_entry::usage, and ast_cli_args::word.
07722 { 07723 struct ast_flags mask = {0,}; 07724 int i; 07725 07726 switch (cmd) { 07727 case CLI_INIT: 07728 e->command = "queue reload {parameters|members|rules|all}"; 07729 e->usage = 07730 "Usage: queue reload {parameters|members|rules|all} [<queuenames>]\n" 07731 "Reload queues. If <queuenames> are specified, only reload information pertaining\n" 07732 "to <queuenames>. One of 'parameters,' 'members,' 'rules,' or 'all' must be\n" 07733 "specified in order to know what information to reload. Below is an explanation\n" 07734 "of each of these qualifiers.\n" 07735 "\n" 07736 "\t'members' - reload queue members from queues.conf\n" 07737 "\t'parameters' - reload all queue options except for queue members\n" 07738 "\t'rules' - reload the queuerules.conf file\n" 07739 "\t'all' - reload queue rules, parameters, and members\n" 07740 "\n" 07741 "Note: the 'rules' qualifier here cannot actually be applied to a specific queue.\n" 07742 "Use of the 'rules' qualifier causes queuerules.conf to be reloaded. Even if only\n" 07743 "one queue is specified when using this command, reloading queue rules may cause\n" 07744 "other queues to be affected\n"; 07745 return NULL; 07746 case CLI_GENERATE: 07747 if (a->pos >= 3) { 07748 return complete_queue(a->line, a->word, a->pos, a->n); 07749 } else { 07750 return NULL; 07751 } 07752 } 07753 07754 if (a->argc < 3) 07755 return CLI_SHOWUSAGE; 07756 07757 if (!strcasecmp(a->argv[2], "rules")) { 07758 ast_set_flag(&mask, QUEUE_RELOAD_RULES); 07759 } else if (!strcasecmp(a->argv[2], "members")) { 07760 ast_set_flag(&mask, QUEUE_RELOAD_MEMBER); 07761 } else if (!strcasecmp(a->argv[2], "parameters")) { 07762 ast_set_flag(&mask, QUEUE_RELOAD_PARAMETERS); 07763 } else if (!strcasecmp(a->argv[2], "all")) { 07764 ast_set_flag(&mask, AST_FLAGS_ALL); 07765 } 07766 07767 if (a->argc == 3) { 07768 reload_handler(1, &mask, NULL); 07769 return CLI_SUCCESS; 07770 } 07771 07772 for (i = 3; i < a->argc; ++i) { 07773 reload_handler(1, &mask, a->argv[i]); 07774 } 07775 07776 return CLI_SUCCESS; 07777 }
| static char* handle_queue_remove_member | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 7447 of file app_queue.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_queue_log(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_queue_remove_member(), ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, remove_from_queue(), RES_EXISTS, RES_NOSUCHQUEUE, RES_NOT_DYNAMIC, RES_OKAY, RES_OUTOFMEMORY, ast_cli_entry::usage, and ast_cli_args::word.
07448 { 07449 const char *queuename, *interface; 07450 07451 switch (cmd) { 07452 case CLI_INIT: 07453 e->command = "queue remove member"; 07454 e->usage = 07455 "Usage: queue remove member <channel> from <queue>\n" 07456 " Remove a specific channel from a queue.\n"; 07457 return NULL; 07458 case CLI_GENERATE: 07459 return complete_queue_remove_member(a->line, a->word, a->pos, a->n); 07460 } 07461 07462 if (a->argc != 6) { 07463 return CLI_SHOWUSAGE; 07464 } else if (strcmp(a->argv[4], "from")) { 07465 return CLI_SHOWUSAGE; 07466 } 07467 07468 queuename = a->argv[5]; 07469 interface = a->argv[3]; 07470 07471 switch (remove_from_queue(queuename, interface)) { 07472 case RES_OKAY: 07473 ast_queue_log(queuename, "CLI", interface, "REMOVEMEMBER", "%s", ""); 07474 ast_cli(a->fd, "Removed interface '%s' from queue '%s'\n", interface, queuename); 07475 return CLI_SUCCESS; 07476 case RES_EXISTS: 07477 ast_cli(a->fd, "Unable to remove interface '%s' from queue '%s': Not there\n", interface, queuename); 07478 return CLI_FAILURE; 07479 case RES_NOSUCHQUEUE: 07480 ast_cli(a->fd, "Unable to remove interface from queue '%s': No such queue\n", queuename); 07481 return CLI_FAILURE; 07482 case RES_OUTOFMEMORY: 07483 ast_cli(a->fd, "Out of memory\n"); 07484 return CLI_FAILURE; 07485 case RES_NOT_DYNAMIC: 07486 ast_cli(a->fd, "Unable to remove interface '%s' from queue '%s': Member is not dynamic\n", interface, queuename); 07487 return CLI_FAILURE; 07488 default: 07489 return CLI_FAILURE; 07490 } 07491 }
| static char* handle_queue_reset | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 7682 of file app_queue.c.
References ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_queue(), ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, QUEUE_RESET_STATS, reload_handler(), ast_cli_entry::usage, and ast_cli_args::word.
07683 { 07684 struct ast_flags mask = {QUEUE_RESET_STATS,}; 07685 int i; 07686 07687 switch (cmd) { 07688 case CLI_INIT: 07689 e->command = "queue reset stats"; 07690 e->usage = 07691 "Usage: queue reset stats [<queuenames>]\n" 07692 "\n" 07693 "Issuing this command will reset statistics for\n" 07694 "<queuenames>, or for all queues if no queue is\n" 07695 "specified.\n"; 07696 return NULL; 07697 case CLI_GENERATE: 07698 if (a->pos >= 3) { 07699 return complete_queue(a->line, a->word, a->pos, a->n); 07700 } else { 07701 return NULL; 07702 } 07703 } 07704 07705 if (a->argc < 3) { 07706 return CLI_SHOWUSAGE; 07707 } 07708 07709 if (a->argc == 3) { 07710 reload_handler(1, &mask, NULL); 07711 return CLI_SUCCESS; 07712 } 07713 07714 for (i = 3; i < a->argc; ++i) { 07715 reload_handler(1, &mask, a->argv[i]); 07716 } 07717 07718 return CLI_SUCCESS; 07719 }
| static char* handle_queue_rule_show | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 7648 of file app_queue.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strlen_zero(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_queue_rule_show(), ast_cli_args::fd, ast_cli_args::line, penalty_rule::max_relative, penalty_rule::max_value, penalty_rule::min_relative, penalty_rule::min_value, ast_cli_args::n, rule_list::name, ast_cli_args::pos, rule_list::rules, penalty_rule::time, ast_cli_entry::usage, and ast_cli_args::word.
07649 { 07650 const char *rule; 07651 struct rule_list *rl_iter; 07652 struct penalty_rule *pr_iter; 07653 switch (cmd) { 07654 case CLI_INIT: 07655 e->command = "queue show rules"; 07656 e->usage = 07657 "Usage: queue show rules [rulename]\n" 07658 " Show the list of rules associated with rulename. If no\n" 07659 " rulename is specified, list all rules defined in queuerules.conf\n"; 07660 return NULL; 07661 case CLI_GENERATE: 07662 return complete_queue_rule_show(a->line, a->word, a->pos, a->n); 07663 } 07664 07665 if (a->argc != 3 && a->argc != 4) 07666 return CLI_SHOWUSAGE; 07667 07668 rule = a->argc == 4 ? a->argv[3] : ""; 07669 AST_LIST_LOCK(&rule_lists); 07670 AST_LIST_TRAVERSE(&rule_lists, rl_iter, list) { 07671 if (ast_strlen_zero(rule) || !strcasecmp(rl_iter->name, rule)) { 07672 ast_cli(a->fd, "Rule: %s\n", rl_iter->name); 07673 AST_LIST_TRAVERSE(&rl_iter->rules, pr_iter, list) { 07674 ast_cli(a->fd, "\tAfter %d seconds, adjust QUEUE_MAX_PENALTY %s %d and adjust QUEUE_MIN_PENALTY %s %d\n", pr_iter->time, pr_iter->max_relative ? "by" : "to", pr_iter->max_value, pr_iter->min_relative ? "by" : "to", pr_iter->min_value); 07675 } 07676 } 07677 } 07678 AST_LIST_UNLOCK(&rule_lists); 07679 return CLI_SUCCESS; 07680 }
| static char* handle_queue_set_member_penalty | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 7586 of file app_queue.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_queue_set_member_penalty(), ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, RESULT_FAILURE, RESULT_SUCCESS, set_member_penalty(), ast_cli_entry::usage, and ast_cli_args::word.
07587 { 07588 const char *queuename = NULL, *interface; 07589 int penalty = 0; 07590 07591 switch (cmd) { 07592 case CLI_INIT: 07593 e->command = "queue set penalty"; 07594 e->usage = 07595 "Usage: queue set penalty <penalty> on <interface> [in <queue>]\n" 07596 " Set a member's penalty in the queue specified. If no queue is specified\n" 07597 " then that interface's penalty is set in all queues to which that interface is a member\n"; 07598 return NULL; 07599 case CLI_GENERATE: 07600 return complete_queue_set_member_penalty(a->line, a->word, a->pos, a->n); 07601 } 07602 07603 if (a->argc != 6 && a->argc != 8) { 07604 return CLI_SHOWUSAGE; 07605 } else if (strcmp(a->argv[4], "on") || (a->argc > 6 && strcmp(a->argv[6], "in"))) { 07606 return CLI_SHOWUSAGE; 07607 } 07608 07609 if (a->argc == 8) 07610 queuename = a->argv[7]; 07611 interface = a->argv[5]; 07612 penalty = atoi(a->argv[3]); 07613 07614 switch (set_member_penalty(queuename, interface, penalty)) { 07615 case RESULT_SUCCESS: 07616 ast_cli(a->fd, "Set penalty on interface '%s' from queue '%s'\n", interface, queuename); 07617 return CLI_SUCCESS; 07618 case RESULT_FAILURE: 07619 ast_cli(a->fd, "Failed to set penalty on interface '%s' from queue '%s'\n", interface, queuename); 07620 return CLI_FAILURE; 07621 default: 07622 return CLI_FAILURE; 07623 } 07624 }
| static int handle_statechange | ( | void * | datap | ) | [static] |
set a member's status based on device state of that member's interface
Definition at line 1286 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_t_iterator_next, ao2_unlock, ast_copy_string(), ast_debug, ast_devstate2str(), ast_free, statechange::dev, call_queue::found, call_queue::members, queue_t_unref, queues, statechange::state, member::state_interface, and update_status().
Referenced by device_state_cb().
01287 { 01288 struct statechange *sc = datap; 01289 struct ao2_iterator miter, qiter; 01290 struct member *m; 01291 struct call_queue *q; 01292 char interface[80], *slash_pos; 01293 int found = 0; 01294 01295 qiter = ao2_iterator_init(queues, 0); 01296 while ((q = ao2_t_iterator_next(&qiter, "Iterate over queues"))) { 01297 ao2_lock(q); 01298 01299 miter = ao2_iterator_init(q->members, 0); 01300 for (; (m = ao2_iterator_next(&miter)); ao2_ref(m, -1)) { 01301 ast_copy_string(interface, m->state_interface, sizeof(interface)); 01302 01303 if ((slash_pos = strchr(interface, '/'))) 01304 if (!strncasecmp(interface, "Local/", 6) && (slash_pos = strchr(slash_pos + 1, '/'))) 01305 *slash_pos = '\0'; 01306 01307 if (!strcasecmp(interface, sc->dev)) { 01308 found = 1; 01309 update_status(q, m, sc->state); 01310 ao2_ref(m, -1); 01311 break; 01312 } 01313 } 01314 ao2_iterator_destroy(&miter); 01315 01316 ao2_unlock(q); 01317 queue_t_unref(q, "Done with iterator"); 01318 } 01319 ao2_iterator_destroy(&qiter); 01320 01321 if (found) 01322 ast_debug(1, "Device '%s' changed to state '%d' (%s)\n", sc->dev, sc->state, ast_devstate2str(sc->state)); 01323 else 01324 ast_debug(3, "Device '%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n", sc->dev, sc->state, ast_devstate2str(sc->state)); 01325 01326 ast_free(sc); 01327 return 0; 01328 }
| static void hangupcalls | ( | struct callattempt * | outgoing, | |
| struct ast_channel * | exception, | |||
| int | cancel_answered_elsewhere | |||
| ) | [static] |
Hang up a list of outgoing calls.
Definition at line 2667 of file app_queue.c.
References callattempt::aoc_s_rate_list, ast_aoc_destroy_decoded(), AST_FLAG_ANSWERED_ELSEWHERE, ast_hangup(), ast_set_flag, callattempt_free(), callattempt::chan, and callattempt::q_next.
Referenced by try_calling().
02668 { 02669 struct callattempt *oo; 02670 02671 while (outgoing) { 02672 /* If someone else answered the call we should indicate this in the CANCEL */ 02673 /* Hangup any existing lines we have open */ 02674 if (outgoing->chan && (outgoing->chan != exception)) { 02675 if (exception || cancel_answered_elsewhere) 02676 ast_set_flag(outgoing->chan, AST_FLAG_ANSWERED_ELSEWHERE); 02677 ast_hangup(outgoing->chan); 02678 } 02679 oo = outgoing; 02680 outgoing = outgoing->q_next; 02681 ast_aoc_destroy_decoded(oo->aoc_s_rate_list); 02682 callattempt_free(oo); 02683 } 02684 }
| static void init_queue | ( | struct call_queue * | q | ) | [static] |
Initialize Queue default values.
Definition at line 1496 of file app_queue.c.
References call_queue::announcefrequency, call_queue::announceholdtime, call_queue::announceposition, ANNOUNCEPOSITION_YES, call_queue::announcepositionlimit, ao2_container_alloc, ast_free, AST_LIST_REMOVE_HEAD, ast_str_create(), ast_str_set(), ast_string_field_set, call_queue::autofill, call_queue::autopause, call_queue::dead, DEFAULT_MIN_ANNOUNCE_FREQUENCY, DEFAULT_RETRY, DEFAULT_TIMEOUT, call_queue::eventwhencalled, call_queue::found, call_queue::joinempty, call_queue::leavewhenempty, call_queue::maskmemberstatus, MAX_PERIODIC_ANNOUNCEMENTS, call_queue::maxlen, member_cmp_fn(), member_hash_fn(), call_queue::memberdelay, call_queue::members, call_queue::minannouncefrequency, call_queue::monfmt, call_queue::montype, call_queue::numperiodicannounce, call_queue::penaltymemberslimit, call_queue::periodicannouncefrequency, QUEUE_AUTOPAUSE_OFF, QUEUE_STRATEGY_LINEAR, call_queue::randomperiodicannounce, call_queue::reportholdtime, call_queue::retry, call_queue::ringinuse, call_queue::roundingseconds, call_queue::rules, call_queue::servicelevel, call_queue::setinterfacevar, call_queue::setqueueentryvar, call_queue::setqueuevar, call_queue::sound_periodicannounce, call_queue::strategy, call_queue::timeout, TIMEOUT_PRIORITY_APP, call_queue::timeoutpriority, call_queue::timeoutrestart, call_queue::weight, and call_queue::wrapuptime.
Referenced by find_queue_by_name_rt(), and reload_single_queue().
01497 { 01498 int i; 01499 struct penalty_rule *pr_iter; 01500 01501 q->dead = 0; 01502 q->retry = DEFAULT_RETRY; 01503 q->timeout = DEFAULT_TIMEOUT; 01504 q->maxlen = 0; 01505 q->announcefrequency = 0; 01506 q->minannouncefrequency = DEFAULT_MIN_ANNOUNCE_FREQUENCY; 01507 q->announceholdtime = 1; 01508 q->announcepositionlimit = 10; /* Default 10 positions */ 01509 q->announceposition = ANNOUNCEPOSITION_YES; /* Default yes */ 01510 q->roundingseconds = 0; /* Default - don't announce seconds */ 01511 q->servicelevel = 0; 01512 q->ringinuse = 1; 01513 q->setinterfacevar = 0; 01514 q->setqueuevar = 0; 01515 q->setqueueentryvar = 0; 01516 q->autofill = autofill_default; 01517 q->montype = montype_default; 01518 q->monfmt[0] = '\0'; 01519 q->reportholdtime = 0; 01520 q->wrapuptime = 0; 01521 q->penaltymemberslimit = 0; 01522 q->joinempty = 0; 01523 q->leavewhenempty = 0; 01524 q->memberdelay = 0; 01525 q->maskmemberstatus = 0; 01526 q->eventwhencalled = 0; 01527 q->weight = 0; 01528 q->timeoutrestart = 0; 01529 q->periodicannouncefrequency = 0; 01530 q->randomperiodicannounce = 0; 01531 q->numperiodicannounce = 0; 01532 q->autopause = QUEUE_AUTOPAUSE_OFF; 01533 q->timeoutpriority = TIMEOUT_PRIORITY_APP; 01534 if (!q->members) { 01535 if (q->strategy == QUEUE_STRATEGY_LINEAR) 01536 /* linear strategy depends on order, so we have to place all members in a single bucket */ 01537 q->members = ao2_container_alloc(1, member_hash_fn, member_cmp_fn); 01538 else 01539 q->members = ao2_container_alloc(37, member_hash_fn, member_cmp_fn); 01540 } 01541 q->found = 1; 01542 01543 ast_string_field_set(q, sound_next, "queue-youarenext"); 01544 ast_string_field_set(q, sound_thereare, "queue-thereare"); 01545 ast_string_field_set(q, sound_calls, "queue-callswaiting"); 01546 ast_string_field_set(q, queue_quantity1, "queue-quantity1"); 01547 ast_string_field_set(q, queue_quantity2, "queue-quantity2"); 01548 ast_string_field_set(q, sound_holdtime, "queue-holdtime"); 01549 ast_string_field_set(q, sound_minutes, "queue-minutes"); 01550 ast_string_field_set(q, sound_minute, "queue-minute"); 01551 ast_string_field_set(q, sound_seconds, "queue-seconds"); 01552 ast_string_field_set(q, sound_thanks, "queue-thankyou"); 01553 ast_string_field_set(q, sound_reporthold, "queue-reporthold"); 01554 01555 if ((q->sound_periodicannounce[0] = ast_str_create(32))) 01556 ast_str_set(&q->sound_periodicannounce[0], 0, "queue-periodic-announce"); 01557 01558 for (i = 1; i < MAX_PERIODIC_ANNOUNCEMENTS; i++) { 01559 if (q->sound_periodicannounce[i]) 01560 ast_str_set(&q->sound_periodicannounce[i], 0, "%s", ""); 01561 } 01562 01563 while ((pr_iter = AST_LIST_REMOVE_HEAD(&q->rules,list))) 01564 ast_free(pr_iter); 01565 }
| static void insert_entry | ( | struct call_queue * | q, | |
| struct queue_ent * | prev, | |||
| struct queue_ent * | new, | |||
| int * | pos | |||
| ) | [inline, static] |
Insert the 'new' entry after the 'prev' entry of queue 'q'.
Definition at line 1151 of file app_queue.c.
References call_queue::head, queue_ent::next, and queue_ref().
Referenced by join_queue().
01152 { 01153 struct queue_ent *cur; 01154 01155 if (!q || !new) 01156 return; 01157 if (prev) { 01158 cur = prev->next; 01159 prev->next = new; 01160 } else { 01161 cur = q->head; 01162 q->head = new; 01163 } 01164 new->next = cur; 01165 01166 /* every queue_ent must have a reference to it's parent call_queue, this 01167 * reference does not go away until the end of the queue_ent's life, meaning 01168 * that even when the queue_ent leaves the call_queue this ref must remain. */ 01169 queue_ref(q); 01170 new->parent = q; 01171 new->pos = ++(*pos); 01172 new->opos = *pos; 01173 }
| static int insert_penaltychange | ( | const char * | list_name, | |
| const char * | content, | |||
| const int | linenum | |||
| ) | [static] |
Change queue penalty by adding rule.
Check rule for errors with time or fomatting, see if rule is relative to rest of queue, iterate list of rules to find correct insertion point, insert and return.
| -1 | on failure | |
| 0 | on success |
Definition at line 1596 of file app_queue.c.
References ast_calloc, ast_free, AST_LIST_INSERT_BEFORE_CURRENT, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_strdupa, ast_strlen_zero(), LOG_WARNING, penalty_rule::max_relative, penalty_rule::max_value, penalty_rule::min_relative, penalty_rule::min_value, rule_list::name, rule_list::rules, and penalty_rule::time.
Referenced by reload_queue_rules().
01597 { 01598 char *timestr, *maxstr, *minstr, *contentdup; 01599 struct penalty_rule *rule = NULL, *rule_iter; 01600 struct rule_list *rl_iter; 01601 int penaltychangetime, inserted = 0; 01602 01603 if (!(rule = ast_calloc(1, sizeof(*rule)))) { 01604 return -1; 01605 } 01606 01607 contentdup = ast_strdupa(content); 01608 01609 if (!(maxstr = strchr(contentdup, ','))) { 01610 ast_log(LOG_WARNING, "Improperly formatted penaltychange rule at line %d. Ignoring.\n", linenum); 01611 ast_free(rule); 01612 return -1; 01613 } 01614 01615 *maxstr++ = '\0'; 01616 timestr = contentdup; 01617 01618 if ((penaltychangetime = atoi(timestr)) < 0) { 01619 ast_log(LOG_WARNING, "Improper time parameter specified for penaltychange rule at line %d. Ignoring.\n", linenum); 01620 ast_free(rule); 01621 return -1; 01622 } 01623 01624 rule->time = penaltychangetime; 01625 01626 if ((minstr = strchr(maxstr,','))) 01627 *minstr++ = '\0'; 01628 01629 /* The last check will evaluate true if either no penalty change is indicated for a given rule 01630 * OR if a min penalty change is indicated but no max penalty change is */ 01631 if (*maxstr == '+' || *maxstr == '-' || *maxstr == '\0') { 01632 rule->max_relative = 1; 01633 } 01634 01635 rule->max_value = atoi(maxstr); 01636 01637 if (!ast_strlen_zero(minstr)) { 01638 if (*minstr == '+' || *minstr == '-') 01639 rule->min_relative = 1; 01640 rule->min_value = atoi(minstr); 01641 } else /*there was no minimum specified, so assume this means no change*/ 01642 rule->min_relative = 1; 01643 01644 /*We have the rule made, now we need to insert it where it belongs*/ 01645 AST_LIST_TRAVERSE(&rule_lists, rl_iter, list){ 01646 if (strcasecmp(rl_iter->name, list_name)) 01647 continue; 01648 01649 AST_LIST_TRAVERSE_SAFE_BEGIN(&rl_iter->rules, rule_iter, list) { 01650 if (rule->time < rule_iter->time) { 01651 AST_LIST_INSERT_BEFORE_CURRENT(rule, list); 01652 inserted = 1; 01653 break; 01654 } 01655 } 01656 AST_LIST_TRAVERSE_SAFE_END; 01657 01658 if (!inserted) { 01659 AST_LIST_INSERT_TAIL(&rl_iter->rules, rule, list); 01660 } 01661 } 01662 01663 return 0; 01664 }
| static const char* int2strat | ( | int | strategy | ) | [static] |
Definition at line 1049 of file app_queue.c.
References ARRAY_LEN, strategy::name, and strategies.
Referenced by __queues_show(), manager_queues_status(), queue_function_var(), queues_data_provider_get_helper(), and set_queue_variables().
01050 { 01051 int x; 01052 01053 for (x = 0; x < ARRAY_LEN(strategies); x++) { 01054 if (strategy == strategies[x].strategy) 01055 return strategies[x].name; 01056 } 01057 01058 return "<unknown>"; 01059 }
| static struct member* interface_exists | ( | struct call_queue * | q, | |
| const char * | interface | |||
| ) | [static, read] |
Definition at line 4907 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, member::interface, and call_queue::members.
Referenced by add_to_queue(), get_member_penalty(), set_member_paused(), and set_member_penalty().
04908 { 04909 struct member *mem; 04910 struct ao2_iterator mem_iter; 04911 04912 if (!q) 04913 return NULL; 04914 04915 mem_iter = ao2_iterator_init(q->members, 0); 04916 while ((mem = ao2_iterator_next(&mem_iter))) { 04917 if (!strcasecmp(interface, mem->interface)) { 04918 ao2_iterator_destroy(&mem_iter); 04919 return mem; 04920 } 04921 ao2_ref(mem, -1); 04922 } 04923 ao2_iterator_destroy(&mem_iter); 04924 04925 return NULL; 04926 }
| static int is_our_turn | ( | struct queue_ent * | qe | ) | [static] |
Check if we should start attempting to call queue members.
A simple process, really. Count the number of members who are available to take our call and then see if we are in a position in the queue at which a member could accept our call.
| [in] | qe | The caller who wants to know if it is his turn |
| 0 | It is not our turn | |
| 1 | It is our turn |
Definition at line 3675 of file app_queue.c.
References ao2_lock, ao2_unlock, ast_debug, call_queue::autofill, queue_ent::chan, call_queue::head, ast_channel::name, queue_ent::next, num_available_members(), queue_ent::parent, queue_ent::pending, and queue_ent::pos.
Referenced by queue_exec(), and wait_our_turn().
03676 { 03677 struct queue_ent *ch; 03678 int res; 03679 int avl; 03680 int idx = 0; 03681 /* This needs a lock. How many members are available to be served? */ 03682 ao2_lock(qe->parent); 03683 03684 avl = num_available_members(qe->parent); 03685 03686 ch = qe->parent->head; 03687 03688 ast_debug(1, "There %s %d available %s.\n", avl != 1 ? "are" : "is", avl, avl != 1 ? "members" : "member"); 03689 03690 while ((idx < avl) && (ch) && (ch != qe)) { 03691 if (!ch->pending) 03692 idx++; 03693 ch = ch->next; 03694 } 03695 03696 ao2_unlock(qe->parent); 03697 /* If the queue entry is within avl [the number of available members] calls from the top ... 03698 * Autofill and position check added to support autofill=no (as only calls 03699 * from the front of the queue are valid when autofill is disabled) 03700 */ 03701 if (ch && idx < avl && (qe->parent->autofill || qe->pos == 1)) { 03702 ast_debug(1, "It's our turn (%s).\n", qe->chan->name); 03703 res = 1; 03704 } else { 03705 ast_debug(1, "It's not our turn (%s).\n", qe->chan->name); 03706 res = 0; 03707 } 03708 03709 return res; 03710 }
| static int join_queue | ( | char * | queuename, | |
| struct queue_ent * | qe, | |||
| enum queue_result * | reason, | |||
| int | position | |||
| ) | [static] |
Definition at line 2286 of file app_queue.c.
References call_queue::announce, queue_ent::announce, ao2_lock, ao2_unlock, ast_copy_string(), ast_debug, ast_log(), ast_manager_event, ast_channel::caller, queue_ent::chan, call_queue::context, queue_ent::context, call_queue::count, EVENT_FLAG_CALL, get_member_status(), call_queue::head, ast_party_caller::id, insert_entry(), call_queue::joinempty, load_realtime_queue(), LOG_NOTICE, queue_ent::max_penalty, call_queue::maxlen, queue_ent::min_penalty, call_queue::moh, queue_ent::moh, call_queue::name, ast_party_id::name, ast_channel::name, queue_ent::next, ast_party_id::number, queue_ent::pos, queue_ent::prio, QUEUE_FULL, QUEUE_JOINEMPTY, QUEUE_UNKNOWN, queues, S_COR, status, ast_party_name::str, ast_party_number::str, ast_channel::uniqueid, ast_party_name::valid, and ast_party_number::valid.
Referenced by queue_exec().
02287 { 02288 struct call_queue *q; 02289 struct queue_ent *cur, *prev = NULL; 02290 int res = -1; 02291 int pos = 0; 02292 int inserted = 0; 02293 02294 if (!(q = load_realtime_queue(queuename))) 02295 return res; 02296 02297 ao2_lock(queues); 02298 ao2_lock(q); 02299 02300 /* This is our one */ 02301 if (q->joinempty) { 02302 int status = 0; 02303 if ((status = get_member_status(q, qe->max_penalty, qe->min_penalty, q->joinempty))) { 02304 *reason = QUEUE_JOINEMPTY; 02305 ao2_unlock(q); 02306 ao2_unlock(queues); 02307 return res; 02308 } 02309 } 02310 if (*reason == QUEUE_UNKNOWN && q->maxlen && (q->count >= q->maxlen)) 02311 *reason = QUEUE_FULL; 02312 else if (*reason == QUEUE_UNKNOWN) { 02313 /* There's space for us, put us at the right position inside 02314 * the queue. 02315 * Take into account the priority of the calling user */ 02316 inserted = 0; 02317 prev = NULL; 02318 cur = q->head; 02319 while (cur) { 02320 /* We have higher priority than the current user, enter 02321 * before him, after all the other users with priority 02322 * higher or equal to our priority. */ 02323 if ((!inserted) && (qe->prio > cur->prio)) { 02324 insert_entry(q, prev, qe, &pos); 02325 inserted = 1; 02326 } 02327 /* <= is necessary for the position comparison because it may not be possible to enter 02328 * at our desired position since higher-priority callers may have taken the position we want 02329 */ 02330 if (!inserted && (qe->prio >= cur->prio) && position && (position <= pos + 1)) { 02331 insert_entry(q, prev, qe, &pos); 02332 /*pos is incremented inside insert_entry, so don't need to add 1 here*/ 02333 if (position < pos) { 02334 ast_log(LOG_NOTICE, "Asked to be inserted at position %d but forced into position %d due to higher priority callers\n", position, pos); 02335 } 02336 inserted = 1; 02337 } 02338 cur->pos = ++pos; 02339 prev = cur; 02340 cur = cur->next; 02341 } 02342 /* No luck, join at the end of the queue */ 02343 if (!inserted) 02344 insert_entry(q, prev, qe, &pos); 02345 ast_copy_string(qe->moh, q->moh, sizeof(qe->moh)); 02346 ast_copy_string(qe->announce, q->announce, sizeof(qe->announce)); 02347 ast_copy_string(qe->context, q->context, sizeof(qe->context)); 02348 q->count++; 02349 res = 0; 02350 ast_manager_event(qe->chan, EVENT_FLAG_CALL, "Join", 02351 "Channel: %s\r\nCallerIDNum: %s\r\nCallerIDName: %s\r\nQueue: %s\r\nPosition: %d\r\nCount: %d\r\nUniqueid: %s\r\n", 02352 qe->chan->name, 02353 S_COR(qe->chan->caller.id.number.valid, qe->chan->caller.id.number.str, "unknown"),/* XXX somewhere else it is <unknown> */ 02354 S_COR(qe->chan->caller.id.name.valid, qe->chan->caller.id.name.str, "unknown"), 02355 q->name, qe->pos, q->count, qe->chan->uniqueid ); 02356 ast_debug(1, "Queue '%s' Join, Channel '%s', Position '%d'\n", q->name, qe->chan->name, qe->pos ); 02357 } 02358 ao2_unlock(q); 02359 ao2_unlock(queues); 02360 02361 return res; 02362 }
| static int kill_dead_members | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 6432 of file app_queue.c.
References CMP_MATCH, member::delme, member::dynamic, get_queue_member_status(), call_queue::membercount, and member::status.
Referenced by reload_single_queue().
06433 { 06434 struct member *member = obj; 06435 struct call_queue *q = arg; 06436 06437 if (!member->delme) { 06438 if (member->dynamic) { 06439 /* dynamic members were not counted toward the member count 06440 * when reloading members from queues.conf, so we do that here 06441 */ 06442 q->membercount++; 06443 } 06444 member->status = get_queue_member_status(member); 06445 return 0; 06446 } else { 06447 q->membercount--; 06448 return CMP_MATCH; 06449 } 06450 }
| static int kill_dead_queues | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 6570 of file app_queue.c.
References ast_strlen_zero(), CMP_MATCH, call_queue::dead, and call_queue::name.
Referenced by reload_queues().
06571 { 06572 struct call_queue *q = obj; 06573 char *queuename = arg; 06574 if ((ast_strlen_zero(queuename) || !strcasecmp(queuename, q->name)) && q->dead) { 06575 return CMP_MATCH; 06576 } else { 06577 return 0; 06578 } 06579 }
| static void leave_queue | ( | struct queue_ent * | qe | ) | [static] |
Caller leaving queue.
Search the queue to find the leaving client, if found remove from queue create manager event, move others up the queue.
Definition at line 2589 of file app_queue.c.
References ao2_lock, ao2_unlock, ast_debug, ast_free, AST_LIST_REMOVE_HEAD, ast_load_realtime(), ast_manager_event, ast_variables_destroy(), queue_ent::chan, call_queue::count, call_queue::dead, EVENT_FLAG_CALL, call_queue::head, call_queue::name, ast_channel::name, queue_ent::next, queue_ent::parent, pbx_builtin_setvar_helper(), queue_ent::pos, queue_ent::qe_rules, queue_t_ref, queue_t_unref, queues, queues_t_unlink, call_queue::realtime, SENTINEL, ast_channel::uniqueid, and var.
Referenced by queue_exec(), try_calling(), and wait_our_turn().
02590 { 02591 struct call_queue *q; 02592 struct queue_ent *current, *prev = NULL; 02593 struct penalty_rule *pr_iter; 02594 int pos = 0; 02595 02596 if (!(q = qe->parent)) 02597 return; 02598 queue_t_ref(q, "Copy queue pointer from queue entry"); 02599 ao2_lock(q); 02600 02601 prev = NULL; 02602 for (current = q->head; current; current = current->next) { 02603 if (current == qe) { 02604 char posstr[20]; 02605 q->count--; 02606 02607 /* Take us out of the queue */ 02608 ast_manager_event(qe->chan, EVENT_FLAG_CALL, "Leave", 02609 "Channel: %s\r\nQueue: %s\r\nCount: %d\r\nPosition: %d\r\nUniqueid: %s\r\n", 02610 qe->chan->name, q->name, q->count, qe->pos, qe->chan->uniqueid); 02611 ast_debug(1, "Queue '%s' Leave, Channel '%s'\n", q->name, qe->chan->name ); 02612 /* Take us out of the queue */ 02613 if (prev) 02614 prev->next = current->next; 02615 else 02616 q->head = current->next; 02617 /* Free penalty rules */ 02618 while ((pr_iter = AST_LIST_REMOVE_HEAD(&qe->qe_rules, list))) 02619 ast_free(pr_iter); 02620 snprintf(posstr, sizeof(posstr), "%d", qe->pos); 02621 pbx_builtin_setvar_helper(qe->chan, "QUEUEPOSITION", posstr); 02622 } else { 02623 /* Renumber the people after us in the queue based on a new count */ 02624 current->pos = ++pos; 02625 prev = current; 02626 } 02627 } 02628 ao2_unlock(q); 02629 02630 /*If the queue is a realtime queue, check to see if it's still defined in real time*/ 02631 if (q->realtime) { 02632 struct ast_variable *var; 02633 if (!(var = ast_load_realtime("queues", "name", q->name, SENTINEL))) { 02634 q->dead = 1; 02635 } else { 02636 ast_variables_destroy(var); 02637 } 02638 } 02639 02640 if (q->dead) { 02641 /* It's dead and nobody is in it, so kill it */ 02642 queues_t_unlink(queues, q, "Queue is now dead; remove it from the container"); 02643 } 02644 /* unref the explicit ref earlier in the function */ 02645 queue_t_unref(q, "Expire copied reference"); 02646 }
| static int load_module | ( | void | ) | [static] |
Definition at line 8120 of file app_queue.c.
References ao2_container_alloc, aqm_exec(), ARRAY_LEN, ast_add_extension2(), ast_cli_register_multiple(), ast_context_find_or_create(), ast_custom_function_register, ast_data_register_multiple, AST_EVENT_DEVICE_STATE, AST_EVENT_IE_END, ast_event_subscribe(), ast_extension_state_add(), AST_FLAGS_ALL, ast_free_ptr, ast_log(), ast_manager_register_xml, AST_MODULE_LOAD_DECLINE, ast_realtime_require_field(), ast_register_application_xml, ast_strdup, ast_taskprocessor_get(), cli_queue, device_state_cb(), EVENT_FLAG_AGENT, extension_state_cb(), LOG_ERROR, LOG_WARNING, manager_add_queue_member(), manager_pause_queue_member(), manager_queue_log_custom(), manager_queue_member_penalty(), manager_queue_reload(), manager_queue_reset(), manager_queue_rule_show(), manager_queues_show(), manager_queues_status(), manager_queues_summary(), manager_remove_queue_member(), MAX_QUEUE_BUCKETS, pqm_exec(), ql_exec(), queue_cmp_cb(), queue_data_providers, queue_exec(), queue_hash_cb(), queueexists_function, queuemembercount_dep, queuemembercount_function, queuememberlist_function, queuememberpenalty_function, queues, queuevar_function, queuewaitingcount_function, reload_handler(), reload_queue_members(), RQ_INTEGER1, RQ_UINTEGER2, rqm_exec(), SENTINEL, and upqm_exec().
08121 { 08122 int res; 08123 struct ast_context *con; 08124 struct ast_flags mask = {AST_FLAGS_ALL, }; 08125 08126 queues = ao2_container_alloc(MAX_QUEUE_BUCKETS, queue_hash_cb, queue_cmp_cb); 08127 08128 use_weight = 0; 08129 08130 if (reload_handler(0, &mask, NULL)) 08131 return AST_MODULE_LOAD_DECLINE; 08132 08133 con = ast_context_find_or_create(NULL, NULL, "app_queue_gosub_virtual_context", "app_queue"); 08134 if (!con) 08135 ast_log(LOG_ERROR, "Queue virtual context 'app_queue_gosub_virtual_context' does not exist and unable to create\n"); 08136 else 08137 ast_add_extension2(con, 1, "s", 1, NULL, NULL, "NoOp", ast_strdup(""), ast_free_ptr, "app_queue"); 08138 08139 if (queue_persistent_members) 08140 reload_queue_members(); 08141 08142 ast_data_register_multiple(queue_data_providers, ARRAY_LEN(queue_data_providers)); 08143 08144 ast_cli_register_multiple(cli_queue, ARRAY_LEN(cli_queue)); 08145 res = ast_register_application_xml(app, queue_exec); 08146 res |= ast_register_application_xml(app_aqm, aqm_exec); 08147 res |= ast_register_application_xml(app_rqm, rqm_exec); 08148 res |= ast_register_application_xml(app_pqm, pqm_exec); 08149 res |= ast_register_application_xml(app_upqm, upqm_exec); 08150 res |= ast_register_application_xml(app_ql, ql_exec); 08151 res |= ast_manager_register_xml("Queues", 0, manager_queues_show); 08152 res |= ast_manager_register_xml("QueueStatus", 0, manager_queues_status); 08153 res |= ast_manager_register_xml("QueueSummary", 0, manager_queues_summary); 08154 res |= ast_manager_register_xml("QueueAdd", EVENT_FLAG_AGENT, manager_add_queue_member); 08155 res |= ast_manager_register_xml("QueueRemove", EVENT_FLAG_AGENT, manager_remove_queue_member); 08156 res |= ast_manager_register_xml("QueuePause", EVENT_FLAG_AGENT, manager_pause_queue_member); 08157 res |= ast_manager_register_xml("QueueLog", EVENT_FLAG_AGENT, manager_queue_log_custom); 08158 res |= ast_manager_register_xml("QueuePenalty", EVENT_FLAG_AGENT, manager_queue_member_penalty); 08159 res |= ast_manager_register_xml("QueueRule", 0, manager_queue_rule_show); 08160 res |= ast_manager_register_xml("QueueReload", 0, manager_queue_reload); 08161 res |= ast_manager_register_xml("QueueReset", 0, manager_queue_reset); 08162 res |= ast_custom_function_register(&queuevar_function); 08163 res |= ast_custom_function_register(&queueexists_function); 08164 res |= ast_custom_function_register(&queuemembercount_function); 08165 res |= ast_custom_function_register(&queuemembercount_dep); 08166 res |= ast_custom_function_register(&queuememberlist_function); 08167 res |= ast_custom_function_register(&queuewaitingcount_function); 08168 res |= ast_custom_function_register(&queuememberpenalty_function); 08169 08170 if (!(devicestate_tps = ast_taskprocessor_get("app_queue", 0))) { 08171 ast_log(LOG_WARNING, "devicestate taskprocessor reference failed - devicestate notifications will not occur\n"); 08172 } 08173 08174 /* in the following subscribe call, do I use DEVICE_STATE, or DEVICE_STATE_CHANGE? */ 08175 if (!(device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, device_state_cb, "AppQueue Device state", NULL, AST_EVENT_IE_END))) { 08176 res = -1; 08177 } 08178 08179 ast_extension_state_add(NULL, NULL, extension_state_cb, NULL); 08180 08181 ast_realtime_require_field("queue_members", "paused", RQ_INTEGER1, 1, "uniqueid", RQ_UINTEGER2, 5, SENTINEL); 08182 08183 return res ? AST_MODULE_LOAD_DECLINE : 0; 08184 }
| static struct call_queue* load_realtime_queue | ( | const char * | queuename | ) | [static, read] |
Definition at line 2160 of file app_queue.c.
References ao2_lock, ao2_t_find, ao2_unlock, ast_atomic_fetchadd_int(), ast_config_destroy(), ast_load_realtime(), ast_load_realtime_multientry(), ast_log(), ast_variables_destroy(), find_queue_by_name_rt(), LOG_ERROR, call_queue::name, OBJ_POINTER, queues, call_queue::realtime, SENTINEL, update_realtime_members(), and call_queue::weight.
Referenced by __queues_show(), add_to_queue(), join_queue(), queue_function_exists(), queue_function_qac(), queue_function_qac_dep(), queues_data_provider_get(), and reload_queue_members().
02161 { 02162 struct ast_variable *queue_vars; 02163 struct ast_config *member_config = NULL; 02164 struct call_queue *q = NULL, tmpq = { 02165 .name = queuename, 02166 }; 02167 int prev_weight = 0; 02168 02169 /* Find the queue in the in-core list first. */ 02170 q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Look for queue in memory first"); 02171 02172 if (!q || q->realtime) { 02173 /*! \note Load from realtime before taking the "queues" container lock, to avoid blocking all 02174 queue operations while waiting for the DB. 02175 02176 This will be two separate database transactions, so we might 02177 see queue parameters as they were before another process 02178 changed the queue and member list as it was after the change. 02179 Thus we might see an empty member list when a queue is 02180 deleted. In practise, this is unlikely to cause a problem. */ 02181 02182 queue_vars = ast_load_realtime("queues", "name", queuename, SENTINEL); 02183 if (queue_vars) { 02184 member_config = ast_load_realtime_multientry("queue_members", "interface LIKE", "%", "queue_name", queuename, SENTINEL); 02185 if (!member_config) { 02186 ast_log(LOG_ERROR, "no queue_members defined in your config (extconfig.conf).\n"); 02187 ast_variables_destroy(queue_vars); 02188 return NULL; 02189 } 02190 } 02191 if (q) { 02192 prev_weight = q->weight ? 1 : 0; 02193 } 02194 02195 ao2_lock(queues); 02196 02197 q = find_queue_by_name_rt(queuename, queue_vars, member_config); 02198 if (member_config) { 02199 ast_config_destroy(member_config); 02200 } 02201 if (queue_vars) { 02202 ast_variables_destroy(queue_vars); 02203 } 02204 /* update the use_weight value if the queue's has gained or lost a weight */ 02205 if (q) { 02206 if (!q->weight && prev_weight) { 02207 ast_atomic_fetchadd_int(&use_weight, -1); 02208 } 02209 if (q->weight && !prev_weight) { 02210 ast_atomic_fetchadd_int(&use_weight, +1); 02211 } 02212 } 02213 /* Other cases will end up with the proper value for use_weight */ 02214 ao2_unlock(queues); 02215 02216 } else { 02217 update_realtime_members(q); 02218 } 02219 return q; 02220 }
| static int manager_add_queue_member | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 7095 of file app_queue.c.
References add_to_queue(), ast_queue_log(), ast_strlen_zero(), ast_true(), astman_get_header(), astman_send_ack(), astman_send_error(), RES_EXISTS, RES_NOSUCHQUEUE, RES_OKAY, and RES_OUTOFMEMORY.
Referenced by load_module().
07096 { 07097 const char *queuename, *interface, *penalty_s, *paused_s, *membername, *state_interface; 07098 int paused, penalty = 0; 07099 07100 queuename = astman_get_header(m, "Queue"); 07101 interface = astman_get_header(m, "Interface"); 07102 penalty_s = astman_get_header(m, "Penalty"); 07103 paused_s = astman_get_header(m, "Paused"); 07104 membername = astman_get_header(m, "MemberName"); 07105 state_interface = astman_get_header(m, "StateInterface"); 07106 07107 if (ast_strlen_zero(queuename)) { 07108 astman_send_error(s, m, "'Queue' not specified."); 07109 return 0; 07110 } 07111 07112 if (ast_strlen_zero(interface)) { 07113 astman_send_error(s, m, "'Interface' not specified."); 07114 return 0; 07115 } 07116 07117 if (ast_strlen_zero(penalty_s)) 07118 penalty = 0; 07119 else if (sscanf(penalty_s, "%30d", &penalty) != 1 || penalty < 0) 07120 penalty = 0; 07121 07122 if (ast_strlen_zero(paused_s)) 07123 paused = 0; 07124 else 07125 paused = abs(ast_true(paused_s)); 07126 07127 switch (add_to_queue(queuename, interface, membername, penalty, paused, queue_persistent_members, state_interface)) { 07128 case RES_OKAY: 07129 ast_queue_log(queuename, "MANAGER", interface, "ADDMEMBER", "%s", ""); 07130 astman_send_ack(s, m, "Added interface to queue"); 07131 break; 07132 case RES_EXISTS: 07133 astman_send_error(s, m, "Unable to add interface: Already there"); 07134 break; 07135 case RES_NOSUCHQUEUE: 07136 astman_send_error(s, m, "Unable to add interface to queue: No such queue"); 07137 break; 07138 case RES_OUTOFMEMORY: 07139 astman_send_error(s, m, "Out of memory"); 07140 break; 07141 } 07142 07143 return 0; 07144 }
| static int manager_pause_queue_member | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 7180 of file app_queue.c.
References ast_strlen_zero(), ast_true(), astman_get_header(), astman_send_ack(), astman_send_error(), and set_member_paused().
Referenced by load_module().
07181 { 07182 const char *queuename, *interface, *paused_s, *reason; 07183 int paused; 07184 07185 interface = astman_get_header(m, "Interface"); 07186 paused_s = astman_get_header(m, "Paused"); 07187 queuename = astman_get_header(m, "Queue"); /* Optional - if not supplied, pause the given Interface in all queues */ 07188 reason = astman_get_header(m, "Reason"); /* Optional - Only used for logging purposes */ 07189 07190 if (ast_strlen_zero(interface) || ast_strlen_zero(paused_s)) { 07191 astman_send_error(s, m, "Need 'Interface' and 'Paused' parameters."); 07192 return 0; 07193 } 07194 07195 paused = abs(ast_true(paused_s)); 07196 07197 if (set_member_paused(queuename, interface, reason, paused)) 07198 astman_send_error(s, m, "Interface not found"); 07199 else 07200 astman_send_ack(s, m, paused ? "Interface paused successfully" : "Interface unpaused successfully"); 07201 return 0; 07202 }
| static int manager_queue_log_custom | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 7204 of file app_queue.c.
References ast_queue_log(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), and S_OR.
Referenced by load_module().
07205 { 07206 const char *queuename, *event, *message, *interface, *uniqueid; 07207 07208 queuename = astman_get_header(m, "Queue"); 07209 uniqueid = astman_get_header(m, "UniqueId"); 07210 interface = astman_get_header(m, "Interface"); 07211 event = astman_get_header(m, "Event"); 07212 message = astman_get_header(m, "Message"); 07213 07214 if (ast_strlen_zero(queuename) || ast_strlen_zero(event)) { 07215 astman_send_error(s, m, "Need 'Queue' and 'Event' parameters."); 07216 return 0; 07217 } 07218 07219 ast_queue_log(queuename, S_OR(uniqueid, "NONE"), interface, event, "%s", message); 07220 astman_send_ack(s, m, "Event added successfully"); 07221 07222 return 0; 07223 }
| static int manager_queue_member_penalty | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 7303 of file app_queue.c.
References ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), and set_member_penalty().
Referenced by load_module().
07304 { 07305 const char *queuename, *interface, *penalty_s; 07306 int penalty; 07307 07308 interface = astman_get_header(m, "Interface"); 07309 penalty_s = astman_get_header(m, "Penalty"); 07310 /* Optional - if not supplied, set the penalty value for the given Interface in all queues */ 07311 queuename = astman_get_header(m, "Queue"); 07312 07313 if (ast_strlen_zero(interface) || ast_strlen_zero(penalty_s)) { 07314 astman_send_error(s, m, "Need 'Interface' and 'Penalty' parameters."); 07315 return 0; 07316 } 07317 07318 penalty = atoi(penalty_s); 07319 07320 if (set_member_penalty((char *)queuename, (char *)interface, penalty)) 07321 astman_send_error(s, m, "Invalid interface, queuename or penalty"); 07322 else 07323 astman_send_ack(s, m, "Interface penalty set successfully"); 07324 07325 return 0; 07326 }
| static int manager_queue_reload | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 7225 of file app_queue.c.
References AST_FLAGS_ALL, ast_set_flag, astman_get_header(), astman_send_ack(), astman_send_error(), QUEUE_RELOAD_MEMBER, QUEUE_RELOAD_PARAMETERS, QUEUE_RELOAD_RULES, reload_handler(), and S_OR.
Referenced by load_module().
07226 { 07227 struct ast_flags mask = {0,}; 07228 const char *queuename = NULL; 07229 int header_found = 0; 07230 07231 queuename = astman_get_header(m, "Queue"); 07232 if (!strcasecmp(S_OR(astman_get_header(m, "Members"), ""), "yes")) { 07233 ast_set_flag(&mask, QUEUE_RELOAD_MEMBER); 07234 header_found = 1; 07235 } 07236 if (!strcasecmp(S_OR(astman_get_header(m, "Rules"), ""), "yes")) { 07237 ast_set_flag(&mask, QUEUE_RELOAD_RULES); 07238 header_found = 1; 07239 } 07240 if (!strcasecmp(S_OR(astman_get_header(m, "Parameters"), ""), "yes")) { 07241 ast_set_flag(&mask, QUEUE_RELOAD_PARAMETERS); 07242 header_found = 1; 07243 } 07244 07245 if (!header_found) { 07246 ast_set_flag(&mask, AST_FLAGS_ALL); 07247 } 07248 07249 if (!reload_handler(1, &mask, queuename)) { 07250 astman_send_ack(s, m, "Queue reloaded successfully"); 07251 } else { 07252 astman_send_error(s, m, "Error encountered while reloading queue"); 07253 } 07254 return 0; 07255 }
| static int manager_queue_reset | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 7257 of file app_queue.c.
References astman_get_header(), astman_send_ack(), astman_send_error(), QUEUE_RESET_STATS, and reload_handler().
Referenced by load_module().
07258 { 07259 const char *queuename = NULL; 07260 struct ast_flags mask = {QUEUE_RESET_STATS,}; 07261 07262 queuename = astman_get_header(m, "Queue"); 07263 07264 if (!reload_handler(1, &mask, queuename)) { 07265 astman_send_ack(s, m, "Queue stats reset successfully"); 07266 } else { 07267 astman_send_error(s, m, "Error encountered while resetting queue stats"); 07268 } 07269 return 0; 07270 }
| static int manager_queue_rule_show | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 6898 of file app_queue.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strlen_zero(), astman_append(), astman_get_header(), penalty_rule::max_relative, penalty_rule::max_value, penalty_rule::min_relative, penalty_rule::min_value, rule_list::name, RESULT_SUCCESS, rule_list::rules, and penalty_rule::time.
Referenced by load_module().
06899 { 06900 const char *rule = astman_get_header(m, "Rule"); 06901 struct rule_list *rl_iter; 06902 struct penalty_rule *pr_iter; 06903 06904 AST_LIST_LOCK(&rule_lists); 06905 AST_LIST_TRAVERSE(&rule_lists, rl_iter, list) { 06906 if (ast_strlen_zero(rule) || !strcasecmp(rule, rl_iter->name)) { 06907 astman_append(s, "RuleList: %s\r\n", rl_iter->name); 06908 AST_LIST_TRAVERSE(&rl_iter->rules, pr_iter, list) { 06909 astman_append(s, "Rule: %d,%s%d,%s%d\r\n", pr_iter->time, pr_iter->max_relative && pr_iter->max_value >= 0 ? "+" : "", pr_iter->max_value, pr_iter->min_relative && pr_iter->min_value >= 0 ? "+" : "", pr_iter->min_value ); 06910 } 06911 if (!ast_strlen_zero(rule)) 06912 break; 06913 } 06914 } 06915 AST_LIST_UNLOCK(&rule_lists); 06916 06917 astman_append(s, "\r\n\r\n"); 06918 06919 return RESULT_SUCCESS; 06920 }
| static int manager_queues_show | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 6888 of file app_queue.c.
References __queues_show(), astman_append(), and RESULT_SUCCESS.
Referenced by load_module().
06889 { 06890 static const char * const a[] = { "queue", "show" }; 06891 06892 __queues_show(s, -1, 2, a); 06893 astman_append(s, "\r\n\r\n"); /* Properly terminate Manager output */ 06894 06895 return RESULT_SUCCESS; 06896 }
| static int manager_queues_status | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Queue status info via AMI.
Definition at line 6998 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_t_iterator_next, ao2_unlock, ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_ack(), ast_channel::caller, member::calls, call_queue::callsabandoned, call_queue::callscompleted, call_queue::callscompletedinsl, queue_ent::chan, call_queue::count, member::dynamic, call_queue::head, call_queue::holdtime, ast_party_caller::id, int2strat(), member::interface, member::lastcall, call_queue::maxlen, member::membername, call_queue::members, ast_party_id::name, ast_channel::name, call_queue::name, queue_ent::next, ast_party_id::number, member::paused, member::penalty, queue_ent::pos, queue_t_unref, queues, RESULT_SUCCESS, S_COR, call_queue::servicelevel, queue_ent::start, member::status, ast_party_name::str, ast_party_number::str, call_queue::strategy, call_queue::talktime, ast_channel::uniqueid, ast_party_name::valid, ast_party_number::valid, and call_queue::weight.
Referenced by load_module().
06999 { 07000 time_t now; 07001 int pos; 07002 const char *id = astman_get_header(m,"ActionID"); 07003 const char *queuefilter = astman_get_header(m,"Queue"); 07004 const char *memberfilter = astman_get_header(m,"Member"); 07005 char idText[256] = ""; 07006 struct call_queue *q; 07007 struct queue_ent *qe; 07008 float sl = 0; 07009 struct member *mem; 07010 struct ao2_iterator queue_iter; 07011 struct ao2_iterator mem_iter; 07012 07013 astman_send_ack(s, m, "Queue status will follow"); 07014 time(&now); 07015 if (!ast_strlen_zero(id)) 07016 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id); 07017 07018 queue_iter = ao2_iterator_init(queues, 0); 07019 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) { 07020 ao2_lock(q); 07021 07022 /* List queue properties */ 07023 if (ast_strlen_zero(queuefilter) || !strcmp(q->name, queuefilter)) { 07024 sl = ((q->callscompleted > 0) ? 100 * ((float)q->callscompletedinsl / (float)q->callscompleted) : 0); 07025 astman_append(s, "Event: QueueParams\r\n" 07026 "Queue: %s\r\n" 07027 "Max: %d\r\n" 07028 "Strategy: %s\r\n" 07029 "Calls: %d\r\n" 07030 "Holdtime: %d\r\n" 07031 "TalkTime: %d\r\n" 07032 "Completed: %d\r\n" 07033 "Abandoned: %d\r\n" 07034 "ServiceLevel: %d\r\n" 07035 "ServicelevelPerf: %2.1f\r\n" 07036 "Weight: %d\r\n" 07037 "%s" 07038 "\r\n", 07039 q->name, q->maxlen, int2strat(q->strategy), q->count, q->holdtime, q->talktime, q->callscompleted, 07040 q->callsabandoned, q->servicelevel, sl, q->weight, idText); 07041 /* List Queue Members */ 07042 mem_iter = ao2_iterator_init(q->members, 0); 07043 while ((mem = ao2_iterator_next(&mem_iter))) { 07044 if (ast_strlen_zero(memberfilter) || !strcmp(mem->interface, memberfilter) || !strcmp(mem->membername, memberfilter)) { 07045 astman_append(s, "Event: QueueMember\r\n" 07046 "Queue: %s\r\n" 07047 "Name: %s\r\n" 07048 "Location: %s\r\n" 07049 "Membership: %s\r\n" 07050 "Penalty: %d\r\n" 07051 "CallsTaken: %d\r\n" 07052 "LastCall: %d\r\n" 07053 "Status: %d\r\n" 07054 "Paused: %d\r\n" 07055 "%s" 07056 "\r\n", 07057 q->name, mem->membername, mem->interface, mem->dynamic ? "dynamic" : "static", 07058 mem->penalty, mem->calls, (int)mem->lastcall, mem->status, mem->paused, idText); 07059 } 07060 ao2_ref(mem, -1); 07061 } 07062 ao2_iterator_destroy(&mem_iter); 07063 /* List Queue Entries */ 07064 pos = 1; 07065 for (qe = q->head; qe; qe = qe->next) { 07066 astman_append(s, "Event: QueueEntry\r\n" 07067 "Queue: %s\r\n" 07068 "Position: %d\r\n" 07069 "Channel: %s\r\n" 07070 "Uniqueid: %s\r\n" 07071 "CallerIDNum: %s\r\n" 07072 "CallerIDName: %s\r\n" 07073 "Wait: %ld\r\n" 07074 "%s" 07075 "\r\n", 07076 q->name, pos++, qe->chan->name, qe->chan->uniqueid, 07077 S_COR(qe->chan->caller.id.number.valid, qe->chan->caller.id.number.str, "unknown"), 07078 S_COR(qe->chan->caller.id.name.valid, qe->chan->caller.id.name.str, "unknown"), 07079 (long) (now - qe->start), idText); 07080 } 07081 } 07082 ao2_unlock(q); 07083 queue_t_unref(q, "Done with iterator"); 07084 } 07085 ao2_iterator_destroy(&queue_iter); 07086 07087 astman_append(s, 07088 "Event: QueueStatusComplete\r\n" 07089 "%s" 07090 "\r\n",idText); 07091 07092 return RESULT_SUCCESS; 07093 }
| static int manager_queues_summary | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Summary of queue info via the AMI.
Definition at line 6923 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_t_iterator_next, ao2_unlock, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_UNAVAILABLE, AST_DEVICE_UNKNOWN, ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_ack(), call_queue::head, call_queue::holdtime, call_queue::members, call_queue::name, queue_ent::next, member::paused, queue_t_unref, queues, RESULT_SUCCESS, queue_ent::start, member::status, and call_queue::talktime.
Referenced by load_module().
06924 { 06925 time_t now; 06926 int qmemcount = 0; 06927 int qmemavail = 0; 06928 int qchancount = 0; 06929 int qlongestholdtime = 0; 06930 const char *id = astman_get_header(m, "ActionID"); 06931 const char *queuefilter = astman_get_header(m, "Queue"); 06932 char idText[256] = ""; 06933 struct call_queue *q; 06934 struct queue_ent *qe; 06935 struct member *mem; 06936 struct ao2_iterator queue_iter; 06937 struct ao2_iterator mem_iter; 06938 06939 astman_send_ack(s, m, "Queue summary will follow"); 06940 time(&now); 06941 if (!ast_strlen_zero(id)) 06942 snprintf(idText, 256, "ActionID: %s\r\n", id); 06943 queue_iter = ao2_iterator_init(queues, 0); 06944 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) { 06945 ao2_lock(q); 06946 06947 /* List queue properties */ 06948 if (ast_strlen_zero(queuefilter) || !strcmp(q->name, queuefilter)) { 06949 /* Reset the necessary local variables if no queuefilter is set*/ 06950 qmemcount = 0; 06951 qmemavail = 0; 06952 qchancount = 0; 06953 qlongestholdtime = 0; 06954 06955 /* List Queue Members */ 06956 mem_iter = ao2_iterator_init(q->members, 0); 06957 while ((mem = ao2_iterator_next(&mem_iter))) { 06958 if ((mem->status != AST_DEVICE_UNAVAILABLE) && (mem->status != AST_DEVICE_INVALID)) { 06959 ++qmemcount; 06960 if (((mem->status == AST_DEVICE_NOT_INUSE) || (mem->status == AST_DEVICE_UNKNOWN)) && !(mem->paused)) { 06961 ++qmemavail; 06962 } 06963 } 06964 ao2_ref(mem, -1); 06965 } 06966 ao2_iterator_destroy(&mem_iter); 06967 for (qe = q->head; qe; qe = qe->next) { 06968 if ((now - qe->start) > qlongestholdtime) { 06969 qlongestholdtime = now - qe->start; 06970 } 06971 ++qchancount; 06972 } 06973 astman_append(s, "Event: QueueSummary\r\n" 06974 "Queue: %s\r\n" 06975 "LoggedIn: %d\r\n" 06976 "Available: %d\r\n" 06977 "Callers: %d\r\n" 06978 "HoldTime: %d\r\n" 06979 "TalkTime: %d\r\n" 06980 "LongestHoldTime: %d\r\n" 06981 "%s" 06982 "\r\n", 06983 q->name, qmemcount, qmemavail, qchancount, q->holdtime, q->talktime, qlongestholdtime, idText); 06984 } 06985 ao2_unlock(q); 06986 queue_t_unref(q, "Done with iterator"); 06987 } 06988 ao2_iterator_destroy(&queue_iter); 06989 astman_append(s, 06990 "Event: QueueSummaryComplete\r\n" 06991 "%s" 06992 "\r\n", idText); 06993 06994 return RESULT_SUCCESS; 06995 }
| static int manager_remove_queue_member | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 7146 of file app_queue.c.
References ast_queue_log(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), remove_from_queue(), RES_EXISTS, RES_NOSUCHQUEUE, RES_NOT_DYNAMIC, RES_OKAY, and RES_OUTOFMEMORY.
Referenced by load_module().
07147 { 07148 const char *queuename, *interface; 07149 07150 queuename = astman_get_header(m, "Queue"); 07151 interface = astman_get_header(m, "Interface"); 07152 07153 if (ast_strlen_zero(queuename) || ast_strlen_zero(interface)) { 07154 astman_send_error(s, m, "Need 'Queue' and 'Interface' parameters."); 07155 return 0; 07156 } 07157 07158 switch (remove_from_queue(queuename, interface)) { 07159 case RES_OKAY: 07160 ast_queue_log(queuename, "MANAGER", interface, "REMOVEMEMBER", "%s", ""); 07161 astman_send_ack(s, m, "Removed interface from queue"); 07162 break; 07163 case RES_EXISTS: 07164 astman_send_error(s, m, "Unable to remove interface: Not there"); 07165 break; 07166 case RES_NOSUCHQUEUE: 07167 astman_send_error(s, m, "Unable to remove interface from queue: No such queue"); 07168 break; 07169 case RES_OUTOFMEMORY: 07170 astman_send_error(s, m, "Out of memory"); 07171 break; 07172 case RES_NOT_DYNAMIC: 07173 astman_send_error(s, m, "Member not dynamic"); 07174 break; 07175 } 07176 07177 return 0; 07178 }
| static int mark_dead_and_unfound | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 6559 of file app_queue.c.
References ast_strlen_zero(), call_queue::dead, call_queue::found, call_queue::name, and call_queue::realtime.
Referenced by reload_queues().
06560 { 06561 struct call_queue *q = obj; 06562 char *queuename = arg; 06563 if (!q->realtime && (ast_strlen_zero(queuename) || !strcasecmp(queuename, q->name))) { 06564 q->dead = 1; 06565 q->found = 0; 06566 } 06567 return 0; 06568 }
| static int mark_member_dead | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 6423 of file app_queue.c.
References member::delme, and member::dynamic.
Referenced by reload_single_queue().
06424 { 06425 struct member *member = obj; 06426 if (!member->dynamic) { 06427 member->delme = 1; 06428 } 06429 return 0; 06430 }
| static int member_cmp_fn | ( | void * | obj1, | |
| void * | obj2, | |||
| int | flags | |||
| ) | [static] |
Definition at line 1486 of file app_queue.c.
References CMP_MATCH, CMP_STOP, and member::interface.
Referenced by init_queue().
01487 { 01488 struct member *mem1 = obj1, *mem2 = obj2; 01489 return strcasecmp(mem1->interface, mem2->interface) ? 0 : CMP_MATCH | CMP_STOP; 01490 }
| static int member_hash_fn | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 1474 of file app_queue.c.
References compress_char(), and member::interface.
Referenced by init_queue().
01475 { 01476 const struct member *mem = obj; 01477 const char *chname = strchr(mem->interface, '/'); 01478 int ret = 0, i; 01479 if (!chname) 01480 chname = mem->interface; 01481 for (i = 0; i < 5 && chname[i]; i++) 01482 ret += compress_char(chname[i]) << (i * 6); 01483 return ret; 01484 }
| static int num_available_members | ( | struct call_queue * | q | ) | [static] |
Get the number of members available to accept a call.
| [in] | q | The queue for which we are couting the number of available members |
Definition at line 2694 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, AST_DEVICE_INUSE, AST_DEVICE_NOT_INUSE, AST_DEVICE_UNKNOWN, call_queue::autofill, call_queue::members, member::paused, QUEUE_STRATEGY_RINGALL, call_queue::ringinuse, member::status, and call_queue::strategy.
Referenced by compare_weight(), and is_our_turn().
02695 { 02696 struct member *mem; 02697 int avl = 0; 02698 struct ao2_iterator mem_iter; 02699 02700 mem_iter = ao2_iterator_init(q->members, 0); 02701 while ((mem = ao2_iterator_next(&mem_iter))) { 02702 switch (mem->status) { 02703 case AST_DEVICE_INUSE: 02704 if (!q->ringinuse) 02705 break; 02706 /* else fall through */ 02707 case AST_DEVICE_NOT_INUSE: 02708 case AST_DEVICE_UNKNOWN: 02709 if (!mem->paused) { 02710 avl++; 02711 } 02712 break; 02713 } 02714 ao2_ref(mem, -1); 02715 02716 /* If autofill is not enabled or if the queue's strategy is ringall, then 02717 * we really don't care about the number of available members so much as we 02718 * do that there is at least one available. 02719 * 02720 * In fact, we purposely will return from this function stating that only 02721 * one member is available if either of those conditions hold. That way, 02722 * functions which determine what action to take based on the number of available 02723 * members will operate properly. The reasoning is that even if multiple 02724 * members are available, only the head caller can actually be serviced. 02725 */ 02726 if ((!q->autofill || q->strategy == QUEUE_STRATEGY_RINGALL) && avl) { 02727 break; 02728 } 02729 } 02730 ao2_iterator_destroy(&mem_iter); 02731 02732 return avl; 02733 }
| static void parse_empty_options | ( | const char * | value, | |
| enum empty_conditions * | empty, | |||
| int | joinempty | |||
| ) | [static] |
Definition at line 1666 of file app_queue.c.
References ast_false(), ast_log(), ast_strdupa, ast_true(), LOG_WARNING, QUEUE_EMPTY_INUSE, QUEUE_EMPTY_INVALID, QUEUE_EMPTY_PAUSED, QUEUE_EMPTY_PENALTY, QUEUE_EMPTY_RINGING, QUEUE_EMPTY_UNAVAILABLE, QUEUE_EMPTY_UNKNOWN, QUEUE_EMPTY_WRAPUP, and strsep().
Referenced by queue_set_param().
01667 { 01668 char *value_copy = ast_strdupa(value); 01669 char *option = NULL; 01670 while ((option = strsep(&value_copy, ","))) { 01671 if (!strcasecmp(option, "paused")) { 01672 *empty |= QUEUE_EMPTY_PAUSED; 01673 } else if (!strcasecmp(option, "penalty")) { 01674 *empty |= QUEUE_EMPTY_PENALTY; 01675 } else if (!strcasecmp(option, "inuse")) { 01676 *empty |= QUEUE_EMPTY_INUSE; 01677 } else if (!strcasecmp(option, "ringing")) { 01678 *empty |= QUEUE_EMPTY_RINGING; 01679 } else if (!strcasecmp(option, "invalid")) { 01680 *empty |= QUEUE_EMPTY_INVALID; 01681 } else if (!strcasecmp(option, "wrapup")) { 01682 *empty |= QUEUE_EMPTY_WRAPUP; 01683 } else if (!strcasecmp(option, "unavailable")) { 01684 *empty |= QUEUE_EMPTY_UNAVAILABLE; 01685 } else if (!strcasecmp(option, "unknown")) { 01686 *empty |= QUEUE_EMPTY_UNKNOWN; 01687 } else if (!strcasecmp(option, "loose")) { 01688 *empty = (QUEUE_EMPTY_PENALTY | QUEUE_EMPTY_INVALID); 01689 } else if (!strcasecmp(option, "strict")) { 01690 *empty = (QUEUE_EMPTY_PENALTY | QUEUE_EMPTY_INVALID | QUEUE_EMPTY_PAUSED | QUEUE_EMPTY_UNAVAILABLE); 01691 } else if ((ast_false(option) && joinempty) || (ast_true(option) && !joinempty)) { 01692 *empty = (QUEUE_EMPTY_PENALTY | QUEUE_EMPTY_INVALID | QUEUE_EMPTY_PAUSED); 01693 } else if ((ast_false(option) && !joinempty) || (ast_true(option) && joinempty)) { 01694 *empty = 0; 01695 } else { 01696 ast_log(LOG_WARNING, "Unknown option %s for '%s'\n", option, joinempty ? "joinempty" : "leavewhenempty"); 01697 } 01698 } 01699 }
| static int play_file | ( | struct ast_channel * | chan, | |
| const char * | filename | |||
| ) | [static] |
Definition at line 2364 of file app_queue.c.
References AST_DIGIT_ANY, ast_fileexists(), ast_stopstream(), ast_streamfile(), ast_strlen_zero(), ast_waitstream(), and ast_channel::language.
Referenced by say_periodic_announcement(), say_position(), and try_calling().
02365 { 02366 int res; 02367 02368 if (ast_strlen_zero(filename)) { 02369 return 0; 02370 } 02371 02372 if (!ast_fileexists(filename, NULL, chan->language)) { 02373 return 0; 02374 } 02375 02376 ast_stopstream(chan); 02377 02378 res = ast_streamfile(chan, filename, chan->language); 02379 if (!res) 02380 res = ast_waitstream(chan, AST_DIGIT_ANY); 02381 02382 ast_stopstream(chan); 02383 02384 return res; 02385 }
| static int pqm_exec | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) | [static] |
PauseQueueMember application.
Definition at line 5342 of file app_queue.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), LOG_WARNING, parse(), pbx_builtin_setvar_helper(), and set_member_paused().
Referenced by load_module().
05343 { 05344 char *parse; 05345 AST_DECLARE_APP_ARGS(args, 05346 AST_APP_ARG(queuename); 05347 AST_APP_ARG(interface); 05348 AST_APP_ARG(options); 05349 AST_APP_ARG(reason); 05350 ); 05351 05352 if (ast_strlen_zero(data)) { 05353 ast_log(LOG_WARNING, "PauseQueueMember requires an argument ([queuename],interface[,options][,reason])\n"); 05354 return -1; 05355 } 05356 05357 parse = ast_strdupa(data); 05358 05359 AST_STANDARD_APP_ARGS(args, parse); 05360 05361 if (ast_strlen_zero(args.interface)) { 05362 ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename],interface[,options[,reason]])\n"); 05363 return -1; 05364 } 05365 05366 if (set_member_paused(args.queuename, args.interface, args.reason, 1)) { 05367 ast_log(LOG_WARNING, "Attempt to pause interface %s, not found\n", args.interface); 05368 pbx_builtin_setvar_helper(chan, "PQMSTATUS", "NOTFOUND"); 05369 return 0; 05370 } 05371 05372 pbx_builtin_setvar_helper(chan, "PQMSTATUS", "PAUSED"); 05373 05374 return 0; 05375 }
| static int ql_exec | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) | [static] |
QueueLog application.
Definition at line 5534 of file app_queue.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), ast_queue_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), LOG_WARNING, and parse().
Referenced by load_module().
05535 { 05536 char *parse; 05537 05538 AST_DECLARE_APP_ARGS(args, 05539 AST_APP_ARG(queuename); 05540 AST_APP_ARG(uniqueid); 05541 AST_APP_ARG(membername); 05542 AST_APP_ARG(event); 05543 AST_APP_ARG(params); 05544 ); 05545 05546 if (ast_strlen_zero(data)) { 05547 ast_log(LOG_WARNING, "QueueLog requires arguments (queuename,uniqueid,membername,event[,additionalinfo]\n"); 05548 return -1; 05549 } 05550 05551 parse = ast_strdupa(data); 05552 05553 AST_STANDARD_APP_ARGS(args, parse); 05554 05555 if (ast_strlen_zero(args.queuename) || ast_strlen_zero(args.uniqueid) 05556 || ast_strlen_zero(args.membername) || ast_strlen_zero(args.event)) { 05557 ast_log(LOG_WARNING, "QueueLog requires arguments (queuename,uniqueid,membername,event[,additionalinfo])\n"); 05558 return -1; 05559 } 05560 05561 ast_queue_log(args.queuename, args.uniqueid, args.membername, args.event, 05562 "%s", args.params ? args.params : ""); 05563 05564 return 0; 05565 }
| static int queue_cmp_cb | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 1100 of file app_queue.c.
References CMP_MATCH, CMP_STOP, and call_queue::name.
Referenced by load_module().
01101 { 01102 struct call_queue *q = obj, *q2 = arg; 01103 return !strcasecmp(q->name, q2->name) ? CMP_MATCH | CMP_STOP : 0; 01104 }
| static int queue_exec | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) | [static] |
The starting point for all queue calls.
The process involved here is to 1. Parse the options specified in the call to Queue() 2. Join the queue 3. Wait in a loop until it is our turn to try calling a queue member 4. Attempt to call a queue member 5. If 4. did not result in a bridged call, then check for between call options such as periodic announcements etc. 6. Try 4 again unless some condition (such as an expiration time) causes us to exit the queue.
Definition at line 5609 of file app_queue.c.
References call_queue::announcefrequency, args, AST_APP_ARG, ast_channel_lock, ast_channel_unlock, AST_CONTROL_RINGING, ast_debug, AST_DECLARE_APP_ARGS, ast_indicate(), AST_LIST_FIRST, ast_log(), ast_moh_start(), ast_moh_stop(), ast_queue_log(), AST_STANDARD_APP_ARGS, ast_stopstream(), ast_strdupa, ast_strlen_zero(), ast_verb, ast_channel::caller, queue_ent::chan, copy_rules(), queue_ent::digits, queue_ent::expire, get_member_status(), queue_ent::handled, ast_party_caller::id, is_our_turn(), join_queue(), queue_ent::last_periodic_announce_sound, queue_ent::last_periodic_announce_time, queue_ent::last_pos, queue_ent::last_pos_said, leave_queue(), call_queue::leavewhenempty, LOG_WARNING, queue_ent::max_penalty, call_queue::membercount, queue_ent::min_penalty, queue_ent::moh, call_queue::name, ast_channel::name, ast_party_id::number, queue_ent::opos, queue_ent::parent, parse(), pbx_builtin_getvar_helper(), call_queue::periodicannouncefrequency, queue_ent::pos, queue_ent::pr, queue_ent::prio, queue_ent::qe_rules, QUEUE_CONTINUE, QUEUE_LEAVEEMPTY, QUEUE_TIMEOUT, QUEUE_UNKNOWN, queue_unref(), record_abandoned(), queue_ent::ring_when_ringing, S_COR, S_OR, say_periodic_announcement(), say_position(), set_queue_result(), set_queue_variables(), queue_ent::start, status, stop, ast_party_number::str, penalty_rule::time, try_calling(), ast_channel::uniqueid, update_qe_rule(), update_realtime_members(), url, ast_party_number::valid, queue_ent::valid_digits, wait_a_bit(), and wait_our_turn().
Referenced by load_module().
05610 { 05611 int res=-1; 05612 int ringing=0; 05613 const char *user_priority; 05614 const char *max_penalty_str; 05615 const char *min_penalty_str; 05616 int prio; 05617 int qcontinue = 0; 05618 int max_penalty, min_penalty; 05619 enum queue_result reason = QUEUE_UNKNOWN; 05620 /* whether to exit Queue application after the timeout hits */ 05621 int tries = 0; 05622 int noption = 0; 05623 char *parse; 05624 int makeannouncement = 0; 05625 int position = 0; 05626 AST_DECLARE_APP_ARGS(args, 05627 AST_APP_ARG(queuename); 05628 AST_APP_ARG(options); 05629 AST_APP_ARG(url); 05630 AST_APP_ARG(announceoverride); 05631 AST_APP_ARG(queuetimeoutstr); 05632 AST_APP_ARG(agi); 05633 AST_APP_ARG(macro); 05634 AST_APP_ARG(gosub); 05635 AST_APP_ARG(rule); 05636 AST_APP_ARG(position); 05637 ); 05638 /* Our queue entry */ 05639 struct queue_ent qe = { 0 }; 05640 05641 if (ast_strlen_zero(data)) { 05642 ast_log(LOG_WARNING, "Queue requires an argument: queuename[,options[,URL[,announceoverride[,timeout[,agi[,macro[,gosub[,rule[,position]]]]]]]]]\n"); 05643 return -1; 05644 } 05645 05646 parse = ast_strdupa(data); 05647 AST_STANDARD_APP_ARGS(args, parse); 05648 05649 /* Setup our queue entry */ 05650 qe.start = time(NULL); 05651 05652 /* set the expire time based on the supplied timeout; */ 05653 if (!ast_strlen_zero(args.queuetimeoutstr)) 05654 qe.expire = qe.start + atoi(args.queuetimeoutstr); 05655 else 05656 qe.expire = 0; 05657 05658 /* Get the priority from the variable ${QUEUE_PRIO} */ 05659 ast_channel_lock(chan); 05660 user_priority = pbx_builtin_getvar_helper(chan, "QUEUE_PRIO"); 05661 if (user_priority) { 05662 if (sscanf(user_priority, "%30d", &prio) == 1) { 05663 ast_debug(1, "%s: Got priority %d from ${QUEUE_PRIO}.\n", chan->name, prio); 05664 } else { 05665 ast_log(LOG_WARNING, "${QUEUE_PRIO}: Invalid value (%s), channel %s.\n", 05666 user_priority, chan->name); 05667 prio = 0; 05668 } 05669 } else { 05670 ast_debug(3, "NO QUEUE_PRIO variable found. Using default.\n"); 05671 prio = 0; 05672 } 05673 05674 /* Get the maximum penalty from the variable ${QUEUE_MAX_PENALTY} */ 05675 05676 if ((max_penalty_str = pbx_builtin_getvar_helper(chan, "QUEUE_MAX_PENALTY"))) { 05677 if (sscanf(max_penalty_str, "%30d", &max_penalty) == 1) { 05678 ast_debug(1, "%s: Got max penalty %d from ${QUEUE_MAX_PENALTY}.\n", chan->name, max_penalty); 05679 } else { 05680 ast_log(LOG_WARNING, "${QUEUE_MAX_PENALTY}: Invalid value (%s), channel %s.\n", 05681 max_penalty_str, chan->name); 05682 max_penalty = 0; 05683 } 05684 } else { 05685 max_penalty = 0; 05686 } 05687 05688 if ((min_penalty_str = pbx_builtin_getvar_helper(chan, "QUEUE_MIN_PENALTY"))) { 05689 if (sscanf(min_penalty_str, "%30d", &min_penalty) == 1) { 05690 ast_debug(1, "%s: Got min penalty %d from ${QUEUE_MIN_PENALTY}.\n", chan->name, min_penalty); 05691 } else { 05692 ast_log(LOG_WARNING, "${QUEUE_MIN_PENALTY}: Invalid value (%s), channel %s.\n", 05693 min_penalty_str, chan->name); 05694 min_penalty = 0; 05695 } 05696 } else { 05697 min_penalty = 0; 05698 } 05699 ast_channel_unlock(chan); 05700 05701 if (args.options && (strchr(args.options, 'r'))) 05702 ringing = 1; 05703 05704 if (ringing != 1 && args.options && (strchr(args.options, 'R'))) { 05705 qe.ring_when_ringing = 1; 05706 } 05707 05708 if (args.options && (strchr(args.options, 'c'))) 05709 qcontinue = 1; 05710 05711 if (args.position) { 05712 position = atoi(args.position); 05713 if (position < 0) { 05714 ast_log(LOG_WARNING, "Invalid position '%s' given for call to queue '%s'. Assuming no preference for position\n", args.position, args.queuename); 05715 position = 0; 05716 } 05717 } 05718 05719 ast_debug(1, "queue: %s, options: %s, url: %s, announce: %s, expires: %ld, priority: %d\n", 05720 args.queuename, args.options, args.url, args.announceoverride, (long)qe.expire, prio); 05721 05722 qe.chan = chan; 05723 qe.prio = prio; 05724 qe.max_penalty = max_penalty; 05725 qe.min_penalty = min_penalty; 05726 qe.last_pos_said = 0; 05727 qe.last_pos = 0; 05728 qe.last_periodic_announce_time = time(NULL); 05729 qe.last_periodic_announce_sound = 0; 05730 qe.valid_digits = 0; 05731 if (join_queue(args.queuename, &qe, &reason, position)) { 05732 ast_log(LOG_WARNING, "Unable to join queue '%s'\n", args.queuename); 05733 set_queue_result(chan, reason); 05734 return 0; 05735 } 05736 ast_queue_log(args.queuename, chan->uniqueid, "NONE", "ENTERQUEUE", "%s|%s|%d", 05737 S_OR(args.url, ""), 05738 S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, ""), 05739 qe.opos); 05740 copy_rules(&qe, args.rule); 05741 qe.pr = AST_LIST_FIRST(&qe.qe_rules); 05742 check_turns: 05743 if (ringing) { 05744 ast_indicate(chan, AST_CONTROL_RINGING); 05745 } else { 05746 ast_moh_start(chan, qe.moh, NULL); 05747 } 05748 05749 /* This is the wait loop for callers 2 through maxlen */ 05750 res = wait_our_turn(&qe, ringing, &reason); 05751 if (res) { 05752 goto stop; 05753 } 05754 05755 makeannouncement = 0; 05756 05757 for (;;) { 05758 /* This is the wait loop for the head caller*/ 05759 /* To exit, they may get their call answered; */ 05760 /* they may dial a digit from the queue context; */ 05761 /* or, they may timeout. */ 05762 05763 /* Leave if we have exceeded our queuetimeout */ 05764 if (qe.expire && (time(NULL) >= qe.expire)) { 05765 record_abandoned(&qe); 05766 reason = QUEUE_TIMEOUT; 05767 res = 0; 05768 ast_queue_log(args.queuename, chan->uniqueid,"NONE", "EXITWITHTIMEOUT", "%d|%d|%ld", 05769 qe.pos, qe.opos, (long) time(NULL) - qe.start); 05770 break; 05771 } 05772 05773 if (makeannouncement) { 05774 /* Make a position announcement, if enabled */ 05775 if (qe.parent->announcefrequency) 05776 if ((res = say_position(&qe,ringing))) 05777 goto stop; 05778 } 05779 makeannouncement = 1; 05780 05781 /* Make a periodic announcement, if enabled */ 05782 if (qe.parent->periodicannouncefrequency) 05783 if ((res = say_periodic_announcement(&qe,ringing))) 05784 goto stop; 05785 05786 /* Leave if we have exceeded our queuetimeout */ 05787 if (qe.expire && (time(NULL) >= qe.expire)) { 05788 record_abandoned(&qe); 05789 reason = QUEUE_TIMEOUT; 05790 res = 0; 05791 ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHTIMEOUT", "%d", qe.pos); 05792 break; 05793 } 05794 05795 /* see if we need to move to the next penalty level for this queue */ 05796 while (qe.pr && ((time(NULL) - qe.start) > qe.pr->time)) { 05797 update_qe_rule(&qe); 05798 } 05799 05800 /* Try calling all queue members for 'timeout' seconds */ 05801 res = try_calling(&qe, args.options, args.announceoverride, args.url, &tries, &noption, args.agi, args.macro, args.gosub, ringing); 05802 if (res) { 05803 goto stop; 05804 } 05805 05806 if (qe.parent->leavewhenempty) { 05807 int status = 0; 05808 if ((status = get_member_status(qe.parent, qe.max_penalty, qe.min_penalty, qe.parent->leavewhenempty))) { 05809 record_abandoned(&qe); 05810 reason = QUEUE_LEAVEEMPTY; 05811 ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITEMPTY", "%d|%d|%ld", qe.pos, qe.opos, (long)(time(NULL) - qe.start)); 05812 res = 0; 05813 break; 05814 } 05815 } 05816 05817 /* exit after 'timeout' cycle if 'n' option enabled */ 05818 if (noption && tries >= qe.parent->membercount) { 05819 ast_verb(3, "Exiting on time-out cycle\n"); 05820 ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHTIMEOUT", "%d", qe.pos); 05821 record_abandoned(&qe); 05822 reason = QUEUE_TIMEOUT; 05823 res = 0; 05824 break; 05825 } 05826 05827 05828 /* Leave if we have exceeded our queuetimeout */ 05829 if (qe.expire && (time(NULL) >= qe.expire)) { 05830 record_abandoned(&qe); 05831 reason = QUEUE_TIMEOUT; 05832 res = 0; 05833 ast_queue_log(qe.parent->name, qe.chan->uniqueid,"NONE", "EXITWITHTIMEOUT", "%d|%d|%ld", qe.pos, qe.opos, (long) time(NULL) - qe.start); 05834 break; 05835 } 05836 05837 /* If using dynamic realtime members, we should regenerate the member list for this queue */ 05838 update_realtime_members(qe.parent); 05839 /* OK, we didn't get anybody; wait for 'retry' seconds; may get a digit to exit with */ 05840 res = wait_a_bit(&qe); 05841 if (res) 05842 goto stop; 05843 05844 /* Since this is a priority queue and 05845 * it is not sure that we are still at the head 05846 * of the queue, go and check for our turn again. 05847 */ 05848 if (!is_our_turn(&qe)) { 05849 ast_debug(1, "Darn priorities, going back in queue (%s)!\n", qe.chan->name); 05850 goto check_turns; 05851 } 05852 } 05853 05854 stop: 05855 if (res) { 05856 if (res < 0) { 05857 if (!qe.handled) { 05858 record_abandoned(&qe); 05859 ast_queue_log(args.queuename, chan->uniqueid, "NONE", "ABANDON", 05860 "%d|%d|%ld", qe.pos, qe.opos, 05861 (long) time(NULL) - qe.start); 05862 res = -1; 05863 } else if (qcontinue) { 05864 reason = QUEUE_CONTINUE; 05865 res = 0; 05866 } 05867 } else if (qe.valid_digits) { 05868 ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", 05869 "%s|%d", qe.digits, qe.pos); 05870 } 05871 } 05872 05873 /* Don't allow return code > 0 */ 05874 if (res >= 0) { 05875 res = 0; 05876 if (ringing) { 05877 ast_indicate(chan, -1); 05878 } else { 05879 ast_moh_stop(chan); 05880 } 05881 ast_stopstream(chan); 05882 } 05883 05884 set_queue_variables(qe.parent, qe.chan); 05885 05886 leave_queue(&qe); 05887 if (reason != QUEUE_UNKNOWN) 05888 set_queue_result(chan, reason); 05889 05890 if (qe.parent) { 05891 /* every queue_ent is given a reference to it's parent call_queue when it joins the queue. 05892 * This ref must be taken away right before the queue_ent is destroyed. In this case 05893 * the queue_ent is about to be returned on the stack */ 05894 qe.parent = queue_unref(qe.parent); 05895 } 05896 05897 return res; 05898 }
| static int queue_function_exists | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Check if a given queue exists.
Definition at line 5952 of file app_queue.c.
References ast_log(), ast_strlen_zero(), load_realtime_queue(), LOG_ERROR, and queue_t_unref.
05953 { 05954 struct call_queue *q; 05955 05956 buf[0] = '\0'; 05957 05958 if (ast_strlen_zero(data)) { 05959 ast_log(LOG_ERROR, "%s requires an argument: queuename\n", cmd); 05960 return -1; 05961 } 05962 q = load_realtime_queue(data); 05963 snprintf(buf, len, "%d", q != NULL? 1 : 0); 05964 if (q) { 05965 queue_t_unref(q, "Done with temporary reference in QUEUE_EXISTS()"); 05966 } 05967 05968 return 0; 05969 }
| static int queue_function_memberpenalty_read | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Dialplan function QUEUE_MEMBER_PENALTY() Gets the members penalty.
Definition at line 6170 of file app_queue.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), get_member_penalty(), and LOG_ERROR.
06171 { 06172 int penalty; 06173 AST_DECLARE_APP_ARGS(args, 06174 AST_APP_ARG(queuename); 06175 AST_APP_ARG(interface); 06176 ); 06177 /* Make sure the returned value on error is NULL. */ 06178 buf[0] = '\0'; 06179 06180 if (ast_strlen_zero(data)) { 06181 ast_log(LOG_ERROR, "Missing argument. QUEUE_MEMBER_PENALTY(<queuename>,<interface>)\n"); 06182 return -1; 06183 } 06184 06185 AST_STANDARD_APP_ARGS(args, data); 06186 06187 if (args.argc < 2) { 06188 ast_log(LOG_ERROR, "Missing argument. QUEUE_MEMBER_PENALTY(<queuename>,<interface>)\n"); 06189 return -1; 06190 } 06191 06192 penalty = get_member_penalty (args.queuename, args.interface); 06193 06194 if (penalty >= 0) /* remember that buf is already '\0' */ 06195 snprintf (buf, len, "%d", penalty); 06196 06197 return 0; 06198 }
| static int queue_function_memberpenalty_write | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| const char * | value | |||
| ) | [static] |
Dialplan function QUEUE_MEMBER_PENALTY() Sets the members penalty.
Definition at line 6201 of file app_queue.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), LOG_ERROR, and set_member_penalty().
06202 { 06203 int penalty; 06204 AST_DECLARE_APP_ARGS(args, 06205 AST_APP_ARG(queuename); 06206 AST_APP_ARG(interface); 06207 ); 06208 06209 if (ast_strlen_zero(data)) { 06210 ast_log(LOG_ERROR, "Missing argument. QUEUE_MEMBER_PENALTY(<queuename>,<interface>)\n"); 06211 return -1; 06212 } 06213 06214 AST_STANDARD_APP_ARGS(args, data); 06215 06216 if (args.argc < 2) { 06217 ast_log(LOG_ERROR, "Missing argument. QUEUE_MEMBER_PENALTY(<queuename>,<interface>)\n"); 06218 return -1; 06219 } 06220 06221 penalty = atoi(value); 06222 06223 if (ast_strlen_zero(args.interface)) { 06224 ast_log (LOG_ERROR, "<interface> parameter can't be null\n"); 06225 return -1; 06226 } 06227 06228 /* if queuename = NULL then penalty will be set for interface in all the queues. */ 06229 if (set_member_penalty(args.queuename, args.interface, penalty)) { 06230 ast_log(LOG_ERROR, "Invalid interface, queue or penalty\n"); 06231 return -1; 06232 } 06233 06234 return 0; 06235 }
| static int queue_function_qac | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Get number either busy / free / ready or total members of a specific queue.
| number | of members (busy / free / ready / total) | |
| -1 | on error |
Definition at line 5976 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_UNAVAILABLE, ast_log(), ast_strlen_zero(), call_queue::count, member::lastcall, load_realtime_queue(), LOG_ERROR, LOG_WARNING, call_queue::membercount, call_queue::members, member::paused, queue_t_unref, member::status, and call_queue::wrapuptime.
05977 { 05978 int count = 0; 05979 struct member *m; 05980 struct ao2_iterator mem_iter; 05981 struct call_queue *q; 05982 char *option; 05983 05984 if (ast_strlen_zero(data)) { 05985 ast_log(LOG_ERROR, "%s requires an argument: queuename\n", cmd); 05986 return -1; 05987 } 05988 05989 if ((option = strchr(data, ','))) 05990 *option++ = '\0'; 05991 else 05992 option = "logged"; 05993 if ((q = load_realtime_queue(data))) { 05994 ao2_lock(q); 05995 if (!strcasecmp(option, "logged")) { 05996 mem_iter = ao2_iterator_init(q->members, 0); 05997 while ((m = ao2_iterator_next(&mem_iter))) { 05998 /* Count the agents who are logged in and presently answering calls */ 05999 if ((m->status != AST_DEVICE_UNAVAILABLE) && (m->status != AST_DEVICE_INVALID)) { 06000 count++; 06001 } 06002 ao2_ref(m, -1); 06003 } 06004 ao2_iterator_destroy(&mem_iter); 06005 } else if (!strcasecmp(option, "free")) { 06006 mem_iter = ao2_iterator_init(q->members, 0); 06007 while ((m = ao2_iterator_next(&mem_iter))) { 06008 /* Count the agents who are logged in and presently answering calls */ 06009 if ((m->status == AST_DEVICE_NOT_INUSE) && (!m->paused)) { 06010 count++; 06011 } 06012 ao2_ref(m, -1); 06013 } 06014 ao2_iterator_destroy(&mem_iter); 06015 } else if (!strcasecmp(option, "ready")) { 06016 time_t now; 06017 time(&now); 06018 mem_iter = ao2_iterator_init(q->members, 0); 06019 while ((m = ao2_iterator_next(&mem_iter))) { 06020 /* Count the agents who are logged in, not paused and not wrapping up */ 06021 if ((m->status == AST_DEVICE_NOT_INUSE) && (!m->paused) && 06022 !(m->lastcall && q->wrapuptime && ((now - q->wrapuptime) < m->lastcall))) { 06023 count++; 06024 } 06025 ao2_ref(m, -1); 06026 } 06027 ao2_iterator_destroy(&mem_iter); 06028 } else /* must be "count" */ 06029 count = q->membercount; 06030 ao2_unlock(q); 06031 queue_t_unref(q, "Done with temporary reference in QUEUE_MEMBER()"); 06032 } else 06033 ast_log(LOG_WARNING, "queue %s was not found\n", data); 06034 06035 snprintf(buf, len, "%d", count); 06036 06037 return 0; 06038 }
| static int queue_function_qac_dep | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Get the total number of members in a specific queue (Deprecated).
| number | of members | |
| -1 | on error |
Definition at line 6045 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, AST_DEVICE_INVALID, AST_DEVICE_UNAVAILABLE, ast_log(), ast_strlen_zero(), call_queue::count, load_realtime_queue(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, call_queue::members, queue_t_unref, and member::status.
06046 { 06047 int count = 0; 06048 struct member *m; 06049 struct call_queue *q; 06050 struct ao2_iterator mem_iter; 06051 static int depflag = 1; 06052 06053 if (depflag) { 06054 depflag = 0; 06055 ast_log(LOG_NOTICE, "The function QUEUE_MEMBER_COUNT has been deprecated in favor of the QUEUE_MEMBER function and will not be in further releases.\n"); 06056 } 06057 06058 if (ast_strlen_zero(data)) { 06059 ast_log(LOG_ERROR, "%s requires an argument: queuename\n", cmd); 06060 return -1; 06061 } 06062 06063 if ((q = load_realtime_queue(data))) { 06064 ao2_lock(q); 06065 mem_iter = ao2_iterator_init(q->members, 0); 06066 while ((m = ao2_iterator_next(&mem_iter))) { 06067 /* Count the agents who are logged in and presently answering calls */ 06068 if ((m->status != AST_DEVICE_UNAVAILABLE) && (m->status != AST_DEVICE_INVALID)) { 06069 count++; 06070 } 06071 ao2_ref(m, -1); 06072 } 06073 ao2_iterator_destroy(&mem_iter); 06074 ao2_unlock(q); 06075 queue_t_unref(q, "Done with temporary reference in QUEUE_MEMBER_COUNT"); 06076 } else 06077 ast_log(LOG_WARNING, "queue %s was not found\n", data); 06078 06079 snprintf(buf, len, "%d", count); 06080 06081 return 0; 06082 }
| static int queue_function_queuememberlist | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Dialplan function QUEUE_MEMBER_LIST() Get list of members in a specific queue.
Definition at line 6121 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_t_find, ao2_unlock, ast_log(), ast_strlen_zero(), member::interface, LOG_ERROR, LOG_WARNING, call_queue::members, OBJ_POINTER, queue_t_unref, and queues.
06122 { 06123 struct call_queue *q, tmpq = { 06124 .name = data, 06125 }; 06126 struct member *m; 06127 06128 /* Ensure an otherwise empty list doesn't return garbage */ 06129 buf[0] = '\0'; 06130 06131 if (ast_strlen_zero(data)) { 06132 ast_log(LOG_ERROR, "QUEUE_MEMBER_LIST requires an argument: queuename\n"); 06133 return -1; 06134 } 06135 06136 if ((q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Find for QUEUE_MEMBER_LIST()"))) { 06137 int buflen = 0, count = 0; 06138 struct ao2_iterator mem_iter = ao2_iterator_init(q->members, 0); 06139 06140 ao2_lock(q); 06141 while ((m = ao2_iterator_next(&mem_iter))) { 06142 /* strcat() is always faster than printf() */ 06143 if (count++) { 06144 strncat(buf + buflen, ",", len - buflen - 1); 06145 buflen++; 06146 } 06147 strncat(buf + buflen, m->interface, len - buflen - 1); 06148 buflen += strlen(m->interface); 06149 /* Safeguard against overflow (negative length) */ 06150 if (buflen >= len - 2) { 06151 ao2_ref(m, -1); 06152 ast_log(LOG_WARNING, "Truncating list\n"); 06153 break; 06154 } 06155 ao2_ref(m, -1); 06156 } 06157 ao2_iterator_destroy(&mem_iter); 06158 ao2_unlock(q); 06159 queue_t_unref(q, "Done with QUEUE_MEMBER_LIST()"); 06160 } else 06161 ast_log(LOG_WARNING, "queue %s was not found\n", data); 06162 06163 /* We should already be terminated, but let's make sure. */ 06164 buf[len - 1] = '\0'; 06165 06166 return 0; 06167 }
| static int queue_function_queuewaitingcount | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Dialplan function QUEUE_WAITING_COUNT() Get number callers waiting in a specific queue.
Definition at line 6085 of file app_queue.c.
References ao2_lock, ao2_t_find, ao2_unlock, ast_load_realtime(), ast_log(), ast_strlen_zero(), ast_variables_destroy(), call_queue::count, LOG_ERROR, LOG_WARNING, OBJ_POINTER, queue_t_unref, queues, SENTINEL, and var.
06086 { 06087 int count = 0; 06088 struct call_queue *q, tmpq = { 06089 .name = data, 06090 }; 06091 struct ast_variable *var = NULL; 06092 06093 buf[0] = '\0'; 06094 06095 if (ast_strlen_zero(data)) { 06096 ast_log(LOG_ERROR, "QUEUE_WAITING_COUNT requires an argument: queuename\n"); 06097 return -1; 06098 } 06099 06100 if ((q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Find for QUEUE_WAITING_COUNT()"))) { 06101 ao2_lock(q); 06102 count = q->count; 06103 ao2_unlock(q); 06104 queue_t_unref(q, "Done with reference in QUEUE_WAITING_COUNT()"); 06105 } else if ((var = ast_load_realtime("queues", "name", data, SENTINEL))) { 06106 /* if the queue is realtime but was not found in memory, this 06107 * means that the queue had been deleted from memory since it was 06108 * "dead." This means it has a 0 waiting count 06109 */ 06110 count = 0; 06111 ast_variables_destroy(var); 06112 } else 06113 ast_log(LOG_WARNING, "queue %s was not found\n", data); 06114 06115 snprintf(buf, len, "%d", count); 06116 06117 return 0; 06118 }
| static int queue_function_var | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
create interface var with all queue details.
| 0 | on success | |
| -1 | on error |
Definition at line 5905 of file app_queue.c.
References ao2_lock, ao2_t_find, ao2_unlock, ast_log(), ast_strlen_zero(), call_queue::callsabandoned, call_queue::callscompleted, call_queue::callscompletedinsl, call_queue::count, call_queue::holdtime, int2strat(), LOG_ERROR, LOG_WARNING, call_queue::maxlen, OBJ_POINTER, pbx_builtin_setvar_multiple(), queue_t_unref, queues, call_queue::servicelevel, call_queue::setqueuevar, call_queue::strategy, and call_queue::talktime.
05906 { 05907 int res = -1; 05908 struct call_queue *q, tmpq = { 05909 .name = data, 05910 }; 05911 05912 char interfacevar[256] = ""; 05913 float sl = 0; 05914 05915 if (ast_strlen_zero(data)) { 05916 ast_log(LOG_ERROR, "%s requires an argument: queuename\n", cmd); 05917 return -1; 05918 } 05919 05920 if ((q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Find for QUEUE() function"))) { 05921 ao2_lock(q); 05922 if (q->setqueuevar) { 05923 sl = 0; 05924 res = 0; 05925 05926 if (q->callscompleted > 0) { 05927 sl = 100 * ((float) q->callscompletedinsl / (float) q->callscompleted); 05928 } 05929 05930 snprintf(interfacevar, sizeof(interfacevar), 05931 "QUEUEMAX=%d,QUEUESTRATEGY=%s,QUEUECALLS=%d,QUEUEHOLDTIME=%d,QUEUETALKTIME=%d,QUEUECOMPLETED=%d,QUEUEABANDONED=%d,QUEUESRVLEVEL=%d,QUEUESRVLEVELPERF=%2.1f", 05932 q->maxlen, int2strat(q->strategy), q->count, q->holdtime, q->talktime, q->callscompleted, q->callsabandoned, q->servicelevel, sl); 05933 05934 pbx_builtin_setvar_multiple(chan, interfacevar); 05935 } 05936 05937 ao2_unlock(q); 05938 queue_t_unref(q, "Done with QUEUE() function"); 05939 } else { 05940 ast_log(LOG_WARNING, "queue %s was not found\n", data); 05941 } 05942 05943 snprintf(buf, len, "%d", res); 05944 05945 return 0; 05946 }
| static int queue_hash_cb | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 1093 of file app_queue.c.
References ast_str_case_hash(), and call_queue::name.
Referenced by load_module().
01094 { 01095 const struct call_queue *q = obj; 01096 01097 return ast_str_case_hash(q->name); 01098 }
| static struct call_queue* queue_ref | ( | struct call_queue * | q | ) | [static, read] |
Definition at line 1118 of file app_queue.c.
References ao2_ref.
Referenced by insert_entry().
01119 { 01120 ao2_ref(q, 1); 01121 return q; 01122 }
| static void queue_set_global_params | ( | struct ast_config * | cfg | ) | [static] |
Set the global queue parameters as defined in the "general" section of queues.conf
Definition at line 6327 of file app_queue.c.
References ast_true(), and ast_variable_retrieve().
Referenced by reload_queues().
06328 { 06329 const char *general_val = NULL; 06330 queue_persistent_members = 0; 06331 if ((general_val = ast_variable_retrieve(cfg, "general", "persistentmembers"))) 06332 queue_persistent_members = ast_true(general_val); 06333 autofill_default = 0; 06334 if ((general_val = ast_variable_retrieve(cfg, "general", "autofill"))) 06335 autofill_default = ast_true(general_val); 06336 montype_default = 0; 06337 if ((general_val = ast_variable_retrieve(cfg, "general", "monitor-type"))) { 06338 if (!strcasecmp(general_val, "mixmonitor")) 06339 montype_default = 1; 06340 } 06341 update_cdr = 0; 06342 if ((general_val = ast_variable_retrieve(cfg, "general", "updatecdr"))) 06343 update_cdr = ast_true(general_val); 06344 shared_lastcall = 0; 06345 if ((general_val = ast_variable_retrieve(cfg, "general", "shared_lastcall"))) 06346 shared_lastcall = ast_true(general_val); 06347 }
| static void queue_set_param | ( | struct call_queue * | q, | |
| const char * | param, | |||
| const char * | val, | |||
| int | linenum, | |||
| int | failunknown | |||
| ) | [static] |
Configure a queue parameter.
The failunknown flag is set for config files (and static realtime) to show errors for unknown parameters. It is cleared for dynamic realtime to allow extra fields in the tables.
Definition at line 1709 of file app_queue.c.
References queue_ent::announce, call_queue::announcefrequency, call_queue::announceholdtime, ANNOUNCEHOLDTIME_ALWAYS, ANNOUNCEHOLDTIME_ONCE, call_queue::announceposition, ANNOUNCEPOSITION_LIMIT, ANNOUNCEPOSITION_MORE_THAN, ANNOUNCEPOSITION_NO, ANNOUNCEPOSITION_YES, call_queue::announcepositionlimit, ast_copy_string(), ast_debug, ast_log(), ast_str_create(), ast_str_set(), ast_strdupa, ast_string_field_set, ast_true(), call_queue::autofill, call_queue::autopause, autopause2int(), queue_ent::context, DEFAULT_RETRY, DEFAULT_TIMEOUT, call_queue::eventwhencalled, call_queue::joinempty, call_queue::leavewhenempty, LOG_WARNING, call_queue::maskmemberstatus, MAX_PERIODIC_ANNOUNCEMENTS, call_queue::maxlen, call_queue::memberdelay, call_queue::minannouncefrequency, queue_ent::moh, call_queue::monfmt, call_queue::montype, call_queue::name, call_queue::numperiodicannounce, parse_empty_options(), call_queue::penaltymemberslimit, call_queue::periodicannouncefrequency, QUEUE_EVENT_VARIABLES, QUEUE_STRATEGY_LINEAR, QUEUE_STRATEGY_RINGALL, call_queue::randomperiodicannounce, call_queue::relativeperiodicannounce, call_queue::reportholdtime, call_queue::retry, call_queue::ringinuse, call_queue::roundingseconds, call_queue::servicelevel, call_queue::setinterfacevar, call_queue::setqueueentryvar, call_queue::setqueuevar, call_queue::sound_periodicannounce, strat2int(), call_queue::strategy, strsep(), call_queue::timeout, TIMEOUT_PRIORITY_APP, TIMEOUT_PRIORITY_CONF, call_queue::timeoutpriority, call_queue::timeoutrestart, call_queue::weight, and call_queue::wrapuptime.
Referenced by find_queue_by_name_rt(), and reload_single_queue().
01710 { 01711 if (!strcasecmp(param, "musicclass") || 01712 !strcasecmp(param, "music") || !strcasecmp(param, "musiconhold")) { 01713 ast_string_field_set(q, moh, val); 01714 } else if (!strcasecmp(param, "announce")) { 01715 ast_string_field_set(q, announce, val); 01716 } else if (!strcasecmp(param, "context")) { 01717 ast_string_field_set(q, context, val); 01718 } else if (!strcasecmp(param, "timeout")) { 01719 q->timeout = atoi(val); 01720 if (q->timeout < 0) 01721 q->timeout = DEFAULT_TIMEOUT; 01722 } else if (!strcasecmp(param, "ringinuse")) { 01723 q->ringinuse = ast_true(val); 01724 } else if (!strcasecmp(param, "setinterfacevar")) { 01725 q->setinterfacevar = ast_true(val); 01726 } else if (!strcasecmp(param, "setqueuevar")) { 01727 q->setqueuevar = ast_true(val); 01728 } else if (!strcasecmp(param, "setqueueentryvar")) { 01729 q->setqueueentryvar = ast_true(val); 01730 } else if (!strcasecmp(param, "monitor-format")) { 01731 ast_copy_string(q->monfmt, val, sizeof(q->monfmt)); 01732 } else if (!strcasecmp(param, "membermacro")) { 01733 ast_string_field_set(q, membermacro, val); 01734 } else if (!strcasecmp(param, "membergosub")) { 01735 ast_string_field_set(q, membergosub, val); 01736 } else if (!strcasecmp(param, "queue-youarenext")) { 01737 ast_string_field_set(q, sound_next, val); 01738 } else if (!strcasecmp(param, "queue-thereare")) { 01739 ast_string_field_set(q, sound_thereare, val); 01740 } else if (!strcasecmp(param, "queue-callswaiting")) { 01741 ast_string_field_set(q, sound_calls, val); 01742 } else if (!strcasecmp(param, "queue-quantity1")) { 01743 ast_string_field_set(q, queue_quantity1, val); 01744 } else if (!strcasecmp(param, "queue-quantity2")) { 01745 ast_string_field_set(q, queue_quantity2, val); 01746 } else if (!strcasecmp(param, "queue-holdtime")) { 01747 ast_string_field_set(q, sound_holdtime, val); 01748 } else if (!strcasecmp(param, "queue-minutes")) { 01749 ast_string_field_set(q, sound_minutes, val); 01750 } else if (!strcasecmp(param, "queue-minute")) { 01751 ast_string_field_set(q, sound_minute, val); 01752 } else if (!strcasecmp(param, "queue-seconds")) { 01753 ast_string_field_set(q, sound_seconds, val); 01754 } else if (!strcasecmp(param, "queue-thankyou")) { 01755 ast_string_field_set(q, sound_thanks, val); 01756 } else if (!strcasecmp(param, "queue-callerannounce")) { 01757 ast_string_field_set(q, sound_callerannounce, val); 01758 } else if (!strcasecmp(param, "queue-reporthold")) { 01759 ast_string_field_set(q, sound_reporthold, val); 01760 } else if (!strcasecmp(param, "announce-frequency")) { 01761 q->announcefrequency = atoi(val); 01762 } else if (!strcasecmp(param, "min-announce-frequency")) { 01763 q->minannouncefrequency = atoi(val); 01764 ast_debug(1, "%s=%s for queue '%s'\n", param, val, q->name); 01765 } else if (!strcasecmp(param, "announce-round-seconds")) { 01766 q->roundingseconds = atoi(val); 01767 /* Rounding to any other values just doesn't make sense... */ 01768 if (!(q->roundingseconds == 0 || q->roundingseconds == 5 || q->roundingseconds == 10 01769 || q->roundingseconds == 15 || q->roundingseconds == 20 || q->roundingseconds == 30)) { 01770 if (linenum >= 0) { 01771 ast_log(LOG_WARNING, "'%s' isn't a valid value for %s " 01772 "using 0 instead for queue '%s' at line %d of queues.conf\n", 01773 val, param, q->name, linenum); 01774 } else { 01775 ast_log(LOG_WARNING, "'%s' isn't a valid value for %s " 01776 "using 0 instead for queue '%s'\n", val, param, q->name); 01777 } 01778 q->roundingseconds=0; 01779 } 01780 } else if (!strcasecmp(param, "announce-holdtime")) { 01781 if (!strcasecmp(val, "once")) 01782 q->announceholdtime = ANNOUNCEHOLDTIME_ONCE; 01783 else if (ast_true(val)) 01784 q->announceholdtime = ANNOUNCEHOLDTIME_ALWAYS; 01785 else 01786 q->announceholdtime = 0; 01787 } else if (!strcasecmp(param, "announce-position")) { 01788 if (!strcasecmp(val, "limit")) 01789 q->announceposition = ANNOUNCEPOSITION_LIMIT; 01790 else if (!strcasecmp(val, "more")) 01791 q->announceposition = ANNOUNCEPOSITION_MORE_THAN; 01792 else if (ast_true(val)) 01793 q->announceposition = ANNOUNCEPOSITION_YES; 01794 else 01795 q->announceposition = ANNOUNCEPOSITION_NO; 01796 } else if (!strcasecmp(param, "announce-position-limit")) { 01797 q->announcepositionlimit = atoi(val); 01798 } else if (!strcasecmp(param, "periodic-announce")) { 01799 if (strchr(val, ',')) { 01800 char *s, *buf = ast_strdupa(val); 01801 unsigned int i = 0; 01802 01803 while ((s = strsep(&buf, ",|"))) { 01804 if (!q->sound_periodicannounce[i]) 01805 q->sound_periodicannounce[i] = ast_str_create(16); 01806 ast_str_set(&q->sound_periodicannounce[i], 0, "%s", s); 01807 i++; 01808 if (i == MAX_PERIODIC_ANNOUNCEMENTS) 01809 break; 01810 } 01811 q->numperiodicannounce = i; 01812 } else { 01813 ast_str_set(&q->sound_periodicannounce[0], 0, "%s", val); 01814 q->numperiodicannounce = 1; 01815 } 01816 } else if (!strcasecmp(param, "periodic-announce-frequency")) { 01817 q->periodicannouncefrequency = atoi(val); 01818 } else if (!strcasecmp(param, "relative-periodic-announce")) { 01819 q->relativeperiodicannounce = ast_true(val); 01820 } else if (!strcasecmp(param, "random-periodic-announce")) { 01821 q->randomperiodicannounce = ast_true(val); 01822 } else if (!strcasecmp(param, "retry")) { 01823 q->retry = atoi(val); 01824 if (q->retry <= 0) 01825 q->retry = DEFAULT_RETRY; 01826 } else if (!strcasecmp(param, "wrapuptime")) { 01827 q->wrapuptime = atoi(val); 01828 } else if (!strcasecmp(param, "penaltymemberslimit")) { 01829 if ((sscanf(val, "%10d", &q->penaltymemberslimit) != 1)) { 01830 q->penaltymemberslimit = 0; 01831 } 01832 } else if (!strcasecmp(param, "autofill")) { 01833 q->autofill = ast_true(val); 01834 } else if (!strcasecmp(param, "monitor-type")) { 01835 if (!strcasecmp(val, "mixmonitor")) 01836 q->montype = 1; 01837 } else if (!strcasecmp(param, "autopause")) { 01838 q->autopause = autopause2int(val); 01839 } else if (!strcasecmp(param, "maxlen")) { 01840 q->maxlen = atoi(val); 01841 if (q->maxlen < 0) 01842 q->maxlen = 0; 01843 } else if (!strcasecmp(param, "servicelevel")) { 01844 q->servicelevel= atoi(val); 01845 } else if (!strcasecmp(param, "strategy")) { 01846 int strategy; 01847 01848 /* We are a static queue and already have set this, no need to do it again */ 01849 if (failunknown) { 01850 return; 01851 } 01852 strategy = strat2int(val); 01853 if (strategy < 0) { 01854 ast_log(LOG_WARNING, "'%s' isn't a valid strategy for queue '%s', using ringall instead\n", 01855 val, q->name); 01856 q->strategy = QUEUE_STRATEGY_RINGALL; 01857 } 01858 if (strategy == q->strategy) { 01859 return; 01860 } 01861 if (strategy == QUEUE_STRATEGY_LINEAR) { 01862 ast_log(LOG_WARNING, "Changing to the linear strategy currently requires asterisk to be restarted.\n"); 01863 return; 01864 } 01865 q->strategy = strategy; 01866 } else if (!strcasecmp(param, "joinempty")) { 01867 parse_empty_options(val, &q->joinempty, 1); 01868 } else if (!strcasecmp(param, "leavewhenempty")) { 01869 parse_empty_options(val, &q->leavewhenempty, 0); 01870 } else if (!strcasecmp(param, "eventmemberstatus")) { 01871 q->maskmemberstatus = !ast_true(val); 01872 } else if (!strcasecmp(param, "eventwhencalled")) { 01873 if (!strcasecmp(val, "vars")) { 01874 q->eventwhencalled = QUEUE_EVENT_VARIABLES; 01875 } else { 01876 q->eventwhencalled = ast_true(val) ? 1 : 0; 01877 } 01878 } else if (!strcasecmp(param, "reportholdtime")) { 01879 q->reportholdtime = ast_true(val); 01880 } else if (!strcasecmp(param, "memberdelay")) { 01881 q->memberdelay = atoi(val); 01882 } else if (!strcasecmp(param, "weight")) { 01883 q->weight = atoi(val); 01884 } else if (!strcasecmp(param, "timeoutrestart")) { 01885 q->timeoutrestart = ast_true(val); 01886 } else if (!strcasecmp(param, "defaultrule")) { 01887 ast_string_field_set(q, defaultrule, val); 01888 } else if (!strcasecmp(param, "timeoutpriority")) { 01889 if (!strcasecmp(val, "conf")) { 01890 q->timeoutpriority = TIMEOUT_PRIORITY_CONF; 01891 } else { 01892 q->timeoutpriority = TIMEOUT_PRIORITY_APP; 01893 } 01894 } else if (failunknown) { 01895 if (linenum >= 0) { 01896 ast_log(LOG_WARNING, "Unknown keyword in queue '%s': %s at line %d of queues.conf\n", 01897 q->name, param, linenum); 01898 } else { 01899 ast_log(LOG_WARNING, "Unknown keyword in queue '%s': %s\n", q->name, param); 01900 } 01901 } 01902 }
| static char* queue_show | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 6869 of file app_queue.c.
References __queues_show(), ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, complete_queue_show(), ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
06870 { 06871 switch ( cmd ) { 06872 case CLI_INIT: 06873 e->command = "queue show"; 06874 e->usage = 06875 "Usage: queue show\n" 06876 " Provides summary information on a specified queue.\n"; 06877 return NULL; 06878 case CLI_GENERATE: 06879 return complete_queue_show(a->line, a->word, a->pos, a->n); 06880 } 06881 06882 return __queues_show(NULL, a->fd, a->argc, a->argv); 06883 }
| static void queue_transfer_destroy | ( | void * | data | ) | [static] |
Definition at line 3991 of file app_queue.c.
References ast_free.
03992 { 03993 struct queue_transfer_ds *qtds = data; 03994 ast_free(qtds); 03995 }
| static void queue_transfer_fixup | ( | void * | data, | |
| struct ast_channel * | old_chan, | |||
| struct ast_channel * | new_chan | |||
| ) | [static] |
Log an attended transfer when a queue caller channel is masqueraded.
When a caller is masqueraded, we want to log a transfer. Fixup time is the closest we can come to when the actual transfer occurs. This happens during the masquerade after datastores are moved from old_chan to new_chan. This is why new_chan is referenced for exten, context, and datastore information.
At the end of this, we want to remove the datastore so that this fixup function is not called on any future masquerades of the caller during the current call.
Definition at line 4014 of file app_queue.c.
References ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_log(), ast_queue_log(), queue_transfer_ds::callcompletedinsl, queue_ent::chan, ast_channel::context, ast_channel::exten, LOG_WARNING, queue_transfer_ds::member, member::membername, call_queue::name, queue_ent::opos, queue_ent::parent, queue_transfer_ds::qe, queue_transfer_info, queue_ent::start, queue_transfer_ds::starttime, ast_channel::uniqueid, and update_queue().
04015 { 04016 struct queue_transfer_ds *qtds = data; 04017 struct queue_ent *qe = qtds->qe; 04018 struct member *member = qtds->member; 04019 time_t callstart = qtds->starttime; 04020 int callcompletedinsl = qtds->callcompletedinsl; 04021 struct ast_datastore *datastore; 04022 04023 ast_queue_log(qe->parent->name, qe->chan->uniqueid, member->membername, "TRANSFER", "%s|%s|%ld|%ld|%d", 04024 new_chan->exten, new_chan->context, (long) (callstart - qe->start), 04025 (long) (time(NULL) - callstart), qe->opos); 04026 04027 update_queue(qe->parent, member, callcompletedinsl, (time(NULL) - callstart)); 04028 04029 /* No need to lock the channels because they are already locked in ast_do_masquerade */ 04030 if ((datastore = ast_channel_datastore_find(old_chan, &queue_transfer_info, NULL))) { 04031 ast_channel_datastore_remove(old_chan, datastore); 04032 } else { 04033 ast_log(LOG_WARNING, "Can't find the queue_transfer datastore.\n"); 04034 } 04035 }
| static struct call_queue* queue_unref | ( | struct call_queue * | q | ) | [static, read] |
Definition at line 1124 of file app_queue.c.
References ao2_ref.
Referenced by queue_exec(), and queues_data_provider_get().
01125 { 01126 ao2_ref(q, -1); 01127 return q; 01128 }
| static int queues_data_provider_get | ( | const struct ast_data_search * | search, | |
| struct ast_data * | data_root | |||
| ) | [static] |
Definition at line 8015 of file app_queue.c.
References ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_unlock, ast_category_browse(), ast_config_destroy(), ast_load_realtime_multientry(), ast_strlen_zero(), load_realtime_queue(), call_queue::name, queue_unref(), queues, queues_data_provider_get_helper(), call_queue::realtime, and SENTINEL.
08017 { 08018 struct ao2_iterator i; 08019 struct call_queue *queue, *queue_realtime = NULL; 08020 struct ast_config *cfg; 08021 char *queuename; 08022 08023 /* load realtime queues. */ 08024 cfg = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL); 08025 if (cfg) { 08026 for (queuename = ast_category_browse(cfg, NULL); 08027 !ast_strlen_zero(queuename); 08028 queuename = ast_category_browse(cfg, queuename)) { 08029 if ((queue = load_realtime_queue(queuename))) { 08030 queue_unref(queue); 08031 } 08032 } 08033 ast_config_destroy(cfg); 08034 } 08035 08036 /* static queues. */ 08037 i = ao2_iterator_init(queues, 0); 08038 while ((queue = ao2_iterator_next(&i))) { 08039 ao2_lock(queue); 08040 if (queue->realtime && !(queue_realtime = load_realtime_queue(queue->name))) { 08041 ao2_unlock(queue); 08042 queue_unref(queue); 08043 continue; 08044 } else if (queue->realtime) { 08045 queue_unref(queue_realtime); 08046 } 08047 08048 queues_data_provider_get_helper(search, data_root, queue); 08049 ao2_unlock(queue); 08050 queue_unref(queue); 08051 } 08052 08053 return 0; 08054 }
| static void queues_data_provider_get_helper | ( | const struct ast_data_search * | search, | |
| struct ast_data * | data_root, | |||
| struct call_queue * | queue | |||
| ) | [static] |
Definition at line 7911 of file app_queue.c.
References call_queue::announceposition, ANNOUNCEPOSITION_LIMIT, ANNOUNCEPOSITION_MORE_THAN, ANNOUNCEPOSITION_NO, ANNOUNCEPOSITION_YES, ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_channel_data_add_structure(), ast_data_add_int(), ast_data_add_node(), ast_data_add_str(), ast_data_add_structure, ast_data_remove_node(), ast_data_search_match(), queue_ent::chan, call_queue::head, int2strat(), call_queue::members, queue_ent::next, and call_queue::strategy.
Referenced by queues_data_provider_get().
07913 { 07914 struct ao2_iterator im; 07915 struct member *member; 07916 struct queue_ent *qe; 07917 struct ast_data *data_queue, *data_members = NULL, *enum_node; 07918 struct ast_data *data_member, *data_callers = NULL, *data_caller, *data_caller_channel; 07919 07920 data_queue = ast_data_add_node(data_root, "queue"); 07921 if (!data_queue) { 07922 return; 07923 } 07924 07925 ast_data_add_structure(call_queue, data_queue, queue); 07926 07927 ast_data_add_str(data_queue, "strategy", int2strat(queue->strategy)); 07928 07929 /* announce position */ 07930 enum_node = ast_data_add_node(data_queue, "announceposition"); 07931 if (!enum_node) { 07932 return; 07933 } 07934 switch (queue->announceposition) { 07935 case ANNOUNCEPOSITION_LIMIT: 07936 ast_data_add_str(enum_node, "text", "limit"); 07937 break; 07938 case ANNOUNCEPOSITION_MORE_THAN: 07939 ast_data_add_str(enum_node, "text", "more"); 07940 break; 07941 case ANNOUNCEPOSITION_YES: 07942 ast_data_add_str(enum_node, "text", "yes"); 07943 break; 07944 case ANNOUNCEPOSITION_NO: 07945 ast_data_add_str(enum_node, "text", "no"); 07946 break; 07947 default: 07948 ast_data_add_str(enum_node, "text", "unknown"); 07949 break; 07950 } 07951 ast_data_add_int(enum_node, "value", queue->announceposition); 07952 07953 /* add queue members */ 07954 im = ao2_iterator_init(queue->members, 0); 07955 while ((member = ao2_iterator_next(&im))) { 07956 if (!data_members) { 07957 data_members = ast_data_add_node(data_queue, "members"); 07958 if (!data_members) { 07959 ao2_ref(member, -1); 07960 continue; 07961 } 07962 } 07963 07964 data_member = ast_data_add_node(data_members, "member"); 07965 if (!data_member) { 07966 ao2_ref(member, -1); 07967 continue; 07968 } 07969 07970 ast_data_add_structure(member, data_member, member); 07971 07972 ao2_ref(member, -1); 07973 } 07974 07975 /* include the callers inside the result. */ 07976 if (queue->head) { 07977 for (qe = queue->head; qe; qe = qe->next) { 07978 if (!data_callers) { 07979 data_callers = ast_data_add_node(data_queue, "callers"); 07980 if (!data_callers) { 07981 continue; 07982 } 07983 } 07984 07985 data_caller = ast_data_add_node(data_callers, "caller"); 07986 if (!data_caller) { 07987 continue; 07988 } 07989 07990 ast_data_add_structure(queue_ent, data_caller, qe); 07991 07992 /* add the caller channel. */ 07993 data_caller_channel = ast_data_add_node(data_caller, "channel"); 07994 if (!data_caller_channel) { 07995 continue; 07996 } 07997 07998 ast_channel_data_add_structure(data_caller_channel, qe->chan, 1); 07999 } 08000 } 08001 08002 /* if this queue doesn't match remove the added queue. */ 08003 if (!ast_data_search_match(search, data_queue)) { 08004 ast_data_remove_node(data_root, data_queue); 08005 } 08006 }
| static void recalc_holdtime | ( | struct queue_ent * | qe, | |
| int | newholdtime | |||
| ) | [static] |
Definition at line 2570 of file app_queue.c.
References ao2_lock, ao2_unlock, call_queue::holdtime, and queue_ent::parent.
Referenced by try_calling().
02571 { 02572 int oldvalue; 02573 02574 /* Calculate holdtime using an exponential average */ 02575 /* Thanks to SRT for this contribution */ 02576 /* 2^2 (4) is the filter coefficient; a higher exponent would give old entries more weight */ 02577 02578 ao2_lock(qe->parent); 02579 oldvalue = qe->parent->holdtime; 02580 qe->parent->holdtime = (((oldvalue << 2) - oldvalue) + newholdtime) >> 2; 02581 ao2_unlock(qe->parent); 02582 }
| static void record_abandoned | ( | struct queue_ent * | qe | ) | [static] |
Record that a caller gave up on waiting in queue.
Definition at line 3174 of file app_queue.c.
References ao2_lock, ao2_unlock, call_queue::callsabandoned, queue_ent::chan, EVENT_FLAG_AGENT, manager_event, call_queue::name, queue_ent::opos, queue_ent::parent, queue_ent::pos, set_queue_variables(), queue_ent::start, and ast_channel::uniqueid.
Referenced by queue_exec(), and try_calling().
03175 { 03176 ao2_lock(qe->parent); 03177 set_queue_variables(qe->parent, qe->chan); 03178 manager_event(EVENT_FLAG_AGENT, "QueueCallerAbandon", 03179 "Queue: %s\r\n" 03180 "Uniqueid: %s\r\n" 03181 "Position: %d\r\n" 03182 "OriginalPosition: %d\r\n" 03183 "HoldTime: %d\r\n", 03184 qe->parent->name, qe->chan->uniqueid, qe->pos, qe->opos, (int)(time(NULL) - qe->start)); 03185 03186 qe->parent->callsabandoned++; 03187 ao2_unlock(qe->parent); 03188 }
| static int reload | ( | void | ) | [static] |
Definition at line 8186 of file app_queue.c.
References AST_FLAGS_ALL, ast_unload_realtime(), QUEUE_RESET_STATS, and reload_handler().
08187 { 08188 struct ast_flags mask = {AST_FLAGS_ALL & ~QUEUE_RESET_STATS,}; 08189 ast_unload_realtime("queue_members"); 08190 reload_handler(1, &mask, NULL); 08191 return 0; 08192 }
| static int reload_handler | ( | int | reload, | |
| struct ast_flags * | mask, | |||
| const char * | queuename | |||
| ) | [static] |
The command center for all reload operations.
Whenever any piece of queue information is to be reloaded, this function is called. It interprets the flags set in the mask parameter and acts based on how they are set.
| reload | True if we are reloading information, false if we are loading information for the first time. | |
| mask | A bitmask which tells the handler what actions to take | |
| queuename | The name of the queue on which we wish to take action |
| 0 | All reloads were successful | |
| non-zero | There was a failure |
Definition at line 6681 of file app_queue.c.
References ast_test_flag, clear_stats(), QUEUE_RELOAD_MEMBER, QUEUE_RELOAD_PARAMETERS, QUEUE_RELOAD_RULES, QUEUE_RESET_STATS, reload_queue_rules(), and reload_queues().
Referenced by handle_queue_reload(), handle_queue_reset(), load_module(), manager_queue_reload(), manager_queue_reset(), and reload().
06682 { 06683 int res = 0; 06684 06685 if (ast_test_flag(mask, QUEUE_RELOAD_RULES)) { 06686 res |= reload_queue_rules(reload); 06687 } 06688 if (ast_test_flag(mask, QUEUE_RESET_STATS)) { 06689 res |= clear_stats(queuename); 06690 } 06691 if (ast_test_flag(mask, (QUEUE_RELOAD_PARAMETERS | QUEUE_RELOAD_MEMBER))) { 06692 res |= reload_queues(reload, mask, queuename); 06693 } 06694 return res; 06695 }
| static void reload_queue_members | ( | void | ) | [static] |
Reload dynamic queue members persisted into the astdb.
Definition at line 5245 of file app_queue.c.
References add_to_queue(), ao2_lock, ao2_t_find, ao2_unlock, ast_db_del(), ast_db_freetree(), ast_db_get(), ast_db_gettree(), ast_debug, ast_log(), ast_strlen_zero(), errno, member::interface, ast_db_entry::key, load_realtime_queue(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, member::membername, call_queue::name, ast_db_entry::next, OBJ_POINTER, member::paused, member::penalty, PM_MAX_LEN, queue_t_unref, queues, RES_OUTOFMEMORY, member::state_interface, and strsep().
Referenced by load_module().
05246 { 05247 char *cur_ptr; 05248 const char *queue_name; 05249 char *member; 05250 char *interface; 05251 char *membername = NULL; 05252 char *state_interface; 05253 char *penalty_tok; 05254 int penalty = 0; 05255 char *paused_tok; 05256 int paused = 0; 05257 struct ast_db_entry *db_tree; 05258 struct ast_db_entry *entry; 05259 struct call_queue *cur_queue; 05260 char queue_data[PM_MAX_LEN]; 05261 05262 ao2_lock(queues); 05263 05264 /* Each key in 'pm_family' is the name of a queue */ 05265 db_tree = ast_db_gettree(pm_family, NULL); 05266 for (entry = db_tree; entry; entry = entry->next) { 05267 05268 queue_name = entry->key + strlen(pm_family) + 2; 05269 05270 { 05271 struct call_queue tmpq = { 05272 .name = queue_name, 05273 }; 05274 cur_queue = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Reload queue members"); 05275 } 05276 05277 if (!cur_queue) 05278 cur_queue = load_realtime_queue(queue_name); 05279 05280 if (!cur_queue) { 05281 /* If the queue no longer exists, remove it from the 05282 * database */ 05283 ast_log(LOG_WARNING, "Error loading persistent queue: '%s': it does not exist\n", queue_name); 05284 ast_db_del(pm_family, queue_name); 05285 continue; 05286 } 05287 05288 if (ast_db_get(pm_family, queue_name, queue_data, PM_MAX_LEN)) { 05289 queue_t_unref(cur_queue, "Expire reload reference"); 05290 continue; 05291 } 05292 05293 cur_ptr = queue_data; 05294 while ((member = strsep(&cur_ptr, ",|"))) { 05295 if (ast_strlen_zero(member)) 05296 continue; 05297 05298 interface = strsep(&member, ";"); 05299 penalty_tok = strsep(&member, ";"); 05300 paused_tok = strsep(&member, ";"); 05301 membername = strsep(&member, ";"); 05302 state_interface = strsep(&member, ";"); 05303 05304 if (!penalty_tok) { 05305 ast_log(LOG_WARNING, "Error parsing persistent member string for '%s' (penalty)\n", queue_name); 05306 break; 05307 } 05308 penalty = strtol(penalty_tok, NULL, 10); 05309 if (errno == ERANGE) { 05310 ast_log(LOG_WARNING, "Error converting penalty: %s: Out of range.\n", penalty_tok); 05311 break; 05312 } 05313 05314 if (!paused_tok) { 05315 ast_log(LOG_WARNING, "Error parsing persistent member string for '%s' (paused)\n", queue_name); 05316 break; 05317 } 05318 paused = strtol(paused_tok, NULL, 10); 05319 if ((errno == ERANGE) || paused < 0 || paused > 1) { 05320 ast_log(LOG_WARNING, "Error converting paused: %s: Expected 0 or 1.\n", paused_tok); 05321 break; 05322 } 05323 05324 ast_debug(1, "Reload Members: Queue: %s Member: %s Name: %s Penalty: %d Paused: %d\n", queue_name, interface, membername, penalty, paused); 05325 05326 if (add_to_queue(queue_name, interface, membername, penalty, paused, 0, state_interface) == RES_OUTOFMEMORY) { 05327 ast_log(LOG_ERROR, "Out of Memory when reloading persistent queue member\n"); 05328 break; 05329 } 05330 } 05331 queue_t_unref(cur_queue, "Expire reload reference"); 05332 } 05333 05334 ao2_unlock(queues); 05335 if (db_tree) { 05336 ast_log(LOG_NOTICE, "Queue members successfully reloaded from database.\n"); 05337 ast_db_freetree(db_tree); 05338 } 05339 }
| static int reload_queue_rules | ( | int | reload | ) | [static] |
Reload the rules defined in queuerules.conf.
| reload | If 1, then only process queuerules.conf if the file has changed since the last time we inspected it. |
Definition at line 6279 of file app_queue.c.
References ast_calloc, ast_category_browse(), ast_config_destroy(), ast_config_load, ast_copy_string(), ast_free, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_log(), AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_variable_browse(), CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, insert_penaltychange(), ast_variable::lineno, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_variable::name, rule_list::name, ast_variable::next, rule_list::rules, and ast_variable::value.
Referenced by reload_handler().
06280 { 06281 struct ast_config *cfg; 06282 struct rule_list *rl_iter, *new_rl; 06283 struct penalty_rule *pr_iter; 06284 char *rulecat = NULL; 06285 struct ast_variable *rulevar = NULL; 06286 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; 06287 06288 if (!(cfg = ast_config_load("queuerules.conf", config_flags))) { 06289 ast_log(LOG_NOTICE, "No queuerules.conf file found, queues will not follow penalty rules\n"); 06290 return AST_MODULE_LOAD_SUCCESS; 06291 } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) { 06292 ast_log(LOG_NOTICE, "queuerules.conf has not changed since it was last loaded. Not taking any action.\n"); 06293 return AST_MODULE_LOAD_SUCCESS; 06294 } else if (cfg == CONFIG_STATUS_FILEINVALID) { 06295 ast_log(LOG_ERROR, "Config file queuerules.conf is in an invalid format. Aborting.\n"); 06296 return AST_MODULE_LOAD_SUCCESS; 06297 } 06298 06299 AST_LIST_LOCK(&rule_lists); 06300 while ((rl_iter = AST_LIST_REMOVE_HEAD(&rule_lists, list))) { 06301 while ((pr_iter = AST_LIST_REMOVE_HEAD(&rl_iter->rules, list))) 06302 ast_free(pr_iter); 06303 ast_free(rl_iter); 06304 } 06305 while ((rulecat = ast_category_browse(cfg, rulecat))) { 06306 if (!(new_rl = ast_calloc(1, sizeof(*new_rl)))) { 06307 AST_LIST_UNLOCK(&rule_lists); 06308 return AST_MODULE_LOAD_FAILURE; 06309 } else { 06310 ast_copy_string(new_rl->name, rulecat, sizeof(new_rl->name)); 06311 AST_LIST_INSERT_TAIL(&rule_lists, new_rl, list); 06312 for (rulevar = ast_variable_browse(cfg, rulecat); rulevar; rulevar = rulevar->next) 06313 if(!strcasecmp(rulevar->name, "penaltychange")) 06314 insert_penaltychange(new_rl->name, rulevar->value, rulevar->lineno); 06315 else 06316 ast_log(LOG_WARNING, "Don't know how to handle rule type '%s' on line %d\n", rulevar->name, rulevar->lineno); 06317 } 06318 } 06319 AST_LIST_UNLOCK(&rule_lists); 06320 06321 ast_config_destroy(cfg); 06322 06323 return AST_MODULE_LOAD_SUCCESS; 06324 }
| static int reload_queues | ( | int | reload, | |
| struct ast_flags * | mask, | |||
| const char * | queuename | |||
| ) | [static] |
reload the queues.conf file
This function reloads the information in the general section of the queues.conf file and potentially more, depending on the value of mask.
| reload | 0 if we are calling this the first time, 1 every other time | |
| mask | Gives flags telling us what information to actually reload | |
| queuename | If set to a non-zero string, then only reload information from that particular queue. Otherwise inspect all queues |
| -1 | Failure occurred | |
| 0 | All clear! |
Definition at line 6593 of file app_queue.c.
References ao2_callback, ao2_lock, ao2_unlock, ast_category_browse(), ast_config_destroy(), ast_config_load, ast_log(), ast_strlen_zero(), ast_test_flag, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, kill_dead_queues(), LOG_ERROR, LOG_NOTICE, mark_dead_and_unfound(), OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, QUEUE_RELOAD_PARAMETERS, queue_set_global_params(), queues, and reload_single_queue().
Referenced by reload_handler().
06594 { 06595 struct ast_config *cfg; 06596 char *cat; 06597 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; 06598 const int queue_reload = ast_test_flag(mask, QUEUE_RELOAD_PARAMETERS); 06599 06600 if (!(cfg = ast_config_load("queues.conf", config_flags))) { 06601 ast_log(LOG_NOTICE, "No call queueing config file (queues.conf), so no call queues\n"); 06602 return -1; 06603 } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) { 06604 return 0; 06605 } else if (cfg == CONFIG_STATUS_FILEINVALID) { 06606 ast_log(LOG_ERROR, "Config file queues.conf is in an invalid format. Aborting.\n"); 06607 return -1; 06608 } 06609 06610 /* We've made it here, so it looks like we're doing operations on all queues. */ 06611 ao2_lock(queues); 06612 06613 /* Mark all queues as dead for the moment if we're reloading queues. 06614 * For clarity, we could just be reloading members, in which case we don't want to mess 06615 * with the other queue parameters at all*/ 06616 if (queue_reload) { 06617 ao2_callback(queues, OBJ_NODATA, mark_dead_and_unfound, (char *) queuename); 06618 } 06619 06620 /* Chug through config file */ 06621 cat = NULL; 06622 while ((cat = ast_category_browse(cfg, cat)) ) { 06623 if (!strcasecmp(cat, "general") && queue_reload) { 06624 queue_set_global_params(cfg); 06625 continue; 06626 } 06627 if (ast_strlen_zero(queuename) || !strcasecmp(cat, queuename)) 06628 reload_single_queue(cfg, mask, cat); 06629 } 06630 06631 ast_config_destroy(cfg); 06632 /* Unref all the dead queues if we were reloading queues */ 06633 if (queue_reload) { 06634 ao2_callback(queues, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, kill_dead_queues, (char *) queuename); 06635 } 06636 ao2_unlock(queues); 06637 return 0; 06638 }
| static void reload_single_member | ( | const char * | memberdata, | |
| struct call_queue * | q | |||
| ) | [static] |
reload information pertaining to a single member
This function is called when a member = line is encountered in queues.conf.
| memberdata | The part after member = in the config file | |
| q | The queue to which this member belongs |
Definition at line 6357 of file app_queue.c.
References ao2_find, ao2_link, ao2_ref, args, AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strip(), ast_strlen_zero(), create_queue_member(), member::interface, LOG_WARNING, call_queue::membercount, call_queue::members, OBJ_POINTER, OBJ_UNLINK, parse(), member::paused, and member::penalty.
Referenced by reload_single_queue().
06358 { 06359 char *membername, *interface, *state_interface, *tmp; 06360 char *parse; 06361 struct member *cur, *newm; 06362 struct member tmpmem; 06363 int penalty; 06364 AST_DECLARE_APP_ARGS(args, 06365 AST_APP_ARG(interface); 06366 AST_APP_ARG(penalty); 06367 AST_APP_ARG(membername); 06368 AST_APP_ARG(state_interface); 06369 ); 06370 06371 if (ast_strlen_zero(memberdata)) { 06372 ast_log(LOG_WARNING, "Empty queue member definition. Moving on!\n"); 06373 return; 06374 } 06375 06376 /* Add a new member */ 06377 parse = ast_strdupa(memberdata); 06378 06379 AST_STANDARD_APP_ARGS(args, parse); 06380 06381 interface = args.interface; 06382 if (!ast_strlen_zero(args.penalty)) { 06383 tmp = args.penalty; 06384 ast_strip(tmp); 06385 penalty = atoi(tmp); 06386 if (penalty < 0) { 06387 penalty = 0; 06388 } 06389 } else { 06390 penalty = 0; 06391 } 06392 06393 if (!ast_strlen_zero(args.membername)) { 06394 membername = args.membername; 06395 ast_strip(membername); 06396 } else { 06397 membername = interface; 06398 } 06399 06400 if (!ast_strlen_zero(args.state_interface)) { 06401 state_interface = args.state_interface; 06402 ast_strip(state_interface); 06403 } else { 06404 state_interface = interface; 06405 } 06406 06407 /* Find the old position in the list */ 06408 ast_copy_string(tmpmem.interface, interface, sizeof(tmpmem.interface)); 06409 cur = ao2_find(q->members, &tmpmem, OBJ_POINTER | OBJ_UNLINK); 06410 if ((newm = create_queue_member(interface, membername, penalty, cur ? cur->paused : 0, state_interface))) { 06411 ao2_link(q->members, newm); 06412 ao2_ref(newm, -1); 06413 } 06414 newm = NULL; 06415 06416 if (cur) { 06417 ao2_ref(cur, -1); 06418 } else { 06419 q->membercount++; 06420 } 06421 }
| static void reload_single_queue | ( | struct ast_config * | cfg, | |
| struct ast_flags * | mask, | |||
| const char * | queuename | |||
| ) | [static] |
Reload information pertaining to a particular queue.
Once we have isolated a queue within reload_queues, we call this. This will either reload information for the queue or if we're just reloading member information, we'll just reload that without touching other settings within the queue
| cfg | The configuration which we are reading | |
| mask | Tells us what information we need to reload | |
| queuename | The name of the queue we are reloading information from |
| void |
Definition at line 6463 of file app_queue.c.
References alloc_queue(), ao2_callback, ao2_lock, ao2_t_find, ao2_unlock, ast_atomic_fetchadd_int(), ast_log(), ast_test_flag, ast_variable_browse(), ast_variable_retrieve(), call_queue::found, init_queue(), kill_dead_members(), ast_variable::lineno, LOG_WARNING, mark_member_dead(), call_queue::membercount, call_queue::members, ast_variable::name, call_queue::name, ast_variable::next, OBJ_MULTIPLE, OBJ_NODATA, OBJ_POINTER, OBJ_UNLINK, QUEUE_RELOAD_MEMBER, QUEUE_RELOAD_PARAMETERS, queue_set_param(), QUEUE_STRATEGY_RINGALL, queue_t_unref, queues, queues_t_link, reload_single_member(), strat2int(), call_queue::strategy, ast_variable::value, var, and call_queue::weight.
Referenced by reload_queues().
06464 { 06465 int new; 06466 struct call_queue *q = NULL; 06467 /*We're defining a queue*/ 06468 struct call_queue tmpq = { 06469 .name = queuename, 06470 }; 06471 const char *tmpvar; 06472 const int queue_reload = ast_test_flag(mask, QUEUE_RELOAD_PARAMETERS); 06473 const int member_reload = ast_test_flag(mask, QUEUE_RELOAD_MEMBER); 06474 int prev_weight = 0; 06475 struct ast_variable *var; 06476 if (!(q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Find queue for reload"))) { 06477 if (queue_reload) { 06478 /* Make one then */ 06479 if (!(q = alloc_queue(queuename))) { 06480 return; 06481 } 06482 } else { 06483 /* Since we're not reloading queues, this means that we found a queue 06484 * in the configuration file which we don't know about yet. Just return. 06485 */ 06486 return; 06487 } 06488 new = 1; 06489 } else { 06490 new = 0; 06491 } 06492 06493 if (!new) { 06494 ao2_lock(q); 06495 prev_weight = q->weight ? 1 : 0; 06496 } 06497 /* Check if we already found a queue with this name in the config file */ 06498 if (q->found) { 06499 ast_log(LOG_WARNING, "Queue '%s' already defined! Skipping!\n", queuename); 06500 if (!new) { 06501 /* It should be impossible to *not* hit this case*/ 06502 ao2_unlock(q); 06503 } 06504 queue_t_unref(q, "We exist! Expiring temporary pointer"); 06505 return; 06506 } 06507 /* Due to the fact that the "linear" strategy will have a different allocation 06508 * scheme for queue members, we must devise the queue's strategy before other initializations. 06509 * To be specific, the linear strategy needs to function like a linked list, meaning the ao2 06510 * container used will have only a single bucket instead of the typical number. 06511 */ 06512 if (queue_reload) { 06513 if ((tmpvar = ast_variable_retrieve(cfg, queuename, "strategy"))) { 06514 q->strategy = strat2int(tmpvar); 06515 if (q->strategy < 0) { 06516 ast_log(LOG_WARNING, "'%s' isn't a valid strategy for queue '%s', using ringall instead\n", 06517 tmpvar, q->name); 06518 q->strategy = QUEUE_STRATEGY_RINGALL; 06519 } 06520 } else { 06521 q->strategy = QUEUE_STRATEGY_RINGALL; 06522 } 06523 init_queue(q); 06524 } 06525 if (member_reload) { 06526 q->membercount = 0; 06527 ao2_callback(q->members, OBJ_NODATA, mark_member_dead, NULL); 06528 } 06529 for (var = ast_variable_browse(cfg, queuename); var; var = var->next) { 06530 if (member_reload && !strcasecmp(var->name, "member")) { 06531 reload_single_member(var->value, q); 06532 } else if (queue_reload) { 06533 queue_set_param(q, var->name, var->value, var->lineno, 1); 06534 } 06535 } 06536 /* At this point, we've determined if the queue has a weight, so update use_weight 06537 * as appropriate 06538 */ 06539 if (!q->weight && prev_weight) { 06540 ast_atomic_fetchadd_int(&use_weight, -1); 06541 } 06542 else if (q->weight && !prev_weight) { 06543 ast_atomic_fetchadd_int(&use_weight, +1); 06544 } 06545 06546 /* Free remaining members marked as delme */ 06547 if (member_reload) { 06548 ao2_callback(q->members, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, kill_dead_members, q); 06549 } 06550 06551 if (new) { 06552 queues_t_link(queues, q, "Add queue to container"); 06553 } else { 06554 ao2_unlock(q); 06555 } 06556 queue_t_unref(q, "Expiring creation reference"); 06557 }
| static int remove_from_queue | ( | const char * | queuename, | |
| const char * | interface | |||
| ) | [static] |
Remove member from queue.
| RES_NOT_DYNAMIC | when they aren't a RT member | |
| RES_NOSUCHQUEUE | queue does not exist | |
| RES_OKAY | removed member from queue | |
| RES_EXISTS | queue exists but no members |
Definition at line 4980 of file app_queue.c.
References ao2_find, ao2_lock, ao2_ref, ao2_t_find, ao2_unlink, ao2_unlock, ast_copy_string(), dump_queue_members(), member::dynamic, EVENT_FLAG_AGENT, member::interface, manager_event, call_queue::membercount, member::membername, call_queue::members, call_queue::name, OBJ_POINTER, queue_t_unref, queues, RES_EXISTS, RES_NOSUCHQUEUE, RES_NOT_DYNAMIC, and RES_OKAY.
Referenced by handle_queue_remove_member(), manager_remove_queue_member(), and rqm_exec().
04981 { 04982 struct call_queue *q, tmpq = { 04983 .name = queuename, 04984 }; 04985 struct member *mem, tmpmem; 04986 int res = RES_NOSUCHQUEUE; 04987 04988 ast_copy_string(tmpmem.interface, interface, sizeof(tmpmem.interface)); 04989 if ((q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Temporary reference for interface removal"))) { 04990 ao2_lock(queues); 04991 ao2_lock(q); 04992 if ((mem = ao2_find(q->members, &tmpmem, OBJ_POINTER))) { 04993 /* XXX future changes should beware of this assumption!! */ 04994 if (!mem->dynamic) { 04995 ao2_ref(mem, -1); 04996 ao2_unlock(q); 04997 queue_t_unref(q, "Interface wasn't dynamic, expiring temporary reference"); 04998 ao2_unlock(queues); 04999 return RES_NOT_DYNAMIC; 05000 } 05001 q->membercount--; 05002 manager_event(EVENT_FLAG_AGENT, "QueueMemberRemoved", 05003 "Queue: %s\r\n" 05004 "Location: %s\r\n" 05005 "MemberName: %s\r\n", 05006 q->name, mem->interface, mem->membername); 05007 ao2_unlink(q->members, mem); 05008 ao2_ref(mem, -1); 05009 05010 if (queue_persistent_members) 05011 dump_queue_members(q); 05012 05013 res = RES_OKAY; 05014 } else { 05015 res = RES_EXISTS; 05016 } 05017 ao2_unlock(q); 05018 ao2_unlock(queues); 05019 queue_t_unref(q, "Expiring temporary reference"); 05020 } 05021 05022 return res; 05023 }
| static int ring_entry | ( | struct queue_ent * | qe, | |
| struct callattempt * | tmp, | |||
| int * | busies | |||
| ) | [static] |
Part 2 of ring_one.
Does error checking before attempting to request a channel and call a member. This function is only called from ring_one(). Failure can occur if:
| 1 | on success to reach a free agent | |
| 0 | on failure to get agent. |
Definition at line 2833 of file app_queue.c.
References ast_cdr::accountcode, ast_channel::adsicpe, ast_cdr::amaflags, ast_party_connected_line::ani, ast_party_caller::ani, ao2_lock, ao2_unlock, ast_channel::appl, ast_call(), ast_cdr_busy(), ast_cdr_isset_unanswered(), ast_cdr_setdestchan(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_set_caller_event(), ast_channel_trylock, ast_channel_unlock, ast_connected_line_copy_from_caller(), ast_copy_string(), ast_debug, AST_DEVICE_NOT_INUSE, AST_DEVICE_UNKNOWN, AST_FLAG_ANSWERED_ELSEWHERE, ast_party_caller_set_init(), ast_party_redirecting_copy(), ast_request(), ast_set_callerid(), ast_set_flag, ast_string_field_set, ast_strlen_zero(), ast_verb, ast_channel::caller, queue_ent::cancel_answered_elsewhere, ast_channel::cdr, callattempt::chan, queue_ent::chan, ast_cdr::channel, CHANNEL_DEADLOCK_AVOIDANCE, ast_cdr::clid, compare_weight(), ast_channel::connected, ast_channel::context, ast_channel::data, ast_cdr::dcontext, callattempt::dial_callerid_absent, dialcontext, ast_channel::dialed, do_hang(), ast_cdr::dst, EVENT_FLAG_AGENT, call_queue::eventwhencalled, ast_channel::exten, get_queue_member_status(), ast_party_connected_line::id, ast_party_caller::id, callattempt::interface, ast_cdr::lastapp, callattempt::lastcall, ast_cdr::lastdata, callattempt::lastqueue, queue_ent::linpos, ast_channel::macroexten, manager_event, callattempt::member, member::membername, ast_party_id::name, ast_channel::name, call_queue::name, ast_channel::nativeformats, ast_party_dialed::number, ast_party_id::number, queue_ent::parent, member::paused, pbx_builtin_getvar_helper(), ast_channel::priority, QUEUE_EVENT_VARIABLES, ast_channel::redirecting, call_queue::ringinuse, call_queue::rrpos, S_COR, S_OR, ast_cdr::src, member::status, status, callattempt::stillgoing, ast_party_name::str, ast_party_number::str, ast_party_dialed::str, ast_party_dialed::transit_network_select, ast_channel::uniqueid, update_status(), ast_cdr::userfield, ast_party_name::valid, ast_party_number::valid, vars2manager(), ast_channel::whentohangup, and call_queue::wrapuptime.
Referenced by ring_one().
02834 { 02835 int res; 02836 int status; 02837 char tech[256]; 02838 char *location; 02839 const char *macrocontext, *macroexten; 02840 02841 /* on entry here, we know that tmp->chan == NULL */ 02842 if ((tmp->lastqueue && tmp->lastqueue->wrapuptime && (time(NULL) - tmp->lastcall < tmp->lastqueue->wrapuptime)) || 02843 (!tmp->lastqueue && qe->parent->wrapuptime && (time(NULL) - tmp->lastcall < qe->parent->wrapuptime))) { 02844 ast_debug(1, "Wrapuptime not yet expired on queue %s for %s\n", 02845 (tmp->lastqueue ? tmp->lastqueue->name : qe->parent->name), tmp->interface); 02846 if (qe->chan->cdr) 02847 ast_cdr_busy(qe->chan->cdr); 02848 tmp->stillgoing = 0; 02849 (*busies)++; 02850 return 0; 02851 } 02852 02853 if (!qe->parent->ringinuse && (tmp->member->status != AST_DEVICE_NOT_INUSE) && (tmp->member->status != AST_DEVICE_UNKNOWN)) { 02854 ast_debug(1, "%s in use, can't receive call\n", tmp->interface); 02855 if (qe->chan->cdr) 02856 ast_cdr_busy(qe->chan->cdr); 02857 tmp->stillgoing = 0; 02858 return 0; 02859 } 02860 02861 if (tmp->member->paused) { 02862 ast_debug(1, "%s paused, can't receive call\n", tmp->interface); 02863 if (qe->chan->cdr) 02864 ast_cdr_busy(qe->chan->cdr); 02865 tmp->stillgoing = 0; 02866 return 0; 02867 } 02868 if (use_weight && compare_weight(qe->parent,tmp->member)) { 02869 ast_debug(1, "Priority queue delaying call to %s:%s\n", qe->parent->name, tmp->interface); 02870 if (qe->chan->cdr) 02871 ast_cdr_busy(qe->chan->cdr); 02872 tmp->stillgoing = 0; 02873 (*busies)++; 02874 return 0; 02875 } 02876 02877 ast_copy_string(tech, tmp->interface, sizeof(tech)); 02878 if ((location = strchr(tech, '/'))) 02879 *location++ = '\0'; 02880 else 02881 location = ""; 02882 02883 /* Request the peer */ 02884 tmp->chan = ast_request(tech, qe->chan->nativeformats, qe->chan, location, &status); 02885 if (!tmp->chan) { /* If we can't, just go on to the next call */ 02886 if (qe->chan->cdr) 02887 ast_cdr_busy(qe->chan->cdr); 02888 tmp->stillgoing = 0; 02889 02890 ao2_lock(qe->parent); 02891 update_status(qe->parent, tmp->member, get_queue_member_status(tmp->member)); 02892 qe->parent->rrpos++; 02893 qe->linpos++; 02894 ao2_unlock(qe->parent); 02895 02896 (*busies)++; 02897 return 0; 02898 } 02899 02900 ast_channel_lock(tmp->chan); 02901 while (ast_channel_trylock(qe->chan)) { 02902 CHANNEL_DEADLOCK_AVOIDANCE(tmp->chan); 02903 } 02904 02905 if (qe->cancel_answered_elsewhere) { 02906 ast_set_flag(tmp->chan, AST_FLAG_ANSWERED_ELSEWHERE); 02907 } 02908 tmp->chan->appl = "AppQueue"; 02909 tmp->chan->data = "(Outgoing Line)"; 02910 memset(&tmp->chan->whentohangup, 0, sizeof(tmp->chan->whentohangup)); 02911 02912 /* If the new channel has no callerid, try to guess what it should be */ 02913 if (!tmp->chan->caller.id.number.valid) { 02914 if (qe->chan->connected.id.number.valid) { 02915 struct ast_party_caller caller; 02916 02917 ast_party_caller_set_init(&caller, &tmp->chan->caller); 02918 caller.id = qe->chan->connected.id; 02919 caller.ani = qe->chan->connected.ani; 02920 ast_channel_set_caller_event(tmp->chan, &caller, NULL); 02921 } else if (!ast_strlen_zero(qe->chan->dialed.number.str)) { 02922 ast_set_callerid(tmp->chan, qe->chan->dialed.number.str, NULL, NULL); 02923 } else if (!ast_strlen_zero(S_OR(qe->chan->macroexten, qe->chan->exten))) { 02924 ast_set_callerid(tmp->chan, S_OR(qe->chan->macroexten, qe->chan->exten), NULL, NULL); 02925 } 02926 tmp->dial_callerid_absent = 1; 02927 } 02928 02929 ast_party_redirecting_copy(&tmp->chan->redirecting, &qe->chan->redirecting); 02930 02931 tmp->chan->dialed.transit_network_select = qe->chan->dialed.transit_network_select; 02932 02933 ast_connected_line_copy_from_caller(&tmp->chan->connected, &qe->chan->caller); 02934 02935 /* Inherit specially named variables from parent channel */ 02936 ast_channel_inherit_variables(qe->chan, tmp->chan); 02937 ast_channel_datastore_inherit(qe->chan, tmp->chan); 02938 02939 /* Presense of ADSI CPE on outgoing channel follows ours */ 02940 tmp->chan->adsicpe = qe->chan->adsicpe; 02941 02942 /* Inherit context and extension */ 02943 macrocontext = pbx_builtin_getvar_helper(qe->chan, "MACRO_CONTEXT"); 02944 ast_string_field_set(tmp->chan, dialcontext, ast_strlen_zero(macrocontext) ? qe->chan->context : macrocontext); 02945 macroexten = pbx_builtin_getvar_helper(qe->chan, "MACRO_EXTEN"); 02946 if (!ast_strlen_zero(macroexten)) 02947 ast_copy_string(tmp->chan->exten, macroexten, sizeof(tmp->chan->exten)); 02948 else 02949 ast_copy_string(tmp->chan->exten, qe->chan->exten, sizeof(tmp->chan->exten)); 02950 if (ast_cdr_isset_unanswered()) { 02951 /* they want to see the unanswered dial attempts! */ 02952 /* set up the CDR fields on all the CDRs to give sensical information */ 02953 ast_cdr_setdestchan(tmp->chan->cdr, tmp->chan->name); 02954 strcpy(tmp->chan->cdr->clid, qe->chan->cdr->clid); 02955 strcpy(tmp->chan->cdr->channel, qe->chan->cdr->channel); 02956 strcpy(tmp->chan->cdr->src, qe->chan->cdr->src); 02957 strcpy(tmp->chan->cdr->dst, qe->chan->exten); 02958 strcpy(tmp->chan->cdr->dcontext, qe->chan->context); 02959 strcpy(tmp->chan->cdr->lastapp, qe->chan->cdr->lastapp); 02960 strcpy(tmp->chan->cdr->lastdata, qe->chan->cdr->lastdata); 02961 tmp->chan->cdr->amaflags = qe->chan->cdr->amaflags; 02962 strcpy(tmp->chan->cdr->accountcode, qe->chan->cdr->accountcode); 02963 strcpy(tmp->chan->cdr->userfield, qe->chan->cdr->userfield); 02964 } 02965 02966 /* Place the call, but don't wait on the answer */ 02967 if ((res = ast_call(tmp->chan, location, 0))) { 02968 /* Again, keep going even if there's an error */ 02969 ast_debug(1, "ast call on peer returned %d\n", res); 02970 ast_verb(3, "Couldn't call %s\n", tmp->interface); 02971 ast_channel_unlock(tmp->chan); 02972 ast_channel_unlock(qe->chan); 02973 do_hang(tmp); 02974 (*busies)++; 02975 update_status(qe->parent, tmp->member, get_queue_member_status(tmp->member)); 02976 return 0; 02977 } else if (qe->parent->eventwhencalled) { 02978 char vars[2048]; 02979 02980 manager_event(EVENT_FLAG_AGENT, "AgentCalled", 02981 "Queue: %s\r\n" 02982 "AgentCalled: %s\r\n" 02983 "AgentName: %s\r\n" 02984 "ChannelCalling: %s\r\n" 02985 "DestinationChannel: %s\r\n" 02986 "CallerIDNum: %s\r\n" 02987 "CallerIDName: %s\r\n" 02988 "Context: %s\r\n" 02989 "Extension: %s\r\n" 02990 "Priority: %d\r\n" 02991 "Uniqueid: %s\r\n" 02992 "%s", 02993 qe->parent->name, tmp->interface, tmp->member->membername, qe->chan->name, tmp->chan->name, 02994 S_COR(tmp->chan->caller.id.number.valid, tmp->chan->caller.id.number.str, "unknown"), 02995 S_COR(tmp->chan->caller.id.name.valid, tmp->chan->caller.id.name.str, "unknown"), 02996 qe->chan->context, qe->chan->exten, qe->chan->priority, qe->chan->uniqueid, 02997 qe->parent->eventwhencalled == QUEUE_EVENT_VARIABLES ? vars2manager(qe->chan, vars, sizeof(vars)) : ""); 02998 ast_verb(3, "Called %s\n", tmp->interface); 02999 } 03000 ast_channel_unlock(tmp->chan); 03001 ast_channel_unlock(qe->chan); 03002 03003 update_status(qe->parent, tmp->member, get_queue_member_status(tmp->member)); 03004 return 1; 03005 }
| static int ring_one | ( | struct queue_ent * | qe, | |
| struct callattempt * | outgoing, | |||
| int * | busies | |||
| ) | [static] |
Place a call to a queue member.
Once metrics have been calculated for each member, this function is used to place a call to the appropriate member (or members). The low-level channel-handling and error detection is handled in ring_entry
| 1 | if a member was called successfully | |
| 0 | otherwise |
Definition at line 3033 of file app_queue.c.
References ast_debug, callattempt::chan, queue_ent::expire, find_best(), callattempt::interface, callattempt::metric, queue_ent::parent, callattempt::q_next, QUEUE_STRATEGY_RINGALL, ring_entry(), callattempt::stillgoing, and call_queue::strategy.
Referenced by try_calling(), and wait_for_answer().
03034 { 03035 int ret = 0; 03036 03037 while (ret == 0) { 03038 struct callattempt *best = find_best(outgoing); 03039 if (!best) { 03040 ast_debug(1, "Nobody left to try ringing in queue\n"); 03041 break; 03042 } 03043 if (qe->parent->strategy == QUEUE_STRATEGY_RINGALL) { 03044 struct callattempt *cur; 03045 /* Ring everyone who shares this best metric (for ringall) */ 03046 for (cur = outgoing; cur; cur = cur->q_next) { 03047 if (cur->stillgoing && !cur->chan && cur->metric <= best->metric) { 03048 ast_debug(1, "(Parallel) Trying '%s' with metric %d\n", cur->interface, cur->metric); 03049 ret |= ring_entry(qe, cur, busies); 03050 } 03051 } 03052 } else { 03053 /* Ring just the best channel */ 03054 ast_debug(1, "Trying '%s' with metric %d\n", best->interface, best->metric); 03055 ret = ring_entry(qe, best, busies); 03056 } 03057 03058 /* If we have timed out, break out */ 03059 if (qe->expire && (time(NULL) >= qe->expire)) { 03060 ast_debug(1, "Queue timed out while ringing members.\n"); 03061 ret = 0; 03062 break; 03063 } 03064 } 03065 03066 return ret; 03067 }
| static void rna | ( | int | rnatime, | |
| struct queue_ent * | qe, | |||
| char * | interface, | |||
| char * | membername, | |||
| int | pause | |||
| ) | [static] |
RNA == Ring No Answer. Common code that is executed when we try a queue member and they don't answer.
Definition at line 3191 of file app_queue.c.
References ast_indicate(), ast_moh_start(), ast_queue_log(), ast_verb, call_queue::autopause, queue_ent::chan, EVENT_FLAG_AGENT, call_queue::eventwhencalled, manager_event, queue_ent::moh, ast_channel::name, call_queue::name, queue_ent::parent, QUEUE_AUTOPAUSE_OFF, QUEUE_AUTOPAUSE_ON, QUEUE_EVENT_VARIABLES, queue_ent::ring_when_ringing, set_member_paused(), ast_channel::uniqueid, and vars2manager().
Referenced by wait_for_answer().
03192 { 03193 ast_verb(3, "Nobody picked up in %d ms\n", rnatime); 03194 03195 /* Stop ringing, and resume MOH if specified */ 03196 if (qe->ring_when_ringing) { 03197 ast_indicate(qe->chan, -1); 03198 ast_moh_start(qe->chan, qe->moh, NULL); 03199 } 03200 03201 if (qe->parent->eventwhencalled) { 03202 char vars[2048]; 03203 03204 manager_event(EVENT_FLAG_AGENT, "AgentRingNoAnswer", 03205 "Queue: %s\r\n" 03206 "Uniqueid: %s\r\n" 03207 "Channel: %s\r\n" 03208 "Member: %s\r\n" 03209 "MemberName: %s\r\n" 03210 "Ringtime: %d\r\n" 03211 "%s", 03212 qe->parent->name, 03213 qe->chan->uniqueid, 03214 qe->chan->name, 03215 interface, 03216 membername, 03217 rnatime, 03218 qe->parent->eventwhencalled == QUEUE_EVENT_VARIABLES ? vars2manager(qe->chan, vars, sizeof(vars)) : ""); 03219 } 03220 ast_queue_log(qe->parent->name, qe->chan->uniqueid, membername, "RINGNOANSWER", "%d", rnatime); 03221 if (qe->parent->autopause != QUEUE_AUTOPAUSE_OFF && pause) { 03222 if (qe->parent->autopause == QUEUE_AUTOPAUSE_ON) { 03223 if (!set_member_paused(qe->parent->name, interface, "Auto-Pause", 1)) { 03224 ast_verb(3, "Auto-Pausing Queue Member %s in queue %s since they failed to answer.\n", 03225 interface, qe->parent->name); 03226 } else { 03227 ast_verb(3, "Failed to pause Queue Member %s in queue %s!\n", interface, qe->parent->name); 03228 } 03229 } else { 03230 /* If queue autopause is mode all, just don't send any queue to stop. 03231 * the function will stop in all queues */ 03232 if (!set_member_paused("", interface, "Auto-Pause", 1)) { 03233 ast_verb(3, "Auto-Pausing Queue Member %s in all queues since they failed to answer on queue %s.\n", 03234 interface, qe->parent->name); 03235 } else { 03236 ast_verb(3, "Failed to pause Queue Member %s in all queues!\n", interface); 03237 } 03238 } 03239 } 03240 return; 03241 }
| static int rqm_exec | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) | [static] |
RemoveQueueMember application.
Definition at line 5414 of file app_queue.c.
References args, AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, ast_log(), ast_queue_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), LOG_NOTICE, LOG_WARNING, ast_channel::name, parse(), pbx_builtin_setvar_helper(), remove_from_queue(), RES_EXISTS, RES_NOSUCHQUEUE, RES_NOT_DYNAMIC, RES_OKAY, and ast_channel::uniqueid.
Referenced by load_module().
05415 { 05416 int res=-1; 05417 char *parse, *temppos = NULL; 05418 AST_DECLARE_APP_ARGS(args, 05419 AST_APP_ARG(queuename); 05420 AST_APP_ARG(interface); 05421 AST_APP_ARG(options); 05422 ); 05423 05424 05425 if (ast_strlen_zero(data)) { 05426 ast_log(LOG_WARNING, "RemoveQueueMember requires an argument (queuename[,interface[,options]])\n"); 05427 return -1; 05428 } 05429 05430 parse = ast_strdupa(data); 05431 05432 AST_STANDARD_APP_ARGS(args, parse); 05433 05434 if (ast_strlen_zero(args.interface)) { 05435 args.interface = ast_strdupa(chan->name); 05436 temppos = strrchr(args.interface, '-'); 05437 if (temppos) 05438 *temppos = '\0'; 05439 } 05440 05441 ast_debug(1, "queue: %s, member: %s\n", args.queuename, args.interface); 05442 05443 switch (remove_from_queue(args.queuename, args.interface)) { 05444 case RES_OKAY: 05445 ast_queue_log(args.queuename, chan->uniqueid, args.interface, "REMOVEMEMBER", "%s", ""); 05446 ast_log(LOG_NOTICE, "Removed interface '%s' from queue '%s'\n", args.interface, args.queuename); 05447 pbx_builtin_setvar_helper(chan, "RQMSTATUS", "REMOVED"); 05448 res = 0; 05449 break; 05450 case RES_EXISTS: 05451 ast_debug(1, "Unable to remove interface '%s' from queue '%s': Not there\n", args.interface, args.queuename); 05452 pbx_builtin_setvar_helper(chan, "RQMSTATUS", "NOTINQUEUE"); 05453 res = 0; 05454 break; 05455 case RES_NOSUCHQUEUE: 05456 ast_log(LOG_WARNING, "Unable to remove interface from queue '%s': No such queue\n", args.queuename); 05457 pbx_builtin_setvar_helper(chan, "RQMSTATUS", "NOSUCHQUEUE"); 05458 res = 0; 05459 break; 05460 case RES_NOT_DYNAMIC: 05461 ast_log(LOG_WARNING, "Unable to remove interface from queue '%s': '%s' is not a dynamic member\n", args.queuename, args.interface); 05462 pbx_builtin_setvar_helper(chan, "RQMSTATUS", "NOTDYNAMIC"); 05463 res = 0; 05464 break; 05465 } 05466 05467 return res; 05468 }
| static void rt_handle_member_record | ( | struct call_queue * | q, | |
| char * | interface, | |||
| const char * | rt_uniqueid, | |||
| const char * | membername, | |||
| const char * | penalty_str, | |||
| const char * | paused_str, | |||
| const char * | state_interface | |||
| ) | [static] |
Find rt member record to update otherwise create one.
Search for member in queue, if found update penalty/paused state, if no member exists create one flag it as a RT member and add to queue member list.
Definition at line 1910 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_link, ao2_ref, ast_copy_string(), ast_log(), ast_queue_log(), ast_strlen_zero(), create_queue_member(), member::dead, member::interface, LOG_WARNING, call_queue::membercount, call_queue::members, call_queue::name, member::paused, member::penalty, member::realtime, member::rt_uniqueid, S_OR, and member::state_interface.
Referenced by find_queue_by_name_rt(), and update_realtime_members().
01911 { 01912 struct member *m; 01913 struct ao2_iterator mem_iter; 01914 int penalty = 0; 01915 int paused = 0; 01916 int found = 0; 01917 01918 if (ast_strlen_zero(rt_uniqueid)) { 01919 ast_log(LOG_WARNING, "Realtime field uniqueid is empty for member %s\n", S_OR(membername, "NULL")); 01920 return; 01921 } 01922 01923 if (penalty_str) { 01924 penalty = atoi(penalty_str); 01925 if (penalty < 0) 01926 penalty = 0; 01927 } 01928 01929 if (paused_str) { 01930 paused = atoi(paused_str); 01931 if (paused < 0) 01932 paused = 0; 01933 } 01934 01935 /* Find member by realtime uniqueid and update */ 01936 mem_iter = ao2_iterator_init(q->members, 0); 01937 while ((m = ao2_iterator_next(&mem_iter))) { 01938 if (!strcasecmp(m->rt_uniqueid, rt_uniqueid)) { 01939 m->dead = 0; /* Do not delete this one. */ 01940 ast_copy_string(m->rt_uniqueid, rt_uniqueid, sizeof(m->rt_uniqueid)); 01941 if (paused_str) 01942 m->paused = paused; 01943 if (strcasecmp(state_interface, m->state_interface)) { 01944 ast_copy_string(m->state_interface, state_interface, sizeof(m->state_interface)); 01945 } 01946 m->penalty = penalty; 01947 found = 1; 01948 ao2_ref(m, -1); 01949 break; 01950 } 01951 ao2_ref(m, -1); 01952 } 01953 ao2_iterator_destroy(&mem_iter); 01954 01955 /* Create a new member */ 01956 if (!found) { 01957 if ((m = create_queue_member(interface, membername, penalty, paused, state_interface))) { 01958 m->dead = 0; 01959 m->realtime = 1; 01960 ast_copy_string(m->rt_uniqueid, rt_uniqueid, sizeof(m->rt_uniqueid)); 01961 ast_queue_log(q->name, "REALTIME", m->interface, "ADDMEMBER", "%s", ""); 01962 ao2_link(q->members, m); 01963 ao2_ref(m, -1); 01964 m = NULL; 01965 q->membercount++; 01966 } 01967 } 01968 }
| static int say_periodic_announcement | ( | struct queue_ent * | qe, | |
| int | ringing | |||
| ) | [static] |
Playback announcement to queued members if peroid has elapsed.
Definition at line 3118 of file app_queue.c.
References AST_CONTROL_RINGING, ast_indicate(), ast_moh_start(), ast_moh_stop(), ast_random(), ast_str_buffer(), ast_str_strlen(), ast_verb, queue_ent::chan, queue_ent::last_periodic_announce_sound, queue_ent::last_periodic_announce_time, queue_ent::moh, call_queue::numperiodicannounce, queue_ent::parent, call_queue::periodicannouncefrequency, play_file(), call_queue::randomperiodicannounce, call_queue::relativeperiodicannounce, call_queue::sound_periodicannounce, and valid_exit().
Referenced by queue_exec(), and wait_our_turn().
03119 { 03120 int res = 0; 03121 time_t now; 03122 03123 /* Get the current time */ 03124 time(&now); 03125 03126 /* Check to see if it is time to announce */ 03127 if ((now - qe->last_periodic_announce_time) < qe->parent->periodicannouncefrequency) 03128 return 0; 03129 03130 /* Stop the music on hold so we can play our own file */ 03131 if (ringing) 03132 ast_indicate(qe->chan,-1); 03133 else 03134 ast_moh_stop(qe->chan); 03135 03136 ast_verb(3, "Playing periodic announcement\n"); 03137 03138 if (qe->parent->randomperiodicannounce && qe->parent->numperiodicannounce) { 03139 qe->last_periodic_announce_sound = ((unsigned long) ast_random()) % qe->parent->numperiodicannounce; 03140 } else if (qe->last_periodic_announce_sound >= qe->parent->numperiodicannounce || 03141 ast_str_strlen(qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound]) == 0) { 03142 qe->last_periodic_announce_sound = 0; 03143 } 03144 03145 /* play the announcement */ 03146 res = play_file(qe->chan, ast_str_buffer(qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound])); 03147 03148 if (res > 0 && !valid_exit(qe, res)) 03149 res = 0; 03150 03151 /* Resume Music on Hold if the caller is going to stay in the queue */ 03152 if (!res) { 03153 if (ringing) 03154 ast_indicate(qe->chan, AST_CONTROL_RINGING); 03155 else 03156 ast_moh_start(qe->chan, qe->moh, NULL); 03157 } 03158 03159 /* update last_periodic_announce_time */ 03160 if (qe->parent->relativeperiodicannounce) 03161 time(&qe->last_periodic_announce_time); 03162 else 03163 qe->last_periodic_announce_time = now; 03164 03165 /* Update the current periodic announcement to the next announcement */ 03166 if (!qe->parent->randomperiodicannounce) { 03167 qe->last_periodic_announce_sound++; 03168 } 03169 03170 return res; 03171 }
| static int say_position | ( | struct queue_ent * | qe, | |
| int | ringing | |||
| ) | [static] |
Definition at line 2426 of file app_queue.c.
References call_queue::announcefrequency, call_queue::announceholdtime, ANNOUNCEHOLDTIME_ONCE, call_queue::announceposition, ANNOUNCEPOSITION_LIMIT, ANNOUNCEPOSITION_MORE_THAN, ANNOUNCEPOSITION_YES, call_queue::announcepositionlimit, AST_CONTROL_RINGING, AST_DIGIT_ANY, ast_indicate(), ast_moh_start(), ast_moh_stop(), ast_say_number(), ast_verb, queue_ent::chan, call_queue::holdtime, ast_channel::language, queue_ent::last_pos, queue_ent::last_pos_said, call_queue::minannouncefrequency, queue_ent::moh, ast_channel::name, call_queue::name, queue_ent::parent, play_file(), queue_ent::pos, call_queue::queue_quantity1, call_queue::queue_quantity2, call_queue::roundingseconds, call_queue::sound_calls, call_queue::sound_holdtime, call_queue::sound_minute, call_queue::sound_minutes, call_queue::sound_next, call_queue::sound_seconds, call_queue::sound_thanks, call_queue::sound_thereare, queue_ent::start, and valid_exit().
Referenced by queue_exec(), and wait_our_turn().
02427 { 02428 int res = 0, avgholdmins, avgholdsecs, announceposition = 0; 02429 int say_thanks = 1; 02430 time_t now; 02431 02432 /* Let minannouncefrequency seconds pass between the start of each position announcement */ 02433 time(&now); 02434 if ((now - qe->last_pos) < qe->parent->minannouncefrequency) 02435 return 0; 02436 02437 /* If either our position has changed, or we are over the freq timer, say position */ 02438 if ((qe->last_pos_said == qe->pos) && ((now - qe->last_pos) < qe->parent->announcefrequency)) 02439 return 0; 02440 02441 if (ringing) { 02442 ast_indicate(qe->chan,-1); 02443 } else { 02444 ast_moh_stop(qe->chan); 02445 } 02446 02447 if (qe->parent->announceposition == ANNOUNCEPOSITION_YES || 02448 qe->parent->announceposition == ANNOUNCEPOSITION_MORE_THAN || 02449 (qe->parent->announceposition == ANNOUNCEPOSITION_LIMIT && 02450 qe->pos <= qe->parent->announcepositionlimit)) 02451 announceposition = 1; 02452 02453 02454 if (announceposition == 1) { 02455 /* Say we're next, if we are */ 02456 if (qe->pos == 1) { 02457 res = play_file(qe->chan, qe->parent->sound_next); 02458 if (res) 02459 goto playout; 02460 else 02461 goto posout; 02462 } else { 02463 if (qe->parent->announceposition == ANNOUNCEPOSITION_MORE_THAN && qe->pos > qe->parent->announcepositionlimit){ 02464 /* More than Case*/ 02465 res = play_file(qe->chan, qe->parent->queue_quantity1); 02466 if (res) 02467 goto playout; 02468 res = ast_say_number(qe->chan, qe->parent->announcepositionlimit, AST_DIGIT_ANY, qe->chan->language, NULL); /* Needs gender */ 02469 if (res) 02470 goto playout; 02471 } else { 02472 /* Normal Case */ 02473 res = play_file(qe->chan, qe->parent->sound_thereare); 02474 if (res) 02475 goto playout; 02476 res = ast_say_number(qe->chan, qe->pos, AST_DIGIT_ANY, qe->chan->language, NULL); /* Needs gender */ 02477 if (res) 02478 goto playout; 02479 } 02480 if (qe->parent->announceposition == ANNOUNCEPOSITION_MORE_THAN && qe->pos > qe->parent->announcepositionlimit){ 02481 /* More than Case*/ 02482 res = play_file(qe->chan, qe->parent->queue_quantity2); 02483 if (res) 02484 goto playout; 02485 } else { 02486 res = play_file(qe->chan, qe->parent->sound_calls); 02487 if (res) 02488 goto playout; 02489 } 02490 } 02491 } 02492 /* Round hold time to nearest minute */ 02493 avgholdmins = abs(((qe->parent->holdtime + 30) - (now - qe->start)) / 60); 02494 02495 /* If they have specified a rounding then round the seconds as well */ 02496 if (qe->parent->roundingseconds) { 02497 avgholdsecs = (abs(((qe->parent->holdtime + 30) - (now - qe->start))) - 60 * avgholdmins) / qe->parent->roundingseconds; 02498 avgholdsecs *= qe->parent->roundingseconds; 02499 } else { 02500 avgholdsecs = 0; 02501 } 02502 02503 ast_verb(3, "Hold time for %s is %d minute(s) %d seconds\n", qe->parent->name, avgholdmins, avgholdsecs); 02504 02505 /* If the hold time is >1 min, if it's enabled, and if it's not 02506 supposed to be only once and we have already said it, say it */ 02507 if ((avgholdmins+avgholdsecs) > 0 && qe->parent->announceholdtime && 02508 ((qe->parent->announceholdtime == ANNOUNCEHOLDTIME_ONCE && !qe->last_pos) || 02509 !(qe->parent->announceholdtime == ANNOUNCEHOLDTIME_ONCE))) { 02510 res = play_file(qe->chan, qe->parent->sound_holdtime); 02511 if (res) 02512 goto playout; 02513 02514 if (avgholdmins >= 1) { 02515 res = ast_say_number(qe->chan, avgholdmins, AST_DIGIT_ANY, qe->chan->language, NULL); 02516 if (res) 02517 goto playout; 02518 02519 if (avgholdmins == 1) { 02520 res = play_file(qe->chan, qe->parent->sound_minute); 02521 if (res) 02522 goto playout; 02523 } else { 02524 res = play_file(qe->chan, qe->parent->sound_minutes); 02525 if (res) 02526 goto playout; 02527 } 02528 } 02529 if (avgholdsecs >= 1) { 02530 res = ast_say_number(qe->chan, avgholdsecs, AST_DIGIT_ANY, qe->chan->language, NULL); 02531 if (res) 02532 goto playout; 02533 02534 res = play_file(qe->chan, qe->parent->sound_seconds); 02535 if (res) 02536 goto playout; 02537 } 02538 } else if (qe->parent->announceholdtime && !qe->parent->announceposition) { 02539 say_thanks = 0; 02540 } 02541 02542 posout: 02543 if (qe->parent->announceposition) { 02544 ast_verb(3, "Told %s in %s their queue position (which was %d)\n", 02545 qe->chan->name, qe->parent->name, qe->pos); 02546 } 02547 if (say_thanks) { 02548 res = play_file(qe->chan, qe->parent->sound_thanks); 02549 } 02550 playout: 02551 02552 if ((res > 0 && !valid_exit(qe, res))) 02553 res = 0; 02554 02555 /* Set our last_pos indicators */ 02556 qe->last_pos = now; 02557 qe->last_pos_said = qe->pos; 02558 02559 /* Don't restart music on hold if we're about to exit the caller from the queue */ 02560 if (!res) { 02561 if (ringing) { 02562 ast_indicate(qe->chan, AST_CONTROL_RINGING); 02563 } else { 02564 ast_moh_start(qe->chan, qe->moh, NULL); 02565 } 02566 } 02567 return res; 02568 }
| static void send_agent_complete | ( | const struct queue_ent * | qe, | |
| const char * | queuename, | |||
| const struct ast_channel * | peer, | |||
| const struct member * | member, | |||
| time_t | callstart, | |||
| char * | vars, | |||
| size_t | vars_len, | |||
| enum agent_complete_reason | rsn | |||
| ) | [static] |
Send out AMI message with member call completion status information.
Definition at line 3948 of file app_queue.c.
References AGENT, CALLER, queue_ent::chan, EVENT_FLAG_AGENT, call_queue::eventwhencalled, member::interface, manager_event, member::membername, ast_channel::name, queue_ent::parent, QUEUE_EVENT_VARIABLES, queue_ent::start, TRANSFER, ast_channel::uniqueid, and vars2manager().
Referenced by try_calling().
03951 { 03952 const char *reason = NULL; /* silence dumb compilers */ 03953 03954 if (!qe->parent->eventwhencalled) 03955 return; 03956 03957 switch (rsn) { 03958 case CALLER: 03959 reason = "caller"; 03960 break; 03961 case AGENT: 03962 reason = "agent"; 03963 break; 03964 case TRANSFER: 03965 reason = "transfer"; 03966 break; 03967 } 03968 03969 manager_event(EVENT_FLAG_AGENT, "AgentComplete", 03970 "Queue: %s\r\n" 03971 "Uniqueid: %s\r\n" 03972 "Channel: %s\r\n" 03973 "Member: %s\r\n" 03974 "MemberName: %s\r\n" 03975 "HoldTime: %ld\r\n" 03976 "TalkTime: %ld\r\n" 03977 "Reason: %s\r\n" 03978 "%s", 03979 queuename, qe->chan->uniqueid, peer->name, member->interface, member->membername, 03980 (long)(callstart - qe->start), (long)(time(NULL) - callstart), reason, 03981 qe->parent->eventwhencalled == QUEUE_EVENT_VARIABLES ? vars2manager(qe->chan, vars, vars_len) : ""); 03982 }
| static int set_member_paused | ( | const char * | queuename, | |
| const char * | interface, | |||
| const char * | reason, | |||
| int | paused | |||
| ) | [static] |
Definition at line 5087 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock, ao2_ref, ao2_t_iterator_next, ao2_unlock, ast_debug, ast_log(), ast_queue_log(), ast_strlen_zero(), dump_queue_members(), EVENT_FLAG_AGENT, member::interface, interface_exists(), LOG_WARNING, manager_event, member::membername, call_queue::name, member::paused, queue_t_unref, queues, member::realtime, RESULT_FAILURE, RESULT_SUCCESS, S_OR, and update_realtime_member_field().
Referenced by handle_queue_pause_member(), manager_pause_queue_member(), pqm_exec(), rna(), and upqm_exec().
05088 { 05089 int found = 0; 05090 struct call_queue *q; 05091 struct member *mem; 05092 struct ao2_iterator queue_iter; 05093 int failed; 05094 05095 /* Special event for when all queues are paused - individual events still generated */ 05096 /* XXX In all other cases, we use the membername, but since this affects all queues, we cannot */ 05097 if (ast_strlen_zero(queuename)) 05098 ast_queue_log("NONE", "NONE", interface, (paused ? "PAUSEALL" : "UNPAUSEALL"), "%s", ""); 05099 05100 queue_iter = ao2_iterator_init(queues, 0); 05101 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate over queues"))) { 05102 ao2_lock(q); 05103 if (ast_strlen_zero(queuename) || !strcasecmp(q->name, queuename)) { 05104 if ((mem = interface_exists(q, interface))) { 05105 if (mem->paused == paused) { 05106 ast_debug(1, "%spausing already-%spaused queue member %s:%s\n", (paused ? "" : "un"), (paused ? "" : "un"), q->name, interface); 05107 } 05108 05109 failed = 0; 05110 if (mem->realtime) { 05111 failed = update_realtime_member_field(mem, q->name, "paused", paused ? "1" : "0"); 05112 } 05113 05114 if (failed) { 05115 ast_log(LOG_WARNING, "Failed %spausing realtime queue member %s:%s\n", (paused ? "" : "un"), q->name, interface); 05116 ao2_ref(mem, -1); 05117 ao2_unlock(q); 05118 queue_t_unref(q, "Done with iterator"); 05119 continue; 05120 } 05121 found++; 05122 mem->paused = paused; 05123 05124 if (queue_persistent_members) 05125 dump_queue_members(q); 05126 05127 ast_queue_log(q->name, "NONE", mem->membername, (paused ? "PAUSE" : "UNPAUSE"), "%s", S_OR(reason, "")); 05128 05129 if (!ast_strlen_zero(reason)) { 05130 manager_event(EVENT_FLAG_AGENT, "QueueMemberPaused", 05131 "Queue: %s\r\n" 05132 "Location: %s\r\n" 05133 "MemberName: %s\r\n" 05134 "Paused: %d\r\n" 05135 "Reason: %s\r\n", 05136 q->name, mem->interface, mem->membername, paused, reason); 05137 } else { 05138 manager_event(EVENT_FLAG_AGENT, "QueueMemberPaused", 05139 "Queue: %s\r\n" 05140 "Location: %s\r\n" 05141 "MemberName: %s\r\n" 05142 "Paused: %d\r\n", 05143 q->name, mem->interface, mem->membername, paused); 05144 } 05145 ao2_ref(mem, -1); 05146 } 05147 } 05148 05149 if (!ast_strlen_zero(queuename) && !strcasecmp(queuename, q->name)) { 05150 ao2_unlock(q); 05151 queue_t_unref(q, "Done with iterator"); 05152 break; 05153 } 05154 05155 ao2_unlock(q); 05156 queue_t_unref(q, "Done with iterator"); 05157 } 05158 ao2_iterator_destroy(&queue_iter); 05159 05160 return found ? RESULT_SUCCESS : RESULT_FAILURE; 05161 }
| static int set_member_penalty | ( | const char * | queuename, | |
| const char * | interface, | |||
| int | penalty | |||
| ) | [static] |
Definition at line 5164 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock, ao2_ref, ao2_t_iterator_next, ao2_unlock, ast_log(), ast_queue_log(), ast_strlen_zero(), EVENT_FLAG_AGENT, member::interface, interface_exists(), LOG_ERROR, manager_event, call_queue::name, member::penalty, queue_t_unref, queues, RESULT_FAILURE, and RESULT_SUCCESS.
Referenced by handle_queue_set_member_penalty(), manager_queue_member_penalty(), and queue_function_memberpenalty_write().
05165 { 05166 int foundinterface = 0, foundqueue = 0; 05167 struct call_queue *q; 05168 struct member *mem; 05169 struct ao2_iterator queue_iter; 05170 05171 if (penalty < 0) { 05172 ast_log(LOG_ERROR, "Invalid penalty (%d)\n", penalty); 05173 return RESULT_FAILURE; 05174 } 05175 05176 queue_iter = ao2_iterator_init(queues, 0); 05177 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) { 05178 ao2_lock(q); 05179 if (ast_strlen_zero(queuename) || !strcasecmp(q->name, queuename)) { 05180 foundqueue++; 05181 if ((mem = interface_exists(q, interface))) { 05182 foundinterface++; 05183 mem->penalty = penalty; 05184 05185 ast_queue_log(q->name, "NONE", interface, "PENALTY", "%d", penalty); 05186 manager_event(EVENT_FLAG_AGENT, "QueueMemberPenalty", 05187 "Queue: %s\r\n" 05188 "Location: %s\r\n" 05189 "Penalty: %d\r\n", 05190 q->name, mem->interface, penalty); 05191 ao2_ref(mem, -1); 05192 } 05193 } 05194 ao2_unlock(q); 05195 queue_t_unref(q, "Done with iterator"); 05196 } 05197 ao2_iterator_destroy(&queue_iter); 05198 05199 if (foundinterface) { 05200 return RESULT_SUCCESS; 05201 } else if (!foundqueue) { 05202 ast_log (LOG_ERROR, "Invalid queuename\n"); 05203 } else { 05204 ast_log (LOG_ERROR, "Invalid interface\n"); 05205 } 05206 05207 return RESULT_FAILURE; 05208 }
| static void set_queue_result | ( | struct ast_channel * | chan, | |
| enum queue_result | res | |||
| ) | [static] |
sets the QUEUESTATUS channel variable
Definition at line 1037 of file app_queue.c.
References ARRAY_LEN, pbx_builtin_setvar_helper(), queue_results, and text.
Referenced by queue_exec().
01038 { 01039 int i; 01040 01041 for (i = 0; i < ARRAY_LEN(queue_results); i++) { 01042 if (queue_results[i].id == res) { 01043 pbx_builtin_setvar_helper(chan, "QUEUESTATUS", queue_results[i].text); 01044 return; 01045 } 01046 } 01047 }
| static void set_queue_variables | ( | struct call_queue * | q, | |
| struct ast_channel * | chan | |||
| ) | [static] |
Set variables of queue.
Definition at line 1132 of file app_queue.c.
References call_queue::callsabandoned, call_queue::callscompleted, call_queue::callscompletedinsl, call_queue::count, call_queue::holdtime, int2strat(), call_queue::maxlen, call_queue::name, pbx_builtin_setvar_multiple(), call_queue::servicelevel, call_queue::setqueuevar, call_queue::strategy, and call_queue::talktime.
Referenced by end_bridge_callback(), queue_exec(), record_abandoned(), and try_calling().
01133 { 01134 char interfacevar[256]=""; 01135 float sl = 0; 01136 01137 if (q->setqueuevar) { 01138 sl = 0; 01139 if (q->callscompleted > 0) 01140 sl = 100 * ((float) q->callscompletedinsl / (float) q->callscompleted); 01141 01142 snprintf(interfacevar, sizeof(interfacevar), 01143 "QUEUENAME=%s,QUEUEMAX=%d,QUEUESTRATEGY=%s,QUEUECALLS=%d,QUEUEHOLDTIME=%d,QUEUETALKTIME=%d,QUEUECOMPLETED=%d,QUEUEABANDONED=%d,QUEUESRVLEVEL=%d,QUEUESRVLEVELPERF=%2.1f", 01144 q->name, q->maxlen, int2strat(q->strategy), q->count, q->holdtime, q->talktime, q->callscompleted, q->callsabandoned, q->servicelevel, sl); 01145 01146 pbx_builtin_setvar_multiple(chan, interfacevar); 01147 } 01148 }
| static struct ast_datastore* setup_transfer_datastore | ( | struct queue_ent * | qe, | |
| struct member * | member, | |||
| time_t | starttime, | |||
| int | callcompletedinsl | |||
| ) | [static, read] |
create a datastore for storing relevant info to log attended transfers in the queue_log
Definition at line 4052 of file app_queue.c.
References ast_calloc, ast_channel_datastore_add(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc, ast_log(), queue_transfer_ds::callcompletedinsl, queue_ent::chan, ast_datastore::data, LOG_WARNING, queue_transfer_ds::member, queue_transfer_ds::qe, queue_transfer_info, and queue_transfer_ds::starttime.
Referenced by try_calling().
04053 { 04054 struct ast_datastore *ds; 04055 struct queue_transfer_ds *qtds = ast_calloc(1, sizeof(*qtds)); 04056 04057 if (!qtds) { 04058 ast_log(LOG_WARNING, "Memory allocation error!\n"); 04059 return NULL; 04060 } 04061 04062 ast_channel_lock(qe->chan); 04063 if (!(ds = ast_datastore_alloc(&queue_transfer_info, NULL))) { 04064 ast_channel_unlock(qe->chan); 04065 ast_log(LOG_WARNING, "Unable to create transfer datastore. queue_log will not show attended transfer\n"); 04066 return NULL; 04067 } 04068 04069 qtds->qe = qe; 04070 /* This member is refcounted in try_calling, so no need to add it here, too */ 04071 qtds->member = member; 04072 qtds->starttime = starttime; 04073 qtds->callcompletedinsl = callcompletedinsl; 04074 ds->data = qtds; 04075 ast_channel_datastore_add(qe->chan, ds); 04076 ast_channel_unlock(qe->chan); 04077 return ds; 04078 }
| static int store_next_lin | ( | struct queue_ent * | qe, | |
| struct callattempt * | outgoing | |||
| ) | [static] |
Search for best metric and add to Linear queue.
Definition at line 3094 of file app_queue.c.
References ast_debug, find_best(), callattempt::interface, queue_ent::linpos, queue_ent::linwrapped, and callattempt::metric.
Referenced by try_calling().
03095 { 03096 struct callattempt *best = find_best(outgoing); 03097 03098 if (best) { 03099 /* Ring just the best channel */ 03100 ast_debug(1, "Next is '%s' with metric %d\n", best->interface, best->metric); 03101 qe->linpos = best->metric % 1000; 03102 } else { 03103 /* Just increment rrpos */ 03104 if (qe->linwrapped) { 03105 /* No more channels, start over */ 03106 qe->linpos = 0; 03107 } else { 03108 /* Prioritize next entry */ 03109 qe->linpos++; 03110 } 03111 } 03112 qe->linwrapped = 0; 03113 03114 return 0; 03115 }
| static int store_next_rr | ( | struct queue_ent * | qe, | |
| struct callattempt * | outgoing | |||
| ) | [static] |
Search for best metric and add to Round Robbin queue.
Definition at line 3070 of file app_queue.c.
References ast_debug, find_best(), callattempt::interface, callattempt::metric, queue_ent::parent, call_queue::rrpos, and call_queue::wrapped.
Referenced by try_calling().
03071 { 03072 struct callattempt *best = find_best(outgoing); 03073 03074 if (best) { 03075 /* Ring just the best channel */ 03076 ast_debug(1, "Next is '%s' with metric %d\n", best->interface, best->metric); 03077 qe->parent->rrpos = best->metric % 1000; 03078 } else { 03079 /* Just increment rrpos */ 03080 if (qe->parent->wrapped) { 03081 /* No more channels, start over */ 03082 qe->parent->rrpos = 0; 03083 } else { 03084 /* Prioritize next entry */ 03085 qe->parent->rrpos++; 03086 } 03087 } 03088 qe->parent->wrapped = 0; 03089 03090 return 0; 03091 }
| static int strat2int | ( | const char * | strategy | ) | [static] |
Definition at line 1061 of file app_queue.c.
References ARRAY_LEN, and strategies.
Referenced by find_queue_by_name_rt(), queue_set_param(), and reload_single_queue().
01062 { 01063 int x; 01064 01065 for (x = 0; x < ARRAY_LEN(strategies); x++) { 01066 if (!strcasecmp(strategy, strategies[x].name)) 01067 return strategies[x].strategy; 01068 } 01069 01070 return -1; 01071 }
| static int try_calling | ( | struct queue_ent * | qe, | |
| const char * | options, | |||
| char * | announceoverride, | |||
| const char * | url, | |||
| int * | tries, | |||
| int * | noption, | |||
| const char * | agi, | |||
| const char * | macro, | |||
| const char * | gosub, | |||
| int | ringing | |||
| ) | [static] |
A large function which calls members, updates statistics, and bridges the caller and a member.
Here is the process of this function 1. Process any options passed to the Queue() application. Options here mean the third argument to Queue() 2. Iterate trough the members of the queue, creating a callattempt corresponding to each member. During this iteration, we also check the dialed_interfaces datastore to see if we have already attempted calling this member. If we have, we do not create a callattempt. This is in place to prevent call forwarding loops. Also during each iteration, we call calc_metric to determine which members should be rung when. 3. Call ring_one to place a call to the appropriate member(s) 4. Call wait_for_answer to wait for an answer. If no one answers, return. 5. Take care of any holdtime announcements, member delays, or other options which occur after a call has been answered. 6. Start the monitor or mixmonitor if the option is set 7. Remove the caller from the queue to allow other callers to advance 8. Bridge the call. 9. Do any post processing after the call has disconnected.
| [in] | qe | the queue_ent structure which corresponds to the caller attempting to reach members |
| [in] | options | the options passed as the third parameter to the Queue() application |
| [in] | announceoverride | filename to play to user when waiting |
| [in] | url | the url passed as the fourth parameter to the Queue() application |
| [in,out] | tries | the number of times we have tried calling queue members |
| [out] | noption | set if the call to Queue() has the 'n' option set. |
| [in] | agi | the agi passed as the fifth parameter to the Queue() application |
| [in] | macro | the macro passed as the sixth parameter to the Queue() application |
| [in] | gosub | the gosub passed as the seventh parameter to the Queue() application |
| [in] | ringing | 1 if the 'r' option is set, otherwise 0 |
Definition at line 4134 of file app_queue.c.
References ast_channel::_softhangup, ast_channel::_state, AGENT, queue_ent::announce, ao2_alloc, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, asprintf, ast_autoservice_start(), ast_autoservice_stop(), ast_bridge_call(), ast_calloc, ast_cdr_failed(), AST_CDR_FLAG_LOCKED, AST_CDR_FLAG_POST_DISABLED, ast_cdr_isset_unanswered(), ast_cdr_setdestchan(), ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_lock, ast_channel_make_compatible(), ast_channel_sendurl(), ast_channel_setoption(), ast_channel_supports_html(), ast_channel_unlock, ast_check_hangup(), ast_clear_flag, ast_copy_string(), ast_datastore_alloc, ast_datastore_free(), ast_debug, AST_DIGIT_ANY, AST_FEATURE_AUTOMIXMON, AST_FEATURE_AUTOMON, AST_FEATURE_DISCONNECT, AST_FEATURE_NO_H_EXTEN, AST_FEATURE_PARKCALL, AST_FEATURE_REDIRECT, AST_FLAG_ANSWERED_ELSEWHERE, ast_free, ast_hangup(), ast_indicate(), AST_LIST_HEAD, AST_LIST_HEAD_INIT, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), AST_MAX_CONTEXT, AST_MAX_EXTENSION, ast_moh_stop(), ast_monitor_setjoinfiles(), ast_monitor_start(), AST_OPTION_TONE_VERIFY, ast_party_connected_line_copy(), ast_pbx_run_args(), ast_queue_log(), ast_random(), ast_safe_sleep(), ast_say_number(), ast_set_flag, AST_STATE_UP, ast_strdupa, ast_strlen_zero(), ast_test_flag, attended_transfer_occurred(), calc_metric(), callattempt_free(), CALLER, member::calls, queue_ent::cancel_answered_elsewhere, ast_channel::cdr, queue_end_bridge::chan, callattempt::chan, queue_ent::chan, ast_channel::connected, callattempt::connected, ast_channel::context, ast_datastore::data, DATASTORE_INHERIT_FOREVER, di, dialed_interface_info, ast_cdr::dstchannel, member::dynamic, end_bridge_callback(), ast_bridge_config::end_bridge_callback, ast_bridge_config::end_bridge_callback_data, end_bridge_callback_data_fixup(), ast_bridge_config::end_bridge_callback_data_fixup, errno, EVENT_FLAG_AGENT, call_queue::eventwhencalled, queue_ent::expire, ast_channel::exten, ast_bridge_config::features_callee, ast_bridge_config::features_caller, queue_ent::handled, hangupcalls(), ast_datastore::inheritance, callattempt::interface, ast_dialed_interface::interface, member::interface, ast_channel::language, member::lastcall, callattempt::lastcall, member::lastqueue, callattempt::lastqueue, leave_queue(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, manager_event, callattempt::member, call_queue::membercount, call_queue::memberdelay, call_queue::membergosub, call_queue::membermacro, member::membername, call_queue::members, call_queue::monfmt, call_queue::montype, call_queue::name, ast_channel::name, ast_pbx_args::no_hangup_chan, queue_ent::opos, queue_ent::parent, pbx_builtin_getvar_helper(), pbx_builtin_setvar_multiple(), pbx_exec(), pbx_findapp(), pbx_substitute_variables_helper(), member::penalty, queue_ent::pending, play_file(), queue_ent::pos, ast_channel::priority, queue_end_bridge::q, callattempt::q_next, QUEUE_EVENT_VARIABLES, QUEUE_STRATEGY_LINEAR, QUEUE_STRATEGY_RRMEMORY, queue_t_ref, queue_transfer_info, queues, member::realtime, recalc_holdtime(), record_abandoned(), call_queue::reportholdtime, ring_one(), send_agent_complete(), call_queue::servicelevel, set_queue_variables(), call_queue::setinterfacevar, call_queue::setqueueentryvar, setup_transfer_datastore(), call_queue::sound_callerannounce, call_queue::sound_minutes, call_queue::sound_reporthold, call_queue::sound_seconds, queue_ent::start, callattempt::stillgoing, store_next_lin(), store_next_rr(), call_queue::strategy, ast_channel::tech, call_queue::timeout, TIMEOUT_PRIORITY_APP, call_queue::timeoutpriority, TRANSFER, ast_channel_tech::type, ast_cdr::uniqueid, ast_channel::uniqueid, update_connectedline(), update_queue(), vars2manager(), wait_for_answer(), X_REC_IN, and X_REC_OUT.
Referenced by queue_exec().
04135 { 04136 struct member *cur; 04137 struct callattempt *outgoing = NULL; /* the list of calls we are building */ 04138 int to, orig; 04139 char oldexten[AST_MAX_EXTENSION]=""; 04140 char oldcontext[AST_MAX_CONTEXT]=""; 04141 char queuename[256]=""; 04142 char interfacevar[256]=""; 04143 struct ast_channel *peer; 04144 struct ast_channel *which; 04145 struct callattempt *lpeer; 04146 struct member *member; 04147 struct ast_app *application; 04148 int res = 0, bridge = 0; 04149 int numbusies = 0; 04150 int x=0; 04151 char *announce = NULL; 04152 char digit = 0; 04153 time_t callstart; 04154 time_t now = time(NULL); 04155 struct ast_bridge_config bridge_config; 04156 char nondataquality = 1; 04157 char *agiexec = NULL; 04158 char *macroexec = NULL; 04159 char *gosubexec = NULL; 04160 int ret = 0; 04161 const char *monitorfilename; 04162 const char *monitor_exec; 04163 const char *monitor_options; 04164 char tmpid[256], tmpid2[256]; 04165 char meid[1024], meid2[1024]; 04166 char mixmonargs[1512]; 04167 struct ast_app *mixmonapp = NULL; 04168 char *p; 04169 char vars[2048]; 04170 int forwardsallowed = 1; 04171 int update_connectedline = 1; 04172 int callcompletedinsl; 04173 struct ao2_iterator memi; 04174 struct ast_datastore *datastore, *transfer_ds; 04175 struct queue_end_bridge *queue_end_bridge = NULL; 04176 const int need_weight = use_weight; 04177 04178 ast_channel_lock(qe->chan); 04179 datastore = ast_channel_datastore_find(qe->chan, &dialed_interface_info, NULL); 04180 ast_channel_unlock(qe->chan); 04181 04182 memset(&bridge_config, 0, sizeof(bridge_config)); 04183 tmpid[0] = 0; 04184 meid[0] = 0; 04185 time(&now); 04186 04187 /* If we've already exceeded our timeout, then just stop 04188 * This should be extremely rare. queue_exec will take care 04189 * of removing the caller and reporting the timeout as the reason. 04190 */ 04191 if (qe->expire && now >= qe->expire) { 04192 res = 0; 04193 goto out; 04194 } 04195 04196 for (; options && *options; options++) 04197 switch (*options) { 04198 case 't': 04199 ast_set_flag(&(bridge_config.features_callee), AST_FEATURE_REDIRECT); 04200 break; 04201 case 'T': 04202 ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_REDIRECT); 04203 break; 04204 case 'w': 04205 ast_set_flag(&(bridge_config.features_callee), AST_FEATURE_AUTOMON); 04206 break; 04207 case 'W': 04208 ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_AUTOMON); 04209 break; 04210 case 'c': 04211 ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_NO_H_EXTEN); 04212 break; 04213 case 'd': 04214 nondataquality = 0; 04215 break; 04216 case 'h': 04217 ast_set_flag(&(bridge_config.features_callee), AST_FEATURE_DISCONNECT); 04218 break; 04219 case 'H': 04220 ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT); 04221 break; 04222 case 'k': 04223 ast_set_flag(&(bridge_config.features_callee), AST_FEATURE_PARKCALL); 04224 break; 04225 case 'K': 04226 ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_PARKCALL); 04227 break; 04228 case 'n': 04229 if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY || qe->parent->strategy == QUEUE_STRATEGY_LINEAR) 04230 (*tries)++; 04231 else 04232 *tries = qe->parent->membercount; 04233 *noption = 1; 04234 break; 04235 case 'i': 04236 forwardsallowed = 0; 04237 break; 04238 case 'I': 04239 update_connectedline = 0; 04240 break; 04241 case 'x': 04242 ast_set_flag(&(bridge_config.features_callee), AST_FEATURE_AUTOMIXMON); 04243 break; 04244 case 'X': 04245 ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_AUTOMIXMON); 04246 break; 04247 case 'C': 04248 qe->cancel_answered_elsewhere = 1; 04249 break; 04250 } 04251 04252 /* if the calling channel has the ANSWERED_ELSEWHERE flag set, make sure this is inherited. 04253 (this is mainly to support chan_local) 04254 */ 04255 if (ast_test_flag(qe->chan, AST_FLAG_ANSWERED_ELSEWHERE)) { 04256 qe->cancel_answered_elsewhere = 1; 04257 } 04258 04259 /* Hold the lock while we setup the outgoing calls */ 04260 if (need_weight) 04261 ao2_lock(queues); 04262 ao2_lock(qe->parent); 04263 ast_debug(1, "%s is trying to call a queue member.\n", 04264 qe->chan->name); 04265 ast_copy_string(queuename, qe->parent->name, sizeof(queuename)); 04266 if (!ast_strlen_zero(qe->announce)) 04267 announce = qe->announce; 04268 if (!ast_strlen_zero(announceoverride)) 04269 announce = announceoverride; 04270 04271 memi = ao2_iterator_init(qe->parent->members, 0); 04272 while ((cur = ao2_iterator_next(&memi))) { 04273 struct callattempt *tmp = ast_calloc(1, sizeof(*tmp)); 04274 struct ast_dialed_interface *di; 04275 AST_LIST_HEAD(, ast_dialed_interface) *dialed_interfaces; 04276 if (!tmp) { 04277 ao2_ref(cur, -1); 04278 ao2_unlock(qe->parent); 04279 ao2_iterator_destroy(&memi); 04280 if (need_weight) 04281 ao2_unlock(queues); 04282 goto out; 04283 } 04284 if (!datastore) { 04285 if (!(datastore = ast_datastore_alloc(&dialed_interface_info, NULL))) { 04286 ao2_ref(cur, -1); 04287 ao2_unlock(qe->parent); 04288 ao2_iterator_destroy(&memi); 04289 if (need_weight) 04290 ao2_unlock(queues); 04291 callattempt_free(tmp); 04292 goto out; 04293 } 04294 datastore->inheritance = DATASTORE_INHERIT_FOREVER; 04295 if (!(dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces)))) { 04296 ao2_ref(cur, -1); 04297 ao2_unlock(&qe->parent); 04298 ao2_iterator_destroy(&memi); 04299 if (need_weight) 04300 ao2_unlock(queues); 04301 callattempt_free(tmp); 04302 goto out; 04303 } 04304 datastore->data = dialed_interfaces; 04305 AST_LIST_HEAD_INIT(dialed_interfaces); 04306 04307 ast_channel_lock(qe->chan); 04308 ast_channel_datastore_add(qe->chan, datastore); 04309 ast_channel_unlock(qe->chan); 04310 } else 04311 dialed_interfaces = datastore->data; 04312 04313 AST_LIST_LOCK(dialed_interfaces); 04314 AST_LIST_TRAVERSE(dialed_interfaces, di, list) { 04315 if (!strcasecmp(cur->interface, di->interface)) { 04316 ast_debug(1, "Skipping dialing interface '%s' since it has already been dialed\n", 04317 di->interface); 04318 break; 04319 } 04320 } 04321 AST_LIST_UNLOCK(dialed_interfaces); 04322 04323 if (di) { 04324 callattempt_free(tmp); 04325 continue; 04326 } 04327 04328 /* It is always ok to dial a Local interface. We only keep track of 04329 * which "real" interfaces have been dialed. The Local channel will 04330 * inherit this list so that if it ends up dialing a real interface, 04331 * it won't call one that has already been called. */ 04332 if (strncasecmp(cur->interface, "Local/", 6)) { 04333 if (!(di = ast_calloc(1, sizeof(*di) + strlen(cur->interface)))) { 04334 ao2_ref(cur, -1); 04335 ao2_unlock(qe->parent); 04336 ao2_iterator_destroy(&memi); 04337 if (need_weight) 04338 ao2_unlock(queues); 04339 callattempt_free(tmp); 04340 goto out; 04341 } 04342 strcpy(di->interface, cur->interface); 04343 04344 AST_LIST_LOCK(dialed_interfaces); 04345 AST_LIST_INSERT_TAIL(dialed_interfaces, di, list); 04346 AST_LIST_UNLOCK(dialed_interfaces); 04347 } 04348 04349 ast_channel_lock(qe->chan); 04350 /* 04351 * Seed the callattempt's connected line information with previously 04352 * acquired connected line info from the queued channel. The 04353 * previously acquired connected line info could have been set 04354 * through the CONNECTED_LINE dialplan function. 04355 */ 04356 ast_party_connected_line_copy(&tmp->connected, &qe->chan->connected); 04357 ast_channel_unlock(qe->chan); 04358 04359 tmp->stillgoing = -1; 04360 tmp->member = cur;/* Place the reference for cur into callattempt. */ 04361 tmp->lastcall = cur->lastcall; 04362 tmp->lastqueue = cur->lastqueue; 04363 ast_copy_string(tmp->interface, cur->interface, sizeof(tmp->interface)); 04364 /* Special case: If we ring everyone, go ahead and ring them, otherwise 04365 just calculate their metric for the appropriate strategy */ 04366 if (!calc_metric(qe->parent, cur, x++, qe, tmp)) { 04367 /* Put them in the list of outgoing thingies... We're ready now. 04368 XXX If we're forcibly removed, these outgoing calls won't get 04369 hung up XXX */ 04370 tmp->q_next = outgoing; 04371 outgoing = tmp; 04372 /* If this line is up, don't try anybody else */ 04373 if (outgoing->chan && (outgoing->chan->_state == AST_STATE_UP)) 04374 break; 04375 } else { 04376 callattempt_free(tmp); 04377 } 04378 } 04379 ao2_iterator_destroy(&memi); 04380 04381 if (qe->parent->timeoutpriority == TIMEOUT_PRIORITY_APP) { 04382 /* Application arguments have higher timeout priority (behaviour for <=1.6) */ 04383 if (qe->expire && (!qe->parent->timeout || (qe->expire - now) <= qe->parent->timeout)) 04384 to = (qe->expire - now) * 1000; 04385 else 04386 to = (qe->parent->timeout) ? qe->parent->timeout * 1000 : -1; 04387 } else { 04388 /* Config timeout is higher priority thatn application timeout */ 04389 if (qe->expire && qe->expire<=now) { 04390 to = 0; 04391 } else if (qe->parent->timeout) { 04392 to = qe->parent->timeout * 1000; 04393 } else { 04394 to = -1; 04395 } 04396 } 04397 orig = to; 04398 ++qe->pending; 04399 ao2_unlock(qe->parent); 04400 ring_one(qe, outgoing, &numbusies); 04401 if (need_weight) 04402 ao2_unlock(queues); 04403 lpeer = wait_for_answer(qe, outgoing, &to, &digit, numbusies, ast_test_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT), forwardsallowed, update_connectedline); 04404 /* The ast_channel_datastore_remove() function could fail here if the 04405 * datastore was moved to another channel during a masquerade. If this is 04406 * the case, don't free the datastore here because later, when the channel 04407 * to which the datastore was moved hangs up, it will attempt to free this 04408 * datastore again, causing a crash 04409 */ 04410 ast_channel_lock(qe->chan); 04411 if (datastore && !ast_channel_datastore_remove(qe->chan, datastore)) { 04412 ast_datastore_free(datastore); 04413 } 04414 ast_channel_unlock(qe->chan); 04415 ao2_lock(qe->parent); 04416 if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY) { 04417 store_next_rr(qe, outgoing); 04418 } 04419 if (qe->parent->strategy == QUEUE_STRATEGY_LINEAR) { 04420 store_next_lin(qe, outgoing); 04421 } 04422 ao2_unlock(qe->parent); 04423 peer = lpeer ? lpeer->chan : NULL; 04424 if (!peer) { 04425 qe->pending = 0; 04426 if (to) { 04427 /* Must gotten hung up */ 04428 res = -1; 04429 } else { 04430 /* User exited by pressing a digit */ 04431 res = digit; 04432 } 04433 if (res == -1) 04434 ast_debug(1, "%s: Nobody answered.\n", qe->chan->name); 04435 if (ast_cdr_isset_unanswered()) { 04436 /* channel contains the name of one of the outgoing channels 04437 in its CDR; zero out this CDR to avoid a dual-posting */ 04438 struct callattempt *o; 04439 for (o = outgoing; o; o = o->q_next) { 04440 if (!o->chan) { 04441 continue; 04442 } 04443 if (strcmp(o->chan->cdr->dstchannel, qe->chan->cdr->dstchannel) == 0) { 04444 ast_set_flag(o->chan->cdr, AST_CDR_FLAG_POST_DISABLED); 04445 break; 04446 } 04447 } 04448 } 04449 } else { /* peer is valid */ 04450 /* Ah ha! Someone answered within the desired timeframe. Of course after this 04451 we will always return with -1 so that it is hung up properly after the 04452 conversation. */ 04453 if (!strcmp(qe->chan->tech->type, "DAHDI")) 04454 ast_channel_setoption(qe->chan, AST_OPTION_TONE_VERIFY, &nondataquality, sizeof(nondataquality), 0); 04455 if (!strcmp(peer->tech->type, "DAHDI")) 04456 ast_channel_setoption(peer, AST_OPTION_TONE_VERIFY, &nondataquality, sizeof(nondataquality), 0); 04457 /* Update parameters for the queue */ 04458 time(&now); 04459 recalc_holdtime(qe, (now - qe->start)); 04460 ao2_lock(qe->parent); 04461 callcompletedinsl = ((now - qe->start) <= qe->parent->servicelevel); 04462 ao2_unlock(qe->parent); 04463 member = lpeer->member; 04464 /* Increment the refcount for this member, since we're going to be using it for awhile in here. */ 04465 ao2_ref(member, 1); 04466 hangupcalls(outgoing, peer, qe->cancel_answered_elsewhere); 04467 outgoing = NULL; 04468 if (announce || qe->parent->reportholdtime || qe->parent->memberdelay) { 04469 int res2; 04470 04471 res2 = ast_autoservice_start(qe->chan); 04472 if (!res2) { 04473 if (qe->parent->memberdelay) { 04474 ast_log(LOG_NOTICE, "Delaying member connect for %d seconds\n", qe->parent->memberdelay); 04475 res2 |= ast_safe_sleep(peer, qe->parent->memberdelay * 1000); 04476 } 04477 if (!res2 && announce) { 04478 play_file(peer, announce); 04479 } 04480 if (!res2 && qe->parent->reportholdtime) { 04481 if (!play_file(peer, qe->parent->sound_reporthold)) { 04482 int holdtime, holdtimesecs; 04483 04484 time(&now); 04485 holdtime = abs((now - qe->start) / 60); 04486 holdtimesecs = abs((now - qe->start) % 60); 04487 if (holdtime > 0) { 04488 ast_say_number(peer, holdtime, AST_DIGIT_ANY, peer->language, NULL); 04489 play_file(peer, qe->parent->sound_minutes); 04490 } 04491 if (holdtimesecs > 1) { 04492 ast_say_number(peer, holdtimesecs, AST_DIGIT_ANY, peer->language, NULL); 04493 play_file(peer, qe->parent->sound_seconds); 04494 } 04495 } 04496 } 04497 } 04498 res2 |= ast_autoservice_stop(qe->chan); 04499 if (ast_check_hangup(peer)) { 04500 /* Agent must have hung up */ 04501 ast_log(LOG_WARNING, "Agent on %s hungup on the customer.\n", peer->name); 04502 ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "AGENTDUMP", "%s", ""); 04503 if (qe->parent->eventwhencalled) 04504 manager_event(EVENT_FLAG_AGENT, "AgentDump", 04505 "Queue: %s\r\n" 04506 "Uniqueid: %s\r\n" 04507 "Channel: %s\r\n" 04508 "Member: %s\r\n" 04509 "MemberName: %s\r\n" 04510 "%s", 04511 queuename, qe->chan->uniqueid, peer->name, member->interface, member->membername, 04512 qe->parent->eventwhencalled == QUEUE_EVENT_VARIABLES ? vars2manager(qe->chan, vars, sizeof(vars)) : ""); 04513 ast_hangup(peer); 04514 ao2_ref(member, -1); 04515 goto out; 04516 } else if (res2) { 04517 /* Caller must have hung up just before being connected*/ 04518 ast_log(LOG_NOTICE, "Caller was about to talk to agent on %s but the caller hungup.\n", peer->name); 04519 ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "ABANDON", "%d|%d|%ld", qe->pos, qe->opos, (long) time(NULL) - qe->start); 04520 record_abandoned(qe); 04521 ast_hangup(peer); 04522 ao2_ref(member, -1); 04523 return -1; 04524 } 04525 } 04526 /* Stop music on hold */ 04527 if (ringing) 04528 ast_indicate(qe->chan,-1); 04529 else 04530 ast_moh_stop(qe->chan); 04531 /* If appropriate, log that we have a destination channel */ 04532 if (qe->chan->cdr) 04533 ast_cdr_setdestchan(qe->chan->cdr, peer->name); 04534 /* Make sure channels are compatible */ 04535 res = ast_channel_make_compatible(qe->chan, peer); 04536 if (res < 0) { 04537 ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "SYSCOMPAT", "%s", ""); 04538 ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", qe->chan->name, peer->name); 04539 record_abandoned(qe); 04540 ast_cdr_failed(qe->chan->cdr); 04541 ast_hangup(peer); 04542 ao2_ref(member, -1); 04543 return -1; 04544 } 04545 04546 /* Play announcement to the caller telling it's his turn if defined */ 04547 if (!ast_strlen_zero(qe->parent->sound_callerannounce)) { 04548 if (play_file(qe->chan, qe->parent->sound_callerannounce)) 04549 ast_log(LOG_WARNING, "Announcement file '%s' is unavailable, continuing anyway...\n", qe->parent->sound_callerannounce); 04550 } 04551 04552 ao2_lock(qe->parent); 04553 /* if setinterfacevar is defined, make member variables available to the channel */ 04554 /* use pbx_builtin_setvar to set a load of variables with one call */ 04555 if (qe->parent->setinterfacevar) { 04556 snprintf(interfacevar, sizeof(interfacevar), "MEMBERINTERFACE=%s,MEMBERNAME=%s,MEMBERCALLS=%d,MEMBERLASTCALL=%ld,MEMBERPENALTY=%d,MEMBERDYNAMIC=%d,MEMBERREALTIME=%d", 04557 member->interface, member->membername, member->calls, (long)member->lastcall, member->penalty, member->dynamic, member->realtime); 04558 pbx_builtin_setvar_multiple(qe->chan, interfacevar); 04559 pbx_builtin_setvar_multiple(peer, interfacevar); 04560 } 04561 04562 /* if setqueueentryvar is defined, make queue entry (i.e. the caller) variables available to the channel */ 04563 /* use pbx_builtin_setvar to set a load of variables with one call */ 04564 if (qe->parent->setqueueentryvar) { 04565 snprintf(interfacevar, sizeof(interfacevar), "QEHOLDTIME=%ld,QEORIGINALPOS=%d", 04566 (long) time(NULL) - qe->start, qe->opos); 04567 pbx_builtin_setvar_multiple(qe->chan, interfacevar); 04568 pbx_builtin_setvar_multiple(peer, interfacevar); 04569 } 04570 04571 /* try to set queue variables if configured to do so*/ 04572 set_queue_variables(qe->parent, qe->chan); 04573 set_queue_variables(qe->parent, peer); 04574 ao2_unlock(qe->parent); 04575 04576 ast_channel_lock(qe->chan); 04577 if ((monitorfilename = pbx_builtin_getvar_helper(qe->chan, "MONITOR_FILENAME"))) { 04578 monitorfilename = ast_strdupa(monitorfilename); 04579 } 04580 ast_channel_unlock(qe->chan); 04581 /* Begin Monitoring */ 04582 if (qe->parent->monfmt && *qe->parent->monfmt) { 04583 if (!qe->parent->montype) { 04584 const char *monexec, *monargs; 04585 ast_debug(1, "Starting Monitor as requested.\n"); 04586 ast_channel_lock(qe->chan); 04587 if ((monexec = pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC")) || (monargs = pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC_ARGS"))) { 04588 which = qe->chan; 04589 monexec = monexec ? ast_strdupa(monexec) : NULL; 04590 } 04591 else 04592 which = peer; 04593 ast_channel_unlock(qe->chan); 04594 if (monitorfilename) { 04595 ast_monitor_start(which, qe->parent->monfmt, monitorfilename, 1, X_REC_IN | X_REC_OUT); 04596 } else if (qe->chan->cdr) { 04597 ast_monitor_start(which, qe->parent->monfmt, qe->chan->cdr->uniqueid, 1, X_REC_IN | X_REC_OUT); 04598 } else { 04599 /* Last ditch effort -- no CDR, make up something */ 04600 snprintf(tmpid, sizeof(tmpid), "chan-%lx", ast_random()); 04601 ast_monitor_start(which, qe->parent->monfmt, tmpid, 1, X_REC_IN | X_REC_OUT); 04602 } 04603 if (!ast_strlen_zero(monexec)) { 04604 ast_monitor_setjoinfiles(which, 1); 04605 } 04606 } else { 04607 mixmonapp = pbx_findapp("MixMonitor"); 04608 04609 if (mixmonapp) { 04610 ast_debug(1, "Starting MixMonitor as requested.\n"); 04611 if (!monitorfilename) { 04612 if (qe->chan->cdr) 04613 ast_copy_string(tmpid, qe->chan->cdr->uniqueid, sizeof(tmpid)); 04614 else 04615 snprintf(tmpid, sizeof(tmpid), "chan-%lx", ast_random()); 04616 } else { 04617 const char *m = monitorfilename; 04618 for (p = tmpid2; p < tmpid2 + sizeof(tmpid2) - 1; p++, m++) { 04619 switch (*m) { 04620 case '^': 04621 if (*(m + 1) == '{') 04622 *p = '$'; 04623 break; 04624 case ',': 04625 *p++ = '\\'; 04626 /* Fall through */ 04627 default: 04628 *p = *m; 04629 } 04630 if (*m == '\0') 04631 break; 04632 } 04633 if (p == tmpid2 + sizeof(tmpid2)) 04634 tmpid2[sizeof(tmpid2) - 1] = '\0'; 04635 04636 pbx_substitute_variables_helper(qe->chan, tmpid2, tmpid, sizeof(tmpid) - 1); 04637 } 04638 04639 ast_channel_lock(qe->chan); 04640 if ((monitor_exec = pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC"))) { 04641 monitor_exec = ast_strdupa(monitor_exec); 04642 } 04643 if ((monitor_options = pbx_builtin_getvar_helper(qe->chan, "MONITOR_OPTIONS"))) { 04644 monitor_options = ast_strdupa(monitor_options); 04645 } else { 04646 monitor_options = ""; 04647 } 04648 ast_channel_unlock(qe->chan); 04649 04650 if (monitor_exec) { 04651 const char *m = monitor_exec; 04652 for (p = meid2; p < meid2 + sizeof(meid2) - 1; p++, m++) { 04653 switch (*m) { 04654 case '^': 04655 if (*(m + 1) == '{') 04656 *p = '$'; 04657 break; 04658 case ',': 04659 *p++ = '\\'; 04660 /* Fall through */ 04661 default: 04662 *p = *m; 04663 } 04664 if (*m == '\0') 04665 break; 04666 } 04667 if (p == meid2 + sizeof(meid2)) 04668 meid2[sizeof(meid2) - 1] = '\0'; 04669 04670 pbx_substitute_variables_helper(qe->chan, meid2, meid, sizeof(meid) - 1); 04671 } 04672 04673 snprintf(tmpid2, sizeof(tmpid2), "%s.%s", tmpid, qe->parent->monfmt); 04674 04675 if (!ast_strlen_zero(monitor_exec)) 04676 snprintf(mixmonargs, sizeof(mixmonargs), "%s,b%s,%s", tmpid2, monitor_options, monitor_exec); 04677 else 04678 snprintf(mixmonargs, sizeof(mixmonargs), "%s,b%s", tmpid2, monitor_options); 04679 04680 ast_debug(1, "Arguments being passed to MixMonitor: %s\n", mixmonargs); 04681 /* We purposely lock the CDR so that pbx_exec does not update the application data */ 04682 if (qe->chan->cdr) 04683 ast_set_flag(qe->chan->cdr, AST_CDR_FLAG_LOCKED); 04684 ret = pbx_exec(qe->chan, mixmonapp, mixmonargs); 04685 if (qe->chan->cdr) 04686 ast_clear_flag(qe->chan->cdr, AST_CDR_FLAG_LOCKED); 04687 04688 } else { 04689 ast_log(LOG_WARNING, "Asked to run MixMonitor on this call, but cannot find the MixMonitor app!\n"); 04690 } 04691 } 04692 } 04693 /* Drop out of the queue at this point, to prepare for next caller */ 04694 leave_queue(qe); 04695 if (!ast_strlen_zero(url) && ast_channel_supports_html(peer)) { 04696 ast_debug(1, "app_queue: sendurl=%s.\n", url); 04697 ast_channel_sendurl(peer, url); 04698 } 04699 04700 /* run a macro for this connection if defined. The macro simply returns, no action is taken on the result */ 04701 /* use macro from dialplan if passed as a option, otherwise use the default queue macro */ 04702 if (!ast_strlen_zero(macro)) { 04703 macroexec = ast_strdupa(macro); 04704 } else { 04705 if (qe->parent->membermacro) 04706 macroexec = ast_strdupa(qe->parent->membermacro); 04707 } 04708 04709 if (!ast_strlen_zero(macroexec)) { 04710 ast_debug(1, "app_queue: macro=%s.\n", macroexec); 04711 04712 res = ast_autoservice_start(qe->chan); 04713 if (res) { 04714 ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n"); 04715 res = -1; 04716 } 04717 04718 application = pbx_findapp("Macro"); 04719 04720 if (application) { 04721 res = pbx_exec(peer, application, macroexec); 04722 ast_debug(1, "Macro exited with status %d\n", res); 04723 res = 0; 04724 } else { 04725 ast_log(LOG_ERROR, "Could not find application Macro\n"); 04726 res = -1; 04727 } 04728 04729 if (ast_autoservice_stop(qe->chan) < 0) { 04730 ast_log(LOG_ERROR, "Could not stop autoservice on calling channel\n"); 04731 res = -1; 04732 } 04733 } 04734 04735 /* run a gosub for this connection if defined. The gosub simply returns, no action is taken on the result */ 04736 /* use gosub from dialplan if passed as a option, otherwise use the default queue gosub */ 04737 if (!ast_strlen_zero(gosub)) { 04738 gosubexec = ast_strdupa(gosub); 04739 } else { 04740 if (qe->parent->membergosub) 04741 gosubexec = ast_strdupa(qe->parent->membergosub); 04742 } 04743 04744 if (!ast_strlen_zero(gosubexec)) { 04745 ast_debug(1, "app_queue: gosub=%s.\n", gosubexec); 04746 04747 res = ast_autoservice_start(qe->chan); 04748 if (res) { 04749 ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n"); 04750 res = -1; 04751 } 04752 04753 application = pbx_findapp("Gosub"); 04754 04755 if (application) { 04756 char *gosub_args, *gosub_argstart; 04757 04758 /* Set where we came from */ 04759 ast_copy_string(peer->context, "app_queue_gosub_virtual_context", sizeof(peer->context)); 04760 ast_copy_string(peer->exten, "s", sizeof(peer->exten)); 04761 peer->priority = 0; 04762 04763 gosub_argstart = strchr(gosubexec, ','); 04764 if (gosub_argstart) { 04765 *gosub_argstart = 0; 04766 if (asprintf(&gosub_args, "%s,s,1(%s)", gosubexec, gosub_argstart + 1) < 0) { 04767 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); 04768 gosub_args = NULL; 04769 } 04770 *gosub_argstart = ','; 04771 } else { 04772 if (asprintf(&gosub_args, "%s,s,1", gosubexec) < 0) { 04773 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); 04774 gosub_args = NULL; 04775 } 04776 } 04777 if (gosub_args) { 04778 res = pbx_exec(peer, application, gosub_args); 04779 if (!res) { 04780 struct ast_pbx_args args; 04781 memset(&args, 0, sizeof(args)); 04782 args.no_hangup_chan = 1; 04783 ast_pbx_run_args(peer, &args); 04784 } 04785 ast_free(gosub_args); 04786 ast_debug(1, "Gosub exited with status %d\n", res); 04787 } else { 04788 ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n"); 04789 } 04790 } else { 04791 ast_log(LOG_ERROR, "Could not find application Gosub\n"); 04792 res = -1; 04793 } 04794 04795 if (ast_autoservice_stop(qe->chan) < 0) { 04796 ast_log(LOG_ERROR, "Could not stop autoservice on calling channel\n"); 04797 res = -1; 04798 } 04799 } 04800 04801 if (!ast_strlen_zero(agi)) { 04802 ast_debug(1, "app_queue: agi=%s.\n", agi); 04803 application = pbx_findapp("agi"); 04804 if (application) { 04805 agiexec = ast_strdupa(agi); 04806 ret = pbx_exec(qe->chan, application, agiexec); 04807 } else 04808 ast_log(LOG_WARNING, "Asked to execute an AGI on this channel, but could not find application (agi)!\n"); 04809 } 04810 qe->handled++; 04811 ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "CONNECT", "%ld|%s|%ld", (long) time(NULL) - qe->start, peer->uniqueid, 04812 (long)(orig - to > 0 ? (orig - to) / 1000 : 0)); 04813 if (update_cdr && qe->chan->cdr) 04814 ast_copy_string(qe->chan->cdr->dstchannel, member->membername, sizeof(qe->chan->cdr->dstchannel)); 04815 if (qe->parent->eventwhencalled) 04816 manager_event(EVENT_FLAG_AGENT, "AgentConnect", 04817 "Queue: %s\r\n" 04818 "Uniqueid: %s\r\n" 04819 "Channel: %s\r\n" 04820 "Member: %s\r\n" 04821 "MemberName: %s\r\n" 04822 "Holdtime: %ld\r\n" 04823 "BridgedChannel: %s\r\n" 04824 "Ringtime: %ld\r\n" 04825 "%s", 04826 queuename, qe->chan->uniqueid, peer->name, member->interface, member->membername, 04827 (long) time(NULL) - qe->start, peer->uniqueid, (long)(orig - to > 0 ? (orig - to) / 1000 : 0), 04828 qe->parent->eventwhencalled == QUEUE_EVENT_VARIABLES ? vars2manager(qe->chan, vars, sizeof(vars)) : ""); 04829 ast_copy_string(oldcontext, qe->chan->context, sizeof(oldcontext)); 04830 ast_copy_string(oldexten, qe->chan->exten, sizeof(oldexten)); 04831 04832 if ((queue_end_bridge = ao2_alloc(sizeof(*queue_end_bridge), NULL))) { 04833 queue_end_bridge->q = qe->parent; 04834 queue_end_bridge->chan = qe->chan; 04835 bridge_config.end_bridge_callback = end_bridge_callback; 04836 bridge_config.end_bridge_callback_data = queue_end_bridge; 04837 bridge_config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup; 04838 /* Since queue_end_bridge can survive beyond the life of this call to Queue, we need 04839 * to make sure to increase the refcount of this queue so it cannot be freed until we 04840 * are done with it. We remove this reference in end_bridge_callback. 04841 */ 04842 queue_t_ref(qe->parent, "For bridge_config reference"); 04843 } 04844 04845 time(&callstart); 04846 transfer_ds = setup_transfer_datastore(qe, member, callstart, callcompletedinsl); 04847 bridge = ast_bridge_call(qe->chan,peer, &bridge_config); 04848 04849 /* If the queue member did an attended transfer, then the TRANSFER already was logged in the queue_log 04850 * when the masquerade occurred. These other "ending" queue_log messages are unnecessary, except for 04851 * the AgentComplete manager event 04852 */ 04853 ast_channel_lock(qe->chan); 04854 if (!attended_transfer_occurred(qe->chan)) { 04855 struct ast_datastore *tds; 04856 04857 /* detect a blind transfer */ 04858 if (!(qe->chan->_softhangup | peer->_softhangup) && (strcasecmp(oldcontext, qe->chan->context) || strcasecmp(oldexten, qe->chan->exten))) { 04859 ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "TRANSFER", "%s|%s|%ld|%ld|%d", 04860 qe->chan->exten, qe->chan->context, (long) (callstart - qe->start), 04861 (long) (time(NULL) - callstart), qe->opos); 04862 send_agent_complete(qe, queuename, peer, member, callstart, vars, sizeof(vars), TRANSFER); 04863 } else if (ast_check_hangup(qe->chan)) { 04864 ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "COMPLETECALLER", "%ld|%ld|%d", 04865 (long) (callstart - qe->start), (long) (time(NULL) - callstart), qe->opos); 04866 send_agent_complete(qe, queuename, peer, member, callstart, vars, sizeof(vars), CALLER); 04867 } else { 04868 ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "COMPLETEAGENT", "%ld|%ld|%d", 04869 (long) (callstart - qe->start), (long) (time(NULL) - callstart), qe->opos); 04870 send_agent_complete(qe, queuename, peer, member, callstart, vars, sizeof(vars), AGENT); 04871 } 04872 if ((tds = ast_channel_datastore_find(qe->chan, &queue_transfer_info, NULL))) { 04873 ast_channel_datastore_remove(qe->chan, tds); 04874 } 04875 update_queue(qe->parent, member, callcompletedinsl, (time(NULL) - callstart)); 04876 } else { 04877 /* We already logged the TRANSFER on the queue_log, but we still need to send the AgentComplete event */ 04878 send_agent_complete(qe, queuename, peer, member, callstart, vars, sizeof(vars), TRANSFER); 04879 } 04880 04881 if (transfer_ds) { 04882 ast_datastore_free(transfer_ds); 04883 } 04884 ast_channel_unlock(qe->chan); 04885 ast_hangup(peer); 04886 res = bridge ? bridge : 1; 04887 ao2_ref(member, -1); 04888 } 04889 out: 04890 hangupcalls(outgoing, NULL, qe->cancel_answered_elsewhere); 04891 04892 return res; 04893 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 8065 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_ref, ao2_t_iterator_next, ARRAY_LEN, ast_cli_unregister_multiple(), ast_context_destroy(), ast_context_find(), ast_context_remove_extension2(), ast_custom_function_unregister(), ast_data_unregister, ast_event_unsubscribe(), ast_extension_state_del(), ast_manager_unregister(), ast_taskprocessor_unreference(), ast_unload_realtime(), ast_unregister_application(), cli_queue, extension_state_cb(), queue_t_unref, queueexists_function, queuemembercount_dep, queuemembercount_function, queuememberlist_function, queuememberpenalty_function, queues, queues_t_unlink, queuevar_function, and queuewaitingcount_function.
08066 { 08067 int res; 08068 struct ast_context *con; 08069 struct ao2_iterator q_iter; 08070 struct call_queue *q = NULL; 08071 08072 ast_cli_unregister_multiple(cli_queue, ARRAY_LEN(cli_queue)); 08073 res = ast_manager_unregister("QueueStatus"); 08074 res |= ast_manager_unregister("Queues"); 08075 res |= ast_manager_unregister("QueueRule"); 08076 res |= ast_manager_unregister("QueueSummary"); 08077 res |= ast_manager_unregister("QueueAdd"); 08078 res |= ast_manager_unregister("QueueRemove"); 08079 res |= ast_manager_unregister("QueuePause"); 08080 res |= ast_manager_unregister("QueueLog"); 08081 res |= ast_manager_unregister("QueuePenalty"); 08082 res |= ast_unregister_application(app_aqm); 08083 res |= ast_unregister_application(app_rqm); 08084 res |= ast_unregister_application(app_pqm); 08085 res |= ast_unregister_application(app_upqm); 08086 res |= ast_unregister_application(app_ql); 08087 res |= ast_unregister_application(app); 08088 res |= ast_custom_function_unregister(&queueexists_function); 08089 res |= ast_custom_function_unregister(&queuevar_function); 08090 res |= ast_custom_function_unregister(&queuemembercount_function); 08091 res |= ast_custom_function_unregister(&queuemembercount_dep); 08092 res |= ast_custom_function_unregister(&queuememberlist_function); 08093 res |= ast_custom_function_unregister(&queuewaitingcount_function); 08094 res |= ast_custom_function_unregister(&queuememberpenalty_function); 08095 08096 res |= ast_data_unregister(NULL); 08097 08098 if (device_state_sub) 08099 ast_event_unsubscribe(device_state_sub); 08100 08101 ast_extension_state_del(0, extension_state_cb); 08102 08103 if ((con = ast_context_find("app_queue_gosub_virtual_context"))) { 08104 ast_context_remove_extension2(con, "s", 1, NULL, 0); 08105 ast_context_destroy(con, "app_queue"); /* leave no trace */ 08106 } 08107 08108 q_iter = ao2_iterator_init(queues, 0); 08109 while ((q = ao2_t_iterator_next(&q_iter, "Iterate through queues"))) { 08110 queues_t_unlink(queues, q, "Remove queue from container due to unload"); 08111 queue_t_unref(q, "Done with iterator"); 08112 } 08113 ao2_iterator_destroy(&q_iter); 08114 ao2_ref(queues, -1); 08115 devicestate_tps = ast_taskprocessor_unreference(devicestate_tps); 08116 ast_unload_realtime("queue_members"); 08117 return res; 08118 }
| static void update_qe_rule | ( | struct queue_ent * | qe | ) | [static] |
update rules for queues
Calculate min/max penalties making sure if relative they stay within bounds. Update queues penalty and set dialplan vars, goto next list entry.
Definition at line 3718 of file app_queue.c.
References ast_debug, AST_LIST_NEXT, queue_ent::chan, queue_ent::max_penalty, penalty_rule::max_relative, penalty_rule::max_value, queue_ent::min_penalty, penalty_rule::min_relative, penalty_rule::min_value, ast_channel::name, pbx_builtin_setvar_helper(), queue_ent::pr, and penalty_rule::time.
Referenced by queue_exec(), and wait_our_turn().
03719 { 03720 int max_penalty = qe->pr->max_relative ? qe->max_penalty + qe->pr->max_value : qe->pr->max_value; 03721 int min_penalty = qe->pr->min_relative ? qe->min_penalty + qe->pr->min_value : qe->pr->min_value; 03722 char max_penalty_str[20], min_penalty_str[20]; 03723 /* a relative change to the penalty could put it below 0 */ 03724 if (max_penalty < 0) 03725 max_penalty = 0; 03726 if (min_penalty < 0) 03727 min_penalty = 0; 03728 if (min_penalty > max_penalty) 03729 min_penalty = max_penalty; 03730 snprintf(max_penalty_str, sizeof(max_penalty_str), "%d", max_penalty); 03731 snprintf(min_penalty_str, sizeof(min_penalty_str), "%d", min_penalty); 03732 pbx_builtin_setvar_helper(qe->chan, "QUEUE_MAX_PENALTY", max_penalty_str); 03733 pbx_builtin_setvar_helper(qe->chan, "QUEUE_MIN_PENALTY", min_penalty_str); 03734 qe->max_penalty = max_penalty; 03735 qe->min_penalty = min_penalty; 03736 ast_debug(3, "Setting max penalty to %d and min penalty to %d for caller %s since %d seconds have elapsed\n", qe->max_penalty, qe->min_penalty, qe->chan->name, qe->pr->time); 03737 qe->pr = AST_LIST_NEXT(qe->pr, list); 03738 }
| static int update_queue | ( | struct call_queue * | q, | |
| struct member * | member, | |||
| int | callcompletedinsl, | |||
| int | newtalktime | |||
| ) | [static] |
update the queue status
| Always | 0 |
Definition at line 3826 of file app_queue.c.
References ao2_find, ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock, ao2_ref, ao2_t_iterator_next, ao2_unlock, member::calls, call_queue::callscompleted, call_queue::callscompletedinsl, member::lastcall, member::lastqueue, call_queue::members, OBJ_POINTER, queue_t_unref, queues, and call_queue::talktime.
Referenced by queue_transfer_fixup(), and try_calling().
03827 { 03828 int oldtalktime; 03829 03830 struct member *mem; 03831 struct call_queue *qtmp; 03832 struct ao2_iterator queue_iter; 03833 03834 if (shared_lastcall) { 03835 queue_iter = ao2_iterator_init(queues, 0); 03836 while ((qtmp = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) { 03837 ao2_lock(qtmp); 03838 if ((mem = ao2_find(qtmp->members, member, OBJ_POINTER))) { 03839 time(&mem->lastcall); 03840 mem->calls++; 03841 mem->lastqueue = q; 03842 ao2_ref(mem, -1); 03843 } 03844 ao2_unlock(qtmp); 03845 queue_t_unref(qtmp, "Done with iterator"); 03846 } 03847 ao2_iterator_destroy(&queue_iter); 03848 } else { 03849 ao2_lock(q); 03850 time(&member->lastcall); 03851 member->calls++; 03852 member->lastqueue = q; 03853 ao2_unlock(q); 03854 } 03855 ao2_lock(q); 03856 q->callscompleted++; 03857 if (callcompletedinsl) 03858 q->callscompletedinsl++; 03859 /* Calculate talktime using the same exponential average as holdtime code*/ 03860 oldtalktime = q->talktime; 03861 q->talktime = (((oldtalktime << 2) - oldtalktime) + newtalktime) >> 2; 03862 ao2_unlock(q); 03863 return 0; 03864 }
| static int update_realtime_member_field | ( | struct member * | mem, | |
| const char * | queue_name, | |||
| const char * | field, | |||
| const char * | value | |||
| ) | [static] |
Definition at line 2222 of file app_queue.c.
References ast_strlen_zero(), ast_update_realtime(), member::rt_uniqueid, and SENTINEL.
Referenced by set_member_paused().
02223 { 02224 int ret = -1; 02225 02226 if (ast_strlen_zero(mem->rt_uniqueid)) 02227 return ret; 02228 02229 if ((ast_update_realtime("queue_members", "uniqueid", mem->rt_uniqueid, field, value, SENTINEL)) > 0) 02230 ret = 0; 02231 02232 return ret; 02233 }
| static void update_realtime_members | ( | struct call_queue * | q | ) | [static] |
Definition at line 2236 of file app_queue.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlink, ao2_unlock, ast_category_browse(), ast_config_destroy(), ast_debug, ast_load_realtime_multientry(), ast_queue_log(), ast_variable_retrieve(), member::dead, member::interface, call_queue::membercount, call_queue::members, call_queue::name, queues, member::realtime, rt_handle_member_record(), S_OR, and SENTINEL.
Referenced by load_realtime_queue(), and queue_exec().
02237 { 02238 struct ast_config *member_config = NULL; 02239 struct member *m; 02240 char *interface = NULL; 02241 struct ao2_iterator mem_iter; 02242 02243 if (!(member_config = ast_load_realtime_multientry("queue_members", "interface LIKE", "%", "queue_name", q->name , SENTINEL))) { 02244 /*This queue doesn't have realtime members*/ 02245 ast_debug(3, "Queue %s has no realtime members defined. No need for update\n", q->name); 02246 return; 02247 } 02248 02249 ao2_lock(queues); 02250 ao2_lock(q); 02251 02252 /* Temporarily set realtime members dead so we can detect deleted ones.*/ 02253 mem_iter = ao2_iterator_init(q->members, 0); 02254 while ((m = ao2_iterator_next(&mem_iter))) { 02255 if (m->realtime) 02256 m->dead = 1; 02257 ao2_ref(m, -1); 02258 } 02259 ao2_iterator_destroy(&mem_iter); 02260 02261 while ((interface = ast_category_browse(member_config, interface))) { 02262 rt_handle_member_record(q, interface, 02263 ast_variable_retrieve(member_config, interface, "uniqueid"), 02264 S_OR(ast_variable_retrieve(member_config, interface, "membername"), interface), 02265 ast_variable_retrieve(member_config, interface, "penalty"), 02266 ast_variable_retrieve(member_config, interface, "paused"), 02267 S_OR(ast_variable_retrieve(member_config, interface, "state_interface"), interface)); 02268 } 02269 02270 /* Delete all realtime members that have been deleted in DB. */ 02271 mem_iter = ao2_iterator_init(q->members, 0); 02272 while ((m = ao2_iterator_next(&mem_iter))) { 02273 if (m->dead) { 02274 ast_queue_log(q->name, "REALTIME", m->interface, "REMOVEMEMBER", "%s", ""); 02275 ao2_unlink(q->members, m); 02276 q->membercount--; 02277 } 02278 ao2_ref(m, -1); 02279 } 02280 ao2_iterator_destroy(&mem_iter); 02281 ao2_unlock(q); 02282 ao2_unlock(queues); 02283 ast_config_destroy(member_config); 02284 }
| static int update_status | ( | struct call_queue * | q, | |
| struct member * | m, | |||
| const int | status | |||
| ) | [static] |
set a member's status based on device state of that member's state_interface.
Lock interface list find sc, iterate through each queues queue_member list for member to update state inside queues
Definition at line 1261 of file app_queue.c.
References EVENT_FLAG_AGENT, and manager_event.
Referenced by extension_state_cb(), handle_statechange(), and ring_entry().
01262 { 01263 m->status = status; 01264 01265 if (q->maskmemberstatus) 01266 return 0; 01267 01268 manager_event(EVENT_FLAG_AGENT, "QueueMemberStatus", 01269 "Queue: %s\r\n" 01270 "Location: %s\r\n" 01271 "MemberName: %s\r\n" 01272 "Membership: %s\r\n" 01273 "Penalty: %d\r\n" 01274 "CallsTaken: %d\r\n" 01275 "LastCall: %d\r\n" 01276 "Status: %d\r\n" 01277 "Paused: %d\r\n", 01278 q->name, m->interface, m->membername, m->dynamic ? "dynamic" : m->realtime ? "realtime" : "static", 01279 m->penalty, m->calls, (int)m->lastcall, m->status, m->paused 01280 ); 01281 01282 return 0; 01283 }
| static int upqm_exec | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) | [static] |
UnPauseQueueMember application.
Definition at line 5378 of file app_queue.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), LOG_WARNING, parse(), pbx_builtin_setvar_helper(), and set_member_paused().
Referenced by load_module().
05379 { 05380 char *parse; 05381 AST_DECLARE_APP_ARGS(args, 05382 AST_APP_ARG(queuename); 05383 AST_APP_ARG(interface); 05384 AST_APP_ARG(options); 05385 AST_APP_ARG(reason); 05386 ); 05387 05388 if (ast_strlen_zero(data)) { 05389 ast_log(LOG_WARNING, "UnpauseQueueMember requires an argument ([queuename],interface[,options[,reason]])\n"); 05390 return -1; 05391 } 05392 05393 parse = ast_strdupa(data); 05394 05395 AST_STANDARD_APP_ARGS(args, parse); 05396 05397 if (ast_strlen_zero(args.interface)) { 05398 ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename],interface[,options[,reason]])\n"); 05399 return -1; 05400 } 05401 05402 if (set_member_paused(args.queuename, args.interface, args.reason, 0)) { 05403 ast_log(LOG_WARNING, "Attempt to unpause interface %s, not found\n", args.interface); 05404 pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "NOTFOUND"); 05405 return 0; 05406 } 05407 05408 pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "UNPAUSED"); 05409 05410 return 0; 05411 }
| static int valid_exit | ( | struct queue_ent * | qe, | |
| char | digit | |||
| ) | [static] |
Check for valid exit from queue via goto.
| 0 | if failure | |
| 1 | if successful |
Definition at line 2392 of file app_queue.c.
References ast_canmatch_extension(), ast_goto_if_exists(), ast_strlen_zero(), ast_channel::caller, queue_ent::chan, queue_ent::context, queue_ent::digits, ast_party_caller::id, ast_party_id::number, S_COR, ast_party_number::str, ast_party_number::valid, and queue_ent::valid_digits.
Referenced by say_periodic_announcement(), say_position(), wait_a_bit(), wait_for_answer(), and wait_our_turn().
02393 { 02394 int digitlen = strlen(qe->digits); 02395 02396 /* Prevent possible buffer overflow */ 02397 if (digitlen < sizeof(qe->digits) - 2) { 02398 qe->digits[digitlen] = digit; 02399 qe->digits[digitlen + 1] = '\0'; 02400 } else { 02401 qe->digits[0] = '\0'; 02402 return 0; 02403 } 02404 02405 /* If there's no context to goto, short-circuit */ 02406 if (ast_strlen_zero(qe->context)) 02407 return 0; 02408 02409 /* If the extension is bad, then reset the digits to blank */ 02410 if (!ast_canmatch_extension(qe->chan, qe->context, qe->digits, 1, 02411 S_COR(qe->chan->caller.id.number.valid, qe->chan->caller.id.number.str, NULL))) { 02412 qe->digits[0] = '\0'; 02413 return 0; 02414 } 02415 02416 /* We have an exact match */ 02417 if (!ast_goto_if_exists(qe->chan, qe->context, qe->digits, 1)) { 02418 qe->valid_digits = 1; 02419 /* Return 1 on a successful goto */ 02420 return 1; 02421 } 02422 02423 return 0; 02424 }
| static char* vars2manager | ( | struct ast_channel * | chan, | |
| char * | vars, | |||
| size_t | len | |||
| ) | [static] |
convert "\n" to "\nVariable: " ready for manager to use
Definition at line 2782 of file app_queue.c.
References ast_copy_string(), ast_str_buffer(), ast_str_thread_get(), and pbx_builtin_serialize_variables().
Referenced by ring_entry(), rna(), send_agent_complete(), and try_calling().
02783 { 02784 struct ast_str *buf = ast_str_thread_get(&ast_str_thread_global_buf, len + 1); 02785 const char *tmp; 02786 02787 if (pbx_builtin_serialize_variables(chan, &buf)) { 02788 int i, j; 02789 02790 /* convert "\n" to "\nVariable: " */ 02791 strcpy(vars, "Variable: "); 02792 tmp = ast_str_buffer(buf); 02793 02794 for (i = 0, j = 10; (i < len - 1) && (j < len - 1); i++, j++) { 02795 vars[j] = tmp[i]; 02796 02797 if (tmp[i + 1] == '\0') 02798 break; 02799 if (tmp[i] == '\n') { 02800 vars[j++] = '\r'; 02801 vars[j++] = '\n'; 02802 02803 ast_copy_string(&(vars[j]), "Variable: ", len - j); 02804 j += 9; 02805 } 02806 } 02807 if (j > len - 3) 02808 j = len - 3; 02809 vars[j++] = '\r'; 02810 vars[j++] = '\n'; 02811 vars[j] = '\0'; 02812 } else { 02813 /* there are no channel variables; leave it blank */ 02814 *vars = '\0'; 02815 } 02816 return vars; 02817 }
| static int wait_a_bit | ( | struct queue_ent * | qe | ) | [static] |
Definition at line 4895 of file app_queue.c.
References ast_waitfordigit(), queue_ent::chan, queue_ent::parent, call_queue::retry, and valid_exit().
Referenced by queue_exec().
04896 { 04897 /* Don't need to hold the lock while we setup the outgoing calls */ 04898 int retrywait = qe->parent->retry * 1000; 04899 04900 int res = ast_waitfordigit(qe->chan, retrywait); 04901 if (res > 0 && !valid_exit(qe, res)) 04902 res = 0; 04903 04904 return res; 04905 }
| static struct callattempt* wait_for_answer | ( | struct queue_ent * | qe, | |
| struct callattempt * | outgoing, | |||
| int * | to, | |||
| char * | digit, | |||
| int | prebusies, | |||
| int | caller_disconnect, | |||
| int | forwardsallowed, | |||
| int | update_connectedline | |||
| ) | [static, read] |
Wait for a member to answer the call.
| [in] | qe | the queue_ent corresponding to the caller in the queue |
| [in] | outgoing | the list of callattempts. Relevant ones will have their chan and stillgoing parameters non-zero |
| [in] | to | the amount of time (in milliseconds) to wait for a response |
| [out] | digit | if a user presses a digit to exit the queue, this is the digit the caller pressed |
| [in] | prebusies | number of busy members calculated prior to calling wait_for_answer |
| [in] | caller_disconnect | if the 'H' option is used when calling Queue(), this is used to detect if the caller pressed * to disconnect the call |
| [in] | forwardsallowed | used to detect if we should allow call forwarding, based on the 'i' option to Queue() |
| [in] | update_connectedline | Allow connected line and redirecting updates to pass through. |
Definition at line 3258 of file app_queue.c.
References ast_channel::_state, ast_channel::accountcode, accountcode, callattempt::aoc_s_rate_list, ast_aoc_decode(), ast_aoc_destroy_decoded(), ast_aoc_destroy_encoded(), ast_aoc_encode(), ast_aoc_get_msg_type(), AST_AOC_S, ast_call(), ast_cdr_busy(), AST_CEL_FORWARD, ast_cel_report_event(), ast_channel_connected_line_macro(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_redirecting_macro(), ast_channel_set_redirecting(), ast_channel_trylock, ast_channel_unlock, ast_channel_update_connected_line(), ast_channel_update_redirecting(), ast_connected_line_copy_from_caller(), ast_connected_line_parse_data(), AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER, AST_CONTROL_ANSWER, AST_CONTROL_AOC, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HANGUP, AST_CONTROL_OFFHOOK, AST_CONTROL_REDIRECTING, AST_CONTROL_RINGING, ast_copy_string(), ast_debug, AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_frfree, ast_hangup(), ast_indicate(), ast_indicate_data(), ast_log(), AST_MAX_WATCHERS, ast_moh_stop(), ast_party_caller_copy(), ast_party_connected_line_copy(), ast_party_connected_line_free(), ast_party_connected_line_init(), ast_party_connected_line_set(), ast_party_connected_line_set_init(), ast_party_number_free(), ast_party_number_init(), ast_party_redirecting_copy(), ast_party_redirecting_free(), ast_party_redirecting_init(), ast_poll_channel_add(), ast_poll_channel_del(), ast_read(), ast_request(), AST_STATE_UP, ast_strdup, ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_verb, ast_waitfor_n(), ast_channel::call_forward, callattempt::call_next, ast_channel::caller, ast_channel::cdr, callattempt::chan, queue_ent::chan, CHANNEL_DEADLOCK_AVOIDANCE, ast_channel::connected, callattempt::connected, ast_channel::context, ast_frame::data, ast_frame::datalen, callattempt::dial_callerid_absent, ast_channel::dialed, do_hang(), ast_channel::exten, f, ast_frame::frametype, ast_party_redirecting::from, ast_channel::hangupcause, ast_frame_subclass::integer, callattempt::interface, member::interface, LOG_NOTICE, ast_channel::macroexten, callattempt::member, member::membername, ast_channel::name, call_queue::name, ast_channel::nativeformats, ast_party_id::number, queue_ent::parent, callattempt::pending_connected_update, queue_ent::pos, ast_frame::ptr, callattempt::q_next, QUEUE_STRATEGY_RINGALL, ast_channel::redirecting, ring_one(), queue_ent::ring_when_ringing, rna(), S_OR, ast_party_connected_line::source, queue_ent::start, starttime, status, callattempt::stillgoing, ast_party_number::str, call_queue::strategy, ast_frame::subclass, ast_channel::tech, call_queue::timeoutrestart, ast_party_dialed::transit_network_select, ast_frame::uint32, ast_party_number::valid, and valid_exit().
Referenced by try_calling().
03259 { 03260 const char *queue = qe->parent->name; 03261 struct callattempt *o, *start = NULL, *prev = NULL; 03262 int res; 03263 int status; 03264 int numbusies = prebusies; 03265 int numnochan = 0; 03266 int stillgoing = 0; 03267 int orig = *to; 03268 struct ast_frame *f; 03269 struct callattempt *peer = NULL; 03270 struct ast_channel *winner; 03271 struct ast_channel *in = qe->chan; 03272 char on[80] = ""; 03273 char membername[80] = ""; 03274 long starttime = 0; 03275 long endtime = 0; 03276 #ifdef HAVE_EPOLL 03277 struct callattempt *epollo; 03278 #endif 03279 struct ast_party_connected_line connected_caller; 03280 char *inchan_name; 03281 03282 ast_party_connected_line_init(&connected_caller); 03283 03284 ast_channel_lock(qe->chan); 03285 inchan_name = ast_strdupa(qe->chan->name); 03286 ast_channel_unlock(qe->chan); 03287 03288 starttime = (long) time(NULL); 03289 #ifdef HAVE_EPOLL 03290 for (epollo = outgoing; epollo; epollo = epollo->q_next) { 03291 if (epollo->chan) 03292 ast_poll_channel_add(in, epollo->chan); 03293 } 03294 #endif 03295 03296 while (*to && !peer) { 03297 int numlines, retry, pos = 1; 03298 struct ast_channel *watchers[AST_MAX_WATCHERS]; 03299 watchers[0] = in; 03300 start = NULL; 03301 03302 for (retry = 0; retry < 2; retry++) { 03303 numlines = 0; 03304 for (o = outgoing; o; o = o->q_next) { /* Keep track of important channels */ 03305 if (o->stillgoing) { /* Keep track of important channels */ 03306 stillgoing = 1; 03307 if (o->chan) { 03308 watchers[pos++] = o->chan; 03309 if (!start) 03310 start = o; 03311 else 03312 prev->call_next = o; 03313 prev = o; 03314 } 03315 } 03316 numlines++; 03317 } 03318 if (pos > 1 /* found */ || !stillgoing /* nobody listening */ || 03319 (qe->parent->strategy != QUEUE_STRATEGY_RINGALL) /* ring would not be delivered */) 03320 break; 03321 /* On "ringall" strategy we only move to the next penalty level 03322 when *all* ringing phones are done in the current penalty level */ 03323 ring_one(qe, outgoing, &numbusies); 03324 /* and retry... */ 03325 } 03326 if (pos == 1 /* not found */) { 03327 if (numlines == (numbusies + numnochan)) { 03328 ast_debug(1, "Everyone is busy at this time\n"); 03329 } else { 03330 ast_debug(3, "No one is answering queue '%s' (%d numlines / %d busies / %d failed channels)\n", queue, numlines, numbusies, numnochan); 03331 } 03332 *to = 0; 03333 return NULL; 03334 } 03335 03336 /* Poll for events from both the incoming channel as well as any outgoing channels */ 03337 winner = ast_waitfor_n(watchers, pos, to); 03338 03339 /* Service all of the outgoing channels */ 03340 for (o = start; o; o = o->call_next) { 03341 /* We go with a static buffer here instead of using ast_strdupa. Using 03342 * ast_strdupa in a loop like this one can cause a stack overflow 03343 */ 03344 char ochan_name[AST_CHANNEL_NAME]; 03345 if (o->chan) { 03346 ast_channel_lock(o->chan); 03347 ast_copy_string(ochan_name, o->chan->name, sizeof(ochan_name)); 03348 ast_channel_unlock(o->chan); 03349 } 03350 if (o->stillgoing && (o->chan) && (o->chan->_state == AST_STATE_UP)) { 03351 if (!peer) { 03352 ast_verb(3, "%s answered %s\n", ochan_name, inchan_name); 03353 if (update_connectedline) { 03354 if (o->pending_connected_update) { 03355 if (ast_channel_connected_line_macro(o->chan, in, &o->connected, 1, 0)) { 03356 ast_channel_update_connected_line(in, &o->connected, NULL); 03357 } 03358 } else if (!o->dial_callerid_absent) { 03359 ast_channel_lock(o->chan); 03360 ast_connected_line_copy_from_caller(&connected_caller, &o->chan->caller); 03361 ast_channel_unlock(o->chan); 03362 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER; 03363 ast_channel_update_connected_line(in, &connected_caller, NULL); 03364 ast_party_connected_line_free(&connected_caller); 03365 } 03366 } 03367 if (o->aoc_s_rate_list) { 03368 size_t encoded_size; 03369 struct ast_aoc_encoded *encoded; 03370 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) { 03371 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size); 03372 ast_aoc_destroy_encoded(encoded); 03373 } 03374 } 03375 peer = o; 03376 } 03377 } else if (o->chan && (o->chan == winner)) { 03378 03379 ast_copy_string(on, o->member->interface, sizeof(on)); 03380 ast_copy_string(membername, o->member->membername, sizeof(membername)); 03381 03382 if (!ast_strlen_zero(o->chan->call_forward) && !forwardsallowed) { 03383 ast_verb(3, "Forwarding %s to '%s' prevented.\n", inchan_name, o->chan->call_forward); 03384 numnochan++; 03385 do_hang(o); 03386 winner = NULL; 03387 continue; 03388 } else if (!ast_strlen_zero(o->chan->call_forward)) { 03389 struct ast_channel *original = o->chan; 03390 char tmpchan[256]; 03391 char *stuff; 03392 char *tech; 03393 03394 ast_copy_string(tmpchan, o->chan->call_forward, sizeof(tmpchan)); 03395 if ((stuff = strchr(tmpchan, '/'))) { 03396 *stuff++ = '\0'; 03397 tech = tmpchan; 03398 } else { 03399 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", o->chan->call_forward, o->chan->context); 03400 stuff = tmpchan; 03401 tech = "Local"; 03402 } 03403 03404 ast_cel_report_event(in, AST_CEL_FORWARD, NULL, o->chan->call_forward, NULL); 03405 03406 /* Before processing channel, go ahead and check for forwarding */ 03407 ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", inchan_name, tech, stuff, ochan_name); 03408 /* Setup parameters */ 03409 o->chan = ast_request(tech, in->nativeformats, in, stuff, &status); 03410 if (!o->chan) { 03411 ast_log(LOG_NOTICE, 03412 "Forwarding failed to create channel to dial '%s/%s'\n", 03413 tech, stuff); 03414 o->stillgoing = 0; 03415 numnochan++; 03416 } else { 03417 struct ast_party_redirecting redirecting; 03418 03419 ast_channel_lock(o->chan); 03420 while (ast_channel_trylock(in)) { 03421 CHANNEL_DEADLOCK_AVOIDANCE(o->chan); 03422 } 03423 ast_channel_inherit_variables(in, o->chan); 03424 ast_channel_datastore_inherit(in, o->chan); 03425 03426 ast_string_field_set(o->chan, accountcode, in->accountcode); 03427 03428 ast_channel_set_redirecting(o->chan, &original->redirecting, NULL); 03429 if (!o->chan->redirecting.from.number.valid 03430 || ast_strlen_zero(o->chan->redirecting.from.number.str)) { 03431 /* 03432 * The call was not previously redirected so it is 03433 * now redirected from this number. 03434 */ 03435 ast_party_number_free(&o->chan->redirecting.from.number); 03436 ast_party_number_init(&o->chan->redirecting.from.number); 03437 o->chan->redirecting.from.number.valid = 1; 03438 o->chan->redirecting.from.number.str = 03439 ast_strdup(S_OR(in->macroexten, in->exten)); 03440 } 03441 03442 o->chan->dialed.transit_network_select = in->dialed.transit_network_select; 03443 03444 ast_party_caller_copy(&o->chan->caller, &in->caller); 03445 ast_party_connected_line_copy(&o->chan->connected, &original->connected); 03446 03447 /* 03448 * We must unlock o->chan before calling 03449 * ast_channel_redirecting_macro, because we put o->chan into 03450 * autoservice there. That is pretty much a guaranteed 03451 * deadlock. This is why the handling of o->chan's lock may 03452 * seem a bit unusual here. 03453 */ 03454 ast_party_redirecting_init(&redirecting); 03455 ast_party_redirecting_copy(&redirecting, &o->chan->redirecting); 03456 ast_channel_unlock(o->chan); 03457 res = ast_channel_redirecting_macro(o->chan, in, &redirecting, 1, 0); 03458 if (res) { 03459 ast_channel_update_redirecting(in, &redirecting, NULL); 03460 } 03461 ast_party_redirecting_free(&redirecting); 03462 ast_channel_unlock(in); 03463 03464 update_connectedline = 1; 03465 03466 if (ast_call(o->chan, stuff, 0)) { 03467 ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n", 03468 tech, stuff); 03469 do_hang(o); 03470 numnochan++; 03471 } 03472 } 03473 /* Hangup the original channel now, in case we needed it */ 03474 ast_hangup(winner); 03475 continue; 03476 } 03477 f = ast_read(winner); 03478 if (f) { 03479 if (f->frametype == AST_FRAME_CONTROL) { 03480 switch (f->subclass.integer) { 03481 case AST_CONTROL_ANSWER: 03482 /* This is our guy if someone answered. */ 03483 if (!peer) { 03484 ast_verb(3, "%s answered %s\n", ochan_name, inchan_name); 03485 if (update_connectedline) { 03486 if (o->pending_connected_update) { 03487 if (ast_channel_connected_line_macro(o->chan, in, &o->connected, 1, 0)) { 03488 ast_channel_update_connected_line(in, &o->connected, NULL); 03489 } 03490 } else if (!o->dial_callerid_absent) { 03491 ast_channel_lock(o->chan); 03492 ast_connected_line_copy_from_caller(&connected_caller, &o->chan->caller); 03493 ast_channel_unlock(o->chan); 03494 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER; 03495 ast_channel_update_connected_line(in, &connected_caller, NULL); 03496 ast_party_connected_line_free(&connected_caller); 03497 } 03498 } 03499 if (o->aoc_s_rate_list) { 03500 size_t encoded_size; 03501 struct ast_aoc_encoded *encoded; 03502 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) { 03503 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size); 03504 ast_aoc_destroy_encoded(encoded); 03505 } 03506 } 03507 peer = o; 03508 } 03509 break; 03510 case AST_CONTROL_BUSY: 03511 ast_verb(3, "%s is busy\n", ochan_name); 03512 if (in->cdr) 03513 ast_cdr_busy(in->cdr); 03514 do_hang(o); 03515 endtime = (long) time(NULL); 03516 endtime -= starttime; 03517 rna(endtime * 1000, qe, on, membername, 0); 03518 if (qe->parent->strategy != QUEUE_STRATEGY_RINGALL) { 03519 if (qe->parent->timeoutrestart) 03520 *to = orig; 03521 /* Have enough time for a queue member to answer? */ 03522 if (*to > 500) { 03523 ring_one(qe, outgoing, &numbusies); 03524 starttime = (long) time(NULL); 03525 } 03526 } 03527 numbusies++; 03528 break; 03529 case AST_CONTROL_CONGESTION: 03530 ast_verb(3, "%s is circuit-busy\n", ochan_name); 03531 if (in->cdr) 03532 ast_cdr_busy(in->cdr); 03533 endtime = (long) time(NULL); 03534 endtime -= starttime; 03535 rna(endtime * 1000, qe, on, membername, 0); 03536 do_hang(o); 03537 if (qe->parent->strategy != QUEUE_STRATEGY_RINGALL) { 03538 if (qe->parent->timeoutrestart) 03539 *to = orig; 03540 if (*to > 500) { 03541 ring_one(qe, outgoing, &numbusies); 03542 starttime = (long) time(NULL); 03543 } 03544 } 03545 numbusies++; 03546 break; 03547 case AST_CONTROL_RINGING: 03548 ast_verb(3, "%s is ringing\n", ochan_name); 03549 03550 /* Start ring indication when the channel is ringing, if specified */ 03551 if (qe->ring_when_ringing) { 03552 ast_moh_stop(qe->chan); 03553 ast_indicate(qe->chan, AST_CONTROL_RINGING); 03554 } 03555 break; 03556 case AST_CONTROL_OFFHOOK: 03557 /* Ignore going off hook */ 03558 break; 03559 case AST_CONTROL_CONNECTED_LINE: 03560 if (!update_connectedline) { 03561 ast_verb(3, "Connected line update to %s prevented.\n", inchan_name); 03562 } else if (qe->parent->strategy == QUEUE_STRATEGY_RINGALL) { 03563 struct ast_party_connected_line connected; 03564 ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n", ochan_name, inchan_name); 03565 ast_party_connected_line_set_init(&connected, &o->connected); 03566 ast_connected_line_parse_data(f->data.ptr, f->datalen, &connected); 03567 ast_party_connected_line_set(&o->connected, &connected, NULL); 03568 ast_party_connected_line_free(&connected); 03569 o->pending_connected_update = 1; 03570 } else { 03571 if (ast_channel_connected_line_macro(o->chan, in, f, 1, 1)) { 03572 ast_indicate_data(in, AST_CONTROL_CONNECTED_LINE, f->data.ptr, f->datalen); 03573 } 03574 } 03575 break; 03576 case AST_CONTROL_AOC: 03577 { 03578 struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan); 03579 if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) { 03580 ast_aoc_destroy_decoded(o->aoc_s_rate_list); 03581 o->aoc_s_rate_list = decoded; 03582 } else { 03583 ast_aoc_destroy_decoded(decoded); 03584 } 03585 } 03586 break; 03587 case AST_CONTROL_REDIRECTING: 03588 if (!update_connectedline) { 03589 ast_verb(3, "Redirecting update to %s prevented\n", inchan_name); 03590 } else { 03591 ast_verb(3, "%s redirecting info has changed, passing it to %s\n", ochan_name, inchan_name); 03592 if (ast_channel_redirecting_macro(o->chan, in, f, 1, 1)) { 03593 ast_indicate_data(in, AST_CONTROL_REDIRECTING, f->data.ptr, f->datalen); 03594 } 03595 } 03596 break; 03597 default: 03598 ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer); 03599 break; 03600 } 03601 } 03602 ast_frfree(f); 03603 } else { /* ast_read() returned NULL */ 03604 endtime = (long) time(NULL) - starttime; 03605 rna(endtime * 1000, qe, on, membername, 1); 03606 do_hang(o); 03607 if (qe->parent->strategy != QUEUE_STRATEGY_RINGALL) { 03608 if (qe->parent->timeoutrestart) 03609 *to = orig; 03610 if (*to > 500) { 03611 ring_one(qe, outgoing, &numbusies); 03612 starttime = (long) time(NULL); 03613 } 03614 } 03615 } 03616 } 03617 } 03618 03619 /* If we received an event from the caller, deal with it. */ 03620 if (winner == in) { 03621 f = ast_read(in); 03622 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) { 03623 /* Got hung up */ 03624 *to = -1; 03625 if (f) { 03626 if (f->data.uint32) { 03627 in->hangupcause = f->data.uint32; 03628 } 03629 ast_frfree(f); 03630 } 03631 return NULL; 03632 } 03633 if ((f->frametype == AST_FRAME_DTMF) && caller_disconnect && (f->subclass.integer == '*')) { 03634 ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer); 03635 *to = 0; 03636 ast_frfree(f); 03637 return NULL; 03638 } 03639 if ((f->frametype == AST_FRAME_DTMF) && valid_exit(qe, f->subclass.integer)) { 03640 ast_verb(3, "User pressed digit: %c\n", f->subclass.integer); 03641 *to = 0; 03642 *digit = f->subclass.integer; 03643 ast_frfree(f); 03644 return NULL; 03645 } 03646 ast_frfree(f); 03647 } 03648 if (!*to) { 03649 for (o = start; o; o = o->call_next) 03650 rna(orig, qe, o->interface, o->member->membername, 1); 03651 } 03652 } 03653 03654 #ifdef HAVE_EPOLL 03655 for (epollo = outgoing; epollo; epollo = epollo->q_next) { 03656 if (epollo->chan) 03657 ast_poll_channel_del(in, epollo->chan); 03658 } 03659 #endif 03660 03661 return peer; 03662 }
| static int wait_our_turn | ( | struct queue_ent * | qe, | |
| int | ringing, | |||
| enum queue_result * | reason | |||
| ) | [static] |
The waiting areas for callers who are not actively calling members.
This function is one large loop. This function will return if a caller either exits the queue or it becomes that caller's turn to attempt calling queue members. Inside the loop, we service the caller with periodic announcements, holdtime announcements, etc. as configured in queues.conf
| 0 | if the caller's turn has arrived | |
| -1 | if the caller should exit the queue. |
Definition at line 3750 of file app_queue.c.
References call_queue::announcefrequency, ast_queue_log(), ast_waitfordigit(), queue_ent::chan, queue_ent::expire, get_member_status(), is_our_turn(), leave_queue(), call_queue::leavewhenempty, queue_ent::max_penalty, queue_ent::min_penalty, call_queue::name, queue_ent::opos, queue_ent::parent, call_queue::periodicannouncefrequency, queue_ent::pos, queue_ent::pr, QUEUE_LEAVEEMPTY, QUEUE_TIMEOUT, RECHECK, say_periodic_announcement(), say_position(), queue_ent::start, status, penalty_rule::time, ast_channel::uniqueid, update_qe_rule(), and valid_exit().
Referenced by queue_exec().
03751 { 03752 int res = 0; 03753 03754 /* This is the holding pen for callers 2 through maxlen */ 03755 for (;;) { 03756 03757 if (is_our_turn(qe)) 03758 break; 03759 03760 /* If we have timed out, break out */ 03761 if (qe->expire && (time(NULL) >= qe->expire)) { 03762 *reason = QUEUE_TIMEOUT; 03763 break; 03764 } 03765 03766 if (qe->parent->leavewhenempty) { 03767 int status = 0; 03768 03769 if ((status = get_member_status(qe->parent, qe->max_penalty, qe->min_penalty, qe->parent->leavewhenempty))) { 03770 *reason = QUEUE_LEAVEEMPTY; 03771 ast_queue_log(qe->parent->name, qe->chan->uniqueid, "NONE", "EXITEMPTY", "%d|%d|%ld", qe->pos, qe->opos, (long) time(NULL) - qe->start); 03772 leave_queue(qe); 03773 break; 03774 } 03775 } 03776 03777 /* Make a position announcement, if enabled */ 03778 if (qe->parent->announcefrequency && 03779 (res = say_position(qe,ringing))) 03780 break; 03781 03782 /* If we have timed out, break out */ 03783 if (qe->expire && (time(NULL) >= qe->expire)) { 03784 *reason = QUEUE_TIMEOUT; 03785 break; 03786 } 03787 03788 /* Make a periodic announcement, if enabled */ 03789 if (qe->parent->periodicannouncefrequency && 03790 (res = say_periodic_announcement(qe,ringing))) 03791 break; 03792 03793 /* see if we need to move to the next penalty level for this queue */ 03794 while (qe->pr && ((time(NULL) - qe->start) >= qe->pr->time)) { 03795 update_qe_rule(qe); 03796 } 03797 03798 /* If we have timed out, break out */ 03799 if (qe->expire && (time(NULL) >= qe->expire)) { 03800 *reason = QUEUE_TIMEOUT; 03801 break; 03802 } 03803 03804 /* Wait a second before checking again */ 03805 if ((res = ast_waitfordigit(qe->chan, RECHECK * 1000))) { 03806 if (res > 0 && !valid_exit(qe, res)) 03807 res = 0; 03808 else 03809 break; 03810 } 03811 03812 /* If we have timed out, break out */ 03813 if (qe->expire && (time(NULL) >= qe->expire)) { 03814 *reason = QUEUE_TIMEOUT; 03815 break; 03816 } 03817 } 03818 03819 return res; 03820 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "True Call Queueing" , .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, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_DEVSTATE_CONSUMER, .nonoptreq = "res_monitor", } [static] |
Definition at line 8200 of file app_queue.c.
char* app = "Queue" [static] |
Definition at line 739 of file app_queue.c.
char* app_aqm = "AddQueueMember" [static] |
Definition at line 741 of file app_queue.c.
char* app_pqm = "PauseQueueMember" [static] |
Definition at line 745 of file app_queue.c.
char* app_ql = "QueueLog" [static] |
Definition at line 749 of file app_queue.c.
char* app_rqm = "RemoveQueueMember" [static] |
Definition at line 743 of file app_queue.c.
char* app_upqm = "UnpauseQueueMember" [static] |
Definition at line 747 of file app_queue.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 8200 of file app_queue.c.
int autofill_default = 1 [static] |
struct autopause autopausesmodes[] [static] |
Referenced by autopause2int().
struct ast_cli_entry cli_queue[] [static] |
struct ast_event_sub* device_state_sub [static] |
struct ast_taskprocessor* devicestate_tps [static] |
Definition at line 723 of file app_queue.c.
| enum queue_result id |
Definition at line 789 of file app_queue.c.
Referenced by _sip_show_peers(), _skinny_show_devices(), _skinny_show_lines(), amixer_max(), ast_cc_extension_monitor_add_dialstring(), frame_trace_helper(), idemodulator(), pidf_validate_tuple(), and setamixer().
int montype_default = 0 [static] |
const char* const pm_family = "Queue/PersistentMembers" [static] |
const char qpm_cmd_usage[] [static] |
Initial value:
"Usage: queue pause member <channel> in <queue> reason <reason>\n"
Definition at line 7779 of file app_queue.c.
const char qsmp_cmd_usage[] [static] |
Initial value:
"Usage: queue set member penalty <channel> from <queue> <penalty>\n"
Definition at line 7785 of file app_queue.c.
struct ast_data_entry queue_data_providers[] [static] |
Initial value:
{
AST_DATA_ENTRY("asterisk/application/queue/list", &queues_data_provider),
}
Definition at line 8061 of file app_queue.c.
Referenced by load_module().
int queue_persistent_members = 0 [static] |
struct { ... } queue_results[] [static] |
Referenced by set_queue_result().
struct ast_datastore_info queue_transfer_info [static] |
Initial value:
{
.type = "queue_transfer",
.chan_fixup = queue_transfer_fixup,
.destroy = queue_transfer_destroy,
}
Definition at line 3999 of file app_queue.c.
Referenced by attended_transfer_occurred(), queue_transfer_fixup(), setup_transfer_datastore(), and try_calling().
struct ast_custom_function queueexists_function [static] |
Initial value:
{
.name = "QUEUE_EXISTS",
.read = queue_function_exists,
}
Definition at line 6237 of file app_queue.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function queuemembercount_dep [static] |
Initial value:
{
.name = "QUEUE_MEMBER_COUNT",
.read = queue_function_qac_dep,
}
Definition at line 6252 of file app_queue.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function queuemembercount_function [static] |
Initial value:
{
.name = "QUEUE_MEMBER",
.read = queue_function_qac,
}
Definition at line 6247 of file app_queue.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function queuememberlist_function [static] |
Initial value:
{
.name = "QUEUE_MEMBER_LIST",
.read = queue_function_queuememberlist,
}
Definition at line 6262 of file app_queue.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function queuememberpenalty_function [static] |
Initial value:
{
.name = "QUEUE_MEMBER_PENALTY",
.read = queue_function_memberpenalty_read,
.write = queue_function_memberpenalty_write,
}
Definition at line 6267 of file app_queue.c.
Referenced by load_module(), and unload_module().
struct ao2_container* queues [static] |
Definition at line 1030 of file app_queue.c.
Referenced by __queues_show(), add_to_queue(), clear_stats(), compare_weight(), complete_queue(), complete_queue_remove_member(), extension_state_cb(), find_queue_by_name_rt(), get_member_penalty(), handle_statechange(), join_queue(), leave_queue(), load_module(), load_realtime_queue(), manager_queues_status(), manager_queues_summary(), queue_function_queuememberlist(), queue_function_queuewaitingcount(), queue_function_var(), queues_data_provider_get(), reload_queue_members(), reload_queues(), reload_single_queue(), remove_from_queue(), set_member_paused(), set_member_penalty(), try_calling(), unload_module(), update_queue(), and update_realtime_members().
struct ast_data_handler queues_data_provider [static] |
Initial value:
{
.version = AST_DATA_HANDLER_VERSION,
.get = queues_data_provider_get
}
Definition at line 8056 of file app_queue.c.
struct ast_custom_function queuevar_function [static] |
Initial value:
{
.name = "QUEUE_VARIABLES",
.read = queue_function_var,
}
Definition at line 6242 of file app_queue.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function queuewaitingcount_function [static] |
Initial value:
{
.name = "QUEUE_WAITING_COUNT",
.read = queue_function_queuewaitingcount,
}
Definition at line 6257 of file app_queue.c.
Referenced by load_module(), and unload_module().
const char qum_cmd_usage[] [static] |
Initial value:
"Usage: queue unpause member <channel> in <queue> reason <reason>\n"
Definition at line 7782 of file app_queue.c.
int shared_lastcall = 1 [static] |
struct strategy strategies[] [static] |
Referenced by int2strat(), and strat2int().
| char* text |
Definition at line 790 of file app_queue.c.
Referenced by _sip_show_peer(), build_reply_digest(), check_auth(), festival_exec(), handle_response(), iconv_read(), method_match(), peers_data_provider_get(), process_sdp(), reqprep(), set_queue_result(), and sip_new().
int update_cdr = 0 [static] |
queues.conf [general] option
Definition at line 775 of file app_queue.c.
Referenced by login_exec().
int use_weight = 0 [static] |
1.5.9