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()
{
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)
/* 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);
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 */
a_len = sizeof (struct sockaddr_in6);
break;
default:
- return NETDB_INTERNAL;
+ return EINVAL;
break;
}
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;
io_cc->s_ctx = NULL;
}
+
int canl_io_destroy(canl_ctx cc, canl_io_handler io)
{
int err = 0;
" 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");