1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** match processing of routing configuration **
10 \*****************************************************************************/
15 struct route_ruleset *ruleset_first; /* first entry */
16 struct route_ruleset *ruleset_main; /* pointer to main ruleset */
18 struct cond_defs cond_defs[] = {
19 { "extern", MATCH_EXTERN, COND_TYPE_NULL,
20 "extern", "Matches if call is from external port (no extension)."},
21 { "intern", MATCH_INTERN,COND_TYPE_NULL,
22 "intern", "Matches if call is from an extension."},
23 { "port", MATCH_PORT, COND_TYPE_INTEGER,
24 "port=<number>[-<number>][,...]", "Matches if call is received from given port(s). NOT INTERFACE!"},
25 { "interface", MATCH_INTERFACE,COND_TYPE_STRING,
26 "interface=<interface>[,...]", "Matches if call is received from given interface(s). NOT PORTS!"},
27 { "callerid", MATCH_CALLERID, COND_TYPE_STRING,
28 "callerid=<digits>[-<digits>][,...]", "Matches if caller ID matches or begins with the given (range(s) of) prefixes(s)."},
29 { "extension", MATCH_EXTENSION,COND_TYPE_STRING,
30 "extension=<digits>[-<digits>][,...]", "Matches if caller calls from given (range(s) of) extension(s)."},
31 { "dialing", MATCH_DIALING, COND_TYPE_STRING,
32 "dialing=<digits>[-<digits>][,...]", "Matches if caller has dialed the given (range(s) of) digits at least."},
33 { "enblock", MATCH_ENBLOCK, COND_TYPE_NULL,
34 "enblock", "Matches if caller dialed en block. (Dial the number before pick up.)"},
35 { "overlap", MATCH_OVERLAP, COND_TYPE_NULL,
36 "overlap", "Matches if caller dialed digit by digit. (Dial the number after pick up.)"},
37 { "anonymous", MATCH_ANONYMOUS,COND_TYPE_NULL,
38 "anonymous", "Matches if caller uses restricted caller ID or if not available."},
39 { "visible", MATCH_VISIBLE, COND_TYPE_NULL,
40 "visible", "Matches if caller ID is presented and if available."},
41 { "unknown", MATCH_UNKNOWN, COND_TYPE_NULL,
42 "unknown", "Matches if no ID is available from caller."},
43 { "available", MATCH_AVAILABLE,COND_TYPE_NULL,
44 "available", "Matches if ID is available from caller."},
45 { "fake", MATCH_FAKE, COND_TYPE_NULL,
46 "fake", "Matches if caller ID is not screened and may be faked by caller."},
47 { "real", MATCH_REAL, COND_TYPE_NULL,
48 "real", "Matches if caller ID is screend and so it is the real caller's ID."},
49 { "redirected", MATCH_REDIRECTED,COND_TYPE_NULL,
50 "redirected", "Matches if caller has been redirected."},
51 { "direct", MATCH_DIRECT ,COND_TYPE_NULL,
52 "direct", "Matches if caller did not come from an redirection."},
53 { "redirid", MATCH_REDIRID ,COND_TYPE_STRING,
54 "redirid=<digits>[-<digits>][,...]", "Matches if the caller has been redirected by the given (range(s) of) ID(s) or prefix(es))"},
55 { "time", MATCH_TIME, COND_TYPE_TIME,
56 "time=<minutes>[-<minutes>][,...]", "Matches if the caller calls within the given (range(s) of) time(s). (e.g. 0700-1900)"},
57 { "mday", MATCH_MDAY, COND_TYPE_MDAY,
58 "mday=<day>[-<day>][,...]", "Matches if the caller calls within the given (range(s) of) day(s) of the month. (1..31)"},
59 { "month", MATCH_MONTH, COND_TYPE_MONTH,
60 "month=<month>[-<month>][,...]", "Matches if the caller calls within the given (range(s) of) month(s). (1=January..12=December)"},
61 { "year", MATCH_YEAR, COND_TYPE_YEAR,
62 "year=<year>[-<year>][,...]", "Matches if the caller calls within the given (range(s) of) year(s). (1970..2106)"},
63 { "wday", MATCH_WDAY, COND_TYPE_WDAY,
64 "wday=<day>[-<day>][,...]", "Matches if the caller calls within the given (range(s) of) weekday(s). (1=Monday..7=Sunday)"},
65 { "capability", MATCH_CAPABILITY, COND_TYPE_CAPABILITY,
66 "capability=speech|audio|video|digital-restricted|digital-unrestricted|digital-unrestricted-tones[,...]", "Matches the given bearer capability(s)."},
67 { "infolayer1", MATCH_INFOLAYER1, COND_TYPE_INTEGER,
68 "infolayer1=<value>[,...]", "Matches the given information layer 1. (2=u-Law, 3=a-law, see info layer 1 in bearer capability.)"},
69 { "hlc", MATCH_HLC, COND_TYPE_INTEGER,
70 "hlc=<value>[,...]", "Matches the high layer capability(s)."},
71 { "file", MATCH_FILE, COND_TYPE_STRING,
72 "file=<path>[,...]", "Mathes is the given file exists and if the first character is '1'."},
73 { "execute", MATCH_EXECUTE, COND_TYPE_STRING,
74 "execute=<command>[,...]","Matches if the return value of the given command is greater 0."},
75 { "default", MATCH_DEFAULT, COND_TYPE_NULL,
76 "default","Matches if no further dialing could match."},
77 { "timeout", MATCH_TIMEOUT, COND_TYPE_INTEGER,
78 "timeout=<seconds>","Matches if the ruleset was entered AFTER given seconds."},
79 { "free", MATCH_FREE, COND_TYPE_IFATTR,
80 "free=<interface>:<channel>","Matches if the given minimum of channels are free."},
81 { "notfree", MATCH_NOTFREE, COND_TYPE_IFATTR,
82 "notfree=<interface>:<channel>","Matches if NOT the given minimum of channels are free."},
83 { "blocked", MATCH_DOWN, COND_TYPE_STRING,
84 "blocked=<interfaces>[,...]","Matches if all of the given interfaces are blocked."},
85 { "idle", MATCH_UP, COND_TYPE_STRING,
86 "idle=<interface>[,...]","Matches if any of the given interfaces is idle."},
87 { "busy", MATCH_BUSY, COND_TYPE_STRING,
88 "busy=<extension>[,...]","Matches if any of the given extension is busy."},
89 { "notbusy", MATCH_IDLE, COND_TYPE_STRING,
90 "notbusy=<extension>[,...]","Matches if any of the given extension is not busy."},
91 { "remote", MATCH_REMOTE, COND_TYPE_STRING,
92 "remote=<application name>","Matches if remote application is running."},
93 { "notremote", MATCH_NOTREMOTE,COND_TYPE_NULL,
94 "notremote=<application name>","Matches if remote application is not running."},
98 struct param_defs param_defs[] = {
100 "proceeding", PARAM_TYPE_NULL,
101 "proceeding", "Will set the call into 'proceeding' state to prevent dial timeout."},
103 "alerting", PARAM_TYPE_NULL,
104 "alerting", "Will set the call into 'altering' state."},
106 "connect", PARAM_TYPE_NULL,
107 "connect", "Will complete the call before processing the action. Audio path for external calls will be established."},
109 "extension", PARAM_TYPE_STRING,
110 "extension=<digits>", "Give extension name (digits) to relate this action to."},
112 "extensions", PARAM_TYPE_STRING,
113 "extensions=<extension>[,<extension>[,...]]", "One or more extensions may be given."},
115 "prefix", PARAM_TYPE_STRING,
116 "prefix=<digits>", "Add prefix in front of the dialed number."},
118 "capability", PARAM_TYPE_CAPABILITY,
119 "capability=speech|audio|video|digital-restricted|digital-unrestricted|digital-unrestricted-tones", "Alter the service type of the call."},
121 "bmode", PARAM_TYPE_BMODE,
122 "bmode=transparent|hdlc", "Alter the bchannel mode of the call. Use hdlc for data calls."},
124 "infolayer1", PARAM_TYPE_INTEGER,
125 "infolayer1=<value>", "Alter the layer 1 information of a call. Use 3 for ALAW or 2 for uLAW."},
127 "hlc", PARAM_TYPE_INTEGER,
128 "hlc=<value>", "Alter the HLC identification. Use 1 for telephony or omit."},
130 "exthlc", PARAM_TYPE_INTEGER,
131 "exthlc=<value>", "Alter extended HLC value. (Mainenance only, don't use it.)"},
133 "present", PARAM_TYPE_YESNO,
134 "present=yes|no", "Allow or restrict caller ID regardless what the caller wants."},
136 "diversion", PARAM_TYPE_DIVERSION,
137 "diversion=cfu|cfnr|cfb|cfp", "Set diversion type."},
139 "dest", PARAM_TYPE_DESTIN,
140 "dest=<string>", "Destination number to divert to. Use 'vbox' to divert to vbox. (cfu,cfnr,cfb only)"},
142 "select", PARAM_TYPE_NULL,
143 "select", "Lets the caller select the history of calls using keys '1'/'3' or '*'/'#'."},
145 "delay", PARAM_TYPE_INTEGER,
146 "delay=<seconds>", "Number of seconds to delay."},
148 "limit", PARAM_TYPE_INTEGER,
149 "limit=<retries>", "Number of maximum retries."},
151 "host", PARAM_TYPE_STRING,
152 "host=<string>", "Name of remote VoIP host."},
154 "port", PARAM_TYPE_STRING,
155 "port=<value>", "Alternate port to use if 'host' is given."},
157 "interfaces", PARAM_TYPE_STRING,
158 "interfaces=<interface>[,<interface>[,...]]", "Give one or a list of Interfaces to select a free channel from."},
160 "address", PARAM_TYPE_STRING,
161 "address=<string>", "Complete VoIP address. ( [user@]host[:port] )"},
163 "sample", PARAM_TYPE_STRING,
164 "sample=<file prefix>", "Filename of sample (current tone's dir) or full path to sample. ('.wav'/'.wave'/'.isdn' is added automatically."},
165 { PARAM_ANNOUNCEMENT,
166 "announcement",PARAM_TYPE_STRING,
167 "announcement=<file prefix>", "Filename of announcement (inside vbox recording dir) or full path to sample. ('.wav'/'.wave'/'.isdn' is added automatically."},
169 "ruleset", PARAM_TYPE_STRING,
170 "ruleset=<name>", "Ruleset to go to."},
172 "cause", PARAM_TYPE_INTEGER,
173 "cause=<cause value>", "Cause value when disconnecting. (21=reject 1=unassigned 63=service not available)"},
175 "location", PARAM_TYPE_INTEGER,
176 "location=<location value>", "Location of cause value when disconnecting. (0=user 1=private network sering local user)"},
178 "display", PARAM_TYPE_STRING,
179 "display=<text>", "Message to display on the caller's telephone. (internal only)"},
181 "ports", PARAM_TYPE_INTEGER,
182 "ports=<port>[,<port>[,...]]", "ISDN port[s] to use."},
184 "tpreset", PARAM_TYPE_INTEGER,
185 "tpreset=<seconds>", "Preset of countdown timer."},
187 "file", PARAM_TYPE_STRING,
188 "file=<full path>", "Full path to file name."},
190 "content", PARAM_TYPE_STRING,
191 "content=<string>", "Content to write into file."},
193 "append", PARAM_TYPE_NULL,
194 "append", "Will append to given file, rather than overwriting it."},
196 "execute", PARAM_TYPE_STRING,
197 "execute=<full path>", "Full path to script/command name. (Dialed digits are the argument 1.)"},
199 "param", PARAM_TYPE_STRING,
200 "param=<string>", "Optionally this parameter can be inserted as argument 1, others are shifted."},
202 "type", PARAM_TYPE_TYPE,
203 "type=unknown|subscriber|national|international", "Type of number to dial, default is 'unknown'."},
205 "complete", PARAM_TYPE_NULL,
206 "complete", "Indicates complete number as given by prefix. Proceeding of long distance calls may be faster."},
208 "callerid", PARAM_TYPE_STRING,
209 "callerid=<digits>", "Change caller ID to given string."},
210 { PARAM_CALLERIDTYPE,
211 "calleridtype",PARAM_TYPE_CALLERIDTYPE,
212 "calleridtype=[unknown|subscriber|national|international]", "Type of caller ID. For normal MSN use 'unknown'"},
214 "callto", PARAM_TYPE_STRING,
215 "callto=<digits>", "Where to call back. By default the caller ID is used."},
217 "room", PARAM_TYPE_INTEGER,
218 "room=<digits>", "Conference room number, must be greater 0, as in real life."},
220 "jingle", PARAM_TYPE_NULL,
221 "jingle", "Conference members will hear a jingle if a member joins."},
223 "timeout", PARAM_TYPE_INTEGER,
224 "timeout=<seconds>", "Timeout before continue with next action."},
226 "nopassword", PARAM_TYPE_NULL,
227 "nopassword", "Don't ask for password. Be sure to authenticate right via real caller ID."},
229 "strip", PARAM_TYPE_NULL,
230 "strip", "Remove digits that were required to match this rule."},
232 "application",PARAM_TYPE_STRING,
233 "application=<name>", "Name of remote application to make call to."},
234 { 0, NULL, 0, NULL, NULL}
237 struct action_defs action_defs[] = {
239 "extern", &EndpointAppPBX::action_init_call, &EndpointAppPBX::action_dialing_external, &EndpointAppPBX::action_hangup_call,
240 PARAM_CONNECT | PARAM_PREFIX | PARAM_COMPLETE | PARAM_TYPE | PARAM_CAPA | PARAM_BMODE | PARAM_INFO1 | PARAM_HLC | PARAM_EXTHLC | PARAM_PRESENT | PARAM_INTERFACES | PARAM_CALLERID | PARAM_CALLERIDTYPE | PARAM_TIMEOUT,
241 "Call is routed to extern number as dialed."},
243 "intern", &EndpointAppPBX::action_init_call, &EndpointAppPBX::action_dialing_internal, &EndpointAppPBX::action_hangup_call,
244 PARAM_CONNECT | PARAM_EXTENSION | PARAM_TYPE | PARAM_CAPA | PARAM_BMODE | PARAM_INFO1 | PARAM_HLC | PARAM_EXTHLC | PARAM_PRESENT | PARAM_TIMEOUT,
245 "Call is routed to intern extension as given by the dialed number or specified by option."},
247 "outdial", &EndpointAppPBX::action_init_call, &EndpointAppPBX::action_dialing_external, &EndpointAppPBX::action_hangup_call,
248 PARAM_CONNECT | PARAM_PREFIX | PARAM_COMPLETE | PARAM_TYPE | PARAM_CAPA | PARAM_BMODE | PARAM_INFO1 | PARAM_HLC | PARAM_EXTHLC | PARAM_PRESENT | PARAM_INTERFACES | PARAM_CALLERID | PARAM_CALLERIDTYPE | PARAM_TIMEOUT,
251 "remote", &EndpointAppPBX::action_init_remote, &EndpointAppPBX::action_dialing_remote, &EndpointAppPBX::action_hangup_call,
252 PARAM_CONNECT | PARAM_APPLICATION | PARAM_TIMEOUT,
253 "Call is routed to Remote application, like Asterisk."},
254 { ACTION_VBOX_RECORD,
255 "vbox-record",&EndpointAppPBX::action_init_call, &EndpointAppPBX::action_dialing_vbox_record, &EndpointAppPBX::action_hangup_call,
256 PARAM_CONNECT | PARAM_EXTENSION | PARAM_ANNOUNCEMENT | PARAM_TIMEOUT,
257 "Caller is routed to the voice box of given extension."},
259 "partyline",&EndpointAppPBX::action_init_partyline, NULL, &EndpointAppPBX::action_hangup_call,
260 PARAM_ROOM | PARAM_JINGLE,
261 "Caller is participating the conference with the given room number."},
263 "login", NULL, &EndpointAppPBX::action_dialing_login, NULL,
264 PARAM_CONNECT | PARAM_EXTENSION | PARAM_NOPASSWORD,
265 "Log into the given extension. Password required."},
267 "callerid", &EndpointAppPBX::action_init_change_callerid, &EndpointAppPBX::action_dialing_callerid, NULL,
268 PARAM_CONNECT | PARAM_CALLERID | PARAM_CALLERIDTYPE | PARAM_PRESENT,
269 "Caller changes the caller ID for all calls."},
270 { ACTION_CALLERIDNEXT,
271 "calleridnext",&EndpointAppPBX::action_init_change_callerid, &EndpointAppPBX::action_dialing_calleridnext, NULL,
272 PARAM_CONNECT | PARAM_CALLERID | PARAM_CALLERIDTYPE | PARAM_PRESENT,
273 "Caller changes the caller ID for the next call."},
275 "forward", &EndpointAppPBX::action_init_change_forward, &EndpointAppPBX::action_dialing_forward, NULL,
276 PARAM_CONNECT | PARAM_DIVERSION | PARAM_DEST | PARAM_DELAY,
277 "Caller changes the diversion of given type to the given destination or voice box."},
279 "redial", &EndpointAppPBX::action_init_redial_reply, &EndpointAppPBX::action_dialing_redial, NULL,
280 PARAM_CONNECT | PARAM_SELECT,
281 "Caller redials. (last outgoing call(s))"},
283 "reply", &EndpointAppPBX::action_init_redial_reply, &EndpointAppPBX::action_dialing_reply, NULL,
284 PARAM_CONNECT | PARAM_SELECT,
285 "Caller replies. (last incoming call(s))"},
287 "powerdial", NULL, &EndpointAppPBX::action_dialing_powerdial, NULL,
288 PARAM_CONNECT | PARAM_DELAY | PARAM_LIMIT | PARAM_TIMEOUT,
289 "Caller redials using powerdialing."},
291 "callback", NULL, &EndpointAppPBX::action_dialing_callback, &EndpointAppPBX::action_hangup_callback,
292 PARAM_PROCEEDING | PARAM_ALERTING | PARAM_CONNECT | PARAM_EXTENSION | PARAM_DELAY | PARAM_CALLTO | PARAM_PREFIX,
293 "Caller will use the callback service. After disconnecting, the callback is triggered."},
295 "abbrev", NULL, &EndpointAppPBX::action_dialing_abbrev, NULL,
297 "Caller dials abbreviation."},
299 "test", NULL, &EndpointAppPBX::action_dialing_test, NULL,
300 PARAM_CONNECT | PARAM_PREFIX | PARAM_TIMEOUT,
301 "Caller dials test mode."},
303 "play", &EndpointAppPBX::action_init_play, NULL, NULL,
304 PARAM_PROCEEDING | PARAM_ALERTING | PARAM_CONNECT | PARAM_SAMPLE | PARAM_TIMEOUT,
305 "Plays the given sample."},
307 "vbox-play", &EndpointAppPBX::action_init_vbox_play, &EndpointAppPBX::action_dialing_vbox_play, NULL,
309 "Caller listens to her voice box or to given extension."},
311 "calculator", NULL, &EndpointAppPBX::action_dialing_calculator, NULL,
313 "Caller calls the calculator."},
315 "timer", NULL, &EndpointAppPBX::action_dialing_timer, NULL,
316 PARAM_CONNECT | PARAM_TPRESET | PARAM_TIMEOUT,
318 // "Caller calls the timer."},
320 "goto", NULL, &EndpointAppPBX::action_dialing_goto, NULL,
321 PARAM_CONNECT | PARAM_RULESET | PARAM_STRIP | PARAM_SAMPLE,
322 "Jump to given ruleset and optionally play sample. Dialed digits are not flushed."},
324 "menu", NULL, &EndpointAppPBX::action_dialing_menu, NULL,
325 PARAM_CONNECT | PARAM_RULESET | PARAM_SAMPLE,
326 "Same as 'goto', but flushes all digits dialed so far."},
328 "disconnect", NULL, &EndpointAppPBX::action_dialing_disconnect, NULL,
329 PARAM_CONNECT | PARAM_CAUSE | PARAM_LOCATION | PARAM_SAMPLE | PARAM_DISPLAY,
330 "Caller gets disconnected optionally with given cause and given sample and given display text."},
332 "deflect", NULL, &EndpointAppPBX::action_dialing_deflect, NULL,
335 // "External call is deflected to the given destination within the telephone network."},
337 "setforward", NULL, &EndpointAppPBX::action_dialing_setforward, NULL,
338 PARAM_CONNECT | PARAM_DIVERSION | PARAM_DEST | PARAM_PORT,
340 // "The call forward is set within the telephone network of the external line."},
342 "execute", NULL, NULL, &EndpointAppPBX::action_hangup_execute,
343 PARAM_CONNECT | PARAM_EXECUTE | PARAM_PARAM,
344 "Executes the given script file. The file must terminate quickly, because it will halt the PBX."},
346 "file", NULL, NULL, &EndpointAppPBX::action_hangup_file,
347 PARAM_CONNECT | PARAM_FILE | PARAM_CONTENT | PARAM_APPEND,
348 "Writes givent content to given file. If content is not given, the dialed digits are written."},
350 "pick", &EndpointAppPBX::action_init_pick, NULL, NULL,
352 "Pick up a call that is ringing on any phone. Extensions may be given to limit the picking ability."},
354 "password", NULL, &EndpointAppPBX::action_dialing_password, NULL,
357 { ACTION_PASSWORD_WRITE,
358 "password_wr",NULL, &EndpointAppPBX::action_dialing_password_wr, NULL,
362 "nothing", NULL, NULL, NULL,
363 PARAM_PROCEEDING | PARAM_ALERTING | PARAM_CONNECT | PARAM_TIMEOUT,
364 "does nothing. Usefull to wait for calls to be released completely, by giving timeout value."},
366 "efi", &EndpointAppPBX::action_init_efi, NULL, NULL,
367 PARAM_PROCEEDING | PARAM_ALERTING | PARAM_CONNECT,
368 "Elektronische Fernsprecher Identifikation - announces caller ID."},
370 NULL, NULL, NULL, NULL, 0, NULL}
374 /* display documentation of rules */
376 void doc_rules(const char *name)
383 while(action_defs[i].name)
385 if (!strcasecmp(action_defs[i].name, name))
389 if (!action_defs[i].name)
391 fprintf(stderr, "Given action '%s' unknown.\n", name);
394 name = action_defs[i].name;
397 printf("Syntax overview:\n");
398 printf("----------------\n\n");
399 printf("[ruleset]\n");
400 printf("<condition> ... : <action> [parameter ...] [timeout=X : <action> ...]\n");
402 printf("Please refer to the documentation for description on rule format.\n\n");
406 printf("Available conditions to match:\n");
407 printf("------------------------------\n\n");
409 while(cond_defs[i].name)
411 printf("Usage: %s\n", cond_defs[i].doc);
412 printf("%s\n\n", cond_defs[i].help);
416 printf("Available actions with their parameters:\n");
417 printf("----------------------------------------\n\n");
420 printf("Detailes parameter description of action:\n");
421 printf("-----------------------------------------\n\n");
424 while(action_defs[i].name)
426 if (name && !!strcmp(action_defs[i].name,name)) /* not selected */
431 if (!action_defs[i].help) /* not internal actions */
436 printf("Usage: %s", action_defs[i].name);
440 if ((1LL<<j) & action_defs[i].params)
441 printf(" [%s]", param_defs[j].doc);
444 printf("\n%s\n\n", action_defs[i].help);
445 if (name) /* only show parameter help for specific action */
450 if ((1LL<<j) & action_defs[i].params)
451 printf("%s:\n\t%s\n", param_defs[j].doc, param_defs[j].help);
460 void ruleset_free(struct route_ruleset *ruleset_start)
462 struct route_ruleset *ruleset;
463 struct route_rule *rule;
464 struct route_cond *cond;
465 struct route_action *action;
466 struct route_param *param;
470 ruleset = ruleset_start;
471 ruleset_start = ruleset->next;
472 while(ruleset->rule_first)
474 rule = ruleset->rule_first;
475 ruleset->rule_first = rule->next;
476 while(rule->cond_first)
478 cond = rule->cond_first;
479 if (cond->string_value)
481 FREE(cond->string_value, 0);
484 if (cond->string_value_to)
486 FREE(cond->string_value_to, 0);
489 rule->cond_first = cond->next;
490 FREE(cond, sizeof(struct route_cond));
493 while(rule->action_first)
495 action = rule->action_first;
496 rule->action_first = action->next;
497 while(action->param_first)
499 param = action->param_first;
500 action->param_first = param->next;
501 if (param->string_value)
503 FREE(param->string_value, 0);
506 FREE(param, sizeof(struct route_param));
509 FREE(action, sizeof(struct route_action));
512 FREE(rule, sizeof(struct route_rule));
515 FREE(ruleset, sizeof(struct route_ruleset));
520 void ruleset_debug(struct route_ruleset *ruleset_start)
522 struct route_ruleset *ruleset;
523 struct route_rule *rule;
524 struct route_cond *cond;
525 struct route_action *action;
526 struct route_param *param;
529 ruleset = ruleset_start;
532 printf("Ruleset: '%s'\n", ruleset->name);
533 rule = ruleset->rule_first;
538 cond = rule->cond_first;
542 printf(" Condition:");
546 printf(" %s", cond_defs[cond->index].name);
547 if (cond->value_type != VALUE_TYPE_NULL)
550 switch(cond->value_type)
552 case VALUE_TYPE_NULL:
555 case VALUE_TYPE_INTEGER:
556 printf("%d", cond->integer_value);
559 case VALUE_TYPE_INTEGER_RANGE:
560 printf("%d-%d", cond->integer_value, cond->integer_value_to);
563 case VALUE_TYPE_STRING:
564 printf("'%s'", cond->string_value);
567 case VALUE_TYPE_STRING_RANGE:
568 printf("'%s'-'%s'", cond->string_value, cond->string_value_to);
572 printf("Software error: VALUE_TYPE_* %d not known in function '%s' line=%d", cond->value_type, __FUNCTION__, __LINE__);
574 if (cond->value_extension && cond->next)
578 goto next_cond_value;
586 action = rule->action_first;
589 printf(" Action: %s\n", action_defs[action->index].name);
592 param = action->param_first;
600 printf(" %s", param_defs[param->index].name);
601 if (param->value_type != VALUE_TYPE_NULL)
603 switch(param->value_type)
605 case VALUE_TYPE_NULL:
608 case VALUE_TYPE_INTEGER:
609 if (param_defs[param->index].type == PARAM_TYPE_CALLERIDTYPE)
611 switch(param->integer_value)
613 case INFO_NTYPE_UNKNOWN:
616 case INFO_NTYPE_SUBSCRIBER:
617 printf("subscriber");
619 case INFO_NTYPE_NATIONAL:
622 case INFO_NTYPE_INTERNATIONAL:
623 printf("international");
626 printf("unknown(%d)", param->integer_value);
630 if (param_defs[param->index].type == PARAM_TYPE_CAPABILITY)
632 switch(param->integer_value)
643 case INFO_BC_DATARESTRICTED:
644 printf("digital-restricted");
646 case INFO_BC_DATAUNRESTRICTED:
647 printf("digital-unrestricted");
649 case INFO_BC_DATAUNRESTRICTED_TONES:
650 printf("digital-unrestricted-tones");
653 printf("unknown(%d)", param->integer_value);
657 if (param_defs[param->index].type == PARAM_TYPE_DIVERSION)
659 switch(param->integer_value)
661 case INFO_DIVERSION_CFU:
664 case INFO_DIVERSION_CFNR:
667 case INFO_DIVERSION_CFB:
670 case INFO_DIVERSION_CFP:
674 printf("unknown(%d)", param->integer_value);
678 if (param_defs[param->index].type == PARAM_TYPE_TYPE)
680 switch(param->integer_value)
682 case INFO_NTYPE_UNKNOWN:
685 case INFO_NTYPE_SUBSCRIBER:
686 printf("subscriber");
688 case INFO_NTYPE_NATIONAL:
691 case INFO_NTYPE_INTERNATIONAL:
692 printf("international");
695 printf("unknown(%d)", param->integer_value);
699 if (param_defs[param->index].type == PARAM_TYPE_YESNO)
701 switch(param->integer_value)
710 printf("unknown(%d)", param->integer_value);
714 if (param_defs[param->index].type == PARAM_TYPE_NULL)
718 printf("%d", param->integer_value);
721 case VALUE_TYPE_STRING:
722 printf("'%s'", param->string_value);
726 printf("Software error: VALUE_TYPE_* %d not known in function '%s' line=%d", param->value_type, __FUNCTION__, __LINE__);
733 printf(" Timeout: %d\n", action->timeout);
734 action = action->next;
740 ruleset = ruleset->next;
748 static char *read_string(char *p, char *key, int key_size, char *special)
774 UPRINT(key, "\001String too long.");
779 UPRINT(key, "\001Unexpected end of line inside quotes.");
786 if (strchr(special, *p))
796 UPRINT(key, "\001Unexpected end of line.");
802 UPRINT(key, "\001String too long.");
810 char ruleset_error[256];
811 struct route_ruleset *ruleset_parse(void)
816 unsigned long long j;
820 FILE *fp[MAXNESTING];
821 char filename[MAXNESTING][256];
822 int line[MAXNESTING];
829 int expecting = 1; /* 1 = expecting ruleset */
833 integer_to; /* condition index, .. */
834 struct route_ruleset *ruleset_start = NULL, *ruleset;
835 struct route_ruleset **ruleset_pointer = &ruleset_start;
836 struct route_rule *rule;
837 struct route_rule **rule_pointer = NULL;
838 struct route_cond *cond;
839 struct route_cond **cond_pointer = NULL;
840 struct route_action *action;
841 struct route_action **action_pointer = NULL;
842 struct route_param *param;
843 struct route_param **param_pointer = NULL;
845 unsigned long long allowed_params;
847 /* check the integrity of IDs for ACTION_* and PARAM_* */
849 while(action_defs[i].name)
851 if (action_defs[i].id != i)
853 PERROR("Software Error action '%s' must have id of %d, but has %d.\n",
854 action_defs[i].name, i, action_defs[i].id);
860 while(param_defs[i].name)
862 if (param_defs[i].id != j)
864 PERROR("Software Error param '%s' must have id of 0x%llx, but has 0x%llx.\n",
865 param_defs[i].name, j, param_defs[i].id);
872 SPRINT(filename[0], "%s/routing.conf", INSTALL_DATA);
874 if (!(fp[0]=fopen(filename[0],"r")))
876 PERROR("Cannot open %s\n",filename[0]);
885 while((fgets(buffer,sizeof(buffer),fp[nesting])))
888 buffer[sizeof(buffer)-1]=0;
889 if (buffer[0]) buffer[strlen(buffer)-1]=0;
900 /* skip spaces, if any */
912 /* don't skip "define" */
913 if (!!strncmp(p, "define", 6))
926 p = read_string(p, key, sizeof(key), " ");
927 if (key[0] == 1) /* error */
929 SPRINT(failure, "Parsing Filename failed: %s", key+1);
932 if (nesting == MAXNESTING-1)
934 SPRINT(failure, "'include' is nesting too deep.\n");
938 SCPY(filename[nesting+1], key);
940 SPRINT(filename[nesting+1], "%s/%s", INSTALL_DATA, key);
941 if (!(fp[nesting+1]=fopen(filename[nesting+1],"r")))
943 PERROR("Cannot open %s\n", filename[nesting+1]);
950 if (*p == '/') if (p[1] == '/')
953 /* skip empty lines */
957 /* expecting ruleset */
964 SPRINT(failure, "Expecting ruleset name starting with '['.");
969 /* reading ruleset name text */
971 while(*p>' ' && *p<127 && *p!=']')
973 if (*p>='A' && *p<='Z') *p = *p-'A'+'a'; /* lower case */
975 if (i == sizeof(key)) i--; /* limit */
978 if (key[0] == '\0') {
979 SPRINT(failure, "Missing ruleset name after '['.");
983 /* expecting ] and nothing more */
985 SPRINT(failure, "Expecting ']' after ruleset name.");
990 SPRINT(failure, "Unexpected character after ruleset name.");
994 /* check for duplicate rulesets */
995 ruleset = ruleset_start;
998 if (!strcmp(ruleset->name, key))
1000 SPRINT(failure, "Duplicate ruleset '%s', already defined in file '%s' line %d.", key, ruleset->file, ruleset->line);
1003 ruleset = ruleset->next;
1006 /* create ruleset */
1007 ruleset = (struct route_ruleset *)MALLOC(sizeof(struct route_ruleset));
1009 *ruleset_pointer = ruleset;
1010 ruleset_pointer = &(ruleset->next);
1011 SCPY(ruleset->name, key);
1012 SCPY(ruleset->file, filename[nesting]);
1013 ruleset->line = line[nesting];
1014 rule_pointer = &(ruleset->rule_first);
1019 /* for new ruleset [ */
1025 /* Alloc memory for rule */
1026 rule = (struct route_rule *)MALLOC(sizeof(struct route_rule));
1028 *rule_pointer = rule;
1029 rule_pointer = &(rule->next);
1030 cond_pointer = &(rule->cond_first);
1031 action_pointer = &(rule->action_first);
1032 SCPY(rule->file, filename[nesting]);
1033 rule->line = line[nesting];
1035 /* loop CONDITIONS */
1036 while(*p!=':' && *p!='\0')
1038 /* read item text */
1040 while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9'))
1042 if (*p>='A' && *p<='Z') *p = *p-'A'+'a'; /* lower case */
1044 if (i == sizeof(key)) i--; /* limit */
1049 SPRINT(failure, "Expecting condition item name or ':' for end of condition list.");
1052 if (*p!=' ' && *p!='=')
1054 SPRINT(failure, "Illegal character '%c' after condition name '%s'. Expecting '=' for equation or ' ' to seperate condition items.", *p, key);
1058 /* check if condition exists */
1060 while(cond_defs[index].name)
1062 if (!strcmp(cond_defs[index].name, key))
1066 if (cond_defs[index].name == NULL)
1068 SPRINT(failure, "Unknown condition item name '%s'.", key);
1072 /* items without values must not have any parameter */
1073 if (cond_defs[index].type == COND_TYPE_NULL)
1077 SPRINT(failure, "Condition item '%s' must not have any value. Don't use '=' for this type of condition.", key);
1082 SPRINT(failure, "Condition item '%s' must not have any value. Expecting ' ' or tab after item name.", key);
1090 SPRINT(failure, "Condition item '%s' must have at least one value, '=' expected, and not a space.", key);
1095 SPRINT(failure, "Condition item '%s' must have at least one value, '=' expected.", key);
1101 /* check for duplicate condition */
1102 cond = rule->cond_first;
1105 if (cond->index == index)
1107 SPRINT(failure, "Duplicate condition '%s', use ',' to give multiple values.", key);
1114 /* Alloc memory for item */
1115 cond = (struct route_cond *)MALLOC(sizeof(struct route_cond));
1117 *cond_pointer = cond;
1118 cond_pointer = &(cond->next);
1119 cond->index = index;
1120 cond->match = cond_defs[index].match;
1121 switch(cond_defs[index].type)
1123 case COND_TYPE_NULL:
1126 SPRINT(failure, "Expecting no value.");
1129 value_type = VALUE_TYPE_NULL;
1132 /* parse all integer values/ranges */
1133 case COND_TYPE_INTEGER:
1134 case COND_TYPE_TIME:
1135 case COND_TYPE_MDAY:
1136 case COND_TYPE_MONTH:
1137 case COND_TYPE_WDAY:
1138 case COND_TYPE_YEAR:
1139 integer = integer_to = 0;
1140 if (*p==',' || *p==' ' || *p=='\0')
1142 SPRINT(failure, "Missing integer value.");
1145 while(*p>='0' && *p<='9')
1147 integer = integer*10 + *p-'0';
1150 value_type = VALUE_TYPE_INTEGER;
1154 if (*p==',' || *p==' ' || *p=='\0')
1156 SPRINT(failure, "Missing integer value.");
1159 while(*p>='0' && *p<='9')
1161 integer_to = integer_to*10 + *p-'0';
1164 value_type = VALUE_TYPE_INTEGER_RANGE;
1166 if (cond_defs[index].type == COND_TYPE_TIME)
1168 // Simon: i store the time as decimal, later i compare it correctly:
1169 // hours * 100 + minutes
1170 if (integer == 2400)
1172 if (integer >= 2400)
1175 SPRINT(failure, "Given time '%d' not in range 0000..2359 (or 2400 for 0000)", integer);
1178 if (integer%100 >= 60)
1179 goto timeoutofrange1;
1180 if (value_type == VALUE_TYPE_INTEGER)
1182 if (integer_to == 2400)
1184 if (integer_to >= 2400)
1187 SPRINT(failure, "Given time '%d' not in range 0000..2359 (or 2400 for 0000)", integer_to);
1190 if (integer_to%100 >= 60)
1191 goto timeoutofrange2;
1193 if (cond_defs[index].type == COND_TYPE_MDAY)
1195 if (integer<1 || integer>31)
1197 SPRINT(failure, "Given day-of-month '%d' not in range 1..31", integer);
1200 if (value_type == VALUE_TYPE_INTEGER)
1202 if (integer_to<1 || integer_to>31)
1204 SPRINT(failure, "Given day-of-month '%d' not in range 1..31", integer_to);
1208 if (cond_defs[index].type == COND_TYPE_WDAY)
1210 if (integer<1 || integer>7)
1212 SPRINT(failure, "Given day-of-week '%d' not in range 1..7", integer);
1215 if (value_type == VALUE_TYPE_INTEGER)
1217 if (integer_to<1 || integer_to>7)
1219 SPRINT(failure, "Given day-of-week '%d' not in range 1..7", integer_to);
1223 if (cond_defs[index].type == COND_TYPE_MONTH)
1225 if (integer<1 || integer>12)
1227 SPRINT(failure, "Given month '%d' not in range 1..12", integer);
1230 if (value_type == VALUE_TYPE_INTEGER)
1232 if (integer_to<1 || integer_to>12)
1234 SPRINT(failure, "Given month '%d' not in range 1..12", integer_to);
1238 if (cond_defs[index].type == COND_TYPE_YEAR)
1240 if (integer<1970 || integer>2106)
1242 SPRINT(failure, "Given year '%d' not in range 1970..2106", integer);
1245 if (value_type == VALUE_TYPE_INTEGER)
1247 if (integer_to<1970 || integer_to>2106)
1249 SPRINT(failure, "Given year '%d' not in range 1970..2106", integer_to);
1254 cond->integer_value = integer;
1255 cond->integer_value_to = integer_to;
1256 cond->value_type = value_type;
1259 /* parse all string values/ranges */
1260 case COND_TYPE_STRING:
1261 key[0] = key_to[0] = '\0';
1262 if (*p==',' || *p==' ' || *p=='\0')
1264 SPRINT(failure, "Missing string value, use \"\" for empty string.");
1267 p = read_string(p, key, sizeof(key), "-, ");
1268 if (key[0] == 1) /* error */
1270 SPRINT(failure, "Parsing String failed: %s", key+1);
1273 value_type = VALUE_TYPE_STRING;
1277 if (*p==',' || *p==' ' || *p=='\0')
1279 SPRINT(failure, "Missing string value, use \"\" for empty string.");
1282 p = read_string(p, key_to, sizeof(key_to), "-, ");
1283 if (key_to[0] == 1) /* error */
1285 SPRINT(failure, "Parsing string failed: %s", key_to+1);
1288 value_type = VALUE_TYPE_STRING_RANGE;
1289 if (strlen(key) != strlen(key_to))
1291 SPRINT(failure, "Given range of strings \"%s\"-\"%s\" have unequal length.", key, key_to);
1296 SPRINT(failure, "Given range has no length.");
1301 cond->string_value = (char *)MALLOC(strlen(key)+1);
1303 UCPY(cond->string_value, key);
1304 if (value_type == VALUE_TYPE_STRING_RANGE)
1306 cond->string_value_to = (char *)MALLOC(strlen(key_to)+1);
1308 UCPY(cond->string_value_to, key_to);
1309 cond->comp_string = strcmp(key, key_to);
1311 cond->value_type = value_type;
1314 /* parse service value */
1315 case COND_TYPE_CAPABILITY:
1316 if (!strncasecmp("speech", p, 6))
1317 cond->integer_value = INFO_BC_SPEECH;
1318 else if (!strncasecmp("audio", p, 5))
1319 cond->integer_value = INFO_BC_AUDIO;
1320 else if (!strncasecmp("video", p, 5))
1321 cond->integer_value = INFO_BC_VIDEO;
1322 else if (!strncasecmp("digital-restricted", p, 18))
1323 cond->integer_value = INFO_BC_DATARESTRICTED;
1324 else if (!strncasecmp("digital-unrestricted", p, 20))
1325 cond->integer_value = INFO_BC_DATAUNRESTRICTED;
1326 else if (!strncasecmp("digital-unrestricted-tones", p, 26))
1327 cond->integer_value = INFO_BC_DATAUNRESTRICTED_TONES;
1330 SPRINT(failure, "Given service type is invalid or misspelled.");
1333 cond->value_type = VALUE_TYPE_INTEGER;
1336 /* parse bmode value */
1337 case COND_TYPE_BMODE:
1338 if (!strncasecmp("transparent", p, 11))
1339 cond->integer_value = INFO_BMODE_CIRCUIT;
1340 else if (!strncasecmp("hdlc", p, 4))
1341 cond->integer_value = INFO_BMODE_PACKET;
1344 SPRINT(failure, "Given bchannel mode is invalid or misspelled.");
1347 cond->value_type = VALUE_TYPE_INTEGER;
1350 /* parse interface attribute <if>:<value> */
1351 case COND_TYPE_IFATTR:
1352 key[0] = key_to[0] = '\0';
1353 if (*p==':' || *p==',' || *p==' ' || *p=='\0')
1355 SPRINT(failure, "Missing interface name.");
1358 p = read_string(p, key, sizeof(key), ":-, ");
1359 if (key[0] == 1) /* error */
1361 SPRINT(failure, "Parsing interface failed: %s", key+1);
1366 SPRINT(failure, "Expeciting kolon to seperate value behind interface name.");
1370 while(*p>='0' && *p<='9')
1374 if (*p!=',' && *p!=' ' && *p!='\0')
1376 SPRINT(failure, "Invalid characters behind value.");
1379 value_type = VALUE_TYPE_STRING;
1384 SPRINT(failure, "Software error: COND_TYPE_* %d not parsed in function '%s'", cond_defs[index].type, __FUNCTION__);
1387 /* if we have another value for that item, we attach it */
1392 cond->value_extension = 1;
1395 /* to seperate the items, a space is required */
1398 SPRINT(failure, "Character '%c' not expected here. Use ',' to seperate multiple possible values.", *p);
1410 /* we are done with CONDITIONS, so we expect the ACTION */
1413 SPRINT(failure, "Expecting ':' after condition item(s).");
1419 /* skip spaces, if any */
1427 /* read action name */
1429 while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9') || *p == '-')
1431 if (*p>='A' && *p<='Z') *p = *p-'A'+'a'; /* lower case */
1433 if (i == sizeof(key)) i--; /* limit */
1436 if (key[0] == '\0') {
1437 SPRINT(failure, "Expecting action name.");
1441 /* check if item exists */
1443 while(action_defs[index].name)
1445 if (!action_defs[index].help) /* not internal actions */
1450 if (!strcmp(action_defs[index].name, key))
1454 if (action_defs[index].name == NULL)
1456 SPRINT(failure, "Unknown action name '%s'.", key);
1459 allowed_params = action_defs[index].params;
1461 /* alloc memory for action */
1462 action = (struct route_action *)MALLOC(sizeof(struct route_action));
1464 *action_pointer = action;
1465 action_pointer = &(action->next);
1466 param_pointer = &(action->param_first);
1467 action->index = index;
1468 action->line = line[nesting];
1470 /* skip spaces after param name */
1481 /* read param text */
1483 while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9'))
1485 if (*p>='A' && *p<='Z') *p = *p-'A'+'a'; /* lower case */
1487 if (i == sizeof(key)) i--; /* limit */
1490 if (key[0] == '\0') {
1491 SPRINT(failure, "Expecting parameter name.");
1495 /* check if item exists */
1497 while(param_defs[index].name)
1499 if (!strcmp(param_defs[index].name, key))
1503 if (param_defs[index].name == NULL)
1505 SPRINT(failure, "Unknown param name '%s'.", key);
1509 /* check if item is allowed for the action */
1510 if (!(param_defs[index].id & allowed_params))
1512 SPRINT(failure, "Param name '%s' exists, but not for this action.", key);
1516 /* params without values must not have any parameter */
1517 if (param_defs[index].type == PARAM_TYPE_NULL)
1519 if (*p!=' ' && *p!='\0')
1521 SPRINT(failure, "Parameter '%s' must not have any value.", key);
1528 SPRINT(failure, "Parameter '%s' must have at least one value, '=' expected and not a space.", key);
1533 SPRINT(failure, "Parameter '%s' must have at least one value, '=' expected.", key);
1539 /* special timeout value */
1540 if (!strcmp("timeout", key))
1542 if (action->timeout)
1544 SPRINT(failure, "Duplicate timeout value.");
1547 if (*p==',' || *p==' ' || *p=='\0')
1549 SPRINT(failure, "Missing integer value.");
1553 while(*p>='0' && *p<='9')
1555 integer = integer*10 + *p-'0';
1560 SPRINT(failure, "Expecting timeout value greater 0.");
1563 if (*p!=' ' && *p!='\0')
1565 SPRINT(failure, "Character '%c' not expected here. Use ' ' to seperate parameters.", *p);
1575 action->timeout = integer;
1576 /* check for next ACTION */
1585 /* check for duplicate parameters */
1586 param = action->param_first;
1589 if (param->index == index)
1591 SPRINT(failure, "Duplicate parameter '%s', use ',' to give multiple values.", key);
1594 param = param->next;
1598 /* Alloc memory for param */
1599 param = (struct route_param *)MALLOC(sizeof(struct route_param));
1601 *param_pointer = param;
1602 param_pointer = &(param->next);
1603 param->index = index;
1604 param->id = param_defs[index].id;
1606 switch(param_defs[index].type)
1608 /* parse null value */
1609 case PARAM_TYPE_NULL:
1610 param->value_type = VALUE_TYPE_NULL;
1613 /* parse integer value */
1614 case PARAM_TYPE_INTEGER:
1616 if (*p==',' || *p==' ' || *p=='\0')
1618 SPRINT(failure, "Missing integer value.");
1621 while(*p>='0' && *p<='9')
1623 integer = integer*10 + *p-'0';
1626 param->integer_value = integer;
1627 param->value_type = VALUE_TYPE_INTEGER;
1631 /* parse ports value */
1632 case PARAM_TYPE_PORTS:
1634 if (*p==',' || *p==' ' || *p=='\0')
1636 SPRINT(failure, "Missing port number, omit parameter or give port number.");
1642 while(*p>='0' && *p<='9')
1644 if (i < (int)sizeof(key)-1)
1649 integer = integer*10 + *p-'0';
1654 SPRINT(failure, "Port number too high.");
1659 if (i < (int)sizeof(key)-1)
1670 /* parse string value */
1671 case PARAM_TYPE_STRING:
1672 case PARAM_TYPE_CALLERIDTYPE:
1673 case PARAM_TYPE_CAPABILITY:
1674 case PARAM_TYPE_BMODE:
1675 case PARAM_TYPE_DIVERSION:
1676 case PARAM_TYPE_DESTIN:
1677 case PARAM_TYPE_TYPE:
1678 case PARAM_TYPE_YESNO:
1680 if (*p==',' || *p==' ' || *p=='\0')
1682 SPRINT(failure, "Missing string value, use \"\" for empty string.");
1685 p = read_string(p, key, sizeof(key), " ");
1686 if (key[0] == 1) /* error */
1688 SPRINT(failure, "Parsing string failed: %s", key+1);
1691 if (param_defs[index].type == PARAM_TYPE_CALLERIDTYPE)
1693 param->value_type = VALUE_TYPE_INTEGER;
1694 if (!strcasecmp(key, "unknown"))
1696 param->integer_value = INFO_NTYPE_UNKNOWN;
1699 if (!strcasecmp(key, "subscriber"))
1701 param->integer_value = INFO_NTYPE_SUBSCRIBER;
1704 if (!strcasecmp(key, "national"))
1706 param->integer_value = INFO_NTYPE_NATIONAL;
1709 if (!strcasecmp(key, "international"))
1711 param->integer_value = INFO_NTYPE_INTERNATIONAL;
1714 SPRINT(failure, "Caller ID type '%s' unknown.", key);
1717 if (param_defs[index].type == PARAM_TYPE_CAPABILITY)
1719 param->value_type = VALUE_TYPE_INTEGER;
1720 if (!strcasecmp(key, "speech"))
1722 param->integer_value = INFO_BC_SPEECH;
1725 if (!strcasecmp(key, "audio"))
1727 param->integer_value = INFO_BC_AUDIO;
1730 if (!strcasecmp(key, "video"))
1732 param->integer_value = INFO_BC_VIDEO;
1735 if (!strcasecmp(key, "digital-restricted"))
1737 param->integer_value = INFO_BC_DATARESTRICTED;
1740 if (!strcasecmp(key, "digital-unrestricted"))
1742 param->integer_value = INFO_BC_DATAUNRESTRICTED;
1745 if (!strcasecmp(key, "digital-unrestricted-tones"))
1747 param->integer_value = INFO_BC_DATAUNRESTRICTED_TONES;
1750 SPRINT(failure, "Service type '%s' unknown.", key);
1753 if (param_defs[index].type == PARAM_TYPE_BMODE)
1755 param->value_type = VALUE_TYPE_INTEGER;
1756 if (!strcasecmp(key, "transparent"))
1758 param->integer_value = INFO_BMODE_CIRCUIT;
1761 if (!strcasecmp(key, "hdlc"))
1763 param->integer_value = INFO_BMODE_PACKET;
1766 SPRINT(failure, "Bchannel mode '%s' unknown.", key);
1769 if (param_defs[index].type == PARAM_TYPE_DIVERSION)
1771 param->value_type = VALUE_TYPE_INTEGER;
1772 if (!strcasecmp(key, "cfu"))
1774 param->integer_value = INFO_DIVERSION_CFU;
1777 if (!strcasecmp(key, "cfb"))
1779 param->integer_value = INFO_DIVERSION_CFB;
1782 if (!strcasecmp(key, "cfnr"))
1784 param->integer_value = INFO_DIVERSION_CFNR;
1787 if (!strcasecmp(key, "cfp"))
1789 param->integer_value = INFO_DIVERSION_CFP;
1792 SPRINT(failure, "Diversion type '%s' unknown.", key);
1795 if (param_defs[index].type == PARAM_TYPE_TYPE)
1797 param->value_type = VALUE_TYPE_INTEGER;
1798 if (!strcasecmp(key, "unknown"))
1800 param->integer_value = INFO_NTYPE_UNKNOWN;
1803 if (!strcasecmp(key, "subscriber"))
1805 param->integer_value = INFO_NTYPE_SUBSCRIBER;
1808 if (!strcasecmp(key, "national"))
1810 param->integer_value = INFO_NTYPE_NATIONAL;
1813 if (!strcasecmp(key, "international"))
1815 param->integer_value = INFO_NTYPE_INTERNATIONAL;
1818 SPRINT(failure, "Number type '%s' unknown.", key);
1821 if (param_defs[index].type == PARAM_TYPE_YESNO)
1823 param->value_type = VALUE_TYPE_INTEGER;
1824 if (!strcasecmp(key, "yes"))
1826 param->integer_value = 1;
1829 if (!strcasecmp(key, "no"))
1831 param->integer_value = 0;
1834 SPRINT(failure, "Value '%s' unknown. ('yes' or 'no')", key);
1837 param->string_value = (char *)MALLOC(strlen(key)+1);
1839 UCPY(param->string_value, key);
1840 param->value_type = VALUE_TYPE_STRING;
1844 SPRINT(failure, "Software error: PARAM_TYPE_* %d not parsed in function '%s'", param_defs[index].type, __FUNCTION__);
1852 param->value_extension = 1;
1853 goto nextparamvalue;
1860 /* to seperate the items, a space is required */
1863 SPRINT(failure, "Character '%c' not expected here. Use ' ' to seperate parameters, or ',' for multiple values.", *p);
1874 /* check for next ACTION */
1883 fclose(fp[nesting--]);
1891 SPRINT(failure, "No ruleset defined.");
1893 return(ruleset_start);
1896 printf("While parsing %s, an error occurred in line %d:\n", filename[nesting], line[nesting]);
1897 printf("-> %s\n", buffer);
1898 memset(pointer, ' ', sizeof(pointer));
1899 pointer[p-buffer] = '^';
1900 pointer[p-buffer+1] = '\0';
1901 printf(" %s\n", pointer);
1902 printf("%s\n", failure);
1903 SPRINT(ruleset_error, "Error in file %s, line %d: %s", filename[nesting], line[nesting], failure);
1908 fclose(fp[nesting--]);
1912 ruleset_free(ruleset_start);
1917 * return ruleset by name
1919 struct route_ruleset *getrulesetbyname(char *name)
1921 struct route_ruleset *ruleset = ruleset_first;
1925 if (!strcasecmp(name, ruleset->name))
1929 ruleset = ruleset->next;
1931 PDEBUG(DEBUG_ROUTE, "ruleset %s %s.\n", name, ruleset?"found":"not found");
1936 * parses the current ruleset and returns action
1938 struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
1941 couldmatch = 0, /* any rule could match */
1948 struct route_rule *rule = ruleset->rule_first;
1949 struct route_cond *cond;
1950 struct route_action *action = NULL;
1951 unsigned long comp_len;
1953 char callerid[64], redirid[64];
1958 struct mISDNport *mISDNport;
1959 struct admin_list *admin;
1961 /* reset timeout action */
1962 e_match_timeout = 0; /* no timeout */
1963 e_match_to_action = NULL;
1965 SCPY(callerid, numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype));
1966 SCPY(redirid, numberrize_callerinfo(e_redirinfo.id, e_redirinfo.ntype));
1968 PDEBUG(DEBUG_ROUTE, "parsing ruleset '%s'\n", ruleset->name);
1971 PDEBUG(DEBUG_ROUTE, "checking rule in line %d\n", rule->line);
1972 match = 1; /* this rule matches */
1973 dialing_required = 0;
1974 timeout = 0; /* timeout time */
1975 cond = rule->cond_first;
1978 condition = 0; /* any condition element is true (1) or could be true (2) */
1980 istrue = 0; /* this condition-element is true */
1981 couldbetrue = 0; /* this conditions-element could be true */
1985 if (!e_ext.number[0])
1990 if (e_ext.number[0])
1995 if (ea_endpoint->ep_portlist)
1996 if ((ea_endpoint->ep_portlist->port_type & PORT_CLASS_mISDN_MASK) != PORT_CLASS_mISDN_DSS1)
1998 integer = e_callerinfo.isdn_port;
2001 case MATCH_INTERFACE:
2002 if (!e_callerinfo.interface[0])
2004 string = e_callerinfo.interface;
2005 goto match_string_prefix;
2007 case MATCH_CALLERID:
2009 goto match_string_prefix;
2011 case MATCH_EXTENSION:
2012 string = e_ext.name;
2016 string = e_dialinginfo.id;
2017 goto match_string_prefix;
2029 case MATCH_ANONYMOUS:
2030 if (e_callerinfo.present != INFO_PRESENT_ALLOWED)
2035 if (e_callerinfo.present == INFO_PRESENT_ALLOWED)
2040 if (e_callerinfo.present == INFO_PRESENT_NOTAVAIL)
2044 case MATCH_AVAILABLE:
2045 if (e_callerinfo.present != INFO_PRESENT_NOTAVAIL)
2050 if (e_callerinfo.screen == INFO_SCREEN_USER)
2055 if (e_callerinfo.screen != INFO_SCREEN_USER)
2059 case MATCH_REDIRECTED:
2060 if (e_redirinfo.present != INFO_PRESENT_NULL)
2065 if (e_redirinfo.present == INFO_PRESENT_NULL)
2071 goto match_string_prefix;
2074 integer = now_tm->tm_hour*100 + now_tm->tm_min;
2078 integer = now_tm->tm_mday;
2082 integer = now_tm->tm_mon+1;
2086 integer = now_tm->tm_year + 1900;
2090 integer = now_tm->tm_wday;
2091 integer = integer?integer:7; /* correct sunday */
2094 case MATCH_CAPABILITY:
2095 integer = e_capainfo.bearer_capa;
2098 case MATCH_INFOLAYER1:
2099 integer = e_capainfo.bearer_info1;
2103 integer = e_capainfo.hlc;
2107 tfp = fopen(cond->string_value, "r");
2112 if (fgetc(tfp) == '1')
2118 if (system(cond->string_value) == 0)
2128 timeout = now_d + cond->integer_value;
2134 if (!(comp_len = (unsigned long)strchr(cond->string_value, ':')))
2136 comp_len = comp_len-(unsigned long)cond->string_value;
2138 mISDNport = mISDNport_first;
2141 if (mISDNport->ifport)
2142 if (strlen(mISDNport->ifport->interface->name) == comp_len)
2143 if (!strncasecmp(mISDNport->ifport->interface->name, cond->string_value, comp_len))
2144 if (!mISDNport->ptp || mISDNport->l2link)
2147 jj = mISDNport->b_num;
2151 if (mISDNport->b_state[j])
2156 mISDNport = mISDNport->next;
2158 if (cond->match == MATCH_FREE)
2160 if (avail >= atoi(cond->string_value + comp_len + 1))
2164 if (avail < atoi(cond->string_value + comp_len + 1))
2171 mISDNport = mISDNport_first;
2174 if (mISDNport->ifport)
2175 if (!strcasecmp(mISDNport->ifport->interface->name, cond->string_value))
2176 if (!mISDNport->ptp || mISDNport->l2link) /* break if one is up */
2178 mISDNport = mISDNport->next;
2180 if (!mISDNport) /* all down */
2185 mISDNport = mISDNport_first;
2188 if (mISDNport->ifport)
2189 if (!strcasecmp(mISDNport->ifport->interface->name, cond->string_value))
2190 if (!mISDNport->ptp || mISDNport->l2link) /* break if one is up */
2193 mISDNport = mISDNport->next;
2195 if (mISDNport) /* one link at least */
2202 mISDNport = mISDNport_first;
2205 if (mISDNport->ifport)
2206 if (!strcasecmp(mISDNport->ifport->interface->name, cond->string_value))
2207 if (mISDNport->use) /* break if in use */
2209 mISDNport = mISDNport->next;
2211 if (mISDNport && cond->match==MATCH_BUSY)
2213 if (!mISDNport && cond->match==MATCH_IDLE)
2218 case MATCH_NOTREMOTE:
2219 admin = admin_first;
2222 if (admin->remote_name[0] && !strcmp(cond->string_value, admin->remote_name))
2224 admin = admin->next;
2226 if (admin && cond->match==MATCH_REMOTE)
2228 if (!admin && cond->match==MATCH_NOTREMOTE)
2233 PERROR("Software error: MATCH_* %d not parsed in function '%s'", cond->match, __FUNCTION__);
2237 if (cond->value_type == VALUE_TYPE_INTEGER)
2239 if (integer != cond->integer_value)
2244 if (cond->value_type == VALUE_TYPE_INTEGER_RANGE)
2246 /* check if negative range (2100 - 700 o'clock) */
2247 if (cond->integer_value > cond->integer_value_to)
2249 if (integer>=cond->integer_value && integer<=cond->integer_value_to)
2253 /* range is positive */
2254 if (integer>=cond->integer_value && integer<=cond->integer_value_to)
2261 if (strlen(cond->string_value) != strlen(string))
2264 match_string_prefix:
2265 comp_len = strlen(cond->string_value); /* because we must reach value's length */
2266 /* we must have greater or equal length to values */
2267 if ((unsigned long)strlen(string) < comp_len)
2269 /* special case for unfinished dialing */
2270 if (cond->match == MATCH_DIALING)
2272 couldbetrue = 1; /* could match */
2273 comp_len = strlen(string);
2279 /* on single string match */
2280 if (cond->value_type == VALUE_TYPE_STRING)
2282 if (!strncmp(string, cond->string_value, comp_len))
2285 /* must be set for changing 'e_extdialing' */
2286 if (cond->match == MATCH_DIALING)
2287 dialing_required = comp_len;
2292 /* on range match */
2293 if (cond->value_type == VALUE_TYPE_STRING_RANGE)
2295 /* check if negative range ("55"-"22") */
2296 if (cond->comp_string > 0)
2298 if (strncmp(string, cond->string_value, comp_len) >= 0)
2301 /* must be set for changing 'e_extdialing' */
2302 if (cond->match == MATCH_DIALING)
2303 dialing_required = comp_len;
2306 if (strncmp(string, cond->string_value_to, comp_len) <= 0)
2308 /* must be set for changing 'e_extdialing' */
2310 if (cond->match == MATCH_DIALING)
2311 dialing_required = comp_len;
2316 /* range is positive */
2317 if (strncmp(string, cond->string_value, comp_len) < 0)
2319 if (strncmp(string, cond->string_value_to, comp_len) > 0)
2322 if (cond->match == MATCH_DIALING)
2323 dialing_required = comp_len;
2329 /* set current condition */
2330 if (istrue && !couldbetrue)
2331 condition = 1; /* element matches, so condition matches */
2332 if (istrue && couldbetrue && !condition)
2333 condition = 2; /* element could match and other elements don't match, so condition could match */
2335 /* if not matching or could match */
2338 /* if we have more values to check */
2339 if (cond->value_extension && cond->next)
2342 goto checkextension;
2348 /* skip exteded values, beacuse we already have one matching value */
2349 while(cond->value_extension && cond->next)
2354 if (timeout>now_d && match==1) /* the matching rule with timeout in the future */
2355 if (e_match_timeout<1 || timeout<e_match_timeout) /* first timeout or lower */
2357 /* set timeout in the furture */
2358 e_match_timeout = timeout;
2359 e_match_to_action = rule->action_first;
2360 e_match_to_extdialing = e_dialinginfo.id + dialing_required;
2361 match = 0; /* matches in the future */
2365 /* matching, we return first action */
2366 action = rule->action_first;
2367 e_match_timeout = 0; /* no timeout */
2368 e_match_to_action = NULL;
2369 e_extdialing = e_dialinginfo.id + dialing_required;
2374 /* rule could match if more is dialed */
2383 * parses the current action's parameters and return them
2385 struct route_param *EndpointAppPBX::routeparam(struct route_action *action, unsigned long long id)
2387 struct route_param *param = action->param_first;
2391 if (param->id == id)
2393 param = param->next;
2400 * internal rules that are not defined by route.conf
2402 struct route_action action_password = {
2410 struct route_action action_password_write = {
2413 ACTION_PASSWORD_WRITE,
2418 struct route_action action_external = {
2426 struct route_action action_internal = {
2434 struct route_action action_remote = {
2442 struct route_action action_vbox = {
2450 struct route_action action_partyline = {
2458 struct route_action action_disconnect = {