Beispiel #1
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);
}
Beispiel #2
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);
}