[SCM] Samba Shared Repository - branch master updated - 69577aa34b23ea2573bcea901586719f2fe14826

Jelmer Vernooij jelmer at samba.org
Sun Sep 21 18:08:58 GMT 2008


The branch, master has been updated
       via  69577aa34b23ea2573bcea901586719f2fe14826 (commit)
       via  bbfce1b43d183cdccbe6f9a189098091f9d4a251 (commit)
       via  f3d513b378fcc094255264de0c73f96fac461b68 (commit)
       via  ef8d9f8a756936578dc770a0ec275e57aa3ee51b (commit)
       via  1ed040d8e22a63079c72126bbc896fa3c32c7f0f (commit)
       via  4141e70da97d924969b48fcd198e5996d615e75d (commit)
       via  1271066234fed0e5f0e28a1e75420482abd20887 (commit)
       via  fda85985e91179f8e03538581335326f54456f4f (commit)
       via  2df040d8995b3198be8d3e1099eeb89860a3222d (commit)
       via  a4e8ff7429db8620a4d91e901295413560be6c91 (commit)
       via  4bb17b60ef608b10284ccd2146c9344cc43b8637 (commit)
       via  ef5a04485ae256f9b803da9173d6194ced82e358 (commit)
       via  da987d8fb407a1386462e295f61ff7dcfb757d1d (commit)
      from  7e5f345cfe2f553bca65deccb4b47f19f9208a5b (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 69577aa34b23ea2573bcea901586719f2fe14826
Merge: bbfce1b43d183cdccbe6f9a189098091f9d4a251 7e5f345cfe2f553bca65deccb4b47f19f9208a5b
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Sep 21 20:08:00 2008 +0200

    Merge branch 'master' of ssh://git.samba.org/data/git/samba into wsgi

commit bbfce1b43d183cdccbe6f9a189098091f9d4a251
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Sep 21 20:06:18 2008 +0200

    Allow SWAT to be run outside of smbd.

commit f3d513b378fcc094255264de0c73f96fac461b68
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Sep 21 20:01:00 2008 +0200

    Support POST requests again, provide more variables in environment.

commit ef8d9f8a756936578dc770a0ec275e57aa3ee51b
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Sep 21 20:00:44 2008 +0200

    Make standard SWAT script print received headers.

commit 1ed040d8e22a63079c72126bbc896fa3c32c7f0f
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Sep 21 19:03:12 2008 +0200

    First GET request works. SWAT now displays a Hello world message.

commit 4141e70da97d924969b48fcd198e5996d615e75d
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Sep 21 18:45:09 2008 +0200

    Properly call WSGI request handler when requests come in.

commit 1271066234fed0e5f0e28a1e75420482abd20887
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Sep 21 16:53:29 2008 +0200

    Remove support for ESP in the web server.

commit fda85985e91179f8e03538581335326f54456f4f
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat May 24 18:13:30 2008 +0200

    Remove some dependencies of the web server on esp.

commit 2df040d8995b3198be8d3e1099eeb89860a3222d
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat May 24 15:43:37 2008 +0200

    Add input / error stream objects in WSGI implementation.

commit a4e8ff7429db8620a4d91e901295413560be6c91
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat May 24 03:54:47 2008 +0200

    Add more parts of the WSGI implementation.

commit 4bb17b60ef608b10284ccd2146c9344cc43b8637
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri May 23 21:21:07 2008 +0200

    Add initial work on WSGI support in the web server.

commit ef5a04485ae256f9b803da9173d6194ced82e358
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri May 23 20:40:05 2008 +0200

    Rename http to esp, in preparation of adding a python backend.

commit da987d8fb407a1386462e295f61ff7dcfb757d1d
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Sep 21 15:55:08 2008 +0200

    No longer set PATH during selftest, was only required for smbscript.

-----------------------------------------------------------------------

Summary of changes:
 source4/selftest/selftest.pl        |    2 -
 source4/web_server/config.mk        |    5 +-
 source4/web_server/http.c           | 1030 -----------------------------------
 source4/web_server/swat/__init__.py |   18 +-
 source4/web_server/web_server.c     |  131 ++++--
 source4/web_server/web_server.h     |   51 +--
 source4/web_server/wsgi.c           |  391 +++++++++++++
 7 files changed, 526 insertions(+), 1102 deletions(-)
 delete mode 100644 source4/web_server/http.c
 create mode 100644 source4/web_server/wsgi.c


Changeset truncated at 500 lines:

diff --git a/source4/selftest/selftest.pl b/source4/selftest/selftest.pl
index b6a31ac..51a354c 100755
--- a/source4/selftest/selftest.pl
+++ b/source4/selftest/selftest.pl
@@ -417,8 +417,6 @@ sub prefix_pathvar($$)
 	}
 }
 prefix_pathvar("PKG_CONFIG_PATH", "$old_pwd/bin/pkgconfig");
-# Required for smbscript:
-prefix_pathvar("PATH", "$old_pwd/bin");
 prefix_pathvar("PYTHONPATH", "$old_pwd/bin/python");
 
 if ($opt_socket_wrapper_keep_pcap) {
diff --git a/source4/web_server/config.mk b/source4/web_server/config.mk
index 02f686a..af3ac5f 100644
--- a/source4/web_server/config.mk
+++ b/source4/web_server/config.mk
@@ -4,12 +4,11 @@
 # Start SUBSYSTEM WEB
 [MODULE::WEB]
 INIT_FUNCTION = server_service_web_init
-ENABLE = NO
 SUBSYSTEM = smbd
-PRIVATE_DEPENDENCIES = ESP LIBTLS smbcalls process_model 
+PRIVATE_DEPENDENCIES = LIBTLS smbcalls process_model LIBPYTHON
 # End SUBSYSTEM WEB
 #######################
 
-WEB_OBJ_FILES = $(addprefix $(web_serversrcdir)/, web_server.o http.o)
+WEB_OBJ_FILES = $(addprefix $(web_serversrcdir)/, web_server.o wsgi.o) 
 
 $(eval $(call proto_header_template,$(web_serversrcdir)/proto.h,$(WEB_OBJ_FILES:.o=.c)))
diff --git a/source4/web_server/http.c b/source4/web_server/http.c
deleted file mode 100644
index bd6efa9..0000000
--- a/source4/web_server/http.c
+++ /dev/null
@@ -1,1030 +0,0 @@
-/* 
-   Unix SMB/CIFS implementation.
-
-   http handling code
-
-   Copyright (C) Andrew Tridgell 2005
-   
-   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 "smbd/service_task.h"
-#include "web_server/web_server.h"
-#include "smbd/service_stream.h"
-#include "smbd/service.h"
-#include "lib/events/events.h"
-#include "system/time.h"
-#include "system/wait.h"
-#include "lib/appweb/esp/esp.h"
-#include "lib/appweb/ejs/ejsInternal.h"
-#include "lib/util/dlinklist.h"
-#include "lib/tls/tls.h"
-#include "scripting/ejs/smbcalls.h"
-#include "param/param.h"
-
-#define SAMBA_SESSION_KEY "SambaSessionId"
-#define HTTP_PREAUTH_URI  "/scripting/preauth.esp"
-
-/* state of the esp subsystem for a specific request */
-struct esp_state {
-	struct websrv_context *web;
-	struct EspRequest *req;
-	struct MprVar variables[ESP_OBJ_MAX];
-	struct session_data *session;
-};
-
-/*
-  output the http headers
-*/
-static void http_output_headers(struct websrv_context *web)
-{
-	int i;
-	char *s;
-	DATA_BLOB b;
-	uint32_t content_length = 0;
-	const char *response_string = "Unknown Code";
-	const struct {
-		unsigned code;
-		const char *response_string;
-	} codes[] = {
-		{ 200, "OK" },
-		{ 301, "Moved" },
-		{ 302, "Found" },
-		{ 303, "Method" },
-		{ 304, "Not Modified" },
-		{ 400, "Bad request" },
-		{ 401, "Unauthorized" },
-		{ 403, "Forbidden" },
-		{ 404, "Not Found" },
-		{ 500, "Internal Server Error" },
-		{ 501, "Not implemented" }
-	};
-	for (i=0;i<ARRAY_SIZE(codes);i++) {
-		if (codes[i].code == web->output.response_code) {
-			response_string = codes[i].response_string;
-		}
-	}
-
-	if (web->output.headers == NULL) return;
-	s = talloc_asprintf(web, "HTTP/1.0 %u %s\r\n", 
-			    web->output.response_code, response_string);
-	if (s == NULL) return;
-	for (i=0;web->output.headers[i];i++) {
-		s = talloc_asprintf_append_buffer(s, "%s\r\n", web->output.headers[i]);
-	}
-
-	/* work out the content length */
-	content_length = web->output.content.length;
-	if (web->output.fd != -1) {
-		struct stat st;
-		fstat(web->output.fd, &st);
-		content_length += st.st_size;
-	}
-	s = talloc_asprintf_append_buffer(s, "Content-Length: %u\r\n\r\n", content_length);
-	if (s == NULL) return;
-
-	b = web->output.content;
-	web->output.content = data_blob_string_const(s);
-	data_blob_append(web, &web->output.content, b.data, b.length);
-	data_blob_free(&b);
-}
-
-/*
-  return the local path for a URL
-*/
-static const char *http_local_path(struct websrv_context *web,
-                                   const char *url,
-                                   const char *base_dir)
-{
-	int i;
-	char *path;
-
-	/* check that the url is OK */
-	if (url[0] != '/') return NULL;
-
-	for (i=0;url[i];i++) {
-		if ((!isalnum((unsigned char)url[i]) && !strchr("./_-", url[i])) ||
-		    (url[i] == '.' && strchr("/.", url[i+1]))) {
-			return NULL;
-		}
-	}
-
-	path = talloc_asprintf(web, "%s/%s", base_dir, url+1);
-	if (path == NULL) return NULL;
-
-	if (directory_exist(path)) {
-		path = talloc_asprintf_append_buffer(path, "/index.esp");
-	}
-	return path;
-}
-
-/*
-  called when esp wants to read a file to support include() calls
-*/
-static int http_readFile(EspHandle handle,
-                         char **buf,
-                         int *len,
-                         const char *path,
-                         const char *base_dir)
-{
-	struct websrv_context *web = talloc_get_type(handle, 
-						     struct websrv_context);
-	int fd = -1;
-	struct stat st;
-	*buf = NULL;
-
-	path = http_local_path(web, path, base_dir);
-	if (path == NULL) goto failed;
-
-	fd = open(path, O_RDONLY);
-	if (fd == -1 || fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) goto failed;
-
-	*buf = talloc_array(handle, char, st.st_size+1);
-	if (*buf == NULL) goto failed;
-
-	if (read(fd, *buf, st.st_size) != st.st_size) goto failed;
-
-	(*buf)[st.st_size] = 0;
-
-	close(fd);
-	*len = st.st_size;
-	return 0;
-
-failed:
-	DEBUG(0,("Failed to read file %s - %s\n", path, strerror(errno)));
-	if (fd != -1) close(fd);
-	talloc_free(*buf);
-	*buf = NULL;
-	return -1;
-}
-
-static int http_readFileFromSwatDir(EspHandle handle, char **buf, int *len,
-                                       const char *path)
-{
-    return http_readFile(handle, buf, len, path, 
-			 lp_swat_directory(global_loadparm));
-}
-
-
-
-/*
-  called when esp wants to find the real path of a file
-*/
-static int http_mapToStorage(EspHandle handle, char *path, int len, const char *uri, int flags)
-{
-	if (uri == NULL || strlen(uri) >= len) return -1;
-	strncpy(path, uri, len);
-	return 0;
-}
-
-/*
-  called when esp wants to output something
-*/
-static int http_writeBlock(EspHandle handle, const char *buf, int size)
-{
-	struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
-	if (!data_blob_append(web, &web->output.content, buf, size))
-		return -1;
-	return size;
-}
-
-
-/*
-  set a http header
-*/
-static void http_setHeader(EspHandle handle, const char *value, bool allowMultiple)
-{
-	struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
-	char *p = strchr(value, ':');
-
-	if (p && !allowMultiple && web->output.headers) {
-		int i;
-		for (i=0;web->output.headers[i];i++) {
-			if (strncmp(web->output.headers[i], value, (p+1)-value) == 0) {
-				web->output.headers[i] = talloc_strdup(web, value);
-				return;
-			}
-		}
-	}
-
-	web->output.headers = str_list_add(web->output.headers, value);
-	talloc_steal(web, web->output.headers);
-}
-
-/*
-  set a http response code
-*/
-static void http_setResponseCode(EspHandle handle, int code)
-{
-	struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
-	web->output.response_code = code;
-}
-
-/*
-  redirect to another web page
- */
-static void http_redirect(EspHandle handle, int code, char *url)
-{
-	struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
-	const char *host = web->input.host;
-	
-	/* form the full url, unless it already looks like a url */
-	if (strchr(url, ':') == NULL) {
-		if (host == NULL) {
-			struct socket_address *socket_address = socket_get_my_addr(web->conn->socket, web);
-			if (socket_address == NULL) goto internal_error;
-			host = talloc_asprintf(web, "%s:%u",
-					       socket_address->addr, socket_address->port);
-		}
-		if (host == NULL) goto internal_error;
-		if (url[0] != '/') {
-			char *p = strrchr(web->input.url, '/');
-			if (p == web->input.url) {
-				url = talloc_asprintf(web, "http%s://%s/%s", 
-						      tls_enabled(web->conn->socket)?"s":"",
-						      host, url);
-			} else {
-				int dirlen = p - web->input.url;
-				url = talloc_asprintf(web, "http%s://%s%*.*s/%s",
-						      tls_enabled(web->conn->socket)?"s":"",
-						      host, 
-						      dirlen, dirlen, web->input.url,
-						      url);
-			}
-			if (url == NULL) goto internal_error;
-		}
-	}
-
-	http_setHeader(handle, talloc_asprintf(web, "Location: %s", url), 0);
-
-	/* make sure we give a valid redirect code */
-	if (code >= 300 && code < 400) {
-		http_setResponseCode(handle, code);
-	} else {
-		http_setResponseCode(handle, 302);
-	}
-	return;
-
-internal_error:
-	http_error(web, 500, "Internal server error");
-}
-
-
-/*
-  setup a cookie
-*/
-static void http_setCookie(EspHandle handle, const char *name, const char *value, 
-			   int lifetime, const char *path, bool secure)
-{
-	struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
-	char *buf;
-	
-	if (lifetime > 0) {
-		buf = talloc_asprintf(web, "Set-Cookie: %s=%s; path=%s; Expires=%s; %s",
-				      name, value, path?path:"/", 
-				      http_timestring(web, time(NULL)+lifetime),
-				      secure?"secure":"");
-	} else {
-		buf = talloc_asprintf(web, "Set-Cookie: %s=%s; path=%s; %s",
-				      name, value, path?path:"/", 
-				      secure?"secure":"");
-	}
-	http_setHeader(handle, "Cache-control: no-cache=\"set-cookie\"", 0);
-	http_setHeader(handle, buf, 0);
-	talloc_free(buf);
-}
-
-/*
-  return the session id
-*/
-static const char *http_getSessionId(EspHandle handle)
-{
-	struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
-	return web->session->id;
-}
-
-/*
-  setup a session
-*/
-static void http_createSession(EspHandle handle, int timeout)
-{
-	struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
-	if (web->session) {
-		web->session->lifetime = timeout;
-		http_setCookie(web, SAMBA_SESSION_KEY, web->session->id, 
-			       web->session->lifetime, "/", 0);
-	}
-}
-
-/*
-  destroy a session
-*/
-static void http_destroySession(EspHandle handle)
-{
-	struct websrv_context *web = talloc_get_type(handle, struct websrv_context);
-	talloc_free(web->session);
-	web->session = NULL;
-}
-
-
-/*
-  setup for a raw http level error
-*/
-void http_error(struct websrv_context *web, int code, const char *info)
-{
-	char *s;
-	s = talloc_asprintf(web,"<HTML><HEAD><TITLE>Error %u</TITLE></HEAD><BODY><H1>Error %u</H1><pre>%s</pre><p></BODY></HTML>\r\n\r\n", 
-			    code, code, info);
-	if (s == NULL) {
-		stream_terminate_connection(web->conn, "http_error: out of memory");
-		return;
-	}
-	http_writeBlock(web, s, strlen(s));
-	http_setResponseCode(web, code);
-	http_output_headers(web);
-	EVENT_FD_NOT_READABLE(web->conn->event.fde);
-	EVENT_FD_WRITEABLE(web->conn->event.fde);
-	web->output.output_pending = true;
-}
-
-/*
-  map a unix error code to a http error
-*/
-void http_error_unix(struct websrv_context *web, const char *info)
-{
-	int code = 500;
-	switch (errno) {
-	case ENOENT:
-	case EISDIR:
-		code = 404;
-		break;
-	case EACCES:
-		code = 403;
-		break;
-	}
-	info = talloc_asprintf(web, "%s<p>%s<p>\n", info, strerror(errno));
-	http_error(web, code, info);
-}
-
-
-/*
-  a simple file request
-*/
-static void http_simple_request(struct websrv_context *web)
-{
-	const char *url = web->input.url;
-	const char *path;
-	struct stat st;
-
-	path = http_local_path(web, url, lp_swat_directory(web->task->lp_ctx));
-	if (path == NULL) goto invalid;
-
-	/* looks ok */
-	web->output.fd = open(path, O_RDONLY);
-	if (web->output.fd == -1) {
-		DEBUG(0,("Failed to read file %s - %s\n", path, strerror(errno)));
-		http_error_unix(web, path);
-		return;
-	}
-
-	if (fstat(web->output.fd, &st) != 0 || !S_ISREG(st.st_mode)) {
-		close(web->output.fd);
-		goto invalid;
-	}
-
-	return;
-
-invalid:
-	http_error(web, 400, "Malformed URL");
-}
-
-/*
-  setup the standard ESP arrays
-*/
-static void http_setup_arrays(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);
-	char *p;
-
-#define SETVAR(type, name, value) do { \
-		const char *v = value; \
-		if (v) espSetStringVar(req, type, name, v); \
-} while (0)
-
-	SETVAR(ESP_REQUEST_OBJ, "CONTENT_LENGTH", 
-	       talloc_asprintf(esp, "%u", web->input.content_length));
-	SETVAR(ESP_REQUEST_OBJ, "QUERY_STRING", web->input.query_string);
-	SETVAR(ESP_REQUEST_OBJ, "POST_DATA",
-               talloc_strndup(esp,
-                              web->input.partial.data,
-                              web->input.partial.length));
-	SETVAR(ESP_REQUEST_OBJ, "REQUEST_METHOD", web->input.post_request?"POST":"GET");
-	SETVAR(ESP_REQUEST_OBJ, "REQUEST_URI", web->input.url);
-	p = strrchr(web->input.url, '/');
-	SETVAR(ESP_REQUEST_OBJ, "SCRIPT_NAME", p+1);
-	SETVAR(ESP_REQUEST_OBJ, "SCRIPT_FILENAME", web->input.url);
-	if (peer_address) {
-		struct MprVar mpv = mprObject("socket_address");
-		mprSetPtrChild(&mpv, "socket_address", peer_address);
-		espSetVar(req, ESP_REQUEST_OBJ, "REMOTE_SOCKET_ADDRESS", mpv);
-		SETVAR(ESP_REQUEST_OBJ, "REMOTE_ADDR", peer_address->addr);
-	}
-	p = socket_get_peer_name(web->conn->socket, esp);
-	SETVAR(ESP_REQUEST_OBJ, "REMOTE_HOST", p);
-	SETVAR(ESP_REQUEST_OBJ, "REMOTE_USER", "");
-	SETVAR(ESP_REQUEST_OBJ, "CONTENT_TYPE", web->input.content_type);
-	if (web->session) {
-		SETVAR(ESP_REQUEST_OBJ, "SESSION_ID", web->session->id);
-	}
-	SETVAR(ESP_REQUEST_OBJ, "COOKIE_SUPPORT", web->input.cookie?"true":"false");
-
-	SETVAR(ESP_HEADERS_OBJ, "HTTP_REFERER", web->input.referer);
-	SETVAR(ESP_HEADERS_OBJ, "HOST", web->input.host);
-	SETVAR(ESP_HEADERS_OBJ, "ACCEPT_ENCODING", web->input.accept_encoding);
-	SETVAR(ESP_HEADERS_OBJ, "ACCEPT_LANGUAGE", web->input.accept_language);
-	SETVAR(ESP_HEADERS_OBJ, "ACCEPT_CHARSET", web->input.accept_charset);
-	SETVAR(ESP_HEADERS_OBJ, "COOKIE", web->input.cookie);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list