DJabberd/SASL.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 95 CC 5 SCAR 14.9
CC
5
Cov
0%
get_sasl_manager
12.0
is_optional
6.0
register
6.0
CRAP 4.4
1 package DJabberd::SASL;
2 use strict;
3 use warnings;
4  
5 use base qw/DJabberd::Plugin/;
6  
7 use DJabberd::Stanza::SASL;
8 use DJabberd::SASL::Connection;
9 use DJabberd::Util qw(as_bool);
10  
11 my $default = "DJabberd::SASL::Manager::AuthenSASL";
12 sub manager_class { $default }
13  
14 my $sasl_ns = "urn:ietf:params:xml:ns:xmpp-sasl";
15 my %sasl_elements = (
16 "{$sasl_ns}auth" => 'DJabberd::Stanza::SASL',
17 "{$sasl_ns}challenge" => 'DJabberd::Stanza::SASL',
18 "{$sasl_ns}response" => 'DJabberd::Stanza::SASL',
19 "{$sasl_ns}abort" => 'DJabberd::Stanza::SASL',
20 );
21  
22 sub get_sasl_manager {
23 my $self = shift;
24 my $conn = shift;
25  
26 my $vhost = $conn->vhost
27 or die "No VHost for this connection";
28  
29 my $class = $self->manager_class || $default;
30  
31 no strict 'refs';
32 unless (defined %{"${class}::"}) {
33 eval "use $class"; ## no critic
34 die $@ if $@;
35 }
36  
37 return $class->new($self, $conn);
38 }
39  
40 sub set_config_optional {
41 my ($self, $val) = @_;
42 $self->{optional} = as_bool($val);
43 }
44  
45 sub is_optional { return $_[0]->{optional} ? 1 : 0 }
46  
47 sub mechanisms { die "implement" }
48  
49 sub mechanisms_str {
50 my $plugin = shift;
51 return join " ", $plugin->mechanisms;
52 }
53  
54 sub mechanisms_list {
55 my $plugin = shift;
56 return keys %{ $plugin->mechanisms };
57 }
58  
59  
60 ## don't override, or be sure to call SUPER:: in the subclass
61 sub register {
62 my ($plugin, $vhost) = @_;
63  
64 $vhost->register_hook("GetSASLManager", sub {
65 my (undef, $cb, %args) = @_;
66 my $conn = $args{conn};
67 my $sasl = $plugin->get_sasl_manager($conn);
68 $cb->get($sasl);
69 });
70  
71 $vhost->register_hook("HandleStanza", sub {
72 my (undef, $cb, $node) = @_;
73 my $class = $sasl_elements{$node->element};
74 return unless $class;
75 $cb->handle($class);
76 return;
77 });
78 }
79  
80 1;
81  
82 __END__