| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Copyright (C) 1999 - 2005, Digium, Inc. | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  |  * Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  |  * This program is free software, distributed under the terms of | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \author Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  |  * \brief Local Proxy Channel | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup channel_drivers | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2005-06-07 17:06:33 +00:00
										 |  |  | #include <unistd.h>
 | 
					
						
							| 
									
										
										
										
											2005-06-06 21:09:59 +00:00
										 |  |  | #include <sys/socket.h>
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <fcntl.h>
 | 
					
						
							|  |  |  | #include <netdb.h>
 | 
					
						
							| 
									
										
										
										
											2005-06-07 17:06:33 +00:00
										 |  |  | #include <netinet/in.h>
 | 
					
						
							| 
									
										
										
										
											2005-06-06 21:09:59 +00:00
										 |  |  | #include <arpa/inet.h>
 | 
					
						
							|  |  |  | #include <sys/signal.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-06 22:12:19 +00:00
										 |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							| 
									
										
										
										
											2005-06-06 21:09:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 06:02:45 +00:00
										 |  |  | #include "asterisk/lock.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/config.h"
 | 
					
						
							|  |  |  | #include "asterisk/logger.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/options.h"
 | 
					
						
							|  |  |  | #include "asterisk/lock.h"
 | 
					
						
							|  |  |  | #include "asterisk/sched.h"
 | 
					
						
							|  |  |  | #include "asterisk/io.h"
 | 
					
						
							|  |  |  | #include "asterisk/rtp.h"
 | 
					
						
							|  |  |  | #include "asterisk/acl.h"
 | 
					
						
							|  |  |  | #include "asterisk/callerid.h"
 | 
					
						
							|  |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/cli.h"
 | 
					
						
							|  |  |  | #include "asterisk/app.h"
 | 
					
						
							|  |  |  | #include "asterisk/musiconhold.h"
 | 
					
						
							|  |  |  | #include "asterisk/manager.h"
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | static const char desc[] = "Local Proxy Channel"; | 
					
						
							|  |  |  | static const char type[] = "Local"; | 
					
						
							|  |  |  | static const char tdesc[] = "Local Proxy Channel Driver"; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int usecnt =0; | 
					
						
							| 
									
										
										
										
											2004-06-09 01:45:08 +00:00
										 |  |  | AST_MUTEX_DEFINE_STATIC(usecnt_lock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define IS_OUTBOUND(a,b) (a == b->chan ? 1 : 0)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Protect the interface list (of sip_pvt's) */ | 
					
						
							| 
									
										
										
										
											2004-06-09 01:45:08 +00:00
										 |  |  | AST_MUTEX_DEFINE_STATIC(locallock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | static struct ast_channel *local_request(const char *type, int format, void *data, int *cause); | 
					
						
							|  |  |  | static int local_digit(struct ast_channel *ast, char digit); | 
					
						
							|  |  |  | static int local_call(struct ast_channel *ast, char *dest, int timeout); | 
					
						
							|  |  |  | static int local_hangup(struct ast_channel *ast); | 
					
						
							|  |  |  | static int local_answer(struct ast_channel *ast); | 
					
						
							|  |  |  | static struct ast_frame *local_read(struct ast_channel *ast); | 
					
						
							|  |  |  | static int local_write(struct ast_channel *ast, struct ast_frame *f); | 
					
						
							|  |  |  | static int local_indicate(struct ast_channel *ast, int condition); | 
					
						
							|  |  |  | static int local_fixup(struct ast_channel *oldchan, struct ast_channel *newchan); | 
					
						
							| 
									
										
										
										
											2005-03-28 20:48:24 +00:00
										 |  |  | static int local_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | /* PBX interface structure for channel registration */ | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | static const struct ast_channel_tech local_tech = { | 
					
						
							|  |  |  | 	.type = type, | 
					
						
							|  |  |  | 	.description = tdesc, | 
					
						
							|  |  |  | 	.capabilities = -1, | 
					
						
							|  |  |  | 	.requester = local_request, | 
					
						
							|  |  |  | 	.send_digit = local_digit, | 
					
						
							|  |  |  | 	.call = local_call, | 
					
						
							|  |  |  | 	.hangup = local_hangup, | 
					
						
							|  |  |  | 	.answer = local_answer, | 
					
						
							|  |  |  | 	.read = local_read, | 
					
						
							|  |  |  | 	.write = local_write, | 
					
						
							|  |  |  | 	.exception = local_read, | 
					
						
							|  |  |  | 	.indicate = local_indicate, | 
					
						
							|  |  |  | 	.fixup = local_fixup, | 
					
						
							|  |  |  | 	.send_html = local_sendhtml, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | static struct local_pvt { | 
					
						
							| 
									
										
										
										
											2005-07-10 23:49:57 +00:00
										 |  |  | 	ast_mutex_t lock;			/* Channel private lock */ | 
					
						
							|  |  |  | 	char context[AST_MAX_CONTEXT];		/* Context to call */ | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	char exten[AST_MAX_EXTENSION];		/* Extension to call */ | 
					
						
							| 
									
										
										
										
											2005-07-10 23:49:57 +00:00
										 |  |  | 	int reqformat;				/* Requested format */ | 
					
						
							|  |  |  | 	int glaredetect;			/* Detect glare on hangup */ | 
					
						
							|  |  |  | 	int cancelqueue;			/* Cancel queue */ | 
					
						
							|  |  |  | 	int alreadymasqed;			/* Already masqueraded */ | 
					
						
							|  |  |  | 	int launchedpbx;			/* Did we launch the PBX */ | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 	int nooptimization;			/* Don't leave masq state */ | 
					
						
							| 
									
										
										
										
											2005-07-10 23:49:57 +00:00
										 |  |  | 	struct ast_channel *owner;		/* Master Channel */ | 
					
						
							|  |  |  | 	struct ast_channel *chan;		/* Outbound channel */ | 
					
						
							|  |  |  | 	struct local_pvt *next;			/* Next entity */ | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | } *locals = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-08 18:09:24 +00:00
										 |  |  | static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_frame *f, struct ast_channel *us) | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-08-08 18:09:24 +00:00
										 |  |  | 	struct ast_channel *other; | 
					
						
							| 
									
										
										
										
											2003-12-02 15:52:37 +00:00
										 |  |  | retrylock:		 | 
					
						
							|  |  |  | 	/* Recalculate outbound channel */ | 
					
						
							| 
									
										
										
										
											2003-08-08 03:01:29 +00:00
										 |  |  | 	if (isoutbound) { | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		other = p->owner; | 
					
						
							| 
									
										
										
										
											2003-08-08 03:01:29 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		other = p->chan; | 
					
						
							| 
									
										
										
										
											2003-08-08 03:01:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-12-02 15:52:37 +00:00
										 |  |  | 	/* Set glare detection */ | 
					
						
							| 
									
										
										
										
											2003-07-01 03:32:14 +00:00
										 |  |  | 	p->glaredetect = 1; | 
					
						
							|  |  |  | 	if (p->cancelqueue) { | 
					
						
							|  |  |  | 		/* We had a glare on the hangup.  Forget all this business,
 | 
					
						
							|  |  |  | 		return and destroy p.  */ | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		ast_mutex_unlock(&p->lock); | 
					
						
							| 
									
										
										
										
											2004-06-22 17:42:14 +00:00
										 |  |  | 		ast_mutex_destroy(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-07-01 03:32:14 +00:00
										 |  |  | 		free(p); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-12-02 15:52:37 +00:00
										 |  |  | 	if (!other) { | 
					
						
							|  |  |  | 		p->glaredetect = 0; | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	if (ast_mutex_trylock(&other->lock)) { | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		/* Failed to lock.  Release main lock and try again */ | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		ast_mutex_unlock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-08-13 17:32:44 +00:00
										 |  |  | 		if (us) { | 
					
						
							|  |  |  | 			if (ast_mutex_unlock(&us->lock)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "%s wasn't locked while sending %d/%d\n", | 
					
						
							|  |  |  | 					us->name, f->frametype, f->subclass); | 
					
						
							|  |  |  | 				us = NULL; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		/* Wait just a bit */ | 
					
						
							|  |  |  | 		usleep(1); | 
					
						
							| 
									
										
										
										
											2003-08-08 03:01:29 +00:00
										 |  |  | 		/* Only we can destroy ourselves, so we can't disappear here */ | 
					
						
							| 
									
										
										
										
											2003-08-08 18:09:24 +00:00
										 |  |  | 		if (us) | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 			ast_mutex_lock(&us->lock); | 
					
						
							|  |  |  | 		ast_mutex_lock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		goto retrylock; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-04-06 22:17:32 +00:00
										 |  |  | 	ast_queue_frame(other, f); | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_unlock(&other->lock); | 
					
						
							| 
									
										
										
										
											2003-07-01 03:32:14 +00:00
										 |  |  | 	p->glaredetect = 0; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int local_answer(struct ast_channel *ast) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct local_pvt *p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2004-06-22 04:54:52 +00:00
										 |  |  | 	int isoutbound; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	int res = -1; | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_lock(&p->lock); | 
					
						
							| 
									
										
										
										
											2004-06-22 04:54:52 +00:00
										 |  |  | 	isoutbound = IS_OUTBOUND(ast, p); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	if (isoutbound) { | 
					
						
							|  |  |  | 		/* Pass along answer since somebody answered us */ | 
					
						
							|  |  |  | 		struct ast_frame answer = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER }; | 
					
						
							| 
									
										
										
										
											2003-08-08 18:09:24 +00:00
										 |  |  | 		res = local_queue_frame(p, isoutbound, &answer, ast); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Huh?  Local is being asked to answer?\n"); | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_unlock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-06 06:11:25 +00:00
										 |  |  | static void check_bridge(struct local_pvt *p, int isoutbound) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-08 02:11:56 +00:00
										 |  |  | 	if (p->alreadymasqed || p->nooptimization) | 
					
						
							| 
									
										
										
										
											2003-04-06 06:11:25 +00:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2005-10-19 03:45:49 +00:00
										 |  |  | 	if (!p->chan || !p->owner) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	if (isoutbound&& p->chan->_bridge /* Not ast_bridged_channel!  Only go one step! */ && !p->owner->readq) { | 
					
						
							| 
									
										
										
										
											2003-04-06 06:11:25 +00:00
										 |  |  | 		/* Masquerade bridged channel into owner */ | 
					
						
							| 
									
										
										
										
											2003-08-14 13:12:39 +00:00
										 |  |  | 		/* Lock everything we need, one by one, and give up if
 | 
					
						
							|  |  |  | 		   we can't get everything.  Remember, we'll get another | 
					
						
							|  |  |  | 		   chance in just a little bit */ | 
					
						
							| 
									
										
										
										
											2005-02-14 23:20:01 +00:00
										 |  |  | 		if (!ast_mutex_trylock(&(p->chan->_bridge)->lock)) { | 
					
						
							| 
									
										
										
										
											2005-10-19 03:45:49 +00:00
										 |  |  | 			if (!p->chan->_bridge->_softhangup) { | 
					
						
							|  |  |  | 				if (!ast_mutex_trylock(&p->owner->lock)) { | 
					
						
							|  |  |  | 					if (!p->owner->_softhangup) { | 
					
						
							|  |  |  | 						ast_channel_masquerade(p->owner, p->chan->_bridge); | 
					
						
							|  |  |  | 						p->alreadymasqed = 1; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					ast_mutex_unlock(&p->owner->lock); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				ast_mutex_unlock(&(p->chan->_bridge)->lock); | 
					
						
							| 
									
										
										
										
											2003-08-14 13:12:39 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	} else if (!isoutbound && p->owner && p->owner->_bridge && p->chan && !p->chan->readq) { | 
					
						
							| 
									
										
										
										
											2003-04-06 06:11:25 +00:00
										 |  |  | 		/* Masquerade bridged channel into chan */ | 
					
						
							| 
									
										
										
										
											2005-02-14 23:20:01 +00:00
										 |  |  | 		if (!ast_mutex_trylock(&(p->owner->_bridge)->lock)) { | 
					
						
							| 
									
										
										
										
											2005-10-19 03:45:49 +00:00
										 |  |  | 			if (!p->owner->_bridge->_softhangup) { | 
					
						
							|  |  |  | 				if (!ast_mutex_trylock(&p->chan->lock)) { | 
					
						
							|  |  |  | 					if (!p->chan->_softhangup) { | 
					
						
							|  |  |  | 						ast_channel_masquerade(p->chan, p->owner->_bridge); | 
					
						
							|  |  |  | 						p->alreadymasqed = 1; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					ast_mutex_unlock(&p->chan->lock); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2003-08-14 13:12:39 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-02-14 23:20:01 +00:00
										 |  |  | 			ast_mutex_unlock(&(p->owner->_bridge)->lock); | 
					
						
							| 
									
										
										
										
											2003-08-14 13:12:39 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-04-06 06:11:25 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | static struct ast_frame  *local_read(struct ast_channel *ast) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static struct ast_frame null = { AST_FRAME_NULL, }; | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	return &null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int local_write(struct ast_channel *ast, struct ast_frame *f) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct local_pvt *p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	int res = -1; | 
					
						
							| 
									
										
										
										
											2004-06-22 04:54:52 +00:00
										 |  |  | 	int isoutbound; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Just queue for delivery to the other side */ | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_lock(&p->lock); | 
					
						
							| 
									
										
										
										
											2004-06-22 04:54:52 +00:00
										 |  |  | 	isoutbound = IS_OUTBOUND(ast, p); | 
					
						
							| 
									
										
										
										
											2005-03-05 04:35:23 +00:00
										 |  |  | 	if (f && (f->frametype == AST_FRAME_VOICE))  | 
					
						
							|  |  |  | 		check_bridge(p, isoutbound); | 
					
						
							|  |  |  | 	if (!p->alreadymasqed) | 
					
						
							|  |  |  | 		res = local_queue_frame(p, isoutbound, f, ast); | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		ast_log(LOG_DEBUG, "Not posting to queue since already masked on '%s'\n", ast->name); | 
					
						
							|  |  |  | 		res = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_unlock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-04-06 22:17:32 +00:00
										 |  |  | static int local_fixup(struct ast_channel *oldchan, struct ast_channel *newchan) | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct local_pvt *p = newchan->tech_pvt; | 
					
						
							| 
									
										
										
										
											2004-04-06 22:17:32 +00:00
										 |  |  | 	ast_mutex_lock(&p->lock); | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	if ((p->owner != oldchan) && (p->chan != oldchan)) { | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Old channel wasn't %p but was %p/%p\n", oldchan, p->owner, p->chan); | 
					
						
							| 
									
										
										
										
											2004-04-06 22:17:32 +00:00
										 |  |  | 		ast_mutex_unlock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (p->owner == oldchan) | 
					
						
							|  |  |  | 		p->owner = newchan; | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 		p->chan = newchan; | 
					
						
							| 
									
										
										
										
											2004-04-06 22:17:32 +00:00
										 |  |  | 	ast_mutex_unlock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int local_indicate(struct ast_channel *ast, int condition) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct local_pvt *p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	int res = -1; | 
					
						
							|  |  |  | 	struct ast_frame f = { AST_FRAME_CONTROL, }; | 
					
						
							| 
									
										
										
										
											2004-06-22 04:54:52 +00:00
										 |  |  | 	int isoutbound; | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	/* Queue up a frame representing the indication as a control frame */ | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_lock(&p->lock); | 
					
						
							| 
									
										
										
										
											2004-06-22 04:54:52 +00:00
										 |  |  | 	isoutbound = IS_OUTBOUND(ast, p); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	f.subclass = condition; | 
					
						
							| 
									
										
										
										
											2003-08-08 18:09:24 +00:00
										 |  |  | 	res = local_queue_frame(p, isoutbound, &f, ast); | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_unlock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int local_digit(struct ast_channel *ast, char digit) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct local_pvt *p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	int res = -1; | 
					
						
							|  |  |  | 	struct ast_frame f = { AST_FRAME_DTMF, }; | 
					
						
							| 
									
										
										
										
											2004-06-22 04:54:52 +00:00
										 |  |  | 	int isoutbound; | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_lock(&p->lock); | 
					
						
							| 
									
										
										
										
											2004-06-22 04:54:52 +00:00
										 |  |  | 	isoutbound = IS_OUTBOUND(ast, p); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	f.subclass = digit; | 
					
						
							| 
									
										
										
										
											2003-08-08 18:09:24 +00:00
										 |  |  | 	res = local_queue_frame(p, isoutbound, &f, ast); | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_unlock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 20:48:24 +00:00
										 |  |  | static int local_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen) | 
					
						
							| 
									
										
										
										
											2005-02-28 06:06:42 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct local_pvt *p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2005-02-28 06:06:42 +00:00
										 |  |  | 	int res = -1; | 
					
						
							|  |  |  | 	struct ast_frame f = { AST_FRAME_HTML, }; | 
					
						
							|  |  |  | 	int isoutbound; | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-02-28 06:06:42 +00:00
										 |  |  | 	ast_mutex_lock(&p->lock); | 
					
						
							|  |  |  | 	isoutbound = IS_OUTBOUND(ast, p); | 
					
						
							|  |  |  | 	f.subclass = subclass; | 
					
						
							| 
									
										
										
										
											2005-03-28 20:48:24 +00:00
										 |  |  | 	f.data = (char *)data; | 
					
						
							| 
									
										
										
										
											2005-02-28 06:06:42 +00:00
										 |  |  | 	f.datalen = datalen; | 
					
						
							|  |  |  | 	res = local_queue_frame(p, isoutbound, &f, ast); | 
					
						
							|  |  |  | 	ast_mutex_unlock(&p->lock); | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-20 00:18:42 +00:00
										 |  |  | /*! \brief Initiate new call, part of PBX interface 
 | 
					
						
							|  |  |  |  * 	dest is the dial string */ | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | static int local_call(struct ast_channel *ast, char *dest, int timeout) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct local_pvt *p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2003-08-19 19:36:52 +00:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
											  
											
												Merged revisions 7265-7266,7268-7275 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r7265 | oej | 2005-12-01 17:18:14 -0600 (Thu, 01 Dec 2005) | 2 lines
Changing bug report address to the Asterisk issue tracker
........
r7266 | kpfleming | 2005-12-01 17:18:29 -0600 (Thu, 01 Dec 2005) | 3 lines
Makefile 'update' target now supports updating from Subversion repositories (issue #5875)
remove support for 'patches' subdirectory, it's no longer useful
........
r7268 | kpfleming | 2005-12-01 17:34:58 -0600 (Thu, 01 Dec 2005) | 2 lines
ensure channel's scheduling context is freed (issue #5788)
........
r7269 | kpfleming | 2005-12-01 17:49:44 -0600 (Thu, 01 Dec 2005) | 2 lines
don't block waiting for the Festival server forever when it goes away (issue #5882)
........
r7270 | kpfleming | 2005-12-01 18:26:12 -0600 (Thu, 01 Dec 2005) | 2 lines
allow variables to exist on both 'halves' of the Local channel (issue #5810)
........
r7271 | kpfleming | 2005-12-01 18:28:48 -0600 (Thu, 01 Dec 2005) | 2 lines
protect agent_bridgedchannel() from segfaulting when there is no bridged channel (issue #5879)
........
r7272 | kpfleming | 2005-12-01 18:39:00 -0600 (Thu, 01 Dec 2005) | 3 lines
properly handle password changes when mailbox is last line of config file and not followed by a newline (issue #5870)
reformat password changing code to conform to coding guidelines (issue #5870)
........
r7273 | kpfleming | 2005-12-01 18:42:40 -0600 (Thu, 01 Dec 2005) | 2 lines
allow previous context-searching behavior to be used if desired (issue #5899)
........
r7274 | kpfleming | 2005-12-01 18:51:15 -0600 (Thu, 01 Dec 2005) | 2 lines
inherit channel variables into channels created by Page() application (issue #5888)
........
r7275 | oej | 2005-12-01 18:52:13 -0600 (Thu, 01 Dec 2005) | 2 lines
Bug #5907. Improve SIP INFO DTMF debugging output. (1.2 & Trunk)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7276 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2005-12-02 01:01:11 +00:00
										 |  |  | 	struct ast_var_t *varptr = NULL, *new; | 
					
						
							|  |  |  | 	size_t len, namelen; | 
					
						
							| 
									
										
										
										
											2003-08-19 19:36:52 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	ast_mutex_lock(&p->lock); | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-11 01:20:29 +00:00
										 |  |  | 	p->chan->cid.cid_num = ast_strdup(p->owner->cid.cid_num); | 
					
						
							|  |  |  | 	p->chan->cid.cid_name = ast_strdup(p->owner->cid.cid_name); | 
					
						
							|  |  |  | 	p->chan->cid.cid_rdnis = ast_strdup(p->owner->cid.cid_rdnis); | 
					
						
							|  |  |  | 	p->chan->cid.cid_ani = ast_strdup(p->owner->cid.cid_ani); | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-05-17 15:52:33 +00:00
										 |  |  | 	strncpy(p->chan->language, p->owner->language, sizeof(p->chan->language) - 1); | 
					
						
							| 
									
										
										
										
											2004-07-12 14:46:10 +00:00
										 |  |  | 	strncpy(p->chan->accountcode, p->owner->accountcode, sizeof(p->chan->accountcode) - 1); | 
					
						
							|  |  |  | 	p->chan->cdrflags = p->owner->cdrflags; | 
					
						
							| 
									
										
											  
											
												Merged revisions 7265-7266,7268-7275 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r7265 | oej | 2005-12-01 17:18:14 -0600 (Thu, 01 Dec 2005) | 2 lines
Changing bug report address to the Asterisk issue tracker
........
r7266 | kpfleming | 2005-12-01 17:18:29 -0600 (Thu, 01 Dec 2005) | 3 lines
Makefile 'update' target now supports updating from Subversion repositories (issue #5875)
remove support for 'patches' subdirectory, it's no longer useful
........
r7268 | kpfleming | 2005-12-01 17:34:58 -0600 (Thu, 01 Dec 2005) | 2 lines
ensure channel's scheduling context is freed (issue #5788)
........
r7269 | kpfleming | 2005-12-01 17:49:44 -0600 (Thu, 01 Dec 2005) | 2 lines
don't block waiting for the Festival server forever when it goes away (issue #5882)
........
r7270 | kpfleming | 2005-12-01 18:26:12 -0600 (Thu, 01 Dec 2005) | 2 lines
allow variables to exist on both 'halves' of the Local channel (issue #5810)
........
r7271 | kpfleming | 2005-12-01 18:28:48 -0600 (Thu, 01 Dec 2005) | 2 lines
protect agent_bridgedchannel() from segfaulting when there is no bridged channel (issue #5879)
........
r7272 | kpfleming | 2005-12-01 18:39:00 -0600 (Thu, 01 Dec 2005) | 3 lines
properly handle password changes when mailbox is last line of config file and not followed by a newline (issue #5870)
reformat password changing code to conform to coding guidelines (issue #5870)
........
r7273 | kpfleming | 2005-12-01 18:42:40 -0600 (Thu, 01 Dec 2005) | 2 lines
allow previous context-searching behavior to be used if desired (issue #5899)
........
r7274 | kpfleming | 2005-12-01 18:51:15 -0600 (Thu, 01 Dec 2005) | 2 lines
inherit channel variables into channels created by Page() application (issue #5888)
........
r7275 | oej | 2005-12-01 18:52:13 -0600 (Thu, 01 Dec 2005) | 2 lines
Bug #5907. Improve SIP INFO DTMF debugging output. (1.2 & Trunk)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7276 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2005-12-02 01:01:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* copy the channel variables from the incoming channel to the outgoing channel */ | 
					
						
							|  |  |  | 	/* Note that due to certain assumptions, they MUST be in the same order */ | 
					
						
							|  |  |  | 	AST_LIST_TRAVERSE(&p->owner->varshead, varptr, entries) { | 
					
						
							|  |  |  | 		namelen = strlen(varptr->name); | 
					
						
							|  |  |  | 		len = sizeof(struct ast_var_t) + namelen + strlen(varptr->value) + 2; | 
					
						
							| 
									
										
										
										
											2006-01-11 01:20:29 +00:00
										 |  |  | 		if ((new = ast_calloc(1, len))) { | 
					
						
							| 
									
										
											  
											
												Merged revisions 7265-7266,7268-7275 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r7265 | oej | 2005-12-01 17:18:14 -0600 (Thu, 01 Dec 2005) | 2 lines
Changing bug report address to the Asterisk issue tracker
........
r7266 | kpfleming | 2005-12-01 17:18:29 -0600 (Thu, 01 Dec 2005) | 3 lines
Makefile 'update' target now supports updating from Subversion repositories (issue #5875)
remove support for 'patches' subdirectory, it's no longer useful
........
r7268 | kpfleming | 2005-12-01 17:34:58 -0600 (Thu, 01 Dec 2005) | 2 lines
ensure channel's scheduling context is freed (issue #5788)
........
r7269 | kpfleming | 2005-12-01 17:49:44 -0600 (Thu, 01 Dec 2005) | 2 lines
don't block waiting for the Festival server forever when it goes away (issue #5882)
........
r7270 | kpfleming | 2005-12-01 18:26:12 -0600 (Thu, 01 Dec 2005) | 2 lines
allow variables to exist on both 'halves' of the Local channel (issue #5810)
........
r7271 | kpfleming | 2005-12-01 18:28:48 -0600 (Thu, 01 Dec 2005) | 2 lines
protect agent_bridgedchannel() from segfaulting when there is no bridged channel (issue #5879)
........
r7272 | kpfleming | 2005-12-01 18:39:00 -0600 (Thu, 01 Dec 2005) | 3 lines
properly handle password changes when mailbox is last line of config file and not followed by a newline (issue #5870)
reformat password changing code to conform to coding guidelines (issue #5870)
........
r7273 | kpfleming | 2005-12-01 18:42:40 -0600 (Thu, 01 Dec 2005) | 2 lines
allow previous context-searching behavior to be used if desired (issue #5899)
........
r7274 | kpfleming | 2005-12-01 18:51:15 -0600 (Thu, 01 Dec 2005) | 2 lines
inherit channel variables into channels created by Page() application (issue #5888)
........
r7275 | oej | 2005-12-01 18:52:13 -0600 (Thu, 01 Dec 2005) | 2 lines
Bug #5907. Improve SIP INFO DTMF debugging output. (1.2 & Trunk)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7276 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2005-12-02 01:01:11 +00:00
										 |  |  | 			memcpy(new, varptr, len); | 
					
						
							|  |  |  | 			new->value = &(new->name[0]) + namelen + 1; | 
					
						
							|  |  |  | 			AST_LIST_INSERT_TAIL(&p->chan->varshead, new, entries); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-19 19:36:52 +00:00
										 |  |  | 	p->launchedpbx = 1; | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	/* Start switch on sub channel */ | 
					
						
							| 
									
										
										
										
											2003-08-19 19:36:52 +00:00
										 |  |  | 	res = ast_pbx_start(p->chan); | 
					
						
							|  |  |  | 	ast_mutex_unlock(&p->lock); | 
					
						
							|  |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | static void local_destroy(struct local_pvt *p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct local_pvt *cur, *prev = NULL; | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_lock(&locallock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	cur = locals; | 
					
						
							|  |  |  | 	while(cur) { | 
					
						
							|  |  |  | 		if (cur == p) { | 
					
						
							|  |  |  | 			if (prev) | 
					
						
							|  |  |  | 				prev->next = cur->next; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				locals = cur->next; | 
					
						
							| 
									
										
										
										
											2004-06-22 17:42:14 +00:00
										 |  |  | 			ast_mutex_destroy(cur); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 			free(cur); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		prev = cur; | 
					
						
							|  |  |  | 		cur = cur->next; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_unlock(&locallock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	if (!cur) | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Unable ot find local '%s@%s' in local list\n", p->exten, p->context); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-20 00:18:42 +00:00
										 |  |  | /*! \brief Hangup a call through the local proxy channel */ | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | static int local_hangup(struct ast_channel *ast) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct local_pvt *p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2004-06-22 04:54:52 +00:00
										 |  |  | 	int isoutbound; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; | 
					
						
							| 
									
										
										
										
											2003-04-08 13:50:04 +00:00
										 |  |  | 	struct local_pvt *cur, *prev=NULL; | 
					
						
							| 
									
										
										
										
											2003-05-19 23:37:38 +00:00
										 |  |  | 	struct ast_channel *ochan = NULL; | 
					
						
							| 
									
										
										
										
											2003-07-01 03:32:14 +00:00
										 |  |  | 	int glaredetect; | 
					
						
							| 
									
										
										
										
											2006-01-17 18:31:03 +00:00
										 |  |  | 	const char *status; | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_lock(&p->lock); | 
					
						
							| 
									
										
										
										
											2004-06-22 04:54:52 +00:00
										 |  |  | 	isoutbound = IS_OUTBOUND(ast, p); | 
					
						
							| 
									
										
										
										
											2003-08-19 19:36:52 +00:00
										 |  |  | 	if (isoutbound) { | 
					
						
							| 
									
										
										
										
											2006-01-13 18:23:30 +00:00
										 |  |  | 		status = pbx_builtin_getvar_helper(p->chan, "DIALSTATUS"); | 
					
						
							|  |  |  | 		if(status) | 
					
						
							|  |  |  | 			pbx_builtin_setvar_helper(p->owner, "CHANLOCALSTATUS", status); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		p->chan = NULL; | 
					
						
							| 
									
										
										
										
											2003-08-19 19:36:52 +00:00
										 |  |  | 		p->launchedpbx = 0; | 
					
						
							|  |  |  | 	} else | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		p->owner = NULL; | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	ast->tech_pvt = NULL; | 
					
						
							| 
									
										
										
										
											2003-05-19 23:37:38 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2004-12-11 04:46:49 +00:00
										 |  |  | 	ast_mutex_lock(&usecnt_lock); | 
					
						
							|  |  |  | 	usecnt--; | 
					
						
							|  |  |  | 	ast_mutex_unlock(&usecnt_lock); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	if (!p->owner && !p->chan) { | 
					
						
							|  |  |  | 		/* Okay, done with the private part now, too. */ | 
					
						
							| 
									
										
										
										
											2003-07-01 03:32:14 +00:00
										 |  |  | 		glaredetect = p->glaredetect; | 
					
						
							|  |  |  | 		/* If we have a queue holding, don't actually destroy p yet, but
 | 
					
						
							|  |  |  | 		   let local_queue do it. */ | 
					
						
							|  |  |  | 		if (p->glaredetect) | 
					
						
							|  |  |  | 			p->cancelqueue = 1; | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		ast_mutex_unlock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-04-08 13:50:04 +00:00
										 |  |  | 		/* Remove from list */ | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		ast_mutex_lock(&locallock); | 
					
						
							| 
									
										
										
										
											2003-04-08 13:50:04 +00:00
										 |  |  | 		cur = locals; | 
					
						
							|  |  |  | 		while(cur) { | 
					
						
							|  |  |  | 			if (cur == p) { | 
					
						
							|  |  |  | 				if (prev) | 
					
						
							| 
									
										
										
										
											2003-04-22 19:20:06 +00:00
										 |  |  | 					prev->next = cur->next; | 
					
						
							| 
									
										
										
										
											2003-04-08 13:50:04 +00:00
										 |  |  | 				else | 
					
						
							|  |  |  | 					locals = cur->next; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			prev = cur; | 
					
						
							|  |  |  | 			cur = cur->next; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		ast_mutex_unlock(&locallock); | 
					
						
							| 
									
										
										
										
											2004-11-06 21:33:01 +00:00
										 |  |  | 		/* Grab / release lock just in case */ | 
					
						
							|  |  |  | 		ast_mutex_lock(&p->lock); | 
					
						
							|  |  |  | 		ast_mutex_unlock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-04-08 13:50:04 +00:00
										 |  |  | 		/* And destroy */ | 
					
						
							| 
									
										
										
										
											2004-06-22 17:42:14 +00:00
										 |  |  | 		if (!glaredetect) { | 
					
						
							|  |  |  | 			ast_mutex_destroy(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-07-01 03:32:14 +00:00
										 |  |  | 			free(p); | 
					
						
							| 
									
										
										
										
											2004-06-22 17:42:14 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-08-19 19:36:52 +00:00
										 |  |  | 	if (p->chan && !p->launchedpbx) | 
					
						
							| 
									
										
										
										
											2003-05-19 23:37:38 +00:00
										 |  |  | 		/* Need to actually hangup since there is no PBX */ | 
					
						
							|  |  |  | 		ochan = p->chan; | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2003-08-11 22:17:46 +00:00
										 |  |  | 		local_queue_frame(p, isoutbound, &f, NULL); | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_unlock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-05-19 23:37:38 +00:00
										 |  |  | 	if (ochan) | 
					
						
							|  |  |  | 		ast_hangup(ochan); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-20 00:18:42 +00:00
										 |  |  | /*! \brief Create a call structure */ | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | static struct local_pvt *local_alloc(char *data, int format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct local_pvt *tmp; | 
					
						
							|  |  |  | 	char *c; | 
					
						
							| 
									
										
										
										
											2003-10-08 02:11:56 +00:00
										 |  |  | 	char *opts; | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-11 01:20:29 +00:00
										 |  |  | 	if (!(tmp = ast_calloc(1, sizeof(*tmp)))) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	ast_mutex_init(&tmp->lock); | 
					
						
							|  |  |  | 	strncpy(tmp->exten, data, sizeof(tmp->exten) - 1); | 
					
						
							|  |  |  | 	opts = strchr(tmp->exten, '/'); | 
					
						
							|  |  |  | 	if (opts) { | 
					
						
							|  |  |  | 		*opts='\0'; | 
					
						
							|  |  |  | 		opts++; | 
					
						
							|  |  |  | 		if (strchr(opts, 'n')) | 
					
						
							|  |  |  | 			tmp->nooptimization = 1; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-01-11 01:20:29 +00:00
										 |  |  | 	c = strchr(tmp->exten, '@'); | 
					
						
							|  |  |  | 	if (c) { | 
					
						
							|  |  |  | 		*c = '\0'; | 
					
						
							|  |  |  | 		c++; | 
					
						
							|  |  |  | 		strncpy(tmp->context, c, sizeof(tmp->context) - 1); | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		strncpy(tmp->context, "default", sizeof(tmp->context) - 1); | 
					
						
							|  |  |  | 	tmp->reqformat = format; | 
					
						
							|  |  |  | 	if (!ast_exists_extension(NULL, tmp->context, tmp->exten, 1, NULL)) { | 
					
						
							|  |  |  | 		ast_log(LOG_NOTICE, "No such extension/context %s@%s creating local channel\n", tmp->exten, tmp->context); | 
					
						
							|  |  |  | 		ast_mutex_destroy(&tmp->lock); | 
					
						
							|  |  |  | 		free(tmp); | 
					
						
							|  |  |  | 		tmp = NULL; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		/* Add to list */ | 
					
						
							|  |  |  | 		ast_mutex_lock(&locallock); | 
					
						
							|  |  |  | 		tmp->next = locals; | 
					
						
							|  |  |  | 		locals = tmp; | 
					
						
							|  |  |  | 		ast_mutex_unlock(&locallock); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	return tmp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-20 00:18:42 +00:00
										 |  |  | /*! \brief Start new local channel */ | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | static struct ast_channel *local_new(struct local_pvt *p, int state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_channel *tmp, *tmp2; | 
					
						
							| 
									
										
										
										
											2003-07-01 03:32:14 +00:00
										 |  |  | 	int randnum = rand() & 0xffff; | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	tmp = ast_channel_alloc(1); | 
					
						
							|  |  |  | 	tmp2 = ast_channel_alloc(1); | 
					
						
							|  |  |  | 	if (!tmp || !tmp2) { | 
					
						
							|  |  |  | 		if (tmp) | 
					
						
							|  |  |  | 			ast_channel_free(tmp); | 
					
						
							|  |  |  | 		if (tmp2) | 
					
						
							|  |  |  | 			ast_channel_free(tmp2); | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	}  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tmp2->tech = tmp->tech = &local_tech; | 
					
						
							|  |  |  | 	tmp->nativeformats = p->reqformat; | 
					
						
							|  |  |  | 	tmp2->nativeformats = p->reqformat; | 
					
						
							|  |  |  | 	snprintf(tmp->name, sizeof(tmp->name), "Local/%s@%s-%04x,1", p->exten, p->context, randnum); | 
					
						
							|  |  |  | 	snprintf(tmp2->name, sizeof(tmp2->name), "Local/%s@%s-%04x,2", p->exten, p->context, randnum); | 
					
						
							|  |  |  | 	tmp->type = type; | 
					
						
							|  |  |  | 	tmp2->type = type; | 
					
						
							|  |  |  | 	ast_setstate(tmp, state); | 
					
						
							|  |  |  | 	ast_setstate(tmp2, AST_STATE_RING); | 
					
						
							|  |  |  | 	tmp->writeformat = p->reqformat; | 
					
						
							|  |  |  | 	tmp2->writeformat = p->reqformat; | 
					
						
							|  |  |  | 	tmp->rawwriteformat = p->reqformat; | 
					
						
							|  |  |  | 	tmp2->rawwriteformat = p->reqformat; | 
					
						
							|  |  |  | 	tmp->readformat = p->reqformat; | 
					
						
							|  |  |  | 	tmp2->readformat = p->reqformat; | 
					
						
							|  |  |  | 	tmp->rawreadformat = p->reqformat; | 
					
						
							|  |  |  | 	tmp2->rawreadformat = p->reqformat; | 
					
						
							|  |  |  | 	tmp->tech_pvt = p; | 
					
						
							|  |  |  | 	tmp2->tech_pvt = p; | 
					
						
							|  |  |  | 	p->owner = tmp; | 
					
						
							|  |  |  | 	p->chan = tmp2; | 
					
						
							|  |  |  | 	ast_mutex_lock(&usecnt_lock); | 
					
						
							|  |  |  | 	usecnt++; | 
					
						
							|  |  |  | 	usecnt++; | 
					
						
							|  |  |  | 	ast_mutex_unlock(&usecnt_lock); | 
					
						
							|  |  |  | 	ast_update_use_count(); | 
					
						
							|  |  |  | 	ast_copy_string(tmp->context, p->context, sizeof(tmp->context)); | 
					
						
							|  |  |  | 	ast_copy_string(tmp2->context, p->context, sizeof(tmp2->context)); | 
					
						
							|  |  |  | 	ast_copy_string(tmp2->exten, p->exten, sizeof(tmp->exten)); | 
					
						
							|  |  |  | 	tmp->priority = 1; | 
					
						
							|  |  |  | 	tmp2->priority = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	return tmp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-20 00:18:42 +00:00
										 |  |  | /*! \brief Part of PBX interface */ | 
					
						
							| 
									
										
										
										
											2004-10-26 22:25:43 +00:00
										 |  |  | static struct ast_channel *local_request(const char *type, int format, void *data, int *cause) | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct local_pvt *p; | 
					
						
							|  |  |  | 	struct ast_channel *chan = NULL; | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	p = local_alloc(data, format); | 
					
						
							| 
									
										
										
										
											2003-04-06 06:11:25 +00:00
										 |  |  | 	if (p) | 
					
						
							|  |  |  | 		chan = local_new(p, AST_STATE_DOWN); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	return chan; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-20 00:18:42 +00:00
										 |  |  | /*! \brief CLI command "local show channels" */ | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | static int locals_show(int fd, int argc, char **argv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct local_pvt *p; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-20 13:26:52 +00:00
										 |  |  | 	if (argc != 3) | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		return RESULT_SHOWUSAGE; | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_lock(&locallock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	p = locals; | 
					
						
							|  |  |  | 	while(p) { | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		ast_mutex_lock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		ast_cli(fd, "%s -- %s@%s\n", p->owner ? p->owner->name : "<unowned>", p->exten, p->context); | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		ast_mutex_unlock(&p->lock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		p = p->next; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!locals) | 
					
						
							|  |  |  | 		ast_cli(fd, "No local channels in use\n"); | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_unlock(&locallock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	return RESULT_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char show_locals_usage[] =  | 
					
						
							| 
									
										
										
										
											2004-03-20 13:26:52 +00:00
										 |  |  | "Usage: local show channels\n" | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | "       Provides summary information on active local proxy channels.\n"; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static struct ast_cli_entry cli_show_locals = { | 
					
						
							| 
									
										
										
										
											2004-03-20 13:26:52 +00:00
										 |  |  | 	{ "local", "show", "channels", NULL }, locals_show,  | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	"Show status of local channels", show_locals_usage, NULL }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-20 00:18:42 +00:00
										 |  |  | /*! \brief Load module into PBX, register channel */ | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | int load_module() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	/* Make sure we can register our channel type */ | 
					
						
							|  |  |  | 	if (ast_channel_register(&local_tech)) { | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		ast_log(LOG_ERROR, "Unable to register channel class %s\n", type); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ast_cli_register(&cli_show_locals); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-20 00:18:42 +00:00
										 |  |  | /*! \brief Reload module */ | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | int reload() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-20 00:18:42 +00:00
										 |  |  | /*! \brief Unload the local proxy channel from Asterisk */ | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | int unload_module() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct local_pvt *p; | 
					
						
							| 
									
										
										
										
											2005-07-25 18:09:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	/* First, take us out of the channel loop */ | 
					
						
							|  |  |  | 	ast_cli_unregister(&cli_show_locals); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	ast_channel_unregister(&local_tech); | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	if (!ast_mutex_lock(&locallock)) { | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 		/* Hangup all interfaces if they have an owner */ | 
					
						
							|  |  |  | 		p = locals; | 
					
						
							|  |  |  | 		while(p) { | 
					
						
							|  |  |  | 			if (p->owner) | 
					
						
							|  |  |  | 				ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); | 
					
						
							|  |  |  | 			p = p->next; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		locals = NULL; | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		ast_mutex_unlock(&locallock); | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Unable to lock the monitor\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	}		 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int usecount() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-06-24 02:15:04 +00:00
										 |  |  | 	return usecnt; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | char *key() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return ASTERISK_GPL_KEY; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | char *description() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	return (char *) desc; | 
					
						
							| 
									
										
										
										
											2003-04-06 02:41:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 |