aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets/test/old_httpd_SUITE_data/cgi_echo.c
diff options
context:
space:
mode:
authorIngela Anderton Andin <[email protected]>2014-01-21 15:41:31 +0100
committerIngela Anderton Andin <[email protected]>2014-01-21 15:41:31 +0100
commit744984833cc1a51f51781e3417db7f152eeab4ae (patch)
tree48a2c08a403d830755e19fc7e2bb452d44f584dd /lib/inets/test/old_httpd_SUITE_data/cgi_echo.c
parent41db1e8520171908b3ebc4ecd1d09d83dd4dc535 (diff)
parent44c4ecd8bad76c1ecc2eae2d23ebf212f1c299b9 (diff)
downloadotp-744984833cc1a51f51781e3417db7f152eeab4ae.tar.gz
otp-744984833cc1a51f51781e3417db7f152eeab4ae.tar.bz2
otp-744984833cc1a51f51781e3417db7f152eeab4ae.zip
Merge branch 'ia/inets/httpd-manager-improvments/OTP-11557' into maint
* ia/inets/httpd-manager-improvments/OTP-11557: inets: Prepare for release inets: Remove log message as it causes more harm than use at the moment inets: Mend broken max_clients check inets: Start CT'ify httpd_SUITE inets: Remove use of default gen_server timeout
Diffstat (limited to 'lib/inets/test/old_httpd_SUITE_data/cgi_echo.c')
-rw-r--r--lib/inets/test/old_httpd_SUITE_data/cgi_echo.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/lib/inets/test/old_httpd_SUITE_data/cgi_echo.c b/lib/inets/test/old_httpd_SUITE_data/cgi_echo.c
new file mode 100644
index 0000000000..580f860e96
--- /dev/null
+++ b/lib/inets/test/old_httpd_SUITE_data/cgi_echo.c
@@ -0,0 +1,97 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#if defined __WIN32__
+#include <windows.h>
+#include <fcntl.h>
+#endif
+
+static int read_exact(char *buffer, int len);
+static int write_exact(char *buffer, int len);
+
+int main(void)
+{
+ char msg[100];
+ int msg_len;
+#ifdef __WIN32__
+ _setmode(_fileno( stdin), _O_BINARY);
+ _setmode(_fileno( stdout), _O_BINARY);
+#endif
+ msg_len = read_exact(msg, 100);
+
+ write_exact("Content-type: text/plain\r\n\r\n", 28);
+ write_exact(msg, msg_len);
+ exit(EXIT_SUCCESS);
+}
+
+
+/* read from stdin */
+#ifdef __WIN32__
+static int read_exact(char *buffer, int len)
+{
+ HANDLE standard_input = GetStdHandle(STD_INPUT_HANDLE);
+
+ unsigned read_result;
+ unsigned sofar = 0;
+
+ if (!len) { /* Happens for "empty packages */
+ return 0;
+ }
+ for (;;) {
+ if (!ReadFile(standard_input, buffer + sofar,
+ len - sofar, &read_result, NULL)) {
+ return -1; /* EOF */
+ }
+ if (!read_result) {
+ return -2; /* Interrupted while reading? */
+ }
+ sofar += read_result;
+ if (sofar == len) {
+ return len;
+ }
+ }
+}
+#else
+static int read_exact(char *buffer, int len) {
+ int i, got = 0;
+
+ do {
+ if ((i = read(0, buffer + got, len - got)) <= 0)
+ return(i);
+ got += i;
+ } while (got < len);
+ return len;
+
+}
+#endif
+
+/* write to stdout */
+#ifdef __WIN32__
+ static int write_exact(char *buffer, int len)
+ {
+ HANDLE standard_output = GetStdHandle(STD_OUTPUT_HANDLE);
+ unsigned written;
+
+ if (!WriteFile(standard_output, buffer, len, &written, NULL)) {
+ return -1; /* Broken Pipe */
+ }
+ if (written < ((unsigned) len)) {
+ /* This should not happen, standard output is not blocking? */
+ return -2;
+ }
+
+ return (int) written;
+}
+
+#else
+ static int write_exact(char *buffer, int len) {
+ int i, wrote = 0;
+
+ do {
+ if ((i = write(1, buffer + wrote, len - wrote)) <= 0)
+ return i;
+ wrote += i;
+ } while (wrote < len);
+ return len;
+ }
+#endif