-/* $Cambridge: exim/src/src/exim_dbutil.c,v 1.1 2004/10/07 10:39:01 ph10 Exp $ */
+/* $Cambridge: exim/src/src/exim_dbutil.c,v 1.10 2006/02/07 11:19:00 ph10 Exp $ */
/*************************************************
* Exim - an Internet mail transport agent *
*************************************************/
-/* Copyright (c) University of Cambridge 1995 - 2004 */
+/* Copyright (c) University of Cambridge 1995 - 2006 */
/* See the file NOTICE for conditions of use and distribution. */
/* Identifiers for the different database types. */
-#define type_retry 1
-#define type_wait 2
-#define type_misc 3
-#define type_callout 4
+#define type_retry 1
+#define type_wait 2
+#define type_misc 3
+#define type_callout 4
+#define type_ratelimit 5
/* For Berkeley DB >= 2, we can define a function to be called in case of DB
errors. This should help with debugging strange DB problems, e.g. getting "File
-exists" when you try to open a db file. */
+exists" when you try to open a db file. The API changed at release 4.3. */
#if defined(USE_DB) && defined(DB_VERSION_STRING)
void
+#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3)
+dbfn_bdb_error_callback(const DB_ENV *dbenv, const char *pfx, const char *msg)
+{
+dbenv = dbenv;
+#else
dbfn_bdb_error_callback(const char *pfx, char *msg)
{
+#endif
pfx = pfx;
printf("Berkeley DB error: %s\n", msg);
}
usage(uschar *name, uschar *options)
{
printf("Usage: exim_%s%s <spool-directory> <database-name>\n", name, options);
-printf(" <database-name> = retry | misc | wait-<transport-name> | callout\n");
+printf(" <database-name> = retry | misc | wait-<transport-name> | callout | ratelimit\n");
exit(1);
}
if (Ustrcmp(argv[2], "misc") == 0) return type_misc;
if (Ustrncmp(argv[2], "wait-", 5) == 0) return type_wait;
if (Ustrcmp(argv[2], "callout") == 0) return type_callout;
+ if (Ustrcmp(argv[2], "ratelimit") == 0) return type_ratelimit;
}
usage(name, options);
return -1; /* Never obeyed */
printf("** Failed to get %s lock for %s: %s",
((flags & O_RDONLY) != 0)? "read" : "write", buffer,
(errno == ETIMEDOUT)? "timed out" : strerror(errno));
- close(dbblock->lockfd);
+ (void)close(dbblock->lockfd);
return NULL;
}
""
#endif
);
- close(dbblock->lockfd);
+ (void)close(dbblock->lockfd);
return NULL;
}
dbfn_close(open_db *dbblock)
{
EXIM_DBCLOSE(dbblock->dbptr);
-close(dbblock->lockfd);
+(void)close(dbblock->lockfd);
}
dbdata_retry *retry;
dbdata_wait *wait;
dbdata_callout_cache *callout;
+ dbdata_ratelimit *ratelimit;
int count_bad = 0;
int i, length;
uschar *t;
print_cache(callout->random_result));
}
+ break;
+
+ case type_ratelimit:
+ ratelimit = (dbdata_ratelimit *)value;
+
+ printf("%s.%06d rate: %10.3f key: %s\n",
+ print_time(ratelimit->time_stamp), ratelimit->time_usec,
+ ratelimit->rate, keybuffer);
+
break;
}
store_reset(value);
dbdata_retry *retry;
dbdata_wait *wait;
dbdata_callout_cache *callout;
+ dbdata_ratelimit *ratelimit;
int i, oldlength;
uschar *t;
uschar field[256], value[256];
/* If the buffer contains just one digit, or just consists of "d", use the
previous name for an update. */
- if ((isdigit((uschar)buffer[0]) && !isdigit((uschar)buffer[1])) ||
- Ustrcmp(buffer, "d") == 0)
+ if ((isdigit((uschar)buffer[0]) && (buffer[1] == ' ' || buffer[1] == '\0'))
+ || Ustrcmp(buffer, "d") == 0)
{
if (name[0] == 0)
{
printf("No previous record name is set\n");
continue;
}
- sscanf(CS buffer, "%s %s", field, value);
+ (void)sscanf(CS buffer, "%s %s", field, value);
}
else
{
name[0] = 0;
- sscanf(CS buffer, "%s %s %s", name, field, value);
+ (void)sscanf(CS buffer, "%s %s %s", name, field, value);
}
/* Handle an update request */
break;
}
break;
+
+ case type_ratelimit:
+ ratelimit = (dbdata_ratelimit *)record;
+ length = sizeof(dbdata_ratelimit);
+ switch(fieldno)
+ {
+ case 0:
+ if ((tt = read_time(value)) > 0) ratelimit->time_stamp = tt;
+ else printf("bad time value\n");
+ break;
+
+ case 1:
+ ratelimit->time_usec = Uatoi(value);
+ break;
+
+ case 2:
+ ratelimit->rate = Ustrtod(value, NULL);
+ break;
+
+ default:
+ printf("unknown field number\n");
+ verify = 0;
+ break;
+ }
+ break;
}
dbfn_write(dbm, name, record, length);
callout->random_result);
}
break;
+
+ case type_ratelimit:
+ ratelimit = (dbdata_ratelimit *)record;
+ printf("0 time stamp: %s\n", print_time(ratelimit->time_stamp));
+ printf("1 fract. time: .%06d\n", ratelimit->time_usec);
+ printf("2 sender rate: % .3f\n", ratelimit->rate);
+ break;
}
}
if (Ustat(buffer, &statbuf) != 0)
{
- dbfn_delete(dbm, key);
- printf("deleted %s (no message)\n", key);
+ sprintf(CS(buffer + path_len), "%c/%s-D", id[5], id);
+ if (Ustat(buffer, &statbuf) != 0)
+ {
+ dbfn_delete(dbm, key);
+ printf("deleted %s (no message)\n", key);
+ }
}
}
}