From 845bc1d41b4ba262cc9c593c672adafa1975505f Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Sun, 31 Jul 2011 18:51:10 +0200 Subject: [PATCH] added data:// facility --- ini.c | 2 +- json.c | 2 +- utils.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ xmlconf.c | 2 +- yaml.c | 2 +- 5 files changed, 61 insertions(+), 4 deletions(-) diff --git a/ini.c b/ini.c index 7f1b6976..5e950349 100644 --- a/ini.c +++ b/ini.c @@ -92,7 +92,7 @@ void uwsgi_ini_config(char *file, char *magic_table[]) { char *section_asked = "uwsgi"; char *colon; - if (!uwsgi_startswith(file, "http://", 7)) { + if (!uwsgi_startswith(file, "http://", 7) || !uwsgi_startswith(file, "data://", 7) || !uwsgi_startswith(file, "sym://", 6) ) { colon = uwsgi_get_last_char(file, '/'); colon = uwsgi_get_last_char(colon, ':'); } diff --git a/json.c b/json.c index a31a7b4e..ef53c2f1 100644 --- a/json.c +++ b/json.c @@ -30,7 +30,7 @@ void uwsgi_json_config(char *file, char *magic_table[]) { char *colon; int i; - if (!uwsgi_startswith(file, "http://", 7)) { + if (!uwsgi_startswith(file, "http://", 7) || !uwsgi_startswith(file, "data://", 7) || !uwsgi_startswith(file, "sym://", 6)) { colon = uwsgi_get_last_char(file, '/'); colon = uwsgi_get_last_char(colon, ':'); } diff --git a/utils.c b/utils.c index 35e15369..209e5740 100644 --- a/utils.c +++ b/utils.c @@ -1793,6 +1793,63 @@ char *uwsgi_open_and_read(char *url, int *size, int add_zero, char *magic_table[ #endif else if (!strncmp("data://", url, 7)) { fd = open(uwsgi.binary_path, O_RDONLY); + if (fd < 0) { + uwsgi_error_open(uwsgi.binary_path); + exit(1); + } + int slot = atoi(url+7); + if (slot < 0) { + uwsgi_log("invalid binary data slot requested\n"); + exit(1); + } + uwsgi_log("requesting binary data slot %d\n", slot); + off_t fo = lseek(fd, 0, SEEK_END); + if (fo < 0) { + uwsgi_error("lseek()"); + uwsgi_log("invalid binary data slot requested\n"); + exit(1); + } + int i = 0; + uint64_t datasize = 0; + for(i=0;i<=slot;i++) { + fo = lseek(fd, -9, SEEK_CUR); + if (fo < 0) { + uwsgi_error("lseek()"); + uwsgi_log("invalid binary data slot requested\n"); + exit(1); + } + ssize_t len = read(fd, &datasize, 8); + if (len != 8) { + uwsgi_error("read()"); + uwsgi_log("invalid binary data slot requested\n"); + exit(1); + } + if (datasize == 0) { + uwsgi_log("0 size binary data !!!\n"); + exit(1); + } + fo = lseek(fd, -(datasize+9), SEEK_CUR); + if (fo < 0) { + uwsgi_error("lseek()"); + uwsgi_log("invalid binary data slot requested\n"); + exit(1); + } + + if (i == slot) { + *size = datasize; + if (add_zero) { + *size+=1; + } + buffer = uwsgi_malloc(*size); + memset(buffer, 0, *size); + len = read(fd, buffer, datasize); + if (len != (ssize_t) datasize) { + uwsgi_error("read()"); + uwsgi_log("invalid binary data slot requested\n"); + exit(1); + } + } + } } else if (!strncmp("sym://", url, 6)) { char *symbol = uwsgi_concat3("_binary_", url+6, "_start") ; diff --git a/xmlconf.c b/xmlconf.c index 39c028d8..9df2b656 100644 --- a/xmlconf.c +++ b/xmlconf.c @@ -26,7 +26,7 @@ void uwsgi_xml_config(char *filename, struct wsgi_request *wsgi_req, int app_tag char *xml_content; int xml_size = 0; - if (!uwsgi_startswith(filename, "http://", 7)) { + if (!uwsgi_startswith(filename, "http://", 7) || !uwsgi_startswith(filename, "data://", 7) || !uwsgi_startswith(filename, "sym://", 6)) { colon = uwsgi_get_last_char(filename, '/'); colon = uwsgi_get_last_char(colon, ':'); } diff --git a/yaml.c b/yaml.c index 47e3b292..f1d7147c 100644 --- a/yaml.c +++ b/yaml.c @@ -107,7 +107,7 @@ void uwsgi_yaml_config(char *file, char *magic_table[]) { char *section_asked = "uwsgi"; char *colon; - if (!uwsgi_startswith(file, "http://", 7)) { + if (!uwsgi_startswith(file, "http://", 7) || !uwsgi_startswith(file, "data://", 7) || !uwsgi_startswith(file, "sym://", 6)) { colon = uwsgi_get_last_char(file, '/'); colon = uwsgi_get_last_char(colon, ':'); }