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