bookmarks

v1
Tony Olagbaiye 4 years ago
parent ee16eaaa7a
commit 0048ffde4c
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -592,7 +592,7 @@ int command__msg(const void *pointer, void *data,
if (ptr_channel->type != CHANNEL_TYPE_MUC) if (ptr_channel->type != CHANNEL_TYPE_MUC)
weechat_printf_date_tags(ptr_channel->buffer, 0, weechat_printf_date_tags(ptr_channel->buffer, 0,
"xmpp_message,message,private,notify_none,self_msg,log1", "xmpp_message,message,private,notify_none,self_msg,log1",
"%s%s", "%s\t%s",
user__as_prefix_raw(ptr_account, account_jid(ptr_account)), text); user__as_prefix_raw(ptr_account, account_jid(ptr_account)), text);
} }

@ -223,15 +223,15 @@ int connection__message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *
const char *edit = replace ? "* " : ""; // Losing which message was edited, sadly const char *edit = replace ? "* " : ""; // Losing which message was edited, sadly
if (strcmp(to, channel->id) == 0) if (strcmp(to, channel->id) == 0)
weechat_printf_date_tags(channel->buffer, date, *dyn_tags, "%s%s[to %s]: %s", weechat_printf_date_tags(channel->buffer, date, *dyn_tags, "%s%s\t[to %s]: %s",
edit, user__as_prefix_raw(account, nick), edit, user__as_prefix_raw(account, nick),
to, intext ? intext : ""); to, intext ? intext : "");
else if (weechat_string_match(intext, "/me *", 0)) else if (weechat_string_match(intext, "/me *", 0))
weechat_printf_date_tags(channel->buffer, date, *dyn_tags, "%s%s%s %s", weechat_printf_date_tags(channel->buffer, date, *dyn_tags, "%s%s\t%s %s",
edit, weechat_prefix("action"), nick, edit, weechat_prefix("action"), nick,
intext ? intext+4 : ""); intext ? intext+4 : "");
else else
weechat_printf_date_tags(channel->buffer, date, *dyn_tags, "%s%s%s", weechat_printf_date_tags(channel->buffer, date, *dyn_tags, "%s%s\t%s",
edit, user__as_prefix_raw(account, nick), edit, user__as_prefix_raw(account, nick),
intext ? intext : ""); intext ? intext : "");
@ -249,12 +249,14 @@ int connection__iq_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userd
struct t_account *account = (struct t_account *)userdata; struct t_account *account = (struct t_account *)userdata;
xmpp_stanza_t *reply, *query, *identity, *feature, *x, *field, *value, *text; xmpp_stanza_t *reply, *query, *identity, *feature, *x, *field, *value, *text;
xmpp_stanza_t *pubsub, *items, *item, *list, *device, *children[2]; xmpp_stanza_t *pubsub, *items, *item, *list, *device, **children;
xmpp_stanza_t *storage, *conference, *nick;
static struct utsname osinfo; static struct utsname osinfo;
query = xmpp_stanza_get_child_by_name_and_ns( query = xmpp_stanza_get_child_by_name_and_ns(
stanza, "query", "http://jabber.org/protocol/disco#info"); stanza, "query", "http://jabber.org/protocol/disco#info");
if (query) const char *type = xmpp_stanza_get_attribute(stanza, "type");
if (query && type && weechat_strcasecmp(type, "get") == 0)
{ {
char *client_name; char *client_name;
@ -279,13 +281,38 @@ int connection__iq_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userd
xmpp_stanza_add_child(query, feature); \ xmpp_stanza_add_child(query, feature); \
xmpp_stanza_release(feature); xmpp_stanza_release(feature);
FEATURE("eu.siacs.conversations.axolotl.devicelist+notify");
FEATURE("http://jabber.org/protocol/caps"); FEATURE("http://jabber.org/protocol/caps");
FEATURE("http://jabber.org/protocol/chatstates");
FEATURE("http://jabber.org/protocol/disco#info"); FEATURE("http://jabber.org/protocol/disco#info");
FEATURE("http://jabber.org/protocol/disco#items"); FEATURE("http://jabber.org/protocol/disco#items");
FEATURE("http://jabber.org/protocol/muc"); FEATURE("http://jabber.org/protocol/muc");
FEATURE("eu.siacs.conversations.axolotl.devicelist"); FEATURE("http://jabber.org/protocol/nick+notify");
FEATURE("eu.siacs.conversations.axolotl.devicelist+notify"); FEATURE("jabber:iq:version");
FEATURE("jabber:x:conference");
FEATURE("jabber:x:oob");
FEATURE("storage:bookmarks+notify"); FEATURE("storage:bookmarks+notify");
FEATURE("urn:xmpp:avatar:metadata+notify");
FEATURE("urn:xmpp:chat-markers:0");
FEATURE("urn:xmpp:idle:1");
//FEATURE("urn:xmpp:jingle-message:0");
//FEATURE("urn:xmpp:jingle:1");
//FEATURE("urn:xmpp:jingle:apps:dtls:0");
//FEATURE("urn:xmpp:jingle:apps:file-transfer:3");
//FEATURE("urn:xmpp:jingle:apps:file-transfer:4");
//FEATURE("urn:xmpp:jingle:apps:file-transfer:5");
//FEATURE("urn:xmpp:jingle:apps:rtp:1");
//FEATURE("urn:xmpp:jingle:apps:rtp:audio");
//FEATURE("urn:xmpp:jingle:apps:rtp:video");
//FEATURE("urn:xmpp:jingle:jet-omemo:0");
//FEATURE("urn:xmpp:jingle:jet:0");
//FEATURE("urn:xmpp:jingle:transports:ibb:1");
//FEATURE("urn:xmpp:jingle:transports:ice-udp:1");
//FEATURE("urn:xmpp:jingle:transports:s5b:1");
FEATURE("urn:xmpp:message-correct:0");
FEATURE("urn:xmpp:ping");
FEATURE("urn:xmpp:receipts");
FEATURE("urn:xmpp:time");
#undef FEATURE #undef FEATURE
x = xmpp_stanza_new(account->context); x = xmpp_stanza_new(account->context);
@ -299,7 +326,7 @@ int connection__iq_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userd
*osinfo.release = 0; *osinfo.release = 0;
} }
// This is utter bullshit, TODO: not this. // This is utter bullshit, TODO: anything but this.
{ {
field = xmpp_stanza_new(account->context); field = xmpp_stanza_new(account->context);
xmpp_stanza_set_name(field, "field"); xmpp_stanza_set_name(field, "field");
@ -452,69 +479,132 @@ int connection__iq_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userd
items = xmpp_stanza_get_child_by_name(pubsub, "items"); items = xmpp_stanza_get_child_by_name(pubsub, "items");
if (items) if (items)
items_node = xmpp_stanza_get_attribute(items, "node");
if (items && items_node
&& weechat_strcasecmp(items_node,
"eu.siacs.conversations.axolotl.devicelist") == 0)
{ {
item = xmpp_stanza_get_child_by_name(items, "item"); items_node = xmpp_stanza_get_attribute(items, "node");
if (item) if (items_node
item_id = xmpp_stanza_get_id(item); && weechat_strcasecmp(items_node,
if (item && item_id && weechat_strcasecmp(item_id, "current") == 0) "eu.siacs.conversations.axolotl.devicelist") == 0)
{ {
list = xmpp_stanza_get_child_by_name_and_ns( item = xmpp_stanza_get_child_by_name(items, "item");
item, "list", "eu.siacs.conversations.axolotl"); if (item)
if (list) item_id = xmpp_stanza_get_id(item);
if (item && item_id && weechat_strcasecmp(item_id, "current") == 0)
{ {
account__free_device_all(account); list = xmpp_stanza_get_child_by_name_and_ns(
item, "list", "eu.siacs.conversations.axolotl");
struct t_device *dev = malloc(sizeof(dev)); if (list)
char id[64] = {0};
dev->id = account->omemo->device_id;
snprintf(id, sizeof(id), "%d", dev->id);
dev->name = strdup(id);
account__add_device(account, dev);
free(dev->name);
free(dev);
for (device = xmpp_stanza_get_children(list);
device; device = xmpp_stanza_get_next(device))
{ {
device_id = xmpp_stanza_get_id(device); account__free_device_all(account);
dev = malloc(sizeof(dev)); struct t_device *dev = malloc(sizeof(dev));
dev->id = atoi(device_id); char id[64] = {0};
dev->name = strdup(device_id);
dev->id = account->omemo->device_id;
snprintf(id, sizeof(id), "%d", dev->id);
dev->name = strdup(id);
account__add_device(account, dev); account__add_device(account, dev);
int i = 0;
children = malloc(sizeof(xmpp_stanza_t *) * 128);
children[i++] = stanza__iq_pubsub_publish_item_list_device(
account->context, NULL, with_noop(dev->name));
free(dev->name); free(dev->name);
free(dev); free(dev);
}
reply = xmpp_stanza_reply(stanza); for (device = xmpp_stanza_get_children(list);
xmpp_stanza_set_type(reply, "result"); device; device = xmpp_stanza_get_next(device))
{
children[1] = NULL; const char *name = xmpp_stanza_get_name(device);
children[0] = stanza__iq_pubsub_publish_item_list_device( if (weechat_strcasecmp(name, "device") != 0)
account->context, NULL, with_noop(id)); continue;
ns = "http://jabber.org/protocol/pubsub";
children[0] = stanza__iq_pubsub_publish_item_list( device_id = xmpp_stanza_get_id(device);
account->context, NULL, children, with_noop(ns));
node = "eu.siacs.conversations.axolotl.devicelist"; dev = malloc(sizeof(dev));
children[0] = stanza__iq_pubsub_publish_item( dev->id = atoi(device_id);
account->context, NULL, children, with_noop(node)); dev->name = strdup(device_id);
children[0] = stanza__iq_pubsub_publish(account->context, account__add_device(account, dev);
NULL, children,
with_noop(ns)); children[i++] = stanza__iq_pubsub_publish_item_list_device(
children[0] = stanza__iq_pubsub(account->context, NULL, account->context, NULL, with_noop(dev->name));
children, with_noop(""));
reply = stanza__iq(account->context, reply, children, NULL, free(dev->name);
NULL, NULL, NULL, NULL); free(dev);
}
xmpp_send(conn, reply);
xmpp_stanza_release(reply); children[i] = NULL;
ns = "eu.siacs.conversations.axolotl";
children[0] = stanza__iq_pubsub_publish_item_list(
account->context, NULL, children, with_noop(ns));
children[1] = NULL;
children[0] = stanza__iq_pubsub_publish_item(
account->context, NULL, children, with_noop("current"));
node = "http://jabber.org/protocol/pubsub";
children[0] = stanza__iq_pubsub_publish(account->context,
NULL, children,
with_noop(node));
children[0] = stanza__iq_pubsub(account->context, NULL,
children, with_noop(""));
reply = stanza__iq(account->context, xmpp_stanza_reply(stanza),
children, NULL, strdup("announce1"),
NULL, NULL, strdup("set"));
free(children);
xmpp_send(conn, reply);
xmpp_stanza_release(reply);
}
}
}
if (items_node
&& weechat_strcasecmp(items_node, "storage:bookmarks") == 0)
{
item = xmpp_stanza_get_child_by_name(items, "item");
if (item)
item_id = xmpp_stanza_get_id(item);
if (item && item_id && weechat_strcasecmp(item_id, "current") == 0)
{
storage = xmpp_stanza_get_child_by_name_and_ns(
item, "storage", "storage:bookmarks");
if (storage)
{
for (conference = xmpp_stanza_get_children(storage);
conference; conference = xmpp_stanza_get_next(conference))
{
const char *name = xmpp_stanza_get_name(conference);
if (weechat_strcasecmp(name, "conference") != 0)
continue;
const char *jid = xmpp_stanza_get_attribute(conference, "jid");
const char *autojoin = xmpp_stanza_get_attribute(conference, "autojoin");
name = xmpp_stanza_get_attribute(conference, "name");
nick = xmpp_stanza_get_child_by_name(conference, "nick");
char *intext;
if (nick)
{
text = xmpp_stanza_get_children(nick);
intext = xmpp_stanza_get_text(text);
}
if (weechat_strcasecmp(autojoin, "true") == 0)
{
char **command = weechat_string_dyn_alloc(256);
weechat_string_dyn_concat(command, "/enter ", -1);
weechat_string_dyn_concat(command, jid, -1);
if (nick)
{
weechat_string_dyn_concat(command, "/", -1);
weechat_string_dyn_concat(command, intext, -1);
}
weechat_command(account->buffer, *command);
weechat_string_dyn_free(command, 1);
}
if (nick)
free(intext);
}
}
} }
} }
} }
@ -577,11 +667,20 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status,
xmpp_send(conn, pres); xmpp_send(conn, pres);
xmpp_stanza_release(pres); xmpp_stanza_release(pres);
char **command = weechat_string_dyn_alloc(256); children[1] = NULL;
weechat_string_dyn_concat(command, "/enter ", -1); children[0] =
weechat_string_dyn_concat(command, account_autojoin(account), -1); stanza__iq_pubsub_items(account->context, NULL,
weechat_command(account->buffer, *command); strdup("storage:bookmarks"));
weechat_string_dyn_free(command, 1); children[0] =
stanza__iq_pubsub(account->context, NULL, children,
with_noop("http://jabber.org/protocol/pubsub"));
children[0] =
stanza__iq(account->context, NULL, children, NULL, strdup("retrieve1"),
strdup(account_jid(account)), strdup(account_jid(account)),
strdup("get"));
xmpp_send(conn, children[0]);
xmpp_stanza_release(children[0]);
children[1] = NULL; children[1] = NULL;
children[0] = children[0] =

@ -30,9 +30,9 @@ const char *user__as_prefix_raw(struct t_account *account,
(void) account; (void) account;
snprintf(result, sizeof(result), "%s%s\t", snprintf(result, sizeof(result), "%s%s%s",
weechat_info_get("nick_color", name), weechat_info_get("nick_color", name),
name); name, weechat_color("reset"));
return result; return result;
} }

@ -186,9 +186,7 @@ xmpp_stanza_t *stanza__iq_pubsub_publish_item_list(xmpp_ctx_t *context, xmpp_sta
while (*child) while (*child)
{ {
xmpp_stanza_add_child(parent, *child); xmpp_stanza_add_child(parent, *child);
xmpp_stanza_release(*child); xmpp_stanza_release(*child++);
++child;
} }
return parent; return parent;

Loading…
Cancel
Save