Skip to content

Commit

Permalink
[ipcamera] Improvements and fix 503 errors go to offline with Hik (op…
Browse files Browse the repository at this point in the history
…enhab#11419)

* Stop hik logging 401 with digest.

Signed-off-by: Matthew Skinner <[email protected]>

* Improve and fix generic cams


Signed-off-by: Matthew Skinner <[email protected]>

* Stop dahua IntelliFrame logging


Signed-off-by: Matthew Skinner <[email protected]>

* Catch IllegalStateException


Signed-off-by: Matthew Skinner <[email protected]>

* Trial reusing channels.


Signed-off-by: Matthew Skinner <[email protected]>

* Tidy up


Signed-off-by: Matthew Skinner <[email protected]>

* cleanup 2


Signed-off-by: Matthew Skinner <[email protected]>

* Cleanup 3


Signed-off-by: Matthew Skinner <[email protected]>

* Disable checking connection with event stream.


Signed-off-by: Matthew Skinner <[email protected]>

* Bug fix


Signed-off-by: Matthew Skinner <[email protected]>

* more cleanup


Signed-off-by: Matthew Skinner <[email protected]>

* more cleanup

Signed-off-by: Matthew Skinner <[email protected]>

* Reduce logging to only whats needed.


Signed-off-by: Matthew Skinner <[email protected]>

* fix offline detection.


Signed-off-by: Matthew Skinner <[email protected]>

* fixes to ipcamera.mjpeg


Signed-off-by: Matthew Skinner <[email protected]>

* reverse some connection checks


Signed-off-by: Matthew Skinner <[email protected]>
  • Loading branch information
Skinah authored and Nemer_Daud committed Jan 28, 2022
1 parent 2799a1f commit 38143e7
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.jdt.annotation.NonNullByDefault;

import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;

/**
* The {@link ChannelTracking} Can be used to find the handle for a HTTP channel if you know the URL. The reply can
Expand Down Expand Up @@ -43,6 +44,15 @@ public Channel getChannel() {
return channel;
}

/**
* Closes the channel, but keeps the HTTP reply stored in the tracker.
*
* @return ChannelFuture
*/
public ChannelFuture closeChannel() {
return channel.close();
}

public String getReply() {
return storedReply;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public DahuaHandler(IpCameraHandler handler, int nvrChannel) {
}

private void processEvent(String content) {
int startIndex = content.indexOf("Code=", 12) + 5;// skip --myboundary
int startIndex = content.indexOf("Code=", 12) + 5;// skip --myboundary and Code=
int endIndex = content.indexOf(";", startIndex + 1);
if (startIndex == -1 || endIndex == -1) {
ipCameraHandler.logger.debug("Code= not found in Dahua event. Content was:{}", content);
Expand Down Expand Up @@ -177,7 +177,9 @@ private void processEvent(String content) {
case "LensMaskClose":
ipCameraHandler.setChannelState(CHANNEL_ENABLE_PRIVACY_MODE, OnOffType.OFF);
break;
// Skip these so they are not logged.
case "TimeChange":
case "IntelliFrame":
case "NTPAdjustTime":
case "StorageChange":
case "Reboot":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void checkKeepAlive() {
}

private class IpCameraFfmpegThread extends Thread {
private ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(2);
private ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(1);
public int countOfMotions;

IpCameraFfmpegThread() {
Expand Down Expand Up @@ -220,6 +220,7 @@ public void stopConverting() {
Process localProcess = process;
if (localProcess != null) {
localProcess.destroyForcibly();
process = null;
}
if (format.equals(FFmpegFormat.HLS)) {
ipCameraHandler.setChannelState(CHANNEL_START_STREAM, OnOffType.OFF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ public void channelRead(@Nullable ChannelHandlerContext ctx, @Nullable Object ms
}
}
break;
default:
logger.debug("Unhandled reply-{}.", content);
break;
}
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public void processAuth(String authenticate, String httpMethod, String requestUR
/////// Fresh Digest Authenticate method follows as Basic is already handled and returned ////////
realm = Helper.searchString(authenticate, "realm=\"");
if (realm.isEmpty()) {
logger.warn("Could not find a valid WWW-Authenticate response in :{}", authenticate);
logger.warn(
"No valid WWW-Authenticate in response. Has the camera activated the illegal login lock? Details:{}",
authenticate);
return;
}
nonce = Helper.searchString(authenticate, "nonce=\"");
Expand Down Expand Up @@ -142,23 +144,17 @@ public void channelRead(@Nullable ChannelHandlerContext ctx, @Nullable Object ms
if (msg == null || ctx == null) {
return;
}
boolean closeConnection = true;
String authenticate = "";
if (msg instanceof HttpResponse) {
HttpResponse response = (HttpResponse) msg;
if (response.status().code() == 401) {
ctx.close();
if (!response.headers().isEmpty()) {
String authenticate = "";
for (CharSequence name : response.headers().names()) {
for (CharSequence value : response.headers().getAll(name)) {
if (name.toString().equalsIgnoreCase("WWW-Authenticate")) {
authenticate = value.toString();
}
if (name.toString().equalsIgnoreCase("Connection")
&& value.toString().contains("keep-alive")) {
// closeConnection = false;
// trial this for a while to see if it solves too many bytes with digest turned on.
closeConnection = true;
}
}
}
if (!authenticate.isEmpty()) {
Expand All @@ -167,24 +163,22 @@ public void channelRead(@Nullable ChannelHandlerContext ctx, @Nullable Object ms
ipCameraHandler.cameraConfigError(
"Camera gave no WWW-Authenticate: Your login details must be wrong.");
}
if (closeConnection) {
ctx.close();// needs to be here
}
}
} else if (response.status().code() != 200) {
logger.debug("Camera at IP:{} gave a reply with a response code of :{}",
ipCameraHandler.cameraConfig.getIp(), response.status().code());
ctx.close();
switch (response.status().code()) {
case 403:
logger.warn(
"403 Forbidden: Check camera setup or has the camera activated the illegal login lock?");
break;
default:
logger.debug("Camera at IP:{} gave a reply with a response code of :{}",
ipCameraHandler.cameraConfig.getIp(), response.status().code());
break;
}
}
}
// Pass the Message back to the pipeline for the next handler to process//
super.channelRead(ctx, msg);
}

@Override
public void handlerAdded(@Nullable ChannelHandlerContext ctx) {
}

@Override
public void handlerRemoved(@Nullable ChannelHandlerContext ctx) {
}
}
Loading

0 comments on commit 38143e7

Please sign in to comment.