Ejemplo n.º 1
0
static void socket_connected(connmgr_request *req)
{
    cccp_provider *cccp = req->data;
    lcb_connection_t conn = req->conn;
    struct lcb_nibufs_st nistrs;
    struct lcb_io_use_st use;
    struct negotiation_context *ctx;
    lcb_error_t err;

    free(req);
    cccp->cur_connreq = NULL;

    LOG(cccp, DEBUG, "CCCP Socket connected");

    if (!conn) {
        mcio_error(cccp, LCB_CONNECT_ERROR);
        return;
    }

    lcb_connuse_easy(&use, cccp, io_read_handler, io_error_handler);
    lcb_connection_transfer_socket(conn, &cccp->connection, &use);
    conn = NULL;


    if (cccp->connection.protoctx) {
        /** Already have SASL */
        if ((err = lcb_connection_reset_buffers(&cccp->connection)) != LCB_SUCCESS) {
            mcio_error(cccp, err);
            return;
        }

        request_config(cccp);
        return;
    }

    if (!lcb_get_nameinfo(&cccp->connection, &nistrs)) {
        mcio_error(cccp, LCB_EINTERNAL);
        return;
    }

    ctx = lcb_negotiation_create(&cccp->connection,
                                 cccp->base.parent->settings,
                                 PROVIDER_SETTING(&cccp->base,
                                         config_node_timeout),
                                 nistrs.remote,
                                 nistrs.local,
                                 &err);
    if (!ctx) {
        mcio_error(cccp, err);
    }

    ctx->complete = negotiation_done;
    ctx->data = cccp;
    cccp->connection.protoctx = ctx;
    cccp->connection.protoctx_dtor = (protoctx_dtor_t)lcb_negotiation_destroy;
}
Ejemplo n.º 2
0
clconfig_provider * lcb_clconfig_create_http(lcb_confmon *parent)
{
    lcb_error_t status;
    struct lcb_io_use_st use;
    http_provider *http = calloc(1, sizeof(*http));
    if (!http) {
        return NULL;
    }

    status = lcb_connection_init(&http->connection,
                                 parent->settings->io,
                                 parent->settings);

    if (status != LCB_SUCCESS) {
        free(http);
        return NULL;
    }

    if (! (http->nodes = hostlist_create())) {
        lcb_connection_cleanup(&http->connection);
        free(http);
        return NULL;
    }

    http->base.type = LCB_CLCONFIG_HTTP;
    http->base.refresh = get_refresh;
    http->base.pause = pause_http;
    http->base.get_cached = http_get_cached;
    http->base.shutdown = shutdown_http;
    http->base.nodes_updated = refresh_nodes;
    http->base.enabled = 0;
    http->io_timer = lcb_timer_create_simple(parent->settings->io,
                                             http,
                                             parent->settings->config_node_timeout,
                                             timeout_handler);
    lcb_timer_disarm(http->io_timer);

    http->disconn_timer = lcb_timer_create_simple(parent->settings->io,
                                                  http,
                                                  parent->settings->bc_http_stream_time,
                                                  delayed_disconn);
    lcb_timer_disarm(http->disconn_timer);

    lcb_connuse_easy(&use, http, io_read_handler, io_error_handler);
    lcb_connection_use(&http->connection, &use);

    lcb_string_init(&http->stream.chunk);
    lcb_string_init(&http->stream.header);
    lcb_string_init(&http->stream.input);

    return &http->base;
}
Ejemplo n.º 3
0
static void negotiation_done(struct negotiation_context *ctx, lcb_error_t err)
{
    cccp_provider *cccp = ctx->data;
    struct lcb_io_use_st use;

    if (err != LCB_SUCCESS) {
        LOG(cccp, ERR, "CCCP SASL negotiation failed");
        mcio_error(cccp, err);

    } else {
        LOG(cccp, DEBUG, "CCCP SASL negotiation done");
        lcb_connuse_easy(&use, cccp, io_read_handler, io_error_handler);
        lcb_connection_use(&cccp->connection, &use);
        request_config(cccp);
    }
}