From 90a141be2b0aa79bbc18976da7809921eea43d4e Mon Sep 17 00:00:00 2001 From: sgerwk Date: Mon, 28 Sep 2020 20:10:55 +0200 Subject: [PATCH] meaningful default save name for data: uri content --- src/protocol/uri.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/protocol/uri.c b/src/protocol/uri.c index 2271892b..56fbe0cf 100644 --- a/src/protocol/uri.c +++ b/src/protocol/uri.c @@ -611,6 +611,14 @@ add_uri_to_string(struct string *string, const struct uri *uri, if (!uri->datalen) return string; + if (uri->protocol == PROTOCOL_DATA) { + char *e; + add_bytes_to_string(string, + "data", sizeof("data") - 1); + e = get_extension_from_uri((struct uri *) uri); + return add_bytes_to_string(string, e, strlen(e)); + } + for (pos = filename; *pos && !end_of_dir(*pos); pos++) if (wants(URI_FILENAME) && is_uri_dir_sep(uri, *pos)) filename = pos + 1; @@ -1316,6 +1324,10 @@ get_translated_uri(unsigned char *uristring, unsigned char *cwd) return uri; } +#define ADD_EXTENSION_FROM_TYPE(string, type, ext) \ + if (!memcmp(uri->data, type ";", sizeof(type ";") - 1) || \ + !memcmp(uri->data, type ",", sizeof(type ",") - 1)) \ + return strdup("." ext); unsigned char * get_extension_from_uri(struct uri *uri) @@ -1326,6 +1338,15 @@ get_extension_from_uri(struct uri *uri) assert(pos); + if (uri->protocol == PROTOCOL_DATA) { + ADD_EXTENSION_FROM_TYPE(uri->data, "image/gif", "gif") + ADD_EXTENSION_FROM_TYPE(uri->data, "image/jpeg", "jpg") + ADD_EXTENSION_FROM_TYPE(uri->data, "image/png", "png") + ADD_EXTENSION_FROM_TYPE(uri->data, "text/plain", "txt") + ADD_EXTENSION_FROM_TYPE(uri->data, "text/html", "html") + return ""; + } + for (; *pos && !end_of_dir(*pos); pos++) { if (!afterslash && !extension && *pos == '.') { extension = pos;