Skip to content

Commit

Permalink
Merge pull request #50 from rufferson/fixes
Browse files Browse the repository at this point in the history
Various Fixes
  • Loading branch information
rufferson committed Oct 28, 2020
2 parents 5c97262 + fde404e commit 9fa945d
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 26 deletions.
2 changes: 1 addition & 1 deletion lib/DJabberd.pm
Expand Up @@ -482,7 +482,7 @@ sub _start_server {
if(lc($1) eq 'g') {
my ($gn,undef,$gid,$mm) = getgrnam($2);
my $un = getpwuid($<);
$logger->debug("Need to chgrp $sock to $gn/$gid: $un should be in '$mm' or $< == 0");
$logger->debug("Need to chgrp $sock to $gn/$gid: $un should be in members($mm) or EUID[$<] == 0");
if($<==0 || grep{$_ eq $un}split('\s+',$mm)) {
chown(-1, $gid, $sock) or $logger->logdie("Error changing group: $@\n");
if(!($stat[2] & 020)) {
Expand Down
3 changes: 3 additions & 0 deletions lib/DJabberd/Delivery/S2S.pm
Expand Up @@ -37,6 +37,9 @@ sub deliver {
return $cb->declined;

$DJabberd::Stats::counter{deliver_s2s}++;

$stanza->replace_ns("jabber:client", "jabber:server");

$out_queue->queue_stanza($stanza, $cb);
}

Expand Down
8 changes: 5 additions & 3 deletions lib/DJabberd/Form.pm
Expand Up @@ -21,10 +21,10 @@ sub new {
my $class = shift;
my $self;
# Try to create from XMLElement tree
if(@_ && $_[0] && ref($_[0]) && UNIVERSAL::isa($_[0],'DJabberd::XMLElement') && $_[0]->element eq '{jabber:x:data}x' && $_[0]->children) {
if(@_ && $_[0] && ref($_[0]) && UNIVERSAL::isa($_[0],'DJabberd::XMLElement') && $_[0]->element eq '{jabber:x:data}x' && ($_[0]->children || $_[0]->attr('{}type') eq 'cancel')) {
$self = from_element($_[0]);
} else {
# Or from raw struct: new('type',[{var=>"var",value=>["val"]},...],[title=>"title",][instructions=>"instructions"]);
# Or from raw struct: new('type',[{var=>"var",value=>["val"],type=>"type",option=>[{value=>"val",label=>"label"},...]},...],[title=>"title",][instructions=>"instructions"]);
my $type = shift;
my $fields = shift;
my %args = @_;
Expand Down Expand Up @@ -109,7 +109,9 @@ sub form_type {
my $self = shift;
my $type = '';
if(exists $self->{fields}->{FORM_TYPE}) {
if($self->{fields}->{FORM_TYPE}->{type} && $self->{fields}->{FORM_TYPE}->{type} eq 'hidden') {
if(($self->{fields}->{FORM_TYPE}->{type} && $self->{fields}->{FORM_TYPE}->{type} eq 'hidden')
|| $self->{type} eq 'submit')
{
$type = $self->{fields}->{FORM_TYPE}->{value}->[0];
}
}
Expand Down
20 changes: 13 additions & 7 deletions lib/DJabberd/Presence.pm
Expand Up @@ -431,14 +431,13 @@ sub broadcast_from {
}

# For the purpose of presence broadcasting
# we act as if all of the other resources
# we act as if all of the bound resources
# for this bare JID are on the roster.
# This means that resources of the same
# JID are aware of each other and can send
# messages to each other, etc.
foreach my $otherconn ($vhost->find_conns_of_bare($from_jid)) {
my $to_jid = $otherconn->bound_jid;
next if $from_jid->eq($to_jid);
my $dpres = $self->clone;
$dpres->set_to($to_jid);
$dpres->set_from($from_jid);
Expand All @@ -462,10 +461,17 @@ sub _process_outbound_available {
$self->_process_outbound_available($conn, 1);
},
},
# Enable fall-through signal-like notifications where
# all subscribers decline it all the way through
fallback => sub {
return if $conn->{closed} > 0;
$self->_process_outbound_available($conn, 1);
},
);
return;
}

$conn->log->debug($self->as_xml);
if ($self->is_directed) {
$conn->add_directed_presence($self->to_jid);
$self->deliver;
Expand Down Expand Up @@ -498,11 +504,11 @@ sub _process_outbound_unavailable {
$self->_process_outbound_unavailable($conn, 1);
},
},
# No idea how it was supposed to be working
# but this way it does
fallback => sub {
$self->_process_outbound_unavailable($conn, 1);
},
# Enable fall-through signal-like notifications where
# all subscribers decline it all the way through
fallback => sub {
$self->_process_outbound_unavailable($conn, 1);
},
);
return;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/DJabberd/RosterStorage.pm
Expand Up @@ -18,6 +18,9 @@ use DJabberd::RosterItem;
}
}

# let others be
sub run_after { qw(ALL) }

# don't override, or at least call SUPER to this if you do.
sub register {
my ($self, $vhost) = @_;
Expand Down
3 changes: 2 additions & 1 deletion lib/DJabberd/Stanza.pm
Expand Up @@ -173,7 +173,8 @@ sub make_error_response {
"{}type" => $type,
},
[
ref $error ? $error : new DJabberd::XMLElement("urn:ietf:params:xml:ns:xmpp-stanzas", $error, {}, []),
ref $error ? $error : new DJabberd::XMLElement("urn:ietf:params:xml:ns:xmpp-stanzas", $error,
{xmlns=>'urn:ietf:params:xml:ns:xmpp-stanzas'}, []),
],
);

Expand Down
4 changes: 2 additions & 2 deletions lib/DJabberd/VHost.pm
Expand Up @@ -380,12 +380,12 @@ sub register_hook {
my $aa = $a->{pkg}->can('run_after');
my $bb = $b->{pkg}->can('run_before');
my $ba = $b->{pkg}->can('run_after');
return -1 if($ab && grep{$_ eq 'ALL'}$ab->($phase) && !($bb && grep{$_ eq 'ALL'}$bb->($phase)));
return -1 if($ab && (grep{$_ eq 'ALL'}$ab->($phase)) && !($bb && grep{$_ eq 'ALL'}$bb->($phase)));
return -1 if($ab && grep{$_ eq $b->{pkg}}$ab->($phase));
return -1 if($ba && grep{$_ eq $a->{pkg}}$ba->($phase));
return +1 if($aa && grep{$_ eq $b->{pkg}}$aa->($phase));
return +1 if($bb && grep{$_ eq $a->{pkg}}$bb->($phase));
return +1 if($aa && grep{$_ eq 'ALL'}$aa->($phase) && !($ba && grep{$_ eq 'ALL'}$ba->($phase)));
return +1 if($aa && (grep{$_ eq 'ALL'}$aa->($phase)) && !($ba && grep{$_ eq 'ALL'}$ba->($phase)));
#$logger->debug('Keeping the ordering for '.$a->{pkg}.' and '.$b->{pkg});
return 0;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/DJabberd/XMLElement.pm
Expand Up @@ -156,7 +156,7 @@ sub as_xml {
}

my $attr_str = "";
my $attr = $self->{attrs};
my $attr = { %{$self->{attrs}} };

$nsmap->{xmlns} = 'http://www.w3.org/2000/xmlns';
$nsmap->{'http://www.w3.org/2000/xmlns'} = 'xmlns';
Expand Down
5 changes: 4 additions & 1 deletion t/directed-presence-v6.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
use strict;
use Test::More tests => 28;
use Test::More tests => 34;
use lib 't/lib';
require 'djabberd-test.pl';

Expand All @@ -9,7 +9,9 @@ two_parties(sub {
$pa->login;
$pb->login;
$pa->send_xml("<presence/>");
like($pa->recv_xml, qr{from=['"]$pa}, "Self presence check");
$pb->send_xml("<presence/>");
like($pb->recv_xml, qr{from=['"]$pb}, "Self presence check");

select(undef, undef, undef, 0.25);

Expand All @@ -27,6 +29,7 @@ two_parties(sub {
like($xml, qr{presence});

$pa->send_xml(qq{<presence><show>this should not go to B</show></presence>});
like($pa->recv_xml, qr/><show>this should not go to B</, "pa got own presence");
$pa->send_xml("<message type='chat' to='$pb'>Hello. I am $pa.</message>");
like($pb->recv_xml, qr/type=.chat.*Hello.*I am \Q$pa\E/, "pb got pa's message");

Expand Down
5 changes: 4 additions & 1 deletion t/directed-presence.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
use strict;
use Test::More tests => 28;
use Test::More tests => 34;
use lib 't/lib';
require 'djabberd-test.pl';

Expand All @@ -9,7 +9,9 @@ two_parties(sub {
$pa->login;
$pb->login;
$pa->send_xml("<presence/>");
like($pa->recv_xml, qr/from=["']$pa/, "own presence check");
$pb->send_xml("<presence/>");
like($pb->recv_xml, qr/from=["']$pb/, "own presence check");

select(undef, undef, undef, 0.25);

Expand All @@ -27,6 +29,7 @@ two_parties(sub {
like($xml, qr{presence});

$pa->send_xml(qq{<presence><show>this should not go to B</show></presence>});
like($pa->recv_xml, qr/from=["']$pa/, "own presence check");
$pa->send_xml("<message type='chat' to='$pb'>Hello. I am $pa.</message>");
like($pb->recv_xml, qr/type=.chat.*Hello.*I am \Q$pa\E/, "pb got pa's message");

Expand Down
4 changes: 3 additions & 1 deletion t/exchange-messages.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
use strict;
use Test::More tests => 10;
use Test::More tests => 14;
use lib 't/lib';

require 'djabberd-test.pl';
Expand All @@ -18,7 +18,9 @@ two_parties(sub {

# now pa/pb send presence to become available resources
$pa->send_xml("<presence/>");
like($pa->recv_xml, qr/from=["']$pa/, "own presence check");
$pb->send_xml("<presence/>");
like($pb->recv_xml, qr/from=["']$pb/, "own presence check");
select(undef, undef, undef, 0.25);

# PA to PB
Expand Down
3 changes: 2 additions & 1 deletion t/handle-stanza-hook.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
use strict;
use Test::More tests => 3;
use Test::More tests => 4;
use lib 't/lib';
require 'djabberd-test.pl';

Expand Down Expand Up @@ -55,6 +55,7 @@ my $client = Test::DJabberd::Client->new(server => $server, name => "client");
{
$client->login;
$client->send_xml("<presence/>");
like($client->recv_xml, qr/from=["']$client/, "own presence check");

select(undef, undef, undef, 0.25);

Expand Down
3 changes: 2 additions & 1 deletion t/inband-reg.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl

use strict;
use Test::More tests => 7;
use Test::More tests => 8;
use lib 't/lib';
BEGIN { $ENV{LOGLEVEL} ||= "FATAL" }
BEGIN { require 'djabberd-test.pl' }
Expand Down Expand Up @@ -52,6 +52,7 @@ my $client = Test::DJabberd::Client->new(server => $server, name => "testuser");
$client->login("jabberwocky");

$client->send_xml("<presence/>");
like($client->recv_xml, qr/<presence\s+.*from=["']$client/, "own presence check");
$client->send_xml("<message type='chat' to='$client'>Hello myself!</message>");
like($client->recv_xml, qr/Hello myself/, "client got own message");

Expand Down
4 changes: 3 additions & 1 deletion t/iq-exchange.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl
use strict;
use Test::More tests => 4;
use Test::More tests => 8;
use lib 't/lib';

require 'djabberd-test.pl';
Expand All @@ -10,7 +10,9 @@ two_parties(sub {
$pa->login;
$pb->login;
$pa->send_xml("<presence/>");
like($pa->recv_xml, qr/from=["']$pa/, "own presence check");
$pb->send_xml("<presence/>");
like($pb->recv_xml, qr/from=["']$pb/, "own presence check");
select(undef,undef,undef,0.25);

my $ja = DJabberd::JID->new($pa.'/'.$pb->resource);
Expand Down
6 changes: 5 additions & 1 deletion t/mutual-add-and-presence.t
@@ -1,17 +1,19 @@
#!/usr/bin/perl
use strict;
use Test::More tests => 36;
use Test::More tests => 44;
use lib 't/lib';
require 'djabberd-test.pl';

two_parties(sub {
my ($pa, $pb) = @_;
$pa->login;
$pa->send_xml(qq{<presence><status>Init-A-Pres</status></presence>});
like($pa->recv_xml, qr/from=["']$pa/, "own presence check");
$pa->get_roster; # pb isn't going to request its roster.

$pb->login;
$pb->send_xml(qq{<presence><status>InitPres</status></presence>});
like($pb->recv_xml, qr/from=["']$pb/, "own presence check");

$pa->send_xml(qq{<iq type='set' id='set1'>
<query xmlns='jabber:iq:roster'>
Expand Down Expand Up @@ -73,6 +75,7 @@ two_parties(sub {

# now PA is subscribed to PB. so let's make PB change its status
$pb->send_xml(qq{<presence><status>PresVer2</status></presence>});
like($pb->recv_xml, qr/from=["']$pb/, "own presence check");
$xml = $pa->recv_xml;
like($xml, qr/<presence.+\bfrom=.$pb.+PresVer2/s, "partya got presver2 presence of pb");

Expand Down Expand Up @@ -111,6 +114,7 @@ two_parties(sub {


$pa->send_xml(qq{<presence><status>I_am_A</status></presence>});
like($pa->recv_xml, qr/from=["']$pa/, "own presence check");
$pb->send_xml(qq{<presence><status>I_am_B</status></presence>});
like($pa->recv_xml, qr/I_am_B/, "a got b's presence");
like($pb->recv_xml, qr/I_am_A/, "b got a's presence");
Expand Down
4 changes: 3 additions & 1 deletion t/quirk-libgaim-iqerrorfrom.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl

use strict;
use Test::More tests => 14;
use Test::More tests => 22;
use lib 't/lib';

BEGIN {
Expand Down Expand Up @@ -32,7 +32,9 @@ sub run_test {
$pa->login;
$pb->login;
$pa->send_xml("<presence/>");
like($pa->recv_xml, qr/from=["']$pa/, "own presence check");
$pb->send_xml("<presence/>");
like($pb->recv_xml, qr/from=["']$pb/, "own presence check");

my $xml;

Expand Down
2 changes: 2 additions & 0 deletions t/s2s-no-dialback-to.t
Expand Up @@ -19,7 +19,9 @@ sub test {
$pa->login;
$pb->login;
$pa->send_xml("<presence/>");
$pa->recv_xml;
$pb->send_xml("<presence/>");
$pb->recv_xml;

# PA to PB
$pa->send_xml("<message type='chat' to='$pb'>Hello. I am $pa.</message>");
Expand Down
4 changes: 4 additions & 0 deletions t/sasl-login.t
Expand Up @@ -23,7 +23,9 @@ my $login_and_be = sub {
my $jid = $pa->sasl_login($sasl, $res);
$pb->login;
$pa->send_xml("<presence/>");
$pa->recv_xml;
$pb->send_xml("<presence/>");
$pb->recv_xml;

select(undef,undef,undef,0.25); # doh
my $jb = DJabberd::JID->new($pb.'/'.$pb->resource);
Expand Down Expand Up @@ -94,7 +96,9 @@ my $login_and_be = sub {
my $jid = $pa->sasl_login($sasl, 'yann');
my $jib = $pb->sasl_login($sbsl, $pb->resource);
$pa->send_xml("<presence/>");
$pa->recv_xml;
$pb->send_xml("<presence/>");
$pb->recv_xml;

select(undef,undef,undef,0.25); # doh
my $jb = DJabberd::JID->new($pb.'/'.$pb->resource);
Expand Down
3 changes: 3 additions & 0 deletions t/server_die.t
Expand Up @@ -10,7 +10,9 @@ two_parties_s2s(sub {
$pa->login;
$pb->login;
$pa->send_xml("<presence/>");
$pa->recv_xml;
$pb->send_xml("<presence/>");
$pb->recv_xml;

$pa->send_xml("<message type='chat' to='$pb'>Hello. I am $pa.</message>");
like($pb->recv_xml, qr/type=.chat.*Hello.*I am \Q$pa\E/, "pb got pa's message");
Expand All @@ -22,6 +24,7 @@ two_parties_s2s(sub {
$server->start;
$pa->login;
$pa->send_xml("<presence/>");
$pa->recv_xml;

$pa->send_xml("<message type='chat' to='$pb'>Hello. I am $pa.</message>");
like($pb->recv_xml, qr/type=.chat.*Hello.*I am \Q$pa\E/, "pb got pa's message");
Expand Down

0 comments on commit 9fa945d

Please sign in to comment.