Remove some dependencies of the web server on esp.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 24 May 2008 16:13:30 +0000 (18:13 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 21 Sep 2008 14:03:52 +0000 (16:03 +0200)
source4/web_server/esp.c
source4/web_server/web_server.c
source4/web_server/web_server.h
source4/web_server/wsgi.c

index 901a1558c483667fa39f6545e41c014cd19f6fae..29bda2a965e57d0089425a850f7ce8698791f3e0 100644 (file)
 #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;
 }
index bfbd254d9e91ef9c0059a16af94ee20cdd31b8d5..6d8b2a2758f20de3bdf7b6f73891cad60b0453f3 100644 (file)
@@ -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;
 
index 52aff05dcc559395fef94be5ccbfc50319cdbcd3..0ce68bdd175e8389870dd33fb338db87a3ac0c15 100644 (file)
 
 #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"
 
index 54adeb094334b52a5df498d98284a29b8bf0bd85..32b1f0dbc292c0e94f12ff523becd43cb5c82d61 100644 (file)
 */
 
 #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)
+{
+
+}