Merge branch 'develop' of https://github.com/verisign/getdns into develop

Conflicts:
	src/sync.c
This commit is contained in:
Glen Wiley 2013-11-04 18:45:00 -05:00
commit 78cb5480d2
14 changed files with 64 additions and 153 deletions

View File

@ -50,16 +50,15 @@ External dependencies are linked outside the getdns API build tree (we rely on c
* [libevent](http://libevent.org) version 2.0.21 stable
* [libldns from NL](https://www.nlnetlabs.nl/projects/ldns/) version 1.6.16 (ldns may require openssl headers and libraries)
* [libunbound from NL](http://www.nlnetlabs.nl/projects/unbound/) svn revision 2985, configure must be run with the --with-libevent option (recommended to also use --with-libunbound-only). The unbound.2985.patch included with getdns must be applied to the source tree prior to building libunbound.
* [libunbound from NL](http://www.nlnetlabs.nl/projects/unbound/) svn revision 3012, configure must be run with the --with-libevent option (recommended to also use --with-libunbound-only).
* Doxygen is used to generate documentation, while this is not technically necessary for the build it makes things a lot more pleasant.
Assuming that the getdns sources are in a diretory named getdns in your home directory, to build libunbound (note that the svn checkout may take a while):
```
# mkdir unbound
# cd unbound
# svn checkout -r 2985 http://unbound.nlnetlabs.nl/svn
# svn checkout -r 3012 http://unbound.nlnetlabs.nl/svn
# cd svn/trunk
# patch -p0 < ~/getdns/unbound.2985.patch
# ./configure --with-libevent --with-libunbound-only
# make
# make install

View File

@ -159,7 +159,7 @@ static getdns_return_t set_os_defaults(getdns_context_t context) {
context->suffix = create_from_ldns_list(rdf_list, rdf_list_sz);
}
/** cleanup **/
ldns_resolver_free(lr);
ldns_resolver_deep_free(lr);
return GETDNS_RETURN_GOOD;
}

View File

@ -666,6 +666,10 @@ getdns_pretty_print_dict(struct getdns_dict *dict)
ldns_buffer *buf;
char *ret;
if (!dict) {
return NULL;
}
buf = ldns_buffer_new(100);
if (! buf)
return NULL;

View File

@ -89,10 +89,6 @@ retregular = getdns_context_create(
boolarg
);
getdns_context_destroy(
contextarg
);
retregular = getdns_cancel_callback(
contextarg,
txidarg
@ -150,18 +146,19 @@ retregular = getdns_dict_get_bindata(dictarg, charstararg, bindataptrarg);
retregular = getdns_dict_get_int(dictarg, charstararg, uint32ptrarg);
listarg = getdns_list_create();
getdns_list_destroy(listarg);
retregular = getdns_list_set_dict(listarg, sizetarg, dictarg);
retregular = getdns_list_set_list(listarg, sizetarg, listarg);
retregular = getdns_list_set_bindata(listarg, sizetarg, bindataarg);
retregular = getdns_list_set_int(listarg, sizetarg, uint32arg);
dictarg = getdns_dict_create();
getdns_dict_destroy(dictarg);
retregular = getdns_dict_set_dict(dictarg, charstararg, dictarg);
retregular = getdns_dict_set_list(dictarg, charstararg, listarg);
retregular = getdns_dict_set_bindata(dictarg, charstararg, bindataarg);
retregular = getdns_dict_set_int(dictarg, charstararg, uint32arg);
retcharstar = getdns_pretty_print_dict(
dictarg
);
retcharstar = getdns_convert_fqdn_to_dns_name(
charstararg
@ -185,10 +182,6 @@ retregular = getdns_validate_dnssec(
listarg
);
retcharstar = getdns_pretty_print_dict(
dictarg
);
retcharstar = getdns_display_ip_address(
bindataarg
);
@ -294,4 +287,8 @@ retregular = getdns_context_set_memory_reallocator(
deallocfunctionarg
);
getdns_list_destroy(listarg);
getdns_dict_destroy(dictarg);
getdns_context_destroy(contextarg);
return(0); } /* End of main() */

View File

@ -69,14 +69,20 @@ void this_callbackfn(struct getdns_context_t *this_context,
for ( size_t rec_count = 0; rec_count < num_addresses; ++rec_count )
{
struct getdns_bindata * this_address_data;
char* ipAddr = NULL;
this_ret = getdns_list_get_bindata(just_the_addresses_ptr, rec_count, &this_address_data); // Ignore any error
printf("The address is %s\n", getdns_display_ip_address(this_address_data));
ipAddr = getdns_display_ip_address(this_address_data);
printf("The address is %s\n", ipAddr);
free(ipAddr);
}
}
else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.", this_transaction_id);
else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.", this_callback_type);
/* clean up */
getdns_dict_destroy(this_response);
}
int
@ -121,6 +127,7 @@ main()
}
/* Clean up */
getdns_context_destroy(this_context);
event_base_free(this_event_base);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
} /* main */

View File

@ -70,6 +70,8 @@ main()
/* Make the call */
getdns_return_t dns_request_return = getdns_general_sync(this_context, this_name, this_request_type,
this_extensions, &this_response_length, &this_response);
/* free the extensions */
getdns_dict_destroy(this_extensions);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);

View File

@ -208,6 +208,10 @@ getdns_general_ub(struct ub_ctx* unbound,
getdns_return_t gr;
int r;
if (!name) {
return GETDNS_RETURN_GENERIC_ERROR;
}
gr = getdns_context_prepare_for_resolution(context);
if (gr != GETDNS_RETURN_GOOD) {
return GETDNS_RETURN_BAD_CONTEXT;

View File

@ -226,8 +226,11 @@ getdns_list_copy(struct getdns_list *srclist, struct getdns_list **dstlist)
&((*dstlist)->items[i].data.dict));
}
}
else
else {
retval = GETDNS_RETURN_GENERIC_ERROR;
getdns_list_destroy(*dstlist);
*dstlist = NULL;
}
if(retval != GETDNS_RETURN_GOOD)
break;
@ -282,6 +285,10 @@ getdns_list_destroy(struct getdns_list *list)
free(list->items[i].data.bindata->data);
free(list->items[i].data.bindata);
}
else if(list->items[i].dtype == t_dict)
{
getdns_dict_destroy(list->items[i].data.dict);
}
}
free(list->items);
}

View File

@ -152,6 +152,7 @@ void
getdns_free_sync_request_memory(
struct getdns_dict *response
)
{ UNUSED_PARAM(response); }
/* sync.c */
{
getdns_dict_destroy(response);
}
/* getdns_core_sync.c */

View File

@ -49,6 +49,7 @@ void
tstmsg_prog_end()
{
printf("TESTPROG %s END\n", testprog);
free(testprog);
} /* tstmsg_prog_end */
void
@ -69,7 +70,11 @@ tstmsg_case_end(void)
printf("TESTCASE %s:%s END\n", testprog, cases[ncases-1]);
ncases--;
free(cases[ncases]);
if (ncases) {
cases = (char **) realloc(cases, sizeof(char *) * ncases);
} else {
cases = NULL;
}
}
} /* tstmsg_case_end */

View File

@ -208,12 +208,14 @@ tst_getnames(void)
tstmsg_case_msg("getdns_dict_get_names(NULL, &list)");
getdns_dict_get_names(NULL, &list);
getdns_list_destroy(list);
tstmsg_case_msg("getdns_dict_get_names(dict, NULL)");
getdns_dict_get_names(dict, NULL);
tstmsg_case_msg("getdns_dict_get_names(dict, &list), empty dictionary");
getdns_dict_get_names(dict, &list);
getdns_list_destroy(list);
/* legit use case, add items out of order to exercise tree */
/* TODO: add elements of type dict, bindata, list to the dict */
@ -263,6 +265,7 @@ tst_getnames(void)
}
getdns_dict_destroy(dict);
getdns_list_destroy(list);
tstmsg_case_end();
} /* tst_getnames */
@ -452,6 +455,7 @@ tst_copy(void)
getdns_dict_copy(NULL, NULL);
dict1 = getdns_dict_create();
getdns_dict_copy(dict1, &dict2);
getdns_dict_destroy(dict2);
getdns_dict_copy(NULL, &dict1);
tstmsg_case_msg("dict1 populate");

View File

@ -33,13 +33,10 @@
#include <getdns/getdns.h>
static void print_response(getdns_dict* response) {
getdns_bindata* bindata = NULL;
getdns_dict_get_bindata(response, "pkt", &bindata);
if (bindata) {
char* data = (char*) bindata->data;
data[bindata->size] = 0;
memcpy(data, bindata->data, bindata->size);
fprintf(stdout, "The packet %s\n", data);
char *dict_str = getdns_pretty_print_dict(response);
if (dict_str) {
fprintf(stdout, "The packet %s\n", dict_str);
free(dict_str);
}
}

View File

@ -423,7 +423,7 @@ static char* get_canonical_name(const char* name) {
return NULL;
}
char* result = convert_rdf_to_str(rdf);
ldns_rdf_free(rdf);
ldns_rdf_deep_free(rdf);
return result;
}
@ -433,7 +433,7 @@ getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request) {
getdns_list* just_addrs = NULL;
getdns_list* replies_tree = getdns_list_create();
getdns_network_req *netreq = completed_request->first_req;
char* canonical_name = NULL;
int r = 0;
@ -443,7 +443,9 @@ getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request) {
}
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_STATUS, GETDNS_RESPSTATUS_GOOD);
r |= getdns_dict_util_set_string(result, GETDNS_STR_KEY_CANONICAL_NM, get_canonical_name(completed_request->name));
canonical_name = get_canonical_name(completed_request->name);
r |= getdns_dict_util_set_string(result, GETDNS_STR_KEY_CANONICAL_NM, canonical_name);
free(canonical_name);
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_ANSWER_TYPE, GETDNS_NAMETYPE_DNS);
while (netreq) {

View File

@ -1,118 +0,0 @@
Index: Makefile.in
===================================================================
--- Makefile.in (revision 2985)
+++ Makefile.in (working copy)
@@ -280,7 +280,7 @@
longtest: tests
if test -x "`which bash`"; then bash testcode/do-tests.sh; else sh testcode/do-tests.sh; fi
-lib: libunbound.la unbound.h
+lib: libunbound.la unbound.h unbound-event.h
libunbound.la: $(LIBUNBOUND_OBJ_LINK)
$(LINK_LIB) $(UBSYMS) -o $@ $(LIBUNBOUND_OBJ_LINK) -rpath $(libdir) -lssl $(LIBS)
@@ -348,6 +348,9 @@
unbound.h: $(srcdir)/libunbound/unbound.h
sed -e 's/@''UNBOUND_VERSION_MAJOR@/$(UNBOUND_VERSION_MAJOR)/' -e 's/@''UNBOUND_VERSION_MINOR@/$(UNBOUND_VERSION_MINOR)/' -e 's/@''UNBOUND_VERSION_MICRO@/$(UNBOUND_VERSION_MICRO)/' < $(srcdir)/libunbound/unbound.h > $@
+unbound-event.h: $(srcdir)/libunbound/unbound-event.h
+ sed -e 's/@''UNBOUND_VERSION_MAJOR@/$(UNBOUND_VERSION_MAJOR)/' -e 's/@''UNBOUND_VERSION_MINOR@/$(UNBOUND_VERSION_MINOR)/' -e 's/@''UNBOUND_VERSION_MICRO@/$(UNBOUND_VERSION_MICRO)/' < $(srcdir)/libunbound/unbound-event.h > $@
+
unbound-control-setup: $(srcdir)/smallapp/unbound-control-setup.sh
sed -e 's:^DESTDIR=.*$$:DESTDIR=$(UNBOUND_RUN_DIR):' < $(srcdir)/smallapp/unbound-control-setup.sh > $@
-chmod +x $@
@@ -496,6 +499,7 @@
$(INSTALL) -c -m 755 unbound-control-setup $(DESTDIR)$(sbindir)/unbound-control-setup
if test ! -e $(DESTDIR)$(configfile); then $(INSTALL) -d `dirname $(DESTDIR)$(configfile)`; $(INSTALL) -c -m 644 doc/example.conf $(DESTDIR)$(configfile); fi
$(LIBTOOL) --mode=install cp unbound.h $(DESTDIR)$(includedir)/unbound.h
+ $(LIBTOOL) --mode=install cp unbound-event.h $(DESTDIR)$(includedir)/unbound-event.h
$(LIBTOOL) --mode=install cp libunbound.la $(DESTDIR)$(libdir)
$(LIBTOOL) --mode=finish $(DESTDIR)$(libdir)
Index: libunbound/ubsyms.def
===================================================================
--- libunbound/ubsyms.def (revision 2985)
+++ libunbound/ubsyms.def (working copy)
@@ -29,3 +29,4 @@
ub_ctx_data_add
ub_ctx_data_remove
ub_version
+ub_ctx_set_event
Index: libunbound/unbound-event.h
===================================================================
--- libunbound/unbound-event.h (revision 2985)
+++ libunbound/unbound-event.h (working copy)
@@ -63,9 +63,9 @@
struct ub_ctx;
struct ub_result;
struct event_base;
-struct ldns_buffer;
+struct ldns_struct_buffer;
-typedef void (*ub_event_callback_t)(void*, int, struct ldns_buffer*, int, char*);
+typedef void (*ub_event_callback_t)(void*, int, struct ldns_struct_buffer*, int, char*);
/**
* Create a resolving and validation context.
@@ -82,6 +82,15 @@
struct ub_ctx* ub_ctx_create_event(struct event_base* base);
/**
+ * Set a new event_base on a context created with ub_ctx_create_event.
+ * Any outbound queries will be canceled.
+ * @param ctx the ub_ctx to update. Must have been created with ub_ctx_create_event
+ * @param base the new event_base to attach to the ctx
+ * @return 0 if OK, else error
+ */
+int ub_ctx_set_event(struct ub_ctx* ctx, struct event_base* base);
+
+/**
* Perform resolution and validation of the target name.
* Asynchronous, after a while, the callback will be called with your
* data and the result. Uses the event_base user installed by creating the
Index: libunbound/libunbound.c
===================================================================
--- libunbound/libunbound.c (revision 2985)
+++ libunbound/libunbound.c (working copy)
@@ -656,15 +656,14 @@
return r;
}
}
+ lock_basic_unlock(&ctx->cfglock);
if(!ctx->event_worker) {
ctx->event_worker = libworker_create_event(ctx,
ctx->event_base);
if(!ctx->event_worker) {
- lock_basic_unlock(&ctx->cfglock);
return UB_INITFAIL;
}
}
- lock_basic_unlock(&ctx->cfglock);
/* create new ctx_query and attempt to add to the list */
q = context_new(ctx, name, rrtype, rrclass, (ub_callback_t)callback,
@@ -1212,3 +1211,24 @@
{
return PACKAGE_VERSION;
}
+
+int
+ub_ctx_set_event(struct ub_ctx* ctx, struct event_base* base) {
+ if (!ctx || !ctx->event_base || !base) {
+ return UB_INITFAIL;
+ }
+ if (ctx->event_base == base) {
+ /* already set */
+ return UB_NOERROR;
+ }
+
+ lock_basic_lock(&ctx->cfglock);
+ /* destroy the current worker - safe to pass in NULL */
+ libworker_delete_event(ctx->event_worker);
+ ctx->event_worker = NULL;
+ ctx->event_base = base;
+ ctx->created_bg = 0;
+ ctx->dothread = 1;
+ lock_basic_unlock(&ctx->cfglock);
+ return UB_NOERROR;
+}