Commit | Line | Data |
0198fd3c |
1 | /* |
2 | * echo.c -- |
3 | * |
4 | * Produce a page containing all FastCGI inputs |
5 | * |
6 | * |
7 | * Copyright (c) 1996 Open Market, Inc. |
8 | * |
9 | * See the file "LICENSE.TERMS" for information on usage and redistribution |
10 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
11 | * |
12 | */ |
13 | |
14 | #ifndef lint |
15 | static const char rcsid[] = "$Id: echo.c,v 1.1 1997/09/16 15:36:28 stanleyg Exp $"; |
16 | #endif /* not lint */ |
17 | |
18 | #include "fcgi_stdio.h" |
19 | #include <stdlib.h> |
20 | |
21 | #ifdef _WIN32 |
22 | #include <process.h> |
23 | #else |
24 | extern char **environ; |
25 | #endif |
26 | |
27 | void PrintEnv(char *label, char **envp) |
28 | { |
29 | printf("%s:<br>\n<pre>\n", label); |
30 | for(; *envp != NULL; envp++) { |
31 | printf("%s\n", *envp); |
32 | } |
33 | printf("</pre><p>\n"); |
34 | } |
35 | |
36 | void main () |
37 | { |
38 | char **initialEnv = environ; |
39 | int count = 0; |
40 | while(FCGI_Accept() >= 0) { |
41 | char *contentLength = getenv("CONTENT_LENGTH"); |
42 | int len; |
43 | printf("Content-type: text/html\r\n" |
44 | "\r\n" |
45 | "<title>FastCGI echo</title>" |
46 | "<h1>FastCGI echo</h1>\n" |
47 | "Request number %d, Process ID: %d<p>\n", ++count, getpid()); |
48 | if(contentLength != NULL) { |
49 | len = strtol(contentLength, NULL, 10); |
50 | } else { |
51 | len = 0; |
52 | } |
53 | if(len <= 0) { |
54 | printf("No data from standard input.<p>\n"); |
55 | } else { |
56 | int i, ch; |
57 | printf("Standard input:<br>\n<pre>\n"); |
58 | for(i = 0; i < len; i++) { |
59 | if((ch = getchar()) < 0) { |
60 | printf("Error: Not enough bytes received " |
61 | "on standard input<p>\n"); |
62 | break; |
63 | } |
64 | putchar(ch); |
65 | } |
66 | printf("\n</pre><p>\n"); |
67 | } |
68 | PrintEnv("Request environment", environ); |
69 | PrintEnv("Initial environment", initialEnv); |
70 | } /* while */ |
71 | } |