This one's been waiting for feedback from me.  Please assume that
I'm not going to do it; it's dropped off my todo list.

Thoughts about it (I haven't talked to upstream about it).

  lwres is intended to have both client and server run on the
  same machine, so implementing an lwres client is only useful on
  machines that have the server (and thus the common library)
  installed.

  c-ares aims to be cross-platform, but already has plenty of
  platform-specific code in #ifdef blocks, adding code specific
  to lwres should be possible.  (I haven't talked to upstream
  yet).

  lwres provides an encoding/decoding API for the lwres
  client/server protocol.  Given the previous two paragraphs,
  using the existing encoding library seems a better idea than
  embedding new code in to c-ares.

  I haven't found a spec for the lwres wire protocol beyond the
  common library's encoding/decoding API, and think the wire
  protocol may be subject to change without notice.

Attached are a couple of patches that may be useful for anyone
else taking up the task.  They're for the /etc/nsswitch.conf
handling code - the first prepares for adding a new config
option (and should help anyone adding mdns too).  The second
(which depends on the first) adds lwres.  

The patches are aimed at upstream's CVS version, as of 20080630.

Steve
Mon Jun 30 17:28:45 BST 2008  Steve Cotton <[EMAIL PROTECTED]>
  * Prepare config_lookup for additional options
diff -rN -u old-cares/curl/ares/ares_init.c new-cares/curl/ares/ares_init.c
--- old-cares/curl/ares/ares_init.c	2008-07-14 15:09:04.000000000 +0100
+++ new-cares/curl/ares/ares_init.c	2008-07-14 15:09:04.000000000 +0100
@@ -1040,30 +1040,57 @@
   return set_search(channel, str);
 }
 
+/* The number of lookup methods supported - currently bind and files. */
+#define ARES_METHODS_MAXNUM 2
+
 static int config_lookup(ares_channel channel, const char *str,
                          const char *bindch, const char *filech)
 {
-  char lookups[3], *l;
+  char lookups[ARES_METHODS_MAXNUM+1];
   const char *p;
+  int i;
 
-  /* Set the lookup order.  Only the first letter of each work
-   * is relevant, and it has to be "b" for DNS or "f" for the
-   * host file.  Ignore everything else.
+  /* Set the lookup order.
+   *
+   * The "str" argument is a line from a config file.
+   *
+   * Different config files have different keywords for the bind
+   * and files methods.  The caller supplies right keywords in
+   * the bindch and later arguments.  If this type of config file
+   * doesn't have a keyword for one of the options, use the empty
+   * string.
+   *
+   * Only the first letter of each keyword is used at the moment,
+   * the rest is ignored.
+   *
+   * On return, channel->lookups contains a single character for
+   * each search method to use, in order.
+   *   "b" for DNS
+   *   "f" for the host file
    */
-  l = lookups;
+  i = 0;
   p = str;
-  while (*p)
+  while ((*p) && (i < ARES_METHODS_MAXNUM))
     {
-      if ((*p == *bindch || *p == *filech) && l < lookups + 2) {
-        if (*p == *bindch) *l++ = 'b';
-        else *l++ = 'f';
-      }
+      char method = '\0';
+
+      /* Match the first letter of the method keyword */
+      if (*p == *bindch)
+        method = 'b';
+      else if (*p == *filech)
+        method = 'f';
+
+      /* Store the lookup method */
+      if (method != '\0')
+        lookups[i++] = method;
+
+      /* Move on to the next word */
       while (*p && !ISSPACE(*p) && (*p != ','))
         p++;
       while (*p && (ISSPACE(*p) || (*p == ',')))
         p++;
     }
-  *l = '\0';
+  lookups[i] = '\0';
   channel->lookups = strdup(lookups);
   return (channel->lookups) ? ARES_SUCCESS : ARES_ENOMEM;
 }

Wed Jul  2 01:58:12 BST 2008  Steve Cotton <[EMAIL PROTECTED]>
  * Add lwres to config_lookup
  This only affects parsing of config files, adding the 'l' option.
  It doesn't add any handling for the 'l' option, so it will be
  silently ignored by the implementation of ares_gethostbyname.
diff -rN -u old-cares/curl/ares/ares_init.c new-cares/curl/ares/ares_init.c
--- old-cares/curl/ares/ares_init.c	2008-07-14 15:09:32.000000000 +0100
+++ new-cares/curl/ares/ares_init.c	2008-07-14 15:09:32.000000000 +0100
@@ -84,7 +84,8 @@
 static void natural_mask(struct apattern *pat);
 static int config_domain(ares_channel channel, char *str);
 static int config_lookup(ares_channel channel, const char *str,
-                         const char *bindch, const char *filech);
+                         const char *bindch, const char *filech,
+                         const char *lwresch);
 static int config_sortlist(struct apattern **sortlist, int *nsort,
                            const char *str);
 static char *try_config(char *s, const char *opt);
@@ -762,7 +763,7 @@
         if ((p = try_config(line, "domain")) && channel->ndomains == -1)
           status = config_domain(channel, p);
         else if ((p = try_config(line, "lookup")) && !channel->lookups)
-          status = config_lookup(channel, p, "bind", "file");
+          status = config_lookup(channel, p, "bind", "file", "");
         else if ((p = try_config(line, "search")) && channel->ndomains == -1)
           status = set_search(channel, p);
         else if ((p = try_config(line, "nameserver")) && channel->nservers == -1)
@@ -800,7 +801,7 @@
         while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
         {
           if ((p = try_config(line, "hosts:")) && !channel->lookups)
-            status = config_lookup(channel, p, "dns", "files");
+            status = config_lookup(channel, p, "dns", "files", "lwres");
         }
         fclose(fp);
       }
@@ -827,7 +828,7 @@
         while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
         {
           if ((p = try_config(line, "order")) && !channel->lookups)
-            status = config_lookup(channel, p, "bind", "hosts");
+            status = config_lookup(channel, p, "bind", "hosts", "");
         }
         fclose(fp);
       }
@@ -854,7 +855,7 @@
         while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
         {
           if ((p = try_config(line, "hosts=")) && !channel->lookups)
-            status = config_lookup(channel, p, "bind", "local");
+            status = config_lookup(channel, p, "bind", "local", "");
         }
         fclose(fp);
       }
@@ -1040,11 +1041,12 @@
   return set_search(channel, str);
 }
 
-/* The number of lookup methods supported - currently bind and files. */
-#define ARES_METHODS_MAXNUM 2
+/* The number of lookup methods supported - currently bind, files and lwres. */
+#define ARES_METHODS_MAXNUM 3
 
 static int config_lookup(ares_channel channel, const char *str,
-                         const char *bindch, const char *filech)
+                         const char *bindch, const char *filech,
+                         const char *lwresch)
 {
   char lookups[ARES_METHODS_MAXNUM+1];
   const char *p;
@@ -1067,6 +1069,7 @@
    * each search method to use, in order.
    *   "b" for DNS
    *   "f" for the host file
+   *   "l" for lwres
    */
   i = 0;
   p = str;
@@ -1079,6 +1082,8 @@
         method = 'b';
       else if (*p == *filech)
         method = 'f';
+      else if (*p == *lwresch)
+        method = 'l';
 
       /* Store the lookup method */
       if (method != '\0')

Reply via email to