/contrib/bind9/lib/dns/rdata/in_1/dhcid_49.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 234 lines · 162 code · 55 blank · 17 comment · 50 complexity · e2e06517e2b105aae94cfbeea13c416c MD5 · raw file

  1. /*
  2. * Copyright (C) 2006, 2007, 2009, 2012 Internet Systems Consortium, Inc. ("ISC")
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  9. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  10. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  12. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  13. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  14. * PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /* $Id$ */
  17. /* RFC 4701 */
  18. #ifndef RDATA_IN_1_DHCID_49_C
  19. #define RDATA_IN_1_DHCID_49_C 1
  20. #define RRTYPE_DHCID_ATTRIBUTES 0
  21. static inline isc_result_t
  22. fromtext_in_dhcid(ARGS_FROMTEXT) {
  23. REQUIRE(type == 49);
  24. REQUIRE(rdclass == 1);
  25. UNUSED(type);
  26. UNUSED(rdclass);
  27. UNUSED(origin);
  28. UNUSED(options);
  29. UNUSED(callbacks);
  30. return (isc_base64_tobuffer(lexer, target, -1));
  31. }
  32. static inline isc_result_t
  33. totext_in_dhcid(ARGS_TOTEXT) {
  34. isc_region_t sr;
  35. char buf[sizeof(" ; 64000 255 64000")];
  36. size_t n;
  37. REQUIRE(rdata->type == 49);
  38. REQUIRE(rdata->rdclass == 1);
  39. REQUIRE(rdata->length != 0);
  40. dns_rdata_toregion(rdata, &sr);
  41. if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
  42. RETERR(str_totext("( " /*)*/, target));
  43. RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak,
  44. target));
  45. if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
  46. RETERR(str_totext(/* ( */ " )", target));
  47. if (rdata->length > 2) {
  48. n = snprintf(buf, sizeof(buf), " ; %u %u %u",
  49. sr.base[0] * 256 + sr.base[1],
  50. sr.base[2], rdata->length - 3);
  51. INSIST(n < sizeof(buf));
  52. RETERR(str_totext(buf, target));
  53. }
  54. }
  55. return (ISC_R_SUCCESS);
  56. }
  57. static inline isc_result_t
  58. fromwire_in_dhcid(ARGS_FROMWIRE) {
  59. isc_region_t sr;
  60. REQUIRE(type == 49);
  61. REQUIRE(rdclass == 1);
  62. UNUSED(type);
  63. UNUSED(rdclass);
  64. UNUSED(dctx);
  65. UNUSED(options);
  66. isc_buffer_activeregion(source, &sr);
  67. if (sr.length == 0)
  68. return (ISC_R_UNEXPECTEDEND);
  69. isc_buffer_forward(source, sr.length);
  70. return (mem_tobuffer(target, sr.base, sr.length));
  71. }
  72. static inline isc_result_t
  73. towire_in_dhcid(ARGS_TOWIRE) {
  74. isc_region_t sr;
  75. REQUIRE(rdata->type == 49);
  76. REQUIRE(rdata->rdclass == 1);
  77. REQUIRE(rdata->length != 0);
  78. UNUSED(cctx);
  79. dns_rdata_toregion(rdata, &sr);
  80. return (mem_tobuffer(target, sr.base, sr.length));
  81. }
  82. static inline int
  83. compare_in_dhcid(ARGS_COMPARE) {
  84. isc_region_t r1;
  85. isc_region_t r2;
  86. REQUIRE(rdata1->type == rdata2->type);
  87. REQUIRE(rdata1->rdclass == rdata2->rdclass);
  88. REQUIRE(rdata1->type == 49);
  89. REQUIRE(rdata1->rdclass == 1);
  90. REQUIRE(rdata1->length != 0);
  91. REQUIRE(rdata2->length != 0);
  92. dns_rdata_toregion(rdata1, &r1);
  93. dns_rdata_toregion(rdata2, &r2);
  94. return (isc_region_compare(&r1, &r2));
  95. }
  96. static inline isc_result_t
  97. fromstruct_in_dhcid(ARGS_FROMSTRUCT) {
  98. dns_rdata_in_dhcid_t *dhcid = source;
  99. REQUIRE(type == 49);
  100. REQUIRE(rdclass == 1);
  101. REQUIRE(source != NULL);
  102. REQUIRE(dhcid->common.rdtype == type);
  103. REQUIRE(dhcid->common.rdclass == rdclass);
  104. REQUIRE(dhcid->length != 0);
  105. UNUSED(type);
  106. UNUSED(rdclass);
  107. return (mem_tobuffer(target, dhcid->dhcid, dhcid->length));
  108. }
  109. static inline isc_result_t
  110. tostruct_in_dhcid(ARGS_TOSTRUCT) {
  111. dns_rdata_in_dhcid_t *dhcid = target;
  112. isc_region_t region;
  113. REQUIRE(rdata->type == 49);
  114. REQUIRE(rdata->rdclass == 1);
  115. REQUIRE(target != NULL);
  116. REQUIRE(rdata->length != 0);
  117. dhcid->common.rdclass = rdata->rdclass;
  118. dhcid->common.rdtype = rdata->type;
  119. ISC_LINK_INIT(&dhcid->common, link);
  120. dns_rdata_toregion(rdata, &region);
  121. dhcid->dhcid = mem_maybedup(mctx, region.base, region.length);
  122. if (dhcid->dhcid == NULL)
  123. return (ISC_R_NOMEMORY);
  124. dhcid->mctx = mctx;
  125. return (ISC_R_SUCCESS);
  126. }
  127. static inline void
  128. freestruct_in_dhcid(ARGS_FREESTRUCT) {
  129. dns_rdata_in_dhcid_t *dhcid = source;
  130. REQUIRE(dhcid != NULL);
  131. REQUIRE(dhcid->common.rdtype == 49);
  132. REQUIRE(dhcid->common.rdclass == 1);
  133. if (dhcid->mctx == NULL)
  134. return;
  135. if (dhcid->dhcid != NULL)
  136. isc_mem_free(dhcid->mctx, dhcid->dhcid);
  137. dhcid->mctx = NULL;
  138. }
  139. static inline isc_result_t
  140. additionaldata_in_dhcid(ARGS_ADDLDATA) {
  141. REQUIRE(rdata->type == 49);
  142. REQUIRE(rdata->rdclass == 1);
  143. UNUSED(rdata);
  144. UNUSED(add);
  145. UNUSED(arg);
  146. return (ISC_R_SUCCESS);
  147. }
  148. static inline isc_result_t
  149. digest_in_dhcid(ARGS_DIGEST) {
  150. isc_region_t r;
  151. REQUIRE(rdata->type == 49);
  152. REQUIRE(rdata->rdclass == 1);
  153. dns_rdata_toregion(rdata, &r);
  154. return ((digest)(arg, &r));
  155. }
  156. static inline isc_boolean_t
  157. checkowner_in_dhcid(ARGS_CHECKOWNER) {
  158. REQUIRE(type == 49);
  159. REQUIRE(rdclass == 1);
  160. UNUSED(name);
  161. UNUSED(type);
  162. UNUSED(rdclass);
  163. UNUSED(wildcard);
  164. return (ISC_TRUE);
  165. }
  166. static inline isc_boolean_t
  167. checknames_in_dhcid(ARGS_CHECKNAMES) {
  168. REQUIRE(rdata->type == 49);
  169. REQUIRE(rdata->rdclass == 1);
  170. UNUSED(rdata);
  171. UNUSED(owner);
  172. UNUSED(bad);
  173. return (ISC_TRUE);
  174. }
  175. static inline int
  176. casecompare_in_dhcid(ARGS_COMPARE) {
  177. return (compare_in_dhcid(rdata1, rdata2));
  178. }
  179. #endif /* RDATA_IN_1_DHCID_49_C */