Beispiel #1
0
static enum conflate_mgmt_cb_result process_set_private(void *opaque,
                                                        conflate_handle_t *handle,
                                                        const char *cmd,
                                                        bool direct,
                                                        kvpair_t *form,
                                                        conflate_form_result *r)
{
    /* Only direct stat requests are handled. */
    assert(direct);
    enum conflate_mgmt_cb_result rv = RV_ERROR;

    char *key = get_simple_kvpair_val(form, "key");
    char *value = get_simple_kvpair_val(form, "value");

    if (key && value) {
        if (conflate_save_private(handle, key, value,
                                  handle->conf->save_path)) {
            rv = RV_OK;
        }
    } else {
        rv = RV_BADARG;
    }

    return rv;
}
END_TEST

START_TEST (test_simple_find_from_null)
{
    fail_unless(get_simple_kvpair_val(NULL, "some_key") == NULL,
                "Couldn't find from NULL.");
}
Beispiel #3
0
static enum conflate_mgmt_cb_result process_get_private(void *opaque,
                                                        conflate_handle_t *handle,
                                                        const char *cmd,
                                                        bool direct,
                                                        kvpair_t *form,
                                                        conflate_form_result *r)
{
    /* Only direct stat requests are handled. */
    assert(direct);
    enum conflate_mgmt_cb_result rv = RV_ERROR;

    char *key = get_simple_kvpair_val(form, "key");

    if (key) {
        /* Initialize the form so there's always one there */
        conflate_init_form(r);
        char *value = conflate_get_private(handle, key,
                                           handle->conf->save_path);
        if (value) {
            conflate_add_field(r, key, value);
            free(value);
        }

        rv = RV_OK;
    } else {
        rv = RV_BADARG;
    }

    return rv;
}
END_TEST

START_TEST (test_simple_find_first_item)
{
    char *val[2] = { "someval", NULL };
    pair = mk_kvpair("some_key", val);
    fail_unless(strcmp(get_simple_kvpair_val(pair, "some_key"),
                       "someval") == 0, "Identity search failed.");
}
END_TEST

START_TEST (test_simple_find_missing_item)
{
    kvpair_t *pair1 = mk_kvpair("some_key", NULL);
    pair = mk_kvpair("some_other_key", NULL);
    pair->next = pair1;

    fail_unless(get_simple_kvpair_val(pair, "missing_key") == NULL,
                "Negative search failed.");
}
END_TEST

START_TEST (test_simple_find_second_item)
{
    char *val[2] = { "someval", NULL };
    kvpair_t *pair1 = mk_kvpair("some_key", val );
    pair = mk_kvpair("some_other_key", NULL);
    pair->next = pair1;

    fail_unless(strcmp(get_simple_kvpair_val(pair, "some_key"),
                       "someval") == 0, "Depth search failed.");
}
Beispiel #7
0
/*
 * Example callback that has an empty result.
 */
static enum conflate_mgmt_cb_result process_reset_stats(void *opaque,
                                                        conflate_handle_t *handle,
                                                        const char *cmd,
                                                        bool direct,
                                                        kvpair_t *form,
                                                        conflate_form_result *r)
{
    char *subtype = get_simple_kvpair_val(form, "-subtype-");

    fprintf(stderr, "Handling stats reset with subtype:  %s\n",
            subtype ? subtype : "(null)");

    return RV_OK;
}
Beispiel #8
0
/*
 * Example callback with a simple form result.
 */
static enum conflate_mgmt_cb_result process_stats(void *opaque,
                                                  conflate_handle_t *handle,
                                                  const char *cmd,
                                                  bool direct,
                                                  kvpair_t *form,
                                                  conflate_form_result *r)
{
    /* Only direct stat requests are handled. */
    assert(direct);

    char *subtype = get_simple_kvpair_val(form, "-subtype-");

    fprintf(stderr, "Handling stats request with subtype:  %s\n",
            subtype ? subtype : "(null)");

    conflate_add_field(r, "stat1", "val1");
    conflate_add_field(r, "stat2", "val2");

    return RV_OK;
}