/*------------------------------------------------
//
// Module: env-cgi.c
//
// Objet :	Afficher en HTML l'environnement important du serveur
//					WebLight
//
// ToDo  :
//
//
//
// Maintenance :
//
//		 Auteur  : Olivier Booklage
//		 Version : V1.0
//		 Date 	 : 22/04/1998
//		 Remarq. :
//
//
//
//-----------------------------------------------*/


/* ---			 Includes externes			 -- */

#include	<stdio.h>
#include	<stdlib.h>
#include	<portab.h>

/* ---			 Includes internes			 -- */

/* --- Constantes globales internes --- */

/* --- Structures globales internes --- */

/* --- Variables globales  internes --- */

/* ---		 Prototypage interne			--- */

int main ( int argc, const char *argv[] );
VOID show ( char *value );

/* ---				 Fonctions						--- */

int main ( int argc, const char *argv[] )
{
int i;
int car;
int length;
UBYTE *ptr;

	printf("Content-type: text/html%c%c\n",10,10);

	printf("<html><head><title>CGI-Environment</title></head><body>\n\n\n");

	printf(" ENV-CGI/1.1 test script report:<br><br>\n");

	printf(" argc is %d argv is :", argc-1);
	
	for (i = 1 ; i < argc; i++ )
		printf("%s ", argv[i]);
	
	printf("<br>\n");

	printf(" 21 environmental variables:\n\n<br><br>");

	show("GATEWAY_INTERFACE");
	show("SERVER_SOFTWARE");
	show("SERVER_NAME");
	show("SERVER_PROTOCOL");
	show("SERVER_PORT");
	show("REQUEST_METHOD");
	show("HTTP_ACCEPT");
	show("HTTP_USER_AGENT");
	show("HTTP_REFERER");
	show("PATH_INFO");
	show("PATH_TRANSLATED");
	show("SCRIPT_NAME");
	show("QUERY_STRING");
	show("REMOTE_HOST");
	show("REMOTE_ADDR");
	show("REMOTE_USER");
	show("REMOTE_IDENT");
	show("AUTH_TYPE");
	show("CONTENT_TYPE");
	show("CONTENT_LENGTH");
	show("ANNOTATION_SERVER");

	if ( (ptr= getenv("CONTENT_LENGTH")) != NULL )
	{
		if ( (length=atoi(ptr)) > 0 )
		{
			printf("<P>Waiting CONTENT_LENGTH (%d) datas from stdin :</P>\n<HR>", length);
			for(;;)
			{
				if ( feof(stdin) != 0 )	break;
				if ( (car= fgetc(stdin)) >= 0 )
					putc( car, stdout);
			}
			printf("\n<HR>\n");
		}
	}

	printf("<br>\n</body></html>\n<br>");

return(0);
}

VOID show ( char *value )
{
char *ptr = getenv( value );

	if ( ptr != NULL )	printf("%s = %s  <br>\n", value, ptr );
}


/* ---					EOF 								--- */
