From patchwork Tue Sep 22 18:25:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3479 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4BwqW006cwz3x5w for ; Tue, 22 Sep 2020 18:25:48 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4BwqVv6s71z12W; Tue, 22 Sep 2020 18:25:43 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4BwqVv5XR4z30Wm; Tue, 22 Sep 2020 18:25:43 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4BwqVs70Ncz2xhT for ; Tue, 22 Sep 2020 18:25:41 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 4BwqVs4q1VzvR; Tue, 22 Sep 2020 18:25:41 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1600799141; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EQn/sK1o1h384qETYYTR8xEZ/Qib5YgobEJbYAMy57g=; b=Q2AvHrRAglq2iU0wq3jIbV8I+gEjkrmHyauyDXu8kEcSWG5/GdV0BXmFk4ea+Q5PRAs3Ok IFhMDVNizHNRY6Ag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1600799141; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EQn/sK1o1h384qETYYTR8xEZ/Qib5YgobEJbYAMy57g=; b=F8eXwybifauLhNatHSKMJMYedFhU4FKcPoIq+U4idZNT0U7TipD05zqY5ns40kAUt1d5gh LXjjyXSmTPamo3RUOwYleyGug4o0DiDwo1YQIenv79taGmi2NVU4G5Z2um+GrolMhtxm6L nEKFu7UIesu4RU6rBOh8eSKDqd3XqejpkyZ14ixObKZjMkjtVRqZrXyLWl83zxK4sZSmDM Z9MFKh+KVwZZBVDwSES1YL3Lst7q6SEYiTsrj3elFrE47IS6SaAkID2ESFuCixd5VBxMLX aPbHmpS9CbU03mIupkkiFB7spQZTmdezpx9VOaCZyjPM3kgZPYEs5Hu3IWCgjw== From: Stefan Schantl 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 Message-Id: <20200922182509.18643-2-stefan.schantl@ipfire.org> In-Reply-To: <20200922182509.18643-1-stefan.schantl@ipfire.org> References: <20200922182509.18643-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Stefan Schantl --- 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;