From: Otto Date: Wed, 8 Dec 2021 12:03:39 +0000 (+0100) Subject: API tweaks in response to reviews X-Git-Tag: auth-4.7.0-alpha1~111^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1747b117e45300cd412e848f21c53b25d2f8289;p=thirdparty%2Fpdns.git API tweaks in response to reviews --- diff --git a/pdns/lua-recursor4-ffi.hh b/pdns/lua-recursor4-ffi.hh index 5b78b41627..95c93c0fc7 100644 --- a/pdns/lua-recursor4-ffi.hh +++ b/pdns/lua-recursor4-ffi.hh @@ -59,6 +59,7 @@ extern "C" typedef struct pdns_ffi_record { const char* name; + size_t name_len; const char* content; size_t content_len; uint32_t ttl; @@ -114,8 +115,10 @@ extern "C" typedef struct pdns_postresolve_ffi_handle pdns_postresolve_ffi_handle_t; const char* pdns_postresolve_ffi_handle_get_qname(pdns_postresolve_ffi_handle_t* ref) __attribute__((visibility("default"))); + void pdns_postresolve_ffi_handle_get_qname_raw(pdns_postresolve_ffi_handle_t* ref, const char** qname, size_t* qnameSize) __attribute__((visibility("default"))); uint16_t pdns_postresolve_ffi_handle_get_qtype(const pdns_postresolve_ffi_handle_t* ref) __attribute__((visibility("default"))); uint16_t pdns_postresolve_ffi_handle_get_rcode(const pdns_postresolve_ffi_handle_t* ref) __attribute__((visibility("default"))); + void pdns_postresolve_ffi_handle_set_rcode(const pdns_postresolve_ffi_handle_t* ref, uint16_t rcode) __attribute__((visibility("default"))); pdns_policy_kind_t pdns_postresolve_ffi_handle_get_appliedpolicy_kind(const pdns_postresolve_ffi_handle_t* ref) __attribute__((visibility("default"))); void pdns_postresolve_ffi_handle_set_appliedpolicy_kind(pdns_postresolve_ffi_handle_t* ref, pdns_policy_kind_t kind) __attribute__((visibility("default"))); bool pdns_postresolve_ffi_handle_get_record(pdns_postresolve_ffi_handle_t* ref, unsigned int i, pdns_ffi_record_t* record, bool raw) __attribute__((visibility("default"))); @@ -125,3 +128,5 @@ extern "C" const char* pdns_postresolve_ffi_handle_get_authip(pdns_postresolve_ffi_handle_t* ref) __attribute__((visibility("default"))); void pdns_postresolve_ffi_handle_get_authip_raw(pdns_postresolve_ffi_handle_t* ref, const void** addr, size_t* addrSize) __attribute__((visibility("default"))); } + +#undef PDNS_VISIBILITY diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 95b7a45f34..0d1a745df8 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -1070,6 +1070,13 @@ const char* pdns_postresolve_ffi_handle_get_qname(pdns_postresolve_ffi_handle_t* return str->c_str(); } +void pdns_postresolve_ffi_handle_get_qname_raw(pdns_postresolve_ffi_handle_t* ref, const char** qname, size_t* qnameSize) +{ + const auto& storage = ref->handle.d_dq.qname.getStorage(); + *qname = storage.data(); + *qnameSize = storage.size(); +} + uint16_t pdns_postresolve_ffi_handle_get_qtype(const pdns_postresolve_ffi_handle_t* ref) { return ref->handle.d_dq.qtype; @@ -1080,6 +1087,11 @@ uint16_t pdns_postresolve_ffi_handle_get_rcode(const pdns_postresolve_ffi_handle return ref->handle.d_dq.rcode; } +void pdns_postresolve_ffi_handle_set_rcode(const pdns_postresolve_ffi_handle_t* ref, uint16_t rcode) +{ + ref->handle.d_dq.rcode = rcode; +} + pdns_policy_kind_t pdns_postresolve_ffi_handle_get_appliedpolicy_kind(const pdns_postresolve_ffi_handle_t* ref) { return static_cast(ref->handle.d_dq.appliedPolicy->d_kind); @@ -1097,7 +1109,15 @@ bool pdns_postresolve_ffi_handle_get_record(pdns_postresolve_ffi_handle_t* ref, } try { DNSRecord& r = ref->handle.d_dq.currentRecords->at(i); - record->name = ref->insert(r.d_name.toStringNoDot())->c_str(); + if (raw) { + const auto& storage = r.d_name.getStorage(); + record->name = storage.data(); + record->name_len = storage.size(); + } else { + std::string name = r.d_name.toStringNoDot(); + record->name_len = name.size(); + record->name = ref->insert(std::move(name))->c_str(); + } if (raw) { auto content = ref->insert(r.d_content->serialize(r.d_name, true)); record->content = content->data(); diff --git a/regression-tests.recursor-dnssec/test_Lua.py b/regression-tests.recursor-dnssec/test_Lua.py index efbae0d958..13081f051b 100644 --- a/regression-tests.recursor-dnssec/test_Lua.py +++ b/regression-tests.recursor-dnssec/test_Lua.py @@ -795,16 +795,19 @@ ffi.cdef[[ typedef struct pdns_ffi_record { const char* name; + size_t name_len; const char* content; - const size_t content_len; + size_t content_len; uint32_t ttl; pdns_record_place_t place; uint16_t type; } pdns_ffi_record_t; const char* pdns_postresolve_ffi_handle_get_qname(pdns_postresolve_ffi_handle_t* ref); + const char* pdns_postresolve_ffi_handle_get_qname_raw(pdns_postresolve_ffi_handle_t* ref, const char** name, size_t* len); uint16_t pdns_postresolve_ffi_handle_get_qtype(const pdns_postresolve_ffi_handle_t* ref); uint16_t pdns_postresolve_ffi_handle_get_rcode(const pdns_postresolve_ffi_handle_t* ref); + void pdns_postresolve_ffi_handle_set_rcode(const pdns_postresolve_ffi_handle_t* ref, uint16_t rcode); void pdns_postresolve_ffi_handle_set_appliedpolicy_kind(pdns_postresolve_ffi_handle_t* ref, pdns_policy_kind_t kind); bool pdns_postresolve_ffi_handle_get_record(pdns_postresolve_ffi_handle_t* ref, unsigned int i, pdns_ffi_record_t *record, bool raw); bool pdns_postresolve_ffi_handle_set_record(pdns_postresolve_ffi_handle_t* ref, unsigned int i, const char* content, size_t contentLen, bool raw);