Commit | Line | Data |
fbf75401 |
1 | /* |
0198fd3c |
2 | * echo2.c -- |
3 | * |
fbf75401 |
4 | * Produce a page containing all the inputs (fcgiapp version) |
0198fd3c |
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 | */ |
0198fd3c |
13 | #ifndef lint |
54cf3fec |
14 | static const char rcsid[] = "$Id: echo2.c,v 1.6 1999/07/27 19:01:39 roberts Exp $"; |
0198fd3c |
15 | #endif /* not lint */ |
16 | |
54cf3fec |
17 | #include "fcgiapp.h" |
18 | |
2fd179ab |
19 | #if defined HAVE_UNISTD_H || __linux__ |
20 | #include <unistd.h> |
21 | #endif |
22 | |
0198fd3c |
23 | #include <stdlib.h> |
0198fd3c |
24 | |
25 | #ifdef _WIN32 |
26 | #include <process.h> |
fbf75401 |
27 | #else |
28 | extern char **environ; |
0198fd3c |
29 | #endif |
30 | |
2fd179ab |
31 | static void PrintEnv(FCGX_Stream *out, char *label, char **envp) |
0198fd3c |
32 | { |
0198fd3c |
33 | FCGX_FPrintF(out, "%s:<br>\n<pre>\n", label); |
fbf75401 |
34 | for( ; *envp != NULL; envp++) { |
0198fd3c |
35 | FCGX_FPrintF(out, "%s\n", *envp); |
36 | } |
37 | FCGX_FPrintF(out, "</pre><p>\n"); |
38 | } |
39 | |
3293ebdf |
40 | int main () |
0198fd3c |
41 | { |
42 | FCGX_Stream *in, *out, *err; |
43 | FCGX_ParamArray envp; |
44 | int count = 0; |
fbf75401 |
45 | |
0198fd3c |
46 | while (FCGX_Accept(&in, &out, &err, &envp) >= 0) { |
47 | char *contentLength = FCGX_GetParam("CONTENT_LENGTH", envp); |
fbf75401 |
48 | int len = 0; |
49 | |
0198fd3c |
50 | FCGX_FPrintF(out, |
fbf75401 |
51 | "Content-type: text/html\r\n" |
52 | "\r\n" |
53 | "<title>FastCGI echo (fcgiapp version)</title>" |
54 | "<h1>FastCGI echo (fcgiapp version)</h1>\n" |
55 | "Request number %d, Process ID: %d<p>\n", ++count, getpid()); |
56 | |
57 | if (contentLength != NULL) |
0198fd3c |
58 | len = strtol(contentLength, NULL, 10); |
fbf75401 |
59 | |
60 | if (len <= 0) { |
61 | FCGX_FPrintF(out, "No data from standard input.<p>\n"); |
0198fd3c |
62 | } |
fbf75401 |
63 | else { |
0198fd3c |
64 | int i, ch; |
fbf75401 |
65 | |
66 | FCGX_FPrintF(out, "Standard input:<br>\n<pre>\n"); |
67 | for (i = 0; i < len; i++) { |
68 | if ((ch = FCGX_GetChar(in)) < 0) { |
69 | FCGX_FPrintF(out, |
70 | "Error: Not enough bytes received on standard input<p>\n"); |
0198fd3c |
71 | break; |
fbf75401 |
72 | } |
0198fd3c |
73 | FCGX_PutChar(ch, out); |
74 | } |
75 | FCGX_FPrintF(out, "\n</pre><p>\n"); |
76 | } |
fbf75401 |
77 | |
0198fd3c |
78 | PrintEnv(out, "Request environment", envp); |
79 | PrintEnv(out, "Initial environment", environ); |
80 | } /* while */ |
3293ebdf |
81 | |
b7720ffb |
82 | return 0; |
0198fd3c |
83 | } |