1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** dialing for answering machine is processed here **
10 \*****************************************************************************/
15 // note: the given display message (e_vbox_display) may include "%s" for the counter
18 * these are the state, the vbox is in. if the current tone has been played,
19 * an action will be calles as defined in vbox_message_eof(), which is called
20 * from Epoint:handler().
21 * also this state is used to determine the correct processing of the current key press
24 VBOX_STATE_MENU, /* tell the menu */
25 VBOX_STATE_CALLINFO_BEGIN, /* this value defines the start of callinfo */
26 VBOX_STATE_CALLINFO_INTRO, /* tell that the "call is received at" */
27 VBOX_STATE_CALLINFO_MONTH, /* tell the month */
28 VBOX_STATE_CALLINFO_DAY, /* tell the day */
29 VBOX_STATE_CALLINFO_HOUR, /* tell the hour */
30 VBOX_STATE_CALLINFO_OCLOCK, /* tell the word "o'clock" */
31 VBOX_STATE_CALLINFO_MIN, /* tell the minute */
32 VBOX_STATE_CALLINFO_MINUTES, /* tell the word "minutes" */
33 VBOX_STATE_CALLINFO_DIGIT, /* tell the digits */
34 VBOX_STATE_CALLINFO_END, /* this value defines the end of callingo */
35 VBOX_STATE_NOTHING, /* tells that no calls are recorded */
36 VBOX_STATE_PLAY, /* play the current recording */
37 VBOX_STATE_PAUSE, /* tell that the recording is paused */
38 VBOX_STATE_RECORD_ASK, /* ask for recording */
39 VBOX_STATE_RECORD_PLAY, /* play recording */
40 VBOX_STATE_RECORD_RECORD, /* record recording */
41 VBOX_STATE_STORE_ASK, /* ask for store */
42 VBOX_STATE_DELETE_ASK, /* ask for delete */
43 VBOX_STATE_STORE_DONE, /* tell that message is store */
44 VBOX_STATE_DELETE_DONE, /* tell that message is delete */
47 const char *months_english[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
48 const char *months_german[] = {"Jan","Feb","Maer","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"};
55 {'1', "<< previous", "<< zurueck"},
56 {'2', "-> play", "-> anhoeren"},
57 {'3', ">> next", ">> vor"},
58 {'4', "< rewind", "< rueckspulen"},
59 {'5', "[] stop", "[] stop"},
60 {'6', "> wind", "> vorspulen"},
61 {'7', "() record", "() Aufnahme"},
62 {'8', "= store", "= speichern"},
63 {'9', "X delete", "X loeschen"},
64 {'0', "* call", "* anrufen"},
69 * initialize the vbox. this is called at process_dialing(), when the VBOX_PLAY
70 * action has been selected by the caller
72 void EndpointAppPBX::action_init_vbox_play(void)
74 int language = e_ext.vbox_language;
75 struct route_param *rparam;
76 struct lcr_msg *message;
77 struct port_list *portlist = ea_endpoint->ep_portlist;
80 SCPY(e_vbox, e_ext.number);
81 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
82 SCPY(e_vbox, rparam->string_value);
83 if (e_vbox[0] == '\0') {
84 /* facility rejected */
85 message_disconnect_port(portlist, CAUSE_FACILITYREJECTED, LOCATION_PRIVATE_LOCAL, "");
86 new_state(EPOINT_STATE_OUT_DISCONNECT);
87 set_tone(portlist,"cause_22");
91 /* connect, but still accept more digits */
92 new_state(EPOINT_STATE_IN_OVERLAP);
95 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
97 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
99 /* initialize the vbox */
100 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) initializing answering vbox state\n", ea_endpoint->ep_serial);
102 e_vbox_state = VBOX_STATE_MENU;
103 SCPY(e_vbox_display, (char *)((language)?"druecke 2 f. wiedergabe":"press 2 to play"));
104 e_vbox_display_refresh = 1;
105 set_tone_vbox("menu");
109 vbox_index_read(e_vbox_play);
110 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) number of calls: %d\n", ea_endpoint->ep_serial, e_vbox_index_num);
112 if (e_vbox_index_num == 0) {
113 e_vbox_state = VBOX_STATE_NOTHING;
114 SCPY(e_vbox_display, (char *)((language)?"keine Anrufe":"no calls"));
115 e_vbox_display_refresh = 1;
116 set_tone_vbox("nothing");
121 * read index list, and fill the index variables with the given position
122 * if the index is empty (or doesn't exist), the variables are not filled.
123 * but alway the e_vbox_index_num is given.
125 void EndpointAppPBX::vbox_index_read(int num)
130 char name[sizeof(buffer)];
131 char callerid[sizeof(buffer)];
132 int year, mon, mday, hour, min;
135 e_vbox_index_num = 0;
137 SPRINT(filename, "%s/%s/vbox/index", EXTENSION_DATA, e_vbox);
138 if (!(fp = fopen(filename, "r"))) {
139 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) no files in index\n", ea_endpoint->ep_serial);
145 while((GETLINE(buffer, fp))) {
146 name[0] = callerid[0] = '\0';
147 mon = mday = hour = min = 0;
148 sscanf(buffer, "%s %d %d %d %d %d %s", name, &year, &mon, &mday, &hour, &min, callerid);
150 if (name[0]=='\0' || name[0]=='#')
153 /* the selected entry */
155 SCPY(e_vbox_index_file, name);
156 e_vbox_index_year = year;
157 e_vbox_index_mon = mon;
158 e_vbox_index_mday = mday;
159 e_vbox_index_hour = hour;
160 e_vbox_index_min = min;
161 SCPY(e_vbox_index_callerid, callerid);
162 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) read entry #%d: '%s', %02d:%02d %02d:%02d cid='%s'\n", ea_endpoint->ep_serial, i, name, mon+1, mday, hour, min, callerid);
168 e_vbox_index_num = i;
176 * removes given index from list
177 * after removing, the list should be reread, since e_vbox_index_num
178 * and the current variabled do not change
180 void EndpointAppPBX::vbox_index_remove(int num)
185 char filename1[256], filename2[256];
187 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) removing entrie #%d\n", ea_endpoint->ep_serial, num);
189 SPRINT(filename1, "%s/%s/vbox/index", EXTENSION_DATA, e_vbox);
190 SPRINT(filename2, "%s/%s/vbox/index-temp", EXTENSION_DATA, e_vbox);
191 if (!(fpr = fopen(filename1, "r"))) {
194 if (!(fpw = fopen(filename2, "w"))) {
201 while((fgets(buffer,sizeof(buffer),fpr))) {
202 buffer[sizeof(buffer)-1] = '\0';
203 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
205 if (buffer[0]=='\0' || buffer[0]=='#') {
206 fprintf(fpw, "%s\n", buffer);
210 /* the selected entry will not be written */
212 fprintf(fpw, "%s\n", buffer);
222 rename(filename2, filename1);
227 * process dialing of vbox_play (actually the menu)
228 * it is depended by the state, which action is performed
230 void EndpointAppPBX::action_dialing_vbox_play(void)
232 int language = e_ext.vbox_language;
233 struct port_list *portlist;
236 portlist = ea_endpoint->ep_portlist;
238 if (e_extdialing[0] == '\0') {
239 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) called with no digit\n", ea_endpoint->ep_serial);
243 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) dialing digit: %c\n", ea_endpoint->ep_serial, e_extdialing[0]);
245 e_vbox_display_refresh = 1;
247 if (e_vbox_state == VBOX_STATE_RECORD_RECORD) {
248 if (e_extdialing[0] == '1' || e_extdialing[0] == '0') {
249 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) stopping recording of announcement.\n", ea_endpoint->ep_serial);
251 port = find_port_id(portlist->port_id);
253 port->close_record((e_extdialing[0]=='1')?6000:0, 2000); /* append beep */
259 if (e_vbox_state == VBOX_STATE_RECORD_PLAY) {
260 if (e_extdialing[0] == '1') {
261 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) stopping playback of announcement.\n", ea_endpoint->ep_serial);
268 if (e_vbox_state == VBOX_STATE_RECORD_ASK) {
269 switch(e_extdialing[0]) {
271 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) quit recoding menu.\n", ea_endpoint->ep_serial);
274 e_vbox_state = VBOX_STATE_MENU;
275 SCPY(e_vbox_display, (char *)((language)?"druecke 2 f. wiedergabe":"press 2 to play"));
276 set_tone_vbox("menu");
280 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) play recoding.\n", ea_endpoint->ep_serial);
281 /* play announcement */
283 e_vbox_counter_last = 0;
284 e_vbox_counter_max = 0;
286 e_vbox_state = VBOX_STATE_RECORD_PLAY;
287 if (e_ext.vbox_language)
288 SCPY(e_vbox_display, "Wied., 1=stop %s");
290 SCPY(e_vbox_display, "play, 1=stop %s");
291 if (e_ext.vbox_display == VBOX_DISPLAY_BRIEF)
292 SCPY(e_vbox_display, "1=stop %s");
293 set_play_vbox("announcement", 0);
297 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) record announcement.\n", ea_endpoint->ep_serial);
298 /* close recording if already recording */
299 port = find_port_id(portlist->port_id);
301 port->close_record(0,0);
302 port->open_record(CODEC_MONO, 1, 4000, e_ext.number, 0, "", 0); /* record announcement, skip the first 4000 samples */
304 e_vbox_state = VBOX_STATE_RECORD_RECORD;
305 if (e_ext.vbox_language)
306 SCPY(e_vbox_display, "Aufnahme, 1=stop");
308 SCPY(e_vbox_display, "recording, 1=stop");
318 if (e_vbox_state==VBOX_STATE_STORE_ASK || e_vbox_state==VBOX_STATE_DELETE_ASK) {
319 char filename[256], filename2[256];
321 switch(e_extdialing[0]) {
323 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) quit store/delete menu.\n", ea_endpoint->ep_serial);
327 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) do store/delete.\n", ea_endpoint->ep_serial);
328 SPRINT(filename, "%s/%s/vbox/%s", EXTENSION_DATA, e_vbox, e_vbox_index_file);
331 if (e_vbox_state == VBOX_STATE_STORE_ASK) {
332 SPRINT(filename, "%s/%s/recordings", EXTENSION_DATA, e_vbox);
333 if (mkdir(filename, 0755) < 0) {
334 if (errno != EEXIST) {
335 PERROR("EPOINT(%d) cannot create directory '%s'\n", ea_endpoint->ep_serial, filename);
339 SPRINT(filename2, "%s/%s/recordings/%s", EXTENSION_DATA, e_vbox, e_vbox_index_file);
340 rename(filename, filename2);
341 e_vbox_state = VBOX_STATE_STORE_DONE;
342 if (e_ext.vbox_language)
343 SCPY(e_vbox_display, "Nachricht gespeichert!");
345 SCPY(e_vbox_display, "Message stored!");
346 set_tone_vbox("store_done");
350 if (e_vbox_state == VBOX_STATE_DELETE_ASK) {
352 e_vbox_state = VBOX_STATE_DELETE_DONE;
353 if (e_ext.vbox_language)
354 SCPY(e_vbox_display, "Nachricht geloescht!");
356 SCPY(e_vbox_display, "Message deleted!");
357 set_tone_vbox("delete_done");
360 /* remove from list */
361 vbox_index_remove(e_vbox_play);
362 vbox_index_read(e_vbox_play);
363 /* stay at the last message+1, so we always get "no messages" */
364 if (e_vbox_play>e_vbox_index_num && e_vbox_play) {
365 e_vbox_play = e_vbox_index_num-1;
373 /* dialing during menu */
374 switch(e_extdialing[0]) {
375 /* process the vbox functions */
376 case '1': /* previous */
377 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) previous call is selected.\n", ea_endpoint->ep_serial);
378 if (e_vbox_index_num == 0) { /* nothing to play */
380 e_vbox_state = VBOX_STATE_MENU;
381 SCPY(e_vbox_display, (char *)((language)?"keine Anrufe":"no calls"));
382 set_tone_vbox("nothing");
386 if (e_vbox_play < 0) {
389 e_vbox_state = VBOX_STATE_MENU;
390 SCPY(e_vbox_display, (char *)((language)?"kein vorheriger Anruf":"no previous call"));
391 set_tone_vbox("nothing");
396 e_vbox_state = VBOX_STATE_CALLINFO_INTRO;
397 SPRINT(e_vbox_display, "#%d", e_vbox_play+1);
398 vbox_index_read(e_vbox_play);
399 if (e_vbox_index_mon!=now_tm->tm_mon || e_vbox_index_year!=now_tm->tm_year) {
400 UPRINT(strchr(e_vbox_display,'\0'), " %s", (language)?months_german[e_vbox_index_mon]:months_english[e_vbox_index_mon]);
402 if (e_vbox_index_mday!=now_tm->tm_mday || e_vbox_index_mon!=now_tm->tm_mon || e_vbox_index_year!=now_tm->tm_year) {
403 UPRINT(strchr(e_vbox_display,'\0'), " %d", e_vbox_index_mday);
405 UPRINT(strchr(e_vbox_display,'\0'), " %02d:%02d", e_vbox_index_hour, e_vbox_index_min);
406 if (e_ext.vbox_display == VBOX_DISPLAY_DETAILED)
407 UPRINT(strchr(e_vbox_display,'\0'), " (%s)", e_vbox_index_callerid);
408 set_tone_vbox("intro");
412 if (e_vbox_play >= e_vbox_index_num)
414 if (e_vbox_index_num == 0) { /* nothing to play */
417 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) play call #%d.\n", ea_endpoint->ep_serial, e_vbox_play+1);
418 if (e_vbox_state>VBOX_STATE_CALLINFO_BEGIN && e_vbox_state<VBOX_STATE_CALLINFO_END) {
419 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) play call #%d. abborting announcement and starting with playback\n", ea_endpoint->ep_serial, e_vbox_play+1);
420 /* the callinfo is played, so we start with the call */
422 e_vbox_counter_last = 0;
423 e_vbox_counter_max = 0;
425 e_vbox_state = VBOX_STATE_PLAY;
426 SPRINT(e_vbox_display, "#%d %%s", e_vbox_play+1);
427 if (e_ext.vbox_display == VBOX_DISPLAY_DETAILED)
428 UPRINT(strchr(e_vbox_display,'\0'), " (%s)", e_vbox_index_callerid);
429 set_play_vbox(e_vbox_index_file, 0);
432 if (e_vbox_state==VBOX_STATE_PLAY && e_vbox_speed!=1) {
433 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) play call #%d. play speed is different from 1, so we play now with normal speed\n", ea_endpoint->ep_serial, e_vbox_play+1);
434 /* we set play speed to normal */
436 set_play_speed(e_vbox_speed);
438 if (e_vbox_state == VBOX_STATE_PLAY) {
439 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) play call #%d. play speed is equals 1, so we pause\n", ea_endpoint->ep_serial, e_vbox_play+1);
440 /* we pause the current play */
441 e_vbox_state = VBOX_STATE_PAUSE;
442 SCPY(e_vbox_display, (char *)((language)?"druecke 2 f. wiedergabe":"press 2 to play"));
443 set_tone_vbox("pause");
445 if (e_vbox_state == VBOX_STATE_PAUSE) {
446 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) play call #%d. currently pause, so we continue play\n", ea_endpoint->ep_serial, e_vbox_play+1);
447 /* we continue the current play */
448 e_vbox_state = VBOX_STATE_PLAY;
449 SPRINT(e_vbox_display, "#%d %%s", e_vbox_play+1);
450 if (e_ext.vbox_display == VBOX_DISPLAY_DETAILED)
451 UPRINT(strchr(e_vbox_display,'\0'), " (%s)", e_vbox_index_callerid);
452 set_play_vbox(e_vbox_index_file, e_vbox_counter);
454 /* now we have something else going on, so we announce the call */
455 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) play call #%d. announcing call during any other state\n", ea_endpoint->ep_serial, e_vbox_play+1);
461 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) next call is selected.\n", ea_endpoint->ep_serial);
462 if (e_vbox_index_num == 0) { /* nothing to play */
466 if (e_vbox_play >= e_vbox_index_num) {
468 e_vbox_play = e_vbox_index_num;
470 e_vbox_state = VBOX_STATE_MENU;
471 SCPY(e_vbox_display, (char *)((language)?"kein weiterer Anruf":"no next call"));
472 set_tone_vbox("nothing");
479 case '4': /* rewind */
480 if (e_vbox_state==VBOX_STATE_PLAY) {
481 if (e_vbox_speed >= -1)
483 e_vbox_speed = e_vbox_speed * 2;
484 set_play_speed(e_vbox_speed);
485 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) rewind speed has been changed to: %d\n", ea_endpoint->ep_serial, e_vbox_speed);
490 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) stop is pressed, so we hear the menu\n", ea_endpoint->ep_serial);
491 e_vbox_state = VBOX_STATE_MENU;
492 SCPY(e_vbox_display, (char *)((language)?"druecke 2 f. wiedergabe":"press 2 to play"));
493 set_tone_vbox("menu");
497 if (e_vbox_state==VBOX_STATE_PLAY) {
498 if (e_vbox_speed <= 1)
500 e_vbox_speed = e_vbox_speed * 2;
501 set_play_speed(e_vbox_speed);
502 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) wind speed has been changed to: %d\n", ea_endpoint->ep_serial, e_vbox_speed);
506 case '7': /* record announcement */
507 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) entering the record announcement menu\n", ea_endpoint->ep_serial);
509 e_vbox_state = VBOX_STATE_RECORD_ASK;
510 SCPY(e_vbox_display, (char *)((language)?"1=Aufn. 2=Wied. 3=nein":"1=record 2=play 3=back"));
511 set_tone_vbox("record_ask");
514 case '8': /* store file */
515 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) entering the store menu\n", ea_endpoint->ep_serial);
516 if (e_vbox_play >= e_vbox_index_num)
518 if (e_vbox_index_num == 0) { /* nothing to play */
521 e_vbox_state = VBOX_STATE_STORE_ASK;
522 SCPY(e_vbox_display, (char *)((language)?"speichern 1=ja 3=nein":"store 1=yes 3=back"));
523 set_tone_vbox("store_ask");
526 case '9': /* delete file */
527 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) entering the delete menu\n", ea_endpoint->ep_serial);
528 if (e_vbox_play >= e_vbox_index_num)
530 if (e_vbox_index_num == 0) { /* nothing to play */
533 e_vbox_state = VBOX_STATE_DELETE_ASK;
534 SCPY(e_vbox_display, (char *)((language)?"loeschen 1=ja 3=nein":"delete 1=yes 3=back"));
535 set_tone_vbox("delete_ask");
539 /* process the menu */
545 if (vbox_menu[e_vbox_menu].english == NULL)
549 SPRINT(e_vbox_display, "%c: %s", vbox_menu[e_vbox_menu].digit, (language)?vbox_menu[e_vbox_menu].german:vbox_menu[e_vbox_menu].english);
553 if (e_vbox_menu < 0) { /* only if menu selection is pressed before*/
554 /* call if phonenumber is given */
555 if (e_vbox_index_num)
556 if (e_vbox_index_callerid[0]!='\0' && !!strcmp(e_vbox_index_callerid,"anonymous") && !!strcmp(e_vbox_index_callerid,"unknown")) {
557 set_tone(portlist, "dialing");
558 SPRINT(e_dialinginfo.id, "extern:%s", e_vbox_index_callerid);
559 e_extdialing = e_dialinginfo.id;
566 e_extdialing[0] = vbox_menu[e_vbox_menu].digit;
567 e_extdialing[1] = '\0';
569 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) executing selected menu:%d\n", e_extdialing[0]);
570 action_dialing_vbox_play(); /* redo this method using the digit */
579 while(vbox_menu[e_vbox_menu+1].english) /* jump to the end */
586 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) unsupported digit '%c'\n", ea_endpoint->ep_serial, e_extdialing);
590 /* reset menu after dialing a function */
591 if (e_extdialing[0]!='*' && e_extdialing[0]!='#')
595 e_extdialing[0] = '\0';
601 * this handler is called by Epoint::handler(), whenever the action is NUMB_ACTION_VBOX_PLAY
603 void EndpointAppPBX::vbox_handler(void)
605 /* refresh if counter changes */
606 if (e_vbox_state==VBOX_STATE_PLAY || e_vbox_state==VBOX_STATE_RECORD_PLAY)
607 if (e_vbox_counter != e_vbox_counter_last) {
608 e_vbox_counter_last = e_vbox_counter;
609 e_vbox_display_refresh = 1;
612 /* refresh display, if required (include counter) */
613 if (e_vbox_display_refresh && e_ext.vbox_display!=VBOX_DISPLAY_OFF) {
615 struct lcr_msg *message;
617 SPRINT(counter, "%02d:%02d", e_vbox_counter/60, e_vbox_counter%60);
618 if (e_vbox_counter_max)
619 UPRINT(strchr(counter,'\0'), " of %02d:%02d", e_vbox_counter_max/60, e_vbox_counter_max%60);
621 e_vbox_display_refresh = 0;
622 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
623 SPRINT(message->param.notifyinfo.display, e_vbox_display, counter);
624 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s pending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
625 message_put(message);
626 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
632 * the audio file has ended
633 * this is called by Endpoint::message_port(), whenever an audio of has been received
635 void EndpointAppPBX::vbox_message_eof(void)
638 int language = e_ext.vbox_language;
640 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s end of file during state: %d\n", ea_endpoint->ep_serial, e_ext.number, e_vbox_state);
642 switch(e_vbox_state) {
643 case VBOX_STATE_MENU:
644 case VBOX_STATE_NOTHING:
645 e_vbox_state = VBOX_STATE_MENU;
646 SCPY(e_vbox_display, (char *)((language)?"druecke 2 f. wiedergabe":"press 2 to play"));
647 e_vbox_display_refresh = 1;
648 set_tone_vbox("menu");
651 case VBOX_STATE_PLAY:
652 if (e_vbox_speed > 0) {
653 e_vbox_state = VBOX_STATE_MENU;
654 SCPY(e_vbox_display, (char *)((language)?"druecke 3 f. Naechste":"press 3 for next"));
655 e_vbox_display_refresh = 1;
656 set_tone_vbox("menu");
658 /* if we have endoffile because we were playing backwards, we continue to play forward */
661 set_play_vbox(e_vbox_index_file, e_vbox_counter);
665 case VBOX_STATE_PAUSE:
666 SCPY(e_vbox_display, (char *)((language)?"druecke 2 f. weiterspielen":"press 2 to continue"));
667 e_vbox_display_refresh = 1;
670 case VBOX_STATE_CALLINFO_INTRO:
671 if (e_vbox_index_mday==now_tm->tm_mday && e_vbox_index_mon==now_tm->tm_mon && e_vbox_index_year==now_tm->tm_year)
673 e_vbox_state = VBOX_STATE_CALLINFO_MONTH; //german day
674 if (e_ext.vbox_language)
675 /* german starts with day */
676 SPRINT(buffer, "day_%02d", e_vbox_index_mday);
678 /* english starts with month */
679 SPRINT(buffer, "month_%02d", e_vbox_index_mon+1);
680 set_tone_vbox(buffer);
683 case VBOX_STATE_CALLINFO_MONTH:
684 e_vbox_state = VBOX_STATE_CALLINFO_DAY; //german month
685 if (e_ext.vbox_language) {
686 /* done with month, so we send the month*/
687 SPRINT(buffer, "month_%02d", e_vbox_index_mon+1);
689 /* done with day, so we send the day */
690 SPRINT(buffer, "day_%02d", e_vbox_index_mday);
692 set_tone_vbox(buffer);
695 case VBOX_STATE_CALLINFO_DAY: //german month
697 e_vbox_state = VBOX_STATE_CALLINFO_HOUR;
698 if (e_ext.vbox_language) {
699 if (e_vbox_index_hour == 1)
700 SCPY(buffer, "number_ein");
702 SPRINT(buffer, "number_%02d", e_vbox_index_hour); /* 1-23 hours */
704 SPRINT(buffer, "number_%02d", ((e_vbox_index_hour+11)%12)+1); /* 12 hours am/pm */
706 set_tone_vbox(buffer);
709 case VBOX_STATE_CALLINFO_HOUR:
710 e_vbox_state = VBOX_STATE_CALLINFO_OCLOCK;
711 if (e_ext.vbox_language) {
712 set_tone_vbox("oclock");
714 if (e_vbox_index_hour >= 12)
715 set_tone_vbox("oclock_pm");
717 set_tone_vbox("oclock_am");
721 case VBOX_STATE_CALLINFO_OCLOCK:
722 e_vbox_state = VBOX_STATE_CALLINFO_MIN;
723 if (e_ext.vbox_language) {
724 // german says "zwölfuhr und eins"
725 // if (e_vbox_index_min == 1)
726 // SCPY(buffer, "number_eine");
728 SPRINT(buffer, "number_%02d", e_vbox_index_min); /* 1-59 minutes */
730 SPRINT(buffer, "number_%02d", e_vbox_index_min);
732 set_tone_vbox(buffer);
735 case VBOX_STATE_CALLINFO_MIN:
736 if (e_ext.vbox_language)
738 e_vbox_state = VBOX_STATE_CALLINFO_MINUTES;
739 if (e_vbox_index_mday == 1)
740 set_tone_vbox("minute");
742 set_tone_vbox("minutes");
745 case VBOX_STATE_CALLINFO_MINUTES:
747 e_vbox_state = VBOX_STATE_CALLINFO_DIGIT;
748 if (e_vbox_index_callerid[0]=='\0' || !strcmp(e_vbox_index_callerid,"anonymous") || !strcmp(e_vbox_index_callerid,"unknown")) {
749 set_tone_vbox("call_anonymous");
750 e_vbox_index_callerid_index = strlen(e_vbox_index_callerid);
752 set_tone_vbox("call_from");
753 e_vbox_index_callerid_index = 0;
757 case VBOX_STATE_CALLINFO_DIGIT:
758 while (e_vbox_index_callerid[e_vbox_index_callerid_index] && (e_vbox_index_callerid[e_vbox_index_callerid_index]<'0' || e_vbox_index_callerid[e_vbox_index_callerid_index]>'9'))
759 e_vbox_index_callerid_index++;
760 if (e_vbox_index_callerid[e_vbox_index_callerid_index]) {
761 SPRINT(buffer, "number_%02d", e_vbox_index_callerid[e_vbox_index_callerid_index]-'0');
762 set_tone_vbox(buffer);
763 e_vbox_index_callerid_index ++;
765 /* the callinfo is played, so we start with the call */
767 e_vbox_counter_last = 0;
768 e_vbox_counter_max = 0;
770 e_vbox_state = VBOX_STATE_PLAY;
771 SPRINT(e_vbox_display, "#%d %%s", e_vbox_play);
772 if (e_ext.vbox_display == VBOX_DISPLAY_DETAILED)
773 UPRINT(strchr(e_vbox_display,'\0'), " (%s)", e_vbox_index_callerid);
774 e_vbox_display_refresh = 1;
775 set_play_vbox(e_vbox_index_file, 0);
779 case VBOX_STATE_RECORD_ASK:
780 set_tone_vbox("record_ask");
781 e_vbox_display_refresh = 1;
784 case VBOX_STATE_STORE_ASK:
785 set_tone_vbox("store_ask");
786 e_vbox_display_refresh = 1;
789 case VBOX_STATE_DELETE_ASK:
790 set_tone_vbox("delete_ask");
791 e_vbox_display_refresh = 1;
794 case VBOX_STATE_RECORD_PLAY:
795 e_vbox_state = VBOX_STATE_RECORD_ASK;
796 SCPY(e_vbox_display, (char *)((language)?"1=Aufn. 2=Wied. 3=nein":"1=record 2=play 3=no"));
797 e_vbox_display_refresh = 1;
798 set_tone_vbox("record_ask");
801 case VBOX_STATE_STORE_DONE:
802 case VBOX_STATE_DELETE_DONE:
803 if (e_vbox_index_num == 0) { /* nothing to play */
804 e_vbox_state = VBOX_STATE_MENU;
805 SCPY(e_vbox_display, (char *)((language)?"keine Anrufe":"no calls"));
806 e_vbox_display_refresh = 1;
807 set_tone_vbox("nothing");
809 e_vbox_state = VBOX_STATE_MENU;
810 SCPY(e_vbox_display, (char *)((language)?"druecke 2 f. wiedergabe":"press 2 to play"));
811 e_vbox_display_refresh = 1;
812 set_tone_vbox("menu");
817 PERROR("vbox_message_eof(ep%d): terminal %s unknown state: %d\n", ea_endpoint->ep_serial, e_ext.number, e_vbox_state);
824 * set the given vbox-tone with full path (without appending)
825 * the tone is played and after eof, a message is received
827 void EndpointAppPBX::set_tone_vbox(const char *tone)
829 struct lcr_msg *message;
834 if (!ea_endpoint->ep_portlist) {
835 PERROR("EPOINT(%d) no portlist\n", ea_endpoint->ep_serial);
837 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_VBOX_TONE);
838 SCPY(message->param.tone.dir, ((e_ext.vbox_language) ? "vbox_german" : "vbox_english"));
839 SCPY(message->param.tone.name, tone);
840 message_put(message);
842 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s set tone '%s'\n", ea_endpoint->ep_serial, e_ext.number, tone);
847 * set the given recording file
848 * the appendix is removed
849 * the file is played and after eof, a message is received
850 * the current counter value is also received by a message
851 * set the offset in seconds of the current recording
853 void EndpointAppPBX::set_play_vbox(const char *file, int offset)
856 struct lcr_msg *message;
858 SPRINT(filename, "%s/%s/vbox/%s", EXTENSION_DATA, e_vbox, file);
861 if (!strcmp(filename+strlen(filename)-4, ".wav")) /* filename is always more than 4 digits long */
862 filename[strlen(filename)-4] = '\0';
863 else // to not check twice
865 if (!strcmp(filename+strlen(filename)-5, ".isdn")) /* filename is always more than 5 digits long */
866 filename[strlen(filename)-5] = '\0';
868 if (!ea_endpoint->ep_portlist) {
869 PERROR("EPOINT(%d) no portlist\n", ea_endpoint->ep_serial);
871 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_VBOX_PLAY);
872 SCPY(message->param.play.file, filename);
873 message->param.play.offset = offset;
874 message_put(message);
876 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s set play '%s'\n", ea_endpoint->ep_serial, e_ext.number, filename);
881 * change speed of the recording file, the default is 1
882 * negative values cause negative speed
884 void EndpointAppPBX::set_play_speed(int speed)
886 struct lcr_msg *message;
888 if (!ea_endpoint->ep_portlist) {
889 PERROR("EPOINT(%d) no portlist\n", ea_endpoint->ep_serial);
891 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_VBOX_PLAY_SPEED);
892 message->param.speed = speed;
893 message_put(message);
895 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s set speed '%d'\n", ea_endpoint->ep_serial, e_ext.number, speed);