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