| 1 | package DJabberd::SASL::AuthenSASL; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use base qw/DJabberd::SASL/; | ||
| 6 | |||
| 7 | sub set_config_mechanisms { | ||
| 8 | my ($self, $val) = @_; | ||
| 9 | $self->{mechanisms} = { map { uc $_ => 1 } split /\s+/, ($val || "") }; | ||
| 10 | } | ||
| 11 | |||
| 12 | sub mechanisms { | ||
| 13 | my $plugin = shift; | ||
| 14 | return $plugin->{mechanisms} || {}; | ||
| 15 | } | ||
| 16 | |||
| 17 | sub register { | ||
| 18 | my ($plugin, $vhost) = @_; | ||
| 19 | $plugin->SUPER::register($vhost); | ||
| 20 | |||
| 21 | $vhost->register_hook("SendFeatures", sub { | ||
| 22 | my ($vh, $cb, $conn) = @_; | ||
| 23 | if (my $sasl_conn = $conn->sasl) { | ||
| 24 | if ($sasl_conn->is_success) { | ||
| 25 | return; | ||
| 26 | } | ||
| 27 | } | ||
| 28 | my @mech = $plugin->mechanisms_list; | ||
| 29 | my $xml_mechanisms = | ||
| 30 | "<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"; | ||
| 31 | $xml_mechanisms .= join "", map { "<mechanism>$_</mechanism>" } @mech; | ||
| 32 | $xml_mechanisms .= "<optional/>" if $plugin->is_optional; | ||
| 33 | $xml_mechanisms .= "</mechanisms>"; | ||
| 34 | $cb->stanza($xml_mechanisms); | ||
| 35 | }); | ||
| 36 | } | ||
| 37 | |||
| 38 | 1; | ||
| 39 | |||
| 40 | __END__ |