Issue Details (XML | Word | Printable)

Key: MODPYTHON-170
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Graham Dumpleton
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

Allow access to request_rec/server_rec/conn_rec/filter_rec as Python CObject.

Created: 07/May/06 07:31 AM   Updated: 17/Apr/07 10:47 AM
Return to search
Component/s: core
Affects Version/s: None
Fix Version/s: 3.3.1

Time Tracking:
Not Specified

Resolution Date: 03/Dec/06 04:37 AM


 Description  « Hide
At the moment, if mod_python doesn't expose a feature of Apache that you may want to use, you are stuffed and either have to convince mod_python maintainers to add it, patch your mod_python or create a Python loadable module that builds against both mod_python headers and Apache headers.

In the latter, it needs access to mod_python headers so as to be able to look inside the mod_python requestobject to get at the request_rec Apache structure. In practice, the only thing from the mod_python requestobject that such a extension module is going to want, is the request_rec structure, thus it is probably simpler and makes building such an extension easier, if the mod_python requestobject provided a "request_rec" attribute which was a Python CObject wrapper which wrapped the C request_rec pointer. Similarly, access to server_rec/conn_rec/filter_rec could also be provided.

For example, you might have a C extension function like:

typedef int (*ssl_is_https_t)(conn_rec*);

static PyObject* is_https(PyObject* module, PyObject* args)
{
  PyObject* req_object = 0;
  request_rec* req;
  ssl_is_https_t ssl_is_https = 0;
  int result = 0;

  if (!PyArg_ParseTuple(args,"O",&req_object))
    return 0;

  if (! PyCObject_Check(req_object))
    PyErr_SetString(PyExc_TypeError,"not a CObject");

  req = PyCObject_AsVoidPtr(req_object);

  ssl_is_https = (ssl_is_https_t)apr_dynamic_fn_retrieve("ssl_is_https");

  if (ssl_is_https == 0)
    return Py_BuildValue("i",0);

  result = ssl_is_https(req->connection);

  return Py_BuildValue("i",result);
}

The call to this form Python code would be:

import myextension

def handler(req):
    if myextension.is_https(req.request_rec):
       ...

Note that something like this was posted some time back:

  http://www.modpython.org/pipermail/mod_python/2006-February/020340.html

but the problem with it was that it needed the mod_python header files when compiling. Using the Python CObject avoids that. Any Python distutils setup.py file still needs to know where the Apache header files etc are, but it can use apxs to get that.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Graham Dumpleton added a comment - 03/Dec/06 04:31 AM
With possible howls of protest, I'm going to add this in for 3.3 except that only doing it for request, server and connection objects. At this point it doesn't make sense to do it for filter objects as how mod_python sets up a bucket brigade probably makes it pointless as that bucket brigade may interfere. I will call the members _request_rec, _server_rec and _conn_rec. The leading underscore is to indicate they are semi private feature and not for normal use.

Sorry, just couldn't resist in putting this in now as have some quite amazing stuff working which requires getting proper access to the underlying Apache structures. I would like other people to be able to experiment with this stuff without hacking mod_python first. :-)

Graham Dumpleton made changes - 03/Dec/06 04:31 AM
Field Original Value New Value
Fix Version/s 3.3 [ 12310101 ]
Graham Dumpleton made changes - 03/Dec/06 04:32 AM
Status Open [ 1 ] In Progress [ 3 ]
Repository Revision Date User Message
ASF #481717 Sun Dec 03 04:36:37 UTC 2006 grahamd (MODPYTHON-170) Added req._request_rec, server._server_rec and
conn._conn_rec semi private members for getting accessing to underlying
Apache struct as a Python CObject. These can be used for use in
implementing SWIG bindings for lower level APIs of Apache. These members
should be regarded as experimental and there are no guarantees that they
will remain present in this specific form in the future.
Files Changed
MODIFY /httpd/mod_python/trunk/src/serverobject.c
MODIFY /httpd/mod_python/trunk/src/requestobject.c
MODIFY /httpd/mod_python/trunk/src/connobject.c
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/__init__.py
MODIFY /httpd/mod_python/trunk/Doc/appendixc.tex
MODIFY /httpd/mod_python/trunk/src/include/mpversion.h

Graham Dumpleton made changes - 03/Dec/06 04:37 AM
Resolution Fixed [ 1 ]
Status In Progress [ 3 ] Resolved [ 5 ]
Graham Dumpleton made changes - 17/Apr/07 10:47 AM
Status Resolved [ 5 ] Closed [ 6 ]