Fix the retry-on-broken-connection codepath for SoupRequest
[platform/upstream/libsoup.git] / tests / dns.c
index 496c543..f594064 100644 (file)
@@ -1,29 +1,33 @@
-#include <config.h>
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
-#include <stdio.h>
-#include <stdlib.h>
+#include "test-utils.h"
 
-#include "libsoup/soup-address.h"
-
-GMainLoop *loop;
+static GMainLoop *loop;
+static int nlookups = 0;
 
 static void
 resolve_callback (SoupAddress *addr, guint status, gpointer data)
 {
-       if (status != SOUP_STATUS_OK) {
-               fprintf (stderr, "%s\n", soup_status_get_phrase (status));
-               exit (1);
+       if (status == SOUP_STATUS_OK) {
+               g_print ("Name:    %s\n", soup_address_get_name (addr));
+               g_print ("Address: %s\n", soup_address_get_physical (addr));
+       } else {
+               g_print ("Name:    %s\n", soup_address_get_name (addr));
+               g_print ("Error:   %s\n", soup_status_get_phrase (status));
        }
+       g_print ("\n");
+
+       g_object_unref (addr);
 
-       printf ("Name:    %s\n", soup_address_get_name (addr));
-       printf ("Address: %s\n", soup_address_get_physical (addr));
-       g_main_loop_quit (loop);
+       nlookups--;
+       if (nlookups == 0)
+               g_main_loop_quit (loop);
 }
 
 static void
 usage (void)
 {
-       fprintf (stderr, "Usage: dns [hostname | -r IP]\n");
+       g_printerr ("Usage: dns hostname ...\n");
        exit (1);
 }
 
@@ -31,23 +35,27 @@ int
 main (int argc, char **argv)
 {
        SoupAddress *addr;
+       int i;
 
-       if (argc != 2)
+       if (argc < 2)
                usage ();
 
        g_type_init ();
-       g_thread_init (NULL);
 
-       addr = soup_address_new (argv[1], 0);
-       if (!addr) {
-               fprintf (stderr, "Could not parse address %s\n", argv[1]);
-               exit (1);
-       }
+       for (i = 1; i < argc; i++) {
+               addr = soup_address_new (argv[i], 0);
+               if (!addr) {
+                       g_printerr ("Could not parse address %s\n", argv[1]);
+                       exit (1);
+               }
 
-       soup_address_resolve_async (addr, resolve_callback, NULL);
+               soup_address_resolve_async (addr, NULL, NULL,
+                                           resolve_callback, NULL);
+               nlookups++;
+       }
 
        loop = g_main_loop_new (NULL, TRUE);
-       g_main_run (loop);
+       g_main_loop_run (loop);
        g_main_loop_unref (loop);
 
        return 0;