From 3fd4b07e3f98f57c85978c02dcd8dfb35664ef82 Mon Sep 17 00:00:00 2001 From: Kai Kreuzer Date: Wed, 18 Oct 2023 19:00:49 +0200 Subject: [PATCH] [ipcamera] Handle empty snapshotUrls and XML encoded characters (#15707) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [ipcamera] Handle empty snapshotUrls and XML encoded characters * use unescape method from StringUtils --------- Signed-off-by: Kai Kreuzer Signed-off-by: Jørgen Austvik --- .../internal/onvif/OnvifConnection.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java index bbc5bec9d1098..161884d058767 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java @@ -40,6 +40,7 @@ import org.openhab.core.library.types.OnOffType; import org.openhab.core.thing.ChannelUID; import org.openhab.core.types.StateOption; +import org.openhab.core.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,6 +69,7 @@ * The {@link OnvifConnection} This is a basic Netty implementation for connecting and communicating to ONVIF cameras. * * @author Matthew Skinner - Initial contribution + * @author Kai Kreuzer - Improve handling for certain cameras */ @NonNullByDefault @@ -358,17 +360,23 @@ public void processReply(String message) { } else if (message.contains("GetDeviceInformationResponse")) { logger.debug("GetDeviceInformationResponse received"); } else if (message.contains("GetSnapshotUriResponse")) { - snapshotUri = removeIPfromUrl(Helper.fetchXML(message, ":MediaUri", ":Uri")); - logger.debug("GetSnapshotUri:{}", snapshotUri); - if (ipCameraHandler.snapshotUri.isEmpty() - && !"ffmpeg".equals(ipCameraHandler.cameraConfig.getSnapshotUrl())) { - ipCameraHandler.snapshotUri = snapshotUri; + String url = Helper.fetchXML(message, ":MediaUri", ":Uri"); + if (!url.isBlank()) { + snapshotUri = removeIPfromUrl(url); + logger.debug("GetSnapshotUri: {}", snapshotUri); + if (ipCameraHandler.snapshotUri.isEmpty() + && !"ffmpeg".equals(ipCameraHandler.cameraConfig.getSnapshotUrl())) { + ipCameraHandler.snapshotUri = snapshotUri; + } } } else if (message.contains("GetStreamUriResponse")) { - rtspUri = Helper.fetchXML(message, ":MediaUri", ":Uri>"); - logger.debug("GetStreamUri:{}", rtspUri); - if (ipCameraHandler.cameraConfig.getFfmpegInput().isEmpty()) { - ipCameraHandler.rtspUri = rtspUri; + String xml = StringUtils.unEscapeXml(Helper.fetchXML(message, ":MediaUri", ":Uri>")); + if (xml != null) { + rtspUri = xml; + logger.debug("GetStreamUri: {}", rtspUri); + if (ipCameraHandler.cameraConfig.getFfmpegInput().isEmpty()) { + ipCameraHandler.rtspUri = rtspUri; + } } } } @@ -564,7 +572,6 @@ public void initChannel(SocketChannel socketChannel) throws Exception { } if (!mainEventLoopGroup.isShuttingDown()) { localBootstap.connect(new InetSocketAddress(ipAddress, onvifPort)).addListener(new ChannelFutureListener() { - @Override public void operationComplete(@Nullable ChannelFuture future) { if (future == null) {