]> jfr.im git - irc/ircd-hybrid/ircd-hybrid-8-cvs.git/commitdiff
- Forward ported some patches from 4/1/2002 to 26/2/2002 applied to -7 but not
authora1kmm <a1kmm>
Sat, 27 Apr 2002 02:48:44 +0000 (02:48 +0000)
committera1kmm <a1kmm>
Sat, 27 Apr 2002 02:48:44 +0000 (02:48 +0000)
  -8.

43 files changed:
Hybrid-team
INSTALL
RELNOTES
adns/check.c
adns/event.c
adns/general.c
adns/parse.c
adns/query.c
adns/reply.c
adns/setup.c
adns/transmit.c
adns/types.c
autoconf/configure.in
doc/example.conf
help/opers/set
include/channel.h
include/hook.h
include/ircd.h
include/ircd_defs.h
include/s_protocol.h
include/supported.h
modules/core/m_nick.c
modules/m_cburst.c
modules/m_kline.c
modules/m_message.c
modules/m_set.c
modules/m_svinfo.c
modules/m_trace.c
src/balloc.c
src/channel.c
src/class.c
src/client.c
src/ircd.c
src/ircd_parser.y
src/listener.c
src/p_ts.c
src/parse.c
src/s_auth.c
src/s_bsd.c
src/s_bsd_sigio.c
src/s_serv.c
src/s_user.c
src/send.c

index a2b35624bc5021f875cd6be1c91a478ec037739b..e75aefa0877904ed5bcb6f6df08e9c1c21353b60 100644 (file)
@@ -1,4 +1,4 @@
-$Id: Hybrid-team,v 1.1 2002/01/04 09:10:22 a1kmm Exp $
+$Id: Hybrid-team,v 1.2 2002/04/27 02:48:44 a1kmm Exp $
 
 The hybrid team is a group of ircd coders who were frustrated
 with the instability and all-out "dirtiness" of the EFnet ircd's
@@ -15,19 +15,17 @@ The core team as, of this major release:
 A1kmm, Andrew Miller <a1kmm@mware.virtualave.net>
 adrian, Adrian Chadd <adrian@creative.net.au>
 AndroSyn, Aaron Sethman <androsyn@ratbox.org>
-billy-jon, Bill Jonus <proggy@earthling.net>
+billy-jon, Bill Jonus <bill@mu.org>
 cosine, Patrick Alken <wnder@uwns.underworld.net>
 David-T, David Taylor <davidt@yadt.co.uk>
 Dianora, Diane Bruce <db@db.net>
 einride, Erik S. Johansen, <einride@einride.org>
 fl_, Lee Hardy <lee@leeh.co.uk>
-Habeeb, David Supuran <habeeb@cfl.rr.com>
 Hwy101, W. Campbell <wcampbel@botbay.net>
-is, Edward Brocklesby <ejb@leguin.org.uk>
+larne, Edward Brocklesby <ejb@sdf.lonestar.org>
 isomer, Perry Lorier <perry@coders.net>
+jmallett, Juli Mallett <jmallett@FreeBSD.org>
 k9, Jeremy Chadwick <yoshi@parodius.com>
-madmax, Paul Lomax <madmax@efnet.org>
-Neph|l|m, Adel Mezibra <adel@cybercable.fr>
 Rodder, Jon Lusky <lusky@blown.net>
 toot, Toby Verrall <to7@antipope.fsnet.co.uk>
 Wohali, Joan Touzet <joant@ieee.org>
@@ -36,18 +34,18 @@ xyst, Greg Prosser <gnp@arrogant.org>
 The following people have contributed blood, sweat, and/or code to
 this release of hybrid, in nick alphabetical order:
  
+adx, Piotr Nizynski <adx@crashnet.pl>
 bysin, Ben Kittridge <bkittridge@cfl.rr.com>
 desrt, Ryan Lortie <desertangel@mindless.com>
+Habeeb, David Supuran <habeeb@cfl.rr.com>
 jv, Jakub Vlasek <jv@pilsedu.cz>
 kre, Dinko Korunic <kreator@fly.srk.fer.hr>
-LarZ, Matthew Ramsey <mjr@blackened.com>
-orabidoo, Roger Espel Llima <espel@unix.bigots.org>
+madmax, Paul Lomax <madmax@efnet.org>
+Neph|l|m, Adel Mezibra <adel@cybercable.fr>
 Riedel, Dennis Vink, <vink@vuurwerk.nl>
-Seaner, Sean McVeigh <sdlmcvei@uwaterloo.ca>
 spookey, David Colburn <spookey@spookey.org>
-vx0, Mark Miller <mark@vx0.net>
-WintrHawk, Jake Khuon <khuon@GCtr.Net>
 vulture, Sean Stanek <vulture@cs.iastate.edu>
+vx0, Mark Miller <mark@vx0.net>
 zb^3, Alfred Perlstein <alfred@freebsd.org>
  
 Others are welcome.  Always.  And if we left anyone off the above list,
diff --git a/INSTALL b/INSTALL
index 04e86713b287d7b442ef56f85fb1e664bb74fab3..9dee200e2b0d598c14513fa7936a73202294ac95 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -1,6 +1,6 @@
                             Hybrid INSTALL Document
 
-   $Id: INSTALL,v 1.1 2002/01/04 09:10:22 a1kmm Exp $
+   $Id: INSTALL,v 1.2 2002/04/27 02:48:44 a1kmm Exp $
 
    Copyright (c) 2001 by ircd-hybrid team
 
@@ -15,6 +15,8 @@
    | - You now need to ./configure --prefix="/path/to/install/it"           |
    |                                                                        |
    |   Important: The old config format WILL NOT WORK. Please see point 6!  |
+   |                                                                        |
+   |   The old kline format WILL NOT WORK. Please see point 7!              |
    +------------------------------------------------------------------------+
 
      ----------------------------------------------------------------------
 
           * 
 
-            --enable-rtsigio - Enable the experimental Linux RealTime Signal
-            I/O system. This code works, but is still considered experimental
-            and therefore not for use on production servers.
-
-              Note: The Hybrid Team would like feedback from people who are
-              willing to test this option.
+            --enable-rtsigio - Enable the superior Linux RealTime Signal I/O
+            system. This is currently only available on 2.4 Linux kernel
+            versions or later.
 
           * 
 
             should be used on all production servers for maximum speed and to
             prevent cores from things that shouldn't normally happen.
 
+          * 
+
+            --enable-small-net - Tunes the server for smaller networks by
+            reducing the startup memory footprint. This should really only be
+            used for *small* networks, as this tends to be a performance hit
+            on larger networks.
+
+          * 
+
+            --with-nicklen - Sets the maximum NICK length. Note that this
+            must be consistant across your entire network.
+
+          * 
+
+            --with-maxclients - Sets the maximum number of clients support by
+            the server. Note that this also twiddles the HARD_FDLIMIT_ define
+            so it is no longer necessary to modify include/config.h for this.
+            If HARD_FDLIMIT_ ends up being larger that FD_SETSIZE when using
+            select() for your I/O loop, s_bsd_select.c will refuse to compile
+            (and tell you to use poll instead). Take this error's advice and
+            use --enable-poll or something a bit more efficient. You'll be
+            happier at the end of the day for it.
+
    3. 
 
        Look over the "include/config.h" file. This allows you to change the
        few remaining hard coded options of how the ircd will operate. Most
-       admins will only have to change a few settings. HARD_FDLIMIT_ and
-       INIT_MAXCLIENTS are two that must be changed to the proper values for
-       your operating system. Note that these two settings must be <=
-       FD_SETSIZE (usually defined in the system includes, but may need to
-       overridden in the Makefile). USE_SYSLOG is the final one that most
-       admins will need to edit.
+       admins will only have to change a few settings. USE_SYSLOG is the only
+       one that most admins will need to edit.
 
          Note: Note that you must have permission by the sysadmin to send
          messages to the system log files.
        If you are upgrading from Hybrid 5 or Hybrid 6, the config file has
        changed drastically...
 
-       There is a utility to convert your old config file, to the new format.
+       There is a utility to convert your old config file to the new format.
        In prefix/bin there is something called "convertconf". Its usage is:
        ./convertconf (old config file to convert) (converted file name)
 
        EDIT IT! There are still things that need changing in the config,
        including the fact that classes MUST be above auth/connect blocks!
 
+   8. 
+
+       If you are upgrading from Hybrid 5 or Hybrid 6, the kline file has
+       also changed...
+
+       There is a utility to convert the old kline configuration file to the
+       new format. In prefix/bin there is a program called "convertklines".
+       Its usage is: ./convertklines (old kline.conf filename) (new
+       kline.conf filename) (dline.conf filename).
+
+       Once this is done, move the new files into the prefix/etc/ directory
+       under their proper names. By default, the kline file is named
+       kline.conf and the dline file is named dline.conf.
+
      ----------------------------------------------------------------------
 
                                 HOW TO GET HELP
    4. 
 
        Save the output of the backtrace command and send it to
-       listmanager@the-project.org.
+       ircd-hybrid@the-project.org.
 
    5. 
 
index 76843af3b50c25f06535a1bb8060647bab30efaf..83f74637850d94eeed941ff66c8ba6a8a0136ca0 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -1,7 +1,7 @@
- ircd-hybrid-7b8 Release Notes
+ ircd-hybrid-8a1 Release Notes
 --------------------------------------------------------------------------------
 
-This is the current beta version of ircd-hybrid-7.
+This is the current beta version of ircd-hybrid-8.
 
 NOTE: This is still BETA code.  Run it at your own risk.  By running this
  code you assume FULL responsibility for any problems it may cause.  We do
@@ -38,4 +38,4 @@ Other files recommended for reading: BUGS, README.FIRST, INSTALL
   *************************************************************************
 
 --------------------------------------------------------------------------------
-$Id: RELNOTES,v 1.1 2002/01/04 09:10:22 a1kmm Exp $
+$Id: RELNOTES,v 1.2 2002/04/27 02:48:44 a1kmm Exp $
index ceccf29842989677134e7e820c4f788c934e6d77..cebd633245ead886c6eacfc44b2a1e13a1427049 100644 (file)
@@ -24,7 +24,7 @@
  *  along with this program; if not, write to the Free Software Foundation,
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  *
- * $Id: check.c,v 1.1 2002/01/04 09:10:43 a1kmm Exp $
+ * $Id: check.c,v 1.2 2002/04/27 02:48:46 a1kmm Exp $
  */
 
 #include "fileio.h"
  * up.
  */
 #define unused_arg /**/
-
-void adns_checkconsistency(adns_state ads, adns_query qu) {
-  adns__consistency(ads,qu,cc_user);
+  void
+adns_checkconsistency(adns_state ads, adns_query qu)
+{
+  adns__consistency(ads, qu, cc_user);
 }
 
 #define DLIST_CHECK(list, nodevar, part, body)                                 \
@@ -60,125 +61,158 @@ void adns_checkconsistency(adns_state ads, adns_query qu) {
     }                                                                          \
   } while(0)
 
-static void checkc_query_alloc(adns_state ads, adns_query qu) {
+static void
+checkc_query_alloc(adns_state ads, adns_query qu)
+{
   allocnode *an;
 
-  DLIST_CHECK(qu->allocations, an, , {
-  });
+  DLIST_CHECK(qu->allocations, an,,
+              {
+              }
+  );
 }
 
-static void checkc_query(adns_state ads, adns_query qu) {
+static void
+checkc_query(adns_state ads, adns_query qu)
+{
   adns_query child;
 
   assert(qu->udpnextserver < ads->nservers);
   assert(!(qu->udpsent & (~0UL << ads->nservers)));
   assert(qu->search_pos <= ads->nsearchlist);
-  if (qu->parent) DLIST_ASSERTON(qu, child, qu->parent->children, siblings.);
+  if (qu->parent)
+    DLIST_ASSERTON(qu, child, qu->parent->children, siblings.);
 }
 
-static void checkc_notcpbuf(adns_state ads) {
+static void
+checkc_notcpbuf(adns_state ads)
+{
   assert(!ads->tcpsend.used);
   assert(!ads->tcprecv.used);
   assert(!ads->tcprecv_skip);
 }
 
-static void checkc_global(adns_state ads) {
+static void
+checkc_global(adns_state ads)
+{
   int i;
-  
+
   assert(ads->udpsocket >= 0);
 
-  for (i=0; i<ads->nsortlist; i++)
+  for (i = 0; i < ads->nsortlist; i++)
     assert(!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr));
 
   assert(ads->tcpserver >= 0 && ads->tcpserver < ads->nservers);
-  
-  switch (ads->tcpstate) {
-  case server_connecting:
-    assert(ads->tcpsocket >= 0);
-    checkc_notcpbuf(ads);
-    break;
-  case server_disconnected:
-  case server_broken:
-    assert(ads->tcpsocket == -1);
-    checkc_notcpbuf(ads);
-    break;
-  case server_ok:
-    assert(ads->tcpsocket >= 0);
-    assert(ads->tcprecv_skip <= ads->tcprecv.used);
-    break;
-  default:
-    assert(!"ads->tcpstate value");
+
+  switch (ads->tcpstate)
+  {
+    case server_connecting:
+      assert(ads->tcpsocket >= 0);
+      checkc_notcpbuf(ads);
+      break;
+    case server_disconnected:
+    case server_broken:
+      assert(ads->tcpsocket == -1);
+      checkc_notcpbuf(ads);
+      break;
+    case server_ok:
+      assert(ads->tcpsocket >= 0);
+      assert(ads->tcprecv_skip <= ads->tcprecv.used);
+      break;
+    default:
+      assert(!"ads->tcpstate value");
   }
 
   assert(ads->searchlist || !ads->nsearchlist);
 }
 
-static void checkc_queue_udpw(adns_state ads) {
+static void
+checkc_queue_udpw(adns_state ads)
+{
   adns_query qu;
-  
-  DLIST_CHECK(ads->udpw, qu, , {
-    assert(qu->state==query_tosend);
-    assert(qu->retries <= UDPMAXRETRIES);
-    assert(qu->udpsent);
-    assert(!qu->children.head && !qu->children.tail);
-    checkc_query(ads,qu);
-    checkc_query_alloc(ads,qu);
-  });
+
+  DLIST_CHECK(ads->udpw, qu,,
+              {
+              assert(qu->state == query_tosend);
+              assert(qu->retries <= UDPMAXRETRIES);
+              assert(qu->udpsent);
+              assert(!qu->children.head && !qu->children.tail);
+              checkc_query(ads, qu);
+              checkc_query_alloc(ads, qu);
+              }
+  );
 }
 
-static void checkc_queue_tcpw(adns_state ads) {
+static void
+checkc_queue_tcpw(adns_state ads)
+{
   adns_query qu;
-  
-  DLIST_CHECK(ads->tcpw, qu, , {
-    assert(qu->state==query_tcpw);
-    assert(!qu->children.head && !qu->children.tail);
-    assert(qu->retries <= ads->nservers+1);
-    checkc_query(ads,qu);
-    checkc_query_alloc(ads,qu);
-  });
+
+  DLIST_CHECK(ads->tcpw, qu,,
+              {
+              assert(qu->state == query_tcpw);
+              assert(!qu->children.head && !qu->children.tail);
+              assert(qu->retries <= ads->nservers + 1); checkc_query(ads, qu);
+              checkc_query_alloc(ads, qu);
+              }
+  );
 }
 
-static void checkc_queue_childw(adns_state ads) {
+static void
+checkc_queue_childw(adns_state ads)
+{
   adns_query parent, child;
 
-  DLIST_CHECK(ads->childw, parent, , {
-    assert(parent->state == query_childw);
-    assert(parent->children.head);
-    DLIST_CHECK(parent->children, child, siblings., {
-      assert(child->parent == parent);
-      assert(child->state != query_done);
-    });
-    checkc_query(ads,parent);
-    checkc_query_alloc(ads,parent);
-  });
+  DLIST_CHECK(ads->childw, parent,,
+              {
+              assert(parent->state == query_childw);
+              assert(parent->children.head);
+              DLIST_CHECK(parent->children, child, siblings.,
+                          {
+                          assert(child->parent == parent);
+                          assert(child->state != query_done);
+                          }
+              ); checkc_query(ads, parent);
+              checkc_query_alloc(ads, parent);
+              }
+  );
 }
 
-static void checkc_queue_output(adns_state ads) {
+static void
+checkc_queue_output(adns_state ads)
+{
   adns_query qu;
-  
-  DLIST_CHECK(ads->output, qu, , {
-    assert(qu->state == query_done);
-    assert(!qu->children.head && !qu->children.tail);
-    assert(!qu->parent);
-    assert(!qu->allocations.head && !qu->allocations.tail);
-    checkc_query(ads,qu);
-  });
+
+  DLIST_CHECK(ads->output, qu,,
+              {
+              assert(qu->state == query_done);
+              assert(!qu->children.head && !qu->children.tail);
+              assert(!qu->parent);
+              assert(!qu->allocations.head && !qu->allocations.tail);
+              checkc_query(ads, qu);
+              }
+  );
 }
 
-void adns__consistency(adns_state ads, adns_query qu, consistency_checks cc) {
+void
+adns__consistency(adns_state ads, adns_query qu, consistency_checks cc)
+{
   adns_query search;
-  
-  switch (cc) {
-  case cc_user:
-    break;
-  case cc_entex:
-    if (!(ads->iflags & adns_if_checkc_entex)) return;
-    break;
-  case cc_freq:
-    if ((ads->iflags & adns_if_checkc_freq) != adns_if_checkc_freq) return;
-    break;
-  default:
-    abort();
+
+  switch (cc)
+  {
+    case cc_user:
+      break;
+    case cc_entex:
+      if (!(ads->iflags & adns_if_checkc_entex))
+        return;
+      break;
+    case cc_freq:
+      if ((ads->iflags & adns_if_checkc_freq) != adns_if_checkc_freq)
+        return;
+      break;
+    default:
+      abort();
   }
 
   checkc_global(ads);
@@ -187,22 +221,24 @@ void adns__consistency(adns_state ads, adns_query qu, consistency_checks cc) {
   checkc_queue_childw(ads);
   checkc_queue_output(ads);
 
-  if (qu) {
-    switch (qu->state) {
-    case query_tosend:
-      DLIST_ASSERTON(qu, search, ads->udpw, unused_arg);
-      break;
-    case query_tcpw:
-      DLIST_ASSERTON(qu, search, ads->tcpw, unused_arg);
-      break;
-    case query_childw:
-      DLIST_ASSERTON(qu, search, ads->childw, unused_arg);
-      break;
-    case query_done:
-      DLIST_ASSERTON(qu, search, ads->output, unused_arg);
-      break;
-    default:
-      assert(!"specific query state");
+  if (qu)
+  {
+    switch (qu->state)
+    {
+      case query_tosend:
+        DLIST_ASSERTON(qu, search, ads->udpw, unused_arg);
+        break;
+      case query_tcpw:
+        DLIST_ASSERTON(qu, search, ads->tcpw, unused_arg);
+        break;
+      case query_childw:
+        DLIST_ASSERTON(qu, search, ads->childw, unused_arg);
+        break;
+      case query_done:
+        DLIST_ASSERTON(qu, search, ads->output, unused_arg);
+        break;
+      default:
+        assert(!"specific query state");
     }
   }
 }
index 1e8bfc0e3cfbfe63e3facd26df8f079a1ee4f67e..fead7cb5ecf8cf887227d2a5c6285c98316da13f 100644 (file)
@@ -26,7 +26,7 @@
  *  along with this program; if not, write to the Free Software Foundation,
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  *
- * $Id: event.c,v 1.1 2002/01/04 09:10:43 a1kmm Exp $
+ * $Id: event.c,v 1.2 2002/04/27 02:48:46 a1kmm Exp $
  */
 
 #include <errno.h>
 
 /* TCP connection management. */
 
-static void tcp_close(adns_state ads) {
+static void
+tcp_close(adns_state ads)
+{
   int serv;
-  
-  serv= ads->tcpserver;
+
+  serv = ads->tcpserver;
   fd_close(ads->tcpsocket);
-  ads->tcpsocket= -1;
-  ads->tcprecv.used= ads->tcprecv_skip= ads->tcpsend.used= 0;
+  ads->tcpsocket = -1;
+  ads->tcprecv.used = ads->tcprecv_skip = ads->tcpsend.used = 0;
 }
 
-void adns__tcp_broken(adns_state ads, const char *what, const char *why) {
+void
+adns__tcp_broken(adns_state ads, const char *what, const char *why)
+{
   int serv;
   adns_query qu;
-  
+
   assert(ads->tcpstate == server_connecting || ads->tcpstate == server_ok);
-  serv= ads->tcpserver;
-  if (what) adns__warn(ads,serv,0,"TCP connection failed: %s: %s",what,why);
+  serv = ads->tcpserver;
+  if (what)
+    adns__warn(ads, serv, 0, "TCP connection failed: %s: %s", what, why);
 
-  if (ads->tcpstate == server_connecting) {
+  if (ads->tcpstate == server_connecting)
+  {
     /* Counts as a retry for all the queries waiting for TCP. */
-    for (qu= ads->tcpw.head; qu; qu= qu->next)
+    for (qu = ads->tcpw.head; qu; qu = qu->next)
       qu->retries++;
   }
 
   tcp_close(ads);
-  ads->tcpstate= server_broken;
-  ads->tcpserver= (serv+1)%ads->nservers;
+  ads->tcpstate = server_broken;
+  ads->tcpserver = (serv + 1) % ads->nservers;
 }
 
-static void tcp_connected(adns_state ads, struct timeval now) {
+static void
+tcp_connected(adns_state ads, struct timeval now)
+{
   adns_query qu, nqu;
-  
-  adns__debug(ads,ads->tcpserver,0,"TCP connected");
-  ads->tcpstate= server_ok;
-  for (qu= ads->tcpw.head; qu && ads->tcpstate == server_ok; qu= nqu) {
-    nqu= qu->next;
+
+  adns__debug(ads, ads->tcpserver, 0, "TCP connected");
+  ads->tcpstate = server_ok;
+  for (qu = ads->tcpw.head; qu && ads->tcpstate == server_ok; qu = nqu)
+  {
+    nqu = qu->next;
     assert(qu->state == query_tcpw);
-    adns__querysend_tcp(qu,now);
+    adns__querysend_tcp(qu, now);
   }
 }
 
-void adns__tcp_tryconnect(adns_state ads, struct timeval now) {
+void
+adns__tcp_tryconnect(adns_state ads, struct timeval now)
+{
   int r, fd, tries;
   struct sockaddr_in addr;
 
-  for (tries=0; tries<ads->nservers; tries++) {
-    switch (ads->tcpstate) {
-    case server_connecting:
-    case server_ok:
-    case server_broken:
-      return;
-    case server_disconnected:
-      break;
-    default:
-      abort();
+  for (tries = 0; tries < ads->nservers; tries++)
+  {
+    switch (ads->tcpstate)
+    {
+      case server_connecting:
+      case server_ok:
+      case server_broken:
+        return;
+      case server_disconnected:
+        break;
+      default:
+        abort();
     }
-    
+
     assert(!ads->tcpsend.used);
     assert(!ads->tcprecv.used);
     assert(!ads->tcprecv_skip);
 
-    fd= comm_open(AF_INET, SOCK_STREAM, 0, "adns TCP socket");
-    if (fd<0) {
-      adns__diag(ads,-1,0,"cannot create TCP socket: %s",strerror(errno));
+    fd = comm_open(AF_INET, SOCK_STREAM, 0, "adns TCP socket");
+    if (fd < 0)
+    {
+      adns__diag(ads, -1, 0, "cannot create TCP socket: %s", strerror(errno));
       return;
     }
-    r= adns__setnonblock(ads,fd);
-    if (r) {
-      adns__diag(ads,-1,0,"cannot make TCP socket nonblocking: %s",strerror(r));
+    r = adns__setnonblock(ads, fd);
+    if (r)
+    {
+      adns__diag(ads, -1, 0, "cannot make TCP socket nonblocking: %s",
+                 strerror(r));
       fd_close(fd);
       return;
     }
-    memset(&addr,0,sizeof(addr));
-    addr.sin_family= AF_INET;
-    addr.sin_port= htons(DNS_PORT);
-    addr.sin_addr= ads->servers[ads->tcpserver].addr;
-    r= connect(fd,(const struct sockaddr*)&addr,sizeof(addr));
-    ads->tcpsocket= fd;
-    ads->tcpstate= server_connecting;
-    if (r==0) { tcp_connected(ads,now); return; }
-    if (errno == EWOULDBLOCK || errno == EINPROGRESS) {
-      ads->tcptimeout= now;
-      timevaladd(&ads->tcptimeout,TCPCONNMS);
+    memset(&addr, 0, sizeof(addr));
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(DNS_PORT);
+    addr.sin_addr = ads->servers[ads->tcpserver].addr;
+    r = connect(fd, (const struct sockaddr *)&addr, sizeof(addr));
+    ads->tcpsocket = fd;
+    ads->tcpstate = server_connecting;
+    if (r == 0)
+    {
+      tcp_connected(ads, now);
       return;
     }
-    adns__tcp_broken(ads,"connect",strerror(errno));
-    ads->tcpstate= server_disconnected;
+    if (errno == EWOULDBLOCK || errno == EINPROGRESS)
+    {
+      ads->tcptimeout = now;
+      timevaladd(&ads->tcptimeout, TCPCONNMS);
+      return;
+    }
+    adns__tcp_broken(ads, "connect", strerror(errno));
+    ads->tcpstate = server_disconnected;
   }
 }
 
 /* Timeout handling functions. */
 
-void adns__must_gettimeofday(adns_state ads, const struct timeval **now_io,
-                            struct timeval *tv_buf) {
+void
+adns__must_gettimeofday(adns_state ads, const struct timeval **now_io,
+                        struct timeval *tv_buf)
+{
   const struct timeval *now;
   int r;
 
-  now= *now_io;
-  if (now) return;
-  r= gettimeofday(tv_buf,0); if (!r) { *now_io= tv_buf; return; }
-  adns__diag(ads,-1,0,"gettimeofday failed: %s",strerror(errno));
+  now = *now_io;
+  if (now)
+    return;
+  r = gettimeofday(tv_buf, 0);
+  if (!r)
+  {
+    *now_io = tv_buf;
+    return;
+  }
+  adns__diag(ads, -1, 0, "gettimeofday failed: %s", strerror(errno));
   adns_globalsystemfailure(ads);
   return;
 }
 
-static void inter_immed(struct timeval **tv_io, struct timeval *tvbuf) {
+static void
+inter_immed(struct timeval **tv_io, struct timeval *tvbuf)
+{
   struct timeval *rbuf;
 
-  if (!tv_io) return;
+  if (!tv_io)
+    return;
 
-  rbuf= *tv_io;
-  if (!rbuf) { *tv_io= rbuf= tvbuf; }
+  rbuf = *tv_io;
+  if (!rbuf)
+  {
+    *tv_io = rbuf = tvbuf;
+  }
 
   timerclear(rbuf);
 }
-    
-static void inter_maxto(struct timeval **tv_io, struct timeval *tvbuf,
-                       struct timeval maxto) {
+
+static void
+inter_maxto(struct timeval **tv_io, struct timeval *tvbuf,
+            struct timeval maxto)
+{
   struct timeval *rbuf;
 
-  if (!tv_io) return;
-  rbuf= *tv_io;
-  if (!rbuf) {
-    *tvbuf= maxto; *tv_io= tvbuf;
-  } else {
-    if (timercmp(rbuf,&maxto,>)) *rbuf= maxto;
+  if (!tv_io)
+    return;
+  rbuf = *tv_io;
+  if (!rbuf)
+  {
+    *tvbuf = maxto;
+    *tv_io = tvbuf;
+  }
+  else
+  {
+    if (timercmp(rbuf, &maxto, >))
+      *rbuf = maxto;
   }
 /*fprintf(stderr,"inter_maxto maxto=%ld.%06ld result=%ld.%06ld\n",
        maxto.tv_sec,maxto.tv_usec,(**tv_io).tv_sec,(**tv_io).tv_usec);*/
 }
 
-static void inter_maxtoabs(struct timeval **tv_io, struct timeval *tvbuf,
-                          struct timeval now, struct timeval maxtime) {
+static void
+inter_maxtoabs(struct timeval **tv_io, struct timeval *tvbuf,
+               struct timeval now, struct timeval maxtime)
+{
   /* tv_io may be 0 */
   ldiv_t dr;
 
 /*fprintf(stderr,"inter_maxtoabs now=%ld.%06ld maxtime=%ld.%06ld\n",
        now.tv_sec,now.tv_usec,maxtime.tv_sec,maxtime.tv_usec);*/
-  if (!tv_io) return;
-  maxtime.tv_sec -= (now.tv_sec+2);
-  maxtime.tv_usec -= (now.tv_usec-2000000);
-  dr= ldiv(maxtime.tv_usec,1000000);
+  if (!tv_io)
+    return;
+  maxtime.tv_sec -= (now.tv_sec + 2);
+  maxtime.tv_usec -= (now.tv_usec - 2000000);
+  dr = ldiv(maxtime.tv_usec, 1000000);
   maxtime.tv_sec += dr.quot;
-  maxtime.tv_usec -= dr.quot*1000000;
-  if (maxtime.tv_sec<0) timerclear(&maxtime);
-  inter_maxto(tv_io,tvbuf,maxtime);
+  maxtime.tv_usec -= dr.quot * 1000000;
+  if (maxtime.tv_sec < 0)
+    timerclear(&maxtime);
+  inter_maxto(tv_io, tvbuf, maxtime);
 }
 
-static void timeouts_queue(adns_state ads, int act,
-                          struct timeval **tv_io, struct timeval *tvbuf,
-                          struct timeval now, struct query_queue *queue) {
+static void
+timeouts_queue(adns_state ads, int act,
+               struct timeval **tv_io, struct timeval *tvbuf,
+               struct timeval now, struct query_queue *queue)
+{
   adns_query qu, nqu;
-  
-  for (qu= queue->head; qu; qu= nqu) {
-    nqu= qu->next;
-    if (!timercmp(&now,&qu->timeout,>)) {
-      inter_maxtoabs(tv_io,tvbuf,now,qu->timeout);
-    } else {
-      if (!act) { inter_immed(tv_io,tvbuf); return; }
-      LIST_UNLINK(*queue,qu);
-      if (qu->state != query_tosend) {
-       adns__query_fail(qu,adns_s_timeout);
-      } else {
-       adns__query_send(qu,now);
+
+  for (qu = queue->head; qu; qu = nqu)
+  {
+    nqu = qu->next;
+    if (!timercmp(&now, &qu->timeout, >))
+    {
+      inter_maxtoabs(tv_io, tvbuf, now, qu->timeout);
+    }
+    else
+    {
+      if (!act)
+      {
+        inter_immed(tv_io, tvbuf);
+        return;
+      }
+      LIST_UNLINK(*queue, qu);
+      if (qu->state != query_tosend)
+      {
+        adns__query_fail(qu, adns_s_timeout);
+      }
+      else
+      {
+        adns__query_send(qu, now);
       }
-      nqu= queue->head;
+      nqu = queue->head;
     }
   }
 }
 
-static void tcp_events(adns_state ads, int act,
-                      struct timeval **tv_io, struct timeval *tvbuf,
-                      struct timeval now) {
+static void
+tcp_events(adns_state ads, int act,
+           struct timeval **tv_io, struct timeval *tvbuf, struct timeval now)
+{
   adns_query qu, nqu;
-  
-  for (;;) {
-    switch (ads->tcpstate) {
-    case server_broken:
-      if (!act) { inter_immed(tv_io,tvbuf); return; }
-      for (qu= ads->tcpw.head; qu; qu= nqu) {
-       nqu= qu->next;
-       assert(qu->state == query_tcpw);
-       if (qu->retries > ads->nservers) {
-         LIST_UNLINK(ads->tcpw,qu);
-         adns__query_fail(qu,adns_s_allservfail);
-       }
-      }
-      ads->tcpstate= server_disconnected;
-    case server_disconnected: /* fall through */
-      if (!ads->tcpw.head) return;
-      if (!act) { inter_immed(tv_io,tvbuf); return; }
-      adns__tcp_tryconnect(ads,now);
-      break;
-    case server_ok:
-      if (ads->tcpw.head) return;
-      if (!ads->tcptimeout.tv_sec) {
-       assert(!ads->tcptimeout.tv_usec);
-       ads->tcptimeout= now;
-       timevaladd(&ads->tcptimeout,TCPIDLEMS);
-      }
-    case server_connecting: /* fall through */
-      if (!act || !timercmp(&now,&ads->tcptimeout,>)) {
-       inter_maxtoabs(tv_io,tvbuf,now,ads->tcptimeout);
-       return;
-      } {
-       /* TCP timeout has happened */
-       switch (ads->tcpstate) {
-       case server_connecting: /* failed to connect */
-         adns__tcp_broken(ads,"unable to make connection","timed out");
-         break;
-       case server_ok: /* idle timeout */
-         tcp_close(ads);
-         ads->tcpstate= server_disconnected;
-         return;
-       default:
-         abort();
-       }
-      }
-      break;
-    default:
-      abort();
+
+  for (;;)
+  {
+    switch (ads->tcpstate)
+    {
+      case server_broken:
+        if (!act)
+        {
+          inter_immed(tv_io, tvbuf);
+          return;
+        }
+        for (qu = ads->tcpw.head; qu; qu = nqu)
+        {
+          nqu = qu->next;
+          assert(qu->state == query_tcpw);
+          if (qu->retries > ads->nservers)
+          {
+            LIST_UNLINK(ads->tcpw, qu);
+            adns__query_fail(qu, adns_s_allservfail);
+          }
+        }
+        ads->tcpstate = server_disconnected;
+      case server_disconnected:        /* fall through */
+        if (!ads->tcpw.head)
+          return;
+        if (!act)
+        {
+          inter_immed(tv_io, tvbuf);
+          return;
+        }
+        adns__tcp_tryconnect(ads, now);
+        break;
+      case server_ok:
+        if (ads->tcpw.head)
+          return;
+        if (!ads->tcptimeout.tv_sec)
+        {
+          assert(!ads->tcptimeout.tv_usec);
+          ads->tcptimeout = now;
+          timevaladd(&ads->tcptimeout, TCPIDLEMS);
+        }
+      case server_connecting:  /* fall through */
+        if (!act || !timercmp(&now, &ads->tcptimeout, >))
+        {
+          inter_maxtoabs(tv_io, tvbuf, now, ads->tcptimeout);
+          return;
+        }
+        {
+          /* TCP timeout has happened */
+          switch (ads->tcpstate)
+          {
+            case server_connecting:    /* failed to connect */
+              adns__tcp_broken(ads, "unable to make connection", "timed out");
+              break;
+            case server_ok:    /* idle timeout */
+              tcp_close(ads);
+              ads->tcpstate = server_disconnected;
+              return;
+            default:
+              abort();
+          }
+        }
+        break;
+      default:
+        abort();
     }
   }
   return;
 }
 
-void adns__timeouts(adns_state ads, int act,
-                   struct timeval **tv_io, struct timeval *tvbuf,
-                   struct timeval now) {
-  timeouts_queue(ads,act,tv_io,tvbuf,now, &ads->udpw);
-  timeouts_queue(ads,act,tv_io,tvbuf,now, &ads->tcpw);
-  tcp_events(ads,act,tv_io,tvbuf,now);
+void
+adns__timeouts(adns_state ads, int act,
+               struct timeval **tv_io, struct timeval *tvbuf,
+               struct timeval now)
+{
+  timeouts_queue(ads, act, tv_io, tvbuf, now, &ads->udpw);
+  timeouts_queue(ads, act, tv_io, tvbuf, now, &ads->tcpw);
+  tcp_events(ads, act, tv_io, tvbuf, now);
 }
 
-void adns_firsttimeout(adns_state ads,
-                      struct timeval **tv_io, struct timeval *tvbuf,
-                      struct timeval now) {
-  adns__consistency(ads,0,cc_entex);
-  adns__timeouts(ads, 0, tv_io,tvbuf, now);
-  adns__consistency(ads,0,cc_entex);
+void
+adns_firsttimeout(adns_state ads,
+                  struct timeval **tv_io, struct timeval *tvbuf,
+                  struct timeval now)
+{
+  adns__consistency(ads, 0, cc_entex);
+  adns__timeouts(ads, 0, tv_io, tvbuf, now);
+  adns__consistency(ads, 0, cc_entex);
 }
 
-void adns_processtimeouts(adns_state ads, const struct timeval *now) {
+void
+adns_processtimeouts(adns_state ads, const struct timeval *now)
+{
   struct timeval tv_buf;
 
-  adns__consistency(ads,0,cc_entex);
-  adns__must_gettimeofday(ads,&now,&tv_buf);
-  if (now) adns__timeouts(ads, 1, 0,0, *now);
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
+  adns__must_gettimeofday(ads, &now, &tv_buf);
+  if (now)
+    adns__timeouts(ads, 1, 0, 0, *now);
+  adns__consistency(ads, 0, cc_entex);
 }
 
 /* fd handling functions.  These are the top-level of the real work of
  * reception and often transmission.
  */
 
-int adns__pollfds(adns_state ads, struct adns_pollfd pollfds_buf[MAX_POLLFDS]) {
+int
+adns__pollfds(adns_state ads, struct adns_pollfd pollfds_buf[MAX_POLLFDS])
+{
   /* Returns the number of entries filled in.  Always zeroes revents. */
 
-  assert(MAX_POLLFDS==2);
-
-  pollfds_buf[0].fd= ads->udpsocket;
-  pollfds_buf[0].events= ADNS_POLLIN;
-  pollfds_buf[0].revents= 0;
-
-  switch (ads->tcpstate) {
-  case server_disconnected:
-  case server_broken:
-    return 1;
-  case server_connecting:
-    pollfds_buf[1].events= ADNS_POLLOUT;
-    break;
-  case server_ok:
-    pollfds_buf[1].events= ads->tcpsend.used ? ADNS_POLLIN|ADNS_POLLOUT|ADNS_POLLPRI : ADNS_POLLIN|ADNS_POLLPRI;
-    break;
-  default:
-    abort();
+  assert(MAX_POLLFDS == 2);
+
+  pollfds_buf[0].fd = ads->udpsocket;
+  pollfds_buf[0].events = ADNS_POLLIN;
+  pollfds_buf[0].revents = 0;
+
+  switch (ads->tcpstate)
+  {
+    case server_disconnected:
+    case server_broken:
+      return 1;
+    case server_connecting:
+      pollfds_buf[1].events = ADNS_POLLOUT;
+      break;
+    case server_ok:
+      pollfds_buf[1].events =
+        ads->tcpsend.
+        used ? ADNS_POLLIN | ADNS_POLLOUT | ADNS_POLLPRI : ADNS_POLLIN |
+        ADNS_POLLPRI;
+      break;
+    default:
+      abort();
   }
-  pollfds_buf[1].fd= ads->tcpsocket;
+  pollfds_buf[1].fd = ads->tcpsocket;
   return 2;
 }
 
-int adns_processreadable(adns_state ads, int fd, const struct timeval *now) {
+int
+adns_processreadable(adns_state ads, int fd, const struct timeval *now)
+{
   int want, dgramlen, r, udpaddrlen, serv, old_skip;
   byte udpbuf[DNS_MAXUDP];
   struct sockaddr_in udpaddr;
-  
-  adns__consistency(ads,0,cc_entex);
-
-  switch (ads->tcpstate) {
-  case server_disconnected:
-  case server_broken:
-  case server_connecting:
-    break;
-  case server_ok:
-    if (fd != ads->tcpsocket) break;
-    assert(!ads->tcprecv_skip);
-    do {
-      if (ads->tcprecv.used >= ads->tcprecv_skip+2) {
-       dgramlen= ((ads->tcprecv.buf[ads->tcprecv_skip]<<8) |
-                  ads->tcprecv.buf[ads->tcprecv_skip+1]);
-       if (ads->tcprecv.used >= ads->tcprecv_skip+2+dgramlen) {
-         old_skip= ads->tcprecv_skip;
-         ads->tcprecv_skip += 2+dgramlen;
-         adns__procdgram(ads, ads->tcprecv.buf+old_skip+2,
-                         dgramlen, ads->tcpserver, 1,*now);
-         continue;
-       } else {
-         want= 2+dgramlen;
-       }
-      } else {
-       want= 2;
-      }
-      ads->tcprecv.used -= ads->tcprecv_skip;
-      memmove(ads->tcprecv.buf,ads->tcprecv.buf+ads->tcprecv_skip,ads->tcprecv.used);
-      ads->tcprecv_skip= 0;
-      if (!adns__vbuf_ensure(&ads->tcprecv,want)) { r= ENOMEM; goto xit; }
-      assert(ads->tcprecv.used <= ads->tcprecv.avail);
-      if (ads->tcprecv.used == ads->tcprecv.avail) continue;
-      r= read(ads->tcpsocket,
-             ads->tcprecv.buf+ads->tcprecv.used,
-             ads->tcprecv.avail-ads->tcprecv.used);
-      if (r>0) {
-       ads->tcprecv.used+= r;
-      } else {
-       if (r) {
-         if (errno==EAGAIN || errno==EWOULDBLOCK) { r= 0; goto xit; }
-         if (errno==EINTR) continue;
-         if (errno_resources(errno)) { r= errno; goto xit; }
-       }
-       adns__tcp_broken(ads,"read",r?strerror(errno):"closed");
+
+  adns__consistency(ads, 0, cc_entex);
+
+  switch (ads->tcpstate)
+  {
+    case server_disconnected:
+    case server_broken:
+    case server_connecting:
+      break;
+    case server_ok:
+      if (fd != ads->tcpsocket)
+        break;
+      assert(!ads->tcprecv_skip);
+      do
+      {
+        if (ads->tcprecv.used >= ads->tcprecv_skip + 2)
+        {
+          dgramlen = ((ads->tcprecv.buf[ads->tcprecv_skip] << 8) |
+                      ads->tcprecv.buf[ads->tcprecv_skip + 1]);
+          if (ads->tcprecv.used >= ads->tcprecv_skip + 2 + dgramlen)
+          {
+            old_skip = ads->tcprecv_skip;
+            ads->tcprecv_skip += 2 + dgramlen;
+            adns__procdgram(ads, ads->tcprecv.buf + old_skip + 2,
+                            dgramlen, ads->tcpserver, 1, *now);
+            continue;
+          }
+          else
+          {
+            want = 2 + dgramlen;
+          }
+        }
+        else
+        {
+          want = 2;
+        }
+        ads->tcprecv.used -= ads->tcprecv_skip;
+        memmove(ads->tcprecv.buf, ads->tcprecv.buf + ads->tcprecv_skip,
+                ads->tcprecv.used);
+        ads->tcprecv_skip = 0;
+        if (!adns__vbuf_ensure(&ads->tcprecv, want))
+        {
+          r = ENOMEM;
+          goto xit;
+        }
+        assert(ads->tcprecv.used <= ads->tcprecv.avail);
+        if (ads->tcprecv.used == ads->tcprecv.avail)
+          continue;
+        r = read(ads->tcpsocket,
+                 ads->tcprecv.buf + ads->tcprecv.used,
+                 ads->tcprecv.avail - ads->tcprecv.used);
+        if (r > 0)
+        {
+          ads->tcprecv.used += r;
+        }
+        else
+        {
+          if (r)
+          {
+            if (errno == EAGAIN || errno == EWOULDBLOCK)
+            {
+              r = 0;
+              goto xit;
+            }
+            if (errno == EINTR)
+              continue;
+            if (errno_resources(errno))
+            {
+              r = errno;
+              goto xit;
+            }
+          }
+          adns__tcp_broken(ads, "read", r ? strerror(errno) : "closed");
+        }
       }
-    } while (ads->tcpstate == server_ok);
-    r= 0; goto xit;
-  default:
-    abort();
+      while (ads->tcpstate == server_ok);
+      r = 0;
+      goto xit;
+    default:
+      abort();
   }
-  if (fd == ads->udpsocket) {
-    for (;;) {
-      udpaddrlen= sizeof(udpaddr);
-      r= recvfrom(ads->udpsocket,udpbuf,sizeof(udpbuf),0,
-                 (struct sockaddr*)&udpaddr,(unsigned int*)&udpaddrlen);
-      if (r<0) {
-       if (errno == EAGAIN || errno == EWOULDBLOCK) { r= 0; goto xit; }
-       if (errno == EINTR) continue;
-       if (errno_resources(errno)) { r= errno; goto xit; }
-       adns__warn(ads,-1,0,"datagram receive error: %s",strerror(errno));
-       r= 0; goto xit;
+  if (fd == ads->udpsocket)
+  {
+    for (;;)
+    {
+      udpaddrlen = sizeof(udpaddr);
+      r = recvfrom(ads->udpsocket, udpbuf, sizeof(udpbuf), 0,
+                   (struct sockaddr *)&udpaddr, (unsigned int *)&udpaddrlen);
+      if (r < 0)
+      {
+        if (errno == EAGAIN || errno == EWOULDBLOCK)
+        {
+          r = 0;
+          goto xit;
+        }
+        if (errno == EINTR)
+          continue;
+        if (errno_resources(errno))
+        {
+          r = errno;
+          goto xit;
+        }
+        adns__warn(ads, -1, 0, "datagram receive error: %s", strerror(errno));
+        r = 0;
+        goto xit;
       }
-      if (udpaddrlen != sizeof(udpaddr)) {
-       adns__diag(ads,-1,0,"datagram received with wrong address length %d"
-                  " (expected %lu)", udpaddrlen,
-                  (unsigned long)sizeof(udpaddr));
-       continue;
+      if (udpaddrlen != sizeof(udpaddr))
+      {
+        adns__diag(ads, -1, 0,
+                   "datagram received with wrong address length %d"
+                   " (expected %lu)", udpaddrlen,
+                   (unsigned long)sizeof(udpaddr));
+        continue;
       }
-      if (udpaddr.sin_family != AF_INET) {
-       adns__diag(ads,-1,0,"datagram received with wrong protocol family"
-                  " %u (expected %u)",udpaddr.sin_family,AF_INET);
-       continue;
+      if (udpaddr.sin_family != AF_INET)
+      {
+        adns__diag(ads, -1, 0,
+                   "datagram received with wrong protocol family"
+                   " %u (expected %u)", udpaddr.sin_family, AF_INET);
+        continue;
       }
-      if (ntohs(udpaddr.sin_port) != DNS_PORT) {
-       adns__diag(ads,-1,0,"datagram received from wrong port %u (expected %u)",
-                  ntohs(udpaddr.sin_port),DNS_PORT);
-       continue;
+      if (ntohs(udpaddr.sin_port) != DNS_PORT)
+      {
+        adns__diag(ads, -1, 0,
+                   "datagram received from wrong port %u (expected %u)",
+                   ntohs(udpaddr.sin_port), DNS_PORT);
+        continue;
       }
-      for (serv= 0;
-          serv < ads->nservers &&
-            ads->servers[serv].addr.s_addr != udpaddr.sin_addr.s_addr;
-          serv++);
-      if (serv >= ads->nservers) {
-       adns__warn(ads,-1,0,"datagram received from unknown nameserver %s",
-                  inetntoa((char *)&udpaddr.sin_addr));
-       continue;
+      for (serv = 0;
+           serv < ads->nservers &&
+           ads->servers[serv].addr.s_addr != udpaddr.sin_addr.s_addr; serv++);
+      if (serv >= ads->nservers)
+      {
+        adns__warn(ads, -1, 0,
+                   "datagram received from unknown nameserver %s",
+                   inetntoa((char *)&udpaddr.sin_addr));
+        continue;
       }
-      adns__procdgram(ads,udpbuf,r,serv,0,*now);
+      adns__procdgram(ads, udpbuf, r, serv, 0, *now);
     }
   }
-  r= 0;
+  r = 0;
 xit:
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
   return r;
 }
 
-int adns_processwriteable(adns_state ads, int fd, const struct timeval *now) {
+int
+adns_processwriteable(adns_state ads, int fd, const struct timeval *now)
+{
   int r;
-  
-  adns__consistency(ads,0,cc_entex);
-
-  switch (ads->tcpstate) {
-  case server_disconnected:
-  case server_broken:
-    break;
-  case server_connecting:
-    if (fd != ads->tcpsocket) break;
-    assert(ads->tcprecv.used==0);
-    assert(ads->tcprecv_skip==0);
-    for (;;) {
-      if (!adns__vbuf_ensure(&ads->tcprecv,1)) { r= ENOMEM; goto xit; }
-      r= read(ads->tcpsocket,&ads->tcprecv.buf,1);
-      if (r==0 || (r<0 && (errno==EAGAIN || errno==EWOULDBLOCK))) {
-       tcp_connected(ads,*now);
-       r= 0; goto xit;
-      }
-      if (r>0) {
-       adns__tcp_broken(ads,"connect/read","sent data before first request");
-       r= 0; goto xit;
-      }
-      if (errno==EINTR) continue;
-      if (errno_resources(errno)) { r= errno; goto xit; }
-      adns__tcp_broken(ads,"connect/read",strerror(errno));
-      r= 0; goto xit;
-    } /* not reached */
-  case server_ok:
-    if (fd != ads->tcpsocket) break;
-    while (ads->tcpsend.used) {
-      r= write(ads->tcpsocket,ads->tcpsend.buf,ads->tcpsend.used);
-      if (r<0) {
-       if (errno==EINTR) continue;
-       if (errno==EAGAIN || errno==EWOULDBLOCK) { r= 0; goto xit; }
-       if (errno_resources(errno)) { r= errno; goto xit; }
-       adns__tcp_broken(ads,"write",strerror(errno));
-       r= 0; goto xit;
-      } else if (r>0) {
-       ads->tcpsend.used -= r;
-       memmove(ads->tcpsend.buf,ads->tcpsend.buf+r,ads->tcpsend.used);
+
+  adns__consistency(ads, 0, cc_entex);
+
+  switch (ads->tcpstate)
+  {
+    case server_disconnected:
+    case server_broken:
+      break;
+    case server_connecting:
+      if (fd != ads->tcpsocket)
+        break;
+      assert(ads->tcprecv.used == 0);
+      assert(ads->tcprecv_skip == 0);
+      for (;;)
+      {
+        if (!adns__vbuf_ensure(&ads->tcprecv, 1))
+        {
+          r = ENOMEM;
+          goto xit;
+        }
+        r = read(ads->tcpsocket, &ads->tcprecv.buf, 1);
+        if (r == 0 || (r < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)))
+        {
+          tcp_connected(ads, *now);
+          r = 0;
+          goto xit;
+        }
+        if (r > 0)
+        {
+          adns__tcp_broken(ads, "connect/read",
+                           "sent data before first request");
+          r = 0;
+          goto xit;
+        }
+        if (errno == EINTR)
+          continue;
+        if (errno_resources(errno))
+        {
+          r = errno;
+          goto xit;
+        }
+        adns__tcp_broken(ads, "connect/read", strerror(errno));
+        r = 0;
+        goto xit;
+      }                         /* not reached */
+    case server_ok:
+      if (fd != ads->tcpsocket)
+        break;
+      while (ads->tcpsend.used)
+      {
+        r = write(ads->tcpsocket, ads->tcpsend.buf, ads->tcpsend.used);
+        if (r < 0)
+        {
+          if (errno == EINTR)
+            continue;
+          if (errno == EAGAIN || errno == EWOULDBLOCK)
+          {
+            r = 0;
+            goto xit;
+          }
+          if (errno_resources(errno))
+          {
+            r = errno;
+            goto xit;
+          }
+          adns__tcp_broken(ads, "write", strerror(errno));
+          r = 0;
+          goto xit;
+        }
+        else if (r > 0)
+        {
+          ads->tcpsend.used -= r;
+          memmove(ads->tcpsend.buf, ads->tcpsend.buf + r, ads->tcpsend.used);
+        }
       }
-    }
-    r= 0;
-    goto xit;
-  default:
-    abort();
+      r = 0;
+      goto xit;
+    default:
+      abort();
   }
-  r= 0;
+  r = 0;
 xit:
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
   return r;
 }
-  
-int adns_processexceptional(adns_state ads, int fd, const struct timeval *now) {
-  adns__consistency(ads,0,cc_entex);
-  switch (ads->tcpstate) {
-  case server_disconnected:
-  case server_broken:
-    break;
-  case server_connecting:
-  case server_ok:
-    if (fd != ads->tcpsocket) break;
-    adns__tcp_broken(ads,"poll/select","exceptional condition detected");
-    break;
-  default:
-    abort();
+
+int
+adns_processexceptional(adns_state ads, int fd, const struct timeval *now)
+{
+  adns__consistency(ads, 0, cc_entex);
+  switch (ads->tcpstate)
+  {
+    case server_disconnected:
+    case server_broken:
+      break;
+    case server_connecting:
+    case server_ok:
+      if (fd != ads->tcpsocket)
+        break;
+      adns__tcp_broken(ads, "poll/select", "exceptional condition detected");
+      break;
+    default:
+      abort();
   }
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
   return 0;
 }
 
-static void fd_event(adns_state ads, int fd,
-                    int revent, int pollflag,
-                    int maxfd, const fd_set *fds,
-                    int (*func)(adns_state, int fd, const struct timeval *now),
-                    struct timeval now, int *r_r) {
+static void
+fd_event(adns_state ads, int fd,
+         int revent, int pollflag,
+         int maxfd, const fd_set * fds,
+         int (*func) (adns_state, int fd, const struct timeval * now),
+         struct timeval now, int *r_r)
+{
   int r;
-  
-  if (!(revent & pollflag)) return;
-  if (fds && !(fd<maxfd && FD_ISSET(fd,fds))) return;
-  r= func(ads,fd,&now);
-  if (r) {
-    if (r_r) {
-      *r_r= r;
-    } else {
-      adns__diag(ads,-1,0,"process fd failed after select: %s",strerror(errno));
+
+  if (!(revent & pollflag))
+    return;
+  if (fds && !(fd < maxfd && FD_ISSET(fd, fds)))
+    return;
+  r = func(ads, fd, &now);
+  if (r)
+  {
+    if (r_r)
+    {
+      *r_r = r;
+    }
+    else
+    {
+      adns__diag(ads, -1, 0, "process fd failed after select: %s",
+                 strerror(errno));
       adns_globalsystemfailure(ads);
     }
   }
 }
 
-void adns__fdevents(adns_state ads,
-                   const struct adns_pollfd *pollfds, int npollfds,
-                   int maxfd, const fd_set *readfds,
-                   const fd_set *writefds, const fd_set *exceptfds,
-                   struct timeval now, int *r_r) {
+void
+adns__fdevents(adns_state ads,
+               const struct adns_pollfd *pollfds, int npollfds,
+               int maxfd, const fd_set * readfds,
+               const fd_set * writefds, const fd_set * exceptfds,
+               struct timeval now, int *r_r)
+{
   int i, fd, revents;
 
-  for (i=0; i<npollfds; i++) {
-    fd= pollfds[i].fd;
-    if (fd >= maxfd) maxfd= fd+1;
-    revents= pollfds[i].revents;
-    fd_event(ads,fd, revents,ADNS_POLLIN, maxfd,readfds, adns_processreadable,now,r_r);
-    fd_event(ads,fd, revents,ADNS_POLLOUT, maxfd,writefds, adns_processwriteable,now,r_r);
-    fd_event(ads,fd, revents,ADNS_POLLPRI, maxfd,exceptfds, adns_processexceptional,now,r_r);
+  for (i = 0; i < npollfds; i++)
+  {
+    fd = pollfds[i].fd;
+    if (fd >= maxfd)
+      maxfd = fd + 1;
+    revents = pollfds[i].revents;
+    fd_event(ads, fd, revents, ADNS_POLLIN, maxfd, readfds,
+             adns_processreadable, now, r_r);
+    fd_event(ads, fd, revents, ADNS_POLLOUT, maxfd, writefds,
+             adns_processwriteable, now, r_r);
+    fd_event(ads, fd, revents, ADNS_POLLPRI, maxfd, exceptfds,
+             adns_processexceptional, now, r_r);
   }
 }
 
 /* Wrappers for select(2). */
 #if 0
-void adns_beforeselect(adns_state ads, int *maxfd_io, fd_set *readfds_io,
-                      fd_set *writefds_io, fd_set *exceptfds_io,
-                      struct timeval **tv_mod, struct timeval *tv_tobuf,
-                      const struct timeval *now) {
+void
+adns_beforeselect(adns_state ads, int *maxfd_io, fd_set * readfds_io,
+                  fd_set * writefds_io, fd_set * exceptfds_io,
+                  struct timeval **tv_mod, struct timeval *tv_tobuf,
+                  const struct timeval *now)
+{
   struct timeval tv_nowbuf;
   struct adns_pollfd pollfds[MAX_POLLFDS];
   int i, fd, maxfd, npollfds;
-  
-  adns__consistency(ads,0,cc_entex);
 
-  if (tv_mod && (!*tv_mod || (*tv_mod)->tv_sec || (*tv_mod)->tv_usec)) {
+  adns__consistency(ads, 0, cc_entex);
+
+  if (tv_mod && (!*tv_mod || (*tv_mod)->tv_sec || (*tv_mod)->tv_usec))
+  {
     /* The caller is planning to sleep. */
-    adns__must_gettimeofday(ads,&now,&tv_nowbuf);
-    if (!now) { inter_immed(tv_mod,tv_tobuf); goto xit; }
-    adns__timeouts(ads, 0, tv_mod,tv_tobuf, *now);
+    adns__must_gettimeofday(ads, &now, &tv_nowbuf);
+    if (!now)
+    {
+      inter_immed(tv_mod, tv_tobuf);
+      goto xit;
+    }
+    adns__timeouts(ads, 0, tv_mod, tv_tobuf, *now);
   }
 
-  npollfds= adns__pollfds(ads,pollfds);
-  maxfd= *maxfd_io;
-  for (i=0; i<npollfds; i++) {
-    fd= pollfds[i].fd;
-    if (fd >= maxfd) maxfd= fd+1;
-    if (pollfds[i].events & ADNS_POLLIN) FD_SET(fd,readfds_io);
-    if (pollfds[i].events & ADNS_POLLOUT) FD_SET(fd,writefds_io);
-    if (pollfds[i].events & ADNS_POLLPRI) FD_SET(fd,exceptfds_io);
+  npollfds = adns__pollfds(ads, pollfds);
+  maxfd = *maxfd_io;
+  for (i = 0; i < npollfds; i++)
+  {
+    fd = pollfds[i].fd;
+    if (fd >= maxfd)
+      maxfd = fd + 1;
+    if (pollfds[i].events & ADNS_POLLIN)
+      FD_SET(fd, readfds_io);
+    if (pollfds[i].events & ADNS_POLLOUT)
+      FD_SET(fd, writefds_io);
+    if (pollfds[i].events & ADNS_POLLPRI)
+      FD_SET(fd, exceptfds_io);
   }
-  *maxfd_io= maxfd;
+  *maxfd_io = maxfd;
 
 xit:
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
 }
 
-void adns_afterselect(adns_state ads, int maxfd, const fd_set *readfds,
-                     const fd_set *writefds, const fd_set *exceptfds,
-                     const struct timeval *now) {
+void
+adns_afterselect(adns_state ads, int maxfd, const fd_set * readfds,
+                 const fd_set * writefds, const fd_set * exceptfds,
+                 const struct timeval *now)
+{
   struct timeval tv_buf;
   struct adns_pollfd pollfds[MAX_POLLFDS];
   int npollfds, i;
 
-  adns__consistency(ads,0,cc_entex);
-  adns__must_gettimeofday(ads,&now,&tv_buf);
-  if (!now) goto xit;
-  adns_processtimeouts(ads,now);
+  adns__consistency(ads, 0, cc_entex);
+  adns__must_gettimeofday(ads, &now, &tv_buf);
+  if (!now)
+    goto xit;
+  adns_processtimeouts(ads, now);
 
-  npollfds= adns__pollfds(ads,pollfds);
-  for (i=0; i<npollfds; i++) pollfds[i].revents= ADNS_POLLIN|ADNS_POLLOUT|ADNS_POLLPRI;
+  npollfds = adns__pollfds(ads, pollfds);
+  for (i = 0; i < npollfds; i++)
+    pollfds[i].revents = ADNS_POLLIN | ADNS_POLLOUT | ADNS_POLLPRI;
   adns__fdevents(ads,
-                pollfds,npollfds,
-                maxfd,readfds,writefds,exceptfds,
-                *now, 0);
+                 pollfds, npollfds,
+                 maxfd, readfds, writefds, exceptfds, *now, 0);
 xit:
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
 }
 #endif
 /* General helpful functions. */
 
-void adns_globalsystemfailure(adns_state ads) {
-  adns__consistency(ads,0,cc_entex);
-
-  while (ads->udpw.head) adns__query_fail(ads->udpw.head, adns_s_systemfail);
-  while (ads->tcpw.head) adns__query_fail(ads->tcpw.head, adns_s_systemfail);
-  
-  switch (ads->tcpstate) {
-  case server_connecting:
-  case server_ok:
-    adns__tcp_broken(ads,0,0);
-    break;
-  case server_disconnected:
-  case server_broken:
-    break;
-  default:
-    abort();
+void
+adns_globalsystemfailure(adns_state ads)
+{
+  adns__consistency(ads, 0, cc_entex);
+
+  while (ads->udpw.head)
+    adns__query_fail(ads->udpw.head, adns_s_systemfail);
+  while (ads->tcpw.head)
+    adns__query_fail(ads->tcpw.head, adns_s_systemfail);
+
+  switch (ads->tcpstate)
+  {
+    case server_connecting:
+    case server_ok:
+      adns__tcp_broken(ads, 0, 0);
+      break;
+    case server_disconnected:
+    case server_broken:
+      break;
+    default:
+      abort();
   }
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
 }
 
-int adns_processany(adns_state ads) {
+int
+adns_processany(adns_state ads)
+{
   int r, i;
   struct timeval now;
   struct adns_pollfd pollfds[MAX_POLLFDS];
   int npollfds;
 
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
 
-  r= gettimeofday(&now,0);
-  if (!r) adns_processtimeouts(ads,&now);
+  r = gettimeofday(&now, 0);
+  if (!r)
+    adns_processtimeouts(ads, &now);
 
   /* We just use adns__fdevents to loop over the fd's trying them.
    * This seems more sensible than calling select, since we're most
    * likely just to want to do a read on one or two fds anyway.
    */
-  npollfds= adns__pollfds(ads,pollfds);
-  for (i=0; i<npollfds; i++) pollfds[i].revents= pollfds[i].events & ~ADNS_POLLPRI;
-  adns__fdevents(ads,
-                pollfds,npollfds,
-                0,0,0,0,
-                now,&r);
+  npollfds = adns__pollfds(ads, pollfds);
+  for (i = 0; i < npollfds; i++)
+    pollfds[i].revents = pollfds[i].events & ~ADNS_POLLPRI;
+  adns__fdevents(ads, pollfds, npollfds, 0, 0, 0, 0, now, &r);
 
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
   return 0;
 }
 
-void adns__autosys(adns_state ads, struct timeval now) {
-  if (ads->iflags & adns_if_noautosys) return;
+void
+adns__autosys(adns_state ads, struct timeval now)
+{
+  if (ads->iflags & adns_if_noautosys)
+    return;
   adns_processany(ads);
 }
 
-int adns__internal_check(adns_state ads,
-                        adns_query *query_io,
-                        adns_answer **answer,
-                        void **context_r) {
+int
+adns__internal_check(adns_state ads,
+                     adns_query * query_io,
+                     adns_answer ** answer, void **context_r)
+{
   adns_query qu;
 
-  qu= *query_io;
-  if (!qu) {
-    if (ads->output.head) {
-      qu= ads->output.head;
-    } else if (ads->udpw.head || ads->tcpw.head) {
+  qu = *query_io;
+  if (!qu)
+  {
+    if (ads->output.head)
+    {
+      qu = ads->output.head;
+    }
+    else if (ads->udpw.head || ads->tcpw.head)
+    {
       return EAGAIN;
-    } else {
+    }
+    else
+    {
       return ESRCH;
     }
-  } else {
-    if (qu->id>=0) return EAGAIN;
   }
-  LIST_UNLINK(ads->output,qu);
-  *answer= qu->answer;
-  if (context_r) *context_r= qu->ctx.ext;
-  *query_io= qu;
+  else
+  {
+    if (qu->id >= 0)
+      return EAGAIN;
+  }
+  LIST_UNLINK(ads->output, qu);
+  *answer = qu->answer;
+  if (context_r)
+    *context_r = qu->ctx.ext;
+  *query_io = qu;
   MyFree(qu);
   return 0;
 }
 
 #if 0
-int adns_wait(adns_state ads,
-             adns_query *query_io,
-             adns_answer **answer_r,
-             void **context_r) {
+int
+adns_wait(adns_state ads,
+          adns_query * query_io, adns_answer ** answer_r, void **context_r)
+{
   int r, maxfd, rsel;
   fd_set readfds, writefds, exceptfds;
   struct timeval tvbuf, *tvp;
-  
-  adns__consistency(ads,*query_io,cc_entex);
-  for (;;) {
-    r= adns__internal_check(ads,query_io,answer_r,context_r);
-    if (r != EAGAIN) break;
-    maxfd= 0; tvp= 0;
-    FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds);
-    adns_beforeselect(ads,&maxfd,&readfds,&writefds,&exceptfds,&tvp,&tvbuf,0);
+
+  adns__consistency(ads, *query_io, cc_entex);
+  for (;;)
+  {
+    r = adns__internal_check(ads, query_io, answer_r, context_r);
+    if (r != EAGAIN)
+      break;
+    maxfd = 0;
+    tvp = 0;
+    FD_ZERO(&readfds);
+    FD_ZERO(&writefds);
+    FD_ZERO(&exceptfds);
+    adns_beforeselect(ads, &maxfd, &readfds, &writefds, &exceptfds, &tvp,
+                      &tvbuf, 0);
     assert(tvp);
-    rsel= select(maxfd,&readfds,&writefds,&exceptfds,tvp);
-    if (rsel==-1) {
-      if (errno == EINTR) {
-       if (ads->iflags & adns_if_eintr) { r= EINTR; break; }
-      } else {
-       adns__diag(ads,-1,0,"select failed in wait: %s",strerror(errno));
-       adns_globalsystemfailure(ads);
+    rsel = select(maxfd, &readfds, &writefds, &exceptfds, tvp);
+    if (rsel == -1)
+    {
+      if (errno == EINTR)
+      {
+        if (ads->iflags & adns_if_eintr)
+        {
+          r = EINTR;
+          break;
+        }
       }
-    } else {
+      else
+      {
+        adns__diag(ads, -1, 0, "select failed in wait: %s", strerror(errno));
+        adns_globalsystemfailure(ads);
+      }
+    }
+    else
+    {
       assert(rsel >= 0);
-      adns_afterselect(ads,maxfd,&readfds,&writefds,&exceptfds,0);
+      adns_afterselect(ads, maxfd, &readfds, &writefds, &exceptfds, 0);
     }
   }
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
   return r;
 }
 #endif
-int adns_check(adns_state ads,
-              adns_query *query_io,
-              adns_answer **answer_r,
-              void **context_r) {
+int
+adns_check(adns_state ads,
+           adns_query * query_io, adns_answer ** answer_r, void **context_r)
+{
   struct timeval now;
   int r;
-  
-  adns__consistency(ads,*query_io,cc_entex);
-  r= gettimeofday(&now,0);
-  if (!r) adns__autosys(ads,now);
 
-  r= adns__internal_check(ads,query_io,answer_r,context_r);
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, *query_io, cc_entex);
+  r = gettimeofday(&now, 0);
+  if (!r)
+    adns__autosys(ads, now);
+
+  r = adns__internal_check(ads, query_io, answer_r, context_r);
+  adns__consistency(ads, 0, cc_entex);
   return r;
 }
index 83f681967230deeed6fd6e2a8ad125af756c515c..2410db4cdccbd39080ffa94ca91ce8848ffa752f 100644 (file)
@@ -25,7 +25,7 @@
  *  along with this program; if not, write to the Free Software Foundation,
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  *
- * $Id: general.c,v 1.1 2002/01/04 09:10:46 a1kmm Exp $
+ * $Id: general.c,v 1.2 2002/04/27 02:48:46 a1kmm Exp $
  */
 
 #include "fileio.h"
 #define LOG_BUFSIZE 2000
 
 #if 0
-void adns__vdiag(adns_state ads, const char *pfx, adns_initflags prevent,
-                int serv, adns_query qu, const char *fmt, va_list al)
+void
+adns__vdiag(adns_state ads, const char *pfx, adns_initflags prevent,
+            int serv, adns_query qu, const char *fmt, va_list al)
 {
 
 /* Fix this to log to the ircd log interface */
 #if 0
   const char *bef, *aft;
   vbuf vb;
-  
-  vfprintf(ads->diagfile,fmt,al);
 
-  bef= " (";
-  aft= "\n";
+  vfprintf(ads->diagfile, fmt, al);
 
-  if (qu && qu->query_dgram) {
+  bef = " (";
+  aft = "\n";
+
+  if (qu && qu->query_dgram)
+  {
     adns__vbuf_init(&vb);
-    fprintf(ads->diagfile,"%sQNAME=%s, QTYPE=%s",
-           bef,
-           adns__diag_domain(qu->ads,-1,0, &vb,
-                             qu->query_dgram,qu->query_dglen,DNS_HDRSIZE),
-           qu->typei ? qu->typei->rrtname : "<unknown>");
+    fprintf(ads->diagfile, "%sQNAME=%s, QTYPE=%s",
+            bef,
+            adns__diag_domain(qu->ads, -1, 0, &vb,
+                              qu->query_dgram, qu->query_dglen,
+                              DNS_HDRSIZE),
+            qu->typei ? qu->typei->rrtname : "<unknown>");
     if (qu->typei && qu->typei->fmtname)
-      fprintf(ads->diagfile,"(%s)",qu->typei->fmtname);
-    bef=", "; aft=")\n";
+      fprintf(ads->diagfile, "(%s)", qu->typei->fmtname);
+    bef = ", ";
+    aft = ")\n";
     adns__vbuf_free(&vb);
   }
-  
-  if (serv>=0) {
-    fprintf(ads->diagfile,"%sNS=%s",bef,inetntoa((unsigned char *)&ads->servers[serv].addr));
-    bef=", "; aft=")\n";
+
+  if (serv >= 0)
+  {
+    fprintf(ads->diagfile, "%sNS=%s", bef,
+            inetntoa((unsigned char *)&ads->servers[serv].addr));
+    bef = ", ";
+    aft = ")\n";
   }
 
-  fputs(aft,ads->diagfile);
+  fputs(aft, ads->diagfile);
 #endif
 }
 #endif
 
-void adns__debug(adns_state ads, int serv, adns_query qu, const char *fmt, ...) {
-  char    buf[LOG_BUFSIZE];
+void
+adns__debug(adns_state ads, int serv, adns_query qu, const char *fmt, ...)
+{
+  char buf[LOG_BUFSIZE];
   va_list al;
 
-  va_start(al,fmt);
+  va_start(al, fmt);
   vsprintf(buf, fmt, al);
 #if 0
-  adns__vdiag(ads," debug",0,serv,qu,fmt,al);
+  adns__vdiag(ads, " debug", 0, serv, qu, fmt, al);
 #endif
   va_end(al);
 
@@ -100,28 +109,33 @@ void adns__debug(adns_state ads, int serv, adns_query qu, const char *fmt, ...)
   ilog(L_DEBUG, "%s", buf);
 }
 
-void adns__warn(adns_state ads, int serv, adns_query qu, const char *fmt, ...) {
-  char    buf[LOG_BUFSIZE];
+void
+adns__warn(adns_state ads, int serv, adns_query qu, const char *fmt, ...)
+{
+  char buf[LOG_BUFSIZE];
   va_list al;
 
-  va_start(al,fmt);
+  va_start(al, fmt);
   vsprintf(buf, fmt, al);
 #if 0
-  adns__vdiag(ads," warning",adns_if_noerrprint|adns_if_noserverwarn,serv,qu,fmt,al);
+  adns__vdiag(ads, " warning", adns_if_noerrprint | adns_if_noserverwarn,
+              serv, qu, fmt, al);
 #endif
   va_end(al);
 
   ilog(L_WARN, "%s", buf);
 }
 
-void adns__diag(adns_state ads, int serv, adns_query qu, const char *fmt, ...) {
-  char    buf[LOG_BUFSIZE];
+void
+adns__diag(adns_state ads, int serv, adns_query qu, const char *fmt, ...)
+{
+  char buf[LOG_BUFSIZE];
   va_list al;
 
-  va_start(al,fmt);
+  va_start(al, fmt);
   vsprintf(buf, fmt, al);
 #if 0
-  adns__vdiag(ads,"",adns_if_noerrprint,serv,qu,fmt,al);
+  adns__vdiag(ads, "", adns_if_noerrprint, serv, qu, fmt, al);
 #endif
   va_end(al);
 
@@ -130,107 +144,150 @@ void adns__diag(adns_state ads, int serv, adns_query qu, const char *fmt, ...) {
 
 /* vbuf functions */
 
-void adns__vbuf_init(vbuf *vb) {
-  vb->used= vb->avail= 0; vb->buf= 0;
+void
+adns__vbuf_init(vbuf * vb)
+{
+  vb->used = vb->avail = 0;
+  vb->buf = 0;
 }
 
-int adns__vbuf_ensure(vbuf *vb, int want) {
+int
+adns__vbuf_ensure(vbuf * vb, int want)
+{
   void *nb;
-  
-  if (vb->avail >= want) return 1;
-  nb= MyRealloc(vb->buf,want); if (!nb) return 0;
-  vb->buf= nb;
-  vb->avail= want;
+
+  if (vb->avail >= want)
+    return 1;
+  nb = MyRealloc(vb->buf, want);
+  if (!nb)
+    return 0;
+  vb->buf = nb;
+  vb->avail = want;
   return 1;
 }
-  
-void adns__vbuf_appendq(vbuf *vb, const byte *ddata, int len) {
-  memcpy(vb->buf+vb->used,ddata,len);
-  vb->used+= len;
+
+void
+adns__vbuf_appendq(vbuf * vb, const byte * ddata, int len)
+{
+  memcpy(vb->buf + vb->used, ddata, len);
+  vb->used += len;
 }
 
-int adns__vbuf_append(vbuf *vb, const byte *ddata, int len) {
+int
+adns__vbuf_append(vbuf * vb, const byte * ddata, int len)
+{
   int newlen;
   void *nb;
 
-  newlen= vb->used+len;
-  if (vb->avail < newlen) {
-    if (newlen<20) newlen= 20;
+  newlen = vb->used + len;
+  if (vb->avail < newlen)
+  {
+    if (newlen < 20)
+      newlen = 20;
     newlen <<= 1;
-    nb= MyRealloc(vb->buf,newlen);
-    if (!nb) { newlen= vb->used+len; nb= MyRealloc(vb->buf,newlen); }
-    if (!nb) return 0;
-    vb->buf= nb;
-    vb->avail= newlen;
+    nb = MyRealloc(vb->buf, newlen);
+    if (!nb)
+    {
+      newlen = vb->used + len;
+      nb = MyRealloc(vb->buf, newlen);
+    }
+    if (!nb)
+      return 0;
+    vb->buf = nb;
+    vb->avail = newlen;
   }
-  adns__vbuf_appendq(vb,ddata,len);
+  adns__vbuf_appendq(vb, ddata, len);
   return 1;
 }
 
-int adns__vbuf_appendstr(vbuf *vb, const char *ddata) {
+int
+adns__vbuf_appendstr(vbuf * vb, const char *ddata)
+{
   int l;
-  l= strlen(ddata);
-  return adns__vbuf_append(vb,(const byte *)ddata,l);
+  l = strlen(ddata);
+  return adns__vbuf_append(vb, (const byte *)ddata, l);
 }
 
-void adns__vbuf_free(vbuf *vb) {
+void
+adns__vbuf_free(vbuf * vb)
+{
   MyFree(vb->buf);
   adns__vbuf_init(vb);
 }
 
 /* Additional diagnostic functions */
 
-const char *adns__diag_domain(adns_state ads, int serv, adns_query qu,
-                             vbuf *vb, const byte *dgram, int dglen, int cbyte) {
+const char *
+adns__diag_domain(adns_state ads, int serv, adns_query qu,
+                  vbuf * vb, const byte * dgram, int dglen, int cbyte)
+{
   adns_status st;
 
-  st= adns__parse_domain(ads,serv,qu,vb, pdf_quoteok, dgram,dglen,&cbyte,dglen);
-  if (st == adns_s_nomemory) {
+  st =
+    adns__parse_domain(ads, serv, qu, vb, pdf_quoteok, dgram, dglen, &cbyte,
+                       dglen);
+  if (st == adns_s_nomemory)
+  {
     return "<cannot report domain... out of memory>";
   }
-  if (st) {
-    vb->used= 0;
-    if (!(adns__vbuf_appendstr(vb,"<bad format... ") &&
-         adns__vbuf_appendstr(vb,adns_strerror(st)) &&
-         adns__vbuf_appendstr(vb,">") &&
-         adns__vbuf_append(vb,(const byte *)"",1))) {
+  if (st)
+  {
+    vb->used = 0;
+    if (!(adns__vbuf_appendstr(vb, "<bad format... ") &&
+          adns__vbuf_appendstr(vb, adns_strerror(st)) &&
+          adns__vbuf_appendstr(vb, ">") &&
+          adns__vbuf_append(vb, (const byte *)"", 1)))
+    {
       return "<cannot report bad format... out of memory>";
     }
   }
-  if (!vb->used) {
-    adns__vbuf_appendstr(vb,"<truncated ...>");
-    adns__vbuf_append(vb,(const byte *)"",1);
+  if (!vb->used)
+  {
+    adns__vbuf_appendstr(vb, "<truncated ...>");
+    adns__vbuf_append(vb, (const byte *)"", 1);
   }
   return (const char *)vb->buf;
 }
 
-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) {
+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)
+{
   const typeinfo *typei;
   vbuf vb;
   adns_status st;
 
-  typei= adns__findtype(type);
-  if (!typei) return adns_s_unknownrrtype;
+  typei = adns__findtype(type);
+  if (!typei)
+    return adns_s_unknownrrtype;
+
+  if (rrtname_r)
+    *rrtname_r = typei->rrtname;
+  if (fmtname_r)
+    *fmtname_r = typei->fmtname;
+  if (len_r)
+    *len_r = typei->rrsz;
 
-  if (rrtname_r) *rrtname_r= typei->rrtname;
-  if (fmtname_r) *fmtname_r= typei->fmtname;
-  if (len_r) *len_r= typei->rrsz;
+  if (!datap)
+    return adns_s_ok;
 
-  if (!datap) return adns_s_ok;
-  
   adns__vbuf_init(&vb);
-  st= typei->convstring(&vb,datap);
-  if (st) goto x_freevb;
-  if (!adns__vbuf_append(&vb,(const byte *)"",1)) { st= adns_s_nomemory; goto x_freevb; }
-  assert(strlen((const char *)vb.buf) == vb.used-1);
-  *data_r= MyRealloc(vb.buf,vb.used);
-  if (!*data_r) *data_r= (char *)vb.buf;
+  st = typei->convstring(&vb, datap);
+  if (st)
+    goto x_freevb;
+  if (!adns__vbuf_append(&vb, (const byte *)"", 1))
+  {
+    st = adns_s_nomemory;
+    goto x_freevb;
+  }
+  assert(strlen((const char *)vb.buf) == vb.used - 1);
+  *data_r = MyRealloc(vb.buf, vb.used);
+  if (!*data_r)
+    *data_r = (char *)vb.buf;
   return adns_s_ok;
 
- x_freevb:
+x_freevb:
   adns__vbuf_free(&vb);
   return st;
 }
@@ -238,120 +295,135 @@ adns_status adns_rr_info(adns_rrtype type,
 
 #define SINFO(n,s) { adns_s_##n, #n, s }
 
-static const struct sinfo {
+static const struct sinfo
+{
   adns_status st;
   const char *abbrev;
   const char *string;
-} sinfos[]= {
-  SINFO(  ok,                  "OK"                                            ),
-
-  SINFO(  nomemory,            "Out of memory"                                 ),
-  SINFO(  unknownrrtype,       "Query not implemented in DNS library"          ),
-  SINFO(  systemfail,          "General resolver or system failure"            ),
-
-  SINFO(  timeout,             "DNS query timed out"                           ),
-  SINFO(  allservfail,         "All nameservers failed"                        ),
-  SINFO(  norecurse,           "Recursion denied by nameserver"                ),
-  SINFO(  invalidresponse,     "Nameserver sent bad response"                  ),
-  SINFO(  unknownformat,       "Nameserver used unknown format"                ),
-
-  SINFO(  rcodeservfail,       "Nameserver reports failure"                    ),
-  SINFO(  rcodeformaterror,    "Query not understood by nameserver"            ),
-  SINFO(  rcodenotimplemented, "Query not implemented by nameserver"           ),
-  SINFO(  rcoderefused,        "Query refused by nameserver"                   ),
-  SINFO(  rcodeunknown,        "Nameserver sent unknown response code"         ),
-  
-  SINFO(  inconsistent,        "Inconsistent resource records in DNS"          ),
-  SINFO(  prohibitedcname,     "DNS alias found where canonical name wanted"   ),
-  SINFO(  answerdomaininvalid, "Found syntactically invalid domain name"       ),
-  SINFO(  answerdomaintoolong, "Found overly-long domain name"                 ),
-  SINFO(  invaliddata,         "Found invalid DNS data"                        ),
-
-  SINFO(  querydomainwrong,    "Domain invalid for particular DNS query type"  ),
-  SINFO(  querydomaininvalid,  "Domain name is syntactically invalid"          ),
-  SINFO(  querydomaintoolong,  "Domain name or component is too long"          ),
-
-  SINFO(  nxdomain,            "No such domain"                                ),
-  SINFO(  nodata,              "No such data"                                  )
-};
-
-static int si_compar(const void *key, const void *elem) {
-  const adns_status *st= key;
-  const struct sinfo *si= elem;
+}
+sinfos[] =
+{
+SINFO(ok, "OK"),
+    SINFO(nomemory, "Out of memory"),
+    SINFO(unknownrrtype, "Query not implemented in DNS library"),
+    SINFO(systemfail, "General resolver or system failure"),
+    SINFO(timeout, "DNS query timed out"),
+    SINFO(allservfail, "All nameservers failed"),
+    SINFO(norecurse, "Recursion denied by nameserver"),
+    SINFO(invalidresponse, "Nameserver sent bad response"),
+    SINFO(unknownformat, "Nameserver used unknown format"),
+    SINFO(rcodeservfail, "Nameserver reports failure"),
+    SINFO(rcodeformaterror, "Query not understood by nameserver"),
+    SINFO(rcodenotimplemented, "Query not implemented by nameserver"),
+    SINFO(rcoderefused, "Query refused by nameserver"),
+    SINFO(rcodeunknown, "Nameserver sent unknown response code"),
+    SINFO(inconsistent, "Inconsistent resource records in DNS"),
+    SINFO(prohibitedcname, "DNS alias found where canonical name wanted"),
+    SINFO(answerdomaininvalid, "Found syntactically invalid domain name"),
+    SINFO(answerdomaintoolong, "Found overly-long domain name"),
+    SINFO(invaliddata, "Found invalid DNS data"),
+    SINFO(querydomainwrong,
+            "Domain invalid for particular DNS query type"),
+    SINFO(querydomaininvalid, "Domain name is syntactically invalid"),
+    SINFO(querydomaintoolong, "Domain name or component is too long"),
+    SINFO(nxdomain, "No such domain"), SINFO(nodata, "No such data")};
+
+static int
+si_compar(const void *key, const void *elem)
+{
+  const adns_status *st = key;
+  const struct sinfo *si = elem;
 
   return *st < si->st ? -1 : *st > si->st ? 1 : 0;
 }
 
-static const struct sinfo *findsinfo(adns_status st) {
-  return bsearch(&st,sinfos,sizeof(sinfos)/sizeof(*sinfos),sizeof(*sinfos),si_compar);
+static const struct sinfo *
+findsinfo(adns_status st)
+{
+  return bsearch(&st, sinfos, sizeof(sinfos) / sizeof(*sinfos),
+                 sizeof(*sinfos), si_compar);
 }
 
-const char *adns_strerror(adns_status st) {
+const char *
+adns_strerror(adns_status st)
+{
   const struct sinfo *si;
 
-  si= findsinfo(st);
+  si = findsinfo(st);
   return si->string;
 }
 
-const char *adns_errabbrev(adns_status st) {
+const char *
+adns_errabbrev(adns_status st)
+{
   const struct sinfo *si;
 
-  si= findsinfo(st);
+  si = findsinfo(st);
   return si->abbrev;
 }
 
 
 #define STINFO(max) { adns_s_max_##max, #max }
 
-static const struct stinfo {
+static const struct stinfo
+{
   adns_status stmax;
   const char *abbrev;
-} stinfos[]= {
-  { adns_s_ok, "ok" },
-  STINFO(  localfail   ),
-  STINFO(  remotefail  ),
-  STINFO(  tempfail    ),
-  STINFO(  misconfig   ),
-  STINFO(  misquery    ),
-  STINFO(  permfail    )
-};
-
-static int sti_compar(const void *key, const void *elem) {
-  const adns_status *st= key;
-  const struct stinfo *sti= elem;
+}
+stinfos[] =
+{
+  {
+  adns_s_ok, "ok"}
+, STINFO(localfail),
+    STINFO(remotefail),
+    STINFO(tempfail), STINFO(misconfig), STINFO(misquery), STINFO(permfail)};
+
+static int
+sti_compar(const void *key, const void *elem)
+{
+  const adns_status *st = key;
+  const struct stinfo *sti = elem;
 
   adns_status here, min, max;
 
-  here= *st;
-  min= (sti==stinfos) ? 0 : sti[-1].stmax+1;
-  max= sti->stmax;
-  
-  return here < min  ? -1 : here > max ? 1 : 0;
+  here = *st;
+  min = (sti == stinfos) ? 0 : sti[-1].stmax + 1;
+  max = sti->stmax;
+
+  return here < min ? -1 : here > max ? 1 : 0;
 }
 
-const char *adns_errtypeabbrev(adns_status st) {
+const char *
+adns_errtypeabbrev(adns_status st)
+{
   const struct stinfo *sti;
 
-  sti= bsearch(&st,stinfos,sizeof(stinfos)/sizeof(*stinfos),sizeof(*stinfos),sti_compar);
+  sti =
+    bsearch(&st, stinfos, sizeof(stinfos) / sizeof(*stinfos),
+            sizeof(*stinfos), sti_compar);
   return sti->abbrev;
 }
 
 
-void adns__isort(void *array, int nobjs, int sz, void *tempbuf,
-                int (*needswap)(void *context, const void *a, const void *b),
-                void *context) {
-  byte *ddata= array;
+void
+adns__isort(void *array, int nobjs, int sz, void *tempbuf,
+            int (*needswap) (void *context, const void *a, const void *b),
+            void *context)
+{
+  byte *ddata = array;
   int i, place;
 
-  for (i=0; i<nobjs; i++) {
-    for (place= i;
-        place>0 && needswap(context, ddata + (place-1)*sz, ddata + i*sz);
-        place--);
-    if (place != i) {
-      memcpy(tempbuf, ddata + i*sz, sz);
-      memmove(ddata + (place+1)*sz, ddata + place*sz, (i-place)*sz);
-      memcpy(ddata + place*sz, tempbuf, sz);
+  for (i = 0; i < nobjs; i++)
+  {
+    for (place = i;
+         place > 0
+         && needswap(context, ddata + (place - 1) * sz, ddata + i * sz);
+         place--);
+    if (place != i)
+    {
+      memcpy(tempbuf, ddata + i * sz, sz);
+      memmove(ddata + (place + 1) * sz, ddata + place * sz, (i - place) * sz);
+      memcpy(ddata + place * sz, tempbuf, sz);
     }
   }
 }
-
index 5a483988b5ad03512acac719295d7bde02c4b3c6..3409b7ac4e44c8c5f700c8c40ff4631ee6d12078 100644 (file)
  *  along with this program; if not, write to the Free Software Foundation,
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  *
- * $Id: parse.c,v 1.1 2002/01/04 09:10:50 a1kmm Exp $
+ * $Id: parse.c,v 1.2 2002/04/27 02:48:46 a1kmm Exp $
  */
 
 #include "fileio.h"
 #include "internal.h"
 
-int vbuf__append_quoted1035(vbuf *vb, const byte *buf, int len) {
+int
+vbuf__append_quoted1035(vbuf * vb, const byte * buf, int len)
+{
   byte qbuf[10];
   int i, ch;
-  
-  while (len) {
-    qbuf[0]= 0;
-    for (i=0; i<len; i++) {
-      ch= buf[i];
-      if (ch <= ' ' || ch >= 127) {
-       ircsprintf((char *)qbuf,"\\%03o",ch);
-       break;
-      } else if (!ctype_domainunquoted(ch)) {
-       ircsprintf((char *)qbuf,"\\%c",ch);
-       break;
+
+  while (len)
+  {
+    qbuf[0] = 0;
+    for (i = 0; i < len; i++)
+    {
+      ch = buf[i];
+      if (ch <= ' ' || ch >= 127)
+      {
+        ircsprintf((char *)qbuf, "\\%03o", ch);
+        break;
+      }
+      else if (!ctype_domainunquoted(ch))
+      {
+        ircsprintf((char *)qbuf, "\\%c", ch);
+        break;
       }
     }
-    if (!adns__vbuf_append(vb,buf,i) || !adns__vbuf_append(vb,qbuf,strlen((const char *)qbuf)))
+    if (!adns__vbuf_append(vb, buf, i)
+        || !adns__vbuf_append(vb, qbuf, strlen((const char *)qbuf)))
       return 0;
-    if (i<len) i++;
-    buf+= i;
-    len-= i;
+    if (i < len)
+      i++;
+    buf += i;
+    len -= i;
   }
   return 1;
 }
 
-void adns__findlabel_start(findlabel_state *fls, adns_state ads,
-                          int serv, adns_query qu,
-                          const byte *dgram, int dglen, int max,
-                          int dmbegin, int *dmend_rlater) {
-  fls->ads= ads;
-  fls->qu= qu;
-  fls->serv= serv;
-  fls->dgram= dgram;
-  fls->dglen= dglen;
-  fls->max= max;
-  fls->cbyte= dmbegin;
-  fls->namelen= 0;
-  fls->dmend_r= dmend_rlater;
+void
+adns__findlabel_start(findlabel_state * fls, adns_state ads,
+                      int serv, adns_query qu,
+                      const byte * dgram, int dglen, int max,
+                      int dmbegin, int *dmend_rlater)
+{
+  fls->ads = ads;
+  fls->qu = qu;
+  fls->serv = serv;
+  fls->dgram = dgram;
+  fls->dglen = dglen;
+  fls->max = max;
+  fls->cbyte = dmbegin;
+  fls->namelen = 0;
+  fls->dmend_r = dmend_rlater;
 }
 
-adns_status adns__findlabel_next(findlabel_state *fls,
-                                int *lablen_r, int *labstart_r) {
+adns_status
+adns__findlabel_next(findlabel_state * fls, int *lablen_r, int *labstart_r)
+{
   int lablen, jumpto;
   const char *dgram;
 
-  dgram= (const char *)fls->dgram;
-  for (;;) {
-    if (fls->cbyte >= fls->dglen) goto x_truncated;
-    if (fls->cbyte >= fls->max) goto x_badresponse;
-    GET_B(fls->cbyte,lablen);
-    if (!(lablen & 0x0c0)) break;
-    if ((lablen & 0x0c0) != 0x0c0) return adns_s_unknownformat;
-    if (fls->cbyte >= fls->dglen) goto x_truncated;
-    if (fls->cbyte >= fls->max) goto x_badresponse;
-    GET_B(fls->cbyte,jumpto);
-    jumpto |= (lablen&0x3f)<<8;
-    if (fls->dmend_r) *(fls->dmend_r)= fls->cbyte;
-    fls->cbyte= jumpto;
-    fls->dmend_r= 0; fls->max= fls->dglen+1;
+  dgram = (const char *)fls->dgram;
+  for (;;)
+  {
+    if (fls->cbyte >= fls->dglen)
+      goto x_truncated;
+    if (fls->cbyte >= fls->max)
+      goto x_badresponse;
+    GET_B(fls->cbyte, lablen);
+    if (!(lablen & 0x0c0))
+      break;
+    if ((lablen & 0x0c0) != 0x0c0)
+      return adns_s_unknownformat;
+    if (fls->cbyte >= fls->dglen)
+      goto x_truncated;
+    if (fls->cbyte >= fls->max)
+      goto x_badresponse;
+    GET_B(fls->cbyte, jumpto);
+    jumpto |= (lablen & 0x3f) << 8;
+    if (fls->dmend_r)
+      *(fls->dmend_r) = fls->cbyte;
+    fls->cbyte = jumpto;
+    fls->dmend_r = 0;
+    fls->max = fls->dglen + 1;
+  }
+  if (labstart_r)
+    *labstart_r = fls->cbyte;
+  if (lablen)
+  {
+    if (fls->namelen)
+      fls->namelen++;
+    fls->namelen += lablen;
+    if (fls->namelen > DNS_MAXDOMAIN)
+      return adns_s_answerdomaintoolong;
+    fls->cbyte += lablen;
+    if (fls->cbyte > fls->dglen)
+      goto x_truncated;
+    if (fls->cbyte > fls->max)
+      goto x_badresponse;
   }
-  if (labstart_r) *labstart_r= fls->cbyte;
-  if (lablen) {
-    if (fls->namelen) fls->namelen++;
-    fls->namelen+= lablen;
-    if (fls->namelen > DNS_MAXDOMAIN) return adns_s_answerdomaintoolong;
-    fls->cbyte+= lablen;
-    if (fls->cbyte > fls->dglen) goto x_truncated;
-    if (fls->cbyte > fls->max) goto x_badresponse;
-  } else {
-    if (fls->dmend_r) *(fls->dmend_r)= fls->cbyte;
+  else
+  {
+    if (fls->dmend_r)
+      *(fls->dmend_r) = fls->cbyte;
   }
-  *lablen_r= lablen;
+  *lablen_r = lablen;
   return adns_s_ok;
 
- x_truncated:
-  *lablen_r= -1;
+x_truncated:
+  *lablen_r = -1;
   return adns_s_ok;
 
- x_badresponse: 
-  adns__diag(fls->ads,fls->serv,fls->qu,"label in domain runs beyond end of domain");
+x_badresponse:
+  adns__diag(fls->ads, fls->serv, fls->qu,
+             "label in domain runs beyond end of domain");
   return adns_s_invalidresponse;
 }
 
-adns_status adns__parse_domain(adns_state ads, int serv, adns_query qu,
-                              vbuf *vb, parsedomain_flags flags,
-                              const byte *dgram, int dglen, int *cbyte_io, int max) {
+adns_status
+adns__parse_domain(adns_state ads, int serv, adns_query qu,
+                   vbuf * vb, parsedomain_flags flags,
+                   const byte * dgram, int dglen, int *cbyte_io, int max)
+{
   findlabel_state fls;
-  
-  adns__findlabel_start(&fls,ads, serv,qu, dgram,dglen,max, *cbyte_io,cbyte_io);
-  vb->used= 0;
-  return adns__parse_domain_more(&fls,ads,qu, vb,flags,dgram);
+
+  adns__findlabel_start(&fls, ads, serv, qu, dgram, dglen, max, *cbyte_io,
+                        cbyte_io);
+  vb->used = 0;
+  return adns__parse_domain_more(&fls, ads, qu, vb, flags, dgram);
 }
 
-adns_status adns__parse_domain_more(findlabel_state *fls, adns_state ads,
-                                   adns_query qu, vbuf *vb, parsedomain_flags flags,
-                                   const byte *dgram) {
+adns_status
+adns__parse_domain_more(findlabel_state * fls, adns_state ads,
+                        adns_query qu, vbuf * vb, parsedomain_flags flags,
+                        const byte * dgram)
+{
   int lablen, labstart, i, ch, first;
   adns_status st;
 
-  first= 1;
-  for (;;) {
-    st= adns__findlabel_next(fls,&lablen,&labstart);
-    if (st) return st;
-    if (lablen<0) { vb->used=0; return adns_s_ok; }
-    if (!lablen) break;
-    if (first) {
-      first= 0;
-    } else {
-      if (!adns__vbuf_append(vb,(const byte *)".",1)) return adns_s_nomemory;
+  first = 1;
+  for (;;)
+  {
+    st = adns__findlabel_next(fls, &lablen, &labstart);
+    if (st)
+      return st;
+    if (lablen < 0)
+    {
+      vb->used = 0;
+      return adns_s_ok;
+    }
+    if (!lablen)
+      break;
+    if (first)
+    {
+      first = 0;
     }
-    if (flags & pdf_quoteok) {
-      if (!vbuf__append_quoted1035(vb,dgram+labstart,lablen))
-       return adns_s_nomemory;
-    } else {
-      ch= dgram[labstart];
-      if (!ctype_alpha(ch) && !ctype_digit(ch)) return adns_s_answerdomaininvalid;
-      for (i= labstart+1; i<labstart+lablen; i++) {
-       ch= dgram[i];
-       if (ch != '-' && !ctype_alpha(ch) && !ctype_digit(ch))
-         return adns_s_answerdomaininvalid;
+    else
+    {
+      if (!adns__vbuf_append(vb, (const byte *)".", 1))
+        return adns_s_nomemory;
+    }
+    if (flags & pdf_quoteok)
+    {
+      if (!vbuf__append_quoted1035(vb, dgram + labstart, lablen))
+        return adns_s_nomemory;
+    }
+    else
+    {
+      ch = dgram[labstart];
+      if (!ctype_alpha(ch) && !ctype_digit(ch))
+        return adns_s_answerdomaininvalid;
+      for (i = labstart + 1; i < labstart + lablen; i++)
+      {
+        ch = dgram[i];
+        if (ch != '-' && !ctype_alpha(ch) && !ctype_digit(ch))
+          return adns_s_answerdomaininvalid;
       }
-      if (!adns__vbuf_append(vb,dgram+labstart,lablen))
-       return adns_s_nomemory;
+      if (!adns__vbuf_append(vb, dgram + labstart, lablen))
+        return adns_s_nomemory;
     }
   }
-  if (!adns__vbuf_append(vb,(const byte *)"",1)) return adns_s_nomemory;
+  if (!adns__vbuf_append(vb, (const byte *)"", 1))
+    return adns_s_nomemory;
   return adns_s_ok;
 }
-       
-adns_status adns__findrr_anychk(adns_query qu, int serv,
-                               const byte *dgram, int dglen, int *cbyte_io,
-                               int *type_r, int *class_r, unsigned long *ttl_r,
-                               int *rdlen_r, int *rdstart_r,
-                               const byte *eo_dgram, int eo_dglen, int eo_cbyte,
-                               int *eo_matched_r) {
+
+adns_status
+adns__findrr_anychk(adns_query qu, int serv,
+                    const byte * dgram, int dglen, int *cbyte_io,
+                    int *type_r, int *class_r, unsigned long *ttl_r,
+                    int *rdlen_r, int *rdstart_r,
+                    const byte * eo_dgram, int eo_dglen, int eo_cbyte,
+                    int *eo_matched_r)
+{
   findlabel_state fls, eo_fls;
   int cbyte;
-  
+
   int tmp, rdlen, mismatch;
   unsigned long ttl;
   int lablen, labstart, ch;
   int eo_lablen, eo_labstart, eo_ch;
   adns_status st;
 
-  cbyte= *cbyte_io;
+  cbyte = *cbyte_io;
 
-  adns__findlabel_start(&fls,qu->ads, serv,qu, dgram,dglen,dglen,cbyte,&cbyte);
-  if (eo_dgram) {
-    adns__findlabel_start(&eo_fls,qu->ads, -1,0, eo_dgram,eo_dglen,eo_dglen,eo_cbyte,0);
-    mismatch= 0;
-  } else {
-    mismatch= 1;
+  adns__findlabel_start(&fls, qu->ads, serv, qu, dgram, dglen, dglen, cbyte,
+                        &cbyte);
+  if (eo_dgram)
+  {
+    adns__findlabel_start(&eo_fls, qu->ads, -1, 0, eo_dgram, eo_dglen,
+                          eo_dglen, eo_cbyte, 0);
+    mismatch = 0;
   }
-  
-  for (;;) {
-    st= adns__findlabel_next(&fls,&lablen,&labstart);
-    if (st) return st;
-    if (lablen<0) goto x_truncated;
-
-    if (!mismatch) {
-      st= adns__findlabel_next(&eo_fls,&eo_lablen,&eo_labstart);
-      assert(!st); assert(eo_lablen>=0);
-      if (lablen != eo_lablen) mismatch= 1;
-      while (!mismatch && eo_lablen-- > 0) {
-       ch= dgram[labstart++]; if (ctype_alpha(ch)) ch &= ~32;
-       eo_ch= eo_dgram[eo_labstart++]; if (ctype_alpha(eo_ch)) eo_ch &= ~32;
-       if (ch != eo_ch) mismatch= 1;
+  else
+  {
+    mismatch = 1;
+  }
+
+  for (;;)
+  {
+    st = adns__findlabel_next(&fls, &lablen, &labstart);
+    if (st)
+      return st;
+    if (lablen < 0)
+      goto x_truncated;
+
+    if (!mismatch)
+    {
+      st = adns__findlabel_next(&eo_fls, &eo_lablen, &eo_labstart);
+      assert(!st);
+      assert(eo_lablen >= 0);
+      if (lablen != eo_lablen)
+        mismatch = 1;
+      while (!mismatch && eo_lablen-- > 0)
+      {
+        ch = dgram[labstart++];
+        if (ctype_alpha(ch))
+          ch &= ~32;
+        eo_ch = eo_dgram[eo_labstart++];
+        if (ctype_alpha(eo_ch))
+          eo_ch &= ~32;
+        if (ch != eo_ch)
+          mismatch = 1;
       }
     }
-    if (!lablen) break;
+    if (!lablen)
+      break;
   }
-  if (eo_matched_r) *eo_matched_r= !mismatch;
-   
-  if (cbyte+10>dglen) goto x_truncated;
-  GET_W(cbyte,tmp); *type_r= tmp;
-  GET_W(cbyte,tmp); *class_r= tmp;
-
-  GET_L(cbyte,ttl);
-  if (ttl > MAXTTLBELIEVE) ttl= MAXTTLBELIEVE;
-  *ttl_r= ttl;
-  
-  GET_W(cbyte,rdlen); if (rdlen_r) *rdlen_r= rdlen;
-  if (rdstart_r) *rdstart_r= cbyte;
-  cbyte+= rdlen;
-  if (cbyte>dglen) goto x_truncated;
-  *cbyte_io= cbyte;
+  if (eo_matched_r)
+    *eo_matched_r = !mismatch;
+
+  if (cbyte + 10 > dglen)
+    goto x_truncated;
+  GET_W(cbyte, tmp);
+  *type_r = tmp;
+  GET_W(cbyte, tmp);
+  *class_r = tmp;
+
+  GET_L(cbyte, ttl);
+  if (ttl > MAXTTLBELIEVE)
+    ttl = MAXTTLBELIEVE;
+  *ttl_r = ttl;
+
+  GET_W(cbyte, rdlen);
+  if (rdlen_r)
+    *rdlen_r = rdlen;
+  if (rdstart_r)
+    *rdstart_r = cbyte;
+  cbyte += rdlen;
+  if (cbyte > dglen)
+    goto x_truncated;
+  *cbyte_io = cbyte;
   return adns_s_ok;
 
- x_truncated:
-  *type_r= -1;
+x_truncated:
+  *type_r = -1;
   return 0;
 }
 
-adns_status adns__findrr(adns_query qu, int serv,
-                        const byte *dgram, int dglen, int *cbyte_io,
-                        int *type_r, int *class_r, unsigned long *ttl_r,
-                        int *rdlen_r, int *rdstart_r,
-                        int *ownermatchedquery_r) {
-  if (!ownermatchedquery_r) {
-    return adns__findrr_anychk(qu,serv,
-                              dgram,dglen,cbyte_io,
-                              type_r,class_r,ttl_r,rdlen_r,rdstart_r,
-                              0,0,0, 0);
-  } else if (!qu->cname_dgram) {
-    return adns__findrr_anychk(qu,serv,
-                              dgram,dglen,cbyte_io,
-                              type_r,class_r,ttl_r,rdlen_r,rdstart_r,
-                              qu->query_dgram,qu->query_dglen,DNS_HDRSIZE,
-                              ownermatchedquery_r);
-  } else {
-    return adns__findrr_anychk(qu,serv,
-                              dgram,dglen,cbyte_io,
-                              type_r,class_r,ttl_r,rdlen_r,rdstart_r,
-                              qu->cname_dgram,qu->cname_dglen,qu->cname_begin,
-                              ownermatchedquery_r);
+adns_status
+adns__findrr(adns_query qu, int serv,
+             const byte * dgram, int dglen, int *cbyte_io,
+             int *type_r, int *class_r, unsigned long *ttl_r,
+             int *rdlen_r, int *rdstart_r, int *ownermatchedquery_r)
+{
+  if (!ownermatchedquery_r)
+  {
+    return adns__findrr_anychk(qu, serv,
+                               dgram, dglen, cbyte_io,
+                               type_r, class_r, ttl_r, rdlen_r, rdstart_r,
+                               0, 0, 0, 0);
+  }
+  else if (!qu->cname_dgram)
+  {
+    return adns__findrr_anychk(qu, serv,
+                               dgram, dglen, cbyte_io,
+                               type_r, class_r, ttl_r, rdlen_r, rdstart_r,
+                               qu->query_dgram, qu->query_dglen,
+                               DNS_HDRSIZE, ownermatchedquery_r);
+  }
+  else
+  {
+    return adns__findrr_anychk(qu, serv,
+                               dgram, dglen, cbyte_io,
+                               type_r, class_r, ttl_r, rdlen_r, rdstart_r,
+                               qu->cname_dgram, qu->cname_dglen,
+                               qu->cname_begin, ownermatchedquery_r);
   }
 }
index cdba9948af81cb86e5d385be11de200f3b4c2000..0e1915a737217c029a26edd6f605d9468b711922 100644 (file)
@@ -26,7 +26,7 @@
  *  along with this program; if not, write to the Free Software Foundation,
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  *
- * $Id: query.c,v 1.1 2002/01/04 09:10:50 a1kmm Exp $
+ * $Id: query.c,v 1.2 2002/04/27 02:48:46 a1kmm Exp $
  */
 
 #include "memory.h"
 
 #include <sys/time.h>
 
-static adns_query query_alloc(adns_state ads, const typeinfo *typei,
-                             adns_queryflags flags, struct timeval now) {
+static adns_query
+query_alloc(adns_state ads, const typeinfo * typei,
+            adns_queryflags flags, struct timeval now)
+{
   /* Allocate a virgin query and return it. */
   adns_query qu;
-  
-  qu= MyMalloc(sizeof(*qu)); 
-  qu->answer= MyMalloc(sizeof(*qu->answer)); 
-  
-  qu->ads= ads;
-  qu->state= query_tosend;
-  qu->back= qu->next= qu->parent= 0;
+
+  qu = MyMalloc(sizeof(*qu));
+  qu->answer = MyMalloc(sizeof(*qu->answer));
+
+  qu->ads = ads;
+  qu->state = query_tosend;
+  qu->back = qu->next = qu->parent = 0;
   ADNS_LIST_INIT(qu->children);
   LINK_INIT(qu->siblings);
   ADNS_LIST_INIT(qu->allocations);
-  qu->interim_allocd= 0;
-  qu->preserved_allocd= 0;
-  qu->final_allocspace= 0;
+  qu->interim_allocd = 0;
+  qu->preserved_allocd = 0;
+  qu->final_allocspace = 0;
 
-  qu->typei= typei;
-  qu->query_dgram= 0;
-  qu->query_dglen= 0;
+  qu->typei = typei;
+  qu->query_dgram = 0;
+  qu->query_dglen = 0;
   adns__vbuf_init(&qu->vb);
 
-  qu->cname_dgram= 0;
-  qu->cname_dglen= qu->cname_begin= 0;
+  qu->cname_dgram = 0;
+  qu->cname_dglen = qu->cname_begin = 0;
 
   adns__vbuf_init(&qu->search_vb);
-  qu->search_origlen= qu->search_pos= qu->search_doneabs= 0;
+  qu->search_origlen = qu->search_pos = qu->search_doneabs = 0;
 
-  qu->id= -2; /* will be overwritten with real id before we leave adns */
-  qu->flags= flags;
-  qu->retries= 0;
-  qu->udpnextserver= 0;
-  qu->udpsent= 0;
+  qu->id = -2;                  /* will be overwritten with real id before we leave adns */
+  qu->flags = flags;
+  qu->retries = 0;
+  qu->udpnextserver = 0;
+  qu->udpsent = 0;
   timerclear(&qu->timeout);
-  qu->expires= now.tv_sec + MAXTTLBELIEVE;
+  qu->expires = now.tv_sec + MAXTTLBELIEVE;
 
-  memset(&qu->ctx,0,sizeof(qu->ctx));
+  memset(&qu->ctx, 0, sizeof(qu->ctx));
 
-  qu->answer->status= adns_s_ok;
-  qu->answer->cname= qu->answer->owner= 0;
-  qu->answer->type= typei->type;
-  qu->answer->expires= -1;
-  qu->answer->nrrs= 0;
-  qu->answer->rrs.untyped= 0;
-  qu->answer->rrsz= typei->rrsz;
+  qu->answer->status = adns_s_ok;
+  qu->answer->cname = qu->answer->owner = 0;
+  qu->answer->type = typei->type;
+  qu->answer->expires = -1;
+  qu->answer->nrrs = 0;
+  qu->answer->rrs.untyped = 0;
+  qu->answer->rrsz = typei->rrsz;
 
   return qu;
 }
 
-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 void
+query_submit(adns_state ads, adns_query qu,
+             const typeinfo * typei, vbuf * qumsg_vb, int id,
+             adns_queryflags flags, struct timeval now)
+{
   /* Fills in the query message in for a previously-allocated query,
    * and submits it.  Cannot fail.  Takes over the memory for qumsg_vb.
    */
 
-  qu->vb= *qumsg_vb;
+  qu->vb = *qumsg_vb;
   adns__vbuf_init(qumsg_vb);
 
-  qu->query_dgram= MyMalloc(qu->vb.used);
-  
-  qu->id= id;
-  qu->query_dglen= qu->vb.used;
-  memcpy(qu->query_dgram,qu->vb.buf,qu->vb.used);
-  
-  adns__query_send(qu,now);
+  qu->query_dgram = MyMalloc(qu->vb.used);
+
+  qu->id = id;
+  qu->query_dglen = qu->vb.used;
+  memcpy(qu->query_dgram, qu->vb.buf, qu->vb.used);
+
+  adns__query_send(qu, 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) {
+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)
+{
   adns_query qu;
 
-  qu= query_alloc(ads,typei,flags,now);
-  if (!qu) { adns__vbuf_free(qumsg_vb); return adns_s_nomemory; }
-  *query_r= qu;
+  qu = query_alloc(ads, typei, flags, now);
+  if (!qu)
+  {
+    adns__vbuf_free(qumsg_vb);
+    return adns_s_nomemory;
+  }
+  *query_r = qu;
+
+  memcpy(&qu->ctx, ctx, sizeof(qu->ctx));
+  query_submit(ads, qu, typei, qumsg_vb, id, flags, now);
 
-  memcpy(&qu->ctx,ctx,sizeof(qu->ctx));
-  query_submit(ads,qu, typei,qumsg_vb,id,flags,now);
-  
   return adns_s_ok;
 }
 
-static void query_simple(adns_state ads, adns_query qu,
-                        const byte *owner, int ol,
-                        const typeinfo *typei, adns_queryflags flags,
-                        struct timeval now) {
+static void
+query_simple(adns_state ads, adns_query qu,
+             const byte * owner, int ol,
+             const typeinfo * typei, adns_queryflags flags,
+             struct timeval now)
+{
   vbuf vb_new;
   int id;
   adns_status status;
 
-  status= adns__mkquery(ads,&qu->vb,&id, (const char *)owner,ol, typei,flags);
-  if (status) {
-    if (status == adns_s_querydomaintoolong && (flags & adns_qf_search)) {
-      adns__search_next(ads,qu,now);
+  status =
+    adns__mkquery(ads, &qu->vb, &id, (const char *)owner, ol, typei, flags);
+  if (status)
+  {
+    if (status == adns_s_querydomaintoolong && (flags & adns_qf_search))
+    {
+      adns__search_next(ads, qu, now);
       return;
-    } else {
-      adns__query_fail(qu,status);
+    }
+    else
+    {
+      adns__query_fail(qu, status);
       return;
     }
   }
 
-  vb_new= qu->vb;
+  vb_new = qu->vb;
   adns__vbuf_init(&qu->vb);
-  query_submit(ads,qu, typei,&vb_new,id, flags,now);
+  query_submit(ads, qu, typei, &vb_new, id, flags, now);
 }
 
-void adns__search_next(adns_state ads, adns_query qu, struct timeval now) {
+void
+adns__search_next(adns_state ads, adns_query qu, struct timeval now)
+{
   const char *nextentry;
   adns_status status;
-  
-  if (qu->search_doneabs<0) {
-    nextentry= 0;
-    qu->search_doneabs= 1;
-  } else {
-    if (qu->search_pos >= ads->nsearchlist) {
-      if (qu->search_doneabs) {
-       status= adns_s_nxdomain; 
-       goto x_fail;
-      } else {
-       nextentry= 0;
-       qu->search_doneabs= 1;
+
+  if (qu->search_doneabs < 0)
+  {
+    nextentry = 0;
+    qu->search_doneabs = 1;
+  }
+  else
+  {
+    if (qu->search_pos >= ads->nsearchlist)
+    {
+      if (qu->search_doneabs)
+      {
+        status = adns_s_nxdomain;
+        goto x_fail;
       }
-    } else {
-      nextentry= ads->searchlist[qu->search_pos++];
+      else
+      {
+        nextentry = 0;
+        qu->search_doneabs = 1;
+      }
+    }
+    else
+    {
+      nextentry = ads->searchlist[qu->search_pos++];
     }
   }
 
-  qu->search_vb.used= qu->search_origlen;
-  if (nextentry) {
-    if (!adns__vbuf_append(&qu->search_vb,(const byte *)".",1) ||
-       !adns__vbuf_appendstr(&qu->search_vb,nextentry)) {
-      status= adns_s_nomemory; goto x_fail;
+  qu->search_vb.used = qu->search_origlen;
+  if (nextentry)
+  {
+    if (!adns__vbuf_append(&qu->search_vb, (const byte *)".", 1) ||
+        !adns__vbuf_appendstr(&qu->search_vb, nextentry))
+    {
+      status = adns_s_nomemory;
+      goto x_fail;
     }
   }
 
   MyFree(qu->query_dgram);
-  qu->query_dgram= 0; qu->query_dglen= 0;
+  qu->query_dgram = 0;
+  qu->query_dglen = 0;
 
-  query_simple(ads,qu, qu->search_vb.buf, qu->search_vb.used, qu->typei, qu->flags, now);
+  query_simple(ads, qu, qu->search_vb.buf, qu->search_vb.used, qu->typei,
+               qu->flags, now);
   return;
-  
+
 x_fail:
-  adns__query_fail(qu,status);
+  adns__query_fail(qu, status);
 }
 
-static int save_owner(adns_query qu, const char *owner, int ol) {
+static int
+save_owner(adns_query qu, const char *owner, int ol)
+{
   /* Returns 1 if OK, otherwise there was no memory. */
   adns_answer *ans;
 
-  ans= qu->answer;
+  ans = qu->answer;
   assert(!ans->owner);
 
-  ans->owner= adns__alloc_preserved(qu,ol+1);  if (!ans->owner) return 0;
+  ans->owner = adns__alloc_preserved(qu, ol + 1);
+  if (!ans->owner)
+    return 0;
 
-  memcpy(ans->owner,owner,ol);
-  ans->owner[ol]= 0;
+  memcpy(ans->owner, owner, ol);
+  ans->owner[ol] = 0;
   return 1;
 }
 
-int adns_submit(adns_state ads,
-               const char *owner,
-               adns_rrtype type,
-               adns_queryflags flags,
-               void *context,
-               adns_query *query_r) {
+int
+adns_submit(adns_state ads,
+            const char *owner,
+            adns_rrtype type,
+            adns_queryflags flags, void *context, adns_query * query_r)
+{
   int r, ol, ndots;
   adns_status status;
   const typeinfo *typei;
@@ -214,85 +251,120 @@ int adns_submit(adns_state ads,
   adns_query qu;
   const char *p;
 
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
+
+  typei = adns__findtype(type);
+  if (!typei)
+    return ENOSYS;
+
+  r = gettimeofday(&now, 0);
+  if (r)
+    goto x_errno;
+  qu = query_alloc(ads, typei, flags, now);
+  if (!qu)
+    goto x_errno;
 
-  typei= adns__findtype(type);
-  if (!typei) return ENOSYS;
+  qu->ctx.ext = context;
+  qu->ctx.callback = 0;
+  memset(&qu->ctx.info, 0, sizeof(qu->ctx.info));
 
-  r= gettimeofday(&now,0); if (r) goto x_errno;
-  qu= query_alloc(ads,typei,flags,now); if (!qu) goto x_errno;
-  
-  qu->ctx.ext= context;
-  qu->ctx.callback= 0;
-  memset(&qu->ctx.info,0,sizeof(qu->ctx.info));
+  *query_r = qu;
 
-  *query_r= qu;
+  ol = strlen(owner);
+  if (!ol)
+  {
+    status = adns_s_querydomaininvalid;
+    goto x_adnsfail;
+  }
+  if (ol > DNS_MAXDOMAIN + 1)
+  {
+    status = adns_s_querydomaintoolong;
+    goto x_adnsfail;
+  }
 
-  ol= strlen(owner);
-  if (!ol) { status= adns_s_querydomaininvalid; goto x_adnsfail; }
-  if (ol>DNS_MAXDOMAIN+1) { status= adns_s_querydomaintoolong; goto x_adnsfail; }
-                                
-  if (ol>=1 && owner[ol-1]=='.' && (ol<2 || owner[ol-2]!='\\')) {
+  if (ol >= 1 && owner[ol - 1] == '.' && (ol < 2 || owner[ol - 2] != '\\'))
+  {
     flags &= ~adns_qf_search;
-    qu->flags= flags;
+    qu->flags = flags;
     ol--;
   }
 
-  if (flags & adns_qf_search) {
-    r= adns__vbuf_append(&qu->search_vb,(const byte *)owner,ol);
-    if (!r) { status= adns_s_nomemory; goto x_adnsfail; }
-
-    for (ndots=0, p=owner; (p= strchr(p,'.')); p++, ndots++);
-    qu->search_doneabs= (ndots >= ads->searchndots) ? -1 : 0;
-    qu->search_origlen= ol;
-    adns__search_next(ads,qu,now);
-  } else {
-    if (flags & adns_qf_owner) {
-      if (!save_owner(qu,owner,ol)) { status= adns_s_nomemory; goto x_adnsfail; }
+  if (flags & adns_qf_search)
+  {
+    r = adns__vbuf_append(&qu->search_vb, (const byte *)owner, ol);
+    if (!r)
+    {
+      status = adns_s_nomemory;
+      goto x_adnsfail;
+    }
+
+    for (ndots = 0, p = owner; (p = strchr(p, '.')); p++, ndots++);
+    qu->search_doneabs = (ndots >= ads->searchndots) ? -1 : 0;
+    qu->search_origlen = ol;
+    adns__search_next(ads, qu, now);
+  }
+  else
+  {
+    if (flags & adns_qf_owner)
+    {
+      if (!save_owner(qu, owner, ol))
+      {
+        status = adns_s_nomemory;
+        goto x_adnsfail;
+      }
     }
-    query_simple(ads,qu, (const byte *)owner,ol, typei,flags, now);
+    query_simple(ads, qu, (const byte *)owner, ol, typei, flags, now);
   }
-  adns__autosys(ads,now);
-  adns__consistency(ads,qu,cc_entex);
+  adns__autosys(ads, now);
+  adns__consistency(ads, qu, cc_entex);
   return 0;
 
- x_adnsfail:
-  adns__query_fail(qu,status);
-  adns__consistency(ads,qu,cc_entex);
+x_adnsfail:
+  adns__query_fail(qu, status);
+  adns__consistency(ads, qu, cc_entex);
   return 0;
 
- x_errno:
-  r= errno;
+x_errno:
+  r = errno;
   assert(r);
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
   return r;
 }
+
 #ifdef IPV6
-int adns_submit_reverse_ip6(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_ip6(adns_state ads,
+                        const struct sockaddr *addr,
+                        const char *zone,
+                        adns_rrtype type,
+                        adns_queryflags flags,
+                        void *context, adns_query * query_r)
+{
   char shortbuf[100];
   char *buf, *buf_free;
   const unsigned char *cp;
   char *qp;
   int n, c, lreq, r;
-               
-  if(addr->sa_family != AF_INET6) return ENOSYS;
-  cp = (const unsigned char *)&(((const struct sockaddr_in6*)addr) -> sin6_addr.s6_addr);
-       lreq = 71 + strlen(zone) + 1;
-  if (lreq > sizeof(shortbuf)) {
-    buf= MyMalloc(strlen(zone) + 4*4 + 1);
+
+  if (addr->sa_family != AF_INET6)
+    return ENOSYS;
+  cp =
+    (const unsigned char *)&(((const struct sockaddr_in6 *)addr)->sin6_addr.
+                             s6_addr);
+  lreq = 71 + strlen(zone) + 1;
+  if (lreq > sizeof(shortbuf))
+  {
+    buf = MyMalloc(strlen(zone) + 4 * 4 + 1);
 #if 0
-    if (!buf) return errno;
+    if (!buf)
+      return errno;
 #endif
-    buf_free= buf;
-  } else {
-    buf= shortbuf;
-    buf_free= 0;  
+    buf_free = buf;
+  }
+  else
+  {
+    buf = shortbuf;
+    buf_free = 0;
   }
   qp = buf;
   for (n = 15; n >= 0; n--)
@@ -301,18 +373,20 @@ int adns_submit_reverse_ip6(adns_state ads,
     qp += c;
   }
   strcpy(qp, zone);
-  r= adns_submit(ads,buf,type,flags,context,query_r);
-  if(buf_free) MyFree(buf_free);
+  r = adns_submit(ads, buf, type, flags, context, query_r);
+  if (buf_free)
+    MyFree(buf_free);
   return r;
 }
 #endif
-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_any(adns_state ads,
+                        const struct sockaddr *addr,
+                        const char *zone,
+                        adns_rrtype type,
+                        adns_queryflags flags,
+                        void *context, adns_query * query_r)
+{
   const unsigned char *iaddr;
   char *buf, *buf_free;
   char shortbuf[100];
@@ -320,306 +394,380 @@ int adns_submit_reverse_any(adns_state ads,
 
   flags &= ~adns_qf_search;
 
-  if (addr->sa_family != AF_INET) return ENOSYS;
-  iaddr= (const unsigned char*) &(((const struct sockaddr_in*)addr) -> sin_addr);
+  if (addr->sa_family != AF_INET)
+    return ENOSYS;
+  iaddr =
+    (const unsigned char *)&(((const struct sockaddr_in *)addr)->sin_addr);
 
-  lreq= strlen(zone) + 4*4 + 1;
-  if (lreq > sizeof(shortbuf)) {
-    buf= MyMalloc(strlen(zone) + 4*4 + 1);
+  lreq = strlen(zone) + 4 * 4 + 1;
+  if (lreq > sizeof(shortbuf))
+  {
+    buf = MyMalloc(strlen(zone) + 4 * 4 + 1);
 #if 0
-    if (!buf) return errno;
+    if (!buf)
+      return errno;
 #endif
-    buf_free= buf;
-  } else {
-    buf= shortbuf;
-    buf_free= 0;
+    buf_free = buf;
+  }
+  else
+  {
+    buf = shortbuf;
+    buf_free = 0;
   }
-  ircsprintf(buf, "%d.%d.%d.%d.%s", iaddr[3], iaddr[2], iaddr[1], iaddr[0], zone);
+  ircsprintf(buf, "%d.%d.%d.%d.%s", iaddr[3], iaddr[2], iaddr[1], iaddr[0],
+             zone);
 
-  r= adns_submit(ads,buf,type,flags,context,query_r);
+  r = adns_submit(ads, buf, type, flags, context, query_r);
   MyFree(buf_free);
   return r;
 }
 
-int adns_submit_reverse(adns_state ads,
-                       const struct sockaddr *addr,
-                       adns_rrtype type,
-                       adns_queryflags flags,
-                       void *context,
-                       adns_query *query_r) {
-  if (type != adns_r_ptr && type != adns_r_ptr_raw && type != adns_r_ptr_ip6 ) return EINVAL;
+int
+adns_submit_reverse(adns_state ads,
+                    const struct sockaddr *addr,
+                    adns_rrtype type,
+                    adns_queryflags flags,
+                    void *context, adns_query * query_r)
+{
+  if (type != adns_r_ptr && type != adns_r_ptr_raw && type != adns_r_ptr_ip6)
+    return EINVAL;
 #ifdef IPV6
-  if(addr->sa_family == AF_INET6)
-         return adns_submit_reverse_ip6(ads,addr,"ip6.int", type,flags,context,query_r);
+  if (addr->sa_family == AF_INET6)
+    return adns_submit_reverse_ip6(ads, addr, "ip6.int", type, flags,
+                                   context, query_r);
   else
 #endif
-         return adns_submit_reverse_any(ads,addr,"in-addr.arpa",type,flags,context,query_r);
+    return adns_submit_reverse_any(ads, addr, "in-addr.arpa", type, flags,
+                                   context, query_r);
 }
 
 #if 0
-int adns_synchronous(adns_state ads,
-                    const char *owner,
-                    adns_rrtype type,
-                    adns_queryflags flags,
-                    adns_answer **answer_r) {
+int
+adns_synchronous(adns_state ads,
+                 const char *owner,
+                 adns_rrtype type,
+                 adns_queryflags flags, adns_answer ** answer_r)
+{
   adns_query qu;
   int r;
-  
-  r= adns_submit(ads,owner,type,flags,0,&qu);
-  if (r) return r;
 
-  r= adns_wait(ads,&qu,answer_r,0);
-  if (r) adns_cancel(qu);
+  r = adns_submit(ads, owner, type, flags, 0, &qu);
+  if (r)
+    return r;
+
+  r = adns_wait(ads, &qu, answer_r, 0);
+  if (r)
+    adns_cancel(qu);
 
   return r;
 }
 #endif
-static void *alloc_common(adns_query qu, size_t sz) {
+static void *
+alloc_common(adns_query qu, size_t sz)
+{
   allocnode *an;
 
-  if (!sz) return qu; /* Any old pointer will do */
+  if (!sz)
+    return qu;                  /* Any old pointer will do */
   assert(!qu->final_allocspace);
-  an= MyMalloc(MEM_ROUND(MEM_ROUND(sizeof(*an)) + sz));
+  an = MyMalloc(MEM_ROUND(MEM_ROUND(sizeof(*an)) + sz));
 #if 0
-  if (!an) return 0;
+  if (!an)
+    return 0;
 #endif
-  LIST_LINK_TAIL(qu->allocations,an);
-  return (byte*)an + MEM_ROUND(sizeof(*an));
+  LIST_LINK_TAIL(qu->allocations, an);
+  return (byte *) an + MEM_ROUND(sizeof(*an));
 }
 
-void *adns__alloc_interim(adns_query qu, size_t sz) {
+void *
+adns__alloc_interim(adns_query qu, size_t sz)
+{
   void *rv;
-  
-  sz= MEM_ROUND(sz);
-  rv= alloc_common(qu,sz);
-  if (!rv) return 0;
+
+  sz = MEM_ROUND(sz);
+  rv = alloc_common(qu, sz);
+  if (!rv)
+    return 0;
   qu->interim_allocd += sz;
   return rv;
 }
 
-void *adns__alloc_preserved(adns_query qu, size_t sz) {
+void *
+adns__alloc_preserved(adns_query qu, size_t sz)
+{
   void *rv;
-  
-  sz= MEM_ROUND(sz);
-  rv= adns__alloc_interim(qu,sz);
-  if (!rv) return 0;
+
+  sz = MEM_ROUND(sz);
+  rv = adns__alloc_interim(qu, sz);
+  if (!rv)
+    return 0;
   qu->preserved_allocd += sz;
   return rv;
 }
 
-void *adns__alloc_mine(adns_query qu, size_t sz) {
-  return alloc_common(qu,MEM_ROUND(sz));
+void *
+adns__alloc_mine(adns_query qu, size_t sz)
+{
+  return alloc_common(qu, MEM_ROUND(sz));
 }
 
-void adns__transfer_interim(adns_query from, adns_query to, void *block, size_t sz) {
+void
+adns__transfer_interim(adns_query from, adns_query to, void *block, size_t sz)
+{
   allocnode *an;
 
-  if (!block) return;
-  an= (void*)((byte*)block - MEM_ROUND(sizeof(*an)));
+  if (!block)
+    return;
+  an = (void *)((byte *) block - MEM_ROUND(sizeof(*an)));
 
   assert(!to->final_allocspace);
   assert(!from->final_allocspace);
-  
-  LIST_UNLINK(from->allocations,an);
-  LIST_LINK_TAIL(to->allocations,an);
 
-  sz= MEM_ROUND(sz);
+  LIST_UNLINK(from->allocations, an);
+  LIST_LINK_TAIL(to->allocations, an);
+
+  sz = MEM_ROUND(sz);
   from->interim_allocd -= sz;
   to->interim_allocd += sz;
 
-  if (to->expires > from->expires) to->expires= from->expires;
+  if (to->expires > from->expires)
+    to->expires = from->expires;
 }
 
-void *adns__alloc_final(adns_query qu, size_t sz) {
+void *
+adns__alloc_final(adns_query qu, size_t sz)
+{
   /* When we're in the _final stage, we _subtract_ from interim_alloc'd
    * each allocation, and use final_allocspace to point to the next free
    * bit.
    */
   void *rp;
 
-  sz= MEM_ROUND(sz);
-  rp= qu->final_allocspace;
+  sz = MEM_ROUND(sz);
+  rp = qu->final_allocspace;
   assert(rp);
   qu->interim_allocd -= sz;
-  assert(qu->interim_allocd>=0);
-  qu->final_allocspace= (byte*)rp + sz;
+  assert(qu->interim_allocd >= 0);
+  qu->final_allocspace = (byte *) rp + sz;
   return rp;
 }
 
-static void cancel_children(adns_query qu) {
+static void
+cancel_children(adns_query qu)
+{
   adns_query cqu, ncqu;
 
-  for (cqu= qu->children.head; cqu; cqu= ncqu) {
-    ncqu= cqu->siblings.next;
+  for (cqu = qu->children.head; cqu; cqu = ncqu)
+  {
+    ncqu = cqu->siblings.next;
     adns_cancel(cqu);
   }
 }
 
-void adns__reset_preserved(adns_query qu) {
+void
+adns__reset_preserved(adns_query qu)
+{
   assert(!qu->final_allocspace);
   cancel_children(qu);
-  qu->answer->nrrs= 0;
-  qu->answer->rrs.untyped= 0;
-  qu->interim_allocd= qu->preserved_allocd;
+  qu->answer->nrrs = 0;
+  qu->answer->rrs.untyped = 0;
+  qu->interim_allocd = qu->preserved_allocd;
 }
 
-static void free_query_allocs(adns_query qu) {
+static void
+free_query_allocs(adns_query qu)
+{
   allocnode *an, *ann;
 
   cancel_children(qu);
-  for (an= qu->allocations.head; an; an= ann) { ann= an->next; MyFree(an);}
+  for (an = qu->allocations.head; an; an = ann)
+  {
+    ann = an->next;
+    MyFree(an);
+  }
   ADNS_LIST_INIT(qu->allocations);
   adns__vbuf_free(&qu->vb);
   adns__vbuf_free(&qu->search_vb);
   MyFree(qu->query_dgram);
-  qu->query_dgram= 0;
+  qu->query_dgram = 0;
 }
 
-void adns_cancel(adns_query qu) {
+void
+adns_cancel(adns_query qu)
+{
   adns_state ads;
+
   assert(qu != NULL);
-  ads= qu->ads;
-  adns__consistency(ads,qu,cc_entex);
-  if (qu->parent) LIST_UNLINK_PART(qu->parent->children,qu,siblings.);
-  switch (qu->state) {
-  case query_tosend:
-    LIST_UNLINK(ads->udpw,qu);
-    break;
-  case query_tcpw:
-    LIST_UNLINK(ads->tcpw,qu);
-    break;
-  case query_childw:
-    LIST_UNLINK(ads->childw,qu);
-    break;
-  case query_done:
-    LIST_UNLINK(ads->output,qu);
-    break;
-  default:
-    break;
+  ads = qu->ads;
+  adns__consistency(ads, qu, cc_entex);
+  if (qu->parent)
+    LIST_UNLINK_PART(qu->parent->children, qu, siblings.);
+  switch (qu->state)
+  {
+    case query_tosend:
+      LIST_UNLINK(ads->udpw, qu);
+      break;
+    case query_tcpw:
+      LIST_UNLINK(ads->tcpw, qu);
+      break;
+    case query_childw:
+      LIST_UNLINK(ads->childw, qu);
+      break;
+    case query_done:
+      LIST_UNLINK(ads->output, qu);
+      break;
+    default:
+      break;
 #if 0
-    abort();
+      abort();
 #endif
   }
   free_query_allocs(qu);
   MyFree(qu->answer);
   MyFree(qu);
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
 }
 
-void adns__update_expires(adns_query qu, unsigned long ttl, struct timeval now) {
+void
+adns__update_expires(adns_query qu, unsigned long ttl, struct timeval now)
+{
   time_t max;
 
   assert(ttl <= MAXTTLBELIEVE);
-  max= now.tv_sec + ttl;
-  if (qu->expires < max) return;
-  qu->expires= max;
+  max = now.tv_sec + ttl;
+  if (qu->expires < max)
+    return;
+  qu->expires = max;
 }
 
-static void makefinal_query(adns_query qu) {
+static void
+makefinal_query(adns_query qu)
+{
   adns_answer *ans;
   int rrn;
 
-  ans= qu->answer;
+  ans = qu->answer;
 
-  if (qu->interim_allocd) {
-    ans= MyRealloc(qu->answer, MEM_ROUND(MEM_ROUND(sizeof(*ans)) + qu->interim_allocd));
-    if (!ans) goto x_nomem;
-    qu->answer= ans;
+  if (qu->interim_allocd)
+  {
+    ans =
+      MyRealloc(qu->answer,
+                MEM_ROUND(MEM_ROUND(sizeof(*ans)) + qu->interim_allocd));
+    if (!ans)
+      goto x_nomem;
+    qu->answer = ans;
   }
 
-  qu->final_allocspace= (byte*)ans + MEM_ROUND(sizeof(*ans));
-  adns__makefinal_str(qu,&ans->cname);
-  adns__makefinal_str(qu,&ans->owner);
-  
-  if (ans->nrrs) {
-    adns__makefinal_block(qu, &ans->rrs.untyped, ans->nrrs*ans->rrsz);
+  qu->final_allocspace = (byte *) ans + MEM_ROUND(sizeof(*ans));
+  adns__makefinal_str(qu, &ans->cname);
+  adns__makefinal_str(qu, &ans->owner);
 
-    for (rrn=0; rrn<ans->nrrs; rrn++)
-      qu->typei->makefinal(qu, ans->rrs.bytes + rrn*ans->rrsz);
+  if (ans->nrrs)
+  {
+    adns__makefinal_block(qu, &ans->rrs.untyped, ans->nrrs * ans->rrsz);
+
+    for (rrn = 0; rrn < ans->nrrs; rrn++)
+      qu->typei->makefinal(qu, ans->rrs.bytes + rrn * ans->rrsz);
   }
-  
+
   free_query_allocs(qu);
   return;
-  
- x_nomem:
-  qu->preserved_allocd= 0;
-  qu->answer->cname= 0;
-  qu->answer->owner= 0;
-  adns__reset_preserved(qu); /* (but we just threw away the preserved stuff) */
-
-  qu->answer->status= adns_s_nomemory;
+
+x_nomem:
+  qu->preserved_allocd = 0;
+  qu->answer->cname = 0;
+  qu->answer->owner = 0;
+  adns__reset_preserved(qu);    /* (but we just threw away the preserved stuff) */
+
+  qu->answer->status = adns_s_nomemory;
   free_query_allocs(qu);
 }
 
-void adns__query_done(adns_query qu) {
+void
+adns__query_done(adns_query qu)
+{
   adns_answer *ans;
   adns_query parent;
 
   cancel_children(qu);
 
-  qu->id= -1;
-  ans= qu->answer;
+  qu->id = -1;
+  ans = qu->answer;
 
   if (qu->flags & adns_qf_owner && qu->flags & adns_qf_search &&
-      ans->status != adns_s_nomemory) {
-    if (!save_owner(qu, (const char *)qu->search_vb.buf, qu->search_vb.used)) {
-      adns__query_fail(qu,adns_s_nomemory);
+      ans->status != adns_s_nomemory)
+  {
+    if (!save_owner(qu, (const char *)qu->search_vb.buf, qu->search_vb.used))
+    {
+      adns__query_fail(qu, adns_s_nomemory);
       return;
     }
   }
 
-  if (ans->nrrs && qu->typei->diff_needswap) {
-    if (!adns__vbuf_ensure(&qu->vb,qu->typei->rrsz)) {
-      adns__query_fail(qu,adns_s_nomemory);
+  if (ans->nrrs && qu->typei->diff_needswap)
+  {
+    if (!adns__vbuf_ensure(&qu->vb, qu->typei->rrsz))
+    {
+      adns__query_fail(qu, adns_s_nomemory);
       return;
     }
     adns__isort(ans->rrs.bytes, ans->nrrs, ans->rrsz,
-               qu->vb.buf,
-               (int(*)(void*, const void*, const void*))qu->typei->diff_needswap,
-               qu->ads);
+                qu->vb.buf,
+                (int (*)(void *, const void *, const void *))qu->typei->
+                diff_needswap, qu->ads);
   }
 
-  ans->expires= qu->expires;
-  parent= qu->parent;
-  if (parent) {
-    LIST_UNLINK_PART(parent->children,qu,siblings.);
-    LIST_UNLINK(qu->ads->childw,parent);
-    qu->ctx.callback(parent,qu);
+  ans->expires = qu->expires;
+  parent = qu->parent;
+  if (parent)
+  {
+    LIST_UNLINK_PART(parent->children, qu, siblings.);
+    LIST_UNLINK(qu->ads->childw, parent);
+    qu->ctx.callback(parent, qu);
     free_query_allocs(qu);
     MyFree(qu->answer);
     MyFree(qu);
-  } else {
+  }
+  else
+  {
     makefinal_query(qu);
-    LIST_LINK_TAIL(qu->ads->output,qu);
-    qu->state= query_done;
+    LIST_LINK_TAIL(qu->ads->output, qu);
+    qu->state = query_done;
   }
 }
 
-void adns__query_fail(adns_query qu, adns_status status) {
+void
+adns__query_fail(adns_query qu, adns_status status)
+{
   adns__reset_preserved(qu);
-  qu->answer->status= status;
+  qu->answer->status = status;
   adns__query_done(qu);
 }
 
-void adns__makefinal_str(adns_query qu, char **strp) {
+void
+adns__makefinal_str(adns_query qu, char **strp)
+{
   int l;
   char *before, *after;
 
-  before= *strp;
-  if (!before) return;
-  l= strlen(before)+1;
-  after= adns__alloc_final(qu,l);
-  memcpy(after,before,l);
-  *strp= after;  
+  before = *strp;
+  if (!before)
+    return;
+  l = strlen(before) + 1;
+  after = adns__alloc_final(qu, l);
+  memcpy(after, before, l);
+  *strp = after;
 }
 
-void adns__makefinal_block(adns_query qu, void **blpp, size_t sz) {
+void
+adns__makefinal_block(adns_query qu, void **blpp, size_t sz)
+{
   void *before, *after;
 
-  before= *blpp;
-  if (!before) return;
-  after= adns__alloc_final(qu,sz);
-  memcpy(after,before,sz);
-  *blpp= after;
+  before = *blpp;
+  if (!before)
+    return;
+  after = adns__alloc_final(qu, sz);
+  memcpy(after, before, sz);
+  *blpp = after;
 }
index b5180ac013d46db31b769d8f69e73205b0616036..55124c02ec6106571a27ff80af839a1d16c6f2d6 100644 (file)
@@ -24,7 +24,7 @@
  *  along with this program; if not, write to the Free Software Foundation,
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  *
- * $Id: reply.c,v 1.1 2002/01/04 09:10:50 a1kmm Exp $
+ * $Id: reply.c,v 1.2 2002/04/27 02:48:47 a1kmm Exp $
  */
 
 #include <stdlib.h>
 #include "fileio.h"
 #include "internal.h"
 
-void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
-                    int serv, int viatcp, struct timeval now) {
+void
+adns__procdgram(adns_state ads, const byte * dgram, int dglen,
+                int serv, int viatcp, struct timeval now)
+{
   int cbyte, rrstart, wantedrrs, rri, foundsoa, foundns, cname_here;
   int id, f1, f2, qdcount, ancount, nscount, arcount;
   int flg_ra, flg_rd, flg_tc, flg_qr, opcode;
@@ -49,230 +51,329 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
   vbuf tempvb;
   byte *newquery, *rrsdata;
   parseinfo pai;
-  
-  if (dglen<DNS_HDRSIZE) {
-    adns__diag(ads,serv,0,"received datagram too short for message header (%d)",dglen);
+
+  if (dglen < DNS_HDRSIZE)
+  {
+    adns__diag(ads, serv, 0,
+               "received datagram too short for message header (%d)", dglen);
     return;
   }
-  cbyte= 0;
-  GET_W(cbyte,id);
-  GET_B(cbyte,f1);
-  GET_B(cbyte,f2);
-  GET_W(cbyte,qdcount);
-  GET_W(cbyte,ancount);
-  GET_W(cbyte,nscount);
-  GET_W(cbyte,arcount);
+  cbyte = 0;
+  GET_W(cbyte, id);
+  GET_B(cbyte, f1);
+  GET_B(cbyte, f2);
+  GET_W(cbyte, qdcount);
+  GET_W(cbyte, ancount);
+  GET_W(cbyte, nscount);
+  GET_W(cbyte, arcount);
   assert(cbyte == DNS_HDRSIZE);
 
-  flg_qr= f1&0x80;
-  opcode= (f1&0x78)>>3;
-  flg_tc= f1&0x02;
-  flg_rd= f1&0x01;
-  flg_ra= f2&0x80;
-  rcode= (f2&0x0f);
-
-  cname_here= 0;
-  
-  if (!flg_qr) {
-    adns__diag(ads,serv,0,"server sent us a query, not a response");
+  flg_qr = f1 & 0x80;
+  opcode = (f1 & 0x78) >> 3;
+  flg_tc = f1 & 0x02;
+  flg_rd = f1 & 0x01;
+  flg_ra = f2 & 0x80;
+  rcode = (f2 & 0x0f);
+
+  cname_here = 0;
+
+  if (!flg_qr)
+  {
+    adns__diag(ads, serv, 0, "server sent us a query, not a response");
     return;
   }
-  if (opcode) {
-    adns__diag(ads,serv,0,"server sent us unknown opcode %d (wanted 0=QUERY)",opcode);
+  if (opcode)
+  {
+    adns__diag(ads, serv, 0,
+               "server sent us unknown opcode %d (wanted 0=QUERY)", opcode);
     return;
   }
 
-  qu= 0;
-  /* See if we can find the relevant query, or leave qu=0 otherwise ... */   
-
-  if (qdcount == 1) {
-    for (qu= viatcp ? ads->tcpw.head : ads->udpw.head; qu; qu= nqu) {
-      nqu= qu->next;
-      if (qu->id != id) continue;
-      if (dglen < qu->query_dglen) continue;
-      if (memcmp(qu->query_dgram+DNS_HDRSIZE,
-                dgram+DNS_HDRSIZE,
-                qu->query_dglen-DNS_HDRSIZE))
-       continue;
-      if (viatcp) {
-       assert(qu->state == query_tcpw);
-      } else {
-       assert(qu->state == query_tosend);
-       if (!(qu->udpsent & (1<<serv))) continue;
+  qu = 0;
+  /* See if we can find the relevant query, or leave qu=0 otherwise ... */
+
+  if (qdcount == 1)
+  {
+    for (qu = viatcp ? ads->tcpw.head : ads->udpw.head; qu; qu = nqu)
+    {
+      nqu = qu->next;
+      if (qu->id != id)
+        continue;
+      if (dglen < qu->query_dglen)
+        continue;
+      if (memcmp(qu->query_dgram + DNS_HDRSIZE,
+                 dgram + DNS_HDRSIZE, qu->query_dglen - DNS_HDRSIZE))
+        continue;
+      if (viatcp)
+      {
+        assert(qu->state == query_tcpw);
+      }
+      else
+      {
+        assert(qu->state == query_tosend);
+        if (!(qu->udpsent & (1 << serv)))
+          continue;
       }
       break;
     }
-    if (qu) {
+    if (qu)
+    {
       /* We're definitely going to do something with this query now */
-      if (viatcp) LIST_UNLINK(ads->tcpw,qu);
-      else LIST_UNLINK(ads->udpw,qu);
+      if (viatcp)
+        LIST_UNLINK(ads->tcpw, qu);
+      else
+        LIST_UNLINK(ads->udpw, qu);
     }
   }
-  
+
   /* If we're going to ignore the packet, we return as soon as we have
    * failed the query (if any) and printed the warning message (if
    * any).
    */
-  switch (rcode) {
-  case rcode_noerror:
-  case rcode_nxdomain:
-    break;
-  case rcode_formaterror:
-    adns__warn(ads,serv,qu,"server cannot understand our query (Format Error)");
-    if (qu) adns__query_fail(qu,adns_s_rcodeformaterror);
-    return;
-  case rcode_servfail:
-    if (qu) adns__query_fail(qu,adns_s_rcodeservfail);
-    else adns__debug(ads,serv,qu,"server failure on unidentifiable query");
-    return;
-  case rcode_notimp:
-    adns__warn(ads,serv,qu,"server claims not to implement our query");
-    if (qu) adns__query_fail(qu,adns_s_rcodenotimplemented);
-    return;
-  case rcode_refused:
-    adns__debug(ads,serv,qu,"server refused our query");
-    if (qu) adns__query_fail(qu,adns_s_rcoderefused);
-    return;
-  default:
-    adns__warn(ads,serv,qu,"server gave unknown response code %d",rcode);
-    if (qu) adns__query_fail(qu,adns_s_rcodeunknown);
-    return;
+  switch (rcode)
+  {
+    case rcode_noerror:
+    case rcode_nxdomain:
+      break;
+    case rcode_formaterror:
+      adns__warn(ads, serv, qu,
+                 "server cannot understand our query (Format Error)");
+      if (qu)
+        adns__query_fail(qu, adns_s_rcodeformaterror);
+      return;
+    case rcode_servfail:
+      if (qu)
+        adns__query_fail(qu, adns_s_rcodeservfail);
+      else
+        adns__debug(ads, serv, qu, "server failure on unidentifiable query");
+      return;
+    case rcode_notimp:
+      adns__warn(ads, serv, qu, "server claims not to implement our query");
+      if (qu)
+        adns__query_fail(qu, adns_s_rcodenotimplemented);
+      return;
+    case rcode_refused:
+      adns__debug(ads, serv, qu, "server refused our query");
+      if (qu)
+        adns__query_fail(qu, adns_s_rcoderefused);
+      return;
+    default:
+      adns__warn(ads, serv, qu, "server gave unknown response code %d",
+                 rcode);
+      if (qu)
+        adns__query_fail(qu, adns_s_rcodeunknown);
+      return;
   }
 
-  if (!qu) {
-    if (!qdcount) {
-      adns__diag(ads,serv,0,"server sent reply without quoting our question");
-    } else if (qdcount>1) {
-      adns__diag(ads,serv,0,"server claimed to answer %d questions with one message",
-                qdcount);
-    } else if (ads->iflags & adns_if_debug) {
+  if (!qu)
+  {
+    if (!qdcount)
+    {
+      adns__diag(ads, serv, 0,
+                 "server sent reply without quoting our question");
+    }
+    else if (qdcount > 1)
+    {
+      adns__diag(ads, serv, 0,
+                 "server claimed to answer %d questions with one message",
+                 qdcount);
+    }
+    else if (ads->iflags & adns_if_debug)
+    {
       adns__vbuf_init(&tempvb);
-      adns__debug(ads,serv,0,"reply not found, id %02x, query owner %s",
-                 id, adns__diag_domain(ads,serv,0,&tempvb,dgram,dglen,DNS_HDRSIZE));
+      adns__debug(ads, serv, 0,
+                  "reply not found, id %02x, query owner %s", id,
+                  adns__diag_domain(ads, serv, 0, &tempvb, dgram, dglen,
+                                    DNS_HDRSIZE));
       adns__vbuf_free(&tempvb);
     }
     return;
   }
 
   /* We're definitely going to do something with this packet and this query now. */
-  
-  anstart= qu->query_dglen;
-  arstart= -1;
+
+  anstart = qu->query_dglen;
+  arstart = -1;
 
   /* Now, take a look at the answer section, and see if it is complete.
    * If it has any CNAMEs we stuff them in the answer.
    */
-  wantedrrs= 0;
-  cbyte= anstart;
-  for (rri= 0; rri<ancount; rri++) {
-    rrstart= cbyte;
-    st= adns__findrr(qu,serv, dgram,dglen,&cbyte,
-                    &rrtype,&rrclass,&ttl, &rdlength,&rdstart,
-                    &ownermatched);
-    if (st) { adns__query_fail(qu,st); return; }
-    if (rrtype == -1) goto x_truncated;
-
-    if (rrclass != DNS_CLASS_IN) {
-      adns__diag(ads,serv,qu,"ignoring answer RR with wrong class %d (expected IN=%d)",
-                rrclass,DNS_CLASS_IN);
+  wantedrrs = 0;
+  cbyte = anstart;
+  for (rri = 0; rri < ancount; rri++)
+  {
+    rrstart = cbyte;
+    st = adns__findrr(qu, serv, dgram, dglen, &cbyte,
+                      &rrtype, &rrclass, &ttl, &rdlength, &rdstart,
+                      &ownermatched);
+    if (st)
+    {
+      adns__query_fail(qu, st);
+      return;
+    }
+    if (rrtype == -1)
+      goto x_truncated;
+
+    if (rrclass != DNS_CLASS_IN)
+    {
+      adns__diag(ads, serv, qu,
+                 "ignoring answer RR with wrong class %d (expected IN=%d)",
+                 rrclass, DNS_CLASS_IN);
       continue;
     }
-    if (!ownermatched) {
-      if (ads->iflags & adns_if_debug) {
-       adns__debug(ads,serv,qu,"ignoring RR with an unexpected owner %s",
-                   adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rrstart));
+    if (!ownermatched)
+    {
+      if (ads->iflags & adns_if_debug)
+      {
+        adns__debug(ads, serv, qu,
+                    "ignoring RR with an unexpected owner %s",
+                    adns__diag_domain(ads, serv, qu, &qu->vb, dgram,
+                                      dglen, rrstart));
       }
       continue;
     }
     if (rrtype == adns_r_cname &&
-       (qu->typei->type & adns__rrt_typemask) != adns_r_cname) {
-      if (qu->flags & adns_qf_cname_forbid) {
-       adns__query_fail(qu,adns_s_prohibitedcname);
-       return;
-      } else if (qu->cname_dgram && ++qu->cname_count >= 2) { 
-       adns__debug(ads,serv,qu,"allegedly canonical name %s is actually alias for %s",
-                   qu->answer->cname,
-                   adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rdstart));
-       adns__query_fail(qu,adns_s_prohibitedcname);
-       return;
-      } else if (wantedrrs) { /* Ignore CNAME(s) after RR(s). */
-       adns__debug(ads,serv,qu,"ignoring CNAME (to %s) coexisting with RR",
-                   adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rdstart));
-      } else {
-       qu->cname_begin= rdstart;
-       qu->cname_dglen= dglen;
-       st= adns__parse_domain(ads,serv,qu, &qu->vb,
-                              qu->flags & adns_qf_quotefail_cname ? 0 : pdf_quoteok,
-                              dgram,dglen, &rdstart,rdstart+rdlength);
-       if (!qu->vb.used) goto x_truncated;
-       if (st) { adns__query_fail(qu,st); return; }
-       l= strlen((char*)qu->vb.buf)+1;
-       qu->answer->cname= adns__alloc_preserved(qu,l);
-       if (!qu->answer->cname) { adns__query_fail(qu,adns_s_nomemory); return; }
-
-       qu->cname_dgram= adns__alloc_mine(qu,dglen);
-       memcpy(qu->cname_dgram,dgram,dglen);
-
-       memcpy(qu->answer->cname,qu->vb.buf,l);
-       cname_here= 1;
-       adns__update_expires(qu,ttl,now);
-       /* If we find the answer section truncated after this point we restart
-        * the query at the CNAME; if beforehand then we obviously have to use
-        * TCP.  If there is no truncation we can use the whole answer if
-        * it contains the relevant info.
-        */
+        (qu->typei->type & adns__rrt_typemask) != adns_r_cname)
+    {
+      if (qu->flags & adns_qf_cname_forbid)
+      {
+        adns__query_fail(qu, adns_s_prohibitedcname);
+        return;
+      }
+      else if (qu->cname_dgram && ++qu->cname_count >= 2)
+      {
+        adns__debug(ads, serv, qu,
+                    "allegedly canonical name %s is actually alias for %s",
+                    qu->answer->cname, adns__diag_domain(ads, serv,
+                                                         qu, &qu->vb,
+                                                         dgram, dglen,
+                                                         rdstart));
+        adns__query_fail(qu, adns_s_prohibitedcname);
+        return;
+      }
+      else if (wantedrrs)
+      {                         /* Ignore CNAME(s) after RR(s). */
+        adns__debug(ads, serv, qu,
+                    "ignoring CNAME (to %s) coexisting with RR",
+                    adns__diag_domain(ads, serv, qu, &qu->vb, dgram,
+                                      dglen, rdstart));
+      }
+      else
+      {
+        qu->cname_begin = rdstart;
+        qu->cname_dglen = dglen;
+        st = adns__parse_domain(ads, serv, qu, &qu->vb,
+                                qu->
+                                flags & adns_qf_quotefail_cname ? 0 :
+                                pdf_quoteok, dgram, dglen, &rdstart,
+                                rdstart + rdlength);
+        if (!qu->vb.used)
+          goto x_truncated;
+        if (st)
+        {
+          adns__query_fail(qu, st);
+          return;
+        }
+        l = strlen((char *)qu->vb.buf) + 1;
+        qu->answer->cname = adns__alloc_preserved(qu, l);
+        if (!qu->answer->cname)
+        {
+          adns__query_fail(qu, adns_s_nomemory);
+          return;
+        }
+
+        qu->cname_dgram = adns__alloc_mine(qu, dglen);
+        memcpy(qu->cname_dgram, dgram, dglen);
+
+        memcpy(qu->answer->cname, qu->vb.buf, l);
+        cname_here = 1;
+        adns__update_expires(qu, ttl, now);
+        /* If we find the answer section truncated after this point we restart
+         * the query at the CNAME; if beforehand then we obviously have to use
+         * TCP.  If there is no truncation we can use the whole answer if
+         * it contains the relevant info.
+         */
       }
-    } else if (rrtype == (qu->typei->type & adns__rrt_typemask)) {
+    }
+    else if (rrtype == (qu->typei->type & adns__rrt_typemask))
+    {
       wantedrrs++;
-    } else {
-      adns__debug(ads,serv,qu,"ignoring answer RR with irrelevant type %d",rrtype);
+    }
+    else
+    {
+      adns__debug(ads, serv, qu,
+                  "ignoring answer RR with irrelevant type %d", rrtype);
     }
   }
 
   /* We defer handling truncated responses here, in case there was a CNAME
    * which we could use.
    */
-  if (flg_tc) goto x_truncated;
-  
-  nsstart= cbyte;
+  if (flg_tc)
+    goto x_truncated;
+
+  nsstart = cbyte;
 
-  if (!wantedrrs) {
+  if (!wantedrrs)
+  {
     /* Oops, NODATA or NXDOMAIN or perhaps a referral (which would be a problem) */
 
     /* RFC2308: NODATA has _either_ a SOA _or_ _no_ NS records in authority section */
-    foundsoa= 0; soattl= 0; foundns= 0;
-    for (rri= 0; rri<nscount; rri++) {
-      rrstart= cbyte;
-      st= adns__findrr(qu,serv, dgram,dglen,&cbyte,
-                      &rrtype,&rrclass,&ttl, &rdlength,&rdstart, 0);
-      if (st) { adns__query_fail(qu,st); return; }
-      if (rrtype==-1) goto x_truncated;
-      if (rrclass != DNS_CLASS_IN) {
-       adns__diag(ads,serv,qu,
-                  "ignoring authority RR with wrong class %d (expected IN=%d)",
-                  rrclass,DNS_CLASS_IN);
-       continue;
+    foundsoa = 0;
+    soattl = 0;
+    foundns = 0;
+    for (rri = 0; rri < nscount; rri++)
+    {
+      rrstart = cbyte;
+      st = adns__findrr(qu, serv, dgram, dglen, &cbyte,
+                        &rrtype, &rrclass, &ttl, &rdlength, &rdstart, 0);
+      if (st)
+      {
+        adns__query_fail(qu, st);
+        return;
+      }
+      if (rrtype == -1)
+        goto x_truncated;
+      if (rrclass != DNS_CLASS_IN)
+      {
+        adns__diag(ads, serv, qu,
+                   "ignoring authority RR with wrong class %d (expected IN=%d)",
+                   rrclass, DNS_CLASS_IN);
+        continue;
+      }
+      if (rrtype == adns_r_soa_raw)
+      {
+        foundsoa = 1;
+        soattl = ttl;
+        break;
+      }
+      else if (rrtype == adns_r_ns_raw)
+      {
+        foundns = 1;
       }
-      if (rrtype == adns_r_soa_raw) { foundsoa= 1; soattl= ttl; break; }
-      else if (rrtype == adns_r_ns_raw) { foundns= 1; }
     }
-    
-    if (rcode == rcode_nxdomain) {
+
+    if (rcode == rcode_nxdomain)
+    {
       /* We still wanted to look for the SOA so we could find the TTL. */
-      adns__update_expires(qu,soattl,now);
+      adns__update_expires(qu, soattl, now);
 
-      if (qu->flags & adns_qf_search) {
-       adns__search_next(ads,qu,now);
-      } else {
-       adns__query_fail(qu,adns_s_nxdomain);
+      if (qu->flags & adns_qf_search)
+      {
+        adns__search_next(ads, qu, now);
+      }
+      else
+      {
+        adns__query_fail(qu, adns_s_nxdomain);
       }
       return;
     }
 
-    if (foundsoa || !foundns) {
+    if (foundsoa || !foundns)
+    {
       /* Aha !  A NODATA response, good. */
-      adns__update_expires(qu,soattl,now);
-      adns__query_fail(qu,adns_s_nodata);
+      adns__update_expires(qu, soattl, now);
+      adns__query_fail(qu, adns_s_nodata);
       return;
     }
 
@@ -281,94 +382,127 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
      * a CNAME in this datagram then we should probably do our own CNAME
      * lookup now in the hope that we won't get a referral again.
      */
-    if (cname_here) goto x_restartquery;
+    if (cname_here)
+      goto x_restartquery;
 
     /* Bloody hell, I thought we asked for recursion ? */
-    if (!flg_ra) {
-      adns__diag(ads,serv,qu,"server is not willing to do recursive lookups for us");
-      adns__query_fail(qu,adns_s_norecurse);
-    } else {
+    if (!flg_ra)
+    {
+      adns__diag(ads, serv, qu,
+                 "server is not willing to do recursive lookups for us");
+      adns__query_fail(qu, adns_s_norecurse);
+    }
+    else
+    {
       if (!flg_rd)
-       adns__diag(ads,serv,qu,"server thinks we didn't ask for recursive lookup");
+        adns__diag(ads, serv, qu,
+                   "server thinks we didn't ask for recursive lookup");
       else
-       adns__debug(ads,serv,qu,"server claims to do recursion, but gave us a referral");
-      adns__query_fail(qu,adns_s_invalidresponse);
+        adns__debug(ads, serv, qu,
+                    "server claims to do recursion, but gave us a referral");
+      adns__query_fail(qu, adns_s_invalidresponse);
     }
     return;
   }
 
   /* Now, we have some RRs which we wanted. */
 
-  qu->answer->rrs.untyped= adns__alloc_interim(qu,qu->typei->rrsz*wantedrrs);
-  if (!qu->answer->rrs.untyped) { adns__query_fail(qu,adns_s_nomemory); return; }
-
-  typei= qu->typei;
-  cbyte= anstart;
-  rrsdata= qu->answer->rrs.bytes;
-
-  pai.ads= qu->ads;
-  pai.qu= qu;
-  pai.serv= serv;
-  pai.dgram= dgram;
-  pai.dglen= dglen;
-  pai.nsstart= nsstart;
-  pai.nscount= nscount;
-  pai.arcount= arcount;
-  pai.now= now;
-
-  for (rri=0, nrrs=0; rri<ancount; rri++) {
-    st= adns__findrr(qu,serv, dgram,dglen,&cbyte,
-                    &rrtype,&rrclass,&ttl, &rdlength,&rdstart,
-                    &ownermatched);
-    assert(!st); assert(rrtype != -1);
+  qu->answer->rrs.untyped =
+    adns__alloc_interim(qu, qu->typei->rrsz * wantedrrs);
+  if (!qu->answer->rrs.untyped)
+  {
+    adns__query_fail(qu, adns_s_nomemory);
+    return;
+  }
+
+  typei = qu->typei;
+  cbyte = anstart;
+  rrsdata = qu->answer->rrs.bytes;
+
+  pai.ads = qu->ads;
+  pai.qu = qu;
+  pai.serv = serv;
+  pai.dgram = dgram;
+  pai.dglen = dglen;
+  pai.nsstart = nsstart;
+  pai.nscount = nscount;
+  pai.arcount = arcount;
+  pai.now = now;
+
+  for (rri = 0, nrrs = 0; rri < ancount; rri++)
+  {
+    st = adns__findrr(qu, serv, dgram, dglen, &cbyte,
+                      &rrtype, &rrclass, &ttl, &rdlength, &rdstart,
+                      &ownermatched);
+    assert(!st);
+    assert(rrtype != -1);
     if (rrclass != DNS_CLASS_IN ||
-       rrtype != (qu->typei->type & adns__rrt_typemask) ||
-       !ownermatched)
+        rrtype != (qu->typei->type & adns__rrt_typemask) || !ownermatched)
       continue;
-    adns__update_expires(qu,ttl,now);
-    st= typei->parse(&pai, rdstart,rdstart+rdlength, rrsdata+nrrs*typei->rrsz);
-    if (st) { adns__query_fail(qu,st); return; }
-    if (rdstart==-1) goto x_truncated;
+    adns__update_expires(qu, ttl, now);
+    st =
+      typei->parse(&pai, rdstart, rdstart + rdlength,
+                   rrsdata + nrrs * typei->rrsz);
+    if (st)
+    {
+      adns__query_fail(qu, st);
+      return;
+    }
+    if (rdstart == -1)
+      goto x_truncated;
     nrrs++;
   }
-  assert(nrrs==wantedrrs);
-  qu->answer->nrrs= nrrs;
+  assert(nrrs == wantedrrs);
+  qu->answer->nrrs = nrrs;
 
   /* This may have generated some child queries ... */
-  if (qu->children.head) {
-    qu->state= query_childw;
-    LIST_LINK_TAIL(ads->childw,qu);
+  if (qu->children.head)
+  {
+    qu->state = query_childw;
+    LIST_LINK_TAIL(ads->childw, qu);
     return;
   }
   adns__query_done(qu);
   return;
 
- x_truncated:
-  
-  if (!flg_tc) {
-    adns__diag(ads,serv,qu,"server sent datagram which points outside itself");
-    adns__query_fail(qu,adns_s_invalidresponse);
+x_truncated:
+
+  if (!flg_tc)
+  {
+    adns__diag(ads, serv, qu,
+               "server sent datagram which points outside itself");
+    adns__query_fail(qu, adns_s_invalidresponse);
     return;
   }
   qu->flags |= adns_qf_usevc;
-  
- x_restartquery:
-  if (qu->cname_dgram) {
-    st= adns__mkquery_frdgram(qu->ads,&qu->vb,&qu->id,
-                             qu->cname_dgram, qu->cname_dglen, qu->cname_begin,
-                             qu->typei->type, qu->flags);
-    if (st) { adns__query_fail(qu,st); return; }
-    
-    newquery= MyRealloc(qu->query_dgram,qu->vb.used);
-    if (!newquery) { adns__query_fail(qu,adns_s_nomemory); return; }
-    
-    qu->query_dgram= newquery;
-    qu->query_dglen= qu->vb.used;
-    memcpy(newquery,qu->vb.buf,qu->vb.used);
+
+x_restartquery:
+  if (qu->cname_dgram)
+  {
+    st = adns__mkquery_frdgram(qu->ads, &qu->vb, &qu->id,
+                               qu->cname_dgram, qu->cname_dglen,
+                               qu->cname_begin, qu->typei->type, qu->flags);
+    if (st)
+    {
+      adns__query_fail(qu, st);
+      return;
+    }
+
+    newquery = MyRealloc(qu->query_dgram, qu->vb.used);
+    if (!newquery)
+    {
+      adns__query_fail(qu, adns_s_nomemory);
+      return;
+    }
+
+    qu->query_dgram = newquery;
+    qu->query_dglen = qu->vb.used;
+    memcpy(newquery, qu->vb.buf, qu->vb.used);
   }
-  
-  if (qu->state == query_tcpw) qu->state= query_tosend;
-  qu->retries= 0;
+
+  if (qu->state == query_tcpw)
+    qu->state = query_tosend;
+  qu->retries = 0;
   adns__reset_preserved(qu);
-  adns__query_send(qu,now);
+  adns__query_send(qu, now);
 }
index 85722e41a69cb2a218fe8d91b9dffaebd0a650f0..dedeb40f4280196cbeec61acf103b18fabbf76b3 100644 (file)
@@ -25,7 +25,7 @@
  *  along with this program; if not, write to the Free Software Foundation,
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  *
- * $Id: setup.c,v 1.1 2002/01/04 09:10:59 a1kmm Exp $
+ * $Id: setup.c,v 1.2 2002/04/27 02:48:47 a1kmm Exp $
  */
 
 #include <stdlib.h>
 
 static void readconfig(adns_state ads, const char *filename, int warnmissing);
 
-static void addserver(adns_state ads, struct in_addr addr)
+static void
+addserver(adns_state ads, struct in_addr addr)
 {
   int i;
   struct server *ss;
-  
-  if(addr.s_addr == 0)
-       addr.s_addr = htonl(INADDR_LOOPBACK);
-  for (i=0; i<ads->nservers; i++)
-    {
-      if (ads->servers[i].addr.s_addr == addr.s_addr)
-       {
-         adns__debug(ads,-1,0,
-                     "duplicate nameserver %s ignored",inetntoa((char *)&addr));
-         return;
-       }
-    }
-  
-  if (ads->nservers>=MAXSERVERS)
+
+  if (addr.s_addr == 0)
+    addr.s_addr = htonl(INADDR_LOOPBACK);
+  for (i = 0; i < ads->nservers; i++)
+  {
+    if (ads->servers[i].addr.s_addr == addr.s_addr)
     {
-      adns__diag(ads,-1,0,"too many nameservers, ignoring %s",inetntoa((char *)&addr));
+      adns__debug(ads, -1, 0,
+                  "duplicate nameserver %s ignored", inetntoa((char *)&addr));
       return;
     }
+  }
+
+  if (ads->nservers >= MAXSERVERS)
+  {
+    adns__diag(ads, -1, 0, "too many nameservers, ignoring %s",
+               inetntoa((char *)&addr));
+    return;
+  }
 
-  ss= ads->servers+ads->nservers;
-  ss->addr= addr;
+  ss = ads->servers + ads->nservers;
+  ss->addr = addr;
   ads->nservers++;
 }
 
-static void freesearchlist(adns_state ads)
+static void
+freesearchlist(adns_state ads)
 {
-  if (ads->nsearchlist) MyFree(*ads->searchlist);
+  if (ads->nsearchlist)
+    MyFree(*ads->searchlist);
   MyFree(ads->searchlist);
 }
 
-static void saveerr(adns_state ads, int en)
+static void
+saveerr(adns_state ads, int en)
 {
-  if (!ads->configerrno) ads->configerrno= en;
+  if (!ads->configerrno)
+    ads->configerrno = en;
 }
 
-static void configparseerr(adns_state ads, const char *fn, int lno,
-                          const char *fmt, ...)
+static void
+configparseerr(adns_state ads, const char *fn, int lno, const char *fmt, ...)
 {
 #if 0
   va_list al;
 #endif
-  saveerr(ads,EINVAL);
-  if (!ads->diagfile || (ads->iflags & adns_if_noerrprint)) return;
+  saveerr(ads, EINVAL);
+  if (!ads->diagfile || (ads->iflags & adns_if_noerrprint))
+    return;
 
 #if 0
-  if (lno==-1) fprintf(ads->diagfile,"adns: %s: ",fn);
-  else fprintf(ads->diagfile,"adns: %s:%d: ",fn,lno);
-  va_start(al,fmt);
-  vfprintf(ads->diagfile,fmt,al);
+  if (lno == -1)
+    fprintf(ads->diagfile, "adns: %s: ", fn);
+  else
+    fprintf(ads->diagfile, "adns: %s:%d: ", fn, lno);
+  va_start(al, fmt);
+  vfprintf(ads->diagfile, fmt, al);
   va_end(al);
-  fputc('\n',ads->diagfile);
+  fputc('\n', ads->diagfile);
 #endif
 }
 
-static int nextword(const char **bufp_io, const char **word_r, int *l_r) {
+static int
+nextword(const char **bufp_io, const char **word_r, int *l_r)
+{
   const char *p, *q;
 
-  p= *bufp_io;
-  while (ctype_whitespace(*p)) p++;
-  if (!*p) return 0;
+  p = *bufp_io;
+  while (ctype_whitespace(*p))
+    p++;
+  if (!*p)
+    return 0;
 
-  q= p;
-  while (*q && !ctype_whitespace(*q)) q++;
+  q = p;
+  while (*q && !ctype_whitespace(*q))
+    q++;
 
-  *l_r= q-p;
-  *word_r= p;
-  *bufp_io= q;
+  *l_r = q - p;
+  *word_r = p;
+  *bufp_io = q;
 
   return 1;
 }
 
-static void ccf_nameserver(adns_state ads, const char *fn, int lno, const char *buf) {
+static void
+ccf_nameserver(adns_state ads, const char *fn, int lno, const char *buf)
+{
   struct in_addr ia;
-  
-  if (inetpton(AF_INET, buf,&ia) <=0) {
-    configparseerr(ads,fn,lno,"invalid nameserver address `%s'",buf);
+
+  if (inetpton(AF_INET, buf, &ia) <= 0)
+  {
+    configparseerr(ads, fn, lno, "invalid nameserver address `%s'", buf);
     return;
   }
-  adns__debug(ads,-1,0,"using nameserver %s",inetntoa((char *)&ia));
-  addserver(ads,ia);
+  adns__debug(ads, -1, 0, "using nameserver %s", inetntoa((char *)&ia));
+  addserver(ads, ia);
 }
 
-static void ccf_search(adns_state ads, const char *fn, int lno, const char *buf) {
+static void
+ccf_search(adns_state ads, const char *fn, int lno, const char *buf)
+{
   const char *bufp, *word;
   char *newchars, **newptrs, **pp;
   int count, tl, l;
 
-  if (!buf) return;
+  if (!buf)
+    return;
 
-  bufp= buf;
-  count= 0;
-  tl= 0;
-  while (nextword(&bufp,&word,&l)) { count++; tl += l+1; }
+  bufp = buf;
+  count = 0;
+  tl = 0;
+  while (nextword(&bufp, &word, &l))
+  {
+    count++;
+    tl += l + 1;
+  }
 
-  newptrs = MyMalloc(sizeof(char*)*count); 
+  newptrs = MyMalloc(sizeof(char *) * count);
   if (!newptrs)
-    {
-      saveerr(ads,errno);
-      return;
-    }
-  newchars= MyMalloc(tl); 
+  {
+    saveerr(ads, errno);
+    return;
+  }
+  newchars = MyMalloc(tl);
   if (!newchars)
-    {
-     saveerr(ads,errno);
-     MyFree(newptrs);
-     return;
-    }
+  {
+    saveerr(ads, errno);
+    MyFree(newptrs);
+    return;
+  }
 
-  bufp= buf;
-  pp= newptrs;
-  while (nextword(&bufp,&word,&l)) {
-    *pp++= newchars;
-    memcpy(newchars,word,l);
+  bufp = buf;
+  pp = newptrs;
+  while (nextword(&bufp, &word, &l))
+  {
+    *pp++ = newchars;
+    memcpy(newchars, word, l);
     newchars += l;
     *newchars++ = 0;
   }
 
   freesearchlist(ads);
-  ads->nsearchlist= count;
-  ads->searchlist= newptrs;
+  ads->nsearchlist = count;
+  ads->searchlist = newptrs;
 }
 
-static void ccf_sortlist(adns_state ads, const char *fn, int lno, const char *buf) {
+static void
+ccf_sortlist(adns_state ads, const char *fn, int lno, const char *buf)
+{
   const char *word;
   char tbuf[200], *slash, *ep;
   struct in_addr base, mask;
   int l;
   unsigned long initial, baselocal;
 
-  if (!buf) return;
-  
-  ads->nsortlist= 0;
-  while (nextword(&buf,&word,&l)) {
-    if (ads->nsortlist >= MAXSORTLIST) {
-      adns__diag(ads,-1,0,"too many sortlist entries, ignoring %.*s onwards",l,word);
+  if (!buf)
+    return;
+
+  ads->nsortlist = 0;
+  while (nextword(&buf, &word, &l))
+  {
+    if (ads->nsortlist >= MAXSORTLIST)
+    {
+      adns__diag(ads, -1, 0,
+                 "too many sortlist entries, ignoring %.*s onwards", l, word);
       return;
     }
 
-    if (l >= sizeof(tbuf)) {
-      configparseerr(ads,fn,lno,"sortlist entry `%.*s' too long",l,word);
+    if (l >= sizeof(tbuf))
+    {
+      configparseerr(ads, fn, lno, "sortlist entry `%.*s' too long", l, word);
       continue;
     }
-    
-    memcpy(tbuf,word,l); tbuf[l]= 0;
-    slash= strchr(tbuf,'/');
-    if (slash) *slash++= 0;
-    
-    if (inetpton(AF_INET, tbuf,&base) <= 0) {
-      configparseerr(ads,fn,lno,"invalid address `%s' in sortlist",tbuf);
+
+    memcpy(tbuf, word, l);
+    tbuf[l] = 0;
+    slash = strchr(tbuf, '/');
+    if (slash)
+      *slash++ = 0;
+
+    if (inetpton(AF_INET, tbuf, &base) <= 0)
+    {
+      configparseerr(ads, fn, lno, "invalid address `%s' in sortlist", tbuf);
       continue;
     }
 
-    if (slash) {
-      if (strchr(slash,'.')) {
-       if (inetpton(AF_INET, slash,&mask) <= 0) {
-         configparseerr(ads,fn,lno,"invalid mask `%s' in sortlist",slash);
-         continue;
-       }
-       if (base.s_addr & ~mask.s_addr) {
-         configparseerr(ads,fn,lno,
-                        "mask `%s' in sortlist overlaps address `%s'",slash,tbuf);
-         continue;
-       }
-      } else {
-       initial= strtoul(slash,&ep,10);
-       if (*ep || initial>32) {
-         configparseerr(ads,fn,lno,"mask length `%s' invalid",slash);
-         continue;
-       }
-       mask.s_addr= htonl((0x0ffffffffUL) << (32-initial));
+    if (slash)
+    {
+      if (strchr(slash, '.'))
+      {
+        if (inetpton(AF_INET, slash, &mask) <= 0)
+        {
+          configparseerr(ads, fn, lno,
+                         "invalid mask `%s' in sortlist", slash);
+          continue;
+        }
+        if (base.s_addr & ~mask.s_addr)
+        {
+          configparseerr(ads, fn, lno,
+                         "mask `%s' in sortlist overlaps address `%s'",
+                         slash, tbuf);
+          continue;
+        }
       }
-    } else {
-      baselocal= ntohl(base.s_addr);
-      if (!baselocal & 0x080000000UL) /* class A */
-       mask.s_addr= htonl(0x0ff000000UL);
+      else
+      {
+        initial = strtoul(slash, &ep, 10);
+        if (*ep || initial > 32)
+        {
+          configparseerr(ads, fn, lno, "mask length `%s' invalid", slash);
+          continue;
+        }
+        mask.s_addr = htonl((0x0ffffffffUL) << (32 - initial));
+      }
+    }
+    else
+    {
+      baselocal = ntohl(base.s_addr);
+      if (!baselocal & 0x080000000UL)   /* class A */
+        mask.s_addr = htonl(0x0ff000000UL);
       else if ((baselocal & 0x0c0000000UL) == 0x080000000UL)
-       mask.s_addr= htonl(0x0ffff0000UL); /* class B */
+        mask.s_addr = htonl(0x0ffff0000UL);     /* class B */
       else if ((baselocal & 0x0f0000000UL) == 0x0e0000000UL)
-       mask.s_addr= htonl(0x0ff000000UL); /* class C */
-      else {
-       configparseerr(ads,fn,lno,
-                      "network address `%s' in sortlist is not in classed ranges,"
-                      " must specify mask explicitly", tbuf);
-       continue;
+        mask.s_addr = htonl(0x0ff000000UL);     /* class C */
+      else
+      {
+        configparseerr(ads, fn, lno,
+                       "network address `%s' in sortlist is not in classed ranges,"
+                       " must specify mask explicitly", tbuf);
+        continue;
       }
     }
 
-    ads->sortlist[ads->nsortlist].base= base;
-    ads->sortlist[ads->nsortlist].mask= mask;
+    ads->sortlist[ads->nsortlist].base = base;
+    ads->sortlist[ads->nsortlist].mask = mask;
     ads->nsortlist++;
   }
 }
 
-static void ccf_options(adns_state ads, const char *fn, int lno, const char *buf) {
+static void
+ccf_options(adns_state ads, const char *fn, int lno, const char *buf)
+{
   const char *word;
   char *ep;
   unsigned long v;
   int l;
 
-  if (!buf) return;
+  if (!buf)
+    return;
 
-  while (nextword(&buf,&word,&l)) {
-    if (l==5 && !memcmp(word,"debug",5)) {
+  while (nextword(&buf, &word, &l))
+  {
+    if (l == 5 && !memcmp(word, "debug", 5))
+    {
       ads->iflags |= adns_if_debug;
       continue;
     }
-    if (l>=6 && !memcmp(word,"ndots:",6)) {
-      v= strtoul(word+6,&ep,10);
-      if (l==6 || ep != word+l || v > INT_MAX) {
-       configparseerr(ads,fn,lno,"option `%.*s' malformed or has bad value",l,word);
-       continue;
+    if (l >= 6 && !memcmp(word, "ndots:", 6))
+    {
+      v = strtoul(word + 6, &ep, 10);
+      if (l == 6 || ep != word + l || v > INT_MAX)
+      {
+        configparseerr(ads, fn, lno,
+                       "option `%.*s' malformed or has bad value", l, word);
+        continue;
       }
-      ads->searchndots= v;
+      ads->searchndots = v;
       continue;
     }
-    if (l>=12 && !memcmp(word,"adns_checkc:",12)) {
-      if (!strcmp(word+12,"none")) {
-       ads->iflags &= ~adns_if_checkc_freq;
-       ads->iflags |= adns_if_checkc_entex;
-      } else if (!strcmp(word+12,"entex")) {
-       ads->iflags &= ~adns_if_checkc_freq;
-       ads->iflags |= adns_if_checkc_entex;
-      } else if (!strcmp(word+12,"freq")) {
-       ads->iflags |= adns_if_checkc_freq;
-      } else {
-       configparseerr(ads,fn,lno, "option adns_checkc has bad value `%s' "
-                      "(must be none, entex or freq", word+12);
+    if (l >= 12 && !memcmp(word, "adns_checkc:", 12))
+    {
+      if (!strcmp(word + 12, "none"))
+      {
+        ads->iflags &= ~adns_if_checkc_freq;
+        ads->iflags |= adns_if_checkc_entex;
+      }
+      else if (!strcmp(word + 12, "entex"))
+      {
+        ads->iflags &= ~adns_if_checkc_freq;
+        ads->iflags |= adns_if_checkc_entex;
+      }
+      else if (!strcmp(word + 12, "freq"))
+      {
+        ads->iflags |= adns_if_checkc_freq;
+      }
+      else
+      {
+        configparseerr(ads, fn, lno,
+                       "option adns_checkc has bad value `%s' "
+                       "(must be none, entex or freq", word + 12);
       }
       continue;
     }
-    adns__diag(ads,-1,0,"%s:%d: unknown option `%.*s'", fn,lno, l,word);
+    adns__diag(ads, -1, 0, "%s:%d: unknown option `%.*s'", fn, lno, l, word);
   }
 }
 
-static void ccf_clearnss(adns_state ads, const char *fn, int lno, const char *buf) {
-  ads->nservers= 0;
+static void
+ccf_clearnss(adns_state ads, const char *fn, int lno, const char *buf)
+{
+  ads->nservers = 0;
 }
 
-static void ccf_include(adns_state ads, const char *fn, int lno, const char *buf) {
-  if (!*buf) {
-    configparseerr(ads,fn,lno,"`include' directive with no filename");
+static void
+ccf_include(adns_state ads, const char *fn, int lno, const char *buf)
+{
+  if (!*buf)
+  {
+    configparseerr(ads, fn, lno, "`include' directive with no filename");
     return;
   }
-  readconfig(ads,buf,1);
+  readconfig(ads, buf, 1);
 }
 
-static const struct configcommandinfo {
+static const struct configcommandinfo
+{
   const char *name;
-  void (*fn)(adns_state ads, const char *fn, int lno, const char *buf);
-} configcommandinfos[]= {
-  { "nameserver",        ccf_nameserver  },
-  { "domain",            ccf_search      },
-  { "search",            ccf_search      },
-  { "sortlist",          ccf_sortlist    },
-  { "options",           ccf_options     },
-  { "clearnameservers",  ccf_clearnss    },
-  { "include",           ccf_include     },
-  {  0                                   }
+  void (*fn) (adns_state ads, const char *fn, int lno, const char *buf);
+}
+configcommandinfos[] =
+{
+  {
+  "nameserver", ccf_nameserver}
+  ,
+  {
+  "domain", ccf_search}
+  ,
+  {
+  "search", ccf_search}
+  ,
+  {
+  "sortlist", ccf_sortlist}
+  ,
+  {
+  "options", ccf_options}
+  ,
+  {
+  "clearnameservers", ccf_clearnss}
+  ,
+  {
+  "include", ccf_include}
+  ,
+  {
+  0}
 };
 
-typedef union {
+typedef union
+{
   FBFILE *file;
   const char *text;
-} getline_ctx;
+}
+getline_ctx;
 
-static int gl_file(adns_state ads, getline_ctx *src_io, const char *filename,
-                  int lno, char *buf, int buflen) {
-  FBFILE *file= src_io->file;
+static int
+gl_file(adns_state ads, getline_ctx * src_io, const char *filename,
+        int lno, char *buf, int buflen)
+{
+  FBFILE *file = src_io->file;
   int c, i;
   char *p;
 
-  p= buf;
+  p = buf;
   buflen--;
-  i= 0;
-    
-  for (;;) { /* loop over chars */
-    if (i == buflen) {
-      adns__diag(ads,-1,0,"%s:%d: line too long, ignored",filename,lno);
+  i = 0;
+
+  for (;;)
+  {                             /* loop over chars */
+    if (i == buflen)
+    {
+      adns__diag(ads, -1, 0, "%s:%d: line too long, ignored", filename, lno);
       goto x_badline;
     }
-    c= fbgetc(file);
-    if (!c) {
-      adns__diag(ads,-1,0,"%s:%d: line contains nul, ignored",filename,lno);
+    c = fbgetc(file);
+    if (!c)
+    {
+      adns__diag(ads, -1, 0, "%s:%d: line contains nul, ignored",
+                 filename, lno);
       goto x_badline;
-    } else if (c == '\n') {
+    }
+    else if (c == '\n')
+    {
       break;
-    } else if (c == EOF) {
-      if (!i) return -1;
+    }
+    else if (c == EOF)
+    {
+      if (!i)
+        return -1;
       break;
-    } else {
-      *p++= c;
+    }
+    else
+    {
+      *p++ = c;
       i++;
     }
   }
 
-  *p++= 0;
+  *p++ = 0;
   return i;
 
- x_badline:
-  saveerr(ads,EINVAL);
-  while ((c= fbgetc(file)) != EOF && c != '\n');
+x_badline:
+  saveerr(ads, EINVAL);
+  while ((c = fbgetc(file)) != EOF && c != '\n');
   return -2;
 }
 
-static int gl_text(adns_state ads, getline_ctx *src_io, const char *filename,
-                  int lno, char *buf, int buflen)
+static int
+gl_text(adns_state ads, getline_ctx * src_io, const char *filename,
+        int lno, char *buf, int buflen)
 {
-  const char *cp= src_io->text;
+  const char *cp = src_io->text;
   int l;
 
-  if (!cp || !*cp) return -1;
+  if (!cp || !*cp)
+    return -1;
 
-  if (*cp == ';' || *cp == '\n') cp++;
-  l= strcspn(cp,";\n");
-  src_io->text = cp+l;
+  if (*cp == ';' || *cp == '\n')
+    cp++;
+  l = strcspn(cp, ";\n");
+  src_io->text = cp + l;
 
-  if (l >= buflen) {
-    adns__diag(ads,-1,0,"%s:%d: line too long, ignored",filename,lno);
-    saveerr(ads,EINVAL);
+  if (l >= buflen)
+  {
+    adns__diag(ads, -1, 0, "%s:%d: line too long, ignored", filename, lno);
+    saveerr(ads, EINVAL);
     return -2;
   }
-    
-  memcpy(buf,cp,l);
-  buf[l]= 0;
+
+  memcpy(buf, cp, l);
+  buf[l] = 0;
   return l;
 }
 
-static void readconfiggeneric(adns_state ads, const char *filename,
-                             int (*getline)(adns_state ads, getline_ctx*,
-                                            const char *filename, int lno,
-                                            char *buf, int buflen),
-                             /* Returns >=0 for success, -1 for EOF or error
-                              * (error will have been reported), or -2 for
-                              * bad line was encountered, try again.
-                              */
-                             getline_ctx gl_ctx)
+static void
+readconfiggeneric(adns_state ads, const char *filename,
+                  int (*getline) (adns_state ads, getline_ctx *,
+                                  const char *filename, int lno,
+                                  char *buf, int buflen),
+                  /* Returns >=0 for success, -1 for EOF or error
+                   * (error will have been reported), or -2 for
+                   * bad line was encountered, try again.
+                   */
+                  getline_ctx gl_ctx)
 {
   char linebuf[2000], *p, *q;
   int lno, l, dirl;
   const struct configcommandinfo *ccip;
 
-  for (lno=1;
-       (l= getline(ads,&gl_ctx, filename,lno, linebuf,sizeof(linebuf))) != -1;
-       lno++) {
-    if (l == -2) continue;
-    while (l>0 && ctype_whitespace(linebuf[l-1])) l--;
-    linebuf[l]= 0;
-    p= linebuf;
-    while (ctype_whitespace(*p)) p++;
-    if (*p == '#' || !*p) continue;
-    q= p;
-    while (*q && !ctype_whitespace(*q)) q++;
-    dirl= q-p;
-    for (ccip=configcommandinfos;
-        ccip->name && !(strlen(ccip->name)==dirl && !memcmp(ccip->name,p,q-p));
-        ccip++);
-    if (!ccip->name) {
-      adns__diag(ads,-1,0,"%s:%d: unknown configuration directive `%.*s'",
-                filename,lno,q-p,p);
+  for (lno = 1;
+       (l =
+        getline(ads, &gl_ctx, filename, lno, linebuf,
+                sizeof(linebuf))) != -1; lno++)
+  {
+    if (l == -2)
+      continue;
+    while (l > 0 && ctype_whitespace(linebuf[l - 1]))
+      l--;
+    linebuf[l] = 0;
+    p = linebuf;
+    while (ctype_whitespace(*p))
+      p++;
+    if (*p == '#' || !*p)
+      continue;
+    q = p;
+    while (*q && !ctype_whitespace(*q))
+      q++;
+    dirl = q - p;
+    for (ccip = configcommandinfos;
+         ccip->name && !(strlen(ccip->name) == dirl
+                         && !memcmp(ccip->name, p, q - p)); ccip++);
+    if (!ccip->name)
+    {
+      adns__diag(ads, -1, 0,
+                 "%s:%d: unknown configuration directive `%.*s'",
+                 filename, lno, q - p, p);
       continue;
     }
-    while (ctype_whitespace(*q)) q++;
-    ccip->fn(ads,filename,lno,q);
+    while (ctype_whitespace(*q))
+      q++;
+    ccip->fn(ads, filename, lno, q);
   }
 }
 
-static const char *instrum_getenv(adns_state ads, const char *envvar) {
+static const char *
+instrum_getenv(adns_state ads, const char *envvar)
+{
   const char *value;
 
-  value= getenv(envvar);
-  if (!value) adns__debug(ads,-1,0,"environment variable %s not set",envvar);
-  else adns__debug(ads,-1,0,"environment variable %s set to `%s'",envvar,value);
+  value = getenv(envvar);
+  if (!value)
+    adns__debug(ads, -1, 0, "environment variable %s not set", envvar);
+  else
+    adns__debug(ads, -1, 0, "environment variable %s set to `%s'", envvar,
+                value);
   return value;
 }
 
-static void readconfig(adns_state ads, const char *filename, int warnmissing) {
+static void
+readconfig(adns_state ads, const char *filename, int warnmissing)
+{
   getline_ctx gl_ctx;
-  
-  gl_ctx.file= fbopen(filename,"r");
-  if (gl_ctx.file == NULL) {
-    if (errno == ENOENT) {
+
+  gl_ctx.file = fbopen(filename, "r");
+  if (gl_ctx.file == NULL)
+  {
+    if (errno == ENOENT)
+    {
       if (warnmissing)
-       adns__debug(ads,-1,0,"configuration file `%s' does not exist",filename);
+        adns__debug(ads, -1, 0, "configuration file `%s' does not exist",
+                    filename);
       return;
     }
-    saveerr(ads,errno);
-    adns__diag(ads,-1,0,"cannot open configuration file `%s': %s",
-              filename,strerror(errno));
+    saveerr(ads, errno);
+    adns__diag(ads, -1, 0, "cannot open configuration file `%s': %s",
+               filename, strerror(errno));
     return;
   }
 
-  readconfiggeneric(ads,filename,gl_file,gl_ctx);
-  
+  readconfiggeneric(ads, filename, gl_file, gl_ctx);
+
   fbclose(gl_ctx.file);
 }
 
-static void readconfigtext(adns_state ads, const char *text, const char *showname) {
+static void
+readconfigtext(adns_state ads, const char *text, const char *showname)
+{
   getline_ctx gl_ctx;
-  
-  gl_ctx.text= text;
-  readconfiggeneric(ads,showname,gl_text,gl_ctx);
+
+  gl_ctx.text = text;
+  readconfiggeneric(ads, showname, gl_text, gl_ctx);
 }
-  
-static void readconfigenv(adns_state ads, const char *envvar) {
+
+static void
+readconfigenv(adns_state ads, const char *envvar)
+{
   const char *filename;
 
-  if (ads->iflags & adns_if_noenv) {
-    adns__debug(ads,-1,0,"not checking environment variable `%s'",envvar);
+  if (ads->iflags & adns_if_noenv)
+  {
+    adns__debug(ads, -1, 0, "not checking environment variable `%s'", envvar);
     return;
   }
-  filename= instrum_getenv(ads,envvar);
-  if (filename) readconfig(ads,filename,1);
+  filename = instrum_getenv(ads, envvar);
+  if (filename)
+    readconfig(ads, filename, 1);
 }
 
-static void readconfigenvtext(adns_state ads, const char *envvar) {
+static void
+readconfigenvtext(adns_state ads, const char *envvar)
+{
   const char *textdata;
 
-  if (ads->iflags & adns_if_noenv) {
-    adns__debug(ads,-1,0,"not checking environment variable `%s'",envvar);
+  if (ads->iflags & adns_if_noenv)
+  {
+    adns__debug(ads, -1, 0, "not checking environment variable `%s'", envvar);
     return;
   }
-  textdata= instrum_getenv(ads,envvar);
-  if (textdata) readconfigtext(ads,textdata,envvar);
+  textdata = instrum_getenv(ads, envvar);
+  if (textdata)
+    readconfigtext(ads, textdata, envvar);
 }
 
 
-int adns__setnonblock(adns_state ads, int fd) {
+int
+adns__setnonblock(adns_state ads, int fd)
+{
   int r;
 #ifdef VMS
   int val = 1;
-  r = ioctl(fd, FIONBIO, &val); if (r < 0) return errno;
+
+  r = ioctl(fd, FIONBIO, &val);
+  if (r < 0)
+    return errno;
 #else
-  r= fcntl(fd,F_GETFL,0); if (r<0) return errno;
+  r = fcntl(fd, F_GETFL, 0);
+  if (r < 0)
+    return errno;
   r |= O_NONBLOCK;
-  r= fcntl(fd,F_SETFL,r); if (r<0) return errno;
+  r = fcntl(fd, F_SETFL, r);
+  if (r < 0)
+    return errno;
 #endif
   return 0;
 }
 
-static int init_begin(adns_state *ads_r, adns_initflags flags, FBFILE *diagfile)
+static int
+init_begin(adns_state * ads_r, adns_initflags flags, FBFILE * diagfile)
 {
   adns_state ads;
-  
+
 
   ads = MyMalloc(sizeof(*ads));
 
   /* Under hybrid, MyMalloc would have aborted already */
 #if 0
- if (!ads) return errno;
+  if (!ads)
+    return errno;
 #endif
 
-  ads->iflags= flags;
-  ads->diagfile= diagfile;
-  ads->configerrno= 0;
+  ads->iflags = flags;
+  ads->diagfile = diagfile;
+  ads->configerrno = 0;
   ADNS_LIST_INIT(ads->udpw);
   ADNS_LIST_INIT(ads->tcpw);
   ADNS_LIST_INIT(ads->childw);
   ADNS_LIST_INIT(ads->output);
-  ads->forallnext= 0;
-  ads->nextid= 0x311f;
-  ads->udpsocket= ads->tcpsocket= -1;
+  ads->forallnext = 0;
+  ads->nextid = 0x311f;
+  ads->udpsocket = ads->tcpsocket = -1;
   adns__vbuf_init(&ads->tcpsend);
   adns__vbuf_init(&ads->tcprecv);
-  ads->tcprecv_skip= 0;
-  ads->nservers= ads->nsortlist= ads->nsearchlist= ads->tcpserver= 0;
-  ads->searchndots= 1;
-  ads->tcpstate= server_disconnected;
+  ads->tcprecv_skip = 0;
+  ads->nservers = ads->nsortlist = ads->nsearchlist = ads->tcpserver = 0;
+  ads->searchndots = 1;
+  ads->tcpstate = server_disconnected;
   timerclear(&ads->tcptimeout);
-  ads->searchlist= 0;
+  ads->searchlist = 0;
 
-  *ads_r= ads;
+  *ads_r = ads;
   return 0;
 }
 
-static int init_finish(adns_state ads) {
+static int
+init_finish(adns_state ads)
+{
   struct in_addr ia;
   int r;
-  
+
   if (!ads->nservers)
-    {
+  {
 #if 0
-      if (ads->diagfile && ads->iflags & adns_if_debug)
-       fprintf(ads->diagfile,"adns: no nameservers, using localhost\n");
+    if (ads->diagfile && ads->iflags & adns_if_debug)
+      fprintf(ads->diagfile, "adns: no nameservers, using localhost\n");
 #endif
-      ia.s_addr= htonl(INADDR_LOOPBACK);
-      addserver(ads,ia);
+    ia.s_addr = htonl(INADDR_LOOPBACK);
+    addserver(ads, ia);
   }
 
   ads->udpsocket = comm_open(AF_INET, SOCK_DGRAM, 0, "UDP Resolver socket");
-  if (ads->udpsocket<0) { ilog(L_CRIT, "Failed to open socket"); r= errno; goto x_free; }
+  if (ads->udpsocket < 0)
+  {
+    ilog(L_CRIT, "Failed to open socket");
+    r = errno;
+    goto x_free;
+  }
+
+  r = adns__setnonblock(ads, ads->udpsocket);
+  if (r)
+  {
+    ilog(L_CRIT, "Failed to make socket non-blocking");
+    r = errno;
+    goto x_closeudp;
+  }
 
-  r= adns__setnonblock(ads,ads->udpsocket);
-  if (r) { ilog(L_CRIT, "Failed to make socket non-blocking"); r= errno; goto x_closeudp; }
-  
   return 0;
 
- x_closeudp:
+x_closeudp:
   fd_close(ads->udpsocket);
- x_free:
+x_free:
   MyFree(ads);
   ilog(L_CRIT, "Returning from init_finish: r = %d", r);
   return r;
 }
 
-static void init_abort(adns_state ads) {
-  if (ads->nsearchlist) {
+static void
+init_abort(adns_state ads)
+{
+  if (ads->nsearchlist)
+  {
     MyFree(ads->searchlist[0]);
     MyFree(ads->searchlist);
   }
   MyFree(ads);
 }
 
-int adns_init(adns_state *ads_r, adns_initflags flags, FBFILE *diagfile) {
+int
+adns_init(adns_state * ads_r, adns_initflags flags, FBFILE * diagfile)
+{
   adns_state ads;
   const char *res_options, *adns_res_options;
   int r;
-  
-  r= init_begin(&ads, flags, diagfile);
-  if (r) return r;
-  
-  res_options= instrum_getenv(ads,"RES_OPTIONS");
-  adns_res_options= instrum_getenv(ads,"ADNS_RES_OPTIONS");
-  ccf_options(ads,"RES_OPTIONS",-1,res_options);
-  ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options);
+
+  r = init_begin(&ads, flags, diagfile);
+  if (r)
+    return r;
+
+  res_options = instrum_getenv(ads, "RES_OPTIONS");
+  adns_res_options = instrum_getenv(ads, "ADNS_RES_OPTIONS");
+  ccf_options(ads, "RES_OPTIONS", -1, res_options);
+  ccf_options(ads, "ADNS_RES_OPTIONS", -1, adns_res_options);
 
 #ifndef VMS
-  readconfig(ads,"/etc/resolv.conf",0);
-  readconfig(ads,"/etc/resolv-adns.conf",0);
+  readconfig(ads, "/etc/resolv.conf", 0);
+  readconfig(ads, "/etc/resolv-adns.conf", 0);
 #else
   ilog(L_CRIT, "Opening []RESOLV.CONF (VMS)");
-  readconfig(ads,"[]RESOLV.CONF",0);
+  readconfig(ads, "[]RESOLV.CONF", 0);
 #endif
-  readconfigenv(ads,"RES_CONF");
-  readconfigenv(ads,"ADNS_RES_CONF");
+  readconfigenv(ads, "RES_CONF");
+  readconfigenv(ads, "ADNS_RES_CONF");
 
-  readconfigenvtext(ads,"RES_CONF_TEXT");
-  readconfigenvtext(ads,"ADNS_RES_CONF_TEXT");
+  readconfigenvtext(ads, "RES_CONF_TEXT");
+  readconfigenvtext(ads, "ADNS_RES_CONF_TEXT");
 
-  ccf_options(ads,"RES_OPTIONS",-1,res_options);
-  ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options);
+  ccf_options(ads, "RES_OPTIONS", -1, res_options);
+  ccf_options(ads, "ADNS_RES_OPTIONS", -1, adns_res_options);
 
-  ccf_search(ads,"LOCALDOMAIN",-1,instrum_getenv(ads,"LOCALDOMAIN"));
-  ccf_search(ads,"ADNS_LOCALDOMAIN",-1,instrum_getenv(ads,"ADNS_LOCALDOMAIN"));
+  ccf_search(ads, "LOCALDOMAIN", -1, instrum_getenv(ads, "LOCALDOMAIN"));
+  ccf_search(ads, "ADNS_LOCALDOMAIN", -1,
+             instrum_getenv(ads, "ADNS_LOCALDOMAIN"));
 
-  if (ads->configerrno && ads->configerrno != EINVAL) {
+  if (ads->configerrno && ads->configerrno != EINVAL)
+  {
     ilog(L_CRIT, "Failed at 1");
-    r= ads->configerrno;
+    r = ads->configerrno;
     init_abort(ads);
     return r;
   }
 
-  r= init_finish(ads);
-  if (r) return r;
+  r = init_finish(ads);
+  if (r)
+    return r;
 
-  adns__consistency(ads,0,cc_entex);
-  *ads_r= ads;
+  adns__consistency(ads, 0, cc_entex);
+  *ads_r = ads;
   return 0;
 }
 
-int adns_init_strcfg(adns_state *ads_r, adns_initflags flags,
-                    FBFILE *diagfile, const char *configtext) {
+int
+adns_init_strcfg(adns_state * ads_r, adns_initflags flags,
+                 FBFILE * diagfile, const char *configtext)
+{
   adns_state ads;
   int r;
 
-  r= init_begin(&ads, flags, diagfile);  if (r) return r;
+  r = init_begin(&ads, flags, diagfile);
+  if (r)
+    return r;
 
-  readconfigtext(ads,configtext,"<supplied configuration text>");
-  if (ads->configerrno) {
-    r= ads->configerrno;
+  readconfigtext(ads, configtext, "<supplied configuration text>");
+  if (ads->configerrno)
+  {
+    r = ads->configerrno;
     init_abort(ads);
     return r;
   }
 
-  r= init_finish(ads);  if (r) return r;
-  adns__consistency(ads,0,cc_entex);
-  *ads_r= ads;
+  r = init_finish(ads);
+  if (r)
+    return r;
+  adns__consistency(ads, 0, cc_entex);
+  *ads_r = ads;
   return 0;
 }
 
 
-void adns_finish(adns_state ads) {
-  adns__consistency(ads,0,cc_entex);
-  for (;;) {
-    if (ads->udpw.head) adns_cancel(ads->udpw.head);
-    else if (ads->tcpw.head) adns_cancel(ads->tcpw.head);
-    else if (ads->childw.head) adns_cancel(ads->childw.head);
-    else if (ads->output.head) adns_cancel(ads->output.head);
-    else break;
+void
+adns_finish(adns_state ads)
+{
+  adns__consistency(ads, 0, cc_entex);
+  for (;;)
+  {
+    if (ads->udpw.head)
+      adns_cancel(ads->udpw.head);
+    else if (ads->tcpw.head)
+      adns_cancel(ads->tcpw.head);
+    else if (ads->childw.head)
+      adns_cancel(ads->childw.head);
+    else if (ads->output.head)
+      adns_cancel(ads->output.head);
+    else
+      break;
   }
   fd_close(ads->udpsocket);
-  if (ads->tcpsocket >= 0) fd_close(ads->tcpsocket);
+  if (ads->tcpsocket >= 0)
+    fd_close(ads->tcpsocket);
   adns__vbuf_free(&ads->tcpsend);
   adns__vbuf_free(&ads->tcprecv);
   freesearchlist(ads);
   MyFree(ads);
 }
 
-void adns_forallqueries_begin(adns_state ads) {
-  adns__consistency(ads,0,cc_entex);
-  ads->forallnext=
+void
+adns_forallqueries_begin(adns_state ads)
+{
+  adns__consistency(ads, 0, cc_entex);
+  ads->forallnext =
     ads->udpw.head ? ads->udpw.head :
     ads->tcpw.head ? ads->tcpw.head :
-    ads->childw.head ? ads->childw.head :
-    ads->output.head;
+    ads->childw.head ? ads->childw.head : ads->output.head;
 }
-  
-adns_query adns_forallqueries_next(adns_state ads, void **context_r) {
+
+adns_query
+adns_forallqueries_next(adns_state ads, void **context_r)
+{
   adns_query qu, nqu;
 
-  adns__consistency(ads,0,cc_entex);
-  nqu= ads->forallnext;
-  for (;;) {
-    qu= nqu;
-    if (!qu) return 0;
-    if (qu->next) {
-      nqu= qu->next;
-    } else if (qu == ads->udpw.tail) {
-      nqu=
-       ads->tcpw.head ? ads->tcpw.head :
-       ads->childw.head ? ads->childw.head :
-       ads->output.head;
-    } else if (qu == ads->tcpw.tail) {
-      nqu=
-       ads->childw.head ? ads->childw.head :
-       ads->output.head;
-    } else if (qu == ads->childw.tail) {
-      nqu= ads->output.head;
-    } else {
-      nqu= 0;
+  adns__consistency(ads, 0, cc_entex);
+  nqu = ads->forallnext;
+  for (;;)
+  {
+    qu = nqu;
+    if (!qu)
+      return 0;
+    if (qu->next)
+    {
+      nqu = qu->next;
     }
-    if (!qu->parent) break;
+    else if (qu == ads->udpw.tail)
+    {
+      nqu =
+        ads->tcpw.head ? ads->tcpw.head :
+        ads->childw.head ? ads->childw.head : ads->output.head;
+    }
+    else if (qu == ads->tcpw.tail)
+    {
+      nqu = ads->childw.head ? ads->childw.head : ads->output.head;
+    }
+    else if (qu == ads->childw.tail)
+    {
+      nqu = ads->output.head;
+    }
+    else
+    {
+      nqu = 0;
+    }
+    if (!qu->parent)
+      break;
   }
-  ads->forallnext= nqu;
-  if (context_r) *context_r= qu->ctx.ext;
+  ads->forallnext = nqu;
+  if (context_r)
+    *context_r = qu->ctx.ext;
   return qu;
 }
 
-int adns__rereadconfig(adns_state ads)
+int
+adns__rereadconfig(adns_state ads)
 {
   struct in_addr ia;
-  adns__consistency(ads,0,cc_entex);
-  ads->nservers = 0;   
+  adns__consistency(ads, 0, cc_entex);
+  ads->nservers = 0;
 #ifndef VMS
-  readconfig(ads,"/etc/resolv.conf",0);
+  readconfig(ads, "/etc/resolv.conf", 0);
 #else
-  readconfig(ads,"[]resolv.conf",0);
+  readconfig(ads, "[]resolv.conf", 0);
 #endif
   if (!ads->nservers)
   {
-      ia.s_addr= htonl(INADDR_LOOPBACK);
-      addserver(ads,ia);
+    ia.s_addr = htonl(INADDR_LOOPBACK);
+    addserver(ads, ia);
   }
-  adns__consistency(ads,0,cc_entex);
+  adns__consistency(ads, 0, cc_entex);
   return 0;
 }
index 0e28b31ffce761c04a7cbde334c21fc255a2e1da..3b697683783aaaca55af027808faf9b070b670d6 100644 (file)
@@ -25,7 +25,7 @@
  *  along with this program; if not, write to the Free Software Foundation,
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  *
- * $Id: transmit.c,v 1.1 2002/01/04 09:10:59 a1kmm Exp $
+ * $Id: transmit.c,v 1.2 2002/04/27 02:48:47 a1kmm Exp $
  */
 
 #include <errno.h>
 #define MKQUERY_ADDW(w) (MKQUERY_ADDB(((w)>>8)&0x0ff), MKQUERY_ADDB((w)&0x0ff))
 #define MKQUERY_STOP(vb) ((vb)->used= rqp-(vb)->buf)
 
-static adns_status mkquery_header(adns_state ads, vbuf *vb, int *id_r, int qdlen) {
+static adns_status
+mkquery_header(adns_state ads, vbuf * vb, int *id_r, int qdlen)
+{
   int id;
   byte *rqp;
-  
-  if (!adns__vbuf_ensure(vb,DNS_HDRSIZE+qdlen+4)) return adns_s_nomemory;
 
-  vb->used= 0;
+  if (!adns__vbuf_ensure(vb, DNS_HDRSIZE + qdlen + 4))
+    return adns_s_nomemory;
+
+  vb->used = 0;
   MKQUERY_START(vb);
-  
-  *id_r= id= (ads->nextid++) & 0x0ffff;
+
+  *id_r = id = (ads->nextid++) & 0x0ffff;
   MKQUERY_ADDW(id);
-  MKQUERY_ADDB(0x01); /* QR=Q(0), OPCODE=QUERY(0000), !AA, !TC, RD */
-  MKQUERY_ADDB(0x00); /* !RA, Z=000, RCODE=NOERROR(0000) */
-  MKQUERY_ADDW(1); /* QDCOUNT=1 */
-  MKQUERY_ADDW(0); /* ANCOUNT=0 */
-  MKQUERY_ADDW(0); /* NSCOUNT=0 */
-  MKQUERY_ADDW(0); /* ARCOUNT=0 */
+  MKQUERY_ADDB(0x01);           /* QR=Q(0), OPCODE=QUERY(0000), !AA, !TC, RD */
+  MKQUERY_ADDB(0x00);           /* !RA, Z=000, RCODE=NOERROR(0000) */
+  MKQUERY_ADDW(1);              /* QDCOUNT=1 */
+  MKQUERY_ADDW(0);              /* ANCOUNT=0 */
+  MKQUERY_ADDW(0);              /* NSCOUNT=0 */
+  MKQUERY_ADDW(0);              /* ARCOUNT=0 */
 
   MKQUERY_STOP(vb);
-  
+
   return adns_s_ok;
 }
 
-static adns_status mkquery_footer(vbuf *vb, adns_rrtype type) {
+static adns_status
+mkquery_footer(vbuf * vb, adns_rrtype type)
+{
   byte *rqp;
 
   MKQUERY_START(vb);
-  MKQUERY_ADDW(type & adns__rrt_typemask); /* QTYPE */
-  MKQUERY_ADDW(DNS_CLASS_IN); /* QCLASS=IN */
+  MKQUERY_ADDW(type & adns__rrt_typemask);      /* QTYPE */
+  MKQUERY_ADDW(DNS_CLASS_IN);   /* QCLASS=IN */
   MKQUERY_STOP(vb);
   assert(vb->used <= vb->avail);
-  
+
   return adns_s_ok;
 }
 
-adns_status adns__mkquery(adns_state ads, vbuf *vb, int *id_r,
-                         const char *owner, int ol,
-                         const typeinfo *typei, adns_queryflags flags) {
+adns_status
+adns__mkquery(adns_state ads, vbuf * vb, int *id_r,
+              const char *owner, int ol,
+              const typeinfo * typei, adns_queryflags flags)
+{
   int ll, c, nbytes;
   byte label[255], *rqp;
   const char *p, *pe;
   adns_status st;
 
-  st= mkquery_header(ads,vb,id_r,ol+2); if (st) return st;
-  
+  st = mkquery_header(ads, vb, id_r, ol + 2);
+  if (st)
+    return st;
+
   MKQUERY_START(vb);
 
-  p= owner; pe= owner+ol;
-  nbytes= 0;
-  while (p!=pe) {
-    ll= 0;
-    while (p!=pe && (c= *p++)!='.') {
-      if (c=='\\') {
-       if (!(flags & adns_qf_quoteok_query)) return adns_s_querydomaininvalid;
-       if (ctype_digit(p[0])) {
-         if (ctype_digit(p[1]) && ctype_digit(p[2])) {
-            c = (*p++ - '0')*100;
-            c += (*p++ - '0')*10;
+  p = owner;
+  pe = owner + ol;
+  nbytes = 0;
+  while (p != pe)
+  {
+    ll = 0;
+    while (p != pe && (c = *p++) != '.')
+    {
+      if (c == '\\')
+      {
+        if (!(flags & adns_qf_quoteok_query))
+          return adns_s_querydomaininvalid;
+        if (ctype_digit(p[0]))
+        {
+          if (ctype_digit(p[1]) && ctype_digit(p[2]))
+          {
+            c = (*p++ - '0') * 100;
+            c += (*p++ - '0') * 10;
             c += (*p++ - '0');
-           if (c >= 256) return adns_s_querydomaininvalid;
-         } else {
-           return adns_s_querydomaininvalid;
-         }
-       } else if (!(c= *p++)) {
-         return adns_s_querydomaininvalid;
-       }
+            if (c >= 256)
+              return adns_s_querydomaininvalid;
+          }
+          else
+          {
+            return adns_s_querydomaininvalid;
+          }
+        }
+        else if (!(c = *p++))
+        {
+          return adns_s_querydomaininvalid;
+        }
       }
-      if (!(flags & adns_qf_quoteok_query)) {
-       if (c == '-') {
-         if (!ll) return adns_s_querydomaininvalid;
-       } else if (!ctype_alpha(c) && !ctype_digit(c)) {
-         return adns_s_querydomaininvalid;
-       }
+      if (!(flags & adns_qf_quoteok_query))
+      {
+        if (c == '-')
+        {
+          if (!ll)
+            return adns_s_querydomaininvalid;
+        }
+        else if (!ctype_alpha(c) && !ctype_digit(c))
+        {
+          return adns_s_querydomaininvalid;
+        }
       }
-      if (ll == sizeof(label)) return adns_s_querydomaininvalid;
-      label[ll++]= c;
+      if (ll == sizeof(label))
+        return adns_s_querydomaininvalid;
+      label[ll++] = c;
     }
-    if (!ll) return adns_s_querydomaininvalid;
-    if (ll > DNS_MAXLABEL) return adns_s_querydomaintoolong;
-    nbytes+= ll+1;
-    if (nbytes >= DNS_MAXDOMAIN) return adns_s_querydomaintoolong;
+    if (!ll)
+      return adns_s_querydomaininvalid;
+    if (ll > DNS_MAXLABEL)
+      return adns_s_querydomaintoolong;
+    nbytes += ll + 1;
+    if (nbytes >= DNS_MAXDOMAIN)
+      return adns_s_querydomaintoolong;
     MKQUERY_ADDB(ll);
-    memcpy(rqp,label,ll); rqp+= ll;
+    memcpy(rqp, label, ll);
+    rqp += ll;
   }
   MKQUERY_ADDB(0);
 
   MKQUERY_STOP(vb);
-  
-  st= mkquery_footer(vb,typei->type);
-  
+
+  st = mkquery_footer(vb, typei->type);
+
   return adns_s_ok;
 }
 
-adns_status adns__mkquery_frdgram(adns_state ads, vbuf *vb, int *id_r,
-                                 const byte *qd_dgram, int qd_dglen, int qd_begin,
-                                 adns_rrtype type, adns_queryflags flags) {
+adns_status
+adns__mkquery_frdgram(adns_state ads, vbuf * vb, int *id_r,
+                      const byte * qd_dgram, int qd_dglen, int qd_begin,
+                      adns_rrtype type, adns_queryflags flags)
+{
   byte *rqp;
   findlabel_state fls;
   int lablen, labstart;
   adns_status st;
 
-  st= mkquery_header(ads,vb,id_r,qd_dglen); if (st) return st;
+  st = mkquery_header(ads, vb, id_r, qd_dglen);
+  if (st)
+    return st;
 
   MKQUERY_START(vb);
 
-  adns__findlabel_start(&fls,ads,-1,0,qd_dgram,qd_dglen,qd_dglen,qd_begin,0);
-  for (;;) {
-    st= adns__findlabel_next(&fls,&lablen,&labstart); assert(!st);
-    if (!lablen) break;
-    assert(lablen<255);
+  adns__findlabel_start(&fls, ads, -1, 0, qd_dgram, qd_dglen, qd_dglen,
+                        qd_begin, 0);
+  for (;;)
+  {
+    st = adns__findlabel_next(&fls, &lablen, &labstart);
+    assert(!st);
+    if (!lablen)
+      break;
+    assert(lablen < 255);
     MKQUERY_ADDB(lablen);
-    memcpy(rqp,qd_dgram+labstart,lablen);
-    rqp+= lablen;
+    memcpy(rqp, qd_dgram + labstart, lablen);
+    rqp += lablen;
   }
   MKQUERY_ADDB(0);
 
   MKQUERY_STOP(vb);
-  
-  st= mkquery_footer(vb,type);
-  
+
+  st = mkquery_footer(vb, type);
+
   return adns_s_ok;
 }
 
-void adns__querysend_tcp(adns_query qu, struct timeval now) {
+void
+adns__querysend_tcp(adns_query qu, struct timeval now)
+{
   byte length[2];
 #if 0
   struct iovec iov[2];
@@ -173,66 +214,87 @@ void adns__querysend_tcp(adns_query qu, struct timeval now) {
   int wr, wr2 = 0, r;
   adns_state ads;
 
-  if (qu->ads->tcpstate != server_ok) return;
+  if (qu->ads->tcpstate != server_ok)
+    return;
 
   assert(qu->state == query_tcpw);
 
-  length[0]= (qu->query_dglen&0x0ff00U) >>8;
-  length[1]= (qu->query_dglen&0x0ff);
+  length[0] = (qu->query_dglen & 0x0ff00U) >> 8;
+  length[1] = (qu->query_dglen & 0x0ff);
 
-  ads= qu->ads;
-  if (!adns__vbuf_ensure(&ads->tcpsend,ads->tcpsend.used+qu->query_dglen+2)) return;
+  ads = qu->ads;
+  if (!adns__vbuf_ensure
+      (&ads->tcpsend, ads->tcpsend.used + qu->query_dglen + 2))
+    return;
 
   qu->retries++;
 
   /* Reset idle timeout. */
-  ads->tcptimeout.tv_sec= ads->tcptimeout.tv_usec= 0;
+  ads->tcptimeout.tv_sec = ads->tcptimeout.tv_usec = 0;
 
-  if (ads->tcpsend.used) {
-    wr= 0;
-  } else {
+  if (ads->tcpsend.used)
+  {
+    wr = 0;
+  }
+  else
+  {
 #if 0
-    iov[0].iov_base= (char *)length;
-    iov[0].iov_len= 2;
-    iov[1].iov_base= (char *)qu->query_dgram;
-    iov[1].iov_len= qu->query_dglen;
-    wr= writev(qu->ads->tcpsocket,iov,2);
+    iov[0].iov_base = (char *)length;
+    iov[0].iov_len = 2;
+    iov[1].iov_base = (char *)qu->query_dgram;
+    iov[1].iov_len = qu->query_dglen;
+    wr = writev(qu->ads->tcpsocket, iov, 2);
 #endif
     wr = write(qu->ads->tcpsocket, (char *)length, 2);
     if (wr > 0)
-        wr2 = write(qu->ads->tcpsocket, (char *)qu->query_dgram, qu->query_dglen);
+      wr2 =
+        write(qu->ads->tcpsocket, (char *)qu->query_dgram, qu->query_dglen);
 
-    if (wr < 0 || wr2 < 0) {
+    if (wr < 0 || wr2 < 0)
+    {
       if (!(errno == EAGAIN || errno == EINTR || errno == ENOSPC ||
-           errno == ENOBUFS || errno == ENOMEM)) {
-       adns__tcp_broken(ads,"write",strerror(errno));
-       return;
+            errno == ENOBUFS || errno == ENOMEM))
+      {
+        adns__tcp_broken(ads, "write", strerror(errno));
+        return;
       }
-      wr= 0;
+      wr = 0;
     }
   }
 
-  if (wr<2) {
-    r= adns__vbuf_append(&ads->tcpsend,length,2-wr); assert(r);
-    wr= 0;
-  } else {
-    wr-= 2;
+  if (wr < 2)
+  {
+    r = adns__vbuf_append(&ads->tcpsend, length, 2 - wr);
+    assert(r);
+    wr = 0;
+  }
+  else
+  {
+    wr -= 2;
   }
-  if (wr<qu->query_dglen) {
-    r= adns__vbuf_append(&ads->tcpsend,qu->query_dgram+wr,qu->query_dglen-wr); assert(r);
+  if (wr < qu->query_dglen)
+  {
+    r =
+      adns__vbuf_append(&ads->tcpsend, qu->query_dgram + wr,
+                        qu->query_dglen - wr);
+    assert(r);
   }
 }
 
-static void query_usetcp(adns_query qu, struct timeval now) {
-  qu->state= query_tcpw;
-  qu->timeout= now;
-  timevaladd(&qu->timeout,TCPWAITMS);
-  LIST_LINK_TAIL(qu->ads->tcpw,qu);
-  adns__querysend_tcp(qu,now);
-  adns__tcp_tryconnect(qu->ads,now);
+static void
+query_usetcp(adns_query qu, struct timeval now)
+{
+  qu->state = query_tcpw;
+  qu->timeout = now;
+  timevaladd(&qu->timeout, TCPWAITMS);
+  LIST_LINK_TAIL(qu->ads->tcpw, qu);
+  adns__querysend_tcp(qu, now);
+  adns__tcp_tryconnect(qu->ads, now);
 }
 
-void adns__query_send(adns_query qu, struct timeval now) {
+void
+adns__query_send(adns_query qu, struct timeval now)
+{
   struct sockaddr_in servaddr;
   int serv, r;
   adns_state ads;
@@ -240,39 +302,48 @@ void adns__query_send(adns_query qu, struct timeval now) {
   assert(qu->ads->nservers > 0);
   assert(qu->state == query_tosend);
 
-#ifdef SOMEBODYFIX_TCP_RESOLVER  /* XXX: The TCP resolver is broken */
-  if ((qu->flags & adns_qf_usevc) || (qu->query_dglen > DNS_MAXUDP)) {
-    query_usetcp(qu,now);
+#ifdef SOMEBODYFIX_TCP_RESOLVER /* XXX: The TCP resolver is broken */
+  if ((qu->flags & adns_qf_usevc) || (qu->query_dglen > DNS_MAXUDP))
+  {
+    query_usetcp(qu, now);
     return;
   }
 #endif
-  if(qu->query_dglen > DNS_MAXUDP) {
+  if (qu->query_dglen > DNS_MAXUDP)
+  {
     adns__query_fail(qu, adns_s_systemfail);
     return;
   }
-  if (qu->retries >= UDPMAXRETRIES) {
-    adns__query_fail(qu,adns_s_timeout);
+
+  if (qu->retries >= UDPMAXRETRIES)
+  {
+    adns__query_fail(qu, adns_s_timeout);
+    return;
+  }
+
+  serv = qu->udpnextserver;
+  memset(&servaddr, 0, sizeof(servaddr));
+
+  ads = qu->ads;
+  servaddr.sin_family = AF_INET;
+  servaddr.sin_addr = ads->servers[serv].addr;
+  servaddr.sin_port = htons(DNS_PORT);
+
+  r = sendto(ads->udpsocket, qu->query_dgram, qu->query_dglen, 0,
+             (const struct sockaddr *)&servaddr, sizeof(servaddr));
+  if (r < 0 && errno == EMSGSIZE)
+  {
+    qu->retries = 0;
+    query_usetcp(qu, now);
     return;
   }
+  if (r < 0 && errno != EAGAIN)
+    adns__warn(ads, serv, 0, "sendto failed: %s", strerror(errno));
 
-  serv= qu->udpnextserver;
-  memset(&servaddr,0,sizeof(servaddr));
-
-  ads= qu->ads;
-  servaddr.sin_family= AF_INET;
-  servaddr.sin_addr= ads->servers[serv].addr;
-  servaddr.sin_port= htons(DNS_PORT);
-  
-  r= sendto(ads->udpsocket,qu->query_dgram,qu->query_dglen,0,
-           (const struct sockaddr*)&servaddr,sizeof(servaddr));
-  if (r<0 && errno == EMSGSIZE) { qu->retries= 0; query_usetcp(qu,now); return; }
-  if (r<0 && errno != EAGAIN) adns__warn(ads,serv,0,"sendto failed: %s",strerror(errno));
-  
-  qu->timeout= now;
-  timevaladd(&qu->timeout,UDPRETRYMS);
-  qu->udpsent |= (1<<serv);
-  qu->udpnextserver= (serv+1)%ads->nservers;
+  qu->timeout = now;
+  timevaladd(&qu->timeout, UDPRETRYMS);
+  qu->udpsent |= (1 << serv);
+  qu->udpnextserver = (serv + 1) % ads->nservers;
   qu->retries++;
-  LIST_LINK_TAIL(ads->udpw,qu);
+  LIST_LINK_TAIL(ads->udpw, qu);
 }
index a39185e0f538da1b9a0bee3cc159dbeb712fed26..2bf03c99889727c6c8b5e06883ea8ec5903f737a 100644 (file)
@@ -24,7 +24,7 @@
  *  along with this program; if not, write to the Free Software Foundation,
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  *
- * $Id: types.c,v 1.1 2002/01/04 09:11:04 a1kmm Exp $
+ * $Id: types.c,v 1.2 2002/04/27 02:48:47 a1kmm Exp $
  */
 
 #include <stdlib.h>
  * _qstring               (pap,csp)
  */
 
-static adns_status pap_qstring(const parseinfo *pai, int *cbyte_io, int max,
-                             int *len_r, char **str_r) {
+static adns_status
+pap_qstring(const parseinfo * pai, int *cbyte_io, int max,
+            int *len_r, char **str_r)
+{
   /* Neither len_r nor str_r may be null.
    * End of datagram (overrun) is indicated by returning adns_s_invaliddata;
    */
-  const byte *dgram= pai->dgram;
+  const byte *dgram = pai->dgram;
   int l, cbyte;
   char *str;
 
-  cbyte= *cbyte_io;
-
-  if (cbyte >= max) return adns_s_invaliddata;
-  GET_B(cbyte,l);
-  if (cbyte+l > max) return adns_s_invaliddata;
-  
-  str= adns__alloc_interim(pai->qu, l+1);
-  if (!str) R_NOMEM;
-  
-  str[l]= 0;
-  memcpy(str,dgram+cbyte,l);
-
-  *len_r= l;
-  *str_r= str;
-  *cbyte_io= cbyte+l;
-  
+  cbyte = *cbyte_io;
+
+  if (cbyte >= max)
+    return adns_s_invaliddata;
+  GET_B(cbyte, l);
+  if (cbyte + l > max)
+    return adns_s_invaliddata;
+
+  str = adns__alloc_interim(pai->qu, l + 1);
+  if (!str)
+    R_NOMEM;
+
+  str[l] = 0;
+  memcpy(str, dgram + cbyte, l);
+
+  *len_r = l;
+  *str_r = str;
+  *cbyte_io = cbyte + l;
+
   return adns_s_ok;
 }
 
-static adns_status csp_qstring(vbuf *vb, const char *dp, int len) {
+static adns_status
+csp_qstring(vbuf * vb, const char *dp, int len)
+{
   unsigned char ch;
   char buf[10];
   int cn;
 
   CSP_ADDSTR("\"");
-  for (cn=0; cn<len; cn++) {
-    ch= *dp++;
-    if (ch == '\\') {
+  for (cn = 0; cn < len; cn++)
+  {
+    ch = *dp++;
+    if (ch == '\\')
+    {
       CSP_ADDSTR("\\\\");
-    } else if (ch == '"') {
+    }
+    else if (ch == '"')
+    {
       CSP_ADDSTR("\\\"");
-    } else if (ch >= 32 && ch <= 126) {
-      if (!adns__vbuf_append(vb,&ch,1)) R_NOMEM;
-    } else {
-      ircsprintf(buf,"\\x%02x",ch);
+    }
+    else if (ch >= 32 && ch <= 126)
+    {
+      if (!adns__vbuf_append(vb, &ch, 1))
+        R_NOMEM;
+    }
+    else
+    {
+      ircsprintf(buf, "\\x%02x", ch);
       CSP_ADDSTR(buf);
     }
   }
   CSP_ADDSTR("\"");
-  
+
   return adns_s_ok;
 }
 
@@ -138,85 +154,105 @@ static adns_status csp_qstring(vbuf *vb, const char *dp, int len) {
  * _str  (mf)
  */
 
-static void mf_str(adns_query qu, void *datap) {
-  char **rrp= datap;
+static void
+mf_str(adns_query qu, void *datap)
+{
+  char **rrp = datap;
 
-  adns__makefinal_str(qu,rrp);
+  adns__makefinal_str(qu, rrp);
 }
 
 /*
  * _intstr  (mf)
  */
 
-static void mf_intstr(adns_query qu, void *datap) {
-  adns_rr_intstr *rrp= datap;
+static void
+mf_intstr(adns_query qu, void *datap)
+{
+  adns_rr_intstr *rrp = datap;
 
-  adns__makefinal_str(qu,&rrp->str);
+  adns__makefinal_str(qu, &rrp->str);
 }
 
 /*
  * _manyistr   (mf)
  */
 
-static void mf_manyistr(adns_query qu, void *datap) {
-  adns_rr_intstr **rrp= datap;
+static void
+mf_manyistr(adns_query qu, void *datap)
+{
+  adns_rr_intstr **rrp = datap;
   adns_rr_intstr *te, *table;
   void *tablev;
   int tc;
 
-  for (tc=0, te= *rrp; te->i >= 0; te++, tc++);
-  tablev= *rrp;
-  adns__makefinal_block(qu,&tablev,sizeof(*te)*(tc+1));
-  *rrp= table= tablev;
-  for (te= *rrp; te->i >= 0; te++)
-    adns__makefinal_str(qu,&te->str);
+  for (tc = 0, te = *rrp; te->i >= 0; te++, tc++);
+  tablev = *rrp;
+  adns__makefinal_block(qu, &tablev, sizeof(*te) * (tc + 1));
+  *rrp = table = tablev;
+  for (te = *rrp; te->i >= 0; te++)
+    adns__makefinal_str(qu, &te->str);
 }
 
 /*
  * _txt   (pa,cs)
  */
 
-static adns_status pa_txt(const parseinfo *pai, int cbyte, int max, void *datap) {
-  adns_rr_intstr **rrp= datap, *table, *te;
-  const byte *dgram= pai->dgram;
+static adns_status
+pa_txt(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  adns_rr_intstr **rrp = datap, *table, *te;
+  const byte *dgram = pai->dgram;
   int ti, tc, l, startbyte;
   adns_status st;
 
-  startbyte= cbyte;
-  if (cbyte >= max) return adns_s_invaliddata;
-  tc= 0;
-  while (cbyte < max) {
-    GET_B(cbyte,l);
-    cbyte+= l;
+  startbyte = cbyte;
+  if (cbyte >= max)
+    return adns_s_invaliddata;
+  tc = 0;
+  while (cbyte < max)
+  {
+    GET_B(cbyte, l);
+    cbyte += l;
     tc++;
   }
-  if (cbyte != max || !tc) return adns_s_invaliddata;
-
-  table= adns__alloc_interim(pai->qu,sizeof(*table)*(tc+1));
-  if (!table) R_NOMEM;
-
-  for (cbyte=startbyte, ti=0, te=table; ti<tc; ti++, te++) {
-    st= pap_qstring(pai, &cbyte, max, &te->i, &te->str);
-    if (st) return st;
+  if (cbyte != max || !tc)
+    return adns_s_invaliddata;
+
+  table = adns__alloc_interim(pai->qu, sizeof(*table) * (tc + 1));
+  if (!table)
+    R_NOMEM;
+
+  for (cbyte = startbyte, ti = 0, te = table; ti < tc; ti++, te++)
+  {
+    st = pap_qstring(pai, &cbyte, max, &te->i, &te->str);
+    if (st)
+      return st;
   }
   assert(cbyte == max);
 
-  te->i= -1;
-  te->str= 0;
-  
-  *rrp= table;
+  te->i = -1;
+  te->str = 0;
+
+  *rrp = table;
   return adns_s_ok;
 }
 
-static adns_status cs_txt(vbuf *vb, const void *datap) {
-  const adns_rr_intstr *const *rrp= datap;
+static adns_status
+cs_txt(vbuf * vb, const void *datap)
+{
+  const adns_rr_intstr *const *rrp = datap;
   const adns_rr_intstr *current;
   adns_status st;
   int spc;
 
-  for (current= *rrp, spc=0;  current->i >= 0;  current++, spc=1) {
-    if (spc) CSP_ADDSTR(" ");
-    st= csp_qstring(vb,current->str,current->i); if (st) return st;
+  for (current = *rrp, spc = 0; current->i >= 0; current++, spc = 1)
+  {
+    if (spc)
+      CSP_ADDSTR(" ");
+    st = csp_qstring(vb, current->str, current->i);
+    if (st)
+      return st;
   }
   return adns_s_ok;
 }
@@ -225,13 +261,19 @@ static adns_status cs_txt(vbuf *vb, const void *datap) {
  * _hinfo   (cs)
  */
 
-static adns_status cs_hinfo(vbuf *vb, const void *datap) {
-  const adns_rr_intstrpair *rrp= datap;
+static adns_status
+cs_hinfo(vbuf * vb, const void *datap)
+{
+  const adns_rr_intstrpair *rrp = datap;
   adns_status st;
 
-  st= csp_qstring(vb,rrp->array[0].str,rrp->array[0].i);  if (st) return st;
+  st = csp_qstring(vb, rrp->array[0].str, rrp->array[0].i);
+  if (st)
+    return st;
   CSP_ADDSTR(" ");
-  st= csp_qstring(vb,rrp->array[1].str,rrp->array[1].i);  if (st) return st;
+  st = csp_qstring(vb, rrp->array[1].str, rrp->array[1].i);
+  if (st)
+    return st;
   return adns_s_ok;
 }
 
@@ -239,53 +281,68 @@ static adns_status cs_hinfo(vbuf *vb, const void *datap) {
  * _inaddr   (pa,dip,di)
  */
 
-static adns_status pa_inaddr(const parseinfo *pai, int cbyte, int max, void *datap) {
-  struct in_addr *storeto= datap;
-  
-  if (max-cbyte != 4) return adns_s_invaliddata;
+static adns_status
+pa_inaddr(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  struct in_addr *storeto = datap;
+
+  if (max - cbyte != 4)
+    return adns_s_invaliddata;
   memcpy(storeto, pai->dgram + cbyte, 4);
   return adns_s_ok;
 }
 
 #ifdef IPV6
-static adns_status pa_in6addr(const parseinfo *pai, int cbyte, int max, void *datap) {
-  struct in6_addr *storeto= datap;
-  
-  if (max-cbyte != 16) return adns_s_invaliddata;
+static adns_status
+pa_in6addr(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  struct in6_addr *storeto = datap;
+
+  if (max - cbyte != 16)
+    return adns_s_invaliddata;
   memcpy(storeto, pai->dgram + cbyte, 16);
   return adns_s_ok;
 }
 #endif
-static int search_sortlist(adns_state ads, struct in_addr ad) {
+static int
+search_sortlist(adns_state ads, struct in_addr ad)
+{
   const struct sortlist *slp;
   int i;
-  
-  for (i=0, slp=ads->sortlist;
-       i<ads->nsortlist && !((ad.s_addr & slp->mask.s_addr) == slp->base.s_addr);
-       i++, slp++);
+
+  for (i = 0, slp = ads->sortlist;
+       i < ads->nsortlist
+       && !((ad.s_addr & slp->mask.s_addr) == slp->base.s_addr); i++, slp++);
   return i;
 }
 
-static int dip_inaddr(adns_state ads, struct in_addr a, struct in_addr b) {
+static int
+dip_inaddr(adns_state ads, struct in_addr a, struct in_addr b)
+{
   int ai, bi;
-  
-  if (!ads->nsortlist) return 0;
 
-  ai= search_sortlist(ads,a);
-  bi= search_sortlist(ads,b);
-  return bi<ai;
+  if (!ads->nsortlist)
+    return 0;
+
+  ai = search_sortlist(ads, a);
+  bi = search_sortlist(ads, b);
+  return bi < ai;
 }
 
-static int di_inaddr(adns_state ads, const void *datap_a, const void *datap_b) {
-  const struct in_addr *ap= datap_a, *bp= datap_b;
+static int
+di_inaddr(adns_state ads, const void *datap_a, const void *datap_b)
+{
+  const struct in_addr *ap = datap_a, *bp = datap_b;
 
-  return dip_inaddr(ads,*ap,*bp);
+  return dip_inaddr(ads, *ap, *bp);
 }
 
 
 #ifdef IPV6
-static adns_status cs_in6addr(vbuf *vb, const void *datap) {
-  const struct in6_addr *rrp= datap, rr= *rrp;
+static adns_status
+cs_in6addr(vbuf * vb, const void *datap)
+{
+  const struct in6_addr *rrp = datap, rr = *rrp;
   char ia[IP6STRLEN];
 
   assert(inetntop(AF_INET6, &rr, ia, IP6STRLEN) != NULL);
@@ -293,11 +350,14 @@ static adns_status cs_in6addr(vbuf *vb, const void *datap) {
   return adns_s_ok;
 }
 #endif
-static adns_status cs_inaddr(vbuf *vb, const void *datap) {
-  const char *rr= datap;
+static adns_status
+cs_inaddr(vbuf * vb, const void *datap)
+{
+  const char *rr = datap;
   const char *ia;
 
-  ia= inetntoa(rr); assert(ia);
+  ia = inetntoa(rr);
+  assert(ia);
   CSP_ADDSTR(ia);
   return adns_s_ok;
 }
@@ -306,81 +366,103 @@ static adns_status cs_inaddr(vbuf *vb, const void *datap) {
  * _addr   (pa,di,csp,cs)
  */
 
-static adns_status pa_addr(const parseinfo *pai, int cbyte, int max, void *datap) {
-  adns_rr_addr *storeto= datap;
-  const byte *dgram= pai->dgram;
-
-  if (max-cbyte != 4) return adns_s_invaliddata;
-  storeto->len= sizeof(storeto->addr.inet);
-  memset(&storeto->addr,0,sizeof(storeto->addr.inet));
-  storeto->addr.inet.sin_family= AF_INET;
-  memcpy(&storeto->addr.inet.sin_addr,dgram+cbyte,4);
+static adns_status
+pa_addr(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  adns_rr_addr *storeto = datap;
+  const byte *dgram = pai->dgram;
+
+  if (max - cbyte != 4)
+    return adns_s_invaliddata;
+  storeto->len = sizeof(storeto->addr.inet);
+  memset(&storeto->addr, 0, sizeof(storeto->addr.inet));
+  storeto->addr.inet.sin_family = AF_INET;
+  memcpy(&storeto->addr.inet.sin_addr, dgram + cbyte, 4);
   return adns_s_ok;
 }
+
 #ifdef IPV6
-static adns_status pa_addr6(const parseinfo *pai, int cbyte, int max, void *datap) {
-  adns_rr_addr *storeto= datap;
-  const byte *dgram= pai->dgram;
-
-  if (max-cbyte != 16) return adns_s_invaliddata;
-  storeto->len= sizeof(storeto->addr.inet6);
-  memset(&storeto->addr,0,sizeof(storeto->addr.inet6));
-  storeto->addr.inet6.sin6_family= AF_INET6;
-  memcpy(&storeto->addr.inet6.sin6_addr.s6_addr,dgram+cbyte,16);
+static adns_status
+pa_addr6(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  adns_rr_addr *storeto = datap;
+  const byte *dgram = pai->dgram;
+
+  if (max - cbyte != 16)
+    return adns_s_invaliddata;
+  storeto->len = sizeof(storeto->addr.inet6);
+  memset(&storeto->addr, 0, sizeof(storeto->addr.inet6));
+  storeto->addr.inet6.sin6_family = AF_INET6;
+  memcpy(&storeto->addr.inet6.sin6_addr.s6_addr, dgram + cbyte, 16);
   return adns_s_ok;
 }
 #endif
-static int di_addr(adns_state ads, const void *datap_a, const void *datap_b) {
-  const adns_rr_addr *ap= datap_a, *bp= datap_b;
+static int
+di_addr(adns_state ads, const void *datap_a, const void *datap_b)
+{
+  const adns_rr_addr *ap = datap_a, *bp = datap_b;
 
   assert(ap->addr.sa.sa_family == AF_INET);
   return dip_inaddr(ads, ap->addr.inet.sin_addr, bp->addr.inet.sin_addr);
 }
 
-static int div_addr(void *context, const void *datap_a, const void *datap_b) {
-  const adns_state ads= context;
+static int
+div_addr(void *context, const void *datap_a, const void *datap_b)
+{
+  const adns_state ads = context;
 
   return di_addr(ads, datap_a, datap_b);
-}                   
+}
 
-static adns_status csp_addr(vbuf *vb, const adns_rr_addr *rrp) {
+static adns_status
+csp_addr(vbuf * vb, const adns_rr_addr * rrp)
+{
   const char *ia;
   static char buf[30];
 
-  switch (rrp->addr.sa.sa_family) {
-  case AF_INET:
-    CSP_ADDSTR("INET ");
-    ia= inetntoa((char *)&rrp->addr.inet.sin_addr); assert(ia);
-    CSP_ADDSTR(ia);
-    break;
+  switch (rrp->addr.sa.sa_family)
+  {
+    case AF_INET:
+      CSP_ADDSTR("INET ");
+      ia = inetntoa((char *)&rrp->addr.inet.sin_addr);
+      assert(ia);
+      CSP_ADDSTR(ia);
+      break;
 #ifdef IPV6
-  case AF_INET6:
+    case AF_INET6:
     {
-       char ip[IP6STRLEN];
-       CSP_ADDSTR("INET6 ");
-       assert(inetntop(AF_INET6, rrp->addr.inet6.sin6_addr.s6_addr, ip, IP6STRLEN) != NULL);
-       CSP_ADDSTR(ip);
-       break;
+      char ip[IP6STRLEN];
+      CSP_ADDSTR("INET6 ");
+      assert(inetntop
+             (AF_INET6, rrp->addr.inet6.sin6_addr.s6_addr, ip,
+              IP6STRLEN) != NULL);
+      CSP_ADDSTR(ip);
+      break;
     }
 #endif
-  default:
-    ircsprintf(buf,"AF=%u",rrp->addr.sa.sa_family);
-    CSP_ADDSTR(buf);
-    break;
+    default:
+      ircsprintf(buf, "AF=%u", rrp->addr.sa.sa_family);
+      CSP_ADDSTR(buf);
+      break;
   }
   return adns_s_ok;
 }
 
-static adns_status cs_addr(vbuf *vb, const void *datap) {
-  const adns_rr_addr *rrp= datap;
+static adns_status
+cs_addr(vbuf * vb, const void *datap)
+{
+  const adns_rr_addr *rrp = datap;
 
-  return csp_addr(vb,rrp);
+  return csp_addr(vb, rrp);
 }
+
 #ifdef IPV6
-static adns_status cs_addr6(vbuf *vb, const void *datap) {
-  const adns_rr_addr *rrp= datap;
+static adns_status
+cs_addr6(vbuf * vb, const void *datap)
+{
+  const adns_rr_addr *rrp = datap;
 
-  return csp_addr(vb,rrp);
+  return csp_addr(vb, rrp);
 }
 #endif
 /*
@@ -388,45 +470,60 @@ static adns_status cs_addr6(vbuf *vb, const void *datap) {
  * _dom_raw     (pa)
  */
 
-static adns_status pap_domain(const parseinfo *pai, int *cbyte_io, int max,
-                             char **domain_r, parsedomain_flags flags) {
+static adns_status
+pap_domain(const parseinfo * pai, int *cbyte_io, int max,
+           char **domain_r, parsedomain_flags flags)
+{
   adns_status st;
   char *dm;
-  
-  st= adns__parse_domain(pai->qu->ads, pai->serv, pai->qu, &pai->qu->vb, flags,
-                        pai->dgram,pai->dglen, cbyte_io, max);
-  if (st) return st;
-  if (!pai->qu->vb.used) return adns_s_invaliddata;
-
-  dm= adns__alloc_interim(pai->qu, pai->qu->vb.used+1);
-  if (!dm) R_NOMEM;
-
-  dm[pai->qu->vb.used]= 0;
-  memcpy(dm,pai->qu->vb.buf,pai->qu->vb.used);
-  
-  *domain_r= dm;
+
+  st =
+    adns__parse_domain(pai->qu->ads, pai->serv, pai->qu, &pai->qu->vb, flags,
+                       pai->dgram, pai->dglen, cbyte_io, max);
+  if (st)
+    return st;
+  if (!pai->qu->vb.used)
+    return adns_s_invaliddata;
+
+  dm = adns__alloc_interim(pai->qu, pai->qu->vb.used + 1);
+  if (!dm)
+    R_NOMEM;
+
+  dm[pai->qu->vb.used] = 0;
+  memcpy(dm, pai->qu->vb.buf, pai->qu->vb.used);
+
+  *domain_r = dm;
   return adns_s_ok;
 }
 
-static adns_status csp_domain(vbuf *vb, const char *domain) {
+static adns_status
+csp_domain(vbuf * vb, const char *domain)
+{
   CSP_ADDSTR(domain);
-  if (!*domain) CSP_ADDSTR(".");
+  if (!*domain)
+    CSP_ADDSTR(".");
   return adns_s_ok;
 }
 
-static adns_status cs_domain(vbuf *vb, const void *datap) {
-  const char *const *domainp= datap;
-  return csp_domain(vb,*domainp);
+static adns_status
+cs_domain(vbuf * vb, const void *datap)
+{
+  const char *const *domainp = datap;
+  return csp_domain(vb, *domainp);
 }
 
-static adns_status pa_dom_raw(const parseinfo *pai, int cbyte, int max, void *datap) {
-  char **rrp= datap;
+static adns_status
+pa_dom_raw(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  char **rrp = datap;
   adns_status st;
 
-  st= pap_domain(pai, &cbyte, max, rrp, pdf_quoteok);
-  if (st) return st;
-  
-  if (cbyte != max) return adns_s_invaliddata;
+  st = pap_domain(pai, &cbyte, max, rrp, pdf_quoteok);
+  if (st)
+    return st;
+
+  if (cbyte != max)
+    return adns_s_invaliddata;
   return adns_s_ok;
 }
 
@@ -434,15 +531,19 @@ static adns_status pa_dom_raw(const parseinfo *pai, int cbyte, int max, void *da
  * _host_raw   (pa)
  */
 
-static adns_status pa_host_raw(const parseinfo *pai, int cbyte, int max, void *datap) {
-  char **rrp= datap;
+static adns_status
+pa_host_raw(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  char **rrp = datap;
   adns_status st;
 
-  st= pap_domain(pai, &cbyte, max, rrp,
-                pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
-  if (st) return st;
-  
-  if (cbyte != max) return adns_s_invaliddata;
+  st = pap_domain(pai, &cbyte, max, rrp,
+                  pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
+  if (st)
+    return st;
+
+  if (cbyte != max)
+    return adns_s_invaliddata;
   return adns_s_ok;
 }
 
@@ -450,65 +551,87 @@ static adns_status pa_host_raw(const parseinfo *pai, int cbyte, int max, void *d
  * _hostaddr   (pap,pa,dip,di,mfp,mf,csp,cs +icb_hostaddr, pap_findaddrs)
  */
 
-static adns_status pap_findaddrs(const parseinfo *pai, adns_rr_hostaddr *ha,
-                                int *cbyte_io, int count, int dmstart) {
+static adns_status
+pap_findaddrs(const parseinfo * pai, adns_rr_hostaddr * ha,
+              int *cbyte_io, int count, int dmstart)
+{
   int rri, naddrs;
   int type, class, rdlen, rdstart, ownermatched;
   unsigned long ttl;
   adns_status st;
-  
-  for (rri=0, naddrs=-1; rri<count; rri++) {
-    st= adns__findrr_anychk(pai->qu, pai->serv, pai->dgram, pai->dglen, cbyte_io,
-                           &type, &class, &ttl, &rdlen, &rdstart,
-                           pai->dgram, pai->dglen, dmstart, &ownermatched);
-    if (st) return st;
-    if (!ownermatched || class != DNS_CLASS_IN || type != adns_r_a) {
-      if (naddrs>0) break; else continue;
+
+  for (rri = 0, naddrs = -1; rri < count; rri++)
+  {
+    st =
+      adns__findrr_anychk(pai->qu, pai->serv, pai->dgram, pai->dglen,
+                          cbyte_io, &type, &class, &ttl, &rdlen, &rdstart,
+                          pai->dgram, pai->dglen, dmstart, &ownermatched);
+    if (st)
+      return st;
+    if (!ownermatched || class != DNS_CLASS_IN || type != adns_r_a)
+    {
+      if (naddrs > 0)
+        break;
+      else
+        continue;
     }
-    if (naddrs == -1) {
-      naddrs= 0;
+    if (naddrs == -1)
+    {
+      naddrs = 0;
     }
-    if (!adns__vbuf_ensure(&pai->qu->vb, (naddrs+1)*sizeof(adns_rr_addr))) R_NOMEM;
-    adns__update_expires(pai->qu,ttl,pai->now);
-    st= pa_addr(pai, rdstart,rdstart+rdlen,
-               pai->qu->vb.buf + naddrs*sizeof(adns_rr_addr));
-    if (st) return st;
+    if (!adns__vbuf_ensure(&pai->qu->vb, (naddrs + 1) * sizeof(adns_rr_addr)))
+      R_NOMEM;
+    adns__update_expires(pai->qu, ttl, pai->now);
+    st = pa_addr(pai, rdstart, rdstart + rdlen,
+                 pai->qu->vb.buf + naddrs * sizeof(adns_rr_addr));
+    if (st)
+      return st;
     naddrs++;
   }
-  if (naddrs >= 0) {
-    ha->addrs= adns__alloc_interim(pai->qu, naddrs*sizeof(adns_rr_addr));
-    if (!ha->addrs) R_NOMEM;
-    memcpy(ha->addrs, pai->qu->vb.buf, naddrs*sizeof(adns_rr_addr));
-    ha->naddrs= naddrs;
-    ha->astatus= adns_s_ok;
+  if (naddrs >= 0)
+  {
+    ha->addrs = adns__alloc_interim(pai->qu, naddrs * sizeof(adns_rr_addr));
+    if (!ha->addrs)
+      R_NOMEM;
+    memcpy(ha->addrs, pai->qu->vb.buf, naddrs * sizeof(adns_rr_addr));
+    ha->naddrs = naddrs;
+    ha->astatus = adns_s_ok;
 
     adns__isort(ha->addrs, naddrs, sizeof(adns_rr_addr), pai->qu->vb.buf,
-               div_addr, pai->ads);
+                div_addr, pai->ads);
   }
   return adns_s_ok;
 }
 
-static void icb_hostaddr(adns_query parent, adns_query child) {
-  adns_answer *cans= child->answer;
-  adns_rr_hostaddr *rrp= child->ctx.info.hostaddr;
-  adns_state ads= parent->ads;
+static void
+icb_hostaddr(adns_query parent, adns_query child)
+{
+  adns_answer *cans = child->answer;
+  adns_rr_hostaddr *rrp = child->ctx.info.hostaddr;
+  adns_state ads = parent->ads;
   adns_status st;
 
-  st= cans->status;
-  rrp->astatus= st;
-  rrp->naddrs= (st>0 && st<=adns_s_max_tempfail) ? -1 : cans->nrrs;
-  rrp->addrs= cans->rrs.addr;
-  adns__transfer_interim(child, parent, rrp->addrs, rrp->naddrs*sizeof(adns_rr_addr));
+  st = cans->status;
+  rrp->astatus = st;
+  rrp->naddrs = (st > 0 && st <= adns_s_max_tempfail) ? -1 : cans->nrrs;
+  rrp->addrs = cans->rrs.addr;
+  adns__transfer_interim(child, parent, rrp->addrs,
+                         rrp->naddrs * sizeof(adns_rr_addr));
 
-  if (parent->children.head) {
-    LIST_LINK_TAIL(ads->childw,parent);
-  } else {
+  if (parent->children.head)
+  {
+    LIST_LINK_TAIL(ads->childw, parent);
+  }
+  else
+  {
     adns__query_done(parent);
   }
 }
 
-static adns_status pap_hostaddr(const parseinfo *pai, int *cbyte_io,
-                               int max, adns_rr_hostaddr *rrp) {
+static adns_status
+pap_hostaddr(const parseinfo * pai, int *cbyte_io,
+             int max, adns_rr_hostaddr * rrp)
+{
   adns_status st;
   int dmstart, cbyte;
   qcontext ctx;
@@ -516,156 +639,200 @@ static adns_status pap_hostaddr(const parseinfo *pai, int *cbyte_io,
   adns_query nqu;
   adns_queryflags nflags;
 
-  dmstart= cbyte= *cbyte_io;
-  st= pap_domain(pai, &cbyte, max, &rrp->host,
-                pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
-  if (st) return st;
-  *cbyte_io= cbyte;
-
-  rrp->astatus= adns_s_ok;
-  rrp->naddrs= -1;
-  rrp->addrs= 0;
-
-  cbyte= pai->nsstart;
-
-  st= pap_findaddrs(pai, rrp, &cbyte, pai->nscount, dmstart);
-  if (st) return st;
-  if (rrp->naddrs != -1) return adns_s_ok;
-
-  st= pap_findaddrs(pai, rrp, &cbyte, pai->arcount, dmstart);
-  if (st) return st;
-  if (rrp->naddrs != -1) return adns_s_ok;
-
-  st= adns__mkquery_frdgram(pai->ads, &pai->qu->vb, &id,
-                           pai->dgram, pai->dglen, dmstart,
-                           adns_r_addr, adns_qf_quoteok_query);
-  if (st) return st;
-
-  ctx.ext= 0;
-  ctx.callback= icb_hostaddr;
-  ctx.info.hostaddr= rrp;
-  
-  nflags= adns_qf_quoteok_query;
-  if (!(pai->qu->flags & adns_qf_cname_loose)) nflags |= adns_qf_cname_forbid;
-  
-  st= adns__internal_submit(pai->ads, &nqu, adns__findtype(adns_r_addr),
-                           &pai->qu->vb, id, nflags, pai->now, &ctx);
-  if (st) return st;
-
-  nqu->parent= pai->qu;
-  LIST_LINK_TAIL_PART(pai->qu->children,nqu,siblings.);
+  dmstart = cbyte = *cbyte_io;
+  st = pap_domain(pai, &cbyte, max, &rrp->host,
+                  pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
+  if (st)
+    return st;
+  *cbyte_io = cbyte;
+
+  rrp->astatus = adns_s_ok;
+  rrp->naddrs = -1;
+  rrp->addrs = 0;
+
+  cbyte = pai->nsstart;
+
+  st = pap_findaddrs(pai, rrp, &cbyte, pai->nscount, dmstart);
+  if (st)
+    return st;
+  if (rrp->naddrs != -1)
+    return adns_s_ok;
+
+  st = pap_findaddrs(pai, rrp, &cbyte, pai->arcount, dmstart);
+  if (st)
+    return st;
+  if (rrp->naddrs != -1)
+    return adns_s_ok;
+
+  st = adns__mkquery_frdgram(pai->ads, &pai->qu->vb, &id,
+                             pai->dgram, pai->dglen, dmstart,
+                             adns_r_addr, adns_qf_quoteok_query);
+  if (st)
+    return st;
+
+  ctx.ext = 0;
+  ctx.callback = icb_hostaddr;
+  ctx.info.hostaddr = rrp;
+
+  nflags = adns_qf_quoteok_query;
+  if (!(pai->qu->flags & adns_qf_cname_loose))
+    nflags |= adns_qf_cname_forbid;
+
+  st = adns__internal_submit(pai->ads, &nqu, adns__findtype(adns_r_addr),
+                             &pai->qu->vb, id, nflags, pai->now, &ctx);
+  if (st)
+    return st;
+
+  nqu->parent = pai->qu;
+  LIST_LINK_TAIL_PART(pai->qu->children, nqu, siblings.);
 
   return adns_s_ok;
 }
 
-static adns_status pa_hostaddr(const parseinfo *pai, int cbyte, int max, void *datap) {
-  adns_rr_hostaddr *rrp= datap;
+static adns_status
+pa_hostaddr(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  adns_rr_hostaddr *rrp = datap;
   adns_status st;
 
-  st= pap_hostaddr(pai, &cbyte, max, rrp);
-  if (st) return st;
-  if (cbyte != max) return adns_s_invaliddata;
+  st = pap_hostaddr(pai, &cbyte, max, rrp);
+  if (st)
+    return st;
+  if (cbyte != max)
+    return adns_s_invaliddata;
 
   return adns_s_ok;
 }
 
-static int dip_hostaddr(adns_state ads, const adns_rr_hostaddr *ap, const adns_rr_hostaddr *bp) {
-  if (ap->astatus != bp->astatus) return ap->astatus;
-  if (ap->astatus) return 0;
+static int
+dip_hostaddr(adns_state ads, const adns_rr_hostaddr * ap,
+             const adns_rr_hostaddr * bp)
+{
+  if (ap->astatus != bp->astatus)
+    return ap->astatus;
+  if (ap->astatus)
+    return 0;
 
   assert(ap->addrs[0].addr.sa.sa_family == AF_INET);
   assert(bp->addrs[0].addr.sa.sa_family == AF_INET);
   return dip_inaddr(ads,
-                   ap->addrs[0].addr.inet.sin_addr,
-                   bp->addrs[0].addr.inet.sin_addr);
+                    ap->addrs[0].addr.inet.sin_addr,
+                    bp->addrs[0].addr.inet.sin_addr);
 }
 
-static int di_hostaddr(adns_state ads, const void *datap_a, const void *datap_b) {
-  const adns_rr_hostaddr *ap= datap_a, *bp= datap_b;
+static int
+di_hostaddr(adns_state ads, const void *datap_a, const void *datap_b)
+{
+  const adns_rr_hostaddr *ap = datap_a, *bp = datap_b;
 
-  return dip_hostaddr(ads, ap,bp);
+  return dip_hostaddr(ads, ap, bp);
 }
 
-static void mfp_hostaddr(adns_query qu, adns_rr_hostaddr *rrp) {
+static void
+mfp_hostaddr(adns_query qu, adns_rr_hostaddr * rrp)
+{
   void *tablev;
 
-  adns__makefinal_str(qu,&rrp->host);
-  tablev= rrp->addrs;
-  adns__makefinal_block(qu, &tablev, rrp->naddrs*sizeof(*rrp->addrs));
-  rrp->addrs= tablev;
+  adns__makefinal_str(qu, &rrp->host);
+  tablev = rrp->addrs;
+  adns__makefinal_block(qu, &tablev, rrp->naddrs * sizeof(*rrp->addrs));
+  rrp->addrs = tablev;
 }
 
-static void mf_hostaddr(adns_query qu, void *datap) {
-  adns_rr_hostaddr *rrp= datap;
+static void
+mf_hostaddr(adns_query qu, void *datap)
+{
+  adns_rr_hostaddr *rrp = datap;
 
-  mfp_hostaddr(qu,rrp);
+  mfp_hostaddr(qu, rrp);
 }
 
-static adns_status csp_hostaddr(vbuf *vb, const adns_rr_hostaddr *rrp) {
+static adns_status
+csp_hostaddr(vbuf * vb, const adns_rr_hostaddr * rrp)
+{
   const char *errstr;
   adns_status st;
   char buf[20];
   int i;
 
-  st= csp_domain(vb,rrp->host);  if (st) return st;
+  st = csp_domain(vb, rrp->host);
+  if (st)
+    return st;
 
   CSP_ADDSTR(" ");
   CSP_ADDSTR(adns_errtypeabbrev(rrp->astatus));
 
-  ircsprintf(buf," %d ",rrp->astatus);
+  ircsprintf(buf, " %d ", rrp->astatus);
   CSP_ADDSTR(buf);
 
   CSP_ADDSTR(adns_errabbrev(rrp->astatus));
   CSP_ADDSTR(" ");
 
-  errstr= adns_strerror(rrp->astatus);
-  st= csp_qstring(vb,errstr,strlen(errstr));  if (st) return st;
-  
-  if (rrp->naddrs >= 0) {
+  errstr = adns_strerror(rrp->astatus);
+  st = csp_qstring(vb, errstr, strlen(errstr));
+  if (st)
+    return st;
+
+  if (rrp->naddrs >= 0)
+  {
     CSP_ADDSTR(" (");
-    for (i=0; i<rrp->naddrs; i++) {
+    for (i = 0; i < rrp->naddrs; i++)
+    {
       CSP_ADDSTR(" ");
-      st= csp_addr(vb,&rrp->addrs[i]);
+      st = csp_addr(vb, &rrp->addrs[i]);
     }
     CSP_ADDSTR(" )");
-  } else {
+  }
+  else
+  {
     CSP_ADDSTR(" ?");
   }
   return adns_s_ok;
 }
 
-static adns_status cs_hostaddr(vbuf *vb, const void *datap) {
-  const adns_rr_hostaddr *rrp= datap;
+static adns_status
+cs_hostaddr(vbuf * vb, const void *datap)
+{
+  const adns_rr_hostaddr *rrp = datap;
 
-  return csp_hostaddr(vb,rrp);
+  return csp_hostaddr(vb, rrp);
 }
 
 /*
  * _mx_raw   (pa,di)
  */
 
-static adns_status pa_mx_raw(const parseinfo *pai, int cbyte, int max, void *datap) {
-  const byte *dgram= pai->dgram;
-  adns_rr_intstr *rrp= datap;
+static adns_status
+pa_mx_raw(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  const byte *dgram = pai->dgram;
+  adns_rr_intstr *rrp = datap;
   adns_status st;
   int pref;
 
-  if (cbyte+2 > max) return adns_s_invaliddata;
-  GET_W(cbyte,pref);
-  rrp->i= pref;
-  st= pap_domain(pai, &cbyte, max, &rrp->str,
-                pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
-  if (st) return st;
-  
-  if (cbyte != max) return adns_s_invaliddata;
+  if (cbyte + 2 > max)
+    return adns_s_invaliddata;
+  GET_W(cbyte, pref);
+  rrp->i = pref;
+  st = pap_domain(pai, &cbyte, max, &rrp->str,
+                  pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
+  if (st)
+    return st;
+
+  if (cbyte != max)
+    return adns_s_invaliddata;
   return adns_s_ok;
 }
 
-static int di_mx_raw(adns_state ads, const void *datap_a, const void *datap_b) {
-  const adns_rr_intstr *ap= datap_a, *bp= datap_b;
+static int
+di_mx_raw(adns_state ads, const void *datap_a, const void *datap_b)
+{
+  const adns_rr_intstr *ap = datap_a, *bp = datap_b;
 
-  if (ap->i < bp->i) return 0;
-  if (ap->i > bp->i) return 1;
+  if (ap->i < bp->i)
+    return 0;
+  if (ap->i > bp->i)
+    return 1;
   return 0;
 }
 
@@ -673,27 +840,36 @@ static int di_mx_raw(adns_state ads, const void *datap_a, const void *datap_b) {
  * _mx   (pa,di)
  */
 
-static adns_status pa_mx(const parseinfo *pai, int cbyte, int max, void *datap) {
-  const byte *dgram= pai->dgram;
-  adns_rr_inthostaddr *rrp= datap;
+static adns_status
+pa_mx(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  const byte *dgram = pai->dgram;
+  adns_rr_inthostaddr *rrp = datap;
   adns_status st;
   int pref;
 
-  if (cbyte+2 > max) return adns_s_invaliddata;
-  GET_W(cbyte,pref);
-  rrp->i= pref;
-  st= pap_hostaddr(pai, &cbyte, max, &rrp->ha);
-  if (st) return st;
-  
-  if (cbyte != max) return adns_s_invaliddata;
+  if (cbyte + 2 > max)
+    return adns_s_invaliddata;
+  GET_W(cbyte, pref);
+  rrp->i = pref;
+  st = pap_hostaddr(pai, &cbyte, max, &rrp->ha);
+  if (st)
+    return st;
+
+  if (cbyte != max)
+    return adns_s_invaliddata;
   return adns_s_ok;
 }
 
-static int di_mx(adns_state ads, const void *datap_a, const void *datap_b) {
-  const adns_rr_inthostaddr *ap= datap_a, *bp= datap_b;
+static int
+di_mx(adns_state ads, const void *datap_a, const void *datap_b)
+{
+  const adns_rr_inthostaddr *ap = datap_a, *bp = datap_b;
 
-  if (ap->i < bp->i) return 0;
-  if (ap->i > bp->i) return 1;
+  if (ap->i < bp->i)
+    return 0;
+  if (ap->i > bp->i)
+    return 1;
   return dip_hostaddr(ads, &ap->ha, &bp->ha);
 }
 
@@ -701,74 +877,95 @@ static int di_mx(adns_state ads, const void *datap_a, const void *datap_b) {
  * _inthostaddr  (mf,cs)
  */
 
-static void mf_inthostaddr(adns_query qu, void *datap) {
-  adns_rr_inthostaddr *rrp= datap;
+static void
+mf_inthostaddr(adns_query qu, void *datap)
+{
+  adns_rr_inthostaddr *rrp = datap;
 
-  mfp_hostaddr(qu,&rrp->ha);
+  mfp_hostaddr(qu, &rrp->ha);
 }
 
-static adns_status cs_inthostaddr(vbuf *vb, const void *datap) {
-  const adns_rr_inthostaddr *rrp= datap;
+static adns_status
+cs_inthostaddr(vbuf * vb, const void *datap)
+{
+  const adns_rr_inthostaddr *rrp = datap;
   char buf[10];
 
-  ircsprintf(buf,"%u ",rrp->i);
+  ircsprintf(buf, "%u ", rrp->i);
   CSP_ADDSTR(buf);
 
-  return csp_hostaddr(vb,&rrp->ha);
+  return csp_hostaddr(vb, &rrp->ha);
 }
 
 /*
  * _inthost  (cs)
  */
 
-static adns_status cs_inthost(vbuf *vb, const void *datap) {
-  const adns_rr_intstr *rrp= datap;
+static adns_status
+cs_inthost(vbuf * vb, const void *datap)
+{
+  const adns_rr_intstr *rrp = datap;
   char buf[10];
 
-  ircsprintf(buf,"%u ",rrp->i);
+  ircsprintf(buf, "%u ", rrp->i);
   CSP_ADDSTR(buf);
-  return csp_domain(vb,rrp->str);
+  return csp_domain(vb, rrp->str);
 }
 
 /*
  * _ptr   (pa, +icb_ptr)
  */
 
-static void icb_ptr(adns_query parent, adns_query child) {
-  adns_answer *cans= child->answer;
+static void
+icb_ptr(adns_query parent, adns_query child)
+{
+  adns_answer *cans = child->answer;
   const adns_rr_addr *queried, *found;
-  adns_state ads= parent->ads;
+  adns_state ads = parent->ads;
   int i;
 
-  if (cans->status == adns_s_nxdomain || cans->status == adns_s_nodata) {
-    adns__query_fail(parent,adns_s_inconsistent);
+  if (cans->status == adns_s_nxdomain || cans->status == adns_s_nodata)
+  {
+    adns__query_fail(parent, adns_s_inconsistent);
     return;
-  } else if (cans->status) {
-    adns__query_fail(parent,cans->status);
+  }
+  else if (cans->status)
+  {
+    adns__query_fail(parent, cans->status);
     return;
   }
 
-  queried= &parent->ctx.info.ptr_parent_addr;
-  for (i=0, found=cans->rrs.addr; i<cans->nrrs; i++, found++) {
+  queried = &parent->ctx.info.ptr_parent_addr;
+  for (i = 0, found = cans->rrs.addr; i < cans->nrrs; i++, found++)
+  {
     if (queried->len == found->len &&
-       !memcmp(&queried->addr,&found->addr,queried->len)) {
-      if (!parent->children.head) {
-       adns__query_done(parent);
-       return;
-      } else {
-       LIST_LINK_TAIL(ads->childw,parent);
-       return;
+        !memcmp(&queried->addr, &found->addr, queried->len))
+    {
+      if (!parent->children.head)
+      {
+        adns__query_done(parent);
+        return;
+      }
+      else
+      {
+        LIST_LINK_TAIL(ads->childw, parent);
+        return;
       }
     }
   }
 
-  adns__query_fail(parent,adns_s_inconsistent);
+  adns__query_fail(parent, adns_s_inconsistent);
 }
+
 #ifdef IPV6
-static adns_status pa_ptr6(const parseinfo *pai, int dmstart, int max, void *datap) {
-  static const char *(expectdomain[])= { DNS_IP6_INT };
-  
-  char **rrp= datap;
+static adns_status
+pa_ptr6(const parseinfo * pai, int dmstart, int max, void *datap)
+{
+  static const char *(expectdomain[]) =
+  {
+  DNS_IP6_INT};
+
+  char **rrp = datap;
   adns_status st;
   adns_rr_addr *ap;
   findlabel_state fls;
@@ -777,77 +974,94 @@ static adns_status pa_ptr6(const parseinfo *pai, int dmstart, int max, void *dat
   adns_query nqu;
   qcontext ctx;
 
-  cbyte= dmstart;
-  st= pap_domain(pai, &cbyte, max, rrp,
-                pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
-  if (st) return st;
-  if (cbyte != max) return adns_s_invaliddata;
+  cbyte = dmstart;
+  st = pap_domain(pai, &cbyte, max, rrp,
+                  pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
+  if (st)
+    return st;
+  if (cbyte != max)
+    return adns_s_invaliddata;
 
   memset(labbuf, 0, sizeof(labbuf));
-  memset(ipv,0, sizeof(ipv));
-  ap= &pai->qu->ctx.info.ptr_parent_addr;
-  if (!ap->len) {
+  memset(ipv, 0, sizeof(ipv));
+  ap = &pai->qu->ctx.info.ptr_parent_addr;
+  if (!ap->len)
+  {
 
     adns__findlabel_start(&fls, pai->ads, -1, pai->qu,
-                         pai->qu->query_dgram, pai->qu->query_dglen,
-                         pai->qu->query_dglen, DNS_HDRSIZE, 0);
-    for(i = 0; i < 32; i++)
+                          pai->qu->query_dgram, pai->qu->query_dglen,
+                          pai->qu->query_dglen, DNS_HDRSIZE, 0);
+    for (i = 0; i < 32; i++)
+    {
+      st = adns__findlabel_next(&fls, &lablen, &labstart);
+      assert(!st);
+      if (lablen <= 0 || lablen > 1)
+        return adns_s_querydomainwrong;
+
+      memcpy(labbuf, pai->qu->query_dgram + labstart, lablen);
+      labbuf[lablen] = 0;
+      strcat(ipv, labbuf);
+      if (lablen > 1 && pai->qu->query_dgram[labstart] == '0')
+        return adns_s_querydomainwrong;
+    }
+    pt = ip6;
+    for (i = 32, x = 0; i >= 0; i--)
     {
-    st= adns__findlabel_next(&fls,&lablen,&labstart); assert(!st);
-    if (lablen<=0 || lablen > 1) return adns_s_querydomainwrong;
-        
-      memcpy(labbuf, pai->qu->query_dgram + labstart, lablen);  labbuf[lablen]= 0;
-      strcat(ipv, labbuf); 
-      if (lablen>1 && pai->qu->query_dgram[labstart]=='0')
-       return adns_s_querydomainwrong;
+      if (x >= 3 && i > 2)
+      {
+        pt += ircsprintf(pt, "%c:", ipv[i - 1]);
+        x = 0;
+      }
+      else
+      {
+        pt += ircsprintf(pt, "%c", ipv[i - 1]);
+        x++;
+      }
     }
-    pt = ip6;     
-    for(i = 32, x = 0; i >= 0; i--)
+    for (i = 0; i < sizeof(expectdomain) / sizeof(*expectdomain); i++)
     {
-       if(x >= 3 && i > 2)
-       {
-               pt += ircsprintf(pt,"%c:", ipv[i-1]);
-               x = 0;
-       } else {
-               pt += ircsprintf(pt,"%c", ipv[i-1]);    
-               x++;
-       }       
-    }    
-    for (i=0; i<sizeof(expectdomain)/sizeof(*expectdomain); i++) {
-        st= adns__findlabel_next(&fls,&lablen,&labstart); assert(!st);
-        l= strlen(expectdomain[i]);
-        if (lablen != l || memcmp(pai->qu->query_dgram + labstart, expectdomain[i], l))
-          return adns_s_querydomainwrong;
+      st = adns__findlabel_next(&fls, &lablen, &labstart);
+      assert(!st);
+      l = strlen(expectdomain[i]);
+      if (lablen != l
+          || memcmp(pai->qu->query_dgram + labstart, expectdomain[i], l))
+        return adns_s_querydomainwrong;
     }
 
-    ap->len= sizeof(struct sockaddr_in6);
-    memset(&ap->addr,0,sizeof(ap->addr.inet6));
-    ap->addr.inet6.sin6_family=AF_INET6;
+    ap->len = sizeof(struct sockaddr_in6);
+    memset(&ap->addr, 0, sizeof(ap->addr.inet6));
+    ap->addr.inet6.sin6_family = AF_INET6;
     inetpton(AF_INET6, ip6, ap->addr.inet6.sin6_addr.s6_addr);
   }
 
-  st= adns__mkquery_frdgram(pai->ads, &pai->qu->vb, &id,
-                           pai->dgram, pai->dglen, dmstart,
-                           adns_r_addr6, adns_qf_quoteok_query);
-  if (st) return st;
-
-  ctx.ext= 0;
-  ctx.callback= icb_ptr;
-  memset(&ctx.info,0,sizeof(ctx.info));
-  st= adns__internal_submit(pai->ads, &nqu, adns__findtype(adns_r_addr6),
-                           &pai->qu->vb, id,
-                           adns_qf_quoteok_query, pai->now, &ctx);
-  if (st) return st;
-
-  nqu->parent= pai->qu;
-  LIST_LINK_TAIL_PART(pai->qu->children,nqu,siblings.);
+  st = adns__mkquery_frdgram(pai->ads, &pai->qu->vb, &id,
+                             pai->dgram, pai->dglen, dmstart,
+                             adns_r_addr6, adns_qf_quoteok_query);
+  if (st)
+    return st;
+
+  ctx.ext = 0;
+  ctx.callback = icb_ptr;
+  memset(&ctx.info, 0, sizeof(ctx.info));
+  st = adns__internal_submit(pai->ads, &nqu, adns__findtype(adns_r_addr6),
+                             &pai->qu->vb, id,
+                             adns_qf_quoteok_query, pai->now, &ctx);
+  if (st)
+    return st;
+
+  nqu->parent = pai->qu;
+  LIST_LINK_TAIL_PART(pai->qu->children, nqu, siblings.);
   return adns_s_ok;
 }
 #endif
-static adns_status pa_ptr(const parseinfo *pai, int dmstart, int max, void *datap) {
-  static const char *(expectdomain[])= { DNS_INADDR_ARPA };
-  
-  char **rrp= datap;
+static adns_status
+pa_ptr(const parseinfo * pai, int dmstart, int max, void *datap)
+{
+  static const char *(expectdomain[]) =
+  {
+  DNS_INADDR_ARPA};
+
+  char **rrp = datap;
   adns_status st;
   adns_rr_addr *ap;
   findlabel_state fls;
@@ -858,56 +1072,72 @@ static adns_status pa_ptr(const parseinfo *pai, int dmstart, int max, void *data
   adns_query nqu;
   qcontext ctx;
 
-  cbyte= dmstart;
-  st= pap_domain(pai, &cbyte, max, rrp,
-                pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
-  if (st) return st;
-  if (cbyte != max) return adns_s_invaliddata;
-
-  ap= &pai->qu->ctx.info.ptr_parent_addr;
-  if (!ap->len) {
+  cbyte = dmstart;
+  st = pap_domain(pai, &cbyte, max, rrp,
+                  pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
+  if (st)
+    return st;
+  if (cbyte != max)
+    return adns_s_invaliddata;
+
+  ap = &pai->qu->ctx.info.ptr_parent_addr;
+  if (!ap->len)
+  {
     adns__findlabel_start(&fls, pai->ads, -1, pai->qu,
-                         pai->qu->query_dgram, pai->qu->query_dglen,
-                         pai->qu->query_dglen, DNS_HDRSIZE, 0);
-    for (i=0; i<4; i++) {
-      st= adns__findlabel_next(&fls,&lablen,&labstart); assert(!st);
-      if (lablen<=0 || lablen>3) return adns_s_querydomainwrong;
-      memcpy(labbuf, pai->qu->query_dgram + labstart, lablen);  labbuf[lablen]= 0;
-      ipv[3-i]= strtoul(labbuf,&ep,10);  if (*ep) return adns_s_querydomainwrong;
-      if (lablen>1 && pai->qu->query_dgram[labstart]=='0')
-       return adns_s_querydomainwrong;
+                          pai->qu->query_dgram, pai->qu->query_dglen,
+                          pai->qu->query_dglen, DNS_HDRSIZE, 0);
+    for (i = 0; i < 4; i++)
+    {
+      st = adns__findlabel_next(&fls, &lablen, &labstart);
+      assert(!st);
+      if (lablen <= 0 || lablen > 3)
+        return adns_s_querydomainwrong;
+      memcpy(labbuf, pai->qu->query_dgram + labstart, lablen);
+      labbuf[lablen] = 0;
+      ipv[3 - i] = strtoul(labbuf, &ep, 10);
+      if (*ep)
+        return adns_s_querydomainwrong;
+      if (lablen > 1 && pai->qu->query_dgram[labstart] == '0')
+        return adns_s_querydomainwrong;
     }
-    for (i=0; i<sizeof(expectdomain)/sizeof(*expectdomain); i++) {
-      st= adns__findlabel_next(&fls,&lablen,&labstart); assert(!st);
-      l= strlen(expectdomain[i]);
-      if (lablen != l || memcmp(pai->qu->query_dgram + labstart, expectdomain[i], l))
-       return adns_s_querydomainwrong;
+    for (i = 0; i < sizeof(expectdomain) / sizeof(*expectdomain); i++)
+    {
+      st = adns__findlabel_next(&fls, &lablen, &labstart);
+      assert(!st);
+      l = strlen(expectdomain[i]);
+      if (lablen != l
+          || memcmp(pai->qu->query_dgram + labstart, expectdomain[i], l))
+        return adns_s_querydomainwrong;
     }
-    st= adns__findlabel_next(&fls,&lablen,0); assert(!st);
-    if (lablen) return adns_s_querydomainwrong;
-    
-    ap->len= sizeof(struct sockaddr_in);
-    memset(&ap->addr,0,sizeof(ap->addr.inet));
-    ap->addr.inet.sin_family= AF_INET;
-    ap->addr.inet.sin_addr.s_addr=
-      htonl((ipv[0]<<24) | (ipv[1]<<16) | (ipv[2]<<8) | (ipv[3]));
+    st = adns__findlabel_next(&fls, &lablen, 0);
+    assert(!st);
+    if (lablen)
+      return adns_s_querydomainwrong;
+
+    ap->len = sizeof(struct sockaddr_in);
+    memset(&ap->addr, 0, sizeof(ap->addr.inet));
+    ap->addr.inet.sin_family = AF_INET;
+    ap->addr.inet.sin_addr.s_addr =
+      htonl((ipv[0] << 24) | (ipv[1] << 16) | (ipv[2] << 8) | (ipv[3]));
   }
 
-  st= adns__mkquery_frdgram(pai->ads, &pai->qu->vb, &id,
-                           pai->dgram, pai->dglen, dmstart,
-                           adns_r_addr, adns_qf_quoteok_query);
-  if (st) return st;
-
-  ctx.ext= 0;
-  ctx.callback= icb_ptr;
-  memset(&ctx.info,0,sizeof(ctx.info));
-  st= adns__internal_submit(pai->ads, &nqu, adns__findtype(adns_r_addr),
-                           &pai->qu->vb, id,
-                           adns_qf_quoteok_query, pai->now, &ctx);
-  if (st) return st;
-
-  nqu->parent= pai->qu;
-  LIST_LINK_TAIL_PART(pai->qu->children,nqu,siblings.);
+  st = adns__mkquery_frdgram(pai->ads, &pai->qu->vb, &id,
+                             pai->dgram, pai->dglen, dmstart,
+                             adns_r_addr, adns_qf_quoteok_query);
+  if (st)
+    return st;
+
+  ctx.ext = 0;
+  ctx.callback = icb_ptr;
+  memset(&ctx.info, 0, sizeof(ctx.info));
+  st = adns__internal_submit(pai->ads, &nqu, adns__findtype(adns_r_addr),
+                             &pai->qu->vb, id,
+                             adns_qf_quoteok_query, pai->now, &ctx);
+  if (st)
+    return st;
+
+  nqu->parent = pai->qu;
+  LIST_LINK_TAIL_PART(pai->qu->children, nqu, siblings.);
   return adns_s_ok;
 }
 
@@ -915,40 +1145,49 @@ static adns_status pa_ptr(const parseinfo *pai, int dmstart, int max, void *data
  * _strpair   (mf)
  */
 
-static void mf_strpair(adns_query qu, void *datap) {
-  adns_rr_strpair *rrp= datap;
+static void
+mf_strpair(adns_query qu, void *datap)
+{
+  adns_rr_strpair *rrp = datap;
 
-  adns__makefinal_str(qu,&rrp->array[0]);
-  adns__makefinal_str(qu,&rrp->array[1]);
+  adns__makefinal_str(qu, &rrp->array[0]);
+  adns__makefinal_str(qu, &rrp->array[1]);
 }
 
 /*
  * _intstrpair   (mf)
  */
 
-static void mf_intstrpair(adns_query qu, void *datap) {
-  adns_rr_intstrpair *rrp= datap;
+static void
+mf_intstrpair(adns_query qu, void *datap)
+{
+  adns_rr_intstrpair *rrp = datap;
 
-  adns__makefinal_str(qu,&rrp->array[0].str);
-  adns__makefinal_str(qu,&rrp->array[1].str);
+  adns__makefinal_str(qu, &rrp->array[0].str);
+  adns__makefinal_str(qu, &rrp->array[1].str);
 }
 
 /*
  * _hinfo   (pa)
  */
 
-static adns_status pa_hinfo(const parseinfo *pai, int cbyte, int max, void *datap) {
-  adns_rr_intstrpair *rrp= datap;
+static adns_status
+pa_hinfo(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  adns_rr_intstrpair *rrp = datap;
   adns_status st;
   int i;
 
-  for (i=0; i<2; i++) {
-    st= pap_qstring(pai, &cbyte, max, &rrp->array[i].i, &rrp->array[i].str);
-    if (st) return st;
+  for (i = 0; i < 2; i++)
+  {
+    st = pap_qstring(pai, &cbyte, max, &rrp->array[i].i, &rrp->array[i].str);
+    if (st)
+      return st;
   }
 
-  if (cbyte != max) return adns_s_invaliddata;
-  
+  if (cbyte != max)
+    return adns_s_invaliddata;
+
   return adns_s_ok;
 }
 
@@ -956,8 +1195,9 @@ static adns_status pa_hinfo(const parseinfo *pai, int cbyte, int max, void *data
  * _mailbox   (pap,cs)
  */
 
-static adns_status pap_mailbox822(const parseinfo *pai, int *cbyte_io, int max,
-                                 char **mb_r) {
+static adns_status
+pap_mailbox822(const parseinfo * pai, int *cbyte_io, int max, char **mb_r)
+{
   int lablen, labstart, i, needquote, c, r, neednorm;
   const unsigned char *p;
   char *str;
@@ -965,142 +1205,194 @@ static adns_status pap_mailbox822(const parseinfo *pai, int *cbyte_io, int max,
   adns_status st;
   vbuf *vb;
 
-  vb= &pai->qu->vb;
-  vb->used= 0;
+  vb = &pai->qu->vb;
+  vb->used = 0;
   adns__findlabel_start(&fls, pai->ads,
-                       -1, pai->qu,
-                       pai->dgram, pai->dglen, max,
-                       *cbyte_io, cbyte_io);
-  st= adns__findlabel_next(&fls,&lablen,&labstart);
-  if (!lablen) {
-    adns__vbuf_appendstr(vb,".");
+                        -1, pai->qu,
+                        pai->dgram, pai->dglen, max, *cbyte_io, cbyte_io);
+  st = adns__findlabel_next(&fls, &lablen, &labstart);
+  if (!lablen)
+  {
+    adns__vbuf_appendstr(vb, ".");
     goto x_ok;
   }
 
-  neednorm= 1;
-  for (i=0, needquote=0, p= pai->dgram+labstart; i<lablen; i++) {
-    c= *p++;
-    if ((c&~128) < 32 || (c&~128) == 127) return adns_s_invaliddata;
-    if (c == '.' && !neednorm) neednorm= 1;
-    else if (c==' ' || c>=127 || ctype_822special(c)) needquote++;
-    else neednorm= 0;
+  neednorm = 1;
+  for (i = 0, needquote = 0, p = pai->dgram + labstart; i < lablen; i++)
+  {
+    c = *p++;
+    if ((c & ~128) < 32 || (c & ~128) == 127)
+      return adns_s_invaliddata;
+    if (c == '.' && !neednorm)
+      neednorm = 1;
+    else if (c == ' ' || c >= 127 || ctype_822special(c))
+      needquote++;
+    else
+      neednorm = 0;
   }
 
-  if (needquote || neednorm) {
-    r= adns__vbuf_ensure(vb, lablen+needquote+4); if (!r) R_NOMEM;
-    adns__vbuf_appendq(vb,(const byte *)"\"",1);
-    for (i=0, needquote=0, p= pai->dgram+labstart; i<lablen; i++, p++) {
-      c= *p;
-      if (c == '"' || c=='\\') adns__vbuf_appendq(vb,(const byte *)"\\",1);
-      adns__vbuf_appendq(vb,p,1);
+  if (needquote || neednorm)
+  {
+    r = adns__vbuf_ensure(vb, lablen + needquote + 4);
+    if (!r)
+      R_NOMEM;
+    adns__vbuf_appendq(vb, (const byte *)"\"", 1);
+    for (i = 0, needquote = 0, p = pai->dgram + labstart; i < lablen;
+         i++, p++)
+    {
+      c = *p;
+      if (c == '"' || c == '\\')
+        adns__vbuf_appendq(vb, (const byte *)"\\", 1);
+      adns__vbuf_appendq(vb, p, 1);
     }
-    adns__vbuf_appendq(vb,(const byte *)"\"",1);
-  } else {
-    r= adns__vbuf_append(vb, pai->dgram+labstart, lablen); if (!r) R_NOMEM;
+    adns__vbuf_appendq(vb, (const byte *)"\"", 1);
+  }
+  else
+  {
+    r = adns__vbuf_append(vb, pai->dgram + labstart, lablen);
+    if (!r)
+      R_NOMEM;
   }
 
-  r= adns__vbuf_appendstr(vb,"@"); if (!r) R_NOMEM;
-
-  st= adns__parse_domain_more(&fls,pai->ads, pai->qu,vb,0, pai->dgram);
-  if (st) return st;
-
- x_ok:
-  str= adns__alloc_interim(pai->qu, vb->used+1); if (!str) R_NOMEM;
-  memcpy(str,vb->buf,vb->used);
-  str[vb->used]= 0;
-  *mb_r= str;
+  r = adns__vbuf_appendstr(vb, "@");
+  if (!r)
+    R_NOMEM;
+
+  st = adns__parse_domain_more(&fls, pai->ads, pai->qu, vb, 0, pai->dgram);
+  if (st)
+    return st;
+
+x_ok:
+  str = adns__alloc_interim(pai->qu, vb->used + 1);
+  if (!str)
+    R_NOMEM;
+  memcpy(str, vb->buf, vb->used);
+  str[vb->used] = 0;
+  *mb_r = str;
   return adns_s_ok;
 }
 
-static adns_status pap_mailbox(const parseinfo *pai, int *cbyte_io, int max,
-                              char **mb_r) {
-  if (pai->qu->typei->type & adns__qtf_mail822) {
+static adns_status
+pap_mailbox(const parseinfo * pai, int *cbyte_io, int max, char **mb_r)
+{
+  if (pai->qu->typei->type & adns__qtf_mail822)
+  {
     return pap_mailbox822(pai, cbyte_io, max, mb_r);
-  } else {
+  }
+  else
+  {
     return pap_domain(pai, cbyte_io, max, mb_r, pdf_quoteok);
   }
 }
 
-static adns_status csp_mailbox(vbuf *vb, const char *mailbox) {
-  return csp_domain(vb,mailbox);
+static adns_status
+csp_mailbox(vbuf * vb, const char *mailbox)
+{
+  return csp_domain(vb, mailbox);
 }
 
 /*
  * _rp   (pa,cs)
  */
 
-static adns_status pa_rp(const parseinfo *pai, int cbyte, int max, void *datap) {
-  adns_rr_strpair *rrp= datap;
+static adns_status
+pa_rp(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  adns_rr_strpair *rrp = datap;
   adns_status st;
 
-  st= pap_mailbox(pai, &cbyte, max, &rrp->array[0]);
-  if (st) return st;
+  st = pap_mailbox(pai, &cbyte, max, &rrp->array[0]);
+  if (st)
+    return st;
 
-  st= pap_domain(pai, &cbyte, max, &rrp->array[1], pdf_quoteok);
-  if (st) return st;
+  st = pap_domain(pai, &cbyte, max, &rrp->array[1], pdf_quoteok);
+  if (st)
+    return st;
 
-  if (cbyte != max) return adns_s_invaliddata;
+  if (cbyte != max)
+    return adns_s_invaliddata;
   return adns_s_ok;
 }
 
-static adns_status cs_rp(vbuf *vb, const void *datap) {
-  const adns_rr_strpair *rrp= datap;
+static adns_status
+cs_rp(vbuf * vb, const void *datap)
+{
+  const adns_rr_strpair *rrp = datap;
   adns_status st;
 
-  st= csp_mailbox(vb,rrp->array[0]);  if (st) return st;
+  st = csp_mailbox(vb, rrp->array[0]);
+  if (st)
+    return st;
   CSP_ADDSTR(" ");
-  st= csp_domain(vb,rrp->array[1]);  if (st) return st;
+  st = csp_domain(vb, rrp->array[1]);
+  if (st)
+    return st;
 
   return adns_s_ok;
-}  
+}
 
 /*
  * _soa   (pa,mf,cs)
  */
 
-static adns_status pa_soa(const parseinfo *pai, int cbyte, int max, void *datap) {
-  adns_rr_soa *rrp= datap;
-  const byte *dgram= pai->dgram;
+static adns_status
+pa_soa(const parseinfo * pai, int cbyte, int max, void *datap)
+{
+  adns_rr_soa *rrp = datap;
+  const byte *dgram = pai->dgram;
   adns_status st;
   int msw, lsw, i;
 
-  st= pap_domain(pai, &cbyte, max, &rrp->mname,
-                pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
-  if (st) return st;
+  st = pap_domain(pai, &cbyte, max, &rrp->mname,
+                  pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
+  if (st)
+    return st;
+
+  st = pap_mailbox(pai, &cbyte, max, &rrp->rname);
+  if (st)
+    return st;
 
-  st= pap_mailbox(pai, &cbyte, max, &rrp->rname);
-  if (st) return st;
+  if (cbyte + 20 != max)
+    return adns_s_invaliddata;
 
-  if (cbyte+20 != max) return adns_s_invaliddata;
-  
-  for (i=0; i<5; i++) {
-    GET_W(cbyte,msw);
-    GET_W(cbyte,lsw);
-    (&rrp->serial)[i]= (msw<<16) | lsw;
+  for (i = 0; i < 5; i++)
+  {
+    GET_W(cbyte, msw);
+    GET_W(cbyte, lsw);
+    (&rrp->serial)[i] = (msw << 16) | lsw;
   }
 
   return adns_s_ok;
 }
 
-static void mf_soa(adns_query qu, void *datap) {
-  adns_rr_soa *rrp= datap;
+static void
+mf_soa(adns_query qu, void *datap)
+{
+  adns_rr_soa *rrp = datap;
 
-  adns__makefinal_str(qu,&rrp->mname);
-  adns__makefinal_str(qu,&rrp->rname);
+  adns__makefinal_str(qu, &rrp->mname);
+  adns__makefinal_str(qu, &rrp->rname);
 }
 
-static adns_status cs_soa(vbuf *vb, const void *datap) {
-  const adns_rr_soa *rrp= datap;
+static adns_status
+cs_soa(vbuf * vb, const void *datap)
+{
+  const adns_rr_soa *rrp = datap;
   char buf[20];
   int i;
   adns_status st;
-  
-  st= csp_domain(vb,rrp->mname);  if (st) return st;
+
+  st = csp_domain(vb, rrp->mname);
+  if (st)
+    return st;
   CSP_ADDSTR(" ");
-  st= csp_mailbox(vb,rrp->rname);  if (st) return st;
+  st = csp_mailbox(vb, rrp->rname);
+  if (st)
+    return st;
 
-  for (i=0; i<5; i++) {
-    ircsprintf(buf," %lu",(&rrp->serial)[i]);
+  for (i = 0; i < 5; i++)
+  {
+    ircsprintf(buf, " %lu", (&rrp->serial)[i]);
     CSP_ADDSTR(buf);
   }
 
@@ -1111,7 +1403,10 @@ static adns_status cs_soa(vbuf *vb, const void *datap) {
  * _flat   (mf)
  */
 
-static void mf_flat(adns_query qu, void *ddata) { }
+static void
+mf_flat(adns_query qu, void *ddata)
+{
+}
 
 /*
  * Now the table.
@@ -1130,43 +1425,51 @@ static void mf_flat(adns_query qu, void *ddata) { }
 static const typeinfo typeinfos[] = {
 /* Must be in ascending order of rrtype ! */
 /* mem-mgmt code  rrt     fmt     member      parser      comparer    printer       */
-                                                                                      
-FLAT_TYPE(a,      "A",     0,     inaddr,     pa_inaddr,  di_inaddr,  cs_inaddr     ),
-DEEP_TYPE(ns_raw, "NS",   "raw",  str,        pa_host_raw,0,          cs_domain     ),
-DEEP_TYPE(cname,  "CNAME", 0,     str,        pa_dom_raw, 0,          cs_domain     ),
-DEEP_TYPE(soa_raw,"SOA",  "raw",  soa,        pa_soa,     0,          cs_soa        ),
-DEEP_TYPE(ptr_raw,"PTR",  "raw",  str,        pa_host_raw,0,          cs_domain     ),
-DEEP_TYPE(hinfo,  "HINFO", 0,     intstrpair, pa_hinfo,   0,          cs_hinfo      ),
-DEEP_TYPE(mx_raw, "MX",   "raw",  intstr,     pa_mx_raw,  di_mx_raw,  cs_inthost    ),
-DEEP_TYPE(txt,    "TXT",   0,     manyistr,   pa_txt,     0,          cs_txt        ),
-DEEP_TYPE(rp_raw, "RP",   "raw",  strpair,    pa_rp,      0,          cs_rp         ),
+
+  FLAT_TYPE(a, "A", 0, inaddr, pa_inaddr, di_inaddr, cs_inaddr),
+  DEEP_TYPE(ns_raw, "NS", "raw", str, pa_host_raw, 0, cs_domain),
+  DEEP_TYPE(cname, "CNAME", 0, str, pa_dom_raw, 0, cs_domain),
+  DEEP_TYPE(soa_raw, "SOA", "raw", soa, pa_soa, 0, cs_soa),
+  DEEP_TYPE(ptr_raw, "PTR", "raw", str, pa_host_raw, 0, cs_domain),
+  DEEP_TYPE(hinfo, "HINFO", 0, intstrpair, pa_hinfo, 0, cs_hinfo),
+  DEEP_TYPE(mx_raw, "MX", "raw", intstr, pa_mx_raw, di_mx_raw, cs_inthost),
+  DEEP_TYPE(txt, "TXT", 0, manyistr, pa_txt, 0, cs_txt),
+  DEEP_TYPE(rp_raw, "RP", "raw", strpair, pa_rp, 0, cs_rp),
 #ifdef IPV6
-FLAT_TYPE(aaaa,          "AAAA",  0,     in6addr,    pa_in6addr, 0,          cs_in6addr    ),
+  FLAT_TYPE(aaaa, "AAAA", 0, in6addr, pa_in6addr, 0, cs_in6addr),
 #endif
-FLAT_TYPE(addr,   "A",  "addr",   addr,       pa_addr,    di_addr,    cs_addr       ),
-DEEP_TYPE(ns,     "NS", "+addr",  hostaddr,   pa_hostaddr,di_hostaddr,cs_hostaddr   ),
-DEEP_TYPE(ptr,    "PTR","checked",str,        pa_ptr,     0,          cs_domain     ),
-DEEP_TYPE(mx,     "MX", "+addr",  inthostaddr,pa_mx,      di_mx,      cs_inthostaddr),
+  FLAT_TYPE(addr, "A", "addr", addr, pa_addr, di_addr, cs_addr),
+  DEEP_TYPE(ns, "NS", "+addr", hostaddr, pa_hostaddr, di_hostaddr,
+            cs_hostaddr),
+  DEEP_TYPE(ptr, "PTR", "checked", str, pa_ptr, 0, cs_domain),
+  DEEP_TYPE(mx, "MX", "+addr", inthostaddr, pa_mx, di_mx, cs_inthostaddr),
 #ifdef IPV6
-FLAT_TYPE(addr6,  "AAAA","addr6", addr,       pa_addr6,   0,         cs_addr6      ),
+  FLAT_TYPE(addr6, "AAAA", "addr6", addr, pa_addr6, 0, cs_addr6),
 #endif
-DEEP_TYPE(soa,    "SOA","822",    soa,        pa_soa,     0,          cs_soa        ),
-DEEP_TYPE(rp,     "RP", "822",    strpair,    pa_rp,      0,          cs_rp         ),
+  DEEP_TYPE(soa, "SOA", "822", soa, pa_soa, 0, cs_soa),
+  DEEP_TYPE(rp, "RP", "822", strpair, pa_rp, 0, cs_rp),
 #ifdef IPV6
-DEEP_TYPE(ptr_ip6,"PTR","checked",str,        pa_ptr6,   0,          cs_domain     ),
+  DEEP_TYPE(ptr_ip6, "PTR", "checked", str, pa_ptr6, 0, cs_domain),
 #endif
 };
 
-const typeinfo *adns__findtype(adns_rrtype type) {
+const typeinfo *
+adns__findtype(adns_rrtype type)
+{
   const typeinfo *begin, *end, *mid;
 
-  begin= typeinfos;  end= typeinfos+(sizeof(typeinfos)/sizeof(typeinfo));
-
-  while (begin < end) {
-    mid= begin + ((end-begin)>>1);
-    if (mid->type == type) return mid;
-    if (type > mid->type) begin= mid+1;
-    else end= mid;
+  begin = typeinfos;
+  end = typeinfos + (sizeof(typeinfos) / sizeof(typeinfo));
+
+  while (begin < end)
+  {
+    mid = begin + ((end - begin) >> 1);
+    if (mid->type == type)
+      return mid;
+    if (type > mid->type)
+      begin = mid + 1;
+    else
+      end = mid;
   }
   return 0;
 }
index 32eba0ab952d014c6fb069c9b946bb2d2853f2a9..93b51dc62c3be95933b1046b5b278bbedf1ea4ad 100644 (file)
@@ -1,6 +1,8 @@
-dnl $Id: configure.in,v 1.1 2002/01/04 09:12:05 a1kmm Exp $
+dnl $Id: configure.in,v 1.2 2002/04/27 02:48:51 a1kmm Exp $
 dnl Process this file with autoconf to produce a configure script.
-AC_INIT(include/class.h)
+dnl AC_INIT(include/class.h) <- what is this ? -TimeMr14C
+
+AC_INIT
 
 AC_CONFIG_AUX_DIR(autoconf)
 AC_CONFIG_HEADER(include/setup.h servlink/setup.h)
@@ -11,31 +13,118 @@ VERSION=7.0
 AC_SUBST(PACKAGE)
 AC_SUBST(VERSION)
 
+OLD_CFLAGS="$CFLAGS"
 dnl Checks for programs.
 AC_PROG_CC
+dnl Make sure autoconf doesnt interfere with cflags -jmallett
+CFLAGS="$OLD_CFLAGS"
+
+dnl Check for various compilers. -jmallett
+SGS=no
+AC_MSG_CHECKING(if we are using TenDRA or MIPSpro)
+case `$CC -version 2>&1` in
+  *TenDRA*)
+    AC_MSG_RESULT(success! We will be using TenDRA.)
+    TenDRA=yes
+    SGS=yes
+    ;;
+  *MIPSpro*)
+    AC_MSG_RESULT(success! We will be using MIPSpro.)
+    MIPSpro=yes
+    SGS=yes
+    ;;
+  *)
+    AC_MSG_RESULT(no)
+    TenDRA=no
+    MIPSpro=no
+    ;;
+esac
+AC_MSG_CHECKING(if we are using Sun WorkShop)
+case `$CC -V 2>&1` in
+  *Sun*WorkShop*)
+    AC_MSG_RESULT(success! We are using Sun WorkShop.)
+    SunWorkShop=yes
+    SGS=yes
+    ;;
+  *)
+    AC_MSG_RESULT(no)
+    SunWorkShop=no
+    ;;
+esac
+AC_MSG_CHECKING(if we are using Apple GCC)
+case `$CC -v 2>&1 | tail -1` in
+  *Apple*)
+    AC_MSG_RESULT(success! We are using GCC from Apple.)
+    AppleGCC=yes
+    ;;
+  *)
+    AC_MSG_RESULT(no)
+    AppleGCC=no
+    ;;
+esac
+
+dnl SVR4 SGS based on what we know about the compiler -jmallett
+AC_MSG_CHECKING(if your compiler supports the SVR4 Software Generation System interfaces)
+if test "$SGS" = "yes"; then
+  AC_MSG_RESULT(yes)
+else
+  AC_MSG_RESULT(no)
+fi
 
+dnl XXX This could be consecutive 'if' statements, and then check
+dnl for a zero "$IRC_CFLAGS" (but what should we use for TenDRA??)
+dnl and then do the check for whether -g works... Hrrm. -jmallett
 if test "x$GCC" = "xyes"; then
   IRC_CFLAGS="-O2 -g -ggdb -Wunused -Wall -Wshadow -Wmissing-declarations"
 else
-  IRC_CFLAGS="-g"
+  if test "x$TenDRA" = "xyes"; then
+    dnl CPPFLAGS here is really IRC_CFLAGS but autoconf does silly
+    dnl things with the wrong variables, so this works. -jmallett
+    IRC_CFLAGS=""
+    CPPFLAGS="$CPPFLAGS -Ylonglong -Yansi -I/usr/include"
+  else
+    if test "x$MIPSpro" = "xyes"; then
+      IRC_CFLAGS="-g"
+    else
+      if test "x$ac_cv_prog_cc_g" = "xyes"; then
+        IRC_CFLAGS="-g"
+      else
+        IRC_CFLAGS=""
+      fi
+    fi
+  fi
 fi
 
-AC_MSG_CHECKING(Checking how to generate dependancy info)
+dnl cc on HPUX 11.00 does not produce any output on cc -V
+dnl Therefore I will use the following hack to discover HPUX 
+dnl -TimeMr14C
 
-if test "x$GCC" = "xyes"; then
-  MKDEP="$CC -MM"
-else
-   case `uname -s` in
-    SunOS*)
-       AC_MSG_RESULT(SunOS - Assuming $CC -xM to make dependancies)
-       MKDEP="$CC -xM"
-    ;;
-    *)
-       AC_MSG_RESULT(Assuming your compiler can take $CC -MM to make dependancies)
-        MKDEP="$CC -MM"        
-    ;;
-   esac
-   
+case `uname -s` in
+        HP-UX*)
+                AC_MSG_RESULT(HP-UX found - Assuming HPUX C compiler cc)  
+               IRC_CFLAGS="$IRC_CFLAGS +e"
+               HPUX=yes
+               ;;
+       OSF*)
+               OSF=yes
+               ;;
+       *)
+               ;;
+esac
+
+
+AC_MSG_CHECKING(how to generate dependancy info)
+if test "$SunWorkShop" = "yes"; then
+  AC_MSG_RESULT(Sun WorkShop using $CC -xM)
+  MKDEP="$CC -xM"
+fi
+if test "$HPUX" = "yes"; then
+  AC_MSG_RESULT(HP-UX C Compiler using makedepend)
+  MKDEP="makedepend"
+fi
+if test "x$MKDEP" = "x"; then
+  AC_MSG_RESULT(assuming $CC -MM)
+  MKDEP="$CC -MM"      
 fi
 
 AC_SUBST(MKDEP)
@@ -44,7 +133,7 @@ dnl jdc -- If CFLAGS is defined, best use it everywhere...
 dnl NOTE: jv says it must be added to the *END*, because things like
 dnl "gcc -O9 -O2" will result in -O2 getting preference.  How stupid.
 if test "x$CFLAGS" != "x"; then
-  IRC_CFLAGS="$IRC_CFLAGS $CFLAGS"
+  IRC_CFLAGS="$IRC_CFLAGS $CPPFLAGS"
 fi
 
 AC_ISC_POSIX
@@ -55,6 +144,7 @@ AC_PATH_PROG(MV, mv)
 AC_PATH_PROG(LN, ln)
 AC_PATH_PROG(SED, sed)
 AC_PATH_PROG(AR, ar)
+AC_PATH_PROG(LD, ld)
 AC_PROG_YACC
 AC_PROG_INSTALL
 AC_PROG_LEX
@@ -108,7 +198,7 @@ AC_CHECK_FUNCS(gettext,, AC_CHECK_LIB(intl, gettext))
 
 dnl Checks for header files.
 AC_HEADER_STDC
-AC_CHECK_HEADERS(sys/param.h unistd.h errno.h string.h strings.h sys/syslog.h stdlib.h stddef.h getopt.h)
+AC_CHECK_HEADERS(inttypes.h sys/resource.h sys/param.h unistd.h errno.h string.h strings.h sys/syslog.h stdlib.h stddef.h getopt.h)
 
 dnl See whether we can include both string.h and strings.h.
 AC_DEFUN(GCC_HEADER_STRING,
@@ -148,19 +238,40 @@ CHECK_SOCKLEN_T
 
 dnl Check for stdarg.h - if we can't find it, halt configure
 AC_CHECK_HEADER(stdarg.h, , AC_MSG_ERROR(** stdarg.h could not be found - ircd-hybrid will not compile without it **))
-dnl Checks for the existance of strlcat
 
+dnl Checks for the existance of strlcat
 AC_CHECK_FUNCS(strlcat strlcpy)
 
 dnl check for socketpair
 AC_CHECK_FUNCS(socketpair)
 
-dnl check for snprintf and vsnprintf
-AC_CHECK_FUNCS(snprintf vsnprintf)
+dnl check for snprintf
+AC_CHECK_FUNCS(snprintf, [have_snprintf=1])
+dnl check for vsnprintf
+AC_CHECK_FUNCS(vsnprintf, [have_vsnprintf=1])
+dnl Tell src/Makefile.in if we need its snprintf.c
+if test -z "$have_snprintf"; then
+       SNPRINTF_C="snprintf.c"
+fi
+if test -z "$have_vsnprintf"; then
+       SNPRINTF_C="snprintf.c"
+fi
+AC_SUBST(SNPRINTF_C)
 
 dnl check for mmap
 AC_CHECK_FUNCS(mmap)
 
+dnl check for nanosleep
+AC_CHECK_FUNC(nanosleep,,[AC_CHECK_LIB(rt,nanosleep, 
+               LIBS="${LIBS} -lrt",
+               [AC_CHECK_LIB(posix4,nanosleep, LIBS="${LIBS} -lposix4"
+               )])])
+if test x$ac_cv_func_nanosleep = x && test x$ac_cv_lib_posix4_nanosleep = xno  && x$ac_cv_lib_rt_nanosleep
+then   
+       AC_MSG_RESULT("nanosleep not found..using select for delay")
+else
+       AC_DEFINE(HAVE_NANOSLEEP)
+fi
 
 dnl Look for definitions such as RLIMIT_FDMAX, RLIMIT_NOFILE, and
 dnl RLIMIT_OPEN_MAX.  These are used for getrlimit().
@@ -469,7 +580,7 @@ esac
 
 dnl Enable RT sigio - linux only
 AC_ARG_ENABLE(rtsigio,
-[  --enable-rtsigio             Enable SIGIO with RT Signals(Linux only) *experimental*.
+[  --enable-rtsigio             Enable SIGIO with RT Signals(Linux only).
   --disable-rtsigio            Disable SIGIO with RT Signals(Linux only). ],
 [
   case "$enableval" in
@@ -489,6 +600,8 @@ AC_PROG_GCC_TRADITIONAL
 
 AC_CHECK_TYPE(u_int32_t, unsigned int)
 
+AC_CHECK_TYPE(uintptr_t)
+
 rm -f conftest conftest.f
 dnl check for poll() call
 AC_CHECK_FUNC(poll, ac_cv_func_poll="yes",)
@@ -514,17 +627,17 @@ if test "$SELECT_TYPE" != "kqueue" ; then
                 SELECT_TYPE="devpoll"
                 AC_DEFINE(HAVE_DEVPOLL)
                 AC_DEFINE(USE_DEVPOLL)
+       elif test "$ac_cv_func_rtsigio" = "yes" ; then
+               SELECT_TYPE="sigio"
+               AC_DEFINE(USE_SIGIO)
        elif test "$ac_cv_func_poll" = "yes" ; then
                 SELECT_TYPE="poll"
                 AC_DEFINE(USE_POLL)
        elif test "$ac_cv_func_select" = "yes" ; then
                 SELECT_TYPE="select"
                 AC_DEFINE(USE_SELECT)
-       elif test "$ac_cv_func_rtsigio" = "yes" ; then
-               SELECT_TYPE="sigio"
-               AC_DEFINE(USE_SIGIO)
         else
-                echo "Eep!  Can't find kqueue, devpoll, poll _or_ select!"
+                echo "Eep!  Can't find kqueue, devpoll, poll, rtsigio _or_ select!"
                 echo "I'll try select and hope for the best."
                 SELECT_TYPE="select"
                 AC_DEFINE(USE_SELECT)
@@ -573,6 +686,87 @@ AC_ARG_ENABLE(assert,
   esac
 ])
 
+dnl Here are two helper functions to discover the
+dnl implemented way in the OS that shared module support 
+dnl has to use. -TimeMr14C
+
+AC_DEFUN(CHECK_DLOPEN_LD,
+[
+        AC_CHECK_FUNC(shl_load,
+                [
+                        AC_DEFINE(HAVE_SHL_LOAD)
+                        ac_cv_have_shl_load='yes'
+                ],
+                AC_CHECK_LIB(dld, shl_load, AC_DEFINE(HAVE_SHL_LOAD),
+                [
+                ac_cv_have_shl_load='no'
+                echo "shl_load could not be found"
+                ]))
+])
+
+AC_DEFUN(CHECK_DLOPEN_DL,
+[
+        AC_CHECK_FUNC(dlopen,
+                [   
+                        ac_cv_have_dlopen='yes'
+                ],
+                AC_CHECK_LIB(dl, dlopen,
+                [
+                        ac_cv_have_dlopen='yes'
+                ],
+                [   
+                        ac_cv_have_dlopen='no'
+                ]))
+])
+
+dnl small-net
+AC_ARG_ENABLE(small-net,
+[  --enable-small-net           Enable small network support.
+  --disable-small-net          Disable small network support. ],
+[
+  case "$enableval" in
+  yes)
+    echo "Enabling small net code."
+    IRC_CFLAGS="$IRC_CFLAGS -DSMALL_NET=1"
+    ;;
+  no)
+    echo "Disabling small net code."
+    IRC_CFLAGS="$IRC_CFLAGS"
+    ;;
+  esac
+])
+
+ac_cv_nicklen="9"
+ac_cv_maxclients="200"
+
+dnl Nicklen
+AC_ARG_WITH(nicklen,
+[  --with-nicklen=              Set the nick length. ],
+
+[
+       echo $withval
+  if test "$withval" = "no"; then
+       ac_cv_nicklen="9"
+  else
+       ac_cv_nicklen="$withval"
+  fi
+])
+AC_MSG_RESULT("Setting NICKLEN to $ac_cv_nicklen")
+AC_DEFINE_UNQUOTED(NICKLEN, ${ac_cv_nicklen}+1)
+
+dnl Max support clients
+AC_ARG_WITH(maxclients,
+[  --with-maxclients=           Set the maximum number of clients. ],
+
+[
+  if test "$withval" = "no"; then
+       ac_cv_maxclients="200"
+  else
+       ac_cv_maxclients="$withval"
+  fi
+])
+AC_MSG_RESULT("Setting MAX_CLIENTS to $ac_cv_maxclients")
+AC_DEFINE_UNQUOTED(MAX_CLIENTS, ${ac_cv_maxclients})
 
 dnl shared-modules
 AC_ARG_ENABLE(shared-modules,
@@ -608,8 +802,17 @@ else
        MODULES_LIBS=""
        MOD_TARGET="shared_modules"
        SEDOBJ="-e s/.o:/.so:/"
-       AC_CHECK_FUNC(dlopen,, AC_CHECK_LIB(dl, dlopen,,AC_MSG_ERROR(**
-       dlopen could not be found - try running configure with --disable-shared-modules)))
+        CHECK_DLOPEN_LD
+        if test "$ac_cv_have_shl_load" = "no"; then
+            AC_CHECK_HEADER([mach-o/dyld.h],, [CHECK_DLOPEN_DL])
+        fi
+        if test "$ac_cv_have_dlopen" = "no"; then
+            AC_MSG_ERROR(shared module support could not be found - try running configure with --disable-shared-modules)
+        fi
+       dnl Without this, include/setup.h will not be set up right.
+       AC_CHECK_LIB(dl, dlsym)
+       AC_CHECK_FUNCS(dlopen)
+       AC_CHECK_HEADERS(mach-o/dyld.h dlfcn.h)
 
        # The GNU linker requires the -export-dynamic option to make
        # all symbols visible in the dynamic symbol table.
@@ -624,20 +827,42 @@ else
        fi
 
        AC_MSG_CHECKING(for compiler option to produce PIC)
-       if test "$ac_cv_prog_gcc" = "yes"; then
-               AC_MSG_RESULT(gcc: -fPIC -DPIC -shared)
-               PICFLAGS="-fPIC -DPIC -shared"
-       else
-               case `uname -s` in
-               SunOS*)
-                       AC_MSG_RESULT(SunOS - Assuming Sun Workshop compiler: -KPIC -DPIC -G)
-                       PICFLAGS="-KPIC -DPIC -G"
-               ;;
-               *)
+       dnl The order should be here to check for groups of compilers,
+       dnl then for odd compilers, then if no PICFLAGS were set up,
+       dnl check for GCC and set defaults, or else error. -jmallett
+       if test "$SGS" = "yes"; then
+               AC_MSG_RESULT(SVR4 Software Generation System interfaces: -KPIC -DPIC -G)
+               PICFLAGS="-KPIC -DPIC -G"
+       fi
+       if test "$AppleGCC" = "yes"; then
+               AC_MSG_RESULT(Darwin or Mac OS X - Assuming you want to make Mach-O bundles: -fno-common -bundle -flat_namespace -undefined suppress)
+               PICFLAGS="-fno-common -bundle -flat_namespace -undefined suppress"
+       fi
+       dnl Please note, that on HPUX two different stages of module compilation occurs, since
+       dnl while compiling modules, the compiler does not allow you to give arguments
+       dnl to the linker. (I did not design this) 
+       dnl So we need -c in the first stage of module compilation.
+       dnl In the second stage, we link the modules via ld -b.
+       dnl Additionally, HPUX does not like -export-dynamic, it likes -E instead.
+       dnl -TimeMr14C
+       if test "$HPUX" = "yes"; then
+               AC_MSG_RESULT(HP-UX - Assuming HPUX C compiler cc: +z -r -q -n +ESfic)
+               PICFLAGS="+z -r -q -n +ESfic -c"
+               MOD_TARGET="hpux_shared"
+               LDFLAGS="${LDFLAGS} -Wl,-E"
+       fi
+       if test -z "$PICFLAGS"; then
+               if test "$ac_cv_prog_gcc" = "yes"; then
+                       AC_MSG_RESULT(gcc: -fPIC -DPIC -shared)
+                       PICFLAGS="-fPIC -DPIC -shared"
+                       if test "$OSF" = "yes"; then
+                               echo "OSF Discovered: Adding -Wl,-expect_unresolved -Wl,* to compiler flags"
+                               PICFLAGS="$PICFLAGS -Wl,-expect_unresolved -Wl,*"
+                       fi
+               else
                        AC_MSG_RESULT(no)
                        AC_MSG_ERROR(could not find a way to produce position independent code. Try ./configure  --disable-shared-modules)
-               ;;
-               esac
+               fi
        fi
        AC_SUBST(PICFLAGS)
 
@@ -707,7 +932,7 @@ cat << EOF > conftest.c
         }
         void _modinit(void) { return; }
 EOF
-               $CC $IRC_CFLAGS -o conftest conftest.c $nlist_lib >/dev/null 2>&1
+               $CC $CPPFLAGS $IRC_CFLAGS -o conftest conftest.c $nlist_lib >/dev/null 2>&1
                symbol_underscores=`./conftest conftest`
                AC_MSG_RESULT($symbol_underscores)
                $RM -f conftest conftest.c
@@ -716,11 +941,13 @@ EOF
        fi
 fi
 
+
 dnl This needs to be near the end for it to work right...
 if test "$ac_cv_efence" = "yes"; then
        AC_CHECK_LIB(efence,malloc)
 fi
 
+
 AC_SUBST(MODULES_DEFINE)
 AC_SUBST(MODULES_LIBS)
 AC_SUBST(MOD_TARGET)
@@ -746,7 +973,6 @@ AC_OUTPUT(                      \
  src/Makefile                   \
  adns/Makefile                  \
  include/Makefile               \
- loader/Makefile               \
  messages/Makefile              \
  messages/translations/Makefile \
  modules/Makefile               \
@@ -762,3 +988,5 @@ if test "X${cf_openssl_ciphers}" != "X"; then
   echo "${cf_openssl_ciphers}"
   echo ""
 fi
+
+AC_MSG_RESULT("Server is configured with NICKLEN=$ac_cv_nicklen and MAX_CLIENTS=$ac_cv_maxclients")
\ No newline at end of file
index c8d71d66301cb3e39f828c7899c15abe8aea1306..cf12b04b33b1b53f1d1003fbaaf2f7c4cb596719 100755 (executable)
@@ -1,5 +1,5 @@
 /* Hybrid 7 Example configuration file
- * $Id: example.conf,v 1.1 2002/01/04 09:11:16 a1kmm Exp $
+ * $Id: example.conf,v 1.2 2002/04/27 02:48:53 a1kmm Exp $
  * December 2000 - ejb, wcampbel, db and others
  */
 
@@ -666,13 +666,13 @@ channel {
         */
        persist_time = 30 minutes;
 
-        /* NOTE: the splitcode works on a timer.  once we enter splitmode,
+        /* NOTE: the splitcode works on a timer. Once we enter splitmode,
         * we check every 60s to see if we should leave it, therefore its
         * possible that there may be a delay between being able to leave
         * splitmode, and actually doing so
         *
         * split_user_count and split_server_count BOTH need to be true, as
-        * well as one of the split options to enter splitmode
+        * well as one of the no_join_on_split=auto or no_create_on_split=auto
         */
 
        /* the minimum number of users we have before we consider ourselves
index ec5c09861d93a71e1c9f17ef8316c0a6bf21b216..f3b32d78c1cf6e72c3e0656c8dfe4d601e82b9f2 100644 (file)
@@ -11,7 +11,6 @@ SET <option> <value>
                 HARD_FDLIMIT in config.h)
   IDLETIME    - The number of seconds a client can be idle
                 before disconnecting them
-  SHIDE       - Turn server hiding on or off on the fly
   FLOODCOUNT  - The number of lines allowed before
                 throttling a connection due to flooding
                 Note that this variable is used for both
@@ -23,3 +22,10 @@ SET <option> <value>
   MSGLOCALE   - Set the gettext() message locale
                 standard - Compiled in defaults
                 custom   - Old CUSTOM_ERR messages
+  SPLITMODE   - Sets splitmode to <value>:
+                       ON - splitmode is on permanently
+                       OFF - splitmode is permanently off
+                       AUTO - ircd chooses splitmode based
+                              on SPLITUSERs and SPLITNUM
+  SPLITUSERS -  Sets the minimum number of users needed to
+                deactivate automatic splitmode.
index 78992337cb1985979dd289684d2a23d8477475a5..85835460945b4dfc65656ad16922ee4116aebb5a 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- * $Id: channel.h,v 1.4 2002/04/26 04:00:23 a1kmm Exp $
+ * $Id: channel.h,v 1.5 2002/04/27 02:48:58 a1kmm Exp $
  */
 
 #include <sys/types.h>        /* time_t */
@@ -157,7 +157,7 @@ extern void check_spambot_warning(struct Client *source_p,
 extern void ts_burst_channel(struct Client *client_p, struct Channel *chptr,
                              int bursttype, int burstflags);
 
-extern void check_splitmode();
+extern void check_splitmode(void *);
 
 /*
 ** Channel Related macros follow
index 2673687051181e66c07968df37b6ceff51b7af43..7668c4ee98cba3f15026316067a7e18c98a9c8a6 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *  $Id: hook.h,v 1.2 2002/01/06 07:18:12 a1kmm Exp $
+ *  $Id: hook.h,v 1.3 2002/04/27 02:48:58 a1kmm Exp $
  */
 
 #ifndef __HOOK_H_INCLUDED
index 9ef2dbd1e73223bb7b1ccf8f1b5e838de94942c7..f6f72cc8d2115c73ddada8a2066c991dfc034197 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *   $Id: ircd.h,v 1.3 2002/01/06 07:18:12 a1kmm Exp $
+ *   $Id: ircd.h,v 1.4 2002/04/27 02:48:58 a1kmm Exp $
  */
 
 #ifndef INCLUDED_ircd_h
@@ -95,6 +95,7 @@ extern time_t         nextconnect;
 extern int            default_server_capabs;
 
 extern int splitmode;
+extern int splitchecking;
 extern int split_users;
 extern int split_servers;
 
index 39743ec8b1024dc66b5511731e6225f8d35e1b61..5247bc9f557749f071effd6ac40f3a91d9ef11dc 100644 (file)
@@ -17,7 +17,7 @@
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  *
- * $Id: ircd_defs.h,v 1.1 2002/01/04 09:12:56 a1kmm Exp $
+ * $Id: ircd_defs.h,v 1.2 2002/04/27 02:48:58 a1kmm Exp $
  *
  * ircd_defs.h - Global size definitions for record entries used
  * througout ircd. Please think 3 times before adding anything to this
 #define HOSTLEN         63      /* Length of hostname.  Updated to         */
                                 /* comply with RFC1123                     */
 
-#define NICKLEN         9       /* Necessary to put 9 here instead of 10
-                                 * if s_msg.c/m_nick has been corrected.
-                                 * This preserves compatibility with old
-                                 * servers --msa
-                                 */
 #define USERLEN         10
 #define REALLEN         50
 #define TOPICLEN        120     /* old value 90, truncated on other servers */
index e50832215529f041c70f23fb33640e56aebf09d5..d936dee9dc4f929c02b1f0c70e0fc20150eb81b1 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *  $Id: s_protocol.h,v 1.2 2002/04/26 04:00:24 a1kmm Exp $
+ *  $Id: s_protocol.h,v 1.3 2002/04/27 02:48:58 a1kmm Exp $
  */
 
 #ifndef INCLUDED_S_PROTOCOL_H
@@ -44,6 +44,8 @@ struct Protocol
                         int bursttype, int burstflags);
   void (*burst_client)(struct Client *client_p, struct Client *target_p,
                        int bursttype, int burstflags);
+  void (*change_nick)(struct Client *client_p, struct Client *target_p,
+                      const char *new_nick);
 };
 
 extern struct Protocol p_unregistered, p_user, p_operuser;
index a12cc9f9545a98c4391f45b1ee6a38314d95380a..fd7c1287aa7aad850b361fef87a78a1dcc19e87b 100644 (file)
@@ -14,7 +14,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- * $Id: supported.h,v 1.2 2002/01/06 07:18:13 a1kmm Exp $
+ * $Id: supported.h,v 1.3 2002/04/27 02:48:58 a1kmm Exp $
  * 
  */
 
                 " MAXTARGETS=%i" \
                 " NICKLEN=%i" \
                 " TOPICLEN=%i" \
-                " KICKLEN=%i" \
-                " CHANTYPES=%s" \
-                " PREFIX=%s" \
-                " CHANMODES=%s"
+                " KICKLEN=%i"
+
+#define FEATURES2 " CHANTYPES=%s" \
+                  " PREFIX=%s" \
+                  " CHANMODES=%s" \
+                  " NETWORK=%s"
 
 #define FEATURESVALUES ConfigChannel.use_knock ? " KNOCK" : "", \
         ConfigChannel.use_vchans ? " VCHANS" : "", \
         ConfigChannel.use_invex ? " INVEX" : "", \
         MAXMODEPARAMS,ConfigChannel.max_chans_per_user, \
         ConfigChannel.maxbans, \
-        ConfigFileEntry.max_targets,NICKLEN,TOPICLEN,TOPICLEN, \
-       ConfigServerHide.disable_local_channels ? "#" : "#&","(ohv)@%+", \
-        "beI,k,l,imnpsta"
+        ConfigFileEntry.max_targets,NICKLEN,TOPICLEN,TOPICLEN
+
+#define FEATURES2VALUES ConfigServerHide.disable_local_channels ? "#" : "#&", \
+                        "(ohv)@%+", "beI,k,l,imnpsta", \
+                        ServerInfo.network_name
 
 /*
  * - from mirc's versions.txt
index 7e6f02641bb43016da99d6cc45eb358371df10e8..80e8031bfcfa025206e78d6f6c3bb714f60d4b0a 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *   $Id: m_nick.c,v 1.6 2002/02/26 04:55:51 a1kmm Exp $
+ *   $Id: m_nick.c,v 1.7 2002/04/27 02:49:05 a1kmm Exp $
  */
 
 #include "handlers.h"
@@ -59,10 +59,10 @@ static void tsm_nick(struct Client *, struct Client *, int, char **);
 static void tsm_client(struct Client *, struct Client *, int, char **);
 static void m_client(struct Client*, struct Client*, int, char**);
 
-static int nick_from_server(struct Client *, struct Client *, int, char **,
-                            time_t, char *);
-static int client_from_server(struct Client *, struct Client *, int, char **,
-                              time_t, char *);
+static void nick_from_server(struct Client *, struct Client *, int, char **,
+                             time_t, char *);
+static void client_from_server(struct Client *, struct Client *, int, char **,
+                               time_t, char *);
 
 static int check_clean_nick(struct Client *, struct Client *,
                             char *, char *, char *);
@@ -105,7 +105,7 @@ _moddeinit(void)
   mod_del_cmd(nick_msgtab);
 }
 
-char *_version = "$Revision: 1.6 $";
+char *_version = "$Revision: 1.7 $";
 #endif
 
 /*
@@ -638,7 +638,7 @@ clean_host_name(char *host)
 /*
  * nick_from_server()
  */
-static int
+static void
 nick_from_server(struct Client *client_p, struct Client *source_p, int parc,
                  char *parv[], time_t newts, char *nick)
 {
@@ -685,8 +685,9 @@ nick_from_server(struct Client *client_p, struct Client *source_p, int parc,
         m++;
       }
 
-      return do_remote_user(nick, client_p, source_p, parv[5], parv[6],
-                            parv[7], parv[8], NULL);
+      do_remote_user(nick, client_p, source_p, parv[5], parv[6],
+                     parv[7], parv[8], NULL);
+      return;
     }
   }
   else if (source_p->name[0])
@@ -717,15 +718,13 @@ nick_from_server(struct Client *client_p, struct Client *source_p, int parc,
 
   /* remove all accepts pointing to the client */
   del_all_accepts(source_p);
-
-  return 0;
 }
 
 
 /*
  * client_from_server()
  */
-static int
+static void
 client_from_server(struct Client *client_p, struct Client *source_p, int parc,
                    char *parv[], time_t newts, char *nick)
 {
@@ -767,8 +766,8 @@ client_from_server(struct Client *client_p, struct Client *source_p, int parc,
 
   }
 
-  return do_remote_user(nick, client_p, source_p, parv[5], parv[6],
-                        parv[7], name, id);
+  do_remote_user(nick, client_p, source_p, parv[5], parv[6],
+                 parv[7], name, id);
 }
 
 static int
index 9d091afa97b296efe7f87e03e49ed0ee0a01ebbb..13d4e3c46868230cb816d8ec875c788dbf292bc2 100644 (file)
@@ -14,7 +14,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- * $Id: m_cburst.c,v 1.4 2002/01/13 07:15:16 a1kmm Exp $
+ * $Id: m_cburst.c,v 1.5 2002/04/27 02:49:01 a1kmm Exp $
  */
 
 #include "tools.h"
@@ -58,7 +58,7 @@ _moddeinit(void)
   mod_del_cmd(cburst_msgtab);
 }
 
-char *_version = "$Revision: 1.4 $";
+char *_version = "$Revision: 1.5 $";
 #endif
 /*
 ** m_cburst
@@ -122,7 +122,7 @@ ms_cburst(struct Client *client_p,
 
   if (IsCapable(client_p, CAP_LL))
   {
-    burst_channel(client_p, chptr);
+    client_p->protocol->burst_channel(client_p, chptr, 0, 0);
 
     if (nick)
       sendto_one(client_p, ":%s LLJOIN %s %s %s", me.name, name, nick, key);
index 9d812e9c6da2c4f2501da3d130e75e48dc6f46f8..ca823e80f806feb5424f527d6df5d5db6865938a 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *   $Id: m_kline.c,v 1.7 2002/04/19 11:25:32 a1kmm Exp $
+ *   $Id: m_kline.c,v 1.8 2002/04/27 02:49:01 a1kmm Exp $
  */
 
 #include "tools.h"
@@ -84,7 +84,7 @@ _moddeinit(void)
   mod_del_cmd(kline_msgtab);
 }
 
-char *_version = "$Revision: 1.7 $";
+char *_version = "$Revision: 1.8 $";
 #endif
 
 /* Local function prototypes */
@@ -135,7 +135,6 @@ mo_kline(struct Client *client_p,
   const char *target_server = NULL;
   struct ConfItem *aconf;
   time_t tkline_time = 0;
-  time_t cur_time;
 
   if (!IsOperK(source_p))
   {
@@ -204,8 +203,7 @@ mo_kline(struct Client *client_p,
   if (!valid_comment(source_p, reason))
     return;
 
-  cur_time = time(NULL);
-  current_date = smalldate(cur_time);
+  current_date = smalldate(CurrentTime);
   aconf = make_conf();
   aconf->status = CONF_KILL;
   DupString(aconf->host, host);
@@ -251,7 +249,8 @@ mo_kline(struct Client *client_p,
   {
     ircsprintf(buffer, "%s (%s)", reason, current_date);
     DupString(aconf->passwd, buffer);
-    apply_kline(source_p, aconf, reason, oper_reason, current_date, cur_time);
+    apply_kline(source_p, aconf, reason, oper_reason, current_date,
+                CurrentTime);
   }
 }                               /* mo_kline() */
 
@@ -267,7 +266,6 @@ ms_kline(struct Client *client_p,
   const char *current_date;
   struct ConfItem *aconf = NULL;
   int tkline_time;
-  time_t cur_time;
 
   char *kuser;
   char *khost;
@@ -344,13 +342,11 @@ ms_kline(struct Client *client_p,
     DupString(aconf->passwd, kreason);
     current_date = smalldate((time_t) 0);
 
-    cur_time = time(NULL);
-
     if (tkline_time)
       apply_tkline(source_p, aconf, current_date, tkline_time);
     else
       apply_kline(source_p, aconf, aconf->passwd, NULL,
-                  current_date, cur_time);
+                  current_date, CurrentTime);
 
   }
 }                               /* ms_kline() */
@@ -584,7 +580,6 @@ mo_dline(struct Client *client_p, struct Client *source_p,
   int bits, t;
   char dlbuffer[1024];
   const char *current_date;
-  time_t cur_time;
 
   if (!IsOperK(source_p))
   {
@@ -699,8 +694,7 @@ mo_dline(struct Client *client_p, struct Client *source_p,
                  me.name, parv[0], dlhost, aconf->host, creason);
     return;
   }
-  cur_time = time(0);
-  current_date = smalldate(cur_time);
+  current_date = smalldate(CurrentTime);
 
   aconf = make_conf();
 
@@ -722,7 +716,7 @@ mo_dline(struct Client *client_p, struct Client *source_p,
    * Write dline to configuration file
    */
   write_ban(DLINE_TYPE, source_p, NULL, (char*)dlhost, reason,
-            oper_reason, current_date, cur_time);
+            oper_reason, current_date, CurrentTime);
   check_klines();
 }                               /* m_dline() */
 
index 65827c3597404a9beeabebaf5bb15d11099c1012..909286eb9693def8e7d906227498648e6fb40f0e 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *   $Id: m_message.c,v 1.5 2002/02/26 04:55:46 a1kmm Exp $
+ *   $Id: m_message.c,v 1.6 2002/04/27 02:49:01 a1kmm Exp $
  */
 
 #include "handlers.h"
@@ -122,7 +122,7 @@ _moddeinit(void)
   mod_del_cmd(privmsg_msgtab);
 }
 
-char *_version = "$Revision: 1.5 $";
+char *_version = "$Revision: 1.6 $";
 #endif
 
 /*
@@ -176,11 +176,6 @@ m_message(int p_or_n,
 {
   int i;
 
-#if 0                           /* Allow servers to send notices to individual people */
-  if (!IsPerson(source_p))
-    return;
-#endif
-
   /* It is stupid to disallow servers to send privmsgs but not notices.
    */
 #if 0
index 34e26e5961c413cf26e771acfd1f39c061450bf9..6e14fc9e0a5b868ed78827efb296cc0625e460b4 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *   $Id: m_set.c,v 1.4 2002/01/13 07:15:19 a1kmm Exp $ */
+ *   $Id: m_set.c,v 1.5 2002/04/27 02:49:01 a1kmm Exp $ */
 
 /* rewritten by jdc */
 
@@ -65,7 +65,7 @@ _moddeinit(void)
   mod_del_cmd(set_msgtab);
 }
 
-char *_version = "$Revision: 1.4 $";
+char *_version = "$Revision: 1.5 $";
 #endif
 /* Structure used for the SET table itself */
 struct SetStruct
@@ -89,7 +89,7 @@ static void quote_max(struct Client *, int);
 static void quote_msglocale(struct Client *, char *);
 static void quote_spamnum(struct Client *, int);
 static void quote_spamtime(struct Client *, int);
-static void quote_splitmode(struct Client *, int);
+static void quote_splitmode(struct Client *, char *);
 static void quote_splitnum(struct Client *, int);
 static void quote_splitusers(struct Client *, int);
 static void list_quote_commands(struct Client *);
@@ -115,7 +115,7 @@ static struct SetStruct set_cmd_table[] = {
   {"MSGLOCALE", quote_msglocale, 1, 0},
   {"SPAMNUM", quote_spamnum, 0, 1},
   {"SPAMTIME", quote_spamtime, 0, 1},
-  {"SPLITMODE", quote_splitmode, 0, 1},
+  {"SPLITMODE", quote_splitmode, 1, 0},
   {"SPLITNUM", quote_splitnum, 0, 1},
   {"SPLITUSERS", quote_splitusers, 0, 1},
   /* -------------------------------------------------------- */
@@ -387,38 +387,90 @@ quote_spamtime(struct Client *source_p, int newval)
   }
 }
 
+
+/* this table is what splitmode may be set to */
+
+static const char *splitmode_values[] =
+{
+  "OFF",
+  "ON",  
+  "AUTO",
+  NULL
+};
+/* this table is what splitmode may be */
+static const char *splitmode_status[] =
+{  
+  "OFF",
+  "AUTO (OFF)",
+  "ON",
+  "AUTO (ON)",
+  NULL
+};
+
+enum
+{
+  SPLITVALUE_OFF = 0,
+  SPLITVALUE_ON,
+  SPLITVALUE_AUTO,
+  SPLITVALUE_ILLEGAL /* This must remain last. */
+};
+
 /* SET SPLITMODE */
 static void
-quote_splitmode(struct Client *source_p, int newval)
+quote_splitmode(struct Client *source_p, char *charval)
 {
-  if (newval >= 0)
+  if (charval)
   {
-    if ((newval > 0) && !splitmode)
+    int newval;
+    for (newval = 0; splitmode_values[newval]; newval++)  
     {
-      sendto_realops_flags(FLAGS_ALL, L_ALL,
-                           "%s is manually activating splitmode",
-                           get_oper_name(source_p));
-      sendto_one(source_p, ":%s NOTICE %s :SPLITMODE has been activated",
-                 me.name, source_p->name);
-      splitmode = 1;
+      if (!irccmp(splitmode_values[newval], charval))
+        break;
     }
-    else if ((newval == 0) && splitmode)
+    
+    switch (newval)
     {
-      sendto_realops_flags(FLAGS_ALL, L_ALL,
-                           "%s is manually deactivating splitmode",
-                           get_oper_name(source_p));
-      sendto_one(source_p, ":%s NOTICE %s :SPLITMODE has been deactivated",
-                 me.name, source_p->name);
-
-      splitmode = 0;
-
-      /* we might be deactivating an automatic splitmode, so pull the event */
-      eventDelete(check_splitmode, NULL);
+      case SPLITVALUE_OFF:
+        splitmode = 0;
+        splitchecking = 0;
+        sendto_realops_flags(FLAGS_ALL, L_ALL,
+                             "%s is disabling splitmode",
+                             get_oper_name(source_p));
+        /* we might be deactivating an automatic splitmode, so pull the event
+         */
+        eventDelete(check_splitmode, NULL);
+        break;
+      case SPLITVALUE_ON:
+        splitmode = 1;
+        splitchecking = 0;
+        sendto_realops_flags(FLAGS_ALL, L_ALL,
+                             "%s is enabling and activating splitmode",
+                             get_oper_name(source_p));
+        break;
+      case SPLITVALUE_AUTO:
+        splitchecking = 1;
+        sendto_realops_flags(FLAGS_ALL, L_ALL,                            
+                             "%s is enabling automatic splitmode",                            
+                             get_oper_name(source_p));
+        check_splitmode(NULL);
+        break;
+      case SPLITVALUE_ILLEGAL:
+        sendto_one(source_p, ":%s NOTICE %s :You have chosen an invalid "
+                   "option. Read '/quote help set'", me.name, source_p->name);
+        break;
     }
   }
   else
-    sendto_one(source_p, ":%s NOTICE %s :SPLITMODE is currently %i",
-               me.name, source_p->name, splitmode);
+  {
+    /* Map splitmode onto a 2 bit case table with the least significant bit
+     * being the current state of splitchecking and the other bit being
+     * whether splitmode is actually on, and look it up in the table.
+     */
+    sendto_one(source_p, ":%s NOTICE %s :SPLITMODE is currently %s",
+               me.name, source_p->name,
+               splitmode_status[splitmode | (splitchecking<<1)]);
+  }
 }
 
 /* SET SPLITNUM */
@@ -431,6 +483,8 @@ quote_splitnum(struct Client *source_p, int newval)
                          "%s has changed SPLITNUM to %i",
                          source_p->name, newval);
     split_servers = newval;
+    if (splitchecking)
+      check_splitmode(NULL);
   }
   else
     sendto_one(source_p, ":%s NOTICE %s :SPLITNUM is currently %i",
@@ -447,6 +501,8 @@ quote_splitusers(struct Client *source_p, int newval)
                          "%s has changed SPLITUSERS to %i",
                          source_p->name, newval);
     split_users = newval;
+    if (splitchecking)
+      check_splitmode(NULL);
   }
   else
     sendto_one(source_p, ":%s NOTICE %s :SPLITUSERS is currently %i",
index cb425fc8ac5141155cb8604d6adffc96b43e7140..f334ce2bbaf36a80aefb5935a1ab455b834eb81a 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *   $Id: m_svinfo.c,v 1.4 2002/01/13 07:15:19 a1kmm Exp $
+ *   $Id: m_svinfo.c,v 1.5 2002/04/27 02:49:01 a1kmm Exp $
  */
 
 #include "handlers.h"
@@ -61,7 +61,7 @@ _moddeinit(void)
   mod_del_cmd(svinfo_msgtab);
 }
 
-char *_version = "$Revision: 1.4 $";
+char *_version = "$Revision: 1.5 $";
 #endif
 /*
  * ms_svinfo - SVINFO message handler
@@ -109,7 +109,7 @@ ms_svinfo(struct Client *client_p, struct Client *source_p,
   /*
    * since we're here, might as well set CurrentTime while we're at it
    */
-  CurrentTime = time(0);
+  set_time();
   theirtime = atol(parv[4]);
   deltat = abs(theirtime - CurrentTime);
 
index 5ca3acd51d90455021057a5348d4ec35e1db1466..35fdb8f05f5d6dac88ecd536dbc03da0a7028acd 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *   $Id: m_trace.c,v 1.5 2002/02/26 04:55:47 a1kmm Exp $
+ *   $Id: m_trace.c,v 1.6 2002/04/27 02:49:01 a1kmm Exp $
  */
 
 #include "handlers.h"
@@ -74,7 +74,7 @@ _moddeinit(void)
   mod_del_cmd(trace_msgtab);
 }
 
-char *_version = "$Revision: 1.5 $";
+char *_version = "$Revision: 1.6 $";
 #endif
 static int report_this_status(struct Client *source_p,
                               struct Client *target_p, int dow, int link_u_p,
@@ -115,7 +115,6 @@ mo_trace(struct Client *client_p, struct Client *source_p,
   char *tname;
   int doall, link_s[MAXCONNECTIONS], link_u[MAXCONNECTIONS];
   int cnt = 0, wilds, dow;
-  static time_t now;
   dlink_node *ptr;
   char *looking_for = parv[0];
 
@@ -158,8 +157,6 @@ mo_trace(struct Client *client_p, struct Client *source_p,
   wilds = !parv[1] || strchr(tname, '*') || strchr(tname, '?');
   dow = wilds || doall;
 
-  now = time(NULL);
-
   if (!IsOper(source_p) || !dow)        /* non-oper traces must be full nicks */
     /* lets also do this for opers tracing nicks */
   {
@@ -183,8 +180,9 @@ mo_trace(struct Client *client_p, struct Client *source_p,
                    me.name, parv[0], class_name, name,
                    MyOper(source_p) ? ipaddr :
                    (IsIPSpoof(target_p) ? "255.255.255.255" : ipaddr),
-                   now - target_p->lasttime,
-                   (target_p->user) ? (now - target_p->user->last) : 0);
+                   CurrentTime - target_p->lasttime,
+                   (target_p->user) ? (CurrentTime - target_p->user->last) :
+                                      0);
       }
       else
       {
@@ -192,8 +190,9 @@ mo_trace(struct Client *client_p, struct Client *source_p,
                    me.name, parv[0], class_name, name,
                    MyOper(source_p) ? ipaddr :
                    (IsIPSpoof(target_p) ? "255.255.255.255" : ipaddr),
-                   now - target_p->lasttime,
-                   (target_p->user) ? (now - target_p->user->last) : 0);
+                   CurrentTime - target_p->lasttime,
+                   (target_p->user) ? (CurrentTime - target_p->user->last) :
+                                      0);
       }
     }
 
@@ -328,15 +327,12 @@ report_this_status(struct Client *source_p, struct Client *target_p,
   const char *class_name;
   char ip[HOSTIPLEN];
   int cnt = 0;
-  static time_t now;
 
   inetntop(target_p->localClient->aftype, &IN_ADDR(target_p->localClient->ip),
            ip, HOSTIPLEN);
   name = get_client_name(target_p, HIDE_IP);
   class_name = get_client_class(target_p);
 
-  now = time(NULL);
-
   switch (target_p->status)
   {
     case STAT_CONNECTING:
@@ -375,24 +371,27 @@ report_this_status(struct Client *source_p, struct Client *target_p,
           sendto_one(source_p, form_str(RPL_TRACEOPERATOR),
                      me.name, source_p->name, class_name, name,
                      IsOperAdmin(source_p) ? ip : "255.255.255.255",
-                     now - target_p->lasttime,
-                     (target_p->user) ? (now - target_p->user->last) : 0);
+                     CurrentTime - target_p->lasttime,
+                     (target_p->user) ? (CurrentTime - target_p->user->last) :
+                                        0);
 
         else if (IsOper(target_p))
           sendto_one(source_p, form_str(RPL_TRACEOPERATOR),
                      me.name, source_p->name, class_name, name,
                      MyOper(source_p) ? ip :
                      (IsIPSpoof(target_p) ? "255.255.255.255" : ip),
-                     now - target_p->lasttime,
-                     (target_p->user) ? (now - target_p->user->last) : 0);
+                     CurrentTime - target_p->lasttime,
+                     (target_p->user) ? (CurrentTime - target_p->user->last) :
+                                         0);
 
         else
           sendto_one(source_p, form_str(RPL_TRACEUSER),
                      me.name, source_p->name, class_name, name,
                      MyOper(source_p) ? ip :
                      (IsIPSpoof(target_p) ? "255.255.255.255" : ip),
-                     now - target_p->lasttime,
-                     (target_p->user) ? (now - target_p->user->last) : 0);
+                     CurrentTime - target_p->lasttime,
+                     (target_p->user) ? (CurrentTime - target_p->user->last) :
+                                        0);
         cnt++;
       }
       break;
@@ -404,7 +403,7 @@ report_this_status(struct Client *source_p, struct Client *target_p,
                  me.name, source_p->name, class_name, link_s_p,
                  link_u_p, name, *(target_p->serv->by) ?
                  target_p->serv->by : "*", "*",
-                 me.name, now - target_p->lasttime);
+                 me.name, CurrentTime - target_p->lasttime);
       cnt++;
       break;
 
index 52278e098ed003f1558ab7942637585db0b21d2a..b14defcf8f1ae76414d8ad021c053f6d7fd95e59 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *   $Id: balloc.c,v 1.6 2002/04/19 10:56:19 a1kmm Exp $
+ *   $Id: balloc.c,v 1.7 2002/04/27 02:49:07 a1kmm Exp $
  */
 
 /* A note on the algorithm:
@@ -155,7 +155,10 @@ initBlockHeap(void)
 static GINLINE void*
 get_block(size_t size)
 {
-  return (mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, zero_fd, 0));
+  void *ptr;
+  ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, zero_fd, 0);
+  return (ptr != MAP_FAILED) ? ptr : NULL;
+  
 }
 #else /* MAP_ANON */ 
 
@@ -184,7 +187,10 @@ initBlockHeap(void)
 static INLINE void*
 get_block(size_t size)
 {
-  return (mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0));
+  void *ptr;
+  ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1,
+             0);
+  return (ptr != MAP_FAILED) ? ptr : NULL;
 }
 
 #endif /* MAP_ANON */
index 0b39c6891d811df226fde63902d0daa2b0ba8e35..8c3e3e3af1d54d4854b98d14c98c4b9e731f5aa2 100644 (file)
@@ -14,7 +14,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- * $Id: channel.c,v 1.7 2002/04/26 04:00:29 a1kmm Exp $
+ * $Id: channel.c,v 1.8 2002/04/27 02:49:07 a1kmm Exp $
  */
 
 #include "tools.h"
@@ -63,6 +63,8 @@ static int check_banned(struct Channel *chptr, struct Client *who,
 static char buf[BUFSIZE];
 static char modebuf[MODEBUFLEN], parabuf[MODEBUFLEN];
 
+int splitchecking;
+
 /* 
  * init_channels
  *
@@ -78,7 +80,7 @@ channelheap_garbage_collect(void *unused)
 void
 init_channels(void)
 {
-  channel_heap = BlockHeapCreate(sizeof(struct Channel), 1024);
+  channel_heap = BlockHeapCreate(sizeof(struct Channel), 2048);
   ban_heap = BlockHeapCreate(sizeof(struct Ban), 2048);
   eventAddIsh("channelheap_garbage_collect", channelheap_garbage_collect,
               NULL, 45);
@@ -266,11 +268,11 @@ send_members(struct Client *client_p,
   int data_to_send = 0;
   char *t;                      /* temp char pointer */
 
-  ircsprintf(buf, ":%s SJOIN %lu %s %s %s :", me.name,
-             (unsigned long)chptr->channelts,
-             chptr->chname, lmodebuf, lparabuf);
+  cur_len = ircsprintf(buf, ":%s SJOIN %lu %s %s %s :", me.name,
+                       (unsigned long)chptr->channelts,
+                       chptr->chname, lmodebuf, lparabuf);
 
-  cur_len = mlen = strlen(buf);
+  mlen = cur_len;
   t = buf + mlen;
 
   for (ptr = list->head; ptr && ptr->data; ptr = ptr->next)
@@ -1246,26 +1248,25 @@ check_spambot_warning(struct Client *source_p, const char *name)
 void
 check_splitmode(void *unused)
 {
-  if (splitmode)
+  if (splitchecking &&
+      (ConfigChannel.no_join_on_split || ConfigChannel.no_create_on_split))
   {
-    if ((Count.server >= split_servers) && (Count.total >= split_users))
+    if ((Count.server < split_servers) && (Count.total < split_users))
+    {
+      if (!splitmode)
+      {
+        splitmode = 1;
+        sendto_realops_flags(FLAGS_ALL, L_ALL,
+                             "Network split, activating splitmode");
+        eventAdd("check_splitmode", check_splitmode, NULL, 60);
+      }
+    }
+    else if (splitmode)
     {
       splitmode = 0;
-
       sendto_realops_flags(FLAGS_ALL, L_ALL,
                            "Network rejoined, deactivating splitmode");
       eventDelete(check_splitmode, NULL);
     }
   }
-  else
-  {
-    if ((Count.server < split_servers) && (Count.total < split_users))
-    {
-      splitmode = 1;
-
-      sendto_realops_flags(FLAGS_ALL, L_ALL,
-                           "Network split, activating splitmode");
-      eventAdd("check_splitmode", check_splitmode, NULL, 60);
-    }
-  }
 }
index b5154b4267303831b5389bbe504e85e83e34d60a..6729e175c83ed73c8ef8e5c5c25881a38e358b7a 100644 (file)
@@ -14,7 +14,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *   $Id: class.c,v 1.3 2002/01/06 07:18:47 a1kmm Exp $
+ *   $Id: class.c,v 1.4 2002/04/27 02:49:07 a1kmm Exp $
  */
 
 #include "tools.h"
@@ -114,34 +114,22 @@ get_client_class(struct Client *target_p)
 int
 get_client_ping(struct Client *target_p)
 {
-  int ping = 0;
-  int ping2;
+  int ping = DEFAULT_PINGFREQUENCY, ping2;
   struct ConfItem *aconf;
   dlink_node *nlink;
 
-
-  if (target_p->localClient->confs.head != NULL)
+  for (nlink = target_p->localClient->confs.head; nlink;
+       nlink = nlink->next)
   {
-    for (nlink = target_p->localClient->confs.head; nlink;
-         nlink = nlink->next)
+    aconf = nlink->data;
+    if (aconf->status & (CONF_CLIENT | CONF_SERVER))
     {
-      aconf = nlink->data;
-      if (aconf->status & (CONF_CLIENT | CONF_SERVER))
-      {
-        ping2 = get_conf_ping(aconf);
-        if ((ping2 != BAD_PING) && ((ping > ping2) || !ping))
-          ping = ping2;
-      }
+      ping2 = get_conf_ping(aconf);
+      if ((ping2 != BAD_PING) && ping2 > 0)
+        ping = ping2;
     }
   }
-  else
-  {
-    ping = DEFAULT_PINGFREQUENCY;
-    Debug((DEBUG_DEBUG, "No Attached Confs"));
-  }
 
-  if (ping <= 0)
-    ping = DEFAULT_PINGFREQUENCY;
   Debug((DEBUG_DEBUG, "Client %s Ping %d", target_p->name, ping));
   return (ping);
 }
index 1caba26fc85b9e696db956b8dae04cc25b927bd0..d656e83c367e3b57689d0e9cac5461f44fb6b6cb 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *  $Id: client.c,v 1.7 2002/04/26 04:00:29 a1kmm Exp $
+ *  $Id: client.c,v 1.8 2002/04/27 02:49:07 a1kmm Exp $
  */
 
 #include "tools.h"
@@ -51,6 +51,7 @@
 #include "memory.h"
 #include "hostmask.h"
 #include "balloc.h"
+#include "s_protocol.h"
 
 #include <assert.h>
 #include <fcntl.h>
@@ -184,10 +185,9 @@ _free_client(struct Client *client_p)
   assert(0 == client_p->prev);
   assert(0 == client_p->next);
 
-  /* If localClient is non NULL, its a local client */
-  if (client_p->localClient != NULL)
+  if (MyConnect(client_p))
   {
-    if (-1 < client_p->localClient->fd)
+    if (client_p->localClient->fd >= 0)
       fd_close(client_p->localClient->fd);
 
 #ifndef NDEBUG
@@ -509,6 +509,23 @@ check_klines(void)
       }
     }
   }
+  /* also check the unknowns list for new dlines */
+  
+  for (ptr = unknown_list.head; ptr; ptr = next_ptr)
+    
+  {
+    next_ptr = ptr->next;    
+    client_p = ptr->data;
+
+    if((aconf = find_dline(&client_p->localClient->ip,
+                           client_p->localClient->aftype)))  
+    {
+      if (aconf->status & CONF_EXEMPTDLINE)
+        continue;      
+      sendto_one(client_p, "NOTICE DLINE :*** You have been D-lined");      
+      exit_client(client_p, client_p, &me, "D-lined"); 
+    } 
+  } 
 }
 
 /*
@@ -537,9 +554,8 @@ update_client_exit_stats(struct Client *client_p)
       --Count.invisi;
   }
 
-  if (!splitmode &&
-      (ConfigChannel.no_join_on_split || ConfigChannel.no_create_on_split))
-    check_splitmode();
+  if (splitchecking && !splitmode)
+    check_splitmode(NULL);
 }
 
 /*
@@ -1625,6 +1641,7 @@ change_local_nick(struct Client *client_p, struct Client *source_p,
      ** on a channel, send note of change to all clients
      ** on that channel. Propagate notice to other servers.
    */
+  dlink_node *servnode;
 
   source_p->tsinfo = CurrentTime;
 
@@ -1658,9 +1675,16 @@ change_local_nick(struct Client *client_p, struct Client *source_p,
        * hubs might not propogate a nick change, if the leaf
        * does not know about that client yet.
        */
-      sendto_server(client_p, source_p, NULL, NOCAPS, NOCAPS,
-                    NOFLAGS, ":%s NICK %s :%lu", source_p->name,
-                    nick, (unsigned long)source_p->tsinfo);
+      /* XXX we generate the linebuf once per protocol later for a
+       * speed boost if this gets to be too slow.
+       */
+      for (servnode = serv_list.head; servnode; servnode = servnode->next)
+      {
+        struct Client *target_p = (struct Client*)servnode->data;
+        if (target_p == client_p)
+          continue;
+        target_p->protocol->change_nick(target_p, source_p, nick);
+      }
     }
   }
   else
index 3d51da786d1a27dbc8cccfbd43c88d4bb9e1117d..1c13094452a537f3a396fb24bb4a3d884b2c0f0e 100644 (file)
@@ -14,7 +14,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- * $Id: ircd.c,v 1.7 2002/04/19 10:56:20 a1kmm Exp $
+ * $Id: ircd.c,v 1.8 2002/04/27 02:49:08 a1kmm Exp $
  */
 
 #include <sys/types.h>
@@ -333,14 +333,16 @@ io_loop(void)
     /* Check on the last activity, sleep for up to 1/2s if we are idle... */
     if (callbacks_called > 0)
       empty_cycles = 0;
+    else
+      empty_cycles++;
 
     /* Reset the callback counter... */
     callbacks_called = 0;
 
-    if (empty_cycles++ > 10)
-      comm_select((st = ((empty_cycles - 10) * 10) > 500 ? 500 : st));
-    else
-      comm_select(0);
+    st = (empty_cycles+1) * 15000;
+    if (st > 250000)
+      st = 250000;
+    usleep(st);
 
     /*
      * Check to see whether we have to rehash the configuration ..
@@ -380,9 +382,12 @@ initialize_global_set_options(void)
   split_users = ConfigChannel.split_server_count;
   split_servers = ConfigChannel.split_user_count;
 
-  if (split_users && split_servers)
+  if (split_users && split_servers &&
+      (ConfigChannel.no_join_on_split || ConfigChannel.no_create_on_split))
+  {
     splitmode = 1;
-
+    splitchecking = 1;
+  }
   /* memset( &ConfigChannel, 0, sizeof(ConfigChannel)); */
 
   /* End of global set options */
index df819b74355d64f0a7f3f144357e6a04f83aab14..bfb1f57a6fd5497cb283d4dcbb9e4a045e5a31c9 100644 (file)
@@ -14,7 +14,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- * $Id: ircd_parser.y,v 1.3 2002/01/06 07:18:49 a1kmm Exp $
+ * $Id: ircd_parser.y,v 1.4 2002/04/27 02:49:08 a1kmm Exp $
  */
 
 %{
@@ -496,6 +496,11 @@ serverinfo_description: DESCRIPTION '=' QSTRING ';'
 
 serverinfo_network_name: NETWORK_NAME '=' QSTRING ';'
   {
+    char *p;
+    /* Clean out spaces... */
+    while ((p = strchr(yylval.string, ' ')) ||
+           (p = strchr(yylval.string, '\t')))
+      strcpy(p, p + 1);
     MyFree(ServerInfo.network_name);
     DupString(ServerInfo.network_name,yylval.string);
   };
index a76f8fec0a15fc3185b53939ddf24ff662b8ecea..140c964bb952f937ecc2fc8de3970dbd6249fc24 100644 (file)
@@ -14,7 +14,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *  $Id: listener.c,v 1.3 2002/01/06 07:18:50 a1kmm Exp $
+ *  $Id: listener.c,v 1.4 2002/04/27 02:49:08 a1kmm Exp $
  */
 
 #include "config.h"
@@ -233,9 +233,7 @@ inetport(struct Listener *listener)
 
   /* Listen completion events are READ events .. */
 
-
-  comm_setselect(fd, FDLIST_SERVICE, COMM_SELECT_READ, accept_connection,
-                 listener, 0);
+  accept_connection(fd, listener);
 
   return 1;
 }
@@ -399,14 +397,17 @@ accept_connection(int pfd, void *data)
 
   if (fd < 0)
   {
-    /*
-     * slow down the whining to opers bit
-     */
-    if ((last_oper_notice + 20) <= CurrentTime)
+    if (!ignoreErrno(errno))
     {
-      report_error(L_ALL, "Error accepting connection %s:%s",
-                   listener->name, errno);
-      last_oper_notice = CurrentTime;
+      /*
+       * slow down the whining to opers bit
+       */
+      if ((last_oper_notice + 20) <= CurrentTime)
+      {
+        report_error(L_ALL, "Error accepting connection %s:%s",
+                     listener->name, errno);
+        last_oper_notice = CurrentTime;
+      }
     }
     /* Re-register a new IO request for the next accept .. */
     comm_setselect(listener->fd, FDLIST_SERVICE, COMM_SELECT_READ,
index 9ee9925c52ba62b31059d685b893136f2da0c8f3..dba0a03b6f2c0ec788eea215bd4b3e60d348fa75 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *   $Id: p_ts.c,v 1.3 2002/04/26 04:00:30 a1kmm Exp $
+ *   $Id: p_ts.c,v 1.4 2002/04/27 02:49:08 a1kmm Exp $
  */
 
 #include "ircd.h"
@@ -33,7 +33,9 @@
 
 #ifdef ENABLE_TS5
 
-void tsm_error(struct Client*, struct Client*, int, char **);
+void tsm_error(struct Client*, struct Client*, int, char**);
+void ts_change_nick(struct Client*, struct Client*, char*);
+
 
 void
 tsm_error(struct Client *client_p, struct Client *source_p,
@@ -55,6 +57,14 @@ tsm_error(struct Client *client_p, struct Client *source_p,
                          para);
 }
 
+void
+ts_change_nick(struct Client *client_p, struct Client *target_p,
+               char *new_nick)
+{
+  sendto_one(client_p, ":%s NICK %s :%lu", target_p->name, new_nick,
+             target_p->tsinfo);
+}
+
 struct Protocol p_ts5 =
 {
   m_error: tsm_error,
index 338757766ab611bef64e7e8360cefe01f4093ef9..f4bc5e9e745c7dc1e194df051545399b79da58b3 100644 (file)
@@ -14,7 +14,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *   $Id: parse.c,v 1.6 2002/02/26 04:55:55 a1kmm Exp $
+ *   $Id: parse.c,v 1.7 2002/04/27 02:49:08 a1kmm Exp $
  */
 
 #include <assert.h>
@@ -106,6 +106,9 @@ string_to_array(char *string, char *parv[MAXPARA])
       return x;
   } while (x < MAXPARA - 1);
 
+  if (*p != ':')
+    p++;
+
   parv[x++] = p;
   parv[x] = NULL;
   return x;
index 9f77038d85d0a0288e92f3e64126b2bcb91bd942..09c838ace659fbc7d33bcfe87a0871690ff66b4f 100644 (file)
@@ -14,9 +14,9 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *   $Id: s_auth.c,v 1.4 2002/02/26 04:55:55 a1kmm Exp $
+ *   $Id: s_auth.c,v 1.5 2002/04/27 02:49:08 a1kmm Exp $
  *
- *  $Id: s_auth.c,v 1.4 2002/02/26 04:55:55 a1kmm Exp $
+ *  $Id: s_auth.c,v 1.5 2002/04/27 02:49:08 a1kmm Exp $
  */
 
 /*
@@ -576,8 +576,7 @@ auth_connect_callback(int fd, int error, void *data)
   ClearAuthConnect(auth);
   SetAuthPending(auth);
   /* Its idle, because we don't mind this taking a little time -- adrian */
-  comm_setselect(auth->fd, FDLIST_IDLECLIENT, COMM_SELECT_READ,
-                 read_auth_reply, auth, 0);
+  read_auth_reply(auth->fd, auth);
 }
 
 
index b1b2c217a2dc3a792cd8e51a9799237968f761e4..8a3d5fbd565f6d16d9566989bc35423ff7f4b74f 100644 (file)
@@ -14,7 +14,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *  $Id: s_bsd.c,v 1.7 2002/02/26 04:55:55 a1kmm Exp $
+ *  $Id: s_bsd.c,v 1.8 2002/04/27 02:49:09 a1kmm Exp $
  */
 
 #include "config.h"
@@ -357,6 +357,18 @@ close_connection(struct Client *client_p)
     client_p->localClient->ctrlfd = -1;
   } 
 
+  if(HasServlink(client_p))  
+  {
+    fd_close(client_p->localClient->ctrlfd);
+#ifndef HAVE_SOCKETPAIR
+    fd_close(client_p->localClient->ctrlfd_r);
+    fd_close(client_p->localClient->fd_r);
+    client_p->localClient->ctrlfd_r = -1;
+    client_p->localClient->fd_r = -1;
+#endif
+    client_p->localClient->ctrlfd = -1;  
+  }
+
   linebuf_donebuf(&client_p->localClient->buf_sendq);
   linebuf_donebuf(&client_p->localClient->buf_recvq);
   memset(client_p->localClient->passwd, 0,
index cbe1554f24cde3d674f1604b966da060f7c008e2..0572f020637a66747cf3f9f2c56c55f1f6dce38d 100644 (file)
@@ -44,7 +44,7 @@
  *   along with this program; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- *  $Id: s_bsd_sigio.c,v 1.3 2002/01/06 07:18:51 a1kmm Exp $
+ *  $Id: s_bsd_sigio.c,v 1.4 2002/04/27 02:49:09 a1kmm Exp $
  */
 
 #ifndef _GNU_SOURCE
@@ -115,40 +115,6 @@ typedef struct _pollfd_list pollfd_list_t;
 pollfd_list_t pollfd_list;
 static void poll_update_pollfds(int, short, PF *);
 
-/*
- * static void set_sigio(int fd)
- *
- * Input: File descriptor to modify
- * Output: None
- * Side Effects:  Sets O_ASYNC on the said descriptor
- */
-static void
-set_sigio(int fd)
-{
-  int flags;
-  fcntl(fd, F_GETFL, &flags);
-  flags |= O_ASYNC | O_NONBLOCK;
-  fcntl(fd, F_SETFL, flags);
-}
-
-/*
- * static void clear_sigio(int fd)
- *
- * Input: File descriptor to modify
- * Output: None
- * Side Effects: Removes O_ASYNC from the fd
- */
-static void
-clear_sigio(int fd)
-{
-  int flags;
-  fcntl(fd, F_GETFL, &flags);
-  flags &= ~O_ASYNC;
-  /* This _is_ needed... */
-  flags |= O_NONBLOCK;
-  fcntl(fd, F_SETFL, flags);
-}
-
 /* 
  * static void mask_our_signal(int s)
  *
@@ -196,7 +162,6 @@ poll_update_pollfds(int fd, short event, PF * handler)
 
   if (F->comm_index < 0)
   {
-    set_sigio(fd);
     F->comm_index = poll_findslot();
   }
   comm_index = F->comm_index;
@@ -218,7 +183,6 @@ poll_update_pollfds(int fd, short event, PF * handler)
       pollfd_list.pollfds[comm_index].events &= ~event;
       if (pollfd_list.pollfds[comm_index].events == 0)
       {
-        clear_sigio(fd);
         pollfd_list.pollfds[comm_index].fd = -1;
         pollfd_list.pollfds[comm_index].revents = 0;
         F->comm_index = -1;
@@ -314,8 +278,6 @@ comm_setselect(int fd, fdlist_t list, unsigned int type, PF * handler,
     F->read_handler = handler;
     F->read_data = client_data;
     poll_update_pollfds(fd, POLLIN, handler);
-    if (new_hdl && handler != NULL)
-      handler(fd, client_data);
   }
   if (type & COMM_SELECT_WRITE)
   {
@@ -323,8 +285,6 @@ comm_setselect(int fd, fdlist_t list, unsigned int type, PF * handler,
     F->write_handler = handler;
     F->write_data = client_data;
     poll_update_pollfds(fd, POLLOUT, handler);
-    if (new_hdl && handler != NULL)
-      handler(fd, client_data);
   }
   if (timeout)
     F->timeout = CurrentTime + (timeout / 1000);
index d6579a87012eab6c8c407792d6179a8ba237d858..46581c204af1a1bd201bd0154c3ad0c03526f060 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *   $Id: s_serv.c,v 1.6 2002/04/26 04:00:30 a1kmm Exp $
+ *   $Id: s_serv.c,v 1.7 2002/04/27 02:49:09 a1kmm Exp $
  */
 
 #include <sys/types.h>
@@ -262,13 +262,10 @@ collect_zipstats(void *unused)
         target_p->localClient->slinkq_len = 1;
 
         /* schedule a write */
-        comm_setselect(target_p->localClient->ctrlfd, FDLIST_IDLECLIENT,
-                       COMM_SELECT_WRITE, send_queued_slink_write,
-                       target_p, 0);
+        send_queued_slink_write(target_p->localClient->ctrlfd, target_p);
       }
     }
   }
-
 }
 
 
@@ -517,6 +514,12 @@ hunt_server(struct Client *client_p, struct Client *source_p, char *command,
 
   if (target_p)
   {
+    if (!IsRegistered(target_p))
+    {
+      sendto_one(source_p, form_str(ERR_NOSUCHSERVER), me.name,
+                 parv[0], parv[server]);
+      return HUNTED_NOSUCH;
+    }
     if (IsMe(target_p) || MyClient(target_p))
       return HUNTED_ISME;
 
@@ -1363,8 +1366,14 @@ fork_server(struct Client *server)
   slink_fds[1][0][1] = fd_temp[1];
 #endif
 
+  /* XXX do we really want a goto? */
+#ifdef __CYGWIN__
+  if ((ret = vfork()) < 0)
+    goto fork_error;
+#else
   if ((ret = fork()) < 0)
     goto fork_error;
+#endif
   else if (ret == 0)
   {
     /* set our fds as non blocking and close everything else */
@@ -1386,8 +1395,9 @@ fork_server(struct Client *server)
       }
       else
       {
-#ifdef VMS
-        if (i > 2)              /* don't close std* */
+#if defined(VMS) || defined(__CYGWIN__)
+        /* don't close std* */
+        if (i > 2) 
 #endif
           close(i);
       }
@@ -1476,8 +1486,8 @@ fork_server(struct Client *server)
 
     comm_setselect(slink_fds[0][1][0], FDLIST_SERVER, COMM_SELECT_READ,
                    read_ctrl_packet, server, 0);
-    comm_setselect(slink_fds[1][1][0], FDLIST_SERVER, COMM_SELECT_READ,
-                   read_packet, server, 0);
+    read_ctrl_packet(slink_fds[0][1][0], server);
+    read_packet(slink_fds[1][1][0], server);
   }
 
   return 0;
index a1699ac3ea3ba735836a9de13dfc533cb4a85aef..f3a836e8de2295ec4fbfe6ce9663172244c69e36 100644 (file)
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *  $Id: s_user.c,v 1.7 2002/04/26 04:00:30 a1kmm Exp $
+ *  $Id: s_user.c,v 1.8 2002/04/27 02:49:09 a1kmm Exp $
  */
 
 #include <sys/types.h>
@@ -270,6 +270,9 @@ show_isupport(struct Client *source_p)
   ircsprintf(isupportbuffer, FEATURES, FEATURESVALUES);
   sendto_one(source_p, form_str(RPL_ISUPPORT), me.name, source_p->name,
              isupportbuffer);
+  ircsprintf(isupportbuffer, FEATURES2, FEATURES2VALUES);
+  sendto_one(source_p, form_str(RPL_ISUPPORT), me.name, source_p->name,
+             isupportbuffer);
 }
 
 void
@@ -432,6 +435,10 @@ register_local_user(struct Client *client_p, struct Client *source_p,
                        nick, source_p->username, source_p->host,
                        ipaddr, get_client_class(source_p), source_p->info);
 
+  assert(!(source_p->umodes & FLAGS_INVISIBLE));
+  source_p->umodes |= FLAGS_INVISIBLE;
+  Count.invisi++;
+
   if ((++Count.local) > Count.max_loc)
   {
     Count.max_loc = Count.local;
@@ -501,7 +508,7 @@ register_remote_user(struct Client *client_p, struct Client *source_p,
     kill_client(client_p, source_p, "%s (Server doesn't exist)", me.name);
 
     source_p->flags |= FLAGS_KILLED;
-    exit_client(NULL, source_p, &me, "Ghost");
+    exit_client(NULL, source_p, &me, "Ghosted Client");
     return;
   }
 
@@ -729,7 +736,7 @@ void
 do_local_user(char *nick, struct Client *client_p, struct Client *source_p,
               char *username, char *host, char *server, char *realname)
 {
-  unsigned int oflags;
+  unsigned int oldmode;
   struct User *user;
 
   assert(0 != source_p);
@@ -737,17 +744,13 @@ do_local_user(char *nick, struct Client *client_p, struct Client *source_p,
 
   user = make_user(source_p);
 
-  oflags = source_p->flags;
+  oldmode = source_p->umodes;
 
   if (!IsUnknown(source_p))
   {
     sendto_one(source_p, form_str(ERR_ALREADYREGISTRED), me.name, nick);
     return;
   }
-  source_p->flags |= FLAGS_INVISIBLE;
-
-  if (!(oflags & FLAGS_INVISIBLE) && IsInvisible(source_p))
-    Count.invisi++;
 
   source_p->servptr = &me;
 
@@ -783,7 +786,6 @@ do_remote_user(char *nick, struct Client *client_p, struct Client *source_p,
                char *username, char *host, char *server, char *realname,
                char *id)
 {
-  unsigned int oflags;
   struct User *user;
 
   assert(0 != source_p);
@@ -791,8 +793,6 @@ do_remote_user(char *nick, struct Client *client_p, struct Client *source_p,
 
   user = make_user(source_p);
 
-  oflags = source_p->flags;
-
   /*
    * coming from another server, take the servers word for it
    */
index e7dd2345d4ae2d93ee18aaad96001f467fb8c129..0a0d404cde281be6a24377ac91758641ae64ab33 100644 (file)
@@ -14,7 +14,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *   $Id: send.c,v 1.5 2002/04/26 04:00:30 a1kmm Exp $
+ *   $Id: send.c,v 1.6 2002/04/27 02:49:09 a1kmm Exp $
  */
 
 #include <sys/types.h>
@@ -110,7 +110,7 @@ dead_link(struct Client *to, char *notice)
     sendto_realops_flags(FLAGS_ALL, L_OPER, notice,
                          get_client_name(to, MASK_IP));
   }
-  exit_client(to, to, &me, notice);
+  exit_client(to, to, &me, "Dead link");
   Debug((DEBUG_ERROR, notice, get_client_name(to, HIDE_IP)));
   return -1;
 }