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

https://bitbucket.org/freebsd/freebsd-head/ · C · 257 lines · 178 code · 60 blank · 19 comment · 52 complexity · 4f6b5582b5bfe8d74852455201cd739c 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: gpos_27.c,v 1.43 2009/12/04 22:06:37 tbox Exp $ */
  18. /* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
  19. /* RFC1712 */
  20. #ifndef RDATA_GENERIC_GPOS_27_C
  21. #define RDATA_GENERIC_GPOS_27_C
  22. #define RRTYPE_GPOS_ATTRIBUTES (0)
  23. static inline isc_result_t
  24. fromtext_gpos(ARGS_FROMTEXT) {
  25. isc_token_t token;
  26. int i;
  27. REQUIRE(type == 27);
  28. UNUSED(type);
  29. UNUSED(rdclass);
  30. UNUSED(origin);
  31. UNUSED(options);
  32. UNUSED(callbacks);
  33. for (i = 0; i < 3; i++) {
  34. RETERR(isc_lex_getmastertoken(lexer, &token,
  35. isc_tokentype_qstring,
  36. ISC_FALSE));
  37. RETTOK(txt_fromtext(&token.value.as_textregion, target));
  38. }
  39. return (ISC_R_SUCCESS);
  40. }
  41. static inline isc_result_t
  42. totext_gpos(ARGS_TOTEXT) {
  43. isc_region_t region;
  44. int i;
  45. REQUIRE(rdata->type == 27);
  46. REQUIRE(rdata->length != 0);
  47. UNUSED(tctx);
  48. dns_rdata_toregion(rdata, &region);
  49. for (i = 0; i < 3; i++) {
  50. RETERR(txt_totext(&region, target));
  51. if (i != 2)
  52. RETERR(str_totext(" ", target));
  53. }
  54. return (ISC_R_SUCCESS);
  55. }
  56. static inline isc_result_t
  57. fromwire_gpos(ARGS_FROMWIRE) {
  58. int i;
  59. REQUIRE(type == 27);
  60. UNUSED(type);
  61. UNUSED(dctx);
  62. UNUSED(rdclass);
  63. UNUSED(options);
  64. for (i = 0; i < 3; i++)
  65. RETERR(txt_fromwire(source, target));
  66. return (ISC_R_SUCCESS);
  67. }
  68. static inline isc_result_t
  69. towire_gpos(ARGS_TOWIRE) {
  70. REQUIRE(rdata->type == 27);
  71. REQUIRE(rdata->length != 0);
  72. UNUSED(cctx);
  73. return (mem_tobuffer(target, rdata->data, rdata->length));
  74. }
  75. static inline int
  76. compare_gpos(ARGS_COMPARE) {
  77. isc_region_t r1;
  78. isc_region_t r2;
  79. REQUIRE(rdata1->type == rdata2->type);
  80. REQUIRE(rdata1->rdclass == rdata2->rdclass);
  81. REQUIRE(rdata1->type == 27);
  82. REQUIRE(rdata1->length != 0);
  83. REQUIRE(rdata2->length != 0);
  84. dns_rdata_toregion(rdata1, &r1);
  85. dns_rdata_toregion(rdata2, &r2);
  86. return (isc_region_compare(&r1, &r2));
  87. }
  88. static inline isc_result_t
  89. fromstruct_gpos(ARGS_FROMSTRUCT) {
  90. dns_rdata_gpos_t *gpos = source;
  91. REQUIRE(type == 27);
  92. REQUIRE(source != NULL);
  93. REQUIRE(gpos->common.rdtype == type);
  94. REQUIRE(gpos->common.rdclass == rdclass);
  95. UNUSED(type);
  96. UNUSED(rdclass);
  97. RETERR(uint8_tobuffer(gpos->long_len, target));
  98. RETERR(mem_tobuffer(target, gpos->longitude, gpos->long_len));
  99. RETERR(uint8_tobuffer(gpos->lat_len, target));
  100. RETERR(mem_tobuffer(target, gpos->latitude, gpos->lat_len));
  101. RETERR(uint8_tobuffer(gpos->alt_len, target));
  102. return (mem_tobuffer(target, gpos->altitude, gpos->alt_len));
  103. }
  104. static inline isc_result_t
  105. tostruct_gpos(ARGS_TOSTRUCT) {
  106. dns_rdata_gpos_t *gpos = target;
  107. isc_region_t region;
  108. REQUIRE(rdata->type == 27);
  109. REQUIRE(target != NULL);
  110. REQUIRE(rdata->length != 0);
  111. gpos->common.rdclass = rdata->rdclass;
  112. gpos->common.rdtype = rdata->type;
  113. ISC_LINK_INIT(&gpos->common, link);
  114. dns_rdata_toregion(rdata, &region);
  115. gpos->long_len = uint8_fromregion(&region);
  116. isc_region_consume(&region, 1);
  117. gpos->longitude = mem_maybedup(mctx, region.base, gpos->long_len);
  118. if (gpos->longitude == NULL)
  119. return (ISC_R_NOMEMORY);
  120. isc_region_consume(&region, gpos->long_len);
  121. gpos->lat_len = uint8_fromregion(&region);
  122. isc_region_consume(&region, 1);
  123. gpos->latitude = mem_maybedup(mctx, region.base, gpos->lat_len);
  124. if (gpos->latitude == NULL)
  125. goto cleanup_longitude;
  126. isc_region_consume(&region, gpos->lat_len);
  127. gpos->alt_len = uint8_fromregion(&region);
  128. isc_region_consume(&region, 1);
  129. if (gpos->lat_len > 0) {
  130. gpos->altitude =
  131. mem_maybedup(mctx, region.base, gpos->alt_len);
  132. if (gpos->altitude == NULL)
  133. goto cleanup_latitude;
  134. } else
  135. gpos->altitude = NULL;
  136. gpos->mctx = mctx;
  137. return (ISC_R_SUCCESS);
  138. cleanup_latitude:
  139. if (mctx != NULL && gpos->longitude != NULL)
  140. isc_mem_free(mctx, gpos->longitude);
  141. cleanup_longitude:
  142. if (mctx != NULL && gpos->latitude != NULL)
  143. isc_mem_free(mctx, gpos->latitude);
  144. return (ISC_R_NOMEMORY);
  145. }
  146. static inline void
  147. freestruct_gpos(ARGS_FREESTRUCT) {
  148. dns_rdata_gpos_t *gpos = source;
  149. REQUIRE(source != NULL);
  150. REQUIRE(gpos->common.rdtype == 27);
  151. if (gpos->mctx == NULL)
  152. return;
  153. if (gpos->longitude != NULL)
  154. isc_mem_free(gpos->mctx, gpos->longitude);
  155. if (gpos->latitude != NULL)
  156. isc_mem_free(gpos->mctx, gpos->latitude);
  157. if (gpos->altitude != NULL)
  158. isc_mem_free(gpos->mctx, gpos->altitude);
  159. gpos->mctx = NULL;
  160. }
  161. static inline isc_result_t
  162. additionaldata_gpos(ARGS_ADDLDATA) {
  163. REQUIRE(rdata->type == 27);
  164. UNUSED(rdata);
  165. UNUSED(add);
  166. UNUSED(arg);
  167. return (ISC_R_SUCCESS);
  168. }
  169. static inline isc_result_t
  170. digest_gpos(ARGS_DIGEST) {
  171. isc_region_t r;
  172. REQUIRE(rdata->type == 27);
  173. dns_rdata_toregion(rdata, &r);
  174. return ((digest)(arg, &r));
  175. }
  176. static inline isc_boolean_t
  177. checkowner_gpos(ARGS_CHECKOWNER) {
  178. REQUIRE(type == 27);
  179. UNUSED(name);
  180. UNUSED(type);
  181. UNUSED(rdclass);
  182. UNUSED(wildcard);
  183. return (ISC_TRUE);
  184. }
  185. static inline isc_boolean_t
  186. checknames_gpos(ARGS_CHECKNAMES) {
  187. REQUIRE(rdata->type == 27);
  188. UNUSED(rdata);
  189. UNUSED(owner);
  190. UNUSED(bad);
  191. return (ISC_TRUE);
  192. }
  193. static inline int
  194. casecompare_gpos(ARGS_COMPARE) {
  195. return (compare_gpos(rdata1, rdata2));
  196. }
  197. #endif /* RDATA_GENERIC_GPOS_27_C */