diff --git a/account.cpp b/account.cpp index 2522e41..23153b7 100644 --- a/account.cpp +++ b/account.cpp @@ -587,6 +587,7 @@ void account__free(struct t_account *account) account__free_data(account); delete account; + account = nullptr; accounts = new_accounts; } @@ -692,12 +693,12 @@ struct t_gui_buffer *account__create_buffer(struct t_account *account) &buffer__close_cb, NULL, NULL); if (!account->buffer) return NULL; + weechat_printf(account->buffer, "xmpp: %s", account->name); if (!weechat_buffer_get_integer(account->buffer, "short_name_is_set")) weechat_buffer_set(account->buffer, "short_name", account->name); weechat_buffer_set(account->buffer, "localvar_set_type", "server"); - weechat_buffer_set(account->buffer, "localvar_set_server", account->name); - weechat_buffer_set(account->buffer, "localvar_set_channel", account->name); + weechat_buffer_set(account->buffer, "localvar_set_account", account->name); snprintf(charset_modifier, sizeof (charset_modifier), "account.%s", account->name); weechat_buffer_set(account->buffer, "localvar_set_charset_modifier", diff --git a/connection.cpp b/connection.cpp index a35ed2b..d2bce7a 100644 --- a/connection.cpp +++ b/connection.cpp @@ -117,9 +117,11 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void xmpp_stanza_release(children[0]); } - channel = channel__search(account, std::string(binding.from->bare).data()); + channel = channel__search(account, binding.from->bare.data()); if (!(binding.type && *binding.type == "unavailable") && !binding.muc_user() && !channel) - channel = channel__new(account, CHANNEL_TYPE_PM, std::string(binding.from->bare).data(), std::string(binding.from->bare).data()); + { + channel = channel__new(account, CHANNEL_TYPE_PM, binding.from->bare.data(), binding.from->bare.data()); + } if (auto x = binding.muc_user()) { @@ -185,12 +187,12 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void std::string affiliation(item.affiliation ? xep0045::format_affiliation(*item.affiliation) : ""); std::string jid = item.target ? item.target->full : clientid; - user = user__search(account, std::string(binding.from->full).data()); + user = user__search(account, binding.from->full.data()); if (!user) - user = user__new(account, std::string(binding.from->full).data(), - channel && std::string(binding.from->bare).data() == channel->id - ? (binding.from->resource.size() ? std::string(binding.from->resource).data() : "") - : std::string(binding.from->full).data()); + user = user__new(account, binding.from->full.data(), + channel && binding.from->bare.data() == channel->id + ? (binding.from->resource.size() ? binding.from->resource.data() : "") + : binding.from->full.data()); auto status = binding.status(); auto show = binding.show(); auto idle = binding.idle_since(); @@ -211,20 +213,20 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void } if (weechat_strcasecmp(role.data(), "none") == 0) - channel__remove_member(account, channel, std::string(binding.from->full).data(), status ? status->data() : nullptr); + channel__remove_member(account, channel, binding.from->full.data(), status ? status->data() : nullptr); else - channel__add_member(account, channel, std::string(binding.from->full).data(), jid.data()); + channel__add_member(account, channel, binding.from->full.data(), jid.data()); } } } else { - user = user__search(account, std::string(binding.from->full).data()); + user = user__search(account, binding.from->full.data()); if (!user) - user = user__new(account, std::string(binding.from->full).data(), - channel && std::string(binding.from->bare).data() == channel->id - ? (binding.from->resource.size() ? std::string(binding.from->resource).data() : "") - : std::string(binding.from->full).data()); + user = user__new(account, binding.from->full.data(), + channel && binding.from->bare.data() == channel->id + ? (binding.from->resource.size() ? binding.from->resource.data() : "") + : binding.from->full.data()); auto status = binding.status(); auto show = binding.show(); auto idle = binding.idle_since(); @@ -244,9 +246,9 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void } if (user->profile.role) - channel__remove_member(account, channel, std::string(binding.from->full).data(), status ? status->data() : nullptr); + channel__remove_member(account, channel, binding.from->full.data(), status ? status->data() : nullptr); else - channel__add_member(account, channel, std::string(binding.from->full).data(), clientid.data()); + channel__add_member(account, channel, binding.from->full.data(), clientid.data()); } } diff --git a/makefile b/makefile index 03b44f0..f862aea 100644 --- a/makefile +++ b/makefile @@ -94,6 +94,8 @@ weechat-xmpp: $(DEPS) xmpp.so xmpp.so: $(OBJS) $(DEPS) $(HDRS) $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(DEPS) $(LDLIBS) + git ls-files | xargs tar c | objcopy --add-section .source=/dev/stdin xmpp.so + #objcopy --dump-section .source=/dev/stdout xmpp.so | tar t .%.o: %.c $(eval GIT_REF=$(shell git describe --abbrev=6 --always --dirty 2>/dev/null || true)) @@ -138,7 +140,7 @@ coverage: tests/run debug: xmpp.so env LD_PRELOAD=$(DEBUG) gdb -ex "handle SIGPIPE nostop noprint pass" --args \ - weechat -a -P 'alias,buflist,exec,irc' -r '/plugin load ./xmpp.so' + weechat -a -P 'alias,buflist,exec,irc,relay' -r '/plugin load ./xmpp.so' depend: $(SRCS) $(HDRS) $(RM) -f ./.depend diff --git a/pgp.cpp b/pgp.cpp index 6a7cec6..adc7913 100644 --- a/pgp.cpp +++ b/pgp.cpp @@ -1,4 +1,4 @@ -// This Source Code Form is subject to the terms of the Mozilla PublicAA +// This Source Code Form is subject to the terms of the Mozilla Public // 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/. diff --git a/xmpp/node.cpp b/xmpp/node.cpp index 1782b7c..368d2d1 100644 --- a/xmpp/node.cpp +++ b/xmpp/node.cpp @@ -49,15 +49,16 @@ const std::regex jid::pattern( "^((?:([^@/<>'\"]+)@)?([^@/<>'\"]+))(?:/([^<>'\"]*))?$"); jid::jid(xmpp_ctx_t *, std::string s) : full(s) { - auto as_sv = [](std::ssub_match m) { - if(!m.matched) return std::string_view(); - return std::string_view { &*m.first, static_cast(m.length()) }; - }; - std::smatch match; if (std::regex_search(full, match, pattern)) { + auto as_sv = [&](std::ssub_match m) { + if(!m.matched) return std::string_view(); + size_t offset = &*m.first - &*match[0].first; + return std::string_view{full.data() + offset, static_cast(m.length())}; + }; + bare = as_sv(match[1]); local = as_sv(match[2]); domain = as_sv(match[3]); diff --git a/xmpp/node.hh b/xmpp/node.hh index 283f69c..6b40933 100644 --- a/xmpp/node.hh +++ b/xmpp/node.hh @@ -34,10 +34,11 @@ public: operator std::string&() { return full; } std::string full; - std::string_view bare; - std::string_view local; - std::string_view domain; - std::string_view resource; + + std::string bare; + std::string local; + std::string domain; + std::string resource; bool is_bare() const; };