cfengine  3.15.4
About: CFEngine is a configuration management system for configuring and maintaining Unix-like computers (using an own high level policy language). Community version.
  Fossies Dox: cfengine-3.15.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

dbm_api.h
Go to the documentation of this file.
1 /*
2  Copyright 2019 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_API_H
26 #define CFENGINE_DBM_API_H
27 
28 #define EC_CORRUPTION_REPAIRED 120
29 #define EC_CORRUPTION_REPAIR_FAILED 121
30 
31 #include <map.h>
32 #include <dbm_api_types.h>
33 
34 // Only append to the end, keep in sync with DB_PATHS_STATEDIR array
35 typedef enum
36 {
37  dbid_classes, // Deprecated
38  dbid_variables, // Deprecated
40  dbid_checksums, // Deprecated
41  dbid_filestats, // Deprecated
57  dbid_bundles, // Deprecated
58  dbid_packages_installed, //new package promise installed packages list
59  dbid_packages_updates, //new package promise list of available updates
60  dbid_cookies, // Enterprise reporting cookies for duplicate host detection
61 
62  dbid_max
63 } dbid;
64 
65 typedef struct DBHandle_ DBHandle;
66 typedef struct DBCursor_ DBCursor;
67 
68 typedef DBHandle CF_DB;
69 typedef DBCursor CF_DBC;
70 
71 void DBSetMaximumConcurrentTransactions(int max_txn);
72 
73 bool OpenDB(CF_DB **dbp, dbid db);
74 bool OpenSubDB(DBHandle **dbp, dbid id, const char *sub_name);
75 bool CleanDB(DBHandle *handle);
76 void CloseDB(CF_DB *dbp);
77 
78 DBHandle *GetDBHandleFromFilename(const char *db_file_name);
79 time_t GetDBOpenTimestamp(const DBHandle *handle);
80 
81 bool HasKeyDB(CF_DB *dbp, const char *key, int key_size);
82 int ValueSizeDB(CF_DB *dbp, const char *key, int key_size);
83 bool ReadComplexKeyDB(CF_DB *dbp, const char *key, int key_size, void *dest, int destSz);
84 bool WriteComplexKeyDB(CF_DB *dbp, const char *key, int keySz, const void *src, int srcSz);
85 bool DeleteComplexKeyDB(CF_DB *dbp, const char *key, int size);
86 bool ReadDB(CF_DB *dbp, const char *key, void *dest, int destSz);
87 bool WriteDB(CF_DB *dbp, const char *key, const void *src, int srcSz);
88 bool OverwriteDB(DBHandle *handle, const char *key, const void *value, size_t value_size,
89  OverwriteCondition Condition, void *data);
90 bool DeleteDB(CF_DB *dbp, const char *key);
91 void FreezeDB(DBHandle *handle);
92 
93 /*
94  * Creating cursor locks the whole database, so keep the amount of work here to
95  * minimum.
96  *
97  * Don't use WriteDB/DeleteDB while iterating database, it will result in
98  * deadlock. Use cursor-specific operations instead. They work on the current
99  * key.
100  */
101 bool NewDBCursor(CF_DB *dbp, CF_DBC **dbcp);
102 bool NextDB(CF_DBC *dbcp, char **key, int *ksize, void **value, int *vsize);
104 bool DBCursorWriteEntry(CF_DBC *cursor, const void *value, int value_size);
105 bool DeleteDBCursor(CF_DBC *dbcp);
106 
107 char *DBIdToPath(dbid id);
108 char *DBIdToSubPath(dbid id, const char *subdb_name);
109 
111 
112 bool CheckDBRepairFlagFile();
113 #endif /* NOT CFENGINE_DBM_API_H */
bool DeleteDB(CF_DB *dbp, const char *key)
Definition: dbm_api.c:583
bool DeleteDBCursor(CF_DBC *dbcp)
Definition: dbm_api.c:617
void CloseDB(CF_DB *dbp)
Definition: dbm_api.c:472
StringMap * LoadDatabaseToStringMap(dbid database_id)
Definition: dbm_api.c:665
void FreezeDB(DBHandle *handle)
Definition: dbm_api.c:528
bool DeleteComplexKeyDB(CF_DB *dbp, const char *key, int size)
Definition: dbm_api.c:551
char * DBIdToPath(dbid id)
Definition: dbm_api.c:171
bool DBCursorDeleteEntry(CF_DBC *cursor)
Definition: dbm_api.c:607
bool WriteDB(CF_DB *dbp, const char *key, const void *src, int srcSz)
Definition: dbm_api.c:561
bool NewDBCursor(CF_DB *dbp, CF_DBC **dbcp)
Definition: dbm_api.c:588
bool OpenSubDB(DBHandle **dbp, dbid id, const char *sub_name)
Definition: dbm_api.c:435
bool ReadComplexKeyDB(CF_DB *dbp, const char *key, int key_size, void *dest, int destSz)
Definition: dbm_api.c:539
bool OverwriteDB(DBHandle *handle, const char *key, const void *value, size_t value_size, OverwriteCondition Condition, void *data)
Definition: dbm_api.c:566
bool ReadDB(CF_DB *dbp, const char *key, void *dest, int destSz)
Definition: dbm_api.c:556
bool WriteComplexKeyDB(CF_DB *dbp, const char *key, int keySz, const void *src, int srcSz)
Definition: dbm_api.c:545
int ValueSizeDB(CF_DB *dbp, const char *key, int key_size)
Definition: dbm_api.c:578
time_t GetDBOpenTimestamp(const DBHandle *handle)
Definition: dbm_api.c:466
bool CleanDB(DBHandle *handle)
Definition: dbm_api.c:508
bool CheckDBRepairFlagFile()
Definition: dbm_api.c:717
char * DBIdToSubPath(dbid id, const char *subdb_name)
Definition: dbm_api.c:155
DBCursor CF_DBC
Definition: dbm_api.h:69
bool DBCursorWriteEntry(CF_DBC *cursor, const void *value, int value_size)
Definition: dbm_api.c:612
bool HasKeyDB(CF_DB *dbp, const char *key, int key_size)
Definition: dbm_api.c:573
bool NextDB(CF_DBC *dbcp, char **key, int *ksize, void **value, int *vsize)
Definition: dbm_api.c:601
void DBSetMaximumConcurrentTransactions(int max_txn)
Definition: dbm_api.c:365
bool OpenDB(CF_DB **dbp, dbid db)
Definition: dbm_api.c:441
DBHandle CF_DB
Definition: dbm_api.h:68
DBHandle * GetDBHandleFromFilename(const char *db_file_name)
Definition: dbm_api.c:450
dbid
Definition: dbm_api.h:36
@ dbid_bundles
Definition: dbm_api.h:57
@ dbid_filestats
Definition: dbm_api.h:41
@ dbid_windows_registry
Definition: dbm_api.h:52
@ dbid_variables
Definition: dbm_api.h:38
@ dbid_cache
Definition: dbm_api.h:53
@ dbid_agent_execution
Definition: dbm_api.h:56
@ dbid_packages_installed
Definition: dbm_api.h:58
@ dbid_checksums
Definition: dbm_api.h:40
@ dbid_lastseen
Definition: dbm_api.h:45
@ dbid_scalars
Definition: dbm_api.h:51
@ dbid_changes
Definition: dbm_api.h:42
@ dbid_max
Definition: dbm_api.h:62
@ dbid_state
Definition: dbm_api.h:44
@ dbid_cookies
Definition: dbm_api.h:60
@ dbid_classes
Definition: dbm_api.h:37
@ dbid_performance
Definition: dbm_api.h:39
@ dbid_license
Definition: dbm_api.h:54
@ dbid_locks
Definition: dbm_api.h:47
@ dbid_static
Definition: dbm_api.h:50
@ dbid_history
Definition: dbm_api.h:48
@ dbid_packages_updates
Definition: dbm_api.h:59
@ dbid_observations
Definition: dbm_api.h:43
@ dbid_audit
Definition: dbm_api.h:46
@ dbid_measure
Definition: dbm_api.h:49
@ dbid_value
Definition: dbm_api.h:55
bool(* OverwriteCondition)(void *value, size_t value_size, void *data)
Definition: dbm_api_types.h:28
DBCursorPriv * cursor
Definition: dbm_api.c:72
Definition: map.h:212