From d15439edffba8f705894981ec1064643f9cf2936 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 9 Mar 2008 11:50:09 +0000 Subject: [PATCH] bug 991: Added the bit field cgi to the structs connection and type_query. CGI scripts are distinguishable from normal files. I hope that this fixes the bug 991. This commit also reverts the previous revert. (cherry picked from commit 7ceba1e46131a96ee78ce999dfbe14e359d8cbcb) --- src/network/connection.h | 1 + src/protocol/file/cgi.c | 1 + src/session/download.c | 28 ++++++++++++++++++++++++++++ src/session/download.h | 1 + 4 files changed, 31 insertions(+) diff --git a/src/network/connection.h b/src/network/connection.h index 61931e192..311bbaaf7 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -58,6 +58,7 @@ struct connection { unsigned int unrestartable:1; unsigned int detached:1; unsigned int popen:1; + unsigned int cgi:1; /* Each document is downloaded with some priority. When downloading a * document, the existing connections are checked to see if a diff --git a/src/protocol/file/cgi.c b/src/protocol/file/cgi.c index 75830fb7b..8cb02bb9d 100644 --- a/src/protocol/file/cgi.c +++ b/src/protocol/file/cgi.c @@ -393,6 +393,7 @@ execute_cgi(struct connection *conn) /* Use data socket for passing the pipe. It will be cleaned up in * close_pipe_and_read(). */ conn->data_socket->fd = pipe_write[1]; + conn->cgi = 1; set_nonblocking_fd(conn->socket->fd); set_nonblocking_fd(conn->data_socket->fd); diff --git a/src/session/download.c b/src/session/download.c index a04e82fc3..45f99964f 100644 --- a/src/session/download.c +++ b/src/session/download.c @@ -977,6 +977,9 @@ init_type_query(struct session *ses, struct download *download, { struct type_query *type_query; + assert(download && download->conn); + if_assert_failed return NULL; + /* There can be only one ... */ foreach (type_query, ses->type_queries) if (compare_uri(type_query->uri, ses->loading_uri, 0)) @@ -990,6 +993,7 @@ init_type_query(struct session *ses, struct download *download, type_query->target_frame = null_or_stracpy(ses->task.target.frame); type_query->cached = cached; + type_query->cgi = download->conn->cgi; object_lock(type_query->cached); move_download(download, &type_query->download, PRI_MAIN); @@ -1088,6 +1092,30 @@ tp_open(struct type_query *type_query) return; } + if (type_query->uri->protocol == PROTOCOL_FILE && !type_query->cgi) { + unsigned char *file = get_uri_string(type_query->uri, URI_PATH); + unsigned char *handler = NULL; + + if (file) { + decode_uri(file); + handler = subst_file(type_query->external_handler, file); + mem_free(file); + } + + if (handler) { + if (type_query->copiousoutput) + read_from_popen(type_query->ses, handler, NULL); + else + exec_on_terminal(type_query->ses->tab->term, + handler, "", + type_query->block ? TERM_EXEC_FG : TERM_EXEC_BG); + mem_free(handler); + } + + done_type_query(type_query); + return; + } + continue_download(type_query, ""); } diff --git a/src/session/download.h b/src/session/download.h index 79923d2ef..39fb29041 100644 --- a/src/session/download.h +++ b/src/session/download.h @@ -49,6 +49,7 @@ struct type_query { unsigned char *external_handler; int block; unsigned int copiousoutput:1; + unsigned int cgi:1; /* int frame; */ };