From b42195a256ee2c5dd8d55c1e68215fdb5288caa4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Fri, 6 Sep 2019 12:10:12 +0200 Subject: [PATCH] lua bindings: compatibility with both libknot versions --- daemon/lua/kres-gen.lua | 8 -------- daemon/lua/kres-gen.sh | 4 ++-- daemon/lua/kres.lua | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 10 deletions(-) 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 -- 2.47.2