smdb.h revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (c) 1999-2002 Sendmail, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*
* $Id: smdb.h,v 8.40.2.1 2002/10/05 17:04:51 ca Exp $
*
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#ifndef _SMDB_H_
# define _SMDB_H_
# include <sm/errstring.h>
# ifdef NDBM
# include <ndbm.h>
# endif /* NDBM */
# ifdef NEWDB
# endif /* NEWDB */
/*
** Some size constants
*/
#define SMDB_MAX_USER_NAME_LEN 1024
/*
** This file defines the abstraction for database lookups. It is pretty
** much a copy of the db2 interface with the exception that every function
** returns 0 on success and non-zero on failure. The non-zero return code
** is meaningful.
**
** I'm going to put the function comments in this file since the interface
** MUST be the same for all inheritors of this interface.
*/
typedef struct database_struct SMDB_DATABASE;
typedef struct cursor_struct SMDB_CURSOR;
typedef struct entry_struct SMDB_DBENT;
/*
** DB_CLOSE_FUNC -- close the database
**
** Parameters:
** db -- The database to close.
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
/*
** DB_DEL_FUNC -- removes a key and data pair from the database
**
** Parameters:
** db -- The database to close.
** key -- The key to remove.
** flags -- delete options. There are currently no defined
** flags for delete.
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
/*
** DB_FD_FUNC -- Returns a pointer to a file used for the database.
**
** Parameters:
** db -- The database to close.
** fd -- A pointer to store the returned fd in.
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
/*
** DB_GET_FUNC -- Gets the data associated with a key.
**
** Parameters:
** db -- The database to close.
** key -- The key to access.
** data -- A place to store the returned data.
** flags -- get options. There are currently no defined
** flags for get.
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
/*
** DB_PUT_FUNC -- Sets some data according to the key.
**
** Parameters:
** db -- The database to close.
** key -- The key to use.
** data -- The data to store.
** flags -- put options:
** SMDBF_NO_OVERWRITE - Return an error if key alread
** exists.
** SMDBF_ALLOW_DUP - Allow duplicates in btree maps.
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
/*
** DB_SYNC_FUNC -- Flush any cached information to disk.
**
** Parameters:
** db -- The database to sync.
** flags -- sync options:
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
/*
** DB_SET_OWNER_FUNC -- Set the owner and group of the database files.
**
** Parameters:
** db -- The database to set.
** uid -- The UID for the new owner (-1 for no change)
** gid -- The GID for the new owner (-1 for no change)
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
/*
** DB_CURSOR -- Obtain a cursor for sequential access
**
** Parameters:
** db -- The database to use.
** cursor -- The address of a cursor pointer.
** flags -- sync options:
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
struct database_struct
{
void *smdb_impl;
};
/*
** DB_CURSOR_CLOSE -- Close a cursor
**
** Parameters:
** cursor -- The cursor to close.
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
/*
**
** Parameters:
** cursor -- The cursor.
** flags -- flags
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
unsigned int flags));
/*
**
** Parameters:
** cursor -- The cursor.
** key -- The current key.
** value -- The current value
** flags -- flags
**
** Returns:
** 0 - Success, otherwise errno.
** SMDBE_LAST_ENTRY - This is a success condition that
** gets returned when the end of the
** database is hit.
**
*/
unsigned int flags));
/*
** Flags for DB_CURSOR_GET
*/
#define SMDB_CURSOR_GET_FIRST 0
#define SMDB_CURSOR_GET_LAST 1
#define SMDB_CURSOR_GET_NEXT 2
#define SMDB_CURSOR_GET_RANGE 3
/*
**
** Parameters:
** cursor -- The cursor.
** key -- The current key.
** value -- The current value
** flags -- flags
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
unsigned int flags));
struct cursor_struct
{
void *smdbc_impl;
};
struct database_params_struct
{
unsigned int smdbp_num_elements;
unsigned int smdbp_cache_size;
bool smdbp_allow_dup;
};
typedef struct database_params_struct SMDB_DBPARAMS;
struct database_user_struct
{
char smdbu_name[SMDB_MAX_USER_NAME_LEN];
};
typedef struct database_user_struct SMDB_USER_INFO;
struct entry_struct
{
void *data;
};
typedef char *SMDB_DBTYPE;
typedef unsigned int SMDB_FLAG;
/*
** These are types of databases.
*/
# define SMDB_TYPE_DEFAULT NULL
# define SMDB_TYPE_DEFAULT_LEN 0
# define SMDB_TYPE_HASH "hash"
# define SMDB_TYPE_HASH_LEN 5
# define SMDB_TYPE_BTREE "btree"
# define SMDB_TYPE_BTREE_LEN 6
# define SMDB_TYPE_NDBM "dbm"
# define SMDB_TYPE_NDBM_LEN 4
/*
** These are flags
*/
/* Flags for put */
# define SMDBF_NO_OVERWRITE 0x00000001
# define SMDBF_ALLOW_DUP 0x00000002
int, long, SMDB_DBTYPE,
SMDB_DBPARAMS *));
# ifdef NEWDB
long, SMDB_DBTYPE, SMDB_USER_INFO *,
SMDB_DBPARAMS *));
# endif /* NEWDB */
# ifdef NDBM
long, SMDB_DBTYPE,
SMDB_DBPARAMS *));
# endif /* NDBM */
extern int smdb_add_extension __P((char *, int, char *, char *));
extern int smdb_setup_file __P((char *, char *, int, long,
SMDB_USER_INFO *, struct stat *));
extern int smdb_lock_file __P((int *, char *, int, long, char *));
extern int smdb_unlock_file __P((int));
extern int smdb_filechanged __P((char *, char *, int,
struct stat *));
extern void smdb_print_available_types __P((void));
#endif /* ! _SMDB_H_ */