LIBCOUCHBASE_API const char * lcb_get_port(lcb_t instance) { const char *rv = lcb_get_node(instance, LCB_NODE_HTCONFIG|LCB_NODE_NEVERNULL, 0); if (rv && (rv = strstr(rv, ":"))) { rv++; } return rv; }
LIBCOUCHBASE_API const char * lcb_get_host(lcb_t instance) { char *colon; const char *rv = lcb_get_node(instance, LCB_NODE_HTCONFIG|LCB_NODE_NEVERNULL, 0); if (rv != NULL && (colon = (char *)strstr(rv, ":")) != NULL) { if (instance->scratch && rv == instance->scratch->base) { *colon = '\0'; } } return rv; }
int main(int argc, char **argv) { lcb_t instance; struct lcb_create_st cropts; lcb_error_t rc; memset(&cropts, 0, sizeof cropts); cropts.version = 3; cropts.v.v3.connstr = "couchbases://10.0.0.31/default?certpath=/tmp/couchbase-ssl-certificate.pem"; rc = lcb_create(&instance, &cropts); if (rc != LCB_SUCCESS) { die(rc, "Creating instance"); } rc = lcb_connect(instance); if (rc != LCB_SUCCESS) { die(rc, "Connection scheduling"); } /* This function required to actually schedule the operations on the network */ lcb_wait(instance); /* Determines if the bootstrap/connection succeeded */ rc = lcb_get_bootstrap_status(instance); if (rc != LCB_SUCCESS) { die(rc, "Connection bootstraping"); } else { printf("Connection succeeded. Cluster has %d nodes\n", lcb_get_num_nodes(instance)); } /* SSL connections use different ports. For example, the REST API * connection will use port 18091 rather than 8091 when using SSL */ const char *node = lcb_get_node(instance, LCB_NODE_HTCONFIG, 0); printf("First node address for REST API: %s\n", node); lcb_destroy(instance); return 0; }