5c5
<  * 
---
>  *
37c37
< 
---
> #include <asthash.h>
39a40
> #define AST_QUEUE_TIMEOUT               100
44a46,47
> #define QUEUE_STRATEGY_SKILLBASED       5
> #define MAX_CHIMELIST                   40
54a58
> 	{ QUEUE_STRATEGY_SKILLBASED, "skillbased" }
63a68,69
> static char *dapp = "DynaQueue";
> static char *dsynopsis = "Build a Queue on the fly";
66a73,76
> static char *ddescrip =
> "  DynaQueue \n"
> ;
> 
68c78
< "  Queue(queuename[|options[|URL][|announceoverride]]):\n"
---
> "  Queue(queuename[|options[|skillmask][|toolong][|URL][|announceoverride]]):\n"
69a80,81
> "skillmask is a bitmask representing the skills of the agent.\n"
> "toolong is a specified timeout 0 = endless where the call will quit the queue returning 2\n"
78d89
< "      'n' -- no retries on the timeout; will exit this application and go to the next step.\n"
88c99
< "   AddQueueMember(queuename[|interface]):\n"
---
> "   AddQueueMember(queuename[|penalty][|skillmask][|interface]):\n"
90a102
> ""
92c104,106
< "";
---
> "Example: AddQueueMember(techsupport|100|SIP/3001)\n"
> "skillmask is a bitmask representing the skills of the agent.\n";
> 
103,104c117
< /* whether to exit Queue application after the timeout hits */
< static int go_on = 0;
---
> 
135c148,153
< 	time_t start;				/* When we started holding */
---
>         int chimerep;                              /* how may revolutions in the q have we made*/
>         int chimepos;                              /* which chime element are we on */
>         time_t toolong;                              /* too long to wait */
>         long skillmask;                          /* skill bit mask */
>         int ok_secondary;             /* ok for secondary?*/
> 	time_t start;                      /* When we started holding */
143a162
>         long skillmask;                         /* skill bitmask */
151c170
< 	ast_mutex_t	lock;	
---
> 	ast_mutex_t	lock;
160d178
< 
161a180
>         int dynamic;                            /* Whether this queue is dynamic or not */
162a182,191
>         int maxwait;                            /* longest wait time in this q */
>         char q_pos_is[80];
>         char q_wait_time[80];
>         char q_min[80];
>         int loopmin;
>         char chimedata[255];
>         char *chimelist[MAX_CHIMELIST];           /* comma sep list of chime-in sound files */
>         int chimelistlen;
>         time_t allow_secondary;             /* how many seconds to make em wait till we let secondary agent answer */
>         int chimereps;
164c193
< 	
---
> 
166c195
< 	
---
> 
170a200
> 	struct member *secondary_members;	/* Member channels to be tried */
197a228,252
> static int intcompare(const void *p1, const void *p2)
> {
>   int i = *((int *)p1);
>   int j = *((int *)p2);
> 
>   if (i > j)
>     return (1);
>   if (i < j)
>     return (-1);
>   return (0);
> }
> 
> 
> static struct queue_ent *pull_member(struct queue_ent *qe,int y) {
>   int x=0;
>   struct queue_ent *cur = NULL;
> 
>   for(cur=qe;cur;cur=cur->next) {
>     if(x==y)
>       return cur;
>     x++;
>     
>   }
> }
> 
201c256
< 	struct queue_ent *cur, *prev = NULL;
---
> 	struct queue_ent *cur, *prev= NULL;
203a259,260
> 
> 
215,217c272,274
< 					cur->pos = ++pos;
< 					prev = cur;
< 					cur = cur->next;
---
> 				  cur->pos = ++pos;
> 				  prev = cur;
> 				  cur = cur->next;
230a288,289
> 				qe->chimepos = 0;
> 				qe->chimerep = 0;
233c292,298
< 				manager_event(EVENT_FLAG_CALL, "Join", 
---
> 
> 				
> 				
> 				
> 
> 
> 				manager_event(EVENT_FLAG_CALL, "Join",
252,266c317,347
< 	struct member *curm, *next, *prev;
< 	curm = q->members;
< 	prev = NULL;
< 	while(curm) {
< 		next = curm->next;
< 		if (all || !curm->dynamic) {
< 			if (prev)
< 				prev->next = next;
< 			else
< 				q->members = next;
< 			free(curm);
< 		} else 
< 			prev = curm;
< 		curm = next;
< 	}
---
>   struct member *curm, *next, *prev;
>   curm = q->members;
>   prev = NULL;
>   while(curm) {
>     next = curm->next;
>     if (all || !curm->dynamic) {
>       if (prev)
> 	prev->next = next;
>       else
> 	q->members = next;
>       free(curm);
>     } else
>       prev = curm;
>     curm = next;
>   }
>   
>   curm = q->secondary_members;
>   prev = NULL;
>   while(curm) {
>     next = curm->next;
>     if (all || !curm->dynamic) {
>       if (prev)
> 	prev->next = next;
>       else
> 	q->secondary_members = next;
>       free(curm);
>     } else
>       prev = curm;
>     curm = next;
>   }
>   
325c406
< 	if (q->dead && !q->count) {	
---
> 	if (q->dead && !q->count) {
353c434
< #endif			
---
> #endif
469c550
< 	
---
> 
552c633
< #endif								
---
> #endif
606c687
< 	
---
> 
608a690,800
> 
> 
> 
> 
> 
> 
> 
> static int announce_loop(struct queue_ent *qe) {
>   time_t now;
>   int res=0;
> 
>   time(&now);
> 
> 
>   time(&now);
>   if((qe->toolong > 0) && (now - qe->start) > qe->toolong) {
>     /* timeout fall to another option in dialplan */ 
>     ast_log(LOG_WARNING,"timeout waiting for reply [%ld] > [%ld] seconds.\n",(now - qe->start),qe->toolong);
>     res = AST_QUEUE_TIMEOUT;
>     return(res);
>   }
> 
> 
> 
> 
> 
>   if(qe->parent->chimelistlen > 0 && (qe->chimerep % qe->parent->chimereps == 0)) {
> 
> 
>     if( qe->parent->chimelist[qe->chimepos] && strcmp(qe->parent->chimelist[qe->chimepos],"skip")) {
> 	    
>       if(qe->parent->chimelist[qe->chimepos] && ! strcmp(qe->parent->chimelist[qe->chimepos],"announce_pos")) {
> 
> 
> 	ast_moh_stop(qe->chan);
> 	ast_safe_sleep(qe->chan, 1000);	      	      
> 			
> 			
> 	res = ast_streamfile(qe->chan,qe->parent->q_pos_is, qe->chan->language);
> 	if(! res)
> 	  ast_waitstream(qe->chan, "");
> 			
> 	res = ast_say_number(qe->chan, qe->pos, "", qe->chan->language);
> 			
> 			
> 	res = ast_streamfile(qe->chan,qe->parent->q_wait_time, qe->chan->language);
> 	if(! res)
> 	  ast_waitstream(qe->chan, "");
> 			
> 	      
> 	res = ast_say_number(qe->chan,qe->parent->maxwait, "", qe->chan->language);
> 			
> 	res = ast_streamfile(qe->chan,qe->parent->q_min, qe->chan->language);
> 	if(! res)
> 	  ast_waitstream(qe->chan, "");
> 			
> 	ast_safe_sleep(qe->chan, 1000);
> 	ast_moh_start(qe->chan, qe->moh);
> 
> 			
> 
>       }
>       else {
> 
> 	ast_moh_stop(qe->chan);
> 	ast_safe_sleep(qe->chan, 1000);	      	      
> 	res = ast_streamfile(qe->chan,qe->parent->chimelist[qe->chimepos], qe->chan->language);
> 	if(! res)
> 	  ast_waitstream(qe->chan, "");
> 			
> 	ast_safe_sleep(qe->chan, 1000);
> 	ast_moh_start(qe->chan, qe->moh);  
> 			
> 	      
>       }
> 	    
> 
> 	  
>     }
> 	  
> 
> 		    
>     qe->chimepos++;
>     if(qe->parent->chimelistlen > 0) {
>       if(qe->chimepos >= qe->parent->chimelistlen)
> 	qe->chimepos = qe->parent->loopmin - 1;
>       if(qe->chimepos >= qe->parent->chimelistlen)
> 	qe->chimepos = 0;
>     }
> 		    
> 		    
>   }
> 		  
> 		  
> 		  
>   if(qe->chimerep == 2147483647) {
>     qe->chimerep = 0;
>   }
> 		  
> 		  
>   qe->chimerep++;
> 
>   ast_mutex_lock(&qe->parent->lock);
>   qe->parent->maxwait = (long) (now - qe->start) / 60;
>   ast_mutex_unlock(&qe->parent->lock);
>   
> 
>   return res;
> }
> 
> 
612a805,807
> 	time_t now;
> 	
> 	
614,622c809,830
< 		/* Atomically read the parent head -- does not need a lock */
< 		ch = qe->parent->head;
< 		/* If we are now at the top of the head, break out */
< 		if (qe->parent->head == qe)
< 			break;
< 		/* Wait a second before checking again */
< 		res = ast_waitfordigit(qe->chan, RECHECK * 1000);
< 		if (res)
< 			break;
---
> 
> 	  /* handle any chimein or position announcement */
> 	  res = announce_loop(qe);
> 	  if (res == AST_QUEUE_TIMEOUT) {
> 	    break;
> 	  }
> 	  time(&now);
> 	  if(qe->ok_secondary != 1 && qe->parent->allow_secondary >= 0 && (((now - qe->start) > qe->parent->allow_secondary))) {
> 	    /* cut the nap short to let secondary agents have a chance */
> 	    qe->ok_secondary = 1;
> 	    break;
> 	  }
> 
> 	  /* Atomically read the parent head -- no lock needed */
> 	  ch = qe->parent->head;
> 	  /* If we are now at the top of the head, break out */
> 	  if (qe->parent->head == qe)
> 	    break;
> 	  /* Wait a second before checking again */
> 	  res = ast_waitfordigit(qe->chan, RECHECK * 1000);
> 	  if (res)
> 	    break;
647a856,857
>   int yes=0;
> 
648a859,878
> 
> 
> 	case QUEUE_STRATEGY_SKILLBASED:
> 		/* penalty and skill 'it's all in the wrist'*/
> 
> 	  if(((qe->skillmask & mem->skillmask) == qe->skillmask) || mem->skillmask == 0 || qe->skillmask == 0 ) {
> 	    tmp->metric = mem->penalty * 1000000;
> 	    yes=1;
> 	  }
> 	  else {
> 	    tmp->metric = -1;
> 
> 	  }
> 
> 	  ast_log(LOG_WARNING,"skillmask %ld & %ld = %ld [%s]\n",qe->skillmask,mem->skillmask,(qe->skillmask & mem->skillmask),yes ? "qualify" : "disqualify");
> 
> 
> 
> 		break;
> 
697c927
< static int try_calling(struct queue_ent *qe, char *options, char *announceoverride, char *url)
---
> static int try_calling(struct queue_ent *qe, char *options, char *announceoverride, char *url,struct member *members)
713a944,945
> 
> 
714a947
> 
716c949
< 	cur = qe->parent->members;
---
> 	cur = members;
721a955,956
> 
> 
725d959
< 			ast_mutex_unlock(&qe->parent->lock);
744,745d977
< 			if (strchr(options, 'n'))
< 				go_on = 1;
749c981
< 		} else 
---
> 		} else
765,771c997,1007
< 		/* Put them in the list of outgoing thingies...  We're ready now. 
< 		   XXX If we're forcibly removed, these outgoing calls won't get
< 		   hung up XXX */
< 		tmp->next = outgoing;
< 		outgoing = tmp;		
< 		/* If this line is up, don't try anybody else */
< 		if (outgoing->chan && (outgoing->chan->_state == AST_STATE_UP))
---
> 
> 
> 
> 		    if(tmp->metric >= 0) {
> 		      /* Put them in the list of outgoing thingies...  We're ready now.
> 			 XXX If we're forcibly removed, these outgoing calls won't get
> 			 hung up XXX */
> 		      tmp->next = outgoing;
> 		      outgoing = tmp;
> 		      /* If this line is up, don't try anybody else */
> 		      if (outgoing->chan && (outgoing->chan->_state == AST_STATE_UP)) {
772a1009,1012
> 		      }
> 		    }
> 		    
> 		    cur = cur->next;
774d1013
< 		cur = cur->next;
775a1015,1019
> 
> 
> 
> 
> 
781a1026
> 
797a1043
> 
802c1048
< 		   we will always return with -1 so that it is hung up properly after the 
---
> 		   we will always return with -1 so that it is hung up properly after the
807c1053
< 		}			
---
> 		}
817a1064
> 		
820a1068,1074
> 
> 			if (!res2)
> 			  res2 = ast_streamfile(peer, "agent_beep", peer->language);
> 			if (!res2)
> 			  res2 = ast_waitstream(peer, "");
> 
> 
824a1079,1080
> 
> 
832a1089
> 
844c1101
< 		leave_queue(qe);			
---
> 		leave_queue(qe);
849a1107
> 
851a1110
> 
857c1116
< 	}	
---
> 	}
865,867c1124,1150
< 	/* Don't need to hold the lock while we setup the outgoing calls */
< 	int retrywait = qe->parent->retry * 1000;
< 	return ast_waitfordigit(qe->chan, retrywait);
---
>   /* We do not need to hold the lock while we setup the outgoing calls */
>   int retrywait,res,res2;
>   time_t now;
> 
>   retrywait=res=res2=0;
> 
> 
> 
>   for(retrywait=0;retrywait < qe->parent->retry ; retrywait++) {
>     res2 = ast_waitfordigit(qe->chan, 1000);
>     /* handle any chimein or position announcement */
>     res = announce_loop(qe);
>     if (res == AST_QUEUE_TIMEOUT) {
>       return res;
>     }
>     if(res2 != 0) {
>       return res2;
>     }
>     time(&now);
>     if(qe->ok_secondary != 1 && qe->parent->allow_secondary >= 0 && (((now - qe->start) > qe->parent->allow_secondary))) {
>       /* cut the nap short to let secondary agents have a chance */
>       qe->ok_secondary = 1;
>       return 0;
>     }
> 
>   }
>   return res2;
902c1185
< 	
---
> 
940c1223
< 	
---
> 
942c1225
< 	
---
> 
963c1246
< 		while( q && ( res != 0 ) && (!found) ) 
---
> 		while( q && ( res != 0 ) && (!found) )
992c1275
< 					ast_log(LOG_NOTICE, "Removed interface '%s' to queue '%s'\n", 
---
> 					ast_log(LOG_NOTICE, "Removed interface '%s' to queue '%s'\n",
1014a1298,1314
> static int parse_list(char *str, char delim,char *alist[]) {
>   char *args,*p;
>   int x = 1;
>   alist[0] = args = str;
>   while((p = strchr(args,delim))) {
>     *p = '\0';
>     p++;
>     alist[x++] = p;
>     args = p;
>     p = NULL;
>   }
> 
>   return(x);
> }
> 
> 
> 
1019c1319,1320
< 	char *queuename;
---
> 	char *args,*queuename,*penalty,*skillmask,*interface,*p;
> 
1022d1322
< 	char *interface=NULL;
1025a1326,1330
> 	int arg_count;
> 	struct string_hash_table *arghash = (struct string_hash_table *) init_string_hash("args");
> 
> 
> 
1028c1333
< 		ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename|optional interface)\n");
---
> 		ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename|penalty|skillmask|optional interface)\n");
1031c1336,1337
< 	
---
> 
> 
1033c1339,1342
< 	
---
> 
> 
> 	args = queuename = penalty = skillmask = interface = p = NULL;
> 
1036,1049c1345,1373
< 	queuename = info;
< 	if (queuename) {
< 		interface = strchr(queuename, '|');
< 		if (interface) {
< 			*interface = '\0';
< 			interface++;
< 		}
< 		else {
< 			strncpy(tmpchan, chan->name, sizeof(tmpchan) - 1);
< 			interface = strrchr(tmpchan, '-');
< 			if (interface)
< 				*interface = '\0';
< 			interface = tmpchan;
< 		}
---
> 
> 
> 
> 
>         arg_count = named_args(arghash,info,'|');
> 
> 	queuename = string_hash_read(arghash,"0");
> 	if(queuename) {
> 	  penalty = string_hash_read(arghash,"1");
> 	  skillmask = string_hash_read(arghash,"2");
> 	  interface = string_hash_read(arghash,"3");
> 	}
> 	else { /* named args yay! */
> 	  queuename = string_hash_read(arghash,"queuename");
> 	  penalty = string_hash_read(arghash,"penalty");
>           skillmask = string_hash_read(arghash,"skillmask");
>           interface = string_hash_read(arghash,"interface");
> 	}
> 
> 
> 
> 
> 
> 	if(! interface) {
> 	  strncpy(tmpchan, chan->name, sizeof(tmpchan) - 1);
> 	    interface = strrchr(tmpchan, '-');
> 	    if (interface)
> 	      *interface = '\0';
> 	    interface = tmpchan;
1051a1376,1377
> 
> 
1054c1380
< 		while( q && ( res != 0 ) && (!found) ) 
---
> 		while( q && ( res != 0 ) && (!found) )
1068a1395,1399
> 						if(penalty)
> 						  q->members->penalty = atoi(penalty);
> 
> 						q->members->skillmask = skillmask ? atol(skillmask) : 0;
> 
1093a1425,1634
> 
> static int dynaqueue_exec(struct ast_channel *chan, void *data) {
>   int res=-1;
>   struct localuser *u;
>   char *queuename,*skillmask,*toolong;
>   char info[512];
>   int arg_count;
>   struct string_hash_table *arghash = (struct string_hash_table *) init_string_hash("args");
> 
>   struct ast_call_queue *q, *ql, *qn;
>   queuename = skillmask = toolong = NULL;
>   int new = 0;
>   struct member *cur,*memb;
>   char *tmp,*mtmp;
> 
>   char i[10];
>   int x;
> 
>   cur=memb=NULL;
> 
>   if (!data) {
>     ast_log(LOG_WARNING, "DynaQueue requires arguments\n");
>     return res;
>   }
> 
>   LOCAL_USER_ADD(u);
> 
>   /* Parse our arguments XXX Check for failure XXX */
>   strncpy(info, (char *)data, strlen((char *)data) + AST_MAX_EXTENSION-1);
> 
>   arg_count = named_args(arghash,info,'|');
> 
> 
>   queuename = string_hash_read(arghash,"queuename");
> 
> 
> 
> 
>   q = queues;
> 
>   while(q) {
>     if (!strcmp(q->name, queuename))
>       break;
>     q = q->next;
>   }
>   
> 
> 
>   if (!q) {
>     ast_mutex_lock(&qlock);
>     /* Make one then */
>     q = malloc(sizeof(struct ast_call_queue));
>     if (q) {
>       /* Initialize it */
>       memset(q, 0, sizeof(struct ast_call_queue));
>       ast_mutex_init(&q->lock);
> 
>       strncpy(q->name,queuename,sizeof(q->name));
> 
>       new = 1;
>     } else new = 0;
>   } 
>   else
>     return -1; /* nevermind its here already */
>     
> 	
>       if (q) {
> 	if (!new)
> 	  ast_mutex_lock(&q->lock);
> 	/* Re-initialize the queue */
> 
> 
> 	q->dead = 0;
> 	q->dynamic = 1;
> 	tmp = string_hash_read(arghash,"retry");
> 	q->retry =  tmp ? atoi(tmp) : 5;
> 	
> 	tmp = string_hash_read(arghash,"maxwait");
> 	q->maxwait = tmp ? atoi(tmp) : 0;
> 	
> 	tmp = string_hash_read(arghash,"timeout");
> 	q->timeout = tmp ? atoi(tmp) : -1;
> 	
> 	tmp = string_hash_read(arghash,"maxlen");
> 	q->maxlen = tmp ? atoi(tmp) : 0;
> 	
> 	tmp = string_hash_read(arghash,"chimereps");
> 	q->chimereps = tmp ? atoi(tmp) : 0;
> 
> 
> 	q->chimelistlen = 0;
> 	
> 	tmp = string_hash_read(arghash,"loopmin");
> 	q->loopmin = tmp ? atoi(tmp) : 1;
> 	
> 	tmp = string_hash_read(arghash,"allow_secondary");
> 	q->allow_secondary = tmp ? atoi(tmp) : -1;
> 	
> 	
> 	strncpy(q->q_wait_time,"q_wait_time",sizeof(q->q_wait_time));
> 	
> 	strncpy(q->q_pos_is,"q_pos_is",sizeof(q->q_pos_is));
> 	
> 	strncpy(q->q_min,"q_min",sizeof(q->q_min));
> 
> 
> 
> 	for(x=0;;x++) {
> 	  sprintf(i,"%d",x);
> 	  tmp=string_hash_read(arghash,i);
> 	  if(!tmp)
> 	    break;
> 
> 	  /* Add a new member */
> 	  memb = malloc(sizeof(struct member));
> 	  if (memb) {
> 	    memset(memb, 0, sizeof(struct member));
> 	    strncpy(memb->tech,tmp, sizeof(memb->tech) - 1);
> 	    if ((mtmp = strchr(memb->tech, ','))) {
> 	      *mtmp = '\0';
> 	      mtmp++;
> 	      memb->penalty = atoi(mtmp);
> 	      if (memb->penalty < 0)
> 		memb->penalty = 0;
> 	      if ((mtmp = strchr(mtmp, ','))) {
> 		*mtmp = '\0';
> 		mtmp++;
> 		memb->skillmask = atol(mtmp);
> 	      }
> 	      
> 	    }
> 	    if ((mtmp = strchr(memb->tech, '/')))
> 	      *mtmp = '\0';
> 	    if ((mtmp = strchr(tmp, '/'))) {
> 	      mtmp++;
> 	      strncpy(memb->loc, mtmp, sizeof(memb->loc) - 1);
> 	      if ((mtmp = strchr(memb->loc, ',')))
> 		*mtmp = '\0';
> 	    }
> 	    else
> 	      ast_log(LOG_WARNING, "No location in dynamic addition\n");
> 	  }
> 
> 	  if(!x) 
> 	    cur = q->members = memb;
> 	  else 
> 	    cur = cur->next = memb;
> 
> 	}
> 	
> 
> 	tmp = string_hash_read(arghash,"chimelist");
> 	if(tmp) {
> 	  strncpy(q->chimedata,tmp, sizeof(q->chimedata) - 1);
> 	  q->chimelistlen = parse_list(q->chimedata,',',q->chimelist);
> 	}
> 
> 
> 
> 	tmp = string_hash_read(arghash,"moh");
> 	strncpy(q->moh, tmp ? tmp : "default" ,sizeof(q->moh));
> 	
> 	tmp = string_hash_read(arghash,"announce");
> 	if(tmp)
> 	  strncpy(q->announce,tmp,sizeof(q->announce));
> 	
> 	tmp = string_hash_read(arghash,"context");
> 	if(tmp)
> 	  strncpy(q->context,tmp,sizeof(q->context));
> 	
> 
> 	
> 	
> 
> 	if (!new)
> 	  ast_mutex_unlock(&q->lock);
> 
> 	if (new) {
> 	  q->next = queues;
> 	  queues = q;
> 	}
> 
>       }
>   
>   
>   q = queues;
>   ql = NULL;
>   while(q) {
>     qn = q->next;
>     if (q->dead) {
>       if (ql)
> 	ql->next = q->next;
>       else
> 	queues = q->next;
>       if (!q->count) {
> 	free(q);
>       } else
> 	ast_log(LOG_WARNING, "XXX Leaking a litttle memory :( XXX\n");
>     } else
>       ql = q;
>     q = qn;
>   }
>   ast_mutex_unlock(&qlock);
> 
> 
>   
>   return 0;
> }
> 
> 
1095a1637,1638
> 
> 
1098c1641
< 	char *queuename;
---
> 	char *queuename,*skillmask,*toolong;
1103c1646,1647
< 	
---
> 	int arg_count;
> 	time_t now;
1106c1650,1658
< 	
---
> 	struct string_hash_table *arghash = (struct string_hash_table *) init_string_hash("args");
> 
> 
> 
> 	queuename = skillmask = toolong = NULL;
> 
> 
> 
> 
1111c1663
< 	
---
> 
1113c1665
< 	
---
> 
1116,1132c1668,1691
< 	queuename = info;
< 	if (queuename) {
< 		options = strchr(queuename, '|');
< 		if (options) {
< 			*options = '\0';
< 			options++;
< 			url = strchr(options, '|');
< 			if (url) {
< 				*url = '\0';
< 				url++;
< 				announceoverride = strchr(url, '|');
< 				if (announceoverride) {
< 					*announceoverride = '\0';
< 					announceoverride++;
< 				}
< 			}
< 		}
---
> 
> 	/* old way
> 	arg_count = parse_list(info,'|',alist);
> 	*/
> 
> 
> 	arg_count = named_args(arghash,info,'|');
> 	
> 
> 	queuename = string_hash_read(arghash,"0");
> 	if(queuename) {
> 	  options = string_hash_read(arghash,"1");
> 	  skillmask = string_hash_read(arghash,"2");
> 	  toolong = string_hash_read(arghash,"3");
> 	  url = string_hash_read(arghash,"4");
> 	  announceoverride = string_hash_read(arghash,"5");
> 	}
> 	else { /* named args */
> 	  queuename = string_hash_read(arghash,"queuename");
> 	  options = string_hash_read(arghash,"options");
>           skillmask = string_hash_read(arghash,"skillmask");
>           toolong = string_hash_read(arghash,"toolong");
>           url = string_hash_read(arghash,"url");
>           announceoverride = string_hash_read(arghash,"announceoverride");
1134,1135c1693,1702
< 	printf("queue: %s, options: %s, url: %s, announce: %s\n",
< 		queuename, options, url, announceoverride);
---
> 
> 
> 
> 
> 	if (!skillmask)
> 	  skillmask = "0";
> 
> 
> 	printf("queue: %s, options: %s, skillmask: %s toolong: %s url: %s, announce: %s\n",
> 		queuename, options, skillmask,toolong, url, announceoverride);
1138a1706
> 
1139a1708,1717
> 	qe.toolong = toolong ? atol(toolong) : 0;
> 	
> 	qe.skillmask = skillmask ? atol(skillmask) : 0;
> 
> 
> 	qe.ok_secondary = 0;
> 	qe.chimepos = 0;
> 	qe.chimerep = 0;
> 
> 
1144c1722,1730
< 			res = wait_our_turn(&qe);
---
> 		  
> 
> 		  /* let all the calls flood to the try calling staging area in skillbased routing otherwise, get in line*/
> 		  res = (qe.parent->strategy == QUEUE_STRATEGY_SKILLBASED) ? 0 : wait_our_turn(&qe);
> 
> 
> 
> 
> 
1159,1168c1745,1783
< 			for (;;) {
< 				res = try_calling(&qe, options, announceoverride, url);
< 				if (res)
< 					break;
< 				/* exit after a timeout if 'n' option enabled */
< 				if (go_on) {
< 					res = 0;
< 					break;
< 				}
< 				res = wait_a_bit(&qe);
---
> 		  /* handle any chimein or position announcement */
> 		  res = announce_loop(&qe);
> 		  while (res != AST_QUEUE_TIMEOUT) {
> 
> 
> 
> 
> 		    res = try_calling(&qe, options, announceoverride, url,qe.parent->members);
> 		    if (res)
> 		      break;
> 
> 		    time(&now);
> 
> 		    /* secondary agents */
> 
> 		    if(qe.ok_secondary !=1 && (qe.parent->allow_secondary >= 0 && (((now - qe.start) > qe.parent->allow_secondary)))) {
> 		      qe.ok_secondary = 1;
> 		    }
> 
> 
> 		    if(qe.ok_secondary == 1) {
> 		      res = try_calling(&qe, options, announceoverride, url,qe.parent->secondary_members);
> 		      if (res)
> 			break;
> 		    }
> 
> 
> 
> 		       res = wait_a_bit(&qe);
> 		       
> 		       if (res == AST_QUEUE_TIMEOUT) {
> 			 break;
> 		       }
> 
> 				
> 
> 
> 
> 
1182c1797
< 			res = 0;	
---
> 			res = 0;
1198a1814,1815
> 
> 	
1200c1817
< 	struct member *prev, *cur;
---
> 	struct member *prev, *cur,*sprev;
1207a1825
> 
1211,1212c1829,1830
< 		q->dead = 1;
< 		q = q->next;
---
> 	  q->dead = 1;
> 	  q = q->next;
1238c1856
< 				if (!new) 
---
> 				if (!new)
1242a1861
> 				q->maxwait = 0;
1243a1863
> 				q->dynamic = 0;
1244a1865,1871
> 				q->chimereps = 0;
> 				q->chimelistlen = 0;
> 				q->loopmin = 1;
>                                 q->allow_secondary = -1;
> 				strncpy(q->q_wait_time,"q_wait_time",sizeof(q->q_wait_time));
> 				strncpy(q->q_pos_is,"q_pos_is",sizeof(q->q_pos_is));
> 				strncpy(q->q_min,"q_min",sizeof(q->q_min));
1254a1882,1889
> 
> 
> 				sprev = q->secondary_members;
> 				if (sprev) {
> 					/* find the end of any dynamic secondary members */
> 					while(sprev->next)
> 						sprev = sprev->next;
> 				}
1257c1892
< 					if (!strcasecmp(var->name, "member")) {
---
> 					if (!strcasecmp(var->name, "member") || !strcasecmp(var->name, "secondary_member")) {
1268a1904,1909
> 								if ((tmp = strchr(tmp, ','))) {
> 								  *tmp = '\0';
> 								  tmp++;
> 								  cur->skillmask = atol(tmp);
> 								}
> 
1271c1912
< 								*tmp = '\0';
---
> 							  *tmp = '\0';
1277,1280c1918
< 							} else
< 								ast_log(LOG_WARNING, "No location at line %d of queue.conf\n", var->lineno);
< 							if (prev)
< 								prev->next = cur;
---
> 							}
1282,1283c1920,1939
< 								q->members = cur;
< 							prev = cur;
---
> 							  ast_log(LOG_WARNING, "No location at line %d of queue.conf\n", var->lineno);
> 
> 
> 							if(!strcasecmp(var->name, "member")) {
> 							  if (prev)
> 							    prev->next = cur;
> 							  else
> 							    q->members = cur;
> 							  prev = cur;
> 							}
> 							   
> 							else {
> 							     
> 							  if (sprev)
> 							    sprev->next = cur;
> 							  else
> 							    q->secondary_members = cur;
> 							  sprev = cur;
> 							}
> 
1288a1945,1951
> 
> 					} else if (!strcasecmp(var->name, "q_min")) {
> 						strncpy(q->q_min, var->value, sizeof(q->q_min) - 1);
> 					} else if (!strcasecmp(var->name, "q_pos_is")) {
> 						strncpy(q->q_pos_is, var->value, sizeof(q->q_pos_is) - 1);
> 					} else if (!strcasecmp(var->name, "q_wait_time")) {
> 						strncpy(q->q_wait_time, var->value, sizeof(q->q_wait_time) - 1);
1292a1956,1957
> 					} else if (!strcasecmp(var->name, "loopmin")) {
> 						q->loopmin = atoi(var->value);
1294a1960,1966
> 					} else if (!strcasecmp(var->name, "allow_secondary")) {
> 						q->allow_secondary = atol(var->value);
> 					} else if (!strcasecmp(var->name, "chimereps")) {
> 						q->chimereps = atoi(var->value);
> 					} else if (!strcasecmp(var->name, "chimelist")) {
> 					  strncpy(q->chimedata, var->value, sizeof(q->chimedata) - 1);
> 					  q->chimelistlen = parse_list(q->chimedata,',',q->chimelist);
1314c1986
< 				if (!new) 
---
> 				if (!new)
1354c2026
< 	
---
> 
1360c2032
< 	if (!q) {	
---
> 	if (!q) {
1371c2043
< 		ast_cli(fd, "%-12.12s has %d calls (max %s) in '%s' strategy\n", q->name, q->count, max, int2strat(q->strategy));
---
> 		ast_cli(fd, "%s has %d calls (max %s) in '%s' strategy; allow secondary after '%ld' seconds\n", q->name, q->count, max, int2strat(q->strategy),q->allow_secondary);
1376c2048
< 					snprintf(max, sizeof(max) - 20, " with penalty %d", mem->penalty);
---
> 					snprintf(max, sizeof(max) - 20, " with penalty %d and skillmask %ld", mem->penalty,mem->skillmask);
1388,1389c2060,2085
< 		} else
< 			ast_cli(fd, "   No Members\n");
---
> 		} 
> 		else
> 		  ast_cli(fd, "   No Members\n");
> 
> 
> 		if (q->secondary_members) {
> 			ast_cli(fd, "   Secondary Members: \n");
> 			for (mem = q->secondary_members; mem; mem = mem->next) {
> 				if (mem->penalty)
> 					snprintf(max, sizeof(max) - 20, " with penalty %d and skillmask %ld", mem->penalty,mem->skillmask);
> 				else
> 					strcpy(max, "");
> 				if (mem->dynamic)
> 					strcat(max, " (dynamic)");
> 				if (mem->calls) {
> 					snprintf(calls, sizeof(calls), " has taken %d calls (last was %ld secs ago)",
> 							mem->calls, (long)(time(NULL) - mem->lastcall));
> 				} else
> 					strcpy(calls, " has taken no calls yet");
> 				ast_cli(fd, "      %s/%s%s%s\n", mem->tech, mem->loc, max, calls);
> 			}
> 		} 
> 		else
> 		  ast_cli(fd, "   No Secondary Members\n");
> 
> 
1393,1395c2089,2091
< 			for (qe = q->head; qe; qe = qe->next) 
< 				ast_cli(fd, "      %d. %s (wait: %ld:%2.2ld)\n", pos++, qe->chan->name,
< 								(long)(now - qe->start) / 60, (long)(now - qe->start) % 60);
---
> 			for (qe = q->head; qe; qe = qe->next)
> 				ast_cli(fd, "      %d. %s (wait: %ld:%2.2ld) skillmask:%ld\n", pos++, qe->chan->name,
> 								(long)(now - qe->start) / 60, (long)(now - qe->start) % 60,qe->skillmask);
1440,1441c2136,2137
< 		/* Do we care about queue members? */					
< 		for (mem = q->members; mem; mem = mem->next) 
---
> 		/* Do we care about queue members? */
> 		for (mem = q->members; mem; mem = mem->next)
1443c2139
< #endif			
---
> #endif
1445c2141
< 		for (qe = q->head; qe; qe = qe->next) 
---
> 		for (qe = q->head; qe; qe = qe->next)
1447a2144
> 				"Skillmask: %ld\r\n"
1453,1454c2150,2151
< 				"\r\n", 
< 					q->name, pos++, qe->chan->name, (qe->chan->callerid ? qe->chan->callerid : ""), (long)(now - qe->start), idText);
---
> 				"\r\n",
> 					q->name, qe->skillmask,pos++, qe->chan->name, (qe->chan->callerid ? qe->chan->callerid : ""), (long)(now - qe->start), idText);
1462c2159
< static char show_queues_usage[] = 
---
> static char show_queues_usage[] =
1467c2164
< 	{ "show", "queues", NULL }, queues_show, 
---
> 	{ "show", "queues", NULL }, queues_show,
1490a2188,2189
> 		res = ast_register_application(dapp, dynaqueue_exec, dsynopsis, ddescrip);
> 
