PostgreSQL Source Code git master
Loading...
Searching...
No Matches
parse_manifest.h File Reference
#include "access/xlogdefs.h"
#include "common/checksum_helper.h"
#include "mb/pg_wchar.h"
Include dependency graph for parse_manifest.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  JsonManifestParseContext
 

Typedefs

typedef struct JsonManifestParseContext JsonManifestParseContext
 
typedef struct JsonManifestParseIncrementalState JsonManifestParseIncrementalState
 
typedef void(* json_manifest_version_callback) (JsonManifestParseContext *, int manifest_version)
 
typedef void(* json_manifest_system_identifier_callback) (JsonManifestParseContext *, uint64 manifest_system_identifier)
 
typedef void(* json_manifest_per_file_callback) (JsonManifestParseContext *, const char *pathname, uint64 size, pg_checksum_type checksum_type, int checksum_length, uint8 *checksum_payload)
 
typedef void(* json_manifest_per_wal_range_callback) (JsonManifestParseContext *, TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn)
 
typedef void(* json_manifest_error_callback) (JsonManifestParseContext *, const char *fmt,...) pg_attribute_printf(2
 

Functions

void json_parse_manifest (JsonManifestParseContext *context, const char *buffer, size_t size)
 
JsonManifestParseIncrementalStatejson_parse_manifest_incremental_init (JsonManifestParseContext *context)
 
void json_parse_manifest_incremental_chunk (JsonManifestParseIncrementalState *incstate, const char *chunk, size_t size, bool is_last)
 
void json_parse_manifest_incremental_shutdown (JsonManifestParseIncrementalState *incstate)
 

Typedef Documentation

◆ json_manifest_error_callback

typedef void(* json_manifest_error_callback) (JsonManifestParseContext *, const char *fmt,...) pg_attribute_printf(2

Definition at line 36 of file parse_manifest.h.

◆ json_manifest_per_file_callback

typedef void(* json_manifest_per_file_callback) (JsonManifestParseContext *, const char *pathname, uint64 size, pg_checksum_type checksum_type, int checksum_length, uint8 *checksum_payload)

Definition at line 29 of file parse_manifest.h.

◆ json_manifest_per_wal_range_callback

typedef void(* json_manifest_per_wal_range_callback) (JsonManifestParseContext *, TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn)

Definition at line 33 of file parse_manifest.h.

◆ json_manifest_system_identifier_callback

typedef void(* json_manifest_system_identifier_callback) (JsonManifestParseContext *, uint64 manifest_system_identifier)

Definition at line 27 of file parse_manifest.h.

◆ json_manifest_version_callback

typedef void(* json_manifest_version_callback) (JsonManifestParseContext *, int manifest_version)

Definition at line 25 of file parse_manifest.h.

◆ JsonManifestParseContext

◆ JsonManifestParseIncrementalState

Function Documentation

◆ json_parse_manifest()

void json_parse_manifest ( JsonManifestParseContext context,
const char buffer,
size_t  size 
)
extern

Definition at line 227 of file parse_manifest.c.

229{
230 JsonLexContext *lex;
234
235 /* Set up our private parsing context. */
236 parse.context = context;
238 parse.saw_version_field = false;
239
240 /* Create a JSON lexing context. */
241 lex = makeJsonLexContextCstringLen(NULL, buffer, size, PG_UTF8, true);
242
243 /* Set up semantic actions. */
244 sem.semstate = &parse;
254
255 /* Run the actual JSON parser. */
259 if (parse.state != JM_EXPECT_EOF)
260 json_manifest_parse_failure(context, "manifest ended unexpectedly");
261
262 /* Verify the manifest checksum. */
263 verify_manifest_checksum(&parse, buffer, size, NULL);
264
266}
void parse(int)
Definition parse.c:49
JsonParseErrorType pg_parse_json(JsonLexContext *lex, const JsonSemAction *sem)
Definition jsonapi.c:744
JsonLexContext * makeJsonLexContextCstringLen(JsonLexContext *lex, const char *json, size_t len, int encoding, bool need_escapes)
Definition jsonapi.c:392
char * json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
Definition jsonapi.c:2404
void freeJsonLexContext(JsonLexContext *lex)
Definition jsonapi.c:687
JsonParseErrorType
Definition jsonapi.h:35
@ JSON_SUCCESS
Definition jsonapi.h:36
#define PG_UTF8
Definition mbprint.c:43
@ JM_EXPECT_TOPLEVEL_START
@ JM_EXPECT_EOF
static JsonParseErrorType json_manifest_array_start(void *state)
static JsonParseErrorType json_manifest_object_field_start(void *state, char *fname, bool isnull)
static JsonParseErrorType json_manifest_object_end(void *state)
static JsonParseErrorType json_manifest_object_start(void *state)
static JsonParseErrorType json_manifest_scalar(void *state, char *token, JsonTokenType tokentype)
static pg_noreturn void json_manifest_parse_failure(JsonManifestParseContext *context, char *msg)
static JsonParseErrorType json_manifest_array_end(void *state)
static void verify_manifest_checksum(JsonManifestParseState *parse, const char *buffer, size_t size, pg_cryptohash_ctx *incr_ctx)
static int fb(int x)
json_struct_action array_end
Definition jsonapi.h:157
json_struct_action object_start
Definition jsonapi.h:154
json_ofield_action object_field_start
Definition jsonapi.h:158
json_aelem_action array_element_start
Definition jsonapi.h:160
json_scalar_action scalar
Definition jsonapi.h:162
void * semstate
Definition jsonapi.h:153
json_aelem_action array_element_end
Definition jsonapi.h:161
json_struct_action array_start
Definition jsonapi.h:156
json_struct_action object_end
Definition jsonapi.h:155
json_ofield_action object_field_end
Definition jsonapi.h:159
static JsonSemAction sem

References JsonSemAction::array_element_end, JsonSemAction::array_element_start, JsonSemAction::array_end, JsonSemAction::array_start, fb(), freeJsonLexContext(), JM_EXPECT_EOF, JM_EXPECT_TOPLEVEL_START, json_errdetail(), json_manifest_array_end(), json_manifest_array_start(), json_manifest_object_end(), json_manifest_object_field_start(), json_manifest_object_start(), json_manifest_parse_failure(), json_manifest_scalar(), JSON_SUCCESS, makeJsonLexContextCstringLen(), JsonSemAction::object_end, JsonSemAction::object_field_end, JsonSemAction::object_field_start, JsonSemAction::object_start, parse(), pg_parse_json(), PG_UTF8, JsonSemAction::scalar, sem, JsonSemAction::semstate, and verify_manifest_checksum().

Referenced by load_backup_manifest(), and parse_manifest_file().

◆ json_parse_manifest_incremental_chunk()

void json_parse_manifest_incremental_chunk ( JsonManifestParseIncrementalState incstate,
const char chunk,
size_t  size,
bool  is_last 
)
extern

Definition at line 185 of file parse_manifest.c.

187{
189 expected;
190 JsonManifestParseState *parse = incstate->sem.semstate;
191 JsonManifestParseContext *context = parse->context;
192
193 res = pg_parse_json_incremental(&(incstate->lex), &(incstate->sem),
194 chunk, size, is_last);
195
197
198 if (res != expected)
200 json_errdetail(res, &(incstate->lex)));
201
202 if (is_last && parse->state != JM_EXPECT_EOF)
203 json_manifest_parse_failure(context, "manifest ended unexpectedly");
204
205 if (!is_last)
206 {
207 if (pg_cryptohash_update(incstate->manifest_ctx,
208 (const uint8 *) chunk, size) < 0)
209 context->error_cb(context, "could not update checksum of manifest");
210 }
211 else
212 {
213 verify_manifest_checksum(parse, chunk, size, incstate->manifest_ctx);
214 }
215}
uint8_t uint8
Definition c.h:544
int pg_cryptohash_update(pg_cryptohash_ctx *ctx, const uint8 *data, size_t len)
Definition cryptohash.c:136
JsonParseErrorType pg_parse_json_incremental(JsonLexContext *lex, const JsonSemAction *sem, const char *json, size_t len, bool is_last)
Definition jsonapi.c:868
@ JSON_INCOMPLETE
Definition jsonapi.h:37
json_manifest_error_callback error_cb

References JsonManifestParseContext::error_cb, fb(), JM_EXPECT_EOF, json_errdetail(), JSON_INCOMPLETE, json_manifest_parse_failure(), JSON_SUCCESS, parse(), pg_cryptohash_update(), pg_parse_json_incremental(), and verify_manifest_checksum().

Referenced by AppendIncrementalManifestData(), FinalizeIncrementalManifest(), load_backup_manifest(), and parse_manifest_file().

◆ json_parse_manifest_incremental_init()

JsonManifestParseIncrementalState * json_parse_manifest_incremental_init ( JsonManifestParseContext context)
extern

Definition at line 129 of file parse_manifest.c.

130{
133 pg_cryptohash_ctx *manifest_ctx;
134
137
138 parse->context = context;
140 parse->saw_version_field = false;
141
143
144 incstate->sem.semstate = parse;
145 incstate->sem.object_start = json_manifest_object_start;
146 incstate->sem.object_end = json_manifest_object_end;
147 incstate->sem.array_start = json_manifest_array_start;
148 incstate->sem.array_end = json_manifest_array_end;
149 incstate->sem.object_field_start = json_manifest_object_field_start;
150 incstate->sem.object_field_end = NULL;
151 incstate->sem.array_element_start = NULL;
152 incstate->sem.array_element_end = NULL;
153 incstate->sem.scalar = json_manifest_scalar;
154
155 manifest_ctx = pg_cryptohash_create(PG_SHA256);
156 if (manifest_ctx == NULL)
157 context->error_cb(context, "out of memory");
158 if (pg_cryptohash_init(manifest_ctx) < 0)
159 context->error_cb(context, "could not initialize checksum of manifest");
160 incstate->manifest_ctx = manifest_ctx;
161
162 return incstate;
163}
pg_cryptohash_ctx * pg_cryptohash_create(pg_cryptohash_type type)
Definition cryptohash.c:74
int pg_cryptohash_init(pg_cryptohash_ctx *ctx)
Definition cryptohash.c:100
@ PG_SHA256
Definition cryptohash.h:24
#define palloc_object(type)
Definition fe_memutils.h:74
JsonLexContext * makeJsonLexContextIncremental(JsonLexContext *lex, int encoding, bool need_escapes)
Definition jsonapi.c:497

References JsonManifestParseContext::error_cb, fb(), JM_EXPECT_TOPLEVEL_START, json_manifest_array_end(), json_manifest_array_start(), json_manifest_object_end(), json_manifest_object_field_start(), json_manifest_object_start(), json_manifest_scalar(), makeJsonLexContextIncremental(), palloc_object, parse(), pg_cryptohash_create(), pg_cryptohash_init(), PG_SHA256, and PG_UTF8.

Referenced by CreateIncrementalBackupInfo(), load_backup_manifest(), and parse_manifest_file().

◆ json_parse_manifest_incremental_shutdown()

void json_parse_manifest_incremental_shutdown ( JsonManifestParseIncrementalState incstate)
extern

Definition at line 169 of file parse_manifest.c.

170{
171 pfree(incstate->sem.semstate);
173 /* incstate->manifest_ctx has already been freed */
175}
void pfree(void *pointer)
Definition mcxt.c:1616

References fb(), freeJsonLexContext(), and pfree().

Referenced by FinalizeIncrementalManifest(), load_backup_manifest(), and parse_manifest_file().