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

Jim Gallacher jpg at jgassociates.ca
Fri Feb 17 10:31:07 EST 2006


Hi Bud,

I think it might be appropriate to move this discussion to the 
python-dev mailing list, as you are digging into the mod_python 
internals for a new feature which has not yet been implemented.

To subscribe send an email to python-dev-subscribe at httpd.apache.org
http://people.apache.org/~jgallacher/mod_python/website-test/lists.html#mp-dev

Jim

Bud P. Bruegger wrote:
> 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 setup.py 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 
> request
> 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. :-)
> 
> Graham
> 
> 
> 
> 
> ------------------------------------------------------------------------------------------------- 
> 
> Ing. Bud P. Bruegger, Ph.D.                 +39-0564-488577 (voice),  
> -21139 (fax)
> Servizio Elaborazione Dati                    e-mail:  
> bud at comune.grosseto.it
> Comune di Grosseto                            jabber:  bud at jabber.no
> Via Ginori, 43                                      
> http://www.comune.grosseto.it/cie/
> 58100 Grosseto (Tuscany, Italy)           
> http://www.comune.grosseto.it/interopEID/
> 
> 
> ------------------------------------------------------------------------
> 
> #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");
> #endif
> 
>   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");
> #endif
> 
>   ssl_var_lookup = (ssl_var_lookup_t)apr_dynamic_fn_retrieve("ssl_var_lookup");
> 
>   if (ssl_var_lookup == 0)
>   {
>     Py_XINCREF(Py_None);
>       
>     return Py_None;
>   }
> 
>   variable_value = ssl_var_lookup(
>    request_object->request_rec->pool,
>    request_object->request_rec->server,
>    request_object->request_rec->connection,
>    request_object->request_rec,
>    variable_name);
> 
>   result = Py_BuildValue("s",variable_value);
> 
>   free(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");
> }
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list