libamxo  4.3.4
Object Definition Language (ODL) parsing
amxo_parser_hooks.c
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 #ifndef _GNU_SOURCE
56 #define _GNU_SOURCE
57 #endif
58 
59 #include "amxo_parser_priv.h"
60 #include "amxo_parser_hooks_priv.h"
61 #include "amxo_parser.tab.h"
62 
63 void amxo_hooks_comment(amxo_parser_t* parser, char* comment, uint32_t len) {
64  comment[len] = 0;
65  amxc_llist_for_each(it, parser->hooks) {
66  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
67  if(hook->comment != NULL) {
68  hook->comment(parser, comment);
69  }
70  }
71 }
72 
74  amxc_llist_for_each(it, parser->hooks) {
75  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
76  if(hook->start != NULL) {
77  hook->start(parser);
78  }
79  }
80 }
81 
83  amxc_llist_for_each(it, parser->hooks) {
84  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
85  if(hook->end != NULL) {
86  hook->end(parser);
87  }
88  }
89 }
90 
91 void amxo_hooks_start_include(amxo_parser_t* parser, const char* file) {
92  amxc_llist_for_each(it, parser->hooks) {
93  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
94  if(hook->start_include != NULL) {
95  hook->start_include(parser, file);
96  }
97  }
98 }
99 
100 void amxo_hooks_end_include(amxo_parser_t* parser, const char* file) {
101  amxc_llist_for_each(it, parser->hooks) {
102  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
103  if(hook->end_include != NULL) {
104  hook->end_include(parser, file);
105  }
106  }
107 }
108 
109 void amxo_hooks_start_section(amxo_parser_t* parser, int section_id) {
110  amxc_llist_for_each(it, parser->hooks) {
111  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
112  if(hook->start_section != NULL) {
113  hook->start_section(parser, section_id);
114  }
115  }
116 }
117 
118 void amxo_hooks_end_section(amxo_parser_t* parser, int section_id) {
119  amxc_llist_for_each(it, parser->hooks) {
120  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
121  if(hook->end_section != NULL) {
122  hook->end_section(parser, section_id);
123  }
124  }
125 }
126 
128  const char* name,
129  amxc_var_t* value) {
130  amxc_llist_for_each(it, parser->hooks) {
131  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
132  if(hook->set_config != NULL) {
133  hook->set_config(parser, name, value);
134  }
135  }
136 }
137 
139  const char* name,
140  int64_t attr_bitmask,
141  amxd_object_type_t type) {
142  amxc_llist_for_each(it, parser->hooks) {
143  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
144  if(hook->create_object != NULL) {
145  hook->create_object(parser,
146  parser->object,
147  name,
148  attr_bitmask,
149  type);
150  }
151  }
152 }
153 
155  uint32_t index,
156  const char* name) {
157  amxc_llist_for_each(it, parser->hooks) {
158  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
159  if(hook->add_instance != NULL) {
160  hook->add_instance(parser,
161  parser->object,
162  index,
163  name);
164  }
165  }
166 }
167 
169  const char* path) {
170  amxc_llist_for_each(it, parser->hooks) {
171  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
172  if(hook->select_object != NULL) {
173  hook->select_object(parser,
174  parser->object,
175  path);
176  }
177  }
178 }
179 
181  amxc_llist_for_each(it, parser->hooks) {
182  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
183  if(hook->end_object != NULL) {
184  hook->end_object(parser,
185  parser->object);
186  }
187  }
188 }
189 
191  const char* name,
192  int64_t attr_bitmask,
193  uint32_t type) {
194  amxc_llist_for_each(it, parser->hooks) {
195  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
196  if(hook->add_param != NULL) {
197  hook->add_param(parser,
198  parser->object,
199  name,
200  attr_bitmask,
201  type);
202  }
203  }
204 }
205 
207  amxc_var_t* value) {
208  amxc_llist_for_each(it, parser->hooks) {
209  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
210  if(hook->set_param != NULL) {
211  hook->set_param(parser,
212  parser->object,
213  parser->param,
214  value);
215  }
216  }
217 }
218 
220  amxc_llist_for_each(it, parser->hooks) {
221  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
222  if(hook->end_param != NULL) {
223  hook->end_param(parser,
224  parser->object,
225  parser->param);
226  }
227  }
228 }
229 
231  const char* name,
232  int64_t attr_bitmask,
233  uint32_t type) {
234  amxc_llist_for_each(it, parser->hooks) {
235  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
236  if(hook->add_func != NULL) {
237  hook->add_func(parser,
238  parser->object,
239  name,
240  attr_bitmask,
241  type);
242  }
243  }
244 }
245 
247  amxc_llist_for_each(it, parser->hooks) {
248  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
249  if(hook->end_func != NULL) {
250  hook->end_func(parser,
251  parser->object,
252  parser->func);
253  }
254  }
255 }
256 
258  const char* mib) {
259  amxc_llist_for_each(it, parser->hooks) {
260  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
261  if(hook->add_mib != NULL) {
262  hook->add_mib(parser,
263  parser->object,
264  mib);
265  }
266  }
267 }
268 
269 
271  const char* name,
272  int64_t attr_bitmask,
273  uint32_t type,
274  amxc_var_t* def_value) {
275  amxc_llist_for_each(it, parser->hooks) {
276  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
277  if(hook->add_func_arg != NULL) {
278  hook->add_func_arg(parser,
279  parser->object,
280  parser->func,
281  name,
282  attr_bitmask,
283  type,
284  def_value);
285  }
286  }
287 }
288 
290  const char* param_name) {
291  amxc_llist_for_each(it, parser->hooks) {
292  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
293  if(hook->set_counter != NULL) {
294  hook->set_counter(parser,
295  parser->object,
296  param_name);
297  }
298  }
299 }
300 
302  amxd_object_t* object,
303  amxd_param_t* param,
304  amxd_action_t action_id,
305  const char* action_name,
306  const amxc_var_t* data) {
307  amxc_llist_for_each(it, parser->hooks) {
308  amxo_hooks_t* hook = amxc_container_of(it, amxo_hooks_t, it);
309  if(hook->set_action_cb != NULL) {
310  hook->set_action_cb(parser,
311  object,
312  param,
313  action_id,
314  action_name,
315  data);
316  }
317  }
318 }
319 
321  amxo_hooks_t* hooks) {
322  int retval = -1;
323  when_null(parser, exit);
324  when_null(hooks, exit);
325  when_not_null(hooks->it.llist, exit);
326 
327  if(parser->hooks == NULL) {
328  amxc_llist_new(&parser->hooks);
329  }
330  retval = amxc_llist_append(parser->hooks, &hooks->it);
331 
332 exit:
333  return retval;
334 }
335 
337  amxo_hooks_t* hooks) {
338  int retval = -1;
339 
340  when_null(parser, exit);
341  when_null(hooks, exit);
342 
343  when_true(parser->hooks != hooks->it.llist, exit);
344 
345  amxc_llist_it_take(&hooks->it);
346  if(amxc_llist_is_empty(parser->hooks)) {
347  amxc_llist_delete(&parser->hooks, NULL);
348  }
349  retval = 0;
350 
351 exit:
352  return retval;
353 }
void amxo_hooks_end_include(amxo_parser_t *parser, const char *file)
void amxo_hooks_comment(amxo_parser_t *parser, char *comment, uint32_t len)
void amxo_hooks_select_object(amxo_parser_t *parser, const char *path)
void amxo_hooks_add_mib(amxo_parser_t *parser, const char *mib)
void amxo_hooks_start(amxo_parser_t *parser)
void amxo_hooks_start_section(amxo_parser_t *parser, int section_id)
void amxo_hooks_end(amxo_parser_t *parser)
void amxo_hooks_end_section(amxo_parser_t *parser, int section_id)
void amxo_hooks_create_object(amxo_parser_t *parser, const char *name, int64_t attr_bitmask, amxd_object_type_t type)
void amxo_hooks_add_func_arg(amxo_parser_t *parser, const char *name, int64_t attr_bitmask, uint32_t type, amxc_var_t *def_value)
void amxo_hooks_set_config(amxo_parser_t *parser, const char *name, amxc_var_t *value)
void amxo_hooks_end_func(amxo_parser_t *parser)
void amxo_hooks_set_param(amxo_parser_t *parser, amxc_var_t *value)
void amxo_hooks_end_object(amxo_parser_t *parser)
void amxo_hooks_add_param(amxo_parser_t *parser, const char *name, int64_t attr_bitmask, uint32_t type)
void amxo_hooks_end_param(amxo_parser_t *parser)
void amxo_hooks_start_include(amxo_parser_t *parser, const char *file)
int amxo_parser_set_hooks(amxo_parser_t *parser, amxo_hooks_t *hooks)
void amxo_hooks_add_instance(amxo_parser_t *parser, uint32_t index, const char *name)
void amxo_hooks_add_func(amxo_parser_t *parser, const char *name, int64_t attr_bitmask, uint32_t type)
void amxo_hooks_set_action_cb(amxo_parser_t *parser, amxd_object_t *object, amxd_param_t *param, amxd_action_t action_id, const char *action_name, const amxc_var_t *data)
void amxo_hooks_set_counter(amxo_parser_t *parser, const char *param_name)
int amxo_parser_unset_hooks(amxo_parser_t *parser, amxo_hooks_t *hooks)
amxo_include_t start_include
Definition: amxo_types.h:186
amxo_set_counter_t set_counter
Definition: amxo_types.h:202
amxo_comment_t comment
Definition: amxo_types.h:183
amxo_start_end_t end
Definition: amxo_types.h:185
amxo_add_func_arg_t add_func_arg
Definition: amxo_types.h:199
amxo_add_instance_t add_instance
Definition: amxo_types.h:192
amxo_section_t end_section
Definition: amxo_types.h:190
amxc_llist_it_t it
Definition: amxo_types.h:182
amxo_add_param_func_t add_param
Definition: amxo_types.h:195
amxo_end_func_t end_func
Definition: amxo_types.h:200
amxo_end_param_t end_param
Definition: amxo_types.h:197
amxo_section_t start_section
Definition: amxo_types.h:189
amxo_set_action_cb_t set_action_cb
Definition: amxo_types.h:203
amxo_add_param_func_t add_func
Definition: amxo_types.h:198
amxo_select_object_t select_object
Definition: amxo_types.h:193
amxo_set_config_t set_config
Definition: amxo_types.h:188
amxo_start_end_t start
Definition: amxo_types.h:184
amxo_add_mib_t add_mib
Definition: amxo_types.h:201
amxo_set_param_t set_param
Definition: amxo_types.h:196
amxo_end_object_t end_object
Definition: amxo_types.h:194
amxo_create_object_t create_object
Definition: amxo_types.h:191
amxo_include_t end_include
Definition: amxo_types.h:187
The ODL parser structure.
Definition: amxo_types.h:245
amxc_llist_t * hooks
Definition: amxo_types.h:274
amxd_param_t * param
Definition: amxo_types.h:263
amxd_object_t * object
Definition: amxo_types.h:262
amxd_function_t * func
Definition: amxo_types.h:264