* Formalized the 'Internet Configuration' logistics. Added new API call
authorArt Cancro <ajc@citadel.org>
Thu, 3 Feb 2000 03:57:35 +0000 (03:57 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 3 Feb 2000 03:57:35 +0000 (03:57 +0000)
  CtdlLocalHost() to detect aliases for the local host.  Used in SMTP listener.

citadel/ChangeLog
citadel/internet_addressing.c
citadel/internet_addressing.h
citadel/serv_inetcfg.c

index 3f808d62c31877b39bf795bd00d0d223d2a7a673..27fcd20246f76bcaa4615adbda8e4da7c280570c 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 1.455  2000/02/03 03:57:35  ajc
+* Formalized the 'Internet Configuration' logistics.  Added new API call
+  CtdlLocalHost() to detect aliases for the local host.  Used in SMTP listener.
+
 Revision 1.454  2000/01/31 02:13:05  ajc
 * <.A>ide <S>ystem configuration <I>nternet  in the client (unfinished)
 
@@ -1596,3 +1600,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
+
index 365a1ec9f57dd6252272072f7cc10bb7a04534b9..16e24233348e29d08bf8d006e74d2bba286fc594 100644 (file)
@@ -38,6 +38,39 @@ struct trynamebuf {
        char buffer2[256];
 };
 
+char *inetcfg = NULL;
+
+
+
+/*
+ * Return nonzero if the supplied name is an alias for this host.
+ */
+int CtdlLocalHost(char *fqdn) {
+       int config_lines;
+       int i;
+       char buf[256];
+       char host[256], type[256];
+
+       if (!strcasecmp(fqdn, config.c_fqdn)) return(1);
+       if (inetcfg == NULL) return(0);
+
+       config_lines = num_tokens(inetcfg, '\n');
+       for (i=0; i<config_lines; ++i) {
+               extract_token(buf, inetcfg, i, '\n');
+               extract_token(host, buf, 0, '|');
+               extract_token(type, buf, 1, '|');
+               if ( (!strcasecmp(type, "localhost"))
+                  && (!strcasecmp(fqdn, host)))  return(1);
+       }
+
+       return(0);
+}
+
+
+
+
+
+
 
 /*
  * Return 0 if a given string fuzzy-matches a Citadel user account
@@ -256,10 +289,9 @@ int convert_internet_address(char *destuser, char *desthost, char *source)
        process_rfc822_addr(source, user, node, name);
 
        /* Map the FQDN to a Citadel node name
-        * FIX ... we have to check for all known aliases for the local
-        *         system, and also handle gateway domains, etc. etc.
+        * FIX ... we have to check for gateway domains
         */
-       if (!strcasecmp(node, config.c_fqdn)) {
+       if (CtdlLocalHost(node)) {
                strcpy(node, config.c_nodename);
        }
 
index 7b8abc9adc321b7f9c59a3789cf3863ad80f3269..86aa0d019bd8cb81d333f7e8ca7d5684f61aa3dd 100644 (file)
@@ -13,3 +13,6 @@ enum {
 
 
 struct CtdlMessage *convert_internet_message(char *rfc822);
+int CtdlLocalHost(char *fqdn);
+
+extern char *inetcfg;
index 7d7c54aeceb26fb83ca15ef25e6a972fcab19abb..47be34f1015be81536e5ca260b2ed47737ff2575 100644 (file)
@@ -1,7 +1,9 @@
 /* $Id$ 
  *
  * This module handles the loading/saving and maintenance of the
- * system's Internet configuration.
+ * system's Internet configuration.  It's not an optional component; I
+ * wrote it as a module merely to keep things as clean and loosely coupled
+ * as possible.
  */
 
 #include "sysdep.h"
 #include "genstamp.h"
 #include "domain.h"
 
+void inetcfg_setTo(struct CtdlMessage *msg) {
+       char *conf;
+       char buf[256];
+
+       if (msg->cm_fields['M']==NULL) return;
+       conf = strdoop(msg->cm_fields['M']);
+
+       if (conf != NULL) {
+               do {
+                       extract_token(buf, conf, 0, '\n');
+                       strcpy(conf, &conf[strlen(buf)+1]);
+               } while ( (strlen(conf)>0) && (strlen(buf)>0) );
+
+               if (inetcfg != NULL) phree(inetcfg);
+               inetcfg = conf;
+       }
+}
+
 
 /*
  * This handler detects changes being made to the system's Internet
@@ -61,7 +81,7 @@ int inetcfg_aftersave(struct CtdlMessage *msg) {
                   strlen(INTERNETCFG) )) ) {
                        /* Bingo!  The user is changing configs.
                         */
-                       lprintf(9, "Internet configuration changed FIX\n");
+                       inetcfg_setTo(msg);
                }
 
                ptr = strchr((char *)ptr, '\n');
@@ -72,6 +92,25 @@ int inetcfg_aftersave(struct CtdlMessage *msg) {
 }
 
 
+void inetcfg_init_backend(long msgnum) {
+       struct CtdlMessage *msg;
+
+               msg = CtdlFetchMessage(msgnum);
+               if (msg != NULL) {
+               inetcfg_setTo(msg);
+                       CtdlFreeMessage(msg);
+       }
+}
+
+
+void inetcfg_init(void) {
+       if (getroom(&CC->quickroom, SYSCONFIGROOM) != 0) return;
+       CtdlForEachMessage(MSGS_LAST, 1, INTERNETCFG, NULL,
+               inetcfg_init_backend);
+}
+
+
+
 
 /*****************************************************************************/
 /*                      MODULE INITIALIZATION STUFF                          */
@@ -81,6 +120,7 @@ int inetcfg_aftersave(struct CtdlMessage *msg) {
 char *Dynamic_Module_Init(void)
 {
        CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
+       inetcfg_init();
        return "$Id$";
 }