joes 2004/07/07 09:12:15
Modified: env test_cgi.c
src apreq_env.c apreq_env.h
Log:
Replace stdio with apr_file in cgi env.
Revision Changes Path
1.10 +14 -8 httpd-apreq-2/env/test_cgi.c
Index: test_cgi.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/env/test_cgi.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- test_cgi.c 15 Jun 2004 04:35:02 -0000 1.9
+++ test_cgi.c 7 Jul 2004 16:12:15 -0000 1.10
@@ -37,6 +37,7 @@
apr_pool_t *pool;
apreq_request_t *req;
const apreq_param_t *foo, *bar, *test, *key;
+ apr_file_t *out;
atexit(apr_terminate);
if (apr_app_initialize(&argc, &argv, NULL) != APR_SUCCESS) {
@@ -49,10 +50,12 @@
exit(-1);
}
+ apr_file_open_stdout(&out, pool);
+
apreq_log(APREQ_DEBUG 0, pool, "%s", "Creating apreq_request");
req = apreq_request(pool, NULL);
- printf("%s", "Content-Type: text/plain\n\n");
+ apr_file_printf(out, "%s", "Content-Type: text/plain\n\n");
apreq_log(APREQ_DEBUG 0, pool, "%s", "Fetching the parameters");
foo = apreq_param(req, "foo");
@@ -63,11 +66,11 @@
if (foo || bar) {
if (foo) {
- printf("\t%s => %s\n", "foo", foo->v.data);
+ apr_file_printf(out, "\t%s => %s\n", "foo", foo->v.data);
apreq_log(APREQ_DEBUG 0, pool, "%s => %s", "foo", foo->v.data);
}
if (bar) {
- printf("\t%s => %s\n", "bar", bar->v.data);
+ apr_file_printf(out, "\t%s => %s\n", "bar", bar->v.data);
apreq_log(APREQ_DEBUG 0, pool, "%s => %s", "bar", bar->v.data);
}
}
@@ -94,10 +97,13 @@
else {
char *dest = apr_pcalloc(pool, cookie->v.size + 1);
if (apreq_decode(dest, cookie->v.data, cookie->v.size) >= 0)
- printf("%s", dest);
- else
- apreq_log(APREQ_DEBUG 0, pool, "Bad cookie encoding: %s",
+ apr_file_printf(out, "%s", dest);
+ else {
+ apreq_log(APREQ_ERROR APR_EGENERAL, pool,
+ "Bad cookie encoding: %s",
cookie->v.data);
+ exit(-1);
+ }
}
}
@@ -108,11 +114,11 @@
apreq_log(APREQ_DEBUG 0, pool, "Fetching all parameters");
if (params == NULL) {
- apreq_log(APREQ_DEBUG 0, pool, "No parameters found!");
+ apreq_log(APREQ_ERROR APR_EGENERAL, pool, "No parameters
found!");
exit(-1);
}
apr_table_do(dump_table, &count, params, NULL);
- printf("%d", count);
+ apr_file_printf(out, "%d", count);
}
return 0;
1.10 +4 -4 httpd-apreq-2/src/apreq_env.c
Index: apreq_env.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_env.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- apreq_env.c 5 Jul 2004 17:39:50 -0000 1.9
+++ apreq_env.c 7 Jul 2004 16:12:15 -0000 1.10
@@ -23,8 +23,6 @@
#include "apr_env.h"
#include "apr_file_io.h"
-#include <stdlib.h>
-#include <stdio.h>
static const apreq_env_t *apreq_env;
@@ -146,7 +144,7 @@
#define APREQ_MODULE_NAME "CGI"
-#define APREQ_MODULE_MAGIC_NUMBER 20040705
+#define APREQ_MODULE_MAGIC_NUMBER 20040707
static apr_pool_t *cgi_pool(void *env)
{
@@ -228,7 +226,9 @@
{
dP;
char buf[256];
- fprintf(stderr, "[%s(%d): %s] %s\n", file, line,
+ apr_file_t *err;
+ apr_file_open_stderr(&err, p);
+ apr_file_printf(err, "[%s(%d): %s] %s\n", file, line,
apr_strerror(status,buf,255),apr_pvsprintf(p,fmt,vp));
}
1.25 +1 -0 httpd-apreq-2/src/apreq_env.h
Index: apreq_env.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_env.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- apreq_env.h 23 Jun 2004 02:22:28 -0000 1.24
+++ apreq_env.h 7 Jul 2004 16:12:15 -0000 1.25
@@ -19,6 +19,7 @@
#include "apreq_params.h"
#include "apreq_cookie.h"
+#include <stdarg.h>
#ifdef HAVE_SYSLOG
#include <syslog.h>