Removed support for SFIO
[catagits/fcgi2.git] / examples / echo-x.c
CommitLineData
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
b9017399 14static const char rcsid[] = "$Id: echo-x.c,v 1.1 2001/06/19 15:06:17 robs 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>
fbf75401 27#else
28extern char **environ;
0198fd3c 29#endif
30
344bf056 31#include "fcgiapp.h"
32
2fd179ab 33static void PrintEnv(FCGX_Stream *out, char *label, char **envp)
0198fd3c 34{
0198fd3c 35 FCGX_FPrintF(out, "%s:<br>\n<pre>\n", label);
fbf75401 36 for( ; *envp != NULL; envp++) {
0198fd3c 37 FCGX_FPrintF(out, "%s\n", *envp);
38 }
39 FCGX_FPrintF(out, "</pre><p>\n");
40}
41
3293ebdf 42int main ()
0198fd3c 43{
44 FCGX_Stream *in, *out, *err;
45 FCGX_ParamArray envp;
46 int count = 0;
fbf75401 47
0198fd3c 48 while (FCGX_Accept(&in, &out, &err, &envp) >= 0) {
49 char *contentLength = FCGX_GetParam("CONTENT_LENGTH", envp);
fbf75401 50 int len = 0;
51
0198fd3c 52 FCGX_FPrintF(out,
fbf75401 53 "Content-type: text/html\r\n"
54 "\r\n"
55 "<title>FastCGI echo (fcgiapp version)</title>"
56 "<h1>FastCGI echo (fcgiapp version)</h1>\n"
57 "Request number %d, Process ID: %d<p>\n", ++count, getpid());
58
59 if (contentLength != NULL)
0198fd3c 60 len = strtol(contentLength, NULL, 10);
fbf75401 61
62 if (len <= 0) {
63 FCGX_FPrintF(out, "No data from standard input.<p>\n");
0198fd3c 64 }
fbf75401 65 else {
0198fd3c 66 int i, ch;
fbf75401 67
68 FCGX_FPrintF(out, "Standard input:<br>\n<pre>\n");
69 for (i = 0; i < len; i++) {
70 if ((ch = FCGX_GetChar(in)) < 0) {
71 FCGX_FPrintF(out,
72 "Error: Not enough bytes received on standard input<p>\n");
0198fd3c 73 break;
fbf75401 74 }
0198fd3c 75 FCGX_PutChar(ch, out);
76 }
77 FCGX_FPrintF(out, "\n</pre><p>\n");
78 }
fbf75401 79
0198fd3c 80 PrintEnv(out, "Request environment", envp);
81 PrintEnv(out, "Initial environment", environ);
82 } /* while */
3293ebdf 83
b7720ffb 84 return 0;
0198fd3c 85}