[334] in BarnOwl Developers
[D-O-H] r479 - in trunk: . owl owl/perl/modules
daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:05:01 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: Tue, 26 Dec 2006 00:59:01 -0500 (EST)
Author: nelhage
Date: 2006-12-26 00:59:00 -0500 (Tue, 26 Dec 2006)
New Revision: 479
Modified:
trunk/
trunk/owl/TODO
trunk/owl/functions.c
trunk/owl/owl.c
trunk/owl/perl/modules/jabber.pl
Log:
r15866@phanatique: nelhage | 2006-12-24 14:17:13 -0500
r15864@phanatique (orig r470): nelhage | 2006-12-24 11:46:49 -0500
Mirror relocated to svn+ssh://nelhage@heretique.mit.edu/mit/nelhage/svn/dirty-owl-hacks
r15865@phanatique (orig r471): asedeno | 2006-12-24 14:15:05 -0500
Updates I've had pending for a while.
* First pass of Roster support
* Redesigning the connection storage as an object.
* Tweaking admin messages to allow reply actions. (Useful for Roster Management)
Possibly a few other things I'm forgetting.
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- fe09232e-8620-0410-8e36-e6b4839e121d:/trunk:442
+ bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h/trunk:15866
Modified: trunk/owl/TODO
===================================================================
Modified: trunk/owl/functions.c
===================================================================
Modified: trunk/owl/owl.c
===================================================================
Modified: trunk/owl/perl/modules/jabber.pl
===================================================================
--- trunk/owl/perl/modules/jabber.pl 2006-12-25 04:37:13 UTC (rev 478)
+++ trunk/owl/perl/modules/jabber.pl 2006-12-26 05:59:00 UTC (rev 479)
@@ -38,28 +38,29 @@
my $self = shift;
my $jidStr = shift;
- my %args = ();
- if(owl::getvar('debug') eq 'on') {
- $args{debuglevel} = 1;
- $args{debugfile} = 'jabber.log';
- }
- my $client = Net::Jabber::Client->new(%args);
-
- $self->{Client}->{$jidStr} = $client;
- $self->{Roster}->{$jidStr} = $client->Roster();
- return $client;
+ $self->{Client}->{$jidStr} =
+ Net::Jabber::Client->new(
+ debuglevel => owl::getvar('debug') eq 'on' ? 1 : 0,
+ debugfile => 'jabber.log'
+ );
+ my $refConn = \$self->{Client}->{$jidStr};
+ $self->{Roster}->{$jidStr} = $$refConn->Roster();
+ return $refConn;
}
sub removeConnection {
my $self = shift;
my $jidStr = shift;
- return 0 unless exists $self->{Client}->{$jidStr};
-
- $self->{Client}->{$jidStr}->Disconnect();
- delete $self->{Roster}->{$jidStr};
- delete $self->{Client}->{$jidStr};
-
- return 1;
+ my $ret = 0;
+ foreach my $j ( keys %{ $self->{Client} } ) {
+ if ($j eq $jidStr) {
+ $self->{Client}->{$j}->Disconnect();
+ delete $self->{Roster}->{$j};
+ delete $self->{Client}->{$j};
+ $ret = 1;
+ }
+ }
+ return $ret;
}
sub connected {
@@ -75,7 +76,10 @@
sub jidExists {
my $self = shift;
my $jidStr = shift;
- return exists $self->{Client}->{$jidStr};
+ foreach my $j ( keys %{ $self->{Client} } ) {
+ return 1 if ($j eq $jidStr);
+ }
+ return 0;
}
sub sidExists {
@@ -87,35 +91,47 @@
return 0;
}
-sub getConnectionFromSid {
+sub getConnRefFromSid {
my $self = shift;
my $sid = shift;
- foreach my $c (values %{ $self->{Client} }) {
- return $c if $c->{SESSION}->{id} eq $sid;
+ foreach my $j ( keys %{ $self->{Client} } ) {
+ if ($self->{Client}->{$j}->{SESSION}->{id} eq $sid) {
+ return \$self->{Client}->{$j};
+ }
}
return undef;
}
-sub getConnectionFromJidStr {
+sub getConnRefFromJidStr {
my $self = shift;
my $jidStr = shift;
- return $self->{Client}->{$jidStr};
+ foreach my $j ( keys %{ $self->{Client} } ) {
+ if ($jidStr eq $j) {
+ return \$self->{Client}->{$j};
+ }
+ }
+ return undef;
}
-sub getRosterFromSid {
+sub getRosterRefFromSid {
my $self = shift;
my $sid = shift;
- foreach my $j ( $self->getJids ) {
- return $self->{Roster}->{$j}
- if $self->{Client}->{$j}->{SESSION}->{id} eq $sid;
+ foreach my $j ( keys %{ $self->{Client} } ) {
+ if ($self->{Client}->{$j}->{SESSION}->{id} eq $sid) {
+ return \$self->{Roster}->{$j};
+ }
}
return undef;
}
-sub getRosterFromJidStr {
+sub getRosterRefFromJidStr {
my $self = shift;
my $jidStr = shift;
- return $self->{Roster}->{$jidStr};
+ foreach my $j ( keys %{ $self->{Client} } ) {
+ if ($jidStr eq $j) {
+ return \$self->{Roster}->{$j};
+ }
+ }
return undef;
}
################################################################################
@@ -144,7 +160,7 @@
return if ( !$conn->connected() );
foreach my $jid ( $conn->getJids() ) {
- my $client = $conn->getConnectionFromJidStr($jid);
+ my $client = $conn->getConnRefFromJidStr($jid);
my $status = $client->Process(0);
if ( !defined($status) ) {
@@ -192,8 +208,8 @@
$jid = resolveJID($jid);
return "" unless $jid;
my $blist = "";
- my $roster = $conn->getRosterFromJidStr($jid);
- if ($roster) {
+ my $roster = $conn->getRosterRefFromJidStr($jid);
+ if ($$roster) {
$blist .= "\n" . boldify("Jabber Roster for $jid\n");
foreach my $group ( $roster->groups() ) {
@@ -334,7 +350,7 @@
headline => sub { owl_jabber::process_incoming_headline_message(@_) },
normal => sub { owl_jabber::process_incoming_normal_message(@_) }
);
- $client->SetPresenceCallBacks(
+ $$client->SetPresenceCallBacks(
# available => sub { owl_jabber::process_presence_available(@_) },
# unavailable => sub { owl_jabber::process_presence_available(@_) },
subscribe => sub { owl_jabber::process_presence_subscribe(@_) },
@@ -362,8 +378,8 @@
"Error in connect: " . join( " ", @result ) );
}
else {
- $conn->getRosterFromJidStr($jidStr)->fetch();
- $client->PresenceSend( priority => 1 );
+ ${ $conn->getRosterRefFromJidStr($jidStr) }->fetch();
+ $$client->PresenceSend( priority => 1 );
queue_admin_msg("Connected to jabber as $jidStr");
}
}
@@ -553,7 +569,7 @@
$x->SetPassword($password);
}
- $conn->getConnectionFromJidStr($jid)->Send($presence);
+ ${ $conn->getConnRefFromJidStr($jid) }->Send($presence);
}
sub jmuc_part {
@@ -562,7 +578,8 @@
$muc = shift @args if scalar @args;
die("Usage: jmuc part {muc} [-a account]") unless $muc;
- $conn->getConnectionFromJidStr($jid)->PresenceSend( to => $muc, type => 'unavailable' );
+ ${ $conn->getConnRefFromJidStr($jid) }
+ ->PresenceSend( to => $muc, type => 'unavailable' );
queue_admin_msg("$jid has left $muc.");
}
@@ -580,7 +597,7 @@
my $x = $message->NewChild('http://jabber.org/protocol/muc#user');
$x->AddInvite();
$x->GetInvite()->SetTo($invite_jid);
- $conn->getConnectionFromJidStr($jid)->Send($message);
+ ${ $conn->getConnRefFromJidStr($jid) }->Send($message);
queue_admin_msg("$jid has invited $invite_jid to $muc.");
}
@@ -595,7 +612,7 @@
my $x = $query->NewChild("jabber:x:data");
$x->SetType('submit');
- $conn->getConnectionFromJidStr($jid)->Send($iq);
+ ${ $conn->getConnRefFromJidStr($jid) }->Send($iq);
queue_admin_msg("Accepted default instant configuration for $muc");
}
@@ -659,7 +676,7 @@
my $purgeGroups = shift;
my $baseJid = baseJID($jid);
- my $roster = $conn->getRosterFromJidStr($jid);
+ my $roster = $conn->getRosterRefFromJidStr($jid);
# Adding lots of users with the same name is a bad idea.
$name = "" unless (1 == scalar(@ARGV));
@@ -668,10 +685,10 @@
$p->SetType('subscribe');
foreach my $to (@ARGV) {
- jroster_add($jid, $name, \@groups, $purgeGroups, ($to)) unless ($roster->exists($to));
+ jroster_add($jid, $name, \@groups, $purgeGroups, ($to)) unless ($$roster->exists($to));
$p->SetTo($to);
- $conn->getConnectionFromJidStr($jid)->Send($p);
+ ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
queue_admin_msg("You ($baseJid) have requested a subscription to ($to)'s presence.");
}
}
@@ -687,7 +704,7 @@
$p->SetType('unsubscribe');
foreach my $to (@ARGV) {
$p->SetTo($to);
- $conn->getConnectionFromJidStr($jid)->Send($p);
+ ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
queue_admin_msg("You ($baseJid) have unsubscribed from ($to)'s presence.");
}
}
@@ -699,13 +716,13 @@
my $purgeGroups = shift;
my $baseJid = baseJID($jid);
- my $roster = $conn->getRosterFromJidStr($jid);
+ my $roster = $conn->getRosterRefFromJidStr($jid);
# Adding lots of users with the same name is a bad idea.
$name = "" unless (1 == scalar(@ARGV));
foreach my $to (@ARGV) {
- my %jq = $roster->query($to);
+ my %jq = $$roster->query($to);
my $iq = new Net::XMPP::IQ;
$iq->SetType('set');
my $item = new XML::Stream::Node('item');
@@ -729,7 +746,7 @@
$item->put_attrib(jid => $to);
$item->put_attrib(name => $name) if $name;
- $conn->getConnectionFromJidStr($jid)->Send($iq);
+ ${ $conn->getConnRefFromJidStr($jid) }->Send($iq);
my $msg = "$baseJid: "
. ($name ? "$name ($to)" : "($to)")
. " is on your roster in the following groups: { "
@@ -753,7 +770,7 @@
$item->put_attrib(subscription=> 'remove');
foreach my $to (@ARGV) {
$item->put_attrib(jid => $to);
- $conn->getConnectionFromJidStr($jid)->Send($iq);
+ ${ $conn->getConnRefFromJidStr($jid) }->Send($iq);
queue_admin_msg("You ($baseJid) have removed ($to) from your roster.");
}
}
@@ -769,7 +786,7 @@
$p->SetType('subscribed');
foreach my $to (@ARGV) {
$p->SetTo($to);
- $conn->getConnectionFromJidStr($jid)->Send($p);
+ ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
queue_admin_msg("($to) has been subscribed to your ($baseJid) presence.");
}
}
@@ -785,7 +802,7 @@
$p->SetType('unsubscribed');
foreach my $to (@ARGV) {
$p->SetTo($to);
- $conn->getConnectionFromJidStr($jid)->Send($p);
+ ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
queue_admin_msg("($to) has been unsubscribed from your ($baseJid) presence.");
}
}
@@ -808,15 +825,17 @@
$j->SetSubject( $vars{jwrite}{subject} ) if ( $vars{jwrite}{subject} );
my $m = j2o( $j, { direction => 'out' } );
- if ( $vars{jwrite}{type} ne 'groupchat' && owl::getvar('displayoutgoing') eq 'on') {
+ if ( $vars{jwrite}{type} ne 'groupchat' ) {
+
+ #XXX TODO: Check for displayoutgoing.
owl::queue_message($m);
}
if ($vars{jwrite}{sid} && $conn->sidExists( $vars{jwrite}{sid} )) {
- $conn->getConnectionFromSid($vars{jwrite}{sid})->Send($j);
+ ${ $conn->getConnRefFromSid($vars{jwrite}{sid}) }->Send($j);
}
else {
- $conn->getConnectionFromJidStr($vars{jwrite}{from})->Send($j);
+ ${ $conn->getConnRefFromJidStr($vars{jwrite}{from}) }->Send($j);
}
delete $vars{jwrite};
@@ -948,7 +967,7 @@
if ($to eq $cJid->GetJID('base') ||
$to eq $cJid->GetJID('full')) {
my $reply = $p->Reply(type=>"unsubscribed");
- $conn->getConnectionFromJidStr($jid)->Send($reply);
+ ${ $conn->getConnRefFromJidStr($jid) }->Send($reply);
return;
}
}