resolv: dead code removal

 - hostalias() and res_hostalias(): these were no-ops

 - res_opt(), res_querydomain(), p_option(), p_query(),
   res_isourserver(), res_nisourserver(): had no callers

 - res_ourserver_p(): made local to res_data.cpp

 - res_send_setqhook(): unused, DnsProxyListener sets the qhook directly
   in android_net_context, which is then copied to res_state by
   res_setnetcontext(). We can further simplify it later on.

Test: atest netd_integration_test
Change-Id: I70f72202e5b940986cac67dc99ab9461af882187
diff --git a/resolv/gethnamaddr.cpp b/resolv/gethnamaddr.cpp
index 3fd6324..5cdcd1d 100644
--- a/resolv/gethnamaddr.cpp
+++ b/resolv/gethnamaddr.cpp
@@ -482,7 +482,7 @@
 /* The prototype of gethostbyname_r is from glibc, not that in netbsd. */
 int gethostbyname_r(const char* name, struct hostent* hp, char* buf, size_t buflen,
                     struct hostent** result, int* errorp) {
-    res_state res = __res_get_state();
+    res_state res = res_get_state();
     if (res == NULL) {
         *result = NULL;
         *errorp = NETDB_INTERNAL;
@@ -495,7 +495,7 @@
         *result = gethostbyname_internal(name, AF_INET6, res, hp, buf, buflen, errorp,
                                          &NETCONTEXT_UNSET);
         if (*result) {
-            __res_put_state(res);
+            res_put_state(res);
             return 0;
         }
     }
@@ -507,7 +507,7 @@
 /* The prototype of gethostbyname2_r is from glibc, not that in netbsd. */
 int gethostbyname2_r(const char* name, int af, struct hostent* hp, char* buf, size_t buflen,
                      struct hostent** result, int* errorp) {
-    res_state res = __res_get_state();
+    res_state res = res_get_state();
     if (res == NULL) {
         *result = NULL;
         *errorp = NETDB_INTERNAL;
@@ -520,9 +520,7 @@
 static struct hostent* gethostbyname_internal_real(const char* name, int af, res_state res,
                                                    struct hostent* hp, char* buf, size_t buflen,
                                                    int* he) {
-    const char* cp;
     struct getnamaddr info;
-    char hbuf[MAXHOSTNAMELEN];
     size_t size;
 
     _DIAGASSERT(name != NULL);
@@ -545,18 +543,11 @@
     hp->h_length = (int) size;
 
     /*
-     * if there aren't any dots, it could be a user-level alias.
-     * this is also done in res_nquery() since we are not the only
-     * function that looks up host names.
-     */
-    if (!strchr(name, '.') && (cp = res_hostalias(res, name, hbuf, sizeof(hbuf)))) name = cp;
-
-    /*
      * disallow names consisting only of digits/dots, unless
      * they end in a dot.
      */
-    if (isdigit((u_char) name[0]))
-        for (cp = name;; ++cp) {
+    if (isdigit((u_char) name[0])) {
+        for (const char* cp = name;; ++cp) {
             if (!*cp) {
                 if (*--cp == '.') break;
                 /*
@@ -568,8 +559,9 @@
             }
             if (!isdigit((u_char) *cp) && *cp != '.') break;
         }
-    if ((isxdigit((u_char) name[0]) && strchr(name, ':') != NULL) || name[0] == ':')
-        for (cp = name;; ++cp) {
+    }
+    if ((isxdigit((u_char) name[0]) && strchr(name, ':') != NULL) || name[0] == ':') {
+        for (const char* cp = name;; ++cp) {
             if (!*cp) {
                 if (*--cp == '.') break;
                 /*
@@ -581,6 +573,7 @@
             }
             if (!isxdigit((u_char) *cp) && *cp != ':' && *cp != '.') break;
         }
+    }
 
     *he = NETDB_INTERNAL;
     info.hp = hp;
@@ -700,7 +693,7 @@
 
 struct hostent* netbsd_gethostent_r(FILE* hf, struct hostent* hent, char* buf, size_t buflen,
                                     int* he) {
-    const size_t line_buf_size = sizeof(__res_get_static()->hostbuf);
+    const size_t line_buf_size = sizeof(res_get_static()->hostbuf);
     char *name;
     char *cp, **q;
     int af, len;
@@ -718,7 +711,7 @@
     if (!aliases) goto nospc;
 
     /* Allocate a new space to read file lines like upstream does.
-     * To keep reentrancy we cannot use __res_get_static()->hostbuf here,
+     * To keep reentrancy we cannot use res_get_static()->hostbuf here,
      * as the buffer may be used to store content for a previous hostent
      * returned by non-reentrant functions like gethostbyname().
      */
@@ -747,7 +740,7 @@
         } else {
             if (inet_pton(AF_INET, p, &host_addr) <= 0) continue;
 
-            res_state res = __res_get_state();
+            res_state res = res_get_state();
             if (res == NULL) goto nospc;
             if (res->options & RES_USE_INET6) {
                 map_v4v6_address(buf, buf);
@@ -757,7 +750,7 @@
                 af = AF_INET;
                 len = NS_INADDRSZ;
             }
-            __res_put_state(res);
+            res_put_state(res);
         }
 
         /* if this is not something we're looking for, skip it. */
@@ -906,7 +899,7 @@
         *info->he = NETDB_INTERNAL;
         return false;
     }
-    res = __res_get_state();
+    res = res_get_state();
     if (res == NULL) {
         free(buf);
         return false;
@@ -915,12 +908,12 @@
     if (n < 0) {
         free(buf);
         debugprintf("res_nsearch failed (%d)\n", res, n);
-        __res_put_state(res);
+        res_put_state(res);
         return false;
     }
     hp = getanswer(buf, n, name, type, res, info->hp, info->buf, info->buflen, info->he);
     free(buf);
-    __res_put_state(res);
+    res_put_state(res);
     if (hp == NULL) {
         return false;
     }
@@ -971,7 +964,7 @@
         *info->he = NETDB_INTERNAL;
         return false;
     }
-    res = __res_get_state();
+    res = res_get_state();
     if (res == NULL) {
         free(buf);
         return false;
@@ -981,13 +974,13 @@
     if (n < 0) {
         free(buf);
         debugprintf("res_nquery failed (%d)\n", res, n);
-        __res_put_state(res);
+        res_put_state(res);
         return false;
     }
     hp = getanswer(buf, n, qbuf, T_PTR, res, info->hp, info->buf, info->buflen, info->he);
     free(buf);
     if (hp == NULL) {
-        __res_put_state(res);
+        res_put_state(res);
         return false;
     }
 
@@ -1004,7 +997,7 @@
         hp->h_length = NS_IN6ADDRSZ;
     }
 
-    __res_put_state(res);
+    res_put_state(res);
     *info->he = NETDB_SUCCESS;
     return true;
 
@@ -1020,7 +1013,7 @@
 
 struct hostent* gethostbyname(const char* name) {
     struct hostent* result = NULL;
-    struct res_static* rs = __res_get_static();  // For thread-safety.
+    struct res_static* rs = res_get_static();  // For thread-safety.
 
     gethostbyname_r(name, &rs->host, rs->hostbuf, sizeof(rs->hostbuf), &result, &h_errno);
     return result;
@@ -1028,7 +1021,7 @@
 
 struct hostent* gethostbyname2(const char* name, int af) {
     struct hostent* result = NULL;
-    struct res_static* rs = __res_get_static();  // For thread-safety.
+    struct res_static* rs = res_get_static();  // For thread-safety.
 
     gethostbyname2_r(name, af, &rs->host, rs->hostbuf, sizeof(rs->hostbuf), &result, &h_errno);
     return result;
@@ -1058,12 +1051,12 @@
 struct hostent* android_gethostbynamefornetcontext(const char* name, int af,
                                                    const struct android_net_context* netcontext) {
     struct hostent* hp;
-    res_state res = __res_get_state();
+    res_state res = res_get_state();
     if (res == NULL) return NULL;
-    struct res_static* rs = __res_get_static();  // For thread-safety.
+    struct res_static* rs = res_get_static();  // For thread-safety.
     hp = gethostbyname_internal(name, af, res, &rs->host, rs->hostbuf, sizeof(rs->hostbuf),
                                 &h_errno, netcontext);
-    __res_put_state(res);
+    res_put_state(res);
     return hp;
 }
 
@@ -1084,7 +1077,7 @@
 
 static struct hostent* android_gethostbyaddrfornetcontext_proxy(
         const void* addr, socklen_t len, int af, const struct android_net_context* netcontext) {
-    struct res_static* rs = __res_get_static();  // For thread-safety.
+    struct res_static* rs = res_get_static();  // For thread-safety.
     return android_gethostbyaddrfornetcontext_proxy_internal(
             addr, len, af, &rs->host, rs->hostbuf, sizeof(rs->hostbuf), &h_errno, netcontext);
 }