chiark / gitweb /
adnshost compiles again, and submits.
authorian <ian>
Sun, 10 Oct 1999 17:01:30 +0000 (17:01 +0000)
committerian <ian>
Sun, 10 Oct 1999 17:01:30 +0000 (17:01 +0000)
client/Makefile.in
client/adh-main.c
client/adh-opts.c
client/adh-query.c
client/adnshost.h

index 0ed57ac8a22119fef777ecb86b2d3d10447b1282..d55057e1513a234d4f3c8224a5070cf63a2735cd 100644 (file)
@@ -43,6 +43,8 @@ install:      $(TARG_INSTALL)
 uninstall:
                for f in $(TARGETS); do rm -f $(bin_dir)/$$f; done
 
 uninstall:
                for f in $(TARGETS); do rm -f $(bin_dir)/$$f; done
 
+$(ADH_OBJS):   adnshost.h
+
 adnshost:      $(ADH_OBJS) $(srcdir)/../dynamic/$(SHLIBFILE)
                $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS)
 
 adnshost:      $(ADH_OBJS) $(srcdir)/../dynamic/$(SHLIBFILE)
                $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS)
 
index 5a4235dbf9163926d62c8e8b46b132b766565f03..7c43d1e6dce70798cdf98a474815bdd50997950e 100644 (file)
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
+#include "adnshost.h"
 
 void sysfail(const char *what, int errnoval) {
   fprintf(stderr,"adnshost failed: %s: %s\n",what,strerror(errnoval));
   exit(10);
 }
 
 
 void sysfail(const char *what, int errnoval) {
   fprintf(stderr,"adnshost failed: %s: %s\n",what,strerror(errnoval));
   exit(10);
 }
 
+void usageerr(const char *fmt, ...) {
+  va_list al;
+  fputs("adnshost usage error: ",stderr);
+  va_start(al,fmt);
+  vfprintf(stderr,fmt,al);
+  va_end(al);
+  putc('\n',stderr);
+  exit(11);
+}
+
 static void domain_do_arg(const char *domain) {
   if (ov_pipe) usageerr("-f/--pipe not consistent with domains on command line");
 static void domain_do_arg(const char *domain) {
   if (ov_pipe) usageerr("-f/--pipe not consistent with domains on command line");
-  domain_do(arg);
+  domain_do(domain);
+}
+
+void *xmalloc(size_t sz) {
+  void *p;
+
+  p= malloc(sz); if (!p) sysfail("malloc",sz);
+  return p;
+}
+
+char *xstrsave(const char *str) {
+  char *p;
+  
+  p= xmalloc(strlen(str)+1);
+  strcpy(p,str);
+  return p;
 }
 
 }
 
-static void of_type(const struct optinfo *oi, const char *arg) { abort(); }
+void of_type(const struct optioninfo *oi, const char *arg) { abort(); }
 
 int main(int argc, const char *const *argv) {
   const char *arg;
 
 int main(int argc, const char *const *argv) {
   const char *arg;
-  const 
+  const struct optioninfo *oip;
   
   
-  while (arg= *++argv) {
-    if (arg[0] != '-') {
+  while ((arg= *++argv)) {
+    if (arg[0] == '-') {
       if (arg[1] == '-') {
        oip= opt_findl(arg+2);
        if (oip->type == ot_funcarg) {
       if (arg[1] == '-') {
        oip= opt_findl(arg+2);
        if (oip->type == ot_funcarg) {
index 7c2c42bfc2572bdf117eef03a738fcce2a7374a6..bc32ba9bb527c1c3ead985d9e3d30b72b2ae5f0f 100644 (file)
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
+#include "adnshost.h"
+
 int ov_env=1, ov_pipe=0, ov_asynch=0;
 int ov_verbose= 0;
 int ov_env=1, ov_pipe=0, ov_asynch=0;
 int ov_verbose= 0;
+adns_rrtype ov_type= adns_r_none;
 int ov_search=0, ov_qc_query=0, ov_qc_anshost=0, ov_qc_cname=1;
 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;
 int ov_tcp=0, ov_cname=0;
+char *ov_id= 0;
+struct perqueryflags_remember ov_pqfr = { 1,1,1, tm_none };
 
 
-static const struct optinfo global_options[]= {
+static const struct optioninfo global_options[]= {
   { ot_desconly, "global binary options:" },
   { ot_flag,             "Do not look at environment variables at all",
     "e", "env",            &ov_env, 0 },
   { ot_desconly, "global binary options:" },
   { ot_flag,             "Do not look at environment variables at all",
     "e", "env",            &ov_env, 0 },
@@ -56,7 +60,7 @@ static const struct optinfo global_options[]= {
   { ot_end }
 };
 
   { ot_end }
 };
 
-static const struct optinfo perquery_options[]= {
+static const struct optioninfo perquery_options[]= {
   { ot_desconly, "per-query options:" },
   { ot_funcarg,          "Query type (see below)",
     "t", "type",           0,0, &of_type, "type" },
   { ot_desconly, "per-query options:" },
   { ot_funcarg,          "Query type (see below)",
     "t", "type",           0,0, &of_type, "type" },
@@ -105,16 +109,16 @@ static const struct optinfo perquery_options[]= {
 };
 
 static void printusage(void) {
 };
 
 static void printusage(void) {
-  static const struct optinfo *const all_optiontables[]= {
+  static const struct optioninfo *const all_optiontables[]= {
     global_options, perquery_options, 0
   };
 
     global_options, perquery_options, 0
   };
 
-  const struct optinfo *const *oiap, *oip=0;
+  const struct optioninfo *const *oiap, *oip=0;
   int maxsopt, maxlopt, l;
 
   maxsopt= maxlopt= 0;
   
   int maxsopt, maxlopt, l;
 
   maxsopt= maxlopt= 0;
   
-  for (oiap=alloptions; *oiap; oiap++) {
+  for (oiap=all_optiontables; *oiap; oiap++) {
     for (oip=*oiap; oip->type != ot_end; oip++) {
       if (oip->type == ot_funcarg) continue;
       if (oip->sopt) { l= strlen(oip->sopt); if (l>maxsopt) maxsopt= l; }
     for (oip=*oiap; oip->type != ot_end; oip++) {
       if (oip->type == ot_funcarg) continue;
       if (oip->sopt) { l= strlen(oip->sopt); if (l>maxsopt) maxsopt= l; }
@@ -131,7 +135,7 @@ static void printusage(void) {
        "       adnshost [global-opts] [query-opts] -f|--pipe\n",
        stdout);
 
        "       adnshost [global-opts] [query-opts] -f|--pipe\n",
        stdout);
 
-  for (oiap=alloptions; *oiap; oiap++) {
+  for (oiap=all_optiontables; *oiap; oiap++) {
     putchar('\n');
     for (oip=*oiap; oip->type != ot_end; oip++) {
       switch (oip->type) {
     putchar('\n');
     for (oip=*oiap; oip->type != ot_end; oip++) {
       switch (oip->type) {
@@ -238,9 +242,66 @@ static void printusage(void) {
   if (ferror(stdout)) sysfail("write usage message",errno);
 }
 
   if (ferror(stdout)) sysfail("write usage message",errno);
 }
 
-static void of_help(const struct optinfo *oi, const char *arg) {
+void of_help(const struct optioninfo *oi, const char *arg) {
   printusage();
   if (fclose(stdout)) sysfail("finish writing output",errno);
   exit(0);
 }
 
   printusage();
   if (fclose(stdout)) sysfail("finish writing output",errno);
   exit(0);
 }
 
+typedef int comparer_type(const char **optp, const struct optioninfo *entry);
+
+static int oc_long(const char **optp, const struct optioninfo *entry) {
+  return entry->lopt && !strcmp(*optp,entry->lopt);
+}
+
+static int oc_short(const char **optp, const struct optioninfo *entry) {
+  const char *sopt;
+  int l;
+
+  sopt= entry->sopt;
+  if (!sopt) return 0;
+  l= strlen(sopt);
+  if (memcmp(*optp,sopt,l)) return 0;
+  (*optp) += l;
+  return 1;
+}
+
+static const struct optioninfo *find1(const char **optp,
+                                     const struct optioninfo *table,
+                                     comparer_type *comparer) {
+  for (;;) {
+    if (table->type == ot_end) return 0;
+    if (comparer(optp,table)) return table;
+    table++;
+  }
+}
+
+static const struct optioninfo *find(const char **optp,
+                                    const char *prefix,
+                                    comparer_type *comparer) {
+  const struct optioninfo *oip;
+
+  oip= find1(optp,perquery_options,comparer);
+  if (oip) return oip;
+  oip= find1(optp,global_options,comparer);
+  if (!oip) usageerr("unknown option %s%s",prefix,*optp);
+  if (ads) usageerr("global option %s%s specified after query domain(s)",prefix,*optp);
+  return oip;
+}
+
+const struct optioninfo *opt_findl(const char *opt) { return find(&opt,"--",oc_long); }
+const struct optioninfo *opt_finds(const char **optp) { return find(optp,"-",oc_short); }
+
+void opt_do(const struct optioninfo *oip, const char *arg) {
+  switch (oip->type) {
+  case ot_flag: case ot_value:
+    assert(!arg);
+    *oip->storep= oip->value;
+    return;
+  case ot_func: case ot_funcarg:
+    oip->func(oip,0);
+    return;
+  default:
+    abort();
+  }
+}
index fa8577977f7aacb5bf138daf64adb4a56f8ba768..5c023a686a740b22a55593f1b6e816196604f1c4 100644 (file)
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
+#include "adnshost.h"
+
+adns_state ads;
+
 struct query_node {
   struct query_node *next, *back;
   struct perqueryflags_remember pqfr;
 struct query_node {
   struct query_node *next, *back;
   struct perqueryflags_remember pqfr;
@@ -33,20 +37,20 @@ struct query_node {
   adns_query qu;
 };
 
   adns_query qu;
 };
 
-static adns_state ads;
 static struct { struct query_node *head, *tail; } outstanding;
 
 static unsigned long idcounter;
 
 static struct { struct query_node *head, *tail; } outstanding;
 
 static unsigned long idcounter;
 
-static void domain_do(const char *domain) {
+void domain_do(const char *domain) {
   struct query_node *qun;
   char idbuf[20];
   struct query_node *qun;
   char idbuf[20];
+  int r;
 
   if (!ads) {
 
   if (!ads) {
-    if (signal(SIGPIPE,SIG_IGN) == SIG_ERR) sysfail("ignore SIGPIPE");
+    if (signal(SIGPIPE,SIG_IGN) == SIG_ERR) sysfail("ignore SIGPIPE",errno);
     r= adns_init(&ads,
                 adns_if_noautosys|adns_if_nosigpipe |
     r= adns_init(&ads,
                 adns_if_noautosys|adns_if_nosigpipe |
-                (ov_env ? 0 : adns_ifnoenv) |
+                (ov_env ? 0 : adns_if_noenv) |
                 ov_verbose,
                 0);
     if (r) sysfail("adns_init",r);
                 ov_verbose,
                 0);
     if (r) sysfail("adns_init",r);
@@ -62,7 +66,8 @@ static void domain_do(const char *domain) {
     qun->id= xstrsave(idbuf);
   }
   
     qun->id= xstrsave(idbuf);
   }
   
-  r= adns_submit(ads, domain, type,
+  r= adns_submit(ads, domain,
+                ov_type == adns_r_none ? adns_r_addr : ov_type,
                 (ov_search ? adns_qf_search : 0) |
                 (ov_tcp ? adns_qf_usevc : 0) |
                 (ov_pqfr.show_owner ? adns_qf_owner : 0) |
                 (ov_search ? adns_qf_search : 0) |
                 (ov_tcp ? adns_qf_usevc : 0) |
                 (ov_pqfr.show_owner ? adns_qf_owner : 0) |
@@ -74,5 +79,8 @@ static void domain_do(const char *domain) {
                 &qun->qu);
   if (r) sysfail("adns_submit",r);
 
                 &qun->qu);
   if (r) sysfail("adns_submit",r);
 
-  DLIST_LINK_TAIL(outstanding,qun);
+  LIST_LINK_TAIL(outstanding,qun);
 }
 }
+
+void of_asynch_id(const struct optioninfo *oi, const char *arg) { abort(); }
+void of_cancel_id(const struct optioninfo *oi, const char *arg) { abort(); }
index 46762f3f0469971c40fefb868ad13b6e9a47d830..3e93ca7b90ca6b7155d4f6e485c3b1748b83fc24 100644 (file)
 #ifndef ADNSHOST_H_INCLUDED
 #define ADNSHOST_H_INCLUDED
 
 #ifndef ADNSHOST_H_INCLUDED
 #define ADNSHOST_H_INCLUDED
 
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <assert.h>
+
 #include "config.h"
 #include "adns.h"
 #include "config.h"
 #include "adns.h"
+#include "dlist.h"
 
 /* declarations related to option processing */
 
 
 /* declarations related to option processing */
 
-struct optinfo;
-typedef void optfunc(const struct optinfo *oi, const char *arg);
+struct optioninfo;
+typedef void optfunc(const struct optioninfo *oi, const char *arg);
 
 
-struct optinfo {
+struct optioninfo {
   enum oi_type {
     ot_end, ot_desconly,
     ot_flag, ot_value, ot_func, ot_funcarg
   enum oi_type {
     ot_end, ot_desconly,
     ot_flag, ot_value, ot_func, ot_funcarg
@@ -57,6 +65,7 @@ struct perqueryflags_remember {
 
 extern int ov_env, ov_pipe, ov_asynch;
 extern int ov_verbose;
 
 extern int ov_env, ov_pipe, ov_asynch;
 extern int ov_verbose;
+extern adns_rrtype ov_type;
 extern int ov_search, ov_qc_query, ov_qc_anshost, ov_qc_cname;
 extern int ov_tcp, ov_cname;
 extern char *ov_id;
 extern int ov_search, ov_qc_query, ov_qc_anshost, ov_qc_cname;
 extern int ov_tcp, ov_cname;
 extern char *ov_id;
@@ -64,13 +73,25 @@ extern struct perqueryflags_remember ov_pqfr;
 
 extern optfunc of_help, of_type, of_asynch_id, of_cancel_id;
 
 
 extern optfunc of_help, of_type, of_asynch_id, of_cancel_id;
 
+const struct optioninfo *opt_findl(const char *opt);
+const struct optioninfo *opt_finds(const char **optp);
+void opt_do(const struct optioninfo *oip, const char *arg);
+
 /* declarations related to query processing */
 
 /* 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(); }
+extern adns_state ads;
+
+void domain_do(const char *domain);
+
+void of_asynch_id(const struct optioninfo *oi, const char *arg);
+void of_cancel_id(const struct optioninfo *oi, const char *arg);
 
 /* declarations related to main program and useful utility functions */
 
 void sysfail(const char *what, int errnoval) NONRETURNING;
 
 /* declarations related to main program and useful utility functions */
 
 void sysfail(const char *what, int errnoval) NONRETURNING;
+void usageerr(const char *what, ...) NONRETURNPRINTFFORMAT(1,2);
+
+void *xmalloc(size_t sz);
+char *xstrsave(const char *str);
 
 #endif
 
 #endif