Changeset 8f2ce3a


Ignore:
Timestamp:
Dec 26, 2006, 12:59:00 AM (14 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
bed4ff1
Parents:
b699e9b
git-author:
Nelson Elhage <nelhage@mit.edu> (12/24/06 14:17:13)
git-committer:
Nelson Elhage <nelhage@mit.edu> (12/26/06 00:59:00)
Message:
 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.
 
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/jabber.pl

    rea67541 r8f2ce3a  
    3939    my $jidStr = shift;
    4040
    41     my %args = ();
    42     if(owl::getvar('debug') eq 'on') {
    43         $args{debuglevel} = 1;
    44         $args{debugfile} = 'jabber.log';
    45     }
    46     my $client = Net::Jabber::Client->new(%args);
    47 
    48     $self->{Client}->{$jidStr} = $client;
    49     $self->{Roster}->{$jidStr} = $client->Roster();
    50     return $client;
     41    $self->{Client}->{$jidStr} =
     42      Net::Jabber::Client->new(
     43          debuglevel => owl::getvar('debug') eq 'on' ? 1 : 0,
     44          debugfile => 'jabber.log'
     45      );
     46    my $refConn = \$self->{Client}->{$jidStr};
     47    $self->{Roster}->{$jidStr} = $$refConn->Roster();
     48    return $refConn;
    5149}
    5250
     
    5452    my $self = shift;
    5553    my $jidStr = shift;
    56     return 0 unless exists $self->{Client}->{$jidStr};
    57    
    58     $self->{Client}->{$jidStr}->Disconnect();
    59     delete $self->{Roster}->{$jidStr};
    60     delete $self->{Client}->{$jidStr};
    61    
    62     return 1;
     54    my $ret = 0;
     55    foreach my $j ( keys %{ $self->{Client} } ) {
     56        if ($j eq $jidStr) {
     57            $self->{Client}->{$j}->Disconnect();
     58            delete $self->{Roster}->{$j};
     59            delete $self->{Client}->{$j};
     60            $ret = 1;
     61        }
     62    }
     63    return $ret;
    6364}
    6465
     
    7677    my $self = shift;
    7778    my $jidStr = shift;
    78     return exists $self->{Client}->{$jidStr};
     79    foreach my $j ( keys %{ $self->{Client} } ) {
     80        return 1 if ($j eq $jidStr);
     81    }
     82    return 0;
    7983}
    8084
     
    8892}
    8993
    90 sub getConnectionFromSid {
     94sub getConnRefFromSid {
    9195    my $self = shift;
    9296    my $sid = shift;
    93     foreach my $c (values %{ $self->{Client} }) {
    94         return $c if $c->{SESSION}->{id} eq $sid;
     97    foreach my $j ( keys %{ $self->{Client} } ) {
     98        if ($self->{Client}->{$j}->{SESSION}->{id} eq $sid) {
     99            return \$self->{Client}->{$j};
     100        }
    95101    }
    96102    return undef;
    97103}
    98104
    99 sub getConnectionFromJidStr {
     105sub getConnRefFromJidStr {
    100106    my $self = shift;
    101107    my $jidStr = shift;
    102     return $self->{Client}->{$jidStr};
    103 }
    104 
    105 sub getRosterFromSid {
     108    foreach my $j ( keys %{ $self->{Client} } ) {
     109        if ($jidStr eq $j) {
     110            return \$self->{Client}->{$j};
     111        }
     112    }
     113    return undef;
     114}
     115
     116sub getRosterRefFromSid {
    106117    my $self = shift;
    107118    my $sid = shift;
    108     foreach my $j ( $self->getJids ) {
    109         return $self->{Roster}->{$j}
    110           if $self->{Client}->{$j}->{SESSION}->{id} eq $sid;
     119    foreach my $j ( keys %{ $self->{Client} } ) {
     120        if ($self->{Client}->{$j}->{SESSION}->{id} eq $sid) {
     121            return \$self->{Roster}->{$j};
     122        }
    111123    }
    112124    return undef;
    113125}
    114126
    115 sub getRosterFromJidStr {
     127sub getRosterRefFromJidStr {
    116128    my $self = shift;
    117129    my $jidStr = shift;
    118     return $self->{Roster}->{$jidStr};
     130    foreach my $j ( keys %{ $self->{Client} } ) {
     131        if ($jidStr eq $j) {
     132            return \$self->{Roster}->{$j};
     133        }
     134    }
    119135    return undef;
    120136}
     
    145161
    146162    foreach my $jid ( $conn->getJids() ) {
    147         my $client = $conn->getConnectionFromJidStr($jid);
     163        my $client = $conn->getConnRefFromJidStr($jid);
    148164
    149165        my $status = $client->Process(0);
     
    193209    return "" unless $jid;
    194210    my $blist = "";
    195     my $roster = $conn->getRosterFromJidStr($jid);
    196     if ($roster) {
     211    my $roster = $conn->getRosterRefFromJidStr($jid);
     212    if ($$roster) {
    197213        $blist .= "\n" . boldify("Jabber Roster for $jid\n");
    198214
     
    335351            normal    => sub { owl_jabber::process_incoming_normal_message(@_) }
    336352        );
    337         $client->SetPresenceCallBacks(
     353        $$client->SetPresenceCallBacks(
    338354#            available    => sub { owl_jabber::process_presence_available(@_) },
    339355#            unavailable  => sub { owl_jabber::process_presence_available(@_) },
     
    363379        }
    364380            else {
    365                 $conn->getRosterFromJidStr($jidStr)->fetch();
    366                 $client->PresenceSend( priority => 1 );
     381                ${ $conn->getRosterRefFromJidStr($jidStr) }->fetch();
     382                $$client->PresenceSend( priority => 1 );
    367383                queue_admin_msg("Connected to jabber as $jidStr");
    368384            }
     
    554570    }
    555571
    556     $conn->getConnectionFromJidStr($jid)->Send($presence);
     572    ${ $conn->getConnRefFromJidStr($jid) }->Send($presence);
    557573}
    558574
     
    563579    die("Usage: jmuc part {muc} [-a account]") unless $muc;
    564580
    565     $conn->getConnectionFromJidStr($jid)->PresenceSend( to => $muc, type => 'unavailable' );
     581    ${ $conn->getConnRefFromJidStr($jid) }
     582      ->PresenceSend( to => $muc, type => 'unavailable' );
    566583    queue_admin_msg("$jid has left $muc.");
    567584}
     
    581598    $x->AddInvite();
    582599    $x->GetInvite()->SetTo($invite_jid);
    583     $conn->getConnectionFromJidStr($jid)->Send($message);
     600    ${ $conn->getConnRefFromJidStr($jid) }->Send($message);
    584601    queue_admin_msg("$jid has invited $invite_jid to $muc.");
    585602}
     
    596613    $x->SetType('submit');
    597614
    598     $conn->getConnectionFromJidStr($jid)->Send($iq);
     615    ${ $conn->getConnRefFromJidStr($jid) }->Send($iq);
    599616    queue_admin_msg("Accepted default instant configuration for $muc");
    600617}
     
    660677    my $baseJid = baseJID($jid);
    661678
    662     my $roster = $conn->getRosterFromJidStr($jid);
     679    my $roster = $conn->getRosterRefFromJidStr($jid);
    663680
    664681    # Adding lots of users with the same name is a bad idea.
     
    669686
    670687    foreach my $to (@ARGV) {
    671         jroster_add($jid, $name, \@groups, $purgeGroups, ($to)) unless ($roster->exists($to));
     688        jroster_add($jid, $name, \@groups, $purgeGroups, ($to)) unless ($$roster->exists($to));
    672689
    673690        $p->SetTo($to);
    674         $conn->getConnectionFromJidStr($jid)->Send($p);
     691        ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
    675692        queue_admin_msg("You ($baseJid) have requested a subscription to ($to)'s presence.");
    676693    }
     
    688705    foreach my $to (@ARGV) {
    689706        $p->SetTo($to);
    690         $conn->getConnectionFromJidStr($jid)->Send($p);
     707        ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
    691708        queue_admin_msg("You ($baseJid) have unsubscribed from ($to)'s presence.");
    692709    }
     
    700717    my $baseJid = baseJID($jid);
    701718
    702     my $roster = $conn->getRosterFromJidStr($jid);
     719    my $roster = $conn->getRosterRefFromJidStr($jid);
    703720
    704721    # Adding lots of users with the same name is a bad idea.
     
    706723
    707724    foreach my $to (@ARGV) {
    708         my %jq  = $roster->query($to);
     725        my %jq  = $$roster->query($to);
    709726        my $iq = new Net::XMPP::IQ;
    710727        $iq->SetType('set');
     
    730747        $item->put_attrib(jid => $to);
    731748        $item->put_attrib(name => $name) if $name;
    732         $conn->getConnectionFromJidStr($jid)->Send($iq);
     749        ${ $conn->getConnRefFromJidStr($jid) }->Send($iq);
    733750        my $msg = "$baseJid: "
    734751          . ($name ? "$name ($to)" : "($to)")
     
    754771    foreach my $to (@ARGV) {
    755772        $item->put_attrib(jid => $to);
    756         $conn->getConnectionFromJidStr($jid)->Send($iq);
     773        ${ $conn->getConnRefFromJidStr($jid) }->Send($iq);
    757774        queue_admin_msg("You ($baseJid) have removed ($to) from your roster.");
    758775    }
     
    770787    foreach my $to (@ARGV) {
    771788        $p->SetTo($to);
    772         $conn->getConnectionFromJidStr($jid)->Send($p);
     789        ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
    773790        queue_admin_msg("($to) has been subscribed to your ($baseJid) presence.");
    774791    }
     
    786803    foreach my $to (@ARGV) {
    787804        $p->SetTo($to);
    788         $conn->getConnectionFromJidStr($jid)->Send($p);
     805        ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
    789806        queue_admin_msg("($to) has been unsubscribed from your ($baseJid) presence.");
    790807    }
     
    809826
    810827    my $m = j2o( $j, { direction => 'out' } );
    811     if ( $vars{jwrite}{type} ne 'groupchat' && owl::getvar('displayoutgoing') eq 'on') {
     828    if ( $vars{jwrite}{type} ne 'groupchat' ) {
     829
     830        #XXX TODO: Check for displayoutgoing.
    812831        owl::queue_message($m);
    813832    }
    814833
    815834    if ($vars{jwrite}{sid} && $conn->sidExists( $vars{jwrite}{sid} )) {
    816         $conn->getConnectionFromSid($vars{jwrite}{sid})->Send($j);
     835        ${ $conn->getConnRefFromSid($vars{jwrite}{sid}) }->Send($j);
    817836    }
    818837    else {
    819         $conn->getConnectionFromJidStr($vars{jwrite}{from})->Send($j);
     838        ${ $conn->getConnRefFromJidStr($vars{jwrite}{from}) }->Send($j);
    820839    }
    821840
     
    949968            $to eq $cJid->GetJID('full')) {
    950969            my $reply = $p->Reply(type=>"unsubscribed");
    951             $conn->getConnectionFromJidStr($jid)->Send($reply);
     970            ${ $conn->getConnRefFromJidStr($jid) }->Send($reply);
    952971            return;
    953972        }
Note: See TracChangeset for help on using the changeset viewer.