Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenadns.h
Go to the documentation of this file.
00001 /* 00002 * adns.h 00003 * - adns user-visible API (single-threaded, without any locking) 00004 */ 00005 /* 00006 * 00007 * This file is 00008 * Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk> 00009 * 00010 * It is part of adns, which is 00011 * Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk> 00012 * Copyright (C) 1999-2000 Tony Finch <dot@dotat.at> 00013 * 00014 * This program is free software; you can redistribute it and/or modify 00015 * it under the terms of the GNU General Public License as published by 00016 * the Free Software Foundation; either version 2, or (at your option) 00017 * any later version. 00018 * 00019 * This program is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 * GNU General Public License for more details. 00023 * 00024 * 00025 * For the benefit of certain LGPL'd `omnibus' software which 00026 * provides a uniform interface to various things including adns, I 00027 * make the following additional licence. I do this because the GPL 00028 * would otherwise force either the omnibus software to be GPL'd or 00029 * the adns-using part to be distributed separately. 00030 * 00031 * So: you may also redistribute and/or modify adns.h (but only the 00032 * public header file adns.h and not any other part of adns) under the 00033 * terms of the GNU Library General Public License as published by the 00034 * Free Software Foundation; either version 2 of the License, or (at 00035 * your option) any later version. 00036 * 00037 * Note that adns itself is GPL'd. Authors of adns-using applications 00038 * with GPL-incompatible licences, and people who distribute adns with 00039 * applications where the whole distribution is not GPL'd, are still 00040 * likely to be in violation of the GPL. Anyone who wants to do this 00041 * should contact Ian Jackson. Please note that to avoid encouraging 00042 * people to infringe the GPL as it applies to the body of adns, Ian 00043 * thinks that if you take advantage of the special exception to 00044 * redistribute just adns.h under the LGPL, you should retain this 00045 * paragraph in its place in the appropriate copyright statements. 00046 * 00047 * 00048 * You should have received a copy of the GNU General Public License, 00049 * or the GNU Library General Public License, as appropriate, along 00050 * with this program; if not, write to the Free Software Foundation, 00051 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00052 * 00053 * 00054 */ 00055 00056 #ifndef ADNS_H_INCLUDED 00057 #define ADNS_H_INCLUDED 00058 00059 #ifdef ADNS_JGAA_WIN32 00060 # include "adns_win32.h" 00061 #else 00062 # include <stdio.h> 00063 # include <sys/socket.h> 00064 # include <netinet/in.h> 00065 # include <sys/types.h> 00066 # include <sys/time.h> 00067 # include <unistd.h> 00068 00069 # define ADNS_API 00070 # define ADNS_SOCKET int 00071 # define adns_socket_close(sck) close(sck) 00072 # define adns_socket_read(sck, data, len) read(sck, data, len) 00073 # define adns_socket_write(sck, data, len) write(sck, data, len) 00074 # define ADNS_CAPTURE_ERRNO {} 00075 # define ADNS_CLEAR_ERRNO {} 00076 #endif 00077 00078 #ifdef __cplusplus 00079 extern "C" { /* I really dislike this - iwj. */ 00080 #endif 00081 00082 /* All struct in_addr anywhere in adns are in NETWORK byte order. */ 00083 00084 typedef struct adns__state *adns_state; 00085 typedef struct adns__query *adns_query; 00086 00087 typedef enum { 00088 adns_if_noenv= 0x0001, /* do not look at environment */ 00089 adns_if_noerrprint= 0x0002, /* never print output to stderr (_debug overrides) */ 00090 adns_if_noserverwarn= 0x0004, /* do not warn to stderr about duff nameservers etc */ 00091 adns_if_debug= 0x0008, /* enable all output to stderr plus debug msgs */ 00092 adns_if_logpid= 0x0080, /* include pid in diagnostic output */ 00093 adns_if_noautosys= 0x0010, /* do not make syscalls at every opportunity */ 00094 adns_if_eintr= 0x0020, /* allow _wait and _synchronous to return EINTR */ 00095 adns_if_nosigpipe= 0x0040, /* applic has SIGPIPE set to SIG_IGN, do not protect */ 00096 adns_if_checkc_entex= 0x0100, /* do consistency checks on entry/exit to adns funcs */ 00097 adns_if_checkc_freq= 0x0300 /* do consistency checks very frequently (slow!) */ 00098 } adns_initflags; 00099 00100 typedef enum { 00101 adns_qf_search= 0x00000001, /* use the searchlist */ 00102 adns_qf_usevc= 0x00000002, /* use a virtual circuit (TCP connection) */ 00103 adns_qf_owner= 0x00000004, /* fill in the owner field in the answer */ 00104 adns_qf_quoteok_query= 0x00000010, /* allow special chars in query domain */ 00105 adns_qf_quoteok_cname= 0x00000000, /* allow ... in CNAME we go via - now default */ 00106 adns_qf_quoteok_anshost= 0x00000040, /* allow ... in things supposed to be hostnames */ 00107 adns_qf_quotefail_cname= 0x00000080, /* refuse if quote-req chars in CNAME we go via */ 00108 adns_qf_cname_loose= 0x00000100, /* allow refs to CNAMEs - without, get _s_cname */ 00109 adns_qf_cname_forbid= 0x00000200, /* don't follow CNAMEs, instead give _s_cname */ 00110 adns__qf_internalmask= 0x0ff00000 00111 } adns_queryflags; 00112 00113 typedef enum { 00114 adns__rrt_typemask= 0x0ffff, 00115 adns__qtf_deref= 0x10000, /* dereference domains and perhaps produce extra data */ 00116 adns__qtf_mail822= 0x20000, /* make mailboxes be in RFC822 rcpt field format */ 00117 00118 adns_r_none= 0, 00119 00120 adns_r_a= 1, 00121 00122 adns_r_ns_raw= 2, 00123 adns_r_ns= adns_r_ns_raw|adns__qtf_deref, 00124 00125 adns_r_cname= 5, 00126 00127 adns_r_soa_raw= 6, 00128 adns_r_soa= adns_r_soa_raw|adns__qtf_mail822, 00129 00130 adns_r_ptr_raw= 12, 00131 adns_r_ptr= adns_r_ptr_raw|adns__qtf_deref, 00132 00133 adns_r_hinfo= 13, 00134 00135 adns_r_mx_raw= 15, 00136 adns_r_mx= adns_r_mx_raw|adns__qtf_deref, 00137 00138 adns_r_txt= 16, 00139 00140 adns_r_rp_raw= 17, 00141 adns_r_rp= adns_r_rp_raw|adns__qtf_mail822, 00142 00143 adns_r_addr= adns_r_a|adns__qtf_deref 00144 00145 } adns_rrtype; 00146 00147 /* 00148 * In queries without qf_quoteok_*, all domains must have standard 00149 * legal syntax, or you get adns_s_querydomainvalid (if the query 00150 * domain contains bad characters) or adns_s_answerdomaininvalid (if 00151 * the answer contains bad characters). 00152 * 00153 * In queries _with_ qf_quoteok_*, domains in the query or response 00154 * may contain any characters, quoted according to RFC1035 5.1. On 00155 * input to adns, the char* is a pointer to the interior of a " 00156 * delimited string, except that " may appear in it unquoted. On 00157 * output, the char* is a pointer to a string which would be legal 00158 * either inside or outside " delimiters; any character which isn't 00159 * legal in a hostname (ie alphanumeric or hyphen) or one of _ / + 00160 * (the three other punctuation characters commonly abused in domain 00161 * names) will be quoted, as \X if it is a printing ASCII character or 00162 * \DDD otherwise. 00163 * 00164 * If the query goes via a CNAME then the canonical name (ie, the 00165 * thing that the CNAME record refers to) is usually allowed to 00166 * contain any characters, which will be quoted as above. With 00167 * adns_qf_quotefail_cname you get adns_s_answerdomaininvalid when 00168 * this happens. (This is a change from version 0.4 and earlier, in 00169 * which failing the query was the default, and you had to say 00170 * adns_qf_quoteok_cname to avoid this; that flag is now deprecated.) 00171 * 00172 * In version 0.4 and earlier, asking for _raw records containing 00173 * mailboxes without specifying _qf_quoteok_anshost was silly. This 00174 * is no longer the case. In this version only parts of responses 00175 * that are actually supposed to be hostnames will be refused by 00176 * default if quote-requiring characters are found. 00177 */ 00178 00179 /* 00180 * If you ask for an RR which contains domains which are actually 00181 * encoded mailboxes, and don't ask for the _raw version, then adns 00182 * returns the mailbox formatted suitably for an RFC822 recipient 00183 * header field. The particular format used is that if the mailbox 00184 * requires quoting according to the rules in RFC822 then the 00185 * local-part is quoted in double quotes, which end at the next 00186 * unescaped double quote (\ is the escape char, and is doubled, and 00187 * is used to escape only \ and "). If the local-part is legal 00188 * without quoting according to RFC822, it is presented as-is. In any 00189 * case the local-part is followed by an @ and the domain. The domain 00190 * will not contain any characters not legal in hostnames. 00191 * 00192 * Unquoted local-parts may contain any printing 7-bit ASCII 00193 * except the punctuation characters ( ) < > @ , ; : \ " [ ] 00194 * I.e. they may contain alphanumerics, and the following 00195 * punctuation characters: ! # % ^ & * - _ = + { } . 00196 * 00197 * adns will reject local parts containing control characters (byte 00198 * values 0-31, 127-159, and 255) - these appear to be legal according 00199 * to RFC822 (at least 0-127) but are clearly a bad idea. RFC1035 00200 * syntax does not make any distinction between a single RFC822 00201 * quoted-string containing full stops, and a series of quoted-strings 00202 * separated by full stops; adns will return anything that isn't all 00203 * valid atoms as a single quoted-string. RFC822 does not allow 00204 * high-bit-set characters at all, but adns does allow them in 00205 * local-parts, treating them as needing quoting. 00206 * 00207 * If you ask for the domain with _raw then _no_ checking is done 00208 * (even on the host part, regardless of adns_qf_quoteok_anshost), and 00209 * you just get the domain name in master file format. 00210 * 00211 * If no mailbox is supplied the returned string will be `.' in either 00212 * case. 00213 */ 00214 00215 typedef enum { 00216 adns_s_ok, 00217 00218 /* locally induced errors */ 00219 adns_s_nomemory, 00220 adns_s_unknownrrtype, 00221 adns_s_systemfail, 00222 00223 adns_s_max_localfail= 29, 00224 00225 /* remotely induced errors, detected locally */ 00226 adns_s_timeout, 00227 adns_s_allservfail, 00228 adns_s_norecurse, 00229 adns_s_invalidresponse, 00230 adns_s_unknownformat, 00231 00232 adns_s_max_remotefail= 59, 00233 00234 /* remotely induced errors, reported by remote server to us */ 00235 adns_s_rcodeservfail, 00236 adns_s_rcodeformaterror, 00237 adns_s_rcodenotimplemented, 00238 adns_s_rcoderefused, 00239 adns_s_rcodeunknown, 00240 00241 adns_s_max_tempfail= 99, 00242 00243 /* remote configuration errors */ 00244 adns_s_inconsistent, /* PTR gives domain whose A does not exist and match */ 00245 adns_s_prohibitedcname, /* CNAME found where eg A expected (not if _qf_loosecname) */ 00246 adns_s_answerdomaininvalid, 00247 adns_s_answerdomaintoolong, 00248 adns_s_invaliddata, 00249 00250 adns_s_max_misconfig= 199, 00251 00252 /* permanent problems with the query */ 00253 adns_s_querydomainwrong, 00254 adns_s_querydomaininvalid, 00255 adns_s_querydomaintoolong, 00256 00257 adns_s_max_misquery= 299, 00258 00259 /* permanent errors */ 00260 adns_s_nxdomain, 00261 adns_s_nodata, 00262 00263 adns_s_max_permfail= 499 00264 00265 } adns_status; 00266 00267 typedef struct { 00268 int len; 00269 union { 00270 struct sockaddr sa; 00271 struct sockaddr_in inet; 00272 } addr; 00273 } adns_rr_addr; 00274 00275 typedef struct { 00276 char *host; 00277 adns_status astatus; 00278 int naddrs; /* temp fail => -1, perm fail => 0, s_ok => >0 */ 00279 adns_rr_addr *addrs; 00280 } adns_rr_hostaddr; 00281 00282 typedef struct { 00283 char *(array[2]); 00284 } adns_rr_strpair; 00285 00286 typedef struct { 00287 int i; 00288 adns_rr_hostaddr ha; 00289 } adns_rr_inthostaddr; 00290 00291 typedef struct { 00292 /* Used both for mx_raw, in which case i is the preference and str the domain, 00293 * and for txt, in which case each entry has i for the `text' length, 00294 * and str for the data (which will have had an extra nul appended 00295 * so that if it was plain text it is now a null-terminated string). 00296 */ 00297 int i; 00298 char *str; 00299 } adns_rr_intstr; 00300 00301 typedef struct { 00302 adns_rr_intstr array[2]; 00303 } adns_rr_intstrpair; 00304 00305 typedef struct { 00306 char *mname, *rname; 00307 unsigned long serial, refresh, retry, expire, minimum; 00308 } adns_rr_soa; 00309 00310 typedef struct { 00311 adns_status status; 00312 char *cname; /* always NULL if query was for CNAME records */ 00313 char *owner; /* only set if requested in query flags, and may be 0 on error anyway */ 00314 adns_rrtype type; /* guaranteed to be same as in query */ 00315 time_t expires; /* expiry time, defined only if _s_ok, nxdomain or nodata. NOT TTL! */ 00316 int nrrs, rrsz; /* nrrs is 0 if an error occurs */ 00317 union { 00318 void *untyped; 00319 unsigned char *bytes; 00320 char *(*str); /* ns_raw, cname, ptr, ptr_raw */ 00321 adns_rr_intstr *(*manyistr); /* txt (list of strings ends with i=-1, str=0) */ 00322 adns_rr_addr *addr; /* addr */ 00323 struct in_addr *inaddr; /* a */ 00324 adns_rr_hostaddr *hostaddr; /* ns */ 00325 adns_rr_intstrpair *intstrpair; /* hinfo */ 00326 adns_rr_strpair *strpair; /* rp, rp_raw */ 00327 adns_rr_inthostaddr *inthostaddr; /* mx */ 00328 adns_rr_intstr *intstr; /* mx_raw */ 00329 adns_rr_soa *soa; /* soa, soa_raw */ 00330 } rrs; 00331 } adns_answer; 00332 00333 /* Memory management: 00334 * adns_state and adns_query are actually pointers to malloc'd state; 00335 * On submission questions are copied, including the owner domain; 00336 * Answers are malloc'd as a single piece of memory; pointers in the 00337 * answer struct point into further memory in the answer. 00338 * query_io: 00339 * Must always be non-null pointer; 00340 * If *query_io is 0 to start with then any query may be returned; 00341 * If *query_io is !0 adns_query then only that query may be returned. 00342 * If the call is successful, *query_io, *answer_r, and *context_r 00343 * will all be set. 00344 * Errors: 00345 * Return values are 0 or an errno value. 00346 * 00347 * For _init, _init_strcfg, _submit and _synchronous, system errors 00348 * (eg, failure to create sockets, malloc failure, etc.) return errno 00349 * values. 00350 * 00351 * For _wait and _check failures are reported in the answer 00352 * structure, and only 0, ESRCH or (for _check) EAGAIN is 00353 * returned: if no (appropriate) requests are done adns_check returns 00354 * EAGAIN; if no (appropriate) requests are outstanding both 00355 * adns_query and adns_wait return ESRCH. 00356 * 00357 * Additionally, _wait can return EINTR if you set adns_if_eintr. 00358 * 00359 * All other errors (nameserver failure, timed out connections, &c) 00360 * are returned in the status field of the answer. After a 00361 * successful _wait or _check, if status is nonzero then nrrs will be 00362 * 0, otherwise it will be >0. type will always be the type 00363 * requested. 00364 */ 00365 00366 ADNS_API int adns_init(adns_state *newstate_r, adns_initflags flags, 00367 FILE *diagfile /*0=>stderr*/); 00368 00369 /* ReactOS addition */ 00370 ADNS_API void adns_addserver(adns_state state, struct in_addr server); 00371 00372 ADNS_API int adns_init_strcfg(adns_state *newstate_r, adns_initflags flags, 00373 FILE *diagfile /*0=>discard*/, const char *configtext); 00374 00375 /* Configuration: 00376 * adns_init reads /etc/resolv.conf, which is expected to be (broadly 00377 * speaking) in the format expected by libresolv, and then 00378 * /etc/resolv-adns.conf if it exists. adns_init_strcfg is instead 00379 * passed a string which is interpreted as if it were the contents of 00380 * resolv.conf or resolv-adns.conf. In general, configuration which 00381 * is set later overrides any that is set earlier. 00382 * 00383 * Standard directives understood in resolv[-adns].conf: 00384 * 00385 * nameserver <address> 00386 * Must be followed by the IP address of a nameserver. Several 00387 * nameservers may be specified, and they will be tried in the order 00388 * found. There is a compiled in limit, currently 5, on the number 00389 * of nameservers. (libresolv supports only 3 nameservers.) 00390 * 00391 * search <domain> ... 00392 * Specifies the search list for queries which specify 00393 * adns_qf_search. This is a list of domains to append to the query 00394 * domain. The query domain will be tried as-is either before all 00395 * of these or after them, depending on the ndots option setting 00396 * (see below). 00397 * 00398 * domain <domain> 00399 * This is present only for backward compatibility with obsolete 00400 * versions of libresolv. It should not be used, and is interpreted 00401 * by adns as if it were `search' - note that this is subtly 00402 * different to libresolv's interpretation of this directive. 00403 * 00404 * sortlist <addr>/<mask> ... 00405 * Should be followed by a sequence of IP-address and netmask pairs, 00406 * separated by spaces. They may be specified as 00407 * eg. 172.30.206.0/24 or 172.30.206.0/255.255.255.0. Currently up 00408 * to 15 pairs may be specified (but note that libresolv only 00409 * supports up to 10). 00410 * 00411 * options 00412 * Should followed by one or more options, separated by spaces. 00413 * Each option consists of an option name, followed by optionally 00414 * a colon and a value. Options are listed below. 00415 * 00416 * Non-standard directives understood in resolv[-adns].conf: 00417 * 00418 * clearnameservers 00419 * Clears the list of nameservers, so that further nameserver lines 00420 * start again from the beginning. 00421 * 00422 * include <filename> 00423 * The specified file will be read. 00424 * 00425 * Additionally, adns will ignore lines in resolv[-adns].conf which 00426 * start with a #. 00427 * 00428 * Standard options understood: 00429 * 00430 * debug 00431 * Enables debugging output from the resolver, which will be written 00432 * to stderr. 00433 * 00434 * ndots:<count> 00435 * Affects whether queries with adns_qf_search will be tried first 00436 * without adding domains from the searchlist, or whether the bare 00437 * query domain will be tried last. Queries which contain at least 00438 * <count> dots will be tried bare first. The default is 1. 00439 * 00440 * Non-standard options understood: 00441 * 00442 * adns_checkc:none 00443 * adns_checkc:entex 00444 * adns_checkc:freq 00445 * Changes the consistency checking frequency; this overrides the 00446 * setting of adns_if_check_entex, adns_if_check_freq, or neither, 00447 * in the flags passed to adns_init. 00448 * 00449 * There are a number of environment variables which can modify the 00450 * behaviour of adns. They take effect only if adns_init is used, and 00451 * the caller of adns_init can disable them using adns_if_noenv. In 00452 * each case there is both a FOO and an ADNS_FOO; the latter is 00453 * interpreted later so that it can override the former. Unless 00454 * otherwise stated, environment variables are interpreted after 00455 * resolv[-adns].conf are read, in the order they are listed here. 00456 * 00457 * RES_CONF, ADNS_RES_CONF 00458 * A filename, whose contets are in the format of resolv.conf. 00459 * 00460 * RES_CONF_TEXT, ADNS_RES_CONF_TEXT 00461 * A string in the format of resolv.conf. 00462 * 00463 * RES_OPTIONS, ADNS_RES_OPTIONS 00464 * These are parsed as if they appeared in the `options' line of a 00465 * resolv.conf. In addition to being parsed at this point in the 00466 * sequence, they are also parsed at the very beginning before 00467 * resolv.conf or any other environment variables are read, so that 00468 * any debug option can affect the processing of the configuration. 00469 * 00470 * LOCALDOMAIN, ADNS_LOCALDOMAIN 00471 * These are interpreted as if their contents appeared in a `search' 00472 * line in resolv.conf. 00473 */ 00474 00475 ADNS_API int adns_synchronous(adns_state ads, 00476 const char *owner, 00477 adns_rrtype type, 00478 adns_queryflags flags, 00479 adns_answer **answer_r); 00480 00481 /* NB: if you set adns_if_noautosys then _submit and _check do not 00482 * make any system calls; you must use some of the asynch-io event 00483 * processing functions to actually get things to happen. 00484 */ 00485 00486 ADNS_API int adns_submit(adns_state ads, 00487 const char *owner, 00488 adns_rrtype type, 00489 adns_queryflags flags, 00490 void *context, 00491 adns_query *query_r); 00492 00493 /* The owner should be quoted in master file format. */ 00494 00495 ADNS_API int adns_check(adns_state ads, 00496 adns_query *query_io, 00497 adns_answer **answer_r, 00498 void **context_r); 00499 00500 ADNS_API int adns_wait(adns_state ads, 00501 adns_query *query_io, 00502 adns_answer **answer_r, 00503 void **context_r); 00504 00505 /* same as adns_wait but uses poll(2) internally */ 00506 ADNS_API int adns_wait_poll(adns_state ads, 00507 adns_query *query_io, 00508 adns_answer **answer_r, 00509 void **context_r); 00510 00511 ADNS_API void adns_cancel(adns_query query); 00512 00513 /* The adns_query you get back from _submit is valid (ie, can be 00514 * legitimately passed into adns functions) until it is returned by 00515 * adns_check or adns_wait, or passed to adns_cancel. After that it 00516 * must not be used. You can rely on it not being reused until the 00517 * first adns_submit or _transact call using the same adns_state after 00518 * it became invalid, so you may compare it for equality with other 00519 * query handles until you next call _query or _transact. 00520 * 00521 * _submit and _synchronous return ENOSYS if they don't understand the 00522 * query type. 00523 */ 00524 00525 ADNS_API int adns_submit_reverse(adns_state ads, 00526 const struct sockaddr *addr, 00527 adns_rrtype type, 00528 adns_queryflags flags, 00529 void *context, 00530 adns_query *query_r); 00531 /* type must be _r_ptr or _r_ptr_raw. _qf_search is ignored. 00532 * addr->sa_family must be AF_INET or you get ENOSYS. 00533 */ 00534 00535 ADNS_API int adns_submit_reverse_any(adns_state ads, 00536 const struct sockaddr *addr, 00537 const char *rzone, 00538 adns_rrtype type, 00539 adns_queryflags flags, 00540 void *context, 00541 adns_query *query_r); 00542 /* For RBL-style reverse `zone's; look up 00543 * <reversed-address>.<zone> 00544 * Any type is allowed. _qf_search is ignored. 00545 * addr->sa_family must be AF_INET or you get ENOSYS. 00546 */ 00547 00548 ADNS_API void adns_finish(adns_state ads); 00549 /* You may call this even if you have queries outstanding; 00550 * they will be cancelled. 00551 */ 00552 00553 00554 ADNS_API void adns_forallqueries_begin(adns_state ads); 00555 ADNS_API adns_query adns_forallqueries_next(adns_state ads, void **context_r); 00556 /* Iterator functions, which you can use to loop over the outstanding 00557 * (submitted but not yet successfuly checked/waited) queries. 00558 * 00559 * You can only have one iteration going at once. You may call _begin 00560 * at any time; after that, an iteration will be in progress. You may 00561 * only call _next when an iteration is in progress - anything else 00562 * may coredump. The iteration remains in progress until _next 00563 * returns 0, indicating that all the queries have been walked over, 00564 * or ANY other adns function is called with the same adns_state (or a 00565 * query in the same adns_state). There is no need to explicitly 00566 * finish an iteration. 00567 * 00568 * context_r may be 0. *context_r may not be set when _next returns 0. 00569 */ 00570 00571 ADNS_API void adns_checkconsistency(adns_state ads, adns_query qu); 00572 /* Checks the consistency of adns's internal data structures. 00573 * If any error is found, the program will abort(). 00574 * You may pass 0 for qu; if you pass non-null then additional checks 00575 * are done to make sure that qu is a valid query. 00576 */ 00577 00578 /* 00579 * Example expected/legal calling sequence for submit/check/wait: 00580 * adns_init 00581 * adns_submit 1 00582 * adns_submit 2 00583 * adns_submit 3 00584 * adns_wait 1 00585 * adns_check 3 -> EAGAIN 00586 * adns_wait 2 00587 * adns_wait 3 00588 * .... 00589 * adns_finish 00590 */ 00591 00592 /* 00593 * Entrypoints for generic asynch io: 00594 * (these entrypoints are not very useful except in combination with * 00595 * some of the other I/O model calls which can tell you which fds to 00596 * be interested in): 00597 * 00598 * Note that any adns call may cause adns to open and close fds, so 00599 * you must call beforeselect or beforepoll again just before 00600 * blocking, or you may not have an up-to-date list of it's fds. 00601 */ 00602 00603 ADNS_API int adns_processany(adns_state ads); 00604 /* Gives adns flow-of-control for a bit. This will never block, and 00605 * can be used with any threading/asynch-io model. If some error 00606 * occurred which might cause an event loop to spin then the errno 00607 * value is returned. 00608 */ 00609 00610 ADNS_API int adns_processreadable(adns_state ads, ADNS_SOCKET fd, const struct timeval *now); 00611 ADNS_API int adns_processwriteable(adns_state ads, ADNS_SOCKET fd, const struct timeval *now); 00612 ADNS_API int adns_processexceptional(adns_state ads, ADNS_SOCKET fd, const struct timeval *now); 00613 /* Gives adns flow-of-control so that it can process incoming data 00614 * from, or send outgoing data via, fd. Very like _processany. If it 00615 * returns zero then fd will no longer be readable or writeable 00616 * (unless of course more data has arrived since). adns will _only_ 00617 * use that fd and only in the manner specified, regardless of whether 00618 * adns_if_noautosys was specified. 00619 * 00620 * adns_processexceptional should be called when select(2) reports an 00621 * exceptional condition, or poll(2) reports POLLPRI. 00622 * 00623 * It is fine to call _processreabable or _processwriteable when the 00624 * fd is not ready, or with an fd that doesn't belong to adns; it will 00625 * then just return 0. 00626 * 00627 * If some error occurred which might prevent an event loop to spin 00628 * then the errno value is returned. 00629 */ 00630 00631 ADNS_API void adns_processtimeouts(adns_state ads, const struct timeval *now); 00632 /* Gives adns flow-of-control so that it can process any timeouts 00633 * which might have happened. Very like _processreadable/writeable. 00634 * 00635 * now may be 0; if it isn't, *now must be the current time, recently 00636 * obtained from gettimeofday. 00637 */ 00638 00639 ADNS_API void adns_firsttimeout(adns_state ads, 00640 struct timeval **tv_mod, struct timeval *tv_buf, 00641 struct timeval now); 00642 /* Asks adns when it would first like the opportunity to time 00643 * something out. now must be the current time, from gettimeofday. 00644 * 00645 * If tv_mod points to 0 then tv_buf must be non-null, and 00646 * _firsttimeout will fill in *tv_buf with the time until the first 00647 * timeout, and make *tv_mod point to tv_buf. If adns doesn't have 00648 * anything that might need timing out it will leave *tv_mod as 0. 00649 * 00650 * If *tv_mod is not 0 then tv_buf is not used. adns will update 00651 * *tv_mod if it has any earlier timeout, and leave it alone if it 00652 * doesn't. 00653 * 00654 * This call will not actually do any I/O, or change the fds that adns 00655 * is using. It always succeeds and never blocks. 00656 */ 00657 00658 ADNS_API void adns_globalsystemfailure(adns_state ads); 00659 /* If serious problem(s) happen which globally affect your ability to 00660 * interact properly with adns, or adns's ability to function 00661 * properly, you or adns can call this function. 00662 * 00663 * All currently outstanding queries will be made to fail with 00664 * adns_s_systemfail, and adns will close any stream sockets it has 00665 * open. 00666 * 00667 * This is used by adns, for example, if gettimeofday() fails. 00668 * Without this the program's event loop might start to spin ! 00669 * 00670 * This call will never block. 00671 */ 00672 00673 /* 00674 * Entrypoints for select-loop based asynch io: 00675 */ 00676 00677 ADNS_API void adns_beforeselect(adns_state ads, int *maxfd, fd_set *readfds, 00678 fd_set *writefds, fd_set *exceptfds, 00679 struct timeval **tv_mod, struct timeval *tv_buf, 00680 const struct timeval *now); 00681 /* Find out file descriptors adns is interested in, and when it would 00682 * like the opportunity to time something out. If you do not plan to 00683 * block then tv_mod may be 0. Otherwise, tv_mod and tv_buf are as 00684 * for adns_firsttimeout. readfds, writefds, exceptfds and maxfd_io may 00685 * not be 0. 00686 * 00687 * If now is not 0 then this will never actually do any I/O, or change 00688 * the fds that adns is using or the timeouts it wants. In any case 00689 * it won't block, and it will set the timeout to zero if a query 00690 * finishes in _beforeselect. 00691 */ 00692 00693 ADNS_API void adns_afterselect(adns_state ads, int maxfd, const fd_set *readfds, 00694 const fd_set *writefds, const fd_set *exceptfds, 00695 const struct timeval *now); 00696 /* Gives adns flow-of-control for a bit; intended for use after 00697 * select. This is just a fancy way of calling adns_processreadable/ 00698 * writeable/timeouts as appropriate, as if select had returned the 00699 * data being passed. Always succeeds. 00700 */ 00701 00702 /* 00703 * Example calling sequence: 00704 * 00705 * adns_init _noautosys 00706 * loop { 00707 * adns_beforeselect 00708 * select 00709 * adns_afterselect 00710 * ... 00711 * adns_submit / adns_check 00712 * ... 00713 * } 00714 */ 00715 00716 /* 00717 * Entrypoints for poll-loop based asynch io: 00718 */ 00719 00720 struct pollfd; 00721 /* In case your system doesn't have it or you forgot to include 00722 * <sys/poll.h>, to stop the following declarations from causing 00723 * problems. If your system doesn't have poll then the following 00724 * entrypoints will not be defined in libadns. Sorry ! 00725 */ 00726 00727 ADNS_API int adns_beforepoll(adns_state ads, struct pollfd *fds, int *nfds_io, int *timeout_io, 00728 const struct timeval *now); 00729 /* Finds out which fd's adns is interested in, and when it would like 00730 * to be able to time things out. This is in a form suitable for use 00731 * with poll(2). 00732 * 00733 * On entry, usually fds should point to at least *nfds_io structs. 00734 * adns will fill up to that many structs will information for poll, 00735 * and record in *nfds_io how many structs it filled. If it wants to 00736 * listen for more structs then *nfds_io will be set to the number 00737 * required and _beforepoll will return ERANGE. 00738 * 00739 * You may call _beforepoll with fds==0 and *nfds_io 0, in which case 00740 * adns will fill in the number of fds that it might be interested in 00741 * in *nfds_io, and always return either 0 (if it is not interested in 00742 * any fds) or ERANGE (if it is). 00743 * 00744 * NOTE that (unless now is 0) adns may acquire additional fds 00745 * from one call to the next, so you must put adns_beforepoll in a 00746 * loop, rather than assuming that the second call (with the buffer 00747 * size requested by the first) will not return ERANGE. 00748 * 00749 * adns only ever sets POLLIN, POLLOUT and POLLPRI in its pollfd 00750 * structs, and only ever looks at those bits. POLLPRI is required to 00751 * detect TCP Urgent Data (which should not be used by a DNS server) 00752 * so that adns can know that the TCP stream is now useless. 00753 * 00754 * In any case, *timeout_io should be a timeout value as for poll(2), 00755 * which adns will modify downwards as required. If the caller does 00756 * not plan to block then *timeout_io should be 0 on entry, or 00757 * alternatively, timeout_io may be 0. (Alternatively, the caller may 00758 * use _beforeselect with timeout_io==0 to find out about file 00759 * descriptors, and use _firsttimeout is used to find out when adns 00760 * might want to time something out.) 00761 * 00762 * adns_beforepoll will return 0 on success, and will not fail for any 00763 * reason other than the fds buffer being too small (ERANGE). 00764 * 00765 * This call will never actually do any I/O. If you supply the 00766 * current time it will not change the fds that adns is using or the 00767 * timeouts it wants. 00768 * 00769 * In any case this call won't block. 00770 */ 00771 00772 #define ADNS_POLLFDS_RECOMMENDED 2 00773 /* If you allocate an fds buf with at least RECOMMENDED entries then 00774 * you are unlikely to need to enlarge it. You are recommended to do 00775 * so if it's convenient. However, you must be prepared for adns to 00776 * require more space than this. 00777 */ 00778 00779 ADNS_API void adns_afterpoll(adns_state ads, const struct pollfd *fds, int nfds, 00780 const struct timeval *now); 00781 /* Gives adns flow-of-control for a bit; intended for use after 00782 * poll(2). fds and nfds should be the results from poll(). pollfd 00783 * structs mentioning fds not belonging to adns will be ignored. 00784 */ 00785 00786 00787 ADNS_API adns_status adns_rr_info(adns_rrtype type, 00788 const char **rrtname_r, const char **fmtname_r, 00789 int *len_r, 00790 const void *datap, char **data_r); 00791 /* 00792 * Get information about a query type, or convert reply data to a 00793 * textual form. type must be specified, and the official name of the 00794 * corresponding RR type will be returned in *rrtname_r, and 00795 * information about the processing style in *fmtname_r. The length 00796 * of the table entry in an answer for that type will be returned in 00797 * in *len_r. Any or all of rrtname_r, fmtname_r and len_r may be 0. 00798 * If fmtname_r is non-null then *fmtname_r may be null on return, 00799 * indicating that no special processing is involved. 00800 * 00801 * data_r be must be non-null iff datap is. In this case *data_r will 00802 * be set to point to a string pointing to a representation of the RR 00803 * data in master file format. (The owner name, timeout, class and 00804 * type will not be present - only the data part of the RR.) The 00805 * memory will have been obtained from malloc() and must be freed by 00806 * the caller. 00807 * 00808 * Usually this routine will succeed. Possible errors include: 00809 * adns_s_nomemory 00810 * adns_s_rrtypeunknown 00811 * adns_s_invaliddata (*datap contained garbage) 00812 * If an error occurs then no memory has been allocated, 00813 * and *rrtname_r, *fmtname_r, *len_r and *data_r are undefined. 00814 * 00815 * There are some adns-invented data formats which are not official 00816 * master file formats. These include: 00817 * 00818 * Mailboxes if __qtf_mail822: these are just included as-is. 00819 * 00820 * Addresses (adns_rr_addr): these may be of pretty much any type. 00821 * The representation is in two parts: first, a word for the address 00822 * family (ie, in AF_XXX, the XXX), and then one or more items for the 00823 * address itself, depending on the format. For an IPv4 address the 00824 * syntax is INET followed by the dotted quad (from inet_ntoa). 00825 * Currently only IPv4 is supported. 00826 * 00827 * Text strings (as in adns_rr_txt) appear inside double quotes, and 00828 * use \" and \\ to represent " and \, and \xHH to represent 00829 * characters not in the range 32-126. 00830 * 00831 * Hostname with addresses (adns_rr_hostaddr): this consists of the 00832 * hostname, as usual, followed by the adns_status value, as an 00833 * abbreviation, and then a descriptive string (encoded as if it were 00834 * a piece of text), for the address lookup, followed by zero or more 00835 * addresses enclosed in ( and ). If the result was a temporary 00836 * failure, then a single ? appears instead of the ( ). If the 00837 * result was a permanent failure then an empty pair of parentheses 00838 * appears (which a space in between). For example, one of the NS 00839 * records for greenend.org.uk comes out like 00840 * ns.chiark.greenend.org.uk ok "OK" ( INET 195.224.76.132 ) 00841 * an MX referring to a nonexistent host might come out like: 00842 * 50 sun2.nsfnet-relay.ac.uk nxdomain "No such domain" ( ) 00843 * and if nameserver information is not available you might get: 00844 * dns2.spong.dyn.ml.org timeout "DNS query timed out" ? 00845 */ 00846 00847 ADNS_API const char *adns_strerror(adns_status st); 00848 ADNS_API const char *adns_errabbrev(adns_status st); 00849 ADNS_API const char *adns_errtypeabbrev(adns_status st); 00850 /* Like strerror but for adns_status values. adns_errabbrev returns 00851 * the abbreviation of the error - eg, for adns_s_timeout it returns 00852 * "timeout". adns_errtypeabbrev returns the abbreviation of the 00853 * error class: ie, for values up to adns_s_max_XXX it will return the 00854 * string XXX. You MUST NOT call these functions with status values 00855 * not returned by the same adns library. 00856 */ 00857 00858 #ifdef __cplusplus 00859 } /* end of extern "C" */ 00860 #endif 00861 #endif Generated on Fri May 25 2012 04:31:58 for ReactOS by
1.7.6.1
|