]> granicus.if.org Git - curl/commitdiff
ssh: add a generic Curl_ssh_version function for SSH backends
authorDaniel Stenberg <daniel@haxx.se>
Fri, 16 Aug 2019 13:32:05 +0000 (15:32 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 17 Aug 2019 14:57:58 +0000 (16:57 +0200)
Closes #4235

lib/ssh.h
lib/version.c
lib/vssh/libssh.c
lib/vssh/libssh2.c

index 96bb640999cb0f96decae6c382ce055eda89fd9a..3213c5a52e66de7e5d6a836768363b52c054afa2 100644 (file)
--- a/lib/ssh.h
+++ b/lib/ssh.h
@@ -239,12 +239,16 @@ extern const struct Curl_handler Curl_handler_sftp;
 
 extern const struct Curl_handler Curl_handler_scp;
 extern const struct Curl_handler Curl_handler_sftp;
+#endif /* USE_LIBSSH2 */
 
+#ifdef USE_SSH
+/* generic SSH backend functions */
 CURLcode Curl_ssh_init(void);
 void Curl_ssh_cleanup(void);
-
+size_t Curl_ssh_version(char *buffer, size_t buflen);
 #else
+/* for non-SSH builds */
 #define Curl_ssh_cleanup()
-#endif /* USE_LIBSSH2 */
+#endif
 
 #endif /* HEADER_CURL_SSH_H */
index afad726d810bfb3d7b900aa041f65fe965fc875d..ae2b09d310b8c3a91335920bc5439ac99fcc423b 100644 (file)
 #include <librtmp/rtmp.h>
 #endif
 
-#ifdef USE_LIBSSH2
-#include <libssh2.h>
-#endif
-
-#ifdef HAVE_LIBSSH2_VERSION
-/* get it run-time if possible */
-#define CURL_LIBSSH2_VERSION libssh2_version(0)
-#else
-/* use build-time if run-time not possible */
-#define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
-#endif
-
 #ifdef HAVE_ZLIB_H
 #include <zlib.h>
 #ifdef __SYMBIAN32__
@@ -173,13 +161,12 @@ char *curl_version(void)
   left -= len;
   ptr += len;
 #endif
-#ifdef USE_LIBSSH2
-  len = msnprintf(ptr, left, " libssh2/%s", CURL_LIBSSH2_VERSION);
-  left -= len;
-  ptr += len;
-#endif
-#ifdef USE_LIBSSH
-  len = msnprintf(ptr, left, " libssh/%s", CURL_LIBSSH_VERSION);
+#ifdef USE_SSH
+  if(left) {
+    *ptr++=' ';
+    left--;
+  }
+  len = Curl_ssh_version(ptr, left);
   left -= len;
   ptr += len;
 #endif
@@ -458,11 +445,8 @@ curl_version_info_data *curl_version_info(CURLversion stamp)
 #endif /* _LIBICONV_VERSION */
 #endif
 
-#if defined(USE_LIBSSH2)
-  msnprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
-  version_info.libssh_version = ssh_buffer;
-#elif defined(USE_LIBSSH)
-  msnprintf(ssh_buffer, sizeof(ssh_buffer), "libssh/%s", CURL_LIBSSH_VERSION);
+#if defined(USE_SSH)
+  Curl_ssh_version(ssh_buffer, sizeof(ssh_buffer));
   version_info.libssh_version = ssh_buffer;
 #endif
 
index d8186e0b2740f7f41e4ecbd3f738eca94d93c61a..76956a3c1fa592709b5daba41c9f936f708b0e40 100644 (file)
@@ -2739,4 +2739,9 @@ void Curl_ssh_cleanup(void)
   (void)ssh_finalize();
 }
 
+size_t Curl_ssh_version(char *buffer, size_t buflen)
+{
+  return msnprintf(buffer, buflen, "libssh/%s", CURL_LIBSSH_VERSION);
+}
+
 #endif                          /* USE_LIBSSH */
index 011f1ecf3ce9d4255ce235f84060743082b68f18..2b25a514f453926bee903c211eb10815ac4a145d 100644 (file)
@@ -3338,5 +3338,9 @@ void Curl_ssh_cleanup(void)
 #endif
 }
 
+size_t Curl_ssh_version(char *buffer, size_t buflen)
+{
+  return msnprintf(buffer, buflen, "libssh2/%s", LIBSSH2_VERSION);
+}
 
 #endif /* USE_LIBSSH2 */