From 86faf2d268d8e1404da9577a6ee6d5ffda3bda7a Mon Sep 17 00:00:00 2001 From: norrarvid Date: Fri, 13 Apr 2012 13:16:08 +0200 Subject: [PATCH] connect error codes added --- include/freerdp/freerdp.h | 1 + libfreerdp-core/connection.c | 3 +++ libfreerdp-core/freerdp.c | 14 +++++++++++++- libfreerdp-core/transport.c | 10 ++++++++++ libfreerdp-utils/tcp.c | 21 ++++++++++++++++++++- 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index e00e1bd15..e6830855a 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -39,6 +39,7 @@ typedef struct rdp_freerdp_peer freerdp_peer; #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/libfreerdp-core/connection.c b/libfreerdp-core/connection.c index aab4a1bc3..175ae82cc 100644 --- a/libfreerdp-core/connection.c +++ b/libfreerdp-core/connection.c @@ -103,6 +103,9 @@ boolean rdp_client_connect(rdpRdp* rdp) if (mcs_send_connect_initial(rdp->mcs) != true) { + if(!connectErrorCode){ + connectErrorCode = MCSCONNECTINITIALERROR; + } printf("Error: unable to send MCS Connect Initial\n"); return false; } diff --git a/libfreerdp-core/freerdp.c b/libfreerdp-core/freerdp.c index e5364d7a2..e059492d8 100644 --- a/libfreerdp-core/freerdp.c +++ b/libfreerdp-core/freerdp.c @@ -28,6 +28,8 @@ #include #include +/* connectErrorCode is 'extern' in errorcodes.h. See comment there.*/ + /** Creates a new connection based on the settings found in the "instance" parameter * It will use the callbacks registered on the structure to process the pre/post connect operations * that the caller requires. @@ -43,6 +45,8 @@ boolean freerdp_connect(freerdp* instance) { rdpRdp* rdp; boolean status = false; + /* We always set the return code to 0 before we start the connect sequence*/ + connectErrorCode = 0 ; rdp = instance->context->rdp; @@ -52,6 +56,9 @@ boolean freerdp_connect(freerdp* instance) if (status != true) { + if(!connectErrorCode){ + connectErrorCode = PREECONNECTERROR; + } printf("freerdp_pre_connect failed\n"); return false; } @@ -74,6 +81,9 @@ boolean freerdp_connect(freerdp* instance) if (status != true) { printf("freerdp_post_connect failed\n"); + if(!connectErrorCode){ + connectErrorCode = POSTCONNECTERROR; + } return false; } @@ -109,7 +119,9 @@ boolean freerdp_connect(freerdp* instance) return true; } } - + if(!connectErrorCode){ + connectErrorCode = UNDEFINEDCONNECTERROR; + } return status; } diff --git a/libfreerdp-core/transport.c b/libfreerdp-core/transport.c index 06dab0ee0..614e050be 100644 --- a/libfreerdp-core/transport.c +++ b/libfreerdp-core/transport.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -93,6 +94,9 @@ boolean transport_connect_tls(rdpTransport* transport) transport->tls->sockfd = transport->tcp->sockfd; if (tls_connect(transport->tls) != true) { + if(!connectErrorCode){ + connectErrorCode = TLSCONNECTERROR; + } tls_free(transport->tls); transport->tls = NULL; return false; @@ -113,6 +117,9 @@ boolean transport_connect_nla(rdpTransport* transport) transport->tls->sockfd = transport->tcp->sockfd; if (tls_connect(transport->tls) != true) { + if(!connectErrorCode){ + connectErrorCode = TLSCONNECTERROR; + } tls_free(transport->tls); transport->tls = NULL; return false; @@ -131,6 +138,9 @@ boolean transport_connect_nla(rdpTransport* transport) if (credssp_authenticate(transport->credssp) < 0) { + if(!connectErrorCode){ + connectErrorCode = AUTHENTICATIONERROR; + } printf("Authentication failure, check credentials.\n" "If credentials are valid, the NTLMSSP implementation may be to blame.\n"); diff --git a/libfreerdp-utils/tcp.c b/libfreerdp-utils/tcp.c index 695855d15..01f4e6e2e 100644 --- a/libfreerdp-utils/tcp.c +++ b/libfreerdp-utils/tcp.c @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -55,6 +56,9 @@ #endif +/* connectErrorCode is 'extern' in errorcodes.h. See comment there.*/ +int connectErrorCode ; + int freerdp_tcp_connect(const char* hostname, int port) { int status; @@ -73,6 +77,14 @@ int freerdp_tcp_connect(const char* hostname, int port) if (status != 0) { + if(status==EAI_NONAME){ + if(!connectErrorCode){ + connectErrorCode = DNSNAMENOTFOUND; + } + } + if(!connectErrorCode){ + connectErrorCode = DNSERROR; + } printf("tcp_connect: getaddrinfo (%s)\n", gai_strerror(status)); return -1; } @@ -90,7 +102,14 @@ int freerdp_tcp_connect(const char* hostname, int port) printf("connected to %s:%s\n", hostname, servname); break; } - + if(!connectErrorCode){ + int tmperror = errno ; + if(tmperror!=0){ + connectErrorCode = tmperror ; + }else{ + connectErrorCode = CONNECTERROR; + } + } close(sockfd); sockfd = -1; }