1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

Merge pull request #73 from sgerwk/master

meaningful default save name for data: uri content
This commit is contained in:
rkd77 2020-09-29 11:56:45 +02:00 committed by GitHub
commit 863c59a46c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -611,6 +611,15 @@ add_uri_to_string(struct string *string, const struct uri *uri,
if (!uri->datalen) return string;
if (uri->protocol == PROTOCOL_DATA) {
char *e;
add_to_string(string, "data");
e = get_extension_from_uri((struct uri *) uri);
add_to_string(string, e);
mem_free(e);
return string;
}
for (pos = filename; *pos && !end_of_dir(*pos); pos++)
if (wants(URI_FILENAME) && is_uri_dir_sep(uri, *pos))
filename = pos + 1;
@ -1316,6 +1325,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 stracpy("." ext);
unsigned char *
get_extension_from_uri(struct uri *uri)
@ -1326,6 +1339,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 stracpy("");
}
for (; *pos && !end_of_dir(*pos); pos++) {
if (!afterslash && !extension && *pos == '.') {
extension = pos;