#!/bin/sh

clhint=0

function msg()
{
	echo $1 >&2
}

function set_verdict()
{
	cat >&3 <<EOF
0 SETVERDICT
[]Verdict
$1
[]Description
$2

EOF
	while read response <&3; do
		if [ "$response" = "" ]; then
			break;
		fi
	done

}

function get_clhint()
{
	cat >&3 <<EOF
0 GETCONTENTHINT

EOF
	while read response <&3; do
		if [ `echo $response | grep "\]Content-Length$"` ]; then
			count=`echo $response | sed -e 's/^\[\([0-9]*\)\].*$/\1/'`
			msg "header length: $count"
			IFS="" read -u 3 -n $count clhint
		elif [ "$response" = "" ]; then
			break;
		fi
	done

}

function set_clhint()
{
	cat >&3 <<EOF
0 SETCONTENTHINT
[]Content-Length
$1

EOF
	while read response <&3; do
		if [ "$response" = "" ]; then
			break;
		fi
	done

}


get_clhint
if [ "$clhint" -ne 0 ]; then
	set_clhint $clhint
fi
set_verdict Z_REJECT
cat
