source: perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm @ ec70b79

barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since ec70b79 was 6b580b0, checked in by Alejandro R. Sedeño <asedeno@mit.edu>, 16 years ago
functions.c: * removing the redisplay call from owl_function_lastmsg_noredisplay() select.c: * Watch AIM sockets for writing as well. This speeds up AIM connections significantly. Jabber.pm * keep a copy of the fd around for later. * Process() on mainloop for keep-alives Jabber/ConnectionManager.pm * Use the stored fd to drop the dispatch for a connection. Jabber/Connection.pm * Use the GetSock() abstraction since we have it. * Call the right do_logout when we have trouble.
  • Property mode set to 100644
File size: 2.5 KB
Line 
1use warnings;
2use strict;
3
4=head1 NAME
5
6BarnOwl::Module::Jabber::ConnectionManager
7
8=head1 DESCRIPTION
9
10A class to keep track of all the active connection in the barnowl
11jabber module
12
13=cut
14
15package BarnOwl::Module::Jabber::ConnectionManager;
16
17sub new {
18    my $class = shift;
19    return bless { }, $class;
20}
21
22sub addConnection {
23    my $self = shift;
24    my $jidStr = shift;
25
26    my $client = BarnOwl::Module::Jabber::Connection->new;
27
28    $self->{$jidStr}->{Client} = $client;
29    $self->{$jidStr}->{Roster} = $client->Roster();
30    $self->{$jidStr}->{Status} = "available";
31    return $client;
32}
33
34sub removeConnection {
35    my $self = shift;
36    my $jidStr = shift;
37    return 0 unless exists $self->{$jidStr};
38
39    BarnOwl::remove_dispatch($self->{$jidStr}->{Client}->{fileno}) if $self->{$jidStr}->{Client}->{fileno};
40    $self->{$jidStr}->{Client}->Disconnect()
41      if $self->{$jidStr}->{Client};
42    delete $self->{$jidStr};
43
44    return 1;
45}
46
47sub renameConnection {
48    my $self = shift;
49    my $oldJidStr = shift;
50    my $newJidStr = shift;
51    return 0 unless exists $self->{$oldJidStr};
52    return 0 if $oldJidStr eq $newJidStr;
53
54    $self->{$newJidStr} = $self->{$oldJidStr};
55    delete $self->{$oldJidStr};
56    return 1;
57}
58
59sub connected {
60    my $self = shift;
61    return scalar keys %{ $self };
62}
63
64sub getJIDs {
65    my $self = shift;
66    return keys %{ $self };
67}
68
69sub jidExists {
70    my $self = shift;
71    my $jidStr = shift;
72    return exists $self->{$jidStr};
73}
74
75sub sidExists {
76    my $self = shift;
77    my $sid = shift || "";
78    foreach my $c ( values %{ $self } ) {
79        return 1 if ($c->{Client}->{SESSION}->{id} eq $sid);
80    }
81    return 0;
82}
83
84sub getConnectionFromSid {
85    my $self = shift;
86    my $sid = shift;
87    foreach my $c (values %{ $self }) {
88        return $c->{Client} if $c->{Client}->{SESSION}->{id} eq $sid;
89    }
90    return undef;
91}
92
93sub getConnectionFromJID {
94    my $self = shift;
95    my $jid = shift;
96    $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::XMPP::JID');
97    return $self->{$jid}->{Client} if exists $self->{$jid};
98}
99
100sub getRosterFromSid {
101    my $self = shift;
102    my $sid = shift;
103    foreach my $c (values %{ $self }) {
104        return $c->{Roster}
105          if $c->{Client}->{SESSION}->{id} eq $sid;
106    }
107    return undef;
108}
109
110sub getRosterFromJID {
111    my $self = shift;
112    my $jid = shift;
113    $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::XMPP::JID');
114    return $self->{$jid}->{Roster} if exists $self->{$jid};
115}
116
117
1181;
Note: See TracBrowser for help on using the repository browser.