Ejemplo n.º 1
0
static void
adns_rx_callback(int fd __attribute__ ((unused)),void *state){
	int r;

	if( (r = adns_processany(state)) ){
		return; // FIXME stat? what else?
	}else{
		adns_query query = NULL;
		adns_answer *answer;
		void *context;

		while((r = adns_check(state,&query,&answer,&context)) == 0){
			dnsmarshal *ds = context;

			ds->cb(answer,ds->cbstate);
			free_dnsmarshal(ds);
			free(answer);
			query = NULL;
		}
		if(r != EAGAIN){
			// FIXME what?
		}
	}
	restore_dns_fds(state,get_thread_evh());
}
Ejemplo n.º 2
0
int main(int argc, const char *const *argv)
{
    struct timeval *tv, tvbuf;
    adns_query qu;
    void *qun_v;
    adns_answer *answer;
    int r, maxfd;
    fd_set readfds, writefds, exceptfds;
    const char *arg;

    ensure_adns_init();

    while ((arg= *++argv)) process_optarg(arg,&argv,0);

    if (!ov_pipe && !ads) usageerr("no domains given, and -f/--pipe not used; try --help");

    for (;;)
    {
        for (;;)
        {
            qu= ov_asynch ? 0 : outstanding.head ? outstanding.head->qu : 0;
            r= adns_check(ads,&qu,&answer,&qun_v);
            if ((r == EAGAIN) || (r == EWOULDBLOCK)) break;
            if (r == ESRCH)
            {
                if (!ov_pipe) goto x_quit;
                else break;
            }
            assert(!r);
            query_done(qun_v,answer);
        }
        maxfd= 0;
        FD_ZERO(&readfds);
        FD_ZERO(&writefds);
        FD_ZERO(&exceptfds);
        if (ov_pipe)
        {
            maxfd= 1;
            FD_SET(0,&readfds);
        }
        tv= 0;
        adns_beforeselect(ads, &maxfd, &readfds,&writefds,&exceptfds, &tv,&tvbuf,0);
        ADNS_CLEAR_ERRNO;
        r= select(maxfd, &readfds,&writefds,&exceptfds, tv);
        ADNS_CAPTURE_ERRNO;
        if (r == -1)
        {
            if (errno == EINTR) continue;
            sysfail("select",errno);
        }
        adns_afterselect(ads, maxfd, &readfds,&writefds,&exceptfds, 0);
        if (ov_pipe && FD_ISSET(0,&readfds)) read_stdin();
    }
x_quit:
    if (fclose(stdout)) outerr();
    quitnow(rcode);
}
Ejemplo n.º 3
0
static void proclog(FILE *inf, FILE *outf, int maxpending, int opts) {
  int eof, err, len;
  adns_state adns;
  adns_answer *answer;
  logline *head, *tail, *line;
  adns_initflags initflags;

  initflags= (opts & OPT_DEBUG) ? adns_if_debug : 0;
  if (config_text) {
    errno= adns_init_strcfg(&adns, initflags, stderr, config_text);
  } else {
    errno= adns_init(&adns, initflags, 0);
  }
  if (errno) aargh("adns_init");
  head= tail= readline(inf, adns, opts);
  len= 1; eof= 0;
  while (head) {
    while (head) {
      if (opts & OPT_DEBUG)
	msg("%d in queue; checking %.*s", len,
	    (int)(head->rest-head->addr), guard_null(head->addr));
      if (eof || len >= maxpending) {
	if (opts & OPT_POLL)
	  err= adns_wait_poll(adns, &head->query, &answer, NULL);
	else
	  err= adns_wait(adns, &head->query, &answer, NULL);
      } else {
	err= adns_check(adns, &head->query, &answer, NULL);
      }
      if (err == EAGAIN) break;
      if (err) {
	fprintf(stderr, "%s: adns_wait/check: %s", progname, strerror(err));
	exit(1);
      }
      printline(outf, head->start, head->addr, head->rest,
		answer->status == adns_s_ok ? *answer->rrs.str : NULL,
                head->fullip, head->is_v6, opts);
      line= head; head= head->next;
      free(line);
      free(answer);
      len--;
    }
    if (!eof) {
      line= readline(inf, adns, opts);
      if (line) {
        if (!head) head= line;
        else tail->next= line;
        tail= line; len++;
      } else {
	eof= 1;
      }
    }
  }
  adns_finish(adns);
}
Ejemplo n.º 4
0
/* void dns_do_callbacks(void)
 * Input: None.
 * Output: None.
 * Side effects: Call all the callbacks(into the ircd core) for the
 *               results of a DNS resolution.
 */
void
dns_do_callbacks(void)
{
	adns_query q, r;
	adns_answer *answer;
	void *xr = &r;
	struct DNSQuery *query;
	void *xq = &query;
	int failure = 0;
	adns_forallqueries_begin(dns_state);

	while ((q = adns_forallqueries_next(dns_state, xr)) != NULL)
	{
		switch (adns_check(dns_state, &q, &answer, xq))
		{
		case 0:
			/* Looks like we got a winner */
			assert(query->callback != NULL);
			if(query->callback != NULL)
			{
				query->query = NULL;
				query->callback(query->ptr, answer);
			}
			break;

		case EAGAIN:
			/* Go into the queue again */
			continue;

		default:
			assert(query->callback != NULL);
			if(query->callback != NULL)
			{
				/* Awww we failed, what a shame */
				query->query = NULL;
				query->callback(query->ptr, NULL);
			}
			if(answer != NULL && answer->status == adns_s_systemfail)
				failure = 1;
			
			break;
		}
	}
        if(failure == 1)
        {       
	        sendto_realops_flags(UMODE_ALL, L_ALL, "adns got a global system failure..attempting to restart resolver");
                init_resolver();
        }
}
Ejemplo n.º 5
0
static void
do_resolver_after(struct io_special *s)
{
  CAST(resolver, self, s);

  adns_query q = NULL;
  adns_answer *answer;
  void *c;
  adns_afterpoll(self->adns, ...);

  while (!adns_check(self->adns, &q,
		     &answer, &c))
    {
      CAST(resolver_context, ctx, c);
      switch (answer->status)
	{
	}
    }
}
Ejemplo n.º 6
0
/* void dns_do_callbacks(void)
 * Input: None.
 * Output: None.
 * Side effects: Call all the callbacks(into the ircd core) for the
 *               results of a DNS resolution.
 */
void dns_do_callbacks(void)
{
  adns_query q, r;
  adns_answer *answer;
  struct DNSQuery *query;
  
  adns_forallqueries_begin(dns_state);
  
  while((q = adns_forallqueries_next(dns_state, (void **)&r)) != NULL)
  {
    switch(adns_check(dns_state, &q, &answer, (void **)&query))  
    {
      case 0:
        /* Looks like we got a winner */            
        assert(query->callback != NULL);
        if(query->callback != NULL)
        {
          query->query = NULL;
          query->callback(query->ptr, answer);
        }
        break;
	
      case EAGAIN:
        /* Go into the queue again */
        break;
	
      default:
        assert(query->callback != NULL);
        if(query->callback != NULL)
        {
          /* Awww we failed, what a shame */
          query->query = NULL;
          query->callback(query->ptr, NULL);      
        }
        break;
    } 
  }
}
Ejemplo n.º 7
0
static void proclog(FILE *inf, FILE *outf, int maxpending, int opts) {
  int eof, err, len;
  adns_state adns;
  adns_answer *answer;
  logline *head, *tail, *line;
  adns_initflags initflags;

  initflags= (opts & OPT_DEBUG) ? adns_if_debug : 0;
  if (config_text) {
    errno= adns_init_strcfg(&adns, initflags, stderr, config_text);
  } else {
    errno= adns_init(&adns, initflags, 0);
  }
  if (errno) aargh("adns_init");
  head= tail= readline(inf, adns, opts);
  len= 1; eof= 0;
  while (head) {
    while (head) {
      if (head->query) {
	if (opts & OPT_DEBUG)
	  msg("%d in queue; checking %.*s", len,
	      (int)(head->rest-head->name), guard_null(head->name));
	if (eof || len >= maxpending) {
	  if (opts & OPT_POLL)
	    err= adns_wait_poll(adns, &head->query, &answer, NULL);
	  else
	    err= adns_wait(adns, &head->query, &answer, NULL);
	} else {
	  err= adns_check(adns, &head->query, &answer, NULL);
	}
	if (err == EAGAIN) break;
	if (err) {
	  fprintf(stderr, "%s: adns_wait/check: %s", progname, strerror(err));
	  exit(1);
	}
	if (answer->status == adns_s_ok) {
	  const char *addr;
	  int ok = 0;
	  fprintf(outf, "%.*s", (int)(head->rest-head->start), head->start);
	  while(answer->nrrs--) {
	    addr= inet_ntoa(answer->rrs.inaddr[answer->nrrs]);
	    ok |= !strncmp(addr, head->addr, strlen(addr));
	    fprintf(outf, " [%s]", addr);
	  }
	  fprintf(outf, "%s%s", ok ? " OK" : "", head->rest);
	} else {
	  if (opts & OPT_DEBUG)
	    msg("query failed");
	  fputs(head->start, outf);
	}
	free(answer);
	len--;
      } else {
	if (opts & OPT_DEBUG)
	  msg("%d in queue; no query on this line", len);
	fputs(head->start, outf);
      }
      line= head; head= head->next;
      free(line);
    }
    if (!eof) {
      line= readline(inf, adns, opts);
      if (line) {
        if (!head) head= line;
        else tail->next= line;
        tail= line;
	if (line->query) len++;
      } else {
	eof= 1;
      }
    }
  }
  adns_finish(adns);
}