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 *, char *pathname, size_t 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, char *buffer, size_t size)
 
JsonManifestParseIncrementalStatejson_parse_manifest_incremental_init (JsonManifestParseContext *context)
 
void json_parse_manifest_incremental_chunk (JsonManifestParseIncrementalState *incstate, char *chunk, int 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 *, char *pathname, size_t 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,
char *  buffer,
size_t  size 
)

Definition at line 228 of file parse_manifest.c.

230 {
231  JsonLexContext *lex;
232  JsonParseErrorType json_error;
235 
236  /* Set up our private parsing context. */
237  parse.context = context;
239  parse.saw_version_field = false;
240 
241  /* Create a JSON lexing context. */
242  lex = makeJsonLexContextCstringLen(NULL, buffer, size, PG_UTF8, true);
243 
244  /* Set up semantic actions. */
245  sem.semstate = &parse;
251  sem.object_field_end = NULL;
252  sem.array_element_start = NULL;
253  sem.array_element_end = NULL;
255 
256  /* Run the actual JSON parser. */
257  json_error = pg_parse_json(lex, &sem);
258  if (json_error != JSON_SUCCESS)
260  if (parse.state != JM_EXPECT_EOF)
261  json_manifest_parse_failure(context, "manifest ended unexpectedly");
262 
263  /* Verify the manifest checksum. */
264  verify_manifest_checksum(&parse, buffer, size, NULL);
265 
266  freeJsonLexContext(lex);
267 }
char * json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
Definition: jsonapi.c:2096
JsonParseErrorType pg_parse_json(JsonLexContext *lex, JsonSemAction *sem)
Definition: jsonapi.c:521
JsonLexContext * makeJsonLexContextCstringLen(JsonLexContext *lex, char *json, int len, int encoding, bool need_escapes)
Definition: jsonapi.c:326
void freeJsonLexContext(JsonLexContext *lex)
Definition: jsonapi.c:482
JsonParseErrorType
Definition: jsonapi.h:37
@ JSON_SUCCESS
Definition: jsonapi.h:38
@ 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, char *buffer, size_t size, pg_cryptohash_ctx *incr_ctx)
@ PG_UTF8
Definition: pg_wchar.h:232
tree context
Definition: radixtree.h:1829
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
Definition: regcomp.c:715
static pg_noinline void Size size
Definition: slab.c:607
json_struct_action array_end
Definition: jsonapi.h:138
json_struct_action object_start
Definition: jsonapi.h:135
json_ofield_action object_field_start
Definition: jsonapi.h:139
json_aelem_action array_element_start
Definition: jsonapi.h:141
json_scalar_action scalar
Definition: jsonapi.h:143
void * semstate
Definition: jsonapi.h:134
json_aelem_action array_element_end
Definition: jsonapi.h:142
json_struct_action array_start
Definition: jsonapi.h:137
json_struct_action object_end
Definition: jsonapi.h:136
json_ofield_action object_field_end
Definition: jsonapi.h:140
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,
char *  chunk,
int  size,
bool  is_last 
)

Definition at line 185 of file parse_manifest.c.

188 {
190  expected;
193 
194  res = pg_parse_json_incremental(&(incstate->lex), &(incstate->sem),
195  chunk, size, is_last);
196 
197  expected = is_last ? JSON_SUCCESS : JSON_INCOMPLETE;
198 
199  if (res != expected)
201  json_errdetail(res, &(incstate->lex)));
202 
203  if (is_last && parse->state != JM_EXPECT_EOF)
204  json_manifest_parse_failure(context, "manifest ended unexpectedly");
205 
206  if (!is_last)
207  {
208  if (pg_cryptohash_update(incstate->manifest_ctx,
209  (uint8 *) chunk, size) < 0)
210  context->error_cb(context, "could not update checksum of manifest");
211  }
212  else
213  {
215  }
216 }
unsigned char uint8
Definition: c.h:504
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, JsonSemAction *sem, char *json, int len, bool is_last)
Definition: jsonapi.c:649
@ JSON_INCOMPLETE
Definition: jsonapi.h:39
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:366
void * palloc(Size size)
Definition: mcxt.c:1316

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:1520

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

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