Changeset 0dbb7d2


Ignore:
Timestamp:
Dec 22, 2009, 6:37:38 PM (10 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
a2a5236
Parents:
6396c1e
git-author:
Alejandro R. Sedeño <asedeno@mit.edu> (12/22/09 01:15:39)
git-committer:
Alejandro R. Sedeño <asedeno@mit.edu> (12/22/09 18:37:38)
Message:
Factor out some common jabber connect-time code

Call it upon successful connection and reconnection.
Location:
perl/modules/Jabber/lib/BarnOwl/Module
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm

    r2b66c361 r0dbb7d2  
    465465                    }
    466466                );
    467                 my $roster = $conn->getRosterFromJID($jidStr);
    468                 $roster->fetch();
    469                 $client->PresenceSend( priority => 1 );
    470                 my $fullJid = $client->{SESSION}->{FULLJID} || $jidStr;
    471                 $conn->renameConnection($jidStr, $fullJid);
    472                 queue_admin_msg("Connected to jabber as $fullJid");
    473                 # The remove_io_dispatch() method is called from the
    474                 # ConnectionManager's removeConnection() method.
    475                 $client->{fileno} = $client->getSocket()->fileno();
    476                 #queue_admin_msg("Connected to jabber as $fullJid ($client->{fileno})");
    477                 BarnOwl::add_io_dispatch($client->{fileno}, 'r', sub { $client->OwlProcess($fullJid) });
    478 
    479                 # populate completion from roster.
    480                 for my $buddy ( $roster->jids('all') ) {
    481                     my %jq  = $roster->query($buddy);
    482                     my $name = $jq{name} || $buddy->GetUserID();
    483                     $completion_jids{$name} = 1;
    484                     $completion_jids{$buddy->GetJID()} = 1;
    485                 }
    486                 $vars{idletime} |= BarnOwl::getidletime();
    487                 unless (exists $vars{keepAliveTimer}) {
    488                     $vars{keepAliveTimer} = BarnOwl::Timer->new({
    489                         'after' => 5,
    490                         'interval' => 5,
    491                         'cb' => sub { BarnOwl::Module::Jabber::do_keep_alive_and_auto_away(@_) }
    492                                                                 });
    493                 }
     467                $client->onConnect($conn, $jidStr);
    494468            }
    495469        }
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm

    r8590774 r0dbb7d2  
    163163}
    164164
     165=head2 OnConnect
     166
     167Actions to perform on connecting and reconnecting.
     168
     169=cut
     170
     171sub onConnect {
     172    my $self = shift;
     173    my $conn = shift;
     174    my $jidStr = shift;
     175
     176    my $fullJid = $self->{SESSION}->{FULLJID} || $jidStr;
     177    my $roster = $conn->getRosterFromJID($jidStr);
     178
     179    $roster->fetch();
     180    $self->PresenceSend( priority => 1 );
     181
     182    $conn->renameConnection($jidStr, $fullJid);
     183    BarnOwl::admin_message('Jabber', "Connected to jabber as $fullJid");
     184    # The remove_io_dispatch() method is called from the
     185    # ConnectionManager's removeConnection() method.
     186    $self->{fileno} = $self->getSocket()->fileno();
     187    BarnOwl::add_io_dispatch($self->{fileno}, 'r', sub { $self->OwlProcess($fullJid) });
     188
     189    # populate completion from roster.
     190    for my $buddy ( $roster->jids('all') ) {
     191        my %jq  = $roster->query($buddy);
     192        my $name = $jq{name} || $buddy->GetUserID();
     193        $BarnOwl::Module::Jabber::completion_jids{$name} = 1;
     194        $BarnOwl::Module::Jabber::completion_jids{$buddy->GetJID()} = 1;
     195    }
     196    $BarnOwl::Module::Jabber::vars{idletime} |= BarnOwl::getidletime();
     197    unless (exists $BarnOwl::Module::Jabber::vars{keepAliveTimer}) {
     198        $BarnOwl::Module::Jabber::vars{keepAliveTimer} =
     199            BarnOwl::Timer->new({
     200                'after' => 5,
     201                'interval' => 5,
     202                'cb' => sub { BarnOwl::Module::Jabber::do_keep_alive_and_auto_away(@_) }
     203                                });
     204    }
     205}
     206
    165207=head1 SEE ALSO
    166208
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm

    rf1a2736 r0dbb7d2  
    8585    $self->{$jidStr}->{ReconnectAt} = time + $self->{$jidStr}->{ReconnectBackoff};
    8686
    87     my $status = $self->{$jidStr}->{Client}->Connect;
     87    my $client = $self->{$jidStr}->{Client};
     88    my $status = $client->Connect;
    8889    return 0 unless $status;
    8990
    90     my @result = $self->{$jidStr}->{Client}->AuthSend( %{ $self->{$jidStr}->{Auth} } );
     91    my @result = $client->AuthSend( %{ $self->{$jidStr}->{Auth} } );
    9192    if ( !@result || $result[0] ne 'ok' ) {
    9293        $self->removeConnection($jidStr);
     
    9495        return 0;
    9596    }
    96 
    97     BarnOwl::admin_message(Jabber => "Reconnected to jabber as $jidStr");
    98     $self->{$jidStr}{Status} = "available";
    99 
    100     foreach my $muc ($self->{$jidStr}->{Client}->MUCs()) {
     97    $self->{$jidStr}->{Status} = "available";
     98    $client->onConnect($self, $jidStr);
     99    foreach my $muc ($client->MUCs()) {
    101100        $muc->Join($muc->{ARGS});
    102101    }
Note: See TracChangeset for help on using the changeset viewer.