From 79a3a28b3421f06960871db0c4fb6927b9c39575 Mon Sep 17 00:00:00 2001 From: Ingo Bauersachs Date: Sun, 15 Jan 2017 01:53:25 +0100 Subject: BLF: Enable plugin and add workaround for Asterisk --- .../sip/OperationSetTelephonyBLFSipImpl.java | 72 +++++++++++++++++----- .../sip/ProtocolProviderServiceSipImpl.java | 12 ++-- .../plugin/busylampfield/BLFActivator.java | 10 +-- .../service/protocol/OperationSetTelephonyBLF.java | 18 +++++- 4 files changed, 84 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetTelephonyBLFSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetTelephonyBLFSipImpl.java index 644c85a..a9aefbe 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetTelephonyBLFSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetTelephonyBLFSipImpl.java @@ -72,6 +72,10 @@ public class OperationSetTelephonyBLFSipImpl * Account property suffix to set/provision monitored line group. */ public static final String BLF_LINE_GROUP_ACC_PROP_PREFIX = "Group"; + /** + * Account property suffix to set/provision monitored line pickup template. + */ + public static final String BLF_LINE_PICKUP_ACC_PROP_PREFIX = "Pickup"; /** * The name of the event package supported by @@ -195,7 +199,7 @@ public class OperationSetTelephonyBLFSipImpl String[] lineValues = lines.get(ix); if(lineValues == null) { - lineValues = new String[3]; + lineValues = new String[4]; lines.put(ix, lineValues); } @@ -211,13 +215,17 @@ public class OperationSetTelephonyBLFSipImpl { lineValues[2] = entryValue; } + else if(pName.contains(BLF_LINE_PICKUP_ACC_PROP_PREFIX)) + { + lineValues[3] = entryValue; + } } for(Map.Entry en : lines.entrySet()) { String[] vals = en.getValue(); - this.lines.add(new Line(vals[0], vals[1], vals[2], this.provider)); + this.lines.add(new Line(vals[0], vals[1], vals[2], vals[3], this.provider)); } } @@ -263,16 +271,25 @@ public class OperationSetTelephonyBLFSipImpl if(details == null) return; - if(StringUtils.isNullOrEmpty(details.callID) - || StringUtils.isNullOrEmpty(details.localTag) - || StringUtils.isNullOrEmpty(details.remoteTag)) - return; - // replaces Address targetAddress = null; try { - targetAddress = provider.parseAddressString(line.getAddress()); + String address = line.getAddress(); + if(asteriskMode(details)) + { + // broken mode for Asterisk, doesn't provide us with + // the proper call-id, etc. attributes. + // send an unspecified pickup-call if a template is set + if (StringUtils.isNullOrEmpty(line.getPickupTemplate(), true)) + { + return; + } + + address = line.getPickupTemplate().replace("\\1", address); + } + + targetAddress = provider.parseAddressString(address); } catch (ParseException ex) { @@ -281,6 +298,16 @@ public class OperationSetTelephonyBLFSipImpl OperationFailedException.ILLEGAL_ARGUMENT, ex, logger); } + OperationSetBasicTelephonySipImpl telOpSet + = (OperationSetBasicTelephonySipImpl)provider + .getOperationSet(OperationSetBasicTelephony.class); + + if (asteriskMode(details)) + { + telOpSet.createOutgoingCall(targetAddress, null, null); + return; + } + Replaces replacesHeader = null; SipURI sipURI = (SipURI) targetAddress.getURI(); @@ -315,12 +342,14 @@ public class OperationSetTelephonyBLFSipImpl OperationFailedException.INTERNAL_ERROR, ex, logger); } - OperationSetBasicTelephonySipImpl telOpSet - = (OperationSetBasicTelephonySipImpl)provider - .getOperationSet(OperationSetBasicTelephony.class); - - CallSipImpl call - = telOpSet.createOutgoingCall(targetAddress, null, null); + telOpSet.createOutgoingCall(targetAddress, null, null); + } + + private boolean asteriskMode(LineDetails details) + { + return StringUtils.isNullOrEmpty(details.callID) + || StringUtils.isNullOrEmpty(details.localTag) + || StringUtils.isNullOrEmpty(details.remoteTag); } /** @@ -549,6 +578,8 @@ public class OperationSetTelephonyBLFSipImpl Node dialogNode = dialogList.item(i); Element dialogElem = (Element)dialogNode; + details.id = dialogElem.getAttribute("id"); + details.direction = dialogElem.getAttribute("direction"); details.callID = dialogElem.getAttribute("call-id"); details.localTag = dialogElem.getAttribute("local-tag"); details.remoteTag = dialogElem.getAttribute("remote-tag"); @@ -698,12 +729,25 @@ public class OperationSetTelephonyBLFSipImpl */ private class LineDetails { + /** * The current status of the line, the last event fired for it. */ int lastStatusEvent = BLFStatusEvent.STATUS_OFFLINE; /** + * id of the dialog. Mandatory. + */ + String id = null; + + /** + * either initiator or recipient, and indicates whether the observed + * user was the initiator of the dialog, or the recipient of the INVITE + * that created it. + */ + String direction; + + /** * call-id of the dialog if any, used for remote pickup. */ String callID = null; diff --git a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java index 009af86..a2a98b8 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java @@ -1589,16 +1589,16 @@ public class ProtocolProviderServiceSipImpl Set instances = new HashSet(); BundleContext context = SipActivator.getBundleContext(); - ServiceReference[] references = context.getServiceReferences( - ProtocolProviderService.class.getName(), - null - ); - for(ServiceReference reference : references) + Collection> references = + context.getServiceReferences(ProtocolProviderService.class, + null); + for(ServiceReference ref : references) { - Object service = context.getService(reference); + ProtocolProviderService service = context.getService(ref); if(service instanceof ProtocolProviderServiceSipImpl) instances.add((ProtocolProviderServiceSipImpl) service); } + return instances; } catch(InvalidSyntaxException ex) diff --git a/src/net/java/sip/communicator/plugin/busylampfield/BLFActivator.java b/src/net/java/sip/communicator/plugin/busylampfield/BLFActivator.java index 036442b..94ea374 100644 --- a/src/net/java/sip/communicator/plugin/busylampfield/BLFActivator.java +++ b/src/net/java/sip/communicator/plugin/busylampfield/BLFActivator.java @@ -181,15 +181,11 @@ public class BLFActivator } else { - BLFContactSourceService css - = new BLFContactSourceService( + BLFContactSourceService css = new BLFContactSourceService( groupName, currentBLFGroups.size() + 1); - serviceReg = (ServiceRegistration) - bundleContext.registerService( - ContactSourceService.class.getName(), - css, - null); + serviceReg = bundleContext.registerService( + ContactSourceService.class, css, null); currentBLFGroups.put(groupName, serviceReg); css.addLine(line); diff --git a/src/net/java/sip/communicator/service/protocol/OperationSetTelephonyBLF.java b/src/net/java/sip/communicator/service/protocol/OperationSetTelephonyBLF.java index 028c2ae..f6a50dc 100644 --- a/src/net/java/sip/communicator/service/protocol/OperationSetTelephonyBLF.java +++ b/src/net/java/sip/communicator/service/protocol/OperationSetTelephonyBLF.java @@ -80,6 +80,11 @@ public interface OperationSetTelephonyBLF private String group; /** + * Asterisk pickup prefix. + */ + private String pickupTemplate; + + /** * The parent provider. */ private ProtocolProviderService provider; @@ -90,14 +95,16 @@ public interface OperationSetTelephonyBLF * @param address the address of the line. * @param name the display name if any * @param group the group name if any + * @param pickup the pickup dial template * @param provider the parent provider. */ - public Line(String address, String name, String group, + public Line(String address, String name, String group, String pickup, ProtocolProviderService provider) { this.address = address; this.name = name; this.group = group; + this.pickupTemplate = pickup; this.provider = provider; } @@ -129,6 +136,15 @@ public interface OperationSetTelephonyBLF } /** + * The pickup template. + * @return the pickup template. + */ + public String getPickupTemplate() + { + return pickupTemplate; + } + + /** * The provider. * @return the provider. */ -- cgit v1.1