[Asterisk-code-review] app queue: Enable set the wrapuptime from AddQueueMember app... (asterisk[master])
Rodrigo Ramirez Norambuena
asteriskteam at digium.com
Tue Dec 11 08:22:26 CST 2018
Rodrigo Ramirez Norambuena has uploaded this change for review. ( https://gerrit.asterisk.org/10785
Change subject: app_queue: Enable set the wrapuptime from AddQueueMember application
......................................................................
app_queue: Enable set the wrapuptime from AddQueueMember application
This change add ability to set the wrapuptime per-member using the
AddQueueMember application.
The feature to set wrapuptime per member was include in the issue
ASTERISK-27483 for static member by configuration file and was not
added to set from AddQueueMember.
ASTERISK-28055 #close
Change-Id: I7c7ee4a6f804922cd7c42cb02eea26eb3806c6cf
---
M apps/app_queue.c
1 file changed, 56 insertions(+), 20 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/85/10785/1
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 136dec5..e70e89e 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -325,6 +325,7 @@
<parameter name="options" />
<parameter name="membername" />
<parameter name="stateinterface" />
+ <parameter name="wrapuptime" />
</syntax>
<description>
<para>Dynamically adds interface to an existing queue. If the interface is
@@ -2274,7 +2275,7 @@
static struct ast_json *queue_member_blob_create(struct call_queue *q, struct member *mem)
{
- return ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: i, s: i, s: i, s: i, s: i, s: i, s: i, s: s, s: i}",
+ return ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: i, s: i, s: i, s: i, s: i, s: i, s: i, s: s, s: i, s: i}",
"Queue", q->name,
"MemberName", mem->membername,
"Interface", mem->interface,
@@ -2288,7 +2289,8 @@
"Status", mem->status,
"Paused", mem->paused,
"PausedReason", mem->reason_paused,
- "Ringinuse", mem->ringinuse);
+ "Ringinuse", mem->ringinuse,
+ "Wrapuptime", mem->wrapuptime);
}
/*! \brief Check if members are available
@@ -2693,7 +2695,7 @@
}
/*! \brief allocate space for new queue member and set fields based on parameters passed */
-static struct member *create_queue_member(const char *interface, const char *membername, int penalty, int paused, const char *state_interface, int ringinuse)
+static struct member *create_queue_member(const char *interface, const char *membername, int penalty, int paused, const char *state_interface, int ringinuse, int wrapuptime)
{
struct member *cur;
@@ -2701,6 +2703,7 @@
cur->ringinuse = ringinuse;
cur->penalty = penalty;
cur->paused = paused;
+ cur->wrapuptime = wrapuptime;
if (paused) {
time(&cur->lastpause); /* Update time of last pause */
}
@@ -3481,7 +3484,7 @@
/* Create a new member */
if (!found) {
- if ((m = create_queue_member(interface, membername, penalty, paused, state_interface, ringinuse))) {
+ if ((m = create_queue_member(interface, membername, penalty, paused, state_interface, ringinuse, wrapuptime))) {
m->dead = 0;
m->realtime = 1;
ast_copy_string(m->rt_uniqueid, rt_uniqueid, sizeof(m->rt_uniqueid));
@@ -7280,14 +7283,15 @@
continue;
}
- ast_str_append(&value, 0, "%s%s;%d;%d;%s;%s;%s",
+ ast_str_append(&value, 0, "%s%s;%d;%d;%s;%s;%s;%d",
ast_str_strlen(value) ? "|" : "",
cur_member->interface,
cur_member->penalty,
cur_member->paused,
cur_member->membername,
cur_member->state_interface,
- cur_member->reason_paused);
+ cur_member->reason_paused,
+ cur_member->wrapuptime);
ao2_ref(cur_member, -1);
}
@@ -7364,7 +7368,7 @@
* \retval RES_EXISTS queue exists but no members
* \retval RES_OUT_OF_MEMORY queue exists but not enough memory to create member
*/
-static int add_to_queue(const char *queuename, const char *interface, const char *membername, int penalty, int paused, int dump, const char *state_interface, const char *reason_paused)
+static int add_to_queue(const char *queuename, const char *interface, const char *membername, int penalty, int paused, int dump, const char *state_interface, const char *reason_paused, int wrapuptime)
{
struct call_queue *q;
struct member *new_member, *old_member;
@@ -7378,7 +7382,7 @@
ao2_lock(q);
if ((old_member = interface_exists(q, interface)) == NULL) {
- if ((new_member = create_queue_member(interface, membername, penalty, paused, state_interface, q->ringinuse))) {
+ if ((new_member = create_queue_member(interface, membername, penalty, paused, state_interface, q->ringinuse, wrapuptime))) {
new_member->dynamic = 1;
if (reason_paused) {
ast_copy_string(new_member->reason_paused, reason_paused, sizeof(new_member->reason_paused));
@@ -7770,6 +7774,8 @@
int penalty = 0;
char *paused_tok;
int paused = 0;
+ char *wrapuptime_tok;
+ int wrapuptime = 0;
char *reason_paused;
struct ast_db_entry *db_tree;
struct ast_db_entry *entry;
@@ -7818,6 +7824,7 @@
membername = strsep(&member, ";");
state_interface = strsep(&member, ";");
reason_paused = strsep(&member, ";");
+ wrapuptime_tok = strsep(&member, ";");
if (!penalty_tok) {
ast_log(LOG_WARNING, "Error parsing persistent member string for '%s' (penalty)\n", queue_name);
@@ -7839,10 +7846,18 @@
break;
}
- ast_debug(1, "Reload Members: Queue: %s Member: %s Name: %s Penalty: %d Paused: %d ReasonPause: %s\n",
- queue_name, interface, membername, penalty, paused, reason_paused);
+ if (!ast_strlen_zero(wrapuptime_tok)) {
+ wrapuptime = strtol(wrapuptime_tok, NULL, 10);
+ if (errno == ERANGE) {
+ ast_log(LOG_WARNING, "Error converting wrapuptime: %s: Out of range.\n", wrapuptime_tok);
+ break;
+ }
+ }
- if (add_to_queue(queue_name, interface, membername, penalty, paused, 0, state_interface, reason_paused) == RES_OUTOFMEMORY) {
+ ast_debug(1, "Reload Members: Queue: %s Member: %s Name: %s Penalty: %d Paused: %d ReasonPause: %s Wrapuptime: %d\n",
+ queue_name, interface, membername, penalty, paused, reason_paused, wrapuptime);
+
+ if (add_to_queue(queue_name, interface, membername, penalty, paused, 0, state_interface, reason_paused, wrapuptime) == RES_OUTOFMEMORY) {
ast_log(LOG_ERROR, "Out of Memory when reloading persistent queue member\n");
break;
}
@@ -8004,7 +8019,7 @@
static int aqm_exec(struct ast_channel *chan, const char *data)
{
int res=-1;
- char *parse, *temppos = NULL;
+ char *parse, *tmp, *temppos = NULL;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(queuename);
AST_APP_ARG(interface);
@@ -8012,11 +8027,13 @@
AST_APP_ARG(options);
AST_APP_ARG(membername);
AST_APP_ARG(state_interface);
+ AST_APP_ARG(wrapuptime);
);
int penalty = 0;
+ int wrapuptime;
if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename[,interface[,penalty[,options[,membername[,stateinterface]]]]])\n");
+ ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename[,interface[,penalty[,options[,membername[,stateinterface][,wrapuptime]]]]])\n");
return -1;
}
@@ -8039,7 +8056,18 @@
}
}
- switch (add_to_queue(args.queuename, args.interface, args.membername, penalty, 0, queue_persistent_members, args.state_interface, NULL)) {
+ if (!ast_strlen_zero(args.wrapuptime)) {
+ tmp = args.wrapuptime;
+ ast_strip(tmp);
+ wrapuptime = atoi(tmp);
+ if (wrapuptime < 0) {
+ wrapuptime = 0;
+ }
+ } else {
+ wrapuptime = 0;
+ }
+
+ switch (add_to_queue(args.queuename, args.interface, args.membername, penalty, 0, queue_persistent_members, args.state_interface, NULL, wrapuptime)) {
case RES_OKAY:
if (ast_strlen_zero(args.membername) || !log_membername_as_agent) {
ast_queue_log(args.queuename, ast_channel_uniqueid(chan), args.interface, "ADDMEMBER", "%s", "");
@@ -9284,7 +9312,7 @@
ast_copy_string(tmpmem.interface, interface, sizeof(tmpmem.interface));
cur = ao2_find(q->members, &tmpmem, OBJ_POINTER);
- if ((newm = create_queue_member(interface, membername, penalty, cur ? cur->paused : 0, state_interface, ringinuse))) {
+ if ((newm = create_queue_member(interface, membername, penalty, cur ? cur->paused : 0, state_interface, ringinuse, wrapuptime))) {
newm->wrapuptime = wrapuptime;
if (cur) {
/* Round Robin Queue Position must be copied if this is replacing an existing member */
@@ -10097,11 +10125,12 @@
"Status: %d\r\n"
"Paused: %d\r\n"
"PausedReason: %s\r\n"
+ "Wrapuptime: %d\r\n"
"%s"
"\r\n",
q->name, mem->membername, mem->interface, mem->state_interface, mem->dynamic ? "dynamic" : "static",
mem->penalty, mem->calls, (int)mem->lastcall, (int)mem->lastpause, mem->starttime ? 1 : 0, mem->status,
- mem->paused, mem->reason_paused, idText);
+ mem->paused, mem->reason_paused, mem->wrapuptime, idText);
++q_items;
}
ao2_ref(mem, -1);
@@ -10146,8 +10175,8 @@
static int manager_add_queue_member(struct mansession *s, const struct message *m)
{
- const char *queuename, *interface, *penalty_s, *paused_s, *membername, *state_interface;
- int paused, penalty = 0;
+ const char *queuename, *interface, *penalty_s, *paused_s, *membername, *state_interface, *wrapuptime_s;
+ int paused, penalty, wrapuptime = 0;
queuename = astman_get_header(m, "Queue");
interface = astman_get_header(m, "Interface");
@@ -10155,6 +10184,7 @@
paused_s = astman_get_header(m, "Paused");
membername = astman_get_header(m, "MemberName");
state_interface = astman_get_header(m, "StateInterface");
+ wrapuptime_s = astman_get_header(m, "Wrapuptime");
if (ast_strlen_zero(queuename)) {
astman_send_error(s, m, "'Queue' not specified.");
@@ -10172,13 +10202,19 @@
penalty = 0;
}
+ if (ast_strlen_zero(wrapuptime_s)) {
+ wrapuptime = 0;
+ } else if (sscanf(wrapuptime_s, "%30d", &wrapuptime) != 1 || wrapuptime < 0) {
+ wrapuptime = 0;
+ }
+
if (ast_strlen_zero(paused_s)) {
paused = 0;
} else {
paused = abs(ast_true(paused_s));
}
- switch (add_to_queue(queuename, interface, membername, penalty, paused, queue_persistent_members, state_interface, NULL)) {
+ switch (add_to_queue(queuename, interface, membername, penalty, paused, queue_persistent_members, state_interface, NULL, wrapuptime)) {
case RES_OKAY:
if (ast_strlen_zero(membername) || !log_membername_as_agent) {
ast_queue_log(queuename, "MANAGER", interface, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
@@ -10528,7 +10564,7 @@
state_interface = a->argv[11];
}
- switch (add_to_queue(queuename, interface, membername, penalty, 0, queue_persistent_members, state_interface, NULL)) {
+ switch (add_to_queue(queuename, interface, membername, penalty, 0, queue_persistent_members, state_interface, NULL, 0)) {
case RES_OKAY:
if (ast_strlen_zero(membername) || !log_membername_as_agent) {
ast_queue_log(queuename, "CLI", interface, "ADDMEMBER", "%s", "");
--
To view, visit https://gerrit.asterisk.org/10785
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7c7ee4a6f804922cd7c42cb02eea26eb3806c6cf
Gerrit-Change-Number: 10785
Gerrit-PatchSet: 1
Gerrit-Owner: Rodrigo Ramirez Norambuena <a at rodrigoramirez.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181211/45c3e89b/attachment-0001.html>
More information about the asterisk-code-review
mailing list