[tpop3d-discuss][PATCH] Allow more than one "listen-address" line in tpop3d.conf

Martin Blapp mb at imp.ch
Wed, 2 Feb 2005 01:22:33 +0100 (CET)


This is quite a handy patch if you only have a few servers which need
to have all their fallback domains.

--- config.c	Thu Jan  9 23:59:37 2003
+++ config.c	Tue Feb  1 11:16:49 2005
@@ -34,6 +34,8 @@
     FILE *fp;
     char *line;
     int i = 1;
+    int listencount = 0;
+    char listenbuf[20];

     line = xmalloc(MAX_CONFIG_LINE);

@@ -89,8 +91,15 @@
                 /* Check that this is a valid key. */
                 if (!is_cfgdirective_valid(key))
                     fprintf(stderr, _("%s:%d: warning: unknown directive `%s'\n"), f, i, key);
-                else if ((I = stringmap_insert(S, key, item_ptr(xstrdup(value)))))
-                    fprintf(stderr, _("%s:%d: warning: repeated directive `%s'\n"), f, i, key);
+                else {
+		    if (strcmp(key, "listen-address") == 0) {
+			snprintf(listenbuf, 20, "%s_%d", "listen-address", listencount);
+			key = listenbuf;
+			listencount++;
+		    }
+		    if ((I = stringmap_insert(S, key, item_ptr(xstrdup(value)))))
+			    fprintf(stderr, _("%s:%d: warning: repeated directive `%s'\n"), f, i, key);
+		}
             }
         }

--- main.c	Mon Nov 24 20:58:28 2003
+++ main.c	Tue Feb  1 10:59:08 2005
@@ -285,6 +285,8 @@
             } else memcpy(&sin.sin_addr, he->h_addr, sizeof sin.sin_addr);
         }

+	if (verbose)
+		log_print(LOG_ERR, _("parse_listeners: `%s': prepare listen for address `%s'"), s, host);

         if ((L = listener_new(&sin, domain
 #ifdef MASS_HOSTING
@@ -342,6 +344,7 @@

 int main(int argc, char **argv, char **envp) {
     int nodaemon = 0;
+    int i;
     char *configfile = CONFIG_DIR"/tpop3d.conf", *s;
     int na, c;
 #ifdef USE_TLS
@@ -472,11 +475,24 @@
     }

     /* Identify addresses on which to listen.
-     * The syntax for these is <addr>[:port][(domain)]. */
-    s = config_get_string("listen-address");
+     * The syntax for these is <addr>[:port][(domain)].
+     */
     listeners = vector_new();
-    if (s)
-        parse_listeners(s);
+    for (i=0; i != -1 && i <= 99; i++) {
+	    char listenstring[20];
+
+	    if (i == 99)
+                log_print(LOG_ERR, _("listen-address can only have 99 entries"));
+
+	    snprintf(listenstring, 20, "%s_%d", "listen-address", i);
+	    s = config_get_string(listenstring);
+	    if (verbose)
+                log_print(LOG_DEBUG, _("Parsed listen entry %s"), listenstring);
+	    if (s)
+		parse_listeners(s);
+	    else
+		break;
+    }

     if (listeners->n_used == 0) {
         log_print(LOG_ERR, _("%s: no listen addresses obtained; exiting"), configfile);

Martin Blapp, <mb@imp.ch> <mbr@FreeBSD.org>
------------------------------------------------------------------
ImproWare AG, UNIXSP & ISP, Zurlindenstrasse 29, 4133 Pratteln, CH
Phone: +41 61 826 93 00 Fax: +41 61 826 93 01
PGP: <finger -l mbr@freebsd.org>
PGP Fingerprint: B434 53FC C87C FE7B 0A18 B84C 8686 EF22 D300 551E
------------------------------------------------------------------