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

barnowl_perlaimdebianrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 892568b was 7f33c18, checked in by Alejandro R. Sedeño <asedeno@mit.edu>, 15 years ago
Net::XMPP::Protocol - Make resource binding note the full jid on connect. BarnOwl::Module::Jabber::ConnectionManager - Allow for connections to be renamed. BarnOwl::Module::Jabber - Rename the connection after connect to match the jid received. This makes Net::XMPP recognize that the server may in fact connect a user under a different resource than the one the user specified. In particular, it works around the crap GoogleTalk appends to the supplied resource.
  • Property mode set to 100644
File size: 2.3 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    $self->{$jidStr}->{Client}->Disconnect()
40      if $self->{$jidStr}->{Client};
41    delete $self->{$jidStr};
42
43    return 1;
44}
45
46sub renameConnection {
47    my $self = shift;
48    my $oldJidStr = shift;
49    my $newJidStr = shift;
50    return 0 unless exists $self->{$oldJidStr};
51    return 0 if $oldJidStr eq $newJidStr;
52
53    $self->{$newJidStr} = $self->{$oldJidStr}; 
54    delete $self->{$oldJidStr};
55    return 1;
56}
57
58sub connected {
59    my $self = shift;
60    return scalar keys %{ $self };
61}
62
63sub getJIDs {
64    my $self = shift;
65    return keys %{ $self };
66}
67
68sub jidExists {
69    my $self = shift;
70    my $jidStr = shift;
71    return exists $self->{$jidStr};
72}
73
74sub sidExists {
75    my $self = shift;
76    my $sid = shift || "";
77    foreach my $c ( values %{ $self } ) {
78        return 1 if ($c->{Client}->{SESSION}->{id} eq $sid);
79    }
80    return 0;
81}
82
83sub getConnectionFromSid {
84    my $self = shift;
85    my $sid = shift;
86    foreach my $c (values %{ $self }) {
87        return $c->{Client} if $c->{Client}->{SESSION}->{id} eq $sid;
88    }
89    return undef;
90}
91
92sub getConnectionFromJID {
93    my $self = shift;
94    my $jid = shift;
95    $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::XMPP::JID');
96    return $self->{$jid}->{Client} if exists $self->{$jid};
97}
98
99sub getRosterFromSid {
100    my $self = shift;
101    my $sid = shift;
102    foreach my $c (values %{ $self }) {
103        return $c->{Roster}
104          if $c->{Client}->{SESSION}->{id} eq $sid;
105    }
106    return undef;
107}
108
109sub getRosterFromJID {
110    my $self = shift;
111    my $jid = shift;
112    $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::XMPP::JID');
113    return $self->{$jid}->{Roster} if exists $self->{$jid};
114}
115
116
1171;
Note: See TracBrowser for help on using the repository browser.