Loading...
Searching...
No Matches
as_host.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2018 Aerospike, Inc.
3 *
4 * Portions may be licensed to Aerospike, Inc. under one or more contributor
5 * license agreements.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8 * use this file except in compliance with the License. You may obtain a copy of
9 * the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17#pragma once
18
19#include <aerospike/as_vector.h>
20#include <citrusleaf/alloc.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/******************************************************************************
27 * TYPES
28 *****************************************************************************/
29
30/**
31 * Host information.
32 */
33typedef struct as_host_s {
34 /**
35 * Host name or IP address of database server.
36 */
37 char* name;
38
39 /**
40 * TLS certificate name for secure connections.
41 */
42 char* tls_name;
43
44 /**
45 * Port of database server.
46 */
47 uint16_t port;
48} as_host;
49
50/******************************************************************************
51 * FUNCTIONS
52 *****************************************************************************/
53
54/**
55 * Parse hosts from format: address1:port1,...
56 * Warning: Destructive parse. String is modified.
57 * Host name pointers are only in scope of string.
58 */
59bool
61
62/**
63 * Deep copy host.
64 */
65static inline void
66as_host_copy(const as_host* src, as_host* trg)
67{
68 trg->name = (char*)cf_strdup(src->name);
69 trg->tls_name = src->tls_name ? (char*)cf_strdup(src->tls_name) : NULL;
70 trg->port = src->port;
71}
72
73/**
74 * Deep copy host from fields.
75 */
76static inline void
77as_host_copy_fields(as_host* trg, const char* hostname, const char* tls_name, uint16_t port)
78{
79 trg->name = (char*)cf_strdup(hostname);
80 trg->tls_name = tls_name ? (char*)cf_strdup(tls_name) : NULL;
81 trg->port = port;
82}
83
84/**
85 * Release memory associated with host.
86 */
87static inline void
89{
90 cf_free(host->name);
91 cf_free(host->tls_name);
92}
93
94#ifdef __cplusplus
95} // end extern "C"
96#endif
static void as_host_copy(const as_host *src, as_host *trg)
Definition as_host.h:66
static void as_host_destroy(as_host *host)
Definition as_host.h:88
bool as_host_parse_addresses(char *str, as_vector *hosts)
static void as_host_copy_fields(as_host *trg, const char *hostname, const char *tls_name, uint16_t port)
Definition as_host.h:77
char * name
Definition as_host.h:37
char * tls_name
Definition as_host.h:42
uint16_t port
Definition as_host.h:47