summaryrefslogtreecommitdiff
path: root/FS/bin/freeside-xmlrpcd
blob: e4e03345afb5a329e2cdcfee1ea3564af059f465 (plain)
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
#!/usr/bin/perl

use FS::Daemon::Preforking qw( freeside_init1 freeside_init2 daemon_run );

use FS::XMLRPC_Lite; #XMLRPC::Lite for XMLRPC::Serializer
                     #and XMLRPC::Transport::HTTP

use FS::Conf;
use FS::API;

#freeside xmlrpc.cgi
my %typelookup = (
#not utf-8 safe#  base64 => [10, sub {$_[0] =~ /[^\x09\x0a\x0d\x20-\x7f]/}, 'as_base64'],
  dateTime => [35, sub {$_[0] =~ /^\d{8}T\d\d:\d\d:\d\d$/}, 'as_dateTime'],
  string   => [40, sub {1}, 'as_string'],
);

use constant ME => 'xmlrpcd';
freeside_init1(ME);
freeside_init2(ME);

my $conf = new FS::Conf;
die "not running; xmlrpc_api conf option is off\n"
  unless $conf->exists('xmlrpc_api');
die "not running; api_shared_secret conf option is not set\n"
  unless $conf->config('api_shared_secret');

daemon_run( 'port' => 8008, 'handle_request' =>
  sub {
    my $request = shift;

    my $serializer = new XMLRPC::Serializer(typelookup => \%typelookup);

    #my $soap = SOAP::Transport::HTTP::Server
    my $soap = XMLRPC::Transport::HTTP::Server
               -> new
               -> dispatch_to('FS::API')
               -> serializer($serializer);

    $soap->request($request);
    $soap->handle;

    $FS::UID::dbh->commit() if $FS::UID::dbh; #XXX handle commit error

    return $soap->response;
  }
);

1;