]> git.ipfire.org Git - thirdparty/pdns.git/blob - contrib/remotebackend-pipe-test.pl
add notified_serial range test to pdnsutil test-schema
[thirdparty/pdns.git] / contrib / remotebackend-pipe-test.pl
1 #!/usr/bin/perl
2 ### This script is intended for testing/developing remotebackend scripts
3 ### To use, please install libjson-any-perl (JSON::Any) and libjson-xs-perl (JSON::XS)
4 ### (c) Aki Tuomi 2013 - Distributed under same license as PowerDNS Authoritative Server
5 use strict;
6 use warnings;
7 use 5.005;
8 use IPC::Open2;
9 use JSON::Any;
10
11 ### CONFIGURATION SECTION
12
13 ## Full path to your remotebackend script
14 my $script = "/home/cmouse/projects/pdns-v6-autorev/rev.pl";
15
16 ## These are used to send initialize method before your actual code
17 my $initparams = { value => "foo", value2 => "bar" };
18
19 ## END CONFIGURATION
20
21 $|=1;
22 my $in;
23 my $out;
24 my $pid = open2($in,$out,$script);
25
26 my $j = JSON::Any->new;
27
28 sub rpc {
29 my $meth = shift;
30 my %p = @_;
31
32 print $j->encode({method => $meth, parameters => \%p}),"\r\n";
33 print $out $j->encode({method => $meth, parameters => \%p}),"\r\n";
34 my $res = <$in>;
35 if ($res) {
36 chomp $res;
37 print $res,"\n";
38 }
39 }
40
41 rpc 'initialize', %$initparams;
42
43 if (@ARGV>1) {
44
45 ## this lets you call whatever method with simple parameters
46 ## like this:
47
48 # perl remotebackend-pipe-test.pl lookup qtype SOA qname powerdns.com
49
50 ## this will execute
51 ## {"parameters":{"qname":"powerdns.com","qtype":"SOA"},"method":"lookup"}
52 ## on your remotebackend
53
54 my $meth = shift;
55 rpc $meth, @ARGV;
56
57
58 } else {
59
60 ## Put whatever you want to run here. Or leave it empty if you
61 ## only want to use the command line
62
63 #rpc 'lookup', qname => 'powerdns.com', qtype => 'SOA';
64
65 }