summaryrefslogtreecommitdiff
path: root/network/elinks/patches/0006-indexes_nocr.patch
blob: 5c68cee8caa99315ba637ed5f63e78a6cf9b5709 (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
62
#######################################################################
# Fixes index listings with only LF and no CRs.
# 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-29 17:14:24.247093626 +0000
+++ b/src/protocol/gopher/gopher.c	2017-12-29 17:12:08.496272595 +0000
@@ -638,15 +638,16 @@
 static unsigned char *
 get_gopher_line_end(unsigned char *data, int datalen)
 {
-	for (; datalen > 1; data++, datalen--)
-		if (data[0] == ASCII_CR && data[1] == ASCII_LF)
+	for (; datalen > 1; data++, datalen--) {
+		if (data[0] == ASCII_CR && data[1] == ASCII_LF)
 			return data + 2;
 		else
 			if(data[0] == ASCII_CR)
-				return data + 2;
-		else
-			if(data[0] == ASCII_LF)
-				return data + 2;
+				return data + 1;
+			else
+				if(data[0] == ASCII_LF)
+					return data + 1;
+	}
 
 	return NULL;
 }
@@ -796,9 +797,21 @@
 
 	/* Now read the data from the socket */
 	switch (gopher->entity->type) {
+	case GOPHER_INDEX:
+		/* Lines with no carriage returns */
+		if (strchr(rb->data, ASCII_CR) == NULL) {
+			unsigned char *tmp;
+			tmp = malloc(rb->length + 3);
+			memcpy(tmp, "i", 1);
+			memcpy(tmp+1, rb->data, rb->length);
+			tmp[rb->length]= '\r';
+			tmp[rb->length+1]= '\n';
+			rb->length+=3;
+			memcpy(rb->data, tmp, rb->length);
+			free(tmp);
+		}
+
 	case GOPHER_DIRECTORY:
-/* Don't do directory list for cgi output (7)
-	case GOPHER_INDEX: */
 		state = read_gopher_directory_data(conn, rb);
 		break;
 
@@ -810,7 +823,6 @@
 		state = connection_state(S_GOPHER_CSO_ERROR);
 		break;
 
-	case GOPHER_INDEX:
 	case GOPHER_SOUND:
 	case GOPHER_PLUS_SOUND:
 	case GOPHER_PLUS_MOVIE: