From: Karel Slany Date: Tue, 10 Sep 2013 13:22:41 +0000 (+0200) Subject: pyLDNS: Added new method ldns_rdf.data_as_bytearray(). X-Git-Tag: release-1.6.17rc1~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=512b12e6abb25bd169c91dcdbd02191dd9c95b99;p=thirdparty%2Fldns.git pyLDNS: Added new method ldns_rdf.data_as_bytearray(). The new method returns the content of the data section in a bytearray. --- diff --git a/contrib/python/Changelog b/contrib/python/Changelog index 25bb2a08..07e57ba9 100644 --- a/contrib/python/Changelog +++ b/contrib/python/Changelog @@ -1,4 +1,6 @@ 1.7.0 + * Added ldns_rdf.data_as_bytearray(). The method returns a bytearray object + containing rdf data. * Changed the behaviour of ldns_resolver.trusted_key() in order to prevent memory corrupotion and leaks. * Fixed memory leaks when destroying ldns_resolver. diff --git a/contrib/python/examples/test_rdf.py b/contrib/python/examples/test_rdf.py index 61a56c62..2e2b73b6 100755 --- a/contrib/python/examples/test_rdf.py +++ b/contrib/python/examples/test_rdf.py @@ -406,6 +406,20 @@ if True: set_error() +#if not error_detected: +if True: + method_name = "ldns_rdf.data_as_bytearray()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf.data_as_bytearray() + if not isinstance(ret, bytearray): + set_error() + if len(ret) != 12: + set_error() + except: + set_error() + + #if not error_detected: if True: method_name = "ldns_rdf.dname_compare()" diff --git a/contrib/python/ldns_rdf.i b/contrib/python/ldns_rdf.i index 2464b45f..9bd32727 100644 --- a/contrib/python/ldns_rdf.i +++ b/contrib/python/ldns_rdf.i @@ -228,6 +228,26 @@ %} +%inline +%{ + /*! + * @brief Returns the rdf data organised into a list of bytes. + */ + PyObject * ldns_rdf_data_as_bytearray(const ldns_rdf *rdf) + { + Py_ssize_t len; + uint8_t *data; + + assert(rdf != NULL); + + len = ldns_rdf_size(rdf); + data = ldns_rdf_data(rdf); + + return PyByteArray_FromStringAndSize((char *) data, len); + } +%} + + /* ========================================================================= */ /* Encapsulating Python code. */ /* ========================================================================= */ @@ -468,6 +488,16 @@ specified in the (16-bit) type field with a value from ldns_rdf_type." #parameters: const ldns_rdf *, #retvals: uint8_t * + def data_as_bytearray(self): + """ + Returns the data of the rdf as a bytearray. + + :return: (bytearray) Bytearray containing the rdf data. + """ + return _ldns.ldns_rdf_data_as_bytearray(self) + #parameters: const ldns_rdf *, + #retvals: bytearray + def get_type(self): """ Returns the type of the rdf.