use strict;
use warnings;
use Exporter;
-use Onis::Config qw#get_config#;
-use Onis::Data::Core qw(nick_to_ident);
-use Onis::Data::Persistent;
-
-@Onis::Users::EXPORT_OK = qw#host_to_username nick_to_username get_link get_image get_realname#;
+use Onis::Config (qw(get_config));
+use Onis::Data::Persistent ();
+
+@Onis::Users::EXPORT_OK =
+(qw(
+ chatter_to_name
+ name_to_chatter name_to_ident name_to_nick
+ get_realname get_link get_image
+));
@Onis::Users::ISA = ('Exporter');
=head1 NAME
=head1 USAGE
- use Onis::Users qw#ident_to_name chatter_to_name nick_to_name get_realname get_link get_image#;
+ use Onis::Users qw#ident_to_name chatter_to_name get_realname get_link get_image#;
# Functions to query the name
$name = ident_to_name ($ident);
$name = chatter_to_name ($chatter);
- $name = nick_to_name ($nick);
# Functions to query a name's properties
my $realname = get_realname ($name);
=cut
our $Users = {};
-# FIXME
-our $HostmaskCache = init ('$HostmaskCache', 'hash');
+our $ChatterToName = {};
+our $NameToChatter = {};
-my $VERSION = '$Id: Users.pm,v 1.2 2004/08/01 13:45:27 octo Exp $';
+my $VERSION = '$Id$';
print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG);
read_config ();
return (1);
+=head1 CONFIGURATION OPTIONS
+
+=over 4
+
+=item B<users_config>: I<users.conf>;
+
+Sets the file from which to read the user configuration.
+
+=back
+
+=cut
+
sub read_config
{
my $config_file = 'users.conf';
=over 4
-=item B<ident_to_name> (I<$ident>)
+=item B<chatter_to_name> (I<$chatter>)
-Matches the ident against the configured hostmasks. Uses caching to
-speed up execution. Returns the name or an empty string if not found.
+Passes the ident-part of I<$chatter> to B<ident_to_name>.
=cut
-sub ident_to_name
+sub chatter_to_name
{
- my $ident = shift;
- my $name = '';
+ my $chatter = shift;
+ my $retval = '';
- if (defined ($HostmaskCache->{$ident}))
+ if (defined ($ChatterToName->{$chatter}))
{
- $name = $HostmaskCache->{$ident};
+ return ($ChatterToName->{$chatter});
}
- else
+
+ USER: for (keys %$Users)
{
- USER: for (keys (%$Users))
+ my $name = $_;
+ for (@{$Users->{$name}{'host'}})
{
- my $this_name = $_;
- for (@{$Users->{$this_name}{'host'}})
- {
- my $host_re = $_;
+ my $re = $_;
- if ($ident =~ $host_re)
- {
- $name = $this_name;
- last (USER);
- }
+ if ($chatter =~ $re)
+ {
+ $retval = $_;
+ last USER;
}
}
+ }
- if (($::DEBUG & 0x1000) and $name)
- {
- print STDERR $/, __FILE__, ": Host ``$ident'' belongs to ``$name''";
- }
+ if (($::DEBUG & 0x1000) and $retval)
+ {
+ print STDERR $/, __FILE__, ": ``$chatter'' identified as ``$retval''";
}
-
- $HostmaskCache->{$ident} = $name;
- return ($name);
+
+ $ChatterToName->{$chatter} = $retval;
+ $NameToChatter->{$retval} = $chatter if ($retval);
+
+ return ($retval);
}
-=item B<chatter_to_name> (I<$chatter>)
+=item B<name_to_chatter> (I<$name>)
-Passes the ident-part of I<$chatter> to B<ident_to_name>.
+Returns the most recent chatter for I<$name>.
=cut
-sub chatter_to_name
+sub name_to_chatter
{
- my $chatter = shift;
- my ($nick, $ident) = split (m/!/, $chatter);
+ my $name = shift;
+
+ if (defined ($NameToChatter->{$name}))
+ {
+ return ($NameToChatter->{$name});
+ }
+ else
+ {
+ return ('');
+ }
+}
+
+=item B<name_to_ident> (I<$name>)
+
+Returns the most recent ident for I<$name>.
+
+=cut
+
+sub name_to_ident
+{
+ my $name = shift;
- return (ident_to_name ($ident));
+ if (defined ($NameToChatter->{$name}))
+ {
+ my $chatter = $NameToChatter->{$name};
+ my ($nick, $ident) = split (m/!/, $chatter);
+
+ return ($ident);
+ }
+ else
+ {
+ return ('');
+ }
}
-=item B<nick_to_name> (I<$nick>)
+=item B<name_to_nick> (I<$name>)
-Return the name associated with I<$nick>. This function uses B<nick_to_ident>
-(see L<Onis::Data::Core>) to convert I<$nick> to an ident and then calls
-B<ident_to_name>.
+Returns the most recent nick for I<$name>.
=cut
-sub nick_to_name
+sub name_to_nick
{
- my $nick = shift;
- my $ident = nick_to_ident ($nick);
+ my $name = shift;
- if ($ident)
+ if (defined ($NameToChatter->{$name}))
{
- return (ident_to_name ($ident));
+ my $chatter = $NameToChatter->{$name};
+ my ($nick, $ident) = split (m/!/, $chatter);
+
+ return ($nick);
}
else
{
=head1 AUTHOR
Florian octo Forster E<lt>octo at verplant.orgE<gt>
+
+=cut