[asterisk-commits] anthonyl: branch anthonyl/7864-1dot4 r43685 - /team/anthonyl/7864-1dot4/apps/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Sep 26 12:16:12 MST 2006


Author: anthonyl
Date: Tue Sep 26 14:16:11 2006
New Revision: 43685

URL: http://svn.digium.com/view/asterisk?rev=43685&view=rev
Log:
patched

Modified:
    team/anthonyl/7864-1dot4/apps/app_queue.c

Modified: team/anthonyl/7864-1dot4/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/7864-1dot4/apps/app_queue.c?rev=43685&r1=43684&r2=43685&view=diff
==============================================================================
--- team/anthonyl/7864-1dot4/apps/app_queue.c (original)
+++ team/anthonyl/7864-1dot4/apps/app_queue.c Tue Sep 26 14:16:11 2006
@@ -340,7 +340,7 @@
 #define QUEUE_EVENT_VARIABLES 3
 
 struct call_queue {
-	ast_mutex_t lock;	
+	ast_mutex_t lock;
 	char name[80];                      /*!< Name */
 	char moh[80];                       /*!< Music On Hold class to be used */
 	char announce[80];                  /*!< Announcement to play when call is answered */
@@ -393,7 +393,7 @@
 	int rrpos;                          /*!< Round Robin - position */
 	int memberdelay;                    /*!< Seconds to delay connecting member to caller */
 	int autofill;                       /*!< Ignore the head call status and ring an available agent */
-	
+
 	struct member *members;             /*!< Head of the list of members */
 	struct queue_ent *head;             /*!< Head of the list of callers */
 	AST_LIST_ENTRY(call_queue) list;    /*!< Next call queue */
@@ -475,10 +475,12 @@
 	QUEUE_NORMAL
 };
 
-static enum queue_member_status get_member_status(const struct call_queue *q, int max_penalty)
+static enum queue_member_status get_member_status(struct call_queue *q, int max_penalty)
 {
 	struct member *member;
 	enum queue_member_status result = QUEUE_NO_MEMBERS;
+
+	ast_mutex_lock(&q->lock);
 
 	for (member = q->members; member; member = member->next) {
 		if (max_penalty && (member->penalty > max_penalty))
@@ -494,10 +496,12 @@
 			result = QUEUE_NO_REACHABLE_MEMBERS;
 			break;
 		default:
+			ast_mutex_unlock(&q->lock);
 			return QUEUE_NORMAL;
 		}
 	}
-	
+
+	ast_mutex_unlock(&q->lock);
 	return result;
 }
 
@@ -599,7 +603,7 @@
 static struct member *create_queue_member(char *interface, const char *membername, int penalty, int paused)
 {
 	struct member *cur;
-	
+
 	if ((cur = ast_calloc(1, sizeof(*cur)))) {
 		cur->penalty = penalty;
 		cur->paused = paused;
@@ -686,7 +690,7 @@
 
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Adding %s to the list of interfaces that make up all of our queue members.\n", interface);
-	
+
 	if ((curint = ast_calloc(1, sizeof(*curint)))) {
 		ast_copy_string(curint->interface, interface, sizeof(curint->interface));
 		AST_LIST_INSERT_HEAD(&interfaces, curint, list);
@@ -763,7 +767,7 @@
 	char *c, *lastc;
 	char buff[80];
 
-	if (!strcasecmp(param, "musicclass") || 
+	if (!strcasecmp(param, "musicclass") ||
 		!strcasecmp(param, "music") || !strcasecmp(param, "musiconhold")) {
 		ast_copy_string(q->moh, val, sizeof(q->moh));
 	} else if (!strcasecmp(param, "announce")) {
@@ -1317,7 +1321,7 @@
 				if (res && valid_exit(qe, res))
 					goto playout;
 			}
-			
+
 			res = play_file(qe->chan, qe->parent->sound_minutes);
 			if (res && valid_exit(qe, res))
 				goto playout;
@@ -1407,7 +1411,7 @@
 	}
 	ast_mutex_unlock(&q->lock);
 
-	if (q->dead && !q->count) {	
+	if (q->dead && !q->count) {
 		/* It's dead and nobody is in it, so kill it */
 		AST_LIST_LOCK(&queues);
 		AST_LIST_REMOVE(&queues, q, list);
@@ -1482,7 +1486,7 @@
 	struct call_queue *q;
 	struct member *mem;
 	int found = 0;
-	
+
 	/* &qlock and &rq->lock already set by try_calling()
 	 * to solve deadlock */
 	AST_LIST_TRAVERSE(&queues, q, list) {
@@ -1618,7 +1622,7 @@
 		return 0;
 	} else if (status != tmp->oldstatus)
 		update_dial_status(qe->parent, tmp->member, status);
-	
+
 	tmp->chan->appl = "AppQueue";
 	tmp->chan->data = "(Outgoing Line)";
 	tmp->chan->whentohangup = 0;
@@ -1762,7 +1766,7 @@
 		/* Stop playback */
 		ast_stopstream(chan);
 	}
-	
+
 	return res;
 }
 
@@ -1788,7 +1792,7 @@
 	if (qe->last_periodic_announce_sound >= MAX_PERIODIC_ANNOUNCEMENTS || !strlen(qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound])) {
 		qe->last_periodic_announce_sound = 0;
 	}
-	
+
 	/* play the announcement */
 	res = background_file(qe, qe->chan, qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound]);
 
@@ -1801,7 +1805,7 @@
 
 	/* Update the current periodic announcement to the next announcement */
 	qe->last_periodic_announce_sound++;
-	
+
 	return res;
 }
 
@@ -1857,10 +1861,10 @@
 	char on[80] = "";
 	char membername[80] = "";
 	long starttime = 0;
-	long endtime = 0;	
+	long endtime = 0;
 
 	starttime = (long) time(NULL);
-	
+
 	while (*to && !peer) {
 		int numlines, retry, pos = 1;
 		struct ast_channel *watchers[AST_MAX_WATCHERS];
@@ -1928,7 +1932,7 @@
 					/* Setup parameters */
 					o->chan = ast_request(tech, in->nativeformats, stuff, &status);
 					if (status != o->oldstatus)
-						update_dial_status(qe->parent, o->member, status);						
+						update_dial_status(qe->parent, o->member, status);
 					if (!o->chan) {
 						ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s'\n", tech, stuff);
 						o->stillgoing = 0;
@@ -2014,7 +2018,7 @@
 							if (!sentringing) {
 #if 0
 								ast_indicate(in, AST_CONTROL_RINGING);
-#endif								
+#endif
 								sentringing++;
 							}
 							break;
@@ -2091,14 +2095,14 @@
 			if (option_debug)
 				ast_log(LOG_DEBUG, "It's not our turn (%s).\n", qe->chan->name);
 			res = 0;
-		}	
+		}
 
 	} else {
 		/* This needs a lock. How many members are available to be served? */
 		ast_mutex_lock(&qe->parent->lock);
-			
+
 		ch = qe->parent->head;
-	
+
 		if (qe->parent->strategy == QUEUE_STRATEGY_RINGALL) {
 			if (option_debug)
 				ast_log(LOG_DEBUG, "Even though there are %d available members, the strategy is ringall so only the head call is allowed in\n", avl);
@@ -2116,12 +2120,12 @@
 
 		if (option_debug)
 			ast_log(LOG_DEBUG, "There are %d available members.\n", avl);
-	
+
 		while ((idx < avl) && (ch) && (ch != qe)) {
 			idx++;
-			ch = ch->next;			
-		}
-	
+			ch = ch->next;
+		}
+
 		/* If the queue entry is within avl [the number of available members] calls from the top ... */
 		if (ch && idx < avl) {
 			if (option_debug)
@@ -2132,7 +2136,7 @@
 				ast_log(LOG_DEBUG, "It's not our turn (%s).\n", qe->chan->name);
 			res = 0;
 		}
-		
+
 		ast_mutex_unlock(&qe->parent->lock);
 	}
 
@@ -2305,7 +2309,7 @@
 
 	memset(&bridge_config, 0, sizeof(bridge_config));
 	time(&now);
-		
+
 	for (; options && *options; options++)
 		switch (*options) {
 		case 't':
@@ -2373,7 +2377,7 @@
 			   XXX If we're forcibly removed, these outgoing calls won't get
 			   hung up XXX */
 			tmp->q_next = outgoing;
-			outgoing = tmp;		
+			outgoing = tmp;
 			/* If this line is up, don't try anybody else */
 			if (outgoing->chan && (outgoing->chan->_state == AST_STATE_UP))
 				break;
@@ -2544,7 +2548,7 @@
 					memset(meid, 0, sizeof(meid));
 					pbx_substitute_variables_helper(qe->chan, meid2, meid, sizeof(meid) - 1);
 				}
-	
+
 				snprintf(tmpid2, sizeof(tmpid2)-1, "%s.%s", tmpid, qe->parent->monfmt);
 
 				mixmonapp = pbx_findapp("MixMonitor");
@@ -2556,7 +2560,7 @@
 
 				if (!monitor_options)
 					monitor_options = "";
-				
+
 				if (strchr(monitor_options, '|')) {
 					ast_log(LOG_WARNING, "MONITOR_OPTIONS cannot contain a '|'! Not recording.\n");
 					mixmonapp = NULL;
@@ -2567,7 +2571,7 @@
 						snprintf(mixmonargs, sizeof(mixmonargs)-1, "%s|b%s|%s", tmpid2, monitor_options, monitor_exec);
 					else
 						snprintf(mixmonargs, sizeof(mixmonargs)-1, "%s|b%s", tmpid2, monitor_options);
-						
+
 					if (option_debug)
 						ast_log(LOG_DEBUG, "Arguments being passed to MixMonitor: %s\n", mixmonargs);
 
@@ -2579,7 +2583,7 @@
 			}
 		}
 		/* Drop out of the queue at this point, to prepare for next caller */
-		leave_queue(qe);			
+		leave_queue(qe);
 		if (!ast_strlen_zero(url) && ast_channel_supports_html(peer)) {
 			if (option_debug)
 				ast_log(LOG_DEBUG, "app_queue: sendurl=%s.\n", url);
@@ -2721,7 +2725,7 @@
 		}
 		value_len += res;
 	}
-	
+
 	if (value_len && !cur_member) {
 		if (ast_db_put(pm_family, pm_queue->name, value))
 			ast_log(LOG_WARNING, "failed to create persistent dynamic entry!\n");
@@ -2763,10 +2767,10 @@
 				"MemberName: %s\r\n",
 				q->name, last_member->interface, last_member->membername);
 			free(last_member);
-			
+
 			if (queue_persistent_members)
 				dump_queue_members(q);
-			
+
 			res = RES_OKAY;
 		} else {
 			res = RES_EXISTS;
@@ -2818,10 +2822,10 @@
 				new_member->dynamic ? "dynamic" : "static",
 				new_member->penalty, new_member->calls, (int) new_member->lastcall,
 				new_member->status, new_member->paused);
-			
+
 			if (dump)
 				dump_queue_members(q);
-			
+
 			res = RES_OKAY;
 		} else {
 			res = RES_OUTOFMEMORY;
@@ -2879,7 +2883,7 @@
 /* Reload dynamic queue members persisted into the astdb */
 static void reload_queue_members(void)
 {
-	char *cur_ptr;	
+	char *cur_ptr;
 	char *queue_name;
 	char *member;
 	char *interface;
@@ -2938,7 +2942,7 @@
 				ast_log(LOG_WARNING, "Error converting penalty: %s: Out of range.\n", penalty_tok);
 				break;
 			}
-			
+
 			if (!paused_tok) {
 				ast_log(LOG_WARNING, "Error parsing persistent member string for '%s' (paused)\n", queue_name);
 				break;
@@ -2953,7 +2957,7 @@
 
 			if (option_debug)
 				ast_log(LOG_DEBUG, "Reload Members: Queue: %s  Member: %s  Name: %s  Penalty: %d  Paused: %d\n", queue_name, interface, membername, penalty, paused);
-			
+
 			if (add_to_queue(queue_name, membername, interface, penalty, paused, 0) == RES_OUTOFMEMORY) {
 				ast_log(LOG_ERROR, "Out of Memory when reloading persistent queue member\n");
 				break;
@@ -3174,7 +3178,7 @@
 			penalty = 0;
 		}
 	}
-	
+
 	if (args.options) {
 		if (strchr(args.options, 'j'))
 			priority_jump = 1;
@@ -3243,7 +3247,7 @@
 		return -1;
 	}
 
-	ast_queue_log(args.queuename, args.uniqueid, args.membername, args.event, 
+	ast_queue_log(args.queuename, args.uniqueid, args.membername, args.event,
 		"%s", args.params ? args.params : "");
 
 	ast_module_user_remove(u);
@@ -3274,12 +3278,12 @@
 	);
 	/* Our queue entry */
 	struct queue_ent qe;
-	
+
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Queue requires an argument: queuename[|options[|URL][|announceoverride][|timeout]]\n");
 		return -1;
 	}
-	
+
 	parse = ast_strdupa(data);
 	AST_STANDARD_APP_ARGS(args, parse);
 
@@ -3495,12 +3499,12 @@
 		}
 		/* Don't allow return code > 0 */
 		if (res >= 0 && res != AST_PBX_KEEPALIVE) {
-			res = 0;	
+			res = 0;
 			if (ringing) {
 				ast_indicate(chan, -1);
 			} else {
 				ast_moh_stop(chan);
-			}			
+			}
 			ast_stopstream(chan);
 		}
 		leave_queue(&qe);
@@ -3524,14 +3528,14 @@
 	struct member *m;
 
 	buf[0] = '\0';
-	
+
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_ERROR, "%s requires an argument: queuename\n", cmd);
 		return -1;
 	}
 
 	lu = ast_module_user_add(chan);
-	
+
 	AST_LIST_LOCK(&queues);
 	AST_LIST_TRAVERSE(&queues, q, list) {
 		if (!strcasecmp(q->name, data)) {
@@ -3565,14 +3569,14 @@
 	struct ast_module_user *lu;
 
 	buf[0] = '\0';
-	
+
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_ERROR, "%s requires an argument: queuename\n", cmd);
 		return -1;
 	}
 
 	lu = ast_module_user_add(chan);
-	
+
 	AST_LIST_LOCK(&queues);
 	AST_LIST_TRAVERSE(&queues, q, list) {
 		if (!strcasecmp(q->name, data)) {
@@ -3606,7 +3610,7 @@
 		ast_log(LOG_ERROR, "QUEUE_MEMBER_LIST requires an argument: queuename\n");
 		return -1;
 	}
-	
+
 	u = ast_module_user_add(chan);
 
 	AST_LIST_LOCK(&queues);
@@ -3701,7 +3705,7 @@
 		AST_APP_ARG(penalty);
 		AST_APP_ARG(membername);
 	);
-	
+
 	if (!(cfg = ast_config_load("queues.conf"))) {
 		ast_log(LOG_NOTICE, "No call queueing config file (queues.conf), so no call queues\n");
 		return 0;
@@ -3715,7 +3719,7 @@
 	/* Chug through config file */
 	cat = NULL;
 	while ((cat = ast_category_browse(cfg, cat)) ) {
-		if (!strcasecmp(cat, "general")) {	
+		if (!strcasecmp(cat, "general")) {
 			/* Initialize global settings */
 			queue_persistent_members = 0;
 			if ((general_val = ast_variable_retrieve(cfg, "general", "persistentmembers")))
@@ -3756,7 +3760,7 @@
 					if (!strcasecmp(var->name, "member")) {
 						/* Add a new member */
 						ast_copy_string(parse, var->value, sizeof(parse));
-						
+
 						AST_NONSTANDARD_APP_ARGS(args, parse, ',');
 
 						interface = args.interface;
@@ -3948,7 +3952,7 @@
 			}
 		} else if (s)
 			astman_append(s, "   No Members%s", term);
-		else	
+		else
 			ast_cli(fd, "   No Members%s", term);
 		if (q->head) {
 			pos = 1;
@@ -3998,11 +4002,11 @@
 	char *ret = NULL;
 	int which = 0;
 	int wordlen = strlen(word);
-	
+
 	AST_LIST_LOCK(&queues);
 	AST_LIST_TRAVERSE(&queues, q, list) {
 		if (!strncasecmp(word, q->name, wordlen) && ++which > state) {
-			ret = ast_strdup(q->name);	
+			ret = ast_strdup(q->name);
 			break;
 		}
 	}



More information about the asterisk-commits mailing list