/contrib/bind9/lib/dns/rdata/generic/x25_19.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 224 lines · 151 code · 54 blank · 19 comment · 40 complexity · 44bdc8060dd6b3d249ca6c8a9018410d MD5 · raw file

  1. /*
  2. * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 1999-2002 Internet Software Consortium.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. * PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /* $Id: x25_19.c,v 1.41 2009/12/04 22:06:37 tbox Exp $ */
  18. /* Reviewed: Thu Mar 16 16:15:57 PST 2000 by bwelling */
  19. /* RFC1183 */
  20. #ifndef RDATA_GENERIC_X25_19_C
  21. #define RDATA_GENERIC_X25_19_C
  22. #define RRTYPE_X25_ATTRIBUTES (0)
  23. static inline isc_result_t
  24. fromtext_x25(ARGS_FROMTEXT) {
  25. isc_token_t token;
  26. unsigned int i;
  27. REQUIRE(type == 19);
  28. UNUSED(type);
  29. UNUSED(rdclass);
  30. UNUSED(origin);
  31. UNUSED(options);
  32. UNUSED(callbacks);
  33. RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
  34. ISC_FALSE));
  35. if (token.value.as_textregion.length < 4)
  36. RETTOK(DNS_R_SYNTAX);
  37. for (i = 0; i < token.value.as_textregion.length; i++)
  38. if (!isdigit(token.value.as_textregion.base[i] & 0xff))
  39. RETTOK(ISC_R_RANGE);
  40. RETTOK(txt_fromtext(&token.value.as_textregion, target));
  41. return (ISC_R_SUCCESS);
  42. }
  43. static inline isc_result_t
  44. totext_x25(ARGS_TOTEXT) {
  45. isc_region_t region;
  46. UNUSED(tctx);
  47. REQUIRE(rdata->type == 19);
  48. REQUIRE(rdata->length != 0);
  49. dns_rdata_toregion(rdata, &region);
  50. return (txt_totext(&region, target));
  51. }
  52. static inline isc_result_t
  53. fromwire_x25(ARGS_FROMWIRE) {
  54. isc_region_t sr;
  55. REQUIRE(type == 19);
  56. UNUSED(type);
  57. UNUSED(dctx);
  58. UNUSED(rdclass);
  59. UNUSED(options);
  60. isc_buffer_activeregion(source, &sr);
  61. if (sr.length < 5)
  62. return (DNS_R_FORMERR);
  63. return (txt_fromwire(source, target));
  64. }
  65. static inline isc_result_t
  66. towire_x25(ARGS_TOWIRE) {
  67. UNUSED(cctx);
  68. REQUIRE(rdata->type == 19);
  69. REQUIRE(rdata->length != 0);
  70. return (mem_tobuffer(target, rdata->data, rdata->length));
  71. }
  72. static inline int
  73. compare_x25(ARGS_COMPARE) {
  74. isc_region_t r1;
  75. isc_region_t r2;
  76. REQUIRE(rdata1->type == rdata2->type);
  77. REQUIRE(rdata1->rdclass == rdata2->rdclass);
  78. REQUIRE(rdata1->type == 19);
  79. REQUIRE(rdata1->length != 0);
  80. REQUIRE(rdata2->length != 0);
  81. dns_rdata_toregion(rdata1, &r1);
  82. dns_rdata_toregion(rdata2, &r2);
  83. return (isc_region_compare(&r1, &r2));
  84. }
  85. static inline isc_result_t
  86. fromstruct_x25(ARGS_FROMSTRUCT) {
  87. dns_rdata_x25_t *x25 = source;
  88. isc_uint8_t i;
  89. REQUIRE(type == 19);
  90. REQUIRE(source != NULL);
  91. REQUIRE(x25->common.rdtype == type);
  92. REQUIRE(x25->common.rdclass == rdclass);
  93. REQUIRE(x25->x25 != NULL && x25->x25_len != 0);
  94. UNUSED(type);
  95. UNUSED(rdclass);
  96. if (x25->x25_len < 4)
  97. return (ISC_R_RANGE);
  98. for (i = 0; i < x25->x25_len; i++)
  99. if (!isdigit(x25->x25[i] & 0xff))
  100. return (ISC_R_RANGE);
  101. RETERR(uint8_tobuffer(x25->x25_len, target));
  102. return (mem_tobuffer(target, x25->x25, x25->x25_len));
  103. }
  104. static inline isc_result_t
  105. tostruct_x25(ARGS_TOSTRUCT) {
  106. dns_rdata_x25_t *x25 = target;
  107. isc_region_t r;
  108. REQUIRE(rdata->type == 19);
  109. REQUIRE(target != NULL);
  110. REQUIRE(rdata->length != 0);
  111. x25->common.rdclass = rdata->rdclass;
  112. x25->common.rdtype = rdata->type;
  113. ISC_LINK_INIT(&x25->common, link);
  114. dns_rdata_toregion(rdata, &r);
  115. x25->x25_len = uint8_fromregion(&r);
  116. isc_region_consume(&r, 1);
  117. x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len);
  118. if (x25->x25 == NULL)
  119. return (ISC_R_NOMEMORY);
  120. x25->mctx = mctx;
  121. return (ISC_R_SUCCESS);
  122. }
  123. static inline void
  124. freestruct_x25(ARGS_FREESTRUCT) {
  125. dns_rdata_x25_t *x25 = source;
  126. REQUIRE(source != NULL);
  127. REQUIRE(x25->common.rdtype == 19);
  128. if (x25->mctx == NULL)
  129. return;
  130. if (x25->x25 != NULL)
  131. isc_mem_free(x25->mctx, x25->x25);
  132. x25->mctx = NULL;
  133. }
  134. static inline isc_result_t
  135. additionaldata_x25(ARGS_ADDLDATA) {
  136. REQUIRE(rdata->type == 19);
  137. UNUSED(rdata);
  138. UNUSED(add);
  139. UNUSED(arg);
  140. return (ISC_R_SUCCESS);
  141. }
  142. static inline isc_result_t
  143. digest_x25(ARGS_DIGEST) {
  144. isc_region_t r;
  145. REQUIRE(rdata->type == 19);
  146. dns_rdata_toregion(rdata, &r);
  147. return ((digest)(arg, &r));
  148. }
  149. static inline isc_boolean_t
  150. checkowner_x25(ARGS_CHECKOWNER) {
  151. REQUIRE(type == 19);
  152. UNUSED(name);
  153. UNUSED(type);
  154. UNUSED(rdclass);
  155. UNUSED(wildcard);
  156. return (ISC_TRUE);
  157. }
  158. static inline isc_boolean_t
  159. checknames_x25(ARGS_CHECKNAMES) {
  160. REQUIRE(rdata->type == 19);
  161. UNUSED(rdata);
  162. UNUSED(owner);
  163. UNUSED(bad);
  164. return (ISC_TRUE);
  165. }
  166. static inline int
  167. casecompare_x25(ARGS_COMPARE) {
  168. return (compare_x25(rdata1, rdata2));
  169. }
  170. #endif /* RDATA_GENERIC_X25_19_C */