Herewith attached the updated patch and log message.

Thanks & Regards,
Vijayaguru

On Tuesday 01 March 2011 06:30 PM, Stefan Sperling wrote:
On Tue, Mar 01, 2011 at 11:59:28AM +0530, vijay wrote:
[[[
Update log_access_verdict to make it work with httpd trunk as well as older
versions. The function is being called with APLOG_MACRO in few places.
The macro APLOG_MARK expands to 2 arguments till httpd-2.2.x but 3
arguments in httpd-2.3-dev, which causes failure while compiling with
httpd-2.3-dev. So we need to handle both the cases.

* subversion/mod_authz_svn/mod_authz_svn.c
   (log_access_verdict): Modify the signature.
Your log message should probably include this link:
http://httpd.apache.org/docs/trunk/developer/new_api_2_4.html#upgrading_logging

Patch by: Vijayaguru G<vijay{_AT_}collab.net>
Suggested by: Kameshj
]]]


Index: subversion/mod_authz_svn/mod_authz_svn.c
===================================================================
--- subversion/mod_authz_svn/mod_authz_svn.c    (revision 1075316)
+++ subversion/mod_authz_svn/mod_authz_svn.c    (working copy)
@@ -32,6 +32,7 @@
  #include<http_log.h>
  #include<ap_config.h>
  #include<ap_provider.h>
+#include<ap_release.h>
  #include<apr_uri.h>
  #include<apr_lib.h>
  #include<mod_dav.h>
@@ -519,12 +520,20 @@
    return OK;
  }

+#if AP_SERVER_MAJORVERSION_NUMBER == 2&&  AP_SERVER_MINORVERSION_NUMBER == 3
+#define LOG_ARGS_SIGNATURE const char *file, int line, int module_index
+#define LOG_ARGS_CASCADE file, line, module_index
+#else
+#define LOG_ARGS_SIGNATURE const char *file, int line
+#define LOG_ARGS_CASCADE file, line
+#endif
I don't really like a macro that expands to function parameters.
Can we do something like this instead?
This will duplicate some code, but the function is small and this way
it's a bit easier to understand what is happening at a glance.

#if AP_MODULE_MAGIC_AT_LEAST(2,3)
static void
log_access_verdict_httpd_v23(const char *file, int line,
                              const request_rec *r, int allowed,
                              const char *repos_path,
                             const char *dest_repos_path)
{
        /* code for v23 */
}
#else
static void
log_access_verdict2_httpd_v22(const char *file, int line, int module_index,
                     const request_rec *r, int allowed,
                     const char *repos_path, const char *dest_repos_path)
{
        /* code for v22 */
}
#endif

static void
log_access_verdict(const char *file, int line, int module_index,
                    const request_rec *r, int allowed,
                    const char *repos_path, const char *dest_repos_path)
{
#if AP_MODULE_MAGIC_AT_LEAST(2,3)
        /* call log_access_verdict_httpd_v23 */
#endif
        /* call log_access_verdict_httpd_v22 */
#endif
}

  /* Log a message indicating the access control decision made about a
- * request.  FILE and LINE should be supplied via the APLOG_MARK macro.
- * ALLOWED is boolean.  REPOS_PATH and DEST_REPOS_PATH are information
+ * request.  LOG_ARGS_SIGNATURE should be supplied via the APLOG_MARK macro
+ * with respect to Apache version. ALLOWED is boolean.
+ * REPOS_PATH and DEST_REPOS_PATH are information
   * about the request.  DEST_REPOS_PATH may be NULL. */
  static void
-log_access_verdict(const char *file, int line,
+log_access_verdict(LOG_ARGS_SIGNATURE,
                     const request_rec *r, int allowed,
                     const char *repos_path, const char *dest_repos_path)
  {
@@ -534,22 +543,22 @@
    if (r->user)
      {
        if (dest_repos_path)
-        ap_log_rerror(file, line, level, 0, r,
+        ap_log_rerror(LOG_ARGS_CASCADE, level, 0, r,
                        "Access %s: '%s' %s %s %s", verdict, r->user,
                        r->method, repos_path, dest_repos_path);
        else
-        ap_log_rerror(file, line, level, 0, r,
+        ap_log_rerror(LOG_ARGS_CASCADE, level, 0, r,
                        "Access %s: '%s' %s %s", verdict, r->user,
                        r->method, repos_path);
      }
    else
      {
        if (dest_repos_path)
-        ap_log_rerror(file, line, level, 0, r,
+        ap_log_rerror(LOG_ARGS_CASCADE, level, 0, r,
                        "Access %s: - %s %s %s", verdict,
                        r->method, repos_path, dest_repos_path);
        else
-        ap_log_rerror(file, line, level, 0, r,
+        ap_log_rerror(LOG_ARGS_CASCADE, level, 0, r,
                        "Access %s: - %s %s", verdict,
                        r->method, repos_path);
      }

Index: subversion/mod_authz_svn/mod_authz_svn.c
===================================================================
--- subversion/mod_authz_svn/mod_authz_svn.c    (revision 1075316)
+++ subversion/mod_authz_svn/mod_authz_svn.c    (working copy)
@@ -30,8 +30,10 @@
 #include <http_request.h>
 #include <http_protocol.h>
 #include <http_log.h>
+#include <http_config.h>
 #include <ap_config.h>
 #include <ap_provider.h>
+#include <ap_mmn.h>
 #include <apr_uri.h>
 #include <apr_lib.h>
 #include <mod_dav.h>
@@ -48,6 +50,10 @@
 
 extern module AP_MODULE_DECLARE_DATA authz_svn_module;
 
+#ifdef APLOG_USE_MODULE
+APLOG_USE_MODULE(authz_svn);
+#endif
+
 typedef struct authz_svn_config_rec {
   int authoritative;
   int anonymous;
@@ -520,11 +526,16 @@
 }
 
 /* Log a message indicating the access control decision made about a
- * request.  FILE and LINE should be supplied via the APLOG_MARK macro.
- * ALLOWED is boolean.  REPOS_PATH and DEST_REPOS_PATH are information
- * about the request.  DEST_REPOS_PATH may be NULL. */
+ * request.  As APLOG_MARK macro has been changed in httpd-2.3 for
+ * per-module loglevel configuration, it supplies FILE, LINE and MODULE_INDEX 
+ * to log_access_verdict_httpd_v23.  To make it compatible with older server
+ * versions, log_access_verdict_httpd_v22 accepts FILE and LINE via
+ * APLOG_MARK.  ALLOWED is boolean.  REPOS_PATH and DEST_REPOS_PATH are
+ * information about the request.  DEST_REPOS_PATH may be NULL. */
+
+#if AP_MODULE_MAGIC_AT_LEAST(20100606,0)
 static void
-log_access_verdict(const char *file, int line,
+log_access_verdict_httpd_v23(const char *file, int line, int module_index,
                    const request_rec *r, int allowed,
                    const char *repos_path, const char *dest_repos_path)
 {
@@ -534,6 +545,38 @@
   if (r->user)
     {
       if (dest_repos_path)
+        ap_log_rerror(file, line, module_index, level, 0, r,
+                      "Access %s: '%s' %s %s %s", verdict, r->user,
+                      r->method, repos_path, dest_repos_path);
+      else
+        ap_log_rerror(file, line, module_index, level, 0, r,
+                      "Access %s: '%s' %s %s", verdict, r->user,
+                      r->method, repos_path);
+    }
+  else
+    {
+      if (dest_repos_path)
+        ap_log_rerror(file, line, module_index, level, 0, r,
+                      "Access %s: - %s %s %s", verdict,
+                      r->method, repos_path, dest_repos_path);
+      else
+        ap_log_rerror(file, line, module_index, level, 0, r,
+                      "Access %s: - %s %s", verdict,
+                      r->method, repos_path);
+    }
+}
+#else
+static void
+log_access_verdict_httpd_v22(const char *file, int line,
+                   const request_rec *r, int allowed,
+                   const char *repos_path, const char *dest_repos_path)
+{
+  int level = allowed ? APLOG_INFO : APLOG_ERR;
+  const char *verdict = allowed ? "granted" : "denied";
+
+  if (r->user)
+    {
+      if (dest_repos_path)
         ap_log_rerror(file, line, level, 0, r,
                       "Access %s: '%s' %s %s %s", verdict, r->user,
                       r->method, repos_path, dest_repos_path);
@@ -554,6 +597,7 @@
                       r->method, repos_path);
     }
 }
+#endif
 
 /*
  * This function is used as a provider to allow mod_dav_svn to bypass the
@@ -580,7 +624,11 @@
   if (!conf->anonymous
       || (! (conf->access_file || conf->repo_relative_access_file)))
     {
-      log_access_verdict(APLOG_MARK, r, 0, repos_path, NULL);
+#if AP_MODULE_MAGIC_AT_LEAST(20100606,0)
+      log_access_verdict_httpd_v23(APLOG_MARK, r, 0, repos_path, NULL);
+#else
+      log_access_verdict_httpd_v22(APLOG_MARK, r, 0, repos_path, NULL);
+#endif
       return HTTP_FORBIDDEN;
     }
 
@@ -618,12 +666,20 @@
         }
       if (!authz_access_granted)
         {
-          log_access_verdict(APLOG_MARK, r, 0, repos_path, NULL);
+#if AP_MODULE_MAGIC_AT_LEAST(20100606,0)
+          log_access_verdict_httpd_v23(APLOG_MARK, r, 0, repos_path, NULL);
+#else
+          log_access_verdict_httpd_v22(APLOG_MARK, r, 0, repos_path, NULL);
+#endif
           return HTTP_FORBIDDEN;
         }
     }
 
-  log_access_verdict(APLOG_MARK, r, 1, repos_path, NULL);
+#if AP_MODULE_MAGIC_AT_LEAST(20100606,0)
+  log_access_verdict_httpd_v23(APLOG_MARK, r, 1, repos_path, NULL);
+#else
+  log_access_verdict_httpd_v22(APLOG_MARK, r, 1, repos_path, NULL);
+#endif
 
   return OK;
 }
@@ -677,7 +733,11 @@
         return DECLINED;
 
       if (!ap_some_auth_required(r))
-        log_access_verdict(APLOG_MARK, r, 0, repos_path, dest_repos_path);
+#if AP_MODULE_MAGIC_AT_LEAST(20100606,0)
+        log_access_verdict_httpd_v23(APLOG_MARK, r, 0, repos_path, 
dest_repos_path);
+#else
+        log_access_verdict_httpd_v22(APLOG_MARK, r, 0, repos_path, 
dest_repos_path);
+#endif
 
       return HTTP_FORBIDDEN;
     }
@@ -685,7 +745,11 @@
   if (status != OK)
     return status;
 
-  log_access_verdict(APLOG_MARK, r, 1, repos_path, dest_repos_path);
+#if AP_MODULE_MAGIC_AT_LEAST(20100606,0)
+  log_access_verdict_httpd_v23(APLOG_MARK, r, 1, repos_path, dest_repos_path);
+#else
+  log_access_verdict_httpd_v22(APLOG_MARK, r, 1, repos_path, dest_repos_path);
+#endif
 
   return OK;
 }
@@ -712,7 +776,11 @@
   if (status == OK)
     {
       apr_table_setn(r->notes, "authz_svn-anon-ok", (const char*)1);
-      log_access_verdict(APLOG_MARK, r, 1, repos_path, dest_repos_path);
+#if AP_MODULE_MAGIC_AT_LEAST(20100606,0)
+      log_access_verdict_httpd_v23(APLOG_MARK, r, 1, repos_path, 
dest_repos_path);
+#else
+      log_access_verdict_httpd_v22(APLOG_MARK, r, 1, repos_path, 
dest_repos_path);
+#endif
       return OK;
     }
 
@@ -742,7 +810,11 @@
     {
       if (conf->authoritative)
         {
-          log_access_verdict(APLOG_MARK, r, 0, repos_path, dest_repos_path);
+#if AP_MODULE_MAGIC_AT_LEAST(20100606,0)
+          log_access_verdict_httpd_v23(APLOG_MARK, r, 0, repos_path, 
dest_repos_path);
+#else
+          log_access_verdict_httpd_v22(APLOG_MARK, r, 0, repos_path, 
dest_repos_path);
+#endif
           ap_note_auth_failure(r);
           return HTTP_FORBIDDEN;
         }
@@ -752,7 +824,11 @@
   if (status != OK)
     return status;
 
-  log_access_verdict(APLOG_MARK, r, 1, repos_path, dest_repos_path);
+#if AP_MODULE_MAGIC_AT_LEAST(20100606,0)
+  log_access_verdict_httpd_v23(APLOG_MARK, r, 1, repos_path, dest_repos_path);
+#else
+  log_access_verdict_httpd_v22(APLOG_MARK, r, 1, repos_path, dest_repos_path);
+#endif
 
   return OK;
 }
[[[
Update log_access_verdict to make it work with httpd trunk as well as older
server versions with reference to [1]. The function is being called
with APLOG_MARK in few places. The macro APLOG_MARK expands to 2 arguments 
till httpd-2.2.x but 3 arguments in httpd-2.3-dev, which causes failure 
while compiling with httpd-2.3-dev. So we need to handle both the cases.
log_access_verdict_httpd_v23 is the copy of log_access_verdict with one
additional parameter module_index through which we can take the advantage of
per-module loglevel configuration introduced in httpd-2.3.
log_access_verdict_httpd_v22 is exactly same as log_access_verdict which will
help to remain compatible with older server versions. These wrapper functions
will be conditionally called in few other places with respect to httpd
version. 

* subversion/mod_authz_svn/mod_authz_svn.c
  (log_access_verdict_httpd_v23): Copy of log_access_verdict with one
   additional parameter module_index for per-module log level configuration 
   introduced in httpd-2.3.
  (log_access_verdict_httpd_v22): Renaming log_access_verdict to
   log_access_verdict_httpd_v22 to make it compatible with 
   older server versions.                                  
  (subreq_bypass, access_checker, check_user_id, auth_checker): Conditionally
   call log_access_verdict_* with respect to httpd version.
                                                           
[1] http://httpd.apache.org/docs/trunk/developer/new_api_2_4.html#upgrading_logging

Patch by: Vijayaguru G <vijay{_AT_}collab.net>
Suggested by: kameshj, stsp
]]]
                        

Reply via email to