Blob Blame History Raw
From 465730eb7c6923e4a4b1a558d306135eed8cc38c Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Fri, 23 May 2014 18:50:19 +0100
Subject: [PATCH 01/47] CMake build working with Visual Studio 8.

Tested:
- static
- 32/64-bit
- OpenSSL/WinCNG
- Without zlib

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 CMakeLists.txt                                |  52 +++++
 cmake/CheckFunctionExistsMayNeedLibrary.cmake |  81 +++++++
 cmake/CheckNonblockingSocketSupport.cmake     | 119 ++++++++++
 cmake/FindLibgcrypt.cmake                     |  53 +++++
 cmake/FixupExecutable.cmake                   |   5 +
 cmake/max_warnings.cmake                      |  26 +++
 example/CMakeLists.txt                        | 103 +++++++++
 example/direct_tcpip.c                        |   5 +-
 example/libssh2_config.h.in                   |  72 ++++++
 example/scp_nonblock.c                        |  10 +-
 example/sftp_nonblock.c                       |  10 +-
 example/ssh2_echo.c                           |   5 +-
 example/ssh2_exec.c                           |   5 +-
 example/subsystem_netconf.c                   |  11 +-
 example/tcpip-forward.c                       |   5 +-
 include/libssh2.h                             |   2 +-
 src/CMakeLists.txt                            | 316 ++++++++++++++++++++++++++
 src/libssh2_config.h.in                       | 104 +++++++++
 tests/CMakeLists.txt                          |  91 ++++++++
 tests/libssh2_config.h.in                     |  43 ++++
 tests/ssh2.c                                  |   6 +-
 21 files changed, 1114 insertions(+), 10 deletions(-)
 create mode 100644 CMakeLists.txt
 create mode 100644 cmake/CheckFunctionExistsMayNeedLibrary.cmake
 create mode 100644 cmake/CheckNonblockingSocketSupport.cmake
 create mode 100644 cmake/FindLibgcrypt.cmake
 create mode 100644 cmake/FixupExecutable.cmake
 create mode 100644 cmake/max_warnings.cmake
 create mode 100644 example/CMakeLists.txt
 create mode 100644 example/libssh2_config.h.in
 create mode 100644 src/CMakeLists.txt
 create mode 100644 src/libssh2_config.h.in
 create mode 100644 tests/CMakeLists.txt
 create mode 100644 tests/libssh2_config.h.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..a5ad188
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,52 @@
+# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+#
+# Redistribution and use in source and binary forms,
+# with or without modification, are permitted provided
+# that the following conditions are met:
+#
+#   Redistributions of source code must retain the above
+#   copyright notice, this list of conditions and the
+#   following disclaimer.
+#
+#   Redistributions in binary form must reproduce the above
+#   copyright notice, this list of conditions and the following
+#   disclaimer in the documentation and/or other materials
+#   provided with the distribution.
+#
+#   Neither the name of the copyright holder nor the names
+#   of any other contributors may be used to endorse or
+#   promote products derived from this software without
+#   specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# OF SUCH DAMAGE.
+
+cmake_minimum_required(VERSION 2.8)
+
+project(libssh2)
+
+option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
+
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
+
+include(max_warnings)
+
+include_directories(include)
+
+enable_testing()
+
+add_subdirectory(src)
+add_subdirectory(example)
+add_subdirectory(tests)
\ No newline at end of file
diff --git a/cmake/CheckFunctionExistsMayNeedLibrary.cmake b/cmake/CheckFunctionExistsMayNeedLibrary.cmake
new file mode 100644
index 0000000..8ac61ab
--- /dev/null
+++ b/cmake/CheckFunctionExistsMayNeedLibrary.cmake
@@ -0,0 +1,81 @@
+# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+#
+# Redistribution and use in source and binary forms,
+# with or without modification, are permitted provided
+# that the following conditions are met:
+#
+#   Redistributions of source code must retain the above
+#   copyright notice, this list of conditions and the
+#   following disclaimer.
+#
+#   Redistributions in binary form must reproduce the above
+#   copyright notice, this list of conditions and the following
+#   disclaimer in the documentation and/or other materials
+#   provided with the distribution.
+#
+#   Neither the name of the copyright holder nor the names
+#   of any other contributors may be used to endorse or
+#   promote products derived from this software without
+#   specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# OF SUCH DAMAGE.
+
+
+# - check_function_exists_maybe_need_library(<function> <var> [lib1 ... libn])
+#
+# Check if function is available for linking, first without extra libraries, and
+# then, if not found that way, linking in each optional library as well.  This
+# function is similar to autotools AC_SEARCH_LIBS.
+#
+# If the function if found, this will define <var>.
+#
+# If the function was only found by linking in an additional library, this
+# will define NEED_LIB_LIBX, where LIBX is the one of lib1 to libn that
+# makes the function available, in uppercase.
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
+#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+#  CMAKE_REQUIRED_INCLUDES = list of include directories
+#  CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+#
+
+include(CheckFunctionExists)
+include(CheckLibraryExists)
+
+function(check_function_exists_may_need_library function variable)
+
+  check_function_exists(${function} ${variable})
+
+  if(NOT ${variable})
+    foreach(lib ${ARGN})
+      string(TOUPPER ${lib} UP_LIB)
+      # Use new variable to prevent cache from previous step shortcircuiting
+      # new test
+      check_library_exists(${lib} ${function} "" HAVE_${function}_IN_${lib})
+      if(HAVE_${function}_IN_${lib})
+	set(${variable} 1 CACHE INTERNAL
+	  "Function ${function} found in library ${lib}")
+	set(NEED_LIB_${UP_LIB} 1 CACHE INTERNAL
+	  "Need to link ${lib}")
+	break()
+      endif()
+    endforeach()
+  endif()
+
+endfunction()
\ No newline at end of file
diff --git a/cmake/CheckNonblockingSocketSupport.cmake b/cmake/CheckNonblockingSocketSupport.cmake
new file mode 100644
index 0000000..74f4776
--- /dev/null
+++ b/cmake/CheckNonblockingSocketSupport.cmake
@@ -0,0 +1,119 @@
+include(CheckCSourceCompiles)
+
+# - check_nonblocking_socket_support()
+#
+# Check for how to set a socket to non-blocking state. There seems to exist
+# four known different ways, with the one used almost everywhere being POSIX
+# and XPG3, while the other different ways for different systems (old BSD,
+# Windows and Amiga).
+#
+# One of the following variables will be set indicating the supported
+# method (if any):
+#   HAVE_O_NONBLOCK
+#   HAVE_FIONBIO
+#   HAVE_IOCTLSOCKET
+#   HAVE_IOCTLSOCKET_CASE
+#   HAVE_SO_NONBLOCK
+#   HAVE_DISABLED_NONBLOCKING
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
+#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+#  CMAKE_REQUIRED_INCLUDES = list of include directories
+#  CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+#
+macro(check_nonblocking_socket_support)
+  # There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
+  # O_NONBLOCK define is found but does not work.
+  check_c_source_compiles("
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+# if defined(__SVR4) || defined(__srv4__)
+#  define PLATFORM_SOLARIS
+# else
+#  define PLATFORM_SUNOS4
+# endif
+#endif
+#if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
+# define PLATFORM_AIX_V3
+#endif
+
+#if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
+#error \"O_NONBLOCK does not work on this platform\"
+#endif
+
+int main()
+{
+    int socket;
+    int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
+}"
+  HAVE_O_NONBLOCK)
+
+  if(NOT HAVE_O_NONBLOCK)
+    check_c_source_compiles("/* FIONBIO test (old-style unix) */
+#include <unistd.h>
+#include <stropts.h>
+
+int main()
+{
+    int socket;
+    int flags = ioctl(socket, FIONBIO, &flags);
+}"
+    HAVE_FIONBIO)
+
+    if(NOT HAVE_FIONBIO)
+      check_c_source_compiles("/* ioctlsocket test (Windows) */
+#undef inline
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+
+#include <windows.h>
+#include <winsock2.h>
+
+int main()
+{
+    SOCKET sd;
+    unsigned long flags = 0;
+    sd = socket(0, 0, 0);
+    ioctlsocket(sd, FIONBIO, &flags);
+}"
+      HAVE_IOCTLSOCKET)
+
+      if(NOT HAVE_IOCTLSOCKET)
+	check_c_source_compiles("/* IoctlSocket test (Amiga?) */
+#include <sys/ioctl.h>
+
+int main()
+{
+    int socket;
+    int flags = IoctlSocket(socket, FIONBIO, (long)1);
+}"
+        HAVE_IOCTLSOCKET_CASE)
+
+        if(NOT HAVE_IOCTLSOCKET_CASE)
+	  check_c_source_compiles("/* SO_NONBLOCK test (BeOS) */
+#include <socket.h>
+
+int main()
+{
+    long b = 1;
+    int socket;
+    int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
+}"
+          HAVE_SO_NONBLOCK)
+
+	  if(NOT HAVE_SO_NONBLOCK)
+	    # No non-blocking socket method found
+	    set(HAVE_DISABLED_NONBLOCKING 1)
+	  endif()
+	endif()
+      endif()
+    endif()
+  endif()
+endmacro()
\ No newline at end of file
diff --git a/cmake/FindLibgcrypt.cmake b/cmake/FindLibgcrypt.cmake
new file mode 100644
index 0000000..44a7987
--- /dev/null
+++ b/cmake/FindLibgcrypt.cmake
@@ -0,0 +1,53 @@
+# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+#
+# Redistribution and use in source and binary forms,
+# with or without modification, are permitted provided
+# that the following conditions are met:
+#
+#   Redistributions of source code must retain the above
+#   copyright notice, this list of conditions and the
+#   following disclaimer.
+#
+#   Redistributions in binary form must reproduce the above
+#   copyright notice, this list of conditions and the following
+#   disclaimer in the documentation and/or other materials
+#   provided with the distribution.
+#
+#   Neither the name of the copyright holder nor the names
+#   of any other contributors may be used to endorse or
+#   promote products derived from this software without
+#   specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# OF SUCH DAMAGE.
+
+# - Try to find Libgcrypt
+# This will define all or none of:
+#  LIBGCRYPT_FOUND - if Libgcrypt headers and library was found
+#  LIBGCRYPT_INCLUDE_DIRS - The Libgcrypt include directories
+#  LIBGCRYPT_LIBRARIES - The libraries needed to use Libgcrypt
+
+find_path(LIBGCRYPT_INCLUDE_DIR gcrypt.h)
+
+find_library(LIBGCRYPT_LIBRARY NAMES gcrypt libgcrypt)
+
+set(LIBGCRYPT_LIBRARIES ${LIBGCRYPT_LIBRARY})
+set(LIBGCRYPT_INCLUDE_DIRS ${LIBGCRYPT_INCLUDE_DIR})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Libgcrypt DEFAULT_MSG
+                                  LIBGCRYPT_LIBRARY LIBGCRYPT_INCLUDE_DIR)
+
+mark_as_advanced(LIBGCRYPT_INCLUDE_DIR LIBGCRYPT_LIBRARY)
\ No newline at end of file
diff --git a/cmake/FixupExecutable.cmake b/cmake/FixupExecutable.cmake
new file mode 100644
index 0000000..2c12b73
--- /dev/null
+++ b/cmake/FixupExecutable.cmake
@@ -0,0 +1,5 @@
+include(BundleUtilities)
+
+message("Fixing up ${EXECUTABLE} using binaries from ${SEARCH_DIRS}")
+
+fixup_bundle("${EXECUTABLE}" "" "${SEARCH_DIRS}")
\ No newline at end of file
diff --git a/cmake/max_warnings.cmake b/cmake/max_warnings.cmake
new file mode 100644
index 0000000..19a2e90
--- /dev/null
+++ b/cmake/max_warnings.cmake
@@ -0,0 +1,26 @@
+
+if(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)")
+  # Use the highest warning level for visual studio.
+  if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
+    string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+  else()
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
+  endif()
+  if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
+    string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+  else()
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
+  endif()
+
+  # Disable broken warnings
+  add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
+endif()
+
+if(CMAKE_BUILD_TOOL MATCHES "make")
+  if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
+  endif()
+  if(NOT CMAKE_C_FLAGS MATCHES "-Wall")
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
+  endif()
+endif()
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
new file mode 100644
index 0000000..deb44e2
--- /dev/null
+++ b/example/CMakeLists.txt
@@ -0,0 +1,103 @@
+# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+#
+# Redistribution and use in source and binary forms,
+# with or without modification, are permitted provided
+# that the following conditions are met:
+#
+#   Redistributions of source code must retain the above
+#   copyright notice, this list of conditions and the
+#   following disclaimer.
+#
+#   Redistributions in binary form must reproduce the above
+#   copyright notice, this list of conditions and the following
+#   disclaimer in the documentation and/or other materials
+#   provided with the distribution.
+#
+#   Neither the name of the copyright holder nor the names
+#   of any other contributors may be used to endorse or
+#   promote products derived from this software without
+#   specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# OF SUCH DAMAGE.
+
+include(CheckIncludeFiles)
+include(CheckFunctionExists)
+include(CheckSymbolExists)
+
+set(EXAMPLES
+  direct_tcpip
+  ssh2
+  scp
+  scp_nonblock
+  scp_write
+  scp_write_nonblock
+  sftp
+  sftp_nonblock
+  sftp_write
+  sftp_write_nonblock
+  sftp_mkdir
+  sftp_mkdir_nonblock
+  sftp_RW_nonblock
+  sftp_write_sliding
+  sftpdir
+  sftpdir_nonblock
+  ssh2_exec
+  ssh2_agent
+  ssh2_echo
+  sftp_append
+  subsystem_netconf
+  tcpip-forward)
+
+# Escape semicolons in runtime library search path list so we can pass it
+# through to the custom command
+string(REPLACE ";" "\$<SEMICOLON>"
+  ESCAPED_RUNTIME_LIBRARY_DIRS "${RUNTIME_LIBRARY_DIRS}")
+
+foreach(example ${EXAMPLES})
+  add_executable(example-${example} ${example}.c)
+  target_link_libraries(example-${example} ssh2)
+
+  add_custom_command(TARGET example-${example} POST_BUILD
+    COMMAND ${CMAKE_COMMAND}
+      -DEXECUTABLE=$<TARGET_FILE:example-${example}>
+      -DSEARCH_DIRS=${ESCAPED_RUNTIME_LIBRARY_DIRS}
+      -P ${CMAKE_SOURCE_DIR}/CMake/FixupExecutable.cmake
+    VERBATIM)
+endforeach()
+
+## Platform checks
+check_include_files(inttypes.h HAVE_INTTYPES_H)
+check_include_files(unistd.h HAVE_UNISTD_H)
+check_include_files(stdlib.h HAVE_STDLIB_H)
+check_include_files(sys/select.h HAVE_SYS_SELECT_H)
+check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
+check_include_files(sys/time.h HAVE_SYS_TIME_H)
+check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
+check_include_files(netinet/in.h HAVE_NETINET_IN_H)
+check_include_files(winsock2.h HAVE_WINSOCK2_H)
+
+check_function_exists(strcasecmp HAVE_STRCASECMP)
+check_function_exists(_stricmp HAVE__STRICMP)
+check_function_exists(snprintf HAVE_SNPRINTF)
+check_function_exists(_snprintf HAVE__SNPRINTF)
+
+check_symbol_exists(__func__ "" HAVE___FUNC__)
+check_symbol_exists(__FUNCTION__ "" HAVE___FUNCTION__)
+
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config.h.in
+  ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}) # to find generated header
\ No newline at end of file
diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c
index e530199..96b317e 100644
--- a/example/direct_tcpip.c
+++ b/example/direct_tcpip.c
@@ -15,10 +15,13 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <stdio.h>
+#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
+#endif
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <sys/types.h>
-
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
diff --git a/example/libssh2_config.h.in b/example/libssh2_config.h.in
new file mode 100644
index 0000000..12264f7
--- /dev/null
+++ b/example/libssh2_config.h.in
@@ -0,0 +1,72 @@
+/* Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ *   Redistributions of source code must retain the above
+ *   copyright notice, this list of conditions and the
+ *   following disclaimer.
+ *
+ *   Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the following
+ *   disclaimer in the documentation and/or other materials
+ *   provided with the distribution.
+ *
+ *   Neither the name of the copyright holder nor the names
+ *   of any other contributors may be used to endorse or
+ *   promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ */
+
+/* Headers */
+#cmakedefine HAVE_UNISTD_H
+#cmakedefine HAVE_INTTYPES_H
+#cmakedefine HAVE_STDLIB_H
+#cmakedefine HAVE_SYS_SELECT_H
+#cmakedefine HAVE_SYS_SOCKET_H
+#cmakedefine HAVE_SYS_TIME_H
+#cmakedefine HAVE_ARPA_INET_H
+#cmakedefine HAVE_NETINET_IN_H
+#cmakedefine HAVE_WINSOCK2_H
+
+/* Functions */
+#cmakedefine HAVE_STRCASECMP
+#cmakedefine HAVE__STRICMP
+#cmakedefine HAVE_SNPRINTF
+#cmakedefine HAVE__SNPRINTF
+
+/* Workaround for platforms without POSIX strcasecmp (e.g. Windows) */
+#ifndef HAVE_STRCASECMP
+# ifdef HAVE__STRICMP
+# define strcasecmp _stricmp
+# define HAVE_STRCASECMP
+# endif
+#endif
+
+/* Symbols */
+#cmakedefine HAVE___FUNC__
+#cmakedefine HAVE___FUNCTION__
+
+/* Workaround for platforms without C90 __func__ */
+#ifndef HAVE___FUNC__
+# ifdef HAVE___FUNCTION__
+# define __func__ __FUNCTION__
+# define HAVE___FUNC__
+# endif
+#endif
diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c
index 5d636c0..7249b5b 100644
--- a/example/scp_nonblock.c
+++ b/example/scp_nonblock.c
@@ -87,11 +87,13 @@ int main(int argc, char *argv[])
     const char *password="password";
     const char *scppath="/tmp/TEST";
     struct stat fileinfo;
+#ifdef HAVE_GETTIMEOFDAY
     struct timeval start;
     struct timeval end;
+    long time_ms;
+#endif
     int rc;
     int total = 0;
-    long time_ms;
     int spin = 0;
     off_t got=0;
 
@@ -144,7 +146,9 @@ int main(int argc, char *argv[])
     /* Since we have set non-blocking, tell libssh2 we are non-blocking */
     libssh2_session_set_blocking(session, 0);
 
+#ifdef HAVE_GETTIMEOFDAY
     gettimeofday(&start, NULL);
+#endif
 
     /* ... start it up. This will trade welcome banners, exchange keys,
      * and setup crypto, compression, and MAC layers
@@ -247,11 +251,15 @@ int main(int argc, char *argv[])
         break;
     }
 
+#ifdef HAVE_GETTIMEOFDAY
     gettimeofday(&end, NULL);
 
     time_ms = tvdiff(end, start);
     fprintf(stderr, "Got %d bytes in %ld ms = %.1f bytes/sec spin: %d\n", total,
            time_ms, total/(time_ms/1000.0), spin );
+#else
+    fprintf(stderr, "Got %d bytes spin: %d\n", total, spin);
+#endif
 
     libssh2_channel_free(channel);
     channel = NULL;
diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c
index 29cec8a..d6ef5f9 100644
--- a/example/sftp_nonblock.c
+++ b/example/sftp_nonblock.c
@@ -86,11 +86,13 @@ int main(int argc, char *argv[])
     const char *username="username";
     const char *password="password";
     const char *sftppath="/tmp/TEST";
+#ifdef HAVE_GETTIMEOFDAY
     struct timeval start;
     struct timeval end;
+    long time_ms;
+#endif
     int rc;
     int total = 0;
-    long time_ms;
     int spin = 0;
     LIBSSH2_SFTP *sftp_session;
     LIBSSH2_SFTP_HANDLE *sftp_handle;
@@ -146,7 +148,9 @@ int main(int argc, char *argv[])
     /* Since we have set non-blocking, tell libssh2 we are non-blocking */
     libssh2_session_set_blocking(session, 0);
 
+#ifdef HAVE_GETTIMEOFDAY
     gettimeofday(&start, NULL);
+#endif
 
     /* ... start it up. This will trade welcome banners, exchange keys,
         * and setup crypto, compression, and MAC layers
@@ -249,10 +253,14 @@ int main(int argc, char *argv[])
         }
     } while (1);
 
+#ifdef HAVE_GETTIMEOFDAY
     gettimeofday(&end, NULL);
     time_ms = tvdiff(end, start);
     fprintf(stderr, "Got %d bytes in %ld ms = %.1f bytes/sec spin: %d\n", total,
            time_ms, total/(time_ms/1000.0), spin );
+#else
+    fprintf(stderr, "Got %d bytes spin: %d\n", total, spin);
+#endif
 
     libssh2_sftp_close(sftp_handle);
     libssh2_sftp_shutdown(sftp_session);
diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c
index 2430e33..45853fe 100644
--- a/example/ssh2_echo.c
+++ b/example/ssh2_echo.c
@@ -29,10 +29,13 @@
 #ifdef HAVE_ARPA_INET_H
 # include <arpa/inet.h>
 #endif
-
+#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
+#endif
 #include <sys/types.h>
+#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
+#endif
 #include <fcntl.h>
 #include <errno.h>
 #include <stdio.h>
diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c
index d47761c..ad40c1c 100644
--- a/example/ssh2_exec.c
+++ b/example/ssh2_exec.c
@@ -31,10 +31,13 @@
 #ifdef HAVE_ARPA_INET_H
 # include <arpa/inet.h>
 #endif
-
+#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
+#endif
 #include <sys/types.h>
+#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
+#endif
 #include <fcntl.h>
 #include <errno.h>
 #include <stdio.h>
diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c
index 6f83661..5d0c4e1 100644
--- a/example/subsystem_netconf.c
+++ b/example/subsystem_netconf.c
@@ -16,10 +16,13 @@
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
+#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
+#endif
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <sys/types.h>
-
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
@@ -28,6 +31,12 @@
 #define INADDR_NONE (in_addr_t)~0
 #endif
 
+#ifndef HAVE_SNPRINTF
+# ifdef HAVE__SNPRINTF
+# define snprintf _snprintf
+# endif
+#endif
+
 const char *keyfile1 = "/home/username/.ssh/id_rsa.pub";
 const char *keyfile2 = "/home/username/.ssh/id_rsa";
 const char *username = "username";
diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c
index 94d3cc8..b91e656 100644
--- a/example/tcpip-forward.c
+++ b/example/tcpip-forward.c
@@ -15,10 +15,13 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <stdio.h>
+#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
+#endif
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <sys/types.h>
-
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
diff --git a/include/libssh2.h b/include/libssh2.h
index df873fc..340f59c 100644
--- a/include/libssh2.h
+++ b/include/libssh2.h
@@ -110,7 +110,7 @@ extern "C" {
 # endif /* LIBSSH2_WIN32 */
 #endif /* LIBSSH2_API */
 
-#if defined(LIBSSH2_DARWIN)
+#ifdef HAVE_SYS_UIO_H
 # include <sys/uio.h>
 #endif
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..afe0cee
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,316 @@
+# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+#
+# Redistribution and use in source and binary forms,
+# with or without modification, are permitted provided
+# that the following conditions are met:
+#
+#   Redistributions of source code must retain the above
+#   copyright notice, this list of conditions and the
+#   following disclaimer.
+#
+#   Redistributions in binary form must reproduce the above
+#   copyright notice, this list of conditions and the following
+#   disclaimer in the documentation and/or other materials
+#   provided with the distribution.
+#
+#   Neither the name of the copyright holder nor the names
+#   of any other contributors may be used to endorse or
+#   promote products derived from this software without
+#   specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# OF SUCH DAMAGE.
+
+include(CheckFunctionExists)
+include(CheckFunctionExistsMayNeedLibrary)
+include(CheckIncludeFiles)
+include(CheckTypeSize)
+include(CheckNonblockingSocketSupport)
+
+## Options
+
+option(ENABLE_ZLIB_COMPRESSION "Use zlib for compression")
+if(ENABLE_ZLIB_COMPRESSION)
+  find_package(ZLIB REQUIRED)
+
+  include_directories(${ZLIB_INCLUDE_DIRS})
+  list(APPEND LIBRARIES ${ZLIB_LIBRARIES})
+  if(ZLIB_FOUND)
+    add_definitions(-DLIBSSH2_HAVE_ZLIB=1)
+  endif()
+endif()
+
+option(ENABLE_CRYPT_NONE "Permit \"none\" cipher -- NOT RECOMMENDED")
+if(ENABLE_CRYPT_NONE)
+  add_definitions(-DLIBSSH2_CRYPT_NONE=1)
+endif()
+
+option(ENABLE_MAC_NONE "Permit \"none\" MAC -- NOT RECOMMMENDED")
+if(ENABLE_MAC_NONE)
+  add_definitions(-DLIBSSH2_MAC_NONE=1)
+endif()
+
+option(DISABLE_GEX_NEW "Disable \"new\" diffie-hellman-group-exchange-sha1
+method")
+if(NOT DISABLE_GEX_NEW)
+  add_definitions(-DLIBSSH2_DH_GEX_NEW=1)
+endif()
+
+# Enable debugging logging by default if the user configured a debug build
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+  set(DEBUG_LOGGING_DEFAULT ON)
+else()
+  set(DEBUG_LOGGING_DEFAULT OFF)
+endif()
+option(ENABLE_DEBUG_LOGGING "Log execution with debug trace" ${DEBUG_LOGGING_DEFAULT})
+if(ENABLE_DEBUG_LOGGING)
+  add_definitions(-DLIBSSH2DEBUG)
+endif()
+
+## Cryptography backend choice
+
+set(CRYPTO_BACKEND
+  ""
+  CACHE
+  STRING
+  "The backend to use for cryptography: OpenSSL, Libgcrypt or WinCNG,
+or empty to try any available")
+
+# If the crypto backend was given, rather than searching for the first
+# we are able to find, the find_package commands must abort configuration
+# and report to the user.
+if(CRYPTO_BACKEND)
+  set(SPECIFIC_CRYPTO_REQUIREMENT REQUIRED)
+endif()
+
+if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
+
+  Find_package(OpenSSL ${SPECIFIC_CRYPTO_REQUIREMENT})
+
+  if(OPENSSL_FOUND)
+    set(CRYPTO_BACKEND "OpenSSL")
+    set(CRYPTO_SOURCES openssl.c openssl.h)
+    add_definitions(-DLIBSSH2_OPENSSL)
+
+    include_directories(${OPENSSL_INCLUDE_DIR})
+    list(APPEND LIBRARIES ${OPENSSL_LIBRARIES})
+
+    if(NOT (DEFINED OPENSSL_RUNTIME_LIBRARY_DIRS))
+      # FindXXX modules should set the runtime library paths but most
+      # don't.  The windows binary installer places the .dll files in
+      # a different directory from the .lib files.
+      get_filename_component(_DIR ${OPENSSL_INCLUDE_DIR} PATH)
+      set(_OPENSSL_RUNTIME_LIBRARY_DIRS ${_DIR})
+      # Also try the same directory as the .dll/.so
+      foreach(library ${OPENSSL_LIBRARIES})
+	get_filename_component(_DIR ${library} PATH)
+	list(APPEND _OPENSSL_RUNTIME_LIBRARY_DIRS ${_DIR})
+      endforeach()
+
+      set(OPENSSL_RUNTIME_LIBRARY_DIRS ${_OPENSSL_RUNTIME_LIBRARY_DIRS}
+	CACHE STRING "Directories containing OpenSSL shared libraries")
+    endif()
+
+    list(APPEND _RUNTIME_LIBRARY_DIRS ${OPENSSL_RUNTIME_LIBRARY_DIRS})
+
+    # Not all OpenSSL have AES-CTR functions.
+    set(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+    set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
+    check_function_exists(EVP_aes_128_ctr HAVE_EVP_AES_128_CTR)
+    set(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES})
+  endif()
+endif()
+
+if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND)
+
+  find_package(Libgcrypt ${SPECIFIC_CRYPTO_REQUIREMENT})
+
+  if(LIBGCRYPT_FOUND)
+    set(CRYPTO_BACKEND "Libgcrypt")
+    set(CRYPTO_SOURCES libgcrypt.c libgcrypt.h)
+    add_definitions(-DLIBSSH2_LIBGCRYPT)
+
+    include_directories(${LIBGCRYPT_INCLUDE_DIRS})
+    list(APPEND LIBRARIES ${LIBGCRYPT_LIBRARIES})
+  endif()
+endif()
+
+if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND)
+
+  # The check actually compiles the header.  This requires windows.h.
+  check_include_files("windows.h;bcrypt.h" HAVE_BCRYPT_H)
+
+  if(HAVE_BCRYPT_H)
+    set(CRYPTO_BACKEND "WinCNG")
+    set(CRYPTO_SOURCES wincng.c wincng.h)
+    add_definitions(-DLIBSSH2_WINCNG)
+
+    set(HAVE_LIBCRYPT32 TRUE)
+    list(APPEND LIBRARIES bcrypt)
+
+    check_include_files(ntdef.h HAVE_NTDEF_H)
+    check_include_files(ntstatus.h HAVE_NTSTATUS_H)
+
+    # Reading keys from files is optional and depends on Wincrypt
+    check_include_files("windows.h;wincrypt.h" HAVE_WINCRYPT_H)
+
+    if(HAVE_WINCRYPT_H)
+      list(APPEND LIBRARIES crypt32)
+    endif()
+
+  elseif(${SPECIFIC_CRYPTO_REQUIREMENT} STREQUAL REQUIRED)
+    message(FATAL_ERROR "WinCNG not available")
+  endif()
+endif()
+
+if(NOT CRYPTO_BACKEND)
+  message(FATAL_ERROR "No suitable cryptography backend found.")
+endif()
+
+## Platform checks
+check_include_files(unistd.h HAVE_UNISTD_H)
+check_include_files(inttypes.h HAVE_INTTYPES_H)
+check_include_files(stdlib.h HAVE_STDLIB_H)
+check_include_files(sys/select.h HAVE_SYS_SELECT_H)
+
+check_include_files(sys/uio.h HAVE_SYS_UIO_H)
+check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
+check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H)
+check_include_files(sys/time.h HAVE_SYS_TIME_H)
+check_include_files(sys/un.h HAVE_SYS_UN_H)
+check_include_files(windows.h HAVE_WINDOWS_H)
+check_include_files(ws2tcpip.h HAVE_WS2TCPIP_H)
+check_include_files(winsock2.h HAVE_WINSOCK2_H)
+
+check_type_size("long long" LONGLONG)
+
+check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
+check_function_exists(strtoll HAVE_STRTOLL)
+check_function_exists(snprintf HAVE_SNPRINTF)
+
+if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR
+   ${CMAKE_SYSTEM_NAME} STREQUAL "Interix")
+  # poll() does not work on these platforms
+  #
+  # Interix: "does provide poll(), but the implementing developer must
+  # have been in a bad mood, because poll() only works on the /proc
+  # filesystem here"
+  #
+  # Mac OS X's poll has funny behaviors, like:
+  # not being able to do poll on no fildescriptors (10.3?)
+  # not being able to poll on some files (like anything in /dev)
+  # not having reliable timeout support
+  # inconsistent return of POLLHUP where other implementations give POLLIN
+  message("poll use is disabled on this platform")
+else()
+  check_function_exists(poll HAVE_POLL)
+endif()
+
+# Some systems have socket function in a library
+# (Solaris -lsocket/-lnsl, Windows -lws2_32)
+if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
+  # x86 Windows uses STDCALL for these functions, so their names are mangled,
+  # meaning the platform checks don't work. Hardcoding these until we get
+  # a better solution.
+  set(HAVE_SOCKET 1)
+  set(HAVE_SELECT 1)
+  set(HAVE_INET_ADDR 1)
+  set(NEED_LIB_WS2_32 1)
+else()
+  check_function_exists_may_need_library(socket HAVE_SOCKET socket ws2_32)
+  check_function_exists_may_need_library(select HAVE_SELECT ws2_32)
+  check_function_exists_may_need_library(inet_addr HAVE_INET_ADDR nsl ws2_32)
+endif()
+
+if(NEED_LIB_SOCKET)
+  list(APPEND LIBRARIES socket)
+endif()
+if(NEED_LIB_NSL)
+  list(APPEND LIBRARIES nsl)
+endif()
+if(NEED_LIB_WS2_32)
+  list(APPEND LIBRARIES ws2_32)
+endif()
+
+# Non-blocking socket support tests.  Must be after after library tests to
+# link correctly
+set(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+set(CMAKE_REQUIRED_LIBRARIES ${LIBRARIES})
+check_nonblocking_socket_support()
+set(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES})
+
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config.h.in
+  ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}) # to find generated header
+
+# Check for the OS.
+# Daniel's note: this should not be necessary and we need to work to
+# get this removed.
+if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+  add_definitions(-DLIBSSH2_WIN32)
+elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+  add_definitions(-DLIBSSH2_DARWIN)
+endif()
+
+## Library definition
+
+set(SOURCES
+  ${CRYPTO_SOURCES}
+  agent.c
+  channel.c
+  channel.h
+  comp.c
+  comp.h
+  crypt.c
+  crypto.h
+  global.c
+  hostkey.c
+  keepalive.c
+  kex.c
+  knownhost.c
+  libssh2_priv.h
+  mac.c
+  mac.h
+  misc.c
+  misc.h
+  packet.c
+  packet.h
+  pem.c
+  publickey.c
+  scp.c
+  session.c
+  session.h
+  sftp.c
+  sftp.h
+  transport.c
+  transport.h
+  userauth.c
+  userauth.h
+  version.c)
+
+add_library(ssh2 ${SOURCES})
+target_link_libraries(ssh2 ${LIBRARIES})
+
+foreach(library ${LIBRARIES})
+  get_filename_component(DIR ${library} PATH)
+  list(APPEND BINARY_DEPENDENCY_DIRS ${DIR})
+endforeach()
+
+set(RUNTIME_LIBRARY_DIRS "${_RUNTIME_LIBRARY_DIRS}"
+  CACHE STRING "Binary modules needed in runtime load path")
+
+install(TARGETS ssh2 DESTINATION lib)
+install(FILES libssh2.h libssh2_publickey.h libssh2_sftp.h DESTINATION include)
diff --git a/src/libssh2_config.h.in b/src/libssh2_config.h.in
new file mode 100644
index 0000000..631e329
--- /dev/null
+++ b/src/libssh2_config.h.in
@@ -0,0 +1,104 @@
+/* Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+ * Copyright (c) 1999-2011 Douglas Gilbert. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ *   Redistributions of source code must retain the above
+ *   copyright notice, this list of conditions and the
+ *   following disclaimer.
+ *
+ *   Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the following
+ *   disclaimer in the documentation and/or other materials
+ *   provided with the distribution.
+ *
+ *   Neither the name of the copyright holder nor the names
+ *   of any other contributors may be used to endorse or
+ *   promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ */
+
+/* Headers */
+#cmakedefine HAVE_UNISTD_H
+#cmakedefine HAVE_INTTYPES_H
+#cmakedefine HAVE_STDLIB_H
+#cmakedefine HAVE_SYS_SELECT_H
+#cmakedefine HAVE_SYS_UIO_H
+#cmakedefine HAVE_SYS_SOCKET_H
+#cmakedefine HAVE_SYS_IOCTL_H
+#cmakedefine HAVE_SYS_TIME_H
+#cmakedefine HAVE_SYS_UN_H
+#cmakedefine HAVE_WINDOWS_H
+#cmakedefine HAVE_WS2TCPIP_H
+#cmakedefine HAVE_WINSOCK2_H
+#cmakedefine HAVE_NTDEF_H
+#cmakedefine HAVE_NTSTATUS_H
+
+/* Libraries */
+#cmakedefine HAVE_LIBCRYPT32
+
+/* Types */
+#cmakedefine HAVE_LONGLONG
+
+/* Functions */
+#cmakedefine HAVE_GETTIMEOFDAY
+#cmakedefine HAVE_INET_ADDR
+#cmakedefine HAVE_POLL
+#cmakedefine HAVE_SELECT
+#cmakedefine HAVE_SOCKET
+#cmakedefine HAVE_STRTOLL
+#cmakedefine HAVE_SNPRINTF
+
+/* OpenSSL functions */
+#cmakedefine HAVE_EVP_AES_128_CTR
+
+/* Socket non-blocking support */
+#cmakedefine HAVE_O_NONBLOCK
+#cmakedefine HAVE_FIONBIO
+#cmakedefine HAVE_IOCTLSOCKET
+#cmakedefine HAVE_IOCTLSOCKET_CASE
+#cmakedefine HAVE_SO_NONBLOCK
+#cmakedefine HAVE_DISABLED_NONBLOCKING
+
+/* snprintf not in Visual Studio CRT and _snprintf dangerously incompatible.
+   We provide a safe wrapper if snprintf not found */
+#ifndef HAVE_SNPRINTF
+#include <stdio.h>
+#include <stdarg.h>
+/* Want safe, 'n += snprintf(b + n ...)' like function. If cp_max_len is 1
+* then assume cp is pointing to a null char and do nothing. Returns number
+* number of chars placed in cp excluding the trailing null char. So for
+* cp_max_len > 0 the return value is always < cp_max_len; for cp_max_len
+* <= 0 the return value is 0 (and no chars are written to cp). */
+static int snprintf(char * cp, int cp_max_len, const char * fmt, ...)
+{
+    va_list args;
+    int n;
+
+    if (cp_max_len < 2)
+        return 0;
+    va_start(args, fmt);
+    n = vsnprintf(cp, cp_max_len, fmt, args);
+    va_end(args);
+    return (n < cp_max_len) ? n : (cp_max_len - 1);
+}
+
+#define HAVE_SNPRINTF
+#endif
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..7c11c3e
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,91 @@
+# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+#
+# Redistribution and use in source and binary forms,
+# with or without modification, are permitted provided
+# that the following conditions are met:
+#
+#   Redistributions of source code must retain the above
+#   copyright notice, this list of conditions and the
+#   following disclaimer.
+#
+#   Redistributions in binary form must reproduce the above
+#   copyright notice, this list of conditions and the following
+#   disclaimer in the documentation and/or other materials
+#   provided with the distribution.
+#
+#   Neither the name of the copyright holder nor the names
+#   of any other contributors may be used to endorse or
+#   promote products derived from this software without
+#   specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# OF SUCH DAMAGE.
+
+include(CheckIncludeFiles)
+include(CheckFunctionExists)
+include(CheckSymbolExists)
+include(BundleUtilities)
+
+## Platform checks
+check_include_files(inttypes.h HAVE_INTTYPES_H)
+check_include_files(unistd.h HAVE_UNISTD_H)
+check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
+check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
+check_include_files(windows.h HAVE_WINDOWS_H)
+check_include_files(winsock2.h HAVE_WINSOCK2_H)
+
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config.h.in
+  ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}) # to find generated header
+
+set(TESTS
+  simple
+  ssh2)
+
+# Escape semicolons in runtime library search path list so we can pass it
+# through to the custom command
+string(REPLACE ";" "\$<SEMICOLON>"
+  ESCAPED_RUNTIME_LIBRARY_DIRS "${RUNTIME_LIBRARY_DIRS}")
+
+foreach(test ${TESTS})
+  add_executable(test-${test} ${test}.c)
+  target_link_libraries(test-${test} ssh2)
+
+  add_custom_command(TARGET test-${test} POST_BUILD
+    COMMAND ${CMAKE_COMMAND}
+      -DEXECUTABLE=$<TARGET_FILE:test-${test}>
+      -DSEARCH_DIRS=${ESCAPED_RUNTIME_LIBRARY_DIRS}
+      -P ${CMAKE_SOURCE_DIR}/cmake/FixupExecutable.cmake
+    VERBATIM)
+endforeach()
+
+# TODO convert mansyntax.sh into CMake script.
+# XXX Just because we can find all three programs, doesn't mean sh can
+# find man and grep
+find_program(SH_EXECUTABLE sh)
+find_program(MAN_EXECUTABLE man)
+find_program(GREP_EXECUTABLE grep)
+if(SH_EXECUTABLE AND MAN_EXECUTABLE AND GREP_EXECUTABLE)
+  add_test(mansyntax
+    ${SH_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/mansyntax.sh")
+endif()
+
+add_test(simple test-simple)
+
+find_program(SSHD_EXECUTABLE sshd)
+if(SSHD_EXECUTABLE)
+  add_test(ssh2 test-ssh2)
+endif()
\ No newline at end of file
diff --git a/tests/libssh2_config.h.in b/tests/libssh2_config.h.in
new file mode 100644
index 0000000..35625af
--- /dev/null
+++ b/tests/libssh2_config.h.in
@@ -0,0 +1,43 @@
+/* Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ *   Redistributions of source code must retain the above
+ *   copyright notice, this list of conditions and the
+ *   following disclaimer.
+ *
+ *   Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the following
+ *   disclaimer in the documentation and/or other materials
+ *   provided with the distribution.
+ *
+ *   Neither the name of the copyright holder nor the names
+ *   of any other contributors may be used to endorse or
+ *   promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ */
+
+/* Headers */
+#cmakedefine HAVE_UNISTD_H
+#cmakedefine HAVE_INTTYPES_H
+#cmakedefine HAVE_SYS_SOCKET_H
+#cmakedefine HAVE_ARPA_INET_H
+#cmakedefine HAVE_WINDOWS_H
+#cmakedefine HAVE_WINSOCK2_H
diff --git a/tests/ssh2.c b/tests/ssh2.c
index 9b12e2a..dba6a0f 100644
--- a/tests/ssh2.c
+++ b/tests/ssh2.c
@@ -41,8 +41,6 @@ int main(int argc, char *argv[])
     LIBSSH2_CHANNEL *channel;
 #ifdef WIN32
     WSADATA wsadata;
-
-    WSAStartup(MAKEWORD(2,0), &wsadata);
 #endif
     const char *pubkeyfile="etc/user.pub";
     const char *privkeyfile="etc/user";
@@ -50,6 +48,10 @@ int main(int argc, char *argv[])
     const char *password="password";
     int ec = 1;
 
+#ifdef WIN32
+    WSAStartup(MAKEWORD(2,0), &wsadata);
+#endif
+
     (void)argc;
     (void)argv;
 
-- 
2.1.0


From 97d1478b0da82ccd237bd50dc1d26a3fcab9e5bf Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Sat, 21 Jun 2014 21:32:28 +0100
Subject: [PATCH 02/47] Fix test for required crypto backend.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 src/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index afe0cee..ed211ac 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -170,7 +170,7 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND)
       list(APPEND LIBRARIES crypt32)
     endif()
 
-  elseif(${SPECIFIC_CRYPTO_REQUIREMENT} STREQUAL REQUIRED)
+  elseif(${SPECIFIC_CRYPTO_REQUIREMENT} STREQUAL ${REQUIRED})
     message(FATAL_ERROR "WinCNG not available")
   endif()
 endif()
-- 
2.1.0


From 4aceb343cf4608866fa67af32cdd0395318f3bf8 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Sun, 22 Jun 2014 00:24:09 +0200
Subject: [PATCH 03/47] Fix case issue so examples build on Linux.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 example/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index deb44e2..f56addf 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -74,7 +74,7 @@ foreach(example ${EXAMPLES})
     COMMAND ${CMAKE_COMMAND}
       -DEXECUTABLE=$<TARGET_FILE:example-${example}>
       -DSEARCH_DIRS=${ESCAPED_RUNTIME_LIBRARY_DIRS}
-      -P ${CMAKE_SOURCE_DIR}/CMake/FixupExecutable.cmake
+      -P ${CMAKE_SOURCE_DIR}/cmake/FixupExecutable.cmake
     VERBATIM)
 endforeach()
 
-- 
2.1.0


From f114ca853d09f94dee71dcb80fb82036f445f404 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Sun, 22 Jun 2014 00:24:53 +0200
Subject: [PATCH 04/47] Let mansyntax.sh work regarless of where it is called
 from.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 tests/mansyntax.sh | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tests/mansyntax.sh b/tests/mansyntax.sh
index 3e72c25..88dfe51 100755
--- a/tests/mansyntax.sh
+++ b/tests/mansyntax.sh
@@ -6,7 +6,7 @@ set -e
 # Run syntax checks for all manpages in the documentation tree.
 #
 
-srcdir=${srcdir:-$PWD}
+srcdir="`cd $(dirname $0);pwd`"
 mandir=${srcdir}/../docs
 
 #
@@ -22,6 +22,18 @@ trap "rm -f $srcdir/man3" EXIT
 
 ln -sf "$mandir" "$srcdir/man3"
 
+echo MANDIR
+echo $mandir
+echo $mandir/libssh2_*.*
+echo $mandir/libssh2_*
+echo ${mandir}/libssh2_*.*
+echo MANDIR2
+mandir2=docs
+echo $mandir2
+echo $mandir2/libssh2_*.*
+echo $mandir2/libssh2_*
+echo ${mandir2}/libssh2_*.*
+
 for manpage in $mandir/libssh2_*.*; do
   echo "$manpage"
   warnings=$(LANG=en_US.UTF-8 MANWIDTH=80 man -M "$srcdir" --warnings \
-- 
2.1.0


From 3d9d048fdf99615dbd2886e91417a2faa802c102 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Fri, 27 Jun 2014 14:18:01 +0200
Subject: [PATCH 05/47] Invoke ssh2 test through wrapper that invokes sshd.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 tests/CMakeLists.txt     | 23 +++++++++++++++++++++--
 tests/ssh2.sh            | 48 ------------------------------------------------
 tests/sshd_fixture.sh.in | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 50 deletions(-)
 delete mode 100755 tests/ssh2.sh
 create mode 100644 tests/sshd_fixture.sh.in

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 7c11c3e..ff8e318 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -86,6 +86,25 @@ endif()
 add_test(simple test-simple)
 
 find_program(SSHD_EXECUTABLE sshd)
-if(SSHD_EXECUTABLE)
-  add_test(ssh2 test-ssh2)
+find_program(CHMOD_EXECUTABLE chmod)
+find_program(KILL_EXECUTABLE kill)
+if(SSHD_EXECUTABLE AND CHMOD_EXECUTABLE AND KILL_EXECUTABLE)
+  set(SSHD_TEST_CONFIG_DIR ${CMAKE_CURRENT_BINARY_DIR})
+  set(TEST_NAME ssh2)
+
+  add_custom_command(
+    TARGET test-${TEST_NAME}
+    COMMAND ${CMAKE_COMMAND} -E copy_directory
+    ${CMAKE_CURRENT_SOURCE_DIR}/etc
+    ${SSHD_TEST_CONFIG_DIR}/etc)
+
+  configure_file(
+    ${CMAKE_CURRENT_SOURCE_DIR}/sshd_fixture.sh.in
+    ${CMAKE_CURRENT_BINARY_DIR}/test-${TEST_NAME}_fixture.sh
+    @ONLY)
+
+  add_test(NAME ssh2 COMMAND ${SH_EXECUTABLE}
+    ${CMAKE_CURRENT_BINARY_DIR}/test-${TEST_NAME}_fixture.sh
+    $<TARGET_FILE:test-${TEST_NAME}>)
+
 endif()
\ No newline at end of file
diff --git a/tests/ssh2.sh b/tests/ssh2.sh
deleted file mode 100755
index c2355d5..0000000
--- a/tests/ssh2.sh
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/sh
-
-# Written by Simon Josefsson.
-
-# Start sshd, invoke parameters, saving exit code, kill sshd, and
-# return exit code.
-
-srcdir=${srcdir:-$PWD}
-SSHD=${SSHD:-/usr/sbin/sshd}
-
-cmd="./ssh2${EXEEXT}"
-srcdir=`cd "$srcdir"; pwd`
-
-PRIVKEY=$srcdir/etc/user
-export PRIVKEY
-PUBKEY=$srcdir/etc/user.pub
-export PUBKEY
-
-if test -n "$DEBUG"; then
-    libssh2_sshd_params="-d -d"
-fi
-
-chmod go-rwx "$srcdir"/etc/host*
-$SSHD -f /dev/null -h "$srcdir"/etc/host \
-    -o 'Port 4711' \
-    -o 'Protocol 2' \
-    -o "AuthorizedKeysFile $srcdir/etc/user.pub" \
-    -o 'UsePrivilegeSeparation no' \
-    -o 'StrictModes no' \
-    -D \
-    $libssh2_sshd_params &
-sshdpid=$!
-
-trap "kill ${sshdpid}; echo signal killing sshd; exit 1;" EXIT
-
-: "started sshd (${sshdpid})"
-
-sleep 3
-
-: Invoking $cmd...
-eval $cmd
-ec=$?
-: Self-test exit code $ec
-
-: "killing sshd (${sshdpid})"
-kill "${sshdpid}" > /dev/null 2>&1
-trap "" EXIT
-exit $ec
diff --git a/tests/sshd_fixture.sh.in b/tests/sshd_fixture.sh.in
new file mode 100644
index 0000000..0058f51
--- /dev/null
+++ b/tests/sshd_fixture.sh.in
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+# Written by Simon Josefsson.
+
+# Start sshd, invoke parameters, saving exit code, kill sshd, and
+# return exit code.
+
+srcdir="@SSHD_TEST_CONFIG_DIR@"
+SSHD="@SSHD_EXECUTABLE@"
+
+cmd="\"$1\""
+
+PRIVKEY=$srcdir/etc/user
+export PRIVKEY
+PUBKEY=$srcdir/etc/user.pub
+export PUBKEY
+
+if test -n "$DEBUG"; then
+    libssh2_sshd_params="-d -d"
+fi
+
+chmod go-rwx "$srcdir"/etc/host*
+"$SSHD" -f /dev/null -h "$srcdir/etc/host" \
+    -o 'Port 4711' \
+    -o 'Protocol 2' \
+    -o "AuthorizedKeysFile \"$srcdir/etc/user.pub\"" \
+    -o 'UsePrivilegeSeparation no' \
+    -o 'StrictModes no' \
+    -D \
+    $libssh2_sshd_params &
+sshdpid=$!
+
+trap "kill ${sshdpid}; echo signal killing sshd; exit 1;" EXIT
+
+: "started sshd (${sshdpid})"
+
+sleep 3
+
+: Invoking $cmd...
+eval "$cmd"
+ec=$?
+: Self-test exit code $ec
+
+: "killing sshd (${sshdpid})"
+kill "${sshdpid}" > /dev/null 2>&1
+trap "" EXIT
+exit $ec
-- 
2.1.0


From c6271f96902d34ec74bf746ba52dcf61da51f90d Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Fri, 27 Jun 2014 18:43:19 +0200
Subject: [PATCH 06/47] Mark test script executables as advanced.

The user usually will not want to set these manually.  They either have them or they don't.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 tests/CMakeLists.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index ff8e318..40fddc9 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -78,6 +78,7 @@ endforeach()
 find_program(SH_EXECUTABLE sh)
 find_program(MAN_EXECUTABLE man)
 find_program(GREP_EXECUTABLE grep)
+mark_as_advanced(SH_EXECUTABLE MAN_EXECUTABLE GREP_EXECUTABLE)
 if(SH_EXECUTABLE AND MAN_EXECUTABLE AND GREP_EXECUTABLE)
   add_test(mansyntax
     ${SH_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/mansyntax.sh")
@@ -88,6 +89,7 @@ add_test(simple test-simple)
 find_program(SSHD_EXECUTABLE sshd)
 find_program(CHMOD_EXECUTABLE chmod)
 find_program(KILL_EXECUTABLE kill)
+mark_as_advanced(SSHD_EXECUTABLE CHMOD_EXECUTABLE KILL_EXECUTABLE)
 if(SSHD_EXECUTABLE AND CHMOD_EXECUTABLE AND KILL_EXECUTABLE)
   set(SSHD_TEST_CONFIG_DIR ${CMAKE_CURRENT_BINARY_DIR})
   set(TEST_NAME ssh2)
-- 
2.1.0


From d2c5a690ce8e008d4035b6d86c19a7d81bb09308 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Sat, 28 Jun 2014 01:40:09 +0100
Subject: [PATCH 07/47] Copy OpenSSL DLLs explicitly on Windows, rather than
 using fixup_bundle.

fixup_bundle was causing problems on Linux and didn't always find the right DLL on Windows.  It was also really slow on both platforms.

This commit just copies the two OpenSSL DLLs for each target that needs it.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 cmake/CopyRuntimeDependencies.cmake | 49 +++++++++++++++++++++++++++++++++++
 cmake/FixupExecutable.cmake         |  5 ----
 example/CMakeLists.txt              | 14 ++--------
 src/CMakeLists.txt                  | 51 +++++++++++++++++++------------------
 tests/CMakeLists.txt                | 14 ++--------
 5 files changed, 79 insertions(+), 54 deletions(-)
 create mode 100644 cmake/CopyRuntimeDependencies.cmake
 delete mode 100644 cmake/FixupExecutable.cmake

diff --git a/cmake/CopyRuntimeDependencies.cmake b/cmake/CopyRuntimeDependencies.cmake
new file mode 100644
index 0000000..84a0336
--- /dev/null
+++ b/cmake/CopyRuntimeDependencies.cmake
@@ -0,0 +1,49 @@
+# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+#
+# Redistribution and use in source and binary forms,
+# with or without modification, are permitted provided
+# that the following conditions are met:
+#
+#   Redistributions of source code must retain the above
+#   copyright notice, this list of conditions and the
+#   following disclaimer.
+#
+#   Redistributions in binary form must reproduce the above
+#   copyright notice, this list of conditions and the following
+#   disclaimer in the documentation and/or other materials
+#   provided with the distribution.
+#
+#   Neither the name of the copyright holder nor the names
+#   of any other contributors may be used to endorse or
+#   promote products derived from this software without
+#   specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# OF SUCH DAMAGE.
+
+function(COPY_TO_TARGET_RUNTIME_DIRECTORY target)
+  foreach(dependency ${ARGN})
+
+    get_filename_component(filename ${dependency} NAME)
+
+    add_custom_command(TARGET ${target}
+      DEPENDS ${filename}
+      COMMAND ${CMAKE_COMMAND} -E copy ${dependency}
+      ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${filename})
+
+    install(PROGRAMS ${dependency} DESTINATION bin)
+
+  endforeach()
+endfunction()
diff --git a/cmake/FixupExecutable.cmake b/cmake/FixupExecutable.cmake
deleted file mode 100644
index 2c12b73..0000000
--- a/cmake/FixupExecutable.cmake
+++ /dev/null
@@ -1,5 +0,0 @@
-include(BundleUtilities)
-
-message("Fixing up ${EXECUTABLE} using binaries from ${SEARCH_DIRS}")
-
-fixup_bundle("${EXECUTABLE}" "" "${SEARCH_DIRS}")
\ No newline at end of file
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index f56addf..5d04268 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -36,6 +36,7 @@
 include(CheckIncludeFiles)
 include(CheckFunctionExists)
 include(CheckSymbolExists)
+include(CopyRuntimeDependencies)
 
 set(EXAMPLES
   direct_tcpip
@@ -61,21 +62,10 @@ set(EXAMPLES
   subsystem_netconf
   tcpip-forward)
 
-# Escape semicolons in runtime library search path list so we can pass it
-# through to the custom command
-string(REPLACE ";" "\$<SEMICOLON>"
-  ESCAPED_RUNTIME_LIBRARY_DIRS "${RUNTIME_LIBRARY_DIRS}")
-
 foreach(example ${EXAMPLES})
   add_executable(example-${example} ${example}.c)
   target_link_libraries(example-${example} ssh2)
-
-  add_custom_command(TARGET example-${example} POST_BUILD
-    COMMAND ${CMAKE_COMMAND}
-      -DEXECUTABLE=$<TARGET_FILE:example-${example}>
-      -DSEARCH_DIRS=${ESCAPED_RUNTIME_LIBRARY_DIRS}
-      -P ${CMAKE_SOURCE_DIR}/cmake/FixupExecutable.cmake
-    VERBATIM)
+  copy_to_target_runtime_directory(example-${example} ${RUNTIME_DEPENDENCIES})
 endforeach()
 
 ## Platform checks
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ed211ac..3e07add 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -97,7 +97,7 @@ endif()
 
 if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
 
-  Find_package(OpenSSL ${SPECIFIC_CRYPTO_REQUIREMENT})
+  find_package(OpenSSL ${SPECIFIC_CRYPTO_REQUIREMENT})
 
   if(OPENSSL_FOUND)
     set(CRYPTO_BACKEND "OpenSSL")
@@ -107,24 +107,30 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
     include_directories(${OPENSSL_INCLUDE_DIR})
     list(APPEND LIBRARIES ${OPENSSL_LIBRARIES})
 
-    if(NOT (DEFINED OPENSSL_RUNTIME_LIBRARY_DIRS))
-      # FindXXX modules should set the runtime library paths but most
-      # don't.  The windows binary installer places the .dll files in
-      # a different directory from the .lib files.
-      get_filename_component(_DIR ${OPENSSL_INCLUDE_DIR} PATH)
-      set(_OPENSSL_RUNTIME_LIBRARY_DIRS ${_DIR})
-      # Also try the same directory as the .dll/.so
-      foreach(library ${OPENSSL_LIBRARIES})
-	get_filename_component(_DIR ${library} PATH)
-	list(APPEND _OPENSSL_RUNTIME_LIBRARY_DIRS ${_DIR})
-      endforeach()
-
-      set(OPENSSL_RUNTIME_LIBRARY_DIRS ${_OPENSSL_RUNTIME_LIBRARY_DIRS}
-	CACHE STRING "Directories containing OpenSSL shared libraries")
+    if (WIN32)
+      find_file(DLL_LIBEAY32
+	NAMES libeay32.dll crypto.dll
+        HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS}
+        PATH_SUFFIXES bin)
+      if (NOT DLL_LIBEAY32)
+        message(WARNING
+          "Unable to find OpenSSL libeay32 DLL, executables may not run")
+      endif()
+
+      find_file(DLL_SSLEAY32
+        NAMES ssleay32.dll ssl.dll
+        HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS}
+        PATH_SUFFIXES bin)
+      if (NOT DLL_SSLEAY32)
+        message(WARNING
+          "Unable to find OpenSSL ssleay32 DLL, executables may not run")
+      endif()
+
+      if(DLL_LIBEAY32 AND DLL_SSLEAY32)
+        set(RUNTIME_DEPENDENCIES ${DLL_LIBEAY32} ${DLL_SSLEAY32})
+      endif()
     endif()
 
-    list(APPEND _RUNTIME_LIBRARY_DIRS ${OPENSSL_RUNTIME_LIBRARY_DIRS})
-
     # Not all OpenSSL have AES-CTR functions.
     set(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
     set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
@@ -179,6 +185,9 @@ if(NOT CRYPTO_BACKEND)
   message(FATAL_ERROR "No suitable cryptography backend found.")
 endif()
 
+set(RUNTIME_DEPENDENCIES ${RUNTIME_DEPENDENCIES} CACHE INTERNAL
+  "Files that must be in the same directory as the executables at runtime.")
+
 ## Platform checks
 check_include_files(unistd.h HAVE_UNISTD_H)
 check_include_files(inttypes.h HAVE_INTTYPES_H)
@@ -304,13 +313,5 @@ set(SOURCES
 add_library(ssh2 ${SOURCES})
 target_link_libraries(ssh2 ${LIBRARIES})
 
-foreach(library ${LIBRARIES})
-  get_filename_component(DIR ${library} PATH)
-  list(APPEND BINARY_DEPENDENCY_DIRS ${DIR})
-endforeach()
-
-set(RUNTIME_LIBRARY_DIRS "${_RUNTIME_LIBRARY_DIRS}"
-  CACHE STRING "Binary modules needed in runtime load path")
-
 install(TARGETS ssh2 DESTINATION lib)
 install(FILES libssh2.h libssh2_publickey.h libssh2_sftp.h DESTINATION include)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 40fddc9..b19cee6 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -37,6 +37,7 @@ include(CheckIncludeFiles)
 include(CheckFunctionExists)
 include(CheckSymbolExists)
 include(BundleUtilities)
+include(CopyRuntimeDependencies)
 
 ## Platform checks
 check_include_files(inttypes.h HAVE_INTTYPES_H)
@@ -55,21 +56,10 @@ set(TESTS
   simple
   ssh2)
 
-# Escape semicolons in runtime library search path list so we can pass it
-# through to the custom command
-string(REPLACE ";" "\$<SEMICOLON>"
-  ESCAPED_RUNTIME_LIBRARY_DIRS "${RUNTIME_LIBRARY_DIRS}")
-
 foreach(test ${TESTS})
   add_executable(test-${test} ${test}.c)
   target_link_libraries(test-${test} ssh2)
-
-  add_custom_command(TARGET test-${test} POST_BUILD
-    COMMAND ${CMAKE_COMMAND}
-      -DEXECUTABLE=$<TARGET_FILE:test-${test}>
-      -DSEARCH_DIRS=${ESCAPED_RUNTIME_LIBRARY_DIRS}
-      -P ${CMAKE_SOURCE_DIR}/cmake/FixupExecutable.cmake
-    VERBATIM)
+  copy_to_target_runtime_directory(test-${test} ${RUNTIME_DEPENDENCIES})
 endforeach()
 
 # TODO convert mansyntax.sh into CMake script.
-- 
2.1.0


From 9456fc70cc21ccd7ded6f6869f375e64206a8370 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Sat, 28 Jun 2014 02:08:58 +0100
Subject: [PATCH 08/47] Copy libssh2 DLL to example and test directories when
 building as a shared library.

Otherwise they won't work out-of-the-box.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 cmake/CopyRuntimeDependencies.cmake |  6 ++----
 src/CMakeLists.txt                  | 12 ++++++++----
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/cmake/CopyRuntimeDependencies.cmake b/cmake/CopyRuntimeDependencies.cmake
index 84a0336..f851740 100644
--- a/cmake/CopyRuntimeDependencies.cmake
+++ b/cmake/CopyRuntimeDependencies.cmake
@@ -36,12 +36,10 @@
 function(COPY_TO_TARGET_RUNTIME_DIRECTORY target)
   foreach(dependency ${ARGN})
 
-    get_filename_component(filename ${dependency} NAME)
-
     add_custom_command(TARGET ${target}
-      DEPENDS ${filename}
+      DEPENDS ${dependency}
       COMMAND ${CMAKE_COMMAND} -E copy ${dependency}
-      ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${filename})
+      ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
 
     install(PROGRAMS ${dependency} DESTINATION bin)
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3e07add..222cfb4 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -127,7 +127,7 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
       endif()
 
       if(DLL_LIBEAY32 AND DLL_SSLEAY32)
-        set(RUNTIME_DEPENDENCIES ${DLL_LIBEAY32} ${DLL_SSLEAY32})
+        list(APPEND RUNTIME_DEPENDENCIES ${DLL_LIBEAY32} ${DLL_SSLEAY32})
       endif()
     endif()
 
@@ -185,9 +185,6 @@ if(NOT CRYPTO_BACKEND)
   message(FATAL_ERROR "No suitable cryptography backend found.")
 endif()
 
-set(RUNTIME_DEPENDENCIES ${RUNTIME_DEPENDENCIES} CACHE INTERNAL
-  "Files that must be in the same directory as the executables at runtime.")
-
 ## Platform checks
 check_include_files(unistd.h HAVE_UNISTD_H)
 check_include_files(inttypes.h HAVE_INTTYPES_H)
@@ -315,3 +312,10 @@ target_link_libraries(ssh2 ${LIBRARIES})
 
 install(TARGETS ssh2 DESTINATION lib)
 install(FILES libssh2.h libssh2_publickey.h libssh2_sftp.h DESTINATION include)
+
+if(BUILD_SHARED_LIBS)
+  list(APPEND RUNTIME_DEPENDENCIES $<TARGET_FILE:ssh2>)
+endif()
+
+set(RUNTIME_DEPENDENCIES ${RUNTIME_DEPENDENCIES} CACHE INTERNAL
+    "Files that must be in the same directory as the executables at runtime.")
-- 
2.1.0


From e474449cc0f7b67ffe968e5aff7e5631900e759e Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Mon, 30 Jun 2014 08:33:41 +0100
Subject: [PATCH 09/47] Added Travis CI file.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 .travis.yml | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 .travis.yml

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..60f07ff
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,21 @@
+language: c
+
+compiler:
+  - gcc
+  - clang
+
+env:
+  matrix:
+   - CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF
+   - CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF
+   - CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON
+   - CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
+   - CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF
+   - CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF
+   - CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON
+   - CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
+
+script: mkdir bin && cd bin && cmake -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. && cmake --build . && cmake --build . --target test
+
+before_install:
+ - sudo apt-get install libgcrypt20-dev
\ No newline at end of file
-- 
2.1.0


From 7ef9c90af3e2e233474835054de31cde3305e6b5 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Mon, 30 Jun 2014 08:46:52 +0100
Subject: [PATCH 10/47] Fix Travis libgcrypt dependency.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 60f07ff..2b2fdd9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,4 +18,4 @@ env:
 script: mkdir bin && cd bin && cmake -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. && cmake --build . && cmake --build . --target test
 
 before_install:
- - sudo apt-get install libgcrypt20-dev
\ No newline at end of file
+ - sudo apt-get install libgcrypt11-dev
\ No newline at end of file
-- 
2.1.0


From b9a3565cc6bbf4302121041ea21503ec9df26cac Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Mon, 30 Jun 2014 18:48:42 +0100
Subject: [PATCH 11/47] Summarise chosen optional features after configuring.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 CMakeLists.txt     |  5 ++++-
 src/CMakeLists.txt | 20 ++++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a5ad188..f801548 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,6 +42,7 @@ option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
 
 include(max_warnings)
+include(FeatureSummary)
 
 include_directories(include)
 
@@ -49,4 +50,6 @@ enable_testing()
 
 add_subdirectory(src)
 add_subdirectory(example)
-add_subdirectory(tests)
\ No newline at end of file
+add_subdirectory(tests)
+
+feature_summary(WHAT ALL)
\ No newline at end of file
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 222cfb4..14d6e47 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -41,7 +41,12 @@ include(CheckNonblockingSocketSupport)
 
 ## Options
 
+add_feature_info("Shared library" BUILD_SHARED_LIBS
+  "creating libssh2 as a shared library (.so/.dll)")
+
 option(ENABLE_ZLIB_COMPRESSION "Use zlib for compression")
+add_feature_info(Compression ENABLE_ZLIB_COMPRESSION
+  "using zlib for compression")
 if(ENABLE_ZLIB_COMPRESSION)
   find_package(ZLIB REQUIRED)
 
@@ -53,18 +58,22 @@ if(ENABLE_ZLIB_COMPRESSION)
 endif()
 
 option(ENABLE_CRYPT_NONE "Permit \"none\" cipher -- NOT RECOMMENDED")
+add_feature_info("\"none\" cipher" ENABLE_CRYPT_NONE "")
 if(ENABLE_CRYPT_NONE)
   add_definitions(-DLIBSSH2_CRYPT_NONE=1)
 endif()
 
 option(ENABLE_MAC_NONE "Permit \"none\" MAC -- NOT RECOMMMENDED")
+add_feature_info("\"none\" MAC" ENABLE_MAC_NONE "")
 if(ENABLE_MAC_NONE)
   add_definitions(-DLIBSSH2_MAC_NONE=1)
 endif()
 
-option(DISABLE_GEX_NEW "Disable \"new\" diffie-hellman-group-exchange-sha1
-method")
-if(NOT DISABLE_GEX_NEW)
+option(ENABLE_GEX_NEW
+  "Enable diffie-hellman-group-exchange-sha1 method" ON)
+add_feature_info("diffie-hellman-group-exchange-sha1" ENABLE_GEX_NEW
+  "\"new\" diffie-hellman-group-exchange-sha1 method")
+if(ENABLE_GEX_NEW)
   add_definitions(-DLIBSSH2_DH_GEX_NEW=1)
 endif()
 
@@ -74,7 +83,10 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
 else()
   set(DEBUG_LOGGING_DEFAULT OFF)
 endif()
-option(ENABLE_DEBUG_LOGGING "Log execution with debug trace" ${DEBUG_LOGGING_DEFAULT})
+option(ENABLE_DEBUG_LOGGING "log execution with debug trace"
+  ${DEBUG_LOGGING_DEFAULT})
+add_feature_info(Logging ENABLE_DEBUG_LOGGING
+   "Logging of execution with debug trace")
 if(ENABLE_DEBUG_LOGGING)
   add_definitions(-DLIBSSH2DEBUG)
 endif()
-- 
2.1.0


From ccdb8d11fb9cd30379271904948b5f42dc77e862 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Wed, 2 Jul 2014 18:32:56 +0100
Subject: [PATCH 12/47] Prevent RUNTIME_DEPENDENCIES list growing on every
 configuration.

This change stops appending to RUNTIME_DEPENDENCIES and, instead, sets it directly on each CMake configuration.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 src/CMakeLists.txt | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 14d6e47..e4f8cc5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -139,7 +139,7 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
       endif()
 
       if(DLL_LIBEAY32 AND DLL_SSLEAY32)
-        list(APPEND RUNTIME_DEPENDENCIES ${DLL_LIBEAY32} ${DLL_SSLEAY32})
+        list(APPEND _RUNTIME_DEPENDENCIES ${DLL_LIBEAY32} ${DLL_SSLEAY32})
       endif()
     endif()
 
@@ -326,8 +326,8 @@ install(TARGETS ssh2 DESTINATION lib)
 install(FILES libssh2.h libssh2_publickey.h libssh2_sftp.h DESTINATION include)
 
 if(BUILD_SHARED_LIBS)
-  list(APPEND RUNTIME_DEPENDENCIES $<TARGET_FILE:ssh2>)
+  list(APPEND _RUNTIME_DEPENDENCIES $<TARGET_FILE:ssh2>)
 endif()
 
-set(RUNTIME_DEPENDENCIES ${RUNTIME_DEPENDENCIES} CACHE INTERNAL
+set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL
     "Files that must be in the same directory as the executables at runtime.")
-- 
2.1.0


From 6e126a748c16c8f9d6e1e8651d8ec030ecab8ce1 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Sun, 6 Jul 2014 18:40:45 +0100
Subject: [PATCH 13/47] Let CMakeLists.txt control the libssh2 version.

This will allow us to use the version number in the packages, when we add support for packaging.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 CMakeLists.txt       |   21 +-
 include/libssh2.h    | 1189 -------------------------------------------------
 include/libssh2.h.in | 1200 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1217 insertions(+), 1193 deletions(-)
 delete mode 100644 include/libssh2.h
 create mode 100644 include/libssh2.h.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f801548..0011241 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,16 +35,29 @@
 
 cmake_minimum_required(VERSION 2.8)
 
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
+
+include(max_warnings)
+include(FeatureSummary)
+
 project(libssh2)
 
 option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
 
-set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
+set(LIBSSH2_VERSION_MAJOR 1)
+set(LIBSSH2_VERSION_MINOR 4)
+set(LIBSSH2_VERSION_PATCH 4)
+set(LIBSSH2_VERSION_NUM 0x010404)
 
-include(max_warnings)
-include(FeatureSummary)
+# We use underscore instead of dash when appending DEV in dev versions
+# just to make the BANNER define (used by src/session.c) be a valid
+# SSH banner. Release versions have no appended strings and may of
+# course not have dashes either.
+set(LIBSSH2_VERSION
+  "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}_DEV")
 
-include_directories(include)
+configure_file(include/libssh2.h.in ${CMAKE_CURRENT_BINARY_DIR}/libssh2.h)
+include_directories(include ${CMAKE_CURRENT_BINARY_DIR})
 
 enable_testing()
 
diff --git a/include/libssh2.h b/include/libssh2.h
deleted file mode 100644
index 340f59c..0000000
--- a/include/libssh2.h
+++ /dev/null
@@ -1,1189 +0,0 @@
-/* Copyright (c) 2004-2009, Sara Golemon <sarag@libssh2.org>
- * Copyright (c) 2009-2012 Daniel Stenberg
- * Copyright (c) 2010 Simon Josefsson <simon@josefsson.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms,
- * with or without modification, are permitted provided
- * that the following conditions are met:
- *
- *   Redistributions of source code must retain the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer.
- *
- *   Redistributions in binary form must reproduce the above
- *   copyright notice, this list of conditions and the following
- *   disclaimer in the documentation and/or other materials
- *   provided with the distribution.
- *
- *   Neither the name of the copyright holder nor the names
- *   of any other contributors may be used to endorse or
- *   promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- */
-
-#ifndef LIBSSH2_H
-#define LIBSSH2_H 1
-
-#define LIBSSH2_COPYRIGHT "2004-2012 The libssh2 project and its contributors."
-
-/* We use underscore instead of dash when appending DEV in dev versions just
-   to make the BANNER define (used by src/session.c) be a valid SSH
-   banner. Release versions have no appended strings and may of course not
-   have dashes either. */
-#define LIBSSH2_VERSION "1.4.3"
-
-/* The numeric version number is also available "in parts" by using these
-   defines: */
-#define LIBSSH2_VERSION_MAJOR 1
-#define LIBSSH2_VERSION_MINOR 4
-#define LIBSSH2_VERSION_PATCH 3
-
-/* This is the numeric version of the libssh2 version number, meant for easier
-   parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
-   always follow this syntax:
-
-         0xXXYYZZ
-
-   Where XX, YY and ZZ are the main version, release and patch numbers in
-   hexadecimal (using 8 bits each). All three numbers are always represented
-   using two digits.  1.2 would appear as "0x010200" while version 9.11.7
-   appears as "0x090b07".
-
-   This 6-digit (24 bits) hexadecimal number does not show pre-release number,
-   and it is always a greater number in a more recent release. It makes
-   comparisons with greater than and less than work.
-*/
-#define LIBSSH2_VERSION_NUM 0x010403
-
-/*
- * This is the date and time when the full source package was created. The
- * timestamp is not stored in the source code repo, as the timestamp is
- * properly set in the tarballs by the maketgz script.
- *
- * The format of the date should follow this template:
- *
- * "Mon Feb 12 11:35:33 UTC 2007"
- */
-#define LIBSSH2_TIMESTAMP "Tue Nov 27 21:45:20 UTC 2012"
-
-#ifndef RC_INVOKED
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#ifdef _WIN32
-# include <basetsd.h>
-# include <winsock2.h>
-#endif
-
-#include <stddef.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Allow alternate API prefix from CFLAGS or calling app */
-#ifndef LIBSSH2_API
-# ifdef LIBSSH2_WIN32
-#  ifdef LIBSSH2_LIBRARY
-#   define LIBSSH2_API __declspec(dllexport)
-#  else
-#   define LIBSSH2_API __declspec(dllimport)
-#  endif /* LIBSSH2_LIBRARY */
-# else /* !LIBSSH2_WIN32 */
-#  define LIBSSH2_API
-# endif /* LIBSSH2_WIN32 */
-#endif /* LIBSSH2_API */
-
-#ifdef HAVE_SYS_UIO_H
-# include <sys/uio.h>
-#endif
-
-#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
-# include <sys/bsdskt.h>
-typedef unsigned char uint8_t;
-typedef unsigned int uint32_t;
-#endif
-
-#ifdef _MSC_VER
-typedef unsigned char uint8_t;
-typedef unsigned int uint32_t;
-typedef unsigned __int64 libssh2_uint64_t;
-typedef __int64 libssh2_int64_t;
-#ifndef ssize_t
-typedef SSIZE_T ssize_t;
-#endif
-#else
-typedef unsigned long long libssh2_uint64_t;
-typedef long long libssh2_int64_t;
-#endif
-
-#ifdef WIN32
-typedef SOCKET libssh2_socket_t;
-#define LIBSSH2_INVALID_SOCKET INVALID_SOCKET
-#else /* !WIN32 */
-typedef int libssh2_socket_t;
-#define LIBSSH2_INVALID_SOCKET -1
-#endif /* WIN32 */
-
-/* Part of every banner, user specified or not */
-#define LIBSSH2_SSH_BANNER                  "SSH-2.0-libssh2_" LIBSSH2_VERSION
-
-/* We *could* add a comment here if we so chose */
-#define LIBSSH2_SSH_DEFAULT_BANNER                  LIBSSH2_SSH_BANNER
-#define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF        LIBSSH2_SSH_DEFAULT_BANNER "\r\n"
-
-/* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1 */
-#define LIBSSH2_DH_GEX_MINGROUP     1024
-#define LIBSSH2_DH_GEX_OPTGROUP     1536
-#define LIBSSH2_DH_GEX_MAXGROUP     2048
-
-/* Defaults for pty requests */
-#define LIBSSH2_TERM_WIDTH      80
-#define LIBSSH2_TERM_HEIGHT     24
-#define LIBSSH2_TERM_WIDTH_PX   0
-#define LIBSSH2_TERM_HEIGHT_PX  0
-
-/* 1/4 second */
-#define LIBSSH2_SOCKET_POLL_UDELAY      250000
-/* 0.25 * 120 == 30 seconds */
-#define LIBSSH2_SOCKET_POLL_MAXLOOPS    120
-
-/* Maximum size to allow a payload to compress to, plays it safe by falling
-   short of spec limits */
-#define LIBSSH2_PACKET_MAXCOMP      32000
-
-/* Maximum size to allow a payload to deccompress to, plays it safe by
-   allowing more than spec requires */
-#define LIBSSH2_PACKET_MAXDECOMP    40000
-
-/* Maximum size for an inbound compressed payload, plays it safe by
-   overshooting spec limits */
-#define LIBSSH2_PACKET_MAXPAYLOAD   40000
-
-/* Malloc callbacks */
-#define LIBSSH2_ALLOC_FUNC(name)   void *name(size_t count, void **abstract)
-#define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, \
-                                              void **abstract)
-#define LIBSSH2_FREE_FUNC(name)    void name(void *ptr, void **abstract)
-
-typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT
-{
-    char* text;
-    unsigned int length;
-    unsigned char echo;
-} LIBSSH2_USERAUTH_KBDINT_PROMPT;
-
-typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE
-{
-    char* text;
-    unsigned int length;
-} LIBSSH2_USERAUTH_KBDINT_RESPONSE;
-
-/* 'publickey' authentication callback */
-#define LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC(name) \
-  int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \
-           const unsigned char *data, size_t data_len, void **abstract)
-
-/* 'keyboard-interactive' authentication callback */
-#define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) \
- void name_(const char* name, int name_len, const char* instruction, \
-            int instruction_len, int num_prompts, \
-            const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, \
-            LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract)
-
-/* Callbacks for special SSH packets */
-#define LIBSSH2_IGNORE_FUNC(name) \
- void name(LIBSSH2_SESSION *session, const char *message, int message_len, \
-           void **abstract)
-
-#define LIBSSH2_DEBUG_FUNC(name) \
- void name(LIBSSH2_SESSION *session, int always_display, const char *message, \
-           int message_len, const char *language, int language_len, \
-           void **abstract)
-
-#define LIBSSH2_DISCONNECT_FUNC(name) \
- void name(LIBSSH2_SESSION *session, int reason, const char *message, \
-           int message_len, const char *language, int language_len, \
-           void **abstract)
-
-#define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) \
- void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, \
-           void **abstract)
-
-#define LIBSSH2_MACERROR_FUNC(name) \
- int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, \
-          void **abstract)
-
-#define LIBSSH2_X11_OPEN_FUNC(name) \
- void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \
-           const char *shost, int sport, void **abstract)
-
-#define LIBSSH2_CHANNEL_CLOSE_FUNC(name) \
-  void name(LIBSSH2_SESSION *session, void **session_abstract, \
-            LIBSSH2_CHANNEL *channel, void **channel_abstract)
-
-/* I/O callbacks */
-#define LIBSSH2_RECV_FUNC(name)  ssize_t name(libssh2_socket_t socket, \
-                                              void *buffer, size_t length, \
-                                              int flags, void **abstract)
-#define LIBSSH2_SEND_FUNC(name)  ssize_t name(libssh2_socket_t socket, \
-                                              const void *buffer, size_t length,\
-                                              int flags, void **abstract)
-
-/* libssh2_session_callback_set() constants */
-#define LIBSSH2_CALLBACK_IGNORE             0
-#define LIBSSH2_CALLBACK_DEBUG              1
-#define LIBSSH2_CALLBACK_DISCONNECT         2
-#define LIBSSH2_CALLBACK_MACERROR           3
-#define LIBSSH2_CALLBACK_X11                4
-#define LIBSSH2_CALLBACK_SEND               5
-#define LIBSSH2_CALLBACK_RECV               6
-
-/* libssh2_session_method_pref() constants */
-#define LIBSSH2_METHOD_KEX          0
-#define LIBSSH2_METHOD_HOSTKEY      1
-#define LIBSSH2_METHOD_CRYPT_CS     2
-#define LIBSSH2_METHOD_CRYPT_SC     3
-#define LIBSSH2_METHOD_MAC_CS       4
-#define LIBSSH2_METHOD_MAC_SC       5
-#define LIBSSH2_METHOD_COMP_CS      6
-#define LIBSSH2_METHOD_COMP_SC      7
-#define LIBSSH2_METHOD_LANG_CS      8
-#define LIBSSH2_METHOD_LANG_SC      9
-
-/* flags */
-#define LIBSSH2_FLAG_SIGPIPE        1
-#define LIBSSH2_FLAG_COMPRESS       2
-
-typedef struct _LIBSSH2_SESSION                     LIBSSH2_SESSION;
-typedef struct _LIBSSH2_CHANNEL                     LIBSSH2_CHANNEL;
-typedef struct _LIBSSH2_LISTENER                    LIBSSH2_LISTENER;
-typedef struct _LIBSSH2_KNOWNHOSTS                  LIBSSH2_KNOWNHOSTS;
-typedef struct _LIBSSH2_AGENT                       LIBSSH2_AGENT;
-
-typedef struct _LIBSSH2_POLLFD {
-    unsigned char type; /* LIBSSH2_POLLFD_* below */
-
-    union {
-        int socket; /* File descriptors -- examined with system select() call */
-        LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */
-        LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound
-                                       connections waiting to be accepted? */
-    } fd;
-
-    unsigned long events; /* Requested Events */
-    unsigned long revents; /* Returned Events */
-} LIBSSH2_POLLFD;
-
-/* Poll FD Descriptor Types */
-#define LIBSSH2_POLLFD_SOCKET       1
-#define LIBSSH2_POLLFD_CHANNEL      2
-#define LIBSSH2_POLLFD_LISTENER     3
-
-/* Note: Win32 Doesn't actually have a poll() implementation, so some of these
-   values are faked with select() data */
-/* Poll FD events/revents -- Match sys/poll.h where possible */
-#define LIBSSH2_POLLFD_POLLIN           0x0001 /* Data available to be read or
-                                                  connection available --
-                                                  All */
-#define LIBSSH2_POLLFD_POLLPRI          0x0002 /* Priority data available to
-                                                  be read -- Socket only */
-#define LIBSSH2_POLLFD_POLLEXT          0x0002 /* Extended data available to
-                                                  be read -- Channel only */
-#define LIBSSH2_POLLFD_POLLOUT          0x0004 /* Can may be written --
-                                                  Socket/Channel */
-/* revents only */
-#define LIBSSH2_POLLFD_POLLERR          0x0008 /* Error Condition -- Socket */
-#define LIBSSH2_POLLFD_POLLHUP          0x0010 /* HangUp/EOF -- Socket */
-#define LIBSSH2_POLLFD_SESSION_CLOSED   0x0010 /* Session Disconnect */
-#define LIBSSH2_POLLFD_POLLNVAL         0x0020 /* Invalid request -- Socket
-                                                  Only */
-#define LIBSSH2_POLLFD_POLLEX           0x0040 /* Exception Condition --
-                                                  Socket/Win32 */
-#define LIBSSH2_POLLFD_CHANNEL_CLOSED   0x0080 /* Channel Disconnect */
-#define LIBSSH2_POLLFD_LISTENER_CLOSED  0x0080 /* Listener Disconnect */
-
-#define HAVE_LIBSSH2_SESSION_BLOCK_DIRECTION
-/* Block Direction Types */
-#define LIBSSH2_SESSION_BLOCK_INBOUND                  0x0001
-#define LIBSSH2_SESSION_BLOCK_OUTBOUND                 0x0002
-
-/* Hash Types */
-#define LIBSSH2_HOSTKEY_HASH_MD5                            1
-#define LIBSSH2_HOSTKEY_HASH_SHA1                           2
-
-/* Hostkey Types */
-#define LIBSSH2_HOSTKEY_TYPE_UNKNOWN			    0
-#define LIBSSH2_HOSTKEY_TYPE_RSA			    1
-#define LIBSSH2_HOSTKEY_TYPE_DSS			    2
-
-/* Disconnect Codes (defined by SSH protocol) */
-#define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT          1
-#define SSH_DISCONNECT_PROTOCOL_ERROR                       2
-#define SSH_DISCONNECT_KEY_EXCHANGE_FAILED                  3
-#define SSH_DISCONNECT_RESERVED                             4
-#define SSH_DISCONNECT_MAC_ERROR                            5
-#define SSH_DISCONNECT_COMPRESSION_ERROR                    6
-#define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE                7
-#define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED       8
-#define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE              9
-#define SSH_DISCONNECT_CONNECTION_LOST                      10
-#define SSH_DISCONNECT_BY_APPLICATION                       11
-#define SSH_DISCONNECT_TOO_MANY_CONNECTIONS                 12
-#define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER               13
-#define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE       14
-#define SSH_DISCONNECT_ILLEGAL_USER_NAME                    15
-
-/* Error Codes (defined by libssh2) */
-#define LIBSSH2_ERROR_NONE                      0
-
-/* The library once used -1 as a generic error return value on numerous places
-   through the code, which subsequently was converted to
-   LIBSSH2_ERROR_SOCKET_NONE uses over time. As this is a generic error code,
-   the goal is to never ever return this code but instead make sure that a
-   more accurate and descriptive error code is used. */
-#define LIBSSH2_ERROR_SOCKET_NONE               -1
-
-#define LIBSSH2_ERROR_BANNER_RECV               -2
-#define LIBSSH2_ERROR_BANNER_SEND               -3
-#define LIBSSH2_ERROR_INVALID_MAC               -4
-#define LIBSSH2_ERROR_KEX_FAILURE               -5
-#define LIBSSH2_ERROR_ALLOC                     -6
-#define LIBSSH2_ERROR_SOCKET_SEND               -7
-#define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE      -8
-#define LIBSSH2_ERROR_TIMEOUT                   -9
-#define LIBSSH2_ERROR_HOSTKEY_INIT              -10
-#define LIBSSH2_ERROR_HOSTKEY_SIGN              -11
-#define LIBSSH2_ERROR_DECRYPT                   -12
-#define LIBSSH2_ERROR_SOCKET_DISCONNECT         -13
-#define LIBSSH2_ERROR_PROTO                     -14
-#define LIBSSH2_ERROR_PASSWORD_EXPIRED          -15
-#define LIBSSH2_ERROR_FILE                      -16
-#define LIBSSH2_ERROR_METHOD_NONE               -17
-#define LIBSSH2_ERROR_AUTHENTICATION_FAILED     -18
-#define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED    LIBSSH2_ERROR_AUTHENTICATION_FAILED
-#define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED      -19
-#define LIBSSH2_ERROR_CHANNEL_OUTOFORDER        -20
-#define LIBSSH2_ERROR_CHANNEL_FAILURE           -21
-#define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED    -22
-#define LIBSSH2_ERROR_CHANNEL_UNKNOWN           -23
-#define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED   -24
-#define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED   -25
-#define LIBSSH2_ERROR_CHANNEL_CLOSED            -26
-#define LIBSSH2_ERROR_CHANNEL_EOF_SENT          -27
-#define LIBSSH2_ERROR_SCP_PROTOCOL              -28
-#define LIBSSH2_ERROR_ZLIB                      -29
-#define LIBSSH2_ERROR_SOCKET_TIMEOUT            -30
-#define LIBSSH2_ERROR_SFTP_PROTOCOL             -31
-#define LIBSSH2_ERROR_REQUEST_DENIED            -32
-#define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED      -33
-#define LIBSSH2_ERROR_INVAL                     -34
-#define LIBSSH2_ERROR_INVALID_POLL_TYPE         -35
-#define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL        -36
-#define LIBSSH2_ERROR_EAGAIN                    -37
-#define LIBSSH2_ERROR_BUFFER_TOO_SMALL          -38
-#define LIBSSH2_ERROR_BAD_USE                   -39
-#define LIBSSH2_ERROR_COMPRESS                  -40
-#define LIBSSH2_ERROR_OUT_OF_BOUNDARY           -41
-#define LIBSSH2_ERROR_AGENT_PROTOCOL            -42
-#define LIBSSH2_ERROR_SOCKET_RECV               -43
-#define LIBSSH2_ERROR_ENCRYPT                   -44
-#define LIBSSH2_ERROR_BAD_SOCKET                -45
-#define LIBSSH2_ERROR_KNOWN_HOSTS               -46
-
-/* this is a define to provide the old (<= 1.2.7) name */
-#define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV
-
-/* Global API */
-#define LIBSSH2_INIT_NO_CRYPTO        0x0001
-
-/*
- * libssh2_init()
- *
- * Initialize the libssh2 functions.  This typically initialize the
- * crypto library.  It uses a global state, and is not thread safe --
- * you must make sure this function is not called concurrently.
- *
- * Flags can be:
- * 0:                              Normal initialize
- * LIBSSH2_INIT_NO_CRYPTO:         Do not initialize the crypto library (ie.
- *                                 OPENSSL_add_cipher_algoritms() for OpenSSL
- *
- * Returns 0 if succeeded, or a negative value for error.
- */
-LIBSSH2_API int libssh2_init(int flags);
-
-/*
- * libssh2_exit()
- *
- * Exit the libssh2 functions and free's all memory used internal.
- */
-LIBSSH2_API void libssh2_exit(void);
-
-/*
- * libssh2_free()
- *
- * Deallocate memory allocated by earlier call to libssh2 functions.
- */
-LIBSSH2_API void libssh2_free(LIBSSH2_SESSION *session, void *ptr);
-
-/*
- * libssh2_session_supported_algs()
- *
- * Fills algs with a list of supported acryptographic algorithms. Returns a
- * non-negative number (number of supported algorithms) on success or a
- * negative number (an eror code) on failure.
- *
- * NOTE: on success, algs must be deallocated (by calling libssh2_free) when
- * not needed anymore
- */
-LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
-                                               int method_type,
-                                               const char*** algs);
-
-/* Session API */
-LIBSSH2_API LIBSSH2_SESSION *
-libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
-                        LIBSSH2_FREE_FUNC((*my_free)),
-                        LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract);
-#define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL)
-
-LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session);
-
-LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session,
-                                               int cbtype, void *callback);
-LIBSSH2_API int libssh2_session_banner_set(LIBSSH2_SESSION *session,
-                                           const char *banner);
-LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session,
-                                   const char *banner);
-
-LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int sock);
-LIBSSH2_API int libssh2_session_handshake(LIBSSH2_SESSION *session,
-                                          libssh2_socket_t sock);
-LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session,
-                                              int reason,
-                                              const char *description,
-                                              const char *lang);
-#define libssh2_session_disconnect(session, description) \
-  libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, \
-                                (description), "")
-
-LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session);
-
-LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session,
-                                             int hash_type);
-
-LIBSSH2_API const char *libssh2_session_hostkey(LIBSSH2_SESSION *session,
-                                                size_t *len, int *type);
-
-LIBSSH2_API int libssh2_session_method_pref(LIBSSH2_SESSION *session,
-                                            int method_type,
-                                            const char *prefs);
-LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session,
-                                                int method_type);
-LIBSSH2_API int libssh2_session_last_error(LIBSSH2_SESSION *session,
-                                           char **errmsg,
-                                           int *errmsg_len, int want_buf);
-LIBSSH2_API int libssh2_session_last_errno(LIBSSH2_SESSION *session);
-LIBSSH2_API int libssh2_session_block_directions(LIBSSH2_SESSION *session);
-
-LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag,
-                                     int value);
-LIBSSH2_API const char *libssh2_session_banner_get(LIBSSH2_SESSION *session);
-
-/* Userauth API */
-LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session,
-                                        const char *username,
-                                        unsigned int username_len);
-LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);
-
-LIBSSH2_API int libssh2_userauth_password_ex(LIBSSH2_SESSION *session,
-                                             const char *username,
-                                             unsigned int username_len,
-                                             const char *password,
-                                             unsigned int password_len,
-                                             LIBSSH2_PASSWD_CHANGEREQ_FUNC((*passwd_change_cb)));
-
-#define libssh2_userauth_password(session, username, password) \
- libssh2_userauth_password_ex((session), (username), strlen(username), \
-                              (password), strlen(password), NULL)
-
-LIBSSH2_API int
-libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
-                                       const char *username,
-                                       unsigned int username_len,
-                                       const char *publickey,
-                                       const char *privatekey,
-                                       const char *passphrase);
-
-#define libssh2_userauth_publickey_fromfile(session, username, publickey, \
-                                            privatekey, passphrase)     \
-  libssh2_userauth_publickey_fromfile_ex((session), (username), \
-                                         strlen(username), (publickey), \
-                                         (privatekey), (passphrase))
-
-LIBSSH2_API int
-libssh2_userauth_publickey(LIBSSH2_SESSION *session,
-                           const char *username,
-                           const unsigned char *pubkeydata,
-                           size_t pubkeydata_len,
-                           LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC((*sign_callback)),
-                           void **abstract);
-
-LIBSSH2_API int
-libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session,
-                                       const char *username,
-                                       unsigned int username_len,
-                                       const char *publickey,
-                                       const char *privatekey,
-                                       const char *passphrase,
-                                       const char *hostname,
-                                       unsigned int hostname_len,
-                                       const char *local_username,
-                                       unsigned int local_username_len);
-
-#define libssh2_userauth_hostbased_fromfile(session, username, publickey, \
-                                            privatekey, passphrase, hostname) \
- libssh2_userauth_hostbased_fromfile_ex((session), (username), \
-                                        strlen(username), (publickey), \
-                                        (privatekey), (passphrase), \
-                                        (hostname), strlen(hostname), \
-                                        (username), strlen(username))
-
-/*
- * response_callback is provided with filled by library prompts array,
- * but client must allocate and fill individual responses. Responses
- * array is already allocated. Responses data will be freed by libssh2
- * after callback return, but before subsequent callback invokation.
- */
-LIBSSH2_API int
-libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session,
-                                         const char *username,
-                                         unsigned int username_len,
-                                         LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC((*response_callback)));
-
-#define libssh2_userauth_keyboard_interactive(session, username, \
-                                              response_callback) \
- libssh2_userauth_keyboard_interactive_ex((session), (username), \
-                                          strlen(username), (response_callback))
-
-LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds,
-                             long timeout);
-
-/* Channel API */
-#define LIBSSH2_CHANNEL_WINDOW_DEFAULT  (2*1024*1024)
-#define LIBSSH2_CHANNEL_PACKET_DEFAULT  32768
-#define LIBSSH2_CHANNEL_MINADJUST       1024
-
-/* Extended Data Handling */
-#define LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL        0
-#define LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE        1
-#define LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE         2
-
-#define SSH_EXTENDED_DATA_STDERR 1
-
-/* Returned by any function that would block during a read/write opperation */
-#define LIBSSH2CHANNEL_EAGAIN LIBSSH2_ERROR_EAGAIN
-
-LIBSSH2_API LIBSSH2_CHANNEL *
-libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type,
-                        unsigned int channel_type_len,
-                        unsigned int window_size, unsigned int packet_size,
-                        const char *message, unsigned int message_len);
-
-#define libssh2_channel_open_session(session) \
-  libssh2_channel_open_ex((session), "session", sizeof("session") - 1, \
-                          LIBSSH2_CHANNEL_WINDOW_DEFAULT, \
-                          LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0)
-
-LIBSSH2_API LIBSSH2_CHANNEL *
-libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host,
-                                int port, const char *shost, int sport);
-#define libssh2_channel_direct_tcpip(session, host, port) \
-  libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22)
-
-LIBSSH2_API LIBSSH2_LISTENER *
-libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host,
-                                  int port, int *bound_port, int queue_maxsize);
-#define libssh2_channel_forward_listen(session, port) \
- libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16)
-
-LIBSSH2_API int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
-
-LIBSSH2_API LIBSSH2_CHANNEL *
-libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener);
-
-LIBSSH2_API int libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel,
-                                          const char *varname,
-                                          unsigned int varname_len,
-                                          const char *value,
-                                          unsigned int value_len);
-
-#define libssh2_channel_setenv(channel, varname, value) \
- libssh2_channel_setenv_ex((channel), (varname), strlen(varname), (value), \
-                           strlen(value))
-
-LIBSSH2_API int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel,
-                                               const char *term,
-                                               unsigned int term_len,
-                                               const char *modes,
-                                               unsigned int modes_len,
-                                               int width, int height,
-                                               int width_px, int height_px);
-#define libssh2_channel_request_pty(channel, term) \
- libssh2_channel_request_pty_ex((channel), (term), strlen(term), NULL, 0, \
-                                LIBSSH2_TERM_WIDTH, LIBSSH2_TERM_HEIGHT, \
-                                LIBSSH2_TERM_WIDTH_PX, LIBSSH2_TERM_HEIGHT_PX)
-
-LIBSSH2_API int libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL *channel,
-                                                    int width, int height,
-                                                    int width_px,
-                                                    int height_px);
-#define libssh2_channel_request_pty_size(channel, width, height) \
-  libssh2_channel_request_pty_size_ex( (channel), (width), (height), 0, 0)
-
-LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel,
-                                           int single_connection,
-                                           const char *auth_proto,
-                                           const char *auth_cookie,
-                                           int screen_number);
-#define libssh2_channel_x11_req(channel, screen_number) \
- libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number))
-
-LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
-                                                const char *request,
-                                                unsigned int request_len,
-                                                const char *message,
-                                                unsigned int message_len);
-#define libssh2_channel_shell(channel) \
-  libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, \
-                                  NULL, 0)
-#define libssh2_channel_exec(channel, command) \
-  libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, \
-                                  (command), strlen(command))
-#define libssh2_channel_subsystem(channel, subsystem) \
-  libssh2_channel_process_startup((channel), "subsystem",              \
-                                  sizeof("subsystem") - 1, (subsystem), \
-                                  strlen(subsystem))
-
-LIBSSH2_API ssize_t libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel,
-                                            int stream_id, char *buf,
-                                            size_t buflen);
-#define libssh2_channel_read(channel, buf, buflen) \
-  libssh2_channel_read_ex((channel), 0, (buf), (buflen))
-#define libssh2_channel_read_stderr(channel, buf, buflen) \
-  libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
-
-LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel,
-                                          int extended);
-
-LIBSSH2_API unsigned long
-libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
-                               unsigned long *read_avail,
-                               unsigned long *window_size_initial);
-#define libssh2_channel_window_read(channel) \
-  libssh2_channel_window_read_ex((channel), NULL, NULL)
-
-/* libssh2_channel_receive_window_adjust is DEPRECATED, do not use! */
-LIBSSH2_API unsigned long
-libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
-                                      unsigned long adjustment,
-                                      unsigned char force);
-
-LIBSSH2_API int
-libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel,
-                                       unsigned long adjustment,
-                                       unsigned char force,
-                                       unsigned int *storewindow);
-
-LIBSSH2_API ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
-                                             int stream_id, const char *buf,
-                                             size_t buflen);
-
-#define libssh2_channel_write(channel, buf, buflen) \
-  libssh2_channel_write_ex((channel), 0, (buf), (buflen))
-#define libssh2_channel_write_stderr(channel, buf, buflen)  \
-  libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
-
-LIBSSH2_API unsigned long
-libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel,
-                                unsigned long *window_size_initial);
-#define libssh2_channel_window_write(channel) \
-  libssh2_channel_window_write_ex((channel), NULL)
-
-LIBSSH2_API void libssh2_session_set_blocking(LIBSSH2_SESSION* session,
-                                              int blocking);
-LIBSSH2_API int libssh2_session_get_blocking(LIBSSH2_SESSION* session);
-
-LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel,
-                                              int blocking);
-
-LIBSSH2_API void libssh2_session_set_timeout(LIBSSH2_SESSION* session,
-                                             long timeout);
-LIBSSH2_API long libssh2_session_get_timeout(LIBSSH2_SESSION* session);
-
-/* libssh2_channel_handle_extended_data is DEPRECATED, do not use! */
-LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel,
-                                                      int ignore_mode);
-LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel,
-                                                      int ignore_mode);
-
-/* libssh2_channel_ignore_extended_data() is defined below for BC with version
- * 0.1
- *
- * Future uses should use libssh2_channel_handle_extended_data() directly if
- * LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read
- * (FIFO) from the standard data channel
- */
-/* DEPRECATED */
-#define libssh2_channel_ignore_extended_data(channel, ignore) \
-  libssh2_channel_handle_extended_data((channel),                       \
-                                       (ignore) ?                       \
-                                       LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : \
-                                       LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL )
-
-#define LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA     -1
-#define LIBSSH2_CHANNEL_FLUSH_ALL               -2
-LIBSSH2_API int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel,
-                                         int streamid);
-#define libssh2_channel_flush(channel) libssh2_channel_flush_ex((channel), 0)
-#define libssh2_channel_flush_stderr(channel) \
- libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR)
-
-LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel);
-LIBSSH2_API int libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL* channel,
-                                                char **exitsignal,
-                                                size_t *exitsignal_len,
-                                                char **errmsg,
-                                                size_t *errmsg_len,
-                                                char **langtag,
-                                                size_t *langtag_len);
-LIBSSH2_API int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel);
-LIBSSH2_API int libssh2_channel_eof(LIBSSH2_CHANNEL *channel);
-LIBSSH2_API int libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel);
-LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel);
-LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel);
-LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel);
-
-LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
-                                              const char *path,
-                                              struct stat *sb);
-LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session,
-                                                 const char *path, int mode,
-                                                 size_t size, long mtime,
-                                                 long atime);
-LIBSSH2_API LIBSSH2_CHANNEL *
-libssh2_scp_send64(LIBSSH2_SESSION *session, const char *path, int mode,
-                   libssh2_int64_t size, time_t mtime, time_t atime);
-
-#define libssh2_scp_send(session, path, mode, size) \
-  libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0)
-
-LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest,
-                                      unsigned int *dest_len,
-                                      const char *src, unsigned int src_len);
-
-LIBSSH2_API
-const char *libssh2_version(int req_version_num);
-
-#define HAVE_LIBSSH2_KNOWNHOST_API 0x010101 /* since 1.1.1 */
-#define HAVE_LIBSSH2_VERSION_API   0x010100 /* libssh2_version since 1.1 */
-
-struct libssh2_knownhost {
-    unsigned int magic;  /* magic stored by the library */
-    void *node; /* handle to the internal representation of this host */
-    char *name; /* this is NULL if no plain text host name exists */
-    char *key;  /* key in base64/printable format */
-    int typemask;
-};
-
-/*
- * libssh2_knownhost_init
- *
- * Init a collection of known hosts. Returns the pointer to a collection.
- *
- */
-LIBSSH2_API LIBSSH2_KNOWNHOSTS *
-libssh2_knownhost_init(LIBSSH2_SESSION *session);
-
-/*
- * libssh2_knownhost_add
- *
- * Add a host and its associated key to the collection of known hosts.
- *
- * The 'type' argument specifies on what format the given host and keys are:
- *
- * plain  - ascii "hostname.domain.tld"
- * sha1   - SHA1(<salt> <host>) base64-encoded!
- * custom - another hash
- *
- * If 'sha1' is selected as type, the salt must be provided to the salt
- * argument. This too base64 encoded.
- *
- * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files.  If
- * a custom type is used, salt is ignored and you must provide the host
- * pre-hashed when checking for it in the libssh2_knownhost_check() function.
- *
- * The keylen parameter may be omitted (zero) if the key is provided as a
- * NULL-terminated base64-encoded string.
- */
-
-/* host format (2 bits) */
-#define LIBSSH2_KNOWNHOST_TYPE_MASK    0xffff
-#define LIBSSH2_KNOWNHOST_TYPE_PLAIN   1
-#define LIBSSH2_KNOWNHOST_TYPE_SHA1    2 /* always base64 encoded */
-#define LIBSSH2_KNOWNHOST_TYPE_CUSTOM  3
-
-/* key format (2 bits) */
-#define LIBSSH2_KNOWNHOST_KEYENC_MASK     (3<<16)
-#define LIBSSH2_KNOWNHOST_KEYENC_RAW      (1<<16)
-#define LIBSSH2_KNOWNHOST_KEYENC_BASE64   (2<<16)
-
-/* type of key (2 bits) */
-#define LIBSSH2_KNOWNHOST_KEY_MASK     (3<<18)
-#define LIBSSH2_KNOWNHOST_KEY_SHIFT    18
-#define LIBSSH2_KNOWNHOST_KEY_RSA1     (1<<18)
-#define LIBSSH2_KNOWNHOST_KEY_SSHRSA   (2<<18)
-#define LIBSSH2_KNOWNHOST_KEY_SSHDSS   (3<<18)
-
-LIBSSH2_API int
-libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
-                      const char *host,
-                      const char *salt,
-                      const char *key, size_t keylen, int typemask,
-                      struct libssh2_knownhost **store);
-
-/*
- * libssh2_knownhost_addc
- *
- * Add a host and its associated key to the collection of known hosts.
- *
- * Takes a comment argument that may be NULL.  A NULL comment indicates
- * there is no comment and the entry will end directly after the key
- * when written out to a file.  An empty string "" comment will indicate an
- * empty comment which will cause a single space to be written after the key.
- *
- * The 'type' argument specifies on what format the given host and keys are:
- *
- * plain  - ascii "hostname.domain.tld"
- * sha1   - SHA1(<salt> <host>) base64-encoded!
- * custom - another hash
- *
- * If 'sha1' is selected as type, the salt must be provided to the salt
- * argument. This too base64 encoded.
- *
- * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files.  If
- * a custom type is used, salt is ignored and you must provide the host
- * pre-hashed when checking for it in the libssh2_knownhost_check() function.
- *
- * The keylen parameter may be omitted (zero) if the key is provided as a
- * NULL-terminated base64-encoded string.
- */
-
-LIBSSH2_API int
-libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts,
-                       const char *host,
-                       const char *salt,
-                       const char *key, size_t keylen,
-                       const char *comment, size_t commentlen, int typemask,
-                       struct libssh2_knownhost **store);
-
-/*
- * libssh2_knownhost_check
- *
- * Check a host and its associated key against the collection of known hosts.
- *
- * The type is the type/format of the given host name.
- *
- * plain  - ascii "hostname.domain.tld"
- * custom - prehashed base64 encoded. Note that this cannot use any salts.
- *
- *
- * 'knownhost' may be set to NULL if you don't care about that info.
- *
- * Returns:
- *
- * LIBSSH2_KNOWNHOST_CHECK_* values, see below
- *
- */
-
-#define LIBSSH2_KNOWNHOST_CHECK_MATCH    0
-#define LIBSSH2_KNOWNHOST_CHECK_MISMATCH 1
-#define LIBSSH2_KNOWNHOST_CHECK_NOTFOUND 2
-#define LIBSSH2_KNOWNHOST_CHECK_FAILURE  3
-
-LIBSSH2_API int
-libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
-                        const char *host, const char *key, size_t keylen,
-                        int typemask,
-                        struct libssh2_knownhost **knownhost);
-
-/* this function is identital to the above one, but also takes a port
-   argument that allows libssh2 to do a better check */
-LIBSSH2_API int
-libssh2_knownhost_checkp(LIBSSH2_KNOWNHOSTS *hosts,
-                         const char *host, int port,
-                         const char *key, size_t keylen,
-                         int typemask,
-                         struct libssh2_knownhost **knownhost);
-
-/*
- * libssh2_knownhost_del
- *
- * Remove a host from the collection of known hosts. The 'entry' struct is
- * retrieved by a call to libssh2_knownhost_check().
- *
- */
-LIBSSH2_API int
-libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts,
-                      struct libssh2_knownhost *entry);
-
-/*
- * libssh2_knownhost_free
- *
- * Free an entire collection of known hosts.
- *
- */
-LIBSSH2_API void
-libssh2_knownhost_free(LIBSSH2_KNOWNHOSTS *hosts);
-
-/*
- * libssh2_knownhost_readline()
- *
- * Pass in a line of a file of 'type'. It makes libssh2 read this line.
- *
- * LIBSSH2_KNOWNHOST_FILE_OPENSSH is the only supported type.
- *
- */
-LIBSSH2_API int
-libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
-                           const char *line, size_t len, int type);
-
-/*
- * libssh2_knownhost_readfile
- *
- * Add hosts+key pairs from a given file.
- *
- * Returns a negative value for error or number of successfully added hosts.
- *
- * This implementation currently only knows one 'type' (openssh), all others
- * are reserved for future use.
- */
-
-#define LIBSSH2_KNOWNHOST_FILE_OPENSSH 1
-
-LIBSSH2_API int
-libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
-                           const char *filename, int type);
-
-/*
- * libssh2_knownhost_writeline()
- *
- * Ask libssh2 to convert a known host to an output line for storage.
- *
- * Note that this function returns LIBSSH2_ERROR_BUFFER_TOO_SMALL if the given
- * output buffer is too small to hold the desired output.
- *
- * This implementation currently only knows one 'type' (openssh), all others
- * are reserved for future use.
- *
- */
-LIBSSH2_API int
-libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
-                            struct libssh2_knownhost *known,
-                            char *buffer, size_t buflen,
-                            size_t *outlen, /* the amount of written data */
-                            int type);
-
-/*
- * libssh2_knownhost_writefile
- *
- * Write hosts+key pairs to a given file.
- *
- * This implementation currently only knows one 'type' (openssh), all others
- * are reserved for future use.
- */
-
-LIBSSH2_API int
-libssh2_knownhost_writefile(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);
-
-#define HAVE_LIBSSH2_AGENT_API 0x010202 /* since 1.2.2 */
-
-struct libssh2_agent_publickey {
-    unsigned int magic;              /* magic stored by the library */
-    void *node;     /* handle to the internal representation of key */
-    unsigned char *blob;           /* public key blob */
-    size_t blob_len;               /* length of the public key blob */
-    char *comment;                 /* comment in printable format */
-};
-
-/*
- * libssh2_agent_init
- *
- * Init an ssh-agent handle. Returns the pointer to the handle.
- *
- */
-LIBSSH2_API LIBSSH2_AGENT *
-libssh2_agent_init(LIBSSH2_SESSION *session);
-
-/*
- * libssh2_agent_connect()
- *
- * Connect to an ssh-agent.
- *
- * Returns 0 if succeeded, or a negative value for error.
- */
-LIBSSH2_API int
-libssh2_agent_connect(LIBSSH2_AGENT *agent);
-
-/*
- * libssh2_agent_list_identities()
- *
- * Request an ssh-agent to list identities.
- *
- * Returns 0 if succeeded, or a negative value for error.
- */
-LIBSSH2_API int
-libssh2_agent_list_identities(LIBSSH2_AGENT *agent);
-
-/*
- * libssh2_agent_get_identity()
- *
- * Traverse the internal list of public keys. 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 public key was stored in 'store'
- * 1 if end of public keys
- * [negative] on errors
- */
-LIBSSH2_API int
-libssh2_agent_get_identity(LIBSSH2_AGENT *agent,
-               struct libssh2_agent_publickey **store,
-               struct libssh2_agent_publickey *prev);
-
-/*
- * libssh2_agent_userauth()
- *
- * Do publickey user authentication with the help of ssh-agent.
- *
- * Returns 0 if succeeded, or a negative value for error.
- */
-LIBSSH2_API int
-libssh2_agent_userauth(LIBSSH2_AGENT *agent,
-               const char *username,
-               struct libssh2_agent_publickey *identity);
-
-/*
- * libssh2_agent_disconnect()
- *
- * Close a connection to an ssh-agent.
- *
- * Returns 0 if succeeded, or a negative value for error.
- */
-LIBSSH2_API int
-libssh2_agent_disconnect(LIBSSH2_AGENT *agent);
-
-/*
- * libssh2_agent_free()
- *
- * Free an ssh-agent handle.  This function also frees the internal
- * collection of public keys.
- */
-LIBSSH2_API void
-libssh2_agent_free(LIBSSH2_AGENT *agent);
-
-
-/*
- * libssh2_keepalive_config()
- *
- * Set how often keepalive messages should be sent.  WANT_REPLY
- * indicates whether the keepalive messages should request a response
- * from the server.  INTERVAL is number of seconds that can pass
- * without any I/O, use 0 (the default) to disable keepalives.  To
- * avoid some busy-loop corner-cases, if you specify an interval of 1
- * it will be treated as 2.
- *
- * Note that non-blocking applications are responsible for sending the
- * keepalive messages using libssh2_keepalive_send().
- */
-LIBSSH2_API void libssh2_keepalive_config (LIBSSH2_SESSION *session,
-                                           int want_reply,
-                                           unsigned interval);
-
-/*
- * libssh2_keepalive_send()
- *
- * Send a keepalive message if needed.  SECONDS_TO_NEXT indicates how
- * many seconds you can sleep after this call before you need to call
- * it again.  Returns 0 on success, or LIBSSH2_ERROR_SOCKET_SEND on
- * I/O errors.
- */
-LIBSSH2_API int libssh2_keepalive_send (LIBSSH2_SESSION *session,
-                                        int *seconds_to_next);
-
-/* NOTE NOTE NOTE
-   libssh2_trace() has no function in builds that aren't built with debug
-   enabled
- */
-LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask);
-#define LIBSSH2_TRACE_TRANS (1<<1)
-#define LIBSSH2_TRACE_KEX   (1<<2)
-#define LIBSSH2_TRACE_AUTH  (1<<3)
-#define LIBSSH2_TRACE_CONN  (1<<4)
-#define LIBSSH2_TRACE_SCP   (1<<5)
-#define LIBSSH2_TRACE_SFTP  (1<<6)
-#define LIBSSH2_TRACE_ERROR (1<<7)
-#define LIBSSH2_TRACE_PUBLICKEY (1<<8)
-#define LIBSSH2_TRACE_SOCKET (1<<9)
-
-typedef void (*libssh2_trace_handler_func)(LIBSSH2_SESSION*,
-                                           void*,
-                                           const char *,
-                                           size_t);
-LIBSSH2_API int libssh2_trace_sethandler(LIBSSH2_SESSION *session,
-                                         void* context,
-                                         libssh2_trace_handler_func callback);
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* !RC_INVOKED */
-
-#endif /* LIBSSH2_H */
diff --git a/include/libssh2.h.in b/include/libssh2.h.in
new file mode 100644
index 0000000..5a06351
--- /dev/null
+++ b/include/libssh2.h.in
@@ -0,0 +1,1200 @@
+/* Copyright (c) 2004-2009, Sara Golemon <sarag@libssh2.org>
+ * Copyright (c) 2009-2012 Daniel Stenberg
+ * Copyright (c) 2010 Simon Josefsson <simon@josefsson.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ *   Redistributions of source code must retain the above
+ *   copyright notice, this list of conditions and the
+ *   following disclaimer.
+ *
+ *   Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the following
+ *   disclaimer in the documentation and/or other materials
+ *   provided with the distribution.
+ *
+ *   Neither the name of the copyright holder nor the names
+ *   of any other contributors may be used to endorse or
+ *   promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ */
+
+#ifndef LIBSSH2_H
+#define LIBSSH2_H 1
+
+#define LIBSSH2_COPYRIGHT "2004-2012 The libssh2 project and its contributors."
+
+#cmakedefine LIBSSH2_VERSION "@LIBSSH2_VERSION@"
+
+/* The numeric version number is also available "in parts" by using these
+   defines: */
+#cmakedefine LIBSSH2_VERSION_MAJOR @LIBSSH2_VERSION_MAJOR@
+#cmakedefine LIBSSH2_VERSION_MINOR @LIBSSH2_VERSION_MINOR@
+#cmakedefine LIBSSH2_VERSION_PATCH @LIBSSH2_VERSION_PATCH@
+
+/* This is the numeric version of the libssh2 version number, meant for easier
+   parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
+   always follow this syntax:
+
+         0xXXYYZZ
+
+   Where XX, YY and ZZ are the main version, release and patch numbers in
+   hexadecimal (using 8 bits each). All three numbers are always represented
+   using two digits.  1.2 would appear as "0x010200" while version 9.11.7
+   appears as "0x090b07".
+
+   This 6-digit (24 bits) hexadecimal number does not show pre-release number,
+   and it is always a greater number in a more recent release. It makes
+   comparisons with greater than and less than work.
+*/
+#cmakedefine LIBSSH2_VERSION_NUM @LIBSSH2_VERSION_NUM@
+
+/*
+ * This is the date and time when the full source package was created. The
+ * timestamp is not stored in the source code repo, as the timestamp is
+ * properly set in the tarballs by the maketgz script.
+ *
+ * The format of the date should follow this template:
+ *
+ * "Mon Feb 12 11:35:33 UTC 2007"
+ */
+#define LIBSSH2_TIMESTAMP "DEV"
+
+#ifndef RC_INVOKED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef _WIN32
+# include <basetsd.h>
+# include <winsock2.h>
+#endif
+
+#include <stddef.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+/* Allow alternate API prefix from CFLAGS or calling app */
+#ifndef LIBSSH2_API
+# ifdef LIBSSH2_WIN32
+#  ifdef _WINDLL
+#   ifdef LIBSSH2_LIBRARY
+#    define LIBSSH2_API __declspec(dllexport)
+#   else
+#    define LIBSSH2_API __declspec(dllimport)
+#   endif /* LIBSSH2_LIBRARY */
+#  else
+#   define LIBSSH2_API
+#  endif
+# else /* !LIBSSH2_WIN32 */
+#  define LIBSSH2_API
+# endif /* LIBSSH2_WIN32 */
+#endif /* LIBSSH2_API */
+
+#ifdef HAVE_SYS_UIO_H
+# include <sys/uio.h>
+#endif
+
+#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
+# include <sys/bsdskt.h>
+typedef unsigned char uint8_t;
+typedef unsigned int uint32_t;
+#endif
+
+#ifdef _MSC_VER
+typedef unsigned char uint8_t;
+typedef unsigned int uint32_t;
+typedef unsigned __int64 libssh2_uint64_t;
+typedef __int64 libssh2_int64_t;
+#ifndef ssize_t
+typedef SSIZE_T ssize_t;
+#endif
+#else
+typedef unsigned long long libssh2_uint64_t;
+typedef long long libssh2_int64_t;
+#endif
+
+#ifdef WIN32
+typedef SOCKET libssh2_socket_t;
+#define LIBSSH2_INVALID_SOCKET INVALID_SOCKET
+#else /* !WIN32 */
+typedef int libssh2_socket_t;
+#define LIBSSH2_INVALID_SOCKET -1
+#endif /* WIN32 */
+
+/* Part of every banner, user specified or not */
+#define LIBSSH2_SSH_BANNER                  "SSH-2.0-libssh2_" LIBSSH2_VERSION
+
+/* We *could* add a comment here if we so chose */
+#define LIBSSH2_SSH_DEFAULT_BANNER                  LIBSSH2_SSH_BANNER
+#define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF        LIBSSH2_SSH_DEFAULT_BANNER "\r\n"
+
+/* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1 */
+#define LIBSSH2_DH_GEX_MINGROUP     1024
+#define LIBSSH2_DH_GEX_OPTGROUP     1536
+#define LIBSSH2_DH_GEX_MAXGROUP     2048
+
+/* Defaults for pty requests */
+#define LIBSSH2_TERM_WIDTH      80
+#define LIBSSH2_TERM_HEIGHT     24
+#define LIBSSH2_TERM_WIDTH_PX   0
+#define LIBSSH2_TERM_HEIGHT_PX  0
+
+/* 1/4 second */
+#define LIBSSH2_SOCKET_POLL_UDELAY      250000
+/* 0.25 * 120 == 30 seconds */
+#define LIBSSH2_SOCKET_POLL_MAXLOOPS    120
+
+/* Maximum size to allow a payload to compress to, plays it safe by falling
+   short of spec limits */
+#define LIBSSH2_PACKET_MAXCOMP      32000
+
+/* Maximum size to allow a payload to deccompress to, plays it safe by
+   allowing more than spec requires */
+#define LIBSSH2_PACKET_MAXDECOMP    40000
+
+/* Maximum size for an inbound compressed payload, plays it safe by
+   overshooting spec limits */
+#define LIBSSH2_PACKET_MAXPAYLOAD   40000
+
+/* Malloc callbacks */
+#define LIBSSH2_ALLOC_FUNC(name)   void *name(size_t count, void **abstract)
+#define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, \
+                                              void **abstract)
+#define LIBSSH2_FREE_FUNC(name)    void name(void *ptr, void **abstract)
+
+typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT
+{
+    char* text;
+    unsigned int length;
+    unsigned char echo;
+} LIBSSH2_USERAUTH_KBDINT_PROMPT;
+
+typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE
+{
+    char* text;
+    unsigned int length;
+} LIBSSH2_USERAUTH_KBDINT_RESPONSE;
+
+/* 'publickey' authentication callback */
+#define LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC(name) \
+  int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \
+           const unsigned char *data, size_t data_len, void **abstract)
+
+/* 'keyboard-interactive' authentication callback */
+#define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) \
+ void name_(const char* name, int name_len, const char* instruction, \
+            int instruction_len, int num_prompts, \
+            const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, \
+            LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract)
+
+/* Callbacks for special SSH packets */
+#define LIBSSH2_IGNORE_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, const char *message, int message_len, \
+           void **abstract)
+
+#define LIBSSH2_DEBUG_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, int always_display, const char *message, \
+           int message_len, const char *language, int language_len, \
+           void **abstract)
+
+#define LIBSSH2_DISCONNECT_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, int reason, const char *message, \
+           int message_len, const char *language, int language_len, \
+           void **abstract)
+
+#define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, \
+           void **abstract)
+
+#define LIBSSH2_MACERROR_FUNC(name) \
+ int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, \
+          void **abstract)
+
+#define LIBSSH2_X11_OPEN_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \
+           const char *shost, int sport, void **abstract)
+
+#define LIBSSH2_CHANNEL_CLOSE_FUNC(name) \
+  void name(LIBSSH2_SESSION *session, void **session_abstract, \
+            LIBSSH2_CHANNEL *channel, void **channel_abstract)
+
+/* I/O callbacks */
+#define LIBSSH2_RECV_FUNC(name)  ssize_t name(libssh2_socket_t socket, \
+                                              void *buffer, size_t length, \
+                                              int flags, void **abstract)
+#define LIBSSH2_SEND_FUNC(name)  ssize_t name(libssh2_socket_t socket, \
+                                              const void *buffer, size_t length,\
+                                              int flags, void **abstract)
+
+/* libssh2_session_callback_set() constants */
+#define LIBSSH2_CALLBACK_IGNORE             0
+#define LIBSSH2_CALLBACK_DEBUG              1
+#define LIBSSH2_CALLBACK_DISCONNECT         2
+#define LIBSSH2_CALLBACK_MACERROR           3
+#define LIBSSH2_CALLBACK_X11                4
+#define LIBSSH2_CALLBACK_SEND               5
+#define LIBSSH2_CALLBACK_RECV               6
+
+/* libssh2_session_method_pref() constants */
+#define LIBSSH2_METHOD_KEX          0
+#define LIBSSH2_METHOD_HOSTKEY      1
+#define LIBSSH2_METHOD_CRYPT_CS     2
+#define LIBSSH2_METHOD_CRYPT_SC     3
+#define LIBSSH2_METHOD_MAC_CS       4
+#define LIBSSH2_METHOD_MAC_SC       5
+#define LIBSSH2_METHOD_COMP_CS      6
+#define LIBSSH2_METHOD_COMP_SC      7
+#define LIBSSH2_METHOD_LANG_CS      8
+#define LIBSSH2_METHOD_LANG_SC      9
+
+/* flags */
+#define LIBSSH2_FLAG_SIGPIPE        1
+#define LIBSSH2_FLAG_COMPRESS       2
+
+typedef struct _LIBSSH2_SESSION                     LIBSSH2_SESSION;
+typedef struct _LIBSSH2_CHANNEL                     LIBSSH2_CHANNEL;
+typedef struct _LIBSSH2_LISTENER                    LIBSSH2_LISTENER;
+typedef struct _LIBSSH2_KNOWNHOSTS                  LIBSSH2_KNOWNHOSTS;
+typedef struct _LIBSSH2_AGENT                       LIBSSH2_AGENT;
+
+typedef struct _LIBSSH2_POLLFD {
+    unsigned char type; /* LIBSSH2_POLLFD_* below */
+
+    union {
+        libssh2_socket_t socket; /* File descriptors -- examined with
+                                    system select() call */
+        LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */
+        LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound
+                                       connections waiting to be accepted? */
+    } fd;
+
+    unsigned long events; /* Requested Events */
+    unsigned long revents; /* Returned Events */
+} LIBSSH2_POLLFD;
+
+/* Poll FD Descriptor Types */
+#define LIBSSH2_POLLFD_SOCKET       1
+#define LIBSSH2_POLLFD_CHANNEL      2
+#define LIBSSH2_POLLFD_LISTENER     3
+
+/* Note: Win32 Doesn't actually have a poll() implementation, so some of these
+   values are faked with select() data */
+/* Poll FD events/revents -- Match sys/poll.h where possible */
+#define LIBSSH2_POLLFD_POLLIN           0x0001 /* Data available to be read or
+                                                  connection available --
+                                                  All */
+#define LIBSSH2_POLLFD_POLLPRI          0x0002 /* Priority data available to
+                                                  be read -- Socket only */
+#define LIBSSH2_POLLFD_POLLEXT          0x0002 /* Extended data available to
+                                                  be read -- Channel only */
+#define LIBSSH2_POLLFD_POLLOUT          0x0004 /* Can may be written --
+                                                  Socket/Channel */
+/* revents only */
+#define LIBSSH2_POLLFD_POLLERR          0x0008 /* Error Condition -- Socket */
+#define LIBSSH2_POLLFD_POLLHUP          0x0010 /* HangUp/EOF -- Socket */
+#define LIBSSH2_POLLFD_SESSION_CLOSED   0x0010 /* Session Disconnect */
+#define LIBSSH2_POLLFD_POLLNVAL         0x0020 /* Invalid request -- Socket
+                                                  Only */
+#define LIBSSH2_POLLFD_POLLEX           0x0040 /* Exception Condition --
+                                                  Socket/Win32 */
+#define LIBSSH2_POLLFD_CHANNEL_CLOSED   0x0080 /* Channel Disconnect */
+#define LIBSSH2_POLLFD_LISTENER_CLOSED  0x0080 /* Listener Disconnect */
+
+#define HAVE_LIBSSH2_SESSION_BLOCK_DIRECTION
+/* Block Direction Types */
+#define LIBSSH2_SESSION_BLOCK_INBOUND                  0x0001
+#define LIBSSH2_SESSION_BLOCK_OUTBOUND                 0x0002
+
+/* Hash Types */
+#define LIBSSH2_HOSTKEY_HASH_MD5                            1
+#define LIBSSH2_HOSTKEY_HASH_SHA1                           2
+
+/* Hostkey Types */
+#define LIBSSH2_HOSTKEY_TYPE_UNKNOWN			    0
+#define LIBSSH2_HOSTKEY_TYPE_RSA			    1
+#define LIBSSH2_HOSTKEY_TYPE_DSS			    2
+
+/* Disconnect Codes (defined by SSH protocol) */
+#define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT          1
+#define SSH_DISCONNECT_PROTOCOL_ERROR                       2
+#define SSH_DISCONNECT_KEY_EXCHANGE_FAILED                  3
+#define SSH_DISCONNECT_RESERVED                             4
+#define SSH_DISCONNECT_MAC_ERROR                            5
+#define SSH_DISCONNECT_COMPRESSION_ERROR                    6
+#define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE                7
+#define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED       8
+#define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE              9
+#define SSH_DISCONNECT_CONNECTION_LOST                      10
+#define SSH_DISCONNECT_BY_APPLICATION                       11
+#define SSH_DISCONNECT_TOO_MANY_CONNECTIONS                 12
+#define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER               13
+#define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE       14
+#define SSH_DISCONNECT_ILLEGAL_USER_NAME                    15
+
+/* Error Codes (defined by libssh2) */
+#define LIBSSH2_ERROR_NONE                      0
+
+/* The library once used -1 as a generic error return value on numerous places
+   through the code, which subsequently was converted to
+   LIBSSH2_ERROR_SOCKET_NONE uses over time. As this is a generic error code,
+   the goal is to never ever return this code but instead make sure that a
+   more accurate and descriptive error code is used. */
+#define LIBSSH2_ERROR_SOCKET_NONE               -1
+
+#define LIBSSH2_ERROR_BANNER_RECV               -2
+#define LIBSSH2_ERROR_BANNER_SEND               -3
+#define LIBSSH2_ERROR_INVALID_MAC               -4
+#define LIBSSH2_ERROR_KEX_FAILURE               -5
+#define LIBSSH2_ERROR_ALLOC                     -6
+#define LIBSSH2_ERROR_SOCKET_SEND               -7
+#define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE      -8
+#define LIBSSH2_ERROR_TIMEOUT                   -9
+#define LIBSSH2_ERROR_HOSTKEY_INIT              -10
+#define LIBSSH2_ERROR_HOSTKEY_SIGN              -11
+#define LIBSSH2_ERROR_DECRYPT                   -12
+#define LIBSSH2_ERROR_SOCKET_DISCONNECT         -13
+#define LIBSSH2_ERROR_PROTO                     -14
+#define LIBSSH2_ERROR_PASSWORD_EXPIRED          -15
+#define LIBSSH2_ERROR_FILE                      -16
+#define LIBSSH2_ERROR_METHOD_NONE               -17
+#define LIBSSH2_ERROR_AUTHENTICATION_FAILED     -18
+#define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED    LIBSSH2_ERROR_AUTHENTICATION_FAILED
+#define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED      -19
+#define LIBSSH2_ERROR_CHANNEL_OUTOFORDER        -20
+#define LIBSSH2_ERROR_CHANNEL_FAILURE           -21
+#define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED    -22
+#define LIBSSH2_ERROR_CHANNEL_UNKNOWN           -23
+#define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED   -24
+#define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED   -25
+#define LIBSSH2_ERROR_CHANNEL_CLOSED            -26
+#define LIBSSH2_ERROR_CHANNEL_EOF_SENT          -27
+#define LIBSSH2_ERROR_SCP_PROTOCOL              -28
+#define LIBSSH2_ERROR_ZLIB                      -29
+#define LIBSSH2_ERROR_SOCKET_TIMEOUT            -30
+#define LIBSSH2_ERROR_SFTP_PROTOCOL             -31
+#define LIBSSH2_ERROR_REQUEST_DENIED            -32
+#define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED      -33
+#define LIBSSH2_ERROR_INVAL                     -34
+#define LIBSSH2_ERROR_INVALID_POLL_TYPE         -35
+#define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL        -36
+#define LIBSSH2_ERROR_EAGAIN                    -37
+#define LIBSSH2_ERROR_BUFFER_TOO_SMALL          -38
+#define LIBSSH2_ERROR_BAD_USE                   -39
+#define LIBSSH2_ERROR_COMPRESS                  -40
+#define LIBSSH2_ERROR_OUT_OF_BOUNDARY           -41
+#define LIBSSH2_ERROR_AGENT_PROTOCOL            -42
+#define LIBSSH2_ERROR_SOCKET_RECV               -43
+#define LIBSSH2_ERROR_ENCRYPT                   -44
+#define LIBSSH2_ERROR_BAD_SOCKET                -45
+#define LIBSSH2_ERROR_KNOWN_HOSTS               -46
+
+/* this is a define to provide the old (<= 1.2.7) name */
+#define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV
+
+/* Global API */
+#define LIBSSH2_INIT_NO_CRYPTO        0x0001
+
+/*
+ * libssh2_init()
+ *
+ * Initialize the libssh2 functions.  This typically initialize the
+ * crypto library.  It uses a global state, and is not thread safe --
+ * you must make sure this function is not called concurrently.
+ *
+ * Flags can be:
+ * 0:                              Normal initialize
+ * LIBSSH2_INIT_NO_CRYPTO:         Do not initialize the crypto library (ie.
+ *                                 OPENSSL_add_cipher_algoritms() for OpenSSL
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int libssh2_init(int flags);
+
+/*
+ * libssh2_exit()
+ *
+ * Exit the libssh2 functions and free's all memory used internal.
+ */
+LIBSSH2_API void libssh2_exit(void);
+
+/*
+ * libssh2_free()
+ *
+ * Deallocate memory allocated by earlier call to libssh2 functions.
+ */
+LIBSSH2_API void libssh2_free(LIBSSH2_SESSION *session, void *ptr);
+
+/*
+ * libssh2_session_supported_algs()
+ *
+ * Fills algs with a list of supported acryptographic algorithms. Returns a
+ * non-negative number (number of supported algorithms) on success or a
+ * negative number (an eror code) on failure.
+ *
+ * NOTE: on success, algs must be deallocated (by calling libssh2_free) when
+ * not needed anymore
+ */
+LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
+                                               int method_type,
+                                               const char*** algs);
+
+/* Session API */
+LIBSSH2_API LIBSSH2_SESSION *
+libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
+                        LIBSSH2_FREE_FUNC((*my_free)),
+                        LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract);
+#define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL)
+
+LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session);
+
+LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session,
+                                               int cbtype, void *callback);
+LIBSSH2_API int libssh2_session_banner_set(LIBSSH2_SESSION *session,
+                                           const char *banner);
+LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session,
+                                   const char *banner);
+
+LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int sock);
+LIBSSH2_API int libssh2_session_handshake(LIBSSH2_SESSION *session,
+                                          libssh2_socket_t sock);
+LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session,
+                                              int reason,
+                                              const char *description,
+                                              const char *lang);
+#define libssh2_session_disconnect(session, description) \
+  libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, \
+                                (description), "")
+
+LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session);
+
+LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session,
+                                             int hash_type);
+
+LIBSSH2_API const char *libssh2_session_hostkey(LIBSSH2_SESSION *session,
+                                                size_t *len, int *type);
+
+LIBSSH2_API int libssh2_session_method_pref(LIBSSH2_SESSION *session,
+                                            int method_type,
+                                            const char *prefs);
+LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session,
+                                                int method_type);
+LIBSSH2_API int libssh2_session_last_error(LIBSSH2_SESSION *session,
+                                           char **errmsg,
+                                           int *errmsg_len, int want_buf);
+LIBSSH2_API int libssh2_session_last_errno(LIBSSH2_SESSION *session);
+LIBSSH2_API int libssh2_session_block_directions(LIBSSH2_SESSION *session);
+
+LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag,
+                                     int value);
+LIBSSH2_API const char *libssh2_session_banner_get(LIBSSH2_SESSION *session);
+
+/* Userauth API */
+LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session,
+                                        const char *username,
+                                        unsigned int username_len);
+LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);
+
+LIBSSH2_API int libssh2_userauth_password_ex(LIBSSH2_SESSION *session,
+                                             const char *username,
+                                             unsigned int username_len,
+                                             const char *password,
+                                             unsigned int password_len,
+                                             LIBSSH2_PASSWD_CHANGEREQ_FUNC((*passwd_change_cb)));
+
+#define libssh2_userauth_password(session, username, password) \
+ libssh2_userauth_password_ex((session), (username),           \
+                              (unsigned int)strlen(username),  \
+                              (password), (unsigned int)strlen(password), NULL)
+
+LIBSSH2_API int
+libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
+                                       const char *username,
+                                       unsigned int username_len,
+                                       const char *publickey,
+                                       const char *privatekey,
+                                       const char *passphrase);
+
+#define libssh2_userauth_publickey_fromfile(session, username, publickey, \
+                                            privatekey, passphrase)     \
+    libssh2_userauth_publickey_fromfile_ex((session), (username),       \
+                                           (unsigned int)strlen(username), \
+                                           (publickey),                 \
+                                           (privatekey), (passphrase))
+
+LIBSSH2_API int
+libssh2_userauth_publickey(LIBSSH2_SESSION *session,
+                           const char *username,
+                           const unsigned char *pubkeydata,
+                           size_t pubkeydata_len,
+                           LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC((*sign_callback)),
+                           void **abstract);
+
+LIBSSH2_API int
+libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session,
+                                       const char *username,
+                                       unsigned int username_len,
+                                       const char *publickey,
+                                       const char *privatekey,
+                                       const char *passphrase,
+                                       const char *hostname,
+                                       unsigned int hostname_len,
+                                       const char *local_username,
+                                       unsigned int local_username_len);
+
+#define libssh2_userauth_hostbased_fromfile(session, username, publickey, \
+                                            privatekey, passphrase, hostname) \
+ libssh2_userauth_hostbased_fromfile_ex((session), (username), \
+                                        (unsigned int)strlen(username), \
+                                        (publickey),                    \
+                                        (privatekey), (passphrase),     \
+                                        (hostname),                     \
+                                        (unsigned int)strlen(hostname), \
+                                        (username),                     \
+                                        (unsigned int)strlen(username))
+
+/*
+ * response_callback is provided with filled by library prompts array,
+ * but client must allocate and fill individual responses. Responses
+ * array is already allocated. Responses data will be freed by libssh2
+ * after callback return, but before subsequent callback invokation.
+ */
+LIBSSH2_API int
+libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session,
+                                         const char *username,
+                                         unsigned int username_len,
+                                         LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC((*response_callback)));
+
+#define libssh2_userauth_keyboard_interactive(session, username,        \
+                                              response_callback)        \
+    libssh2_userauth_keyboard_interactive_ex((session), (username),     \
+                                             (unsigned int)strlen(username), \
+                                             (response_callback))
+
+LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds,
+                             long timeout);
+
+/* Channel API */
+#define LIBSSH2_CHANNEL_WINDOW_DEFAULT  (2*1024*1024)
+#define LIBSSH2_CHANNEL_PACKET_DEFAULT  32768
+#define LIBSSH2_CHANNEL_MINADJUST       1024
+
+/* Extended Data Handling */
+#define LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL        0
+#define LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE        1
+#define LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE         2
+
+#define SSH_EXTENDED_DATA_STDERR 1
+
+/* Returned by any function that would block during a read/write opperation */
+#define LIBSSH2CHANNEL_EAGAIN LIBSSH2_ERROR_EAGAIN
+
+LIBSSH2_API LIBSSH2_CHANNEL *
+libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type,
+                        unsigned int channel_type_len,
+                        unsigned int window_size, unsigned int packet_size,
+                        const char *message, unsigned int message_len);
+
+#define libssh2_channel_open_session(session) \
+  libssh2_channel_open_ex((session), "session", sizeof("session") - 1, \
+                          LIBSSH2_CHANNEL_WINDOW_DEFAULT, \
+                          LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0)
+
+LIBSSH2_API LIBSSH2_CHANNEL *
+libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host,
+                                int port, const char *shost, int sport);
+#define libssh2_channel_direct_tcpip(session, host, port) \
+  libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22)
+
+LIBSSH2_API LIBSSH2_LISTENER *
+libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host,
+                                  int port, int *bound_port, int queue_maxsize);
+#define libssh2_channel_forward_listen(session, port) \
+ libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16)
+
+LIBSSH2_API int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
+
+LIBSSH2_API LIBSSH2_CHANNEL *
+libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener);
+
+LIBSSH2_API int libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel,
+                                          const char *varname,
+                                          unsigned int varname_len,
+                                          const char *value,
+                                          unsigned int value_len);
+
+#define libssh2_channel_setenv(channel, varname, value)                 \
+    libssh2_channel_setenv_ex((channel), (varname),                     \
+                              (unsigned int)strlen(varname), (value),   \
+                              (unsigned int)strlen(value))
+
+LIBSSH2_API int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel,
+                                               const char *term,
+                                               unsigned int term_len,
+                                               const char *modes,
+                                               unsigned int modes_len,
+                                               int width, int height,
+                                               int width_px, int height_px);
+#define libssh2_channel_request_pty(channel, term)                      \
+    libssh2_channel_request_pty_ex((channel), (term),                   \
+                                   (unsigned int)strlen(term),          \
+                                   NULL, 0,                             \
+                                   LIBSSH2_TERM_WIDTH, LIBSSH2_TERM_HEIGHT, \
+                                   LIBSSH2_TERM_WIDTH_PX, LIBSSH2_TERM_HEIGHT_PX)
+
+LIBSSH2_API int libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL *channel,
+                                                    int width, int height,
+                                                    int width_px,
+                                                    int height_px);
+#define libssh2_channel_request_pty_size(channel, width, height) \
+  libssh2_channel_request_pty_size_ex( (channel), (width), (height), 0, 0)
+
+LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel,
+                                           int single_connection,
+                                           const char *auth_proto,
+                                           const char *auth_cookie,
+                                           int screen_number);
+#define libssh2_channel_x11_req(channel, screen_number) \
+ libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number))
+
+LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
+                                                const char *request,
+                                                unsigned int request_len,
+                                                const char *message,
+                                                unsigned int message_len);
+#define libssh2_channel_shell(channel) \
+  libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, \
+                                  NULL, 0)
+#define libssh2_channel_exec(channel, command) \
+  libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, \
+                                  (command), (unsigned int)strlen(command))
+#define libssh2_channel_subsystem(channel, subsystem) \
+  libssh2_channel_process_startup((channel), "subsystem",              \
+                                  sizeof("subsystem") - 1, (subsystem), \
+                                  (unsigned int)strlen(subsystem))
+
+LIBSSH2_API ssize_t libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel,
+                                            int stream_id, char *buf,
+                                            size_t buflen);
+#define libssh2_channel_read(channel, buf, buflen) \
+  libssh2_channel_read_ex((channel), 0, (buf), (buflen))
+#define libssh2_channel_read_stderr(channel, buf, buflen) \
+  libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
+
+LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel,
+                                          int extended);
+
+LIBSSH2_API unsigned long
+libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
+                               unsigned long *read_avail,
+                               unsigned long *window_size_initial);
+#define libssh2_channel_window_read(channel) \
+  libssh2_channel_window_read_ex((channel), NULL, NULL)
+
+/* libssh2_channel_receive_window_adjust is DEPRECATED, do not use! */
+LIBSSH2_API unsigned long
+libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
+                                      unsigned long adjustment,
+                                      unsigned char force);
+
+LIBSSH2_API int
+libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel,
+                                       unsigned long adjustment,
+                                       unsigned char force,
+                                       unsigned int *storewindow);
+
+LIBSSH2_API ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
+                                             int stream_id, const char *buf,
+                                             size_t buflen);
+
+#define libssh2_channel_write(channel, buf, buflen) \
+  libssh2_channel_write_ex((channel), 0, (buf), (buflen))
+#define libssh2_channel_write_stderr(channel, buf, buflen)  \
+  libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
+
+LIBSSH2_API unsigned long
+libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel,
+                                unsigned long *window_size_initial);
+#define libssh2_channel_window_write(channel) \
+  libssh2_channel_window_write_ex((channel), NULL)
+
+LIBSSH2_API void libssh2_session_set_blocking(LIBSSH2_SESSION* session,
+                                              int blocking);
+LIBSSH2_API int libssh2_session_get_blocking(LIBSSH2_SESSION* session);
+
+LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel,
+                                              int blocking);
+
+LIBSSH2_API void libssh2_session_set_timeout(LIBSSH2_SESSION* session,
+                                             long timeout);
+LIBSSH2_API long libssh2_session_get_timeout(LIBSSH2_SESSION* session);
+
+/* libssh2_channel_handle_extended_data is DEPRECATED, do not use! */
+LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel,
+                                                      int ignore_mode);
+LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel,
+                                                      int ignore_mode);
+
+/* libssh2_channel_ignore_extended_data() is defined below for BC with version
+ * 0.1
+ *
+ * Future uses should use libssh2_channel_handle_extended_data() directly if
+ * LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read
+ * (FIFO) from the standard data channel
+ */
+/* DEPRECATED */
+#define libssh2_channel_ignore_extended_data(channel, ignore) \
+  libssh2_channel_handle_extended_data((channel),                       \
+                                       (ignore) ?                       \
+                                       LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : \
+                                       LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL )
+
+#define LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA     -1
+#define LIBSSH2_CHANNEL_FLUSH_ALL               -2
+LIBSSH2_API int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel,
+                                         int streamid);
+#define libssh2_channel_flush(channel) libssh2_channel_flush_ex((channel), 0)
+#define libssh2_channel_flush_stderr(channel) \
+ libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR)
+
+LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel);
+LIBSSH2_API int libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL* channel,
+                                                char **exitsignal,
+                                                size_t *exitsignal_len,
+                                                char **errmsg,
+                                                size_t *errmsg_len,
+                                                char **langtag,
+                                                size_t *langtag_len);
+LIBSSH2_API int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_eof(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel);
+
+LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
+                                              const char *path,
+                                              struct stat *sb);
+LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session,
+                                                 const char *path, int mode,
+                                                 size_t size, long mtime,
+                                                 long atime);
+LIBSSH2_API LIBSSH2_CHANNEL *
+libssh2_scp_send64(LIBSSH2_SESSION *session, const char *path, int mode,
+                   libssh2_int64_t size, time_t mtime, time_t atime);
+
+#define libssh2_scp_send(session, path, mode, size) \
+  libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0)
+
+LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest,
+                                      unsigned int *dest_len,
+                                      const char *src, unsigned int src_len);
+
+LIBSSH2_API
+const char *libssh2_version(int req_version_num);
+
+#define HAVE_LIBSSH2_KNOWNHOST_API 0x010101 /* since 1.1.1 */
+#define HAVE_LIBSSH2_VERSION_API   0x010100 /* libssh2_version since 1.1 */
+
+struct libssh2_knownhost {
+    unsigned int magic;  /* magic stored by the library */
+    void *node; /* handle to the internal representation of this host */
+    char *name; /* this is NULL if no plain text host name exists */
+    char *key;  /* key in base64/printable format */
+    int typemask;
+};
+
+/*
+ * libssh2_knownhost_init
+ *
+ * Init a collection of known hosts. Returns the pointer to a collection.
+ *
+ */
+LIBSSH2_API LIBSSH2_KNOWNHOSTS *
+libssh2_knownhost_init(LIBSSH2_SESSION *session);
+
+/*
+ * libssh2_knownhost_add
+ *
+ * Add a host and its associated key to the collection of known hosts.
+ *
+ * The 'type' argument specifies on what format the given host and keys are:
+ *
+ * plain  - ascii "hostname.domain.tld"
+ * sha1   - SHA1(<salt> <host>) base64-encoded!
+ * custom - another hash
+ *
+ * If 'sha1' is selected as type, the salt must be provided to the salt
+ * argument. This too base64 encoded.
+ *
+ * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files.  If
+ * a custom type is used, salt is ignored and you must provide the host
+ * pre-hashed when checking for it in the libssh2_knownhost_check() function.
+ *
+ * The keylen parameter may be omitted (zero) if the key is provided as a
+ * NULL-terminated base64-encoded string.
+ */
+
+/* host format (2 bits) */
+#define LIBSSH2_KNOWNHOST_TYPE_MASK    0xffff
+#define LIBSSH2_KNOWNHOST_TYPE_PLAIN   1
+#define LIBSSH2_KNOWNHOST_TYPE_SHA1    2 /* always base64 encoded */
+#define LIBSSH2_KNOWNHOST_TYPE_CUSTOM  3
+
+/* key format (2 bits) */
+#define LIBSSH2_KNOWNHOST_KEYENC_MASK     (3<<16)
+#define LIBSSH2_KNOWNHOST_KEYENC_RAW      (1<<16)
+#define LIBSSH2_KNOWNHOST_KEYENC_BASE64   (2<<16)
+
+/* type of key (2 bits) */
+#define LIBSSH2_KNOWNHOST_KEY_MASK     (7<<18)
+#define LIBSSH2_KNOWNHOST_KEY_SHIFT    18
+#define LIBSSH2_KNOWNHOST_KEY_RSA1     (1<<18)
+#define LIBSSH2_KNOWNHOST_KEY_SSHRSA   (2<<18)
+#define LIBSSH2_KNOWNHOST_KEY_SSHDSS   (3<<18)
+#define LIBSSH2_KNOWNHOST_KEY_UNKNOWN  (7<<18)
+
+LIBSSH2_API int
+libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
+                      const char *host,
+                      const char *salt,
+                      const char *key, size_t keylen, int typemask,
+                      struct libssh2_knownhost **store);
+
+/*
+ * libssh2_knownhost_addc
+ *
+ * Add a host and its associated key to the collection of known hosts.
+ *
+ * Takes a comment argument that may be NULL.  A NULL comment indicates
+ * there is no comment and the entry will end directly after the key
+ * when written out to a file.  An empty string "" comment will indicate an
+ * empty comment which will cause a single space to be written after the key.
+ *
+ * The 'type' argument specifies on what format the given host and keys are:
+ *
+ * plain  - ascii "hostname.domain.tld"
+ * sha1   - SHA1(<salt> <host>) base64-encoded!
+ * custom - another hash
+ *
+ * If 'sha1' is selected as type, the salt must be provided to the salt
+ * argument. This too base64 encoded.
+ *
+ * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files.  If
+ * a custom type is used, salt is ignored and you must provide the host
+ * pre-hashed when checking for it in the libssh2_knownhost_check() function.
+ *
+ * The keylen parameter may be omitted (zero) if the key is provided as a
+ * NULL-terminated base64-encoded string.
+ */
+
+LIBSSH2_API int
+libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts,
+                       const char *host,
+                       const char *salt,
+                       const char *key, size_t keylen,
+                       const char *comment, size_t commentlen, int typemask,
+                       struct libssh2_knownhost **store);
+
+/*
+ * libssh2_knownhost_check
+ *
+ * Check a host and its associated key against the collection of known hosts.
+ *
+ * The type is the type/format of the given host name.
+ *
+ * plain  - ascii "hostname.domain.tld"
+ * custom - prehashed base64 encoded. Note that this cannot use any salts.
+ *
+ *
+ * 'knownhost' may be set to NULL if you don't care about that info.
+ *
+ * Returns:
+ *
+ * LIBSSH2_KNOWNHOST_CHECK_* values, see below
+ *
+ */
+
+#define LIBSSH2_KNOWNHOST_CHECK_MATCH    0
+#define LIBSSH2_KNOWNHOST_CHECK_MISMATCH 1
+#define LIBSSH2_KNOWNHOST_CHECK_NOTFOUND 2
+#define LIBSSH2_KNOWNHOST_CHECK_FAILURE  3
+
+LIBSSH2_API int
+libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
+                        const char *host, const char *key, size_t keylen,
+                        int typemask,
+                        struct libssh2_knownhost **knownhost);
+
+/* this function is identital to the above one, but also takes a port
+   argument that allows libssh2 to do a better check */
+LIBSSH2_API int
+libssh2_knownhost_checkp(LIBSSH2_KNOWNHOSTS *hosts,
+                         const char *host, int port,
+                         const char *key, size_t keylen,
+                         int typemask,
+                         struct libssh2_knownhost **knownhost);
+
+/*
+ * libssh2_knownhost_del
+ *
+ * Remove a host from the collection of known hosts. The 'entry' struct is
+ * retrieved by a call to libssh2_knownhost_check().
+ *
+ */
+LIBSSH2_API int
+libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts,
+                      struct libssh2_knownhost *entry);
+
+/*
+ * libssh2_knownhost_free
+ *
+ * Free an entire collection of known hosts.
+ *
+ */
+LIBSSH2_API void
+libssh2_knownhost_free(LIBSSH2_KNOWNHOSTS *hosts);
+
+/*
+ * libssh2_knownhost_readline()
+ *
+ * Pass in a line of a file of 'type'. It makes libssh2 read this line.
+ *
+ * LIBSSH2_KNOWNHOST_FILE_OPENSSH is the only supported type.
+ *
+ */
+LIBSSH2_API int
+libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
+                           const char *line, size_t len, int type);
+
+/*
+ * libssh2_knownhost_readfile
+ *
+ * Add hosts+key pairs from a given file.
+ *
+ * Returns a negative value for error or number of successfully added hosts.
+ *
+ * This implementation currently only knows one 'type' (openssh), all others
+ * are reserved for future use.
+ */
+
+#define LIBSSH2_KNOWNHOST_FILE_OPENSSH 1
+
+LIBSSH2_API int
+libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
+                           const char *filename, int type);
+
+/*
+ * libssh2_knownhost_writeline()
+ *
+ * Ask libssh2 to convert a known host to an output line for storage.
+ *
+ * Note that this function returns LIBSSH2_ERROR_BUFFER_TOO_SMALL if the given
+ * output buffer is too small to hold the desired output.
+ *
+ * This implementation currently only knows one 'type' (openssh), all others
+ * are reserved for future use.
+ *
+ */
+LIBSSH2_API int
+libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
+                            struct libssh2_knownhost *known,
+                            char *buffer, size_t buflen,
+                            size_t *outlen, /* the amount of written data */
+                            int type);
+
+/*
+ * libssh2_knownhost_writefile
+ *
+ * Write hosts+key pairs to a given file.
+ *
+ * This implementation currently only knows one 'type' (openssh), all others
+ * are reserved for future use.
+ */
+
+LIBSSH2_API int
+libssh2_knownhost_writefile(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);
+
+#define HAVE_LIBSSH2_AGENT_API 0x010202 /* since 1.2.2 */
+
+struct libssh2_agent_publickey {
+    unsigned int magic;              /* magic stored by the library */
+    void *node;     /* handle to the internal representation of key */
+    unsigned char *blob;           /* public key blob */
+    size_t blob_len;               /* length of the public key blob */
+    char *comment;                 /* comment in printable format */
+};
+
+/*
+ * libssh2_agent_init
+ *
+ * Init an ssh-agent handle. Returns the pointer to the handle.
+ *
+ */
+LIBSSH2_API LIBSSH2_AGENT *
+libssh2_agent_init(LIBSSH2_SESSION *session);
+
+/*
+ * libssh2_agent_connect()
+ *
+ * Connect to an ssh-agent.
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int
+libssh2_agent_connect(LIBSSH2_AGENT *agent);
+
+/*
+ * libssh2_agent_list_identities()
+ *
+ * Request an ssh-agent to list identities.
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int
+libssh2_agent_list_identities(LIBSSH2_AGENT *agent);
+
+/*
+ * libssh2_agent_get_identity()
+ *
+ * Traverse the internal list of public keys. 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 public key was stored in 'store'
+ * 1 if end of public keys
+ * [negative] on errors
+ */
+LIBSSH2_API int
+libssh2_agent_get_identity(LIBSSH2_AGENT *agent,
+               struct libssh2_agent_publickey **store,
+               struct libssh2_agent_publickey *prev);
+
+/*
+ * libssh2_agent_userauth()
+ *
+ * Do publickey user authentication with the help of ssh-agent.
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int
+libssh2_agent_userauth(LIBSSH2_AGENT *agent,
+               const char *username,
+               struct libssh2_agent_publickey *identity);
+
+/*
+ * libssh2_agent_disconnect()
+ *
+ * Close a connection to an ssh-agent.
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int
+libssh2_agent_disconnect(LIBSSH2_AGENT *agent);
+
+/*
+ * libssh2_agent_free()
+ *
+ * Free an ssh-agent handle.  This function also frees the internal
+ * collection of public keys.
+ */
+LIBSSH2_API void
+libssh2_agent_free(LIBSSH2_AGENT *agent);
+
+
+/*
+ * libssh2_keepalive_config()
+ *
+ * Set how often keepalive messages should be sent.  WANT_REPLY
+ * indicates whether the keepalive messages should request a response
+ * from the server.  INTERVAL is number of seconds that can pass
+ * without any I/O, use 0 (the default) to disable keepalives.  To
+ * avoid some busy-loop corner-cases, if you specify an interval of 1
+ * it will be treated as 2.
+ *
+ * Note that non-blocking applications are responsible for sending the
+ * keepalive messages using libssh2_keepalive_send().
+ */
+LIBSSH2_API void libssh2_keepalive_config (LIBSSH2_SESSION *session,
+                                           int want_reply,
+                                           unsigned interval);
+
+/*
+ * libssh2_keepalive_send()
+ *
+ * Send a keepalive message if needed.  SECONDS_TO_NEXT indicates how
+ * many seconds you can sleep after this call before you need to call
+ * it again.  Returns 0 on success, or LIBSSH2_ERROR_SOCKET_SEND on
+ * I/O errors.
+ */
+LIBSSH2_API int libssh2_keepalive_send (LIBSSH2_SESSION *session,
+                                        int *seconds_to_next);
+
+/* NOTE NOTE NOTE
+   libssh2_trace() has no function in builds that aren't built with debug
+   enabled
+ */
+LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask);
+#define LIBSSH2_TRACE_TRANS (1<<1)
+#define LIBSSH2_TRACE_KEX   (1<<2)
+#define LIBSSH2_TRACE_AUTH  (1<<3)
+#define LIBSSH2_TRACE_CONN  (1<<4)
+#define LIBSSH2_TRACE_SCP   (1<<5)
+#define LIBSSH2_TRACE_SFTP  (1<<6)
+#define LIBSSH2_TRACE_ERROR (1<<7)
+#define LIBSSH2_TRACE_PUBLICKEY (1<<8)
+#define LIBSSH2_TRACE_SOCKET (1<<9)
+
+typedef void (*libssh2_trace_handler_func)(LIBSSH2_SESSION*,
+                                           void*,
+                                           const char *,
+                                           size_t);
+LIBSSH2_API int libssh2_trace_sethandler(LIBSSH2_SESSION *session,
+                                         void* context,
+                                         libssh2_trace_handler_func callback);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* !RC_INVOKED */
+
+#endif /* LIBSSH2_H */
-- 
2.1.0


From b003306e7f12d9ffbc45998af9faf6d9cc3605e5 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Sun, 6 Jul 2014 21:10:50 +0100
Subject: [PATCH 14/47] Support packaging with CPack.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 CMakeLists.txt                      | 24 ++++++++++++++++++++----
 cmake/CopyRuntimeDependencies.cmake |  2 --
 src/CMakeLists.txt                  |  6 ++++--
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0011241..05d2a58 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,9 +37,6 @@ cmake_minimum_required(VERSION 2.8)
 
 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
 
-include(max_warnings)
-include(FeatureSummary)
-
 project(libssh2)
 
 option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
@@ -56,13 +53,32 @@ set(LIBSSH2_VERSION_NUM 0x010404)
 set(LIBSSH2_VERSION
   "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}_DEV")
 
+install(
+  FILES AUTHORS COPYING HACKING README RELEASE-NOTES NEWS
+  DESTINATION .)
+
 configure_file(include/libssh2.h.in ${CMAKE_CURRENT_BINARY_DIR}/libssh2.h)
 include_directories(include ${CMAKE_CURRENT_BINARY_DIR})
 
+install(FILES
+  ${CMAKE_CURRENT_BINARY_DIR}/libssh2.h
+  include/libssh2_publickey.h
+  include/libssh2_sftp.h
+  DESTINATION include)
+
 enable_testing()
 
+include(max_warnings)
+include(FeatureSummary)
+
 add_subdirectory(src)
 add_subdirectory(example)
 add_subdirectory(tests)
 
-feature_summary(WHAT ALL)
\ No newline at end of file
+feature_summary(WHAT ALL)
+
+set(CPACK_PACKAGE_VERSION_MAJOR ${LIBSSH2_VERSION_MAJOR})
+set(CPACK_PACKAGE_VERSION_MINOR ${LIBSSH2_VERSION_MINOR})
+set(CPACK_PACKAGE_VERSION_PATCH ${LIBSSH2_VERSION_PATCH})
+set(CPACK_PACKAGE_VERSION ${LIBSSH2_VERSION})
+include(CPack)
diff --git a/cmake/CopyRuntimeDependencies.cmake b/cmake/CopyRuntimeDependencies.cmake
index f851740..293f9b0 100644
--- a/cmake/CopyRuntimeDependencies.cmake
+++ b/cmake/CopyRuntimeDependencies.cmake
@@ -41,7 +41,5 @@ function(COPY_TO_TARGET_RUNTIME_DIRECTORY target)
       COMMAND ${CMAKE_COMMAND} -E copy ${dependency}
       ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
 
-    install(PROGRAMS ${dependency} DESTINATION bin)
-
   endforeach()
 endfunction()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e4f8cc5..b852092 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -322,8 +322,10 @@ set(SOURCES
 add_library(ssh2 ${SOURCES})
 target_link_libraries(ssh2 ${LIBRARIES})
 
-install(TARGETS ssh2 DESTINATION lib)
-install(FILES libssh2.h libssh2_publickey.h libssh2_sftp.h DESTINATION include)
+install(TARGETS ssh2
+  RUNTIME DESTINATION bin
+  LIBRARY DESTINATION lib
+  ARCHIVE DESTINATION lib)
 
 if(BUILD_SHARED_LIBS)
   list(APPEND _RUNTIME_DEPENDENCIES $<TARGET_FILE:ssh2>)
-- 
2.1.0


From 3b847ee0362ee55a1d931d974db6ad9c1c5e7b2a Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Sun, 6 Jul 2014 21:21:00 +0100
Subject: [PATCH 15/47] Test packaging using Travis CI.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 2b2fdd9..c271379 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -15,7 +15,7 @@ env:
    - CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON
    - CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
 
-script: mkdir bin && cd bin && cmake -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. && cmake --build . && cmake --build . --target test
+script: mkdir bin && cd bin && cmake -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. && cmake --build . && cmake --build . --target test && cmake --build . --target package
 
 before_install:
  - sudo apt-get install libgcrypt11-dev
\ No newline at end of file
-- 
2.1.0


From 1a065b8cfd35022c824ecbea9305eade8f049ca7 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Tue, 15 Jul 2014 09:51:04 +0200
Subject: [PATCH 16/47] Test cross-compiling 32-bit on 64-bit Travis CI.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 .travis.yml                    | 40 +++++++++++++++++++++++++++++-----------
 CMakeLists.txt                 |  2 +-
 cmake/Toolchain-Linux-32.cmake | 42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 12 deletions(-)
 create mode 100644 cmake/Toolchain-Linux-32.cmake

diff --git a/.travis.yml b/.travis.yml
index c271379..5f7d7df 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,16 +6,34 @@ compiler:
 
 env:
   matrix:
-   - CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF
-   - CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF
-   - CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON
-   - CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
-   - CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF
-   - CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF
-   - CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON
-   - CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
-
-script: mkdir bin && cd bin && cmake -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. && cmake --build . && cmake --build . --target test && cmake --build . --target package
+   - ADDRESS_SIZE=64 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF
+   - ADDRESS_SIZE=64 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF
+   - ADDRESS_SIZE=64 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON
+   - ADDRESS_SIZE=64 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
+   - ADDRESS_SIZE=64 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF
+   - ADDRESS_SIZE=64 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF
+   - ADDRESS_SIZE=64 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON
+   - ADDRESS_SIZE=64 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
+   - ADDRESS_SIZE=32 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF
+   - ADDRESS_SIZE=32 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF
+   - ADDRESS_SIZE=32 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON
+   - ADDRESS_SIZE=32 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
+   - ADDRESS_SIZE=32 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF
+   - ADDRESS_SIZE=32 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF
+   - ADDRESS_SIZE=32 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON
+   - ADDRESS_SIZE=32 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
 
 before_install:
- - sudo apt-get install libgcrypt11-dev
\ No newline at end of file
+  - if [ $ADDRESS_SIZE = '64' ]; then sudo apt-get install -y libgcrypt11-dev libssl-dev zlib1g-dev; fi
+  - if [ $ADDRESS_SIZE = '32' ]; then sudo apt-get install -y gcc-multilib libgcrypt11-dev:i386 libssl-dev:i386 zlib1g-dev:i386; fi
+  - if [ $ADDRESS_SIZE = '32' ]; then export TOOLCHAIN_OPTION="-DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-Linux-32.cmake"; fi
+
+install:
+  - mkdir bin
+  - cd bin
+
+script:
+  - cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION ..
+  - cmake --build .
+  - cmake --build . --target test
+  - cmake --build . --target package
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 05d2a58..fe7c0e0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,7 +37,7 @@ cmake_minimum_required(VERSION 2.8)
 
 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
 
-project(libssh2)
+project(libssh2 C)
 
 option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
 
diff --git a/cmake/Toolchain-Linux-32.cmake b/cmake/Toolchain-Linux-32.cmake
new file mode 100644
index 0000000..6aad9b1
--- /dev/null
+++ b/cmake/Toolchain-Linux-32.cmake
@@ -0,0 +1,42 @@
+# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+#
+# Redistribution and use in source and binary forms,
+# with or without modification, are permitted provided
+# that the following conditions are met:
+#
+#   Redistributions of source code must retain the above
+#   copyright notice, this list of conditions and the
+#   following disclaimer.
+#
+#   Redistributions in binary form must reproduce the above
+#   copyright notice, this list of conditions and the following
+#   disclaimer in the documentation and/or other materials
+#   provided with the distribution.
+#
+#   Neither the name of the copyright holder nor the names
+#   of any other contributors may be used to endorse or
+#   promote products derived from this software without
+#   specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# OF SUCH DAMAGE.
+
+# Cross-compile 32-bit binary on 64-bit linux host
+set(CMAKE_SYSTEM_NAME Linux)
+set(CMAKE_SYSTEM_VERSION 1)
+set(CMAKE_SYSTEM_PROCESSOR "i386")
+
+set(CMAKE_CXX_COMPILER_ARG1 "-m32")
+set(CMAKE_C_COMPILER_ARG1 "-m32")
\ No newline at end of file
-- 
2.1.0


From b0815252e6b3fb6cf3b0eae90ec42847bdc9ae53 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Tue, 15 Jul 2014 10:07:20 +0200
Subject: [PATCH 17/47] Refresh Travis CI packages before installing
 dependencies.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 .travis.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.travis.yml b/.travis.yml
index 5f7d7df..5b09dd8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -24,6 +24,7 @@ env:
    - ADDRESS_SIZE=32 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
 
 before_install:
+  - sudo apt-get update
   - if [ $ADDRESS_SIZE = '64' ]; then sudo apt-get install -y libgcrypt11-dev libssl-dev zlib1g-dev; fi
   - if [ $ADDRESS_SIZE = '32' ]; then sudo apt-get install -y gcc-multilib libgcrypt11-dev:i386 libssl-dev:i386 zlib1g-dev:i386; fi
   - if [ $ADDRESS_SIZE = '32' ]; then export TOOLCHAIN_OPTION="-DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-Linux-32.cmake"; fi
-- 
2.1.0


From 63e4b4e4b08dc40ae503ed03af048ec5a49d02de Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Tue, 15 Jul 2014 23:20:43 +0200
Subject: [PATCH 18/47] Resolve Travis CI libc-dev 32-bit dependency problem.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 .travis.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.travis.yml b/.travis.yml
index 5b09dd8..f29ba8d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -26,6 +26,7 @@ env:
 before_install:
   - sudo apt-get update
   - if [ $ADDRESS_SIZE = '64' ]; then sudo apt-get install -y libgcrypt11-dev libssl-dev zlib1g-dev; fi
+  - if [ $ADDRESS_SIZE = '32' ]; then sudo apt-get install -y linux-libc-dev linux-libc-dev:i386; fi
   - if [ $ADDRESS_SIZE = '32' ]; then sudo apt-get install -y gcc-multilib libgcrypt11-dev:i386 libssl-dev:i386 zlib1g-dev:i386; fi
   - if [ $ADDRESS_SIZE = '32' ]; then export TOOLCHAIN_OPTION="-DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-Linux-32.cmake"; fi
 
-- 
2.1.0


From 793382cb6f922d5958333dd3313f00d2092f33c8 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Mon, 28 Jul 2014 21:27:05 +0200
Subject: [PATCH 19/47] Make SSHD tests fail if SSHD dies before test runs.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 tests/sshd_fixture.sh.in | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tests/sshd_fixture.sh.in b/tests/sshd_fixture.sh.in
index 0058f51..a76f433 100644
--- a/tests/sshd_fixture.sh.in
+++ b/tests/sshd_fixture.sh.in
@@ -36,6 +36,12 @@ trap "kill ${sshdpid}; echo signal killing sshd; exit 1;" EXIT
 
 sleep 3
 
+if ! kill -0 ${sshdpid}
+then
+    echo "SSHD exited before test started"
+    exit 1
+fi
+
 : Invoking $cmd...
 eval "$cmd"
 ec=$?
-- 
2.1.0


From 6bed9b011fe1e738d4e22ccb9fa6ce260cda095a Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Thu, 14 Aug 2014 21:06:11 +0100
Subject: [PATCH 20/47] Make max_warnings work with Visual C++ Express.

VC Express didn't match the previous condition because it uses vcexpress.exe instead of devenv.exe as the CMAKE_BUILD_TOOL.  This change uses MSVC which should catch all the cases.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 cmake/max_warnings.cmake | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/cmake/max_warnings.cmake b/cmake/max_warnings.cmake
index 19a2e90..9dcabc3 100644
--- a/cmake/max_warnings.cmake
+++ b/cmake/max_warnings.cmake
@@ -1,5 +1,4 @@
-
-if(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)")
+if(MSVC)
   # Use the highest warning level for visual studio.
   if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
     string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
-- 
2.1.0


From 398e30c0b95ce9fe305e0b0640dde8b8594855a2 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Thu, 14 Aug 2014 21:10:31 +0100
Subject: [PATCH 21/47] Return valid code from test fixture on failure.

The sshd test fixture was returning -1 if an error occurred, but negative error codes aren't technically valid (google it).  Bash on Windows converted them to 0 which made setup failure look as though all tests were passing.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 tests/ssh2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/ssh2.c b/tests/ssh2.c
index dba6a0f..4df4d1b 100644
--- a/tests/ssh2.c
+++ b/tests/ssh2.c
@@ -76,7 +76,7 @@ int main(int argc, char *argv[])
     if (connect(sock, (struct sockaddr*)(&sin),
                 sizeof(struct sockaddr_in)) != 0) {
         fprintf(stderr, "failed to connect!\n");
-        return -1;
+        return 1;
     }
 
     /* Create a session instance and start it up
@@ -85,7 +85,7 @@ int main(int argc, char *argv[])
     session = libssh2_session_init();
     if (libssh2_session_startup(session, sock)) {
         fprintf(stderr, "Failure establishing SSH session\n");
-        return -1;
+        return 1;
     }
 
     /* At this point we havn't authenticated,
-- 
2.1.0


From f6191bc1f0bd2db3138f12d50ffc3b05bacd295a Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Mon, 29 Sep 2014 08:18:59 +0100
Subject: [PATCH 22/47] Revert to defining the version number in libssh2.h.

This avoids having to configure libssh2.h from libssh2.h.in, meaning the source remains compilable even without CMake.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 CMakeLists.txt       |   40 +-
 include/libssh2.h    | 1204 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/libssh2.h.in | 1200 -------------------------------------------------
 3 files changed, 1230 insertions(+), 1214 deletions(-)
 create mode 100644 include/libssh2.h
 delete mode 100644 include/libssh2.h.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fe7c0e0..a0148a1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,27 +41,39 @@ project(libssh2 C)
 
 option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
 
-set(LIBSSH2_VERSION_MAJOR 1)
-set(LIBSSH2_VERSION_MINOR 4)
-set(LIBSSH2_VERSION_PATCH 4)
-set(LIBSSH2_VERSION_NUM 0x010404)
+# Parse version
+
+file(READ ${CMAKE_CURRENT_SOURCE_DIR}/include/libssh2.h _HEADER_CONTENTS)
+string(
+  REGEX REPLACE ".*#define LIBSSH2_VERSION[ \t]+\"([^\"]+)\".*" "\\1"
+  LIBSSH2_VERSION "${_HEADER_CONTENTS}")
+string(
+  REGEX REPLACE ".*#define LIBSSH2_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1"
+  LIBSSH2_VERSION_MAJOR "${_HEADER_CONTENTS}")
+string(
+  REGEX REPLACE ".*#define LIBSSH2_VERSION_MINOR[ \t]+([0-9]+).*" "\\1"
+  LIBSSH2_VERSION_MINOR "${_HEADER_CONTENTS}")
+string(
+  REGEX REPLACE ".*#define LIBSSH2_VERSION_PATCH[ \t]+([0-9]+).*" "\\1"
+  LIBSSH2_VERSION_PATCH "${_HEADER_CONTENTS}")
+
+if(NOT LIBSSH2_VERSION OR
+   NOT LIBSSH2_VERSION_MAJOR MATCHES "^[0-9]+$" OR
+   NOT LIBSSH2_VERSION_MINOR MATCHES "^[0-9]+$" OR
+   NOT LIBSSH2_VERSION_PATCH MATCHES "^[0-9]+$")
+  message(
+    FATAL_ERROR
+    "Unable to parse version from"
+    "${CMAKE_CURRENT_SOURCE_DIR}/include/libssh2.h")
+endif()
 
-# We use underscore instead of dash when appending DEV in dev versions
-# just to make the BANNER define (used by src/session.c) be a valid
-# SSH banner. Release versions have no appended strings and may of
-# course not have dashes either.
-set(LIBSSH2_VERSION
-  "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}_DEV")
 
 install(
   FILES AUTHORS COPYING HACKING README RELEASE-NOTES NEWS
   DESTINATION .)
 
-configure_file(include/libssh2.h.in ${CMAKE_CURRENT_BINARY_DIR}/libssh2.h)
-include_directories(include ${CMAKE_CURRENT_BINARY_DIR})
-
 install(FILES
-  ${CMAKE_CURRENT_BINARY_DIR}/libssh2.h
+  include/libssh2.h
   include/libssh2_publickey.h
   include/libssh2_sftp.h
   DESTINATION include)
diff --git a/include/libssh2.h b/include/libssh2.h
new file mode 100644
index 0000000..c59fba3
--- /dev/null
+++ b/include/libssh2.h
@@ -0,0 +1,1204 @@
+/* Copyright (c) 2004-2009, Sara Golemon <sarag@libssh2.org>
+ * Copyright (c) 2009-2012 Daniel Stenberg
+ * Copyright (c) 2010 Simon Josefsson <simon@josefsson.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ *   Redistributions of source code must retain the above
+ *   copyright notice, this list of conditions and the
+ *   following disclaimer.
+ *
+ *   Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the following
+ *   disclaimer in the documentation and/or other materials
+ *   provided with the distribution.
+ *
+ *   Neither the name of the copyright holder nor the names
+ *   of any other contributors may be used to endorse or
+ *   promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ */
+
+#ifndef LIBSSH2_H
+#define LIBSSH2_H 1
+
+#define LIBSSH2_COPYRIGHT "2004-2012 The libssh2 project and its contributors."
+
+/* We use underscore instead of dash when appending DEV in dev versions just
+   to make the BANNER define (used by src/session.c) be a valid SSH
+   banner. Release versions have no appended strings and may of course not
+   have dashes either. */
+#define LIBSSH2_VERSION                             "1.4.4_DEV"
+
+/* The numeric version number is also available "in parts" by using these
+   defines: */
+#define LIBSSH2_VERSION_MAJOR                       1
+#define LIBSSH2_VERSION_MINOR                       4
+#define LIBSSH2_VERSION_PATCH                       4
+
+/* This is the numeric version of the libssh2 version number, meant for easier
+   parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
+   always follow this syntax:
+
+         0xXXYYZZ
+
+   Where XX, YY and ZZ are the main version, release and patch numbers in
+   hexadecimal (using 8 bits each). All three numbers are always represented
+   using two digits.  1.2 would appear as "0x010200" while version 9.11.7
+   appears as "0x090b07".
+
+   This 6-digit (24 bits) hexadecimal number does not show pre-release number,
+   and it is always a greater number in a more recent release. It makes
+   comparisons with greater than and less than work.
+*/
+#define LIBSSH2_VERSION_NUM                         0x010404
+
+/*
+ * This is the date and time when the full source package was created. The
+ * timestamp is not stored in the source code repo, as the timestamp is
+ * properly set in the tarballs by the maketgz script.
+ *
+ * The format of the date should follow this template:
+ *
+ * "Mon Feb 12 11:35:33 UTC 2007"
+ */
+#define LIBSSH2_TIMESTAMP "DEV"
+
+#ifndef RC_INVOKED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef _WIN32
+# include <basetsd.h>
+# include <winsock2.h>
+#endif
+
+#include <stddef.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+/* Allow alternate API prefix from CFLAGS or calling app */
+#ifndef LIBSSH2_API
+# ifdef LIBSSH2_WIN32
+#  ifdef _WINDLL
+#   ifdef LIBSSH2_LIBRARY
+#    define LIBSSH2_API __declspec(dllexport)
+#   else
+#    define LIBSSH2_API __declspec(dllimport)
+#   endif /* LIBSSH2_LIBRARY */
+#  else
+#   define LIBSSH2_API
+#  endif
+# else /* !LIBSSH2_WIN32 */
+#  define LIBSSH2_API
+# endif /* LIBSSH2_WIN32 */
+#endif /* LIBSSH2_API */
+
+#ifdef HAVE_SYS_UIO_H
+# include <sys/uio.h>
+#endif
+
+#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
+# include <sys/bsdskt.h>
+typedef unsigned char uint8_t;
+typedef unsigned int uint32_t;
+#endif
+
+#ifdef _MSC_VER
+typedef unsigned char uint8_t;
+typedef unsigned int uint32_t;
+typedef unsigned __int64 libssh2_uint64_t;
+typedef __int64 libssh2_int64_t;
+#ifndef ssize_t
+typedef SSIZE_T ssize_t;
+#endif
+#else
+typedef unsigned long long libssh2_uint64_t;
+typedef long long libssh2_int64_t;
+#endif
+
+#ifdef WIN32
+typedef SOCKET libssh2_socket_t;
+#define LIBSSH2_INVALID_SOCKET INVALID_SOCKET
+#else /* !WIN32 */
+typedef int libssh2_socket_t;
+#define LIBSSH2_INVALID_SOCKET -1
+#endif /* WIN32 */
+
+/* Part of every banner, user specified or not */
+#define LIBSSH2_SSH_BANNER                  "SSH-2.0-libssh2_" LIBSSH2_VERSION
+
+/* We *could* add a comment here if we so chose */
+#define LIBSSH2_SSH_DEFAULT_BANNER                  LIBSSH2_SSH_BANNER
+#define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF        LIBSSH2_SSH_DEFAULT_BANNER "\r\n"
+
+/* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1 */
+#define LIBSSH2_DH_GEX_MINGROUP     1024
+#define LIBSSH2_DH_GEX_OPTGROUP     1536
+#define LIBSSH2_DH_GEX_MAXGROUP     2048
+
+/* Defaults for pty requests */
+#define LIBSSH2_TERM_WIDTH      80
+#define LIBSSH2_TERM_HEIGHT     24
+#define LIBSSH2_TERM_WIDTH_PX   0
+#define LIBSSH2_TERM_HEIGHT_PX  0
+
+/* 1/4 second */
+#define LIBSSH2_SOCKET_POLL_UDELAY      250000
+/* 0.25 * 120 == 30 seconds */
+#define LIBSSH2_SOCKET_POLL_MAXLOOPS    120
+
+/* Maximum size to allow a payload to compress to, plays it safe by falling
+   short of spec limits */
+#define LIBSSH2_PACKET_MAXCOMP      32000
+
+/* Maximum size to allow a payload to deccompress to, plays it safe by
+   allowing more than spec requires */
+#define LIBSSH2_PACKET_MAXDECOMP    40000
+
+/* Maximum size for an inbound compressed payload, plays it safe by
+   overshooting spec limits */
+#define LIBSSH2_PACKET_MAXPAYLOAD   40000
+
+/* Malloc callbacks */
+#define LIBSSH2_ALLOC_FUNC(name)   void *name(size_t count, void **abstract)
+#define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, \
+                                              void **abstract)
+#define LIBSSH2_FREE_FUNC(name)    void name(void *ptr, void **abstract)
+
+typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT
+{
+    char* text;
+    unsigned int length;
+    unsigned char echo;
+} LIBSSH2_USERAUTH_KBDINT_PROMPT;
+
+typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE
+{
+    char* text;
+    unsigned int length;
+} LIBSSH2_USERAUTH_KBDINT_RESPONSE;
+
+/* 'publickey' authentication callback */
+#define LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC(name) \
+  int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \
+           const unsigned char *data, size_t data_len, void **abstract)
+
+/* 'keyboard-interactive' authentication callback */
+#define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) \
+ void name_(const char* name, int name_len, const char* instruction, \
+            int instruction_len, int num_prompts, \
+            const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, \
+            LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract)
+
+/* Callbacks for special SSH packets */
+#define LIBSSH2_IGNORE_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, const char *message, int message_len, \
+           void **abstract)
+
+#define LIBSSH2_DEBUG_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, int always_display, const char *message, \
+           int message_len, const char *language, int language_len, \
+           void **abstract)
+
+#define LIBSSH2_DISCONNECT_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, int reason, const char *message, \
+           int message_len, const char *language, int language_len, \
+           void **abstract)
+
+#define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, \
+           void **abstract)
+
+#define LIBSSH2_MACERROR_FUNC(name) \
+ int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, \
+          void **abstract)
+
+#define LIBSSH2_X11_OPEN_FUNC(name) \
+ void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \
+           const char *shost, int sport, void **abstract)
+
+#define LIBSSH2_CHANNEL_CLOSE_FUNC(name) \
+  void name(LIBSSH2_SESSION *session, void **session_abstract, \
+            LIBSSH2_CHANNEL *channel, void **channel_abstract)
+
+/* I/O callbacks */
+#define LIBSSH2_RECV_FUNC(name)  ssize_t name(libssh2_socket_t socket, \
+                                              void *buffer, size_t length, \
+                                              int flags, void **abstract)
+#define LIBSSH2_SEND_FUNC(name)  ssize_t name(libssh2_socket_t socket, \
+                                              const void *buffer, size_t length,\
+                                              int flags, void **abstract)
+
+/* libssh2_session_callback_set() constants */
+#define LIBSSH2_CALLBACK_IGNORE             0
+#define LIBSSH2_CALLBACK_DEBUG              1
+#define LIBSSH2_CALLBACK_DISCONNECT         2
+#define LIBSSH2_CALLBACK_MACERROR           3
+#define LIBSSH2_CALLBACK_X11                4
+#define LIBSSH2_CALLBACK_SEND               5
+#define LIBSSH2_CALLBACK_RECV               6
+
+/* libssh2_session_method_pref() constants */
+#define LIBSSH2_METHOD_KEX          0
+#define LIBSSH2_METHOD_HOSTKEY      1
+#define LIBSSH2_METHOD_CRYPT_CS     2
+#define LIBSSH2_METHOD_CRYPT_SC     3
+#define LIBSSH2_METHOD_MAC_CS       4
+#define LIBSSH2_METHOD_MAC_SC       5
+#define LIBSSH2_METHOD_COMP_CS      6
+#define LIBSSH2_METHOD_COMP_SC      7
+#define LIBSSH2_METHOD_LANG_CS      8
+#define LIBSSH2_METHOD_LANG_SC      9
+
+/* flags */
+#define LIBSSH2_FLAG_SIGPIPE        1
+#define LIBSSH2_FLAG_COMPRESS       2
+
+typedef struct _LIBSSH2_SESSION                     LIBSSH2_SESSION;
+typedef struct _LIBSSH2_CHANNEL                     LIBSSH2_CHANNEL;
+typedef struct _LIBSSH2_LISTENER                    LIBSSH2_LISTENER;
+typedef struct _LIBSSH2_KNOWNHOSTS                  LIBSSH2_KNOWNHOSTS;
+typedef struct _LIBSSH2_AGENT                       LIBSSH2_AGENT;
+
+typedef struct _LIBSSH2_POLLFD {
+    unsigned char type; /* LIBSSH2_POLLFD_* below */
+
+    union {
+        libssh2_socket_t socket; /* File descriptors -- examined with
+                                    system select() call */
+        LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */
+        LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound
+                                       connections waiting to be accepted? */
+    } fd;
+
+    unsigned long events; /* Requested Events */
+    unsigned long revents; /* Returned Events */
+} LIBSSH2_POLLFD;
+
+/* Poll FD Descriptor Types */
+#define LIBSSH2_POLLFD_SOCKET       1
+#define LIBSSH2_POLLFD_CHANNEL      2
+#define LIBSSH2_POLLFD_LISTENER     3
+
+/* Note: Win32 Doesn't actually have a poll() implementation, so some of these
+   values are faked with select() data */
+/* Poll FD events/revents -- Match sys/poll.h where possible */
+#define LIBSSH2_POLLFD_POLLIN           0x0001 /* Data available to be read or
+                                                  connection available --
+                                                  All */
+#define LIBSSH2_POLLFD_POLLPRI          0x0002 /* Priority data available to
+                                                  be read -- Socket only */
+#define LIBSSH2_POLLFD_POLLEXT          0x0002 /* Extended data available to
+                                                  be read -- Channel only */
+#define LIBSSH2_POLLFD_POLLOUT          0x0004 /* Can may be written --
+                                                  Socket/Channel */
+/* revents only */
+#define LIBSSH2_POLLFD_POLLERR          0x0008 /* Error Condition -- Socket */
+#define LIBSSH2_POLLFD_POLLHUP          0x0010 /* HangUp/EOF -- Socket */
+#define LIBSSH2_POLLFD_SESSION_CLOSED   0x0010 /* Session Disconnect */
+#define LIBSSH2_POLLFD_POLLNVAL         0x0020 /* Invalid request -- Socket
+                                                  Only */
+#define LIBSSH2_POLLFD_POLLEX           0x0040 /* Exception Condition --
+                                                  Socket/Win32 */
+#define LIBSSH2_POLLFD_CHANNEL_CLOSED   0x0080 /* Channel Disconnect */
+#define LIBSSH2_POLLFD_LISTENER_CLOSED  0x0080 /* Listener Disconnect */
+
+#define HAVE_LIBSSH2_SESSION_BLOCK_DIRECTION
+/* Block Direction Types */
+#define LIBSSH2_SESSION_BLOCK_INBOUND                  0x0001
+#define LIBSSH2_SESSION_BLOCK_OUTBOUND                 0x0002
+
+/* Hash Types */
+#define LIBSSH2_HOSTKEY_HASH_MD5                            1
+#define LIBSSH2_HOSTKEY_HASH_SHA1                           2
+
+/* Hostkey Types */
+#define LIBSSH2_HOSTKEY_TYPE_UNKNOWN			    0
+#define LIBSSH2_HOSTKEY_TYPE_RSA			    1
+#define LIBSSH2_HOSTKEY_TYPE_DSS			    2
+
+/* Disconnect Codes (defined by SSH protocol) */
+#define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT          1
+#define SSH_DISCONNECT_PROTOCOL_ERROR                       2
+#define SSH_DISCONNECT_KEY_EXCHANGE_FAILED                  3
+#define SSH_DISCONNECT_RESERVED                             4
+#define SSH_DISCONNECT_MAC_ERROR                            5
+#define SSH_DISCONNECT_COMPRESSION_ERROR                    6
+#define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE                7
+#define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED       8
+#define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE              9
+#define SSH_DISCONNECT_CONNECTION_LOST                      10
+#define SSH_DISCONNECT_BY_APPLICATION                       11
+#define SSH_DISCONNECT_TOO_MANY_CONNECTIONS                 12
+#define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER               13
+#define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE       14
+#define SSH_DISCONNECT_ILLEGAL_USER_NAME                    15
+
+/* Error Codes (defined by libssh2) */
+#define LIBSSH2_ERROR_NONE                      0
+
+/* The library once used -1 as a generic error return value on numerous places
+   through the code, which subsequently was converted to
+   LIBSSH2_ERROR_SOCKET_NONE uses over time. As this is a generic error code,
+   the goal is to never ever return this code but instead make sure that a
+   more accurate and descriptive error code is used. */
+#define LIBSSH2_ERROR_SOCKET_NONE               -1
+
+#define LIBSSH2_ERROR_BANNER_RECV               -2
+#define LIBSSH2_ERROR_BANNER_SEND               -3
+#define LIBSSH2_ERROR_INVALID_MAC               -4
+#define LIBSSH2_ERROR_KEX_FAILURE               -5
+#define LIBSSH2_ERROR_ALLOC                     -6
+#define LIBSSH2_ERROR_SOCKET_SEND               -7
+#define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE      -8
+#define LIBSSH2_ERROR_TIMEOUT                   -9
+#define LIBSSH2_ERROR_HOSTKEY_INIT              -10
+#define LIBSSH2_ERROR_HOSTKEY_SIGN              -11
+#define LIBSSH2_ERROR_DECRYPT                   -12
+#define LIBSSH2_ERROR_SOCKET_DISCONNECT         -13
+#define LIBSSH2_ERROR_PROTO                     -14
+#define LIBSSH2_ERROR_PASSWORD_EXPIRED          -15
+#define LIBSSH2_ERROR_FILE                      -16
+#define LIBSSH2_ERROR_METHOD_NONE               -17
+#define LIBSSH2_ERROR_AUTHENTICATION_FAILED     -18
+#define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED    LIBSSH2_ERROR_AUTHENTICATION_FAILED
+#define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED      -19
+#define LIBSSH2_ERROR_CHANNEL_OUTOFORDER        -20
+#define LIBSSH2_ERROR_CHANNEL_FAILURE           -21
+#define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED    -22
+#define LIBSSH2_ERROR_CHANNEL_UNKNOWN           -23
+#define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED   -24
+#define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED   -25
+#define LIBSSH2_ERROR_CHANNEL_CLOSED            -26
+#define LIBSSH2_ERROR_CHANNEL_EOF_SENT          -27
+#define LIBSSH2_ERROR_SCP_PROTOCOL              -28
+#define LIBSSH2_ERROR_ZLIB                      -29
+#define LIBSSH2_ERROR_SOCKET_TIMEOUT            -30
+#define LIBSSH2_ERROR_SFTP_PROTOCOL             -31
+#define LIBSSH2_ERROR_REQUEST_DENIED            -32
+#define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED      -33
+#define LIBSSH2_ERROR_INVAL                     -34
+#define LIBSSH2_ERROR_INVALID_POLL_TYPE         -35
+#define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL        -36
+#define LIBSSH2_ERROR_EAGAIN                    -37
+#define LIBSSH2_ERROR_BUFFER_TOO_SMALL          -38
+#define LIBSSH2_ERROR_BAD_USE                   -39
+#define LIBSSH2_ERROR_COMPRESS                  -40
+#define LIBSSH2_ERROR_OUT_OF_BOUNDARY           -41
+#define LIBSSH2_ERROR_AGENT_PROTOCOL            -42
+#define LIBSSH2_ERROR_SOCKET_RECV               -43
+#define LIBSSH2_ERROR_ENCRYPT                   -44
+#define LIBSSH2_ERROR_BAD_SOCKET                -45
+#define LIBSSH2_ERROR_KNOWN_HOSTS               -46
+
+/* this is a define to provide the old (<= 1.2.7) name */
+#define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV
+
+/* Global API */
+#define LIBSSH2_INIT_NO_CRYPTO        0x0001
+
+/*
+ * libssh2_init()
+ *
+ * Initialize the libssh2 functions.  This typically initialize the
+ * crypto library.  It uses a global state, and is not thread safe --
+ * you must make sure this function is not called concurrently.
+ *
+ * Flags can be:
+ * 0:                              Normal initialize
+ * LIBSSH2_INIT_NO_CRYPTO:         Do not initialize the crypto library (ie.
+ *                                 OPENSSL_add_cipher_algoritms() for OpenSSL
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int libssh2_init(int flags);
+
+/*
+ * libssh2_exit()
+ *
+ * Exit the libssh2 functions and free's all memory used internal.
+ */
+LIBSSH2_API void libssh2_exit(void);
+
+/*
+ * libssh2_free()
+ *
+ * Deallocate memory allocated by earlier call to libssh2 functions.
+ */
+LIBSSH2_API void libssh2_free(LIBSSH2_SESSION *session, void *ptr);
+
+/*
+ * libssh2_session_supported_algs()
+ *
+ * Fills algs with a list of supported acryptographic algorithms. Returns a
+ * non-negative number (number of supported algorithms) on success or a
+ * negative number (an eror code) on failure.
+ *
+ * NOTE: on success, algs must be deallocated (by calling libssh2_free) when
+ * not needed anymore
+ */
+LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
+                                               int method_type,
+                                               const char*** algs);
+
+/* Session API */
+LIBSSH2_API LIBSSH2_SESSION *
+libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
+                        LIBSSH2_FREE_FUNC((*my_free)),
+                        LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract);
+#define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL)
+
+LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session);
+
+LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session,
+                                               int cbtype, void *callback);
+LIBSSH2_API int libssh2_session_banner_set(LIBSSH2_SESSION *session,
+                                           const char *banner);
+LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session,
+                                   const char *banner);
+
+LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int sock);
+LIBSSH2_API int libssh2_session_handshake(LIBSSH2_SESSION *session,
+                                          libssh2_socket_t sock);
+LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session,
+                                              int reason,
+                                              const char *description,
+                                              const char *lang);
+#define libssh2_session_disconnect(session, description) \
+  libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, \
+                                (description), "")
+
+LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session);
+
+LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session,
+                                             int hash_type);
+
+LIBSSH2_API const char *libssh2_session_hostkey(LIBSSH2_SESSION *session,
+                                                size_t *len, int *type);
+
+LIBSSH2_API int libssh2_session_method_pref(LIBSSH2_SESSION *session,
+                                            int method_type,
+                                            const char *prefs);
+LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session,
+                                                int method_type);
+LIBSSH2_API int libssh2_session_last_error(LIBSSH2_SESSION *session,
+                                           char **errmsg,
+                                           int *errmsg_len, int want_buf);
+LIBSSH2_API int libssh2_session_last_errno(LIBSSH2_SESSION *session);
+LIBSSH2_API int libssh2_session_block_directions(LIBSSH2_SESSION *session);
+
+LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag,
+                                     int value);
+LIBSSH2_API const char *libssh2_session_banner_get(LIBSSH2_SESSION *session);
+
+/* Userauth API */
+LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session,
+                                        const char *username,
+                                        unsigned int username_len);
+LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);
+
+LIBSSH2_API int libssh2_userauth_password_ex(LIBSSH2_SESSION *session,
+                                             const char *username,
+                                             unsigned int username_len,
+                                             const char *password,
+                                             unsigned int password_len,
+                                             LIBSSH2_PASSWD_CHANGEREQ_FUNC((*passwd_change_cb)));
+
+#define libssh2_userauth_password(session, username, password) \
+ libssh2_userauth_password_ex((session), (username),           \
+                              (unsigned int)strlen(username),  \
+                              (password), (unsigned int)strlen(password), NULL)
+
+LIBSSH2_API int
+libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
+                                       const char *username,
+                                       unsigned int username_len,
+                                       const char *publickey,
+                                       const char *privatekey,
+                                       const char *passphrase);
+
+#define libssh2_userauth_publickey_fromfile(session, username, publickey, \
+                                            privatekey, passphrase)     \
+    libssh2_userauth_publickey_fromfile_ex((session), (username),       \
+                                           (unsigned int)strlen(username), \
+                                           (publickey),                 \
+                                           (privatekey), (passphrase))
+
+LIBSSH2_API int
+libssh2_userauth_publickey(LIBSSH2_SESSION *session,
+                           const char *username,
+                           const unsigned char *pubkeydata,
+                           size_t pubkeydata_len,
+                           LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC((*sign_callback)),
+                           void **abstract);
+
+LIBSSH2_API int
+libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session,
+                                       const char *username,
+                                       unsigned int username_len,
+                                       const char *publickey,
+                                       const char *privatekey,
+                                       const char *passphrase,
+                                       const char *hostname,
+                                       unsigned int hostname_len,
+                                       const char *local_username,
+                                       unsigned int local_username_len);
+
+#define libssh2_userauth_hostbased_fromfile(session, username, publickey, \
+                                            privatekey, passphrase, hostname) \
+ libssh2_userauth_hostbased_fromfile_ex((session), (username), \
+                                        (unsigned int)strlen(username), \
+                                        (publickey),                    \
+                                        (privatekey), (passphrase),     \
+                                        (hostname),                     \
+                                        (unsigned int)strlen(hostname), \
+                                        (username),                     \
+                                        (unsigned int)strlen(username))
+
+/*
+ * response_callback is provided with filled by library prompts array,
+ * but client must allocate and fill individual responses. Responses
+ * array is already allocated. Responses data will be freed by libssh2
+ * after callback return, but before subsequent callback invokation.
+ */
+LIBSSH2_API int
+libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session,
+                                         const char *username,
+                                         unsigned int username_len,
+                                         LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC((*response_callback)));
+
+#define libssh2_userauth_keyboard_interactive(session, username,        \
+                                              response_callback)        \
+    libssh2_userauth_keyboard_interactive_ex((session), (username),     \
+                                             (unsigned int)strlen(username), \
+                                             (response_callback))
+
+LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds,
+                             long timeout);
+
+/* Channel API */
+#define LIBSSH2_CHANNEL_WINDOW_DEFAULT  (2*1024*1024)
+#define LIBSSH2_CHANNEL_PACKET_DEFAULT  32768
+#define LIBSSH2_CHANNEL_MINADJUST       1024
+
+/* Extended Data Handling */
+#define LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL        0
+#define LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE        1
+#define LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE         2
+
+#define SSH_EXTENDED_DATA_STDERR 1
+
+/* Returned by any function that would block during a read/write opperation */
+#define LIBSSH2CHANNEL_EAGAIN LIBSSH2_ERROR_EAGAIN
+
+LIBSSH2_API LIBSSH2_CHANNEL *
+libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type,
+                        unsigned int channel_type_len,
+                        unsigned int window_size, unsigned int packet_size,
+                        const char *message, unsigned int message_len);
+
+#define libssh2_channel_open_session(session) \
+  libssh2_channel_open_ex((session), "session", sizeof("session") - 1, \
+                          LIBSSH2_CHANNEL_WINDOW_DEFAULT, \
+                          LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0)
+
+LIBSSH2_API LIBSSH2_CHANNEL *
+libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host,
+                                int port, const char *shost, int sport);
+#define libssh2_channel_direct_tcpip(session, host, port) \
+  libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22)
+
+LIBSSH2_API LIBSSH2_LISTENER *
+libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host,
+                                  int port, int *bound_port, int queue_maxsize);
+#define libssh2_channel_forward_listen(session, port) \
+ libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16)
+
+LIBSSH2_API int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
+
+LIBSSH2_API LIBSSH2_CHANNEL *
+libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener);
+
+LIBSSH2_API int libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel,
+                                          const char *varname,
+                                          unsigned int varname_len,
+                                          const char *value,
+                                          unsigned int value_len);
+
+#define libssh2_channel_setenv(channel, varname, value)                 \
+    libssh2_channel_setenv_ex((channel), (varname),                     \
+                              (unsigned int)strlen(varname), (value),   \
+                              (unsigned int)strlen(value))
+
+LIBSSH2_API int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel,
+                                               const char *term,
+                                               unsigned int term_len,
+                                               const char *modes,
+                                               unsigned int modes_len,
+                                               int width, int height,
+                                               int width_px, int height_px);
+#define libssh2_channel_request_pty(channel, term)                      \
+    libssh2_channel_request_pty_ex((channel), (term),                   \
+                                   (unsigned int)strlen(term),          \
+                                   NULL, 0,                             \
+                                   LIBSSH2_TERM_WIDTH, LIBSSH2_TERM_HEIGHT, \
+                                   LIBSSH2_TERM_WIDTH_PX, LIBSSH2_TERM_HEIGHT_PX)
+
+LIBSSH2_API int libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL *channel,
+                                                    int width, int height,
+                                                    int width_px,
+                                                    int height_px);
+#define libssh2_channel_request_pty_size(channel, width, height) \
+  libssh2_channel_request_pty_size_ex( (channel), (width), (height), 0, 0)
+
+LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel,
+                                           int single_connection,
+                                           const char *auth_proto,
+                                           const char *auth_cookie,
+                                           int screen_number);
+#define libssh2_channel_x11_req(channel, screen_number) \
+ libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number))
+
+LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
+                                                const char *request,
+                                                unsigned int request_len,
+                                                const char *message,
+                                                unsigned int message_len);
+#define libssh2_channel_shell(channel) \
+  libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, \
+                                  NULL, 0)
+#define libssh2_channel_exec(channel, command) \
+  libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, \
+                                  (command), (unsigned int)strlen(command))
+#define libssh2_channel_subsystem(channel, subsystem) \
+  libssh2_channel_process_startup((channel), "subsystem",              \
+                                  sizeof("subsystem") - 1, (subsystem), \
+                                  (unsigned int)strlen(subsystem))
+
+LIBSSH2_API ssize_t libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel,
+                                            int stream_id, char *buf,
+                                            size_t buflen);
+#define libssh2_channel_read(channel, buf, buflen) \
+  libssh2_channel_read_ex((channel), 0, (buf), (buflen))
+#define libssh2_channel_read_stderr(channel, buf, buflen) \
+  libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
+
+LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel,
+                                          int extended);
+
+LIBSSH2_API unsigned long
+libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
+                               unsigned long *read_avail,
+                               unsigned long *window_size_initial);
+#define libssh2_channel_window_read(channel) \
+  libssh2_channel_window_read_ex((channel), NULL, NULL)
+
+/* libssh2_channel_receive_window_adjust is DEPRECATED, do not use! */
+LIBSSH2_API unsigned long
+libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
+                                      unsigned long adjustment,
+                                      unsigned char force);
+
+LIBSSH2_API int
+libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel,
+                                       unsigned long adjustment,
+                                       unsigned char force,
+                                       unsigned int *storewindow);
+
+LIBSSH2_API ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
+                                             int stream_id, const char *buf,
+                                             size_t buflen);
+
+#define libssh2_channel_write(channel, buf, buflen) \
+  libssh2_channel_write_ex((channel), 0, (buf), (buflen))
+#define libssh2_channel_write_stderr(channel, buf, buflen)  \
+  libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
+
+LIBSSH2_API unsigned long
+libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel,
+                                unsigned long *window_size_initial);
+#define libssh2_channel_window_write(channel) \
+  libssh2_channel_window_write_ex((channel), NULL)
+
+LIBSSH2_API void libssh2_session_set_blocking(LIBSSH2_SESSION* session,
+                                              int blocking);
+LIBSSH2_API int libssh2_session_get_blocking(LIBSSH2_SESSION* session);
+
+LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel,
+                                              int blocking);
+
+LIBSSH2_API void libssh2_session_set_timeout(LIBSSH2_SESSION* session,
+                                             long timeout);
+LIBSSH2_API long libssh2_session_get_timeout(LIBSSH2_SESSION* session);
+
+/* libssh2_channel_handle_extended_data is DEPRECATED, do not use! */
+LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel,
+                                                      int ignore_mode);
+LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel,
+                                                      int ignore_mode);
+
+/* libssh2_channel_ignore_extended_data() is defined below for BC with version
+ * 0.1
+ *
+ * Future uses should use libssh2_channel_handle_extended_data() directly if
+ * LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read
+ * (FIFO) from the standard data channel
+ */
+/* DEPRECATED */
+#define libssh2_channel_ignore_extended_data(channel, ignore) \
+  libssh2_channel_handle_extended_data((channel),                       \
+                                       (ignore) ?                       \
+                                       LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : \
+                                       LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL )
+
+#define LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA     -1
+#define LIBSSH2_CHANNEL_FLUSH_ALL               -2
+LIBSSH2_API int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel,
+                                         int streamid);
+#define libssh2_channel_flush(channel) libssh2_channel_flush_ex((channel), 0)
+#define libssh2_channel_flush_stderr(channel) \
+ libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR)
+
+LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel);
+LIBSSH2_API int libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL* channel,
+                                                char **exitsignal,
+                                                size_t *exitsignal_len,
+                                                char **errmsg,
+                                                size_t *errmsg_len,
+                                                char **langtag,
+                                                size_t *langtag_len);
+LIBSSH2_API int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_eof(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel);
+LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel);
+
+LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
+                                              const char *path,
+                                              struct stat *sb);
+LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session,
+                                                 const char *path, int mode,
+                                                 size_t size, long mtime,
+                                                 long atime);
+LIBSSH2_API LIBSSH2_CHANNEL *
+libssh2_scp_send64(LIBSSH2_SESSION *session, const char *path, int mode,
+                   libssh2_int64_t size, time_t mtime, time_t atime);
+
+#define libssh2_scp_send(session, path, mode, size) \
+  libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0)
+
+LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest,
+                                      unsigned int *dest_len,
+                                      const char *src, unsigned int src_len);
+
+LIBSSH2_API
+const char *libssh2_version(int req_version_num);
+
+#define HAVE_LIBSSH2_KNOWNHOST_API 0x010101 /* since 1.1.1 */
+#define HAVE_LIBSSH2_VERSION_API   0x010100 /* libssh2_version since 1.1 */
+
+struct libssh2_knownhost {
+    unsigned int magic;  /* magic stored by the library */
+    void *node; /* handle to the internal representation of this host */
+    char *name; /* this is NULL if no plain text host name exists */
+    char *key;  /* key in base64/printable format */
+    int typemask;
+};
+
+/*
+ * libssh2_knownhost_init
+ *
+ * Init a collection of known hosts. Returns the pointer to a collection.
+ *
+ */
+LIBSSH2_API LIBSSH2_KNOWNHOSTS *
+libssh2_knownhost_init(LIBSSH2_SESSION *session);
+
+/*
+ * libssh2_knownhost_add
+ *
+ * Add a host and its associated key to the collection of known hosts.
+ *
+ * The 'type' argument specifies on what format the given host and keys are:
+ *
+ * plain  - ascii "hostname.domain.tld"
+ * sha1   - SHA1(<salt> <host>) base64-encoded!
+ * custom - another hash
+ *
+ * If 'sha1' is selected as type, the salt must be provided to the salt
+ * argument. This too base64 encoded.
+ *
+ * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files.  If
+ * a custom type is used, salt is ignored and you must provide the host
+ * pre-hashed when checking for it in the libssh2_knownhost_check() function.
+ *
+ * The keylen parameter may be omitted (zero) if the key is provided as a
+ * NULL-terminated base64-encoded string.
+ */
+
+/* host format (2 bits) */
+#define LIBSSH2_KNOWNHOST_TYPE_MASK    0xffff
+#define LIBSSH2_KNOWNHOST_TYPE_PLAIN   1
+#define LIBSSH2_KNOWNHOST_TYPE_SHA1    2 /* always base64 encoded */
+#define LIBSSH2_KNOWNHOST_TYPE_CUSTOM  3
+
+/* key format (2 bits) */
+#define LIBSSH2_KNOWNHOST_KEYENC_MASK     (3<<16)
+#define LIBSSH2_KNOWNHOST_KEYENC_RAW      (1<<16)
+#define LIBSSH2_KNOWNHOST_KEYENC_BASE64   (2<<16)
+
+/* type of key (2 bits) */
+#define LIBSSH2_KNOWNHOST_KEY_MASK     (7<<18)
+#define LIBSSH2_KNOWNHOST_KEY_SHIFT    18
+#define LIBSSH2_KNOWNHOST_KEY_RSA1     (1<<18)
+#define LIBSSH2_KNOWNHOST_KEY_SSHRSA   (2<<18)
+#define LIBSSH2_KNOWNHOST_KEY_SSHDSS   (3<<18)
+#define LIBSSH2_KNOWNHOST_KEY_UNKNOWN  (7<<18)
+
+LIBSSH2_API int
+libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
+                      const char *host,
+                      const char *salt,
+                      const char *key, size_t keylen, int typemask,
+                      struct libssh2_knownhost **store);
+
+/*
+ * libssh2_knownhost_addc
+ *
+ * Add a host and its associated key to the collection of known hosts.
+ *
+ * Takes a comment argument that may be NULL.  A NULL comment indicates
+ * there is no comment and the entry will end directly after the key
+ * when written out to a file.  An empty string "" comment will indicate an
+ * empty comment which will cause a single space to be written after the key.
+ *
+ * The 'type' argument specifies on what format the given host and keys are:
+ *
+ * plain  - ascii "hostname.domain.tld"
+ * sha1   - SHA1(<salt> <host>) base64-encoded!
+ * custom - another hash
+ *
+ * If 'sha1' is selected as type, the salt must be provided to the salt
+ * argument. This too base64 encoded.
+ *
+ * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files.  If
+ * a custom type is used, salt is ignored and you must provide the host
+ * pre-hashed when checking for it in the libssh2_knownhost_check() function.
+ *
+ * The keylen parameter may be omitted (zero) if the key is provided as a
+ * NULL-terminated base64-encoded string.
+ */
+
+LIBSSH2_API int
+libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts,
+                       const char *host,
+                       const char *salt,
+                       const char *key, size_t keylen,
+                       const char *comment, size_t commentlen, int typemask,
+                       struct libssh2_knownhost **store);
+
+/*
+ * libssh2_knownhost_check
+ *
+ * Check a host and its associated key against the collection of known hosts.
+ *
+ * The type is the type/format of the given host name.
+ *
+ * plain  - ascii "hostname.domain.tld"
+ * custom - prehashed base64 encoded. Note that this cannot use any salts.
+ *
+ *
+ * 'knownhost' may be set to NULL if you don't care about that info.
+ *
+ * Returns:
+ *
+ * LIBSSH2_KNOWNHOST_CHECK_* values, see below
+ *
+ */
+
+#define LIBSSH2_KNOWNHOST_CHECK_MATCH    0
+#define LIBSSH2_KNOWNHOST_CHECK_MISMATCH 1
+#define LIBSSH2_KNOWNHOST_CHECK_NOTFOUND 2
+#define LIBSSH2_KNOWNHOST_CHECK_FAILURE  3
+
+LIBSSH2_API int
+libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
+                        const char *host, const char *key, size_t keylen,
+                        int typemask,
+                        struct libssh2_knownhost **knownhost);
+
+/* this function is identital to the above one, but also takes a port
+   argument that allows libssh2 to do a better check */
+LIBSSH2_API int
+libssh2_knownhost_checkp(LIBSSH2_KNOWNHOSTS *hosts,
+                         const char *host, int port,
+                         const char *key, size_t keylen,
+                         int typemask,
+                         struct libssh2_knownhost **knownhost);
+
+/*
+ * libssh2_knownhost_del
+ *
+ * Remove a host from the collection of known hosts. The 'entry' struct is
+ * retrieved by a call to libssh2_knownhost_check().
+ *
+ */
+LIBSSH2_API int
+libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts,
+                      struct libssh2_knownhost *entry);
+
+/*
+ * libssh2_knownhost_free
+ *
+ * Free an entire collection of known hosts.
+ *
+ */
+LIBSSH2_API void
+libssh2_knownhost_free(LIBSSH2_KNOWNHOSTS *hosts);
+
+/*
+ * libssh2_knownhost_readline()
+ *
+ * Pass in a line of a file of 'type'. It makes libssh2 read this line.
+ *
+ * LIBSSH2_KNOWNHOST_FILE_OPENSSH is the only supported type.
+ *
+ */
+LIBSSH2_API int
+libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
+                           const char *line, size_t len, int type);
+
+/*
+ * libssh2_knownhost_readfile
+ *
+ * Add hosts+key pairs from a given file.
+ *
+ * Returns a negative value for error or number of successfully added hosts.
+ *
+ * This implementation currently only knows one 'type' (openssh), all others
+ * are reserved for future use.
+ */
+
+#define LIBSSH2_KNOWNHOST_FILE_OPENSSH 1
+
+LIBSSH2_API int
+libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
+                           const char *filename, int type);
+
+/*
+ * libssh2_knownhost_writeline()
+ *
+ * Ask libssh2 to convert a known host to an output line for storage.
+ *
+ * Note that this function returns LIBSSH2_ERROR_BUFFER_TOO_SMALL if the given
+ * output buffer is too small to hold the desired output.
+ *
+ * This implementation currently only knows one 'type' (openssh), all others
+ * are reserved for future use.
+ *
+ */
+LIBSSH2_API int
+libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
+                            struct libssh2_knownhost *known,
+                            char *buffer, size_t buflen,
+                            size_t *outlen, /* the amount of written data */
+                            int type);
+
+/*
+ * libssh2_knownhost_writefile
+ *
+ * Write hosts+key pairs to a given file.
+ *
+ * This implementation currently only knows one 'type' (openssh), all others
+ * are reserved for future use.
+ */
+
+LIBSSH2_API int
+libssh2_knownhost_writefile(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);
+
+#define HAVE_LIBSSH2_AGENT_API 0x010202 /* since 1.2.2 */
+
+struct libssh2_agent_publickey {
+    unsigned int magic;              /* magic stored by the library */
+    void *node;     /* handle to the internal representation of key */
+    unsigned char *blob;           /* public key blob */
+    size_t blob_len;               /* length of the public key blob */
+    char *comment;                 /* comment in printable format */
+};
+
+/*
+ * libssh2_agent_init
+ *
+ * Init an ssh-agent handle. Returns the pointer to the handle.
+ *
+ */
+LIBSSH2_API LIBSSH2_AGENT *
+libssh2_agent_init(LIBSSH2_SESSION *session);
+
+/*
+ * libssh2_agent_connect()
+ *
+ * Connect to an ssh-agent.
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int
+libssh2_agent_connect(LIBSSH2_AGENT *agent);
+
+/*
+ * libssh2_agent_list_identities()
+ *
+ * Request an ssh-agent to list identities.
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int
+libssh2_agent_list_identities(LIBSSH2_AGENT *agent);
+
+/*
+ * libssh2_agent_get_identity()
+ *
+ * Traverse the internal list of public keys. 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 public key was stored in 'store'
+ * 1 if end of public keys
+ * [negative] on errors
+ */
+LIBSSH2_API int
+libssh2_agent_get_identity(LIBSSH2_AGENT *agent,
+               struct libssh2_agent_publickey **store,
+               struct libssh2_agent_publickey *prev);
+
+/*
+ * libssh2_agent_userauth()
+ *
+ * Do publickey user authentication with the help of ssh-agent.
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int
+libssh2_agent_userauth(LIBSSH2_AGENT *agent,
+               const char *username,
+               struct libssh2_agent_publickey *identity);
+
+/*
+ * libssh2_agent_disconnect()
+ *
+ * Close a connection to an ssh-agent.
+ *
+ * Returns 0 if succeeded, or a negative value for error.
+ */
+LIBSSH2_API int
+libssh2_agent_disconnect(LIBSSH2_AGENT *agent);
+
+/*
+ * libssh2_agent_free()
+ *
+ * Free an ssh-agent handle.  This function also frees the internal
+ * collection of public keys.
+ */
+LIBSSH2_API void
+libssh2_agent_free(LIBSSH2_AGENT *agent);
+
+
+/*
+ * libssh2_keepalive_config()
+ *
+ * Set how often keepalive messages should be sent.  WANT_REPLY
+ * indicates whether the keepalive messages should request a response
+ * from the server.  INTERVAL is number of seconds that can pass
+ * without any I/O, use 0 (the default) to disable keepalives.  To
+ * avoid some busy-loop corner-cases, if you specify an interval of 1
+ * it will be treated as 2.
+ *
+ * Note that non-blocking applications are responsible for sending the
+ * keepalive messages using libssh2_keepalive_send().
+ */
+LIBSSH2_API void libssh2_keepalive_config (LIBSSH2_SESSION *session,
+                                           int want_reply,
+                                           unsigned interval);
+
+/*
+ * libssh2_keepalive_send()
+ *
+ * Send a keepalive message if needed.  SECONDS_TO_NEXT indicates how
+ * many seconds you can sleep after this call before you need to call
+ * it again.  Returns 0 on success, or LIBSSH2_ERROR_SOCKET_SEND on
+ * I/O errors.
+ */
+LIBSSH2_API int libssh2_keepalive_send (LIBSSH2_SESSION *session,
+                                        int *seconds_to_next);
+
+/* NOTE NOTE NOTE
+   libssh2_trace() has no function in builds that aren't built with debug
+   enabled
+ */
+LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask);
+#define LIBSSH2_TRACE_TRANS (1<<1)
+#define LIBSSH2_TRACE_KEX   (1<<2)
+#define LIBSSH2_TRACE_AUTH  (1<<3)
+#define LIBSSH2_TRACE_CONN  (1<<4)
+#define LIBSSH2_TRACE_SCP   (1<<5)
+#define LIBSSH2_TRACE_SFTP  (1<<6)
+#define LIBSSH2_TRACE_ERROR (1<<7)
+#define LIBSSH2_TRACE_PUBLICKEY (1<<8)
+#define LIBSSH2_TRACE_SOCKET (1<<9)
+
+typedef void (*libssh2_trace_handler_func)(LIBSSH2_SESSION*,
+                                           void*,
+                                           const char *,
+                                           size_t);
+LIBSSH2_API int libssh2_trace_sethandler(LIBSSH2_SESSION *session,
+                                         void* context,
+                                         libssh2_trace_handler_func callback);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* !RC_INVOKED */
+
+#endif /* LIBSSH2_H */
diff --git a/include/libssh2.h.in b/include/libssh2.h.in
deleted file mode 100644
index 5a06351..0000000
--- a/include/libssh2.h.in
+++ /dev/null
@@ -1,1200 +0,0 @@
-/* Copyright (c) 2004-2009, Sara Golemon <sarag@libssh2.org>
- * Copyright (c) 2009-2012 Daniel Stenberg
- * Copyright (c) 2010 Simon Josefsson <simon@josefsson.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms,
- * with or without modification, are permitted provided
- * that the following conditions are met:
- *
- *   Redistributions of source code must retain the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer.
- *
- *   Redistributions in binary form must reproduce the above
- *   copyright notice, this list of conditions and the following
- *   disclaimer in the documentation and/or other materials
- *   provided with the distribution.
- *
- *   Neither the name of the copyright holder nor the names
- *   of any other contributors may be used to endorse or
- *   promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- */
-
-#ifndef LIBSSH2_H
-#define LIBSSH2_H 1
-
-#define LIBSSH2_COPYRIGHT "2004-2012 The libssh2 project and its contributors."
-
-#cmakedefine LIBSSH2_VERSION "@LIBSSH2_VERSION@"
-
-/* The numeric version number is also available "in parts" by using these
-   defines: */
-#cmakedefine LIBSSH2_VERSION_MAJOR @LIBSSH2_VERSION_MAJOR@
-#cmakedefine LIBSSH2_VERSION_MINOR @LIBSSH2_VERSION_MINOR@
-#cmakedefine LIBSSH2_VERSION_PATCH @LIBSSH2_VERSION_PATCH@
-
-/* This is the numeric version of the libssh2 version number, meant for easier
-   parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
-   always follow this syntax:
-
-         0xXXYYZZ
-
-   Where XX, YY and ZZ are the main version, release and patch numbers in
-   hexadecimal (using 8 bits each). All three numbers are always represented
-   using two digits.  1.2 would appear as "0x010200" while version 9.11.7
-   appears as "0x090b07".
-
-   This 6-digit (24 bits) hexadecimal number does not show pre-release number,
-   and it is always a greater number in a more recent release. It makes
-   comparisons with greater than and less than work.
-*/
-#cmakedefine LIBSSH2_VERSION_NUM @LIBSSH2_VERSION_NUM@
-
-/*
- * This is the date and time when the full source package was created. The
- * timestamp is not stored in the source code repo, as the timestamp is
- * properly set in the tarballs by the maketgz script.
- *
- * The format of the date should follow this template:
- *
- * "Mon Feb 12 11:35:33 UTC 2007"
- */
-#define LIBSSH2_TIMESTAMP "DEV"
-
-#ifndef RC_INVOKED
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#ifdef _WIN32
-# include <basetsd.h>
-# include <winsock2.h>
-#endif
-
-#include <stddef.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Allow alternate API prefix from CFLAGS or calling app */
-#ifndef LIBSSH2_API
-# ifdef LIBSSH2_WIN32
-#  ifdef _WINDLL
-#   ifdef LIBSSH2_LIBRARY
-#    define LIBSSH2_API __declspec(dllexport)
-#   else
-#    define LIBSSH2_API __declspec(dllimport)
-#   endif /* LIBSSH2_LIBRARY */
-#  else
-#   define LIBSSH2_API
-#  endif
-# else /* !LIBSSH2_WIN32 */
-#  define LIBSSH2_API
-# endif /* LIBSSH2_WIN32 */
-#endif /* LIBSSH2_API */
-
-#ifdef HAVE_SYS_UIO_H
-# include <sys/uio.h>
-#endif
-
-#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
-# include <sys/bsdskt.h>
-typedef unsigned char uint8_t;
-typedef unsigned int uint32_t;
-#endif
-
-#ifdef _MSC_VER
-typedef unsigned char uint8_t;
-typedef unsigned int uint32_t;
-typedef unsigned __int64 libssh2_uint64_t;
-typedef __int64 libssh2_int64_t;
-#ifndef ssize_t
-typedef SSIZE_T ssize_t;
-#endif
-#else
-typedef unsigned long long libssh2_uint64_t;
-typedef long long libssh2_int64_t;
-#endif
-
-#ifdef WIN32
-typedef SOCKET libssh2_socket_t;
-#define LIBSSH2_INVALID_SOCKET INVALID_SOCKET
-#else /* !WIN32 */
-typedef int libssh2_socket_t;
-#define LIBSSH2_INVALID_SOCKET -1
-#endif /* WIN32 */
-
-/* Part of every banner, user specified or not */
-#define LIBSSH2_SSH_BANNER                  "SSH-2.0-libssh2_" LIBSSH2_VERSION
-
-/* We *could* add a comment here if we so chose */
-#define LIBSSH2_SSH_DEFAULT_BANNER                  LIBSSH2_SSH_BANNER
-#define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF        LIBSSH2_SSH_DEFAULT_BANNER "\r\n"
-
-/* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1 */
-#define LIBSSH2_DH_GEX_MINGROUP     1024
-#define LIBSSH2_DH_GEX_OPTGROUP     1536
-#define LIBSSH2_DH_GEX_MAXGROUP     2048
-
-/* Defaults for pty requests */
-#define LIBSSH2_TERM_WIDTH      80
-#define LIBSSH2_TERM_HEIGHT     24
-#define LIBSSH2_TERM_WIDTH_PX   0
-#define LIBSSH2_TERM_HEIGHT_PX  0
-
-/* 1/4 second */
-#define LIBSSH2_SOCKET_POLL_UDELAY      250000
-/* 0.25 * 120 == 30 seconds */
-#define LIBSSH2_SOCKET_POLL_MAXLOOPS    120
-
-/* Maximum size to allow a payload to compress to, plays it safe by falling
-   short of spec limits */
-#define LIBSSH2_PACKET_MAXCOMP      32000
-
-/* Maximum size to allow a payload to deccompress to, plays it safe by
-   allowing more than spec requires */
-#define LIBSSH2_PACKET_MAXDECOMP    40000
-
-/* Maximum size for an inbound compressed payload, plays it safe by
-   overshooting spec limits */
-#define LIBSSH2_PACKET_MAXPAYLOAD   40000
-
-/* Malloc callbacks */
-#define LIBSSH2_ALLOC_FUNC(name)   void *name(size_t count, void **abstract)
-#define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, \
-                                              void **abstract)
-#define LIBSSH2_FREE_FUNC(name)    void name(void *ptr, void **abstract)
-
-typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT
-{
-    char* text;
-    unsigned int length;
-    unsigned char echo;
-} LIBSSH2_USERAUTH_KBDINT_PROMPT;
-
-typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE
-{
-    char* text;
-    unsigned int length;
-} LIBSSH2_USERAUTH_KBDINT_RESPONSE;
-
-/* 'publickey' authentication callback */
-#define LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC(name) \
-  int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \
-           const unsigned char *data, size_t data_len, void **abstract)
-
-/* 'keyboard-interactive' authentication callback */
-#define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) \
- void name_(const char* name, int name_len, const char* instruction, \
-            int instruction_len, int num_prompts, \
-            const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, \
-            LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract)
-
-/* Callbacks for special SSH packets */
-#define LIBSSH2_IGNORE_FUNC(name) \
- void name(LIBSSH2_SESSION *session, const char *message, int message_len, \
-           void **abstract)
-
-#define LIBSSH2_DEBUG_FUNC(name) \
- void name(LIBSSH2_SESSION *session, int always_display, const char *message, \
-           int message_len, const char *language, int language_len, \
-           void **abstract)
-
-#define LIBSSH2_DISCONNECT_FUNC(name) \
- void name(LIBSSH2_SESSION *session, int reason, const char *message, \
-           int message_len, const char *language, int language_len, \
-           void **abstract)
-
-#define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) \
- void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, \
-           void **abstract)
-
-#define LIBSSH2_MACERROR_FUNC(name) \
- int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, \
-          void **abstract)
-
-#define LIBSSH2_X11_OPEN_FUNC(name) \
- void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \
-           const char *shost, int sport, void **abstract)
-
-#define LIBSSH2_CHANNEL_CLOSE_FUNC(name) \
-  void name(LIBSSH2_SESSION *session, void **session_abstract, \
-            LIBSSH2_CHANNEL *channel, void **channel_abstract)
-
-/* I/O callbacks */
-#define LIBSSH2_RECV_FUNC(name)  ssize_t name(libssh2_socket_t socket, \
-                                              void *buffer, size_t length, \
-                                              int flags, void **abstract)
-#define LIBSSH2_SEND_FUNC(name)  ssize_t name(libssh2_socket_t socket, \
-                                              const void *buffer, size_t length,\
-                                              int flags, void **abstract)
-
-/* libssh2_session_callback_set() constants */
-#define LIBSSH2_CALLBACK_IGNORE             0
-#define LIBSSH2_CALLBACK_DEBUG              1
-#define LIBSSH2_CALLBACK_DISCONNECT         2
-#define LIBSSH2_CALLBACK_MACERROR           3
-#define LIBSSH2_CALLBACK_X11                4
-#define LIBSSH2_CALLBACK_SEND               5
-#define LIBSSH2_CALLBACK_RECV               6
-
-/* libssh2_session_method_pref() constants */
-#define LIBSSH2_METHOD_KEX          0
-#define LIBSSH2_METHOD_HOSTKEY      1
-#define LIBSSH2_METHOD_CRYPT_CS     2
-#define LIBSSH2_METHOD_CRYPT_SC     3
-#define LIBSSH2_METHOD_MAC_CS       4
-#define LIBSSH2_METHOD_MAC_SC       5
-#define LIBSSH2_METHOD_COMP_CS      6
-#define LIBSSH2_METHOD_COMP_SC      7
-#define LIBSSH2_METHOD_LANG_CS      8
-#define LIBSSH2_METHOD_LANG_SC      9
-
-/* flags */
-#define LIBSSH2_FLAG_SIGPIPE        1
-#define LIBSSH2_FLAG_COMPRESS       2
-
-typedef struct _LIBSSH2_SESSION                     LIBSSH2_SESSION;
-typedef struct _LIBSSH2_CHANNEL                     LIBSSH2_CHANNEL;
-typedef struct _LIBSSH2_LISTENER                    LIBSSH2_LISTENER;
-typedef struct _LIBSSH2_KNOWNHOSTS                  LIBSSH2_KNOWNHOSTS;
-typedef struct _LIBSSH2_AGENT                       LIBSSH2_AGENT;
-
-typedef struct _LIBSSH2_POLLFD {
-    unsigned char type; /* LIBSSH2_POLLFD_* below */
-
-    union {
-        libssh2_socket_t socket; /* File descriptors -- examined with
-                                    system select() call */
-        LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */
-        LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound
-                                       connections waiting to be accepted? */
-    } fd;
-
-    unsigned long events; /* Requested Events */
-    unsigned long revents; /* Returned Events */
-} LIBSSH2_POLLFD;
-
-/* Poll FD Descriptor Types */
-#define LIBSSH2_POLLFD_SOCKET       1
-#define LIBSSH2_POLLFD_CHANNEL      2
-#define LIBSSH2_POLLFD_LISTENER     3
-
-/* Note: Win32 Doesn't actually have a poll() implementation, so some of these
-   values are faked with select() data */
-/* Poll FD events/revents -- Match sys/poll.h where possible */
-#define LIBSSH2_POLLFD_POLLIN           0x0001 /* Data available to be read or
-                                                  connection available --
-                                                  All */
-#define LIBSSH2_POLLFD_POLLPRI          0x0002 /* Priority data available to
-                                                  be read -- Socket only */
-#define LIBSSH2_POLLFD_POLLEXT          0x0002 /* Extended data available to
-                                                  be read -- Channel only */
-#define LIBSSH2_POLLFD_POLLOUT          0x0004 /* Can may be written --
-                                                  Socket/Channel */
-/* revents only */
-#define LIBSSH2_POLLFD_POLLERR          0x0008 /* Error Condition -- Socket */
-#define LIBSSH2_POLLFD_POLLHUP          0x0010 /* HangUp/EOF -- Socket */
-#define LIBSSH2_POLLFD_SESSION_CLOSED   0x0010 /* Session Disconnect */
-#define LIBSSH2_POLLFD_POLLNVAL         0x0020 /* Invalid request -- Socket
-                                                  Only */
-#define LIBSSH2_POLLFD_POLLEX           0x0040 /* Exception Condition --
-                                                  Socket/Win32 */
-#define LIBSSH2_POLLFD_CHANNEL_CLOSED   0x0080 /* Channel Disconnect */
-#define LIBSSH2_POLLFD_LISTENER_CLOSED  0x0080 /* Listener Disconnect */
-
-#define HAVE_LIBSSH2_SESSION_BLOCK_DIRECTION
-/* Block Direction Types */
-#define LIBSSH2_SESSION_BLOCK_INBOUND                  0x0001
-#define LIBSSH2_SESSION_BLOCK_OUTBOUND                 0x0002
-
-/* Hash Types */
-#define LIBSSH2_HOSTKEY_HASH_MD5                            1
-#define LIBSSH2_HOSTKEY_HASH_SHA1                           2
-
-/* Hostkey Types */
-#define LIBSSH2_HOSTKEY_TYPE_UNKNOWN			    0
-#define LIBSSH2_HOSTKEY_TYPE_RSA			    1
-#define LIBSSH2_HOSTKEY_TYPE_DSS			    2
-
-/* Disconnect Codes (defined by SSH protocol) */
-#define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT          1
-#define SSH_DISCONNECT_PROTOCOL_ERROR                       2
-#define SSH_DISCONNECT_KEY_EXCHANGE_FAILED                  3
-#define SSH_DISCONNECT_RESERVED                             4
-#define SSH_DISCONNECT_MAC_ERROR                            5
-#define SSH_DISCONNECT_COMPRESSION_ERROR                    6
-#define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE                7
-#define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED       8
-#define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE              9
-#define SSH_DISCONNECT_CONNECTION_LOST                      10
-#define SSH_DISCONNECT_BY_APPLICATION                       11
-#define SSH_DISCONNECT_TOO_MANY_CONNECTIONS                 12
-#define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER               13
-#define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE       14
-#define SSH_DISCONNECT_ILLEGAL_USER_NAME                    15
-
-/* Error Codes (defined by libssh2) */
-#define LIBSSH2_ERROR_NONE                      0
-
-/* The library once used -1 as a generic error return value on numerous places
-   through the code, which subsequently was converted to
-   LIBSSH2_ERROR_SOCKET_NONE uses over time. As this is a generic error code,
-   the goal is to never ever return this code but instead make sure that a
-   more accurate and descriptive error code is used. */
-#define LIBSSH2_ERROR_SOCKET_NONE               -1
-
-#define LIBSSH2_ERROR_BANNER_RECV               -2
-#define LIBSSH2_ERROR_BANNER_SEND               -3
-#define LIBSSH2_ERROR_INVALID_MAC               -4
-#define LIBSSH2_ERROR_KEX_FAILURE               -5
-#define LIBSSH2_ERROR_ALLOC                     -6
-#define LIBSSH2_ERROR_SOCKET_SEND               -7
-#define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE      -8
-#define LIBSSH2_ERROR_TIMEOUT                   -9
-#define LIBSSH2_ERROR_HOSTKEY_INIT              -10
-#define LIBSSH2_ERROR_HOSTKEY_SIGN              -11
-#define LIBSSH2_ERROR_DECRYPT                   -12
-#define LIBSSH2_ERROR_SOCKET_DISCONNECT         -13
-#define LIBSSH2_ERROR_PROTO                     -14
-#define LIBSSH2_ERROR_PASSWORD_EXPIRED          -15
-#define LIBSSH2_ERROR_FILE                      -16
-#define LIBSSH2_ERROR_METHOD_NONE               -17
-#define LIBSSH2_ERROR_AUTHENTICATION_FAILED     -18
-#define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED    LIBSSH2_ERROR_AUTHENTICATION_FAILED
-#define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED      -19
-#define LIBSSH2_ERROR_CHANNEL_OUTOFORDER        -20
-#define LIBSSH2_ERROR_CHANNEL_FAILURE           -21
-#define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED    -22
-#define LIBSSH2_ERROR_CHANNEL_UNKNOWN           -23
-#define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED   -24
-#define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED   -25
-#define LIBSSH2_ERROR_CHANNEL_CLOSED            -26
-#define LIBSSH2_ERROR_CHANNEL_EOF_SENT          -27
-#define LIBSSH2_ERROR_SCP_PROTOCOL              -28
-#define LIBSSH2_ERROR_ZLIB                      -29
-#define LIBSSH2_ERROR_SOCKET_TIMEOUT            -30
-#define LIBSSH2_ERROR_SFTP_PROTOCOL             -31
-#define LIBSSH2_ERROR_REQUEST_DENIED            -32
-#define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED      -33
-#define LIBSSH2_ERROR_INVAL                     -34
-#define LIBSSH2_ERROR_INVALID_POLL_TYPE         -35
-#define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL        -36
-#define LIBSSH2_ERROR_EAGAIN                    -37
-#define LIBSSH2_ERROR_BUFFER_TOO_SMALL          -38
-#define LIBSSH2_ERROR_BAD_USE                   -39
-#define LIBSSH2_ERROR_COMPRESS                  -40
-#define LIBSSH2_ERROR_OUT_OF_BOUNDARY           -41
-#define LIBSSH2_ERROR_AGENT_PROTOCOL            -42
-#define LIBSSH2_ERROR_SOCKET_RECV               -43
-#define LIBSSH2_ERROR_ENCRYPT                   -44
-#define LIBSSH2_ERROR_BAD_SOCKET                -45
-#define LIBSSH2_ERROR_KNOWN_HOSTS               -46
-
-/* this is a define to provide the old (<= 1.2.7) name */
-#define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV
-
-/* Global API */
-#define LIBSSH2_INIT_NO_CRYPTO        0x0001
-
-/*
- * libssh2_init()
- *
- * Initialize the libssh2 functions.  This typically initialize the
- * crypto library.  It uses a global state, and is not thread safe --
- * you must make sure this function is not called concurrently.
- *
- * Flags can be:
- * 0:                              Normal initialize
- * LIBSSH2_INIT_NO_CRYPTO:         Do not initialize the crypto library (ie.
- *                                 OPENSSL_add_cipher_algoritms() for OpenSSL
- *
- * Returns 0 if succeeded, or a negative value for error.
- */
-LIBSSH2_API int libssh2_init(int flags);
-
-/*
- * libssh2_exit()
- *
- * Exit the libssh2 functions and free's all memory used internal.
- */
-LIBSSH2_API void libssh2_exit(void);
-
-/*
- * libssh2_free()
- *
- * Deallocate memory allocated by earlier call to libssh2 functions.
- */
-LIBSSH2_API void libssh2_free(LIBSSH2_SESSION *session, void *ptr);
-
-/*
- * libssh2_session_supported_algs()
- *
- * Fills algs with a list of supported acryptographic algorithms. Returns a
- * non-negative number (number of supported algorithms) on success or a
- * negative number (an eror code) on failure.
- *
- * NOTE: on success, algs must be deallocated (by calling libssh2_free) when
- * not needed anymore
- */
-LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
-                                               int method_type,
-                                               const char*** algs);
-
-/* Session API */
-LIBSSH2_API LIBSSH2_SESSION *
-libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
-                        LIBSSH2_FREE_FUNC((*my_free)),
-                        LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract);
-#define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL)
-
-LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session);
-
-LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session,
-                                               int cbtype, void *callback);
-LIBSSH2_API int libssh2_session_banner_set(LIBSSH2_SESSION *session,
-                                           const char *banner);
-LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session,
-                                   const char *banner);
-
-LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int sock);
-LIBSSH2_API int libssh2_session_handshake(LIBSSH2_SESSION *session,
-                                          libssh2_socket_t sock);
-LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session,
-                                              int reason,
-                                              const char *description,
-                                              const char *lang);
-#define libssh2_session_disconnect(session, description) \
-  libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, \
-                                (description), "")
-
-LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session);
-
-LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session,
-                                             int hash_type);
-
-LIBSSH2_API const char *libssh2_session_hostkey(LIBSSH2_SESSION *session,
-                                                size_t *len, int *type);
-
-LIBSSH2_API int libssh2_session_method_pref(LIBSSH2_SESSION *session,
-                                            int method_type,
-                                            const char *prefs);
-LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session,
-                                                int method_type);
-LIBSSH2_API int libssh2_session_last_error(LIBSSH2_SESSION *session,
-                                           char **errmsg,
-                                           int *errmsg_len, int want_buf);
-LIBSSH2_API int libssh2_session_last_errno(LIBSSH2_SESSION *session);
-LIBSSH2_API int libssh2_session_block_directions(LIBSSH2_SESSION *session);
-
-LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag,
-                                     int value);
-LIBSSH2_API const char *libssh2_session_banner_get(LIBSSH2_SESSION *session);
-
-/* Userauth API */
-LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session,
-                                        const char *username,
-                                        unsigned int username_len);
-LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);
-
-LIBSSH2_API int libssh2_userauth_password_ex(LIBSSH2_SESSION *session,
-                                             const char *username,
-                                             unsigned int username_len,
-                                             const char *password,
-                                             unsigned int password_len,
-                                             LIBSSH2_PASSWD_CHANGEREQ_FUNC((*passwd_change_cb)));
-
-#define libssh2_userauth_password(session, username, password) \
- libssh2_userauth_password_ex((session), (username),           \
-                              (unsigned int)strlen(username),  \
-                              (password), (unsigned int)strlen(password), NULL)
-
-LIBSSH2_API int
-libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
-                                       const char *username,
-                                       unsigned int username_len,
-                                       const char *publickey,
-                                       const char *privatekey,
-                                       const char *passphrase);
-
-#define libssh2_userauth_publickey_fromfile(session, username, publickey, \
-                                            privatekey, passphrase)     \
-    libssh2_userauth_publickey_fromfile_ex((session), (username),       \
-                                           (unsigned int)strlen(username), \
-                                           (publickey),                 \
-                                           (privatekey), (passphrase))
-
-LIBSSH2_API int
-libssh2_userauth_publickey(LIBSSH2_SESSION *session,
-                           const char *username,
-                           const unsigned char *pubkeydata,
-                           size_t pubkeydata_len,
-                           LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC((*sign_callback)),
-                           void **abstract);
-
-LIBSSH2_API int
-libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session,
-                                       const char *username,
-                                       unsigned int username_len,
-                                       const char *publickey,
-                                       const char *privatekey,
-                                       const char *passphrase,
-                                       const char *hostname,
-                                       unsigned int hostname_len,
-                                       const char *local_username,
-                                       unsigned int local_username_len);
-
-#define libssh2_userauth_hostbased_fromfile(session, username, publickey, \
-                                            privatekey, passphrase, hostname) \
- libssh2_userauth_hostbased_fromfile_ex((session), (username), \
-                                        (unsigned int)strlen(username), \
-                                        (publickey),                    \
-                                        (privatekey), (passphrase),     \
-                                        (hostname),                     \
-                                        (unsigned int)strlen(hostname), \
-                                        (username),                     \
-                                        (unsigned int)strlen(username))
-
-/*
- * response_callback is provided with filled by library prompts array,
- * but client must allocate and fill individual responses. Responses
- * array is already allocated. Responses data will be freed by libssh2
- * after callback return, but before subsequent callback invokation.
- */
-LIBSSH2_API int
-libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session,
-                                         const char *username,
-                                         unsigned int username_len,
-                                         LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC((*response_callback)));
-
-#define libssh2_userauth_keyboard_interactive(session, username,        \
-                                              response_callback)        \
-    libssh2_userauth_keyboard_interactive_ex((session), (username),     \
-                                             (unsigned int)strlen(username), \
-                                             (response_callback))
-
-LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds,
-                             long timeout);
-
-/* Channel API */
-#define LIBSSH2_CHANNEL_WINDOW_DEFAULT  (2*1024*1024)
-#define LIBSSH2_CHANNEL_PACKET_DEFAULT  32768
-#define LIBSSH2_CHANNEL_MINADJUST       1024
-
-/* Extended Data Handling */
-#define LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL        0
-#define LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE        1
-#define LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE         2
-
-#define SSH_EXTENDED_DATA_STDERR 1
-
-/* Returned by any function that would block during a read/write opperation */
-#define LIBSSH2CHANNEL_EAGAIN LIBSSH2_ERROR_EAGAIN
-
-LIBSSH2_API LIBSSH2_CHANNEL *
-libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type,
-                        unsigned int channel_type_len,
-                        unsigned int window_size, unsigned int packet_size,
-                        const char *message, unsigned int message_len);
-
-#define libssh2_channel_open_session(session) \
-  libssh2_channel_open_ex((session), "session", sizeof("session") - 1, \
-                          LIBSSH2_CHANNEL_WINDOW_DEFAULT, \
-                          LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0)
-
-LIBSSH2_API LIBSSH2_CHANNEL *
-libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host,
-                                int port, const char *shost, int sport);
-#define libssh2_channel_direct_tcpip(session, host, port) \
-  libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22)
-
-LIBSSH2_API LIBSSH2_LISTENER *
-libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host,
-                                  int port, int *bound_port, int queue_maxsize);
-#define libssh2_channel_forward_listen(session, port) \
- libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16)
-
-LIBSSH2_API int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
-
-LIBSSH2_API LIBSSH2_CHANNEL *
-libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener);
-
-LIBSSH2_API int libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel,
-                                          const char *varname,
-                                          unsigned int varname_len,
-                                          const char *value,
-                                          unsigned int value_len);
-
-#define libssh2_channel_setenv(channel, varname, value)                 \
-    libssh2_channel_setenv_ex((channel), (varname),                     \
-                              (unsigned int)strlen(varname), (value),   \
-                              (unsigned int)strlen(value))
-
-LIBSSH2_API int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel,
-                                               const char *term,
-                                               unsigned int term_len,
-                                               const char *modes,
-                                               unsigned int modes_len,
-                                               int width, int height,
-                                               int width_px, int height_px);
-#define libssh2_channel_request_pty(channel, term)                      \
-    libssh2_channel_request_pty_ex((channel), (term),                   \
-                                   (unsigned int)strlen(term),          \
-                                   NULL, 0,                             \
-                                   LIBSSH2_TERM_WIDTH, LIBSSH2_TERM_HEIGHT, \
-                                   LIBSSH2_TERM_WIDTH_PX, LIBSSH2_TERM_HEIGHT_PX)
-
-LIBSSH2_API int libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL *channel,
-                                                    int width, int height,
-                                                    int width_px,
-                                                    int height_px);
-#define libssh2_channel_request_pty_size(channel, width, height) \
-  libssh2_channel_request_pty_size_ex( (channel), (width), (height), 0, 0)
-
-LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel,
-                                           int single_connection,
-                                           const char *auth_proto,
-                                           const char *auth_cookie,
-                                           int screen_number);
-#define libssh2_channel_x11_req(channel, screen_number) \
- libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number))
-
-LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
-                                                const char *request,
-                                                unsigned int request_len,
-                                                const char *message,
-                                                unsigned int message_len);
-#define libssh2_channel_shell(channel) \
-  libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, \
-                                  NULL, 0)
-#define libssh2_channel_exec(channel, command) \
-  libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, \
-                                  (command), (unsigned int)strlen(command))
-#define libssh2_channel_subsystem(channel, subsystem) \
-  libssh2_channel_process_startup((channel), "subsystem",              \
-                                  sizeof("subsystem") - 1, (subsystem), \
-                                  (unsigned int)strlen(subsystem))
-
-LIBSSH2_API ssize_t libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel,
-                                            int stream_id, char *buf,
-                                            size_t buflen);
-#define libssh2_channel_read(channel, buf, buflen) \
-  libssh2_channel_read_ex((channel), 0, (buf), (buflen))
-#define libssh2_channel_read_stderr(channel, buf, buflen) \
-  libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
-
-LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel,
-                                          int extended);
-
-LIBSSH2_API unsigned long
-libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
-                               unsigned long *read_avail,
-                               unsigned long *window_size_initial);
-#define libssh2_channel_window_read(channel) \
-  libssh2_channel_window_read_ex((channel), NULL, NULL)
-
-/* libssh2_channel_receive_window_adjust is DEPRECATED, do not use! */
-LIBSSH2_API unsigned long
-libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
-                                      unsigned long adjustment,
-                                      unsigned char force);
-
-LIBSSH2_API int
-libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel,
-                                       unsigned long adjustment,
-                                       unsigned char force,
-                                       unsigned int *storewindow);
-
-LIBSSH2_API ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
-                                             int stream_id, const char *buf,
-                                             size_t buflen);
-
-#define libssh2_channel_write(channel, buf, buflen) \
-  libssh2_channel_write_ex((channel), 0, (buf), (buflen))
-#define libssh2_channel_write_stderr(channel, buf, buflen)  \
-  libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
-
-LIBSSH2_API unsigned long
-libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel,
-                                unsigned long *window_size_initial);
-#define libssh2_channel_window_write(channel) \
-  libssh2_channel_window_write_ex((channel), NULL)
-
-LIBSSH2_API void libssh2_session_set_blocking(LIBSSH2_SESSION* session,
-                                              int blocking);
-LIBSSH2_API int libssh2_session_get_blocking(LIBSSH2_SESSION* session);
-
-LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel,
-                                              int blocking);
-
-LIBSSH2_API void libssh2_session_set_timeout(LIBSSH2_SESSION* session,
-                                             long timeout);
-LIBSSH2_API long libssh2_session_get_timeout(LIBSSH2_SESSION* session);
-
-/* libssh2_channel_handle_extended_data is DEPRECATED, do not use! */
-LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel,
-                                                      int ignore_mode);
-LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel,
-                                                      int ignore_mode);
-
-/* libssh2_channel_ignore_extended_data() is defined below for BC with version
- * 0.1
- *
- * Future uses should use libssh2_channel_handle_extended_data() directly if
- * LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read
- * (FIFO) from the standard data channel
- */
-/* DEPRECATED */
-#define libssh2_channel_ignore_extended_data(channel, ignore) \
-  libssh2_channel_handle_extended_data((channel),                       \
-                                       (ignore) ?                       \
-                                       LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : \
-                                       LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL )
-
-#define LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA     -1
-#define LIBSSH2_CHANNEL_FLUSH_ALL               -2
-LIBSSH2_API int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel,
-                                         int streamid);
-#define libssh2_channel_flush(channel) libssh2_channel_flush_ex((channel), 0)
-#define libssh2_channel_flush_stderr(channel) \
- libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR)
-
-LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel);
-LIBSSH2_API int libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL* channel,
-                                                char **exitsignal,
-                                                size_t *exitsignal_len,
-                                                char **errmsg,
-                                                size_t *errmsg_len,
-                                                char **langtag,
-                                                size_t *langtag_len);
-LIBSSH2_API int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel);
-LIBSSH2_API int libssh2_channel_eof(LIBSSH2_CHANNEL *channel);
-LIBSSH2_API int libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel);
-LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel);
-LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel);
-LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel);
-
-LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
-                                              const char *path,
-                                              struct stat *sb);
-LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session,
-                                                 const char *path, int mode,
-                                                 size_t size, long mtime,
-                                                 long atime);
-LIBSSH2_API LIBSSH2_CHANNEL *
-libssh2_scp_send64(LIBSSH2_SESSION *session, const char *path, int mode,
-                   libssh2_int64_t size, time_t mtime, time_t atime);
-
-#define libssh2_scp_send(session, path, mode, size) \
-  libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0)
-
-LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest,
-                                      unsigned int *dest_len,
-                                      const char *src, unsigned int src_len);
-
-LIBSSH2_API
-const char *libssh2_version(int req_version_num);
-
-#define HAVE_LIBSSH2_KNOWNHOST_API 0x010101 /* since 1.1.1 */
-#define HAVE_LIBSSH2_VERSION_API   0x010100 /* libssh2_version since 1.1 */
-
-struct libssh2_knownhost {
-    unsigned int magic;  /* magic stored by the library */
-    void *node; /* handle to the internal representation of this host */
-    char *name; /* this is NULL if no plain text host name exists */
-    char *key;  /* key in base64/printable format */
-    int typemask;
-};
-
-/*
- * libssh2_knownhost_init
- *
- * Init a collection of known hosts. Returns the pointer to a collection.
- *
- */
-LIBSSH2_API LIBSSH2_KNOWNHOSTS *
-libssh2_knownhost_init(LIBSSH2_SESSION *session);
-
-/*
- * libssh2_knownhost_add
- *
- * Add a host and its associated key to the collection of known hosts.
- *
- * The 'type' argument specifies on what format the given host and keys are:
- *
- * plain  - ascii "hostname.domain.tld"
- * sha1   - SHA1(<salt> <host>) base64-encoded!
- * custom - another hash
- *
- * If 'sha1' is selected as type, the salt must be provided to the salt
- * argument. This too base64 encoded.
- *
- * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files.  If
- * a custom type is used, salt is ignored and you must provide the host
- * pre-hashed when checking for it in the libssh2_knownhost_check() function.
- *
- * The keylen parameter may be omitted (zero) if the key is provided as a
- * NULL-terminated base64-encoded string.
- */
-
-/* host format (2 bits) */
-#define LIBSSH2_KNOWNHOST_TYPE_MASK    0xffff
-#define LIBSSH2_KNOWNHOST_TYPE_PLAIN   1
-#define LIBSSH2_KNOWNHOST_TYPE_SHA1    2 /* always base64 encoded */
-#define LIBSSH2_KNOWNHOST_TYPE_CUSTOM  3
-
-/* key format (2 bits) */
-#define LIBSSH2_KNOWNHOST_KEYENC_MASK     (3<<16)
-#define LIBSSH2_KNOWNHOST_KEYENC_RAW      (1<<16)
-#define LIBSSH2_KNOWNHOST_KEYENC_BASE64   (2<<16)
-
-/* type of key (2 bits) */
-#define LIBSSH2_KNOWNHOST_KEY_MASK     (7<<18)
-#define LIBSSH2_KNOWNHOST_KEY_SHIFT    18
-#define LIBSSH2_KNOWNHOST_KEY_RSA1     (1<<18)
-#define LIBSSH2_KNOWNHOST_KEY_SSHRSA   (2<<18)
-#define LIBSSH2_KNOWNHOST_KEY_SSHDSS   (3<<18)
-#define LIBSSH2_KNOWNHOST_KEY_UNKNOWN  (7<<18)
-
-LIBSSH2_API int
-libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
-                      const char *host,
-                      const char *salt,
-                      const char *key, size_t keylen, int typemask,
-                      struct libssh2_knownhost **store);
-
-/*
- * libssh2_knownhost_addc
- *
- * Add a host and its associated key to the collection of known hosts.
- *
- * Takes a comment argument that may be NULL.  A NULL comment indicates
- * there is no comment and the entry will end directly after the key
- * when written out to a file.  An empty string "" comment will indicate an
- * empty comment which will cause a single space to be written after the key.
- *
- * The 'type' argument specifies on what format the given host and keys are:
- *
- * plain  - ascii "hostname.domain.tld"
- * sha1   - SHA1(<salt> <host>) base64-encoded!
- * custom - another hash
- *
- * If 'sha1' is selected as type, the salt must be provided to the salt
- * argument. This too base64 encoded.
- *
- * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files.  If
- * a custom type is used, salt is ignored and you must provide the host
- * pre-hashed when checking for it in the libssh2_knownhost_check() function.
- *
- * The keylen parameter may be omitted (zero) if the key is provided as a
- * NULL-terminated base64-encoded string.
- */
-
-LIBSSH2_API int
-libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts,
-                       const char *host,
-                       const char *salt,
-                       const char *key, size_t keylen,
-                       const char *comment, size_t commentlen, int typemask,
-                       struct libssh2_knownhost **store);
-
-/*
- * libssh2_knownhost_check
- *
- * Check a host and its associated key against the collection of known hosts.
- *
- * The type is the type/format of the given host name.
- *
- * plain  - ascii "hostname.domain.tld"
- * custom - prehashed base64 encoded. Note that this cannot use any salts.
- *
- *
- * 'knownhost' may be set to NULL if you don't care about that info.
- *
- * Returns:
- *
- * LIBSSH2_KNOWNHOST_CHECK_* values, see below
- *
- */
-
-#define LIBSSH2_KNOWNHOST_CHECK_MATCH    0
-#define LIBSSH2_KNOWNHOST_CHECK_MISMATCH 1
-#define LIBSSH2_KNOWNHOST_CHECK_NOTFOUND 2
-#define LIBSSH2_KNOWNHOST_CHECK_FAILURE  3
-
-LIBSSH2_API int
-libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
-                        const char *host, const char *key, size_t keylen,
-                        int typemask,
-                        struct libssh2_knownhost **knownhost);
-
-/* this function is identital to the above one, but also takes a port
-   argument that allows libssh2 to do a better check */
-LIBSSH2_API int
-libssh2_knownhost_checkp(LIBSSH2_KNOWNHOSTS *hosts,
-                         const char *host, int port,
-                         const char *key, size_t keylen,
-                         int typemask,
-                         struct libssh2_knownhost **knownhost);
-
-/*
- * libssh2_knownhost_del
- *
- * Remove a host from the collection of known hosts. The 'entry' struct is
- * retrieved by a call to libssh2_knownhost_check().
- *
- */
-LIBSSH2_API int
-libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts,
-                      struct libssh2_knownhost *entry);
-
-/*
- * libssh2_knownhost_free
- *
- * Free an entire collection of known hosts.
- *
- */
-LIBSSH2_API void
-libssh2_knownhost_free(LIBSSH2_KNOWNHOSTS *hosts);
-
-/*
- * libssh2_knownhost_readline()
- *
- * Pass in a line of a file of 'type'. It makes libssh2 read this line.
- *
- * LIBSSH2_KNOWNHOST_FILE_OPENSSH is the only supported type.
- *
- */
-LIBSSH2_API int
-libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
-                           const char *line, size_t len, int type);
-
-/*
- * libssh2_knownhost_readfile
- *
- * Add hosts+key pairs from a given file.
- *
- * Returns a negative value for error or number of successfully added hosts.
- *
- * This implementation currently only knows one 'type' (openssh), all others
- * are reserved for future use.
- */
-
-#define LIBSSH2_KNOWNHOST_FILE_OPENSSH 1
-
-LIBSSH2_API int
-libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
-                           const char *filename, int type);
-
-/*
- * libssh2_knownhost_writeline()
- *
- * Ask libssh2 to convert a known host to an output line for storage.
- *
- * Note that this function returns LIBSSH2_ERROR_BUFFER_TOO_SMALL if the given
- * output buffer is too small to hold the desired output.
- *
- * This implementation currently only knows one 'type' (openssh), all others
- * are reserved for future use.
- *
- */
-LIBSSH2_API int
-libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
-                            struct libssh2_knownhost *known,
-                            char *buffer, size_t buflen,
-                            size_t *outlen, /* the amount of written data */
-                            int type);
-
-/*
- * libssh2_knownhost_writefile
- *
- * Write hosts+key pairs to a given file.
- *
- * This implementation currently only knows one 'type' (openssh), all others
- * are reserved for future use.
- */
-
-LIBSSH2_API int
-libssh2_knownhost_writefile(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);
-
-#define HAVE_LIBSSH2_AGENT_API 0x010202 /* since 1.2.2 */
-
-struct libssh2_agent_publickey {
-    unsigned int magic;              /* magic stored by the library */
-    void *node;     /* handle to the internal representation of key */
-    unsigned char *blob;           /* public key blob */
-    size_t blob_len;               /* length of the public key blob */
-    char *comment;                 /* comment in printable format */
-};
-
-/*
- * libssh2_agent_init
- *
- * Init an ssh-agent handle. Returns the pointer to the handle.
- *
- */
-LIBSSH2_API LIBSSH2_AGENT *
-libssh2_agent_init(LIBSSH2_SESSION *session);
-
-/*
- * libssh2_agent_connect()
- *
- * Connect to an ssh-agent.
- *
- * Returns 0 if succeeded, or a negative value for error.
- */
-LIBSSH2_API int
-libssh2_agent_connect(LIBSSH2_AGENT *agent);
-
-/*
- * libssh2_agent_list_identities()
- *
- * Request an ssh-agent to list identities.
- *
- * Returns 0 if succeeded, or a negative value for error.
- */
-LIBSSH2_API int
-libssh2_agent_list_identities(LIBSSH2_AGENT *agent);
-
-/*
- * libssh2_agent_get_identity()
- *
- * Traverse the internal list of public keys. 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 public key was stored in 'store'
- * 1 if end of public keys
- * [negative] on errors
- */
-LIBSSH2_API int
-libssh2_agent_get_identity(LIBSSH2_AGENT *agent,
-               struct libssh2_agent_publickey **store,
-               struct libssh2_agent_publickey *prev);
-
-/*
- * libssh2_agent_userauth()
- *
- * Do publickey user authentication with the help of ssh-agent.
- *
- * Returns 0 if succeeded, or a negative value for error.
- */
-LIBSSH2_API int
-libssh2_agent_userauth(LIBSSH2_AGENT *agent,
-               const char *username,
-               struct libssh2_agent_publickey *identity);
-
-/*
- * libssh2_agent_disconnect()
- *
- * Close a connection to an ssh-agent.
- *
- * Returns 0 if succeeded, or a negative value for error.
- */
-LIBSSH2_API int
-libssh2_agent_disconnect(LIBSSH2_AGENT *agent);
-
-/*
- * libssh2_agent_free()
- *
- * Free an ssh-agent handle.  This function also frees the internal
- * collection of public keys.
- */
-LIBSSH2_API void
-libssh2_agent_free(LIBSSH2_AGENT *agent);
-
-
-/*
- * libssh2_keepalive_config()
- *
- * Set how often keepalive messages should be sent.  WANT_REPLY
- * indicates whether the keepalive messages should request a response
- * from the server.  INTERVAL is number of seconds that can pass
- * without any I/O, use 0 (the default) to disable keepalives.  To
- * avoid some busy-loop corner-cases, if you specify an interval of 1
- * it will be treated as 2.
- *
- * Note that non-blocking applications are responsible for sending the
- * keepalive messages using libssh2_keepalive_send().
- */
-LIBSSH2_API void libssh2_keepalive_config (LIBSSH2_SESSION *session,
-                                           int want_reply,
-                                           unsigned interval);
-
-/*
- * libssh2_keepalive_send()
- *
- * Send a keepalive message if needed.  SECONDS_TO_NEXT indicates how
- * many seconds you can sleep after this call before you need to call
- * it again.  Returns 0 on success, or LIBSSH2_ERROR_SOCKET_SEND on
- * I/O errors.
- */
-LIBSSH2_API int libssh2_keepalive_send (LIBSSH2_SESSION *session,
-                                        int *seconds_to_next);
-
-/* NOTE NOTE NOTE
-   libssh2_trace() has no function in builds that aren't built with debug
-   enabled
- */
-LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask);
-#define LIBSSH2_TRACE_TRANS (1<<1)
-#define LIBSSH2_TRACE_KEX   (1<<2)
-#define LIBSSH2_TRACE_AUTH  (1<<3)
-#define LIBSSH2_TRACE_CONN  (1<<4)
-#define LIBSSH2_TRACE_SCP   (1<<5)
-#define LIBSSH2_TRACE_SFTP  (1<<6)
-#define LIBSSH2_TRACE_ERROR (1<<7)
-#define LIBSSH2_TRACE_PUBLICKEY (1<<8)
-#define LIBSSH2_TRACE_SOCKET (1<<9)
-
-typedef void (*libssh2_trace_handler_func)(LIBSSH2_SESSION*,
-                                           void*,
-                                           const char *,
-                                           size_t);
-LIBSSH2_API int libssh2_trace_sethandler(LIBSSH2_SESSION *session,
-                                         void* context,
-                                         libssh2_trace_handler_func callback);
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* !RC_INVOKED */
-
-#endif /* LIBSSH2_H */
-- 
2.1.0


From 14c8d3985b5ec1bba0557c4efbcaf1f56be5db52 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Mon, 29 Sep 2014 22:48:22 +0100
Subject: [PATCH 23/47] Fixed missing include directory.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 CMakeLists.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a0148a1..7f5e51e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -72,6 +72,8 @@ install(
   FILES AUTHORS COPYING HACKING README RELEASE-NOTES NEWS
   DESTINATION .)
 
+include_directories(include)
+
 install(FILES
   include/libssh2.h
   include/libssh2_publickey.h
-- 
2.1.0


From 9a37bb00b5b0739932a4154c2a4285c41c8a10e1 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Tue, 30 Sep 2014 08:31:26 +0100
Subject: [PATCH 24/47] Output detailed failure information if tests fail in
 Travis CI.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index f29ba8d..bd2e635 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -37,5 +37,5 @@ install:
 script:
   - cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION ..
   - cmake --build .
-  - cmake --build . --target test
+  - CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --target test
   - cmake --build . --target package
-- 
2.1.0


From 8227bf0cf1fe7486728bd8ad909fa3fc55c9ab0b Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Tue, 30 Sep 2014 08:33:57 +0100
Subject: [PATCH 25/47] Abort Travis CI build on first failure.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 .travis.yml | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index bd2e635..2cdfe7a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -35,7 +35,4 @@ install:
   - cd bin
 
 script:
-  - cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION ..
-  - cmake --build .
-  - CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --target test
-  - cmake --build . --target package
+  - cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. && cmake --build . && CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --target test && cmake --build . --target package
-- 
2.1.0


From 348e992ac86de222638c7eba36c6335d166a2069 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Tue, 30 Sep 2014 08:53:50 +0100
Subject: [PATCH 26/47] Use CMake 'usage requirements' to propagate
 requirements between targets.

Limits their scope which helps prevent requirements pollution.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 CMakeLists.txt         |   8 --
 example/CMakeLists.txt |   5 +-
 src/CMakeLists.txt     | 210 ++++++++++++++++++++++++++-----------------------
 tests/CMakeLists.txt   |   4 +-
 4 files changed, 117 insertions(+), 110 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7f5e51e..9e215ad 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -72,14 +72,6 @@ install(
   FILES AUTHORS COPYING HACKING README RELEASE-NOTES NEWS
   DESTINATION .)
 
-include_directories(include)
-
-install(FILES
-  include/libssh2.h
-  include/libssh2_publickey.h
-  include/libssh2_sftp.h
-  DESTINATION include)
-
 enable_testing()
 
 include(max_warnings)
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index 5d04268..f8438b4 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -64,7 +64,9 @@ set(EXAMPLES
 
 foreach(example ${EXAMPLES})
   add_executable(example-${example} ${example}.c)
-  target_link_libraries(example-${example} ssh2)
+  # to find generated header
+  target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+  target_link_libraries(example-${example} PRIVATE ssh2)
   copy_to_target_runtime_directory(example-${example} ${RUNTIME_DEPENDENCIES})
 endforeach()
 
@@ -90,4 +92,3 @@ check_symbol_exists(__FUNCTION__ "" HAVE___FUNCTION__)
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config.h.in
   ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h)
-include_directories(${CMAKE_CURRENT_BINARY_DIR}) # to find generated header
\ No newline at end of file
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b852092..9e70268 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -39,58 +39,6 @@ include(CheckIncludeFiles)
 include(CheckTypeSize)
 include(CheckNonblockingSocketSupport)
 
-## Options
-
-add_feature_info("Shared library" BUILD_SHARED_LIBS
-  "creating libssh2 as a shared library (.so/.dll)")
-
-option(ENABLE_ZLIB_COMPRESSION "Use zlib for compression")
-add_feature_info(Compression ENABLE_ZLIB_COMPRESSION
-  "using zlib for compression")
-if(ENABLE_ZLIB_COMPRESSION)
-  find_package(ZLIB REQUIRED)
-
-  include_directories(${ZLIB_INCLUDE_DIRS})
-  list(APPEND LIBRARIES ${ZLIB_LIBRARIES})
-  if(ZLIB_FOUND)
-    add_definitions(-DLIBSSH2_HAVE_ZLIB=1)
-  endif()
-endif()
-
-option(ENABLE_CRYPT_NONE "Permit \"none\" cipher -- NOT RECOMMENDED")
-add_feature_info("\"none\" cipher" ENABLE_CRYPT_NONE "")
-if(ENABLE_CRYPT_NONE)
-  add_definitions(-DLIBSSH2_CRYPT_NONE=1)
-endif()
-
-option(ENABLE_MAC_NONE "Permit \"none\" MAC -- NOT RECOMMMENDED")
-add_feature_info("\"none\" MAC" ENABLE_MAC_NONE "")
-if(ENABLE_MAC_NONE)
-  add_definitions(-DLIBSSH2_MAC_NONE=1)
-endif()
-
-option(ENABLE_GEX_NEW
-  "Enable diffie-hellman-group-exchange-sha1 method" ON)
-add_feature_info("diffie-hellman-group-exchange-sha1" ENABLE_GEX_NEW
-  "\"new\" diffie-hellman-group-exchange-sha1 method")
-if(ENABLE_GEX_NEW)
-  add_definitions(-DLIBSSH2_DH_GEX_NEW=1)
-endif()
-
-# Enable debugging logging by default if the user configured a debug build
-if(CMAKE_BUILD_TYPE STREQUAL "Debug")
-  set(DEBUG_LOGGING_DEFAULT ON)
-else()
-  set(DEBUG_LOGGING_DEFAULT OFF)
-endif()
-option(ENABLE_DEBUG_LOGGING "log execution with debug trace"
-  ${DEBUG_LOGGING_DEFAULT})
-add_feature_info(Logging ENABLE_DEBUG_LOGGING
-   "Logging of execution with debug trace")
-if(ENABLE_DEBUG_LOGGING)
-  add_definitions(-DLIBSSH2DEBUG)
-endif()
-
 ## Cryptography backend choice
 
 set(CRYPTO_BACKEND
@@ -114,9 +62,8 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
   if(OPENSSL_FOUND)
     set(CRYPTO_BACKEND "OpenSSL")
     set(CRYPTO_SOURCES openssl.c openssl.h)
-    add_definitions(-DLIBSSH2_OPENSSL)
-
-    include_directories(${OPENSSL_INCLUDE_DIR})
+    list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_OPENSSL)
+    list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
     list(APPEND LIBRARIES ${OPENSSL_LIBRARIES})
 
     if (WIN32)
@@ -158,9 +105,8 @@ if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND)
   if(LIBGCRYPT_FOUND)
     set(CRYPTO_BACKEND "Libgcrypt")
     set(CRYPTO_SOURCES libgcrypt.c libgcrypt.h)
-    add_definitions(-DLIBSSH2_LIBGCRYPT)
-
-    include_directories(${LIBGCRYPT_INCLUDE_DIRS})
+    list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_LIBGCRYPT)
+    list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${LIBGCRYPT_INCLUDE_DIRS})
     list(APPEND LIBRARIES ${LIBGCRYPT_LIBRARIES})
   endif()
 endif()
@@ -173,7 +119,7 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND)
   if(HAVE_BCRYPT_H)
     set(CRYPTO_BACKEND "WinCNG")
     set(CRYPTO_SOURCES wincng.c wincng.h)
-    add_definitions(-DLIBSSH2_WINCNG)
+    list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_WINCNG)
 
     set(HAVE_LIBCRYPT32 TRUE)
     list(APPEND LIBRARIES bcrypt)
@@ -197,6 +143,102 @@ if(NOT CRYPTO_BACKEND)
   message(FATAL_ERROR "No suitable cryptography backend found.")
 endif()
 
+## Library definition
+
+set(SOURCES
+  ${CRYPTO_SOURCES}
+  agent.c
+  channel.c
+  channel.h
+  comp.c
+  comp.h
+  crypt.c
+  crypto.h
+  global.c
+  hostkey.c
+  keepalive.c
+  kex.c
+  knownhost.c
+  libssh2_priv.h
+  mac.c
+  mac.h
+  misc.c
+  misc.h
+  packet.c
+  packet.h
+  pem.c
+  publickey.c
+  scp.c
+  session.c
+  session.h
+  sftp.c
+  sftp.h
+  transport.c
+  transport.h
+  userauth.c
+  userauth.h
+  version.c)
+
+add_library(ssh2 ${SOURCES})
+target_compile_definitions(ssh2 PRIVATE ${PRIVATE_COMPILE_DEFINITIONS})
+target_include_directories(ssh2
+  PRIVATE ${PRIVATE_INCLUDE_DIRECTORIES}
+  PUBLIC
+    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
+    $<INSTALL_INTERFACE:include>)
+
+## Options
+
+add_feature_info("Shared library" BUILD_SHARED_LIBS
+  "creating libssh2 as a shared library (.so/.dll)")
+
+option(ENABLE_ZLIB_COMPRESSION "Use zlib for compression")
+add_feature_info(Compression ENABLE_ZLIB_COMPRESSION
+  "using zlib for compression")
+if(ENABLE_ZLIB_COMPRESSION)
+  find_package(ZLIB REQUIRED)
+
+  target_include_directories(ssh2 PRIVATE ${ZLIB_INCLUDE_DIRS})
+  list(APPEND LIBRARIES ${ZLIB_LIBRARIES})
+  if(ZLIB_FOUND)
+    target_compile_definitions(ssh2 PRIVATE LIBSSH2_HAVE_ZLIB=1)
+  endif()
+endif()
+
+option(ENABLE_CRYPT_NONE "Permit \"none\" cipher -- NOT RECOMMENDED")
+add_feature_info("\"none\" cipher" ENABLE_CRYPT_NONE "")
+if(ENABLE_CRYPT_NONE)
+  target_compile_definitions(ssh2 PRIVATE LIBSSH2_CRYPT_NONE=1)
+endif()
+
+option(ENABLE_MAC_NONE "Permit \"none\" MAC -- NOT RECOMMMENDED")
+add_feature_info("\"none\" MAC" ENABLE_MAC_NONE "")
+if(ENABLE_MAC_NONE)
+  target_compile_definitions(ssh2 PRIVATE LIBSSH2_MAC_NONE=1)
+endif()
+
+option(ENABLE_GEX_NEW
+  "Enable diffie-hellman-group-exchange-sha1 method" ON)
+add_feature_info("diffie-hellman-group-exchange-sha1" ENABLE_GEX_NEW
+  "\"new\" diffie-hellman-group-exchange-sha1 method")
+if(ENABLE_GEX_NEW)
+  target_compile_definitions(ssh2 PRIVATE LIBSSH2_DH_GEX_NEW=1)
+endif()
+
+# Enable debugging logging by default if the user configured a debug build
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+  set(DEBUG_LOGGING_DEFAULT ON)
+else()
+  set(DEBUG_LOGGING_DEFAULT OFF)
+endif()
+option(ENABLE_DEBUG_LOGGING "log execution with debug trace"
+  ${DEBUG_LOGGING_DEFAULT})
+add_feature_info(Logging ENABLE_DEBUG_LOGGING
+   "Logging of execution with debug trace")
+if(ENABLE_DEBUG_LOGGING)
+  target_compile_definitions(ssh2 PRIVATE LIBSSH2DEBUG)
+endif()
+
 ## Platform checks
 check_include_files(unistd.h HAVE_UNISTD_H)
 check_include_files(inttypes.h HAVE_INTTYPES_H)
@@ -272,55 +314,27 @@ set(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES})
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config.h.in
   ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h)
-include_directories(${CMAKE_CURRENT_BINARY_DIR}) # to find generated header
+# to find generated header
+target_include_directories(ssh2 PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
 
 # Check for the OS.
 # Daniel's note: this should not be necessary and we need to work to
 # get this removed.
 if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
-  add_definitions(-DLIBSSH2_WIN32)
+  target_compile_definitions(ssh2 PRIVATE LIBSSH2_WIN32)
 elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
-  add_definitions(-DLIBSSH2_DARWIN)
+  target_compile_definitions(ssh2 PRIVATE LIBSSH2_DARWIN)
 endif()
 
-## Library definition
+target_link_libraries(ssh2 PRIVATE ${LIBRARIES})
 
-set(SOURCES
-  ${CRYPTO_SOURCES}
-  agent.c
-  channel.c
-  channel.h
-  comp.c
-  comp.h
-  crypt.c
-  crypto.h
-  global.c
-  hostkey.c
-  keepalive.c
-  kex.c
-  knownhost.c
-  libssh2_priv.h
-  mac.c
-  mac.h
-  misc.c
-  misc.h
-  packet.c
-  packet.h
-  pem.c
-  publickey.c
-  scp.c
-  session.c
-  session.h
-  sftp.c
-  sftp.h
-  transport.c
-  transport.h
-  userauth.c
-  userauth.h
-  version.c)
+## Installation
 
-add_library(ssh2 ${SOURCES})
-target_link_libraries(ssh2 ${LIBRARIES})
+install(FILES
+  ${CMAKE_SOURCE_DIR}/include/libssh2.h
+  ${CMAKE_SOURCE_DIR}/include/libssh2_publickey.h
+  ${CMAKE_SOURCE_DIR}/include/libssh2_sftp.h
+  DESTINATION include)
 
 install(TARGETS ssh2
   RUNTIME DESTINATION bin
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b19cee6..7ed368c 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -50,7 +50,6 @@ check_include_files(winsock2.h HAVE_WINSOCK2_H)
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config.h.in
   ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h)
-include_directories(${CMAKE_CURRENT_BINARY_DIR}) # to find generated header
 
 set(TESTS
   simple
@@ -58,7 +57,8 @@ set(TESTS
 
 foreach(test ${TESTS})
   add_executable(test-${test} ${test}.c)
-  target_link_libraries(test-${test} ssh2)
+  target_link_libraries(test-${test} PRIVATE ssh2)
+  target_include_directories(test-${test} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
   copy_to_target_runtime_directory(test-${test} ${RUNTIME_DEPENDENCIES})
 endforeach()
 
-- 
2.1.0


From 89c8a4ccae4e065a184fe9dd1fc4326bba51cd8f Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Tue, 30 Sep 2014 13:23:22 +0100
Subject: [PATCH 27/47] Update minimum CMake version to 2.8.11 for
 `target_compile_definitions`.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 .travis.yml    | 2 ++
 CMakeLists.txt | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 2cdfe7a..de24fc6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -24,7 +24,9 @@ env:
    - ADDRESS_SIZE=32 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
 
 before_install:
+  - sudo add-apt-repository --yes ppa:kalakris/cmake
   - sudo apt-get update
+  - sudo apt-get install cmake
   - if [ $ADDRESS_SIZE = '64' ]; then sudo apt-get install -y libgcrypt11-dev libssl-dev zlib1g-dev; fi
   - if [ $ADDRESS_SIZE = '32' ]; then sudo apt-get install -y linux-libc-dev linux-libc-dev:i386; fi
   - if [ $ADDRESS_SIZE = '32' ]; then sudo apt-get install -y gcc-multilib libgcrypt11-dev:i386 libssl-dev:i386 zlib1g-dev:i386; fi
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e215ad..dffe66c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,7 +33,7 @@
 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 # OF SUCH DAMAGE.
 
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 2.8.11)
 
 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
 
-- 
2.1.0


From fc557bb7b4fa11691210bacfe61a68eee84e0a84 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Tue, 30 Sep 2014 18:53:51 +0100
Subject: [PATCH 28/47] Updated Travis CI to use CMake 3.

The build requires at least 2.8.12 for `target_link_libraries` with `PRIVATE` argument.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 .travis.yml    | 4 ++--
 CMakeLists.txt | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index de24fc6..3aebc28 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -24,9 +24,9 @@ env:
    - ADDRESS_SIZE=32 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
 
 before_install:
-  - sudo add-apt-repository --yes ppa:kalakris/cmake
+  - sudo add-apt-repository --yes ppa:purplekarrot/cmake
   - sudo apt-get update
-  - sudo apt-get install cmake
+  - sudo apt-get -y install cmake
   - if [ $ADDRESS_SIZE = '64' ]; then sudo apt-get install -y libgcrypt11-dev libssl-dev zlib1g-dev; fi
   - if [ $ADDRESS_SIZE = '32' ]; then sudo apt-get install -y linux-libc-dev linux-libc-dev:i386; fi
   - if [ $ADDRESS_SIZE = '32' ]; then sudo apt-get install -y gcc-multilib libgcrypt11-dev:i386 libssl-dev:i386 zlib1g-dev:i386; fi
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dffe66c..d6f348d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,7 +33,7 @@
 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 # OF SUCH DAMAGE.
 
-cmake_minimum_required(VERSION 2.8.11)
+cmake_minimum_required(VERSION 2.8.12)
 
 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
 
-- 
2.1.0


From 574b34fe7fdff961a54850a653e1d775b38fec4b Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Tue, 30 Sep 2014 21:48:41 +0100
Subject: [PATCH 29/47] Make libssh2 support CMake 2.8.11 again.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 .travis.yml            | 2 +-
 CMakeLists.txt         | 2 +-
 example/CMakeLists.txt | 2 +-
 src/CMakeLists.txt     | 7 ++++++-
 tests/CMakeLists.txt   | 2 +-
 5 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 3aebc28..a1213b3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -24,7 +24,7 @@ env:
    - ADDRESS_SIZE=32 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON
 
 before_install:
-  - sudo add-apt-repository --yes ppa:purplekarrot/cmake
+  - sudo add-apt-repository --yes ppa:kalakris/cmake
   - sudo apt-get update
   - sudo apt-get -y install cmake
   - if [ $ADDRESS_SIZE = '64' ]; then sudo apt-get install -y libgcrypt11-dev libssl-dev zlib1g-dev; fi
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d6f348d..dffe66c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,7 +33,7 @@
 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 # OF SUCH DAMAGE.
 
-cmake_minimum_required(VERSION 2.8.12)
+cmake_minimum_required(VERSION 2.8.11)
 
 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
 
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index f8438b4..dd118bb 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -66,7 +66,7 @@ foreach(example ${EXAMPLES})
   add_executable(example-${example} ${example}.c)
   # to find generated header
   target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-  target_link_libraries(example-${example} PRIVATE ssh2)
+  target_link_libraries(example-${example} ssh2)
   copy_to_target_runtime_directory(example-${example} ${RUNTIME_DEPENDENCIES})
 endforeach()
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9e70268..123979b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -326,7 +326,12 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
   target_compile_definitions(ssh2 PRIVATE LIBSSH2_DARWIN)
 endif()
 
-target_link_libraries(ssh2 PRIVATE ${LIBRARIES})
+if(CMAKE_VERSION VERSION_LESS "2.8.12")
+  # Fall back to over-linking dependencies
+  target_link_libraries(ssh2 ${LIBRARIES})
+else()
+  target_link_libraries(ssh2 PRIVATE ${LIBRARIES})
+endif()
 
 ## Installation
 
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 7ed368c..49ee720 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -57,7 +57,7 @@ set(TESTS
 
 foreach(test ${TESTS})
   add_executable(test-${test} ${test}.c)
-  target_link_libraries(test-${test} PRIVATE ssh2)
+  target_link_libraries(test-${test} ssh2)
   target_include_directories(test-${test} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
   copy_to_target_runtime_directory(test-${test} ${RUNTIME_DEPENDENCIES})
 endforeach()
-- 
2.1.0


From c7b8c89bc2521d9d9e10243a8ca85f9c67418878 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Wed, 1 Oct 2014 18:05:29 +0100
Subject: [PATCH 30/47] Prevent conflicts when copying DLLs to binary output
 directories.

Every target was executing command to copy all its dependencies.  If they were running in parallel, these commands could conflict and cause the build to fail.  This change makes sure the dependencies are only copied once for each binary output directory.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 cmake/CopyRuntimeDependencies.cmake | 36 ++++++++++++++++++++++++++++++------
 example/CMakeLists.txt              |  6 +++++-
 tests/CMakeLists.txt                |  7 ++++++-
 3 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/cmake/CopyRuntimeDependencies.cmake b/cmake/CopyRuntimeDependencies.cmake
index 293f9b0..3f1541d 100644
--- a/cmake/CopyRuntimeDependencies.cmake
+++ b/cmake/CopyRuntimeDependencies.cmake
@@ -33,13 +33,37 @@
 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 # OF SUCH DAMAGE.
 
-function(COPY_TO_TARGET_RUNTIME_DIRECTORY target)
-  foreach(dependency ${ARGN})
+include(CMakeParseArguments)
 
-    add_custom_command(TARGET ${target}
-      DEPENDS ${dependency}
-      COMMAND ${CMAKE_COMMAND} -E copy ${dependency}
-      ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
+function(ADD_TARGET_TO_COPY_DEPENDENCIES)
+  set(options)
+  set(oneValueArgs TARGET)
+  set(multiValueArgs DEPENDENCIES BEFORE_TARGETS)
+  cmake_parse_arguments(COPY
+    "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
 
+  # Using a custom target to drive custom commands stops multiple
+  # parallel builds trying to kick off the commands at the same time
+  add_custom_target(${COPY_TARGET} DEPENDS ${COPY_DEPENDENCIES})
+  add_dependencies(${COPY_TARGET} ${COPY_DEPENDENCIES})
+
+  foreach(target ${COPY_BEFORE_TARGETS})
+    add_dependencies(${target} ${COPY_TARGET})
   endforeach()
+
+  foreach(dependency ${COPY_DEPENDENCIES})
+
+    get_filename_component(DEP_NAME ${dependency} NAME)
+    set(RUNTIME_DEP_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${DEP_NAME})
+    list(APPEND RUNTIME_DEPS ${RUNTIME_DEP_PATH})
+
+    add_custom_command(
+      TARGET ${COPY_TARGET}
+      COMMAND ${CMAKE_COMMAND}
+      ARGS -E copy ${dependency} ${RUNTIME_DEP_PATH}
+      COMMENT "Copying ${dependency} for ${target}"
+      VERBATIM)
+
+  endforeach()
+
 endfunction()
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index dd118bb..7ba0aa9 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -64,11 +64,15 @@ set(EXAMPLES
 
 foreach(example ${EXAMPLES})
   add_executable(example-${example} ${example}.c)
+  list(APPEND EXAMPLE_TARGETS example-${example})
   # to find generated header
   target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
   target_link_libraries(example-${example} ssh2)
-  copy_to_target_runtime_directory(example-${example} ${RUNTIME_DEPENDENCIES})
 endforeach()
+add_target_to_copy_dependencies(
+  TARGET copy_example_dependencies
+  DEPENDENCIES ${RUNTIME_DEPENDENCIES}
+  BEFORE_TARGETS ${EXAMPLE_TARGETS})
 
 ## Platform checks
 check_include_files(inttypes.h HAVE_INTTYPES_H)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 49ee720..9a74102 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -59,9 +59,14 @@ foreach(test ${TESTS})
   add_executable(test-${test} ${test}.c)
   target_link_libraries(test-${test} ssh2)
   target_include_directories(test-${test} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-  copy_to_target_runtime_directory(test-${test} ${RUNTIME_DEPENDENCIES})
+  list(APPEND TEST_TARGETS test-${test})
 endforeach()
 
+add_target_to_copy_dependencies(
+  TARGET copy_test_dependencies
+  DEPENDENCIES ${RUNTIME_DEPENDENCIES}
+  BEFORE_TARGETS ${TEST_TARGETS})
+
 # TODO convert mansyntax.sh into CMake script.
 # XXX Just because we can find all three programs, doesn't mean sh can
 # find man and grep
-- 
2.1.0


From 59da9610ca937666368053f3f43c52808f353881 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Wed, 1 Oct 2014 18:23:46 +0100
Subject: [PATCH 31/47] Add options to disable building tests or examples.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 CMakeLists.txt | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index dffe66c..f5f48c2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -72,14 +72,21 @@ install(
   FILES AUTHORS COPYING HACKING README RELEASE-NOTES NEWS
   DESTINATION .)
 
-enable_testing()
-
 include(max_warnings)
 include(FeatureSummary)
 
 add_subdirectory(src)
-add_subdirectory(example)
-add_subdirectory(tests)
+
+option(BUILD_EXAMPLES "Build libssh2 examples" ON)
+if(BUILD_EXAMPLES)
+  add_subdirectory(example)
+endif()
+
+option(BUILD_TESTING "Build libssh2 test suite" ON)
+if(BUILD_TESTING)
+  enable_testing()
+  add_subdirectory(tests)
+endif()
 
 feature_summary(WHAT ALL)
 
-- 
2.1.0


From 98b298604f842a69c8213bf03afe778ec44fdae3 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Wed, 1 Oct 2014 19:21:55 +0100
Subject: [PATCH 32/47] Fix `add_target_to_copy_dependencies` when list of
 dependencies is empty.

This happens on non-windows platforms.  Was calling `add_dependencies` with just one argument which caused an error.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 cmake/CopyRuntimeDependencies.cmake | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/cmake/CopyRuntimeDependencies.cmake b/cmake/CopyRuntimeDependencies.cmake
index 3f1541d..bab9e45 100644
--- a/cmake/CopyRuntimeDependencies.cmake
+++ b/cmake/CopyRuntimeDependencies.cmake
@@ -42,6 +42,10 @@ function(ADD_TARGET_TO_COPY_DEPENDENCIES)
   cmake_parse_arguments(COPY
     "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
 
+  if(NOT COPY_DEPENDENCIES)
+    return()
+  endif()
+
   # Using a custom target to drive custom commands stops multiple
   # parallel builds trying to kick off the commands at the same time
   add_custom_target(${COPY_TARGET} DEPENDS ${COPY_DEPENDENCIES})
-- 
2.1.0


From 96ecffe62c2d9e204b598f2c98b81597b41f51d2 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Wed, 1 Oct 2014 20:58:47 +0100
Subject: [PATCH 33/47] Fix copying dependencies in shared library builds.

We forgot that we might includes target generator syntax in the dependencies to be copied, as in the case where libssh2 is a shared library.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 cmake/CopyRuntimeDependencies.cmake | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/cmake/CopyRuntimeDependencies.cmake b/cmake/CopyRuntimeDependencies.cmake
index bab9e45..083f762 100644
--- a/cmake/CopyRuntimeDependencies.cmake
+++ b/cmake/CopyRuntimeDependencies.cmake
@@ -48,8 +48,7 @@ function(ADD_TARGET_TO_COPY_DEPENDENCIES)
 
   # Using a custom target to drive custom commands stops multiple
   # parallel builds trying to kick off the commands at the same time
-  add_custom_target(${COPY_TARGET} DEPENDS ${COPY_DEPENDENCIES})
-  add_dependencies(${COPY_TARGET} ${COPY_DEPENDENCIES})
+  add_custom_target(${COPY_TARGET})
 
   foreach(target ${COPY_BEFORE_TARGETS})
     add_dependencies(${target} ${COPY_TARGET})
@@ -57,15 +56,15 @@ function(ADD_TARGET_TO_COPY_DEPENDENCIES)
 
   foreach(dependency ${COPY_DEPENDENCIES})
 
-    get_filename_component(DEP_NAME ${dependency} NAME)
-    set(RUNTIME_DEP_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${DEP_NAME})
-    list(APPEND RUNTIME_DEPS ${RUNTIME_DEP_PATH})
-
     add_custom_command(
       TARGET ${COPY_TARGET}
+      DEPENDS ${dependency}
+      # Make directory first otherwise file is copied in place of
+      # directory instead of into it
+      COMMAND ${CMAKE_COMMAND}
+      ARGS -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
       COMMAND ${CMAKE_COMMAND}
-      ARGS -E copy ${dependency} ${RUNTIME_DEP_PATH}
-      COMMENT "Copying ${dependency} for ${target}"
+      ARGS -E copy ${dependency} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
       VERBATIM)
 
   endforeach()
-- 
2.1.0


From 630ee2a34938cabd0642b3c8f2c865c154f9fe34 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Wed, 1 Oct 2014 23:13:40 +0100
Subject: [PATCH 34/47] Renamed library target to the less surprising
 'libssh2'.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 example/CMakeLists.txt |  2 +-
 src/CMakeLists.txt     | 32 ++++++++++++++++----------------
 tests/CMakeLists.txt   |  2 +-
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index 7ba0aa9..4fcfa16 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -67,7 +67,7 @@ foreach(example ${EXAMPLES})
   list(APPEND EXAMPLE_TARGETS example-${example})
   # to find generated header
   target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-  target_link_libraries(example-${example} ssh2)
+  target_link_libraries(example-${example} libssh2)
 endforeach()
 add_target_to_copy_dependencies(
   TARGET copy_example_dependencies
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 123979b..65054d7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -179,9 +179,9 @@ set(SOURCES
   userauth.h
   version.c)
 
-add_library(ssh2 ${SOURCES})
-target_compile_definitions(ssh2 PRIVATE ${PRIVATE_COMPILE_DEFINITIONS})
-target_include_directories(ssh2
+add_library(libssh2 ${SOURCES})
+target_compile_definitions(libssh2 PRIVATE ${PRIVATE_COMPILE_DEFINITIONS})
+target_include_directories(libssh2
   PRIVATE ${PRIVATE_INCLUDE_DIRECTORIES}
   PUBLIC
     $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
@@ -198,23 +198,23 @@ add_feature_info(Compression ENABLE_ZLIB_COMPRESSION
 if(ENABLE_ZLIB_COMPRESSION)
   find_package(ZLIB REQUIRED)
 
-  target_include_directories(ssh2 PRIVATE ${ZLIB_INCLUDE_DIRS})
+  target_include_directories(libssh2 PRIVATE ${ZLIB_INCLUDE_DIRS})
   list(APPEND LIBRARIES ${ZLIB_LIBRARIES})
   if(ZLIB_FOUND)
-    target_compile_definitions(ssh2 PRIVATE LIBSSH2_HAVE_ZLIB=1)
+    target_compile_definitions(libssh2 PRIVATE LIBSSH2_HAVE_ZLIB=1)
   endif()
 endif()
 
 option(ENABLE_CRYPT_NONE "Permit \"none\" cipher -- NOT RECOMMENDED")
 add_feature_info("\"none\" cipher" ENABLE_CRYPT_NONE "")
 if(ENABLE_CRYPT_NONE)
-  target_compile_definitions(ssh2 PRIVATE LIBSSH2_CRYPT_NONE=1)
+  target_compile_definitions(libssh2 PRIVATE LIBSSH2_CRYPT_NONE=1)
 endif()
 
 option(ENABLE_MAC_NONE "Permit \"none\" MAC -- NOT RECOMMMENDED")
 add_feature_info("\"none\" MAC" ENABLE_MAC_NONE "")
 if(ENABLE_MAC_NONE)
-  target_compile_definitions(ssh2 PRIVATE LIBSSH2_MAC_NONE=1)
+  target_compile_definitions(libssh2 PRIVATE LIBSSH2_MAC_NONE=1)
 endif()
 
 option(ENABLE_GEX_NEW
@@ -222,7 +222,7 @@ option(ENABLE_GEX_NEW
 add_feature_info("diffie-hellman-group-exchange-sha1" ENABLE_GEX_NEW
   "\"new\" diffie-hellman-group-exchange-sha1 method")
 if(ENABLE_GEX_NEW)
-  target_compile_definitions(ssh2 PRIVATE LIBSSH2_DH_GEX_NEW=1)
+  target_compile_definitions(libssh2 PRIVATE LIBSSH2_DH_GEX_NEW=1)
 endif()
 
 # Enable debugging logging by default if the user configured a debug build
@@ -236,7 +236,7 @@ option(ENABLE_DEBUG_LOGGING "log execution with debug trace"
 add_feature_info(Logging ENABLE_DEBUG_LOGGING
    "Logging of execution with debug trace")
 if(ENABLE_DEBUG_LOGGING)
-  target_compile_definitions(ssh2 PRIVATE LIBSSH2DEBUG)
+  target_compile_definitions(libssh2 PRIVATE LIBSSH2DEBUG)
 endif()
 
 ## Platform checks
@@ -315,22 +315,22 @@ configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config.h.in
   ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h)
 # to find generated header
-target_include_directories(ssh2 PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_include_directories(libssh2 PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
 
 # Check for the OS.
 # Daniel's note: this should not be necessary and we need to work to
 # get this removed.
 if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
-  target_compile_definitions(ssh2 PRIVATE LIBSSH2_WIN32)
+  target_compile_definitions(libssh2 PRIVATE LIBSSH2_WIN32)
 elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
-  target_compile_definitions(ssh2 PRIVATE LIBSSH2_DARWIN)
+  target_compile_definitions(libssh2 PRIVATE LIBSSH2_DARWIN)
 endif()
 
 if(CMAKE_VERSION VERSION_LESS "2.8.12")
   # Fall back to over-linking dependencies
-  target_link_libraries(ssh2 ${LIBRARIES})
+  target_link_libraries(libssh2 ${LIBRARIES})
 else()
-  target_link_libraries(ssh2 PRIVATE ${LIBRARIES})
+  target_link_libraries(libssh2 PRIVATE ${LIBRARIES})
 endif()
 
 ## Installation
@@ -341,13 +341,13 @@ install(FILES
   ${CMAKE_SOURCE_DIR}/include/libssh2_sftp.h
   DESTINATION include)
 
-install(TARGETS ssh2
+install(TARGETS libssh2
   RUNTIME DESTINATION bin
   LIBRARY DESTINATION lib
   ARCHIVE DESTINATION lib)
 
 if(BUILD_SHARED_LIBS)
-  list(APPEND _RUNTIME_DEPENDENCIES $<TARGET_FILE:ssh2>)
+  list(APPEND _RUNTIME_DEPENDENCIES $<TARGET_FILE:libssh2>)
 endif()
 
 set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 9a74102..157eed1 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -57,7 +57,7 @@ set(TESTS
 
 foreach(test ${TESTS})
   add_executable(test-${test} ${test}.c)
-  target_link_libraries(test-${test} ssh2)
+  target_link_libraries(test-${test} libssh2)
   target_include_directories(test-${test} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
   list(APPEND TEST_TARGETS test-${test})
 endforeach()
-- 
2.1.0


From e1539a57810255191e87ac2415a79c024734b2e3 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Thu, 2 Oct 2014 00:27:05 +0200
Subject: [PATCH 35/47] Remove double 'lib' prefix on non-windows platforms.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 src/CMakeLists.txt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 65054d7..4737251 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -180,6 +180,9 @@ set(SOURCES
   version.c)
 
 add_library(libssh2 ${SOURCES})
+# we want it to be called libssh2 on all platforms
+set_target_properties(libssh2 PROPERTIES PREFIX "")
+
 target_compile_definitions(libssh2 PRIVATE ${PRIVATE_COMPILE_DEFINITIONS})
 target_include_directories(libssh2
   PRIVATE ${PRIVATE_INCLUDE_DIRECTORIES}
-- 
2.1.0


From 40c813a194bdf58da97b2c2d005b1cbc040624a9 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Thu, 2 Oct 2014 08:00:14 +0100
Subject: [PATCH 36/47] Use explicit echo in tests.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 tests/sshdwrap | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100755 tests/sshdwrap

diff --git a/tests/sshdwrap b/tests/sshdwrap
new file mode 100755
index 0000000..599140c
--- /dev/null
+++ b/tests/sshdwrap
@@ -0,0 +1,28 @@
+#!/bin/sh -x
+
+# Written by Simon Josefsson
+
+# Start sshd, invoke parameters, saving exit code, kill sshd, and
+# return exit code.
+
+cmd="$@"
+SSHD=${SSHD:-/usr/sbin/sshd}
+
+$SSHD -f etc/sshd_config -h $PWD/etc/host -D &
+sshdpid=$!
+
+trap "kill ${sshdpid}; echo signal killing sshd; exit 1;" EXIT
+
+echo "started sshd (${sshdpid})"
+
+sleep 1
+
+echo Invoking $cmd...
+eval $cmd
+ec=$?
+echo Self-test exit code $ec
+
+echo "killing sshd (${sshdpid})"
+kill "${sshdpid}" > /dev/null 2>&1
+trap "" EXIT
+exit $ec
-- 
2.1.0


From 47ba9e5ca9773abab3481f8d7b2a98ddfd2cf431 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Thu, 2 Oct 2014 08:10:05 +0100
Subject: [PATCH 37/47] Explicitly specify the include install prefix.

Required by CMake 2.8.11.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 src/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4737251..fb17624 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -188,7 +188,7 @@ target_include_directories(libssh2
   PRIVATE ${PRIVATE_INCLUDE_DIRECTORIES}
   PUBLIC
     $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
-    $<INSTALL_INTERFACE:include>)
+    $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>)
 
 ## Options
 
-- 
2.1.0


From cfc4e591d9937c20785d3bc87b3bd45ac9e75403 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Thu, 2 Oct 2014 08:47:46 +0100
Subject: [PATCH 38/47] Fix building test and examples when libssh2 is a DLL.

The tests and examples need the socket library, independently of libssh2 becuase they create sockets themselves.  These were accidentally being inherited from libssh2 before we made the linkage private, but since then they have been missing.  This only showed up on DLL builds because DLLs don't link their dependencies into their dependents.

This change fixes the problem by making the tests and examples explictly link against the sockets libraries.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 cmake/SocketLibraries.cmake | 64 +++++++++++++++++++++++++++++++++++++++++++++
 example/CMakeLists.txt      |  5 +++-
 src/CMakeLists.txt          | 27 ++-----------------
 tests/CMakeLists.txt        |  5 +++-
 4 files changed, 74 insertions(+), 27 deletions(-)
 create mode 100644 cmake/SocketLibraries.cmake

diff --git a/cmake/SocketLibraries.cmake b/cmake/SocketLibraries.cmake
new file mode 100644
index 0000000..bfbbd71
--- /dev/null
+++ b/cmake/SocketLibraries.cmake
@@ -0,0 +1,64 @@
+# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+#
+# Redistribution and use in source and binary forms,
+# with or without modification, are permitted provided
+# that the following conditions are met:
+#
+#   Redistributions of source code must retain the above
+#   copyright notice, this list of conditions and the
+#   following disclaimer.
+#
+#   Redistributions in binary form must reproduce the above
+#   copyright notice, this list of conditions and the following
+#   disclaimer in the documentation and/or other materials
+#   provided with the distribution.
+#
+#   Neither the name of the copyright holder nor the names
+#   of any other contributors may be used to endorse or
+#   promote products derived from this software without
+#   specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# OF SUCH DAMAGE.
+
+# Some systems have their socket functions in a library.
+# (Solaris -lsocket/-lnsl, Windows -lws2_32).  This macro appends those
+# libraries to the given list
+macro(append_needed_socket_libraries LIBRARIES_LIST)
+  if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
+    # x86 Windows uses STDCALL for these functions, so their names are mangled,
+    # meaning the platform checks don't work. Hardcoding these until we get
+    # a better solution.
+    set(HAVE_SOCKET 1)
+    set(HAVE_SELECT 1)
+    set(HAVE_INET_ADDR 1)
+    set(NEED_LIB_WS2_32 1)
+  else()
+    check_function_exists_may_need_library(socket HAVE_SOCKET socket ws2_32)
+    check_function_exists_may_need_library(select HAVE_SELECT ws2_32)
+    check_function_exists_may_need_library(inet_addr HAVE_INET_ADDR nsl ws2_32)
+  endif()
+
+  if(NEED_LIB_SOCKET)
+    list(APPEND ${LIBRARIES_LIST} socket)
+  endif()
+  if(NEED_LIB_NSL)
+    list(APPEND ${LIBRARIES_LIST} nsl)
+  endif()
+  if(NEED_LIB_WS2_32)
+    list(APPEND ${LIBRARIES_LIST} ws2_32)
+  endif()
+
+endmacro()
\ No newline at end of file
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index 4fcfa16..07eb43a 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -37,6 +37,7 @@ include(CheckIncludeFiles)
 include(CheckFunctionExists)
 include(CheckSymbolExists)
 include(CopyRuntimeDependencies)
+include(SocketLibraries)
 
 set(EXAMPLES
   direct_tcpip
@@ -62,12 +63,14 @@ set(EXAMPLES
   subsystem_netconf
   tcpip-forward)
 
+append_needed_socket_libraries(LIBRARIES)
+
 foreach(example ${EXAMPLES})
   add_executable(example-${example} ${example}.c)
   list(APPEND EXAMPLE_TARGETS example-${example})
   # to find generated header
   target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-  target_link_libraries(example-${example} libssh2)
+  target_link_libraries(example-${example} libssh2 ${LIBRARIES})
 endforeach()
 add_target_to_copy_dependencies(
   TARGET copy_example_dependencies
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fb17624..d39310e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -38,6 +38,7 @@ include(CheckFunctionExistsMayNeedLibrary)
 include(CheckIncludeFiles)
 include(CheckTypeSize)
 include(CheckNonblockingSocketSupport)
+include(SocketLibraries)
 
 ## Cryptography backend choice
 
@@ -281,31 +282,7 @@ else()
   check_function_exists(poll HAVE_POLL)
 endif()
 
-# Some systems have socket function in a library
-# (Solaris -lsocket/-lnsl, Windows -lws2_32)
-if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
-  # x86 Windows uses STDCALL for these functions, so their names are mangled,
-  # meaning the platform checks don't work. Hardcoding these until we get
-  # a better solution.
-  set(HAVE_SOCKET 1)
-  set(HAVE_SELECT 1)
-  set(HAVE_INET_ADDR 1)
-  set(NEED_LIB_WS2_32 1)
-else()
-  check_function_exists_may_need_library(socket HAVE_SOCKET socket ws2_32)
-  check_function_exists_may_need_library(select HAVE_SELECT ws2_32)
-  check_function_exists_may_need_library(inet_addr HAVE_INET_ADDR nsl ws2_32)
-endif()
-
-if(NEED_LIB_SOCKET)
-  list(APPEND LIBRARIES socket)
-endif()
-if(NEED_LIB_NSL)
-  list(APPEND LIBRARIES nsl)
-endif()
-if(NEED_LIB_WS2_32)
-  list(APPEND LIBRARIES ws2_32)
-endif()
+append_needed_socket_libraries(LIBRARIES)
 
 # Non-blocking socket support tests.  Must be after after library tests to
 # link correctly
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 157eed1..d209c21 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -38,6 +38,7 @@ include(CheckFunctionExists)
 include(CheckSymbolExists)
 include(BundleUtilities)
 include(CopyRuntimeDependencies)
+include(SocketLibraries)
 
 ## Platform checks
 check_include_files(inttypes.h HAVE_INTTYPES_H)
@@ -55,9 +56,11 @@ set(TESTS
   simple
   ssh2)
 
+append_needed_socket_libraries(LIBRARIES)
+
 foreach(test ${TESTS})
   add_executable(test-${test} ${test}.c)
-  target_link_libraries(test-${test} libssh2)
+  target_link_libraries(test-${test} libssh2 ${LIBRARIES})
   target_include_directories(test-${test} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
   list(APPEND TEST_TARGETS test-${test})
 endforeach()
-- 
2.1.0


From 0f6be541e2c44be8c2fc37fd18d2a07fed522a3f Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Thu, 2 Oct 2014 18:02:26 +0100
Subject: [PATCH 39/47] Export CMake target and usage requirements in
 Libssh2Config.cmake package.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 src/CMakeLists.txt | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d39310e..07d8ce2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -322,6 +322,7 @@ install(FILES
   DESTINATION include)
 
 install(TARGETS libssh2
+  EXPORT Libssh2Config
   RUNTIME DESTINATION bin
   LIBRARY DESTINATION lib
   ARCHIVE DESTINATION lib)
@@ -332,3 +333,24 @@ endif()
 
 set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL
     "Files that must be in the same directory as the executables at runtime.")
+
+# Package config
+
+## During package installation, install Libssh2Config.cmake
+install(EXPORT Libssh2Config NAMESPACE Libssh2:: DESTINATION lib)
+
+## During build, register directly from build tree
+# create Libssh2Config.cmake
+export(TARGETS libssh2 NAMESPACE Libssh2:: FILE Libssh2Config.cmake)
+export(PACKAGE Libssh2) # register it
+
+## Versioning
+
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file(
+  ${CMAKE_CURRENT_BINARY_DIR}/Libssh2ConfigVersion.cmake
+  VERSION "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}"
+  COMPATIBILITY SameMajorVersion)
+install(
+  FILES ${CMAKE_CURRENT_BINARY_DIR}/Libssh2ConfigVersion.cmake
+  DESTINATION lib)
-- 
2.1.0


From 9d3b6c300bb3ba620a52a8042b9c3a09928ac204 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Wed, 3 Dec 2014 19:48:10 +0000
Subject: [PATCH 40/47] Put CMake package configs on default search path.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 src/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 07d8ce2..f95b393 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -337,7 +337,7 @@ set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL
 # Package config
 
 ## During package installation, install Libssh2Config.cmake
-install(EXPORT Libssh2Config NAMESPACE Libssh2:: DESTINATION lib)
+install(EXPORT Libssh2Config NAMESPACE Libssh2:: DESTINATION lib/cmake/libssh2)
 
 ## During build, register directly from build tree
 # create Libssh2Config.cmake
@@ -353,4 +353,4 @@ write_basic_package_version_file(
   COMPATIBILITY SameMajorVersion)
 install(
   FILES ${CMAKE_CURRENT_BINARY_DIR}/Libssh2ConfigVersion.cmake
-  DESTINATION lib)
+  DESTINATION lib/cmake/libssh2)
-- 
2.1.0


From 7629f6b4cfc1fcd186e4c51f4e1c0fc6e49b47c9 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Wed, 3 Dec 2014 20:29:41 +0000
Subject: [PATCH 41/47] Compile Windows DLLs with version information and other
 extended properties.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 src/CMakeLists.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f95b393..93de53a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -180,6 +180,10 @@ set(SOURCES
   userauth.h
   version.c)
 
+if(WIN32)
+  list(APPEND SOURCES ${CMAKE_SOURCE_DIR}/win32/libssh2.rc)
+endif()
+
 add_library(libssh2 ${SOURCES})
 # we want it to be called libssh2 on all platforms
 set_target_properties(libssh2 PROPERTIES PREFIX "")
-- 
2.1.0


From fbd7cdb051ee2c62aaf5a48f6d4de2c16e0895db Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Wed, 3 Dec 2014 22:07:34 +0000
Subject: [PATCH 42/47] Fix builds with non-GNU compilers used with Unix-style
 make.

An example of this is OpenWatcom.  It uses wmake but doesn't understand GNU-style warning flags.

This change fixes the problem by using the compiler, rather than the make tool, when deciding which warning flags to use.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 cmake/max_warnings.cmake | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/cmake/max_warnings.cmake b/cmake/max_warnings.cmake
index 9dcabc3..b176d30 100644
--- a/cmake/max_warnings.cmake
+++ b/cmake/max_warnings.cmake
@@ -13,9 +13,7 @@ if(MSVC)
 
   # Disable broken warnings
   add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
-endif()
-
-if(CMAKE_BUILD_TOOL MATCHES "make")
+elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
   if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
   endif()
-- 
2.1.0


From 443bba198309ad5f1ffd9f48b4b09f2598e86a4b Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Wed, 3 Dec 2014 22:15:18 +0000
Subject: [PATCH 43/47] Remove redundant Windows project files and make files.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 Makefile.am            |  69 +----------
 Makefile.inc           |   7 --
 NMakefile              |  28 -----
 src/Makefile.am        |   2 +-
 src/NMakefile          |  20 ----
 win32/GNUmakefile      | 317 -------------------------------------------------
 win32/Makefile.Watcom  | 179 ----------------------------
 win32/config.mk        |  30 -----
 win32/libssh2.dsw      |  41 -------
 win32/msvcproj.foot    |   3 -
 win32/rules.mk         |  15 ---
 win32/test/GNUmakefile | 261 ----------------------------------------
 win32/tests.dsp        | 102 ----------------
 13 files changed, 2 insertions(+), 1072 deletions(-)
 delete mode 100644 Makefile.inc
 delete mode 100644 NMakefile
 delete mode 100644 src/NMakefile
 delete mode 100644 win32/GNUmakefile
 delete mode 100644 win32/Makefile.Watcom
 delete mode 100644 win32/config.mk
 delete mode 100644 win32/libssh2.dsw
 delete mode 100644 win32/msvcproj.foot
 delete mode 100644 win32/rules.mk
 delete mode 100644 win32/test/GNUmakefile
 delete mode 100644 win32/tests.dsp

diff --git a/Makefile.am b/Makefile.am
index 023200d..bc0d66d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -18,19 +18,11 @@ NETWAREFILES =  nw/keepscreen.c \
 	nw/GNUmakefile \
 	nw/test/GNUmakefile
 
-DSP = win32/libssh2.dsp
-VCPROJ = win32/libssh2.vcproj
-
-DISTCLEANFILES = $(DSP)
-
 VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl	\
 vms/libssh2_make_kit.dcl vms/libssh2_make_lib.dcl vms/man2help.c	\
 vms/readme.vms vms/libssh2_config.h
 
-WIN32FILES = win32/GNUmakefile win32/test/GNUmakefile		\
-win32/libssh2_config.h win32/config.mk win32/rules.mk		\
-win32/Makefile.Watcom win32/libssh2.dsw win32/tests.dsp $(DSP)	\
-win32/msvcproj.head win32/msvcproj.foot win32/libssh2.rc
+WIN32FILES = win32/libssh2.rc
 
 EXTRA_DIST = $(WIN32FILES) buildconf $(NETWAREFILES) get_ver.awk HACKING \
  maketgz NMakefile TODO RELEASE-NOTES libssh2.pc.in $(VMSFILES) config.rpath
@@ -73,62 +65,3 @@ gen-coverage:
 		--title "$(PACKAGE_NAME)"
 
 coverage: init-coverage build-coverage gen-coverage
-
-# DSP/VCPROJ generation adapted from libcurl
-# Makefile.inc provides the CSOURCES and HHEADERS defines
-include Makefile.inc
-
-WIN32SOURCES = $(CSOURCES)
-WIN32HEADERS = $(HHEADERS) libssh2_config.h
-
-$(DSP): win32/msvcproj.head win32/msvcproj.foot Makefile.am
-	echo "creating $(DSP)"
-	@( (cat $(srcdir)/win32/msvcproj.head; \
-	echo "# Begin Group \"Source Files\""; \
-	echo ""; \
-	echo "# PROP Default_Filter \"cpp;c;cxx\""; \
-	win32_srcs='$(WIN32SOURCES)'; \
-	sorted_srcs=`for file in $$win32_srcs; do echo $$file; done | sort`; \
-	for file in $$sorted_srcs; do \
-		echo "# Begin Source File"; \
-		echo ""; \
-		echo "SOURCE=..\\src\\"$$file; \
-		echo "# End Source File"; \
-	done; \
-	echo "# End Group"; \
-	echo "# Begin Group \"Header Files\""; \
-	echo ""; \
-	echo "# PROP Default_Filter \"h;hpp;hxx\""; \
-	win32_hdrs='$(WIN32HEADERS)'; \
-	sorted_hdrs=`for file in $$win32_hdrs; do echo $$file; done | sort`; \
-	for file in $$sorted_hdrs; do \
-		echo "# Begin Source File"; \
-		echo ""; \
-		if [ "$$file" == "libssh2_config.h" ]; \
-		then \
-			echo "SOURCE=.\\"$$file; \
-		else \
-			echo "SOURCE=..\\src\\"$$file; \
-		fi; \
-		echo "# End Source File"; \
-	done; \
-	echo "# End Group"; \
-	cat $(srcdir)/win32/msvcproj.foot) | \
-	awk '{printf("%s\r\n", gensub("\r", "", "g"))}' > $@ )
-
-$(VCPROJ): win32/vc8proj.head win32/vc8proj.foot Makefile.am
-	echo "creating $(VCPROJ)"
-	@( (cat $(srcdir)/vc8proj.head; \
-	win32_srcs='$(WIN32SOURCES)'; \
-	sorted_srcs=`for file in $$win32_srcs; do echo $$file; done | sort`; \
-	for file in $$sorted_srcs; do \
-		echo "<File RelativePath=\""..\src\$$file"\"></File>"; \
-	done; \
-	echo "</Filter><Filter	Name=\"Header Files\">"; \
-	win32_hdrs='$(WIN32HEADERS)'; \
-	sorted_hdrs=`for file in $$win32_hdrs; do echo $$file; done | sort`; \
-	for file in $$sorted_hdrs; do \
-		echo "<File RelativePath=\""..\src\$$file"\"></File>"; \
-	done; \
-	cat $(srcdir)/vc8proj.foot) | \
-	awk '{printf("%s\r\n", gensub("\r", "", "g"))}' > $@ )
diff --git a/Makefile.inc b/Makefile.inc
deleted file mode 100644
index 12a89e5..0000000
--- a/Makefile.inc
+++ /dev/null
@@ -1,7 +0,0 @@
-CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \
- packet.c publickey.c scp.c session.c sftp.c userauth.c transport.c \
- version.c knownhost.c agent.c openssl.c libgcrypt.c pem.c keepalive.c \
- global.c
-
-HHEADERS = libssh2_priv.h openssl.h libgcrypt.h transport.h channel.h \
- comp.h mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h
diff --git a/NMakefile b/NMakefile
deleted file mode 100644
index f3fcce1..0000000
--- a/NMakefile
+++ /dev/null
@@ -1,28 +0,0 @@
-!include "win32/config.mk"
-
-!include "Makefile.inc"
-
-OBJECTS=$(CSOURCES:.c=.obj)
-
-# SUBDIRS=src example
-SUBDIRS=src
-
-all-sub: win32\objects.mk
-	-for %D in ($(SUBDIRS)) do $(MAKE) /nologo /f %D/NMakefile BUILD=$(BUILD) SUBDIR=%D all-sub
-
-clean: 
-	-rmdir 2>NUL /s/q $(TARGET)
-
-real-clean vclean: clean
-	-del 2>NUL libssh2.dll
-	-del 2>NUL libssh2.exp
-	-del 2>NUL libssh2.ilk
-	-del 2>NUL libssh2.lib
-	-del 2>NUL *.pdb
-	-del 2>NUL win32\objects.mk
-
-win32\objects.mk: Makefile.inc
-	@echo OBJECTS = \>$@
-	@for %O in ($(OBJECTS)) do @echo $$(INTDIR)\%O \>>$@
-	@echo $$(EOL)>>$@
-
diff --git a/src/Makefile.am b/src/Makefile.am
index 53fb4e8..aa878d4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,7 +6,7 @@ include ../Makefile.inc
 
 libssh2_la_SOURCES = $(CSOURCES) $(HHEADERS)
 
-EXTRA_DIST = libssh2_config.h.in NMakefile
+EXTRA_DIST = libssh2_config.h.in
 
 lib_LTLIBRARIES = libssh2.la
 
diff --git a/src/NMakefile b/src/NMakefile
deleted file mode 100644
index faa3916..0000000
--- a/src/NMakefile
+++ /dev/null
@@ -1,20 +0,0 @@
-!include "win32/config.mk"
-
-!include "win32/objects.mk"
-
-CFLAGS=$(CFLAGS)
-
-RESOURCE=$(INTDIR)\libssh2.res
-
-DLL=libssh2$(SUFFIX).dll
-
-all: $(DLL)
-
-$(DLL): $(OBJECTS) $(RESOURCE)
-	$(CC) -o $(DLL) $(DLLFLAGS) $(OBJECTS) $(RESOURCE) $(LIBS)
-
-$(RESOURCE): win32\libssh2.rc
-	$(RC) $(RCFLAGS) /Fo"$@" $?
-
-!include "win32/rules.mk"
-
diff --git a/win32/GNUmakefile b/win32/GNUmakefile
deleted file mode 100644
index aef6423..0000000
--- a/win32/GNUmakefile
+++ /dev/null
@@ -1,317 +0,0 @@
-#########################################################################
-#
-## Makefile for building libssh2 (Win32 version - gnu make)
-## Use: make -f GNUmakefile [help|all|clean|dev|devclean|dist|distclean|dll|objclean]
-##
-## Hacked by: Guenter Knauf
-#
-#########################################################################
-
-# Edit the path below to point to the base of your Zlib sources.
-ifndef ZLIB_PATH
-ZLIB_PATH = ../../zlib-1.2.7
-endif
-
-# Edit the path below to point to the base of your OpenSSL package.
-ifndef OPENSSL_PATH
-OPENSSL_PATH = ../../openssl-0.9.8x
-endif
-
-# Edit the var below to set to your architecture or set environment var.
-ifndef ARCH
-ARCH = w32
-endif
-
-# Edit the path below to point to your Distribution folder.
-ifndef DISTDIR
-DISTDIR	= libssh2-$(LIBSSH2_VERSION_STR)-bin-$(ARCH)
-endif
-DISTARC	= $(DISTDIR).zip
-
-# Edit the path below to point to your Development folder.
-ifndef DEVLDIR
-DEVLDIR	= libssh2-$(LIBSSH2_VERSION_STR)-dev-$(ARCH)
-endif
-DEVLARC	= $(DEVLDIR).zip
-
-# Edit the vars below to change target settings.
-TARGET	= libssh2
-WWWURL	= http://www.libssh2.org/
-DESCR	= libssh2 $(LIBSSH2_VERSION_STR)
-#STACK	= 64000
-
-# must be equal to DEBUG or NDEBUG
-ifndef DB
-	DB	= NDEBUG
-	# DB	= DEBUG
-endif
-# Optimization: -O<n> or debugging: -g
-ifeq ($(DB),NDEBUG)
-	OPT	= -O2
-	OBJDIR	= release
-else
-	OPT	= -g
-	OPT	+= -DLIBSSH2DEBUG
-	OBJDIR	= debug
-endif
-
-# Here you can find a native Win32 binary of the original awk:
-# http://www.gknw.net/development/prgtools/awk-20100523.zip
-AWK	= awk
-ZIP	= zip -qzr9
-
-# Platform-dependent helper tool macros
-ifeq ($(findstring /sh,$(SHELL)),/sh)
-DEL	= rm -f $1
-RMDIR	= rm -fr $1
-MKDIR	= mkdir -p $1
-COPY	= -cp -afv $1 $2
-#COPYR	= -cp -afr $1/* $2
-COPYR	= -rsync -aC $1/* $2
-TOUCH	= touch $1
-CAT	= cat
-ECHONL	= echo ""
-DL	= '
-else
-ifeq "$(OS)" "Windows_NT"
-DEL	= -del 2>NUL /q /f $(subst /,\,$1)
-RMDIR	= -rd 2>NUL /q /s $(subst /,\,$1)
-else
-DEL	= -del 2>NUL $(subst /,\,$1)
-RMDIR	= -deltree 2>NUL /y $(subst /,\,$1)
-endif
-MKDIR	= -md 2>NUL $(subst /,\,$1)
-COPY	= -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
-COPYR	= -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
-TOUCH	= copy 2>&1>NUL /b $(subst /,\,$1) +,,
-CAT	= type
-ECHONL	= $(ComSpec) /c echo.
-endif
-
-# The following line defines your compiler.
-ifdef METROWERKS
-	CC = mwcc
-else
-	CC = $(CROSSPREFIX)gcc
-endif
-
-# Include the version info retrieved from libssh2.h
--include $(OBJDIR)/version.inc
-
-# Global flags for all compilers
-CFLAGS	= $(OPT) -D$(DB) -DLIBSSH2_WIN32 # -DHAVE_CONFIG_H
-ifeq ($(ARCH),w64)
-CFLAGS	+= -D_AMD64_
-endif
-
-ifeq ($(CC),mwcc)
-LD	= mwld
-RC	= mwwinrc
-LDFLAGS	= -nostdlib
-AR	= $(LD)
-ARFLAGS	= -nostdlib -library -o
-LIBEXT	= lib
-#RANLIB	=
-LIBPATH	+= -lr "$(METROWERKS)/MSL" -lr "$(METROWERKS)/Win32-x86 Support"
-LDLIBS	+= -lMSL_Runtime_x86.lib -lMSL_C_x86.lib -lMSL_Extras_x86.lib
-LDLIBS	+= -lkernel32.lib -luser32.lib -lwsock32.lib
-RCFLAGS	=
-CFLAGS	+= -nostdinc -gccinc -msgstyle gcc -inline off -opt nointrinsics -proc 586
-CFLAGS	+= -ir "$(METROWERKS)/MSL" -ir "$(METROWERKS)/Win32-x86 Support"
-CFLAGS	+= -w on,nounused,nounusedexpr # -ansi strict
-else
-LD	= $(CROSSPREFIX)gcc
-RC	= $(CROSSPREFIX)windres
-LDFLAGS	= -s -shared -Wl,--output-def,$(TARGET).def,--out-implib,$(TARGET)dll.a
-AR	= $(CROSSPREFIX)ar
-ARFLAGS	= -cq
-LIBEXT	= a
-RANLIB	= $(CROSSPREFIX)ranlib
-#LDLIBS	+= -lwsock32
-LDLIBS	+= -lws2_32
-RCFLAGS	= -I. -I ../include -O coff -i
-CFLAGS	+= -fno-strict-aliasing
-CFLAGS	+= -Wall # -pedantic
-endif
-
-INCLUDES = -I. -I../include
-
-ifndef OPENSSL_INCLUDE
-	ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
-		OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
-	endif
-	ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
-		OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
-	endif
-endif
-ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
-$(error Invalid OPENSSL_PATH: $(OPENSSL_PATH))
-endif
-INCLUDES += -I"$(OPENSSL_INCLUDE)"
-ifndef OPENSSL_LIBPATH
-	OPENSSL_LIBS_STAT = crypto ssl
-	ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
-		OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
-		OPENSSL_LIBS_DYN = eay32 ssl32
-	endif
-	ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
-		OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
-		OPENSSL_LIBS_DYN = crypto.dll ssl.dll
-	endif
-endif
-ifdef LINK_OPENSSL_STATIC
-	LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32
-else
-	LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN))
-endif
-
-ifdef WITH_ZLIB
-	CFLAGS += -DLIBSSH2_HAVE_ZLIB
-	INCLUDES += -I$(ZLIB_PATH)
-	ifdef LINK_ZLIB_STATIC
-		LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT)
-	else
-		LDLIBS += $(ZLIB_PATH)/libz.dll.$(LIBEXT)
-	endif
-endif
-
-CFLAGS	+= $(INCLUDES)
-
-vpath %.c . ../src
-
-# include Makefile.inc to get CSOURCES define
-include ../Makefile.inc
-
-OBJECTS	:= $(patsubst %.c,%.o,$(CSOURCES))
-OBJS	:= $(addprefix $(OBJDIR)/,$(OBJECTS))
-OBJL	= $(OBJS) $(OBJDIR)/$(TARGET).res
-
-all: lib dll
-
-dll: prebuild $(TARGET).dll
-
-lib: prebuild $(TARGET).$(LIBEXT)
-
-prebuild: $(OBJDIR) $(OBJDIR)/version.inc
-# libssh2_config.h
-
-test: all
-	$(MAKE) -C test -f GNUmakefile
- 
-$(OBJDIR)/%.o: %.c
-#	@echo Compiling $<
-	$(CC) $(CFLAGS) -c $< -o $@
-
-$(OBJDIR)/version.inc: ../get_ver.awk ../include/libssh2.h $(OBJDIR)
-	@echo Creating $@
-	@$(AWK) -f $^ > $@
-
-dist: all $(DISTDIR) $(DISTDIR)/readme.txt
-	@$(call MKDIR, $(DISTDIR)/bin)
-	@$(call CP, ../AUTHORS, $(DISTDIR))
-	@$(call CP, ../COPYING, $(DISTDIR))
-	@$(call CP, ../INSTALL, $(DISTDIR))
-	@$(call CP, ../README, $(DISTDIR))
-	@$(call CP, ../RELEASE-NOTES, $(DISTDIR))
-	@$(call CP, $(TARGET).dll, $(DISTDIR)/bin)
-	@echo Creating $(DISTARC)
-	@$(ZIP) $(DISTARC) $(DISTDIR)/* < $(DISTDIR)/readme.txt
-
-dev: all $(DEVLDIR) $(DEVLDIR)/readme.txt
-	@$(call MKDIR, $(DEVLDIR)/bin)
-	@$(call MKDIR,$(DEVLDIR)/include)
-	@$(call MKDIR, $(DEVLDIR)/win32)
-	@$(call CP, ../AUTHORS, $(DEVLDIR))
-	@$(call CP, ../COPYING, $(DEVLDIR))
-	@$(call CP, ../INSTALL, $(DEVLDIR))
-	@$(call CP, ../README, $(DEVLDIR))
-	@$(call CP, ../RELEASE-NOTES, $(DEVLDIR))
-	@$(call CP, $(TARGET).dll, $(DEVLDIR)/bin)
-	@$(call CP, ../include/*.h, $(DEVLDIR)/include)
-	@$(call CP, libssh2_config.h, $(DEVLDIR)/include)
-	@$(call CP, *.$(LIBEXT), $(DEVLDIR)/win32)
-	@echo Creating $(DEVLARC)
-	@$(ZIP) $(DEVLARC) $(DEVLDIR)/* < $(DEVLDIR)/readme.txt
-
-distclean: clean
-	$(call RMDIR, $(DISTDIR))
-	$(call DEL, $(DISTARC))
-
-devclean: clean
-	$(call RMDIR, $(DEVLDIR))
-	$(call DEL, $(DEVLARC))
-
-objclean: all
-	$(call RMDIR, $(OBJDIR))
-
-testclean: clean
-	$(MAKE) -C test -f GNUmakefile clean
-
-clean:
-#	$(call DEL, libssh2_config.h)
-	$(call DEL, $(TARGET).dll $(TARGET).def $(TARGET).$(LIBEXT) $(TARGET)dll.$(LIBEXT))
-	$(call RMDIR, $(OBJDIR))
-
-$(OBJDIR):
-	@$(call MKDIR, $@)
-
-$(DISTDIR):
-	@$(call MKDIR, $@)
-
-$(DEVLDIR):
-	@$(call MKDIR, $@)
-
-$(TARGET).$(LIBEXT): $(OBJS)
-	@echo Creating $@
-	@$(call DEL, $@)
-	@$(AR) $(ARFLAGS) $@ $^
-ifdef RANLIB
-	@$(RANLIB) $@
-endif
-
-$(TARGET).dll $(TARGET)dll.a: $(OBJL)
-	@echo Linking $@
-	@$(call DEL, $@)
-	@$(LD) $(LDFLAGS) $^ -o $@ $(LIBPATH) $(LDLIBS)
-
-
-$(OBJDIR)/%.res: %.rc
-	@echo Creating $@
-	@$(RC) $(RCFLAGS) $< -o $@
-
-
-$(DISTDIR)/readme.txt: GNUmakefile
-	@echo Creating $@
-	@echo $(DL)This is a binary distribution for Win32 platform.$(DL) > $@
-	@echo $(DL)libssh version $(LIBSSH2_VERSION_STR)$(DL) >> $@
-	@echo $(DL)Please download the complete libssh package for$(DL) >> $@
-	@echo $(DL)any further documentation:$(DL) >> $@
-	@echo $(DL)$(WWWURL)$(DL) >> $@
-
-$(DEVLDIR)/readme.txt: GNUmakefile
-	@echo Creating $@
-	@echo $(DL)This is a development distribution for Win32 platform.$(DL) > $@
-	@echo $(DL)libssh version $(LIBSSH2_VERSION_STR)$(DL) >> $@
-	@echo $(DL)Please download the complete libssh package for$(DL) >> $@
-	@echo $(DL)any further documentation:$(DL) >> $@
-	@echo $(DL)$(WWWURL)$(DL) >> $@
-
-help: $(OBJDIR)/version.inc
-	@echo $(DL)===========================================================$(DL)
-	@echo $(DL)OpenSSL path    = $(OPENSSL_PATH)$(DL)
-	@echo $(DL)Zlib path       = $(ZLIB_PATH)$(DL)
-	@echo $(DL)===========================================================$(DL)
-	@echo $(DL)libssh $(LIBSSH2_VERSION_STR) - available targets are:$(DL)
-	@echo $(DL)$(MAKE) all$(DL)
-	@echo $(DL)$(MAKE) dll$(DL)
-	@echo $(DL)$(MAKE) lib$(DL)
-	@echo $(DL)$(MAKE) clean$(DL)
-	@echo $(DL)$(MAKE) dev$(DL)
-	@echo $(DL)$(MAKE) devclean$(DL)
-	@echo $(DL)$(MAKE) dist$(DL)
-	@echo $(DL)$(MAKE) distclean$(DL)
-	@echo $(DL)$(MAKE) objclean$(DL)
-	@echo $(DL)$(MAKE) test$(DL)
-	@echo $(DL)===========================================================$(DL)
-
-
diff --git a/win32/Makefile.Watcom b/win32/Makefile.Watcom
deleted file mode 100644
index b9da40c..0000000
--- a/win32/Makefile.Watcom
+++ /dev/null
@@ -1,179 +0,0 @@
-#
-#  Watcom / OpenWatcom Win32 makefile for libssh2.
-#
-#  Comments to: Guenter Knauf http://www.gknw.net/phpbb
-#
-
-!ifndef %watcom
-!error WATCOM environment variable not set!
-!else
-SYS_INCL = -I$(%watcom)\h\nt -I$(%watcom)\h
-SYS_LIBS = $(%watcom)\lib386\nt;$(%watcom)\lib386
-!endif
-
-!ifdef %libname
-LIBNAME = $(%libname)
-!else
-LIBNAME = libssh2
-!endif
-TARGETS = $(LIBNAME).dll $(LIBNAME)_imp.lib $(LIBNAME).lib
-
-CC = wcc386
-LD = wlink
-AR = wlib
-RC = wrc
-
-!ifdef __LOADDLL__
-!  loaddll wcc386  wccd386
-!  loaddll wpp386  wppd386
-!  loaddll wlib    wlibd
-!  if $(__VERSION__) > 1270
-!    loaddll wlink   wlinkd
-!  else
-!    loaddll wlink   wlink
-!  endif
-!endif
-
-!if $(__VERSION__) < 1250                                                                                                           
-RM = del /q /f 2>NUL
-!else                                                                                                                               
-RM = rm -f                                                                                                                          
-!endif
-MD = mkdir
-RD = rmdir /q /s 2>NUL
-CP = copy
-
-CFLAGS = -3r -mf -hc -zff -zgf -zq -zm -zc -s -fr=nul -w2 -fpi -oilrtfm &
-         -wcd=201 -bt=nt -d+ -dWIN32 -DLIBSSH2_WIN32 &
-         -I. -I..\include $(SYS_INCL)
-
-!ifdef %debug
-DEBUG  = -dDEBUG=1 -dDEBUGBUILD
-CFLAGS += -d3 $(DEBUG)
-!else
-CFLAGS += -d0
-!endif
-
-!ifdef %use_ipv6
-CFLAGS += -d_WIN32_WINNT=0x0501 -dENABLE_IPV6
-!endif
-
-#
-# Change to suite.
-#
-!ifdef %zlib_root
-ZLIB_ROOT = $(%zlib_root)
-!else
-ZLIB_ROOT = ..\..\zlib-1.2.7
-!endif
-
-!ifdef %openssl_root
-OPENSSL_ROOT = $(%openssl_root)
-!else
-OPENSSL_ROOT = ..\..\openssl-0.9.8x
-!endif
-
-#!ifdef %use_zlib
-CFLAGS += -dHAVE_ZLIB_H -dHAVE_LIBZ -I$(ZLIB_ROOT)
-#!endif
-
-#!ifdef %use_ssl
-CFLAGS += -wcd=138 -dUSE_OPENSSL -dUSE_SSLEAY -I$(OPENSSL_ROOT)\inc32
-#!endif
-
-!ifdef %use_watt32
-CFLAGS += -dUSE_WATT32 -I$(%watt_root)\inc
-!endif
-
-OBJ_BASE = WC_Win32.obj
-LINK_ARG = $(OBJ_BASE)\dyn\wlink.arg
-LIB_ARG  = $(OBJ_BASE)\stat\wlib.arg
-
-# In order to process Makefile.inc wmake must be called with -u switch!
-!ifndef %MAKEFLAGS
-!error You MUST call wmake with the -u switch!
-!else
-!include ..\Makefile.inc
-!endif
-
-OBJS = $(CSOURCES:.c=.obj)
-OBJS = $OBJ_DIR\$(OBJS: = $OBJ_DIR\)
-
-#
-# Use $(OBJS) as a template to generate $(OBJS_STAT) and $(OBJS_DYN).
-#
-OBJ_DIR    = $(OBJ_BASE)\stat
-OBJS_STAT  = $+ $(OBJS) $-
-
-OBJ_DIR    = $(OBJ_BASE)\dyn
-OBJS_DYN   = $+ $(OBJS) $-
-
-RESOURCE   = $(OBJ_BASE)\dyn\libssh2.res
-
-.c: ..\src
-
-
-all: $(OBJ_BASE) $(TARGETS) .SYMBOLIC
-	@echo Welcome to libssh2
-
-clean: .SYMBOLIC
-	-$(RM) $(OBJS_STAT)
-	-$(RM) $(OBJS_DYN)
-	-$(RM) $(RESOURCE) $(LINK_ARG) $(LIB_ARG)
-
-vclean realclean: clean .SYMBOLIC
-	-$(RM) $(TARGETS) $(LIBNAME).map $(LIBNAME).sym
-	-$(RD) $(OBJ_BASE)\stat
-	-$(RD) $(OBJ_BASE)\dyn
-	-$(RD) $(OBJ_BASE)
-
-$(OBJ_BASE):
-	-$(MD) $^@
-	-$(MD) $^@\stat
-	-$(MD) $^@\dyn
-
-$(LIBNAME).dll: $(OBJS_DYN) $(RESOURCE) $(LINK_ARG)
-	$(LD) name $^@ @$]@
-
-$(LIBNAME).lib: $(OBJS_STAT) $(LIB_ARG)
-	$(AR) -q -b -c $^@ @$]@
-
-.ERASE
-$(RESOURCE): libssh2.rc
-	$(RC) $(DEBUG) -q -r -zm -I..\include $(SYS_INCL) $[@ -fo=$^@
-
-.ERASE
-.c{$(OBJ_BASE)\dyn}.obj:
-	$(CC) $(CFLAGS) -bd -br $[@ -fo=$^@
-
-.ERASE
-.c{$(OBJ_BASE)\stat}.obj:
-	$(CC) $(CFLAGS) $[@ -fo=$^@
-
-$(LINK_ARG): $(__MAKEFILES__)
-	%create $^@
-	@%append $^@ system nt dll
-	@%append $^@ file { $(OBJS_DYN) }
-!ifdef %debug
-	@%append $^@ debug all
-	@%append $^@ option symfile
-!endif
-	@%append $^@ option quiet, map, caseexact, eliminate, implib=$(LIBNAME)_imp.lib,
-	@%append $^@ res=$(RESOURCE) libpath $(SYS_LIBS)
-!ifdef %use_watt32
-	@%append $^@ library $(%watt_root)\lib\wattcpw_imp.lib
-!else
-	@%append $^@ library ws2_32.lib
-!endif
-#!ifdef %use_zlib
-	@%append $^@ library $(ZLIB_ROOT)\zlib.lib
-#!endif
-#!ifdef %use_ssl
-	@%append $^@ library $(OPENSSL_ROOT)\out32\libeay32.lib, $(OPENSSL_ROOT)\out32\ssleay32.lib
-#!endif
-
-$(LIB_ARG): $(__MAKEFILES__)
-	%create $^@
-	@for %f in ($(OBJS_STAT)) do @%append $^@ +- %f
-
-
diff --git a/win32/config.mk b/win32/config.mk
deleted file mode 100644
index 64b95b3..0000000
--- a/win32/config.mk
+++ /dev/null
@@ -1,30 +0,0 @@
-
-# Tweak these for your system
-OPENSSLINC=..\openssl-0.9.8x\inc32
-OPENSSLLIB=..\openssl-0.9.8x\out32dll
-
-ZLIBINC=-DLIBSSH2_HAVE_ZLIB=1 /I..\zlib-1.2.7
-ZLIBLIB=..\zlib-1.2.7
-
-!if "$(TARGET)" == ""
-TARGET=Release
-!endif
-
-!if "$(TARGET)" == "Debug"
-SUFFIX=_debug
-CPPFLAGS=/Od /MDd
-DLLFLAGS=/DEBUG /LDd
-!else
-CPPFLAGS=/Og /Oi /O2 /Oy /GF /Y- /MD /DNDEBUG
-DLLFLAGS=/DEBUG /LD
-!endif
-
-CPPFLAGS=/nologo /GL /Zi /EHsc $(CPPFLAGS) /Iwin32 /Iinclude /I$(OPENSSLINC) $(ZLIBINC) -DLIBSSH2_WIN32
-CFLAGS=$(CPPFLAGS)
-RCFLAGS=/Iinclude
-DLLFLAGS=$(CFLAGS) $(DLLFLAGS)
-LIBS=$(OPENSSLLIB)\libeay32.lib $(OPENSSLLIB)\ssleay32.lib ws2_32.lib user32.lib $(ZLIBLIB)\zlib.lib
-
-INTDIR=$(TARGET)\$(SUBDIR)
-
-
diff --git a/win32/libssh2.dsw b/win32/libssh2.dsw
deleted file mode 100644
index 36ad8fc..0000000
--- a/win32/libssh2.dsw
+++ /dev/null
@@ -1,41 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "libssh2"=".\libssh2.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Project: "tests"=".\tests.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/win32/msvcproj.foot b/win32/msvcproj.foot
deleted file mode 100644
index 07defa4..0000000
--- a/win32/msvcproj.foot
+++ /dev/null
@@ -1,3 +0,0 @@
-# End Target
-# End Project
-
diff --git a/win32/rules.mk b/win32/rules.mk
deleted file mode 100644
index bfb7784..0000000
--- a/win32/rules.mk
+++ /dev/null
@@ -1,15 +0,0 @@
-
-all-sub: $(INTDIR) all
-
-clean-sub: clean
-
-$(INTDIR):
-!if "$(SRCDIR)" == ""
-	@if not exist $(TARGET) mkdir $(TARGET)
-!endif
-	@if not exist $(INTDIR) mkdir $(INTDIR)
-
-{$(SUBDIR)}.c{$(INTDIR)}.obj::
-	$(CC) -c $(CFLAGS) /Fo"$(INTDIR)\\" $<
-
-
diff --git a/win32/test/GNUmakefile b/win32/test/GNUmakefile
deleted file mode 100644
index 66baced..0000000
--- a/win32/test/GNUmakefile
+++ /dev/null
@@ -1,261 +0,0 @@
-#########################################################################
-#
-## Makefile for building libssh2 samples (Win32 version - gnu make)
-## Use: make -f GNUmakefile [help]
-##
-## Hacked by: Guenter Knauf
-#
-#########################################################################
-
-# Edit the path below to point to the base of your Zlib sources.
-ifndef ZLIB_PATH
-ZLIB_PATH = ../../../zlib-1.2.7
-endif
-
-# Edit the path below to point to the base of your OpenSSL package.
-ifndef OPENSSL_PATH
-OPENSSL_PATH = ../../../openssl-0.9.8x
-endif
-
-# Edit the var below to set to your architecture or set environment var.
-ifndef ARCH
-ARCH = w32
-endif
-
-# Edit the var below to enable static linking of libssh2 and libz
-LINK_STATIC = 1
-
-# Edit the vars below to change target settings.
-SAMPLES	= ../../example
-TARGETS := $(filter-out x11.exe,$(patsubst $(SAMPLES)/%.c,%.exe,$(strip $(wildcard $(SAMPLES)/*.c))))
-WWWURL	= http://www.libssh2.org/
-DESCR	= libssh2 $(subst .rc,,$(notdir $@)) $(LIBSSH2_VERSION_STR)
-#STACK	= 64000
-
-# must be equal to DEBUG or NDEBUG
-ifndef DB
-	DB	= NDEBUG
-	# DB	= DEBUG
-endif
-# Optimization: -O<n> or debugging: -g
-ifeq ($(DB),NDEBUG)
-	OPT	= -O2
-	OBJDIR	= release
-else
-	OPT	= -g
-	OBJDIR	= debug
-endif
-
-# Here you can find a native Win32 binary of the original awk:
-# http://www.gknw.net/development/prgtools/awk-20100523.zip
-AWK     = awk
-ZIP     = zip -qzr9
-
-# Platform-dependent helper tool macros
-ifeq ($(findstring /sh,$(SHELL)),/sh)
-DEL	= rm -f $1
-RMDIR	= rm -fr $1
-MKDIR	= mkdir -p $1
-COPY	= -cp -afv $1 $2
-#COPYR	= -cp -afr $1/* $2
-COPYR	= -rsync -aC $1/* $2
-TOUCH	= touch $1
-CAT	= cat
-ECHONL	= echo ""
-DL	= '
-else
-ifeq "$(OS)" "Windows_NT"
-DEL	= -del 2>NUL /q /f $(subst /,\,$1)
-RMDIR	= -rd 2>NUL /q /s $(subst /,\,$1)
-else
-DEL	= -del 2>NUL $(subst /,\,$1)
-RMDIR	= -deltree 2>NUL /y $(subst /,\,$1)
-endif
-MKDIR	= -md 2>NUL $(subst /,\,$1)
-COPY	= -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
-COPYR	= -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
-TOUCH	= copy 2>&1>NUL /b $(subst /,\,$1) +,,
-CAT	= type
-ECHONL	= $(ComSpec) /c echo.
-endif
-
-# The following line defines your compiler.
-ifdef METROWERKS
-	CC = mwcc
-else
-	CC = $(CROSSPREFIX)gcc
-endif
-
-# Include the version info retrieved from libssh2.h
--include $(OBJDIR)/version.inc
-
-# Global flags for all compilers
-CFLAGS	= $(OPT) -D$(DB) -DLIBSSH2_WIN32 # -DHAVE_CONFIG_H
-ifeq ($(ARCH),w64)
-CFLAGS  += -D_AMD64_
-endif
-
-ifeq ($(CC),mwcc)
-LD	= mwld
-RC	= mwwinrc
-LDFLAGS	= -nostdlib
-AR	= $(LD)
-ARFLAGS	= -nostdlib -library -o
-LIBEXT	= lib
-LIBPATH	+= -lr "$(METROWERKS)/MSL" -lr "$(METROWERKS)/Win32-x86 Support"
-LDLIBS	+= -lMSL_Runtime_x86.lib -lMSL_C_x86.lib -lMSL_Extras_x86.lib
-LDLIBS	+= -lkernel32.lib -luser32.lib -lwsock32.lib
-RCFLAGS	=
-CFLAGS	+= -nostdinc -gccinc -msgstyle gcc -inline off -opt nointrinsics -proc 586
-CFLAGS	+= -ir "$(METROWERKS)/MSL" -ir "$(METROWERKS)/Win32-x86 Support"
-CFLAGS	+= -w on,nounused,nounusedexpr # -ansi strict
-else
-LD	= $(CROSSPREFIX)gcc
-RC	= $(CROSSPREFIX)windres
-LDFLAGS	= -s
-AR	= $(CROSSPREFIX)ar
-ARFLAGS	= -cq
-LIBEXT	= a
-#LDLIBS	+= -lwsock32
-LDLIBS	+= -lws2_32
-RCFLAGS	= -O coff -i
-CFLAGS	+= -fno-strict-aliasing
-CFLAGS	+= -Wall #-Wno-unused #-pedantic
-endif
-
-INCLUDES = -I.. -I../../include
-LIBPATH += -L..
-
-ifdef LINK_STATIC
-	LDLIBS += -llibssh2
-else
-	LDLIBS += -llibssh2dll
-endif
-
-ifndef OPENSSL_INCLUDE
-	ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
-		OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
-	endif
-	ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
-		OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
-	endif
-endif
-ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
-$(error Invalid OPENSSL_PATH: $(OPENSSL_PATH))
-endif
-INCLUDES += -I"$(OPENSSL_INCLUDE)"
-ifndef OPENSSL_LIBPATH
-	OPENSSL_LIBS_STAT = crypto ssl
-	ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
-		OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
-		OPENSSL_LIBS_DYN = eay32 ssl32
-	endif
-	ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
-		OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
-		OPENSSL_LIBS_DYN = crypto.dll ssl.dll
-	endif
-endif
-ifdef LINK_STATIC
-ifdef LINK_OPENSSL_STATIC
-	LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32
-else
-	LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN))
-endif
-endif
-
-ifdef WITH_ZLIB
-	CFLAGS += -DLIBSSH2_HAVE_ZLIB
-	INCLUDES += -I$(ZLIB_PATH)
-	ifdef LINK_ZLIB_STATIC
-		LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT)
-	else
-		LDLIBS += $(ZLIB_PATH)/libzdll.$(LIBEXT)
-	endif
-endif
-
-CFLAGS	+= $(INCLUDES)
-
-vpath %.c ../../example
-
-.PRECIOUS: $(OBJDIR)/%.o $(OBJDIR)/%.rc $(OBJDIR)/%.res
-
-
-all: prebuild $(TARGETS)
-
-prebuild: $(OBJDIR) $(OBJDIR)/version.inc
-
-$(OBJDIR)/%.o: %.c
-#	@echo Compiling $<
-	$(CC) $(CFLAGS) -c $< -o $@
-
-$(OBJDIR)/version.inc: ../../include/libssh2.h $(OBJDIR)
-	@echo Creating $@
-	@$(AWK) -f ../../get_ver.awk $< > $@
-
-objclean:
-	$(call RMDIR, $(OBJDIR))
-
-clean: objclean
-	$(call DEL, $(TARGETS))
-
-$(OBJDIR):
-	$(call MKDIR, $@)
-
-%.exe: $(OBJDIR)/%.o $(OBJDIR)/%.res
-	@echo Linking $@
-	@$(call DEL, $@)
-	$(LD) $(LDFLAGS) $^ -o $@ $(LIBPATH) $(LDLIBS)
-
-$(OBJDIR)/%.res: $(OBJDIR)/%.rc
-	@echo Creating $@
-	@$(RC) $(RCFLAGS) $< -o $@
-
-$(OBJDIR)/%.rc: GNUmakefile $(OBJDIR)/version.inc
-	@echo $(DL)1 VERSIONINFO$(DL) > $@
-	@echo $(DL) FILEVERSION $(LIBSSH2_VERSION),0$(DL) >> $@
-	@echo $(DL) PRODUCTVERSION $(LIBSSH2_VERSION),0$(DL) >> $@
-	@echo $(DL) FILEFLAGSMASK 0x3fL$(DL) >> $@
-	@echo $(DL) FILEOS 0x40004L$(DL) >> $@
-	@echo $(DL) FILEFLAGS 0x0L$(DL) >> $@
-	@echo $(DL) FILETYPE 0x1L$(DL) >> $@
-	@echo $(DL) FILESUBTYPE 0x0L$(DL) >> $@
-	@echo $(DL)BEGIN$(DL) >> $@
-	@echo $(DL)  BLOCK "StringFileInfo"$(DL) >> $@
-	@echo $(DL)  BEGIN$(DL) >> $@
-	@echo $(DL)    BLOCK "040904E4"$(DL) >> $@
-	@echo $(DL)    BEGIN$(DL) >> $@
-	@echo $(DL)      VALUE "LegalCopyright","\xA9 $(LIBSSH2_COPYRIGHT_STR)\0"$(DL) >> $@
-ifdef COMPANY
-	@echo $(DL)      VALUE "CompanyName","$(COMPANY)\0"$(DL) >> $@
-endif
-	@echo $(DL)      VALUE "ProductName","$(notdir $(@:.rc=.exe))\0"$(DL) >> $@
-	@echo $(DL)      VALUE "ProductVersion","$(LIBSSH2_VERSION_STR)\0"$(DL) >> $@
-	@echo $(DL)      VALUE "License","Released under GPL.\0"$(DL) >> $@
-	@echo $(DL)      VALUE "FileDescription","$(DESCR)\0"$(DL) >> $@
-	@echo $(DL)      VALUE "FileVersion","$(LIBSSH2_VERSION_STR)\0"$(DL) >> $@
-	@echo $(DL)      VALUE "InternalName","$(notdir $(@:.rc=))\0"$(DL) >> $@
-	@echo $(DL)      VALUE "OriginalFilename","$(notdir $(@:.rc=.exe))\0"$(DL) >> $@
-	@echo $(DL)      VALUE "WWW","$(WWWURL)\0"$(DL) >> $@
-	@echo $(DL)    END$(DL) >> $@
-	@echo $(DL)  END$(DL) >> $@
-	@echo $(DL)  BLOCK "VarFileInfo"$(DL) >> $@
-	@echo $(DL)  BEGIN$(DL) >> $@
-	@echo $(DL)    VALUE "Translation", 0x409, 1252$(DL) >> $@
-	@echo $(DL)  END$(DL) >> $@
-	@echo $(DL)END$(DL) >> $@
-ifdef ICON
-	@echo $(DL)10 ICON DISCARDABLE "$(ICON)"$(DL) >> $@
-endif
-
-help: $(OBJDIR)/version.inc
-	@echo $(DL)===========================================================$(DL)
-	@echo $(DL)OpenSSL path    = $(OPENSSL_PATH)$(DL)
-	@echo $(DL)Zlib path       = $(ZLIB_PATH)$(DL)
-	@echo $(DL)===========================================================$(DL)
-	@echo $(DL)libssh $(LIBSSH2_VERSION_STR) - available targets are:$(DL)
-	@echo $(DL)$(MAKE) all$(DL)
-	@echo $(DL)$(MAKE) clean$(DL)
-	@echo $(DL)$(MAKE) objclean$(DL)
-	@echo $(DL)===========================================================$(DL)
-
-
diff --git a/win32/tests.dsp b/win32/tests.dsp
deleted file mode 100644
index b6df324..0000000
--- a/win32/tests.dsp
+++ /dev/null
@@ -1,102 +0,0 @@
-# Microsoft Developer Studio Project File - Name="tests" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=tests - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE 
-!MESSAGE NMAKE /f "tests.mak".
-!MESSAGE 
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE 
-!MESSAGE NMAKE /f "tests.mak" CFG="tests - Win32 Debug"
-!MESSAGE 
-!MESSAGE Possible choices for configuration are:
-!MESSAGE 
-!MESSAGE "tests - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "tests - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE 
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF  "$(CFG)" == "tests - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "tests___Win32_Release"
-# PROP BASE Intermediate_Dir "tests___Win32_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\include" /I "..\win32" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libeay32.lib ssleay32.lib ws2_32.lib zlib.lib libssh2.lib /nologo /subsystem:console /machine:I386 /libpath:"Release" /out:"simple.exe"
-
-!ELSEIF  "$(CFG)" == "tests - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "tests___Win32_Debug"
-# PROP BASE Intermediate_Dir "tests___Win32_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\win32" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libeay32.lib ssleay32.lib ws2_32.lib zlib.lib libssh2d.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /pdbtype:sept /libpath:"Debug" /out:"simple.exe"
-
-!ENDIF 
-
-# Begin Target
-
-# Name "tests - Win32 Release"
-# Name "tests - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=..\tests\simple.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# End Group
-# End Target
-# End Project
-- 
2.1.0


From d2dc259992b610eb8daaab7aa29951e4d113bb8e Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Wed, 3 Dec 2014 23:28:18 +0000
Subject: [PATCH 44/47] Added new README for CMake build process.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 README           | 154 ++++++++++++++++++++++++++++++++-----------------------
 README.autotools |  97 +++++++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+), 65 deletions(-)
 create mode 100644 README.autotools

diff --git a/README b/README
index 0ba17f9..927deb7 100644
--- a/README
+++ b/README
@@ -8,90 +8,114 @@ Web site: http://www.libssh2.org/
 
 Mailing list: http://cool.haxx.se/mailman/listinfo/libssh2-devel
 
-Generic installation instructions are in INSTALL.  Some ./configure
-options deserve additional comments:
+To build libssh2 you will need [CMake][1] v2.8 or later and one of the
+following cryptography libraries:
 
-	* --enable-crypt-none
+* OpenSSL
+* Libgcrypt
+* WinCNG
 
-		The SSH2 Transport allows for unencrypted data
-		transmission using the "none" cipher.  Because this is
-		such a huge security hole, it is typically disabled on
-		SSH2 implementations and is disabled in libssh2 by
-		default as well.
+Getting started
+---------------
 
-		Enabling this option will allow for "none" as a
-		negotiable method, however it still requires that the
-		method be advertized by the remote end and that no
-		more-preferable methods are available.
+If you are happy with the default options, make a new build directory,
+change to it, and run the following commands:
 
-	* --enable-mac-none
+  cmake <libssh2-source-directory>
+  cmake --build .
 
-		The SSH2 Transport also allows implementations to
-		forego a message authentication code.  While this is
-		less of a security risk than using a "none" cipher, it
-		is still not recommended as disabling MAC hashes
-		removes a layer of security.
+libssh2 will be built as a static library and will use any
+cryptography library available.
 
-		Enabling this option will allow for "none" as a
-		negotiable method, however it still requires that the
-		method be advertized by the remote end and that no
-		more-preferable methods are available.
+Customising the build
+---------------------
 
-	* --disable-gex-new
+Of course, you might want to customise the build options.  You can
+pass the options to CMake on the command line:
 
-		The diffie-hellman-group-exchange-sha1 (dh-gex) key
-		exchange method originally defined an exchange
-		negotiation using packet type 30 to request a
-		generation pair based on a single target value.  Later
-		refinement of dh-gex provided for range and target
-		values.  By default libssh2 will use the newer range
-		method.
+  cmake -D<option>=<value> <libssh2-source-directory>
 
-		If you experience trouble connecting to an old SSH
-		server using dh-gex, try this option to fallback on
-		the older more reliable method.
+The following options are available:
 
-  	* --with-libgcrypt
-  	* --without-libgcrypt
-	* --with-libgcrypt-prefix=DIR
+ * `BUILD_SHARED_LIBS=OFF`
 
-		libssh2 can use the Libgcrypt library
-		(http://www.gnupg.org/) for cryptographic operations.
-		Either Libgcrypt or OpenSSL is required.
+    Determines whether libssh2 is built as a static library or as a
+    shared library (.dll/.so).  Can be `ON` or `OFF`.
 
-		Configure will attempt to locate Libgcrypt
-		automatically.
+ * `CRYPTO_BACKEND=`
 
- 		If your installation of Libgcrypt is in another
-		location, specify it using --with-libgcrypt-prefix.
+    Chooses a specific cryptography library to use for cryptographic
+    operations.  Can be `OpenSSL` (http://www.openssl.org),
+    `Libgcrypt` (http://www.gnupg.org/), `WinCNG` (Windows Vista+) or
+    blank to use any library available.
 
-	* --with-openssl
-	* --without-openssl
-	* --with-libssl-prefix=[DIR]
+    CMake will attempt to locate the libraries automatically.  See [2]
+    for more information.
 
-		libssh2 can use the OpenSSL library
-		(http://www.openssl.org) for cryptographic operations.
-		Either Libgcrypt or OpenSSL is required.
+ * `ENABLE_ZLIB_COMPRESSION=OFF`
 
-		Configure will attempt to locate OpenSSL in the
-		default location.
+    Will use zlib (http://www.zlib.org) for payload compression.  Can
+    be `ON` or `OFF`.
 
-		If your installation of OpenSSL is in another
-		location, specify it using --with-libssl-prefix.
+ * `ENABLE_CRYPT_NONE=OFF`
 
-	* --with-libz
-	* --without-libz
-	* --with-libz-prefix=[DIR]
+    The SSH2 Transport allows for unencrypted data transmission using
+    the "none" cipher.  Because this is such a huge security hole, it
+    is typically disabled on SSH2 implementations and is disabled in
+    libssh2 by default as well.
 
-		If present, libssh2 will attempt to use the zlib
-		(http://www.zlib.org) for payload compression, however
-		zlib is not required.
+    Enabling this option will allow for "none" as a negotiable method,
+    however it still requires that the method be advertized by the
+    remote end and that no more-preferable methods are available.
 
-		If your installation of Libz is in another location,
-		specify it using --with-libz-prefix.
+ * `ENABLE_MAC_NONE=OFF`
 
-	* --enable-debug
+    The SSH2 Transport also allows implementations to forego a message
+    authentication code.  While this is less of a security risk than
+    using a "none" cipher, it is still not recommended as disabling
+    MAC hashes removes a layer of security.
 
-		Will make the build use more pedantic and strict compiler
-		options as well as enable the libssh2_trace() function (for
-		showing debug traces).
+    Enabling this option will allow for "none" as a negotiable method,
+    however it still requires that the method be advertized by the
+    remote end and that no more-preferable methods are available.
+
+ * `ENABLE_GEX_NEW=ON`
+
+    The diffie-hellman-group-exchange-sha1 (dh-gex) key exchange
+    method originally defined an exchange negotiation using packet
+    type 30 to request a generation pair based on a single target
+    value.  Later refinement of dh-gex provided for range and target
+    values.  By default libssh2 will use the newer range method.
+
+    If you experience trouble connecting to an old SSH server using
+    dh-gex, try this option to fallback on the older more reliable
+    method.
+
+ * `ENABLE_DEBUG_LOGGING=ON` in Debug, `=OFF` in Release
+
+    Will enable the libssh2_trace() function for showing debug traces.
+
+Build tools
+-----------
+
+The previous examples used CMake to start the build using:
+
+  cmake --build .
+
+Alternatively, once CMake has configured your project, you can just
+use your own build tool, e.g GNU make, Visual Studio, etc., from that
+point onwards.
+
+Tests
+-----
+
+To test the build, run the appropriate test target for your build
+system.  For example:
+
+  cmake --build . --target test
+or
+  cmake --build . --target RUN_TESTS
+
+
+[1] http://www.cmake.org/cmake/resources/software.html
+[2] http://www.cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html
\ No newline at end of file
diff --git a/README.autotools b/README.autotools
new file mode 100644
index 0000000..0ba17f9
--- /dev/null
+++ b/README.autotools
@@ -0,0 +1,97 @@
+libssh2 - SSH2 library
+======================
+
+libssh2 is a library implementing the SSH2 protocol, available under
+the revised BSD license.
+
+Web site: http://www.libssh2.org/
+
+Mailing list: http://cool.haxx.se/mailman/listinfo/libssh2-devel
+
+Generic installation instructions are in INSTALL.  Some ./configure
+options deserve additional comments:
+
+	* --enable-crypt-none
+
+		The SSH2 Transport allows for unencrypted data
+		transmission using the "none" cipher.  Because this is
+		such a huge security hole, it is typically disabled on
+		SSH2 implementations and is disabled in libssh2 by
+		default as well.
+
+		Enabling this option will allow for "none" as a
+		negotiable method, however it still requires that the
+		method be advertized by the remote end and that no
+		more-preferable methods are available.
+
+	* --enable-mac-none
+
+		The SSH2 Transport also allows implementations to
+		forego a message authentication code.  While this is
+		less of a security risk than using a "none" cipher, it
+		is still not recommended as disabling MAC hashes
+		removes a layer of security.
+
+		Enabling this option will allow for "none" as a
+		negotiable method, however it still requires that the
+		method be advertized by the remote end and that no
+		more-preferable methods are available.
+
+	* --disable-gex-new
+
+		The diffie-hellman-group-exchange-sha1 (dh-gex) key
+		exchange method originally defined an exchange
+		negotiation using packet type 30 to request a
+		generation pair based on a single target value.  Later
+		refinement of dh-gex provided for range and target
+		values.  By default libssh2 will use the newer range
+		method.
+
+		If you experience trouble connecting to an old SSH
+		server using dh-gex, try this option to fallback on
+		the older more reliable method.
+
+  	* --with-libgcrypt
+  	* --without-libgcrypt
+	* --with-libgcrypt-prefix=DIR
+
+		libssh2 can use the Libgcrypt library
+		(http://www.gnupg.org/) for cryptographic operations.
+		Either Libgcrypt or OpenSSL is required.
+
+		Configure will attempt to locate Libgcrypt
+		automatically.
+
+ 		If your installation of Libgcrypt is in another
+		location, specify it using --with-libgcrypt-prefix.
+
+	* --with-openssl
+	* --without-openssl
+	* --with-libssl-prefix=[DIR]
+
+		libssh2 can use the OpenSSL library
+		(http://www.openssl.org) for cryptographic operations.
+		Either Libgcrypt or OpenSSL is required.
+
+		Configure will attempt to locate OpenSSL in the
+		default location.
+
+		If your installation of OpenSSL is in another
+		location, specify it using --with-libssl-prefix.
+
+	* --with-libz
+	* --without-libz
+	* --with-libz-prefix=[DIR]
+
+		If present, libssh2 will attempt to use the zlib
+		(http://www.zlib.org) for payload compression, however
+		zlib is not required.
+
+		If your installation of Libz is in another location,
+		specify it using --with-libz-prefix.
+
+	* --enable-debug
+
+		Will make the build use more pedantic and strict compiler
+		options as well as enable the libssh2_trace() function (for
+		showing debug traces).
-- 
2.1.0


From c69638e0305d88be2c93d4d9bc0c834e873fe040 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Fri, 5 Dec 2014 23:55:43 +0000
Subject: [PATCH 45/47] Update README with explanation of how to consume
 libssh2 in another project.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 README | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 61 insertions(+), 6 deletions(-)

diff --git a/README b/README
index 927deb7..8209d0b 100644
--- a/README
+++ b/README
@@ -8,7 +8,7 @@ Web site: http://www.libssh2.org/
 
 Mailing list: http://cool.haxx.se/mailman/listinfo/libssh2-devel
 
-To build libssh2 you will need [CMake][1] v2.8 or later and one of the
+To build libssh2 you will need CMake v2.8 or later [1] and one of the
 following cryptography libraries:
 
 * OpenSSL
@@ -19,13 +19,17 @@ Getting started
 ---------------
 
 If you are happy with the default options, make a new build directory,
-change to it, and run the following commands:
+change to it, configure the build environment and build the project:
 
-  cmake <libssh2-source-directory>
+  mkdir bin
+  cd bin
+  cmake ..
   cmake --build .
 
 libssh2 will be built as a static library and will use any
-cryptography library available.
+cryptography library available.  The library binary will be put in
+`bin/src`, with the examples in `bin/example` and the tests in
+`bin/tests`.
 
 Customising the build
 ---------------------
@@ -33,7 +37,7 @@ Customising the build
 Of course, you might want to customise the build options.  You can
 pass the options to CMake on the command line:
 
-  cmake -D<option>=<value> <libssh2-source-directory>
+  cmake -D<option>=<value> ..
 
 The following options are available:
 
@@ -116,6 +120,57 @@ system.  For example:
 or
   cmake --build . --target RUN_TESTS
 
+How do I use libssh2 in my project if my project doesn't use CMake?
+-------------------------------------------------------------------
+
+If you are not using CMake for your own project, install libssh2
+
+  cmake <libssh2 source location>
+  cmake --build .
+  cmake --build . --target install
+or
+  cmake --build . --target INSTALL
+
+and then specify the install location to your project in the normal
+way for your build environment.  If you don't like the default install
+location, add `-DCMAKE_INSTALL_PREFIX=<chosen prefix>` when initially
+configuring the project.
+
+How can I use libssh2 in my project if it also uses CMake?
+----------------------------------------------------------
+
+If your own project also uses CMake, you don't need to worry about
+setting it up with libssh2's location.  Just add just the following
+lines and CMake will find libssh2 on your system, set up the necessary
+paths and link the library with your binary.
+
+    find_package(Libssh2 REQUIRED CONFIG)
+    target_link_libraries(my_project_target Libssh2::libssh2)
+
+Of course, you still have to make libssh2 available on your system
+first.  You can install it in the traditional way shown above, but you
+don't have to.  Instead you can just build it, which will export its
+location to the user package registry [3] where `find_package` will
+find it.
+
+You can even combine the two steps using a so-called 'superbuild'
+project [4] that downloads, builds and exports libssh2, and then
+builds your project:
+
+    include(ExternalProject)
+
+    ExternalProject_Add(
+        Libssh2
+        URL <libssh2 download location>
+        URL_HASH SHA1=<libssh2 archive SHA1>
+	INSTALL_COMMAND "")
+
+    ExternalProject_Add(
+        MyProject DEPENDS Libssh2
+        SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src
+        INSTALL_COMMAND "")
 
 [1] http://www.cmake.org/cmake/resources/software.html
-[2] http://www.cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html
\ No newline at end of file
+[2] http://www.cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html
+[3] http://www.cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html#package-registry
+[4] http://www.kitware.com/media/html/BuildingExternalProjectsWithCMake2.8.html
\ No newline at end of file
-- 
2.1.0


From 9b509f95a6c3f36679b03dff08d99d4709a001b3 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Sat, 6 Dec 2014 00:00:05 +0000
Subject: [PATCH 46/47] Put text files in libssh2-tagged install location.

Prevents them overwriting other files of the same name from another package.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f5f48c2..50c6c23 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -70,7 +70,7 @@ endif()
 
 install(
   FILES AUTHORS COPYING HACKING README RELEASE-NOTES NEWS
-  DESTINATION .)
+  DESTINATION share/libssh2)
 
 include(max_warnings)
 include(FeatureSummary)
-- 
2.1.0


From de4a53c9bf871db9935779d5b3a9d9d44636a144 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Sat, 6 Dec 2014 00:16:02 +0000
Subject: [PATCH 47/47] Restore files still needed to make autotools legacy
 builds work.

We should keep autotools build working for the moment.
This partially reverts commit 3c939b49eadbd1e629eab0a626c80cd71a23642d.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 Makefile.OpenSSL.inc   |   2 +
 Makefile.WinCNG.inc    |   2 +
 Makefile.am            |   4 +-
 Makefile.inc           |   6 ++
 Makefile.libgcrypt.inc |   2 +
 win32/Makefile.Watcom  | 182 +++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 196 insertions(+), 2 deletions(-)
 create mode 100644 Makefile.OpenSSL.inc
 create mode 100644 Makefile.WinCNG.inc
 create mode 100644 Makefile.inc
 create mode 100644 Makefile.libgcrypt.inc
 create mode 100644 win32/Makefile.Watcom

diff --git a/Makefile.OpenSSL.inc b/Makefile.OpenSSL.inc
new file mode 100644
index 0000000..76f3e85
--- /dev/null
+++ b/Makefile.OpenSSL.inc
@@ -0,0 +1,2 @@
+CRYPTO_CSOURCES = openssl.c
+CRYPTO_HHEADERS = openssl.h
diff --git a/Makefile.WinCNG.inc b/Makefile.WinCNG.inc
new file mode 100644
index 0000000..c18350e
--- /dev/null
+++ b/Makefile.WinCNG.inc
@@ -0,0 +1,2 @@
+CRYPTO_CSOURCES = wincng.c
+CRYPTO_HHEADERS = wincng.h
diff --git a/Makefile.am b/Makefile.am
index bc0d66d..f91da79 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,7 +22,7 @@ VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl	\
 vms/libssh2_make_kit.dcl vms/libssh2_make_lib.dcl vms/man2help.c	\
 vms/readme.vms vms/libssh2_config.h
 
-WIN32FILES = win32/libssh2.rc
+WIN32FILES = win32/Makefile.Watcom win32/libssh2.rc
 
 EXTRA_DIST = $(WIN32FILES) buildconf $(NETWAREFILES) get_ver.awk HACKING \
  maketgz NMakefile TODO RELEASE-NOTES libssh2.pc.in $(VMSFILES) config.rpath
@@ -32,7 +32,7 @@ ACLOCAL_AMFLAGS = -I m4
 .PHONY: ChangeLog
 ChangeLog:
 	echo "see NEWS" > ./ChangeLog
-DISTCLEANFILES += ChangeLog
+DISTCLEANFILES = ChangeLog
 
 dist-hook:
 	rm -rf $(top_builddir)/tests/log
diff --git a/Makefile.inc b/Makefile.inc
new file mode 100644
index 0000000..8f2e570
--- /dev/null
+++ b/Makefile.inc
@@ -0,0 +1,6 @@
+CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \
+ packet.c publickey.c scp.c session.c sftp.c userauth.c transport.c \
+ version.c knownhost.c agent.c $(CRYPTO_CSOURCES) pem.c keepalive.c global.c
+
+HHEADERS = libssh2_priv.h $(CRYPTO_HHEADERS) transport.h channel.h comp.h \
+ mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h
diff --git a/Makefile.libgcrypt.inc b/Makefile.libgcrypt.inc
new file mode 100644
index 0000000..5d56292
--- /dev/null
+++ b/Makefile.libgcrypt.inc
@@ -0,0 +1,2 @@
+CRYPTO_CSOURCES = libgcrypt.c
+CRYPTO_HHEADERS = libgcrypt.h
diff --git a/win32/Makefile.Watcom b/win32/Makefile.Watcom
new file mode 100644
index 0000000..f0f0408
--- /dev/null
+++ b/win32/Makefile.Watcom
@@ -0,0 +1,182 @@
+#
+#  Watcom / OpenWatcom Win32 makefile for libssh2.
+#
+#  Comments to: Guenter Knauf http://www.gknw.net/phpbb
+#
+
+!ifndef %watcom
+!error WATCOM environment variable not set!
+!else
+SYS_INCL = -I$(%watcom)\h\nt -I$(%watcom)\h
+SYS_LIBS = $(%watcom)\lib386\nt;$(%watcom)\lib386
+!endif
+
+!ifdef %libname
+LIBNAME = $(%libname)
+!else
+LIBNAME = libssh2
+!endif
+TARGETS = $(LIBNAME).dll $(LIBNAME)_imp.lib $(LIBNAME).lib
+
+CC = wcc386
+LD = wlink
+AR = wlib
+RC = wrc
+
+!ifdef __LOADDLL__
+!  loaddll wcc386  wccd386
+!  loaddll wpp386  wppd386
+!  loaddll wlib    wlibd
+!  if $(__VERSION__) > 1270
+!    loaddll wlink   wlinkd
+!  else
+!    loaddll wlink   wlink
+!  endif
+!endif
+
+!if $(__VERSION__) < 1250                                                                                                           
+RM = del /q /f 2>NUL
+!else                                                                                                                               
+RM = rm -f                                                                                                                          
+!endif
+MD = mkdir
+RD = rmdir /q /s 2>NUL
+CP = copy
+
+CFLAGS = -3r -mf -hc -zff -zgf -zq -zm -zc -s -fr=nul -w2 -fpi -oilrtfm &
+         -wcd=201 -bt=nt -d+ -dWIN32 -DLIBSSH2_WIN32 &
+         -I. -I..\include $(SYS_INCL)
+
+!ifdef %debug
+DEBUG  = -dDEBUG=1 -dDEBUGBUILD
+CFLAGS += -d3 $(DEBUG)
+!else
+CFLAGS += -d0
+!endif
+
+!ifdef %use_ipv6
+CFLAGS += -d_WIN32_WINNT=0x0501 -dENABLE_IPV6
+!endif
+
+#
+# Change to suite.
+#
+!ifdef %zlib_root
+ZLIB_ROOT = $(%zlib_root)
+!else
+ZLIB_ROOT = ..\..\zlib-1.2.7
+!endif
+
+!ifdef %openssl_root
+OPENSSL_ROOT = $(%openssl_root)
+!else
+OPENSSL_ROOT = ..\..\openssl-0.9.8y
+!endif
+
+#!ifdef %use_zlib
+CFLAGS += -dHAVE_ZLIB_H -dHAVE_LIBZ -I$(ZLIB_ROOT)
+#!endif
+
+#!ifdef %use_ssl
+CFLAGS += -wcd=138 -dUSE_OPENSSL -dUSE_SSLEAY -I$(OPENSSL_ROOT)\inc32
+#!endif
+
+!ifdef %use_watt32
+CFLAGS += -dUSE_WATT32 -I$(%watt_root)\inc
+!endif
+
+OBJ_BASE = WC_Win32.obj
+LINK_ARG = $(OBJ_BASE)\dyn\wlink.arg
+LIB_ARG  = $(OBJ_BASE)\stat\wlib.arg
+
+# In order to process Makefile.inc wmake must be called with -u switch!
+!ifndef %MAKEFLAGS
+!error You MUST call wmake with the -u switch!
+!else
+# only OpenSSL is supported with this build system
+CFLAGS += -dLIBSSH2_OPENSSL
+!include ..\Makefile.OpenSSL.inc
+!include ..\Makefile.inc
+!endif
+
+OBJS = $(CSOURCES:.c=.obj)
+OBJS = $OBJ_DIR\$(OBJS: = $OBJ_DIR\)
+
+#
+# Use $(OBJS) as a template to generate $(OBJS_STAT) and $(OBJS_DYN).
+#
+OBJ_DIR    = $(OBJ_BASE)\stat
+OBJS_STAT  = $+ $(OBJS) $-
+
+OBJ_DIR    = $(OBJ_BASE)\dyn
+OBJS_DYN   = $+ $(OBJS) $-
+
+RESOURCE   = $(OBJ_BASE)\dyn\libssh2.res
+
+.c: ..\src
+
+
+all: $(OBJ_BASE) $(TARGETS) .SYMBOLIC
+	@echo Welcome to libssh2
+
+clean: .SYMBOLIC
+	-$(RM) $(OBJS_STAT)
+	-$(RM) $(OBJS_DYN)
+	-$(RM) $(RESOURCE) $(LINK_ARG) $(LIB_ARG)
+
+vclean realclean: clean .SYMBOLIC
+	-$(RM) $(TARGETS) $(LIBNAME).map $(LIBNAME).sym
+	-$(RD) $(OBJ_BASE)\stat
+	-$(RD) $(OBJ_BASE)\dyn
+	-$(RD) $(OBJ_BASE)
+
+$(OBJ_BASE):
+	-$(MD) $^@
+	-$(MD) $^@\stat
+	-$(MD) $^@\dyn
+
+$(LIBNAME).dll: $(OBJS_DYN) $(RESOURCE) $(LINK_ARG)
+	$(LD) name $^@ @$]@
+
+$(LIBNAME).lib: $(OBJS_STAT) $(LIB_ARG)
+	$(AR) -q -b -c $^@ @$]@
+
+.ERASE
+$(RESOURCE): libssh2.rc
+	$(RC) $(DEBUG) -q -r -zm -I..\include $(SYS_INCL) $[@ -fo=$^@
+
+.ERASE
+.c{$(OBJ_BASE)\dyn}.obj:
+	$(CC) $(CFLAGS) -bd -br $[@ -fo=$^@
+
+.ERASE
+.c{$(OBJ_BASE)\stat}.obj:
+	$(CC) $(CFLAGS) $[@ -fo=$^@
+
+$(LINK_ARG): $(__MAKEFILES__)
+	%create $^@
+	@%append $^@ system nt dll
+	@%append $^@ file { $(OBJS_DYN) }
+!ifdef %debug
+	@%append $^@ debug all
+	@%append $^@ option symfile
+!endif
+	@%append $^@ option quiet, map, caseexact, eliminate, implib=$(LIBNAME)_imp.lib,
+	@%append $^@ res=$(RESOURCE) libpath $(SYS_LIBS)
+!ifdef %use_watt32
+	@%append $^@ library $(%watt_root)\lib\wattcpw_imp.lib
+!else
+	@%append $^@ library ws2_32.lib
+!endif
+#!ifdef %use_zlib
+	@%append $^@ library $(ZLIB_ROOT)\zlib.lib
+#!endif
+#!ifdef %use_ssl
+	@%append $^@ library $(OPENSSL_ROOT)\out32\libeay32.lib, $(OPENSSL_ROOT)\out32\ssleay32.lib
+#!endif
+
+$(LIB_ARG): $(__MAKEFILES__)
+	%create $^@
+	@for %f in ($(OBJS_STAT)) do @%append $^@ +- %f
+
+
-- 
2.1.0

From 739a1b9e5f09293a7b5135ffd7d1382c7099b041 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Mon, 8 Dec 2014 14:03:25 +0100
Subject: [PATCH] CMake: hard-wire SO version in src/CMakeLists.txt

---
 src/CMakeLists.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 93de53a..0053fee 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -186,7 +186,9 @@ endif()
 
 add_library(libssh2 ${SOURCES})
 # we want it to be called libssh2 on all platforms
-set_target_properties(libssh2 PROPERTIES PREFIX "")
+set_target_properties(libssh2 PROPERTIES PREFIX ""
+  SOVERSION 1
+  VERSION 1.0.1)
 
 target_compile_definitions(libssh2 PRIVATE ${PRIVATE_COMPILE_DEFINITIONS})
 target_include_directories(libssh2
-- 
2.1.0

From 1df2809089dd50353b12dee8aca31de4e413a7f3 Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamaison@gmail.com>
Date: Tue, 9 Dec 2014 00:39:53 +0000
Subject: [PATCH] Include man pages when installing.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 CMakeLists.txt      |   2 +
 docs/CMakeLists.txt | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 205 insertions(+)
 create mode 100644 docs/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 50c6c23..f951629 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -88,6 +88,8 @@ if(BUILD_TESTING)
   add_subdirectory(tests)
 endif()
 
+add_subdirectory(docs)
+
 feature_summary(WHAT ALL)
 
 set(CPACK_PACKAGE_VERSION_MAJOR ${LIBSSH2_VERSION_MAJOR})
diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt
new file mode 100644
index 0000000..fc94d8d
--- /dev/null
+++ b/docs/CMakeLists.txt
@@ -0,0 +1,203 @@
+# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
+#
+# Redistribution and use in source and binary forms,
+# with or without modification, are permitted provided
+# that the following conditions are met:
+#
+#   Redistributions of source code must retain the above
+#   copyright notice, this list of conditions and the
+#   following disclaimer.
+#
+#   Redistributions in binary form must reproduce the above
+#   copyright notice, this list of conditions and the following
+#   disclaimer in the documentation and/or other materials
+#   provided with the distribution.
+#
+#   Neither the name of the copyright holder nor the names
+#   of any other contributors may be used to endorse or
+#   promote products derived from this software without
+#   specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# OF SUCH DAMAGE.
+
+set(MAN_PAGES
+  libssh2_agent_connect.3
+  libssh2_agent_disconnect.3
+  libssh2_agent_free.3
+  libssh2_agent_get_identity.3
+  libssh2_agent_init.3
+  libssh2_agent_list_identities.3
+  libssh2_agent_userauth.3
+  libssh2_banner_set.3
+  libssh2_base64_decode.3
+  libssh2_channel_close.3
+  libssh2_channel_direct_tcpip.3
+  libssh2_channel_direct_tcpip_ex.3
+  libssh2_channel_eof.3
+  libssh2_channel_exec.3
+  libssh2_channel_flush.3
+  libssh2_channel_flush_ex.3
+  libssh2_channel_flush_stderr.3
+  libssh2_channel_forward_accept.3
+  libssh2_channel_forward_cancel.3
+  libssh2_channel_forward_listen.3
+  libssh2_channel_forward_listen_ex.3
+  libssh2_channel_free.3
+  libssh2_channel_get_exit_signal.3
+  libssh2_channel_get_exit_status.3
+  libssh2_channel_handle_extended_data.3
+  libssh2_channel_handle_extended_data2.3
+  libssh2_channel_ignore_extended_data.3
+  libssh2_channel_open_ex.3
+  libssh2_channel_open_session.3
+  libssh2_channel_process_startup.3
+  libssh2_channel_read.3
+  libssh2_channel_read_ex.3
+  libssh2_channel_read_stderr.3
+  libssh2_channel_receive_window_adjust.3
+  libssh2_channel_receive_window_adjust2.3
+  libssh2_channel_request_pty.3
+  libssh2_channel_request_pty_ex.3
+  libssh2_channel_request_pty_size.3
+  libssh2_channel_request_pty_size_ex.3
+  libssh2_channel_send_eof.3
+  libssh2_channel_set_blocking.3
+  libssh2_channel_setenv.3
+  libssh2_channel_setenv_ex.3
+  libssh2_channel_shell.3
+  libssh2_channel_subsystem.3
+  libssh2_channel_wait_closed.3
+  libssh2_channel_wait_eof.3
+  libssh2_channel_window_read.3
+  libssh2_channel_window_read_ex.3
+  libssh2_channel_window_write.3
+  libssh2_channel_window_write_ex.3
+  libssh2_channel_write.3
+  libssh2_channel_write_ex.3
+  libssh2_channel_write_stderr.3
+  libssh2_channel_x11_req.3
+  libssh2_channel_x11_req_ex.3
+  libssh2_exit.3
+  libssh2_free.3
+  libssh2_hostkey_hash.3
+  libssh2_init.3
+  libssh2_keepalive_config.3
+  libssh2_keepalive_send.3
+  libssh2_knownhost_add.3
+  libssh2_knownhost_addc.3
+  libssh2_knownhost_check.3
+  libssh2_knownhost_checkp.3
+  libssh2_knownhost_del.3
+  libssh2_knownhost_free.3
+  libssh2_knownhost_get.3
+  libssh2_knownhost_init.3
+  libssh2_knownhost_readfile.3
+  libssh2_knownhost_readline.3
+  libssh2_knownhost_writefile.3
+  libssh2_knownhost_writeline.3
+  libssh2_poll.3
+  libssh2_poll_channel_read.3
+  libssh2_publickey_add.3
+  libssh2_publickey_add_ex.3
+  libssh2_publickey_init.3
+  libssh2_publickey_list_fetch.3
+  libssh2_publickey_list_free.3
+  libssh2_publickey_remove.3
+  libssh2_publickey_remove_ex.3
+  libssh2_publickey_shutdown.3
+  libssh2_scp_recv.3
+  libssh2_scp_send.3
+  libssh2_scp_send64.3
+  libssh2_scp_send_ex.3
+  libssh2_session_abstract.3
+  libssh2_session_banner_get.3
+  libssh2_session_banner_set.3
+  libssh2_session_block_directions.3
+  libssh2_session_callback_set.3
+  libssh2_session_disconnect.3
+  libssh2_session_disconnect_ex.3
+  libssh2_session_flag.3
+  libssh2_session_free.3
+  libssh2_session_get_blocking.3
+  libssh2_session_get_timeout.3
+  libssh2_session_hostkey.3
+  libssh2_session_init.3
+  libssh2_session_init_ex.3
+  libssh2_session_last_errno.3
+  libssh2_session_last_error.3
+  libssh2_session_method_pref.3
+  libssh2_session_methods.3
+  libssh2_session_set_blocking.3
+  libssh2_session_set_timeout.3
+  libssh2_session_startup.3
+  libssh2_session_supported_algs.3
+  libssh2_sftp_close.3
+  libssh2_sftp_close_handle.3
+  libssh2_sftp_closedir.3
+  libssh2_sftp_fsetstat.3
+  libssh2_sftp_fstat.3
+  libssh2_sftp_fstat_ex.3
+  libssh2_sftp_fstatvfs.3
+  libssh2_sftp_fsync.3
+  libssh2_sftp_get_channel.3
+  libssh2_sftp_init.3
+  libssh2_sftp_last_error.3
+  libssh2_sftp_lstat.3
+  libssh2_sftp_mkdir.3
+  libssh2_sftp_mkdir_ex.3
+  libssh2_sftp_open.3
+  libssh2_sftp_open_ex.3
+  libssh2_sftp_opendir.3
+  libssh2_sftp_read.3
+  libssh2_sftp_readdir.3
+  libssh2_sftp_readdir_ex.3
+  libssh2_sftp_readlink.3
+  libssh2_sftp_realpath.3
+  libssh2_sftp_rename.3
+  libssh2_sftp_rename_ex.3
+  libssh2_sftp_rewind.3
+  libssh2_sftp_rmdir.3
+  libssh2_sftp_rmdir_ex.3
+  libssh2_sftp_seek.3
+  libssh2_sftp_seek64.3
+  libssh2_sftp_setstat.3
+  libssh2_sftp_shutdown.3
+  libssh2_sftp_stat.3
+  libssh2_sftp_stat_ex.3
+  libssh2_sftp_statvfs.3
+  libssh2_sftp_symlink.3
+  libssh2_sftp_symlink_ex.3
+  libssh2_sftp_tell.3
+  libssh2_sftp_tell64.3
+  libssh2_sftp_unlink.3
+  libssh2_sftp_unlink_ex.3
+  libssh2_sftp_write.3
+  libssh2_trace.3
+  libssh2_trace_sethandler.3
+  libssh2_userauth_authenticated.3
+  libssh2_userauth_hostbased_fromfile.3
+  libssh2_userauth_hostbased_fromfile_ex.3
+  libssh2_userauth_keyboard_interactive.3
+  libssh2_userauth_keyboard_interactive_ex.3
+  libssh2_userauth_list.3
+  libssh2_userauth_password.3
+  libssh2_userauth_password_ex.3
+  libssh2_userauth_publickey.3
+  libssh2_userauth_publickey_fromfile.3
+  libssh2_userauth_publickey_fromfile_ex.3
+  libssh2_version.3)
+
+install(FILES ${MAN_PAGES} DESTINATION share/man/man3)
-- 
2.1.0