chiark / gitweb /
Reorganised adnshost into several files, some querying.
authorian <ian>
Sun, 10 Oct 1999 16:30:46 +0000 (16:30 +0000)
committerian <ian>
Sun, 10 Oct 1999 16:30:46 +0000 (16:30 +0000)
client/Makefile.in
client/adh-main.c [new file with mode: 0644]
client/adh-opts.c [moved from client/adnshost.c with 82% similarity]
client/adh-query.c [new file with mode: 0644]
client/adnshost.h [new file with mode: 0644]

index 02effcb2b7cd9155380a36f6de7d796564342578..0ed57ac8a22119fef777ecb86b2d3d10447b1282 100644 (file)
@@ -32,6 +32,8 @@ include               $(srcdir)/../settings.make
 
 DIRCFLAGS=     -I$(srcdir)/../src
 
+ADH_OBJS=      adh-main.o adh-opts.o adh-query.o
+
 all:           $(TARGETS)
 
 install:       $(TARG_INSTALL)
@@ -41,6 +43,12 @@ install:     $(TARG_INSTALL)
 uninstall:
                for f in $(TARGETS); do rm -f $(bin_dir)/$$f; done
 
+adnshost:      $(ADH_OBJS) $(srcdir)/../dynamic/$(SHLIBFILE)
+               $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS)
+
+adnshost_s:    $(ADH_OBJS) $(srcdir)/../src/libadns.a
+               $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS)
+
 %:             %.o $(srcdir)/../dynamic/$(SHLIBFILE)
                $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS)
 
diff --git a/client/adh-main.c b/client/adh-main.c
new file mode 100644 (file)
index 0000000..380c183
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * adh-main.c
+ * - useful general-purpose resolver client program
+ *   main program and useful subroutines
+ */
+/*
+ *  This file is
+ *    Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+ *
+ *  It is part of adns, which is
+ *    Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+ *    Copyright (C) 1999 Tony Finch <dot@dotat.at>
+ *  
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software Foundation,
+ *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+void sysfail(const char *what, int errnoval) {
+  fprintf(stderr,"adnshost failed: %s: %s\n",what,strerror(errnoval));
+  exit(10);
+}
+
+static void domain_do_arg(const char *domain) {
+  if (ov_pipe) usageerr("-f/--pipe not consistent with domains on command line");
+  domain_do(arg);
+}
+
+static void of_type(const struct optinfo *oi, const char *arg) { abort(); }
+
+int main(int argc, const char *const *argv) {
+  const char *arg;
+  const 
+  
+  while (arg= *++argv) {
+    if (arg[0] != '-') {
+      if (arg[1] == '-') {
+       oip= opt_findl(arg+2);
+       if (oip->type == ot_funcarg) {
+         arg= *++argv;
+         if (!arg) usageerr("option --%s requires a value argument",oip->lopt);
+       } else {
+         arg= 0;
+       }
+       opt_do(oip,arg);
+      } else if (arg[1] == 0) {
+       arg= *++argv;
+       if (!arg) usageerr("option `-' must be followed by a domain");
+       domain_do_arg(arg);
+      } else { /* arg[1] != '-', != '\0' */
+       ++arg;
+       while (*arg) {
+         oip= opt_finds(&arg);
+         if (oip->type == ot_funcarg) {
+           if (!*arg) {
+             arg= *++argv;
+             if (!arg) usageerr("option -%s requires a value argument",oip->sopt);
+           }
+           arg= "";
+         } else {
+           arg= 0;
+         }
+         opt_do(oip,arg);
+       }
+      }
+    } else { /* arg[0] != '-' */
+      domain_do_arg(arg);
+    }
+  }
+
+  if (ov_pipe) {
+    
+      if (ov_pipe) usageerr("-f/--pipe not 
+         
+       if (oip && ads) usageerr("global option %s must precede all query domains",arg);
+       if (!oip) oip= opt_findl(arg+2,perquery_options);
+       if (!oip) usageerr("unknown option %s",arg);
+       }
+
+       if (!oip && 
+       if (!oip) {
+  }
+  while (argv[1] && argv[1][0] == '-') {
+    if (argv[1][1] == '-') {
+      oip= findlong(
+  }
+  of_help(0,0);
+  abort();
+}
similarity index 82%
rename from client/adnshost.c
rename to client/adh-opts.c
index b35af291934108b02b1df630a6570d8c4f2202d9..7c2c42bfc2572bdf117eef03a738fcce2a7374a6 100644 (file)
@@ -1,6 +1,7 @@
 /*
- * adnshost.c
+ * adh-opts.c
  * - useful general-purpose resolver client program
+ *   option handling tables etc.
  */
 /*
  *  This file is
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-#include "config.h"
-#include "adns.h"
-
-static void sysfail(const char *what, int errnoval) NONRETURNING;
-static void sysfail(const char *what, int errnoval) {
-  fprintf(stderr,"adnshost failed: %s: %s\n",what,strerror(errnoval));
-  exit(10);
-}
-
-struct optinfo;
-typedef void optfunc(const struct optinfo *oi, const char *arg);
-
-struct optinfo {
-  enum oi_type {
-    ot_end, ot_desconly,
-    ot_flag, ot_value, ot_func, ot_funcarg
-  } type;
-  const char *desc;
-  const char *sopt, *lopt;
-  int *storep, value;
-  optfunc *func;
-  const char *argdesc;
-};
-
-static int ov_env=1, ov_pipe=0, ov_asynch=0;
-static int ov_verbose= 0;
-static int ov_search=0, ov_qc_query=0, ov_qc_anshost=0, ov_qc_cname=1;
-static int ov_tcp=0, ov_show_owner=1, ov_show_type=1, ov_show_cname=1;
-static int ov_cname=0;
-enum ttlmode { tm_none, tm_rel, tm_abs };
-static int ov_ttl= tm_none;
-
-static optfunc of_help, of_type, of_asynch_id, of_cancel_id;
+int ov_env=1, ov_pipe=0, ov_asynch=0;
+int ov_verbose= 0;
+int ov_search=0, ov_qc_query=0, ov_qc_anshost=0, ov_qc_cname=1;
+struct perqueryflags_remember ov_pqfr = { 1,1,1, tm_none };
+int ov_tcp=0, ov_cname=0;
 
 static const struct optinfo global_options[]= {
   { ot_desconly, "global binary options:" },
@@ -104,19 +73,19 @@ static const struct optinfo perquery_options[]= {
   { ot_flag,             "Force use of a virtual circuit",
     "u", "tcp",            &ov_tcp, 1 },
   { ot_flag,             "Do not display owner name in output",
-    "Do", "show-owner",   &ov_show_owner, 0 },
+    "Do", "show-owner",   &ov_pqfr.show_owner, 0 },
   { ot_flag,             "Do not display RR type in output",
-    "Dt", "show-type",    &ov_show_type, 0 },
+    "Dt", "show-type",    &ov_pqfr.show_type, 0 },
   { ot_flag,             "Do not display CNAME target in output",
-    "Dc", "show-cname",    &ov_show_cname, 0 },
+    "Dc", "show-cname",    &ov_pqfr.show_cname, 0 },
   
   { ot_desconly, "per-query TTL mode (NB TTL is minimum across all info in reply):" },
   { ot_value,            "Show the TTL as a TTL",
-    "Tt", "ttl-ttl",       &ov_ttl, tm_rel },
+    "Tt", "ttl-ttl",       &ov_pqfr.ttl, tm_rel },
   { ot_value,            "Show the TTL as a time_t when the data might expire",
-    "Ta", "ttl-abs",       &ov_ttl, tm_abs },
+    "Ta", "ttl-abs",       &ov_pqfr.ttl, tm_abs },
   { ot_value,            "Do not show the TTL (default)",
-    "Tn", "no-ttl",        &ov_ttl, tm_none },
+    "Tn", "no-ttl",        &ov_pqfr.ttl, tm_none },
   
   { ot_desconly, "per-query CNAME handling mode:" },
   { ot_value,            "Call it an error if a CNAME is found",
@@ -126,11 +95,7 @@ static const struct optinfo perquery_options[]= {
   { ot_value,            "CNAME ok for query domain, but not in RRs (default)",
     "Cs", "cname-ok",      &ov_cname, 0 },
   
-  { ot_end }
-};
-
-static const struct optinfo asynch_options[]= {
-  { ot_desconly, "asynchronous mode `options':" },
+  { ot_desconly, "asynchronous/pipe mode options:" },
   { ot_funcarg,          "Set <id>, default is decimal sequence starting 0",
     "i", "asynch-id",      0,0, &of_asynch_id, "id" },
   { ot_funcarg,          "Cancel the query with id <id>",
@@ -140,8 +105,8 @@ static const struct optinfo asynch_options[]= {
 };
 
 static void printusage(void) {
-  static const struct optinfo *const alloptions[]= {
-    global_options, perquery_options, asynch_options, 0
+  static const struct optinfo *const all_optiontables[]= {
+    global_options, perquery_options, 0
   };
 
   const struct optinfo *const *oiap, *oip=0;
@@ -279,11 +244,3 @@ static void of_help(const struct optinfo *oi, const char *arg) {
   exit(0);
 }
 
-static void of_type(const struct optinfo *oi, const char *arg) { abort(); }
-static void of_asynch_id(const struct optinfo *oi, const char *arg) { abort(); }
-static void of_cancel_id(const struct optinfo *oi, const char *arg) { abort(); }
-
-int main(int argc, const char *const *argv) {
-  of_help(0,0);
-  abort();
-}
diff --git a/client/adh-query.c b/client/adh-query.c
new file mode 100644 (file)
index 0000000..fa85779
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * adh-query.c
+ * - useful general-purpose resolver client program
+ *   make queries and print answers
+ */
+/*
+ *  This file is
+ *    Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+ *
+ *  It is part of adns, which is
+ *    Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+ *    Copyright (C) 1999 Tony Finch <dot@dotat.at>
+ *  
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software Foundation,
+ *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+ */
+
+struct query_node {
+  struct query_node *next, *back;
+  struct perqueryflags_remember pqfr;
+  char *id;
+  adns_query qu;
+};
+
+static adns_state ads;
+static struct { struct query_node *head, *tail; } outstanding;
+
+static unsigned long idcounter;
+
+static void domain_do(const char *domain) {
+  struct query_node *qun;
+  char idbuf[20];
+
+  if (!ads) {
+    if (signal(SIGPIPE,SIG_IGN) == SIG_ERR) sysfail("ignore SIGPIPE");
+    r= adns_init(&ads,
+                adns_if_noautosys|adns_if_nosigpipe |
+                (ov_env ? 0 : adns_ifnoenv) |
+                ov_verbose,
+                0);
+    if (r) sysfail("adns_init",r);
+  }
+
+  qun= malloc(sizeof(*qun));
+  qun->pqfr= ov_pqfr;
+  if (ov_id) {
+    qun->id= xstrsave(ov_id);
+  } else {
+    sprintf(idbuf,"%lu",idcounter++);
+    idcounter &= 0x0fffffffflu;
+    qun->id= xstrsave(idbuf);
+  }
+  
+  r= adns_submit(ads, domain, type,
+                (ov_search ? adns_qf_search : 0) |
+                (ov_tcp ? adns_qf_usevc : 0) |
+                (ov_pqfr.show_owner ? adns_qf_owner : 0) |
+                (ov_qc_query ? adns_qf_quoteok_query : 0) |
+                (ov_qc_anshost ? adns_qf_quoteok_anshost : 0) |
+                (ov_qc_cname ? 0 : adns_qf_quoteok_cname) |
+                ov_cname,
+                qun,
+                &qun->qu);
+  if (r) sysfail("adns_submit",r);
+
+  DLIST_LINK_TAIL(outstanding,qun);
+}
diff --git a/client/adnshost.h b/client/adnshost.h
new file mode 100644 (file)
index 0000000..46762f3
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * adnshost.h
+ * - useful general-purpose resolver client program, header file
+ */
+/*
+ *  This file is
+ *    Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+ *
+ *  It is part of adns, which is
+ *    Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+ *    Copyright (C) 1999 Tony Finch <dot@dotat.at>
+ *  
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software Foundation,
+ *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+ */
+
+#ifndef ADNSHOST_H_INCLUDED
+#define ADNSHOST_H_INCLUDED
+
+#include "config.h"
+#include "adns.h"
+
+/* declarations related to option processing */
+
+struct optinfo;
+typedef void optfunc(const struct optinfo *oi, const char *arg);
+
+struct optinfo {
+  enum oi_type {
+    ot_end, ot_desconly,
+    ot_flag, ot_value, ot_func, ot_funcarg
+  } type;
+  const char *desc;
+  const char *sopt, *lopt;
+  int *storep, value;
+  optfunc *func;
+  const char *argdesc;
+};
+
+enum ttlmode { tm_none, tm_rel, tm_abs };
+
+struct perqueryflags_remember {
+  int show_owner, show_type, show_cname;
+  int ttl;
+};
+
+extern int ov_env, ov_pipe, ov_asynch;
+extern int ov_verbose;
+extern int ov_search, ov_qc_query, ov_qc_anshost, ov_qc_cname;
+extern int ov_tcp, ov_cname;
+extern char *ov_id;
+extern struct perqueryflags_remember ov_pqfr;
+
+extern optfunc of_help, of_type, of_asynch_id, of_cancel_id;
+
+/* declarations related to query processing */
+
+static void of_asynch_id(const struct optinfo *oi, const char *arg) { abort(); }
+static void of_cancel_id(const struct optinfo *oi, const char *arg) { abort(); }
+
+/* declarations related to main program and useful utility functions */
+
+void sysfail(const char *what, int errnoval) NONRETURNING;
+
+#endif