]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
pyLDNS: Added new method ldns_rdf.data_as_bytearray().
authorKarel Slany <karel.slany@nic.cz>
Tue, 10 Sep 2013 13:22:41 +0000 (15:22 +0200)
committerKarel Slany <karel.slany@nic.cz>
Tue, 10 Sep 2013 13:22:41 +0000 (15:22 +0200)
The new method returns the content of the data section in a bytearray.

contrib/python/Changelog
contrib/python/examples/test_rdf.py
contrib/python/ldns_rdf.i

index 25bb2a08e9b7ec2df79968ff99910da4a42faf9c..07e57ba9f5e7304759aae59c63b0fd82eda26c86 100644 (file)
@@ -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.
index 61a56c623eb0416ca4b5439b783772278b2d0669..2e2b73b6b751e3816f113a53845d49d6a4f6d793 100755 (executable)
@@ -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()"
index 2464b45f6826f73a4b366c3190e9fb5e7141a79b..9bd327274af255be2b1f169178c4b77c9d5eb97f 100644 (file)
 %}
 
 
+%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.