/* * echo.c -- * * Produce a page containing all FastCGI inputs * * * Copyright (c) 1996 Open Market, Inc. * * See the file "LICENSE.TERMS" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * */ #ifndef lint static const char rcsid[] = "$Id: echo.c,v 1.5 1999/07/28 00:29:37 roberts Exp $"; #endif /* not lint */ #include "fcgi_config.h" #include #ifdef HAVE_UNISTD_H #include #endif #ifdef _WIN32 #include #else extern char **environ; #endif #include "fcgi_stdio.h" static void PrintEnv(char *label, char **envp) { printf("%s:
\n
\n", label);
    for ( ; *envp != NULL; envp++) {
        printf("%s\n", *envp);
    }
    printf("

\n"); } int main () { char **initialEnv = environ; int count = 0; while (FCGI_Accept() >= 0) { char *contentLength = getenv("CONTENT_LENGTH"); int len; printf("Content-type: text/html\r\n" "\r\n" "FastCGI echo" "

FastCGI echo

\n" "Request number %d, Process ID: %d

\n", ++count, getpid()); if (contentLength != NULL) { len = strtol(contentLength, NULL, 10); } else { len = 0; } if (len <= 0) { printf("No data from standard input.

\n"); } else { int i, ch; printf("Standard input:
\n

\n");
            for (i = 0; i < len; i++) {
                if ((ch = getchar()) < 0) {
                    printf("Error: Not enough bytes received on standard input

\n"); break; } putchar(ch); } printf("\n

\n"); } PrintEnv("Request environment", environ); PrintEnv("Initial environment", initialEnv); } /* while */ return 0; }