1 |
/*! |
2 |
|
3 |
\file pdl.h |
4 |
\brief Callback functions for parser of the evaluation manager |
5 |
\author Aram Verstegen |
6 |
|
7 |
This header contains some callback functions used for the PDL parser: |
8 |
It contains the following functions: |
9 |
|
10 |
-# pdl_init(const char*): Inilizes the parser |
11 |
-# pdl_term(void): terminates the parser |
12 |
-# set_modules_path(record_t*): sets the path to use for plug-ins (used by the parser) |
13 |
-# get_pdl_path(void): returns the path read from the config file or empty string if none was parsed |
14 |
-# add_policy(record_t*, rule_t*): adds a new policy |
15 |
-# add_rule(record_t*, record_t*, record_t*): adds a new rule |
16 |
-# remove_policy(record_t* policy): removes a policy |
17 |
-# add_variable(record_t* name, record_t* value): adds a variable (plug-in) to the list |
18 |
-# allow_rules(int): |
19 |
-# allowed_policy_rule(const char* label): |
20 |
|
21 |
-# concat_strings(record_t*, record_t*): concatenates two strings |
22 |
-# concat_strings_with_space(record_t*, record_t*): concatenates two strings separated by a space |
23 |
*/ |
24 |
|
25 |
#ifndef PDL_H |
26 |
#define PDL_H |
27 |
|
28 |
#if HAVE_CONFIG_H |
29 |
#include "config.h" |
30 |
#endif |
31 |
#if HAVE_STDIO_H |
32 |
#include <stdio.h> |
33 |
#endif |
34 |
#if HAVE_STDLIB_H |
35 |
#include <stdlib.h> |
36 |
#endif |
37 |
#include "plugin_manager.h" |
38 |
#include "eef_log.h" |
39 |
|
40 |
#define TRUE 1 |
41 |
#define FALSE 0 |
42 |
|
43 |
/*! |
44 |
* \brief Structure for symbols used by the parser internally |
45 |
*/ |
46 |
typedef struct record_s { |
47 |
char* string; /*!< Hold the symbol that lex has found. */ |
48 |
int lineno; /*!< Hold the line number the symbol has been found. */ |
49 |
} record_t; |
50 |
|
51 |
|
52 |
/*! |
53 |
* \brief Structure keeps track of the variables, their value and the line number they are defined on. |
54 |
*/ |
55 |
typedef struct var_s { |
56 |
char* name; /*!< Name of the variable. */ |
57 |
char* value; /*!< Value of the variable. */ |
58 |
unsigned int lineno; /*!< Line number the variable appears on. */ |
59 |
struct var_s* next; /*!< Next variable, or 0 if none. */ |
60 |
} var_t; |
61 |
|
62 |
/*! |
63 |
* \brief Structure to make a tree of |
64 |
* |
65 |
*/ |
66 |
typedef struct rule_s { |
67 |
unsigned int lineno; /*!< Line number where rule appeared. */ |
68 |
char* state; /*!< Name of the state.*/ |
69 |
struct rule_s* true_branch; /*!< True branch or NULL if none */ |
70 |
struct rule_s* false_branch; /*!< False branch or NULL if none */ |
71 |
struct rule_s* next; /*!< Next rule, or NULL if none */ |
72 |
} rule_t; |
73 |
|
74 |
/*! |
75 |
* \brief Structure to build a tree of plugins as defined in a policy in the config file |
76 |
*/ |
77 |
typedef struct policy_s { |
78 |
char* name; |
79 |
unsigned int lineno; |
80 |
rule_t* rules; |
81 |
struct policy_s* next; |
82 |
} policy_t; |
83 |
|
84 |
/* lifecycle functions */ |
85 |
EES_RC pdl_init(const char*); |
86 |
EES_RC pdl_term(void); |
87 |
EES_RC add_plugins(void); |
88 |
|
89 |
EES_RC clean_variables_list(void); |
90 |
EES_RC clean_policies_list(void); |
91 |
EES_RC clean_rules_list(rule_t*); |
92 |
|
93 |
eef_plugindl_t* build_plugin_tree(policy_t*); |
94 |
|
95 |
|
96 |
/* callback functions */ |
97 |
void set_pdl_path(record_t*); |
98 |
void add_policy(record_t*, rule_t*); |
99 |
rule_t * add_rule(record_t*, record_t*, record_t*); |
100 |
const char * get_pdl_path(void); |
101 |
void remove_policy(record_t* policy); |
102 |
void add_variable(record_t* name, record_t* value); |
103 |
EES_RC allow_rules(int); |
104 |
EES_RC allowed_policy_rule(const char* label); |
105 |
|
106 |
/* convenience methods used by the lexer */ |
107 |
record_t * concat_strings(record_t*, record_t*); |
108 |
record_t * concat_strings_with_space(record_t*, record_t*); |
109 |
char ** _var_to_argv(char*, int*); |
110 |
var_t* get_variable_by_name(char*); |
111 |
rule_t* find_state(rule_t* rule, const char* state); |
112 |
rule_t* check_for_recursion(rule_t*, rule_t*); |
113 |
|
114 |
|
115 |
/* Lex/Yacc stuff */ |
116 |
int yyerror(char*); |
117 |
void set_yylval(record_t* r); |
118 |
|
119 |
/* debug functions */ |
120 |
void print_policies(void); |
121 |
|
122 |
#endif |