-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathroute.c
2577 lines (2425 loc) · 76.9 KB
/
route.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************\
** **
** PBX4Linux **
** **
**---------------------------------------------------------------------------**
** Copyright: Andreas Eversberg **
** **
** match processing of routing configuration **
** **
\*****************************************************************************/
#include "main.h"
struct route_ruleset *ruleset_first; /* first entry */
struct route_ruleset *ruleset_main; /* pointer to main ruleset */
struct cond_defs cond_defs[] = {
{ "extern", MATCH_EXTERN, COND_TYPE_NULL,
"extern", "Matches if call is from external port (no extension)."},
{ "intern", MATCH_INTERN,COND_TYPE_NULL,
"intern", "Matches if call is from an extension."},
{ "port", MATCH_PORT, COND_TYPE_INTEGER,
"port=<number>[-<number>][,...]", "Matches if call is received from given port(s). NOT INTERFACE!"},
{ "interface", MATCH_INTERFACE,COND_TYPE_STRING,
"interface=<interface>[,...]", "Matches if call is received from given interface(s). NOT PORTS!"},
{ "callerid", MATCH_CALLERID, COND_TYPE_STRING,
"callerid=<digits>[-<digits>][,...]", "Matches if caller ID matches or begins with the given (range(s) of) prefixes(s)."},
{ "callerid2", MATCH_CALLERID2,COND_TYPE_STRING,
"callerid2=<digits>[-<digits>][,...]", "Matches the second caller ID (network provided)."},
{ "extension", MATCH_EXTENSION,COND_TYPE_STRING,
"extension=<digits>[-<digits>][,...]", "Matches if caller calls from given (range(s) of) extension(s)."},
{ "dialing", MATCH_DIALING, COND_TYPE_STRING,
"dialing=<digits>[-<digits>][,...]", "Matches if caller has dialed the given (range(s) of) digits at least."},
{ "enblock", MATCH_ENBLOCK, COND_TYPE_NULL,
"enblock", "Matches if caller dialed en block. (Dial the number before pick up.)"},
{ "overlap", MATCH_OVERLAP, COND_TYPE_NULL,
"overlap", "Matches if caller dialed digit by digit. (Dial the number after pick up.)"},
{ "anonymous", MATCH_ANONYMOUS,COND_TYPE_NULL,
"anonymous", "Matches if caller uses restricted caller ID or if not available."},
{ "visible", MATCH_VISIBLE, COND_TYPE_NULL,
"visible", "Matches if caller ID is presented and if available."},
{ "unknown", MATCH_UNKNOWN, COND_TYPE_NULL,
"unknown", "Matches if no ID is available from caller."},
{ "available", MATCH_AVAILABLE,COND_TYPE_NULL,
"available", "Matches if ID is available from caller."},
{ "fake", MATCH_FAKE, COND_TYPE_NULL,
"fake", "Matches if caller ID is not screened and may be faked by caller."},
{ "real", MATCH_REAL, COND_TYPE_NULL,
"real", "Matches if caller ID is screend and so it is the real caller's ID."},
{ "redirected", MATCH_REDIRECTED,COND_TYPE_NULL,
"redirected", "Matches if caller has been redirected."},
{ "direct", MATCH_DIRECT ,COND_TYPE_NULL,
"direct", "Matches if caller did not come from an redirection."},
{ "redirid", MATCH_REDIRID ,COND_TYPE_STRING,
"redirid=<digits>[-<digits>][,...]", "Matches if the caller has been redirected by the given (range(s) of) ID(s) or prefix(es))"},
{ "time", MATCH_TIME, COND_TYPE_TIME,
"time=<minutes>[-<minutes>][,...]", "Matches if the caller calls within the given (range(s) of) time(s). (e.g. 0700-1900)"},
{ "mday", MATCH_MDAY, COND_TYPE_MDAY,
"mday=<day>[-<day>][,...]", "Matches if the caller calls within the given (range(s) of) day(s) of the month. (1..31)"},
{ "month", MATCH_MONTH, COND_TYPE_MONTH,
"month=<month>[-<month>][,...]", "Matches if the caller calls within the given (range(s) of) month(s). (1=January..12=December)"},
{ "year", MATCH_YEAR, COND_TYPE_YEAR,
"year=<year>[-<year>][,...]", "Matches if the caller calls within the given (range(s) of) year(s). (1970..2106)"},
{ "wday", MATCH_WDAY, COND_TYPE_WDAY,
"wday=<day>[-<day>][,...]", "Matches if the caller calls within the given (range(s) of) weekday(s). (1=Monday..7=Sunday)"},
{ "capability", MATCH_CAPABILITY, COND_TYPE_CAPABILITY,
"capability=speech|audio|video|digital-restricted|digital-unrestricted|digital-unrestricted-tones[,...]", "Matches the given bearer capability(s)."},
{ "infolayer1", MATCH_INFOLAYER1, COND_TYPE_INTEGER,
"infolayer1=<value>[,...]", "Matches the given information layer 1. (2=u-Law, 3=a-law, see info layer 1 in bearer capability.)"},
{ "hlc", MATCH_HLC, COND_TYPE_HLC,
"hlc=telephony|faxg2g3|faxg4|teletex1|teletex2|teletex3|videotex1|videotex2|telex|mhs|osi|maintenance|management|audiovisual[,...]", "Matches the high layer capability(s)."},
{ "file", MATCH_FILE, COND_TYPE_STRING,
"file=<path>[,...]", "Mathes is the given file exists and if the first character is '1'."},
{ "execute", MATCH_EXECUTE, COND_TYPE_STRING,
"execute=<command>[,...]","Matches if the return value of the given command is greater 0."},
{ "default", MATCH_DEFAULT, COND_TYPE_NULL,
"default","Matches if no further dialing could match."},
{ "timeout", MATCH_TIMEOUT, COND_TYPE_INTEGER,
"timeout=<seconds>","Matches if the ruleset was entered AFTER given seconds."},
{ "free", MATCH_FREE, COND_TYPE_IFATTR,
"free=<interface>:<channel>","Matches if the given minimum of channels are free."},
{ "notfree", MATCH_NOTFREE, COND_TYPE_IFATTR,
"notfree=<interface>:<channel>","Matches if NOT the given minimum of channels are free."},
{ "blocked", MATCH_DOWN, COND_TYPE_STRING,
"blocked=<interfaces>[,...]","Matches if all of the given interfaces are blocked."},
{ "idle", MATCH_UP, COND_TYPE_STRING,
"idle=<interface>[,...]","Matches if any of the given interfaces is idle."},
{ "busy", MATCH_BUSY, COND_TYPE_STRING,
"busy=<extension>[,...]","Matches if any of the given extension is busy."},
{ "notbusy", MATCH_IDLE, COND_TYPE_STRING,
"notbusy=<extension>[,...]","Matches if any of the given extension is not busy."},
{ "remote", MATCH_REMOTE, COND_TYPE_STRING,
"remote=<application name>","Matches if remote application is running."},
{ "notremote", MATCH_NOTREMOTE,COND_TYPE_STRING,
"notremote=<application name>","Matches if remote application is not running."},
{ "pots-flash", MATCH_POTS_FLASH,COND_TYPE_NULL,
"pots-flash","When using POTS: Matches if call was invoked by flash/earth button."},
{ "pots-cw", MATCH_POTS_CW, COND_TYPE_NULL,
"pots-cw","When using POTS: Matches if a call is waiting."},
{ "pots-calls", MATCH_POTS_CALLS,COND_TYPE_INTEGER,
"pots-calls=<total number>","When using POTS: Matches if given number of calls are held."},
{ "pots-last", MATCH_POTS_LAST,COND_TYPE_INTEGER,
"pots-last=<call number>","When using POTS: Matches if given call number (1=oldest) was the last active call."},
{ NULL, 0, 0, NULL}
};
struct param_defs param_defs[] = {
{ PARAM_PROCEEDING,
"proceeding", PARAM_TYPE_NULL,
"proceeding", "Will set the call into 'proceeding' state to prevent dial timeout."},
{ PARAM_ALERTING,
"alerting", PARAM_TYPE_NULL,
"alerting", "Will set the call into 'altering' state."},
{ PARAM_CONNECT,
"connect", PARAM_TYPE_NULL,
"connect", "Will complete the call before processing the action. Audio path for external calls will be established."},
{ PARAM_EXTENSION,
"extension", PARAM_TYPE_STRING,
"extension=<digits>", "Give extension name (digits) to relate this action to."},
{ PARAM_EXTENSIONS,
"extensions", PARAM_TYPE_STRING,
"extensions=<extension>[,<extension>[,...]]", "One or more extensions may be given."},
{ PARAM_PREFIX,
"prefix", PARAM_TYPE_STRING,
"prefix=<digits>", "Add prefix in front of the dialed number."},
{ PARAM_CAPA,
"capability", PARAM_TYPE_CAPABILITY,
"capability=speech|audio|video|digital-restricted|digital-unrestricted|digital-unrestricted-tones", "Alter the service type of the call."},
{ PARAM_BMODE,
"bmode", PARAM_TYPE_BMODE,
"bmode=transparent|hdlc", "Alter the bchannel mode of the call. Use hdlc for data calls."},
{ PARAM_INFO1,
"infolayer1", PARAM_TYPE_INTEGER,
"infolayer1=<value>", "Alter the layer 1 information of a call. Use 3 for ALAW or 2 for uLAW."},
{ PARAM_HLC,
"hlc", PARAM_TYPE_HLC,
"hlc=telephony|faxg2g3|faxg4|teletex1|teletex2|teletex3|videotex1|videotex2|telex|mhs|osi|maintenance|management|audiovisual", "Alter the HLC identification."},
{ PARAM_EXTHLC,
"exthlc", PARAM_TYPE_HLC,
"exthlc=<value>", "Alter extended HLC value, see hlc. (Mainenance only, don't use it.)"},
{ PARAM_PRESENT,
"present", PARAM_TYPE_YESNO,
"present=yes|no", "Allow or restrict caller ID regardless what the caller wants."},
{ PARAM_DIVERSION,
"diversion", PARAM_TYPE_DIVERSION,
"diversion=cfu|cfnr|cfb|cfp", "Set diversion type."},
{ PARAM_DEST,
"dest", PARAM_TYPE_DESTIN,
"dest=<string>", "Destination number to divert to. Use 'vbox' to divert to vbox. (cfu,cfnr,cfb only)"},
{ PARAM_SELECT,
"select", PARAM_TYPE_NULL,
"select", "Lets the caller select the history of calls using keys '1'/'3' or '*'/'#'."},
{ PARAM_DELAY,
"delay", PARAM_TYPE_INTEGER,
"delay=<seconds>", "Number of seconds to delay."},
{ PARAM_LIMIT,
"limit", PARAM_TYPE_INTEGER,
"limit=<retries>", "Number of maximum retries."},
{ PARAM_HOST,
"host", PARAM_TYPE_STRING,
"host=<string>", "Name of remote VoIP host."},
{ PARAM_PORT,
"port", PARAM_TYPE_STRING,
"port=<value>", "Alternate port to use if 'host' is given."},
{ PARAM_INTERFACES,
"interfaces", PARAM_TYPE_STRING,
"interfaces=<interface>[,<interface>[,...]]", "Give one or a list of Interfaces to select a free channel from."},
{ PARAM_ADDRESS,
"address", PARAM_TYPE_STRING,
"address=<string>", "Complete VoIP address. ( [user@]host[:port] )"},
{ PARAM_SAMPLE,
"sample", PARAM_TYPE_STRING,
"sample=<file prefix>", "Filename of sample (current tone's dir) or full path to sample. ('.wav'/'.wave'/'.isdn' is added automatically."},
{ PARAM_ANNOUNCEMENT,
"announcement",PARAM_TYPE_STRING,
"announcement=<file prefix>", "Filename of announcement (inside vbox recording dir) or full path to sample. ('.wav'/'.wave'/'.isdn' is added automatically."},
{ PARAM_RULESET,
"ruleset", PARAM_TYPE_STRING,
"ruleset=<name>", "Ruleset to go to."},
{ PARAM_CAUSE,
"cause", PARAM_TYPE_INTEGER,
"cause=<cause value>", "Cause value when disconnecting. (21=reject 1=unassigned 63=service not available)"},
{ PARAM_LOCATION,
"location", PARAM_TYPE_INTEGER,
"location=<location value>", "Location of cause value when disconnecting. (0=user 1=private network sering local user)"},
{ PARAM_DISPLAY,
"display", PARAM_TYPE_STRING,
"display=<text>", "Message to display on the caller's telephone. (internal only)"},
{ PARAM_PORTS,
"ports", PARAM_TYPE_INTEGER,
"ports=<port>[,<port>[,...]]", "ISDN port[s] to use."},
{ PARAM_TPRESET,
"tpreset", PARAM_TYPE_INTEGER,
"tpreset=<seconds>", "Preset of countdown timer."},
{ PARAM_FILE,
"file", PARAM_TYPE_STRING,
"file=<full path>", "Full path to file name."},
{ PARAM_CONTENT,
"content", PARAM_TYPE_STRING,
"content=<string>", "Content to write into file."},
{ PARAM_APPEND,
"append", PARAM_TYPE_NULL,
"append", "Will append to given file, rather than overwriting it."},
{ PARAM_EXECUTE,
"execute", PARAM_TYPE_STRING,
"execute=<full path>", "Full path to script/command name. (Dialed digits are the argument 1.)"},
{ PARAM_PARAM,
"param", PARAM_TYPE_STRING,
"param=<string>", "Optionally this parameter can be inserted as argument 1, others are shifted."},
{ PARAM_TYPE,
"type", PARAM_TYPE_TYPE,
"type=unknown|subscriber|national|international", "Type of number to dial, default is 'unknown'."},
{ PARAM_COMPLETE,
"complete", PARAM_TYPE_NULL,
"complete", "Indicates complete number as given by prefix. Proceeding of long distance calls may be faster."},
{ PARAM_CALLERID,
"callerid", PARAM_TYPE_STRING,
"callerid=<digits>", "Change caller ID to given string."},
{ PARAM_CALLERIDTYPE,
"calleridtype",PARAM_TYPE_CALLERIDTYPE,
"calleridtype=[unknown|subscriber|national|international]", "Type of caller ID. For normal MSN use 'unknown'"},
{ PARAM_CALLTO,
"callto", PARAM_TYPE_STRING,
"callto=<digits>", "Where to call back. By default the caller ID is used."},
{ PARAM_ROOM,
"room", PARAM_TYPE_INTEGER,
"room=<digits>", "Conference room number, must be greater 0, as in real life."},
{ PARAM_JINGLE,
"jingle", PARAM_TYPE_NULL,
"jingle", "Conference members will hear a jingle if a member joins."},
{ PARAM_TIMEOUT,
"timeout", PARAM_TYPE_INTEGER,
"timeout=<seconds>", "Timeout before continue with next action."},
{ PARAM_NOPASSWORD,
"nopassword", PARAM_TYPE_NULL,
"nopassword", "Don't ask for password. Be sure to authenticate right via real caller ID."},
{ PARAM_STRIP,
"strip", PARAM_TYPE_NULL,
"strip", "Remove digits that were required to match this rule."},
{ PARAM_APPLICATION,
"application",PARAM_TYPE_STRING,
"application=<name>", "Name of remote application to make call to."},
{ PARAM_CONTEXT,
"context", PARAM_TYPE_STRING,
"context=<context>", "Give context parameter to the remote application."},
{ PARAM_EXTEN,
"exten", PARAM_TYPE_STRING,
"exten=<extension>", "Give exten parameter to the remote application. (overrides dialed number)"},
{ PARAM_ON,
"on", PARAM_TYPE_STRING,
"on=[init|hangup]", "Defines if the action is executed on call init or on hangup."},
{ PARAM_KEYPAD,
"keypad", PARAM_TYPE_NULL,
"keypad", "Use 'keypad facility' for dialing, instead of 'called number'."},
{ PARAM_POTS_CALL,
"pots-call", PARAM_TYPE_INTEGER,
"pots-call=<call #>", "Select call number. The oldest call is number 1."},
{ 0, NULL, 0, NULL, NULL}
};
struct action_defs action_defs[] = {
{ ACTION_EXTERNAL,
"extern", &EndpointAppPBX::action_init_call, &EndpointAppPBX::action_dialing_external, &EndpointAppPBX::action_hangup_call,
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_KEYPAD | PARAM_CONTEXT | PARAM_TIMEOUT,
"Call is routed to extern number as dialed."},
{ ACTION_INTERNAL,
"intern", &EndpointAppPBX::action_init_call, &EndpointAppPBX::action_dialing_internal, &EndpointAppPBX::action_hangup_call,
PARAM_CONNECT | PARAM_EXTENSION | PARAM_TYPE | PARAM_CAPA | PARAM_BMODE | PARAM_INFO1 | PARAM_HLC | PARAM_EXTHLC | PARAM_PRESENT | PARAM_TIMEOUT,
"Call is routed to intern extension as given by the dialed number or specified by option."},
{ ACTION_OUTDIAL,
"outdial", &EndpointAppPBX::action_init_call, &EndpointAppPBX::action_dialing_external, &EndpointAppPBX::action_hangup_call,
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_KEYPAD | PARAM_TIMEOUT,
"Same as 'extern'"},
{ ACTION_VBOX_RECORD,
"vbox-record",&EndpointAppPBX::action_init_call, &EndpointAppPBX::action_dialing_vbox_record, &EndpointAppPBX::action_hangup_call,
PARAM_CONNECT | PARAM_EXTENSION | PARAM_ANNOUNCEMENT | PARAM_TIMEOUT,
"Caller is routed to the voice box of given extension."},
{ ACTION_PARTYLINE,
"partyline",&EndpointAppPBX::action_init_partyline, NULL, &EndpointAppPBX::action_hangup_call,
PARAM_ROOM | PARAM_JINGLE,
"Caller is participating the conference with the given room number."},
{ ACTION_LOGIN,
"login", NULL, &EndpointAppPBX::action_dialing_login, NULL,
PARAM_CONNECT | PARAM_EXTENSION | PARAM_NOPASSWORD,
"Log into the given extension. Password required."},
{ ACTION_CALLERID,
"callerid", &EndpointAppPBX::action_init_change_callerid, &EndpointAppPBX::action_dialing_callerid, NULL,
PARAM_CONNECT | PARAM_CALLERID | PARAM_CALLERIDTYPE | PARAM_PRESENT,
"Caller changes the caller ID for all calls."},
{ ACTION_CALLERIDNEXT,
"calleridnext",&EndpointAppPBX::action_init_change_callerid, &EndpointAppPBX::action_dialing_calleridnext, NULL,
PARAM_CONNECT | PARAM_CALLERID | PARAM_CALLERIDTYPE | PARAM_PRESENT,
"Caller changes the caller ID for the next call."},
{ ACTION_FORWARD,
"forward", &EndpointAppPBX::action_init_change_forward, &EndpointAppPBX::action_dialing_forward, NULL,
PARAM_CONNECT | PARAM_DIVERSION | PARAM_DEST | PARAM_DELAY,
"Caller changes the diversion of given type to the given destination or voice box."},
{ ACTION_REDIAL,
"redial", &EndpointAppPBX::action_init_redial_reply, &EndpointAppPBX::action_dialing_redial, NULL,
PARAM_CONNECT | PARAM_SELECT,
"Caller redials. (last outgoing call(s))"},
{ ACTION_REPLY,
"reply", &EndpointAppPBX::action_init_redial_reply, &EndpointAppPBX::action_dialing_reply, NULL,
PARAM_CONNECT | PARAM_SELECT,
"Caller replies. (last incoming call(s))"},
{ ACTION_POWERDIAL,
"powerdial", NULL, &EndpointAppPBX::action_dialing_powerdial, NULL,
PARAM_CONNECT | PARAM_DELAY | PARAM_LIMIT | PARAM_TIMEOUT,
"Caller redials using powerdialing."},
{ ACTION_CALLBACK,
"callback", NULL, &EndpointAppPBX::action_dialing_callback, &EndpointAppPBX::action_hangup_callback,
PARAM_PROCEEDING | PARAM_ALERTING | PARAM_CONNECT | PARAM_EXTENSION | PARAM_DELAY | PARAM_CALLTO | PARAM_PREFIX,
"Caller will use the callback service. After disconnecting, the callback is triggered."},
{ ACTION_ABBREV,
"abbrev", NULL, &EndpointAppPBX::action_dialing_abbrev, NULL,
PARAM_CONNECT,
"Caller dials abbreviation."},
{ ACTION_TEST,
"test", NULL, &EndpointAppPBX::action_dialing_test, NULL,
PARAM_CONNECT | PARAM_PREFIX | PARAM_TIMEOUT,
"Caller dials test mode."},
{ ACTION_PLAY,
"play", &EndpointAppPBX::action_init_play, NULL, NULL,
PARAM_PROCEEDING | PARAM_ALERTING | PARAM_CONNECT | PARAM_SAMPLE | PARAM_TIMEOUT,
"Plays the given sample."},
{ ACTION_VBOX_PLAY,
"vbox-play", &EndpointAppPBX::action_init_vbox_play, &EndpointAppPBX::action_dialing_vbox_play, NULL,
PARAM_EXTENSION,
"Caller listens to her voice box or to given extension."},
{ ACTION_CALCULATOR,
"calculator", NULL, &EndpointAppPBX::action_dialing_calculator, NULL,
PARAM_CONNECT,
"Caller calls the calculator."},
{ ACTION_TIMER,
"timer", NULL, &EndpointAppPBX::action_dialing_timer, NULL,
PARAM_CONNECT | PARAM_TPRESET | PARAM_TIMEOUT,
NULL},
// "Caller calls the timer."},
{ ACTION_GOTO,
"goto", NULL, &EndpointAppPBX::action_dialing_goto, NULL,
PARAM_PROCEEDING | PARAM_ALERTING | PARAM_CONNECT | PARAM_RULESET | PARAM_STRIP | PARAM_SAMPLE,
"Jump to given ruleset and optionally play sample. Dialed digits are not flushed."},
{ ACTION_MENU,
"menu", NULL, &EndpointAppPBX::action_dialing_menu, NULL,
PARAM_CONNECT | PARAM_RULESET | PARAM_SAMPLE,
"Same as 'goto', but flushes all digits dialed so far."},
{ ACTION_DISCONNECT,
"disconnect", NULL, &EndpointAppPBX::action_dialing_disconnect, NULL,
PARAM_CONNECT | PARAM_CAUSE | PARAM_LOCATION | PARAM_SAMPLE | PARAM_DISPLAY,
"Caller gets disconnected optionally with given cause and given sample and given display text."},
{ ACTION_RELEASE,
"release", NULL, &EndpointAppPBX::action_dialing_release, NULL,
PARAM_CONNECT | PARAM_CAUSE | PARAM_LOCATION | PARAM_DISPLAY,
"Same as 'disconnect', but using RELEASE message on ISDN."},
{ ACTION_DEFLECT,
"deflect", NULL, &EndpointAppPBX::action_dialing_deflect, NULL,
PARAM_DEST,
NULL},
// "External call is deflected to the given destination within the telephone network."},
{ ACTION_SETFORWARD,
"setforward", NULL, &EndpointAppPBX::action_dialing_setforward, NULL,
PARAM_CONNECT | PARAM_DIVERSION | PARAM_DEST | PARAM_PORT,
NULL},
// "The call forward is set within the telephone network of the external line."},
{ ACTION_EXECUTE,
"execute", &EndpointAppPBX::action_init_execute, NULL, &EndpointAppPBX::action_hangup_execute,
PARAM_CONNECT | PARAM_EXECUTE | PARAM_PARAM | PARAM_ON | PARAM_TIMEOUT,
"Executes the given script file. The file must terminate quickly, because it will halt the PBX."},
{ ACTION_FILE,
"file", NULL, NULL, &EndpointAppPBX::action_hangup_file,
PARAM_CONNECT | PARAM_FILE | PARAM_CONTENT | PARAM_APPEND,
"Writes givent content to given file. If content is not given, the dialed digits are written."},
{ ACTION_PICK,
"pick", &EndpointAppPBX::action_init_pick, NULL, NULL,
PARAM_EXTENSIONS,
"Pick up a call that is ringing on any phone. Extensions may be given to limit the picking ability."},
{ ACTION_PASSWORD,
"password", NULL, &EndpointAppPBX::action_dialing_password, NULL,
0,
NULL},
{ ACTION_PASSWORD_WRITE,
"password_wr",NULL, &EndpointAppPBX::action_dialing_password_wr, NULL,
0,
NULL},
{ ACTION_NOTHING,
"nothing", NULL, NULL, NULL,
PARAM_PROCEEDING | PARAM_ALERTING | PARAM_CONNECT | PARAM_TIMEOUT,
"does nothing. Usefull to wait for calls to be released completely, by giving timeout value."},
{ ACTION_EFI,
"efi", &EndpointAppPBX::action_init_efi, NULL, NULL,
PARAM_PROCEEDING | PARAM_ALERTING | PARAM_CONNECT,
"Elektronische Fernsprecher Identifikation - announces caller ID."},
{ ACTION_POTS_RETRIEVE,
"pots-retrieve", &EndpointAppPBX::action_init_pots_retrieve, NULL, NULL,
PARAM_POTS_CALL,
"When using POTS: Select call on hold to retrieve."},
{ ACTION_POTS_RELEASE,
"pots-release", &EndpointAppPBX::action_init_pots_release, NULL, NULL,
PARAM_POTS_CALL,
"When using POTS: Select call on hold to release."},
{ ACTION_POTS_REJECT,
"pots-reject", &EndpointAppPBX::action_init_pots_reject, NULL, NULL,
0,
"When using POTS: Reject incomming waiting call."},
{ ACTION_POTS_ANSWER,
"pots-answer", &EndpointAppPBX::action_init_pots_answer, NULL, NULL,
0,
"When using POTS: Answer incomming waiting call."},
{ ACTION_POTS_3PTY,
"pots-3pty", &EndpointAppPBX::action_init_pots_3pty, NULL, NULL,
0,
"When using POTS: Invoke 3PTY call of two calls on hold"},
{ ACTION_POTS_TRANSFER,
"pots-transfer", &EndpointAppPBX::action_init_pots_transfer, NULL, NULL,
0,
"When using POTS: Interconnect two calls on hold"},
{ -1,
NULL, NULL, NULL, NULL, 0, NULL}
};
/* display documentation of rules */
void doc_rules(const char *name)
{
int i, j;
if (name) {
i = 0;
while(action_defs[i].name) {
if (!strcasecmp(action_defs[i].name, name))
break;
i++;
}
if (!action_defs[i].name) {
fprintf(stderr, "Given action '%s' unknown.\n", name);
return;
}
name = action_defs[i].name;
}
printf("Syntax overview:\n");
printf("----------------\n\n");
printf("[ruleset]\n");
printf("<condition> ... : <action> [parameter ...] [timeout=X : <action> ...]\n");
printf("...\n");
printf("Please refer to the documentation for description on rule format.\n\n");
if (!name) {
printf("Available conditions to match:\n");
printf("------------------------------\n\n");
i = 0;
while(cond_defs[i].name) {
printf("Usage: %s\n", cond_defs[i].doc);
printf("%s\n\n", cond_defs[i].help);
i++;
}
printf("Available actions with their parameters:\n");
printf("----------------------------------------\n\n");
} else {
printf("Detailes parameter description of action:\n");
printf("-----------------------------------------\n\n");
}
i = 0;
while(action_defs[i].name) {
if (name && !!strcmp(action_defs[i].name,name)) { /* not selected */
i++;
continue;
}
if (!action_defs[i].help) { /* not internal actions */
i++;
continue;
}
printf("Usage: %s", action_defs[i].name);
j = 0;
while(j < 64) {
if ((1LL<<j) & action_defs[i].params)
printf(" [%s]", param_defs[j].doc);
j++;
}
printf("\n%s\n\n", action_defs[i].help);
if (name) { /* only show parameter help for specific action */
j = 0;
while(j < 64) {
if ((1LL<<j) & action_defs[i].params)
printf("%s:\n\t%s\n", param_defs[j].doc, param_defs[j].help);
j++;
}
printf("\n");
}
i++;
}
}
void ruleset_free(struct route_ruleset *ruleset_start)
{
struct route_ruleset *ruleset;
struct route_rule *rule;
struct route_cond *cond;
struct route_action *action;
struct route_param *param;
while(ruleset_start) {
ruleset = ruleset_start;
ruleset_start = ruleset->next;
while(ruleset->rule_first) {
rule = ruleset->rule_first;
ruleset->rule_first = rule->next;
while(rule->cond_first) {
cond = rule->cond_first;
if (cond->string_value) {
FREE(cond->string_value, 0);
rmemuse--;
}
if (cond->string_value_to) {
FREE(cond->string_value_to, 0);
rmemuse--;
}
rule->cond_first = cond->next;
FREE(cond, sizeof(struct route_cond));
rmemuse--;
}
while(rule->action_first) {
action = rule->action_first;
rule->action_first = action->next;
while(action->param_first) {
param = action->param_first;
action->param_first = param->next;
if (param->string_value) {
FREE(param->string_value, 0);
rmemuse--;
}
FREE(param, sizeof(struct route_param));
rmemuse--;
}
FREE(action, sizeof(struct route_action));
rmemuse--;
}
FREE(rule, sizeof(struct route_rule));
rmemuse--;
}
FREE(ruleset, sizeof(struct route_ruleset));
rmemuse--;
}
}
void ruleset_debug(struct route_ruleset *ruleset_start)
{
struct route_ruleset *ruleset;
struct route_rule *rule;
struct route_cond *cond;
struct route_action *action;
struct route_param *param;
int first;
ruleset = ruleset_start;
while(ruleset) {
printf("Ruleset: '%s'\n", ruleset->name);
rule = ruleset->rule_first;
while(rule) {
/* CONDITION */
first = 1;
cond = rule->cond_first;
while(cond) {
if (first)
printf(" Condition:");
else
printf(" and ");
first = 0;
printf(" %s", cond_defs[cond->index].name);
if (cond->value_type != VALUE_TYPE_NULL)
printf(" = ");
next_cond_value:
switch(cond->value_type) {
case VALUE_TYPE_NULL:
break;
case VALUE_TYPE_INTEGER:
printf("%d", cond->integer_value);
break;
case VALUE_TYPE_INTEGER_RANGE:
printf("%d-%d", cond->integer_value, cond->integer_value_to);
break;
case VALUE_TYPE_STRING:
printf("'%s'", cond->string_value);
break;
case VALUE_TYPE_STRING_RANGE:
printf("'%s'-'%s'", cond->string_value, cond->string_value_to);
break;
default:
printf("Software error: VALUE_TYPE_* %d not known in function '%s' line=%d", cond->value_type, __FUNCTION__, __LINE__);
}
if (cond->value_extension && cond->next) {
cond = cond->next;
printf(" or ");
goto next_cond_value;
}
cond = cond->next;
printf("\n");
}
/* ACTION */
action = rule->action_first;
while(action) {
printf(" Action: %s\n", action_defs[action->index].name);
/* PARAM */
first = 1;
param = action->param_first;
while(param) {
if (first)
printf(" Param:");
else
printf(" ");
first = 0;
printf(" %s", param_defs[param->index].name);
if (param->value_type != VALUE_TYPE_NULL)
printf(" = ");
switch(param->value_type) {
case VALUE_TYPE_NULL:
break;
case VALUE_TYPE_INTEGER:
if (param_defs[param->index].type == PARAM_TYPE_CALLERIDTYPE) {
switch(param->integer_value) {
case INFO_NTYPE_UNKNOWN:
printf("unknown");
break;
case INFO_NTYPE_SUBSCRIBER:
printf("subscriber");
break;
case INFO_NTYPE_NATIONAL:
printf("national");
break;
case INFO_NTYPE_INTERNATIONAL:
printf("international");
break;
default:
printf("unknown(%d)", param->integer_value);
}
break;
}
if (param_defs[param->index].type == PARAM_TYPE_CAPABILITY) {
switch(param->integer_value) {
case INFO_BC_SPEECH:
printf("speech");
break;
case INFO_BC_AUDIO:
printf("audio");
break;
case INFO_BC_VIDEO:
printf("video");
break;
case INFO_BC_DATARESTRICTED:
printf("digital-restricted");
break;
case INFO_BC_DATAUNRESTRICTED:
printf("digital-unrestricted");
break;
case INFO_BC_DATAUNRESTRICTED_TONES:
printf("digital-unrestricted-tones");
break;
default:
printf("unknown(%d)", param->integer_value);
}
break;
}
if (param_defs[param->index].type == PARAM_TYPE_DIVERSION) {
switch(param->integer_value) {
case INFO_DIVERSION_CFU:
printf("cfu");
break;
case INFO_DIVERSION_CFNR:
printf("cfnr");
break;
case INFO_DIVERSION_CFB:
printf("cfb");
break;
case INFO_DIVERSION_CFP:
printf("cfp");
break;
default:
printf("unknown(%d)", param->integer_value);
}
break;
}
if (param_defs[param->index].type == PARAM_TYPE_TYPE) {
switch(param->integer_value) {
case INFO_NTYPE_UNKNOWN:
printf("unknown");
break;
case INFO_NTYPE_SUBSCRIBER:
printf("subscriber");
break;
case INFO_NTYPE_NATIONAL:
printf("national");
break;
case INFO_NTYPE_INTERNATIONAL:
printf("international");
break;
default:
printf("unknown(%d)", param->integer_value);
}
break;
}
if (param_defs[param->index].type == PARAM_TYPE_YESNO) {
switch(param->integer_value) {
case 1:
printf("yes");
break;
case 0:
printf("no");
break;
default:
printf("unknown(%d)", param->integer_value);
}
break;
}
if (param_defs[param->index].type == PARAM_TYPE_NULL) {
break;
}
printf("%d", param->integer_value);
break;
case VALUE_TYPE_STRING:
printf("'%s'", param->string_value);
break;
default:
printf("Software error: VALUE_TYPE_* %d not known in function '%s' line=%d", param->value_type, __FUNCTION__, __LINE__);
}
param = param->next;
printf("\n");
}
/* TIMEOUT */
if (action->timeout)
printf(" Timeout: %d\n", action->timeout);
action = action->next;
}
printf("\n");
rule = rule->next;
}
printf("\n");
ruleset = ruleset->next;
}
}
/*
* parse ruleset
*/
static char *read_string(char *p, char *key, int key_size, const char *special)
{
key[0] = 0;
if (*p == '\"') {
p++;
/* quote */
while(*p) {
if (*p == '\"') {
p++;
*key = '\0';
return(p);
}
if (*p == '\\') {
p++;
if (*p == '\0') {
break;
}
}
if (--key_size == 0) {
UPRINT(key, "\001String too long.");
return(p);
}
*key++ = *p++;
}
UPRINT(key, "\001Unexpected end of line inside quotes.");
return(p);
}
/* no quote */
while(*p) {
if (strchr(special, *p)) {
*key = '\0';
return(p);
}
if (*p == '\\') {
p++;
if (*p == '\0') {
UPRINT(key, "\001Unexpected end of line.");
return(p);
}
}
if (--key_size == 0) {
UPRINT(key, "\001String too long.");
return(p);
}
*key++ = *p++;
}
*key = '\0';
return(p);
}
char ruleset_error[256];
struct route_ruleset *ruleset_parse(void)
{
// char from[128];
// char to[128];
int i;
unsigned long long j;
// int a,
// b;
#define MAXNESTING 8
FILE *fp[MAXNESTING];
char filename[MAXNESTING][256];
int line[MAXNESTING];
int nesting = -1;
char buffer[1024],
key[1024],
key_to[1024],
pointer[1024+1],
*p;
int expecting = 1; /* 1 = expecting ruleset */
int index,
value_type,
integer,
integer_to; /* condition index, .. */
struct route_ruleset *ruleset_start = NULL, *ruleset;
struct route_ruleset **ruleset_pointer = &ruleset_start;
struct route_rule *rule;
struct route_rule **rule_pointer = NULL;
struct route_cond *cond;
struct route_cond **cond_pointer = NULL;
struct route_action *action;
struct route_action **action_pointer = NULL;
struct route_param *param;
struct route_param **param_pointer = NULL;
char failure[256];
unsigned long long allowed_params;
/* check the integrity of IDs for ACTION_* and PARAM_* */
i = 0;
while(action_defs[i].name) {
if (action_defs[i].id != i) {
PERROR("Software Error action '%s' must have id of %d, but has %d.\n",
action_defs[i].name, i, action_defs[i].id);
goto openerror;
}
i++;
}
i = 0; j = 1;
while(param_defs[i].name) {
if (param_defs[i].id != j) {
PERROR("Software Error param '%s' must have id of 0x%llx, but has 0x%llx.\n",
param_defs[i].name, j, param_defs[i].id);
goto openerror;
}
i++;
j<<=1;
}
SPRINT(filename[0], "%s/routing.conf", CONFIG_DATA);
if (!(fp[0]=fopen(filename[0],"r")))
{
PERROR("Cannot open %s\n",filename[0]);
goto openerror;
}
nesting++;
fduse++;
go_leaf:
line[nesting]=0;
go_root:
while((GETLINE(buffer, fp[nesting])))
{
line[nesting]++;
p = buffer;
/* remove tabs */
while(*p) {
if (*p < 32)
*p = 32;
p++;
}
p = buffer;
/* skip spaces, if any */
while(*p == 32)
{
if (*p == 0)
break;
p++;
}
/* skip comments */
if (*p == '#') {
p++;
/* don't skip "define" */
if (!!strncmp(p, "define", 6))
continue;
p+=6;
if (*p != 32)
continue;
/* skip spaces */
while(*p == 32) {
if (*p == 0)
break;
p++;
}
p++;
p = read_string(p, key, sizeof(key), " ");
if (key[0] == 1) { /* error */
SPRINT(failure, "Parsing Filename failed: %s", key+1);
goto parse_error;
}
if (nesting == MAXNESTING-1) {
SPRINT(failure, "'include' is nesting too deep.\n");
goto parse_error;
}
if (key[0] == '/')
SCPY(filename[nesting+1], key);
else
SPRINT(filename[nesting+1], "%s/%s", CONFIG_DATA, key);
if (!(fp[nesting+1]=fopen(filename[nesting+1],"r"))) {
PERROR("Cannot open %s\n", filename[nesting+1]);
goto parse_error;
}
fduse++;
nesting++;
goto go_leaf;
}
if (*p == '/') if (p[1] == '/')
continue;
/* skip empty lines */
if (*p == 0)
continue;
/* expecting ruleset */
if (expecting) {
new_ruleset:
/* expecting [ */
if (*p != '[') {
SPRINT(failure, "Expecting ruleset name starting with '['.");
goto parse_error;
}
p++;
/* reading ruleset name text */
i = 0;
while(*p>' ' && *p<127 && *p!=']') {
if (*p>='A' && *p<='Z') *p = *p-'A'+'a'; /* lower case */
key[i++] = *p++;
if (i == sizeof(key)) i--; /* limit */
}
key[i] = 0;
if (key[0] == '\0') {
SPRINT(failure, "Missing ruleset name after '['.");
goto parse_error;
}
/* expecting ] and nothing more */
if (*p != ']') {
SPRINT(failure, "Expecting ']' after ruleset name.");
goto parse_error;
}
p++;
if (*p != 0) {
SPRINT(failure, "Unexpected character after ruleset name.");
goto parse_error;
}
/* check for duplicate rulesets */
ruleset = ruleset_start;
while(ruleset) {
if (!strcmp(ruleset->name, key)) {
SPRINT(failure, "Duplicate ruleset '%s', already defined in file '%s' line %d.", key, ruleset->file, ruleset->line);
goto parse_error;
}
ruleset = ruleset->next;
}
/* create ruleset */
ruleset = (struct route_ruleset *)MALLOC(sizeof(struct route_ruleset));
rmemuse++;
*ruleset_pointer = ruleset;
ruleset_pointer = &(ruleset->next);
SCPY(ruleset->name, key);
SCPY(ruleset->file, filename[nesting]);
ruleset->line = line[nesting];
rule_pointer = &(ruleset->rule_first);
expecting = 0;
continue;
}