Code

SSL utils: Add sdb_ssl_free_options().
authorSebastian Harl <sh@tokkee.org>
Fri, 30 Jan 2015 10:26:49 +0000 (11:26 +0100)
committerSebastian Harl <sh@tokkee.org>
Fri, 30 Jan 2015 10:26:49 +0000 (11:26 +0100)
src/client/sock.c
src/include/utils/ssl.h
src/utils/ssl.c

index b67910efa4b5eb843504b825587e52a14367f465..65b6b0e3a3bc20c530b096ec72a2c61ffdf8c80d 100644 (file)
@@ -188,20 +188,6 @@ connect_tcp(sdb_client_t *client, const char *address)
        return client->fd;
 } /* connect_tcp */
 
-static void
-free_ssl_options(sdb_ssl_options_t *opts)
-{
-       if (opts->ca_file)
-               free(opts->ca_file);
-       if (opts->key_file)
-               free(opts->key_file);
-       if (opts->cert_file)
-               free(opts->cert_file);
-       if (opts->crl_file)
-               free(opts->crl_file);
-       opts->ca_file = opts->key_file = opts->cert_file = opts->crl_file = NULL;
-} /* free_ssl_options */
-
 /*
  * public API
  */
@@ -249,7 +235,7 @@ sdb_client_destroy(sdb_client_t *client)
                free(client->address);
        client->address = NULL;
 
-       free_ssl_options(&client->ssl_opts);
+       sdb_ssl_free_options(&client->ssl_opts);
 
        free(client);
 } /* sdb_client_destroy */
@@ -262,7 +248,7 @@ sdb_client_set_ssl_options(sdb_client_t *client, const sdb_ssl_options_t *opts)
        if ((! client) || (! opts))
                return -1;
 
-       free_ssl_options(&client->ssl_opts);
+       sdb_ssl_free_options(&client->ssl_opts);
 
        if (opts->ca_file) {
                client->ssl_opts.ca_file = strdup(opts->ca_file);
@@ -286,7 +272,7 @@ sdb_client_set_ssl_options(sdb_client_t *client, const sdb_ssl_options_t *opts)
        }
 
        if (ret)
-               free_ssl_options(&client->ssl_opts);
+               sdb_ssl_free_options(&client->ssl_opts);
        return ret;
 } /* sdb_client_set_ssl_options */
 
index 6489f8b01f871535b9e47f24e46580f3164c7e4b..801c574ba0b7df7d663935156b25ae75dbcd0e61 100644 (file)
@@ -143,6 +143,14 @@ sdb_ssl_session_write(sdb_ssl_session_t *session, const void *buf, size_t n);
 ssize_t
 sdb_ssl_session_read(sdb_ssl_session_t *session, void *buf, size_t n);
 
+/*
+ * sdb_ssl_free_options:
+ * Free all strings stored in the specified options. All fields will be set to
+ * NULL.
+ */
+void
+sdb_ssl_free_options(sdb_ssl_options_t *opts);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
index 477d16c28ae1fe7cb2ae9cd78c270a30d2125d55..f75223c03667d18d077be5bc770b9198d254aefc 100644 (file)
@@ -164,19 +164,6 @@ copy_options(sdb_ssl_options_t *dst, sdb_ssl_options_t *src)
        return 0;
 } /* copy_options */
 
-static void
-free_options(sdb_ssl_options_t *opts)
-{
-       if (opts->ca_file)
-               free(opts->ca_file);
-       if (opts->key_file)
-               free(opts->key_file);
-       if (opts->cert_file)
-               free(opts->cert_file);
-       if (opts->crl_file)
-               free(opts->crl_file);
-} /* free_options */
-
 /*
  * public API
  */
@@ -243,7 +230,7 @@ sdb_ssl_client_destroy(sdb_ssl_client_t *client)
 
        if (client->ctx)
                SSL_CTX_free(client->ctx);
-       free_options(&client->opts);
+       sdb_ssl_free_options(&client->opts);
        free(client);
 } /* sdb_ssl_client_destroy */
 
@@ -364,7 +351,7 @@ sdb_ssl_server_destroy(sdb_ssl_server_t *server)
 
        if (server->ctx)
                SSL_CTX_free(server->ctx);
-       free_options(&server->opts);
+       sdb_ssl_free_options(&server->opts);
        free(server);
 } /* sdb_ssl_server_destroy */
 
@@ -512,5 +499,23 @@ sdb_ssl_session_read(sdb_ssl_session_t *session, void *buf, size_t n)
        return -1;
 } /* sdb_ssl_session_read */
 
+void
+sdb_ssl_free_options(sdb_ssl_options_t *opts)
+{
+       if (! opts)
+               return;
+
+       if (opts->ca_file)
+               free(opts->ca_file);
+       if (opts->key_file)
+               free(opts->key_file);
+       if (opts->cert_file)
+               free(opts->cert_file);
+       if (opts->crl_file)
+               free(opts->crl_file);
+
+       opts->ca_file = opts->key_file = opts->cert_file = opts->crl_file = NULL;
+} /* sdb_ssl_free_options */
+
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */