mirror of
https://github.com/Ponce/slackbuilds
synced 2024-11-07 20:27:02 +01:00
47 lines
1.5 KiB
Diff
47 lines
1.5 KiB
Diff
###################################################################
|
|
# Encode < > to HTML.
|
|
###################################################################
|
|
diff -Naur '--exclude=.git' bb/src/protocol/gopher/gopher.c cc/src/protocol/gopher/gopher.c
|
|
--- bb/src/protocol/gopher/gopher.c 2020-01-14 03:26:41.791778387 +0000
|
|
+++ cc/src/protocol/gopher/gopher.c 2020-01-14 06:19:56.964025440 +0000
|
|
@@ -620,6 +620,25 @@
|
|
return line[0] == '.' && !line[1] ? NULL : line;
|
|
}
|
|
|
|
+/* substring replacement */
|
|
+static void
|
|
+str_replace(char * in_string, char * s_string, char * r_string)
|
|
+{
|
|
+ /* max == replace all characters */
|
|
+ char temp[strlen(in_string) * (strlen(r_string) - strlen(s_string)) + 1];
|
|
+ char * pos;
|
|
+
|
|
+ if (!(pos = strstr(in_string, s_string)))
|
|
+ return;
|
|
+
|
|
+ strncpy(temp, in_string, pos - in_string);
|
|
+ temp[pos - in_string] = 0;
|
|
+ sprintf(temp + (pos - in_string), "%s%s", r_string, pos + 1);
|
|
+ in_string[0] = 0;
|
|
+ strcpy(in_string, temp);
|
|
+ return str_replace(in_string, s_string, r_string);
|
|
+}
|
|
+
|
|
/* Parse a Gopher Menu document */
|
|
static struct connection_state
|
|
read_gopher_directory_data(struct connection *conn, struct read_buffer *rb)
|
|
@@ -639,6 +658,14 @@
|
|
return connection_state(S_OUT_OF_MEM);
|
|
}
|
|
|
|
+ /* Lines with characters that need to be converted to html */
|
|
+ if (strstr(rb->data, "<")) {
|
|
+ str_replace(rb->data, "<", "<");
|
|
+ }
|
|
+ if (strstr(rb->data, ">")) {
|
|
+ str_replace(rb->data, ">", ">");
|
|
+ }
|
|
+
|
|
while ((end = get_gopher_line_end(rb->data, rb->length))) {
|
|
unsigned char *line = check_gopher_last_line(rb->data, end);
|
|
|