1/*****************************************************************************\
2*  _  _       _          _              ___                                   *
3* | || | ___ | |_  _ __ | | _  _  __ _ |_  )                                  *
4* | __ |/ _ \|  _|| '_ \| || || |/ _` | / /                                   *
5* |_||_|\___/ \__|| .__/|_| \_,_|\__, |/___|                                  *
6*                 |_|            |___/                                        *
7\*****************************************************************************/
8
9#ifndef RULES_H
10#define RULES_H 1
11
12#define COND_MATCH_CMP			0	/* == */
13#define COND_MATCH_RE			1	/* ~~ */
14#define COND_NMATCH_CMP			2	/* != */
15#define COND_NMATCH_RE			3	/* !~ */
16#define COND_MATCH_IS			4	/* is */
17
18#define ACT_RUN_SHELL			0	/* system app <...>, run app <...> */
19#define ACT_RUN_NOSHELL			1	/* exec app <...> */
20#define ACT_STOP_PROCESSING		2	/* break */
21#define ACT_STOP_IF_FAILED		3	/* break_if_failed */
22#define ACT_MAKE_DEVICE			4	/* makedev <...> */
23#define ACT_CHMOD			5	/* chmod <...> */
24#define ACT_CHGRP			6	/* chgrp <...> */
25#define ACT_CHOWN			7	/* chown <...> */
26#define ACT_SYMLINK			8	/* symlink <...> */
27#define ACT_NEXT_EVENT		9	/* next */
28#define ACT_NEXT_IF_FAILED		10	/* next_if_failed */
29#define ACT_SETENV			11	/* setenv <...> */
30
31#define EVAL_MATCH			1
32#define EVAL_NOT_MATCH			0
33#define EVAL_NOT_AVAILABLE		-1
34
35#define QUOTES_NONE			0
36#define QUOTES_SINGLE			1
37#define QUOTES_DOUBLE			2
38
39#define STATUS_KEY			0	/* just about anything */
40#define STATUS_CONDTYPE			1	/* viz COND_* */
41#define STATUS_VALUE			2	/* just about anything */
42#define STATUS_INITIATOR		3	/* ',' for next cond, '{' for block*/
43#define STATUS_ACTION			4	/* viz ACT_* and '}' for end of block */
44
45struct key_rec_t {
46	char *key;
47	int param;
48	int type;
49};
50
51struct condition_t {
52	int type;
53	char *key;
54	char *value;
55};
56
57struct action_t {
58	int type;
59	char **parameter;
60};
61
62struct rule_t {
63	struct condition_t *conditions;
64	int conditions_c;
65
66	struct action_t *actions;
67	int actions_c;
68};
69
70struct rules_t {
71	struct rule_t *rules;
72	int rules_c;
73};
74
75int rule_execute(struct hotplug2_event_t *, struct rule_t *);
76void rules_free(struct rules_t *);
77struct rules_t *rules_from_config(char *);
78
79#endif /* ifndef RULES_H*/
80