//-----------------------------------------------------------------------------
// Copyright © 2003 - Philip Howard - All rights reserved
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/cgi
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	phil at ipal dot org
// homepage	http://phil.ipal.org/
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 112 columns wide.
//-----------------------------------------------------------------------------

#include <stdlib.h>

#include "cgi_lib.h"

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	cgi_is_nph
//
// purpose	Return true (1) if CGI is running in Non-Parsed-Header (NPH)
//		mode under Apache or an equivalently compatible web server.
//
// arguments	-none-
//
// returns	(int) -1 : error (maybe not CGI at all)
//		(int)  0 : not NPH mode
//		(int)  1 : NPH mode
//-----------------------------------------------------------------------------
int
cgi_is_nph ()
__PROTO_END__
{
    const char *	script_name	;
    const char *	script_tail	;

    script_name = getenv( "SCRIPT_NAME" );
    if ( ! script_name ) return -1;

    script_tail = script_name;
    while ( * script_name ) {
	if ( * script_name ++ == '/' ) {
	    script_tail = script_name;
	}
    }

    if ( ( ( script_tail[0] == 'n' && script_tail[1] == 'p' && script_tail[2] == 'h' ) ||
	   ( script_tail[0] == 'N' && script_tail[1] == 'P' && script_tail[2] == 'H' ) ) &&
	 script_tail[3] == '-' ) {
	return 1;
    }

    return 0;
}

