sub getMapping = { my $uri_in = shift; $uri_in =~ m!.*://([^/]*)!; my $domain = $1; my $dbh = getDBH(); my $path = ''; my $query = qq{ SELECT ftpID, uri, path # first get all records that FROM tURIMapping # refer to the domain WHERE uri REGEXP '.*$domain.*'; }; my $sth = $dbh->prepare($query); $sth->execute; my $aMapping = undef; # now let's search for the best match my $i = '0'; while ($aMapping = $sth->fetchrow_arrayref()){ # while there are still mappings my $target = $uri_in; # set the target while ($i < 5) { last if $aMapping->[1] eq $target; # exit if this is the mapping $target =~ s!(^\w+://.*)/(.*)$!$1!i; # remove the last part of the uri $path = '/'.$2.$path if $2; # save the last part as the path last if $target =~ m!^\w+://[^/]/?$!i; # exit if this just a domain $i++; } # end while ($i) last if $aMapping->[1] eq $target; # double check this is the target } # end while ($aMapping = $sth->fetchrow_arrayref()) die "No Mapping Found for $uri_in" unless $aMapping; my ($ftpID, $uri, $map_path) = @$aMapping; # if the ftpID is null my $type = $ftpID? 'ftpAccount':'filesystem'; # this is a filesystem $sth->finish; $dbh->disconnect; return ($type, $map_path.$path, $ftpID); };