X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=lib%2FOnis%2FUsers.pm;h=2b4eb40d2e87430e1e8718afa3ed3954afcb0b4a;hb=b6854b441dbda2d31b904be2a6b76417becd3b5e;hp=9b07f15aa300eaa631dd9b04db1349c4c2d633cb;hpb=f980a0f03f3f7727a602b94251f8d6d1e3a15178;p=onis.git diff --git a/lib/Onis/Users.pm b/lib/Onis/Users.pm index 9b07f15..2b4eb40 100644 --- a/lib/Onis/Users.pm +++ b/lib/Onis/Users.pm @@ -3,13 +3,13 @@ package Onis::Users; use strict; use warnings; use Exporter; -use Onis::Config qw#get_config#; -use Onis::Data::Core qw(nick_to_ident); -use Onis::Data::Persistent; +use Onis::Config (qw(get_config)); +use Onis::Data::Persistent (); @Onis::Users::EXPORT_OK = (qw( - ident_to_name chatter_to_name nick_to_name name_to_ident + chatter_to_name + name_to_chatter name_to_ident name_to_nick get_realname get_link get_image )); @Onis::Users::ISA = ('Exporter'); @@ -24,12 +24,11 @@ Parses user-info and provides query-routines. The definition of "name" can be fo =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); @@ -43,17 +42,28 @@ Set $::DEBUG to ``0x1000'' to get extra debug messages. =cut our $Users = {}; -our $IdentToName = {}; -our $NameToIdent = {}; +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: I; + +Sets the file from which to read the user configuration. + +=back + +=cut + sub read_config { my $config_file = 'users.conf'; @@ -186,80 +196,84 @@ sub read_config =over 4 -=item B (I<$ident>) +=item B (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. =cut -sub ident_to_name +sub chatter_to_name { - my $ident = shift; - my $name = ''; + my $chatter = shift; + my $retval = ''; - if (defined ($IdentToName->{$ident})) + if (defined ($ChatterToName->{$chatter})) { - $name = $IdentToName->{$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 = $name; + 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''"; } - - $IdentToName->{$ident} = $name; - $NameToIdent->{$name} = $ident if ($name); - return ($name); + + $ChatterToName->{$chatter} = $retval; + $NameToChatter->{$retval} = $chatter if ($retval); + + return ($retval); } -=item B (I<$chatter>) +=item B (I<$name>) -Passes the ident-part of I<$chatter> to B. +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; - return (ident_to_name ($ident)); + if (defined ($NameToChatter->{$name})) + { + return ($NameToChatter->{$name}); + } + else + { + return (''); + } } -=item B (I<$nick>) +=item B (I<$name>) -Return the name associated with I<$nick>. This function uses B -(see L) to convert I<$nick> to an ident and then calls -B. +Returns the most recent ident for I<$name>. =cut -sub nick_to_name +sub name_to_ident { - 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 ($ident); } else { @@ -267,20 +281,22 @@ sub nick_to_name } } -=item B (I<$name>) +=item B (I<$name>) -Does the reverse of B: Returns the most recent association of -I<$name> to an ident. This function should rarely be needed.. +Returns the most recent nick for I<$name>. =cut -sub name_to_ident +sub name_to_nick { my $name = shift; - if (defined ($NameToIdent->{$name})) + if (defined ($NameToChatter->{$name})) { - return ($NameToIdent->{$name}); + my $chatter = $NameToChatter->{$name}; + my ($nick, $ident) = split (m/!/, $chatter); + + return ($nick); } else { @@ -354,3 +370,5 @@ sub get_image =head1 AUTHOR Florian octo Forster Eocto at verplant.orgE + +=cut