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: 2463 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 46k2dt3Q0Kz3yqH for ; Wed, 2 Oct 2019 17:08:18 +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 46k2dq2ttPz3Bx; 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 46k2dq0Hk0z2yt6; 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: 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" 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