Fix the retry-on-broken-connection codepath for SoupRequest
[platform/upstream/libsoup.git] / tests / dns.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 #include "test-utils.h"
4
5 static GMainLoop *loop;
6 static int nlookups = 0;
7
8 static void
9 resolve_callback (SoupAddress *addr, guint status, gpointer data)
10 {
11         if (status == SOUP_STATUS_OK) {
12                 g_print ("Name:    %s\n", soup_address_get_name (addr));
13                 g_print ("Address: %s\n", soup_address_get_physical (addr));
14         } else {
15                 g_print ("Name:    %s\n", soup_address_get_name (addr));
16                 g_print ("Error:   %s\n", soup_status_get_phrase (status));
17         }
18         g_print ("\n");
19
20         g_object_unref (addr);
21
22         nlookups--;
23         if (nlookups == 0)
24                 g_main_loop_quit (loop);
25 }
26
27 static void
28 usage (void)
29 {
30         g_printerr ("Usage: dns hostname ...\n");
31         exit (1);
32 }
33
34 int
35 main (int argc, char **argv)
36 {
37         SoupAddress *addr;
38         int i;
39
40         if (argc < 2)
41                 usage ();
42
43         g_type_init ();
44
45         for (i = 1; i < argc; i++) {
46                 addr = soup_address_new (argv[i], 0);
47                 if (!addr) {
48                         g_printerr ("Could not parse address %s\n", argv[1]);
49                         exit (1);
50                 }
51
52                 soup_address_resolve_async (addr, NULL, NULL,
53                                             resolve_callback, NULL);
54                 nlookups++;
55         }
56
57         loop = g_main_loop_new (NULL, TRUE);
58         g_main_loop_run (loop);
59         g_main_loop_unref (loop);
60
61         return 0;
62 }