diff --git a/.gitignore b/.gitignore index 96691e0f..337ff82e 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ src/test/tests_dict src/test/tests_list src/test/tests_stub_async src/test/tests_stub_sync +src/test/tests_json-pointers src/test/tests_dnssec src/test/tests_namespaces src/test/check_getdns @@ -36,6 +37,8 @@ src/test/check_getdns_event src/test/check_getdns_uv src/test/check_getdns_ev src/test/getdns_query +src/test/scratchpad +src/test/scratchpad.c doc/*.3 src/getdns/getdns.h *.log diff --git a/Makefile.in b/Makefile.in index 93ef6946..64e8b135 100644 --- a/Makefile.in +++ b/Makefile.in @@ -97,6 +97,12 @@ test: getdns_query: cd src && $(MAKE) $@ +scratchpad: + cd src && $(MAKE) $@ + +pad: scratchpad + src/test/scratchpad || ./libtool exec gdb src/test/scratchpad + install-getdns_query: cd src/test && $(MAKE) install diff --git a/configure.ac b/configure.ac index d297a23b..22f05f3e 100644 --- a/configure.ac +++ b/configure.ac @@ -112,6 +112,7 @@ AC_SUBST(libtool) AC_PROG_LIBTOOL AC_PROG_INSTALL + initial_LIBS="$LIBS" initial_LDFLAGS="$LDFLAGS" @@ -417,23 +418,6 @@ case "$enable_stub_only" in ;; esac -AC_ARG_WITH(getdns_query, AS_HELP_STRING([--with-getdns_query], - [Also compile and install the getdns_query tool]), - [], [withval="no"]) -if test x_$withval = x_no; then - GETDNS_QUERY="" - INSTALL_GETDNS_QUERY="" - UNINSTALL_GETDNS_QUERY="" -else - GETDNS_QUERY="getdns_query" - INSTALL_GETDNS_QUERY="install-getdns_query" - UNINSTALL_GETDNS_QUERY="uninstall-getdns_query" -fi -AC_SUBST(GETDNS_QUERY) -AC_SUBST(INSTALL_GETDNS_QUERY) -AC_SUBST(UNINSTALL_GETDNS_QUERY) - - # search to set include and library paths right # find libidn my_with_libidn=1 @@ -866,6 +850,22 @@ AC_DEFINE_UNQUOTED([TRUST_ANCHOR_FILE], ["$TRUST_ANCHOR_FILE"], [Default trust a AC_SUBST(TRUST_ANCHOR_FILE) AC_MSG_NOTICE([Default trust anchor: $TRUST_ANCHOR_FILE]) +AC_ARG_WITH(getdns_query, AS_HELP_STRING([--with-getdns_query], + [Also compile and install the getdns_query tool]), + [], [withval="no"]) +if test x_$withval = x_no; then + GETDNS_QUERY="" + INSTALL_GETDNS_QUERY="" + UNINSTALL_GETDNS_QUERY="" +else + GETDNS_QUERY="getdns_query" + INSTALL_GETDNS_QUERY="install-getdns_query" + UNINSTALL_GETDNS_QUERY="uninstall-getdns_query" +fi +AC_SUBST(GETDNS_QUERY) +AC_SUBST(INSTALL_GETDNS_QUERY) +AC_SUBST(UNINSTALL_GETDNS_QUERY) + AC_CONFIG_FILES([Makefile src/Makefile src/version.c src/getdns/getdns.h src/getdns/getdns_extra.h spec/example/Makefile src/test/Makefile doc/Makefile]) if [ test -n "$DOXYGEN" ] then AC_CONFIG_FILES([src/Doxyfile]) diff --git a/src/Makefile.in b/src/Makefile.in index 5389e0fc..d444aff1 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -148,12 +148,17 @@ libgetdns.la: $(GETDNS_OBJ) version.lo context.lo libmini_event.lo $(GLDNS_OBJ) $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ $(GETDNS_OBJ) version.lo context.lo libmini_event.lo $(GLDNS_OBJ) $(COMPAT_OBJ) $(UTIL_OBJ) $(LDFLAGS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/libgetdns.symbols -test: FORCE +test: all cd test && $(MAKE) $@ -getdns_query: FORCE +getdns_query: all cd test && $(MAKE) $@ +scratchpad: all + cd test && $(MAKE) $@ + +pad: scratchpad + clean: cd test && $(MAKE) $@ rm -f *.o *.lo extension/*.lo extension/*.o $(PROGRAMS) libgetdns.la libgetdns_ext_*.la diff --git a/src/dict.c b/src/dict.c index 33a3930a..16e0b3fb 100644 --- a/src/dict.c +++ b/src/dict.c @@ -150,6 +150,62 @@ _getdns_dict_find(const getdns_dict *dict, const char *key, getdns_item **item) } } + +/*---------------------------------------- getdns_dict_item_free */ +/** + * private function used to release storage associated with a dictionary item + * @param node all memory in this structure and its children will be freed + * @param arg is a dict who's custom memory function will be used + * to free the items + * @return void + */ +static void +getdns_dict_item_free(_getdns_rbnode_t *node, void *arg) +{ + struct getdns_dict_item *d = (struct getdns_dict_item *)node; + struct getdns_dict *dict = (struct getdns_dict *)arg; + + assert(node); + assert(arg); + + switch (d->i.dtype) { + case t_dict : getdns_dict_destroy(d->i.data.dict); break; + case t_list : getdns_list_destroy(d->i.data.list); break; + case t_bindata: _getdns_bindata_destroy(&dict->mf, d->i.data.bindata); + default : break; + } + if (node->key) + GETDNS_FREE(dict->mf, (void *)node->key); + GETDNS_FREE(dict->mf, node); +} /* getdns_dict_item_free */ + + +getdns_return_t +getdns_dict_remove_name(getdns_dict *dict, const char *name) +{ + const char *next; + struct getdns_dict_item *d; + + if (!dict || !name) + return GETDNS_RETURN_INVALID_PARAMETER; + + if (!(d = _find_dict_item(dict, name))) + return GETDNS_RETURN_NO_SUCH_DICT_NAME; + + if (*name != '/' || !(next = strchr(name + 1, '/'))) { + d = _delete_dict_item(dict, name); + getdns_dict_item_free(&d->node, dict); + return GETDNS_RETURN_GOOD; + + } else switch (d->i.dtype) { + case t_dict: return getdns_dict_remove_name(d->i.data.dict, next); + case t_list: return _getdns_list_remove_name(d->i.data.list, next); + default : /* Trying to dereference a non list or dict */ + return GETDNS_RETURN_WRONG_TYPE_REQUESTED; + } +} + + getdns_return_t _getdns_dict_find_and_add( getdns_dict *dict, const char *key, getdns_item **item) @@ -164,31 +220,41 @@ _getdns_dict_find_and_add( _getdns_rbtree_insert(&(dict->root), (_getdns_rbnode_t *) d); if (*key != '/' || !(next = strchr(key + 1, '/'))) { (void) memset(&d->i.data, 0, sizeof(d->i.data)); + d->i.dtype = t_int; + d->i.data.n = 55555333; *item = &d->i; return GETDNS_RETURN_GOOD; } if ((next[1] == '0' || next[1] == '-') && (next[2] == '/' || next[2] == '\0')) { + d->i.dtype = t_list; d->i.data.list =_getdns_list_create_with_mf(&dict->mf); return _getdns_list_find_and_add( d->i.data.list, next, item); } + d->i.dtype = t_dict; d->i.data.dict = _getdns_dict_create_with_mf(&dict->mf); - return _getdns_dict_find_and_add( - d->i.data.dict, next, item); + return _getdns_dict_find_and_add(d->i.data.dict, next, item); } if (*key != '/' || !(next = strchr(key + 1, '/'))) { + switch (d->i.dtype) { + case t_dict : getdns_dict_destroy(d->i.data.dict); break; + case t_list : getdns_list_destroy(d->i.data.list); break; + case t_bindata: _getdns_bindata_destroy( + &dict->mf, d->i.data.bindata); break; + default : break; + } + d->i.dtype = t_int; + d->i.data.n = 33355555; *item = &d->i; return GETDNS_RETURN_GOOD; } else switch (d->i.dtype) { /* Key was nested reference */ - case t_dict: return _getdns_dict_find_and_add( - d->i.data.dict, next, item); - case t_list: return _getdns_list_find_and_add( - d->i.data.list, next, item); - default : /* Trying to dereference a non list or dict */ - return GETDNS_RETURN_WRONG_TYPE_REQUESTED; + case t_dict:return _getdns_dict_find_and_add(d->i.data.dict,next,item); + case t_list:return _getdns_list_find_and_add(d->i.data.list,next,item); + default :/* Trying to dereference a non list or dict */ + return GETDNS_RETURN_WRONG_TYPE_REQUESTED; } } /* getdns_dict_find_and_add */ @@ -448,40 +514,6 @@ _getdns_dict_copy(const struct getdns_dict * srcdict, return GETDNS_RETURN_GOOD; } /* _getdns_dict_copy */ -/*---------------------------------------- getdns_dict_item_free */ -/** - * private function used to release storage associated with a dictionary item - * @param node all memory in this structure and its children will be freed - * @param arg is a dict who's custom memory function will be used - * to free the items - * @return void - */ -static void -getdns_dict_item_free(_getdns_rbnode_t * node, void *arg) -{ - struct getdns_dict_item *item = (struct getdns_dict_item *) node; - struct getdns_dict *dict = (struct getdns_dict *)arg; - - if (!item) - return; - - switch (item->i.dtype) { - case t_bindata: - _getdns_bindata_destroy(&dict->mf, item->i.data.bindata); - break; - case t_dict: - getdns_dict_destroy(item->i.data.dict); - break; - case t_list: - getdns_list_destroy(item->i.data.list); - break; - default: - break; - } - if (item->node.key) - GETDNS_FREE(dict->mf, (void *)item->node.key); - GETDNS_FREE(dict->mf, item); -} /* getdns_dict_item_free */ /*---------------------------------------- getdns_dict_destroy */ void @@ -1202,29 +1234,4 @@ getdns_snprint_json_list( ? -1 : gldns_buffer_position(&buf); } -getdns_return_t -getdns_dict_remove_name(getdns_dict *dict, const char *name) -{ - const char *next; - struct getdns_dict_item *d; - - if (!dict || !name) - return GETDNS_RETURN_INVALID_PARAMETER; - - if (!(d = _find_dict_item(dict, name))) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; - - if (*name != '/' || !(next = strchr(name + 1, '/'))) { - d = _delete_dict_item(dict, name); - getdns_dict_item_free(&d->node, dict); - return GETDNS_RETURN_GOOD; - - } else switch (d->i.dtype) { - case t_dict: return getdns_dict_remove_name(d->i.data.dict, next); - case t_list: return _getdns_list_remove_name(d->i.data.list, next); - default : /* Trying to dereference a non list or dict */ - return GETDNS_RETURN_WRONG_TYPE_REQUESTED; - } -} - /* dict.c */ diff --git a/src/list.c b/src/list.c index 28b7cef7..be4886aa 100644 --- a/src/list.c +++ b/src/list.c @@ -47,6 +47,7 @@ _getdns_list_find(const getdns_list *list, const char *key, getdns_item **item) const char *next; char *endptr; size_t index; + getdns_item *i; if (*key == '/') { if (!(next = strchr(++key, '/'))) @@ -54,7 +55,7 @@ _getdns_list_find(const getdns_list *list, const char *key, getdns_item **item) } else next = strchr(key, '\0'); - if (key[0] == '-' && (key[1] == '/' || key[1] == '\0')) + if (key[0] == '-' && next == key + 1) return GETDNS_RETURN_NO_SUCH_LIST_ITEM; index = strtoul(key, &endptr, 10); @@ -65,80 +66,17 @@ _getdns_list_find(const getdns_list *list, const char *key, getdns_item **item) if (index >= list->numinuse) return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - if (*next) - switch (list->items[index].dtype) { - case t_dict: return _getdns_dict_find( - list->items[index].data.dict, next, item); - case t_list: return _getdns_list_find( - list->items[index].data.list, next, item); - default : /* Trying to dereference a non list or dict */ - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - } - *item = &list->items[index]; - return GETDNS_RETURN_GOOD; -} + i = &list->items[index]; + if (!*next) { + *item = i; + return GETDNS_RETURN_GOOD; -getdns_return_t -_getdns_list_find_and_add( - getdns_list *list, const char *key, getdns_item **item) -{ - const char *next; - char *endptr; - size_t index; - getdns_item *newlist; - - if (*key == '/') { - if (!(next = strchr(++key, '/'))) - next = strchr(key, '\0'); - } else - next = strchr(key, '\0'); - - if (key[0] == '-' && key[1] == '/') - index = list->numinuse; - else { - index = strtoul(key, &endptr, 10); - if (!isdigit((int)*key) || endptr != next) - /* Not a list index, so it was assumed */ - return GETDNS_RETURN_WRONG_TYPE_REQUESTED; + } else switch (i->dtype) { + case t_dict: return _getdns_dict_find(i->data.dict, next, item); + case t_list: return _getdns_list_find(i->data.list, next, item); + default : /* Trying to dereference a non list or dict */ + return GETDNS_RETURN_NO_SUCH_LIST_ITEM; } - if (*next && index == list->numinuse) { - - if (list->numalloc < list->numinuse) { - if (!(newlist = GETDNS_XREALLOC(list->mf, list->items, - getdns_item, list->numalloc+GETDNS_LIST_BLOCKSZ))) - return GETDNS_RETURN_MEMORY_ERROR; - list->items = newlist; - list->numalloc += GETDNS_LIST_BLOCKSZ; - } - list->numinuse++; - - if ((next[1] == '0' || next[1] == '-') && - (next[2] == '/' || next[2] == '\0')) { - - list->items[index].data.list = - _getdns_list_create_with_mf(&list->mf); - return _getdns_list_find_and_add( - list->items[index].data.list, next, item); - } - list->items[index].data.dict = - _getdns_dict_create_with_mf(&list->mf); - return _getdns_dict_find_and_add( - list->items[index].data.dict, next, item); - } - if (index >= list->numinuse) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - - if (*next) - switch (list->items[index].dtype) { - case t_dict: return _getdns_dict_find( - list->items[index].data.dict, next, item); - case t_list: return _getdns_list_find( - list->items[index].data.list, next, item); - default : /* Trying to dereference a non list or dict */ - return GETDNS_RETURN_WRONG_TYPE_REQUESTED; - } - *item = &list->items[index]; - return GETDNS_RETURN_GOOD; } @@ -148,6 +86,7 @@ _getdns_list_remove_name(getdns_list *list, const char *name) const char *next, *key = name; char *endptr; size_t index; + getdns_item *i; if (*key == '/') { if (!(next = strchr(++key, '/'))) @@ -155,7 +94,7 @@ _getdns_list_remove_name(getdns_list *list, const char *name) } else next = strchr(key, '\0'); - if (key[0] == '-' && (key[1] == '/' || key[1] == '\0')) + if (key[0] == '-' && next == key + 1) return GETDNS_RETURN_NO_SUCH_LIST_ITEM; index = strtoul(key, &endptr, 10); @@ -166,25 +105,102 @@ _getdns_list_remove_name(getdns_list *list, const char *name) if (index >= list->numinuse) return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - if (*next) - switch (list->items[index].dtype) { - case t_dict: return getdns_dict_remove_name( - list->items[index].data.dict, next); - case t_list: return _getdns_list_remove_name( - list->items[index].data.list, next); - default : /* Trying to dereference a non list or dict */ - return GETDNS_RETURN_WRONG_TYPE_REQUESTED; - } + i = &list->items[index]; + if (!*next) { + if (index < list->numinuse - 1) + (void) memmove( i, &i[1], + (list->numinuse - index) * sizeof(getdns_item)); + list->numinuse -= 1; + return GETDNS_RETURN_GOOD; - if (index < list->numinuse - 1) - (void) memmove( &list->items[index] - , &list->items[index + 1] - , list->numinuse - index); - list->numinuse -= 1; - return GETDNS_RETURN_GOOD; + } else switch (i->dtype) { + case t_dict: return getdns_dict_remove_name(i->data.dict, next); + case t_list: return _getdns_list_remove_name(i->data.list, next); + default : /* Trying to dereference a non list or dict */ + return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + } } +getdns_return_t +_getdns_list_find_and_add( + getdns_list *list, const char *key, getdns_item **item) +{ + const char *next; + char *endptr; + size_t index; + getdns_item *newlist, *i; + + if (*key == '/') { + if (!(next = strchr(++key, '/'))) + next = strchr(key, '\0'); + } else + next = strchr(key, '\0'); + + if (key[0] == '-' && next == key + 1) + index = list->numinuse; + else { + index = strtoul(key, &endptr, 10); + if (!isdigit((int)*key) || endptr != next) + /* Not a list index, so it was assumed */ + return GETDNS_RETURN_WRONG_TYPE_REQUESTED; + } + if (index > list->numinuse) + return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + + if (index == list->numinuse) { + if (list->numalloc <= list->numinuse) { + if (!(newlist = GETDNS_XREALLOC(list->mf, list->items, + getdns_item, list->numalloc+GETDNS_LIST_BLOCKSZ))) + return GETDNS_RETURN_MEMORY_ERROR; + list->items = newlist; + list->numalloc += GETDNS_LIST_BLOCKSZ; + } + list->numinuse++; + i = &list->items[index]; + + if (!*next) { + i->dtype = t_int; + i->data.n = 55555333; + *item = i; + return GETDNS_RETURN_GOOD; + } + if ((next[1] == '0' || next[1] == '-') && + (next[2] == '/' || next[2] == '\0')) { + + i->dtype = t_list; + i->data.list = _getdns_list_create_with_mf(&list->mf); + return _getdns_list_find_and_add( + i->data.list, next, item); + } + i->dtype = t_dict; + i->data.dict = _getdns_dict_create_with_mf(&list->mf); + return _getdns_dict_find_and_add(i->data.dict, next, item); + } + i = &list->items[index]; + if (!*next) { + switch (i->dtype) { + case t_dict : getdns_dict_destroy(i->data.dict); break; + case t_list : getdns_list_destroy(i->data.list); break; + case t_bindata: _getdns_bindata_destroy( + &list->mf, i->data.bindata); break; + default : break; + } + i->dtype = t_int; + i->data.n = 33355555; + *item = i; + return GETDNS_RETURN_GOOD; + + } else switch (i->dtype) { + case t_dict: return _getdns_dict_find_and_add(i->data.dict,next,item); + case t_list: return _getdns_list_find_and_add(i->data.list,next,item); + default : /* Trying to dereference a non list or dict */ + return GETDNS_RETURN_WRONG_TYPE_REQUESTED; + } +} + + + /*---------------------------------------- getdns_list_get_length */ getdns_return_t getdns_list_get_length(const struct getdns_list * list, size_t * answer) diff --git a/src/test/Makefile.in b/src/test/Makefile.in index cb07b954..1ffa7644 100644 --- a/src/test/Makefile.in +++ b/src/test/Makefile.in @@ -71,13 +71,13 @@ CHECK_OBJS=check_getdns_common.lo check_getdns_context_set_timeout.lo \ check_getdns.lo check_getdns_transport.lo ALL_OBJS=$(CHECK_OBJS) check_getdns_libevent.lo check_getdns_libev.lo \ - check_getdns_selectloop.lo getdns_query.lo testmessages.lo \ - tests_dict.lo tests_list.lo tests_namespaces.lo \ - tests_stub_async.lo tests_stub_sync.lo + check_getdns_selectloop.lo getdns_query.lo scratchpad.lo \ + testmessages.lo tests_dict.lo tests_list.lo tests_namespaces.lo \ + tests_stub_async.lo tests_stub_sync.lo tests_json-pointers.lo NON_C99_OBJS=check_getdns_libuv.lo -PROGRAMS=tests_dict tests_list tests_namespaces tests_stub_async tests_stub_sync getdns_query $(CHECK_GETDNS) $(CHECK_EV_PROG) $(CHECK_EVENT_PROG) $(CHECK_UV_PROG) +PROGRAMS=tests_dict tests_list tests_namespaces tests_stub_async tests_stub_sync tests_json-pointers getdns_query $(CHECK_GETDNS) $(CHECK_EV_PROG) $(CHECK_EVENT_PROG) $(CHECK_UV_PROG) .SUFFIXES: .c .o .a .lo .h @@ -113,6 +113,9 @@ tests_stub_async: tests_stub_async.lo testmessages.lo tests_stub_sync: tests_stub_sync.lo $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_stub_sync.lo +tests_json-pointers: tests_json-pointers.lo + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_json-pointers.lo + check_getdns_common: check_getdns_common.lo $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ check_getdns_common.lo @@ -131,6 +134,14 @@ check_getdns_ev: check_getdns.lo check_getdns_common.lo check_getdns_context_set getdns_query: getdns_query.lo $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ getdns_query.lo $(LDFLAGS) $(LDLIBS) +scratchpad: scratchpad.lo + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ scratchpad.lo $(LDFLAGS) $(LDLIBS) + +scratchpad.lo: scratchpad.c + +$(srcdir)/scratchpad.c: scratchpad.template.c + [ ! -f $(srcdir)/scratchpad.c ] && cp -p $(srcdir)/scratchpad.template.c $(srcdir)/scratchpad.c || true + install: getdns_query $(INSTALL) -m 755 -d $(DESTDIR)$(bindir) $(LIBTOOL) --mode=install cp getdns_query $(DESTDIR)$(bindir) @@ -165,11 +176,12 @@ test: $(NOLIBCHECK) $(NOLIBLDNS) all @echo "All tests OK" clean: - rm -f *.o *.lo $(PROGRAMS) + rm -f *.o *.lo $(PROGRAMS) scratchpad rm -rf .libs rm -f check_getdns.log distclean : clean + rm -f scratchpad.c rm -f Makefile config.status config.log rm -Rf autom4te.cache @@ -265,8 +277,13 @@ check_getdns_transport.lo check_getdns_transport.o: $(srcdir)/check_getdns_trans ../getdns/getdns_extra.h getdns_query.lo getdns_query.o: $(srcdir)/getdns_query.c ../config.h ../getdns/getdns.h \ ../getdns/getdns_extra.h +scratchpad.lo scratchpad.o: $(srcdir)/scratchpad.c ../getdns/getdns.h ../getdns/getdns_extra.h +scratchpad.template.lo scratchpad.template.o: scratchpad.template.c ../getdns/getdns.h \ + ../getdns/getdns_extra.h testmessages.lo testmessages.o: $(srcdir)/testmessages.c $(srcdir)/testmessages.h tests_dict.lo tests_dict.o: $(srcdir)/tests_dict.c $(srcdir)/testmessages.h ../getdns/getdns.h +tests_json-pointers.lo tests_json-pointers.o: $(srcdir)/tests_json-pointers.c ../getdns/getdns.h \ + ../getdns/getdns_extra.h tests_list.lo tests_list.o: $(srcdir)/tests_list.c $(srcdir)/testmessages.h ../getdns/getdns.h tests_namespaces.lo tests_namespaces.o: $(srcdir)/tests_namespaces.c $(srcdir)/testmessages.h ../getdns/getdns.h tests_stub_async.lo tests_stub_async.o: $(srcdir)/tests_stub_async.c ../config.h $(srcdir)/testmessages.h \ diff --git a/src/test/scratchpad.template.c b/src/test/scratchpad.template.c new file mode 100644 index 00000000..a3077c5a --- /dev/null +++ b/src/test/scratchpad.template.c @@ -0,0 +1,21 @@ +#include +#include +#include + +int main() +{ + getdns_return_t r; + getdns_context *ctx = NULL; + + if ((r = getdns_context_create(&ctx, 1))) + fprintf(stderr, "Could not create context"); + + if (ctx) + getdns_context_destroy(ctx); + + if (r) { + fprintf(stderr, ": %s\n", getdns_get_errorstr_by_id(r)); + exit(EXIT_FAILURE); + } + exit(EXIT_SUCCESS); +} diff --git a/src/test/tests_json-pointers.c b/src/test/tests_json-pointers.c new file mode 100644 index 00000000..6faa19f2 --- /dev/null +++ b/src/test/tests_json-pointers.c @@ -0,0 +1,46 @@ +#include +#include +#include + +int main() +{ + getdns_return_t r; + getdns_dict *dict = NULL; + unsigned char bladiebla_str[] = "bla die bla"; + getdns_bindata bladiebla = { sizeof(bladiebla_str), bladiebla_str }; + + if (!(dict = getdns_dict_create())) + fprintf(stderr, "Could not create dict\n"); + + else if ((r = getdns_dict_set_int(dict, "/bla/bloe/blie", 53280)) + || (r = getdns_dict_set_int(dict, "/bla/hola", 53281)) + || (r = getdns_dict_set_int(dict, "/bla/cola/-", 1)) + || (r = getdns_dict_set_int(dict, "/bla/cola/-", 2)) + || (r = getdns_dict_set_int(dict, "/bla/cola/-/drie", 3)) + || (r = getdns_dict_set_int(dict, "/bla/cola/-", 4)) + || (r = getdns_dict_set_int(dict, "/bla/cola/1", 5)) + || (r = getdns_dict_set_int(dict, "/bla/cola/2/zes", 6)) + || (r = getdns_dict_set_bindata(dict, "/die/bla", &bladiebla)) + ) + fprintf(stderr, "Error setting dict data"); + else { + char *dict_str = getdns_pretty_print_dict(dict); + + if (!dict_str) + fprintf(stderr, "Could not convert dict to string.\n"); + else { + printf("%s\n", dict_str); + free(dict_str); + } + } + if (r) + fprintf(stderr, ": %s\n", getdns_get_errorstr_by_id(r)); + + if (dict) + getdns_dict_destroy(dict); + + if (r) + exit(EXIT_FAILURE); + + exit(EXIT_SUCCESS); +} diff --git a/src/test/tests_json-pointers.good b/src/test/tests_json-pointers.good new file mode 100644 index 00000000..3587ed83 --- /dev/null +++ b/src/test/tests_json-pointers.good @@ -0,0 +1,24 @@ +{ + "bla": + { + "bloe": + { + "blie": 53280 + }, + "cola": + [ + 1, + 5, + { + "drie": 3, + "zes": 6 + }, + 4 + ], + "hola": 53281 + }, + "die": + { + "bla": + } +}