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 "parser/pg_list.h"
27 #include "watchdog/watchdog.h"
28 
29 #ifndef WD_JSON_DATA_H
30 #define WD_JSON_DATA_H
31 
32 /*
33  * The structure to hold the parsed PG backend node status data fetched
34  * from the leader watchdog node
35  */
36 typedef struct WDPGBackendStatus
37 {
38 	int			primary_node_id;
39 	int			node_count;
40 	BACKEND_STATUS backend_status[MAX_NUM_BACKENDS];
41 	char		nodeName[WD_MAX_HOST_NAMELEN];	/* name of the watchdog node
42 												 * that sent the data */
43 }			WDPGBackendStatus;
44 
45 extern WatchdogNode * get_watchdog_node_from_json(char *json_data, int data_len, char **authkey);
46 extern char *get_watchdog_node_info_json(WatchdogNode * wdNode, char *authkey);
47 extern POOL_CONFIG * get_pool_config_from_json(char *json_data, int data_len);
48 extern char *get_pool_config_json(void);
49 extern char *get_lifecheck_node_status_change_json(int nodeID, int nodeStatus, char *message, char *authKey);
50 extern bool parse_node_status_json(char *json_data, int data_len, int *nodeID, int *nodeStatus, char **message);
51 
52 
53 extern bool parse_beacon_message_json(char *json_data, int data_len, int *state,
54 						  long *seconds_since_node_startup,
55 						  long *seconds_since_current_state,
56 						  int *quorumStatus,
57 						  int *standbyNodesCount,
58 						  bool *escalated);
59 extern char *get_beacon_message_json(WatchdogNode * wdNode);
60 
61 extern char *get_wd_node_function_json(char *func_name, int *node_id_set, int count, unsigned char flags, unsigned int sharedKey, char *authKey);
62 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);
63 extern char *get_wd_simple_message_json(char *message);
64 
65 extern WDPGBackendStatus * get_pg_backend_node_status_from_json(char *json_data, int data_len);
66 extern char *get_backend_node_status_json(WatchdogNode * wdNode);
67 
68 extern char *get_simple_request_json(char *key, char *value, unsigned int sharedKey, char *authKey);
69 
70 extern bool parse_data_request_json(char *json_data, int data_len, char **request_type);
71 extern char *get_data_request_json(char *request_type, unsigned int sharedKey, char *authKey);
72 
73 extern bool
74 parse_wd_exec_cluster_command_json(char *json_data, int data_len,
75 								   char **clusterCommand, List **args_list);
76 
77 extern char *
78 get_wd_exec_cluster_command_json(char *clusterCommand,List *args_list,
79 								unsigned int sharedKey, char *authKey);
80 
81 #endif
82