-=item B<store> (I<$type>, I<$data>)
-
-Passes I<$data> (a hashref) to all plugins which registered for I<$type>.
-
-=cut
-
-sub store
-{
- my $data = shift;
- my $type = $data->{'type'};
- my $nick;
- my $ident;
-
- if (!defined ($type))
- {
- print STDERR $/, __FILE__, ": Plugin data did not include a type. This line will be skipped." if ($::DEBUG & 0x20);
- return (undef);
- }
-
- if (!defined ($data->{'nick'}))
- {
- print STDERR $/, __FILE__, ": Plugin data did not include a nick. This line will be skipped." if ($::DEBUG & 0x20);
- return (undef);
- }
-
- $nick = $data->{'nick'};
-
- if (defined ($data->{'host'}))
- {
- my $user = host_to_username ($nick . '!' . $data->{'host'});
-
- if ($user)
- {
- $data->{'ident'} = $user;
- $NICK2IDENT{$nick} = $user;
- }
- else
- {
- my $host = unsharp ($data->{'host'});
- $data->{'host'} = $host;
- $data->{'ident'} = $host;
- $NICK2IDENT{$nick} = $host;
- }
-
- if (defined ($DATA->{'byident'}{"$nick\@unidentified"}))
- {
- my $ident = $data->{'ident'};
-
- print STDERR $/, __FILE__, ": Merging ``$nick\@unidentified'' to ``$ident''" if ($::DEBUG & 0x100);
-
- if (!defined ($DATA->{'byident'}{$ident}))
- {
- $DATA->{'byident'}{$ident} = {};
- }
-
- add_hash ($DATA->{'byident'}{$ident}, $DATA->{'byident'}{"$nick\@unidentified"});
- delete ($DATA->{'byident'}{"$nick\@unidentified"});
- }
- }
- elsif (defined ($NICK2IDENT{$nick}))
- {
- $data->{'ident'} = $NICK2IDENT{$nick};
- }
- else
- {
- my $user = nick_to_username ($nick);
-
- if ($user)
- {
- $data->{'ident'} = $user;
- $NICK2IDENT{$nick} = $user;
- }
- else
- {
- $data->{'ident'} = $nick . '@unidentified';
- }
- }
-
- $ident = $data->{'ident'};
-
- if ($::DEBUG & 0x0100)
- {
- print STDERR $/, __FILE__, ": id ($nick) = ", $data->{'ident'};
- }
-
- if (defined ($data->{'channel'}))
- {
- my $chan = lc ($data->{'channel'});
- $DATA->{'channel'}{$chan}++;
- }
-
- if ($::DEBUG & 0x400)
- {
- my @keys = keys (%$data);
- for (sort (@keys))
- {
- my $key = $_;
- my $val = $data->{$key};
- print STDERR $/, __FILE__, ': ';
- printf STDERR ("%10s: %s", $key, $val);
- }
- }
-
- if (lc ($ident) eq "ignore")
- {
- print STDERR $/, __FILE__, ': Ignoring line from ignored user.' if ($::DEBUG & 0x0100);
- return (0);
- }
-
- $DATA->{'idents_of_nick'}{$nick}{$ident}++;
- $DATA->{'total_lines'}++;
-
- if (defined ($REGISTER->{$type}))
- {
- for (@{$REGISTER->{$type}})
- {
- my $sub_ref = $_;
- &$sub_ref ($data);
- }
- }
-
- return (1);
-}
-
-=item B<unsharp> (I<$ident>)
-
-Takes an ident (i.e. a user-host-pair, e.g. I<user@host.domain.com> or
-I<login@123.123.123.123>) and "unsharps it". The unsharp version is then
-returned.
-
-What unsharp exactly does is described in the F<README>.
-
-=cut
-
-sub unsharp
-{
- my $user_host = shift;
-
- my $user;
- my $host;
- my @parts;
- my $num_parts;
- my $i;
- my $retval;
-
- print STDERR $/, __FILE__, ": Unsharp ``$user_host''" if ($::DEBUG & 0x100);
-
- ($user, $host) = split (m/@/, $user_host, 2);
-
- @parts = split (m/\./, $host);
- $num_parts = scalar (@parts);
-
- if (($UNSHARP ne 'NONE')
- and ($user =~ m/^[\~\^\-\+\=](.+)$/))
- {
- $user = $1;
- }
-
- if ($UNSHARP eq 'NONE')
- {
- return ($user . '@' . $host);
- }
- elsif ($host =~ m/^[\d\.]{7,15}$/)
- {
- if ($UNSHARP ne 'LIGHT')
- {
- $parts[-1] = '*';
- }
- }
- else
- {
- for ($i = 0; $i < ($num_parts - 2); $i++)
- {
- if ($UNSHARP eq 'LIGHT')
- {
- if ($parts[$i] !~ s/\d+/*/g)
- {
- last;
- }
- }
- elsif ($UNSHARP eq 'MEDIUM')
- {
- if ($parts[$i] =~ m/\d/)
- {
- $parts[$i] = '*';
- }
- else
- {
- last;
- }
- }
- else # ($UNSHARP eq 'HARD')
- {
- $parts[$i] = '*';
- }
- }
- }
-
- $host = lc (join ('.', @parts));
- $host =~ s/\*(\.\*)+/*/;
- $retval = $user . '@' . $host;
-
- print STDERR " -> ``$retval''" if ($::DEBUG & 0x100);
- return ($retval);
-}
-