modified: chan_lcr.c
[lcr.git] / action.cpp
index 0bb68cd..67c8396 100644 (file)
@@ -121,7 +121,7 @@ void EndpointAppPBX::action_init_remote(void)
 {
        struct route_param      *rparam;
        struct port_list        *portlist = ea_endpoint->ep_portlist;
-       struct message          *message;
+       struct lcr_msg          *message;
        struct capa_info        capainfo;
        struct caller_info      callerinfo;
        struct redir_info       redirinfo;
@@ -169,7 +169,7 @@ void EndpointAppPBX::action_dialing_internal(void)
        struct redir_info       redirinfo;
        struct dialing_info     dialinginfo;
        struct port_list        *portlist = ea_endpoint->ep_portlist;
-       struct message          *message;
+       struct lcr_msg          *message;
        struct extension        ext;
        struct route_param      *rparam;
 
@@ -277,7 +277,7 @@ void EndpointAppPBX::action_dialing_external(void)
        struct dialing_info dialinginfo;
        char *p;
        struct port_list *portlist = ea_endpoint->ep_portlist;
-       struct message *message;
+       struct lcr_msg *message;
        struct route_param *rparam;
 
        /* special processing of delete characters '*' and '#' */
@@ -438,7 +438,7 @@ void EndpointAppPBX::action_dialing_external(void)
 
 void EndpointAppPBX::action_dialing_remote(void)
 {
-       struct message *message;
+       struct lcr_msg *message;
        struct dialing_info dialinginfo;
 //     struct route_param *rparam;
 
@@ -465,7 +465,7 @@ void EndpointAppPBX::action_dialing_vbox_record(void)
 {
        struct dialing_info dialinginfo;
        struct port_list *portlist = ea_endpoint->ep_portlist;
-       struct message *message;
+       struct lcr_msg *message;
        struct extension ext;
        struct route_param *rparam;
 
@@ -546,7 +546,7 @@ void EndpointAppPBX::action_init_partyline(void)
        class Join *join;
        class JoinPBX *joinpbx;
        struct port_list *portlist = ea_endpoint->ep_portlist;
-       struct message *message;
+       struct lcr_msg *message;
        struct route_param *rparam;
        int partyline, jingle = 0;
        struct join_relation *relation;
@@ -647,7 +647,7 @@ void EndpointAppPBX::action_hangup_call(void)
 void EndpointAppPBX::action_dialing_login(void)
 {
        struct port_list *portlist = ea_endpoint->ep_portlist;
-       struct message *message;
+       struct lcr_msg *message;
        char *extension;
        struct route_param *rparam;
 
@@ -991,7 +991,7 @@ void EndpointAppPBX::action_init_redial_reply(void)
 */
 void EndpointAppPBX::_action_redial_reply(int in)
 {
-       struct message *message;
+       struct lcr_msg *message;
        char *last;
        struct route_param *rparam;
 
@@ -1090,7 +1090,7 @@ void EndpointAppPBX::action_dialing_reply(void)
 void EndpointAppPBX::action_dialing_powerdial(void)
 {
        struct port_list *portlist = ea_endpoint->ep_portlist;
-       struct message *message;
+       struct lcr_msg *message;
        struct route_param *rparam;
 
        /* power dialing only possible if we have a last dialed number */
@@ -1321,7 +1321,7 @@ void EndpointAppPBX::action_dialing_test(void)
        unsigned int cause;
        char causestr[16];
        struct port_list *portlist = ea_endpoint->ep_portlist;
-       struct message *message;
+       struct lcr_msg *message;
        class Port *port;
        char testcode[32] = "";
        struct route_param *rparam;
@@ -1533,7 +1533,7 @@ void EndpointAppPBX::action_init_play(void)
 void EndpointAppPBX::action_dialing_calculator(void)
 {
        struct port_list *portlist = ea_endpoint->ep_portlist;
-       struct message *message;
+       struct lcr_msg *message;
        double value1, value2, v, sign1;
        int komma1, komma2, k, state, mode, first;
        char *p;
@@ -1837,13 +1837,18 @@ void EndpointAppPBX::_action_goto_menu(int mode)
        trace_header("ACTION goto/menu (change to)", DIRECTION_NONE);
        add_trace("ruleset", NULL, "%s", e_ruleset->name);
        if (e_dialinginfo.id[0])
+       {
                add_trace("dialing", NULL, "%s", e_dialinginfo.id);
+       }
        if ((rparam = routeparam(e_action, PARAM_SAMPLE)))
        {
                add_trace("sample", NULL, "%s", rparam->string_value);
+               end_trace();
                set_tone(ea_endpoint->ep_portlist, rparam->string_value);
+       } else
+       {
+               end_trace();
        }
-       end_trace();
 
        /* do dialing with new ruleset */
        e_action = NULL;
@@ -1872,7 +1877,7 @@ void EndpointAppPBX::action_dialing_disconnect(void)
 {
        struct route_param *rparam;
        struct port_list *portlist = ea_endpoint->ep_portlist;
-       struct message *message;
+       struct lcr_msg *message;
        int cause = CAUSE_NORMAL; /* normal call clearing */
        int location = LOCATION_PRIVATE_LOCAL;
        char cause_string[256] = "", display[84] = "";
@@ -1942,7 +1947,7 @@ void EndpointAppPBX::action_dialing_help(void)
        struct numbering *numbering = numbering_int;
        char dialing[sizeof(e_dialinginfo.id)];
        int i;
-       struct message *message;
+       struct lcr_msg *message;
        struct route_param *rparam;
 
        /* in case we have no menu (this should never happen) */
@@ -2035,8 +2040,9 @@ void EndpointAppPBX::action_dialing_setforward(void)
 void EndpointAppPBX::action_hangup_execute(void)
 {
        struct route_param *rparam;
+       pid_t pid;
        char *command = "", isdn_port[10];
-       char *argv[7+1]; /* check also number of args below */
+       char *argv[11]; /* check also number of args below */
        int i = 0;
 
        /* get script / command */
@@ -2048,26 +2054,35 @@ void EndpointAppPBX::action_hangup_execute(void)
                end_trace();
                return;
        }
-       trace_header("ACTION execute", DIRECTION_NONE);
-       add_trace("command", NULL, "%s", command);
-       end_trace();
-
-       argv[0] = command;
-       while(strchr(argv[0], '/'))
-               argv[0] = strchr(argv[0], '/')+1;
+       argv[i++] = "/bin/sh";
+       argv[i++] = "-c";
+       argv[i++] = command;
+       argv[i++] = command;
        if ((rparam = routeparam(e_action, PARAM_PARAM)))
        {
-               argv[1] = rparam->string_value;
-               i++;
+               argv[i++] = rparam->string_value;
        }
-       argv[1+i] = e_extdialing;
-       argv[2+i] = numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype);
-       argv[3+i] = e_callerinfo.extension;
-       argv[4+i] = e_callerinfo.name;
+       argv[i++] = e_extdialing;
+       argv[i++] = numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype);
+       argv[i++] = e_callerinfo.extension;
+       argv[i++] = e_callerinfo.name;
        SPRINT(isdn_port, "%d", e_callerinfo.isdn_port);
-       argv[5+i] = isdn_port;
-       argv[6+i] = NULL; /* check also number of args above */
-       execve("/bin/sh", argv, environ);
+       argv[i++] = isdn_port;
+       argv[i++] = NULL; /* check also number of args above */
+       switch (pid = fork ()) {
+               case -1:
+                       trace_header("ACTION execute (fork failed)", DIRECTION_NONE);
+                       end_trace();
+                       break;
+               case 0:
+                       execve("/bin/sh", argv, environ);
+                       break;
+               default:
+                       trace_header("ACTION execute", DIRECTION_NONE);
+                       add_trace("command", NULL, "%s", command);
+                       end_trace();
+                       break;
+       }
 }
 
 
@@ -2207,7 +2222,7 @@ void EndpointAppPBX::action_dialing_password_wr(void)
 void EndpointAppPBX::process_dialing(void)
 {
        struct port_list *portlist = ea_endpoint->ep_portlist;
-       struct message *message;
+       struct lcr_msg *message;
        struct route_param *rparam;
 
 //#warning Due to HANG-BUG somewhere here, I added some HANG-BUG-DEBUGGING output that cannot be disabled. after bug has been found, this will be removed.
@@ -2276,7 +2291,7 @@ void EndpointAppPBX::process_dialing(void)
        if (e_state!=EPOINT_STATE_IN_SETUP
         && e_state!=EPOINT_STATE_IN_OVERLAP)
        {
-               PDEBUG(DEBUG_EPOINT, "EPOINT(%d): we are not in incomming setup/overlap state, so we ignore init/dialing process.\n", ea_endpoint->ep_serial, e_rule_nesting);
+               PDEBUG(DEBUG_EPOINT, "EPOINT(%d): we are not in incoming setup/overlap state, so we ignore init/dialing process.\n", ea_endpoint->ep_serial, e_rule_nesting);
                e_match_timeout = 0;
                goto end;
        }
@@ -2444,7 +2459,7 @@ void EndpointAppPBX::process_dialing(void)
                if (e_state!=EPOINT_STATE_IN_SETUP
                 && e_state!=EPOINT_STATE_IN_OVERLAP)
                {
-                       PDEBUG(DEBUG_EPOINT, "EPOINT(%d): AFTER init process: we are not in incomming setup/overlap state anymore, so we ignore further dialing process.\n", ea_endpoint->ep_serial, e_rule_nesting);
+                       PDEBUG(DEBUG_EPOINT, "EPOINT(%d): AFTER init process: we are not in incoming setup/overlap state anymore, so we ignore further dialing process.\n", ea_endpoint->ep_serial, e_rule_nesting);
                        goto display_action;
                }
        }
@@ -2544,7 +2559,7 @@ void EndpointAppPBX::process_hangup(int cause, int location)
                write_log(e_ext.number, callertext, dialingtext, e_start, e_stop, 0, cause, location);
 
                /* store last received call for reply-list */
-               if (e_origin == 1) // outgoing to phone is incomming for user
+               if (e_origin == 1) // outgoing to phone is incoming for user
                if (e_callerinfo.id[0] || e_callerinfo.extension[0])
                if (e_ext.anon_ignore || e_callerinfo.present!=INFO_PRESENT_RESTRICTED)
                {
@@ -2568,7 +2583,7 @@ void EndpointAppPBX::process_hangup(int cause, int location)
                }
 
                /* store last made call for reply-list */
-               if (e_origin == 0) // incomming from phone is outgoing for user
+               if (e_origin == 0) // incoming from phone is outgoing for user
                if (e_dialinginfo.id[0])
                {
                        if (!!strcmp(e_dialinginfo.id, e_ext.last_out[0]))