diff --git a/include/sntl/connection.h b/include/sntl/connection.h index e8a2bcd..6c92d64 100644 --- a/include/sntl/connection.h +++ b/include/sntl/connection.h @@ -196,6 +196,7 @@ typedef struct __connections_subsys_type { usrtc_t* (*get_rpc_typed_list_tree)(conn_t *); /** < this function is used to set RPC list of the functions */ int (*set_typed_list_callback)(conn_t *, int, char *); /** < this function is a callback * during setting up a typed channel */ + void (*on_destroy)(conn_t *); /** < callback on connection destroy */ void *priv; } conn_sys_t; @@ -223,6 +224,7 @@ int connections_subsystem_setrpclist_function(usrtc_t* (*get_rpc_typed_list_tree #define connections_subsystem_set_securecheck(c, fuu) (c)->secure_check = fuu #define connections_subsystem_set_sslvalidator(c, fuu) (c)->validate_sslpem = fuu #define connections_subsystem_set_rpctlist_call(c, fuu) (c)->set_typed_list_callback = fuu +#define connections_subsystem_set_on_destroy(c, fuu) (c)->on_destroy = fuu /* connection */ int connection_initiate (conn_t *co, const char *host, int port, diff --git a/lib/Makefile.am b/lib/Makefile.am index 90baed7..90e65e4 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -18,8 +18,8 @@ libsntl_la_SOURCES = \ libsntl_la_LDFLAGS = -Wl,--export-dynamic -libsntl_la_LIBADD = -lpthread -lcrypto $(LIBTDATA_LIBS) $(LIBSEXPR_LIBS) $(OPENSSL_LIBS) \ - -luuid +libsntl_la_LIBADD = -lpthread $(LIBTDATA_LIBS) $(LIBSEXPR_LIBS) $(OPENSSL_LIBS) \ + -lcrypto -luuid pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libsntl.pc diff --git a/lib/connection.c b/lib/connection.c index 5ed6ace..cfa6834 100644 --- a/lib/connection.c +++ b/lib/connection.c @@ -1929,6 +1929,7 @@ int connections_subsystem_init(void) conn_sys->rootca = conn_sys->certkey = conn_sys->certpem = NULL; conn_sys->validate_sslpem = NULL; conn_sys->secure_check = NULL; + conn_sys->on_destroy = NULL; /* init connections list */ usrtc_init(conn_sys->connections, USRTC_REDBLACK, MAX_CONNECTIONS, __cmp_cstr); @@ -2388,7 +2389,7 @@ int connection_create(conn_t *co, int sck) /* shutdown connection */ goto __fail_3; } /* if success we're ready to use established SSL channel */ - printf("%s:%d\n", __FUNCTION__, __LINE__); + BIO_set_nbio(SSL_get_rbio(co->ssl), 1); /*******************************************/ /*-=Protocol part of connection establish=-*/ @@ -2490,7 +2491,12 @@ static void __connection_free(conn_t *co) pthread_join(co->msgthread, &nil); /* wait for it */ /* since we don't have any threads working with channels destroy them */ __destroy_all_channels(co); - /* TODO: permission context and callbacks */ + /* permission context and callback of exists */ + if(conn_sys->on_destroy) conn_sys->on_destroy(co); + else { /* we don't have a handler */ + if(co->pctx->login) free(co->pctx->login); + if(co->pctx->passwd) free(co->pctx->passwd); + } __connections_subsystem_connection_remove(co); /* now we're ready to free other resources */ if(co->uuid) free(co->uuid); @@ -2508,6 +2514,8 @@ static void __connection_free(conn_t *co) /* locks */ pthread_rwlock_destroy(&(co->chnl_lock)); pthread_mutex_destroy(&(co->oplock)); + /* kill permission context */ + if(co->pctx) free(co->pctx); return; }