work on chan_lcr
[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         {
35                 /* facility rejected */
36                 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
37                 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
38                 message->param.disconnectinfo.cause = CAUSE_FACILITYREJECTED;
39                 message_put(message);
40                 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
41                 new_state(EPOINT_STATE_OUT_DISCONNECT);
42                 set_tone(portlist,"cause_22");
43                 return;
44         }
45
46         /* connect */
47         new_state(EPOINT_STATE_CONNECT);
48
49         /* initialize the vbox */
50         PDEBUG(DEBUG_EPOINT, "EPOINT(%d) initializing efi\n", ea_endpoint->ep_serial);
51
52         e_efi_state = EFI_STATE_HELLO;
53         set_tone_efi("hello");
54
55         e_efi_digit = 0;
56 }
57
58 /*
59  * the audio file has ended
60  * this is called by Endpoint::message_port(), whenever an audio of has been received
61  */
62 void EndpointAppPBX::efi_message_eof(void)
63 {
64 //      char buffer[32];
65         char digit[] = "number_00";
66 //      struct lcr_msg          *message;
67 //      struct port_list        *portlist = ea_endpoint->ep_portlist;
68
69         PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s end of file during state: %d\n", ea_endpoint->ep_serial, e_ext.number, e_vbox_state);
70
71         switch(e_efi_state)
72         {
73                 case EFI_STATE_HELLO:
74                 e_efi_state = EFI_STATE_DIE;
75                 set_tone_efi("die");
76                 break;
77                 case EFI_STATE_DIE:
78                 if (e_callerinfo.screen==INFO_SCREEN_USER)
79                 {
80                         e_efi_state = EFI_STATE_BENUTZERDEFINIERTE;
81                         set_tone_efi("benutzerdefinierte");
82                         break;
83                 }
84                 // fall through
85                 case EFI_STATE_BENUTZERDEFINIERTE:
86                 if (e_callerinfo.present==INFO_PRESENT_RESTRICTED)
87                 {
88                         e_efi_state = EFI_STATE_UNTERDRUECKTE;
89                         set_tone_efi("unterdrueckte");
90                         break;
91                 }
92                 // fall through
93                 case EFI_STATE_UNTERDRUECKTE:
94                 e_efi_state = EFI_STATE_RUFNUMMER_LAUTET;
95                 set_tone_efi("rufnummer_lautet");
96                 break;
97
98                 case EFI_STATE_RUFNUMMER_LAUTET:
99                 e_efi_state = EFI_STATE_DIGIT;
100                 e_efi_digit = 0;
101                 // fall through
102                 case EFI_STATE_DIGIT:
103                 digit[8] = numberrize_callerinfo(e_callerinfo.id,e_callerinfo.ntype, options.national, options.international)[e_efi_digit];
104                 if (digit[8])
105                 {
106                         set_tone_efi(digit);
107                         e_efi_digit++;
108                 } else
109                 {
110 //                      e_efi_state = EFI_STATE_STOP;
111                         e_efi_state = EFI_STATE_ICH_WIEDERHOLE;
112 //                      message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
113 //                      message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
114 //                      message->param.disconnectinfo.cause = CAUSE_NORMAL;
115 //                      message_put(message);
116 //                      logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
117 //                      new_state(EPOINT_STATE_OUT_DISCONNECT);
118 //                      set_tone(portlist,"cause_10");
119                         set_tone_efi("ich_wiederhole");
120                 }
121                 break;
122
123                 case EFI_STATE_ICH_WIEDERHOLE:
124                 e_efi_state = EFI_STATE_DIE;
125                 set_tone_efi("die");
126                 break;
127
128                 case EFI_STATE_STOP:
129                 break;
130
131                 default:
132                 PERROR("efi_message_eof(ep%d): terminal %s unknown state: %d\n", ea_endpoint->ep_serial, e_ext.number, e_vbox_state);
133         }
134 }
135
136
137
138 /*
139  * set the given vbox-tone with full path (without appending)
140  * the tone is played and after eof, a message is received
141  */
142 void EndpointAppPBX::set_tone_efi(char *tone)
143 {
144         struct lcr_msg *message;
145
146         if (tone == NULL)
147                 tone = "";
148
149         if (!ea_endpoint->ep_portlist)
150         {
151                 PERROR("EPOINT(%d) no portlist\n", ea_endpoint->ep_serial);
152         }
153         message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_VBOX_TONE);
154         SCPY(message->param.tone.dir, (char *)"tones_efi");
155         SCPY(message->param.tone.name, tone);
156         message_put(message);
157
158         PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s set tone '%s'\n", ea_endpoint->ep_serial, e_ext.number, tone);
159 }
160