libamxo  4.3.4
Object Definition Language (ODL) parsing
amxo_parser_priv.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2023 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or without modification,
8 ** are permitted provided that the following conditions are met:
9 **
10 ** 1. Redistributions of source code must retain the above copyright notice,
11 ** this list of conditions and the following disclaimer.
12 **
13 ** 2. Redistributions in binary form must reproduce the above copyright notice,
14 ** this list of conditions and the following disclaimer in the documentation
15 ** and/or other materials provided with the distribution.
16 **
17 ** Subject to the terms and conditions of this license, each copyright holder
18 ** and contributor hereby grants to those receiving rights under this license
19 ** a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
20 ** (except for failure to satisfy the conditions of this license) patent license
21 ** to make, have made, use, offer to sell, sell, import, and otherwise transfer
22 ** this software, where such license applies only to those patent claims, already
23 ** acquired or hereafter acquired, licensable by such copyright holder or contributor
24 ** that are necessarily infringed by:
25 **
26 ** (a) their Contribution(s) (the licensed copyrights of copyright holders and
27 ** non-copyrightable additions of contributors, in source or binary form) alone;
28 ** or
29 **
30 ** (b) combination of their Contribution(s) with the work of authorship to which
31 ** such Contribution(s) was added by such copyright holder or contributor, if,
32 ** at the time the Contribution is added, such addition causes such combination
33 ** to be necessarily infringed. The patent license shall not apply to any other
34 ** combinations which include the Contribution.
35 **
36 ** Except as expressly stated above, no rights or licenses from any copyright
37 ** holder or contributor is granted under this license, whether expressly, by
38 ** implication, estoppel or otherwise.
39 **
40 ** DISCLAIMER
41 **
42 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
46 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
51 ** USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 **
53 ****************************************************************************/
54 
55 #if !defined(__AMXO_PARSER_PRIV_H__)
56 #define __AMXO_PARSER_PRIV_H__
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
63 #include <sys/resource.h>
64 #include <sys/types.h>
65 #include <sys/stat.h>
66 
67 #include <stdlib.h>
68 #include <string.h>
69 #include <fcntl.h>
70 #include <errno.h>
71 #include <limits.h>
72 #include <libgen.h>
73 #include <ctype.h>
74 #include <dlfcn.h>
75 #include <unistd.h>
76 #include <dirent.h>
77 #include <syslog.h>
78 
79 #include <amxc/amxc_macros.h>
80 #include <amxc/amxc.h>
81 #include <amxp/amxp.h>
82 #include <amxd/amxd_common.h>
83 #include <amxd/amxd_dm.h>
84 #include <amxd/amxd_object.h>
85 #include <amxd/amxd_object_expression.h>
86 #include <amxd/amxd_object_event.h>
87 #include <amxd/amxd_parameter.h>
88 #include <amxd/amxd_action.h>
89 #include <amxd/amxd_path.h>
90 #include <amxo/amxo.h>
91 #include <amxs/amxs.h>
92 
94 {
108 };
109 
110 typedef enum _amxo_parser_attr {
127 
128 typedef enum _amxo_action {
143 
144 typedef enum _event_id {
149 
150 typedef struct _event {
152  amxc_var_t data;
153  char* path;
154  amxc_llist_it_t it;
156 
157 typedef struct _amxo_txt {
158  char* txt;
159  int length;
161 
162 typedef struct _amxo_txt_regexp {
163  char* txt;
164  bool is_regexp;
166 
167 typedef struct _amxo_res_data {
168  amxc_htable_it_t hit;
169  amxc_htable_t data;
171 
172 PRIVATE
173 void amxo_parser_free_event(amxc_llist_it_t* it);
174 
175 PRIVATE
176 void amxo_ftab_fn_free(const char* key, amxc_htable_it_t* it);
177 
178 PRIVATE
179 void amxo_parser_del_mib_info(const char* key, amxc_htable_it_t* it);
180 
181 PRIVATE
182 ssize_t amxo_parser_fd_reader(amxo_parser_t* parser, char* buf, size_t max_size);
183 
184 PRIVATE
185 int amxo_parser_parse_file_impl(amxo_parser_t* parser, const char* file_path, amxd_object_t* object);
186 
187 PRIVATE
189 
190 PRIVATE
192 
193 PRIVATE
195 
196 PRIVATE
197 void amxo_parser_msg(amxo_parser_t* parser, const char* format, ...) \
198  __attribute__ ((format(printf, 2, 3)));
199 
200 PRIVATE
201 int amxo_parser_printf(amxo_parser_t* parser, const char* format, ...) \
202  __attribute__ ((format(printf, 2, 3)));
203 
204 
205 PRIVATE
206 bool amxo_parser_find(amxo_parser_t* parser, const amxc_llist_t* dirs,
207  const char* file_path, char** full_path);
208 
209 
210 PRIVATE
211 bool amxo_parser_check_attr(amxo_parser_t* pctx, int64_t attributes, int64_t bitmask);
212 
213 PRIVATE
214 bool amxo_parser_set_param_attrs(amxo_parser_t* pctx, uint64_t attr, bool enable);
215 
216 PRIVATE
217 bool amxo_parser_set_param_flags(amxo_parser_t* pctx, amxc_var_t* flags);
218 
219 PRIVATE
220 bool amxo_parser_set_object_attrs(amxo_parser_t* pctx, uint64_t attr, bool enable);
221 
222 PRIVATE
223 int amxo_parser_create_object(amxo_parser_t* pctx, const char* name,
224  int64_t attr_bitmask, amxd_object_type_t type);
225 
226 PRIVATE
227 bool amxo_parser_add_instance(amxo_parser_t* pctx, uint32_t index,
228  const char* name, amxc_var_t* params);
229 
230 PRIVATE
231 bool amxo_parser_push_object(amxo_parser_t* pctx, const char* name);
232 
233 PRIVATE
235 
236 PRIVATE
237 bool amxo_parser_push_param(amxo_parser_t* pctx, const char* name,
238  int64_t attr_bitmask, uint32_t type);
239 
240 PRIVATE
241 int amxo_parser_set_param(amxo_parser_t* pctx, const char* name, amxc_var_t* value);
242 
243 PRIVATE
245 
246 PRIVATE
247 int amxo_parser_push_func(amxo_parser_t* pctx, const char* name,
248  int64_t attr_bitmask, uint32_t type);
249 
250 PRIVATE
251 bool amxo_parser_set_function_flags(amxo_parser_t* pctx, amxc_var_t* flags);
252 
253 PRIVATE
255 
256 PRIVATE
257 bool amxo_parser_add_arg(amxo_parser_t* pctx, const char* name, int64_t attr_bitmask,
258  uint32_t type, amxc_var_t* def_value);
259 
260 PRIVATE
261 bool amxo_parser_set_counter(amxo_parser_t* pctx, const char* param_name);
262 
263 
264 PRIVATE
265 int amxo_parser_subscribe_path(amxo_parser_t* pctx, const char* event, bool event_is_regexp,
266  const char* path, bool path_is_regexp);
267 
268 PRIVATE
269 int amxo_parser_subscribe(amxo_parser_t* pctx, const char* event,
270  bool event_is_regexp, const char* full_expr);
271 
272 PRIVATE
273 int amxo_parser_subscribe_object(amxo_parser_t* pctx, const char* event,
274  bool event_is_regexp, const char* full_expr);
275 
276 PRIVATE
277 int amxo_parser_add_post_include(amxo_parser_t* pctx, const char* file_path);
278 
279 PRIVATE
280 int amxo_parser_include(amxo_parser_t* pctx, const char* file_path);
281 
282 
283 PRIVATE
284 amxc_htable_t* amxo_parser_get_resolvers(void);
285 
286 
287 PRIVATE
288 int amxo_parser_resolve_internal(amxo_parser_t* parser, const char* fn_name,
289  amxo_fn_type_t type, const char* data);
290 
291 PRIVATE
292 void amxo_resolver_import_clean(amxo_parser_t* parser, void* priv);
293 
294 PRIVATE
295 int amxo_parser_resolve(amxo_parser_t* parser, const char* resolver_name,
296  const char* func_name, amxo_fn_type_t type, const char* data);
297 
298 PRIVATE
300 
301 PRIVATE
303 
304 PRIVATE
305 int amxo_parser_call_entry_point(amxo_parser_t* pctx, const char* lib_name, const char* fn_name);
306 
307 PRIVATE
308 int amxo_parser_set_action(amxo_parser_t* pctx, amxo_action_t action, const char* name, amxc_var_t* data);
309 
310 PRIVATE
311 amxo_action_t amxo_parser_get_action_id(amxo_parser_t* pctx, const char* action_name);
312 
313 PRIVATE
314 void amxo_parser_print(amxo_parser_t* pctx, const char* text);
315 
316 PRIVATE
317 bool amxo_parser_add_mib(amxo_parser_t* pctx, const char* mib_name);
318 
319 PRIVATE
321 
322 PRIVATE
323 bool amxo_parser_check_config(amxo_parser_t* pctx, const char* path, const char* check);
324 
325 PRIVATE
326 void amxo_parser_resolve_value(amxo_parser_t* pctx, amxc_string_t* value);
327 
328 PRIVATE
329 void amxo_parser_del_sync_data(amxc_llist_it_t* it);
330 
331 PRIVATE
333 
334 PRIVATE
335 int amxo_parser_push_sync_ctx(amxo_parser_t* pctx, const char* path_a, const char* path_b, int direction);
336 
337 PRIVATE
339  const char* path_a,
340  const char* path_b,
341  int direction,
342  const char* name);
343 PRIVATE
344 int amxo_parser_push_sync_object(amxo_parser_t* pctx, const char* path_a, const char* path_b, int direction);
345 
346 PRIVATE
347 int amxo_parser_push_sync_parameter(amxo_parser_t* pctx, const char* param_a, const char* param_b, int direction);
348 
349 PRIVATE
350 int amxo_parser_start_sync(amxc_llist_it_t* it);
351 
352 PRIVATE
353 void amxo_parser_stop_sync(amxc_llist_it_t* it);
354 
355 PRIVATE
356 amxs_sync_entry_type_t amxo_parser_get_sync_type(amxo_parser_t* pctx);
357 
358 PRIVATE
360 
361 PRIVATE
362 amxd_status_t amxo_parser_sync_set_translator(amxo_parser_t* pctx, amxs_translation_cb_t cb);
363 
364 PRIVATE
365 amxd_status_t amxo_parser_sync_set_action(amxo_parser_t* pctx, amxs_action_cb_t cb);
366 
367 PRIVATE
369 
370 PRIVATE
372 
373 PRIVATE
374 int amxo_parser_sync_update_flags(int direction);
375 
376 PRIVATE
377 amxs_sync_ctx_t* amxo_parser_sync_get(const char* sync_template);
378 
379 #ifdef __cplusplus
380 }
381 #endif
382 
383 #endif // __AMXO_PARSER_PRIV_H__
384 
Ambiorix ODL parser header file.
PRIVATE ssize_t amxo_parser_fd_reader(amxo_parser_t *parser, char *buf, size_t max_size)
struct _event event_t
PRIVATE bool amxo_parser_set_param_attrs(amxo_parser_t *pctx, uint64_t attr, bool enable)
PRIVATE amxs_sync_ctx_t * amxo_parser_sync_get(const char *sync_template)
PRIVATE int amxo_parser_parse_file_impl(amxo_parser_t *parser, const char *file_path, amxd_object_t *object)
PRIVATE void amxo_resolver_import_clean(amxo_parser_t *parser, void *priv)
PRIVATE void amxo_parser_del_mib_info(const char *key, amxc_htable_it_t *it)
PRIVATE void amxo_parser_create_lex(amxo_parser_t *parser)
PRIVATE int amxo_parser_sync_update_flags(int direction)
struct _amxo_txt amxo_txt_t
PRIVATE amxo_action_t amxo_parser_get_action_id(amxo_parser_t *pctx, const char *action_name)
PRIVATE int amxo_parser_subscribe_path(amxo_parser_t *pctx, const char *event, bool event_is_regexp, const char *path, bool path_is_regexp)
_amxo_parser_attr
@ attr_instance
@ attr_variable
@ attr_protected
@ attr_asynchronous
@ attr_template
@ attr_persistent
@ attr_readonly
@ attr_mandatory
@ attr_private
@ attr_strict
@ attr_in
@ attr_key
@ attr_unique
@ attr_out
@ attr_mutable
PRIVATE void amxo_parser_stop_sync(amxc_llist_it_t *it)
PRIVATE bool amxo_parser_add_mib(amxo_parser_t *pctx, const char *mib_name)
PRIVATE amxc_htable_t * amxo_parser_get_resolvers(void)
PRIVATE amxd_status_t amxo_parser_sync_set_action(amxo_parser_t *pctx, amxs_action_cb_t cb)
PRIVATE void amxo_parser_del_sync_data(amxc_llist_it_t *it)
PRIVATE bool amxo_parser_set_counter(amxo_parser_t *pctx, const char *param_name)
enum _amxo_parser_attr amxo_parser_attr_t
PRIVATE bool amxo_parser_set_param_flags(amxo_parser_t *pctx, amxc_var_t *flags)
PRIVATE amxd_status_t amxo_parser_sync_set_translator(amxo_parser_t *pctx, amxs_translation_cb_t cb)
_amxo_action
@ action_read
@ action_translate
@ action_all
@ action_write
@ action_apply
@ action_add_inst
@ action_list
@ action_describe
@ amxo_action_invalid
@ action_max
@ action_destroy
@ action_del_inst
@ action_validate
PRIVATE bool amxo_parser_set_object_attrs(amxo_parser_t *pctx, uint64_t attr, bool enable)
PRIVATE void amxo_parser_sync_remove_invalid(amxo_parser_t *pctx)
PRIVATE int amxo_parser_create_object(amxo_parser_t *pctx, const char *name, int64_t attr_bitmask, amxd_object_type_t type)
PRIVATE void amxo_parser_destroy_lex(amxo_parser_t *parser)
PRIVATE bool amxo_parser_check_attr(amxo_parser_t *pctx, int64_t attributes, int64_t bitmask)
PRIVATE bool amxo_parser_pop_object(amxo_parser_t *pctx)
PRIVATE int amxo_parser_start_sync(amxc_llist_it_t *it)
struct _amxo_txt_regexp amxo_txt_regexp_t
PRIVATE bool amxo_parser_no_resolve(amxo_parser_t *parser)
PRIVATE void PRIVATE int PRIVATE bool amxo_parser_find(amxo_parser_t *parser, const amxc_llist_t *dirs, const char *file_path, char **full_path)
PRIVATE int amxo_parser_set_param(amxo_parser_t *pctx, const char *name, amxc_var_t *value)
PRIVATE int amxo_parser_push_sync_object(amxo_parser_t *pctx, const char *path_a, const char *path_b, int direction)
PRIVATE int amxo_parser_add_post_include(amxo_parser_t *pctx, const char *file_path)
PRIVATE void amxo_ftab_fn_free(const char *key, amxc_htable_it_t *it)
PRIVATE int amxo_parser_push_sync_parameter(amxo_parser_t *pctx, const char *param_a, const char *param_b, int direction)
PRIVATE bool amxo_parser_check_config(amxo_parser_t *pctx, const char *path, const char *check)
PRIVATE void amxo_parser_msg(amxo_parser_t *parser, const char *format,...) __attribute__((format(printf
PRIVATE amxs_sync_entry_type_t amxo_parser_get_sync_type(amxo_parser_t *pctx)
PRIVATE void amxo_parser_pop_sync_item(amxo_parser_t *pctx)
PRIVATE int amxo_parser_set_action(amxo_parser_t *pctx, amxo_action_t action, const char *name, amxc_var_t *data)
PRIVATE bool amxo_parser_sync_item_contains_entries(amxo_parser_t *pctx)
PRIVATE int amxo_parser_resolve(amxo_parser_t *parser, const char *resolver_name, const char *func_name, amxo_fn_type_t type, const char *data)
PRIVATE void PRIVATE int amxo_parser_printf(amxo_parser_t *parser, const char *format,...) __attribute__((format(printf
amxo_parser_tokens_t
@ token_define
@ token_post_include
@ token_requires
@ token_object
@ token_conditional_include
@ token_mib
@ token_eof
@ token_keyword
@ token_import
@ token_populate
@ token_optional_include
@ token_include
@ token_config
PRIVATE void amxo_parser_resolve_value(amxo_parser_t *pctx, amxc_string_t *value)
PRIVATE bool amxo_parser_push_object(amxo_parser_t *pctx, const char *name)
PRIVATE int amxo_parser_call_entry_point(amxo_parser_t *pctx, const char *lib_name, const char *fn_name)
PRIVATE void amxo_parser_clean_resolvers(amxo_parser_t *parser)
PRIVATE bool amxo_parser_set_function_flags(amxo_parser_t *pctx, amxc_var_t *flags)
PRIVATE int amxo_parser_subscribe(amxo_parser_t *pctx, const char *event, bool event_is_regexp, const char *full_expr)
PRIVATE bool amxo_parser_push_param(amxo_parser_t *pctx, const char *name, int64_t attr_bitmask, uint32_t type)
PRIVATE void amxo_parser_print(amxo_parser_t *pctx, const char *text)
PRIVATE int amxo_parser_subscribe_object(amxo_parser_t *pctx, const char *event, bool event_is_regexp, const char *full_expr)
PRIVATE void amxo_parser_child_init(amxo_parser_t *parser)
PRIVATE int amxo_parser_include(amxo_parser_t *pctx, const char *file_path)
enum _amxo_action amxo_action_t
PRIVATE int amxo_parser_push_func(amxo_parser_t *pctx, const char *name, int64_t attr_bitmask, uint32_t type)
PRIVATE bool amxo_parser_add_instance(amxo_parser_t *pctx, uint32_t index, const char *name, amxc_var_t *params)
PRIVATE int amxo_parser_push_sync_template(amxo_parser_t *pctx, const char *path_a, const char *path_b, int direction, const char *name)
PRIVATE int amxo_parser_resolve_internal(amxo_parser_t *parser, const char *fn_name, amxo_fn_type_t type, const char *data)
PRIVATE bool amxo_parser_pop_param(amxo_parser_t *pctx)
PRIVATE void amxo_parser_init_resolvers(amxo_parser_t *parser)
PRIVATE bool amxo_parser_is_sync_item(amxo_parser_t *pctx)
PRIVATE bool amxo_parser_add_arg(amxo_parser_t *pctx, const char *name, int64_t attr_bitmask, uint32_t type, amxc_var_t *def_value)
enum _event_id event_id_t
_event_id
@ event_instance_add
@ event_object_change
@ event_none
PRIVATE void amxo_parser_pop_func(amxo_parser_t *pctx)
struct _amxo_res_data amxo_res_data_t
PRIVATE int amxo_parser_push_sync_ctx(amxo_parser_t *pctx, const char *path_a, const char *path_b, int direction)
PRIVATE void amxo_parser_free_event(amxc_llist_it_t *it)
enum _amxo_fn_type amxo_fn_type_t
The ODL parser structure.
Definition: amxo_types.h:245
amxc_htable_it_t hit
amxc_htable_t data
char * path
event_id_t id
amxc_llist_it_t it
amxc_var_t data