[tin-dev] [PATCH] add MOTD to nntp_conninfo() ('J')

Urs Janßen urs at tin.org
Tue Dec 12 12:43:04 CET 2023


low hanging fruit ...

=== modified file 'src/nntplib.c'
--- old/src/nntplib.c	2023-12-06 09:12:10 +0000
+++ new/src/nntplib.c	2023-12-12 11:36:29 +0000
@@ -63,7 +63,7 @@
 	static int reconnect(int retry);
 	static int server_init(char *machine, const char *cservice, unsigned short port, char *text, size_t mlen);
 	static void close_server(t_bool send_no_quit);
-	static void list_motd(void);
+	static void list_motd(FILE *stream);
 #	ifdef INET6
 		static int get_tcp6_socket(char *machine, unsigned short port);
 #	else
@@ -1850,7 +1850,7 @@
 		 *   (currently done automatically for -d, -q and -Q)
 		 */
 		if (nntp_caps.list_motd)
-			list_motd();
+			list_motd(NULL);
 	}
 
 	is_reconnect = TRUE;
@@ -2152,7 +2152,7 @@
 
 static void
 list_motd(
-	void)
+	FILE *stream)
 {
 	char *ptr;
 	char *p;
@@ -2167,8 +2167,10 @@
 	switch (i) {
 		case OK_MOTD:
 #	ifdef HAVE_COLOR
-			fcol(tinrc.col_message);
+			if (!stream) /* just on startup */
+				fcol(tinrc.col_message);
 #	endif /* HAVE_COLOR */
+
 			while ((ptr = tin_fgets(FAKE_NNTP_FP, FALSE)) != NULL) {
 #	ifdef DEBUG
 				if (debug & DEBUG_NNTP)
@@ -2176,23 +2178,24 @@
 #	endif /* DEBUG */
 				/*
 				 * RFC 6048 2.5.2 "The information MUST be in UTF-8"
-				 *
-				 * TODO: - store a hash value of the entire motd in the server-rc
-				 *         and only if it differs from the old value display the
-				 *         motd?
-				 *       - use some sort of pager?
 				 */
 				p = my_strdup(ptr);
 				len = strlen(p);
 				process_charsets(&p, &len, "UTF-8", tinrc.mm_local_charset, FALSE);
-				my_printf(_(txt_motd), p);
+				if (stream && !l)
+					fprintf(stream, "\n");
+				if (stream)
+					fprintf(stream, _(txt_motd), p);
+				else
+					my_printf(_(txt_motd), p);
 				free(p);
 				l++;
 			}
 #	ifdef HAVE_COLOR
-			fcol(tinrc.col_normal);
+			if (!stream)
+				fcol(tinrc.col_normal);
 #	endif /* HAVE_COLOR */
-			if (l) {
+			if (l && !stream) { /* no sleep in nntp_conninfo() */
 				my_flush();
 				sleep((l >> 1) | 0x01);
 			}
@@ -2678,6 +2681,7 @@
 
 #undef SZ
 
+
 int
 nntp_conninfo(
 	FILE *stream)
@@ -2716,6 +2720,10 @@
 	fprintf(stream, _(txt_conninfo_timeout), TIN_NNTP_TIMEOUT, TIN_NNTP_TIMEOUT ? "" : _(txt_conninfo_disabled));
 #	endif /* HAVE_ALARM && SIGALRM */
 
+#	ifdef NNTP_ABLE
+	list_motd(stream);
+#	endif /* NNTPS_ABLE */
+
 #	ifdef NNTPS_ABLE
 	if (nntp_buf.tls_ctx)
 		retval = tintls_conninfo(nntp_buf.tls_ctx, stream);




More information about the tin-dev mailing list