1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00
samba-mirror/source4/web_server/wsgi.c

108 lines
2.7 KiB
C
Raw Normal View History

/*
Unix SMB/CIFS implementation.
Samba utility functions
Copyright © Jelmer Vernooij <jelmer@samba.org> 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 <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include <Python.h>
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;
}
/*
* read(size) input 1
* readline() input 1,2
* readlines(hint) input 1,3
* __iter__() input
* flush() errors 4
* write(str) errors
* writelines(seq) errors
*/
static PyObject *Py_InputHttpStream(void *foo)
{
/* FIXME */
return NULL;
}
static PyObject *Py_ErrorHttpStream(void)
{
/* FIXME */
return NULL;
}
static PyObject *create_environ(void)
{
PyObject *env, *osmodule, *osenviron;
PyObject *inputstream, *errorstream;
osmodule = PyImport_ImportModule("os");
if (osmodule == NULL)
return NULL;
osenviron = PyObject_CallMethod(osmodule, "environ", NULL);
env = PyDict_Copy(osenviron);
Py_DECREF(env);
inputstream = Py_InputHttpStream(NULL); /* FIXME */
if (inputstream == NULL) {
Py_DECREF(env);
return NULL;
}
errorstream = Py_ErrorHttpStream();
if (errorstream == NULL) {
Py_DECREF(env);
Py_DECREF(inputstream);
return NULL;
}
PyDict_SetItemString(env, "wsgi.input", inputstream);
PyDict_SetItemString(env, "wsgi.errors", errorstream);
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;
}