Back to index

courier  0.68.2
Defines | Functions | Variables
islocal.c File Reference
#include "courier.h"
#include "dbobj.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

Go to the source code of this file.

Defines

#define ISLOCAL_MAX_DOT_COUNT   5

Functions

static const char * get_control_locals ()
int config_islocal (const char *address, char **domainp)
int config_is_indomain (const char *address, const char *localp)

Variables

static const char * control_locals = 0
static int isinit = 0
static struct dbobj

Define Documentation

#define ISLOCAL_MAX_DOT_COUNT   5

Definition at line 13 of file islocal.c.


Function Documentation

int config_is_indomain ( const char *  address,
const char *  localp 
)

Definition at line 119 of file islocal.c.

{
       while (*localp)
       {
       unsigned i;

              for (i=0; localp[i] && localp[i] != '\n' && localp[i] != '\r';
                     ++i)
                     ;

              if ( i > 0 && localp[0] == '!' && *address != '!' &&
                   config_domaincmp(address, localp+1, i-1) == 0)
                     return (0);

              if ( config_domaincmp(address, localp, i) == 0)
                     return (1);
              localp += i;
              if (*localp)  ++localp;
       }
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int config_islocal ( const char *  address,
char **  domainp 
)

Definition at line 48 of file islocal.c.

{
char   *k;
char   *v;
size_t vl;
size_t kl;

const char *p;
size_t pl;
char   *lcaddress;
int    dotcount;

       if (domainp)  *domainp=0;

       if (config_is_indomain(address, get_control_locals()))
              return (1);


       if (!isinit)
       {
       char    *filename;

              dbobj_init(&db);
              filename=config_localfilename("hosteddomains.dat");
              isinit=1;
              dbobj_open(&db, filename, "R");
              free(filename);
        }

       if (!dbobj_isopen(&db))
              return (0);

       kl=strlen(address);

       k=strcpy(courier_malloc(kl+1), address);
       for (v=k; *v; v++)
              *v=tolower((int)(unsigned char)*v);

       lcaddress = k;
       dotcount = 0;

       while ( (v=dbobj_fetch(&db, k, kl, &vl, "")) == NULL &&
               (k = strchr(k+1,'.')) != NULL &&
               dotcount++ < ISLOCAL_MAX_DOT_COUNT )
                  kl = strlen(k);

       if (k) address += k-lcaddress;
       free(lcaddress);
       if (!v)       return (0);

       /* Default entry is "1", so punt it to k*/

       p=v;
       pl=vl;

       if (vl <= 1)
       {
              p=address;
              pl=kl;
       }

       if (domainp)
       {
              *domainp=courier_malloc(pl+1);
              memcpy( *domainp, p, pl);
              (*domainp)[pl]=0;
       }
       free(v);
       return (1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static const char* get_control_locals ( ) [static]

Definition at line 26 of file islocal.c.

{
       if (!control_locals)
       {
       char *filename=config_localfilename("locals");
       char *buf=readfile(filename, 0);

              free(filename);
              if (!buf)
                     control_locals=config_me();
              else
              {
                     removecomments(buf);
                     control_locals=buf;
              }
       }
       return (control_locals);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char* control_locals = 0 [static]

Definition at line 22 of file islocal.c.

struct dbobj [static]

Definition at line 46 of file islocal.c.

int isinit = 0 [static]

Definition at line 45 of file islocal.c.