diff --git a/channel.cpp b/channel.cpp index 4df14d2..dc903a4 100644 --- a/channel.cpp +++ b/channel.cpp @@ -890,6 +890,19 @@ void channel__update_topic(struct t_channel *channel, weechat_buffer_set(channel->buffer, "title", ""); } +void channel__update_name(struct t_channel *channel, + const char* name) +{ + if (channel->name) + free(channel->name); + channel->name = (name) ? strdup(name) : NULL; + + if (channel->name) + weechat_buffer_set(channel->buffer, "short_name", name); + else + weechat_buffer_set(channel->buffer, "short_name", ""); +} + struct t_channel_member *channel__add_member(struct t_account *account, struct t_channel *channel, const char *id, const char *client) diff --git a/channel.hh b/channel.hh index 3298201..3819d24 100644 --- a/channel.hh +++ b/channel.hh @@ -180,6 +180,9 @@ void channel__update_topic(struct t_channel *channel, const char* creator, int last_set); +void channel__update_name(struct t_channel *channel, + const char* name); + void channel__update_purpose(struct t_channel *channel, const char* purpose, const char* creator, diff --git a/command.cpp b/command.cpp index 3cfd44f..5b613ad 100644 --- a/command.cpp +++ b/command.cpp @@ -905,7 +905,11 @@ int command__xml(const void *pointer, void *data, stanza = xmpp_stanza_new_from_string(ptr_account->context, argv_eol[1]); if (!stanza) + { + weechat_printf(nullptr, _("%s%s: Bad XML"), + weechat_prefix("error"), WEECHAT_XMPP_PLUGIN_NAME); return WEECHAT_RC_ERROR; + } xmpp_send(ptr_account->connection, stanza); xmpp_stanza_release(stanza); diff --git a/connection.cpp b/connection.cpp index 9cc149f..8cc7ac3 100644 --- a/connection.cpp +++ b/connection.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -980,15 +981,16 @@ int connection__iq_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userd if (const char *attr = xmpp_stanza_get_attribute(identity, "category")) category = attr; if (const char *attr = xmpp_stanza_get_attribute(identity, "name")) - name = attr; + name = unescape(attr); if (const char *attr = xmpp_stanza_get_attribute(identity, "type")) type = attr; if (category == "conference") { struct t_channel *ptr_channel = channel__search(account, from); - weechat_printf(ptr_channel ? ptr_channel->buffer : nullptr, "%sname = %s", - weechat_prefix("network"), name.data()); + + if (ptr_channel) + channel__update_name(ptr_channel, name.data()); } else if (category == "conference") { diff --git a/util.cpp b/util.cpp index 6ab5037..06c7b7a 100644 --- a/util.cpp +++ b/util.cpp @@ -2,6 +2,9 @@ // License, version 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. +#include +#include +#include #include #include #include @@ -48,3 +51,25 @@ char *stanza_xml(xmpp_stanza_t *stanza) xmpp_stanza_to_text(stanza, &result, &len); return result; } + +std::string unescape(const std::string& str) +{ + std::regex regex("\\&\\#(\\d+);"); + std::sregex_iterator begin(str.begin(), str.end(), regex), end; + if (begin != end) + { + std::ostringstream output; + do { + std::smatch const& m = *begin; + if (m[1].matched) + { + auto ch = static_cast(std::stoul(m.str(1))); + output << m.prefix() << ch; + } + else output << m.prefix() << m.str(0); + } while (++begin != end); + output << str.substr(str.size() - begin->position()); + return output.str(); + } + return str; +} diff --git a/util.hh b/util.hh index d83cf6a..633e2c1 100644 --- a/util.hh +++ b/util.hh @@ -4,8 +4,12 @@ #pragma once +#include + int char_cmp(const void *p1, const void *p2); char *exec(const char *command); char *stanza_xml(struct _xmpp_stanza_t *stanza); + +std::string unescape(const std::string& str); diff --git a/xmpp/ns.hh b/xmpp/ns.hh index 5716dd4..d6164aa 100644 --- a/xmpp/ns.hh +++ b/xmpp/ns.hh @@ -16,6 +16,19 @@ public: inline operator const char *() { return _uri; } }; +struct eu { + struct siacs { + struct conversations { + struct axolotl : public xmlns { axolotl() : xmlns("eu.siacs.conversations.axolotl") {} + struct bundles : public xmlns { bundles() : xmlns("eu.siacs.conversations.axolotl.bundles") {} }; + struct devicelist : public xmlns { devicelist() : xmlns("eu.siacs.conversations.axolotl.devicelist") {} + struct notify : public xmlns { notify() : xmlns("eu.siacs.conversations.axolotl.devicelist+notify") {} }; + }; + }; + }; + }; +}; + struct etherx_jabber_org { struct streams : public xmlns { streams() : xmlns("http://etherx.jabber.org/streams") {} }; }; diff --git a/xmpp/xep-0030.inl b/xmpp/xep-0030.inl index 23382a0..d17a209 100644 --- a/xmpp/xep-0030.inl +++ b/xmpp/xep-0030.inl @@ -27,7 +27,7 @@ namespace stanza { iq& xep0030() { return *this; } - iq& query(query q = xep0030::query()) { child(q); return *this; } + iq& query(xep0030::query q = {}) { child(q); return *this; } }; }; diff --git a/xmpp/xep-0049.inl b/xmpp/xep-0049.inl index f9f82a2..d6ad54c 100644 --- a/xmpp/xep-0049.inl +++ b/xmpp/xep-0049.inl @@ -35,7 +35,7 @@ namespace stanza { iq& xep0049() { return *this; } - iq& query(query q = xep0049::query()) { child(q); return *this; } + iq& query(xep0049::query q = {}) { child(q); return *this; } }; };