]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
libloc: Import latest upstream perl functions. next-libloc-next
authorStefan Schantl <stefan.schantl@ipfire.org>
Sun, 20 Sep 2020 07:27:18 +0000 (09:27 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 20 Sep 2020 07:27:18 +0000 (09:27 +0200)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
lfs/libloc
src/patches/libloc-0.9.3-add-upstream-perl-functions.patch [new file with mode: 0644]

index 178f9f9ccd95e1280ce96b8e526a84739768bb26..b9367d4c1d46c4883d9cb4d23602e41345602078 100644 (file)
@@ -87,6 +87,9 @@ ifeq "$(BUILD_ARCH)" "i586"
        cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/libloc-0.9.3-perl-i586-regular-stack-protector.patch
 endif
 
+       # Add patch for adding latest upstream perl module functions.
+       cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/libloc-0.9.3-add-upstream-perl-functions.patch
+
        cd $(DIR_APP) && ./autogen.sh
        cd $(DIR_APP) && ./configure \
                --prefix=/usr \
diff --git a/src/patches/libloc-0.9.3-add-upstream-perl-functions.patch b/src/patches/libloc-0.9.3-add-upstream-perl-functions.patch
new file mode 100644 (file)
index 0000000..11b5599
--- /dev/null
@@ -0,0 +1,228 @@
+commit c1590ddd718fb3659ea7a7ac07549cb5b08dba93
+Author: Stefan Schantl <stefan.schantl@ipfire.org>
+Date:   Thu Aug 20 19:28:54 2020 +0200
+
+    perl: Add database_countries() function.
+    
+    This function is used to the stored countries of a database, which
+    easily can be assigned to an array.
+    
+    Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
+    Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
+
+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 <stdio.h>
+ #include <string.h>
+-
+ #include <loc/libloc.h>
+ #include <loc/database.h>
+ #include <loc/network.h>
+-
++#include <loc/country.h>
+ 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
+ #
+commit 696b94482420c65990871a8a9f473949c2b92fb6
+Author: Stefan Schantl <stefan.schantl@ipfire.org>
+Date:   Sat Aug 22 16:01:12 2020 +0200
+
+    perl: Add get_as_name()
+    
+    This function can be use to give the numer of an Autonomous System and
+    get back the stored name from the used location database.
+    
+    Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
+
+diff --git a/src/perl/Location.xs b/src/perl/Location.xs
+index 3c347db..7afa3e7 100644
+--- a/src/perl/Location.xs
++++ b/src/perl/Location.xs
+@@ -229,6 +229,29 @@ get_continent_code(db, ccode)
+       OUTPUT:
+               RETVAL
++SV*
++get_as_name(db, as_number)
++      struct loc_database* db;
++      unsigned int as_number;
++
++      CODE:
++              RETVAL = &PL_sv_undef;
++
++              // Lookup AS.
++              struct loc_as *as;
++              int err = loc_database_get_as(db, &as, as_number);
++              if(!err) {
++                      // Get the name of the given AS number.
++                      const char* as_name = loc_as_get_name(as);
++
++                      RETVAL = newSVpv(as_name, strlen(as_name));
++
++                      loc_as_unref(as);
++              }
++
++      OUTPUT:
++              RETVAL
++
+ void
+ DESTROY(db)
+       struct loc_database* db;
+commit 9e0dac40f44bf3e9a99636ef987e80c731640093
+Author: Stefan Schantl <stefan.schantl@ipfire.org>
+Date:   Sun Aug 30 12:29:23 2020 +0200
+
+    perl: Add lookup_network_has_flag() function.
+    
+    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>
+
+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;
+commit 4a45868cb79f83dd87c5dc00acb053f2be12b0e2
+Author: Stefan Schantl <stefan.schantl@ipfire.org>
+Date:   Thu Sep 10 17:41:42 2020 +0200
+
+    perl: Add get_country_name() function.
+    
+    This function can be used to get the stored name for a given country
+    code.
+    
+    Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
+
+diff --git a/src/perl/Location.xs b/src/perl/Location.xs
+index 1cb2e21..dcf3f0d 100644
+--- a/src/perl/Location.xs
++++ b/src/perl/Location.xs
+@@ -243,6 +243,28 @@ lookup_asn(db, address)
+ #
+ # Get functions
+ #
++SV*
++get_country_name(db, ccode)
++      struct loc_database* db;
++      char* ccode;
++
++      CODE:
++              RETVAL = &PL_sv_undef;
++
++              // Lookup country code
++              struct loc_country *country;
++              int err = loc_database_get_country(db, &country, ccode);
++              if(!err) {
++                      // Extract the name for the given country code.
++                      const char* country_name = loc_country_get_name(country);
++                      RETVAL = newSVpv(country_name, strlen(country_name));
++
++                      loc_country_unref(country);
++              }
++
++      OUTPUT:
++              RETVAL
++
+ SV*
+ get_continent_code(db, ccode)
+       struct loc_database* db;