diff options
Diffstat (limited to 'source4')
-rw-r--r-- | source4/web_server/esp.c | 38 | ||||
-rw-r--r-- | source4/web_server/web_server.c | 20 | ||||
-rw-r--r-- | source4/web_server/web_server.h | 23 | ||||
-rw-r--r-- | source4/web_server/wsgi.c | 24 |
4 files changed, 61 insertions, 44 deletions
diff --git a/source4/web_server/esp.c b/source4/web_server/esp.c index 901a1558c4..29bda2a965 100644 --- a/source4/web_server/esp.c +++ b/source4/web_server/esp.c @@ -37,6 +37,24 @@ #define SAMBA_SESSION_KEY "SambaSessionId" #define HTTP_PREAUTH_URI "/scripting/preauth.esp" +/* + context for long term storage in the web server, to support session[] + and application[] data. Stored in task->private. +*/ +struct esp_data { + struct session_data { + struct session_data *next, *prev; + struct esp_data *edata; + const char *id; + struct MprVar *data; + struct timed_event *te; + int lifetime; + } *sessions; + struct MprVar *application_data; +}; + + + /* state of the esp subsystem for a specific request */ struct esp_state { struct websrv_context *web; @@ -413,10 +431,9 @@ invalid: /* setup the standard ESP arrays */ -static void http_setup_arrays(struct esp_state *esp) +static void http_setup_arrays(struct web_server_data *wdata, struct esp_state *esp) { struct websrv_context *web = esp->web; - struct esp_data *edata = talloc_get_type(web->task->private, struct esp_data); struct EspRequest *req = esp->req; struct socket_address *socket_address = socket_get_my_addr(web->conn->socket, esp); struct socket_address *peer_address = socket_get_peer_addr(web->conn->socket, esp); @@ -474,7 +491,7 @@ static void http_setup_arrays(struct esp_state *esp) SETVAR(ESP_SERVER_OBJ, "SERVER_PROTOCOL", tls_enabled(web->conn->socket)?"https":"http"); SETVAR(ESP_SERVER_OBJ, "SERVER_SOFTWARE", "SAMBA"); SETVAR(ESP_SERVER_OBJ, "GATEWAY_INTERFACE", "CGI/1.1"); - SETVAR(ESP_SERVER_OBJ, "TLS_SUPPORT", tls_support(edata->tls_params)?"true":"false"); + SETVAR(ESP_SERVER_OBJ, "TLS_SUPPORT", tls_support(wdata->tls_params)?"true":"false"); } #if HAVE_SETJMP_H @@ -696,13 +713,12 @@ static int session_destructor(struct session_data *s) /* setup the session for this request */ -static void http_setup_session(struct esp_state *esp) +static void http_setup_session(struct esp_data *edata, struct esp_state *esp) { const char *session_key = SAMBA_SESSION_KEY; char *p; const char *cookie = esp->web->input.cookie; const char *key = NULL; - struct esp_data *edata = talloc_get_type(esp->web->task->private, struct esp_data); struct session_data *s; bool generated_key = false; @@ -771,11 +787,11 @@ static const struct Esp esp_control = { /* process a complete http request */ -void http_process_input(struct websrv_context *web) +void esp_process_http_input(struct web_server_data *wdata, struct websrv_context *web) { NTSTATUS status; struct esp_state *esp = NULL; - struct esp_data *edata = talloc_get_type(web->task->private, struct esp_data); + struct esp_data *edata = talloc_get_type(wdata->private, struct esp_data); struct smbcalls_context *smbcalls_ctx; char *p; void *save_mpr_ctx = mprMemCtx(); @@ -865,7 +881,7 @@ void http_process_input(struct websrv_context *web) } } - http_setup_session(esp); + http_setup_session(edata, esp); esp->req = espCreateRequest(web, web->input.url, esp->variables); if (esp->req == NULL) goto internal_error; @@ -894,7 +910,7 @@ void http_process_input(struct websrv_context *web) http_setHeader(web, "Connection: close", 0); http_setHeader(web, talloc_asprintf(esp, "Content-Type: %s", file_type), 0); - http_setup_arrays(esp); + http_setup_arrays(wdata, esp); /* * Do pre-authentication. If pre-authentication succeeds, do @@ -1022,9 +1038,5 @@ struct esp_data *http_setup_esp(TALLOC_CTX *mem_ctx, struct loadparm_context *lp if (edata == NULL) return NULL; - edata->tls_params = tls_initialise(edata, lp_ctx); - if (edata->tls_params == NULL) - return NULL; - return edata; } diff --git a/source4/web_server/web_server.c b/source4/web_server/web_server.c index bfbd254d9e..6d8b2a2758 100644 --- a/source4/web_server/web_server.c +++ b/source4/web_server/web_server.c @@ -123,7 +123,7 @@ static void websrv_recv(struct stream_connection *conn, uint16_t flags) destroy the stack variables being used by that rendering process when we handle the timeout. */ if (!talloc_reference(web->task, web)) goto failed; - http_process_input(web); + web->http_process_input(web); talloc_unlink(web->task, web); } return; @@ -192,13 +192,14 @@ static void websrv_send(struct stream_connection *conn, uint16_t flags) static void websrv_accept(struct stream_connection *conn) { struct task_server *task = talloc_get_type(conn->private, struct task_server); - struct esp_data *edata = talloc_get_type(task->private, struct esp_data); + struct web_server_data *wdata = talloc_get_type(task->private, struct web_server_data); struct websrv_context *web; struct socket_context *tls_socket; web = talloc_zero(conn, struct websrv_context); if (web == NULL) goto failed; + web->http_process_input = esp_process_http_input; web->task = task; web->conn = conn; conn->private = web; @@ -210,7 +211,7 @@ static void websrv_accept(struct stream_connection *conn) websrv_timeout, web); /* Overwrite the socket with a (possibly) TLS socket */ - tls_socket = tls_init_server(edata->tls_params, conn->socket, + tls_socket = tls_init_server(wdata->tls_params, conn->socket, conn->event.fde, "GPHO"); /* We might not have TLS, or it might not have initilised */ if (tls_socket) { @@ -243,6 +244,7 @@ static void websrv_task_init(struct task_server *task) NTSTATUS status; uint16_t port = lp_web_port(task->lp_ctx); const struct model_ops *model_ops; + struct web_server_data *wdata; task_server_set_title(task, "task[websrv]"); @@ -280,8 +282,16 @@ static void websrv_task_init(struct task_server *task) /* startup the esp processor - unfortunately we can't do this per connection as that wouldn't allow for session variables */ - task->private = http_setup_esp(task, task->lp_ctx); - if (task->private == NULL) goto failed; + wdata = talloc_zero(task, struct web_server_data); + if (wdata == NULL)goto failed; + + task->private = wdata; + + wdata->tls_params = tls_initialise(wdata, task->lp_ctx); + if (wdata->tls_params == NULL) goto failed; + + wdata->private = http_setup_esp(task, task->lp_ctx); + if (wdata->private == NULL) goto failed; return; diff --git a/source4/web_server/web_server.h b/source4/web_server/web_server.h index 52aff05dcc..0ce68bdd17 100644 --- a/source4/web_server/web_server.h +++ b/source4/web_server/web_server.h @@ -19,12 +19,18 @@ #include "smbd/process_model.h" +struct web_server_data { + struct tls_params *tls_params; + void *private; +}; + /* context of one open web connection */ struct websrv_context { struct task_server *task; struct stream_connection *conn; + void (*http_process_input)(struct websrv_context *web); struct { bool tls_detect; bool tls_first_char; @@ -57,22 +63,5 @@ struct websrv_context { }; -/* - context for long term storage in the web server, to support session[] - and application[] data. Stored in task->private. -*/ -struct esp_data { - struct session_data { - struct session_data *next, *prev; - struct esp_data *edata; - const char *id; - struct MprVar *data; - struct timed_event *te; - int lifetime; - } *sessions; - struct MprVar *application_data; - struct tls_params *tls_params; -}; - #include "web_server/proto.h" diff --git a/source4/web_server/wsgi.c b/source4/web_server/wsgi.c index 54adeb0943..32b1f0dbc2 100644 --- a/source4/web_server/wsgi.c +++ b/source4/web_server/wsgi.c @@ -21,9 +21,10 @@ */ #include "includes.h" +#include "web_server/web_server.h" #include <Python.h> -static PyObject *start_response(PyObject *args, PyObject *kwargs) +static PyObject *start_response(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject *response_header, *exc_info; char *status; @@ -84,9 +85,9 @@ static PyObject *py_error_writelines(PyObject *self, PyObject *args, PyObject *k } static PyMethodDef error_Stream_methods[] = { - { "flush", (PyCFunction)py_error_flush, METH_VARARGS|METH_KEYWORDS, NULL }, - { "write", (PyCFunction)py_error_write, METH_VARARGS|METH_KEYWORDS, NULL }, - { "writelines", (PyCFunction)py_error_writelines, METH_VARARGS|METH_KEYWORDS, NULL }, + { "flush", (PyCFunction)py_error_flush, METH_O|METH_VARARGS|METH_KEYWORDS, NULL }, + { "write", (PyCFunction)py_error_write, METH_O|METH_VARARGS|METH_KEYWORDS, NULL }, + { "writelines", (PyCFunction)py_error_writelines, METH_O|METH_VARARGS|METH_KEYWORDS, NULL }, { NULL, NULL, 0, NULL } }; @@ -123,10 +124,10 @@ static PyObject *py_input___iter__(PyObject *self, PyObject *args, PyObject *kwa } static PyMethodDef input_Stream_methods[] = { - { "read", (PyCFunction)py_input_read, METH_VARARGS|METH_KEYWORDS, NULL }, - { "readline", (PyCFunction)py_input_readline, METH_VARARGS|METH_KEYWORDS, NULL }, - { "readlines", (PyCFunction)py_input_readlines, METH_VARARGS|METH_KEYWORDS, NULL }, - { "__iter__", (PyCFunction)py_input___iter__, METH_VARARGS|METH_KEYWORDS, NULL }, + { "read", (PyCFunction)py_input_read, METH_O|METH_VARARGS|METH_KEYWORDS, NULL }, + { "readline", (PyCFunction)py_input_readline, METH_O|METH_VARARGS|METH_KEYWORDS, NULL }, + { "readlines", (PyCFunction)py_input_readlines, METH_O|METH_VARARGS|METH_KEYWORDS, NULL }, + { "__iter__", (PyCFunction)py_input___iter__, METH_O|METH_VARARGS|METH_KEYWORDS, NULL }, { NULL, NULL, 0, NULL } }; @@ -165,7 +166,7 @@ static PyObject *create_environ(void) Py_DECREF(env); - inputstream = Py_InputHttpStream(NULL); /* FIXME */ + inputstream = Py_InputHttpStream(NULL); if (inputstream == NULL) { Py_DECREF(env); return NULL; @@ -192,3 +193,8 @@ static PyObject *create_environ(void) return env; } + +void wsgi_process_http_input(struct websrv_context *web) +{ + +} |