Changeset 455f1ab for perl/modules
- Timestamp:
- Jan 23, 2007, 6:26:41 PM (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:
- 65581e9
- Parents:
- 17b7fc5
- git-author:
- Nelson Elhage <nelhage@mit.edu> (01/23/07 17:35:07)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (01/23/07 18:26:41)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/jabber.pl
r1d8503b r455f1ab 183 183 } 184 184 185 sub getConnectionFromJidStr { 186 my $self = shift; 187 my $jidStr = shift; 188 return $self->{$jidStr}->{Client}; 185 sub getConnectionFromJID { 186 my $self = shift; 187 my $jid = shift; 188 $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::XMPP::JID'); 189 return $self->{$jid}->{Client} if exists $self->{$jid}; 189 190 } 190 191 … … 199 200 } 200 201 201 sub getRosterFromJidStr { 202 my $self = shift; 203 my $jidStr = shift; 204 return $self->{$jidStr}->{Roster}; 202 sub getRosterFromJID { 203 my $self = shift; 204 my $jid = shift; 205 $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::XMPP::JID'); 206 return $self->{$jid}->{Roster} if exists $self->{$jid}; 205 207 } 206 208 ################################################################################ … … 246 248 247 249 foreach my $jid ( $conn->getJids() ) { 248 my $client = $conn->getConnectionFromJ idStr($jid);250 my $client = $conn->getConnectionFromJID($jid); 249 251 250 252 unless($client) { … … 304 306 sub getSingleBuddyList { 305 307 my $jid = shift; 306 $jid = resolve JID($jid);308 $jid = resolveConnectedJID($jid); 307 309 return "" unless $jid; 308 310 my $blist = ""; 309 my $roster = $conn->getRosterFromJ idStr($jid);311 my $roster = $conn->getRosterFromJID($jid); 310 312 if ($roster) { 311 313 $blist .= "\n" . boldify("Jabber Roster for $jid\n"); … … 354 356 { 355 357 summary => "Send a Jabber Message", 356 usage => "jwrite JID [- g] [-t thread] [-s subject]"358 usage => "jwrite JID [-t thread] [-s subject]" 357 359 } 358 360 ); … … 480 482 BarnOwl::error( "Error in connect: " . join( " ", @result ) ); 481 483 } else { 482 $conn->getRosterFromJ idStr($jidStr)->fetch();484 $conn->getRosterFromJID($jidStr)->fetch(); 483 485 $client->PresenceSend( priority => 1 ); 484 486 queue_admin_msg("Connected to jabber as $jidStr"); … … 524 526 else #One account. 525 527 { 526 my $jid = resolve JID( $_[1] );528 my $jid = resolveConnectedJID( $_[1] ); 527 529 do_logout($jid) if ( $jid ne '' ); 528 530 } … … 555 557 my $jwrite_thread = ""; 556 558 my $jwrite_subject = ""; 559 my $to; 557 560 my $jwrite_type = "chat"; 558 561 … … 566 569 'account=s' => \$jwrite_from, 567 570 'id=s' => \$jwrite_sid, 568 'groupchat' => \$gc569 571 ); 570 572 $jwrite_type = 'groupchat' if $gc; … … 572 574 if ( scalar @ARGV != 1 ) { 573 575 BarnOwl::error( 574 "Usage: jwrite JID [- g] [-t thread] [-s 'subject'] [-a account]");576 "Usage: jwrite JID [-t thread] [-s 'subject'] [-a account]"); 575 577 return; 576 578 } 577 579 else { 578 $jwrite_to = shift @ARGV; 579 } 580 581 if ( !$jwrite_from ) { 582 if ( $conn->connected() == 1 ) { 583 $jwrite_from = ( $conn->getJids() )[0]; 584 } 585 else { 586 BarnOwl::error("Please specify an account with -a JID"); 587 return; 588 } 589 } 590 else { 591 $jwrite_from = resolveJID($jwrite_from); 592 return unless $jwrite_from; 593 } 594 580 $to = shift @ARGV; 581 } 582 583 ($jwrite_from, $jwrite_to, $jwrite_type) = guess_jwrite($jwrite_from, $to); 584 585 unless($jwrite_from && $jwrite_to) { 586 die("Unable to resolve JID $to"); 587 } 588 595 589 $vars{jwrite} = { 596 590 to => $jwrite_to, … … 605 599 "Type your message below. End with a dot on a line by itself. ^C will quit." 606 600 ); 607 BarnOwl::start_edit_win( join( ' ', @args ), \&process_owl_jwrite ); 601 my $cmd = "jwrite $jwrite_to -a $jwrite_from"; 602 $cmd .= " -t $jwrite_thread" if $jwrite_thread; 603 $cmd .= " -t $jwrite_subject" if $jwrite_subject; 604 BarnOwl::start_edit_win( $cmd, \&process_owl_jwrite ); 608 605 } 609 606 … … 646 643 $jid ||= defaultJID(); 647 644 if ($jid) { 648 $jid = resolve JID($jid);645 $jid = resolveConnectedJID($jid); 649 646 return unless $jid; 650 647 } … … 665 662 or die("Usage: jmuc join MUC [-p password] [-a account]"); 666 663 667 $conn->getConnectionFromJ idStr($jid)->MUCJoin(Jid => $muc,664 $conn->getConnectionFromJID($jid)->MUCJoin(Jid => $muc, 668 665 Password => $password, 669 666 History => { … … 679 676 die("Usage: jmuc part MUC [-a account]") unless $muc; 680 677 681 $conn->getConnectionFromJ idStr($jid)->MUCLeave(JID => $muc);678 $conn->getConnectionFromJID($jid)->MUCLeave(JID => $muc); 682 679 queue_admin_msg("$jid has left $muc."); 683 680 } … … 697 694 $x->AddInvite(); 698 695 $x->GetInvite()->SetTo($invite_jid); 699 $conn->getConnectionFromJ idStr($jid)->Send($message);696 $conn->getConnectionFromJID($jid)->Send($message); 700 697 queue_admin_msg("$jid has invited $invite_jid to $muc."); 701 698 } … … 712 709 $x->SetType('submit'); 713 710 714 $conn->getConnectionFromJ idStr($jid)->Send($iq);711 $conn->getConnectionFromJID($jid)->Send($iq); 715 712 queue_admin_msg("Accepted default instant configuration for $muc"); 716 713 } … … 722 719 die("Usage: jmuc presence MUC") unless $muc; 723 720 724 my $m = $conn->getConnectionFromJ idStr($jid)->FindMUC(jid => $muc);721 my $m = $conn->getConnectionFromJID($jid)->FindMUC(jid => $muc); 725 722 die("No such muc: $muc") unless $m; 726 723 … … 772 769 $jid ||= defaultJID(); 773 770 if ($jid) { 774 $jid = resolve JID($jid);771 $jid = resolveConnectedJID($jid); 775 772 return unless $jid; 776 773 } … … 789 786 my $baseJid = baseJID($jid); 790 787 791 my $roster = $conn->getRosterFromJ idStr($jid);788 my $roster = $conn->getRosterFromJID($jid); 792 789 793 790 # Adding lots of users with the same name is a bad idea. … … 801 798 802 799 $p->SetTo($to); 803 $conn->getConnectionFromJ idStr($jid)->Send($p);800 $conn->getConnectionFromJID($jid)->Send($p); 804 801 queue_admin_msg("You ($baseJid) have requested a subscription to ($to)'s presence."); 805 802 } … … 817 814 foreach my $to (@ARGV) { 818 815 $p->SetTo($to); 819 $conn->getConnectionFromJ idStr($jid)->Send($p);816 $conn->getConnectionFromJID($jid)->Send($p); 820 817 queue_admin_msg("You ($baseJid) have unsubscribed from ($to)'s presence."); 821 818 } … … 829 826 my $baseJid = baseJID($jid); 830 827 831 my $roster = $conn->getRosterFromJ idStr($jid);828 my $roster = $conn->getRosterFromJID($jid); 832 829 833 830 # Adding lots of users with the same name is a bad idea. … … 859 856 $item->put_attrib(jid => $to); 860 857 $item->put_attrib(name => $name) if $name; 861 $conn->getConnectionFromJ idStr($jid)->Send($iq);858 $conn->getConnectionFromJID($jid)->Send($iq); 862 859 my $msg = "$baseJid: " 863 860 . ($name ? "$name ($to)" : "($to)") … … 883 880 foreach my $to (@ARGV) { 884 881 $item->put_attrib(jid => $to); 885 $conn->getConnectionFromJ idStr($jid)->Send($iq);882 $conn->getConnectionFromJID($jid)->Send($iq); 886 883 queue_admin_msg("You ($baseJid) have removed ($to) from your roster."); 887 884 } … … 899 896 foreach my $to (@ARGV) { 900 897 $p->SetTo($to); 901 $conn->getConnectionFromJ idStr($jid)->Send($p);898 $conn->getConnectionFromJID($jid)->Send($p); 902 899 queue_admin_msg("($to) has been subscribed to your ($baseJid) presence."); 903 900 } … … 915 912 foreach my $to (@ARGV) { 916 913 $p->SetTo($to); 917 $conn->getConnectionFromJ idStr($jid)->Send($p);914 $conn->getConnectionFromJID($jid)->Send($p); 918 915 queue_admin_msg("($to) has been unsubscribed from your ($baseJid) presence."); 919 916 } … … 947 944 } 948 945 else { 949 $conn->getConnectionFromJ idStr($vars{jwrite}{from})->Send($j);946 $conn->getConnectionFromJID($vars{jwrite}{from})->Send($j); 950 947 } 951 948 … … 1083 1080 $to eq $cJid->GetJID('full')) { 1084 1081 my $reply = $p->Reply(type=>"unsubscribed"); 1085 $conn->getConnectionFromJ idStr($jid)->Send($reply);1082 $conn->getConnectionFromJID($jid)->Send($reply); 1086 1083 return; 1087 1084 } … … 1157 1154 my $nick = $props{nick} = $from->GetResource(); 1158 1155 my $room = $props{room} = $from->GetJID('base'); 1159 $props{replycmd} = "jwrite -g$room";1156 $props{replycmd} = "jwrite $room"; 1160 1157 $props{replycmd} .= 1161 1158 " -a " . ( ( $dir eq 'out' ) ? $props{from} : $props{to} ); … … 1243 1240 } 1244 1241 1245 sub resolve JID {1242 sub resolveConnectedJID { 1246 1243 my $givenJidStr = shift; 1247 1244 my $givenJid = new Net::XMPP::JID; … … 1252 1249 # Specified account exists 1253 1250 return $givenJidStr if ($conn->jidExists($givenJidStr) ); 1254 BarnOwl::error("Invalid account: $givenJidStr");1251 die("Invalid account: $givenJidStr"); 1255 1252 } 1256 1253 … … 1274 1271 # Need further disambiguation. 1275 1272 if ($ambiguous) { 1276 queue_admin_msg($errStr);1273 die($errStr); 1277 1274 } 1278 1275 1279 1276 # Not one of ours. 1280 1277 elsif ( $matchingJid eq "" ) { 1281 BarnOwl::error("Invalid account: $givenJidStr");1278 die("Invalid account: $givenJidStr"); 1282 1279 } 1283 1280 … … 1288 1285 } 1289 1286 return ""; 1287 } 1288 1289 sub resolveDestJID { 1290 my ($to, $from) = @_; 1291 my $jid = Net::Jabber::JID->new($to); 1292 if($jid->GetResource()) { 1293 return $jid->GetJID('full'); 1294 } 1295 1296 my $roster = $conn->getRosterFromJID($from); 1297 my @jids = $roster->jids('all'); 1298 for my $j (@jids) { 1299 if($roster->query($j, 'name') eq $to) { 1300 return $j->GetJID('full'); 1301 } 1302 } 1303 1304 return undef; 1305 } 1306 1307 sub resolveType { 1308 my $to = shift; 1309 my $from = shift; 1310 my @mucs = $conn->getConnectionFromJID($from)->MUCs; 1311 if(grep {$_->BaseJID eq $to } @mucs) { 1312 return 'groupchat'; 1313 } else { 1314 return 'chat'; 1315 } 1316 } 1317 1318 sub guess_jwrite { 1319 # Heuristically guess what jids a jwrite was meant to be going to/from 1320 my ($from, $to) = (@_); 1321 my ($from_jid, $to_jid); 1322 if($from) { 1323 $from_jid = resolveConnectedJID($from); 1324 die("Unable to resolve account $from") unless $from_jid; 1325 $to_jid = resolveDestJID($to, $from_jid); 1326 } elsif($to =~ /@/) { 1327 $to_jid = $to; 1328 $from_jid = defaultJID(); 1329 die("You must specify a JID with -a") unless $from_jid; 1330 } else { 1331 for my $f ($conn->getJids) { 1332 $to_jid = resolveDestJID($to, $f); 1333 if(defined($to_jid)) { 1334 $from_jid = $f; 1335 } 1336 } 1337 die("Unable to resolve JID $to") unless $to_jid; 1338 } 1339 1340 my $type = resolveType($to_jid, $from_jid); 1341 return ($from_jid, $to_jid, $type); 1290 1342 } 1291 1343
Note: See TracChangeset
for help on using the changeset viewer.