1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- */
/* Lac - Library for asynchronous communication
* Copyright (C) 2002, 2003 Søren Sandmann (sandmann@daimi.au.dk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <lac.h>
#include <string.h>
static int n_outstanding;
static GMainLoop *main_loop;
static void
name_callback (const gchar *name, gpointer data, const GError *err)
{
gchar *addr_str = data;
if (err)
{
g_print ("reverse %s: %s\n", addr_str, err->message);
}
else
{
g_print ("reverse %s: %s\n", addr_str, name);
}
g_free (addr_str);
}
static void
callback (const GPtrArray *addresses, gpointer data, const GError *err)
{
const gchar *name = data;
if (err)
{
g_print ("%s: %s\n", name, err->message);
}
else
{
int i;
GQueue *reverse_lookups = g_queue_new ();
g_assert (addresses->len > 0);
g_print ("%s: ", name);
for (i = 0; i < addresses->len; ++i)
{
gchar *addr_str = lac_address_to_string (addresses->pdata[i]);
g_print ("%s ", addr_str);
g_queue_push_tail (reverse_lookups, addresses->pdata[i]);
g_queue_push_tail (reverse_lookups, addr_str);
}
g_print ("\n");
while (!g_queue_is_empty (reverse_lookups))
{
LacAddress *address = g_queue_pop_head (reverse_lookups);
gpointer addr_string = g_queue_pop_head (reverse_lookups);
lac_address_lookup_name (address, name_callback, addr_string);
}
g_queue_free (reverse_lookups);
}
}
int
main (int argc, char *argv[])
{
int i;
main_loop = g_main_loop_new (NULL, TRUE);
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR |
G_LOG_LEVEL_CRITICAL);
lac_set_verbose (TRUE);
if (argc > 1)
{
for (i = 1; i < argc; ++i)
{
LacActivity activity;
++n_outstanding;
activity = lac_address_new_lookup_all_from_name (
argv[i], callback, argv[i]);
if (i == 3 || i == 4)
{
g_print ("canceling\n");
lac_activity_cancel (activity);
}
}
}
else
{
g_print ("usage %s <names>\n", argv[0]);
return 1;
}
g_assert (main_loop);
g_timeout_add (500, g_main_loop_quit, main_loop);
g_main_loop_run (main_loop);
return 0;
}
|