From patchwork Wed Oct 2 17:07:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 2460 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 46k2dr2wHgz3yqH for ; Wed, 2 Oct 2019 17:08:16 +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 46k2dq6YGnz3Ck; Wed, 2 Oct 2019 17:08:15 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 46k2dq38Tyz2yWr; Wed, 2 Oct 2019 17:08:15 +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 46k2dn3jBGz2yWr; Wed, 2 Oct 2019 17:08:13 +0000 (UTC) Received: from tuxedo.stevee (213162068236.public.t-mobile.at [213.162.68.236]) (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 46k2dl5wfcz2KQ; Wed, 2 Oct 2019 17:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909rsa; t=1570036093; 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=FS/z3SdoLaYaOEBjRlL9KJaLCGskVgtFijuDi7SP6UA=; b=FLRGLlte4qA/4m+9Yjdw/e4AnqMF+cB7xFYMP3lNVl0KNfHP30i0UEApJkH1K+B9Fp/bs9 ebCCsK0k1NiJKyXXUznEDTtsisbNcA1FI80CQyTZYvnwu/DVK2VXPnostMPj8mEO/zG9Id V6dVhaLWWNdx+Vi268Rj9fhsRxkqCjn/bdn4sKM3VqFkcr0jdZiWGOjD+QPcYdS253vT/b utGoRs+irGsQcB1Kgq6lpYsW2BBmjyma6XFHr23gEglb6R2GuqkI2Tf+A5lO3NLGAqlX7E 4n0kQArTTa8G6chq++oKfaIVX9ovJTW593MJ+Gf+fi0mA8ENy6jqbOfWGdaZbA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909ed25519; t=1570036093; 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=FS/z3SdoLaYaOEBjRlL9KJaLCGskVgtFijuDi7SP6UA=; b=SV6GrsnsONr56OJ61d+PdvAenRVnmALVrnypqcVdSpCuDFv/8s+JV5KQNH6TYawSVea/KE haTX+1Dja+NohGCg== From: Stefan Schantl To: development@lists.ipfire.org, location@lists.ipfire.org Subject: [PATCH 1/2] perl: Fix lookup if given address is invalid or not in DB. Date: Wed, 2 Oct 2019 19:07:52 +0200 Message-Id: <20191002170753.6738-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.auth=stevee 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: , Errors-To: location-bounces@lists.ipfire.org Sender: "Location" In this case now undef will be returned. Signed-off-by: Stefan Schantl --- src/perl/Location.xs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/perl/Location.xs b/src/perl/Location.xs index ab27f0b..cdbc7e7 100644 --- a/src/perl/Location.xs +++ b/src/perl/Location.xs @@ -92,27 +92,23 @@ get_license(db) # # Lookup functions # -char* +SV* lookup_country_code(db, address) struct loc_database* db; char* address; CODE: + RETVAL = &PL_sv_undef; + // Lookup network struct loc_network *network; int err = loc_database_lookup_from_string(db, address, &network); - if (err) { - croak("Could not look up for %s\n", address); - } - - // Extract the country code - const char* country_code = loc_network_get_country_code(network); - loc_network_unref(network); + if (!err) { + // Extract the country code + const char* country_code = loc_network_get_country_code(network); + RETVAL = newSVpv(country_code, strlen(country_code)); - if (country_code) { - RETVAL = strdup(country_code); - } else { - RETVAL = NULL; + loc_network_unref(network); } OUTPUT: RETVAL From patchwork Wed Oct 2 17:07:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 2461 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 46k2dr50k2z400h for ; Wed, 2 Oct 2019 17:08:16 +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 46k2dr4S7Xz3Ck; Wed, 2 Oct 2019 17:08:16 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 46k2dr24s1z2yLN; Wed, 2 Oct 2019 17:08:16 +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 46k2dp0gKcz2yWr; Wed, 2 Oct 2019 17:08:14 +0000 (UTC) Received: from tuxedo.stevee (213162068236.public.t-mobile.at [213.162.68.236]) (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 46k2dn4Wz3z2Qh; Wed, 2 Oct 2019 17:08:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909rsa; t=1570036094; 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=avVGRfMXyFDMUfgmjv5ynX+06RZv845+9HLzu5yv9eo=; b=lXpFLpnjU9TLnm14JqqFt2YjmI/iFg+K5BFW/+CMjQJssSZiJP/Jo/FCIs8Gy76ODos3Y/ psLhssJqGNVfuNT+L5KbyUcRf6iH/trOv43JQqLzB63LWqzgGIG50YXJzh1GxWCZ7Sll1c +sGSRQ5/wktyD9Y8bvBGLd12oBmLUddNQSZ5pWZRO8wW3sqV6a3WV2Q9CGRgXAWvrOt183 LjbfLdBFZ5SukXao9pF1U8sh3yf2zZOQ22xYOf0v2Vi+YmksOLhoi3I89XEz7q2xHDz3KH Ky/seYfVOJgZ2kSuDDxoy0y3LEX2Gk1DMgzFveBixi9EGc5zLK9y9xhNkyIsmw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909ed25519; t=1570036094; 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=avVGRfMXyFDMUfgmjv5ynX+06RZv845+9HLzu5yv9eo=; b=FKGSe50TOHTI3wfZH+M9Njskh28OKOVnWrIRivKbxz0gReT9PL0bS8fpb0cm8wWQeXcYjU kWrJ02GrbWQEKRDg== From: Stefan Schantl To: development@lists.ipfire.org, location@lists.ipfire.org Subject: [PATCH 2/2] perl: Testsuite: Add tests for invalid address and address not in the database. Date: Wed, 2 Oct 2019 19:07:53 +0200 Message-Id: <20191002170753.6738-2-stefan.schantl@ipfire.org> In-Reply-To: <20191002170753.6738-1-stefan.schantl@ipfire.org> References: <20191002170753.6738-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.auth=stevee 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: , Errors-To: location-bounces@lists.ipfire.org Sender: "Location" Signed-off-by: Stefan Schantl --- src/perl/t/Location.t | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/perl/t/Location.t b/src/perl/t/Location.t index b583af4..55a18f3 100644 --- a/src/perl/t/Location.t +++ b/src/perl/t/Location.t @@ -36,3 +36,9 @@ ok($description eq "This is a geo location database", "Test 3 - Get Database Des my $country_code = &Location::lookup_country_code($db, $address); ok($country_code eq "DE", "Test 4 - Lookup country code for $address"); + +$country_code = &Location::lookup_country_code($db, "1.1.1.1"); +if(defined($country_code)) { fail("Test 5 - Lookup country code for address not in Database."); } + +$country_code = &Location::lookup_country_code($db, "a.b.c.d"); +if(defined($country_code)) { fail("Test 6 - Lookup country code for invalid address.") }