SIP: Fix incoming re-invite
[lcr.git] / action_efi.cpp
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** elektronische fernmelder identifikation                                   **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include "main.h"
13
14 enum {
15         EFI_STATE_HELLO,
16         EFI_STATE_DIE,
17         EFI_STATE_BENUTZERDEFINIERTE,
18         EFI_STATE_UNTERDRUECKTE,
19         EFI_STATE_RUFNUMMER_LAUTET,
20         EFI_STATE_DIGIT,
21         EFI_STATE_ICH_WIEDERHOLE,
22         EFI_STATE_STOP,
23 };
24
25 void EndpointAppPBX::action_init_efi(void)
26 {
27 //      int                     language = e_ext.vbox_language;
28 //      struct route_param      *rparam;
29         struct lcr_msg          *message;
30         struct port_list        *portlist = ea_endpoint->ep_portlist;
31
32         /* if no caller id */
33         if (e_callerinfo.id[0] == '\0') {
34                 /* facility rejected */
35                 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
36                 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
37                 message->param.disconnectinfo.cause = CAUSE_FACILITYREJECTED;
38                 message_put(message);
39                 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
40                 new_state(EPOINT_STATE_OUT_DISCONNECT);
41                 set_tone(portlist,"cause_22");
42                 return;
43         }
44
45         /* connect */
46         new_state(EPOINT_STATE_CONNECT);
47
48         /* initialize the vbox */
49         PDEBUG(DEBUG_EPOINT, "EPOINT(%d) initializing efi\n", ea_endpoint->ep_serial);
50
51         e_efi_state = EFI_STATE_HELLO;
52         set_tone_efi("hello");
53
54         e_efi_digit = 0;
55 }
56
57 /*
58  * the audio file has ended
59  * this is called by Endpoint::message_port(), whenever an audio of has been received
60  */
61 void EndpointAppPBX::efi_message_eof(void)
62 {
63 //      char buffer[32];
64         char digit[] = "number_00";
65 //      struct lcr_msg          *message;
66 //      struct port_list        *portlist = ea_endpoint->ep_portlist;
67
68         PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s end of file during state: %d\n", ea_endpoint->ep_serial, e_ext.number, e_vbox_state);
69
70         switch(e_efi_state) {
71                 case EFI_STATE_HELLO:
72                 e_efi_state = EFI_STATE_DIE;
73                 set_tone_efi("die");
74                 break;
75                 case EFI_STATE_DIE:
76                 if (e_callerinfo.screen==INFO_SCREEN_USER) {
77                         e_efi_state = EFI_STATE_BENUTZERDEFINIERTE;
78                         set_tone_efi("benutzerdefinierte");
79                         break;
80                 }
81                 // fall through
82                 case EFI_STATE_BENUTZERDEFINIERTE:
83                 if (e_callerinfo.present==INFO_PRESENT_RESTRICTED) {
84                         e_efi_state = EFI_STATE_UNTERDRUECKTE;
85                         set_tone_efi("unterdrueckte");
86                         break;
87                 }
88                 // fall through
89                 case EFI_STATE_UNTERDRUECKTE:
90                 e_efi_state = EFI_STATE_RUFNUMMER_LAUTET;
91                 set_tone_efi("rufnummer_lautet");
92                 break;
93
94                 case EFI_STATE_RUFNUMMER_LAUTET:
95                 e_efi_state = EFI_STATE_DIGIT;
96                 e_efi_digit = 0;
97                 // fall through
98                 case EFI_STATE_DIGIT:
99                 digit[8] = numberrize_callerinfo(e_callerinfo.id,e_callerinfo.ntype, options.national, options.international)[e_efi_digit];
100                 if (digit[8]) {
101                         set_tone_efi(digit);
102                         e_efi_digit++;
103                 } else {
104 //                      e_efi_state = EFI_STATE_STOP;
105                         e_efi_state = EFI_STATE_ICH_WIEDERHOLE;
106 //                      message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
107 //                      message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
108 //                      message->param.disconnectinfo.cause = CAUSE_NORMAL;
109 //                      message_put(message);
110 //                      logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
111 //                      new_state(EPOINT_STATE_OUT_DISCONNECT);
112 //                      set_tone(portlist,"cause_10");
113                         set_tone_efi("ich_wiederhole");
114                 }
115                 break;
116
117                 case EFI_STATE_ICH_WIEDERHOLE:
118                 e_efi_state = EFI_STATE_DIE;
119                 set_tone_efi("die");
120                 break;
121
122                 case EFI_STATE_STOP:
123                 break;
124
125                 default:
126                 PERROR("efi_message_eof(ep%d): terminal %s unknown state: %d\n", ea_endpoint->ep_serial, e_ext.number, e_vbox_state);
127         }
128 }
129
130
131
132 /*
133  * set the given vbox-tone with full path (without appending)
134  * the tone is played and after eof, a message is received
135  */
136 void EndpointAppPBX::set_tone_efi(const char *tone)
137 {
138         struct lcr_msg *message;
139
140         if (tone == NULL)
141                 tone = "";
142
143         if (!ea_endpoint->ep_portlist) {
144                 PERROR("EPOINT(%d) no portlist\n", ea_endpoint->ep_serial);
145         }
146         message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_VBOX_TONE);
147         SCPY(message->param.tone.dir, (char *)"tones_efi");
148         SCPY(message->param.tone.name, tone);
149         message_put(message);
150
151         PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s set tone '%s'\n", ea_endpoint->ep_serial, e_ext.number, tone);
152 }
153