mirror of
https://github.com/simon987/sist2.git
synced 2025-04-19 18:26:43 +00:00
Fix files with # character in url redirect
This commit is contained in:
parent
69f0c1f2cf
commit
4109ba6d34
@ -5,7 +5,7 @@
|
|||||||
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
||||||
|
|
||||||
|
|
||||||
static const char *const Version = "1.0.6";
|
static const char *const Version = "1.0.7";
|
||||||
static const char *const usage[] = {
|
static const char *const usage[] = {
|
||||||
"sist2 scan [OPTION]... PATH",
|
"sist2 scan [OPTION]... PATH",
|
||||||
"sist2 index [OPTION]... INDEX",
|
"sist2 index [OPTION]... INDEX",
|
||||||
|
18
src/util.c
18
src/util.c
@ -5,6 +5,24 @@
|
|||||||
#define PBSTR "========================================"
|
#define PBSTR "========================================"
|
||||||
#define PBWIDTH 40
|
#define PBWIDTH 40
|
||||||
|
|
||||||
|
dyn_buffer_t url_escape(char *str) {
|
||||||
|
|
||||||
|
dyn_buffer_t text = dyn_buffer_create();
|
||||||
|
|
||||||
|
char * ptr = str;
|
||||||
|
while (*ptr) {
|
||||||
|
if (*ptr == '#') {
|
||||||
|
dyn_buffer_write(&text, "%23", 3);
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
dyn_buffer_write_char(&text, *ptr++);
|
||||||
|
}
|
||||||
|
dyn_buffer_write_char(&text, '\0');
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
char *abspath(const char *path) {
|
char *abspath(const char *path) {
|
||||||
wordexp_t w;
|
wordexp_t w;
|
||||||
wordexp(path, &w, 0);
|
wordexp(path, &w, 0);
|
||||||
|
@ -149,6 +149,7 @@ int text_buffer_append_char(text_buffer_t *buf, int c) {
|
|||||||
|
|
||||||
char *abspath(const char * path);
|
char *abspath(const char * path);
|
||||||
char *expandpath(const char *path);
|
char *expandpath(const char *path);
|
||||||
|
dyn_buffer_t url_escape(char *str);
|
||||||
|
|
||||||
void progress_bar_print(double percentage, size_t tn_size, size_t index_size);
|
void progress_bar_print(double percentage, size_t tn_size, size_t index_size);
|
||||||
|
|
||||||
|
@ -287,7 +287,10 @@ int serve_file_from_url(cJSON *json, index_t *idx, onion_request *req, onion_res
|
|||||||
"%s%s/%s%s%s",
|
"%s%s/%s%s%s",
|
||||||
idx->desc.rewrite_url, path, name, strlen(ext) == 0 ? "" : ".", ext);
|
idx->desc.rewrite_url, path, name, strlen(ext) == 0 ? "" : ".", ext);
|
||||||
|
|
||||||
return onion_shortcut_redirect(url, req, res);
|
dyn_buffer_t encoded = url_escape(url);
|
||||||
|
int ret = onion_shortcut_redirect(encoded.buf, req, res);
|
||||||
|
dyn_buffer_destroy(&encoded);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int serve_file_from_disk(cJSON *json, index_t *idx, onion_request *req, onion_response *res) {
|
int serve_file_from_disk(cJSON *json, index_t *idx, onion_request *req, onion_response *res) {
|
||||||
@ -301,6 +304,11 @@ int serve_file_from_disk(cJSON *json, index_t *idx, onion_request *req, onion_re
|
|||||||
snprintf(full_path, PATH_MAX, "%s%s/%s%s%s",
|
snprintf(full_path, PATH_MAX, "%s%s/%s%s%s",
|
||||||
idx->desc.root, path, name, strlen(ext) == 0 ? "" : ".", ext);
|
idx->desc.root, path, name, strlen(ext) == 0 ? "" : ".", ext);
|
||||||
|
|
||||||
|
char disposition[8196];
|
||||||
|
snprintf(disposition, sizeof(disposition), "inline; filename=\"%s%s%s\"",
|
||||||
|
name, strlen(ext) == 0 ? "" : ".", ext);
|
||||||
|
onion_response_set_header(res, "Content-Disposition", disposition);
|
||||||
|
|
||||||
return chunked_response_file(full_path, mime, 1, req, res);
|
return chunked_response_file(full_path, mime, 1, req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,13 +358,6 @@ int file(void *p, onion_request *req, onion_response *res) {
|
|||||||
return OCS_NOT_PROCESSED;
|
return OCS_NOT_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *name = cJSON_GetObjectItem(source, "name")->valuestring;
|
|
||||||
const char *ext = cJSON_GetObjectItem(source, "extension")->valuestring;
|
|
||||||
char disposition[8196];
|
|
||||||
snprintf(disposition, sizeof(disposition), "inline; filename=\"%s%s%s\"",
|
|
||||||
name, strlen(ext) == 0 ? "" : ".", ext);
|
|
||||||
onion_response_set_header(res, "Content-Disposition", disposition);
|
|
||||||
|
|
||||||
if (strlen(idx->desc.rewrite_url) == 0) {
|
if (strlen(idx->desc.rewrite_url) == 0) {
|
||||||
return serve_file_from_disk(source, idx, req, res);
|
return serve_file_from_disk(source, idx, req, res);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user