/*
* history - handle a news history file
*
* Copyright (C) 1992/93/94 Stephen Hebditch <steveh@tqmcomms.co.uk>.
* All rights reserved. TQM Communications, BCM Box 225, London, WC1N 3XX.
*
* See README for more information and disclaimers
*
* Routines to open and close a C-News style history file and determine
* whether or not a particular message id exists in the history file.
*
* $Id: history.c,v 1.9 1995/01/10 12:53:13 root Exp $
*
* $Log: history.c,v $
* Revision 1.9 1995/01/10 12:53:13 root
* Moved includes from slurp.h.
* Added support for Gnu DBM.
* Always return TRUE in check_id if no_history_flag is set.
*
* Revision 1.7 1993/06/07 11:07:14 root
* If neither DBZ, DBM or NDBM are defined then don't carry out
* any history file lookups.
*
* Revision 1.6 1993/04/22 18:07:11 root
* No changes - put back in RCS after the RCS file went missing...
*
* Revision 1.4 1993/02/14 14:51:59 root
* No changes.
*
* Revision 1.0 1992/09/92
* Initial coding.
*
*/
#include "conf.h"
/* POSIX headers */
#define _POSIX_SOURCE 1
#include <sys/types.h>
#include <fcntl.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* Local headers */
#include "slurp.h"
/* DBM / DBZ / GDBM / NDBM headers */
#if defined (DBM)
#undef NULL
#include <dbm.h>
#undef NULL
#define NULL 0
#elif defined (DBZ)
#include <dbz.h>
#elif defined (GDBM)
#include <gdbm.h>
static GDBM_FILE db;
#elif defined (NDBM)
#include <ndbm.h>
static DBM *db = NULL;
#endif
/*
* open_history - Open history file
*/
int
open_history ()
{
#if defined (DBM) || defined (DBZ)
if (dbminit (HISTORY_FILE) < 0)
return (1);
#elif defined (GDBM)
if ((db = gdbm_open (HISTORY_FILE, 4096, GDBM_READER, 0, 0)) == NULL)
return (1);
#elif defined (NDBM)
if ((db = dbm_open (HISTORY_FILE, O_RDONLY, 0)) == NULL)
return (1);
#endif
return (0);
}
/*
* close_history - Close history file
*/
void
close_history ()
{
#if defined (DBM) || defined (DBZ)
(void) dbmclose ();
#elif defined (GDBM)
gdbm_close (db);
#elif defined (NDBM)
dbm_close (db);
#endif
}
/*
* Determine if message id already exists in the history file
*/
int
check_id (const char *message_id)
{
#if defined (DBM) || defined (DBZ) || defined (GDBM) || defined (NDBM)
datum k, d;
/* Now check for presence with dbm/ndbm */
k.dptr = (char *) message_id;
k.dsize = strlen (message_id) + 1;
if (no_history_flag)
return (TRUE);
#endif
#if defined (DBM) || defined (DBZ)
d = fetch (k);
return (d.dptr == NULL);
#elif defined (GDBM)
d = gdbm_fetch (db, k);
return (d.dptr == NULL);
#elif defined (NDBM)
d = dbm_fetch (db, k);
return (d.dptr == NULL);
#else
return (TRUE);
#endif
}
/* END-OF-FILE */
syntax highlighted by Code2HTML, v. 0.9.1