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