Changeset 9f183ff for perl/modules
- Timestamp:
- Nov 10, 2006, 12:38:53 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:
- b405ff6
- Parents:
- 71e1e80
- git-author:
- Nelson Elhage <nelhage@mit.edu> (11/10/06 12:38:43)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (11/10/06 12:38:53)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/jabber.pl
r6df381b r9f183ff 1 1 package owl_jabber; 2 use warnings; 3 use strict; 4 2 5 use Authen::SASL qw(Perl); 3 6 use Net::Jabber; … … 38 41 } 39 42 } 43 40 44 push @::onStartSubs, sub { owl_jabber::onStart(@_) }; 41 45 … … 221 225 if($result[0] ne 'ok') 222 226 { 223 if ($result[1] = "401")227 if ($result[1] == 401) 224 228 { 225 229 $vars{jlogin_jid} = $jidStr; … … 316 320 else 317 321 { 318 if ($_[1] ='-a') #All accounts.322 if ($_[1] eq '-a') #All accounts. 319 323 { 320 324 foreach my $jid (keys %$connections) … … 364 368 my @args = @_; 365 369 shift; 366 local @ ::ARGV = @_;370 local @ARGV = @_; 367 371 my $gc; 368 372 GetOptions('thread=s' => \$jwrite_thread, … … 372 376 $jwrite_type = 'groupchat' if $gc; 373 377 374 if (scalar @ ::ARGV != 1)378 if (scalar @ARGV != 1) 375 379 { 376 380 owl::error("Usage: jwrite JID [-g] [-t thread] [-s 'subject'] [-a account]"); … … 379 383 else 380 384 { 381 $jwrite_to = @::ARGV[0];385 $jwrite_to = shift @ARGV; 382 386 } 383 387 … … 410 414 } 411 415 412 #XXX Todo: Split off sub-commands into their own subroutines.413 # It'll make them more managable.414 416 sub cmd_jmuc 415 417 { 416 if (!connected()) 417 { 418 owl::error("You are not logged in to Jabber."); 419 return; 420 } 421 418 die "You are not logged in to Jabber" unless connected(); 422 419 my $ocmd = shift; 423 420 my $cmd = shift; … … 429 426 430 427 my %jmuc_commands = ( 431 join => \&jmuc_join, 432 part => \&jmuc_part, 433 invite => \&jmuc_invite 428 join => \&jmuc_join, 429 part => \&jmuc_part, 430 invite => \&jmuc_invite, 431 configure => \&jmuc_configure 434 432 ); 435 433 my $func = $jmuc_commands{$cmd}; 436 434 if(!$func) { 437 435 owl::error("jmuc: Unknown command: $cmd"); 438 } else { 439 return $func->(@_); 436 return; 437 } 438 439 { 440 local @ARGV = @_; 441 my $jid; 442 my $muc; 443 my $m = owl::getcurmsg(); 444 if ($m->is_jabber && $m->{jtype} eq 'groupchat') 445 { 446 $muc = $m->{room}; 447 $jid = $m->{to}; 448 } 449 450 my $getopt = Getopt::Long::Parser->new; 451 $getopt->configure('pass_through'); 452 $getopt->getoptions('account=s' => \$jid); 453 $jid ||= defaultJID(); 454 if($jid) { 455 $jid = resolveJID($jid); 456 return unless $jid; 457 } else { 458 owl::error('You must specify an account with -a {jid}'); 459 } 460 return $func->($jid, $muc, @ARGV); 440 461 } 441 462 } 442 463 443 464 sub jmuc_join { 444 local @ARGV = @_; 465 my ($jid, $muc, @args) = @_; 466 local @ARGV = @args; 445 467 my $password; 446 my $jid; 447 GetOptions('password=s' => \$password, 448 'account=s' => \$jid); 449 450 my $muc; 451 if (scalar @ARGV != 1) 452 { 453 owl::error('Usage: jmuc join {muc} [-p password] [-a account]'); 454 return; 455 } 456 else 457 { 458 $muc = @ARGV[0]; 459 } 460 461 if (!$jid) 462 { 463 if (connected() == 1) 464 { 465 $jid = (keys %$connections)[0]; 466 } 467 else 468 { 469 owl::error("Please specify an account with -a {jid}"); 470 return; 471 } 472 } 473 else 474 { 475 $jid = resolveJID($jid); 476 return unless $jid; 477 } 468 GetOptions('password=s' => \$password); 469 470 $muc = shift @ARGV or die("Usage: jmuc join {muc} [-p password] [-a account]"); 478 471 479 472 my $x = new XML::Stream::Node('x'); … … 481 474 $x->add_child('history')->put_attrib(maxchars => '0'); 482 475 483 if ($ jmuc_password)484 { 485 $x->add_child('password')->add_cdata($ jmuc_password);476 if ($password) 477 { 478 $x->add_child('password')->add_cdata($password); 486 479 } 487 480 … … 493 486 494 487 sub jmuc_part { 495 my $muc; 496 my $jid; 497 if (!$_[0]) 498 { 499 my $m = owl::getcurmsg(); 500 if ($m->is_jabber && $m->{jtype} eq 'groupchat') 501 { 502 $muc = $m->{room}; 503 $jid = $m->{to}; 504 } 505 else 506 { 507 owl::error('Usage: jmuc part {muc} [-a account]'); 508 return; 509 } 510 } 511 else 512 { 513 local @ARGV = @_; 514 GetOptions('account=s' => \$jid); 515 if (scalar @ARGV != 1) 516 { 517 owl::error('Usage: jmuc part {muc} [-a account]'); 518 return; 519 } 520 else 521 { 522 $muc = @ARGV[0]; 523 } 524 if (!$jid) 525 { 526 if (connected() == 1) 527 { 528 $jid = (keys %$connections)[0]; 529 } 530 else 531 { 532 owl::error("Please specify an account with -a {jid}"); 533 return; 534 } 535 } 536 else 537 { 538 $jid = resolveJID($jid); 539 return unless $jid; 540 } 541 } 488 my ($jid, $muc, @args) = @_; 489 490 $muc = shift @args if scalar @args; 491 die("Usage: jmuc part {muc} [-a account]") unless $muc; 492 542 493 $connections->{$jid}->{client}->PresenceSend(to => $muc, type => 'unavailable'); 543 494 queue_admin_msg("$jid has left $muc."); … … 546 497 sub jmuc_invite 547 498 { 548 my $jid; 549 my $invite_jid; 550 my $muc; 551 552 owl::error('Usage: jmuc invite {jid} [muc] [-a account]') if (!$_[0]); 553 $invite_jid = $_[0]; 554 555 if (!@_[1]) 556 { 557 my $m = owl::getcurmsg(); 558 if ($m->is_jabber && $m->{jtype} eq 'groupchat') 559 { 560 $muc = $m->{room}; 561 $jid = $m->{to}; 562 } 563 else 564 { 565 owl::error('Usage: jmuc invite {jid} [muc] [-a account]'); 566 return; 567 } 568 } 569 else 570 { 571 local @ARGV = @_; 572 GetOptions('account=s' => \$jid); 573 if (scalar @ARGV != 2) 574 { 575 owl::error('Usage: jmuc invite {jid} [muc] [-a account]'); 576 return; 577 } 578 else 579 { 580 ($muc, $invite_jid) = @ARGV; 581 } 582 if (!$jid) 583 { 584 if (connected() == 1) 585 { 586 $jid = (keys %$connections)[0]; 587 } 588 else 589 { 590 owl::error("Please specify an account with -a {jid}"); 591 return; 592 } 593 } 594 else 595 { 596 $jid = resolveJID($jid); 597 return unless $jid; 598 } 599 } 499 my ($jid, $muc, @args) = @_; 500 501 my $invite_jid = shift @args; 502 $muc = shift @args if scalar @args; 503 504 die('Usage: jmuc invite {jid} [muc] [-a account]') unless $muc && $invite_jid; 600 505 601 506 my $x = new XML::Stream::Node('x'); … … 608 513 $connections->{$jid}->{client}->Send($message); 609 514 queue_admin_msg("$jid has invited $invite_jid to $muc."); 515 } 516 517 Net::Jabber::Namespaces::add_ns( 518 ns => "http://jabber.org/protocol/muc#owner", 519 tag => 'query', 520 ); 521 522 sub jmuc_configure { 523 my ($jid, $muc, @args) = @_; 524 $muc = shift @args if scalar @args; 525 die("Usage: jmuc configure [muc]") unless $muc; 526 my $iq = Net::Jabber::IQ->new(); 527 $iq->SetTo($muc); 528 $iq->SetType('set'); 529 my $query = $iq->NewQuery("http://jabber.org/protocol/muc#owner"); 530 my $x = $query->NewChild("jabber:x:data"); 531 $x->SetType('submit'); 532 533 $connections->{$jid}->{client}->Send($iq); 534 queue_admin_msg("Accepted default instant configuration for $muc"); 610 535 } 611 536 … … 776 701 sub boldify($) 777 702 { 778 $str = shift;703 my $str = shift; 779 704 780 705 return '@b('.$str.')' if ( $str !~ /\)/ ); … … 807 732 { 808 733 return scalar keys %$connections; 734 } 735 736 sub defaultJID { 737 return (keys %$connections)[0] if (connected() == 1); 738 return; 809 739 } 810 740
Note: See TracChangeset
for help on using the changeset viewer.