From 1834ca38200a46e4d1f539f2ec7c1bcd93564b9a Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Fri, 27 Aug 2010 11:52:09 +0200 Subject: Added a SSH_NO_CPP_EXCEPTIONS mode to libsshpp.h --- examples/CMakeLists.txt | 2 ++ examples/libsshpp_noexcept.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 examples/libsshpp_noexcept.cpp (limited to 'examples') diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 867869c8..ad614294 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -19,6 +19,7 @@ add_executable(senddata senddata.c ${examples_SRCS}) add_executable(sshnetcat sshnetcat.c ${examples_SRCS}) add_executable(libsshpp libsshpp.cpp) +add_executable(libsshpp_noexcept libsshpp_noexcept.cpp) target_link_libraries(libssh_scp ${LIBSSH_SHARED_LIBRARY}) target_link_libraries(scp_download ${LIBSSH_SHARED_LIBRARY}) @@ -26,6 +27,7 @@ target_link_libraries(samplessh ${LIBSSH_SHARED_LIBRARY}) target_link_libraries(exec ${LIBSSH_SHARED_LIBRARY}) target_link_libraries(senddata ${LIBSSH_SHARED_LIBRARY}) target_link_libraries(libsshpp ${LIBSSH_SHARED_LIBRARY}) +target_link_libraries(libsshpp_noexcept ${LIBSSH_SHARED_LIBRARY}) target_link_libraries(sshnetcat ${LIBSSH_SHARED_LIBRARY}) diff --git a/examples/libsshpp_noexcept.cpp b/examples/libsshpp_noexcept.cpp new file mode 100644 index 00000000..624cfe9f --- /dev/null +++ b/examples/libsshpp_noexcept.cpp @@ -0,0 +1,41 @@ +/* +Copyright 2010 Aris Adamantiadis + +This file is part of the SSH Library + +You are free to copy this file, modify it in any way, consider it being public +domain. This does not apply to the rest of the library though, but it is +allowed to cut-and-paste working code from this file to any license of +program. +*/ + +/* This file demonstrates the use of the C++ wrapper to libssh + * specifically, without C++ exceptions + */ + +#include +#define SSH_NO_CPP_EXCEPTIONS +#include + +int main(int argc, const char **argv){ + ssh::Session session,s2; + int err; + if(argc>1) + err=session.setOption(SSH_OPTIONS_HOST,argv[1]); + else + err=session.setOption(SSH_OPTIONS_HOST,"localhost"); + if(err==SSH_ERROR) + goto error; + err=session.connect(); + if(err==SSH_ERROR) + goto error; + err=session.userauthAutopubkey(); + if(err==SSH_ERROR) + goto error; + + return 0; + error: + std::cout << "Error during connection : "; + std::cout << session.getError() << std::endl; + return 1; +} -- cgit