Welcome to mirror list, hosted at ThFree Co, Russian Federation.

jsonpath.h « zbxjson « libs « src - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 644aef6aa4aeaf70264ad3888a61143bdec42e77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/

#ifndef ZABBIX_JSONPATH_H
#define ZABBIX_JSONPATH_H

#include "zbxjson.h"

typedef struct zbx_jsonpath_token zbx_jsonpath_token_t;

typedef enum
{
	ZBX_JSONPATH_SEGMENT_UNKNOWN,
	ZBX_JSONPATH_SEGMENT_MATCH_ALL,
	ZBX_JSONPATH_SEGMENT_MATCH_LIST,
	ZBX_JSONPATH_SEGMENT_MATCH_RANGE,
	ZBX_JSONPATH_SEGMENT_MATCH_EXPRESSION,
	ZBX_JSONPATH_SEGMENT_FUNCTION
}
zbx_jsonpath_segment_type_t;

/* specifies if the match list contains object property names or array indices */
typedef enum
{
	ZBX_JSONPATH_LIST_NAME = 1,
	ZBX_JSONPATH_LIST_INDEX
}
zbx_jsonpath_list_type_t;

typedef enum
{
	ZBX_JSONPATH_FUNCTION_MIN = 1,
	ZBX_JSONPATH_FUNCTION_MAX,
	ZBX_JSONPATH_FUNCTION_AVG,
	ZBX_JSONPATH_FUNCTION_LENGTH,
	ZBX_JSONPATH_FUNCTION_FIRST,
	ZBX_JSONPATH_FUNCTION_SUM,
	/* the element name suffix '~' internally is treated as a function */
	ZBX_JSONPATH_FUNCTION_NAME
}
zbx_jsonpath_function_type_t;

typedef struct zbx_jsonpath_list_item
{
	struct zbx_jsonpath_list_item	*next;
	/* the structure is always over-allocated so that either int */
	/* or a zero terminated string can be stored in data         */
	char				data[1];
}
zbx_jsonpath_list_node_t;

typedef struct
{
	zbx_jsonpath_list_node_t	*values;
	zbx_jsonpath_list_type_t	type;
}
zbx_jsonpath_list_t;

typedef struct
{
	int		start;
	int		end;
	unsigned int	flags;
}
zbx_jsonpath_range_t;

typedef enum
{
	ZBX_JSONPATH_EXPRESSION_INDEX_TRUE,
	ZBX_JSONPATH_EXPRESSION_INDEX_FALSE,
}
zbx_json_path_expression_index_t;

/* expression tokens in postfix notation */
typedef struct
{
	zbx_vector_ptr_t	tokens;
	zbx_jsonpath_token_t	*index_token;	/* relative path token that is used to index parent object */
	zbx_jsonpath_token_t	*value_token;	/* the index value token */
}
zbx_jsonpath_expression_t;

typedef struct
{
	zbx_jsonpath_function_type_t	type;
}
zbx_jsonpath_function_t;

typedef union
{
	zbx_jsonpath_list_t		list;
	zbx_jsonpath_range_t		range;
	zbx_jsonpath_expression_t	expression;
	zbx_jsonpath_function_t		function;
}
zbx_jsonpath_data_t;

struct zbx_jsonpath_segment
{
	zbx_jsonpath_segment_type_t	type;
	zbx_jsonpath_data_t		data;

	/* set to 1 if the segment is 'detached' and can be anywhere in parent node tree */
	unsigned char			detached;
};

/*                                                                            */
/* Token groups:                                                              */
/*   operand - constant value, jsonpath reference, result of () evaluation    */
/*   operator2 - binary operator (arithmetic or comparison)                   */
/*   operator1 - unary operator (negation !)                                  */
/*                                                                            */
typedef enum
{
	ZBX_JSONPATH_TOKEN_GROUP_NONE,
	ZBX_JSONPATH_TOKEN_GROUP_OPERAND,
	ZBX_JSONPATH_TOKEN_GROUP_OPERATOR2,	/* binary operator */
	ZBX_JSONPATH_TOKEN_GROUP_OPERATOR1	/* unary operator */
}
zbx_jsonpath_token_group_t;

/* expression token types */
typedef enum
{
	ZBX_JSONPATH_TOKEN_PATH_ABSOLUTE = 1,
	ZBX_JSONPATH_TOKEN_PATH_RELATIVE,
	ZBX_JSONPATH_TOKEN_CONST_STR,
	ZBX_JSONPATH_TOKEN_CONST_NUM,
	ZBX_JSONPATH_TOKEN_PAREN_LEFT,
	ZBX_JSONPATH_TOKEN_PAREN_RIGHT,
	ZBX_JSONPATH_TOKEN_OP_PLUS,
	ZBX_JSONPATH_TOKEN_OP_MINUS,
	ZBX_JSONPATH_TOKEN_OP_MULT,
	ZBX_JSONPATH_TOKEN_OP_DIV,
	ZBX_JSONPATH_TOKEN_OP_EQ,
	ZBX_JSONPATH_TOKEN_OP_NE,
	ZBX_JSONPATH_TOKEN_OP_GT,
	ZBX_JSONPATH_TOKEN_OP_GE,
	ZBX_JSONPATH_TOKEN_OP_LT,
	ZBX_JSONPATH_TOKEN_OP_LE,
	ZBX_JSONPATH_TOKEN_OP_NOT,
	ZBX_JSONPATH_TOKEN_OP_AND,
	ZBX_JSONPATH_TOKEN_OP_OR,
	ZBX_JSONPATH_TOKEN_OP_REGEXP
}
zbx_jsonpath_token_type_t;

struct zbx_jsonpath_token
{
	unsigned char	type;
	char		*text;
	zbx_jsonpath_t	*path;
};

#endif