-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapppbx.cpp
4770 lines (4302 loc) · 176 KB
/
apppbx.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
/*****************************************************************************\
** **
** Linux Call Router **
** **
**---------------------------------------------------------------------------**
** Copyright: Andreas Eversberg **
** **
** The EndpointAppPBX implements PBX4Linux **
** **
\*****************************************************************************/
#include "main.h"
class EndpointAppPBX *apppbx_first = NULL;
int action_timeout(struct lcr_timer *timer, void *instance, int index);
int match_timeout(struct lcr_timer *timer, void *instance, int index);
int redial_timeout(struct lcr_timer *timer, void *instance, int index);
int powerdial_timeout(struct lcr_timer *timer, void *instance, int index);
int cfnr_timeout(struct lcr_timer *timer, void *instance, int index);
int cfnr_call_timeout(struct lcr_timer *timer, void *instance, int index);
int password_timeout(struct lcr_timer *timer, void *instance, int index);
int callback_timeout(struct lcr_timer *timer, void *instance, int index);
/*
* EndpointAppPBX constructor
*/
EndpointAppPBX::EndpointAppPBX(class Endpoint *epoint, int origin) : EndpointApp(epoint, origin, EAPP_TYPE_PBX)
{
class EndpointAppPBX **apppointer;
#ifdef WITH_CRYPT
memset(&e_crypt_handler, 0, sizeof(e_crypt_handler));
add_timer(&e_crypt_handler, crypt_handler, this, 0);
#endif
memset(&e_vbox_refresh, 0, sizeof(e_vbox_refresh));
add_timer(&e_vbox_refresh, vbox_refresh, this, 0);
memset(&e_action_timeout, 0, sizeof(e_action_timeout));
add_timer(&e_action_timeout, action_timeout, this, 0);
memset(&e_match_timeout, 0, sizeof(e_match_timeout));
add_timer(&e_match_timeout, match_timeout, this, 0);
memset(&e_redial_timeout, 0, sizeof(e_redial_timeout));
add_timer(&e_redial_timeout, redial_timeout, this, 0);
memset(&e_powerdial_timeout, 0, sizeof(e_powerdial_timeout));
add_timer(&e_powerdial_timeout, powerdial_timeout, this, 0);
memset(&e_cfnr_timeout, 0, sizeof(e_cfnr_timeout));
add_timer(&e_cfnr_timeout, cfnr_timeout, this, 0);
memset(&e_cfnr_call_timeout, 0, sizeof(e_cfnr_call_timeout));
add_timer(&e_cfnr_call_timeout, cfnr_call_timeout, this, 0);
memset(&e_callback_timeout, 0, sizeof(e_callback_timeout));
add_timer(&e_callback_timeout, callback_timeout, this, 0);
memset(&e_password_timeout, 0, sizeof(e_password_timeout));
add_timer(&e_password_timeout, password_timeout, this, 0);
e_powerdial_on = 0;
/* add application to chain */
next = NULL;
apppointer = &apppbx_first;
while(*apppointer)
apppointer = &((*apppointer)->next);
*apppointer = this;
/* initialize */
memset(&e_ext, 0, sizeof(struct extension));
// *************** NOTE: also change value in read_extension() **************
e_ext.rights = 4; /* international */
e_ext.rx_gain = e_ext.tx_gain = 0;
e_state = EPOINT_STATE_IDLE;
e_ext.number[0] = '\0';
e_extension_interface[0] = '\0';
memset(&e_callerinfo, 0, sizeof(struct caller_info));
memset(&e_dialinginfo, 0, sizeof(struct dialing_info));
memset(&e_connectinfo, 0, sizeof(struct connect_info));
memset(&e_redirinfo, 0, sizeof(struct redir_info));
memset(&e_capainfo, 0, sizeof(struct capa_info));
memset(&e_rtpinfo, 0, sizeof(struct rtp_info));
e_start = e_stop = 0;
e_origin = origin;
e_ruleset = ruleset_main;
if (e_ruleset)
e_rule = e_ruleset->rule_first;
e_rule_nesting = 0;
e_action = NULL;
e_match_to_action = NULL;
e_select = 0;
e_extdialing = e_dialinginfo.id;
// e_knocking = 0;
// e_knocktime = 0;
e_hold = 0;
// e_join_tone[0] = e_hold_tone[0] = '\0';
e_join_pattern /*= e_hold_pattern*/ = 0;
e_tone[0] = '\0';
e_adminid = 0; // will be set, if call was initiated via admin socket
e_powerdelay = 0;
e_powerlimit = 0;
e_cbdialing[0] = '\0';
e_cbcaller[0] = '\0';
e_cbto[0] = '\0';
memset(&e_callbackinfo, 0, sizeof(struct caller_info));
e_connectedmode = 0;
e_dtmf = 0;
e_dtmf_time = 0;
e_dtmf_last = 0;
e_enablekeypad = 0;
e_multipoint_cause = 0;
e_multipoint_location = 0;
e_dialing_queue[0] = '\0';
#ifdef WITH_CRYPT
e_crypt = CRYPT_OFF;
e_crypt_state = CM_ST_NULL;
e_crypt_keyengine_busy = 0;
e_crypt_info[0] = '\0';
#endif
e_overlap = 0;
e_vbox[0] = '\0';
e_tx_state = NOTIFY_STATE_ACTIVE;
e_rx_state = NOTIFY_STATE_ACTIVE;
e_join_cause = e_join_location = 0;
/*********************************
*********************************
********* ATTENTION *************
*********************************
*********************************/
/* if you add new values, that must be initialized, also check if they must
* be initialized when doing callback
*/
}
/*
* EpointAppPBX destructor
*/
EndpointAppPBX::~EndpointAppPBX(void)
{
class EndpointAppPBX *temp, **tempp;
#ifdef WITH_CRYPT
del_timer(&e_crypt_handler);
#endif
del_timer(&e_vbox_refresh);
del_timer(&e_action_timeout);
del_timer(&e_match_timeout);
del_timer(&e_redial_timeout);
del_timer(&e_powerdial_timeout);
del_timer(&e_cfnr_timeout);
del_timer(&e_cfnr_call_timeout);
del_timer(&e_callback_timeout);
del_timer(&e_password_timeout);
/* detach */
temp =apppbx_first;
tempp = &apppbx_first;
while(temp) {
if (temp == this)
break;
tempp = &temp->next;
temp = temp->next;
}
if (temp == 0)
FATAL("Endpoint not in endpoint's list.\n");
*tempp = next;
}
/*
* trace header for application
*/
void EndpointAppPBX::trace_header(const char *name, int direction)
{
struct trace _trace;
char msgtext[sizeof(_trace.name)];
SCPY(msgtext, name);
/* init trace with given values */
start_trace(-1,
NULL,
numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international),
e_dialinginfo.id,
direction,
CATEGORY_EP,
ea_endpoint->ep_serial,
msgtext);
}
EPOINT_STATE_NAMES
/* set new endpoint state
*/
void EndpointAppPBX::new_state(int state)
{
#if 0
if (e_state != state) {
trace_header("NEW STATE", DIRECTION_NONE);
add_trace("state", "old", "%s", state_name[e_state]);
add_trace("state", "new", "%s", state_name[state]);
end_trace();
}
#endif
e_state = state;
}
/* release join and port (as specified)
*/
void EndpointAppPBX::release(int release, int joinlocation, int joincause, int portlocation, int portcause, int force)
{
struct port_list *portlist;
struct lcr_msg *message;
char cause[16];
/* message to test call */
admin_call_response(e_adminid, ADMIN_CALL_RELEASE, "", joincause, joinlocation, 0);
/* if a release is pending */
if (release==RELEASE_JOIN || release==RELEASE_ALL || release==RELEASE_PORT_JOINONLY) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d): do pending release (joincause %d location %d)\n", ea_endpoint->ep_serial, joincause, joinlocation);
if (ea_endpoint->ep_join_id) {
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_RELEASE);
message->param.disconnectinfo.cause = joincause;
message->param.disconnectinfo.location = joinlocation;
message_put(message);
ea_endpoint->ep_join_id = 0;
}
e_join_pattern = 0;
#if 0
if (release != RELEASE_PORT_JOINONLY) {
if (e_hold_id)
join_release(e_hold_id, ea_endpoint->ep_serial, 1, joinlocation, joincause);
e_hold_id = 0;
}
#endif
}
if (release==RELEASE_ALL || release==RELEASE_PORT_JOINONLY) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) do pending release (portcause %d portlocation)\n", ea_endpoint->ep_serial, portcause, portlocation);
while((portlist = ea_endpoint->ep_portlist)) {
if (portlist->port_id) {
SPRINT(cause, "cause_%02x", portcause);
set_tone(portlist, cause);
message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_RELEASE);
message->param.disconnectinfo.cause = portcause;
message->param.disconnectinfo.location = portlocation;
message->param.disconnectinfo.force = force; // set, if port should release imediately
message_put(message);
logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
}
ea_endpoint->free_portlist(portlist);
}
/* if callback is enabled, call back with the given caller id */
if (e_callback_timeout.active) {
/* reset some stuff */
new_state(EPOINT_STATE_IDLE);
memset(&e_connectinfo, 0, sizeof(struct connect_info));
memset(&e_redirinfo, 0, sizeof(struct redir_info));
e_start = e_stop = 0;
e_ruleset = ruleset_main;
if (e_ruleset)
e_rule = e_ruleset->rule_first;
e_action = NULL;
unsched_timer(&e_action_timeout);
unsched_timer(&e_match_timeout);
unsched_timer(&e_cfnr_timeout);
unsched_timer(&e_cfnr_call_timeout);
e_match_to_action = NULL;
//e_select = 0;
e_extdialing = e_dialinginfo.id;
e_connectedmode = 0;
e_dtmf = 0;
e_dtmf_time = 0;
e_dtmf_last = 0;
e_enablekeypad = 0;
e_multipoint_cause = 0;
e_multipoint_location = 0;
e_dialing_queue[0] = '\0';
#ifdef WITH_CRYPT
e_crypt = 0;
e_crypt_state = CM_ST_NULL;
e_crypt_keyengine_busy = 0;
e_crypt_info[0] = '\0';
#endif
e_tone[0] = '\0';
e_overlap = 0;
e_vbox[0] = '\0';
e_tx_state = NOTIFY_STATE_ACTIVE;
e_rx_state = NOTIFY_STATE_ACTIVE;
e_join_cause = e_join_location = 0;
e_rule_nesting = 0;
/* the caller info of the callback user */
memcpy(&e_callbackinfo, &e_callerinfo, sizeof(e_callbackinfo));
memset(&e_dialinginfo, 0, sizeof(e_dialinginfo));
/* create dialing by callerinfo */
if (e_ext.number[0] && e_extension_interface[0]) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) preparing callback to internal: %s interface %s\n", ea_endpoint->ep_serial, e_ext.number, e_extension_interface);
/* create callback to the current terminal */
SCPY(e_dialinginfo.id, e_ext.number);
SCPY(e_dialinginfo.interfaces, e_extension_interface);
e_dialinginfo.itype = INFO_ITYPE_ISDN_EXTENSION;
e_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
} else {
if (e_cbto[0]) {
SCPY(e_dialinginfo.id, e_cbto);
} else {
/* numberrize caller id and use it to dial to the callback */
SCPY(e_dialinginfo.id, numberrize_callerinfo(e_callerinfo.id,e_callerinfo.ntype, options.national, options.international));
}
e_dialinginfo.itype = INFO_ITYPE_ISDN;
e_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) preparing callback to external: %s\n", ea_endpoint->ep_serial, e_dialinginfo.id);
}
return;
}
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) do pending release of epoint itself.\n", ea_endpoint->ep_serial);
if (--ea_endpoint->ep_use <= 0) /* when e_lock is 0, the endpoint will be deleted */
trigger_work(&ea_endpoint->ep_delete);
return;
}
}
/* cancel callerid if restricted, unless anon-ignore is enabled at extension or port is of type external (so called police gets caller id :)*/
void apply_callerid_restriction(struct extension *ext, char *id, int *ntype, int *present, int *screen, char *extension, char *name)
{
PDEBUG(DEBUG_EPOINT, "id='%s' ntype=%d present=%d screen=%d extension='%s' name='%s'\n", (id)?id:"NULL", (ntype)?*ntype:-1, (present)?*present:-1, (screen)?*screen:-1, (extension)?extension:"NULL", (name)?name:"NULL");
/* caller id is not restricted, so we do nothing */
if (*present != INFO_PRESENT_RESTRICTED)
return;
/* only extensions are restricted */
if (!ext->number[0])
return;
/* if we enabled anonymouse ignore */
if (ext->anon_ignore)
return;
/* else we remove the caller id */
if (id)
id[0] = '\0';
if (ntype)
*ntype = INFO_NTYPE_UNKNOWN;
// if (screen)
// *screen = INFO_SCREEN_USER;
// maybe we should not make voip address anonymous
// if (voip)
// voip[0] = '\0';
// maybe it's no fraud to present extension id
// if (extension)
// extension[0] = '\0';
if (name)
name[0] = '\0';
}
/* used display message to display callerid as available */
char *EndpointAppPBX::apply_callerid_display(const char *id, int itype, int ntype, int present, int screen, const char *extension, const char *name)
{
static char display[81];
display[0] = '\0';
const char *cid = numberrize_callerinfo(id, ntype, options.national, options.international);
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) id='%s' itype=%d ntype=%d present=%d screen=%d extension='%s' name='%s'\n", ea_endpoint->ep_serial, (id)?id:"NULL", itype, ntype, present, screen, (extension)?extension:"NULL", (name)?name:"NULL");
if (!id)
id = "";
if (!extension)
extension = "";
if (!name)
name = "";
/* NOTE: is caller is is not available for this extesion, it has been removed by apply_callerid_restriction already */
/* internal extension's caller id */
if (extension[0] && e_ext.display_int) {
if (!display[0])
SCAT(display, extension);
if (display[0])
SCAT(display, " ");
if (itype == INFO_ITYPE_VBOX)
SCAT(display, "(vbox)");
else
SCAT(display, "(int)");
}
/* external caller id */
if (!extension[0] && e_ext.display_ext) {
if (!display[0]) {
if (!cid[0]) {
if (present == INFO_PRESENT_RESTRICTED)
SCAT(display, "anonymous");
else
SCAT(display, "unknown");
}
else
SCAT(display, cid);
}
}
/* display if callerid is anonymouse but available due anon-ignore */
if (e_ext.display_anon && present==INFO_PRESENT_RESTRICTED) {
if (!cid[0])
SCAT(display, "unknown");
else
SCAT(display, cid);
SCAT(display, " anon");
}
/* display if callerid is anonymouse but available due anon-ignore */
if (e_ext.display_fake && screen==INFO_SCREEN_USER && ntype!=INFO_NTYPE_NOTPRESENT) {
if (!display[0]) {
if (!id[0]) {
if (present == INFO_PRESENT_RESTRICTED)
SCAT(display, "anonymous");
else
SCAT(display, "unknown");
}
else
SCAT(display, cid);
}
SCAT(display, " fake");
}
/* caller name */
if (name[0] && e_ext.display_name) {
if (!display[0] && cid[0])
SCAT(display, cid);
if (display[0])
SCAT(display, " ");
SCAT(display, name);
}
return(display);
}
/*
* uses the current state to notify activity
*/
void EndpointAppPBX::notify_active(void)
{
struct port_list *portlist = ea_endpoint->ep_portlist;
struct lcr_msg *message;
int notify = 0;
switch(e_tx_state) {
case NOTIFY_STATE_ACTIVE:
/* we are already active, so we don't do anything */
break;
case NOTIFY_STATE_SUSPEND:
notify = INFO_NOTIFY_USER_RESUMED;
while(portlist) {
set_tone(portlist, NULL);
portlist = portlist->next;
}
portlist = ea_endpoint->ep_portlist;
break;
case NOTIFY_STATE_HOLD:
notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
while(portlist) {
set_tone(portlist, NULL);
portlist = portlist->next;
}
portlist = ea_endpoint->ep_portlist;
break;
case NOTIFY_STATE_CONFERENCE:
notify = INFO_NOTIFY_CONFERENCE_DISCONNECTED;
while(portlist) {
set_tone(portlist, NULL);
portlist = portlist->next;
}
portlist = ea_endpoint->ep_portlist;
break;
default:
PERROR("unknown e_tx_state = %d\n", e_tx_state);
}
if (notify)
while(portlist) {
message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
message->param.notifyinfo.notify = notify;
message_put(message);
logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
portlist = portlist->next;
}
}
/*
* keypad functions during call. one example to use this is to put a call on hold or start a conference
*/
void EndpointAppPBX::keypad_function(char digit)
{
class Port *port;
/* we must be in a call, in order to send messages to the call */
if (e_ext.number[0] == '\0') {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) IGNORING keypad received not from extension.\n", ea_endpoint->ep_serial);
return;
}
switch(digit) {
/* join conference */
case '3':
if (ea_endpoint->ep_join_id == 0) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) keypad received during connect but not during a call.\n", ea_endpoint->ep_serial);
break;
}
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) join call with call on hold\n", ea_endpoint->ep_serial);
port = find_port_id(ea_endpoint->ep_portlist->port_id);
if (!port)
break;
if ((port->p_type & PORT_CLASS_POTS_MASK) == PORT_CLASS_POTS_FXS)
join_join_fxs();
else if ((port->p_type & PORT_CLASS_mISDN_MASK) == PORT_CLASS_DSS1)
join_join_dss1();
break;
#ifdef WITH_CRYPT
/* crypt shared */
case '7':
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) shared key encryption selected.\n", ea_endpoint->ep_serial);
encrypt_shared();
break;
/* crypt key-exchange */
case '8':
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) key exchange encryption selected.\n", ea_endpoint->ep_serial);
encrypt_keyex();
break;
/* crypt off */
case '9':
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) encryption off selected.\n", ea_endpoint->ep_serial);
encrypt_off();
break;
#endif
default:
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) unsupported keypad digit '%c'.\n", ea_endpoint->ep_serial, digit);
}
}
/* set tone pattern for port */
void EndpointAppPBX::set_tone(struct port_list *portlist, const char *tone)
{
struct lcr_msg *message;
if (!tone)
tone = "";
/* store for suspended processes */
SCPY(e_tone, tone);
if (e_join_pattern /* pattern are provided */
&& !(e_ext.own_setup && e_state == EPOINT_STATE_IN_SETUP)
&& !(e_ext.own_setup && e_state == EPOINT_STATE_IN_OVERLAP)
&& !(e_ext.own_proceeding && e_state == EPOINT_STATE_IN_PROCEEDING)
&& !(e_ext.own_alerting && e_state == EPOINT_STATE_IN_ALERTING)
&& !(e_ext.own_cause && e_state == EPOINT_STATE_IN_DISCONNECT)
&& !(e_ext.own_setup && e_state == EPOINT_STATE_OUT_SETUP)
&& !(e_ext.own_setup && e_state == EPOINT_STATE_OUT_OVERLAP)
&& !(e_ext.own_proceeding && e_state == EPOINT_STATE_OUT_PROCEEDING)
&& !(e_ext.own_alerting && e_state == EPOINT_STATE_OUT_ALERTING)
&& !(e_ext.own_cause && e_state == EPOINT_STATE_OUT_DISCONNECT)
&& tone[0] && !!strncmp(tone,"crypt_*",6)) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) tone not provided since patterns are available\n", ea_endpoint->ep_serial);
tone = "";
}
if (portlist) {
message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_TONE);
SCPY(message->param.tone.dir, e_ext.tones_dir);
SCPY(message->param.tone.name, tone);
message_put(message);
logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
} else {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) no port to notify tone.\n", ea_endpoint->ep_serial);
return;
}
}
/* outgoing setup to port(s)
* ports will be created and a setup is sent if everything is ok. otherwhise
* the endpoint is destroyed.
*/
void EndpointAppPBX::out_setup(int cfnr)
{
struct dialing_info dialinginfo;
class Port *port;
struct port_list *portlist;
struct lcr_msg *message;
int anycall = 0;
int cause = CAUSE_RESSOURCEUNAVAIL;
const char *p;
char cfp[64];
struct interface *interface;
#ifdef WITH_MISDN
struct mISDNport *mISDNport;
#endif
char portname[32];
char *dirname;
class EndpointAppPBX *atemp;
// char allowed_ports[256];
// char exten[256];
char ifname[sizeof(e_ext.interfaces)],
*ifname_p,
number[256],
*number_p;
struct port_settings port_settings;
#ifdef WITH_MISDN
int channel = 0;
#endif
struct admin_list *admin;
int earlyb;
int mode = B_MODE_TRANSPARENT;
/* set bchannel mode */
mode = e_capainfo.source_mode;
/* create settings for creating port */
memset(&port_settings, 0, sizeof(port_settings));
if (e_ext.tones_dir)
SCPY(port_settings.tones_dir, e_ext.tones_dir);
else
SCPY(port_settings.tones_dir, options.tones_dir);
port_settings.no_seconds = e_ext.no_seconds;
/* NOTE: currently the try_card feature is not supported. it should be used later to try another card, if the outgoing call fails on one port */
/* check what dialinginfo.itype we got */
switch(e_dialinginfo.itype) {
/* *********************** call to extension or vbox */
case INFO_ITYPE_ISDN_EXTENSION:
/* check if we deny incoming calls when we use an extension */
if (e_ext.noknocking) {
atemp = apppbx_first;
while(atemp) {
if (atemp != this)
if (!strcmp(atemp->e_ext.number, e_ext.number))
break;
atemp = atemp->next;
}
if (atemp) {
PERROR("EPOINT(%d) noknocking and currently a call\n", ea_endpoint->ep_serial);
release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_BUSY, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0); /* RELEASE_TYSPE_ join, port */
return; /* must exit here */
}
}
/* FALL THROUGH !!!! */
case INFO_ITYPE_VBOX:
/* get dialed extension's info */
// SCPY(exten, e_dialinginfo.id);
// if (strchr(exten, ','))
// *strchr(exten, ',') = '\0';
// if (!read_extension(&e_ext, exten))
if (!read_extension(&e_ext, e_dialinginfo.id)) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) extension %s not configured\n", ea_endpoint->ep_serial, e_dialinginfo.id);
release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_OUTOFORDER, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0); /* RELEASE_TYPE, join, port */
return; /* must exit here */
}
e_dialinginfo.sending_complete = 1;
if (e_dialinginfo.itype == INFO_ITYPE_VBOX) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) dialing directly to VBOX\n", ea_endpoint->ep_serial);
p = "vbox";
goto vbox_only;
}
/* string from unconditional call forward (cfu) */
p = e_ext.cfu;
if (*p) {
/* present to forwarded party */
if (e_ext.anon_ignore && e_callerinfo.id[0]) {
e_callerinfo.present = INFO_PRESENT_ALLOWED;
}
if (!!strcmp(p, "vbox") || (e_capainfo.bearer_capa==INFO_BC_AUDIO) || (e_capainfo.bearer_capa==INFO_BC_SPEECH))
goto cfu_only;
}
/* string from busy call forward (cfb) */
p = e_ext.cfb;
if (*p) {
class EndpointAppPBX *checkapp = apppbx_first;
while(checkapp) {
if (checkapp != this) { /* any other endpoint except our own */
if (!strcmp(checkapp->e_ext.number, e_ext.number)) {
/* present to forwarded party */
if (e_ext.anon_ignore && e_callerinfo.id[0]) {
e_callerinfo.present = INFO_PRESENT_ALLOWED;
}
if (!!strcmp(p, "vbox") || (e_capainfo.bearer_capa==INFO_BC_AUDIO) || (e_capainfo.bearer_capa==INFO_BC_SPEECH))
goto cfb_only;
}
}
checkapp = checkapp->next;
}
}
/* string from no-response call forward (cfnr) */
p = e_ext.cfnr;
if (*p) {
/* when cfnr is done, out_setup() will setup the call */
if (cfnr) {
/* present to forwarded party */
if (e_ext.anon_ignore && e_callerinfo.id[0]) {
e_callerinfo.present = INFO_PRESENT_ALLOWED;
}
goto cfnr_only;
}
if (!!strcmp(p, "vbox") || (e_capainfo.bearer_capa==INFO_BC_AUDIO) || (e_capainfo.bearer_capa==INFO_BC_SPEECH)) {
schedule_timer(&e_cfnr_timeout, e_ext.cfnr_delay, 0);
schedule_timer(&e_cfnr_call_timeout, e_ext.cfnr_delay + 1, 0); /* call one second after release */
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) setting time for call-forward-busy to %s with delay %ld.\n", ea_endpoint->ep_serial, e_ext.cfnr, e_ext.cfnr_delay);
}
}
/* call to all internal interfaces */
p = e_ext.interfaces;
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) generating multiple joins for extension %s to interfaces %s\n", ea_endpoint->ep_serial, e_dialinginfo.id, p);
while(*p) {
earlyb = 0;
ifname[0] = '\0';
while(*p!=',' && *p!='\0')
if (*p > ' ')
SCCAT(ifname, *p++);
if (*p == ',')
p++;
/* search interface */
interface = hunt_interface(ifname);
if (!interface) {
trace_header("INTERFACE (not found)", DIRECTION_NONE);
add_trace("interface", NULL, "%s", ifname);
end_trace();
continue;
}
/* found interface */
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) calling to interface %s\n", ea_endpoint->ep_serial, ifname);
if (interface->remote) {
admin = admin_first;
while(admin) {
if (admin->remote_name[0] && !strcmp(admin->remote_name, interface->remote_app))
break;
admin = admin->next;
}
if (!admin) {
trace_header("INTERFACE (remote not connected)", DIRECTION_NONE);
add_trace("application", NULL, "%s", interface->remote_app);
end_trace();
continue;
}
SPRINT(portname, "%s-%d-out", interface->name, 0);
port = new Premote(PORT_TYPE_REMOTE_OUT, portname, &port_settings, interface, admin->sock);
earlyb = (interface->is_earlyb == IS_YES);
} else
#ifdef WITH_GSM_BS
if (interface->gsm_bs) {
SPRINT(portname, "%s-%d-out", interface->name, 0);
port = new Pgsm_bs(PORT_TYPE_GSM_BS_OUT, portname, &port_settings, interface);
earlyb = (interface->is_earlyb == IS_YES);
} else
#endif
#ifdef WITH_GSM_MS
if (interface->gsm_ms) {
SPRINT(portname, "%s-%d-out", interface->name, 0);
port = new Pgsm_ms(PORT_TYPE_GSM_MS_OUT, portname, &port_settings, interface);
earlyb = (interface->is_earlyb == IS_YES);
} else
#endif
#ifdef WITH_SIP
if (interface->sip) {
SPRINT(portname, "%s-%d-out", interface->name, 0);
port = new Psip(PORT_TYPE_SIP_OUT, portname, &port_settings, interface);
earlyb = (interface->is_earlyb == IS_YES);
} else
#endif
{
#ifdef WITH_MISDN
/* hunt for mISDNport and create Port */
mISDNport = hunt_port(ifname, &channel);
if (!mISDNport) {
trace_header("INTERFACE (busy)", DIRECTION_NONE);
add_trace("interface", NULL, "%s", ifname);
end_trace();
continue;
}
SPRINT(portname, "%s-%d-out", mISDNport->ifport->interface->name, mISDNport->portnum);
#ifdef WITH_SS5
if (mISDNport->ss5)
port = ss5_hunt_line(mISDNport);
else
#endif
#ifdef ISDN_P_FXS_POTS
if (mISDNport->pots)
port = new Pfxs(PORT_TYPE_POTS_FXS_OUT, mISDNport, portname, &port_settings, mISDNport->ifport->interface, mode);
else
#endif
port = new Pdss1((mISDNport->ntmode)?PORT_TYPE_DSS1_NT_OUT:PORT_TYPE_DSS1_TE_OUT, mISDNport, portname, &port_settings, mISDNport->ifport->interface, channel, mISDNport->ifport->channel_force, mode);
earlyb = mISDNport->earlyb;
#else
trace_header("INTERFACE (has no function)", DIRECTION_NONE);
add_trace("interface", NULL, "%s", ifname);
end_trace();
continue;
#endif
}
if (!port)
FATAL("Failed to create Port instance\n");
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) got port %s\n", ea_endpoint->ep_serial, port->p_name);
memset(&dialinginfo, 0, sizeof(dialinginfo));
SCPY(dialinginfo.id, e_dialinginfo.id);
dialinginfo.itype = INFO_ITYPE_ISDN_EXTENSION;
dialinginfo.ntype = e_dialinginfo.ntype;
/* create port_list relation */
portlist = ea_endpoint->portlist_new(port->p_serial, port->p_type, earlyb);
if (!portlist) {
PERROR("EPOINT(%d) cannot allocate port_list relation\n", ea_endpoint->ep_serial);
delete port;
goto check_anycall_intern;
}
/* directory.list */
if (e_callerinfo.id[0] && e_ext.display_name) {
dirname = parse_directory(e_callerinfo.id, e_callerinfo.ntype);
if (dirname)
SCPY(e_callerinfo.name, dirname);
}
// dss1 = (class Pdss1 *)port;
/* message */
//printf("INTERNAL caller=%s,id=%s,dial=%s\n", param.setup.networkid, param.setup.callerinfo.id, param.setup.dialinginfo.id);
message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, 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));
memcpy(&message->param.setup.rtpinfo, &e_rtpinfo, sizeof(struct rtp_info));
//terminal SCPY(message->param.setup.from_terminal, e_ext.number);
//terminal if (e_dialinginfo.id)
//terminal SCPY(message->param.setup.to_terminal, e_dialinginfo.id);
/* handle restricted caller ids */
apply_callerid_restriction(&e_ext, message->param.setup.callerinfo.id, &message->param.setup.callerinfo.ntype, &message->param.setup.callerinfo.present, &message->param.setup.callerinfo.screen, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name);
apply_callerid_restriction(&e_ext, message->param.setup.callerinfo.id2, &message->param.setup.callerinfo.ntype2, &message->param.setup.callerinfo.present2, &message->param.setup.callerinfo.screen2, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name);
apply_callerid_restriction(&e_ext, message->param.setup.redirinfo.id, &message->param.setup.redirinfo.ntype, &message->param.setup.redirinfo.present, 0, message->param.setup.redirinfo.extension, NULL);
/* display callerid if desired for extension */
SCPY(message->param.setup.callerinfo.display, apply_callerid_display(message->param.setup.callerinfo.id, message->param.setup.callerinfo.itype, message->param.setup.callerinfo.ntype, message->param.setup.callerinfo.present, message->param.setup.callerinfo.screen, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name));
//printf("\n\ndisplay = %s\n\n\n",message->param.setup.callerinfo.display);
/* use cnip, if enabld */
// if (!e_ext.centrex)
// message->param.setup.callerinfo.name[0] = '\0';
/* screen clip if prefix is required */
if (message->param.setup.callerinfo.id[0] && e_ext.clip_prefix[0]) {
SCPY(message->param.setup.callerinfo.id, e_ext.clip_prefix);
SCAT(message->param.setup.callerinfo.id, numberrize_callerinfo(e_callerinfo.id,e_callerinfo.ntype, options.national, options.international));
message->param.setup.callerinfo.ntype = INFO_NTYPE_UNKNOWN;
}
if (message->param.setup.callerinfo.id2[0] && e_ext.clip_prefix[0]) {
SCPY(message->param.setup.callerinfo.id2, e_ext.clip_prefix);
SCAT(message->param.setup.callerinfo.id2, numberrize_callerinfo(e_callerinfo.id2,e_callerinfo.ntype2, options.national, options.international));
message->param.setup.callerinfo.ntype2 = INFO_NTYPE_UNKNOWN;
}
/* use internal caller id */
if (e_callerinfo.extension[0] && (message->param.setup.callerinfo.present!=INFO_PRESENT_RESTRICTED || e_ext.anon_ignore)) {
SCPY(message->param.setup.callerinfo.id, e_callerinfo.extension);
message->param.setup.callerinfo.ntype = INFO_NTYPE_UNKNOWN;
message->param.setup.callerinfo.ntype2 = INFO_NTYPE_NOTPRESENT;
}
message_put(message);
logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
anycall = 1;
}
/* string from parallel call forward (cfp) */
p = e_ext.cfp;
if (*p) {
if (e_ext.anon_ignore && e_callerinfo.id[0]) {
e_callerinfo.present = INFO_PRESENT_ALLOWED;
e_callerinfo.present2 = INFO_PRESENT_ALLOWED;
}
}
vbox_only: /* entry point for answering machine only */
cfu_only: /* entry point for cfu */
cfb_only: /* entry point for cfb */
cfnr_only: /* entry point for cfnr */
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) call extension %s for external destiantion(s) '%s'\n", ea_endpoint->ep_serial, e_dialinginfo.id, p);
// i=0;
while(*p) {
earlyb = 0;
/* only if vbox should be dialed, and terminal is given */
if (!strcmp(p, "vbox") && e_ext.number[0]) {
/* go to the end of p */
p += strlen(p);
/* answering vbox call */
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) answering machine\n", ea_endpoint->ep_serial);
/* alloc port */
if (!(port = new VBoxPort(PORT_TYPE_VBOX_OUT, &port_settings)))
FATAL("No memory for VBOX Port instance\n");
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) allocated port %s\n", ea_endpoint->ep_serial, port->p_name);
UCPY(cfp, e_ext.number); /* cfp or any other direct forward/vbox */
} else {
cfp[0] = '\0';
while(*p!=',' && *p!='\0')
SCCAT(cfp, *p++);
if (*p == ',')
p++;
/* external call */
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) cfp external %s\n", ea_endpoint->ep_serial, cfp);
#ifdef WITH_MISDN
/* hunt for mISDNport and create Port */
mISDNport = hunt_port(e_dialinginfo.interfaces[0]?e_dialinginfo.interfaces:NULL, &channel);
if (mISDNport) {
/* creating EXTERNAL port*/
SPRINT(portname, "%s-%d-out", mISDNport->ifport->interface->name, mISDNport->portnum);
#ifdef WITH_SS5
if (mISDNport->ss5)
port = ss5_hunt_line(mISDNport);
else
#endif
#ifdef ISDN_P_FXS_POTS
if (mISDNport->pots)
port = new Pfxs(PORT_TYPE_POTS_FXS_OUT, mISDNport, portname, &port_settings, mISDNport->ifport->interface, mode);
else
#endif
port = new Pdss1((mISDNport->ntmode)?PORT_TYPE_DSS1_NT_OUT:PORT_TYPE_DSS1_TE_OUT, mISDNport, portname, &port_settings, mISDNport->ifport->interface, channel, mISDNport->ifport->channel_force, mode);
if (!port)
FATAL("No memory for Port instance\n");
earlyb = mISDNport->earlyb;
} else
#endif
{
port = NULL;
trace_header("INTERFACE (too busy)", DIRECTION_NONE);
add_trace("interface", NULL, "%s", e_dialinginfo.interfaces[0]?e_dialinginfo.interfaces:"any interface");
end_trace();
}
}
if (!port) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) no port found or created, which is idle.\n", ea_endpoint->ep_serial);
goto check_anycall_intern;
}
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) found or created port %s\n", ea_endpoint->ep_serial, port->p_name);
memset(&dialinginfo, 0, sizeof(dialinginfo));
SCPY(dialinginfo.id, cfp);
dialinginfo.itype = INFO_ITYPE_ISDN;
dialinginfo.ntype = e_dialinginfo.ntype;
portlist = ea_endpoint->portlist_new(port->p_serial, port->p_type, earlyb);
if (!portlist) {
PERROR("EPOINT(%d) cannot allocate port_list relation\n", ea_endpoint->ep_serial);
delete port;
goto check_anycall_intern;
}
//printf("EXTERNAL caller=%s,id=%s,dial=%s\n", param.setup.networkid, param.setup.callerinfo.id, param.setup.dialinginfo.id);
message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, 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));
/* if clip is hidden */
if (e_ext.clip==CLIP_HIDE && port->p_type!=PORT_TYPE_VBOX_OUT) {
SCPY(message->param.setup.callerinfo.id, e_ext.callerid);
SCPY(message->param.setup.callerinfo.extension, e_ext.number);
message->param.setup.callerinfo.ntype = e_ext.callerid_type;
message->param.setup.callerinfo.present = e_ext.callerid_present;
message->param.setup.callerinfo.ntype = INFO_NTYPE_NOTPRESENT;
}
memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
//terminal SCPY(message->param.setup.from_terminal, e_ext.number);
//terminal if (e_dialinginfo.id)
//terminal SCPY(message->param.setup.to_terminal, e_dialinginfo.id);
/* handle restricted caller ids */
apply_callerid_restriction(&e_ext, message->param.setup.callerinfo.id, &message->param.setup.callerinfo.ntype, &message->param.setup.callerinfo.present, &message->param.setup.callerinfo.screen, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name);
apply_callerid_restriction(&e_ext, message->param.setup.callerinfo.id2, &message->param.setup.callerinfo.ntype2, &message->param.setup.callerinfo.present2, &message->param.setup.callerinfo.screen2, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name);
apply_callerid_restriction(&e_ext, message->param.setup.redirinfo.id, &message->param.setup.redirinfo.ntype, &message->param.setup.redirinfo.present, 0, message->param.setup.redirinfo.extension, NULL);
/* display callerid if desired for extension */
SCPY(message->param.setup.callerinfo.display, apply_callerid_display(message->param.setup.callerinfo.id, message->param.setup.callerinfo.itype, message->param.setup.callerinfo.ntype, message->param.setup.callerinfo.present, message->param.setup.callerinfo.screen, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name));
message_put(message);
logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
anycall = 1;
}
check_anycall_intern:
/* now we have all ports created */
if (!anycall) {
trace_header("INTERFACE (no extension's interface)", DIRECTION_NONE);
end_trace();
if (!ea_endpoint->ep_join_id)
break;
release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, cause, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0); /* RELEASE_TYPE, join, port */