61 #include "amxo_parser.tab.h"
67 result = amxc_rbuffer_read(&parser->
rbuffer, (
char*) buf, max_size);
75 amxd_object_t*
object) {
81 parser->
status = amxd_status_ok;
83 amxc_string_reset(&parser->
msg);
85 retval = yyparse(parser->
scanner);
93 amxc_string_clean(&parser->
msg);
109 result = read(parser->
fd, buf, max_size - 1);
110 if((result == -1) && (errno != EAGAIN)) {
111 printf(
"Read failed %d\n", errno);
117 while(result - offset > 0 && buf[result - offset - 1] !=
'\n') {
120 if(result - offset > 0) {
121 lseek(parser->
fd, -offset, SEEK_CUR);
130 amxd_object_t*
object = amxd_dm_findf(dm,
"%s", e->
path);
132 when_null(
object, exit);
134 if(dm->sigmngr.enabled) {
136 amxd_object_send_add_inst(
object,
false);
138 amxd_object_send_changed(
object, &e->
data,
false);
143 amxc_llist_it_take(&e->
it);
144 amxc_var_clean(&e->
data);
150 amxc_llist_for_each(it, &parser->
event_list) {
157 const char* file_path,
158 amxd_object_t*
object) {
162 fd = open(file_path, O_RDONLY);
165 if(errno == ENOENT) {
172 parser->
file = file_path;
182 when_null(parser, exit);
186 parser->
param = NULL;
188 parser->
status = amxd_status_ok;
192 parser->
hooks = NULL;
203 memset(parser->
buffer, 0, 128);
204 amxc_rbuffer_init(&parser->
rbuffer, 0);
205 amxc_string_init(&parser->
msg, 0);
208 amxc_var_init(&parser->
config);
210 amxc_htable_init(&parser->
mibs, 5);
213 parser->
file =
"<unknown>";
221 amxc_var_t* inc_dirs = NULL;
222 when_null(parser, exit);
226 amxc_var_set_type(&parser->
config, AMXC_VAR_ID_HTABLE);
227 inc_dirs = amxc_var_add_key(amxc_llist_t, &parser->
config,
"include-dirs", NULL);
228 amxc_var_add(cstring_t, inc_dirs,
".");
239 when_null(parser, exit);
243 parser->
param = NULL;
245 parser->
status = amxd_status_ok;
248 amxc_rbuffer_clean(&parser->
rbuffer);
249 amxc_string_clean(&parser->
msg);
252 amxc_llist_clean(&parser->
global_config, amxc_string_list_it_free);
256 amxc_htable_delete(&parser->
resolvers, NULL);
259 amxc_llist_delete(&parser->
hooks, NULL);
260 amxc_var_clean(&parser->
config);
263 amxc_llist_clean(&parser->
function_names, amxc_string_list_it_free);
276 when_null(parser, exit);
279 when_null((*parser), exit);
284 if((retval != 0) && (*parser != NULL)) {
293 when_null(parser, exit);
294 when_null(*parser, exit);
306 amxd_object_t*
object) {
308 struct rlimit nofile = { 0, 0 };
309 when_null(parser, exit);
310 when_null(
object, exit);
312 when_failed(getrlimit(RLIMIT_NOFILE, &nofile), exit);
314 when_true(fd < 0 || (rlim_t) llabs(fd) > nofile.rlim_max, exit);
315 when_failed(fcntl((
int) llabs(fd), F_GETFD), exit);
319 amxc_llist_clean(&parser->
global_config, amxc_string_list_it_free);
329 const char* file_path,
330 amxd_object_t*
object) {
332 char* current_wd = getcwd(NULL, 0);
333 char* real_path = NULL;
334 char* dir_name = NULL;
335 amxc_string_t res_file_path;
336 amxc_string_init(&res_file_path, 0);
338 when_null(parser, exit);
339 when_str_empty(file_path, exit);
340 when_null(
object, exit);
342 if(amxc_string_set_resolved(&res_file_path, file_path, &parser->
config) > 0) {
343 file_path = amxc_string_get(&res_file_path, 0);
346 real_path = realpath(file_path, NULL);
347 if(real_path != NULL) {
348 dir_name = dirname(real_path);
349 when_true(chdir(dir_name) == -1, exit);
350 if(dir_name[1] != 0) {
351 dir_name[strlen(dir_name)] =
'/';
354 real_path = realpath(file_path, NULL);
358 parser->
file = (real_path == NULL) ? file_path : real_path;
361 real_path == NULL ? file_path : real_path,
363 amxc_llist_clean(&parser->
global_config, amxc_string_list_it_free);
368 if(real_path != NULL) {
369 when_true(chdir(current_wd) == -1, exit);
373 amxc_string_clean(&res_file_path);
381 amxd_object_t*
object) {
383 when_null(parser, exit);
384 when_null(
object, exit);
385 when_str_empty(text, exit);
387 amxc_rbuffer_write(&parser->
rbuffer, text, strlen(text));
390 parser->
status = amxd_status_ok;
393 amxc_string_reset(&parser->
msg);
395 retval = yyparse(parser->
scanner);
403 amxc_rbuffer_clean(&parser->
rbuffer);
412 amxc_var_t* retval = NULL;
413 when_null(parser, exit);
414 when_str_empty(path, exit);
420 amxc_var_init(&dummy);
423 amxc_var_clean(&dummy);
432 amxc_var_t* retval = NULL;
433 when_null(parser, exit);
434 when_str_empty(path, exit);
436 retval = amxc_var_get_path(&parser->
config, path, AMXC_VAR_FLAG_DEFAULT);
446 when_null(parser, exit);
447 when_null(value, exit);
448 when_str_empty(path, exit);
450 retval = amxc_var_set_path(&parser->
config,
453 AMXC_VAR_FLAG_UPDATE | AMXC_VAR_FLAG_COPY | AMXC_VAR_FLAG_AUTO_ADD);
463 when_null(parser, exit);
498 bool dm_eventing_enabled =
true;
499 when_null(parser, exit);
513 when_true(fail_count > 0, exit);
517 while(amxp_signal_read() == 0) {
520 dm_eventing_enabled = GET_BOOL(&parser->
config,
"dm-eventing-enabled");
521 amxp_sigmngr_enable(&dm->sigmngr, dm_eventing_enabled);
523 const char* file = amxc_var_constcast(cstring_t, var);
527 amxc_var_delete(&var);
529 amxp_sigmngr_enable(&dm->sigmngr,
true);
542 when_null(parser, exit);
564 when_null(parser, exit);
580 when_null(parser, exit);
593 const char* object_a,
594 const char* object_b) {
595 amxs_sync_ctx_t* templ = NULL;
596 amxs_sync_ctx_t* ctx = NULL;
597 amxs_status_t status = amxs_status_ok;
600 status = amxs_sync_ctx_copy(&ctx, templ, NULL);
601 when_failed(status, exit);
603 status = amxs_sync_ctx_set_paths(ctx, object_a, object_b);
606 if(status != amxs_status_ok) {
607 amxs_sync_ctx_delete(&ctx);
PRIVATE void amxo_hooks_start(amxo_parser_t *parser)
PRIVATE void amxo_hooks_end(amxo_parser_t *parser)
static ssize_t amxo_parser_string_reader(amxo_parser_t *parser, char *buf, size_t max_size)
static void amxo_parser_pop_event(event_t *e, amxd_dm_t *dm)
static void amxo_parser_send_events(amxo_parser_t *parser, amxd_dm_t *dm)
static void amxo_parser_entry_point_free(amxc_llist_it_t *it)
static int amxo_parser_parse_fd_internal(amxo_parser_t *parser, int fd, amxd_object_t *object)
void amxo_parser_child_init(amxo_parser_t *parser)
ssize_t amxo_parser_fd_reader(amxo_parser_t *parser, char *buf, size_t max_size)
int amxo_parser_parse_file_impl(amxo_parser_t *parser, const char *file_path, amxd_object_t *object)
PRIVATE amxs_sync_ctx_t * amxo_parser_sync_get(const char *sync_template)
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 void amxo_parser_stop_sync(amxc_llist_it_t *it)
PRIVATE void amxo_parser_del_sync_data(amxc_llist_it_t *it)
PRIVATE void amxo_parser_sync_remove_invalid(amxo_parser_t *pctx)
PRIVATE void amxo_parser_destroy_lex(amxo_parser_t *parser)
PRIVATE int amxo_parser_start_sync(amxc_llist_it_t *it)
PRIVATE void amxo_parser_msg(amxo_parser_t *parser, const char *format,...) __attribute__((format(printf
PRIVATE void amxo_parser_clean_resolvers(amxo_parser_t *parser)
PRIVATE void amxo_parser_init_resolvers(amxo_parser_t *parser)
PRIVATE void amxo_parser_free_event(amxc_llist_it_t *it)
int(* amxo_entry_point_t)(int reason, amxd_dm_t *dm, amxo_parser_t *parser)
amxc_var_t * amxo_parser_get_config(amxo_parser_t *parser, const char *path)
Gets a configuration option.
int amxo_parser_set_config(amxo_parser_t *parser, const char *path, amxc_var_t *value)
Sets a configuration option.
amxc_var_t * amxo_parser_claim_config(amxo_parser_t *parser, const char *path)
Gets or creates a configuration option.
int amxo_parser_parse_fd(amxo_parser_t *parser, int fd, amxd_object_t *object)
Parses an odl file.
int amxo_parser_start_synchronize(amxo_parser_t *parser)
Start all object and parameter synchronizations that were declared in the loaded odl files.
int amxo_parser_parse_string(amxo_parser_t *parser, const char *text, amxd_object_t *object)
Parses a string containing a valid ODL part.
void amxo_parser_clean(amxo_parser_t *parser)
Cleans up the odl parser instance.
int amxo_parser_parse_file(amxo_parser_t *parser, const char *file_path, amxd_object_t *object)
Parses an odl file.
int amxo_parser_add_entry_point(amxo_parser_t *parser, amxo_entry_point_t fn)
Adds an entry point function.
int amxo_parser_new(amxo_parser_t **parser)
Allocates memory for a new parser instance on the heap and initializes the odl parser.
amxs_sync_ctx_t * amxo_parser_new_sync_ctx(const char *sync_template, const char *object_a, const char *object_b)
Create a new synchronization context from a synchronization template.
int amxo_parser_init(amxo_parser_t *parser)
Initializes a new odl parser instance.
int amxo_parser_rinvoke_entry_points(amxo_parser_t *parser, amxd_dm_t *dm, int reason)
Invokes all registered entry points in reversed order.
void amxo_parser_delete(amxo_parser_t **parser)
Cleans the odl parser content and frees the allocated memory.
void amxo_parser_stop_synchronize(amxo_parser_t *parser)
Stop all object and parameter synchronizations that were declared in odl files.
int amxo_parser_invoke_entry_points(amxo_parser_t *parser, amxd_dm_t *dm, int reason)
Invokes all registered entry points.
amxo_entry_point_t entry_point
The ODL parser structure.
amxc_htable_t * resolvers
amxo_fn_ptr_t resolved_fn
amxc_astack_t object_stack
amxc_llist_t function_names
amxc_string_t * resolved_fn_name
amxc_var_t * include_stack
amxc_llist_t * entry_points
amxc_llist_t global_config
amxc_var_t * post_includes
amxc_llist_t * sync_contexts