other-licenses/android/res_data.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/android/res_data.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,348 @@
     1.4 +/*	$NetBSD: res_data.c,v 1.8 2004/06/09 18:07:03 christos Exp $	*/
     1.5 +
     1.6 +/*
     1.7 + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
     1.8 + * Copyright (c) 1995-1999 by Internet Software Consortium.
     1.9 + *
    1.10 + * Permission to use, copy, modify, and distribute this software for any
    1.11 + * purpose with or without fee is hereby granted, provided that the above
    1.12 + * copyright notice and this permission notice appear in all copies.
    1.13 + *
    1.14 + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
    1.15 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
    1.16 + * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
    1.17 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    1.18 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
    1.19 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
    1.20 + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    1.21 + */
    1.22 +
    1.23 +/*
    1.24 + * This version of this file is derived from Android 2.3 "Gingerbread",
    1.25 + * which contains uncredited changes by Android/Google developers.  It has
    1.26 + * been modified in 2011 for use in the Android build of Mozilla Firefox by
    1.27 + * Mozilla contributors (including Michael Edwards <m.k.edwards@gmail.com>,
    1.28 + * and Steve Workman <sjhworkman@gmail.com>).
    1.29 + * These changes are offered under the same license as the original NetBSD
    1.30 + * file, whose copyright and license are unchanged above.
    1.31 + */
    1.32 +
    1.33 +#define ANDROID_CHANGES 1
    1.34 +#define MOZILLA_NECKO_EXCLUDE_CODE 1
    1.35 +
    1.36 +#include <sys/cdefs.h>
    1.37 +#if defined(LIBC_SCCS) && !defined(lint)
    1.38 +#ifdef notdef
    1.39 +static const char rcsid[] = "Id: res_data.c,v 1.1.206.2 2004/03/16 12:34:18 marka Exp";
    1.40 +#else
    1.41 +__RCSID("$NetBSD: res_data.c,v 1.8 2004/06/09 18:07:03 christos Exp $");
    1.42 +#endif
    1.43 +#endif /* LIBC_SCCS and not lint */
    1.44 +
    1.45 +
    1.46 +
    1.47 +#include <sys/types.h>
    1.48 +#include <sys/param.h>
    1.49 +#include <sys/socket.h>
    1.50 +#include <sys/time.h>
    1.51 +
    1.52 +#include <netinet/in.h>
    1.53 +#include <arpa/inet.h>
    1.54 +#include "arpa_nameser.h"
    1.55 +
    1.56 +#include <ctype.h>
    1.57 +#include <netdb.h>
    1.58 +#include "resolv_private.h"
    1.59 +#include <stdio.h>
    1.60 +#include <stdlib.h>
    1.61 +#include <string.h>
    1.62 +#include <unistd.h>
    1.63 +
    1.64 +
    1.65 +const char * const _res_opcodes[] = {
    1.66 +	"QUERY",
    1.67 +	"IQUERY",
    1.68 +	"CQUERYM",
    1.69 +	"CQUERYU",	/* experimental */
    1.70 +	"NOTIFY",	/* experimental */
    1.71 +	"UPDATE",
    1.72 +	"6",
    1.73 +	"7",
    1.74 +	"8",
    1.75 +	"9",
    1.76 +	"10",
    1.77 +	"11",
    1.78 +	"12",
    1.79 +	"13",
    1.80 +	"ZONEINIT",
    1.81 +	"ZONEREF",
    1.82 +};
    1.83 +
    1.84 +#ifdef BIND_UPDATE
    1.85 +const char * const _res_sectioncodes[] = {
    1.86 +	"ZONE",
    1.87 +	"PREREQUISITES",
    1.88 +	"UPDATE",
    1.89 +	"ADDITIONAL",
    1.90 +};
    1.91 +#endif
    1.92 +
    1.93 +#ifndef MOZILLA_NECKO_EXCLUDE_CODE
    1.94 +#ifndef __BIND_NOSTATIC
    1.95 +extern struct __res_state _nres;
    1.96 +
    1.97 +/* Proto. */
    1.98 +
    1.99 +int  res_ourserver_p(const res_state, const struct sockaddr *);
   1.100 +
   1.101 +#ifdef ANDROID_CHANGES
   1.102 +int res_need_init() {
   1.103 +	return ((_nres.options & RES_INIT) == 0U) || res_get_dns_changed();
   1.104 +}
   1.105 +#else
   1.106 +#define res_need_init()   ((_nres.options & RES_INIT) == 0U)
   1.107 +#endif
   1.108 +
   1.109 +int
   1.110 +res_init(void) {
   1.111 +	int rv;
   1.112 +	extern int __res_vinit(res_state, int);
   1.113 +#ifdef COMPAT__RES
   1.114 +	/*
   1.115 +	 * Compatibility with program that were accessing _res directly
   1.116 +	 * to set options. We keep another struct res that is the same
   1.117 +	 * size as the original res structure, and then copy fields to
   1.118 +	 * it so that we achieve the same initialization
   1.119 +	 */
   1.120 +	extern void *__res_get_old_state(void);
   1.121 +	extern void __res_put_old_state(void *);
   1.122 +	res_state ores = __res_get_old_state();
   1.123 +
   1.124 +	if (ores->options != 0)
   1.125 +		_nres.options = ores->options;
   1.126 +	if (ores->retrans != 0)
   1.127 +		_nres.retrans = ores->retrans;
   1.128 +	if (ores->retry != 0)
   1.129 +		_nres.retry = ores->retry;
   1.130 +#endif
   1.131 +
   1.132 +	/*
   1.133 +	 * These three fields used to be statically initialized.  This made
   1.134 +	 * it hard to use this code in a shared library.  It is necessary,
   1.135 +	 * now that we're doing dynamic initialization here, that we preserve
   1.136 +	 * the old semantics: if an application modifies one of these three
   1.137 +	 * fields of _res before res_init() is called, res_init() will not
   1.138 +	 * alter them.  Of course, if an application is setting them to
   1.139 +	 * _zero_ before calling res_init(), hoping to override what used
   1.140 +	 * to be the static default, we can't detect it and unexpected results
   1.141 +	 * will follow.  Zero for any of these fields would make no sense,
   1.142 +	 * so one can safely assume that the applications were already getting
   1.143 +	 * unexpected results.
   1.144 +	 *
   1.145 +	 * _nres.options is tricky since some apps were known to diddle the bits
   1.146 +	 * before res_init() was first called. We can't replicate that semantic
   1.147 +	 * with dynamic initialization (they may have turned bits off that are
   1.148 +	 * set in RES_DEFAULT).  Our solution is to declare such applications
   1.149 +	 * "broken".  They could fool us by setting RES_INIT but none do (yet).
   1.150 +	 */
   1.151 +	if (!_nres.retrans)
   1.152 +		_nres.retrans = RES_TIMEOUT;
   1.153 +	if (!_nres.retry)
   1.154 +		_nres.retry = 4;
   1.155 +	if (!(_nres.options & RES_INIT))
   1.156 +		_nres.options = RES_DEFAULT;
   1.157 +
   1.158 +	/*
   1.159 +	 * This one used to initialize implicitly to zero, so unless the app
   1.160 +	 * has set it to something in particular, we can randomize it now.
   1.161 +	 */
   1.162 +	if (!_nres.id)
   1.163 +		_nres.id = res_randomid();
   1.164 +
   1.165 +	rv = __res_vinit(&_nres, 1);
   1.166 +#ifdef COMPAT__RES
   1.167 +	__res_put_old_state(&_nres);
   1.168 +#endif
   1.169 +	return rv;
   1.170 +}
   1.171 +
   1.172 +void
   1.173 +p_query(const u_char *msg) {
   1.174 +	fp_query(msg, stdout);
   1.175 +}
   1.176 +
   1.177 +void
   1.178 +fp_query(const u_char *msg, FILE *file) {
   1.179 +	fp_nquery(msg, PACKETSZ, file);
   1.180 +}
   1.181 +
   1.182 +void
   1.183 +fp_nquery(const u_char *msg, int len, FILE *file) {
   1.184 +	if (res_need_init() && res_init() == -1)
   1.185 +		return;
   1.186 +
   1.187 +	res_pquery(&_nres, msg, len, file);
   1.188 +}
   1.189 +
   1.190 +int
   1.191 +res_mkquery(int op,			/* opcode of query */
   1.192 +	    const char *dname,		/* domain name */
   1.193 +	    int class, int type,	/* class and type of query */
   1.194 +	    const u_char *data,		/* resource record data */
   1.195 +	    int datalen,		/* length of data */
   1.196 +	    const u_char *newrr_in,	/* new rr for modify or append */
   1.197 +	    u_char *buf,		/* buffer to put query */
   1.198 +	    int buflen)			/* size of buffer */
   1.199 +{
   1.200 +	if (res_need_init() && res_init() == -1) {
   1.201 +		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
   1.202 +		return (-1);
   1.203 +	}
   1.204 +	return (res_nmkquery(&_nres, op, dname, class, type,
   1.205 +			     data, datalen,
   1.206 +			     newrr_in, buf, buflen));
   1.207 +}
   1.208 +
   1.209 +#ifdef _LIBRESOLV
   1.210 +int
   1.211 +res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
   1.212 +	if (res_need_init() && res_init() == -1) {
   1.213 +		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
   1.214 +		return (-1);
   1.215 +	}
   1.216 +
   1.217 +	return (res_nmkupdate(&_nres, rrecp_in, buf, buflen));
   1.218 +}
   1.219 +#endif
   1.220 +
   1.221 +int
   1.222 +res_query(const char *name,	/* domain name */
   1.223 +	  int class, int type,	/* class and type of query */
   1.224 +	  u_char *answer,	/* buffer to put answer */
   1.225 +	  int anslen)		/* size of answer buffer */
   1.226 +{
   1.227 +	if (res_need_init() && res_init() == -1) {
   1.228 +		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
   1.229 +		return (-1);
   1.230 +	}
   1.231 +	return (res_nquery(&_nres, name, class, type, answer, anslen));
   1.232 +}
   1.233 +
   1.234 +void
   1.235 +res_send_setqhook(res_send_qhook hook) {
   1.236 +	_nres.qhook = hook;
   1.237 +}
   1.238 +
   1.239 +void
   1.240 +res_send_setrhook(res_send_rhook hook) {
   1.241 +	_nres.rhook = hook;
   1.242 +}
   1.243 +
   1.244 +int
   1.245 +res_isourserver(const struct sockaddr_in *inp) {
   1.246 +	return (res_ourserver_p(&_nres, (const struct sockaddr *)(const void *)inp));
   1.247 +}
   1.248 +
   1.249 +int
   1.250 +res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) {
   1.251 +	if (res_need_init() && res_init() == -1) {
   1.252 +		/* errno should have been set by res_init() in this case. */
   1.253 +		return (-1);
   1.254 +	}
   1.255 +
   1.256 +	return (res_nsend(&_nres, buf, buflen, ans, anssiz));
   1.257 +}
   1.258 +
   1.259 +#ifdef _LIBRESOLV
   1.260 +int
   1.261 +res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key,
   1.262 +	       u_char *ans, int anssiz)
   1.263 +{
   1.264 +	if (res_need_init() && res_init() == -1) {
   1.265 +		/* errno should have been set by res_init() in this case. */
   1.266 +		return (-1);
   1.267 +	}
   1.268 +
   1.269 +	return (res_nsendsigned(&_nres, buf, buflen, key, ans, anssiz));
   1.270 +}
   1.271 +#endif
   1.272 +
   1.273 +void
   1.274 +res_close(void) {
   1.275 +	res_nclose(&_nres);
   1.276 +}
   1.277 +
   1.278 +#ifdef _LIBRESOLV
   1.279 +int
   1.280 +res_update(ns_updrec *rrecp_in) {
   1.281 +	if (res_need_init() && res_init() == -1) {
   1.282 +		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
   1.283 +		return (-1);
   1.284 +	}
   1.285 +
   1.286 +	return (res_nupdate(&_nres, rrecp_in, NULL));
   1.287 +}
   1.288 +#endif
   1.289 +
   1.290 +int
   1.291 +res_search(const char *name,	/* domain name */
   1.292 +	   int class, int type,	/* class and type of query */
   1.293 +	   u_char *answer,	/* buffer to put answer */
   1.294 +	   int anslen)		/* size of answer */
   1.295 +{
   1.296 +	if (res_need_init() && res_init() == -1) {
   1.297 +		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
   1.298 +		return (-1);
   1.299 +	}
   1.300 +
   1.301 +	return (res_nsearch(&_nres, name, class, type, answer, anslen));
   1.302 +}
   1.303 +
   1.304 +int
   1.305 +res_querydomain(const char *name,
   1.306 +		const char *domain,
   1.307 +		int class, int type,	/* class and type of query */
   1.308 +		u_char *answer,		/* buffer to put answer */
   1.309 +		int anslen)		/* size of answer */
   1.310 +{
   1.311 +	if (res_need_init() && res_init() == -1) {
   1.312 +		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
   1.313 +		return (-1);
   1.314 +	}
   1.315 +
   1.316 +	return (res_nquerydomain(&_nres, name, domain,
   1.317 +				 class, type,
   1.318 +				 answer, anslen));
   1.319 +}
   1.320 +
   1.321 +int
   1.322 +res_opt(int a, u_char *b, int c, int d)
   1.323 +{
   1.324 +	return res_nopt(&_nres, a, b, c, d);
   1.325 +}
   1.326 +#endif
   1.327 +#endif
   1.328 +
   1.329 +const char *
   1.330 +hostalias(const char *name) {
   1.331 +	return NULL;
   1.332 +}
   1.333 +
   1.334 +#ifndef MOZILLA_NECKO_EXCLUDE_CODE
   1.335 +#ifdef ultrix
   1.336 +int
   1.337 +local_hostname_length(const char *hostname) {
   1.338 +	int len_host, len_domain;
   1.339 +
   1.340 +	if (!*_nres.defdname)
   1.341 +		res_init();
   1.342 +	len_host = strlen(hostname);
   1.343 +	len_domain = strlen(_nres.defdname);
   1.344 +	if (len_host > len_domain &&
   1.345 +	    !strcasecmp(hostname + len_host - len_domain, _nres.defdname) &&
   1.346 +	    hostname[len_host - len_domain - 1] == '.')
   1.347 +		return (len_host - len_domain - 1);
   1.348 +	return (0);
   1.349 +}
   1.350 +#endif /*ultrix*/
   1.351 +#endif

mercurial