LIBSSH2_API int libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts, const char *filename, int type) { FILE *file; int num = 0; char buf[2048]; if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH) return _libssh2_error(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, "Unsupported type of known-host information " "store"); file = fopen(filename, "r"); if(file) { while(fgets(buf, sizeof(buf), file)) { if(libssh2_knownhost_readline(hosts, buf, strlen(buf), type)) { num = _libssh2_error(hosts->session, LIBSSH2_ERROR_KNOWN_HOSTS, "Failed to parse known hosts file"); break; } num++; } fclose(file); } else return _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE, "Failed to open file"); return num; }
lv_libssh2_status_t lv_libssh2_knownhosts_read_line( lv_libssh2_knownhosts_t* handle, const char* line, const size_t line_len ) { if (handle == NULL) { return LV_LIBSSH2_STATUS_ERROR_NULL_VALUE; } if (line == NULL) { return LV_LIBSSH2_STATUS_ERROR_NULL_VALUE; } int result = libssh2_knownhost_readline( handle->inner, line, line_len, LIBSSH2_KNOWNHOST_FILE_OPENSSH ); return lv_libssh2_status_from_result(result); }
LIBSSH2_API int libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts, const char *filename, int type) { FILE *file; int num = 0; char buf[2048]; if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH) return LIBSSH2_ERROR_METHOD_NOT_SUPPORTED; file = fopen(filename, "r"); if(file) { while(fgets(buf, sizeof(buf), file)) { if(libssh2_knownhost_readline(hosts, buf, strlen(buf), type)) break; num++; } fclose(file); } else return LIBSSH2_ERROR_FILE; return num; }