ReactOS  0.4.15-dev-1197-g8081ba9
query.c File Reference
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>
#include "internal.h"
Include dependency graph for query.c:

Go to the source code of this file.

Functions

static adns_query query_alloc (adns_state ads, const typeinfo *typei, adns_queryflags flags, struct timeval now)
 
static void query_submit (adns_state ads, adns_query qu, const typeinfo *typei, vbuf *qumsg_vb, int id, adns_queryflags flags, struct timeval now)
 
adns_status adns__internal_submit (adns_state ads, adns_query *query_r, const typeinfo *typei, vbuf *qumsg_vb, int id, adns_queryflags flags, struct timeval now, const qcontext *ctx)
 
static void query_simple (adns_state ads, adns_query qu, const char *owner, int ol, const typeinfo *typei, adns_queryflags flags, struct timeval now)
 
void adns__search_next (adns_state ads, adns_query qu, struct timeval now)
 
static int save_owner (adns_query qu, const char *owner, int ol)
 
int adns_submit (adns_state ads, const char *owner, adns_rrtype type, adns_queryflags flags, void *context, adns_query *query_r)
 
int adns_submit_reverse_any (adns_state ads, const struct sockaddr *addr, const char *zone, adns_rrtype type, adns_queryflags flags, void *context, adns_query *query_r)
 
int adns_submit_reverse (adns_state ads, const struct sockaddr *addr, adns_rrtype type, adns_queryflags flags, void *context, adns_query *query_r)
 
int adns_synchronous (adns_state ads, const char *owner, adns_rrtype type, adns_queryflags flags, adns_answer **answer_r)
 
static voidalloc_common (adns_query qu, size_t sz)
 
voidadns__alloc_interim (adns_query qu, size_t sz)
 
voidadns__alloc_preserved (adns_query qu, size_t sz)
 
voidadns__alloc_mine (adns_query qu, size_t sz)
 
void adns__transfer_interim (adns_query from, adns_query to, void *block, size_t sz)
 
voidadns__alloc_final (adns_query qu, size_t sz)
 
static void cancel_children (adns_query qu)
 
void adns__reset_preserved (adns_query qu)
 
static void free_query_allocs (adns_query qu)
 
void adns_cancel (adns_query qu)
 
void adns__update_expires (adns_query qu, unsigned long ttl, struct timeval now)
 
static void makefinal_query (adns_query qu)
 
void adns__query_done (adns_query qu)
 
void adns__query_fail (adns_query qu, adns_status stat)
 
void adns__makefinal_str (adns_query qu, char **strp)
 
void adns__makefinal_block (adns_query qu, void **blpp, size_t sz)
 

Function Documentation

◆ adns__alloc_final()

void* adns__alloc_final ( adns_query  qu,
size_t  sz 
)

Definition at line 385 of file query.c.

385  {
386  /* When we're in the _final stage, we _subtract_ from interim_alloc'd
387  * each allocation, and use final_allocspace to point to the next free
388  * bit.
389  */
390  void *rp;
391 
392  sz= MEM_ROUND(sz);
393  rp= qu->final_allocspace;
394  assert(rp);
395  qu->interim_allocd -= sz;
396  assert(qu->interim_allocd>=0);
397  qu->final_allocspace= (byte*)rp + sz;
398  return rp;
399 }
#define assert(x)
Definition: debug.h:53
void * final_allocspace
Definition: internal.h:189
#define MEM_ROUND(sz)
Definition: internal.h:711
int interim_allocd
Definition: internal.h:188

Referenced by adns__makefinal_block(), and adns__makefinal_str().

◆ adns__alloc_interim()

void* adns__alloc_interim ( adns_query  qu,
size_t  sz 
)

Definition at line 342 of file query.c.

342  {
343  void *rv;
344 
345  sz= MEM_ROUND(sz);
346  rv= alloc_common(qu,sz);
347  if (!rv) return 0;
348  qu->interim_allocd += sz;
349  return rv;
350 }
static void * alloc_common(adns_query qu, size_t sz)
Definition: query.c:331
#define MEM_ROUND(sz)
Definition: internal.h:711
int interim_allocd
Definition: internal.h:188

Referenced by adns__alloc_preserved(), adns__procdgram(), pa_txt(), pap_domain(), pap_findaddrs(), pap_mailbox822(), and pap_qstring().

◆ adns__alloc_mine()

void* adns__alloc_mine ( adns_query  qu,
size_t  sz 
)

Definition at line 362 of file query.c.

362  {
363  return alloc_common(qu,MEM_ROUND(sz));
364 }
static void * alloc_common(adns_query qu, size_t sz)
Definition: query.c:331
#define MEM_ROUND(sz)
Definition: internal.h:711

Referenced by adns__procdgram().

◆ adns__alloc_preserved()

void* adns__alloc_preserved ( adns_query  qu,
size_t  sz 
)

Definition at line 352 of file query.c.

352  {
353  void *rv;
354 
355  sz= MEM_ROUND(sz);
356  rv= adns__alloc_interim(qu,sz);
357  if (!rv) return 0;
358  qu->preserved_allocd += sz;
359  return rv;
360 }
int preserved_allocd
Definition: internal.h:188
void * adns__alloc_interim(adns_query qu, size_t sz)
Definition: query.c:342
#define MEM_ROUND(sz)
Definition: internal.h:711

Referenced by adns__procdgram(), and save_owner().

◆ adns__internal_submit()

adns_status adns__internal_submit ( adns_state  ads,
adns_query query_r,
const typeinfo typei,
vbuf qumsg_vb,
int  id,
adns_queryflags  flags,
struct timeval  now,
const qcontext ctx 
)

Definition at line 111 of file query.c.

114  {
115  adns_query qu;
116 
117  qu= query_alloc(ads,typei,flags,now);
118  if (!qu) { adns__vbuf_free(qumsg_vb); return adns_s_nomemory; }
119  *query_r= qu;
120 
121  memcpy(&qu->ctx,ctx,(size_t) sizeof(qu->ctx));
122  query_submit(ads,qu, typei,qumsg_vb,id,flags,now);
123 
124  return adns_s_ok;
125 }
void adns__vbuf_free(vbuf *vb)
Definition: general.c:155
adns_state ads
Definition: adh-query.c:35
static adns_query query_alloc(adns_state ads, const typeinfo *typei, adns_queryflags flags, struct timeval now)
Definition: query.c:41
time_t now
Definition: finger.c:65
qcontext ctx
Definition: internal.h:233
GLbitfield flags
Definition: glext.h:7161
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void query_submit(adns_state ads, adns_query qu, const typeinfo *typei, vbuf *qumsg_vb, int id, adns_queryflags flags, struct timeval now)
Definition: query.c:91

Referenced by pa_ptr(), and pap_hostaddr().

◆ adns__makefinal_block()

void adns__makefinal_block ( adns_query  qu,
void **  blpp,
size_t  sz 
)

Definition at line 565 of file query.c.

565  {
566  void *before, *after;
567 
568  before= *blpp;
569  if (!before) return;
570  after= adns__alloc_final(qu,sz);
571  memcpy(after,before, (size_t) sz);
572  *blpp= after;
573 }
__inline int before(__u32 seq1, __u32 seq2)
Definition: tcpcore.h:2414
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
__inline int after(__u32 seq1, __u32 seq2)
Definition: tcpcore.h:2419
void * adns__alloc_final(adns_query qu, size_t sz)
Definition: query.c:385

Referenced by makefinal_query(), mf_manyistr(), and mfp_hostaddr().

◆ adns__makefinal_str()

void adns__makefinal_str ( adns_query  qu,
char **  strp 
)

Definition at line 553 of file query.c.

553  {
554  int l;
555  char *before, *after;
556 
557  before= *strp;
558  if (!before) return;
559  l= strlen(before)+1;
560  after= adns__alloc_final(qu, (size_t) l);
561  memcpy(after,before,(size_t) l);
562  *strp= after;
563 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
__inline int before(__u32 seq1, __u32 seq2)
Definition: tcpcore.h:2414
r l[0]
Definition: byte_order.h:167
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
__inline int after(__u32 seq1, __u32 seq2)
Definition: tcpcore.h:2419
void * adns__alloc_final(adns_query qu, size_t sz)
Definition: query.c:385

Referenced by makefinal_query(), mf_intstr(), mf_intstrpair(), mf_manyistr(), mf_soa(), mf_str(), mf_strpair(), and mfp_hostaddr().

◆ adns__query_done()

void adns__query_done ( adns_query  qu)

Definition at line 503 of file query.c.

503  {
504  adns_answer *ans;
506 
507  cancel_children(qu);
508 
509  qu->id= -1;
510  ans= qu->answer;
511 
512  if (qu->flags & adns_qf_owner && qu->flags & adns_qf_search &&
513  ans->status != adns_s_nomemory) {
514  if (!save_owner(qu, (char*)qu->search_vb.buf, qu->search_vb.used)) {
516  return;
517  }
518  }
519 
520  if (ans->nrrs && qu->typei->diff_needswap) {
521  if (!adns__vbuf_ensure(&qu->vb,qu->typei->rrsz)) {
523  return;
524  }
525  adns__isort(ans->rrs.bytes, ans->nrrs, ans->rrsz,
526  qu->vb.buf,
527  (int(*)(void*, const void*, const void*))qu->typei->diff_needswap,
528  qu->ads);
529  }
530 
531  ans->expires= qu->expires;
532  parent= qu->parent;
533  if (parent) {
534  LIST_UNLINK_PART(parent->children,qu,siblings.);
535  LIST_UNLINK(qu->ads->childw,parent);
536  qu->ctx.callback(parent,qu);
537  free_query_allocs(qu);
538  free(qu->answer);
539  free(qu);
540  } else {
541  makefinal_query(qu);
542  LIST_LINK_TAIL(qu->ads->output,qu);
543  qu->state= query_done;
544  }
545 }
time_t expires
Definition: internal.h:231
void query_done(struct query_node *qun, adns_answer *answer)
Definition: adh-query.c:253
void adns__isort(void *array, int nobjs, int sz, void *tempbuf, int(*needswap)(void *context, const void *a, const void *b), void *context)
Definition: general.c:319
unsigned char * bytes
Definition: adns.h:319
#define free
Definition: debug_ros.c:5
const typeinfo * typei
Definition: internal.h:191
int(* diff_needswap)(adns_state ads, const void *datap_a, const void *datap_b)
Definition: internal.h:153
int rrsz
Definition: adns.h:316
int adns__vbuf_ensure(vbuf *vb, int want)
Definition: general.c:116
#define LIST_LINK_TAIL(list, node)
Definition: dlist.h:51
#define LIST_UNLINK(list, node)
Definition: dlist.h:50
adns_state ads
Definition: internal.h:182
vbuf search_vb
Definition: internal.h:216
static int save_owner(adns_query qu, const char *owner, int ol)
Definition: query.c:190
qcontext ctx
Definition: internal.h:233
r parent
Definition: btrfs.c:2944
adns_answer * answer
Definition: internal.h:201
time_t expires
Definition: adns.h:315
#define LIST_UNLINK_PART(list, node, part)
Definition: dlist.h:34
adns_status status
Definition: adns.h:311
void(* callback)(adns_query parent, adns_query child)
Definition: internal.h:174
union adns_answer::@3958 rrs
static void cancel_children(adns_query qu)
Definition: query.c:401
byte * buf
Definition: internal.h:112
int nrrs
Definition: adns.h:316
static void makefinal_query(adns_query qu)
Definition: query.c:467
int used
Definition: internal.h:111
void adns__query_fail(adns_query qu, adns_status stat)
Definition: query.c:547
int rrsz
Definition: internal.h:128
struct query_queue udpw tcpw childw output
Definition: internal.h:295
enum adns__query::@3960 state
static void free_query_allocs(adns_query qu)
Definition: query.c:418
adns_query parent
Definition: internal.h:184

Referenced by adns__procdgram(), adns__query_fail(), icb_hostaddr(), and icb_ptr().

◆ adns__query_fail()

void adns__query_fail ( adns_query  qu,
adns_status  stat 
)

Definition at line 547 of file query.c.

547  {
549  qu->answer->status= stat;
550  adns__query_done(qu);
551 }
adns_answer * answer
Definition: internal.h:201
void adns__query_done(adns_query qu)
Definition: query.c:503
adns_status status
Definition: adns.h:311
void adns__reset_preserved(adns_query qu)
Definition: query.c:410
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345

Referenced by adns__procdgram(), adns__query_done(), adns__query_send(), adns__search_next(), adns_globalsystemfailure(), adns_submit(), icb_ptr(), query_simple(), query_submit(), tcp_events(), and timeouts_queue().

◆ adns__reset_preserved()

void adns__reset_preserved ( adns_query  qu)

Definition at line 410 of file query.c.

410  {
411  assert(!qu->final_allocspace);
412  cancel_children(qu);
413  qu->answer->nrrs= 0;
414  qu->answer->rrs.untyped= 0;
416 }
int preserved_allocd
Definition: internal.h:188
#define assert(x)
Definition: debug.h:53
void * final_allocspace
Definition: internal.h:189
adns_answer * answer
Definition: internal.h:201
void * untyped
Definition: adns.h:318
union adns_answer::@3958 rrs
static void cancel_children(adns_query qu)
Definition: query.c:401
int nrrs
Definition: adns.h:316
int interim_allocd
Definition: internal.h:188

Referenced by adns__procdgram(), adns__query_fail(), and makefinal_query().

◆ adns__search_next()

void adns__search_next ( adns_state  ads,
adns_query  qu,
struct timeval  now 
)

Definition at line 151 of file query.c.

151  {
152  const char *nextentry;
154 
155  if (qu->search_doneabs<0) {
156  nextentry= 0;
157  qu->search_doneabs= 1;
158  } else {
159  if (qu->search_pos >= ads->nsearchlist) {
160  if (qu->search_doneabs) {
161  stat= adns_s_nxdomain; goto x_fail;
162  return;
163  } else {
164  nextentry= 0;
165  qu->search_doneabs= 1;
166  }
167  } else {
168  nextentry= ads->searchlist[qu->search_pos++];
169  }
170  }
171 
172  qu->search_vb.used= qu->search_origlen;
173  if (nextentry) {
174  if (!adns__vbuf_append(&qu->search_vb,(byte*)".",1) ||
175  !adns__vbuf_appendstr(&qu->search_vb,nextentry)) {
176  stat= adns_s_nomemory; goto x_fail;
177  }
178  }
179 
180  free(qu->query_dgram);
181  qu->query_dgram= 0; qu->query_dglen= 0;
182 
183  query_simple(ads,qu, (char*)qu->search_vb.buf, qu->search_vb.used, qu->typei, qu->flags, now);
184  return;
185 
186 x_fail:
188 }
adns_state ads
Definition: adh-query.c:35
char ** searchlist
Definition: internal.h:322
#define free
Definition: debug_ros.c:5
const typeinfo * typei
Definition: internal.h:191
adns_status
Definition: adns.h:215
time_t now
Definition: finger.c:65
int search_origlen
Definition: internal.h:217
int adns__vbuf_append(vbuf *vb, const byte *data, int len)
Definition: general.c:131
vbuf search_vb
Definition: internal.h:216
byte * query_dgram
Definition: internal.h:192
int query_dglen
Definition: internal.h:193
int adns__vbuf_appendstr(vbuf *vb, const char *data)
Definition: general.c:149
int search_pos
Definition: internal.h:217
Definition: stat.h:55
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
byte * buf
Definition: internal.h:112
int search_doneabs
Definition: internal.h:217
int used
Definition: internal.h:111
void adns__query_fail(adns_query qu, adns_status stat)
Definition: query.c:547
int nsearchlist
Definition: internal.h:300
static void query_simple(adns_state ads, adns_query qu, const char *owner, int ol, const typeinfo *typei, adns_queryflags flags, struct timeval now)
Definition: query.c:127

Referenced by adns__procdgram(), adns_submit(), and query_simple().

◆ adns__transfer_interim()

void adns__transfer_interim ( adns_query  from,
adns_query  to,
void block,
size_t  sz 
)

Definition at line 366 of file query.c.

366  {
367  allocnode *an;
368 
369  if (!block) return;
370  an= (void*)((byte*)block - MEM_ROUND(sizeof(*an)));
371 
372  assert(!to->final_allocspace);
373  assert(!from->final_allocspace);
374 
375  LIST_UNLINK(from->allocations,an);
376  LIST_LINK_TAIL(to->allocations,an);
377 
378  sz= MEM_ROUND(sz);
379  from->interim_allocd -= sz;
380  to->interim_allocd += sz;
381 
382  if (to->expires > from->expires) to->expires= from->expires;
383 }
static unsigned int block
Definition: xmlmemory.c:118
time_t expires
Definition: internal.h:231
struct adns__query::@3963 allocations
#define assert(x)
Definition: debug.h:53
#define LIST_LINK_TAIL(list, node)
Definition: dlist.h:51
void * final_allocspace
Definition: internal.h:189
#define LIST_UNLINK(list, node)
Definition: dlist.h:50
#define MEM_ROUND(sz)
Definition: internal.h:711
CardRegion * from
Definition: spigame.cpp:19
int interim_allocd
Definition: internal.h:188

Referenced by icb_hostaddr().

◆ adns__update_expires()

void adns__update_expires ( adns_query  qu,
unsigned long  ttl,
struct timeval  now 
)

Definition at line 458 of file query.c.

458  {
459  time_t max;
460 
461  assert(ttl <= MAXTTLBELIEVE);
462  max= now.tv_sec + ttl;
463  if (qu->expires < max) return;
464  qu->expires= max;
465 }
time_t expires
Definition: internal.h:231
#define max(a, b)
Definition: svc.c:63
#define assert(x)
Definition: debug.h:53
time_t now
Definition: finger.c:65
#define MAXTTLBELIEVE
Definition: internal.h:70
__kernel_time_t time_t
Definition: linux.h:252

Referenced by adns__procdgram(), and pap_findaddrs().

◆ adns_cancel()

void adns_cancel ( adns_query  qu)

Definition at line 430 of file query.c.

430  {
431  adns_state ads;
432 
433  ads= qu->ads;
435  if (qu->parent) LIST_UNLINK_PART(qu->parent->children,qu,siblings.);
436  switch (qu->state) {
437  case query_tosend:
438  LIST_UNLINK(ads->udpw,qu);
439  break;
440  case query_tcpw:
441  LIST_UNLINK(ads->tcpw,qu);
442  break;
443  case query_childw:
444  LIST_UNLINK(ads->childw,qu);
445  break;
446  case query_done:
447  LIST_UNLINK(ads->output,qu);
448  break;
449  default:
450  abort();
451  }
452  free_query_allocs(qu);
453  free(qu->answer);
454  free(qu);
456 }
void query_done(struct query_node *qun, adns_answer *answer)
Definition: adh-query.c:253
struct adns__query::@3961 children
adns_state ads
Definition: adh-query.c:35
#define free
Definition: debug_ros.c:5
#define LIST_UNLINK(list, node)
Definition: dlist.h:50
adns_state ads
Definition: internal.h:182
adns_answer * answer
Definition: internal.h:201
#define LIST_UNLINK_PART(list, node, part)
Definition: dlist.h:34
#define abort()
Definition: i386-dis.c:35
void adns__consistency(adns_state ads, adns_query qu, consistency_checks cc)
Definition: check.c:185
struct query_queue udpw tcpw childw output
Definition: internal.h:295
enum adns__query::@3960 state
static void free_query_allocs(adns_query qu)
Definition: query.c:418
adns_query parent
Definition: internal.h:184

Referenced by adns_finish(), adns_synchronous(), cancel_children(), and of_cancel_id().

◆ adns_submit()

int adns_submit ( adns_state  ads,
const char owner,
adns_rrtype  type,
adns_queryflags  flags,
void context,
adns_query query_r 
)

Definition at line 204 of file query.c.

209  {
210  int r, ol, ndots;
212  const typeinfo *typei;
213  struct timeval now;
214  adns_query qu;
215  const char *p;
216 
218 
219  typei= adns__findtype(type);
220  if (!typei) return ENOSYS;
221 
222  r= gettimeofday(&now,0); if (r) goto x_errno;
223  qu= query_alloc(ads,typei,flags,now); if (!qu) goto x_errno;
224 
225  qu->ctx.ext= context;
226  qu->ctx.callback= 0;
227  memset(&qu->ctx.info,0,sizeof(qu->ctx.info));
228 
229  *query_r= qu;
230 
231  ol= strlen(owner);
232  if (!ol) { stat= adns_s_querydomaininvalid; goto x_adnsfail; }
233  if (ol>DNS_MAXDOMAIN+1) { stat= adns_s_querydomaintoolong; goto x_adnsfail; }
234 
235  if (ol>=1 && owner[ol-1]=='.' && (ol<2 || owner[ol-2]!='\\')) {
236  flags &= ~adns_qf_search;
237  qu->flags= flags;
238  ol--;
239  }
240 
241  if (flags & adns_qf_search) {
242  r= adns__vbuf_append(&qu->search_vb,(byte*)owner,ol);
243  if (!r) { stat= adns_s_nomemory; goto x_adnsfail; }
244 
245  for (ndots=0, p=owner; (p= strchr(p,'.')); p++, ndots++);
246  qu->search_doneabs= (ndots >= ads->searchndots) ? -1 : 0;
247  qu->search_origlen= ol;
249  } else {
250  if (flags & adns_qf_owner) {
251  if (!save_owner(qu,owner,ol)) { stat= adns_s_nomemory; goto x_adnsfail; }
252  }
253  query_simple(ads,qu, owner,ol, typei,flags, now);
254  }
257  return 0;
258 
259  x_adnsfail:
262  return 0;
263 
264  x_errno:
265  r= errno;
266  assert(r);
268  return r;
269 }
adns_state ads
Definition: adh-query.c:35
Definition: http.c:7094
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
static adns_query query_alloc(adns_state ads, const typeinfo *typei, adns_queryflags flags, struct timeval now)
Definition: query.c:41
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define assert(x)
Definition: debug.h:53
int errno
#define gettimeofday(tv, tz)
Definition: adns_win32.h:159
adns_status
Definition: adns.h:215
time_t now
Definition: finger.c:65
int adns__vbuf_append(vbuf *vb, const byte *data, int len)
Definition: general.c:131
static int save_owner(adns_query qu, const char *owner, int ol)
Definition: query.c:190
const typeinfo * adns__findtype(adns_rrtype type)
Definition: types.c:1025
#define ENOSYS
Definition: errno.h:45
GLbitfield flags
Definition: glext.h:7161
Definition: stat.h:55
void adns__autosys(adns_state ads, struct timeval now)
Definition: event.c:665
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
#define DNS_MAXDOMAIN
Definition: internal.h:75
void adns__query_fail(adns_query qu, adns_status stat)
Definition: query.c:547
char * strchr(const char *String, int ch)
Definition: utclib.c:501
void adns__consistency(adns_state ads, adns_query qu, consistency_checks cc)
Definition: check.c:185
GLfloat GLfloat p
Definition: glext.h:8902
#define memset(x, y, z)
Definition: compat.h:39
void adns__search_next(adns_state ads, adns_query qu, struct timeval now)
Definition: query.c:151
int searchndots
Definition: internal.h:300
static void query_simple(adns_state ads, adns_query qu, const char *owner, int ol, const typeinfo *typei, adns_queryflags flags, struct timeval now)
Definition: query.c:127

Referenced by adns_submit_reverse_any(), adns_synchronous(), main(), query_do(), and readline().

◆ adns_submit_reverse()

int adns_submit_reverse ( adns_state  ads,
const struct sockaddr addr,
adns_rrtype  type,
adns_queryflags  flags,
void context,
adns_query query_r 
)

Definition at line 304 of file query.c.

309  {
310  if (type != adns_r_ptr && type != adns_r_ptr_raw) return EINVAL;
311  return adns_submit_reverse_any(ads,addr,"in-addr.arpa",type,flags,context,query_r);
312 }
adns_state ads
Definition: adh-query.c:35
Definition: http.c:7094
Definition: arc.h:39
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
int adns_submit_reverse_any(adns_state ads, const struct sockaddr *addr, const char *zone, adns_rrtype type, adns_queryflags flags, void *context, adns_query *query_r)
Definition: query.c:271
GLbitfield flags
Definition: glext.h:7161
GLenum const GLvoid * addr
Definition: glext.h:9621

Referenced by of_ptr(), and procaddr().

◆ adns_submit_reverse_any()

int adns_submit_reverse_any ( adns_state  ads,
const struct sockaddr addr,
const char zone,
adns_rrtype  type,
adns_queryflags  flags,
void context,
adns_query query_r 
)

Definition at line 271 of file query.c.

277  {
278  const unsigned char *iaddr;
279  char *buf, *buf_free;
280  char shortbuf[100];
281  int r, lreq;
282 
283  flags &= ~adns_qf_search;
284 
285  if (addr->sa_family != AF_INET) return ENOSYS;
286  iaddr= (const unsigned char*) &(((const struct sockaddr_in*)addr) -> sin_addr);
287 
288  lreq= strlen(zone) + 4*4 + 1;
289  if (lreq > (int)sizeof(shortbuf)) {
290  buf= malloc( strlen(zone) + 4*4 + 1 );
291  if (!buf) return errno;
292  buf_free= buf;
293  } else {
294  buf= shortbuf;
295  buf_free= 0;
296  }
297  sprintf(buf, "%d.%d.%d.%d.%s", iaddr[3], iaddr[2], iaddr[1], iaddr[0], zone);
298 
299  r= adns_submit(ads,buf,type,flags,context,query_r);
300  free(buf_free);
301  return r;
302 }
adns_state ads
Definition: adh-query.c:35
Definition: http.c:7094
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define free
Definition: debug_ros.c:5
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
int errno
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define ENOSYS
Definition: errno.h:45
GLbitfield flags
Definition: glext.h:7161
GLenum const GLvoid * addr
Definition: glext.h:9621
Definition: dhcpd.h:125
DWORD zone
Definition: sec_mgr.c:1754
#define AF_INET
Definition: tcpip.h:117
#define malloc
Definition: debug_ros.c:4
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

Referenced by adns_submit_reverse(), and of_reverse().

◆ adns_synchronous()

int adns_synchronous ( adns_state  ads,
const char owner,
adns_rrtype  type,
adns_queryflags  flags,
adns_answer **  answer_r 
)

Definition at line 314 of file query.c.

318  {
319  adns_query qu;
320  int r;
321 
322  r= adns_submit(ads,owner,type,flags,0,&qu);
323  if (r) return r;
324 
325  r= adns_wait(ads,&qu,answer_r,0);
326  if (r) adns_cancel(qu);
327 
328  return r;
329 }
adns_state ads
Definition: adh-query.c:35
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
void adns_cancel(adns_query qu)
Definition: query.c:430
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLbitfield flags
Definition: glext.h:7161
ADNS_API int adns_wait(adns_state ads, adns_query *query_io, adns_answer **answer_r, void **context_r)
Definition: event.c:696
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

Referenced by Query_Main().

◆ alloc_common()

static void* alloc_common ( adns_query  qu,
size_t  sz 
)
static

Definition at line 331 of file query.c.

331  {
332  allocnode *an;
333 
334  if (!sz) return qu; /* Any old pointer will do */
335  assert(!qu->final_allocspace);
336  an= malloc(MEM_ROUND(MEM_ROUND(sizeof(*an)) + sz));
337  if (!an) return 0;
338  LIST_LINK_TAIL(qu->allocations,an);
339  return (byte*)an + MEM_ROUND(sizeof(*an));
340 }
struct adns__query::@3963 allocations
#define assert(x)
Definition: debug.h:53
#define LIST_LINK_TAIL(list, node)
Definition: dlist.h:51
void * final_allocspace
Definition: internal.h:189
#define MEM_ROUND(sz)
Definition: internal.h:711
#define malloc
Definition: debug_ros.c:4

Referenced by adns__alloc_interim(), and adns__alloc_mine().

◆ cancel_children()

static void cancel_children ( adns_query  qu)
static

Definition at line 401 of file query.c.

401  {
402  adns_query cqu, ncqu;
403 
404  for (cqu= qu->children.head; cqu; cqu= ncqu) {
405  ncqu= cqu->siblings.next;
406  adns_cancel(cqu);
407  }
408 }
struct adns__query::@3961 children
void adns_cancel(adns_query qu)
Definition: query.c:430
struct adns__query::@3962 siblings

Referenced by adns__query_done(), adns__reset_preserved(), and free_query_allocs().

◆ free_query_allocs()

static void free_query_allocs ( adns_query  qu)
static

Definition at line 418 of file query.c.

418  {
419  allocnode *an, *ann;
420 
421  cancel_children(qu);
422  for (an= qu->allocations.head; an; an= ann) { ann= an->next; free(an); }
423  LIST_INIT(qu->allocations);
424  adns__vbuf_free(&qu->vb);
426  free(qu->query_dgram);
427  qu->query_dgram= 0;
428 }
void adns__vbuf_free(vbuf *vb)
Definition: general.c:155
struct adns__query::@3963 allocations
#define free
Definition: debug_ros.c:5
vbuf search_vb
Definition: internal.h:216
#define LIST_INIT(head)
Definition: queue.h:197
struct allocnode * next
Definition: internal.h:160
byte * query_dgram
Definition: internal.h:192
static void cancel_children(adns_query qu)
Definition: query.c:401

Referenced by adns__query_done(), adns_cancel(), and makefinal_query().

◆ makefinal_query()

static void makefinal_query ( adns_query  qu)
static

Definition at line 467 of file query.c.

467  {
468  adns_answer *ans;
469  int rrn;
470 
471  ans= qu->answer;
472 
473  if (qu->interim_allocd) {
474  ans= realloc(qu->answer, MEM_ROUND(MEM_ROUND(sizeof(*ans)) + qu->interim_allocd));
475  if (!ans) goto x_nomem;
476  qu->answer= ans;
477  }
478 
479  qu->final_allocspace= (byte*)ans + MEM_ROUND(sizeof(*ans));
480  adns__makefinal_str(qu,&ans->cname);
481  adns__makefinal_str(qu,&ans->owner);
482 
483  if (ans->nrrs) {
484  adns__makefinal_block(qu, &ans->rrs.untyped, (size_t) ans->nrrs*ans->rrsz);
485 
486  for (rrn=0; rrn<ans->nrrs; rrn++)
487  qu->typei->makefinal(qu, ans->rrs.bytes + rrn*ans->rrsz);
488  }
489 
490  free_query_allocs(qu);
491  return;
492 
493  x_nomem:
494  qu->preserved_allocd= 0;
495  qu->answer->cname= 0;
496  qu->answer->owner= 0;
497  adns__reset_preserved(qu); /* (but we just threw away the preserved stuff) */
498 
500  free_query_allocs(qu);
501 }
#define realloc
Definition: debug_ros.c:6
int preserved_allocd
Definition: internal.h:188
unsigned char * bytes
Definition: adns.h:319
const typeinfo * typei
Definition: internal.h:191
int rrsz
Definition: adns.h:316
void * final_allocspace
Definition: internal.h:189
void adns__makefinal_block(adns_query qu, void **blpp, size_t sz)
Definition: query.c:565
void adns__makefinal_str(adns_query qu, char **strp)
Definition: query.c:553
void(* makefinal)(adns_query qu, void *data)
Definition: internal.h:130
#define MEM_ROUND(sz)
Definition: internal.h:711
adns_answer * answer
Definition: internal.h:201
void * untyped
Definition: adns.h:318
adns_status status
Definition: adns.h:311
void adns__reset_preserved(adns_query qu)
Definition: query.c:410
char * cname
Definition: adns.h:312
union adns_answer::@3958 rrs
int nrrs
Definition: adns.h:316
char * owner
Definition: adns.h:313
static void free_query_allocs(adns_query qu)
Definition: query.c:418
int interim_allocd
Definition: internal.h:188

Referenced by adns__query_done().

◆ query_alloc()

static adns_query query_alloc ( adns_state  ads,
const typeinfo typei,
adns_queryflags  flags,
struct timeval  now 
)
static

Definition at line 41 of file query.c.

42  {
43  /* Allocate a virgin query and return it. */
44  adns_query qu;
45 
46  qu= malloc(sizeof(*qu)); if (!qu) return 0;
47  qu->answer= malloc(sizeof(*qu->answer)); if (!qu->answer) { free(qu); return 0; }
48 
49  qu->ads= ads;
50  qu->state= query_tosend;
51  qu->back= qu->next= qu->parent= 0;
52  LIST_INIT(qu->children);
53  LINK_INIT(qu->siblings);
55  qu->interim_allocd= 0;
56  qu->preserved_allocd= 0;
57  qu->final_allocspace= 0;
58 
59  qu->typei= typei;
60  qu->query_dgram= 0;
61  qu->query_dglen= 0;
62  adns__vbuf_init(&qu->vb);
63 
64  qu->cname_dgram= 0;
65  qu->cname_dglen= qu->cname_begin= 0;
66 
68  qu->search_origlen= qu->search_pos= qu->search_doneabs= 0;
69 
70  qu->id= -2; /* will be overwritten with real id before we leave adns */
71  qu->flags= flags;
72  qu->retries= 0;
73  qu->udpnextserver= 0;
74  qu->udpsent= 0;
75  timerclear(&qu->timeout);
76  qu->expires= now.tv_sec + MAXTTLBELIEVE;
77 
78  memset(&qu->ctx,0,sizeof(qu->ctx));
79 
80  qu->answer->status= adns_s_ok;
81  qu->answer->cname= qu->answer->owner= 0;
82  qu->answer->type= typei->type;
83  qu->answer->expires= -1;
84  qu->answer->nrrs= 0;
85  qu->answer->rrs.untyped= 0;
86  qu->answer->rrsz= typei->rrsz;
87 
88  return qu;
89 }
int preserved_allocd
Definition: internal.h:188
time_t expires
Definition: internal.h:231
struct adns__query::@3961 children
adns_state ads
Definition: adh-query.c:35
adns_rrtype type
Definition: adns.h:314
void adns__vbuf_init(vbuf *vb)
Definition: general.c:112
struct adns__query::@3963 allocations
#define free
Definition: debug_ros.c:5
int cname_begin
Definition: internal.h:213
int udpnextserver
Definition: internal.h:228
int retries
Definition: internal.h:227
const typeinfo * typei
Definition: internal.h:191
int cname_dglen
Definition: internal.h:213
int rrsz
Definition: adns.h:316
time_t now
Definition: finger.c:65
unsigned long udpsent
Definition: internal.h:229
struct timeval timeout
Definition: internal.h:230
int search_origlen
Definition: internal.h:217
adns_query back
Definition: internal.h:184
void * final_allocspace
Definition: internal.h:189
byte * cname_dgram
Definition: internal.h:212
#define LINK_INIT(link)
Definition: dlist.h:32
adns_state ads
Definition: internal.h:182
vbuf search_vb
Definition: internal.h:216
struct adns__query::@3962 siblings
adns_query next
Definition: internal.h:184
qcontext ctx
Definition: internal.h:233
#define LIST_INIT(head)
Definition: queue.h:197
adns_answer * answer
Definition: internal.h:201
void * untyped
Definition: adns.h:318
time_t expires
Definition: adns.h:315
#define MAXTTLBELIEVE
Definition: internal.h:70
GLbitfield flags
Definition: glext.h:7161
byte * query_dgram
Definition: internal.h:192
adns_status status
Definition: adns.h:311
int query_dglen
Definition: internal.h:193
int search_pos
Definition: internal.h:217
char * cname
Definition: adns.h:312
union adns_answer::@3958 rrs
int nrrs
Definition: adns.h:316
int search_doneabs
Definition: internal.h:217
adns_rrtype type
Definition: internal.h:125
int rrsz
Definition: internal.h:128
#define malloc
Definition: debug_ros.c:4
char * owner
Definition: adns.h:313
enum adns__query::@3960 state
#define memset(x, y, z)
Definition: compat.h:39
#define timerclear(tvp)
Definition: rdesktop.h:190
adns_query parent
Definition: internal.h:184
int interim_allocd
Definition: internal.h:188

Referenced by adns__internal_submit(), and adns_submit().

◆ query_simple()

static void query_simple ( adns_state  ads,
adns_query  qu,
const char owner,
int  ol,
const typeinfo typei,
adns_queryflags  flags,
struct timeval  now 
)
static

Definition at line 127 of file query.c.

130  {
131  vbuf vb_new;
132  int id;
134 
135  stat= adns__mkquery(ads,&qu->vb,&id, owner,ol, typei,flags);
136  if (stat) {
139  return;
140  } else {
142  return;
143  }
144  }
145 
146  vb_new= qu->vb;
147  adns__vbuf_init(&qu->vb);
148  query_submit(ads,qu, typei,&vb_new,id, flags,now);
149 }
adns_state ads
Definition: adh-query.c:35
void adns__vbuf_init(vbuf *vb)
Definition: general.c:112
adns_status
Definition: adns.h:215
time_t now
Definition: finger.c:65
adns_status adns__mkquery(adns_state ads, vbuf *vb, int *id_r, const char *owner, int ol, const typeinfo *typei, adns_queryflags flags)
Definition: transmit.c:81
GLbitfield flags
Definition: glext.h:7161
Definition: stat.h:55
Definition: internal.h:110
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
void adns__query_fail(adns_query qu, adns_status stat)
Definition: query.c:547
GLenum GLuint id
Definition: glext.h:5579
void adns__search_next(adns_state ads, adns_query qu, struct timeval now)
Definition: query.c:151
static void query_submit(adns_state ads, adns_query qu, const typeinfo *typei, vbuf *qumsg_vb, int id, adns_queryflags flags, struct timeval now)
Definition: query.c:91

Referenced by adns__search_next(), and adns_submit().

◆ query_submit()

static void query_submit ( adns_state  ads,
adns_query  qu,
const typeinfo typei,
vbuf qumsg_vb,
int  id,
adns_queryflags  flags,
struct timeval  now 
)
static

Definition at line 91 of file query.c.

93  {
94  /* Fills in the query message in for a previously-allocated query,
95  * and submits it. Cannot fail. Takes over the memory for qumsg_vb.
96  */
97 
98  qu->vb= *qumsg_vb;
99  adns__vbuf_init(qumsg_vb);
100 
101  qu->query_dgram= malloc( (size_t) qu->vb.used);
102  if (!qu->query_dgram) { adns__query_fail(qu,adns_s_nomemory); return; }
103 
104  qu->id= id;
105  qu->query_dglen= qu->vb.used;
106  memcpy(qu->query_dgram,qu->vb.buf,(size_t) qu->vb.used);
107 
108  adns__query_send(qu,now);
109 }
void adns__vbuf_init(vbuf *vb)
Definition: general.c:112
time_t now
Definition: finger.c:65
byte * query_dgram
Definition: internal.h:192
int query_dglen
Definition: internal.h:193
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
byte * buf
Definition: internal.h:112
int used
Definition: internal.h:111
void adns__query_fail(adns_query qu, adns_status stat)
Definition: query.c:547
void adns__query_send(adns_query qu, struct timeval now)
Definition: transmit.c:232
GLenum GLuint id
Definition: glext.h:5579
#define malloc
Definition: debug_ros.c:4

Referenced by adns__internal_submit(), and query_simple().

◆ save_owner()

static int save_owner ( adns_query  qu,
const char owner,
int  ol 
)
static

Definition at line 190 of file query.c.

190  {
191  /* Returns 1 if OK, otherwise there was no memory. */
192  adns_answer *ans;
193 
194  ans= qu->answer;
195  assert(!ans->owner);
196 
197  ans->owner= adns__alloc_preserved(qu, (size_t) ol+1); if (!ans->owner) return 0;
198 
199  memcpy(ans->owner,owner, (size_t) ol);
200  ans->owner[ol]= 0;
201  return 1;
202 }
#define assert(x)
Definition: debug.h:53
void * adns__alloc_preserved(adns_query qu, size_t sz)
Definition: query.c:352
adns_answer * answer
Definition: internal.h:201
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
char * owner
Definition: adns.h:313

Referenced by adns__query_done(), and adns_submit().