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.
pull/1/head
John Safranek 2014-08-11 14:29:06 -07:00
parent a96a764bc0
commit 490fd75fa9
6 changed files with 80 additions and 86 deletions

View File

@ -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 <config.h>
#endif
#include <wolfssh/ssh.h>
#include <wolfssh/log.h>
#include <wolfssh/error.h>
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
}

View File

@ -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}

View File

@ -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;

View File

@ -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) {

View File

@ -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 */

View File

@ -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*);