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

https://bitbucket.org/freebsd/freebsd-head/ · C · 242 lines · 167 code · 56 blank · 19 comment · 41 complexity · b0813f4a9956fe7202ac52becaf931d5 MD5 · raw file

  1. /*
  2. * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 1998-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: spf_99.c,v 1.6 2009/12/04 22:06:37 tbox Exp $ */
  18. /* Reviewed: Thu Mar 16 15:40:00 PST 2000 by bwelling */
  19. #ifndef RDATA_GENERIC_SPF_99_C
  20. #define RDATA_GENERIC_SPF_99_C
  21. #define RRTYPE_SPF_ATTRIBUTES (0)
  22. static inline isc_result_t
  23. fromtext_spf(ARGS_FROMTEXT) {
  24. isc_token_t token;
  25. int strings;
  26. REQUIRE(type == 99);
  27. UNUSED(type);
  28. UNUSED(rdclass);
  29. UNUSED(origin);
  30. UNUSED(options);
  31. UNUSED(callbacks);
  32. strings = 0;
  33. for (;;) {
  34. RETERR(isc_lex_getmastertoken(lexer, &token,
  35. isc_tokentype_qstring,
  36. ISC_TRUE));
  37. if (token.type != isc_tokentype_qstring &&
  38. token.type != isc_tokentype_string)
  39. break;
  40. RETTOK(txt_fromtext(&token.value.as_textregion, target));
  41. strings++;
  42. }
  43. /* Let upper layer handle eol/eof. */
  44. isc_lex_ungettoken(lexer, &token);
  45. return (strings == 0 ? ISC_R_UNEXPECTEDEND : ISC_R_SUCCESS);
  46. }
  47. static inline isc_result_t
  48. totext_spf(ARGS_TOTEXT) {
  49. isc_region_t region;
  50. UNUSED(tctx);
  51. REQUIRE(rdata->type == 99);
  52. dns_rdata_toregion(rdata, &region);
  53. while (region.length > 0) {
  54. RETERR(txt_totext(&region, target));
  55. if (region.length > 0)
  56. RETERR(str_totext(" ", target));
  57. }
  58. return (ISC_R_SUCCESS);
  59. }
  60. static inline isc_result_t
  61. fromwire_spf(ARGS_FROMWIRE) {
  62. isc_result_t result;
  63. REQUIRE(type == 99);
  64. UNUSED(type);
  65. UNUSED(dctx);
  66. UNUSED(rdclass);
  67. UNUSED(options);
  68. do {
  69. result = txt_fromwire(source, target);
  70. if (result != ISC_R_SUCCESS)
  71. return (result);
  72. } while (!buffer_empty(source));
  73. return (ISC_R_SUCCESS);
  74. }
  75. static inline isc_result_t
  76. towire_spf(ARGS_TOWIRE) {
  77. isc_region_t region;
  78. REQUIRE(rdata->type == 99);
  79. UNUSED(cctx);
  80. isc_buffer_availableregion(target, &region);
  81. if (region.length < rdata->length)
  82. return (ISC_R_NOSPACE);
  83. memcpy(region.base, rdata->data, rdata->length);
  84. isc_buffer_add(target, rdata->length);
  85. return (ISC_R_SUCCESS);
  86. }
  87. static inline int
  88. compare_spf(ARGS_COMPARE) {
  89. isc_region_t r1;
  90. isc_region_t r2;
  91. REQUIRE(rdata1->type == rdata2->type);
  92. REQUIRE(rdata1->rdclass == rdata2->rdclass);
  93. REQUIRE(rdata1->type == 99);
  94. dns_rdata_toregion(rdata1, &r1);
  95. dns_rdata_toregion(rdata2, &r2);
  96. return (isc_region_compare(&r1, &r2));
  97. }
  98. static inline isc_result_t
  99. fromstruct_spf(ARGS_FROMSTRUCT) {
  100. dns_rdata_spf_t *txt = source;
  101. isc_region_t region;
  102. isc_uint8_t length;
  103. REQUIRE(type == 99);
  104. REQUIRE(source != NULL);
  105. REQUIRE(txt->common.rdtype == type);
  106. REQUIRE(txt->common.rdclass == rdclass);
  107. REQUIRE(txt->txt != NULL && txt->txt_len != 0);
  108. UNUSED(type);
  109. UNUSED(rdclass);
  110. region.base = txt->txt;
  111. region.length = txt->txt_len;
  112. while (region.length > 0) {
  113. length = uint8_fromregion(&region);
  114. isc_region_consume(&region, 1);
  115. if (region.length <= length)
  116. return (ISC_R_UNEXPECTEDEND);
  117. isc_region_consume(&region, length);
  118. }
  119. return (mem_tobuffer(target, txt->txt, txt->txt_len));
  120. }
  121. static inline isc_result_t
  122. tostruct_spf(ARGS_TOSTRUCT) {
  123. dns_rdata_spf_t *txt = target;
  124. isc_region_t r;
  125. REQUIRE(rdata->type == 99);
  126. REQUIRE(target != NULL);
  127. txt->common.rdclass = rdata->rdclass;
  128. txt->common.rdtype = rdata->type;
  129. ISC_LINK_INIT(&txt->common, link);
  130. dns_rdata_toregion(rdata, &r);
  131. txt->txt_len = r.length;
  132. txt->txt = mem_maybedup(mctx, r.base, r.length);
  133. if (txt->txt == NULL)
  134. return (ISC_R_NOMEMORY);
  135. txt->offset = 0;
  136. txt->mctx = mctx;
  137. return (ISC_R_SUCCESS);
  138. }
  139. static inline void
  140. freestruct_spf(ARGS_FREESTRUCT) {
  141. dns_rdata_spf_t *txt = source;
  142. REQUIRE(source != NULL);
  143. REQUIRE(txt->common.rdtype == 99);
  144. if (txt->mctx == NULL)
  145. return;
  146. if (txt->txt != NULL)
  147. isc_mem_free(txt->mctx, txt->txt);
  148. txt->mctx = NULL;
  149. }
  150. static inline isc_result_t
  151. additionaldata_spf(ARGS_ADDLDATA) {
  152. REQUIRE(rdata->type == 99);
  153. UNUSED(rdata);
  154. UNUSED(add);
  155. UNUSED(arg);
  156. return (ISC_R_SUCCESS);
  157. }
  158. static inline isc_result_t
  159. digest_spf(ARGS_DIGEST) {
  160. isc_region_t r;
  161. REQUIRE(rdata->type == 99);
  162. dns_rdata_toregion(rdata, &r);
  163. return ((digest)(arg, &r));
  164. }
  165. static inline isc_boolean_t
  166. checkowner_spf(ARGS_CHECKOWNER) {
  167. REQUIRE(type == 99);
  168. UNUSED(name);
  169. UNUSED(type);
  170. UNUSED(rdclass);
  171. UNUSED(wildcard);
  172. return (ISC_TRUE);
  173. }
  174. static inline isc_boolean_t
  175. checknames_spf(ARGS_CHECKNAMES) {
  176. REQUIRE(rdata->type == 99);
  177. UNUSED(rdata);
  178. UNUSED(owner);
  179. UNUSED(bad);
  180. return (ISC_TRUE);
  181. }
  182. static inline int
  183. casecompare_spf(ARGS_COMPARE) {
  184. return (compare_spf(rdata1, rdata2));
  185. }
  186. #endif /* RDATA_GENERIC_SPF_99_C */