From: Vladimír Čunát Date: Fri, 6 Sep 2019 10:10:12 +0000 (+0200) Subject: lua bindings: compatibility with both libknot versions X-Git-Tag: v4.2.1~5^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b42195a2;p=thirdparty%2Fknot-resolver.git lua bindings: compatibility with both libknot versions --- diff --git a/daemon/lua/kres-gen.lua b/daemon/lua/kres-gen.lua index 07647cc84..ed48d753e 100644 --- a/daemon/lua/kres-gen.lua +++ b/daemon/lua/kres-gen.lua @@ -22,14 +22,6 @@ typedef struct { uint16_t compress_ptr[16]; } knot_rrinfo_t; typedef unsigned char knot_dname_t; -typedef struct { - uint16_t len; - uint8_t data[]; -} knot_rdata_t; -typedef struct { - uint16_t count; - knot_rdata_t *rdata; -} knot_rdataset_t; typedef struct { knot_dname_t *_owner; uint32_t _ttl; diff --git a/daemon/lua/kres-gen.sh b/daemon/lua/kres-gen.sh index c28d346f2..fd16e492c 100755 --- a/daemon/lua/kres-gen.sh +++ b/daemon/lua/kres-gen.sh @@ -75,8 +75,8 @@ ${CDEFS} ${LIBKRES} types <<-EOF knot_section_t knot_rrinfo_t knot_dname_t - knot_rdata_t - knot_rdataset_t + #knot_rdata_t + #knot_rdataset_t EOF genResType() { diff --git a/daemon/lua/kres.lua b/daemon/lua/kres.lua index 2fc21503f..5198c2fcd 100644 --- a/daemon/lua/kres.lua +++ b/daemon/lua/kres.lua @@ -57,6 +57,40 @@ int inet_pton(int af, const char *src, void *dst); int gettimeofday(struct timeval *tv, struct timezone *tz); ]] + +-- TMP: compatibility with both libknot 2.8 and 2.9 +local knot_rdataset_t_cdef +local sover_pos = string.find(libknot_SONAME, '%d') +if not sover_pos then + error('unexpected libknot soname: ' .. libknot_SONAME) +end +local sover = string.sub(libknot_SONAME, sover_pos , sover_pos) +if sover == '8' then + knot_rdataset_t_cdef = [[ + typedef struct { + uint16_t count; + knot_rdata_t *rdata; + } knot_rdataset_t; + ]] +elseif sover == '9' then + knot_rdataset_t_cdef = [[ + typedef struct { + uint16_t count; + uint32_t size; + knot_rdata_t *rdata; + } knot_rdataset_t; + ]] +else + error('unexpected libknot version: ' .. sover) +end +ffi.cdef([[ + typedef struct { + uint16_t len; + uint8_t data[]; + } knot_rdata_t; + ]] .. knot_rdataset_t_cdef) + + require('kres-gen') -- Error code representation