]> code.citadel.org Git - citadel.git/blobdiff - citadel/internet_addressing.c
* Formalized the 'Internet Configuration' logistics. Added new API call
[citadel.git] / citadel / internet_addressing.c
index 53067543a51bc29608d58e1fbb7cc92fdf2cd1ac..16e24233348e29d08bf8d006e74d2bba286fc594 100644 (file)
 #include "tools.h"
 #include "internet_addressing.h"
 #include "user_ops.h"
+#include "room_ops.h"
 #include "parsedate.h"
 
 
+struct trynamebuf {
+       char buffer1[256];
+       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
@@ -217,18 +256,20 @@ void process_rfc822_addr(char *rfc822, char *user, char *node, char *name)
  * Back end for convert_internet_address()
  * (Compares an internet name [buffer1] and stores in [buffer2] if found)
  */
-void try_name(struct usersupp *us) {
+void try_name(struct usersupp *us, void *data) {
+       struct trynamebuf *tnb;
+       tnb = (struct trynamebuf *)data;
        
-       if (!strncasecmp(CC->buffer1, "cit", 3))
-               if (atol(&CC->buffer1[3]) == us->usernum)
-                       strcpy(CC->buffer2, us->fullname);
+       if (!strncasecmp(tnb->buffer1, "cit", 3))
+               if (atol(&tnb->buffer1[3]) == us->usernum)
+                       strcpy(tnb->buffer2, us->fullname);
 
-       if (!collapsed_strcmp(CC->buffer1, us->fullname)) 
-                       strcpy(CC->buffer2, us->fullname);
+       if (!collapsed_strcmp(tnb->buffer1, us->fullname)) 
+                       strcpy(tnb->buffer2, us->fullname);
 
        if (us->uid != BBSUID)
-               if (!strcasecmp(CC->buffer1, getpwuid(us->uid)->pw_name))
-                       strcpy(CC->buffer2, us->fullname);
+               if (!strcasecmp(tnb->buffer1, getpwuid(us->uid)->pw_name))
+                       strcpy(tnb->buffer2, us->fullname);
 }
 
 
@@ -241,15 +282,16 @@ int convert_internet_address(char *destuser, char *desthost, char *source)
        char node[256];
        char name[256];
        struct quickroom qrbuf;
+       int i;
+       struct trynamebuf tnb;
 
        /* Split it up */
        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);
        }
 
@@ -258,18 +300,25 @@ int convert_internet_address(char *destuser, char *desthost, char *source)
         */
        if (!strcasecmp(node, config.c_nodename)) {
                /* Try all local rooms */
-               if (!strncasecmp(destuser, "room_", 5)) {
-                       /* FIX do this here */
+               if (!strncasecmp(user, "room_", 5)) {
+                       strcpy(name, &user[5]);
+                       for (i=0; i<strlen(name); ++i) 
+                               if (name[i]=='_') name[i]=' ';
+                       if (getroom(&qrbuf, name) == 0) {
+                               strcpy(destuser, qrbuf.QRname);
+                               strcpy(desthost, config.c_nodename);
+                               return rfc822_room_delivery;
+                       }
                }
 
                /* Try all local users */
                strcpy(destuser, user);
                strcpy(desthost, config.c_nodename);
-               strcpy(CC->buffer1, user);
-               strcpy(CC->buffer2, "");
-               ForEachUser(try_name);
-               if (strlen(CC->buffer2) == 0) return(rfc822_no_such_user);
-               strcpy(destuser, CC->buffer2);
+               strcpy(tnb.buffer1, user);
+               strcpy(tnb.buffer2, "");
+               ForEachUser(try_name, &tnb);
+               if (strlen(tnb.buffer2) == 0) return(rfc822_no_such_user);
+               strcpy(destuser, tnb.buffer2);
                return(rfc822_address_locally_validated);
        }
 
@@ -324,9 +373,9 @@ int convert_field(struct CtdlMessage *msg, int beg, int end) {
        }
 
        else if (!strcasecmp(key, "From")) {
-               user = mallok(strlen(value));
-               node = mallok(strlen(value));
-               name = mallok(strlen(value));
+               user = mallok(1024);
+               node = mallok(1024);
+               name = mallok(1024);
                process_rfc822_addr(value, user, node, name);
                lprintf(9, "Converted to <%s@%s> (%s)\n", user, node, name);
                if (msg->cm_fields['A'] == NULL)