Пример #1
0
static const char *get_rest_param(lcb_t obj, int paramtype)
{
    const char *ret = NULL;
    const lcb_host_t *host = lcb_confmon_get_rest_host(obj->confmon);
    ret = param_from_host(host, paramtype);

    if (ret) {
        return ret;
    }

    /** Don't have a REST API connection? */
    if (obj->vbucket_config) {
        lcb_server_t *server = obj->servers;
        if (paramtype == PARAM_CONFIG_HOST) {
            ret = param_from_host(&server->curhost, paramtype);
            if (ret) {
                return ret;
            }
        } else {
            char *colon = strstr(server->rest_api_server, ":");
            if (colon) {
                if (obj->scratch) {
                    free(obj->scratch);
                }
                obj->scratch = malloc(NI_MAXSERV + 1);
                strcpy(obj->scratch, colon+1);
                if (*obj->scratch) {
                    return obj->scratch;
                }
            }
        }
    }
    return param_from_host(obj->usernodes->entries, paramtype);
}
Пример #2
0
LIBCOUCHBASE_API
const char *
lcb_get_node(lcb_t instance, lcb_GETNODETYPE type, unsigned ix)
{
    if (type & LCB_NODE_HTCONFIG) {
        if (type & LCB_NODE_CONNECTED) {
            const lcb_host_t *host = lcb_confmon_get_rest_host(instance->confmon);
            if (host) {
                return mk_scratch_host(instance, host);
            } else {
                return return_badhost(type);
            }

        } else {
            /* Retrieve one from the vbucket configuration */
            lcbvb_CONFIG *vbc = LCBT_VBCONFIG(instance);
            lcbvb_SVCMODE mode;
            const char *hp = NULL;
            if (LCBT_SETTING(instance, sslopts) & LCB_SSL_ENABLED) {
                mode = LCBVB_SVCMODE_SSL;
            } else {
                mode = LCBVB_SVCMODE_PLAIN;
            }

            if (instance->type == LCB_TYPE_BUCKET) {
                if (vbc) {
                    ix %= LCBVB_NSERVERS(vbc);
                    hp = lcbvb_get_hostport(vbc, ix, LCBVB_SVCTYPE_MGMT, mode);

                } else if ((type & LCB_NODE_NEVERNULL) == 0) {
                    return NULL;
                }
            }
            if (hp == NULL && instance->ht_nodes && instance->ht_nodes->nentries) {
                ix %= instance->ht_nodes->nentries;
                hostlist_ensure_strlist(instance->ht_nodes);
                hp = instance->ht_nodes->slentries[ix];
            }
            if (!hp) {
                if ((hp = return_badhost(type)) == NULL) {
                    return NULL;
                }
            }
            if (!ensure_scratch(instance, strlen(hp)+1)) {
                return NULL;
            }
            lcb_string_appendz(instance->scratch, hp);
            return instance->scratch->base;
        }
    } else if (type & (LCB_NODE_DATA|LCB_NODE_VIEWS)) {
        const mc_SERVER *server;
        ix %= LCBT_NSERVERS(instance);
        server = LCBT_GET_SERVER(instance, ix);

        if ((type & LCB_NODE_CONNECTED) && server->connctx == NULL) {
            return return_badhost(type);
        }
        if (server->curhost == NULL) {
            return return_badhost(type);
        }

        /* otherwise, return the actual host:port of the server */
        if (type & LCB_NODE_DATA) {
            return mk_scratch_host(instance, server->curhost);
        } else {
            return server->viewshost;
        }
    } else {
        return NULL; /* don't know the type */
    }
}
Пример #3
0
LIBCOUCHBASE_API
const char *lcb_get_port(lcb_t instance)
{
    return lcb_confmon_get_rest_host(instance->confmon)->port;
}