X-Git-Url: https://git.p6c8.net/selfforum.git/blobdiff_plain/aaff267fdddc495df3bfa2fc0eb0d20a76b6d220..aa8d61528704dd0f5b5567f535161ffdecf4a135:/selfforum-cgi/shared/Id.pm diff --git a/selfforum-cgi/shared/Id.pm b/selfforum-cgi/shared/Id.pm index fb51d48..8e91379 100644 --- a/selfforum-cgi/shared/Id.pm +++ b/selfforum-cgi/shared/Id.pm @@ -1,65 +1,73 @@ -# Id.pm - -############################################## -# # -# Autor: n.d.p. / nd@o3media.de # -# # -# Letze Aenderung: n.d.p. / 2001-01-28 # -# # -# ========================================== # -# # -# Funktion: # -# # -# Bereitsstellen einer einmaligen ID # -# # -############################################## - -use strict; - package Id; -##################### -# Funktionsexport -##################### +################################################################################ +# # +# File: shared/Id.pm # +# # +# Authors: André Malo , 2001-05-03 # +# # +# Description: compose an unique ID (in CGI context) # +# # +################################################################################ -use base qw(Exporter); -@Id::EXPORT = qw(unique_id); +use strict; +use vars qw( + @table + @EXPORT + $VERSION +); -use vars qw(@table); +################################################################################ +# +# Version check +# +$VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; -########################################## -# EXPORT # -# # -# sub &unique_id # -# # -# Funktion: # -# Rueckgabe der ID # -########################################## +################################################################################ +# +# Export +# +use base qw(Exporter); +@EXPORT = qw( + unique_id + may_id +); -# sub unique_id ################################################ +### sub unique_id () ########################################################### # -# composing of an unique ID... +# compose an unique ID +# +# Params: ~none~ +# +# Return: Scalar: unique ID # sub unique_id () { my $id; - my $ip=$ENV{'REMOTE_ADDR'}; - my $time=time(); - my $port=$ENV{'REMOTE_PORT'}; - my $rand=int(rand(time())); - $ip = hex(join ('',map {sprintf ('%02X',$_)} split (/\./,$ip))); + my $ip=$ENV{REMOTE_ADDR}; + my $time=time; + my $port=$ENV{REMOTE_PORT}; + my $rand=int(rand(time)); + + # works only with IPv4! (will be changed later...) + # + $ip = hex(join ('',map {sprintf ('%02X',$_)} split (/\./,$ip))); - join '',map {to_base64 ($_)} ($time, $port, $ip, $rand, $$); + join '' => map {to_base64 ($_)} ($time, $port, $ip, $rand, $$); } -# sub to_base64 ################################################ +### sub to_base64 ($) ########################################################## +# +# only converts (max.) 32-bit numbers into a system with base 64 +# +# Params: $x - number to convert # -# only converts (max.) 32-bit numbers into a -# system with base 64 -# its not the RFC base64 format! +# Return: converted number ;-) # sub to_base64 ($) { my $x = shift; + return '' unless defined $x; + my $y = $table[$x % 64]; $y = $table[$x % 64].$y while ($x = int ($x/64)); @@ -68,13 +76,21 @@ sub to_base64 ($) { } BEGIN { - srand(time()^$$); + # 64 'digits' (for our base 64 system) + # @table = ('a'..'z','-','0'..'9','A'..'Z','_'); + + # define sub may_id + # + *may_id = eval join quotemeta join ('' => @table) => ( + q[sub {local $_=shift; defined and length and not y/], + q[//cd;}] + ); } -# making 'require' happy +# keep 'require' happy 1; -##################### -# end of Id -##################### \ No newline at end of file +# +# +### end of Id ################################################################## \ No newline at end of file