[asterisk-commits] res resolver unbound: Allow compilation with libunbound ver... (asterisk[14.0])
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Aug 11 16:11:31 CDT 2016
Joshua Colp has submitted this change and it was merged.
Change subject: res_resolver_unbound: Allow compilation with libunbound version < 1.5
......................................................................
res_resolver_unbound: Allow compilation with libunbound version < 1.5
libunbound at version 1.4.20 (which CentOS still uses) declared all
of their string function parameters as as 'char *'. 1.4.21 changed
them all to 'const char *'. Thankfully 1.4.21 also introduced the
UNBOUND_VERSION_MAJOR define so configure now checks for that and
sets HAVE_UNBOUND_CONST_PARAMS. res_resolver_unbound then checks
that and casts away the 'const' if it's not set.
Tested compile and testsuite on CentOS6 (1.4.20), Ubuntu14 (1.4.22) and
Fedora24 (1.5.4). There are a few failing tests to be addressed though.
ASTERISK-26283 #close
Change-Id: Ib708b19b706c5d0ba7b7d5473e6df339d9ae4148
---
M configure
M configure.ac
M include/asterisk/autoconfig.h.in
M res/res_resolver_unbound.c
4 files changed, 81 insertions(+), 23 deletions(-)
Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved; Verified
diff --git a/configure b/configure
index 86ae202..d7d1fbb 100755
--- a/configure
+++ b/configure
@@ -23683,7 +23683,7 @@
pbxlibdir="-L${UNBOUND_DIR}"
fi
fi
- pbxfuncname="ub_ctx_add_ta_autr"
+ pbxfuncname="ub_ctx_delete"
if test "x${pbxfuncname}" = "x" ; then # empty lib, assume only headers
AST_UNBOUND_FOUND=yes
else
@@ -23777,6 +23777,49 @@
+ if test "x${PBX_UNBOUND_CONST_PARAMS}" != "x1" -a "${USE_UNBOUND_CONST_PARAMS}" != "no"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for UNBOUND_VERSION_MAJOR declared in unbound.h" >&5
+$as_echo_n "checking for UNBOUND_VERSION_MAJOR declared in unbound.h... " >&6; }
+ saved_cppflags="${CPPFLAGS}"
+ if test "x${UNBOUND_CONST_PARAMS_DIR}" != "x"; then
+ UNBOUND_CONST_PARAMS_INCLUDE="-I${UNBOUND_CONST_PARAMS_DIR}/include"
+ fi
+ CPPFLAGS="${CPPFLAGS} ${UNBOUND_CONST_PARAMS_INCLUDE}"
+
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+ #include <unbound.h>
+int
+main ()
+{
+#if !defined(UNBOUND_VERSION_MAJOR)
+ (void) UNBOUND_VERSION_MAJOR;
+ #endif
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ PBX_UNBOUND_CONST_PARAMS=1
+
+$as_echo "#define HAVE_UNBOUND_CONST_PARAMS 1" >>confdefs.h
+
+
+
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+ CPPFLAGS="${saved_cppflags}"
+ fi
+
+
if test "x${PBX_UNIXODBC}" != "x1" -a "${USE_UNIXODBC}" != "no"; then
pbxlibdir=""
diff --git a/configure.ac b/configure.ac
index ed6f8a8..8ea1cb0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2101,7 +2101,8 @@
# script bug which does not find the ldns library. The bug is fixed in
# v1.4.22 but that version is not easily detectable.
#
-AST_EXT_LIB_CHECK([UNBOUND], [unbound], [ub_ctx_add_ta_autr], [unbound.h], [])
+AST_EXT_LIB_CHECK([UNBOUND], [unbound], [ub_ctx_delete], [unbound.h], [])
+AST_C_DECLARE_CHECK([UNBOUND_CONST_PARAMS], [UNBOUND_VERSION_MAJOR], [unbound.h])
AST_EXT_LIB_CHECK([UNIXODBC], [odbc], [SQLConnect], [sql.h], [])
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index b48257e..bdd93bb 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -1108,6 +1108,9 @@
/* Define to 1 if you have the unbound library. */
#undef HAVE_UNBOUND
+/* Define if your system has UNBOUND_VERSION_MAJOR declared. */
+#undef HAVE_UNBOUND_CONST_PARAMS
+
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
diff --git a/res/res_resolver_unbound.c b/res/res_resolver_unbound.c
index 3eeb651..40f3cfe 100644
--- a/res/res_resolver_unbound.c
+++ b/res/res_resolver_unbound.c
@@ -79,6 +79,17 @@
</configInfo>
***/
+/*!
+ * Unbound versions <= 1.4.20 declare string function parameters as 'char *'
+ * but versions >= 1.4.21 declare them as 'const char *'. Since CentOS6 is still
+ * at 1.4.20, we need to cast away the 'const' if we detect the earlier version.
+ */
+#ifdef HAVE_UNBOUND_CONST_PARAMS
+#define UNBOUND_CHAR const char
+#else
+#define UNBOUND_CHAR char
+#endif
+
/*! \brief Structure for an unbound resolver */
struct unbound_resolver {
/*! \brief Resolver context itself */
@@ -292,7 +303,7 @@
data->resolver = ao2_bump(cfg->global->state->resolver);
ast_dns_resolver_set_data(query, data);
- res = ub_resolve_async(data->resolver->context, ast_dns_query_get_name(query),
+ res = ub_resolve_async(data->resolver->context, (UNBOUND_CHAR *)ast_dns_query_get_name(query),
ast_dns_query_get_rr_type(query), ast_dns_query_get_rr_class(query),
ao2_bump(query), unbound_resolver_callback, &data->id);
@@ -404,7 +415,7 @@
if (!strcmp(cfg->global->hosts, "system")) {
res = ub_ctx_hosts(cfg->global->state->resolver->context, NULL);
} else if (!ast_strlen_zero(cfg->global->hosts)) {
- res = ub_ctx_hosts(cfg->global->state->resolver->context, cfg->global->hosts);
+ res = ub_ctx_hosts(cfg->global->state->resolver->context, (UNBOUND_CHAR *)cfg->global->hosts);
}
if (res) {
@@ -419,7 +430,7 @@
it_nameservers = ao2_iterator_init(cfg->global->nameservers, 0);
while ((nameserver = ao2_iterator_next(&it_nameservers))) {
- res = ub_ctx_set_fwd(cfg->global->state->resolver->context, nameserver);
+ res = ub_ctx_set_fwd(cfg->global->state->resolver->context, (UNBOUND_CHAR *)nameserver);
if (res) {
ast_log(LOG_ERROR, "Failed to add nameserver '%s' to unbound resolver: %s\n",
@@ -434,7 +445,7 @@
if (!strcmp(cfg->global->resolv, "system")) {
res = ub_ctx_resolvconf(cfg->global->state->resolver->context, NULL);
} else if (!ast_strlen_zero(cfg->global->resolv)) {
- res = ub_ctx_resolvconf(cfg->global->state->resolver->context, cfg->global->resolv);
+ res = ub_ctx_resolvconf(cfg->global->state->resolver->context, (UNBOUND_CHAR *)cfg->global->resolv);
}
if (res) {
@@ -444,7 +455,7 @@
}
if (!ast_strlen_zero(cfg->global->ta_file)) {
- res = ub_ctx_add_ta_file(cfg->global->state->resolver->context, cfg->global->ta_file);
+ res = ub_ctx_add_ta_file(cfg->global->state->resolver->context, (UNBOUND_CHAR *)cfg->global->ta_file);
if (res) {
ast_log(LOG_ERROR, "Failed to set trusted anchor file to '%s' in unbound resolver: %s\n",
@@ -740,13 +751,13 @@
static const size_t V4_SIZE = sizeof(struct in_addr);
static const size_t V6_SIZE = sizeof(struct in6_addr);
- static const char *DOMAIN1 = "goose.feathers";
- static const char *DOMAIN2 = "duck.feathers";
+ static UNBOUND_CHAR *DOMAIN1 = "goose.feathers";
+ static UNBOUND_CHAR *DOMAIN2 = "duck.feathers";
- static const char *ADDR1 = "127.0.0.2";
- static const char *ADDR2 = "127.0.0.3";
- static const char *ADDR3 = "::1";
- static const char *ADDR4 = "127.0.0.4";
+ static UNBOUND_CHAR *ADDR1 = "127.0.0.2";
+ static UNBOUND_CHAR *ADDR2 = "127.0.0.3";
+ static UNBOUND_CHAR *ADDR3 = "::1";
+ static UNBOUND_CHAR *ADDR4 = "127.0.0.4";
char addr1_buf[V4_SIZE];
char addr2_buf[V4_SIZE];
@@ -786,7 +797,7 @@
ub_ctx_zone_add(resolver->context, DOMAIN2, "static");
for (i = 0; i < ARRAY_LEN(records); ++i) {
- ub_ctx_data_add(resolver->context, records[i].as_string);
+ ub_ctx_data_add(resolver->context, (UNBOUND_CHAR *)records[i].as_string);
}
for (i = 0; i < ARRAY_LEN(runs); ++i) {
@@ -808,7 +819,7 @@
cleanup:
for (i = 0; i < ARRAY_LEN(records); ++i) {
- ub_ctx_data_remove(resolver->context, records[i].as_string);
+ ub_ctx_data_remove(resolver->context, (UNBOUND_CHAR *)records[i].as_string);
}
ub_ctx_zone_remove(resolver->context, DOMAIN1);
ub_ctx_zone_remove(resolver->context, DOMAIN2);
@@ -1012,10 +1023,10 @@
static const size_t V4_SIZE = sizeof(struct in_addr);
- static const char *DOMAIN1 = "goose.feathers";
- static const char *DOMAIN2 = "duck.feathers";
+ static UNBOUND_CHAR *DOMAIN1 = "goose.feathers";
+ static UNBOUND_CHAR *DOMAIN2 = "duck.feathers";
- static const char *ADDR1 = "127.0.0.2";
+ static UNBOUND_CHAR *ADDR1 = "127.0.0.2";
char addr1_buf[V4_SIZE];
@@ -1046,7 +1057,7 @@
ub_ctx_zone_add(resolver->context, DOMAIN2, "static");
for (i = 0; i < ARRAY_LEN(records); ++i) {
- ub_ctx_data_add(resolver->context, records[i].as_string);
+ ub_ctx_data_add(resolver->context, (UNBOUND_CHAR *)records[i].as_string);
}
for (i = 0; i < ARRAY_LEN(runs); ++i) {
@@ -1196,7 +1207,7 @@
const struct ast_dns_record *record;
- static const char * DOMAIN1 = "goose.feathers";
+ static char * DOMAIN1 = "goose.feathers";
int i;
enum ast_test_result_state res = AST_TEST_PASS;
@@ -1234,7 +1245,7 @@
ub_ctx_zone_add(resolver->context, DOMAIN1, "static");
for (i = 0; i < ARRAY_LEN(records); ++i) {
- ub_ctx_data_add(resolver->context, records[i].zone_entry);
+ ub_ctx_data_add(resolver->context, (UNBOUND_CHAR *)records[i].zone_entry);
}
if (ast_dns_resolve(DOMAIN1, ns_t_naptr, ns_c_in, &result)) {
@@ -1311,8 +1322,8 @@
RAII_VAR(struct unbound_config *, cfg, NULL, ao2_cleanup);
RAII_VAR(struct ast_dns_result *, result, NULL, ast_dns_result_free);
const struct ast_dns_record *record;
- static const char *DOMAIN1 = "taco.bananas";
- static const char *DOMAIN1_SRV = "taco.bananas 12345 IN SRV 10 20 5060 sip.taco.bananas";
+ static UNBOUND_CHAR *DOMAIN1 = "taco.bananas";
+ static UNBOUND_CHAR *DOMAIN1_SRV = "taco.bananas 12345 IN SRV 10 20 5060 sip.taco.bananas";
enum ast_test_result_state res = AST_TEST_PASS;
switch (cmd) {
--
To view, visit https://gerrit.asterisk.org/3454
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib708b19b706c5d0ba7b7d5473e6df339d9ae4148
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14.0
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
More information about the asterisk-commits
mailing list