[asterisk-commits] sruffell: branch sruffell/asterisk-1.4-transcoder r166344 - in /team/sruffell...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 22 11:46:57 CST 2008


Author: sruffell
Date: Mon Dec 22 11:46:56 2008
New Revision: 166344

URL: http://svn.digium.com/view/asterisk?view=rev&rev=166344
Log:
Merged revisions 165991,166093,166157,166262,166297 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r165991 | jpeeler | 2008-12-19 11:48:00 -0800 (Fri, 19 Dec 2008) | 15 lines

(closes issue #13480)
Reported by: tzafrir

Replace a bunch of if defined checks for Zaptel/DAHDI through several new defines in dahdi_compat.h. This removes a lot of code duplication. Example from bug:

#ifdef HAVE_ZAPTEL
  fd = open("/dev/zap/pseudo", O_RDWR);
#else
  fd = open("/dev/dahdi/pseudo", O_RDWR);
#endif

is replaced with:
  fd = open(DAHDI_FILE_PSEUDO, O_RDRW);


........
r166093 | murf | 2008-12-19 14:30:32 -0800 (Fri, 19 Dec 2008) | 133 lines

This merges the masqpark branch into 1.4

These changes eliminate the need for (and use of)
the KEEPALIVE return code in res_features.c;
There are other places that use this result code
for similar purposes at a higher level, these appear
to be left alone in 1.4, but attacked in trunk.

The reason these changes are being made in 1.4, is
that parking ends a channel's life, in some situations,
and the code in the bridge (and some other places),
was not checking the result code properly, and dereferencing
the channel pointer, which could lead to memory corruption
and crashes.

Calling the masq_park function eliminates this danger 
in higher levels.

A series of previous commits have replaced some parking calls
with masq_park, but this patch puts them ALL to rest,
(except one, purposely left alone because a masquerade
is done anyway), and gets rid of the code that tests
the KEEPALIVE result, and the NOHANGUP_PEER result codes.

While bug 13820 inspired this work, this patch does
not solve all the problems mentioned there.

I have tested this patch (again) to make sure I have
not introduced regressions. 

Crashes that occurred when a parked party hung up
while the parking party was listening to the numbers
of the parking stall being assigned, is eliminated.

These are the cases where parking code may be activated:

1. Feature one touch (eg. *3)
2. Feature blind xfer to parking lot (eg ##700)
3. Run Park() app from dialplan (eg sip xfer to 700)
   (eg. dahdi hookflash xfer to 700)
4. Run Park via manager.

The interesting testing cases for parking are:
I. A calls B, A parks B
    a. B hangs up while A is getting the numbers announced.
    b. B hangs up after A gets the announcement, but 
       before the parking time expires
    c. B waits, time expires, A is redialed,
       A answers, B and A are connected, after
       which, B hangs up.
    d. C picks up B while still in parking lot.

II. A calls B, B parks A
    a. A hangs up while B is getting the numbers announced.
    b. A hangs up after B gets the announcement, but 
       before the parking time expires
    c. A waits, time expires, B is redialed,
       B answers, A and B are connected, after
       which, A hangs up.
    d. C picks up A while still in parking lot.

Testing this throroughly involves acting all the permutations
of I and II, in situations 1,2,3, and 4.

Since I added a few more changes (ALL references to KEEPALIVE in the bridge
code eliimated (I missed one earlier), I retested
most of the above cases, and no crashes.

H-extension weirdness.

Current h-extension execution is not completely
correct for several of the cases.

For the case where A calls B, and A parks B, the
'h' exten is run on A's channel as soon as the park
is accomplished. This is expected behavior.

But when A calls B, and B parks A, this will be
current behavior:

After B parks A, B is hung up by the system, and
the 'h' (hangup) exten gets run, but the channel
mentioned will be a derivative of A's...

Thus, if A is DAHDI/1, and B is DAHDI/2,
the h-extension will be run on channel
Parked/DAHDI/1-1<ZOMBIE>, and the 
start/answer/end info will be those 
relating to Channel A.

And, in the case where A is reconnected to
B after the park time expires, when both parties
hang up after the joyful reunion, no h-exten
will be run at all.

In the case where C picks up A from the 
parking lot, when either A or C hang up,
the h-exten will be run for the C channel.

CDR's are a separate issue, and not addressed
here.

As to WHY this strange behavior occurs, 
the answer lies in the procedure followed
to accomplish handing over the channel
to the parking manager thread. This procedure
is called masquerading. In the process,
a duplicate copy of the channel is created,
and most of the active data is given to the
new copy. The original channel gets its name
changed to XXX<ZOMBIE> and keeps the PBX
information for the sake of the original
thread (preserving its role as a call 
originator, if it had this role to begin
with), while the new channel is without
this info and becomes a call target (a
"peer").

In this case, the parking lot manager
thread is handed the new (masqueraded)
channel. It will not run an h-exten
on the channel if it hangs up while
in the parking lot. The h exten will
be run on the original channel instead,
in the original thread, after the bridge
completes.

See bug 13820 for our intentions as
to how to clean up the h exten behavior.

Review: http://reviewboard.digium.com/r/29/


........
r166157 | mmichelson | 2008-12-19 15:34:57 -0800 (Fri, 19 Dec 2008) | 9 lines

Backport of AUDIOHOOK_INHERIT for Asterisk 1.4

(closes issue #13538)
Reported by: mbit
Patches:
      13538.patch uploaded by putnopvut (license 60)
Tested by: putnopvut


........
r166262 | russell | 2008-12-22 06:45:27 -0800 (Mon, 22 Dec 2008) | 7 lines

Re-work ref count handling of MoH classes using astobj2 to resolve crashes.

(closes issue #13566)
Reported by: igorcarneiro
Tested by: russell
Review: http://reviewboard.digium.com/r/106/

........
r166297 | russell | 2008-12-22 09:22:56 -0800 (Mon, 22 Dec 2008) | 2 lines

Fix up timeout handling in ast_carefulwrite().

........

Modified:
    team/sruffell/asterisk-1.4-transcoder/   (props changed)
    team/sruffell/asterisk-1.4-transcoder/CHANGES
    team/sruffell/asterisk-1.4-transcoder/apps/app_dahdibarge.c
    team/sruffell/asterisk-1.4-transcoder/apps/app_dahdiscan.c
    team/sruffell/asterisk-1.4-transcoder/apps/app_dial.c
    team/sruffell/asterisk-1.4-transcoder/apps/app_meetme.c
    team/sruffell/asterisk-1.4-transcoder/apps/app_queue.c
    team/sruffell/asterisk-1.4-transcoder/channels/chan_dahdi.c
    team/sruffell/asterisk-1.4-transcoder/channels/chan_iax2.c
    team/sruffell/asterisk-1.4-transcoder/channels/chan_sip.c
    team/sruffell/asterisk-1.4-transcoder/codecs/codec_dahdi.c
    team/sruffell/asterisk-1.4-transcoder/include/asterisk/audiohook.h
    team/sruffell/asterisk-1.4-transcoder/include/asterisk/dahdi_compat.h
    team/sruffell/asterisk-1.4-transcoder/include/asterisk/pbx.h
    team/sruffell/asterisk-1.4-transcoder/include/asterisk/strings.h
    team/sruffell/asterisk-1.4-transcoder/main/asterisk.c
    team/sruffell/asterisk-1.4-transcoder/main/audiohook.c
    team/sruffell/asterisk-1.4-transcoder/main/channel.c
    team/sruffell/asterisk-1.4-transcoder/main/utils.c
    team/sruffell/asterisk-1.4-transcoder/res/res_features.c
    team/sruffell/asterisk-1.4-transcoder/res/res_musiconhold.c

Propchange: team/sruffell/asterisk-1.4-transcoder/
------------------------------------------------------------------------------
    automerge = yes

Propchange: team/sruffell/asterisk-1.4-transcoder/
------------------------------------------------------------------------------
    automerge-mail = sruffell at digium.com

Propchange: team/sruffell/asterisk-1.4-transcoder/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Dec 22 11:46:56 2008
@@ -1,1 +1,1 @@
-/branches/1.4:1-165945
+/branches/1.4:1-166341

Modified: team/sruffell/asterisk-1.4-transcoder/CHANGES
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/CHANGES?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/CHANGES (original)
+++ team/sruffell/asterisk-1.4-transcoder/CHANGES Mon Dec 22 11:46:56 2008
@@ -120,6 +120,7 @@
         19. SQL_ESC()
         20. STAT()
         21. STRPTIME()
+		22. AUDIOHOOK_INHERIT()
     * Apps that have changes to their interface:
          1. Authenticate() -- optional maxdigits argument added.
          2. ChanSpy() -- new options:

Modified: team/sruffell/asterisk-1.4-transcoder/apps/app_dahdibarge.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/apps/app_dahdibarge.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/apps/app_dahdibarge.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/apps/app_dahdibarge.c Mon Dec 22 11:46:56 2008
@@ -134,11 +134,7 @@
 zapretry:
 	origfd = chan->fds[0];
 	if (retryzap) {
-#ifdef HAVE_ZAPTEL
-		fd = open("/dev/zap/pseudo", O_RDWR);
-#else
-		fd = open("/dev/dahdi/pseudo", O_RDWR);
-#endif
+		fd = open(DAHDI_FILE_PSEUDO, O_RDWR);
 		if (fd < 0) {
 			ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
 			goto outrun;

Modified: team/sruffell/asterisk-1.4-transcoder/apps/app_dahdiscan.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/apps/app_dahdiscan.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/apps/app_dahdiscan.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/apps/app_dahdiscan.c Mon Dec 22 11:46:56 2008
@@ -135,7 +135,7 @@
  zapretry:
 	origfd = chan->fds[0];
 	if (retryzap) {
-		fd = open("/dev/zap/pseudo", O_RDWR);
+		fd = open(DAHDI_FILE_PSEUDO, O_RDWR);
 		if (fd < 0) {
 			ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
 			goto outrun;

Modified: team/sruffell/asterisk-1.4-transcoder/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/apps/app_dial.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/apps/app_dial.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/apps/app_dial.c Mon Dec 22 11:46:56 2008
@@ -1837,37 +1837,29 @@
 			res = -1;
 		}
 
-		if (res != AST_PBX_NO_HANGUP_PEER && res != AST_PBX_NO_HANGUP_PEER_PARKED) {
-			if (res != AST_PBX_KEEPALIVE && !chan->_softhangup)
-				chan->hangupcause = peer->hangupcause;
-			ast_hangup(peer);
-		}
+		if (!chan->_softhangup)
+			chan->hangupcause = peer->hangupcause;
+		ast_hangup(peer);
 	}	
 out:
-	/* cleaning up chan is not a good idea here if AST_PBX_KEEPALIVE
-	   is returned; chan will get the love it needs from another
-	   thread */
-	if (res != AST_PBX_KEEPALIVE) {
-		if (moh) {
-			moh = 0;
-			ast_moh_stop(chan);
-		} else if (sentringing) {
-			sentringing = 0;
-			ast_indicate(chan, -1);
-		}
-		ast_rtp_early_bridge(chan, NULL);
-		hanguptree(outgoing, NULL);
-		pbx_builtin_setvar_helper(chan, "DIALSTATUS", status);
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Exiting with DIALSTATUS=%s.\n", status);
-		
-		if ((ast_test_flag(peerflags, OPT_GO_ON)) && (!chan->_softhangup) && (res != AST_PBX_KEEPALIVE)) {
-			if (timelimit)
-				chan->whentohangup = 0;
-			res = 0;
-		}
-	}
-
+	if (moh) {
+		moh = 0;
+		ast_moh_stop(chan);
+	} else if (sentringing) {
+		sentringing = 0;
+		ast_indicate(chan, -1);
+	}
+	ast_rtp_early_bridge(chan, NULL);
+	hanguptree(outgoing, NULL);
+	pbx_builtin_setvar_helper(chan, "DIALSTATUS", status);
+	if (option_debug)
+		ast_log(LOG_DEBUG, "Exiting with DIALSTATUS=%s.\n", status);
+	
+	if (ast_test_flag(peerflags, OPT_GO_ON) && !chan->_softhangup) {
+		if (calldurationlimit)
+			chan->whentohangup = 0;
+		res = 0;
+	}
 done:
 	ast_module_user_remove(u);    
 	return res;

Modified: team/sruffell/asterisk-1.4-transcoder/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/apps/app_meetme.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/apps/app_meetme.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/apps/app_meetme.c Mon Dec 22 11:46:56 2008
@@ -795,11 +795,7 @@
 	/* Setup a new zap conference */
 	ztc.confno = -1;
 	ztc.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
-#ifdef HAVE_ZAPTEL
-	cnf->fd = open("/dev/zap/pseudo", O_RDWR);
-#else
-	cnf->fd = open("/dev/dahdi/pseudo", O_RDWR);
-#endif
+	cnf->fd = open(DAHDI_FILE_PSEUDO, O_RDWR);
 	if (cnf->fd < 0 || ioctl(cnf->fd, DAHDI_SETCONF, &ztc)) {
 		ast_log(LOG_WARNING, "Unable to open pseudo device\n");
 		if (cnf->fd >= 0)
@@ -1732,11 +1728,7 @@
  zapretry:
 	origfd = chan->fds[0];
 	if (retryzap) {
-#ifdef HAVE_ZAPTEL
-		fd = open("/dev/zap/pseudo", O_RDWR);
-#else
-		fd = open("/dev/dahdi/pseudo", O_RDWR);
-#endif
+		fd = open(DAHDI_FILE_PSEUDO, O_RDWR);
 		if (fd < 0) {
 			ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
 			goto outrun;

Modified: team/sruffell/asterisk-1.4-transcoder/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/apps/app_queue.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/apps/app_queue.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/apps/app_queue.c Mon Dec 22 11:46:56 2008
@@ -3155,7 +3155,7 @@
 		transfer_ds = setup_transfer_datastore(qe, member, callstart, callcompletedinsl);
 		bridge = ast_bridge_call(qe->chan,peer, &bridge_config);
 
-		if (bridge != AST_PBX_KEEPALIVE && !attended_transfer_occurred(qe->chan)) {
+		if (!attended_transfer_occurred(qe->chan)) {
 			struct ast_datastore *tds;
 			if (strcasecmp(oldcontext, qe->chan->context) || strcasecmp(oldexten, qe->chan->exten)) {
 				ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "TRANSFER", "%s|%s|%ld|%ld",
@@ -3164,7 +3164,7 @@
 			} else if (qe->chan->_softhangup) {
 				ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "COMPLETECALLER", "%ld|%ld|%d",
 					(long) (callstart - qe->start), (long) (time(NULL) - callstart), qe->opos);
-				if (bridge != AST_PBX_NO_HANGUP_PEER && bridge != AST_PBX_NO_HANGUP_PEER_PARKED && qe->parent->eventwhencalled)
+				if (qe->parent->eventwhencalled)
 					manager_event(EVENT_FLAG_AGENT, "AgentComplete",
 							"Queue: %s\r\n"
 							"Uniqueid: %s\r\n"
@@ -3181,7 +3181,7 @@
 			} else {
 				ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "COMPLETEAGENT", "%ld|%ld|%d",
 					(long) (callstart - qe->start), (long) (time(NULL) - callstart), qe->opos);
-				if (bridge != AST_PBX_NO_HANGUP_PEER && bridge != AST_PBX_NO_HANGUP_PEER_PARKED && qe->parent->eventwhencalled)
+				if (qe->parent->eventwhencalled)
 					manager_event(EVENT_FLAG_AGENT, "AgentComplete",
 							"Queue: %s\r\n"
 							"Uniqueid: %s\r\n"
@@ -3206,8 +3206,7 @@
 		if (transfer_ds) {
 			ast_channel_datastore_free(transfer_ds);
 		}
-		if (bridge != AST_PBX_NO_HANGUP_PEER && bridge != AST_PBX_NO_HANGUP_PEER_PARKED)
-			ast_hangup(peer);
+		ast_hangup(peer);
 		res = bridge ? bridge : 1;
 		ao2_ref(member, -1);
 	}
@@ -4079,7 +4078,7 @@
 		}
 
 		/* Don't allow return code > 0 */
-		if (res >= 0 && res != AST_PBX_KEEPALIVE) {
+		if (res >= 0) {
 			res = 0;	
 			if (ringing) {
 				ast_indicate(chan, -1);

Modified: team/sruffell/asterisk-1.4-transcoder/channels/chan_dahdi.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/channels/chan_dahdi.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/channels/chan_dahdi.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/channels/chan_dahdi.c Mon Dec 22 11:46:56 2008
@@ -915,11 +915,7 @@
 			ast_log(LOG_WARNING, "Invalid channel number '%s'\n", fn);
 			return -1;
 		}
-#ifdef HAVE_ZAPTEL
-		fn = "/dev/zap/channel";
-#else
-		fn = "/dev/dahdi/channel";
-#endif
+		fn = DAHDI_FILE_CHANNEL;
 	}
 	fd = open(fn, O_RDWR | O_NONBLOCK);
 	if (fd < 0) {
@@ -981,11 +977,7 @@
 	struct dahdi_bufferinfo bi;
 	int res;
 	if (p->subs[x].dfd < 0) {
-#ifdef HAVE_ZAPTEL
-		p->subs[x].dfd = dahdi_open("/dev/zap/pseudo");
-#else
-		p->subs[x].dfd = dahdi_open("/dev/dahdi/pseudo");
-#endif
+		p->subs[x].dfd = dahdi_open(DAHDI_FILE_PSEUDO);
 		if (p->subs[x].dfd > -1) {
 			res = ioctl(p->subs[x].dfd, DAHDI_GET_BUFINFO, &bi);
 			if (!res) {
@@ -7222,11 +7214,7 @@
 			break;
 		memset(&si, 0, sizeof(si));
 		memset(&p, 0, sizeof(p));
-#ifdef HAVE_ZAPTEL
-		fd = open("/dev/zap/channel", O_RDWR);
-#else
-		fd = open("/dev/dahdi/channel", O_RDWR);
-#endif
+		fd = open(DAHDI_FILE_CHANNEL, O_RDWR);
 		if (fd < 0) {
 			ast_log(LOG_WARNING, "Failed to open channel: %s\n", strerror(errno));
 			return -1;
@@ -7886,11 +7874,7 @@
 	if ((p = ast_malloc(sizeof(*p)))) {
 		memcpy(p, src, sizeof(struct dahdi_pvt));
 		ast_mutex_init(&p->lock);
-#ifdef HAVE_ZAPTEL
-		p->subs[SUB_REAL].dfd = dahdi_open("/dev/zap/pseudo");
-#else
-		p->subs[SUB_REAL].dfd = dahdi_open("/dev/dahdi/pseudo");
-#endif
+		p->subs[SUB_REAL].dfd = dahdi_open(DAHDI_FILE_PSEUDO);
 		/* Allocate a DAHDI structure */
 		if (p->subs[SUB_REAL].dfd < 0) {
 			ast_log(LOG_ERROR, "Unable to dup channel: %s\n",  strerror(errno));
@@ -9638,11 +9622,7 @@
 	for (i = 0; i < NUM_DCHANS; i++) {
 		if (!pri->dchannels[i])
 			break;
-#ifdef HAVE_ZAPTEL
-		pri->fds[i] = open("/dev/zap/channel", O_RDWR, 0600);
-#else
-		pri->fds[i] = open("/dev/dahdi/channel", O_RDWR, 0600);
-#endif
+		pri->fds[i] = open(DAHDI_FILE_CHANNEL, O_RDWR, 0600);
 		x = pri->dchannels[i];
 		if ((pri->fds[i] < 0) || (ioctl(pri->fds[i],DAHDI_SPECIFY,&x) == -1)) {
 			ast_log(LOG_ERROR, "Unable to open D-channel %d (%s)\n", x, strerror(errno));
@@ -10417,19 +10397,11 @@
 	int ctl;
 	struct dahdi_spaninfo s;
 
-#ifdef HAVE_ZAPTEL
-	if ((ctl = open("/dev/zap/ctl", O_RDWR)) < 0) {
-		ast_log(LOG_WARNING, "Unable to open /dev/zap/ctl: %s\n", strerror(errno));
-		ast_cli(fd, "No Zaptel interface found.\n");
+	if ((ctl = open(DAHDI_FILE_CTL, O_RDWR)) < 0) {
+		ast_log(LOG_WARNING, "Unable to open " DAHDI_FILE_CTL ": %s\n", strerror(errno));
+		ast_cli(fd, "No " DAHDI_NAME " interface found.\n");
 		return RESULT_FAILURE;
 	}
-#else
-	if ((ctl = open("/dev/dahdi/ctl", O_RDWR)) < 0) {
-		ast_log(LOG_WARNING, "Unable to open /dev/dahdi/ctl: %s\n", strerror(errno));
-		ast_cli(fd, "No DAHDI interface found.\n");
-		return RESULT_FAILURE;
-	}
-#endif
 	ast_cli(fd, FORMAT2, "Description", "Alarms", "IRQ", "bpviol", "CRC4");
 
 	for (span = 1; span < DAHDI_MAX_SPANS; ++span) {
@@ -11616,14 +11588,10 @@
 				int res;
 				struct dahdi_dialparams dps;
 
-#ifdef HAVE_ZAPTEL
-				ctlfd = open("/dev/zap/ctl", O_RDWR);
-#else
-				ctlfd = open("/dev/dahdi/ctl", O_RDWR);
-#endif
+				ctlfd = open(DAHDI_FILE_CTL, O_RDWR);
 
 				if (ctlfd == -1) {
-					ast_log(LOG_ERROR, "Unable to open /dev/dahdi/ctl to set toneduration\n");
+					ast_log(LOG_ERROR, "Unable to open " DAHDI_FILE_CTL " to set toneduration\n");
 					return -1;
 				}
 

Modified: team/sruffell/asterisk-1.4-transcoder/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/channels/chan_iax2.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/channels/chan_iax2.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/channels/chan_iax2.c Mon Dec 22 11:46:56 2008
@@ -11231,23 +11231,13 @@
 	iax_set_error(iax_error_output);
 	jb_setoutput(jb_error_output, jb_warning_output, NULL);
 	
-#ifdef HAVE_ZAPTEL
-#ifdef ZAPTEL_TIMERACK
-	timingfd = open("/dev/zap/timer", O_RDWR);
+#ifdef DAHDI_TIMERACK
+	timingfd = open(DAHDI_FILE_TIMER, O_RDWR);
 	if (timingfd < 0)
 #endif
-		timingfd = open("/dev/zap/pseudo", O_RDWR);
+		timingfd = open(DAHDI_FILE_PSEUDO, O_RDWR);
 	if (timingfd < 0) 
 		ast_log(LOG_WARNING, "Unable to open IAX timing interface: %s\n", strerror(errno));
-#elif defined(HAVE_DAHDI)
-#ifdef DAHDI_TIMERACK
-	timingfd = open("/dev/dahdi/timer", O_RDWR);
-	if (timingfd < 0)
-#endif
-		timingfd = open("/dev/dahdi/pseudo", O_RDWR);
-	if (timingfd < 0) 
-		ast_log(LOG_WARNING, "Unable to open IAX timing interface: %s\n", strerror(errno));
-#endif
 
 	memset(iaxs, 0, sizeof(iaxs));
 

Modified: team/sruffell/asterisk-1.4-transcoder/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/channels/chan_sip.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/channels/chan_sip.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/channels/chan_sip.c Mon Dec 22 11:46:56 2008
@@ -14189,7 +14189,6 @@
 			char *uri = ast_strdupa(req->rlPart2);
 			char *at = strchr(uri, '@');
 			char *peerorhost;
-			struct sip_pkt *pkt = NULL;
 			if (option_debug > 2) {
 				ast_log(LOG_DEBUG, "Potential spiral detected. Original RURI was %s, new RURI is %s\n", p->initreq.rlPart2, req->rlPart2);
 			}
@@ -14200,14 +14199,12 @@
 			if ((peerorhost = strchr(uri, ':'))) {
 				*peerorhost++ = '\0';
 			}
-			create_addr(p, peerorhost);
 			ast_string_field_free(p, theirtag);
-			for (pkt = p->packets; pkt; pkt = pkt->next) {
-				if (pkt->seqno == p->icseq && pkt->method == SIP_INVITE) {
-					AST_SCHED_DEL(sched, pkt->retransid);
-				}
-			}
-			return transmit_invite(p, SIP_INVITE, 1, 3);
+			/* Treat this as if there were a call forward instead...
+			 */
+			ast_string_field_set(p->owner, call_forward, peerorhost);
+			ast_queue_control(p->owner, AST_CONTROL_BUSY);
+			return 0;
 		}
 	}
 	

Modified: team/sruffell/asterisk-1.4-transcoder/codecs/codec_dahdi.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/codecs/codec_dahdi.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/codecs/codec_dahdi.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/codecs/codec_dahdi.c Mon Dec 22 11:46:56 2008
@@ -633,17 +633,10 @@
 	int fd, res;
 	unsigned int x, y;
 
-#ifdef HAVE_ZAPTEL
-	if ((fd = open("/dev/zap/transcode", O_RDWR)) < 0) {
-		ast_log(LOG_ERROR, "Failed to open /dev/zap/transcode: %s\n", strerror(errno));
+	if ((fd = open(DAHDI_FILE_TRANSCODE, O_RDWR)) < 0) {
+		ast_log(LOG_ERROR, "Failed to open " DAHDI_FILE_TRANSCODE ": %s\n", strerror(errno));
 		return 0;
 	}
-#else
-	if ((fd = open("/dev/dahdi/transcode", O_RDWR)) < 0) {
-		ast_log(LOG_ERROR, "Failed to open /dev/dahdi/transcode: %s\n", strerror(errno));
-		return 0;
-	}
-#endif
 
 	for (info.tcnum = 0; !(res = ioctl(fd, DAHDI_TC_GETINFO, &info)); info.tcnum++) {
 		if (option_verbose > 1)

Modified: team/sruffell/asterisk-1.4-transcoder/include/asterisk/audiohook.h
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/include/asterisk/audiohook.h?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/include/asterisk/audiohook.h (original)
+++ team/sruffell/asterisk-1.4-transcoder/include/asterisk/audiohook.h Mon Dec 22 11:46:56 2008
@@ -146,12 +146,39 @@
  */
 int ast_audiohook_detach_list(struct ast_audiohook_list *audiohook_list);
 
+/*! \brief Move an audiohook from one channel to a new one
+ *
+ * \todo Currently only the first audiohook of a specific source found will be moved.
+ * We should add the capability to move multiple audiohooks from a single source as well.
+ *
+ * \note It is required that both old_chan and new_chan are locked prior to calling
+ * this function. Besides needing to protect the data within the channels, not locking
+ * these channels can lead to a potential deadlock
+ *
+ * \param old_chan The source of the audiohook to move
+ * \param new_chan The destination to which we want the audiohook to move
+ * \param source The source of the audiohook we want to move
+ */
+void ast_audiohook_move_by_source(struct ast_channel *old_chan, struct ast_channel *new_chan, const char *source);
+
 /*! \brief Detach specified source audiohook from channel
  * \param chan Channel to detach from
  * \param source Name of source to detach
  * \return Returns 0 on success, -1 on failure
  */
 int ast_audiohook_detach_source(struct ast_channel *chan, const char *source);
+
+/*!
+ * \brief Remove an audiohook from a specified channel
+ *
+ * \param chan Channel to remove from
+ * \param audiohook Audiohook to remove
+ *
+ * \return Returns 0 on success, -1 on failure
+ *
+ * \note The channel does not need to be locked before calling this function
+ */
+int ast_audiohook_remove(struct ast_channel *chan, struct ast_audiohook *audiohook);
 
 /*! \brief Pass a frame off to be handled by the audiohook core
  * \param chan Channel that the list is coming off of

Modified: team/sruffell/asterisk-1.4-transcoder/include/asterisk/dahdi_compat.h
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/include/asterisk/dahdi_compat.h?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/include/asterisk/dahdi_compat.h (original)
+++ team/sruffell/asterisk-1.4-transcoder/include/asterisk/dahdi_compat.h Mon Dec 22 11:46:56 2008
@@ -26,9 +26,15 @@
 
 #include <dahdi/user.h>
 
+#define DAHDI_DIR_NAME "/dev/dahdi"
+#define DAHDI_NAME "DAHDI"
+
 #elif defined(HAVE_ZAPTEL)
 
 #include <zaptel/zaptel.h>
+
+#define DAHDI_DIR_NAME "/dev/zap"
+#define DAHDI_NAME "DAHDI"
 
 /* Compiling against Zaptel instead of DAHDI */
 
@@ -443,4 +449,10 @@
 
 #endif
 
+#define DAHDI_FILE_CHANNEL   DAHDI_DIR_NAME "/channel"
+#define DAHDI_FILE_CTL       DAHDI_DIR_NAME "/ctl"
+#define DAHDI_FILE_PSEUDO    DAHDI_DIR_NAME "/pseudo"
+#define DAHDI_FILE_TIMER     DAHDI_DIR_NAME "/timer"
+#define DAHDI_FILE_TRANSCODE DAHDI_DIR_NAME "/transcode"
+
 #endif /* DAHDI_COMPAT_H */

Modified: team/sruffell/asterisk-1.4-transcoder/include/asterisk/pbx.h
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/include/asterisk/pbx.h?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/include/asterisk/pbx.h (original)
+++ team/sruffell/asterisk-1.4-transcoder/include/asterisk/pbx.h Mon Dec 22 11:46:56 2008
@@ -38,8 +38,6 @@
 
 /*! \brief Special return values from applications to the PBX { */
 #define AST_PBX_KEEPALIVE               10	/*!< Destroy the thread, but don't hang up the channel */
-#define AST_PBX_NO_HANGUP_PEER	        11  /*!< The peer has been involved in a transfer */
-#define AST_PBX_NO_HANGUP_PEER_PARKED	12  /*!< Don't touch the peer channel - it was sent to the parking lot and might be gone by now */
 /*! } */
 
 #define PRIORITY_HINT	-1	/*!< Special Priority for a hint */

Modified: team/sruffell/asterisk-1.4-transcoder/include/asterisk/strings.h
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/include/asterisk/strings.h?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/include/asterisk/strings.h (original)
+++ team/sruffell/asterisk-1.4-transcoder/include/asterisk/strings.h Mon Dec 22 11:46:56 2008
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
+#include <ctype.h>
 
 #include "asterisk/inline_api.h"
 #include "asterisk/compiler.h"
@@ -282,4 +283,22 @@
 	return abs(hash);
 }
 
+/*!
+ * \brief Compute a hash value on a case-insensitive string
+ *
+ * Uses the same hash algorithm as ast_str_hash, but converts
+ * all characters to lowercase prior to computing a hash. This
+ * allows for easy case-insensitive lookups in a hash table.
+ */
+static force_inline int ast_str_case_hash(const char *str)
+{
+	int hash = 5381;
+
+	while (*str) {
+		hash = hash * 33 ^ tolower(*str++);
+	}
+
+	return abs(hash);
+}
+
 #endif /* _ASTERISK_STRINGS_H */

Modified: team/sruffell/asterisk-1.4-transcoder/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/main/asterisk.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/main/asterisk.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/main/asterisk.c Mon Dec 22 11:46:56 2008
@@ -3034,53 +3034,35 @@
 	dahdi_chan_name_len = &_dahdi_chan_name_len;
 	dahdi_chan_mode = &_dahdi_chan_mode;
 
-#ifdef HAVE_ZAPTEL
 	{
 		int fd;
 		int x = 160;
-		fd = open("/dev/zap/timer", O_RDWR);
+		fd = open(DAHDI_FILE_TIMER, O_RDWR);
 		if (fd >= 0) {
 			if (ioctl(fd, DAHDI_TIMERCONFIG, &x)) {
-				ast_log(LOG_ERROR, "You have Zaptel built and drivers loaded, but the Zaptel timer test failed to set ZT_TIMERCONFIG to %d.\n", x);
+				ast_log(LOG_ERROR, "You have " DAHDI_NAME
+						" built and drivers loaded, but the "
+						DAHDI_NAME " timer test failed to set DAHDI_TIMERCONFIG to %d.\n", x);
 				exit(1);
 			}
 			if ((x = ast_wait_for_input(fd, 300)) < 0) {
-				ast_log(LOG_ERROR, "You have Zaptel built and drivers loaded, but the Zaptel timer could not be polled during the Zaptel timer test.\n");
-				exit(1);
-			}
-			if (!x) {
-				const char zaptel_timer_error[] = {
-					"Asterisk has detected a problem with your Zaptel configuration and will shutdown for your protection.  You have options:"
-					"\n\t1. You only have to compile Zaptel support into Asterisk if you need it.  One option is to recompile without Zaptel support."
-					"\n\t2. You only have to load Zaptel drivers if you want to take advantage of Zaptel services.  One option is to unload zaptel modules if you don't need them."
-					"\n\t3. If you need Zaptel services, you must correctly configure Zaptel."
-				};
-				ast_log(LOG_ERROR, "%s\n", zaptel_timer_error);
-				exit(1);
-			}
-			close(fd);
-		}
-	}
-#elif defined(HAVE_DAHDI)
-{
-		int fd;
-		int x = 160;
-		fd = open("/dev/dahdi/timer", O_RDWR);
-		if (fd >= 0) {
-			if (ioctl(fd, DAHDI_TIMERCONFIG, &x)) {
-				ast_log(LOG_ERROR, "You have DAHDI built and drivers loaded, but the DAHDI timer test failed to set DAHDI_TIMERCONFIG to %d.\n", x);
-				exit(1);
-			}
-			if ((x = ast_wait_for_input(fd, 300)) < 0) {
-				ast_log(LOG_ERROR, "You have DAHDI built and drivers loaded, but the DAHDI timer could not be polled during the DAHDI timer test.\n");
+				ast_log(LOG_ERROR, "You have " DAHDI_NAME 
+						"built and drivers loaded, but the " 
+						DAHDI_NAME " timer could not be polled during the " 
+						DAHDI_NAME " timer test.\n");
 				exit(1);
 			}
 			if (!x) {
 				const char dahdi_timer_error[] = {
-					"Asterisk has detected a problem with your DAHDI configuration and will shutdown for your protection.  You have options:"
-					"\n\t1. You only have to compile DAHDI support into Asterisk if you need it.  One option is to recompile without DAHDI support."
-					"\n\t2. You only have to load DAHDI drivers if you want to take advantage of DAHDI services.  One option is to unload DAHDI modules if you don't need them."
-					"\n\t3. If you need DAHDI services, you must correctly configure DAHDI."
+					"Asterisk has detected a problem with your " DAHDI_NAME 
+						" configuration and will shutdown for your protection.  You have options:"
+					"\n\t1. You only have to compile " DAHDI_NAME 
+						" support into Asterisk if you need it.  One option is to recompile without " 
+						DAHDI_NAME " support."
+					"\n\t2. You only have to load " DAHDI_NAME " drivers if you want to take advantage of " 
+						DAHDI_NAME " services.  One option is to unload " 
+						DAHDI_NAME " modules if you don't need them."
+					"\n\t3. If you need Zaptel services, you must correctly configure " DAHDI_NAME "."
 				};
 				ast_log(LOG_ERROR, "%s\n", dahdi_timer_error);
 				exit(1);
@@ -3088,8 +3070,6 @@
 			close(fd);
 		}
 	}
-
-#endif
 	threadstorage_init();
 
 	astobj2_init();

Modified: team/sruffell/asterisk-1.4-transcoder/main/audiohook.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/main/audiohook.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/main/audiohook.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/main/audiohook.c Mon Dec 22 11:46:56 2008
@@ -451,6 +451,25 @@
 	return NULL;
 }
 
+void ast_audiohook_move_by_source (struct ast_channel *old_chan, struct ast_channel *new_chan, const char *source)
+{
+	struct ast_audiohook *audiohook = find_audiohook_by_source(old_chan->audiohooks, source);
+
+	if (!audiohook) {
+		return;
+	}
+	
+	/* By locking both channels and the audiohook, we can assure that
+	 * another thread will not have a chance to read the audiohook's status
+	 * as done, even though ast_audiohook_remove signals the trigger
+	 * condition
+	 */
+	ast_audiohook_lock(audiohook);
+	ast_audiohook_remove(old_chan, audiohook);
+	ast_audiohook_attach(new_chan, audiohook);
+	ast_audiohook_unlock(audiohook);
+}
+
 /*! \brief Detach specified source audiohook from channel
  * \param chan Channel to detach from
  * \param source Name of source to detach
@@ -476,6 +495,42 @@
 		audiohook->status = AST_AUDIOHOOK_STATUS_SHUTDOWN;
 
 	return (audiohook ? 0 : -1);
+}
+
+/*!
+ * \brief Remove an audiohook from a specified channel
+ *
+ * \param chan Channel to remove from
+ * \param audiohook Audiohook to remove
+ *
+ * \return Returns 0 on success, -1 on failure
+ *
+ * \note The channel does not need to be locked before calling this function
+ */
+int ast_audiohook_remove(struct ast_channel *chan, struct ast_audiohook *audiohook)
+{
+	ast_channel_lock(chan);
+
+	if (!chan->audiohooks) {
+		ast_channel_unlock(chan);
+		return -1;
+	}
+
+	if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY)
+		AST_LIST_REMOVE(&chan->audiohooks->spy_list, audiohook, list);
+	else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER)
+		AST_LIST_REMOVE(&chan->audiohooks->whisper_list, audiohook, list);
+	else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE)
+		AST_LIST_REMOVE(&chan->audiohooks->manipulate_list, audiohook, list);
+
+	ast_audiohook_lock(audiohook);
+	audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
+	ast_cond_signal(&audiohook->trigger);
+	ast_audiohook_unlock(audiohook);
+
+	ast_channel_unlock(chan);
+
+	return 0;
 }
 
 /*! \brief Pass a DTMF frame off to be handled by the audiohook core

Modified: team/sruffell/asterisk-1.4-transcoder/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/main/channel.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/main/channel.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/main/channel.c Mon Dec 22 11:46:56 2008
@@ -744,11 +744,7 @@
 
 #ifdef HAVE_DAHDI
 
-#ifdef HAVE_ZAPTEL
-	tmp->timingfd = open("/dev/zap/timer", O_RDWR);
-#else
-	tmp->timingfd = open("/dev/dahdi/timer", O_RDWR);
-#endif
+	tmp->timingfd = open(DAHDI_FILE_TIMER, O_RDWR);
 
 	if (tmp->timingfd > -1) {
 		/* Check if timing interface supports new
@@ -3669,11 +3665,11 @@
 	/* Move data stores over */
 	if (AST_LIST_FIRST(&clone->datastores)) {
 		struct ast_datastore *ds;
-		AST_LIST_APPEND_LIST(&original->datastores, &clone->datastores, entry);
-		AST_LIST_TRAVERSE(&original->datastores, ds, entry) {
+		AST_LIST_TRAVERSE(&clone->datastores, ds, entry) {
 			if (ds->info->chan_fixup)
 				ds->info->chan_fixup(ds->data, clone, original);
 		}
+		AST_LIST_APPEND_LIST(&original->datastores, &clone->datastores, entry);
 	}
 
 	clone_variables(original, clone);

Modified: team/sruffell/asterisk-1.4-transcoder/main/utils.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/main/utils.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/main/utils.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/main/utils.c Mon Dec 22 11:46:56 2008
@@ -921,7 +921,9 @@
 
 int ast_carefulwrite(int fd, char *s, int len, int timeoutms) 
 {
+	struct timeval start = ast_tvnow();
 	int res = 0;
+	int elapsed = 0;
 
 	while (len) {
 		struct pollfd pfd = {
@@ -930,7 +932,7 @@
 		};
 
 		/* poll() until the fd is writable without blocking */
-		while ((res = poll(&pfd, 1, timeoutms)) <= 0) {
+		while ((res = poll(&pfd, 1, timeoutms - elapsed)) <= 0) {
 			if (res == 0) {
 				/* timed out. */
 				ast_log(LOG_NOTICE, "Timed out trying to write\n");
@@ -939,6 +941,13 @@
 				/* poll() returned an error, check to see if it was fatal */
 
 				if (errno == EINTR || errno == EAGAIN) {
+					elapsed = ast_tvdiff_ms(ast_tvnow(), start);
+					if (elapsed > timeoutms) {
+						/* We've taken too long to write 
+						 * This is only an error condition if we haven't finished writing. */
+						res = len ? -1 : 0;
+						break;
+					}
 					/* This was an acceptable error, go back into poll() */
 					continue;
 				}
@@ -967,6 +976,14 @@
 		len -= res;
 		s += res;
 		res = 0;
+
+		elapsed = ast_tvdiff_ms(ast_tvnow(), start);
+		if (elapsed > timeoutms) {
+			/* We've taken too long to write 
+			 * This is only an error condition if we haven't finished writing. */
+			res = len ? -1 : 0;
+			break;
+		}
 	}
 
 	return res;

Modified: team/sruffell/asterisk-1.4-transcoder/res/res_features.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/res/res_features.c?view=diff&rev=166344&r1=166343&r2=166344
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/res/res_features.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/res/res_features.c Mon Dec 22 11:46:56 2008
@@ -535,12 +535,8 @@
 {
 	return masq_park_call(rchan, peer, timeout, extout, 1);
 }
-
 #define FEATURE_RETURN_HANGUP                  -1
 #define FEATURE_RETURN_SUCCESSBREAK             0
-#define FEATURE_RETURN_PBX_KEEPALIVE            AST_PBX_KEEPALIVE
-#define FEATURE_RETURN_NO_HANGUP_PEER           AST_PBX_NO_HANGUP_PEER
-#define FEATURE_RETURN_NO_HANGUP_PEER_PARKED    AST_PBX_NO_HANGUP_PEER_PARKED
 #define FEATURE_RETURN_PASSDIGITS               21
 #define FEATURE_RETURN_STOREDIGITS              22
 #define FEATURE_RETURN_SUCCESS                  23
@@ -575,30 +571,22 @@
 	u = ast_module_user_add(chan);
 
 	set_peers(&parker, &parkee, peer, chan, sense);
-	/* Setup the exten/priority to be s/1 since we don't know
-	   where this call should return */
-	strcpy(chan->exten, "s");
-	chan->priority = 1;
+	/* we used to set chan's exten and priority to "s" and 1
+	   here, but this generates (in some cases) an invalid
+	   extension, and if "s" exists, could errantly
+	   cause execution of extensions you don't expect It
+	   makes more sense to let nature take its course
+	   when chan finishes, and let the pbx do its thing
+	   and hang up when the park is over.
+	*/
 	if (chan->_state != AST_STATE_UP)
 		res = ast_answer(chan);
 	if (!res)
 		res = ast_safe_sleep(chan, 1000);
 
-	if (!res) {
-		if (sense == FEATURE_SENSE_CHAN) {

[... 1269 lines stripped ...]



More information about the asterisk-commits mailing list