fixed data:// scheme

This commit is contained in:
Unbit
2013-10-07 11:37:52 +02:00
parent 192312e3ea
commit 9fe9fe1bb6
3 changed files with 27 additions and 4 deletions
+5 -4
View File
@@ -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);
+21
View File
@@ -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);
}
+1
View File
@@ -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 *);