diff --git a/src/session/download.c b/src/session/download.c index c04ebcbb5..b0d573809 100644 --- a/src/session/download.c +++ b/src/session/download.c @@ -31,6 +31,7 @@ #include "dialogs/menu.h" #include "intl/gettext/libintl.h" #include "main/object.h" +#include "main/select.h" #include "mime/mime.h" #include "network/connection.h" #include "network/progress.h" @@ -973,6 +974,24 @@ tp_display(struct type_query *type_query) done_type_query(type_query); } +static void +read_from_popen(struct type_query *type_query, unsigned char *handler) +{ + FILE *pop = popen(handler, "r"); + + if (pop) { + int fd = fileno(pop); + + if (fd > 0) { + struct session *ses = type_query->ses; + unsigned char buf[48]; + + snprintf(buf, 48, "file:///dev/fd/%d", fd); + goto_url(ses, buf); + } + } +} + static void tp_open(struct type_query *type_query) { @@ -991,7 +1010,10 @@ tp_open(struct type_query *type_query) } if (handler) { - exec_on_terminal(type_query->ses->tab->term, + if (type_query->copiousoutput) + read_from_popen(type_query, handler); + else + exec_on_terminal(type_query->ses->tab->term, handler, "", !!type_query->block); mem_free(handler); } @@ -1078,7 +1100,7 @@ do_type_query(struct type_query *type_query, unsigned char *ct, struct mime_hand if (handler && handler->program) { int programlen = strlen(handler->program); - programlen = int_max(programlen, MAX_STR_LEN); + programlen = int_min(programlen, MAX_STR_LEN); memcpy(field, handler->program, programlen); } @@ -1208,7 +1230,7 @@ setup_download_handler(struct session *ses, struct download *loading, type_query = init_type_query(ses, loading, cached); if (type_query) { ret = 1; - type_query->copiousoutput = handler->copiousoutput; + if (handler) type_query->copiousoutput = handler->copiousoutput; #ifdef CONFIG_BITTORRENT /* A terrible waste of a good MIME handler here, but we want * to use the type_query this is easier. */