work around missing id, RT#83146
[freeside.git] / FS / bin / freeside-xmlrpcd
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 freeside-xmlrpcd
6
7 =cut
8
9 use FS::Daemon::Preforking qw( freeside_init1 freeside_init2 daemon_run );
10
11 use FS::XMLRPC_Lite; #XMLRPC::Lite for XMLRPC::Serializer
12                      #and XMLRPC::Transport::HTTP
13
14 use FS::Conf;
15 use FS::API;
16
17 #freeside xmlrpc.cgi
18 my %typelookup = (
19 #not utf-8 safe#  base64 => [10, sub {$_[0] =~ /[^\x09\x0a\x0d\x20-\x7f]/}, 'as_base64'],
20   dateTime => [35, sub {$_[0] =~ /^\d{8}T\d\d:\d\d:\d\d$/}, 'as_dateTime'],
21   string   => [40, sub {1}, 'as_string'],
22 );
23
24 use constant ME => 'xmlrpcd';
25 freeside_init1(ME);
26 freeside_init2(ME);
27
28 my $conf = new FS::Conf;
29 die "not running; xmlrpc_api conf option is off\n"
30   unless $conf->exists('xmlrpc_api');
31 die "not running; api_shared_secret conf option is not set\n"
32   unless $conf->config('api_shared_secret');
33
34 daemon_run( 'port' => 8008, 'handle_request' =>
35   sub {
36     my $request = shift;
37
38     my $serializer = new XMLRPC::Serializer(typelookup => \%typelookup);
39
40     #my $soap = SOAP::Transport::HTTP::Server
41     my $soap = XMLRPC::Transport::HTTP::Server
42                -> new
43                -> dispatch_to('FS::API')
44                -> serializer($serializer);
45
46     $soap->request($request);
47     $soap->handle;
48
49     $FS::UID::dbh->commit() if $FS::UID::dbh; #XXX handle commit error
50
51     return $soap->response;
52   }
53 );
54
55 1;