[1/3] perl: Add lookup_network_has_flag() function.
Commit Message
This function can be used to check if a given address or network has one
of the following network flags.
* LOC_NETWORK_FLAG_ANONYMOUS_PROXY
* LOC_NETWORK_FLAG_SATELLITE_PROVIDER
* LOC_NETWORK_FLAG_ANYCAST
It will return true if the given flag is set.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
src/perl/Location.xs | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
Comments
Hello,
Thank you for sending those.
How are we going to proceed from here? Would you like to build the stuff that is needed for the web UI and if it all works I will tag a release? I would prefer to leave this open for as long we might have to add some more patches.
Best,
-Michael
> On 30 Aug 2020, at 11:36, Stefan Schantl <stefan.schantl@ipfire.org> wrote:
>
> This function can be used to check if a given address or network has one
> of the following network flags.
>
> * LOC_NETWORK_FLAG_ANONYMOUS_PROXY
> * LOC_NETWORK_FLAG_SATELLITE_PROVIDER
> * LOC_NETWORK_FLAG_ANYCAST
>
> It will return true if the given flag is set.
>
> Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
> ---
> src/perl/Location.xs | 36 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 36 insertions(+)
>
> diff --git a/src/perl/Location.xs b/src/perl/Location.xs
> index 7afa3e7..1cb2e21 100644
> --- a/src/perl/Location.xs
> +++ b/src/perl/Location.xs
> @@ -181,6 +181,42 @@ lookup_country_code(db, address)
> OUTPUT:
> RETVAL
>
> +bool
> +lookup_network_has_flag(db, address, flag)
> + struct loc_database* db;
> + char* address;
> + char* flag;
> +
> + CODE:
> + RETVAL = false;
> +
> + enum loc_network_flags iv = 0;
> +
> + if (strcmp("LOC_NETWORK_FLAG_ANONYMOUS_PROXY", flag) == 0)
> + iv |= LOC_NETWORK_FLAG_ANONYMOUS_PROXY;
> + else if (strcmp("LOC_NETWORK_FLAG_SATELLITE_PROVIDER", flag) == 0)
> + iv |= LOC_NETWORK_FLAG_SATELLITE_PROVIDER;
> + else if (strcmp("LOC_NETWORK_FLAG_ANYCAST", flag) == 0)
> + iv |= LOC_NETWORK_FLAG_ANYCAST;
> + else
> + croak("Invalid flag");
> +
> + // Lookup network
> + struct loc_network *network;
> + int err = loc_database_lookup_from_string(db, address, &network);
> +
> + if (!err) {
> + // Check if the network has the given flag.
> + if (loc_network_has_flag(network, iv)) {
> + RETVAL = true;
> + }
> +
> + loc_network_unref(network);
> + }
> +
> + OUTPUT:
> + RETVAL
> +
> SV*
> lookup_asn(db, address)
> struct loc_database* db;
> --
> 2.20.1
>
@@ -181,6 +181,42 @@ lookup_country_code(db, address)
OUTPUT:
RETVAL
+bool
+lookup_network_has_flag(db, address, flag)
+ struct loc_database* db;
+ char* address;
+ char* flag;
+
+ CODE:
+ RETVAL = false;
+
+ enum loc_network_flags iv = 0;
+
+ if (strcmp("LOC_NETWORK_FLAG_ANONYMOUS_PROXY", flag) == 0)
+ iv |= LOC_NETWORK_FLAG_ANONYMOUS_PROXY;
+ else if (strcmp("LOC_NETWORK_FLAG_SATELLITE_PROVIDER", flag) == 0)
+ iv |= LOC_NETWORK_FLAG_SATELLITE_PROVIDER;
+ else if (strcmp("LOC_NETWORK_FLAG_ANYCAST", flag) == 0)
+ iv |= LOC_NETWORK_FLAG_ANYCAST;
+ else
+ croak("Invalid flag");
+
+ // Lookup network
+ struct loc_network *network;
+ int err = loc_database_lookup_from_string(db, address, &network);
+
+ if (!err) {
+ // Check if the network has the given flag.
+ if (loc_network_has_flag(network, iv)) {
+ RETVAL = true;
+ }
+
+ loc_network_unref(network);
+ }
+
+ OUTPUT:
+ RETVAL
+
SV*
lookup_asn(db, address)
struct loc_database* db;