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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Mar 29 20:44:17 MST 2006


Author: bweschke
Date: Wed Mar 29 21:44:16 2006
New Revision: 16388

URL: http://svn.digium.com/view/asterisk?rev=16388&view=rev
Log:
 More cleanups. (Code formatting, better memory management, adapting new Asterisk best practices brought in with /trunk) thx oej!

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=16388&r1=16387&r2=16388&view=diff
==============================================================================
--- team/bweschke/findme_followme/apps/app_followme.c (original)
+++ team/bweschke/findme_followme/apps/app_followme.c Wed Mar 29 21:44:16 2006
@@ -65,30 +65,26 @@
 "  FollowMe(followmeid):\n"
 "Performs Find-Me/Follow-Me functionality as defined in followme.conf.\n";
 
-static char *defaultmoh = "default";    /* Default Music-On-Hold Class */
-
-STANDARD_LOCAL_USER;
 
 LOCAL_USER_DECL;
 
 struct number {
-	char number[512];	/* Phone Number and/or Extension */
-	long timeout;		/* Dial Timeout, if used. */
-	struct number *next;		/* Next Number record */
+	char number[512];	/*!< Phone Number and/or Extension */
+	long timeout;		/*!< Dial Timeout, if used. */
+	struct number *next;	/*!< Next Number record */
 };
 
 struct ast_call_followme {
 	ast_mutex_t lock;
-	char name[AST_MAX_EXTENSION];	/* Name - FollowMeID */
-	char moh[AST_MAX_CONTEXT];	/* Music On Hold Class to be used */
-	char context[AST_MAX_CONTEXT];  /* Context to dial from */
-	unsigned int active;		/* Profile is active (1), or disabled (0). */
-	char vm[AST_MAX_CONTEXT];	/* Voicemail Box Defined for the profile */
-	
-	struct number *numbers;		/* Head of the list of follow-me numbers */
-	struct number *blnumbers; 	/* Head of the list of black-listed numbers */
-	struct number *wlnumbers;	/* Head of the list of white-listed numbers */
-	struct ast_call_followme *next; /* Next Follow-Me record */
+	char name[AST_MAX_EXTENSION];	/*!< Name - FollowMeID */
+	char moh[AST_MAX_CONTEXT];	/*!< Music On Hold Class to be used */
+	char context[AST_MAX_CONTEXT];  /*!< Context to dial from */
+	unsigned int active;		/*!< Profile is active (1), or disabled (0). */
+	
+	struct number *numbers;		/*!< Head of the list of follow-me numbers */
+	struct number *blnumbers; 	/*!< Head of the list of black-listed numbers */
+	struct number *wlnumbers;	/*!< Head of the list of white-listed numbers */
+	struct ast_call_followme *next; /*!< Next Follow-Me record */
 };
 
 struct thread_args {
@@ -110,21 +106,21 @@
 	struct findme_user *next;	
 };
 
-struct thread_args targs;
-struct ast_bridge_config config;
-int res, ret = 0, ynlongest = 0;
-char toast[80];
-time_t start_time, answer_time, end_time;
-
-char *featuredigittostr;
-int featuredigittimeout = 5000;
-int maxretries = 3;
-
-char takecall[20] = "1", nextindp[20] = "2", nextinfmfm[20] = "", blindxferexten[20] = "", atxferexten[20] = "";
+static struct thread_args targs;
+static struct ast_bridge_config config;
+static int ynlongest = 0;
+static char toast[80];
+static time_t start_time, answer_time, end_time;
+
+static char *featuredigittostr;
+static int featuredigittimeout = 5000;		/*!< Feature Digit Timeout */
+static const char *defaultmoh = "default";    	/*!< Default Music-On-Hold Class */
+
+static char takecall[20] = "1", nextindp[20] = "2", nextinfmfm[20] = "", blindxferexten[20] = "", atxferexten[20] = "";
 
 static struct ast_call_followme *followmes = NULL;
+
 AST_MUTEX_DEFINE_STATIC(fmlock);
-
 
 static void free_numbers(struct ast_call_followme *f, int all)
 {
@@ -183,14 +179,12 @@
 {
 	struct ast_call_followme *f;
 
-	f = malloc(sizeof(*f));
+	f = ast_calloc(1, sizeof(*f));
 	if (f) {
-		memset(f, 0, sizeof(*f));
 		ast_mutex_init(&f->lock);
 		ast_copy_string(f->name, fmname, sizeof(f->name));
 		ast_copy_string(f->moh, "", sizeof(f->moh));
 		ast_copy_string(f->context, "", sizeof(f->context));
-		ast_copy_string(f->vm, "", sizeof(f->vm));
 	}
 	return f;
 }
@@ -205,12 +199,10 @@
    
 static void profile_set_param(struct ast_call_followme *f, const char *param, const char *val, int linenum, int failunknown)
 {
-	if (!strcasecmp(param, "music") || !strcasecmp(param, "musiconhold")) {
+	if (!strcasecmp(param, "musicclass") || !strcasecmp(param, "musiconhold") || !strcasecmp(param, "music")) {
 		ast_copy_string(f->moh, val, sizeof(f->moh));
 	} else if (!strcasecmp(param, "context")) {
 		ast_copy_string(f->context, val, sizeof(f->context));
-	} else if (!strcasecmp(param, "vmbox")) {
-		ast_copy_string(f->vm, val, sizeof(f->vm));
 	} else if(failunknown) {
 		if (linenum >= 0) {
 			ast_log(LOG_WARNING, "Unknown keyword in profile '%s': %s at line %d of followme.conf\n",
@@ -228,25 +220,23 @@
 	
 	/* Add a new number */
 
-	cur = malloc(sizeof(struct number));
+	cur = ast_calloc(1, sizeof(*cur));
 
 	if (cur) {
-		memset(cur, 0, sizeof(struct number));
 		cur->timeout = timeout;
-		if (strchr(number, ','))
-		{ 
+		if (strchr(number, ',')) { 
 			tmp = strchr(number, ',');
 			*tmp = '\0';
 		}
 		ast_copy_string(cur->number, number, sizeof(cur->number));
-		ast_log(LOG_DEBUG, "Created a number, %s, with a timeout of %ld.\n", cur->number, cur->timeout);
-
+		if (option_debug > 2)
+			ast_log(LOG_DEBUG, "Created a number, %s, with a timeout of %ld.\n", cur->number, cur->timeout);
 	}
 
 	return cur;
 }
 
-static void reload_followme(void)
+static int reload_followme(void)
 {
 	struct ast_call_followme *f;
 	struct ast_config *cfg;
@@ -260,9 +250,13 @@
 	cfg = ast_config_load("followme.conf");
 	if (!cfg) {
 		ast_log(LOG_WARNING, "No follow me config file (followme.conf), so no follow me\n");
-		return;
+		return 0;
 	}
 	ast_mutex_lock(&fmlock);
+
+	/* Reset Global Var Values */
+	featuredigittimeout = 5000;
+
 	/* Mark all profiles as inactive for the moment */
 	f = followmes;
 	while(f) {
@@ -280,73 +274,77 @@
 	/* Chug through config file */
 	cat = ast_category_browse(cfg, NULL);
 	while(cat) {
-			/* Define a new profile */
-			/* Look for an existing one */
-			f = followmes;
-			while(f) {
-				if (!strcmp(f->name, cat))
-					break;
-				f = f->next;
-			}
+		/* Define a new profile */
+		/* Look for an existing one */
+		f = followmes;
+		while(f) {
+			if (!strcmp(f->name, cat))
+				break;
+			f = f->next;
+		}
+		if (option_debug > 2)
 			ast_log(LOG_DEBUG, "New profile %s.\n", cat);
-			if (!f) {
-				/* Make one then */
-				f = alloc_profile(cat);
-				new = 1;
-			} else
-				new = 0;
-			if (f) {
-				if (!new)
-					ast_mutex_lock(&f->lock);
-				/* Re-initialize the profile */
-				init_profile(f);
-				free_numbers(f, 1);
-				prev = f->numbers;
-				if (prev) {
-					/* find the end of any dynamic numbers */
-					while(prev->next)
-						prev = prev->next;
+		if (!f) {
+			/* Make one then */
+			f = alloc_profile(cat);
+			new = 1;
+		} else
+			new = 0;
+	
+		if (f) {
+			if (!new)
+				ast_mutex_lock(&f->lock);
+			/* Re-initialize the profile */
+			init_profile(f);
+			free_numbers(f, 1);
+			prev = f->numbers;
+			if (prev) {
+				/* find the end of any dynamic numbers */
+				while(prev->next)
+					prev = prev->next;
+			}
+			var = ast_variable_browse(cfg, cat);
+			while(var) {
+				if (!strcasecmp(var->name, "number")) {
+					/* Add a new number */
+					ast_copy_string(numberstr, var->value, sizeof(numberstr));
+					if ((tmp = strchr(numberstr, ','))) {
+						*tmp = '\0';
+						tmp++;
+						timeout = atoi(tmp);
+						if (timeout < 0) 
+							timeout = 12;
+					} else
+							timeout = 12;
+					cur = create_followme_number(numberstr, timeout);
+						
+					if (cur) {
+						if (prev)
+							prev->next = cur;
+						else
+							f->numbers = cur;
+						prev = cur;
+					}
+				} else {
+					profile_set_param(f, var->name, var->value, var->lineno, 1);
+					if (option_debug > 2)
+						ast_log(LOG_DEBUG, "Logging parameter %s with value %s from lineno %d\n", var->name, var->value, var->lineno);
 				}
-				var = ast_variable_browse(cfg, cat);
-				while(var) {
-					if (!strcasecmp(var->name, "number")) {
-						/* Add a new number */
-						ast_copy_string(numberstr, var->value, sizeof(numberstr));
-						if ((tmp = strchr(numberstr, ','))) {
-							*tmp = '\0';
-							tmp++;
-							timeout = atoi(tmp);
-							if (timeout < 0) {
-								timeout = 12;
-							}
-						} else
-							timeout = 12;
-						cur = create_followme_number(numberstr, timeout);
-						
-						if (cur) {
-							if (prev)
-								prev->next = cur;
-							else
-								f->numbers = cur;
-							prev = cur;
-						}
-					} else {
-						profile_set_param(f, var->name, var->value, var->lineno, 1);
-						ast_log(LOG_DEBUG, "Logging parameter %s with value %s from lineno %d\n", var->name, var->value, var->lineno);
-					}
-					var = var->next;
-				}
-				if (!new) 
-					ast_mutex_unlock(&f->lock);
-				if (new) {
-					f->next = followmes;
-					followmes = f;
-				}
-			}
+				var = var->next;
+			} /* End while(var) loop */
+
+			if (!new) 
+				ast_mutex_unlock(&f->lock);
+			if (new) {
+				f->next = followmes;
+				followmes = f;
+			}
+		}
 		cat = ast_category_browse(cfg, cat);
 	}
 	ast_config_destroy(cfg);
 	ast_mutex_unlock(&fmlock);
+	return 1;
 }
 
 static void clear_calling_tree(struct findme_user *headuser,int wholetree) 
@@ -387,9 +385,8 @@
 
 
 
-static struct ast_channel *wait_for_winner(struct findme_user *headuser, struct number *nm, struct ast_channel *caller, char *namerecloc, int *status)
-{
-
+static struct ast_channel *wait_for_winner(struct findme_user *headuser, struct number *nm, struct ast_channel *caller, char *namerecloc, int *status) 
+{
 		struct ast_channel *watchers[256];
 		int pos;
 		struct ast_channel *winner;
@@ -397,7 +394,7 @@
 		int ctstatus;
 		int dg;
 		struct findme_user *tmpuser = NULL;
-		int *to = malloc(sizeof(int));
+		int *to = ast_calloc(1, sizeof(*to));
 		int livechannels = 0;
 		int tmpto;
 		long totalwait = 0;
@@ -414,6 +411,7 @@
 			if (!caller) {
 				ast_log(LOG_NOTICE, "Original caller hungup. Cleanup.\n");
 				clear_calling_tree(headuser,1);
+				free(to);
 				return 0;
 			}
 			ctstatus = 0;
@@ -437,6 +435,7 @@
 								ast_sched_runq(tmpuser->ochan->sched);
 							} else {
 								ast_log(LOG_WARNING, "Unable to playback %s.\n", callfromname);
+								free(to);
 								return NULL;
 							}							
 						}
@@ -453,6 +452,7 @@
 										tmpuser->state = 2;
 									} else {
 										ast_log(LOG_WARNING, "Unable to playback %s.\n", namerecloc);
+										free(to);
 										return NULL;
 									}
 								} else if (tmpuser->state == 2) {
@@ -464,7 +464,7 @@
 										tmpuser->state = 3;
 										
 									} else {
-										ast_log(LOG_WARNING, "Unable to playback %s.\n", pressbuttonname);
+										ast_log(LOG_WARNING, "Unable to playback %s.\n", pressbuttonname);										  free(to);
 										return NULL;
 									} 
 								} else if (tmpuser->state == 3) {
@@ -484,6 +484,7 @@
 				if (totalwait <= 0) {
 					ast_log(LOG_NOTICE, "We've hit our timeout for this step. Drop everyone and move on to the next one. %ld\n", totalwait);
 					clear_calling_tree(headuser,1);
+					free(to);
 					return 0;
 				}
 				if (winner) {
@@ -522,6 +523,7 @@
 										tmpuser->state = 1;
 									} else {
 										ast_log(LOG_WARNING, "Unable to playback %s.\n", callfromname);
+										free(to);
 										return NULL;
 									}							
 								}
@@ -567,7 +569,9 @@
 									ast_verbose( VERBOSE_PREFIX_3 "%s stopped sounds\n", winner->name);
 								break;
 							default:
-								ast_log(LOG_DEBUG, "Dunno what to do with control type %d\n", f->subclass);
+								if (option_debug > 2)
+									ast_log(LOG_DEBUG, "Dunno what to do with control type %d\n", f->subclass);
+								break;
 							}
 						} 
 						if (tmpuser && tmpuser->state == 3 && f->frametype == AST_FRAME_DTMF) {
@@ -583,26 +587,31 @@
 								ast_log(LOG_NOTICE, "reached longest possible match\n");
 								if (!strcmp(tmpuser->yn, takecall)) {
 									ast_log(LOG_NOTICE, "Match to take the call!\n");
+									free(to);
 									return tmpuser->ochan;	
 								}
 								if (!strcmp(tmpuser->yn, nextindp)) {
 									ast_log(LOG_NOTICE, "Next in dial plan step requested.\n");
 									*status = 1;
+									free(to);
 									return 0;
 								}	
 								if (!strcmp(tmpuser->yn, nextinfmfm)) {
 									ast_log(LOG_NOTICE, "Next in find me/follow me step requested.\n");
 									*status = 2;
+									free(to);
 									return 0;
 								}	
 								if (!strcmp(tmpuser->yn, blindxferexten)) {
 									ast_log(LOG_NOTICE, "Blind Transfer requested.\n");
 									*status = 3;
+									free(to);
 									return 0;
 								}	
 								if (!strcmp(tmpuser->yn, atxferexten)) {
 									ast_log(LOG_NOTICE, "Attended Transfer requested.\n");
 									*status = 4;
+									free(to);
 									return 0;
 								}	
 
@@ -616,6 +625,7 @@
 							ast_log(LOG_NOTICE, "we didn't get a frame. hanging up. dg is %d\n",dg);					      
 							if (!dg) {
 								clear_calling_tree(headuser,1);
+								free(to);
 								return 0;
 							} else {
 								tmpuser->state = -1;
@@ -624,6 +634,7 @@
 								ast_log(LOG_NOTICE, "live channels left %d\n", livechannels);
 								if (!livechannels) {
 									ast_log(LOG_NOTICE, "no live channels left. exiting.\n");
+									free(to);
 									return 0;
 								}
 							}
@@ -640,148 +651,144 @@
 		}
 		
 		/* --- WAIT FOR WINNER NUMBER END! -----------*/
+		free(to);
 		return NULL;
 }
 
-static void findmethread(void *args)
-{
-				struct thread_args *tpargs;
-				struct number *nm;
-				struct ast_channel *outbound = NULL;
-				struct ast_channel *caller;
-				struct ast_channel *winner = NULL;
-				char dialarg[512];
-				int dg;
-				char *rest, *number;
-				struct findme_user *tmpuser = NULL;
-			        struct findme_user *fmuser = NULL;
-			        struct findme_user *headuser = NULL;
-				int status;
+static void findmeexec(void *args)
+{
+	struct thread_args *tpargs;
+	struct number *nm;
+	struct ast_channel *outbound = NULL;
+	struct ast_channel *caller;
+	struct ast_channel *winner = NULL;
+	char dialarg[512];
+	int dg;
+	char *rest, *number;
+	struct findme_user *tmpuser = NULL;
+	struct findme_user *fmuser = NULL;
+	struct findme_user *headuser = NULL;
+	int status;
 					
-	
-				tpargs = (struct thread_args *)args;
+
+	tpargs = (struct thread_args *)args;
+			
+	if (!tpargs->chan) 
+		return;
+	
+
+	/* We're going to figure out what the longest possible string of digits to collect is */
+	ynlongest = 0;
+	if (strlen((void *)&takecall) > ynlongest)
+		ynlongest = strlen((void *)&takecall);
+	if (strlen((void *)&nextindp) > ynlongest)
+		ynlongest = strlen((void *)&nextindp);
+	if (strlen((void *)&nextinfmfm) > ynlongest)
+		ynlongest = strlen((void *)&nextinfmfm);
+	if (strlen((void *)&blindxferexten) > ynlongest)
+		ynlongest = strlen((void *)&blindxferexten);
+	if (strlen((void *)&atxferexten) > ynlongest)
+		ynlongest = strlen((void *)&atxferexten);
+
+
+	caller = tpargs->chan;
+	nm = tpargs->numbers;
+	while (nm) {
+		if (option_debug > 2)	
+			ast_log(LOG_DEBUG, "sleeping now inside the thread. Number %s timeout %ld\n",nm->number,nm->timeout);
+		time(&start_time);
+
+		number = ast_strdupa(nm->number);
+		ast_log(LOG_NOTICE, "examining %s\n", number);
+		do {
+			rest = strchr(number, '&');
+			if (rest) {
+				*rest = 0;
+				rest++;
+			}
+
+			if (!strcmp(tpargs->context, ""))
+				sprintf(dialarg, "%s", number);
+			else
+				sprintf(dialarg, "%s@%s", number, tpargs->context);
+					
+			tmpuser = ast_calloc(1, sizeof(*tmpuser));
+			if (!tmpuser) {
+				ast_log(LOG_WARNING, "Out of memory!\n");
+				return;
+			}
+					
+			outbound = ast_request("Local", ast_best_codec(caller->nativeformats), dialarg, &dg);
+			if (outbound) {
+				ast_set_callerid(outbound, caller->cid.cid_num, caller->cid.cid_name, caller->cid.cid_num);
+				ast_channel_inherit_variables(tpargs->chan, outbound);
+				ast_log(LOG_NOTICE, "calling %s\n", dialarg);
+				if (!ast_call(outbound,dialarg,0)) {
+					tmpuser->ochan = outbound;
+					tmpuser->state = 0;
+					ast_copy_string(tmpuser->dialarg, dialarg, sizeof(dialarg));
+					tmpuser->next = fmuser;
+					fmuser = tmpuser;
+				} else { 
+					ast_log(LOG_NOTICE, "couldn't reach at this number.\n"); 
+					if (outbound) {
+						if (!outbound->cdr) {
+							outbound->cdr = ast_cdr_alloc();
+						}
+						if (outbound->cdr) {
+							ast_cdr_init(outbound->cdr, outbound);
+							char tmp[256];
+							snprintf(tmp, 256, "%s/%s", "Local", dialarg);
+							ast_cdr_setapp(outbound->cdr,"FollowMe",tmp);
+							ast_cdr_update(outbound);
+							ast_cdr_start(outbound->cdr);
+							ast_cdr_end(outbound->cdr);
+							/* If the cause wasn't handled properly */
+							if (ast_cdr_disposition(outbound->cdr,outbound->hangupcause))
+								ast_cdr_failed(outbound->cdr);
+						} else {
+							ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
+							ast_hangup(outbound);
+							outbound = NULL;
+						}
+					}
+						
+				}
+			} else 
+				ast_log(LOG_WARNING, "Unable to allocate a channel for Local/%s cause: %s\n", dialarg, ast_cause2str(dg));
+					
+			number = rest;
+		} while (number);
 				
-				if (!tpargs->chan) {
-					return;
-				}
-
-				/* We're going to figure out what the longest possible string of digits to collect is */
-				ynlongest = 0;
-				if (strlen((void *)&takecall) > ynlongest)
-					ynlongest = strlen((void *)&takecall);
-				if (strlen((void *)&nextindp) > ynlongest)
-					ynlongest = strlen((void *)&nextindp);
-				if (strlen((void *)&nextinfmfm) > ynlongest)
-					ynlongest = strlen((void *)&nextinfmfm);
-				if (strlen((void *)&blindxferexten) > ynlongest)
-					ynlongest = strlen((void *)&blindxferexten);
-				if (strlen((void *)&atxferexten) > ynlongest)
-					ynlongest = strlen((void *)&atxferexten);
-
-
-				caller = tpargs->chan;
-				nm = tpargs->numbers;
-				while (nm)
-				{
-				
-				ast_log(LOG_DEBUG, "sleeping now inside the thread. Number %s timeout %ld\n",nm->number,nm->timeout);
-				time(&start_time);
-
-				number = ast_strdupa(nm->number);
-				ast_log(LOG_NOTICE, "examining %s\n", number);
-				do {
-					rest = strchr(number, '&');
-					if (rest) {
-						*rest = 0;
-						rest++;
-					}
-
-					if (!strcmp(tpargs->context, ""))
-						sprintf(dialarg, "%s", number);
-					else
-						sprintf(dialarg, "%s@%s", number, tpargs->context);
-					
-					tmpuser = malloc(sizeof(struct findme_user));
-					if (!tmpuser) {
-						ast_log(LOG_WARNING, "Out of memory!\n");
-						return;
-					}
-					memset(tmpuser, 0, sizeof(struct findme_user));
-					
-					outbound = ast_request("Local", ast_best_codec(caller->nativeformats), dialarg, &dg);
-					if (outbound) {
-						ast_set_callerid(outbound, caller->cid.cid_num, caller->cid.cid_name, caller->cid.cid_num);
-						ast_channel_inherit_variables(tpargs->chan, outbound);
-						ast_log(LOG_NOTICE, "calling %s\n", dialarg);
-						if (!ast_call(outbound,dialarg,0)) {
-							tmpuser->ochan = outbound;
-							tmpuser->state = 0;
-							ast_copy_string(tmpuser->dialarg, dialarg, sizeof(dialarg));
-							tmpuser->next = fmuser;
-							fmuser = tmpuser;
-						} else { 
-							ast_log(LOG_NOTICE, "couldn't reach at this number.\n"); 
-								 if (outbound) {
-									if (!outbound->cdr) {
-										outbound->cdr = ast_cdr_alloc();
-										if (outbound->cdr)
-											ast_cdr_init(outbound->cdr, outbound);
-									}
-									if (outbound->cdr) {
-										char tmp[256];
-										snprintf(tmp, 256, "%s/%s", "Local", dialarg);
-										ast_cdr_setapp(outbound->cdr,"FollowMe",tmp);
-										ast_cdr_update(outbound);
-										ast_cdr_start(outbound->cdr);
-										ast_cdr_end(outbound->cdr);
-										/* If the cause wasn't handled properly */
-										if (ast_cdr_disposition(outbound->cdr,outbound->hangupcause))
-											ast_cdr_failed(outbound->cdr);
-									} else
-										ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
-									ast_hangup(outbound);
-									outbound = NULL;
-								}
-							
-						}
-						
-						
-					} else {
-						ast_log(LOG_WARNING, "Unable to allocate a channel for Local/%s cause: %s\n", dialarg, ast_cause2str(dg));
-					}
-					
-					number = rest;
-				} while (number);
-				
-				headuser = fmuser;
+		headuser = fmuser;
 			
-				status = 0;	
-				if (headuser->ochan)
-					winner = wait_for_winner(headuser, nm, caller, tpargs->namerecloc, &status);
+		status = 0;	
+		if (headuser->ochan)
+			winner = wait_for_winner(headuser, nm, caller, tpargs->namerecloc, &status);
 		
 					
-				fmuser = headuser;
-				while (fmuser) {
-					headuser = fmuser->next;
-					if (fmuser->ochan != winner)
-						clear_calling_tree(fmuser, 0);
-					free(fmuser);
-					fmuser = headuser;
-				}
-				fmuser = NULL;
-				tmpuser = NULL;
-				headuser = NULL;	
-				nm = nm->next;
-				if (winner)
-					break;
-				}
-				if (!winner) {
-					tpargs->status = 1;
-				} else {
-					tpargs->status = 100;
-					tpargs->outbound = winner;
-				}
-				return;
+		fmuser = headuser;
+		while (fmuser) {
+			headuser = fmuser->next;
+			if (fmuser->ochan != winner)
+				clear_calling_tree(fmuser, 0);
+			free(fmuser);
+			fmuser = headuser;
+		}
+		fmuser = NULL;
+		tmpuser = NULL;
+		headuser = NULL;	
+		nm = nm->next;
+		if (winner)
+			break;
+	}
+	if (!winner) {
+		tpargs->status = 1;
+	} else {
+		tpargs->status = 100;
+		tpargs->outbound = winner;
+	}
+	return;
 		
 }
 
@@ -816,7 +823,7 @@
 
 	AST_STANDARD_APP_ARGS(args, argstr);
 
-	if (!ast_strlen_zero(args.followmeid)) 
+	if (!ast_strlen_zero(args.followmeid) && (option_debug > 2)) 
 		ast_log(LOG_DEBUG, "Follow me ID value is : %s\n", args.followmeid);
 	
 
@@ -826,7 +833,8 @@
 					break;
 				f = f->next;
 			}
-			ast_log(LOG_DEBUG, "New profile %s.\n", args.followmeid);
+			if (option_debug > 2)
+				ast_log(LOG_DEBUG, "New profile %s.\n", args.followmeid);
 			if (!f)
 			{ 
 				ast_log(LOG_WARNING, "Profile not found.");
@@ -852,7 +860,8 @@
 				else
 					ast_moh_start(chan, f->moh);
 				while (nm) {
-					 ast_log(LOG_DEBUG, "Number %s, timeout %ld\n", nm->number, nm->timeout);
+					 	if (option_debug > 2)
+							ast_log(LOG_DEBUG, "Number %s, timeout %ld\n", nm->number, nm->timeout);
 					 nm = nm->next;
 				}
 
@@ -863,7 +872,7 @@
 				ast_copy_string(targs.namerecloc, namerecloc, sizeof(targs.namerecloc));
 				ast_copy_string(targs.context, f->context, sizeof(targs.context));
 
-				findmethread(&targs);			
+				findmeexec(&targs);			
 	
 				unlink(namerecloc);	
 				if (targs.status != 100)
@@ -917,21 +926,32 @@
 			}
 	outrun:
 	
-	/* Do our thing here */
 	LOCAL_USER_REMOVE(u);
 	return res;
 }
 
 int unload_module(void)
 {
+	struct ast_call_followme *f, *prior;
+	/* Free Memory. Yeah! I'm free! */
+	f = followmes;
+	while(f) {
+		f->active = 0;
+		prior = f;
+		f = f->next;
+		free_numbers(f,1);
+		free(prior);
+	}
 	STANDARD_HANGUP_LOCALUSERS;
 	return ast_unregister_application(app);
 }
 
 int load_module(void)
 {
-	reload_followme();
-	return ast_register_application(app, app_exec, synopsis, descrip);
+	if (reload_followme())
+		return ast_register_application(app, app_exec, synopsis, descrip);
+	else
+		return -1;
 }
 
 char *description(void)



More information about the asterisk-commits mailing list