danf: curl-www ipwhere.pm, 1.2, 1.3 latest.cgi, 1.41, 1.42 metalink.cgi, 1.4, 1.5
[email protected] Mon, 23 Jul 2007 20:03:47 +0000
Newsgroups
gmane.comp.web.curl.www.cvs
Message-ID
<[email protected] >
Update of /cvsroot/curl/curl-www
In directory labb:/tmp/cvs-serv27789
Modified Files:
ipwhere.pm latest.cgi metalink.cgi
Log Message:
Added country2tld to avoid duplicating code several times in gettld.
Index: metalink.cgi
===================================================================
RCS file: /cvsroot/curl/curl-www/metalink.cgi,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- metalink.cgi 11 Apr 2007 19:02:44 -0000 1.4
+++ metalink.cgi 23 Jul 2007 20:03:45 -0000 1.5
@@ -87,66 +87,9 @@
sub gettld {
my ($country)=@_;
- my $tld;
+ my $tld = country2tld($country);
- if($country =~ /Australia/) {
- $tld="au";
- }
- elsif($country =~ /Austria/) {
- $tld="at";
- }
- elsif($country =~ /Belgium/i) {
- $tld="be";
- }
- elsif($country =~ /Canada/) {
- $tld="ca";
- }
- elsif($country =~ /Denmark/) {
- $tld="dk";
- }
- elsif($country =~ /Estonia/) {
- $tld="ee";
- }
- elsif($country =~ /France/) {
- $tld="fr";
- }
- elsif($country =~ /Netherlands/) {
- $tld="nl";
- }
- elsif($country =~ /Germany/) {
- $tld="de";
- }
- elsif($country =~ /Greece/) {
- $tld="gr";
- }
- elsif($country =~ /Hong Kong/) {
- $tld="hk";
- }
- elsif($country =~ /Ireland/) {
- $tld="ie";
- }
- elsif($country =~ /Japan/) {
- $tld="jp";
- }
- elsif($country =~ /Poland/) {
- $tld="pl";
- }
- elsif($country =~ /Russia/) {
- $tld="ru";
- }
- elsif($country =~ /Sweden/) {
- $tld="se";
- }
- elsif($country =~ /Thailand/) {
- $tld="th";
- }
- elsif($country =~ /Taiwan/) {
- $tld="tw";
- }
- elsif($country =~ /US/) {
- $tld="us";
- }
- elsif($country =~ /United Kingdom/i) {
+ if($country =~ /United Kingdom/i) {
# NOTE: this is GB not UK, as the Metalink spec says
$tld="gb";
}
@@ -222,10 +165,10 @@
for(sort {$where{$a} cmp $where{$b}} @dl) {
my $url=$_;
- if(gettld($where{$url}) eq lc($mytld)) {
+ if(country2tld($where{$url}) eq lc($mytld)) {
$pref = 90;
}
- elsif(tld2continent( gettld($where{$url})) eq $mycontinent) {
+ elsif(tld2continent( country2tld($where{$url})) eq $mycontinent) {
$pref = 70;
} else {
$pref = 30;
Index: latest.cgi
===================================================================
RCS file: /cvsroot/curl/curl-www/latest.cgi,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- latest.cgi 11 Apr 2007 07:51:18 -0000 1.41
+++ latest.cgi 23 Jul 2007 20:03:45 -0000 1.42
@@ -121,81 +121,13 @@
close(DATA);
sub randomorder {
- my @dl = @_;
return sort { return int(rand(4)-2); } @_;
}
-sub gettld {
- my ($country)=@_;
- my $tld;
-
- if($country =~ /Australia/) {
- $tld="au";
- }
- elsif($country =~ /Austria/) {
- $tld="at";
- }
- elsif($country =~ /Belgium/i) {
- $tld="be";
- }
- elsif($country =~ /Canada/) {
- $tld="ca";
- }
- elsif($country =~ /Denmark/) {
- $tld="dk";
- }
- elsif($country =~ /Estonia/) {
- $tld="ee";
- }
- elsif($country =~ /France/) {
- $tld="fr";
- }
- elsif($country =~ /Netherlands/) {
- $tld="nl";
- }
- elsif($country =~ /Germany/) {
- $tld="de";
- }
- elsif($country =~ /Greece/) {
- $tld="gr";
- }
- elsif($country =~ /Hong Kong/) {
- $tld="hk";
- }
- elsif($country =~ /Ireland/) {
- $tld="ie";
- }
- elsif($country =~ /Japan/) {
- $tld="jp";
- }
- elsif($country =~ /Poland/) {
- $tld="pl";
- }
- elsif($country =~ /Russia/) {
- $tld="ru";
- }
- elsif($country =~ /Sweden/) {
- $tld="se";
- }
- elsif($country =~ /Thailand/) {
- $tld="th";
- }
- elsif($country =~ /Taiwan/) {
- $tld="tw";
- }
- elsif($country =~ /US/) {
- $tld="us";
- }
- elsif($country =~ /United Kingdom/i) {
- $tld="uk";
- }
- return $tld;
-}
-
sub flag {
my ($country)=@_;
- my $tld = gettld($country);
+ my $tld = country2tld($country);
if($tld) {
return "<img src=\"/pix/flags/$tld.png\" alt=\"$tld\">";
@@ -282,7 +214,7 @@
for(@dl) {
my $url=$_;
- my $flag = gettld($where{$url});
+ my $flag = country2tld($where{$url});
my $urlcontinent = tld2continent( $flag );
if($flag eq lc($mytld)) {
@@ -335,12 +267,12 @@
;
}
elsif($inmycountry) {
- if(gettld($where{$url}) ne lc($mytld)) {
+ if(country2tld($where{$url}) ne lc($mytld)) {
next;
}
}
elsif($inmycontinent) {
- if(tld2continent( gettld($where{$url})) ne $mycontinent) {
+ if(tld2continent( country2tld($where{$url})) ne $mycontinent) {
next;
}
}
Index: ipwhere.pm
===================================================================
RCS file: /cvsroot/curl/curl-www/ipwhere.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ipwhere.pm 14 Nov 2005 12:32:28 -0000 1.2
+++ ipwhere.pm 23 Jul 2007 20:03:45 -0000 1.3
@@ -521,4 +521,20 @@
return $tld2cntr{lc($tld)};
}
+# convert an exact country string into a two-letter TLD
+sub country2tld {
+ my ($cntr)=@_;
+
+ for (keys(%tld2cntr)) {
+ if ($cntr =~ /$tld2cntr{$_}/) {
+ return $_;
+ }
+ }
+ # Special case alternative country name
+ if ($cntr =~ /US/) {
+ return "us";
+ }
+ return "";
+}
+
1;