1 /****************************************************************************** 2 * ldns_rdf.i: LDNS record data 3 * 4 * Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz) 5 * Karel Slany (slany AT fit.vutbr.cz) 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * 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. 19 * 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 *****************************************************************************/ 32 33 34 /* ========================================================================= */ 35 /* SWIG setting and definitions. */ 36 /* ========================================================================= */ 37 38 /* Creates a temporary instance of (ldns_rdf *). */ 39 %typemap(in, numinputs=0, noblock=1) (ldns_rdf **) 40 { 41 ldns_rdf *$1_rdf = NULL; 42 $1 = &$1_rdf; 43 } 44 45 /* Result generation, appends (ldns_rdf *) after the result. */ 46 %typemap(argout, noblock=1) (ldns_rdf **) 47 { 48 $result = SWIG_Python_AppendOutput($result, 49 SWIG_NewPointerObj(SWIG_as_voidptr($1_rdf), 50 SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0)); 51 } 52 53 /* 54 * Automatic conversion of const (ldns_rdf *) parameter from string. 55 * Argument default value. 56 */ 57 %typemap(arginit, noblock=1) const ldns_rdf * 58 { 59 char *$1_str = NULL; 60 } 61 62 /* 63 * Automatic conversion of const (ldns_rdf *) parameter from string. 64 * Preparation of arguments. 65 */ 66 %typemap(in, noblock=1) const ldns_rdf * (void* argp, $1_ltype tmp = 0, int res) 67 { 68 if (Python_str_Check($input)) { 69 $1_str = SWIG_Python_str_AsChar($input); 70 if ($1_str == NULL) { 71 %argument_fail(SWIG_TypeError, "char *", $symname, $argnum); 72 } 73 tmp = ldns_dname_new_frm_str($1_str); 74 if (tmp == NULL) { 75 %argument_fail(SWIG_TypeError, "char *", $symname, $argnum); 76 } 77 $1 = ($1_ltype) tmp; 78 } else { 79 res = SWIG_ConvertPtr($input, &argp, SWIGTYPE_p_ldns_struct_rdf, 0 | 0); 80 if (!SWIG_IsOK(res)) { 81 %argument_fail(res, "ldns_rdf const *", $symname, $argnum); 82 } 83 $1 = ($1_ltype) argp; 84 } 85 } 86 87 /* 88 * Automatic conversion of const (ldns_rdf *) parameter from string. 89 * Freeing of allocated memory (in Python 3 when daling with strings). 90 */ 91 %typemap(freearg, noblock=1) const ldns_rdf * 92 { 93 if ($1_str != NULL) { 94 /* Is not NULL only when a conversion form string occurred. */ 95 SWIG_Python_str_DelForPy3($1_str); /* Is a empty macro for Python < 3. */ 96 } 97 } 98 99 %nodefaultctor ldns_struct_rdf; /* No default constructor. */ 100 %nodefaultdtor ldns_struct_rdf; /* No default destructor. */ 101 102 103 /* 104 * This file must contain all %newobject and %delobject tags also for 105 * ldns_dname. This is because the ldns_dname is a derived class from ldns_rdf. 106 */ 107 108 109 %newobject ldns_rdf_new; 110 %newobject ldns_rdf_new_frm_str; 111 %newobject ldns_rdf_new_frm_data; 112 113 %newobject ldns_rdf_address_reverse; 114 %newobject ldns_rdf_clone; 115 %newobject ldns_rdf2str; 116 117 %newobject ldns_dname_new; 118 %newobject ldns_dname_new_frm_str; 119 %newobject ldns_dname_new_frm_data; 120 121 %newobject ldns_dname_cat_clone; 122 %newobject ldns_dname_label; 123 %newobject ldns_dname_left_chop; 124 %newobject ldns_dname_reverse; 125 126 %delobject ldns_rdf_deep_free; 127 %delobject ldns_rdf_free; 128 129 130 /* 131 * Should the ldns_rdf_new() also be marked as deleting its data parameter? 132 */ 133 %delobject ldns_rdf_set_data; /* Because data are directly coupled into rdf. */ 134 135 %rename(ldns_rdf) ldns_struct_rdf; 136 137 138 /* ========================================================================= */ 139 /* Debugging related code. */ 140 /* ========================================================================= */ 141 142 #ifdef LDNS_DEBUG 143 %rename(__ldns_rdf_deep_free) ldns_rdf_deep_free; 144 %rename(__ldns_rdf_free) ldns_rdf_free; 145 %inline 146 %{ 147 /*! 148 * @brief Prints information about deallocated rdf and deallocates. 149 */ _ldns_rdf_deep_free(ldns_rdf * r)150 void _ldns_rdf_deep_free (ldns_rdf *r) 151 { 152 printf("******** LDNS_RDF deep free 0x%lX ************\n", 153 (long unsigned int) r); 154 ldns_rdf_deep_free(r); 155 } 156 157 /*! 158 * @brief Prints information about deallocated rdf and deallocates. 159 */ _ldns_rdf_free(ldns_rdf * r)160 void _ldns_rdf_free (ldns_rdf* r) 161 { 162 printf("******** LDNS_RDF free 0x%lX ************\n", 163 (long unsigned int) r); 164 ldns_rdf_free(r); 165 } 166 %} 167 #else /* !LDNS_DEBUG */ 168 %rename(_ldns_rdf_deep_free) ldns_rdf_deep_free; 169 %rename(_ldns_rdf_free) ldns_rdf_free; 170 #endif /* LDNS_DEBUG */ 171 172 173 /* ========================================================================= */ 174 /* Added C code. */ 175 /* ========================================================================= */ 176 177 178 %inline 179 %{ 180 /*! 181 * @brief returns a human readable string containing rdf type. 182 */ ldns_rdf_type2str(const ldns_rdf * rdf)183 const char *ldns_rdf_type2str(const ldns_rdf *rdf) 184 { 185 if (rdf) { 186 switch(ldns_rdf_get_type(rdf)) { 187 case LDNS_RDF_TYPE_NONE: return 0; 188 case LDNS_RDF_TYPE_DNAME: return "DNAME"; 189 case LDNS_RDF_TYPE_INT8: return "INT8"; 190 case LDNS_RDF_TYPE_INT16: return "INT16"; 191 case LDNS_RDF_TYPE_INT32: return "INT32"; 192 case LDNS_RDF_TYPE_A: return "A"; 193 case LDNS_RDF_TYPE_AAAA: return "AAAA"; 194 case LDNS_RDF_TYPE_STR: return "STR"; 195 case LDNS_RDF_TYPE_APL: return "APL"; 196 case LDNS_RDF_TYPE_B32_EXT: return "B32_EXT"; 197 case LDNS_RDF_TYPE_B64: return "B64"; 198 case LDNS_RDF_TYPE_HEX: return "HEX"; 199 case LDNS_RDF_TYPE_NSEC: return "NSEC"; 200 case LDNS_RDF_TYPE_TYPE: return "TYPE"; 201 case LDNS_RDF_TYPE_CLASS: return "CLASS"; 202 case LDNS_RDF_TYPE_CERT_ALG: return "CER_ALG"; 203 case LDNS_RDF_TYPE_ALG: return "ALG"; 204 case LDNS_RDF_TYPE_UNKNOWN: return "UNKNOWN"; 205 case LDNS_RDF_TYPE_TIME: return "TIME"; 206 case LDNS_RDF_TYPE_PERIOD: return "PERIOD"; 207 case LDNS_RDF_TYPE_TSIGTIME: return "TSIGTIME"; 208 case LDNS_RDF_TYPE_HIP: return "HIP"; 209 case LDNS_RDF_TYPE_INT16_DATA: return "INT16_DATA"; 210 case LDNS_RDF_TYPE_SERVICE: return "SERVICE"; 211 case LDNS_RDF_TYPE_LOC: return "LOC"; 212 case LDNS_RDF_TYPE_WKS: return "WKS"; 213 case LDNS_RDF_TYPE_NSAP: return "NSAP"; 214 case LDNS_RDF_TYPE_ATMA: return "ATMA"; 215 case LDNS_RDF_TYPE_IPSECKEY: return "IPSECKEY"; 216 case LDNS_RDF_TYPE_NSEC3_SALT: return "NSEC3_SALT"; 217 case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER: 218 return "NSEC3_NEXT_OWNER"; 219 case LDNS_RDF_TYPE_ILNP64: return "ILNP64"; 220 case LDNS_RDF_TYPE_EUI48: return "EUI48"; 221 case LDNS_RDF_TYPE_EUI64: return "EUI64"; 222 case LDNS_RDF_TYPE_TAG: return "TAG"; 223 case LDNS_RDF_TYPE_LONG_STR: return "LONG_STR"; 224 case LDNS_RDF_TYPE_AMTRELAY: return "AMTRELAY"; 225 case LDNS_RDF_TYPE_SVCPARAMS: return "SVCPARAMS"; 226 case LDNS_RDF_TYPE_CERTIFICATE_USAGE: 227 return "CERTIFICATE_USAGE"; 228 case LDNS_RDF_TYPE_SELECTOR: return "SELECTOR"; 229 case LDNS_RDF_TYPE_MATCHING_TYPE: 230 return "MATCHING_TYPE"; 231 } 232 } 233 return 0; 234 } 235 %} 236 237 238 %inline 239 %{ 240 /*! 241 * @brief Returns the rdf data organised into a list of bytes. 242 */ ldns_rdf_data_as_bytearray(const ldns_rdf * rdf)243 PyObject * ldns_rdf_data_as_bytearray(const ldns_rdf *rdf) 244 { 245 Py_ssize_t len; 246 uint8_t *data; 247 248 assert(rdf != NULL); 249 250 len = ldns_rdf_size(rdf); 251 data = ldns_rdf_data(rdf); 252 253 return PyByteArray_FromStringAndSize((char *) data, len); 254 } 255 %} 256 257 258 /* ========================================================================= */ 259 /* Encapsulating Python code. */ 260 /* ========================================================================= */ 261 262 %feature("docstring") ldns_struct_rdf "Resource record data field. 263 264 The data is a network ordered array of bytes, which size is specified 265 by the (16-bit) size field. To correctly parse it, use the type 266 specified in the (16-bit) type field with a value from ldns_rdf_type." 267 268 %extend ldns_struct_rdf { 269 270 %pythoncode 271 %{ 272 def __init__(self): 273 """ 274 Cannot be created directly from Python. 275 """ 276 raise Exception("This class can't be created directly. " + 277 "Please use: ldns_rdf_new, ldns_rdf_new_frm_data, " + 278 "ldns_rdf_new_frm_str, ldns_rdf_new_frm_fp, " + 279 "ldns_rdf_new_frm_fp_l") 280 281 __swig_destroy__ = _ldns._ldns_rdf_deep_free 282 283 # 284 # LDNS_RDF_CONSTRUCTORS_ 285 # 286 287 @staticmethod 288 def new_frm_str(string, rr_type, raiseException = True): 289 """ 290 Creates a new rdf from a string of a given type. 291 292 :param string: string to use 293 :type string: string 294 :param rr_type: The type of the rdf. See predefined `RDF_TYPE_` 295 constants. 296 :type rr_type: integer 297 :param raiseException: If True, an exception occurs in case 298 a RDF object can't be created. 299 :type raiseException: bool 300 :throws TypeError: When parameters of mismatching types. 301 :throws Exception: When raiseException set and rdf couldn't 302 be created. 303 :return: :class:`ldns_rdf` object or None. If the object 304 can't be created and `raiseException` is True, 305 an exception occurs. 306 307 **Usage** 308 309 >>> rdf = ldns.ldns_rdf.new_frm_str("74.125.43.99", ldns.LDNS_RDF_TYPE_A) 310 >>> print rdf, rdf.get_type_str() 311 A 74.125.43.99 312 >>> name = ldns.ldns_resolver.new_frm_file().get_name_by_addr(rdf) 313 >>> if (name): print name 314 99.43.125.74.in-addr.arpa. 85277 IN PTR bw-in-f99.google.com. 315 """ 316 rr = _ldns.ldns_rdf_new_frm_str(rr_type, string) 317 if (not rr) and raiseException: 318 raise Exception("Can't create query packet, " + 319 "error: %d" % status) 320 return rr 321 322 # 323 # _LDNS_RDF_CONSTRUCTORS 324 # 325 326 def __str__(self): 327 """ 328 Converts the rdata field to presentation format. 329 """ 330 return _ldns.ldns_rdf2str(self) 331 332 def __cmp__(self, other): 333 """ 334 Compares two rdfs on their wire formats. 335 336 (To order dnames according to rfc4034, use ldns_dname_compare.) 337 338 :param other: The second one RDF. 339 :type other: :class:`ldns_rdf` 340 :throws TypeError: When `other` of non-:class:`ldns_rdf` type. 341 :return: (int) -1, 0 or 1 if self comes before other, 342 is equal or self comes after other respectively. 343 """ 344 return _ldns.ldns_rdf_compare(self, other) 345 346 def __lt__(self, other): 347 """ 348 Compares two rdfs on their formats. 349 350 :param other: The socond one RDF. 351 :type other: :class:`ldns_rdf` 352 :throws TypeError: When `other` of non-:class:`ldns_rdf` type. 353 :return: (bool) True when `self` is less than 'other'. 354 """ 355 return _ldns.ldns_rdf_compare(self, other) == -1 356 357 def __le__(self, other): 358 """ 359 Compares two rdfs on their formats. 360 361 :param other: The socond one RDF. 362 :type other: :class:`ldns_rdf` 363 :throws TypeError: When `other` of non-:class:`ldns_rdf` type. 364 :return: (bool) True when `self` is less than or equal to 365 'other'. 366 """ 367 return _ldns.ldns_rdf_compare(self, other) != 1 368 369 def __eq__(self, other): 370 """ 371 Compares two rdfs on their formats. 372 373 :param other: The socond one RDF. 374 :type other: :class:`ldns_rdf` 375 :throws TypeError: When `other` of non-:class:`ldns_rdf` type. 376 :return: (bool) True when `self` is equal to 'other'. 377 """ 378 return _ldns.ldns_rdf_compare(self, other) == 0 379 380 def __ne__(self, other): 381 """ 382 Compares two rdfs on their formats. 383 384 :param other: The socond one RDF. 385 :type other: :class:`ldns_rdf` 386 :throws TypeError: When `other` of non-:class:`ldns_rdf` type. 387 :return: (bool) True when `self` is not equal to 'other'. 388 """ 389 return _ldns.ldns_rdf_compare(self, other) != 0 390 391 def __gt__(self, other): 392 """ 393 Compares two rdfs on their formats. 394 395 :param other: The socond one RDF. 396 :type other: :class:`ldns_rdf` 397 :throws TypeError: When `other` of non-:class:`ldns_rdf` type. 398 :return: (bool) True when `self` is greater than 'other'. 399 """ 400 return _ldns.ldns_rdf_compare(self, other) == 1 401 402 def __ge__(self, other): 403 """ 404 Compares two rdfs on their formats. 405 406 :param other: The socond one RDF. 407 :type other: :class:`ldns_rdf` 408 :throws TypeError: When `other` of non-:class:`ldns_rdf` type. 409 :return: (bool) True when `self` is greater than or equal to 410 'other'. 411 """ 412 return _ldns.ldns_rdf_compare(self, other) != -1 413 414 def print_to_file(self, output): 415 """ 416 Prints the data in the rdata field to the given `output` file 417 stream (in presentation format). 418 """ 419 _ldns.ldns_rdf_print(output, self) 420 421 def get_type_str(self): 422 """ 423 Returns the type of the rdf as a human readable string. 424 425 :return: String containing rdf type. 426 """ 427 return ldns_rdf_type2str(self) 428 429 def write_to_buffer(self, buffer): 430 """ 431 Copies the rdata data to the buffer in wire format. 432 433 :param buffer: Buffer to append the rdf to. 434 :type param: :class:`ldns_buffer` 435 :throws TypeError: When `buffer` of non-:class:`ldns_buffer` 436 type. 437 :return: (ldns_status) ldns_status 438 """ 439 return _ldns.ldns_rdf2buffer_wire(buffer, self) 440 #parameters: ldns_buffer *, const ldns_rdf *, 441 #retvals: ldns_status 442 443 def write_to_buffer_canonical(self, buffer): 444 """ 445 Copies the rdata data to the buffer in wire format. 446 If the rdata is a dname, the letters will be converted 447 to lower case during the conversion. 448 449 :param buffer: LDNS buffer. 450 :type buffer: :class:`ldns_buffer` 451 :throws TypeError: When `buffer` of non-:class:`ldns_buffer` 452 type. 453 :return: (ldns_status) ldns_status 454 """ 455 return _ldns.ldns_rdf2buffer_wire_canonical(buffer, self) 456 #parameters: ldns_buffer *, const ldns_rdf *, 457 #retvals: ldns_status 458 459 # 460 # LDNS_RDF_METHODS_ 461 # 462 463 def address_reverse(self): 464 """ 465 Reverses an rdf, only actually useful for AAAA and A records. 466 467 The returned rdf has the type LDNS_RDF_TYPE_DNAME! 468 469 :return: (:class:`ldns_rdf`) The reversed rdf 470 (a newly created rdf). 471 """ 472 return _ldns.ldns_rdf_address_reverse(self) 473 #parameters: ldns_rdf *, 474 #retvals: ldns_rdf * 475 476 def clone(self): 477 """ 478 Clones a rdf structure. 479 480 The data are copied. 481 482 :return: (:class:`ldns_rdf`) A new rdf structure. 483 """ 484 return _ldns.ldns_rdf_clone(self) 485 #parameters: const ldns_rdf *, 486 #retvals: ldns_rdf * 487 488 def data(self): 489 """ 490 Returns the data of the rdf. 491 492 :return: (uint8_t \*) uint8_t* pointer to the rdf's data. 493 """ 494 return _ldns.ldns_rdf_data(self) 495 #parameters: const ldns_rdf *, 496 #retvals: uint8_t * 497 498 def data_as_bytearray(self): 499 """ 500 Returns the data of the rdf as a bytearray. 501 502 :return: (bytearray) Bytearray containing the rdf data. 503 """ 504 return _ldns.ldns_rdf_data_as_bytearray(self) 505 #parameters: const ldns_rdf *, 506 #retvals: bytearray 507 508 def get_type(self): 509 """ 510 Returns the type of the rdf. 511 512 We need to prepend the prefix get_ here to prevent conflict 513 with the rdf_type TYPE. 514 515 :return: (ldns_rdf_type) Identifier of the type. 516 """ 517 return _ldns.ldns_rdf_get_type(self) 518 #parameters: const ldns_rdf *, 519 #retvals: ldns_rdf_type 520 521 def set_data(self, data): 522 """ 523 Sets the data portion of the rdf. 524 525 The data are not copied, but are assigned to the rdf, 526 `data` are decoupled from the Python engine. 527 528 :param data: Data to be set. 529 :type data: void \* 530 """ 531 _ldns.ldns_rdf_set_data(self, data) 532 #parameters: ldns_rdf *, void *, 533 #retvals: 534 535 def set_size(self, size): 536 """ 537 Sets the size of the rdf. 538 539 :param size: The new size. 540 :type size: integer 541 :throws TypeError: When size of non-integer type. 542 """ 543 _ldns.ldns_rdf_set_size(self,size) 544 #parameters: ldns_rdf *,size_t, 545 #retvals: 546 547 def set_type(self, atype): 548 """ 549 Sets the type of the rdf. 550 551 :param atype: rdf type 552 :type atype: integer 553 :throws TypeError: When atype of non-integer type. 554 """ 555 _ldns.ldns_rdf_set_type(self, atype) 556 #parameters: ldns_rdf *, ldns_rdf_type, 557 #retvals: 558 559 def size(self): 560 """ 561 Returns the size of the rdf. 562 563 :return: (size_t) uint16_t with the size. 564 """ 565 return _ldns.ldns_rdf_size(self) 566 #parameters: const ldns_rdf *, 567 #retvals: size_t 568 569 @staticmethod 570 def dname_new_frm_str(string): 571 """ 572 Creates a new dname rdf instance from a given string. 573 574 This static method is equivalent to using of default 575 :class:`ldns_rdf` constructor. 576 577 :parameter string: String to use. 578 :type string: string 579 :throws TypeError: When not a string used. 580 :return: :class:`ldns_rdf` or None if error. 581 582 .. warning:: 583 584 It is scheduled to be deprecated and removed. Use 585 :class:`ldns_dname` constructor instead. 586 """ 587 warnings.warn("The ldns_rdf.dname_new_frm_str() method is" + 588 " scheduled to be deprecated in future releases." + 589 " Use ldns_dname constructor instead.", 590 PendingDeprecationWarning, stacklevel=2) 591 return _ldns.ldns_dname_new_frm_str(string) 592 593 def absolute(self): 594 """ 595 Checks whether the given dname string is absolute 596 (i.e., ends with a '.'). 597 598 :return: (bool) True or False 599 600 .. note:: 601 602 This method was malfunctioning in ldns-1.3.16 and also 603 possibly earlier. 604 605 .. warning:: 606 607 It is scheduled to be deprecated and removed. Convert 608 :class:`ldns_rdf` to :class:`ldns_dname` to use the method. 609 """ 610 warnings.warn("The ldns_rdf.absolute() method is scheduled" + 611 " to be deprecated in future releases." + 612 " Convert the ldns_rdf to ldns_dname and the use its" + 613 " methods.", PendingDeprecationWarning, stacklevel=2) 614 if self.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: 615 string = self.__str__() 616 return _ldns.ldns_dname_str_absolute(string) != 0 617 else: 618 return False 619 620 def make_canonical(self): 621 """ 622 Put a dname into canonical format (i.e., convert to lower case). 623 624 Performs no action if not a dname. 625 626 .. warning:: 627 628 This method is scheduled to be deprecated and removed. 629 Convert :class:`ldns_rdf` to :class:`ldns_dname` to use 630 the method. 631 """ 632 warnings.warn("The ldns_rdf.make_canonical() method is scheduled" + 633 " to be deprecated in future releases." + 634 " Convert the ldns_rdf to ldns_dname and the use its" + 635 " methods.", PendingDeprecationWarning, stacklevel=2) 636 _ldns.ldns_dname2canonical(self) 637 638 def dname_compare(self, other): 639 """ 640 Compares two dname rdf according to the algorithm 641 for ordering in RFC4034 Section 6. 642 643 :param other: The second dname rdf to compare. 644 :type other: :class:`ldns_rdf` 645 :throws TypeError: When not a :class:`ldns_rdf` used. 646 :throws Exception: When not dnames compared. 647 :return: (int) -1, 0 or 1 if `self` comes before `other`, 648 `self` is equal or `self` comes after `other` respectively. 649 650 .. warning:: 651 652 It is scheduled to be deprecated and removed. Convert 653 :class:`ldns_rdf` to :class:`ldns_dname`. 654 """ 655 warnings.warn("The ldns_rdf.dname_compare() method is" + 656 " scheduled to be deprecated in future releases." + 657 " Convert the ldns_rdf to ldns_dname and the use its" + 658 " methods.", PendingDeprecationWarning, stacklevel=2) 659 # 660 # The wrapped function generates asserts instead of setting 661 # error status. They cannot be caught from Python so a check 662 # is necessary. 663 # 664 if not isinstance(other, ldns_rdf): 665 raise TypeError("Parameter must be derived from ldns_rdf.") 666 if (self.get_type() != _ldns.LDNS_RDF_TYPE_DNAME) or \ 667 (other.get_type() != _ldns.LDNS_RDF_TYPE_DNAME): 668 raise Exception("Both operands must be dname rdfs.") 669 return _ldns.ldns_dname_compare(self, other) 670 671 def cat(self, rd2): 672 """ 673 Concatenates `rd2` after `this` dname (`rd2` is copied, 674 `this` dname is modified). 675 676 :param rd2: The right-hand side. 677 :type rd2: :class:`ldns_rdf` 678 :throws TypeError: When `rd2` of non-:class:`ldns_rdf` or 679 non-:class:`ldns_dname` type. 680 :return: (ldns_status) LDNS_STATUS_OK on success. 681 682 .. warning:: 683 684 It is scheduled to be deprecated and removed. Convert 685 :class:`ldns_rdf` to :class:`ldns_dname`. 686 """ 687 warnings.warn("The ldns_rdf.cat() method is scheduled" + 688 " to be deprecated in future releases." + 689 " Convert the ldns_rdf to ldns_dname and the use its" + 690 " methods.", PendingDeprecationWarning, stacklevel=2) 691 return _ldns.ldns_dname_cat(self, rd2) 692 #parameters: ldns_rdf *, ldns_rdf *, 693 #retvals: ldns_status 694 695 def cat_clone(self, rd2): 696 """ 697 Concatenates two dnames together. 698 699 :param rd2: The right-hand side. 700 :type rd2: :class:`ldns_rdf` 701 :throws TypeError: When `rd2` of non-:class:`ldns_rdf` or 702 non-:class:`ldns_dname` type. 703 :return: (:class:`ldns_rdf`) A new rdf with 704 left-hand side + right-hand side content None when 705 error. 706 707 .. warning:: 708 709 It is scheduled to be deprecated and removed. Convert 710 :class:`ldns_rdf` to :class:`ldns_dname`. 711 """ 712 warnings.warn("The ldns_rdf.cat_clone() method is scheduled" + 713 " to be deprecated in future releases." + 714 " Convert the ldns_rdf to ldns_dname and the use its" + 715 " methods.", PendingDeprecationWarning, stacklevel=2) 716 return _ldns.ldns_dname_cat_clone(self, rd2) 717 #parameters: const ldns_rdf *, const ldns_rdf *, 718 #retvals: ldns_rdf * 719 720 def interval(self, middle, next): 721 """ 722 Check whether the `middle` lays in the interval defined by 723 `this` and `next` (`this` <= `middle` < `next`). 724 725 This method is useful for nsec checking 726 727 :param middle: The dname to check. 728 :type middle: :class:`ldns_rdf` 729 :param next: The boundary. 730 :type next: :class:`ldns_rdf` 731 :throws TypeError: When `middle` or `next` of 732 non-:class:`ldns_rdf` type. 733 :throws Exception: When non-dname rdfs compared. 734 :return: (int) 0 on error or unknown, 735 -1 when middle is in the interval, 1 when not. 736 737 .. warning:: 738 739 It is scheduled to be deprecated and removed. Convert 740 :class:`ldns_rdf` to :class:`ldns_dname`. 741 """ 742 warnings.warn("The ldns_rdf.interval() method is scheduled" + 743 " to be deprecated in future releases." + 744 " Convert the ldns_rdf to ldns_dname and the use its" + 745 " methods.", PendingDeprecationWarning, stacklevel=2) 746 # 747 # The wrapped function generates asserts instead of setting 748 # error status. They cannot be caught from Python so a check 749 # is necessary. 750 # 751 if (not isinstance(middle, ldns_rdf)) or \ 752 (not isinstance(next, ldns_rdf)): 753 raise TypeError("Parameters must be derived from ldns_rdf.") 754 if (self.get_type() != _ldns.LDNS_RDF_TYPE_DNAME) or \ 755 (middle.get_type() != _ldns.LDNS_RDF_TYPE_DNAME) or \ 756 (next.get_type() != _ldns.LDNS_RDF_TYPE_DNAME): 757 raise Exception("All operands must be dname rdfs.") 758 return _ldns.ldns_dname_interval(self, middle, next) 759 #parameters: const ldns_rdf *, const ldns_rdf *, const ldns_rdf *, 760 #retvals: int 761 762 def is_subdomain(self, parent): 763 """ 764 Tests whether the name of the given instance falls under 765 `parent` (i.e., is a sub-domain of `parent`). 766 767 This function will return False if the given dnames 768 are equal. 769 770 :param parent: The parent's name. 771 :type parent: :class:`ldns_rdf` 772 :throws TypeError: When `parent` of non-:class:`ldns_rdf` type. 773 :return: (bool) True if `this` falls under `parent`, otherwise 774 False. 775 776 .. warning:: 777 778 It is scheduled to be deprecated and removed. Convert 779 :class:`ldns_rdf` to :class:`ldns_dname`. 780 """ 781 warnings.warn("The ldns_rdf.is_subdomain() method is scheduled" + 782 " to be deprecated in future releases." + 783 " Convert the ldns_rdf to ldns_dname and the use its" + 784 " methods.", PendingDeprecationWarning, stacklevel=2) 785 return _ldns.ldns_dname_is_subdomain(self, parent) 786 #parameters: const ldns_rdf *, const ldns_rdf *, 787 #retvals: bool 788 789 def label(self, labelpos): 790 """ 791 Look inside the rdf and if it is an LDNS_RDF_TYPE_DNAME try 792 and retrieve a specific label. 793 794 The labels are numbered starting from 0 (left most). 795 796 :param labelpos: Index of the label. (Labels are numbered 797 0, which is the left most.) 798 :type labelpos: integer 799 :throws TypeError: When `labelpos` of non-integer type. 800 :return: (:class:`ldns_rdf`) A new rdf with the label 801 as name or None on error. 802 803 .. warning:: 804 805 It is scheduled to be deprecated and removed. Convert 806 :class:`ldns_rdf` to :class:`ldns_dname`. 807 """ 808 warnings.warn("The ldns_rdf.label() method is scheduled" + 809 " to be deprecated in future releases." + 810 " Convert the ldns_rdf to ldns_dname and the use its" + 811 " methods.", PendingDeprecationWarning, stacklevel=2) 812 return _ldns.ldns_dname_label(self, labelpos) 813 #parameters: const ldns_rdf *, uint8_t, 814 #retvals: ldns_rdf * 815 816 def label_count(self): 817 """ 818 Count the number of labels inside a LDNS_RDF_DNAME type rdf. 819 820 :return: (uint8_t) The number of labels. Will return 0 if 821 not a dname. 822 823 .. warning:: 824 825 It is scheduled to be deprecated and removed. Convert 826 :class:`ldns_rdf` to :class:`ldns_dname`. 827 """ 828 warnings.warn("The ldns_rdf.label_count() method is scheduled" + 829 " to be deprecated in future releases." + 830 " Convert the ldns_rdf to ldns_dname and the use its" + 831 " methods.", PendingDeprecationWarning, stacklevel=2) 832 return _ldns.ldns_dname_label_count(self) 833 #parameters: const ldns_rdf *, 834 #retvals: uint8_t 835 836 def left_chop(self): 837 """ 838 Chop one label off the left side of a dname. 839 840 (e.g., wwww.nlnetlabs.nl, becomes nlnetlabs.nl) 841 842 :return: (:class:`ldns_rdf`) The remaining dname or None when 843 error. 844 845 .. warning:: 846 847 It is scheduled to be deprecated and removed. Convert 848 :class:`ldns_rdf` to :class:`ldns_dname`. 849 """ 850 warnings.warn("The ldns_rdf.left_chop() method is scheduled" + 851 " to be deprecated in future releases." + 852 " Convert the ldns_rdf to ldns_dname and the use its" + 853 " methods.", PendingDeprecationWarning, stacklevel=2) 854 return _ldns.ldns_dname_left_chop(self) 855 #parameters: const ldns_rdf *, 856 #retvals: ldns_rdf * 857 858 def reverse(self): 859 """ 860 Returns a clone of the given dname with the labels reversed. 861 862 When reversing non-dnames a "." (root name) dname is returned. 863 864 :throws Exception: When used on non-dname rdfs. 865 :return: (:class:`ldns_rdf`) Clone of the dname with the labels 866 reversed or ".". 867 868 .. warning:: 869 870 It is scheduled to be deprecated and removed. Convert 871 :class:`ldns_rdf` to :class:`ldns_dname`. 872 """ 873 warnings.warn("The ldns_rdf.reverse() method is scheduled" + 874 " to be deprecated in future releases." + 875 " Convert the ldns_rdf to ldns_dname and the use its" + 876 " methods.", PendingDeprecationWarning, stacklevel=2) 877 if self.get_type() != _ldns.LDNS_RDF_TYPE_DNAME: 878 raise Exception("Operand must be a dname rdf.") 879 return _ldns.ldns_dname_reverse(self) 880 #parameters: const ldns_rdf *, 881 #retvals: ldns_rdf * 882 883 # 884 # _LDNS_RDF_METHODS 885 # 886 %} 887 } 888