[asterisk-commits] mmichelson: branch mmichelson/queue-penalty r93344 - /team/mmichelson/queue-p...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 17 15:50:47 CST 2007


Author: mmichelson
Date: Mon Dec 17 15:50:47 2007
New Revision: 93344

URL: http://svn.digium.com/view/asterisk?view=rev&rev=93344
Log:
This batch of code defines the structure for storing penaltychange rules in the queue. It also contains
the code to parse the config file and insert the rules into the list. The list is ordered from earliest time
to latest. This gives me an idea for a "trick" to document in queues.conf.sample


Modified:
    team/mmichelson/queue-penalty/apps/app_queue.c

Modified: team/mmichelson/queue-penalty/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/queue-penalty/apps/app_queue.c?view=diff&rev=93344&r1=93343&r2=93344
==============================================================================
--- team/mmichelson/queue-penalty/apps/app_queue.c (original)
+++ team/mmichelson/queue-penalty/apps/app_queue.c Mon Dec 17 15:50:47 2007
@@ -452,6 +452,14 @@
 	int membercount;
 	struct queue_ent *head;             /*!< Head of the list of callers */
 	AST_LIST_ENTRY(call_queue) list;    /*!< Next call queue */
+	AST_LIST_HEAD_NOLOCK_STATIC(rules, penalty_rule); /*!< The list of penalty rules to invoke */
+};
+
+static struct penalty_rule {
+	int time;							/*!< Number of seconds that need to pass before applying this rule */
+	int value;                          /*!< The amount specified in the penalty rule */
+	int relative;						/*!< Is this a relative amount? 1 for relative, 0 for absolute */
+	AST_LIST_ENTRY(penalty_rule) list;  /*!< Next penalty_rule */
 };
 
 static struct ao2_container *queues;
@@ -968,6 +976,67 @@
 	while ((curint = AST_LIST_REMOVE_HEAD(&interfaces, list)))
 		ast_free(curint);
 	AST_LIST_UNLOCK(&interfaces);
+}
+
+static int insert_penaltychange (struct call_queue *q, const char *content, const int linenum)
+{
+	char *timestr, *changestr, *contentdup;
+	struct penalty_rule *pr = NULL, *iter;
+	int time, change, inserted = 0;
+
+	if (!(pr = ast_calloc(1, sizeof(*pr)))) {
+		ast_log(LOG_ERROR, "Cannot allocate memory for penaltychange rule at line %d!\n", linenum);
+		return -1;
+	}
+
+	contentdup = ast_strdupa(content);
+	
+	if(!(changestr = strchr(contentdup, ','))) {
+		ast_log(LOG_WARNING, "Improperly formatted penaltychange rule at line %d. Ignoring.\n", linenum);
+		return -1;
+	}
+	
+	*changestr++ = '\0';
+	timestr = contentdup;
+
+	/*Let's get the number of seconds first...*/
+	if((time = atoi(timestr)) < 0) {
+		ast_log(LOG_WARNING, "Improper time parameter specified for penaltychange rule at line %d. Ignoring.\n", linenum);
+		ast_free(pr);
+		return -1;
+	}
+
+	pr->time = time;
+
+	/*Now on to the change*/
+	if(*changeistr == '+' || *changestr == '-') {
+		pr->relative = 1;
+		changestr++;
+	}
+
+	if((change = atoi(changestr)) < 0) {
+		ast_log(LOG_WARNING, "Improper change parameter specified for penaltychange rule at line %d. Ignoring.\n", linenum);
+		ast_free(pr);
+		return -1;
+	}
+
+	pr->change = change;
+
+	/*We have the rule made, now we need to insert it where it belongs*/
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&q->rules, iter, list) {
+		if(pr->time < iter->time) {
+			AST_LIST_INSERT_BEFORE_CURRENT(pr, list);
+			inserted = 1;
+			break;
+		}
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+
+	if(!inserted) {
+		AST_LIST_INSERT_TAIL(&q->rules, pr);
+	}
+
+	return 0;
 }
 
 /*! \brief Configure a queue parameter.
@@ -1131,6 +1200,8 @@
 		   we will not see any effect on use_weight until next reload. */
 	} else if (!strcasecmp(param, "timeoutrestart")) {
 		q->timeoutrestart = ast_true(val);
+	} else if (!strcasecmp(param, "penaltychange" )) {
+		insert_penaltychange(q, val, linenum);
 	} else if (failunknown) {
 		if (linenum >= 0) {
 			ast_log(LOG_WARNING, "Unknown keyword in queue '%s': %s at line %d of queues.conf\n",




More information about the asterisk-commits mailing list