LCR now runs as a user.
[lcr.git] / chan_lcr.c
index 8d46357..52c2a31 100644 (file)
@@ -295,6 +295,7 @@ struct chan_call *alloc_call(void)
                free_call(*callp);
                return(NULL);
        }
+       fcntl((*callp)->pipe[0], F_SETFL, O_NONBLOCK);
        CDEBUG(*callp, NULL, "Call instance allocated.\n");
        return(*callp);
 }
@@ -476,7 +477,7 @@ void apply_opt(struct chan_call *call, char *data)
                                bchannel_pipeline(call->bchannel, call->pipeline);
                        break;
                case 'r':
-                       if (opt[1] == '\0') {
+                       if (opt[1] != '\0') {
                                CERROR(call, call->ast, "Option 'r' (re-buffer 160 bytes) expects no parameter.\n", opt);
                                break;
                        }
@@ -592,8 +593,12 @@ static void send_setup_to_lcr(struct chan_call *call)
        }
        newparam.setup.capainfo.bearer_capa = ast->transfercapability;
        newparam.setup.capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
-       if (!call->hdlc)
+       if (call->hdlc)
+               newparam.setup.capainfo.source_mode = B_MODE_HDLC;
+       else {
+               newparam.setup.capainfo.source_mode = B_MODE_TRANSPARENT;
                newparam.setup.capainfo.bearer_info1 = (options.law=='a')?3:2;
+       }
        newparam.setup.capainfo.hlc = INFO_HLC_NONE;
        newparam.setup.capainfo.exthlc = INFO_HLC_NONE;
        send_message(MESSAGE_SETUP, call->ref, &newparam);
@@ -742,10 +747,10 @@ static void lcr_start_pbx(struct chan_call *call, struct ast_channel *ast, int c
        }
        call->pbx_started = 1;
 //     if (call->state == CHAN_LCR_STATE_IN_DIALING)
-//             ast_setstate(ast, AST_STATE_DIALING);
+               ast_setstate(ast, AST_STATE_RINGING);
 //     else
-//             ast_setstate(ast, AST_STATE_OFFHOOK);
-       return;
+//             ast_setstate(ast, AST_STATE_RINGING);
+//     return;
 }
 
 /*
@@ -814,9 +819,7 @@ static void lcr_in_setup(struct chan_call *call, int message_type, union paramet
        }
        ast->transfercapability = param->setup.capainfo.bearer_capa;
        /* enable hdlc if transcap is data */
-       if (ast->transfercapability == INFO_BC_DATAUNRESTRICTED
-        || ast->transfercapability == INFO_BC_DATARESTRICTED
-        || ast->transfercapability == INFO_BC_VIDEO)
+       if (param->setup.capainfo.source_mode == B_MODE_HDLC)
                call->hdlc = 1;
        strncpy(call->oad, numberrize_callerinfo(param->setup.callerinfo.id, param->setup.callerinfo.ntype, options.national, options.international), sizeof(call->oad)-1);
 
@@ -1425,7 +1428,6 @@ int handle_socket(void)
 int open_socket(void)
 {
        int ret;
-       char *socket_name = SOCKET_NAME;
        int conn;
        struct sockaddr_un sock_address;
        unsigned int on = 1;
@@ -1441,7 +1443,7 @@ int open_socket(void)
        /* set socket address and name */
        memset(&sock_address, 0, sizeof(sock_address));
        sock_address.sun_family = PF_UNIX;
-       strcpy(sock_address.sun_path, socket_name);
+       sprintf(sock_address.sun_path, SOCKET_NAME, options.lock);
 
        /* connect socket */
        if ((conn = connect(lcr_sock, (struct sockaddr *)&sock_address, SUN_LEN(&sock_address))) < 0)
@@ -1962,9 +1964,14 @@ static struct ast_frame *lcr_read(struct ast_channel *ast)
                } else {
                        len = read(call->pipe[0], call->read_buff, sizeof(call->read_buff));
                }
+               if (len < 0 && errno == EAGAIN) {
+                       ast_mutex_unlock(&chan_lock);
+                       return &ast_null_frame;
+               }
                if (len <= 0) {
                        close(call->pipe[0]);
                        call->pipe[0] = -1;
+                       ast_mutex_unlock(&chan_lock);
                        return NULL;
                }
        }
@@ -2088,21 +2095,25 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz
 /*
  * fixup asterisk
  */
-static int lcr_fixup(struct ast_channel *oldast, struct ast_channel *newast)
+static int lcr_fixup(struct ast_channel *oldast, struct ast_channel *ast)
 {
         struct chan_call *call;
 
+       if (!ast) {
+               return -1;
+       }
+
        ast_mutex_lock(&chan_lock);
-       call = oldast->tech_pvt;
+       call = ast->tech_pvt;
        if (!call) {
-               CERROR(NULL, oldast, "Received fixup from Asterisk, but no call instance exists.\n");
+               CERROR(NULL, ast, "Received fixup from Asterisk, but no call instance exists.\n");
                ast_mutex_unlock(&chan_lock);
                return -1;
        }
 
-       CDEBUG(call, oldast, "Received fixup from Asterisk.\n");
-       call->ast = newast;
-       ast_mutex_lock(&chan_lock);
+       CDEBUG(call, ast, "Received fixup from Asterisk.\n");
+       call->ast = ast;
+       ast_mutex_unlock(&chan_lock);
        return 0;
 }