Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ZoneMinder/zoneminder
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Connor committed Oct 22, 2024
2 parents 5ff4bee + b273db2 commit bbe366f
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 183 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ if(NOT ZM_NO_MQTT)
find_package(MOSQUITTO)
if(MOSQUITTO_FOUND)
include_directories(${MOSQUITTO_INCLUDE_DIRS})
list(APPEND ZM_BIN_LIBS "${MOSQUITTO_LIBRARIES}")
list(APPEND ZM_BIN_LIBS "${MOSQUITTO_LIBRARY}")
set(optlibsfound "${optlibsfound} Mosquitto")
else()
set(optlibsnotfound "${optlibsnotfound} Mosquitto")
Expand All @@ -454,7 +454,7 @@ if(NOT ZM_NO_MQTT)
find_package(MOSQUITTOPP)
if(MOSQUITTOPP_FOUND)
include_directories(${MOSQUITTOPP_INCLUDE_DIRS})
list(APPEND ZM_BIN_LIBS "${MOSQUITTOPP_LIBRARIES}")
list(APPEND ZM_BIN_LIBS "${MOSQUITTOPP_LIBRARY}")
set(optlibsfound "${optlibsfound} Mosquittopp")
else()
set(optlibsnotfound "${optlibsnotfound} Mosquittopp")
Expand Down
83 changes: 0 additions & 83 deletions dep/jwt-cpp/jwt-cpp-config-version.cmake

This file was deleted.

43 changes: 0 additions & 43 deletions dep/jwt-cpp/jwt-cpp-config.cmake

This file was deleted.

58 changes: 32 additions & 26 deletions scripts/zmx10.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ $ENV{PATH} = '/bin:/usr/bin:/usr/local/bin';
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};

logInit();
logSetSignal();

my $command;
my $unit_code;
my $version;
Expand All @@ -102,6 +99,16 @@ if ( $command eq 'start' ) {
exit();
}

logInit();
logSetSignal();
my $zm_terminate = 0;
sub TermHandler {
Info('Received TERM, exiting');
$zm_terminate = 1;
}
$SIG{TERM} = \&TermHandler;
$SIG{INT} = \&TermHandler;

socket(CLIENT, PF_UNIX, SOCK_STREAM, 0)
or Fatal("Can't open socket: $!");

Expand All @@ -116,10 +123,8 @@ if ( !connect(CLIENT, $saddr) ) {
# Parent process just sleep and fall through
sleep(2);
logReinit();
socket(CLIENT, PF_UNIX, SOCK_STREAM, 0)
or Fatal("Can't open socket: $!");
connect(CLIENT, $saddr)
or Fatal("Can't connect: $!");
socket(CLIENT, PF_UNIX, SOCK_STREAM, 0) or Fatal("Can't open socket: $!");
connect(CLIENT, $saddr) or Fatal("Can't connect: $!");
} elsif ( defined($cpid) ) {
setpgrp();

Expand All @@ -130,7 +135,6 @@ if ( !connect(CLIENT, $saddr) ) {
}
}
# The server is there, connect to it
#print( "Writing commands\n" );
CLIENT->autoflush();
my $message = $command;
$message .= ';'.$unit_code if $unit_code;
Expand All @@ -141,7 +145,6 @@ while ( my $line = <CLIENT> ) {
print("$line\n");
}
close(CLIENT);
#print( "Finished writing, bye\n" );
exit;

#
Expand Down Expand Up @@ -173,8 +176,7 @@ our %pending_tasks;
sub runServer {
Info('X10 server starting');

socket(SERVER, PF_UNIX, SOCK_STREAM, 0)
or Fatal("Can't open socket: $!");
socket(SERVER, PF_UNIX, SOCK_STREAM, 0) or Fatal("Can't open socket: $!");
unlink(main::SOCK_FILE);
my $saddr = sockaddr_un(main::SOCK_FILE);
bind(SERVER, $saddr) or Fatal("Can't bind: $!");
Expand All @@ -185,7 +187,7 @@ sub runServer {
$x10 = new X10::ActiveHome(
port=>$Config{ZM_X10_DEVICE},
house_code=>$Config{ZM_X10_HOUSE_CODE},
debug=>0
debug=>1
);
Fatal("Failed to open x10 device at $Config{ZM_X10_DEVICE}") if !$x10;

Expand All @@ -194,20 +196,22 @@ sub runServer {
$x10->register_listener(\&x10listen);

my $rin = '';
vec($rin, fileno(SERVER),1) = 1;
vec($rin, $x10->select_fds(),1) = 1;
my $timeout = 0.2;
#print( 'F:'.fileno(SERVER)."\n" );
vec($rin, fileno(SERVER), 1) = 1;
vec($rin, $x10->select_fds(), 1) = 1;
my $timeout = 1.0; # WHy .2? Why not 1s?
Debug(2, 'F:'.fileno(SERVER)."\n" );
my $reload = undef;
my $reload_count = 0;
my $reload_limit = $Config{ZM_X10_DB_RELOAD_INTERVAL} / $timeout;
while( 1 ) {
while ( !$zm_terminate ) {
Debug("Selecting for $timeout");
my $nfound = select(my $rout = $rin, undef, undef, $timeout);
#print( "Off select, NF:$nfound, ER:$!\n" );
#print( vec( $rout, fileno(SERVER),1)."\n" );
#print( vec( $rout, $x10->select_fds(),1)."\n" );
if ( $nfound > 0 ) {
if ( vec($rout, fileno(SERVER),1) ) {
Debug("Nfound $nfound");
if ( vec($rout, fileno(SERVER), 1) ) {
my $paddr = accept(CLIENT, SERVER);
my $message = <CLIENT>;

Expand Down Expand Up @@ -268,17 +272,19 @@ sub runServer {
}
} # end if defined result
close(CLIENT);
} elsif ( vec($rout, $x10->select_fds(),1) ) {
} elsif ( vec($rout, $x10->select_fds(), 1) ) {
$x10->handle_input();
} else {
Fatal('Bogus descriptor');
}
} elsif ( $nfound < 0 ) {
if ( $! != EINTR ) {
Fatal("Can't select: $!");
} else {
Debug("Nfound $nfound $!");
}
} else {
#print( "Select timed out\n" );
Debug("Select timed out");
# Check for state changes
foreach my $monitor_id ( sort(keys(%monitor_hash) ) ) {
my $monitor = $monitor_hash{$monitor_id};
Expand All @@ -290,15 +296,13 @@ sub runServer {
if ( defined( $monitor->{LastState} ) ) {
my $task_list;
if ( ($state == STATE_ALARM || $state == STATE_ALERT)
&& ($monitor->{LastState} == STATE_IDLE || $monitor->{LastState} == STATE_TAPE)
&& ($monitor->{LastState} == STATE_IDLE )
) # Gone into alarm state
{
Debug("Applying ON_list for $monitor_id");
$task_list = $monitor->{ON_list};
} elsif ( ($state == STATE_IDLE && $monitor->{LastState} != STATE_IDLE)
|| ($state == STATE_TAPE && $monitor->{LastState} != STATE_TAPE)
) # Come out of alarm state
{
} elsif ($state == STATE_IDLE && $monitor->{LastState} != STATE_IDLE) {
# Come out of alarm state
Debug("Applying OFF_list for $monitor_id");
$task_list = $monitor->{OFF_list};
}
Expand Down Expand Up @@ -657,8 +661,10 @@ sub x10listen {
processTask($task);
}
}
} else {
Debug("Not for out house code ".$event->house_code().' eq '.$Config{ZM_X10_HOUSE_CODE});
} # end if correct house code
Info('Got event - '.$event->as_string());
Debug('Got event - '.$event->as_string());
}
} # end sub x10listen

Expand Down
4 changes: 3 additions & 1 deletion src/zm_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "zm_fifo.h"
#include "zm_file_camera.h"
#include "zm_monitorlink_expression.h"
#include "zm_mqtt.h"
#include "zm_remote_camera.h"
#include "zm_remote_camera_http.h"
#include "zm_remote_camera_nvsocket.h"
Expand All @@ -35,7 +36,6 @@
#include "zm_uri.h"
#include "zm_zone.h"


#if ZM_HAS_V4L2
#include "zm_local_camera.h"
#endif // ZM_HAS_V4L2
Expand Down Expand Up @@ -717,6 +717,8 @@ void Monitor::Load(MYSQL_ROW dbrow, bool load_zones=true, Purpose p = QUERY) {
mqtt_subscriptions = Split(mqtt_subscriptions_string, ',');
col++;
Error("MQTT enabled ? %d, subs %s", mqtt_enabled, mqtt_subscriptions_string.c_str());
#else
Debug(1, "Not compiled with MQTT");
#endif
startup_delay = dbrow[col] ? atoi(dbrow[col]) : 0;
col++;
Expand Down
1 change: 1 addition & 0 deletions src/zm_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class Monitor : public std::enable_shared_from_this<Monitor> {
PullPointSubscriptionBindingProxy proxyEvent;
void set_credentials(struct soap *soap);
std::unordered_map<std::string, std::string> alarms;
std::mutex alarms_mutex;
#endif
public:
explicit ONVIF(Monitor *parent_);
Expand Down
8 changes: 7 additions & 1 deletion src/zm_monitor_amcrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ Monitor::AmcrestAPI::~AmcrestAPI() {
int Monitor::AmcrestAPI::start() {
// init the transfer and start it in multi-handle
int running_handles;
long response_code;
CURLMcode curl_error;
if (Amcrest_handle != nullptr) { // potentially clean up the old handle
curl_multi_remove_handle(curl_multi, Amcrest_handle);
Expand All @@ -49,6 +48,7 @@ int Monitor::AmcrestAPI::start() {
std::string full_url = parent->onvif_url;
if (full_url.back() != '/') full_url += '/';
full_url += "eventManager.cgi?action=attach&codes=[VideoMotion]";
Debug(1, "AMCREST url is %s", full_url.c_str());
Amcrest_handle = curl_easy_init();
if (!Amcrest_handle) {
Warning("Handle is null!");
Expand All @@ -66,15 +66,20 @@ int Monitor::AmcrestAPI::start() {
}
curl_error = curl_multi_perform(curl_multi, &running_handles);
if (curl_error == CURLM_OK) {
long response_code;
curl_easy_getinfo(Amcrest_handle, CURLINFO_RESPONSE_CODE, &response_code);
int msgq = 0;
struct CURLMsg *m = curl_multi_info_read(curl_multi, &msgq);
if (m && (m->msg == CURLMSG_DONE)) {
Warning("AMCREST Libcurl exited Early: %i", m->data.result);
} else {
Debug(1, "AMCREST response code %ld, response %s", response_code, amcrest_response.c_str());
}

curl_multi_wait(curl_multi, nullptr, 0, 300, nullptr);
curl_error = curl_multi_perform(curl_multi, &running_handles);
} else {
Debug(1, "Error code %i", curl_error);
}

if ((curl_error == CURLM_OK) && (running_handles > 0)) {
Expand All @@ -84,6 +89,7 @@ int Monitor::AmcrestAPI::start() {
Warning("AMCREST Response: %s", amcrest_response.c_str());
Warning("AMCREST Seeing %i streams, and error of %i, url: %s",
running_handles, curl_error, full_url.c_str());
long response_code;
curl_easy_getinfo(Amcrest_handle, CURLINFO_OS_ERRNO, &response_code);
Warning("AMCREST Response code: %lu", response_code);
}
Expand Down
Loading

0 comments on commit bbe366f

Please sign in to comment.