int lcb_getenv_boolean_multi(const char *key, ...) { va_list ap; const char *cur; int ret = 0; va_start(ap, key); if (lcb_getenv_boolean(key)) { va_end(ap); return 1; } while ((cur = va_arg(ap, const char *))) { if ((ret = lcb_getenv_boolean(cur))) { break; } } va_end(ap); return ret; }
lcb_error_t lcb_init_providers(lcb_t obj, const struct lcb_create_st2 *e_options) { hostlist_t mc_nodes; lcb_error_t err; const char *hosts; int http_enabled = 1; int cccp_enabled = 1; clconfig_provider *http = lcb_confmon_get_provider(obj->confmon, LCB_CLCONFIG_HTTP); clconfig_provider *cccp = lcb_confmon_get_provider(obj->confmon, LCB_CLCONFIG_CCCP); if (e_options->transports) { int cccp_found = 0; int http_found = 0; const lcb_config_transport_t *cur; for (cur = e_options->transports; *cur != LCB_CONFIG_TRANSPORT_LIST_END; cur++) { if (*cur == LCB_CONFIG_TRANSPORT_CCCP) { cccp_found = 1; } else if (*cur == LCB_CONFIG_TRANSPORT_HTTP) { http_found = 1; } else { return LCB_EINVAL; } } if (http_found || cccp_found) { cccp_enabled = cccp_found; http_enabled = http_found; } } if (lcb_getenv_boolean("LCB_NO_CCCP")) { cccp_enabled = 0; } if (lcb_getenv_boolean("LCB_NO_HTTP")) { http_enabled = 0; } /** The only way we can get to here is if one of the vars are set */ if (cccp_enabled == 0 && http_enabled == 0) { return LCB_BAD_ENVIRONMENT; } if (http_enabled) { lcb_clconfig_http_enable(http); lcb_clconfig_http_set_nodes(http, obj->usernodes); } else { lcb_confmon_set_provider_active(obj->confmon, LCB_CLCONFIG_HTTP, 0); } if (!cccp_enabled) { lcb_confmon_set_provider_active(obj->confmon, LCB_CLCONFIG_CCCP, 0); return LCB_SUCCESS; } hosts = get_nonempty_string(e_options->mchosts); mc_nodes = hostlist_create(); if (!mc_nodes) { return LCB_CLIENT_ENOMEM; } if (hosts) { err = hostlist_add_stringz(mc_nodes, hosts, LCB_CONFIG_MCD_PORT); if (err != LCB_SUCCESS) { hostlist_destroy(mc_nodes); return err; } } else { lcb_size_t ii; for (ii = 0; ii < obj->usernodes->nentries; ii++) { lcb_host_t *cur = obj->usernodes->entries + ii; hostlist_add_stringz(mc_nodes, cur->host, LCB_CONFIG_MCD_PORT); } } lcb_clconfig_cccp_enable(cccp, obj); lcb_clconfig_cccp_set_nodes(cccp, mc_nodes); hostlist_destroy(mc_nodes); return LCB_SUCCESS; }