1 /* 2 Copyright 2021 Northern.tech AS 3 4 This file is part of CFEngine 3 - written and maintained by Northern.tech AS. 5 6 This program is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License as published by the 8 Free Software Foundation; version 3. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 18 19 To the extent this program is licensed as part of the Enterprise 20 versions of CFEngine, the applicable Commercial Open Source License 21 (COSL) may apply to this file if you as a licensee so wish it. See 22 included file COSL.txt. 23 */ 24 25 #ifndef CFENGINE_DBM_PRIV_H 26 #define CFENGINE_DBM_PRIV_H 27 28 #include <dbm_api_types.h> 29 /* DBM implementation is supposed to define the following structures and 30 * implement the following functions */ 31 32 typedef struct DBPriv_ DBPriv; 33 typedef struct DBCursorPriv_ DBCursorPriv; 34 35 const char *DBPrivGetFileExtension(void); 36 37 #define DB_PRIV_DATABASE_BROKEN ((DBPriv *)-1) 38 39 void DBPrivSetMaximumConcurrentTransactions(int max_txn); 40 41 /* 42 * These two functions will always be called with a per-database lock held. 43 */ 44 45 /* 46 * Should return either 47 * - NULL in case of generic error 48 * - DB_PRIV_DATABASE_BROKEN in case database file is broken, need to be moved 49 away and attempt to open database again should be performed. 50 * - valid pointer to DBPriv * in case database was opened successfully. 51 */ 52 DBPriv *DBPrivOpenDB(const char *dbpath, dbid id); 53 void DBPrivCloseDB(DBPriv *hdbp); 54 void DBPrivCommit(DBPriv *hdbp); 55 bool DBPrivClean(DBPriv *hdbp); 56 57 bool DBPrivHasKey(DBPriv *db, const void *key, int key_size); 58 int DBPrivGetValueSize(DBPriv *db, const void *key, int key_size); 59 60 bool DBPrivRead(DBPriv *db, const void *key, int key_size, 61 void *dest, size_t dest_size); 62 63 bool DBPrivWrite(DBPriv *db, const void *key, int key_size, 64 const void *value, int value_size); 65 66 bool DBPrivOverwrite(DBPriv *handle, 67 const char *key, int key_size, 68 const void *value, size_t value_size, 69 OverwriteCondition Condition, void *data); 70 71 bool DBPrivDelete(DBPriv *db, const void *key, int key_size); 72 73 74 DBCursorPriv *DBPrivOpenCursor(DBPriv *db); 75 bool DBPrivAdvanceCursor(DBCursorPriv *cursor, void **key, int *key_size, 76 void **value, int *value_size); 77 bool DBPrivDeleteCursorEntry(DBCursorPriv *cursor); 78 bool DBPrivWriteCursorEntry(DBCursorPriv *cursor, const void *value, int value_size); 79 void DBPrivCloseCursor(DBCursorPriv *cursor); 80 81 /** 82 * @brief Check a database file for consistency 83 * @param dbpath Path to database file 84 * @return NULL if successful, else an error string that must be freed 85 */ 86 char *DBPrivDiagnose(const char *dbpath); 87 88 #endif 89