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 e975155
Show file tree
Hide file tree
Showing 3 changed files with 37 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
31 changes: 31 additions & 0 deletions base/hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,37 @@ gvm_hosts_next (gvm_hosts_t *hosts)
return hosts->hosts[hosts->current++];
}

/**
* @brief Gets the curren gvm_host_t from a gvm_hosts_t structure and
* move it to the last position in the list. The next host occupies the
* the current position.
*
* @param[in/out] hosts gvm_hosts_t structure which hosts must be
* rearange.
*
* @return Pointer to the new current host. NULL if error.
*/
gvm_host_t *
gvm_hosts_move_host_forward (gvm_hosts_t *hosts)
{
void *host_tmp;
size_t i;

/* If it is the last host, there is nothing to rearange and
* returns the same host.*/
if (!hosts || hosts->current == hosts->count)
return hosts->hosts[hosts->current - 1];

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

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

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

return hosts->hosts[hosts->current - 1];
}

/**
* @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 *);

gvm_host_t *
gvm_hosts_move_host_forward (gvm_hosts_t *);

void
gvm_hosts_free (gvm_hosts_t *);

Expand Down

0 comments on commit e975155

Please sign in to comment.