From patchwork Thu Aug 20 17:28:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3380 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) 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 web04.haj.ipfire.org (Postfix) with ESMTPS id 4BXWpv1nt4z3x1f for ; Thu, 20 Aug 2020 17:29:11 +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 4BXWpt69vJzt9; Thu, 20 Aug 2020 17:29:10 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4BXWpt45hcz2y0p; Thu, 20 Aug 2020 17:29:10 +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 4BXWps3nkMz2xfh; Thu, 20 Aug 2020 17:29:09 +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 4BXWpr5hdYzbv; Thu, 20 Aug 2020 17:29:08 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1597944549; 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=UF96ZdHTqJMElVq7b2P6kJOiVAFTQ1em2SzTMeWE4Ts=; b=kz3XZsl9vcPhGh8qAly9d/Yr4XSB3NCFfPH9aqKP4dPlOdYGZX88FBW/3ArV9/Ml1dooJI i12VM5E2c7RRAaBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1597944549; 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=UF96ZdHTqJMElVq7b2P6kJOiVAFTQ1em2SzTMeWE4Ts=; b=CyswMOOgdPM/lAQcvyGgc/HFReX/TVJhjhZ3xD7y8IcbR1GSQ+vQvTZcFN7isjsgYdC2On 7QZM8gs3aumXTgKSWiYbij4OrQa+d6r6dSE+q5ynHQHlWDuM/HjpRIBJlxEu6hzSkGa45z 7Ehl50fqKL+u1MhYd8gHUd4yLJ4ZSLOc3bzri5uW5Tc9Az0qco83k657w9ts9G4W9UVKPd dCqcGD6l2n7dsbebzB2bCOGX2gs2FuGD9GxBTahvVZ6ivXlTEypM2YfxnNReALhauPvkts Ze7NybQrgM22dYF1UZz++Q8Ie4FJpG5SI8zLJ5/LmbDE1MPlQBn+GM/da9JRGw== From: Stefan Schantl To: location@lists.ipfire.org Subject: [PATCH 1/3] perl: Add database_countries() function. Date: Thu, 20 Aug 2020 19:28:54 +0200 Message-Id: <20200820172856.6983-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: location@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: development@lists.ipfire.org Errors-To: location-bounces@lists.ipfire.org Sender: "Location" This function is used to the stored countries of a database, which easily can be assigned to an array. Signed-off-by: Stefan Schantl --- src/perl/Location.xs | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/perl/Location.xs b/src/perl/Location.xs index 5693744..3c347db 100644 --- a/src/perl/Location.xs +++ b/src/perl/Location.xs @@ -6,11 +6,10 @@ #include #include - #include #include #include - +#include MODULE = Location PACKAGE = Location @@ -119,6 +118,45 @@ get_license(db) OUTPUT: RETVAL +void +database_countries(db) + struct loc_database* db; + + PPCODE: + // Create Database enumerator + struct loc_database_enumerator* enumerator; + int err = loc_database_enumerator_new(&enumerator, db, LOC_DB_ENUMERATE_COUNTRIES); + + if (err) { + croak("Could not create a database enumerator\n"); + } + + // Init and enumerate first country. + struct loc_country* country; + err = loc_database_enumerator_next_country(enumerator, &country); + if (err) { + croak("Could not enumerate next country\n"); + } + + while (country) { + // Extract the country code. + const char* ccode = loc_country_get_code(country); + + // Push country code. + XPUSHs(sv_2mortal(newSVpv(ccode, 2))); + + // Unref country pointer. + loc_country_unref(country); + + // Enumerate next item. + err = loc_database_enumerator_next_country(enumerator, &country); + if (err) { + croak("Could not enumerate next country\n"); + } + } + + loc_database_enumerator_unref(enumerator); + # # Lookup functions # From patchwork Thu Aug 20 17:28:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3383 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 4BXWpx6S33z3x24 for ; Thu, 20 Aug 2020 17:29:13 +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 4BXWpw65rTzvQ; Thu, 20 Aug 2020 17:29:12 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4BXWpw5ZP0z2xfm; Thu, 20 Aug 2020 17:29:12 +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 4BXWpt3G8Tz2xcT; Thu, 20 Aug 2020 17:29:10 +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 4BXWps55qCzqJ; Thu, 20 Aug 2020 17:29:09 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1597944550; 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=kDa1QPAlweMcqUpn8K0+24ZCrf74bV6xnxeXEb1IG/g=; b=Jk5DQTr8dM7cUi7gT+H2ovYnysVY4NcZUFJChdYFKRAvgaf0gAuqwctuwLubZDjYTP1DwI b1R8ipLvhMUbisAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1597944550; 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=kDa1QPAlweMcqUpn8K0+24ZCrf74bV6xnxeXEb1IG/g=; b=CWPqlj9B8gWWVTpceGNNugJTrAJQmvPWYF7I2uuQbFLLtDmg9JAXaRVS7kNKp0KUdlgmPR ITIs2HN15fX+3T/HjrRxJV2ASzV+p5irjnARIo2VSCHvUziJi0kxvbPc+XfpVtuz4CXegv rhSdcRCFuyi8al1KeIPaM6x6ZS80rNS4JH9+N7RrBgqZQgPy0mVxuJ9VXDEwi3GxJV+EpG 9soGI3rPRoxziQC9KQ7Wy5XU43KtsGLnH96WbM8KdIKf652Fwslx+KULpDnsz4cPwCz99z xja6pXTDGtglVjYncoIIFcP1ajNyYl0DzZ+rBwhrNmvRU7wplx6AtmJIgz4qiQ== From: Stefan Schantl To: location@lists.ipfire.org Subject: [PATCH 2/3] Add an example country to the python create-database example script. Date: Thu, 20 Aug 2020 19:28:55 +0200 Message-Id: <20200820172856.6983-2-stefan.schantl@ipfire.org> In-Reply-To: <20200820172856.6983-1-stefan.schantl@ipfire.org> References: <20200820172856.6983-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: location@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: development@lists.ipfire.org Errors-To: location-bounces@lists.ipfire.org Sender: "Location" The generated database is used by the testsuite of the perl binding. Signed-off-by: Stefan Schantl --- examples/python/create-database.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/python/create-database.py b/examples/python/create-database.py index 0eaa945..b57ad94 100644 --- a/examples/python/create-database.py +++ b/examples/python/create-database.py @@ -20,6 +20,9 @@ with open(private_key_path, "r") as pkey: # Set a license w.license = "CC" + # Add a country + c = w.add_country("DE") + # Add an AS a = w.add_as(204867) a.name = "Lightning Wire Labs GmbH" From patchwork Thu Aug 20 17:28:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3384 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 4BXWpy2RQgz3x1f for ; Thu, 20 Aug 2020 17:29:14 +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 4BXWpx02lszvY; Thu, 20 Aug 2020 17:29:12 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4BXWpw6Nr2z30WH; Thu, 20 Aug 2020 17:29:12 +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 4BXWpv484lz2y0p; Thu, 20 Aug 2020 17:29:11 +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 4BXWpv16CXzv9; Thu, 20 Aug 2020 17:29:11 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1597944551; 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=h1K7Vvd/btAepuSV24Aret4GaDQp4xe9trdoTz8V9eQ=; b=42/g2r2G1rhdAzKx3TqKn46+oStBpmRY2313uzEdfdHhxIXoRe/xMV3xhevYK1zk/RFJAi TZXx5v/n+Vm33PCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1597944551; 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=h1K7Vvd/btAepuSV24Aret4GaDQp4xe9trdoTz8V9eQ=; b=u7IknizxqB8NKBeq3Eg5hunG4yT0k77ePkLU8BREylaPwf3IHyrY0BIDKV1yrmZrQoKRsR OtJjw7ppNYukVWVFm5Wl3lWd7AvXpMrlKmKkaRuhUvB8s1oaGNhkYTxsUHrpFcTV/qHykk u7ogA2Bw08fy8yxQqdfVoPMAmhWvwyuSxvgjJLZ0EAPtnE3giExnAoh2V/uy3rcy6GbmJ0 FKHlmF1gvYazB/cX7pNn5IUIyKOQOqLEuI/CPC48gGTt4hmhzM8wH8QeM1eJTs7RSf1vqW EXmAIijdPIyVqdBA7E23ZJfqX6asst8mgBQreLVMjTnOWg7pko0r1w6OiZquvA== From: Stefan Schantl To: location@lists.ipfire.org Subject: [PATCH 3/3] perl: Add test for the database_countries() function. Date: Thu, 20 Aug 2020 19:28:56 +0200 Message-Id: <20200820172856.6983-3-stefan.schantl@ipfire.org> In-Reply-To: <20200820172856.6983-1-stefan.schantl@ipfire.org> References: <20200820172856.6983-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: location@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: development@lists.ipfire.org Errors-To: location-bounces@lists.ipfire.org Sender: "Location" Signed-off-by: Stefan Schantl --- src/perl/t/Location.t | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/perl/t/Location.t b/src/perl/t/Location.t index 3ba2d8f..ec7f1e0 100644 --- a/src/perl/t/Location.t +++ b/src/perl/t/Location.t @@ -12,7 +12,7 @@ use warnings; my $testdb = $ENV{'database'}; my $keyfile = $ENV{'keyfile'}; -use Test::More tests => 7; +use Test::More tests => 8; BEGIN { use_ok('Location') }; ######################### @@ -56,3 +56,6 @@ if(defined($as_number)) { fail("Test 8 - Lookup Autonomous System Number for add $as_number = &Location::lookup_asn($db, "a.b.c.d"); if(defined($as_number)) { fail("Test 9 - Lookup Autonomous System Number for invalid address.") } + +my @locations = &Location::database_countries($db); +ok(@locations != 0, "Test 10 - Get database countries.");