[asterisk-commits] branch murf/bug_6264-1.2 r8694 - in /team/murf/bug_6264-1.2: ./ apps/ channel...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Jan 25 14:38:59 MST 2006


Author: murf
Date: Wed Jan 25 15:38:50 2006
New Revision: 8694

URL: http://svn.digium.com/view/asterisk?rev=8694&view=rev
Log:
Merged revisions 8232,8242,8276,8281,8320,8347,8394,8412,8414,8418 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r8232 | russell | 2006-01-18 21:17:45 -0700 (Wed, 18 Jan 2006) | 3 lines

fix a seg fault due to assuming that space gets allocatted on the stack in the
same order that we declare the variables (issue #6290)

........
r8242 | russell | 2006-01-18 21:56:48 -0700 (Wed, 18 Jan 2006) | 3 lines

fix Message-Account header to use the ip address if the fromdomain 
isn't set (issue #6278)

........
r8276 | tilghman | 2006-01-19 12:14:37 -0700 (Thu, 19 Jan 2006) | 2 lines

Bug 6072 - Memory leaks in the expression parser

........
r8281 | oej | 2006-01-19 12:40:28 -0700 (Thu, 19 Jan 2006) | 2 lines

Enable "musicclass" setting for sip peers as per the config sample.

........
r8320 | mogorman | 2006-01-19 18:00:46 -0700 (Thu, 19 Jan 2006) | 3 lines

solved problem with delayreject and iax trunking
bug 4291

........
r8347 | russell | 2006-01-20 11:34:42 -0700 (Fri, 20 Jan 2006) | 2 lines

fix invalid value of prev_q (issue #6302)

........
r8394 | tilghman | 2006-01-21 11:29:39 -0700 (Sat, 21 Jan 2006) | 2 lines

Bug 5936 - AddQueueMember fails on realtime queue, if queue not yet loaded

........
r8412 | russell | 2006-01-21 16:17:06 -0700 (Sat, 21 Jan 2006) | 2 lines

prevent the possibility of writing outside of the available workspace (issue #6271)

........
r8414 | russell | 2006-01-21 16:43:14 -0700 (Sat, 21 Jan 2006) | 2 lines

temporarily revert substring fix pending the result of the discussion in issue #6271

........
r8418 | russell | 2006-01-21 19:05:41 -0700 (Sat, 21 Jan 2006) | 3 lines

add a modified fix to prevent writing outside of the provided workspace when 
calculating a substring (issue #6271)

........

Modified:
    team/murf/bug_6264-1.2/   (props changed)
    team/murf/bug_6264-1.2/apps/app_dial.c
    team/murf/bug_6264-1.2/apps/app_queue.c
    team/murf/bug_6264-1.2/asterisk.c
    team/murf/bug_6264-1.2/channel.c
    team/murf/bug_6264-1.2/channels/chan_features.c
    team/murf/bug_6264-1.2/channels/chan_sip.c
    team/murf/bug_6264-1.2/channels/chan_zap.c
    team/murf/bug_6264-1.2/pbx.c
    team/murf/bug_6264-1.2/utils/astman.c

Propchange: team/murf/bug_6264-1.2/
------------------------------------------------------------------------------
    automerge = 1

Propchange: team/murf/bug_6264-1.2/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed Jan 25 15:38:50 2006
@@ -1,1 +1,1 @@
-/branches/1.2:1-8417
+/branches/1.2:1-8693

Modified: team/murf/bug_6264-1.2/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_6264-1.2/apps/app_dial.c?rev=8694&r1=8693&r2=8694&view=diff
==============================================================================
--- team/murf/bug_6264-1.2/apps/app_dial.c (original)
+++ team/murf/bug_6264-1.2/apps/app_dial.c Wed Jan 25 15:38:50 2006
@@ -648,6 +648,7 @@
 					ast_hangup(o->chan);
 					o->chan = NULL;
 					ast_clear_flag(o, DIAL_STILLGOING);
+					HANDLE_CAUSE(in->hangupcause, in);
 				}
 			}
 			o = o->next;

Modified: team/murf/bug_6264-1.2/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_6264-1.2/apps/app_queue.c?rev=8694&r1=8693&r2=8694&view=diff
==============================================================================
--- team/murf/bug_6264-1.2/apps/app_queue.c (original)
+++ team/murf/bug_6264-1.2/apps/app_queue.c Wed Jan 25 15:38:50 2006
@@ -755,6 +755,48 @@
 	}
 }
 
+static void free_members(struct ast_call_queue *q, int all)
+{
+	/* Free non-dynamic members */
+	struct member *curm, *next, *prev = NULL;
+
+	for (curm = q->members; curm; curm = next) {
+		next = curm->next;
+		if (all || !curm->dynamic) {
+			if (prev)
+				prev->next = next;
+			else
+				q->members = next;
+			free(curm);
+		} else 
+			prev = curm;
+	}
+}
+
+static void destroy_queue(struct ast_call_queue *q)
+{
+	free_members(q, 1);
+	ast_mutex_destroy(&q->lock);
+	free(q);
+}
+
+static void remove_queue(struct ast_call_queue *q)
+{
+	struct ast_call_queue *cur, *prev = NULL;
+
+	ast_mutex_lock(&qlock);
+	for (cur = queues; cur; cur = cur->next) {
+		if (cur == q) {
+			if (prev)
+				prev->next = cur->next;
+			else
+				queues = cur->next;
+		} else {
+			prev = cur;
+		}
+	}
+	ast_mutex_unlock(&qlock);
+}
 
 /*!\brief Reload a single queue via realtime.
    \return Return the queue, or NULL if it doesn't exist.
@@ -811,7 +853,7 @@
 					prev_q->next = q->next;
 				}
 				ast_mutex_unlock(&q->lock);
-				free(q);
+				destroy_queue(q);
 			} else
 				ast_mutex_unlock(&q->lock);
 		}
@@ -997,48 +1039,6 @@
 	return res;
 }
 
-static void free_members(struct ast_call_queue *q, int all)
-{
-	/* Free non-dynamic members */
-	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;
-	}
-}
-
-static void destroy_queue(struct ast_call_queue *q)
-{
-	struct ast_call_queue *cur, *prev = NULL;
-
-	ast_mutex_lock(&qlock);
-	for (cur = queues; cur; cur = cur->next) {
-		if (cur == q) {
-			if (prev)
-				prev->next = cur->next;
-			else
-				queues = cur->next;
-		} else {
-			prev = cur;
-		}
-	}
-	ast_mutex_unlock(&qlock);
-	free_members(q, 1);
-        ast_mutex_destroy(&q->lock);
-	free(q);
-}
-
 static int play_file(struct ast_channel *chan, char *filename)
 {
 	int res;
@@ -1246,6 +1246,7 @@
 	ast_mutex_unlock(&q->lock);
 	if (q->dead && !q->count) {	
 		/* It's dead and nobody is in it, so kill it */
+		remove_queue(q);
 		destroy_queue(q);
 	}
 }
@@ -3266,7 +3267,7 @@
 			else
 				queues = q->next;
 			if (!q->count) {
-				free(q);
+				destroy_queue(q);
 			} else
 				ast_log(LOG_WARNING, "XXX Leaking a little memory :( XXX\n");
 		} else {

Modified: team/murf/bug_6264-1.2/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_6264-1.2/asterisk.c?rev=8694&r1=8693&r2=8694&view=diff
==============================================================================
--- team/murf/bug_6264-1.2/asterisk.c (original)
+++ team/murf/bug_6264-1.2/asterisk.c Wed Jan 25 15:38:50 2006
@@ -18,6 +18,7 @@
 
 
 /* Doxygenified Copyright Header */
+
 /*!
  * \mainpage Asterisk -- An Open Source Telephony Toolkit
  *

Modified: team/murf/bug_6264-1.2/channel.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_6264-1.2/channel.c?rev=8694&r1=8693&r2=8694&view=diff
==============================================================================
--- team/murf/bug_6264-1.2/channel.c (original)
+++ team/murf/bug_6264-1.2/channel.c Wed Jan 25 15:38:50 2006
@@ -2005,10 +2005,12 @@
 {
 	int res = -1;
 
+	ast_mutex_lock(&chan->lock);
 	/* Stop if we're a zombie or need a soft hangup */
-	if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 
+	if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
+		ast_mutex_unlock(&chan->lock);
 		return -1;
-	ast_mutex_lock(&chan->lock);
+	}
 	if (chan->tech->indicate)
 		res = chan->tech->indicate(chan, condition);
 	ast_mutex_unlock(&chan->lock);
@@ -3233,11 +3235,14 @@
 			res = AST_BRIDGE_RETRY;
 			break;
 		}
-		to = ast_tvdiff_ms(bridge_end, ast_tvnow());
-		if (to <= 0) {
-			res = AST_BRIDGE_RETRY;
-			break;
-		}
+		if (bridge_end.tv_sec) {
+			to = ast_tvdiff_ms(bridge_end, ast_tvnow());
+			if (to <= 0) {
+				res = AST_BRIDGE_RETRY;
+				break;
+			}
+		} else
+			to = -1;
 		who = ast_waitfor_n(cs, 2, &to);
 		if (!who) {
 			ast_log(LOG_DEBUG, "Nobody there, continuing...\n"); 
@@ -3830,7 +3835,7 @@
 		}
 
 		tocopy = (f->samples > samples) ? samples : f->samples;
-		bytestocopy = ast_codec_get_len(queue->format, samples);
+		bytestocopy = ast_codec_get_len(queue->format, tocopy);
 		memcpy(buf, f->data, bytestocopy);
 		samples -= tocopy;
 		buf += tocopy;

Modified: team/murf/bug_6264-1.2/channels/chan_features.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_6264-1.2/channels/chan_features.c?rev=8694&r1=8693&r2=8694&view=diff
==============================================================================
--- team/murf/bug_6264-1.2/channels/chan_features.c (original)
+++ team/murf/bug_6264-1.2/channels/chan_features.c Wed Jan 25 15:38:50 2006
@@ -568,17 +568,17 @@
 
 int unload_module()
 {
-	struct feature_pvt *p;
+	struct feature_pvt *p, *prev;
 	/* First, take us out of the channel loop */
 	ast_cli_unregister(&cli_show_features);
 	ast_channel_unregister(&features_tech);
 	if (!ast_mutex_lock(&featurelock)) {
 		/* Hangup all interfaces if they have an owner */
-		p = features;
-		while(p) {
+		for (p = features; p; p = p->next) {
+			prev = p;
 			if (p->owner)
 				ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
-			p = p->next;
+			free(prev);
 		}
 		features = NULL;
 		ast_mutex_unlock(&featurelock);

Modified: team/murf/bug_6264-1.2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_6264-1.2/channels/chan_sip.c?rev=8694&r1=8693&r2=8694&view=diff
==============================================================================
--- team/murf/bug_6264-1.2/channels/chan_sip.c (original)
+++ team/murf/bug_6264-1.2/channels/chan_sip.c Wed Jan 25 15:38:50 2006
@@ -560,6 +560,8 @@
 #define SIP_CALL_LIMIT		(1 << 29)
 /* Remote Party-ID Support */
 #define SIP_SENDRPID		(1 << 30)
+/* Did this connection increment the counter of in-use calls? */
+#define SIP_INC_COUNT (1 << 31)
 
 #define SIP_FLAGS_TO_COPY \
 	(SIP_PROMISCREDIR | SIP_TRUSTRPID | SIP_SENDRPID | SIP_DTMF | SIP_REINVITE | \
@@ -1588,16 +1590,15 @@
 {
 	char port[10];
 	char ipaddr[20];
-	char regseconds[20] = "0";
+	char regseconds[20];
+	time_t nowtime;
 	
-	if (expirey) {	/* Registration */
-		time_t nowtime;
-		time(&nowtime);
-		nowtime += expirey;
-		snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime);	/* Expiration time */
-		ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr);
-		snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port));
-	}
+	time(&nowtime);
+	nowtime += expirey;
+	snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime);	/* Expiration time */
+	ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr);
+	snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port));
+	
 	if (fullcontact)
 		ast_update_realtime("sippeers", "name", peername, "ipaddr", ipaddr, "port", port, "regseconds", regseconds, "username", username, "fullcontact", fullcontact, NULL);
 	else
@@ -2224,7 +2225,8 @@
 		/* incoming and outgoing affects the inUse counter */
 		case DEC_CALL_LIMIT:
 			if ( *inuse > 0 ) {
-				(*inuse)--;
+			         if (ast_test_flag(fup,SIP_INC_COUNT))
+				         (*inuse)--;
 			} else {
 				*inuse = 0;
 			}
@@ -2244,6 +2246,7 @@
 				}
 			}
 			(*inuse)++;
+	                ast_set_flag(fup,SIP_INC_COUNT);
 			if (option_debug > 1 || sipdebug) {
 				ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *inuse, *call_limit);
 			}
@@ -10615,7 +10618,8 @@
 			}
 		} else {
 			ast_log(LOG_WARNING, "Invalid transfer information from '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr));
-			ast_queue_hangup(p->owner);
+			if (p->owner)
+				ast_queue_hangup(p->owner);
 		}
 	} else if (p->owner)
 		ast_queue_hangup(p->owner);
@@ -10940,8 +10944,10 @@
 		ast_log(LOG_DEBUG, "**** Received %s (%d) - Command in SIP %s\n", sip_methods[p->method].text, sip_methods[p->method].id, cmd); 
 
 	if (p->icseq && (p->icseq > seqno)) {
-		ast_log(LOG_DEBUG, "Ignoring too old SIP packet packet %d (expecting >= %d)\n", seqno, p->icseq);
-		transmit_response(p, "503 Server error", req);	/* We must respond according to RFC 3261 sec 12.2 */
+		if (option_debug)
+			ast_log(LOG_DEBUG, "Ignoring too old SIP packet packet %d (expecting >= %d)\n", seqno, p->icseq);
+		if (req->method != SIP_ACK)
+			transmit_response(p, "503 Server error", req);	/* We must respond according to RFC 3261 sec 12.2 */
 		return -1;
 	} else if (p->icseq && (p->icseq == seqno) && req->method != SIP_ACK &&(p->method != SIP_CANCEL|| ast_test_flag(p, SIP_ALREADYGONE))) {
 		/* ignore means "don't do anything with it" but still have to 
@@ -12796,14 +12802,11 @@
 /*! \brief  sip_addheader: Add a SIP header ---*/
 static int sip_addheader(struct ast_channel *chan, void *data)
 {
-	int arglen;
 	int no = 0;
 	int ok = 0;
-	char *content = (char *) NULL;
 	char varbuf[128];
 	
-	arglen = strlen(data);
-	if (!arglen) {
+	if (ast_strlen_zero((char *)data)) {
 		ast_log(LOG_WARNING, "This application requires the argument: Header\n");
 		return 0;
 	}
@@ -12812,14 +12815,12 @@
 	/* Check for headers */
 	while (!ok && no <= 50) {
 		no++;
-		snprintf(varbuf, sizeof(varbuf), "_SIPADDHEADER%.2d", no);
-		content = pbx_builtin_getvar_helper(chan, varbuf);
-
-		if (!content)
+		snprintf(varbuf, sizeof(varbuf), "_SIPADDHEADER%02d", no);
+		if (ast_strlen_zero(pbx_builtin_getvar_helper(chan, varbuf + 1)))
 			ok = 1;
 	}
 	if (ok) {
-		pbx_builtin_setvar_helper (chan, varbuf, data);
+		pbx_builtin_setvar_helper (chan, varbuf, (char *)data);
 		if (sipdebug)
 			ast_log(LOG_DEBUG,"SIP Header added \"%s\" as %s\n", (char *) data, varbuf);
 	} else {

Modified: team/murf/bug_6264-1.2/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_6264-1.2/channels/chan_zap.c?rev=8694&r1=8693&r2=8694&view=diff
==============================================================================
--- team/murf/bug_6264-1.2/channels/chan_zap.c (original)
+++ team/murf/bug_6264-1.2/channels/chan_zap.c Wed Jan 25 15:38:50 2006
@@ -4200,6 +4200,10 @@
                                      (ast->_state == AST_STATE_RINGING))) {
                                         ast_log(LOG_DEBUG, "Answering on polarity switch!\n");
                                         ast_setstate(p->owner, AST_STATE_UP);
+					if(p->hanguponpolarityswitch) {
+						gettimeofday(&p->polaritydelaytv, NULL);
+					}
+					break;
                                 } else
                                         ast_log(LOG_DEBUG, "Ignore switch to REVERSED Polarity on channel %d, state %d\n", p->channel, ast->_state);
 			} 

Modified: team/murf/bug_6264-1.2/pbx.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_6264-1.2/pbx.c?rev=8694&r1=8693&r2=8694&view=diff
==============================================================================
--- team/murf/bug_6264-1.2/pbx.c (original)
+++ team/murf/bug_6264-1.2/pbx.c Wed Jan 25 15:38:50 2006
@@ -927,40 +927,38 @@
 	}
 }
 
-static char *substring(char *value, int offset, int length, char *workspace, size_t workspace_len)
+/*! \brief takes a substring. It is ok to call with value == workspace.
+ *
+ * offset < 0 means start from the end of the string and set the beginning
+ *   to be that many characters back.
+ * length is the length of the substring, -1 means unlimited
+ * (we take any negative value).
+ * Always return a copy in workspace.
+ */
+static char *substring(const char *value, int offset, int length, char *workspace, size_t workspace_len)
 {
 	char *ret = workspace;
-
-	/* No need to do anything */
-	if (offset == 0 && length==-1) {
-		return value;
-	}
-
-	ast_copy_string(workspace, value, workspace_len);
-
-	if (abs(offset) > strlen(ret)) {	/* Offset beyond string */
-		if (offset >= 0) 
-			offset = strlen(ret);
-		else 
-			offset =- strlen(ret);	
-	}
-
-	/* Detect too-long length */
-	if ((offset < 0 && length > -offset) || (offset >= 0 && offset+length > strlen(ret))) {
-		if (offset >= 0) 
-			length = strlen(ret)-offset;
-		else 
-			length = strlen(ret)+offset;
-	}
-
-	/* Bounce up to the right offset */
-	if (offset >= 0)
-		ret += offset;
-	else
-		ret += strlen(ret)+offset;
-
-	/* Chop off at the requisite length */
-	if (length >= 0)
+	int lr;	/* length of the input string after the copy */
+
+	ast_copy_string(workspace, value, workspace_len); /* always make a copy */
+
+	if (offset == 0 && length < 0)	/* take the whole string */
+		return ret;
+
+	lr = strlen(ret); /* compute length after copy, so we never go out of the workspace */
+
+	if (offset < 0)	{	/* translate negative offset into positive ones */
+		offset = lr + offset;
+		if (offset < 0) /* If the negative offset was greater than the length of the string, just start at the beginning */
+			offset = 0;
+	}
+
+	/* too large offset result in empty string so we know what to return */
+	if (offset >= lr)
+		return ret + lr;	/* the final '\0' */
+
+	ret += offset;		/* move to the start position */
+	if (length >= 0 && length < lr - offset)	/* truncate if necessary */
 		ret[length] = '\0';
 
 	return ret;

Modified: team/murf/bug_6264-1.2/utils/astman.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_6264-1.2/utils/astman.c?rev=8694&r1=8693&r2=8694&view=diff
==============================================================================
--- team/murf/bug_6264-1.2/utils/astman.c (original)
+++ team/murf/bug_6264-1.2/utils/astman.c Wed Jan 25 15:38:50 2006
@@ -111,6 +111,7 @@
 				prev->next = chan->next;
 			else
 				chans = chan->next;
+			free(chan);
 			return;
 		}
 		prev = chan;



More information about the asterisk-commits mailing list