ReactOS 0.4.15-dev-5893-g1bb4167
adh-query.c File Reference
#include "adnshost.h"
Include dependency graph for adh-query.c:

Go to the source code of this file.

Functions

void ensure_adns_init (void)
 
static void prep_query (struct query_node **qun_r, int *quflags_r)
 
void of_ptr (const struct optioninfo *oi, const char *arg, const char *arg2)
 
void of_reverse (const struct optioninfo *oi, const char *arg, const char *arg2)
 
void query_do (const char *domain)
 
static void dequeue_query (struct query_node *qun)
 
static void print_withspace (const char *str)
 
static void print_ttl (struct query_node *qun, adns_answer *answer)
 
static const charowner_show (struct query_node *qun, adns_answer *answer)
 
static void print_owner_ttl (struct query_node *qun, adns_answer *answer)
 
static void check_status (adns_status st)
 
static void print_status (adns_status st, struct query_node *qun, adns_answer *answer)
 
static void print_dnsfail (adns_status st, struct query_node *qun, adns_answer *answer)
 
void query_done (struct query_node *qun, adns_answer *answer)
 
void of_asynch_id (const struct optioninfo *oi, const char *arg, const char *arg2)
 
void of_cancel_id (const struct optioninfo *oi, const char *arg, const char *arg2)
 

Variables

adns_state ads
 
struct outstanding_list outstanding
 
static unsigned long idcounter
 

Function Documentation

◆ check_status()

static void check_status ( adns_status  st)
static

Definition at line 194 of file adh-query.c.

194 {
195 static const adns_status statuspoints[]= {
196 adns_s_ok,
199 };
200
201 const adns_status *spp;
202 int minrcode;
203
204 for (minrcode=0, spp=statuspoints;
205 spp < statuspoints + (sizeof(statuspoints)/sizeof(statuspoints[0]));
206 spp++)
207 if (st > *spp) minrcode++;
208 if (rcode < minrcode) rcode= minrcode;
209}
int rcode
Definition: adh-main.c:36
adns_status
Definition: adns.h:215
@ adns_s_max_misconfig
Definition: adns.h:250
@ adns_s_max_localfail
Definition: adns.h:223
@ adns_s_ok
Definition: adns.h:216
@ adns_s_max_misquery
Definition: adns.h:257
@ adns_s_max_tempfail
Definition: adns.h:241
@ adns_s_max_remotefail
Definition: adns.h:232

Referenced by query_done().

◆ dequeue_query()

static void dequeue_query ( struct query_node qun)
static

Definition at line 154 of file adh-query.c.

154 {
156 free(qun->id);
157 free(qun->owner);
158 free(qun);
159}
struct outstanding_list outstanding
Definition: adh-query.c:36
#define free
Definition: debug_ros.c:5
#define LIST_UNLINK(list, node)
Definition: dlist.h:50
char * owner
Definition: adnshost.h:102
char * id
Definition: adnshost.h:102

Referenced by of_cancel_id(), and query_done().

◆ ensure_adns_init()

void ensure_adns_init ( void  )

Definition at line 40 of file adh-query.c.

40 {
42 int r;
43
44 if (ads) return;
45
46#ifdef SIGPIPE
47 if (signal(SIGPIPE,SIG_IGN) == SIG_ERR) sysfail("ignore SIGPIPE",errno);
48#endif
49
52
53 if (config_text) {
55 } else {
56 r= adns_init(&ads, initflags, 0);
57 }
58 if (r) sysfail("adns_init",r);
59
62}
const char * config_text
Definition: adh-main.c:37
void sysfail(const char *what, int errnoval)
Definition: adh-main.c:49
int ov_format
Definition: adh-opts.c:39
int ov_verbose
Definition: adh-opts.c:36
int ov_env
Definition: adh-opts.c:35
int ov_asynch
Definition: adh-opts.c:35
adns_state ads
Definition: adh-query.c:35
ADNS_API int adns_init(adns_state *newstate_r, adns_initflags flags, FILE *diagfile)
Definition: setup.c:568
adns_initflags
Definition: adns.h:87
@ adns_if_noautosys
Definition: adns.h:93
@ adns_if_noenv
Definition: adns.h:88
@ adns_if_nosigpipe
Definition: adns.h:95
ADNS_API int adns_init_strcfg(adns_state *newstate_r, adns_initflags flags, FILE *diagfile, const char *configtext)
Definition: setup.c:629
@ fmt_simple
Definition: adnshost.h:75
@ fmt_asynch
Definition: adnshost.h:75
@ fmt_default
Definition: adnshost.h:75
static adns_initflags initflags
Definition: adnsresfilter.c:62
#define SIG_ERR
Definition: signal.h:52
#define SIGPIPE
Definition: signal.h:35
#define SIG_IGN
Definition: signal.h:48
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define stderr
Definition: stdio.h:100
#define errno
Definition: errno.h:18
int signal
Definition: except.c:82

Referenced by main(), and prep_query().

◆ of_asynch_id()

void of_asynch_id ( const struct optioninfo oi,
const char arg,
const char arg2 
)

Definition at line 301 of file adh-query.c.

301 {
302 free(ov_id);
304}
char * ov_id
Definition: adh-opts.c:40
WCHAR * xstrsave(const WCHAR *str)
Definition: query.c:544

◆ of_cancel_id()

void of_cancel_id ( const struct optioninfo oi,
const char arg,
const char arg2 
)

Definition at line 306 of file adh-query.c.

306 {
307 struct query_node *qun;
308
309 for (qun= outstanding.head;
310 qun && strcmp(qun->id,arg);
311 qun= qun->next);
312 if (!qun) return;
313 adns_cancel(qun->qu);
314 dequeue_query(qun);
315}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static void dequeue_query(struct query_node *qun)
Definition: adh-query.c:154
ADNS_API void adns_cancel(adns_query query)
Definition: query.c:430
struct query_node * next
Definition: adnshost.h:100
adns_query qu
Definition: adnshost.h:103

◆ of_ptr()

void of_ptr ( const struct optioninfo oi,
const char arg,
const char arg2 
)

Definition at line 93 of file adh-query.c.

93 {
94 struct query_node *qun;
95 int quflags, r;
96 struct sockaddr_in sa;
97
98 memset(&sa,0,sizeof(sa));
99 sa.sin_family= AF_INET;
100 if (!inet_aton(arg,&sa.sin_addr)) usageerr("invalid IP address %s",arg);
101
102 prep_query(&qun,&quflags);
103 qun->owner= xstrsave(arg);
105 (struct sockaddr*)&sa,
107 quflags,
108 qun,
109 &qun->qu);
110 if (r) sysfail("adns_submit_reverse",r);
111
113}
void usageerr(const char *fmt,...)
Definition: adh-main.c:54
adns_rrtype ov_type
Definition: adh-opts.c:37
static void prep_query(struct query_node **qun_r, int *quflags_r)
Definition: adh-query.c:64
@ adns_r_none
Definition: adns.h:118
@ adns_r_ptr
Definition: adns.h:131
ADNS_API int adns_submit_reverse(adns_state ads, const struct sockaddr *addr, adns_rrtype type, adns_queryflags flags, void *context, adns_query *query_r)
Definition: query.c:304
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define AF_INET
Definition: tcpip.h:117
#define inet_aton(cp, addr)
Definition: inet.h:99
#define LIST_LINK_TAIL(list, node)
Definition: dlist.h:51
#define memset(x, y, z)
Definition: compat.h:39

◆ of_reverse()

void of_reverse ( const struct optioninfo oi,
const char arg,
const char arg2 
)

Definition at line 115 of file adh-query.c.

115 {
116 struct query_node *qun;
117 int quflags, r;
118 struct sockaddr_in sa;
119
120 memset(&sa,0,sizeof(sa));
121 sa.sin_family= AF_INET;
122 if (!inet_aton(arg,&sa.sin_addr)) usageerr("invalid IP address %s",arg);
123
124 prep_query(&qun,&quflags);
125 qun->owner= xmalloc(strlen(arg) + strlen(arg2) + 2);
126 sprintf(qun->owner, "%s %s", arg,arg2);
128 (struct sockaddr*)&sa, arg2,
130 quflags,
131 qun,
132 &qun->qu);
133 if (r) sysfail("adns_submit_reverse",r);
134
136}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
@ adns_r_txt
Definition: adns.h:138
ADNS_API int adns_submit_reverse_any(adns_state ads, const struct sockaddr *addr, const char *rzone, adns_rrtype type, adns_queryflags flags, void *context, adns_query *query_r)
Definition: query.c:271
void * xmalloc(int size)
Definition: uimain.c:747
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
#define sprintf(buf, format,...)
Definition: sprintf.c:55

◆ owner_show()

static const char * owner_show ( struct query_node qun,
adns_answer answer 
)
static

Definition at line 185 of file adh-query.c.

185 {
186 return answer->owner ? answer->owner : qun->owner;
187}
char * owner
Definition: adns.h:313

Referenced by print_dnsfail(), print_owner_ttl(), and query_done().

◆ prep_query()

static void prep_query ( struct query_node **  qun_r,
int quflags_r 
)
static

Definition at line 64 of file adh-query.c.

64 {
65 struct query_node *qun;
66 char idbuf[20];
67
68 if (ov_pipe && !ads) usageerr("-f/--pipe not consistent with domains on command line");
70
71 qun= malloc(sizeof(*qun));
72 qun->pqfr= ov_pqfr;
73 if (ov_id) {
74 qun->id= xstrsave(ov_id);
75 } else {
76 sprintf(idbuf,"%lu",idcounter++);
77 idcounter &= 0x0fffffffflu;
78 qun->id= xstrsave(idbuf);
79 }
80
81 *quflags_r=
83 (ov_tcp ? adns_qf_usevc : 0) |
84 ((ov_pqfr.show_owner || ov_format == fmt_simple) ? adns_qf_owner : 0) |
89
90 *qun_r= qun;
91}
int ov_qc_anshost
Definition: adh-opts.c:38
int ov_qc_cname
Definition: adh-opts.c:38
struct perqueryflags_remember ov_pqfr
Definition: adh-opts.c:41
int ov_cname
Definition: adh-opts.c:39
int ov_qc_query
Definition: adh-opts.c:38
int ov_pipe
Definition: adh-opts.c:35
int ov_search
Definition: adh-opts.c:38
int ov_tcp
Definition: adh-opts.c:39
static unsigned long idcounter
Definition: adh-query.c:38
void ensure_adns_init(void)
Definition: adh-query.c:40
@ adns_qf_quoteok_cname
Definition: adns.h:105
@ adns_qf_usevc
Definition: adns.h:102
@ adns_qf_quoteok_query
Definition: adns.h:104
@ adns_qf_quoteok_anshost
Definition: adns.h:106
@ adns_qf_search
Definition: adns.h:101
@ adns_qf_owner
Definition: adns.h:103
#define malloc
Definition: debug_ros.c:4
struct perqueryflags_remember pqfr
Definition: adnshost.h:101

Referenced by of_ptr(), of_reverse(), and query_do().

◆ print_dnsfail()

static void print_dnsfail ( adns_status  st,
struct query_node qun,
adns_answer answer 
)
static

Definition at line 227 of file adh-query.c.

227 {
228 int r;
229 const char *typename, *statusstring;
230 adns_status ist;
231
232 if (ov_format == fmt_inline) {
233 if (fputs("; failed ",stdout) == EOF) outerr();
234 print_status(st,qun,answer);
235 return;
236 }
238 if (st == adns_s_nxdomain) {
239 r= fprintf(stderr,"%s does not exist\n", owner_show(qun,answer));
240 } else {
241 ist= adns_rr_info(answer->type, &typename, 0,0,0,0);
242 if (st == adns_s_nodata) {
243 r= fprintf(stderr,"%s has no %s record\n", owner_show(qun,answer), typename);
244 } else {
245 statusstring= adns_strerror(st);
246 r= fprintf(stderr,"Error during DNS %s lookup for %s: %s\n",
247 typename, owner_show(qun,answer), statusstring);
248 }
249 }
250 if (r == EOF) sysfail("write error message to stderr",errno);
251}
void outerr(void)
Definition: adh-main.c:64
static void print_status(adns_status st, struct query_node *qun, adns_answer *answer)
Definition: adh-query.c:211
static const char * owner_show(struct query_node *qun, adns_answer *answer)
Definition: adh-query.c:185
ADNS_API const char * adns_strerror(adns_status st)
Definition: general.c:268
ADNS_API adns_status adns_rr_info(adns_rrtype type, const char **rrtname_r, const char **fmtname_r, int *len_r, const void *datap, char **data_r)
Definition: general.c:186
@ adns_s_nodata
Definition: adns.h:261
@ adns_s_nxdomain
Definition: adns.h:260
@ fmt_inline
Definition: adnshost.h:75
#define assert(x)
Definition: debug.h:53
#define stdout
Definition: stdio.h:99
#define EOF
Definition: stdio.h:24
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
adns_rrtype type
Definition: adns.h:314

Referenced by query_done().

◆ print_owner_ttl()

static void print_owner_ttl ( struct query_node qun,
adns_answer answer 
)
static

Definition at line 189 of file adh-query.c.

189 {
190 if (qun->pqfr.show_owner) print_withspace(owner_show(qun,answer));
191 print_ttl(qun,answer);
192}
static void print_ttl(struct query_node *qun, adns_answer *answer)
Definition: adh-query.c:165
static void print_withspace(const char *str)
Definition: adh-query.c:161

Referenced by print_status(), and query_done().

◆ print_status()

static void print_status ( adns_status  st,
struct query_node qun,
adns_answer answer 
)
static

Definition at line 211 of file adh-query.c.

211 {
212 const char *statustypeabbrev, *statusabbrev, *statusstring;
213
214 statustypeabbrev= adns_errtypeabbrev(st);
215 statusabbrev= adns_errabbrev(st);
216 statusstring= adns_strerror(st);
217 assert(!strchr(statusstring,'"'));
218
219 if (printf("%s %d %s ", statustypeabbrev, st, statusabbrev)
220 == EOF) outerr();
221 print_owner_ttl(qun,answer);
222 if (qun->pqfr.show_cname)
223 print_withspace(answer->cname ? answer->cname : "$");
224 if (printf("\"%s\"\n", statusstring) == EOF) outerr();
225}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
static void print_owner_ttl(struct query_node *qun, adns_answer *answer)
Definition: adh-query.c:189
ADNS_API const char * adns_errtypeabbrev(adns_status st)
Definition: general.c:311
ADNS_API const char * adns_errabbrev(adns_status st)
Definition: general.c:275
#define printf
Definition: freeldr.h:94
char * cname
Definition: adns.h:312

Referenced by print_dnsfail(), and query_done().

◆ print_ttl()

static void print_ttl ( struct query_node qun,
adns_answer answer 
)
static

Definition at line 165 of file adh-query.c.

165 {
166 unsigned long ttl;
167 time_t now;
168
169 switch (qun->pqfr.ttl) {
170 case tm_none:
171 return;
172 case tm_rel:
173 if (time(&now) == (time_t)-1) sysfail("get current time",errno);
174 ttl= answer->expires < now ? 0 : answer->expires - now;
175 break;
176 case tm_abs:
177 ttl= answer->expires;
178 break;
179 default:
180 abort();
181 }
182 if (printf("%lu ",ttl) == EOF) outerr();
183}
@ tm_rel
Definition: adnshost.h:74
@ tm_none
Definition: adnshost.h:74
@ tm_abs
Definition: adnshost.h:74
__kernel_time_t time_t
Definition: linux.h:252
time_t now
Definition: finger.c:65
#define abort()
Definition: i386-dis.c:35
__u16 time
Definition: mkdosfs.c:8
time_t expires
Definition: adns.h:315

Referenced by print_owner_ttl(), and query_done().

◆ print_withspace()

static void print_withspace ( const char str)
static

Definition at line 161 of file adh-query.c.

161 {
162 if (printf("%s ", str) == EOF) outerr();
163}
const WCHAR * str

Referenced by print_owner_ttl(), print_status(), and query_done().

◆ query_do()

void query_do ( const char domain)

Definition at line 138 of file adh-query.c.

138 {
139 struct query_node *qun;
140 int quflags, r;
141
142 prep_query(&qun,&quflags);
143 qun->owner= xstrsave(domain);
146 quflags,
147 qun,
148 &qun->qu);
149 if (r) sysfail("adns_submit",r);
150
152}
@ adns_r_addr
Definition: adns.h:143
ADNS_API int adns_submit(adns_state ads, const char *owner, adns_rrtype type, adns_queryflags flags, void *context, adns_query *query_r)
Definition: query.c:204
Definition: cookie.c:42

Referenced by process_optarg().

◆ query_done()

void query_done ( struct query_node qun,
adns_answer answer 
)

Definition at line 253 of file adh-query.c.

253 {
254 adns_status st, ist;
255 int rrn, nrrs;
256 const char *rrp, *realowner, *typename;
257 char *datastr;
258
259 st= answer->status;
260 nrrs= answer->nrrs;
261 if (ov_format == fmt_asynch) {
262 check_status(st);
263 if (printf("%s %d ", qun->id, nrrs) == EOF) outerr();
264 print_status(st,qun,answer);
265 } else {
266 if (qun->pqfr.show_cname && answer->cname) {
267 print_owner_ttl(qun,answer);
268 if (qun->pqfr.show_type) print_withspace("CNAME");
269 if (printf("%s\n", answer->cname) == EOF) outerr();
270 }
271 if (st) {
272 check_status(st);
273 print_dnsfail(st,qun,answer);
274 }
275 }
276 if (qun->pqfr.show_owner) {
277 realowner= answer->cname ? answer->cname : owner_show(qun,answer);
278 assert(realowner);
279 } else {
280 realowner= 0;
281 }
282 if (nrrs) {
283 for (rrn=0, rrp = answer->rrs.untyped;
284 rrn < nrrs;
285 rrn++, rrp += answer->rrsz) {
286 if (realowner) print_withspace(realowner);
287 print_ttl(qun,answer);
288 ist= adns_rr_info(answer->type, &typename, 0, 0, rrp, &datastr);
289 if (ist == adns_s_nomemory) sysfail("adns_rr_info failed",ENOMEM);
290 assert(!ist);
291 if (qun->pqfr.show_type) print_withspace(typename);
292 if (printf("%s\n",datastr) == EOF) outerr();
293 free(datastr);
294 }
295 }
296 if (fflush(stdout)) outerr();
297 free(answer);
298 dequeue_query(qun);
299}
#define ENOMEM
Definition: acclib.h:84
static void print_dnsfail(adns_status st, struct query_node *qun, adns_answer *answer)
Definition: adh-query.c:227
static void check_status(adns_status st)
Definition: adh-query.c:194
@ adns_s_nomemory
Definition: adns.h:219
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
int nrrs
Definition: adns.h:316
int rrsz
Definition: adns.h:316
adns_status status
Definition: adns.h:311
union adns_answer::@4019 rrs
void * untyped
Definition: adns.h:318

Referenced by adns__consistency(), adns__query_done(), adns_cancel(), and main().

Variable Documentation

◆ ads

Definition at line 35 of file adh-query.c.

Referenced by _Function_class_(), addserver(), adns__autosys(), adns__consistency(), adns__debug(), adns__diag(), adns__diag_domain(), adns__fdevents(), adns__findlabel_start(), adns__internal_check(), adns__internal_submit(), adns__mkquery(), adns__mkquery_frdgram(), adns__must_gettimeofday(), adns__parse_domain(), adns__pollfds(), adns__procdgram(), adns__query_send(), adns__querysend_tcp(), adns__search_next(), adns__sigpipe_protect(), adns__sigpipe_unprotect(), adns__tcp_broken(), adns__tcp_tryconnect(), adns__timeouts(), adns__vdiag(), adns__warn(), adns_addserver(), adns_afterselect(), adns_beforeselect(), adns_cancel(), adns_ccf_search(), adns_check(), adns_checkconsistency(), adns_finish(), adns_firsttimeout(), adns_forallqueries_begin(), adns_forallqueries_next(), adns_globalsystemfailure(), adns_init(), adns_init_strcfg(), adns_numservers(), adns_processany(), adns_processexceptional(), adns_processreadable(), adns_processtimeouts(), adns_processwriteable(), adns_submit(), adns_submit_reverse(), adns_submit_reverse_any(), adns_synchronous(), adns_wait(), ccf_clearnss(), ccf_include(), ccf_nameserver(), ccf_options(), ccf_search(), ccf_sortlist(), checkc_global(), checkc_notcpbuf(), checkc_query(), checkc_queue_childw(), checkc_queue_output(), checkc_queue_tcpw(), checkc_queue_udpw(), configparseerr(), di_addr(), di_hostaddr(), di_inaddr(), di_mx(), dip_hostaddr(), dip_inaddr(), div_addr(), ensure_adns_init(), fd_event(), find(), freesearchlist(), gl_file(), gl_text(), icb_hostaddr(), icb_ptr(), init_abort(), init_begin(), init_finish(), instrum_getenv(), main(), mkquery_header(), of_ptr(), of_reverse(), prep_query(), query_alloc(), query_do(), query_simple(), quitnow(), readconfig(), readconfigenv(), readconfigenvtext(), readconfiggeneric(), readconfigtext(), saveerr(), search_sortlist(), tcp_close(), tcp_connected(), and tcp_events().

◆ idcounter

unsigned long idcounter
static

Definition at line 38 of file adh-query.c.

Referenced by prep_query().

◆ outstanding