#!/usr/local/bin/perl -w

use strict;

use App::Options (
    options => [qw(verbose)],
    option => {
        verbose => {
            description => "Print more detail so we can see what's going on (range=0-9)",
            default => 0,
        },
    },
);

=head1 NAME

otaserver - A CGI program (and Registry program under mod_perl) that responds to OTA messages sent via simple HTTP/HTTPS

=head1 SYNOPSIS

  # use the "otaclient" program to exercise "otaserver"
  # (by default, the "client_class" is set to "Business::Travel::OTA::Client::HTTP")

  otaclient --ping
  otaclient --ping --client_class=Business::Travel::OTA::Client::HTTP --responder=http://localhost/cgi-bin/otaserver

=head1 DESCRIPTION

The "otaserver" program is a CGI program (and Registry program under mod_perl)
that responds to OTA messages sent via simple HTTP/HTTPS.

=cut

use CGI;
use CGI::Carp 'fatalsToBrowser';
use Business::Travel::OTA::Server;
use Business::Travel::OTA::Utils qw(dump);

{
    my $cgi = CGI->new();
    # print "cgi={", join(",",%$cgi), "}\n";
    my $request_xml = $cgi->{POSTDATA}[0];
    my $server = Business::Travel::OTA::Server->new();
    my $response_xml = $server->execute($request_xml);
    &send_response($cgi, $response_xml);
}

sub send_response {
    my ($cgi, $response_xml) = @_;
    print "Content-type: application/xml\n";
    print "Content-length: ", length($response_xml), "\n";
    print "\n";
    print $response_xml;
}

sub read_file {
    my ($file) = @_;
    open(FILE, $file) || die "Unable to open $file: $!";
    my $data = join("", <main::FILE>);
    close(FILE);
    return($data);
}

=head1 ACKNOWLEDGEMENTS

 * Author:  Stephen Adkins <sadkins@therubicongroup.com>
 * Copyright: (c) 2005 Stephen Adkins (for the purpose of making it Free)
 * License: This is free software. It is licensed under the same terms as Perl itself.

=head1 SEE ALSO

=cut

