-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction.cpp
2795 lines (2502 loc) · 85.7 KB
/
action.cpp
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 **
** **
** all actions (and hangup) are processed here **
** **
\*****************************************************************************/
#include "main.h"
extern char **environ;
/*
* process init 'internal' / 'external' / 'vbox-record' / 'partyline'...
*/
void EndpointAppPBX::action_init_call(void)
{
class Join *join;
/* a created call, this should never happen */
if (ea_endpoint->ep_join_id) {
if (options.deb & DEBUG_EPOINT)
PERROR("EPOINT(%d): We already have a call instance, this should never happen!\n", ea_endpoint->ep_serial);
return;
}
/* create join */
PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
join = new JoinPBX(ea_endpoint);
if (!join)
FATAL("No memoy for Join instance.\n");
ea_endpoint->ep_join_id = join->j_serial;
return;
}
/*
* process dialing 'internal'
*/
void EndpointAppPBX::action_dialing_internal(void)
{
struct capa_info capainfo;
struct caller_info callerinfo;
struct redir_info redirinfo;
struct rtp_info rtpinfo;
struct dialing_info dialinginfo;
struct port_list *portlist = ea_endpoint->ep_portlist;
struct lcr_msg *message;
struct extension ext;
struct route_param *rparam;
/* send proceeding, because number is complete */
set_tone(portlist, "proceeding");
message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
message_put(message);
logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
new_state(EPOINT_STATE_IN_PROCEEDING);
/* create bearer/caller/dialinginfo */
memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
memcpy(&rtpinfo, &e_rtpinfo, sizeof(rtpinfo));
memset(&dialinginfo, 0, sizeof(dialinginfo));
dialinginfo.itype = INFO_ITYPE_ISDN_EXTENSION;
SCPY(dialinginfo.id, e_dialinginfo.id);
/* process extension */
if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
SCPY(dialinginfo.id, rparam->string_value);
/* process number type */
if ((rparam = routeparam(e_action, PARAM_TYPE)))
dialinginfo.ntype = rparam->integer_value;
/* process service */
if ((rparam = routeparam(e_action, PARAM_CAPA))) {
capainfo.bearer_capa = rparam->integer_value;
if (capainfo.bearer_capa != INFO_BC_SPEECH
&& capainfo.bearer_capa != INFO_BC_AUDIO) {
capainfo.bearer_mode = INFO_BMODE_PACKET;
}
capainfo.bearer_info1 = INFO_INFO1_NONE;
capainfo.hlc = INFO_HLC_NONE;
capainfo.exthlc = INFO_HLC_NONE;
}
if ((rparam = routeparam(e_action, PARAM_BMODE))) {
capainfo.bearer_mode = rparam->integer_value;
}
if ((rparam = routeparam(e_action, PARAM_INFO1))) {
capainfo.bearer_info1 = rparam->integer_value;
}
if ((rparam = routeparam(e_action, PARAM_HLC))) {
capainfo.hlc = rparam->integer_value;
}
if ((rparam = routeparam(e_action, PARAM_EXTHLC))) {
capainfo.exthlc = rparam->integer_value;
}
/* process presentation */
if ((rparam = routeparam(e_action, PARAM_PRESENT))) {
callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
}
/* check if extension exists AND only if not multiple extensions */
if (!strchr(dialinginfo.id,',') && !read_extension(&ext, dialinginfo.id)) {
trace_header("ACTION extension (extension doesn't exist)", DIRECTION_NONE);
add_trace("extension", NULL, dialinginfo.id);
end_trace();
release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
new_state(EPOINT_STATE_OUT_DISCONNECT);
message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
set_tone(portlist, "cause_86");
return;
}
/* check if internal calls are denied */
if (e_ext.rights < 1) {
trace_header("ACTION extension (dialing to extension denied)", DIRECTION_NONE);
add_trace("extension", NULL, dialinginfo.id);
end_trace();
new_state(EPOINT_STATE_OUT_DISCONNECT);
release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
set_tone(portlist, "cause_81");
return;
}
/* add or update internal call */
trace_header("ACTION extension (calling)", DIRECTION_NONE);
add_trace("extension", NULL, dialinginfo.id);
end_trace();
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
memcpy(&message->param.setup.rtpinfo, &rtpinfo, sizeof(struct rtp_info));
message_put(message);
}
/* process dialing external
*/
void EndpointAppPBX::action_dialing_external(void)
{
struct capa_info capainfo;
struct caller_info callerinfo;
struct redir_info redirinfo;
struct rtp_info rtpinfo;
struct dialing_info dialinginfo;
char *p;
struct port_list *portlist = ea_endpoint->ep_portlist;
struct lcr_msg *message;
struct route_param *rparam;
/* special processing of delete characters '*' and '#' */
if (e_ext.delete_ext) {
/* dialing a # causes a clearing of complete number */
if (strchr(e_extdialing, '#')) {
e_extdialing[0] = '\0';
PDEBUG(DEBUG_EPOINT, "EPOINT(%d): '#' detected: terminal '%s' selected caller id '%s' and continues dialing: '%s'\n", ea_endpoint->ep_serial, e_ext.number, e_callerinfo.id, e_extdialing);
}
/* eliminate digits before '*', which is a delete digit
*/
if (strchr(e_extdialing, '*')) {
/* remove digits */
while((p=strchr(e_extdialing, '*'))) {
if (p > e_extdialing) { /* only if there is a digit in front */
UCPY(p-1, p);
p--;
}
UCPY(p, p+1); /* remove '*' */
}
PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s deleted digits and got new string: %s\n", ea_endpoint->ep_serial, e_ext.number, e_extdialing);
}
}
/* create bearer/caller/dialinginfo */
memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
memcpy(&rtpinfo, &e_rtpinfo, sizeof(rtpinfo));
memset(&dialinginfo, 0, sizeof(dialinginfo));
dialinginfo.itype = INFO_ITYPE_ISDN;
// dialinginfo.sending_complete = 0;
SCPY(dialinginfo.id, e_extdialing);
/* process prefix */
if ((rparam = routeparam(e_action, PARAM_PREFIX)))
SPRINT(dialinginfo.id, "%s%s", rparam->string_value, e_extdialing);
if ((rparam = routeparam(e_action, PARAM_CONTEXT)))
SCPY(dialinginfo.context, rparam->string_value);
/* process keypad */
if ((rparam = routeparam(e_action, PARAM_KEYPAD))) {
SCPY(dialinginfo.keypad, dialinginfo.id);
dialinginfo.id[0] = '\0';
}
/* process number complete */
if ((rparam = routeparam(e_action, PARAM_COMPLETE)))
dialinginfo.sending_complete = 1;
/* process number type */
if ((rparam = routeparam(e_action, PARAM_TYPE)))
dialinginfo.ntype = rparam->integer_value;
/* process service */
if ((rparam = routeparam(e_action, PARAM_CAPA))) {
capainfo.bearer_capa = rparam->integer_value;
if (capainfo.bearer_capa != INFO_BC_SPEECH
&& capainfo.bearer_capa != INFO_BC_AUDIO) {
capainfo.bearer_mode = INFO_BMODE_PACKET;
}
capainfo.bearer_info1 = INFO_INFO1_NONE;
capainfo.hlc = INFO_HLC_NONE;
capainfo.exthlc = INFO_HLC_NONE;
}
if ((rparam = routeparam(e_action, PARAM_BMODE))) {
capainfo.bearer_mode = rparam->integer_value;
}
if ((rparam = routeparam(e_action, PARAM_INFO1))) {
capainfo.bearer_info1 = rparam->integer_value;
}
if ((rparam = routeparam(e_action, PARAM_HLC))) {
capainfo.hlc = rparam->integer_value;
}
if ((rparam = routeparam(e_action, PARAM_EXTHLC))) {
capainfo.exthlc = rparam->integer_value;
}
/* process callerid */
if ((rparam = routeparam(e_action, PARAM_CALLERID))) {
SCPY(callerinfo.id, rparam->string_value);
}
if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE))) {
callerinfo.ntype = rparam->integer_value;
}
/* process presentation */
if ((rparam = routeparam(e_action, PARAM_PRESENT))) {
callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
}
/* process interfaces */
if ((rparam = routeparam(e_action, PARAM_INTERFACES)))
SCPY(dialinginfo.interfaces, rparam->string_value);
/* check if local calls are denied */
if (e_ext.rights < 2) {
trace_header("ACTION extern (calling denied)", DIRECTION_NONE);
end_trace();
release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
set_tone(portlist, "cause_82");
denied:
message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
new_state(EPOINT_STATE_OUT_DISCONNECT);
return;
}
if (!strncmp(dialinginfo.id, options.national, strlen(options.national))
|| dialinginfo.ntype == INFO_NTYPE_NATIONAL
|| dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL) {
/* check if national calls are denied */
if (e_ext.rights < 3) {
trace_header("ACTION extern (national calls denied)", DIRECTION_NONE);
end_trace();
release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
set_tone(portlist, "cause_83");
goto denied;
}
}
if (!strncmp(dialinginfo.id, options.international, strlen(options.international))
|| dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL) {
/* check if international calls are denied */
if (e_ext.rights < 4) {
trace_header("ACTION extern (international calls denied)", DIRECTION_NONE);
end_trace();
release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
set_tone(portlist, "cause_84");
goto denied;
}
}
/* add or update outgoing call */
trace_header("ACTION extern (calling)", DIRECTION_NONE);
add_trace("number", NULL, dialinginfo.id);
if (dialinginfo.sending_complete)
add_trace("number", "complete", "yes");
if (dialinginfo.interfaces[0])
add_trace("interfaces", NULL, dialinginfo.interfaces);
end_trace();
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
memcpy(&message->param.setup.rtpinfo, &rtpinfo, sizeof(struct rtp_info));
message_put(message);
}
/*
* process dialing the "am" and record
*/
void EndpointAppPBX::action_dialing_vbox_record(void)
{
struct dialing_info dialinginfo;
struct port_list *portlist = ea_endpoint->ep_portlist;
struct lcr_msg *message;
struct extension ext;
struct route_param *rparam;
portlist = ea_endpoint->ep_portlist;
/* check for given extension */
if (!(rparam = routeparam(e_action, PARAM_EXTENSION))) {
trace_header("ACTION vbox-record (no extension given by parameter)", DIRECTION_NONE);
end_trace();
new_state(EPOINT_STATE_OUT_DISCONNECT);
message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
set_tone(portlist, "cause_3f");
return;
}
/* check if extension exists */
if (!read_extension(&ext, rparam->string_value)) {
trace_header("ACTION vbox-record (given extension does not exists)", DIRECTION_NONE);
add_trace("extension", NULL, "%s", rparam->string_value);
end_trace();
new_state(EPOINT_STATE_OUT_DISCONNECT);
message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
set_tone(portlist, "cause_86");
return;
}
/* check if internal calls are denied */
if (e_ext.rights < 1) {
trace_header("ACTION vbox-record (internal calls are denied)", DIRECTION_NONE);
end_trace();
new_state(EPOINT_STATE_OUT_DISCONNECT);
message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
set_tone(portlist, "cause_81");
return;
}
set_tone(portlist, "proceeding");
message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
message_put(message);
logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
new_state(EPOINT_STATE_IN_PROCEEDING);
memset(&dialinginfo, 0, sizeof(dialinginfo));
dialinginfo.itype = INFO_ITYPE_VBOX;
dialinginfo.sending_complete = 1;
SCPY(dialinginfo.id, rparam->string_value);
/* append special announcement (if given) */
if ((rparam = routeparam(e_action, PARAM_ANNOUNCEMENT)))
if (rparam->string_value[0]) {
SCAT(dialinginfo.id, ",");
SCAT(dialinginfo.id, rparam->string_value);
}
/* add or update internal call */
trace_header("ACTION vbox-record (calling)", DIRECTION_NONE);
add_trace("extension", NULL, "%s", dialinginfo.id);
end_trace();
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
message_put(message);
}
/*
* process partyline
*/
void EndpointAppPBX::action_init_partyline(void)
{
class Join *join;
class JoinPBX *joinpbx;
struct port_list *portlist = ea_endpoint->ep_portlist;
struct lcr_msg *message;
struct route_param *rparam;
int partyline, jingle = 0;
struct join_relation *relation;
portlist = ea_endpoint->ep_portlist;
/* check for given extension */
if (!(rparam = routeparam(e_action, PARAM_ROOM))) {
trace_header("ACTION partyline (no room parameter)", DIRECTION_NONE);
end_trace();
noroom:
new_state(EPOINT_STATE_OUT_DISCONNECT);
message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
set_tone(portlist, "cause_3f");
return;
}
if (rparam->integer_value <= 0) {
trace_header("ACTION partyline (illegal room parameter)", DIRECTION_NONE);
add_trace("room", NULL, "%d", rparam->integer_value);
end_trace();
PDEBUG(DEBUG_EPOINT, "EPOINT(%d): invalid value for 'room'.\n", ea_endpoint->ep_serial);
goto noroom;
}
partyline = rparam->integer_value;
if ((rparam = routeparam(e_action, PARAM_JINGLE)))
jingle = 1;
/* don't create join if partyline exists */
join = join_first;
while(join) {
if (join->j_type == JOIN_TYPE_PBX) {
joinpbx = (class JoinPBX *)join;
if (joinpbx->j_partyline == partyline)
break;
}
join = join->next;
}
if (!join) {
/* create join */
PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
if (!(join = new JoinPBX(ea_endpoint)))
FATAL("No memory for join object\n");
} else {
//NOTE: joinpbx must be set here
/* add relation to existing join */
if (!(relation=joinpbx->add_relation()))
FATAL("No memory for join relation\n");
relation->type = RELATION_TYPE_SETUP;
relation->channel_state = 1;
relation->rx_state = NOTIFY_STATE_ACTIVE;
relation->tx_state = NOTIFY_STATE_ACTIVE;
relation->epoint_id = ea_endpoint->ep_serial;
}
ea_endpoint->ep_join_id = join->j_serial;
set_tone(portlist, "proceeding");
message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
message_put(message);
logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
new_state(EPOINT_STATE_IN_PROCEEDING);
/* send setup to join */
trace_header("ACTION partyline (calling)", DIRECTION_NONE);
add_trace("room", NULL, "%d", partyline);
add_trace("jingle", NULL, (jingle)?"on":"off");
end_trace();
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
message->param.setup.partyline = partyline;
message->param.setup.partyline_jingle = jingle;
memcpy(&message->param.setup.dialinginfo, &e_dialinginfo, sizeof(struct dialing_info));
memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
message_put(message);
}
/*
* process hangup of all calls
*/
void EndpointAppPBX::action_hangup_call(void)
{
trace_header("ACTION hangup", DIRECTION_NONE);
end_trace();
}
/*
* process dialing 'login'
*/
void EndpointAppPBX::action_dialing_login(void)
{
struct port_list *portlist = ea_endpoint->ep_portlist;
struct lcr_msg *message;
char *extension;
struct route_param *rparam;
/* extension parameter */
if ((rparam = routeparam(e_action, PARAM_EXTENSION))) {
/* extension is given by parameter */
extension = rparam->string_value;
if (extension[0] == '\0')
return;
if (!read_extension(&e_ext, extension)) {
trace_header("ACTION login (extension doesn't exist)", DIRECTION_NONE);
add_trace("extension", NULL, "%s", extension);
end_trace();
/* extension doesn't exist */
new_state(EPOINT_STATE_OUT_DISCONNECT);
message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
set_tone(portlist, "cause_86");
return;
}
} else {
/* extension must be given by dialstring */
extension = e_extdialing;
if (extension[0] == '\0')
return;
if (!read_extension(&e_ext, extension)) {
trace_header("ACTION login (extension incomplete or does not exist)", DIRECTION_NONE);
add_trace("extension", NULL, "%s", extension);
end_trace();
return;
}
}
/* we changed our extension */
SCPY(e_ext.number, extension);
new_state(EPOINT_STATE_CONNECT);
e_dtmf = 1;
e_connectedmode = 1;
/* send connect with extension's caller id (COLP) */
message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
SCPY(message->param.connectinfo.id, e_ext.callerid);
message->param.connectinfo.ntype = e_ext.callerid_type;
if (e_ext.callerid_present==INFO_PRESENT_ALLOWED && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
message->param.connectinfo.present = INFO_PRESENT_RESTRICTED;
else message->param.connectinfo.present = e_ext.callerid_present;
/* handle restricted caller ids */
apply_callerid_restriction(&e_ext, message->param.connectinfo.id, &message->param.connectinfo.ntype, &message->param.connectinfo.present, &message->param.connectinfo.screen, message->param.connectinfo.extension, message->param.connectinfo.name);
/* display callerid if desired for extension */
SCPY(message->param.connectinfo.display, apply_callerid_display(message->param.connectinfo.id, message->param.connectinfo.itype, message->param.connectinfo.ntype, message->param.connectinfo.present, message->param.connectinfo.screen, message->param.connectinfo.extension, message->param.connectinfo.name));
message->param.connectinfo.ntype = e_ext.callerid_type;
message_put(message);
logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
/* set our caller id */
SCPY(e_callerinfo.id, e_ext.callerid);
e_callerinfo.ntype = e_ext.callerid_type;
e_callerinfo.present = e_ext.callerid_present;
/* enable connectedmode */
e_connectedmode = 1;
e_dtmf = 1;
if (!(rparam = routeparam(e_action, PARAM_NOPASSWORD))) {
/* make call state to enter password */
trace_header("ACTION login (ask for password)", DIRECTION_NONE);
add_trace("extension", NULL, "%s", e_ext.number);
end_trace();
new_state(EPOINT_STATE_IN_OVERLAP);
e_ruleset = NULL;
e_rule = NULL;
e_action = &action_password;
unsched_timer(&e_match_timeout);
e_match_to_action = NULL;
e_dialinginfo.id[0] = '\0';
e_extdialing = strchr(e_dialinginfo.id, '\0');
/* set timeout */
schedule_timer(&e_password_timeout, 20, 0);
/* do dialing */
process_dialing(0);
} else {
/* make call state */
new_state(EPOINT_STATE_IN_OVERLAP);
e_ruleset = ruleset_main;
if (e_ruleset)
e_rule = e_ruleset->rule_first;
e_action = NULL;
e_dialinginfo.id[0] = '\0';
e_extdialing = e_dialinginfo.id;
set_tone(portlist, "dialpbx");
}
}
/*
* process init 'change_callerid'
*/
void EndpointAppPBX::action_init_change_callerid(void)
{
struct port_list *portlist = ea_endpoint->ep_portlist;
if (!e_ext.change_callerid) {
/* service not available */
trace_header("ACTION change-callerid (denied for this caller)", DIRECTION_NONE);
end_trace();
message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
new_state(EPOINT_STATE_OUT_DISCONNECT);
set_tone(portlist,"cause_87");
return;
}
}
/* process dialing callerid
*/
void EndpointAppPBX::_action_callerid_calleridnext(int next)
{
struct port_list *portlist = ea_endpoint->ep_portlist;
struct route_param *rparam;
char buffer[64], *callerid;
char old_id[64] = "", new_id[64] = "";
int old_type=0, new_type=0, old_present=0, new_present=0;
if ((rparam = routeparam(e_action, PARAM_CALLERID))) {
/* the caller ID is given by parameter */
callerid = rparam->string_value;
} else {
/* caller ID is dialed */
if (!strchr(e_extdialing, '#')) {
/* no complete ID yet */
return;
}
*strchr(e_extdialing, '#') = '\0';
callerid = e_extdialing;
}
/* given callerid type */
if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
switch(rparam->integer_value) {
case INFO_NTYPE_SUBSCRIBER:
SPRINT(buffer, "s%s", callerid);
callerid = buffer;
break;
case INFO_NTYPE_NATIONAL:
SPRINT(buffer, "n%s", callerid);
callerid = buffer;
break;
case INFO_NTYPE_INTERNATIONAL:
SPRINT(buffer, "i%s", callerid);
callerid = buffer;
break;
default:
SPRINT(buffer, "%s", callerid);
callerid = buffer;
break;
}
/* caller id complete, dialing with new caller id */
/* write new parameters */
if (read_extension(&e_ext, e_ext.number)) {
old_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
old_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
SCPY(old_id, (!next)?e_ext.callerid:e_ext.id_next_call);
if (callerid[0] == '\0') {
/* no caller id */
(!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
} else {
/* new caller id */
(!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_ALLOWED;
if ((rparam = routeparam(e_action, PARAM_PRESENT))) if (rparam->integer_value == 0)
(!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
if (e_ext.callerid_type == INFO_NTYPE_UNKNOWN) /* if callerid is unknown, the given id is not nationalized */ {
SCPY((!next)?e_ext.callerid:e_ext.id_next_call, callerid);
(!next)?e_ext.callerid_type:e_ext.id_next_call_type = INFO_NTYPE_UNKNOWN;
} else {
SCPY((!next)?e_ext.callerid:e_ext.id_next_call, nationalize_callerinfo(callerid,&((!next)?e_ext.callerid_type:e_ext.id_next_call_type), options.national, options.international));
}
if (!next) e_ext.id_next_call_type = -1;
PDEBUG(DEBUG_EPOINT, "EPOINT(%d): nationalized callerid: '%s' type=%d\n", ea_endpoint->ep_serial, (!next)?e_ext.callerid:e_ext.id_next_call, (!next)?e_ext.callerid_type:e_ext.id_next_call_type);
}
new_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
new_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
SCPY(new_id, (!next)?e_ext.callerid:e_ext.id_next_call);
write_extension(&e_ext, e_ext.number);
}
/* function activated */
if (next)
trace_header("ACTION change-callerid (only next call)", DIRECTION_NONE);
else
trace_header("ACTION change-callerid (all future calls)", DIRECTION_NONE);
add_trace("old", "caller id", "%s", numberrize_callerinfo(old_id, old_type, options.national, options.international));
add_trace("old", "present", "%s", (old_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
add_trace("new", "caller id", "%s", numberrize_callerinfo(new_id, new_type, options.national, options.international));
add_trace("new", "present", "%s", (new_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
end_trace();
message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
new_state(EPOINT_STATE_OUT_DISCONNECT);
set_tone(portlist,"activated");
}
/* process dialing callerid for all call
*/
void EndpointAppPBX::action_dialing_callerid(void)
{
_action_callerid_calleridnext(0);
}
/* process dialing callerid for next call
*/
void EndpointAppPBX::action_dialing_calleridnext(void)
{
_action_callerid_calleridnext(1);
}
/*
* process init 'change_forward'
*/
void EndpointAppPBX::action_init_change_forward(void)
{
struct port_list *portlist = ea_endpoint->ep_portlist;
if (!e_ext.change_forward) {
trace_header("ACTION change-forward (denied for this caller)", DIRECTION_NONE);
end_trace();
/* service not available */
message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
new_state(EPOINT_STATE_OUT_DISCONNECT);
set_tone(portlist,"cause_87");
return;
}
}
/* process dialing forwarding
*/
void EndpointAppPBX::action_dialing_forward(void)
{
struct port_list *portlist = ea_endpoint->ep_portlist;
int diversion = INFO_DIVERSION_CFU;
char *dest = e_extdialing;
struct route_param *rparam;
/* if diversion type is given */
if ((rparam = routeparam(e_action, PARAM_DIVERSION)))
diversion = rparam->integer_value;
if ((rparam = routeparam(e_action, PARAM_DEST))) {
/* if destination is given */
dest = rparam->string_value;
} else {
if (!strchr(e_extdialing, '#'))
return;
*strchr(e_extdialing, '#') = '\0';
dest = e_extdialing;
}
PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing forwarding to '%s'.\n", ea_endpoint->ep_serial, e_ext.number, dest);
if (read_extension(&e_ext, e_ext.number)) {
switch(diversion) {
case INFO_DIVERSION_CFU:
trace_header("ACTION change-forward (new CFU=unconditional)", DIRECTION_NONE);
add_trace("destin'", NULL, "%s", dest);
end_trace();
SCPY(e_ext.cfu, dest);
break;
case INFO_DIVERSION_CFB:
trace_header("ACTION change-forward (new CFB=busy)", DIRECTION_NONE);
add_trace("destin'", NULL, "%s", dest);
end_trace();
SCPY(e_ext.cfb, dest);
break;
case INFO_DIVERSION_CFNR:
if ((rparam = routeparam(e_action, PARAM_DELAY)))
e_ext.cfnr_delay = rparam->integer_value;
trace_header("ACTION change-forward (new CFNR=no response)", DIRECTION_NONE);
add_trace("destin'", NULL, "%s", dest);
add_trace("delay", NULL, "%s", e_ext.cfnr_delay);
end_trace();
SCPY(e_ext.cfnr, dest);
break;
case INFO_DIVERSION_CFP:
trace_header("ACTION change-forward (new CFP=parallel)", DIRECTION_NONE);
add_trace("destin'", NULL, "%s", dest);
end_trace();
SCPY(e_ext.cfp, dest);
break;
}
write_extension(&e_ext, e_ext.number);
}
/* function (de)activated */
message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
new_state(EPOINT_STATE_OUT_DISCONNECT);
if (dest[0])
set_tone(portlist,"activated");
else
set_tone(portlist,"deactivated");
}
/* process dialing redial
*/
void EndpointAppPBX::action_init_redial_reply(void)
{
struct port_list *portlist = ea_endpoint->ep_portlist;
e_select = 0;
if (!e_ext.last_out[0]) {
trace_header("ACTION redial/reply (no last number stored)", DIRECTION_NONE);
end_trace();
new_state(EPOINT_STATE_OUT_DISCONNECT);
message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
set_tone(portlist, "cause_3f");
return;
}
}
/* process dialing redial
*/
void EndpointAppPBX::_action_redial_reply(int in)
{
struct lcr_msg *message;
char *last;
struct route_param *rparam;
last = (in)?e_ext.last_in[0]:e_ext.last_out[0];
/* if no display is available */
if (!e_ext.display_menu)
goto nodisplay;
if (ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_IN && ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_OUT)
goto nodisplay;
/* if select is not given */
if (!(rparam = routeparam(e_action, PARAM_SELECT)))
goto nodisplay;
/* scroll menu */
if (e_extdialing[0]=='*' || e_extdialing[0]=='1') {
/* find prev entry */
e_select--;
if (e_select < 0)
e_select = 0;
}
if (e_extdialing[0]=='#' || e_extdialing[0]=='3') {
/* find next entry */
e_select++;
if (e_select >= MAX_REMEMBER) {
e_select--;
} else if (in) {
if (e_ext.last_in[e_select][0] == '\0')
e_select--;
} else
if (e_ext.last_out[e_select][0] == '\0')
e_select--;
}
last = (in)?e_ext.last_in[e_select]:e_ext.last_out[e_select];
if (e_extdialing[0]=='0' || e_extdialing[0]=='2') {
nodisplay:
if (in)
trace_header("ACTION reply (dialing)", DIRECTION_NONE);
else
trace_header("ACTION redial (dialing)", DIRECTION_NONE);
add_trace("number", NULL, "%s", last);
add_trace("last but", NULL, "%d", e_select);
end_trace();
SCPY(e_dialinginfo.id, last);
e_extdialing = e_dialinginfo.id;
e_action = NULL;
process_dialing(0);
return;
}
e_extdialing[0] = '\0';
/* send display message to port */
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
if (!strncmp(last, "extern:", 7))
SPRINT(message->param.notifyinfo.display, "(%d) %s ext", e_select+1, last+7);
else
if (!strncmp(last, "intern:", 7))
SPRINT(message->param.notifyinfo.display, "(%d) %s int", e_select+1, last+7);
else
if (!strncmp(last, "chan:", 4))
SPRINT(message->param.notifyinfo.display, "(%d) %s chan", e_select+1, last+5);
else
if (!strncmp(last, "vbox:", 5))
SPRINT(message->param.notifyinfo.display, "(%d) %s vbox", e_select+1, last+5);
else
SPRINT(message->param.notifyinfo.display, "(%d) %s", e_select+1, (last[0])?last:"- empty -");
PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s sending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
message_put(message);
logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
}
/* process dialing redial
*/
void EndpointAppPBX::action_dialing_redial(void)
{
_action_redial_reply(0);
}
/* process dialing reply
*/
void EndpointAppPBX::action_dialing_reply(void)
{
_action_redial_reply(1);
}
/* dialing powerdialing delay
*/
void EndpointAppPBX::action_dialing_powerdial(void)
{
struct port_list *portlist = ea_endpoint->ep_portlist;
struct lcr_msg *message;
struct route_param *rparam;
/* power dialing only possible if we have a last dialed number */
if (!e_ext.last_out[0]) {
trace_header("ACTION powerdial (no last number stored)", DIRECTION_NONE);
end_trace();
new_state(EPOINT_STATE_OUT_DISCONNECT);
message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
set_tone(portlist, "cause_3f");
return;
}
/* limit */
if ((rparam = routeparam(e_action, PARAM_LIMIT))) {
e_powerlimit = rparam->integer_value;
} else {
e_powerlimit = 0;
}
/* delay */
if ((rparam = routeparam(e_action, PARAM_DELAY))) {
e_powerdelay = rparam->integer_value;
} else {
/* delay incomplete */
if (!strchr(e_extdialing, '#'))
return;
*strchr(e_extdialing, '#') = '\0';
e_powerdelay = e_extdialing[0]?atoi(e_extdialing): 0;
}
if (e_powerdelay < 1)
e_powerdelay = 0.2;
trace_header("ACTION powerdial (dialing)", DIRECTION_NONE);
add_trace("number", NULL, "%s", e_ext.last_out[0]);
add_trace("delay", NULL, "%d", e_powerdelay);
end_trace();
/* send connect to avoid overlap timeout */
// new_state(EPOINT_STATE_CONNECT); connect may prevent further dialing
if (e_ext.number[0])
e_dtmf = 1;
memset(&e_connectinfo, 0, sizeof(e_connectinfo));
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
message_put(message);
logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
/* do dialing */
SCPY(e_dialinginfo.id, e_ext.last_out[0]);
e_powerdial_on = 1; /* indicates the existence of powerdialing but no redial time given */
e_powercount = 0;
e_action = NULL;
process_dialing(0);
}
/* dialing callback
*/
void EndpointAppPBX::action_dialing_callback(void)
{
struct port_list *portlist = ea_endpoint->ep_portlist;
struct route_param *rparam;
struct extension cbext;
portlist = ea_endpoint->ep_portlist;
/* check given extension */
if (!(rparam = routeparam(e_action, PARAM_EXTENSION))) {
noextension:
trace_header("ACTION callback (no extension defined)", DIRECTION_NONE);
end_trace();
disconnect:
new_state(EPOINT_STATE_OUT_DISCONNECT);
message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
set_tone(portlist, "cause_3f");
e_action = NULL;
e_cbcaller[0] = e_cbdialing[0] = '\0';
return;
}
/* if extension is given */
SCPY(e_cbcaller, rparam->string_value);
if (e_cbcaller[0] == '\0')
goto noextension;
/* read callback extension */
memset(&cbext, 0, sizeof(cbext));
if (!read_extension(&cbext, e_cbcaller)) {
trace_header("ACTION callback (extension doesn't exist)", DIRECTION_NONE);
add_trace("extension", NULL, "%s", e_cbcaller);
end_trace();
goto disconnect;
}
/* if password is not given */