The "trylock" test patch.
[lcr.git] / route.h
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** match header file                                                         **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12
13 /* memory structure of rulesets */
14
15 enum { /* value types */
16         VALUE_TYPE_NULL,
17         VALUE_TYPE_INTEGER,
18         VALUE_TYPE_INTEGER_RANGE,
19         VALUE_TYPE_STRING,
20         VALUE_TYPE_STRING_RANGE,
21 };
22
23 enum { /* how to parse text file during startup */
24         COND_TYPE_NULL,
25         COND_TYPE_INTEGER,
26         COND_TYPE_TIME,
27         COND_TYPE_MDAY,
28         COND_TYPE_MONTH,
29         COND_TYPE_WDAY,
30         COND_TYPE_YEAR,
31         COND_TYPE_STRING,
32         COND_TYPE_IP,
33         COND_TYPE_CAPABILITY,
34         COND_TYPE_BMODE,
35         COND_TYPE_HLC,
36         COND_TYPE_IFATTR,
37 };
38
39 enum { /* what to check during runtime */
40         MATCH_EXTERN,
41         MATCH_INTERN,
42         MATCH_PORT,
43         MATCH_INTERFACE,
44         MATCH_CALLERID,
45         MATCH_CALLERID2,
46         MATCH_EXTENSION,
47         MATCH_DIALING,
48         MATCH_ENBLOCK,
49         MATCH_OVERLAP,
50         MATCH_ANONYMOUS,
51         MATCH_VISIBLE,
52         MATCH_UNKNOWN,
53         MATCH_AVAILABLE,
54         MATCH_FAKE,
55         MATCH_REAL,
56         MATCH_REDIRECTED,
57         MATCH_DIRECT,
58         MATCH_REDIRID,
59         MATCH_TIME,
60         MATCH_MDAY,
61         MATCH_MONTH,
62         MATCH_YEAR,
63         MATCH_WDAY,
64         MATCH_CAPABILITY,
65         MATCH_INFOLAYER1,
66         MATCH_HLC,
67         MATCH_FILE,
68         MATCH_EXECUTE,
69         MATCH_DEFAULT,
70         MATCH_TIMEOUT,
71         MATCH_FREE,
72         MATCH_NOTFREE,
73         MATCH_DOWN,
74         MATCH_UP,
75         MATCH_BUSY,
76         MATCH_IDLE,
77         MATCH_REMOTE,
78         MATCH_NOTREMOTE,
79 };
80
81 enum { /* how to parse text file during startup */
82         PARAM_TYPE_NULL,
83         PARAM_TYPE_INTEGER,
84         PARAM_TYPE_STRING,
85         PARAM_TYPE_YESNO,
86         PARAM_TYPE_CAPABILITY,
87         PARAM_TYPE_BMODE,
88         PARAM_TYPE_HLC,
89         PARAM_TYPE_DIVERSION,
90         PARAM_TYPE_DESTIN,
91         PARAM_TYPE_PORTS,
92         PARAM_TYPE_TYPE,
93         PARAM_TYPE_CALLERIDTYPE,
94         PARAM_TYPE_ON,
95 };
96
97 enum { /* defines when a statement should be executed */
98         INFO_ON_INIT,
99         INFO_ON_HANGUP,
100 };
101
102 /* parameter ID bits */
103 #define PARAM_PROCEEDING        1LL
104 #define PARAM_ALERTING          (1LL<<1)
105 #define PARAM_CONNECT           (1LL<<2)
106 #define PARAM_EXTENSION         (1LL<<3)
107 #define PARAM_EXTENSIONS        (1LL<<4)
108 #define PARAM_PREFIX            (1LL<<5)
109 #define PARAM_CAPA              (1LL<<6)
110 #define PARAM_BMODE             (1LL<<7)
111 #define PARAM_INFO1             (1LL<<8)
112 #define PARAM_HLC               (1LL<<9)
113 #define PARAM_EXTHLC            (1LL<<10)
114 #define PARAM_PRESENT           (1LL<<11)
115 #define PARAM_DIVERSION         (1LL<<12)
116 #define PARAM_DEST              (1LL<<13)
117 #define PARAM_SELECT            (1LL<<14)
118 #define PARAM_DELAY             (1LL<<15)
119 #define PARAM_LIMIT             (1LL<<16)
120 #define PARAM_HOST              (1LL<<17)
121 #define PARAM_PORT              (1LL<<18)
122 #define PARAM_INTERFACES        (1LL<<19)
123 #define PARAM_ADDRESS           (1LL<<20)
124 #define PARAM_SAMPLE            (1LL<<21)
125 #define PARAM_ANNOUNCEMENT      (1LL<<22)
126 #define PARAM_RULESET           (1LL<<23)
127 #define PARAM_CAUSE             (1LL<<24)
128 #define PARAM_LOCATION          (1LL<<25)
129 #define PARAM_DISPLAY           (1LL<<26)
130 #define PARAM_PORTS             (1LL<<27)
131 #define PARAM_TPRESET           (1LL<<28)
132 #define PARAM_FILE              (1LL<<29)
133 #define PARAM_CONTENT           (1LL<<30)
134 #define PARAM_APPEND            (1LL<<31)
135 #define PARAM_EXECUTE           (1LL<<32)
136 #define PARAM_PARAM             (1LL<<33)
137 #define PARAM_TYPE              (1LL<<34)
138 #define PARAM_COMPLETE          (1LL<<35)
139 #define PARAM_CALLERID          (1LL<<36)
140 #define PARAM_CALLERIDTYPE      (1LL<<37)
141 #define PARAM_CALLTO            (1LL<<38)
142 #define PARAM_ROOM              (1LL<<39)
143 #define PARAM_JINGLE            (1LL<<40)
144 #define PARAM_TIMEOUT           (1LL<<41)
145 #define PARAM_NOPASSWORD        (1LL<<42)
146 #define PARAM_STRIP             (1LL<<43)
147 #define PARAM_APPLICATION       (1LL<<44)
148 #define PARAM_CONTEXT           (1LL<<45)
149 #define PARAM_EXTEN             (1LL<<46)
150 #define PARAM_ON                (1LL<<47)
151 #define PARAM_KEYPAD            (1LL<<48)
152
153 /* action index
154  * NOTE: The given index is the actual entry number of action_defs[], so add/remove both lists!!!
155  */
156 #define ACTION_EXTERNAL         0
157 #define ACTION_INTERNAL         1
158 #define ACTION_OUTDIAL          2
159 #define ACTION_REMOTE           3
160 #define ACTION_VBOX_RECORD      4
161 #define ACTION_PARTYLINE        5
162 #define ACTION_LOGIN            6
163 #define ACTION_CALLERID         7
164 #define ACTION_CALLERIDNEXT     8
165 #define ACTION_FORWARD          9
166 #define ACTION_REDIAL           10
167 #define ACTION_REPLY            11
168 #define ACTION_POWERDIAL        12      
169 #define ACTION_CALLBACK         13
170 #define ACTION_ABBREV           14
171 #define ACTION_TEST             15
172 #define ACTION_PLAY             16
173 #define ACTION_VBOX_PLAY        17
174 #define ACTION_CALCULATOR       18
175 #define ACTION_TIMER            19
176 #define ACTION_GOTO             20
177 #define ACTION_MENU             21
178 #define ACTION_DISCONNECT       22
179 #define ACTION_RELEASE          23
180 #define ACTION_DEFLECT          24
181 #define ACTION_SETFORWARD       25
182 #define ACTION_EXECUTE          26
183 #define ACTION_FILE             27
184 #define ACTION_PICK             28
185 #define ACTION_PASSWORD         29
186 #define ACTION_PASSWORD_WRITE   30
187 #define ACTION_NOTHING          31
188 #define ACTION_EFI              32
189
190 struct route_cond { /* an item */
191         struct route_cond       *next;                  /* next entry */
192         int                     index;                  /* index of cond_defs */
193         int                     match;                  /* what is matching (MATCH_*) */
194         int                     value_type;             /* type of value (VALUE_TYPE_*) */
195         int                     value_extension;        /* will it be extended? */
196         int                     integer_value;          /* first integer */
197         int                     integer_value_to;       /* second integer */
198         char                    *string_value;          /* first string */
199         char                    *string_value_to;       /* second string */
200         int                     comp_string;            /* compare value of strings */
201 };
202
203 struct route_param { /* a parameter */
204         struct route_param      *next;                  /* next item */
205         int                     index;                  /* index of param_defs */
206         unsigned long long      id;                     /* what is it (PARAM_*) */
207         int                     value_type;             /* type of value (VALUE_TYPE_*) */
208         int                     value_extension;        /* will it be extended? */
209         int                     integer_value;          /* integer value */
210         char                    *string_value;          /* string value */
211 };
212
213 struct route_action { /* an action has a list of parameters */
214         struct route_action     *next;                  /* next item */
215         struct route_param      *param_first;           /* link to parameter list */
216         int                     index;                  /* index of action_defs */
217         int                     timeout;                /* timeout value for action (0 = no timeout) */
218         int                     line;                   /* line parsed from */
219 };
220
221 struct route_rule { /* a rule has a list of items and actions */
222         struct route_rule       *next;                  /* next item */
223         char                    file[128];              /* filename */
224         int                     line;                   /* line parsed from */
225         struct route_cond       *cond_first;            /* link to condition list */
226         struct route_action     *action_first;          /* link to action list */
227 //      int                     temp_couldmatch;        /* stores, if the dialing could match. this is used to make a list of rules, that could match */
228 };
229
230 struct route_ruleset { /* the ruleset is a list of rules */
231         struct route_ruleset    *next;                  /* next item */
232         char                    file[128];              /* filename */
233         int                     line;                   /* line parsed from */
234         char                    name[64];               /* name of ruleset */
235         struct route_rule       *rule_first;            /* linke to rule list */
236 };
237
238 struct cond_defs { /* defintion of all conditions */
239         const char              *name;                  /* item's name */
240         int                     match;                  /* what to check */
241         int                     type;                   /* type of value (COND_TYPE) */
242         const char              *doc;                   /* syntax */
243         const char              *help;                  /* short help */
244 };
245
246 struct param_defs { /* definition of all options */
247         unsigned long long      id;                     /* ID of parameter (just for checking) */
248         const char              *name;                  /* name of parameter */
249         int                     type;                   /* type of value (PARAM_TYPE_*) */
250         const char              *doc;                   /* syntax */
251         const char              *help;                  /* quick help */
252 };
253
254 struct action_defs { /* definition of all actions */
255         int                     id;                     /* ID of parameter (just for checking) */
256         const char              *name;
257         void                    (EndpointAppPBX::*init_func)(void);
258         void                    (EndpointAppPBX::*dialing_func)(void);
259         void                    (EndpointAppPBX::*hangup_func)(void);
260         unsigned long long       params;
261         const char              *help;
262 };
263
264
265
266 extern struct cond_defs         cond_defs[];
267 extern struct param_defs        param_defs[];
268 extern struct action_defs       action_defs[];
269 extern struct route_ruleset     *ruleset_first;
270 extern struct route_ruleset     *ruleset_main;
271 extern struct route_action      action_external;
272 extern struct route_action      action_internal;
273 extern struct route_action      action_remote;
274 extern struct route_action      action_vbox;
275 extern struct route_action      action_partyline;
276 extern struct route_action      action_password;
277 extern struct route_action      action_password_write;
278 extern struct route_action      action_disconnect;
279
280 /* functions */
281
282 void doc_rules(const char *action);
283 void ruleset_free(struct route_ruleset *ruleset_start);
284 void ruleset_debug(struct route_ruleset *ruleset_start);
285 extern char ruleset_error[256];
286 struct route_ruleset *ruleset_parse(void);
287 struct route_ruleset *getrulesetbyname(const char *name);
288