File: dns-resolver.e

package info (click to toggle)
entity 1.0.1-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 5,604 kB
  • ctags: 5,394
  • sloc: ansic: 64,242; sh: 7,377; makefile: 776; perl: 319
file content (62 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download | duplicates (3)
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
<object>
  <window ondelete="entity:quit">
    <label text="Non-blocking DNS lookups"/>
    <entry name="userinput"/> 
    <button label="Get hostname from IP" onclick="lookup_host"/>
    <button label="Get IP from hostname" onclick="lookup_ip"/>
    <resolver name="first" ip="127.0.0.1" action="first_lookup_finished"/>
  </window>
  <?perl

sub lookup_host
{
	my $ip = enode("entry.userinput")->attrib("text");

	my $obj = enode("object");
	$res = $obj->new_child ("resolver");
	$res->attrib("action" => "host_lookup_finished");
	$res->attrib("onerror" => "lookup_error");
	$res->attrib("ip" => "$ip");
}

sub lookup_ip
{
	my $hostname = enode("entry.userinput")->attrib("text");
	
	my $obj = enode("object");

	# Build a resolver with append_xml to verify the sync_attribs works.
	my $xml = 
	   qq!<resolver hostname="$hostname" action="ip_lookup_finished"/>!;
	$obj->append_xml($xml);
}

sub first_lookup_finished
{
	my ($node, $result) = @_;
	print "127.0.0.1 resolves to $result\n";
	$node->destroy();
}

sub host_lookup_finished
{
	my ($node, $result) = @_;
	print "hostname resolved to $result\n";
	$node->destroy();
}

sub ip_lookup_finished
{
	my ($node, $result) = @_;
	print "ip resolved to $result\n";
	$node->destroy();
}

sub lookup_error
{
	my ($node, $error) = @_;
	print "error in resolving: $error\n";
}

  ?>
</object>