Skip to content

Commit

Permalink
Add function to move a host to the end of the list
Browse files Browse the repository at this point in the history
Allows to put a host in the hosts structure at the end
of the host list without reset the iterator.
  • Loading branch information
jjnicola committed Oct 15, 2020
1 parent 82e739e commit 0aff1bd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added
- Use dedicated port list for alive detection (Boreas only) if supplied via OSP. [#391](https://github.com/greenbone/gvm-libs/pull/391)
- Allow to re allocate the finish flag in the host queue for alive tests. [#407](https://github.com/greenbone/gvm-libs/pull/407)
- Allow to re allocate the finish flag in the host queue for alive tests.
[#407](https://github.com/greenbone/gvm-libs/pull/407)
[#410](https://github.com/greenbone/gvm-libs/pull/410)

### Added
- Add multiple severities for nvti [#317](https://github.com/greenbone/gvm-libs/pull/317)
Expand Down
33 changes: 33 additions & 0 deletions base/hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,39 @@ gvm_hosts_next (gvm_hosts_t *hosts)
return hosts->hosts[hosts->current++];
}

/**
* @brief Move the current gvm_host_t from a gvm_hosts_t structure to
* the end of the hosts list.
*
* @param[in/out] hosts gvm_hosts_t structure which hosts must be
* rearange. The hosts->current index points to the last used hosts and
* gvm_hosts_next() must be called to get the next host in the list.
*
*/
void
gvm_hosts_move_current_host_to_end (gvm_hosts_t *hosts)
{
void *host_tmp;
size_t i;

if (!hosts)// hosts->current == hosts->count)
return;

if (hosts->current == hosts->count)
{
hosts->current -= 1;
return;
}

hosts->current -= 1;
host_tmp = hosts->hosts[hosts->current];

for (i = hosts->current; i < hosts->count; i++)
hosts->hosts[i-1] = hosts->hosts[i];

hosts->hosts[hosts->count - 1] = host_tmp;
}

/**
* @brief Frees memory occupied by an gvm_hosts_t structure.
*
Expand Down
3 changes: 3 additions & 0 deletions base/hosts.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ gvm_hosts_new_with_max (const gchar *, unsigned int);
gvm_host_t *
gvm_hosts_next (gvm_hosts_t *);

void
gvm_hosts_move_current_host_to_end (gvm_hosts_t *);

void
gvm_hosts_free (gvm_hosts_t *);

Expand Down

0 comments on commit 0aff1bd

Please sign in to comment.