Add initial work on WSGI support in the web server.
[bbaumbach/samba-autobuild/.git] / source4 / web_server / wsgi.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Samba utility functions
4    Copyright © Jelmer Vernooij <jelmer@samba.org> 2008
5
6    Implementation of the WSGI interface described in PEP0333 
7    (http://www.python.org/dev/peps/pep-0333)
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "includes.h"
24 #include <Python.h>
25
26 static PyObject *start_response(PyObject *args, PyObject *kwargs)
27 {
28         PyObject *response_header, *exc_info;
29         char *status;
30         const char *kwnames[] = {
31                 "status", "response_header", "exc_info", NULL
32         };
33
34         if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *)"sOO:start_response", (char **)kwnames, &status, &response_header, &exc_info)) {
35                 return NULL;
36         }
37
38         /* FIXME: response_header, exc_info */
39
40         /* FIXME: Wrap stdout */
41         return NULL;
42 }
43
44 static PyObject *create_environ(void)
45 {
46         PyObject *env, *osmodule, *osenviron;
47
48         osmodule = PyImport_ImportModule("os"); 
49         if (osmodule == NULL)
50                 return NULL;
51
52         osenviron = PyObject_CallMethod(osmodule, "environ", NULL);
53
54         env = PyDict_Copy(osenviron);
55
56         PyDict_SetItemString(env, "wsgi.input", NULL); /* FIXME */
57         PyDict_SetItemString(env, "wsgi.errors", NULL); /* FIXME */
58         PyDict_SetItemString(env, "wsgi.version", Py_BuildValue("(i,i)", 1, 0));
59         PyDict_SetItemString(env, "wsgi.multithread", Py_False);
60         PyDict_SetItemString(env, "wsgi.multiprocess", Py_True);
61         PyDict_SetItemString(env, "wsgi.run_once", Py_False);
62
63         /* FIXME: 
64         PyDict_SetItemString(env, "wsgi.url_scheme", "http");
65         PyDict_SetItemString(env, "wsgi.url_scheme", "https");
66         */
67
68         return env;
69 }