mirror of
https://github.com/nmap/nmap.git
synced 2025-12-27 01:49:03 +00:00
Move NewTargets class to its own h/cc files
This commit is contained in:
103
TargetGroup.cc
103
TargetGroup.cc
@@ -199,8 +199,6 @@ public:
|
||||
std::string str() const;
|
||||
};
|
||||
|
||||
NewTargets *NewTargets::new_targets;
|
||||
|
||||
/* Return a newly allocated string containing the part of expr up to the last
|
||||
'/' (or a copy of the whole string if there is no slash). *bits will contain
|
||||
the number after the slash, or -1 if there was no slash. In case of error
|
||||
@@ -777,104 +775,3 @@ std::string NetBlockHostname::str() const {
|
||||
|
||||
return result.str();
|
||||
}
|
||||
|
||||
/* debug level for the adding target is: 3 */
|
||||
NewTargets *NewTargets::get (void) {
|
||||
if (new_targets)
|
||||
return new_targets;
|
||||
new_targets = new NewTargets();
|
||||
return new_targets;
|
||||
}
|
||||
|
||||
NewTargets::NewTargets (void) {
|
||||
Initialize();
|
||||
}
|
||||
|
||||
void NewTargets::Initialize (void) {
|
||||
history.clear();
|
||||
while (!queue.empty())
|
||||
queue.pop();
|
||||
}
|
||||
|
||||
/* This private method is used to push new targets to the
|
||||
* queue. It returns the number of targets in the queue. */
|
||||
unsigned long NewTargets::push (const char *target) {
|
||||
std::pair<std::set<std::string>::iterator, bool> pair_iter;
|
||||
std::string tg(target);
|
||||
|
||||
if (tg.length() > 0) {
|
||||
/* save targets in the scanned history here (NSE side). */
|
||||
pair_iter = history.insert(tg);
|
||||
|
||||
/* A new target */
|
||||
if (pair_iter.second == true) {
|
||||
/* push target onto the queue for future scans */
|
||||
queue.push(tg);
|
||||
|
||||
if (o.debugging > 2)
|
||||
log_write(LOG_PLAIN, "New Targets: target %s pushed onto the queue.\n", tg.c_str());
|
||||
} else {
|
||||
if (o.debugging > 2)
|
||||
log_write(LOG_PLAIN, "New Targets: target %s is already in the queue.\n", tg.c_str());
|
||||
/* Return 1 when the target is already in the history cache,
|
||||
* this will prevent returning 0 when the target queue is
|
||||
* empty since no target was added. */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return queue.size();
|
||||
}
|
||||
|
||||
/* Reads a target from the queue and return it to be pushed
|
||||
* onto Nmap scan queue */
|
||||
std::string NewTargets::read (void) {
|
||||
std::string str;
|
||||
|
||||
/* check to see it there are targets in the queue */
|
||||
if (!new_targets->queue.empty()) {
|
||||
str = new_targets->queue.front();
|
||||
new_targets->queue.pop();
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void NewTargets::clear (void) {
|
||||
new_targets->history.clear();
|
||||
}
|
||||
|
||||
unsigned long NewTargets::get_number (void) {
|
||||
return new_targets->history.size();
|
||||
}
|
||||
|
||||
unsigned long NewTargets::get_scanned (void) {
|
||||
return new_targets->history.size() - new_targets->queue.size();
|
||||
}
|
||||
|
||||
unsigned long NewTargets::get_queued (void) {
|
||||
return new_targets->queue.size();
|
||||
}
|
||||
|
||||
/* This is the function that is used by nse_nmaplib.cc to add
|
||||
* new targets.
|
||||
* Returns the number of targets in the queue on success, or 0 on
|
||||
* failures or when the queue is empty. */
|
||||
unsigned long NewTargets::insert (const char *target) {
|
||||
if (*target) {
|
||||
if (new_targets == NULL) {
|
||||
error("ERROR: to add targets run with -sC or --script options.");
|
||||
return 0;
|
||||
}
|
||||
if (o.current_scantype == SCRIPT_POST_SCAN) {
|
||||
error("ERROR: adding targets is disabled in the Post-scanning phase.");
|
||||
return 0;
|
||||
}
|
||||
if (strlen(target) >= 1024) {
|
||||
error("ERROR: new target is too long (>= 1024), failed to add it.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return new_targets->push(target);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user