1 /***********************************************************************************************************************************
2 PostgreSQL Info Handler
3 ***********************************************************************************************************************************/
4 #ifndef INFO_INFOPG_H
5 #define INFO_INFOPG_H
6
7 #include <stdint.h>
8
9 /***********************************************************************************************************************************
10 Object type
11 ***********************************************************************************************************************************/
12 typedef struct InfoPg InfoPg;
13
14 #include "common/crypto/common.h"
15 #include "common/ini.h"
16 #include "info/info.h"
17 #include "storage/storage.h"
18
19 /***********************************************************************************************************************************
20 Constants
21 ***********************************************************************************************************************************/
22 #define INFO_KEY_DB_ID "db-id"
23 VARIANT_DECLARE(INFO_KEY_DB_ID_VAR);
24
25 /***********************************************************************************************************************************
26 Information about the PostgreSQL cluster
27 ***********************************************************************************************************************************/
28 typedef struct InfoPgData
29 {
30 unsigned int id;
31 uint64_t systemId;
32 unsigned int catalogVersion;
33 unsigned int version;
34 } InfoPgData;
35
36 /***********************************************************************************************************************************
37 Info types for determining data in DB section
38 ***********************************************************************************************************************************/
39 typedef enum
40 {
41 infoPgArchive = STRID5("archive", 0x16c940e410), // archive info file
42 infoPgBackup = STRID5("backup", 0x21558c220), // backup info file
43 } InfoPgType;
44
45 /***********************************************************************************************************************************
46 Constructors
47 ***********************************************************************************************************************************/
48 InfoPg *infoPgNew(InfoPgType type, const String *cipherPassSub);
49
50 // Create new object and load contents from a file
51 InfoPg *infoPgNewLoad(IoRead *read, InfoPgType type, InfoLoadNewCallback *callbackFunction, void *callbackData);
52
53 /***********************************************************************************************************************************
54 Getters/Setters
55 ***********************************************************************************************************************************/
56 typedef struct InfoPgPub
57 {
58 Info *info; // Info contents
59 List *history; // A list of InfoPgData
60 } InfoPgPub;
61
62 // Archive id
63 String *infoPgArchiveId(const InfoPg *this, unsigned int pgDataIdx);
64
65 // Base info
66 __attribute__((always_inline)) static inline Info *
infoPgInfo(const InfoPg * const this)67 infoPgInfo(const InfoPg *const this)
68 {
69 return THIS_PUB(InfoPg)->info;
70 }
71
72 // Return the cipher passphrase
73 __attribute__((always_inline)) static inline const String *
infoPgCipherPass(const InfoPg * const this)74 infoPgCipherPass(const InfoPg *const this)
75 {
76 return infoCipherPass(infoPgInfo(this));
77 }
78
79 // Return current pgId from the history
80 unsigned int infoPgCurrentDataId(const InfoPg *this);
81
82 // PostgreSQL info
83 InfoPgData infoPgData(const InfoPg *this, unsigned int pgDataIdx);
84
85 // Current PostgreSQL data
86 InfoPgData infoPgDataCurrent(const InfoPg *this);
87
88 // Current history index
89 unsigned int infoPgDataCurrentId(const InfoPg *this);
90
91 // Total PostgreSQL data in the history
92 __attribute__((always_inline)) static inline unsigned int
infoPgDataTotal(const InfoPg * const this)93 infoPgDataTotal(const InfoPg *const this)
94 {
95 return lstSize(THIS_PUB(InfoPg)->history);
96 }
97
98 /***********************************************************************************************************************************
99 Functions
100 ***********************************************************************************************************************************/
101 // Add Postgres data to the history list at position 0 to ensure the latest history is always first in the list
102 void infoPgAdd(InfoPg *this, const InfoPgData *infoPgData);
103
104 // Save to IO
105 void infoPgSave(InfoPg *this, IoWrite *write, InfoSaveCallback *callbackFunction, void *callbackData);
106
107 // Set the InfoPg object data based on values passed
108 InfoPg *infoPgSet(
109 InfoPg *this, InfoPgType type, const unsigned int pgVersion, const uint64_t pgSystemId, const unsigned int pgCatalogVersion);
110
111 /***********************************************************************************************************************************
112 Macros for function logging
113 ***********************************************************************************************************************************/
114 String *infoPgDataToLog(const InfoPgData *this);
115
116 #define FUNCTION_LOG_INFO_PG_TYPE \
117 InfoPg *
118 #define FUNCTION_LOG_INFO_PG_FORMAT(value, buffer, bufferSize) \
119 objToLog(value, "InfoPg", buffer, bufferSize)
120
121 #define FUNCTION_LOG_INFO_PG_DATA_TYPE \
122 InfoPgData
123 #define FUNCTION_LOG_INFO_PG_DATA_FORMAT(value, buffer, bufferSize) \
124 FUNCTION_LOG_STRING_OBJECT_FORMAT(&value, infoPgDataToLog, buffer, bufferSize)
125
126
127 #endif
128