1 /* -*-pgsql-c-*- */
2 /*
3  *
4  * $Header$
5  *
6  * pgpool: a language independent connection pool server for PostgreSQL
7  * written by Tatsuo Ishii
8  *
9  * Copyright (c) 2003-2015	PgPool Global Development Group
10  *
11  * Permission to use, copy, modify, and distribute this software and
12  * its documentation for any purpose and without fee is hereby
13  * granted, provided that the above copyright notice appear in all
14  * copies and that both that copyright notice and this permission
15  * notice appear in supporting documentation, and that the name of the
16  * author not be used in advertising or publicity pertaining to
17  * distribution of the software without specific, written prior
18  * permission. The author makes no representations about the
19  * suitability of this software for any purpose.  It is provided "as
20  * is" without express or implied warranty.
21  *
22  *
23  */
24 #include "utils/json.h"
25 #include "pool_config.h"
26 #include "watchdog/watchdog.h"
27 
28 #ifndef WD_JSON_DATA_H
29 #define WD_JSON_DATA_H
30 
31 /*
32  * The structure to hold the parsed PG backend node status data fetched
33  * from the leader watchdog node
34  */
35 typedef struct WDPGBackendStatus
36 {
37 	int			primary_node_id;
38 	int			node_count;
39 	BACKEND_STATUS backend_status[MAX_NUM_BACKENDS];
40 	char		nodeName[WD_MAX_HOST_NAMELEN];	/* name of the watchdog node
41 												 * that sent the data */
42 }			WDPGBackendStatus;
43 
44 extern WatchdogNode * get_watchdog_node_from_json(char *json_data, int data_len, char **authkey);
45 extern char *get_watchdog_node_info_json(WatchdogNode * wdNode, char *authkey);
46 extern POOL_CONFIG * get_pool_config_from_json(char *json_data, int data_len);
47 extern char *get_pool_config_json(void);
48 extern char *get_lifecheck_node_status_change_json(int nodeID, int nodeStatus, char *message, char *authKey);
49 extern bool parse_node_status_json(char *json_data, int data_len, int *nodeID, int *nodeStatus, char **message);
50 
51 
52 extern bool parse_beacon_message_json(char *json_data, int data_len, int *state,
53 						  long *seconds_since_node_startup,
54 						  long *seconds_since_current_state,
55 						  int *quorumStatus,
56 						  int *standbyNodesCount,
57 						  bool *escalated);
58 extern char *get_beacon_message_json(WatchdogNode * wdNode);
59 
60 extern char *get_wd_node_function_json(char *func_name, int *node_id_set, int count, unsigned char flags, unsigned int sharedKey, char *authKey);
61 extern bool parse_wd_node_function_json(char *json_data, int data_len, char **func_name, int **node_id_set, int *count, unsigned char *flags);
62 extern char *get_wd_simple_message_json(char *message);
63 
64 extern WDPGBackendStatus * get_pg_backend_node_status_from_json(char *json_data, int data_len);
65 extern char *get_backend_node_status_json(WatchdogNode * wdNode);
66 
67 extern char *get_simple_request_json(char *key, char *value, unsigned int sharedKey, char *authKey);
68 
69 extern bool parse_data_request_json(char *json_data, int data_len, char **request_type);
70 extern char *get_data_request_json(char *request_type, unsigned int sharedKey, char *authKey);
71 
72 extern bool
73 parse_wd_exec_cluster_command_json(char *json_data, int data_len,
74 								   char **clusterCommand,
75 								   int *nArgs, WDExecCommandArg **wdExecCommandArg);
76 
77 extern char *
78 get_wd_exec_cluster_command_json(char *clusterCommand,int nArgs,
79 								 WDExecCommandArg *wdExecCommandArg,
80 								unsigned int sharedKey, char *authKey);
81 
82 #endif
83