You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by gr...@apache.org on 2006/03/15 08:48:51 UTC

svn commit: r385992 - in /httpd/mod_python/trunk: lib/python/mod_python/__init__.py src/include/mpversion.h src/mod_python.c

Author: grahamd
Date: Tue Mar 14 23:48:48 2006
New Revision: 385992

URL: http://svn.apache.org/viewcvs?rev=385992&view=rev
Log:
Fix SSI suppport so that it compiles and works on Apache 2.2. Fix issue
in SSI where Python code still executed in false part of conditional.
Also remove calls to release interpreter being done prior to interpreter
having been acquired by SSI code in the first place. (MODPYTHON-104)

Modified:
    httpd/mod_python/trunk/lib/python/mod_python/__init__.py
    httpd/mod_python/trunk/src/include/mpversion.h
    httpd/mod_python/trunk/src/mod_python.c

Modified: httpd/mod_python/trunk/lib/python/mod_python/__init__.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/lib/python/mod_python/__init__.py?rev=385992&r1=385991&r2=385992&view=diff
==============================================================================
--- httpd/mod_python/trunk/lib/python/mod_python/__init__.py (original)
+++ httpd/mod_python/trunk/lib/python/mod_python/__init__.py Tue Mar 14 23:48:48 2006
@@ -20,5 +20,5 @@
 __all__ = ["apache", "cgihandler", "psp",
            "publisher", "util", "python22"]
 
-version = "3.3.0-dev-20060312"
+version = "3.3.0-dev-20060315"
 

Modified: httpd/mod_python/trunk/src/include/mpversion.h
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/include/mpversion.h?rev=385992&r1=385991&r2=385992&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mpversion.h (original)
+++ httpd/mod_python/trunk/src/include/mpversion.h Tue Mar 14 23:48:48 2006
@@ -1,5 +1,5 @@
 #define MPV_MAJOR 3
 #define MPV_MINOR 3
 #define MPV_PATCH 0
-#define MPV_BUILD 20060312
-#define MPV_STRING "3.3.0-dev-20060312"
+#define MPV_BUILD 20060315
+#define MPV_STRING "3.3.0-dev-20060315"

Modified: httpd/mod_python/trunk/src/mod_python.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/mod_python.c?rev=385992&r1=385991&r2=385992&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/mod_python.c (original)
+++ httpd/mod_python/trunk/src/mod_python.c Tue Mar 14 23:48:48 2006
@@ -1533,8 +1533,158 @@
  ** handle_python
  **
  *    handler function for mod_include tag
+ *
+ *    The mod_include tag handler interface changed somewhere
+ *    between Apache 2.0 and Apache 2.2. Not sure what the
+ *    official way of detecting change point is, so look for
+ *    the SSI_CREATE_ERROR_BUCKET macro as indication that
+ *    new interface should be used. Provide a completely
+ *    separate implementation for now until determine whether
+ *    the SSI_CREATE_ERROR_BUCKET macro can be replicated for
+ *    backward compatibility.
  */
 
+#if defined(SSI_CREATE_ERROR_BUCKET)
+
+static apr_status_t handle_python(include_ctx_t *ctx,
+                                  ap_filter_t *f,
+                                  apr_bucket_brigade *bb) {
+
+    py_config *conf;
+    const char *interp_name = NULL;
+    interpreterdata *idata;
+    requestobject *request_obj;
+    PyObject *resultobject = NULL;
+    filterobject *filter;
+    apr_bucket *tmp_buck;
+
+    char *file = f->r->filename;
+    char *tag = NULL;
+    char *tag_val = NULL;
+
+    PyObject *tagobject = NULL;
+    PyObject *codeobject = NULL;
+
+    request_rec *req = f->r;
+
+    if (!(ctx->flags & SSI_FLAG_PRINTING)) {
+        return APR_SUCCESS;
+    }
+
+    if (ctx->flags & SSI_FLAG_NO_EXEC) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
+                      "#python used but not allowed in %s", file);
+
+        SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
+        return APR_SUCCESS;
+    }
+
+    /* process tags */
+    while (1) {
+        optfn_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1);
+
+        if (!tag || !tag_val)
+            break;
+
+        if (!strlen(tag_val)) {
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
+                          "empty value for '%s' parameter to tag 'python' in %s",
+                          tag, file);
+
+            SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
+            Py_XDECREF(tagobject);
+            Py_XDECREF(codeobject);
+            return APR_SUCCESS;
+        }
+
+        if (!strcmp(tag, "eval") || !strcmp(tag, "exec")) {
+            if (tagobject) {
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
+                              "multiple 'eval/exec' parameters to tag 'python' in %s",
+                              file);
+
+                SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
+                Py_XDECREF(tagobject);
+                Py_XDECREF(codeobject);
+                return APR_SUCCESS;
+            }
+
+            tagobject = PyString_FromString(tag);
+            codeobject = PyString_FromString(tag_val);
+        } else {
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
+                          "unexpected '%s' parameter to tag 'python' in %s",
+                          tag, file);
+
+            SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
+            Py_XDECREF(tagobject);
+            Py_XDECREF(codeobject);
+            return APR_SUCCESS;
+        }
+    }
+
+    if (!tagobject) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
+                      "missing 'eval/exec' parameter to tag 'python' in %s",
+                      file);
+
+        SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
+        return APR_SUCCESS;
+    }
+
+    /* get configuration */
+    conf = (py_config *) ap_get_module_config(req->per_dir_config, 
+                                              &python_module);
+
+    /* determine interpreter to use */
+    interp_name = select_interp_name(req, NULL, conf, NULL, f->frec->name, 0);
+
+    /* get/create interpreter */
+    idata = get_interpreter(interp_name, req->server);
+   
+    if (!idata) {
+        ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, req,
+                      "handle_python: Can't get/create interpreter.");
+
+        Py_XDECREF(tagobject);
+        Py_XDECREF(codeobject);
+        release_interpreter();
+        return HTTP_INTERNAL_SERVER_ERROR;
+    }
+
+    /* create/acquire request object */
+    request_obj = get_request_object(req, interp_name, 0);
+
+    /* create filter */
+    filter = (filterobject *)MpFilter_FromFilter(f, bb, 0, 0, 0, 0, 0);
+
+    Py_INCREF(request_obj);
+    filter->request_obj = request_obj;
+
+    /* 
+     * Here is where we call into Python!
+     */
+    resultobject = PyObject_CallMethod(idata->obcallback,
+            "IncludeDispatch", "OOO", filter, tagobject, codeobject);
+
+    if (!resultobject)
+    {
+        SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
+        release_interpreter();
+        return APR_SUCCESS;
+    }
+
+    /* clean up */
+    Py_XDECREF(resultobject);
+
+    /* release interpreter */
+    release_interpreter();
+    
+    return filter->rc;
+}
+
+#else
+
 static apr_status_t handle_python(include_ctx_t *ctx,
                                   apr_bucket_brigade **bb,
                                   request_rec *r_bogus,
@@ -1557,20 +1707,18 @@
     PyObject *tagobject = NULL;
     PyObject *codeobject = NULL;
 
-    /* prepare for 2.2 - get everything from f */
     request_rec *req = f->r;
 
-    /* check for Options +IncludesNOEXEC */
-    if (ctx->flags & FLAG_PRINTING) {
-        if (ctx->flags & FLAG_NO_EXEC) {
+    if (!(ctx->flags & FLAG_PRINTING)) {
+        return APR_SUCCESS;
+    }
 
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
-                          "#python used but not allowed in %s", file);
+    if (ctx->flags & FLAG_NO_EXEC) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
+                      "#python used but not allowed in %s", file);
 
-            CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
-            release_interpreter();
-            return APR_SUCCESS;
-        }
+        SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
+        return APR_SUCCESS;
     }
 
     /* process tags */
@@ -1588,7 +1736,6 @@
             CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
             Py_XDECREF(tagobject);
             Py_XDECREF(codeobject);
-            release_interpreter();
             return APR_SUCCESS;
         }
 
@@ -1601,12 +1748,20 @@
                 CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
                 Py_XDECREF(tagobject);
                 Py_XDECREF(codeobject);
-                release_interpreter();
                 return APR_SUCCESS;
             }
 
             tagobject = PyString_FromString(tag);
             codeobject = PyString_FromString(tag_val);
+        } else {
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
+                          "unexpected '%s' parameter to tag 'python' in %s",
+                          tag, file);
+
+            CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
+            Py_XDECREF(tagobject);
+            Py_XDECREF(codeobject);
+            return APR_SUCCESS;
         }
     }
 
@@ -1616,7 +1771,6 @@
                       file);
 
         CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
-        release_interpreter();
         return APR_SUCCESS;
     }
 
@@ -1671,6 +1825,7 @@
     return filter->rc;
 }
 
+#endif
 
 /**
  ** directive_PythonImport



Re: svn commit: r385992 - in /httpd/mod_python/trunk: lib/python/mod_python/__init__.py src/include/mpversion.h src/mod_python.c

Posted by André Malo <nd...@perlig.de>.
* grahamd@apache.org wrote:

>   **
>   *    handler function for mod_include tag
> + *
> + *    The mod_include tag handler interface changed somewhere
> + *    between Apache 2.0 and Apache 2.2. Not sure what the
> + *    official way of detecting change point is, so look for
> + *    the SSI_CREATE_ERROR_BUCKET macro as indication that
> + *    new interface should be used. Provide a completely
> + *    separate implementation for now until determine whether
> + *    the SSI_CREATE_ERROR_BUCKET macro can be replicated for
> + *    backward compatibility.
>   */

mod_include was completely refactored for 2.2 and changed its external API
(and ABI) during this step. The reason was, that the API before exposed too
many internal details, which made silent refactoring impossible. At this
point it was changed to fix these mistakes and go on with the refactoring :)

Anyway. The official way to determine such changes is the module magic number
in ap_mmn.h. There's a major MMN and a minor MMN. The major MMN bumps for
backward incompatiblity and the minor number for forward compatibility
(e.g. new functions).

And there you'll find:

 * 20030821 (2.1.0-dev) bumped mod_include's entire API

You can use the macros in ap_mmn.h to determine the version of the code.

nd