*/
#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
data_blob_free(&b);
}
-void websrv_output(struct websrv_context *web, void *data, size_t length)
+void websrv_output(struct websrv_context *web, const 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;
}
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];
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
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);
*/
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;
*/
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);
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);
}