[b405ff6] | 1 | # -*- mode: cperl; cperl-indent-level: 4; indent-tabs-mode: nil -*- |
---|
[60986b2] | 2 | package BarnOwl::Jabber; |
---|
[9f183ff] | 3 | use warnings; |
---|
| 4 | use strict; |
---|
| 5 | |
---|
[38ffdf9] | 6 | use Authen::SASL qw(Perl); |
---|
| 7 | use Net::Jabber; |
---|
[1dfc7df] | 8 | use Net::Jabber::MUC; |
---|
[6a6dd47] | 9 | use Net::DNS; |
---|
| 10 | use Getopt::Long; |
---|
| 11 | |
---|
[84296f6] | 12 | no warnings 'redefine'; |
---|
| 13 | |
---|
[38ffdf9] | 14 | ################################################################################ |
---|
| 15 | # owl perl jabber support |
---|
| 16 | # |
---|
[b6a253c] | 17 | # XXX Todo: |
---|
| 18 | # Rosters for MUCs |
---|
| 19 | # More user feedback |
---|
| 20 | # * joining MUC |
---|
| 21 | # * parting MUC |
---|
| 22 | # * presence (Roster and MUC) |
---|
| 23 | # Implementing formatting and logging callbacks for C |
---|
| 24 | # Appropriate callbacks for presence subscription messages. |
---|
[38ffdf9] | 25 | # |
---|
| 26 | ################################################################################ |
---|
| 27 | |
---|
[f62550d] | 28 | |
---|
| 29 | ################################################################################ |
---|
| 30 | ################################################################################ |
---|
[30c735c] | 31 | package BarnOwl::Jabber::Connection; |
---|
| 32 | |
---|
| 33 | use base qw(Net::Jabber::Client); |
---|
| 34 | |
---|
| 35 | sub new { |
---|
| 36 | my $class = shift; |
---|
| 37 | |
---|
| 38 | my %args = (); |
---|
| 39 | if(BarnOwl::getvar('debug') eq 'on') { |
---|
| 40 | $args{debuglevel} = 1; |
---|
| 41 | $args{debugfile} = 'jabber.log'; |
---|
| 42 | } |
---|
| 43 | my $self = $class->SUPER::new(%args); |
---|
[1dfc7df] | 44 | $self->{_BARNOWL_MUCS} = []; |
---|
| 45 | return $self; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | =head2 MUCJoin |
---|
| 49 | |
---|
| 50 | Extends MUCJoin to keep track of the MUCs we're joined to as |
---|
| 51 | Net::Jabber::MUC objects. Takes the same arguments as |
---|
| 52 | L<Net::Jabber::MUC/new> and L<Net::Jabber::MUC/Connect> |
---|
| 53 | |
---|
| 54 | =cut |
---|
| 55 | |
---|
| 56 | sub MUCJoin { |
---|
| 57 | my $self = shift; |
---|
| 58 | my $muc = Net::Jabber::MUC->new(connection => $self, @_); |
---|
| 59 | $muc->Join(@_); |
---|
| 60 | push @{$self->MUCs}, $muc; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | =head2 MUCLeave ARGS |
---|
| 64 | |
---|
| 65 | Leave a MUC. The MUC is specified in the same form as L</FindMUC> |
---|
| 66 | |
---|
| 67 | =cut |
---|
| 68 | |
---|
| 69 | sub MUCLeave { |
---|
| 70 | my $self = shift; |
---|
| 71 | my $muc = $self->FindMUC(@_); |
---|
| 72 | return unless $muc; |
---|
| 73 | |
---|
| 74 | $muc->Leave(); |
---|
[e1b197e8] | 75 | $self->{_BARNOWL_MUCS} = [grep {$_->BaseJID ne $muc->BaseJID} $self->MUCs]; |
---|
[1dfc7df] | 76 | } |
---|
| 77 | |
---|
| 78 | =head2 FindMUC ARGS |
---|
| 79 | |
---|
| 80 | Return the Net::Jabber::MUC object representing a specific MUC we're |
---|
| 81 | joined to, undef if it doesn't exists. ARGS can be either JID => $JID, |
---|
| 82 | or Room => $room, Server => $server. |
---|
| 83 | |
---|
| 84 | =cut |
---|
| 85 | |
---|
| 86 | sub FindMUC { |
---|
| 87 | my $self = shift; |
---|
| 88 | |
---|
| 89 | my %args; |
---|
| 90 | while($#_ >= 0) { $args{ lc(pop(@_)) } = pop(@_); } |
---|
| 91 | |
---|
| 92 | my $jid; |
---|
| 93 | if($args{jid}) { |
---|
| 94 | $jid = $args{jid}; |
---|
| 95 | } elsif($args{room} && $args{server}) { |
---|
| 96 | $jid = Net::Jabber::JID->new(userid => $args{room}, |
---|
| 97 | server => $args{server}); |
---|
| 98 | } |
---|
| 99 | $jid = $jid->GetJID('base') if UNIVERSAL::isa($jid, 'Net::Jabber::JID'); |
---|
| 100 | |
---|
| 101 | foreach my $muc ($self->MUCs) { |
---|
| 102 | return $muc if $muc->BaseJID eq $jid; |
---|
| 103 | } |
---|
| 104 | return undef; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | =head2 MUCs |
---|
| 108 | |
---|
| 109 | Returns a list (or arrayref in scalar context) of Net::Jabber::MUC |
---|
| 110 | objects we believe ourself to be connected to. |
---|
| 111 | |
---|
| 112 | =cut |
---|
| 113 | |
---|
| 114 | sub MUCs { |
---|
| 115 | my $self = shift; |
---|
| 116 | my $mucs = $self->{_BARNOWL_MUCS}; |
---|
| 117 | return wantarray ? @$mucs : $mucs; |
---|
[30c735c] | 118 | } |
---|
| 119 | |
---|
| 120 | ################################################################################ |
---|
| 121 | ################################################################################ |
---|
[60986b2] | 122 | package BarnOwl::Jabber::ConnectionManager; |
---|
[f62550d] | 123 | sub new { |
---|
| 124 | my $class = shift; |
---|
| 125 | return bless { }, $class; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | sub addConnection { |
---|
| 129 | my $self = shift; |
---|
| 130 | my $jidStr = shift; |
---|
| 131 | |
---|
[30c735c] | 132 | my $client = BarnOwl::Jabber::Connection->new; |
---|
[bed4ff1] | 133 | |
---|
| 134 | $self->{Client}->{$jidStr} = $client; |
---|
| 135 | $self->{Roster}->{$jidStr} = $client->Roster(); |
---|
| 136 | return $client; |
---|
[f62550d] | 137 | } |
---|
| 138 | |
---|
| 139 | sub removeConnection { |
---|
| 140 | my $self = shift; |
---|
| 141 | my $jidStr = shift; |
---|
[bed4ff1] | 142 | return 0 unless exists $self->{Client}->{$jidStr}; |
---|
[4096d1f] | 143 | |
---|
[bed4ff1] | 144 | $self->{Client}->{$jidStr}->Disconnect(); |
---|
| 145 | delete $self->{Roster}->{$jidStr}; |
---|
| 146 | delete $self->{Client}->{$jidStr}; |
---|
[4096d1f] | 147 | |
---|
[bed4ff1] | 148 | return 1; |
---|
[f62550d] | 149 | } |
---|
| 150 | |
---|
| 151 | sub connected { |
---|
| 152 | my $self = shift; |
---|
| 153 | return scalar keys %{ $self->{Client} }; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | sub getJids { |
---|
| 157 | my $self = shift; |
---|
| 158 | return keys %{ $self->{Client} }; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | sub jidExists { |
---|
| 162 | my $self = shift; |
---|
| 163 | my $jidStr = shift; |
---|
[bed4ff1] | 164 | return exists $self->{Client}->{$jidStr}; |
---|
[f62550d] | 165 | } |
---|
| 166 | |
---|
| 167 | sub sidExists { |
---|
| 168 | my $self = shift; |
---|
| 169 | my $sid = shift || ""; |
---|
| 170 | foreach my $j ( keys %{ $self->{Client} } ) { |
---|
| 171 | return 1 if ($self->{Client}->{$j}->{SESSION}->{id} eq $sid); |
---|
| 172 | } |
---|
| 173 | return 0; |
---|
| 174 | } |
---|
| 175 | |
---|
[bed4ff1] | 176 | sub getConnectionFromSid { |
---|
[f62550d] | 177 | my $self = shift; |
---|
| 178 | my $sid = shift; |
---|
[bed4ff1] | 179 | foreach my $c (values %{ $self->{Client} }) { |
---|
| 180 | return $c if $c->{SESSION}->{id} eq $sid; |
---|
[f62550d] | 181 | } |
---|
| 182 | return undef; |
---|
| 183 | } |
---|
| 184 | |
---|
[bed4ff1] | 185 | sub getConnectionFromJidStr { |
---|
[f62550d] | 186 | my $self = shift; |
---|
| 187 | my $jidStr = shift; |
---|
[bed4ff1] | 188 | return $self->{Client}->{$jidStr}; |
---|
[f62550d] | 189 | } |
---|
| 190 | |
---|
[bed4ff1] | 191 | sub getRosterFromSid { |
---|
[f62550d] | 192 | my $self = shift; |
---|
| 193 | my $sid = shift; |
---|
[bed4ff1] | 194 | foreach my $j ( $self->getJids ) { |
---|
| 195 | return $self->{Roster}->{$j} |
---|
| 196 | if $self->{Client}->{$j}->{SESSION}->{id} eq $sid; |
---|
[f62550d] | 197 | } |
---|
| 198 | return undef; |
---|
| 199 | } |
---|
| 200 | |
---|
[bed4ff1] | 201 | sub getRosterFromJidStr { |
---|
[f62550d] | 202 | my $self = shift; |
---|
| 203 | my $jidStr = shift; |
---|
[bed4ff1] | 204 | return $self->{Roster}->{$jidStr}; |
---|
[f62550d] | 205 | return undef; |
---|
| 206 | } |
---|
| 207 | ################################################################################ |
---|
| 208 | |
---|
[30c735c] | 209 | package BarnOwl::Jabber; |
---|
[f62550d] | 210 | |
---|
[60986b2] | 211 | our $conn = new BarnOwl::Jabber::ConnectionManager unless $conn;; |
---|
[6a6dd47] | 212 | our %vars; |
---|
[38ffdf9] | 213 | |
---|
[b405ff6] | 214 | sub onStart { |
---|
[5551208] | 215 | if ( *BarnOwl::queue_message{CODE} ) { |
---|
[b405ff6] | 216 | register_owl_commands(); |
---|
[60986b2] | 217 | push @::onMainLoop, sub { BarnOwl::Jabber::onMainLoop(@_) }; |
---|
| 218 | push @::onGetBuddyList, sub { BarnOwl::Jabber::onGetBuddyList(@_) }; |
---|
[9667006] | 219 | } else { |
---|
[38ffdf9] | 220 | # Our owl doesn't support queue_message. Unfortunately, this |
---|
[d609dd6] | 221 | # means it probably *also* doesn't support BarnOwl::error. So just |
---|
[38ffdf9] | 222 | # give up silently. |
---|
| 223 | } |
---|
| 224 | } |
---|
[9f183ff] | 225 | |
---|
[60986b2] | 226 | push @::onStartSubs, sub { BarnOwl::Jabber::onStart(@_) }; |
---|
[38ffdf9] | 227 | |
---|
[b405ff6] | 228 | sub onMainLoop { |
---|
[f62550d] | 229 | return if ( !$conn->connected() ); |
---|
[6a6dd47] | 230 | |
---|
[f62550d] | 231 | foreach my $jid ( $conn->getJids() ) { |
---|
[bed4ff1] | 232 | my $client = $conn->getConnectionFromJidStr($jid); |
---|
[b405ff6] | 233 | |
---|
[5c9c27d] | 234 | my $status = $client->Process(0); |
---|
[b405ff6] | 235 | if ( !defined($status) ) { |
---|
[d609dd6] | 236 | BarnOwl::error("Jabber account $jid disconnected!"); |
---|
[960395d] | 237 | do_logout($jid); |
---|
| 238 | } |
---|
[b405ff6] | 239 | if ($::shutdown) { |
---|
| 240 | do_logout($jid); |
---|
| 241 | return; |
---|
| 242 | } |
---|
[38ffdf9] | 243 | } |
---|
| 244 | } |
---|
[b6a253c] | 245 | |
---|
[b405ff6] | 246 | sub blist_listBuddy { |
---|
[6a6dd47] | 247 | my $roster = shift; |
---|
[b405ff6] | 248 | my $buddy = shift; |
---|
[b6a253c] | 249 | my $blistStr .= " "; |
---|
[5c9c27d] | 250 | my %jq = $roster->query($buddy); |
---|
| 251 | my $res = $roster->resource($buddy); |
---|
[b6a253c] | 252 | |
---|
[f62550d] | 253 | $blistStr .= $jq{name} ? $jq{name} . "\t(" .$buddy->GetJID() . ')' : $buddy->GetJID(); |
---|
[b405ff6] | 254 | |
---|
| 255 | if ($res) { |
---|
[5c9c27d] | 256 | my %rq = $roster->resourceQuery( $buddy, $res ); |
---|
[b405ff6] | 257 | $blistStr .= " [" . ( $rq{show} ? $rq{show} : 'online' ) . "]"; |
---|
| 258 | $blistStr .= " " . $rq{status} if $rq{status}; |
---|
| 259 | $blistStr = boldify($blistStr); |
---|
[b6a253c] | 260 | } |
---|
[b405ff6] | 261 | else { |
---|
[84296f6] | 262 | if ($jq{ask}) { |
---|
| 263 | $blistStr .= " [pending]"; |
---|
| 264 | } |
---|
| 265 | elsif ($jq{subscription} eq 'none' || $jq{subscription} eq 'from') { |
---|
| 266 | $blistStr .= " [not subscribed]"; |
---|
| 267 | } |
---|
| 268 | else { |
---|
| 269 | $blistStr .= " [offline]"; |
---|
| 270 | } |
---|
[b6a253c] | 271 | } |
---|
[b405ff6] | 272 | return $blistStr . "\n"; |
---|
[b6a253c] | 273 | } |
---|
| 274 | |
---|
[84296f6] | 275 | sub getSingleBuddyList { |
---|
| 276 | my $jid = shift; |
---|
| 277 | $jid = resolveJID($jid); |
---|
| 278 | return "" unless $jid; |
---|
[6a6dd47] | 279 | my $blist = ""; |
---|
[bed4ff1] | 280 | my $roster = $conn->getRosterFromJidStr($jid); |
---|
| 281 | if ($roster) { |
---|
[84296f6] | 282 | $blist .= "\n" . boldify("Jabber Roster for $jid\n"); |
---|
| 283 | |
---|
[5c9c27d] | 284 | foreach my $group ( $roster->groups() ) { |
---|
[84296f6] | 285 | $blist .= " Group: $group\n"; |
---|
[5c9c27d] | 286 | foreach my $buddy ( $roster->jids( 'group', $group ) ) { |
---|
[84296f6] | 287 | $blist .= blist_listBuddy( $roster, $buddy ); |
---|
[b405ff6] | 288 | } |
---|
[84296f6] | 289 | } |
---|
[b405ff6] | 290 | |
---|
[5c9c27d] | 291 | my @unsorted = $roster->jids('nogroup'); |
---|
[84296f6] | 292 | if (@unsorted) { |
---|
| 293 | $blist .= " [unsorted]\n"; |
---|
| 294 | foreach my $buddy (@unsorted) { |
---|
| 295 | $blist .= blist_listBuddy( $roster, $buddy ); |
---|
[b405ff6] | 296 | } |
---|
| 297 | } |
---|
[b6a253c] | 298 | } |
---|
[6a6dd47] | 299 | return $blist; |
---|
[b6a253c] | 300 | } |
---|
[38ffdf9] | 301 | |
---|
[84296f6] | 302 | sub onGetBuddyList { |
---|
| 303 | my $blist = ""; |
---|
[f62550d] | 304 | foreach my $jid ($conn->getJids()) { |
---|
[84296f6] | 305 | $blist .= getSingleBuddyList($jid); |
---|
| 306 | } |
---|
| 307 | return $blist; |
---|
| 308 | } |
---|
| 309 | |
---|
[38ffdf9] | 310 | ################################################################################ |
---|
| 311 | ### Owl Commands |
---|
[b405ff6] | 312 | sub register_owl_commands() { |
---|
[d609dd6] | 313 | BarnOwl::new_command( |
---|
[38ffdf9] | 314 | jabberlogin => \&cmd_login, |
---|
[5adb3d7] | 315 | { summary => "Log into jabber", }, |
---|
| 316 | { usage => "jabberlogin JID" } |
---|
[38ffdf9] | 317 | ); |
---|
[d609dd6] | 318 | BarnOwl::new_command( |
---|
[38ffdf9] | 319 | jabberlogout => \&cmd_logout, |
---|
| 320 | { summary => "Log out of jabber" } |
---|
| 321 | ); |
---|
[d609dd6] | 322 | BarnOwl::new_command( |
---|
[38ffdf9] | 323 | jwrite => \&cmd_jwrite, |
---|
| 324 | { |
---|
[b405ff6] | 325 | summary => "Send a Jabber Message", |
---|
| 326 | usage => "jwrite JID [-g] [-t thread] [-s subject]" |
---|
[38ffdf9] | 327 | } |
---|
| 328 | ); |
---|
[d609dd6] | 329 | BarnOwl::new_command( |
---|
[b6a253c] | 330 | jlist => \&cmd_jlist, |
---|
[38ffdf9] | 331 | { |
---|
[b405ff6] | 332 | summary => "Show your Jabber roster.", |
---|
| 333 | usage => "jlist" |
---|
[38ffdf9] | 334 | } |
---|
| 335 | ); |
---|
[d609dd6] | 336 | BarnOwl::new_command( |
---|
[b6a253c] | 337 | jmuc => \&cmd_jmuc, |
---|
[38ffdf9] | 338 | { |
---|
[b6a253c] | 339 | summary => "Jabber MUC related commands.", |
---|
[b405ff6] | 340 | description => "jmuc sends jabber commands related to muc.\n\n" |
---|
| 341 | . "The following commands are available\n\n" |
---|
[5adb3d7] | 342 | . "join MUC Join a muc.\n\n" |
---|
| 343 | . "part MUC Part a muc.\n" |
---|
[b405ff6] | 344 | . " The muc is taken from the current message if not supplied.\n\n" |
---|
[5adb3d7] | 345 | . "invite JID MUC\n" |
---|
[d609dd6] | 346 | . " Invite JID to MUC.\n" |
---|
[b405ff6] | 347 | . " The muc is taken from the current message if not supplied.\n\n" |
---|
[5adb3d7] | 348 | . "configure MUC\n" |
---|
[d9f4a5c] | 349 | . " Configure [muc].\n" |
---|
[5adb3d7] | 350 | . " Necessary to initalize a new MUC\n" |
---|
| 351 | . " At present, only the default configuration is supported.", |
---|
| 352 | usage => "jmuc COMMAND ARGS" |
---|
[38ffdf9] | 353 | } |
---|
| 354 | ); |
---|
[d609dd6] | 355 | BarnOwl::new_command( |
---|
[f62550d] | 356 | jroster => \&cmd_jroster, |
---|
| 357 | { |
---|
| 358 | summary => "Jabber Roster related commands.", |
---|
[5adb3d7] | 359 | description => "jroster sends jabber commands related to rosters.\n\n", |
---|
| 360 | usage => "jroster COMMAND ARGS" |
---|
[f62550d] | 361 | } |
---|
| 362 | ); |
---|
[38ffdf9] | 363 | } |
---|
| 364 | |
---|
[b405ff6] | 365 | sub cmd_login { |
---|
[6a6dd47] | 366 | my $cmd = shift; |
---|
| 367 | my $jid = new Net::XMPP::JID; |
---|
| 368 | $jid->SetJID(shift); |
---|
[b405ff6] | 369 | |
---|
| 370 | my $uid = $jid->GetUserID(); |
---|
[6a6dd47] | 371 | my $componentname = $jid->GetServer(); |
---|
[b405ff6] | 372 | my $resource = $jid->GetResource() || 'owl'; |
---|
[6a6dd47] | 373 | $jid->SetResource($resource); |
---|
| 374 | my $jidStr = $jid->GetJID('full'); |
---|
| 375 | |
---|
[b405ff6] | 376 | if ( !$uid || !$componentname ) { |
---|
[d609dd6] | 377 | BarnOwl::error("usage: $cmd JID"); |
---|
[b405ff6] | 378 | return; |
---|
[38ffdf9] | 379 | } |
---|
[b6a253c] | 380 | |
---|
[f62550d] | 381 | if ( $conn->jidExists($jidStr) ) { |
---|
[d609dd6] | 382 | BarnOwl::error("Already logged in as $jidStr."); |
---|
[b405ff6] | 383 | return; |
---|
[6a6dd47] | 384 | } |
---|
| 385 | |
---|
[b405ff6] | 386 | my ( $server, $port ) = getServerFromJID($jid); |
---|
[6a6dd47] | 387 | |
---|
[84296f6] | 388 | $vars{jlogin_jid} = $jidStr; |
---|
| 389 | $vars{jlogin_havepass} = 0; |
---|
[b405ff6] | 390 | $vars{jlogin_connhash} = { |
---|
| 391 | hostname => $server, |
---|
| 392 | tls => 1, |
---|
| 393 | port => $port, |
---|
| 394 | componentname => $componentname |
---|
| 395 | }; |
---|
| 396 | $vars{jlogin_authhash} = |
---|
[84296f6] | 397 | { username => $uid, |
---|
| 398 | resource => $resource, |
---|
| 399 | }; |
---|
| 400 | |
---|
| 401 | return do_login(''); |
---|
[6a6dd47] | 402 | } |
---|
[38ffdf9] | 403 | |
---|
[84296f6] | 404 | sub do_login { |
---|
| 405 | $vars{jlogin_password} = shift; |
---|
| 406 | $vars{jlogin_authhash}->{password} = sub { return $vars{jlogin_password} || '' }; |
---|
| 407 | my $jidStr = $vars{jlogin_jid}; |
---|
| 408 | if ( !$jidStr && $vars{jlogin_havepass}) { |
---|
[d609dd6] | 409 | BarnOwl::error("Got password but have no jid!"); |
---|
[6a6dd47] | 410 | } |
---|
[84296f6] | 411 | else |
---|
| 412 | { |
---|
[f62550d] | 413 | my $client = $conn->addConnection($jidStr); |
---|
[84296f6] | 414 | |
---|
| 415 | #XXX Todo: Add more callbacks. |
---|
| 416 | # * MUC presence handlers |
---|
[60986b2] | 417 | # We use the anonymous subrefs in order to have the correct behavior |
---|
| 418 | # when we reload |
---|
[5c9c27d] | 419 | $client->SetMessageCallBacks( |
---|
[60986b2] | 420 | chat => sub { BarnOwl::Jabber::process_incoming_chat_message(@_) }, |
---|
| 421 | error => sub { BarnOwl::Jabber::process_incoming_error_message(@_) }, |
---|
| 422 | groupchat => sub { BarnOwl::Jabber::process_incoming_groupchat_message(@_) }, |
---|
| 423 | headline => sub { BarnOwl::Jabber::process_incoming_headline_message(@_) }, |
---|
| 424 | normal => sub { BarnOwl::Jabber::process_incoming_normal_message(@_) } |
---|
[84296f6] | 425 | ); |
---|
[bed4ff1] | 426 | $client->SetPresenceCallBacks( |
---|
[60986b2] | 427 | available => sub { BarnOwl::Jabber::process_presence_available(@_) }, |
---|
[8fa9562] | 428 | unavailable => sub { BarnOwl::Jabber::process_presence_available(@_) }, |
---|
[60986b2] | 429 | subscribe => sub { BarnOwl::Jabber::process_presence_subscribe(@_) }, |
---|
| 430 | subscribed => sub { BarnOwl::Jabber::process_presence_subscribed(@_) }, |
---|
| 431 | unsubscribe => sub { BarnOwl::Jabber::process_presence_unsubscribe(@_) }, |
---|
| 432 | unsubscribed => sub { BarnOwl::Jabber::process_presence_unsubscribed(@_) }, |
---|
| 433 | error => sub { BarnOwl::Jabber::process_presence_error(@_) }); |
---|
[84296f6] | 434 | |
---|
[5c9c27d] | 435 | my $status = $client->Connect( %{ $vars{jlogin_connhash} } ); |
---|
[84296f6] | 436 | if ( !$status ) { |
---|
[f62550d] | 437 | $conn->removeConnection($jidStr); |
---|
[d609dd6] | 438 | BarnOwl::error("We failed to connect"); |
---|
[46e8a1e] | 439 | } else { |
---|
[5c9c27d] | 440 | my @result = $client->AuthSend( %{ $vars{jlogin_authhash} } ); |
---|
[84296f6] | 441 | |
---|
[ffe70f9] | 442 | if ( !@result || $result[0] ne 'ok' ) { |
---|
[d609dd6] | 443 | if ( !$vars{jlogin_havepass} && ( !@result || $result[0] eq '401' ) ) { |
---|
[46e8a1e] | 444 | $vars{jlogin_havepass} = 1; |
---|
| 445 | $conn->removeConnection($jidStr); |
---|
[d609dd6] | 446 | BarnOwl::start_password( "Password for $jidStr: ", \&do_login ); |
---|
[46e8a1e] | 447 | return ""; |
---|
| 448 | } |
---|
[f62550d] | 449 | $conn->removeConnection($jidStr); |
---|
[d609dd6] | 450 | BarnOwl::error( "Error in connect: " . join( " ", @result ) ); |
---|
[46e8a1e] | 451 | } else { |
---|
[20eb22c] | 452 | $conn->getRosterFromJidStr($jidStr)->fetch(); |
---|
[bed4ff1] | 453 | $client->PresenceSend( priority => 1 ); |
---|
[84296f6] | 454 | queue_admin_msg("Connected to jabber as $jidStr"); |
---|
| 455 | } |
---|
| 456 | } |
---|
[46e8a1e] | 457 | |
---|
[6a6dd47] | 458 | } |
---|
[84296f6] | 459 | delete $vars{jlogin_jid}; |
---|
| 460 | $vars{jlogin_password} =~ tr/\0-\377/x/; |
---|
| 461 | delete $vars{jlogin_password}; |
---|
| 462 | delete $vars{jlogin_havepass}; |
---|
[6a6dd47] | 463 | delete $vars{jlogin_connhash}; |
---|
| 464 | delete $vars{jlogin_authhash}; |
---|
[38ffdf9] | 465 | return ""; |
---|
| 466 | } |
---|
| 467 | |
---|
[b405ff6] | 468 | sub do_logout { |
---|
[6a6dd47] | 469 | my $jid = shift; |
---|
[f62550d] | 470 | my $disconnected = $conn->removeConnection($jid); |
---|
| 471 | queue_admin_msg("Jabber disconnected ($jid).") if $disconnected; |
---|
[6a6dd47] | 472 | } |
---|
| 473 | |
---|
[b405ff6] | 474 | sub cmd_logout { |
---|
[6a6dd47] | 475 | # Logged into multiple accounts |
---|
[f62550d] | 476 | if ( $conn->connected() > 1 ) { |
---|
[b405ff6] | 477 | # Logged into multiple accounts, no accout specified. |
---|
| 478 | if ( !$_[1] ) { |
---|
| 479 | my $errStr = |
---|
[84296f6] | 480 | "You are logged into multiple accounts. Please specify an account to log out of.\n"; |
---|
[f62550d] | 481 | foreach my $jid ( $conn->getJids() ) { |
---|
[b405ff6] | 482 | $errStr .= "\t$jid\n"; |
---|
| 483 | } |
---|
| 484 | queue_admin_msg($errStr); |
---|
| 485 | } |
---|
| 486 | # Logged into multiple accounts, account specified. |
---|
| 487 | else { |
---|
| 488 | if ( $_[1] eq '-a' ) #All accounts. |
---|
| 489 | { |
---|
[f62550d] | 490 | foreach my $jid ( $conn->getJids() ) { |
---|
[b405ff6] | 491 | do_logout($jid); |
---|
| 492 | } |
---|
| 493 | } |
---|
| 494 | else #One account. |
---|
| 495 | { |
---|
| 496 | my $jid = resolveJID( $_[1] ); |
---|
| 497 | do_logout($jid) if ( $jid ne '' ); |
---|
| 498 | } |
---|
| 499 | } |
---|
| 500 | } |
---|
| 501 | else # Only one account logged in. |
---|
[6a6dd47] | 502 | { |
---|
[f62550d] | 503 | do_logout( ( $conn->getJids() )[0] ); |
---|
[38ffdf9] | 504 | } |
---|
| 505 | return ""; |
---|
| 506 | } |
---|
| 507 | |
---|
[b405ff6] | 508 | sub cmd_jlist { |
---|
[f62550d] | 509 | if ( !( scalar $conn->getJids() ) ) { |
---|
[d609dd6] | 510 | BarnOwl::error("You are not logged in to Jabber."); |
---|
[b405ff6] | 511 | return; |
---|
[b6a253c] | 512 | } |
---|
[d609dd6] | 513 | BarnOwl::popless_ztext( onGetBuddyList() ); |
---|
[b6a253c] | 514 | } |
---|
| 515 | |
---|
[b405ff6] | 516 | sub cmd_jwrite { |
---|
[f62550d] | 517 | if ( !$conn->connected() ) { |
---|
[d609dd6] | 518 | BarnOwl::error("You are not logged in to Jabber."); |
---|
[b405ff6] | 519 | return; |
---|
[38ffdf9] | 520 | } |
---|
| 521 | |
---|
[b405ff6] | 522 | my $jwrite_to = ""; |
---|
| 523 | my $jwrite_from = ""; |
---|
[f62550d] | 524 | my $jwrite_sid = ""; |
---|
[b405ff6] | 525 | my $jwrite_thread = ""; |
---|
[6a6dd47] | 526 | my $jwrite_subject = ""; |
---|
[b405ff6] | 527 | my $jwrite_type = "chat"; |
---|
[38ffdf9] | 528 | |
---|
[6a6dd47] | 529 | my @args = @_; |
---|
| 530 | shift; |
---|
[9f183ff] | 531 | local @ARGV = @_; |
---|
[6a6dd47] | 532 | my $gc; |
---|
[b405ff6] | 533 | GetOptions( |
---|
| 534 | 'thread=s' => \$jwrite_thread, |
---|
| 535 | 'subject=s' => \$jwrite_subject, |
---|
| 536 | 'account=s' => \$jwrite_from, |
---|
[f62550d] | 537 | 'id=s' => \$jwrite_sid, |
---|
[b405ff6] | 538 | 'groupchat' => \$gc |
---|
| 539 | ); |
---|
[6a6dd47] | 540 | $jwrite_type = 'groupchat' if $gc; |
---|
| 541 | |
---|
[b405ff6] | 542 | if ( scalar @ARGV != 1 ) { |
---|
[d609dd6] | 543 | BarnOwl::error( |
---|
[b405ff6] | 544 | "Usage: jwrite JID [-g] [-t thread] [-s 'subject'] [-a account]"); |
---|
| 545 | return; |
---|
[6a6dd47] | 546 | } |
---|
[b405ff6] | 547 | else { |
---|
| 548 | $jwrite_to = shift @ARGV; |
---|
[6a6dd47] | 549 | } |
---|
[b6a253c] | 550 | |
---|
[b405ff6] | 551 | if ( !$jwrite_from ) { |
---|
[f62550d] | 552 | if ( $conn->connected() == 1 ) { |
---|
| 553 | $jwrite_from = ( $conn->getJids() )[0]; |
---|
[b405ff6] | 554 | } |
---|
| 555 | else { |
---|
[d609dd6] | 556 | BarnOwl::error("Please specify an account with -a JID"); |
---|
[b405ff6] | 557 | return; |
---|
| 558 | } |
---|
| 559 | } |
---|
| 560 | else { |
---|
| 561 | $jwrite_from = resolveJID($jwrite_from); |
---|
| 562 | return unless $jwrite_from; |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | $vars{jwrite} = { |
---|
| 566 | to => $jwrite_to, |
---|
| 567 | from => $jwrite_from, |
---|
[f62550d] | 568 | sid => $jwrite_sid, |
---|
[b405ff6] | 569 | subject => $jwrite_subject, |
---|
| 570 | thread => $jwrite_thread, |
---|
| 571 | type => $jwrite_type |
---|
| 572 | }; |
---|
| 573 | |
---|
[d609dd6] | 574 | BarnOwl::message( |
---|
[f62550d] | 575 | "Type your message below. End with a dot on a line by itself. ^C will quit." |
---|
| 576 | ); |
---|
[d609dd6] | 577 | BarnOwl::start_edit_win( join( ' ', @args ), \&process_owl_jwrite ); |
---|
[38ffdf9] | 578 | } |
---|
| 579 | |
---|
[b405ff6] | 580 | sub cmd_jmuc { |
---|
[f62550d] | 581 | die "You are not logged in to Jabber" unless $conn->connected(); |
---|
[b405ff6] | 582 | my $ocmd = shift; |
---|
| 583 | my $cmd = shift; |
---|
| 584 | if ( !$cmd ) { |
---|
| 585 | |
---|
| 586 | #XXX TODO: Write general usage for jmuc command. |
---|
| 587 | return; |
---|
| 588 | } |
---|
| 589 | |
---|
| 590 | my %jmuc_commands = ( |
---|
| 591 | join => \&jmuc_join, |
---|
| 592 | part => \&jmuc_part, |
---|
| 593 | invite => \&jmuc_invite, |
---|
[1dfc7df] | 594 | configure => \&jmuc_configure, |
---|
| 595 | presence => \&jmuc_presence |
---|
[b405ff6] | 596 | ); |
---|
| 597 | my $func = $jmuc_commands{$cmd}; |
---|
| 598 | if ( !$func ) { |
---|
[d609dd6] | 599 | BarnOwl::error("jmuc: Unknown command: $cmd"); |
---|
[b405ff6] | 600 | return; |
---|
| 601 | } |
---|
| 602 | |
---|
| 603 | { |
---|
| 604 | local @ARGV = @_; |
---|
| 605 | my $jid; |
---|
| 606 | my $muc; |
---|
[d609dd6] | 607 | my $m = BarnOwl::getcurmsg(); |
---|
[b405ff6] | 608 | if ( $m->is_jabber && $m->{jtype} eq 'groupchat' ) { |
---|
| 609 | $muc = $m->{room}; |
---|
| 610 | $jid = $m->{to}; |
---|
| 611 | } |
---|
| 612 | |
---|
| 613 | my $getopt = Getopt::Long::Parser->new; |
---|
| 614 | $getopt->configure('pass_through'); |
---|
| 615 | $getopt->getoptions( 'account=s' => \$jid ); |
---|
| 616 | $jid ||= defaultJID(); |
---|
| 617 | if ($jid) { |
---|
| 618 | $jid = resolveJID($jid); |
---|
| 619 | return unless $jid; |
---|
| 620 | } |
---|
| 621 | else { |
---|
[d609dd6] | 622 | BarnOwl::error('You must specify an account with -a {jid}'); |
---|
[b405ff6] | 623 | } |
---|
| 624 | return $func->( $jid, $muc, @ARGV ); |
---|
| 625 | } |
---|
[6df381b] | 626 | } |
---|
| 627 | |
---|
| 628 | sub jmuc_join { |
---|
[b405ff6] | 629 | my ( $jid, $muc, @args ) = @_; |
---|
| 630 | local @ARGV = @args; |
---|
| 631 | my $password; |
---|
| 632 | GetOptions( 'password=s' => \$password ); |
---|
| 633 | |
---|
| 634 | $muc = shift @ARGV |
---|
[60986b2] | 635 | or die("Usage: jmuc join MUC [-p password] [-a account]"); |
---|
[b405ff6] | 636 | |
---|
[1dfc7df] | 637 | $conn->getConnectionFromJidStr($jid)->MUCJoin(Jid => $muc, |
---|
| 638 | Password => $password, |
---|
| 639 | History => { |
---|
| 640 | MaxChars => 0 |
---|
| 641 | }); |
---|
| 642 | return; |
---|
[6df381b] | 643 | } |
---|
| 644 | |
---|
| 645 | sub jmuc_part { |
---|
[b405ff6] | 646 | my ( $jid, $muc, @args ) = @_; |
---|
[9f183ff] | 647 | |
---|
[b405ff6] | 648 | $muc = shift @args if scalar @args; |
---|
[60986b2] | 649 | die("Usage: jmuc part MUC [-a account]") unless $muc; |
---|
[9f183ff] | 650 | |
---|
[1dfc7df] | 651 | $conn->getConnectionFromJidStr($jid)->MUCLeave(JID => $muc); |
---|
[b405ff6] | 652 | queue_admin_msg("$jid has left $muc."); |
---|
[6df381b] | 653 | } |
---|
| 654 | |
---|
[b405ff6] | 655 | sub jmuc_invite { |
---|
| 656 | my ( $jid, $muc, @args ) = @_; |
---|
| 657 | |
---|
| 658 | my $invite_jid = shift @args; |
---|
| 659 | $muc = shift @args if scalar @args; |
---|
| 660 | |
---|
[60986b2] | 661 | die('Usage: jmuc invite JID [muc] [-a account]') |
---|
[b405ff6] | 662 | unless $muc && $invite_jid; |
---|
| 663 | |
---|
[d9f4a5c] | 664 | my $message = Net::Jabber::Message->new(); |
---|
[b405ff6] | 665 | $message->SetTo($muc); |
---|
[d9f4a5c] | 666 | my $x = $message->NewChild('http://jabber.org/protocol/muc#user'); |
---|
| 667 | $x->AddInvite(); |
---|
| 668 | $x->GetInvite()->SetTo($invite_jid); |
---|
[bed4ff1] | 669 | $conn->getConnectionFromJidStr($jid)->Send($message); |
---|
[b405ff6] | 670 | queue_admin_msg("$jid has invited $invite_jid to $muc."); |
---|
[38ffdf9] | 671 | } |
---|
| 672 | |
---|
[9f183ff] | 673 | sub jmuc_configure { |
---|
[b405ff6] | 674 | my ( $jid, $muc, @args ) = @_; |
---|
| 675 | $muc = shift @args if scalar @args; |
---|
| 676 | die("Usage: jmuc configure [muc]") unless $muc; |
---|
| 677 | my $iq = Net::Jabber::IQ->new(); |
---|
| 678 | $iq->SetTo($muc); |
---|
| 679 | $iq->SetType('set'); |
---|
| 680 | my $query = $iq->NewQuery("http://jabber.org/protocol/muc#owner"); |
---|
| 681 | my $x = $query->NewChild("jabber:x:data"); |
---|
| 682 | $x->SetType('submit'); |
---|
| 683 | |
---|
[bed4ff1] | 684 | $conn->getConnectionFromJidStr($jid)->Send($iq); |
---|
[b405ff6] | 685 | queue_admin_msg("Accepted default instant configuration for $muc"); |
---|
[9f183ff] | 686 | } |
---|
| 687 | |
---|
[1dfc7df] | 688 | sub jmuc_presence { |
---|
| 689 | my ( $jid, $muc, @args ) = @_; |
---|
| 690 | |
---|
[e1b197e8] | 691 | $muc = shift @args if scalar @args; |
---|
| 692 | die("Usage: jmuc presence MUC") unless $muc; |
---|
| 693 | |
---|
[1dfc7df] | 694 | my $m = $conn->getConnectionFromJidStr($jid)->FindMUC(jid => $muc); |
---|
| 695 | die("No such muc: $muc") unless $m; |
---|
| 696 | |
---|
| 697 | my @jids = $m->Presence(); |
---|
| 698 | BarnOwl::popless_ztext("JIDs present in " . $m->BaseJID . "\n\t" . |
---|
[e1b197e8] | 699 | join("\n\t", map {$_->GetResource}@jids) . "\n"); |
---|
[1dfc7df] | 700 | } |
---|
| 701 | |
---|
[f62550d] | 702 | |
---|
| 703 | #XXX TODO: Consider merging this with jmuc and selecting off the first two args. |
---|
| 704 | sub cmd_jroster { |
---|
| 705 | die "You are not logged in to Jabber" unless $conn->connected(); |
---|
| 706 | my $ocmd = shift; |
---|
| 707 | my $cmd = shift; |
---|
| 708 | if ( !$cmd ) { |
---|
| 709 | |
---|
| 710 | #XXX TODO: Write general usage for jroster command. |
---|
| 711 | return; |
---|
| 712 | } |
---|
| 713 | |
---|
| 714 | my %jroster_commands = ( |
---|
| 715 | sub => \&jroster_sub, |
---|
| 716 | unsub => \&jroster_unsub, |
---|
| 717 | add => \&jroster_add, |
---|
| 718 | remove => \&jroster_remove, |
---|
| 719 | auth => \&jroster_auth, |
---|
| 720 | deauth => \&jroster_deauth |
---|
| 721 | ); |
---|
| 722 | |
---|
| 723 | my $func = $jroster_commands{$cmd}; |
---|
| 724 | if ( !$func ) { |
---|
[d609dd6] | 725 | BarnOwl::error("jroster: Unknown command: $cmd"); |
---|
[f62550d] | 726 | return; |
---|
| 727 | } |
---|
| 728 | |
---|
| 729 | { |
---|
| 730 | local @ARGV = @_; |
---|
| 731 | my $jid; |
---|
| 732 | my $name; |
---|
| 733 | my @groups; |
---|
| 734 | my $purgeGroups; |
---|
| 735 | my $getopt = Getopt::Long::Parser->new; |
---|
| 736 | $getopt->configure('pass_through'); |
---|
| 737 | $getopt->getoptions( |
---|
| 738 | 'account=s' => \$jid, |
---|
| 739 | 'group=s' => \@groups, |
---|
| 740 | 'purgegroups' => \$purgeGroups, |
---|
| 741 | 'name=s' => \$name |
---|
| 742 | ); |
---|
| 743 | $jid ||= defaultJID(); |
---|
| 744 | if ($jid) { |
---|
| 745 | $jid = resolveJID($jid); |
---|
| 746 | return unless $jid; |
---|
| 747 | } |
---|
| 748 | else { |
---|
[d609dd6] | 749 | BarnOwl::error('You must specify an account with -a {jid}'); |
---|
[f62550d] | 750 | } |
---|
| 751 | return $func->( $jid, $name, \@groups, $purgeGroups, @ARGV ); |
---|
| 752 | } |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | sub jroster_sub { |
---|
| 756 | my $jid = shift; |
---|
| 757 | my $name = shift; |
---|
| 758 | my @groups = @{ shift() }; |
---|
| 759 | my $purgeGroups = shift; |
---|
| 760 | my $baseJid = baseJID($jid); |
---|
| 761 | |
---|
[bed4ff1] | 762 | my $roster = $conn->getRosterFromJidStr($jid); |
---|
[f62550d] | 763 | |
---|
| 764 | # Adding lots of users with the same name is a bad idea. |
---|
| 765 | $name = "" unless (1 == scalar(@ARGV)); |
---|
| 766 | |
---|
| 767 | my $p = new Net::XMPP::Presence; |
---|
| 768 | $p->SetType('subscribe'); |
---|
| 769 | |
---|
| 770 | foreach my $to (@ARGV) { |
---|
[bed4ff1] | 771 | jroster_add($jid, $name, \@groups, $purgeGroups, ($to)) unless ($roster->exists($to)); |
---|
[f62550d] | 772 | |
---|
| 773 | $p->SetTo($to); |
---|
[bed4ff1] | 774 | $conn->getConnectionFromJidStr($jid)->Send($p); |
---|
[f62550d] | 775 | queue_admin_msg("You ($baseJid) have requested a subscription to ($to)'s presence."); |
---|
| 776 | } |
---|
| 777 | } |
---|
| 778 | |
---|
| 779 | sub jroster_unsub { |
---|
| 780 | my $jid = shift; |
---|
| 781 | my $name = shift; |
---|
| 782 | my @groups = @{ shift() }; |
---|
| 783 | my $purgeGroups = shift; |
---|
| 784 | my $baseJid = baseJID($jid); |
---|
| 785 | |
---|
| 786 | my $p = new Net::XMPP::Presence; |
---|
| 787 | $p->SetType('unsubscribe'); |
---|
| 788 | foreach my $to (@ARGV) { |
---|
| 789 | $p->SetTo($to); |
---|
[bed4ff1] | 790 | $conn->getConnectionFromJidStr($jid)->Send($p); |
---|
[f62550d] | 791 | queue_admin_msg("You ($baseJid) have unsubscribed from ($to)'s presence."); |
---|
| 792 | } |
---|
| 793 | } |
---|
| 794 | |
---|
| 795 | sub jroster_add { |
---|
| 796 | my $jid = shift; |
---|
| 797 | my $name = shift; |
---|
| 798 | my @groups = @{ shift() }; |
---|
| 799 | my $purgeGroups = shift; |
---|
| 800 | my $baseJid = baseJID($jid); |
---|
| 801 | |
---|
[bed4ff1] | 802 | my $roster = $conn->getRosterFromJidStr($jid); |
---|
[f62550d] | 803 | |
---|
| 804 | # Adding lots of users with the same name is a bad idea. |
---|
| 805 | $name = "" unless (1 == scalar(@ARGV)); |
---|
| 806 | |
---|
| 807 | foreach my $to (@ARGV) { |
---|
[bed4ff1] | 808 | my %jq = $roster->query($to); |
---|
[f62550d] | 809 | my $iq = new Net::XMPP::IQ; |
---|
| 810 | $iq->SetType('set'); |
---|
| 811 | my $item = new XML::Stream::Node('item'); |
---|
| 812 | $iq->NewChild('jabber:iq:roster')->AddChild($item); |
---|
| 813 | |
---|
| 814 | my %allGroups = (); |
---|
| 815 | |
---|
| 816 | foreach my $g (@groups) { |
---|
| 817 | $allGroups{$g} = $g; |
---|
| 818 | } |
---|
| 819 | |
---|
| 820 | unless ($purgeGroups) { |
---|
| 821 | foreach my $g (@{$jq{groups}}) { |
---|
| 822 | $allGroups{$g} = $g; |
---|
| 823 | } |
---|
| 824 | } |
---|
| 825 | |
---|
| 826 | foreach my $g (keys %allGroups) { |
---|
| 827 | $item->add_child('group')->add_cdata($g); |
---|
| 828 | } |
---|
| 829 | |
---|
| 830 | $item->put_attrib(jid => $to); |
---|
| 831 | $item->put_attrib(name => $name) if $name; |
---|
[bed4ff1] | 832 | $conn->getConnectionFromJidStr($jid)->Send($iq); |
---|
[f62550d] | 833 | my $msg = "$baseJid: " |
---|
| 834 | . ($name ? "$name ($to)" : "($to)") |
---|
| 835 | . " is on your roster in the following groups: { " |
---|
| 836 | . join(" , ", keys %allGroups) |
---|
| 837 | . " }"; |
---|
| 838 | queue_admin_msg($msg); |
---|
| 839 | } |
---|
| 840 | } |
---|
| 841 | |
---|
| 842 | sub jroster_remove { |
---|
| 843 | my $jid = shift; |
---|
| 844 | my $name = shift; |
---|
| 845 | my @groups = @{ shift() }; |
---|
| 846 | my $purgeGroups = shift; |
---|
| 847 | my $baseJid = baseJID($jid); |
---|
| 848 | |
---|
| 849 | my $iq = new Net::XMPP::IQ; |
---|
| 850 | $iq->SetType('set'); |
---|
| 851 | my $item = new XML::Stream::Node('item'); |
---|
| 852 | $iq->NewChild('jabber:iq:roster')->AddChild($item); |
---|
| 853 | $item->put_attrib(subscription=> 'remove'); |
---|
| 854 | foreach my $to (@ARGV) { |
---|
| 855 | $item->put_attrib(jid => $to); |
---|
[bed4ff1] | 856 | $conn->getConnectionFromJidStr($jid)->Send($iq); |
---|
[f62550d] | 857 | queue_admin_msg("You ($baseJid) have removed ($to) from your roster."); |
---|
| 858 | } |
---|
| 859 | } |
---|
| 860 | |
---|
| 861 | sub jroster_auth { |
---|
| 862 | my $jid = shift; |
---|
| 863 | my $name = shift; |
---|
| 864 | my @groups = @{ shift() }; |
---|
| 865 | my $purgeGroups = shift; |
---|
| 866 | my $baseJid = baseJID($jid); |
---|
| 867 | |
---|
| 868 | my $p = new Net::XMPP::Presence; |
---|
| 869 | $p->SetType('subscribed'); |
---|
| 870 | foreach my $to (@ARGV) { |
---|
| 871 | $p->SetTo($to); |
---|
[bed4ff1] | 872 | $conn->getConnectionFromJidStr($jid)->Send($p); |
---|
[f62550d] | 873 | queue_admin_msg("($to) has been subscribed to your ($baseJid) presence."); |
---|
| 874 | } |
---|
| 875 | } |
---|
| 876 | |
---|
| 877 | sub jroster_deauth { |
---|
| 878 | my $jid = shift; |
---|
| 879 | my $name = shift; |
---|
| 880 | my @groups = @{ shift() }; |
---|
| 881 | my $purgeGroups = shift; |
---|
| 882 | my $baseJid = baseJID($jid); |
---|
| 883 | |
---|
| 884 | my $p = new Net::XMPP::Presence; |
---|
| 885 | $p->SetType('unsubscribed'); |
---|
| 886 | foreach my $to (@ARGV) { |
---|
| 887 | $p->SetTo($to); |
---|
[bed4ff1] | 888 | $conn->getConnectionFromJidStr($jid)->Send($p); |
---|
[f62550d] | 889 | queue_admin_msg("($to) has been unsubscribed from your ($baseJid) presence."); |
---|
| 890 | } |
---|
| 891 | } |
---|
| 892 | |
---|
[38ffdf9] | 893 | ################################################################################ |
---|
| 894 | ### Owl Callbacks |
---|
[b405ff6] | 895 | sub process_owl_jwrite { |
---|
[38ffdf9] | 896 | my $body = shift; |
---|
| 897 | |
---|
| 898 | my $j = new Net::XMPP::Message; |
---|
| 899 | $body =~ s/\n\z//; |
---|
[b405ff6] | 900 | $j->SetMessage( |
---|
| 901 | to => $vars{jwrite}{to}, |
---|
| 902 | from => $vars{jwrite}{from}, |
---|
| 903 | type => $vars{jwrite}{type}, |
---|
| 904 | body => $body |
---|
| 905 | ); |
---|
[f62550d] | 906 | |
---|
[b405ff6] | 907 | $j->SetThread( $vars{jwrite}{thread} ) if ( $vars{jwrite}{thread} ); |
---|
| 908 | $j->SetSubject( $vars{jwrite}{subject} ) if ( $vars{jwrite}{subject} ); |
---|
| 909 | |
---|
[f62550d] | 910 | my $m = j2o( $j, { direction => 'out' } ); |
---|
[d609dd6] | 911 | if ( $vars{jwrite}{type} ne 'groupchat' && BarnOwl::getvar('displayoutgoing') eq 'on') { |
---|
| 912 | BarnOwl::queue_message($m); |
---|
[38ffdf9] | 913 | } |
---|
[f62550d] | 914 | |
---|
| 915 | if ($vars{jwrite}{sid} && $conn->sidExists( $vars{jwrite}{sid} )) { |
---|
[bed4ff1] | 916 | $conn->getConnectionFromSid($vars{jwrite}{sid})->Send($j); |
---|
[f62550d] | 917 | } |
---|
| 918 | else { |
---|
[bed4ff1] | 919 | $conn->getConnectionFromJidStr($vars{jwrite}{from})->Send($j); |
---|
[f62550d] | 920 | } |
---|
| 921 | |
---|
[6a6dd47] | 922 | delete $vars{jwrite}; |
---|
[d609dd6] | 923 | BarnOwl::message(""); # Kludge to make the ``type your message...'' message go away |
---|
[38ffdf9] | 924 | } |
---|
| 925 | |
---|
| 926 | ### XMPP Callbacks |
---|
| 927 | |
---|
[b405ff6] | 928 | sub process_incoming_chat_message { |
---|
[f62550d] | 929 | my ( $sid, $j ) = @_; |
---|
[d609dd6] | 930 | BarnOwl::queue_message( j2o( $j, { direction => 'in', |
---|
[f62550d] | 931 | sid => $sid } ) ); |
---|
[38ffdf9] | 932 | } |
---|
| 933 | |
---|
[b405ff6] | 934 | sub process_incoming_error_message { |
---|
[f62550d] | 935 | my ( $sid, $j ) = @_; |
---|
| 936 | my %jhash = j2hash( $j, { direction => 'in', |
---|
| 937 | sid => $sid } ); |
---|
[b6a253c] | 938 | $jhash{type} = 'admin'; |
---|
[d609dd6] | 939 | BarnOwl::queue_message( BarnOwl::Message->new(%jhash) ); |
---|
[38ffdf9] | 940 | } |
---|
| 941 | |
---|
[b405ff6] | 942 | sub process_incoming_groupchat_message { |
---|
[f62550d] | 943 | my ( $sid, $j ) = @_; |
---|
[b405ff6] | 944 | |
---|
[38ffdf9] | 945 | # HACK IN PROGRESS (ignoring delayed messages) |
---|
[b405ff6] | 946 | return if ( $j->DefinedX('jabber:x:delay') && $j->GetX('jabber:x:delay') ); |
---|
[d609dd6] | 947 | BarnOwl::queue_message( j2o( $j, { direction => 'in', |
---|
[f62550d] | 948 | sid => $sid } ) ); |
---|
[38ffdf9] | 949 | } |
---|
| 950 | |
---|
[b405ff6] | 951 | sub process_incoming_headline_message { |
---|
[f62550d] | 952 | my ( $sid, $j ) = @_; |
---|
[d609dd6] | 953 | BarnOwl::queue_message( j2o( $j, { direction => 'in', |
---|
[f62550d] | 954 | sid => $sid } ) ); |
---|
[38ffdf9] | 955 | } |
---|
| 956 | |
---|
[b405ff6] | 957 | sub process_incoming_normal_message { |
---|
[f62550d] | 958 | my ( $sid, $j ) = @_; |
---|
| 959 | my %jhash = j2hash( $j, { direction => 'in', |
---|
| 960 | sid => $sid } ); |
---|
[b6a253c] | 961 | |
---|
| 962 | # XXX TODO: handle things such as MUC invites here. |
---|
| 963 | |
---|
[b405ff6] | 964 | # if ($j->HasX('http://jabber.org/protocol/muc#user')) |
---|
| 965 | # { |
---|
| 966 | # my $x = $j->GetX('http://jabber.org/protocol/muc#user'); |
---|
| 967 | # if ($x->HasChild('invite')) |
---|
| 968 | # { |
---|
| 969 | # $props |
---|
| 970 | # } |
---|
| 971 | # } |
---|
| 972 | # |
---|
[d609dd6] | 973 | BarnOwl::queue_message( BarnOwl::Message->new(%jhash) ); |
---|
[b6a253c] | 974 | } |
---|
| 975 | |
---|
[b405ff6] | 976 | sub process_muc_presence { |
---|
[f62550d] | 977 | my ( $sid, $p ) = @_; |
---|
[b405ff6] | 978 | return unless ( $p->HasX('http://jabber.org/protocol/muc#user') ); |
---|
[f62550d] | 979 | } |
---|
| 980 | |
---|
| 981 | |
---|
| 982 | sub process_presence_available { |
---|
| 983 | my ( $sid, $p ) = @_; |
---|
| 984 | my $from = $p->GetFrom(); |
---|
| 985 | my $to = $p->GetTo(); |
---|
| 986 | my $type = $p->GetType(); |
---|
| 987 | my %props = ( |
---|
| 988 | to => $to, |
---|
| 989 | from => $from, |
---|
| 990 | recipient => $to, |
---|
| 991 | sender => $from, |
---|
| 992 | type => 'jabber', |
---|
| 993 | jtype => $p->GetType(), |
---|
| 994 | status => $p->GetStatus(), |
---|
| 995 | show => $p->GetShow(), |
---|
| 996 | xml => $p->GetXML(), |
---|
| 997 | direction => 'in'); |
---|
| 998 | |
---|
| 999 | if ($type eq '' || $type eq 'available') { |
---|
| 1000 | $props{body} = "$from is now online. "; |
---|
| 1001 | $props{loginout} = 'login'; |
---|
| 1002 | } |
---|
| 1003 | else { |
---|
| 1004 | $props{body} = "$from is now offline. "; |
---|
| 1005 | $props{loginout} = 'logout'; |
---|
| 1006 | } |
---|
| 1007 | $props{replysendercmd} = $props{replycmd} = "jwrite $from -i $sid"; |
---|
[575877f] | 1008 | if(BarnOwl::getvar('debug') eq 'on') { |
---|
[f3c1aba] | 1009 | BarnOwl::queue_message(BarnOwl::Message->new(%props)); |
---|
[575877f] | 1010 | } |
---|
[f62550d] | 1011 | } |
---|
| 1012 | |
---|
| 1013 | sub process_presence_subscribe { |
---|
| 1014 | my ( $sid, $p ) = @_; |
---|
| 1015 | my $from = $p->GetFrom(); |
---|
| 1016 | my $to = $p->GetTo(); |
---|
| 1017 | my %props = ( |
---|
| 1018 | to => $to, |
---|
| 1019 | from => $from, |
---|
| 1020 | xml => $p->GetXML(), |
---|
| 1021 | type => 'admin', |
---|
| 1022 | adminheader => 'Jabber presence: subscribe', |
---|
| 1023 | direction => 'in'); |
---|
| 1024 | |
---|
[5551208] | 1025 | $props{body} = "Allow user ($from) to subscribe to your ($to) presence?\n" . |
---|
| 1026 | "(Answer with the `yes' or `no' commands)"; |
---|
| 1027 | $props{yescommand} = "jroster auth $from -a $to"; |
---|
| 1028 | $props{nocommand} = "jroster deauth $from -a $to"; |
---|
| 1029 | $props{question} = "true"; |
---|
[d609dd6] | 1030 | BarnOwl::queue_message(BarnOwl::Message->new(%props)); |
---|
[f62550d] | 1031 | } |
---|
| 1032 | |
---|
| 1033 | sub process_presence_unsubscribe { |
---|
| 1034 | my ( $sid, $p ) = @_; |
---|
| 1035 | my $from = $p->GetFrom(); |
---|
| 1036 | my $to = $p->GetTo(); |
---|
| 1037 | my %props = ( |
---|
| 1038 | to => $to, |
---|
| 1039 | from => $from, |
---|
| 1040 | xml => $p->GetXML(), |
---|
| 1041 | type => 'admin', |
---|
| 1042 | adminheader => 'Jabber presence: unsubscribe', |
---|
| 1043 | direction => 'in'); |
---|
| 1044 | |
---|
| 1045 | $props{body} = "The user ($from) has been unsubscribed from your ($to) presence.\n"; |
---|
[d609dd6] | 1046 | BarnOwl::queue_message(BarnOwl::Message->new(%props)); |
---|
[f62550d] | 1047 | |
---|
| 1048 | # Find a connection to reply with. |
---|
| 1049 | foreach my $jid ($conn->getJids()) { |
---|
| 1050 | my $cJid = new Net::XMPP::JID; |
---|
| 1051 | $cJid->SetJID($jid); |
---|
| 1052 | if ($to eq $cJid->GetJID('base') || |
---|
| 1053 | $to eq $cJid->GetJID('full')) { |
---|
| 1054 | my $reply = $p->Reply(type=>"unsubscribed"); |
---|
[bed4ff1] | 1055 | $conn->getConnectionFromJidStr($jid)->Send($reply); |
---|
[f62550d] | 1056 | return; |
---|
| 1057 | } |
---|
| 1058 | } |
---|
| 1059 | } |
---|
[38ffdf9] | 1060 | |
---|
[f62550d] | 1061 | sub process_presence_subscribed { |
---|
| 1062 | my ( $sid, $p ) = @_; |
---|
| 1063 | queue_admin_msg("ignoring:".$p->GetXML()); |
---|
| 1064 | # RFC 3921 says we should respond to this with a "subscribe" |
---|
| 1065 | # but this causes a flood of sub/sub'd presence packets with |
---|
| 1066 | # some servers, so we won't. We may want to detect this condition |
---|
| 1067 | # later, and have per-server settings. |
---|
| 1068 | return; |
---|
| 1069 | } |
---|
| 1070 | |
---|
| 1071 | sub process_presence_unsubscribed { |
---|
| 1072 | my ( $sid, $p ) = @_; |
---|
| 1073 | queue_admin_msg("ignoring:".$p->GetXML()); |
---|
| 1074 | # RFC 3921 says we should respond to this with a "subscribe" |
---|
| 1075 | # but this causes a flood of unsub/unsub'd presence packets with |
---|
| 1076 | # some servers, so we won't. We may want to detect this condition |
---|
| 1077 | # later, and have per-server settings. |
---|
| 1078 | return; |
---|
[b405ff6] | 1079 | } |
---|
[38ffdf9] | 1080 | |
---|
[9667006] | 1081 | sub process_presence_error { |
---|
| 1082 | my ( $sid, $p ) = @_; |
---|
| 1083 | my $code = $p->GetErrorCode(); |
---|
| 1084 | my $error = $p->GetError(); |
---|
[d609dd6] | 1085 | BarnOwl::error("Jabber: $code $error"); |
---|
[9667006] | 1086 | } |
---|
| 1087 | |
---|
[f62550d] | 1088 | |
---|
[38ffdf9] | 1089 | ### Helper functions |
---|
| 1090 | |
---|
[b405ff6] | 1091 | sub j2hash { |
---|
| 1092 | my $j = shift; |
---|
[f62550d] | 1093 | my %initProps = %{ shift() }; |
---|
[38ffdf9] | 1094 | |
---|
[f62550d] | 1095 | my $dir = 'none'; |
---|
| 1096 | my %props = ( type => 'jabber' ); |
---|
| 1097 | |
---|
| 1098 | foreach my $k (keys %initProps) { |
---|
| 1099 | $dir = $initProps{$k} if ($k eq 'direction'); |
---|
| 1100 | $props{$k} = $initProps{$k}; |
---|
| 1101 | } |
---|
[38ffdf9] | 1102 | |
---|
[b6a253c] | 1103 | my $jtype = $props{jtype} = $j->GetType(); |
---|
[b405ff6] | 1104 | my $from = $j->GetFrom('jid'); |
---|
| 1105 | my $to = $j->GetTo('jid'); |
---|
[38ffdf9] | 1106 | |
---|
[b6a253c] | 1107 | $props{from} = $from->GetJID('full'); |
---|
| 1108 | $props{to} = $to->GetJID('full'); |
---|
[38ffdf9] | 1109 | |
---|
[b6a253c] | 1110 | $props{recipient} = $to->GetJID('base'); |
---|
| 1111 | $props{sender} = $from->GetJID('base'); |
---|
[b405ff6] | 1112 | $props{subject} = $j->GetSubject() if ( $j->DefinedSubject() ); |
---|
| 1113 | $props{thread} = $j->GetThread() if ( $j->DefinedThread() ); |
---|
| 1114 | $props{body} = $j->GetBody() if ( $j->DefinedBody() ); |
---|
| 1115 | $props{error} = $j->GetError() if ( $j->DefinedError() ); |
---|
| 1116 | $props{error_code} = $j->GetErrorCode() if ( $j->DefinedErrorCode() ); |
---|
[b6a253c] | 1117 | $props{xml} = $j->GetXML(); |
---|
[38ffdf9] | 1118 | |
---|
[b405ff6] | 1119 | if ( $jtype eq 'chat' ) { |
---|
| 1120 | $props{replycmd} = |
---|
[f62550d] | 1121 | "jwrite " . ( ( $dir eq 'in' ) ? $props{from} : $props{to} ); |
---|
| 1122 | $props{replycmd} .= |
---|
| 1123 | " -a " . ( ( $dir eq 'out' ) ? $props{from} : $props{to} ); |
---|
[cb769bb] | 1124 | $props{private} = 1; |
---|
[38ffdf9] | 1125 | } |
---|
[b405ff6] | 1126 | elsif ( $jtype eq 'groupchat' ) { |
---|
| 1127 | my $nick = $props{nick} = $from->GetResource(); |
---|
| 1128 | my $room = $props{room} = $from->GetJID('base'); |
---|
[f62550d] | 1129 | $props{replycmd} = "jwrite -g $room"; |
---|
| 1130 | $props{replycmd} .= |
---|
| 1131 | " -a " . ( ( $dir eq 'out' ) ? $props{from} : $props{to} ); |
---|
[b405ff6] | 1132 | |
---|
| 1133 | $props{sender} = $nick || $room; |
---|
| 1134 | $props{recipient} = $room; |
---|
| 1135 | |
---|
| 1136 | if ( $props{subject} && !$props{body} ) { |
---|
| 1137 | $props{body} = |
---|
| 1138 | '[' . $nick . " has set the topic to: " . $props{subject} . "]"; |
---|
| 1139 | } |
---|
[b6a253c] | 1140 | } |
---|
[b405ff6] | 1141 | elsif ( $jtype eq 'normal' ) { |
---|
| 1142 | $props{replycmd} = undef; |
---|
[cb769bb] | 1143 | $props{private} = 1; |
---|
[b6a253c] | 1144 | } |
---|
[b405ff6] | 1145 | elsif ( $jtype eq 'headline' ) { |
---|
| 1146 | $props{replycmd} = undef; |
---|
[b6a253c] | 1147 | } |
---|
[b405ff6] | 1148 | elsif ( $jtype eq 'error' ) { |
---|
| 1149 | $props{replycmd} = undef; |
---|
| 1150 | $props{body} = "Error " |
---|
| 1151 | . $props{error_code} |
---|
| 1152 | . " sending to " |
---|
| 1153 | . $props{from} . "\n" |
---|
| 1154 | . $props{error}; |
---|
| 1155 | } |
---|
| 1156 | |
---|
[f62550d] | 1157 | $props{replysendercmd} = $props{replycmd}; |
---|
[b6a253c] | 1158 | return %props; |
---|
| 1159 | } |
---|
[38ffdf9] | 1160 | |
---|
[b405ff6] | 1161 | sub j2o { |
---|
[d609dd6] | 1162 | return BarnOwl::Message->new( j2hash(@_) ); |
---|
[38ffdf9] | 1163 | } |
---|
| 1164 | |
---|
[b405ff6] | 1165 | sub queue_admin_msg { |
---|
[38ffdf9] | 1166 | my $err = shift; |
---|
[d609dd6] | 1167 | my $m = BarnOwl::Message->new( |
---|
[b405ff6] | 1168 | type => 'admin', |
---|
| 1169 | direction => 'none', |
---|
| 1170 | body => $err |
---|
| 1171 | ); |
---|
[d609dd6] | 1172 | BarnOwl::queue_message($m); |
---|
[38ffdf9] | 1173 | } |
---|
[b6a253c] | 1174 | |
---|
[b405ff6] | 1175 | sub boldify($) { |
---|
[9f183ff] | 1176 | my $str = shift; |
---|
[b6a253c] | 1177 | |
---|
[b405ff6] | 1178 | return '@b(' . $str . ')' if ( $str !~ /\)/ ); |
---|
| 1179 | return '@b<' . $str . '>' if ( $str !~ /\>/ ); |
---|
| 1180 | return '@b{' . $str . '}' if ( $str !~ /\}/ ); |
---|
| 1181 | return '@b[' . $str . ']' if ( $str !~ /\]/ ); |
---|
[b6a253c] | 1182 | |
---|
[9667006] | 1183 | my $txt = "$str"; |
---|
| 1184 | $txt =~ s{[)]}{)\@b[)]\@b(}g; |
---|
| 1185 | return '@b(' . $txt . ')'; |
---|
[b6a253c] | 1186 | } |
---|
| 1187 | |
---|
[b405ff6] | 1188 | sub getServerFromJID { |
---|
[6a6dd47] | 1189 | my $jid = shift; |
---|
| 1190 | my $res = new Net::DNS::Resolver; |
---|
[b405ff6] | 1191 | my $packet = |
---|
| 1192 | $res->search( '_xmpp-client._tcp.' . $jid->GetServer(), 'srv' ); |
---|
[6a6dd47] | 1193 | |
---|
[b405ff6] | 1194 | if ($packet) # Got srv record. |
---|
[6a6dd47] | 1195 | { |
---|
[b405ff6] | 1196 | my @answer = $packet->answer; |
---|
| 1197 | return $answer[0]{target}, $answer[0]{port}; |
---|
[6a6dd47] | 1198 | } |
---|
| 1199 | |
---|
| 1200 | return $jid->GetServer(), 5222; |
---|
| 1201 | } |
---|
| 1202 | |
---|
[9f183ff] | 1203 | sub defaultJID { |
---|
[f62550d] | 1204 | return ( $conn->getJids() )[0] if ( $conn->connected() == 1 ); |
---|
[b405ff6] | 1205 | return; |
---|
[9f183ff] | 1206 | } |
---|
| 1207 | |
---|
[84296f6] | 1208 | sub baseJID { |
---|
| 1209 | my $givenJidStr = shift; |
---|
| 1210 | my $givenJid = new Net::XMPP::JID; |
---|
| 1211 | $givenJid->SetJID($givenJidStr); |
---|
| 1212 | return $givenJid->GetJID('base'); |
---|
| 1213 | } |
---|
| 1214 | |
---|
[b405ff6] | 1215 | sub resolveJID { |
---|
[6a6dd47] | 1216 | my $givenJidStr = shift; |
---|
[b405ff6] | 1217 | my $givenJid = new Net::XMPP::JID; |
---|
[6a6dd47] | 1218 | $givenJid->SetJID($givenJidStr); |
---|
[b405ff6] | 1219 | |
---|
[6a6dd47] | 1220 | # Account fully specified. |
---|
[b405ff6] | 1221 | if ( $givenJid->GetResource() ) { |
---|
| 1222 | # Specified account exists |
---|
[f62550d] | 1223 | return $givenJidStr if ($conn->jidExists($givenJidStr) ); |
---|
[d609dd6] | 1224 | BarnOwl::error("Invalid account: $givenJidStr"); |
---|
[6a6dd47] | 1225 | } |
---|
[b405ff6] | 1226 | |
---|
[6a6dd47] | 1227 | # Disambiguate. |
---|
[b405ff6] | 1228 | else { |
---|
| 1229 | my $matchingJid = ""; |
---|
| 1230 | my $errStr = |
---|
| 1231 | "Ambiguous account reference. Please specify a resource.\n"; |
---|
| 1232 | my $ambiguous = 0; |
---|
| 1233 | |
---|
[f62550d] | 1234 | foreach my $jid ( $conn->getJids() ) { |
---|
[b405ff6] | 1235 | my $cJid = new Net::XMPP::JID; |
---|
| 1236 | $cJid->SetJID($jid); |
---|
| 1237 | if ( $givenJidStr eq $cJid->GetJID('base') ) { |
---|
| 1238 | $ambiguous = 1 if ( $matchingJid ne "" ); |
---|
| 1239 | $matchingJid = $jid; |
---|
| 1240 | $errStr .= "\t$jid\n"; |
---|
| 1241 | } |
---|
| 1242 | } |
---|
| 1243 | |
---|
| 1244 | # Need further disambiguation. |
---|
| 1245 | if ($ambiguous) { |
---|
| 1246 | queue_admin_msg($errStr); |
---|
| 1247 | } |
---|
| 1248 | |
---|
| 1249 | # Not one of ours. |
---|
| 1250 | elsif ( $matchingJid eq "" ) { |
---|
[d609dd6] | 1251 | BarnOwl::error("Invalid account: $givenJidStr"); |
---|
[b405ff6] | 1252 | } |
---|
| 1253 | |
---|
[84296f6] | 1254 | # It's this one. |
---|
[b405ff6] | 1255 | else { |
---|
| 1256 | return $matchingJid; |
---|
| 1257 | } |
---|
[6a6dd47] | 1258 | } |
---|
| 1259 | return ""; |
---|
| 1260 | } |
---|
[84296f6] | 1261 | |
---|
[25729b2] | 1262 | ##################################################################### |
---|
| 1263 | ##################################################################### |
---|
| 1264 | |
---|
[d609dd6] | 1265 | package BarnOwl::Message::Jabber; |
---|
[25729b2] | 1266 | |
---|
[d609dd6] | 1267 | our @ISA = qw( BarnOwl::Message ); |
---|
[25729b2] | 1268 | |
---|
| 1269 | sub jtype { shift->{jtype} }; |
---|
| 1270 | sub from { shift->{from} }; |
---|
| 1271 | sub to { shift->{to} }; |
---|
[0d5d51b] | 1272 | sub room { shift->{room} }; |
---|
[25729b2] | 1273 | |
---|
| 1274 | sub smartfilter { |
---|
| 1275 | my $self = shift; |
---|
| 1276 | my $inst = shift; |
---|
| 1277 | |
---|
[0d5d51b] | 1278 | my ($filter, $ftext); |
---|
| 1279 | |
---|
[25729b2] | 1280 | if($self->jtype eq 'chat') { |
---|
[0d5d51b] | 1281 | my $user; |
---|
[25729b2] | 1282 | if($self->direction eq 'in') { |
---|
| 1283 | $user = $self->from; |
---|
| 1284 | } else { |
---|
| 1285 | $user = $self->to; |
---|
| 1286 | } |
---|
| 1287 | $user = Net::Jabber::JID->new($user)->GetJID($inst ? 'full' : 'base'); |
---|
| 1288 | $filter = "jabber-user-$user"; |
---|
| 1289 | $ftext = qq{type ^jabber\$ and ( ( direction ^in\$ and from ^$user ) } . |
---|
| 1290 | qq{or ( direction ^out\$ and to ^$user ) ) }; |
---|
[d609dd6] | 1291 | BarnOwl::filter("$filter $ftext"); |
---|
[25729b2] | 1292 | return $filter; |
---|
[0d5d51b] | 1293 | } elsif ($self->jtype eq 'groupchat') { |
---|
| 1294 | my $room = $self->room; |
---|
| 1295 | $filter = "jabber-room-$room"; |
---|
| 1296 | $ftext = qq{type ^jabber\$ and room ^$room\$}; |
---|
[d609dd6] | 1297 | BarnOwl::filter("$filter $ftext"); |
---|
[0d5d51b] | 1298 | return $filter; |
---|
[25729b2] | 1299 | } |
---|
| 1300 | } |
---|
| 1301 | |
---|
[84296f6] | 1302 | 1; |
---|