From 7e9981c6ecd7f1cd05a0b1b256e3e69fa0268eea Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 9 Jan 2019 14:25:28 -0800 Subject: [PATCH] Updated the main API, echoserver, client, and server for the NO_WOLFSSH_SERVER and NO_WOLFSSH_CLIENT options. --- examples/client/client.c | 7 ++++++- examples/echoserver/echoserver.c | 11 +++++++---- examples/server/server.c | 7 +++++++ src/ssh.c | 13 +++++++++++-- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/examples/client/client.c b/examples/client/client.c index b7aa9f2..1111782 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -20,7 +20,6 @@ #define WOLFSSH_TEST_CLIENT - #include #include #include "examples/client/client.h" @@ -28,6 +27,8 @@ #include #endif +#ifndef NO_WOLFSSH_CLIENT + const char testString[] = "Hello, wolfSSH!"; @@ -323,6 +324,8 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args) return 0; } +#endif /* NO_WOLFSSH_CLIENT */ + #ifndef NO_MAIN_DRIVER @@ -344,7 +347,9 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args) wolfSSH_Init(); ChangeToWolfSshRoot(); +#ifndef NO_WOLFSSH_CLIENT client_test(&args); +#endif wolfSSH_Cleanup(); diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index 100b7e8..7850003 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -46,6 +46,8 @@ #endif +#ifndef NO_WOLFSSH_SERVER + static const char echoserverBanner[] = "wolfSSH Example Echo Server\n"; @@ -179,14 +181,11 @@ static int ssh_worker(thread_ctx_t* threadCtx) { * returns 0 on success */ static int sftp_worker(thread_ctx_t* threadCtx) { - int ret = 0; + int ret; - (void)threadCtx; -#ifndef NO_WOLFSSH_SERVER do { ret = wolfSSH_SFTP_read(threadCtx->ssh); } while (ret != WS_FATAL_ERROR); -#endif return ret; } @@ -815,6 +814,8 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) return 0; } +#endif /* NO_WOLFSSH_SERVER */ + #ifndef NO_MAIN_DRIVER @@ -836,7 +837,9 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) #ifndef WOLFSSL_NUCLEUS ChangeToWolfSshRoot(); #endif +#ifndef NO_WOLFSSH_SERVER echoserver_test(&args); +#endif wolfSSH_Cleanup(); diff --git a/examples/server/server.c b/examples/server/server.c index 54822bc..0c10ed8 100644 --- a/examples/server/server.c +++ b/examples/server/server.c @@ -39,6 +39,8 @@ #endif +#ifndef NO_WOLFSSH_SERVER + static const char serverBanner[] = "wolfSSH Example Server\n"; @@ -709,6 +711,9 @@ THREAD_RETURN WOLFSSH_THREAD server_test(void* args) return 0; } +#endif /* NO_WOLFSSH_SERVER */ + + #ifndef NO_MAIN_DRIVER int main(int argc, char** argv) @@ -728,7 +733,9 @@ THREAD_RETURN WOLFSSH_THREAD server_test(void* args) wolfSSH_Init(); +#ifndef NO_WOLFSSH_SERVER server_test(&args); +#endif wolfSSH_Cleanup(); diff --git a/src/ssh.c b/src/ssh.c index e77c4ce..5430a40 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -254,6 +254,8 @@ const char* wolfSSH_ErrorToName(int err) } +#ifndef NO_WOLFSSH_SERVER + const char acceptError[] = "accept error: %s, %d"; const char acceptState[] = "accept state: %s"; @@ -434,6 +436,10 @@ int wolfSSH_accept(WOLFSSH* ssh) return WS_SUCCESS; } +#endif /* NO_WOLFSSH_SERVER */ + + +#ifndef NO_WOLFSSH_CLIENT const char connectError[] = "connect error: %s, %d"; const char connectState[] = "connect state: %s"; @@ -473,7 +479,7 @@ int wolfSSH_connect(WOLFSSH* ssh) case CONNECT_SERVER_VERSION_DONE: if ( (ssh->error = SendKexInit(ssh)) < WS_SUCCESS) { - WLOG(WS_LOG_DEBUG, acceptError, + WLOG(WS_LOG_DEBUG, connectError, "SERVER_VERSION_DONE", ssh->error); return WS_FATAL_ERROR; } @@ -648,6 +654,8 @@ int wolfSSH_connect(WOLFSSH* ssh) return WS_SUCCESS; } +#endif /* NO_WOLFSSH_CLIENT */ + int wolfSSH_shutdown(WOLFSSH* ssh) { @@ -1232,7 +1240,8 @@ int wolfSSH_ChannelSend(WOLFSSH_CHANNEL* channel, { int bytesTxd = 0; - WLOG(WS_LOG_DEBUG, "Entering wolfSSH_ChannelSend(), ID = %d, peerID = %d", channel->channel, channel->peerChannel); + WLOG(WS_LOG_DEBUG, "Entering wolfSSH_ChannelSend(), ID = %d, peerID = %d", + channel->channel, channel->peerChannel); #ifdef DEBUG_WOLFSSH DumpOctetString(buf, bufSz);