From 490fd75fa94888068a75f0904b1d90eed2309e19 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Mon, 11 Aug 2014 14:29:06 -0700 Subject: [PATCH] 1. Moved error number to string conversion to internal.c 2. Removed file error.c 3. Added error code accessor for WOLFSSH objects. 4. Added error string accesor for WOLFSSH objects. 5. Cleaned up the I/O callback prototypes. --- src/error.c | 81 ---------------------------------------------- src/include.am | 3 +- src/internal.c | 52 +++++++++++++++++++++++++++++ src/ssh.c | 20 ++++++++++++ wolfssh/internal.h | 7 ++-- wolfssh/ssh.h | 3 +- 6 files changed, 80 insertions(+), 86 deletions(-) delete mode 100644 src/error.c diff --git a/src/error.c b/src/error.c deleted file mode 100644 index eba623a..0000000 --- a/src/error.c +++ /dev/null @@ -1,81 +0,0 @@ -/* error.c - * - * Copyright (C) 2014 wolfSSL Inc. - * - * This file is part of wolfSSH. - * - * wolfSSH is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * wolfSSH is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include -#include -#include - - -const char* wolfSSH_get_error(int err) -{ -#ifdef NO_WOLFSSH_STRINGS - return "No wolfSSH strings available"; -#else - switch (err) { - case WS_SUCCESS: - return "function success"; - - case WS_FATAL_ERROR: - return "general function failure"; - - case WS_BAD_ARGUMENT: - return "bad function argument"; - - case WS_MEMORY_E: - return "memory allocation failure"; - - case WS_BUFFER_E: - return "input/output buffer size error"; - - case WS_PARSE_E: - return "general parsing error"; - - case WS_NOT_COMPILED: - return "feature not compiled in"; - - case WS_OVERFLOW_E: - return "would overflow if continued failure"; - - case WS_BAD_USAGE: - return "bad example usage"; - - case WS_SOCKET_ERROR_E: - return "socket error"; - - case WS_WANT_READ: - return "I/O callback would read block error"; - - case WS_WANT_WRITE: - return "I/O callback would write block error"; - - case WS_RECV_OVERFLOW_E: - return "receive buffer overflow"; - default: - - return "Unknown error code"; - } -#endif -} - diff --git a/src/include.am b/src/include.am index 8f59269..8157f94 100644 --- a/src/include.am +++ b/src/include.am @@ -9,8 +9,7 @@ src_libwolfssh_la_SOURCES = src/ssh.c \ src/memory.c \ src/log.c \ src/io.c \ - src/port.c \ - src/error.c + src/port.c src_libwolfssh_la_CFLAGS = -DBUILDING_WOLFSSH $(AM_CFLAGS) src_libwolfssh_la_CPPFLAGS = -DBUILDING_WOLFSSH $(AM_CPPFLAGS) src_libwolfssh_la_LDFLAGS = ${AM_LDFLAGS} -no-undefined -version-info ${WOLFSSH_LIBRARY_VERSION} diff --git a/src/internal.c b/src/internal.c index c89ac2e..9ccb7d0 100644 --- a/src/internal.c +++ b/src/internal.c @@ -36,6 +36,58 @@ static /*INLINE*/ void ato32(const uint8_t* c, uint32_t* u32) } +const char* GetErrorString(int err) +{ +#ifdef NO_WOLFSSH_STRINGS + return "No wolfSSH strings available"; +#else + switch (err) { + case WS_SUCCESS: + return "function success"; + + case WS_FATAL_ERROR: + return "general function failure"; + + case WS_BAD_ARGUMENT: + return "bad function argument"; + + case WS_MEMORY_E: + return "memory allocation failure"; + + case WS_BUFFER_E: + return "input/output buffer size error"; + + case WS_PARSE_E: + return "general parsing error"; + + case WS_NOT_COMPILED: + return "feature not compiled in"; + + case WS_OVERFLOW_E: + return "would overflow if continued failure"; + + case WS_BAD_USAGE: + return "bad example usage"; + + case WS_SOCKET_ERROR_E: + return "socket error"; + + case WS_WANT_READ: + return "I/O callback would read block error"; + + case WS_WANT_WRITE: + return "I/O callback would write block error"; + + case WS_RECV_OVERFLOW_E: + return "receive buffer overflow"; + + default: + return "Unknown error code"; + } +#endif +} + + typedef struct { uint8_t id; const char* name; diff --git a/src/ssh.c b/src/ssh.c index 4ed0f1c..ff3f3f4 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -209,6 +209,26 @@ int wolfSSH_get_fd(const WOLFSSH* ssh) } +int wolfSSH_get_error(const WOLFSSH* ssh) +{ + WLOG(WS_LOG_DEBUG, "Enter wolfSSH_get_error()"); + if (ssh) + return ssh->error; + + return WS_BAD_ARGUMENT; +} + + +const char* wolfSSH_get_error_name(const WOLFSSH* ssh) +{ + WLOG(WS_LOG_DEBUG, "Enter wolfSSH_get_error_name()"); + if (ssh) + return GetErrorString(ssh->error); + + return NULL; +} + + int wolfSSH_accept(WOLFSSH* ssh) { switch (ssh->acceptState) { diff --git a/wolfssh/internal.h b/wolfssh/internal.h index 746676c..9af1ff4 100644 --- a/wolfssh/internal.h +++ b/wolfssh/internal.h @@ -44,6 +44,9 @@ extern "C" { #endif +WOLFSSH_LOCAL const char* GetErrorString(int); + + enum { /* Any of the items can be none. */ ID_NONE = 0, @@ -135,8 +138,8 @@ struct WOLFSSH { #ifndef WOLFSSH_USER_IO /* default I/O handlers */ -WOLFSSH_LOCAL int wsEmbedRecv(WOLFSSH* ssh, void*, uint32_t sz, void* ctx); -WOLFSSH_LOCAL int wsEmbedSend(WOLFSSH* ssh, void*, uint32_t sz, void* ctx); +WOLFSSH_LOCAL int wsEmbedRecv(WOLFSSH*, void*, uint32_t, void*); +WOLFSSH_LOCAL int wsEmbedSend(WOLFSSH*, void*, uint32_t, void*); #endif /* WOLFSSH_USER_IO */ diff --git a/wolfssh/ssh.h b/wolfssh/ssh.h index dfc75e4..6087a0b 100644 --- a/wolfssh/ssh.h +++ b/wolfssh/ssh.h @@ -54,7 +54,8 @@ WOLFSSH_API void wolfSSH_free(WOLFSSH*); WOLFSSH_API int wolfSSH_set_fd(WOLFSSH*, int); WOLFSSH_API int wolfSSH_get_fd(const WOLFSSH*); -WOLFSSH_API const char* wolfSSH_get_error(int); +WOLFSSH_API int wolfSSH_get_error(const WOLFSSH*); +WOLFSSH_API const char* wolfSSH_get_error_name(const WOLFSSH*); /* I/O callbacks */ typedef int (*WS_CallbackIORecv)(WOLFSSH*, void*, uint32_t, void*);