summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnbit <info@unbit.it>2013-10-07 11:37:52 +0200
committerUnbit <info@unbit.it>2013-10-07 11:37:52 +0200
commit9fe9fe1bb6cfdfb1e79e75d1d73a2ca62e92f782 (patch)
tree0e029cd73bb4169b8b047c9e18c0317c3604b016
parent192312e3ea153d519cabdb1d2897232d83b02212 (diff)
downloaduwsgi-9fe9fe1bb6cfdfb1e79e75d1d73a2ca62e92f782.tar.gz
fixed data:// scheme
-rw-r--r--core/io.c9
-rw-r--r--core/uwsgi.c21
-rw-r--r--uwsgi.h1
3 files changed, 27 insertions, 4 deletions
diff --git a/core/io.c b/core/io.c
index 48bde691..ef705bec 100644
--- a/core/io.c
+++ b/core/io.c
@@ -138,7 +138,6 @@ static char *uwsgi_scheme_http(char *url, size_t *size, int add_zero) {
char byte;
int body = 0;
char *buffer = NULL;
- *size = 0;
char *domain = url;
char *uri = strchr(domain, '/');
@@ -260,7 +259,6 @@ static char *uwsgi_scheme_emperor(char *url, size_t *size, int add_zero) {
exit(1);
}
ssize_t rlen;
- *size = 0;
struct uwsgi_header uh;
size_t remains = 4;
char *ptr = (char *) &uh;
@@ -328,7 +326,7 @@ static char *uwsgi_scheme_data(char *url, size_t *size, int add_zero) {
int i = 0;
uint64_t datasize = 0;
for (i = 0; i <= slot; i++) {
- fo = lseek(fd, -9, SEEK_CUR);
+ fo = lseek(fd, -8, SEEK_CUR);
if (fo < 0) {
uwsgi_error("lseek()");
uwsgi_log("invalid binary data slot requested\n");
@@ -344,7 +342,7 @@ static char *uwsgi_scheme_data(char *url, size_t *size, int add_zero) {
uwsgi_log("0 size binary data !!!\n");
exit(1);
}
- fo = lseek(fd, -(datasize + 9), SEEK_CUR);
+ fo = lseek(fd, -(datasize + 8), SEEK_CUR);
if (fo < 0) {
uwsgi_error("lseek()");
uwsgi_log("invalid binary data slot requested\n");
@@ -366,6 +364,7 @@ static char *uwsgi_scheme_data(char *url, size_t *size, int add_zero) {
}
}
}
+
return buffer;
}
@@ -468,6 +467,8 @@ char *uwsgi_open_and_read(char *url, size_t *size, int add_zero, char *magic_tab
char *magic_buf;
int fd;
+ *size = 0;
+
// stdin ?
if (!strcmp(url, "-")) {
buffer = uwsgi_read_fd(0, size, add_zero);
diff --git a/core/uwsgi.c b/core/uwsgi.c
index e81487a6..0772d79f 100644
--- a/core/uwsgi.c
+++ b/core/uwsgi.c
@@ -879,6 +879,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
{"dump-options", no_argument, 0, "dump the full list of available options", uwsgi_opt_true, &uwsgi.dump_options, 0},
{"show-config", no_argument, 0, "show the current config reformatted as ini", uwsgi_opt_true, &uwsgi.show_config, 0},
+ {"binary-append-data", required_argument, 0, "return the content of a resource to stdout for appending to a uwsgi binary (for data:// usage)", uwsgi_opt_binary_append_data, NULL, UWSGI_OPT_IMMEDIATE},
{"print", required_argument, 0, "simple print", uwsgi_opt_print, NULL, 0},
{"exit", optional_argument, 0, "force exit() of the instance", uwsgi_opt_exit, NULL, UWSGI_OPT_IMMEDIATE},
{"cflags", no_argument, 0, "report uWSGI CFLAGS (useful for building external plugins)", uwsgi_opt_cflags, NULL, UWSGI_OPT_IMMEDIATE},
@@ -4554,3 +4555,23 @@ void uwsgi_update_pidfiles() {
uwsgi_write_pidfile(uwsgi.pidfile2);
}
}
+
+void uwsgi_opt_binary_append_data(char *opt, char *value, void *none) {
+
+ size_t size;
+ char *buf = uwsgi_open_and_read(value, &size, 0, NULL);
+
+ uint64_t file_len = size;
+
+ if (write(1, buf, size) != (ssize_t) size) {
+ uwsgi_error("uwsgi_opt_binary_append_data()/write()");
+ exit(1);
+ }
+
+ if (write(1, &file_len, 8) != 8) {
+ uwsgi_error("uwsgi_opt_binary_append_data()/write()");
+ exit(1);
+ }
+
+ exit(0);
+}
diff --git a/uwsgi.h b/uwsgi.h
index 479d94b1..3b8c7ceb 100644
--- a/uwsgi.h
+++ b/uwsgi.h
@@ -3492,6 +3492,7 @@ void uwsgi_opt_add_string_list(char *, char *, void *);
void uwsgi_opt_add_addr_list(char *, char *, void *);
void uwsgi_opt_add_string_list_custom(char *, char *, void *);
void uwsgi_opt_add_dyn_dict(char *, char *, void *);
+void uwsgi_opt_binary_append_data(char *, char *, void *);
#ifdef UWSGI_PCRE
void uwsgi_opt_pcre_jit(char *, char *, void *);
void uwsgi_opt_add_regexp_dyn_dict(char *, char *, void *);