if (err)
continue;
- err = mech->connect(glb_cc, io_cc, mech->global_context,
- ctx, timeout, host); //TODO timeout
+ err = mech->connect(glb_cc, io_cc, ctx, timeout, host); //TODO timeout
if (err) {
mech->free_ctx(glb_cc, ctx);
continue;
io_cc->sock = new_fd;
- err = ssl_server_init(glb_cc, mech->global_context, &conn_ctx);
+ err = mech->server_init(glb_cc, mech->global_context, &conn_ctx);
if (err)
goto end;
- err = ssl_accept(glb_cc, io_cc, timeout, conn_ctx);
+ err = mech->accept(glb_cc, io_cc, timeout, conn_ctx);
if (err)
goto end;
io_handler *io_cc = (io_handler*) io;
glb_ctx *glb_cc = (glb_ctx*) cc;
int b_recvd = 0;
+ struct canl_mech *mech;
if (!cc)
return -1;
if (io_cc->authn_mech.ctx == NULL)
return set_error(cc, EINVAL, posix_error, "Connection not secured");
-
if (!buffer || !size) {
set_error(cc, EINVAL, posix_error, "No memory to write into");
return -1;
}
- b_recvd = ssl_read(glb_cc, io_cc, io_cc->authn_mech.ctx,
- buffer, size, timeout);
+ mech = find_mech(io_cc->authn_mech.oid);
+
+ b_recvd = mech->read(glb_cc, io_cc, io_cc->authn_mech.ctx,
+ buffer, size, timeout);
return b_recvd;
}
io_handler *io_cc = (io_handler*) io;
glb_ctx *glb_cc = (glb_ctx*) cc;
int b_written = 0;
+ struct canl_mech *mech;
if (!cc)
return -1;
return -1;
}
- b_written = ssl_write(glb_cc, io_cc, io_cc->authn_mech.ctx,
- buffer, size, timeout);
+ mech = find_mech(io_cc->authn_mech.oid);
+
+ b_written = mech->write(glb_cc, io_cc, io_cc->authn_mech.ctx,
+ buffer, size, timeout);
return b_written;
}
(glb_ctx *, void *);
canl_err_code (*connect)
- (glb_ctx *, io_handler *, void *, void *, struct timeval *, const char *);
+ (glb_ctx *, io_handler *, void *, struct timeval *, const char *);
canl_err_code (*accept)
- (glb_ctx *, io_handler *, void *, void *, struct timeval *);
+ (glb_ctx *, io_handler *, void *, struct timeval *);
canl_err_code (*close)
(glb_ctx *, io_handler *, void *);
canl_err_code (*read)
- (glb_ctx *, io_handler *, void *, size_t, struct timeval *);
+ (glb_ctx *, io_handler *, void *, void *, size_t, struct timeval *);
canl_err_code (*write)
- (glb_ctx *, void *, io_handler *, void *, size_t, struct timeval *);
+ (glb_ctx *, io_handler *, void *, void *, size_t, struct timeval *);
} canl_mech;
struct canl_mech *
void free_hostent(struct hostent *h); //TODO is there some standard funcion to free hostent?
int asyn_getservbyname(int a_family, asyn_result *ares_result,char const *name,
struct timeval *timeout);
-int ssl_client_init(glb_ctx *cc, void *mech_ctx, void **ctx);
-int ssl_server_init(glb_ctx *cc, void *mech_ctx, void **ctx);
-int ssl_free(glb_ctx *cc, void *ctx);
-int ssl_connect(glb_ctx *cc, io_handler *io, void *conn_ctx, struct timeval *timeout, const char * host);
-int ssl_accept(glb_ctx *cc, io_handler *io, void *conn_ctx,
- struct timeval *timeout);
-int ssl_read(glb_ctx *cc, io_handler *io, void *auth_ctx,
- void *buffer, size_t size, struct timeval *tout);
-int ssl_write(glb_ctx *cc, io_handler *io, void *auth_ctx,
- void *buffer, size_t size, struct timeval *tout);
-int ssl_close(glb_ctx *cc, io_handler *io, void *auth_ctx);
-int ssl_initialize();
#endif
static void dbg_print_ssl_error(int errorcode);
#endif
-int ssl_initialize(glb_ctx *cc, void **ctx)
+static canl_err_code
+ssl_initialize(glb_ctx *cc, void **ctx)
{
int err = 0;
char *ca_cert_fn, *user_cert_fn, *user_key_fn, *user_proxy_fn;
return err;
}
-int ssl_server_init(glb_ctx *cc, void *mech_ctx, void **ctx)
+static canl_err_code
+ssl_server_init(glb_ctx *cc, void *mech_ctx, void **ctx)
{
SSL_CTX *ssl_ctx = (SSL_CTX *) mech_ctx;
SSL *ssl = NULL;
return 0;
}
-int ssl_client_init(glb_ctx *cc, void *mech_ctx, void **ctx)
+static canl_err_code
+ssl_client_init(glb_ctx *cc, void *mech_ctx, void **ctx)
{
SSL_CTX *ssl_ctx = (SSL_CTX *) mech_ctx;
SSL *ssl = NULL;
return 0;
}
-int ssl_connect(glb_ctx *cc, io_handler *io, void *auth_ctx,
+static canl_err_code
+ssl_connect(glb_ctx *cc, io_handler *io, void *auth_ctx,
struct timeval *timeout, const char * host)
{
SSL_CTX *ctx;
}
}
-int ssl_accept(glb_ctx *cc, io_handler *io, void *auth_ctx,
- struct timeval *timeout)
+static canl_err_code
+ssl_accept(glb_ctx *cc, io_handler *io, void *auth_ctx, struct timeval *timeout)
{
SSL_CTX *ctx = NULL;
SSL *ssl = (SSL *) auth_ctx;
}
/* this function has to return # bytes written or ret < 0 when sth went wrong*/
-int ssl_write(glb_ctx *cc, io_handler *io, void *auth_ctx,
+static canl_err_code
+ssl_write(glb_ctx *cc, io_handler *io, void *auth_ctx,
void *buffer, size_t size, struct timeval *timeout)
{
int err = 0;
return ret;
}
-int ssl_read(glb_ctx *cc, io_handler *io, void *auth_ctx,
+static canl_err_code
+ssl_read(glb_ctx *cc, io_handler *io, void *auth_ctx,
void *buffer, size_t size, struct timeval *tout)
{
int err = 0;
* ret = 0 connection closed successfully (one direction)
* ret = 1 connection closed successfully (both directions)
* ret < 0 error occured (e.g. timeout reached) */
-int ssl_close(glb_ctx *cc, io_handler *io, void *auth_ctx)
+static canl_err_code
+ssl_close(glb_ctx *cc, io_handler *io, void *auth_ctx)
{
SSL_CTX *ctx;
int timeout = DESTROY_TIMEOUT;
}
}
-int
+static canl_err_code
ssl_free(glb_ctx *cc, void *ctx)
{
SSL_free(ctx);
return 0;
}
-int
+static canl_err_code
ssl_finish(glb_ctx *cc, void *ctx)
{
SSL_CTX_free(ctx);
TLS,
NULL,
ssl_initialize,
+ ssl_finish,
ssl_client_init,
ssl_server_init,
ssl_free,