#!/usr/bin/perl -I.

###############################################################################
# setcookie.cgi
#
#
# Dreamcast Version
# SONIC ADVENTURE
#
# called as:
#  setcookie.cgi?file=SourceFile&name=CookieName&value=CookieValue&path=CookiePath
#
###############################################################################

## Ensure strict variable usage
use strict;

use CGI;
use	DC;

## Set up variables
use vars	( '$q',		# CGI object
			  '$dc',	# DC object
			  '$errorURL'
			);

###############################################################################
# Main Program
###############################################################################

	$q = new CGI;
	$dc = new DC($q);
	$errorURL = "chao_gardens.html";
	my $location = "";

    if(!defined($q->param('file')) ||
		!defined($q->param('name')) ||
		!defined($q->param('value')) ||
		!defined($q->param('path')) ) {
        $dc->error("Missing fields for cookie.", $errorURL);
    }

	my $cookie = $q->cookie(-name    => $q->param('name'),
							-value   => $q->param('value'),
							-expires => '+1d',
							-path    => $q->param('path'));

	#print $dc->q->header(-cookie => $cookie). "\n";
	print "Set-Cookie: ".$cookie."\n";
	
	print "Cache-control: no-cache\n";

	if (($dc->q->param('file') =~ /^chao_.+\.html$/) && ($dc->q->param('file') =~ /[0-9a-zA-Z_\.]/)) 
	{
		$location = sprintf "../../../%s", $dc->q->param('file');
		$dc->output_form($location);
	} else {
		$dc->error("Invalid file was chosen.", $errorURL);
	}

    exit;
 
#------------------------ EOF --------------------------

