From fc099127ccf39f81eb0a03e27c253ea02cbe3f71 Mon Sep 17 00:00:00 2001 From: Marcel Poul Date: Sun, 18 Dec 2011 22:10:03 +0000 Subject: [PATCH] do not use openSSL method calls in canl API --- emi.canl.canl-c/src/canl.c | 23 +++++++++++++++-------- emi.canl.canl-c/src/canl_ssl.c | 6 +++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/emi.canl.canl-c/src/canl.c b/emi.canl.canl-c/src/canl.c index 8b75cbc..010641a 100644 --- a/emi.canl.canl-c/src/canl.c +++ b/emi.canl.canl-c/src/canl.c @@ -4,6 +4,7 @@ static void io_destroy(glb_ctx *cc, io_handler *io); static int init_io_content(glb_ctx *cc, io_handler *io); static int try_connect(glb_ctx *glb_cc, io_handler *io_cc, char *addr, int addrtype, int port, struct timeval *timeout); +static void ssl_init(); canl_ctx canl_create_ctx() { @@ -14,9 +15,15 @@ canl_ctx canl_create_ctx() if (!ctx) return NULL; + ssl_init(); + + return ctx; +} + +static void ssl_init() +{ SSL_library_init(); SSL_load_error_strings(); - return ctx; } void canl_free_ctx(canl_ctx cc) @@ -131,10 +138,12 @@ int canl_io_connect(canl_ctx cc, canl_io_handler io, char * host, int port, /* XXX can the list be empty? */ while (ar.ent->h_addr_list[i]) { - err = try_connect(glb_cc, io_cc, ar.ent->h_addr_list[i], + err = try_connect(glb_cc, io_cc, ar.ent->h_addr_list[i], ar.ent->h_addrtype, port, timeout);//TODO timeout - if (!err) - break; + if (!err){ + err_orig = posix_error; + break; + } i++; } free_hostent(ar.ent); @@ -164,8 +173,6 @@ end: return err; } /* try to connect to addr with port (both ipv4 and 6) -static int try_connect(io_handler *io_cc, glb_ctx *glb_cc, char *addr, - int addrtype, int port, struct timeval *timeout) * return 0 when successful * errno otherwise*/ /* XXX use set_error on errors and return a CANL return code */ @@ -196,7 +203,7 @@ static int try_connect(glb_ctx *glb_cc, io_handler *io_cc, char *addr, a_len = sizeof (struct sockaddr_in6); break; default: - return NETDB_INTERNAL; + return EINVAL; break; } @@ -281,7 +288,6 @@ static void io_destroy(glb_ctx *cc, io_handler *io) int err = 0; if (io_cc->s_ctx) { - /*TODO maybe new function because of BIO_free and SSL_free*/ if (io_cc->s_ctx->ssl_io) { SSL_free(io_cc->s_ctx->ssl_io); io_cc->s_ctx->ssl_io = NULL; @@ -295,6 +301,7 @@ static void io_destroy(glb_ctx *cc, io_handler *io) io_cc->s_ctx = NULL; } + int canl_io_destroy(canl_ctx cc, canl_io_handler io) { int err = 0; diff --git a/emi.canl.canl-c/src/canl_ssl.c b/emi.canl.canl-c/src/canl_ssl.c index ad72d9e..e6b4ccb 100644 --- a/emi.canl.canl-c/src/canl_ssl.c +++ b/emi.canl.canl-c/src/canl_ssl.c @@ -379,9 +379,9 @@ static int do_ssl_connect( glb_ctx *cc, io_handler *io, struct timeval *timeout) " handshake: timeout reached"); } else if (ret2 < 0) - set_error (cc, ssl_err, e_orig, "Error during SSL handshake"); - else if (ret2 == 0) - set_error (cc, 0, unknown_error, "Connection closed" + return set_error(cc, ssl_err, e_orig, "Error during SSL handshake"); + else if (ret2 == 0)//TODO is 0 (conn closed by the other side) error? + set_error (cc, 0, ssl_error, "Connection closed" " by the other side"); else set_error (cc, err, unknown_error, "Error during SSL handshake"); -- 1.8.2.3