aboutsummaryrefslogtreecommitdiff
path: root/bindings
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-08-04 14:18:00 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2011-09-15 14:15:28 +0300
commitb4e9659ae72be31fb4b345efeaf0f66607ed73fa (patch)
tree8ef6f7bf0b60a58c280a2cb48f0306b127886075 /bindings
parent544747d02cd4c8b6ad2b6e8a8bf35e0242ba2d2e (diff)
downloadlibssh-b4e9659ae72be31fb4b345efeaf0f66607ed73fa.tar.gz
libssh-b4e9659ae72be31fb4b345efeaf0f66607ed73fa.tar.xz
libssh-b4e9659ae72be31fb4b345efeaf0f66607ed73fa.zip
binding: Added python bindings support using swig.
Diffstat (limited to 'bindings')
-rw-r--r--bindings/CMakeLists.txt11
-rw-r--r--bindings/python/CMakeLists.txt26
-rw-r--r--bindings/ssh-options.i23
-rw-r--r--bindings/ssh.i54
4 files changed, 114 insertions, 0 deletions
diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt
new file mode 100644
index 00000000..b5cbd722
--- /dev/null
+++ b/bindings/CMakeLists.txt
@@ -0,0 +1,11 @@
+project(LIBSSH_BINDINGS)
+
+include(${SWIG_USE_FILE})
+
+set(SWIG_INPUT "${CMAKE_CURRENT_SOURCE_DIR}/ssh.i")
+
+find_package(PythonLibs)
+
+if (PYTHON_LIBRARY AND PYTHON_INCLUDE_PATH)
+ add_subdirectory(python)
+endif (PYTHON_LIBRARY AND PYTHON_INCLUDE_PATH)
diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt
new file mode 100644
index 00000000..4d410339
--- /dev/null
+++ b/bindings/python/CMakeLists.txt
@@ -0,0 +1,26 @@
+project(libssh-python CXX)
+
+set(SWIG_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ssh_python.cpp")
+
+find_package(PythonInterp REQUIRED)
+execute_process(
+ COMMAND
+ ${PYTHON_EXECUTABLE} -c "from sys import stdout; from distutils import sysconfig; stdout.write(sysconfig.get_python_lib())"
+ OUTPUT_VARIABLE
+ PYTHON_LIB_DIR
+)
+
+if (NOT PYTHON_SITEDIR)
+ set(PYTHON_SITEDIR ${PYTHON_LIB_DIR})
+endif (NOT PYTHON_SITEDIR)
+
+include_directories(${LIBSSH_PUBLIC_INCLUDE_DIRS} ${PYTHON_INCLUDE_PATH})
+
+set_source_files_properties(${SWIG_INPUT} PROPERTIES CPLUSPLUS ON)
+# Py_True and Py_False are a bit tricky
+set_source_files_properties(${swig_generated_file_fullname} PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing")
+swig_add_module(ssh python ${SWIG_INPUT})
+swig_link_libraries(ssh ${LIBSSH_SHARED_LIBRARY} ${PYTHON_LIBRARIES})
+
+install(TARGETS ${SWIG_MODULE_ssh_REAL_NAME} LIBRARY DESTINATION ${PYTHON_SITEDIR})
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ssh.py DESTINATION ${PYTHON_SITEDIR})
diff --git a/bindings/ssh-options.i b/bindings/ssh-options.i
new file mode 100644
index 00000000..d67ca6f2
--- /dev/null
+++ b/bindings/ssh-options.i
@@ -0,0 +1,23 @@
+typedef struct {} options;
+%extend options {
+ Options() {
+ Options *opt = ssh_options_new();
+ if (opt == NULL) {
+ return NULL;
+ } else {
+ return opt;
+ }
+ }
+
+ ~Options() {
+ ssh_options_free(self);
+ }
+
+ void setWantedAlogs(int algo, const char *list) {
+ ssh_options_set_wanted_algos(self, algo, list);
+ }
+
+ void setUsername(const char *name) {
+ ssh_options_set_username(self, name);
+ }
+};
diff --git a/bindings/ssh.i b/bindings/ssh.i
new file mode 100644
index 00000000..eff9e1b5
--- /dev/null
+++ b/bindings/ssh.i
@@ -0,0 +1,54 @@
+/* libssh bindings */
+%module ssh
+
+%feature("autodoc", "1");
+%include "stl.i"
+%include "std_string.i"
+
+%{
+ #include "libssh/libsshpp.hpp"
+%}
+
+enum ssh_options_e {
+ SSH_OPTIONS_HOST,
+ SSH_OPTIONS_PORT,
+ SSH_OPTIONS_PORT_STR,
+ SSH_OPTIONS_FD,
+ SSH_OPTIONS_USER,
+ SSH_OPTIONS_SSH_DIR,
+ SSH_OPTIONS_IDENTITY,
+ SSH_OPTIONS_ADD_IDENTITY,
+ SSH_OPTIONS_KNOWNHOSTS,
+ SSH_OPTIONS_TIMEOUT,
+ SSH_OPTIONS_TIMEOUT_USEC,
+ SSH_OPTIONS_SSH1,
+ SSH_OPTIONS_SSH2,
+ SSH_OPTIONS_LOG_VERBOSITY,
+ SSH_OPTIONS_LOG_VERBOSITY_STR,
+ SSH_OPTIONS_CIPHERS_C_S,
+ SSH_OPTIONS_CIPHERS_S_C,
+ SSH_OPTIONS_COMPRESSION_C_S,
+ SSH_OPTIONS_COMPRESSION_S_C,
+ SSH_OPTIONS_HOSTKEYCHECK,
+ SSH_OPTIONS_PROXYCOMMAND,
+ SSH_OPTIONS_BINDADDR
+};
+
+enum ssh_server_known_e {
+ SSH_SERVER_ERROR = -1,
+ SSH_SERVER_NOT_KNOWN = 0,
+ SSH_SERVER_KNOWN_OK,
+ SSH_SERVER_KNOWN_CHANGED,
+ SSH_SERVER_FOUND_OTHER,
+ SSH_SERVER_FILE_NOT_FOUND
+};
+
+enum ssh_auth_e {
+ SSH_AUTH_SUCCESS = 0,
+ SSH_AUTH_DENIED,
+ SSH_AUTH_PARTIAL,
+ SSH_AUTH_INFO,
+ SSH_AUTH_ERROR = -1
+};
+
+%include libssh/libsshpp.hpp