nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

rcpthosts.c (1231B)


      1 #include "rcpthosts.h"
      2 
      3 #include "case.h"
      4 #include "cdb.h"
      5 #include "byte.h"
      6 #include "open.h"
      7 #include "error.h"
      8 #include "control.h"
      9 #include "constmap.h"
     10 #include "stralloc.h"
     11 
     12 static int flagrh = 0;
     13 static stralloc rh = {0};
     14 static struct constmap maprh;
     15 static int fdmrh;
     16 
     17 int rcpthosts_init()
     18 {
     19   flagrh = control_readfile(&rh,"control/rcpthosts",0);
     20   if (flagrh != 1) return flagrh;
     21   if (!constmap_init(&maprh,rh.s,rh.len,0)) return flagrh = -1;
     22   fdmrh = open_read("control/morercpthosts.cdb");
     23   if (fdmrh == -1) if (errno != error_noent) return flagrh = -1;
     24   return 0;
     25 }
     26 
     27 static stralloc host = {0};
     28 
     29 int rcpthosts(buf,len)
     30 char *buf;
     31 int len;
     32 {
     33   int j;
     34 
     35   if (flagrh != 1) return 1;
     36 
     37   j = byte_rchr(buf,len,'@');
     38   if (j >= len) return 1; /* presumably envnoathost is acceptable */
     39 
     40   ++j; buf += j; len -= j;
     41 
     42   if (!stralloc_copyb(&host,buf,len)) return -1;
     43   buf = host.s;
     44   case_lowerb(buf,len);
     45 
     46   for (j = 0;j < len;++j)
     47     if (!j || (buf[j] == '.'))
     48       if (constmap(&maprh,buf + j,len - j)) return 1;
     49 
     50   if (fdmrh != -1) {
     51     uint32 dlen;
     52     int r;
     53 
     54     for (j = 0;j < len;++j)
     55       if (!j || (buf[j] == '.')) {
     56 	r = cdb_seek(fdmrh,buf + j,len - j,&dlen);
     57 	if (r) return r;
     58       }
     59   }
     60 
     61   return 0;
     62 }