1 /******************************************************************************
2 * ldns_rr.i: LDNS resource records (RR), RR list
4 * Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz)
5 * Karel Slany (slany AT fit.vutbr.cz)
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * * Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of the organization nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *****************************************************************************/
34 /* ========================================================================= */
35 /* SWIG setting and definitions. */
36 /* ========================================================================= */
38 /* Creates a temporary instance of (ldns_rr *). */
39 %typemap(in, numinputs=0, noblock=1) (ldns_rr **)
45 /* Result generation, appends (ldns_rr *) after the result. */
46 %typemap(argout, noblock=1) (ldns_rr **)
48 $result = SWIG_Python_AppendOutput($result,
49 SWIG_NewPointerObj(SWIG_as_voidptr($1_rr),
50 SWIGTYPE_p_ldns_struct_rr, SWIG_POINTER_OWN | 0 ));
53 %nodefaultctor ldns_struct_rr; /* No default constructor. */
54 %nodefaultdtor ldns_struct_rr; /* No default destructor. */
56 %ignore ldns_struct_rr::_rdata_fields;
58 %newobject ldns_rr_clone;
59 %newobject ldns_rr_new;
60 %newobject ldns_rr_new_frm_type;
61 %newobject ldns_rr_pop_rdf;
62 %delobject ldns_rr_free;
64 %rename(ldns_rr) ldns_struct_rr;
66 %newobject ldns_rr2str;
67 %newobject ldns_rr_type2str;
68 %newobject ldns_rr_class2str;
69 %newobject ldns_read_anchor_file;
72 /* Clone rdf data on pull. */
74 /* Clone will fail with NULL argument. */
76 %newobject _ldns_rr_rdf;
77 %rename(__ldns_rr_rdf) ldns_rr_rdf;
80 ldns_rdf * _ldns_rr_rdf(ldns_rr *rr, size_t i)
83 rdf = ldns_rr_rdf(rr, i);
84 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
88 %newobject _ldns_rr_rrsig_algorithm;
89 %rename(__ldns_rr_rrsig_algorithm) ldns_rr_rrsig_algorithm;
92 ldns_rdf * _ldns_rr_rrsig_algorithm(ldns_rr *rr) {
94 rdf = ldns_rr_rrsig_algorithm(rr);
95 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
99 %newobject _ldns_rr_dnskey_algorithm;
100 %rename(__ldns_rr_dnskey_algorithm) ldns_rr_dnskey_algorithm;
103 ldns_rdf * _ldns_rr_dnskey_algorithm(ldns_rr *rr)
106 rdf = ldns_rr_dnskey_algorithm(rr);
107 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
111 %newobject _ldns_rr_dnskey_flags;
112 %rename(__ldns_rr_dnskey_flags) ldns_rr_dnskey_flags;
115 ldns_rdf * _ldns_rr_dnskey_flags(ldns_rr *rr)
118 rdf = ldns_rr_dnskey_flags(rr);
119 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
123 %newobject _ldns_rr_dnskey_key;
124 %rename(__ldns_rr_dnskey_key) ldns_rr_dnskey_key;
127 ldns_rdf * _ldns_rr_dnskey_key(ldns_rr *rr)
130 rdf = ldns_rr_dnskey_key(rr);
131 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
135 %newobject _ldns_rr_dnskey_protocol;
136 %rename(__ldns_rr_dnskey_protocol) ldns_rr_dnskey_protocol;
139 ldns_rdf * _ldns_rr_dnskey_protocol(ldns_rr *rr)
142 rdf = ldns_rr_dnskey_protocol(rr);
143 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
148 %newobject _ldns_rr_owner;
149 %rename(__ldns_rr_owner) ldns_rr_owner;
152 ldns_rdf * _ldns_rr_owner(ldns_rr *rr)
155 rdf = ldns_rr_owner(rr);
156 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
161 %newobject _ldns_rr_a_address;
162 %rename(__ldns_rr_a_address) ldns_rr_a_address;
165 ldns_rdf * _ldns_rr_a_address(ldns_rr *rr)
168 rdf = ldns_rr_a_address(rr);
169 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
174 %newobject _ldns_rr_mx_exchange;
175 %rename(__ldns_rr_mx_exchange) ldns_rr_mx_exchange;
178 ldns_rdf * _ldns_rr_mx_exchange(ldns_rr *rr)
181 rdf = ldns_rr_mx_exchange(rr);
182 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
187 %newobject _ldns_rr_mx_preference;
188 %rename(__ldns_rr_mx_preference) ldns_rr_mx_preference;
191 ldns_rdf * _ldns_rr_mx_preference(ldns_rr *rr)
194 rdf = ldns_rr_mx_preference(rr);
195 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
200 %newobject _ldns_rr_ns_nsdname;
201 %rename(__ldns_rr_ns_nsdname) ldns_rr_ns_nsdname;
204 ldns_rdf * _ldns_rr_ns_nsdname(ldns_rr *rr)
207 rdf = ldns_rr_ns_nsdname(rr);
208 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
213 %newobject _ldns_rr_rrsig_expiration;
214 %rename(__ldns_rr_rrsig_expiration) ldns_rr_rrsig_expiration;
217 ldns_rdf * _ldns_rr_rrsig_expiration(ldns_rr *rr)
220 rdf = ldns_rr_rrsig_expiration(rr);
221 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
226 %newobject _ldns_rr_rrsig_inception;
227 %rename(__ldns_rr_rrsig_inception) ldns_rr_rrsig_inception;
230 ldns_rdf * _ldns_rr_rrsig_inception(ldns_rr *rr)
233 rdf = ldns_rr_rrsig_inception(rr);
234 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
239 %newobject _ldns_rr_rrsig_keytag;
240 %rename(__ldns_rr_rrsig_keytag) ldns_rr_rrsig_keytag;
243 ldns_rdf * _ldns_rr_rrsig_keytag(ldns_rr *rr)
246 rdf = ldns_rr_rrsig_keytag(rr);
247 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
252 %newobject _ldns_rr_rrsig_labels;
253 %rename(__ldns_rr_rrsig_labels) ldns_rr_rrsig_labels;
256 ldns_rdf * _ldns_rr_rrsig_labels(ldns_rr *rr)
259 rdf = ldns_rr_rrsig_labels(rr);
260 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
265 %newobject _ldns_rr_rrsig_origttl;
266 %rename(__ldns_rr_rrsig_origttl) ldns_rr_rrsig_origttl;
269 ldns_rdf * _ldns_rr_rrsig_origttl(ldns_rr *rr)
272 rdf = ldns_rr_rrsig_origttl(rr);
273 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
278 %newobject _ldns_rr_rrsig_sig;
279 %rename(__ldns_rr_rrsig_sig) ldns_rr_rrsig_sig;
282 ldns_rdf * _ldns_rr_rrsig_sig(ldns_rr *rr)
285 rdf = ldns_rr_rrsig_sig(rr);
286 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
291 %newobject _ldns_rr_rrsig_signame;
292 %rename(__ldns_rr_rrsig_signame) ldns_rr_rrsig_signame;
295 ldns_rdf * _ldns_rr_rrsig_signame(ldns_rr *rr)
298 rdf = ldns_rr_rrsig_signame(rr);
299 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
304 %newobject _ldns_rr_rrsig_typecovered;
305 %rename(__ldns_rr_rrsig_typecovered) ldns_rr_rrsig_typecovered;
308 ldns_rdf * _ldns_rr_rrsig_typecovered(ldns_rr *rr)
311 rdf = ldns_rr_rrsig_typecovered(rr);
312 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
316 /* End of pull cloning. */
318 /* Clone rdf data on push. */
320 %rename(__ldns_rr_a_set_address) ldns_rr_a_set_address;
323 bool _ldns_rr_a_set_address(ldns_rr *rr, ldns_rdf *rdf)
325 return ldns_rr_a_set_address(rr, ldns_rdf_clone(rdf));
329 %rename(__ldns_rr_dnskey_set_algorithm) ldns_rr_dnskey_set_algorithm;
332 bool _ldns_rr_dnskey_set_algorithm(ldns_rr *rr, ldns_rdf *rdf)
334 return ldns_rr_dnskey_set_algorithm(rr, ldns_rdf_clone(rdf));
338 %rename(__ldns_rr_dnskey_set_flags) ldns_rr_dnskey_set_flags;
341 bool _ldns_rr_dnskey_set_flags(ldns_rr *rr, ldns_rdf *rdf)
343 return ldns_rr_dnskey_set_flags(rr, ldns_rdf_clone(rdf));
347 %rename(__ldns_rr_dnskey_set_key) ldns_rr_dnskey_set_key;
350 bool _ldns_rr_dnskey_set_key(ldns_rr *rr, ldns_rdf *rdf)
352 return ldns_rr_dnskey_set_key(rr, ldns_rdf_clone(rdf));
356 %rename(__ldns_rr_dnskey_set_protocol) ldns_rr_dnskey_set_protocol;
359 bool _ldns_rr_dnskey_set_protocol(ldns_rr *rr, ldns_rdf *rdf)
361 return ldns_rr_dnskey_set_protocol(rr, ldns_rdf_clone(rdf));
365 %rename(__ldns_rr_push_rdf) ldns_rr_push_rdf;
368 bool _ldns_rr_push_rdf(ldns_rr *rr, ldns_rdf *rdf)
370 return ldns_rr_push_rdf(rr, ldns_rdf_clone(rdf));
374 %rename(__ldns_rr_rrsig_set_algorithm) ldns_rr_rrsig_set_algorithm;
377 bool _ldns_rr_rrsig_set_algorithm(ldns_rr *rr, ldns_rdf *rdf)
379 return ldns_rr_rrsig_set_algorithm(rr, ldns_rdf_clone(rdf));
383 %rename(__ldns_rr_rrsig_set_expiration) ldns_rr_rrsig_set_expiration;
386 bool _ldns_rr_rrsig_set_expiration(ldns_rr *rr, ldns_rdf *rdf)
388 return ldns_rr_rrsig_set_expiration(rr, ldns_rdf_clone(rdf));
392 %rename(__ldns_rr_rrsig_set_inception) ldns_rr_rrsig_set_inception;
395 bool _ldns_rr_rrsig_set_inception(ldns_rr *rr, ldns_rdf *rdf)
397 return ldns_rr_rrsig_set_inception(rr, ldns_rdf_clone(rdf));
401 %rename(__ldns_rr_rrsig_set_keytag) ldns_rr_rrsig_set_keytag;
404 bool _ldns_rr_rrsig_set_keytag(ldns_rr *rr, ldns_rdf *rdf)
406 return ldns_rr_rrsig_set_keytag(rr, ldns_rdf_clone(rdf));
410 %rename(__ldns_rr_rrsig_set_labels) ldns_rr_rrsig_set_labels;
413 bool _ldns_rr_rrsig_set_labels(ldns_rr *rr, ldns_rdf *rdf)
415 return ldns_rr_rrsig_set_labels(rr, ldns_rdf_clone(rdf));
419 %rename(__ldns_rr_rrsig_set_origttl) ldns_rr_rrsig_set_origttl;
422 bool _ldns_rr_rrsig_set_origttl(ldns_rr *rr, ldns_rdf *rdf)
424 return ldns_rr_rrsig_set_origttl(rr, ldns_rdf_clone(rdf));
428 %rename(__ldns_rr_rrsig_set_sig) ldns_rr_rrsig_set_sig;
431 bool _ldns_rr_rrsig_set_sig(ldns_rr *rr, ldns_rdf *rdf) {
432 return ldns_rr_rrsig_set_sig(rr, ldns_rdf_clone(rdf));
436 %rename(__ldns_rr_rrsig_set_signame) ldns_rr_rrsig_set_signame;
439 bool _ldns_rr_rrsig_set_signame(ldns_rr *rr, ldns_rdf *rdf)
441 return ldns_rr_rrsig_set_signame(rr, ldns_rdf_clone(rdf));
445 %rename(__ldns_rr_rrsig_set_typecovered) ldns_rr_rrsig_set_typecovered;
448 bool _ldns_rr_rrsig_set_typecovered(ldns_rr *rr, ldns_rdf *rdf)
450 return ldns_rr_rrsig_set_typecovered(rr, ldns_rdf_clone(rdf));
454 %rename(__ldns_rr_set_owner) ldns_rr_set_owner;
457 void _ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *rdf)
459 return ldns_rr_set_owner(rr, ldns_rdf_clone(rdf));
463 %newobject _ldns_rr_set_rdf;
464 %rename(__ldns_rr_set_rdf) ldns_rr_set_rdf;
467 ldns_rdf * _ldns_rr_set_rdf(ldns_rr *rr, ldns_rdf *rdf, size_t pos)
469 /* May leak memory on unsuccessful calls. */
472 new = ldns_rdf_clone(rdf);
474 if ((ret = ldns_rr_set_rdf(rr, new, pos)) == NULL) {
475 ldns_rdf_deep_free(new);
482 /* End of push cloning. */
484 %rename(_ldns_rr_new_frm_str) ldns_rr_new_frm_str;
485 %rename(_ldns_rr_new_frm_fp_l) ldns_rr_new_frm_fp_l;
486 %rename(_ldns_rr_new_frm_fp) ldns_rr_new_frm_fp;
489 /* ========================================================================= */
490 /* Debugging related code. */
491 /* ========================================================================= */
495 %rename(__ldns_rr_free) ldns_rr_free;
497 void _ldns_rr_free (ldns_rr *r)
499 printf("******** LDNS_RR free 0x%lX ************\n", (long unsigned int)r);
503 #else /* !LDNS_DEBUG */
504 %rename(_ldns_rr_free) ldns_rr_free;
505 #endif /* LDNS_DEBUG */
508 /* ========================================================================= */
510 /* ========================================================================= */
515 /* ========================================================================= */
516 /* Encapsulating Python code. */
517 /* ========================================================================= */
520 %feature("docstring") ldns_struct_rr "Resource Record (RR).
522 The RR is the basic DNS element that contains actual data. This class allows
523 to create RR and manipulate with the content.
525 Use :meth:`ldns_rr_new`, :meth:`ldns_rr_new_frm_type`, :meth:`new_frm_fp`,
526 :meth:`new_frm_fp_l`, :meth:`new_frm_str` or :meth:`new_question_frm_str`
527 to create :class:`ldns_rr` instances.
530 %extend ldns_struct_rr {
535 raise Exception("This class can't be created directly. " +
536 "Please use: ldns_rr_new(), ldns_rr_new_frm_type(), " +
537 "new_frm_fp(), new_frm_fp_l(), new_frm_str() or " +
538 "new_question_frm_str()")
540 __swig_destroy__ = _ldns._ldns_rr_free
543 # LDNS_RR_CONSTRUCTORS_
547 def new_frm_str(string, default_ttl=0, origin=None, prev=None, raiseException=True):
549 Creates an rr object from a string.
551 The string should be a fully filled-in rr, like "owner_name
552 [space] TTL [space] CLASS [space] TYPE [space] RDATA."
554 :param string: The string to convert.
556 :param default_ttl: Default ttl value for the rr.
557 If 0 DEF_TTL will be used.
558 :type default_ttl: int
559 :param origin: When the owner is relative add this.
560 :type origin: :class:`ldns_dname`
561 :param prev: The previous owner name.
562 :type prev: :class:`ldns_rdf`
563 :param raiseException: If True, an exception occurs in case a rr
564 instance can't be created.
565 :throws Exception: If `raiseExceprion` is set and fails.
566 :throws TypeError: When parameters of incorrect types.
567 :return: (:class:`ldns_rr`) RR instance or None.
570 The type checking of `origin` is benevolent.
571 It allows also to pass a dname :class:`ldns_rdf` object.
572 This will probably change in future.
577 >>> rr = ldns.ldns_rr.new_frm_str("www.nic.cz. IN A 192.168.1.1", 300)
579 www.nic.cz. 300 IN A 192.168.1.1
580 >>> rr = ldns.ldns_rr.new_frm_str("test.nic.cz. 600 IN A 192.168.1.2")
582 test.nic.cz. 600 IN A 192.168.1.2
585 if (not isinstance(origin, ldns_dname)) and \
586 isinstance(origin, ldns_rdf) and \
587 origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
588 warnings.warn("The ldns_rr.new_frm_str() method will" +
589 " drop the possibility to accept ldns_rdf as origin." +
590 " Convert argument to ldns_dname.",
591 PendingDeprecationWarning, stacklevel=2)
592 status, rr, prev = _ldns.ldns_rr_new_frm_str_(string, default_ttl,
594 if status != LDNS_STATUS_OK:
596 raise Exception("Can't create RR, error: %d" % status)
601 def new_question_frm_str(string, default_ttl=0, origin=None, prev=None, raiseException=True):
603 Creates an rr object from a string.
605 The string is like :meth:`new_frm_str` but without rdata.
607 :param string: The string to convert.
609 :param origin: When the owner is relative add this.
610 :type origin: :class:`ldns_dname`
611 :param prev: The previous owner name.
612 :type prev: :class:`ldns_rdf`
613 :param raiseException: If True, an exception occurs in case
614 a rr instance can't be created.
615 :throws Exception: If `raiseExceprion` is set and fails.
616 :throws TypeError: When parameters of incorrect types.
617 :return: (:class:`ldns_rr`) RR instance or None. If the object
618 can't be created and `raiseException` is True,
622 The type checking of `origin` is benevolent.
623 It allows also to pass a dname :class:`ldns_rdf` object.
624 This will probably change in future.
626 if (not isinstance(origin, ldns_dname)) and \
627 isinstance(origin, ldns_rdf) and \
628 origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
629 warnings.warn("The ldns_rr.new_question_frm_str() method will" +
630 " drop the possibility to accept ldns_rdf as origin." +
631 " Convert argument to ldns_dname.",
632 PendingDeprecationWarning, stacklevel=2)
633 status, rr, prev = _ldns.ldns_rr_new_question_frm_str_(string,
635 if status != LDNS_STATUS_OK:
637 raise Exception("Can't create RR, error: %d" % status)
642 def new_frm_str_prev(string, default_ttl=0, origin=None, prev=None, raiseException=True):
644 Creates an rr object from a string.
646 The string should be a fully filled-in rr, like "owner_name
647 [space] TTL [space] CLASS [space] TYPE [space] RDATA".
649 :param string: The string to convert.
651 :param default_ttl: Default ttl value for the rr.
652 If 0 DEF_TTL will be used.
653 :type default_ttl: int
654 :param origin: When the owner is relative add this.
655 :type origin: :class:`ldns_dname`
656 :param prev: The previous owner name.
657 :type prev: :class:`ldns_rdf`
658 :param raiseException: If True, an exception occurs in case when
659 a rr instance can't be created.
660 :throws Exception: If `raiseExceprion` is set and fails.
661 :throws TypeError: When parameters of incorrect types.
662 :return: None when fails, otherwise a tuple containing:
664 * rr - (:class:`ldns_rr`) RR instance or None.
665 If the object can't be created and `raiseException`
666 is True, an exception occurs.
668 * prev - (:class:`ldns_rdf`) Owner name found in this string
672 The type checking of `origin` is benevolent.
673 It allows also to pass a dname :class:`ldns_rdf` object.
674 This will probably change in future.
676 if (not isinstance(origin, ldns_dname)) and \
677 isinstance(origin, ldns_rdf) and \
678 origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
679 warnings.warn("The ldns_rr.new_frm_str_prev() method will" +
680 " drop the possibility to accept ldns_rdf as origin." +
681 " Convert argument to ldns_dname.",
682 PendingDeprecationWarning, stacklevel=2)
683 status, rr, prev = _ldns.ldns_rr_new_frm_str_(string, default_ttl,
685 if status != LDNS_STATUS_OK:
687 raise Exception("Can't create RR, error: %d" % status)
692 def new_frm_fp(file, default_ttl=0, origin=None, prev=None, raiseException=True):
694 Creates a new rr from a file containing a string.
696 :param file: Opened file.
697 :param default_ttl: If 0 DEF_TTL will be used.
698 :type default_ttl: int
699 :param origin: When the owner is relative add this.
700 :type origin: :class:`ldns_dname`
701 :param prev: When the owner is white spaces use this.
702 :type prev: :class:`ldns_rdf`
703 :param raiseException: If True, an exception occurs in case
704 a resolver object can't be created.
705 :throws Exception: If `raiseException` is set and the input
707 :throws TypeError: When parameters of incorrect types.
708 :return: None when fails, otherwise a tuple containing:
710 * rr - (:class:`ldns_rr`) RR object or None. If the object
711 can't be created and `raiseException` is True,
714 * ttl - (int) None or TTL if the file contains a TTL
717 * origin - (:class:`ldns_rdf`) None or dname rdf if the file
718 contains a ORIGIN directive.
720 * prev - (:class:`ldns_rdf`) None or updated value
724 The type checking of `origin` is benevolent.
725 It allows also to pass a dname :class:`ldns_rdf` object.
726 This will probably change in future.
728 if (not isinstance(origin, ldns_dname)) and \
729 isinstance(origin, ldns_rdf) and \
730 origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
731 warnings.warn("The ldns_rr.new_frm_fp() method will" +
732 " drop the possibility to accept ldns_rdf as origin." +
733 " Convert argument to ldns_dname.",
734 PendingDeprecationWarning, stacklevel=2)
735 res = _ldns.ldns_rr_new_frm_fp_(file, default_ttl, origin, prev)
736 if res[0] != LDNS_STATUS_OK:
738 raise Exception("Can't create RR, error: %d" % res[0])
743 def new_frm_fp_l(file, default_ttl=0, origin=None, prev=None, raiseException=True):
745 Creates a new rr from a file containing a string.
747 :param file: Opened file.
748 :param default_ttl: If 0 DEF_TTL will be used.
749 :type default_ttl: int
750 :param origin: When the owner is relative add this.
751 :type origin: :class:`ldns_dname`
752 :param prev: When the owner is white spaces use this.
753 :type prev: :class:`ldns_rdf`
754 :param raiseException: Iif True, an exception occurs in case
755 a resolver object can't be created.
756 :throws Exception: If `raiseException` is set and the input
758 :throws TypeError: When parameters of incorrect types.
759 :return: None when fails, otherwise a tuple containing:
761 * rr - (:class:`ldns_rr`) RR object or None. If the object
762 can't be created and `raiseException` is True,
765 * line - (int) line number (for debugging).
767 * ttl - (int) None or TTL if the file contains a TTL
770 * origin - (:class:`ldns_rdf`) None or dname rdf if the file
771 contains a ORIGIN directive.
773 * prev - (:class:`ldns_rdf`) None or updated value of prev
777 The type checking of `origin` is benevolent.
778 It allows also to pass a dname :class:`ldns_rdf` object.
779 This will probably change in future.
781 if (not isinstance(origin, ldns_dname)) and \
782 isinstance(origin, ldns_rdf) and \
783 origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
784 warnings.warn("The ldns_rr.new_frm_fp_l() method will" +
785 " drop the possibility to accept ldns_rdf as origin." +
786 " Convert argument to ldns_dname.",
787 PendingDeprecationWarning, stacklevel=2)
788 res = _ldns.ldns_rr_new_frm_fp_l_(file, default_ttl, origin, prev)
789 if res[0] != LDNS_STATUS_OK:
791 raise Exception("Can't create RR, error: %d" % res[0])
796 # _LDNS_RR_CONSTRUCTORS
801 Converts the data in the resource record to presentation format.
805 return _ldns.ldns_rr2str(self)
807 def __cmp__(self, other):
811 The TTL is not looked at.
813 :param other: The second RR one.
814 :type other: :class:`ldns_rr`
815 :throws TypeError: When `other` of non-:class:`ldns_rr` type.
816 :return: (int) 0 if equal, -1 if `self` comes before `other`,
817 1 if `other` RR comes before `self`.
819 return _ldns.ldns_rr_compare(self, other)
821 def __lt__(self, other):
825 The TTL is not looked at.
827 :param other: The second RR one.
828 :type other: :class:`ldns_rr`
829 :throws TypeError: When `other` of non-:class:`ldns_rr` type.
830 :return: (bool) True when `self` is less than 'other'.
832 return _ldns.ldns_rr_compare(self, other) == -1
834 def __le__(self, other):
838 The TTL is not looked at.
840 :param other: The second RR one.
841 :type other: :class:`ldns_rr`
842 :throws TypeError: When `other` of non-:class:`ldns_rr` type.
843 :return: (bool) True when `self` is less than or equal to
846 return _ldns.ldns_rr_compare(self, other) != 1
848 def __eq__(self, other):
852 The TTL is not looked at.
854 :param other: The second RR one.
855 :type other: :class:`ldns_rr`
856 :throws TypeError: When `other` of non-:class:`ldns_rr` type.
857 :return: (bool) True when `self` is equal to 'other'.
859 return _ldns.ldns_rr_compare(self, other) == 0
861 def __ne__(self, other):
865 The TTL is not looked at.
867 :param other: The second RR one.
868 :type other: :class:`ldns_rr`
869 :throws TypeError: When `other` of non-:class:`ldns_rr` type.
870 :return: (bool) True when `self` is not equal to 'other'.
872 return _ldns.ldns_rr_compare(self, other) != 0
874 def __gt__(self, other):
878 The TTL is not looked at.
880 :param other: The second RR one.
881 :type other: :class:`ldns_rr`
882 :throws TypeError: When `other` of non-:class:`ldns_rr` type.
883 :return: (bool) True when `self` is greater than 'other'.
885 return _ldns.ldns_rr_compare(self, other) == 1
887 def __ge__(self, other):
891 The TTL is not looked at.
893 :param other: The second RR one.
894 :type other: :class:`ldns_rr`
895 :throws TypeError: When `other` of non-:class:`ldns_rr` type.
896 :return: (bool) True when `self` is greater than or equal to
899 return _ldns.ldns_rr_compare(self, other) != -1
902 def class_by_name(string):
904 Retrieves a class identifier value by looking up its name.
906 :param string: Class name.
908 :throws TypeError: when `string` of inappropriate type.
909 :return: (int) Class identifier value, or 0 if not valid
912 return _ldns.ldns_get_rr_class_by_name(string)
916 Returns a generator object of rdata records.
918 :return: Generator of :class:`ldns_rdf`.
920 for i in range(0, self.rd_count()):
923 def print_to_file(self, output):
925 Prints the data in the resource record to the given file stream
926 (in presentation format).
928 :param output: Opened file stream.
929 :throws TypeError: When `output` not a file.
931 _ldns.ldns_rr_print(output, self)
932 #parameters: FILE *, const ldns_rr *,
934 def get_type_str(self):
936 Converts an RR type value to its string representation,
937 and returns that string.
939 :return: (str) containing type identification.
941 return _ldns.ldns_rr_type2str(self.get_type())
942 #parameters: const ldns_rr_type,
944 def get_class_str(self):
946 Converts an RR class value to its string representation,
947 and returns that string.
949 :return: (str) containing class identification.
951 return _ldns.ldns_rr_class2str(self.get_class())
952 #parameters: const ldns_rr_class,
955 def dnskey_key_size_raw(keydata, len, alg):
957 Get the length of the keydata in bits.
959 :param keydata: Key raw data.
960 :type keydata: unsigned char \*
961 :param len: Number of bytes of `keydata`.
963 :param alg: Algorithm identifier.
964 :type alg: ldns_algorithm
966 :return: (size_t) The length of key data in bits.
968 return _ldns.ldns_rr_dnskey_key_size_raw(keydata, len, alg)
969 #parameters: const unsigned char *,const size_t,const ldns_algorithm,
972 def write_to_buffer(self,buffer,section):
974 Copies the rr data to the buffer in wire format.
976 :param buffer: Buffer to append the result to.
977 :type buffer: :class:`ldns_buffer`
978 :param section: The section in the packet this rr is supposed
979 to be in (to determine whether to add rdata or not).
981 :throws TypeError: when arguments of mismatching types passed.
982 :return: (ldns_status) ldns_status
984 return _ldns.ldns_rr2buffer_wire(buffer, self, section)
985 #parameters: ldns_buffer *,const ldns_rr *,int,
986 #retvals: ldns_status
988 def write_to_buffer_canonical(self,buffer,section):
990 Copies the rr data to the buffer in wire format, in canonical
991 format according to RFC3597 (every dname in rdata fields
992 of RR's mentioned in that RFC will be converted to lower-case).
994 :param buffer: Buffer to append the result to.
995 :type buffer: :class:`ldns_buffer`
996 :param section: The section in the packet this rr is supposed
997 to be in (to determine whether to add rdata or not).
999 :throws TypeError: when arguments of mismatching types passed.
1000 :return: (ldns_status) ldns_status
1002 return _ldns.ldns_rr2buffer_wire_canonical(buffer,self,section)
1003 #parameters: ldns_buffer *,const ldns_rr *,int,
1004 #retvals: ldns_status
1006 def write_data_to_buffer(self, buffer):
1008 Converts an rr's rdata to wire format, while excluding the
1009 owner name and all the stuff before the rdata.
1011 This is needed in DNSSEC key-tag calculation, the ds
1012 calculation from the key and maybe elsewhere.
1014 :param buffer: Buffer to append the result to.
1015 :type buffer: :class:`ldns_buffer`
1016 :throws TypeError: when `buffer` of non-:class:`ldns_buffer`
1018 :return: (ldns_status) ldns_status
1020 return _ldns.ldns_rr_rdata2buffer_wire(buffer,self)
1021 #parameters: ldns_buffer *, const ldns_rr *,
1022 #retvals: ldns_status
1024 def write_rrsig_to_buffer(self, buffer):
1026 Converts a rrsig to wire format BUT EXCLUDE the rrsig rdata.
1028 This is needed in DNSSEC verification.
1030 :param buffer: Buffer to append the result to.
1031 :type buffer: :class:`ldns_buffer`
1032 :throws TypeError: when `buffer` of non-:class:`ldns_buffer`
1034 :return: (ldns_status) ldns_status
1036 return _ldns.ldns_rrsig2buffer_wire(buffer,self)
1037 #parameters: ldns_buffer *,const ldns_rr *,
1038 #retvals: ldns_status
1044 def a_address(self):
1046 Returns the address rdf of a LDNS_RR_TYPE_A or LDNS_RR_TYPE_AAAA
1049 :return: (:class:`ldns_rdf`) with the address or None on
1052 return _ldns._ldns_rr_a_address(self)
1053 #parameters: const ldns_rr *,
1054 #retvals: ldns_rdf *
1056 def a_set_address(self, f):
1058 Sets the address of a LDNS_RR_TYPE_A or LDNS_RR_TYPE_AAAA rr.
1060 :param f: The address to be set.
1061 :type f: :class:`ldns_rdf`
1062 :throws TypeError: When `f` of non-:class:`ldns_rdf` type.
1063 :return: (bool) True on success, False otherwise.
1065 return _ldns._ldns_rr_a_set_address(self, f)
1066 #parameters: ldns_rr *, ldns_rdf *,
1071 Clones a rr and all its data.
1073 :return: (:class:`ldns_rr`) The new rr or None on failure.
1075 return _ldns.ldns_rr_clone(self)
1076 #parameters: const ldns_rr *,
1079 def compare_ds(self, rr2):
1081 Returns True if the given rr's are equal.
1083 Also returns True if one record is a DS that represents the
1084 same DNSKEY record as the other record.
1086 :param rr2: The second rr.
1087 :type rr2: :class:`ldns_rr`
1088 :throws TypeError: When `rr2` of non-:class:`ldns_rr` type.
1089 :return: (bool) True if equal otherwise False.
1091 return _ldns.ldns_rr_compare_ds(self, rr2)
1092 #parameters: const ldns_rr *, const ldns_rr *,
1095 def compare_no_rdata(self, rr2):
1097 Compares two rrs, up to the rdata.
1099 :param rr2: Rhe second rr.
1100 :type rr2: :class:`ldns_rr`
1101 :throws TypeError: When `rr2` of non-:class:`ldns_rr` type.
1102 :return: (int) 0 if equal, negative integer if `self` comes
1103 before `rr2`, positive integer if `rr2` comes before `self`.
1105 return _ldns.ldns_rr_compare_no_rdata(self, rr2)
1106 #parameters: const ldns_rr *, const ldns_rr *,
1109 def dnskey_algorithm(self):
1111 Returns the algorithm of a LDNS_RR_TYPE_DNSKEY rr.
1113 :return: (:class:`ldns_rdf`) with the algorithm or None
1116 return _ldns._ldns_rr_dnskey_algorithm(self)
1117 #parameters: const ldns_rr *,
1118 #retvals: ldns_rdf *
1120 def dnskey_flags(self):
1122 Returns the flags of a LDNS_RR_TYPE_DNSKEY rr.
1124 :return: (:class:`ldns_rdf`) with the flags or None on failure.
1126 return _ldns._ldns_rr_dnskey_flags(self)
1127 #parameters: const ldns_rr *,
1128 #retvals: ldns_rdf *
1130 def dnskey_key(self):
1132 Returns the key data of a LDNS_RR_TYPE_DNSKEY rr.
1134 :return: (:class:`ldns_rdf`) with the key data or None on
1137 return _ldns._ldns_rr_dnskey_key(self)
1138 #parameters: const ldns_rr *,
1139 #retvals: ldns_rdf *
1141 def dnskey_key_size(self):
1143 Get the length of the keydata in bits.
1145 :return: (size_t) the keysize in bits.
1147 return _ldns.ldns_rr_dnskey_key_size(self)
1148 #parameters: const ldns_rr *,
1151 def dnskey_protocol(self):
1153 Returns the protocol of a LDNS_RR_TYPE_DNSKEY rr.
1155 :return: (:class:`ldns_rdf`) with the protocol or None on
1158 return _ldns._ldns_rr_dnskey_protocol(self)
1159 #parameters: const ldns_rr *,
1160 #retvals: ldns_rdf *
1162 def dnskey_set_algorithm(self, f):
1164 Sets the algorithm of a LDNS_RR_TYPE_DNSKEY rr
1166 :param f: The algorithm to set.
1167 :type f: :class:`ldns_rdf`
1168 :throws TypeError: When `f` of non-:class:`ldns_rdf` type.
1169 :return: (bool) True on success, False otherwise.
1171 return _ldns._ldns_rr_dnskey_set_algorithm(self, f)
1172 #parameters: ldns_rr *, ldns_rdf *,
1175 def dnskey_set_flags(self, f):
1177 Sets the flags of a LDNS_RR_TYPE_DNSKEY rr.
1179 :param f: The flags to be set.
1180 :type f: :class:`ldns_rdf`
1181 :throws TypeError: When `f` of non-:class:`ldns_rdf` type.
1182 :return: (bool) True on success, False otherwise.
1184 return _ldns._ldns_rr_dnskey_set_flags(self, f)
1185 #parameters: ldns_rr *, ldns_rdf *,
1188 def dnskey_set_key(self, f):
1190 Sets the key data of a LDNS_RR_TYPE_DNSKEY rr.
1192 :param f: The key data to set.
1193 :type f: :class:`ldns_rdf`
1194 :throws TypeError: When `f` of non-:class:`ldns_rdf` type.
1195 :return: (bool) True on success, False otherwise.
1197 return _ldns._ldns_rr_dnskey_set_key(self, f)
1198 #parameters: ldns_rr *, ldns_rdf *,
1201 def dnskey_set_protocol(self,f):
1203 Sets the protocol of a LDNS_RR_TYPE_DNSKEY rr.
1205 :param f: The protocol to set.
1206 :type f: :class:`ldns_rdf`
1207 :throws TypeError: When `f` of non-:class:`ldns_rdf` type.
1208 :return: (bool) True on success, False otherwise.
1210 return _ldns._ldns_rr_dnskey_set_protocol(self,f)
1211 #parameters: ldns_rr *,ldns_rdf *,
1214 def get_class(self):
1216 Returns the class of the rr.
1218 :return: (int) The class identifier of the rr.
1220 return _ldns.ldns_rr_get_class(self)
1221 #parameters: const ldns_rr *,
1222 #retvals: ldns_rr_class
1226 Returns the type of the rr.
1228 :return: (int) The type identifier of the rr.
1230 return _ldns.ldns_rr_get_type(self)
1231 #parameters: const ldns_rr *,
1232 #retvals: ldns_rr_type
1234 def is_question(self):
1236 Returns the question flag of a rr structure.
1238 :return: (bool) True if question flag is set.
1240 return _ldns.ldns_rr_is_question(self)
1242 def label_count(self):
1244 Counts the number of labels of the owner name.
1246 :return: (int) The number of labels.
1248 return _ldns.ldns_rr_label_count(self)
1249 #parameters: ldns_rr *,
1252 def mx_exchange(self):
1254 Returns the mx host of a LDNS_RR_TYPE_MX rr.
1256 :return: (:class:`ldns_rdf`) with the name of the MX host
1259 return _ldns._ldns_rr_mx_exchange(self)
1260 #parameters: const ldns_rr *,
1261 #retvals: ldns_rdf *
1263 def mx_preference(self):
1265 Returns the mx preference of a LDNS_RR_TYPE_MX rr.
1267 :return: (:class:`ldns_rdf`) with the preference or None
1270 return _ldns._ldns_rr_mx_preference(self)
1271 #parameters: const ldns_rr *,
1272 #retvals: ldns_rdf *
1274 def ns_nsdname(self):
1276 Returns the name of a LDNS_RR_TYPE_NS rr.
1278 :return: (:class:`ldns_rdf`) A dname rdf with the name or
1281 return _ldns._ldns_rr_ns_nsdname(self)
1282 #parameters: const ldns_rr *,
1283 #retvals: ldns_rdf *
1287 Returns the owner name of an rr structure.
1289 :return: (:class:`ldns_dname`) Owner name or None on failure.
1291 rdf = _ldns._ldns_rr_owner(self)
1293 rdf = ldns_dname(rdf, clone=False)
1295 #parameters: const ldns_rr *,
1296 #retvals: ldns_rdf *
1300 Removes a rd_field member, it will be popped from the last
1303 :return: (:class:`ldns_rdf`) rdf which was popped, None if
1306 return _ldns.ldns_rr_pop_rdf(self)
1307 #parameters: ldns_rr *,
1308 #retvals: ldns_rdf *
1310 def push_rdf(self,f):
1312 Sets rd_field member, it will be placed in the next available
1315 :param f: The rdf to be appended.
1316 :type f: :class:`ldns_rdf`
1317 :throws TypeError: When `f` of non-:class:`ldns_rdf` type.
1318 :return: (bool) Returns True if success, False otherwise.
1320 return _ldns._ldns_rr_push_rdf(self, f)
1321 #parameters: ldns_rr *, const ldns_rdf *,
1326 Returns the rd_count of an rr structure.
1328 :return: (size_t) the rd count of the rr.
1330 return _ldns.ldns_rr_rd_count(self)
1331 #parameters: const ldns_rr *,
1336 Returns the rdata field with the given index.
1338 :param nr: The index of the rdf to return.
1339 :type nr: positive int
1340 :throws TypeError: When `nr` not a positive integer.
1341 :return: (:class:`ldns_rdf`) The given rdf or None if fails.
1343 return _ldns._ldns_rr_rdf(self, nr)
1344 #parameters: const ldns_rr *, size_t,
1345 #retvals: ldns_rdf *
1347 def rrsig_algorithm(self):
1349 Returns the algorithm identifier of a LDNS_RR_TYPE_RRSIG RR.
1351 :return: (:class:`ldns_rdf`) with the algorithm or None
1354 return _ldns._ldns_rr_rrsig_algorithm(self)
1355 #parameters: const ldns_rr *,
1356 #retvals: ldns_rdf *
1358 def rrsig_expiration(self):
1360 Returns the expiration time of a LDNS_RR_TYPE_RRSIG RR.
1362 :return: (:class:`ldns_rdf`) with the expiration time or None
1365 return _ldns._ldns_rr_rrsig_expiration(self)
1366 #parameters: const ldns_rr *,
1367 #retvals: ldns_rdf *
1369 def rrsig_inception(self):
1371 Returns the inception time of a LDNS_RR_TYPE_RRSIG RR.
1373 :return: (:class:`ldns_rdf`) with the inception time or None
1376 return _ldns._ldns_rr_rrsig_inception(self)
1377 #parameters: const ldns_rr *,
1378 #retvals: ldns_rdf *
1380 def rrsig_keytag(self):
1382 Returns the keytag of a LDNS_RR_TYPE_RRSIG RR.
1384 :return: (:class:`ldns_rdf`) with the keytag or None on failure.
1386 return _ldns._ldns_rr_rrsig_keytag(self)
1387 #parameters: const ldns_rr *,
1388 #retvals: ldns_rdf *
1390 def rrsig_labels(self):
1392 Returns the number of labels of a LDNS_RR_TYPE_RRSIG RR.
1394 :return: (:class:`ldns_rdf`) with the number of labels or None
1397 return _ldns._ldns_rr_rrsig_labels(self)
1398 #parameters: const ldns_rr *,
1399 #retvals: ldns_rdf *
1401 def rrsig_origttl(self):
1403 Returns the original TTL of a LDNS_RR_TYPE_RRSIG RR.
1405 :return: (:class:`ldns_rdf`) with the original TTL or None
1408 return _ldns._ldns_rr_rrsig_origttl(self)
1409 #parameters: const ldns_rr *,
1410 #retvals: ldns_rdf *
1412 def rrsig_set_algorithm(self, f):
1414 Sets the algorithm of a LDNS_RR_TYPE_RRSIG rr.
1416 :param f: The algorithm to set.
1417 :type f: :class:`ldns_rdf`
1418 :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1419 :return: (bool) True on success, False otherwise.
1421 return _ldns._ldns_rr_rrsig_set_algorithm(self, f)
1422 #parameters: ldns_rr *, ldns_rdf *,
1425 def rrsig_set_expiration(self, f):
1427 Sets the expireation date of a LDNS_RR_TYPE_RRSIG rr.
1429 :param f: The expireation date to set.
1430 :type f: :class:`ldns_rdf`
1431 :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1432 :return: (bool) True on success, False otherwise.
1434 return _ldns._ldns_rr_rrsig_set_expiration(self, f)
1435 #parameters: ldns_rr *, ldns_rdf *,
1438 def rrsig_set_inception(self, f):
1440 Sets the inception date of a LDNS_RR_TYPE_RRSIG rr.
1442 :param f: The inception date to set.
1443 :type f: :class:`ldns_rdf`
1444 :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1445 :return: (bool) True on success, False otherwise.
1447 return _ldns._ldns_rr_rrsig_set_inception(self, f)
1448 #parameters: ldns_rr *, ldns_rdf *,
1451 def rrsig_set_keytag(self, f):
1453 Sets the keytag of a LDNS_RR_TYPE_RRSIG rr.
1455 :param f: The keytag to set.
1456 :type f: :class:`ldns_rdf`
1457 :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1458 :return: (bool) True on success, False otherwise.
1460 return _ldns._ldns_rr_rrsig_set_keytag(self, f)
1461 #parameters: ldns_rr *, ldns_rdf *,
1464 def rrsig_set_labels(self, f):
1466 Sets the number of labels of a LDNS_RR_TYPE_RRSIG rr.
1468 :param f: The number of labels to set.
1469 :type f: :class:`ldns_rdf`
1470 :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1471 :return: (bool) True on success, False otherwise.
1473 return _ldns._ldns_rr_rrsig_set_labels(self, f)
1474 #parameters: ldns_rr *, ldns_rdf *,
1477 def rrsig_set_origttl(self, f):
1479 Sets the original TTL of a LDNS_RR_TYPE_RRSIG rr.
1481 :param f: The original TTL to set.
1482 :type f: :class:`ldns_rdf`
1483 :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1484 :return: (bool) True on success, False otherwise.
1486 return _ldns._ldns_rr_rrsig_set_origttl(self, f)
1487 #parameters: ldns_rr *, ldns_rdf *,
1490 def rrsig_set_sig(self, f):
1492 Sets the signature data of a LDNS_RR_TYPE_RRSIG rr.
1494 :param f: The signature data to set.
1495 :type f: :class:`ldns_rdf`
1496 :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1497 :return: (bool) True on success, False otherwise.
1499 return _ldns._ldns_rr_rrsig_set_sig(self, f)
1500 #parameters: ldns_rr *, ldns_rdf *,
1503 def rrsig_set_signame(self, f):
1505 Sets the signers name of a LDNS_RR_TYPE_RRSIG rr.
1507 :param f: The signers name to set.
1508 :type f: :class:`ldns_rdf`
1509 :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1510 :return: (bool) True on success, False otherwise.
1512 return _ldns._ldns_rr_rrsig_set_signame(self, f)
1513 #parameters: ldns_rr *, ldns_rdf *,
1516 def rrsig_set_typecovered(self, f):
1518 Sets the typecovered of a LDNS_RR_TYPE_RRSIG rr.
1520 :param f: The type covered to set.
1521 :type f: :class:`ldns_rdf`
1522 :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1523 :return: (bool) True on success, False otherwise.
1525 return _ldns._ldns_rr_rrsig_set_typecovered(self, f)
1526 #parameters: ldns_rr *, ldns_rdf *,
1529 def rrsig_sig(self):
1531 Returns the signature data of a LDNS_RR_TYPE_RRSIG RR.
1533 :return: (:class:`ldns_rdf`) with the signature data or None
1536 return _ldns._ldns_rr_rrsig_sig(self)
1537 #parameters: const ldns_rr *,
1538 #retvals: ldns_rdf *
1540 def rrsig_signame(self):
1542 Returns the signers name of a LDNS_RR_TYPE_RRSIG RR.
1544 :return: (:class:`ldns_rdf`) with the signers name or None
1547 return _ldns._ldns_rr_rrsig_signame(self)
1548 #parameters: const ldns_rr *,
1549 #retvals: ldns_rdf *
1551 def rrsig_typecovered(self):
1553 Returns the type covered of a LDNS_RR_TYPE_RRSIG rr.
1555 :return: (:class:`ldns_rdf`) with the type covered or None
1558 return _ldns._ldns_rr_rrsig_typecovered(self)
1559 #parameters: const ldns_rr *,
1560 #retvals: ldns_rdf *
1562 def set_class(self, rr_class):
1564 Sets the class in the rr.
1566 :param rr_class: Set to this class.
1568 :throws TypeError: when `rr_class` of non-integer type.
1570 _ldns.ldns_rr_set_class(self, rr_class)
1571 #parameters: ldns_rr *, ldns_rr_class,
1574 def set_owner(self, owner):
1576 Sets the owner in the rr structure.
1578 :param owner: Owner name.
1579 :type owner: :class:`ldns_dname`
1580 :throws TypeError: when `owner` of non-:class:`ldns_dname` type.
1583 The type checking of `owner` is benevolent.
1584 It allows also to pass a dname :class:`ldns_rdf` object.
1585 This will probably change in future.
1587 if (not isinstance(owner, ldns_dname)) and \
1588 isinstance(owner, ldns_rdf) and \
1589 owner.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
1590 warnings.warn("The ldns_rr.new_frm_str() method will" +
1591 " drop the possibility to accept ldns_rdf as owner." +
1592 " Convert argument to ldns_dname.",
1593 PendingDeprecationWarning, stacklevel=2)
1594 _ldns._ldns_rr_set_owner(self, owner)
1595 #parameters: ldns_rr *, ldns_rdf *,
1598 def set_question(self, question):
1600 Sets the question flag in the rr structure.
1602 :param question: Question flag.
1603 :type question: bool
1605 _ldns.ldns_rr_set_question(self, question)
1606 #parameters: ldns_rr *, bool,
1609 def set_rd_count(self, count):
1611 Sets the rd_count in the rr.
1613 :param count: Set to this count.
1614 :type count: positive int
1615 :throws TypeError: when `count` of non-integer type.
1617 _ldns.ldns_rr_set_rd_count(self, count)
1618 #parameters: ldns_rr *, size_t,
1621 def set_rdf(self, f, position):
1623 Sets a rdf member, it will be set on the position given.
1625 The old value is returned, like pop.
1627 :param f: The rdf to be set.
1628 :type f: :class:`ldns_rdf`
1629 :param position: The position the set the rdf.
1630 :type position: positive int
1631 :throws TypeError: when mismatching types passed.
1632 :return: (:class:`ldns_rdf`) the old value in the rr, None
1635 return _ldns._ldns_rr_set_rdf(self, f, position)
1636 #parameters: ldns_rr *, const ldns_rdf *, size_t,
1637 #retvals: ldns_rdf *
1639 def set_ttl(self, ttl):
1641 Sets the ttl in the rr structure.
1643 :param ttl: Set to this ttl.
1644 :type ttl: positive int
1645 :throws TypeError: when `ttl` of non-integer type.
1647 _ldns.ldns_rr_set_ttl(self, ttl)
1648 #parameters: ldns_rr *, uint32_t,
1651 def set_type(self, rr_type):
1653 Sets the type in the rr.
1655 :param rr_type: Set to this type.
1656 :type rr_type: ineteger
1657 :throws TypeError: when `rr_type` of non-integer type.
1659 _ldns.ldns_rr_set_type(self, rr_type)
1660 #parameters: ldns_rr *, ldns_rr_type,
1663 def to_canonical(self):
1665 Converts each dname in a rr to its canonical form.
1667 _ldns.ldns_rr2canonical(self)
1671 Returns the ttl of an rr structure.
1673 :return: (int) the ttl of the rr.
1675 return _ldns.ldns_rr_ttl(self)
1676 #parameters: const ldns_rr *,
1680 def type_by_name(string):
1682 Retrieves a rr type identifier value by looking up its name.
1684 Returns 0 if invalid name passed.
1686 :param string: RR type name.
1688 :throws TypeError: when `string` of inappropriate type.
1689 :return: (int) RR type identifier, or 0 if no matching value
1690 to identifier found.
1692 return _ldns.ldns_get_rr_type_by_name(string)
1694 def uncompressed_size(self):
1696 Calculates the uncompressed size of an RR.
1698 :return: (inetger) size of the rr.
1700 return _ldns.ldns_rr_uncompressed_size(self)
1701 #parameters: const ldns_rr *,
1711 /* ========================================================================= */
1712 /* SWIG setting and definitions. */
1713 /* ========================================================================= */
1716 %nodefaultctor ldns_struct_rr_list; /* No default constructor. */
1717 %nodefaultdtor ldns_struct_rr_list; /* No default destructor. */
1719 %ignore ldns_struct_rr_list::_rrs;
1721 %newobject ldns_rr_list_cat_clone;
1722 %newobject ldns_rr_list_clone;
1723 %newobject ldns_rr_list_pop_rr;
1724 %newobject ldns_rr_list_pop_rr_list;
1725 %newobject ldns_rr_list_pop_rrset;
1726 %newobject ldns_rr_list_rr;
1727 %newobject ldns_rr_list_new;
1728 %newobject ldns_get_rr_list_hosts_frm_file;
1729 %newobject ldns_rr_list_subtype_by_rdf;
1730 %newobject ldns_rr_list2str;
1731 %delobject ldns_rr_list_deep_free;
1732 %delobject ldns_rr_list_free;
1734 /* Clone data on push. */
1736 %rename(__ldns_rr_list_push_rr) ldns_rr_list_push_rr;
1739 bool _ldns_rr_list_push_rr(ldns_rr_list* r, ldns_rr *rr)
1744 new = ldns_rr_clone(rr);
1745 if (!(ret = ldns_rr_list_push_rr(r, new))) {
1752 %rename(__ldns_rr_list_push_rr_list) ldns_rr_list_push_rr_list;
1755 bool _ldns_rr_list_push_rr_list(ldns_rr_list* r, ldns_rr_list *r2)
1760 new = ldns_rr_list_clone(r2);
1761 if (!(ret = ldns_rr_list_push_rr_list(r, new))) {
1762 ldns_rr_list_deep_free(new);
1769 %newobject _ldns_rr_list_set_rr;
1770 %rename(__ldns_rr_list_set_rr) ldns_rr_list_set_rr;
1773 ldns_rr * _ldns_rr_list_set_rr(ldns_rr_list * rrl, ldns_rr *rr,
1779 new = ldns_rr_clone(rr);
1780 if ((ret = ldns_rr_list_set_rr(rrl, new, idx)) == NULL) {
1788 %rename(__ldns_rr_list_cat) ldns_rr_list_cat;
1791 bool _ldns_rr_list_cat(ldns_rr_list *r, ldns_rr_list *r2)
1793 return ldns_rr_list_cat(r, ldns_rr_list_clone(r2));
1798 /* End clone data on push. */
1801 /* Clone data on pull. */
1803 %newobject _ldns_rr_list_rr;
1804 %rename(__ldns_rr_list_rr) ldns_rr_list_rr;
1807 ldns_rr * _ldns_rr_list_rr(ldns_rr_list *r, int i)
1810 rr = ldns_rr_list_rr(r, i);
1811 return (rr != NULL) ? ldns_rr_clone(rr) : NULL;
1815 %newobject _ldns_rr_list_owner;
1816 %rename(__ldns_rr_list_owner) ldns_rr_list_owner;
1819 ldns_rdf * _ldns_rr_list_owner(ldns_rr_list *r)
1822 rdf = ldns_rr_list_owner(r);
1823 return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
1828 /* End clone data on pull. */
1831 /* ========================================================================= */
1832 /* Debugging related code. */
1833 /* ========================================================================= */
1836 %rename(ldns_rr_list) ldns_struct_rr_list;
1838 %rename(__ldns_rr_list_deep_free) ldns_rr_list_deep_free;
1839 %rename(__ldns_rr_list_free) ldns_rr_list_free;
1842 void _ldns_rr_list_deep_free(ldns_rr_list *r)
1844 printf("******** LDNS_RR_LIST deep free 0x%lX ************\n",
1845 (long unsigned int) r);
1846 ldns_rr_list_deep_free(r);
1849 void _ldns_rr_list_free(ldns_rr_list *r)
1851 printf("******** LDNS_RR_LIST deep free 0x%lX ************\n",
1852 (long unsigned int) r);
1853 ldns_rr_list_free(r);
1857 %rename(_ldns_rr_list_deep_free) ldns_rr_list_deep_free;
1858 %rename(_ldns_rr_list_free) ldns_rr_list_free;
1862 /* ========================================================================= */
1864 /* ========================================================================= */
1870 /* ========================================================================= */
1871 /* Encapsulating Python code. */
1872 /* ========================================================================= */
1875 %feature("docstring") ldns_struct_rr_list "List of Resource Records.
1877 This class contains a list of RR's (see :class:`ldns.ldns_rr`).
1880 %extend ldns_struct_rr_list {
1885 self.this = _ldns.ldns_rr_list_new()
1887 raise Exception("Can't create new RR_LIST")
1889 __swig_destroy__ = _ldns._ldns_rr_list_deep_free
1892 # LDNS_RR_LIST_CONSTRUCTORS_
1896 def new(raiseException=True):
1898 Creates an empty RR List object.
1900 :param raiseException: Set to True if an exception should
1902 :type raiseException: bool
1903 :throws Exception: when `raiseException` is True and error
1905 :return: :class:`ldns_rr_list` Empty RR list.
1907 rrl = _ldns.ldns_rr_list_new()
1908 if (not rrl) and raiseException:
1909 raise Exception("Can't create RR List.")
1913 def new_frm_file(filename="/etc/hosts", raiseException=True):
1915 Creates an RR List object from file content.
1917 Goes through a file and returns a rr list containing
1918 all the defined hosts in there.
1920 :param filename: The filename to use.
1922 :param raiseException: Set to True if an exception should
1924 :type raiseException: bool
1925 :throws TypeError: when `filename` of inappropriate type.
1926 :throws Exception: when `raiseException` is True and error
1928 :return: RR List object or None. If the object can't be
1929 created and `raiseException` is True, an exception occurs.
1933 >>> alist = ldns.ldns_rr_list.new_frm_file()
1935 localhost. 3600 IN A 127.0.0.1
1939 rr = _ldns.ldns_get_rr_list_hosts_frm_file(filename)
1940 if (not rr) and (raiseException):
1941 raise Exception("Can't create RR List.")
1945 # _LDNS_RR_LIST_CONSTRUCTORS
1950 Converts a list of resource records to presentation format.
1952 :return: (str) Presentation format.
1954 return _ldns.ldns_rr_list2str(self)
1956 def print_to_file(self, output):
1958 Print a rr_list to output.
1960 :param output: Opened file to print to.
1961 :throws TypeError: when `output` of inappropriate type.
1963 _ldns.ldns_rr_list_print(output, self)
1966 def to_canonical(self):
1968 Converts each dname in each rr in a rr_list to its canonical
1971 _ldns.ldns_rr_list2canonical(self)
1972 #parameters: ldns_rr_list *,
1977 Returns a generator object of a list of rr records.
1979 :return: (generator) generator object.
1981 for i in range(0, self.rr_count()):
1986 Checks if the rr list is a rr set.
1988 :return: (bool) True if rr list is a rr set.
1990 return _ldns.ldns_is_rrset(self)
1992 def __cmp__(self, rrl2):
1994 Compares two rr lists.
1996 :param rrl2: The second one.
1997 :type rrl2: :class:`ldns_rr_list`
1998 :throws TypeError: when `rrl2` of non-:class:`ldns_rr_list`
2000 :return: (int) 0 if equal, -1 if this list comes before
2001 `rrl2`, 1 if `rrl2` comes before this list.
2003 return _ldns.ldns_rr_list_compare(self, rrl2)
2005 def __lt__(self, other):
2007 Compares two rr lists.
2009 :param other: The second one.
2010 :type other: :class:`ldns_rr_list`
2011 :throws TypeError: when `other` of non-:class:`ldns_rr_list`
2013 :return: (bool) True when `self` is less than 'other'.
2015 return _ldns.ldns_rr_list_compare(self, other) == -1
2017 def __le__(self, other):
2019 Compares two rr lists.
2021 :param other: The second one.
2022 :type other: :class:`ldns_rr_list`
2023 :throws TypeError: when `other` of non-:class:`ldns_rr_list`
2025 :return: (bool) True when `self` is less than or equal to
2028 return _ldns.ldns_rr_list_compare(self, other) != 1
2030 def __eq__(self, other):
2032 Compares two rr lists.
2034 :param other: The second one.
2035 :type other: :class:`ldns_rr_list`
2036 :throws TypeError: when `other` of non-:class:`ldns_rr_list`
2038 :return: (bool) True when `self` is equal to 'other'.
2040 return _ldns.ldns_rr_list_compare(self, other) == 0
2042 def __ne__(self, other):
2044 Compares two rr lists.
2046 :param other: The second one.
2047 :type other: :class:`ldns_rr_list`
2048 :throws TypeError: when `other` of non-:class:`ldns_rr_list`
2050 :return: (bool) True when `self` is not equal to 'other'.
2052 return _ldns.ldns_rr_list_compare(self, other) != 0
2054 def __gt__(self, other):
2056 Compares two rr lists.
2058 :param other: The second one.
2059 :type other: :class:`ldns_rr_list`
2060 :throws TypeError: when `other` of non-:class:`ldns_rr_list`
2062 :return: (bool) True when `self` is greater than 'other'.
2064 return _ldns.ldns_rr_list_compare(self, other) == 1
2066 def __ge__(self, other):
2068 Compares two rr lists.
2070 :param other: The second one.
2071 :type other: :class:`ldns_rr_list`
2072 :throws TypeError: when `other` of non-:class:`ldns_rr_list`
2074 :return: (bool) True when `self` is greater than or equal to
2077 return _ldns.ldns_rr_list_compare(self, other) != -1
2079 def write_to_buffer(self, buffer):
2081 Copies the rr_list data to the buffer in wire format.
2083 :param buffer: Output buffer to append the result to.
2084 :type buffer: :class:`ldns_buffer`
2085 :throws TypeError: when `buffer` of non-:class:`ldns_buffer`
2087 :return: (ldns_status) ldns_status
2089 return _ldns.ldns_rr_list2buffer_wire(buffer, self)
2092 # LDNS_RR_LIST_METHODS_
2095 def cat(self, right):
2097 Concatenates two ldns_rr_lists together.
2099 This modifies rr list (to extend it and adds RRs from right).
2101 :param right: The right-hand side.
2102 :type right: :class:`ldns_rr_list`
2103 :throws TypeError: when `right` of non-:class:`ldns_rr_list`
2105 :return: (bool) True if success.
2107 return _ldns._ldns_rr_list_cat(self, right)
2108 #parameters: ldns_rr_list *, ldns_rr_list *,
2111 def cat_clone(self, right):
2113 Concatenates two ldns_rr_lists together, creates a new list
2114 of the rr's (instead of appending the content to an existing
2117 :param right: The right-hand side.
2118 :type right: :class:`ldns_rr_list`
2119 :throws TypeError: when `right` of non-:class:`ldns_rr_list`
2121 :return: (:class:`ldns_rr_list`) rr list with left-hand side +
2122 right-hand side concatenated, on None on error.
2124 return _ldns.ldns_rr_list_cat_clone(self, right)
2125 #parameters: ldns_rr_list *, ldns_rr_list *,
2126 #retvals: ldns_rr_list *
2132 :return: (:class:`ldns_rr_list`) the cloned rr list,
2135 return _ldns.ldns_rr_list_clone(self)
2136 #parameters: const ldns_rr_list *,
2137 #retvals: ldns_rr_list *
2139 def contains_rr(self, rr):
2141 Returns True if the given rr is one of the rrs in the list,
2142 or if it is equal to one.
2144 :param rr: The rr to check.
2145 :type rr: :class:`ldns_rr`
2146 :throws TypeError: when `rr` of non-:class:`ldns_rr` type.
2147 :return: (bool) True if rr_list contains `rr`, False otherwise.
2149 return _ldns.ldns_rr_list_contains_rr(self, rr)
2150 #parameters: const ldns_rr_list *, ldns_rr *,
2155 Returns the owner domain name rdf of the first element of
2156 the RR. If there are no elements present, None is returned.
2158 :return: (:class:`ldns_dname`) dname of the first element,
2159 or None if the list is empty.
2161 rdf = _ldns._ldns_rr_list_owner(self)
2163 rdf = ldns_dname(rdf, clone=False)
2165 #parameters: const ldns_rr_list *,
2166 #retvals: ldns_rdf *
2170 Pops the last rr from an rrlist.
2172 :return: (:class:`ldns_rr`) None if nothing to pop.
2173 Otherwise the popped RR.
2175 rr = _ldns.ldns_rr_list_pop_rr(self)
2177 #parameters: ldns_rr_list *,
2180 def pop_rr_list(self, size):
2182 Pops an rr_list of size s from an rrlist.
2184 :param size: The number of rr's to pop.
2185 :type size: positive int
2186 :throws TypeError: when `size` of inappropriate type.
2187 :return: (:class:`ldns_rr_list`) None if nothing to pop.
2188 Otherwise the popped rr list.
2190 return _ldns.ldns_rr_list_pop_rr_list(self, size)
2191 #parameters: ldns_rr_list *, size_t,
2192 #retvals: ldns_rr_list *
2194 def pop_rrset(self):
2196 Pops the first rrset from the list, the list must be sorted,
2197 so that all rr's from each rrset are next to each other.
2199 :return: (:class:`ldns_rr_list`) the first rrset, or None when
2202 return _ldns.ldns_rr_list_pop_rrset(self)
2203 #parameters: ldns_rr_list *,
2204 #retvals: ldns_rr_list *
2206 def push_rr(self, rr):
2208 Pushes an rr to an rrlist.
2210 :param rr: The rr to push.
2211 :type rr: :class:`ldns_rr`
2212 :throws TypeError: when `rr` of non-:class:`ldns_rr` type.
2213 :return: (bool) False on error, otherwise True.
2215 return _ldns._ldns_rr_list_push_rr(self, rr)
2216 #parameters: ldns_rr_list *, const ldns_rr *,
2219 def push_rr_list(self, push_list):
2221 Pushes an rr list to an rr list.
2223 :param push_list: The rr_list to push.
2224 :type push_list: :class:`ldns_rr_list`
2225 :throws TypeError: when `push_list` of non-:class:`ldns_rr_list`
2227 :returns: (bool) False on error, otherwise True.
2229 return _ldns._ldns_rr_list_push_rr_list(self, push_list)
2230 #parameters: ldns_rr_list *, const ldns_rr_list *,
2235 Returns a specific rr of an rrlist.
2237 :param nr: Index of the desired rr.
2238 :type nr: positive int
2239 :throws TypeError: when `nr` of inappropriate type.
2240 :return: (:class:`ldns_rr`) The rr at position `nr`, or None
2243 return _ldns._ldns_rr_list_rr(self, nr)
2244 #parameters: const ldns_rr_list *, size_t,
2249 Returns the number of rr's in an rr_list.
2251 :return: (int) The number of rr's.
2253 return _ldns.ldns_rr_list_rr_count(self)
2254 #parameters: const ldns_rr_list *,
2257 def set_rr(self, r, idx):
2259 Set a rr on a specific index in a ldns_rr_list.
2261 :param r: The rr to set.
2262 :type r: :class:`ldns_rr`
2263 :param idx: Index into the rr_list.
2264 :type idx: positive int
2265 :throws TypeError: when parameters of inappropriate types.
2266 :return: (:class:`ldns_rr`) the old rr which was stored in
2267 the rr_list, or None if the index was too large
2268 to set a specific rr.
2270 return _ldns._ldns_rr_list_set_rr(self, r, idx)
2271 #parameters: ldns_rr_list *, const ldns_rr *, size_t,
2274 def set_rr_count(self, count):
2276 Sets the number of rr's in an rr_list.
2278 :param count: The number of rr in this list.
2279 :type count: positive int
2280 :throws TypeError: when `count` of non-integer type.
2281 :throws Exception: when `count` out of acceptable range.
2284 Don't use this method unless you really know what you
2287 # The function C has a tendency to generate an assertion fail when
2288 # the count exceeds the list's capacity -- therefore the checking
2290 if isinstance(count, int) and \
2291 ((count < 0) or (count > self._rr_capacity)):
2292 raise Exception("Given count %d is out of range " % (count) +
2293 "of the rr list's capacity %d." % (self._rr_capacity))
2294 _ldns.ldns_rr_list_set_rr_count(self, count)
2295 #parameters: ldns_rr_list *, size_t,
2300 Sorts an rr_list (canonical wire format).
2302 _ldns.ldns_rr_list_sort(self)
2303 #parameters: ldns_rr_list *,
2306 def subtype_by_rdf(self, r, pos):
2308 Return the rr_list which matches the rdf at position field.
2310 Think type-covered stuff for RRSIG.
2312 :param r: The rdf to use for the comparison.
2313 :type r: :class:`ldns_rdf`
2314 :param pos: At which position we can find the rdf.
2315 :type pos: positive int
2316 :throws TypeError: when parameters of inappropriate types.
2317 :return: (:class:`ldns_rr_list`) a new rr list with only
2318 the RRs that match, or None when nothing matches.
2320 return _ldns.ldns_rr_list_subtype_by_rdf(self, r, pos)
2321 #parameters: ldns_rr_list *, ldns_rdf *, size_t,
2322 #retvals: ldns_rr_list *
2326 Returns the type of the first element of the RR.
2328 If there are no elements present, 0 is returned.
2330 :return: (int) rr_type of the first element,
2331 or 0 if the list is empty.
2333 return _ldns.ldns_rr_list_type(self)
2334 #parameters: const ldns_rr_list *,
2335 #retvals: ldns_rr_type
2338 # _LDNS_RR_LIST_METHODS
2344 /* ========================================================================= */
2345 /* SWIG setting and definitions. */
2346 /* ========================================================================= */
2349 %newobject ldns_rr_descript;
2351 %nodefaultctor ldns_struct_rr_descriptor; /* No default constructor. */
2352 %nodefaultdtor ldns_struct_rr_descriptor; /* No default destructor.*/
2353 %rename(ldns_rr_descriptor) ldns_struct_rr_descriptor;
2356 /* ========================================================================= */
2357 /* Debugging related code. */
2358 /* ========================================================================= */
2363 /* ========================================================================= */
2365 /* ========================================================================= */
2371 * Does nothing, but keeps the SWIG wrapper quiet about absent destructor.
2373 void ldns_rr_descriptor_dummy_free(const ldns_rr_descriptor *rd)
2380 /* ========================================================================= */
2381 /* Encapsulating Python code. */
2382 /* ========================================================================= */
2385 %feature("docstring") ldns_struct_rr_descriptor "Resource Record descriptor.
2387 This structure contains, for all rr types, the rdata fields that are defined.
2389 In order to create a class instance use :meth:`ldns_rr_descriptor`.
2392 %extend ldns_struct_rr_descriptor {
2395 def __init__(self, rr_type):
2397 Returns the resource record descriptor for the given type.
2399 :param rr_type: RR type.
2401 :throws TypeError: when `rr_type` of inappropriate type.
2402 :return: (:class:`ldns_rr_descriptor`) RR descriptor class.
2404 self.this = self.ldns_rr_descriptor(rr_type)
2407 raise Exception("The content of this class cannot be printed.")
2409 __swig_destroy__ = _ldns.ldns_rr_descriptor_dummy_free
2412 # LDNS_RR_DESCRIPTOR_CONSTRUCTORS_
2416 def ldns_rr_descriptor(rr_type):
2418 Returns the resource record descriptor for the given type.
2420 :param rr_type: RR type.
2422 :throws TypeError: when `rr_type` of inappropriate type.
2423 :return: (:class:`ldns_rr_descriptor`) RR descriptor class.
2425 return _ldns.ldns_rr_descript(rr_type)
2426 #parameters: uint16_t
2427 #retvals: const ldns_rr_descriptor *
2430 # _LDNS_RR_DESCRIPTOR_CONSTRUCTORS
2434 # LDNS_RR_DESCRIPTOR_METHODS_
2437 def field_type(self, field):
2439 Returns the rdf type for the given rdata field number of the
2440 rr type for the given descriptor.
2442 :param field: The field number.
2443 :type field: positive int
2444 :throws TypeError: when `field` of non-inetger type.
2445 :return: (int) the rdf type for the field.
2447 return _ldns.ldns_rr_descriptor_field_type(self, field)
2448 #parameters: const ldns_rr_descriptor *, size_t,
2449 #retvals: ldns_rdf_type
2453 Returns the maximum number of rdata fields of the rr type this
2454 descriptor describes.
2456 :return: (int) the maximum number of rdata fields.
2458 return _ldns.ldns_rr_descriptor_maximum(self)
2459 #parameters: const ldns_rr_descriptor *,
2464 Returns the minimum number of rdata fields of the rr type this
2465 descriptor describes.
2467 :return: (int) the minimum number of rdata fields.
2469 return _ldns.ldns_rr_descriptor_minimum(self)
2470 #parameters: const ldns_rr_descriptor *,
2474 # _LDNS_RR_DESCRIPTOR_METHODS
2480 /* ========================================================================= */
2482 /* ========================================================================= */
2486 * rrsig checking wrappers
2488 * Copying of rr pointers into the good_keys list leads to double free
2489 * problems, therefore we provide two options - either ignore the keys
2490 * or get list of indexes of the keys. The latter allows fetching of the
2491 * keys later on from the original key set.
2494 %rename(__ldns_verify_rrsig_keylist) ldns_verify_rrsig_keylist;
2497 ldns_status ldns_verify_rrsig_keylist_status_only(ldns_rr_list *rrset,
2498 ldns_rr *rrsig, const ldns_rr_list *keys)
2500 ldns_rr_list *good_keys = ldns_rr_list_new();
2501 ldns_status status = ldns_verify_rrsig_keylist(rrset, rrsig, keys,
2503 ldns_rr_list_free(good_keys);
2508 %rename(__ldns_verify_rrsig_keylist) ldns_verify_rrsig_keylist;
2511 PyObject* ldns_verify_rrsig_keylist_(ldns_rr_list *rrset,
2512 ldns_rr *rrsig, const ldns_rr_list *keys)
2516 ldns_rr_list *good_keys = ldns_rr_list_new();
2517 ldns_status status = ldns_verify_rrsig_keylist(rrset, rrsig, keys,
2520 tuple = PyTuple_New(2);
2521 PyTuple_SetItem(tuple, 0, SWIG_From_int(status));
2522 keylist = PyList_New(0);
2523 if (status == LDNS_STATUS_OK) {
2525 for (i = 0; i < ldns_rr_list_rr_count(keys); i++) {
2526 if (ldns_rr_list_contains_rr(good_keys, ldns_rr_list_rr(keys, i))) {
2527 PyList_Append(keylist, SWIG_From_int(i));
2531 PyTuple_SetItem(tuple, 1, keylist);
2532 ldns_rr_list_free(good_keys);
2538 %rename(__ldns_verify_rrsig_keylist_notime) ldns_verify_rrsig_keylist_notime;
2541 ldns_status ldns_verify_rrsig_keylist_notime_status_only(ldns_rr_list *rrset,
2542 ldns_rr *rrsig, const ldns_rr_list *keys)
2544 ldns_rr_list *good_keys = ldns_rr_list_new();
2545 ldns_status status = ldns_verify_rrsig_keylist_notime(rrset, rrsig, keys,
2547 ldns_rr_list_free(good_keys);
2552 %rename(__ldns_verify_rrsig_keylist_notime) ldns_verify_rrsig_keylist_notime;
2555 PyObject* ldns_verify_rrsig_keylist_notime_(ldns_rr_list *rrset,
2556 ldns_rr *rrsig, const ldns_rr_list *keys)
2560 ldns_rr_list *good_keys = ldns_rr_list_new();
2561 ldns_status status = ldns_verify_rrsig_keylist_notime(rrset, rrsig, keys,
2564 tuple = PyTuple_New(2);
2565 PyTuple_SetItem(tuple, 0, SWIG_From_int(status));
2566 keylist = PyList_New(0);
2567 if (status == LDNS_STATUS_OK) {
2569 for (i = 0; i < ldns_rr_list_rr_count(keys); i++) {
2570 if (ldns_rr_list_contains_rr(good_keys, ldns_rr_list_rr(keys, i))) {
2571 PyList_Append(keylist, SWIG_From_int(i));
2575 PyTuple_SetItem(tuple, 1, keylist);
2576 ldns_rr_list_free(good_keys);
2581 /* End of rrsig checking wrappers. */