#! /usr/bin/perl
######################################################################
#
# main module
#
######################################################################
#
# $Id: upgrade.pl,v 1.7 2000/10/19 19:48:47 koike Exp $
# Created by Yuichi Koike (koike@w3.org)
#

use strict;
require "common.pl";
require "xml.pl";
use CGI;
#
# Main routine
#

######################################################################
#  Initialization
######################################################################

# Dealing with parameters
$| = 1;

my $q = new CGI;

# URI correction
my $xml = new P3P::XML;
my $uri;
my $buffer;
if($q->param("uri")) {
	$uri = P3P::Common::correctURI($q->param("uri"));
	$xml->setURI($uri);
	if($xml->access eq 200) {
		$buffer = $xml->{content};
	}
} elsif($q->param("file")) {
	my $f = $q->param('file');
	$uri = scalar($f);
	my $h = $q->uploadInfo($f);
	while (not eof $f) {$buffer .= <$f>};
}

if(! $buffer) {
	print "Content-type: text/html

<html><body>
Error: Can not retrieve the contents of [uri=$uri].<br />
Please try again with another URI.
</body></html>
";
} else {
	open BBB, ">> /home/koike/validator/20001018/upgrade.log";
	print BBB scalar(localtime()), " ", $ENV{"REMOTE_ADDR"}, " ", $uri, "\n";
	close BBB;

	print "Content-type: text/xml\n\n";

	my $tmp1 = "/tmp/p3p1.$$";
	my $tmp2 = "/tmp/p3p2.$$";
	open(AAA, "> ".$tmp1);
	print AAA $buffer;
	close AAA;

	$ENV{"LD_LIBRARY_PATH"} = "/home/koike/XSLT/";
	system("/home/koike/XSLT/sabcmd /usr/local/p3p-validator/20001018/p3p-up.xsl < $tmp1 >& $tmp2");
	open BBB, $tmp2;
	my $cont;
	while(<BBB>) { print $_; };
	close BBB;
	unlink $tmp1;
	unlink $tmp2;
}
1;


