public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Stefan Schantl <stefan.schantl@ipfire.org>
To: development@lists.ipfire.org
Subject: [PATCH 02/11] location-functions.pl: Refactor get_full_country_name() function to use the Location module.
Date: Tue, 22 Sep 2020 20:25:00 +0200	[thread overview]
Message-ID: <20200922182509.18643-2-stefan.schantl@ipfire.org> (raw)
In-Reply-To: <20200922182509.18643-1-stefan.schantl@ipfire.org>

[-- Attachment #1: Type: text/plain, Size: 1869 bytes --]

Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
---
 config/cfgroot/location-functions.pl | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/config/cfgroot/location-functions.pl b/config/cfgroot/location-functions.pl
index a94d5909e..c8ccd94c2 100644
--- a/config/cfgroot/location-functions.pl
+++ b/config/cfgroot/location-functions.pl
@@ -24,18 +24,13 @@
 package Location::Functions;
 
 use Location;
-use Locale::Codes::Country;
 
 # Hash which contains country codes and their names which are special or not
 # part of ISO 3166-1.
 my %not_iso_3166_location = (
-	"a1" => "Anonymous Proxy",
-	"a2" => "Satellite Provider",
-	"a3" => "Worldwide Anycast Instance",
-	"an" => "Netherlands Antilles",
-	"ap" => "Asia/Pacific Region",
-	"eu" => "Europe",
-	"fx" => "France, Metropolitan"
+	"A1" => "Anonymous Proxy",
+	"A2" => "Satellite Provider",
+	"A3" => "Worldwide Anycast Instance",
 );
 
 # Array which contains special country codes.
@@ -152,17 +147,19 @@ sub get_full_country_name($) {
 	# Remove whitespaces.
 	chomp($input);
 
+	# Convert input into upper case format.
+	my $code = uc($input);
 
-	# Convert input into lower case format.
-	my $code = lc($input);
-
-	# Handle country codes which are not in the list.
+	# Handle country codes which are special or not part of the list.
 	if ($not_iso_3166_location{$code}) {
 		# Grab location name from hash.
 		$name = $not_iso_3166_location{$code};
 	} else {
-		# Use perl built-in module to get the country code.
-		$name = &Locale::Codes::Country::code2country($code);
+		# Init libloc database connection.
+		my $db_handle = &init();
+
+		# Get the country name by using the location module.
+		$name = &Location::get_country_name($db_handle, $code);
 	}
 
 	return $name;
-- 
2.20.1


  reply	other threads:[~2020-09-22 18:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22 18:24 [PATCH 01/11] location-functions.pl: Refactor get_locations() " Stefan Schantl
2020-09-22 18:25 ` Stefan Schantl [this message]
2020-09-22 18:25 ` [PATCH 03/11] location-functions.pl: Add address_has_flag() function Stefan Schantl
2020-09-22 18:25 ` [PATCH 04/11] country.cgi: Use own location-functions Stefan Schantl
2020-09-22 18:25 ` [PATCH 05/11] tor.cgi: Use own location functions Stefan Schantl
2020-09-22 18:25 ` [PATCH 06/11] guardian.cgi: Drop unused use of Locale::Codes::Country Stefan Schantl
2020-09-22 18:25 ` [PATCH 07/11] general-functions.pl: " Stefan Schantl
2020-09-22 18:25 ` [PATCH 08/11] ipinfo.cgi: Display network flags of the given addresses Stefan Schantl
2020-09-22 18:25 ` [PATCH 09/11] Locale-Country: Drop package Stefan Schantl
2020-09-22 18:25 ` [PATCH 10/11] ipinfo.cgi: Allow to display multiple flags Stefan Schantl
2020-09-22 18:25 ` [PATCH 11/11] libloc: Update to 0.9.4 Stefan Schantl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200922182509.18643-2-stefan.schantl@ipfire.org \
    --to=stefan.schantl@ipfire.org \
    --cc=development@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox