Ignore:
Timestamp:
Dec 26, 2006, 12:59:12 AM (18 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
140d02a
Parents:
8f2ce3a
git-author:
Nelson Elhage <nelhage@mit.edu> (12/24/06 17:59:01)
git-committer:
Nelson Elhage <nelhage@mit.edu> (12/26/06 00:59:12)
Message:
Some cleanup of the jabber.pl style
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/jabber.pl

    r8f2ce3a rbed4ff1  
    3939    my $jidStr = shift;
    4040
    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;
     41    my $client = Net::Jabber::Client->new(
     42        owl::getvar('debug') eq 'on'
     43          ? (debuglevel =>  ? 1 : 0,
     44             debugfile => 'jabber.log')
     45          : ()
     46         );
     47
     48    $self->{Client}->{$jidStr} = $client;
     49    $self->{Roster}->{$jidStr} = $client->Roster();
     50    return $client;
    4951}
    5052
     
    5254    my $self = shift;
    5355    my $jidStr = shift;
    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;
     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;
    6463}
    6564
     
    7776    my $self = shift;
    7877    my $jidStr = shift;
    79     foreach my $j ( keys %{ $self->{Client} } ) {
    80         return 1 if ($j eq $jidStr);
    81     }
    82     return 0;
     78    return exists $self->{Client}->{$jidStr};
    8379}
    8480
     
    9288}
    9389
    94 sub getConnRefFromSid {
     90sub getConnectionFromSid {
    9591    my $self = shift;
    9692    my $sid = shift;
    97     foreach my $j ( keys %{ $self->{Client} } ) {
    98         if ($self->{Client}->{$j}->{SESSION}->{id} eq $sid) {
    99             return \$self->{Client}->{$j};
    100         }
     93    foreach my $c (values %{ $self->{Client} }) {
     94        return $c if $c->{SESSION}->{id} eq $sid;
    10195    }
    10296    return undef;
    10397}
    10498
    105 sub getConnRefFromJidStr {
     99sub getConnectionFromJidStr {
    106100    my $self = shift;
    107101    my $jidStr = shift;
    108     foreach my $j ( keys %{ $self->{Client} } ) {
    109         if ($jidStr eq $j) {
    110             return \$self->{Client}->{$j};
    111         }
    112     }
    113     return undef;
    114 }
    115 
    116 sub getRosterRefFromSid {
     102    return $self->{Client}->{$jidStr};
     103}
     104
     105sub getRosterFromSid {
    117106    my $self = shift;
    118107    my $sid = shift;
    119     foreach my $j ( keys %{ $self->{Client} } ) {
    120         if ($self->{Client}->{$j}->{SESSION}->{id} eq $sid) {
    121             return \$self->{Roster}->{$j};
    122         }
     108    foreach my $j ( $self->getJids ) {
     109        return $self->{Roster}->{$j}
     110          if $self->{Client}->{$j}->{SESSION}->{id} eq $sid;
    123111    }
    124112    return undef;
    125113}
    126114
    127 sub getRosterRefFromJidStr {
     115sub getRosterFromJidStr {
    128116    my $self = shift;
    129117    my $jidStr = shift;
    130     foreach my $j ( keys %{ $self->{Client} } ) {
    131         if ($jidStr eq $j) {
    132             return \$self->{Roster}->{$j};
    133         }
    134     }
     118    return $self->{Roster}->{$jidStr};
    135119    return undef;
    136120}
     
    161145
    162146    foreach my $jid ( $conn->getJids() ) {
    163         my $client = $conn->getConnRefFromJidStr($jid);
     147        my $client = $conn->getConnectionFromJidStr($jid);
    164148
    165149        my $status = $client->Process(0);
     
    209193    return "" unless $jid;
    210194    my $blist = "";
    211     my $roster = $conn->getRosterRefFromJidStr($jid);
    212     if ($$roster) {
     195    my $roster = $conn->getRosterFromJidStr($jid);
     196    if ($roster) {
    213197        $blist .= "\n" . boldify("Jabber Roster for $jid\n");
    214198
     
    351335            normal    => sub { owl_jabber::process_incoming_normal_message(@_) }
    352336        );
    353         $$client->SetPresenceCallBacks(
     337        $client->SetPresenceCallBacks(
    354338#            available    => sub { owl_jabber::process_presence_available(@_) },
    355339#            unavailable  => sub { owl_jabber::process_presence_available(@_) },
     
    379363        }
    380364            else {
    381                 ${ $conn->getRosterRefFromJidStr($jidStr) }->fetch();
    382                 $$client->PresenceSend( priority => 1 );
     365                ${ $conn->getRosterFromJidStr($jidStr) }->fetch();
     366                $client->PresenceSend( priority => 1 );
    383367                queue_admin_msg("Connected to jabber as $jidStr");
    384368            }
     
    570554    }
    571555
    572     ${ $conn->getConnRefFromJidStr($jid) }->Send($presence);
     556    $conn->getConnectionFromJidStr($jid)->Send($presence);
    573557}
    574558
     
    579563    die("Usage: jmuc part {muc} [-a account]") unless $muc;
    580564
    581     ${ $conn->getConnRefFromJidStr($jid) }
    582       ->PresenceSend( to => $muc, type => 'unavailable' );
     565    $conn->getConnectionFromJidStr($jid)->PresenceSend( to => $muc, type => 'unavailable' );
    583566    queue_admin_msg("$jid has left $muc.");
    584567}
     
    598581    $x->AddInvite();
    599582    $x->GetInvite()->SetTo($invite_jid);
    600     ${ $conn->getConnRefFromJidStr($jid) }->Send($message);
     583    $conn->getConnectionFromJidStr($jid)->Send($message);
    601584    queue_admin_msg("$jid has invited $invite_jid to $muc.");
    602585}
     
    613596    $x->SetType('submit');
    614597
    615     ${ $conn->getConnRefFromJidStr($jid) }->Send($iq);
     598    $conn->getConnectionFromJidStr($jid)->Send($iq);
    616599    queue_admin_msg("Accepted default instant configuration for $muc");
    617600}
     
    677660    my $baseJid = baseJID($jid);
    678661
    679     my $roster = $conn->getRosterRefFromJidStr($jid);
     662    my $roster = $conn->getRosterFromJidStr($jid);
    680663
    681664    # Adding lots of users with the same name is a bad idea.
     
    686669
    687670    foreach my $to (@ARGV) {
    688         jroster_add($jid, $name, \@groups, $purgeGroups, ($to)) unless ($$roster->exists($to));
     671        jroster_add($jid, $name, \@groups, $purgeGroups, ($to)) unless ($roster->exists($to));
    689672
    690673        $p->SetTo($to);
    691         ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
     674        $conn->getConnectionFromJidStr($jid)->Send($p);
    692675        queue_admin_msg("You ($baseJid) have requested a subscription to ($to)'s presence.");
    693676    }
     
    705688    foreach my $to (@ARGV) {
    706689        $p->SetTo($to);
    707         ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
     690        $conn->getConnectionFromJidStr($jid)->Send($p);
    708691        queue_admin_msg("You ($baseJid) have unsubscribed from ($to)'s presence.");
    709692    }
     
    717700    my $baseJid = baseJID($jid);
    718701
    719     my $roster = $conn->getRosterRefFromJidStr($jid);
     702    my $roster = $conn->getRosterFromJidStr($jid);
    720703
    721704    # Adding lots of users with the same name is a bad idea.
     
    723706
    724707    foreach my $to (@ARGV) {
    725         my %jq  = $$roster->query($to);
     708        my %jq  = $roster->query($to);
    726709        my $iq = new Net::XMPP::IQ;
    727710        $iq->SetType('set');
     
    747730        $item->put_attrib(jid => $to);
    748731        $item->put_attrib(name => $name) if $name;
    749         ${ $conn->getConnRefFromJidStr($jid) }->Send($iq);
     732        $conn->getConnectionFromJidStr($jid)->Send($iq);
    750733        my $msg = "$baseJid: "
    751734          . ($name ? "$name ($to)" : "($to)")
     
    771754    foreach my $to (@ARGV) {
    772755        $item->put_attrib(jid => $to);
    773         ${ $conn->getConnRefFromJidStr($jid) }->Send($iq);
     756        $conn->getConnectionFromJidStr($jid)->Send($iq);
    774757        queue_admin_msg("You ($baseJid) have removed ($to) from your roster.");
    775758    }
     
    787770    foreach my $to (@ARGV) {
    788771        $p->SetTo($to);
    789         ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
     772        $conn->getConnectionFromJidStr($jid)->Send($p);
    790773        queue_admin_msg("($to) has been subscribed to your ($baseJid) presence.");
    791774    }
     
    803786    foreach my $to (@ARGV) {
    804787        $p->SetTo($to);
    805         ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
     788        $conn->getConnectionFromJidStr($jid)->Send($p);
    806789        queue_admin_msg("($to) has been unsubscribed from your ($baseJid) presence.");
    807790    }
     
    833816
    834817    if ($vars{jwrite}{sid} && $conn->sidExists( $vars{jwrite}{sid} )) {
    835         ${ $conn->getConnRefFromSid($vars{jwrite}{sid}) }->Send($j);
     818        $conn->getConnectionFromSid($vars{jwrite}{sid})->Send($j);
    836819    }
    837820    else {
    838         ${ $conn->getConnRefFromJidStr($vars{jwrite}{from}) }->Send($j);
     821        $conn->getConnectionFromJidStr($vars{jwrite}{from})->Send($j);
    839822    }
    840823
     
    968951            $to eq $cJid->GetJID('full')) {
    969952            my $reply = $p->Reply(type=>"unsubscribed");
    970             ${ $conn->getConnRefFromJidStr($jid) }->Send($reply);
     953            $conn->getConnectionFromJidStr($jid)->Send($reply);
    971954            return;
    972955        }
Note: See TracChangeset for help on using the changeset viewer.