chan_lcr: Select remote interface by chan_lcr
authorAndreas Eversberg <jolly@eversberg.eu>
Sun, 19 Aug 2012 06:36:45 +0000 (08:36 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Sun, 16 Dec 2012 09:10:34 +0000 (10:10 +0100)
Usage: Dial(LCR/<interface>/<digits>/<options>)

The interface must match the interface name in interface.conf. If omitted,
the first remote interface is used.

Example:
Dial(LCR/ast/123) will send a call to LCR and select remote interface
'ast'.
Dial(LCR//123) will send a call to LCR and select the first remote
interface.

Now it is possible to have multiple remote interfaces.

chan_lcr.c
message.h
remote.h
socket_server.c

index 2278510..657edf8 100644 (file)
@@ -646,8 +646,6 @@ static void send_setup_to_lcr(struct chan_call *call)
                strncpy(newparam.setup.dialinginfo.keypad, call->dialstring, sizeof(newparam.setup.dialinginfo.keypad)-1);
        else
                strncpy(newparam.setup.dialinginfo.id, call->dialstring, sizeof(newparam.setup.dialinginfo.id)-1);
                strncpy(newparam.setup.dialinginfo.keypad, call->dialstring, sizeof(newparam.setup.dialinginfo.keypad)-1);
        else
                strncpy(newparam.setup.dialinginfo.id, call->dialstring, sizeof(newparam.setup.dialinginfo.id)-1);
-       if (!!strcmp(call->interface, "pbx"))
-               strncpy(newparam.setup.dialinginfo.interfaces, call->interface, sizeof(newparam.setup.dialinginfo.interfaces)-1);
        newparam.setup.callerinfo.itype = INFO_ITYPE_CHAN;
        newparam.setup.callerinfo.ntype = INFO_NTYPE_UNKNOWN;
        strncpy(newparam.setup.callerinfo.display, call->display, sizeof(newparam.setup.callerinfo.display)-1);
        newparam.setup.callerinfo.itype = INFO_ITYPE_CHAN;
        newparam.setup.callerinfo.ntype = INFO_NTYPE_UNKNOWN;
        strncpy(newparam.setup.callerinfo.display, call->display, sizeof(newparam.setup.callerinfo.display)-1);
@@ -2425,6 +2423,7 @@ static int lcr_call(struct ast_channel *ast, char *dest, int timeout)
        /* send MESSAGE_NEWREF */
        memset(&newparam, 0, sizeof(union parameter));
        newparam.newref.direction = 0; /* request from app */
        /* send MESSAGE_NEWREF */
        memset(&newparam, 0, sizeof(union parameter));
        newparam.newref.direction = 0; /* request from app */
+       strncpy(newparam.newref.interface, call->interface, sizeof(newparam.newref.interface) - 1);
        send_message(MESSAGE_NEWREF, 0, &newparam);
 
        /* set hdlc if capability requires hdlc */
        send_message(MESSAGE_NEWREF, 0, &newparam);
 
        /* set hdlc if capability requires hdlc */
index 97bfddc..76adfdb 100644 (file)
--- a/message.h
+++ b/message.h
@@ -336,6 +336,7 @@ struct param_bchannel {
 
 struct param_newref {
         int direction; /* who requests a refe? */
 
 struct param_newref {
         int direction; /* who requests a refe? */
+       char interface[32]; /* interface name for selecting remote interface */
 };
 
 struct param_traffic {
 };
 
 struct param_traffic {
index eba9b2c..bdb20f3 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -1,3 +1,4 @@
+extern unsigned int new_remote;
 
 /* GSM port class */
 class Premote : public Port
 
 /* GSM port class */
 class Premote : public Port
index 7bb69fc..ac821b0 100644 (file)
@@ -618,23 +618,42 @@ int admin_message_to_lcr(struct admin_msg *msg, struct admin_list *admin)
                return(-1);
        }
 
                return(-1);
        }
 
-       /* new join. the reply (NEWREF assignment) is sent from constructor */
+       /* new remote instance. the reply (NEWREF assignment) is sent from constructor */
        if (msg->type == MESSAGE_NEWREF) {
                char name[32];
                /* find remote port */
                interface = interface_first;
                while(interface) {
        if (msg->type == MESSAGE_NEWREF) {
                char name[32];
                /* find remote port */
                interface = interface_first;
                while(interface) {
-                       if (interface->remote && !strcmp(interface->remote_app, admin->remote_name))
-                               break;
+                       /* interface must match the remote application */
+                       if (interface->remote && !strcmp(interface->remote_app, admin->remote_name)) {
+                               /* interface must match the name, if given */
+                               if (!msg->param.newref.interface[0] || !strcmp(msg->param.newref.interface, interface->name))
+                                       break;
+                       }
                        interface = interface->next;
                }
                if (!interface) {
                        union parameter param;
                        interface = interface->next;
                }
                if (!interface) {
                        union parameter param;
+                       unsigned int ref = new_remote++;
 
 
+                       start_trace(-1,
+                               NULL,
+                               NULL,
+                               NULL,
+                               DIRECTION_NONE,
+                               0,
+                               0,
+                               "REMOTE APP illegal interface");
+                       add_trace("app", "name", "%s", admin->remote_name);
+                       add_trace("interface", "name", "%s", msg->param.newref.interface);
+                       end_trace();
+                       memset(&param, 0, sizeof(union parameter));
+                       param.newref.direction = 0;
+                       admin_message_from_lcr(admin->sock, ref, MESSAGE_NEWREF, &param);
                        memset(&param, 0, sizeof(union parameter));
                        param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
                        param.disconnectinfo.cause = CAUSE_RESSOURCEUNAVAIL;
                        memset(&param, 0, sizeof(union parameter));
                        param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
                        param.disconnectinfo.cause = CAUSE_RESSOURCEUNAVAIL;
-                       admin_message_from_lcr(admin->sock, 0, MESSAGE_RELEASE, &param);
+                       admin_message_from_lcr(admin->sock, ref, MESSAGE_RELEASE, &param);
                        return 0;
                }
                /* creating port object, transparent until setup with hdlc */
                        return 0;
                }
                /* creating port object, transparent until setup with hdlc */