Changeset d609dd6 for perl/modules/jabber.pl
- Timestamp:
- Jan 10, 2007, 11:12:05 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:
- f4d32cd
- Parents:
- 8203afd
- git-author:
- Nelson Elhage <nelhage@mit.edu> (01/10/07 11:11:57)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (01/10/07 11:12:05)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/jabber.pl
rffe70f9 rd609dd6 40 40 41 41 my %args = (); 42 if( owl::getvar('debug') eq 'on') {42 if(BarnOwl::getvar('debug') eq 'on') { 43 43 $args{debuglevel} = 1; 44 44 $args{debugfile} = 'jabber.log'; … … 127 127 128 128 sub onStart { 129 if ( eval { \& owl::queue_message } ) {129 if ( eval { \&BarnOwl::queue_message } ) { 130 130 register_owl_commands(); 131 131 push @::onMainLoop, sub { owl_jabber::onMainLoop(@_) }; … … 133 133 } else { 134 134 # Our owl doesn't support queue_message. Unfortunately, this 135 # means it probably *also* doesn't support owl::error. So just135 # means it probably *also* doesn't support BarnOwl::error. So just 136 136 # give up silently. 137 137 } … … 148 148 my $status = $client->Process(0); 149 149 if ( !defined($status) ) { 150 owl::error("Jabber account $jid disconnected!");150 BarnOwl::error("Jabber account $jid disconnected!"); 151 151 do_logout($jid); 152 152 } … … 225 225 ### Owl Commands 226 226 sub register_owl_commands() { 227 owl::new_command(227 BarnOwl::new_command( 228 228 jabberlogin => \&cmd_login, 229 229 { summary => "Log into jabber", }, 230 230 { usage => "jabberlogin JID" } 231 231 ); 232 owl::new_command(232 BarnOwl::new_command( 233 233 jabberlogout => \&cmd_logout, 234 234 { summary => "Log out of jabber" } 235 235 ); 236 owl::new_command(236 BarnOwl::new_command( 237 237 jwrite => \&cmd_jwrite, 238 238 { … … 241 241 } 242 242 ); 243 owl::new_command(243 BarnOwl::new_command( 244 244 jlist => \&cmd_jlist, 245 245 { … … 248 248 } 249 249 ); 250 owl::new_command(250 BarnOwl::new_command( 251 251 jmuc => \&cmd_jmuc, 252 252 { … … 258 258 . " The muc is taken from the current message if not supplied.\n\n" 259 259 . "invite JID MUC\n" 260 . " Invite {jid} to [muc].\n"260 . " Invite JID to MUC.\n" 261 261 . " The muc is taken from the current message if not supplied.\n\n" 262 262 . "configure MUC\n" … … 267 267 } 268 268 ); 269 owl::new_command(269 BarnOwl::new_command( 270 270 jroster => \&cmd_jroster, 271 271 { … … 289 289 290 290 if ( !$uid || !$componentname ) { 291 owl::error("usage: $cmd {jid}");291 BarnOwl::error("usage: $cmd JID"); 292 292 return; 293 293 } 294 294 295 295 if ( $conn->jidExists($jidStr) ) { 296 owl::error("Already logged in as $jidStr.");296 BarnOwl::error("Already logged in as $jidStr."); 297 297 return; 298 298 } … … 321 321 my $jidStr = $vars{jlogin_jid}; 322 322 if ( !$jidStr && $vars{jlogin_havepass}) { 323 owl::error("Got password but have no jid!");323 BarnOwl::error("Got password but have no jid!"); 324 324 } 325 325 else … … 348 348 if ( !$status ) { 349 349 $conn->removeConnection($jidStr); 350 owl::error("We failed to connect");350 BarnOwl::error("We failed to connect"); 351 351 } else { 352 352 my @result = $client->AuthSend( %{ $vars{jlogin_authhash} } ); 353 353 354 354 if ( !@result || $result[0] ne 'ok' ) { 355 if ( !$vars{jlogin_havepass} && ( $#result == -1|| $result[0] eq '401' ) ) {355 if ( !$vars{jlogin_havepass} && ( !@result || $result[0] eq '401' ) ) { 356 356 $vars{jlogin_havepass} = 1; 357 357 $conn->removeConnection($jidStr); 358 owl::start_password( "Password for $jidStr: ", \&do_login );358 BarnOwl::start_password( "Password for $jidStr: ", \&do_login ); 359 359 return ""; 360 360 } 361 361 $conn->removeConnection($jidStr); 362 owl::error( "Error in connect: " . join( " ", @result ) );362 BarnOwl::error( "Error in connect: " . join( " ", @result ) ); 363 363 } else { 364 364 $conn->getRosterFromJidStr($jidStr)->fetch(); … … 420 420 sub cmd_jlist { 421 421 if ( !( scalar $conn->getJids() ) ) { 422 owl::error("You are not logged in to Jabber.");422 BarnOwl::error("You are not logged in to Jabber."); 423 423 return; 424 424 } 425 owl::popless_ztext( onGetBuddyList() );425 BarnOwl::popless_ztext( onGetBuddyList() ); 426 426 } 427 427 428 428 sub cmd_jwrite { 429 429 if ( !$conn->connected() ) { 430 owl::error("You are not logged in to Jabber.");430 BarnOwl::error("You are not logged in to Jabber."); 431 431 return; 432 432 } … … 453 453 454 454 if ( scalar @ARGV != 1 ) { 455 owl::error(455 BarnOwl::error( 456 456 "Usage: jwrite JID [-g] [-t thread] [-s 'subject'] [-a account]"); 457 457 return; … … 466 466 } 467 467 else { 468 owl::error("Please specify an account with -a {jid}");468 BarnOwl::error("Please specify an account with -a JID"); 469 469 return; 470 470 } … … 484 484 }; 485 485 486 owl::message(486 BarnOwl::message( 487 487 "Type your message below. End with a dot on a line by itself. ^C will quit." 488 488 ); 489 owl::start_edit_win( join( ' ', @args ), \&process_owl_jwrite );489 BarnOwl::start_edit_win( join( ' ', @args ), \&process_owl_jwrite ); 490 490 } 491 491 … … 508 508 my $func = $jmuc_commands{$cmd}; 509 509 if ( !$func ) { 510 owl::error("jmuc: Unknown command: $cmd");510 BarnOwl::error("jmuc: Unknown command: $cmd"); 511 511 return; 512 512 } … … 516 516 my $jid; 517 517 my $muc; 518 my $m = owl::getcurmsg();518 my $m = BarnOwl::getcurmsg(); 519 519 if ( $m->is_jabber && $m->{jtype} eq 'groupchat' ) { 520 520 $muc = $m->{room}; … … 531 531 } 532 532 else { 533 owl::error('You must specify an account with -a {jid}');533 BarnOwl::error('You must specify an account with -a {jid}'); 534 534 } 535 535 return $func->( $jid, $muc, @ARGV ); … … 623 623 my $func = $jroster_commands{$cmd}; 624 624 if ( !$func ) { 625 owl::error("jroster: Unknown command: $cmd");625 BarnOwl::error("jroster: Unknown command: $cmd"); 626 626 return; 627 627 } … … 647 647 } 648 648 else { 649 owl::error('You must specify an account with -a {jid}');649 BarnOwl::error('You must specify an account with -a {jid}'); 650 650 } 651 651 return $func->( $jid, $name, \@groups, $purgeGroups, @ARGV ); … … 809 809 810 810 my $m = j2o( $j, { direction => 'out' } ); 811 if ( $vars{jwrite}{type} ne 'groupchat' && owl::getvar('displayoutgoing') eq 'on') {812 owl::queue_message($m);811 if ( $vars{jwrite}{type} ne 'groupchat' && BarnOwl::getvar('displayoutgoing') eq 'on') { 812 BarnOwl::queue_message($m); 813 813 } 814 814 … … 821 821 822 822 delete $vars{jwrite}; 823 owl::message(""); # Kludge to make the ``type your message...'' message go away823 BarnOwl::message(""); # Kludge to make the ``type your message...'' message go away 824 824 } 825 825 … … 828 828 sub process_incoming_chat_message { 829 829 my ( $sid, $j ) = @_; 830 owl::queue_message( j2o( $j, { direction => 'in',830 BarnOwl::queue_message( j2o( $j, { direction => 'in', 831 831 sid => $sid } ) ); 832 832 } … … 837 837 sid => $sid } ); 838 838 $jhash{type} = 'admin'; 839 owl::queue_message( owl::Message->new(%jhash) );839 BarnOwl::queue_message( BarnOwl::Message->new(%jhash) ); 840 840 } 841 841 … … 845 845 # HACK IN PROGRESS (ignoring delayed messages) 846 846 return if ( $j->DefinedX('jabber:x:delay') && $j->GetX('jabber:x:delay') ); 847 owl::queue_message( j2o( $j, { direction => 'in',847 BarnOwl::queue_message( j2o( $j, { direction => 'in', 848 848 sid => $sid } ) ); 849 849 } … … 851 851 sub process_incoming_headline_message { 852 852 my ( $sid, $j ) = @_; 853 owl::queue_message( j2o( $j, { direction => 'in',853 BarnOwl::queue_message( j2o( $j, { direction => 'in', 854 854 sid => $sid } ) ); 855 855 } … … 871 871 # } 872 872 # 873 owl::queue_message( owl::Message->new(%jhash) );873 BarnOwl::queue_message( BarnOwl::Message->new(%jhash) ); 874 874 } 875 875 … … 906 906 } 907 907 $props{replysendercmd} = $props{replycmd} = "jwrite $from -i $sid"; 908 owl::queue_message(owl::Message->new(%props));908 BarnOwl::queue_message(BarnOwl::Message->new(%props)); 909 909 } 910 910 … … 924 924 $props{replycmd} = "jroster auth $from -a $to"; 925 925 $props{replysendercmd} = "jroster deauth $from -a $to"; 926 owl::queue_message(owl::Message->new(%props));926 BarnOwl::queue_message(BarnOwl::Message->new(%props)); 927 927 } 928 928 … … 940 940 941 941 $props{body} = "The user ($from) has been unsubscribed from your ($to) presence.\n"; 942 owl::queue_message(owl::Message->new(%props));942 BarnOwl::queue_message(BarnOwl::Message->new(%props)); 943 943 944 944 # Find a connection to reply with. … … 979 979 my $code = $p->GetErrorCode(); 980 980 my $error = $p->GetError(); 981 owl::error("Jabber: $code $error");981 BarnOwl::error("Jabber: $code $error"); 982 982 } 983 983 … … 1056 1056 1057 1057 sub j2o { 1058 return owl::Message->new( j2hash(@_) );1058 return BarnOwl::Message->new( j2hash(@_) ); 1059 1059 } 1060 1060 1061 1061 sub queue_admin_msg { 1062 1062 my $err = shift; 1063 my $m = owl::Message->new(1063 my $m = BarnOwl::Message->new( 1064 1064 type => 'admin', 1065 1065 direction => 'none', 1066 1066 body => $err 1067 1067 ); 1068 owl::queue_message($m);1068 BarnOwl::queue_message($m); 1069 1069 } 1070 1070 … … 1118 1118 # Specified account exists 1119 1119 return $givenJidStr if ($conn->jidExists($givenJidStr) ); 1120 owl::error("Invalid account: $givenJidStr");1120 BarnOwl::error("Invalid account: $givenJidStr"); 1121 1121 } 1122 1122 … … 1145 1145 # Not one of ours. 1146 1146 elsif ( $matchingJid eq "" ) { 1147 owl::error("Invalid account: $givenJidStr");1147 BarnOwl::error("Invalid account: $givenJidStr"); 1148 1148 } 1149 1149 … … 1159 1159 ##################################################################### 1160 1160 1161 package owl::Message::Jabber;1162 1163 our @ISA = qw( owl::Message );1161 package BarnOwl::Message::Jabber; 1162 1163 our @ISA = qw( BarnOwl::Message ); 1164 1164 1165 1165 sub jtype { shift->{jtype} }; … … 1185 1185 $ftext = qq{type ^jabber\$ and ( ( direction ^in\$ and from ^$user ) } . 1186 1186 qq{or ( direction ^out\$ and to ^$user ) ) }; 1187 owl::filter("$filter $ftext");1187 BarnOwl::filter("$filter $ftext"); 1188 1188 return $filter; 1189 1189 } elsif ($self->jtype eq 'groupchat') { … … 1191 1191 $filter = "jabber-room-$room"; 1192 1192 $ftext = qq{type ^jabber\$ and room ^$room\$}; 1193 owl::filter("$filter $ftext");1193 BarnOwl::filter("$filter $ftext"); 1194 1194 return $filter; 1195 1195 }
Note: See TracChangeset
for help on using the changeset viewer.