[asterisk-commits] file: branch file/audiohook-chains r114694 - in /team/file/audiohook-chains: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Apr 26 19:22:49 CDT 2008


Author: file
Date: Sat Apr 26 19:22:49 2008
New Revision: 114694

URL: http://svn.digium.com/view/asterisk?view=rev&rev=114694
Log:
Merged revisions 114674,114676,114678,114683,114690,114692 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
r114674 | russell | 2008-04-25 19:00:35 -0300 (Fri, 25 Apr 2008) | 11 lines

Merged revisions 114673 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r114673 | russell | 2008-04-25 16:54:40 -0500 (Fri, 25 Apr 2008) | 3 lines

Use consistent logic for checking to see if a call number has been chosen yet.
Also, remove some redundant logic I recently added in a fix.

........

................
r114676 | russell | 2008-04-25 19:04:46 -0300 (Fri, 25 Apr 2008) | 7 lines

Lock the channel around datastore access

(closes issue #12527)
Reported by: mnicholson
Patches:
      pbx_lua4.diff uploaded by mnicholson (license 96)

................
r114678 | mmichelson | 2008-04-25 19:24:32 -0300 (Fri, 25 Apr 2008) | 11 lines

Adding a new option, 'B' to app_chanspy. This option allows the spy to
barge on the call. It is like the existing whisper option, except that
it allows the spy to talk to both sides of the conversation on which
he is spying.

This feature has existed in Switchvox, and this merges the functionality
into Asterisk.

(AST-32)


................
r114683 | tilghman | 2008-04-25 23:48:56 -0300 (Fri, 25 Apr 2008) | 8 lines

Add 'sip qualify peer <peer>' command (with AMI SIPqualifypeer)
(closes issue #12524)
 Reported by: ctooley
 Patches: 
       sip_qualify_peer.diff.2 uploaded by ctooley (license 136)
       some modifications for trunk by Corydon76
 Tested by: Corydon76

................
r114690 | tilghman | 2008-04-26 10:17:19 -0300 (Sat, 26 Apr 2008) | 14 lines

Merged revisions 114689 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r114689 | tilghman | 2008-04-26 08:15:21 -0500 (Sat, 26 Apr 2008) | 6 lines

Clicking forward without selecting a message leaves an errant .lock file.
(closes issue #12528)
 Reported by: pukepail
 Patches: 
       patch.diff uploaded by pukepail (license 431)

........

................
r114692 | tilghman | 2008-04-26 12:08:51 -0300 (Sat, 26 Apr 2008) | 2 lines

Unleak reference

................

Modified:
    team/file/audiohook-chains/   (props changed)
    team/file/audiohook-chains/CHANGES
    team/file/audiohook-chains/apps/app_chanspy.c
    team/file/audiohook-chains/channels/chan_iax2.c
    team/file/audiohook-chains/channels/chan_sip.c
    team/file/audiohook-chains/contrib/scripts/vmail.cgi
    team/file/audiohook-chains/pbx/pbx_lua.c

Propchange: team/file/audiohook-chains/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Propchange: team/file/audiohook-chains/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Sat Apr 26 19:22:49 2008
@@ -1,1 +1,1 @@
-/trunk:1-114669
+/trunk:1-114693

Modified: team/file/audiohook-chains/CHANGES
URL: http://svn.digium.com/view/asterisk/team/file/audiohook-chains/CHANGES?view=diff&rev=114694&r1=114693&r2=114694
==============================================================================
--- team/file/audiohook-chains/CHANGES (original)
+++ team/file/audiohook-chains/CHANGES Sat Apr 26 19:22:49 2008
@@ -33,6 +33,9 @@
  * ChanSpy and ExtenSpy have a new option, 's' which suppresses speaking the
    technology name (e.g. SIP, IAX, etc) of the channel being spied on.
  * The Jack application now has a c() option to supply a custom client name.
+ * Chanspy has a new option, 'B', which can be used to "barge" on a call. This is
+   like the pre-existing whisper mode, except that the spy can also talk to the
+   participant on the bridged channel as well.
 
 SIP Changes
 -----------

Modified: team/file/audiohook-chains/apps/app_chanspy.c
URL: http://svn.digium.com/view/asterisk/team/file/audiohook-chains/apps/app_chanspy.c?view=diff&rev=114694&r1=114693&r2=114694
==============================================================================
--- team/file/audiohook-chains/apps/app_chanspy.c (original)
+++ team/file/audiohook-chains/apps/app_chanspy.c Sat Apr 26 19:22:49 2008
@@ -148,6 +148,7 @@
 	OPTION_EXIT      = (1 << 8),    /* Exit to a valid single digit extension */
 	OPTION_ENFORCED  = (1 << 9),    /* Enforced mode */
 	OPTION_NOTECH    = (1 << 10),   /* Skip technology name playback */
+	OPTION_BARGE     = (1 << 11),   /* Barge mode (whisper to both channels) */
 } chanspy_opt_flags;
 
 enum {
@@ -161,6 +162,7 @@
 AST_APP_OPTIONS(spy_opts, {
 	AST_APP_OPTION('q', OPTION_QUIET),
 	AST_APP_OPTION('b', OPTION_BRIDGED),
+	AST_APP_OPTION('B', OPTION_BARGE),
 	AST_APP_OPTION('w', OPTION_WHISPER),
 	AST_APP_OPTION('W', OPTION_PRIVATE),
 	AST_APP_OPTION_ARG('v', OPTION_VOLUME, OPT_ARG_VOLUME),
@@ -177,6 +179,7 @@
 	/* spy data */
 	struct ast_audiohook spy_audiohook;
 	struct ast_audiohook whisper_audiohook;
+	struct ast_audiohook bridge_whisper_audiohook;
 	int fd;
 	int volfactor;
 };
@@ -230,7 +233,7 @@
 	.generate = spy_generate,
 };
 
-static int start_spying(struct ast_channel *chan, const char *spychan_name, struct ast_audiohook *audiohook) 
+static int start_spying(struct ast_channel *chan, const char *spychan_name, struct ast_audiohook *audiohook)
 {
 	int res = 0;
 	struct ast_channel *peer = NULL;
@@ -296,10 +299,15 @@
 		return 0;
 	}
 
-	if (ast_test_flag(flags, OPTION_WHISPER)) {
+	if (ast_test_flag(flags, OPTION_BARGE)) {
+  		ast_audiohook_init(&csth.whisper_audiohook, AST_AUDIOHOOK_TYPE_WHISPER, "ChanSpy");
+		ast_audiohook_init(&csth.bridge_whisper_audiohook, AST_AUDIOHOOK_TYPE_WHISPER, "Chanspy");
+  		start_spying(spyee, spyer_name, &csth.whisper_audiohook); /* Unlocks spyee */
+		start_spying(ast_bridged_channel(spyee), spyer_name, &csth.bridge_whisper_audiohook);
+	} else if (ast_test_flag(flags, OPTION_WHISPER)) {
 		ast_audiohook_init(&csth.whisper_audiohook, AST_AUDIOHOOK_TYPE_WHISPER, "ChanSpy");
-		start_spying(spyee, spyer_name, &csth.whisper_audiohook);
-	}
+		start_spying(spyee, spyer_name, &csth.whisper_audiohook); /* Unlocks spyee */
+  	}
 
 	ast_channel_unlock(spyee);
 	spyee = NULL;
@@ -338,7 +346,16 @@
 			break;
 		}
 
-		if (ast_test_flag(flags, OPTION_WHISPER) && f->frametype == AST_FRAME_VOICE) {
+		if (ast_test_flag(flags, OPTION_BARGE) && f->frametype == AST_FRAME_VOICE) {
+			ast_audiohook_lock(&csth.whisper_audiohook);
+			ast_audiohook_lock(&csth.bridge_whisper_audiohook);
+			ast_audiohook_write_frame(&csth.whisper_audiohook, AST_AUDIOHOOK_DIRECTION_WRITE, f);
+			ast_audiohook_write_frame(&csth.bridge_whisper_audiohook, AST_AUDIOHOOK_DIRECTION_WRITE, f);
+			ast_audiohook_unlock(&csth.whisper_audiohook);
+			ast_audiohook_unlock(&csth.bridge_whisper_audiohook);
+			ast_frfree(f);
+			continue;
+		} else if (ast_test_flag(flags, OPTION_WHISPER) && f->frametype == AST_FRAME_VOICE) {
 			ast_audiohook_lock(&csth.whisper_audiohook);
 			ast_audiohook_write_frame(&csth.whisper_audiohook, AST_AUDIOHOOK_DIRECTION_WRITE, f);
 			ast_audiohook_unlock(&csth.whisper_audiohook);
@@ -400,7 +417,16 @@
 	else
 		ast_deactivate_generator(chan);
 
-	if (ast_test_flag(flags, OPTION_WHISPER)) {
+	if (ast_test_flag(flags, OPTION_BARGE)) {
+		ast_audiohook_lock(&csth.whisper_audiohook);
+		ast_audiohook_detach(&csth.whisper_audiohook);
+		ast_audiohook_unlock(&csth.whisper_audiohook);
+		ast_audiohook_destroy(&csth.whisper_audiohook);
+		ast_audiohook_lock(&csth.bridge_whisper_audiohook);
+		ast_audiohook_detach(&csth.bridge_whisper_audiohook);
+		ast_audiohook_unlock(&csth.bridge_whisper_audiohook);
+		ast_audiohook_destroy(&csth.bridge_whisper_audiohook);
+	} else if (ast_test_flag(flags, OPTION_WHISPER)) {
 		ast_audiohook_lock(&csth.whisper_audiohook);
 		ast_audiohook_detach(&csth.whisper_audiohook);
 		ast_audiohook_unlock(&csth.whisper_audiohook);

Modified: team/file/audiohook-chains/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/file/audiohook-chains/channels/chan_iax2.c?view=diff&rev=114694&r1=114693&r2=114694
==============================================================================
--- team/file/audiohook-chains/channels/chan_iax2.c (original)
+++ team/file/audiohook-chains/channels/chan_iax2.c Sat Apr 26 19:22:49 2008
@@ -1499,7 +1499,7 @@
 	char host[80];
 
 	if (new <= NEW_ALLOW) {
-		for (x=1;(res < 1) && (x<maxnontrunkcall);x++) {
+		for (x = 1; !res && x < maxnontrunkcall; x++) {
 			ast_mutex_lock(&iaxsl[x]);
 			if (iaxs[x]) {
 				/* Look for an exact match */
@@ -1507,10 +1507,10 @@
 					res = x;
 				}
 			}
-			if (!res || (res && !return_locked))
+			if (!res || !return_locked)
 				ast_mutex_unlock(&iaxsl[x]);
 		}
-		for (x=TRUNK_CALL_START;(res < 1) && (x<maxtrunkcall);x++) {
+		for (x = TRUNK_CALL_START; !res && x < maxtrunkcall; x++) {
 			ast_mutex_lock(&iaxsl[x]);
 			if (iaxs[x]) {
 				/* Look for an exact match */
@@ -1518,11 +1518,11 @@
 					res = x;
 				}
 			}
-			if (!res || (res && !return_locked))
+			if (!res || !return_locked)
 				ast_mutex_unlock(&iaxsl[x]);
 		}
 	}
-	if ((res < 1) && (new >= NEW_ALLOW)) {
+	if (!res && (new >= NEW_ALLOW)) {
 		int start, found = 0;
 
 		/* It may seem odd that we look through the peer list for a name for

Modified: team/file/audiohook-chains/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/file/audiohook-chains/channels/chan_sip.c?view=diff&rev=114694&r1=114693&r2=114694
==============================================================================
--- team/file/audiohook-chains/channels/chan_sip.c (original)
+++ team/file/audiohook-chains/channels/chan_sip.c Sat Apr 26 19:22:49 2008
@@ -1944,7 +1944,7 @@
 static int cb_extensionstate(char *context, char* exten, int state, void *data);
 static int sip_devicestate(void *data);
 static int sip_poke_noanswer(const void *data);
-static int sip_poke_peer(struct sip_peer *peer);
+static int sip_poke_peer(struct sip_peer *peer, int force);
 static void sip_poke_all_peers(void);
 static void sip_peer_hold(struct sip_pvt *p, int hold);
 static void mwi_event_cb(const struct ast_event *, void *);
@@ -1973,6 +1973,8 @@
 static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[]);
 static char *sip_show_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *sip_show_user(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+static char *_sip_qualify_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[]);
+static char *sip_qualify_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *sip_show_registry(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *sip_unregister(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
@@ -2024,7 +2026,6 @@
 static void sip_destroy_peer_fn(void *peer);
 static void sip_destroy_user(struct sip_user *user);
 static void sip_destroy_user_fn(void *user);
-static int sip_poke_peer(struct sip_peer *peer);
 static void set_peer_defaults(struct sip_peer *peer);
 static struct sip_peer *temp_peer(const char *name);
 static void register_peer_exten(struct sip_peer *peer, int onoff);
@@ -9977,7 +9978,7 @@
 	struct sip_peer *peer = (struct sip_peer *)data;
 
 	peer->pokeexpire = -1;
-	sip_poke_peer(peer);
+	sip_poke_peer(peer, 0);
 	return 0;
 }
 
@@ -10030,8 +10031,9 @@
 	if (sipsock < 0) {
 		/* SIP isn't up yet, so schedule a poke only, pretty soon */
 		AST_SCHED_REPLACE(peer->pokeexpire, sched, ast_random() % 5000 + 1, sip_poke_peer_s, peer);
-	} else
-		sip_poke_peer(peer);
+	} else {
+		sip_poke_peer(peer, 0);
+	}
 	AST_SCHED_REPLACE(peer->expire, sched, (expiry + 10) * 1000, expire_register, peer);
 	register_peer_exten(peer, TRUE);
 }
@@ -10236,7 +10238,7 @@
 
 	/* Is this a new IP address for us? */
 	if (inaddrcmp(&peer->addr, &oldsin)) {
-		sip_poke_peer(peer);
+		sip_poke_peer(peer, 0);
 		ast_verb(3, "Registered SIP '%s' at %s port %d expires %d\n", peer->name, ast_inet_ntoa(peer->addr.sin_addr), ntohs(peer->addr.sin_port), expiry);
 		register_peer_exten(peer, TRUE);
 	}
@@ -13314,6 +13316,65 @@
 		return complete_sip_show_peer(a->line, a->word, a->pos, a->n);
 	}
 	return _sip_show_peer(0, a->fd, NULL, NULL, a->argc, (const char **) a->argv);
+}
+
+/*! \brief Show one peer in detail (main function) */
+static char *_sip_qualify_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[])
+{
+	struct sip_peer *peer;
+	int load_realtime;
+
+	if (argc < 4)
+		return CLI_SHOWUSAGE;
+
+	load_realtime = (argc == 5 && !strcmp(argv[4], "load")) ? TRUE : FALSE;
+	if ((peer = find_peer(argv[3], NULL, load_realtime))) {
+		sip_poke_peer(peer, 1);
+		unref_peer(peer, "qualify: done with peer");
+	} else if (type == 0) {
+		ast_cli(fd, "Peer '%s' not found\n", argv[3]);
+	} else {
+		astman_send_error(s, m, "Peer not found\n");
+	}
+	return CLI_SUCCESS;
+}
+
+/*! \brief Qualify SIP peers in the manager API  */
+static int manager_sip_qualify_peer(struct mansession *s, const struct message *m)
+{
+	const char *a[4];
+	const char *peer;
+
+	peer = astman_get_header(m, "Peer");
+	if (ast_strlen_zero(peer)) {
+		astman_send_error(s, m, "Peer: <name> missing.\n");
+		return 0;
+	}
+	a[0] = "sip";
+	a[1] = "qualify";
+	a[2] = "peer";
+	a[3] = peer;
+
+	_sip_qualify_peer(1, -1, s, m, 4, a);
+	astman_append(s, "\r\n\r\n" );
+	return 0;
+}
+
+/*! \brief Send an OPTIONS packet to a SIP peer */
+static char *sip_qualify_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "sip qualify peer";
+		e->usage =
+			"Usage: sip qualify peer <name> [load]\n"
+			"       Requests a response from one SIP peer and the current status.\n"
+			"       Option \"load\" forces lookup of peer in realtime storage.\n";
+		return NULL;
+	case CLI_GENERATE:
+		return complete_sip_show_peer(a->line, a->word, a->pos, a->n);
+	}
+	return _sip_qualify_peer(0, a->fd, NULL, NULL, a->argc, (const char **) a->argv);
 }
 
 /*! \brief list peer mailboxes to CLI */
@@ -13605,7 +13666,6 @@
 	return CLI_SUCCESS;
 }
 
-
 /*! \brief Show one user in detail */
 static char *sip_show_user(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
@@ -14169,8 +14229,9 @@
 /*! \brief Support routine for 'sip show peer' CLI */
 static char *complete_sip_show_peer(const char *line, const char *word, int pos, int state)
 {
-	if (pos == 3)
+	if (pos == 3) {
 		return complete_sip_peer(word, state, 0);
+	}
 
 	return NULL;
 }
@@ -19866,12 +19927,12 @@
 /*! \brief Check availability of peer, also keep NAT open
 \note	This is done with the interval in qualify= configuration option
 	Default is 2 seconds */
-static int sip_poke_peer(struct sip_peer *peer)
+static int sip_poke_peer(struct sip_peer *peer, int force)
 {
 	struct sip_pvt *p;
 	int xmitres = 0;
 	
-	if (!peer->maxms || !peer->addr.sin_addr.s_addr) {
+	if ((!peer->maxms && !force) || !peer->addr.sin_addr.s_addr) {
 		/* IF we have no IP, or this isn't to be monitored, return
 		  immediately after clearing things out */
 		AST_SCHED_DEL(sched, peer->pokeexpire);
@@ -19927,9 +19988,9 @@
 	xmitres = transmit_invite(p, SIP_OPTIONS, 0, 2); /* sinks the p refcount */
 #endif
 	peer->ps = ast_tvnow();
-	if (xmitres == XMIT_ERROR)
+	if (xmitres == XMIT_ERROR) {
 		sip_poke_noanswer(peer);	/* Immediately unreachable, network problems */
-	else {
+	} else if (!force) {
 		AST_SCHED_REPLACE(peer->pokeexpire, sched, 
 			peer->maxms * 2, sip_poke_noanswer, peer);
 	}
@@ -22477,6 +22538,7 @@
 	AST_CLI_DEFINE(sip_show_channel, "Show detailed SIP channel info"),
 	AST_CLI_DEFINE(sip_show_history, "Show SIP dialog history"),
 	AST_CLI_DEFINE(sip_show_peer, "Show details on specific SIP peer"),
+	AST_CLI_DEFINE(sip_qualify_peer, "Send an OPTIONS packet to a peer"),
 	AST_CLI_DEFINE(sip_show_users, "List defined SIP users"),
 	AST_CLI_DEFINE(sip_show_user, "Show details on specific SIP user"),
 	AST_CLI_DEFINE(sip_show_sched, "Present a report on the status of the sched queue"),
@@ -22555,6 +22617,8 @@
 			"List SIP peers (text format)", mandescr_show_peers);
 	ast_manager_register2("SIPshowpeer", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_sip_show_peer,
 			"Show SIP peer (text format)", mandescr_show_peer);
+	ast_manager_register2("SIPqualifypeer", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_sip_qualify_peer,
+			"Show SIP peer (text format)", mandescr_show_peer);
 	ast_manager_register2("SIPshowregistry", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_show_registry,
 			"Show SIP registrations (text format)", mandescr_show_registry);
 	sip_poke_all_peers();	
@@ -22601,6 +22665,7 @@
 	/* Unregister AMI actions */
 	ast_manager_unregister("SIPpeers");
 	ast_manager_unregister("SIPshowpeer");
+	ast_manager_unregister("SIPqualifypeer");
 	ast_manager_unregister("SIPshowregistry");
 	
 	/* Kill TCP/TLS server threads */

Modified: team/file/audiohook-chains/contrib/scripts/vmail.cgi
URL: http://svn.digium.com/view/asterisk/team/file/audiohook-chains/contrib/scripts/vmail.cgi?view=diff&rev=114694&r1=114693&r2=114694
==============================================================================
--- team/file/audiohook-chains/contrib/scripts/vmail.cgi (original)
+++ team/file/audiohook-chains/contrib/scripts/vmail.cgi Sat Apr 26 19:22:49 2008
@@ -21,7 +21,7 @@
 use Fcntl qw ( O_WRONLY O_CREAT O_EXCL );
 use Time::HiRes qw ( usleep );
 
-$context=""; # Define here your by default context (so you dont need to put voicemail at context in the login
+$context=""; # Define here your by default context (so you dont need to put voicemail at context in the login)
 
 @validfolders = ( "INBOX", "Old", "Work", "Family", "Friends", "Cust1", "Cust2", "Cust3", "Cust4", "Cust5" );
 
@@ -46,10 +46,10 @@
 $astpath = "/_asterisk";
 
 $stdcontainerstart = "<table align=center width=600><tr><td>\n";
-$footer = "<hr><font size=-1><a href=\"http://www.asterisk.org\">The Asterisk Open Source PBX</a> Copyright 2004, <a href=\"http://www.digium.com\">Digium, Inc.</a></a>";
+$footer = "<hr><font size=-1><a href=\"http://www.asterisk.org\">The Asterisk Open Source PBX</a> Copyright 2004-2008, <a href=\"http://www.digium.com\">Digium, Inc.</a></a>";
 $stdcontainerend = "</td></tr><tr><td align=right>$footer</td></tr></table>\n";
 
-sub lock_path() {
+sub lock_path($) {
 
 	my($path) = @_;
 	my $rand;
@@ -80,14 +80,14 @@
 	}
 }
 
-sub unlock_path() {
+sub unlock_path($) {
 
 	my($path) = @_;
 	
 	unlink("$path/.lock");
 }
 
-sub untaint() {
+sub untaint($) {
 
 	my($data) = @_;
 	
@@ -100,7 +100,7 @@
 	return $data;
 }
 
-sub login_screen() {
+sub login_screen($) {
 	print header;
 	my ($message) = @_;
 	print <<_EOH;
@@ -126,7 +126,7 @@
 
 }
 
-sub check_login()
+sub check_login($$)
 {
 	local ($filename, $startcat) = @_;
 	local ($mbox, $context) = split(/\@/, param('mailbox'));
@@ -160,28 +160,28 @@
 			}
 		} elsif (/\[(.*)\]/) {
 			$category = $1;
-                } elsif ($category eq "general") {
-                        if (/([^\s]+)\s*\=\s*(.*)/) {
-                                if ($1 eq "dbname") {
-                                        $dbname = $2;
-                                } elsif ($1 eq "dbpass") {
-                                        $dbpass = $2;
-                                } elsif ($1 eq "dbhost") {
-                                        $dbhost = $2;
-                                } elsif ($1 eq "dbuser") {
-                                        $dbuser = $2;
-                                }
-                        }
-                        if ($dbname and $dbpass and $dbhost and $dbuser) {
-
-                                # db variables are present.  Use db for authentication.
-                                my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpass);
-                                my $sth = $dbh->prepare(qq{select fullname,context from voicemail where mailbox='$mbox' and password='$pass' and context='$context'});
-                                $sth->execute();
-                                if (($fullname, $category) = $sth->fetchrow_array()) {;
-                                        return ($fullname ? $fullname : "Extension $mbox in $context",$category);
-                                }
-                        }
+		} elsif ($category eq "general") {
+			if (/([^\s]+)\s*\=\s*(.*)/) {
+				if ($1 eq "dbname") {
+					$dbname = $2;
+				} elsif ($1 eq "dbpass") {
+					$dbpass = $2;
+				} elsif ($1 eq "dbhost") {
+					$dbhost = $2;
+				} elsif ($1 eq "dbuser") {
+					$dbuser = $2;
+				}
+			}
+			if ($dbname and $dbpass and $dbhost and $dbuser) {
+
+				# db variables are present.  Use db for authentication.
+				my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpass);
+				my $sth = $dbh->prepare(qq{select fullname,context from voicemail where mailbox='$mbox' and password='$pass' and context='$context'});
+				$sth->execute();
+				if (($fullname, $category) = $sth->fetchrow_array()) {
+					return ($fullname ? $fullname : "Extension $mbox in $context",$category);
+				}
+			}
 		} elsif (($category ne "general") && ($category ne "zonemessages")) { 
 			if (/([^\s]+)\s*\=\>?\s*(.*)/) {
 				@fields = split(/\,\s*/, $2);
@@ -196,7 +196,7 @@
 	return ("", $category);
 }
 
-sub validmailbox()
+sub validmailbox($$$$)
 {
 	local ($context, $mbox, $filename, $startcat) = @_;
 	local $category = $startcat;
@@ -215,7 +215,7 @@
 		$category = "general";
 	}
 	open(VMAIL, "<$filename") || die("Bleh, no $filename");
-	while(<VMAIL>) {
+	while (<VMAIL>) {
 		chomp;
 		if (/include\s\"([^\"]+)\"$/) {
 			($tmp, $category) = &validmailbox($mbox, $context, "/etc/asterisk/$1");
@@ -224,28 +224,28 @@
 			}
 		} elsif (/\[(.*)\]/) {
 			$category = $1;
-                } elsif ($category eq "general") {
-                        if (/([^\s]+)\s*\=\s*(.*)/) {
-                                if ($1 eq "dbname") {
-                                        $dbname = $2;
-                                } elsif ($1 eq "dbpass") {
-                                        $dbpass = $2;
-                                } elsif ($1 eq "dbhost") {
-                                        $dbhost = $2;
-                                } elsif ($1 eq "dbuser") {
-                                        $dbuser = $2;
-                                }
-                        }
-                        if ($dbname and $dbpass and $dbhost and $dbuser) {
-
-                                # db variables are present.  Use db for authentication.
-                                my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpass);
-                                my $sth = $dbh->prepare(qq{select fullname,context from voicemail where mailbox='$mbox' and password='$pass' and context='$context'});
-                                $sth->execute();
-				if (($fullname, $context) = $sth->fetchrow_array()) {;
-                                        return ($fullname ? $fullname : "unknown", $category);
-                                }
-                        }
+		} elsif ($category eq "general") {
+			if (/([^\s]+)\s*\=\s*(.*)/) {
+				if ($1 eq "dbname") {
+					$dbname = $2;
+				} elsif ($1 eq "dbpass") {
+					$dbpass = $2;
+				} elsif ($1 eq "dbhost") {
+					$dbhost = $2;
+				} elsif ($1 eq "dbuser") {
+					$dbuser = $2;
+				}
+			}
+			if ($dbname and $dbpass and $dbhost and $dbuser) {
+
+				# db variables are present.  Use db for authentication.
+				my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpass);
+				my $sth = $dbh->prepare(qq{select fullname,context from voicemail where mailbox='$mbox' and password='$pass' and context='$context'});
+				$sth->execute();
+				if (($fullname, $context) = $sth->fetchrow_array()) {
+					return ($fullname ? $fullname : "unknown", $category);
+				}
+			}
 		} elsif (($category ne "general") && ($category ne "zonemessages") && ($category eq $context)) {
 			if (/([^\s]+)\s*\=\>?\s*(.*)/) {
 				@fields = split(/\,\s*/, $2);
@@ -282,37 +282,37 @@
 			$tmp .= $tmp2;
 		} elsif (/\[(.*)\]/) {
 			$category = $1;
-                } elsif ($category eq "general") {
-                        if (/([^\s]+)\s*\=\s*(.*)/) {
-                                if ($1 eq "dbname") {
-                                        $dbname = $2;
-                                } elsif ($1 eq "dbpass") {
-                                        $dbpass = $2;
-                                } elsif ($1 eq "dbhost") {
-                                        $dbhost = $2;
-                                } elsif ($1 eq "dbuser") {
-                                        $dbuser = $2;
-                                }
-                        }
-                        if ($dbname and $dbpass and $dbhost and $dbuser) {
-
-                                # db variables are present.  Use db for authentication.
-                                my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpass);
-                                my $sth = $dbh->prepare(qq{select mailbox,fullname,context from voicemail where context='$context' order by mailbox});
-                                $sth->execute();
-                                while (($mailbox, $fullname, $category) = $sth->fetchrow_array()) {
-                                        $text = $mailbox;
-                                        if ($fullname) {
-                                                $text .= " (".$fullname.")";
-                                        }
-                                        if ($mailbox eq $current) {
-                                                $tmp .= "<OPTION SELECTED>$text</OPTION>\n";
-                                        } else {
-                                                $tmp .= "<OPTION>$text</OPTION>\n";
-                                        }
-                                }
-                                return ($tmp, $category);
-                        }
+		} elsif ($category eq "general") {
+			if (/([^\s]+)\s*\=\s*(.*)/) {
+				if ($1 eq "dbname") {
+					$dbname = $2;
+				} elsif ($1 eq "dbpass") {
+					$dbpass = $2;
+				} elsif ($1 eq "dbhost") {
+					$dbhost = $2;
+				} elsif ($1 eq "dbuser") {
+					$dbuser = $2;
+				}
+			}
+			if ($dbname and $dbpass and $dbhost and $dbuser) {
+
+				# db variables are present.  Use db for authentication.
+				my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpass);
+				my $sth = $dbh->prepare(qq{select mailbox,fullname,context from voicemail where context='$context' order by mailbox});
+				$sth->execute();
+				while (($mailbox, $fullname, $category) = $sth->fetchrow_array()) {
+					$text = $mailbox;
+					if ($fullname) {
+						$text .= " (".$fullname.")";
+					}
+					if ($mailbox eq $current) {
+						$tmp .= "<OPTION SELECTED>$text</OPTION>\n";
+					} else {
+						$tmp .= "<OPTION>$text</OPTION>\n";
+					}
+				}
+				return ($tmp, $category);
+			}
 		} elsif (($category ne "general") && ($category ne "zonemessages")) {
 			if (/([^\s]+)\s*\=\>?\s*(.*)/) {
 				@fields = split(/\,\s*/, $2);
@@ -587,7 +587,7 @@
 	my $message2;
 	my $msgcount;	
 	my $hasmsg;
-	my $newmessages, $oldmessages;
+	my ($newmessages, $oldmessages);
 	my $format = param('format');
 	if (!$format) {
 		$format = &getcookie('format');
@@ -737,14 +737,14 @@
 sub message_rename()
 {
 	my ($context, $mbox, $oldfolder, $old, $newfolder, $new) = @_;
-	my $oldfile, $newfile;
+	my ($oldfile, $newfile);
 	return if ($old eq $new) && ($oldfolder eq $newfolder);
 
-        if ($context =~ /^(\w+)$/) {
-                $context = $1;
-        } else {
-                die("Invalid Context<BR>\n");
-        }
+	if ($context =~ /^(\w+)$/) {
+		$context = $1;
+	} else {
+		die("Invalid Context<BR>\n");
+	}
 	
 	if ($mbox =~ /^(\w+)$/) {
 		$mbox = $1;
@@ -780,7 +780,7 @@
 	$path =~ /^(.*)$/;
 	$path = $1;
 	mkdir $path, 0770;
-	my $path = "/var/spool/asterisk/voicemail/$context/$mbox/$oldfolder";
+	$path = "/var/spool/asterisk/voicemail/$context/$mbox/$oldfolder";
 	opendir(DIR, $path) || die("Unable to open directory\n");
 	my @files = grep /^msg${old}\.\w+$/, readdir(DIR);
 	closedir(DIR);
@@ -818,7 +818,7 @@
 sub message_copy()
 {
 	my ($context, $mbox, $newmbox, $oldfolder, $old, $new) = @_;
-	my $oldfile, $newfile;
+	my ($oldfile, $newfile);
 	return if ($mbox eq $newmbox);
 	
 	if ($mbox =~ /^(\w+)$/) {
@@ -855,11 +855,11 @@
 	$path =~ /^(.*)$/;
 	$path = $1;
 	mkdir $path, 0770;
-	my $path = "/var/spool/asterisk/voicemail/$context/$newmbox/INBOX";
+	$path = "/var/spool/asterisk/voicemail/$context/$newmbox/INBOX";
 	$path =~ /^(.*)$/;
 	$path = $1;
 	mkdir $path, 0770;
-	my $path = "/var/spool/asterisk/voicemail/$context/$mbox/$oldfolder";
+	$path = "/var/spool/asterisk/voicemail/$context/$mbox/$oldfolder";
 	opendir(DIR, $path) || die("Unable to open directory\n");
 	my @files = grep /^msg${old}\.\w+$/, readdir(DIR);
 	closedir(DIR);
@@ -936,23 +936,27 @@
 	$context = &untaint($context);
 	$newmbox = &untaint($newmbox);
 	my $path = "/var/spool/asterisk/voicemail/$context/$newmbox/INBOX";
-	if (&lock_path($path) == 0) {
-		$msgcount = &msgcount($context, $newmbox, "INBOX");
-		
-		if ($newmbox ne $mbox) {
-#			print header;
-			foreach $msg (@msgs) {
-#				print "Forwarding $msg from $mbox to $newmbox<BR>\n";
-				&message_copy($context, $mbox, $newmbox, $folder, $msg, sprintf "%04d", $msgcount);
-				$msgcount++;
-			}
-			$txt = "Forwarded messages " . join(', ', @msgs) . "to $newmbox";
+	if ($msgs[0]) {
+		if (&lock_path($path) == 0) {
+			$msgcount = &msgcount($context, $newmbox, "INBOX");
+			
+			if ($newmbox ne $mbox) {
+	#			print header;
+				foreach $msg (@msgs) {
+	#				print "Forwarding $msg from $mbox to $newmbox<BR>\n";
+					&message_copy($context, $mbox, $newmbox, $folder, $msg, sprintf "%04d", $msgcount);
+					$msgcount++;
+				}
+				$txt = "Forwarded messages " . join(', ', @msgs) . "to $newmbox";
+			} else {
+				$txt = "Can't forward messages to yourself!\n";
+			}
+			&unlock_path($path); 
 		} else {
-			$txt = "Can't forward messages to yourself!\n";
-		}
-		&unlock_path($path); 
-	} else {
-		$txt = "Cannot forward messages: Unable to lock path.\n";
+			$txt = "Cannot forward messages: Unable to lock path.\n";
+		}
+	} else {
+		$txt = "Please Select Message(s) for this action.\n";
 	}
 	if ($toindex) {
 		&message_index($folder, $txt);
@@ -966,7 +970,7 @@
 	my ($toindex, $del, @msgs) = @_;
 	my $txt;
 	my $path;
-	my $y, $x;
+	my ($y, $x);
 	my $folder = param('folder');
 	my $newfolder = param('newfolder') unless $del;
 	$newfolder =~ s/^(\w+)\s+.*$/$1/;
@@ -981,39 +985,43 @@
 	$context = &untaint($context);
 	$mbox = &untaint($mbox);
 	$folder = &untaint($folder);
-	my $path = "/var/spool/asterisk/voicemail/$context/$mbox/$folder";
-	if (&lock_path($path) == 0) {
-		my $msgcount = &msgcount($context, $mbox, $folder);
-		my $omsgcount = &msgcount($context, $mbox, $newfolder) if $newfolder;
-	#	print header;
-		if ($newfolder ne $folder) {
-			$y = 0;
-			for ($x=0;$x<$msgcount;$x++) {
-				my $msg = sprintf "%04d", $x;
-				my $newmsg = sprintf "%04d", $y;
-				if (grep(/^$msg$/, @msgs)) {
-					if ($newfolder) {
-						&message_rename($context, $mbox, $folder, $msg, $newfolder, sprintf "%04d", $omsgcount);
-						$omsgcount++;
+	$path = "/var/spool/asterisk/voicemail/$context/$mbox/$folder";
+	if ($msgs[0]) {
+		if (&lock_path($path) == 0) {
+			my $msgcount = &msgcount($context, $mbox, $folder);
+			my $omsgcount = &msgcount($context, $mbox, $newfolder) if $newfolder;
+		#	print header;
+			if ($newfolder ne $folder) {
+				$y = 0;
+				for ($x=0;$x<$msgcount;$x++) {
+					my $msg = sprintf "%04d", $x;
+					my $newmsg = sprintf "%04d", $y;
+					if (grep(/^$msg$/, @msgs)) {
+						if ($newfolder) {
+							&message_rename($context, $mbox, $folder, $msg, $newfolder, sprintf "%04d", $omsgcount);
+							$omsgcount++;
+						} else {
+							&message_delete($context, $mbox, $folder, $msg);
+						}
 					} else {
-						&message_delete($context, $mbox, $folder, $msg);
+						&message_rename($context, $mbox, $folder, $msg, $folder, $newmsg);
+						$y++;
 					}
+				}
+				if ($del) {
+					$txt = "Deleted messages "  . join (', ', @msgs);
 				} else {
-					&message_rename($context, $mbox, $folder, $msg, $folder, $newmsg);
-					$y++;
-				}
-			}
-			if ($del) {
-				$txt = "Deleted messages "  . join (', ', @msgs);
+					$txt = "Moved messages "  . join (', ', @msgs) . " to $newfolder";
+				}
 			} else {
-				$txt = "Moved messages "  . join (', ', @msgs) . " to $newfolder";
-			}
+				$txt = "Can't move a message to the same folder they're in already";
+			}
+			&unlock_path($path);
 		} else {
-			$txt = "Can't move a message to the same folder they're in already";
-		}
-		&unlock_path($path);
-	} else {
-		$txt = "Cannot move/delete messages: Unable to lock path.\n";
+			$txt = "Cannot move/delete messages: Unable to lock path.\n";
+		}
+	} else {
+		$txt = "Please Select Message(s) for this action.\n";
 	}
 	# Not as many messages now
 	$msgcount--;

Modified: team/file/audiohook-chains/pbx/pbx_lua.c
URL: http://svn.digium.com/view/asterisk/team/file/audiohook-chains/pbx/pbx_lua.c?view=diff&rev=114694&r1=114693&r2=114694
==============================================================================
--- team/file/audiohook-chains/pbx/pbx_lua.c (original)
+++ team/file/audiohook-chains/pbx/pbx_lua.c Sat Apr 26 19:22:49 2008
@@ -982,7 +982,9 @@
 		}
 		return L;
 	} else {
+		ast_channel_lock(chan);
 		datastore = ast_channel_datastore_find(chan, &lua_datastore, NULL);
+		ast_channel_unlock(chan);
 
 		if (!datastore) {
 			/* nothing found, allocate a new lua state */




More information about the asterisk-commits mailing list