Index: apps/app_queue.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_queue.c,v retrieving revision 1.154 diff -u -r1.154 app_queue.c --- apps/app_queue.c 27 Jul 2005 23:05:52 -0000 1.154 +++ apps/app_queue.c 30 Jul 2005 20:10:36 -0000 @@ -72,6 +72,7 @@ #include "asterisk/causes.h" #include "asterisk/astdb.h" #include "asterisk/devicestate.h" +#include "asterisk/version.h" #define QUEUE_STRATEGY_RINGALL 0 #define QUEUE_STRATEGY_ROUNDROBIN 1 @@ -178,6 +179,15 @@ "same way, except it unpauses instead of pausing the given interface.\n" "Example: UnpauseQueueMember(|SIP/3000)\n"; +#if (ASTERISK_VERSION_NUM < 10200) +static char *app_iqm = "IsQueueMember"; +static char *app_iqm_synopsis = "Checks if a channel is a member of a queue"; +static char *app_iqm_descrip = +" IsQueueMember(=queuename|interface):\n" +"Sets to 1 if the requested interface is a member of \n" +"or 0 otherwise. Always returns 0.\n"; +#endif + /* Persistent Members astdb family */ static const char *pm_family = "/Queue/PersistentMembers"; /* The maximum lengh of each persistent member queue database entry */ @@ -2904,6 +2914,7 @@ return res; } +#if (ASTERISK_VERSION_NUM > 10199) static char *queue_function_qac(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { int count = 0; @@ -2945,6 +2956,63 @@ return buf; } +static char *queue_function_iqm(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +{ + struct ast_call_queue *q; + char *queuename, *interface; + struct localuser *u; + + LOCAL_USER_ACF_ADD(u); + + if (!data) { + ast_log(LOG_WARNING, "ISQUEUEMEMBER requires an argument (|)\n"); + strncpy(buf, "0", len - 1); + LOCAL_USER_REMOVE(u); + return buf; + } + + queuename = ast_strdupa(data); + if (!queuename) { + ast_log(LOG_ERROR, "Out of memory\n"); + strncpy(buf, "0", len - 1); + LOCAL_USER_REMOVE(u); + return buf; + } + + interface = strchr(queuename, '|'); + if (interface) { + *interface = '\0'; + interface++; + } else { + ast_log(LOG_WARNING, "ISQUEUEMEMBER requires an argument (|)\n"); + strncpy(buf, "0", len - 1); + LOCAL_USER_REMOVE(u); + return buf; + } + + strncpy(buf, "0", len - 1); + if (ast_strlen_zero(queuename)) { + ast_mutex_lock(&qlock); + for (q=queues; q; q=q->next) { + if (interface_exists(q, interface)) { + strncpy(buf, "1", len - 1); + break; + } + } + ast_mutex_unlock(&qlock); + } else { + ast_mutex_lock(&qlock); + for (q=queues; q; q=q->next) { + if (strcasecmp(q->name, queuename) && interface_exists(q, interface)) { + strncpy(buf, "1", len - 1); + break; + } + } + ast_mutex_unlock(&qlock); + } + return buf; +} + static struct ast_custom_function queueagentcount_function = { .name = "QUEUEAGENTCOUNT", .synopsis = "Count number of agents answering a queue", @@ -2952,6 +3020,77 @@ .read = queue_function_qac, }; +static struct ast_custom_function isqueuemember_function = { + .name = "ISQUEUEMEMBER", + .synopsis = "Check if specified channel is a member of a queue", + .syntax = "ISQUEUEMEMBER(|)", + .read = queue_function_iqm, +}; +#else +static int iqm_exec(struct ast_channel *chan, void *data) +{ + struct ast_call_queue *q; + char *varname, *queuename, *interface; + struct localuser *u; + + if (!data) { + ast_log(LOG_WARNING, "IsQueueMember requires an argument (=|)\n"); + return 0; + } + + varname = ast_strdupa((char *)data); + if (!varname) { + ast_log(LOG_ERROR, "Out of memory\n"); + return 0; + } + LOCAL_USER_ADD(u); + + queuename = strchr(varname, '='); + if (queuename) { + *queuename = '\0'; + queuename++; + + interface = strchr(queuename, '|'); + if (interface) { + *interface = '\0'; + interface++; + } + + if ((!interface) || ast_strlen_zero(interface)) { + ast_log(LOG_WARNING, "IsQueueMember requires an argument (=|)\n"); + LOCAL_USER_REMOVE(u); + return 0; + } + } else { + ast_log(LOG_WARNING, "IsQueueMember requires an argument (=|)\n"); + LOCAL_USER_REMOVE(u); + return 0; + } + + pbx_builtin_setvar_helper(chan, varname, "0"); + if (ast_strlen_zero(queuename)) { + ast_mutex_lock(&qlock); + for (q=queues; q; q=q->next) { + if (interface_exists(q, interface)) { + pbx_builtin_setvar_helper(chan, varname, "1"); + break; + } + } + ast_mutex_unlock(&qlock); + } else { + ast_mutex_lock(&qlock); + for (q=queues; q; q=q->next) { + if (strcasecmp(q->name, queuename) && interface_exists(q, interface)) { + pbx_builtin_setvar_helper(chan, varname, "0"); + break; + } + } + ast_mutex_unlock(&qlock); + } + return 0; +} +#endif + static void reload_queues(void) { struct ast_call_queue *q, *ql, *qn; @@ -3621,7 +3760,12 @@ ast_unregister_application(app_rqm); ast_unregister_application(app_pqm); ast_unregister_application(app_upqm); +#if (ASTERISK_VERSION_NUM > 10199) ast_custom_function_unregister(&queueagentcount_function); + ast_custom_function_unregister(&isqueuemember_function); +#else + ast_unregister_function(app_iqm); +#endif return ast_unregister_application(app); } @@ -3644,7 +3788,12 @@ ast_register_application(app_rqm, rqm_exec, app_rqm_synopsis, app_rqm_descrip) ; ast_register_application(app_pqm, pqm_exec, app_pqm_synopsis, app_pqm_descrip) ; ast_register_application(app_upqm, upqm_exec, app_upqm_synopsis, app_upqm_descrip) ; +#if (ASTERISK_VERSION_NUM > 10199) ast_custom_function_register(&queueagentcount_function); + ast_custom_function_register(&isqueuemember_function); +#else + ast_register_application(app_iqm, iqm_exec, app_iqm_synopsis, app_iqm_descrip); +#endif } reload_queues();