svn commit: samba r6986 - in branches/SAMBA_4_0/source: script web_server

tridge at samba.org tridge at samba.org
Thu May 26 02:52:05 GMT 2005


Author: tridge
Date: 2005-05-26 02:52:05 +0000 (Thu, 26 May 2005)
New Revision: 6986

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=6986

Log:
added support for <% include("somefile.ejs") %> for including common scripts


Modified:
   branches/SAMBA_4_0/source/script/installswat.sh
   branches/SAMBA_4_0/source/web_server/http.c


Changeset:
Modified: branches/SAMBA_4_0/source/script/installswat.sh
===================================================================
--- branches/SAMBA_4_0/source/script/installswat.sh	2005-05-26 02:40:22 UTC (rev 6985)
+++ branches/SAMBA_4_0/source/script/installswat.sh	2005-05-26 02:52:05 UTC (rev 6986)
@@ -18,9 +18,9 @@
     done
 }
 
-installdir html html
-installdir html/esptest html
-installdir html/images png
+installdir . html
+installdir esptest html
+installdir images png
 installdir scripting ejs
 
 cat << EOF

Modified: branches/SAMBA_4_0/source/web_server/http.c
===================================================================
--- branches/SAMBA_4_0/source/web_server/http.c	2005-05-26 02:40:22 UTC (rev 6985)
+++ branches/SAMBA_4_0/source/web_server/http.c	2005-05-26 02:52:05 UTC (rev 6986)
@@ -97,6 +97,36 @@
 }
 
 /*
+  called when esp wants to read a file to support include() calls
+*/
+static int http_readFile(EspHandle handle, char **buf, int *len, char *path)
+{
+	int fd = -1;
+	struct stat st;
+	*buf = NULL;
+
+	fd = open(path, O_RDONLY);
+	if (fd == -1 || fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) goto failed;
+
+	*buf = talloc_size(handle, 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:
+	if (fd != -1) close(fd);
+	talloc_free(*buf);
+	*buf = NULL;
+	return -1;
+}
+
+/*
   called when esp wants to output something
 */
 static int http_writeBlock(EspHandle handle, char *buf, int size)
@@ -191,7 +221,8 @@
 	.writeBlock      = http_writeBlock,
 	.setHeader       = http_setHeader,
 	.redirect        = http_redirect,
-	.setResponseCode = http_setResponseCode
+	.setResponseCode = http_setResponseCode,
+	.readFile        = http_readFile
 };
 
 
@@ -250,7 +281,7 @@
 		}
 	}
 
-	path = talloc_asprintf(web, "%s/html/%s", lp_swat_directory(), url+1);
+	path = talloc_asprintf(web, "%s/%s", lp_swat_directory(), url+1);
 	if (path == NULL) return NULL;
 
 	if (directory_exist(path)) {
@@ -338,11 +369,10 @@
 {
 	struct websrv_context *web = esp->web;
 	const char *url = web->input.url;
-	char *buf;
 	const char *path;
-	struct stat st;
-	int fd, res;
-	char *emsg = NULL;
+	size_t size;
+	int res;
+	char *emsg = NULL, *buf;
 
 	http_setup_arrays(esp);
 
@@ -351,31 +381,16 @@
 
 	espSetStringVar(esp->req, ESP_REQUEST_OBJ, "SCRIPT_FILENAME", path);
 
-	/* looks ok */
-	fd = open(path, O_RDONLY);
-	if (fd == -1) {
+	if (http_readFile(web, &buf, &size, path) != 0) {
 		http_error_unix(web, path);
 		return;
 	}
 
-	if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) {
-		close(fd);
-		goto invalid;
-	}
-
-	buf = talloc_size(esp, st.st_size+1);
-	if (buf == NULL) goto invalid;
-
-	if (read(fd, buf, st.st_size) != st.st_size) {
-		goto invalid;
-	}
-	buf[st.st_size] = 0;
-	close(fd);
-
 	res = espProcessRequest(esp->req, path, buf, &emsg);
 	if (res != 0 && emsg) {
 		http_writeBlock(esp, emsg, strlen(emsg));
 	}
+	talloc_free(buf);
 	http_output_headers(web);
 	EVENT_FD_WRITEABLE(web->conn->event.fde);
 	return;



More information about the samba-cvs mailing list