1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-28 03:06:20 -04:00

meaningful default save name for data: uri content

This commit is contained in:
sgerwk 2020-09-28 20:10:55 +02:00
parent 3dd17876a1
commit 90a141be2b

View File

@ -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;