- polished the methods and their prototypes in the authN "object"
authorDaniel Kouřil <kouril@ics.muni.cz>
Tue, 17 Jan 2012 20:14:05 +0000 (20:14 +0000)
committerDaniel Kouřil <kouril@ics.muni.cz>
Tue, 17 Jan 2012 20:14:05 +0000 (20:14 +0000)
- don't call the ssl routines directly but solely through the object

emi.canl.canl-c/src/canl.c
emi.canl.canl-c/src/canl_locl.h
emi.canl.canl-c/src/canl_ssl.c

index bfa242e..3303091 100644 (file)
@@ -151,8 +151,7 @@ canl_io_connect(canl_ctx cc, canl_io_handler io, const char *host, const char *s
                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;
@@ -254,11 +253,11 @@ canl_io_accept(canl_ctx cc, canl_io_handler io, int new_fd,
 
     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;
 
@@ -357,6 +356,7 @@ size_t canl_io_read(canl_ctx cc, canl_io_handler io, void *buffer, size_t size,
     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;
@@ -368,15 +368,16 @@ size_t canl_io_read(canl_ctx cc, canl_io_handler io, void *buffer, size_t size,
 
     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;
 }
@@ -386,6 +387,7 @@ size_t canl_io_write(canl_ctx cc, canl_io_handler io, void *buffer, size_t size,
     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;
@@ -403,8 +405,10 @@ size_t canl_io_write(canl_ctx cc, canl_io_handler io, void *buffer, size_t size,
        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;
 }
index 08b7a83..a75c387 100644 (file)
@@ -111,19 +111,19 @@ typedef struct canl_mech {
        (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 *
@@ -139,17 +139,5 @@ int update_error (glb_ctx *cc, unsigned long err_code, CANL_ERROR_ORIGIN err_ori
 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
index 3793eb4..c416369 100644 (file)
@@ -11,7 +11,8 @@ static int check_hostname_cert(glb_ctx *cc, io_handler *io, SSL *ssl, const char
 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;
@@ -65,7 +66,8 @@ end:
     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;
@@ -150,7 +152,8 @@ int ssl_server_init(glb_ctx *cc, void *mech_ctx, void **ctx)
     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;
@@ -210,7 +213,8 @@ int ssl_client_init(glb_ctx *cc, void *mech_ctx, void **ctx)
     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;
@@ -326,8 +330,8 @@ end:
     }
 }
 
-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;
@@ -533,7 +537,8 @@ static int do_ssl_accept(glb_ctx *cc, io_handler *io,
 }
 
 /* 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;
@@ -631,7 +636,8 @@ end:
     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;
@@ -696,7 +702,8 @@ int ssl_read(glb_ctx *cc, io_handler *io, void *auth_ctx,
  * 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;
@@ -763,14 +770,14 @@ int ssl_close(glb_ctx *cc, io_handler *io, void *auth_ctx)
     }
 }
 
-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);
@@ -841,6 +848,7 @@ struct canl_mech canl_mech_ssl = {
     TLS,
     NULL,
     ssl_initialize,
+    ssl_finish,
     ssl_client_init,
     ssl_server_init,
     ssl_free,