Skip to content

Commit

Permalink
11.09: added %jelp_outgoing_commands and %jelp_incoming_commands APIs…
Browse files Browse the repository at this point in the history
…. added JELP SASL implementation. #9.             added sasl_mechanisms (SASL M) forwarding in TS6.
  • Loading branch information
cooper committed Jul 6, 2016
1 parent 2fce42e commit c76ddd5
Show file tree
Hide file tree
Showing 8 changed files with 437 additions and 22 deletions.
4 changes: 4 additions & 0 deletions INDEV
Expand Up @@ -3219,3 +3219,7 @@ CHANGES:
added support for sticky capabilities, updated SASL accordingly.
added cap-notify capability and version parameter to CAP LS.
cap-notify is sticky only when IRCv3.2 is used but not for IRCv3.1.

09. added %jelp_outgoing_commands and %jelp_incoming_commands APIs.
added JELP SASL implementation. #9.
added sasl_mechanisms (SASL M) forwarding in TS6.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
11.08
11.09
2 changes: 1 addition & 1 deletion modules/JELP/Base.module/Base.json
Expand Up @@ -11,5 +11,5 @@
},
"name" : "JELP::Base",
"package" : "M::JELP::Base",
"version" : "13.53"
"version" : "13.63"
}
56 changes: 39 additions & 17 deletions modules/JELP/Base.module/Base.pm
Expand Up @@ -22,15 +22,19 @@ my $PARAM_BAD = $message::PARAM_BAD;
my $props = $Evented::Object::props;

sub init {

# register methods.
$mod->register_module_method('register_jelp_command' ) or return;
$mod->register_module_method('register_global_command' ) or return;
$mod->register_module_method('register_outgoing_command') or return;
# module unload event.

# module events.
$api->on('module.unload' => \&unload_module, with_eo => 1) or return;

$api->on('module.init' => \&module_init,
name => '%jelp_outgoing_commands',
with_eo => 1
) or return;

return 1;
}

Expand All @@ -48,10 +52,10 @@ sub register_jelp_command {
L("JELP command $opts{name} does not have '$what' option");
return;
}

my $command = uc $opts{name};
my $e_name = "server.jelp_message_$command";

# attach the event.
$pool->on($e_name => \&_handle_command,
priority => 0, # registration commands are 500 priority
Expand All @@ -63,7 +67,7 @@ sub register_jelp_command {
parameters => $opts{parameters} // $opts{params},
cb_code => $opts{code}
});

# this callback forwards to other servers.
$pool->on($e_name => \&_forward_handler,
priority => 0,
Expand All @@ -72,33 +76,33 @@ sub register_jelp_command {
name => "jelp.$command.forward",
data => { forward => $opts{forward} }
) if $opts{forward};

$mod->list_store_add('jelp_commands', $command);
}

sub register_global_command {
my ($mod, $event, %opts) = @_;

# make sure all required options are present
foreach my $what (qw|name|) {
next if exists $opts{$what};
$opts{name} ||= 'unknown';
L("global command $opts{name} does not have '$what' option");
return;
}

# create a handler that calls ->handle_unsafe().
$opts{code} = sub {
my ($server, $msg, $user, $rest) = @_;
$user->handle_unsafe("$opts{name} $rest");
};

# pass it on to this base's ->register_jelp_command().
return register_jelp_command($mod, $event,
%opts,
parameters => '-source(user) :rest(opt)'
);

}

sub register_outgoing_command {
Expand Down Expand Up @@ -137,19 +141,19 @@ sub _handle_command {
# JELP param handlers and lookup method.
$msg->{source_lookup_method} = \&_lookup_source;
$msg->{param_package} = __PACKAGE__;

# figure parameters.
my @params;
if (my $params = $event->callback_data('parameters')) {
# $msg->{_event} = $event;
@params = $msg->parse_params($params);
return if defined $params[0] && $params[0] eq $message::PARAM_BAD;
}

# call actual callback.
$event->{$props}{data}{allow_fantasy} = $event->callback_data('fantasy');
$event->callback_data('cb_code')->($server, $msg, @params);

}

sub _forward_handler {
Expand All @@ -163,7 +167,7 @@ sub _forward_handler {
# forward = 2 means don't do it even if THAT server is bursting.
#
return if $forward == 2 && $server->{is_burst};

$server->send_children($msg->data);
}

Expand Down Expand Up @@ -196,7 +200,7 @@ sub _param_user {
# channel: match a channel name.
sub _param_channel {
my ($msg, $param, $params, $opts) = @_;
my $channel = $pool->lookup_channel((split ',', $param)[0]) or return $PARAM_BAD;
my $channel = $pool->lookup_channel((split ',', $param)[0]) or return $PARAM_BAD;
push @$params, $channel;
}

Expand All @@ -218,6 +222,24 @@ sub _lookup_source {
### Module events ###
#####################

sub module_init {
my ($mod, $event) = @_;

my %commands = $mod->get_symbol('%jelp_outgoing_commands');
$mod->register_outgoing_command(
name => $_,
code => $commands{$_}
) or return foreach keys %commands;

%commands = $mod->get_symbol('%jelp_incoming_commands');
$mod->register_jelp_command(
name => $_,
%{ $commands{$_} }
) or return foreach keys %commands;

return 1;
}

sub unload_module {
my ($mod, $event) = @_;
$pool->delete_outgoing_handler($_, 'jelp')
Expand Down
2 changes: 1 addition & 1 deletion modules/SASL/SASL.module/JELP.module/JELP.json
Expand Up @@ -6,5 +6,5 @@
"description" : "JELP SASL implementation",
"name" : "SASL::JELP",
"package" : "M::SASL::JELP",
"version" : "0.1"
"version" : "0.4"
}

0 comments on commit c76ddd5

Please sign in to comment.