Neo4j-Client

 view release on metacpan or  search on metacpan

build/lib/src/connection.c  view on Meta::CPAN


static int send_requests(neo4j_connection_t *connection);
static int receive_responses(neo4j_connection_t *connection,
        const unsigned int *condition, bool interruptable);
static int drain_queued_requests(neo4j_connection_t *connection);

static struct neo4j_request *new_request(neo4j_connection_t *connection);
static void pop_request(neo4j_connection_t* connection);

static int initialize(neo4j_connection_t *connection);
static int initialize_callback(void *cdata, neo4j_message_type_t type,
        const neo4j_value_t *argv, uint16_t argc);
static int ack_failure(neo4j_connection_t *connection  );
static int ack_failure_callback(void *cdata, neo4j_message_type_t type,
       const neo4j_value_t *argv, uint16_t argc);

static int hello(neo4j_connection_t *connection);
static int goodbye(neo4j_connection_t *connection);

static neo4j_map_entry_t xtra[2];

struct neo4j_connection_factory neo4j_std_connection_factory =
{
    .tcp_connect = &std_tcp_connect

build/lib/src/connection.c  view on Meta::CPAN

	if ( MESSAGE_TYPE_IS(type,FAILURE) )
#endif
        {
            failure = true;
        }

        neo4j_log_debug(connection->logger, "rcvd %s in response to %s (%p)",
                neo4j_message_type_str(type),
                neo4j_message_type_str(request->type), (void *)request);
        // request callback executed here
        int result = request->receive(request->cdata, type, argv, argc);
        int errsv = errno;
        if (result <= 0)
        {
            pop_request(connection);
            (connection->inflight_requests)--;
        }
        if (result < 0)
        {
	    char code[128];
	    neo4j_string_value(neo4j_map_get(argv[0],"code"),code,sizeof(code));

build/lib/src/connection.c  view on Meta::CPAN

    int err = 0;
    int errsv = errno;
    while (connection->request_queue_depth > 0)
    {
        struct neo4j_request *request =
            &(connection->request_queue[connection->request_queue_head]);

        neo4j_log_trace(connection->logger, "draining %s (%p) from queue on %p",
                neo4j_message_type_str(request->type),
                (void *)request, (void *)connection);
        int result = request->receive(request->cdata, NULL, NULL, 0);
        assert(result <= 0);
        if (err == 0 && result < 0)
        {
            err = -1;
            errsv = errno;
        }
        pop_request(connection);
    }

    connection->inflight_requests = 0;

build/lib/src/connection.c  view on Meta::CPAN

    (connection->request_queue_depth)--;
    (connection->request_queue_head)++;
    if (connection->request_queue_head >= connection->request_queue_size)
    {
        assert(connection->request_queue_head == connection->request_queue_size);
        connection->request_queue_head = 0;
    }
}


struct init_cdata
{
    neo4j_connection_t *connection;
    int error;
};

int initialize(neo4j_connection_t *connection)
{
    assert(connection != NULL);
    neo4j_config_t *config = connection->config;

build/lib/src/connection.c  view on Meta::CPAN

    }

    int err = -1;

    struct neo4j_request *req = new_request(connection);
    if (req == NULL)
    {
        goto cleanup;
    }

    struct init_cdata cdata = { .connection = connection, .error = 0 };

    req->type = NEO4J_INIT_MESSAGE;
    if (connection->version < 3)
      {
      req->_argv[0] = neo4j_string(config->client_id);
      neo4j_map_entry_t auth_token[3] =
        { neo4j_map_entry("scheme", neo4j_string("basic")),
          neo4j_map_entry("principal", neo4j_string(config->username)),
          neo4j_map_entry("credentials", neo4j_string(config->password)) };
      req->_argv[1] = neo4j_map(auth_token, 3);

build/lib/src/connection.c  view on Meta::CPAN

        neo4j_map_entry_t auth_token[4] =
          { neo4j_map_entry("user_agent", neo4j_string(config->client_id)),
            neo4j_map_entry("scheme", neo4j_string("basic")),
            neo4j_map_entry("principal", neo4j_string(config->username)),
            neo4j_map_entry("credentials", neo4j_string(config->password)) };
        req->_argv[0] = neo4j_map(auth_token, 4);
        req->argv = req->_argv;
        req->argc = 1;
      }
    req->receive = initialize_callback;
    req->cdata = &cdata;

    neo4j_log_trace(connection->logger,
                    (connection->version < 3)?
            "enqu INIT{\"%s\", {scheme: basic, principal: \"%s\", "
                    "credentials: ****}} (%p) in %p" :
            "enqu INIT{user_agent: \"%s\", scheme: basic, principal: \"%s\", "
                    "credentials: ****}} (%p) in %p",
            config->client_id, config->username,
            (void *)req, (void *)connection);

    if (neo4j_session_sync(connection, NULL))
    {
        if (cdata.error != 0)
        {
            errno = cdata.error;
        }
        goto cleanup;
    }

    if (cdata.error != 0)
    {
        assert(cdata.error == NEO4J_INVALID_CREDENTIALS ||
                cdata.error == NEO4J_AUTH_RATE_LIMIT);
        errno = cdata.error;
        goto cleanup;
    }

    err = 0;

    int errsv;
cleanup:
    errsv = errno;
    // clear password out of connection config
    ignore_unused_result(neo4j_config_set_password(connection->config, NULL));

build/lib/src/connection.c  view on Meta::CPAN

	neo4j_log_trace(connection->logger,
			"Connection failed in neo4j_connection_send() (goodbye) on %p",
			(void *)connection);
	
        return -1;
      }
    neo4j_log_trace(connection->logger, "sent GOODBYE in %p", (void *)connection);
    return 0;
}

int initialize_callback(void *cdata, neo4j_message_type_t type,
        const neo4j_value_t *argv, uint16_t argc)
{
    if (type == NULL)
    {
        return 0;
    }

    assert(cdata != NULL);
    neo4j_connection_t *connection = ((struct init_cdata *)cdata)->connection;

    char description[128];

#ifndef NEOCLIENT_BUILD
    if (type == NEO4J_SUCCESS_MESSAGE)
#else
    if ( MESSAGE_TYPE_IS(type,SUCCESS) )
#endif
    {
        snprintf(description, sizeof(description),

build/lib/src/connection.c  view on Meta::CPAN

    int result = -1;

    if (strcmp("Neo.ClientError.Security.EncryptionRequired",
            details.code) == 0)
    {
        errno = NEO4J_SERVER_REQUIRES_SECURE_CONNECTION;
        goto cleanup;
    }
    if (strcmp("Neo.ClientError.Security.Unauthorized", details.code) == 0)
    {
        ((struct init_cdata *)cdata)->error = NEO4J_INVALID_CREDENTIALS;
        result = 0;
        goto cleanup;
    }
    if (strcmp("Neo.ClientError.Security.AuthenticationRateLimit",
            details.code) == 0)
    {
        ((struct init_cdata *)cdata)->error = NEO4J_AUTH_RATE_LIMIT;
        result = 0;
        goto cleanup;
    }

    neo4j_log_error(connection->logger, "Session initialization failed: %s",
            details.message);
    errno = NEO4J_UNEXPECTED_ERROR;

cleanup:
    neo4j_mpool_drain(&mpool);

build/lib/src/connection.c  view on Meta::CPAN


    struct neo4j_request *req = new_request(connection);
    if (req == NULL)
    {
        return -1;
    }
    req->type = (connection->version < 3)? NEO4J_ACK_FAILURE_MESSAGE :
      NEO4J_RESET_MESSAGE;
    req->argc = 0;
    req->receive = ack_failure_callback;
    req->cdata = connection;

    neo4j_log_trace(connection->logger, "enqu %s (%p) in %p",
            (connection->version < 3)? "ACK_FAILURE" : "RESET",
            (void *)req, (void *)connection);

    return neo4j_session_sync(connection, NULL);
}


int ack_failure_callback(void *cdata, neo4j_message_type_t type,
        const neo4j_value_t *argv, uint16_t argc)
{
    assert(cdata != NULL);
    neo4j_connection_t *connection = (neo4j_connection_t *)cdata;

    char buf[12];
    strcpy(buf, (connection->version < 3)? "ACK_FAILURE" : "RESET");
#ifndef NEOCLIENT_BUILD
    if (type == NEO4J_IGNORED_MESSAGE || type == NULL)
#else
    if ( MESSAGE_TYPE_IS(type,IGNORED) || type == NULL )
#endif
    {
        // only when draining after connection close

build/lib/src/connection.c  view on Meta::CPAN

    }

    neo4j_log_trace(connection->logger, "%s complete in %p", buf,
            (void *)connection);
    return 0;
}


int neo4j_session_run(neo4j_connection_t *connection, neo4j_mpool_t *mpool,
        const char *statement, neo4j_value_t params, neo4j_value_t extra,
        neo4j_response_recv_t callback, void *cdata)
{
    REQUIRE(connection != NULL, -1);
    REQUIRE(mpool != NULL, -1);
    REQUIRE(statement != NULL, -1);
    REQUIRE(neo4j_type(params) == NEO4J_MAP || neo4j_is_null(params), -1);
    REQUIRE(neo4j_type(extra) == NEO4J_MAP || neo4j_is_null(extra), -1);
    REQUIRE(callback != NULL, -1);

    if (neo4j_atomic_bool_set(&(connection->processing), true))
    {

build/lib/src/connection.c  view on Meta::CPAN

        goto cleanup;
    }
    req->type = NEO4J_RUN_MESSAGE;
    req->_argv[0] = neo4j_string(statement);
    req->_argv[1] = neo4j_is_null(params)? neo4j_map(NULL, 0) : params;
    req->_argv[2] = neo4j_is_null(extra)? neo4j_map(NULL,0) : extra;
    req->argv = req->_argv;
    req->argc = (connection->version > 2)? 3 : 2;
    req->mpool = mpool;
    req->receive = callback;
    req->cdata = cdata;

    if (neo4j_log_is_enabled(connection->logger, NEO4J_LOG_TRACE))
    {
        char buf[1024];
        if (connection->version < 3)
          {
            neo4j_log_trace(connection->logger, "enqu RUN{\"%s\", %s} (%p) in %p",
                            statement, neo4j_tostring(req->argv[1], buf, sizeof(buf)),
                            (void *)req, (void *)connection);
          }

build/lib/src/connection.c  view on Meta::CPAN

    }

    err = 0;

cleanup:
    neo4j_atomic_bool_set(&(connection->processing), false);
    return err;
}

int neo4j_session_pull_all(neo4j_connection_t *connection, int n, int qid, 
        neo4j_mpool_t *mpool, neo4j_response_recv_t callback, void *cdata)
{
    REQUIRE(connection != NULL, -1);
    REQUIRE(mpool != NULL, -1);
    REQUIRE(callback != NULL, -1);

    if (neo4j_atomic_bool_set(&(connection->processing), true))
    {
        errno = NEO4J_SESSION_BUSY;
        return -1;
    }

build/lib/src/connection.c  view on Meta::CPAN

    else
      {
        xtra[0] = neo4j_map_entry("n",neo4j_int( n));
        xtra[1] = neo4j_map_entry("qid",neo4j_int( qid));
        req->_argv[0] = neo4j_map(xtra, 2);
        req->argv = req->_argv;
        req->argc = 1;
      }
    req->mpool = mpool;
    req->receive = callback;
    req->cdata = cdata;
    if (connection->version < 4)
      {
        neo4j_log_trace(connection->logger, "enqu PULL_ALL (%p) in %p",
		        (void *)req, (void *)connection);
      }
    else
      {
        char buf[128];
        neo4j_log_trace(connection->logger, "enqu PULL %s (%p) in %p",
                neo4j_tostring(req->argv[0],buf, sizeof(buf)), (void *)req, (void *)connection);

build/lib/src/connection.c  view on Meta::CPAN


    err = 0;

cleanup:
    neo4j_atomic_bool_set(&(connection->processing), false);
    return err;
}


int neo4j_session_discard_all(neo4j_connection_t *connection, int n, int qid,
        neo4j_mpool_t *mpool, neo4j_response_recv_t callback, void *cdata)
{
    REQUIRE(connection != NULL, -1);
    REQUIRE(mpool != NULL, -1);
    REQUIRE(callback != NULL, -1);

    if (neo4j_atomic_bool_set(&(connection->processing), true))
    {
        errno = NEO4J_SESSION_BUSY;
        return -1;
    }

build/lib/src/connection.c  view on Meta::CPAN

    else
      {
        xtra[0] = neo4j_map_entry("n",neo4j_int(n));
        xtra[1] = neo4j_map_entry("qid",neo4j_int(qid));
        req->_argv[0] = neo4j_map(xtra, 2);
        req->argv = req->_argv;
        req->argc = 1;
      }
    req->mpool = mpool;
    req->receive = callback;
    req->cdata = cdata;

    if (connection->version < 4)
      {
        neo4j_log_trace(connection->logger, "enqu DISCARD_ALL (%p) in %p",
                        (void *)req, (void *)connection);
      }
    else
      {
        char buf[128];
        neo4j_log_trace(connection->logger, "enqu DISCARD %s (%p) in %p",
                        neo4j_tostring(req->argv[0],buf, sizeof(buf)), (void *)req, (void *)connection);
      }

    err = 0;

cleanup:
    neo4j_atomic_bool_set(&(connection->processing), false);
    return err;
}

int neo4j_session_transact(neo4j_connection_t *connection, const char*msg_type, neo4j_response_recv_t callback, void *cdata)
{
    REQUIRE(connection != NULL, -1);
    REQUIRE(cdata != NULL, -1);
    REQUIRE(callback != NULL, -1);

    neo4j_transaction_t *tx = (neo4j_transaction_t *) cdata;
    int err = -1;
    struct neo4j_request *req = new_request(connection);
    if (req == NULL)
    {
        goto cleanup;
    }

    req->type = neo4j_message_type_for_type(msg_type);
    if (strcmp(msg_type,"BEGIN") == 0)
    {

build/lib/src/connection.c  view on Meta::CPAN

	req->argv = req->_argv;
	req->argc = 1;
    }
    else
    {
	req->argv = NULL;
	req->argc = 0;
    }
    req->mpool = &(tx->mpool);
    req->receive = callback; // callback specified in transaction.c
    req->cdata = cdata; // this will be the neo4j_transaction_t object
    if (neo4j_log_is_enabled(connection->logger,NEO4J_LOG_TRACE)) {
        neo4j_log_trace(connection->logger, "enqu %s (%p) in %p",
                        msg_type, (void *)req, (void *)connection);
    }
    if (neo4j_session_sync(connection,NULL)) {
      if (tx->failed != 0) {
        errno = tx->failure;
      }
      goto cleanup;
    }

build/lib/src/connection.h  view on Meta::CPAN

#include <stdlib.h>
#include <stdio.h>

#define vstonl(vs) htonl((vs.and_lower<<16)|(vs.minor<<8)|vs.major)

/**
 * Callback for receiving responses to requests.
 *
 * @internal
 *
 * @param [cdata] The opaque callback data.
 * @param [type] The type of the response message.
 * @param [argv] The response argument vector.
 * @param [argc] The number of arguments in the argument vector.
 * @return 0 if the response was processed successfully and no more
 *        responses are expected for the request, <0 if an error occurs
 *        (errno will be set), >0 if the response was processed successfully
 *        and there are more responses expected for the request.
 */
typedef int (*neo4j_response_recv_t)(void *cdata, neo4j_message_type_t type,
            const neo4j_value_t *argv, uint16_t argc);


#define NEO4J_REQUEST_ARGV_PREALLOC 4

struct neo4j_request
{
    neo4j_message_type_t type;
    neo4j_value_t _argv[NEO4J_REQUEST_ARGV_PREALLOC];
    const neo4j_value_t *argv;
    uint16_t argc;

    neo4j_mpool_t _mpool;
    neo4j_mpool_t *mpool;

    neo4j_response_recv_t receive;
    void *cdata;
};


struct neo4j_connection
{
    neo4j_config_t *config;
    neo4j_logger_t *logger;

    char *hostname;
    unsigned int port;

build/lib/src/connection.h  view on Meta::CPAN

 * Send a RUN message in a session.
 *
 * @internal
 * 
 * @param [connection] The connection to send the message in.
 * @param [mpool] The memory pool to use when sending and receiving.
 * @param [statement] The statement to send.
 * @param [params] The parameters to send.
 * @param [extra] The 'extra' map containing bolt metadata (Neo4j 3+)
 * @param [callback] The callback to be invoked for responses.
 * @param [cdata] Opaque data to be provided to the callback.
 * @return 0 on success, -1 on failure (errno will be set).
 */
__neo4j_must_check
int neo4j_session_run(neo4j_connection_t *connection, neo4j_mpool_t *mpool,
        const char *statement, neo4j_value_t params, neo4j_value_t extra,
        neo4j_response_recv_t callback, void *cdata);

/**
 * Send a PULL_ALL message in a session.
 *
 * @internal
 *
 * @param [connection] The connection to send the message in.
 * @param [n] Number of records to pull; set to -1 to pull all (Bolt 4+)
 * @param [qid] ID of query to pull from; set to -1 for most recent (Bolt 4+)
 * @param [mpool] The memory pool to use when sending and receiving.
 * @param [callback] The callback to be invoked for responses.
 * @param [cdata] Opaque data to be provided to the callback.
 * @return 0 on success, -1 on failure (errno will be set).
 */
__neo4j_must_check
int neo4j_session_pull_all(neo4j_connection_t *connection, int n, int qid,
        neo4j_mpool_t *mpool, neo4j_response_recv_t callback, void *cdata);

/**
 * Send a DISCARD_ALL message in a session.
 *
 * @internal
 *
 * @param [connection] The connection to send the message in.
 * @param [n] Number of records to discard; set to -1 to discard all (Bolt 4+)
 * @param [qid] ID of query to discard from; set to -1 for most recent (Bolt 4+)
 * @param [mpool] The memory pool to use when sending and receiving.
 * @param [callback] The callback to be invoked for responses.
 * @param [cdata] Opaque data to be provided to the callback.
 * @return 0 on success, -1 on failure (errno will be set).
 */
__neo4j_must_check
int neo4j_session_discard_all(neo4j_connection_t *connection, int n, int qid,
        neo4j_mpool_t *mpool, neo4j_response_recv_t callback, void *cdata);


// bolt 3 stuff here for now
__neo4j_must_check
int neo4j_session_transact(neo4j_connection_t *connection, const char*msg_name, neo4j_response_recv_t callback, void *cdata);

neo4j_value_t extract_extra( neo4j_value_t *params);

int parse_version_string(char *version_string, version_spec_t *vs);

#endif/*NEO4J_CONNECTION_H*/

build/lib/src/render.c  view on Meta::CPAN

        return -1;
    }
    return 0;
}


int render_row(FILE *stream, unsigned int ncolumns,
        const unsigned int *widths, bool undersize, uint_fast32_t flags,
        const struct neo4j_results_table_colors *colors,
        const char * const field_color[2],
        render_row_callback_t callback, void *cdata)
{
    assert(stream != NULL);
    assert(ncolumns == 0 || widths != NULL);
    assert(colors != NULL);

    struct fields
    {
        const char *s;
        size_t n;
        char *dup;

build/lib/src/render.c  view on Meta::CPAN

                fputc(' ', stream) == EOF)
        {
            goto cleanup;
        }

        assert(widths[i] >= 2);
        unsigned int value_width = widths[i] - 2;
        ssize_t n = 0;
        const char *s = NULL;
        bool duplicate = false;
        if (callback != NULL && (n = callback(cdata, i, &s, &duplicate)) < 0)
        {
            goto cleanup;
        }
        assert(n == 0 || s != NULL);

        ssize_t consumed = render_field(stream, s, n, value_width, flags,
                field_color);
        if (consumed < 0)
        {
            goto cleanup;

build/lib/src/render.h  view on Meta::CPAN


int render_hrule(FILE *stream, unsigned int ncolumns,
        unsigned int *widths, hline_position_t position,
        bool undersize, uint_fast32_t flags,
        const struct neo4j_results_table_colors *colors);

int render_overflow(FILE *stream, uint_fast32_t flags,
        const char * const color[2]);

typedef ssize_t (*render_row_callback_t)(
        void *cdata, unsigned int n, const char **s, bool *duplicate);
int render_row(FILE *stream, unsigned int ncolumns,
        const unsigned int *widths, bool undersize, uint_fast32_t flags,
        const struct neo4j_results_table_colors *colors,
        const char * const field_color[2],
        render_row_callback_t callback, void *cdata);

int fit_column_widths(unsigned int n, unsigned int widths[],
        unsigned int min, unsigned int max_total);

#endif/*NEO4J_RENDER_H*/

build/lib/src/render_results.c  view on Meta::CPAN

        }
    }

    return 0;
}


ssize_t obtain_fieldname(void *data, unsigned int n, const char **s,
        bool *duplicate)
{
    struct obtain_fieldname_cb_data *cdata =
            (struct obtain_fieldname_cb_data *)data;
    *s = neo4j_fieldname(cdata->results, n);
    *duplicate = false;
    return (*s != NULL)? strlen(*s) : 0;
}


ssize_t obtain_result_field(void *data, unsigned int n, const char **s,
        bool *duplicate)
{
    struct obtain_result_field_cb_data *cdata =
            (struct obtain_result_field_cb_data *)data;
    neo4j_value_t value = neo4j_result_field(cdata->result, n);

    if (neo4j_type(value) == NEO4J_STRING &&
            !(cdata->flags & NEO4J_RENDER_QUOTE_STRINGS))
    {
        *s = neo4j_ustring_value(value);
        *duplicate = false;
        return neo4j_string_length(value);
    }

    *duplicate = true;
    return render_field_value(value, s, cdata->buffer, cdata->bufcap,
            cdata->flags);
}


ssize_t render_field_value(neo4j_value_t value, const char **s,
        char **buf, size_t *bufcap, uint_fast32_t flags)
{
    size_t length;
    do
    {
        length = value_tostring(&value, *buf, *bufcap, flags);

build/lib/src/result_stream.c  view on Meta::CPAN

static struct neo4j_update_counts run_rs_update_counts(
        neo4j_result_stream_t *self);
static int run_rs_close(neo4j_result_stream_t *self);

static neo4j_value_t run_result_field(const neo4j_result_t *self,
        unsigned int index);
static neo4j_result_t *run_result_retain(neo4j_result_t *self);
static void run_result_release(neo4j_result_t *self);

static void abort_job(neo4j_job_t *job, int err);
static int run_callback(void *cdata, neo4j_message_type_t type,
        const neo4j_value_t *argv, uint16_t argc);
static int pull_all_callback(void *cdata, neo4j_message_type_t type,
        const neo4j_value_t *argv, uint16_t argc);
static int discard_all_callback(void *cdata, neo4j_message_type_t type,
        const neo4j_value_t *argv, uint16_t argc);
static int stream_end(run_result_stream_t *results, neo4j_message_type_t type,
        const char *src_message_type, const neo4j_value_t *argv, uint16_t argc);
static int await(run_result_stream_t *results, const unsigned int *condition);
static int append_result(run_result_stream_t *results,
        const neo4j_value_t *argv, uint16_t argc);
void result_record_release(result_record_t *record);
static int set_eval_failure(run_result_stream_t *results,
        const char *src_message_type, const neo4j_value_t *argv, uint16_t argc);
static void set_failure(run_result_stream_t *results, int error);

build/lib/src/result_stream.c  view on Meta::CPAN


    job->next = NULL;
    results->connection = NULL;
    if (results->streaming && results->failure == 0)
    {
        set_failure(results, err);
    }
}


int run_callback(void *cdata, neo4j_message_type_t type,
        const neo4j_value_t *argv, uint16_t argc)
{
    assert(cdata != NULL);
    assert(argc == 0 || argv != NULL);
    run_result_stream_t *results = (run_result_stream_t *)cdata;
    neo4j_logger_t *logger = results->logger;
    neo4j_connection_t *connection = results->connection;

    results->starting = false;
    --(results->refcount);

    if (type == NULL || connection == NULL)
    {
        return 0;
    }

build/lib/src/result_stream.c  view on Meta::CPAN

    {
        set_failure(results, errno);
        return -1;
    }
    results->available_after = available_after;

    return 0;
}


int pull_all_callback(void *cdata, neo4j_message_type_t type,
        const neo4j_value_t *argv, uint16_t argc)
{
    assert(cdata != NULL);
    assert(argc == 0 || argv != NULL);
    run_result_stream_t *results = (run_result_stream_t *)cdata;

#ifndef NEOCLIENT_BUILD
    if (type == NEO4J_RECORD_MESSAGE)
#else
    if ( MESSAGE_TYPE_IS(type,RECORD) )
#endif
    {
        if (append_result(results, argv, argc))
        {
            neo4j_log_trace_errno(results->logger, "append_result failed");

build/lib/src/result_stream.c  view on Meta::CPAN

    {
        neo4j_log_trace_errno(results->logger, "neo4j_mpool_merge failed");
        set_failure(results, errno);
        return -1;
    }

    return stream_end(results, type, "PULL_ALL", argv, argc);
}


int discard_all_callback(void *cdata, neo4j_message_type_t type,
        const neo4j_value_t *argv, uint16_t argc)
{
    assert(cdata != NULL);
    assert(argc == 0 || argv != NULL);
    run_result_stream_t *results = (run_result_stream_t *)cdata;

    --(results->refcount);
    results->streaming = false;

    return stream_end(results, type, "DISCARD_ALL", argv, argc);
}


int stream_end(run_result_stream_t *results, neo4j_message_type_t type,
        const char *src_message_type, const neo4j_value_t *argv, uint16_t argc)

build/lib/src/transaction.c  view on Meta::CPAN

#include "util.h"
#include "values.h"
#include "atomic.h"
#include <assert.h>
#include <string.h>
#include <stddef.h>
#include <unistd.h>
#include <stdio.h>

neo4j_transaction_t *new_transaction(neo4j_config_t *config, neo4j_connection_t *connection, int timeout, const char *mode, const char *dbname);
int begin_callback(void *cdata, neo4j_message_type_t type, const neo4j_value_t *argv, uint16_t argc);
int commit_callback(void *cdata, neo4j_message_type_t type, const neo4j_value_t *argv, uint16_t argc);
int rollback_callback(void *cdata, neo4j_message_type_t type, const neo4j_value_t *argv, uint16_t argc);
int tx_failure(neo4j_transaction_t *tx);
bool tx_defunct(neo4j_transaction_t *tx);
int tx_commit(neo4j_transaction_t *tx);
int tx_rollback(neo4j_transaction_t *tx);
neo4j_result_stream_t *tx_run(neo4j_transaction_t *tx, const char *statement, neo4j_value_t params, int send);


// rough out the transaction based calls
// there will be bookkeeping to do - handling errors when server state
// is mismatch with the request:

build/lib/src/transaction.c  view on Meta::CPAN

    neo4j_transaction_t *tx = new_transaction(config, connection, tx_timeout, tx_mode, dbname);
    if (neo4j_session_transact(connection, "BEGIN", begin_callback, tx))
      {
        neo4j_log_error_errno(tx->logger, "tx begin failed");
        tx->failed = 1;
        tx->failure = errno;
      }
    return tx;
}

int begin_callback(void *cdata, neo4j_message_type_t type, const neo4j_value_t *argv, uint16_t argc)
{
  assert(cdata != NULL);
  assert(argc == 0 || argv != NULL);
  neo4j_transaction_t *tx = (neo4j_transaction_t *) cdata;

#ifndef NEOCLIENT_BUILD  
  if (type == NEO4J_FAILURE_MESSAGE)
#else
  if ( MESSAGE_TYPE_IS(type,FAILURE) )
#endif
    {
      // get FAILURE argv and set tx failure info here
      tx->failed = 1;
      tx->failure = NEO4J_TRANSACTION_FAILED;

build/lib/src/transaction.c  view on Meta::CPAN

    else
    {
	tx->is_open = 0;
	tx->failed = 0;
	tx->failure_code = neo4j_null;
	tx->failure_message = neo4j_null;	
    }
    return -tx->failed;
}

int commit_callback(void *cdata, neo4j_message_type_t type, const neo4j_value_t *argv, uint16_t argc)
{
  assert(cdata != NULL);
  assert(argc == 0 || argv != NULL);
  neo4j_transaction_t *tx = (neo4j_transaction_t *) cdata;

#ifndef NEOCLIENT_BUILD  
  if (type == NEO4J_FAILURE_MESSAGE)
#else
  if ( MESSAGE_TYPE_IS(type,FAILURE) )
#endif
    {
      // get FAILURE argv and set tx failure info here
      tx->failed = 1;
      tx->failure = NEO4J_TRANSACTION_FAILED;

build/lib/src/transaction.c  view on Meta::CPAN

    }
  else {
      tx->is_open = 0;
      tx->failed = 0;
      tx->failure_code = neo4j_null;
      tx->failure_message = neo4j_null;
  }
  return -tx->failed;
}

int rollback_callback(void *cdata, neo4j_message_type_t type, const neo4j_value_t *argv, uint16_t argc)
{
  assert(cdata != NULL);
  assert(argc == 0 || argv != NULL);
  neo4j_transaction_t *tx = (neo4j_transaction_t *) cdata;
#ifndef NEOCLIENT_BUILD  
  if (type == NEO4J_FAILURE_MESSAGE)
#else
  if ( MESSAGE_TYPE_IS(type,FAILURE) )
#endif
    {
      // get FAILURE argv and set tx failure info here
      tx->failed = 1;
      tx->failure = NEO4J_TRANSACTION_FAILED;
      tx->failure_code = neo4j_map_get(argv[0],"code");



( run in 0.663 second using v1.01-cache-2.11-cpan-454fe037f31 )