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 #