Пример #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;
}
Пример #2
0
END_TEST

START_TEST (test_private_save)
{
    fail_unless(conflate_save_private(handle,"some key", "some value",
                                      db_loc),
                "Failed to save a new value.");
}
Пример #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
static void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
                         const int error, xmpp_stream_error_t * const stream_error,
                         void * const userdata)
{
    conflate_handle_t *handle = (conflate_handle_t *)userdata;

    if (status == XMPP_CONN_CONNECT) {
        xmpp_stanza_t* pres = NULL, *priority = NULL, *pri_text = NULL;
        CONFLATE_LOG(handle, LOG_LVL_INFO, "Connected.");
        xmpp_handler_add(conn, version_handler, "jabber:iq:version", "iq", NULL, handle);
        xmpp_handler_add(conn, command_handler, "http://jabber.org/protocol/commands",
                         "iq", NULL, handle);
        xmpp_handler_add(conn, disco_items_handler,
                         "http://jabber.org/protocol/disco#items", "iq", NULL, handle);
        xmpp_handler_add(conn, message_handler, NULL, "message", NULL, handle);
        xmpp_timed_handler_add(conn, keepalive_handler, 60000, handle);
        xmpp_timed_handler_add(conn, alarmqueue_handler, 10000, handle);

        /* Send initial <presence/> so that we appear online to contacts */
        pres = xmpp_stanza_new(handle->ctx);
        assert(pres);
        xmpp_stanza_set_name(pres, "presence");

        priority = xmpp_stanza_new(handle->ctx);
        assert(priority);
        xmpp_stanza_set_name(priority, "priority");
        add_and_release(pres, priority);

        pri_text = xmpp_stanza_new(handle->ctx);
        assert(pri_text);
        xmpp_stanza_set_text(pri_text, "5");
        add_and_release(priority, pri_text);

        xmpp_send(conn, pres);
        xmpp_stanza_release(pres);

        /* Store the bound jid */
        if (!conflate_save_private(handle, STORED_JID_KEY,
                                   xmpp_conn_get_bound_jid(conn),
                                   handle->conf->save_path)) {
            CONFLATE_LOG(handle, LOG_LVL_WARN, "Failed to save the bound jid");
        }
    }
    else {
        CONFLATE_LOG(handle, LOG_LVL_INFO, "disconnected.");
        xmpp_stop(handle->ctx);
    }
}