1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-23 16:48:49 -05:00

vssh: move ssh init/cleanup functions into backend code

This commit is contained in:
Daniel Stenberg 2019-08-16 16:16:33 +02:00
parent 5b2d703fe5
commit d6dea75af7
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
4 changed files with 41 additions and 18 deletions

View File

@ -187,16 +187,8 @@ static CURLcode global_init(long flags, bool memoryfuncs)
(void)Curl_ipv6works(); (void)Curl_ipv6works();
#if defined(USE_LIBSSH2) && defined(HAVE_LIBSSH2_INIT) #if defined(USE_SSH)
if(libssh2_init(0)) { if(Curl_ssh_init()) {
DEBUGF(fprintf(stderr, "Error: libssh2_init failed\n"));
return CURLE_FAILED_INIT;
}
#endif
#if defined(USE_LIBSSH)
if(ssh_init()) {
DEBUGF(fprintf(stderr, "Error: libssh_init failed\n"));
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
} }
#endif #endif
@ -274,13 +266,7 @@ void curl_global_cleanup(void)
Curl_amiga_cleanup(); Curl_amiga_cleanup();
#if defined(USE_LIBSSH2) && defined(HAVE_LIBSSH2_EXIT) Curl_ssh_cleanup();
(void)libssh2_exit();
#endif
#if defined(USE_LIBSSH)
(void)ssh_finalize();
#endif
init_flags = 0; init_flags = 0;
} }

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -240,6 +240,11 @@ extern const struct Curl_handler Curl_handler_sftp;
extern const struct Curl_handler Curl_handler_scp; extern const struct Curl_handler Curl_handler_scp;
extern const struct Curl_handler Curl_handler_sftp; extern const struct Curl_handler Curl_handler_sftp;
CURLcode Curl_ssh_init(void);
void Curl_ssh_cleanup(void);
#else
#define Curl_ssh_cleanup()
#endif /* USE_LIBSSH2 */ #endif /* USE_LIBSSH2 */
#endif /* HEADER_CURL_SSH_H */ #endif /* HEADER_CURL_SSH_H */

View File

@ -2725,5 +2725,18 @@ static void sftp_quote_stat(struct connectdata *conn)
return; return;
} }
CURLcode Curl_ssh_init(void)
{
if(ssh_init()) {
DEBUGF(fprintf(stderr, "Error: libssh_init failed\n"));
return CURLE_FAILED_INIT;
}
return CURLE_OK;
}
void Curl_ssh_cleanup(void)
{
(void)ssh_finalize();
}
#endif /* USE_LIBSSH */ #endif /* USE_LIBSSH */

View File

@ -3320,4 +3320,23 @@ static const char *sftp_libssh2_strerror(int err)
return "Unknown error in libssh2"; return "Unknown error in libssh2";
} }
CURLcode Curl_ssh_init(void)
{
#ifdef HAVE_LIBSSH2_INIT
if(libssh2_init(0)) {
DEBUGF(fprintf(stderr, "Error: libssh2_init failed\n"));
return CURLE_FAILED_INIT;
}
#endif
return CURLE_OK;
}
void Curl_ssh_cleanup(void)
{
#ifdef HAVE_LIBSSH2_EXIT
(void)libssh2_exit();
#endif
}
#endif /* USE_LIBSSH2 */ #endif /* USE_LIBSSH2 */