]> source.dussan.org Git - rspamd.git/commitdiff
Allow multiply bind configurations.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 15 Sep 2013 23:48:38 +0000 (00:48 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 15 Sep 2013 23:48:38 +0000 (00:48 +0100)
src/cfg_file.h
src/cfg_utils.c
src/cfg_xml.c
src/main.c

index 829b4b453ee1db42b2053443ca2fa3843c21a7b1..bfbc0efa92b75c0a0560ad7b0774144c753e6d2f 100644 (file)
@@ -11,6 +11,7 @@
 #include "upstream.h"
 #include "memcached.h"
 #include "symbols_cache.h"
+#include "utlist.h"
 
 #define DEFAULT_BIND_PORT 768
 #define DEFAULT_CONTROL_PORT 7608
@@ -245,6 +246,12 @@ struct config_scalar {
     } type;                                                                                    /**< type of data                                                                               */
 };
 
+struct rspamd_worker_bind_conf {
+       gchar *bind_host;
+       guint16 bind_port;
+       gboolean is_unix;
+       struct rspamd_worker_bind_conf *next;
+};
 
 /**
  * Config params for rspamd worker
@@ -252,10 +259,7 @@ struct config_scalar {
 struct worker_conf {
        worker_t *worker;                                                               /**< pointer to worker type                                                             */
        GQuark type;                                                                    /**< type of worker                                                                             */
-       gchar *bind_host;                                                               /**< bind line                                                                                  */
-       gchar *bind_addr;                                                               /**< bind address in case of TCP socket                                 */
-       guint16 bind_port;                                                              /**< bind port in case of TCP socket                                    */
-       guint16 bind_family;                                                    /**< bind type (AF_UNIX or AF_INET)                                             */
+       struct rspamd_worker_bind_conf *bind_conf;              /**< bind configuration                                                                 */
        guint16 count;                                                                  /**< number of workers                                                                  */
        GList *listen_socks;                                                    /**< listening sockets desctiptors                                              */
        guint32 rlimit_nofile;                                                  /**< max files limit                                                                    */
@@ -407,7 +411,7 @@ gboolean parse_host_priority (memory_pool_t *pool, const gchar *str, gchar **add
  * @param type type of credits
  * @return 1 if line was successfully parsed and 0 in case of error
  */
-gint parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str);
+gboolean parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str);
 
 /**
  * Init default values
index 6bdb3c8f7136a1c6a18919f22342a55f8d0593c7..e7e57cd8a526a4e048f267f1a03321fa38aef03a 100644 (file)
@@ -163,21 +163,16 @@ parse_host_priority (memory_pool_t *pool, const gchar *str, gchar **addr, guint
        return parse_host_port_priority (pool, str, addr, NULL, priority);
 }
 
-gint
+gboolean
 parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str)
 {
-       gchar                          **host;
-       guint16                        *family, *port;
-       gchar                          **addr;
+       struct rspamd_worker_bind_conf *cnf;
 
        if (str == NULL)
                return 0;
 
-       host = &cf->bind_host;
-       port = &cf->bind_port;
-       *port = DEFAULT_BIND_PORT;
-       family = &cf->bind_family;
-       addr = &cf->bind_addr;
+       cnf = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_bind_conf));
+       cnf->bind_port = DEFAULT_BIND_PORT;
 
        if (str[0] == '/' || str[0] == '.') {
 #ifdef HAVE_DIRNAME
@@ -189,7 +184,7 @@ parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str)
                        if (errno == ENOENT) {
                                if ((fd = open (str, O_RDWR | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR)) == -1) {
                                        msg_err ("cannot open path %s for making socket, %s", str, strerror (errno));
-                                       return 0;
+                                       return FALSE;
                                }
                                else {
                                        close (fd);
@@ -208,21 +203,20 @@ parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str)
                        }
                }
 #endif
-               *host = memory_pool_strdup (cfg->cfg_pool, str);
-               *addr = *host;
-               *family = AF_UNIX;
-               return 1;
+               cnf->bind_host = memory_pool_strdup (cfg->cfg_pool, str);
+               cnf->is_unix = TRUE;
+               LL_PREPEND (cf->bind_conf, cnf);
+               return TRUE;
        }
        else {
-               if (parse_host_port (cfg->cfg_pool, str, addr, port)) {
-                       *host = memory_pool_strdup (cfg->cfg_pool, str);
-                       *family = AF_INET;
-
-                       return 1;
+               cnf->bind_host = memory_pool_strdup (cfg->cfg_pool, str);
+               if (parse_host_port (cfg->cfg_pool, str, &cnf->bind_host, &cnf->bind_port)) {
+                       LL_PREPEND (cf->bind_conf, cnf);
+                       return TRUE;
                }
        }
 
-       return 0;
+       return FALSE;
 }
 
 void
index 0393f026c59dde0f1b5fc071e310390c2c5b197e..fc7245390e339f63a4dda50bfb27c5729876f4dc 100644 (file)
@@ -2748,9 +2748,6 @@ xml_dump_workers (struct config_file *cfg, FILE *f)
                rspamd_fprintf (f, "<worker>" EOL);
 
                rspamd_fprintf (f, "  <type>%s</type>" EOL, g_quark_to_string (wrk->type));
-               escaped_str = g_markup_escape_text (wrk->bind_host, -1); 
-               rspamd_fprintf (f, "  <bind_socket>%s</bind_socket>" EOL, escaped_str);
-               g_free (escaped_str);
 
                rspamd_fprintf (f, "  <count>%ud</count>" EOL, wrk->count);
                rspamd_fprintf (f, "  <maxfiles>%ud</maxfiles>" EOL, wrk->rlimit_nofile);
index cab81c10e6cae1f86a30e42d411d9114b7160fb1..6b593f6389a670bc2790ea4565de3e225c51d840 100644 (file)
@@ -612,6 +612,7 @@ spawn_workers (struct rspamd_main *rspamd)
        struct worker_conf             *cf;
        gint                            i;
        gpointer                        p;
+       struct rspamd_worker_bind_conf *bcf;
 
        cur = rspamd->cfg->workers;
 
@@ -623,23 +624,26 @@ spawn_workers (struct rspamd_main *rspamd)
                }
                else {
                        if (cf->worker->has_socket) {
-                               if ((p = g_hash_table_lookup (listen_sockets, GINT_TO_POINTER (
-                                               make_listen_key (cf->bind_addr, cf->bind_port, cf->bind_family)))) == NULL) {
-                                       /* Create listen socket */
-                                       ls = create_listen_socket (cf->bind_addr, cf->bind_port, cf->bind_family,
-                                                       cf->worker->listen_type);
-                                       if (ls == NULL) {
-                                               exit (-errno);
+                               LL_FOREACH (cf->bind_conf, bcf) {
+                                       if ((p = g_hash_table_lookup (listen_sockets, GINT_TO_POINTER (
+                                                       make_listen_key (bcf->bind_host, bcf->bind_port, bcf->is_unix)))) == NULL) {
+                                               /* Create listen socket */
+                                               ls = create_listen_socket (bcf->bind_host, bcf->bind_port,
+                                                               bcf->is_unix ? AF_UNIX : AF_INET,
+                                                               cf->worker->listen_type);
+                                               if (ls == NULL) {
+                                                       exit (-errno);
+                                               }
+                                               g_hash_table_insert (listen_sockets, GINT_TO_POINTER (
+                                                               make_listen_key (bcf->bind_host, bcf->bind_port, bcf->is_unix)),
+                                                               ls);
                                        }
-                                       g_hash_table_insert (listen_sockets, GINT_TO_POINTER (
-                                                       make_listen_key (cf->bind_addr, cf->bind_port, cf->bind_family)),
-                                                       ls);
-                               }
-                               else {
-                                       /* We had socket for this type of worker */
-                                       ls = p;
+                                       else {
+                                               /* We had socket for this type of worker */
+                                               ls = p;
+                                       }
+                                       cf->listen_socks = g_list_prepend (cf->listen_socks, ls);
                                }
-                               cf->listen_socks = ls;
                        }
 
                        if (cf->worker->unique) {