From 4bb17b60ef608b10284ccd2146c9344cc43b8637 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 21:21:07 +0200 Subject: Add initial work on WSGI support in the web server. --- source4/web_server/config.mk | 2 +- source4/web_server/wsgi.c | 69 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 source4/web_server/wsgi.c diff --git a/source4/web_server/config.mk b/source4/web_server/config.mk index 4094d6be07..810cc7f430 100644 --- a/source4/web_server/config.mk +++ b/source4/web_server/config.mk @@ -10,6 +10,6 @@ PRIVATE_DEPENDENCIES = ESP LIBTLS smbcalls process_model # End SUBSYSTEM WEB ####################### -WEB_OBJ_FILES = $(addprefix $(web_serversrcdir)/, web_server.o esp.o) +WEB_OBJ_FILES = $(addprefix $(web_serversrcdir)/, web_server.o esp.o wsgi.o) $(eval $(call proto_header_template,$(web_serversrcdir)/proto.h,$(WEB_OBJ_FILES:.o=.c))) diff --git a/source4/web_server/wsgi.c b/source4/web_server/wsgi.c new file mode 100644 index 0000000000..50f8599869 --- /dev/null +++ b/source4/web_server/wsgi.c @@ -0,0 +1,69 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright © Jelmer Vernooij 2008 + + Implementation of the WSGI interface described in PEP0333 + (http://www.python.org/dev/peps/pep-0333) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include + +static PyObject *start_response(PyObject *args, PyObject *kwargs) +{ + PyObject *response_header, *exc_info; + char *status; + const char *kwnames[] = { + "status", "response_header", "exc_info", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *)"sOO:start_response", (char **)kwnames, &status, &response_header, &exc_info)) { + return NULL; + } + + /* FIXME: response_header, exc_info */ + + /* FIXME: Wrap stdout */ + return NULL; +} + +static PyObject *create_environ(void) +{ + PyObject *env, *osmodule, *osenviron; + + osmodule = PyImport_ImportModule("os"); + if (osmodule == NULL) + return NULL; + + osenviron = PyObject_CallMethod(osmodule, "environ", NULL); + + env = PyDict_Copy(osenviron); + + PyDict_SetItemString(env, "wsgi.input", NULL); /* FIXME */ + PyDict_SetItemString(env, "wsgi.errors", NULL); /* FIXME */ + PyDict_SetItemString(env, "wsgi.version", Py_BuildValue("(i,i)", 1, 0)); + PyDict_SetItemString(env, "wsgi.multithread", Py_False); + PyDict_SetItemString(env, "wsgi.multiprocess", Py_True); + PyDict_SetItemString(env, "wsgi.run_once", Py_False); + + /* FIXME: + PyDict_SetItemString(env, "wsgi.url_scheme", "http"); + PyDict_SetItemString(env, "wsgi.url_scheme", "https"); + */ + + return env; +} -- cgit