unescape xml names, and misc

master
bqv 2 years ago
parent 54a8ca57a5
commit efffd451fa
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -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)

@ -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,

@ -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);

@ -10,6 +10,7 @@
#include <sys/utsname.h>
#include <fmt/core.h>
#include <fmt/chrono.h>
#include <libxml/uri.h>
#include <strophe.h>
#include <weechat/weechat-plugin.h>
@ -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")
{

@ -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 <regex>
#include <string>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -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<char>(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;
}

@ -4,8 +4,12 @@
#pragma once
#include <string>
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);

@ -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") {} };
};

@ -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; }
};
};

@ -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; }
};
};

Loading…
Cancel
Save