Code

SSL utils: Pass a constant options object to all constructors.
authorSebastian Harl <sh@tokkee.org>
Fri, 30 Jan 2015 11:35:20 +0000 (12:35 +0100)
committerSebastian Harl <sh@tokkee.org>
Fri, 30 Jan 2015 11:35:20 +0000 (12:35 +0100)
src/include/utils/ssl.h
src/utils/ssl.c

index 801c574ba0b7df7d663935156b25ae75dbcd0e61..5379bc9ebf7f15af9b93844b9c78e6fc3c045a38 100644 (file)
@@ -73,7 +73,7 @@ typedef struct sdb_ssl_session sdb_ssl_session_t;
  * options are specified, default values will be used instead.
  */
 sdb_ssl_client_t *
-sdb_ssl_client_create(sdb_ssl_options_t *opts);
+sdb_ssl_client_create(const sdb_ssl_options_t *opts);
 
 /*
  * sdb_ssl_client_destroy:
@@ -95,7 +95,7 @@ sdb_ssl_client_connect(sdb_ssl_client_t *client, int fd);
  * options are specified, default values will be used instead.
  */
 sdb_ssl_server_t *
-sdb_ssl_server_create(sdb_ssl_options_t *opts);
+sdb_ssl_server_create(const sdb_ssl_options_t *opts);
 
 /*
  * sdb_ssl_server_destroy:
index d9ad060bb2270a86157135cb57e442b1a15af76e..723df2115600d404c3bf127c4d985e0fcc537203 100644 (file)
@@ -137,27 +137,30 @@ ssl_log_err(int prio, SSL *ssl, int status, const char *prefix, ...)
 } /* ssl_log_err */
 
 static int
-copy_options(sdb_ssl_options_t *dst, sdb_ssl_options_t *src)
+copy_options(sdb_ssl_options_t *dst, const sdb_ssl_options_t *src)
 {
+       sdb_ssl_options_t tmp;
        sdb_ssl_options_t def = SDB_SSL_DEFAULT_OPTIONS;
 
-       if (! src)
-               src = &def;
-
-       if (! src->ca_file)
-               src->ca_file = def.ca_file;
-       if (! src->key_file)
-               src->key_file = def.key_file;
-       if (! src->cert_file)
-               src->cert_file = def.cert_file;
-
-       dst->ca_file = strdup(src->ca_file);
-       dst->key_file = strdup(src->key_file);
-       dst->cert_file = strdup(src->cert_file);
+       if (src)
+               tmp = *src;
+       else
+               tmp = def;
+
+       if (! tmp.ca_file)
+               tmp.ca_file = def.ca_file;
+       if (! tmp.key_file)
+               tmp.key_file = def.key_file;
+       if (! tmp.cert_file)
+               tmp.cert_file = def.cert_file;
+
+       dst->ca_file = strdup(tmp.ca_file);
+       dst->key_file = strdup(tmp.key_file);
+       dst->cert_file = strdup(tmp.cert_file);
        if ((! dst->ca_file) || (! dst->key_file) || (! dst->cert_file))
                return -1;
-       if (src->crl_file) {
-               dst->crl_file = strdup(src->crl_file);
+       if (tmp.crl_file) {
+               dst->crl_file = strdup(tmp.crl_file);
                if (! dst->crl_file)
                        return -1;
        }
@@ -169,7 +172,7 @@ copy_options(sdb_ssl_options_t *dst, sdb_ssl_options_t *src)
  */
 
 sdb_ssl_client_t *
-sdb_ssl_client_create(sdb_ssl_options_t *opts)
+sdb_ssl_client_create(const sdb_ssl_options_t *opts)
 {
        sdb_ssl_client_t *client;
 
@@ -278,7 +281,7 @@ sdb_ssl_client_connect(sdb_ssl_client_t *client, int fd)
 } /* sdb_ssl_client_connect */
 
 sdb_ssl_server_t *
-sdb_ssl_server_create(sdb_ssl_options_t *opts)
+sdb_ssl_server_create(const sdb_ssl_options_t *opts)
 {
        sdb_ssl_server_t *server;