Adjust src/include/utils/jsonapi.h so it's not backend-only.

The major change here is that we no longer include jsonb.h into
jsonapi.h. The reason that was necessary is that jsonapi.h included
several prototypes functions in jsonfuncs.c that depend on the Jsonb
type. Move those prototypes to a new header, jsonfuncs.h, and include
it where needed.

The other change is that JsonEncodeDateTime is now declared in
json.h rather than jsonapi.h.

Taken together, these steps eliminate all dependencies of jsonapi.h
on backend-only data types and header files, so that it can
potentially be included in frontend code.
This commit is contained in:
Robert Haas 2020-01-24 09:58:37 -08:00
parent d694e0bb79
commit ce0425b162
7 changed files with 55 additions and 33 deletions

View File

@ -17,6 +17,7 @@
#include "tsearch/ts_utils.h"
#include "utils/builtins.h"
#include "utils/jsonapi.h"
#include "utils/jsonfuncs.h"
typedef struct MorphOpaque

View File

@ -21,6 +21,7 @@
#include "tsearch/ts_utils.h"
#include "utils/builtins.h"
#include "utils/jsonapi.h"
#include "utils/jsonfuncs.h"
#include "utils/varlena.h"
/******sql-level interface******/

View File

@ -19,6 +19,7 @@
#include "utils/builtins.h"
#include "utils/datetime.h"
#include "utils/hashutils.h"
#include "utils/json.h"
#include "utils/jsonapi.h"
#include "utils/jsonb.h"
#include "utils/memutils.h"

View File

@ -29,6 +29,7 @@
#include "utils/json.h"
#include "utils/jsonapi.h"
#include "utils/jsonb.h"
#include "utils/jsonfuncs.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/syscache.h"

View File

@ -18,5 +18,7 @@
/* functions in json.c */
extern void escape_json(StringInfo buf, const char *str);
extern char *JsonEncodeDateTime(char *buf, Datum value, Oid typid,
const int *tzp);
#endif /* JSON_H */

View File

@ -14,7 +14,6 @@
#ifndef JSONAPI_H
#define JSONAPI_H
#include "jsonb.h"
#include "lib/stringinfo.h"
typedef enum
@ -132,36 +131,4 @@ extern JsonLexContext *makeJsonLexContextCstringLen(char *json,
*/
extern bool IsValidJsonNumber(const char *str, int len);
/*
* Flag types for iterate_json(b)_values to specify what elements from a
* json(b) document we want to iterate.
*/
typedef enum JsonToIndex
{
jtiKey = 0x01,
jtiString = 0x02,
jtiNumeric = 0x04,
jtiBool = 0x08,
jtiAll = jtiKey | jtiString | jtiNumeric | jtiBool
} JsonToIndex;
/* an action that will be applied to each value in iterate_json(b)_values functions */
typedef void (*JsonIterateStringValuesAction) (void *state, char *elem_value, int elem_len);
/* an action that will be applied to each value in transform_json(b)_values functions */
typedef text *(*JsonTransformStringValuesAction) (void *state, char *elem_value, int elem_len);
extern uint32 parse_jsonb_index_flags(Jsonb *jb);
extern void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state,
JsonIterateStringValuesAction action);
extern void iterate_json_values(text *json, uint32 flags, void *action_state,
JsonIterateStringValuesAction action);
extern Jsonb *transform_jsonb_string_values(Jsonb *jsonb, void *action_state,
JsonTransformStringValuesAction transform_action);
extern text *transform_json_string_values(text *json, void *action_state,
JsonTransformStringValuesAction transform_action);
extern char *JsonEncodeDateTime(char *buf, Datum value, Oid typid,
const int *tzp);
#endif /* JSONAPI_H */

View File

@ -0,0 +1,49 @@
/*-------------------------------------------------------------------------
*
* jsonfuncs.h
* Functions to process JSON data types.
*
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/utils/jsonapi.h
*
*-------------------------------------------------------------------------
*/
#ifndef JSONFUNCS_H
#define JSONFUNCS_H
#include "utils/jsonapi.h"
#include "utils/jsonb.h"
/*
* Flag types for iterate_json(b)_values to specify what elements from a
* json(b) document we want to iterate.
*/
typedef enum JsonToIndex
{
jtiKey = 0x01,
jtiString = 0x02,
jtiNumeric = 0x04,
jtiBool = 0x08,
jtiAll = jtiKey | jtiString | jtiNumeric | jtiBool
} JsonToIndex;
/* an action that will be applied to each value in iterate_json(b)_values functions */
typedef void (*JsonIterateStringValuesAction) (void *state, char *elem_value, int elem_len);
/* an action that will be applied to each value in transform_json(b)_values functions */
typedef text *(*JsonTransformStringValuesAction) (void *state, char *elem_value, int elem_len);
extern uint32 parse_jsonb_index_flags(Jsonb *jb);
extern void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state,
JsonIterateStringValuesAction action);
extern void iterate_json_values(text *json, uint32 flags, void *action_state,
JsonIterateStringValuesAction action);
extern Jsonb *transform_jsonb_string_values(Jsonb *jsonb, void *action_state,
JsonTransformStringValuesAction transform_action);
extern text *transform_json_string_values(text *json, void *action_state,
JsonTransformStringValuesAction transform_action);
#endif