PostgreSQL Source Code  git master
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
 
typedef void(* pg_attribute_noreturn) ()
 

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

Definition at line 1 of file parse_manifest.h.

◆ JsonManifestParseIncrementalState

◆ pg_attribute_noreturn

typedef void(* pg_attribute_noreturn) ()

Definition at line 38 of file parse_manifest.h.

Function Documentation

◆ json_parse_manifest()

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

Definition at line 227 of file parse_manifest.c.

229 {
230  JsonLexContext *lex;
231  JsonParseErrorType json_error;
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;
250  sem.object_field_end = NULL;
251  sem.array_element_start = NULL;
252  sem.array_element_end = NULL;
254 
255  /* Run the actual JSON parser. */
256  json_error = pg_parse_json(lex, &sem);
257  if (json_error != JSON_SUCCESS)
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 
265  freeJsonLexContext(lex);
266 }
JsonParseErrorType pg_parse_json(JsonLexContext *lex, const JsonSemAction *sem)
Definition: jsonapi.c:744
char * json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
Definition: jsonapi.c:2397
JsonLexContext * makeJsonLexContextCstringLen(JsonLexContext *lex, const char *json, size_t len, int encoding, bool need_escapes)
Definition: jsonapi.c:392
void freeJsonLexContext(JsonLexContext *lex)
Definition: jsonapi.c:687
JsonParseErrorType
Definition: jsonapi.h:35
@ JSON_SUCCESS
Definition: jsonapi.h:36
@ 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 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)
@ PG_UTF8
Definition: pg_wchar.h:232
tree context
Definition: radixtree.h:1837
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
Definition: regcomp.c:717
static pg_noinline void Size size
Definition: slab.c:607
json_struct_action array_end
Definition: jsonapi.h:151
json_struct_action object_start
Definition: jsonapi.h:148
json_ofield_action object_field_start
Definition: jsonapi.h:152
json_aelem_action array_element_start
Definition: jsonapi.h:154
json_scalar_action scalar
Definition: jsonapi.h:156
void * semstate
Definition: jsonapi.h:147
json_aelem_action array_element_end
Definition: jsonapi.h:155
json_struct_action array_start
Definition: jsonapi.h:150
json_struct_action object_end
Definition: jsonapi.h:149
json_ofield_action object_field_end
Definition: jsonapi.h:153
static JsonSemAction sem

References JsonSemAction::array_element_end, JsonSemAction::array_element_start, JsonSemAction::array_end, JsonSemAction::array_start, context, 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, size, 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 
)

Definition at line 185 of file parse_manifest.c.

187 {
189  expected;
192 
193  res = pg_parse_json_incremental(&(incstate->lex), &(incstate->sem),
194  chunk, size, is_last);
195 
196  expected = is_last ? JSON_SUCCESS : JSON_INCOMPLETE;
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  {
214  }
215 }
uint8_t uint8
Definition: c.h:483
int pg_cryptohash_update(pg_cryptohash_ctx *ctx, const uint8 *data, size_t len)
Definition: cryptohash.c:136
uint64 chunk
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
pg_cryptohash_ctx * manifest_ctx

References chunk, context, JM_EXPECT_EOF, json_errdetail(), JSON_INCOMPLETE, json_manifest_parse_failure(), JSON_SUCCESS, JsonManifestParseIncrementalState::lex, JsonManifestParseIncrementalState::manifest_ctx, parse(), pg_cryptohash_update(), pg_parse_json_incremental(), res, JsonManifestParseIncrementalState::sem, JsonSemAction::semstate, size, 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)

Definition at line 129 of file parse_manifest.c.

130 {
133  pg_cryptohash_ctx *manifest_ctx;
134 
135  incstate = palloc(sizeof(JsonManifestParseIncrementalState));
137 
138  parse->context = context;
140  parse->saw_version_field = false;
141 
142  makeJsonLexContextIncremental(&(incstate->lex), PG_UTF8, true);
143 
144  incstate->sem.semstate = parse;
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 }
int pg_cryptohash_init(pg_cryptohash_ctx *ctx)
Definition: cryptohash.c:100
pg_cryptohash_ctx * pg_cryptohash_create(pg_cryptohash_type type)
Definition: cryptohash.c:74
@ PG_SHA256
Definition: cryptohash.h:24
JsonLexContext * makeJsonLexContextIncremental(JsonLexContext *lex, int encoding, bool need_escapes)
Definition: jsonapi.c:497
void * palloc(Size size)
Definition: mcxt.c:1317

References JsonSemAction::array_element_end, JsonSemAction::array_element_start, JsonSemAction::array_end, JsonSemAction::array_start, context, 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(), JsonManifestParseIncrementalState::lex, makeJsonLexContextIncremental(), JsonManifestParseIncrementalState::manifest_ctx, JsonSemAction::object_end, JsonSemAction::object_field_end, JsonSemAction::object_field_start, JsonSemAction::object_start, palloc(), parse(), pg_cryptohash_create(), pg_cryptohash_init(), PG_SHA256, PG_UTF8, JsonSemAction::scalar, JsonManifestParseIncrementalState::sem, and JsonSemAction::semstate.

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

◆ json_parse_manifest_incremental_shutdown()

void json_parse_manifest_incremental_shutdown ( JsonManifestParseIncrementalState incstate)

Definition at line 169 of file parse_manifest.c.

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

References freeJsonLexContext(), JsonManifestParseIncrementalState::lex, pfree(), JsonManifestParseIncrementalState::sem, and JsonSemAction::semstate.

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