Index: source/lobby/XmppClient.cpp =================================================================== --- source/lobby/XmppClient.cpp +++ source/lobby/XmppClient.cpp @@ -172,6 +172,8 @@ glooxwrapper::Tag::free(t); for (const glooxwrapper::Tag* const& t : m_Profile) glooxwrapper::Tag::free(t); + + delete m_sessionManager; } /// Network Index: source/lobby/glooxwrapper/glooxwrapper.h =================================================================== --- source/lobby/glooxwrapper/glooxwrapper.h +++ source/lobby/glooxwrapper/glooxwrapper.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -585,6 +585,9 @@ ConstTagList findTagList_clone(const string& expression) const; // like findTagList but each tag must be Tag::free()d }; + /** + * See XEP-0166: Jingle and https://camaya.net/api/gloox/namespacegloox_1_1Jingle.html. + */ namespace Jingle { @@ -605,13 +608,9 @@ typedef list PluginList; - class GLOOXWRAPPER_API Content : public Plugin - { - public: - Content(const string& name, const PluginList& plugins); - Content(); - }; - + /** + * See XEP-0176: Jingle ICE-UDP Transport Method + */ class GLOOXWRAPPER_API ICEUDP : public Plugin { public: @@ -624,6 +623,7 @@ ICEUDP(CandidateList& candidates); ICEUDP(); + ~ICEUDP(); const CandidateList candidates() const; }; @@ -643,12 +643,11 @@ public: Jingle(const gloox::Jingle::Session::Jingle* wrapped, bool owned) : m_Wrapped(wrapped), m_Owned(owned) {} - const PluginList plugins() const; - ICEUDP::Candidate getCandidate() const; }; - Session(gloox::Jingle::Session* wrapped, bool owned) : m_Wrapped(wrapped), m_Owned(owned) {} + Session(gloox::Jingle::Session* wrapped, bool owned); + ~Session(); bool sessionInitiate(char* ipStr, uint16_t port); }; Index: source/lobby/glooxwrapper/glooxwrapper.cpp =================================================================== --- source/lobby/glooxwrapper/glooxwrapper.cpp +++ source/lobby/glooxwrapper/glooxwrapper.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -282,9 +282,17 @@ SessionHandlerWrapper(glooxwrapper::Jingle::SessionHandler* wrapped, bool owned) : m_Wrapped(wrapped), m_Owned(owned) {} + ~SessionHandlerWrapper() + { + if (m_Owned) + delete m_Wrapped; + } + virtual void handleSessionAction(gloox::Jingle::Action action, gloox::Jingle::Session* session, const gloox::Jingle::Session::Jingle* jingle) { - m_Wrapped->handleSessionAction(action, new glooxwrapper::Jingle::Session(session, false), new glooxwrapper::Jingle::Session::Jingle(jingle, false)); + glooxwrapper::Jingle::Session sessionWrapper(session, false); + glooxwrapper::Jingle::Session::Jingle jingleWrapper(jingle, false); + m_Wrapped->handleSessionAction(action, &sessionWrapper, &jingleWrapper); } virtual void handleSessionActionError(gloox::Jingle::Action UNUSED(action), gloox::Jingle::Session* UNUSED(session), const gloox::Error* UNUSED(error)) @@ -374,8 +382,8 @@ void glooxwrapper::Client::registerStanzaExtension(glooxwrapper::StanzaExtension* ext) { - gloox::StanzaExtension* stanza = new StanzaExtensionWrapper(ext, true); - m_Wrapped->registerStanzaExtension(stanza); + // ~StanzaExtensionFactory() deletes this new StanzaExtensionWrapper + m_Wrapped->registerStanzaExtension(new StanzaExtensionWrapper(ext, true)); } void glooxwrapper::Client::registerConnectionListener(glooxwrapper::ConnectionListener* hnd) @@ -788,32 +796,6 @@ return glooxwrapper::Jingle::Plugin(m_Wrapped->findPlugin(type), false); } -glooxwrapper::Jingle::Content::Content(const string& name, const PluginList& plugins) - : glooxwrapper::Jingle::Plugin(NULL, false) -{ - gloox::Jingle::PluginList glooxPluginList; - for (const glooxwrapper::Jingle::Plugin* const& plugin: plugins) - glooxPluginList.push_back(plugin->getWrapped()); - - m_Wrapped = new gloox::Jingle::Content(name.to_string(), glooxPluginList); - m_Owned = true; -} - -glooxwrapper::Jingle::Content::Content() - : glooxwrapper::Jingle::Plugin(NULL, false) -{ - m_Wrapped = new gloox::Jingle::Content(); - m_Owned = true; -} - -const glooxwrapper::Jingle::PluginList glooxwrapper::Jingle::Session::Jingle::plugins() const -{ - glooxwrapper::Jingle::PluginList pluginListWrapper; - for (const gloox::Jingle::Plugin* const& plugin : m_Wrapped->plugins()) - pluginListWrapper.push_back(new glooxwrapper::Jingle::Plugin(const_cast(plugin), false)); - return pluginListWrapper; -} - glooxwrapper::Jingle::ICEUDP::Candidate glooxwrapper::Jingle::Session::Jingle::getCandidate() const { const gloox::Jingle::Content* content = static_cast(m_Wrapped->plugins().front()); @@ -828,11 +810,22 @@ return glooxwrapper::Jingle::ICEUDP::Candidate{glooxCandidate.ip, glooxCandidate.port}; } +glooxwrapper::Jingle::Session::Session(gloox::Jingle::Session* wrapped, bool owned) + : m_Wrapped(wrapped), m_Owned(owned) +{ +} + +glooxwrapper::Jingle::Session::~Session() +{ + if (m_Owned) + delete m_Wrapped; +} + bool glooxwrapper::Jingle::Session::sessionInitiate(char* ipStr, u16 port) { - gloox::Jingle::ICEUDP::CandidateList* candidateList = new gloox::Jingle::ICEUDP::CandidateList(); + gloox::Jingle::ICEUDP::CandidateList candidateList; - candidateList->push_back(gloox::Jingle::ICEUDP::Candidate + candidateList.push_back(gloox::Jingle::ICEUDP::Candidate { "1", // component_id, "1", // foundation @@ -848,9 +841,12 @@ gloox::Jingle::ICEUDP::ServerReflexive }); - gloox::Jingle::PluginList* pluginList = new gloox::Jingle::PluginList(); - pluginList->push_back(new gloox::Jingle::ICEUDP(/*local_pwd*/"", /*local_ufrag*/"", *candidateList)); - return m_Wrapped->sessionInitiate(new gloox::Jingle::Content(std::string("game-data"), *pluginList)); + gloox::Jingle::PluginList pluginList; + pluginList.push_back(new gloox::Jingle::ICEUDP(/*local_pwd*/"", /*local_ufrag*/"", candidateList)); + + gloox::Jingle::Content glooxJingleContent(std::string("game-data"), pluginList); + + return m_Wrapped->sessionInitiate(&glooxJingleContent); } glooxwrapper::Jingle::ICEUDP::ICEUDP(glooxwrapper::Jingle::ICEUDP::CandidateList& candidates) @@ -885,6 +881,11 @@ m_Owned = true; } +glooxwrapper::Jingle::ICEUDP::~ICEUDP() +{ + delete m_Wrapped; +} + const glooxwrapper::Jingle::ICEUDP::CandidateList glooxwrapper::Jingle::ICEUDP::candidates() const { glooxwrapper::Jingle::ICEUDP::CandidateList candidateListWrapper; @@ -907,6 +908,7 @@ void glooxwrapper::SessionManager::registerPlugins() { + // ~PluginFactory() deletes these new plugins m_Wrapped->registerPlugin(new gloox::Jingle::Content()); m_Wrapped->registerPlugin(new gloox::Jingle::ICEUDP()); } @@ -914,5 +916,5 @@ glooxwrapper::Jingle::Session glooxwrapper::SessionManager::createSession(const JID& callee) { gloox::Jingle::Session* glooxSession = m_Wrapped->createSession(callee.getWrapped(), m_HandlerWrapper); - return glooxwrapper::Jingle::Session(glooxSession, false); + return glooxwrapper::Jingle::Session(glooxSession, true); }