Index: app_queue.c =================================================================== --- app_queue.c (revision 22265) +++ app_queue.c (working copy) @@ -3148,6 +3148,45 @@ return buf; } +static char *queue_function_qwc(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +{ + int count = 0; + struct ast_call_queue *q; + struct localuser *u; + struct member *m; + + LOCAL_USER_ACF_ADD(u); + + ast_copy_string(buf, "0", len); + + if (ast_strlen_zero(data)) { + ast_log(LOG_ERROR, "QUEUEWAITINGCOUNT requires an argument: queuename\n"); + LOCAL_USER_REMOVE(u); + return buf; + } + + ast_mutex_lock(&qlock); + + /* Find the right queue */ + for (q = queues; q; q = q->next) { + if (!strcasecmp(q->name, data)) { + ast_mutex_lock(&q->lock); + break; + } + } + + ast_mutex_unlock(&qlock); + + if (q) { + count = q->count; + ast_mutex_unlock(&q->lock); + } + + snprintf(buf, len, "%d", count); + LOCAL_USER_REMOVE(u); + return buf; +} + static struct ast_custom_function queueagentcount_function = { .name = "QUEUEAGENTCOUNT", .synopsis = "Count number of agents answering a queue", @@ -3155,6 +3194,13 @@ .read = queue_function_qac, }; +static struct ast_custom_function queuewaitingcount_function = { + .name = "QUEUEWAITINGCOUNT", + .synopsis = "Count number of callers waiting in a queue", + .syntax = "QUEUEWAITINGCOUNT()", + .read = queue_function_qwc, +}; + static void reload_queues(void) { struct ast_call_queue *q, *ql, *qn; @@ -3808,6 +3854,7 @@ res |= ast_unregister_application(app_pqm); res |= ast_unregister_application(app_upqm); res |= ast_custom_function_unregister(&queueagentcount_function); + res |= ast_custom_function_unregister(&queuewaitingcount_function); res |= ast_unregister_application(app); STANDARD_HANGUP_LOCALUSERS; @@ -3835,6 +3882,7 @@ res |= ast_register_application(app_pqm, pqm_exec, app_pqm_synopsis, app_pqm_descrip) ; res |= ast_register_application(app_upqm, upqm_exec, app_upqm_synopsis, app_upqm_descrip) ; res |= ast_custom_function_register(&queueagentcount_function); + res |= ast_custom_function_register(&queuewaitingcount_function); if (!res) { reload_queues();