Index: apps/app_queue.c =================================================================== --- apps/app_queue.c (revision 66315) +++ apps/app_queue.c (working copy) @@ -3910,6 +3910,124 @@ return 0; } +/*! \brief Dialplan function QUEUE_MEMBER_PENALTY() + * Gets the members penalty. */ +static int queue_function_memberpenalty_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) { + struct call_queue *q; + struct member *mem; + int foundqueue=0; + + /* Make sure the returned value on error is NULL. */ + buf[0] = '\0'; + + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(queuename); + AST_APP_ARG(interface); + ); + + if (ast_strlen_zero(data)) { + ast_log(LOG_ERROR, "Missing argument. QUEUE_MEMBER_PENALTY(,)\n"); + return -1; + } + + AST_STANDARD_APP_ARGS(args, data); + + if (args.argc < 2) { + ast_log(LOG_ERROR, "Missing argument. QUEUE_MEMBER_PENALTY(,)\n"); + return -1; + } + + AST_LIST_LOCK(&queues); + AST_LIST_TRAVERSE(&queues, q, list) { + if (!strcasecmp(q->name, args.queuename)) { + foundqueue++; + ast_mutex_lock(&q->lock); + if ((mem = interface_exists(q, args.interface))) { + sprintf(buf, "%d", mem->penalty); + ast_mutex_unlock(&q->lock); + AST_LIST_UNLOCK(&queues); + return 0; + } + ast_mutex_unlock(&q->lock); + } + } + AST_LIST_UNLOCK(&queues); + + if (foundqueue) { + ast_log (LOG_ERROR, "Invalid interface name\n"); + } else { + ast_log (LOG_ERROR, "Invalid queuename\n"); + } + + return 0; +} + +/*! Dialplan function QUEUE_MEMBER_PENALTY() + * Sets the members penalty. */ +static int queue_function_memberpenalty_write(struct ast_channel *chan, const char *cmd, char *data, const char *value) { + struct call_queue *q; + struct member *mem; + int foundqueue=0; + int penalty; + + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(queuename); + AST_APP_ARG(interface); + ); + + if (ast_strlen_zero(data)) { + ast_log(LOG_ERROR, "Missing argument. QUEUE_MEMBER_PENALTY(,)\n"); + return -1; + } + + AST_STANDARD_APP_ARGS(args, data); + + if (args.argc < 2) { + ast_log(LOG_ERROR, "Missing argument. QUEUE_MEMBER_PENALTY(,)\n"); + return -1; + } + + penalty = atoi(value); + if (penalty < 0) { + ast_log(LOG_ERROR, "Invalid penalty\n"); + return -1; + } + + AST_LIST_LOCK(&queues); + AST_LIST_TRAVERSE(&queues, q, list) { + if (!strcasecmp(q->name, args.queuename)) { + foundqueue++; + ast_mutex_lock(&q->lock); + if ((mem = interface_exists(q, args.interface))) { + mem->penalty = penalty; + + ast_queue_log(q->name, "NONE", mem->interface, "PENALTY", "%d", penalty); + + manager_event(EVENT_FLAG_AGENT, "QueueMemberPenalty", + "Queue: %s\r\n" + "Location: %s\r\n" + "Penalty: %d\r\n", + q->name, mem->interface, penalty); + + + ast_mutex_unlock(&q->lock); + AST_LIST_UNLOCK(&queues); + return 0; + } + ast_mutex_unlock(&q->lock); + } + } + AST_LIST_UNLOCK(&queues); + + if (foundqueue) { + ast_log (LOG_ERROR, "Invalid interface name\n"); + } else { + ast_log (LOG_ERROR, "Invalid queuename\n"); + } + + return 0; +} + static struct ast_custom_function queuevar_function = { .name = "QUEUE_VARIABLES", .synopsis = "Return Queue information in variables", @@ -3955,6 +4073,16 @@ .read = queue_function_queuememberlist, }; +static struct ast_custom_function queuememberpenalty_function = { + .name = "QUEUE_MEMBER_PENALTY", + .synopsis = "Gets or sets queue members penalty.", + .syntax = "QUEUE_MEMBER_PENALTY([],)", + .desc = +"Gets or sets queue members penalty\n", + .read = queue_function_memberpenalty_read, + .write = queue_function_memberpenalty_write, +}; + static int reload_queues(void) { struct call_queue *q; @@ -4788,6 +4916,7 @@ res |= ast_custom_function_register(&queuemembercount_function); res |= ast_custom_function_register(&queuememberlist_function); res |= ast_custom_function_register(&queuewaitingcount_function); + res |= ast_custom_function_register(&queuememberpenalty_function); res |= ast_devstate_add(statechange_queue, NULL); return res;