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); } }
void bookmark_request(void) { char *id; xmpp_conn_t *conn = connection_get_conn(); xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_stanza_t *iq; id = strdup("bookmark_init_request"); autojoin_count = 0; if (bookmark_ac != NULL) { autocomplete_free(bookmark_ac); } bookmark_ac = autocomplete_new(); if (bookmark_list != NULL) { g_list_free_full(bookmark_list, _bookmark_item_destroy); bookmark_list = NULL; } xmpp_timed_handler_add(conn, _bookmark_handle_delete, BOOKMARK_TIMEOUT, id); xmpp_id_handler_add(conn, _bookmark_handle_result, id, id); iq = stanza_create_storage_bookmarks(ctx); xmpp_stanza_set_id(iq, id); xmpp_send(conn, iq); xmpp_stanza_release(iq); }
static void _iq_set_autoping(const int seconds) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); if (jabber_get_connection_status() == JABBER_CONNECTED) { xmpp_timed_handler_delete(conn, _ping_timed_handler); if (seconds != 0) { int millis = seconds * 1000; xmpp_timed_handler_add(conn, _ping_timed_handler, millis, ctx); } } }
void iq_add_handlers(void) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); HANDLE(NULL, STANZA_TYPE_ERROR, _error_handler); HANDLE(XMPP_NS_DISCO_INFO, STANZA_TYPE_GET, _disco_info_get_handler); HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_GET, _disco_items_get_handler); HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_RESULT, _disco_items_result_handler); HANDLE(STANZA_NS_VERSION, STANZA_TYPE_GET, _version_get_handler); HANDLE(STANZA_NS_VERSION, STANZA_TYPE_RESULT, _version_result_handler); HANDLE(STANZA_NS_PING, STANZA_TYPE_GET, _ping_get_handler); if (prefs_get_autoping() != 0) { int millis = prefs_get_autoping() * 1000; xmpp_timed_handler_add(conn, _ping_timed_handler, millis, ctx); } }