Commit 0611e530 authored by Ondrej Sury's avatar Ondrej Sury

Imported Upstream version 1.6.10

parent 534e4f00
1.6.10
* New example tool added: ldns-gen-zone.
* bugfix #359: Serial-arithmetic for the inception and expiration
fields of a RRSIG and correctly converting them to broken-out time
information.
* bugfix #364: Slight performance increase of ldns-verifyzone.
* bugfix #367: Fix to allow glue records with the same name as the
delegation.
* Fix ldns-verifyzone to allow NSEC3-less records for NS rrsets *and*
glue when the zone is opt-out.
* bugfix #376: Adapt ldns_nsec3_salt, ldns_nsec3_iterations,
ldns_nsec3_flags and ldns_nsec3_algorithm to work for NSEC3PARAMS too.
* pyldns memory leaks fixed by Bedrich Kosata (at the cost of a bit
performance)
* Better handling of reference variables in ldns_rr_new_frm_fp_l from
pyldns, with a very nice generator function by Bedrich Kosata.
* Decoupling of the rdfs in rrs in the python wrappers to enable
the python garbage collector by Bedrich Kosata.
* bugfix #380: Minimizing effect of discrepancies in sizeof(bool) at
build time and when used.
* bugfix #383: Fix detection of empty nonterminals of multiple labels.
* Fixed the ommission of rrsets in nsec(3)s and rrsigs to all occluded
names (in stead of just the ones that contain glue only) and all
occluded records on the delegation points (in stead of just the glue).
* Clarify the operation of ldns_dnssec_mark_glue and the usage of
ldns_dnssec_node_next_nonglue functions in the documentation.
* Added function ldns_dnssec_mark_and_get_glue as an real fast
alternative for ldns_zone_glue_rr_list.
* Fix parse buffer overflow for max length domain names.
* Fix Makefile for U in environment, since wrong U is more common than
deansification necessity.
1.6.9 2011-03-16
* Fix creating NSEC(3) bitmaps: make array size 65536,
don't add doubles.
......
......@@ -32,6 +32,10 @@ ifdef glibtool
libtool = $(glibtool)
endif
# override $U variable which is used by autotools for deansification (for
# K&R C compilers), but causes problems if $U is defined in the env).
U=
CC = @CC@
ifeq "$(srcdir)" "."
CPPFLAGS = $(strip -I. @CPPFLAGS@ @DEFS@)
......@@ -44,6 +48,7 @@ LIBS = @LIBS@
LIBOBJS = @LIBOBJS@
PYTHON_CPPFLAGS = @PYTHON_CPPFLAGS@
PYTHON_LDFLAGS = @PYTHON_LDFLAGS@
PYTHON_X_CFLAGS = @PYTHON_X_CFLAGS@
LIBSSL_CPPFLAGS = @LIBSSL_CPPFLAGS@
LIBSSL_LDFLAGS = @LIBSSL_LDFLAGS@
LIBSSL_LIBS = @LIBSSL_LIBS@
......@@ -56,7 +61,7 @@ LINT = splint
LINTFLAGS=+quiet -weak -warnposix -unrecog -Din_addr_t=uint32_t -Du_int=unsigned -Du_char=uint8_t -preproc -Drlimit=rlimit64 -D__gnuc_va_list=va_list
#-Dglob64=glob -Dglobfree64=globfree
# compat with openssl linux edition.
LINTFLAGS+="-DBN_ULONG=unsigned long" -Dkrb5_int32=int "-Dkrb5_ui_4=unsigned int" -DPQ_64BIT=uint64_t -DRC4_INT=unsigned -fixedformalarray -D"ENGINE=unsigned" -D"RSA=unsigned" -D"DSA=unsigned" -D"EVP_PKEY=unsigned" -D"EVP_MD=unsigned" -D"SSL=unsigned" -D"SSL_CTX=unsigned" -D"X509=unsigned" -D"RC4_KEY=unsigned" -D"EVP_MD_CTX=unsigned" -D"EC_KEY=unsigned" -D"EC_POINT=unsigned" -D"EC_GROUP=unsigned"
LINTFLAGS+="-DBN_ULONG=unsigned long" -Dkrb5_int32=int "-Dkrb5_ui_4=unsigned int" -DPQ_64BIT=uint64_t -DRC4_INT=unsigned -fixedformalarray -D"ENGINE=unsigned" -D"RSA=unsigned" -D"DSA=unsigned" -D"EVP_PKEY=unsigned" -D"EVP_MD=unsigned" -D"SSL=unsigned" -D"SSL_CTX=unsigned" -D"X509=unsigned" -D"RC4_KEY=unsigned" -D"EVP_MD_CTX=unsigned" -D"EC_KEY=unsigned" -D"EC_POINT=unsigned" -D"EC_GROUP=unsigned" -D"EVP_PKEY_ASN1_METHOD=struct evp_pkey_asn1_method_st" -D"EVP_PKEY_CTX=struct evp_pkey_ctx_st"
# compat with NetBSD
ifeq "$(shell uname)" "NetBSD"
LINTFLAGS+="-D__RENAME(x)=" -D_NETINET_IN_H_
......@@ -76,7 +81,6 @@ LIBDNS_SOURCES = rdata.c util.c rr.c packet.c wire2host.c \
sha1.c sha2.c
LIBDNS_HEADERS = $(srcdir)/ldns/error.h \
$(srcdir)/ldns/packet.h \
$(srcdir)/ldns/common.h \
$(srcdir)/ldns/rdata.h \
$(srcdir)/ldns/rr.h \
$(srcdir)/ldns/wire2host.h \
......@@ -111,7 +115,7 @@ COMP_LIB = $(LIBTOOL) --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS)
LINK = $(CC) $(strip $(CFLAGS) $(LDFLAGS) $(LIBS))
LINK_LIB = $(LIBTOOL) --mode=link $(CC) $(strip $(CFLAGS) $(LDFLAGS) $(LIBS) -version-number $(version_info) -no-undefined)
%.o: $(srcdir)/%.c $(LIBDNS_HEADERS) ldns/net.h ldns/util.h ldns/config.h
%.o: $(srcdir)/%.c $(LIBDNS_HEADERS) ldns/common.h ldns/net.h ldns/util.h ldns/config.h
$(COMP_LIB) $(LIBSSL_CPPFLAGS) -c $<
.PHONY: clean realclean docclean manpages doc lint all lib pyldns test
......@@ -120,7 +124,7 @@ LINK_LIB = $(LIBTOOL) --mode=link $(CC) $(strip $(CFLAGS) $(LDFLAGS) $(LIBS) -ve
all: copy-headers lib linktest manpages @PYLDNS@
linktest: $(srcdir)/linktest.c $(LIBDNS_HEADERS) ldns/net.h ldns/util.h ldns/config.h libldns.la
linktest: $(srcdir)/linktest.c $(LIBDNS_HEADERS) ldns/common.h ldns/net.h ldns/util.h ldns/config.h libldns.la
$(LIBTOOL) --mode=link $(CC) $(srcdir)/linktest.c $(CPPFLAGS) $(LIBSSL_CPPFLAGS) $(CFLAGS) -lldns $(LIBS) -o linktest
lib: libldns.la
......@@ -140,12 +144,12 @@ $(addprefix include/ldns/, $(notdir $(LIBDNS_HEADERS))): include/ldns/%.h: $(src
@if [ ! -d include/ldns ] ; then (cd include; ln -s ../ldns ./ldns || echo "include/ldns exists") ; fi ;
$(INSTALL) -c -m 644 $< ./include/ldns/
include/ldns/util.h include/ldns/net.h include/ldns/config.h: include/ldns/%.h: ./ldns/%.h
include/ldns/util.h include/ldns/common.h include/ldns/net.h include/ldns/config.h: include/ldns/%.h: ./ldns/%.h
@if [ ! -d include ] ; then ($(INSTALL) -d include || echo "include exists") ; fi ;
@if [ ! -d include/ldns ] ; then (cd include; ln -s ../ldns ./ldns || echo "include/ldns exists") ; fi ;
$(INSTALL) -c -m 644 $< ./include/ldns/
copy-headers: $(addprefix include/ldns/, $(notdir $(LIBDNS_HEADERS))) include/ldns/util.h include/ldns/net.h include/ldns/config.h
copy-headers: $(addprefix include/ldns/, $(notdir $(LIBDNS_HEADERS))) include/ldns/common.h include/ldns/util.h include/ldns/net.h include/ldns/config.h
mancheck:
sh -c 'find . -name \*.\[13\] -exec troff -z {} \;' 2>&1 | sed "s/^\.\///" | sed "s/\(:[0\-9]\+:\)/\1 warning:/g"
......@@ -167,18 +171,18 @@ manpages: $(srcdir)/doc/function_manpages
pyldns: _ldns.la
$(pywrapdir)/ldns_wrapper.c: $(pywrapdir)/ldns.i $(wildcard $(pywrapdir)/*.i) $(LIBDNS_HEADERS) ldns/util.h ldns/config.h
$(pywrapdir)/ldns_wrapper.c: $(pywrapdir)/ldns.i $(wildcard $(pywrapdir)/*.i) $(LIBDNS_HEADERS) ldns/common.h ldns/util.h ldns/config.h
$(swig) -python -o $@ $(CPPFLAGS) $(PYTHON_CPPFLAGS) $<
ldns_wrapper.lo: $(pywrapdir)/ldns_wrapper.c $(LIBDNS_HEADERS) ldns/util.h ldns/config.h
$(COMP_LIB) -I./include/ldns $(PYTHON_CPPFLAGS) -c $< -o $@
ldns_wrapper.lo: $(pywrapdir)/ldns_wrapper.c $(LIBDNS_HEADERS) ldns/common.h ldns/util.h ldns/config.h
$(COMP_LIB) -I./include/ldns $(PYTHON_CPPFLAGS) $(PYTHON_X_CFLAGS) -c $< -o $@
_ldns.la: ldns_wrapper.lo libldns.la
$(LIBTOOL) --tag=CC --mode=link $(CC) $(strip $(CFLAGS) $(PYTHON_CFLAGS) $(LDFLAGS) $(PYTHON_LDFLAGS) -module -version-number $(version_info) -no-undefined -o $@ $< -rpath $(python_site) -L. -L.libs -lldns $(LIBS))
install: install-h install-lib install-config install-manpages $(pyldns_inst)
uninstall: uninstall-manpages uninstall-h uninstall-lib $(pyldns_uninst)
uninstall: uninstall-manpages uninstall-config uninstall-h uninstall-lib $(pyldns_uninst)
destclean: uninstall
......@@ -188,6 +192,12 @@ install-config:
$(INSTALL) -c -m 755 packaging/ldns-config $(DESTDIR)$(bindir)/; \
fi
uninstall-config:
if [ $(INSTALL_LDNS_CONFIG) = "yes" ] ; then \
rm -f $(DESTDIR)$(bindir)/ldns-config; \
[ ! -d $(DESTDIR)$(bindir) ] || rmdir -p $(DESTDIR)$(bindir) || echo "ok, dir already gone"; \
fi
install-manpages: manpages
${INSTALL} -d $(DESTDIR)$(mandir)/man3
for f in doc/man/man3/*; do \
......@@ -203,12 +213,16 @@ install-h: lib
$(INSTALL) -m 755 -d $(DESTDIR)$(includedir)/ldns
for i in $(LIBDNS_HEADERS); do \
$(INSTALL) -c -m 644 $$i $(DESTDIR)$(includedir)/ldns/; done
$(INSTALL) -c -m 644 include/ldns/common.h $(DESTDIR)$(includedir)/ldns/
$(INSTALL) -c -m 644 include/ldns/util.h $(DESTDIR)$(includedir)/ldns/
$(INSTALL) -c -m 644 include/ldns/net.h $(DESTDIR)$(includedir)/ldns/
uninstall-h:
for i in $(LIBDNS_HEADERS); do \
rm -f $(DESTDIR)$(includedir)/$$i; done
rm -f $(DESTDIR)$(includedir)/ldns/net.h
rm -f $(DESTDIR)$(includedir)/ldns/util.h
rm -f $(DESTDIR)$(includedir)/ldns/common.h
[ ! -d $(DESTDIR)$(includedir)/ldns ] || rmdir -p $(DESTDI)$(includedir)/ldns || echo "ok, dir already gone"
exit 0
......@@ -255,6 +269,7 @@ realclean: clean docclean libclean
rm -f ldns/config.h.in
rm -f ldns/config.h
rm -f ldns/util.h
rm -f ldns/common.h
rm -f config.h.in
rm -f configure
rm -f config.sub
......@@ -275,7 +290,7 @@ libclean:
$(LIBTOOL) --mode clean rm -f libldns.so
$(LIBTOOL) --mode clean rm -f libldns.so.*
$(LIBTOOL) --mode clean rm -f _ldns.la
rm -rf ldns/net.h ldns/util.h ldns/config.h
rm -rf ldns/net.h ldns/util.h ldns/config.h ldns/common.h
rm -rf *.lo
rm -rf .libs
rm -rf libtool
......
......@@ -8,6 +8,8 @@ Contents:
INFORMATION FOR SPECIFIC OPERATING SYSTEMS
Mac OS X
Solaris
KNOWN ISSUES
pyldns
Your Support
Project page:
......@@ -65,6 +67,7 @@ commands may be a little bit different on your machine. Most notable, you'll nee
* Developers
ldns is developed by the ldns team at NLnet Labs. This team currently
consists of:
o Willem Toorop
o Wouter Wijngaards
o Matthijs Mekking
......@@ -74,6 +77,7 @@ Former main developers:
* Credits
We have received patches from the following people, thanks!
o Bedrich Kosata
o Erik Rozendaal
o Håkan Olsson
o Jakob Schlyter
......@@ -82,7 +86,7 @@ We have received patches from the following people, thanks!
o Ondřej Surý
IFORMATION FOR SPECIFIC OPERATING SYSTEMS
INFORMATION FOR SPECIFIC OPERATING SYSTEMS
MAC OS X
......@@ -103,6 +107,17 @@ compile in 64-bit mode. Jakob Schlyter has kindly contributed a build
script that sets the right build and link options. You can find it in
contrib/build-solaris.sh
KNOWN ISSUES
A complete list of currently known open issues can be found here:
http://www.nlnetlabs.nl/projects/ldns/bugs
* pyldns
Compiling pyldns produces many ``unused parameter'' warnings. Those are
harmless and may safely be ignored.
Also when building with Swig which version is before 2.0.4, compiling
pyldns produces many ``missing initializer'' warnings. Those are harmless
too.
Your Support
NLnet Labs offers all of its software products as open source, most are
......
/* Just a replacement, if the original malloc is not
GNU-compliant. See autoconf documentation. */
#if HAVE_CONFIG_H
#include <ldns/config.h>
#endif
void *calloc();
#if !HAVE_BZERO && HAVE_MEMSET
# define bzero(buf, bytes) ((void) memset (buf, 0, bytes))
#endif
void *
calloc(size_t num, size_t size)
{
void *new = malloc(num * size);
if (!new) {
return NULL;
}
bzero(new, num * size);
return new;
}
This diff is collapsed.
......@@ -6,7 +6,7 @@ sinclude(acx_nlnetlabs.m4)
# must be numbers. ac_defun because of later processing.
m4_define([VERSION_MAJOR],[1])
m4_define([VERSION_MINOR],[6])
m4_define([VERSION_MICRO],[9])
m4_define([VERSION_MICRO],[10])
AC_INIT(ldns, m4_defn([VERSION_MAJOR]).m4_defn([VERSION_MINOR]).m4_defn([VERSION_MICRO]), libdns@nlnetlabs.nl, libdns)
AC_CONFIG_SRCDIR([packet.c])
# needed to build correct soname
......@@ -84,6 +84,7 @@ AC_SEARCH_LIBS([socket], [socket])
AC_SEARCH_LIBS([inet_pton], [nsl])
# check for python
PYTHON_X_CFLAGS=""
AC_ARG_WITH(pyldns, AC_HELP_STRING([--with-pyldns],
[generate python library, or --without-pyldns to disable Python support.]),
[],[ withval="no" ])
......@@ -113,9 +114,15 @@ if test x_$withval != x_no; then
AC_SUBST(swig, "$SWIG")
fi
else
AC_MSG_RESULT([*** don't have Python, skipping Swig, no pyldns ***])
AC_MSG_RESULT([*** don't have Python, skipping Swig, no pyldns ***]) # '
fi
# xtra cflags for pyldns
if test x_$ldns_have_python != x_no; then
ACX_CHECK_COMPILER_FLAG(fno-strict-aliasing, [PYTHON_X_CFLAGS="-fno-strict-aliasing"])
fi
fi
AC_SUBST(PYTHON_X_CFLAGS)
# Use libtool
ACX_LIBTOOL_C_ONLY
......@@ -177,6 +184,7 @@ case "$enable_ecdsa" in
])
# we now know we have ECDSA and the required curves.
AC_DEFINE_UNQUOTED([USE_ECDSA], [1], [Define this to enable ECDSA support.])
AC_SUBST(ldns_build_config_use_ecdsa, 1)
AC_WARN([
*****************************************************************
*** YOU HAVE ENABLED ECDSA WHICH IS EXPERIMENTAL AT THIS TIME ***
......@@ -184,8 +192,10 @@ case "$enable_ecdsa" in
*****************************************************************])
;;
no)
AC_SUBST(ldns_build_config_use_ecdsa, 0)
;;
*)
AC_SUBST(ldns_build_config_use_ecdsa, 0)
;;
esac
......@@ -229,10 +239,11 @@ AC_C_BIGENDIAN
# Checks for header files.
AC_HEADER_STDC
AC_HEADER_STDBOOL
#AC_HEADER_SYS_WAIT
#AC_CHECK_HEADERS([getopt.h fcntl.h stdlib.h string.h strings.h unistd.h])
# do the very minimum - we can always extend this
AC_CHECK_HEADERS([getopt.h stdarg.h stdbool.h openssl/ssl.h netinet/in.h time.h arpa/inet.h netdb.h],,, [AC_INCLUDES_DEFAULT])
AC_CHECK_HEADERS([getopt.h stdarg.h openssl/ssl.h netinet/in.h time.h arpa/inet.h netdb.h],,, [AC_INCLUDES_DEFAULT])
AC_CHECK_HEADERS(sys/param.h sys/mount.h,,,
[AC_INCLUDES_DEFAULT
[
......@@ -259,8 +270,10 @@ AC_CHECK_HEADER(inttypes.h,
[
include_inttypes_h='#include <inttypes.h>'
AC_DEFINE(HAVE_INTTYPES_H, 1, [define if you have inttypes.h])
AC_SUBST(ldns_build_config_have_inttypes_h, 1)
],[
include_inttypes_h=''
AC_SUBST(ldns_build_config_have_inttypes_h, 0)
],[AC_INCLUDES_DEFAULT
])
AC_SUBST(include_inttypes_h)
......@@ -283,6 +296,20 @@ include_unistd_h=''
])
AC_SUBST(include_unistd_h)
AC_CHECK_SIZEOF(time_t,,[
AC_INCLUDES_DEFAULT
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
])
ACX_TYPE_SOCKLEN_T
AC_CHECK_TYPE(ssize_t, int)
AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [
......@@ -308,6 +335,7 @@ AC_REPLACE_FUNCS(b64_pton)
AC_REPLACE_FUNCS(b64_ntop)
AC_REPLACE_FUNCS(b32_pton)
AC_REPLACE_FUNCS(b32_ntop)
AC_REPLACE_FUNCS(calloc)
AC_REPLACE_FUNCS(timegm)
AC_REPLACE_FUNCS(gmtime_r)
AC_REPLACE_FUNCS(ctime_r)
......@@ -319,7 +347,7 @@ AC_REPLACE_FUNCS(inet_ntop)
AC_REPLACE_FUNCS(snprintf)
AC_REPLACE_FUNCS(strlcpy)
AC_REPLACE_FUNCS(memmove)
AC_CHECK_FUNCS([endprotoent endservent sleep random fcntl strtoul])
AC_CHECK_FUNCS([endprotoent endservent sleep random fcntl strtoul bzero memset])
ACX_CHECK_GETADDRINFO_WITH_INCLUDES
if test $ac_cv_func_getaddrinfo = no; then
......@@ -479,7 +507,23 @@ size_t strlcpy(char *dst, const char *src, size_t siz);
#endif
])
AC_CONFIG_FILES([Makefile ldns/net.h ldns/util.h packaging/libldns.pc packaging/ldns-config])
if test "x$HAVE_SSL" = "xyes"; then
AC_SUBST(ldns_build_config_have_ssl, 1)
else
AC_SUBST(ldns_build_config_have_ssl, 0)
fi
if test "x$ac_cv_c_format_attribute" = "xyes"; then
AC_SUBST(ldns_build_config_have_attr_format, 1)
else
AC_SUBST(ldns_build_config_have_attr_format, 0)
fi
if test "x$ac_cv_c_unused_attribute" = "xyes"; then
AC_SUBST(ldns_build_config_have_attr_unused, 1)
else
AC_SUBST(ldns_build_config_have_attr_unused, 0)
fi
AC_CONFIG_FILES([Makefile ldns/common.h ldns/net.h ldns/util.h packaging/libldns.pc packaging/ldns-config])
AC_CONFIG_HEADER([ldns/config.h])
AC_OUTPUT
......
......@@ -62,6 +62,6 @@ doc: ../../.libs/ldns.so.1 _ldns.so
#for development only
swig: ldns.i
swig -python -o ldns_wrapper.c -I../.. ldns.i
gcc -c ldns_wrapper.c -O9 -fPIC -I../.. -I../../ldns -I/usr/include/python2.5 -I. -o ldns_wrapper.o
gcc -c ldns_wrapper.c -O9 -fPIC -I../.. -I../../ldns -I/usr/local/include/python2.6 -I. -o ldns_wrapper.o
ld -shared ldns_wrapper.o -L../../.libs -lldns -o _ldns.so
import ldns
import sys
if len(sys.argv) <= 1:
print "Usage: %s zone_file" % sys.argv[0]
sys.exit()
inp = open(sys.argv[1],"r");
for rr in ldns.ldns_rr_iter_frm_fp_l(inp):
print rr
inp.close()
import ldns
import sys
if len(sys.argv) <= 1:
print "Usage: %s zone_file" % sys.argv[0]
sys.exit()
inp = open(sys.argv[1],"r");
# variables that preserve the parsers state
my_ttl = 3600;
my_origin = None
my_prev = None
# additional state variables
last_pos = 0
line_nr = 0
while True:
ret = ldns.ldns_rr_new_frm_fp_l_(inp, my_ttl, my_origin, my_prev)
s, rr, line_inc, new_ttl, new_origin, new_prev = ret # unpack the result
line_nr += line_inc # increase number of parsed lines
my_prev = new_prev # update ref to previous owner
if s == ldns.LDNS_STATUS_SYNTAX_TTL:
my_ttl = new_ttl # update default TTL
print "$TTL:", my_ttl
elif s == ldns.LDNS_STATUS_SYNTAX_ORIGIN:
my_origin = new_origin # update reference to origin
print "$ORIGIN:", my_origin
elif s == ldns.LDNS_STATUS_SYNTAX_EMPTY:
if last_pos == inp.tell():
break # no advance since last read - EOF
last_pos = inp.tell()
elif s != ldns.LDNS_STATUS_OK:
print "! parse error in line", line_nr
else:
# we are sure to have LDNS_STATUS_OK
print rr
inp.close()
print "--------------------"
print "Read %d lines" % line_nr
......@@ -95,6 +95,9 @@ uint32_t ldns_read_timeval_usec(struct timeval* t) {
%apply int *OUTPUT { int *line_nr};
%apply uint32_t *OUTPUT { uint32_t *default_ttl};
// wire2pkt
%apply (char *STRING, int LENGTH) { (const char *str, int len) };
%include "ldns_packet.i"
%include "ldns_resolver.i"
%include "ldns_rr.i"
......@@ -144,6 +147,14 @@ typedef struct ldns_dnssec_zone { };
{
PyObject* tuple;
/* origin and prev have to be cloned in order to decouple the data
* from the python wrapper
*/
if (origin != NULL)
origin = ldns_rdf_clone(origin);
if (prev != NULL)
prev = ldns_rdf_clone(prev);
ldns_rdf *p_prev = prev;
ldns_rdf **pp_prev = &p_prev;
if (p_prev == 0) pp_prev = 0;
......@@ -157,14 +168,14 @@ typedef struct ldns_dnssec_zone { };
PyTuple_SetItem(tuple, 0, SWIG_From_int(st));
PyTuple_SetItem(tuple, 1, (st == LDNS_STATUS_OK) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_rr), SWIGTYPE_p_ldns_struct_rr, SWIG_POINTER_OWN | 0 ) :
Py_None);
(Py_INCREF(Py_None), Py_None));
PyTuple_SetItem(tuple, 2, (p_prev != prev) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_prev), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 ) :
Py_None);
(Py_INCREF(Py_None), Py_None));
return tuple;
}
PyObject* ldns_rr_new_frm_fp_l_(FILE *fp, uint32_t default_ttl, ldns_rdf* origin, ldns_rdf* prev, int ret_linenr)
PyObject* ldns_rr_new_frm_fp_l_(FILE *fp, uint32_t default_ttl, ldns_rdf* origin, ldns_rdf* prev)
//returns tuple (status, ldns_rr, [line if ret_linenr], ttl, origin, prev)
{
int linenr = 0;
......@@ -174,13 +185,21 @@ typedef struct ldns_dnssec_zone { };
uint32_t *p_defttl = &defttl;
if (defttl == 0) p_defttl = 0;
/* origin and prev have to be cloned in order to decouple the data
* from the python wrapper
*/
if (origin != NULL)
origin = ldns_rdf_clone(origin);
if (prev != NULL)
prev = ldns_rdf_clone(prev);
ldns_rdf *p_origin = origin;
ldns_rdf **pp_origin = &p_origin;
if (p_origin == 0) pp_origin = 0;
//if (p_origin == 0) pp_origin = 0;
ldns_rdf *p_prev = prev;
ldns_rdf **pp_prev = &p_prev;
if (p_prev == 0) pp_prev = 0;
//if (p_prev == 0) pp_prev = 0;
ldns_rr *p_rr = 0;
ldns_rr **pp_rr = &p_rr;
......@@ -188,35 +207,38 @@ typedef struct ldns_dnssec_zone { };
ldns_status st = ldns_rr_new_frm_fp_l(pp_rr, fp, p_defttl, pp_origin, pp_prev, p_linenr);
PyObject* tuple;
tuple = PyTuple_New(ret_linenr ? 6 : 5);
tuple = PyTuple_New(6);
int idx = 0;
PyTuple_SetItem(tuple, idx, SWIG_From_int(st));
idx++;
PyTuple_SetItem(tuple, idx, (st == LDNS_STATUS_OK) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_rr), SWIGTYPE_p_ldns_struct_rr, SWIG_POINTER_OWN | 0 ) :
Py_None);
(Py_INCREF(Py_None), Py_None));
idx++;
if (ret_linenr) {
PyTuple_SetItem(tuple, idx, SWIG_From_int(linenr));
idx++;
}
PyTuple_SetItem(tuple, idx, (defttl != default_ttl) ? SWIG_From_int(defttl) : Py_None);
PyTuple_SetItem(tuple, idx, SWIG_From_int(defttl));
idx++;
PyTuple_SetItem(tuple, idx, (p_origin != origin) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_origin), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 ) :
Py_None);
PyTuple_SetItem(tuple, idx, SWIG_NewPointerObj(SWIG_as_voidptr(p_origin), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 ));
idx++;
PyTuple_SetItem(tuple, idx, (p_prev != prev) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_prev), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 ) :
Py_None);
PyTuple_SetItem(tuple, idx, SWIG_NewPointerObj(SWIG_as_voidptr(p_prev), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 ));
return tuple;
}
PyObject* ldns_rr_new_question_frm_str_(const char *str, ldns_rdf* origin, ldns_rdf* prev)
PyObject* ldns_rr_new_question_frm_str_(const char *str, ldns_rdf* origin, ldns_rdf* prev)
//returns tuple (status, ldns_rr, prev)
{
PyObject* tuple;
/* origin and prev have to be cloned in order to decouple the data
* from the python wrapper
*/
if (origin != NULL)
origin = ldns_rdf_clone(origin);
if (prev != NULL)
prev = ldns_rdf_clone(prev);
ldns_rdf *p_prev = prev;
ldns_rdf **pp_prev = &p_prev;
if (p_prev == 0) pp_prev = 0;
......@@ -230,10 +252,10 @@ typedef struct ldns_dnssec_zone { };
PyTuple_SetItem(tuple, 0, SWIG_From_int(st));
PyTuple_SetItem(tuple, 1, (st == LDNS_STATUS_OK) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_rr), SWIGTYPE_p_ldns_struct_rr, SWIG_POINTER_OWN | 0 ) :
Py_None);
(Py_INCREF(Py_None), Py_None));
PyTuple_SetItem(tuple, 2, (p_prev != prev) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_prev), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 ) :
Py_None);
(Py_INCREF(Py_None), Py_None));
return tuple;
}
......@@ -254,14 +276,70 @@ PyObject* ldns_fetch_valid_domain_keys_(const ldns_resolver * res, const ldns_rd
PyTuple_SetItem(tuple, 0, SWIG_From_int(st));
PyTuple_SetItem(tuple, 1, (st == LDNS_STATUS_OK) ?
SWIG_NewPointerObj(SWIG_as_voidptr(rrl), SWIGTYPE_p_ldns_struct_rr_list, SWIG_POINTER_OWN | 0 ) :
Py_None);
(Py_INCREF(Py_None), Py_None));
return tuple;
}
PyObject* ldns_wire2pkt_(const char *str, int len)
//returns tuple (status, result)
{
PyObject *resultobj = 0;
ldns_pkt *arg1 = NULL;
uint8_t *arg2 = (uint8_t *) str;
size_t arg3 = (size_t) len;
ldns_status result;
PyObject* tuple;
result = (ldns_status)ldns_wire2pkt(&arg1,arg2,arg3);
tuple = PyTuple_New(2);
PyTuple_SetItem(tuple, 0, SWIG_From_int(result));
if (result == LDNS_STATUS_OK)
PyTuple_SetItem(tuple, 1, SWIG_NewPointerObj(SWIG_as_voidptr(arg1), SWIGTYPE_p_ldns_struct_pkt, SWIG_POINTER_OWN | 0 ));
else {
Py_INCREF(Py_None);
PyTuple_SetItem(tuple, 1, Py_None);
}
return tuple;
}
%}
%pythoncode %{
def ldns_fetch_valid_domain_keys(res, domain, keys):
return _ldns.ldns_fetch_valid_domain_keys_(res, domain, keys)
%}
def ldns_wire2pkt(data):
return _ldns.ldns_wire2pkt_(data)
def ldns_rr_iter_frm_fp_l(input_file):
"""Creates an iterator (generator) that returns individual parsed
RRs from an open zone file."""
# variables that preserve the parsers state
my_ttl = 0;
my_origin = None
my_prev = None
# additional state variables
last_pos = 0
line_nr = 0
while True:
ret = _ldns.ldns_rr_new_frm_fp_l_(input_file, my_ttl, my_origin, my_prev)
s, rr, line_inc, new_ttl, new_origin, new_prev = ret # unpack the result
line_nr += line_inc # increase number of parsed lines
my_prev = new_prev # update ref to previous owner
if s == _ldns.LDNS_STATUS_SYNTAX_TTL:
my_ttl = new_ttl # update default TTL
elif s == _ldns.LDNS_STATUS_SYNTAX_ORIGIN:
my_origin = new_origin # update reference to origin
elif s == _ldns.LDNS_STATUS_SYNTAX_EMPTY:
if last_pos == input_file.tell():
break # no advance since last read - EOF
last_pos = input_file.tell()
elif s != _ldns.LDNS_STATUS_OK:
raise ValueError("Parse error in line %d" % line_nr)
else:
# we are sure to have LDNS_STATUS_OK
yield rr
%}
......@@ -51,6 +51,10 @@
%newobject ldns_dname_new_frm_data;
%newobject ldns_dname_label;
# limit the number of arguments to 2 and
# deal with variable number of arguments the Python way
%varargs(2, char *arg = NULL) ldns_buffer_printf;
%rename(ldns_buffer) ldns_struct_buffer;
#ifdef LDNS_DEBUG
......@@ -232,14 +236,15 @@ void _ldns_buffer_free (ldns_buffer* b) {
#parameters: ldns_buffer *,
#retvals: size_t
def printf(self,*str):
def printf(self, str, *args):
"""Prints to the buffer, increasing the capacity if required using buffer_reserve().
The buffer's position is set to the terminating '\0'. Returns the number of characters written (not including the terminating '\0') or -1 on failure.
:param str: a string
:returns: (int)
"""
return _ldns.ldns_buffer_printf(self,*str)
data = str % args
return _ldns.ldns_buffer_printf(self,data)
#parameters: ldns_buffer *,const char *,...
#retvals: int
......
......@@ -41,12 +41,14 @@
$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr($1_pkt), SWIGTYPE_p_ldns_struct_pkt, SWIG_POINTER_OWN | 0 ));
}
%newobject ldns_pkt_new;
%newobject ldns_pkt_clone;
%newobject ldns_pkt_rr_list_by_type;
%newobject ldns_pkt_rr_list_by_name_and_type;
%newobject ldns_pkt_rr_list_by_name;
%newobject ldns_update_pkt_new;
%nodefaultctor ldns_struct_pkt; //no default constructor & destructor
%nodefaultdtor ldns_struct_pkt;
......@@ -69,9 +71,57 @@ void _ldns_pkt_free (ldns_pkt* p) {
%newobject ldns_pkt_algorithm2str;
%newobject ldns_pkt_cert_algorithm2str;
%exception ldns_pkt_push_rr(ldns_pkt *packet, ldns_pkt_section section, ldns_rr *rr) %{ $action if (result) Py_INCREF(obj2); %}
%exception ldns_pkt_push_rr_list(ldns_pkt *packet, ldns_pkt_section section, ldns_rr_list *list) %{ $action if (result) Py_INCREF(obj2); %}
/* cloning of packet_lists to make them independent of the original packet */
%newobject _ldns_pkt_additional;
%newobject _ldns_pkt_answer;
%newobject _ldns_pkt_authority;
%newobject _ldns_pkt_question;
%rename(__ldns_pkt_additional) ldns_pkt_additional;
%inline %{
ldns_rr_list* _ldns_pkt_additional(ldns_pkt* p) {
return ldns_rr_list_clone(ldns_pkt_additional(p));
}
%}
%rename(__ldns_pkt_answer) ldns_pkt_answer;
%inline %{
ldns_rr_list* _ldns_pkt_answer(ldns_pkt* p) {
return ldns_rr_list_clone(ldns_pkt_answer(p));
}
%}
%rename(__ldns_pkt_authority) ldns_pkt_authority;
%inline %{
ldns_rr_list* _ldns_pkt_authority(ldns_pkt* p) {
return ldns_rr_list_clone(ldns_pkt_authority(p));
}
%}
%rename(__ldns_pkt_question) ldns_pkt_question;
%inline %{
ldns_rr_list* _ldns_pkt_question(ldns_pkt* p) {