diff --git a/include/libssh2.h b/include/libssh2.h index b539f2a..efca3fd 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -794,6 +794,24 @@ LIBSSH2_API int libssh2_knownhost_parsefile(LIBSSH2_KNOWNHOSTS *hosts, const char *filename, int type); + +/* + * libssh2_knownhost_get() + * + * Traverse the internal list of known hosts. Pass NULL to 'prev' to get + * the first one. Or pass a poiner to the previously returned one to get the + * next. + * + * Returns: + * 0 if a fine host was stored in 'store' + * 1 if end of hosts + * [negative] on errors + */ +LIBSSH2_API int +libssh2_knownhost_get(LIBSSH2_KNOWNHOSTS *hosts, + struct libssh2_knownhost *store, + struct libssh2_knownhost *prev); + /* NOTE NOTE NOTE libssh2_trace() has no function in builds that aren't built with debug enabled diff --git a/src/knownhost.c b/src/knownhost.c index 7dabadf..d043f10 100644 --- a/src/knownhost.c +++ b/src/knownhost.c @@ -562,3 +562,40 @@ libssh2_knownhost_parsefile(LIBSSH2_KNOWNHOSTS *hosts, return -1; return num; } + +/* + * libssh2_knownhost_get() + * + * Traverse the internal list of known hosts. Pass NULL to 'prev' to get + * the first one. + * + * Returns: + * 0 if a fine host was stored in 'store' + * 1 if end of hosts + * [negative] on errors + */ +LIBSSH2_API int +libssh2_knownhost_get(LIBSSH2_KNOWNHOSTS *hosts, + struct libssh2_knownhost *store, + struct libssh2_knownhost *oprev) +{ + struct known_host *node; + if(oprev && oprev->node) { + /* we have a starting point */ + struct known_host *prev = oprev->node; + + /* get the next node in the list */ + node = _libssh2_list_next(&prev->node); + + } + else + node = _libssh2_list_first(&hosts->head); + + if(!node) + /* no (more) node */ + return 1; + + knownhost_to_external(node, store); + + return 0; +}