summaryrefslogtreecommitdiffstats
path: root/network/elinks/patches/0003-gopher_directory_links.patch
blob: dc80ef3728549efcfe013f98dc75b8b8bf741137 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#######################################################################
# elinks does not follow links to directories on other servers
# properly. This adds a '/' before the '1' at the start of a link and 
# removes any trailing 1.
# dave@dawoodfall.net
#######################################################################
diff -Naur a/src/protocol/gopher/gopher.c b/src/protocol/gopher/gopher.c
--- a/src/protocol/gopher/gopher.c	2017-12-17 01:54:27.941645180 +0000
+++ b/src/protocol/gopher/gopher.c	2017-12-17 21:52:05.072454433 +0000
@@ -317,6 +317,9 @@
 	unsigned char *URL = "hURL%3";
 	unsigned char *CURI = "HURI%3";
 	unsigned char *CURL = "HURL%3";
+	unsigned char *DIR = "1";
+	unsigned char *SLASHDIR = "/1";
+	unsigned char *SLASHPOS;
 	int selectorlen = conn->uri->datalen;
 	struct gopher_entity_info *entity_info;
 	size_t size;
@@ -354,6 +357,26 @@
 		selectorlen++;
 	}
 
+	if (entity_info->type == '1')
+	{
+		if (strstr(selector, DIR) == selector)
+		{
+			*selector++;
+			selectorlen--;
+		}
+		else
+		{
+			SLASHPOS = strstr(selector, SLASHDIR);
+			if (SLASHPOS != NULL)
+			{
+				if (strlen(SLASHPOS) == 2)
+				{
+					selectorlen--;
+				}
+			}
+		}
+	}
+
 	state = add_gopher_command(conn, &command, entity, selector, selectorlen);
 	if (!is_in_state(state, S_CONN))
 		return state;
@@ -379,10 +402,10 @@
 	gopher->entity = entity_info;
 	gopher->commandlen = command.length;
 
-debug_log("439 gopher->entity:", 1);
-debug_log(gopher->entity, 1);
-debug_log("437 command.source:", 1);
-debug_log(command.source, 1);
+	debug_log("439 gopher->entity: ", 0);
+	debug_log(gopher->entity, 1);
+	debug_log("437 command.source: ", 0);
+	debug_log(command.source, 1);
 	memcpy(gopher->command, command.source, command.length);
 	done_string(&command);