[asterisk-commits] branch bweschke/findme_followme r31837 - /team/bweschke/findme_followme/apps/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Jun 3 14:26:13 MST 2006


Author: bweschke
Date: Sat Jun  3 16:26:13 2006
New Revision: 31837

URL: http://svn.digium.com/view/asterisk?rev=31837&view=rev
Log:
 Add a third "numorder" field to a number definition in the conf file to make sure the entire conf file is "realtime friendly".


Modified:
    team/bweschke/findme_followme/apps/app_followme.c

Modified: team/bweschke/findme_followme/apps/app_followme.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/findme_followme/apps/app_followme.c?rev=31837&r1=31836&r2=31837&view=diff
==============================================================================
--- team/bweschke/findme_followme/apps/app_followme.c (original)
+++ team/bweschke/findme_followme/apps/app_followme.c Sat Jun  3 16:26:13 2006
@@ -68,8 +68,9 @@
 LOCAL_USER_DECL;
 
 struct number {
-	char number[512];	/*!< Phone Number and/or Extension */
+	char number[512];	/*!< Phone Number(s) and/or Extension(s) */
 	long timeout;		/*!< Dial Timeout, if used. */
+	int order;		/*!< The order to dial in */
 	AST_LIST_ENTRY(number) entry; /*!< Next Number record */
 };
 
@@ -181,7 +182,7 @@
 	}
 }
 
-static struct number *create_followme_number(char *number, int timeout)
+static struct number *create_followme_number(char *number, int timeout, int numorder)
 {
 	struct number *cur;
 	char *tmp;
@@ -197,8 +198,9 @@
 			*tmp = '\0';
 		}
 		ast_copy_string(cur->number, number, sizeof(cur->number));
+		cur->order = numorder;
 		if (option_debug)
-			ast_log(LOG_DEBUG, "Created a number, %s, with a timeout of %ld.\n", cur->number, cur->timeout);
+			ast_log(LOG_DEBUG, "Created a number, %s, order of , %d, with a timeout of %ld.\n", cur->number, cur->order, cur->timeout);
 	}
 
 	return cur;
@@ -210,11 +212,13 @@
 	struct ast_config *cfg;
 	char *cat, *tmp;
 	struct ast_variable *var;
-	struct number *cur;
-	int new;
+	struct number *cur, *nm;
+	int new, idx;
 	char numberstr[90];
 	int timeout;
-	
+	char *timeoutstr;
+	int numorder;	
+
 	cfg = ast_config_load("followme.conf");
 	if (!cfg) {
 		ast_log(LOG_WARNING, "No follow me config file (followme.conf), so no follow me\n");
@@ -269,14 +273,31 @@
 					if ((tmp = strchr(numberstr, ','))) {
 						*tmp = '\0';
 						tmp++;
-						timeout = atoi(tmp);
+						timeoutstr = ast_strdupa(tmp);
+						if ((tmp = strchr(timeoutstr, ','))) {
+							*tmp = '\0';
+							tmp++;
+							numorder = atoi(tmp);
+							if (numorder < 0)
+								numorder = 0;
+						} else 
+							numorder = 0;
+						timeout = atoi(timeoutstr);
 						if (timeout < 0) 
 							timeout = 12;
-					} else
-							timeout = 12;
-					cur = create_followme_number(numberstr, timeout);
-		
-					AST_LIST_INSERT_HEAD(&f->numbers, cur, entry);
+					} else {
+						timeout = 12;
+						numorder = 0;
+					}
+
+					if (!numorder) {	
+						idx = 1;
+						AST_LIST_TRAVERSE(&f->numbers, nm, entry) 
+							idx++;
+						numorder = idx;
+					}
+					cur = create_followme_number(numberstr, timeout, numorder);
+					AST_LIST_INSERT_TAIL(&f->numbers, cur, entry);
 				} else {
 					profile_set_param(f, var->name, var->value, var->lineno, 1);
 					if (option_debug)
@@ -633,7 +654,7 @@
 	struct ast_channel *caller;
 	struct ast_channel *winner;
 	char dialarg[512];
-	int dg;
+	int dg, idx;
 	char *rest, *number;
 	struct findme_user *tmpuser;
 	struct findme_user *fmuser;
@@ -662,9 +683,14 @@
 	if (strlen(atxferexten) > ynlongest)
 		ynlongest = strlen(atxferexten);
 
-
+	idx = 1;
 	caller = tpargs->chan;
-	AST_LIST_TRAVERSE(&tpargs->cnumbers, nm, entry) {
+	AST_LIST_TRAVERSE(&tpargs->cnumbers, nm, entry)
+		if (nm->order == idx)
+			break;
+
+	while (nm) {
+
 		if (option_debug)	
 			ast_log(LOG_DEBUG, "Number %s timeout %ld\n",nm->number,nm->timeout);
 		time(&start_time);
@@ -750,6 +776,12 @@
 		headuser = NULL;	
 		if (winner)
 			break;
+
+		idx++;
+		AST_LIST_TRAVERSE(&tpargs->cnumbers, nm, entry)
+			if (nm->order == idx)
+				break;
+
 	}
 	if (!winner) 
 		tpargs->status = 1;
@@ -822,7 +854,7 @@
 				   (and locked) while we're trying to do a follow-me */
 				AST_LIST_HEAD_INIT_NOLOCK(&targs.cnumbers);
 				AST_LIST_TRAVERSE(&f->numbers, nm, entry) {
-					newnm = create_followme_number(nm->number, nm->timeout);
+					newnm = create_followme_number(nm->number, nm->timeout, nm->order);
 					AST_LIST_INSERT_TAIL(&targs.cnumbers, newnm, entry);
 				}
 				ast_mutex_unlock(&f->lock);



More information about the asterisk-commits mailing list