Skip to content

Commit

Permalink
[ipcamera] Handle empty snapshotUrls and XML encoded characters (open…
Browse files Browse the repository at this point in the history
…hab#15707)

* [ipcamera] Handle empty snapshotUrls and XML encoded characters
* use unescape method from StringUtils

---------

Signed-off-by: Kai Kreuzer <kai@openhab.org>
Signed-off-by: querdenker2k <querdenker2k@gmx.de>
  • Loading branch information
kaikreuzer authored and querdenker2k committed Oct 29, 2023
1 parent 3a9eb8e commit 0371bd3
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0371bd3

Please sign in to comment.