Blame include/apr_sdbm.h

Packit 383869
/* Licensed to the Apache Software Foundation (ASF) under one or more
Packit 383869
 * contributor license agreements.  See the NOTICE file distributed with
Packit 383869
 * this work for additional information regarding copyright ownership.
Packit 383869
 * The ASF licenses this file to You under the Apache License, Version 2.0
Packit 383869
 * (the "License"); you may not use this file except in compliance with
Packit 383869
 * the License.  You may obtain a copy of the License at
Packit 383869
 *
Packit 383869
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 383869
 *
Packit 383869
 * Unless required by applicable law or agreed to in writing, software
Packit 383869
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 383869
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 383869
 * See the License for the specific language governing permissions and
Packit 383869
 * limitations under the License.
Packit 383869
 */
Packit 383869
Packit 383869
/*
Packit 383869
 * sdbm - ndbm work-alike hashed database library
Packit 383869
 * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
Packit 383869
 * author: oz@nexus.yorku.ca
Packit 383869
 * status: ex-public domain
Packit 383869
 */
Packit 383869
Packit 383869
#ifndef APR_SDBM_H
Packit 383869
#define APR_SDBM_H
Packit 383869
Packit 383869
#include "apu.h"
Packit 383869
#include "apr_errno.h"
Packit 383869
#include "apr_file_io.h"   /* for apr_fileperms_t */
Packit 383869
Packit 383869
/** 
Packit 383869
 * @file apr_sdbm.h
Packit 383869
 * @brief apr-util SDBM library
Packit 383869
 */
Packit 383869
/**
Packit 383869
 * @defgroup APR_Util_DBM_SDBM SDBM library
Packit 383869
 * @ingroup APR_Util_DBM
Packit 383869
 * @{
Packit 383869
 */
Packit 383869
Packit 383869
/**
Packit 383869
 * Structure for referencing an sdbm
Packit 383869
 */
Packit 383869
typedef struct apr_sdbm_t apr_sdbm_t;
Packit 383869
Packit 383869
/**
Packit 383869
 * Structure for referencing the datum record within an sdbm
Packit 383869
 */
Packit 383869
typedef struct {
Packit 383869
    /** pointer to the data stored/retrieved */
Packit 383869
    char *dptr;
Packit 383869
    /** size of data */
Packit 383869
    /* apr_ssize_t for release 2.0??? */
Packit 383869
    int dsize;
Packit 383869
} apr_sdbm_datum_t;
Packit 383869
Packit 383869
/* The extensions used for the database files */
Packit 383869
/** SDBM Directory file extension */
Packit 383869
#define APR_SDBM_DIRFEXT	".dir"
Packit 383869
/** SDBM page file extension */
Packit 383869
#define APR_SDBM_PAGFEXT	".pag"
Packit 383869
Packit 383869
/* flags to sdbm_store */
Packit 383869
#define APR_SDBM_INSERT     0   /**< Insert */
Packit 383869
#define APR_SDBM_REPLACE    1   /**< Replace */
Packit 383869
#define APR_SDBM_INSERTDUP  2   /**< Insert with duplicates */
Packit 383869
Packit 383869
/**
Packit 383869
 * Open an sdbm database by file name
Packit 383869
 * @param db The newly opened database
Packit 383869
 * @param name The sdbm file to open
Packit 383869
 * @param mode The flag values (APR_READ and APR_BINARY flags are implicit)
Packit 383869
 * 
Packit 383869
 *           APR_WRITE          open for read-write access
Packit 383869
 *           APR_CREATE         create the sdbm if it does not exist
Packit 383869
 *           APR_TRUNCATE       empty the contents of the sdbm
Packit 383869
 *           APR_EXCL           fail for APR_CREATE if the file exists
Packit 383869
 *           APR_DELONCLOSE     delete the sdbm when closed
Packit 383869
 *           APR_SHARELOCK      support locking across process/machines
Packit 383869
 * 
Packit 383869
 * @param perms Permissions to apply to if created
Packit 383869
 * @param p The pool to use when creating the sdbm
Packit 383869
 * @remark The sdbm name is not a true file name, as sdbm appends suffixes 
Packit 383869
 * for seperate data and index files.
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_sdbm_open(apr_sdbm_t **db, const char *name, 
Packit 383869
                                        apr_int32_t mode, 
Packit 383869
                                        apr_fileperms_t perms, apr_pool_t *p);
Packit 383869
Packit 383869
/**
Packit 383869
 * Close an sdbm file previously opened by apr_sdbm_open
Packit 383869
 * @param db The database to close
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_sdbm_close(apr_sdbm_t *db);
Packit 383869
Packit 383869
/**
Packit 383869
 * Lock an sdbm database for concurency of multiple operations
Packit 383869
 * @param db The database to lock
Packit 383869
 * @param type The lock type
Packit 383869
 * 
Packit 383869
 *           APR_FLOCK_SHARED
Packit 383869
 *           APR_FLOCK_EXCLUSIVE
Packit 383869
 * 
Packit 383869
 * @remark Calls to apr_sdbm_lock may be nested.  All apr_sdbm functions
Packit 383869
 * perform implicit locking.  Since an APR_FLOCK_SHARED lock cannot be 
Packit 383869
 * portably promoted to an APR_FLOCK_EXCLUSIVE lock, apr_sdbm_store and 
Packit 383869
 * apr_sdbm_delete calls will fail if an APR_FLOCK_SHARED lock is held.
Packit 383869
 * The apr_sdbm_lock call requires the database to be opened with the
Packit 383869
 * APR_SHARELOCK mode value.
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_sdbm_lock(apr_sdbm_t *db, int type);
Packit 383869
Packit 383869
/**
Packit 383869
 * Release an sdbm lock previously aquired by apr_sdbm_lock
Packit 383869
 * @param db The database to unlock
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_sdbm_unlock(apr_sdbm_t *db);
Packit 383869
Packit 383869
/**
Packit 383869
 * Fetch an sdbm record value by key
Packit 383869
 * @param db The database 
Packit 383869
 * @param value The value datum retrieved for this record
Packit 383869
 * @param key The key datum to find this record
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_sdbm_fetch(apr_sdbm_t *db, 
Packit 383869
                                         apr_sdbm_datum_t *value, 
Packit 383869
                                         apr_sdbm_datum_t key);
Packit 383869
Packit 383869
/**
Packit 383869
 * Store an sdbm record value by key
Packit 383869
 * @param db The database 
Packit 383869
 * @param key The key datum to store this record by
Packit 383869
 * @param value The value datum to store in this record
Packit 383869
 * @param opt The method used to store the record
Packit 383869
 * 
Packit 383869
 *           APR_SDBM_INSERT     return an error if the record exists
Packit 383869
 *           APR_SDBM_REPLACE    overwrite any existing record for key
Packit 383869
 * 
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_sdbm_store(apr_sdbm_t *db, apr_sdbm_datum_t key,
Packit 383869
                                         apr_sdbm_datum_t value, int opt);
Packit 383869
Packit 383869
/**
Packit 383869
 * Delete an sdbm record value by key
Packit 383869
 * @param db The database 
Packit 383869
 * @param key The key datum of the record to delete
Packit 383869
 * @remark It is not an error to delete a non-existent record.
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_sdbm_delete(apr_sdbm_t *db, 
Packit 383869
                                          const apr_sdbm_datum_t key);
Packit 383869
Packit 383869
/**
Packit 383869
 * Retrieve the first record key from a dbm
Packit 383869
 * @param db The database 
Packit 383869
 * @param key The key datum of the first record
Packit 383869
 * @remark The keys returned are not ordered.  To traverse the list of keys
Packit 383869
 * for an sdbm opened with APR_SHARELOCK, the caller must use apr_sdbm_lock
Packit 383869
 * prior to retrieving the first record, and hold the lock until after the
Packit 383869
 * last call to apr_sdbm_nextkey.
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_sdbm_firstkey(apr_sdbm_t *db, apr_sdbm_datum_t *key);
Packit 383869
Packit 383869
/**
Packit 383869
 * Retrieve the next record key from an sdbm
Packit 383869
 * @param db The database 
Packit 383869
 * @param key The key datum of the next record
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_sdbm_nextkey(apr_sdbm_t *db, apr_sdbm_datum_t *key);
Packit 383869
Packit 383869
/**
Packit 383869
 * Returns true if the sdbm database opened for read-only access
Packit 383869
 * @param db The database to test
Packit 383869
 */
Packit 383869
APU_DECLARE(int) apr_sdbm_rdonly(apr_sdbm_t *db);
Packit 383869
/** @} */
Packit 383869
#endif /* APR_SDBM_H */