Data-Over-Voice
[lcr.git] / action_vbox.cpp
index 650bf9a..120bfa6 100644 (file)
@@ -9,13 +9,6 @@
 **                                                                           **
 \*****************************************************************************/ 
 
-#include <stdio.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
 #include "main.h"
 
 
@@ -51,14 +44,14 @@ VBOX_STATE_CALLINFO_END, /* this value defines the end of callingo */
        VBOX_STATE_DELETE_DONE, /* tell that message is delete */
 };
 
-char *months_english[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
-char *months_german[] = {"Jan","Feb","Maer","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"};
+const char *months_english[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
+const char *months_german[] = {"Jan","Feb","Maer","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"};
 
 struct vbox_menu {
-       char digit;
-       char *english;
-       char *german;
-       } vbox_menu[] = {
+       const char digit;
+       const char *english;
+       const char *german;
+} vbox_menu[] = {
        {'1', "<< previous", "<< zurueck"},
        {'2', "-> play", "-> anhoeren"},
        {'3', ">> next", ">> vor"},
@@ -70,7 +63,7 @@ struct vbox_menu {
        {'9', "X  delete", "X  loeschen"},
        {'0', "*  call", "*  anrufen"},
        {'\0', NULL, NULL}
-       };
+};
 
 /*
  * initialize the vbox. this is called at process_dialing(), when the VBOX_PLAY
@@ -80,15 +73,14 @@ void EndpointAppPBX::action_init_vbox_play(void)
 {
        int                     language = e_ext.vbox_language;
        struct route_param      *rparam;
-       struct message          *message;
+       struct lcr_msg          *message;
        struct port_list        *portlist = ea_endpoint->ep_portlist;
 
        /* get extension */
        SCPY(e_vbox, e_ext.number);
        if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
                SCPY(e_vbox, rparam->string_value);
-       if (e_vbox[0] == '\0')
-       {
+       if (e_vbox[0] == '\0') {
                /* facility rejected */
                message_disconnect_port(portlist, CAUSE_FACILITYREJECTED, LOCATION_PRIVATE_LOCAL, "");
                new_state(EPOINT_STATE_OUT_DISCONNECT);
@@ -102,14 +94,14 @@ void EndpointAppPBX::action_init_vbox_play(void)
                e_dtmf = 1;
        message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
        message_put(message);
-       logmessage(message);
+       logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
 
        /* initialize the vbox */
        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) initializing answering vbox state\n", ea_endpoint->ep_serial);
 
        e_vbox_state = VBOX_STATE_MENU;
        SCPY(e_vbox_display, (char *)((language)?"druecke 2 f. wiedergabe":"press 2 to play"));
-       e_vbox_display_refresh = 1;
+       schedule_timer(&e_vbox_refresh, 0, 0);
        set_tone_vbox("menu");
 
        e_vbox_menu = -1;
@@ -117,11 +109,10 @@ void EndpointAppPBX::action_init_vbox_play(void)
        vbox_index_read(e_vbox_play);
        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) number of calls: %d\n", ea_endpoint->ep_serial, e_vbox_index_num);
 
-       if (e_vbox_index_num == 0)
-       {
+       if (e_vbox_index_num == 0) {
                e_vbox_state = VBOX_STATE_NOTHING;
                SCPY(e_vbox_display, (char *)((language)?"keine Anrufe":"no calls"));
-               e_vbox_display_refresh = 1;
+               schedule_timer(&e_vbox_refresh, 0, 0);
                set_tone_vbox("nothing");
        }
 }
@@ -143,20 +134,15 @@ void EndpointAppPBX::vbox_index_read(int num)
 
        e_vbox_index_num = 0;
 
-       SPRINT(filename, "%s/%s/%s/vbox/index", INSTALL_DATA, options.extensions_dir, e_vbox);
-       if (!(fp = fopen(filename, "r")))
-       {
+       SPRINT(filename, "%s/%s/vbox/index", EXTENSION_DATA, e_vbox);
+       if (!(fp = fopen(filename, "r"))) {
                PDEBUG(DEBUG_EPOINT, "EPOINT(%d) no files in index\n", ea_endpoint->ep_serial);
                return;
        }
        fduse++;
 
        i = 0;
-       while((fgets(buffer,sizeof(buffer),fp)))
-       {
-               buffer[sizeof(buffer)-1] = '\0';
-               if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
-
+       while((GETLINE(buffer, fp))) {
                name[0] = callerid[0] = '\0';
                mon = mday = hour = min = 0;
                sscanf(buffer, "%s %d %d %d %d %d %s", name, &year, &mon, &mday, &hour, &min, callerid);
@@ -165,8 +151,7 @@ void EndpointAppPBX::vbox_index_read(int num)
                        continue;
 
                /* the selected entry */
-               if (i == num)
-               {
+               if (i == num) {
                        SCPY(e_vbox_index_file, name);
                        e_vbox_index_year = year;
                        e_vbox_index_mon = mon;
@@ -201,34 +186,29 @@ void EndpointAppPBX::vbox_index_remove(int num)
 
        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) removing entrie #%d\n", ea_endpoint->ep_serial, num);
 
-       SPRINT(filename1, "%s/%s/%s/vbox/index", INSTALL_DATA, options.extensions_dir, e_vbox);
-       SPRINT(filename2, "%s/%s/%s/vbox/index-temp", INSTALL_DATA, options.extensions_dir, e_vbox);
-       if (!(fpr = fopen(filename1, "r")))
-       {
+       SPRINT(filename1, "%s/%s/vbox/index", EXTENSION_DATA, e_vbox);
+       SPRINT(filename2, "%s/%s/vbox/index-temp", EXTENSION_DATA, e_vbox);
+       if (!(fpr = fopen(filename1, "r"))) {
                return;
        }
-       if (!(fpw = fopen(filename2, "w")))
-       {
+       if (!(fpw = fopen(filename2, "w"))) {
                fclose(fpr);
                return;
        }
        fduse += 2;
 
        i = 0;
-       while((fgets(buffer,sizeof(buffer),fpr)))
-       {
+       while((fgets(buffer,sizeof(buffer),fpr))) {
                buffer[sizeof(buffer)-1] = '\0';
                if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
 
-               if (buffer[0]=='\0' || buffer[0]=='#')
-               {
+               if (buffer[0]=='\0' || buffer[0]=='#') {
                        fprintf(fpw, "%s\n", buffer);
                        continue;       
                }
 
                /* the selected entry will not be written */
-               if (i != num)
-               {
+               if (i != num) {
                        fprintf(fpw, "%s\n", buffer);
                }
 
@@ -252,37 +232,34 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
        int language = e_ext.vbox_language;
        struct port_list *portlist;
        class Port *port;
+       time_t current_time;
+       struct tm *current_tm;
        
        portlist = ea_endpoint->ep_portlist;
 
-       if (e_extdialing[0] == '\0')
-       {
+       if (e_extdialing[0] == '\0') {
                PDEBUG(DEBUG_EPOINT, "EPOINT(%d) called with no digit\n", ea_endpoint->ep_serial);
                return;
        }
 
        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) dialing digit: %c\n", ea_endpoint->ep_serial, e_extdialing[0]);
 
-       e_vbox_display_refresh = 1;
+       schedule_timer(&e_vbox_refresh, 0, 0);
 
-       if (e_vbox_state == VBOX_STATE_RECORD_RECORD)
-       {
-               if (e_extdialing[0] == '1')
-               {
+       if (e_vbox_state == VBOX_STATE_RECORD_RECORD) {
+               if (e_extdialing[0] == '1' || e_extdialing[0] == '0') {
                        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) stopping recording of announcement.\n", ea_endpoint->ep_serial);
 
                        port = find_port_id(portlist->port_id);
                        if (port)
-                               port->close_record(6000); /* append beep */
+                               port->close_record((e_extdialing[0]=='1')?6000:0, 2000); /* append beep */
                        goto record_ask;
                }
                goto done;
        }
 
-       if (e_vbox_state == VBOX_STATE_RECORD_PLAY)
-       {
-               if (e_extdialing[0] == '1')
-               {
+       if (e_vbox_state == VBOX_STATE_RECORD_PLAY) {
+               if (e_extdialing[0] == '1') {
                        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) stopping playback of announcement.\n", ea_endpoint->ep_serial);
 
                        goto record_ask;
@@ -290,10 +267,8 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                goto done;
        }
 
-       if (e_vbox_state == VBOX_STATE_RECORD_ASK)
-       {
-               switch(e_extdialing[0])
-               {
+       if (e_vbox_state == VBOX_STATE_RECORD_ASK) {
+               switch(e_extdialing[0]) {
                        case '3':
                        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) quit recoding menu.\n", ea_endpoint->ep_serial);
                        ask_abort:
@@ -307,10 +282,10 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) play recoding.\n", ea_endpoint->ep_serial);
                        /* play announcement */
                        e_vbox_counter = 0;
-                       e_vbox_counter_last = 0;
                        e_vbox_counter_max = 0;
                        e_vbox_speed = 1;
                        e_vbox_state = VBOX_STATE_RECORD_PLAY;
+                       schedule_timer(&e_vbox_refresh, 0, 0);
                        if (e_ext.vbox_language)
                                SCPY(e_vbox_display, "Wied., 1=stop %s");
                        else
@@ -324,10 +299,9 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) record announcement.\n", ea_endpoint->ep_serial);
                        /* close recording if already recording */
                        port = find_port_id(portlist->port_id);
-                       if (port)
-                       {
-                               port->close_record(6000); /* append beep */
-                               port->open_record(CODEC_MONO, 1, 5000, e_ext.number, 0, "", 0); /* record announcement, skip the first 5000 samples */
+                       if (port) {
+                               port->close_record(0,0); 
+                               port->open_record(CODEC_MONO, 1, 4000, e_ext.number, 0, "", 0); /* record announcement, skip the first 4000 samples */
                        }
                        e_vbox_state = VBOX_STATE_RECORD_RECORD;
                        if (e_ext.vbox_language)
@@ -343,33 +317,28 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                goto done;
        }
 
-       if (e_vbox_state==VBOX_STATE_STORE_ASK || e_vbox_state==VBOX_STATE_DELETE_ASK)
-       {
+       if (e_vbox_state==VBOX_STATE_STORE_ASK || e_vbox_state==VBOX_STATE_DELETE_ASK) {
                char filename[256], filename2[256];
 
-               switch(e_extdialing[0])
-               {
+               switch(e_extdialing[0]) {
                        case '3':
                        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) quit store/delete menu.\n", ea_endpoint->ep_serial);
                        goto ask_abort;
 
                        case '1':
                        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) do store/delete.\n", ea_endpoint->ep_serial);
-                       SPRINT(filename, "%s/%s/%s/vbox/%s", INSTALL_DATA, options.extensions_dir, e_vbox, e_vbox_index_file);
+                       SPRINT(filename, "%s/%s/vbox/%s", EXTENSION_DATA, e_vbox, e_vbox_index_file);
 
                        /* move file */
-                       if (e_vbox_state == VBOX_STATE_STORE_ASK)
-                       {
-                               SPRINT(filename, "%s/%s/%s/recordings", INSTALL_DATA, options.extensions_dir, e_vbox);
-                               if (mkdir(filename, 0755) < 0)
-                               {
-                                       if (errno != EEXIST)
-                                       {
+                       if (e_vbox_state == VBOX_STATE_STORE_ASK) {
+                               SPRINT(filename, "%s/%s/recordings", EXTENSION_DATA, e_vbox);
+                               if (mkdir(filename, 0755) < 0) {
+                                       if (errno != EEXIST) {
                                                PERROR("EPOINT(%d) cannot create directory '%s'\n", ea_endpoint->ep_serial, filename);
                                                goto done;
                                        }
                                }
-                               SPRINT(filename2, "%s/%s/%s/recordings/%s", INSTALL_DATA, options.extensions_dir, e_vbox, e_vbox_index_file);
+                               SPRINT(filename2, "%s/%s/recordings/%s", EXTENSION_DATA, e_vbox, e_vbox_index_file);
                                rename(filename, filename2);
                                e_vbox_state = VBOX_STATE_STORE_DONE;
                                if (e_ext.vbox_language)
@@ -380,8 +349,7 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                        }
 
                        /* remove file */
-                       if (e_vbox_state == VBOX_STATE_DELETE_ASK)
-                       {
+                       if (e_vbox_state == VBOX_STATE_DELETE_ASK) {
                                remove(filename);
                                e_vbox_state = VBOX_STATE_DELETE_DONE;
                                if (e_ext.vbox_language)
@@ -395,8 +363,7 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                        vbox_index_remove(e_vbox_play);
                        vbox_index_read(e_vbox_play);
                        /* stay at the last message+1, so we always get "no messages" */
-                       if (e_vbox_play>e_vbox_index_num && e_vbox_play)
-                       {
+                       if (e_vbox_play>e_vbox_index_num && e_vbox_play) {
                                e_vbox_play = e_vbox_index_num-1;
                        }
                        default:
@@ -406,13 +373,11 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
        }
 
        /* dialing during menu */
-       switch(e_extdialing[0])
-       {
+       switch(e_extdialing[0]) {
                /* process the vbox functions */
                case '1': /* previous */
                PDEBUG(DEBUG_EPOINT, "EPOINT(%d) previous call is selected.\n", ea_endpoint->ep_serial);
-               if (e_vbox_index_num == 0) /* nothing to play */
-               {
+               if (e_vbox_index_num == 0) { /* nothing to play */
                        no_calls:
                        e_vbox_state = VBOX_STATE_MENU;
                        SCPY(e_vbox_display, (char *)((language)?"keine Anrufe":"no calls"));
@@ -420,8 +385,7 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                        break;
                }
                e_vbox_play--;
-               if (e_vbox_play < 0)
-               {
+               if (e_vbox_play < 0) {
                        e_vbox_play = 0;
 
                        e_vbox_state = VBOX_STATE_MENU;
@@ -434,12 +398,12 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                e_vbox_state = VBOX_STATE_CALLINFO_INTRO;
                SPRINT(e_vbox_display, "#%d", e_vbox_play+1);
                vbox_index_read(e_vbox_play);
-               if (e_vbox_index_mon!=now_tm->tm_mon || e_vbox_index_year!=now_tm->tm_year)
-               {
+               time(&current_time);
+               current_tm = localtime(&current_time);
+               if (e_vbox_index_mon!=current_tm->tm_mon || e_vbox_index_year!=current_tm->tm_year) {
                        UPRINT(strchr(e_vbox_display,'\0'), " %s", (language)?months_german[e_vbox_index_mon]:months_english[e_vbox_index_mon]);
                }
-               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)
-               {
+               if (e_vbox_index_mday!=current_tm->tm_mday || e_vbox_index_mon!=current_tm->tm_mon || e_vbox_index_year!=current_tm->tm_year) {
                        UPRINT(strchr(e_vbox_display,'\0'), " %d", e_vbox_index_mday);
                }
                UPRINT(strchr(e_vbox_display,'\0'), " %02d:%02d", e_vbox_index_hour, e_vbox_index_min);
@@ -451,43 +415,38 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                case '2': /* play */
                if (e_vbox_play >= e_vbox_index_num)
                        goto no_messages;
-               if (e_vbox_index_num == 0) /* nothing to play */
-               {
+               if (e_vbox_index_num == 0) { /* nothing to play */
                        goto no_calls;
                }
                PDEBUG(DEBUG_EPOINT, "EPOINT(%d) play call #%d.\n", ea_endpoint->ep_serial, e_vbox_play+1);
-               if (e_vbox_state>VBOX_STATE_CALLINFO_BEGIN && e_vbox_state<VBOX_STATE_CALLINFO_END)
-               {
+               if (e_vbox_state>VBOX_STATE_CALLINFO_BEGIN && e_vbox_state<VBOX_STATE_CALLINFO_END) {
                        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) play call #%d. abborting announcement and starting with playback\n", ea_endpoint->ep_serial, e_vbox_play+1);
                        /* the callinfo is played, so we start with the call */
                        e_vbox_counter = 0;
-                       e_vbox_counter_last = 0;
                        e_vbox_counter_max = 0;
                        e_vbox_speed = 1;
                        e_vbox_state = VBOX_STATE_PLAY;
+                       schedule_timer(&e_vbox_refresh, 0, 0);
                        SPRINT(e_vbox_display, "#%d %%s", e_vbox_play+1);
                        if (e_ext.vbox_display == VBOX_DISPLAY_DETAILED)
                                UPRINT(strchr(e_vbox_display,'\0'), " (%s)", e_vbox_index_callerid);
                        set_play_vbox(e_vbox_index_file, 0);
                        break;
                } else
-               if (e_vbox_state==VBOX_STATE_PLAY && e_vbox_speed!=1)
-               {
+               if (e_vbox_state==VBOX_STATE_PLAY && e_vbox_speed!=1) {
                        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);
                        /* we set play speed to normal */
                        e_vbox_speed = 1;
                        set_play_speed(e_vbox_speed);
                } else
-               if (e_vbox_state == VBOX_STATE_PLAY)
-               {
+               if (e_vbox_state == VBOX_STATE_PLAY) {
                        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);
                        /* we pause the current play */
                        e_vbox_state = VBOX_STATE_PAUSE;
                        SCPY(e_vbox_display, (char *)((language)?"druecke 2 f. wiedergabe":"press 2 to play"));
                        set_tone_vbox("pause");
                } else
-               if (e_vbox_state == VBOX_STATE_PAUSE)
-               {
+               if (e_vbox_state == VBOX_STATE_PAUSE) {
                        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) play call #%d. currently pause, so we continue play\n", ea_endpoint->ep_serial, e_vbox_play+1);
                        /* we continue the current play */
                        e_vbox_state = VBOX_STATE_PLAY;
@@ -495,8 +454,7 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                        if (e_ext.vbox_display == VBOX_DISPLAY_DETAILED)
                                UPRINT(strchr(e_vbox_display,'\0'), " (%s)", e_vbox_index_callerid);
                        set_play_vbox(e_vbox_index_file, e_vbox_counter);
-               } else
-               {
+               } else {
                        /* now we have something else going on, so we announce the call */
                        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) play call #%d. announcing call during any other state\n", ea_endpoint->ep_serial, e_vbox_play+1);
                        goto announce_call;
@@ -505,13 +463,11 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
 
                case '3': /* next */
                PDEBUG(DEBUG_EPOINT, "EPOINT(%d) next call is selected.\n", ea_endpoint->ep_serial);
-               if (e_vbox_index_num == 0) /* nothing to play */
-               {
+               if (e_vbox_index_num == 0) { /* nothing to play */
                        goto no_calls;
                }
                e_vbox_play++;
-               if (e_vbox_play >= e_vbox_index_num)
-               {
+               if (e_vbox_play >= e_vbox_index_num) {
                        no_messages:
                        e_vbox_play = e_vbox_index_num;
 
@@ -525,8 +481,7 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                break;
 
                case '4': /* rewind */
-               if (e_vbox_state==VBOX_STATE_PLAY)
-               {
+               if (e_vbox_state==VBOX_STATE_PLAY) {
                        if (e_vbox_speed >= -1)
                                e_vbox_speed = -1;
                        e_vbox_speed = e_vbox_speed * 2;
@@ -543,8 +498,7 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                break;
 
                case '6': /* wind */
-               if (e_vbox_state==VBOX_STATE_PLAY)
-               {
+               if (e_vbox_state==VBOX_STATE_PLAY) {
                        if (e_vbox_speed <= 1)
                                e_vbox_speed = 1;
                        e_vbox_speed = e_vbox_speed * 2;
@@ -565,8 +519,7 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                PDEBUG(DEBUG_EPOINT, "EPOINT(%d) entering the store menu\n", ea_endpoint->ep_serial);
                if (e_vbox_play >= e_vbox_index_num)
                        goto no_messages;
-               if (e_vbox_index_num == 0) /* nothing to play */
-               {
+               if (e_vbox_index_num == 0) { /* nothing to play */
                        goto no_calls;
                }
                e_vbox_state = VBOX_STATE_STORE_ASK;
@@ -578,8 +531,7 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                PDEBUG(DEBUG_EPOINT, "EPOINT(%d) entering the delete menu\n", ea_endpoint->ep_serial);
                if (e_vbox_play >= e_vbox_index_num)
                        goto no_messages;
-               if (e_vbox_index_num == 0) /* nothing to play */
-               {
+               if (e_vbox_index_num == 0) { /* nothing to play */
                        goto no_calls;
                }
                e_vbox_state = VBOX_STATE_DELETE_ASK;
@@ -602,17 +554,15 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
                break;
 
                case '0':
-               if (e_vbox_menu < 0) /* only if menu selection is pressed before*/
-               {
+               if (e_vbox_menu < 0) { /* only if menu selection is pressed before*/
                        /* call if phonenumber is given */
                        if (e_vbox_index_num)
-                       if (e_vbox_index_callerid[0]!='\0' && !!strcmp(e_vbox_index_callerid,"anonymous") && !!strcmp(e_vbox_index_callerid,"unknown"))
-                       {
+                       if (e_vbox_index_callerid[0]!='\0' && !!strcmp(e_vbox_index_callerid,"anonymous") && !!strcmp(e_vbox_index_callerid,"unknown")) {
                                set_tone(portlist, "dialing");
                                SPRINT(e_dialinginfo.id, "extern:%s", e_vbox_index_callerid);
                                e_extdialing = e_dialinginfo.id;
                                e_action = NULL;
-                               process_dialing();
+                               process_dialing(0);
                                return;
                        }
                        break;
@@ -654,33 +604,35 @@ void EndpointAppPBX::action_dialing_vbox_play(void)
 /*
  * this handler is called by Epoint::handler(), whenever the action is NUMB_ACTION_VBOX_PLAY
  */
-void EndpointAppPBX::vbox_handler(void)
+int vbox_refresh(struct lcr_timer *timer, void *instance, int index)
 {
-       /* refresh if counter changes */
-       if (e_vbox_state==VBOX_STATE_PLAY || e_vbox_state==VBOX_STATE_RECORD_PLAY)
-       if (e_vbox_counter != e_vbox_counter_last)
-       {
-               e_vbox_counter_last = e_vbox_counter;
-               e_vbox_display_refresh = 1;
-       }
+       class EndpointAppPBX *ea = (class EndpointAppPBX *)instance;
 
-       /* refresh display, if required (include counter) */
-       if (e_vbox_display_refresh && e_ext.vbox_display!=VBOX_DISPLAY_OFF)
-       {
-               char counter[32];
-               struct message *message;
-
-               SPRINT(counter, "%02d:%02d", e_vbox_counter/60, e_vbox_counter%60);
-               if (e_vbox_counter_max)
-                       UPRINT(strchr(counter,'\0'), " of %02d:%02d", e_vbox_counter_max/60, e_vbox_counter_max%60);
-
-               e_vbox_display_refresh = 0;
-               message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
-               SPRINT(message->param.notifyinfo.display, e_vbox_display, counter);
-               PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s pending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
-               message_put(message);
-               logmessage(message);
-       }
+       /* no display */
+       if (ea->e_ext.vbox_display == VBOX_DISPLAY_OFF)
+               return 0;
+
+       /* refresh display */
+       char counter[32];
+       struct lcr_msg *message;
+
+       SPRINT(counter, "%02d:%02d", ea->e_vbox_counter/60, ea->e_vbox_counter%60);
+       if (ea->e_vbox_counter_max)
+               UPRINT(strchr(counter,'\0'), " of %02d:%02d", ea->e_vbox_counter_max/60, ea->e_vbox_counter_max%60);
+
+       message = message_create(ea->ea_endpoint->ep_serial, ea->ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
+       SPRINT(message->param.notifyinfo.display, ea->e_vbox_display, counter);
+       PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s pending display:%s\n", ea->ea_endpoint->ep_serial, ea->e_ext.number, message->param.notifyinfo.display);
+       message_put(message);
+       ea->logmessage(message->type, &message->param, ea->ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
+
+       /* not playing anymore */
+       if (!ea->e_vbox_state==VBOX_STATE_PLAY && !ea->e_vbox_state==VBOX_STATE_RECORD_PLAY)
+               return 0;
+       
+       schedule_timer(&ea->e_vbox_refresh, 1, 0);
+
+       return 0;
 }
 
 
@@ -692,28 +644,27 @@ void EndpointAppPBX::vbox_message_eof(void)
 {
        char buffer[32];
        int language = e_ext.vbox_language;
+       time_t current_time;
+       struct tm *current_tm;
 
        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s end of file during state: %d\n", ea_endpoint->ep_serial, e_ext.number, e_vbox_state);
 
-       switch(e_vbox_state)
-       {
+       switch(e_vbox_state) {
                case VBOX_STATE_MENU:
                case VBOX_STATE_NOTHING:
                e_vbox_state = VBOX_STATE_MENU;
                SCPY(e_vbox_display, (char *)((language)?"druecke 2 f. wiedergabe":"press 2 to play"));
-               e_vbox_display_refresh = 1;
+               schedule_timer(&e_vbox_refresh, 0, 0);
                set_tone_vbox("menu");
                break;
 
                case VBOX_STATE_PLAY:
-               if (e_vbox_speed > 0)
-               {
+               if (e_vbox_speed > 0) {
                        e_vbox_state = VBOX_STATE_MENU;
                        SCPY(e_vbox_display, (char *)((language)?"druecke 3 f. Naechste":"press 3 for next"));
-                       e_vbox_display_refresh = 1;
+               schedule_timer(&e_vbox_refresh, 0, 0);
                        set_tone_vbox("menu");
-               } else
-               {
+               } else {
                        /* if we have endoffile because we were playing backwards, we continue to play forward */
                        e_vbox_speed = 1;
                        e_vbox_counter = 1;
@@ -723,11 +674,13 @@ void EndpointAppPBX::vbox_message_eof(void)
 
                case VBOX_STATE_PAUSE:
                SCPY(e_vbox_display, (char *)((language)?"druecke 2 f. weiterspielen":"press 2 to continue"));
-               e_vbox_display_refresh = 1;
+               schedule_timer(&e_vbox_refresh, 0, 0);
                break;
 
                case VBOX_STATE_CALLINFO_INTRO:
-               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)
+               time(&current_time);
+               current_tm = localtime(&current_time);
+               if (e_vbox_index_mday==current_tm->tm_mday && e_vbox_index_mon==current_tm->tm_mon && e_vbox_index_year==current_tm->tm_year)
                        goto skip_day_month;
                e_vbox_state = VBOX_STATE_CALLINFO_MONTH; //german day
                if (e_ext.vbox_language)
@@ -741,12 +694,10 @@ void EndpointAppPBX::vbox_message_eof(void)
 
                case VBOX_STATE_CALLINFO_MONTH:
                e_vbox_state = VBOX_STATE_CALLINFO_DAY; //german month
-               if (e_ext.vbox_language)
-               {
+               if (e_ext.vbox_language) {
                        /* done with month, so we send the month*/
                        SPRINT(buffer, "month_%02d", e_vbox_index_mon+1);
-               } else
-               {
+               } else {
                        /* done with day, so we send the day */
                        SPRINT(buffer, "day_%02d", e_vbox_index_mday);
                }
@@ -756,14 +707,12 @@ void EndpointAppPBX::vbox_message_eof(void)
                case VBOX_STATE_CALLINFO_DAY: //german month
                skip_day_month:
                e_vbox_state = VBOX_STATE_CALLINFO_HOUR;
-               if (e_ext.vbox_language)
-               {
+               if (e_ext.vbox_language) {
                        if (e_vbox_index_hour == 1)
                                SCPY(buffer, "number_ein");
                        else
                                SPRINT(buffer, "number_%02d", e_vbox_index_hour); /* 1-23 hours */
-               } else
-               {
+               } else {
                        SPRINT(buffer, "number_%02d", ((e_vbox_index_hour+11)%12)+1); /* 12 hours am/pm */
                }
                set_tone_vbox(buffer);
@@ -771,11 +720,9 @@ void EndpointAppPBX::vbox_message_eof(void)
 
                case VBOX_STATE_CALLINFO_HOUR:
                e_vbox_state = VBOX_STATE_CALLINFO_OCLOCK;
-               if (e_ext.vbox_language)
-               {
+               if (e_ext.vbox_language) {
                        set_tone_vbox("oclock");
-               } else
-               {
+               } else {
                        if (e_vbox_index_hour >= 12)
                                set_tone_vbox("oclock_pm");
                        else
@@ -785,15 +732,13 @@ void EndpointAppPBX::vbox_message_eof(void)
 
                case VBOX_STATE_CALLINFO_OCLOCK:
                e_vbox_state = VBOX_STATE_CALLINFO_MIN;
-               if (e_ext.vbox_language)
-               {
+               if (e_ext.vbox_language) {
 // german says "zwölfuhr und eins"
 //                     if (e_vbox_index_min == 1)
 //                             SCPY(buffer, "number_eine");
 //                     else
                                SPRINT(buffer, "number_%02d", e_vbox_index_min); /* 1-59 minutes */
-               } else
-               {
+               } else {
                        SPRINT(buffer, "number_%02d", e_vbox_index_min);
                }
                set_tone_vbox(buffer);
@@ -812,12 +757,10 @@ void EndpointAppPBX::vbox_message_eof(void)
                case VBOX_STATE_CALLINFO_MINUTES:
                start_digits:
                e_vbox_state = VBOX_STATE_CALLINFO_DIGIT;
-               if (e_vbox_index_callerid[0]=='\0' || !strcmp(e_vbox_index_callerid,"anonymous") || !strcmp(e_vbox_index_callerid,"unknown"))
-               {
+               if (e_vbox_index_callerid[0]=='\0' || !strcmp(e_vbox_index_callerid,"anonymous") || !strcmp(e_vbox_index_callerid,"unknown")) {
                        set_tone_vbox("call_anonymous");
                        e_vbox_index_callerid_index = strlen(e_vbox_index_callerid);
-               } else
-               {
+               } else {
                        set_tone_vbox("call_from");
                        e_vbox_index_callerid_index = 0;
                }
@@ -826,62 +769,58 @@ void EndpointAppPBX::vbox_message_eof(void)
                case VBOX_STATE_CALLINFO_DIGIT:
                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'))
                        e_vbox_index_callerid_index++;
-               if (e_vbox_index_callerid[e_vbox_index_callerid_index])
-               {
+               if (e_vbox_index_callerid[e_vbox_index_callerid_index]) {
                        SPRINT(buffer, "number_%02d", e_vbox_index_callerid[e_vbox_index_callerid_index]-'0');
                        set_tone_vbox(buffer);
                        e_vbox_index_callerid_index ++;
-               } else
-               {
+               } else {
                        /* the callinfo is played, so we start with the call */
                        e_vbox_counter = 0;
-                       e_vbox_counter_last = 0;
                        e_vbox_counter_max = 0;
                        e_vbox_speed = 1;
                        e_vbox_state = VBOX_STATE_PLAY;
+                       schedule_timer(&e_vbox_refresh, 0, 0);
                        SPRINT(e_vbox_display, "#%d %%s", e_vbox_play);
                        if (e_ext.vbox_display == VBOX_DISPLAY_DETAILED)
                                UPRINT(strchr(e_vbox_display,'\0'), " (%s)", e_vbox_index_callerid);
-                       e_vbox_display_refresh = 1;
+                       schedule_timer(&e_vbox_refresh, 0, 0);
                        set_play_vbox(e_vbox_index_file, 0);
                }
                break;
 
                case VBOX_STATE_RECORD_ASK:
                set_tone_vbox("record_ask");
-               e_vbox_display_refresh = 1;
+               schedule_timer(&e_vbox_refresh, 0, 0);
                break;
 
                case VBOX_STATE_STORE_ASK:
                set_tone_vbox("store_ask");
-               e_vbox_display_refresh = 1;
+               schedule_timer(&e_vbox_refresh, 0, 0);
                break;
 
                case VBOX_STATE_DELETE_ASK:
                set_tone_vbox("delete_ask");
-               e_vbox_display_refresh = 1;
+               schedule_timer(&e_vbox_refresh, 0, 0);
                break;
 
                case VBOX_STATE_RECORD_PLAY:
                e_vbox_state = VBOX_STATE_RECORD_ASK;
                SCPY(e_vbox_display, (char *)((language)?"1=Aufn. 2=Wied. 3=nein":"1=record 2=play 3=no"));
-               e_vbox_display_refresh = 1;
+               schedule_timer(&e_vbox_refresh, 0, 0);
                set_tone_vbox("record_ask");
                break;
 
                case VBOX_STATE_STORE_DONE:
                case VBOX_STATE_DELETE_DONE:
-               if (e_vbox_index_num == 0) /* nothing to play */
-               {
+               if (e_vbox_index_num == 0) { /* nothing to play */
                        e_vbox_state = VBOX_STATE_MENU;
                        SCPY(e_vbox_display, (char *)((language)?"keine Anrufe":"no calls"));
-                       e_vbox_display_refresh = 1;
+               schedule_timer(&e_vbox_refresh, 0, 0);
                        set_tone_vbox("nothing");
-               } else
-               {
+               } else {
                        e_vbox_state = VBOX_STATE_MENU;
                        SCPY(e_vbox_display, (char *)((language)?"druecke 2 f. wiedergabe":"press 2 to play"));
-                       e_vbox_display_refresh = 1;
+               schedule_timer(&e_vbox_refresh, 0, 0);
                        set_tone_vbox("menu");
                }
                break;
@@ -897,19 +836,18 @@ void EndpointAppPBX::vbox_message_eof(void)
  * set the given vbox-tone with full path (without appending)
  * the tone is played and after eof, a message is received
  */
-void EndpointAppPBX::set_tone_vbox(char *tone)
+void EndpointAppPBX::set_tone_vbox(const char *tone)
 {
-       struct message *message;
+       struct lcr_msg *message;
 
        if (tone == NULL)
                tone = "";
 
-       if (!ea_endpoint->ep_portlist)
-       {
+       if (!ea_endpoint->ep_portlist) {
                PERROR("EPOINT(%d) no portlist\n", ea_endpoint->ep_serial);
        }
        message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_VBOX_TONE);
-       SCPY(message->param.tone.dir, (char *)((e_ext.vbox_language)?"vbox_german":"vbox_english"));
+       SCPY(message->param.tone.dir, ((e_ext.vbox_language) ? "vbox_german" : "vbox_english"));
        SCPY(message->param.tone.name, tone);
        message_put(message);
 
@@ -924,12 +862,12 @@ void EndpointAppPBX::set_tone_vbox(char *tone)
  * the current counter value is also received by a message
  * set the offset in seconds of the current recording
  */
-void EndpointAppPBX::set_play_vbox(char *file, int offset)
+void EndpointAppPBX::set_play_vbox(const char *file, int offset)
 {
        char filename[256];
-       struct message *message;
+       struct lcr_msg *message;
 
-       SPRINT(filename, "%s/%s/%s/vbox/%s", INSTALL_DATA, options.extensions_dir, e_vbox, file);
+       SPRINT(filename, "%s/%s/vbox/%s", EXTENSION_DATA, e_vbox, file);
        
        /* remove .wav */
        if (!strcmp(filename+strlen(filename)-4, ".wav")) /* filename is always more than 4 digits long */
@@ -939,8 +877,7 @@ void EndpointAppPBX::set_play_vbox(char *file, int offset)
        if (!strcmp(filename+strlen(filename)-5, ".isdn")) /* filename is always more than 5 digits long */
                filename[strlen(filename)-5] = '\0';
 
-       if (!ea_endpoint->ep_portlist)
-       {
+       if (!ea_endpoint->ep_portlist) {
                PERROR("EPOINT(%d) no portlist\n", ea_endpoint->ep_serial);
        }
        message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_VBOX_PLAY);
@@ -958,10 +895,9 @@ void EndpointAppPBX::set_play_vbox(char *file, int offset)
  */
 void EndpointAppPBX::set_play_speed(int speed)
 {
-       struct message *message;
+       struct lcr_msg *message;
 
-       if (!ea_endpoint->ep_portlist)
-       {
+       if (!ea_endpoint->ep_portlist) {
                PERROR("EPOINT(%d) no portlist\n", ea_endpoint->ep_serial);
        }
        message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_VBOX_PLAY_SPEED);