fixed overlap dialing problem:
authorSuper User <root@isdn.jolly.ten>
Thu, 24 Jul 2008 17:19:56 +0000 (19:19 +0200)
committerSuper User <root@isdn.jolly.ten>
Thu, 24 Jul 2008 17:19:56 +0000 (19:19 +0200)
-> YES, you may now overlap dial through asterisk

fixed answering call when bridging, because asterisk will not call lcr_answer when bridging.

modified:   chan_lcr.c

chan_lcr.c

index 7eabe0e..5978865 100644 (file)
@@ -690,7 +690,6 @@ static void lcr_start_pbx(struct chan_call *call, struct ast_channel *ast, int c
 
                /* change state */
                call->state = CHAN_LCR_STATE_IN_PROCEEDING;
 
                /* change state */
                call->state = CHAN_LCR_STATE_IN_PROCEEDING;
-               ast_setstate(ast, AST_STATE_OFFHOOK);
 
                goto start;
        }
 
                goto start;
        }
@@ -705,7 +704,6 @@ static void lcr_start_pbx(struct chan_call *call, struct ast_channel *ast, int c
 
                /* change state */
                call->state = CHAN_LCR_STATE_IN_DIALING;
 
                /* change state */
                call->state = CHAN_LCR_STATE_IN_DIALING;
-               ast_setstate(ast, AST_STATE_OFFHOOK);
 
                /* if match, start pbx */
                if (ast_exists_extension(ast, ast->context, ast->exten, 1, call->oad)) {
 
                /* if match, start pbx */
                if (ast_exists_extension(ast, ast->context, ast->exten, 1, call->oad)) {
@@ -742,6 +740,10 @@ static void lcr_start_pbx(struct chan_call *call, struct ast_channel *ast, int c
                goto release;
        }
        call->pbx_started = 1;
                goto release;
        }
        call->pbx_started = 1;
+//     if (call->state == CHAN_LCR_STATE_IN_DIALING)
+//             ast_setstate(ast, AST_STATE_DIALING);
+//     else
+//             ast_setstate(ast, AST_STATE_OFFHOOK);
        return;
 }
 
        return;
 }
 
@@ -996,6 +998,13 @@ static void lcr_in_information(struct chan_call *call, int message_type, union p
                return;
        }
        
                return;
        }
        
+       /* change dailing state after setup */
+       if (call->state == CHAN_LCR_STATE_IN_SETUP) {
+               CDEBUG(call, call->ast, "Changing from SETUP to DIALING state.\n");
+               call->state = CHAN_LCR_STATE_IN_DIALING;
+//             ast_setstate(ast, AST_STATE_DIALING);
+       }
+       
        /* queue digits */
        if (call->state == CHAN_LCR_STATE_IN_DIALING && param->information.id[0])
                strncat(call->queue_string, param->information.id, sizeof(call->queue_string)-1);
        /* queue digits */
        if (call->state == CHAN_LCR_STATE_IN_DIALING && param->information.id[0])
                strncat(call->queue_string, param->information.id, sizeof(call->queue_string)-1);
@@ -1520,10 +1529,11 @@ static int queue_send(void)
                                                CDEBUG(call, ast, "Sending queued digit '%c' to Asterisk.\n", *p);
                                                /* send digit to asterisk */
                                                memset(&fr, 0, sizeof(fr));
                                                CDEBUG(call, ast, "Sending queued digit '%c' to Asterisk.\n", *p);
                                                /* send digit to asterisk */
                                                memset(&fr, 0, sizeof(fr));
-                                               fr.frametype = AST_FRAME_DTMF;
+                                               fr.frametype = AST_FRAME_DTMF_BEGIN;
                                                fr.subclass = *p;
                                                fr.delivery = ast_tv(0, 0);
                                                fr.subclass = *p;
                                                fr.delivery = ast_tv(0, 0);
-                                               fr.len = 100;
+                                               ast_queue_frame(ast, &fr);
+                                               fr.frametype = AST_FRAME_DTMF_END;
                                                ast_queue_frame(ast, &fr);
                                                break;
                                        default:
                                                ast_queue_frame(ast, &fr);
                                                break;
                                        default:
@@ -1823,17 +1833,19 @@ static int lcr_answer(struct ast_channel *ast)
                return -1;
        }
        
                return -1;
        }
        
-       CDEBUG(call, ast, "Received answer from Asterisk.\n");
+       CDEBUG(call, ast, "Received answer from Asterisk (maybe during lcr_bridge).\n");
                
        /* copy connectinfo, if bridged */
        if (call->bridge_call)
                memcpy(&call->connectinfo, &call->bridge_call->connectinfo, sizeof(struct connect_info));
        /* send connect message to lcr */
                
        /* copy connectinfo, if bridged */
        if (call->bridge_call)
                memcpy(&call->connectinfo, &call->bridge_call->connectinfo, sizeof(struct connect_info));
        /* send connect message to lcr */
-       memset(&newparam, 0, sizeof(union parameter));
-       memcpy(&newparam.connectinfo, &call->connectinfo, sizeof(struct connect_info));
-       send_message(MESSAGE_CONNECT, call->ref, &newparam);
+       if (call->state != CHAN_LCR_STATE_CONNECT) {
+               memset(&newparam, 0, sizeof(union parameter));
+               memcpy(&newparam.connectinfo, &call->connectinfo, sizeof(struct connect_info));
+               send_message(MESSAGE_CONNECT, call->ref, &newparam);
+               call->state = CHAN_LCR_STATE_CONNECT;
+       }
        /* change state */
        /* change state */
-       call->state = CHAN_LCR_STATE_CONNECT;
        /* request bchannel */
        if (!call->bchannel) {
                CDEBUG(call, ast, "Requesting B-channel.\n");
        /* request bchannel */
        if (!call->bchannel) {
                CDEBUG(call, ast, "Requesting B-channel.\n");
@@ -2143,7 +2155,7 @@ enum ast_bridge_result lcr_bridge(struct ast_channel *ast1,
 
        carr[0] = ast1;
        carr[1] = ast2;
 
        carr[0] = ast1;
        carr[1] = ast2;
-       
+
        /* join via dsp (if the channels are currently open) */
        ast_mutex_lock(&chan_lock);
        bridge_id = new_bridge_id();
        /* join via dsp (if the channels are currently open) */
        ast_mutex_lock(&chan_lock);
        bridge_id = new_bridge_id();
@@ -2163,6 +2175,22 @@ enum ast_bridge_result lcr_bridge(struct ast_channel *ast1,
                        bchannel_join(call2->bchannel, bridge_id);
                call2->bridge_call = call1;
        }
                        bchannel_join(call2->bchannel, bridge_id);
                call2->bridge_call = call1;
        }
+
+       if (call1->state == CHAN_LCR_STATE_IN_SETUP
+        || call1->state == CHAN_LCR_STATE_IN_DIALING
+        || call1->state == CHAN_LCR_STATE_IN_PROCEEDING
+        || call1->state == CHAN_LCR_STATE_IN_ALERTING) {
+               CDEBUG(call1, ast1, "Bridge established before lcr_answer, so we call it ourself: Calling lcr_answer...\n");
+               lcr_answer(ast1);
+       }
+       if (call2->state == CHAN_LCR_STATE_IN_SETUP
+        || call2->state == CHAN_LCR_STATE_IN_DIALING
+        || call2->state == CHAN_LCR_STATE_IN_PROCEEDING
+        || call2->state == CHAN_LCR_STATE_IN_ALERTING) {
+               CDEBUG(call2, ast2, "Bridge established before lcr_answer, so we call it ourself: Calling lcr_answer...\n");
+               lcr_answer(ast2);
+       }
+       
        ast_mutex_unlock(&chan_lock);
        
        while(1) {
        ast_mutex_unlock(&chan_lock);
        
        while(1) {