From bd2aa91302a9d2de07d2210cbd6da499f3e45e53 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 19 Aug 2012 08:36:45 +0200 Subject: [PATCH] chan_lcr: Select remote interface by chan_lcr Usage: Dial(LCR///) 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 | 3 +-- message.h | 1 + remote.h | 1 + socket_server.c | 27 +++++++++++++++++++++++---- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/chan_lcr.c b/chan_lcr.c index 2278510..657edf8 100644 --- a/chan_lcr.c +++ b/chan_lcr.c @@ -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); - 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); @@ -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 */ + strncpy(newparam.newref.interface, call->interface, sizeof(newparam.newref.interface) - 1); send_message(MESSAGE_NEWREF, 0, &newparam); /* set hdlc if capability requires hdlc */ diff --git a/message.h b/message.h index 97bfddc..76adfdb 100644 --- a/message.h +++ b/message.h @@ -336,6 +336,7 @@ struct param_bchannel { struct param_newref { int direction; /* who requests a refe? */ + char interface[32]; /* interface name for selecting remote interface */ }; struct param_traffic { diff --git a/remote.h b/remote.h index eba9b2c..bdb20f3 100644 --- a/remote.h +++ b/remote.h @@ -1,3 +1,4 @@ +extern unsigned int new_remote; /* GSM port class */ class Premote : public Port diff --git a/socket_server.c b/socket_server.c index 7bb69fc..ac821b0 100644 --- a/socket_server.c +++ b/socket_server.c @@ -618,23 +618,42 @@ int admin_message_to_lcr(struct admin_msg *msg, struct admin_list *admin) 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 (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; + 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(¶m, 0, sizeof(union parameter)); + param.newref.direction = 0; + admin_message_from_lcr(admin->sock, ref, MESSAGE_NEWREF, ¶m); memset(¶m, 0, sizeof(union parameter)); param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; param.disconnectinfo.cause = CAUSE_RESSOURCEUNAVAIL; - admin_message_from_lcr(admin->sock, 0, MESSAGE_RELEASE, ¶m); + admin_message_from_lcr(admin->sock, ref, MESSAGE_RELEASE, ¶m); return 0; } /* creating port object, transparent until setup with hdlc */ -- 2.13.6