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

https://bitbucket.org/freebsd/freebsd-head/ · C · 260 lines · 186 code · 54 blank · 20 comment · 63 complexity · 03b94c9a36cbfcccca08c54b9cd958da 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: nsap_22.c,v 1.44 2009/12/04 22:06:37 tbox Exp $ */
  18. /* Reviewed: Fri Mar 17 10:41:07 PST 2000 by gson */
  19. /* RFC1706 */
  20. #ifndef RDATA_IN_1_NSAP_22_C
  21. #define RDATA_IN_1_NSAP_22_C
  22. #define RRTYPE_NSAP_ATTRIBUTES (0)
  23. static inline isc_result_t
  24. fromtext_in_nsap(ARGS_FROMTEXT) {
  25. isc_token_t token;
  26. isc_textregion_t *sr;
  27. int n;
  28. int digits;
  29. unsigned char c = 0;
  30. REQUIRE(type == 22);
  31. REQUIRE(rdclass == 1);
  32. UNUSED(type);
  33. UNUSED(origin);
  34. UNUSED(options);
  35. UNUSED(rdclass);
  36. UNUSED(callbacks);
  37. /* 0x<hex.string.with.periods> */
  38. RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
  39. ISC_FALSE));
  40. sr = &token.value.as_textregion;
  41. if (sr->length < 2)
  42. RETTOK(ISC_R_UNEXPECTEDEND);
  43. if (sr->base[0] != '0' || (sr->base[1] != 'x' && sr->base[1] != 'X'))
  44. RETTOK(DNS_R_SYNTAX);
  45. isc_textregion_consume(sr, 2);
  46. digits = 0;
  47. n = 0;
  48. while (sr->length > 0) {
  49. if (sr->base[0] == '.') {
  50. isc_textregion_consume(sr, 1);
  51. continue;
  52. }
  53. if ((n = hexvalue(sr->base[0])) == -1)
  54. RETTOK(DNS_R_SYNTAX);
  55. c <<= 4;
  56. c += n;
  57. if (++digits == 2) {
  58. RETERR(mem_tobuffer(target, &c, 1));
  59. digits = 0;
  60. }
  61. isc_textregion_consume(sr, 1);
  62. }
  63. if (digits)
  64. RETTOK(ISC_R_UNEXPECTEDEND);
  65. return (ISC_R_SUCCESS);
  66. }
  67. static inline isc_result_t
  68. totext_in_nsap(ARGS_TOTEXT) {
  69. isc_region_t region;
  70. char buf[sizeof("xx")];
  71. REQUIRE(rdata->type == 22);
  72. REQUIRE(rdata->rdclass == 1);
  73. REQUIRE(rdata->length != 0);
  74. UNUSED(tctx);
  75. dns_rdata_toregion(rdata, &region);
  76. RETERR(str_totext("0x", target));
  77. while (region.length != 0) {
  78. sprintf(buf, "%02x", region.base[0]);
  79. isc_region_consume(&region, 1);
  80. RETERR(str_totext(buf, target));
  81. }
  82. return (ISC_R_SUCCESS);
  83. }
  84. static inline isc_result_t
  85. fromwire_in_nsap(ARGS_FROMWIRE) {
  86. isc_region_t region;
  87. REQUIRE(type == 22);
  88. REQUIRE(rdclass == 1);
  89. UNUSED(type);
  90. UNUSED(dctx);
  91. UNUSED(options);
  92. UNUSED(rdclass);
  93. isc_buffer_activeregion(source, &region);
  94. if (region.length < 1)
  95. return (ISC_R_UNEXPECTEDEND);
  96. RETERR(mem_tobuffer(target, region.base, region.length));
  97. isc_buffer_forward(source, region.length);
  98. return (ISC_R_SUCCESS);
  99. }
  100. static inline isc_result_t
  101. towire_in_nsap(ARGS_TOWIRE) {
  102. REQUIRE(rdata->type == 22);
  103. REQUIRE(rdata->rdclass == 1);
  104. REQUIRE(rdata->length != 0);
  105. UNUSED(cctx);
  106. return (mem_tobuffer(target, rdata->data, rdata->length));
  107. }
  108. static inline int
  109. compare_in_nsap(ARGS_COMPARE) {
  110. isc_region_t r1;
  111. isc_region_t r2;
  112. REQUIRE(rdata1->type == rdata2->type);
  113. REQUIRE(rdata1->rdclass == rdata2->rdclass);
  114. REQUIRE(rdata1->type == 22);
  115. REQUIRE(rdata1->rdclass == 1);
  116. REQUIRE(rdata1->length != 0);
  117. REQUIRE(rdata2->length != 0);
  118. dns_rdata_toregion(rdata1, &r1);
  119. dns_rdata_toregion(rdata2, &r2);
  120. return (isc_region_compare(&r1, &r2));
  121. }
  122. static inline isc_result_t
  123. fromstruct_in_nsap(ARGS_FROMSTRUCT) {
  124. dns_rdata_in_nsap_t *nsap = source;
  125. REQUIRE(type == 22);
  126. REQUIRE(rdclass == 1);
  127. REQUIRE(source != NULL);
  128. REQUIRE(nsap->common.rdtype == type);
  129. REQUIRE(nsap->common.rdclass == rdclass);
  130. REQUIRE(nsap->nsap != NULL || nsap->nsap_len == 0);
  131. UNUSED(type);
  132. UNUSED(rdclass);
  133. return (mem_tobuffer(target, nsap->nsap, nsap->nsap_len));
  134. }
  135. static inline isc_result_t
  136. tostruct_in_nsap(ARGS_TOSTRUCT) {
  137. dns_rdata_in_nsap_t *nsap = target;
  138. isc_region_t r;
  139. REQUIRE(rdata->type == 22);
  140. REQUIRE(rdata->rdclass == 1);
  141. REQUIRE(target != NULL);
  142. REQUIRE(rdata->length != 0);
  143. nsap->common.rdclass = rdata->rdclass;
  144. nsap->common.rdtype = rdata->type;
  145. ISC_LINK_INIT(&nsap->common, link);
  146. dns_rdata_toregion(rdata, &r);
  147. nsap->nsap_len = r.length;
  148. nsap->nsap = mem_maybedup(mctx, r.base, r.length);
  149. if (nsap->nsap == NULL)
  150. return (ISC_R_NOMEMORY);
  151. nsap->mctx = mctx;
  152. return (ISC_R_SUCCESS);
  153. }
  154. static inline void
  155. freestruct_in_nsap(ARGS_FREESTRUCT) {
  156. dns_rdata_in_nsap_t *nsap = source;
  157. REQUIRE(source != NULL);
  158. REQUIRE(nsap->common.rdclass == 1);
  159. REQUIRE(nsap->common.rdtype == 22);
  160. if (nsap->mctx == NULL)
  161. return;
  162. if (nsap->nsap != NULL)
  163. isc_mem_free(nsap->mctx, nsap->nsap);
  164. nsap->mctx = NULL;
  165. }
  166. static inline isc_result_t
  167. additionaldata_in_nsap(ARGS_ADDLDATA) {
  168. REQUIRE(rdata->type == 22);
  169. REQUIRE(rdata->rdclass == 1);
  170. UNUSED(rdata);
  171. UNUSED(add);
  172. UNUSED(arg);
  173. return (ISC_R_SUCCESS);
  174. }
  175. static inline isc_result_t
  176. digest_in_nsap(ARGS_DIGEST) {
  177. isc_region_t r;
  178. REQUIRE(rdata->type == 22);
  179. REQUIRE(rdata->rdclass == 1);
  180. dns_rdata_toregion(rdata, &r);
  181. return ((digest)(arg, &r));
  182. }
  183. static inline isc_boolean_t
  184. checkowner_in_nsap(ARGS_CHECKOWNER) {
  185. REQUIRE(type == 22);
  186. REQUIRE(rdclass == 1);
  187. UNUSED(name);
  188. UNUSED(type);
  189. UNUSED(rdclass);
  190. UNUSED(wildcard);
  191. return (ISC_TRUE);
  192. }
  193. static inline isc_boolean_t
  194. checknames_in_nsap(ARGS_CHECKNAMES) {
  195. REQUIRE(rdata->type == 22);
  196. REQUIRE(rdata->rdclass == 1);
  197. UNUSED(rdata);
  198. UNUSED(owner);
  199. UNUSED(bad);
  200. return (ISC_TRUE);
  201. }
  202. static inline int
  203. casecompare_in_nsap(ARGS_COMPARE) {
  204. return (compare_in_nsap(rdata1, rdata2));
  205. }
  206. #endif /* RDATA_IN_1_NSAP_22_C */