]> granicus.if.org Git - curl/commitdiff
vssh: move ssh init/cleanup functions into backend code
authorDaniel Stenberg <daniel@haxx.se>
Fri, 16 Aug 2019 14:16:33 +0000 (16:16 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 17 Aug 2019 14:57:55 +0000 (16:57 +0200)
lib/easy.c
lib/ssh.h
lib/vssh/libssh.c
lib/vssh/libssh2.c

index b8d94c740686fd372be28947333cbe2d4f8001a4..1d49a036621a4c986f9e740968c18dfa3bd96135 100644 (file)
@@ -187,16 +187,8 @@ static CURLcode global_init(long flags, bool memoryfuncs)
 
   (void)Curl_ipv6works();
 
-#if defined(USE_LIBSSH2) && defined(HAVE_LIBSSH2_INIT)
-  if(libssh2_init(0)) {
-    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"));
+#if defined(USE_SSH)
+  if(Curl_ssh_init()) {
     return CURLE_FAILED_INIT;
   }
 #endif
@@ -274,13 +266,7 @@ void curl_global_cleanup(void)
 
   Curl_amiga_cleanup();
 
-#if defined(USE_LIBSSH2) && defined(HAVE_LIBSSH2_EXIT)
-  (void)libssh2_exit();
-#endif
-
-#if defined(USE_LIBSSH)
-  (void)ssh_finalize();
-#endif
+  Curl_ssh_cleanup();
 
   init_flags  = 0;
 }
index 0620aac3286b1804caaafa06ca6b34828574f9f9..96bb640999cb0f96decae6c382ce055eda89fd9a 100644 (file)
--- a/lib/ssh.h
+++ b/lib/ssh.h
@@ -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
  * 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_sftp;
 
+CURLcode Curl_ssh_init(void);
+void Curl_ssh_cleanup(void);
+
+#else
+#define Curl_ssh_cleanup()
 #endif /* USE_LIBSSH2 */
 
 #endif /* HEADER_CURL_SSH_H */
index 4b34b02128dc7fabbc0c59bb1ccf84346510d49d..d8186e0b2740f7f41e4ecbd3f738eca94d93c61a 100644 (file)
@@ -2725,5 +2725,18 @@ static void sftp_quote_stat(struct connectdata *conn)
   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 */
index 5dd6ee29e334f03bbb552f171e5d34fd7be43a30..011f1ecf3ce9d4255ce235f84060743082b68f18 100644 (file)
@@ -3320,4 +3320,23 @@ static const char *sftp_libssh2_strerror(int err)
   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 */