Пример #1
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;
}
Пример #2
0
static enum conflate_mgmt_cb_result process_serverlist(void *opaque,
                                                       conflate_handle_t *handle,
                                                       const char *cmd,
                                                       bool direct,
                                                       kvpair_t *conf,
                                                       conflate_form_result *r)
{
    /* If we have "config_is_private" set to "yes" we should only
       process this if it's direct (i.e. ignore pubsub) */
    if (!direct) {
        char *priv = conflate_get_private(handle, "config_is_private",
                                          handle->conf->save_path);

        if (priv && strcmp(priv, "yes") == 0) {
            CONFLATE_LOG(handle, INFO,
                         "Currently using a private config, ignoring update.");
            return RV_OK;
        }
        free(priv);
    }

    CONFLATE_LOG(handle, INFO, "Processing a serverlist");

    /* Persist the config lists */
    if (!save_kvpairs(handle, conf, handle->conf->save_path)) {
        CONFLATE_LOG(handle, ERROR, "Can not save config to %s",
                     handle->conf->save_path);
    }

    /* Send the config to the callback */
    handle->conf->new_config(handle->conf->userdata, conf);

    return RV_OK;
}
Пример #3
0
END_TEST

START_TEST (test_private_retrieve)
{
    fail_unless(conflate_save_private(handle, "some key", "some value",
                                      db_loc),
                "Failed to save a new value.");
    char *val = conflate_get_private(handle, "some key", db_loc);
    fail_if(val == NULL, "Did not retrieve a value.");
    fail_unless(strcmp(val, "some value") == 0,
                "Incorrect value returned.");
    free(val);
}
Пример #4
0
void* run_conflate(void *arg) {
    conflate_handle_t* handle = (conflate_handle_t*)arg;

    /* Before connecting and all that, load the stored config */
    kvpair_t* conf = load_kvpairs(handle, handle->conf->save_path);
    if (conf) {
        handle->conf->new_config(handle->conf->userdata, conf);
        free_kvpair(conf);
    }

    xmpp_log_t strophe_logger = { &conflate_strophe_logger, handle };

    /* Run forever */
    for (;;) {
        handle->ctx = xmpp_ctx_new(NULL, &strophe_logger);
        assert(handle->ctx);

        handle->conn = xmpp_conn_new(handle->ctx);
        assert(handle->conn);

        /* Use the stored jid if there is one */
        char *db_jid = conflate_get_private(handle, STORED_JID_KEY,
                                            handle->conf->save_path);
        if (db_jid) {
            CONFLATE_LOG(handle, LOG_LVL_DEBUG, "Using jid from db: %s",
                         db_jid);
            xmpp_conn_set_jid(handle->conn, db_jid);
            free(db_jid);
        } else {
            CONFLATE_LOG(handle, LOG_LVL_DEBUG, "Using provided jid:  %s",
                         handle->conf->jid);
            xmpp_conn_set_jid(handle->conn, handle->conf->jid);
        }

        xmpp_conn_set_pass(handle->conn, handle->conf->pass);

        xmpp_connect_client(handle->conn, handle->conf->host, 0,
                            conn_handler, handle);
        xmpp_run(handle->ctx);
        CONFLATE_LOG(handle, LOG_LVL_INFO, "xmpp_run exited");

        xmpp_conn_release(handle->conn);
        xmpp_ctx_free(handle->ctx);

        sleep(5);
        CONFLATE_LOG(handle, LOG_LVL_INFO, "reconnecting");
    }
    CONFLATE_LOG(handle, LOG_LVL_FATAL, "Exited an infinite loop.");
    return NULL;
}