You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by rb...@covalent.net on 2000/04/19 19:19:34 UTC

ap_strerror implementation..

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
-------------------------------------------------------------------------------


Re: ap_strerror implementation..

Posted by rb...@covalent.net.
> Why not const char * instead of char *?

because you didn't have const in your last post, and I didn't think about
why you didn't.  I added const already, and it will be in the actual
commit.

> 
> Why make a copy of "APR does not understand this error code"? (I guess
> because your return value is char *)  Are you going to want to make
> copies of strings for APR messages too?

Because I didn't have const in there before.  This problem is already
solved.  No, the APR messages are not copied, they are const now.

> 
> Why include a Win32 implementation in the same file as the Unix
> implementation?  "Everybody" agrees with the proper segregation of
> implementation.  The mailing list archives are full of people speaking
> up in favor of that.

Because this is segregated using a simple macro, and you were correct when
you pointed out that adding a new file for a single call to a system
dependant function is too much overhead for new programmers.  If we really
want to segregate in new C files, then we can just create a new C file
than implements SYS_ERR_STRING().

> Why not include a Win32 implementation that is closer to working (or
> was GetErrorString() added after VC++ 5.0)?  I posted one a while back.  

Because I don't have a Windows box that has a compiler on it right now,
and I'm not going to try to add real code without one.  I was providing a
structure that will allow somebody with a Windows box to fix this easily
once it is committed.  I didn't really feel like digging through all of my
back messages to find the patch that had the actual function right
now.  It is much faster to show somebody with a Windows box where the code
belongs than to try to code it myself without a box.

I have just changed it to be #error "not implemented yet" just like the
rest of them though.

Ryan

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


Re: ap_strerror implementation..

Posted by Jeff Trawick <tr...@bellsouth.net>.
> char *ap_strerror(ap_status_t statcode, ap_pool_t *p)
> {
>     if (statcode < APR_OS_START_ERROR) {
>         return strerror(statcode);
>     }
>     else if (statcode < APR_OS_START_USEERR) {
>         return apr_error_string(statcode);
>     }
>     else if (statcode < APR_OS_START_SYSERR) {
>         char *errstr = ap_pstrdup(p, 
>                                    "APR does not understand this error code");
>         return errstr;
>     }
>     else {
>         char *errstr;
>         SYS_ERR_STRING(statcode - APR_OS_START_SYSERR, p);
>         return errstr;
>     }
> }

Why not const char * instead of char *?

Why make a copy of "APR does not understand this error code"? (I guess
because your return value is char *)  Are you going to want to make
copies of strings for APR messages too?

Why include a Win32 implementation in the same file as the Unix
implementation?  "Everybody" agrees with the proper segregation of
implementation.  The mailing list archives are full of people speaking
up in favor of that.

Why not include a Win32 implementation that is closer to working (or
was GetErrorString() added after VC++ 5.0)?  I posted one a while back.  

-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Re: ap_strerror implementation..

Posted by rb...@covalent.net.
On Thu, 20 Apr 2000, Ben Laurie wrote:

> rbb@covalent.net wrote:
> >     case (APR_ENOPOOL):
> >     case (APR_ENOFILE):
> >     case (APR_EBADDATE):
> >     case (APR_ENOCONT):
> 
> etc. ad nauseam...
> 
> Blech! Please, no brackets!

They were removed in the actual commit.

Ryan

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


Re: ap_strerror implementation..

Posted by Ben Laurie <be...@algroup.co.uk>.
rbb@covalent.net wrote:
>     case (APR_ENOPOOL):
>     case (APR_ENOFILE):
>     case (APR_EBADDATE):
>     case (APR_ENOCONT):

etc. ad nauseam...

Blech! Please, no brackets!

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html

Re: [PATCH 2.0] WinBuild - The End of the long and winding discussion (I hope!)

Posted by Bill Stoddard <st...@raleigh.ibm.com>.
> > > our coding (there seems to be many bad Win32 CGI things going on!)
> >
> > What are you seeing? I am pretty familier with the code so
> > maybe it is a
> > quick fix. At one time is was working reasonable well but I
> > may have broken
> > it with the non-blocking pipes.
>
> Specifically, .bat files (without a shebang, which they shouldn't
> require), won't work.  I've created a little echoline to toss
> newlines at the console, and tried to launch the following:
>

Ahh, okay. Yes, there is a lot that could be done better when it comes to supporting Win32
isms.

Bill


RE: [PATCH 2.0] WinBuild - The End of the long and winding discussion (I hope!)

Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
> > our coding (there seems to be many bad Win32 CGI things going on!)
> 
> What are you seeing? I am pretty familier with the code so 
> maybe it is a
> quick fix. At one time is was working reasonable well but I 
> may have broken
> it with the non-blocking pipes.

Specifically, .bat files (without a shebang, which they shouldn't
require), won't work.  I've created a little echoline to toss 
newlines at the console, and tried to launch the following:

@ECHO OFF
echo Content-type: text/plain
echoline
echo CGI/1.0 test script report:
echoline
echo argc is $#. argv is "$*".
echoline
echo SERVER_SOFTWARE = %SERVER_SOFTWARE%
echo SERVER_NAME = %SERVER_NAME%
echo GATEWAY_INTERFACE = %GATEWAY_INTERFACE%
echo SERVER_PROTOCOL = %SERVER_PROTOCOL%
echo SERVER_PORT = %SERVER_PORT%
echo REQUEST_METHOD = %REQUEST_METHOD%
echo HTTP_ACCEPT = %HTTP_ACCEPT%
echo PATH_INFO = %PATH_INFO%
echo PATH_TRANSLATED = %PATH_TRANSLATED%
echo SCRIPT_NAME = %SCRIPT_NAME%
echo QUERY_STRING = %QUERY_STRING%
echo REMOTE_HOST = %REMOTE_HOST%
echo REMOTE_ADDR = %REMOTE_ADDR%
echo REMOTE_USER = %REMOTE_USER%
echo AUTH_TYPE = %AUTH_TYPE%
echo CONTENT_TYPE = %CONTENT_TYPE%
echo CONTENT_LENGTH = %CONTENT_LENGTH%

It fails horribly.

I've walked the code path and am 80% sure what's left to be done.
BTW - it's mapped with AddHandler cgi-script .bat

This should have been a no brainer.  But of course we can't directly
launch it.

This is what I have so far... but it's far from complete...


Index: apache-2.0/src/main/http_core.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/main/http_core.c,v
retrieving revision 1.48
diff -u -r1.48 http_core.c
--- http_core.c	2000/04/14 15:58:55	1.48
+++ http_core.c	2000/04/19 23:01:18
@@ -853,8 +853,11 @@
     }
     ext = strrchr(exename, '.');
 
+    /* Todo - WRONG - not eFileTypeEXE32 but eFileTypeSCRIPT */
     if (ext && (!strcasecmp(ext,".bat") || !strcasecmp(ext,".cmd"))) {
-        return eFileTypeEXE32;
+        *interpreter = ap_pstrcat(r->pool, getenv("COMSPEC"), " /c ", NULL);
+        if (*interpreter)
+            return eFileTypeSCRIPT;
     }
 
     /* If the file has an extension and it is not .com and not .exe and

Of course there is more too it than this... it's wigged.

I'll finish it later this week, if someone else (hint hint) will clean
up what I've already thrown up unopposed.  And yes, I noted the one
objection to having a static library at all, and almost capitulated,
until I remembered there is -no friggin way- we will run install.dll
against an apr.lib, and that's our own module.

I'm dead set against -ever again- calling the same source code into
multiple projects, as install.dll and the support tree has done in
the past.  Link to libraries, easy as that.

By the way, when you try this patch (not the cgi - the aprlib/aprlibdll)
and don't finally fix the string exports, you will see it crash and
burn.  I've harped that fix a few times :-)

RE: CGI workups (was WinBuild)

Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
> From: Bill Stoddard [mailto:stoddard@raleigh.ibm.com]
> Sent: Thursday, April 20, 2000 9:53 AM
> 
> > our coding (there seems to be many bad Win32 CGI things going on!)
> 
> What are you seeing? I am pretty familier with the code so 
> maybe it is a
> quick fix. At one time is was working reasonable well but I 
> may have broken
> it with the non-blocking pipes.

My other biggie is to create a mapping table function to allow
administrators to quickly map, say, all /usr/bin/perl to 
/home/usr/bin/perl (or for windows folks, map /usr/bin/perl
to c:\program files\perl\bin\perl :-)

This is a big hangup I have provided all the websites I cross
test and code for... when silly things like that change alot
I'm always forgetting to trip it.

I'm also less than pleased with any of the registry handling
stuff, since everything after the %1 script name argument is
lopped off (and may be critical, such as a perl switch).  
I'd also like to see an override (or exclusive control) option 
within the registry, to override today's options:

HKEY_CLASSES_ROOT
    \perlfile
         \shell
              \open
                   \command  commandstring

with something like

HKEY_CLASSES_ROOT
    \perlfile
         \shell (possibly httpd or apache instead)
              \ExecCGI
                   \command  commandstring

which would allow web admins not to worry about people trying
to serve up .doc files with notepad :-)  The advantage to 
keeping shell is that they could edit these with the Windows
Explorer options dialog.

Just ideas I'm playing with.

Re: [PATCH 2.0] WinBuild - The End of the long and winding discussion (I hope!)

Posted by Bill Stoddard <st...@raleigh.ibm.com>.
> our coding (there seems to be many bad Win32 CGI things going on!)

What are you seeing? I am pretty familier with the code so maybe it is a
quick fix. At one time is was working reasonable well but I may have broken
it with the non-blocking pipes.

Bill


RE: [PATCH 2.0] WinBuild - The End of the long and winding discussion (I hope!)

Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
> From: William A. Rowe, Jr. [mailto:wrowe@lnd.com]
> Sent: Wednesday, April 19, 2000 9:15 PM
> 
> Ok... here is my final patch to the overall project structure,
> let's put this thing to bed so I and others can move on with
> our coding (there seems to be many bad Win32 CGI things going on!)
> 
How could I forget :-)

7) Eliminate -ALL- makefiles from distribution.  Modify the
   win_compiling.html doc to that effect.

TODO: Change build notes to inform Win32 roller that the release
      requires all .mak files to be exported to the .zip package 
      from the Apache.dsw workspace, for those with less than
      sufficient skill to try this themselves.


RE: [PATCH 2.0] WinBuild - The End of the long and winding discussion (I hope!)

Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
One minor ommission...  

-- New file src/lib/apr/misc/win32/aprlib.c --
/*
 * Placeholder to force aprlib.dll creation with no LNK4001 error
 *
 * However, this isn't a bad place to store dynamic-only functions 
 * that determine which version of apr the application has loaded.
 * These functions are of (less?) importance to static-bound apps.
 */
-- End of new src/lib/apr/misc/win32/aprlib.c --


[PATCH 2.0] WinBuild - The End of the long and winding discussion (I hope!)

Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
Ok... here is my final patch to the overall project structure,
let's put this thing to bed so I and others can move on with
our coding (there seems to be many bad Win32 CGI things going on!)

Please commit it... other's are welcome to build on this.
I do have one patch once this is committed... I will fix
the htdigest/logresolve modules to build on Win32, and
the htpasswd to build on apr (if it doesn't already).
That should make us ready for a -good- Win32 alpha!

1) Implement new src/os/win32/BaseAddr.ref for all offsets.
   Addresses concerns that binaries should be consistent from
   build to build, base addresses are centralized in a single
   file, and relocations won't be an issue.

2) aprlib.dsp becomes a static library in src/lib/apr/Lib[D|R].
   All apr source remains in this project, to minimize confusion.
   aprlib.def must move to the actual dll project. Standalone
   executables (p/w support and install files) and other binaries
   using a -minimal- set of functions may link here.

3) Move gen_test_char.exe and gen_uri_delim.exe pipes into the
   ApacheCore project, as custom actions, not post build steps.
   See success in apr.hw->apr.h custom actions.  This eliminates
   extra cleanup from makefile.win.

4) Implement new src/lib/apr/aprlibdll.dsp to build the actual
   aprlib.dll.  The location remains src/lib/apr/[Debug|Release],
   and the aprlib.def file moves into this project.  Only the
   empty src/lib/apr/misc/win32/aprlib.c source file is included
   to eliminate compiler warning of no objects to link.

5) Implement new src/InstallBin.dsp to wrap the makefile.win for
   the copy functions.  Default INSTDIR folder is set to ../ to
   simplify building and installing multiple versions or deveopment
   iterations, but this may be changed by the user to simplify
   their life.

6) Create the src/Apache.dsw workspace.  The top target is
   InstallBin.dsp, which carries dependencies on all projects.
   Each project is dependent on the libraries and modules it
   links to.  There must be no dependencies on broken sources
   (htdigest, logresolve, ApacheModuleProxy and ApacheModuleInfo).

------------------

The two patches for htdigest and logresolve will drop in tommorow.

The advantage to aprlib/aprlibdll is that the library is always
called aprlib.lib, just link to the correct folder for your
desired result (LibD/LibR/Debug/Release).

BTW - don't overthink this... if you would rather see apr.lib/apr.dll
wait for this patch to be applied, then propose it as it's own patch.
I didn't change the name of this project since I felt that was it's
own issue.  I also didn't add, but support, Greg's build directory
tree overhaul.  That too should be a seperate patch.

I KNOW this patch will be harder to review.  This is the diff between
the aprlib.dsp and aprlibdll.dsp, since aprlibdsp was cloned from the
aprlib settings, and you won't waste as much time reviewing the new
aprlibdll.dsp file...

--- d:aprlib.dsp	Mon Apr 17 13:20:43 2000
+++ aprlibdll.dsp	Wed Apr 19 17:39:38 2000
@@ -1,24 +1,26 @@
-# Microsoft Developer Studio Project File - Name="aprlib" - Package Owner=<4>
+# Microsoft Developer Studio Project File - Name="aprlibdll" - Package Owner=<4>
 # Microsoft Developer Studio Generated Build File, Format Version 5.00
 # ** DO NOT EDIT **

 # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102

-CFG=aprlib - Win32 Debug
+CFG=aprlibdll - Win32 Debug
 !MESSAGE This is not a valid makefile. To build this project using NMAKE,
 !MESSAGE use the Export Makefile command and run
 !MESSAGE
-!MESSAGE NMAKE /f "aprlib.mak".
+!MESSAGE NMAKE /f "aprlibdll.mak".
 !MESSAGE
 !MESSAGE You can specify a configuration when running NMAKE
 !MESSAGE by defining the macro CFG on the command line. For example:
 !MESSAGE
-!MESSAGE NMAKE /f "aprlib.mak" CFG="aprlib - Win32 Debug"
+!MESSAGE NMAKE /f "aprlibdll.mak" CFG="aprlibdll - Win32 Debug"
 !MESSAGE
 !MESSAGE Possible choices for configuration are:
 !MESSAGE
-!MESSAGE "aprlib - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "aprlib - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "aprlibdll - Win32 Release" (based on\
+ "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "aprlibdll - Win32 Debug" (based on\
+ "Win32 (x86) Dynamic-Link Library")
 !MESSAGE

 # Begin Project
@@ -28,7 +30,7 @@
 MTL=midl.exe
 RSC=rc.exe

-!IF  "$(CFG)" == "aprlib - Win32 Release"
+!IF  "$(CFG)" == "aprlibdll - Win32 Release"

 # PROP BASE Use_MFC 0
 # PROP BASE Use_Debug_Libraries 0
@@ -52,10 +54,10 @@
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo
 LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib /nologo /base:"0x278A0000" /subsystem:windows /dll /map
/machine:I386
-# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib /nologo /base:"0x278A0000" /subsystem:windows /dll /map /machine:I386
+# ADD BASE LINK32 aprlib.lib kernel32.lib advapi32.lib ws2_32.lib mswsock.lib /nologo /base:@"..\..\os\win32\BaseAddr.ref",aprlib
/subsystem:windows /dll /map /machine:I386 /out:"Release/aprlib.dll" /libpath:"LibR"
+# ADD LINK32 aprlib.lib kernel32.lib advapi32.lib ws2_32.lib mswsock.lib /nologo /base:@"..\..\os\win32\BaseAddr.ref",aprlib
/subsystem:windows /dll /map /machine:I386 /out:"Release/aprlib.dll" /libpath:"LibR"

-!ELSEIF  "$(CFG)" == "aprlib - Win32 Debug"
+!ELSEIF  "$(CFG)" == "aprlibdll - Win32 Debug"

 # PROP BASE Use_MFC 0
 # PROP BASE Use_Debug_Libraries 1
@@ -79,320 +82,24 @@
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo
 LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib /nologo /base:"0x278A0000" /subsystem:windows /dll /map /debug
/machine:I386
-# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib /nologo /base:"0x278A0000" /subsystem:windows /dll /map /debug
/machine:I386
+# ADD BASE LINK32 aprlib.lib kernel32.lib advapi32.lib ws2_32.lib mswsock.lib /nologo /base:@"..\..\os\win32\BaseAddr.ref",aprlib
/subsystem:windows /dll /map /debug /machine:I386 /out:"Debug/aprlib.dll" /libpath:"LibD"
+# ADD LINK32 aprlib.lib kernel32.lib advapi32.lib ws2_32.lib mswsock.lib /nologo /base:@"..\..\os\win32\BaseAddr.ref",aprlib
/subsystem:windows /dll /map /debug /machine:I386 /out:"Debug/aprlib.dll" /libpath:"LibD"
 !ENDIF

 # Begin Target

 # Name "aprlibdll - Win32 Release"
 # Name "aprlibdll - Win32 Debug"
===
===[ALL SOURCES STRIPPED AND REPLACED WITH]
===
 # Begin Source File

+SOURCE=.\misc\win32\aprlib.c
 # End Source File
 # Begin Source File

 SOURCE=.\aprlib.def
 # End Source File
 # End Target
 # End Project


Re: ap_strerror implementation..

Posted by rb...@covalent.net.
> > -#include <errno.h>
> > +#include "apr_general.h"
> >  #include "apr.h"
> > +#include <errno.h>
> 
> Is errno.h always there? Should there be an APR_HAS_ERRNO_H ?
> 
> Should errno.h even be exported from apr_errno.h? (IMO: no)

Yes, errno is always provided.  We actually rely on errno being there in
most cases.  errno.h must be exported from apr_errno.h.  Otherwise, when
we want to define canonical error values, we can't.  Consider:

#ifdef EINTR
#define APR_EINTR  EINTR
#else
#define APR_EINTR  (APR_OS_CANON_ERR + 1)
#endif

> > +char *ap_strerror(ap_status_t statcode, ap_pool_t *p);
> 
> I think that I would agree with Jeff on this: make the return value
> "const" for the most flexibility of implementation.
> 
> Jeff didn't add const cuz a buffer was passed. That isn't the case here.

I left it out because Jeff left it out of his last patch.  I'll add it
back in.

> 
> > static char *apr_error_string(ap_status_t statcode)
> > {
> >     switch (statcode) {
> >     case (APR_ENOPOOL):
> >     case (APR_ENOFILE):
> >     case (APR_EBADDATE):
> >     case (APR_ENOCONT):
> >     case (APR_ENOPROC):
> >     case (APR_ENOTIME):
> >     case (APR_ENODIR):
> 
> Personal style nit: those parens are superflous syntactic sugar that is
> somewhat annoying to read through.

OK.

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



Re: ap_strerror implementation..

Posted by Greg Stein <gs...@lyra.org>.
On Wed, 19 Apr 2000 rbb@covalent.net wrote:
>...
> --- include/apr_errno.h	2000/04/08 06:58:41	1.23
> +++ include/apr_errno.h	2000/04/19 20:59:35
> @@ -52,8 +52,9 @@
>   * <http://www.apache.org/>.
>   */
>  
> -#include <errno.h>
> +#include "apr_general.h"
>  #include "apr.h"
> +#include <errno.h>

Is errno.h always there? Should there be an APR_HAS_ERRNO_H ?

Should errno.h even be exported from apr_errno.h? (IMO: no)

> --- include/apr_general.h	2000/04/16 04:46:53	1.26
> +++ include/apr_general.h	2000/04/19 20:59:35
> @@ -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
> + */
> +char *ap_strerror(ap_status_t statcode, ap_pool_t *p);

I think that I would agree with Jeff on this: make the return value
"const" for the most flexibility of implementation.

Jeff didn't add const cuz a buffer was passed. That isn't the case here.

> static char *apr_error_string(ap_status_t statcode)
> {
>     switch (statcode) {
>     case (APR_ENOPOOL):
>     case (APR_ENOFILE):
>     case (APR_EBADDATE):
>     case (APR_ENOCONT):
>     case (APR_ENOPROC):
>     case (APR_ENOTIME):
>     case (APR_ENODIR):

Personal style nit: those parens are superflous syntactic sugar that is
somewhat annoying to read through.

> char *ap_strerror(ap_status_t statcode, ap_pool_t *p)
> {
>     if (statcode < APR_OS_START_ERROR) {
>         return strerror(statcode);
>     }
>     else if (statcode < APR_OS_START_USEERR) {
>         return apr_error_string(statcode);
>     }
>     else if (statcode < APR_OS_START_SYSERR) {
>         char *errstr = ap_pstrdup(p, 
>                                    "APR does not understand this error code");

No need for a dup if you return a const string.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/


Re: ap_strerror implementation..

Posted by rb...@covalent.net.
I'm going to re-post the patch here, because I REALLY screwed up last
time.  I'll apologize now.  :-(  Jeff, thanks for pointing out that I'm an
idiot. :-)

The patch:

? misc/unix/errorcodes.c
Index: file_io/unix/dir.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/dir.c,v
retrieving revision 1.29
diff -u -d -b -w -u -r1.29 dir.c
--- file_io/unix/dir.c	2000/04/14 15:58:22	1.29
+++ file_io/unix/dir.c	2000/04/19 20:59:35
@@ -181,7 +181,7 @@
                        thedir->entry->d_name, NULL);
     if (stat(fname, &filestat) == -1) {
         *size = -1;
-        return APR_ENOSTAT;
+        return errno;
     }
     
     *size = filestat.st_size;
@@ -205,7 +205,7 @@
                        thedir->entry->d_name, NULL);
     if (stat(fname, &filestat) == -1) {
         *mtime = -1;
-        return APR_ENOSTAT;
+        return errno;
     }
     
     ap_ansi_time_to_ap_time(mtime, filestat.st_mtime);
@@ -229,7 +229,7 @@
                        thedir->entry->d_name, NULL);
     if (stat(fname, &filestat) == -1) {
         *type = APR_REG;
-        return APR_ENOSTAT;
+        return errno;
     }
 
     if (S_ISREG(filestat.st_mode))
Index: 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
--- include/apr_errno.h	2000/04/08 06:58:41	1.23
+++ include/apr_errno.h	2000/04/19 20:59:35
@@ -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: 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
--- include/apr_general.h	2000/04/16 04:46:53	1.26
+++ include/apr_general.h	2000/04/19 20:59:35
@@ -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
+ */
+char *ap_strerror(ap_status_t statcode, ap_pool_t *p);
 #ifdef __cplusplus
 }
 #endif
Index: 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
--- misc/unix/Makefile.in	2000/04/15 19:05:13	1.12
+++ misc/unix/Makefile.in	2000/04/19 20:59:39
@@ -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) $<


misc/unix/errorcode.c

/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2000 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

#include "misc.h"

#ifdef WIN32
#define SYS_ERR_STRING(code, p) \
   errstr = ap_pcalloc(p, 256); \
   GetErrorString(code, errstr, 256);
#elif OS/2
#error "not implemented yet"
#elif BEOS    
#error "not implemented yet"
#else
#define SYS_ERR_STRING(code, p) \
    errstr = strerror(code);
#endif

static char *apr_error_string(ap_status_t statcode)
{
    switch (statcode) {
    case (APR_ENOPOOL):
    case (APR_ENOFILE):
    case (APR_EBADDATE):
    case (APR_ENOCONT):
    case (APR_ENOPROC):
    case (APR_ENOTIME):
    case (APR_ENODIR):
    case (APR_ENOLOCK):
    case (APR_ENOPOLL):
    case (APR_ENOSOCKET):
    case (APR_ENOTHREAD):
    case (APR_ENOTHDKEY):
    case (APR_ENOTTHREADSAFE):
    case (APR_ESHMLOCK):
    case (APR_EFUNCNOTFOUND):
    case (APR_ENOFUNCPOINTER):
    case (APR_ENODSOHANDLE):
    case (APR_EDSOOPEN):
    case (APR_EBADARG):
    case (APR_INCHILD):
    case (APR_INPARENT):
    case (APR_DETACH):
    case (APR_NOTDETACH):
    case (APR_CHILD_DONE):
    case (APR_CHILD_NOTDONE):
    case (APR_TIMEUP):
    case (APR_INVALSOCK):
    case (APR_ALLSTD):
    case (APR_STDOUT):
    case (APR_STDERR):
    case (APR_BADCH):
    case (APR_BADARG):
    case (APR_EOF):
    case (APR_NOTFOUND):
    case (APR_LESS):
    case (APR_EQUAL):
    case (APR_MORE):
    case (APR_ANONYMOUS):
    case (APR_FILEBASED):
    case (APR_KEYBASED):
    case (APR_EINIT):
    case (APR_ENOTIMPL):
    case (APR_EMISMATCH):
    default:
        return "Error string not specified yet";
    }
}

char *ap_strerror(ap_status_t statcode, ap_pool_t *p)
{
    if (statcode < APR_OS_START_ERROR) {
        return strerror(statcode);
    }
    else if (statcode < APR_OS_START_USEERR) {
        return apr_error_string(statcode);
    }
    else if (statcode < APR_OS_START_SYSERR) {
        char *errstr = ap_pstrdup(p, 
                                   "APR does not understand this error code");
        return errstr;
    }
    else {
        char *errstr;
        SYS_ERR_STRING(statcode - APR_OS_START_SYSERR, p);
        return errstr;
    }
}

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


Re: ap_strerror implementation..

Posted by Jeff Trawick <tr...@bellsouth.net>.
+/*
+
+=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);

minor comments:

1) where is ap_strerror() prototype?  Did you mean to prototype
   ap_strerror() instead of ap_set_abort()?

2) I don't see your implementation, but if it will return strerror()
   directly on Unix and not copy into the specified pool first (or you
   want to leave open the possibility that for some platform we don't
   have to take up storage from the pool), consider returning "const
   char *" instead of "char *".  In my version, I used "char *" since
   I was returning the address of the caller's buffer and obviously
   they should be able to do whatever they want with it. 

-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...