Skip to content

Commit

Permalink
fixup: Use function instead of macro to enable TLS
Browse files Browse the repository at this point in the history
Signed-off-by: Björn Svensson <[email protected]>
  • Loading branch information
bjosv committed Dec 13, 2024
1 parent 8f0e516 commit 425af3f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/cluster-async-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int main(int argc, char **argv) {
options.onConnect = connectCallback;
options.onDisconnect = disconnectCallback;
options.options = VALKEY_OPT_USE_CLUSTER_SLOTS;
VALKEY_CLUSTER_OPTIONS_SET_SSL(&options, tls);
valkeyClusterSetOptionEnableTLS(&options, tls);

struct event_base *base = event_base_new();
VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBEVENT(&options, base);
Expand Down
2 changes: 1 addition & 1 deletion examples/cluster-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main(int argc, char **argv) {
options.initial_nodes = CLUSTER_NODE_TLS;
options.connect_timeout = &timeout;
options.options = VALKEY_OPT_USE_CLUSTER_SLOTS;
VALKEY_CLUSTER_OPTIONS_SET_SSL(&options, tls);
valkeyClusterSetOptionEnableTLS(&options, tls);

valkeyClusterContext *cc = valkeyClusterConnectWithOptions(&options);
if (!cc) {
Expand Down
2 changes: 1 addition & 1 deletion include/valkey/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ typedef struct {
const char *password; /* Authentication password. */
int max_retry_count; /* Allowed retry attempts. */

/* TLS enabled using VALKEY_CLUSTER_OPTIONS_SET_SSL macro. */
/* TLS set by valkeyClusterSetOptionEnableTLS. */
void *tls;
int (*tls_init_fn)(struct valkeyContext *, struct valkeyTLSContext *);

Expand Down
9 changes: 1 addition & 8 deletions include/valkey/cluster_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,9 @@ extern "C" {
/**
* Configuration option to enable TLS negotiation on a context.
*/
int valkeyClusterSetOptionEnableTLS(valkeyClusterContext *cc,
int valkeyClusterSetOptionEnableTLS(valkeyClusterOptions *options,
valkeyTLSContext *tls);

/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_SSL(opts, tls_) \
do { \
(opts)->tls = tls_; \
(opts)->tls_init_fn = &valkeyInitiateTLSWithContext; \
} while (0)

#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 4 additions & 6 deletions src/cluster_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@
*/
#include "cluster_tls.h"

int valkeyClusterSetOptionEnableTLS(valkeyClusterContext *cc,
int valkeyClusterSetOptionEnableTLS(valkeyClusterOptions *options,
valkeyTLSContext *tls) {
if (cc == NULL || tls == NULL) {
if (options == NULL || tls == NULL) {
return VALKEY_ERR;
}

cc->tls = tls;
cc->tls_init_fn = &valkeyInitiateTLSWithContext;

options->tls = tls;
options->tls_init_fn = &valkeyInitiateTLSWithContext;
return VALKEY_OK;
}

0 comments on commit 425af3f

Please sign in to comment.