gpos_27.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2009, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1999-2002  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: gpos_27.c,v 1.43 2009/12/04 22:06:37 tbox Exp $ */
00019 
00020 /* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
00021 
00022 /* RFC1712 */
00023 
00024 #ifndef RDATA_GENERIC_GPOS_27_C
00025 #define RDATA_GENERIC_GPOS_27_C
00026 
00027 #define RRTYPE_GPOS_ATTRIBUTES (0)
00028 
00029 static inline isc_result_t
00030 fromtext_gpos(ARGS_FROMTEXT) {
00031         isc_token_t token;
00032         int i;
00033 
00034         REQUIRE(type == 27);
00035 
00036         UNUSED(type);
00037         UNUSED(rdclass);
00038         UNUSED(origin);
00039         UNUSED(options);
00040         UNUSED(callbacks);
00041 
00042         for (i = 0; i < 3; i++) {
00043                 RETERR(isc_lex_getmastertoken(lexer, &token,
00044                                               isc_tokentype_qstring,
00045                                               ISC_FALSE));
00046                 RETTOK(txt_fromtext(&token.value.as_textregion, target));
00047         }
00048         return (ISC_R_SUCCESS);
00049 }
00050 
00051 static inline isc_result_t
00052 totext_gpos(ARGS_TOTEXT) {
00053         isc_region_t region;
00054         int i;
00055 
00056         REQUIRE(rdata->type == 27);
00057         REQUIRE(rdata->length != 0);
00058 
00059         UNUSED(tctx);
00060 
00061         dns_rdata_toregion(rdata, &region);
00062 
00063         for (i = 0; i < 3; i++) {
00064                 RETERR(txt_totext(&region, ISC_TRUE, target));
00065                 if (i != 2)
00066                         RETERR(str_totext(" ", target));
00067         }
00068 
00069         return (ISC_R_SUCCESS);
00070 }
00071 
00072 static inline isc_result_t
00073 fromwire_gpos(ARGS_FROMWIRE) {
00074         int i;
00075 
00076         REQUIRE(type == 27);
00077 
00078         UNUSED(type);
00079         UNUSED(dctx);
00080         UNUSED(rdclass);
00081         UNUSED(options);
00082 
00083         for (i = 0; i < 3; i++)
00084                 RETERR(txt_fromwire(source, target));
00085         return (ISC_R_SUCCESS);
00086 }
00087 
00088 static inline isc_result_t
00089 towire_gpos(ARGS_TOWIRE) {
00090 
00091         REQUIRE(rdata->type == 27);
00092         REQUIRE(rdata->length != 0);
00093 
00094         UNUSED(cctx);
00095 
00096         return (mem_tobuffer(target, rdata->data, rdata->length));
00097 }
00098 
00099 static inline int
00100 compare_gpos(ARGS_COMPARE) {
00101         isc_region_t r1;
00102         isc_region_t r2;
00103 
00104         REQUIRE(rdata1->type == rdata2->type);
00105         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00106         REQUIRE(rdata1->type == 27);
00107         REQUIRE(rdata1->length != 0);
00108         REQUIRE(rdata2->length != 0);
00109 
00110         dns_rdata_toregion(rdata1, &r1);
00111         dns_rdata_toregion(rdata2, &r2);
00112         return (isc_region_compare(&r1, &r2));
00113 }
00114 
00115 static inline isc_result_t
00116 fromstruct_gpos(ARGS_FROMSTRUCT) {
00117         dns_rdata_gpos_t *gpos = source;
00118 
00119         REQUIRE(type == 27);
00120         REQUIRE(source != NULL);
00121         REQUIRE(gpos->common.rdtype == type);
00122         REQUIRE(gpos->common.rdclass == rdclass);
00123 
00124         UNUSED(type);
00125         UNUSED(rdclass);
00126 
00127         RETERR(uint8_tobuffer(gpos->long_len, target));
00128         RETERR(mem_tobuffer(target, gpos->longitude, gpos->long_len));
00129         RETERR(uint8_tobuffer(gpos->lat_len, target));
00130         RETERR(mem_tobuffer(target, gpos->latitude, gpos->lat_len));
00131         RETERR(uint8_tobuffer(gpos->alt_len, target));
00132         return (mem_tobuffer(target, gpos->altitude, gpos->alt_len));
00133 }
00134 
00135 static inline isc_result_t
00136 tostruct_gpos(ARGS_TOSTRUCT) {
00137         dns_rdata_gpos_t *gpos = target;
00138         isc_region_t region;
00139 
00140         REQUIRE(rdata->type == 27);
00141         REQUIRE(target != NULL);
00142         REQUIRE(rdata->length != 0);
00143 
00144         gpos->common.rdclass = rdata->rdclass;
00145         gpos->common.rdtype = rdata->type;
00146         ISC_LINK_INIT(&gpos->common, link);
00147 
00148         dns_rdata_toregion(rdata, &region);
00149         gpos->long_len = uint8_fromregion(&region);
00150         isc_region_consume(&region, 1);
00151         gpos->longitude = mem_maybedup(mctx, region.base, gpos->long_len);
00152         if (gpos->longitude == NULL)
00153                 return (ISC_R_NOMEMORY);
00154         isc_region_consume(&region, gpos->long_len);
00155 
00156         gpos->lat_len = uint8_fromregion(&region);
00157         isc_region_consume(&region, 1);
00158         gpos->latitude = mem_maybedup(mctx, region.base, gpos->lat_len);
00159         if (gpos->latitude == NULL)
00160                 goto cleanup_longitude;
00161         isc_region_consume(&region, gpos->lat_len);
00162 
00163         gpos->alt_len = uint8_fromregion(&region);
00164         isc_region_consume(&region, 1);
00165         if (gpos->lat_len > 0) {
00166                 gpos->altitude =
00167                         mem_maybedup(mctx, region.base, gpos->alt_len);
00168                 if (gpos->altitude == NULL)
00169                         goto cleanup_latitude;
00170         } else
00171                 gpos->altitude = NULL;
00172 
00173         gpos->mctx = mctx;
00174         return (ISC_R_SUCCESS);
00175 
00176  cleanup_latitude:
00177         if (mctx != NULL && gpos->longitude != NULL)
00178                 isc_mem_free(mctx, gpos->longitude);
00179 
00180  cleanup_longitude:
00181         if (mctx != NULL && gpos->latitude != NULL)
00182                 isc_mem_free(mctx, gpos->latitude);
00183         return (ISC_R_NOMEMORY);
00184 }
00185 
00186 static inline void
00187 freestruct_gpos(ARGS_FREESTRUCT) {
00188         dns_rdata_gpos_t *gpos = source;
00189 
00190         REQUIRE(source != NULL);
00191         REQUIRE(gpos->common.rdtype == 27);
00192 
00193         if (gpos->mctx == NULL)
00194                 return;
00195 
00196         if (gpos->longitude != NULL)
00197                 isc_mem_free(gpos->mctx, gpos->longitude);
00198         if (gpos->latitude != NULL)
00199                 isc_mem_free(gpos->mctx, gpos->latitude);
00200         if (gpos->altitude != NULL)
00201                 isc_mem_free(gpos->mctx, gpos->altitude);
00202         gpos->mctx = NULL;
00203 }
00204 
00205 static inline isc_result_t
00206 additionaldata_gpos(ARGS_ADDLDATA) {
00207         REQUIRE(rdata->type == 27);
00208 
00209         UNUSED(rdata);
00210         UNUSED(add);
00211         UNUSED(arg);
00212 
00213         return (ISC_R_SUCCESS);
00214 }
00215 
00216 static inline isc_result_t
00217 digest_gpos(ARGS_DIGEST) {
00218         isc_region_t r;
00219 
00220         REQUIRE(rdata->type == 27);
00221 
00222         dns_rdata_toregion(rdata, &r);
00223 
00224         return ((digest)(arg, &r));
00225 }
00226 
00227 static inline isc_boolean_t
00228 checkowner_gpos(ARGS_CHECKOWNER) {
00229 
00230         REQUIRE(type == 27);
00231 
00232         UNUSED(name);
00233         UNUSED(type);
00234         UNUSED(rdclass);
00235         UNUSED(wildcard);
00236 
00237         return (ISC_TRUE);
00238 }
00239 
00240 static inline isc_boolean_t
00241 checknames_gpos(ARGS_CHECKNAMES) {
00242 
00243         REQUIRE(rdata->type == 27);
00244 
00245         UNUSED(rdata);
00246         UNUSED(owner);
00247         UNUSED(bad);
00248 
00249         return (ISC_TRUE);
00250 }
00251 
00252 static inline int
00253 casecompare_gpos(ARGS_COMPARE) {
00254         return (compare_gpos(rdata1, rdata2));
00255 }
00256 
00257 #endif  /* RDATA_GENERIC_GPOS_27_C */

Generated on Tue Apr 28 17:40:59 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha