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 |
2fd179ab |
15 | static const char rcsid[] = "$Id: echo.c,v 1.2 1999/01/30 22:27:31 roberts Exp $"; |
0198fd3c |
16 | #endif /* not lint */ |
17 | |
2fd179ab |
18 | #if defined HAVE_UNISTD_H || __linux__ |
19 | #include <unistd.h> |
20 | #endif |
21 | |
0198fd3c |
22 | #include "fcgi_stdio.h" |
23 | #include <stdlib.h> |
24 | |
25 | #ifdef _WIN32 |
26 | #include <process.h> |
27 | #else |
28 | extern char **environ; |
29 | #endif |
30 | |
2fd179ab |
31 | static void PrintEnv(char *label, char **envp) |
0198fd3c |
32 | { |
33 | printf("%s:<br>\n<pre>\n", label); |
34 | for(; *envp != NULL; envp++) { |
35 | printf("%s\n", *envp); |
36 | } |
37 | printf("</pre><p>\n"); |
38 | } |
39 | |
40 | void main () |
41 | { |
42 | char **initialEnv = environ; |
43 | int count = 0; |
44 | while(FCGI_Accept() >= 0) { |
45 | char *contentLength = getenv("CONTENT_LENGTH"); |
46 | int len; |
47 | printf("Content-type: text/html\r\n" |
48 | "\r\n" |
49 | "<title>FastCGI echo</title>" |
50 | "<h1>FastCGI echo</h1>\n" |
51 | "Request number %d, Process ID: %d<p>\n", ++count, getpid()); |
52 | if(contentLength != NULL) { |
53 | len = strtol(contentLength, NULL, 10); |
54 | } else { |
55 | len = 0; |
56 | } |
57 | if(len <= 0) { |
58 | printf("No data from standard input.<p>\n"); |
59 | } else { |
60 | int i, ch; |
61 | printf("Standard input:<br>\n<pre>\n"); |
62 | for(i = 0; i < len; i++) { |
63 | if((ch = getchar()) < 0) { |
64 | printf("Error: Not enough bytes received " |
65 | "on standard input<p>\n"); |
66 | break; |
67 | } |
68 | putchar(ch); |
69 | } |
70 | printf("\n</pre><p>\n"); |
71 | } |
72 | PrintEnv("Request environment", environ); |
73 | PrintEnv("Initial environment", initialEnv); |
74 | } /* while */ |
75 | } |