HoneyClient-Agent
view release on metacpan or search on metacpan
lib/HoneyClient/Agent.pm view on Meta::CPAN
# Check for any additional external driver updates.
$driver = _update($driver);
# Copy object data to shared memory.
$data->{$driverName}->{'next'} = $driver->next();
$data->{$driverName}->{'status'} = $driver->status();
$data->{$driverName}->{'status'}->{'is_compromised'} = $isCompromised;
$data->{$driverName}->{'status'}->{'fingerprint'} = $changes;
$data->{$driverName}->{'status'}->{'is_running'} = 0;
$data->{$driverName}->{'state'} = $driver;
# Release lock on stored driver state.
_unlock($data);
};
###################################
### Driver Cleanup Phase ###
###################################
# Check to see if any errors occurred within the thread.
# Queue any faults found, to transmit back to the next SOAP
# caller.
if ($@) {
# Release any pending locks, to avoid deadlocks.
_unlock();
# TODO: Do proper fault queuing.
$LOG->error($driverName . " - FAULT: " . $@);
}
# XXX: Debugging, remove eventually.
print $driverName . " - About to return out of child thread.\n";
if (!threads->is_detached()) {
threads->detach();
}
threads->exit();
}
# XXX: Document this.
# Should be something like:
# updateState(
# IE => {
# links => [ url1, url2, ... , ],
# params => {
# timeout => 5,
# blah => "testing",
# },
# },
# )
# TODO: When updateState() hashtable data is sent across SOAP,
# we get the warning message:
#
# Cannot encode 'links_to_visit' element as 'hash'.
# Will be encoded as 'map' instead.
#
# Check to make sure this issue is not critical.
#
# We must base64 encode the data, since SOAP doesn't like URLs
# that contain amperstands.
sub updateState {
# Extract arguments.
my ($class, $arg) = @_;
my %args = ();
# Decode serialized hash.
if (defined($arg)) {
%args = %{thaw(decode_base64($arg))};
}
my $argsExist = scalar(%args);
# Temporary variable, used to hold thawed driver data.
my $data = undef;
# Temporary variable, used to hold thread IDs.
my $tid = undef;
# Temporary variable, used to hold retrieved driver state.
my $driver = undef;
# Temporary variable, used to hold thread objects.
my $thread = undef;
# Figure out which driver to use.
for my $driverName (@{$ALLOWED_DRIVERS}) {
# If the corresponding key within the argument
# hash does not exist or is not defined, then
# go ahead and skip to the next
if (!($argsExist &&
exists($args{$driverName}) &&
defined($args{$driverName}))) {
next;
}
# Enqueue the updated state information.
# If this call fails, an exception is thrown or the process
# remains locked. If the process locks, then external
# detection is used to catch for these types of failures.
$driverUpdateQueues{$driverName}->enqueue(nfreeze($args{$driverName}));
# Acquire data lock.
$data = _lock();
# Sanity check: See if the run() thread is already running.
$tid = $data->{$driverName}->{'thread_id'};
if (defined($tid) &&
defined($thread = threads->object($tid)) &&
$thread->is_running()) {
# The run() thread is active, so we assume that the run() thread will actually
# merge these updates into the shared driver state.
# Release data lock.
_unlock();
} else {
# If we've gotten this far, then the run() thread is no longer active,
( run in 0.986 second using v1.01-cache-2.11-cpan-bbe5e583499 )