perl paranoia about @INC
[exim.git] / src / src / dbstuff.h
index 7c581ad29285ea8b8434e91613bd13d2fbb6ede8..576941b61276c2e1a91620b5d3b19e9166734bf9 100644 (file)
@@ -1,10 +1,8 @@
-/* $Cambridge: exim/src/src/dbstuff.h,v 1.1 2004/10/07 10:39:01 ph10 Exp $ */
-
 /*************************************************
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2004 */
+/* Copyright (c) University of Cambridge 1995 - 2009 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 /* This header file contains macro definitions so that a variety of DBM
@@ -66,7 +64,7 @@ tdb_traverse to be called) */
 
 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation */
 #define EXIM_DBCREATE_CURSOR(db, cursor) { \
-   *(cursor) = malloc(sizeof(TDB_DATA)); (*(cursor))->dptr = NULL; }
+   *(cursor) = store_malloc(sizeof(TDB_DATA)); (*(cursor))->dptr = NULL; }
 
 /* EXIM_DBSCAN - This is complicated because we have to free the last datum
 free() must not die when passed NULL */
@@ -135,7 +133,7 @@ API changed for DB 4.1. */
 #define EXIM_DBOPEN(name, flags, mode, dbpp) \
        if (db_create(dbpp, NULL, 0) != 0 || \
          ((*dbpp)->set_errcall(*dbpp, dbfn_bdb_error_callback), \
-         (*dbpp)->open(*dbpp, NULL, CS name, NULL, \
+         ((*dbpp)->open)(*dbpp, NULL, CS name, NULL, \
          ((flags) == O_RDONLY)? DB_UNKNOWN : DB_HASH, \
          ((flags) == O_RDONLY)? DB_RDONLY : DB_CREATE, \
          mode)) != 0) *(dbpp) = NULL
@@ -143,7 +141,7 @@ API changed for DB 4.1. */
 #define EXIM_DBOPEN(name, flags, mode, dbpp) \
        if (db_create(dbpp, NULL, 0) != 0 || \
          ((*dbpp)->set_errcall(*dbpp, dbfn_bdb_error_callback), \
-         (*dbpp)->open(*dbpp, CS name, NULL, \
+         ((*dbpp)->open)(*dbpp, CS name, NULL, \
          ((flags) == O_RDONLY)? DB_UNKNOWN : DB_HASH, \
          ((flags) == O_RDONLY)? DB_RDONLY : DB_CREATE, \
          mode)) != 0) *(dbpp) = NULL
@@ -300,6 +298,17 @@ before use, but we don't have to free anything after reading data. */
 /* Some text for messages */
 #define EXIM_DBTYPE   "db (v1)"
 
+/* When scanning, for the non-first case we historically just passed 0
+as the flags field and it worked.  On FreeBSD 8 it no longer works and
+instead leads to memory exhaustion.  The man-page on FreeBSD says to use
+R_NEXT, but this 1.x is a historical fallback and I've no idea how portable
+the use of that flag is; so the solution is to define R_NEXT here if it's not
+already defined, with a default value of 0 because that's what we've always
+before been able to pass successfully. */
+#ifndef R_NEXT
+#define R_NEXT 0
+#endif
+
 /* Access functions */
 
 /* EXIM_DBOPEN - sets *dbpp to point to an EXIM_DB, NULL if failed */
@@ -331,7 +340,7 @@ before use, but we don't have to free anything after reading data. */
 
 /* EXIM_DBSCAN - returns TRUE if data is returned, FALSE at end */
 #define EXIM_DBSCAN(db, key, data, first, cursor)      \
-       ((db)->seq(db, &key, &data, (first? R_FIRST : 0)) == 0)
+       ((db)->seq(db, &key, &data, (first? R_FIRST : R_NEXT)) == 0)
 
 /* EXIM_DBDELETE_CURSOR - terminate scanning operation (null). Make it
 refer to cursor, to keep picky compilers happy. */
@@ -363,8 +372,8 @@ after reading data. */
 
 /* Basic DB type */
 typedef struct {
-       GDBM_FILE gdbm; /* Database */
-       datum lkey;     /* Last key, for scans */
+       GDBM_FILE gdbm;  /* Database */
+       datum lkey;      /* Last key, for scans */
 } EXIM_DB;
 
 /* Cursor type, not used with gdbm: just set up a dummy */
@@ -564,14 +573,16 @@ performed on them. There are two groups of records:
 2. keyed by domain -
      Domain response upto MAIL FROM:<>, postmaster, random local part;
 
-If a record exists, the result field is either ccache_accept or ccache_reject.
-The other fields, however, (which are only relevant to domain records) may also
-contain ccache_unknown if that particular test has not been done.
+If a record exists, the result field is either ccache_accept or ccache_reject,
+or, for a domain record only, ccache_reject_mfnull when MAIL FROM:<> was
+rejected. The other fields, however, (which are only relevant to domain
+records) may also contain ccache_unknown if that particular test has not been
+done.
 
 Originally, there was only one structure, used for both types. However, it got
 expanded for domain records, so it got split. To make it possible for Exim to
 handle the old type of record, we retain the old definition. The different
-kinds of record can be distinguised by their different lengths. */
+kinds of record can be distinguished by their different lengths. */
 
 typedef struct {
   time_t time_stamp;
@@ -631,4 +642,24 @@ typedef struct {
 } dbdata_serialize;
 
 
+/* This structure records the information required for the ratelimit
+ACL condition. */
+
+typedef struct {
+  time_t time_stamp;
+  /*************/
+  int    time_usec;       /* Fractional part of time, from gettimeofday() */
+  double rate;            /* Smoothed sending rate at that time */
+} dbdata_ratelimit;
+
+/* Same as above, plus a Bloom filter for uniquifying events. */
+
+typedef struct {
+  dbdata_ratelimit dbd;
+  time_t   bloom_epoch;   /* When the Bloom filter was last reset */
+  unsigned bloom_size;    /* Number of bytes in the Bloom filter */
+  uschar   bloom[40];     /* Bloom filter which may be larger than this */
+} dbdata_ratelimit_unique;
+
+
 /* End of dbstuff.h */