]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
resolv: Move fp_nquery, fp_query, p_query, _res_opcodes
authorFlorian Weimer <fweimer@redhat.com>
Fri, 30 Jun 2017 09:31:35 +0000 (11:31 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Fri, 30 Jun 2017 09:31:35 +0000 (11:31 +0200)
From res_data.c to res_debug.c.

Also drop the unnecessary _res initialization from fp_nquery.

ChangeLog
include/resolv.h
resolv/res_data.c
resolv/res_debug.c

index de97c6571e76d361772aeecabe1cfe8918ac5c12..a3969176ec0d853fafa5d4f7f56c6a1809645c9f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2017-06-30  Florian Weimer  <fweimer@redhat.com>
+
+       * include/resolv.h (res_pquery): Remove declaration.
+       * resolv/res_data.c (fp_nquery, fp_query, p_query): Remove
+       functions.
+       (_res_opcodes): Remove variable.
+       * resolv/res_debug.c (do_section): Receive pfcode instead of
+       statp.
+       (res_pquery): Rename ...
+       (fp_nquery): to this function.  Skip unnecessary _res
+       initialization.
+       (fp_query, p_query, _res_opcodes): Copied from resolv/res_data.c.
+
 2017-06-30  Florian Weimer  <fweimer@redhat.com>
 
        * resolv/res_debug.h: Remove file.
index 37e4047ac40c6ae1b388bde7e541bc13eb990296..4d5b51e873ad62a177ba6e99e6f3abdb111fa825 100644 (file)
@@ -32,8 +32,6 @@ extern struct hostent *_gethtbyname2 (const char *__name, int __af);
 struct hostent *_gethtbyaddr (const char *addr, size_t __len, int __af);
 extern uint32_t _getlong (const unsigned char *__src);
 extern uint16_t _getshort (const unsigned char *__src);
-extern void res_pquery (const res_state __statp, const unsigned char *__msg,
-                       int __len, FILE *__file);
 extern int res_ourserver_p (const res_state __statp,
                            const struct sockaddr_in6 *__inp);
 extern void __res_iclose (res_state statp, bool free_addr);
index d907bfc9bd8a55fd5ccc1da29d28ccaa91f5b8e9..d05389e1347a57abda15acff63a22dd4ac9af80b 100644 (file)
 #include <string.h>
 #include <unistd.h>
 
-const char *_res_opcodes[] = {
-       "QUERY",
-       "IQUERY",
-       "CQUERYM",
-       "CQUERYU",      /* experimental */
-       "NOTIFY",       /* experimental */
-       "UPDATE",
-       "6",
-       "7",
-       "8",
-       "9",
-       "10",
-       "11",
-       "12",
-       "13",
-       "ZONEINIT",
-       "ZONEREF",
-};
-libresolv_hidden_data_def (_res_opcodes)
-
-void
-p_query(const u_char *msg) {
-       fp_query(msg, stdout);
-}
-
-void
-fp_query(const u_char *msg, FILE *file) {
-       fp_nquery(msg, PACKETSZ, file);
-}
-libresolv_hidden_def (fp_query)
-
-void
-fp_nquery(const u_char *msg, int len, FILE *file) {
-       if (__res_maybe_init (&_res, 0) == -1)
-               return;
-
-       res_pquery(&_res, msg, len, file);
-}
-libresolv_hidden_def (fp_nquery)
-
 int
 res_query(const char *name,    /* domain name */
          int class, int type,  /* class and type of query */
index e23559bad3d92e71d00e87430c1cb5e73b3066bf..182aeefa1f8683f481a0fce36717281fb2b69211 100644 (file)
 
 extern const char *_res_sectioncodes[] attribute_hidden;
 
+const char *_res_opcodes[] =
+  {
+    "QUERY",
+    "IQUERY",
+    "CQUERYM",
+    "CQUERYU", /* experimental */
+    "NOTIFY",  /* experimental */
+    "UPDATE",
+    "6",
+    "7",
+    "8",
+    "9",
+    "10",
+    "11",
+    "12",
+    "13",
+    "ZONEINIT",
+    "ZONEREF",
+  };
+libresolv_hidden_data_def (_res_opcodes)
+
 static const char *p_section(int section, int opcode);
 
 /*
@@ -132,9 +153,7 @@ fp_resstat(const res_state statp, FILE *file) {
 }
 
 static void
-do_section(const res_state statp,
-          ns_msg *handle, ns_sect section,
-          int pflag, FILE *file)
+do_section (int pfcode, ns_msg *handle, ns_sect section, int pflag, FILE *file)
 {
        int n, sflag, rrnum;
        static int buflen = 2048;
@@ -145,8 +164,8 @@ do_section(const res_state statp,
        /*
         * Print answer records.
         */
-       sflag = (statp->pfcode & pflag);
-       if (statp->pfcode && !sflag)
+       sflag = (pfcode & pflag);
+       if (pfcode && !sflag)
                return;
 
        buf = malloc(buflen);
@@ -163,11 +182,11 @@ do_section(const res_state statp,
                                fprintf(file, ";; ns_parserr: %s\n",
                                        strerror(errno));
                        else if (rrnum > 0 && sflag != 0 &&
-                                (statp->pfcode & RES_PRF_HEAD1))
+                                (pfcode & RES_PRF_HEAD1))
                                putc('\n', file);
                        goto cleanup;
                }
-               if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1))
+               if (rrnum == 0 && sflag != 0 && (pfcode & RES_PRF_HEAD1))
                        fprintf(file, ";; %s SECTION:\n",
                                p_section(section, opcode));
                if (section == ns_s_qd)
@@ -209,11 +228,19 @@ do_section(const res_state statp,
  * This is intended to be primarily a debugging routine.
  */
 void
-res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
+fp_nquery (const unsigned char *msg, int len, FILE *file)
+{
        ns_msg handle;
        int qdcount, ancount, nscount, arcount;
        u_int opcode, rcode, id;
 
+       /* There is no need to initialize _res: If _res is not yet
+          initialized, _res.pfcode is zero.  But initialization will
+          leave it at zero, too.  _res.pfcode is an unsigned long,
+          but the code here assumes that the flags fit into an int,
+          so use that.  */
+       int pfcode = _res.pfcode;
+
        if (ns_initparse(msg, len, &handle) < 0) {
                fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
                return;
@@ -229,13 +256,13 @@ res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
        /*
         * Print header fields.
         */
-       if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX) || rcode)
+       if ((!pfcode) || (pfcode & RES_PRF_HEADX) || rcode)
                fprintf(file,
                        ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
                        _res_opcodes[opcode], p_rcode(rcode), id);
-       if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX))
+       if ((!pfcode) || (pfcode & RES_PRF_HEADX))
                putc(';', file);
-       if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD2)) {
+       if ((!pfcode) || (pfcode & RES_PRF_HEAD2)) {
                fprintf(file, "; flags:");
                if (ns_msg_getflag(handle, ns_f_qr))
                        fprintf(file, " qr");
@@ -254,7 +281,7 @@ res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
                if (ns_msg_getflag(handle, ns_f_cd))
                        fprintf(file, " cd");
        }
-       if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD1)) {
+       if ((!pfcode) || (pfcode & RES_PRF_HEAD1)) {
                fprintf(file, "; %s: %d",
                        p_section(ns_s_qd, opcode), qdcount);
                fprintf(file, ", %s: %d",
@@ -264,21 +291,35 @@ res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
                fprintf(file, ", %s: %d",
                        p_section(ns_s_ar, opcode), arcount);
        }
-       if ((!statp->pfcode) || (statp->pfcode &
+       if ((!pfcode) || (pfcode &
                (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
                putc('\n',file);
        }
        /*
         * Print the various sections.
         */
-       do_section(statp, &handle, ns_s_qd, RES_PRF_QUES, file);
-       do_section(statp, &handle, ns_s_an, RES_PRF_ANS, file);
-       do_section(statp, &handle, ns_s_ns, RES_PRF_AUTH, file);
-       do_section(statp, &handle, ns_s_ar, RES_PRF_ADD, file);
+       do_section (pfcode, &handle, ns_s_qd, RES_PRF_QUES, file);
+       do_section (pfcode, &handle, ns_s_an, RES_PRF_ANS, file);
+       do_section (pfcode, &handle, ns_s_ns, RES_PRF_AUTH, file);
+       do_section (pfcode, &handle, ns_s_ar, RES_PRF_ADD, file);
        if (qdcount == 0 && ancount == 0 &&
            nscount == 0 && arcount == 0)
                putc('\n', file);
 }
+libresolv_hidden_def (fp_nquery)
+
+void
+fp_query (const unsigned char *msg, FILE *file)
+{
+  fp_nquery (msg, PACKETSZ, file);
+}
+libresolv_hidden_def (fp_query)
+
+void
+p_query (const unsigned char *msg)
+{
+  fp_query (msg, stdout);
+}
 
 const u_char *
 p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {