s4:misc: remove last usage of legacy event_ fn names
[idra/samba.git] / source4 / web_server / web_server.c
index 74eea9e60b412b5b967139f66a8f1ec8f10d5e85..99a6b65f674890cdccaf80e61d44dc6938268b7d 100644 (file)
 */
 
 #include "includes.h"
-#include "smbd/service_task.h"
-#include "smbd/service_stream.h"
-#include "smbd/service.h"
 #include "web_server/web_server.h"
+#include "../lib/util/dlinklist.h"
+#include "lib/tls/tls.h"
 #include "lib/events/events.h"
-#include "system/filesys.h"
-#include "system/network.h"
 #include "lib/socket/netif.h"
-#include "lib/tls/tls.h"
-#include "../lib/util/dlinklist.h"
 #include "param/param.h"
 
+NTSTATUS server_service_web_init(void);
+
 /* don't allow connections to hang around forever */
 #define HTTP_TIMEOUT 120
 
@@ -48,11 +45,11 @@ static int websrv_destructor(struct websrv_context *web)
   called when a connection times out. This prevents a stuck connection
   from hanging around forever
 */
-static void websrv_timeout(struct event_context *event_context, 
-                          struct timed_event *te, 
-                          struct timeval t, void *private)
+static void websrv_timeout(struct tevent_context *event_context, 
+                          struct tevent_timer *te, 
+                          struct timeval t, void *private_data)
 {
-       struct websrv_context *web = talloc_get_type(private, struct websrv_context);
+       struct websrv_context *web = talloc_get_type(private_data, struct websrv_context);
        struct stream_connection *conn = web->conn;
        web->conn = NULL;
        /* TODO: send a message to any running esp context on this connection
@@ -99,8 +96,8 @@ void websrv_output_headers(struct websrv_context *web, const char *status, struc
 void websrv_output(struct websrv_context *web, void *data, size_t length)
 {
        data_blob_append(web, &web->output.content, data, length);
-       EVENT_FD_NOT_READABLE(web->conn->event.fde);
-       EVENT_FD_WRITEABLE(web->conn->event.fde);
+       TEVENT_FD_NOT_READABLE(web->conn->event.fde);
+       TEVENT_FD_WRITEABLE(web->conn->event.fde);
        web->output.output_pending = true;
 }
 
@@ -145,7 +142,7 @@ NTSTATUS http_parse_header(struct websrv_context *web, const char *line)
 static void websrv_recv(struct stream_connection *conn, uint16_t flags)
 {
        struct web_server_data *wdata;
-       struct websrv_context *web = talloc_get_type(conn->private
+       struct websrv_context *web = talloc_get_type(conn->private_data,
                                                     struct websrv_context);
        NTSTATUS status;
        uint8_t buf[1024];
@@ -192,7 +189,7 @@ static void websrv_recv(struct stream_connection *conn, uint16_t flags)
                if (web->input.partial.length > web->input.content_length) {
                        web->input.partial.data[web->input.content_length] = 0;
                }
-               EVENT_FD_NOT_READABLE(web->conn->event.fde);
+               TEVENT_FD_NOT_READABLE(web->conn->event.fde);
 
                /* the reference/unlink code here is quite subtle. It
                 is needed because the rendering of the web-pages, and
@@ -202,7 +199,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;
-               wdata = talloc_get_type(web->task->private, struct web_server_data);
+               wdata = talloc_get_type(web->task->private_data, struct web_server_data);
                if (wdata == NULL) goto failed;
                wdata->http_process_input(wdata, web);
                talloc_unlink(web->task, web);
@@ -220,7 +217,7 @@ failed:
 */
 static void websrv_send(struct stream_connection *conn, uint16_t flags)
 {
-       struct websrv_context *web = talloc_get_type(conn->private
+       struct websrv_context *web = talloc_get_type(conn->private_data,
                                                     struct websrv_context);
        NTSTATUS status;
        size_t nsent;
@@ -251,20 +248,19 @@ 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 web_server_data *wdata = talloc_get_type(task->private, struct web_server_data);
+       struct web_server_data *wdata = talloc_get_type(conn->private_data, 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->task = task;
+       web->task = wdata->task;
        web->conn = conn;
-       conn->private = web;
+       conn->private_data = web;
        talloc_set_destructor(web, websrv_destructor);
 
-       event_add_timed(conn->event.ctx, web, 
+       tevent_add_timer(conn->event.ctx, web,
                        timeval_current_ofs(HTTP_TIMEOUT, 0),
                        websrv_timeout, web);
 
@@ -300,60 +296,75 @@ static const struct stream_server_ops web_stream_ops = {
 static void websrv_task_init(struct task_server *task)
 {
        NTSTATUS status;
-       uint16_t port = lp_web_port(task->lp_ctx);
+       uint16_t port = lpcfg_web_port(task->lp_ctx);
        const struct model_ops *model_ops;
        struct web_server_data *wdata;
 
        task_server_set_title(task, "task[websrv]");
 
        /* run the web server as a single process */
-       model_ops = process_model_startup(task->event_ctx, "single");
+       model_ops = process_model_startup("single");
        if (!model_ops) goto failed;
 
-       if (lp_interfaces(task->lp_ctx) && lp_bind_interfaces_only(task->lp_ctx)) {
+       /* startup the Python processor - unfortunately we can't do this
+          per connection as that wouldn't allow for session variables */
+       wdata = talloc_zero(task, struct web_server_data);
+       if (wdata == NULL) goto failed;
+
+       wdata->task = task;
+       task->private_data = wdata;
+
+       if (lpcfg_interfaces(task->lp_ctx) && lpcfg_bind_interfaces_only(task->lp_ctx)) {
                int num_interfaces;
                int i;
                struct interface *ifaces;
 
-               load_interfaces(NULL, lp_interfaces(task->lp_ctx), &ifaces);
+               load_interface_list(NULL, task->lp_ctx, &ifaces);
 
-               num_interfaces = iface_count(ifaces);
+               num_interfaces = iface_list_count(ifaces);
                for(i = 0; i < num_interfaces; i++) {
-                       const char *address = iface_n_ip(ifaces, i);
-                       status = stream_setup_socket(task->event_ctx, 
-                                                    task->lp_ctx, model_ops, 
+                       const char *address = iface_list_n_ip(ifaces, i);
+                       status = stream_setup_socket(task,
+                                                    task->event_ctx,
+                                                    task->lp_ctx, model_ops,
                                                     &web_stream_ops, 
-                                                    "ipv4", address, 
-                                                    &port, lp_socket_options(task->lp_ctx), 
+                                                    "ip", address,
+                                                    &port, lpcfg_socket_options(task->lp_ctx),
                                                     task);
                        if (!NT_STATUS_IS_OK(status)) goto failed;
                }
 
                talloc_free(ifaces);
        } else {
-               status = stream_setup_socket(task->event_ctx, task->lp_ctx,
-                                            model_ops, &web_stream_ops, 
-                                            "ipv4", lp_socket_address(task->lp_ctx), 
-                                            &port, lp_socket_options(task->lp_ctx), task);
-               if (!NT_STATUS_IS_OK(status)) goto failed;
+               const char **wcard;
+               int i;
+               wcard = iface_list_wildcard(task, task->lp_ctx);
+               if (wcard == NULL) {
+                       DEBUG(0,("No wildcard addresses available\n"));
+                       goto failed;
+               }
+               for (i=0; wcard[i]; i++) {
+                       status = stream_setup_socket(task, task->event_ctx,
+                                                    task->lp_ctx, model_ops,
+                                                    &web_stream_ops,
+                                                    "ip", wcard[i],
+                                                    &port, lpcfg_socket_options(task->lp_ctx),
+                                                    wdata);
+                       if (!NT_STATUS_IS_OK(status)) goto failed;
+               }
+               talloc_free(wcard);
        }
 
-       /* startup the esp processor - unfortunately we can't do this
-          per connection as that wouldn't allow for session variables */
-       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;
 
        if (!wsgi_initialize(wdata)) goto failed;
 
+
        return;
 
 failed:
-       task_server_terminate(task, "websrv_task_init: failed to startup web server task");
+       task_server_terminate(task, "websrv_task_init: failed to startup web server task", true);
 }