Changeset View
Standalone View
source/lobby/glooxwrapper/glooxwrapper.cpp
/* Copyright (C) 2015 Wildfire Games. | /* Copyright (C) 2017 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
virtual gloox::StanzaExtension* clone() const | virtual gloox::StanzaExtension* clone() const | ||||
{ | { | ||||
return new StanzaExtensionWrapper(m_Wrapped->clone(), true); | return new StanzaExtensionWrapper(m_Wrapped->clone(), true); | ||||
} | } | ||||
}; | }; | ||||
class SessionHandlerWrapper : public gloox::Jingle::SessionHandler | |||||
{ | |||||
public: | |||||
glooxwrapper::Jingle::SessionHandler* m_Wrapped; | |||||
bool m_Owned; | |||||
SessionHandlerWrapper(glooxwrapper::Jingle::SessionHandler* wrapped, bool owned) | |||||
: m_Wrapped(wrapped), m_Owned(owned) {} | |||||
elexis: make that session UNUSED() | |||||
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)); | |||||
} | |||||
virtual void handleSessionActionError(gloox::Jingle::Action UNUSED(action), gloox::Jingle::Session* UNUSED(session), const gloox::Error* UNUSED(error)) | |||||
{ | |||||
elexisUnsubmitted Not Done Inline Actions(This could become useful once we implement asynchroneous calls) elexis: (This could become useful once we implement asynchroneous calls) | |||||
} | |||||
virtual void handleIncomingSession(gloox::Jingle::Session* UNUSED(session)) | |||||
elexisUnsubmitted Not Done Inline Actions(This occurs for the host if someone attempts to join the game via ICE+STUN but we have nothing to do here as the connection to the STUN server is already registered) elexis: (This occurs for the host if someone attempts to join the game via ICE+STUN but we have nothing… | |||||
{ | |||||
} | |||||
}; | |||||
class ClientImpl | class ClientImpl | ||||
{ | { | ||||
public: | public: | ||||
// List of registered callback wrappers, to get deleted when Client is deleted | // List of registered callback wrappers, to get deleted when Client is deleted | ||||
std::list<shared_ptr<gloox::ConnectionListener> > m_ConnectionListeners; | std::list<shared_ptr<gloox::ConnectionListener> > m_ConnectionListeners; | ||||
std::list<shared_ptr<gloox::MessageHandler> > m_MessageHandlers; | std::list<shared_ptr<gloox::MessageHandler> > m_MessageHandlers; | ||||
std::list<shared_ptr<gloox::IqHandler> > m_IqHandlers; | std::list<shared_ptr<gloox::IqHandler> > m_IqHandlers; | ||||
}; | }; | ||||
static const std::string XMLNS = "xmlns"; | |||||
static const std::string XMLNS_JINGLE_0AD_GAME = "urn:xmpp:jingle:apps:0ad-game:1"; | |||||
class ZeroADGameData : public gloox::Jingle::Plugin | |||||
elexisUnsubmitted Not Done Inline ActionsThe engine should be agnostic of 0 A.D. (it should be usable for other games, f.e. for 500 AD). I could find no use or need for this Plugin and propose to delete it. elexis: The engine should be agnostic of 0 A.D. (it should be usable for other games, f.e. for 500 AD). | |||||
{ | |||||
public: | |||||
ZeroADGameData() : Plugin(gloox::Jingle::PluginUser) {} | |||||
ZeroADGameData(const gloox::Tag* UNUSED(tag)) : Plugin(gloox::Jingle::PluginUser) | |||||
{ | |||||
} | |||||
Not Done Inline ActionsWhat's the point of this? leper: What's the point of this? | |||||
Not Done Inline Actions404 elexis: 404 | |||||
const std::string& filterString() const { | |||||
static const std::string filter = "content/description[@xmlns='" + XMLNS_JINGLE_0AD_GAME + "']"; | |||||
return filter; | |||||
} | |||||
gloox::Tag* tag() const { | |||||
gloox::Tag* r = new gloox::Tag("description", XMLNS, XMLNS_JINGLE_0AD_GAME); | |||||
return r; | |||||
} | |||||
Plugin* newInstance(const gloox::Tag* tag) const | |||||
{ | |||||
return new ZeroADGameData(tag); | |||||
} | |||||
Plugin* clone() const | |||||
{ | |||||
return new ZeroADGameData(*this); | |||||
} | |||||
}; | |||||
} // namespace glooxwrapper | } // namespace glooxwrapper | ||||
glooxwrapper::Client::Client(const string& server) | glooxwrapper::Client::Client(const string& server) | ||||
{ | { | ||||
m_Wrapped = new gloox::Client(server.to_string()); | m_Wrapped = new gloox::Client(server.to_string()); | ||||
m_DiscoWrapper = new glooxwrapper::Disco(m_Wrapped->disco()); | m_DiscoWrapper = new glooxwrapper::Disco(m_Wrapped->disco()); | ||||
m_Impl = new ClientImpl; | m_Impl = new ClientImpl; | ||||
▲ Show 20 Lines • Show All 435 Lines • ▼ Show 20 Lines | |||||
glooxwrapper::ConstTagList glooxwrapper::Tag::findTagList_clone(const string& expression) const | glooxwrapper::ConstTagList glooxwrapper::Tag::findTagList_clone(const string& expression) const | ||||
{ | { | ||||
glooxwrapper::ConstTagList tagListWrapper; | glooxwrapper::ConstTagList tagListWrapper; | ||||
for (const gloox::Tag* const& t : m_Wrapped->findTagList(expression.to_string())) | for (const gloox::Tag* const& t : m_Wrapped->findTagList(expression.to_string())) | ||||
tagListWrapper.push_back(new glooxwrapper::Tag(const_cast<gloox::Tag*>(t), false)); | tagListWrapper.push_back(new glooxwrapper::Tag(const_cast<gloox::Tag*>(t), false)); | ||||
return tagListWrapper; | return tagListWrapper; | ||||
} | } | ||||
glooxwrapper::Jingle::Plugin::~Plugin() | |||||
{ | |||||
if (m_Owned) | |||||
delete m_Wrapped; | |||||
} | |||||
const glooxwrapper::Jingle::Plugin glooxwrapper::Jingle::Plugin::findPlugin(int type) const | |||||
{ | |||||
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; | |||||
elexisUnsubmitted Not Done Inline ActionsAppears correct to own the wrapped object as it's not used otherwise and needs to be deleted after usage. elexis: Appears correct to own the wrapped object as it's not used otherwise and needs to be deleted… | |||||
} | |||||
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()) | |||||
Not Done Inline Actionsspace before the colon elexis: space before the colon | |||||
pluginListWrapper.push_back(new glooxwrapper::Jingle::Plugin(const_cast<gloox::Jingle::Plugin*>(plugin), false)); | |||||
return pluginListWrapper; | |||||
} | |||||
glooxwrapper::Jingle::ICEUDP::Candidate glooxwrapper::Jingle::Session::Jingle::getCandidate() const | |||||
{ | |||||
const gloox::Jingle::Content *content = static_cast<const gloox::Jingle::Content*>(m_Wrapped->plugins().front()); | |||||
if (content == NULL) | |||||
{ | |||||
Not Done Inline Actionsprobably make those errors LOGERROR and the others LOGMESSAGE after including CLogger, elexis: probably make those errors LOGERROR and the others LOGMESSAGE after including CLogger,
so that… | |||||
printf("Failed to retrieve Jingle content\n"); | |||||
return glooxwrapper::Jingle::ICEUDP::Candidate(); | |||||
} | |||||
const ZeroADGameData *gameData = static_cast<const ZeroADGameData*>(content->findPlugin(gloox::Jingle::PluginUser)); | |||||
if (gameData == NULL) | |||||
{ | |||||
printf("Failed to retrieve Jingle game data\n"); | |||||
return glooxwrapper::Jingle::ICEUDP::Candidate(); | |||||
} | |||||
const gloox::Jingle::ICEUDP *iceUDP = static_cast<const gloox::Jingle::ICEUDP*>(content->findPlugin(gloox::Jingle::PluginICEUDP)); | |||||
if (iceUDP == NULL) | |||||
{ | |||||
printf("Failed to retrieve Jingle ICE-UDP data\n"); | |||||
return glooxwrapper::Jingle::ICEUDP::Candidate(); | |||||
} | |||||
gloox::Jingle::ICEUDP::Candidate glooxCandidate = iceUDP->candidates().front(); | |||||
return glooxwrapper::Jingle::ICEUDP::Candidate{glooxCandidate.ip, glooxCandidate.port}; | |||||
} | |||||
bool glooxwrapper::Jingle::Session::sessionInitiate(char* ipStr, uint16_t port) | |||||
{ | |||||
ZeroADGameData *gameData = new ZeroADGameData(); | |||||
gloox::Jingle::ICEUDP::CandidateList *candidateList = new gloox::Jingle::ICEUDP::CandidateList(); | |||||
Not Done Inline Actionsthe comments should be removed. elexis: the comments should be removed.
If those are arbitrary identifiers, "component_1" might be… | |||||
Not Done Inline ActionsfcxSanya: > If those are arbitrary identifiers, "component_1" might be nicer to read than "1"
I guess I… | |||||
candidateList->push_back(gloox::Jingle::ICEUDP::Candidate | |||||
{ | |||||
/*component_id*/ "1", | |||||
/*foundation*/ "1", | |||||
/*candidate_generation*/ "0", | |||||
/*candidate_id*/ "1", | |||||
ipStr, | |||||
/*network*/ "", | |||||
elexisUnsubmitted Not Done Inline Actionsnetwork should be a number elexis: network should be a number | |||||
port, | |||||
/*priotiry*/ 0, | |||||
"udp", | |||||
/*base_ip*/ "", | |||||
/*base_port*/ 0, | |||||
/*type*/ gloox::Jingle::ICEUDP::ServerReflexive | |||||
}); | |||||
gloox::Jingle::ICEUDP *iceUDP = new gloox::Jingle::ICEUDP(/*local_pwd*/"", /*local_ufrag*/"", *candidateList); | |||||
gloox::Jingle::PluginList *pluginList = new gloox::Jingle::PluginList(); | |||||
pluginList->push_back(gameData); | |||||
pluginList->push_back(iceUDP); | |||||
gloox::Jingle::Content *content = new gloox::Jingle::Content(std::string("game-data"), *pluginList); | |||||
return m_Wrapped->sessionInitiate(content); | |||||
} | |||||
glooxwrapper::Jingle::ICEUDP::ICEUDP(glooxwrapper::Jingle::ICEUDP::CandidateList& candidates) | |||||
: glooxwrapper::Jingle::Plugin(NULL, false) | |||||
{ | |||||
gloox::Jingle::ICEUDP::CandidateList glooxCandidates; | |||||
for (const glooxwrapper::Jingle::ICEUDP::Candidate candidate : candidates) | |||||
glooxCandidates.push_back(gloox::Jingle::ICEUDP::Candidate | |||||
{ | |||||
/*component_id*/ "1", | |||||
/*foundation*/ "1", | |||||
/*candidate_generation*/ "0", | |||||
/*candidate_id*/ "1", | |||||
candidate.ip.to_string(), | |||||
/*network*/ "", | |||||
candidate.port, | |||||
/*priotiry*/0, "udp", | |||||
/*base_ip*/ "", | |||||
/*base_port*/ 0, | |||||
/*type*/ gloox::Jingle::ICEUDP::ServerReflexive | |||||
}); | |||||
m_Wrapped = new gloox::Jingle::ICEUDP(/*local_pwd*/"", /*local_ufrag*/"", glooxCandidates); | |||||
m_Owned = true; | |||||
} | |||||
glooxwrapper::Jingle::ICEUDP::ICEUDP() | |||||
: glooxwrapper::Jingle::Plugin(NULL, false) | |||||
{ | |||||
m_Wrapped = new gloox::Jingle::ICEUDP(); | |||||
m_Owned = true; | |||||
} | |||||
const glooxwrapper::Jingle::ICEUDP::CandidateList glooxwrapper::Jingle::ICEUDP::candidates() const | |||||
{ | |||||
glooxwrapper::Jingle::ICEUDP::CandidateList candidateListWrapper; | |||||
for (const gloox::Jingle::ICEUDP::Candidate candidate : static_cast<const gloox::Jingle::ICEUDP*>(m_Wrapped)->candidates()) | |||||
candidateListWrapper.push_back(glooxwrapper::Jingle::ICEUDP::Candidate{candidate.ip, candidate.port}); | |||||
return candidateListWrapper; | |||||
} | |||||
glooxwrapper::SessionManager::SessionManager(Client* parent, Jingle::SessionHandler* sh) | |||||
{ | |||||
m_HandlerWrapper = new SessionHandlerWrapper(sh, false); | |||||
m_Wrapped = new gloox::Jingle::SessionManager(parent->getWrapped(), m_HandlerWrapper); | |||||
} | |||||
glooxwrapper::SessionManager::~SessionManager() | |||||
{ | |||||
delete m_Wrapped; | |||||
delete m_HandlerWrapper; | |||||
} | |||||
void glooxwrapper::SessionManager::registerPlugins() | |||||
{ | |||||
m_Wrapped->registerPlugin(new gloox::Jingle::Content()); | |||||
m_Wrapped->registerPlugin(new gloox::Jingle::ICEUDP()); | |||||
m_Wrapped->registerPlugin(new ZeroADGameData()); | |||||
} | |||||
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); | |||||
} |
make that session UNUSED()