[Asterisk-cvs] asterisk/channels chan_agent.c,1.65,1.66 chan_alsa.c,1.11,1.12 chan_h323.c,1.31,1.32 chan_iax.c,1.49,1.50 chan_iax2.c,1.100,1.101 chan_local.c,1.22,1.23 chan_mgcp.c,1.34,1.35 chan_oss.c,1.21,1.22 chan_sip.c,1.303,1.304 chan_skinny.c,1.27,1.28 chan_vpb.c,1.12,1.13 chan_zap.c,1.180,1.181

markster at lists.digium.com markster at lists.digium.com
Wed Mar 3 20:20:31 CST 2004


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv30685/channels

Modified Files:
	chan_agent.c chan_alsa.c chan_h323.c chan_iax.c chan_iax2.c 
	chan_local.c chan_mgcp.c chan_oss.c chan_sip.c chan_skinny.c 
	chan_vpb.c chan_zap.c 
Log Message:
Add support for parking with IAX2


Index: chan_agent.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_agent.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- chan_agent.c	14 Feb 2004 04:54:39 -0000	1.65
+++ chan_agent.c	4 Mar 2004 01:11:25 -0000	1.66
@@ -380,17 +380,19 @@
 	return res;
 }
 
-static int agent_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
+static int agent_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, int needlock)
 {
 	struct agent_pvt *p = newchan->pvt->pvt;
-	ast_mutex_lock(&p->lock);
+	if (needlock)
+		ast_mutex_lock(&p->lock);
 	if (p->owner != oldchan) {
 		ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, p->owner);
 		ast_mutex_unlock(&p->lock);
 		return -1;
 	}
 	p->owner = newchan;
-	ast_mutex_unlock(&p->lock);
+	if (needlock)
+		ast_mutex_unlock(&p->lock);
 	return 0;
 }
 

Index: chan_alsa.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_alsa.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- chan_alsa.c	28 Jan 2004 21:06:03 -0000	1.11
+++ chan_alsa.c	4 Mar 2004 01:11:25 -0000	1.12
@@ -755,7 +755,7 @@
 	return &f;
 }
 
-static int alsa_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
+static int alsa_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, int needlock)
 {
 	struct chan_alsa_pvt *p = newchan->pvt->pvt;
 	p->owner = newchan;

Index: chan_h323.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_h323.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- chan_h323.c	13 Jan 2004 09:24:26 -0000	1.31
+++ chan_h323.c	4 Mar 2004 01:11:25 -0000	1.32
@@ -623,17 +623,19 @@
 }
 
 // FIXME: WTF is this? Do I need this???
-static int oh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
+static int oh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, int needlock)
 {
 	struct oh323_pvt *p = newchan->pvt->pvt;
 
-	ast_mutex_lock(&p->lock);
+	if (needlock)
+		ast_mutex_lock(&p->lock);
 	if (p->owner != oldchan) {
 		ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, p->owner);
 		return -1;
 	}
 	p->owner = newchan;
-	ast_mutex_unlock(&p->lock);
+	if (needlock)
+		ast_mutex_unlock(&p->lock);
 	return 0;
 }
 

Index: chan_iax.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- chan_iax.c	2 Feb 2004 06:38:08 -0000	1.49
+++ chan_iax.c	4 Mar 2004 01:11:25 -0000	1.50
@@ -1515,7 +1515,7 @@
 	return send_command(c->pvt->pvt, AST_FRAME_HTML, subclass, 0, data, datalen, -1);
 }
 
-static int iax_fixup(struct ast_channel *oldchannel, struct ast_channel *newchan)
+static int iax_fixup(struct ast_channel *oldchannel, struct ast_channel *newchan, int needlock)
 {
 	struct chan_iax_pvt *pvt = newchan->pvt->pvt;
 	pvt->owner = newchan;

Index: chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -d -r1.100 -r1.101
--- chan_iax2.c	27 Feb 2004 16:35:32 -0000	1.100
+++ chan_iax2.c	4 Mar 2004 01:11:25 -0000	1.101
@@ -33,6 +33,7 @@
 #include <asterisk/app.h>
 #include <asterisk/astdb.h>
 #include <asterisk/musiconhold.h>
+#include <asterisk/parking.h>
 #include <sys/mman.h>
 #include <arpa/inet.h>
 #include <dirent.h>
@@ -1750,15 +1751,17 @@
 	return send_command_locked(PTR_TO_CALLNO(c->pvt->pvt), AST_FRAME_HTML, subclass, 0, data, datalen, -1);
 }
 
-static int iax2_fixup(struct ast_channel *oldchannel, struct ast_channel *newchan)
+static int iax2_fixup(struct ast_channel *oldchannel, struct ast_channel *newchan, int lock)
 {
 	unsigned short callno = PTR_TO_CALLNO(newchan->pvt->pvt);
-	ast_mutex_lock(&iaxsl[callno]);
+	if (lock)
+		ast_mutex_lock(&iaxsl[callno]);
 	if (iaxs[callno])
 		iaxs[callno]->owner = newchan;
 	else
 		ast_log(LOG_WARNING, "Uh, this isn't a good sign...\n");
-	ast_mutex_unlock(&iaxsl[callno]);
+	if (lock)
+		ast_mutex_unlock(&iaxsl[callno]);
 	return 0;
 }
 
@@ -4228,7 +4231,7 @@
 	memset(&ied1, 0, sizeof(ied1));
 	mm = ast_matchmore_extension(NULL, context, callednum, 1, callerid);
 	/* Must be started */
-	if (ast_exists_extension(NULL, context, callednum, 1, callerid)) {
+	if (!strcmp(callednum, ast_parking_ext()) || ast_exists_extension(NULL, context, callednum, 1, callerid)) {
 		dpstatus = IAX_DPSTATUS_EXISTS;
 	} else if (ast_canmatch_extension(NULL, context, callednum, 1, callerid)) {
 		dpstatus = IAX_DPSTATUS_CANEXIST;
@@ -4281,6 +4284,84 @@
 		ast_log(LOG_WARNING, "Out of memory!\n");
 }
 
+struct iax_dual {
+	struct ast_channel *chan1;
+	struct ast_channel *chan2;
+};
+
+static void *iax_park_thread(void *stuff)
+{
+	struct ast_channel *chan1, *chan2;
+	struct iax_dual *d;
+	struct ast_frame *f;
+	int ext;
+	int res;
+	d = stuff;
+	chan1 = d->chan1;
+	chan2 = d->chan2;
+	free(d);
+	f = ast_read(chan1);
+	if (f)
+		ast_frfree(f);
+	res = ast_park_call(chan1, chan2, 0, &ext);
+	ast_hangup(chan2);
+	ast_log(LOG_DEBUG, "Parked on extension '%d'\n", ext);
+	return NULL;
+}
+
+static int iax_park(struct ast_channel *chan1, struct ast_channel *chan2)
+{
+	struct iax_dual *d;
+	struct ast_channel *chan1m, *chan2m;
+	pthread_t th;
+	chan1m = ast_channel_alloc(0);
+	chan2m = ast_channel_alloc(0);
+	if (chan2m && chan1m) {
+		snprintf(chan1m->name, sizeof(chan1m->name), "Parking/%s", chan1->name);
+		/* Make formats okay */
+		chan1m->readformat = chan1->readformat;
+		chan1m->writeformat = chan1->writeformat;
+		ast_channel_masquerade(chan1m, chan1);
+		/* Setup the extensions and such */
+		strncpy(chan1m->context, chan1->context, sizeof(chan1m->context) - 1);
+		strncpy(chan1m->exten, chan1->exten, sizeof(chan1m->exten) - 1);
+		chan1m->priority = chan1->priority;
+		
+		/* We make a clone of the peer channel too, so we can play
+		   back the announcement */
+		snprintf(chan2m->name, sizeof (chan2m->name), "IAXPeer/%s",chan2->name);
+		/* Make formats okay */
+		chan2m->readformat = chan2->readformat;
+		chan2m->writeformat = chan2->writeformat;
+		ast_channel_masquerade(chan2m, chan2);
+		/* Setup the extensions and such */
+		strncpy(chan2m->context, chan2->context, sizeof(chan2m->context) - 1);
+		strncpy(chan2m->exten, chan2->exten, sizeof(chan2m->exten) - 1);
+		chan2m->priority = chan2->priority;
+		if (ast_do_masquerade(chan2m, 0)) {
+			ast_log(LOG_WARNING, "Masquerade failed :(\n");
+			ast_hangup(chan2m);
+			return -1;
+		}
+	} else {
+		if (chan1m)
+			ast_hangup(chan1m);
+		if (chan2m)
+			ast_hangup(chan2m);
+		return -1;
+	}
+	d = malloc(sizeof(struct iax_dual));
+	if (d) {
+		memset(d, 0, sizeof(*d));
+		d->chan1 = chan1m;
+		d->chan2 = chan2m;
+		if (!pthread_create(&th, NULL, iax_park_thread, d))
+			return 0;
+		free(d);
+	}
+	return -1;
+}
+
 static int socket_read(int *id, int fd, short events, void *cbdata)
 {
 	struct sockaddr_in sin;
@@ -4799,12 +4880,19 @@
 				break;
 			case IAX_COMMAND_TRANSFER:
 				if (iaxs[fr.callno]->owner && iaxs[fr.callno]->owner->bridge && ies.called_number) {
-					if (ast_async_goto(iaxs[fr.callno]->owner->bridge, iaxs[fr.callno]->context, ies.called_number, 1, 1))
-						ast_log(LOG_WARNING, "Async goto of '%s' to '%s@%s' failed\n", iaxs[fr.callno]->owner->bridge->name, 
-							ies.called_number, iaxs[fr.callno]->context);
-					else
-						ast_log(LOG_DEBUG, "Async goto of '%s' to '%s@%s' started\n", iaxs[fr.callno]->owner->bridge->name, 
-							ies.called_number, iaxs[fr.callno]->context);
+					if (!strcmp(ies.called_number, ast_parking_ext())) {
+						if (iax_park(iaxs[fr.callno]->owner->bridge, iaxs[fr.callno]->owner)) {
+							ast_log(LOG_WARNING, "Failed to park call on '%s'\n", iaxs[fr.callno]->owner->bridge->name);
+						} else
+							ast_log(LOG_DEBUG, "Parked call on '%s'\n", iaxs[fr.callno]->owner->bridge->name);
+					} else {
+						if (ast_async_goto(iaxs[fr.callno]->owner->bridge, iaxs[fr.callno]->context, ies.called_number, 1, 1))
+							ast_log(LOG_WARNING, "Async goto of '%s' to '%s@%s' failed\n", iaxs[fr.callno]->owner->bridge->name, 
+								ies.called_number, iaxs[fr.callno]->context);
+						else
+							ast_log(LOG_DEBUG, "Async goto of '%s' to '%s@%s' started\n", iaxs[fr.callno]->owner->bridge->name, 
+								ies.called_number, iaxs[fr.callno]->context);
+					}
 				} else
 						ast_log(LOG_DEBUG, "Async goto not applicable on call %d\n", fr.callno);
 				break;

Index: chan_local.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_local.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- chan_local.c	28 Jan 2004 21:06:03 -0000	1.22
+++ chan_local.c	4 Mar 2004 01:11:25 -0000	1.23
@@ -185,20 +185,23 @@
 	return res;
 }
 
-static int local_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
+static int local_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, int needlock)
 {
 	struct local_pvt *p = newchan->pvt->pvt;
-	ast_mutex_lock(&p->lock);
+	if (needlock)
+		ast_mutex_lock(&p->lock);
 	if ((p->owner != oldchan) && (p->chan != oldchan)) {
 		ast_log(LOG_WARNING, "old channel wasn't %p but was %p/%p\n", oldchan, p->owner, p->chan);
-		ast_mutex_unlock(&p->lock);
+		if (needlock)
+			ast_mutex_unlock(&p->lock);
 		return -1;
 	}
 	if (p->owner == oldchan)
 		p->owner = newchan;
 	else
 		p->chan = newchan;	
-	ast_mutex_unlock(&p->lock);
+	if (needlock)
+		ast_mutex_unlock(&p->lock);
 	return 0;
 }
 

Index: chan_mgcp.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_mgcp.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- chan_mgcp.c	2 Feb 2004 06:38:08 -0000	1.34
+++ chan_mgcp.c	4 Mar 2004 01:11:25 -0000	1.35
@@ -771,7 +771,7 @@
 	return res;
 }
 
-static int mgcp_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
+static int mgcp_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, int needlock)
 {
 	struct mgcp_subchannel *sub = newchan->pvt->pvt;
     ast_log(LOG_NOTICE, "mgcp_fixup(%s, %s)\n", oldchan->name, newchan->name);

Index: chan_oss.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_oss.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- chan_oss.c	22 Oct 2003 03:10:34 -0000	1.21
+++ chan_oss.c	4 Mar 2004 01:11:25 -0000	1.22
@@ -661,7 +661,7 @@
 	return &f;
 }
 
-static int oss_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
+static int oss_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, int needlock)
 {
 	struct chan_oss_pvt *p = newchan->pvt->pvt;
 	p->owner = newchan;

Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.303
retrieving revision 1.304
diff -u -d -r1.303 -r1.304
--- chan_sip.c	2 Mar 2004 23:29:00 -0000	1.303
+++ chan_sip.c	4 Mar 2004 01:11:25 -0000	1.304
@@ -1364,17 +1364,20 @@
 	return res;
 }
 
-static int sip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
+static int sip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, int needlock)
 {
 	struct sip_pvt *p = newchan->pvt->pvt;
-	ast_mutex_lock(&p->lock);
+	if (needlock)
+		ast_mutex_lock(&p->lock);
 	if (p->owner != oldchan) {
 		ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, p->owner);
-		ast_mutex_unlock(&p->lock);
+		if (needlock)
+			ast_mutex_unlock(&p->lock);
 		return -1;
 	}
 	p->owner = newchan;
-	ast_mutex_unlock(&p->lock);
+	if (needlock)
+		ast_mutex_unlock(&p->lock);
 	return 0;
 }
 

Index: chan_skinny.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_skinny.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- chan_skinny.c	2 Feb 2004 06:38:08 -0000	1.27
+++ chan_skinny.c	4 Mar 2004 01:11:25 -0000	1.28
@@ -1650,7 +1650,7 @@
 	return res;
 }
 
-static int skinny_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
+static int skinny_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, int needlock)
 {
 	struct skinny_subchannel *sub = newchan->pvt->pvt;
     ast_log(LOG_NOTICE, "skinny_fixup(%s, %s)\n", oldchan->name, newchan->name);

Index: chan_vpb.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_vpb.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- chan_vpb.c	9 Dec 2003 23:55:17 -0000	1.12
+++ chan_vpb.c	4 Mar 2004 01:11:25 -0000	1.13
@@ -651,7 +651,7 @@
     return res;
 }
 
-static int vpb_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
+static int vpb_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, int needlock)
 {
 	struct vpb_pvt *p = (struct vpb_pvt *)newchan->pvt->pvt;
 

Index: chan_zap.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v
retrieving revision 1.180
retrieving revision 1.181
diff -u -d -r1.180 -r1.181
--- chan_zap.c	3 Mar 2004 03:54:25 -0000	1.180
+++ chan_zap.c	4 Mar 2004 01:11:25 -0000	1.181
@@ -2537,11 +2537,12 @@
 
 static int zt_indicate(struct ast_channel *chan, int condition);
 
-static int zt_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
+static int zt_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, int needlock)
 {
 	struct zt_pvt *p = newchan->pvt->pvt;
 	int x;
-	ast_mutex_lock(&p->lock);
+	if (needlock)
+		ast_mutex_lock(&p->lock);
 	ast_log(LOG_DEBUG, "New owner for channel %d is %s\n", p->channel, newchan->name);
 	if (p->owner == oldchan)
 		p->owner = newchan;
@@ -2554,7 +2555,8 @@
 	if (newchan->_state == AST_STATE_RINGING) 
 		zt_indicate(newchan, AST_CONTROL_RINGING);
 	update_conf(p);
-	ast_mutex_unlock(&p->lock);
+	if (needlock)
+		ast_mutex_unlock(&p->lock);
 	return 0;
 }
 




More information about the svn-commits mailing list