httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@covalent.net
Subject ap_strerror implementation..
Date Wed, 19 Apr 2000 17:19:34 GMT

This is pretty much gauranteed to compile and work only for the simplest
cases, but the basic idea is sound.

I'll try to clean this up now, and I'm going to commit this soon, unless
somebody objects.

Ryan


? argh
? argh.21144
? argh.21145
? lib/apr/misc/unix/errorcodes.c
Index: include/http_log.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/include/http_log.h,v
retrieving revision 1.15
diff -u -d -b -w -u -r1.15 http_log.h
--- include/http_log.h	2000/04/14 15:58:17	1.15
+++ include/http_log.h	2000/04/19 20:11:08
@@ -111,9 +111,9 @@
 
 void ap_open_logs (server_rec *, ap_pool_t *p);
 
-/* The two primary logging functions, ap_log_error and ap_log_rerror,
- * use a printf style format string to build the log message.  It is
- * VERY IMPORTANT that you not include any raw data from the network,
+/* The three primary logging functions, ap_log_error, ap_log_rerror, and 
+ * ap_log_perror use a printf style format string to build the log message.  
+ * It is VERY IMPORTANT that you not include any raw data from the network, 
  * such as the request-URI or request header fields, within the format
  * string.  Doing so makes the server vulnerable to a denial-of-service
  * attack and other messy behavior.  Instead, use a simple format string
@@ -121,6 +121,10 @@
  */
 API_EXPORT(void) ap_log_error(const char *file, int line, int level, 
                              ap_status_t status, const server_rec *s, 
+                             const char *fmt, ...)
+			    __attribute__((format(printf,6,7)));
+API_EXPORT(void) ap_log_perror(const char *file, int line, int level, 
+                             ap_status_t status, ap_pool_t *p, 
                              const char *fmt, ...)
 			    __attribute__((format(printf,6,7)));
 API_EXPORT(void) ap_log_rerror(const char *file, int line, int level, 
Index: lib/apr/include/apr_errno.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_errno.h,v
retrieving revision 1.23
diff -u -d -b -w -u -r1.23 apr_errno.h
--- lib/apr/include/apr_errno.h	2000/04/08 06:58:41	1.23
+++ lib/apr/include/apr_errno.h	2000/04/19 20:11:09
@@ -52,8 +52,9 @@
  * <http://www.apache.org/>.
  */
 
-#include <errno.h>
+#include "apr_general.h"
 #include "apr.h"
+#include <errno.h>
 
 #ifndef APR_ERRNO_H
 #define APR_ERRNO_H
@@ -62,6 +63,11 @@
 extern "C" {
 #endif /* __cplusplus */
 
+typedef int ap_status_t;
+
+int ap_canonical_error(ap_status_t err);
+
+
 /* APR_OS_START_ERROR is where the APR specific error values should start.
  * APR_OS_START_STATUS is where the APR specific status codes should start.
  * APR_OS_START_USEERR are reserved for applications that use APR that
@@ -75,11 +81,6 @@
 #define APR_OS_START_CANONERR  (APR_OS_START_USEERR + 500)
 #define APR_OS_START_SYSERR    (APR_OS_START_CANONERR + 500)
 
-typedef int ap_status_t;
-
-int ap_canonical_error(ap_status_t err);
-const char *ap_strerror(ap_status_t err);
-
 #define APR_OS2_STATUS(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR)
 
 #define APR_SUCCESS 0
@@ -130,16 +131,16 @@
 #define APR_KEYBASED       (APR_OS_START_STATUS + 21)
 
 /* A simple value to be used to initialze a status variable. */
-#define APR_EINIT          (APR_OS_START_STATUS + 16)  
+#define APR_EINIT          (APR_OS_START_STATUS + 22)  
 
 /* Not implemented either because we haven't gotten to it yet, or 
  * because it is not possible to do correctly.  
  */
-#define APR_ENOTIMPL       (APR_OS_START_STATUS + 17)
+#define APR_ENOTIMPL       (APR_OS_START_STATUS + 23)
 
 /* Passwords do not match.
  */
-#define APR_EMISMATCH      (APR_OS_START_STATUS + 18)
+#define APR_EMISMATCH      (APR_OS_START_STATUS + 24)
 
 #ifdef EACCES
 #define APR_EACCES EACCES
Index: lib/apr/include/apr_general.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_general.h,v
retrieving revision 1.26
diff -u -d -b -w -u -r1.26 apr_general.h
--- lib/apr/include/apr_general.h	2000/04/16 04:46:53	1.26
+++ lib/apr/include/apr_general.h	2000/04/19 20:11:09
@@ -357,6 +357,18 @@
  */
 ap_status_t ap_set_abort(int (*apr_abort)(int retcode), ap_pool_t *cont);
 
+/*
+
+=head1 char *ap_strerror(ap_status_t statcode, ap_pool_t *p)
+
+B<Return a human readable string describing the specified error.>
+
+    arg 1)  The error code the get a string for.
+    arg 2)  The pool to use to allocate memory for the string.
+
+=cut
+ */
+ap_status_t ap_set_abort(int (*apr_abort)(int retcode), ap_pool_t *cont);
 #ifdef __cplusplus
 }
 #endif
Index: lib/apr/misc/unix/Makefile.in
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/unix/Makefile.in,v
retrieving revision 1.12
diff -u -d -b -w -u -r1.12 Makefile.in
--- lib/apr/misc/unix/Makefile.in	2000/04/15 19:05:13	1.12
+++ lib/apr/misc/unix/Makefile.in	2000/04/19 20:11:10
@@ -15,7 +15,7 @@
 
 #LIB=libmisc.a
 
-OBJS=start.o getopt.o otherchild.o error.o rand.o
+OBJS=start.o getopt.o otherchild.o errorcodes.o rand.o
 
 .c.o:
 	$(CC) $(CFLAGS) -c $(INCLUDES) $<
Index: main/http_log.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/http_log.c,v
retrieving revision 1.40
diff -u -d -b -w -u -r1.40 http_log.c
--- main/http_log.c	2000/04/17 19:57:30	1.40
+++ main/http_log.c	2000/04/19 20:11:13
@@ -312,7 +312,8 @@
 
 static void log_error_core(const char *file, int line, int level, 
                            ap_status_t status, const server_rec *s, 
-                           const request_rec *r, const char *fmt, va_list args)
+                           const request_rec *r, ap_pool_t *pool,
+                           const char *fmt, va_list args)
 {
     char errstr[MAX_STRING_LEN + 1];    /* + 1 to have room for '\n' */
     size_t len;
@@ -408,11 +409,20 @@
 	len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
 		"[client %s] ", r->connection->remote_ip);
     }
-    /* XXX - need an APRized strerror() */
     if (!(level & APLOG_NOERRNO)
 	&& (status != 0)) {
+        ap_pool_t *p;
+        if (r) {
+            p = r->pool;
+        }
+        else if (s) {
+            p = s->process->pool;
+        }
+        else {
+            p = pool;
+        }
 	len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
-		"(%d)%s: ", status, strerror(status));
+		"(%d)%s: ", status, ap_strerror(status, p));
     }
 
     len += ap_vsnprintf(errstr + len, MAX_STRING_LEN - len, fmt, args);
@@ -441,7 +451,18 @@
     va_list args;
 
     va_start(args, fmt);
-    log_error_core(file, line, level, status, s, NULL, fmt, args);
+    log_error_core(file, line, level, status, s, NULL, NULL, fmt, args);
+    va_end(args);
+}
+
+API_EXPORT(void) ap_log_perror(const char *file, int line, int level,
+			      ap_status_t status, ap_pool_t *p, 
+                              const char *fmt, ...)
+{
+    va_list args;
+
+    va_start(args, fmt);
+    log_error_core(file, line, level, status, NULL, NULL, p, fmt, args);
     va_end(args);
 }
 
@@ -452,7 +473,7 @@
     va_list args;
 
     va_start(args, fmt);
-    log_error_core(file, line, level, status, r->server, r, fmt, args);
+    log_error_core(file, line, level, status, r->server, r, NULL, fmt, args);
     /*
      * IF the error level is 'warning' or more severe,
      * AND there isn't already error text associated with this request,
@@ -537,7 +558,7 @@
     va_list args;
     
     va_start(args, fmt);
-    log_error_core(APLOG_MARK, APLOG_ERR, errno, s, NULL, fmt, args);
+    log_error_core(APLOG_MARK, APLOG_ERR, errno, s, NULL, NULL, fmt, args);
     va_end(args);
 }
 


_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Mime
View raw message