[asterisk-commits] branch bweschke/bug_5374 - r7679 in /team/bweschke/bug_5374: ./ apps/ channel...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Dec 30 10:49:14 CST 2005


Author: bweschke
Date: Fri Dec 30 10:49:07 2005
New Revision: 7679

URL: http://svn.digium.com/view/asterisk?rev=7679&view=rev
Log:
 Bringing branch up to date with /trunk


Added:
    team/bweschke/bug_5374/doc/README.app_sms
      - copied unchanged from r7678, trunk/doc/README.app_sms
    team/bweschke/bug_5374/doc/README.channels
      - copied unchanged from r7678, trunk/doc/README.channels
    team/bweschke/bug_5374/doc/README.linkedlists
      - copied unchanged from r7678, trunk/doc/README.linkedlists
Removed:
    team/bweschke/bug_5374/doc/app_sms.html
    team/bweschke/bug_5374/doc/channel.txt
    team/bweschke/bug_5374/doc/linkedlists.README
Modified:
    team/bweschke/bug_5374/   (props changed)
    team/bweschke/bug_5374/Makefile
    team/bweschke/bug_5374/apps/app_chanspy.c
    team/bweschke/bug_5374/apps/app_dictate.c
    team/bweschke/bug_5374/apps/app_queue.c
    team/bweschke/bug_5374/apps/app_voicemail.c
    team/bweschke/bug_5374/asterisk.c
    team/bweschke/bug_5374/channel.c
    team/bweschke/bug_5374/channels/chan_iax2.c
    team/bweschke/bug_5374/channels/chan_sip.c
    team/bweschke/bug_5374/channels/iax2-provision.c
    team/bweschke/bug_5374/cli.c
    team/bweschke/bug_5374/config.c
    team/bweschke/bug_5374/configs/extconfig.conf.sample
    team/bweschke/bug_5374/funcs/func_strings.c
    team/bweschke/bug_5374/include/asterisk/logger.h
    team/bweschke/bug_5374/logger.c
    team/bweschke/bug_5374/manager.c
    team/bweschke/bug_5374/pbx.c

Propchange: team/bweschke/bug_5374/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Dec 30 10:49:07 2005
@@ -1,2 +1,2 @@
 /branches/1.2:1-7351
-/trunk:1-7644
+/trunk:1-7678

Modified: team/bweschke/bug_5374/Makefile
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/Makefile?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/Makefile (original)
+++ team/bweschke/bug_5374/Makefile Fri Dec 30 10:49:07 2005
@@ -45,6 +45,11 @@
 
 #Tell gcc to optimize the code
 OPTIMIZE+=-O6
+else
+  # Stack backtraces, while useful for debugging, are incompatible with optimizations
+  ifeq (${OSARCH},Linux)
+    CFLAGS+=-DSTACK_BACKTRACES
+  endif
 endif
 
 #Overwite config files on "make samples"
@@ -332,7 +337,10 @@
 ASTCFLAGS+= $(MALLOC_DEBUG)
 ASTCFLAGS+= $(BUSYDETECT)
 ASTCFLAGS+= $(OPTIONS)
+ifneq ($(findstring dont-optimize,$(MAKECMDGOALS)),dont-optimize)
 ASTCFLAGS+= -fomit-frame-pointer 
+endif
+
 SUBDIRS=res channels pbx apps codecs formats agi cdr funcs utils stdtime
 
 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \

Modified: team/bweschke/bug_5374/apps/app_chanspy.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/apps/app_chanspy.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/apps/app_chanspy.c (original)
+++ team/bweschke/bug_5374/apps/app_chanspy.c Fri Dec 30 10:49:07 2005
@@ -440,7 +440,7 @@
 	if (recbase) {
 		char filename[512];
 		snprintf(filename,sizeof(filename),"%s/%s.%d.raw",ast_config_AST_MONITOR_DIR, recbase, (int)time(NULL));
-		if ((fd = open(filename, O_CREAT | O_WRONLY, O_TRUNC)) <= 0) {
+		if ((fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644)) <= 0) {
 			ast_log(LOG_WARNING, "Cannot open %s for recording\n", filename);
 			fd = 0;
 		}

Modified: team/bweschke/bug_5374/apps/app_dictate.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/apps/app_dictate.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/apps/app_dictate.c (original)
+++ team/bweschke/bug_5374/apps/app_dictate.c Fri Dec 30 10:49:07 2005
@@ -47,7 +47,7 @@
 static char *tdesc = "Virtual Dictation Machine";
 static char *app = "Dictate";
 static char *synopsis = "Virtual Dictation Machine";
-static char *desc = "  Dictate([<base_dir>])\n"
+static char *desc = "  Dictate([<base_dir>[|<filename>]])\n"
 "Start dictation machine using optional base dir for files.\n";
 
 
@@ -80,7 +80,7 @@
 
 static int dictate_exec(struct ast_channel *chan, void *data)
 {
-	char *mydata, *argv[2], *path = NULL, filein[256];
+	char *mydata, *argv[3], *path = NULL, filein[256], *filename = "";
 	char dftbase[256];
 	char *base;
 	struct ast_flags flags = {0};
@@ -112,7 +112,9 @@
 	} else {
 		base = dftbase;
 	}
-
+	if (argc && argv[1]) {
+		filename = argv[1];
+	} 
 	oldr = chan->readformat;
 	if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)) < 0) {
 		ast_log(LOG_WARNING, "Unable to set to linear mode.\n");
@@ -122,13 +124,17 @@
 
 	ast_answer(chan);
 	ast_safe_sleep(chan, 200);
-	for(res = 0; !res;) {
-		if (ast_app_getdata(chan, "dictate/enter_filename", filein, sizeof(filein), 0) || 
-			ast_strlen_zero(filein)) {
-			res = -1;
-			break;
+	for (res = 0; !res;) {
+		if (ast_strlen_zero(filename)) {
+			if (ast_app_getdata(chan, "dictate/enter_filename", filein, sizeof(filein), 0) || 
+				ast_strlen_zero(filein)) {
+				res = -1;
+				break;
+			}
+		} else {
+			ast_copy_string(filein, filename, sizeof(filein));
+			filename = "";
 		}
-		
 		mkdir(base, 0755);
 		len = strlen(base) + strlen(filein) + 2;
 		if (!path || len > maxlen) {

Modified: team/bweschke/bug_5374/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/apps/app_queue.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/apps/app_queue.c (original)
+++ team/bweschke/bug_5374/apps/app_queue.c Fri Dec 30 10:49:07 2005
@@ -3360,17 +3360,22 @@
 static char *complete_queue(char *line, char *word, int pos, int state)
 {
 	struct ast_call_queue *q;
-	int which=0;
+	char *ret = NULL;
+	int which = 0;
+	int wordlen = strlen(word);
 	
 	ast_mutex_lock(&qlock);
 	for (q = queues; q; q = q->next) {
-		if (!strncasecmp(word, q->name, strlen(word))) {
-			if (++which > state)
+		if (!strncasecmp(word, q->name, wordlen)) {
+			if (++which > state) {
+				ret = strdup(q->name);	
 				break;
+			}
 		}
 	}
 	ast_mutex_unlock(&qlock);
-	return q ? strdup(q->name) : NULL;
+
+	return ret;
 }
 
 /*!\brief callback to display queues status in manager 

Modified: team/bweschke/bug_5374/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/apps/app_voicemail.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/apps/app_voicemail.c (original)
+++ team/bweschke/bug_5374/apps/app_voicemail.c Fri Dec 30 10:49:07 2005
@@ -1587,7 +1587,7 @@
 	return 1;
 }
 
-static void prep_email_sub_vars(struct ast_channel *ast, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *dur, char *date, char *passdata, size_t passdatasize)
+static void prep_email_sub_vars(struct ast_channel *ast, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *dur, char *date, char *passdata, size_t passdatasize, const char *category)
 {
 	char callerid[256];
 	/* Prepare variables for substition in email body and subject */
@@ -1601,6 +1601,7 @@
 	pbx_builtin_setvar_helper(ast, "VM_CIDNAME", (cidname ? cidname : "an unknown caller"));
 	pbx_builtin_setvar_helper(ast, "VM_CIDNUM", (cidnum ? cidnum : "an unknown caller"));
 	pbx_builtin_setvar_helper(ast, "VM_DATE", date);
+	pbx_builtin_setvar_helper(ast, "VM_CATEGORY", category ? ast_strdupa(category) : "no category");
 }
 
 /*
@@ -1638,7 +1639,7 @@
 	return p;
 }
 
-static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *attach, char *format, int duration, int attach_user_voicemail)
+static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *attach, char *format, int duration, int attach_user_voicemail, const char *category)
 {
 	FILE *p=NULL;
 	char date[256];
@@ -1685,7 +1686,7 @@
 				int vmlen = strlen(fromstring)*3 + 200;
 				if ((passdata = alloca(vmlen))) {
 					memset(passdata, 0, vmlen);
-					prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,passdata, vmlen);
+					prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
 					pbx_substitute_variables_helper(ast,fromstring,passdata,vmlen);
 					fprintf(p, "From: %s <%s>\n",passdata,who);
 				} else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
@@ -1702,7 +1703,7 @@
 				int vmlen = strlen(emailsubject)*3 + 200;
 				if ((passdata = alloca(vmlen))) {
 					memset(passdata, 0, vmlen);
-					prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,passdata, vmlen);
+					prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
 					pbx_substitute_variables_helper(ast,emailsubject,passdata,vmlen);
 					fprintf(p, "Subject: %s\n",passdata);
 				} else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
@@ -1734,7 +1735,7 @@
 				int vmlen = strlen(emailbody)*3 + 200;
 				if ((passdata = alloca(vmlen))) {
 					memset(passdata, 0, vmlen);
-					prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,passdata, vmlen);
+					prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
 					pbx_substitute_variables_helper(ast,emailbody,passdata,vmlen);
 					fprintf(p, "%s\n",passdata);
 				} else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
@@ -1771,7 +1772,7 @@
 	return 0;
 }
 
-static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, int duration, struct ast_vm_user *vmu)
+static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, int duration, struct ast_vm_user *vmu, const char *category)
 {
 	char date[256];
 	char host[MAXHOSTNAMELEN]="";
@@ -1803,7 +1804,7 @@
 				int vmlen = strlen(fromstring)*3 + 200;
 				if ((passdata = alloca(vmlen))) {
 					memset(passdata, 0, vmlen);
-					prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,passdata, vmlen);
+					prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
 					pbx_substitute_variables_helper(ast,pagerfromstring,passdata,vmlen);
 					fprintf(p, "From: %s <%s>\n",passdata,who);
 				} else 
@@ -1820,7 +1821,7 @@
                                int vmlen = strlen(pagersubject)*3 + 200;
                                if ((passdata = alloca(vmlen))) {
                                        memset(passdata, 0, vmlen);
-                                       prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,passdata, vmlen);
+                                       prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
                                        pbx_substitute_variables_helper(ast,pagersubject,passdata,vmlen);
                                        fprintf(p, "Subject: %s\n\n",passdata);
                                } else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
@@ -1836,7 +1837,7 @@
                                int vmlen = strlen(pagerbody)*3 + 200;
                                if ((passdata = alloca(vmlen))) {
                                        memset(passdata, 0, vmlen);
-                                       prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,passdata, vmlen);
+                                       prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
                                        pbx_substitute_variables_helper(ast,pagerbody,passdata,vmlen);
                                        fprintf(p, "%s\n",passdata);
                                } else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
@@ -3259,6 +3260,7 @@
 {
 	char todir[256], fn[256], ext_context[256], *stringp;
 	int newmsgs = 0, oldmsgs = 0;
+	const char *category = pbx_builtin_getvar_helper(chan, "VM_CATEGORY");
 
 	make_dir(todir, sizeof(todir), vmu->context, vmu->mailbox, "INBOX");
 	make_file(fn, sizeof(fn), todir, msgnum);
@@ -3276,14 +3278,14 @@
 			attach_user_voicemail = ast_test_flag(vmu, VM_ATTACH);
 			if (!ast_strlen_zero(vmu->serveremail))
 				myserveremail = vmu->serveremail;
-			sendmail(myserveremail, vmu, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, fn, fmt, duration, attach_user_voicemail);
+			sendmail(myserveremail, vmu, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, fn, fmt, duration, attach_user_voicemail, category);
 		}
 
 		if (!ast_strlen_zero(vmu->pager)) {
 			char *myserveremail = serveremail;
 			if (!ast_strlen_zero(vmu->serveremail))
 				myserveremail = vmu->serveremail;
-			sendpage(myserveremail, vmu->pager, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, duration, vmu);
+			sendpage(myserveremail, vmu->pager, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, duration, vmu, category);
 		}
 	} else {
 		ast_log(LOG_ERROR, "Out of memory\n");
@@ -3443,6 +3445,7 @@
 		leave_options.record_gain = record_gain;
 		cmd = leave_voicemail(chan, username, &leave_options);
 	} else {
+
 		/* Forward VoiceMail */
 		RETRIEVE(dir, curmsg);
 		cmd = vm_forwardoptions(chan, sender, dir, curmsg, vmfmts, context, record_gain);
@@ -3487,7 +3490,8 @@
 				/* load the information on the source message so we can send an e-mail like a new message */
 				snprintf(miffile, sizeof(miffile), "%s/msg%04d.txt", dir, curmsg);
 				if ((mif=ast_config_load(miffile))) {
-	
+					const char *category = ast_variable_retrieve(mif, NULL, "category");
+
 					/* set callerid and duration variables */
 					snprintf(callerid, sizeof(callerid), "FWD from: %s from %s", sender->fullname, ast_variable_retrieve(mif, NULL, "callerid"));
 					s = ast_variable_retrieve(mif, NULL, "duration");
@@ -3501,14 +3505,14 @@
 						attach_user_voicemail = ast_test_flag(vmtmp, VM_ATTACH);
 						if (!ast_strlen_zero(vmtmp->serveremail))
 							myserveremail = vmtmp->serveremail;
-						sendmail(myserveremail, vmtmp, todircount, vmtmp->context, vmtmp->mailbox, chan->cid.cid_num, chan->cid.cid_name, fn, tmp, duration, attach_user_voicemail);
+						sendmail(myserveremail, vmtmp, todircount, vmtmp->context, vmtmp->mailbox, chan->cid.cid_num, chan->cid.cid_name, fn, tmp, duration, attach_user_voicemail, category);
 					}
 
 					if (!ast_strlen_zero(vmtmp->pager)) {
 						char *myserveremail = serveremail;
 						if (!ast_strlen_zero(vmtmp->serveremail))
 							myserveremail = vmtmp->serveremail;
-						sendpage(myserveremail, vmtmp->pager, todircount, vmtmp->context, vmtmp->mailbox, chan->cid.cid_num, chan->cid.cid_name, duration, vmtmp);
+						sendpage(myserveremail, vmtmp->pager, todircount, vmtmp->context, vmtmp->mailbox, chan->cid.cid_num, chan->cid.cid_name, duration, vmtmp, category);
 					}
 				  
 					ast_config_destroy(mif); /* or here */
@@ -5737,7 +5741,8 @@
 static char *complete_show_voicemail_users(char *line, char *word, int pos, int state)
 {
 	int which = 0;
-	struct ast_vm_user *vmu = users;
+	int wordlen;
+	struct ast_vm_user *vmu;
 	char *context = "";
 
 	/* 0 - show; 1 - voicemail; 2 - users; 3 - for; 4 - <context> */
@@ -5749,8 +5754,9 @@
 		else
 			return NULL;
 	}
-	while (vmu) {
-		if (!strncasecmp(word, vmu->context, strlen(word))) {
+	wordlen = strlen(word);
+	for (vmu = users; vmu; vmu = vmu->next) {
+		if (!strncasecmp(word, vmu->context, wordlen)) {
 			if (context && strcmp(context, vmu->context)) {
 				if (++which > state) {
 					return strdup(vmu->context);
@@ -5758,7 +5764,6 @@
 				context = vmu->context;
 			}
 		}
-		vmu = vmu->next;
 	}
 	return NULL;
 }

Modified: team/bweschke/bug_5374/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/asterisk.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/asterisk.c (original)
+++ team/bweschke/bug_5374/asterisk.c Fri Dec 30 10:49:07 2005
@@ -1602,12 +1602,13 @@
 			free(mbuf);
 		} else
 			matches = (char **) NULL;
-
-
 	} else {
-
-		nummatches = ast_cli_generatornummatches((char *)lf->buffer,ptr);
+		char **p;
+		int count = 0;
 		matches = ast_cli_completion_matches((char *)lf->buffer,ptr);
+		for (p = matches; p && *p; p++)
+			count++;
+		nummatches = count - 1; /* XXX apparently there is one dup ? */
 	}
 
 	if (matches) {
@@ -1641,7 +1642,7 @@
 				retval = CC_REFRESH;
 			}
 		}
-	free(matches);
+		free(matches);
 	}
 
 	return (char *)(long)retval;

Modified: team/bweschke/bug_5374/channel.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/channel.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/channel.c (original)
+++ team/bweschke/bug_5374/channel.c Fri Dec 30 10:49:07 2005
@@ -94,6 +94,7 @@
  */
 static int shutting_down = 0;
 
+AST_MUTEX_DEFINE_STATIC(uniquelock);
 static int uniqueint = 0;
 
 unsigned long global_fin = 0, global_fout = 0;
@@ -572,7 +573,9 @@
 	tmp->data = NULL;
 	tmp->fin = global_fin;
 	tmp->fout = global_fout;
+	ast_mutex_lock(&uniquelock);
 	snprintf(tmp->uniqueid, sizeof(tmp->uniqueid), "%li.%d", (long) time(NULL), uniqueint++);
+	ast_mutex_unlock(&uniquelock);
 	headp = &tmp->varshead;
 	ast_mutex_init(&tmp->lock);
 	AST_LIST_HEAD_INIT_NOLOCK(headp);

Modified: team/bweschke/bug_5374/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/channels/chan_iax2.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/channels/chan_iax2.c (original)
+++ team/bweschke/bug_5374/channels/chan_iax2.c Fri Dec 30 10:49:07 2005
@@ -1975,13 +1975,14 @@
 	int which = 0;
 	struct iax2_peer *p;
 	char *res = NULL;
+	int wordlen = strlen(word);
 
 	/* 0 - iax2; 1 - show; 2 - peer; 3 - <peername> */
-	if(pos == 3) {
+	if (pos == 3) {
 		ast_mutex_lock(&peerl.lock);
-		for(p = peerl.peers ; p ; p = p->next) {
-			if(!strncasecmp(p->name, word, strlen(word))) {
-				if(++which > state) {
+		for (p = peerl.peers ; p ; p = p->next) {
+			if (!strncasecmp(p->name, word, wordlen)) {
+				if (++which > state) {
 					res = strdup(p->name);
 					break;
 				}

Modified: team/bweschke/bug_5374/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/channels/chan_sip.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/channels/chan_sip.c (original)
+++ team/bweschke/bug_5374/channels/chan_sip.c Fri Dec 30 10:49:07 2005
@@ -4629,13 +4629,10 @@
 	if (p->rpid || p->rpid_from)
 		return;
 
-	if (p->owner && p->owner->cid.cid_num) {
-		clid = strdup(p->owner->cid.cid_num);
-	} 
-
-	if (p->owner && p->owner->cid.cid_name) {
-		clin = strdup(p->owner->cid.cid_name);
-	}
+	if (p->owner && p->owner->cid.cid_num)
+		clid = p->owner->cid.cid_num;
+	if (p->owner && p->owner->cid.cid_name)
+		clin = p->owner->cid.cid_name;
 	if (ast_strlen_zero(clin))
 		clin = clid;
 
@@ -8295,17 +8292,16 @@
 	int which=0;
 	struct sip_pvt *cur;
 	char *c = NULL;
+	int wordlen = strlen(word);
 
 	ast_mutex_lock(&iflock);
-	cur = iflist;
-	while(cur) {
-		if (!strncasecmp(word, cur->callid, strlen(word))) {
+	for (cur = iflist; cur; cur = cur->next) {
+		if (!strncasecmp(word, cur->callid, wordlen)) {
 			if (++which > state) {
 				c = strdup(cur->callid);
 				break;
 			}
 		}
-		cur = cur->next;
 	}
 	ast_mutex_unlock(&iflock);
 	return c;
@@ -8385,22 +8381,21 @@
 
 	if (pos == 2) {
 		int which = 0;
-		char *cat;
+		char *cat = NULL;
+		int wordlen = strlen(word);
 
 		/* do completion for notify type */
 
 		if (!notify_types)
 			return NULL;
 		
-		cat = ast_category_browse(notify_types, NULL);
-		while(cat) {
-			if (!strncasecmp(word, cat, strlen(word))) {
+		while ( (cat = ast_category_browse(notify_types, cat)) ) {
+			if (!strncasecmp(word, cat, wordlen)) {
 				if (++which > state) {
 					c = strdup(cat);
 					break;
 				}
 			}
-			cat = ast_category_browse(notify_types, cat);
 		}
 		return c;
 	}
@@ -8440,9 +8435,8 @@
 		return RESULT_SHOWUSAGE;
 	len = strlen(argv[3]);
 	ast_mutex_lock(&iflock);
-	cur = iflist;
-	while(cur) {
-		if (!strncasecmp(cur->callid, argv[3],len)) {
+	for (cur = iflist; cur; cur = cur->next) {
+		if (!strncasecmp(cur->callid, argv[3], len)) {
 			ast_cli(fd,"\n");
 			if (cur->subscribed != NONE)
 				ast_cli(fd, "  * Subscription (type: %s)\n", subscription_type2str(cur->subscribed));
@@ -8487,7 +8481,6 @@
 			ast_cli(fd, "\n\n");
 			found++;
 		}
-		cur = cur->next;
 	}
 	ast_mutex_unlock(&iflock);
 	if (!found) 
@@ -8510,8 +8503,7 @@
 		ast_cli(fd, "\n***Note: History recording is currently DISABLED.  Use 'sip history' to ENABLE.\n");
 	len = strlen(argv[3]);
 	ast_mutex_lock(&iflock);
-	cur = iflist;
-	while(cur) {
+	for (cur = iflist; cur; cur = cur->next) {
 		if (!strncasecmp(cur->callid, argv[3], len)) {
 			ast_cli(fd,"\n");
 			if (cur->subscribed != NONE)
@@ -8529,7 +8521,6 @@
 				ast_cli(fd, "Call '%s' has no history\n", cur->callid);
 			found++;
 		}
-		cur = cur->next;
 	}
 	ast_mutex_unlock(&iflock);
 	if (!found) 
@@ -8553,11 +8544,9 @@
 	else
 		ast_log(LOG_DEBUG, "  * SIP Call\n");
 	x = 0;
-	hist = dialog->history;
-	while(hist) {
+	for (hist = dialog->history; hist; hist = hist->next) {
 		x++;
 		ast_log(LOG_DEBUG, "  %d. %s\n", x, hist->event);
-		hist = hist->next;
 	}
 	if (!x)
 		ast_log(LOG_DEBUG, "Call '%s' has no history\n", dialog->callid);
@@ -11208,8 +11197,7 @@
 		ast_mutex_lock(&iflock);
 restartsearch:		
 		time(&t);
-		sip = iflist;
-		while(sip) {
+		for (sip = iflist; sip; sip = sip->next) {
 			ast_mutex_lock(&sip->lock);
 			if (sip->rtp && sip->owner && (sip->owner->_state == AST_STATE_UP) && !sip->redirip.sin_addr.s_addr) {
 				if (sip->lastrtptx && sip->rtpkeepalive && t > sip->lastrtptx + sip->rtpkeepalive) {
@@ -11247,7 +11235,6 @@
 				goto restartsearch;
 			}
 			ast_mutex_unlock(&sip->lock);
-			sip = sip->next;
 		}
 		ast_mutex_unlock(&iflock);
 		/* Don't let anybody kill us right away.  Nobody should lock the interface list
@@ -11829,13 +11816,11 @@
 /*! \brief  find_realm_authentication: Find authentication for a specific realm ---*/
 static struct sip_auth *find_realm_authentication(struct sip_auth *authlist, char *realm)
 {
-	struct sip_auth *a = authlist; 	/* First entry in auth list */
-
-	while (a) {
-		if (!strcasecmp(a->realm, realm)){
+	struct sip_auth *a;
+
+	for (a = authlist; a; a = a->next) {
+		if (!strcasecmp(a->realm, realm))
 			break;
-		}
-		a = a->next;
 	}
 	
 	return a;

Modified: team/bweschke/bug_5374/channels/iax2-provision.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/channels/iax2-provision.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/channels/iax2-provision.c (original)
+++ team/bweschke/bug_5374/channels/iax2-provision.c Fri Dec 30 10:49:07 2005
@@ -156,21 +156,20 @@
 {
 	struct iax_template *c;
 	int which=0;
-	char *ret;
+	char *ret = NULL;
+	int wordlen = strlen(word);
+
 	ast_mutex_lock(&provlock);
-	c = templates;
-	while(c) {
-		if (!strncasecmp(word, c->name, strlen(word))) {
-			if (++which > state)
+	for (c = templates; c; c = c->next) {
+		if (!strncasecmp(word, c->name, wordlen)) {
+			if (++which > state) {
+				ret = strdup(c->name);
 				break;
-		}
-		c = c->next;
-	}
-	if (c) {
-		ret = strdup(c->name);
-	} else
-		ret = NULL;
+			}
+		}
+	}
 	ast_mutex_unlock(&provlock);
+	
 	return ret;
 }
 

Modified: team/bweschke/bug_5374/cli.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/cli.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/cli.c (original)
+++ team/bweschke/bug_5374/cli.c Fri Dec 30 10:49:07 2005
@@ -953,6 +953,7 @@
 	{ { "_command", "matchesarray", NULL }, handle_commandmatchesarray, "Returns command matches array", commandmatchesarray_help },
 	{ { "debug", "channel", NULL }, handle_debugchan, "Enable debugging on a channel", debugchan_help, complete_ch_3 },
 	{ { "debug", "level", NULL }, handle_debuglevel, "Set global debug level", debuglevel_help },
+	{ { "group", "show", "channels", NULL }, group_show_channels, "Show active channels with group(s)", group_show_channels_help},
 	{ { "help", NULL }, handle_help, "Display help list, or specific help on a command", help_help },
 	{ { "load", NULL }, handle_load, "Load a dynamic module by name", load_help, complete_fn },
 	{ { "no", "debug", "channel", NULL }, handle_nodebugchan, "Disable debugging on a channel", nodebugchan_help, complete_ch_4 },
@@ -967,7 +968,6 @@
 	{ { "show", "version", NULL }, handle_version, "Display version info", version_help },
 	{ { "soft", "hangup", NULL }, handle_softhangup, "Request a hangup on a given channel", softhangup_help, complete_ch_3 },
 	{ { "unload", NULL }, handle_unload, "Unload a dynamic module by name", unload_help, complete_fn },
-	{ { "group", "show", "channels", NULL }, group_show_channels, "Show active channels with group(s)", group_show_channels_help},
 	{ { NULL }, NULL, NULL, NULL }
 };
 

Modified: team/bweschke/bug_5374/config.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/config.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/config.c (original)
+++ team/bweschke/bug_5374/config.c Fri Dec 30 10:49:07 2005
@@ -811,9 +811,19 @@
 	for (v = ast_variable_browse(config, "settings"); v; v = v->next) {
 		stringp = v->value;
 		driver = strsep(&stringp, ",");
-		database = strsep(&stringp, ",");
+
+		/* check if the database text starts with a double quote */
+		if (*stringp == '"') {
+			stringp++;
+			database = strsep(&stringp, "\"");
+			strsep(&stringp, ",");
+		} else {
+			/* apparently this text has no quotes */
+			database = strsep(&stringp, ",");
+		}
+
 		table = strsep(&stringp, ",");
-			
+
 		if (!strcmp(v->name, extconfig_conf)) {
 			ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf);
 			continue;

Modified: team/bweschke/bug_5374/configs/extconfig.conf.sample
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/configs/extconfig.conf.sample?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/configs/extconfig.conf.sample (original)
+++ team/bweschke/bug_5374/configs/extconfig.conf.sample Fri Dec 30 10:49:07 2005
@@ -40,6 +40,8 @@
 ; the family if the table is not specified
 ;
 ;example => odbc,asterisk,alttable
+;example2 => ldap,"dc=oxymium,dc=net",example2
+;
 ;iaxusers => odbc,asterisk
 ;iaxpeers => odbc,asterisk
 ;sipusers => odbc,asterisk

Modified: team/bweschke/bug_5374/funcs/func_strings.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/funcs/func_strings.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/funcs/func_strings.c (original)
+++ team/bweschke/bug_5374/funcs/func_strings.c Fri Dec 30 10:49:07 2005
@@ -157,6 +157,64 @@
 	.read = builtin_function_regex,
 };
 
+static void builtin_function_array(struct ast_channel *chan, char *cmd, char *data, const char *value)
+{
+	char *varv[100];
+	char *valuev[100];
+	char *var, *value2;
+	int varcount, valuecount, i;
+
+	var = ast_strdupa(data);
+	value2 = ast_strdupa(value);
+	if (!var || !value2) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		return;
+	}
+
+	/* The functions this will generally be used with are SORT and ODBC_*, which
+	 * both return comma-delimited lists.  However, if somebody uses literal lists,
+	 * their commas will be translated to vertical bars by the load, and I don't
+	 * want them to be surprised by the result.  Hence, we prefer commas as the
+	 * delimiter, but we'll fall back to vertical bars if commas aren't found.
+	 */
+	if (strchr(var, ',')) {
+		varcount = ast_app_separate_args(var, ',', varv, 100);
+	} else {
+		varcount = ast_app_separate_args(var, '|', varv, 100);
+	}
+
+	if (strchr(value2, ',')) {
+		valuecount = ast_app_separate_args(value2, ',', valuev, 100);
+	} else {
+		valuecount = ast_app_separate_args(value2, '|', valuev, 100);
+	}
+
+	for (i = 0; i < varcount; i++) {
+		if (i < valuecount) {
+			pbx_builtin_setvar_helper(chan, varv[i], valuev[i]);
+		} else {
+			/* We could unset the variable, by passing a NULL, but due to
+			 * pushvar semantics, that could create some undesired behavior. */
+			pbx_builtin_setvar_helper(chan, varv[i], "");
+		}
+	}
+}
+
+#ifndef BUILTIN_FUNC
+static
+#endif
+struct ast_custom_function array_function = {
+	.name = "ARRAY",
+	.synopsis = "Allows setting multiple variables at once",
+	.syntax = "ARRAY(var1[,var2[...][,varN]])",
+	.write = builtin_function_array,
+	.desc =
+"The comma-separated list passed as a value to which the function is set\n"
+"will be interpreted as a set of values to which the comma-separated list\n"
+"of variable names in the argument should be set.\n"
+"Hence, Set(ARRAY(var1,var2)=1,2) will set var1 to 1 and var2 to 2\n",
+};
+
 static char *builtin_function_len(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) 
 {
 	int length = 0;

Modified: team/bweschke/bug_5374/include/asterisk/logger.h
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/include/asterisk/logger.h?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/include/asterisk/logger.h (original)
+++ team/bweschke/bug_5374/include/asterisk/logger.h Fri Dec 30 10:49:07 2005
@@ -60,6 +60,8 @@
  */
 extern void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
 	__attribute__ ((format (printf, 5, 6)));
+
+extern void ast_backtrace(void);
 
 extern void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...)
 	__attribute__ ((format (printf, 5, 6)));

Modified: team/bweschke/bug_5374/logger.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/logger.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/logger.c (original)
+++ team/bweschke/bug_5374/logger.c Fri Dec 30 10:49:07 2005
@@ -32,6 +32,9 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <sys/stat.h>
+#ifdef STACK_BACKTRACES
+#include <execinfo.h>
+#endif
 
 #define SYSLOG_NAMES /* so we can map syslog facilities names to their numeric values,
 		        from <syslog.h> which is included by logger.h */
@@ -816,6 +819,39 @@
 	}
 }
 
+void ast_backtrace(void)
+{
+#ifdef STACK_BACKTRACES
+	int count=0, i=0;
+	void **addresses;
+	char **strings;
+
+	addresses = calloc(levels, sizeof(void *));
+	if (addresses) {
+		count = backtrace(addresses, 20);
+		strings = backtrace_symbols(addresses, count);
+		if (strings) {
+			ast_log(LOG_WARNING, "Got %d backtrace record%c\n", count, count != 1 ? 's' : ' ');
+			for (i=0; i < count ; i++) {
+				ast_log(LOG_WARNING, "#%d: [%08X] %s\n", i, (unsigned int)addresses[i], strings[i]);
+			}
+			free(strings);
+		} else {
+			ast_log(LOG_WARNING, "Could not allocate memory for backtrace\n");
+		}
+		free(addresses);
+	} else {
+		ast_log(LOG_WARNING, "Could not allocate memory for backtrace\n");
+	}
+#else
+#ifdef Linux
+	ast_log(LOG_WARNING, "Must compile with 'make dont-optimize' for stack backtraces\n");
+#else
+	ast_log(LOG_WARNING, "Inline stack backtraces are only available on the Linux platform.\n");
+#endif
+#endif
+}
+
 void ast_verbose(const char *fmt, ...)
 {
 	static char stuff[4096];

Modified: team/bweschke/bug_5374/manager.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/manager.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/manager.c (original)
+++ team/bweschke/bug_5374/manager.c Fri Dec 30 10:49:07 2005
@@ -722,35 +722,32 @@
 
 static int action_getvar(struct mansession *s, struct message *m)
 {
-        struct ast_channel *c = NULL;
-        char *name = astman_get_header(m, "Channel");
-        char *varname = astman_get_header(m, "Variable");
+	struct ast_channel *c = NULL;
+	char *name = astman_get_header(m, "Channel");
+	char *varname = astman_get_header(m, "Variable");
 	char *id = astman_get_header(m,"ActionID");
-	const char *varval;
-	char *varval2=NULL;
-
-	if (!strlen(varname)) {
+	char *varval;
+	char workspace[1024];
+
+	if (ast_strlen_zero(varname)) {
 		astman_send_error(s, m, "No variable specified");
 		return 0;
 	}
 
-	if (strlen(name)) {
+	if (!ast_strlen_zero(name)) {
 		c = ast_get_channel_by_name_locked(name);
 		if (!c) {
 			astman_send_error(s, m, "No such channel");
 			return 0;
 		}
 	}
-	
-	varval=pbx_builtin_getvar_helper(c,varname);
-	if (varval)
-		varval2 = ast_strdupa(varval);
-	if (!varval2)
-		varval2 = "";
+
+	pbx_retrieve_variable(c, varname, &varval, workspace, sizeof(workspace), NULL);
+
 	if (c)
 		ast_mutex_unlock(&c->lock);
 	ast_cli(s->fd, "Response: Success\r\n"
-		"Variable: %s\r\nValue: %s\r\n" ,varname,varval2);
+		"Variable: %s\r\nValue: %s\r\n", varname, varval);
 	if (!ast_strlen_zero(id))
 		ast_cli(s->fd, "ActionID: %s\r\n",id);
 	ast_cli(s->fd, "\r\n");
@@ -874,8 +871,10 @@
 		return 0;
 	}
 	if (!ast_strlen_zero(priority) && (sscanf(priority, "%d", &pi) != 1)) {
-		astman_send_error(s, m, "Invalid priority\n");
-		return 0;
+		if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
+			astman_send_error(s, m, "Invalid priority\n");
+			return 0;
+		}
 	}
 	chan = ast_get_channel_by_name_locked(name);
 	if (!chan) {
@@ -1020,8 +1019,10 @@
 		return 0;
 	}
 	if (!ast_strlen_zero(priority) && (sscanf(priority, "%d", &pi) != 1)) {
-		astman_send_error(s, m, "Invalid priority\n");
-		return 0;
+		if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
+			astman_send_error(s, m, "Invalid priority\n");
+			return 0;
+		}
 	}
 	if (!ast_strlen_zero(timeout) && (sscanf(timeout, "%d", &to) != 1)) {
 		astman_send_error(s, m, "Invalid timeout\n");

Modified: team/bweschke/bug_5374/pbx.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/pbx.c?rev=7679&r1=7678&r2=7679&view=diff
==============================================================================
--- team/bweschke/bug_5374/pbx.c (original)
+++ team/bweschke/bug_5374/pbx.c Fri Dec 30 10:49:07 2005
@@ -1196,10 +1196,9 @@
 static char *complete_show_function(char *line, char *word, int pos, int state)
 {
 	struct ast_custom_function *acf;
+	char *ret = NULL;
 	int which = 0;
-	int wordlen;
-
-	wordlen = strlen(word);
+	int wordlen = strlen(word);
 
 	/* try to lock functions list ... */
 	if (ast_mutex_lock(&acflock)) {
@@ -1210,15 +1209,15 @@
 	for (acf = acf_root; acf; acf = acf->next) {
 		if (!strncasecmp(word, acf->name, wordlen)) {
 			if (++which > state) {
-				char *ret = strdup(acf->name);
-				ast_mutex_unlock(&acflock);
-				return ret;
+				ret = strdup(acf->name);
+				break;
 			}
 		}
 	}
 
 	ast_mutex_unlock(&acflock);
-	return NULL; 
+
+	return ret; 
 }
 
 struct ast_custom_function* ast_custom_function_find(const char *name) 
@@ -2957,11 +2956,12 @@
  * application at one time. You can type 'show application Dial Echo' and
  * you will see informations about these two applications ...
  */
-static char *complete_show_application(char *line, char *word,
-	int pos, int state)
+static char *complete_show_application(char *line, char *word, int pos, int state)
 {
 	struct ast_app *a;
+	char *ret = NULL;
 	int which = 0;
+	int wordlen = strlen(word);
 
 	/* try to lock applications list ... */
 	if (ast_mutex_lock(&applock)) {
@@ -2972,19 +2972,18 @@
 	/* ... walk all applications ... */
 	for (a = apps; a; a = a->next) {
 		/* ... check if word matches this application ... */
-		if (!strncasecmp(word, a->name, strlen(word))) {
+		if (!strncasecmp(word, a->name, wordlen)) {
 			/* ... if this is right app serve it ... */
 			if (++which > state) {
-				char *ret = strdup(a->name);
-				ast_mutex_unlock(&applock);
-				return ret;
+				ret = strdup(a->name);
+				break;
 			}
 		}
 	}
 
-	/* no application match */
 	ast_mutex_unlock(&applock);
-	return NULL; 
+
+	return ret; 
 }
 
 static int handle_show_application(int fd, int argc, char *argv[])
@@ -3198,6 +3197,8 @@
 
 static char *complete_show_applications(char *line, char *word, int pos, int state)
 {
+	int wordlen = strlen(word);
+
 	if (pos == 2) {
 		if (ast_strlen_zero(word)) {
 			switch (state) {
@@ -3208,13 +3209,13 @@
 			default:
 				return NULL;
 			}
-		} else if (! strncasecmp(word, "like", strlen(word))) {
+		} else if (! strncasecmp(word, "like", wordlen)) {
 			if (state == 0) {
 				return strdup("like");
 			} else {
 				return NULL;
 			}
-		} else if (! strncasecmp(word, "describing", strlen(word))) {
+		} else if (! strncasecmp(word, "describing", wordlen)) {
 			if (state == 0) {
 				return strdup("describing");
 			} else {



More information about the asterisk-commits mailing list