chiark / gitweb /
Add adns support in background resolver.
authormdw <mdw>
Sat, 13 Dec 2003 20:37:59 +0000 (20:37 +0000)
committermdw <mdw>
Sat, 13 Dec 2003 20:37:59 +0000 (20:37 +0000)
16 files changed:
.cvsignore
.links
Makefile.am
bres-adns.c [new file with mode: 0644]
bres.h
configure.in
debian/.cvsignore
debian/changelog
debian/control
debian/copyright
debian/mlib2-adns.copyright [new file with mode: 0644]
debian/rules
macros.h [new file with mode: 0644]
man/Makefile.am
man/bres.3
man/macros.3 [new file with mode: 0644]

index 25ce188098a98449e2295d5a0df02bdb359ac6e9..855d50cf034758d4acc5dfbe11c57ae64be129aa 100644 (file)
@@ -3,3 +3,4 @@ aclocal.m4
 build
 configure
 deb-build
+deb-noadns
diff --git a/.links b/.links
index f2a69071b4063f8d8be35d1a51afe33eacf3b5d5..3a05ceabc5354cadb61154f86f7dbc3bf6858678 100644 (file)
--- a/.links
+++ b/.links
@@ -6,3 +6,4 @@ mdwopt.c
 mdwopt.h
 missing
 mkinstalldirs
+COPYING
index c583808c8660c56278b4cf410249eab6c6f496b8..8e0c51d776a7fb4edb80fe79909fc2def35873a0 100644 (file)
@@ -1,6 +1,6 @@
 ## -*-Makefile-*-
 ##
-## $Id: Makefile.am,v 1.41 2003/11/29 11:59:17 mdw Exp $
+## $Id: Makefile.am,v 1.42 2003/12/13 20:37:59 mdw Exp $
 ##
 ## Building the distribution
 ##
@@ -29,6 +29,9 @@
 ##----- Revision history ----------------------------------------------------
 ##
 ## $Log: Makefile.am,v $
+## Revision 1.42  2003/12/13 20:37:59  mdw
+## Add adns support in background resolver.
+##
 ## Revision 1.41  2003/11/29 11:59:17  mdw
 ## Various stuff.
 ##
@@ -145,10 +148,11 @@ bin_PROGRAMS = crc-mktab
 
 lib_LTLIBRARIES = libmLib.la
 pkglibexecdir = $(libexecdir)/$(PACKAGE)
-pkglibexec_PROGRAMS = bres
+pkglibexec_PROGRAMS = @BRES_LIBEXEC@
+EXTRA_PROGRAMS = bres
 
 pkginclude_HEADERS = \
-       align.h alloc.h arena.h bits.h exc.h quis.h report.h sub.h \
+       align.h alloc.h arena.h bits.h exc.h macros.h quis.h report.h sub.h \
        trace.h track.h unihash.h \
        pool.h \
        atom.h assoc.h darray.h dstr.h dspool.h hash.h sym.h crc32.h \
@@ -159,7 +163,7 @@ pkginclude_HEADERS = \
 
 ## --- Things to put in the library ---
 
-libmLib_la_LDFLAGS = -version-info 2:2:0
+libmLib_la_LDFLAGS = -version-info 2:3:0
 ## Middle number is the patchlevel.  Final number is the minor version.  The
 ## difference between the first and last numbers is major version.
 
@@ -170,9 +174,12 @@ libmLib_la_SOURCES = \
        atom.c assoc.c darray.c dstr.c dputf.c dspool.c hash.c sym.c \
        crc32.c crc32-tab.c \
        env.c fdflags.c fdpass.c fwatch.c lock.c \
-       bres.c conn.c lbuf.c ident.c pkbuf.c sel.c selbuf.c selpk.c sig.c \
+       @BRES_SOURCE@.c \
+       conn.c lbuf.c ident.c pkbuf.c sel.c selbuf.c selpk.c sig.c \
        tv.c \
        base64.c hex.c mdwopt.c str.c testrig.c url.c
+EXTRA_libmLib_la_SOURCES = bres.c bres-adns.c
+libmLib_la_LIBADD = @DEPLIBS@
 
 BUILT_SOURCES = crc32-tab.c
 
@@ -274,7 +281,7 @@ TEST_DIST = \
 ## I must (a) build the standalone version, and (b) inform the client library
 ## where the standalone version is.
 
-bres: bres-stnd.o
+bres$(EXEEXT): bres-stnd.o
        $(LINK) -o bres bres-stnd.o $(LIBS)
 
 bres-stnd.o: $(srcdir)/bres.c
diff --git a/bres-adns.c b/bres-adns.c
new file mode 100644 (file)
index 0000000..54e6708
--- /dev/null
@@ -0,0 +1,339 @@
+/* -*-c-*-
+ *
+ * $Id: bres-adns.c,v 1.1 2003/12/13 20:37:59 mdw Exp $
+ *
+ * Background reverse name resolution (ADNS version)
+ *
+ * (c) 2003 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of the mLib utilities library.
+ *
+ * mLib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ * 
+ * mLib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Library General Public
+ * License along with mLib; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ *
+ *
+ * HOWEVER, since GNU adns is covered by the full GNU General Public
+ * License, this file (only) is also covered by the full GNU GPL, and
+ * you may NOT take advantage of the more liberal conditions of the
+ * LGPL when modifying or redistributing this file.  This doesn't mean
+ * that a program which uses the interface provided by this file is
+ * covered by the GPL, since @bres.c@ provides the same interface and
+ * is LGPL.  However, it does mean that if your program depends, for
+ * some reason (e.g., to meet particular performance criteria), on
+ * this adns-based implementation of mLib's background resolver then it
+ * must be licensed under the full GPL.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: bres-adns.c,v $
+ * Revision 1.1  2003/12/13 20:37:59  mdw
+ * Add adns support in background resolver.
+ *
+ */
+
+#ifndef HAVE_ADNS
+#  error "You need the ADNS library to compile this file."
+#endif
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <assert.h>
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
+#include <adns.h>
+
+#include "alloc.h"
+#include "bres.h"
+#include "macros.h"
+#include "report.h"
+#include "sel.h"
+
+/*----- Static variables --------------------------------------------------*/
+
+static adns_state ads;
+static sel_state *sel;
+static sel_hook selhook;
+
+/*----- Main code ---------------------------------------------------------*/
+
+/* --- @bres_abort@ --- *
+ *
+ * Arguments:  @bres_client *rc@ = pointer to client block
+ *
+ * Returns:    ---
+ *
+ * Use:                Removes a queued job.
+ */
+
+void bres_abort(bres_client *rc)
+{
+  if (rc->q == adns_r_addr) xfree(rc->u.name);
+  if (rc->a) free(rc->a);
+  adns_cancel(rc->aq);
+}
+
+/* --- @bres_byaddr@ --- *
+ *
+ * Arguments:  @bres_client *rc@ = pointer to client block
+ *             @struct in_addr addr@ = address to resolve
+ *             @void (*func)(struct hostent *h, void *p)@ = handler function
+ *             @void *p@ = argument for handler function
+ *
+ * Returns:    ---
+ *
+ * Use:                Adds an address lookup job to the queue.  The job will be
+ *             processed when there's a spare resolver process to deal with
+ *             it.
+ */
+
+void bres_byaddr(bres_client *rc, struct in_addr addr,
+                void (*func)(struct hostent */*h*/, void */*p*/),
+                void *p)
+{
+  int e;
+  struct sockaddr_in sin;
+
+  if (!ads) goto fail;
+  sin.sin_family = AF_INET;
+  sin.sin_addr = addr;
+  sin.sin_port = 0;
+  if ((e = adns_submit_reverse(ads, (struct sockaddr *)&sin, adns_r_ptr,
+                              0, rc, &rc->aq)) != 0)
+    goto fail;
+  rc->a = 0;
+  rc->q = adns_r_ptr;
+  rc->u.addr = addr;
+  rc->func = func;
+  rc->p = p;
+  return;
+
+fail:
+  func(0, p);
+}
+
+/* --- @bres_byname@ --- *
+ *
+ * Arguments:  @bres_client *rc@ = pointer to client block
+ *             @const char *name@ = name to resolve
+ *             @void (*func)(struct hostent *h, void *p)@ = handler function
+ *             @void *p@ = argument for handler function
+ *
+ * Returns:    ---
+ *
+ * Use:                Adds a name lookup job to the queue.  The job will be
+ *             processed when there's a spare resolver process to deal with
+ *             it.
+ */
+
+void bres_byname(bres_client *rc, const char *name,
+                void (*func)(struct hostent */*h*/, void */*p*/),
+                void *p)
+{
+  int e;
+
+  if (!ads) goto fail;
+  if ((e = adns_submit(ads, name, adns_r_addr,
+                      adns_qf_search, rc, &rc->aq)) != 0)
+    goto fail;
+  rc->a = 0;
+  rc->q = adns_r_addr;
+  rc->u.name = xstrdup(name);
+  rc->func = func;
+  rc->p = p;
+  return;
+
+fail:
+  func(0, p);
+}
+
+/* --- @bres_exec@ --- *
+ *
+ * Arguments:  @const char *file@ = file containing server code or null
+ *
+ * Returns:    ---
+ *
+ * Use:                Makes `bres' use a standalone server rather than copies of
+ *             the current process.  This can reduce memory consumption for
+ *             large processes, at the expense of startup time (which
+ *             shouldn't be too bad anyway, because of the resolver design).
+ *             If the filename is null, a default set up at install time is
+ *             used.  It's probably a good idea to leave it alone.
+ */
+
+void bres_exec(const char *file)
+{
+  /* Nothin' doin' */
+}
+
+/* --- @report@ --- *
+ *
+ * Arguments:  @bres_client *c@ = client descriptor block
+ *             @adns_answer *a@ = A-record answer from resolver library
+ *             @adns_rr_addr *av@ = vector of address records
+ *             @int an@ = number of address records (must be positive)
+ *             @char **nv@ = vector of name strings
+ *             @int nn@ = number of name strings (must be positive)
+ *
+ * Returns:    ---
+ *
+ * Use:                Formats the given answer into a @struct hostent@ and reports
+ *             it to the waiting client application.
+ */
+
+static void report(bres_client *rc, adns_answer *a,
+                  adns_rr_addr *av, int an,
+                  char **nv, int nn)
+{
+  struct hostent h;
+  char *n[16];
+  char *aa[16];
+  int i, j;
+
+  j = 0;
+  if (a->cname) n[j++] = a->cname;
+  else { n[j++] = *nv; nv++; nn--; }
+  for (i = 0; i < nn && j < N(n) - 1; i++)
+    if (strcmp(n[0], nv[i]) != 0) n[j++] = nv[i];
+  n[j++] = 0;
+  for (i = j = 0; i < an && j < N(av) - 1; i++) {
+    if (av[i].addr.sa.sa_family == AF_INET)
+      aa[j++] = (char *)&av[i].addr.inet.sin_addr;
+  }
+  aa[j++] = 0;
+  h.h_name = n[0];
+  h.h_aliases = n + 1;
+  h.h_addrtype = AF_INET;
+  h.h_length = sizeof(struct in_addr);
+  h.h_addr_list = aa;
+  rc->func(&h, rc->p);  
+}
+
+/* --- @beforehook@, @afterhook@ --- *
+ *
+ * Arguments:  @sel_state *s@ = select state
+ *             @sel_args *sa@ = argument block
+ *             @void *p@ = uninteresting pointer
+ *
+ * Returns:    ---
+ *
+ * Use:                Processes the selector's arguments before @select@ is
+ *             called, to allow ADNS to do its thing.
+ */
+
+static void beforehook(sel_state *s, sel_args *sa, void *p)
+{
+  adns_beforeselect(ads, &sa->maxfd,
+                   &sa->fd[SEL_READ], &sa->fd[SEL_WRITE], &sa->fd[SEL_EXC],
+                   &sa->tvp, &sa->tv, &sa->now);
+}
+
+static void afterhook(sel_state *s, sel_args *sa, void *p)
+{
+  void *c;
+  bres_client *rc;
+  adns_query q;
+  adns_answer *a;
+  int e;
+  int i;
+
+  adns_afterselect(ads, sa->maxfd,
+                  &sa->fd[SEL_READ], &sa->fd[SEL_WRITE], &sa->fd[SEL_EXC],
+                  &sa->now);
+  while (q = 0, (e = adns_check(ads, &q, &a, &c)) == 0) {
+    rc = c;
+    if (a->status != 0)
+      goto fail;
+    else switch (rc->q) {
+      case adns_r_addr:
+       assert(a->type == adns_r_addr);
+       report(rc, a, a->rrs.addr, a->nrrs, &rc->u.name, 1);
+       free(rc->u.name);
+       free(a);
+       break;
+      case adns_r_ptr:
+       if (a->type == adns_r_ptr) {
+         rc->a = a;
+         if ((e = adns_submit(ads, a->rrs.str[0], adns_r_addr,
+                              0, rc, &q)) != 0)
+           goto fail;
+         rc->aq = q;
+       } else {
+         assert(a->type == adns_r_addr);
+         for (i = 0; i < a->nrrs; i++) {
+           if (a->rrs.addr[i].addr.sa.sa_family == AF_INET &&
+               a->rrs.addr[i].addr.inet.sin_addr.s_addr ==
+                 rc->u.addr.s_addr)
+             goto match;
+         }
+         goto fail;
+       match:
+         report(rc, a, &a->rrs.addr[i], 1, rc->a->rrs.str, rc->a->nrrs);
+         free(rc->a);
+         free(a);
+       }
+       break;
+      default:
+       abort();
+    }
+    continue;
+
+  fail:
+    rc->func(0, rc->p);
+    if (rc->q == adns_r_addr) xfree(rc->u.name);
+    if (rc->a) free(rc->a);
+    free(a);
+  }
+}
+
+/* --- @bres_init@ --- *
+ *
+ * Arguments:  @sel_state *s@ = pointer to select multiplexor
+ *
+ * Returns:    ---
+ *
+ * Use:                Initializes the background resolver for use.
+ */
+
+void bres_init(sel_state *s)
+{
+  int e;
+
+  if ((e = adns_init(&ads, 0, 0)) != 0) {
+    moan("adns_init failed: resolver won't work");
+    return;
+  }
+  sel_addhook(s, &selhook, beforehook, afterhook, 0);
+  sel = s;
+}
+
+/*----- That's all, folks -------------------------------------------------*/
diff --git a/bres.h b/bres.h
index 51ed0f2721672baaf948066352580440fa56c099..fa533d0550d182d6fd3ae9643dd667dab5c49822 100644 (file)
--- a/bres.h
+++ b/bres.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: bres.h,v 1.3 1999/12/10 23:42:04 mdw Exp $
+ * $Id: bres.h,v 1.4 2003/12/13 20:37:59 mdw Exp $
  *
  * Background reverse name resolution
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: bres.h,v $
+ * Revision 1.4  2003/12/13 20:37:59  mdw
+ * Add adns support in background resolver.
+ *
  * Revision 1.3  1999/12/10 23:42:04  mdw
  * Change header file guard names.
  *
 #include <arpa/inet.h>
 #include <netdb.h>
 
+#ifdef HAVE_ADNS
+#  include <adns.h>
+#endif
+
 #include "sel.h"
 #include "selbuf.h"
 
 /* --- Client allocated request block --- */
 
 typedef struct bres_client {
+#ifdef HAVE_ADNS
+  adns_query aq;                       /* ADNS query handle */
+  adns_answer *a;                      /* Answer for reverse resolution */
+  struct _unused *_pad1;               /* And a spare slot */
+#else
   struct bres_client *next, *prev;     /* Queue of waiting resolve jobs */
   struct bres_server *rs;              /* Pointer to attached server */
+#endif
   int q;                               /* Query type (name or address) */
   union {
     struct in_addr addr;               /* Address to resolve */
index 53dae3b8914ccda5e53ac152d0414e45175d16a5..eb39a81ece7f0e172e0546b2d5c84beffb65ce1d 100644 (file)
@@ -1,6 +1,6 @@
 dnl -*-m4-*-
 dnl
-dnl $Id: configure.in,v 1.36 2003/11/29 20:38:38 mdw Exp $
+dnl $Id: configure.in,v 1.37 2003/12/13 20:37:59 mdw Exp $
 dnl
 dnl Configuration script for mLib
 dnl
@@ -29,6 +29,9 @@ dnl MA 02111-1307, USA.
 dnl ----- Revision history --------------------------------------------------
 dnl
 dnl $Log: configure.in,v $
+dnl Revision 1.37  2003/12/13 20:37:59  mdw
+dnl Add adns support in background resolver.
+dnl
 dnl Revision 1.36  2003/11/29 20:38:38  mdw
 dnl Debianization fixes.
 dnl
@@ -109,6 +112,27 @@ AC_CHECK_HEADERS(float.h)
 mdw_CHECK_MANYLIBS(socket, socket)
 mdw_CHECK_MANYLIBS(gethostbyname, nsl resolv)
 
+DEPLIBS=$LIBS AC_SUBST(DEPLIBS)
+BRES_LIBEXEC="bres" BRES_SOURCE="bres"
+AC_SUBST(BRES_LIBEXEC) AC_SUBST(BRES_SOURCE)
+AC_ARG_WITH(adns,
+[  --with-adns             use ADNS library for background name resolution],
+[want_adns=$withval], [want_adns=auto])
+if test $want_adns != no; then
+  save_LIBS=$LIBS
+  LIBS=$DEPLIBS
+  mdw_CHECK_MANYLIBS(adns_init, adns, [have_adns=yes], [have_adns=no])
+  DEPLIBS=$LIBS
+  LIBS=$save_LIBS
+  if test $have_adns = yes; then
+    AC_DEFINE(HAVE_ADNS)
+    BRES_LIBEXEC=""
+    BRES_SOURCE="bres-adns"
+  elif test $want_adns = yes; then
+    AC_MSG_ERROR([ADNS library not found, but explicitly requested])
+  fi
+fi
+
 AC_CACHE_CHECK([for msg_control], [mdw_cv_msg_control],
 [AC_TRY_COMPILE(
 [#include <sys/types.h>
index 3243fc7db35b36de0ff9b62ed65f8ab458283db7..7364f5154da68cfdddb47bc89a743e576aca2ec1 100644 (file)
@@ -2,3 +2,4 @@ files mlib-dev tmp substvars *.debhelper
 mlib
 *.substvars
 mlib2
+mlib2-adns
index 80a1bbe66cd3b21f25a39d17feb877015a21288e..d426a5373718ce92e237d0e5850c3a5a3fb6fd84 100644 (file)
@@ -4,7 +4,9 @@ mlib (2.0.3) experimental; urgency=low
 
   * Add file descriptor passing.
 
- -- Mark Wooding <mdw@nsict.org>  Sat, 29 Nov 2003 11:58:00 +0000
+  * Add ADNS-based background resolver.
+
+ -- Mark Wooding <mdw@nsict.org>  Sat, 13 Dec 2003 19:54:22 +0000
 
 mlib (2.0.2) experimental; urgency=low
 
index 0593f08b0dfc7ef54a0a7ffca4555b33a2ea4af0..e6a480f04ff0eea03e7c077053b44001cfecffd0 100644 (file)
@@ -2,17 +2,58 @@ Source: mlib
 Section: libs
 Priority: extra
 Maintainer: Mark Wooding <mdw@nsict.org>
-Build-Depends: debhelper (>= 4.0.2)
+Build-Depends: debhelper (>= 4.0.2), libadns1-dev
 Standards-Version: 3.1.1
 
 Package: mlib2
 Architecture: any
 Depends: ${shlibs:Depends}
+Conflicts: mlib2-adns
 Description: A library of miscellaneous stuff
+ The mLib library provides various handy utilities, including
+   * yet another options parser, like GNU getopt but more so;
+   * a suite for writing event-driven select-based servers;
+   * a simple exception-handling system, based on longjmp;
+   * dynamically resizing strings and arrays;
+   * a resizing hashtable;
+   * base64 and hex encoding and decoding; and
+   * a simple background DNS resolver.
+ This package provides the mLib run-time library.  It uses an
+ implementation of the background resolver forks and calls
+ gethostbyname, so it therefore (a) depends only on the standard
+ C library, and (b) is distributed under the terms of the GNU 
+ LGPL or GPL.
+
+Package: mlib2-adns
+Architecture: any
+Depends: ${shlibs:Depends}
+Conflicts: mlib2
+Description: A library of miscellaneous stuff
+ The mLib library provides various handy utilities, including
+   * yet another options parser, like GNU getopt but more so;
+   * a suite for writing event-driven select-based servers;
+   * a simple exception-handling system, based on longjmp;
+   * dynamically resizing strings and arrays;
+   * a resizing hashtable;
+   * base64 and hex encoding and decoding; and
+   * a simple background DNS resolver.
+ This package provides the mLib run-time library.  It uses an
+ implementation of the background resolver based on the GNU adns
+ resolver, and therefore (a) depends on the libadns1 package, and
+ (b) is distributed under the terms of the full GPL only.
 
 Package: mlib-dev
 Architecture: any
-Depends: mlib2 (= ${Source-Version}), libc6-dev
+Depends: mlib2 (= ${Source-Version}) | mlib2-adns (= ${Source-Version}),
+ libc6-dev
 Description: A library of miscellaneous stuff
+ The mLib library provides various handy utilities, including
+   * yet another options parser, like GNU getopt but more so;
+   * a suite for writing event-driven select-based servers;
+   * a simple exception-handling system, based on longjmp;
+   * dynamically resizing strings and arrays;
+   * a resizing hashtable;
+   * base64 and hex encoding and decoding; and
+   * a simple background DNS resolver.
  This package contains the header files and static libraries needed to
  compile programs which use mLib.
index eff6dd5e042a0140fdbad6466647f861b9349526..38984938639585633acde9b1e758ec21b33c94cb 100644 (file)
@@ -14,3 +14,4 @@ You should have a copy of the GNU Library General Public License in
 /usr/share/common-licenses/LGPL-2; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 USA.
+
diff --git a/debian/mlib2-adns.copyright b/debian/mlib2-adns.copyright
new file mode 100644 (file)
index 0000000..5070c55
--- /dev/null
@@ -0,0 +1,26 @@
+mLib is copyright (c) 2003 Straylight/Edgeware
+
+mLib is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+mLib is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+License for more details.
+
+You should have a copy of the GNU General Public License in
+/usr/share/common-licenses/GPL-2; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+USA.
+
+
+The usual version of mLib is distributed under the terms of the weaker
+GNU Library General Public License, version 2.  However, this version of
+mLib uses the GNU adns library as its background DNS resolver, and is
+therefore subject to the full GPL only.  This doesn't mean that you must
+apply the GPL to your program just because it uses mLib, even if it uses
+the `bres' background resolver interface: you only need to do that if
+you depend on the adns version specifically, e.g., to acheive some
+performance criterion.
index 83ea3610a436deb20cabcf8a458ab53b9ab23af1..1f22ffb55e933648ef0bf5fc667d7d62bd534a10 100755 (executable)
@@ -3,13 +3,21 @@
 export DH_COMPAT = 4
 
 build:
-       rm -rf deb-build build; mkdir deb-build
+       rm -rf deb-build deb-noadns build; mkdir deb-build deb-noadns
        cd deb-build; ../configure \
+               --with-adns \
                --prefix=/usr \
                --mandir=/usr/share/man \
                --libexecdir=/usr/lib
        make -C deb-build
        make -C deb-build check
+       cd deb-noadns; ../configure \
+               --without-adns \
+               --prefix=/usr \
+               --mandir=/usr/share/man \
+               --libexecdir=/usr/lib
+       make -C deb-noadns
+       make -C deb-noadns check
        touch build
 
 clean:
@@ -18,7 +26,7 @@ clean:
 
 install: build
        dh_clean
-       make -C deb-build install DESTDIR=`pwd`/debian/mlib2
+       make -C deb-noadns install DESTDIR=`pwd`/debian/mlib2
        mkdir -p debian/mlib-dev/usr/lib 
        mkdir -p debian/mlib-dev/usr/share/man
        mkdir -p debian/mlib-dev/usr/bin
@@ -28,6 +36,13 @@ install: build
        mv debian/mlib2/usr/lib/*.so debian/mlib-dev/usr/lib
        mv debian/mlib2/usr/lib/*.la debian/mlib-dev/usr/lib
        mv debian/mlib2/usr/include debian/mlib-dev/usr
+       make -C deb-build install DESTDIR=`pwd`/debian/mlib2-adns
+       rm debian/mlib2-adns/usr/bin/mLib-config
+       rm -r debian/mlib2-adns/usr/share/man/man3
+       rm debian/mlib2-adns/usr/lib/*.a
+       rm debian/mlib2-adns/usr/lib/*.so
+       rm debian/mlib2-adns/usr/lib/*.la
+       rm -rf debian/mlib2-adns/usr/include 
        dh_strip -a
 
 binary-indep:
@@ -35,7 +50,7 @@ binary-indep:
 binary-arch: install
        dh_testdir -a
        dh_testroot -a
-       dh_makeshlibs -a -V
+       dh_makeshlibs -a -V"mlib2 (>= 2.0.3) | mlib2-adns (>= 2.0.3)"
        dh_installman -a
        dh_compress -a
        dh_installdocs -a
diff --git a/macros.h b/macros.h
new file mode 100644 (file)
index 0000000..b8ea4df
--- /dev/null
+++ b/macros.h
@@ -0,0 +1,52 @@
+/* -*-c-*-
+ Handy macrosose]]
+ *
+ * (c) 2003 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of the mLib utilities library.
+ *
+ * mLib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ * 
+ * mLib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Library General Public
+ * License along with mLib; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: macros.h,v $
+ * Revision 1.1  2003/12/13 20:37:59  mdw
+ * Add adns support in background resolver.
+ *
+ */
+
+#ifndef MLIB_MACROS_H
+#define MLIB_MACROS_H
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+/*----- Macros provided ---------------------------------------------------*/
+
+#define N(v) (sizeof(v)/sizeof(*v))
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif
index bc023d6c30af15f771a6c8f8c33a4780ad4b42b3..1258469c50aaf51f36e528b05299483f334a643a 100644 (file)
@@ -1,6 +1,6 @@
 ## -*-makefile-*-
 ##
-## $Id: Makefile.am,v 1.5 2003/11/29 11:59:17 mdw Exp $
+## $Id: Makefile.am,v 1.6 2003/12/13 20:37:59 mdw Exp $
 ##
 ## Makefile for mLib's manual pages
 ##
@@ -29,6 +29,9 @@
 ##----- Revision history ----------------------------------------------------
 ##
 ## $Log: Makefile.am,v $
+## Revision 1.6  2003/12/13 20:37:59  mdw
+## Add adns support in background resolver.
+##
 ## Revision 1.5  2003/11/29 11:59:17  mdw
 ## Various stuff.
 ##
@@ -65,7 +68,7 @@ MANPAGESEXT = \
        crc32.3 darray.3 dspool.3 dstr.3 env.3 exc.3 fdflags.3 fwatch.3 \
        hash.3 ident.3 lbuf.3 lock.3 mLib.3 mdwopt.3 pkbuf.3 pool.3 \
        quis.3 report.3 sel.3 selbuf.3 selpk.3 sig.3 str.3 sub.3 sym.3 \
-       testrig.3 trace.3 tv.3 url.3 hex.3 fdpass.3
+       testrig.3 trace.3 tv.3 url.3 hex.3 fdpass.3 macros.3
 
 install-man: $(MANPAGES)
        @$(NORMAL_INSTALL)
index 9552656df42e867814304bc3152249f7a41b2f65..f6f790bedad6215643acf1fc4066e0a1429eee30 100644 (file)
@@ -85,12 +85,14 @@ The function
 cancels a running resolver job.  When it returns, the client structure
 is safe to discard.
 .PP
-The resolver is currently implemented using a pool of server processes.
-Incoming resolver jobs are passed to an available server, or a new
-server is started if all are busy.  There is a maximum number of
-servers, and jobs are queued once this limit is reached.  Old servers
-which have been idle for a period of time are killed off.  Servers are
-also killed if they start misbehaving or their jobs are aborted.
+There are two versions of 
+.BR bres .
+The standard one uses a pool of server processes.  Incoming resolver
+jobs are passed to an available server, or a new server is started if
+all are busy.  There is a maximum number of servers, and jobs are queued
+once this limit is reached.  Old servers which have been idle for a
+period of time are killed off.  Servers are also killed if they start
+misbehaving or their jobs are aborted.
 .PP
 By default, servers are started simply by calling
 .BR fork (2).
@@ -105,6 +107,18 @@ memory consumption.  The argument to
 is the full pathname of the server program, or null to accept the
 default set at library configuration time (which is usually correct).
 .PP
+The other implementation of
+.B bres
+uses the
+.B adns
+library to do asynchronous resolution.  It can cope with many more
+simultaneous resolver jobs, and doesn't use up external processes.  If
+you're using the
+.BR adns -based
+resolver, then the
+.B bres_exec
+function does nothing at all.
+.PP
 For security reasons, when an address is resolved, the hostname received
 is verified by performing a forward lookup.  If the forward lookup fails
 to return the expected IP address, an error is reported.
diff --git a/man/macros.3 b/man/macros.3
new file mode 100644 (file)
index 0000000..93a58cb
--- /dev/null
@@ -0,0 +1,20 @@
+.\" -*-nroff-*-
+.TH macros 3 "13 December 2003" "Straylight/Edgeware" "mLib utilities library"
+.SH NAME
+macros \- useful macros
+.\" @N
+.SH SYNOPSIS
+.nf
+.B "#include <mLib/macros.h>"
+
+.BI "size_t N(" array ");"
+.fi
+.SH DESCRIPTION
+The
+.B N
+macro returns the number of elements in the named
+.IR array .
+.SH "SEE ALSO"
+.BR mLib (3).
+.SH "AUTHOR"
+Mark Wooding, <mdw@nsict.org>