SSL-data access from verious handlers. was: Re:[mod_python] problem w/ authen handler

Bud P. Bruegger bud at
Fri Feb 17 09:26:49 EST 2006

Graham Dumpleton wrote ..
 > The macros supposedly try and make it type safe, so haven't quite worked
 > out how you are meant to use them yet. In part it looks like compile time
 > binding is required, which would be an issue with Python. What you might
 > be able to do though is write a little C based Python module which did
 > the lookup and calling of "ssl_var_lookup()" for you by going direct to
 > the Apache runtime library calls. May work. :-)

See if you can get the attached code (2 files) to work for you. You will 
need to
modify the to point to appropriate include and library directories and
correct name for APR libraries on your platform.

The code all compiles, but since I don't have mod_ssl setup I get back nothing.
The first argument to each method must be the request object. It will crash if
it isn't as haven't been able to have check in code that it is in fact a 
object because undefined as am not linking against mod_python .so.

The handler I was using was as follows, but you should be able to adapt it.

import _mp_mod_ssl
import vampire

class _Object:

   def is_https(self,req):
     return _mp_mod_ssl.is_https(req)

   def var_lookup(self,req,name):
     return _mp_mod_ssl.var_lookup(req,name)

handler = vampire.Publisher(_Object())

Let me know how you go. Is an interesting problem which is why I decided
to play with it when I should have been doing real work. :-)


Ing. Bud P. Bruegger, Ph.D.                 +39-0564-488577 
(voice),  -21139 (fax)
Servizio Elaborazione Dati                    e-mail:  bud at
Comune di Grosseto                            jabber:  bud at
Via Ginori, 
58100 Grosseto (Tuscany, 
-------------- next part --------------
#include <Python.h>

#include <apr.h>
#include <mod_python.h>

typedef int (*ssl_is_https_t)(conn_rec*);

static PyObject* is_https(PyObject* module, PyObject* args)
  requestobject* request_object = 0;
  ssl_is_https_t ssl_is_https = 0;
  int result = 0;

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

#if 0
  /* How to ensure symbol is resolved. */
  if (!MpRequest_Check(request_object))
    PyErr_SetString(PyExc_TypeError,"not a request 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(request_object->request_rec->connection);

  return Py_BuildValue("i",result);

typedef char* (*ssl_var_lookup_t)(apr_pool_t*,
 server_rec*, conn_rec*, request_rec*, char*);

static PyObject* var_lookup(PyObject* module, PyObject* args)
  requestobject* request_object = 0;
  char* variable_name = 0;
  ssl_var_lookup_t ssl_var_lookup = 0;
  char* variable_value = 0;
  PyObject* result = 0;

  if (!PyArg_ParseTuple(args,"Os",&request_object,&variable_name))
    return 0;

#if 0
  /* How to ensure symbol is resolved. */
  if (!MpRequest_Check(request_object))
    PyErr_SetString(PyExc_TypeError,"not a request object");

  ssl_var_lookup = (ssl_var_lookup_t)apr_dynamic_fn_retrieve("ssl_var_lookup");

  if (ssl_var_lookup == 0)
    return Py_None;

  variable_value = ssl_var_lookup(

  result = Py_BuildValue("s",variable_value);


  return result;

static struct PyMethodDef mp_mod_ssl_methods[] = {
  { "is_https", is_https, 1 },
  { "var_lookup", var_lookup, 1 },
  { NULL, NULL },

void init_mp_mod_ssl(void)
  PyObject* module;

  module = Py_InitModule("_mp_mod_ssl",mp_mod_ssl_methods);

  if (module == 0)
    Py_FatalError("can't initialise module _mp_mod_ssl");
-------------- next part --------------
A non-text attachment was scrubbed...
Type: application/octet-stream
Size: 605 bytes
Desc: not available
Url : http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20060217/befe5232/setup.obj

More information about the Mod_python mailing list