mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-24 02:16:20 +00:00
Fix devicelist subscription and handle pubsub event
Devicelist subscription can be done directly with caps_add feature.
This commit is contained in:
@@ -76,7 +76,6 @@ static void _handel_muc_user(xmpp_stanza_t *const stanza);
|
||||
static void _handle_conference(xmpp_stanza_t *const stanza);
|
||||
static void _handle_captcha(xmpp_stanza_t *const stanza);
|
||||
static void _handle_receipt_received(xmpp_stanza_t *const stanza);
|
||||
static void _handle_pubsub_event(xmpp_stanza_t *const stanza);
|
||||
static void _handle_chat(xmpp_stanza_t *const stanza);
|
||||
|
||||
static void _send_message_stanza(xmpp_stanza_t *const stanza);
|
||||
@@ -129,7 +128,20 @@ _message_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *con
|
||||
|
||||
xmpp_stanza_t *event = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_PUBSUB_EVENT);
|
||||
if (event) {
|
||||
_handle_pubsub_event(event);
|
||||
xmpp_stanza_t *child = xmpp_stanza_get_children(event);
|
||||
if (child) {
|
||||
const char *node = xmpp_stanza_get_attribute(child, STANZA_ATTR_NODE);
|
||||
if (node) {
|
||||
ProfMessageHandler *handler = g_hash_table_lookup(pubsub_event_handlers, node);
|
||||
if (handler) {
|
||||
int keep = handler->func(stanza, handler->userdata);
|
||||
if (!keep) {
|
||||
free(handler);
|
||||
g_hash_table_remove(pubsub_event_handlers, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_handle_chat(stanza);
|
||||
@@ -665,25 +677,6 @@ _handle_receipt_received(xmpp_stanza_t *const stanza)
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
static void
|
||||
_handle_pubsub_event(xmpp_stanza_t *const event)
|
||||
{
|
||||
xmpp_stanza_t *child = xmpp_stanza_get_children(event);
|
||||
if (child) {
|
||||
const char *node = xmpp_stanza_get_attribute(event, STANZA_ATTR_NODE);
|
||||
if (node) {
|
||||
ProfMessageHandler *handler = g_hash_table_lookup(pubsub_event_handlers, node);
|
||||
if (handler) {
|
||||
int keep = handler->func(event, handler->userdata);
|
||||
if (!keep) {
|
||||
free(handler);
|
||||
g_hash_table_remove(pubsub_event_handlers, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_receipt_request_handler(xmpp_stanza_t *const stanza)
|
||||
{
|
||||
|
||||
@@ -1,30 +1,36 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "xmpp/connection.h"
|
||||
#include "xmpp/message.h"
|
||||
#include "xmpp/iq.h"
|
||||
#include "xmpp/stanza.h"
|
||||
|
||||
#include "omemo/omemo.h"
|
||||
|
||||
static int _omemo_receive_devicelist(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
|
||||
void
|
||||
omemo_devicelist_subscribe(void)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
char *barejid = xmpp_jid_bare(ctx, session_get_account_name());
|
||||
xmpp_stanza_t *iq = stanza_create_omemo_devicelist_subscribe(ctx, barejid);
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
message_pubsub_event_handler_add(STANZA_NS_OMEMO_DEVICELIST, _omemo_receive_devicelist, NULL, NULL);
|
||||
|
||||
free(barejid);
|
||||
caps_add_feature(XMPP_FEATURE_OMEMO_DEVICELIST_NOTIFY);
|
||||
}
|
||||
|
||||
void
|
||||
omemo_devicelist_publish(void)
|
||||
omemo_devicelist_publish(GList *device_list)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_omemo_devicelist_publish(ctx, omemo_device_list());
|
||||
xmpp_stanza_t *iq = stanza_create_omemo_devicelist_publish(ctx, device_list);
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
void
|
||||
omemo_devicelist_fetch(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
omemo_bundle_publish(void)
|
||||
{
|
||||
@@ -53,3 +59,47 @@ omemo_bundle_publish(void)
|
||||
free(signed_prekey);
|
||||
free(signed_prekey_signature);
|
||||
}
|
||||
|
||||
void
|
||||
omemo_bundles_fetch(const char * const jid)
|
||||
{
|
||||
}
|
||||
|
||||
static int
|
||||
_omemo_receive_devicelist(xmpp_stanza_t *const stanza, void *const userdata)
|
||||
{
|
||||
GList *device_list = NULL;
|
||||
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||
if (!from) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *event = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_PUBSUB_EVENT);
|
||||
if (!event) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *items = xmpp_stanza_get_child_by_name(event, "items");
|
||||
if (!items) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(items, "item");
|
||||
if (!item) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *list = xmpp_stanza_get_child_by_ns(item, STANZA_NS_OMEMO);
|
||||
if (!list) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *device;
|
||||
for (device = xmpp_stanza_get_children(list); device != NULL; device = xmpp_stanza_get_next(device)) {
|
||||
const char *id = xmpp_stanza_get_id(device);
|
||||
device_list = g_list_append(device_list, GINT_TO_POINTER(strtoul(id, NULL, 10)));
|
||||
}
|
||||
omemo_set_device_list(from, device_list);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <glib.h>
|
||||
|
||||
void omemo_devicelist_subscribe(void);
|
||||
void omemo_devicelist_publish(void);
|
||||
void omemo_devicelist_publish(GList *device_list);
|
||||
void omemo_bundle_publish(void);
|
||||
|
||||
@@ -321,7 +321,7 @@ session_login_success(gboolean secured)
|
||||
#ifdef HAVE_OMEMO
|
||||
omemo_devicelist_subscribe();
|
||||
if (omemo_loaded()) {
|
||||
omemo_devicelist_publish();
|
||||
/* TODO: update devicelist */
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2105,7 +2105,7 @@ stanza_create_omemo_devicelist_subscribe(xmpp_ctx_t *ctx, const char *const jid)
|
||||
|
||||
xmpp_stanza_t *subscribe = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(subscribe, STANZA_NAME_SUBSCRIBE);
|
||||
xmpp_stanza_set_attribute(subscribe, "node", "eu.siacs.conversations.axolotl.devicelist");
|
||||
xmpp_stanza_set_attribute(subscribe, "node", STANZA_NS_OMEMO_DEVICELIST);
|
||||
xmpp_stanza_set_attribute(subscribe, "jid", jid);
|
||||
|
||||
xmpp_stanza_add_child(pubsub, subscribe);
|
||||
@@ -2130,7 +2130,7 @@ stanza_create_omemo_devicelist_publish(xmpp_ctx_t *ctx, GList *const ids)
|
||||
|
||||
xmpp_stanza_t *publish = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(publish, STANZA_NAME_PUBLISH);
|
||||
xmpp_stanza_set_attribute(publish, "node", "eu.siacs.conversations.axolotl.devicelist");
|
||||
xmpp_stanza_set_attribute(publish, "node", STANZA_NS_OMEMO_DEVICELIST);
|
||||
|
||||
xmpp_stanza_t *item = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
|
||||
|
||||
@@ -191,6 +191,8 @@
|
||||
#define STANZA_NS_X_OOB "jabber:x:oob"
|
||||
#define STANZA_NS_BLOCKING "urn:xmpp:blocking"
|
||||
#define STANZA_NS_COMMAND "http://jabber.org/protocol/commands"
|
||||
#define STANZA_NS_OMEMO "eu.siacs.conversations.axolotl"
|
||||
#define STANZA_NS_OMEMO_DEVICELIST "eu.siacs.conversations.axolotl.devicelist"
|
||||
|
||||
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
#define XMPP_FEATURE_LASTACTIVITY "jabber:iq:last"
|
||||
#define XMPP_FEATURE_MUC "http://jabber.org/protocol/muc"
|
||||
#define XMPP_FEATURE_COMMANDS "http://jabber.org/protocol/commands"
|
||||
#define XMPP_FEATURE_OMEMO_DEVICELIST_NOTIFY "eu.siacs.conversations.axolotl.devicelist+notify"
|
||||
|
||||
typedef enum {
|
||||
JABBER_CONNECTING,
|
||||
|
||||
Reference in New Issue
Block a user