diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-05-26 02:52:05 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:17:02 -0500 |
commit | e8e8eab400fbc310bcf1af8dd1d5436fe9e1cac4 (patch) | |
tree | bb63692e09e9a777c129d68a0bbdd17dca58f356 | |
parent | 9f9b8aa8ea9b0d2fadaa4259c821ad9aae0af0cc (diff) | |
download | samba-e8e8eab400fbc310bcf1af8dd1d5436fe9e1cac4.tar.gz samba-e8e8eab400fbc310bcf1af8dd1d5436fe9e1cac4.tar.bz2 samba-e8e8eab400fbc310bcf1af8dd1d5436fe9e1cac4.zip |
r6986: added support for <% include("somefile.ejs") %> for including common scripts
(This used to be commit e54b31904c69b1aaad748e5be6dce1c882d02c67)
-rw-r--r-- | source4/script/installswat.sh | 6 | ||||
-rw-r--r-- | source4/web_server/http.c | 61 |
2 files changed, 41 insertions, 26 deletions
diff --git a/source4/script/installswat.sh b/source4/script/installswat.sh index dbf0e7351f..3e6e104d03 100644 --- a/source4/script/installswat.sh +++ b/source4/script/installswat.sh @@ -18,9 +18,9 @@ installdir() { 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 diff --git a/source4/web_server/http.c b/source4/web_server/http.c index 61ed685361..5f89e47163 100644 --- a/source4/web_server/http.c +++ b/source4/web_server/http.c @@ -97,6 +97,36 @@ static void http_output_headers(struct websrv_context *web) } /* + 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 @@ static const struct Esp esp_control = { .writeBlock = http_writeBlock, .setHeader = http_setHeader, .redirect = http_redirect, - .setResponseCode = http_setResponseCode + .setResponseCode = http_setResponseCode, + .readFile = http_readFile }; @@ -250,7 +281,7 @@ static const char *http_local_path(struct websrv_context *web, const char *url) } } - 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 @@ static void esp_request(struct esp_state *esp) { 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 @@ static void esp_request(struct esp_state *esp) 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; |