[glib: 11/13] resolver: Add SRV support to manual resolver test




commit e8e8aebcbeac5791db05d13e73fb81282adc3810
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Mar 21 17:53:25 2022 +0000

    resolver: Add SRV support to manual resolver test
    
    This allows for tests like:
    ```
    resolver -t SRV _http._tcp.mxtoolbox.com
    ```
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 gio/tests/resolver.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 51 insertions(+), 3 deletions(-)
---
diff --git a/gio/tests/resolver.c b/gio/tests/resolver.c
index 6e0c4d73b4..d62a4fd182 100644
--- a/gio/tests/resolver.c
+++ b/gio/tests/resolver.c
@@ -44,12 +44,12 @@ static G_NORETURN void
 usage (void)
 {
        fprintf (stderr, "Usage: resolver [-s] [hostname | IP | service/protocol/domain ] ...\n");
-       fprintf (stderr, "Usage: resolver [-s] [-t MX|TXT|NS|SOA] rrname ...\n");
+       fprintf (stderr, "Usage: resolver [-s] [-t MX|TXT|NS|SOA|SRV] rrname ...\n");
        fprintf (stderr, "       resolver [-s] -c NUMBER [hostname | IP | service/protocol/domain ]\n");
        fprintf (stderr, "       Use -s to do synchronous lookups.\n");
        fprintf (stderr, "       Use -c NUMBER (and only a single resolvable argument) to test 
GSocketConnectable.\n");
        fprintf (stderr, "       The given NUMBER determines how many times the connectable will be 
enumerated.\n");
-       fprintf (stderr, "       Use -t with MX, TXT, NS or SOA to look up DNS records of those types.\n");
+       fprintf (stderr, "       Use -t with MX, TXT, NS, SOA or SRV to look up DNS records of those 
types.\n");
        exit (1);
 }
 
@@ -232,6 +232,46 @@ print_resolved_txt (const char *rrname,
   G_UNLOCK (response);
 }
 
+static void
+print_resolved_srv (const char *rrname,
+                    GList      *records,
+                    GError     *error)
+{
+  G_LOCK (response);
+  printf ("Domain: %s\n", rrname);
+  if (error)
+    {
+      printf ("Error: %s\n", error->message);
+      g_error_free (error);
+    }
+  else if (!records)
+    {
+      printf ("no SRV records\n");
+    }
+  else
+    {
+      GList *t;
+
+      for (t = records; t != NULL; t = t->next)
+        {
+          guint16 priority, weight, port;
+          const gchar *target;
+
+          g_variant_get (t->data, "(qqq&s)", &priority, &weight, &port, &target);
+
+          printf ("%s (priority %u, weight %u, port %u)\n",
+                  target, (guint) priority, (guint) weight, (guint) port);
+          g_variant_unref (t->data);
+        }
+
+      g_list_free (records);
+    }
+  printf ("\n");
+
+  done_lookup ();
+  G_UNLOCK (response);
+}
+
 static void
 print_resolved_soa (const char *rrname,
                     GList      *records,
@@ -331,6 +371,9 @@ lookup_one_sync (const char *arg)
         case G_RESOLVER_RECORD_TXT:
           print_resolved_txt (arg, records, error);
           break;
+        case G_RESOLVER_RECORD_SRV:
+          print_resolved_srv (arg, records, error);
+          break;
         default:
           g_warn_if_reached ();
           break;
@@ -449,6 +492,9 @@ lookup_records_callback (GObject      *source,
     case G_RESOLVER_RECORD_TXT:
       print_resolved_txt (arg, records, error);
       break;
+    case G_RESOLVER_RECORD_SRV:
+      print_resolved_srv (arg, records, error);
+      break;
     default:
       g_warn_if_reached ();
       break;
@@ -659,9 +705,11 @@ record_type_arg (const gchar *option_name,
     record_type = G_RESOLVER_RECORD_SOA;
   } else if (g_ascii_strcasecmp (value, "NS") == 0) {
     record_type = G_RESOLVER_RECORD_NS;
+  } else if (g_ascii_strcasecmp (value, "SRV") == 0) {
+    record_type = G_RESOLVER_RECORD_SRV;
   } else {
       g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
-                   "Specify MX, TXT, NS or SOA for the special record lookup types");
+                   "Specify MX, TXT, NS, SOA or SRV for the special record lookup types");
       return FALSE;
   }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]