Changeset bed4ff1 for perl/modules/jabber.pl
- Timestamp:
- Dec 26, 2006, 12:59:12 AM (18 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/jabber.pl
r8f2ce3a rbed4ff1 39 39 my $jidStr = shift; 40 40 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; 49 51 } 50 52 … … 52 54 my $self = shift; 53 55 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; 64 63 } 65 64 … … 77 76 my $self = shift; 78 77 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}; 83 79 } 84 80 … … 92 88 } 93 89 94 sub getConn RefFromSid {90 sub getConnectionFromSid { 95 91 my $self = shift; 96 92 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; 101 95 } 102 96 return undef; 103 97 } 104 98 105 sub getConn RefFromJidStr {99 sub getConnectionFromJidStr { 106 100 my $self = shift; 107 101 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 105 sub getRosterFromSid { 117 106 my $self = shift; 118 107 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; 123 111 } 124 112 return undef; 125 113 } 126 114 127 sub getRoster RefFromJidStr {115 sub getRosterFromJidStr { 128 116 my $self = shift; 129 117 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}; 135 119 return undef; 136 120 } … … 161 145 162 146 foreach my $jid ( $conn->getJids() ) { 163 my $client = $conn->getConn RefFromJidStr($jid);147 my $client = $conn->getConnectionFromJidStr($jid); 164 148 165 149 my $status = $client->Process(0); … … 209 193 return "" unless $jid; 210 194 my $blist = ""; 211 my $roster = $conn->getRoster RefFromJidStr($jid);212 if ($ $roster) {195 my $roster = $conn->getRosterFromJidStr($jid); 196 if ($roster) { 213 197 $blist .= "\n" . boldify("Jabber Roster for $jid\n"); 214 198 … … 351 335 normal => sub { owl_jabber::process_incoming_normal_message(@_) } 352 336 ); 353 $ $client->SetPresenceCallBacks(337 $client->SetPresenceCallBacks( 354 338 # available => sub { owl_jabber::process_presence_available(@_) }, 355 339 # unavailable => sub { owl_jabber::process_presence_available(@_) }, … … 379 363 } 380 364 else { 381 ${ $conn->getRoster RefFromJidStr($jidStr) }->fetch();382 $ $client->PresenceSend( priority => 1 );365 ${ $conn->getRosterFromJidStr($jidStr) }->fetch(); 366 $client->PresenceSend( priority => 1 ); 383 367 queue_admin_msg("Connected to jabber as $jidStr"); 384 368 } … … 570 554 } 571 555 572 $ { $conn->getConnRefFromJidStr($jid) }->Send($presence);556 $conn->getConnectionFromJidStr($jid)->Send($presence); 573 557 } 574 558 … … 579 563 die("Usage: jmuc part {muc} [-a account]") unless $muc; 580 564 581 ${ $conn->getConnRefFromJidStr($jid) } 582 ->PresenceSend( to => $muc, type => 'unavailable' ); 565 $conn->getConnectionFromJidStr($jid)->PresenceSend( to => $muc, type => 'unavailable' ); 583 566 queue_admin_msg("$jid has left $muc."); 584 567 } … … 598 581 $x->AddInvite(); 599 582 $x->GetInvite()->SetTo($invite_jid); 600 $ { $conn->getConnRefFromJidStr($jid) }->Send($message);583 $conn->getConnectionFromJidStr($jid)->Send($message); 601 584 queue_admin_msg("$jid has invited $invite_jid to $muc."); 602 585 } … … 613 596 $x->SetType('submit'); 614 597 615 $ { $conn->getConnRefFromJidStr($jid) }->Send($iq);598 $conn->getConnectionFromJidStr($jid)->Send($iq); 616 599 queue_admin_msg("Accepted default instant configuration for $muc"); 617 600 } … … 677 660 my $baseJid = baseJID($jid); 678 661 679 my $roster = $conn->getRoster RefFromJidStr($jid);662 my $roster = $conn->getRosterFromJidStr($jid); 680 663 681 664 # Adding lots of users with the same name is a bad idea. … … 686 669 687 670 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)); 689 672 690 673 $p->SetTo($to); 691 $ { $conn->getConnRefFromJidStr($jid) }->Send($p);674 $conn->getConnectionFromJidStr($jid)->Send($p); 692 675 queue_admin_msg("You ($baseJid) have requested a subscription to ($to)'s presence."); 693 676 } … … 705 688 foreach my $to (@ARGV) { 706 689 $p->SetTo($to); 707 $ { $conn->getConnRefFromJidStr($jid) }->Send($p);690 $conn->getConnectionFromJidStr($jid)->Send($p); 708 691 queue_admin_msg("You ($baseJid) have unsubscribed from ($to)'s presence."); 709 692 } … … 717 700 my $baseJid = baseJID($jid); 718 701 719 my $roster = $conn->getRoster RefFromJidStr($jid);702 my $roster = $conn->getRosterFromJidStr($jid); 720 703 721 704 # Adding lots of users with the same name is a bad idea. … … 723 706 724 707 foreach my $to (@ARGV) { 725 my %jq = $ $roster->query($to);708 my %jq = $roster->query($to); 726 709 my $iq = new Net::XMPP::IQ; 727 710 $iq->SetType('set'); … … 747 730 $item->put_attrib(jid => $to); 748 731 $item->put_attrib(name => $name) if $name; 749 $ { $conn->getConnRefFromJidStr($jid) }->Send($iq);732 $conn->getConnectionFromJidStr($jid)->Send($iq); 750 733 my $msg = "$baseJid: " 751 734 . ($name ? "$name ($to)" : "($to)") … … 771 754 foreach my $to (@ARGV) { 772 755 $item->put_attrib(jid => $to); 773 $ { $conn->getConnRefFromJidStr($jid) }->Send($iq);756 $conn->getConnectionFromJidStr($jid)->Send($iq); 774 757 queue_admin_msg("You ($baseJid) have removed ($to) from your roster."); 775 758 } … … 787 770 foreach my $to (@ARGV) { 788 771 $p->SetTo($to); 789 $ { $conn->getConnRefFromJidStr($jid) }->Send($p);772 $conn->getConnectionFromJidStr($jid)->Send($p); 790 773 queue_admin_msg("($to) has been subscribed to your ($baseJid) presence."); 791 774 } … … 803 786 foreach my $to (@ARGV) { 804 787 $p->SetTo($to); 805 $ { $conn->getConnRefFromJidStr($jid) }->Send($p);788 $conn->getConnectionFromJidStr($jid)->Send($p); 806 789 queue_admin_msg("($to) has been unsubscribed from your ($baseJid) presence."); 807 790 } … … 833 816 834 817 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); 836 819 } 837 820 else { 838 $ { $conn->getConnRefFromJidStr($vars{jwrite}{from}) }->Send($j);821 $conn->getConnectionFromJidStr($vars{jwrite}{from})->Send($j); 839 822 } 840 823 … … 968 951 $to eq $cJid->GetJID('full')) { 969 952 my $reply = $p->Reply(type=>"unsubscribed"); 970 $ { $conn->getConnRefFromJidStr($jid) }->Send($reply);953 $conn->getConnectionFromJidStr($jid)->Send($reply); 971 954 return; 972 955 }
Note: See TracChangeset
for help on using the changeset viewer.