added: autoconf environment
[lcr.git] / apppbx.cpp
index 375980a..f4fa4c9 100644 (file)
@@ -309,9 +309,9 @@ void EndpointAppPBX::screen(int out, char *id, int idsize, int *type, int *prese
                        SCPY(suffix, strchr(ifscreen->match,'%') - ifscreen->match + id);
                        UNCPY(id, ifscreen->result, idsize);
                        id[idsize-1] = '\0';
-                       if (strchr(ifscreen->result,'%'))
+                       if (strchr(id,'%'))
                        {
-                               *strchr(ifscreen->result,'%') = '\0';
+                               *strchr(id,'%') = '\0';
                                UNCAT(id, suffix, idsize);
                                id[idsize-1] = '\0';
                        }
@@ -697,11 +697,6 @@ void EndpointAppPBX::set_tone(struct port_list *portlist, char *tone)
        /* store for suspended processes */
        SCPY(e_tone, tone);
 
-       if (!portlist)
-       {
-               PDEBUG(DEBUG_EPOINT, "EPOINT(%d) no endpoint to notify tone.\n", ea_endpoint->ep_serial);
-               return;
-       }
 
        if (e_join_pattern /* pattern are provided */
         && !(e_ext.own_setup && e_state == EPOINT_STATE_IN_SETUP)
@@ -727,6 +722,10 @@ void EndpointAppPBX::set_tone(struct port_list *portlist, char *tone)
                SCPY(message->param.tone.name, tone);
                message_put(message);
                logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
+       } else
+       {
+               PDEBUG(DEBUG_EPOINT, "EPOINT(%d) no port to notify tone.\n", ea_endpoint->ep_serial);
+               return;
        }
 }
 
@@ -867,14 +866,24 @@ foundif:
                                }
                                i++;
                        }
+                       trace_header("CHANNEL SELECTION (no channel is 'free')", DIRECTION_NONE);
+                       add_trace("port", NULL, "%d", ifport->portnum);
+                       add_trace("position", NULL, "%d", index);
+                       end_trace();
                        break;
 
                        case CHANNEL_ANY: /* don't ask for channel */
                        if (mISDNport->b_reserved >= mISDNport->b_num)
                        {
+                               trace_header("CHANNEL SELECTION (cannot ask for 'any' channel, all reserved)", DIRECTION_NONE);
+                               add_trace("port", NULL, "%d", ifport->portnum);
+                               add_trace("position", NULL, "%d", index);
+                               add_trace("total", NULL, "%d", mISDNport->b_num);
+                               add_trace("reserved", NULL, "%d", mISDNport->b_reserved);
+                               end_trace();
                                break; /* all channel in use or reserverd */
                        }
-                       trace_header("CHANNEL SELECTION (using 'any channel')", DIRECTION_NONE);
+                       trace_header("CHANNEL SELECTION (using 'any' channel)", DIRECTION_NONE);
                        add_trace("port", NULL, "%d", ifport->portnum);
                        add_trace("position", NULL, "%d", index);
                        end_trace();
@@ -882,7 +891,7 @@ foundif:
                        break;
 
                        case CHANNEL_NO: /* call waiting */
-                       trace_header("CHANNEL SELECTION (using 'no channel', call-waiting)", DIRECTION_NONE);
+                       trace_header("CHANNEL SELECTION (using 'no' channel, call-waiting)", DIRECTION_NONE);
                        add_trace("port", NULL, "%d", ifport->portnum);
                        add_trace("position", NULL, "%d", index);
                        end_trace();
@@ -891,10 +900,25 @@ foundif:
 
                        default:
                        if (selchannel->channel<1 || selchannel->channel==16)
+                       {
+                               trace_header("CHANNEL SELECTION (channel out of range)", DIRECTION_NONE);
+                               add_trace("port", NULL, "%d", ifport->portnum);
+                               add_trace("position", NULL, "%d", index);
+                               add_trace("channel", NULL, "%d", selchannel->channel);
+                               end_trace();
                                break; /* invalid channels */
+                       }
                        i = selchannel->channel-1-(selchannel->channel>=17);
                        if (i >= mISDNport->b_num)
+                       {
+                               trace_header("CHANNEL SELECTION (channel out of range)", DIRECTION_NONE);
+                               add_trace("port", NULL, "%d", ifport->portnum);
+                               add_trace("position", NULL, "%d", index);
+                               add_trace("channel", NULL, "%d", selchannel->channel);
+                               add_trace("channels", NULL, "%d", mISDNport->b_num);
+                               end_trace();
                                break; /* channel not in port */
+                       }
                        if (mISDNport->b_port[i] == NULL)
                        {
                                *channel = selchannel->channel;
@@ -3419,10 +3443,13 @@ void EndpointAppPBX::join_notify(struct port_list *portlist, int message_type, u
                                /* unhold if */
                                if (new_state!=NOTIFY_STATE_HOLD && new_state!=NOTIFY_STATE_SUSPEND)
                                {
-                                       while(portlist)
+                                       if (!strcmp(e_tone, "hold")) // don't interrupt other tones
                                        {
-                                               set_tone(portlist, "");
-                                               portlist = portlist->next;
+                                               while(portlist)
+                                               {
+                                                       set_tone(portlist, "");
+                                                       portlist = portlist->next;
+                                               }
                                        }
                                        portlist = ea_endpoint->ep_portlist;
                                        e_hold = 0;
@@ -3495,6 +3522,12 @@ void EndpointAppPBX::ea_message_join(unsigned long join_id, int message_type, un
 //     PDEBUG(DEBUG_EPOINT, "EPOINT(%d) received message %d for active JOIN (terminal %s, caller id %s state=%d)\n", ea_endpoint->ep_serial, message, e_ext.number, e_callerinfo.id, e_state);
        switch(message_type)
        {
+               /* JOIN SENDS TONE message */
+               case MESSAGE_TONE:
+               PDEBUG(DEBUG_EPOINT, "EPOINT(%d) epoint with terminal '%s' (caller id '%s') received tone message: '%d'\n", ea_endpoint->ep_serial, e_ext.number, e_callerinfo.id, param->tone.name);
+               set_tone(portlist, param->tone.name);
+               break;
+
                /* JOIN SENDS CRYPT message */
                case MESSAGE_CRYPT:
                PDEBUG(DEBUG_EPOINT, "EPOINT(%d) epoint with terminal '%s' (caller id '%s') received crypt message: '%d'\n", ea_endpoint->ep_serial, e_ext.number, e_callerinfo.id, param->crypt.type);