move router infos to individual driver files
authorJeremy Harris <jgh146exb@wizmail.org>
Tue, 13 Aug 2024 12:14:12 +0000 (13:14 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Wed, 14 Aug 2024 09:51:22 +0000 (10:51 +0100)
src/src/drtables.c
src/src/lookups/cdb.c
src/src/route.c
src/src/routers/accept.c
src/src/routers/dnslookup.c
src/src/routers/ipliteral.c
src/src/routers/iplookup.c
src/src/routers/manualroute.c
src/src/routers/queryprogram.c
src/src/routers/redirect.c
src/src/structs.h

index 9225fafe1958f6401d4c01bc932da0849a1213b4..1a3a804601e50eeeb5903afd35fc865cc4548bde 100644 (file)
@@ -230,10 +230,7 @@ exim binary. */
 
 #include "routers/rf_functions.h"
 
-#ifdef ROUTER_ACCEPT
-# include "routers/accept.h"
-#endif
-
+/*XXX delete */
 #ifdef ROUTER_DNSLOOKUP
 # include "routers/dnslookup.h"
 #endif
@@ -288,96 +285,6 @@ router_info * routers_available_newlist = NULL;
 /* Now set up the structures, terminated by an entry with a null name. */
 
 router_info routers_available_oldarray[] = {
-#ifdef ROUTER_ACCEPT
-  {
-  .drinfo = {
-    .driver_name =     US"accept",
-    .options =         accept_router_options,
-    .options_count =   &accept_router_options_count,
-    .options_block =   &accept_router_option_defaults,
-    .options_len =     sizeof(accept_router_options_block),
-    .init =            accept_router_init,
-    },
-  .code =              accept_router_entry,
-  .tidyup =            NULL,     /* no tidyup entry */
-  .ri_flags =          ri_yestransport
-  },
-#endif
-#ifdef ROUTER_DNSLOOKUP
-  {
-  .drinfo = {
-    .driver_name =     US"dnslookup",
-    .options =         dnslookup_router_options,
-    .options_count =   &dnslookup_router_options_count,
-    .options_block =   &dnslookup_router_option_defaults,
-    .options_len =     sizeof(dnslookup_router_options_block),
-    .init =            dnslookup_router_init,
-    },
-  .code =              dnslookup_router_entry,
-  .tidyup =            NULL,     /* no tidyup entry */
-  .ri_flags =          ri_yestransport
-  },
-#endif
-#ifdef ROUTER_IPLITERAL
-  {
-  .drinfo = {
-    .driver_name =     US"ipliteral",
-    .options =         ipliteral_router_options,
-    .options_count =   &ipliteral_router_options_count,
-    .options_block =   &ipliteral_router_option_defaults,
-    .options_len =     sizeof(ipliteral_router_options_block),
-    .init =            ipliteral_router_init,
-    },
-  .code =              ipliteral_router_entry,
-  .tidyup =            NULL,     /* no tidyup entry */
-  .ri_flags =          ri_yestransport
-  },
-#endif
-#ifdef ROUTER_IPLOOKUP
-  {
-  .drinfo = {
-    .driver_name =     US"iplookup",
-    .options =         iplookup_router_options,
-    .options_count =   &iplookup_router_options_count,
-    .options_block =   &iplookup_router_option_defaults,
-    .options_len =     sizeof(iplookup_router_options_block),
-    .init =            iplookup_router_init,
-    },
-  .code =              iplookup_router_entry,
-  .tidyup =            NULL,     /* no tidyup entry */
-  .ri_flags =          ri_notransport
-  },
-#endif
-#ifdef ROUTER_MANUALROUTE
-  {
-  .drinfo = {
-    .driver_name =     US"manualroute",
-    .options =         manualroute_router_options,
-    .options_count =   &manualroute_router_options_count,
-    .options_block =   &manualroute_router_option_defaults,
-    .options_len =     sizeof(manualroute_router_options_block),
-    .init =            manualroute_router_init,
-    },
-  .code =              manualroute_router_entry,
-  .tidyup =            NULL,     /* no tidyup entry */
-  .ri_flags =          0
-  },
-#endif
-#ifdef ROUTER_REDIRECT
-  {
-  .drinfo = {
-    .driver_name =     US"redirect",
-    .options =         redirect_router_options,
-    .options_count =   &redirect_router_options_count,
-    .options_block =   &redirect_router_option_defaults,
-    .options_len =     sizeof(redirect_router_options_block),
-    .init =            redirect_router_init,
-    },
-  .code =              redirect_router_entry,
-  .tidyup =            NULL,     /* no tidyup entry */
-  .ri_flags =          ri_notransport
-  },
-#endif
   { .drinfo = { .driver_name = US"" }}
 };
 
index 696e520194cb736edfd3abe04e9d3e0e7e0dc5a5..a0f668b983275d8f19321668475184fe8db33c34 100644 (file)
@@ -482,7 +482,7 @@ lookup_info cdb_lookup_info = {
 };
 
 #ifdef DYNLOOKUP
-#define cdb_lookup_module_info _lookup_module_info
+# define cdb_lookup_module_info _lookup_module_info
 #endif
 
 static lookup_info *_lookup_list[] = { &cdb_lookup_info };
index c0cc1fee9724b08513a60601a49d8161b35848f1..cce1209671e7c8a5f2aa54de27e7dcd7ce8efecd 100644 (file)
@@ -220,6 +220,17 @@ if (after && !afterthis)
 *             Initialize router list             *
 *************************************************/
 
+/*XXX will likely want to rename to generic */
+
+static void
+add_router(driver_info ** drlist_p, const driver_info * newent, size_t size)
+{
+driver_info * listent = store_get(size, newent);
+memcpy(listent, newent, size);
+listent->next = *drlist_p;
+*drlist_p= listent;
+}
+
 /* Read the routers section of the configuration file, and set up a chain of
 router instances according to its contents. Each router has generic options and
 may also have its own private options. This function is only ever called when
@@ -230,10 +241,9 @@ function. */
 void
 route_init(void)
 {
-/*XXX temp loop just copying the old array to build the new list.
-Will replace with haul from either static build file or dyn module
-done by readconf_driver_init() */
 
+#ifdef old
+/*XXX temp loop just copying the old array to build the new list. */
 for (router_info * tblent = routers_available_oldarray;
     *tblent->drinfo.driver_name; tblent++)
   {
@@ -242,7 +252,58 @@ for (router_info * tblent = routers_available_oldarray;
   listent->next = (driver_info *)routers_available_newlist;
   routers_available_newlist = (router_info *)listent;
   }
+#else
+
+/*XXX
+Will replace with ifdeffed explicit calls in drtab.c just building list
+(2 lists?) of names for -bV (DONE),
+plut ifdeffed repeated code here adding static-build modules to list (DONE)
+plus code in readconf.c for dlopen()s just before per-driver init api call.
+*/
+
+int old_pool = store_pool;
+store_pool = POOL_PERM;
+  {
+  driver_info ** anchor = (driver_info **) &routers_available_newlist;
+  extern router_info accept_router_info;
+  extern router_info dnslookup_router_info;
+  extern router_info ipliteral_router_info;
+  extern router_info iplookup_router_info;
+  extern router_info manualroute_router_info;
+  extern router_info redirect_router_info;
+  extern router_info queryprogram_router_info;
+
+  /*XXX this addsonly the statics.  We can't get the dynamics as they
+  are not linked.  Until dlopen(), when we can use dlsym().  So the discovery
+  is by the file exitence, via the filename pattern. */
+  /*XXX TODO: move the info structs to individual driver files */
+#if defined(ROUTER_ACCEPT) && ROUTER_ACCEPT!=2
+  add_router(anchor, &accept_router_info.drinfo, sizeof(router_info));
+#endif
+#if defined(ROUTER_DNSLOOKUP) && ROUTER_DNSLOOKUP!=2
+  add_router(anchor, &dnslookup_router_info.drinfo, sizeof(router_info));
+#endif
+# if defined(ROUTER_IPLITERAL) && ROUTER_IPLITERAL!=2
+  add_router(anchor, &ipliteral_router_info.drinfo, sizeof(router_info));
+#endif
+#if defined(ROUTER_IPLOOKUP) && ROUTER_IPLOOKUP!=2
+  add_router(anchor, &iplookup_router_info.drinfo, sizeof(router_info));
+#endif
+#if defined(ROUTER_MANUALROUTE) && ROUTER_MANUALROUTE!=2
+  add_router(anchor, &manualroute_router_info.drinfo, sizeof(router_info));
+#endif
+#if defined(ROUTER_REDIRECT) && ROUTER_REDIRECT!=2
+  add_router(anchor, &redirect_router_info.drinfo, sizeof(router_info));
+#endif
+#if defined(ROUTER_QUERYPROGRAM) && ROUTER_QUERYPROGRAM!=2
+  add_router(anchor, &queryprogram_router_info.drinfo, sizeof(router_info));
+#endif
+  }
+store_pool = old_pool;
+
+#endif /*!old*/
 
+/*XXX this does the config file "routers" section reading */
 readconf_driver_init((driver_instance **)&routers,     /* chain anchor */
   (driver_info *)routers_available_newlist,   /* available drivers */
   sizeof(router_info),                /* size of info blocks */
index 6cbde6decefbbbb92c3fb395268115f2e5ce53be..353d1762c69f3c505c4f1134ef837bcbe03d18df 100644 (file)
@@ -140,6 +140,30 @@ addr->prop.remove_headers = remove_headers;
 return rf_queue_add(addr, addr_local, addr_remote, rblock, pw) ? OK : DEFER;
 }
 
+
+
+# ifdef DYNLOOKUP
+#  define accept_router_info _router_info
+# endif
+
+router_info accept_router_info =
+{
+.drinfo = {
+  .driver_name =       US"accept",
+  .options =           accept_router_options,
+  .options_count =     &accept_router_options_count,
+  .options_block =     &accept_router_option_defaults,
+  .options_len =       sizeof(accept_router_options_block),
+  .init =              accept_router_init,
+# ifdef DYNLOOKUP
+  .dyn_magic =         ROUTER_MAGIC,           /*XXX*/
+# endif
+  },
+.code =                accept_router_entry,
+.tidyup =              NULL,     /* no tidyup entry */
+.ri_flags =            ri_yestransport
+};
+
 #endif /*!MACRO_PREDEF*/
 #endif /*ROUTER_ACCEPT*/
 
index 8a6f72d5d65f270824628598338cad8f0d25b93d..90ea0f6131059142091e4cc195db499a7943c367 100644 (file)
@@ -475,6 +475,31 @@ addr->transport = rblock->transport;
 return rf_queue_add(addr, addr_local, addr_remote, rblock, pw) ?  OK : DEFER;
 }
 
+
+
+
+# ifdef DYNLOOKUP
+#  define dnslookup_router_info _router_info
+# endif
+
+router_info dnslookup_router_info =
+{
+.drinfo = {
+  .driver_name =       US"dnslookup",
+  .options =           dnslookup_router_options,
+  .options_count =     &dnslookup_router_options_count,
+  .options_block =     &dnslookup_router_option_defaults,
+  .options_len =       sizeof(dnslookup_router_options_block),
+  .init =              dnslookup_router_init,
+# ifdef DYNLOOKUP
+  .dyn_magic =         ROUTER_MAGIC,           /*XXX*/
+# endif
+  },
+.code =                        dnslookup_router_entry,
+.tidyup =              NULL,     /* no tidyup entry */
+.ri_flags =            ri_yestransport
+};
+
 #endif /*!MACRO_PREDEF*/
 #endif /*ROUTER_DNSLOOKUP*/
 /* End of routers/dnslookup.c */
index 790ef15f0816c52e4f3a96dc7d30268ca4455bd4..a5ef20d32530c8c88d1a02aafbcb663bca377f39 100644 (file)
@@ -201,6 +201,30 @@ return rf_queue_add(addr, addr_local, addr_remote, rblock, pw)?
   OK : DEFER;
 }
 
+
+
+# ifdef DYNLOOKUP
+#  define ipliteral_router_info _router_info
+# endif
+
+router_info ipliteral_router_info =
+{
+.drinfo = {
+  .driver_name =       US"ipliteral",
+  .options =           ipliteral_router_options,
+  .options_count =     &ipliteral_router_options_count,
+  .options_block =     &ipliteral_router_option_defaults,
+  .options_len =       sizeof(ipliteral_router_options_block),
+  .init =              ipliteral_router_init,
+# ifdef DYNLOOKUP
+  .dyn_magic =         ROUTER_MAGIC,           /*XXX*/
+# endif
+  },
+.code =                        ipliteral_router_entry,
+.tidyup =              NULL,     /* no tidyup entry */
+.ri_flags =            ri_yestransport
+};
+
 #endif /*!MACRO_PREDEF*/
 #endif /*ROUTER_IPLITERAL*/
 /* End of routers/ipliteral.c */
index 26e9b7ce7c0f2cc97c1964e5443b4763d6ba27f8..24362fa8873430991a9e74a6bf62e7238ec2bb1b 100644 (file)
@@ -417,6 +417,30 @@ if (rc != OK) return rc;
 return OK;
 }
 
+
+
+# ifdef DYNLOOKUP
+#  define iplookup_router_info _router_info
+# endif
+
+router_info iplookup_router_info =
+{
+.drinfo = {
+  .driver_name =       US"iplookup",
+  .options =           iplookup_router_options,
+  .options_count =     &iplookup_router_options_count,
+  .options_block =     &iplookup_router_option_defaults,
+  .options_len =       sizeof(iplookup_router_options_block),
+  .init =              iplookup_router_init,
+# ifdef DYNLOOKUP
+  .dyn_magic =         ROUTER_MAGIC,           /*XXX*/
+# endif
+  },
+.code =                        iplookup_router_entry,
+.tidyup =              NULL,     /* no tidyup entry */
+.ri_flags =            ri_notransport
+};
+
 #endif /*!MACRO_PREDEF*/
 #endif /*ROUTER_IPLOOKUP*/
 /* End of routers/iplookup.c */
index 05043a8147ae71a95afe79365270283906099e03..095a3af16585fac8c564b3fef42921f4f0bb7487 100644 (file)
@@ -495,6 +495,31 @@ addr->transport = transport;
 return OK;
 }
 
+
+
+
+# ifdef DYNLOOKUP
+#  define manualroute_router_info _router_info
+# endif
+
+router_info manualroute_router_info =
+{
+.drinfo = {
+  .driver_name =       US"manualroute",
+  .options =           manualroute_router_options,
+  .options_count =     &manualroute_router_options_count,
+  .options_block =     &manualroute_router_option_defaults,
+  .options_len =       sizeof(manualroute_router_options_block),
+  .init =              manualroute_router_init,
+# ifdef DYNLOOKUP
+  .dyn_magic =         ROUTER_MAGIC,           /*XXX*/
+# endif
+  },
+.code =                        manualroute_router_entry,
+.tidyup =              NULL,     /* no tidyup entry */
+.ri_flags =            0
+};
+
 #endif /*!MACRO_PREDEF*/
 #endif /*ROUTER_MANUALROUTE*/
 /* End of routers/manualroute.c */
index 82c3f2001568f1b4916a17b6277b0e871e462f9b..606124e7ed336245736fd87bae49c2ce7b2e4c5d 100644 (file)
@@ -534,6 +534,30 @@ addr->prop = addr_prop;
 return rf_queue_add(addr, addr_local, addr_remote, rblock, pw) ? OK : DEFER;
 }
 
+
+
+# ifdef DYNLOOKUP
+#  define queryprogram_router_info _router_info
+# endif
+
+router_info queryprogram_router_info =
+{
+.drinfo = {
+  .driver_name =      US"queryprogram",
+  .options =          queryprogram_router_options,
+  .options_count =    &queryprogram_router_options_count,
+  .options_block =    &queryprogram_router_option_defaults,
+  .options_len =      sizeof(queryprogram_router_options_block),
+  .init =             queryprogram_router_init,
+# ifdef DYNLOOKUP
+  .dyn_magic =       ROUTER_MAGIC,           /*XXX*/
+# endif
+  },
+.code =               queryprogram_router_entry,
+.tidyup =             NULL,     /* no tidyup entry */
+.ri_flags =           0
+};
+
 #endif /*!MACRO_PREDEF*/
 #endif /*ROUTER_QUERYPROGRAM*/
 /* End of routers/queryprogram.c */
index 936cfca14635a0fc1fbb80880f39471888c9e3e0..50b180372bb7b8f5eb19fd767c0a5e724b66ab45 100644 (file)
@@ -788,6 +788,30 @@ addr->next = *addr_succeed;
 return yield;
 }
 
+
+
+# ifdef DYNLOOKUP
+#  define redirect_router_info _router_info
+# endif
+
+router_info redirect_router_info =
+{
+.drinfo = {
+  .driver_name =       US"redirect",
+  .options =           redirect_router_options,
+  .options_count =     &redirect_router_options_count,
+  .options_block =     &redirect_router_option_defaults,
+  .options_len =       sizeof(redirect_router_options_block),
+  .init =              redirect_router_init,
+# ifdef DYNLOOKUP
+  .dyn_magic =         ROUTER_MAGIC,           /*XXX*/
+# endif
+  },
+.code =                        redirect_router_entry,
+.tidyup =              NULL,     /* no tidyup entry */
+.ri_flags =            ri_notransport
+};
+
 #endif   /*!MACRO_PREDEF*/
 #endif /*ROUTER_REDIRECT*/
 /* End of routers/redirect.c */
index 392a4a08c5b2bae57f89938838a5678b6991cbd6..3446664cd8b1631999023dbc03b78f845eee0fea 100644 (file)
@@ -150,9 +150,14 @@ typedef struct driver_info {
   int     options_len;            /* Length of same in bytes */
   void  (*init)(                  /* Initialization entry point */
          struct driver_instance *);
-  BOOL   dynamic;                /* Built as dynamic-load module */
+  uint   dyn_magic;              /* Magic num if dynamic, else zero */
 } driver_info;
 
+/* Values for dyn_magic.  Encode types and api version. */
+#define ROUTER_MAGIC   0x52544d31      /* RTM1 */
+#define TRANSPORT_MAGIC        0x54504d31      /* TPM1 */
+#define AUTH_MAGIC     0x65554d31      /* AUM1 */
+
 
 /* Structure for holding information about the configured transports. Some
 of the generally accessible options are set from the configuration file; others