From patchwork Tue Sep 22 18:24:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3480 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 4BwqW00R0Jz3x5y 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) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4BwqVv102Vz126; 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 4BwqVt4pdQz30Vt; Tue, 22 Sep 2020 18:25:42 +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) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4BwqVs1zbqz2xTN 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 4BwqVr38yCzJQ; Tue, 22 Sep 2020 18:25:40 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1600799140; 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; bh=e3Ai4xRuMZqoQhnOy6CxLMbPJa20qchzpBOtoQf2IYQ=; b=Eq5pMhqj7ugPpWXmpJCL8nNEJsY6EUv4CYeddp6zFKKdHe4gDyYpp+SOIB4if2UM2hUXJ+ Mi5JUDj0fQkYk4DQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1600799140; 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; bh=e3Ai4xRuMZqoQhnOy6CxLMbPJa20qchzpBOtoQf2IYQ=; b=C7mJmLLO6bU3tgXKKSkp1Fpbvk0YfwMFFVNWRvpMaVXERsKBJpKrCmc699/Lai3yz6EAvP lOmYhu9oullheYH8p2WY6CJ3su42stMzMI3NSx+2MxIru6vkRV/xBieCdm5mTG1KnQBv2C +KJixDvSkr4W5jU1mXFeKyofa6NIKzBT9kLbQrDwavLV9G7SmirmaZbADRKIJs/239EOCN EE+YZ4YrkutMQKRDtG9pYyghUG1ScK1y6ynOlUUFuRRiUfInt/VQtEJknQNxT01GzDPbyz bRBZYRr4w61adTpUyQ7kghdjvoBkC/LCJRJfHyXdfCBIdDkE3TdB4Aimvw6DdQ== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH 01/11] location-functions.pl: Refactor get_locations() function to use the Location module. Date: Tue, 22 Sep 2020 20:24:59 +0200 Message-Id: <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 | 30 +++++++++------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/config/cfgroot/location-functions.pl b/config/cfgroot/location-functions.pl index ab99e71d3..a94d5909e 100644 --- a/config/cfgroot/location-functions.pl +++ b/config/cfgroot/location-functions.pl @@ -38,6 +38,9 @@ my %not_iso_3166_location = ( "fx" => "France, Metropolitan" ); +# Array which contains special country codes. +my @special_locations = ( "A1", "A2", "A3" ); + # Directory where the libloc database and keyfile lives. our $location_dir = "/var/lib/location/"; @@ -167,29 +170,14 @@ sub get_full_country_name($) { # Function to get all available locations. sub get_locations() { - my @locations = (); - - # Get listed country codes from ISO 3166-1. - my @locations_lc = &Locale::Codes::Country::all_country_codes(); - - # The Codes::Country module provides the country codes only in lower case. - # So we have to loop over the array and convert them into upper case format. - foreach my $ccode (@locations_lc) { - # Convert the country code to uppercase. - my $ccode_uc = uc($ccode); + # Create libloc database handle. + my $db_handle = &init(); - # Add the converted ccode to the locations array. - push(@locations, $ccode_uc); - } - - # Add locations from not_iso_3166_locations. - foreach my $location (keys %not_iso_3166_location) { - # Convert the location into uppercase. - my $location_uc = uc($location); + # Get locations which are stored in the location database. + my @database_locations = &Location::database_countries($db_handle); - # Add the location to the locations array. - push(@locations, $location_uc); - } + # Merge special locations array and the database locations array. + my @locations = (@special_locations, @database_locations); # Sort locations array in alphabetical order. my @sorted_locations = sort(@locations);