#######################################################################
# elinks by default generates its own search query form when it sees
# a type 7 index entity. The problem is that it didn't read the
# served results page and instead generated another search page after
# you had entered the first. This patch fixes that and in my tests it
# seems to work so far. I've also added a primitive debug log.
# dave@slackbuilds.org
#######################################################################
diff -Naur a/src/protocol/gopher/gopher.c b/src/protocol/gopher/gopher.c
--- a/src/protocol/gopher/gopher.c 2020-01-08 05:37:57.443382095 +0000
+++ b/src/protocol/gopher/gopher.c 2020-01-08 05:36:42.849199857 +0000
@@ -43,6 +43,34 @@
#include "util/memory.h"
#include "util/string.h"
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h> /* OS/2 needs this after sys/types.h */
+#endif
+
+/* To enable logging for debugging purposes. */
+#if 0
+
+#define LOGFILE "/tmp/log"
+
+static void
+debug_log(unsigned char *data, int NL)
+{
+ int fd = open(LOGFILE, O_WRONLY | O_APPEND | O_CREAT, 0622);
+
+ if (fd == -1) return;
+
+ set_bin(fd);
+ write(fd, data, strlen(data));
+ if (NL)
+ write(fd, "\n", 1);
+ close(fd);
+}
+#undef LOGFILE
+
+#else
+#define debug_log(data, len)
+#endif
+
struct module gopher_protocol_module = struct_module(
/* name: */ N_("Gopher"),
/* options: */ NULL,
@@ -219,11 +247,13 @@
if (query) selectorlen -= 1;
query = NULL;
querylen = 0;
- } else {
- query += 1;
+ } else if (entity == GOPHER_INDEX) {
+ /* fix query size to not include the search= part */
+ query += 8;
querylen = selector + selectorlen - query;
/* Exclude '?' */
- selectorlen -= querylen + 1;
+ /* fix selector length to fit with query */
+ selectorlen -= querylen + 8;
if (querylen >= 7 && !c_strncasecmp(query, "search=", 7)) {
query += 7;
querylen -= 7;
@@ -233,9 +263,11 @@
switch (entity) {
case GOPHER_INDEX:
/* No search required? */
+ /* Don't display the form page */
if (!query) {
done_string(command);
- return init_gopher_index_cache_entry(conn);
+ add_uri_decoded(command, selector, selectorlen, 0);
+ break;
}
add_uri_decoded(command, selector, selectorlen, 0);
@@ -371,13 +403,14 @@
add_gopher_search_field(struct string *buffer, const unsigned char *text,
const unsigned char *addr)
{
+ /* Not *every* query is a search */
add_format_to_string(buffer,
"<form action=\"%s\">"
"<table>"
"<td> </td>"
"<td>%s:</td>"
"<td><input maxlength=\"256\" name=\"search\" value=\"\"></td>"
- "<td><input type=submit value=\"Search\"></td>"
+ "<td><input type=submit value=\"Submit\"></td>"
"</table>"
"</form>",
addr, text);
|