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