[308] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r453 - / trunk/owl/perl/modules

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:04:44 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Thu,  9 Nov 2006 23:40:50 -0500 (EST)

Author: nelhage
Date: 2006-11-09 23:40:50 -0500 (Thu, 09 Nov 2006)
New Revision: 453

Modified:
   /
   trunk/owl/perl/modules/jabber.pl
Log:
 r23943@heretique:  nelhage | 2006-11-09 23:40:36 -0500
 Refactoring jmuc somewhat. Also, @ARGV refers to @::ARGV by default
 (see perlmod), so changing to use that, since it looks nicer.



Property changes on: 
___________________________________________________________________
Name: svk:merge
   - 6122c8b4-0e12-0410-9533-8bcd7c66c992:/local/dirty-owl-hacks:23941
6aa88b72-b502-0410-8cb4-a5dd0230fb79:/owl-local:1356
   + 6122c8b4-0e12-0410-9533-8bcd7c66c992:/local/dirty-owl-hacks:23943
6aa88b72-b502-0410-8cb4-a5dd0230fb79:/owl-local:1356

Modified: trunk/owl/perl/modules/jabber.pl
===================================================================
--- trunk/owl/perl/modules/jabber.pl	2006-11-10 00:45:13 UTC (rev 452)
+++ trunk/owl/perl/modules/jabber.pl	2006-11-10 04:40:50 UTC (rev 453)
@@ -187,7 +187,8 @@
 
     my ($server, $port) = getServerFromJID($jid);
 
-    $connections->{$jidStr}->{client} = Net::Jabber::Client->new();
+    $connections->{$jidStr}->{client} = Net::Jabber::Client->new(debuglevel => owl::getvar('debug') eq 'on' ? 1 : 0,
+                                                                 debugfile  => 'jabber.log');
     my $client = \$connections->{$jidStr}->{client};
     $connections->{$jidStr}->{roster} = $connections->{$jidStr}->{client}->Roster();
 
@@ -412,37 +413,49 @@
 # It'll make them more managable.
 sub cmd_jmuc
 {
-    if (!connected())
-    {
-	owl::error("You are not logged in to Jabber.");
-	return;
-    }
+	if (!connected())
+		{
+			owl::error("You are not logged in to Jabber.");
+			return;
+		}
     
-    my $ocmd = shift;
-    my $cmd = shift;    
-    if (!$cmd)
-    {
-	#XXX TODO: Write general usage for jmuc command.
-	return;
-    }
+	my $ocmd = shift;
+	my $cmd = shift;    
+	if (!$cmd)
+	{
+		#XXX TODO: Write general usage for jmuc command.
+		return;
+	}
 
-    if ($cmd eq 'join')
-    {
-	local @::ARGV = @_;
+	my %jmuc_commands = (
+		join => \&jmuc_join,
+		part => \&jmuc_part,
+		invite => \&jmuc_invite
+	       );
+	my $func = $jmuc_commands{$cmd};
+	if(!$func) {
+		owl::error("jmuc: Unknown command: $cmd");
+	} else {
+		return $func->(@_);
+	}
+}
+
+sub jmuc_join {
+	local @ARGV = @_;
 	my $password;
 	my $jid;
 	GetOptions('password=s' => \$password,
 		   'account=s' => \$jid);
 
 	my $muc;
-	if (scalar @::ARGV != 1)
+	if (scalar @ARGV != 1)
 	{
 	    owl::error('Usage: jmuc join {muc} [-p password] [-a account]');
 	    return;
 	}
 	else
 	{
-	    $muc = @::ARGV[0];
+	    $muc = @ARGV[0];
 	}
 
 	if (!$jid)
@@ -476,9 +489,9 @@
 	$presence->SetPresence(to => $muc);
 	$presence->AddX($x);
 	$connections->{$jid}->{client}->Send($presence);
-    }
-    elsif ($cmd eq 'part')
-    {
+}
+
+sub jmuc_part {
 	my $muc;
 	my $jid;
 	if (!$_[0])
@@ -497,16 +510,16 @@
 	}
 	else
 	{
-	    local @::ARGV = @_;
+	    local @ARGV = @_;
 	    GetOptions('account=s' => \$jid);
-	    if (scalar @::ARGV != 1)
+	    if (scalar @ARGV != 1)
 	    {
 		owl::error('Usage: jmuc part {muc} [-a account]');
 		return;
 	    }
 	    else
 	    {
-		$muc = @::ARGV[0];
+		$muc = @ARGV[0];
 	    }
 	    if (!$jid)
 	    {
@@ -528,9 +541,10 @@
 	}
 	$connections->{$jid}->{client}->PresenceSend(to => $muc, type => 'unavailable');
 	queue_admin_msg("$jid has left $muc.");
-    }
-    elsif ($cmd eq 'invite')
-    {
+}
+
+sub jmuc_invite
+{
 	my $jid;
 	my $invite_jid;
 	my $muc;
@@ -554,16 +568,16 @@
 	}
 	else
 	{
-	    local @::ARGV = @_;
+	    local @ARGV = @_;
 	    GetOptions('account=s' => \$jid);
-	    if (scalar @::ARGV != 2)
+	    if (scalar @ARGV != 2)
 	    {
 		owl::error('Usage: jmuc invite {jid} [muc] [-a account]');
 		return;
 	    }
 	    else
 	    {
-		($muc, $invite_jid) = @::ARGV;
+		($muc, $invite_jid) = @ARGV;
 	    }
 	    if (!$jid)
 	    {
@@ -593,14 +607,9 @@
 	$message->AddX($x);
 	$connections->{$jid}->{client}->Send($message);
 	queue_admin_msg("$jid has invited $invite_jid to $muc.");
-    }
-    else
-    {
-	owl::error('jmuc: unrecognized command.');
-    }
-    return "";
 }
 
+
 ################################################################################
 ### Owl Callbacks
 sub process_owl_jwrite


home help back first fref pref prev next nref lref last post