From 163d4c96259ea352519f61df19d3f203fc8ce623 Mon Sep 17 00:00:00 2001 From: Marcel Poul Date: Sat, 3 Dec 2011 20:46:02 +0000 Subject: [PATCH] return values checking improved, set_error with unsigned long parameter; --- emi.canl.canl-c/src/canl.c | 21 ++------------------- emi.canl.canl-c/src/canl_cert.c | 6 +++--- emi.canl.canl-c/src/canl_locl.h | 6 +++--- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/emi.canl.canl-c/src/canl.c b/emi.canl.canl-c/src/canl.c index 0955e58..861662e 100644 --- a/emi.canl.canl-c/src/canl.c +++ b/emi.canl.canl-c/src/canl.c @@ -16,24 +16,12 @@ canl_ctx canl_create_ctx() int err = 0; /*create context*/ - ctx = (glb_ctx *) malloc(sizeof(*ctx)); + ctx = (glb_ctx *) calloc(1, sizeof(*ctx)); if (!ctx) { err = ENOMEM; goto end; } - /*openssl init. -check return value - ssl_library_init(); - ssl_load_error_strings(); - canl_ctx->ssl_ctx->ssl_meth = ;//choose ssl method SSLv3_method(); - canl_ctx->ssl_ctx = SSL_CTX_new (canl_ctx->ssl_ct->ssl_meth) - */ - - /*initial values ...*/ - ctx->err_msg = NULL; - ctx->err_code = no_error; - ctx->opened_ios = 0; - end: if (err) return NULL; @@ -77,17 +65,12 @@ canl_io_handler canl_create_io_handler(canl_ctx cc) } /*create io handler*/ - new_io_h = (io_handler *) malloc(sizeof(*new_io_h)); + new_io_h = (io_handler *) calloc(1, sizeof(*new_io_h)); if (!new_io_h){ err = ENOMEM; return NULL; } - /*read cc and set io_handler accordingly ...*/ - new_io_h->ar = NULL; - new_io_h->s_addr = NULL; - new_io_h->sock = -1; - /* allocate memory and initialize io content*/ if ((err = init_io_content(g_cc ,new_io_h))){ goto end; diff --git a/emi.canl.canl-c/src/canl_cert.c b/emi.canl.canl-c/src/canl_cert.c index df2538e..cc9243e 100644 --- a/emi.canl.canl-c/src/canl_cert.c +++ b/emi.canl.canl-c/src/canl_cert.c @@ -36,7 +36,7 @@ int do_set_ctx_own_cert(glb_ctx *cc, canl_x509 cert, canl_stack_of_x509 chain, static int set_cert(glb_ctx *cc, X509 *cert) { int err = 0; - CANL_ERROR_ORIGIN err_orig; + CANL_ERROR_ORIGIN err_orig = 0; if (cc->cert_key->cert) { free(cc->cert_key->cert); @@ -111,7 +111,7 @@ static int set_key_file(glb_ctx *cc, char *key) } end: - fclose(key_file); + err = fclose(key_file); return err; } @@ -159,6 +159,6 @@ static int set_cert_file(glb_ctx *cc, char *cert) } end: - fclose(cert_file); + err = fclose(cert_file); return err; } diff --git a/emi.canl.canl-c/src/canl_locl.h b/emi.canl.canl-c/src/canl_locl.h index 029e8e7..1cb81d1 100644 --- a/emi.canl.canl-c/src/canl_locl.h +++ b/emi.canl.canl-c/src/canl_locl.h @@ -24,7 +24,7 @@ typedef struct _glb_ctx { int opened_ios; char * err_msg; - CANL_ERROR err_code; + unsigned long err_code; CANL_ERROR_ORIGIN err_orig; cert_key_store *cert_key; SSL_CTX *ssl_ctx; @@ -49,8 +49,8 @@ typedef struct _io_handler ossl_ctx * s_ctx; } io_handler; -void reset_error (glb_ctx *cc, CANL_ERROR err_code); -void set_error (glb_ctx *cc, CANL_ERROR err_code, CANL_ERROR_ORIGIN err_orig, +void reset_error (glb_ctx *cc, unsigned long err_code); +void set_error (glb_ctx *cc, unsigned long err_code, CANL_ERROR_ORIGIN err_orig, const char *err_format, ...); void update_error (glb_ctx *cc, const char *err_format, ...); void free_hostent(struct hostent *h); //TODO is there some standard funcion to free hostent? -- 1.8.2.3