Exemple #1
0
void
lcbio_ctx_senderr(lcbio_CTX *ctx, lcb_error_t err)
{
    if (ctx->err == LCB_SUCCESS) {
        ctx->err = err;
    }
    deactivate_watcher(ctx);
    lcbio_async_signal(ctx->as_err);
}
Exemple #2
0
static lcb_error_t refresh_file(clconfig_provider *pb)
{
    file_provider *provider = (file_provider *)pb;
    if (lcbio_timer_armed(provider->timer)) {
        return LCB_SUCCESS;
    }

    lcbio_async_signal(provider->timer);
    return LCB_SUCCESS;
}
Exemple #3
0
lcb_error_t
lcb_clconfig_mcraw_update(clconfig_provider *pb, const char *nodes)
{
    lcb_error_t err;
    bc_MCRAW *mcr = (bc_MCRAW *)pb;
    hostlist_t hl = hostlist_create();
    err = hostlist_add_stringz(hl, nodes, LCB_CONFIG_MCCOMPAT_PORT);
    if (err != LCB_SUCCESS) {
        hostlist_destroy(hl);
        return err;
    }

    configure_nodes(pb, hl);
    hostlist_destroy(hl);
    lcbio_async_signal(mcr->async);
    return LCB_SUCCESS;
}
Exemple #4
0
static void
cs_state_signal(lcbio_CONNSTART *cs, connect_state state, lcb_error_t err)
{
    if (cs->state != CS_PENDING) {
        /** State already set */
        return;
    }


    if (state == CS_CONNECTED) {
        /* clear last errors if we're successful */
        cs->pending = LCB_SUCCESS;
    } else if (cs->pending == LCB_SUCCESS) {
        /* set error code only if previous code was not a failure */
        cs->pending = err;
    }

    cs->state = state;
    lcbio_async_signal(cs->async);
}
Exemple #5
0
/**
 * set_next listener callback which schedules an async call to our config
 * callback.
 */
static void
async_step_callback(clconfig_listener *listener, clconfig_event_t event,
    clconfig_info *info)
{
    struct lcb_BOOTSTRAP *bs = (struct lcb_BOOTSTRAP *)listener;

    if (event != CLCONFIG_EVENT_GOT_NEW_CONFIG) {
        return;
    }

    if (lcbio_timer_armed(bs->tm) && lcbio_timer_get_target(bs->tm) == async_refresh) {
        lcb_log(LOGARGS(bs->parent, DEBUG), "Timer already present..");
        return;
    }

    lcb_log(LOGARGS(bs->parent, INFO), "Got async step callback..");
    lcbio_timer_set_target(bs->tm, async_refresh);
    lcbio_async_signal(bs->tm);
    (void)info;
}
Exemple #6
0
mc_pSESSREQ
mc_sessreq_start(lcbio_SOCKET *sock, lcb_settings *settings,
              uint32_t tmo, lcbio_CONNDONE_cb callback, void *data)
{
    lcb_error_t err;
    cbsasl_error_t saslerr;
    protocol_binary_request_no_extras req;
    const lcb_host_t *curhost;
    struct lcbio_NAMEINFO nistrs;
    mc_pSESSREQ sreq;
    mc_pSESSINFO sasl;
    lcbio_CTXPROCS procs;

    if ((sreq = calloc(1, sizeof(*sreq))) == NULL) {
        return NULL;
    }

    if ((sasl = calloc(1, sizeof(*sasl))) == NULL) {
        cleanup_pending(sreq);
        return NULL;
    }

    procs.cb_err = handle_ioerr;
    procs.cb_read = handle_read;

    lcbio_get_nameinfo(sock, &nistrs);
    sreq->cb = callback;
    sreq->data = data;
    sreq->inner = sasl;
    sreq->timer = lcbio_timer_new(sock->io, sreq, timeout_handler);

    if ((err = lcbio_sslify_if_needed(sock, settings)) != LCB_SUCCESS) {
        set_error_ex(sreq, err, "Couldn't initialize SSL on socket");
        lcbio_async_signal(sreq->timer);
        return sreq;
    }

    sreq->ctx = lcbio_ctx_new(sock, sreq, &procs);
    sreq->ctx->subsys = "sasl";

    if (tmo) {
        lcbio_timer_rearm(sreq->timer, tmo);
    }

    sasl->base.id = LCBIO_PROTOCTX_SESSINFO;
    sasl->base.dtor = (void (*)(struct lcbio_PROTOCTX *))cleanup_negotiated;
    sasl->settings = settings;

    err = setup_sasl_params(sasl);
    if (err != LCB_SUCCESS) {
        cleanup_pending(sreq);
        return NULL;
    }


    curhost = lcbio_get_host(sock);
    saslerr = cbsasl_client_new(
            "couchbase", curhost->host, nistrs.local, nistrs.remote,
            sasl->sasl_callbacks, 0, &sasl->sasl);

    if (saslerr != SASL_OK) {
        cleanup_pending(sreq);
        return NULL;
    }

    memset(&req, 0, sizeof(req));
    req.message.header.request.magic = PROTOCOL_BINARY_REQ;
    req.message.header.request.opcode = PROTOCOL_BINARY_CMD_SASL_LIST_MECHS;
    req.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES;
    req.message.header.request.bodylen = 0;
    req.message.header.request.keylen = 0;
    req.message.header.request.opaque = 0;

    lcbio_ctx_put(sreq->ctx, req.bytes, sizeof(req.bytes));
    LCBIO_CTX_RSCHEDULE(sreq->ctx, 24);
    return sreq;
}
Exemple #7
0
static lcb_error_t get_refresh(clconfig_provider *pb) {
    lcbio_async_signal( ((bc_MCRAW*)pb)->async );
    return LCB_SUCCESS;
}